Skip to contentSkip to conversation

sched/deadline: Reject debugfs dl_server writes for offline CPUs

PATCH Applied Andrea Righi 4 participants 5 messages May 26 – May 29 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/deadline: Reject debugfs dl_server writes for offline CPUs

Writing runtime or period via the per-CPU dl_server debugfs files (/sys/kernel/debug/sched/{fair,ext}_server/cpu*/{runtime,period}) on an offline CPU can trigger two distinct kernel issues:

1) Divide-by-zero in dl_server_apply_params():

  Oops: divide error: 0000 [#1] SMP NOPTI
  RIP: 0010:dl_server_apply_params+0x239/0x3a0
  Call Trace:
   sched_server_write_common.isra.0+0x21a/0x3c0
   full_proxy_write+0x78/0xd0
   vfs_write+0xe7/0x6e0

Both __dl_sub() and __dl_add() divide by cpus internally, which can be 0 once the CPU has been removed from any active root-domain span (this has been latent since the debugfs interface was introduced).

2) WARN_ON_ONCE in dl_server_start():

  WARNING: kernel/sched/deadline.c:1805 at dl_server_start+0x232/0x270

Commit ee6e44dfe6e5 ("sched/deadline: Stop dl_server before CPU goes offline") added this check to catch enqueueing the server on an offline rq.

There's no meaningful semantics for re-configuring the per-CPU dl_server bandwidth while the CPU is offline, so simply reject the write with -EBUSY so userspace gets a clear error.

Fixes d741f297bcea ("sched/fair: Fair server interface")
---
 kernel/sched/debug.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/sched/debug.c +3 -0
index ed3a0d65da0ca..e57ad8c78a60e 100644
@@ -415,6 +415,9 @@ static ssize_t sched_server_write_common(struct file *filp, const char __user *u
 			return  -EINVAL;
 		}
 
+		if (!cpu_online(cpu_of(rq)))
+			return -EBUSY;
+
 		update_rq_clock(rq);
 		dl_server_stop(dl_se);
 		retval = dl_server_apply_params(dl_se, runtime, period, 0);

base-commit: 7b197f597bc895b01204d8389a4cf3b00780bd21

Signature · 1 line
2.54.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi Andrea,

Quoted 42 lines · Andrea Righi

Writing runtime or period via the per-CPU dl_server debugfs files (/sys/kernel/debug/sched/{fair,ext}_server/cpu*/{runtime,period}) on an offline CPU can trigger two distinct kernel issues:

1) Divide-by-zero in dl_server_apply_params():

  Oops: divide error: 0000 [#1] SMP NOPTI
  RIP: 0010:dl_server_apply_params+0x239/0x3a0
  Call Trace:
   sched_server_write_common.isra.0+0x21a/0x3c0
   full_proxy_write+0x78/0xd0
   vfs_write+0xe7/0x6e0

Both __dl_sub() and __dl_add() divide by cpus internally, which can be 0 once the CPU has been removed from any active root-domain span (this has been latent since the debugfs interface was introduced).

2) WARN_ON_ONCE in dl_server_start():

  WARNING: kernel/sched/deadline.c:1805 at dl_server_start+0x232/0x270

Commit ee6e44dfe6e5 ("sched/deadline: Stop dl_server before CPU goes offline") added this check to catch enqueueing the server on an offline rq.

There's no meaningful semantics for re-configuring the per-CPU dl_server bandwidth while the CPU is offline, so simply reject the write with -EBUSY so userspace gets a clear error.

Fixes d741f297bcea ("sched/fair: Fair server interface")
---
 kernel/sched/debug.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/sched/debug.c +0 -0
index ed3a0d65da0ca..e57ad8c78a60e 100644

