From: Patrick Roy <[email protected]> x86 supports GUEST_MEMFD_FLAG_NO_DIRECT_MAP whenever direct map modifications are possible (which is always the case).
Signed-off-by: Patrick Roy <[email protected]> Reviewed-by: Ackerley Tng <[email protected]> Reviewed-by: David Hildenbrand (Arm) <[email protected]> Signed-off-by: Nikita Kalyazin <[email protected]> --- arch/x86/include/asm/kvm_host.h | 6 ++++++ arch/x86/kvm/x86.c | 5 +++++ include/linux/kvm_host.h | 9 +++++++++ 3 files changed, 20 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 6e4e3ef9b8c7..171ce8b84137 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -28,6 +28,7 @@ #include <linux/sched/vhost_task.h> #include <linux/call_once.h> #include <linux/atomic.h> +#include <linux/set_memory.h> #include <asm/apic.h> #include <asm/pvclock-abi.h> @@ -2504,4 +2505,9 @@ static inline bool kvm_arch_has_irq_bypass(void) return enable_device_posted_irqs; } +#ifdef CONFIG_KVM_GUEST_MEMFD +bool kvm_arch_gmem_supports_no_direct_map(struct kvm *kvm); +#define kvm_arch_gmem_supports_no_direct_map kvm_arch_gmem_supports_no_direct_map +#endif /* CONFIG_KVM_GUEST_MEMFD */ + #endif /* _ASM_X86_KVM_HOST_H */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index fd1c4a36b593..6a4dcf449a37 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -14079,6 +14079,11 @@ void kvm_arch_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end) kvm_x86_call(gmem_invalidate)(start, end); } #endif + +bool kvm_arch_gmem_supports_no_direct_map(struct kvm *kvm) +{ + return can_set_direct_map() && kvm->arch.vm_type != KVM_X86_TDX_VM; +} #endif int kvm_spec_ctrl_test_value(u64 value) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index e8aa3d676c31..ce8c5fdf2752 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -742,6 +742,15 @@ static inline u64 kvm_gmem_get_supported_flags(struct kvm *kvm) } #endif +#ifdef CONFIG_KVM_GUEST_MEMFD +#ifndef kvm_arch_gmem_supports_no_direct_map +static inline bool kvm_arch_gmem_supports_no_direct_map(struct kvm *kvm) +{ + return false; +} +#endif +#endif /* CONFIG_KVM_GUEST_MEMFD */ + #ifndef kvm_arch_has_readonly_mem static inline bool kvm_arch_has_readonly_mem(struct kvm *kvm) { -- 2.50.1

