Skip to content

Commit 4c5c496

Browse files
Eric Dumazetkuba-moo
Eric Dumazet
authored andcommitted
ipv6: flowlabel: do not disable BH where not needed
struct ip6_flowlabel are rcu managed, and call_rcu() is used to delay fl_free_rcu() after RCU grace period. There is no point disabling BH for pure RCU lookups. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f6f4e73 commit 4c5c496

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

net/ipv6/ip6_flowlabel.c

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ DEFINE_STATIC_KEY_DEFERRED_FALSE(ipv6_flowlabel_exclusive, HZ);
5858
EXPORT_SYMBOL(ipv6_flowlabel_exclusive);
5959

6060
#define for_each_fl_rcu(hash, fl) \
61-
for (fl = rcu_dereference_bh(fl_ht[(hash)]); \
61+
for (fl = rcu_dereference(fl_ht[(hash)]); \
6262
fl != NULL; \
63-
fl = rcu_dereference_bh(fl->next))
63+
fl = rcu_dereference(fl->next))
6464
#define for_each_fl_continue_rcu(fl) \
65-
for (fl = rcu_dereference_bh(fl->next); \
65+
for (fl = rcu_dereference(fl->next); \
6666
fl != NULL; \
67-
fl = rcu_dereference_bh(fl->next))
67+
fl = rcu_dereference(fl->next))
6868

6969
#define for_each_sk_fl_rcu(np, sfl) \
70-
for (sfl = rcu_dereference_bh(np->ipv6_fl_list); \
70+
for (sfl = rcu_dereference(np->ipv6_fl_list); \
7171
sfl != NULL; \
72-
sfl = rcu_dereference_bh(sfl->next))
72+
sfl = rcu_dereference(sfl->next))
7373

