[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 28/42] i386/hvf: Fixes dirty memory tracking by page granularity R
From: |
Paolo Bonzini |
Subject: |
[PULL 28/42] i386/hvf: Fixes dirty memory tracking by page granularity RX->RWX change |
Date: |
Sat, 8 Jun 2024 10:34:01 +0200 |
From: Phil Dennis-Jordan <phil@philjordan.eu>
When using x86 macOS Hypervisor.framework as accelerator, detection of
dirty memory regions is implemented by marking logged memory region
slots as read-only in the EPT, then setting the dirty flag when a
guest write causes a fault. The area marked dirty should then be marked
writable in order for subsequent writes to succeed without a VM exit.
However, dirty bits are tracked on a per-page basis, whereas the fault
handler was marking the whole logged memory region as writable. This
change fixes the fault handler so only the protection of the single
faulting page is marked as dirty.
(Note: the dirty page tracking appeared to work despite this error
because HVF’s hv_vcpu_run() function generated unnecessary EPT fault
exits, which ended up causing the dirty marking handler to run even
when the memory region had been marked RW. When using
hv_vcpu_run_until(), a change planned for a subsequent commit, these
spurious exits no longer occur, so dirty memory tracking malfunctions.)
Additionally, the dirty page is set to permit code execution, the same
as all other guest memory; changing memory protection from RX to RW not
RWX appears to have been an oversight.
Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
Reviewed-by: Roman Bolshakov <roman@roolebo.dev>
Tested-by: Roman Bolshakov <roman@roolebo.dev>
Message-ID: <20240605112556.43193-5-phil@philjordan.eu>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/hvf/hvf.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index e6e916225bf..268c5734d5c 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -135,9 +135,10 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64_t
gpa, uint64_t ept_qual)
if (write && slot) {
if (slot->flags & HVF_SLOT_LOG) {
+ uint64_t dirty_page_start = gpa & ~(TARGET_PAGE_SIZE - 1u);
memory_region_set_dirty(slot->region, gpa - slot->start, 1);
- hv_vm_protect((hv_gpaddr_t)slot->start, (size_t)slot->size,
- HV_MEMORY_READ | HV_MEMORY_WRITE);
+ hv_vm_protect(dirty_page_start, TARGET_PAGE_SIZE,
+ HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC);
}
}
--
2.45.1
- [PULL 18/42] osdep: Make qemu_madvise() to set errno in all cases, (continued)
- [PULL 18/42] osdep: Make qemu_madvise() to set errno in all cases, Paolo Bonzini, 2024/06/08
- [PULL 20/42] backends/hostmem: Report error when memory size is unaligned, Paolo Bonzini, 2024/06/08
- [PULL 21/42] machine, hostmem: improve error messages for unsupported features, Paolo Bonzini, 2024/06/08
- [PULL 22/42] hostmem: simplify the code for merge and dump properties, Paolo Bonzini, 2024/06/08
- [PULL 19/42] osdep: Make qemu_madvise() return ENOSYS on unsupported OSes, Paolo Bonzini, 2024/06/08
- [PULL 23/42] scsi-disk: Don't silently truncate serial number, Paolo Bonzini, 2024/06/08
- [PULL 24/42] stubs/meson: Fix qemuutil build when --disable-system, Paolo Bonzini, 2024/06/08
- [PULL 25/42] i386/hvf: Adds support for INVTSC cpuid bit, Paolo Bonzini, 2024/06/08
- [PULL 27/42] hvf: Consistent types for vCPU handles, Paolo Bonzini, 2024/06/08
- [PULL 26/42] i386/hvf: Fixes some compilation warnings, Paolo Bonzini, 2024/06/08
- [PULL 28/42] i386/hvf: Fixes dirty memory tracking by page granularity RX->RWX change,
Paolo Bonzini <=
- [PULL 29/42] i386/hvf: In kick_vcpu use hv_vcpu_interrupt to force exit, Paolo Bonzini, 2024/06/08
- [PULL 31/42] hvf: Makes assert_hvf_ok report failed expression, Paolo Bonzini, 2024/06/08
- [PULL 30/42] i386/hvf: Updates API usage to use modern vCPU run function, Paolo Bonzini, 2024/06/08
- [PULL 33/42] target/i386: mark CR4.FRED not reserved, Paolo Bonzini, 2024/06/08
- [PULL 32/42] target/i386: add support for FRED in CPUID enumeration, Paolo Bonzini, 2024/06/08
- [PULL 34/42] vmxcap: add support for VMX FRED controls, Paolo Bonzini, 2024/06/08
- [PULL 35/42] target/i386: enumerate VMX nested-exception support, Paolo Bonzini, 2024/06/08
- [PULL 36/42] target/i386: Add get/set/migrate support for FRED MSRs, Paolo Bonzini, 2024/06/08
- [PULL 37/42] docs: i386: pc: Avoid mentioning limit of maximum vCPUs, Paolo Bonzini, 2024/06/08
- [PULL 40/42] i386: Add support for overflow recovery, Paolo Bonzini, 2024/06/08