From: Eric Dumazet <eric.dumazet@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Paul Mackerras <paulus@samba.org>,
tytso@mit.edu, Salman <sqazi@google.com>,
mingo@elte.hu, linux-kernel@vger.kernel.org,
peterz@infradead.org, tytso@google.com,
torvalds@linux-foundation.org, walken@google.com,
Chen Liqin <liqin.chen@sunplusct.com>,
Lennox Wu <lennox.wu@gmail.com>
Subject: Re: [PATCH] Fix a race in pid generation that causes pids to be reused immediately.
Date: Tue, 15 Jun 2010 06:38:46 +0200 [thread overview]
Message-ID: <1276576726.30434.209.camel@edumazet-laptop> (raw)
In-Reply-To: <20100614212150.4dcb1feb.akpm@linux-foundation.org>
Le lundi 14 juin 2010 à 21:21 -0700, Andrew Morton a écrit :
> On Tue, 15 Jun 2010 13:26:08 +1000 Paul Mackerras <paulus@samba.org> wrote:
>
> > On Mon, Jun 14, 2010 at 06:55:56PM -0700, Andrew Morton wrote:
> >
> > > > kernel/sched_clock.c: if (cmpxchg64(&scd->clock, old_clock, clock) != old_cloc
> > >
> > > I guess that'll flush out any stragglers.
> >
> > And break most non-x86 32-bit architectures, including 32-bit powerpc.
>
> If CONFIG_SMP=y, yes. On UP there's a generic implementation
> (include/asm-generic/cmpxchg-local.h, include/asm-generic/cmpxchg.h)
>
> > Fortunately that code is only used if CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
> > is set, and it looks like only x86 and ia64 set it.
> >
>
> If that happens then the best fix is for those architectures to get
> themselves a cmpxchg64(). Unless for some reason it's simply
> unimplementable? Worst case I guess one could use a global spinlock.
> Second-worst-case: hashed spinlocks.
Hmm, this reminds me a patch I had somewhere, not yet sent to David :)
1) cmpxchg() was not available for all arches, maybe
atomic_long_cmpxchg() is ?
2) I am not sure atomic_long_t quarantee that all 32 or 64 bits of the
underlying long container are available.
Thanks !
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index a291edb..335ca89 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1268,17 +1268,18 @@ skip_hashing:
void rt_bind_peer(struct rtable *rt, int create)
{
- static DEFINE_SPINLOCK(rt_peer_lock);
struct inet_peer *peer;
peer = inet_getpeer(rt->rt_dst, create);
- spin_lock_bh(&rt_peer_lock);
- if (rt->peer == NULL) {
- rt->peer = peer;
+#if defined(__HAVE_ARCH_CMPXCHG)
+ if (!cmpxchg(&rt->peer, NULL, peer))
peer = NULL;
- }
- spin_unlock_bh(&rt_peer_lock);
+#else
+ BUILD_BUG_ON(sizeof(rt->peer) != sizeof(atomic_long_t));
+ if (!atomic_long_cmpxchg((atomic_long_t *)&rt->peer, 0, (long)peer))
+ peer = NULL;
+#endif
if (peer)
inet_putpeer(peer);
}
next prev parent reply other threads:[~2010-06-15 4:38 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-11 17:17 Salman
2010-06-11 17:44 ` Linus Torvalds
2010-06-11 22:49 ` Salman
2010-06-11 23:07 ` Linus Torvalds
2010-06-14 23:58 ` Andrew Morton
2010-06-15 0:56 ` tytso
2010-06-15 1:55 ` Andrew Morton
2010-06-15 3:26 ` Paul Mackerras
2010-06-15 4:21 ` Andrew Morton
2010-06-15 4:38 ` Eric Dumazet [this message]
2010-06-15 6:57 ` Benjamin Herrenschmidt
2010-06-15 7:25 ` Paul Mackerras
2010-06-15 12:56 ` tytso
2010-06-15 13:06 ` Kyle McMartin
2010-06-15 14:35 ` Peter Zijlstra
2010-06-15 19:37 ` Andrew Morton
2010-06-15 18:35 ` [PATCH 0/1] (Was: Fix a race in pid generation that causes pids to be reused immediately.) Oleg Nesterov
2010-06-15 18:35 ` [PATCH 1/1] pids: alloc_pidmap: remove the unnecessary boundary checks Oleg Nesterov
-- strict thread matches above, loose matches on Subject: below --
2010-06-10 21:24 [PATCH] Fix a race in pid generation that causes pids to be reused immediately Salman
2010-06-10 20:09 Salman
2010-06-10 20:38 ` tytso
2010-06-10 21:04 ` Salman Qazi
2010-06-09 21:00 Salman
2010-06-09 21:21 ` Linus Torvalds
2010-06-09 21:33 ` Peter Zijlstra
2010-06-09 22:20 ` Linus Torvalds
2010-06-09 22:27 ` Linus Torvalds
2010-06-10 0:08 ` Salman Qazi
2010-06-10 0:20 ` Linus Torvalds
[not found] ` <AANLkTilXJ0X2qxD9cNTlLayKzySEZu1HEZUWu--Go8kw@mail.gmail.com>
2010-06-10 5:55 ` Salman Qazi
2010-06-10 16:39 ` Linus Torvalds
2010-06-09 6:24 Salman
2010-06-09 6:53 ` Andi Kleen
2010-06-09 9:48 ` Ingo Molnar
2010-06-09 15:39 ` Linus Torvalds
2010-06-09 15:50 ` tytso
2010-06-09 16:06 ` Linus Torvalds
2010-06-09 17:10 ` tytso
2010-06-09 17:23 ` Linus Torvalds
2010-06-09 17:25 ` Linus Torvalds
2010-06-09 17:34 ` tytso
2010-06-09 17:43 ` Linus Torvalds
2010-06-09 17:47 ` tytso
2010-06-09 18:09 ` Salman Qazi
2010-06-09 11:49 ` Michel Lespinasse
2010-06-09 12:37 ` tytso
2010-06-09 12:17 ` tytso
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=1276576726.30434.209.camel@edumazet-laptop \
--to=eric.dumazet@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=lennox.wu@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=liqin.chen@sunplusct.com \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
--cc=sqazi@google.com \
--cc=torvalds@linux-foundation.org \
--cc=tytso@google.com \
--cc=tytso@mit.edu \
--cc=walken@google.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
all inboxes | Powered by JetHome®