Commit 94fa523e authored by Paolo Abeni's avatar Paolo Abeni
Browse files

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/20241017152422.487406-1-atenart@kernel.org


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parents 6886c14b 124afe77
Loading
Loading
Loading
Loading
+27 −11
Original line number Diff line number Diff line
@@ -51,29 +51,45 @@ int sysctl_devconf_inherit_init_net __read_mostly;
EXPORT_SYMBOL(sysctl_devconf_inherit_init_net);

#if IS_ENABLED(CONFIG_NET_FLOW_LIMIT) || IS_ENABLED(CONFIG_RPS)
static void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos,
static int dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos,
			struct cpumask *mask)
{
	char kbuf[128];
	char *kbuf;
	int len;

	if (*ppos || !*lenp) {
		*lenp = 0;
		return;
		return 0;
	}

	/* CPUs are displayed as a hex bitmap + a comma between each groups of 8
	 * nibbles (except the last one which has a newline instead).
	 * Guesstimate the buffer size at the group granularity level.
	 */
	len = min(DIV_ROUND_UP(nr_cpumask_bits, 32) * (8 + 1), *lenp);
	kbuf = kmalloc(len, GFP_KERNEL);
	if (!kbuf) {
		*lenp = 0;
		return -ENOMEM;
	}

	len = min(sizeof(kbuf) - 1, *lenp);
	len = scnprintf(kbuf, len, "%*pb", cpumask_pr_args(mask));
	if (!len) {
		*lenp = 0;
		return;
		goto free_buf;
	}

	if (len < *lenp)
	/* scnprintf writes a trailing null char not counted in the returned
	 * length, override it with a newline.
	 */
	kbuf[len++] = '\n';
	memcpy(buffer, kbuf, len);
	*lenp = len;
	*ppos += len;

free_buf:
	kfree(kbuf);
	return 0;
}
#endif

@@ -117,7 +133,7 @@ static int rps_default_mask_sysctl(const struct ctl_table *table, int write,
		if (err)
			goto done;
	} else {
		dump_cpumask(buffer, lenp, ppos,
		err = dump_cpumask(buffer, lenp, ppos,
				   net->core.rps_default_mask ? : cpu_none_mask);
	}

@@ -247,7 +263,7 @@ static int flow_limit_cpu_sysctl(const struct ctl_table *table, int write,
		}
		rcu_read_unlock();

		dump_cpumask(buffer, lenp, ppos, mask);
		ret = dump_cpumask(buffer, lenp, ppos, mask);
	}

done: