From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Yuan Liu <yuan1.liu@intel.com>,
Oscar Salvador <osalvador@suse.de>,
Mike Rapoport <rppt@kernel.org>,
Wei Yang <richard.weiyang@gmail.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Chen Yu <yu.c.chen@intel.com>, Jason Zeng <jason.zeng@intel.com>,
Vlastimil Babka <vbabka@kernel.org>
Subject: Re: [BUG] mm/memory_hotplug: panic due to race between compaction and memory hot-unplug
Date: Mon, 7 Sep 2026 16:27:50 +0200 [thread overview]
Message-ID: <1d625a60-9473-4f48-a384-7d756ccb7135@kernel.org> (raw)
In-Reply-To: <20260903095543.3752338-1-yuan1.liu@intel.com>
On 9/3/26 11:55, Yuan Liu wrote:
> Hi all,
Hi!
>
> While stress testing memory hotplug on a VM guest running an
> unmodified vanilla mainline kernel (7.3.0-rc1, as reported by
> uname -r), we hit a kernel panic in the guest when memory
> hot-unplug runs concurrently with memory compaction.
>
> The kernel was built from mainline at commit:
>
> cee9395acd80 ("Linux 7.3-rc1")
>
> To be more specific, after a large virtio-mem hot-unplug, the guest
> kernel takes a fatal page fault in suitable_migration_target(), called
> from isolate_freepages() during compaction.
Sounds like a real problem we should tackle.
>
> We are not sure whether this race is reachable under realistic
> workloads or only under this synthetic stress test. Sharing it here
> in case it is useful, and in case this is already a known issue.
> Thanks.
>
>
> Call trace (top to bottom)
> ==========================
> - RIP: suitable_migration_target+0x5/0x70
> isolate_freepages() <- compaction_alloc() <-
> migrate_pages() <- compact_zone() <- compact_node() <-
> sysctl_compaction_handler().
>
>
> Why the race happens
> ====================
> CPU0 (compaction free-scanner) CPU1 (virtio-mem hot-unplug)
> ---- ----
> page = pageblock_pfn_to_page()
> /* checks pass, section ONLINE */
> /* returns valid struct page* */
>
> offline_pages()
> /* section -> offline */
> __remove_pages()
> vmemmap_free()
> /* struct page UNMAPPED */
>
> suitable_migration_target(page)
> PageBuddy(page)
> read page->page_type
> *** not-present fault -> panic ***
>
If it can be hit with virtio-mem, it can be hit with any other memory hotunplug
code path (e.g., dimm, dax).
It is known that pfn_to_online_page() is racy. We usually expect the race window
to be extremely small. But for compaction the race window is much larger.
We do have get_online_mems()/put_online_mems(), big its the big hammer.
We once discussed using RCU to protect pfn_to_online_page(), but I suspect for
comapction that's not actually helpful (again, large race window).
We'd have to use the memory notifier or a dedicated callback to let memory
offlining sync with compaction.
That's where it gets tricky :)
It would be sufficient to let MEM_OFFLINE wait until any previous compaction
users would be done with the range. In that case, the sections would be offline,
but the memmap and zone range would not have been adjusted yet.
--
Cheers,
David
next prev parent reply other threads:[~2026-09-07 14:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 9:55 [BUG] mm/memory_hotplug: panic due to race between compaction and memory hot-unplug Yuan Liu
2026-09-07 14:27 ` David Hildenbrand (Arm) [this message]
2026-09-10 3:16 ` Wei Yang
2026-09-10 7:40 ` David Hildenbrand (Arm)
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=1d625a60-9473-4f48-a384-7d756ccb7135@kernel.org \
--to=david@kernel.org \
--cc=jason.zeng@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=osalvador@suse.de \
--cc=richard.weiyang@gmail.com \
--cc=rppt@kernel.org \
--cc=vbabka@kernel.org \
--cc=yu.c.chen@intel.com \
--cc=yuan1.liu@intel.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.