2020-06-19 15:44:38

by Mohammed Gamal

[permalink] [raw]
Subject: [PATCH v2 09/11] KVM: SVM: introduce svm_need_pf_intercept

CC: Tom Lendacky <[email protected]>
CC: Babu Moger <[email protected]>
Signed-off-by: Mohammed Gamal <[email protected]>
---
arch/x86/kvm/svm/svm.c | 8 ++++++++
arch/x86/kvm/svm/svm.h | 6 ++++++
2 files changed, 14 insertions(+)

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 94108e6cc6da..05412818027d 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -1087,6 +1087,9 @@ static void init_vmcb(struct vcpu_svm *svm)
}
svm->asid_generation = 0;

+ if (svm_need_pf_intercept(svm))
+ set_exception_intercept(svm, PF_VECTOR);
+
svm->nested.vmcb = 0;
svm->vcpu.arch.hflags = 0;

@@ -1633,6 +1636,11 @@ static void update_exception_bitmap(struct kvm_vcpu *vcpu)

clr_exception_intercept(svm, BP_VECTOR);

+ if (svm_need_pf_intercept(svm))
+ set_exception_intercept(svm, PF_VECTOR);
+ else
+ clr_exception_intercept(svm, PF_VECTOR);
+
if (vcpu->guest_debug & KVM_GUESTDBG_ENABLE) {
if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP)
set_exception_intercept(svm, BP_VECTOR);
diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
index 6ac4c00a5d82..2b7469f3db0e 100644
--- a/arch/x86/kvm/svm/svm.h
+++ b/arch/x86/kvm/svm/svm.h
@@ -19,6 +19,7 @@
#include <linux/kvm_host.h>

#include <asm/svm.h>
+#include "cpuid.h"

static const u32 host_save_user_msrs[] = {
#ifdef CONFIG_X86_64
@@ -345,6 +346,11 @@ static inline bool gif_set(struct vcpu_svm *svm)
return !!(svm->vcpu.arch.hflags & HF_GIF_MASK);
}

+static inline bool svm_need_pf_intercept(struct vcpu_svm *svm)
+{
+ return !npt_enabled;
+}
+
/* svm.c */
#define MSR_INVALID 0xffffffffU

--
2.26.2