Skip to contentSkip to conversation

x86/xen: Fix __xen_hypercall_setfunc

PATCH Applied Jason Andryuk 4 participants 6 messages Apr 10, 2025 – Apr 11, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/xen: Fix __xen_hypercall_setfunc

Hypercall detection is failing with xen_hypercall_intel() chosen even on an AMD processor. Looking at the disassembly, the call to xen_get_vendor() was removed.

The check for boot_cpu_has(X86_FEATURE_CPUID) was used as a proxy for the x86_vendor having been set. When CONFIG_X86_REQUIRED_FEATURE_CPUID=y (the default value), DCE eliminates the call to xen_get_vendor(). An uninitialized value 0 means X86_VENDOR_INTEL, so the Intel function is always returned.

Remove the if and always call xen_get_vendor() to avoid this issue.

Fixes 3d37d9396eb3 ("x86/cpufeatures: Add {REQUIRED,DISABLED} feature configs")

---
I think the Fixes is correct in that it default enables requiring the feature. There were a lot of other changes to how headers were generated as well.

---
 arch/x86/xen/enlighten.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
arch/x86/xen/enlighten.c +1 -6
index 43dcd8c7badc..6a5cae915eb1 100644
@@ -100,10 +100,6 @@ noinstr void *__xen_hypercall_setfunc(void)
 	void (*func)(void);
 
 	/*
-	 * Xen is supported only on CPUs with CPUID, so testing for
-	 * X86_FEATURE_CPUID is a test for early_cpu_init() having been
-	 * run.
-	 *
 	 * Note that __xen_hypercall_setfunc() is noinstr only due to a nasty
 	 * dependency chain: it is being called via the xen_hypercall static
 	 * call when running as a PVH or HVM guest. Hypercalls need to be
@@ -115,8 +111,7 @@ noinstr void *__xen_hypercall_setfunc(void)
 	 */
 	instrumentation_begin();
 
-	if (!boot_cpu_has(X86_FEATURE_CPUID))
-		xen_get_vendor();
+	xen_get_vendor();
 
 	if ((boot_cpu_data.x86_vendor == X86_VENDOR_AMD ||
 	     boot_cpu_data.x86_vendor == X86_VENDOR_HYGON))
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Jason Andryuk

Hypercall detection is failing with xen_hypercall_intel() chosen even on an AMD processor. Looking at the disassembly, the call to xen_get_vendor() was removed.

The check for boot_cpu_has(X86_FEATURE_CPUID) was used as a proxy for the x86_vendor having been set. When CONFIG_X86_REQUIRED_FEATURE_CPUID=y (the default value), DCE eliminates the call to xen_get_vendor(). An uninitialized value 0 means X86_VENDOR_INTEL, so the Intel function is always returned.

Quoted 5 lines

Remove the if and always call xen_get_vendor() to avoid this issue.

Fixes 3d37d9396eb3 ("x86/cpufeatures: Add {REQUIRED,DISABLED} feature configs")

Juergen

Acked-by
#2 lore raw
Quoted 11 lines · Juergen Gross
Quoted 10 lines · Jason Andryuk

Hypercall detection is failing with xen_hypercall_intel() chosen even on an AMD processor. Looking at the disassembly, the call to xen_get_vendor() was removed.

The check for boot_cpu_has(X86_FEATURE_CPUID) was used as a proxy for the x86_vendor having been set. When CONFIG_X86_REQUIRED_FEATURE_CPUID=y (the default value), DCE eliminates the call to xen_get_vendor(). An uninitialized value 0 means X86_VENDOR_INTEL, so the Intel function is always returned.

Quoted 7 lines
Quoted 5 lines

Remove the if and always call xen_get_vendor() to avoid this issue.

Fixes 3d37d9396eb3 ("x86/cpufeatures: Add {REQUIRED,DISABLED} feature configs")

Wanna merge this via the Xen tree, or should it go to x86/urgent?

The bug was *caused* by the x86 tree so we'd be glad to merge, but your call.

If you'll merge it:

Thanks,

Ingo

maintainer
#3 lore raw
Quoted 20 lines · Ingo Molnar
Quoted 17 lines · Juergen Gross
Quoted 15 lines · Jason Andryuk

Hypercall detection is failing with xen_hypercall_intel() chosen even on an AMD processor. Looking at the disassembly, the call to xen_get_vendor() was removed.

