[PATCH v6 2/5] x86/cpufeatures: Add X86_FEATURE_SGX_EUPDATESVN feature flag

Elena Reshetova posted 5 patches 6 months, 3 weeks ago
There is a newer version of this series
[PATCH v6 2/5] x86/cpufeatures: Add X86_FEATURE_SGX_EUPDATESVN feature flag
Posted by Elena Reshetova 6 months, 3 weeks ago
Add a flag indicating whenever ENCLS[EUPDATESVN] SGX instruction
is supported. This will be used by SGX driver to perform CPU
SVN updates.

Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
---
 arch/x86/include/asm/cpufeatures.h       | 1 +
 arch/x86/kernel/cpu/cpuid-deps.c         | 1 +
 arch/x86/kernel/cpu/scattered.c          | 1 +
 tools/arch/x86/include/asm/cpufeatures.h | 1 +
 4 files changed, 4 insertions(+)

diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
index 5b50e0e35129..ee8f0e30ab6c 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -483,6 +483,7 @@
 #define X86_FEATURE_PREFER_YMM		(21*32+ 8) /* Avoid ZMM registers due to downclocking */
 #define X86_FEATURE_APX			(21*32+ 9) /* Advanced Performance Extensions */
 #define X86_FEATURE_INDIRECT_THUNK_ITS	(21*32+10) /* Use thunk for indirect branches in lower half of cacheline */
+#define X86_FEATURE_SGX_EUPDATESVN	(21*32+11) /* Support for ENCLS[EUPDATESVN] instruction */
 
 /*
  * BUG word(s)
diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c
index 46efcbd6afa4..3d9f49ad0efd 100644
--- a/arch/x86/kernel/cpu/cpuid-deps.c
+++ b/arch/x86/kernel/cpu/cpuid-deps.c
@@ -79,6 +79,7 @@ static const struct cpuid_dep cpuid_deps[] = {
 	{ X86_FEATURE_SGX_LC,			X86_FEATURE_SGX	      },
 	{ X86_FEATURE_SGX1,			X86_FEATURE_SGX       },
 	{ X86_FEATURE_SGX2,			X86_FEATURE_SGX1      },
+	{ X86_FEATURE_SGX_EUPDATESVN,		X86_FEATURE_SGX1      },
 	{ X86_FEATURE_SGX_EDECCSSA,		X86_FEATURE_SGX1      },
 	{ X86_FEATURE_XFD,			X86_FEATURE_XSAVES    },
 	{ X86_FEATURE_XFD,			X86_FEATURE_XGETBV1   },
diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c
index dbf6d71bdf18..2a29fc33a891 100644
--- a/arch/x86/kernel/cpu/scattered.c
+++ b/arch/x86/kernel/cpu/scattered.c
@@ -42,6 +42,7 @@ static const struct cpuid_bit cpuid_bits[] = {
 	{ X86_FEATURE_PER_THREAD_MBA,		CPUID_ECX,  0, 0x00000010, 3 },
 	{ X86_FEATURE_SGX1,			CPUID_EAX,  0, 0x00000012, 0 },
 	{ X86_FEATURE_SGX2,			CPUID_EAX,  1, 0x00000012, 0 },
+	{ X86_FEATURE_SGX_EUPDATESVN,		CPUID_EAX, 10, 0x00000012, 0 },
 	{ X86_FEATURE_SGX_EDECCSSA,		CPUID_EAX, 11, 0x00000012, 0 },
 	{ X86_FEATURE_HW_PSTATE,		CPUID_EDX,  7, 0x80000007, 0 },
 	{ X86_FEATURE_CPB,			CPUID_EDX,  9, 0x80000007, 0 },
diff --git a/tools/arch/x86/include/asm/cpufeatures.h b/tools/arch/x86/include/asm/cpufeatures.h
index bc81b9d1aeca..769ee7e411c3 100644
--- a/tools/arch/x86/include/asm/cpufeatures.h
+++ b/tools/arch/x86/include/asm/cpufeatures.h
@@ -481,6 +481,7 @@
 #define X86_FEATURE_AMD_HTR_CORES	(21*32+ 6) /* Heterogeneous Core Topology */
 #define X86_FEATURE_AMD_WORKLOAD_CLASS	(21*32+ 7) /* Workload Classification */
 #define X86_FEATURE_PREFER_YMM		(21*32+ 8) /* Avoid ZMM registers due to downclocking */
+#define X86_FEATURE_SGX_EUPDATESVN	(21*32+11) /* Support for ENCLS[EUPDATESVN] instruction */
 
 /*
  * BUG word(s)
-- 
2.45.2
Re: [PATCH v6 2/5] x86/cpufeatures: Add X86_FEATURE_SGX_EUPDATESVN feature flag
Posted by Huang, Kai 6 months, 3 weeks ago
On Thu, 2025-05-22 at 12:21 +0300, Elena Reshetova wrote:
> --- a/tools/arch/x86/include/asm/cpufeatures.h
> +++ b/tools/arch/x86/include/asm/cpufeatures.h
> @@ -481,6 +481,7 @@
>  #define X86_FEATURE_AMD_HTR_CORES	(21*32+ 6) /* Heterogeneous Core Topology */
>  #define X86_FEATURE_AMD_WORKLOAD_CLASS	(21*32+ 7) /* Workload Classification */
>  #define X86_FEATURE_PREFER_YMM		(21*32+ 8) /* Avoid ZMM registers due to downclocking */
> +#define X86_FEATURE_SGX_EUPDATESVN	(21*32+11) /* Support for ENCLS[EUPDATESVN] instruction */

