git: d4676f565d9a - stable/13 - x86: test the right CPUID bit when checking for XSAVEOPT support

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 02 Apr 2024 15:18:15 UTC
The branch stable/13 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=d4676f565d9ad0ec76acb50a930d26dc27dd8ce7

commit d4676f565d9ad0ec76acb50a930d26dc27dd8ce7
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-03-25 10:34:06 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-04-02 15:18:00 +0000

    x86: test the right CPUID bit when checking for XSAVEOPT support
    
    (cherry picked from commit 960d151eaa1ecde109accc30ca0c3306551d8e58)
---
 sys/amd64/amd64/fpu.c | 5 ++++-
 sys/i386/i386/npx.c   | 8 ++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/sys/amd64/amd64/fpu.c b/sys/amd64/amd64/fpu.c
index 073c56e4902d..18330cb58d3c 100644
--- a/sys/amd64/amd64/fpu.c
+++ b/sys/amd64/amd64/fpu.c
@@ -260,9 +260,12 @@ fpurestore_fxrstor(void *addr)
 
 DEFINE_IFUNC(, void, fpusave, (void *))
 {
+	u_int cp[4];
+
 	if (!use_xsave)
 		return (fpusave_fxsave);
-	if ((cpu_stdext_feature & CPUID_EXTSTATE_XSAVEOPT) != 0) {
+	cpuid_count(0xd, 0x1, cp);
+	if ((cp[0] & CPUID_EXTSTATE_XSAVEOPT) != 0) {
 		return ((cpu_stdext_feature & CPUID_STDEXT_NFPUSG) != 0 ?
 		    fpusave_xsaveopt64 : fpusave_xsaveopt3264);
 	}
diff --git a/sys/i386/i386/npx.c b/sys/i386/i386/npx.c
index 628fab71499f..e7e8fc01fa6b 100644
--- a/sys/i386/i386/npx.c
+++ b/sys/i386/i386/npx.c
@@ -341,9 +341,13 @@ fpusave_fnsave(union savefpu *addr)
 
 DEFINE_IFUNC(, void, fpusave, (union savefpu *))
 {
-	if (use_xsave)
-		return ((cpu_stdext_feature & CPUID_EXTSTATE_XSAVEOPT) != 0 ?
+	u_int cp[4];
+
+	if (use_xsave) {
+		cpuid_count(0xd, 0x1, cp);
+		return ((cp[0] & CPUID_EXTSTATE_XSAVEOPT) != 0 ?
 		    fpusave_xsaveopt : fpusave_xsave);
+	}
 	if (cpu_fxsr)
 		return (fpusave_fxsave);
 	return (fpusave_fnsave);