x86/cpu/amd: Make the NODEID_MSR union actually work
authorThomas Gleixner <tglx@linutronix.de>
Wed, 10 Apr 2024 19:45:28 +0000 (21:45 +0200)
committerIngo Molnar <mingo@kernel.org>
Fri, 12 Apr 2024 10:05:54 +0000 (12:05 +0200)
commitc064b536a8f9ab7c8e204da8f5a22f7420d0b56c
treec0f0d3a21d2389ecc534033cdd0e7aa18ab2dc54
parent1b3108f6898ef2e03973d65255182792e94e2240
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: f7fb3b2dd92c ("x86/cpu: Provide an AMD/HYGON specific topology parser")
Reported-by: "kernelci.org bot" <bot@kernelci.org>
Reported-by: Laura Nao <laura.nao@collabora.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Laura Nao <laura.nao@collabora.com>
Link: https://lore.kernel.org/r/20240410194311.596282919@linutronix.de
Closes: https://lore.kernel.org/all/20240322175210.124416-1-laura.nao@collabora.com/
arch/x86/kernel/cpu/topology_amd.c