public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] x86: Disable OSXSAVE related features [BZ #27605]
@ 2021-03-19 13:27 H.J. Lu
  2021-03-19 21:42 ` DJ Delorie
  0 siblings, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2021-03-19 13:27 UTC (permalink / raw)
  To: libc-alpha

If OSXSAVE is disabled by glibc tunables, disable features which depend
on OSXSAVE.
---
 sysdeps/x86/cpu-features.c | 40 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
index d7248cbb45..804e9a879b 100644
--- a/sysdeps/x86/cpu-features.c
+++ b/sysdeps/x86/cpu-features.c
@@ -654,6 +654,46 @@ no_cpuid:
 
 #if HAVE_TUNABLES
   TUNABLE_GET (hwcaps, tunable_val_t *, TUNABLE_CALLBACK (set_hwcaps));
+
+  if (!CPU_FEATURE_USABLE_P (cpu_features, OSXSAVE))
+    {
+      /* These features are usable only if OSXSAVE is usable.  */
+      cpu_features->xsave_state_size = 0;
+      CPU_FEATURE_UNSET (cpu_features, AVX);
+      CPU_FEATURE_UNSET (cpu_features, AVX2);
+      CPU_FEATURE_UNSET (cpu_features, AVX_VNNI);
+      CPU_FEATURE_UNSET (cpu_features, FMA);
+      CPU_FEATURE_UNSET (cpu_features, VAES);
+      CPU_FEATURE_UNSET (cpu_features, VPCLMULQDQ);
+      CPU_FEATURE_UNSET (cpu_features, XOP);
+      CPU_FEATURE_UNSET (cpu_features, F16C);
+      CPU_FEATURE_UNSET (cpu_features, AVX512F);
+      CPU_FEATURE_UNSET (cpu_features, AVX512CD);
+      CPU_FEATURE_UNSET (cpu_features, AVX512ER);
+      CPU_FEATURE_UNSET (cpu_features, AVX512PF);
+      CPU_FEATURE_UNSET (cpu_features, AVX512VL);
+      CPU_FEATURE_UNSET (cpu_features, AVX512DQ);
+      CPU_FEATURE_UNSET (cpu_features, AVX512BW);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_4FMAPS);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_4VNNIW);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_BITALG);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_IFMA);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VBMI);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VBMI2);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VNNI);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VPOPCNTDQ);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VP2INTERSECT);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_BF16);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_FP16);
+      CPU_FEATURE_UNSET (cpu_features, AMX_BF16);
+      CPU_FEATURE_UNSET (cpu_features, AMX_TILE);
+      CPU_FEATURE_UNSET (cpu_features, AMX_INT8);
+      CPU_FEATURE_UNSET (cpu_features, XSAVE);
+      CPU_FEATURE_UNSET (cpu_features, XSAVEOPT);
+      CPU_FEATURE_UNSET (cpu_features, XSAVEC);
+      CPU_FEATURE_UNSET (cpu_features, XGETBV_ECX_1);
+      CPU_FEATURE_UNSET (cpu_features, XFD);
+    }
 #elif defined SHARED
   /* Reuse dl_platform, dl_hwcap and dl_hwcap_mask for x86.  The
      glibc.cpu.hwcap_mask tunable is initialized already, so no
-- 
2.30.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] x86: Disable OSXSAVE related features [BZ #27605]
  2021-03-19 13:27 [PATCH] x86: Disable OSXSAVE related features [BZ #27605] H.J. Lu
@ 2021-03-19 21:42 ` DJ Delorie
  2021-03-19 22:22   ` [PATCH v2] " H.J. Lu
  0 siblings, 1 reply; 8+ messages in thread
From: DJ Delorie @ 2021-03-19 21:42 UTC (permalink / raw)
  To: H.J. Lu; +Cc: libc-alpha

"H.J. Lu" <hjl.tools@gmail.com> writes:
> If OSXSAVE is disabled by glibc tunables, disable features which depend
> on OSXSAVE.

This one seems to ignore -XSAVE, both on an 11th gen (-XSAVE,-XSAVEC ->
xsave()) and on 4th (just -XSAVE).  Is this patch supposed to be used
with the previous patch, or standalone?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2] x86: Disable OSXSAVE related features [BZ #27605]
  2021-03-19 21:42 ` DJ Delorie
@ 2021-03-19 22:22   ` H.J. Lu
  2021-03-20  0:06     ` [PATCH v3] x86: Properly disable XSAVE " H.J. Lu
  0 siblings, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2021-03-19 22:22 UTC (permalink / raw)
  To: DJ Delorie; +Cc: GNU C Library

[-- Attachment #1: Type: text/plain, Size: 451 bytes --]

On Fri, Mar 19, 2021 at 2:42 PM DJ Delorie <dj@redhat.com> wrote:
>
> "H.J. Lu" <hjl.tools@gmail.com> writes:
> > If OSXSAVE is disabled by glibc tunables, disable features which depend
> > on OSXSAVE.
>
> This one seems to ignore -XSAVE, both on an 11th gen (-XSAVE,-XSAVEC ->
> xsave()) and on 4th (just -XSAVE).  Is this patch supposed to be used
> with the previous patch, or standalone?
>

Fixed.  Here is the v2 patch.  OK for master?

-- 
H.J.

[-- Attachment #2: v2-0001-x86-Disable-OSXSAVE-related-features-BZ-27605.patch --]
[-- Type: text/x-patch, Size: 3718 bytes --]

From 36e3a13647d3915d307281334d1cba13ab975a1a Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Fri, 19 Mar 2021 06:15:37 -0700
Subject: [PATCH v2] x86: Disable OSXSAVE related features [BZ #27605]

1. Support GLIBC_TUNABLES=glibc.cpu.hwcaps=-XSAVE.
2. If OSXSAVE is disabled by glibc tunables, disable features which
depend on OSXSAVE.
3. Clear xsave_state_size if both XSAVE and XSAVEC aren't usable.
---
 sysdeps/x86/cpu-features.c | 46 ++++++++++++++++++++++++++++++++++++++
 sysdeps/x86/cpu-tunables.c |  1 +
 2 files changed, 47 insertions(+)

diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
index d7248cbb45..a9c62b4231 100644
--- a/sysdeps/x86/cpu-features.c
+++ b/sysdeps/x86/cpu-features.c
@@ -654,6 +654,52 @@ no_cpuid:
 
 #if HAVE_TUNABLES
   TUNABLE_GET (hwcaps, tunable_val_t *, TUNABLE_CALLBACK (set_hwcaps));
+
+  if (!CPU_FEATURE_USABLE_P (cpu_features, OSXSAVE))
+    {
+      /* These features are usable only if OSXSAVE is usable.  */
+      CPU_FEATURE_UNSET (cpu_features, AVX);
+      CPU_FEATURE_UNSET (cpu_features, AVX2);
+      CPU_FEATURE_UNSET (cpu_features, AVX_VNNI);
+      CPU_FEATURE_UNSET (cpu_features, FMA);
+      CPU_FEATURE_UNSET (cpu_features, VAES);
+      CPU_FEATURE_UNSET (cpu_features, VPCLMULQDQ);
+      CPU_FEATURE_UNSET (cpu_features, XOP);
+      CPU_FEATURE_UNSET (cpu_features, F16C);
+      CPU_FEATURE_UNSET (cpu_features, AVX512F);
+      CPU_FEATURE_UNSET (cpu_features, AVX512CD);
+      CPU_FEATURE_UNSET (cpu_features, AVX512ER);
+      CPU_FEATURE_UNSET (cpu_features, AVX512PF);
+      CPU_FEATURE_UNSET (cpu_features, AVX512VL);
+      CPU_FEATURE_UNSET (cpu_features, AVX512DQ);
+      CPU_FEATURE_UNSET (cpu_features, AVX512BW);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_4FMAPS);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_4VNNIW);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_BITALG);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_IFMA);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VBMI);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VBMI2);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VNNI);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VPOPCNTDQ);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VP2INTERSECT);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_BF16);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_FP16);
+      CPU_FEATURE_UNSET (cpu_features, AMX_BF16);
+      CPU_FEATURE_UNSET (cpu_features, AMX_TILE);
+      CPU_FEATURE_UNSET (cpu_features, AMX_INT8);
+      CPU_FEATURE_UNSET (cpu_features, XSAVE);
+      CPU_FEATURE_UNSET (cpu_features, XSAVEOPT);
+      CPU_FEATURE_UNSET (cpu_features, XSAVEC);
+      CPU_FEATURE_UNSET (cpu_features, XGETBV_ECX_1);
+      CPU_FEATURE_UNSET (cpu_features, XFD);
+
+      CPU_FEATURE_UNSET (cpu_features, FMA4);
+    }
+
+  /* Clear xsave_state_size if both XSAVE and XSAVEC aren't usable.  */
+  if (!CPU_FEATURE_USABLE_P (cpu_features, XSAVE)
+      && !CPU_FEATURE_USABLE_P (cpu_features, XSAVEC))
+    cpu_features->xsave_state_size = 0;
 #elif defined SHARED
   /* Reuse dl_platform, dl_hwcap and dl_hwcap_mask for x86.  The
      glibc.cpu.hwcap_mask tunable is initialized already, so no
diff --git a/sysdeps/x86/cpu-tunables.c b/sysdeps/x86/cpu-tunables.c
index 126896f41b..61b05e5b1d 100644
--- a/sysdeps/x86/cpu-tunables.c
+++ b/sysdeps/x86/cpu-tunables.c
@@ -168,6 +168,7 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
 	      CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, MOVBE, 5);
 	      CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, SHSTK, 5);
 	      CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, SSSE3, 5);
+	      CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, XSAVE, 5);
 	    }
 	  break;
 	case 6:
-- 
2.30.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3] x86: Properly disable XSAVE related features [BZ #27605]
  2021-03-19 22:22   ` [PATCH v2] " H.J. Lu
@ 2021-03-20  0:06     ` H.J. Lu
  2021-03-22 18:32       ` DJ Delorie
  0 siblings, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2021-03-20  0:06 UTC (permalink / raw)
  To: DJ Delorie; +Cc: GNU C Library

[-- Attachment #1: Type: text/plain, Size: 647 bytes --]

On Fri, Mar 19, 2021 at 3:22 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Fri, Mar 19, 2021 at 2:42 PM DJ Delorie <dj@redhat.com> wrote:
> >
> > "H.J. Lu" <hjl.tools@gmail.com> writes:
> > > If OSXSAVE is disabled by glibc tunables, disable features which depend
> > > on OSXSAVE.
> >
> > This one seems to ignore -XSAVE, both on an 11th gen (-XSAVE,-XSAVEC ->
> > xsave()) and on 4th (just -XSAVE).  Is this patch supposed to be used
> > with the previous patch, or standalone?
> >
>
> Fixed.  Here is the v2 patch.  OK for master?
>

Here is the v3 patch to disable all XSAVE related features if both
XSAVE and XSAVEC aren't usable.

-- 
H.J.

[-- Attachment #2: v3-0001-x86-Properly-disable-XSAVE-related-features-BZ-27.patch --]
[-- Type: text/x-patch, Size: 3855 bytes --]

From 7ed30c76a7e20f77eb1b65f9b38c905819ad1880 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Fri, 19 Mar 2021 06:15:37 -0700
Subject: [PATCH v3] x86: Properly disable XSAVE related features [BZ #27605]

1. Support GLIBC_TUNABLES=glibc.cpu.hwcaps=-XSAVE.
2. Disable all features which depend on XSAVE:
   a. If OSXSAVE is disabled by glibc tunables.  Or
   b. If both XSAVE and XSAVEC aren't usable.
---
 sysdeps/x86/cpu-features.c | 55 ++++++++++++++++++++++++++++++++++++++
 sysdeps/x86/cpu-tunables.c |  1 +
 2 files changed, 56 insertions(+)

diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
index d7248cbb45..e99e67f34d 100644
--- a/sysdeps/x86/cpu-features.c
+++ b/sysdeps/x86/cpu-features.c
@@ -654,6 +654,61 @@ no_cpuid:
 
 #if HAVE_TUNABLES
   TUNABLE_GET (hwcaps, tunable_val_t *, TUNABLE_CALLBACK (set_hwcaps));
+
+  bool disable_xsave_features = false;
+
+  if (!CPU_FEATURE_USABLE_P (cpu_features, OSXSAVE))
+    {
+      /* These features are usable only if OSXSAVE is usable.  */
+      CPU_FEATURE_UNSET (cpu_features, XSAVE);
+      CPU_FEATURE_UNSET (cpu_features, XSAVEOPT);
+      CPU_FEATURE_UNSET (cpu_features, XSAVEC);
+      CPU_FEATURE_UNSET (cpu_features, XGETBV_ECX_1);
+      CPU_FEATURE_UNSET (cpu_features, XFD);
+
+      disable_xsave_features = true;
+    }
+
+  if (disable_xsave_features
+      || (!CPU_FEATURE_USABLE_P (cpu_features, XSAVE)
+	  && !CPU_FEATURE_USABLE_P (cpu_features, XSAVEC)))
+    {
+      /* Clear xsave_state_size if both XSAVE and XSAVEC aren't usable.  */
+      cpu_features->xsave_state_size = 0;
+
+      CPU_FEATURE_UNSET (cpu_features, AVX);
+      CPU_FEATURE_UNSET (cpu_features, AVX2);
+      CPU_FEATURE_UNSET (cpu_features, AVX_VNNI);
+      CPU_FEATURE_UNSET (cpu_features, FMA);
+      CPU_FEATURE_UNSET (cpu_features, VAES);
+      CPU_FEATURE_UNSET (cpu_features, VPCLMULQDQ);
+      CPU_FEATURE_UNSET (cpu_features, XOP);
+      CPU_FEATURE_UNSET (cpu_features, F16C);
+      CPU_FEATURE_UNSET (cpu_features, AVX512F);
+      CPU_FEATURE_UNSET (cpu_features, AVX512CD);
+      CPU_FEATURE_UNSET (cpu_features, AVX512ER);
+      CPU_FEATURE_UNSET (cpu_features, AVX512PF);
+      CPU_FEATURE_UNSET (cpu_features, AVX512VL);
+      CPU_FEATURE_UNSET (cpu_features, AVX512DQ);
+      CPU_FEATURE_UNSET (cpu_features, AVX512BW);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_4FMAPS);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_4VNNIW);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_BITALG);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_IFMA);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VBMI);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VBMI2);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VNNI);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VPOPCNTDQ);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VP2INTERSECT);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_BF16);
+      CPU_FEATURE_UNSET (cpu_features, AVX512_FP16);
+      CPU_FEATURE_UNSET (cpu_features, AMX_BF16);
+      CPU_FEATURE_UNSET (cpu_features, AMX_TILE);
+      CPU_FEATURE_UNSET (cpu_features, AMX_INT8);
+
+      CPU_FEATURE_UNSET (cpu_features, FMA4);
+    }
+
 #elif defined SHARED
   /* Reuse dl_platform, dl_hwcap and dl_hwcap_mask for x86.  The
      glibc.cpu.hwcap_mask tunable is initialized already, so no
diff --git a/sysdeps/x86/cpu-tunables.c b/sysdeps/x86/cpu-tunables.c
index 126896f41b..61b05e5b1d 100644
--- a/sysdeps/x86/cpu-tunables.c
+++ b/sysdeps/x86/cpu-tunables.c
@@ -168,6 +168,7 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
 	      CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, MOVBE, 5);
 	      CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, SHSTK, 5);
 	      CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, SSSE3, 5);
+	      CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, XSAVE, 5);
 	    }
 	  break;
 	case 6:
-- 
2.30.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] x86: Properly disable XSAVE related features [BZ #27605]
  2021-03-20  0:06     ` [PATCH v3] x86: Properly disable XSAVE " H.J. Lu
@ 2021-03-22 18:32       ` DJ Delorie
  2021-03-22 18:38         ` H.J. Lu
  0 siblings, 1 reply; 8+ messages in thread
From: DJ Delorie @ 2021-03-22 18:32 UTC (permalink / raw)
  To: H.J. Lu; +Cc: libc-alpha

"H.J. Lu" <hjl.tools@gmail.com> writes:
> Here is the v3 patch to disable all XSAVE related features if both
> XSAVE and XSAVEC aren't usable.

This version passes all my tests, on both cpus.  Thanks!


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] x86: Properly disable XSAVE related features [BZ #27605]
  2021-03-22 18:32       ` DJ Delorie
@ 2021-03-22 18:38         ` H.J. Lu
  2021-03-22 18:42           ` DJ Delorie
  0 siblings, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2021-03-22 18:38 UTC (permalink / raw)
  To: DJ Delorie; +Cc: GNU C Library

On Mon, Mar 22, 2021 at 11:32 AM DJ Delorie <dj@redhat.com> wrote:
>
> "H.J. Lu" <hjl.tools@gmail.com> writes:
> > Here is the v3 patch to disable all XSAVE related features if both
> > XSAVE and XSAVEC aren't usable.
>
> This version passes all my tests, on both cpus.  Thanks!
>

Are there any objections or comments?

-- 
H.J.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] x86: Properly disable XSAVE related features [BZ #27605]
  2021-03-22 18:38         ` H.J. Lu
@ 2021-03-22 18:42           ` DJ Delorie
  2021-03-23 13:08             ` H.J. Lu
  0 siblings, 1 reply; 8+ messages in thread
From: DJ Delorie @ 2021-03-22 18:42 UTC (permalink / raw)
  To: H.J. Lu; +Cc: libc-alpha

"H.J. Lu" <hjl.tools@gmail.com> writes:
> Are there any objections or comments?

None from me.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] x86: Properly disable XSAVE related features [BZ #27605]
  2021-03-22 18:42           ` DJ Delorie
@ 2021-03-23 13:08             ` H.J. Lu
  0 siblings, 0 replies; 8+ messages in thread
From: H.J. Lu @ 2021-03-23 13:08 UTC (permalink / raw)
  To: DJ Delorie; +Cc: GNU C Library

On Mon, Mar 22, 2021 at 11:42 AM DJ Delorie <dj@redhat.com> wrote:
>
> "H.J. Lu" <hjl.tools@gmail.com> writes:
> > Are there any objections or comments?
>
> None from me.
>

If there are no objections, I will check this in on Thursday.

-- 
H.J.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-03-23 13:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-19 13:27 [PATCH] x86: Disable OSXSAVE related features [BZ #27605] H.J. Lu
2021-03-19 21:42 ` DJ Delorie
2021-03-19 22:22   ` [PATCH v2] " H.J. Lu
2021-03-20  0:06     ` [PATCH v3] x86: Properly disable XSAVE " H.J. Lu
2021-03-22 18:32       ` DJ Delorie
2021-03-22 18:38         ` H.J. Lu
2021-03-22 18:42           ` DJ Delorie
2021-03-23 13:08             ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).