From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796246722; b=WW9OxvWevVilM9/wrUr+pOIo7AdM/ODy9Yhi7gNj9verztLCGRDUyuyixY9jRqs3zLzZ /tOjeINoTPwcK6zjO8sRr1+ndszu3uYorXOuHfVJDGTYucDQ/UXAy4xI3XCZVLPT4hLrj b5UX8MtepDC9M0DAzmMDdT2Od88JRGZtyFrbbEmoER/8qDA7na9ZweK5ohu8WwvVXL7Cx ngOVhIums6RVK1FqEM9qnoT8ATzdzsEclGZjFV/1Vk+jDmfLPG4B+1pHsmsLGneKJsNMY w8rkhVYizd7jPTwR0aVQYXhiiF1DGzIu+PJZsTuwhBmOrqj/jRn3gWz6OshmVUfzulw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796246722; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: MIME-Version:Content-Type:Content-Transfer-Encoding:Subject:From:To: Cc:In-Reply-To:References:Date:Message-Id:X-Mailer; bh=vfTz6eRwh95YC1DecOjJBrF5GDVP5Vjx4glc9jlK/jc=; b=BcpdT+5Vbqp135lyySTMnUMUJrXLtggcLokUafmghcBGibmoAlpvYbbuODPoGOeNyTsi +GAD7fytLVCTPTsDF+bbVLcZ+vsRMzy4a2dkNvjNQdMNrBJH9ZhyZx7meLuvSSeyy6WVA jiPQOCGB1Yp5L+zhrWY5fImO+KluSQZ/5Ae8jr/mtqYH9xbvlgQFd5AJY0OFMUuhajK7l YEVROCk18nd32D/8U2pNYbcJ3wq6mORiWfXkJytMaOu5sW7/qUMQlP/cKabBCbIpyiBie J/6g96xuAK+1r7URy64egNR3Bc8ChKs79OkBhtd5fGdSCRKs65vNAGt7T4qy/4YUK1w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass header.d=gourry.net header.i=@gourry.net header.a=rsa-sha256 header.s=google header.b=HHeGdVRu; arc=none smtp.remote-ip=209.85.160.169 Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) (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 01A47606A32C for ; Wed, 2 Dec 2026 21:25:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 01A47606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.a=rsa-sha256 header.s=google header.b=HHeGdVRu Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-5363316fa0cso142216511cf.3 for ; Wed, 02 Dec 2026 13:25:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1796246721; x=1796851521; darn=vger.kernel.org; h=message-id:date:references:in-reply-to:cc:to:from:subject :content-transfer-encoding:content-type:mime-version:from:to:cc :subject:date:message-id:reply-to:content-type; bh=vfTz6eRwh95YC1DecOjJBrF5GDVP5Vjx4glc9jlK/jc=; b=HHeGdVRu5TUdg7KvVdwCoEZ/aSUTSqPdO9JnKpNbNnSMX/Y/T8KzIJtfgF1Jzins/g aAXlA+8ASlf6dT3HX5JntEWxk+RmAvdIdosyagAIUe2qStD+B9AWpLlvro8jV68aJamw PD5oyDRLp99BxHvAjYzRI1J5yla2Q9NFfPpcjGQ1VRHLNosnINCz3NTaAPrcwiYCK/8I +xttJB0rBx01jK7sS+a9ptZgTB2X6ISqisF1GngEDl9hWQiicTPdDja8nrcRzPuQhejC pYDmXViFXoPBrfb9X7SF+7hxXrGuZ59OKUp0HjVmFQ50Xax72G5CIzKb12s5P2pkRiOM aP1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796246721; x=1796851521; h=message-id:date:references:in-reply-to:cc:to:from:subject :content-transfer-encoding:content-type:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=vfTz6eRwh95YC1DecOjJBrF5GDVP5Vjx4glc9jlK/jc=; b=SVCg74MeyWejV4VyJ3Ra3d+s+LGMxv/6Y/mimcjrwyS7teiMgC2/YumiyKwFBOnmak igOA2c6saM56Tn8pvdBgW9cAz+cXWZ++LXdKvkV/MbCzwieY9rfg+oZZ2Q2rnL338tgV akXyWqkyrD3rZ5h38oGCkx3LXp7vQp9oSngkDUKwyPEB5dSlw+Gvl/zeLPaSXNyetdUE x8ZvhEP8XriFk6Cb/EEeUbN+RpqBlCvb+KhbAYZ2xDAcZznx3soVuddkMP+l+j5PvpaR 6LFNSmukhy/Mt/H5DOJh9MXwHoqCwLEfoP/U+jc1LAUzeapmNXh/c9ekUDjxhr+u+nmw 4Szw== X-Forwarded-Encrypted: i=1; AL+hErHXLrHNQIuTlqrEnZ1JSsxl4hfYvOQ4dd8WOP/xJ+5xrt+uooPDJItdslAYv/I1cQWGwagbx5kmvUiTPbE=@vger.kernel.org X-Gm-Message-State: APuU4Z+hKB/R8ElFj3iDScF/v8dEGJI5v4kCCxcnwL0BW48DboPodndH MVZUoV7HuFPhFQNWZ9PFwz5pK1N7RqdhQ/iL0xsZ4dNwRmeAXeIXqxoOSjd9Aht+/6w= X-Gm-Gg: AZFdTZcY/757pxF1p/1VjV/DXFDItlRqCbUkynlDOjxPi9Wkcg47YX/yI7C+XSTjLSZ jOkwBdk4H5YZNIZ3tRbvRQbNsVCjij2XsOyaO0IGqOgx9AouQM6bApmBJQtj07IP6rD/xciU23a QKdGHi23m7gv0bjRf7PzcxTlW5FbiH93K6CoUP5Ok2uFyX5wRNHiNmK0U7i3/+y3oeTPUFOsLA2 0wyy4DjC1n0xFBA53e2D4rGBhb4rbKrgUlrR3u/g39hDLfnzYChPcx/eD3FkTeWtBzoO0LiWwfl /N+qT1kD3YF56fFOWRnq1usmxdyttEh+49AXvRDQS3E8Km1LNFmBSKEbIra7OHIbOkcMScICwqa e5BdXrr4SfGooDFbjZHr9aQ5bioM0WGx+lso/rxr+jGl4MX7T72gDnRCElnjCizpugkWYoT/cx3 aRyqIgUeYqd/Vwg56IQwy08yQiUm/83aKlm6xAACluojf632sFXVkD3FEF6ZvISg/ZhsA4qE15N Sn/sxyIglb7LbWEJlu27t/fO0WU29P4Y3vTetMpZaMYyT+5pR/bySeK6qn7J29biePjpvuwfrYR icQLiqdZSwG51bY6ICm7y9EtxQ495PvxN/2mALg39S49o7szdnD32YTbrmUijQzDiljoL61lRgm XjFy1SMwchAF4iHjN+8WHWvZ7t3kp X-Received: by 2002:a05:622a:4d97:b0:532:abc9:8f4f with SMTP id d75a77b69052e-55d76a1fc19mr763773071cf.37.1796246720621; Wed, 02 Dec 2026 13:25:20 -0800 (PST) Received: from [192.168.50.231] (pool-71-191-145-202.washdc.fios.verizon.net. [71.191.145.202]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-921cf1e78ebsm9347406d6.16.2026.12.02.13.25.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 13:25:20 -0800 (PST) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: Re: [PATCH 02/32] mm/shmem: don't skip parts of a split swap entry when punching holes From: "Gregory Price (Meta)" To: "David Hildenbrand (Arm)" Cc: 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 , 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 In-Reply-To: <20261129-fixes_core_3-v1-2-f66094116801@kernel.org> References: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> <20261129-fixes_core_3-v1-2-f66094116801@kernel.org> Date: Wed, 02 Dec 2026 16:25:17 -0500 Message-Id: <179624671795.2841792.9232720270890845730.b4-reply@b4> X-Mailer: b4 0.17-dev On 2026-11-29 11:06 +0100, 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) race is indeed hard to hit, i could not actually prove that i could hit it even with the normal tricks. I did at least validate the behavior looks otherwise unchanged and the return value is a nice improvement. Tested-by: Gregory Price (Meta) Reviewed-by: Gregory Price (Meta) -- ~Gregory