From: sashiko-bot@kernel.org
To: "Andrew Morton" <akpm@linux-foundation.org>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: linux-mm@kvack.org,
"Shardul Bankar" <shardul.b@mpiricsoftware.com>,
"David Hildenbrand (ARM)" <david@kernel.org>,
"Dev Jain" <dev.jain@arm.com>,
janak@mpiricsoftware.com, "Jinjiang Tu" <tujinjiang@huawei.com>
Subject: Re: [PATCH 1/2] lib: xarray: free unused spare node in xas_create_range()
Date: Mon, 16 Nov 2026 03:17:13 +0000 [thread overview]
Message-ID: <sashiko-outbox-216113@kernel.org> (raw)
In-Reply-To: <2dfabfd9476542e39c7d5473a6597208.1@linux-foundation.org>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] lib: xarray: inaccurate Fixes trailer in xas_create_range()
commit
--
commit 844089b2ad8c28a781a9ee223d1c1eac3cd107f2
Author: Shardul Bankar <shardul.b@mpiricsoftware.com>
> lib: xarray: free unused spare node in xas_create_range()
>
> xas_create_range() is typically called in a retry loop that uses
> xas_nomem() to handle -ENOMEM errors. xas_nomem() may allocate a spare
> xa_node and store it in xas->xa_alloc for use in the retry.
>
> If the lock is dropped after xas_nomem(), another thread can expand the
> xarray tree in the meantime. On the next retry, xas_create_range() can
> then succeed without consuming the spare node stored in xas->xa_alloc. If
> the function returns without freeing this spare node, it leaks.
>
> xas_create_range() calls xas_create() multiple times in a loop for
> different index ranges. A spare node that isn't needed for one range
> iteration might be needed for the next, so we cannot free it after each
> xas_create() call. We can only safely free it after xas_create_range()
> completes.
>
> Fix this by calling xas_destroy() at the end of xas_create_range() to free
> any unused spare node. This makes the API safer by default and prevents
> callers from needing to remember cleanup.
>
> This fixes a memory leak in mm/khugepaged.c and potentially other callers
> that use xas_nomem() with xas_create_range().
>
> Link: https://lore.kernel.org/20251204142625.1763372-1-shardul.b@mpiricsoftware.com
> Link: https://syzkaller.appspot.com/bug?id=a274d65fc733448ed518ad15481ed575669dd98c
> Link: https://lore.kernel.org/all/20251201074540.3576327-1-shardul.b@mpiricsoftware.com/ ("v3")
> Fixes: cae106dd67b9 ("mm/khugepaged: refactor collapse_file control flow")
> Signed-off-by: Shardul Bankar <shardul.b@mpiricsoftware.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Reviewed-by: David Hildenbrand (ARM) <david@kernel.org>
> Tested-by: Andrew Morton <akpm@linux-foundation.org>
> Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
> Cc: Dev Jain <dev.jain@arm.com>
> Cc: <janak@mpiricsoftware.com>
> Cc: Jinjiang Tu <tujinjiang@huawei.com>
[Severity: Low]
Is the Fixes tag pointing to the right commit?
cae106dd67b9 ("mm/khugepaged: refactor collapse_file control flow") only moved
__SetPageLocked(hpage) before the xas_create_range() loop and changed the
!xas_nomem() failure target from out to rollback, where xas.xa_alloc is
already NULL.
xas_create_range() was introduced without xas_destroy() in 2264f5132fe4
("xarray: Add xas_create_range"), and the retry loop in collapse_file() that
breaks out on !xas_error(&xas) without freeing xas.xa_alloc dates back to
77da9389b9d5 ("mm: Convert collapse_shmem to XArray").
--
Sashiko AI review · https://sashiko.dev/#/patchset/2dfabfd9476542e39c7d5473a6597208.0@linux-foundation.org?part=1
next prev parent reply other threads:[~2026-11-16 3:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 3:16 [PATCH 0/2] xarray: free unused spare node after range creation Andrew Morton
2026-11-15 3:16 ` [PATCH 1/2] lib: xarray: free unused spare node in xas_create_range() Andrew Morton
2026-11-16 3:17 ` sashiko-bot [this message]
2026-11-16 3:59 ` Andrew Morton
2026-11-15 3:16 ` [PATCH 2/2] lib/test_xarray: check unused spare node after range creation 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=sashiko-outbox-216113@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=janak@mpiricsoftware.com \
--cc=linux-mm@kvack.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shardul.b@mpiricsoftware.com \
--cc=tujinjiang@huawei.com \
--cc=willy@infradead.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.