Skip to content

Commit e7b9ecc

Browse files
edumazetkuba-moo
authored andcommitted
tcp: convert to dev_net_rcu()
TCP uses of dev_net() are under RCU protection, change them to dev_net_rcu() to get LOCKDEP support. Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a11a791 commit e7b9ecc

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

include/net/inet6_hashtables.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static inline struct sock *__inet6_lookup_skb(struct inet_hashinfo *hashinfo,
150150
int iif, int sdif,
151151
bool *refcounted)
152152
{
153-
struct net *net = dev_net(skb_dst(skb)->dev);
153+
struct net *net = dev_net_rcu(skb_dst(skb)->dev);
154154
const struct ipv6hdr *ip6h = ipv6_hdr(skb);
155155
struct sock *sk;
156156

include/net/inet_hashtables.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ static inline struct sock *__inet_lookup_skb(struct inet_hashinfo *hashinfo,
492492
const int sdif,
493493
bool *refcounted)
494494
{
495-
struct net *net = dev_net(skb_dst(skb)->dev);
495+
struct net *net = dev_net_rcu(skb_dst(skb)->dev);
496496
const struct iphdr *iph = ip_hdr(skb);
497497
struct sock *sk;
498498

net/ipv4/tcp_ipv4.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,14 @@ int tcp_v4_err(struct sk_buff *skb, u32 info)
494494
{
495495
const struct iphdr *iph = (const struct iphdr *)skb->data;
496496
struct tcphdr *th = (struct tcphdr *)(skb->data + (iph->ihl << 2));
497-
struct tcp_sock *tp;
497+
struct net *net = dev_net_rcu(skb->dev);
498498
const int type = icmp_hdr(skb)->type;
499499
const int code = icmp_hdr(skb)->code;
500-
struct sock *sk;
501500
struct request_sock *fastopen;
501+
struct tcp_sock *tp;
502502
u32 seq, snd_una;
503+
struct sock *sk;
503504
int err;
504-
struct net *net = dev_net(skb->dev);
505505

506506
sk = __inet_lookup_established(net, net->ipv4.tcp_death_row.hashinfo,
507507
iph->daddr, th->dest, iph->saddr,
@@ -786,7 +786,7 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb,
786786
arg.iov[0].iov_base = (unsigned char *)&rep;
787787
arg.iov[0].iov_len = sizeof(rep.th);
788788

789-
net = sk ? sock_net(sk) : dev_net(skb_dst(skb)->dev);
789+
net = sk ? sock_net(sk) : dev_net_rcu(skb_dst(skb)->dev);
790790

791791
/* Invalid TCP option size or twice included auth */
792792
if (tcp_parse_auth_options(tcp_hdr(skb), &md5_hash_location, &aoh))
@@ -1961,7 +1961,7 @@ EXPORT_SYMBOL(tcp_v4_do_rcv);
19611961

19621962
int tcp_v4_early_demux(struct sk_buff *skb)
19631963
{
1964-
struct net *net = dev_net(skb->dev);
1964+
struct net *net = dev_net_rcu(skb->dev);
19651965
const struct iphdr *iph;
19661966
const struct tcphdr *th;
19671967
struct sock *sk;
@@ -2172,7 +2172,7 @@ static void tcp_v4_fill_cb(struct sk_buff *skb, const struct iphdr *iph,
21722172

21732173
int tcp_v4_rcv(struct sk_buff *skb)
21742174
{
2175-
struct net *net = dev_net(skb->dev);
2175+
struct net *net = dev_net_rcu(skb->dev);
21762176
enum skb_drop_reason drop_reason;
21772177
int sdif = inet_sdif(skb);
21782178
int dif = inet_iif(skb);

net/ipv4/tcp_metrics.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst,
170170
bool reclaim = false;
171171

172172
spin_lock_bh(&tcp_metrics_lock);
173-
net = dev_net(dst->dev);
173+
net = dev_net_rcu(dst->dev);
174174

175175
/* While waiting for the spin-lock the cache might have been populated
176176
* with this entry and so we have to check again.
@@ -273,7 +273,7 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req,
273273
return NULL;
274274
}
275275

276-
net = dev_net(dst->dev);
276+
net = dev_net_rcu(dst->dev);
277277
hash ^= net_hash_mix(net);
278278
hash = hash_32(hash, tcp_metrics_hash_log);
279279

@@ -318,7 +318,7 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk,
318318
else
319319
return NULL;
320320

321-
net = dev_net(dst->dev);
321+
net = dev_net_rcu(dst->dev);
322322
hash ^= net_hash_mix(net);
323323
hash = hash_32(hash, tcp_metrics_hash_log);
324324

net/ipv6/tcp_ipv6.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
376376
{
377377
const struct ipv6hdr *hdr = (const struct ipv6hdr *)skb->data;
378378
const struct tcphdr *th = (struct tcphdr *)(skb->data+offset);
379-
struct net *net = dev_net(skb->dev);
379+
struct net *net = dev_net_rcu(skb->dev);
380380
struct request_sock *fastopen;
381381
struct ipv6_pinfo *np;
382382
struct tcp_sock *tp;
@@ -866,16 +866,16 @@ static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32
866866
int oif, int rst, u8 tclass, __be32 label,
867867
u32 priority, u32 txhash, struct tcp_key *key)
868868
{
869-
const struct tcphdr *th = tcp_hdr(skb);
870-
struct tcphdr *t1;
871-
struct sk_buff *buff;
872-
struct flowi6 fl6;
873-
struct net *net = sk ? sock_net(sk) : dev_net(skb_dst(skb)->dev);
874-
struct sock *ctl_sk = net->ipv6.tcp_sk;
869+
struct net *net = sk ? sock_net(sk) : dev_net_rcu(skb_dst(skb)->dev);
875870
unsigned int tot_len = sizeof(struct tcphdr);
871+
struct sock *ctl_sk = net->ipv6.tcp_sk;
872+
const struct tcphdr *th = tcp_hdr(skb);
876873
__be32 mrst = 0, *topt;
877874
struct dst_entry *dst;
878-
__u32 mark = 0;
875+
struct sk_buff *buff;
876+
struct tcphdr *t1;
877+
struct flowi6 fl6;
878+
u32 mark = 0;
879879

880880
if (tsecr)
881881
tot_len += TCPOLEN_TSTAMP_ALIGNED;
@@ -1041,7 +1041,7 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb,
10411041
if (!sk && !ipv6_unicast_destination(skb))
10421042
return;
10431043

1044-
net = sk ? sock_net(sk) : dev_net(skb_dst(skb)->dev);
1044+
net = sk ? sock_net(sk) : dev_net_rcu(skb_dst(skb)->dev);
10451045
/* Invalid TCP option size or twice included auth */
10461046
if (tcp_parse_auth_options(th, &md5_hash_location, &aoh))
10471047
return;
@@ -1740,6 +1740,7 @@ static void tcp_v6_fill_cb(struct sk_buff *skb, const struct ipv6hdr *hdr,
17401740

17411741
INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
17421742
{
1743+
struct net *net = dev_net_rcu(skb->dev);
17431744
enum skb_drop_reason drop_reason;
17441745
int sdif = inet6_sdif(skb);
17451746
int dif = inet6_iif(skb);
@@ -1749,7 +1750,6 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
17491750
bool refcounted;
17501751
int ret;
17511752
u32 isn;
1752-
struct net *net = dev_net(skb->dev);
17531753

17541754
drop_reason = SKB_DROP_REASON_NOT_SPECIFIED;
17551755
if (skb->pkt_type != PACKET_HOST)
@@ -2001,7 +2001,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
20012001

20022002
void tcp_v6_early_demux(struct sk_buff *skb)
20032003
{
2004-
struct net *net = dev_net(skb->dev);
2004+
struct net *net = dev_net_rcu(skb->dev);
20052005
const struct ipv6hdr *hdr;
20062006
const struct tcphdr *th;
20072007
struct sock *sk;

0 commit comments

Comments
 (0)