Skip to content

Commit 0b35f60

Browse files
TaeheeYooummakynes
authored andcommitted
netfilter: Remove duplicated rcu_read_lock.
This patch removes duplicate rcu_read_lock(). 1. IPVS part: According to Julian Anastasov's mention, contexts of ipvs are described at: http://marc.info/?l=netfilter-devel&m=149562884514072&w=2, in summary: - packet RX/TX: does not need locks because packets come from hooks. - sync msg RX: backup server uses RCU locks while registering new connections. - ip_vs_ctl.c: configuration get/set, RCU locks needed. - xt_ipvs.c: It is a netfilter match, running from hook context. As result, rcu_read_lock and rcu_read_unlock can be removed from: - ip_vs_core.c: all - ip_vs_ctl.c: - only from ip_vs_has_real_service - ip_vs_ftp.c: all - ip_vs_proto_sctp.c: all - ip_vs_proto_tcp.c: all - ip_vs_proto_udp.c: all - ip_vs_xmit.c: all (contains only packet processing) 2. Netfilter part: There are three types of functions that are guaranteed the rcu_read_lock(). First, as result, functions are only called by nf_hook(): - nf_conntrack_broadcast_help(), pptp_expectfn(), set_expected_rtp_rtcp(). - tcpmss_reverse_mtu(), tproxy_laddr4(), tproxy_laddr6(). - match_lookup_rt6(), check_hlist(), hashlimit_mt_common(). - xt_osf_match_packet(). Second, functions that caller already held the rcu_read_lock(). - destroy_conntrack(), ctnetlink_conntrack_event(). - ctnl_timeout_find_get(), nfqnl_nf_hook_drop(). Third, functions that are mixed with type1 and type2. These functions are called by nf_hook() also these are called by ordinary functions that already held the rcu_read_lock(): - __ctnetlink_glue_build(), ctnetlink_expect_event(). - ctnetlink_proto_size(). Applied files are below: - nf_conntrack_broadcast.c, nf_conntrack_core.c, nf_conntrack_netlink.c. - nf_conntrack_pptp.c, nf_conntrack_sip.c, nfnetlink_cttimeout.c. - nfnetlink_queue.c, xt_TCPMSS.c, xt_TPROXY.c, xt_addrtype.c. - xt_connlimit.c, xt_hashlimit.c, xt_osf.c Detailed calltrace can be found at: http://marc.info/?l=netfilter-devel&m=149667610710350&w=2 Signed-off-by: Taehee Yoo <[email protected]> Acked-by: Julian Anastasov <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 9f08ea8 commit 0b35f60

20 files changed

+13
-128
lines changed

net/netfilter/ipvs/ip_vs_core.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,12 @@ ip_vs_in_stats(struct ip_vs_conn *cp, struct sk_buff *skb)
125125
s->cnt.inbytes += skb->len;
126126
u64_stats_update_end(&s->syncp);
127127

128-
rcu_read_lock();
129128
svc = rcu_dereference(dest->svc);
130129
s = this_cpu_ptr(svc->stats.cpustats);
131130
u64_stats_update_begin(&s->syncp);
132131
s->cnt.inpkts++;
133132
s->cnt.inbytes += skb->len;
134133
u64_stats_update_end(&s->syncp);
135-
rcu_read_unlock();
136134

137135
s = this_cpu_ptr(ipvs->tot_stats.cpustats);
138136
u64_stats_update_begin(&s->syncp);
@@ -159,14 +157,12 @@ ip_vs_out_stats(struct ip_vs_conn *cp, struct sk_buff *skb)
159157
s->cnt.outbytes += skb->len;
160158
u64_stats_update_end(&s->syncp);
161159

162-
rcu_read_lock();
163160
svc = rcu_dereference(dest->svc);
164161
s = this_cpu_ptr(svc->stats.cpustats);
165162
u64_stats_update_begin(&s->syncp);
166163
s->cnt.outpkts++;
167164
s->cnt.outbytes += skb->len;
168165
u64_stats_update_end(&s->syncp);
169-
rcu_read_unlock();
170166

