[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 19/49] kvm: Make kvm_convert_memory() obey ram_block_discard_i
From: |
Michael Roth |
Subject: |
[PATCH v3 19/49] kvm: Make kvm_convert_memory() obey ram_block_discard_is_enabled() |
Date: |
Wed, 20 Mar 2024 03:39:15 -0500 |
Some subsystems like VFIO might disable ram block discard for
uncoordinated cases. Since kvm_convert_memory()/guest_memfd don't
implement a RamDiscardManager handler to convey discard operations to
various listeners like VFIO. Because of this, sequences like the
following can result due to stale IOMMU mappings:
- convert page shared->private
- discard shared page
- convert page private->shared
- new page is allocated
- issue DMA operations against that shared page
Address this by taking ram_block_discard_is_enabled() into account when
deciding whether or not to discard pages.
Signed-off-by: Michael Roth <michael.roth@amd.com>
---
accel/kvm/kvm-all.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 53ce4f091e..6ae03c880f 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -2962,10 +2962,14 @@ static int kvm_convert_memory(hwaddr start, hwaddr
size, bool to_private)
*/
return 0;
} else {
- ret = ram_block_discard_range(rb, offset, size);
+ ret = ram_block_discard_is_disabled()
+ ? ram_block_discard_range(rb, offset, size)
+ : 0;
}
} else {
- ret = ram_block_discard_guest_memfd_range(rb, offset, size);
+ ret = ram_block_discard_is_disabled()
+ ? ram_block_discard_guest_memfd_range(rb, offset, size)
+ : 0;
}
} else {
error_report("Convert non guest_memfd backed memory region "
--
2.25.1
- Re: [PATCH v3 11/49] physmem: Introduce ram_block_discard_guest_memfd_range(), (continued)
[PATCH v3 12/49] kvm: handle KVM_EXIT_MEMORY_FAULT, Michael Roth, 2024/03/20
[PATCH v3 13/49] [FIXUP] "kvm: handle KVM_EXIT_MEMORY_FAULT": drop qemu_host_page_size, Michael Roth, 2024/03/20
[PATCH v3 14/49] trace/kvm: Add trace for page convertion between shared and private, Michael Roth, 2024/03/20
[PATCH v3 15/49] kvm/memory: Make memory type private by default if it has guest memfd backend, Michael Roth, 2024/03/20
[PATCH v3 16/49] memory: Introduce memory_region_init_ram_guest_memfd(), Michael Roth, 2024/03/20
[PATCH v3 17/49] pci-host/q35: Move PAM initialization above SMRAM initialization, Michael Roth, 2024/03/20
[PATCH v3 18/49] q35: Introduce smm_ranges property for q35-pci-host, Michael Roth, 2024/03/20
[PATCH v3 19/49] kvm: Make kvm_convert_memory() obey ram_block_discard_is_enabled(),
Michael Roth <=
[PATCH v3 20/49] trace/kvm: Add trace for KVM_EXIT_MEMORY_FAULT, Michael Roth, 2024/03/20
[PATCH v3 01/49] Revert "linux-headers hack" from sevinit2 base tree, Michael Roth, 2024/03/20
[PATCH v3 21/49] i386/sev: Introduce "sev-common" type to encapsulate common SEV state, Michael Roth, 2024/03/20