Add overlap check between MMIO passthrough regions and MMIO intercept handler regions#327
Open
Solicey wants to merge 2 commits into
Open
Add overlap check between MMIO passthrough regions and MMIO intercept handler regions#327Solicey wants to merge 2 commits into
Solicey wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MMIO passthrough regions (MEM_TYPE_IO, mapped in stage-2 page table) and MMIO intercept handler regions (registered via
mmio_region_register()) have no cross-overlap validation. If both occupy overlapping GPA ranges, the handler silently becomes dead code — the stage-2 mapping prevents any fault, so the handler is never invoked.Background
hvisor uses two mechanisms for guest MMIO:
pt_init()→gpm.insert()mmio_region_register()→ZoneInner.mmioEach mechanism checks overlaps internally (gpm checks gpm-vs-gpm; mmio checks exact start-address duplicates), but no cross-check exists between them. The zone creation flow processes them independently:
Fix
Added bidirectional overlap checks at two insertion points:
1.
mmio_region_register()(src/zone.rs) — When registering a new intercept handler, panic if:2.
pt_init()(all four architectures) — Before inserting a passthrough region into gpm, check whether it overlaps with any already-registered MMIO handler. Overlap triggers a panic.New utility methods:
MMIORegion::is_overlap_with()in src/memory/mmio.rs — range overlap testMemorySet::is_range_overlap()in src/memory/mm.rs — public O(log n) query against stage-2 mappingsZoneInner::is_mmio_handler_overlap()in src/zone.rs — helper for pt_init checksOn loongarch64, the VIRTIO branch in
pt_init()was reordered (mmio_region_registerbeforegpm.insert) to avoid a false positive from the VIRTIO trap page.Coverage
mmio_region_register()handler-vs-handlermmio_region_register()handler-vs-gpmpt_init()gpm-vs-handlermmio_region_register()handler-vs-gpmpt_init()gpm-vs-handlerFiles Changed
src/memory/mmio.rs— addMMIORegion::is_overlap_with()src/memory/mm.rs— addMemorySet::is_range_overlap()src/zone.rs— add checks inmmio_region_register()+is_mmio_handler_overlap()helpersrc/arch/x86_64/zone.rs— add handler overlap check beforegpm.insert()src/arch/aarch64/zone.rs— samesrc/arch/riscv64/zone.rs— samesrc/arch/loongarch64/zone.rs— same + swap VIRTIO orderVerification
Tested on x86_64 QEMU by adding a VIRTIO region at the same address as the HPET IO passthrough (0xfed0_0000). The fix correctly panics at zone creation:
All four architectures (x86_64, aarch64, riscv64, loongarch64) compile successfully.