From: Fan Du <fan.du@windriver.com>
To: "Eric Dumazet" <eric.dumazet@gmail.com>, 王聪 <xiyou.wangcong@gmail.com>
Cc: <steffen.klassert@secunet.com>, <davem@davemloft.net>,
<netdev@vger.kernel.org>
Subject: Re: [PATCHv2 ipsec-next] xfrm: Namespacify xfrm_policy_sk_bundles
Date: Thu, 19 Dec 2013 09:35:57 +0800 [thread overview]
Message-ID: <52B24D7D.6060902@windriver.com> (raw)
In-Reply-To: <1387342211.19078.295.camel@edumazet-glaptop2.roam.corp.google.com>
Hi, Eric and Cong
On 2013年12月18日 12:50, Eric Dumazet wrote:
>> static DEFINE_SPINLOCK(xfrm_policy_afinfo_lock);
>> > static struct xfrm_policy_afinfo __rcu *xfrm_policy_afinfo[NPROTO]
>> > __read_mostly;
>> > @@ -2108,12 +2106,8 @@ struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
>> > }
>> >
>> > dst_hold(&xdst->u.dst);
>> > -
>> > - spin_lock_bh(&net->xfrm.xfrm_policy_sk_bundle_lock);
>> > - xdst->u.dst.next = xfrm_policy_sk_bundles;
>> > - xfrm_policy_sk_bundles =&xdst->u.dst;
>> > - spin_unlock_bh(&net->xfrm.xfrm_policy_sk_bundle_lock);
>> > -
>> > + xdst->u.dst.next = xchg(&net->xfrm.xfrm_policy_sk_bundles,
>> > + &xdst->u.dst);
> This is not safe.
>
> Take a look at include/linux/llist.h if you really want to avoid the
> spinlock.
Here is my understanding about llist_add_batch, assume when add one single
entry into list, i.e., new_last equates new_first.
1 do {
2 new->next = first = ACCESS_ONCE(head->first);
3 } while (cmpxchg(&head->first, first, new) != first);
Caller 1:Add new1 into head Caller 2:Add new2 into head
line 2: Link head into new1
line 2: Link head into new2
line 3: Make the cmpxchg, then succeed.
After this, new2 -> old_head
line 3: Make the cmpxchg, failed, try
again will succeed, after this
new1 -> new2 -> old_head
So in order to not use locks, try again if cmpxchg found out someone else
has update the head. For the case involved in the patch, the problem is, after
xchg, assign the old head to the new->next will race with the delete part when
saving the head for deleting after setting the head to NULL, as the traverse
of saved head probably not see a consistent list, that's a broken one.
I think an analogy of llist_add_batch for the updating part will be ok for this:
struct dst_entry *first;
do {
xdst->u.dst.next = first = ACCESS_ONCE(xfrm_policy_sk_bundles);
} while (cmpxchg(&xfrm_policy_sk_bundles, first, &xdst->u.dst) != first);
And the deleting part:
head = xchg(&net->xfrm.xfrm_policy_sk_bundles, NULL);
--
浮沉随浪只记今朝笑
--fan
next prev parent reply other threads:[~2013-12-19 1:36 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-18 3:34 [PATCHv2 ipsec-next] xfrm: Namespacify xfrm_policy_sk_bundles Fan Du
2013-12-18 4:50 ` Eric Dumazet
2013-12-18 5:33 ` Cong Wang
2013-12-18 5:33 ` Fan Du
2013-12-18 5:44 ` Eric Dumazet
2013-12-19 1:35 ` Fan Du [this message]
2013-12-19 2:15 ` Eric Dumazet
2013-12-19 3:17 ` [PATCHv3 net-next] " Fan Du
2013-12-19 3:44 ` Eric Dumazet
2013-12-19 7:47 ` Fan Du
2013-12-20 3:34 ` [PATCHv4 " Fan Du
2013-12-24 1:12 ` Fan Du
2013-12-24 5:31 ` David Miller
2013-12-24 5:39 ` Fan Du
2013-12-24 9:50 ` Steffen Klassert
2013-12-24 9:56 ` Fan Du
2013-12-24 17:54 ` David Miller
2013-12-24 10:35 ` Steffen Klassert
2013-12-25 6:40 ` Fan Du
2013-12-25 8:11 ` Timo Teras
2013-12-25 8:44 ` Fan Du
2014-01-06 10:35 ` Steffen Klassert
2014-01-07 2:43 ` Fan Du
2014-01-09 12:38 ` Steffen Klassert
2014-01-10 9:23 ` Fan Du
2013-12-19 3:48 ` [PATCHv3 " Eric Dumazet
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=52B24D7D.6060902@windriver.com \
--to=fan.du@windriver.com \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=steffen.klassert@secunet.com \
--cc=xiyou.wangcong@gmail.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).