7474
static inline struct ip6_flowlabel *__fl_lookup(struct net *net, __be32 label)
7575
{
@@ -86,11 +86,11 @@ static struct ip6_flowlabel *fl_lookup(struct net *net, __be32 label)
8686
{
8787
struct ip6_flowlabel *fl;
8888

89-
rcu_read_lock_bh();
89+
rcu_read_lock();
9090
fl = __fl_lookup(net, label);
9191
if (fl && !atomic_inc_not_zero(&fl->users))
9292
fl = NULL;
93-
rcu_read_unlock_bh();
93+
rcu_read_unlock();
9494
return fl;
9595
}
9696

@@ -217,6 +217,7 @@ static struct ip6_flowlabel *fl_intern(struct net *net,
217217

218218
fl->label = label & IPV6_FLOWLABEL_MASK;
219219

220+
rcu_read_lock();
220221
spin_lock_bh(&ip6_fl_lock);
221222
if (label == 0) {
222223
for (;;) {
@@ -240,6 +241,7 @@ static struct ip6_flowlabel *fl_intern(struct net *net,
240241
if (lfl) {
241242
atomic_inc(&lfl->users);
242243
spin_unlock_bh(&ip6_fl_lock);
244+
rcu_read_unlock();
243245
return lfl;
244246
}
245247
}
@@ -249,6 +251,7 @@ static struct ip6_flowlabel *fl_intern(struct net *net,
249251
rcu_assign_pointer(fl_ht[FL_HASH(fl->label)], fl);
250252
atomic_inc(&fl_size);
251253
spin_unlock_bh(&ip6_fl_lock);
254+
rcu_read_unlock();
252255
return NULL;
253256
}
254257

@@ -263,17 +266,17 @@ struct ip6_flowlabel *__fl6_sock_lookup(struct sock *sk, __be32 label)
263266

264267
label &= IPV6_FLOWLABEL_MASK;
265268

266-
rcu_read_lock_bh();
269+
rcu_read_lock();
267270
for_each_sk_fl_rcu(np, sfl) {
268271
struct ip6_flowlabel *fl = sfl->fl;
269272

270273
if (fl->label == label && atomic_inc_not_zero(&fl->users)) {
271274
fl->lastuse = jiffies;
272-
rcu_read_unlock_bh();
275+
rcu_read_unlock();
273276
return fl;
274277
}
275278
}
276-
rcu_read_unlock_bh();
279+
rcu_read_unlock();
277280
return NULL;
278281
}
279282
EXPORT_SYMBOL_GPL(__fl6_sock_lookup);
@@ -475,10 +478,10 @@ static int mem_check(struct sock *sk)
475478
if (room > FL_MAX_SIZE - FL_MAX_PER_SOCK)
476479
return 0;
477480

478-
rcu_read_lock_bh();
481+
rcu_read_lock();
479482
for_each_sk_fl_rcu(np, sfl)
480483
count++;
481-
rcu_read_unlock_bh();
484+
rcu_read_unlock();
482485

483486
if (room <= 0 ||
484487
((count >= FL_MAX_PER_SOCK ||
@@ -515,7 +518,7 @@ int ipv6_flowlabel_opt_get(struct sock *sk, struct in6_flowlabel_req *freq,
515518
return 0;
516519
}
517520

518-
rcu_read_lock_bh();
521+
rcu_read_lock();
519522

520523
for_each_sk_fl_rcu(np, sfl) {
521524
if (sfl->fl->label == (np->flow_label & IPV6_FLOWLABEL_MASK)) {
@@ -527,11 +530,11 @@ int ipv6_flowlabel_opt_get(struct sock *sk, struct in6_flowlabel_req *freq,
527530
freq->flr_linger = sfl->fl->linger / HZ;
528531

529532
spin_unlock_bh(&ip6_fl_lock);
530-
rcu_read_unlock_bh();
533+
rcu_read_unlock();
531534
return 0;
532535
}
533536
}
534-
rcu_read_unlock_bh();
537+
rcu_read_unlock();
535538

536539
return -ENOENT;
537540
}
@@ -581,16 +584,16 @@ static int ipv6_flowlabel_renew(struct sock *sk, struct in6_flowlabel_req *freq)
581584
struct ipv6_fl_socklist *sfl;
582585
int err;
583586

584-
rcu_read_lock_bh();
587+
rcu_read_lock();
585588
for_each_sk_fl_rcu(np, sfl) {
586589
if (sfl->fl->label == freq->flr_label) {
587590
err = fl6_renew(sfl->fl, freq->flr_linger,
588591
freq->flr_expires);
589-
rcu_read_unlock_bh();
592+
rcu_read_unlock();
590593
return err;
591594
}
592595
}
593-
rcu_read_unlock_bh();
596+
rcu_read_unlock();
594597

595598
if (freq->flr_share == IPV6_FL_S_NONE &&
596599
ns_capable(net->user_ns, CAP_NET_ADMIN)) {
@@ -641,11 +644,11 @@ static int ipv6_flowlabel_get(struct sock *sk, struct in6_flowlabel_req *freq,
641644

642645
if (freq->flr_label) {
643646
err = -EEXIST;
644-
rcu_read_lock_bh();
647+
rcu_read_lock();
645648
for_each_sk_fl_rcu(np, sfl) {
646649
if (sfl->fl->label == freq->flr_label) {
647650
if (freq->flr_flags & IPV6_FL_F_EXCL) {
648-
rcu_read_unlock_bh();
651+
rcu_read_unlock();
649652
goto done;
650653
}
651654
fl1 = sfl->fl;
@@ -654,7 +657,7 @@ static int ipv6_flowlabel_get(struct sock *sk, struct in6_flowlabel_req *freq,
654657
break;
655658
}
656659
}
657-
rcu_read_unlock_bh();
660+
rcu_read_unlock();
658661

659662
if (!fl1)
660663
fl1 = fl_lookup(net, freq->flr_label);
@@ -809,7 +812,7 @@ static void *ip6fl_seq_start(struct seq_file *seq, loff_t *pos)
809812

810813
state->pid_ns = proc_pid_ns(file_inode(seq->file)->i_sb);
811814

812-
rcu_read_lock_bh();
815+
rcu_read_lock();
813816
return *pos ? ip6fl_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
814817
}
815818

@@ -828,7 +831,7 @@ static void *ip6fl_seq_next(struct seq_file *seq, void *v, loff_t *pos)
828831
static void ip6fl_seq_stop(struct seq_file *seq, void *v)
829832
__releases(RCU)
830833
{
831-
rcu_read_unlock_bh();
834+
rcu_read_unlock();
832835
}
833836

834837
static int ip6fl_seq_show(struct seq_file *seq, void *v)

0 commit comments

Comments
 (0)