Skip to content

Commit

Permalink
KVM: x86: Add fault checks for CR4.CET
Browse files Browse the repository at this point in the history
Add the fault checks for CR4.CET, which is the master control for all
CET features (SHSTK and IBT).  In addition to basic support checks, CET
can be enabled if and only if CR0.WP==1, i.e. setting CR4.CET=1 faults
if CR0.WP==0 and setting CR0.WP=0 fails if CR4.CET==1.

Co-developed-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
  • Loading branch information
yang-weijiang authored and intel-lab-lkp committed Feb 3, 2021
1 parent bc4d185 commit bc17249
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions arch/x86/kvm/x86.c
Expand Up @@ -867,6 +867,9 @@ int kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
if (!(cr0 & X86_CR0_PG) && kvm_read_cr4_bits(vcpu, X86_CR4_PCIDE))
return 1;

if (!(cr0 & X86_CR0_WP) && kvm_read_cr4_bits(vcpu, X86_CR4_CET))
return 1;

kvm_x86_ops.set_cr0(vcpu, cr0);

kvm_post_set_cr0(vcpu, old_cr0, cr0);
Expand Down Expand Up @@ -1033,6 +1036,9 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
return 1;
}

if ((cr4 & X86_CR4_CET) && !(kvm_read_cr0(vcpu) & X86_CR0_WP))
return 1;

kvm_x86_ops.set_cr4(vcpu, cr4);

kvm_post_set_cr4(vcpu, old_cr4, cr4);
Expand Down
3 changes: 3 additions & 0 deletions arch/x86/kvm/x86.h
Expand Up @@ -425,6 +425,9 @@ bool kvm_msr_allowed(struct kvm_vcpu *vcpu, u32 index, u32 type);
__reserved_bits |= X86_CR4_UMIP; \
if (!__cpu_has(__c, X86_FEATURE_VMX)) \
__reserved_bits |= X86_CR4_VMXE; \
if (!__cpu_has(__c, X86_FEATURE_SHSTK) && \
!__cpu_has(__c, X86_FEATURE_IBT)) \
__reserved_bits |= X86_CR4_CET; \
__reserved_bits; \
})

Expand Down

0 comments on commit bc17249

Please sign in to comment.