From: Andrew Morton <akpm@linux-foundation.org>
To: Hui Su <sh_def@163.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>,
Alexander Potapenko <glider@google.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Dmitry Vyukov <dvyukov@google.com>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Zqiang <qiang1.zhang@intel.com>,
kasan-dev@googlegroups.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v2] kasan: fix cache shrink race with CPU hotplug
Date: Sat, 8 Aug 2026 00:39:21 -0700 [thread overview]
Message-ID: <20260808003921.fdb0df9ee4417b38f15e8c68@linux-foundation.org> (raw)
In-Reply-To: <20260808031459.3032812-1-sh_def@163.com>
On Sat, 8 Aug 2026 11:14:59 +0800 Hui Su <sh_def@163.com> wrote:
> kasan_quarantine_remove_cache() first invokes per_cpu_remove_cache() on
> all online CPUs. Each callback moves objects belonging to the cache from
> cpu_quarantine to the CPU's shrink_qlist, where they can later be freed
> from task context.
>
> kmem_cache_destroy() invokes the quarantine removal path while holding
> cpus_read_lock(), but kmem_cache_shrink() does not. The latter can
> therefore race with CPU offlining as follows:
>
> kmem_cache_shrink() CPU hotplug
> ------------------- -----------
> on_each_cpu()
> CPU1 moves objects to
> CPU1's shrink_qlist
> on_each_cpu() returns
> CPU1 goes offline
> kasan_cpu_offline()
> drains cpu_quarantine
> leaves shrink_qlist untouched
> for_each_online_cpu()
> skips CPU1
>
> The objects left on CPU1's shrink_qlist are not returned to the slab
> allocator. This may prevent kmem_cache_shrink() from releasing slabs
> that would otherwise become empty. If CPU1 remains offline, a later
> kmem_cache_destroy() also skips the list and can report that the cache
> still contains objects.
>
> An intermittent occurrence was observed with a virtio-9p filesystem.
> The mount and umount commands both returned 0, but the kernel logged
> the following during the userspace-triggered teardown:
>
> ...
>
Thanks, I'll queue this for testing while we await maintainer review.
AI review suggests that there's a pre-existing quarantine_size
accounting flaw later in this function:
https://sashiko.dev/#/patchset/20260808031459.3032812-1-sh_def@163.com
If true, I'm surprised this hasn't yet been reported.
Also, I'd like to see a need_resched() wrapping that expensive
/* Scanning whole quarantine can take a while. */
raw_spin_unlock_irqrestore(&quarantine_lock, flags);
cond_resched();
raw_spin_lock_irqsave(&quarantine_lock, flags);
next prev parent reply other threads:[~2026-08-08 7:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-08 3:14 [PATCH v2] kasan: fix cache shrink race with CPU hotplug Hui Su
2026-08-08 7:39 ` Andrew Morton [this message]
2026-08-08 9:38 ` Hui Su
2026-08-08 16:53 ` Andrew Morton
2026-08-11 17:32 ` Andrey Ryabinin
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=20260808003921.fdb0df9ee4417b38f15e8c68@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=qiang1.zhang@intel.com \
--cc=ryabinin.a.a@gmail.com \
--cc=sh_def@163.com \
--cc=stable@vger.kernel.org \
--cc=vincenzo.frascino@arm.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 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.