Skip to content

Commit 627778b

Browse files
Binbin Wusean-jc
authored andcommitted
KVM: SVM: Use kvm_is_cr4_bit_set() to query SMAP/SMEP in "can emulate"
Use kvm_is_cr4_bit_set() to query SMAP and SMEP when determining whether or not AMD's SMAP+SEV errata prevents KVM from emulating an instruction. This eliminates an implicit cast from ulong to bool and makes the code slightly more readable. Note, any overhead from making multiple calls to kvm_read_cr4_bits() is negligible, not to mention the code is question is encountered only in rare situations, i.e. is not a remotely hot path. Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com> Link: https://lore.kernel.org/r/20230322045824.22970-4-binbin.wu@linux.intel.com [sean: keep local smap/smep variables, massage changelog] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent bede6eb commit 627778b

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

arch/x86/kvm/svm/svm.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4545,7 +4545,6 @@ static bool svm_can_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
45454545
void *insn, int insn_len)
45464546
{
45474547
bool smep, smap, is_user;
4548-
unsigned long cr4;
45494548
u64 error_code;
45504549

45514550
/* Emulation is always possible when KVM has access to all guest state. */
@@ -4637,9 +4636,8 @@ static bool svm_can_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type,
46374636
if (error_code & (PFERR_GUEST_PAGE_MASK | PFERR_FETCH_MASK))
46384637
goto resume_guest;
46394638

4640-
cr4 = kvm_read_cr4(vcpu);
4641-
smep = cr4 & X86_CR4_SMEP;
4642-
smap = cr4 & X86_CR4_SMAP;
4639+
smep = kvm_is_cr4_bit_set(vcpu, X86_CR4_SMEP);
4640+
smap = kvm_is_cr4_bit_set(vcpu, X86_CR4_SMAP);
46434641
is_user = svm_get_cpl(vcpu) == 3;
46444642
if (smap && (!smep || is_user)) {
46454643
pr_err_ratelimited("SEV Guest triggered AMD Erratum 1096\n");

0 commit comments

Comments
 (0)