diff mbox series

[net-next,10/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in INET_MATCH()

Message ID 20220511233757.2001218-11-eric.dumazet@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: add annotations for sk->sk_bound_dev_if | 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: 1118 this patch: 1123
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 142 this patch: 142
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1123 this patch: 1123
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 62 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Eric Dumazet May 11, 2022, 11:37 p.m. UTC
From: Eric Dumazet <edumazet@google.com>

INET_MATCH() runs without holding a lock on the socket.

We probably need to annotate most reads.

This patch makes INET_MATCH() an inline function
to ease our changes. This also allows us
to add some __always_unused qualifiers.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 include/net/inet_hashtables.h | 52 +++++++++++++++++++++++++----------
 1 file changed, 38 insertions(+), 14 deletions(-)

Comments

kernel test robot May 12, 2022, 1:15 p.m. UTC | #1
Hi Eric,

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/Eric-Dumazet/net-add-annotations-for-sk-sk_bound_dev_if/20220512-073914
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git b57c7e8b76c646cf77ce4353a779a8b781592209
config: hexagon-randconfig-r035-20220512 (https://download.01.org/0day-ci/archive/20220512/202205122132.HUrst9JA-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 18dd123c56754edf62c7042dcf23185c3727610f)
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/c92cfd9f3ecb483ff055edb02f7498494b96ba68
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Eric-Dumazet/net-add-annotations-for-sk-sk_bound_dev_if/20220512-073914
        git checkout c92cfd9f3ecb483ff055edb02f7498494b96ba68
        # 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=hexagon SHELL=/bin/bash net/ipv4/

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/ipv4/inet_hashtables.c:413:34: warning: variable 'acookie' is uninitialized when used here [-Wuninitialized]
                   if (likely(INET_MATCH(sk, net, acookie,
                                                  ^~~~~~~
   include/linux/compiler.h:77:40: note: expanded from macro 'likely'
   # define likely(x)      __builtin_expect(!!(x), 1)
                                               ^
   net/ipv4/inet_hashtables.c:398:2: note: variable 'acookie' is declared here
           INET_ADDR_COOKIE(acookie, saddr, daddr);
           ^
   include/net/inet_hashtables.h:330:2: note: expanded from macro 'INET_ADDR_COOKIE'
           const int __name __deprecated __always_unused
           ^
   net/ipv4/inet_hashtables.c:468:35: warning: variable 'acookie' is uninitialized when used here [-Wuninitialized]
                   if (likely(INET_MATCH(sk2, net, acookie,
                                                   ^~~~~~~
   include/linux/compiler.h:77:40: note: expanded from macro 'likely'
   # define likely(x)      __builtin_expect(!!(x), 1)
                                               ^
   net/ipv4/inet_hashtables.c:452:2: note: variable 'acookie' is declared here
           INET_ADDR_COOKIE(acookie, saddr, daddr);
           ^
   include/net/inet_hashtables.h:330:2: note: expanded from macro 'INET_ADDR_COOKIE'
           const int __name __deprecated __always_unused
           ^
   net/ipv4/inet_hashtables.c:535:38: warning: variable 'acookie' is uninitialized when used here [-Wuninitialized]
                           if (unlikely(INET_MATCH(esk, net, acookie,
                                                             ^~~~~~~
   include/linux/compiler.h:78:42: note: expanded from macro 'unlikely'
   # define unlikely(x)    __builtin_expect(!!(x), 0)
                                               ^
   net/ipv4/inet_hashtables.c:529:2: note: variable 'acookie' is declared here
           INET_ADDR_COOKIE(acookie, sk->sk_daddr, sk->sk_rcv_saddr);
           ^
   include/net/inet_hashtables.h:330:2: note: expanded from macro 'INET_ADDR_COOKIE'
           const int __name __deprecated __always_unused
           ^
   3 warnings generated.
--
>> net/ipv4/udp.c:2566:27: warning: variable 'acookie' is uninitialized when used here [-Wuninitialized]
                   if (INET_MATCH(sk, net, acookie, rmt_addr,
                                           ^~~~~~~
   net/ipv4/udp.c:2561:2: note: variable 'acookie' is declared here
           INET_ADDR_COOKIE(acookie, rmt_addr, loc_addr);
           ^
   include/net/inet_hashtables.h:330:2: note: expanded from macro 'INET_ADDR_COOKIE'
           const int __name __deprecated __always_unused
           ^
   1 warning generated.


vim +/acookie +413 net/ipv4/inet_hashtables.c

2c13270b441054 Eric Dumazet     2015-03-15  391  
c67499c0e77206 Pavel Emelyanov  2008-01-31  392  struct sock *__inet_lookup_established(struct net *net,
c67499c0e77206 Pavel Emelyanov  2008-01-31  393  				  struct inet_hashinfo *hashinfo,
77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  394  				  const __be32 saddr, const __be16 sport,
77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  395  				  const __be32 daddr, const u16 hnum,
3fa6f616a7a4d0 David Ahern      2017-08-07  396  				  const int dif, const int sdif)
77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  397  {
c7228317441f4d Joe Perches      2014-05-13  398  	INET_ADDR_COOKIE(acookie, saddr, daddr);
77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  399  	const __portpair ports = INET_COMBINED_PORTS(sport, hnum);
77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  400  	struct sock *sk;
3ab5aee7fe840b Eric Dumazet     2008-11-16  401  	const struct hlist_nulls_node *node;
77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  402  	/* Optimize here for direct hit, only listening connections can
77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  403  	 * have wildcards anyways.
77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  404  	 */
9f26b3add3783c Pavel Emelyanov  2008-06-16  405  	unsigned int hash = inet_ehashfn(net, daddr, hnum, saddr, sport);
f373b53b5fe67a Eric Dumazet     2009-10-09  406  	unsigned int slot = hash & hashinfo->ehash_mask;
3ab5aee7fe840b Eric Dumazet     2008-11-16  407  	struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  408  
3ab5aee7fe840b Eric Dumazet     2008-11-16  409  begin:
3ab5aee7fe840b Eric Dumazet     2008-11-16  410  	sk_nulls_for_each_rcu(sk, node, &head->chain) {
ce43b03e888947 Eric Dumazet     2012-11-30  411  		if (sk->sk_hash != hash)
ce43b03e888947 Eric Dumazet     2012-11-30  412  			continue;
ce43b03e888947 Eric Dumazet     2012-11-30 @413  		if (likely(INET_MATCH(sk, net, acookie,
3fa6f616a7a4d0 David Ahern      2017-08-07  414  				      saddr, daddr, ports, dif, sdif))) {
41c6d650f6537e Reshetova, Elena 2017-06-30  415  			if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))
05dbc7b59481ca Eric Dumazet     2013-10-03  416  				goto out;
ce43b03e888947 Eric Dumazet     2012-11-30  417  			if (unlikely(!INET_MATCH(sk, net, acookie,
3fa6f616a7a4d0 David Ahern      2017-08-07  418  						 saddr, daddr, ports,
3fa6f616a7a4d0 David Ahern      2017-08-07  419  						 dif, sdif))) {
05dbc7b59481ca Eric Dumazet     2013-10-03  420  				sock_gen_put(sk);
3ab5aee7fe840b Eric Dumazet     2008-11-16  421  				goto begin;
77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  422  			}
05dbc7b59481ca Eric Dumazet     2013-10-03  423  			goto found;
3ab5aee7fe840b Eric Dumazet     2008-11-16  424  		}
3ab5aee7fe840b Eric Dumazet     2008-11-16  425  	}
3ab5aee7fe840b Eric Dumazet     2008-11-16  426  	/*
3ab5aee7fe840b Eric Dumazet     2008-11-16  427  	 * if the nulls value we got at the end of this lookup is
3ab5aee7fe840b Eric Dumazet     2008-11-16  428  	 * not the expected one, we must restart lookup.
3ab5aee7fe840b Eric Dumazet     2008-11-16  429  	 * We probably met an item that was moved to another chain.
3ab5aee7fe840b Eric Dumazet     2008-11-16  430  	 */
3ab5aee7fe840b Eric Dumazet     2008-11-16  431  	if (get_nulls_value(node) != slot)
3ab5aee7fe840b Eric Dumazet     2008-11-16  432  		goto begin;
77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  433  out:
05dbc7b59481ca Eric Dumazet     2013-10-03  434  	sk = NULL;
05dbc7b59481ca Eric Dumazet     2013-10-03  435  found:
77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  436  	return sk;
77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  437  }
77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  438  EXPORT_SYMBOL_GPL(__inet_lookup_established);
77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  439
Eric Dumazet May 12, 2022, 4:13 p.m. UTC | #2
On Thu, May 12, 2022 at 6:16 AM kernel test robot <lkp@intel.com> wrote:
>
> Hi Eric,
>
> 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/Eric-Dumazet/net-add-annotations-for-sk-sk_bound_dev_if/20220512-073914
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git b57c7e8b76c646cf77ce4353a779a8b781592209
> config: hexagon-randconfig-r035-20220512 (https://download.01.org/0day-ci/archive/20220512/202205122132.HUrst9JA-lkp@intel.com/config)
> compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 18dd123c56754edf62c7042dcf23185c3727610f)
> 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/c92cfd9f3ecb483ff055edb02f7498494b96ba68
>         git remote add linux-review https://github.com/intel-lab-lkp/linux
>         git fetch --no-tags linux-review Eric-Dumazet/net-add-annotations-for-sk-sk_bound_dev_if/20220512-073914
>         git checkout c92cfd9f3ecb483ff055edb02f7498494b96ba68
>         # 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=hexagon SHELL=/bin/bash net/ipv4/

Thank you for the instructions.
Unfortunately this is failing for me.

I have tested ARCH=i386 before sending the series, I am not sure what
the issue is for ARCH=hexagon and the cross compiler.

Maybe __always_unused is not yet understood for this combination.

It might be the time to just use __addrpair even on 32bit arches...

Then we can remove saddr,daddr args from INET_MATCH()

diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h
index 5d3fa071d754601149c9ad0dd559f074ac58deaa..34ddb54506dd02e702dd20cbe8b7dba006130c5a
100644
--- a/include/net/inet_hashtables.h
+++ b/include/net/inet_hashtables.h
@@ -295,7 +295,6 @@ static inline struct sock
*inet_lookup_listener(struct net *net,
        ((__force __portpair)(((__u32)(__dport) << 16) | (__force
__u32)(__be16)(__sport)))
 #endif

-#if (BITS_PER_LONG == 64)
 #ifdef __BIG_ENDIAN
 #define INET_ADDR_COOKIE(__name, __saddr, __daddr) \
        const __addrpair __name = (__force __addrpair) ( \
@@ -325,30 +324,6 @@ static inline bool INET_MATCH(const struct sock
*sk, struct net *net,
        bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
        return bound_dev_if == dif || bound_dev_if == sdif;
 }
-#else /* 32-bit arch */
-#define INET_ADDR_COOKIE(__name, __saddr, __daddr) \
-       const int __name __deprecated __always_unused
-
-static inline bool INET_MATCH(const struct sock *sk, struct net *net,
-                             const __addrpair __always_unused cookie,
-                             const __be32 saddr,
-                             const __be32 daddr,
-                             const __portpair ports,
-                             const int dif,
-                             const int sdif)
-{
-       int bound_dev_if;
-
-       if (!net_eq(sock_net(sk), net) ||
-           sk->sk_portpair != ports ||
-           sk->sk_daddr != saddr ||
-           sk->sk_rcv_saddr != daddr)
-               return false;
-
-       bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
-       return bound_dev_if == dif || bound_dev_if == sdif;
-}
-#endif /* 64-bit arch */


I will cook a small patch to simplify INET_MATCH(), then if/when
merged, I will resend the pach series about sk_bound_dev_if.

Thanks.




>
> 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/ipv4/inet_hashtables.c:413:34: warning: variable 'acookie' is uninitialized when used here [-Wuninitialized]
>                    if (likely(INET_MATCH(sk, net, acookie,
>                                                   ^~~~~~~
>    include/linux/compiler.h:77:40: note: expanded from macro 'likely'
>    # define likely(x)      __builtin_expect(!!(x), 1)
>                                                ^
>    net/ipv4/inet_hashtables.c:398:2: note: variable 'acookie' is declared here
>            INET_ADDR_COOKIE(acookie, saddr, daddr);
>            ^
>    include/net/inet_hashtables.h:330:2: note: expanded from macro 'INET_ADDR_COOKIE'
>            const int __name __deprecated __always_unused
>            ^
>    net/ipv4/inet_hashtables.c:468:35: warning: variable 'acookie' is uninitialized when used here [-Wuninitialized]
>                    if (likely(INET_MATCH(sk2, net, acookie,
>                                                    ^~~~~~~
>    include/linux/compiler.h:77:40: note: expanded from macro 'likely'
>    # define likely(x)      __builtin_expect(!!(x), 1)
>                                                ^
>    net/ipv4/inet_hashtables.c:452:2: note: variable 'acookie' is declared here
>            INET_ADDR_COOKIE(acookie, saddr, daddr);
>            ^
>    include/net/inet_hashtables.h:330:2: note: expanded from macro 'INET_ADDR_COOKIE'
>            const int __name __deprecated __always_unused
>            ^
>    net/ipv4/inet_hashtables.c:535:38: warning: variable 'acookie' is uninitialized when used here [-Wuninitialized]
>                            if (unlikely(INET_MATCH(esk, net, acookie,
>                                                              ^~~~~~~
>    include/linux/compiler.h:78:42: note: expanded from macro 'unlikely'
>    # define unlikely(x)    __builtin_expect(!!(x), 0)
>                                                ^
>    net/ipv4/inet_hashtables.c:529:2: note: variable 'acookie' is declared here
>            INET_ADDR_COOKIE(acookie, sk->sk_daddr, sk->sk_rcv_saddr);
>            ^
>    include/net/inet_hashtables.h:330:2: note: expanded from macro 'INET_ADDR_COOKIE'
>            const int __name __deprecated __always_unused
>            ^
>    3 warnings generated.
> --
> >> net/ipv4/udp.c:2566:27: warning: variable 'acookie' is uninitialized when used here [-Wuninitialized]
>                    if (INET_MATCH(sk, net, acookie, rmt_addr,
>                                            ^~~~~~~
>    net/ipv4/udp.c:2561:2: note: variable 'acookie' is declared here
>            INET_ADDR_COOKIE(acookie, rmt_addr, loc_addr);
>            ^
>    include/net/inet_hashtables.h:330:2: note: expanded from macro 'INET_ADDR_COOKIE'
>            const int __name __deprecated __always_unused
>            ^
>    1 warning generated.
>
>
> vim +/acookie +413 net/ipv4/inet_hashtables.c
>
> 2c13270b441054 Eric Dumazet     2015-03-15  391
> c67499c0e77206 Pavel Emelyanov  2008-01-31  392  struct sock *__inet_lookup_established(struct net *net,
> c67499c0e77206 Pavel Emelyanov  2008-01-31  393                                   struct inet_hashinfo *hashinfo,
> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  394                                   const __be32 saddr, const __be16 sport,
> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  395                                   const __be32 daddr, const u16 hnum,
> 3fa6f616a7a4d0 David Ahern      2017-08-07  396                                   const int dif, const int sdif)
> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  397  {
> c7228317441f4d Joe Perches      2014-05-13  398         INET_ADDR_COOKIE(acookie, saddr, daddr);
> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  399         const __portpair ports = INET_COMBINED_PORTS(sport, hnum);
> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  400         struct sock *sk;
> 3ab5aee7fe840b Eric Dumazet     2008-11-16  401         const struct hlist_nulls_node *node;
> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  402         /* Optimize here for direct hit, only listening connections can
> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  403          * have wildcards anyways.
> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  404          */
> 9f26b3add3783c Pavel Emelyanov  2008-06-16  405         unsigned int hash = inet_ehashfn(net, daddr, hnum, saddr, sport);
> f373b53b5fe67a Eric Dumazet     2009-10-09  406         unsigned int slot = hash & hashinfo->ehash_mask;
> 3ab5aee7fe840b Eric Dumazet     2008-11-16  407         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  408
> 3ab5aee7fe840b Eric Dumazet     2008-11-16  409  begin:
> 3ab5aee7fe840b Eric Dumazet     2008-11-16  410         sk_nulls_for_each_rcu(sk, node, &head->chain) {
> ce43b03e888947 Eric Dumazet     2012-11-30  411                 if (sk->sk_hash != hash)
> ce43b03e888947 Eric Dumazet     2012-11-30  412                         continue;
> ce43b03e888947 Eric Dumazet     2012-11-30 @413                 if (likely(INET_MATCH(sk, net, acookie,
> 3fa6f616a7a4d0 David Ahern      2017-08-07  414                                       saddr, daddr, ports, dif, sdif))) {
> 41c6d650f6537e Reshetova, Elena 2017-06-30  415                         if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))
> 05dbc7b59481ca Eric Dumazet     2013-10-03  416                                 goto out;
> ce43b03e888947 Eric Dumazet     2012-11-30  417                         if (unlikely(!INET_MATCH(sk, net, acookie,
> 3fa6f616a7a4d0 David Ahern      2017-08-07  418                                                  saddr, daddr, ports,
> 3fa6f616a7a4d0 David Ahern      2017-08-07  419                                                  dif, sdif))) {
> 05dbc7b59481ca Eric Dumazet     2013-10-03  420                                 sock_gen_put(sk);
> 3ab5aee7fe840b Eric Dumazet     2008-11-16  421                                 goto begin;
> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  422                         }
> 05dbc7b59481ca Eric Dumazet     2013-10-03  423                         goto found;
> 3ab5aee7fe840b Eric Dumazet     2008-11-16  424                 }
> 3ab5aee7fe840b Eric Dumazet     2008-11-16  425         }
> 3ab5aee7fe840b Eric Dumazet     2008-11-16  426         /*
> 3ab5aee7fe840b Eric Dumazet     2008-11-16  427          * if the nulls value we got at the end of this lookup is
> 3ab5aee7fe840b Eric Dumazet     2008-11-16  428          * not the expected one, we must restart lookup.
> 3ab5aee7fe840b Eric Dumazet     2008-11-16  429          * We probably met an item that was moved to another chain.
> 3ab5aee7fe840b Eric Dumazet     2008-11-16  430          */
> 3ab5aee7fe840b Eric Dumazet     2008-11-16  431         if (get_nulls_value(node) != slot)
> 3ab5aee7fe840b Eric Dumazet     2008-11-16  432                 goto begin;
> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  433  out:
> 05dbc7b59481ca Eric Dumazet     2013-10-03  434         sk = NULL;
> 05dbc7b59481ca Eric Dumazet     2013-10-03  435  found:
> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  436         return sk;
> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  437  }
> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  438  EXPORT_SYMBOL_GPL(__inet_lookup_established);
> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  439
>
> --
> 0-DAY CI Kernel Test Service
> https://01.org/lkp
Chen, Rong A May 20, 2022, 8:40 a.m. UTC | #3
On 5/13/2022 12:13 AM, Eric Dumazet wrote:
> On Thu, May 12, 2022 at 6:16 AM kernel test robot <lkp@intel.com> wrote:
>>
>> Hi Eric,
>>
>> 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/Eric-Dumazet/net-add-annotations-for-sk-sk_bound_dev_if/20220512-073914
>> base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git b57c7e8b76c646cf77ce4353a779a8b781592209
>> config: hexagon-randconfig-r035-20220512 (https://download.01.org/0day-ci/archive/20220512/202205122132.HUrst9JA-lkp@intel.com/config)
>> compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 18dd123c56754edf62c7042dcf23185c3727610f)
>> 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/c92cfd9f3ecb483ff055edb02f7498494b96ba68
>>          git remote add linux-review https://github.com/intel-lab-lkp/linux
>>          git fetch --no-tags linux-review Eric-Dumazet/net-add-annotations-for-sk-sk_bound_dev_if/20220512-073914
>>          git checkout c92cfd9f3ecb483ff055edb02f7498494b96ba68
>>          # 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=hexagon SHELL=/bin/bash net/ipv4/
> 
> Thank you for the instructions.
> Unfortunately this is failing for me.

Hi Eric,

Can you share the problem you met?

Best Regards,
Rong Chen

> 
> I have tested ARCH=i386 before sending the series, I am not sure what
> the issue is for ARCH=hexagon and the cross compiler.
> 
> Maybe __always_unused is not yet understood for this combination.
> 
> It might be the time to just use __addrpair even on 32bit arches...
> 
> Then we can remove saddr,daddr args from INET_MATCH()
> 
> diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h
> index 5d3fa071d754601149c9ad0dd559f074ac58deaa..34ddb54506dd02e702dd20cbe8b7dba006130c5a
> 100644
> --- a/include/net/inet_hashtables.h
> +++ b/include/net/inet_hashtables.h
> @@ -295,7 +295,6 @@ static inline struct sock
> *inet_lookup_listener(struct net *net,
>          ((__force __portpair)(((__u32)(__dport) << 16) | (__force
> __u32)(__be16)(__sport)))
>   #endif
> 
> -#if (BITS_PER_LONG == 64)
>   #ifdef __BIG_ENDIAN
>   #define INET_ADDR_COOKIE(__name, __saddr, __daddr) \
>          const __addrpair __name = (__force __addrpair) ( \
> @@ -325,30 +324,6 @@ static inline bool INET_MATCH(const struct sock
> *sk, struct net *net,
>          bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
>          return bound_dev_if == dif || bound_dev_if == sdif;
>   }
> -#else /* 32-bit arch */
> -#define INET_ADDR_COOKIE(__name, __saddr, __daddr) \
> -       const int __name __deprecated __always_unused
> -
> -static inline bool INET_MATCH(const struct sock *sk, struct net *net,
> -                             const __addrpair __always_unused cookie,
> -                             const __be32 saddr,
> -                             const __be32 daddr,
> -                             const __portpair ports,
> -                             const int dif,
> -                             const int sdif)
> -{
> -       int bound_dev_if;
> -
> -       if (!net_eq(sock_net(sk), net) ||
> -           sk->sk_portpair != ports ||
> -           sk->sk_daddr != saddr ||
> -           sk->sk_rcv_saddr != daddr)
> -               return false;
> -
> -       bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
> -       return bound_dev_if == dif || bound_dev_if == sdif;
> -}
> -#endif /* 64-bit arch */
> 
> 
> I will cook a small patch to simplify INET_MATCH(), then if/when
> merged, I will resend the pach series about sk_bound_dev_if.
> 
> Thanks.
> 
> 
> 
> 
>>
>> 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/ipv4/inet_hashtables.c:413:34: warning: variable 'acookie' is uninitialized when used here [-Wuninitialized]
>>                     if (likely(INET_MATCH(sk, net, acookie,
>>                                                    ^~~~~~~
>>     include/linux/compiler.h:77:40: note: expanded from macro 'likely'
>>     # define likely(x)      __builtin_expect(!!(x), 1)
>>                                                 ^
>>     net/ipv4/inet_hashtables.c:398:2: note: variable 'acookie' is declared here
>>             INET_ADDR_COOKIE(acookie, saddr, daddr);
>>             ^
>>     include/net/inet_hashtables.h:330:2: note: expanded from macro 'INET_ADDR_COOKIE'
>>             const int __name __deprecated __always_unused
>>             ^
>>     net/ipv4/inet_hashtables.c:468:35: warning: variable 'acookie' is uninitialized when used here [-Wuninitialized]
>>                     if (likely(INET_MATCH(sk2, net, acookie,
>>                                                     ^~~~~~~
>>     include/linux/compiler.h:77:40: note: expanded from macro 'likely'
>>     # define likely(x)      __builtin_expect(!!(x), 1)
>>                                                 ^
>>     net/ipv4/inet_hashtables.c:452:2: note: variable 'acookie' is declared here
>>             INET_ADDR_COOKIE(acookie, saddr, daddr);
>>             ^
>>     include/net/inet_hashtables.h:330:2: note: expanded from macro 'INET_ADDR_COOKIE'
>>             const int __name __deprecated __always_unused
>>             ^
>>     net/ipv4/inet_hashtables.c:535:38: warning: variable 'acookie' is uninitialized when used here [-Wuninitialized]
>>                             if (unlikely(INET_MATCH(esk, net, acookie,
>>                                                               ^~~~~~~
>>     include/linux/compiler.h:78:42: note: expanded from macro 'unlikely'
>>     # define unlikely(x)    __builtin_expect(!!(x), 0)
>>                                                 ^
>>     net/ipv4/inet_hashtables.c:529:2: note: variable 'acookie' is declared here
>>             INET_ADDR_COOKIE(acookie, sk->sk_daddr, sk->sk_rcv_saddr);
>>             ^
>>     include/net/inet_hashtables.h:330:2: note: expanded from macro 'INET_ADDR_COOKIE'
>>             const int __name __deprecated __always_unused
>>             ^
>>     3 warnings generated.
>> --
>>>> net/ipv4/udp.c:2566:27: warning: variable 'acookie' is uninitialized when used here [-Wuninitialized]
>>                     if (INET_MATCH(sk, net, acookie, rmt_addr,
>>                                             ^~~~~~~
>>     net/ipv4/udp.c:2561:2: note: variable 'acookie' is declared here
>>             INET_ADDR_COOKIE(acookie, rmt_addr, loc_addr);
>>             ^
>>     include/net/inet_hashtables.h:330:2: note: expanded from macro 'INET_ADDR_COOKIE'
>>             const int __name __deprecated __always_unused
>>             ^
>>     1 warning generated.
>>
>>
>> vim +/acookie +413 net/ipv4/inet_hashtables.c
>>
>> 2c13270b441054 Eric Dumazet     2015-03-15  391
>> c67499c0e77206 Pavel Emelyanov  2008-01-31  392  struct sock *__inet_lookup_established(struct net *net,
>> c67499c0e77206 Pavel Emelyanov  2008-01-31  393                                   struct inet_hashinfo *hashinfo,
>> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  394                                   const __be32 saddr, const __be16 sport,
>> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  395                                   const __be32 daddr, const u16 hnum,
>> 3fa6f616a7a4d0 David Ahern      2017-08-07  396                                   const int dif, const int sdif)
>> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  397  {
>> c7228317441f4d Joe Perches      2014-05-13  398         INET_ADDR_COOKIE(acookie, saddr, daddr);
>> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  399         const __portpair ports = INET_COMBINED_PORTS(sport, hnum);
>> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  400         struct sock *sk;
>> 3ab5aee7fe840b Eric Dumazet     2008-11-16  401         const struct hlist_nulls_node *node;
>> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  402         /* Optimize here for direct hit, only listening connections can
>> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  403          * have wildcards anyways.
>> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  404          */
>> 9f26b3add3783c Pavel Emelyanov  2008-06-16  405         unsigned int hash = inet_ehashfn(net, daddr, hnum, saddr, sport);
>> f373b53b5fe67a Eric Dumazet     2009-10-09  406         unsigned int slot = hash & hashinfo->ehash_mask;
>> 3ab5aee7fe840b Eric Dumazet     2008-11-16  407         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
>> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  408
>> 3ab5aee7fe840b Eric Dumazet     2008-11-16  409  begin:
>> 3ab5aee7fe840b Eric Dumazet     2008-11-16  410         sk_nulls_for_each_rcu(sk, node, &head->chain) {
>> ce43b03e888947 Eric Dumazet     2012-11-30  411                 if (sk->sk_hash != hash)
>> ce43b03e888947 Eric Dumazet     2012-11-30  412                         continue;
>> ce43b03e888947 Eric Dumazet     2012-11-30 @413                 if (likely(INET_MATCH(sk, net, acookie,
>> 3fa6f616a7a4d0 David Ahern      2017-08-07  414                                       saddr, daddr, ports, dif, sdif))) {
>> 41c6d650f6537e Reshetova, Elena 2017-06-30  415                         if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))
>> 05dbc7b59481ca Eric Dumazet     2013-10-03  416                                 goto out;
>> ce43b03e888947 Eric Dumazet     2012-11-30  417                         if (unlikely(!INET_MATCH(sk, net, acookie,
>> 3fa6f616a7a4d0 David Ahern      2017-08-07  418                                                  saddr, daddr, ports,
>> 3fa6f616a7a4d0 David Ahern      2017-08-07  419                                                  dif, sdif))) {
>> 05dbc7b59481ca Eric Dumazet     2013-10-03  420                                 sock_gen_put(sk);
>> 3ab5aee7fe840b Eric Dumazet     2008-11-16  421                                 goto begin;
>> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  422                         }
>> 05dbc7b59481ca Eric Dumazet     2013-10-03  423                         goto found;
>> 3ab5aee7fe840b Eric Dumazet     2008-11-16  424                 }
>> 3ab5aee7fe840b Eric Dumazet     2008-11-16  425         }
>> 3ab5aee7fe840b Eric Dumazet     2008-11-16  426         /*
>> 3ab5aee7fe840b Eric Dumazet     2008-11-16  427          * if the nulls value we got at the end of this lookup is
>> 3ab5aee7fe840b Eric Dumazet     2008-11-16  428          * not the expected one, we must restart lookup.
>> 3ab5aee7fe840b Eric Dumazet     2008-11-16  429          * We probably met an item that was moved to another chain.
>> 3ab5aee7fe840b Eric Dumazet     2008-11-16  430          */
>> 3ab5aee7fe840b Eric Dumazet     2008-11-16  431         if (get_nulls_value(node) != slot)
>> 3ab5aee7fe840b Eric Dumazet     2008-11-16  432                 goto begin;
>> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  433  out:
>> 05dbc7b59481ca Eric Dumazet     2013-10-03  434         sk = NULL;
>> 05dbc7b59481ca Eric Dumazet     2013-10-03  435  found:
>> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  436         return sk;
>> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  437  }
>> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  438  EXPORT_SYMBOL_GPL(__inet_lookup_established);
>> 77a5ba55dab7b4 Pavel Emelyanov  2007-12-20  439
>>
>> --
>> 0-DAY CI Kernel Test Service
>> https://01.org/lkp
>
Eric Dumazet May 20, 2022, 1:17 p.m. UTC | #4
On Fri, May 20, 2022 at 1:40 AM Chen, Rong A <rong.a.chen@intel.com> wrote:
>
>
>
> On 5/13/2022 12:13 AM, Eric Dumazet wrote:
> > On Thu, May 12, 2022 at 6:16 AM kernel test robot <lkp@intel.com> wrote:
> >>
> >> Hi Eric,
> >>
> >> 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/Eric-Dumazet/net-add-annotations-for-sk-sk_bound_dev_if/20220512-073914
> >> base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git b57c7e8b76c646cf77ce4353a779a8b781592209
> >> config: hexagon-randconfig-r035-20220512 (https://download.01.org/0day-ci/archive/20220512/202205122132.HUrst9JA-lkp@intel.com/config)
> >> compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 18dd123c56754edf62c7042dcf23185c3727610f)
> >> 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/c92cfd9f3ecb483ff055edb02f7498494b96ba68
> >>          git remote add linux-review https://github.com/intel-lab-lkp/linux
> >>          git fetch --no-tags linux-review Eric-Dumazet/net-add-annotations-for-sk-sk_bound_dev_if/20220512-073914
> >>          git checkout c92cfd9f3ecb483ff055edb02f7498494b96ba68
> >>          # 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=hexagon SHELL=/bin/bash net/ipv4/
> >
> > Thank you for the instructions.
> > Unfortunately this is failing for me.
>
> Hi Eric,
>
> Can you share the problem you met?

It seems the problem has disappeared on the host where I retried the
recipe this morning.

It is very possible that this was because I started from a fresh
directory, instead of reusing a prior git tree,
hoping to not pull 4 GB of data from the Internet :/
diff mbox series

Patch

diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h
index 98e1ec1a14f0382d1f4f8e85fe5ac2a056d2d6bc..5d3fa071d754601149c9ad0dd559f074ac58deaa 100644
--- a/include/net/inet_hashtables.h
+++ b/include/net/inet_hashtables.h
@@ -307,23 +307,47 @@  static inline struct sock *inet_lookup_listener(struct net *net,
 				   (((__force __u64)(__be32)(__daddr)) << 32) | \
 				   ((__force __u64)(__be32)(__saddr)))
 #endif /* __BIG_ENDIAN */
-#define INET_MATCH(__sk, __net, __cookie, __saddr, __daddr, __ports, __dif, __sdif) \
-	(((__sk)->sk_portpair == (__ports))			&&	\
-	 ((__sk)->sk_addrpair == (__cookie))			&&	\
-	 (((__sk)->sk_bound_dev_if == (__dif))			||	\
-	  ((__sk)->sk_bound_dev_if == (__sdif)))		&&	\
-	 net_eq(sock_net(__sk), (__net)))
+static inline bool INET_MATCH(const struct sock *sk, struct net *net,
+			      const __addrpair cookie,
+			      const __be32 __always_unused saddr,
+			      const __be32 __always_unused daddr,
+			      const __portpair ports,
+			      const int dif,
+			      const int sdif)
+{
+	int bound_dev_if;
+
+	if (!net_eq(sock_net(sk), net) ||
+	    sk->sk_portpair != ports ||
+	    sk->sk_addrpair != cookie)
+		return false;
+
+	bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
+	return bound_dev_if == dif || bound_dev_if == sdif;
+}
 #else /* 32-bit arch */
 #define INET_ADDR_COOKIE(__name, __saddr, __daddr) \
-	const int __name __deprecated __attribute__((unused))
+	const int __name __deprecated __always_unused
 
-#define INET_MATCH(__sk, __net, __cookie, __saddr, __daddr, __ports, __dif, __sdif) \
-	(((__sk)->sk_portpair == (__ports))		&&		\
-	 ((__sk)->sk_daddr	== (__saddr))		&&		\
-	 ((__sk)->sk_rcv_saddr	== (__daddr))		&&		\
-	 (((__sk)->sk_bound_dev_if == (__dif))		||		\
-	  ((__sk)->sk_bound_dev_if == (__sdif)))	&&		\
-	 net_eq(sock_net(__sk), (__net)))
+static inline bool INET_MATCH(const struct sock *sk, struct net *net,
+			      const __addrpair __always_unused cookie,
+			      const __be32 saddr,
+			      const __be32 daddr,
+			      const __portpair ports,
+			      const int dif,
+			      const int sdif)
+{
+	int bound_dev_if;
+
+	if (!net_eq(sock_net(sk), net) ||
+	    sk->sk_portpair != ports ||
+	    sk->sk_daddr != saddr ||
+	    sk->sk_rcv_saddr != daddr)
+		return false;
+
+	bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
+	return bound_dev_if == dif || bound_dev_if == sdif;
+}
 #endif /* 64-bit arch */
 
 /* Sockets in TCP_CLOSE state are _always_ taken out of the hash, so we need