Skip to content

Commit 4c1cdec

Browse files
muralimk-amdbp3tk0v
authored andcommitted
x86/MCE/AMD: Use an u64 for bank_map
Thee maximum number of MCA banks is 64 (MAX_NR_BANKS), see a0bc32b ("x86/mce: Increase maximum number of banks to 64"). However, the bank_map which contains a bitfield of which banks to initialize is of type unsigned int and that overflows when those bit numbers are >= 32, leading to UBSAN complaining correctly: UBSAN: shift-out-of-bounds in arch/x86/kernel/cpu/mce/amd.c:1365:38 shift exponent 32 is too large for 32-bit type 'int' Change the bank_map to a u64 and use the proper BIT_ULL() macro when modifying bits in there. [ bp: Rewrite commit message. ] Fixes: a0bc32b ("x86/mce: Increase maximum number of banks to 64") Signed-off-by: Muralidhara M K <muralimk@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20230127151601.1068324-1-muralimk@amd.com
1 parent 554eec0 commit 4c1cdec

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

  • arch/x86/kernel/cpu/mce

arch/x86/kernel/cpu/mce/amd.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ static DEFINE_PER_CPU(struct threshold_bank **, threshold_banks);
235235
* A list of the banks enabled on each logical CPU. Controls which respective
236236
* descriptors to initialize later in mce_threshold_create_device().
237237
*/
238-
static DEFINE_PER_CPU(unsigned int, bank_map);
238+
static DEFINE_PER_CPU(u64, bank_map);
239239

240240
/* Map of banks that have more than MCA_MISC0 available. */
241-
static DEFINE_PER_CPU(u32, smca_misc_banks_map);
241+
static DEFINE_PER_CPU(u64, smca_misc_banks_map);
242242

243243
static void amd_threshold_interrupt(void);
244244
static void amd_deferred_error_interrupt(void);
@@ -267,7 +267,7 @@ static void smca_set_misc_banks_map(unsigned int bank, unsigned int cpu)
267267
return;
268268

269269
if (low & MASK_BLKPTR_LO)
270-
per_cpu(smca_misc_banks_map, cpu) |= BIT(bank);
270+
per_cpu(smca_misc_banks_map, cpu) |= BIT_ULL(bank);
271271

272272
}
273273

@@ -530,7 +530,7 @@ static u32 smca_get_block_address(unsigned int bank, unsigned int block,
530530
if (!block)
531531
return MSR_AMD64_SMCA_MCx_MISC(bank);
532532

533-
if (!(per_cpu(smca_misc_banks_map, cpu) & BIT(bank)))
533+
if (!(per_cpu(smca_misc_banks_map, cpu) & BIT_ULL(bank)))
534534
return 0;
535535

536536
return MSR_AMD64_SMCA_MCx_MISCy(bank, block - 1);
@@ -574,7 +574,7 @@ prepare_threshold_block(unsigned int bank, unsigned int block, u32 addr,
574574
int new;
575575

576576
if (!block)
577-
per_cpu(bank_map, cpu) |= (1 << bank);
577+
per_cpu(bank_map, cpu) |= BIT_ULL(bank);
578578

579579
memset(&b, 0, sizeof(b));
580580
b.cpu = cpu;
@@ -878,7 +878,7 @@ static void amd_threshold_interrupt(void)
878878
return;
879879

880880
for (bank = 0; bank < this_cpu_read(mce_num_banks); ++bank) {
881-
if (!(per_cpu(bank_map, cpu) & (1 << bank)))
881+
if (!(per_cpu(bank_map, cpu) & BIT_ULL(bank)))
882882
continue;
883883

884884
first_block = bp[bank]->blocks;
@@ -1356,7 +1356,7 @@ int mce_threshold_create_device(unsigned int cpu)
13561356
return -ENOMEM;
13571357

13581358
for (bank = 0; bank < numbanks; ++bank) {
1359-
if (!(this_cpu_read(bank_map) & (1 << bank)))
1359+
if (!(this_cpu_read(bank_map) & BIT_ULL(bank)))
13601360
continue;
13611361
err = threshold_create_bank(bp, cpu, bank);
13621362
if (err) {

0 commit comments

Comments
 (0)