Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Stefan Wiehler" <stefan.wiehler@nokia.com>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Andrew Morton" <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Subject: Re: [PATCH] mm: kmemleak: Keep full physical address for OBJECT_PHYS objects
Date: Fri, 04 Dec 2026 11:56:41 +0000	[thread overview]
Message-ID: <sashiko-outbox-249738@kernel.org> (raw)
In-Reply-To: <20261203115429.2383861-1-stefan.wiehler@nokia.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] mm: kmemleak: dump_str_object_info() truncates >4GB physical
  addresses
- [Low] mm: kmemleak: missing Fixes trailer for commit 0c24e061196c
- [Low] mm: kmemleak u64 pointer adds struct padding and 32-bit lookup
  overhead
--

commit 42bc9a7add9577059db2423f9b06da1b825a2889
Author: Stefan Wiehler <stefan.wiehler@nokia.com>

> mm: kmemleak: Keep full physical address for OBJECT_PHYS objects
>
> On 32-bit kernels with CONFIG_ARM_LPAE, kmemleak_alloc_phys() and the
> other *_phys() helpers pass a phys_addr_t, but kmemleak stored the
> address in an unsigned long. Memory above 4GB therefore lost its upper
> bits. At scan time the lowmem check then compared the truncated page
> frame against min_low_pfn/max_low_pfn, painted the object black, and
> skipped scanning it.
>
> On our KeyStone II setup, the unflattened device tree lives in a
> memblock above 4GB. Every pointer that only exists in that tree, such as
> kobject names, property names and fwnode links created during
> of_core_init(), was therefore reported as an unreferenced object.
>
> Store the object pointer as u64 and carry it through the object tree,
> lookup, create, delete, paint and scan paths. Virtual addresses are
> still untagged and cast to unsigned long where they are dereferenced
> or printed.
>
> Signed-off-by: Stefan Wiehler <stefan.wiehler@nokia.com>

[Severity: Low]
This fixes a bug introduced when physical addresses began being stored
directly in struct kmemleak_object.pointer.  Should this include:

  Fixes: 0c24e061196c ("mm: kmemleak: add rbtree and store physical address for objects allocated with PA")

> diff --git a/mm/kmemleak.c b/mm/kmemleak.c
> index d84c1e2c30478..428e2679dbcef 100644
> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -144,7 +144,8 @@ struct kmemleak_object {
>  	/* object usage count; object freed when use_count == 0 */
>  	atomic_t use_count;
>  	unsigned int del_state;		/* deletion state */
> -	unsigned long pointer;
> +	/* virtual or physical address of the block */
> +	u64 pointer;
>  	size_t size;
>  	/* pass surplus references to this pointer */
>  	unsigned long excess_ref;

[Severity: Low]
Could this use phys_addr_t instead of u64, and place size before pointer?

On 32-bit SMP architectures with 8-byte u64 alignment (such as ARM EABI),
putting u64 pointer before size adds 8 bytes of padding, growing struct
kmemleak_object from 116 to 128 bytes (+192 KB for the default mem_pool)
and pushing size into a second cacheline away from rb_node and pointer.

Using phys_addr_t avoids both the growth and 64-bit arithmetic in
__lookup_object() and __link_object() on 32-bit !CONFIG_PHYS_ADDR_T_64BIT
builds, while moving size before pointer eliminates the padding and
cacheline split on 32-bit CONFIG_PHYS_ADDR_T_64BIT builds too.

[ ... ]

> @@ -593,7 +608,7 @@ static void put_object(struct kmemleak_object *object)
>  /*
>   * Look up an object in the object search tree and increase its use_count.
>   */
> -static struct kmemleak_object *__find_and_get_object(unsigned long ptr, int alias,
> +static struct kmemleak_object *__find_and_get_object(u64 ptr, int alias,
>  						     unsigned int objflags)
>  {
>  	unsigned long flags;

[Severity: Medium]
Should dump_str_object_info() and __dump_str_object_info() also be updated
for 64-bit physical addresses?

dump_str_object_info() still parses the debugfs dump= input into an
unsigned long with kstrtoul() (and prints unknown addresses with 0x%08lx),
so on 32-bit LPAE kernels looking up an OBJECT_PHYS object above 4GB
returns -EINVAL.

When widening dump_str_object_info() to kstrtou64() and
__dump_str_object_info() to u64, the virtual and OBJECT_PERCPU lookups
should be skipped when addr > ULONG_MAX; otherwise object_tree_addr()
truncates the upper bits and can match an unrelated 32-bit object.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203115429.2383861-1-stefan.wiehler@nokia.com?part=1


      reply	other threads:[~2026-12-04 11:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 11:54 [PATCH] mm: kmemleak: Keep full physical address for OBJECT_PHYS objects Stefan Wiehler
2026-12-04 11:56 ` sashiko-bot [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=sashiko-outbox-249738@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=catalin.marinas@arm.com \
    --cc=linux-mm@kvack.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=stefan.wiehler@nokia.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