mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched/numa: Fix divide by zero for sysctl_numa_balancing_scan_size.
@ 2023-03-29 16:26 Chris Hyser
  2023-03-29 18:28 ` chris hyser
  2023-03-30  1:51 ` Chen Yu
  0 siblings, 2 replies; 6+ messages in thread
From: Chris Hyser @ 2023-03-29 16:26 UTC (permalink / raw)
  To: chris.hyser, linux-kernel, dietmar.eggemann, peterz, vincent.guittot

From: chris hyser <chris.hyser@oracle.com>

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 | 50 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 1637b65ba07a..dfd0fe6123ec 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -278,6 +278,54 @@ 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)
+{
+	char buf[16];
+	unsigned int scan_size;
+
+	if (cnt > 15)
+		cnt = 15;
+
+	if (copy_from_user(&buf, ubuf, cnt))
+		return -EFAULT;
+	buf[cnt] = '\0';
+
+	if (kstrtouint(buf, 10, &scan_size))
+		return -EINVAL;
+
+	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 +380,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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] sched/numa: Fix divide by zero for sysctl_numa_balancing_scan_size.
  2023-03-29 16:26 [PATCH] sched/numa: Fix divide by zero for sysctl_numa_balancing_scan_size Chris Hyser
@ 2023-03-29 18:28 ` chris hyser
  2023-03-30 13:45   ` Peter Zijlstra
  2023-03-30  1:51 ` Chen Yu
  1 sibling, 1 reply; 6+ messages in thread
From: chris hyser @ 2023-03-29 18:28 UTC (permalink / raw)
  To: linux-kernel, dietmar.eggemann, peterz, vincent.guittot

On 3/29/23 12:26, Chris Hyser wrote:
> From: chris hyser <chris.hyser@oracle.com>

Apologies. Something in my email chain put this in, but I think I 
figured it out and sent a version 1.

-chrish

> 
> 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 | 50 +++++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 49 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
> index 1637b65ba07a..dfd0fe6123ec 100644
> --- a/kernel/sched/debug.c
> +++ b/kernel/sched/debug.c
> @@ -278,6 +278,54 @@ 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)
> +{
> +	char buf[16];
> +	unsigned int scan_size;
> +
> +	if (cnt > 15)
> +		cnt = 15;
> +
> +	if (copy_from_user(&buf, ubuf, cnt))
> +		return -EFAULT;
> +	buf[cnt] = '\0';
> +
> +	if (kstrtouint(buf, 10, &scan_size))
> +		return -EINVAL;
> +
> +	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 +380,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
>   


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] sched/numa: Fix divide by zero for sysctl_numa_balancing_scan_size.
  2023-03-29 16:26 [PATCH] sched/numa: Fix divide by zero for sysctl_numa_balancing_scan_size Chris Hyser
  2023-03-29 18:28 ` chris hyser
@ 2023-03-30  1:51 ` Chen Yu
  2023-03-30 15:09   ` chris hyser
  1 sibling, 1 reply; 6+ messages in thread
From: Chen Yu @ 2023-03-30  1:51 UTC (permalink / raw)
  To: Chris Hyser; +Cc: linux-kernel, dietmar.eggemann, peterz, vincent.guittot

