From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795983744; b=VGpcb15TA5XwZ0iFfHVYWJDzcqMg7EhIsRrKeCBfkTeX23J9D1uIOErJ5GnkBZv9u72R kktIjadZqa3XqWHlTGkl8gJN2fdjByE7fW+pSk2rK34JsMKUTYZdzqz3pSmhkZAz4L/+a 8tX7+HvlVNZNyF7SScflpTN1ORD6d/dLNCXu5qUlyeBHeWF91505bJg5edGem6fWi9n4D cew6b6S1zUnmJstqRLt/LtDQokutPhlUXU32pbCV37MfdWiloyMovV+kuZuGtow82TfUW /+rB+Dkl5BziNsJF4fvkjVdD71fmHnkbuzZEMci589FJDNdWq2I1vJsNo7f7h+sj7bA== 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=XpZedFKOE72Tk1jWuBh6tKiRMtzKqemQBDmKVFj7VgavRvA18HKNy5/Pg7TdY/uLytDy tzifcVasVOqDoxWFibsR0EcEv3WopdGwXfYY2Vuz3IIVDdc4wxuJ0jNZEwsQVk/2FYf3I zfDghU1k/ClKC3RwA/oNFj7K23ujYylXs1L9TY5PcJhYB8bREGv5HgGLitxQXv+hTR2JZ 51uHMqmR/DV7zP+6q3V+sszb5USZbp8s+73RTocm2kXBcNpmYu7BaQGJFigIhSkuK2PlJ BZfouR6nrFXY/x6dryd5oZyOyOb7zuMYrTHKrCG154jw7LQETrRAUPGfg5OtmyXfTWg== 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.42 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 A8BF7606A32D for ; Sun, 29 Nov 2026 20:22:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A8BF7606A32D 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-f42.google.com with SMTP id ffacd0b85a97d-491846221ffso8594749f8f.3 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=niHaB017YGv3ap1vLGxwjC3C2kfaBxmU5OY9CT7HWvW27DllRmRSL/YQfI4Yn+Dqp0 zAGu07gzWvBJtPaXB6FB3TslOePMa800Pu/6DijrGSdb7E15cuZ2JYHEaYhWZ0nBBxqW 52rCjw/4ZUTobJDoI13g+hVpFy+bCqIvcbDqCQz/UZqae9Z4SJPWGV2TlSEE0IK6KDLs eH+60QfCJWmvr6YRuLuZuv191mp+LmkGCUnlGbGOQcZmQkFBX8+q9i11FR66FJ6+GN8z 5HVUZMp6XC/yT2rwqQqKeDLnFZbz5b19cfivz7+9ipUp5AG+f5lldc1sGnhC/DmRscmB 7IYg== X-Forwarded-Encrypted: i=1; AL+hErE3WPB/3mIoe5Va6UxSShSxszotEZ//wX6JGkNzKE3eea3jxKsIgojv6kGxZbii3QpuCF5wo3BZF1raMcA=@vger.kernel.org X-Gm-Message-State: APuU4Z/tLS5K3bEi9a3hvW6oE0hEgohHW6R6GTHeaes3DV2pzLBpNe+/ zum60IMAALrxmLtCtYfzx9JEkfjgksAq9Wj7+yTyO1/OPFkMm3Ozcz16 X-Gm-Gg: AZFdTZcQJ1pSoveWb0PMHdOO3c9Uriiiz+JMNdw3quAhBWQfbEzKbHWljlOIThCrKtI ZgYRUDWdMPPQ8zOcEfKzStXvc/wBrWW0KJKm1p1FtPRP3qzJ/uywL/a4VY1Q9hIAFAFcdNkVJng zbF2RrAD3mftyB2QOGhrejRBvwZpewUbvyxUBZIFByBcKOmsNmFJQ2V0ZbKYbyW1mrTGSdM0bO5 4f2UbXxRWR3CjHqr/ATyI5qrxAk+4QhOzBXk7KT8svzSFQK6W8QRUXlj8tNbxQqt2L3X+8/J7xZ Nkmk9ldZ/hom3oph27DHwFCUVx1PDQhJEljkXjvG5whEjgvcewNO29kPmkSzjKwQCgZnAFJgNCP yT7/7ojefk+CKRmKhU7pBpl4nsggT7qcmzM5fCtn0Jqh2uEZ2QGh82ViBPD+TZ7JkhotsvKaBkm Y+3jzSihx4Xo8gvB1mXUaAK64xIvW1VfR68yMXlwrfbsuKDNtOdeaDdGuhXsu6LQluSC5j6S7KD 4SQXXO2o328Vu2NUVSf+O9qcor7gR8Yzkg+M31VFEPb3ByZYWkUqkbpTswMUmHcOkQEUZ1hMF6e AuDloH92OTr2X8QUsZSagRot 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-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 , 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