From: chris hyser <chris.hyser@oracle.com>
To: chris.hyser@oracle.com, linux-kernel@vger.kernel.org,
dietmar.eggemann@arm.com, peterz@infradead.org,
vincent.guittot@linaro.org, "Chen Yu" <yu.c.chen@intel.com>
Subject: [PATCH v2] sched/numa: Fix divide by zero for sysctl_numa_balancing_scan_size.
Date: Thu, 30 Mar 2023 11:07:57 -0400 [thread overview]
Message-ID: <20230330150757.547423-1-chris.hyser@oracle.com> (raw)
Commit 6419265899d9 ("sched/fair: Fix division by zero
sysctl_numa_balancing_scan_size") prevented a divide by zero by using
sysctl mechanisms to return EINVAL for a sysctl_numa_balancing_scan_size
value of zero. When moved from a sysctl to a debugfs file, this checking
was lost.
This patch puts zero checking back in place.
Signed-off-by: Chris Hyser <chris.hyser@oracle.com>
---
kernel/sched/debug.c | 52 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 1637b65ba07a..b5fc7e250128 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -278,6 +278,56 @@ static const struct file_operations sched_dynamic_fops = {
#endif /* CONFIG_PREEMPT_DYNAMIC */
+#ifdef CONFIG_NUMA_BALANCING
+
+static ssize_t sched_numa_scan_write(struct file *filp, const char __user *ubuf,
+ size_t cnt, loff_t *ppos)
+{
+ int err;
+ char buf[16];
+ unsigned int scan_size;
+
+ if (cnt > 15)
+ cnt = 15;
+
+ if (copy_from_user(&buf, ubuf, cnt))
+ return -EFAULT;
+ buf[cnt] = '\0';
+
+ err = kstrtouint(buf, 10, &scan_size);
+ if (err)
+ return err;
+
+ if (!scan_size)
+ return -EINVAL;
+
+ sysctl_numa_balancing_scan_size = scan_size;
+
+ *ppos += cnt;
+ return cnt;
+}
+
+static int sched_numa_scan_show(struct seq_file *m, void *v)
+{
+ seq_printf(m, "%d\n", sysctl_numa_balancing_scan_size);
+ return 0;
+}
+
+static int sched_numa_scan_open(struct inode *inode, struct file *filp)
+{
+ return single_open(filp, sched_numa_scan_show, NULL);
+}
+
+static const struct file_operations sched_numa_scan_fops = {
+ .open = sched_numa_scan_open,
+ .write = sched_numa_scan_write,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+#endif /* CONFIG_NUMA_BALANCING */
+
__read_mostly bool sched_debug_verbose;
static const struct seq_operations sched_debug_sops;
@@ -332,7 +382,7 @@ static __init int sched_init_debug(void)
debugfs_create_u32("scan_delay_ms", 0644, numa, &sysctl_numa_balancing_scan_delay);
debugfs_create_u32("scan_period_min_ms", 0644, numa, &sysctl_numa_balancing_scan_period_min);
debugfs_create_u32("scan_period_max_ms", 0644, numa, &sysctl_numa_balancing_scan_period_max);
- debugfs_create_u32("scan_size_mb", 0644, numa, &sysctl_numa_balancing_scan_size);
+ debugfs_create_file("scan_size_mb", 0644, numa, NULL, &sched_numa_scan_fops);
debugfs_create_u32("hot_threshold_ms", 0644, numa, &sysctl_numa_balancing_hot_threshold);
#endif
--
2.31.1
next reply other threads:[~2023-03-30 15:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-30 15:07 chris hyser [this message]
2023-04-04 15:32 ` Chen Yu
2023-04-04 16:10 ` chris hyser
2023-04-04 18:33 ` chris hyser
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230330150757.547423-1-chris.hyser@oracle.com \
--to=chris.hyser@oracle.com \
--cc=dietmar.eggemann@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=vincent.guittot@linaro.org \
--cc=yu.c.chen@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®