From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.77 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796353775; b=w0VsVgHxtTxooCfsmveDlZfC3ooeOWCovb1GOxD4isL5vuRxa6MWXHBNHsGFw91HMtYe 27MzNe8GoK8fkth2RnjbLyaR5CpS7hLP/cxUSJTDVu45rMEFMNIMX3af11tQ9039NueiS kIPd6bNULIDxmFrrRQjktHuzG3pl3yjH0PQnBCS7fl7wewhmetMgWzdT8ejmy8cfHvcNm 0xe5a7qCcxymSoajJA5UtUvlbpaC5QBZMDo/SjpgQTbtPByNYcuogOMDUxik3W08CifKC EZxyJNjk7tQhK7QHHjDAUHuZxTy0M/l2EM6FQ8X8nZRsJ/sYZmCw/xFGHpyqxjqrJCw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796353775; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-Id: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=chXcGVg7OIbCkbwkzBWiSfXxYiHYwL3si7u42P6SITM=; b=w15Mx0dMVXnDkBN177otRbvGqq+lRKjM9mQDUDqBta4nb2buYJmGjaw+M4bqhShGu5qj WCFyeXBwEJLVT9raWziUNqmniXHbFbBaUXhbg9gQpnZ53xBlH9ZQi5s3iX0wMpSdKO34W m1GpPzuY3u6rrmYGqtwWmDEJFWY3sSV4Rmr3Jb7Xsl9AiTN1IAj/Q6+RKe4Rp0Q5Nktij 9CuL49Ys6zfqb50NCPDbGv3n0wYiPsHS/kH+h672/E8ji9E1dLYpDF4hXTpR9kGlsz5m3 VIQ6f6OZt8NWnn0BcSgEgE843hN2Yt/ErlPYM5KJLIi0/aUHpEOrM9q/bcW0dDAmLLQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Y2eRSNYA; arc=none smtp.remote-ip=95.215.58.77 Received: from mta1.migadu.com (out-77.mta1.migadu.com [95.215.58.77]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D49E0606A322 for ; Fri, 4 Dec 2026 03:09:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D49E0606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Y2eRSNYA X-Envelope-To: linux-rt-devel@lists.linux.dev DKIM-Signature: a=rsa-sha256; bh=WFIaRxyY4MPyj6z/HclbT6a4lBAvwrMO9Hm2EtG8TgI=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796353772; v=1; x=1796958572; b=Y2eRSNYAiXHU/tNesSR4aQGnYvwoqbF42ZIauRPQzXhWuAbKvY+51gCxsIpVZQuzXWL71Q+w x5oo0JibojyqgQl843dt447YOccH551tKtv6rnRUqj+SNr5AGl99K3xFenpbZaXo35R+hwOKOgT bI3vH6Nz0OFYwDqYbjDZJxvY= X-Envelope-To: linux-rt-devel@lists.linux.dev Received: by mta11.migadu.com with ESMTPS id 6b20903da0a6cc25; Fri, 04 Dec 2026 03:09:31 +0000 X-Mizu-Trace-ID: 6b20903da0a6cc25 X-Migadu-Flow: FLOW_OUT From: xu.xin@linux.dev To: david@kernel.org Cc: Felix.Kuehling@amd.com, James.Bottomley@HansenPartnership.com, airlied@redhat.com, akpm@linux-foundation.org, alex.sierra@amd.com, alex@shazbot.org, apopple@nvidia.com, ast@kernel.org, axelrasmussen@google.com, balbirs@nvidia.com, baohua@kernel.org, baolin.wang@linux.alibaba.com, baoquan.he@linux.dev, bigeasy@linutronix.de, byungchul@sk.com, chengming.zhou@linux.dev, cl@gentwo.org, clrkwllms@kernel.org, dave.jiang@intel.com, dave@stgolabs.net, dev.jain@arm.com, djbw@kernel.org, gorcunov@gmail.com, gourry@gourry.net, hagen@jauu.net, hao.li@linux.dev, harry@kernel.org, hughd@google.com, jack@suse.cz, jannh@google.com, jgg@ziepe.ca, jhubbard@nvidia.com, joshua.hahnjy@gmail.com, kas@kernel.org, kasong@tencent.com, kraxel@redhat.com, lance.yang@linux.dev, liam@infradead.org, linmiaohe@huawei.com, linux-cxl@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-rt-devel@lists.linux.dev, ljs@kernel.org, manfred@colorfullife.com, mason@kernel.org, matthew.brost@intel.com, mgorman@suse.de, mhocko@suse.com, muchun.song@linux.dev, nico.pache@linux.dev, osalvador@suse.de, peterx@redhat.com, qi.zheng@linux.dev, rakie.kim@sk.com, riel@surriel.com, rientjes@google.com, roman.gushchin@linux.dev, rostedt@goodmis.org, rppt@kernel.org, ryan.roberts@arm.com, shakeel.butt@linux.dev, shivankg@amd.com, shy828301@gmail.com, sj@kernel.org, song@kernel.org, stable@vger.kernel.org, stevensd@chromium.org, surenb@google.com, usama.arif@linux.dev, vbabka@kernel.org, vivek.kasireddy@intel.com, wangkefeng.wang@huawei.com, weixugc@google.com, willy@infradead.org, xu.xin@linux.dev, ying.huang@linux.alibaba.com, yuanchu@google.com, ziy@nvidia.com, zokeefe@google.com Subject: Re: [PATCH 26/32] mm/ksm: look up the folio again in cmp_and_merge_page() Date: Fri, 4 Dec 2026 11:08:54 +0800 Message-Id: <20261204030854.515947-1-xu.xin@linux.dev> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261129-fixes_core_3-v1-26-f66094116801@kernel.org> References: <20261129-fixes_core_3-v1-26-f66094116801@kernel.org> X-Mailing-List: linux-rt-devel@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit > 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) > --- > 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 > Simple enough, and make sense. Reviewed-by: Xu Xin (vivo)