From: Thomas Graf <tgraf@suug.ch>
To: Ying Xue <ying.xue@windriver.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: Re: [PATCH net-next 2/3] netlink: eliminate nl_sk_hash_lock
Date: Fri, 9 Jan 2015 10:55:16 +0000 [thread overview]
Message-ID: <20150109105516.GA1600@casper.infradead.org> (raw)
In-Reply-To: <1420791818-22150-3-git-send-email-ying.xue@windriver.com>
On 01/09/15 at 04:23pm, Ying Xue wrote:
> static struct sock *netlink_lookup(struct net *net, int protocol, u32 portid)
> {
> struct netlink_table *table = &nl_table[protocol];
> @@ -1041,41 +1050,33 @@ netlink_update_listeners(struct sock *sk)
> static int netlink_insert(struct sock *sk, struct net *net, u32 portid)
> {
> struct netlink_table *table = &nl_table[sk->sk_protocol];
> - int err = -EADDRINUSE;
> -
> - mutex_lock(&nl_sk_hash_lock);
> - if (__netlink_lookup(table, portid, net))
> - goto err;
>
> - err = -EBUSY;
> if (nlk_sk(sk)->portid)
> - goto err;
> + return -EBUSY;
>
> - err = -ENOMEM;
> if (BITS_PER_LONG > 32 &&
> unlikely(atomic_read(&table->hash.nelems) >= UINT_MAX))
> - goto err;
> + return -ENOMEM;
>
> nlk_sk(sk)->portid = portid;
Since this code can now run in parallel, there is a race between
checking portid and then setting it. CPU#1 could overwrite portid after
CPU#0 has already checked portid, this would then insert the socket on
CPU#0 with the portid created on CPU#1. So this would need some kind
of atomic operation.
next prev parent reply other threads:[~2015-01-09 10:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-09 8:23 [PATCH net-next 0/3] remove nl_sk_hash_lock from netlink socket Ying Xue
2015-01-09 8:23 ` [PATCH net-next 1/3] rhashtable: involve rhashtable_lookup_compare_insert routine Ying Xue
2015-01-09 10:31 ` Thomas Graf
2015-01-09 8:23 ` [PATCH net-next 2/3] netlink: eliminate nl_sk_hash_lock Ying Xue
2015-01-09 10:55 ` Thomas Graf [this message]
2015-01-12 21:27 ` David Miller
2015-01-09 8:23 ` [PATCH net-next 3/3] rhashtable: add a note for grow and shrink decision functions Ying Xue
2015-01-09 10:31 ` Thomas Graf
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=20150109105516.GA1600@casper.infradead.org \
--to=tgraf@suug.ch \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=ying.xue@windriver.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).