netfilter: conntrack: don't acquire lock during seq_printf
Subsystems (2)
Florian Westphal
maintainerPATCH 1/1 netfilter: conntrack: don't acquire lock during seq_printf
read access doesn't need any lock here.
--- net/netfilter/nf_conntrack_proto_sctp.c | 8 +------- net/netfilter/nf_conntrack_proto_tcp.c | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-)
net/netfilter/nf_conntrack_proto_sctp.c +1 -7
@@ -191,13 +191,7 @@ static void sctp_print_tuple(struct seq_file *s,/* Print out the private part of the conntrack. */ static void sctp_print_conntrack (struct seq_file *s,struct nf_conn *ct) { -enum sctp_conntrack state; - -spin_lock_bh (&ct->lock); - state = ct->proto.sctp.state; -spin_unlock_bh (&ct->lock); - -seq_printf (s,"%s " , sctp_conntrack_names[state]); +seq_printf (s,"%s " , sctp_conntrack_names[ct->proto.sctp.state]); }#define for_each_sctp_chunk (skb, sch, _sch, offset, dataoff, count) \
net/netfilter/nf_conntrack_proto_tcp.c +1 -7
@@ -313,13 +313,7 @@ static void tcp_print_tuple(struct seq_file *s,/* Print out the private part of the conntrack. */ static void tcp_print_conntrack (struct seq_file *s,struct nf_conn *ct) { -enum tcp_conntrack state; - -spin_lock_bh (&ct->lock); - state = ct->proto.tcp.state; -spin_unlock_bh (&ct->lock); - -seq_printf (s,"%s " , tcp_conntrack_names[state]); +seq_printf (s,"%s " , tcp_conntrack_names[ct->proto.tcp.state]); }static unsigned int get_conntrack_index (const struct tcphdr *tcph)
Signature · 1 line
2.7.3
A message that is not in the archive (sent off-list or not yet received): 20160414094346.GA2056@salvia
Pablo Neira Ayuso
maintainerQuoted 13 lines · Florian Westphal
read access doesn't need any lock here.
Signed-off-by Florian Westphal <[email protected]>--- net/netfilter/nf_conntrack_proto_sctp.c | 8 +------- net/netfilter/nf_conntrack_proto_tcp.c | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-)net/netfilter/nf_conntrack_proto_sctp.c +0
-0
net/netfilter/nf_conntrack_proto_sctp.c static void sctp_print_tuple(struct seq_file *s, · line 197
Quoted 7 lines
net/netfilter/nf_conntrack_proto_sctp.c +0
-4@@ -191,13 +191,7 @@ static void sctp_print_tuple(struct seq_file *s,/* Print out the private part of the conntrack. */ static void sctp_print_conntrack (struct seq_file *s,struct nf_conn *ct) { -enum sctp_conntrack state; - -spin_lock_bh (&ct->lock); - state = ct->proto.sctp.state;
Don't we need at least READ_ONCE() here?
Quoted 7 lines
net/netfilter/nf_conntrack_proto_sctp.c +1
-3-spin_unlock_bh (&ct->lock); - -seq_printf (s,"%s " , sctp_conntrack_names[state]); +seq_printf (s,"%s " , sctp_conntrack_names[ct->proto.sctp.state]); }#define for_each_sctp_chunk (skb, sch, _sch, offset, dataoff, count) \
Florian Westphal
maintainerQuoted 4 lines · Pablo Neira Ayuso
Quoted 4 lines
net/netfilter/nf_conntrack_proto_sctp.c | 8 +------- net/netfilter/nf_conntrack_proto_tcp.c | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-)
Quoted 14 lines
net/netfilter/nf_conntrack_proto_sctp.c static void sctp_print_tuple(struct seq_file *s, · line 197
Quoted 12 lines
net/netfilter/nf_conntrack_proto_sctp.c +0
-4@@ -191,13 +191,7 @@ static void sctp_print_tuple(struct seq_file *s,/* Print out the private part of the conntrack. */ static void sctp_print_conntrack (struct seq_file *s,struct nf_conn *ct) { -enum sctp_conntrack state; - -spin_lock_bh (&ct->lock); - state = ct->proto.sctp.state;Don't we need at least
READ_ONCE()here?
Why?
seq_printf(s, "%s ", sctp_conntrack_names[ct->proto.sctp.state]);
I think thats fine, where do you see a problem?
Pablo Neira Ayuso
maintainerQuoted 20 lines · Florian Westphal
Quoted 4 lines · Pablo Neira Ayuso
Quoted 4 lines
net/netfilter/nf_conntrack_proto_sctp.c | 8 +------- net/netfilter/nf_conntrack_proto_tcp.c | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-)Quoted 14 lines
net/netfilter/nf_conntrack_proto_sctp.c static void sctp_print_tuple(struct seq_file *s, · line 197
Quoted 12 lines
net/netfilter/nf_conntrack_proto_sctp.c +0
-4@@ -191,13 +191,7 @@ static void sctp_print_tuple(struct seq_file *s,/* Print out the private part of the conntrack. */ static void sctp_print_conntrack (struct seq_file *s,struct nf_conn *ct) { -enum sctp_conntrack state; - -spin_lock_bh (&ct->lock); - state = ct->proto.sctp.state;Don't we need at least
READ_ONCE()here?
Quoted 5 lines
Why?
seq_printf(s, "%s ", sctp_conntrack_names[ct->proto.sctp.state]);I think thats fine, where do you see a problem?
ct->proto.sctp.state may be modified from another cpu while reading this, is this read guaranteed to be atomic in any arch?
Florian Westphal
maintainerQuoted 21 lines · Pablo Neira Ayuso
Quoted 20 lines · Florian Westphal
Quoted 18 lines · Pablo Neira Ayuso
Quoted 9 lines
net/netfilter/nf_conntrack_proto_sctp.c | 8 +------- net/netfilter/nf_conntrack_proto_tcp.c | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-)net/netfilter/nf_conntrack_proto_sctp.c +0
-0net/netfilter/nf_conntrack_proto_sctp.c static void sctp_print_tuple(struct seq_file *s, · line 197
Quoted 7 lines
net/netfilter/nf_conntrack_proto_sctp.c +0
-4@@ -191,13 +191,7 @@ static void sctp_print_tuple(struct seq_file *s,/* Print out the private part of the conntrack. */ static void sctp_print_conntrack (struct seq_file *s,struct nf_conn *ct) { -enum sctp_conntrack state; - -spin_lock_bh (&ct->lock); - state = ct->proto.sctp.state;Don't we need at least
READ_ONCE()here?
Quoted 8 lines
Quoted 5 lines
Why?
seq_printf(s, "%s ", sctp_conntrack_names[ct->proto.sctp.state]);I think thats fine, where do you see a problem?
ct->proto.sctp.statemay be modified from another cpu while reading this, is this read guaranteed to be atomic in any arch?
Yes, safe on all. Only problem would be if we change sctp.state to u64, we'd have to add locking for 32bit arches.
I can add a compiletime_assert_atomic_type() for this but I think its not needed.
I don't feel strongly about it; if you prefer locking here just mark patch as rejected.