lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <56d545ff-3b72-430b-86e9-fd630dbac942@suse.com>
Date: Thu, 13 Nov 2025 07:37:33 +1030
From: Qu Wenruo <wqu@...e.com>
To: Daniel Vacek <neelx@...e.com>, Chris Mason <clm@...com>,
 Josef Bacik <josef@...icpanda.com>, David Sterba <dsterba@...e.com>
Cc: linux-btrfs@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v6 4/8] btrfs: add orig_logical to btrfs_bio



在 2025/11/13 06:06, Daniel Vacek 写道:
> From: Josef Bacik <josef@...icpanda.com>
> 
> 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.

We have already btrfs_bio::csum_saved_iter, we can just reuse it to grab 
logical bytenr by csum_saved_iter->bi_iter.bi_sector.

Although that member is only for data writes with data checksum, it's 
not hard to adapt it for encryption.

But in that case, we may want to rename that member to something more 
generic, maybe like write_saved_iter?

Thanks,
Qu

> 
> Signed-off-by: Josef Bacik <josef@...icpanda.com>
> ---
> No code changes other than context since v5.
> ---
>   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 a69174b2b6b6..aba452dd9904 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 = orig_bbio->ordered;
> +		bbio->orig_logical = orig_bbio->orig_logical;
> +		orig_bbio->orig_logical += map_length;
>   	}
>   	bbio->csum_search_commit_root = orig_bbio->csum_search_commit_root;
>   	atomic_inc(&orig_bbio->pending_ios);
> @@ -726,6 +728,14 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
>   		goto end_bbio;
>   	}
>   
> +	/*
> +	 * 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) == REQ_OP_WRITE && is_data_bbio(bbio))
> +		bbio->orig_logical = logical;
> +
>   	map_length = min(map_length, length);
>   	if (use_append)
>   		map_length = btrfs_append_map_length(bbio, map_length);
> diff --git a/fs/btrfs/bio.h b/fs/btrfs/bio.h
> index c5a6c66d51a0..5015e327dbd9 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;
> @@ -61,6 +62,7 @@ struct btrfs_bio {
>   			struct bio *csum_bio;
>   			struct bvec_iter csum_saved_iter;
>   			u64 orig_physical;
> +			u64 orig_logical;
>   		};
>   
>   		/* For metadata reads: parentness verification. */
> diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
> index 474949074da8..d2ecd26727ac 100644
> --- a/fs/btrfs/file-item.c
> +++ b/fs/btrfs/file-item.c
> @@ -812,7 +812,7 @@ int btrfs_csum_one_bio(struct btrfs_bio *bbio, struct bio *bio, bool async)
>   	if (!sums)
>   		return -ENOMEM;
>   
> -	sums->logical = bio->bi_iter.bi_sector << SECTOR_SHIFT;
> +	sums->logical = bbio->orig_logical;
>   	sums->len = bio->bi_iter.bi_size;
>   	INIT_LIST_HEAD(&sums->list);
>   	bbio->sums = sums;


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