On 2023-03-29 at 12:26:10 -0400, Chris Hyser wrote:
> From: chris hyser <chris.hyser@oracle.com>
> 
> 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 | 50 +++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 49 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
> index 1637b65ba07a..dfd0fe6123ec 100644
> --- a/kernel/sched/debug.c
> +++ b/kernel/sched/debug.c
> @@ -278,6 +278,54 @@ 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)
> +{
> +	char buf[16];
> +	unsigned int scan_size;
> +
> +	if (cnt > 15)
> +		cnt = 15;
> +
> +	if (copy_from_user(&buf, ubuf, cnt))
> +		return -EFAULT;
> +	buf[cnt] = '\0';
> +
> +	if (kstrtouint(buf, 10, &scan_size))
> +		return -EINVAL;
error code of kstrtouint() includes -ERANGE other than -EINVAL, how
about return the error code directly?

thanks,
Chenyu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] sched/numa: Fix divide by zero for sysctl_numa_balancing_scan_size.
  2023-03-29 18:28 ` chris hyser
@ 2023-03-30 13:45   ` Peter Zijlstra
  2023-03-30 15:10     ` chris hyser
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Zijlstra @ 2023-03-30 13:45 UTC (permalink / raw)
  To: chris hyser; +Cc: linux-kernel, dietmar.eggemann, vincent.guittot

On Wed, Mar 29, 2023 at 02:28:25PM -0400, chris hyser wrote:
> On 3/29/23 12:26, Chris Hyser wrote:
> > From: chris hyser <chris.hyser@oracle.com>
> 
> Apologies. Something in my email chain put this in, but I think I figured it
> out and sent a version 1.

Not actually a problem -- all patch processing tools can deal with this
since it's a common pattern when forwarding patches written by others.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] sched/numa: Fix divide by zero for sysctl_numa_balancing_scan_size.
  2023-03-30  1:51 ` Chen Yu
@ 2023-03-30 15:09   ` chris hyser
  0 siblings, 0 replies; 6+ messages in thread
From: chris hyser @ 2023-03-30 15:09 UTC (permalink / raw)
  To: Chen Yu; +Cc: linux-kernel, dietmar.eggemann, peterz, vincent.guittot

On 3/29/23 21:51, Chen Yu wrote:
> On 2023-03-29 at 12:26:10 -0400, Chris Hyser wrote:
>> From: chris hyser <chris.hyser@oracle.com>
>>
>> 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 | 50 +++++++++++++++++++++++++++++++++++++++++++-
>>   1 file changed, 49 insertions(+), 1 deletion(-)
>>
>> diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
>> index 1637b65ba07a..dfd0fe6123ec 100644
>> --- a/kernel/sched/debug.c
>> +++ b/kernel/sched/debug.c
>> @@ -278,6 +278,54 @@ 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)
>> +{
>> +	char buf[16];
>> +	unsigned int scan_size;
>> +
>> +	if (cnt > 15)
>> +		cnt = 15;
>> +
>> +	if (copy_from_user(&buf, ubuf, cnt))
>> +		return -EFAULT;
>> +	buf[cnt] = '\0';
>> +
>> +	if (kstrtouint(buf, 10, &scan_size))
>> +		return -EINVAL;
> error code of kstrtouint() includes -ERANGE other than -EINVAL, how
> about return the error code directly?

Sure. I just sent out a v2.

-chrish

> thanks,
> Chenyu


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] sched/numa: Fix divide by zero for sysctl_numa_balancing_scan_size.
  2023-03-30 13:45   ` Peter Zijlstra
@ 2023-03-30 15:10     ` chris hyser
  0 siblings, 0 replies; 6+ messages in thread
From: chris hyser @ 2023-03-30 15:10 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: linux-kernel, dietmar.eggemann, vincent.guittot

On 3/30/23 09:45, Peter Zijlstra wrote:
> On Wed, Mar 29, 2023 at 02:28:25PM -0400, chris hyser wrote:
>> On 3/29/23 12:26, Chris Hyser wrote:
>>> From: chris hyser <chris.hyser@oracle.com>
>>
>> Apologies. Something in my email chain put this in, but I think I figured it
>> out and sent a version 1.
> 
> Not actually a problem -- all patch processing tools can deal with this
> since it's a common pattern when forwarding patches written by others.

Makes sense. Thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-30 16:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-29 16:26 [PATCH] sched/numa: Fix divide by zero for sysctl_numa_balancing_scan_size Chris Hyser
2023-03-29 18:28 ` chris hyser
2023-03-30 13:45   ` Peter Zijlstra
2023-03-30 15:10     ` chris hyser
2023-03-30  1:51 ` Chen Yu
2023-03-30 15:09   ` chris hyser

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®