diff mbox series

[v3,net-next,1/4] net-sysctl: factor out cpumask parsing helper

Message ID f171c4f78c17c259deb0cae78a26dc274afe9fce.1675708062.git.pabeni@redhat.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: introduce rps_default_mask | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 2 this patch: 4
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang fail Errors and warnings before: 1 this patch: 3
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 2 this patch: 4
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Paolo Abeni Feb. 6, 2023, 6:30 p.m. UTC
Will be used by the following patch to avoid code
duplication. No functional changes intended.

The only difference is that now flow_limit_cpu_sysctl() will
always compute the flow limit mask on each read operation,
even when read() will not return any byte to user-space.

Note that the new helper is placed under a new #ifdef at
the file start to better fit the usage in the later patch

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
new in v3
---
 net/core/sysctl_net_core.c | 45 +++++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 18 deletions(-)

Comments

kernel test robot Feb. 6, 2023, 8:07 p.m. UTC | #1
Hi Paolo,

I love your patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Paolo-Abeni/net-sysctl-factor-out-cpumask-parsing-helper/20230207-023315
patch link:    https://lore.kernel.org/r/f171c4f78c17c259deb0cae78a26dc274afe9fce.1675708062.git.pabeni%40redhat.com
patch subject: [PATCH v3 net-next 1/4] net-sysctl: factor out cpumask parsing helper
config: ia64-allyesconfig (https://download.01.org/0day-ci/archive/20230207/202302070311.gE92izdH-lkp@intel.com/config)
compiler: ia64-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/f4b9914b6f1b7a7b3e416e1ef67db9ce6ad87f38
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Paolo-Abeni/net-sysctl-factor-out-cpumask-parsing-helper/20230207-023315
        git checkout f4b9914b6f1b7a7b3e416e1ef67db9ce6ad87f38
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=ia64 olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=ia64 SHELL=/bin/bash net/core/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> net/core/sysctl_net_core.c:49:6: warning: no previous prototype for 'dump_cpumask' [-Wmissing-prototypes]
      49 | void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos, struct cpumask *mask)
         |      ^~~~~~~~~~~~


vim +/dump_cpumask +49 net/core/sysctl_net_core.c

    47	
    48	#if IS_ENABLED(CONFIG_NET_FLOW_LIMIT)
  > 49	void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos, struct cpumask *mask)
    50	{
    51		char kbuf[128];
    52		int len;
    53	
    54		if (*ppos || !*lenp) {
    55			*lenp = 0;
    56			return;
    57		}
    58	
    59		len = min(sizeof(kbuf) - 1, *lenp);
    60		len = scnprintf(kbuf, len, "%*pb", cpumask_pr_args(mask));
    61		if (!len) {
    62			*lenp = 0;
    63			return;
    64		}
    65	
    66		if (len < *lenp)
    67			kbuf[len++] = '\n';
    68		memcpy(buffer, kbuf, len);
    69		*lenp = len;
    70		*ppos += len;
    71	}
    72	#endif
    73
kernel test robot Feb. 7, 2023, 11:06 a.m. UTC | #2
Hi Paolo,

I love your patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Paolo-Abeni/net-sysctl-factor-out-cpumask-parsing-helper/20230207-023315
patch link:    https://lore.kernel.org/r/f171c4f78c17c259deb0cae78a26dc274afe9fce.1675708062.git.pabeni%40redhat.com
patch subject: [PATCH v3 net-next 1/4] net-sysctl: factor out cpumask parsing helper
config: i386-randconfig-a004-20230206 (https://download.01.org/0day-ci/archive/20230207/202302071859.cwSYKxyV-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/f4b9914b6f1b7a7b3e416e1ef67db9ce6ad87f38
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Paolo-Abeni/net-sysctl-factor-out-cpumask-parsing-helper/20230207-023315
        git checkout f4b9914b6f1b7a7b3e416e1ef67db9ce6ad87f38
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash net/core/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> net/core/sysctl_net_core.c:49:6: warning: no previous prototype for function 'dump_cpumask' [-Wmissing-prototypes]
   void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos, struct cpumask *mask)
        ^
   net/core/sysctl_net_core.c:49:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos, struct cpumask *mask)
   ^
   static 
   1 warning generated.


vim +/dump_cpumask +49 net/core/sysctl_net_core.c

    47	
    48	#if IS_ENABLED(CONFIG_NET_FLOW_LIMIT)
  > 49	void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos, struct cpumask *mask)
    50	{
    51		char kbuf[128];
    52		int len;
    53	
    54		if (*ppos || !*lenp) {
    55			*lenp = 0;
    56			return;
    57		}
    58	
    59		len = min(sizeof(kbuf) - 1, *lenp);
    60		len = scnprintf(kbuf, len, "%*pb", cpumask_pr_args(mask));
    61		if (!len) {
    62			*lenp = 0;
    63			return;
    64		}
    65	
    66		if (len < *lenp)
    67			kbuf[len++] = '\n';
    68		memcpy(buffer, kbuf, len);
    69		*lenp = len;
    70		*ppos += len;
    71	}
    72	#endif
    73
diff mbox series

Patch

diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index e7b98162c632..31a5adc1ba94 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -45,6 +45,32 @@  EXPORT_SYMBOL(sysctl_fb_tunnels_only_for_init_net);
 int sysctl_devconf_inherit_init_net __read_mostly;
 EXPORT_SYMBOL(sysctl_devconf_inherit_init_net);
 
+#if IS_ENABLED(CONFIG_NET_FLOW_LIMIT)
+void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos, struct cpumask *mask)
+{
+	char kbuf[128];
+	int len;
+
+	if (*ppos || !*lenp) {
+		*lenp = 0;
+		return;
+	}
+
+	len = min(sizeof(kbuf) - 1, *lenp);
+	len = scnprintf(kbuf, len, "%*pb", cpumask_pr_args(mask));
+	if (!len) {
+		*lenp = 0;
+		return;
+	}
+
+	if (len < *lenp)
+		kbuf[len++] = '\n';
+	memcpy(buffer, kbuf, len);
+	*lenp = len;
+	*ppos += len;
+}
+#endif
+
 #ifdef CONFIG_RPS
 static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
 				void *buffer, size_t *lenp, loff_t *ppos)
@@ -155,13 +181,6 @@  static int flow_limit_cpu_sysctl(struct ctl_table *table, int write,
 write_unlock:
 		mutex_unlock(&flow_limit_update_mutex);
 	} else {
-		char kbuf[128];
-
-		if (*ppos || !*lenp) {
-			*lenp = 0;
-			goto done;
-		}
-
 		cpumask_clear(mask);
 		rcu_read_lock();
 		for_each_possible_cpu(i) {
@@ -171,17 +190,7 @@  static int flow_limit_cpu_sysctl(struct ctl_table *table, int write,
 		}
 		rcu_read_unlock();
 
-		len = min(sizeof(kbuf) - 1, *lenp);
-		len = scnprintf(kbuf, len, "%*pb", cpumask_pr_args(mask));
-		if (!len) {
-			*lenp = 0;
-			goto done;
-		}
-		if (len < *lenp)
-			kbuf[len++] = '\n';
-		memcpy(buffer, kbuf, len);
-		*lenp = len;
-		*ppos += len;
+		dump_cpumask(buffer, lenp, ppos, mask);
 	}
 
 done: