linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Muchun Song <muchun.song@linux.dev>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Muchun Song <songmuchun@bytedance.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Oscar Salvador <osalvador@suse.de>,
	Charan Teja Kalla <quic_charante@quicinc.com>,
	Kairui Song <kasong@tencent.com>, Qi Zheng <qi.zheng@linux.dev>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Barry Song <baohua@kernel.org>,
	Axel Rasmussen <axelrasmussen@google.com>,
	Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
	Lorenzo Stoakes <ljs@kernel.org>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-cxl@vger.kernel.org
Subject: Re: [PATCH] mm/sparse: Fix race on mem_section->usage in pfn walkers
Date: Tue, 21 Apr 2026 20:55:16 +0800	[thread overview]
Message-ID: <FBD66BD2-79E6-4CBB-BBCA-8E8CB7DEB6CF@linux.dev> (raw)
In-Reply-To: <76cec69e-6ee1-4630-847b-80dc1e49d643@kernel.org>



> On Apr 21, 2026, at 19:21, David Hildenbrand (Arm) <david@kernel.org> wrote:
> 
> On 4/15/26 11:20, Muchun Song wrote:
>> 
>> 
>>> On Apr 15, 2026, at 16:04, David Hildenbrand (Arm) <david@kernel.org> wrote:
>>> 
>>> On 4/15/26 04:23, Muchun Song wrote:
>>>> When memory is hot-removed, section_deactivate() can tear down
>>>> mem_section->usage while concurrent pfn walkers still inspect the
>>>> subsection map via pfn_section_valid() or pfn_section_first_valid().
>>> 
>>> I'll note that it's all racy either way: someone checking pfn_valid() /
>>> pfn_to_online_page() can race with concurrent unplug.
>> 
>> Agree. When I first saw the commit message for 5ec8e8ea8b77, I was curious
>> because the goal of this commit was to fix an access issue with ms->usage.
>> Looking at the race diagram, I realized that while this only addresses the
>> ->usage access, subsequent accesses to struct page will still be problematic.
>> It's just that the former issue happened to be triggered first in this specific
>> commit.
>> 
>>> 
>>> We've known that for years; it's hard to fix; it never ever triggers :)
>> 
>> Glad to know my analysis wasn't off! It seems I've just stumbled upon a
>> 'well-known secret' within the community. :)
> 
> Heh, yes.
> 
>> 
>>> 
>>> So is this really worth it, when we should in fact, work on protecting
>>> the users of pfn_valid() / pfn_to_online_page() with rcu or similar?
>> 
>> I am not sure if it is worth fixing, especially since I just realized the
>> community has been aware of this issue for many years. If we do decide to
>> fix it, I think the most straightforward approach would be to protect it
>> using RCU, something like:
>> 
>> 	# the user side of pfn_to_online_page():
>> 	rcu_read_lock(); 
>> 	page = pfn_to_online_page();
>> 	if (!get_page_unless_zero(page))
>>    		goto out_unlock;
>> 	rcu_read_unlock();
> 
> 
> Right, but we'd have to protect against the sections being marked as
> offline as well here, though. So against a pure concurrent offline_pages().

Right.

> 
> If you're looking for a project, this is really one worth doing! :)
> 

Initially, I wasn't sure if this issue was worth fixing, but it seems
we are moving in the right direction. I'll give it some more thought
in my spare time.

> 
> pfn_to_online_page() is more in need for protection than pfn_valid() I
> think.

Agree.

Muchun,
Thanks.

> 
> -- 
> Cheers,
> 
> David




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

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15  2:23 Muchun Song
2026-04-15  5:44 ` Andrew Morton
2026-04-15  6:06   ` Muchun Song
2026-04-15  8:04 ` David Hildenbrand (Arm)
2026-04-15  9:20   ` Muchun Song
2026-04-21 11:21     ` David Hildenbrand (Arm)
2026-04-21 12:55       ` Muchun Song [this message]
2026-04-21 13:40         ` David Hildenbrand (Arm)
2026-04-15  8:37 ` Oscar Salvador
2026-04-15  9:45   ` Muchun Song

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=FBD66BD2-79E6-4CBB-BBCA-8E8CB7DEB6CF@linux.dev \
    --to=muchun.song@linux.dev \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=david@kernel.org \
    --cc=kasong@tencent.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=osalvador@suse.de \
    --cc=qi.zheng@linux.dev \
    --cc=quic_charante@quicinc.com \
    --cc=rppt@kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=songmuchun@bytedance.com \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=weixugc@google.com \
    --cc=yuanchu@google.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