From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795983744; b=P1tiWxjk63heY/j22777VsXKUehGzLCmQhaUashQRj4lbg1wzHVkjxtm0zZP0Y7bjH03 cT+nIqcBMeO5bDslmkhe81qD8GZzWb67EqOTznWHSEOi21bT7PS2khnf636j7n9pmcbUQ P3eDk/TTfVV9+5a3kxKaqqJYxCtniJ9rWf/Hmz18MX9PvDHDVA8jttE+a/dj0L8DhQ5nS iI9Cca2FYkNJsdmuPYAWoHtHCliDV5c/x3DCJcjJ8FLb6hE2H0zwx19uzz6Gh8n0lBqMC +cktm0oR2lVhXT8vYCav6x5TLYz0g9uJ/a4cAVkAT6gNIzq7/fdnDkGbLnkUIswVk9w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795983744; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=Hsdfxd/0c1+6MLhJ4rlSqjJbMFtePqVxCWpgSrABWWM=; b=u9+XRgbXHkzUvwLMnFwgOpyNEMMSBbcOIFJM3uKWVDtGrcTV894GrL2tDG4epmxnkQ6B 2+iUid83uXdl3SAG4pzOzEqKa9gwZd/NTQviKLvHclsTn+gknEC7gSE3xrW5TOE3almqw WftYJyWlcePcSjHRbHsac23ViGZVnYgVKMY72OWLnenW5OFEwCVQczffM6mp7yjGx+XZP e45KyBZddCp6utpgghdaSNmpUOKt208R/CJfw5kkGu1wKW/Z2oAxl3D4KVRMQrVnR+3Fk pw96jhbdEYYVdVQ6E6xcLXq/fnoQ+MKitd5bVGHIdbcIe2qbRcQNfknxG6Qy68Id7aQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=OBKXVuh9; arc=none smtp.remote-ip=209.85.221.49 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 ABD40606A32E for ; Sun, 29 Nov 2026 20:22:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ABD40606A32E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=OBKXVuh9 Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-492f0a1b685so7042667f8f.0 for ; Sun, 29 Nov 2026 12:22:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795983742; x=1796588542; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Hsdfxd/0c1+6MLhJ4rlSqjJbMFtePqVxCWpgSrABWWM=; b=OBKXVuh98gdy1RITb4Lmuvtgtbd9HfF2HZGmNI1fz2Bxpar8cOGwJuIgWhAj/ncjda honudeyuIFfK/6XsFOhWWptf4lpOR3Bgw2F1a1TDBMMRnPGNcJCsC0dmXgHH98eHwCNR qMPvDd9x4pElKdypPEzbuXwhlipNB1eGzpKHB3TMO1tTWjhZvmZ8DgDpxnwC/G3yWb+x hHQuA3GmG9rTOS1EpPXvI93NxH7P2QgUybHq4eodHLn7fY++lmufdzOxIb5bpBJGh3Ch A5/HAsgzwGRnU5FXstl8fW6eU3XTDBJTgrtHom1EWpGuIx1GioJMlRET1RQLp7D1Nr/Y yoLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795983742; x=1796588542; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Hsdfxd/0c1+6MLhJ4rlSqjJbMFtePqVxCWpgSrABWWM=; b=Go78wpGN1lBrn8Va31Uvtb3lxN5xcqDCrhRegm2uJxfNZ+4dweQn5wtiSamH9uug/t 2W0Kgae7doPCmrMRDOQjTnxD8NuuIn+6b2YFQM0WSdowjGpEdbJRm7T77UsDN08KsPqe Hm6y+jZjikJyONby/KOyRaS/HKsTxj21fBuQddvQhY/hRxd+KXmMcBkK1Hx2c/ThCVX/ u3+sa05t2+H+IUDwbxMWqWkJgp9MjxKIJjjjQwszLdeuYswVU2WtspDbtCe8KIrWWgwe QGhZvAuA9/DvYzh0zMUFU9vsReanPDzgw7qCb6FvSfsoVUIuxBtH76/laHHkC73oNk8N aynw== X-Forwarded-Encrypted: i=1; AL+hErGT6URYE43giwrt9fYFQ0dIixR9s5D8I11F1hkRA2ccMVDqk8xAZ0fsw1LOG2fVSEHl2sqUo0ZiZG0=@vger.kernel.org X-Gm-Message-State: APuU4Z/L0qMmD5oS/kqWw/9MCpZIwVroopIu6tC/Hm5qX/HKFBLruWBg pEe5u90tj5vN/qO4OhtwWu/WGPAUlrvegoLV9GluTxC5PswaRnn2hplK X-Gm-Gg: AZFdTZeqEwWZ8QNUI1XTIZmtYU5n63oXSBi+qjTFR2e6bZ2VHQzlknNcUyGdzzghCrh eGJPJq2e/VVXjx51Sr/3EpJQ6B7YGHGW/wcGcpsWX85TQeEFUHYyrjiIWV8qtPMsZHQkv4FlZXQ 71SlDEjwPIIdRto5Tkhj/Un7z/HdWgyhY7zjNF/7lGRuvBJhQQnjoWWNKw3PmcXn7hNzCiljyB3 V0ZQTjgQw7JzyAlwr5THGisxdQEaUW27b9HFNnezWGnQxa5MmRFsg/VE6XxFFrRSjIF9gce5JCb +hA6F6m8gyNvNZ7ml9UtBRtf7nw1tuBI2AuVbhf/+M4U+iRKbUQrNPez/a6/PeqQG0TEkmrGgNQ 42UIfocA6zPEk1rZOP1lQUr0lVriR3xc5B1WJQJnonohMPN3h/Fi1rOO+g8akg5UaR+7M2D0wk2 0cROLgXVbyWZPT696ogfkjGPIrtgPc0pi2nyNEykvz7mJG5D+lUBoEhGgvAYaDz36DvJ9iscPKM TSDjH/wlnKjbzmTy9tKzV15omgUtYFtSjDdGPvaQoom6ANq8ukOwKgv6rW1eh/qkGBJEsC1iycV ywKYFNDzOJ+1rPDfX9Tgryr5 X-Received: by 2002:a05:6000:2c13:b0:4a5:b0ea:3f5c with SMTP id ffacd0b85a97d-4abaac57beamr61789745f8f.2.1795983741738; Sun, 29 Nov 2026 12:22:21 -0800 (PST) Received: from [192.168.1.22] ([83.231.69.9]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6ae2dd55sm58790707f8f.30.2026.11.29.12.22.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 Nov 2026 12:22:21 -0800 (PST) Message-ID: Date: Sun, 29 Nov 2026 21:22:17 +0100 X-Mailing-List: linux-cxl@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 , 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 , 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> Content-Language: en-US From: "Jose A. Perez de Azpillaga" In-Reply-To: <20261129-fixes_core_3-v1-11-f66094116801@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 11/29/26 11:06 AM, 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: Jose A. Perez de Azpillaga -- cheers, jose a. p-a