From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.110 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796212026; b=JNVI+E7PPZK3kCiymImLet/Qga+yqkKY1tpYPOKta8EzSHEZ9G1Ifvsbd7QNVQv6LWMF eSLMcyw+5sd+mEX99aU9mPgK/v93EB9JyGDNM/reLB88HnCxASD2CYBe1nwXY3B5C6Ks9 SEjJQR5Bwu3pLd/uUp2PAaMy7EaIEW8+agG0vbS63Enz3cyoV0UyWCMxjtpipoVLfDSVr G13y9sViYYLsb0fEOUGYXDIFaPzjVneEdonocr0w5yTBMKPLW501y5FeN/AWpw/bdPwUQ Q6fuFRF1ViQafyO871pG3IRRH6mKMfX7Pn4g+cMEKyFA+eFrOIA++VnZnlLpNJjOwFQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796212026; 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=3AVhcX7zdvFVmnxK//ApGlIX+BlFYnkW3n4U+CIxYvs=; b=IJJG59o7W/XTiMOwhQrl2wsTzwoVZ8U25ico3O7dqlbd+0m8NOb9xu34zL6SqhiXhByj IL6+K0T8OTrQUOLJvCD9gXaPsSMXlk0sVajrNGLcIt2PJeHHQAhHuMnvkZ+hlWW+eEVST /OqsQEvd3ULh4bp1N4mTW5RZibwPwcwd4ghGKEaSxdT/APyi5/9GLoku9iKAVNR9FZW0p Ym97k/gBdDxrask7ZKVmalz6FWWbx+EV9fleVhZ2Zz2VUNtPaPQCIMAGNCTKWVEDl7kvK 0tKZoLzZslM2BM38UZO8MIfOpmBrPij2jqK7tftMBo9oHHgNA6s/+8ayTdnnHqLcUHQ== 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=Zrwg+6Kv; arc=none smtp.remote-ip=115.124.30.110 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (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 56EE6606A31A; Wed, 2 Dec 2026 11:47:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 56EE6606A31A 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, unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=Zrwg+6Kv DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1796212021; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=3AVhcX7zdvFVmnxK//ApGlIX+BlFYnkW3n4U+CIxYvs=; b=Zrwg+6Kvds3Fbzxgqy85/oUA76+/woM3qeDdOSHhdkQZtoM/S0wOwmAZtGnjXDPJ3hbAJb+73ZOLHvocHUb3aCZHQkgo3NUKt/sjzkor41vawc8oUbRFHqb5/QuQXvOjjz7RG8PUbaxCI26CtEzIXlUmCc+J7rCZ8Az1gOc1TW0= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R731e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037033178;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=81;SR=0;TI=SMTPD_---0XGAFJuz_1796212013; Received: from 30.74.144.133(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XGAFJuz_1796212013 cluster:ay36) by smtp.aliyun-inc.com; Wed, 02 Dec 2026 19:46:56 +0800 Message-ID: <5a59f5c0-14e9-4d0d-b039-97c179ac44a8@linux.alibaba.com> Date: Wed, 2 Dec 2026 19:46:53 +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 02/32] mm/shmem: don't skip parts of a split swap entry when punching holes 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 , stable@vger.kernel.org, Chris Mason References: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> <20261129-fixes_core_3-v1-2-f66094116801@kernel.org> From: Baolin Wang In-Reply-To: <20261129-fixes_core_3-v1-2-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: > The final loop in shmem_undo_range() looks up a batch of entries and > calls shmem_free_swap() for each swap entry. Concurrently swapping in a > folio that is smaller than the swap entry splits the entry. The first > piece keeps the value of the original entry, so shmem_free_swap() only > frees that piece and reports success. The loop then continues with the > next entry of the batch, skipping the remaining pieces: > > hole punch read() > ========== ====== > find_get_entries() > index 192: swap, order 6 > index 256: swap, order 6 > shmem_swapin_folio(), index 200 > shmem_split_large_entry() > shmem_free_swap(), index 192 > order 0 by now: frees 1 page > shmem_free_swap(), index 256 > /* 193 to 255 are left behind */ > > While truncate scans again until nothing is left, a hole punch only > makes a single pass and does not revisit these entries. > > Consequently, punching a hole into a shmem/tmpfs file with large swap > entries can leave old data behind if it races with a read of that range: > fallocate() succeeds, but later reads return the old data instead of > zeroes, and the swap space stays in use. > > Let's fix it by letting shmem_free_swap() return the number of pages the > swap entry covered, and looking up the remaining entries again starting > at the first index that was not freed. > > As the first loop in shmem_undo_range() already frees all swap entries > within the range, these additional lookups are rare. > > This has low urgency, as the race is hard to hit. > > Fixes: 809bc86517cc ("mm: shmem: support large folio swap out") > Cc: stable@vger.kernel.org > Reported-by: Chris Mason > Signed-off-by: David Hildenbrand (Arm) > --- LGTM. Reviewed-by: Baolin Wang