Skip to contentSkip to conversation

x86/sev: Fix operator precedence in GHCB_MSR_VMPL_REQ_LEVEL macro

PATCH Superseded Seongmanlee 2 participants 2 messages May 10, 2025 – May 11, 2025 x86

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/sev: Fix operator precedence in GHCB_MSR_VMPL_REQ_LEVEL macro

From: leonardo-leecaprio <[email protected]>

The GHCB_MSR_VMPL_REQ_LEVEL macro lacked parentheses around the bitmask expression, causing the shift operation to bind too early. As a result, when switching to VMPL2 from VMPL1 (e.g., GHCB_MSR_VMPL_REQ_LEVEL(1)), incorrect values such as 0x000000016 were generated instead of the intended 0x100000016.

This patch fixes the precedence issue by grouping the masked value before applying the shift.

---
 arch/x86/include/asm/sev-common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/sev-common.h +1 -1
index acb85b934..0020d77a0 100644
@@ -116,7 +116,7 @@ enum psc_op {
 #define GHCB_MSR_VMPL_REQ		0x016
 #define GHCB_MSR_VMPL_REQ_LEVEL(v)			\
 	/* GHCBData[39:32] */				\
-	(((u64)(v) & GENMASK_ULL(7, 0) << 32) |		\
+	((((u64)(v) & GENMASK_ULL(7, 0)) << 32) |	\
 	/* GHCBDdata[11:0] */				\
 	GHCB_MSR_VMPL_REQ)
 
Signature · 1 line
2.39.5 (Apple Git-154)
maintainer
#1 lore raw

+ Tom.

Quoted 9 lines · Seongmanlee

From: leonardo-leecaprio <[email protected]>

The GHCB_MSR_VMPL_REQ_LEVEL macro lacked parentheses around the bitmask expression, causing the shift operation to bind too early. As a result, when switching to VMPL2 from VMPL1 (e.g., GHCB_MSR_VMPL_REQ_LEVEL(1)), incorrect values such as 0x000000016 were generated instead of the intended 0x100000016.

This patch fixes the precedence issue by grouping the masked value

Avoid having "This patch" or "This commit" in the commit message. It is tautologically useless.

Also, do

$ git grep 'This patch' Documentation/process

for more details.

Quoted 2 lines

before applying the shift.

Fixes 34ff65901735 ("x86/sev: Use kernel provided SVSM Calling Areas")
Quoted 1 line

Please use your real name.

Quoted 9 lines
---
 arch/x86/include/asm/sev-common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/sev-common.h +0 -0
index acb85b934..0020d77a0 100644

arch/x86/include/asm/sev-common.h enum psc_op { · line 122

Quoted 8 lines
arch/x86/include/asm/sev-common.h +1 -1
@@ -116,7 +116,7 @@ enum psc_op {
 #define GHCB_MSR_VMPL_REQ		0x016
 #define GHCB_MSR_VMPL_REQ_LEVEL(v)			\
 	/* GHCBData[39:32] */				\
-	(((u64)(v) & GENMASK_ULL(7, 0) << 32) |		\
+	((((u64)(v) & GENMASK_ULL(7, 0)) << 32) |	\
 	/* GHCBDdata[11:0] */				\
 	GHCB_MSR_VMPL_REQ)
 

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette