x86/mce: Synchronize sysfs reconfiguration against CPU hotplug
Subsystems (2)
syzbot
syzbotWhen offlining a CPU, the CPU hotplug teardown callback mce_cpu_pre_down() is invoked at CPUHP_AP_ONLINE_DYN to disable MCE reporting and delete the per-CPU timer via timer_delete_sync(). However, the CPU remains marked in cpu_online_mask until the later CPUHP_TEARDOWN_CPU state. If a user concurrently updates MCE configuration settings via sysfs (such as ignore_ce, cmci_disabled, check_interval, or bank controls), the sysfs handlers broadcast configuration changes across all online CPUs using on_each_cpu(). Because cpus_read_lock() is not held by the sysfs store handlers, an offlining CPU that is still present in cpu_online_mask can receive the IPI after its timer has already been deactivated. The IPI handler (such as mce_enable_ce() or mce_cpu_restart()) calls __mcheck_cpu_init_timer(), which re-arms the timer on the dying CPU. The CPU then finishes the offline teardown and halts with an active timer left in the timer wheel.
When the CPU is subsequently brought back online, identify_secondary_cpu() calls mcheck_cpu_init() -> __mcheck_cpu_setup_timer(), which invokes timer_setup() on the already active timer, triggering a debugobjects warning:
ODEBUG: init active (active state 0) object: ffff88827be234a0 object type:timer_list hint: mce_timer_fn+0x0/0x280
WARNING: lib/debugobjects.c:632 at debug_print_object+0xec/0x230 lib/debugobjects.c:629 Call Trace: <TASK> __debug_object_init+0x224/0x350 lib/debugobjects.c:818 timer_init_key+0x41/0x2c0 kernel/time/timer.c:880 __mcheck_cpu_setup_timer arch/x86/kernel/cpu/mce/core.c:2087 [inline] mcheck_cpu_init+0x3dc/0x600 arch/x86/kernel/cpu/mce/core.c:2262 identify_cpu+0x1f2c/0x3940 arch/x86/kernel/cpu/common.c:2126 identify_secondary_cpu+0xaa/0x160 arch/x86/kernel/cpu/common.c:2187 ap_starting+0x9c/0x150 arch/x86/kernel/smpboot.c:190 start_secondary+0x66/0x110 arch/x86/kernel/smpboot.c:280 common_startup_64+0x13e/0x157 </TASK>
Fix this by acquiring cpus_read_lock() around mce_sysfs_mutex in the sysfs store handlers (set_bank(), set_ignore_ce(), set_cmci_disabled(), and store_int_with_restart()). Holding cpus_read_lock() serializes sysfs reconfigurations against CPU hotplug, ensuring that CPUs undergoing teardown do not receive broadcast IPIs to re-enable or re-arm MCE timers after mce_cpu_pre_down() has cleaned them up.
To: "Borislav Petkov" <[email protected]>
To: "Dave Hansen" <[email protected]>
To: <[email protected]>
To: "Ingo Molnar" <[email protected]>
To: "Thomas Gleixner" <[email protected]>
To: "Tony Luck" <[email protected]>
To: <[email protected]>
To: "Seunghun Han" <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: <[email protected]>
---
arch/x86/kernel/cpu/mce/core.c +8 -0
@@ -2532,9 +2532,11 @@ static ssize_t set_bank(struct device *s, struct device_attribute *attr, b->ctl = new; +cpus_read_lock ();mutex_lock (&mce_sysfs_mutex);mce_restart ();mutex_unlock (&mce_sysfs_mutex); +cpus_read_unlock ();return size; }
@@ -2548,6 +2550,7 @@ static ssize_t set_ignore_ce(struct device *s,if (kstrtou64 (buf,0 , &new) <0 )return -EINVAL ; +cpus_read_lock ();mutex_lock (&mce_sysfs_mutex);if (mca_cfg.ignore_ce ^ !!new) {if (new) {
@@ -2562,6 +2565,7 @@ static ssize_t set_ignore_ce(struct device *s, } }mutex_unlock (&mce_sysfs_mutex); +cpus_read_unlock ();return size; }
@@ -2575,6 +2579,7 @@ static ssize_t set_cmci_disabled(struct device *s,if (kstrtou64 (buf,0 , &new) <0 )return -EINVAL ; +cpus_read_lock ();mutex_lock (&mce_sysfs_mutex);if (mca_cfg.cmci_disabled ^ !!new) {if (new) {
@@ -2588,6 +2593,7 @@ static ssize_t set_cmci_disabled(struct device *s, } }mutex_unlock (&mce_sysfs_mutex); +cpus_read_unlock ();return size; }
@@ -2602,9 +2608,11 @@ static ssize_t store_int_with_restart(struct device *s,if (check_interval == old_check_interval)return ret; +cpus_read_lock ();mutex_lock (&mce_sysfs_mutex);mce_restart ();mutex_unlock (&mce_sysfs_mutex); +cpus_read_unlock ();return ret; }
base-commit: a90ee4305c4a5df72c11b31dacfdc76e00fcf78a
Signature · 9 lines
This is an AI-generated patch subject to moderation.
Reply with '#syz upstream' to Sign-off the patch as a human author
and send it to the upstream kernel mailing lists.
Reply with '#syz reject' to reject it ('#syz unreject' to undo).
See https://goo.gle/syzbot-ai-patches for information about AI-generated patches.
You can comment on the patch as usual, syzbot will try to address
the comments and send a new version of the patch if necessary.
syzbot engineers can be reached at [email protected].#syz reject
Quoted 140 lines · syzbot' via syzkaller-upstream-moderation
When offlining a CPU, the CPU hotplug teardown callback
mce_cpu_pre_down()is invoked atCPUHP_AP_ONLINE_DYNto disable MCE reporting and delete the per-CPU timer viatimer_delete_sync(). However, the CPU remains marked incpu_online_maskuntil the laterCPUHP_TEARDOWN_CPUstate. If a user concurrently updates MCE configuration settings via sysfs (such asignore_ce,cmci_disabled,check_interval, or bank controls), the sysfs handlers broadcast configuration changes across all online CPUs usingon_each_cpu(). Becausecpus_read_lock()is not held by the sysfs store handlers, an offlining CPU that is still present incpu_online_maskcan receive the IPI after its timer has already been deactivated. The IPI handler (such asmce_enable_ce()ormce_cpu_restart()) calls__mcheck_cpu_init_timer(), which re-arms the timer on the dying CPU. The CPU then finishes the offline teardown and halts with an active timer left in the timer wheel.When the CPU is subsequently brought back online,
identify_secondary_cpu()callsmcheck_cpu_init()->__mcheck_cpu_setup_timer(), which invokestimer_setup()on the already active timer, triggering a debugobjects warning:ODEBUG: init active (active state 0) object:
ffff88827be234a0object type:timer_listhint:mce_timer_fn+0x0/0x280WARNING: lib/debugobjects.c:632 at debug_print_object+0xec/0x230 lib/debugobjects.c:629 Call Trace: <TASK> __debug_object_init+0x224/0x350 lib/debugobjects.c:818 timer_init_key+0x41/0x2c0 kernel/time/timer.c:880 __mcheck_cpu_setup_timer arch/x86/kernel/cpu/mce/core.c:2087 [inline] mcheck_cpu_init+0x3dc/0x600 arch/x86/kernel/cpu/mce/core.c:2262 identify_cpu+0x1f2c/0x3940 arch/x86/kernel/cpu/common.c:2126 identify_secondary_cpu+0xaa/0x160 arch/x86/kernel/cpu/common.c:2187 ap_starting+0x9c/0x150 arch/x86/kernel/smpboot.c:190 start_secondary+0x66/0x110 arch/x86/kernel/smpboot.c:280 common_startup_64+0x13e/0x157 </TASK>Fix this by acquiring
cpus_read_lock()aroundmce_sysfs_mutexin the sysfs store handlers (set_bank(),set_ignore_ce(),set_cmci_disabled(), andstore_int_with_restart()). Holdingcpus_read_lock()serializes sysfs reconfigurations against CPU hotplug, ensuring that CPUs undergoing teardown do not receive broadcast IPIs to re-enable or re-arm MCE timers aftermce_cpu_pre_down()has cleaned them up.Fixes b3b7c4795cca ("x86/MCE: Serialize sysfs changes")Assisted-by Gemini:gemini-3.8-flash Gemini:gemini-3.1-pro-preview syzbotReported-by [email protected]To: "Borislav Petkov" <[email protected]>
To: "Dave Hansen" <[email protected]>
To: <[email protected]>
To: "Ingo Molnar" <[email protected]>
To: "Thomas Gleixner" <[email protected]>
To: "Tony Luck" <[email protected]>
To: <[email protected]>
To: "Seunghun Han" <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: <[email protected]>---
arch/x86/kernel/cpu/mce/core.c +8
-0@@ -2532,9 +2532,11 @@ static ssize_t set_bank(struct device *s, struct device_attribute *attr, b->ctl = new; +cpus_read_lock ();mutex_lock (&mce_sysfs_mutex);mce_restart ();mutex_unlock (&mce_sysfs_mutex); +cpus_read_unlock ();return size; }@@ -2548,6 +2550,7 @@ static ssize_t set_ignore_ce(struct device *s,if (kstrtou64 (buf,0 , &new) <0 )return -EINVAL ; +cpus_read_lock ();mutex_lock (&mce_sysfs_mutex);if (mca_cfg.ignore_ce ^ !!new) {if (new) {@@ -2562,6 +2565,7 @@ static ssize_t set_ignore_ce(struct device *s, } }mutex_unlock (&mce_sysfs_mutex); +cpus_read_unlock ();return size; }@@ -2575,6 +2579,7 @@ static ssize_t set_cmci_disabled(struct device *s,if (kstrtou64 (buf,0 , &new) <0 )return -EINVAL ; +cpus_read_lock ();mutex_lock (&mce_sysfs_mutex);if (mca_cfg.cmci_disabled ^ !!new) {if (new) {@@ -2588,6 +2593,7 @@ static ssize_t set_cmci_disabled(struct device *s, } }mutex_unlock (&mce_sysfs_mutex); +cpus_read_unlock ();return size; }@@ -2602,9 +2608,11 @@ static ssize_t store_int_with_restart(struct device *s,if (check_interval == old_check_interval)return ret; +cpus_read_lock ();mutex_lock (&mce_sysfs_mutex);mce_restart ();mutex_unlock (&mce_sysfs_mutex); +cpus_read_unlock ();return ret; }base-commit:
a90ee4305c4a5df72c11b31dacfdc76e00fcf78a--
This is an AI-generated patch subject to moderation. Reply with '#syz upstream' to Sign-off the patch as a human author and send it to the upstream kernel mailing lists.
Reply with '#syz reject' to reject it ('#syz unreject' to undo).See https://goo.gle/syzbot-ai-patches for information about AI-generated patches. You can comment on the patch as usual, syzbot will try to address the comments and send a new version of the patch if necessary. syzbot engineers can be reached at [email protected].
--
You received this message because you are subscribed to the Google Groups "syzkaller-upstream-moderation" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/syzkaller-upstream-moderation/eca86078-6360-4453-9893-a384d3df0065%40mail.kernel.org.