linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Lameter <cl@linux.com>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: Pekka Enberg <penberg@kernel.org>,
	David Rientjes <rientjes@google.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	Andrey Konovalov <andreyknvl@google.com>,
	Alexander Potapenko <glider@google.com>,
	Paul McKenney <paulmck@linux.vnet.ibm.com>
Subject: Re: Is it OK to pass non-acquired objects to kfree?
Date: Wed, 9 Sep 2015 12:56:20 -0500 (CDT)	[thread overview]
Message-ID: <alpine.DEB.2.11.1509091251150.20311@east.gentwo.org> (raw)
In-Reply-To: <CACT4Y+a6rjbEoP7ufgyJimjx3qVh81TToXjL9Rnj-bHNregZXg@mail.gmail.com>

On Wed, 9 Sep 2015, Dmitry Vyukov wrote:

> > Guess this means that cachelines (A) may not have been be written back to
> > memory when the pointer to the object is written to another cacheline(B)
> > and that cacheline B arrives at the other processor first which has
> > outdated cachelines A in its cache? So the other processor uses the
> > contents of B to get to the pointer to A but then accesses outdated
> > information since the object contents cachelines (A) have not arrive there
> > yet?
>
> That's one example.
> Another example will be that kfree reads size from the object _before_
> the object to the pointer is read. That sounds crazy, but it as
> actually possible on Alpha processors.

The size is encoded in the kmem_cache structure which is not changed. How
can that be relevant?

> Another example will be that C compiler lets a store to the object in
> kmalloc sink below the store of the pointer to the object into global.

Well if the pointer is used nakedly to communicate between threads the
barriers need to be used but what does this have to do with slabs?

> > Ok lets say that is the case then any write attempt to A results in an
> > exclusive cacheline state and at that point the cacheline is going to
> > reflect current contents. So if kfree would write to the object then it
> > will have the current information.
>
> No, because store to the object can still be pending on another CPU.

That would violate the cache coherency protocol as far as I can tell?

> So kfree can get the object in E state in cache, but then another CPU
> will finally issue the store and overwrite the slab freelist.

Sounds like a broken processor design to me. AFAICT the MESI protocol does
not allow this.

> > Also what does it matter for kfree since the contents of the object are no
> > longer in use?
>
> I don't understand. First, it is not "not in use" infinitely, it can
> be in use the very next moment. Also, we don't want corruption of slab
> freelist as well. And we don't want spurious failure of debug
> allocator that checks that there no writes after free.

Slab freelists are protected by locks.

A processor that can randomly defer writes to cachelines in the face of
other processors owning cachelines exclusively does not seem sane to me.
In fact its no longer exclusive.

> > Could you please come up with a concrete example where there is
> > brokenness that we need to consider.
>
> Well, both examples in the first email are broken according to all of
> Documentation/memory-barriers.txt, Alpha processor manual and C
> standard (assuming that object passed to kfree must be in "quiescent"
> state).
> If you want a description of an exact scenario of how it can break:
> building of freelist in kfree can be hoisted above check of
> atomic_read(&pid->count) == 1 on Alpha processors, then the freelist
> can become corrupted.

Sounds like the atomic_read needs more barriers.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2015-09-09 17:56 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-08  7:51 Dmitry Vyukov
2015-09-08 14:13 ` Christoph Lameter
2015-09-08 14:41   ` Dmitry Vyukov
2015-09-08 15:13     ` Christoph Lameter
2015-09-08 15:23       ` Dmitry Vyukov
2015-09-08 15:33         ` Christoph Lameter
2015-09-08 15:37           ` Dmitry Vyukov
2015-09-08 17:09             ` Christoph Lameter
2015-09-08 19:24               ` Dmitry Vyukov
2015-09-09 14:02                 ` Christoph Lameter
2015-09-09 14:19                   ` Dmitry Vyukov
2015-09-09 14:36                     ` Christoph Lameter
2015-09-09 15:30                       ` Dmitry Vyukov
2015-09-09 15:44                         ` Christoph Lameter
2015-09-09 16:09                           ` Dmitry Vyukov
2015-09-09 17:56                             ` Christoph Lameter [this message]
2015-09-09 18:44                               ` Paul E. McKenney
2015-09-09 19:01                                 ` Christoph Lameter
2015-09-09 20:36                                   ` Paul E. McKenney
2015-09-09 23:23                                     ` Store Buffers (was Re: Is it OK to pass non-acquired objects to kfree?) Christoph Lameter
2015-09-10  0:08                                       ` Paul E. McKenney
2015-09-10  0:21                                         ` Christoph Lameter
2015-09-10  1:10                                           ` Paul E. McKenney
2015-09-10  1:47                                             ` Christoph Lameter
2015-09-10  7:38                                               ` Vlastimil Babka
2015-09-10 16:37                                                 ` Christoph Lameter
2015-09-10  7:22                                       ` Vlastimil Babka
2015-09-10 16:36                                         ` Christoph Lameter
2015-09-09 23:31                                     ` Is it OK to pass non-acquired objects to kfree? Christoph Lameter
2015-09-10  9:55                                       ` Dmitry Vyukov
2015-09-10 10:42                                         ` Jesper Dangaard Brouer
2015-09-10 12:08                                           ` Dmitry Vyukov
2015-09-10 13:37                                             ` Eric Dumazet
2015-09-10 12:47                                         ` Vlastimil Babka
2015-09-10 13:17                                           ` Dmitry Vyukov
2015-09-10 17:13                                         ` Paul E. McKenney
2015-09-10 17:21                                           ` Paul E. McKenney
2015-09-10 17:26                                           ` Dmitry Vyukov
2015-09-10 17:44                                             ` Paul E. McKenney
2015-09-10 18:01                                           ` Christoph Lameter
2015-09-10 18:11                                             ` Dmitry Vyukov
2015-09-10 18:13                                               ` Christoph Lameter
2015-09-10 18:26                                                 ` Dmitry Vyukov
2015-09-10 18:56                                                   ` Paul E. McKenney
2015-09-10 22:00                                                   ` Christoph Lameter

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=alpine.DEB.2.11.1509091251150.20311@east.gentwo.org \
    --to=cl@linux.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@google.com \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-mm@kvack.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=penberg@kernel.org \
    --cc=rientjes@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