From: John Reiser <jreiser@BitWagon.com>
To: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Steve VanDeBogart <vandebo-lkml@nerdbox.net>,
user-mode-linux-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org,
"Paul E. McKenney" <paulmck@us.ibm.com>,
Ingo Molnar <mingo@elte.hu>,
dkegel@google.com, jiayingz@google.com
Subject: Re: [uml-devel] [PATCH 5/6] slab: Annotate slab
Date: Tue, 02 Sep 2008 19:54:47 -0700 [thread overview]
Message-ID: <48BDFC77.4060909@BitWagon.com> (raw)
In-Reply-To: <84144f020808300350i7cb2d23aj6d1ffcbeceaf7e9c@mail.gmail.com>
Pekka Enberg wrote:
> Steve VanDeBogart proposed
[snip]
>> Index: linux-2.6.27-rc5/mm/slab.c
>> ===================================================================
>> --- linux-2.6.27-rc5.orig/mm/slab.c 2008-08-29 14:24:25.000000000 -0700
>> +++ linux-2.6.27-rc5/mm/slab.c 2008-08-29 14:24:42.000000000 -0700
[snip]
> @@ -3466,6 +3481,8 @@
>> objp = cache_alloc_debugcheck_after(cachep, flags, objp, caller);
>> prefetchw(objp);
>>
>> + if (!cachep->ctor)
>> + VALGRIND_MALLOCLIKE_BLOCK(objp, cachep->buffer_size, 0, 0);
>> if (unlikely((flags & __GFP_ZERO) && objp))
>> memset(objp, 0, obj_size(cachep));
>>
[snip]
> I'm not sure why you want to treat caches with constructor
> differently. Sure, the memory regions *are* initialized but from
> programmer's point of view you're not supposed to be touching the
> memory unless you got it from kmalloc() or kmem_cache_alloc(). Same
> goes for kfree() and kmem_cache_free() -- no touchy touchy after you
> pass a pointer to either of the functions (unless you're RCU, of
> course).
Hi, I developed the predecessor to Steve's patches. The patch treats
a cache with a constructor differently because the semantics of kmalloc
are different in that case. If a cache has a constructor then the
object returned by kmalloc has been initialized for certain. Namely,
the constructor initialized the object before it was kmalloc'ed the first
time, and each corresponding caller [re-]initialized the object before
calling kfree. This is emphasized by comments in mm/slab.c:
* This means, that your constructor is used only for newly allocated
* slabs and you must pass objects with the same initializations to
* kmem_cache_free.
The slab allocator has the property that the contents of a block [object]
that is returned by kmalloc are identical to the contents that were passed
to kfree (or back as result from the constructor) unless something special
happens, such as SLAB_POISON. A block [object] which is handed back and
forth between kfree and kmalloc builds and retains history throughout the
lifetime of the cache. This property is directly contrary to the semantics
of libc malloc. The contents of the result of libc malloc must be considered
to be *un*initialized always.
Yes, there is at least one kmalloc+kfree slab object cache that depends on
retaining state from kfree to kmalloc. My first attempt treated kmalloc+kfree
like libc malloc+free, but I soon learned that was not the actual semantics.
Because the slab allocator deals in objects that persist through kfree
and kmalloc, then there are only two indications that objects ever become
uninitialized: SLAB_POISON, and not having a constructor. Obviously the
application of SLAB_POISON means that the object becomes [logically] uninit.
Not having a constructor *tends* to indicate that kmalloc() implies uninit,
by chain of reasoning based on the comment quoted above from mm/slab.c.
If the object was uninit upon first kmalloc, and if kfree is supposed to
receive objects that are "ready for kmalloc", and because a caller cannot
discern the first-ever return of an object by kmalloc, then the caller
must treat each result of kmalloc (from that particular cache) as uninit.
It would be helpful if each cache had a documenting comment such as "This
cache depends on objects whose contents persist from kfree() to kmalloc()"
or a comment such as "An object in this cache is considered to become
uninitialized when the object is passed to kfree."
With regard to Read-Copy-Update, I anticipate that RCU will require
special annotations because of the deliberate references after kfree
and before the next corresponding kmalloc. These special annotations
will require great care, because bugs in this area have high value.
--
John Reiser, jreiser@BitWagon.com
next prev parent reply other threads:[~2008-09-03 2:55 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-29 23:12 [PATCH 0/6] support valgrinding uml Steve VanDeBogart
2008-08-29 23:14 ` [PATCH 1/6] base: Valgrind headers and Kconfig Steve VanDeBogart
2008-09-01 9:32 ` Andi Kleen
2008-09-01 14:06 ` Jeff Dike
2008-09-01 14:22 ` Andi Kleen
2008-09-01 15:47 ` Jeff Dike
2008-08-29 23:15 ` [PATCH 2/6] UML: Don't valgrind userspace Steve VanDeBogart
2008-09-05 16:37 ` [uml-devel] " Jeff Dike
2008-09-06 20:55 ` John Reiser
2008-09-06 22:12 ` Jeff Dike
2008-08-29 23:16 ` [PATCH 3/6] UML and sched: Annotate stacks Steve VanDeBogart
2008-08-29 23:16 ` [PATCH 4/6] VM: Annotate pagealloc Steve VanDeBogart
2008-08-30 10:57 ` Pekka Enberg
2008-09-03 5:25 ` [uml-devel] " Steve VanDeBogart
2008-09-03 9:35 ` Pekka Enberg
2008-08-29 23:17 ` [PATCH 5/6] slab: Annotate slab Steve VanDeBogart
2008-08-30 10:50 ` Pekka Enberg
2008-09-03 2:54 ` John Reiser [this message]
2008-09-03 9:39 ` [uml-devel] " Pekka J Enberg
2008-09-03 5:08 ` Steve VanDeBogart
2008-09-03 9:27 ` Pekka Enberg
2008-09-03 9:40 ` Pekka Enberg
2008-09-03 15:42 ` Steve VanDeBogart
2008-09-04 7:33 ` Pekka Enberg
2008-08-29 23:18 ` [PATCH 6/6] VM: Annotate vmalloc Steve VanDeBogart
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=48BDFC77.4060909@BitWagon.com \
--to=jreiser@bitwagon.com \
--cc=dkegel@google.com \
--cc=jiayingz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulmck@us.ibm.com \
--cc=penberg@cs.helsinki.fi \
--cc=user-mode-linux-devel@lists.sourceforge.net \
--cc=vandebo-lkml@nerdbox.net \
/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