[PATCH 11/11] KVM: Disallow dirty logging for x86 TDX

From: Xiaoyao Li
Date: Fri Nov 12 2021 - 10:40:07 EST


From: Sean Christopherson <sean.j.christopherson@xxxxxxxxx>

TDX doesn't support dirty logging for now.

Suggested-by: Kai Huang <kai.huang@xxxxxxxxx>
Signed-off-by: Sean Christopherson <sean.j.christopherson@xxxxxxxxx>
Signed-off-by: Xiaoyao Li <xiaoyao.li@xxxxxxxxx>
---

Do we need to introduce a VM-scope CAP to report if dirty log is supported?
since in the future, next generation of TDX will support live migration.
---
arch/x86/kvm/x86.c | 5 +++++
include/linux/kvm_host.h | 1 +
virt/kvm/kvm_main.c | 10 +++++++++-
3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index f091a4d3c8f2..c30933289b54 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -12611,6 +12611,11 @@ int kvm_sev_es_string_io(struct kvm_vcpu *vcpu, unsigned int size,
}
EXPORT_SYMBOL_GPL(kvm_sev_es_string_io);

+bool kvm_arch_dirty_log_supported(struct kvm *kvm)
+{
+ return kvm->arch.vm_type != KVM_X86_TDX_VM;
+}
+
bool kvm_arch_support_readonly_mem(struct kvm *kvm)
{
return kvm->arch.vm_type != KVM_X86_TDX_VM;
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 1dbabf199c13..5f3debcd4295 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -1071,6 +1071,7 @@ bool kvm_arch_dy_has_pending_interrupt(struct kvm_vcpu *vcpu);
int kvm_arch_post_init_vm(struct kvm *kvm);
void kvm_arch_pre_destroy_vm(struct kvm *kvm);
int kvm_arch_create_vm_debugfs(struct kvm *kvm);
+bool kvm_arch_dirty_log_supported(struct kvm *kvm);
bool kvm_arch_support_readonly_mem(struct kvm *kvm);

#ifndef __KVM_HAVE_ARCH_VM_ALLOC
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index c288c92a9c82..4c9d1e7834eb 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1421,6 +1421,11 @@ static void update_memslots(struct kvm_memslots *slots,
}
}

+bool __weak kvm_arch_dirty_log_supported(struct kvm *kvm)
+{
+ return true;
+}
+
bool __weak kvm_arch_support_readonly_mem(struct kvm *kvm)
{
#ifdef __KVM_HAVE_READONLY_MEM
@@ -1433,7 +1438,10 @@ bool __weak kvm_arch_support_readonly_mem(struct kvm *kvm)
static int check_memory_region_flags(struct kvm *kvm,
const struct kvm_userspace_memory_region *mem)
{
- u32 valid_flags = KVM_MEM_LOG_DIRTY_PAGES;
+ u32 valid_flags = 0;
+
+ if (kvm_arch_dirty_log_supported(kvm))
+ valid_flags |= KVM_MEM_LOG_DIRTY_PAGES;

if (kvm_arch_support_readonly_mem(kvm))
valid_flags |= KVM_MEM_READONLY;
--
2.27.0