[RFC PATCH 3/3] RFC: KVM: x86: support KVM_CAP_DMA_MEM
Chia-I Wu
olvaffe at gmail.com
Thu Feb 13 21:30:36 UTC 2020
When a memslot has KVM_MEM_DMA set, we want VMX_EPT_IPAT_BIT cleared
for the memslot. Before that is possible, simply call
kvm_arch_register_noncoherent_dma for the memslot.
SVM does not have the ignore-pat bit. Guest PAT is always honored.
Signed-off-by: Chia-I Wu <olvaffe at gmail.com>
Cc: Gurchetan Singh <gurchetansingh at chromium.org>
Cc: Gerd Hoffmann <kraxel at redhat.com>
---
arch/x86/include/uapi/asm/kvm.h | 1 +
arch/x86/kvm/x86.c | 6 ++++++
2 files changed, 7 insertions(+)
diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h
index 503d3f42da16..578b686e3880 100644
--- a/arch/x86/include/uapi/asm/kvm.h
+++ b/arch/x86/include/uapi/asm/kvm.h
@@ -48,6 +48,7 @@
#define __KVM_HAVE_XSAVE
#define __KVM_HAVE_XCRS
#define __KVM_HAVE_READONLY_MEM
+#define __KVM_HAVE_DMA_MEM
/* Architectural interrupt line count. */
#define KVM_NR_INTERRUPTS 256
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index fb5d64ebc35d..c89a4647fef6 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3331,6 +3331,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
case KVM_CAP_GET_TSC_KHZ:
case KVM_CAP_KVMCLOCK_CTRL:
case KVM_CAP_READONLY_MEM:
+ case KVM_CAP_DMA_MEM:
case KVM_CAP_HYPERV_TIME:
case KVM_CAP_IOAPIC_POLARITY_IGNORED:
case KVM_CAP_TSC_DEADLINE_TIMER:
@@ -10045,6 +10046,11 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
*/
if (change != KVM_MR_DELETE)
kvm_mmu_slot_apply_flags(kvm, (struct kvm_memory_slot *) new);
+
+ if (change == KVM_MR_CREATE && new->flags & KVM_MEM_DMA)
+ kvm_arch_register_noncoherent_dma(kvm);
+ else if (change == KVM_MR_DELETE && old->flags & KVM_MEM_DMA)
+ kvm_arch_unregister_noncoherent_dma(kvm);
}
void kvm_arch_flush_shadow_all(struct kvm *kvm)
--
2.25.0.265.gbab2e86ba0-goog
More information about the dri-devel
mailing list