Skip to content

Commit c064b53

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
x86/cpu/amd: Make the NODEID_MSR union actually work
A system with NODEID_MSR was reported to crash during early boot without any output. The reason is that the union which is used for accessing the bitfields in the MSR is written wrongly and the resulting executable code accesses the wrong part of the MSR data. As a consequence a later division by that value results in 0 and that result is used for another division as divisor, which obviously does not work well. The magic world of C, unions and bitfields: union { u64 bita : 3, bitb : 3; u64 all; } x; x.all = foo(); a = x.bita; b = x.bitb; results in the effective executable code of: a = b = x.bita; because bita and bitb are treated as union members and therefore both end up at bit offset 0. Wrapping the bitfield into an anonymous struct: union { struct { u64 bita : 3, bitb : 3; }; u64 all; } x; works like expected. Rework the NODEID_MSR union in exactly that way to cure the problem. Fixes: f7fb3b2 ("x86/cpu: Provide an AMD/HYGON specific topology parser") Reported-by: "kernelci.org bot" <[email protected]> Reported-by: Laura Nao <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Laura Nao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Closes: https://lore.kernel.org/all/[email protected]/
1 parent 1b3108f commit c064b53

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

arch/x86/kernel/cpu/topology_amd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ static bool parse_8000_001e(struct topo_scan *tscan, bool has_0xb)
121121

122122
static bool parse_fam10h_node_id(struct topo_scan *tscan)
123123
{
124-
struct {
125-
union {
124+
union {
125+
struct {
126126
u64 node_id : 3,
127127
nodes_per_pkg : 3,
128128
unused : 58;
129-
u64 msr;
130129
};
130+
u64 msr;
131131
} nid;
132132

133133
if (!boot_cpu_has(X86_FEATURE_NODEID_MSR))

0 commit comments

Comments
 (0)