[Sorry for not mentioning in the previous version.]

Nit:

I am not sure we need to change tool headers.

Per commit

  f6d9883f8e68 ("tools/include: Sync x86 headers with the kernel sources")

.. and tools/include/uapi/README:

  ...

  What we are doing now is a third option:

   - A software-enforced copy-on-write mechanism of kernel headers to
     tooling, driven by non-fatal warnings on the tooling side build when
     kernel headers get modified:

      Warning: Kernel ABI header differences:
        diff -u tools/include/uapi/drm/i915_drm.h include/uapi/drm/i915_drm.h
        diff -u tools/include/uapi/linux/fs.h include/uapi/linux/fs.h
        diff -u tools/include/uapi/linux/kvm.h include/uapi/linux/kvm.h
        ...

     The tooling policy is to always pick up the kernel side headers as-is,
     and integate them into the tooling build. The warnings above serve as a
     notification to tooling maintainers that there's changes on the kernel
     side.

  We've been using this for many years now, and it might seem hacky, but
  works surprisingly well.

.. I interpret the updating to tools headers is not mandatory (unless building
tools fails w/o the new feature bit definition which I believe isn't the case of
SGX_UPDATESVN).  The tools maintainers will eventually do the sync.

But on the other hand, modifying tools headers in this patch also reduces tools
maintainer's effort in the future.

That being said, I am unclear with the rule here.  Perhaps Dave/Ingo can help to
clarify.
RE: [PATCH v6 2/5] x86/cpufeatures: Add X86_FEATURE_SGX_EUPDATESVN feature flag
Posted by Reshetova, Elena 6 months, 3 weeks ago
> -----Original Message-----
> From: Huang, Kai <kai.huang@intel.com>
> Sent: Friday, May 23, 2025 3:18 AM
> To: Reshetova, Elena <elena.reshetova@intel.com>; Hansen, Dave
> <dave.hansen@intel.com>
> Cc: Raynor, Scott <scott.raynor@intel.com>; seanjc@google.com;
> mingo@kernel.org; Scarlata, Vincent R <vincent.r.scarlata@intel.com>;
> x86@kernel.org; jarkko@kernel.org; Annapurve, Vishal
> <vannapurve@google.com>; linux-kernel@vger.kernel.org; Mallick, Asit K
> <asit.k.mallick@intel.com>; Aktas, Erdem <erdemaktas@google.com>; Cai,
> Chong <chongc@google.com>; bondarn@google.com; linux-
> sgx@vger.kernel.org; dionnaglaze@google.com
> Subject: Re: [PATCH v6 2/5] x86/cpufeatures: Add
> X86_FEATURE_SGX_EUPDATESVN feature flag
> 
> On Thu, 2025-05-22 at 12:21 +0300, Elena Reshetova wrote:
> > --- a/tools/arch/x86/include/asm/cpufeatures.h
> > +++ b/tools/arch/x86/include/asm/cpufeatures.h
> > @@ -481,6 +481,7 @@
> >  #define X86_FEATURE_AMD_HTR_CORES	(21*32+ 6) /* Heterogeneous
> Core Topology */
> >  #define X86_FEATURE_AMD_WORKLOAD_CLASS	(21*32+ 7) /*
> Workload Classification */
> >  #define X86_FEATURE_PREFER_YMM		(21*32+ 8) /* Avoid ZMM
> registers due to downclocking */
> > +#define X86_FEATURE_SGX_EUPDATESVN	(21*32+11) /* Support for
> ENCLS[EUPDATESVN] instruction */
> 
> [Sorry for not mentioning in the previous version.]
> 
> Nit:
> 
> I am not sure we need to change tool headers.
> 
> Per commit
> 
>   f6d9883f8e68 ("tools/include: Sync x86 headers with the kernel sources")
> 
> .. and tools/include/uapi/README:
> 
>   ...
> 
>   What we are doing now is a third option:
> 
>    - A software-enforced copy-on-write mechanism of kernel headers to
>      tooling, driven by non-fatal warnings on the tooling side build when
>      kernel headers get modified:
> 
>       Warning: Kernel ABI header differences:
>         diff -u tools/include/uapi/drm/i915_drm.h include/uapi/drm/i915_drm.h
>         diff -u tools/include/uapi/linux/fs.h include/uapi/linux/fs.h
>         diff -u tools/include/uapi/linux/kvm.h include/uapi/linux/kvm.h
>         ...
> 
>      The tooling policy is to always pick up the kernel side headers as-is,
>      and integate them into the tooling build. The warnings above serve as a
>      notification to tooling maintainers that there's changes on the kernel
>      side.
> 
>   We've been using this for many years now, and it might seem hacky, but
>   works surprisingly well.
> 
> .. I interpret the updating to tools headers is not mandatory (unless building
> tools fails w/o the new feature bit definition which I believe isn't the case of
> SGX_UPDATESVN).  The tools maintainers will eventually do the sync.
> 
> But on the other hand, modifying tools headers in this patch also reduces
> tools
> maintainer's effort in the future.
> 
> That being said, I am unclear with the rule here.  Perhaps Dave/Ingo can help
> to
> clarify.


Thank you Kai! I am also not sure what is the rule since I have checked before
and different patches to x86/cpufeatures.c do it differently (some do the
updates to tools and some don't).
I also would like to hear suggestions from Dave and Ingo on this.

Best Regards,
Elena.