linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Vegard Nossum" <vegard.nossum@gmail.com>
To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [BUG 2.6.24-rc3-git6] SLUB's ksize() fails for size > 2048.
Date: Sun, 2 Dec 2007 17:43:09 +0100	[thread overview]
Message-ID: <19f34abd0712020843m1dccfa3bu38388e1a53b05fc@mail.gmail.com> (raw)
In-Reply-To: <19f34abd0712020830y4825691atdfc9dac07ce4cb35@mail.gmail.com>

On Dec 2, 2007 5:30 PM, Vegard Nossum <vegard.nossum@gmail.com> wrote:
> On Dec 2, 2007 11:39 AM, Tetsuo Handa
> <penguin-kernel@i-love.sakura.ne.jp> wrote:
> > Hello.
> >
> > I can't pass memory allocated by kmalloc() to ksize()
> > if it is allocated by SLUB allocator and
> > size is larger than (I guess) PAGE_SIZE / 2.
> >
> > Regards.
> The error of ksize() seems to be that it does not check if the
> allocation was made by SLUB or the page allocator. Maybe something
> like this will fix it? (completely untested)

That didn't work. I guess that's what you get for no testing ;-) After
some more investigations, it seems that this is the correct way to fix
it (and tested!):

diff --git a/mm/slub.c b/mm/slub.c
index 9acb413..b9f37cb 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2558,8 +2558,12 @@ size_t ksize(const void *object)
        if (unlikely(object == ZERO_SIZE_PTR))
                return 0;

-       page = get_object_page(object);
+       page = virt_to_head_page(object);
        BUG_ON(!page);
+
+       if (unlikely(!PageSlab(page)))
+               return PAGE_SIZE << compound_order(page);
+
        s = page->slab;
        BUG_ON(!s);


> It's going to round up, though, so you would get ksize(kmalloc(2049))
> = PAGE_SIZE.


Vegard

--
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:[~2007-12-02 16:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-02 10:39 Tetsuo Handa
2007-12-02 15:56 ` Mark Lord
2007-12-02 16:03   ` Mark Lord
2007-12-02 16:16   ` Adrian Bunk
2007-12-02 16:13 ` Adrian Bunk
2007-12-02 16:30 ` Vegard Nossum
2007-12-02 16:43   ` Vegard Nossum [this message]
2007-12-02 18:23     ` Pekka Enberg
2007-12-03 11:33     ` Tetsuo Handa

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=19f34abd0712020843m1dccfa3bu38388e1a53b05fc@mail.gmail.com \
    --to=vegard.nossum@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    /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