From: Eric Dumazet <eric.dumazet@gmail.com>
To: Stephen Hemminger <shemminger@vyatta.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Li Zefan <lizf@cn.fujitsu.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] packet: convert socket list to RCU
Date: Fri, 19 Feb 2010 16:16:24 +0100 [thread overview]
Message-ID: <1266592584.3136.41.camel@edumazet-laptop> (raw)
In-Reply-To: <20100219054201.501571315@vyatta.com>
Le jeudi 18 février 2010 à 21:41 -0800, Stephen Hemminger a écrit :
> Convert AF_PACKET to use RCU, eliminating one more reader/writer lock.
>
> I needed to create some minor additional socket list RCU infrastructure
> to make this work. Note: there is no need for a real sk_del_node_init_rcu(),
> because sk_del_node_init is doing the equivalent thing to
> hlst_del_init_rcu already; but added some comments to try and make that obvious.
>
> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
>
Stephen, I am a bit worried by the interaction between packet_release()
and packet_notifier()
With your version, packet_notifier() can run and let another cpu run
packet_release() un-contented. Both cpus could manipulate same po (and
particularly po->running)
Before your patch, the read_lock() done in packet_notifier() was
preventing packet_release() runnning at the same time.
Maybe packet_release() should lock po->bind_lock before manipulating
po->running, avoiding a refcount error.
Something like this preliminary patch :
[PATCH] packet: fix a race in packet_release
packet_release() has a potential race with packet_notifier(NETDEV_DOWN),
leading to a double __sock_put(). (dev_remove_pack() is safe)
Fix is to always use po->bind_lock before accessing po->running
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 10f7295..b706031 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1271,15 +1271,15 @@ static int packet_release(struct socket *sock)
* Unhook packet receive handler.
*/
+ spin_lock(&po->bind_lock);
if (po->running) {
- /*
- * Remove the protocol hook
- */
- dev_remove_pack(&po->prot_hook);
+ __sock_put(sk);
po->running = 0;
po->num = 0;
- __sock_put(sk);
- }
+ spin_unlock(&po->bind_lock);
+ dev_remove_pack(&po->prot_hook);
+ } else
+ spin_unlock(&po->bind_lock);
packet_flush_mclist(sk);
prev parent reply other threads:[~2010-02-19 15:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20100219054145.959067404@vyatta.com>
2010-02-19 5:41 ` [PATCH 1/2] seq_file: add RCU versions of new hlist/list iterators (v2) Stephen Hemminger
2010-02-19 5:41 ` [PATCH 2/2] packet: convert socket list to RCU Stephen Hemminger
2010-02-19 15:16 ` Eric Dumazet [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1266592584.3136.41.camel@edumazet-laptop \
--to=eric.dumazet@gmail.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lizf@cn.fujitsu.com \
--cc=netdev@vger.kernel.org \
--cc=shemminger@vyatta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).