Skip to content

Commit 6458de9

Browse files
KAGA-KOKOsuryasaimadhu
authored andcommitted
x86/mce/amd: Straighten CPU hotplug path
mce_threshold_create_device() hotplug callback runs on the plugged in CPU so: - use this_cpu_read() which is faster - pass in struct threshold_bank **bp to threshold_create_bank() and instead of doing per-CPU accesses - Use rdmsr_safe() instead of rdmsr_safe_on_cpu() which avoids an IPI. No functional changes. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 6e7a41c commit 6458de9

File tree

1 file changed

+15
-17
lines changed
  • arch/x86/kernel/cpu/mce

1 file changed

+15
-17
lines changed

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,10 +1223,10 @@ static int allocate_threshold_blocks(unsigned int cpu, struct threshold_bank *tb
12231223
u32 low, high;
12241224
int err;
12251225

1226-
if ((bank >= per_cpu(mce_num_banks, cpu)) || (block >= NR_BLOCKS))
1226+
if ((bank >= this_cpu_read(mce_num_banks)) || (block >= NR_BLOCKS))
12271227
return 0;
12281228

1229-
if (rdmsr_safe_on_cpu(cpu, address, &low, &high))
1229+
if (rdmsr_safe(address, &low, &high))
12301230
return 0;
12311231

12321232
if (!(high & MASK_VALID_HI)) {
@@ -1316,9 +1316,10 @@ static int __threshold_add_blocks(struct threshold_bank *b)
13161316
return err;
13171317
}
13181318

1319-
static int threshold_create_bank(unsigned int cpu, unsigned int bank)
1319+
static int threshold_create_bank(struct threshold_bank **bp, unsigned int cpu,
1320+
unsigned int bank)
13201321
{
1321-
struct device *dev = per_cpu(mce_device, cpu);
1322+
struct device *dev = this_cpu_read(mce_device);
13221323
struct amd_northbridge *nb = NULL;
13231324
struct threshold_bank *b = NULL;
13241325
const char *name = get_name(bank, NULL);
@@ -1338,7 +1339,7 @@ static int threshold_create_bank(unsigned int cpu, unsigned int bank)
13381339
if (err)
13391340
goto out;
13401341

1341-
per_cpu(threshold_banks, cpu)[bank] = b;
1342+
bp[bank] = b;
13421343
refcount_inc(&b->cpus);
13431344

13441345
err = __threshold_add_blocks(b);
@@ -1374,8 +1375,7 @@ static int threshold_create_bank(unsigned int cpu, unsigned int bank)
13741375
if (err)
13751376
goto out_kobj;
13761377

1377-
per_cpu(threshold_banks, cpu)[bank] = b;
1378-
1378+
bp[bank] = b;
13791379
return 0;
13801380

13811381
out_kobj:
@@ -1487,35 +1487,33 @@ int mce_threshold_remove_device(unsigned int cpu)
14871487
*/
14881488
int mce_threshold_create_device(unsigned int cpu)
14891489
{
1490-
unsigned int bank;
1490+
unsigned int numbanks, bank;
14911491
struct threshold_bank **bp;
14921492
int err;
14931493

14941494
if (!mce_flags.amd_threshold)
14951495
return 0;
14961496

1497-
bp = per_cpu(threshold_banks, cpu);
1497+
bp = this_cpu_read(threshold_banks);
14981498
if (bp)
14991499
return 0;
15001500

1501-
bp = kcalloc(per_cpu(mce_num_banks, cpu), sizeof(struct threshold_bank *),
1502-
GFP_KERNEL);
1501+
numbanks = this_cpu_read(mce_num_banks);
1502+
bp = kcalloc(numbanks, sizeof(*bp), GFP_KERNEL);
15031503
if (!bp)
15041504
return -ENOMEM;
15051505

1506-
per_cpu(threshold_banks, cpu) = bp;
1507-
1508-
for (bank = 0; bank < per_cpu(mce_num_banks, cpu); ++bank) {
1509-
if (!(per_cpu(bank_map, cpu) & (1 << bank)))
1506+
for (bank = 0; bank < numbanks; ++bank) {
1507+
if (!(this_cpu_read(bank_map) & (1 << bank)))
15101508
continue;
1511-
err = threshold_create_bank(cpu, bank);
1509+
err = threshold_create_bank(bp, cpu, bank);
15121510
if (err)
15131511
goto out_err;
15141512
}
1513+
this_cpu_write(threshold_banks, bp);
15151514

15161515
if (thresholding_irq_en)
15171516
mce_threshold_vector = amd_threshold_interrupt;
1518-
15191517
return 0;
15201518
out_err:
15211519
mce_threshold_remove_device(cpu);

0 commit comments

Comments
 (0)