All of lore.kernel.org
 help / color / mirror / Atom feed
* [netfilter-nf-next:testing 9/12] net/netfilter/core.c:130:26: warning: variable 'hook_bpf_prog' set but not used
@ 2022-05-19 21:42 kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2022-05-19 21:42 UTC (permalink / raw)
  To: Florian Westphal; +Cc: kbuild-all, linux-kernel

tree:   git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git testing
head:   4456ac35299c131e2ac26b4dc025b257d810277b
commit: 11b2910d788799e8c68df305994260fd79a61e10 [9/12] netfilter: add bpf base hook program generator
config: alpha-defconfig (https://download.01.org/0day-ci/archive/20220520/202205200503.Y3uqHqTF-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 11.3.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://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git/commit/?id=11b2910d788799e8c68df305994260fd79a61e10
        git remote add netfilter-nf-next git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git
        git fetch --no-tags netfilter-nf-next testing
        git checkout 11b2910d788799e8c68df305994260fd79a61e10
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=alpha SHELL=/bin/bash net/netfilter/

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

All warnings (new ones prefixed by >>):

   net/netfilter/core.c: In function 'nf_hook_entries_grow':
>> net/netfilter/core.c:130:26: warning: variable 'hook_bpf_prog' set but not used [-Wunused-but-set-variable]
     130 |         struct bpf_prog *hook_bpf_prog;
         |                          ^~~~~~~~~~~~~
   net/netfilter/core.c: In function '__nf_hook_entries_try_shrink':
   net/netfilter/core.c:269:26: warning: unused variable 'hook_bpf_prog' [-Wunused-variable]
     269 |         struct bpf_prog *hook_bpf_prog = NULL;
         |                          ^~~~~~~~~~~~~


vim +/hook_bpf_prog +130 net/netfilter/core.c

   123	
   124	static struct nf_hook_entries *
   125	nf_hook_entries_grow(const struct nf_hook_entries *old,
   126			     const struct nf_hook_ops *reg)
   127	{
   128		unsigned int i, alloc_entries, nhooks, old_entries;
   129		struct nf_hook_ops **orig_ops = NULL;
 > 130		struct bpf_prog *hook_bpf_prog;
   131		struct nf_hook_ops **new_ops;
   132		struct nf_hook_entries *new;
   133		bool inserted = false;
   134	
   135		alloc_entries = 1;
   136		old_entries = old ? old->num_hook_entries : 0;
   137	
   138		if (old) {
   139			orig_ops = nf_hook_entries_get_hook_ops(old);
   140	
   141			for (i = 0; i < old_entries; i++) {
   142				if (orig_ops[i] != &dummy_ops)
   143					alloc_entries++;
   144			}
   145		}
   146	
   147		if (alloc_entries > MAX_HOOK_COUNT)
   148			return ERR_PTR(-E2BIG);
   149	
   150		new = allocate_hook_entries_size(alloc_entries);
   151		if (!new)
   152			return ERR_PTR(-ENOMEM);
   153	
   154		new_ops = nf_hook_entries_get_hook_ops(new);
   155	
   156		i = 0;
   157		nhooks = 0;
   158		while (i < old_entries) {
   159			if (orig_ops[i] == &dummy_ops) {
   160				++i;
   161				continue;
   162			}
   163	
   164			if (inserted || reg->priority > orig_ops[i]->priority) {
   165				new_ops[nhooks] = (void *)orig_ops[i];
   166				new->hooks[nhooks] = old->hooks[i];
   167				i++;
   168			} else {
   169				new_ops[nhooks] = (void *)reg;
   170				new->hooks[nhooks].hook = reg->hook;
   171				new->hooks[nhooks].priv = reg->priv;
   172				inserted = true;
   173			}
   174			nhooks++;
   175		}
   176	
   177		if (!inserted) {
   178			new_ops[nhooks] = (void *)reg;
   179			new->hooks[nhooks].hook = reg->hook;
   180			new->hooks[nhooks].priv = reg->priv;
   181		}
   182	
   183		hook_bpf_prog = nf_hook_bpf_create(new);
   184	
   185		/* allocate_hook_entries_size() pre-inits ->hook_prog
   186		 * to a fallback program that calls nf_hook_slow().
   187		 *
   188		 * Alternatively we could have nf_hook_entries_grow()
   189		 * return an error here.
   190		 */
   191	#if IS_ENABLED(CONFIG_NF_HOOK_BPF)
   192		if (hook_bpf_prog) {
   193			struct bpf_prog *old_prog = NULL;
   194	
   195			new->hook_prog = hook_bpf_prog;
   196	
   197			if (old)
   198				old_prog = old->hook_prog;
   199	
   200			nf_hook_bpf_change_prog(BPF_DISPATCHER_PTR(nf_hook_base),
   201						old_prog, hook_bpf_prog);
   202		}
   203	#endif
   204		return new;
   205	}
   206	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

* [netfilter-nf-next:testing 9/12] net/netfilter/core.c:130:26: warning: variable 'hook_bpf_prog' set but not used
@ 2022-05-19 21:54 kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2022-05-19 21:54 UTC (permalink / raw)
  To: Florian Westphal; +Cc: kbuild-all, linux-kernel

tree:   git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git testing
head:   4456ac35299c131e2ac26b4dc025b257d810277b
commit: 11b2910d788799e8c68df305994260fd79a61e10 [9/12] netfilter: add bpf base hook program generator
config: i386-randconfig-a005 (https://download.01.org/0day-ci/archive/20220520/202205200540.Em86BBF9-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-1) 11.3.0
reproduce (this is a W=1 build):
        # https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git/commit/?id=11b2910d788799e8c68df305994260fd79a61e10
        git remote add netfilter-nf-next git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git
        git fetch --no-tags netfilter-nf-next testing
        git checkout 11b2910d788799e8c68df305994260fd79a61e10
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash net/netfilter/

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

All warnings (new ones prefixed by >>):

   net/netfilter/core.c: In function 'nf_hook_entries_grow':
>> net/netfilter/core.c:130:26: warning: variable 'hook_bpf_prog' set but not used [-Wunused-but-set-variable]
     130 |         struct bpf_prog *hook_bpf_prog;
         |                          ^~~~~~~~~~~~~
   net/netfilter/core.c: In function '__nf_hook_entries_try_shrink':
>> net/netfilter/core.c:269:26: warning: unused variable 'hook_bpf_prog' [-Wunused-variable]
     269 |         struct bpf_prog *hook_bpf_prog = NULL;
         |                          ^~~~~~~~~~~~~


vim +/hook_bpf_prog +130 net/netfilter/core.c

   123	
   124	static struct nf_hook_entries *
   125	nf_hook_entries_grow(const struct nf_hook_entries *old,
   126			     const struct nf_hook_ops *reg)
   127	{
   128		unsigned int i, alloc_entries, nhooks, old_entries;
   129		struct nf_hook_ops **orig_ops = NULL;
 > 130		struct bpf_prog *hook_bpf_prog;
   131		struct nf_hook_ops **new_ops;
   132		struct nf_hook_entries *new;
   133		bool inserted = false;
   134	
   135		alloc_entries = 1;
   136		old_entries = old ? old->num_hook_entries : 0;
   137	
   138		if (old) {
   139			orig_ops = nf_hook_entries_get_hook_ops(old);
   140	
   141			for (i = 0; i < old_entries; i++) {
   142				if (orig_ops[i] != &dummy_ops)
   143					alloc_entries++;
   144			}
   145		}
   146	
   147		if (alloc_entries > MAX_HOOK_COUNT)
   148			return ERR_PTR(-E2BIG);
   149	
   150		new = allocate_hook_entries_size(alloc_entries);
   151		if (!new)
   152			return ERR_PTR(-ENOMEM);
   153	
   154		new_ops = nf_hook_entries_get_hook_ops(new);
   155	
   156		i = 0;
   157		nhooks = 0;
   158		while (i < old_entries) {
   159			if (orig_ops[i] == &dummy_ops) {
   160				++i;
   161				continue;
   162			}
   163	
   164			if (inserted || reg->priority > orig_ops[i]->priority) {
   165				new_ops[nhooks] = (void *)orig_ops[i];
   166				new->hooks[nhooks] = old->hooks[i];
   167				i++;
   168			} else {
   169				new_ops[nhooks] = (void *)reg;
   170				new->hooks[nhooks].hook = reg->hook;
   171				new->hooks[nhooks].priv = reg->priv;
   172				inserted = true;
   173			}
   174			nhooks++;
   175		}
   176	
   177		if (!inserted) {
   178			new_ops[nhooks] = (void *)reg;
   179			new->hooks[nhooks].hook = reg->hook;
   180			new->hooks[nhooks].priv = reg->priv;
   181		}
   182	
   183		hook_bpf_prog = nf_hook_bpf_create(new);
   184	
   185		/* allocate_hook_entries_size() pre-inits ->hook_prog
   186		 * to a fallback program that calls nf_hook_slow().
   187		 *
   188		 * Alternatively we could have nf_hook_entries_grow()
   189		 * return an error here.
   190		 */
   191	#if IS_ENABLED(CONFIG_NF_HOOK_BPF)
   192		if (hook_bpf_prog) {
   193			struct bpf_prog *old_prog = NULL;
   194	
   195			new->hook_prog = hook_bpf_prog;
   196	
   197			if (old)
   198				old_prog = old->hook_prog;
   199	
   200			nf_hook_bpf_change_prog(BPF_DISPATCHER_PTR(nf_hook_base),
   201						old_prog, hook_bpf_prog);
   202		}
   203	#endif
   204		return new;
   205	}
   206	
   207	static void hooks_validate(const struct nf_hook_entries *hooks)
   208	{
   209	#ifdef CONFIG_DEBUG_MISC
   210		struct nf_hook_ops **orig_ops;
   211		int prio = INT_MIN;
   212		size_t i = 0;
   213	
   214		orig_ops = nf_hook_entries_get_hook_ops(hooks);
   215	
   216		for (i = 0; i < hooks->num_hook_entries; i++) {
   217			if (orig_ops[i] == &dummy_ops)
   218				continue;
   219	
   220			WARN_ON(orig_ops[i]->priority < prio);
   221	
   222			if (orig_ops[i]->priority > prio)
   223				prio = orig_ops[i]->priority;
   224		}
   225	#endif
   226	}
   227	
   228	int nf_hook_entries_insert_raw(struct nf_hook_entries __rcu **pp,
   229					const struct nf_hook_ops *reg)
   230	{
   231		struct nf_hook_entries *new_hooks;
   232		struct nf_hook_entries *p;
   233	
   234		p = rcu_dereference_raw(*pp);
   235		new_hooks = nf_hook_entries_grow(p, reg);
   236		if (IS_ERR(new_hooks))
   237			return PTR_ERR(new_hooks);
   238	
   239		hooks_validate(new_hooks);
   240	
   241		rcu_assign_pointer(*pp, new_hooks);
   242	
   243		BUG_ON(p == new_hooks);
   244		nf_hook_entries_free(p);
   245		return 0;
   246	}
   247	EXPORT_SYMBOL_GPL(nf_hook_entries_insert_raw);
   248	
   249	/*
   250	 * __nf_hook_entries_try_shrink - try to shrink hook array
   251	 *
   252	 * @old -- current hook blob at @pp
   253	 * @pp -- location of hook blob
   254	 *
   255	 * Hook unregistration must always succeed, so to-be-removed hooks
   256	 * are replaced by a dummy one that will just move to next hook.
   257	 *
   258	 * This counts the current dummy hooks, attempts to allocate new blob,
   259	 * copies the live hooks, then replaces and discards old one.
   260	 *
   261	 * return values:
   262	 *
   263	 * Returns address to free, or NULL.
   264	 */
   265	static void *__nf_hook_entries_try_shrink(struct nf_hook_entries *old,
   266						  struct nf_hook_entries __rcu **pp)
   267	{
   268		unsigned int i, j, skip = 0, hook_entries;
 > 269		struct bpf_prog *hook_bpf_prog = NULL;
   270		struct nf_hook_entries *new = NULL;
   271		struct nf_hook_ops **orig_ops;
   272		struct nf_hook_ops **new_ops;
   273	
   274		if (WARN_ON_ONCE(!old))
   275			return NULL;
   276	
   277		orig_ops = nf_hook_entries_get_hook_ops(old);
   278		for (i = 0; i < old->num_hook_entries; i++) {
   279			if (orig_ops[i] == &dummy_ops)
   280				skip++;
   281		}
   282	
   283		/* if skip == hook_entries all hooks have been removed */
   284		hook_entries = old->num_hook_entries;
   285		if (skip == hook_entries)
   286			goto out_assign;
   287	
   288		if (skip == 0)
   289			return NULL;
   290	
   291		hook_entries -= skip;
   292		new = allocate_hook_entries_size(hook_entries);
   293		if (!new) {
   294	#if IS_ENABLED(CONFIG_NF_HOOK_BPF)
   295			struct bpf_prog *old_prog = old->hook_prog;
   296	
   297			WRITE_ONCE(old->hook_prog, fallback_nf_hook_slow);
   298			nf_hook_bpf_change_prog(BPF_DISPATCHER_PTR(nf_hook_base), old_prog, NULL);
   299	#endif
   300			return NULL;
   301		}
   302	
   303		new_ops = nf_hook_entries_get_hook_ops(new);
   304		for (i = 0, j = 0; i < old->num_hook_entries; i++) {
   305			if (orig_ops[i] == &dummy_ops)
   306				continue;
   307			new->hooks[j] = old->hooks[i];
   308			new_ops[j] = (void *)orig_ops[i];
   309			j++;
   310		}
   311		hooks_validate(new);
   312	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

end of thread, other threads:[~2022-05-19 21:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-19 21:42 [netfilter-nf-next:testing 9/12] net/netfilter/core.c:130:26: warning: variable 'hook_bpf_prog' set but not used kernel test robot
2022-05-19 21:54 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.