Skip to content

Commit 6e7a41c

Browse files
KAGA-KOKOsuryasaimadhu
authored andcommitted
x86/mce/amd: Sanitize thresholding device creation hotplug path
Drop the stupid threshold_init_device() initcall iterating over all online CPUs in favor of properly setting up everything on the CPU hotplug path, when each CPU's callback is invoked. [ bp: Write commit message. ] Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent cca9cc0 commit 6e7a41c

File tree

2 files changed

+27
-41
lines changed

2 files changed

+27
-41
lines changed

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

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,12 +1474,22 @@ int mce_threshold_remove_device(unsigned int cpu)
14741474
return 0;
14751475
}
14761476

1477-
/* create dir/files for all valid threshold banks */
1477+
/**
1478+
* mce_threshold_create_device - Create the per-CPU MCE threshold device
1479+
* @cpu: The plugged in CPU
1480+
*
1481+
* Create directories and files for all valid threshold banks.
1482+
*
1483+
* This is invoked from the CPU hotplug callback which was installed in
1484+
* mcheck_init_device(). The invocation happens in context of the hotplug
1485+
* thread running on @cpu. The callback is invoked on all CPUs which are
1486+
* online when the callback is installed or during a real hotplug event.
1487+
*/
14781488
int mce_threshold_create_device(unsigned int cpu)
14791489
{
14801490
unsigned int bank;
14811491
struct threshold_bank **bp;
1482-
int err = 0;
1492+
int err;
14831493

14841494
if (!mce_flags.amd_threshold)
14851495
return 0;
@@ -1500,49 +1510,14 @@ int mce_threshold_create_device(unsigned int cpu)
15001510
continue;
15011511
err = threshold_create_bank(cpu, bank);
15021512
if (err)
1503-
goto err;
1504-
}
1505-
return err;
1506-
err:
1507-
mce_threshold_remove_device(cpu);
1508-
return err;
1509-
}
1510-
1511-
static __init int threshold_init_device(void)
1512-
{
1513-
unsigned lcpu = 0;
1514-
1515-
/* to hit CPUs online before the notifier is up */
1516-
for_each_online_cpu(lcpu) {
1517-
int err = mce_threshold_create_device(lcpu);
1518-
1519-
if (err)
1520-
return err;
1513+
goto out_err;
15211514
}
15221515

15231516
if (thresholding_irq_en)
15241517
mce_threshold_vector = amd_threshold_interrupt;
15251518

15261519
return 0;
1520+
out_err:
1521+
mce_threshold_remove_device(cpu);
1522+
return err;
15271523
}
1528-
/*
1529-
* there are 3 funcs which need to be _initcalled in a logic sequence:
1530-
* 1. xen_late_init_mcelog
1531-
* 2. mcheck_init_device
1532-
* 3. threshold_init_device
1533-
*
1534-
* xen_late_init_mcelog must register xen_mce_chrdev_device before
1535-
* native mce_chrdev_device registration if running under xen platform;
1536-
*
1537-
* mcheck_init_device should be inited before threshold_init_device to
1538-
* initialize mce_device, otherwise a NULL ptr dereference will cause panic.
1539-
*
1540-
* so we use following _initcalls
1541-
* 1. device_initcall(xen_late_init_mcelog);
1542-
* 2. device_initcall_sync(mcheck_init_device);
1543-
* 3. late_initcall(threshold_init_device);
1544-
*
1545-
* when running under xen, the initcall order is 1,2,3;
1546-
* on baremetal, we skip 1 and we do only 2 and 3.
1547-
*/
1548-
late_initcall(threshold_init_device);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,6 +2481,13 @@ static __init void mce_init_banks(void)
24812481
}
24822482
}
24832483

2484+
/*
2485+
* When running on XEN, this initcall is ordered against the XEN mcelog
2486+
* initcall:
2487+
*
2488+
* device_initcall(xen_late_init_mcelog);
2489+
* device_initcall_sync(mcheck_init_device);
2490+
*/
24842491
static __init int mcheck_init_device(void)
24852492
{
24862493
int err;
@@ -2512,6 +2519,10 @@ static __init int mcheck_init_device(void)
25122519
if (err)
25132520
goto err_out_mem;
25142521

2522+
/*
2523+
* Invokes mce_cpu_online() on all CPUs which are online when
2524+
* the state is installed.
2525+
*/
25152526
err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/mce:online",
25162527
mce_cpu_online, mce_cpu_pre_down);
25172528
if (err < 0)

0 commit comments

Comments
 (0)