From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3B1835836B for ; Mon, 24 Aug 2026 02:33:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787538797; cv=none; b=S41SuNg1MgCLuKbWKQ5UEJO688QG24xAu1tdSopfxu1Gk/mHwYng0vQNB16rA2fpiNEiwGhheNxfP79S8mRGuaxhUmZGrOHbR5xG1rsAZ4FK0y5mCnQRg7sKe94RSLdQoSJvh5jKUNWuY1+mqyj8A5rqmcpep2x9hR1YHDpmsDs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787538797; c=relaxed/simple; bh=IpG3oU2hqwUfyAagaEDt2V8QWCbUe5Amu3fla6RZdko=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=UunHZbbkf4uilxN2IigoLVUpuS2Z2qg5/hvWwCIsSaH4qOuwWr3jgwaUTnY+lAZUixzxyLrl6ZXECjQlgZ6vz0JzuvOsFm3OFbXhZVryE2RY40nhaEmUD0pXr8/CMREHaMwZQeGxXaNhcXDg30iLiH6PX/gJ0NLGTpMi3EllEjY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Y3HrU6ZM; arc=none smtp.client-ip=209.85.214.173 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.b="Y3HrU6ZM" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2ce87c7e3bbso32252745ad.1 for ; Sun, 23 Aug 2026 19:33:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787538788; x=1788143588; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=2W3X3/X9OGpB4hHUUielWb4210XDqU18448NB33jQxk=; b=Y3HrU6ZMNX7bRzlCOtgBR/pfPjM4nm0oCXIqIJhsClP3Gn4YFNqVvSIZ5Ejxee8ikF fR78DhCxXM88RA4gcKYz7hHVl34zf8KkbBu8a9ow2l1zAqXLEyat7QcdYTv92oZlrl4i sfwvDY+fLrkt7xL2ObzFlNQOfEUyI3rlIt/MFfebFYS1VT1EuuNmSvOuHN6GN0lXMltH qfT8P/wy/DALdeTXIMD4+hfttiY8XYsqKvsCI70QLd5Y8qiQjv+vb9eMFUiP1PlLcKfH 6OSFilTiJfh+8wVpR7ramwjPSEJd1HPYz/w5xlSwUO123YxouI5booSEl3dgXdCtpcth V1fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787538788; x=1788143588; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=2W3X3/X9OGpB4hHUUielWb4210XDqU18448NB33jQxk=; b=NTeVbP4t8dsrv6DjHV1g3XzJBuO5GWpqt4PS/qFsOpTXkD5+XQ1/z895twsECwihaz zyKfh2GzUeZG1OW1kS0AP5UTpQmJNbl+tTiUU3xeEgHkp1yDqAnX2Q6dhDQw0PZpinE+ 27SaDsasnsV+zBOjPRFQfR7zKwWInNRPMdGRYmqg75HxGn/SgbQyRbY7w76MfBAOxyLw 7vtLER8y0uy2OOCqzDAbVIugKAr0mOy/O0ywp2u6GVOU68j9KU1tA6yXWbbjfktGk1Bn e3WjrT+kCcLsVcKBOsjVZ+aP09YTTJJetmiHhJNoblmjMHfsIQg2FgftZZ8mfMfmrHgt FVnw== X-Forwarded-Encrypted: i=1; AHgh+RqKtUkLewPZF7xJ8vES9MCieCfXfNjByvmmkmQXu6H/he4PfDNOpG+cTZ4Tq2o5Q/sY5gRMoaTSbwTzZLg=@vger.kernel.org X-Gm-Message-State: AFuF++n6rRFQpRc2+G1GVtsJL6gxMRYXvynkzZ/RIDPGoojFCKBLkA4m By8ACijVc6VBRcitNiHfxv8LMBbLxUywedUIj0Vslo8coeWHytAvU0sU X-Gm-Gg: AR+sD10EQ4RiC8TNuYjDKuMnuD31sW+V6RB7JRGNb+CZtJGjGk3D7w2HEKarfVCkgje eTZKU+b3Xoh5/YrbJqo9UVSXyouO84qc4JaGuHptSdbr2pNeH20TXqlTR2/QlbQPTiOOTPnv2wa +Gk2jvPuS8PP2iwOHNCI0yFhLOFITB+PzQzXd566hebEjHF//zQ/pbjF7YvIDA6wV0dYMBLotNx l3y7VuZgn8srU3Vk3u3FhqCBBUaKAT8WEyS2mC5i/52IBEG0kIMTT+eDNLljPWKRH4+vYMk7H3d f1eT6b/qI7idvl7R0yKScoG3qSAsL7NkABGAvk8EE+jCgIU0jsc2MX10H8A4KLOSCVC8w112UEl DD4wY6jy6/3XAswb9DPkj4YRu+V/PAMa5VqJZbk6Go5S9+yj/Ip6nwpRSApgnXM7WTkjKkI5cnr FDwZ2PQcsJO3hxfZkEvmuic/1U2rGbceJe1Ue4gyQ4zH0Y62cfr3P9A56pBmyk/smoUf7JdfvCb BoS75I1HCqu0wOPoFH8esKkl1D9qEPCdSCW6/95VyT3eNg00o2gMI+bnAjINqP6pc/IMGJh8Q== X-Received: by 2002:a17:902:da89:b0:2d3:716e:e2ae with SMTP id d9443c01a7336-2d64ae18c43mr417897145ad.6.1787538788312; Sun, 23 Aug 2026 19:33:08 -0700 (PDT) Received: from codespaces-2362ac.3gx5x4kts4veljes22u4ri2f3b.ix.internal.cloudapp.net ([23.97.62.152]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d676761c35sm12684135ad.15.2026.08.23.19.33.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Aug 2026 19:33:07 -0700 (PDT) From: Seongjae Jeong To: Jaegeuk Kim , Chao Yu Cc: Daeho Jeong , Yonggil Song , Hans Holmberg , linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Seongjae Jeong Subject: [PATCH v2] f2fs: use adjusted write range after f2fs_write_checks() Date: Mon, 24 Aug 2026 02:32:31 +0000 Message-ID: <20260824023231.24616-1-jsjlee1020@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit generic_write_checks() in f2fs_write_checks() can adjust iocb->ki_pos for append writes and truncate the iterator to limit the number of bytes to write. In f2fs_file_write_iter(), the pinned-file overwrite check currently uses the position and count saved before f2fs_write_checks(), so it can check a range different from the actual write range. The forced buffered I/O cleanup also uses orig_pos saved before f2fs_write_checks(). For O_APPEND writes, this can make the cleanup flush and invalidate the wrong page cache range. Move the pinned-file overwrite check after f2fs_write_checks() and use the adjusted iocb->ki_pos and iov_iter_count(from). Also save the adjusted write position and use it for the forced buffered I/O cleanup. Fixes: 3fdd89b452c2 ("f2fs: prevent writing without fallocate() for pinned files") Fixes: 92318f20d703 ("f2fs: preserve direct write semantics when buffering is forced") Signed-off-by: Seongjae Jeong --- V1 -> V2: Move the pinned-file overwrite check after f2fs_write_checks() and use the adjusted write position and iterator count fs/f2fs/file.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index d82be8c1502a..d440231b8cb9 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -5641,9 +5641,8 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) bool dio; bool may_need_sync = true; int preallocated; - const loff_t pos = iocb->ki_pos; - const ssize_t count = iov_iter_count(from); ssize_t ret; + loff_t bufio_start_pos; if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) { ret = -EIO; @@ -5664,15 +5663,17 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) inode_lock(inode); } + ret = f2fs_write_checks(iocb, from); + if (ret <= 0) + goto out_unlock; + if (f2fs_is_pinned_file(inode) && - !f2fs_overwrite_io(inode, pos, count)) { + !f2fs_overwrite_io(inode, iocb->ki_pos, iov_iter_count(from))) { ret = -EIO; goto out_unlock; } - ret = f2fs_write_checks(iocb, from); - if (ret <= 0) - goto out_unlock; + bufio_start_pos = iocb->ki_pos; /* Determine whether we will do a direct write or a buffered write. */ dio = f2fs_should_use_dio(inode, iocb, from); @@ -5727,8 +5728,8 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) */ if (ret > 0 && !dio && (iocb->ki_flags & IOCB_DIRECT)) f2fs_flush_buffered_write(iocb->ki_filp->f_mapping, - orig_pos, - orig_pos + ret - 1); + bufio_start_pos, + bufio_start_pos + ret - 1); return ret; } base-commit: dafb84f092a6387748b2df4c8f647d46873bc1a0 -- 2.53.0