From: Catalin Marinas <catalin.marinas@arm.com>
To: Liu Shixin <liushixin2@huawei.com>
Cc: Patrick Wang <patrick.wang.shcn@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Kefeng Wang <wangkefeng.wang@huawei.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 7/7] mm/kmemleak: fix partially freeing unknown object warning
Date: Wed, 18 Oct 2023 17:39:02 +0100 [thread overview]
Message-ID: <ZTAKJstsXrcUtOjn@arm.com> (raw)
In-Reply-To: <20231018102952.3339837-8-liushixin2@huawei.com>
On Wed, Oct 18, 2023 at 06:29:52PM +0800, Liu Shixin wrote:
> diff --git a/mm/kmemleak.c b/mm/kmemleak.c
> index 7c9125c18956..a956b2734324 100644
> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -816,16 +816,25 @@ static void delete_object_full(unsigned long ptr)
> */
> static void delete_object_part(unsigned long ptr, size_t size, bool is_phys)
> {
> - struct kmemleak_object *object;
> - unsigned long start, end;
> + struct kmemleak_object *object, *object_l, *object_r;
> + unsigned long start, end, flags;
> +
> + object_l = __alloc_object(GFP_KERNEL);
> + if (!object_l)
> + return;
>
> - object = find_and_remove_object(ptr, 1, is_phys);
> + object_r = __alloc_object(GFP_KERNEL);
> + if (!object_r)
> + goto out;
> +
> + raw_spin_lock_irqsave(&kmemleak_lock, flags);
> + object = __find_and_remove_object(ptr, 1, is_phys);
> if (!object) {
> #ifdef DEBUG
> kmemleak_warn("Partially freeing unknown object at 0x%08lx (size %zu)\n",
> ptr, size);
> #endif
> - return;
> + goto unlock;
> }
>
> /*
> @@ -835,14 +844,25 @@ static void delete_object_part(unsigned long ptr, size_t size, bool is_phys)
> */
> start = object->pointer;
> end = object->pointer + object->size;
> - if (ptr > start)
> - __create_object(start, ptr - start, object->min_count,
> - GFP_KERNEL, is_phys);
> - if (ptr + size < end)
> - __create_object(ptr + size, end - ptr - size, object->min_count,
> - GFP_KERNEL, is_phys);
> + if ((ptr > start) &&
> + !__link_object(object_l, start, ptr - start,
> + object->min_count, is_phys))
> + object_l = NULL;
> + if ((ptr + size < end) &&
> + !__link_object(object_r, ptr + size, end - ptr - size,
> + object->min_count, is_phys))
> + object_r = NULL;
> +
> +unlock:
> + raw_spin_unlock_irqrestore(&kmemleak_lock, flags);
> + if (object)
> + __delete_object(object);
>
> - __delete_object(object);
> +out:
> + if (object_l)
> + mem_pool_free(object_l);
> + if (object_r)
> + mem_pool_free(object_r);
> }
Ah, I see now why __link_object() needs to do further object
initialisation under the lock as prior to find_and_remove_object() we
don't have all the information needed for object_l and object_r.
Maybe in the __create_object splitting patch you can leave
__alloc_object() just do the actual allocation and __link_object() do
the full initialisation. Up to you, you can send a separate patch on top
as I can see Andrew picked them up already.
Otherwise the series looks fine.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
prev parent reply other threads:[~2023-10-18 16:39 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-18 10:29 [PATCH v3 0/7] Some bugfix about kmemleak Liu Shixin
2023-10-18 10:29 ` [PATCH v3 1/7] bootmem: use kmemleak_free_part_phys in put_page_bootmem Liu Shixin
2023-10-18 10:29 ` [PATCH v3 2/7] bootmem: use kmemleak_free_part_phys in free_bootmem_page Liu Shixin
2023-10-18 10:29 ` [PATCH v3 3/7] mm/kmemleak: fix print format of pointer in pr_debug() Liu Shixin
2023-10-18 10:29 ` [PATCH v3 4/7] mm: kmemleak: split __create_object into two functions Liu Shixin
2023-10-18 15:42 ` Catalin Marinas
2023-10-18 10:29 ` [PATCH v3 5/7] mm: kmemleak: use mem_pool_free() to free object Liu Shixin
2023-10-18 15:48 ` Catalin Marinas
2023-10-18 15:57 ` Catalin Marinas
2023-10-18 16:22 ` Andrew Morton
2023-10-18 16:34 ` Catalin Marinas
2023-10-18 10:29 ` [PATCH v3 6/7] mm: kmemleak: add __find_and_remove_object() Liu Shixin
2023-10-18 15:51 ` Catalin Marinas
2023-10-18 10:29 ` [PATCH v3 7/7] mm/kmemleak: fix partially freeing unknown object warning Liu Shixin
2023-10-18 16:39 ` Catalin Marinas [this message]
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=ZTAKJstsXrcUtOjn@arm.com \
--to=catalin.marinas@arm.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liushixin2@huawei.com \
--cc=patrick.wang.shcn@gmail.com \
--cc=wangkefeng.wang@huawei.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