From nobody Tue Dec 2 02:42:58 2025 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 5AD3221ABA2 for ; Tue, 18 Nov 2025 16:01:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763481665; cv=none; b=gimF4WNZOOobxvd0ShBLrT3dV9aUt0QL+ojxSZzdzZtautkyY5aeCAs6uRccrvQLi/NLY120Brjs4+9J80mqYkVzhiktg0XidlzSMXuEng1sFUAcA5DEYQgOAFPmHgYm0izikc1q1R8Jqkpk9SCLhVaSlt/GB53Eow+G/iDOv9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763481665; c=relaxed/simple; bh=Nzhid2/pJpHrx5bd6hwPpov67PXovshnomGwlX0XCu8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dfLAPCJ036veS9YOPmoQKmHiW4x01e+x/2CQ29woOHUx+SAc2GQPGbcKXuqJIYJUdm6/XoEk+NjDZRSB9VhUsVp2WdK9iQLOU6VlVL/arSaQcIEm8VuEpMKRySm9H5L5GrPqioiD0QKBXuwpeYgfIV0+F2HaqympB6NFuiZHpsY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B2B371FF82; Tue, 18 Nov 2025 16:01:01 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 996483EA61; Tue, 18 Nov 2025 16:01:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id GLHpJD2YHGkSWgAAD6G6ig (envelope-from ); Tue, 18 Nov 2025 16:01:01 +0000 From: Daniel Vacek To: Chris Mason , Josef Bacik , David Sterba Cc: Daniel Vacek , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Daniel Vacek Subject: [PATCH v7 3/6] btrfs: add orig_logical to btrfs_bio Date: Tue, 18 Nov 2025 17:00:38 +0100 Message-ID: <20251118160043.3005684-4-neelx@suse.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251118160043.3005684-1-neelx@suse.com> References: <20251118160043.3005684-1-neelx@suse.com> 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 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[]; TAGGED_RCPT(0.00)[] X-Rspamd-Queue-Id: B2B371FF82 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Spam-Flag: NO X-Spam-Score: -4.00 Content-Type: text/plain; charset="utf-8" From: Josef Bacik When checksumming the encrypted bio on writes we need to know which logical address this checksum is for. At the point where we get the encrypted bio the bi_sector is the physical location on the target disk, so we need to save the original logical offset in the btrfs_bio. Then we can use this when csum'ing the bio instead of the bio->iter.bi_sector. Signed-off-by: Josef Bacik Signed-off-by: Daniel Vacek --- fs/btrfs/bio.c | 10 ++++++++++ fs/btrfs/bio.h | 2 ++ fs/btrfs/file-item.c | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index 1b38e3ee0a33..4a7bef895b97 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -94,6 +94,8 @@ static struct btrfs_bio *btrfs_split_bio(struct btrfs_fs_= info *fs_info, if (bbio_has_ordered_extent(bbio)) { refcount_inc(&orig_bbio->ordered->refs); bbio->ordered =3D orig_bbio->ordered; + bbio->orig_logical =3D orig_bbio->orig_logical; + orig_bbio->orig_logical +=3D map_length; } bbio->csum_search_commit_root =3D orig_bbio->csum_search_commit_root; atomic_inc(&orig_bbio->pending_ios); @@ -765,6 +767,14 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio,= int mirror_num) goto end_bbio; } =20 + /* + * For fscrypt writes we will get the encrypted bio after we've + * remapped our bio to the physical disk location, so we need to + * save the original bytenr so we know what we're checksumming. + */ + if (bio_op(bio) =3D=3D REQ_OP_WRITE && is_data_bbio(bbio)) + bbio->orig_logical =3D logical; + map_length =3D min(map_length, length); if (use_append) map_length =3D btrfs_append_map_length(bbio, map_length); diff --git a/fs/btrfs/bio.h b/fs/btrfs/bio.h index 035145909b00..56279b7f3b2a 100644 --- a/fs/btrfs/bio.h +++ b/fs/btrfs/bio.h @@ -52,6 +52,7 @@ struct btrfs_bio { * - pointer to the checksums for this bio * - original physical address from the allocator * (for zone append only) + * - original logical address, used for checksumming fscrypt bios. */ struct { struct btrfs_ordered_extent *ordered; @@ -60,6 +61,7 @@ struct btrfs_bio { struct completion csum_done; struct bvec_iter csum_saved_iter; u64 orig_physical; + u64 orig_logical; }; =20 /* For metadata reads: parentness verification. */ diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index b17632ea085f..14e5257f0f04 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -824,7 +824,7 @@ int btrfs_csum_one_bio(struct btrfs_bio *bbio, bool asy= nc) if (!sums) return -ENOMEM; =20 - sums->logical =3D bio->bi_iter.bi_sector << SECTOR_SHIFT; + sums->logical =3D bbio->orig_logical; sums->len =3D bio->bi_iter.bi_size; INIT_LIST_HEAD(&sums->list); bbio->sums =3D sums; --=20 2.51.0