171167
s = this_cpu_ptr(ipvs->tot_stats.cpustats);
172168
u64_stats_update_begin(&s->syncp);
@@ -1222,7 +1218,6 @@ static struct ip_vs_conn *__ip_vs_rs_conn_out(unsigned int hooknum,
12221218
if (!pptr)
12231219
return NULL;
12241220

1225-
rcu_read_lock();
12261221
dest = ip_vs_find_real_service(ipvs, af, iph->protocol,
12271222
&iph->saddr, pptr[0]);
12281223
if (dest) {
@@ -1237,7 +1232,6 @@ static struct ip_vs_conn *__ip_vs_rs_conn_out(unsigned int hooknum,
12371232
pptr[0], pptr[1]);
12381233
}
12391234
}
1240-
rcu_read_unlock();
12411235

12421236
return cp;
12431237
}
@@ -1689,11 +1683,9 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,
16891683
if (dest) {
16901684
struct ip_vs_dest_dst *dest_dst;
16911685

1692-
rcu_read_lock();
16931686
dest_dst = rcu_dereference(dest->dest_dst);
16941687
if (dest_dst)
16951688
mtu = dst_mtu(dest_dst->dst_cache);
1696-
rcu_read_unlock();
16971689
}
16981690
if (mtu > 68 + sizeof(struct iphdr))
16991691
mtu -= sizeof(struct iphdr);

net/netfilter/ipvs/ip_vs_ctl.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,18 +550,15 @@ bool ip_vs_has_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol,
550550
/* Check for "full" addressed entries */
551551
hash = ip_vs_rs_hashkey(af, daddr, dport);
552552

553-
rcu_read_lock();
554553
hlist_for_each_entry_rcu(dest, &ipvs->rs_table[hash], d_list) {
555554
if (dest->port == dport &&
556555
dest->af == af &&
557556
ip_vs_addr_equal(af, &dest->addr, daddr) &&
558557
(dest->protocol == protocol || dest->vfwmark)) {
559558
/* HIT */
560-
rcu_read_unlock();
561559
return true;
562560
}
563561
}
564-
rcu_read_unlock();
565562

566563
return false;
567564
}

net/netfilter/ipvs/ip_vs_ftp.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,11 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,
269269
* hopefully it will succeed on the retransmitted
270270
* packet.
271271
*/
272-
rcu_read_lock();
273272
mangled = nf_nat_mangle_tcp_packet(skb, ct, ctinfo,
274273
iph->ihl * 4,
275274
start - data,
276275
end - start,
277276
buf, buf_len);
278-
rcu_read_unlock();
279277
if (mangled) {
280278
ip_vs_nfct_expect_related(skb, ct, n_cp,
281279
IPPROTO_TCP, 0, 0);

net/netfilter/ipvs/ip_vs_proto_sctp.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
3838
return 0;
3939
}
4040

41-
rcu_read_lock();
4241
if (likely(!ip_vs_iph_inverse(iph)))
4342
svc = ip_vs_service_find(ipvs, af, skb->mark, iph->protocol,
4443
&iph->daddr, ports[1]);
@@ -53,7 +52,6 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
5352
* It seems that we are very loaded.
5453
* We have to drop this packet :(
5554
*/
56-
rcu_read_unlock();
5755
*verdict = NF_DROP;
5856
return 0;
5957
}
@@ -67,11 +65,9 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
6765
*verdict = ip_vs_leave(svc, skb, pd, iph);
6866
else
6967
*verdict = NF_DROP;
70-
rcu_read_unlock();
7168
return 0;
7269
}
7370
}
74-
rcu_read_unlock();
7571
/* NF_ACCEPT */
7672
return 1;
7773
}
@@ -526,12 +522,10 @@ static int sctp_app_conn_bind(struct ip_vs_conn *cp)
526522
/* Lookup application incarnations and bind the right one */
527523
hash = sctp_app_hashkey(cp->vport);
528524

529-
rcu_read_lock();
530525
list_for_each_entry_rcu(inc, &ipvs->sctp_apps[hash], p_list) {
531526
if (inc->port == cp->vport) {
532527
if (unlikely(!ip_vs_app_inc_get(inc)))
533528
break;
534-
rcu_read_unlock();
535529

536530
IP_VS_DBG_BUF(9, "%s: Binding conn %s:%u->"
537531
"%s:%u to app %s on port %u\n",
@@ -544,11 +538,10 @@ static int sctp_app_conn_bind(struct ip_vs_conn *cp)
544538
cp->app = inc;
545539
if (inc->init_conn)
546540
result = inc->init_conn(inc, cp);
547-
goto out;
541+
break;
548542
}
549543
}
550-
rcu_read_unlock();
551-
out:
544+
552545
return result;
553546
}
554547

