Skip to contentSkip to conversation

x86/amd: Fix DE_CFG truncation in amd_check_zenbleed()

PATCH In review Andrew Cooper 2 participants 3 messages Jul 28, 2023 – Jul 31, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/amd: Fix DE_CFG truncation in amd_check_zenbleed()

This line:

	val &= ~chickenbit;

ends up truncating val to 32 bits, and turning off various errata workarounds in Zen2 systems.

Fixes f91c5ea97067 ("x86/amd: Mitigations for Zenbleed")

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

The choice is between int or uint64_t. This is one case where the insistence on using unsigned int as a default data type is genuinely unsafe.

---
 xen/arch/x86/cpu/amd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/x86/cpu/amd.c +2 -1
index 3ed06f670491..089038bf62c5 100644
@@ -909,8 +909,9 @@ void __init detect_zen2_null_seg_behaviour(void)
 void amd_check_zenbleed(void)
 {
 	const struct cpu_signature *sig = &this_cpu(cpu_sig);
-	unsigned int good_rev, chickenbit = (1 << 9);
+	unsigned int good_rev;
 	uint64_t val, old_val;
+	int chickenbit = (1 << 9);
 
 	/*
 	 * If we're virtualised, we can't do family/model checks safely, and
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Andrew Cooper

This line:

	val &= ~chickenbit;

ends up truncating val to 32 bits, and turning off various errata workarounds in Zen2 systems.

Fixes f91c5ea97067 ("x86/amd: Mitigations for Zenbleed")
Quoted 7 lines

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

The choice is between int or uint64_t. This is one case where the insistence on using unsigned int as a default data type is genuinely unsafe.

It is not. The (unsigned) type should have been wide enough. From a Misra perspective I'm pretty sure we would be better off using uint64_t. But in the interest of getting this in without a lot of discussion I'll leave the decision up to you; either way

Jan

#2 lore raw
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Andrew Cooper

This line:

	val &= ~chickenbit;

ends up truncating val to 32 bits, and turning off various errata workarounds in Zen2 systems.

Fixes f91c5ea97067 ("x86/amd: Mitigations for Zenbleed")

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

Quoted 7 lines
Quoted 2 lines

The choice is between int or uint64_t. This is one case where the insistence on using unsigned int as a default data type is genuinely unsafe.

It is not. The (unsigned) type should have been wide enough. From a Misra perspective I'm pretty sure we would be better off using uint64_t. But in the interest of getting this in without a lot of discussion I'll leave the decision up to you; either way

Roger asked for uint64_t too so I'll go with that.  Thanks.

~Andrew