kernel/sched/debug.c static ssize_t sched_server_write_common(struct file *filp, const char __user *u · line 423

Quoted 9 lines
kernel/sched/debug.c +3 -0
@@ -415,6 +415,9 @@ static ssize_t sched_server_write_common(struct file *filp, const char __user *u
 			return  -EINVAL;
 		}
 
+		if (!cpu_online(cpu_of(rq)))
+			return -EBUSY;
+
 		update_rq_clock(rq);
 		dl_server_stop(dl_se);
 		retval = dl_server_apply_params(dl_se, runtime, period, 0);

I was looking at Sashiko findings and wondered what to do about this as well. I think what you are proposing should be fine, unless for some reason one wants to tweak dl-server parameters before swithcing a CPU on. but since hotplug it's a disruptive operation already, I would say imposing to make such a change after CPU is online should be ok (and simpler to get right from a bandwidth accounting pov).

Thanks,
Juri

#2 lore raw

Hi Peter,

Quoted 62 lines · Juri Lelli

Hi Andrea,

Quoted 42 lines · Andrea Righi

Writing runtime or period via the per-CPU dl_server debugfs files (/sys/kernel/debug/sched/{fair,ext}_server/cpu*/{runtime,period}) on an offline CPU can trigger two distinct kernel issues:

1) Divide-by-zero in dl_server_apply_params():

  Oops: divide error: 0000 [#1] SMP NOPTI
  RIP: 0010:dl_server_apply_params+0x239/0x3a0
  Call Trace:
   sched_server_write_common.isra.0+0x21a/0x3c0
   full_proxy_write+0x78/0xd0
   vfs_write+0xe7/0x6e0

Both __dl_sub() and __dl_add() divide by cpus internally, which can be 0 once the CPU has been removed from any active root-domain span (this has been latent since the debugfs interface was introduced).

2) WARN_ON_ONCE in dl_server_start():

  WARNING: kernel/sched/deadline.c:1805 at dl_server_start+0x232/0x270

Commit ee6e44dfe6e5 ("sched/deadline: Stop dl_server before CPU goes offline") added this check to catch enqueueing the server on an offline rq.

There's no meaningful semantics for re-configuring the per-CPU dl_server bandwidth while the CPU is offline, so simply reject the write with -EBUSY so userspace gets a clear error.

Fixes d741f297bcea ("sched/fair: Fair server interface")
---
 kernel/sched/debug.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/sched/debug.c +0 -0
index ed3a0d65da0ca..e57ad8c78a60e 100644

kernel/sched/debug.c static ssize_t sched_server_write_common(struct file *filp, const char __user *u · line 423

Quoted 9 lines
kernel/sched/debug.c +3 -0
@@ -415,6 +415,9 @@ static ssize_t sched_server_write_common(struct file *filp, const char __user *u
 			return  -EINVAL;
 		}
 
+		if (!cpu_online(cpu_of(rq)))
+			return -EBUSY;
+
 		update_rq_clock(rq);
 		dl_server_stop(dl_se);
 		retval = dl_server_apply_params(dl_se, runtime, period, 0);

I was looking at Sashiko findings and wondered what to do about this as well. I think what you are proposing should be fine, unless for some reason one wants to tweak dl-server parameters before swithcing a CPU on. but since hotplug it's a disruptive operation already, I would say imposing to make such a change after CPU is online should be ok (and simpler to get right from a bandwidth accounting pov).

Quoted 1 line

If this makes sense to you, could you add it to your queue:sched/core?

Otherwise it's possible to trigger the issues above by changing dl_server bandwidth for offline CPUs.

Thanks,
-Andrea

maintainer
#3 lore raw
Quoted 65 lines · Andrea Righi

Hi Peter,

Quoted 62 lines · Juri Lelli

Hi Andrea,

Quoted 42 lines · Andrea Righi

Writing runtime or period via the per-CPU dl_server debugfs files (/sys/kernel/debug/sched/{fair,ext}_server/cpu*/{runtime,period}) on an offline CPU can trigger two distinct kernel issues:

1) Divide-by-zero in dl_server_apply_params():

  Oops: divide error: 0000 [#1] SMP NOPTI
  RIP: 0010:dl_server_apply_params+0x239/0x3a0
  Call Trace:
   sched_server_write_common.isra.0+0x21a/0x3c0
   full_proxy_write+0x78/0xd0
   vfs_write+0xe7/0x6e0

Both __dl_sub() and __dl_add() divide by cpus internally, which can be 0 once the CPU has been removed from any active root-domain span (this has been latent since the debugfs interface was introduced).

2) WARN_ON_ONCE in dl_server_start():

  WARNING: kernel/sched/deadline.c:1805 at dl_server_start+0x232/0x270

