Skip to content

fix(x86_64/uefi): unmap stack on drop - #2591

Open
mkroening wants to merge 1 commit into
mainfrom
uefi-unmap-stack
Open

fix(x86_64/uefi): unmap stack on drop#2591
mkroening wants to merge 1 commit into
mainfrom
uefi-unmap-stack

Conversation

@mkroening

Copy link
Copy Markdown
Member

This PR makes the kernel unmap user stacks on drop. In early UEFI times, this was not necessary, since we would never touch the page tables for stacks. This changed in a68db87, but forgot to enable unmapping.

This PR makes the following UB program throw a page fault as expected on UEFI:

use std::thread;

struct Ptr(*mut ());

unsafe impl Send for Ptr {}

fn main() {
	let thread = thread::spawn(move || {
		let rsp: *mut ();
		unsafe {
			core::arch::asm!("mov {}, rsp", out(reg) rsp);
		}
		Ptr(rsp)
	});
	let ptr = thread.join().unwrap().0;
	dbg!(ptr);

	// Yield to drop thread.
	thread::yield_now();

	unsafe {
		ptr.cast::<u8>().write(0);
	}
}

I noticed this while working on #2546.

@mkroening mkroening self-assigned this Aug 2, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark Results

Details
Benchmark Current: 72e1efe Previous: 2e23902 Performance Ratio
startup_benchmark Build Time 82.34 s 80.34 s 1.02
startup_benchmark File Size 0.76 MB 0.80 MB 0.96
Startup Time - 1 core 0.75 s (±0.02 s) 0.75 s (±0.02 s) 1.00
Startup Time - 2 cores 0.76 s (±0.03 s) 0.74 s (±0.02 s) 1.03
Startup Time - 4 cores 0.77 s (±0.02 s) 0.74 s (±0.02 s) 1.04
multithreaded_benchmark Build Time 85.95 s 82.11 s 1.05
multithreaded_benchmark File Size 0.90 MB 0.86 MB 1.05
Multithreaded Pi Efficiency - 2 Threads 88.45 % (±4.31 %) 85.89 % (±6.61 %) 1.03
Multithreaded Pi Efficiency - 4 Threads 42.96 % (±2.52 %) 43.43 % (±2.56 %) 0.99
Multithreaded Pi Efficiency - 8 Threads 25.51 % (±1.24 %) 25.76 % (±1.53 %) 0.99
micro_benchmarks Build Time 83.33 s 80.40 s 1.04
micro_benchmarks File Size 0.90 MB 0.86 MB 1.05
Scheduling time - 1 thread 65.61 ticks (±2.53 ticks) 62.65 ticks (±4.06 ticks) 1.05
Scheduling time - 2 threads 35.16 ticks (±4.19 ticks) 34.08 ticks (±4.10 ticks) 1.03
Micro - Time for syscall (getpid) 4.39 ticks (±0.67 ticks) 3.45 ticks (±0.58 ticks) 1.27
Memcpy speed - (built_in) block size 4096 85349.81 MByte/s (±58857.17 MByte/s) 82448.38 MByte/s (±56997.13 MByte/s) 1.04
Memcpy speed - (built_in) block size 1048576 30318.36 MByte/s (±24516.13 MByte/s) 30585.98 MByte/s (±24707.84 MByte/s) 0.99
Memcpy speed - (built_in) block size 16777216 25749.61 MByte/s (±21245.64 MByte/s) 26340.06 MByte/s (±21720.96 MByte/s) 0.98
Memset speed - (built_in) block size 4096 85394.45 MByte/s (±58890.27 MByte/s) 82292.76 MByte/s (±56891.50 MByte/s) 1.04
Memset speed - (built_in) block size 1048576 31082.33 MByte/s (±24971.90 MByte/s) 31323.85 MByte/s (±25145.86 MByte/s) 0.99
Memset speed - (built_in) block size 16777216 26529.51 MByte/s (±21769.55 MByte/s) 27104.68 MByte/s (±22209.94 MByte/s) 0.98
Memcpy speed - (rust) block size 4096 76137.56 MByte/s (±52956.16 MByte/s) 74097.96 MByte/s (±51811.44 MByte/s) 1.03
Memcpy speed - (rust) block size 1048576 30296.96 MByte/s (±24508.85 MByte/s) 30361.60 MByte/s (±24602.37 MByte/s) 1.00
Memcpy speed - (rust) block size 16777216 25845.41 MByte/s (±21335.12 MByte/s) 27625.34 MByte/s (±22806.88 MByte/s) 0.94
Memset speed - (rust) block size 4096 76824.44 MByte/s (±53411.16 MByte/s) 74373.47 MByte/s (±51976.48 MByte/s) 1.03
Memset speed - (rust) block size 1048576 31059.74 MByte/s (±24969.87 MByte/s) 31110.89 MByte/s (±25033.24 MByte/s) 1.00
Memset speed - (rust) block size 16777216 26627.72 MByte/s (±21861.40 MByte/s) 28386.93 MByte/s (±23265.03 MByte/s) 0.94
alloc_benchmarks Build Time 81.66 s 74.76 s 1.09
alloc_benchmarks File Size 0.84 MB 0.87 MB 0.96
Allocations - Allocation success 91.31 % 91.31 % 1
Allocations - Deallocation success 100.00 % 100.00 % 1
Allocations - Pre-fail Allocations 61.44 % 61.44 % 1
Allocations - Average Allocation time 4349.35 Ticks (±135.04 Ticks) 5860.58 Ticks (±98.43 Ticks) 0.74
Allocations - Average Allocation time (no fail) 5077.44 Ticks (±134.66 Ticks) 6554.81 Ticks (±92.86 Ticks) 0.77
Allocations - Average Deallocation time 966.06 Ticks (±199.59 Ticks) 1805.01 Ticks (±250.35 Ticks) 0.54
mutex_benchmark Build Time 81.23 s 79.82 s 1.02
mutex_benchmark File Size 0.90 MB 0.86 MB 1.05
Mutex Stress Test Average Time per Iteration - 1 Threads 12.26 ns (±0.48 ns) 12.10 ns (±0.41 ns) 1.01
Mutex Stress Test Average Time per Iteration - 2 Threads 41.52 ns (±2.58 ns) 40.26 ns (±1.68 ns) 1.03

This comment was automatically generated by workflow using github-action-benchmark.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant