diff mbox series

[v14,05/13] KVM: x86: Add fault checks for CR4.CET

Message ID 20201106011637.14289-6-weijiang.yang@intel.com (mailing list archive)
State New, archived
Headers show
Series Introduce support for guest CET feature | expand

Commit Message

Yang, Weijiang Nov. 6, 2020, 1:16 a.m. UTC
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>
---
 arch/x86/kvm/x86.c | 6 ++++++
 arch/x86/kvm/x86.h | 3 +++
 2 files changed, 9 insertions(+)

Comments

kernel test robot Nov. 9, 2020, 10:44 a.m. UTC | #1
Hi Yang,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on tip/master]
[also build test ERROR on linus/master kvm/linux-next v5.10-rc3 next-20201109]
[cannot apply to vhost/linux-next linux/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Yang-Weijiang/Introduce-support-for-guest-CET-feature/20201106-090915
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 6f72faf4a32303c8bdc6491186b79391e9cf0c7e
config: i386-randconfig-r022-20201109 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/6ad097a38652897acc9b138f8c43f6c61ce92fc5
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Yang-Weijiang/Introduce-support-for-guest-CET-feature/20201106-090915
        git checkout 6ad097a38652897acc9b138f8c43f6c61ce92fc5
        # save the attached .config to linux build tree
        make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   arch/x86/kvm/x86.c: In function 'kvm_set_cr0':
   arch/x86/kvm/x86.c:850:53: error: 'X86_CR4_CET' undeclared (first use in this function); did you mean 'X86_CR4_DE'?
     850 |  if (!(cr0 & X86_CR0_WP) && kvm_read_cr4_bits(vcpu, X86_CR4_CET))
         |                                                     ^~~~~~~~~~~
         |                                                     X86_CR4_DE
   arch/x86/kvm/x86.c:850:53: note: each undeclared identifier is reported only once for each function it appears in
   arch/x86/kvm/x86.c: In function 'kvm_set_cr4':
   arch/x86/kvm/x86.c:1014:13: error: 'X86_CR4_CET' undeclared (first use in this function); did you mean 'X86_CR4_DE'?
    1014 |  if ((cr4 & X86_CR4_CET) && !(kvm_read_cr0(vcpu) & X86_CR0_WP))
         |             ^~~~~~~~~~~
         |             X86_CR4_DE
   arch/x86/kvm/x86.c: In function 'kvm_arch_hardware_setup':
>> arch/x86/kvm/x86.h:401:22: error: 'X86_FEATURE_SHSTK' undeclared (first use in this function); did you mean 'X86_FEATURE_EST'?
     401 |  if (!__cpu_has(__c, X86_FEATURE_SHSTK) && \
         |                      ^~~~~~~~~~~~~~~~~
   arch/x86/kvm/x86.c:10175:55: note: in definition of macro '__kvm_cpu_cap_has'
   10175 | #define __kvm_cpu_cap_has(UNUSED_, f) kvm_cpu_cap_has(f)
         |                                                       ^
   arch/x86/kvm/x86.c:10176:22: note: in expansion of macro '__cr4_reserved_bits'
   10176 |  cr4_reserved_bits = __cr4_reserved_bits(__kvm_cpu_cap_has, UNUSED_);
         |                      ^~~~~~~~~~~~~~~~~~~
>> arch/x86/kvm/x86.h:402:22: error: 'X86_FEATURE_IBT' undeclared (first use in this function); did you mean 'X86_FEATURE_IBS'?
     402 |      !__cpu_has(__c, X86_FEATURE_IBT))  \
         |                      ^~~~~~~~~~~~~~~
   arch/x86/kvm/x86.c:10175:55: note: in definition of macro '__kvm_cpu_cap_has'
   10175 | #define __kvm_cpu_cap_has(UNUSED_, f) kvm_cpu_cap_has(f)
         |                                                       ^
   arch/x86/kvm/x86.c:10176:22: note: in expansion of macro '__cr4_reserved_bits'
   10176 |  cr4_reserved_bits = __cr4_reserved_bits(__kvm_cpu_cap_has, UNUSED_);
         |                      ^~~~~~~~~~~~~~~~~~~
   In file included from arch/x86/kvm/cpuid.h:5,
                    from arch/x86/kvm/mmu.h:7,
                    from arch/x86/kvm/x86.c:22:
   arch/x86/kvm/x86.h:403:22: error: 'X86_CR4_CET' undeclared (first use in this function); did you mean 'X86_CR4_DE'?
     403 |   __reserved_bits |= X86_CR4_CET;  \
         |                      ^~~~~~~~~~~
   arch/x86/kvm/x86.c:10176:22: note: in expansion of macro '__cr4_reserved_bits'
   10176 |  cr4_reserved_bits = __cr4_reserved_bits(__kvm_cpu_cap_has, UNUSED_);
         |                      ^~~~~~~~~~~~~~~~~~~
   In file included from arch/x86/include/asm/thread_info.h:53,
                    from include/linux/thread_info.h:38,
                    from arch/x86/include/asm/preempt.h:7,
                    from include/linux/preempt.h:78,
                    from include/linux/percpu.h:6,
                    from include/linux/context_tracking_state.h:5,
                    from include/linux/hardirq.h:5,
                    from include/linux/kvm_host.h:7,
                    from arch/x86/kvm/x86.c:19:
   arch/x86/kvm/x86.c: In function 'kvm_arch_check_processor_compat':
>> arch/x86/kvm/x86.h:401:22: error: 'X86_FEATURE_SHSTK' undeclared (first use in this function); did you mean 'X86_FEATURE_EST'?
     401 |  if (!__cpu_has(__c, X86_FEATURE_SHSTK) && \
         |                      ^~~~~~~~~~~~~~~~~
   arch/x86/include/asm/cpufeature.h:118:24: note: in definition of macro 'cpu_has'
     118 |  (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
         |                        ^~~
   arch/x86/kvm/x86.c:10209:6: note: in expansion of macro '__cr4_reserved_bits'
   10209 |  if (__cr4_reserved_bits(cpu_has, c) !=
         |      ^~~~~~~~~~~~~~~~~~~
>> arch/x86/kvm/x86.h:402:22: error: 'X86_FEATURE_IBT' undeclared (first use in this function); did you mean 'X86_FEATURE_IBS'?
     402 |      !__cpu_has(__c, X86_FEATURE_IBT))  \
         |                      ^~~~~~~~~~~~~~~
   arch/x86/include/asm/cpufeature.h:118:24: note: in definition of macro 'cpu_has'
     118 |  (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
         |                        ^~~
   arch/x86/kvm/x86.c:10209:6: note: in expansion of macro '__cr4_reserved_bits'
   10209 |  if (__cr4_reserved_bits(cpu_has, c) !=
         |      ^~~~~~~~~~~~~~~~~~~
   In file included from arch/x86/kvm/cpuid.h:5,
                    from arch/x86/kvm/mmu.h:7,
                    from arch/x86/kvm/x86.c:22:
   arch/x86/kvm/x86.h:403:22: error: 'X86_CR4_CET' undeclared (first use in this function); did you mean 'X86_CR4_DE'?
     403 |   __reserved_bits |= X86_CR4_CET;  \
         |                      ^~~~~~~~~~~
   arch/x86/kvm/x86.c:10209:6: note: in expansion of macro '__cr4_reserved_bits'
   10209 |  if (__cr4_reserved_bits(cpu_has, c) !=
         |      ^~~~~~~~~~~~~~~~~~~
--
   In file included from arch/x86/kvm/cpuid.h:5,
                    from arch/x86/kvm/cpuid.c:21:
   arch/x86/kvm/cpuid.c: In function 'kvm_vcpu_after_set_cpuid':
>> arch/x86/kvm/x86.h:401:22: error: 'X86_FEATURE_SHSTK' undeclared (first use in this function); did you mean 'X86_FEATURE_EST'?
     401 |  if (!__cpu_has(__c, X86_FEATURE_SHSTK) && \
         |                      ^~~~~~~~~~~~~~~~~
   arch/x86/kvm/cpuid.c:185:6: note: in expansion of macro '__cr4_reserved_bits'
     185 |      __cr4_reserved_bits(guest_cpuid_has, vcpu);
         |      ^~~~~~~~~~~~~~~~~~~
   arch/x86/kvm/x86.h:401:22: note: each undeclared identifier is reported only once for each function it appears in
     401 |  if (!__cpu_has(__c, X86_FEATURE_SHSTK) && \
         |                      ^~~~~~~~~~~~~~~~~
   arch/x86/kvm/cpuid.c:185:6: note: in expansion of macro '__cr4_reserved_bits'
     185 |      __cr4_reserved_bits(guest_cpuid_has, vcpu);
         |      ^~~~~~~~~~~~~~~~~~~
>> arch/x86/kvm/x86.h:402:22: error: 'X86_FEATURE_IBT' undeclared (first use in this function); did you mean 'X86_FEATURE_IBS'?
     402 |      !__cpu_has(__c, X86_FEATURE_IBT))  \
         |                      ^~~~~~~~~~~~~~~
   arch/x86/kvm/cpuid.c:185:6: note: in expansion of macro '__cr4_reserved_bits'
     185 |      __cr4_reserved_bits(guest_cpuid_has, vcpu);
         |      ^~~~~~~~~~~~~~~~~~~
   arch/x86/kvm/x86.h:403:22: error: 'X86_CR4_CET' undeclared (first use in this function); did you mean 'X86_CR4_MCE'?
     403 |   __reserved_bits |= X86_CR4_CET;  \
         |                      ^~~~~~~~~~~
   arch/x86/kvm/cpuid.c:185:6: note: in expansion of macro '__cr4_reserved_bits'
     185 |      __cr4_reserved_bits(guest_cpuid_has, vcpu);
         |      ^~~~~~~~~~~~~~~~~~~

vim +401 arch/x86/kvm/x86.h

   380	
   381	#define __cr4_reserved_bits(__cpu_has, __c)             \
   382	({                                                      \
   383		u64 __reserved_bits = CR4_RESERVED_BITS;        \
   384	                                                        \
   385		if (!__cpu_has(__c, X86_FEATURE_XSAVE))         \
   386			__reserved_bits |= X86_CR4_OSXSAVE;     \
   387		if (!__cpu_has(__c, X86_FEATURE_SMEP))          \
   388			__reserved_bits |= X86_CR4_SMEP;        \
   389		if (!__cpu_has(__c, X86_FEATURE_SMAP))          \
   390			__reserved_bits |= X86_CR4_SMAP;        \
   391		if (!__cpu_has(__c, X86_FEATURE_FSGSBASE))      \
   392			__reserved_bits |= X86_CR4_FSGSBASE;    \
   393		if (!__cpu_has(__c, X86_FEATURE_PKU))           \
   394			__reserved_bits |= X86_CR4_PKE;         \
   395		if (!__cpu_has(__c, X86_FEATURE_LA57))          \
   396			__reserved_bits |= X86_CR4_LA57;        \
   397		if (!__cpu_has(__c, X86_FEATURE_UMIP))          \
   398			__reserved_bits |= X86_CR4_UMIP;        \
   399		if (!__cpu_has(__c, X86_FEATURE_VMX))           \
   400			__reserved_bits |= X86_CR4_VMXE;        \
 > 401		if (!__cpu_has(__c, X86_FEATURE_SHSTK) &&	\
 > 402		    !__cpu_has(__c, X86_FEATURE_IBT))		\
   403			__reserved_bits |= X86_CR4_CET;		\
   404		__reserved_bits;                                \
   405	})
   406	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0433015ee443..8c9d631d7842 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -847,6 +847,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);
 
 	if ((cr0 ^ old_cr0) & X86_CR0_PG) {
@@ -1008,6 +1011,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;
+
 	if (kvm_x86_ops.set_cr4(vcpu, cr4))
 		return 1;
 
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 74858c18978a..50386318a382 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -398,6 +398,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;                                \
 })