* [PATCH net-next 00/10] net: add annotations for sk->sk_bound_dev_if
@ 2022-05-11 23:37 Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 01/10] net: annotate races around sk->sk_bound_dev_if Eric Dumazet
` (9 more replies)
0 siblings, 10 replies; 20+ messages in thread
From: Eric Dumazet @ 2022-05-11 23:37 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, Eric Dumazet, Eric Dumazet
From: Eric Dumazet <edumazet@google.com>
While writes on sk->sk_bound_dev_if are protected by socket lock,
we have many lockless reads all over the places.
This is based on syzbot report found in the first patch changelog.
Eric Dumazet (10):
net: annotate races around sk->sk_bound_dev_if
sctp: read sk->sk_bound_dev_if once in sctp_rcv()
tcp: sk->sk_bound_dev_if once in inet_request_bound_dev_if()
net: core: add READ_ONCE/WRITE_ONCE annotations for
sk->sk_bound_dev_if
dccp: use READ_ONCE() to read sk->sk_bound_dev_if
inet: add READ_ONCE(sk->sk_bound_dev_if) in inet_csk_bind_conflict()
net_sched: em_meta: add READ_ONCE() in var_sk_bound_if()
l2tp: use add READ_ONCE() to fetch sk->sk_bound_dev_if
ipv6: add READ_ONCE(sk->sk_bound_dev_if) in INET6_MATCH()
inet: add READ_ONCE(sk->sk_bound_dev_if) in INET_MATCH()
include/net/inet6_hashtables.h | 25 +++++++++++-----
include/net/inet_hashtables.h | 52 ++++++++++++++++++++++++---------
include/net/inet_sock.h | 5 ++--
include/net/ip.h | 2 +-
include/net/sock.h | 5 ++--
net/core/sock.c | 11 ++++---
net/dccp/ipv4.c | 2 +-
net/dccp/ipv6.c | 4 +--
net/ipv4/inet_connection_sock.c | 12 +++++---
net/ipv6/datagram.c | 6 ++--
net/ipv6/udp.c | 11 +++----
net/l2tp/l2tp_ip.c | 4 ++-
net/l2tp/l2tp_ip6.c | 8 +++--
net/sched/em_meta.c | 7 +++--
net/sctp/input.c | 4 ++-
15 files changed, 105 insertions(+), 53 deletions(-)
--
2.36.0.512.ge40c2bad7a-goog
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH net-next 01/10] net: annotate races around sk->sk_bound_dev_if
2022-05-11 23:37 [PATCH net-next 00/10] net: add annotations for sk->sk_bound_dev_if Eric Dumazet
@ 2022-05-11 23:37 ` Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 02/10] sctp: read sk->sk_bound_dev_if once in sctp_rcv() Eric Dumazet
` (8 subsequent siblings)
9 siblings, 0 replies; 20+ messages in thread
From: Eric Dumazet @ 2022-05-11 23:37 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, Eric Dumazet, Eric Dumazet, syzbot
From: Eric Dumazet <edumazet@google.com>
UDP sendmsg() is lockless, and reads sk->sk_bound_dev_if while
this field can be changed by another thread.
Adds minimal annotations to avoid KCSAN splats for UDP.
Following patches will add more annotations to potential lockless readers.
BUG: KCSAN: data-race in __ip6_datagram_connect / udpv6_sendmsg
write to 0xffff888136d47a94 of 4 bytes by task 7681 on cpu 0:
__ip6_datagram_connect+0x6e2/0x930 net/ipv6/datagram.c:221
ip6_datagram_connect+0x2a/0x40 net/ipv6/datagram.c:272
inet_dgram_connect+0x107/0x190 net/ipv4/af_inet.c:576
__sys_connect_file net/socket.c:1900 [inline]
__sys_connect+0x197/0x1b0 net/socket.c:1917
__do_sys_connect net/socket.c:1927 [inline]
__se_sys_connect net/socket.c:1924 [inline]
__x64_sys_connect+0x3d/0x50 net/socket.c:1924
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x2b/0x50 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0xae
read to 0xffff888136d47a94 of 4 bytes by task 7670 on cpu 1:
udpv6_sendmsg+0xc60/0x16e0 net/ipv6/udp.c:1436
inet6_sendmsg+0x5f/0x80 net/ipv6/af_inet6.c:652
sock_sendmsg_nosec net/socket.c:705 [inline]
sock_sendmsg net/socket.c:725 [inline]
____sys_sendmsg+0x39a/0x510 net/socket.c:2413
___sys_sendmsg net/socket.c:2467 [inline]
__sys_sendmmsg+0x267/0x4c0 net/socket.c:2553
__do_sys_sendmmsg net/socket.c:2582 [inline]
__se_sys_sendmmsg net/socket.c:2579 [inline]
__x64_sys_sendmmsg+0x53/0x60 net/socket.c:2579
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x2b/0x50 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0xae
value changed: 0x00000000 -> 0xffffff9b
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 PID: 7670 Comm: syz-executor.3 Tainted: G W 5.18.0-rc1-syzkaller-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
I chose to not add Fixes: tag because race has minor consequences
and stable teams busy enough.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
---
include/net/ip.h | 2 +-
include/net/sock.h | 5 +++--
net/ipv6/datagram.c | 6 +++---
net/ipv6/udp.c | 11 ++++++-----
4 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/include/net/ip.h b/include/net/ip.h
index 3984f2c39c4ba8b4d2a4e4dab6d743f0c9faf798..8ad04f60b4132e163381b3a051c3f3d13e57c2ba 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -93,7 +93,7 @@ static inline void ipcm_init_sk(struct ipcm_cookie *ipcm,
ipcm->sockc.mark = inet->sk.sk_mark;
ipcm->sockc.tsflags = inet->sk.sk_tsflags;
- ipcm->oif = inet->sk.sk_bound_dev_if;
+ ipcm->oif = READ_ONCE(inet->sk.sk_bound_dev_if);
ipcm->addr = inet->inet_saddr;
}
diff --git a/include/net/sock.h b/include/net/sock.h
index 73063c88a2499b31c1e8d25dc157d21f93b02bf5..f6663e1d881d16014cc1439f7bb04f5d16b3db4f 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2878,13 +2878,14 @@ static inline void sk_pacing_shift_update(struct sock *sk, int val)
*/
static inline bool sk_dev_equal_l3scope(struct sock *sk, int dif)
{
+ int bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
int mdif;
- if (!sk->sk_bound_dev_if || sk->sk_bound_dev_if == dif)
+ if (!bound_dev_if || bound_dev_if == dif)
return true;
mdif = l3mdev_master_ifindex_by_index(sock_net(sk), dif);
- if (mdif && mdif == sk->sk_bound_dev_if)
+ if (mdif && mdif == bound_dev_if)
return true;
return false;
diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
index 39b2327edc4e993d5a74a03eae8986a9152dea2b..df665d4e8f0f130f1d65e368f1b495fed794b70a 100644
--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -218,11 +218,11 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr,
err = -EINVAL;
goto out;
}
- sk->sk_bound_dev_if = usin->sin6_scope_id;
+ WRITE_ONCE(sk->sk_bound_dev_if, usin->sin6_scope_id);
}
if (!sk->sk_bound_dev_if && (addr_type & IPV6_ADDR_MULTICAST))
- sk->sk_bound_dev_if = np->mcast_oif;
+ WRITE_ONCE(sk->sk_bound_dev_if, np->mcast_oif);
/* Connect to link-local address requires an interface */
if (!sk->sk_bound_dev_if) {
@@ -798,7 +798,7 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk,
if (src_idx) {
if (fl6->flowi6_oif &&
src_idx != fl6->flowi6_oif &&
- (sk->sk_bound_dev_if != fl6->flowi6_oif ||
+ (READ_ONCE(sk->sk_bound_dev_if) != fl6->flowi6_oif ||
!sk_dev_equal_l3scope(sk, src_idx)))
return -EINVAL;
fl6->flowi6_oif = src_idx;
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 3fc97d4621ac4a1f86de1f20375b33afffd0a2e6..960cfea820160614f3606ce4f407b7aa89fc70e1 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -105,7 +105,7 @@ static int compute_score(struct sock *sk, struct net *net,
const struct in6_addr *daddr, unsigned short hnum,
int dif, int sdif)
{
- int score;
+ int bound_dev_if, score;
struct inet_sock *inet;
bool dev_match;
@@ -132,10 +132,11 @@ static int compute_score(struct sock *sk, struct net *net,
score++;
}
- dev_match = udp_sk_bound_dev_eq(net, sk->sk_bound_dev_if, dif, sdif);
+ bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
+ dev_match = udp_sk_bound_dev_eq(net, bound_dev_if, dif, sdif);
if (!dev_match)
return -1;
- if (sk->sk_bound_dev_if)
+ if (bound_dev_if)
score++;
if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id())
@@ -789,7 +790,7 @@ static bool __udp_v6_is_mcast_sock(struct net *net, struct sock *sk,
(inet->inet_dport && inet->inet_dport != rmt_port) ||
(!ipv6_addr_any(&sk->sk_v6_daddr) &&
!ipv6_addr_equal(&sk->sk_v6_daddr, rmt_addr)) ||
- !udp_sk_bound_dev_eq(net, sk->sk_bound_dev_if, dif, sdif) ||
+ !udp_sk_bound_dev_eq(net, READ_ONCE(sk->sk_bound_dev_if), dif, sdif) ||
(!ipv6_addr_any(&sk->sk_v6_rcv_saddr) &&
!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, loc_addr)))
return false;
@@ -1433,7 +1434,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
}
if (!fl6->flowi6_oif)
- fl6->flowi6_oif = sk->sk_bound_dev_if;
+ fl6->flowi6_oif = READ_ONCE(sk->sk_bound_dev_if);
if (!fl6->flowi6_oif)
fl6->flowi6_oif = np->sticky_pktinfo.ipi6_ifindex;
--
2.36.0.512.ge40c2bad7a-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH net-next 02/10] sctp: read sk->sk_bound_dev_if once in sctp_rcv()
2022-05-11 23:37 [PATCH net-next 00/10] net: add annotations for sk->sk_bound_dev_if Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 01/10] net: annotate races around sk->sk_bound_dev_if Eric Dumazet
@ 2022-05-11 23:37 ` Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 03/10] tcp: sk->sk_bound_dev_if once in inet_request_bound_dev_if() Eric Dumazet
` (7 subsequent siblings)
9 siblings, 0 replies; 20+ messages in thread
From: Eric Dumazet @ 2022-05-11 23:37 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, Eric Dumazet, Eric Dumazet
From: Eric Dumazet <edumazet@google.com>
sctp_rcv() reads sk->sk_bound_dev_if twice while the socket
is not locked. Another cpu could change this field under us.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
net/sctp/input.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/sctp/input.c b/net/sctp/input.c
index 90e12bafdd4894624b3a63d625ed21c85b60a4f0..4f43afa8678f9febf2f02c2ce1a840ce3ab6a07d 100644
--- a/net/sctp/input.c
+++ b/net/sctp/input.c
@@ -92,6 +92,7 @@ int sctp_rcv(struct sk_buff *skb)
struct sctp_chunk *chunk;
union sctp_addr src;
union sctp_addr dest;
+ int bound_dev_if;
int family;
struct sctp_af *af;
struct net *net = dev_net(skb->dev);
@@ -169,7 +170,8 @@ int sctp_rcv(struct sk_buff *skb)
* If a frame arrives on an interface and the receiving socket is
* bound to another interface, via SO_BINDTODEVICE, treat it as OOTB
*/
- if (sk->sk_bound_dev_if && (sk->sk_bound_dev_if != af->skb_iif(skb))) {
+ bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
+ if (bound_dev_if && (bound_dev_if != af->skb_iif(skb))) {
if (transport) {
sctp_transport_put(transport);
asoc = NULL;
--
2.36.0.512.ge40c2bad7a-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH net-next 03/10] tcp: sk->sk_bound_dev_if once in inet_request_bound_dev_if()
2022-05-11 23:37 [PATCH net-next 00/10] net: add annotations for sk->sk_bound_dev_if Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 01/10] net: annotate races around sk->sk_bound_dev_if Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 02/10] sctp: read sk->sk_bound_dev_if once in sctp_rcv() Eric Dumazet
@ 2022-05-11 23:37 ` Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 04/10] net: core: add READ_ONCE/WRITE_ONCE annotations for sk->sk_bound_dev_if Eric Dumazet
` (6 subsequent siblings)
9 siblings, 0 replies; 20+ messages in thread
From: Eric Dumazet @ 2022-05-11 23:37 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, Eric Dumazet, Eric Dumazet
From: Eric Dumazet <edumazet@google.com>
inet_request_bound_dev_if() reads sk->sk_bound_dev_if twice
while listener socket is not locked.
Another cpu could change this field under us.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
include/net/inet_sock.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h
index 234d70ae5f4cbdc3b2caaf10df81495439a101a5..c1b5dcd6597c622dfea3d4a646f97c87acb7ea32 100644
--- a/include/net/inet_sock.h
+++ b/include/net/inet_sock.h
@@ -116,14 +116,15 @@ static inline u32 inet_request_mark(const struct sock *sk, struct sk_buff *skb)
static inline int inet_request_bound_dev_if(const struct sock *sk,
struct sk_buff *skb)
{
+ int bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
#ifdef CONFIG_NET_L3_MASTER_DEV
struct net *net = sock_net(sk);
- if (!sk->sk_bound_dev_if && net->ipv4.sysctl_tcp_l3mdev_accept)
+ if (!bound_dev_if && net->ipv4.sysctl_tcp_l3mdev_accept)
return l3mdev_master_ifindex_by_index(net, skb->skb_iif);
#endif
- return sk->sk_bound_dev_if;
+ return bound_dev_if;
}
static inline int inet_sk_bound_l3mdev(const struct sock *sk)
--
2.36.0.512.ge40c2bad7a-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH net-next 04/10] net: core: add READ_ONCE/WRITE_ONCE annotations for sk->sk_bound_dev_if
2022-05-11 23:37 [PATCH net-next 00/10] net: add annotations for sk->sk_bound_dev_if Eric Dumazet
` (2 preceding siblings ...)
2022-05-11 23:37 ` [PATCH net-next 03/10] tcp: sk->sk_bound_dev_if once in inet_request_bound_dev_if() Eric Dumazet
@ 2022-05-11 23:37 ` Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 05/10] dccp: use READ_ONCE() to read sk->sk_bound_dev_if Eric Dumazet
` (5 subsequent siblings)
9 siblings, 0 replies; 20+ messages in thread
From: Eric Dumazet @ 2022-05-11 23:37 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, Eric Dumazet, Eric Dumazet
From: Eric Dumazet <edumazet@google.com>
sock_bindtoindex_locked() needs to use WRITE_ONCE(sk->sk_bound_dev_if, val),
because other cpus/threads might locklessly read this field.
sock_getbindtodevice(), sock_getsockopt() need READ_ONCE()
because they run without socket lock held.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
net/core/sock.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/net/core/sock.c b/net/core/sock.c
index 6b287eb5427b32865d25fc22122fefeff3a4ccf5..2500f9989117441a67ce2c457af25bf8f780b110 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -635,7 +635,9 @@ static int sock_bindtoindex_locked(struct sock *sk, int ifindex)
if (ifindex < 0)
goto out;
- sk->sk_bound_dev_if = ifindex;
+ /* Paired with all READ_ONCE() done locklessly. */
+ WRITE_ONCE(sk->sk_bound_dev_if, ifindex);
+
if (sk->sk_prot->rehash)
sk->sk_prot->rehash(sk);
sk_dst_reset(sk);
@@ -713,10 +715,11 @@ static int sock_getbindtodevice(struct sock *sk, char __user *optval,
{
int ret = -ENOPROTOOPT;
#ifdef CONFIG_NETDEVICES
+ int bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
struct net *net = sock_net(sk);
char devname[IFNAMSIZ];
- if (sk->sk_bound_dev_if == 0) {
+ if (bound_dev_if == 0) {
len = 0;
goto zero;
}
@@ -725,7 +728,7 @@ static int sock_getbindtodevice(struct sock *sk, char __user *optval,
if (len < IFNAMSIZ)
goto out;
- ret = netdev_get_name(net, devname, sk->sk_bound_dev_if);
+ ret = netdev_get_name(net, devname, bound_dev_if);
if (ret)
goto out;
@@ -1861,7 +1864,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
break;
case SO_BINDTOIFINDEX:
- v.val = sk->sk_bound_dev_if;
+ v.val = READ_ONCE(sk->sk_bound_dev_if);
break;
case SO_NETNS_COOKIE:
--
2.36.0.512.ge40c2bad7a-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH net-next 05/10] dccp: use READ_ONCE() to read sk->sk_bound_dev_if
2022-05-11 23:37 [PATCH net-next 00/10] net: add annotations for sk->sk_bound_dev_if Eric Dumazet
` (3 preceding siblings ...)
2022-05-11 23:37 ` [PATCH net-next 04/10] net: core: add READ_ONCE/WRITE_ONCE annotations for sk->sk_bound_dev_if Eric Dumazet
@ 2022-05-11 23:37 ` Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 06/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in inet_csk_bind_conflict() Eric Dumazet
` (4 subsequent siblings)
9 siblings, 0 replies; 20+ messages in thread
From: Eric Dumazet @ 2022-05-11 23:37 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, Eric Dumazet, Eric Dumazet
From: Eric Dumazet <edumazet@google.com>
When reading listener sk->sk_bound_dev_if locklessly,
we must use READ_ONCE().
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
net/dccp/ipv4.c | 2 +-
net/dccp/ipv6.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index 82696ab86f74fd61aae5f60a3e14e769fb21abf9..3074248721607541a707d2e27dc0dfb9ff68463f 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -628,7 +628,7 @@ int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
sk_daddr_set(req_to_sk(req), ip_hdr(skb)->saddr);
ireq->ir_mark = inet_request_mark(sk, skb);
ireq->ireq_family = AF_INET;
- ireq->ir_iif = sk->sk_bound_dev_if;
+ ireq->ir_iif = READ_ONCE(sk->sk_bound_dev_if);
/*
* Step 3: Process LISTEN state
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
index 4d95b6400915db56e1058099e6d7015d2d64647e..d717ef0def64a9f3321fc53107f421b70a21bd16 100644
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -374,10 +374,10 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
refcount_inc(&skb->users);
ireq->pktopts = skb;
}
- ireq->ir_iif = sk->sk_bound_dev_if;
+ ireq->ir_iif = READ_ONCE(sk->sk_bound_dev_if);
/* So that link locals have meaning */
- if (!sk->sk_bound_dev_if &&
+ if (!ireq->ir_iif &&
ipv6_addr_type(&ireq->ir_v6_rmt_addr) & IPV6_ADDR_LINKLOCAL)
ireq->ir_iif = inet6_iif(skb);
--
2.36.0.512.ge40c2bad7a-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH net-next 06/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in inet_csk_bind_conflict()
2022-05-11 23:37 [PATCH net-next 00/10] net: add annotations for sk->sk_bound_dev_if Eric Dumazet
` (4 preceding siblings ...)
2022-05-11 23:37 ` [PATCH net-next 05/10] dccp: use READ_ONCE() to read sk->sk_bound_dev_if Eric Dumazet
@ 2022-05-11 23:37 ` Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 07/10] net_sched: em_meta: add READ_ONCE() in var_sk_bound_if() Eric Dumazet
` (3 subsequent siblings)
9 siblings, 0 replies; 20+ messages in thread
From: Eric Dumazet @ 2022-05-11 23:37 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, Eric Dumazet, Eric Dumazet
From: Eric Dumazet <edumazet@google.com>
inet_csk_bind_conflict() can access sk->sk_bound_dev_if for
unlocked sockets.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
net/ipv4/inet_connection_sock.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 1e5b53c2bb2670fc90b789e853458f5c86a00c27..53f5f956d9485df5cb863c8287c1fa9989bb29c9 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -155,10 +155,14 @@ static int inet_csk_bind_conflict(const struct sock *sk,
*/
sk_for_each_bound(sk2, &tb->owners) {
- if (sk != sk2 &&
- (!sk->sk_bound_dev_if ||
- !sk2->sk_bound_dev_if ||
- sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
+ int bound_dev_if2;
+
+ if (sk == sk2)
+ continue;
+ bound_dev_if2 = READ_ONCE(sk2->sk_bound_dev_if);
+ if ((!sk->sk_bound_dev_if ||
+ !bound_dev_if2 ||
+ sk->sk_bound_dev_if == bound_dev_if2)) {
if (reuse && sk2->sk_reuse &&
sk2->sk_state != TCP_LISTEN) {
if ((!relax ||
--
2.36.0.512.ge40c2bad7a-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH net-next 07/10] net_sched: em_meta: add READ_ONCE() in var_sk_bound_if()
2022-05-11 23:37 [PATCH net-next 00/10] net: add annotations for sk->sk_bound_dev_if Eric Dumazet
` (5 preceding siblings ...)
2022-05-11 23:37 ` [PATCH net-next 06/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in inet_csk_bind_conflict() Eric Dumazet
@ 2022-05-11 23:37 ` Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 08/10] l2tp: use add READ_ONCE() to fetch sk->sk_bound_dev_if Eric Dumazet
` (2 subsequent siblings)
9 siblings, 0 replies; 20+ messages in thread
From: Eric Dumazet @ 2022-05-11 23:37 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, Eric Dumazet, Eric Dumazet
From: Eric Dumazet <edumazet@google.com>
sk->sk_bound_dev_if can change under us, use READ_ONCE() annotation.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
net/sched/em_meta.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c
index 0a04468b73145546097788db0645ef9e5b459bca..49bae3d5006b0f83330b4cbe30344c0741743575 100644
--- a/net/sched/em_meta.c
+++ b/net/sched/em_meta.c
@@ -311,12 +311,15 @@ META_COLLECTOR(int_sk_bound_if)
META_COLLECTOR(var_sk_bound_if)
{
+ int bound_dev_if;
+
if (skip_nonlocal(skb)) {
*err = -1;
return;
}
- if (skb->sk->sk_bound_dev_if == 0) {
+ bound_dev_if = READ_ONCE(skb->sk->sk_bound_dev_if);
+ if (bound_dev_if == 0) {
dst->value = (unsigned long) "any";
dst->len = 3;
} else {
@@ -324,7 +327,7 @@ META_COLLECTOR(var_sk_bound_if)
rcu_read_lock();
dev = dev_get_by_index_rcu(sock_net(skb->sk),
- skb->sk->sk_bound_dev_if);
+ bound_dev_if);
*err = var_dev(dev, dst);
rcu_read_unlock();
}
--
2.36.0.512.ge40c2bad7a-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH net-next 08/10] l2tp: use add READ_ONCE() to fetch sk->sk_bound_dev_if
2022-05-11 23:37 [PATCH net-next 00/10] net: add annotations for sk->sk_bound_dev_if Eric Dumazet
` (6 preceding siblings ...)
2022-05-11 23:37 ` [PATCH net-next 07/10] net_sched: em_meta: add READ_ONCE() in var_sk_bound_if() Eric Dumazet
@ 2022-05-11 23:37 ` Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 09/10] ipv6: add READ_ONCE(sk->sk_bound_dev_if) in INET6_MATCH() Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 10/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in INET_MATCH() Eric Dumazet
9 siblings, 0 replies; 20+ messages in thread
From: Eric Dumazet @ 2022-05-11 23:37 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, Eric Dumazet, Eric Dumazet
From: Eric Dumazet <edumazet@google.com>
Use READ_ONCE() in paths not holding the socket lock.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
net/l2tp/l2tp_ip.c | 4 +++-
net/l2tp/l2tp_ip6.c | 8 +++++---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
index 6af09e188e52cfd84defb42ad34aea25f66f1e25..4db5a554bdbd9e80eb697a88cb7208e15d7931bc 100644
--- a/net/l2tp/l2tp_ip.c
+++ b/net/l2tp/l2tp_ip.c
@@ -50,11 +50,13 @@ static struct sock *__l2tp_ip_bind_lookup(const struct net *net, __be32 laddr,
sk_for_each_bound(sk, &l2tp_ip_bind_table) {
const struct l2tp_ip_sock *l2tp = l2tp_ip_sk(sk);
const struct inet_sock *inet = inet_sk(sk);
+ int bound_dev_if;
if (!net_eq(sock_net(sk), net))
continue;
- if (sk->sk_bound_dev_if && dif && sk->sk_bound_dev_if != dif)
+ bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
+ if (bound_dev_if && dif && bound_dev_if != dif)
continue;
if (inet->inet_rcv_saddr && laddr &&
diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
index 217c7192691e160e9727afd78126006aba3736b4..c6ff8bf9b55f916e80380bb2e4ea81b11e544a32 100644
--- a/net/l2tp/l2tp_ip6.c
+++ b/net/l2tp/l2tp_ip6.c
@@ -62,11 +62,13 @@ static struct sock *__l2tp_ip6_bind_lookup(const struct net *net,
const struct in6_addr *sk_laddr = inet6_rcv_saddr(sk);
const struct in6_addr *sk_raddr = &sk->sk_v6_daddr;
const struct l2tp_ip6_sock *l2tp = l2tp_ip6_sk(sk);
+ int bound_dev_if;
if (!net_eq(sock_net(sk), net))
continue;
- if (sk->sk_bound_dev_if && dif && sk->sk_bound_dev_if != dif)
+ bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
+ if (bound_dev_if && dif && bound_dev_if != dif)
continue;
if (sk_laddr && !ipv6_addr_any(sk_laddr) &&
@@ -445,7 +447,7 @@ static int l2tp_ip6_getname(struct socket *sock, struct sockaddr *uaddr,
lsa->l2tp_conn_id = lsk->conn_id;
}
if (ipv6_addr_type(&lsa->l2tp_addr) & IPV6_ADDR_LINKLOCAL)
- lsa->l2tp_scope_id = sk->sk_bound_dev_if;
+ lsa->l2tp_scope_id = READ_ONCE(sk->sk_bound_dev_if);
return sizeof(*lsa);
}
@@ -560,7 +562,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
}
if (fl6.flowi6_oif == 0)
- fl6.flowi6_oif = sk->sk_bound_dev_if;
+ fl6.flowi6_oif = READ_ONCE(sk->sk_bound_dev_if);
if (msg->msg_controllen) {
opt = &opt_space;
--
2.36.0.512.ge40c2bad7a-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH net-next 09/10] ipv6: add READ_ONCE(sk->sk_bound_dev_if) in INET6_MATCH()
2022-05-11 23:37 [PATCH net-next 00/10] net: add annotations for sk->sk_bound_dev_if Eric Dumazet
` (7 preceding siblings ...)
2022-05-11 23:37 ` [PATCH net-next 08/10] l2tp: use add READ_ONCE() to fetch sk->sk_bound_dev_if Eric Dumazet
@ 2022-05-11 23:37 ` Eric Dumazet
2022-05-12 15:48 ` kernel test robot
2022-05-13 1:00 ` kernel test robot
2022-05-11 23:37 ` [PATCH net-next 10/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in INET_MATCH() Eric Dumazet
9 siblings, 2 replies; 20+ messages in thread
From: Eric Dumazet @ 2022-05-11 23:37 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, Eric Dumazet, Eric Dumazet
From: Eric Dumazet <edumazet@google.com>
INET6_MATCH() runs without holding a lock on the socket.
We probably need to annotate most reads.
This patch makes INET6_MATCH() an inline function
to ease our changes.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
include/net/inet6_hashtables.h | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/include/net/inet6_hashtables.h b/include/net/inet6_hashtables.h
index 81b96595303680dee9c43f8c64d97b71fb4c4977..a7523e2e7ce50564c3ef1b3563a55dc80a03927d 100644
--- a/include/net/inet6_hashtables.h
+++ b/include/net/inet6_hashtables.h
@@ -105,13 +105,22 @@ struct sock *inet6_lookup(struct net *net, struct inet_hashinfo *hashinfo,
int inet6_hash(struct sock *sk);
#endif /* IS_ENABLED(CONFIG_IPV6) */
-#define INET6_MATCH(__sk, __net, __saddr, __daddr, __ports, __dif, __sdif) \
- (((__sk)->sk_portpair == (__ports)) && \
- ((__sk)->sk_family == AF_INET6) && \
- ipv6_addr_equal(&(__sk)->sk_v6_daddr, (__saddr)) && \
- ipv6_addr_equal(&(__sk)->sk_v6_rcv_saddr, (__daddr)) && \
- (((__sk)->sk_bound_dev_if == (__dif)) || \
- ((__sk)->sk_bound_dev_if == (__sdif))) && \
- net_eq(sock_net(__sk), (__net)))
+static inline bool INET6_MATCH(const struct sock *sk, struct net *net,
+ const struct in6_addr *saddr,
+ const struct in6_addr *daddr,
+ const __portpair ports,
+ const int dif, const int sdif)
+{
+ int bound_dev_if;
+ if (!net_eq(sock_net(sk), net) ||
+ sk->sk_family != AF_INET6 ||
+ sk->sk_portpair != ports ||
+ !ipv6_addr_equal(&sk->sk_v6_daddr, saddr) ||
+ !ipv6_addr_equal(&sk->sk_v6_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 /* _INET6_HASHTABLES_H */
--
2.36.0.512.ge40c2bad7a-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH net-next 10/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in INET_MATCH()
2022-05-11 23:37 [PATCH net-next 00/10] net: add annotations for sk->sk_bound_dev_if Eric Dumazet
` (8 preceding siblings ...)
2022-05-11 23:37 ` [PATCH net-next 09/10] ipv6: add READ_ONCE(sk->sk_bound_dev_if) in INET6_MATCH() Eric Dumazet
@ 2022-05-11 23:37 ` Eric Dumazet
2022-05-12 13:15 ` kernel test robot
9 siblings, 1 reply; 20+ messages in thread
From: Eric Dumazet @ 2022-05-11 23:37 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, Eric Dumazet, Eric Dumazet
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(-)
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
--
2.36.0.512.ge40c2bad7a-goog
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH net-next 10/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in INET_MATCH()
2022-05-11 23:37 ` [PATCH net-next 10/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in INET_MATCH() Eric Dumazet
@ 2022-05-12 13:15 ` kernel test robot
2022-05-12 16:13 ` Eric Dumazet
0 siblings, 1 reply; 20+ messages in thread
From: kernel test robot @ 2022-05-12 13:15 UTC (permalink / raw)
To: Eric Dumazet, David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: llvm, kbuild-all, netdev, Eric Dumazet
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
--
0-DAY CI Kernel Test Service
https://01.org/lkp
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH net-next 09/10] ipv6: add READ_ONCE(sk->sk_bound_dev_if) in INET6_MATCH()
2022-05-11 23:37 ` [PATCH net-next 09/10] ipv6: add READ_ONCE(sk->sk_bound_dev_if) in INET6_MATCH() Eric Dumazet
@ 2022-05-12 15:48 ` kernel test robot
2022-05-13 1:00 ` kernel test robot
1 sibling, 0 replies; 20+ messages in thread
From: kernel test robot @ 2022-05-12 15:48 UTC (permalink / raw)
To: Eric Dumazet, David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: llvm, kbuild-all, netdev, Eric Dumazet
Hi Eric,
I love your patch! Yet something to improve:
[auto build test ERROR 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: riscv-randconfig-r032-20220512 (https://download.01.org/0day-ci/archive/20220512/202205122338.qp5zlcyC-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
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/ba3ce839eb3de33511aa07e29cabb8e7ed4e0cf0
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 ba3ce839eb3de33511aa07e29cabb8e7ed4e0cf0
# 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=riscv SHELL=/bin/bash net/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
In file included from net/core/filter.c:26:
In file included from include/linux/sock_diag.h:5:
In file included from include/linux/netlink.h:7:
In file included from include/linux/skbuff.h:17:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:464:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __raw_readb(PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:477:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
#define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
^
In file included from net/core/filter.c:26:
In file included from include/linux/sock_diag.h:5:
In file included from include/linux/netlink.h:7:
In file included from include/linux/skbuff.h:17:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
^
In file included from net/core/filter.c:26:
In file included from include/linux/sock_diag.h:5:
In file included from include/linux/netlink.h:7:
In file included from include/linux/skbuff.h:17:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:501:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:511:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:521:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:1024:55: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
~~~~~~~~~~ ^
In file included from net/core/filter.c:64:
>> include/net/inet6_hashtables.h:119:28: error: no member named 'skc_v6_daddr' in 'struct sock_common'; did you mean 'skc_daddr'?
!ipv6_addr_equal(&sk->sk_v6_daddr, saddr) ||
^
include/net/sock.h:388:34: note: expanded from macro 'sk_v6_daddr'
#define sk_v6_daddr __sk_common.skc_v6_daddr
^
include/net/sock.h:170:11: note: 'skc_daddr' declared here
__be32 skc_daddr;
^
In file included from net/core/filter.c:64:
>> include/net/inet6_hashtables.h:120:28: error: no member named 'skc_v6_rcv_saddr' in 'struct sock_common'; did you mean 'skc_rcv_saddr'?
!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
^
include/net/sock.h:389:37: note: expanded from macro 'sk_v6_rcv_saddr'
#define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr
^
include/net/sock.h:171:11: note: 'skc_rcv_saddr' declared here
__be32 skc_rcv_saddr;
^
7 warnings and 2 errors generated.
vim +119 include/net/inet6_hashtables.h
107
108 static inline bool INET6_MATCH(const struct sock *sk, struct net *net,
109 const struct in6_addr *saddr,
110 const struct in6_addr *daddr,
111 const __portpair ports,
112 const int dif, const int sdif)
113 {
114 int bound_dev_if;
115
116 if (!net_eq(sock_net(sk), net) ||
117 sk->sk_family != AF_INET6 ||
118 sk->sk_portpair != ports ||
> 119 !ipv6_addr_equal(&sk->sk_v6_daddr, saddr) ||
> 120 !ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
--
0-DAY CI Kernel Test Service
https://01.org/lkp
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH net-next 10/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in INET_MATCH()
2022-05-12 13:15 ` kernel test robot
@ 2022-05-12 16:13 ` Eric Dumazet
0 siblings, 0 replies; 20+ messages in thread
From: Eric Dumazet @ 2022-05-12 16:13 UTC (permalink / raw)
To: kernel test robot
Cc: Eric Dumazet, David S . Miller, Jakub Kicinski, Paolo Abeni,
llvm, kbuild-all, netdev
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
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH net-next 10/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in INET_MATCH()
@ 2022-05-12 16:13 ` Eric Dumazet
0 siblings, 0 replies; 20+ messages in thread
From: Eric Dumazet @ 2022-05-12 16:13 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 11390 bytes --]
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(a)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
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH net-next 09/10] ipv6: add READ_ONCE(sk->sk_bound_dev_if) in INET6_MATCH()
2022-05-11 23:37 ` [PATCH net-next 09/10] ipv6: add READ_ONCE(sk->sk_bound_dev_if) in INET6_MATCH() Eric Dumazet
2022-05-12 15:48 ` kernel test robot
@ 2022-05-13 1:00 ` kernel test robot
1 sibling, 0 replies; 20+ messages in thread
From: kernel test robot @ 2022-05-13 1:00 UTC (permalink / raw)
To: Eric Dumazet, David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: kbuild-all, netdev, Eric Dumazet
Hi Eric,
I love your patch! Yet something to improve:
[auto build test ERROR 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: x86_64-randconfig-a015 (https://download.01.org/0day-ci/archive/20220513/202205130816.Wo8OVaxg-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.2.0-20) 11.2.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/ba3ce839eb3de33511aa07e29cabb8e7ed4e0cf0
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 ba3ce839eb3de33511aa07e29cabb8e7ed4e0cf0
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
In file included from include/linux/sock_diag.h:8,
from net/core/filter.c:26:
include/net/inet6_hashtables.h: In function 'INET6_MATCH':
>> include/net/sock.h:388:45: error: 'const struct sock_common' has no member named 'skc_v6_daddr'; did you mean 'skc_daddr'?
388 | #define sk_v6_daddr __sk_common.skc_v6_daddr
| ^~~~~~~~~~~~
include/net/inet6_hashtables.h:119:35: note: in expansion of macro 'sk_v6_daddr'
119 | !ipv6_addr_equal(&sk->sk_v6_daddr, saddr) ||
| ^~~~~~~~~~~
>> include/net/sock.h:389:37: error: 'const struct sock_common' has no member named 'skc_v6_rcv_saddr'; did you mean 'skc_rcv_saddr'?
389 | #define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr
| ^~~~~~~~~~~~~~~~
include/net/inet6_hashtables.h:120:35: note: in expansion of macro 'sk_v6_rcv_saddr'
120 | !ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
| ^~~~~~~~~~~~~~~
vim +388 include/net/sock.h
4dc6dc7162c08b9 Eric Dumazet 2009-07-15 368
68835aba4d9b74e Eric Dumazet 2010-11-30 369 #define sk_dontcopy_begin __sk_common.skc_dontcopy_begin
68835aba4d9b74e Eric Dumazet 2010-11-30 370 #define sk_dontcopy_end __sk_common.skc_dontcopy_end
4dc6dc7162c08b9 Eric Dumazet 2009-07-15 371 #define sk_hash __sk_common.skc_hash
5080546682bae3d Eric Dumazet 2013-10-02 372 #define sk_portpair __sk_common.skc_portpair
05dbc7b59481ca8 Eric Dumazet 2013-10-03 373 #define sk_num __sk_common.skc_num
05dbc7b59481ca8 Eric Dumazet 2013-10-03 374 #define sk_dport __sk_common.skc_dport
5080546682bae3d Eric Dumazet 2013-10-02 375 #define sk_addrpair __sk_common.skc_addrpair
5080546682bae3d Eric Dumazet 2013-10-02 376 #define sk_daddr __sk_common.skc_daddr
5080546682bae3d Eric Dumazet 2013-10-02 377 #define sk_rcv_saddr __sk_common.skc_rcv_saddr
^1da177e4c3f415 Linus Torvalds 2005-04-16 378 #define sk_family __sk_common.skc_family
^1da177e4c3f415 Linus Torvalds 2005-04-16 379 #define sk_state __sk_common.skc_state
^1da177e4c3f415 Linus Torvalds 2005-04-16 380 #define sk_reuse __sk_common.skc_reuse
055dc21a1d1d219 Tom Herbert 2013-01-22 381 #define sk_reuseport __sk_common.skc_reuseport
9fe516ba3fb29b6 Eric Dumazet 2014-06-27 382 #define sk_ipv6only __sk_common.skc_ipv6only
26abe14379f8e2f Eric W. Biederman 2015-05-08 383 #define sk_net_refcnt __sk_common.skc_net_refcnt
^1da177e4c3f415 Linus Torvalds 2005-04-16 384 #define sk_bound_dev_if __sk_common.skc_bound_dev_if
^1da177e4c3f415 Linus Torvalds 2005-04-16 385 #define sk_bind_node __sk_common.skc_bind_node
8feaf0c0a5488b3 Arnaldo Carvalho de Melo 2005-08-09 386 #define sk_prot __sk_common.skc_prot
07feaebfcc10cd3 Eric W. Biederman 2007-09-12 387 #define sk_net __sk_common.skc_net
efe4208f47f907b Eric Dumazet 2013-10-03 @388 #define sk_v6_daddr __sk_common.skc_v6_daddr
efe4208f47f907b Eric Dumazet 2013-10-03 @389 #define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr
33cf7c90fe2f97a Eric Dumazet 2015-03-11 390 #define sk_cookie __sk_common.skc_cookie
70da268b569d32a Eric Dumazet 2015-10-08 391 #define sk_incoming_cpu __sk_common.skc_incoming_cpu
8e5eb54d303b7cb Eric Dumazet 2015-10-08 392 #define sk_flags __sk_common.skc_flags
ed53d0ab761f5c7 Eric Dumazet 2015-10-08 393 #define sk_rxhash __sk_common.skc_rxhash
efe4208f47f907b Eric Dumazet 2013-10-03 394
43f51df41729559 Eric Dumazet 2021-11-15 395 /* early demux fields */
8b3f91332291fa2 Jakub Kicinski 2021-12-23 396 struct dst_entry __rcu *sk_rx_dst;
43f51df41729559 Eric Dumazet 2021-11-15 397 int sk_rx_dst_ifindex;
43f51df41729559 Eric Dumazet 2021-11-15 398 u32 sk_rx_dst_cookie;
43f51df41729559 Eric Dumazet 2021-11-15 399
^1da177e4c3f415 Linus Torvalds 2005-04-16 400 socket_lock_t sk_lock;
9115e8cd2a0c6ea Eric Dumazet 2016-12-03 401 atomic_t sk_drops;
9115e8cd2a0c6ea Eric Dumazet 2016-12-03 402 int sk_rcvlowat;
9115e8cd2a0c6ea Eric Dumazet 2016-12-03 403 struct sk_buff_head sk_error_queue;
b178bb3dfc30d95 Eric Dumazet 2010-11-16 404 struct sk_buff_head sk_receive_queue;
fa438ccfdfd3f6d Eric Dumazet 2007-03-04 405 /*
fa438ccfdfd3f6d Eric Dumazet 2007-03-04 406 * The backlog queue is special, it is always used with
fa438ccfdfd3f6d Eric Dumazet 2007-03-04 407 * the per-socket spinlock held and requires low latency
fa438ccfdfd3f6d Eric Dumazet 2007-03-04 408 * access. Therefore we special case it's implementation.
b178bb3dfc30d95 Eric Dumazet 2010-11-16 409 * Note : rmem_alloc is in this structure to fill a hole
b178bb3dfc30d95 Eric Dumazet 2010-11-16 410 * on 64bit arches, not because its logically part of
b178bb3dfc30d95 Eric Dumazet 2010-11-16 411 * backlog.
fa438ccfdfd3f6d Eric Dumazet 2007-03-04 412 */
fa438ccfdfd3f6d Eric Dumazet 2007-03-04 413 struct {
b178bb3dfc30d95 Eric Dumazet 2010-11-16 414 atomic_t rmem_alloc;
b178bb3dfc30d95 Eric Dumazet 2010-11-16 415 int len;
fa438ccfdfd3f6d Eric Dumazet 2007-03-04 416 struct sk_buff *head;
fa438ccfdfd3f6d Eric Dumazet 2007-03-04 417 struct sk_buff *tail;
fa438ccfdfd3f6d Eric Dumazet 2007-03-04 418 } sk_backlog;
f35f821935d8df7 Eric Dumazet 2021-11-15 419
--
0-DAY CI Kernel Test Service
https://01.org/lkp
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH net-next 10/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in INET_MATCH()
2022-05-12 16:13 ` Eric Dumazet
(?)
@ 2022-05-20 8:40 ` Chen, Rong A
2022-05-20 13:17 ` Eric Dumazet
-1 siblings, 1 reply; 20+ messages in thread
From: Chen, Rong A @ 2022-05-20 8:40 UTC (permalink / raw)
To: Eric Dumazet, kernel test robot
Cc: Eric Dumazet, David S . Miller, Jakub Kicinski, Paolo Abeni,
llvm, kbuild-all, netdev
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
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH net-next 10/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in INET_MATCH()
2022-05-20 8:40 ` Chen, Rong A
@ 2022-05-20 13:17 ` Eric Dumazet
0 siblings, 0 replies; 20+ messages in thread
From: Eric Dumazet @ 2022-05-20 13:17 UTC (permalink / raw)
To: Chen, Rong A
Cc: kernel test robot, Eric Dumazet, David S . Miller,
Jakub Kicinski, Paolo Abeni, llvm, kbuild-all, netdev
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 :/
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH net-next 10/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in INET_MATCH()
@ 2022-05-20 13:17 ` Eric Dumazet
0 siblings, 0 replies; 20+ messages in thread
From: Eric Dumazet @ 2022-05-20 13:17 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 2073 bytes --]
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(a)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 :/
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH net-next 10/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in INET_MATCH()
@ 2022-05-13 21:30 kernel test robot
0 siblings, 0 replies; 20+ messages in thread
From: kernel test robot @ 2022-05-13 21:30 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 15970 bytes --]
CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
In-Reply-To: <20220511233757.2001218-11-eric.dumazet@gmail.com>
References: <20220511233757.2001218-11-eric.dumazet@gmail.com>
TO: Eric Dumazet <eric.dumazet@gmail.com>
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
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: i386-randconfig-m021 (https://download.01.org/0day-ci/archive/20220514/202205140547.cDVaemuQ-lkp(a)intel.com/config)
compiler: gcc-11 (Debian 11.2.0-20) 11.2.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
New smatch warnings:
net/ipv4/inet_hashtables.c:413 __inet_lookup_established() error: uninitialized symbol 'acookie'.
net/ipv4/inet_hashtables.c:468 __inet_check_established() error: uninitialized symbol 'acookie'.
net/ipv4/inet_hashtables.c:535 inet_ehash_lookup_by_sk() error: uninitialized symbol 'acookie'.
net/ipv4/udp.c:2566 __udp4_lib_demux_lookup() error: uninitialized symbol 'acookie'.
Old smatch warnings:
net/ipv4/udp.c:496 __udp4_lib_lookup() warn: potential spectre issue 'udptable->hash2' [r]
net/ipv4/udp.c:2297 __udp4_lib_mcast_deliver() warn: potential spectre issue 'udptable->hash2' [r]
net/ipv4/udp.c:2529 __udp4_lib_mcast_demux_lookup() warn: potential spectre issue 'udp_table.hash' [r]
net/ipv4/udp.c:2560 __udp4_lib_demux_lookup() warn: potential spectre issue 'udp_table.hash2' [r]
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
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 440 /* called with local bh disabled */
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 441 static int __inet_check_established(struct inet_timewait_death_row *death_row,
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 442 struct sock *sk, __u16 lport,
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 443 struct inet_timewait_sock **twp)
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 444 {
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 445 struct inet_hashinfo *hinfo = death_row->hashinfo;
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 446 struct inet_sock *inet = inet_sk(sk);
c720c7e8383aff Eric Dumazet 2009-10-15 447 __be32 daddr = inet->inet_rcv_saddr;
c720c7e8383aff Eric Dumazet 2009-10-15 448 __be32 saddr = inet->inet_daddr;
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 449 int dif = sk->sk_bound_dev_if;
3fa6f616a7a4d0 David Ahern 2017-08-07 450 struct net *net = sock_net(sk);
3fa6f616a7a4d0 David Ahern 2017-08-07 451 int sdif = l3mdev_master_ifindex_by_index(net, dif);
c7228317441f4d Joe Perches 2014-05-13 452 INET_ADDR_COOKIE(acookie, saddr, daddr);
c720c7e8383aff Eric Dumazet 2009-10-15 453 const __portpair ports = INET_COMBINED_PORTS(inet->inet_dport, lport);
c720c7e8383aff Eric Dumazet 2009-10-15 454 unsigned int hash = inet_ehashfn(net, daddr, lport,
c720c7e8383aff Eric Dumazet 2009-10-15 455 saddr, inet->inet_dport);
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 456 struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash);
9db66bdcc83749 Eric Dumazet 2008-11-20 457 spinlock_t *lock = inet_ehash_lockp(hinfo, hash);
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 458 struct sock *sk2;
3ab5aee7fe840b Eric Dumazet 2008-11-16 459 const struct hlist_nulls_node *node;
05dbc7b59481ca Eric Dumazet 2013-10-03 460 struct inet_timewait_sock *tw = NULL;
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 461
9db66bdcc83749 Eric Dumazet 2008-11-20 462 spin_lock(lock);
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 463
05dbc7b59481ca Eric Dumazet 2013-10-03 464 sk_nulls_for_each(sk2, node, &head->chain) {
ce43b03e888947 Eric Dumazet 2012-11-30 465 if (sk2->sk_hash != hash)
ce43b03e888947 Eric Dumazet 2012-11-30 466 continue;
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 467
05dbc7b59481ca Eric Dumazet 2013-10-03 @468 if (likely(INET_MATCH(sk2, net, acookie,
3fa6f616a7a4d0 David Ahern 2017-08-07 469 saddr, daddr, ports, dif, sdif))) {
05dbc7b59481ca Eric Dumazet 2013-10-03 470 if (sk2->sk_state == TCP_TIME_WAIT) {
ce43b03e888947 Eric Dumazet 2012-11-30 471 tw = inet_twsk(sk2);
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 472 if (twsk_unique(sk, sk2, twp))
05dbc7b59481ca Eric Dumazet 2013-10-03 473 break;
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 474 }
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 475 goto not_unique;
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 476 }
05dbc7b59481ca Eric Dumazet 2013-10-03 477 }
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 478
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 479 /* Must record num and sport now. Otherwise we will see
05dbc7b59481ca Eric Dumazet 2013-10-03 480 * in hash table socket with a funny identity.
05dbc7b59481ca Eric Dumazet 2013-10-03 481 */
c720c7e8383aff Eric Dumazet 2009-10-15 482 inet->inet_num = lport;
c720c7e8383aff Eric Dumazet 2009-10-15 483 inet->inet_sport = htons(lport);
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 484 sk->sk_hash = hash;
547b792cac0a03 Ilpo Järvinen 2008-07-25 485 WARN_ON(!sk_unhashed(sk));
3ab5aee7fe840b Eric Dumazet 2008-11-16 486 __sk_nulls_add_node_rcu(sk, &head->chain);
13475a30b66cdb Eric Dumazet 2009-12-02 487 if (tw) {
fc01538f9fb755 Eric Dumazet 2015-07-08 488 sk_nulls_del_node_init_rcu((struct sock *)tw);
02a1d6e7a6bb02 Eric Dumazet 2016-04-27 489 __NET_INC_STATS(net, LINUX_MIB_TIMEWAITRECYCLED);
13475a30b66cdb Eric Dumazet 2009-12-02 490 }
9db66bdcc83749 Eric Dumazet 2008-11-20 491 spin_unlock(lock);
c29a0bc4dfc4d8 Pavel Emelyanov 2008-03-31 492 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 493
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 494 if (twp) {
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 495 *twp = tw;
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 496 } else if (tw) {
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 497 /* Silly. Should hash-dance instead... */
dbe7faa4045ea8 Eric Dumazet 2015-07-08 498 inet_twsk_deschedule_put(tw);
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 499 }
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 500 return 0;
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 501
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 502 not_unique:
9db66bdcc83749 Eric Dumazet 2008-11-20 503 spin_unlock(lock);
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 504 return -EADDRNOTAVAIL;
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 505 }
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 506
b2d057560b8107 Willy Tarreau 2022-05-02 507 static u64 inet_sk_port_offset(const struct sock *sk)
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 508 {
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 509 const struct inet_sock *inet = inet_sk(sk);
e2baad9e4b153c Eric Dumazet 2015-05-27 510
c720c7e8383aff Eric Dumazet 2009-10-15 511 return secure_ipv4_port_ephemeral(inet->inet_rcv_saddr,
c720c7e8383aff Eric Dumazet 2009-10-15 512 inet->inet_daddr,
c720c7e8383aff Eric Dumazet 2009-10-15 513 inet->inet_dport);
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 514 }
a7f5e7f164788a Arnaldo Carvalho de Melo 2005-12-13 515
01770a16616573 Ricardo Dias 2020-11-20 516 /* Searches for an exsiting socket in the ehash bucket list.
01770a16616573 Ricardo Dias 2020-11-20 517 * Returns true if found, false otherwise.
01770a16616573 Ricardo Dias 2020-11-20 518 */
01770a16616573 Ricardo Dias 2020-11-20 519 static bool inet_ehash_lookup_by_sk(struct sock *sk,
01770a16616573 Ricardo Dias 2020-11-20 520 struct hlist_nulls_head *list)
01770a16616573 Ricardo Dias 2020-11-20 521 {
01770a16616573 Ricardo Dias 2020-11-20 522 const __portpair ports = INET_COMBINED_PORTS(sk->sk_dport, sk->sk_num);
01770a16616573 Ricardo Dias 2020-11-20 523 const int sdif = sk->sk_bound_dev_if;
01770a16616573 Ricardo Dias 2020-11-20 524 const int dif = sk->sk_bound_dev_if;
01770a16616573 Ricardo Dias 2020-11-20 525 const struct hlist_nulls_node *node;
01770a16616573 Ricardo Dias 2020-11-20 526 struct net *net = sock_net(sk);
01770a16616573 Ricardo Dias 2020-11-20 527 struct sock *esk;
01770a16616573 Ricardo Dias 2020-11-20 528
01770a16616573 Ricardo Dias 2020-11-20 529 INET_ADDR_COOKIE(acookie, sk->sk_daddr, sk->sk_rcv_saddr);
01770a16616573 Ricardo Dias 2020-11-20 530
01770a16616573 Ricardo Dias 2020-11-20 531 sk_nulls_for_each_rcu(esk, node, list) {
01770a16616573 Ricardo Dias 2020-11-20 532 if (esk->sk_hash != sk->sk_hash)
01770a16616573 Ricardo Dias 2020-11-20 533 continue;
01770a16616573 Ricardo Dias 2020-11-20 534 if (sk->sk_family == AF_INET) {
01770a16616573 Ricardo Dias 2020-11-20 @535 if (unlikely(INET_MATCH(esk, net, acookie,
01770a16616573 Ricardo Dias 2020-11-20 536 sk->sk_daddr,
01770a16616573 Ricardo Dias 2020-11-20 537 sk->sk_rcv_saddr,
01770a16616573 Ricardo Dias 2020-11-20 538 ports, dif, sdif))) {
01770a16616573 Ricardo Dias 2020-11-20 539 return true;
01770a16616573 Ricardo Dias 2020-11-20 540 }
01770a16616573 Ricardo Dias 2020-11-20 541 }
01770a16616573 Ricardo Dias 2020-11-20 542 #if IS_ENABLED(CONFIG_IPV6)
01770a16616573 Ricardo Dias 2020-11-20 543 else if (sk->sk_family == AF_INET6) {
01770a16616573 Ricardo Dias 2020-11-20 544 if (unlikely(INET6_MATCH(esk, net,
01770a16616573 Ricardo Dias 2020-11-20 545 &sk->sk_v6_daddr,
01770a16616573 Ricardo Dias 2020-11-20 546 &sk->sk_v6_rcv_saddr,
01770a16616573 Ricardo Dias 2020-11-20 547 ports, dif, sdif))) {
01770a16616573 Ricardo Dias 2020-11-20 548 return true;
01770a16616573 Ricardo Dias 2020-11-20 549 }
01770a16616573 Ricardo Dias 2020-11-20 550 }
01770a16616573 Ricardo Dias 2020-11-20 551 #endif
01770a16616573 Ricardo Dias 2020-11-20 552 }
01770a16616573 Ricardo Dias 2020-11-20 553 return false;
01770a16616573 Ricardo Dias 2020-11-20 554 }
01770a16616573 Ricardo Dias 2020-11-20 555
--
0-DAY CI Kernel Test Service
https://01.org/lkp
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2022-05-20 13:17 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-11 23:37 [PATCH net-next 00/10] net: add annotations for sk->sk_bound_dev_if Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 01/10] net: annotate races around sk->sk_bound_dev_if Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 02/10] sctp: read sk->sk_bound_dev_if once in sctp_rcv() Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 03/10] tcp: sk->sk_bound_dev_if once in inet_request_bound_dev_if() Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 04/10] net: core: add READ_ONCE/WRITE_ONCE annotations for sk->sk_bound_dev_if Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 05/10] dccp: use READ_ONCE() to read sk->sk_bound_dev_if Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 06/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in inet_csk_bind_conflict() Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 07/10] net_sched: em_meta: add READ_ONCE() in var_sk_bound_if() Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 08/10] l2tp: use add READ_ONCE() to fetch sk->sk_bound_dev_if Eric Dumazet
2022-05-11 23:37 ` [PATCH net-next 09/10] ipv6: add READ_ONCE(sk->sk_bound_dev_if) in INET6_MATCH() Eric Dumazet
2022-05-12 15:48 ` kernel test robot
2022-05-13 1:00 ` kernel test robot
2022-05-11 23:37 ` [PATCH net-next 10/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in INET_MATCH() Eric Dumazet
2022-05-12 13:15 ` kernel test robot
2022-05-12 16:13 ` Eric Dumazet
2022-05-12 16:13 ` Eric Dumazet
2022-05-20 8:40 ` Chen, Rong A
2022-05-20 13:17 ` Eric Dumazet
2022-05-20 13:17 ` Eric Dumazet
2022-05-13 21:30 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.