From nobody Mon Jun 8 06:38:24 2026 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 F35233B19B4 for ; Wed, 3 Jun 2026 12:05:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780488345; cv=none; b=qn6GwSla9R8eal+EAaccUCT7A2jHzEZqcGwriEbQS3WPtJ1gdVbiq2PXHyTsC/LZaTKiG+o6soF3Ey288IAYrSErsWzRi0Pf7GeuFua1PBn9o+hQeqOs7WT5fnbgbFFEiJ4PjqXDRhDtYRnBtEXhy8OHdTh3/KCLEkTf7+jAFUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780488345; c=relaxed/simple; bh=7NFsRasn8T3zyLqanO3jDYeY1SxFMHq38Y43WYMOIKQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Kvfu1m8s6e0w1LdhftwAOIqN0vsWJq2GKQ2QAxODP4RqpOWthIFK12cvKQAnqsypG+SXqSBReyOj1k3eDyd/lJWRItLQxFeVdlYFTLHooEkgEIDLDYDaLduk4O8TDn6YMm29n3/gvU+TbmgzSN5cI1x/0iSoBbdwRr/G+mCr8dY= 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=Dfgql663; arc=none smtp.client-ip=209.85.210.175 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="Dfgql663" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-8422f148dfcso2027987b3a.3 for ; Wed, 03 Jun 2026 05:05:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780488342; x=1781093142; 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=Dfgql663KVmlo/CTqeAvHOG3Prd9bvglz4QdktZWDx0DJZjP7lY1GGVlF1vjEF0gNT sTdoIq5ttWrNE3tUCdwewgVtTIAXVEPF8xbDE1R18e8duLLeFhfqqmNzMO3XjDuGGHYY 1WYEHrg3Y6u8RCCjNLU4krYXdxzc/HTCpkZjssJvWjucv+cv7J3HSIlLuLcGqbdpAF3V rx9m6Q16Dajil0BRXuRwBf1v+0tmKsFla0ozxQ2Dn1RvaUvfifX2sXElEdm0S1i44nL4 zP3hFxdgKroCcry4RtBk8zqxfQ7l3ZNKJt592qCge5QIMS8x0kRhhDUaFxWL6uO5w7sv mwlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780488342; x=1781093142; 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=PLQBi3p/STOflwolOUK1HLMGxOxvuMfkgcQrxHmBPNjYx9ZCX5zMiFu+pkGpubElBJ ctfGsJP1HeFVOtZACXXeTa4ME+uPuhGCywCcJh1U349j3jFs2/nkk+vzDDLvDdLg/gjO cLFBlDbsslFJ12jx6u0GtxQvayzECruGho4EGVy8fn+YDlWRXHfMfaotwlAggR9P+h4x usCWpYyIjgla4JS9mzagQTzvuN2u0cxxAOD2sliCEbh3ExOYLxouHU6MTUzQdHI/U8i2 gc7jEQtZLQZ26i/Y0bg6IQlrMDeccTKzgWMdeWK5zHeT8Nmnlfto86cqrMBixm80xPth 5/pQ== X-Forwarded-Encrypted: i=1; AFNElJ8QS/X+opiHXxl3k0RjbjypJpfjCes6htS7AVisGa0vCygQ8M3DmgXTFoMMMlDB7Ox6X3zov6X0ICp3nQk=@vger.kernel.org X-Gm-Message-State: AOJu0YzuctAnLrKvKZ7hG8ibbbcFJyCwwwCKa69GshuS7HE8YoTZS0UR gtpq1+Xf9MMVdGTTRbd9JcIXJviCejFX1gkEJ1z9gjRsk4Pod9bujkLL X-Gm-Gg: Acq92OFf3S42QoiZJT3KSuQGpze3q7SnTpHc+pErOsOS/+hL3ZjFyNdCSlqQD2/2L4w WwhXQJkf4/nXTZ3nzfwg3q5hVYRACxcbQoG3PeP4S9YXeZ0JVQOzthXA5IWEcCl8eoQeIItvkoA UpYQ38lNZ/0RAiN5WCh3mpliB4pV6/RkH33QizQtqagXYjj96+rvHcTiQrUDS3uG7px72f+q3cn 5Lc7EM4xBYGiflU0IZeT30FlkPYtrIy5fTWBvQJPGPpj0be4OTlarODtG6ACM98adlJMqiLx7fN TpyCbrnLvoIcOvpcuYT5o0+NaXFdrpKYLwZmCsZFVl41v5A4YbsLdh4VXaCQtc6JD2tOBovj2I8 fMf9/swdeoWhS85bpy9irWLlqPwjwyxJTniLgZ7Ei3xwVP9RSQ4BHwbiMZ9JiQFBXwsQLOt7akG N6OHsoVtv62oJb7nj2woAHWBD9H+lROFM= X-Received: by 2002:a05:6a00:3288:b0:82c:ebae:3cb with SMTP id d2e1a72fcca58-84284f0d090mr2886891b3a.43.1780488341967; Wed, 03 Jun 2026 05:05:41 -0700 (PDT) Received: from lgs.. ([101.76.249.46]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84282372868sm3230422b3a.17.2026.06.03.05.05.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 05:05:41 -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: Wed, 3 Jun 2026 20:04:43 +0800 Message-ID: <20260603120443.1394044-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