Skip to contentSkip to conversation

clockevents: Match the CPU when unbinding devices via sysfs

PATCH Applied Avi Weiss 3 participants 3 messages Nov 1 – Nov 9 High-resolution timers, timer wheel, clockevents

lore
Share & tools
lore

Avi Weiss

author
#0 lore raw

PATCH 1/1 clockevents: Match the CPU when unbinding devices via sysfs

Clockevent devices belonging to different CPUs can share the same name. The sysfs unbind handler selects the first matching name from the global device list, which can cause a request for one CPU to unbind another CPU's device or incorrectly return -EBUSY.

Check the device's CPU mask when selecting the clockevent to unbind so that the request targets a device eligible for the specified CPU.

Fixes 03e13cf5ee60 ("clockevents: Implement unbind functionality")
---
 kernel/time/clockevents.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/time/clockevents.c +2 -1
index 62ad7c000386..05e9d966b024 100644
@@ -756,7 +756,8 @@ static ssize_t unbind_device_store(struct device *dev,
 	mutex_lock(&clockevents_mutex);
 	raw_spin_lock_irq(&clockevents_lock);
 	list_for_each_entry(iter, &clockevent_devices, list) {
-		if (!strcmp(iter->name, name)) {
+		if (!strcmp(iter->name, name) &&
+		    cpumask_test_cpu(dev->id, iter->cpumask)) {
 			ret = __clockevents_try_unbind(iter, dev->id);
 			ce = iter;
 			break;

base-commit: cbbddb6b08cc9900a87cccaa9b22bbe06aa4f50a

Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Avi Weiss

Clockevent devices belonging to different CPUs can share the same name. The sysfs unbind handler selects the first matching name from the global device list, which can cause a request for one CPU to unbind another CPU's device or incorrectly return -EBUSY.

Check the device's CPU mask when selecting the clockevent to unbind so that the request targets a device eligible for the specified CPU.

Fixes 03e13cf5ee60 ("clockevents: Implement unbind functionality")
Signature · 2 lines
Frederic Weisbecker
SUSE Labs
merge bot Applied
#2 lore raw
In reply to Avi Weiss
The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     6b1f622e0a725e0b9a3dc36c24276d24b5b6e295
Gitweb:        https://git.kernel.org/tip/6b1f622e0a725e0b9a3dc36c24276d24b5b6e295
Author:        Avi Weiss <[email protected]>
AuthorDate:    Sun, 01 Nov 2026 16:11:20 +02:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Mon, 09 Nov 2026 20:25:25 +01:00

clockevents: Match the CPU when unbinding devices via sysfs

Clockevent devices belonging to different CPUs can share the same name. The sysfs unbind handler selects the first matching name from the global device list, which can cause a request for one CPU to unbind another CPU's device or incorrectly return -EBUSY.

Check the device's CPU mask when selecting the clockevent to unbind so that the request targets a device eligible for the specified CPU.

Fixes 03e13cf5ee60 ("clockevents: Implement unbind functionality")
---
 kernel/time/clockevents.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/time/clockevents.c +2 -1
index 62ad7c0..05e9d96 100644
@@ -756,7 +756,8 @@ static ssize_t unbind_device_store(struct device *dev,
 	mutex_lock(&clockevents_mutex);
 	raw_spin_lock_irq(&clockevents_lock);
 	list_for_each_entry(iter, &clockevent_devices, list) {
-		if (!strcmp(iter->name, name)) {
+		if (!strcmp(iter->name, name) &&
+		    cpumask_test_cpu(dev->id, iter->cpumask)) {
 			ret = __clockevents_try_unbind(iter, dev->id);
 			ce = iter;
 			break;