The check for boot_cpu_has(X86_FEATURE_CPUID) was used as a proxy for the x86_vendor having been set. When CONFIG_X86_REQUIRED_FEATURE_CPUID=y (the default value), DCE eliminates the call to xen_get_vendor(). An uninitialized value 0 means X86_VENDOR_INTEL, so the Intel function is always returned.

Remove the if and always call xen_get_vendor() to avoid this issue.

Fixes 3d37d9396eb3 ("x86/cpufeatures: Add {REQUIRED,DISABLED} feature configs")
Quoted 6 lines
Quoted 1 line

Wanna merge this via the Xen tree, or should it go to x86/urgent?

The bug was *caused* by the x86 tree so we'd be glad to merge, but your call.

x86/urgent is fine for me.

Juergen

Applied
#4 lore raw
Quoted 21 lines · Jürgen Groß
Quoted 20 lines · Ingo Molnar
Quoted 17 lines · Juergen Gross
Quoted 15 lines · Jason Andryuk

Hypercall detection is failing with xen_hypercall_intel() chosen even on an AMD processor. Looking at the disassembly, the call to xen_get_vendor() was removed.

The check for boot_cpu_has(X86_FEATURE_CPUID) was used as a proxy for the x86_vendor having been set. When CONFIG_X86_REQUIRED_FEATURE_CPUID=y (the default value), DCE eliminates the call to xen_get_vendor(). An uninitialized value 0 means X86_VENDOR_INTEL, so the Intel function is always returned.

Remove the if and always call xen_get_vendor() to avoid this issue.

Fixes 3d37d9396eb3 ("x86/cpufeatures: Add {REQUIRED,DISABLED} feature configs")
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Wanna merge this via the Xen tree, or should it go to x86/urgent?

The bug was *caused* by the x86 tree so we'd be glad to merge, but your call.

x86/urgent is fine for me.

Applied, thanks!

Ingo

merge bot Applied
#5 lore raw

[tip: x86/urgent] x86/xen: Fix __xen_hypercall_setfunc()

In reply to Jason Andryuk
The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     164a9f712fa53e4c92b2a435bb071a5be0c31dbc
Gitweb:        https://git.kernel.org/tip/164a9f712fa53e4c92b2a435bb071a5be0c31dbc
Author:        Jason Andryuk <[email protected]>
AuthorDate:    Thu, 10 Apr 2025 15:31:05 -04:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 11 Apr 2025 11:39:50 +02:00

x86/xen: Fix __xen_hypercall_setfunc()

Hypercall detection is failing with xen_hypercall_intel() chosen even on an AMD processor. Looking at the disassembly, the call to xen_get_vendor() was removed.

The check for boot_cpu_has(X86_FEATURE_CPUID) was used as a proxy for the x86_vendor having been set.

When CONFIG_X86_REQUIRED_FEATURE_CPUID=y (the default value), DCE eliminates the call to xen_get_vendor(). An uninitialized value 0 means X86_VENDOR_INTEL, so the Intel function is always returned.

Remove the if and always call xen_get_vendor() to avoid this issue.

Fixes 3d37d9396eb3 ("x86/cpufeatures: Add {REQUIRED,DISABLED} feature configs")
Cc Boris Ostrovsky <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc "Xin Li (Intel)" <[email protected]>
---
 arch/x86/xen/enlighten.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
arch/x86/xen/enlighten.c +1 -6
index 1b7710b..53282dc 100644
@@ -103,10 +103,6 @@ noinstr void *__xen_hypercall_setfunc(void)
 	void (*func)(void);
 
 	/*
-	 * Xen is supported only on CPUs with CPUID, so testing for
-	 * X86_FEATURE_CPUID is a test for early_cpu_init() having been
-	 * run.
-	 *
 	 * Note that __xen_hypercall_setfunc() is noinstr only due to a nasty
 	 * dependency chain: it is being called via the xen_hypercall static
 	 * call when running as a PVH or HVM guest. Hypercalls need to be
@@ -118,8 +114,7 @@ noinstr void *__xen_hypercall_setfunc(void)
 	 */
 	instrumentation_begin();
 
-	if (!boot_cpu_has(X86_FEATURE_CPUID))
-		xen_get_vendor();
+	xen_get_vendor();
 
 	if ((boot_cpu_data.x86_vendor == X86_VENDOR_AMD ||
 	     boot_cpu_data.x86_vendor == X86_VENDOR_HYGON))