From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385904; b=nNZscl3e26+ej6JADCcYPJCSUArOZXOQR0bK6GFD/6SSv9HuWUVrcAbIoX6lKECPJFWi 7f9awCVaBx8K6mkaNWWSR+z+r6J3KV5PqC5uIyrydR+L6dhA3xBi/Tj1ZipHlfVR0kJc3 YafkINeBnu+L2hwcORZ1NSgQm6MrerLdPFD4BvjQcj7uqui+biseAXWnyjqKSBlqpiH9V OTuPIkq44HmMf7B0zWqAlbRVnv5TYc+lxXezwRioGMKVlUKU5OrMWVVebt1rHaUxsEdjC 1ezzwzAHzblD0VxzYAxKhdjHctQkWGUGkryqACB27hD8a/4dUcbuNq7gXZ3IneUzlVg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385904; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=luTwmA+Z9Z1L8tL3NMTlo3YGKqvb8ySFVH/J7u/PAgU=; b=HMbHX6naJh0BxpuSYo4i95u2WaJ9e6UpcQzNHUF6rZABJmbagBpSCqgIRt49WEqb5KJ+ nd70M+BpVPpc7iiYJGbDXqUgrP3ChGDuDBPZ7ZiVbXHALUZjdK9Lei17qJb75wwbtBLMo ReDTryJswnMjC77iDVdSDmehNopdRnthyfhNfUcmg1IcChX+CuSXKHqG36898Rb9XrQMa ooJtHcgUm1Ee3G1SUeIIv0exffNke3dPraGCQWdZQig7pvMlwmeJWWbJJZv5qKH3XAQN9 JOfyRMKYrbnLnjCGoc+EMdr/hcLPbyjR9SpZzrq+0txJFAcxuHfbMyIIRU/pAYeZRtw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=m1HPnUca; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CB8A606A322; Fri, 4 Dec 2026 12:05:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=m1HPnUca Received: by smtp.kernel.org (Postfix) with ESMTPSA id B66371F0092C; Fri, 4 Dec 2026 12:04:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796385903; bh=luTwmA+Z9Z1L8tL3NMTlo3YGKqvb8ySFVH/J7u/PAgU=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=m1HPnUcaDpl/u7kgTSjZGAY9djMixdZiJdHDikg5sLYjygkCR5xi8bZW75w3nv3G6 jxpKHLPnrJJt4em+uRWzxW0fmW1kcMdSwRz8IN+V9hmuQsWA5p8nvop1z7kYtA2DdL pi0X3m5O1HJJ7tDiiA9EA/YvJZBJU8HN2HnuDDo46MZeGTPcZWw0uw0BnamyeoFQ2S 9psmlVqNbfgCSD1wOPtDr00xtl1us0vTaq08jgm1UVSvOvfuc4VrbJijjWvyCSevD7 SL/9A+zcBEq5sW+ffcIMc1Mh51G/Y/K3b/BCUYfmLfQoFq8AdYn9wf/NLFTr57ufBK qvCflCq5IL4DQ== Date: Fri, 4 Dec 2026 12:04:43 +0000 From: "Lorenzo Stoakes (ARM)" To: "David Hildenbrand (Arm)" Cc: Hugh Dickins , Baolin Wang , Andrew Morton , Mike Rapoport , Peter Xu , Michal Hocko , Kiryl Shutsemau , Manfred Spraul , Davidlohr Bueso , Cyrill Gorcunov , Zi Yan , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Rik van Riel , Vlastimil Babka , Harry Yoo , Jann Horn , Yang Shi , Zach O'Keefe , Song Liu , David Stevens , Kefeng Wang , Alex Williamson , Suren Baghdasaryan , Dave Jiang , Matthew Wilcox , Miaohe Lin , David Rientjes , Shakeel Butt , Jan Kara , Mel Gorman , Jason Gunthorpe , John Hubbard , Gerd Hoffmann , Vivek Kasireddy , Dave Airlie , Matthew Brost , Joshua Hahn , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Hagen Paul Pfeifer , James Bottomley , Felix Kuehling , Alex Sierra , Balbir Singh , Kairui Song , Qi Zheng , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Oscar Salvador , Muchun Song , Dan Williams , Rakie Kim , Hao Li , Christoph Lameter , Roman Gushchin , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Alexei Starovoitov , Xu Xin , Chengming Zhou , Shivank Garg , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-cxl@vger.kernel.org, linux-rt-devel@lists.linux.dev, SJ Park , Chris Mason , stable@vger.kernel.org Subject: Re: [PATCH 26/32] mm/ksm: look up the folio again in cmp_and_merge_page() Message-ID: References: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> <20261129-fixes_core_3-v1-26-f66094116801@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261129-fixes_core_3-v1-26-f66094116801@kernel.org> On Sun, Nov 29, 2026 at 11:06:57AM +0100, David Hildenbrand (Arm) wrote: > From: Chris Mason > > try_to_merge_two_pages() gets a page (not a folio) passed and can end > up splitting a large folio in try_to_merge_one_page(). > > However, cmp_and_merge_page() does not look up the page's folio again > after possibly splitting it, but compares the stale folio against > tree_folio since commit a35d8872dae7 ("mm: remove PageTransCompound()"). > > Consequently, we can end up locking a folio we hold no reference on and > never unlocking it, but unlocking another folio that someone else might > have locked instead. > > Let's fix it by looking up the folio after calling > try_to_merge_two_pages(). > > This has medium urgency, as ksmd can leave a folio locked. > > Fixes: a35d8872dae7 ("mm: remove PageTransCompound()") > Cc: stable@vger.kernel.org > Signed-off-by: Chris Mason > [ david: simplify comment and description ] > Signed-off-by: David Hildenbrand (Arm) LGTM Reviewed-by: Lorenzo Stoakes (ARM) > --- > mm/ksm.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/mm/ksm.c b/mm/ksm.c > index 444bb7bb62cfe..90cc83275764d 100644 > --- a/mm/ksm.c > +++ b/mm/ksm.c > @@ -2361,6 +2361,8 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite > > kfolio = try_to_merge_two_pages(rmap_item, page, > tree_rmap_item, tree_page); > + /* We might have split the folio. */ > + folio = page_folio(page); > tree_folio = page_folio(tree_page); > /* > * If both pages we tried to merge belong to the same (large) > > -- > 2.56.1 > -- Cheers, Lorenzo