git: 960d151eaa1e - main - x86: test the right CPUID bit when checking for XSAVEOPT support

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 26 Mar 2024 02:09:26 UTC
The branch main has been updated by kib:

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

commit 960d151eaa1ecde109accc30ca0c3306551d8e58
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-03-25 10:34:06 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-03-26 02:01:30 +0000

    x86: test the right CPUID bit when checking for XSAVEOPT support
    
    Reviewed by:    emaste
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D44497
---
 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 83bcc8f0776d..dcc6ff1a03a8 100644
--- a/sys/amd64/amd64/fpu.c
+++ b/sys/amd64/amd64/fpu.c
@@ -233,9 +233,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 25c760ca55e7..16ad7a96ab35 100644
--- a/sys/i386/i386/npx.c
+++ b/sys/i386/i386/npx.c
@@ -315,9 +315,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);