From nobody Mon Jun 8 07:24:33 2026 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (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 643323AEB4A for ; Mon, 1 Jun 2026 14:12:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780323132; cv=none; b=BttKJ3Q37SAFzRNu0GpZklvHN4nhzCneaR9H+m1/PxySOTdUKHmhzwQimVcVJFCQ3HCS2fadOnKoRzeAN1v5no5PvPhl3atnJHEyWD/Z7TFIGdOH/8W/YqqGUW2fMBh/+y4lz9LA99BLKS2qEIFC0mjsiP/vUreu+E1KZQ3IZc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780323132; c=relaxed/simple; bh=7NFsRasn8T3zyLqanO3jDYeY1SxFMHq38Y43WYMOIKQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=WMY4615d3s3D9kYA68K8tN3LLAWCIBaxIg6K66cRORBdtU24FJznAi4+P7SfRdOFJsk9UgUDxE79qwcvBPQhq423X6MDbvgF956tU5Cc+MXQ+XyA1jWhe004BaafSoYsm8/DHoOBHE+ryNkV7miDKtWsjUsVEsj35RA4RHxuZf0= 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=HZ4+qZBR; arc=none smtp.client-ip=209.85.216.50 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="HZ4+qZBR" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-36d630c0e35so1807274a91.3 for ; Mon, 01 Jun 2026 07:12:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780323130; x=1780927930; 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=BJkVFTFP++6lvX7D98bQzjb1G5a2yBkaBl1RBWQ2FC0=; b=HZ4+qZBRZVzTUgMLP0K5CSTOO9v0rSbMqWDFGETEzfLqsxR6FNDykhtzzbR1TSbLjT nXRAyNtrtFtZpivMRc2BBnCANrCFeiGlXQMtH/W0kDnqmDBvMo48rR0ELgHWSGx9Zr7h deUL/In7sEPUjfkCp6IYy8WUCF1ZZfJGcUSGBLgieBo2gBwLIAmfvxWKpmMc3hwQI76s v1wdS65VReoo5yHTm1O2mmqqbn3L93ukKLlmaHPP8UQwqp8UUmlTINV5xoVYbU2nLr/R kk0Y7N9n9RSl2lE1tyXDqOHJ7ptljJr1Dh1ricl8pbmTG62r6TpJ6fhY8gAtalvTnDk1 BSkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780323130; x=1780927930; 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=BJkVFTFP++6lvX7D98bQzjb1G5a2yBkaBl1RBWQ2FC0=; b=Ks2iiXvskB7LN63TPm+zR9vCOx04T9GcEvhogukENT67hmCZCTaknIlee6koLvGil6 5Yy74Ke45437ZLiYzHzpdXjrIQxxw8DXhcq+8thJNuJxCUkpcPAuesBO1Bs9V35g5s/I 7I3rLSKGpsk1MzoNl3RvSIqt6Y16j1Gotf9VRVj87vSXXyqvwz5AL3wh4tB/FroDJL24 7KdPwPd0U7lSblJd/E9ARZY2n4pnVEIsHudV9MDPeq7LqHVKXZJY2Sjc7phP4htNqlC5 i2yRWt5uaoWH80HtIry/6wMKFbDm07nkzwNOb7NU/Jvh8OEnoniiM49uYDggGAru1IdJ VLYg== X-Forwarded-Encrypted: i=1; AFNElJ+4MkReELnCp1BjyO4X+LbZsPvf2rzw3pCjGAoDMjCS6G7kE7hBDseSVKKZ2QUdUA1f+FHl/dGYACBbzNs=@vger.kernel.org X-Gm-Message-State: AOJu0YxZX3+Vwyl55IrbiJMo5hocQhSHo7IrG6JJP/R2+TRQUQznjNHv o1bEdZ4x9vsavCbdXYLdffje1SCQmO/EfO4s+RKvD9gWKwp0G0TrR/U9 X-Gm-Gg: Acq92OHrcNpuxb0tv3tlhedhoaEK43mtB3knK2gCnugmNuR6e+wIgNezwCTKRgCZywy mj5kxwp0DB0wKzN8N85Ewg39WlqSmXIexGLyMFIcJcDh6P5+ApAvdRpV/yVDTdhKYn/ckL9yChq BcmIpgzRtKTgVH9/mm6A31Lq7vC95UvDy1LcbmZFbp9+DlyiQGVi6zBNv8QbBDW4IdITs/MIgdk OXqxImomA+g3gtMWLKxSoQL2QzDb9KlyYqhk3IZ7SxaFP8IFraWIgBWtF+TJWf5qwRhMSEmleHI QRnAmUQMAmGcSjpzGAdVYL45nBt/6OAQS1CNr52vVgQgdXR5Kys+/EoMaX49w+41GqUnN7tbNOy liOncbYA/CsuS68YtCExPquhj1LxPIPlJsZ0RolKOJtHrYaNxbpH2cGaIbSN91TaA1lUo/QLZKS khFEVL0bRUm8Oh4y9W X-Received: by 2002:a17:90b:3e88:b0:368:341a:a925 with SMTP id 98e67ed59e1d1-36c5021a7c7mr12809400a91.23.1780323129515; Mon, 01 Jun 2026 07:12:09 -0700 (PDT) Received: from lgs.. ([2001:250:5800:1000::f280]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36dbe6ea489sm2820118a91.5.2026.06.01.07.12.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2026 07:12:09 -0700 (PDT) From: Guangshuo Li To: Chris Mason , David Sterba , Filipe Manana , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Guangshuo Li Subject: [PATCH] btrfs: fix inline reflink deadlock at non-zero offset Date: Mon, 1 Jun 2026 22:09:58 +0800 Message-ID: <20260601140958.1333017-1-lgs201920130244@gmail.com> X-Mailer: git-send-email 2.43.0 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" clone_copy_inline_extent() can copy an inline extent into a page of the destination inode before starting a transaction. If that page is beyond EOF, writeback started by a transaction commit with flushoncommit can invalidate the folio and block on the same extent range lock held by the reflink task, while the reflink task waits to start a transaction. The copy_to_page path already updates i_size after copy_inline_to_page(), so writeback no longer treats the copied page as beyond EOF. However, clone_copy_inline_extent() has an earlier new_key->offset > 0 path that also calls copy_inline_to_page() and then goes to out, where it starts a transaction. That path still leaves i_size unchanged before starting the transaction. Update i_size after a successful copy_inline_to_page() in the early non-zero offset path as well, matching the existing copy_to_page path. Fixes: 05a5a7621ce66 ("Btrfs: implement full reflink support for inline ext= ents") Signed-off-by: Guangshuo Li --- fs/btrfs/reflink.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/reflink.c b/fs/btrfs/reflink.c index 49865a463780..5722cccb53eb 100644 --- a/fs/btrfs/reflink.c +++ b/fs/btrfs/reflink.c @@ -185,6 +185,8 @@ static int clone_copy_inline_extent(struct btrfs_inode = *inode, if (new_key->offset > 0) { ret =3D copy_inline_to_page(inode, new_key->offset, inline_data, size, datal, comp_type); + if (ret =3D=3D 0 && new_key->offset + datal > i_size_read(&inode->vfs_in= ode)) + i_size_write(&inode->vfs_inode, new_key->offset + datal); goto out; } =20 --=20 2.43.0