Commit ee6e44dfe6e5 ("sched/deadline: Stop dl_server before CPU goes offline") added this check to catch enqueueing the server on an offline rq.

There's no meaningful semantics for re-configuring the per-CPU dl_server bandwidth while the CPU is offline, so simply reject the write with -EBUSY so userspace gets a clear error.

Fixes d741f297bcea ("sched/fair: Fair server interface")
---
 kernel/sched/debug.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/sched/debug.c +0 -0
index ed3a0d65da0ca..e57ad8c78a60e 100644

kernel/sched/debug.c static ssize_t sched_server_write_common(struct file *filp, const char __user *u · line 423

Quoted 9 lines
kernel/sched/debug.c +3 -0
@@ -415,6 +415,9 @@ static ssize_t sched_server_write_common(struct file *filp, const char __user *u
 			return  -EINVAL;
 		}
 
+		if (!cpu_online(cpu_of(rq)))
+			return -EBUSY;
+
 		update_rq_clock(rq);
 		dl_server_stop(dl_se);
 		retval = dl_server_apply_params(dl_se, runtime, period, 0);

I was looking at Sashiko findings and wondered what to do about this as well. I think what you are proposing should be fine, unless for some reason one wants to tweak dl-server parameters before swithcing a CPU on. but since hotplug it's a disruptive operation already, I would say imposing to make such a change after CPU is online should be ok (and simpler to get right from a bandwidth accounting pov).

Quoted 6 lines
Quoted 1 line

If this makes sense to you, could you add it to your queue:sched/core?

Otherwise it's possible to trigger the issues above by changing dl_server bandwidth for offline CPUs.

Right, so I had seen these patches fly by, but then I couldn't find it in a hurry when I took these other patches :/.

It is a bit unfortunate, but oh well. I'm sure people will try and fix it if they're too annoyed by this behaviour and we can revisit thing then.

So yes, let me go add this to the other two.

merge bot Applied
#4 lore raw
In reply to Andrea Righi
The following commit has been merged into the sched/core branch of tip:

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

Commit-ID:     4043f549841619a01999bf5d4e0b7931ef87f6cc
Gitweb:        https://git.kernel.org/tip/4043f549841619a01999bf5d4e0b7931ef87f6cc
Author:        Andrea Righi <[email protected]>
AuthorDate:    Tue, 26 May 2026 12:05:02 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Fri, 29 May 2026 12:43:15 +02:00

sched/deadline: Reject debugfs dl_server writes for offline CPUs

Writing runtime or period via the per-CPU dl_server debugfs files (/sys/kernel/debug/sched/{fair,ext}_server/cpu*/{runtime,period}) on an offline CPU can trigger two distinct kernel issues:

1) Divide-by-zero in dl_server_apply_params():

  Oops: divide error: 0000 [#1] SMP NOPTI
  RIP: 0010:dl_server_apply_params+0x239/0x3a0
  Call Trace:
   sched_server_write_common.isra.0+0x21a/0x3c0
   full_proxy_write+0x78/0xd0
   vfs_write+0xe7/0x6e0

Both __dl_sub() and __dl_add() divide by cpus internally, which can be 0 once the CPU has been removed from any active root-domain span (this has been latent since the debugfs interface was introduced).

2) WARN_ON_ONCE in dl_server_start():

  WARNING: kernel/sched/deadline.c:1805 at dl_server_start+0x232/0x270

Commit ee6e44dfe6e5 ("sched/deadline: Stop dl_server before CPU goes offline") added this check to catch enqueueing the server on an offline rq.

There's no meaningful semantics for re-configuring the per-CPU dl_server bandwidth while the CPU is offline, so simply reject the write with -EBUSY so userspace gets a clear error.

---
 kernel/sched/debug.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/sched/debug.c +3 -0
index 4809e1d..5e09cf9 100644
@@ -416,6 +416,9 @@ static ssize_t sched_server_write_common(struct file *filp, const char __user *u
 			return  -EINVAL;
 		}
 
+		if (!cpu_online(cpu_of(rq)))
+			return -EBUSY;
+
 		update_rq_clock(rq);
 		dl_server_stop(dl_se);
 		retval = dl_server_apply_params(dl_se, runtime, period, 0);