From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.113 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796203211; b=rHzr8Csw67smXlzKNM5YRYFiBDhfmC9rhx/TconQpw5ET8qU8yIcW/EX8oKXxTOUN15o BnogYaDOrsLy20jwLHD8sotTDoouhFUj0ntgGzURBXdO5D5t4e/t/M3fjuFEn35unkAdR W6+RjuMOhKPeXeDHqlYoYBntedmu4Cjs8tr0/qMaV2pSElJTxuEbdr5RBId+NOXtqyzEH ZwmrxZPKFxoHa0RuPXII4JsyW18MBj4b4vwr58zeyKWWDPckiJDP5JNiIVd95EzyI4Qjb Lh39nyeqKePYqEFBwXmSJBEy9aHaKX61bNGvtVhWVePWzkeVeRpjhBPfTNBGbcTl9MQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796203211; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:Message-ID: Date:MIME-Version:User-Agent:Subject:To:Cc:References:From: In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=aUzHNmBMf/janTiyO9ShnEG1c8zq6kC7nWyNPSKuM3Y=; b=mbxmeXAPB4TWOTRtl/RBgVvWI2xbfR2TdJ/54ZBMS5or8kw8M7/aU4iMCtRWDet42Y8z Xoh0xynfJ+gJRrB3KTET0/ZoaUz7jBD7KrfY4vjyil71rSuFgKOXiestti1XIAOCrJo/V S+vavCDvW9TGzJmf0vegQO5sIXN4ctN1YGitK46zjhuBnV+Zb8OOgMf1Yt5yf8DwpDqCO bCCHSCu87cX1sivPZvnpx5y9XZpg0sDeVwir8dS1rqSr3di+b9GNjd3jd/DoZ2AY7RsUE OlFfqVWdXxw1EMqoQB3vBkX5GjODyE7REHhcPsswcYp2VMP/ALvJhQ252I/T69ML4Rw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=SdryhQMe; arc=none smtp.remote-ip=115.124.30.113 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D06F606A31A; Wed, 2 Dec 2026 09:20:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6D06F606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=SdryhQMe DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1796203207; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=aUzHNmBMf/janTiyO9ShnEG1c8zq6kC7nWyNPSKuM3Y=; b=SdryhQMeQt4UMsJP2xVhzJ/8FZbWPSMMUF7xlXt1MHG/ZHhfmsbst/AYmiiR3ES/NfbBA9yFn/EBjQ1vi+sWQUyGKzcSX+AQCqqnv6GFmJCr5a8z2v7XRyvw5CP9iL5WYA3buysc3t2Zegtc30HaL6RrM4G4tHJtdE2+x2aeA4E= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033040069076;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=80;SR=0;TI=SMTPD_---0XG8khsX_1796203199; Received: from 30.74.144.133(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XG8khsX_1796203199 cluster:ay36) by smtp.aliyun-inc.com; Wed, 02 Dec 2026 17:20:02 +0800 Message-ID: <3385aadc-76bc-4ec5-8062-f52d79b236e8@linux.alibaba.com> Date: Wed, 2 Dec 2026 17:19:58 +0800 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 11/32] mm/khugepaged: store new folio before adding it to LRU To: "David Hildenbrand (Arm)" , Hugh Dickins , 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 , Lorenzo Stoakes , 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 Cc: 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 References: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> <20261129-fixes_core_3-v1-11-f66094116801@kernel.org> From: Baolin Wang In-Reply-To: <20261129-fixes_core_3-v1-11-f66094116801@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/29/26 6:06 PM, David Hildenbrand (Arm) wrote: > From: Chris Mason > > collapse_file() adds the new folio to the LRU before adding it to the > page cache. If SHM_LOCKed, the folio will be added to the unevictable > LRU. A concurrent SHM_UNLOCK walks the page cache to make all folios > evictable again, and can miss the new folio: > > collapse_file() SHM_UNLOCK > =============== ========== > folio_add_lru(new_folio) > /* unevictable */ > shmem_unlock_mapping() > /* misses new_folio */ > xas_store(&xas, new_folio) > > Consequently, if SHM_UNLOCK races with a collapse in a SHM_LOCKed SysV > shared memory segment, the new folio can get stranded on the unevictable > LRU. > > Let's improve it by adding the new folio to the LRU only after adding it > to the page cache. > > There is a more fundamental race that must be sorted out to fix this > completely: check_move_unevictable_folios() skips folios that are not on > the LRU without taking the lruvec lock, while lru_add() checks evictability > before marking the folio as being on the LRU. That affects all folios that > are added to the LRU, and requires a more generic fix. > > This has low urgency, as it only strands a folio on the unevictable LRU. > No need to CC stable. > > Fixes: a2e17cc2efc7 ("mm/khugepaged: maintain page cache uptodate flag") > Signed-off-by: Chris Mason > [ david: simplify description and comment ] > Signed-off-by: David Hildenbrand (Arm) > --- LGTM. Reviewed-by: Baolin Wang