net/netfilter/ipvs/ip_vs_proto_tcp.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
6363
}
6464

6565
/* No !th->ack check to allow scheduling on SYN+ACK for Active FTP */
66-
rcu_read_lock();
6766

6867
if (likely(!ip_vs_iph_inverse(iph)))
6968
svc = ip_vs_service_find(ipvs, af, skb->mark, iph->protocol,
@@ -80,7 +79,6 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
8079
* It seems that we are very loaded.
8180
* We have to drop this packet :(
8281
*/
83-
rcu_read_unlock();
8482
*verdict = NF_DROP;
8583
return 0;
8684
}
@@ -95,11 +93,9 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
9593
*verdict = ip_vs_leave(svc, skb, pd, iph);
9694
else
9795
*verdict = NF_DROP;
98-
rcu_read_unlock();
9996
return 0;
10097
}
10198
}
102-
rcu_read_unlock();
10399
/* NF_ACCEPT */
104100
return 1;
105101
}
@@ -661,12 +657,10 @@ tcp_app_conn_bind(struct ip_vs_conn *cp)
661657
/* Lookup application incarnations and bind the right one */
662658
hash = tcp_app_hashkey(cp->vport);
663659

664-
rcu_read_lock();
665660
list_for_each_entry_rcu(inc, &ipvs->tcp_apps[hash], p_list) {
666661
if (inc->port == cp->vport) {
667662
if (unlikely(!ip_vs_app_inc_get(inc)))
668663
break;
669-
rcu_read_unlock();
670664

671665
IP_VS_DBG_BUF(9, "%s(): Binding conn %s:%u->"
672666
"%s:%u to app %s on port %u\n",
@@ -680,12 +674,10 @@ tcp_app_conn_bind(struct ip_vs_conn *cp)
680674
cp->app = inc;
681675
if (inc->init_conn)
682676
result = inc->init_conn(inc, cp);
683-
goto out;
677+
break;
684678
}
685679
}
686-
rcu_read_unlock();
687680

688-
out:
689681
return result;
690682
}
691683

net/netfilter/ipvs/ip_vs_proto_udp.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
5353
return 0;
5454
}
5555

56-
rcu_read_lock();
5756
if (likely(!ip_vs_iph_inverse(iph)))
5857
svc = ip_vs_service_find(ipvs, af, skb->mark, iph->protocol,
5958
&iph->daddr, ports[1]);
@@ -69,7 +68,6 @@ udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
6968
* It seems that we are very loaded.
7069
* We have to drop this packet :(
7170
*/
72-
rcu_read_unlock();
7371
*verdict = NF_DROP;
7472
return 0;
7573
}
@@ -84,11 +82,9 @@ udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
8482
*verdict = ip_vs_leave(svc, skb, pd, iph);
8583
else
8684
*verdict = NF_DROP;
87-
rcu_read_unlock();
8885
return 0;
8986
}
9087
}
91-
rcu_read_unlock();
9288
/* NF_ACCEPT */
9389
return 1;
9490
}
@@ -410,12 +406,10 @@ static int udp_app_conn_bind(struct ip_vs_conn *cp)
410406
/* Lookup application incarnations and bind the right one */
411407
hash = udp_app_hashkey(cp->vport);
412408

413-
rcu_read_lock();
414409
list_for_each_entry_rcu(inc, &ipvs->udp_apps[hash], p_list) {
415410
if (inc->port == cp->vport) {
416411
if (unlikely(!ip_vs_app_inc_get(inc)))
417412
break;
418-
rcu_read_unlock();
419413

420414
IP_VS_DBG_BUF(9, "%s(): Binding conn %s:%u->"
421415
"%s:%u to app %s on port %u\n",
@@ -429,12 +423,10 @@ static int udp_app_conn_bind(struct ip_vs_conn *cp)
429423
cp->app = inc;
430424
if (inc->init_conn)
431425
result = inc->init_conn(inc, cp);
432-
goto out;
426+
break;
433427
}
434428
}
435-
rcu_read_unlock();
436429

437-
out:
438430
return result;
439431
}
440432

0 commit comments

Comments
 (0)