From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793880763; b=WkmC1g5tBYu1VszddXyOcHStwQ/2EkhGXWbp/93I8O766GzYTtVYkDFcHmjjoCK98ka0 jvLSl6HgA+akFZ56Q4Tv45P51lOlSAd+QPJbkOvvaMvz3n3VPKGIvilLbYvFU/sYa8uzI /y1WC9838CxQOC4/wCuAs2nhRXpQfBqO00DAhGWFwWDDrgeKHRlp3FZlJg7Y2HhBLoXWj eUoHAP9FzHTRB/UfDuIgvpDQO+q9LTK+ndd4/AfboREzCVZSoKFFaXK15jsYr8sKjAdaV cf6ScmDHoXcRXkrvH5+ZW6B8pZgnJHrlzPOCJCqwJj+RVmNhim61Fd0Ar2s9gGSNeUA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793880763; h=Received:DKIM-Signature:Received:Received:X-ME-Sender:X-ME-Received: X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=zHMd/dXYh7gIG0cBwUrUnPLYGKq0g6gjljh3Mny/LFw=; b=DgkWxZO3uJUyZN5INh2jujekfo/p1ReoIGX0CIZc0OR8kug6evNDPMYE0S/JyfWvbQX/ t3suC/lKjC/tPuqw447r07WQ+12QtAI5RFFldO+xw9SoqrttDaPTZL6208Qj+k0P8GekF anAaeVIfJvoiZJfCqhUhqUDJjco7KvQCa8fyAoyRIBskdIOSRbYwtASSBYQcrnLiBuKB2 AeUm9X+DSiVy1n1+VWtq+ETWRpsaOp+4/VSy3OK92zuwunc54+9fdN262P1SCyji3pQn8 n/cp7676XlVZYJGUBYroYY/lDy7548T6gUDDonkCr6La1J/VepkdxoLHRmwLY5EfN6Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=n83ov0yb; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBB45606A31B; Thu, 5 Nov 2026 12:12:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=n83ov0yb Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4BF01F000C1; Thu, 5 Nov 2026 12:12:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793880762; bh=zHMd/dXYh7gIG0cBwUrUnPLYGKq0g6gjljh3Mny/LFw=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=n83ov0ybs9zKjBE+JDKTc4TPiw5KduZShNqgRdasi9NMkwyZpv9GLkz4bkaF9cFXT t1RXCJACx+SLGqI76ahilnF5Hghlr8BcHq5Q4+ctzVdzne1JxE1T80Z+msPh8iSWcG Wq/F1ukxPloyUBAKh2tFffyAngWvC2GqcFWfyMGYXCdIIdsZrI43ONo8fczLlAYQiu fWqAQ2THJmzKgeR6S4k2jBoiMsGdPGbPXgf6Vg1E5v3mf+LXtxpi+Mdycih4L4nz+t bIPbeOyGnj1SwlPupDwntO7HTqvB4zyyzBFD8//WJe/f3ipgyqkUSuZ8zoBTd8wPRa zi1CQyyyWdH+A== Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfauth.ams.internal (Postfix) with ESMTP id BFC97198003A; Thu, 5 Nov 2026 07:12:38 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Thu, 05 Nov 2026 07:12:40 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFSCgiRUzVCJYCqptrUSa9RHQsLWQK1L6z9r9zyIOoZgIGHK/fHlQJAVg90TKAzJ3 s4UplecP7s1f3qOUWNCj5tYaRHeCEDqQKOYgk3SWTs3mYDAtRtLSDSya2S0qC24O4N3NP7 Hc222vgyIrKhtZHOstUnlYYDNDcxuWUYVxaKNabOt10YTuemJKgd7oOphgIehKzrjXcH+V YHa8b2QL81OVg8O0nTCEw0sxzYDLw5LJ1tdblkIm2kd/XRoBN5iuZBfEh0LXeo6+/pZ+Bj 9/ybhAJ6xcJ/Rib4C9vXdNXcqtFniKdrO19OrbOg5LNTt/el6+WBUWKwXLc7Sy8y3GeZFq xAGe7EK8aR7Nld64zmyK1EMnNXKRWPa7dPDsLG7XgfWEx9jXTHU9TApHgygnxsw71KnEhr +E0Uc0ouJy3xpuTYTPcPym6iVmVuPwbOHiMJb+4rYKxvdfBnVfQZxTheF/5Dmzo0t+Ihvc E2r8qAWyRV3T0wKJMPoyozVSXaLKFLmmDsnespiGkdOim9QHqyZDYJTnQfD/YFJD7Gt/Bd MkcHiQLVZMIwvUNZPsfOEelQMt5BXwHLuOxmUIobhmNRBMdOaaZvCGqVn4iTczB4mCBznY MWgm/wVf17mSFUw921U8q8JLuzeLlj2XEPeH+nRaAoiFL+3rMtGPysUjxlgw X-ME-Proxy: Feedback-ID: i10464835:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Nov 2026 07:12:37 -0500 (EST) Date: Thu, 5 Nov 2026 12:12:36 +0000 From: Kiryl Shutsemau To: Hungyu Lin Cc: willy@infradead.org, jack@suse.cz, akpm@linux-foundation.org, dave.hansen@linux.intel.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] filemap: prefault writes starting beyond EOF Message-ID: References: <20261104071002.49693-1-dennylin0707@gmail.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20261104071002.49693-1-dennylin0707@gmail.com> On Wed, Nov 04, 2026 at 07:10:02AM +0000, Hungyu Lin wrote: > Since prefaulting moved to the slow write path, a buffered write can reach > ->write_begin() and ->write_end() before discovering that its source buffer > is unreadable. Several filesystems can extend i_size in these callbacks > even when no data was copied. For example, a one-byte pwrite() at offset > 4096 into an empty file can fail with EFAULT but leave a 4096-byte file. > > Prefault the source before ->write_begin() when the write position is > beyond EOF, and return EFAULT if no source bytes can be made readable. > Overwrites and appends continue to skip this prefault. Keep the existing > slow-path faulting for forward progress after a failed atomic copy. > > This also leaves intentional zero-length ->write_end() calls used by > generic_cont_expand_simple() unchanged. As with the previous prefaulting > behavior, a concurrent userspace unmap can still race with the later copy. > > Fixes: 665575cff098 ("filemap: move prefaulting out of hot write path") > Reported-by: Kiryl Shutsemau > Closes: https://lore.kernel.org/linux-mm/at9xXRhD2xZhszEj@thinkstation/ > Suggested-by: Kiryl Shutsemau > Link: https://lore.kernel.org/all/at-XtWBQg3jv3H8Z@thinkstation/ > Cc: stable@vger.kernel.org > Signed-off-by: Hungyu Lin You found the bug, I only pointed out that it is not tmpfs-specific. Please drop Reported-by and Closes; Suggested-by and Link are enough. Reviewed-by: Kiryl Shutsemau (Meta) . -- Kiryl Shutsemau / Kirill A. Shutemov