[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <4D77AD25-6DC2-406D-9D54-9032F38260B4@linux.dev>
Date: Thu, 9 Jan 2025 10:40:26 +0800
From: Muchun Song <muchun.song@...ux.dev>
To: Yu Zhao <yuzhao@...gle.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
David Hildenbrand <david@...hat.com>,
Mateusz Guzik <mjguzik@...il.com>,
"Matthew Wilcox (Oracle)" <willy@...radead.org>,
linux-mm@...ck.org,
linux-kernel@...r.kernel.org,
Will Deacon <will@...nel.org>
Subject: Re: [PATCH mm-unstable v2] mm/hugetlb_vmemmap: fix memory loads
ordering
> On Jan 8, 2025, at 15:48, Yu Zhao <yuzhao@...gle.com> wrote:
>
> Using x86_64 as an example, for a 32KB struct page[] area describing a
> 2MB hugeTLB, HVO reduces the area to 4KB by the following steps:
> 1. Split the (r/w vmemmap) PMD mapping the area into 512 (r/w) PTEs;
> 2. For the 8 PTEs mapping the area, remap PTE 1-7 to the page mapped
> by PTE 0, and at the same time change the permission from r/w to
> r/o;
> 3. Free the pages PTE 1-7 used to map, hence the reduction from 32KB
> to 4KB.
>
> However, the following race can happen due to improperly memory loads
> ordering:
> CPU 1 (HVO) CPU 2 (speculative PFN walker)
>
> page_ref_freeze()
> synchronize_rcu()
> rcu_read_lock()
> page_is_fake_head() is false
> vmemmap_remap_pte()
> XXX: struct page[] becomes r/o
>
> page_ref_unfreeze()
> page_ref_count() is not zero
>
> atomic_add_unless(&page->_refcount)
> XXX: try to modify r/o struct page[]
>
> Specifically, page_is_fake_head() must be ordered after
> page_ref_count() on CPU 2 so that it can only return true for this
> case, to avoid the later attempt to modify r/o struct page[].
>
> This patch adds the missing memory barrier and makes the tests on
> page_is_fake_head() and page_ref_count() done in the proper order.
>
> Fixes: bd225530a4c7 ("mm/hugetlb_vmemmap: fix race with speculative PFN walkers")
> Reported-by: Will Deacon <will@...nel.org>
> Closes: https://lore.kernel.org/20241128142028.GA3506@willie-the-truck/
> Signed-off-by: Yu Zhao <yuzhao@...gle.com>
Reviewed-by: Muchun Song <muchun.song@...ux.dev>
Thanks.
Powered by blists - more mailing lists