[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v2 06/19] KVM: x86: Add kvm_x86_ops.fault_gva()
|
From: |
Mickaël Salaün |
|
Subject: |
[RFC PATCH v2 06/19] KVM: x86: Add kvm_x86_ops.fault_gva() |
|
Date: |
Sun, 12 Nov 2023 21:23:13 -0500 |
This function is needed for kvm_mmu_page_fault() to create synthetic
page faults.
Code originally written by Mihai Donțu and Nicușor Cîțu:
https://lore.kernel.org/r/20211006173113.26445-18-alazar@bitdefender.com
Renamed fault_gla() to fault_gva() and use the new
EPT_VIOLATION_GVA_IS_VALID.
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Wanpeng Li <wanpengli@tencent.com>
Co-developed-by: Mihai Donțu <mdontu@bitdefender.com>
Signed-off-by: Mihai Donțu <mdontu@bitdefender.com>
Co-developed-by: Nicușor Cîțu <nicu.citu@icloud.com>
Signed-off-by: Nicușor Cîțu <nicu.citu@icloud.com>
Signed-off-by: Mickaël Salaün <mic@digikod.net>
---
arch/x86/include/asm/kvm-x86-ops.h | 1 +
arch/x86/include/asm/kvm_host.h | 2 ++
arch/x86/kvm/svm/svm.c | 9 +++++++++
arch/x86/kvm/vmx/vmx.c | 10 ++++++++++
4 files changed, 22 insertions(+)
diff --git a/arch/x86/include/asm/kvm-x86-ops.h
b/arch/x86/include/asm/kvm-x86-ops.h
index e3054e3e46d5..ba3db679db2b 100644
--- a/arch/x86/include/asm/kvm-x86-ops.h
+++ b/arch/x86/include/asm/kvm-x86-ops.h
@@ -134,6 +134,7 @@ KVM_X86_OP(msr_filter_changed)
KVM_X86_OP(complete_emulated_msr)
KVM_X86_OP(vcpu_deliver_sipi_vector)
KVM_X86_OP_OPTIONAL_RET0(vcpu_get_apicv_inhibit_reasons);
+KVM_X86_OP(fault_gva)
#undef KVM_X86_OP
#undef KVM_X86_OP_OPTIONAL
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index dff10051e9b6..0415dacd4b28 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1750,6 +1750,8 @@ struct kvm_x86_ops {
* Returns vCPU specific APICv inhibit reasons
*/
unsigned long (*vcpu_get_apicv_inhibit_reasons)(struct kvm_vcpu *vcpu);
+
+ u64 (*fault_gva)(struct kvm_vcpu *vcpu);
};
struct kvm_x86_nested_ops {
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index beea99c8e8e0..d32517a2cf9c 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -4906,6 +4906,13 @@ static int svm_vm_init(struct kvm *kvm)
return 0;
}
+static u64 svm_fault_gva(struct kvm_vcpu *vcpu)
+{
+ const struct vcpu_svm *svm = to_svm(vcpu);
+
+ return svm->vcpu.arch.cr2 ? svm->vcpu.arch.cr2 : ~0ull;
+}
+
static struct kvm_x86_ops svm_x86_ops __initdata = {
.name = KBUILD_MODNAME,
@@ -5037,6 +5044,8 @@ static struct kvm_x86_ops svm_x86_ops __initdata = {
.vcpu_deliver_sipi_vector = svm_vcpu_deliver_sipi_vector,
.vcpu_get_apicv_inhibit_reasons = avic_vcpu_get_apicv_inhibit_reasons,
+
+ .fault_gva = svm_fault_gva,
};
/*
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 1b1581f578b0..a8158bc1dda9 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -8233,6 +8233,14 @@ static void vmx_vm_destroy(struct kvm *kvm)
free_pages((unsigned long)kvm_vmx->pid_table,
vmx_get_pid_table_order(kvm));
}
+static u64 vmx_fault_gva(struct kvm_vcpu *vcpu)
+{
+ if (vcpu->arch.exit_qualification & EPT_VIOLATION_GVA_IS_VALID)
+ return vmcs_readl(GUEST_LINEAR_ADDRESS);
+
+ return ~0ull;
+}
+
static struct kvm_x86_ops vmx_x86_ops __initdata = {
.name = KBUILD_MODNAME,
@@ -8373,6 +8381,8 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = {
.complete_emulated_msr = kvm_complete_insn_gp,
.vcpu_deliver_sipi_vector = kvm_vcpu_deliver_sipi_vector,
+
+ .fault_gva = vmx_fault_gva,
};
static unsigned int vmx_handle_intel_pt_intr(void)
--
2.42.1
- [RFC PATCH v2 00/19] Hypervisor-Enforced Kernel Integrity, Mickaël Salaün, 2023/11/12
- [RFC PATCH v2 01/19] virt: Introduce Hypervisor Enforced Kernel Integrity (Heki), Mickaël Salaün, 2023/11/12
- [RFC PATCH v2 02/19] KVM: x86: Add new hypercall to lock control registers, Mickaël Salaün, 2023/11/12
- [RFC PATCH v2 03/19] KVM: x86: Add notifications for Heki policy configuration and violation, Mickaël Salaün, 2023/11/12
- [RFC PATCH v2 04/19] heki: Lock guest control registers at the end of guest kernel init, Mickaël Salaün, 2023/11/12
- [RFC PATCH v2 05/19] KVM: VMX: Add MBEC support, Mickaël Salaün, 2023/11/12
- [RFC PATCH v2 06/19] KVM: x86: Add kvm_x86_ops.fault_gva(),
Mickaël Salaün <=
- [RFC PATCH v2 07/19] KVM: x86: Make memory attribute helpers more generic, Mickaël Salaün, 2023/11/12
- [RFC PATCH v2 09/19] KVM: x86: Extend kvm_range_has_memory_attributes() with match_all, Mickaël Salaün, 2023/11/12
- [RFC PATCH v2 10/19] KVM: x86: Implement per-guest-page permissions, Mickaël Salaün, 2023/11/12
- [RFC PATCH v2 11/19] KVM: x86: Add new hypercall to set EPT permissions, Mickaël Salaün, 2023/11/12
- [RFC PATCH v2 08/19] KVM: x86: Extend kvm_vm_set_mem_attributes() with a mask, Mickaël Salaün, 2023/11/12
- [RFC PATCH v2 12/19] x86: Implement the Memory Table feature to store arbitrary per-page data, Mickaël Salaün, 2023/11/12
- [RFC PATCH v2 13/19] heki: Implement a kernel page table walker, Mickaël Salaün, 2023/11/12
- [RFC PATCH v2 14/19] heki: x86: Initialize permissions counters for pages mapped into KVA, Mickaël Salaün, 2023/11/12
- [RFC PATCH v2 15/19] heki: x86: Initialize permissions counters for pages in vmap()/vunmap(), Mickaël Salaün, 2023/11/12
- [RFC PATCH v2 17/19] heki: x86: Update permissions counters during text patching, Mickaël Salaün, 2023/11/12