Skip to content

Commit 94fa523

Browse files
author
Paolo Abeni
committed
Merge branch 'net-sysctl-allow-dump_cpumask-to-handle-higher-numbers-of-cpus'
Antoine Tenart says: ==================== net: sysctl: allow dump_cpumask to handle higher numbers of CPUs The main goal of this series is to allow dump_cpumask to handle higher numbers of CPUs (patch 3). While doing so I had the opportunity to make the function a bit simpler, which is done in patches 1-2. None of those is net material IMO. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents 6886c14 + 124afe7 commit 94fa523

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

net/core/sysctl_net_core.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,45 @@ int sysctl_devconf_inherit_init_net __read_mostly;
5151
EXPORT_SYMBOL(sysctl_devconf_inherit_init_net);
5252

5353
#if IS_ENABLED(CONFIG_NET_FLOW_LIMIT) || IS_ENABLED(CONFIG_RPS)
54-
static void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos,
55-
struct cpumask *mask)
54+
static int dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos,
55+
struct cpumask *mask)
5656
{
57-
char kbuf[128];
57+
char *kbuf;
5858
int len;
5959

6060
if (*ppos || !*lenp) {
6161
*lenp = 0;
62-
return;
62+
return 0;
63+
}
64+
65+
/* CPUs are displayed as a hex bitmap + a comma between each groups of 8
66+
* nibbles (except the last one which has a newline instead).
67+
* Guesstimate the buffer size at the group granularity level.
68+
*/
69+
len = min(DIV_ROUND_UP(nr_cpumask_bits, 32) * (8 + 1), *lenp);
70+
kbuf = kmalloc(len, GFP_KERNEL);
71+
if (!kbuf) {
72+
*lenp = 0;
73+
return -ENOMEM;
6374
}
6475

65-
len = min(sizeof(kbuf) - 1, *lenp);
6676
len = scnprintf(kbuf, len, "%*pb", cpumask_pr_args(mask));
6777
if (!len) {
6878
*lenp = 0;
69-
return;
79+
goto free_buf;
7080
}
7181

72-
if (len < *lenp)
73-
kbuf[len++] = '\n';
82+
/* scnprintf writes a trailing null char not counted in the returned
83+
* length, override it with a newline.
84+
*/
85+
kbuf[len++] = '\n';
7486
memcpy(buffer, kbuf, len);
7587
*lenp = len;
7688
*ppos += len;
89+
90+
free_buf:
91+
kfree(kbuf);
92+
return 0;
7793
}
7894
#endif
7995

@@ -117,8 +133,8 @@ static int rps_default_mask_sysctl(const struct ctl_table *table, int write,
117133
if (err)
118134
goto done;
119135
} else {
120-
dump_cpumask(buffer, lenp, ppos,
121-
net->core.rps_default_mask ? : cpu_none_mask);
136+
err = dump_cpumask(buffer, lenp, ppos,
137+
net->core.rps_default_mask ? : cpu_none_mask);
122138
}
123139

124140
done:
@@ -247,7 +263,7 @@ static int flow_limit_cpu_sysctl(const struct ctl_table *table, int write,
247263
}
248264
rcu_read_unlock();
249265

250-
dump_cpumask(buffer, lenp, ppos, mask);
266+
ret = dump_cpumask(buffer, lenp, ppos, mask);
251267
}
252268

253269
done:

0 commit comments

Comments
 (0)