Skip to content

Conversation

@copybara-service
Copy link

kvm: avoid mmio exits when Sentry faults on unmapped memory

Currently, we generate page tables for the entire sentry address space.
Consequently, when the Sentry faults on unmapped memory - meaning a memory
region not yet mapped into the VM - an MMIO exit is triggered. The issue is
that because the current instruction is emulated (instead of executed
natively), it becomes impossible to trigger a "normal" memory fault.

To solve this, we must set up page tables only for the regions that are
explicitly mapped into the VM. This, however, is more challenging than it
sounds for several reasons:

We map memory regions into the VM from a signal handler, where memory
allocation is prohibited. This means all necessary page table entries must be
allocated during platform initialization.

Our memory regions are not aligned to huge page boundaries. Therefore, when
mapping a memory slot, we often need to split huge pages and allocate new page
table entries.

We run into the nosplit stack limit, requiring us to introduce a PTE.Get method
to safely avoid accessing splice entries via indices, which could
trigger a panic and so requires a lot of extra stack.

@copybara-service copybara-service bot added the exported Issue was exported automatically label Nov 4, 2025
@copybara-service copybara-service bot force-pushed the test/cl827726897 branch 2 times, most recently from de344fb to 0488814 Compare November 4, 2025 16:49
Currently, we generate page tables for the entire sentry address space.
Consequently, when the Sentry faults on unmapped memory - meaning a memory
region not yet mapped into the VM - an MMIO exit is triggered. The issue is
that because the current instruction is emulated (instead of executed
natively), it becomes impossible to trigger a "normal" memory fault.

To solve this, we must set up page tables only for the regions that are
explicitly mapped into the VM. This, however, is more challenging than it
sounds for several reasons:

We map memory regions into the VM from a signal handler, where memory
allocation is prohibited. This means all necessary page table entries must be
allocated during platform initialization.

Our memory regions are not aligned to huge page boundaries. Therefore, when
mapping a memory slot, we often need to split huge pages and allocate new page
table entries.

We run into the nosplit stack limit, requiring us to introduce a PTE.Get method
to safely avoid accessing splice entries via indices, which could
trigger a panic and so requires a lot of extra stack.

PiperOrigin-RevId: 827726897
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

exported Issue was exported automatically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants