From: Pekka Enberg <penberg@cs.helsinki.fi>
To: Linus Torvalds <torvalds@osdl.org>
Cc: "Daniel Hokka Zakrisson" <daniel@hozac.com>,
linux-kernel@vger.kernel.org,
"Björn Steinbrink" <B.Steinbrink@gmx.de>,
greg@kroah.com, matthew@wil.cx,
"Christoph Lameter" <clameter@sgi.com>,
manfred@colorfullife.com, akpm@osdl.org
Subject: Re: [PATCH] fs: fcntl_setlease defies lease_init assumptions
Date: Mon, 08 May 2006 22:36:30 +0300 [thread overview]
Message-ID: <1147116991.11282.3.camel@localhost> (raw)
In-Reply-To: <Pine.LNX.4.64.0605080913240.3718@g5.osdl.org>
On Mon, 2006-05-08 at 09:28 -0700, Linus Torvalds wrote:
> So from a performance standpoint, maybe my previous trivial patch is the
> right thing to do, along with an even _stronger_ test for
> kmem_cache_free(), where we could do
>
> BUG_ON(virt_to_cache(objp) != cachep);
>
> which you can then remove from the slab debug case.
>
> So for a lot of the normal paths, you'd basically have no extra cost (two
> instructions, no data cache pressure), but for kmem_cache_free() we'd have
> a slight overhead (but a lot lower than SLAB_DEBUG, and at least for NUMA
> it's reading a cacheline that we'd be using regardless.
>
> I think it sounds like it's worth it, but I'm not going to really push it.
Sounds good to me. Andrew?
Pekka
[PATCH] slab: verify pointers before free
From: Pekka Enberg <penberg@cs.helsinki.fi>
Passing an invalid pointer to kfree() and kmem_cache_free() is likely
to cause bad memory corruption or even take down the whole system
because the bad pointer is likely reused immediately due to the
per-CPU caches. Until now, we don't do any verification for this if
CONFIG_DEBUG_SLAB is disabled.
As suggested by Linus, add PageSlab check to page_to_cache() and
page_to_slab() to verify pointers passed to kfree(). Also, move the
stronger check from cache_free_debugcheck() to kmem_cache_free() to
ensure the passed pointer actually belongs to the cache we're about to
free the object.
For page_to_cache() and page_to_slab(), the assertions should have
virtually no extra cost (two instructions, no data cache pressure) and
for kmem_cache_free() the overhead should be minimal.
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---
mm/slab.c | 13 ++++---------
1 files changed, 4 insertions(+), 9 deletions(-)
8e4b800f3fb45bbffcc7b365115a63b2a4c911cb
diff --git a/mm/slab.c b/mm/slab.c
index c32af7e..bc9805a 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -597,6 +597,7 @@ static inline struct kmem_cache *page_ge
{
if (unlikely(PageCompound(page)))
page = (struct page *)page_private(page);
+ BUG_ON(!PageSlab(page));
return (struct kmem_cache *)page->lru.next;
}
@@ -609,6 +610,7 @@ static inline struct slab *page_get_slab
{
if (unlikely(PageCompound(page)))
page = (struct page *)page_private(page);
+ BUG_ON(!PageSlab(page));
return (struct slab *)page->lru.prev;
}
@@ -2597,15 +2599,6 @@ static void *cache_free_debugcheck(struc
kfree_debugcheck(objp);
page = virt_to_page(objp);
- if (page_get_cache(page) != cachep) {
- printk(KERN_ERR "mismatch in kmem_cache_free: expected "
- "cache %p, got %p\n",
- page_get_cache(page), cachep);
- printk(KERN_ERR "%p is %s.\n", cachep, cachep->name);
- printk(KERN_ERR "%p is %s.\n", page_get_cache(page),
- page_get_cache(page)->name);
- WARN_ON(1);
- }
slabp = page_get_slab(page);
if (cachep->flags & SLAB_RED_ZONE) {
@@ -3361,6 +3354,8 @@ void kmem_cache_free(struct kmem_cache *
{
unsigned long flags;
+ BUG_ON(virt_to_cache(objp) != cachep);
+
local_irq_save(flags);
__cache_free(cachep, objp);
local_irq_restore(flags);
--
1.3.0
next prev parent reply other threads:[~2006-05-08 19:36 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-07 23:21 [PATCH] fs: fcntl_setlease defies lease_init assumptions Daniel Hokka Zakrisson
2006-05-08 3:33 ` Linus Torvalds
2006-05-08 3:34 ` Linus Torvalds
2006-05-08 8:02 ` Daniel Hokka Zakrisson
2006-05-08 7:57 ` Daniel Hokka Zakrisson
2006-05-08 8:31 ` Pekka Enberg
2006-05-08 8:34 ` Pekka Enberg
2006-05-08 15:12 ` Linus Torvalds
2006-05-08 16:06 ` Pekka Enberg
2006-05-08 16:28 ` Linus Torvalds
2006-05-08 19:36 ` Pekka Enberg [this message]
2006-05-09 3:38 ` Christoph Lameter
2006-05-09 3:49 ` Martin J. Bligh
2006-05-09 5:31 ` Christoph Lameter
2006-05-09 6:16 ` Martin J. Bligh
2006-05-09 6:22 ` Manfred Spraul
2006-05-09 6:35 ` Keith Owens
2006-05-09 6:37 ` Nick Piggin
2006-05-09 10:26 ` Pekka J Enberg
2006-05-09 18:25 ` Manfred Spraul
2006-05-09 18:56 ` Linus Torvalds
2006-05-09 19:05 ` Pekka Enberg
2006-05-09 19:15 ` Pekka Enberg
2006-05-09 14:40 ` Linus Torvalds
2006-05-09 23:59 ` Christoph Lameter
2006-05-08 16:36 ` Dave Jones
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=1147116991.11282.3.camel@localhost \
--to=penberg@cs.helsinki.fi \
--cc=B.Steinbrink@gmx.de \
--cc=akpm@osdl.org \
--cc=clameter@sgi.com \
--cc=daniel@hozac.com \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=manfred@colorfullife.com \
--cc=matthew@wil.cx \
--cc=torvalds@osdl.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.