[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CACVXFVPKgg98UBDaCC9eU605mRYrtCiPH6+zQLcvdY2Hp4LMYg@mail.gmail.com>
Date: Sat, 10 Dec 2011 22:07:08 +0800
From: Ming Lei <tom.leiming@...il.com>
To: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: gregkh@...e.de, akpm@...ux-foundation.org,
linux-kernel@...r.kernel.org, ostrikov@...dia.com,
adobriyan@...il.com, eric.dumazet@...il.com, mingo@...e.hu,
Oliver Neukum <oneukum@...e.de>
Subject: Re: [PATCH 3/3] kref: Remove the memory barriers
Hi,
On Sat, Dec 10, 2011 at 6:43 PM, Peter Zijlstra <a.p.zijlstra@...llo.nl> wrote:
> Commit 1b0b3b9980e ("kref: fix CPU ordering with respect to krefs")
> wrongly adds memory barriers to kref.
>
> It states:
>
> some atomic operations are only atomic, not ordered. Thus a CPU is allowed
> to reorder memory references to an object to before the reference is
> obtained. This fixes it.
>
> While true, it fails to show why this is a problem. I say it is not a
IMO, the added two barriers are pairs of the implicit barrier in kref_put, so
that we can order between kref_init/kref_get and kref_put.
> problem because if there is a race with kref_put() such that we could
> end up referencing a free'd object without this memory barrier, we
> would still have that race with the memory barrier.
>
> The kref_put() in question could complete (and free the object) before
> the atomic_inc() and we'd still be up shit creek.
>
> The kref_init() case is even worse, if your object is published at this
> time you're so wrong the memory barrier won't make a difference what
> so ever. If its not published, the act of publishing should include
> the needed barriers/locks to make sure all writes prior to the act of
> publishing are complete such that others will only observe a complete
> object.
>
> Cc: adobriyan@...il.com
> Cc: eric.dumazet@...il.com
> Cc: mingo@...e.hu
> Cc: Oliver Neukum <oneukum@...e.de>
> Signed-off-by: Peter Zijlstra <a.p.zijlstra@...llo.nl>
> ---
> include/linux/kref.h | 2 --
> 1 file changed, 2 deletions(-)
>
> Index: linux-2.6/include/linux/kref.h
> ===================================================================
> --- linux-2.6.orig/include/linux/kref.h
> +++ linux-2.6/include/linux/kref.h
> @@ -28,7 +28,6 @@ struct kref {
> static inline void kref_init(struct kref *kref)
> {
> atomic_set(&kref->refcount, 1);
> - smp_mb();
> }
>
> /**
> @@ -39,7 +38,6 @@ static inline void kref_get(struct kref
> {
> WARN_ON(!atomic_read(&kref->refcount));
> atomic_inc(&kref->refcount);
> - smp_mb__after_atomic_inc();
> }
>
> /**
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@...r.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
thanks,
--
Ming Lei
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists