vmm: probe soft-dirty support with real pagemap round-trip#1115
vmm: probe soft-dirty support with real pagemap round-trip#1115aichitudou123 wants to merge 1 commit into
Conversation
The original probe_soft_dirty_support() simply wrote "4" to
/proc/self/clear_refs to determine whether the kernel supports the
soft-dirty mechanism. However, on kernels without CONFIG_MEM_SOFT_DIRTY
(ARM64, x86 with the option disabled), clear_refs_write() silently
no-ops the write and returns success, causing the probe to incorrectly
return true. This led three soft-dirty-dependent unit tests to enter the
test body on unsupported kernels and panic because bit 55 is always 0.
Replace the probe with a real pagemap round-trip:
1. mmap one page of anonymous memory, then write one byte to trigger
VM_SOFTDIRTY to set bit 55 in the PTE.
2. Read /proc/self/pagemap to verify bit 55 is actually set.
- If bit 55 is not 1, treat the kernel as unsupported and return
false directly (skip clear_soft_dirty to avoid unnecessary
mmap_lock write-lock PTE traversal on incapable machines).
- If bit 55 is 1, call clear_soft_dirty once to arm the tracker and
return true.
Signed-off-by: Jiahui Xu <2479844665@qq.com>
| } | ||
|
|
||
| // Step 3: read the pagemap entry and check bit 55. | ||
| let bit55_set = get_soft_dirty_pages(host_addr, page_size) |
There was a problem hiding this comment.
Swap edge case: The probe relies on get_soft_dirty_pages which treats swapped pages (bit 62) as dirty regardless of bit 55. If the freshly-written scratch page is swapped out between the write and the pagemap read (extremely unlikely — ~ms window, startup, single page), the probe would return a false positive.
Consider guarding the probe result against this: if get_soft_dirty_pages returns true only because swapped=true (bit 62) on a page you know you just wrote, the result is ambiguous. Adding an inline note or a dedicated is_soft_dirty_supported(host_addr) helper that checks present && (entry & SOFT_DIRTY_BIT) != 0 would eliminate this theoretical false positive entirely.
Review: vmm — probe soft-dirty support with real pagemap round-tripAI-generated review. No human approval has been obtained. OverviewThis PR replaces the unreliable Files changed: 1 file ( What the old code got wrongThe old This is a real, well-diagnosed bug. The fix is correct and necessary. Implementation assessmentApproach — soundThe round-trip is the right way to probe:
On kernels without Error handling — adequateAll fallible operations are handled gracefully with
All paths are covered; no panic is introduced. SafetyThe function remains entirely Dependency on
|
|
Please fix the error in the code format check |
The original probe_soft_dirty_support() simply wrote "4" to /proc/self/clear_refs to determine whether the kernel supports the soft-dirty mechanism. However, on kernels without CONFIG_MEM_SOFT_DIRTY (ARM64, x86 with the option disabled), clear_refs_write() silently no-ops the write and returns success, causing the probe to incorrectly return true. This led three soft-dirty-dependent unit tests to enter the test body on unsupported kernels and panic because bit 55 is always 0.
Replace the probe with a real pagemap round-trip: