[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/2] x86: guard synthetic feature and bug enumerators


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Jason Andryuk <jason.andryuk@xxxxxxx>
  • Date: Fri, 10 Oct 2025 20:30:42 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uHPTNJkGoogf4KZ3qDka5bjf+WbdE69cYaeQ2wBDJYY=; b=MmrXGvWpUW8RiHI4Y2W4Kh3AprtAtjroww07tWLF7bLQ///+kNxSB1G8AQ2Y3dCube4P+Np1tB7h1W5bejYYlyK2+QGIbQYSuYfyaQ6jR4El0iLCFiZgAs6BNBfboOiSSlQcGp7FH98Ucm3iOGAYlsDJq14W4uLKMxKU46971W0LU/mtOCqhDlF+JGi9LVFmttxZ61r2oBeTnqxG+Gyg+F4BDjuDoywCmXjMbB0z7aYvIUd90ug1X0W1R3RtTuSK0oGU/N7n05AF3pNPrFN89SqXpbGC8MaDHcqoWn8M5mKip239ZJ1+nx+samXpsyQKi7tyasawh30q+vdDtGeQJg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ew0WLqiJdLAGZ2+urJojDChHEO/Ep3+1orDnJNJD74fmblnV+PiGeWtGOVLnLNzW+5pGEyc1tWqqMLLCABSbQ8vwk7Tz/5oaZP806Wkhdcj2K3SKe0ZinqaKOBXAyrQFphy2JoOMFF+OptbP/JQFdD1fam2TmwEtU3tb8SV+Zjpwm5eeo1C1/ro8+Svu8v/1clUIHWjooTWeLiE0TOjW+/YCsFJlY8xc4guRy5an4AnnNPCg29gKIFP1GHkprdzX3r5PZaQo30ILD04uFuZj2+4YK05LKzZvdcnSsnVtZ8utAXLcxMwLSFoSGpDViVp9aXgwSdSlwWAAjf0EQIEeUA==
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Sat, 11 Oct 2025 00:31:10 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 2025-10-08 01:56, Jan Beulich wrote:
On 07.10.2025 21:38, Jason Andryuk wrote:
On 2025-10-07 08:22, Jan Beulich wrote:
On 30.09.2025 01:36, Jason Andryuk wrote:
On 2025-09-25 06:48, Jan Beulich wrote:
--- a/xen/arch/x86/include/asm/spec_ctrl.h
+++ b/xen/arch/x86/include/asm/spec_ctrl.h
@@ -73,7 +73,7 @@ static always_inline void spec_ctrl_new_
/* (ab)use alternative_input() to specify clobbers. */
        alternative_input("", "DO_OVERWRITE_RSB xu=%=", X86_BUG_IBPB_NO_RET,
-                      : "rax", "rcx");
+                      "i" (0) : "rax", "rcx");

"i" (0) is to work around the trailing comma in alternative_input() and
does nothing?

Yes. If more such "uses" appeared, we may want to introduce some kind of
abstraction.

Thanks for confirming.

Reviewed-by: Jason Andryuk <jason.andryuk@xxxxxxx>

Thanks.

Though I also wondered if just #define X86_BUG_MAX/X86_SYNTH_MAX
combined with a BUILD_BUG_ON might be good enough.  Your approach avoids
the extra define but is more complicated.  Anyway, just a thought.

How would that end up simplifying things? IOW what would the BUILD_BUG_ON()
look like that you're thinking about? After all X86_{SYNTH,BUG}_MAX aren't
meaningfully different from X86_NR_{SYNTH,BUG}.

Originally, I was thinking something like
 XEN_CPUFEATURE(PDX_COMPRESSION,   X86_SYNTH(31)) /* PDX compression */
+#define X86_SYNTH_MAX 31 /* Bump when adding flags */

and:
BUILD_BUG_ON( ((X86_SYNTH_MAX / 32) + 1) > X86_NR_SYNTH )

Not automated, but adding a new flag should make it obvious X86_SYNTH_MAX should increase.

But as you point out the redundancy of X86_{SYNTH,BUG}_MAX and X86_NR_{SYNTH,BUG}. But we could re-arrange to make X86_NR_{SYNTH,BUG} calculated from X86_{SYNTH,BUG}_MAX like below.

Again, it's not automated, but it should make it harder to miss increasing the value.

Regards,
Jason

diff --git i/xen/arch/x86/include/asm/cpufeatures.h w/xen/arch/x86/include/asm/cpufeatures.h
index 0a98676c16..724eb1599f 100644
--- i/xen/arch/x86/include/asm/cpufeatures.h
+++ w/xen/arch/x86/include/asm/cpufeatures.h
@@ -7,7 +7,6 @@
 #define FSCAPINTS FEATURESET_NR_ENTRIES

 /* Synthetic words follow the featureset words. */
-#define X86_NR_SYNTH 1
 #define X86_SYNTH(x) (FSCAPINTS * 32 + (x))

 /* Synthetic features */
@@ -43,9 +42,10 @@ XEN_CPUFEATURE(IBPB_ENTRY_PV, X86_SYNTH(28)) /* MSR_PRED_CMD used by Xen for XEN_CPUFEATURE(IBPB_ENTRY_HVM, X86_SYNTH(29)) /* MSR_PRED_CMD used by Xen for HVM */ XEN_CPUFEATURE(USE_VMCALL, X86_SYNTH(30)) /* Use VMCALL instead of VMMCALL */
 XEN_CPUFEATURE(PDX_COMPRESSION,   X86_SYNTH(31)) /* PDX compression */
+#define X86_SYNTH_MAX             31 /* Bump when adding new flags. */
+#define X86_NR_SYNTH              ((X86_SYNTH_MAX / 32) + 1)

 /* Bug words follow the synthetic words. */
-#define X86_NR_BUG 1
 #define X86_BUG(x) ((FSCAPINTS + X86_NR_SYNTH) * 32 + (x))

#define X86_BUG_FPU_PTRS X86_BUG( 0) /* (F)X{SAVE,RSTOR} doesn't save/restore FOP/FIP/FDP. */ @@ -62,6 +62,8 @@ XEN_CPUFEATURE(PDX_COMPRESSION, X86_SYNTH(31)) /* PDX compression */ #define X86_SPEC_BHB_TSX X86_BUG(19) /* Use clear_bhb_tsx for BHI mitigation. */ #define X86_SPEC_BHB_LOOPS X86_BUG(20) /* Use clear_bhb_loops for BHI mitigation.*/ #define X86_SPEC_BHB_LOOPS_LONG X86_BUG(21) /* Upgrade clear_bhb_loops to the "long" sequence. */
+#define X86_BUX_MAX               21 /* Bump when adding new flags. */
+#define X86_NR_BUG                ((X86_BUG_MAX / 32) + 1)

 /* Total number of capability words, inc synth and bug words. */
#define NCAPINTS (FSCAPINTS + X86_NR_SYNTH + X86_NR_BUG) /* N 32-bit words worth of info */




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.