From: Miaohe Lin <linmiaohe@huawei.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: <gregkh@linuxfoundation.org>, <faiyazm@codeaurora.org>,
<andreyknvl@gmail.com>, <ryabinin.a.a@gmail.com>,
<thgarnie@google.com>, <keescook@chromium.org>,
<bharata@linux.ibm.com>, <guro@fb.com>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Christoph Lameter <cl@linux.com>,
Pekka Enberg <penberg@kernel.org>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>
Subject: Re: [PATCH 2/5] mm, slub: fix mismatch between reconstructed freelist depth and cnt
Date: Fri, 8 Oct 2021 10:01:08 +0800 [thread overview]
Message-ID: <c8cbecc8-e176-e63d-1c7e-e624410f685f@huawei.com> (raw)
In-Reply-To: <3b0351d3-4753-1d69-a115-60b20c69656c@suse.cz>
On 2021/10/5 17:57, Vlastimil Babka wrote:
> On 9/16/21 14:39, Miaohe Lin wrote:
>> If object's reuse is delayed, it will be excluded from the reconstructed
>> freelist. But we forgot to adjust the cnt accordingly. So there will be
>> a mismatch between reconstructed freelist depth and cnt. This will lead
>> to free_debug_processing() complain about freelist count or a incorrect
>> slub inuse count.
>>
>> Fixes: c3895391df38 ("kasan, slub: fix handling of kasan_slab_free hook")
>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>
> Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
>
> I was worried about taking pointer of the cnt parameter when it's hardcoded
> 1, whether it would destroy inlining. Looks like not, luckily, the function
> is just renamed:
>
Many thanks for your review and thoughtful consideration! :)
>> ./scripts/bloat-o-meter mm/slub.o slub.o.after
> add/remove: 1/1 grow/shrink: 0/0 up/down: 292/-292 (0)
> Function old new delta
> slab_free_freelist_hook.constprop - 292 +292
> slab_free_freelist_hook 292 - -292
>
>> ---
>> mm/slub.c | 11 +++++++++--
>> 1 file changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/mm/slub.c b/mm/slub.c
>> index ed160b6c54f8..a56a6423d4e8 100644
>> --- a/mm/slub.c
>> +++ b/mm/slub.c
>> @@ -1701,7 +1701,8 @@ static __always_inline bool slab_free_hook(struct kmem_cache *s,
>> }
>>
>> static inline bool slab_free_freelist_hook(struct kmem_cache *s,
>> - void **head, void **tail)
>> + void **head, void **tail,
>> + int *cnt)
>> {
>>
>> void *object;
>> @@ -1728,6 +1729,12 @@ static inline bool slab_free_freelist_hook(struct kmem_cache *s,
>> *head = object;
>> if (!*tail)
>> *tail = object;
>> + } else {
>> + /*
>> + * Adjust the reconstructed freelist depth
>> + * accordingly if object's reuse is delayed.
>> + */
>> + --(*cnt);
>> }
>> } while (object != old_tail);
>>
>> @@ -3480,7 +3487,7 @@ static __always_inline void slab_free(struct kmem_cache *s, struct page *page,
>> * With KASAN enabled slab_free_freelist_hook modifies the freelist
>> * to remove objects, whose reuse must be delayed.
>> */
>> - if (slab_free_freelist_hook(s, &head, &tail))
>> + if (slab_free_freelist_hook(s, &head, &tail, &cnt))
>> do_slab_free(s, page, head, tail, cnt, addr);
>> }
>>
>>
>
> .
>
next prev parent reply other threads:[~2021-10-08 2:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-16 12:39 [PATCH 0/5] Fixups for slub Miaohe Lin
2021-09-16 12:39 ` [PATCH 1/5] mm, slub: fix two bugs in slab_debug_trace_open() Miaohe Lin
2021-10-05 9:46 ` Vlastimil Babka
2021-09-16 12:39 ` [PATCH 2/5] mm, slub: fix mismatch between reconstructed freelist depth and cnt Miaohe Lin
2021-10-05 9:57 ` Vlastimil Babka
2021-10-08 2:01 ` Miaohe Lin [this message]
2021-09-16 12:39 ` [PATCH 3/5] mm, slub: fix potential memoryleak in kmem_cache_open() Miaohe Lin
2021-10-05 10:02 ` Vlastimil Babka
2021-09-16 12:39 ` [PATCH 4/5] mm, slub: fix potential use-after-free in slab_debugfs_fops Miaohe Lin
2021-10-05 10:36 ` Vlastimil Babka
2021-09-16 12:39 ` [PATCH 5/5] mm, slub: fix incorrect memcg slab count for bulk free Miaohe Lin
2021-10-05 10:50 ` Vlastimil Babka
2021-10-05 21:43 ` Andrew Morton
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=c8cbecc8-e176-e63d-1c7e-e624410f685f@huawei.com \
--to=linmiaohe@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=bharata@linux.ibm.com \
--cc=cl@linux.com \
--cc=faiyazm@codeaurora.org \
--cc=gregkh@linuxfoundation.org \
--cc=guro@fb.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--cc=ryabinin.a.a@gmail.com \
--cc=thgarnie@google.com \
--cc=vbabka@suse.cz \
/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