[PATCH 3/4] KVM: SVM: Remove implicit cast from ulong to bool in svm_can_emulate_instruction()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Remove implicit cast from ulong to bool in svm_can_emulate_instruction().

Drop the local var smep and smap, which are used only once.
Instead, use kvm_is_cr4_bit_set() directly.
It should be OK to call kvm_is_cr4_bit_set() twice since X86_CR4_SMAP and
X86_CR4_SMEP are intercepted and the values are read from cache instead of
VMCS field.

Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx>
Signed-off-by: Binbin Wu <binbin.wu@xxxxxxxxxxxxxxx>
---
 arch/x86/kvm/svm/svm.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 70183d2271b5..a5b9278f0052 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -4544,8 +4544,7 @@ static void svm_enable_smi_window(struct kvm_vcpu *vcpu)
 static bool svm_can_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
 					void *insn, int insn_len)
 {
-	bool smep, smap, is_user;
-	unsigned long cr4;
+	bool is_user;
 	u64 error_code;
 
 	/* Emulation is always possible when KVM has access to all guest state. */
@@ -4637,11 +4636,9 @@ static bool svm_can_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
 	if (error_code & (PFERR_GUEST_PAGE_MASK | PFERR_FETCH_MASK))
 		goto resume_guest;
 
-	cr4 = kvm_read_cr4(vcpu);
-	smep = cr4 & X86_CR4_SMEP;
-	smap = cr4 & X86_CR4_SMAP;
 	is_user = svm_get_cpl(vcpu) == 3;
-	if (smap && (!smep || is_user)) {
+	if (kvm_is_cr4_bit_set(vcpu, X86_CR4_SMAP) &&
+	    (!kvm_is_cr4_bit_set(vcpu, X86_CR4_SMEP) || is_user)) {
 		pr_err_ratelimited("SEV Guest triggered AMD Erratum 1096\n");
 
 		/*
-- 
2.25.1




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux