From nobody Sat Jun 13 21:00:35 2026 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (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 C3D7D29BD8C for ; Tue, 5 May 2026 12:46:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777985215; cv=none; b=Qh+E2ul9WXQKAQ8pceTuHoQrR0mb1Dc+Zz6omk6RjOVLUQZ3H+ePdxEUhLnUoMNWosCLUjzLpbzod5VH7rIzUQpy79oF4zQXdHo0tRz3Ni7WvMaABwVkSpeYLhOYPsd/hF1qvAwJ8NJNVaRRsKlabNwn8XAY6yzh4ZaqVCuaEWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777985215; c=relaxed/simple; bh=WdLTUHQ4IK4gD4WmP/5C10CZKhgvSk2Zoahi5p0xF50=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=J1p/QeywwerdZ4Ko+HS13sqYdjzdS/sb6pcbpv1t1w+ubtf58j/HM9PNCKI1cllsAbSPlnvbqAK6Z859UfyvWy0tTj5feMUnqjZOE3jLc1untKPCVrLGbwok73neNVDoIrbJIDLqdAULqiEtlm0WemOFk/dqJQwJcn+ShwGZGZo= 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=T7/AraZP; arc=none smtp.client-ip=209.85.215.181 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="T7/AraZP" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-c80291e6237so1547146a12.0 for ; Tue, 05 May 2026 05:46:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777985212; x=1778590012; 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; bh=DyER5HkMLx02h4jPGr5WinKEOkBh5cJM3fYlZo/LlRk=; b=T7/AraZPleuemDEYkCUtpuIoTGkWBXFQHZF5vjLMdGyWackC+tihcH8gFzCi2O/7cL 2EA/jTLBcojkIz+6s2CkMHxVdr2Rnh4Fif/cffkzfc6BI3qoLdsfF3Cra8jjwZuZl+X9 0hfPsT9gL6JSj6u7U2w+dj3SmGZgxEBOoyV+EaHsRe4idcJsZBhoN4RwFSHMKB/F7tV9 ++7Dc99rb51g8Mn23t2+ej28AILbaLYLAGrEKGqVGa5zO0D/FlMz07tV7JslVwoDpdY2 nHzYqy52NdSw/Q/G7cGyE8FL+42qyCpj3O4SC0zLwtit4q3vMDaep5+SYuGuNkK5t5Dt 7l4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777985212; x=1778590012; 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; bh=DyER5HkMLx02h4jPGr5WinKEOkBh5cJM3fYlZo/LlRk=; b=L+DS0qFRdmBEEJ4uDUIN0adrMpB0FR7+ri7AXuy9xvzPTBxsekJ8P0UgQhaqkjziN9 Hd79jATXHov1ETK2RgiBUJkZU+JLnQgD/kUW8Ws+WsdvUaJpBJhQenoaYKI6TmyWkHid fEAb+Li0RH5264pfLCeUg4xS10UpSVHFuT/u9k8J4ZadYNepGlomYOFhpZN8+Kvch9+a 7DjiBFdN2eOSxKjbNgHiFgKXGRmEzNQI+Co/APsUwVgiLqWJoXUfZyse1wQfNaFWscyd yfTpsIf+2iBFF3jYiCcz3kebIz3pHuD2d1FTvM0n5WZi5GKIvmWVUMVlTs4T08GJYcno mkoQ== X-Forwarded-Encrypted: i=1; AFNElJ+/OjDuVFIzWZ3ew6e3KPqqrzmHBZLbDjMZRuOwqIb1eF+AKTtnT6Fldqb1wZhg85Y+RwiNr+Won9odKwQ=@vger.kernel.org X-Gm-Message-State: AOJu0YysFzlHdmW0vJoTrmXvO3pg1wnZZdFGBuzqd4g138yWsV8ICJx8 3q89kyj0HDwMXqk3eZ/qmJOaBAR8DDQ8cXmTfZDJvSWUi7YmPU0yFdl5 X-Gm-Gg: AeBDieswLiezXRv5nzRUJ8Pmi5tSCGZXWJU4/GCHOzMlEF1L9CuvwX1pSqUmqvg5xgL Jx4rK/QwpVhL8dbC0vPEm4fOGxqlARzCvFybnAylNTX3xx4JjzjjDfFubIM3lXjb4h+Vu4GC/d6 3Iy12xhW66UAjTK3FDfSciZbRc29pS3fKurslDqLuFVTN1DUrBQ23VxhPZmnFx+e5av+rfEGGPy N2c9EqIjSK4qwQ99L7/L7pVz8Le1Cg02/0Y/EzONoi+ApEITYyTUiJ/JYCm4IoeqKKe8m6vMrYg cKQXqIrXiiBarJx13oZlEKYYX17vFc1JPOCB0Uvx7U9j+1tT2Y0fVWFjCT634SSII5GiaOdoa4j EAptnGirfAcTUsEMtYVMrLu1Xl+UusAFc5OUczHj5iD5zG2UyUC8XO4YiO+Pu70S4vQIQWwCW1M WB2bvckhGiVZ1vyKLf15t9WkvAEifg X-Received: by 2002:a05:6a21:3293:b0:39f:794f:94d8 with SMTP id adf61e73a8af0-3aa3b63574amr3326987637.29.1777985211486; Tue, 05 May 2026 05:46:51 -0700 (PDT) Received: from localhost ([111.228.63.84]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8025008cb9sm7678986a12.30.2026.05.05.05.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 05:46:51 -0700 (PDT) From: Cen Zhang To: cem@kernel.org Cc: linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, baijiaju1990@gmail.com, Cen Zhang Subject: [PATCH] xfs: snapshot i_disk_size before truncate writeback Date: Tue, 5 May 2026 20:46:39 +0800 Message-Id: <20260505124639.1346827-1-zzzccc427@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" xfs_setattr_size() updates the in-core i_size and truncates the page cache before it writes back the range between the on-disk EOF and the new EOF. The range calculation currently samples ip->i_disk_size without the inode ILOCK. Buffered unwritten-extent completion can advance ip->i_disk_size from xfs_iomap_write_unwritten() under XFS_ILOCK_EXCL at the same time. A stale coherent value is harmless here because concurrent EOF advancement only makes the pre-transaction writeback range conservative, but a lockless 64-bit load can tear on 32-bit builds and create a bogus range start or condition. That can cause the null-files avoidance writeback to be skipped or shortened before the size change is logged. Snapshot ip->i_disk_size under XFS_ILOCK_SHARED after truncate_setsize() and use that snapshot for the writeback decision and range start. Signed-off-by: Cen Zhang --- fs/xfs/xfs_iops.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 208543e..a531715 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -915,6 +915,7 @@ xfs_setattr_size( struct xfs_mount *mp =3D ip->i_mount; struct inode *inode =3D VFS_I(ip); xfs_off_t oldsize, newsize; + xfs_fsize_t ondisk_size; struct xfs_trans *tp; int error; uint lock_flags =3D 0; @@ -1024,6 +1025,9 @@ xfs_setattr_size( * guaranteed not to write stale data past the new EOF on truncate down. */ truncate_setsize(inode, newsize); + xfs_ilock(ip, XFS_ILOCK_SHARED); + ondisk_size =3D ip->i_disk_size; + xfs_iunlock(ip, XFS_ILOCK_SHARED); =20 /* * We are going to log the inode size change in this transaction so @@ -1034,9 +1038,9 @@ xfs_setattr_size( * otherwise those blocks may not be zeroed after a crash. */ if (did_zeroing || - (newsize > ip->i_disk_size && oldsize !=3D ip->i_disk_size)) { + (newsize > ondisk_size && oldsize !=3D ondisk_size)) { error =3D filemap_write_and_wait_range(VFS_I(ip)->i_mapping, - ip->i_disk_size, newsize - 1); + ondisk_size, newsize - 1); if (error) return error; } --=20 2.43.0