Subject: linux-next: manual merge of the block tree with the vfs-brauner tree

From: Mark Brown <[email-masked]>
Date: Thu, 5 Mar 2026 13:44:28 +0000

Hi all,

Today's linux-next merge of the block tree got a conflict in:

  block/t10-pi.c

between commit:

  179c2a24466b2 ("block: prepare generation / verification helpers for fs usage")

from the vfs-brauner tree and commit:

  7f0bc835bd428 ("blk-integrity: support arbitrary buffer alignment")

from the block tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

I don't have a huge degree of confidence in this merge as the block
change was quite large and the code is entirely unfamiliar to me.

diff --cc block/t10-pi.c
index d27be6041fd31,3a564c0e2fe80..0000000000000
--- a/block/t10-pi.c
+++ b/block/t10-pi.c
@@@ -372,83 -267,283 +267,284 @@@ static void blk_integrity_set(struct bl
  	}
  }
  
+ static blk_status_t blk_integrity_interval(struct blk_integrity_iter *iter,
+ 					   bool verify)
+ {
+ 	blk_status_t ret = BLK_STS_OK;
+ 	union pi_tuple tuple;
+ 	void *ptuple = &tuple;
+ 	struct bio_vec pbv;
+ 
+ 	blk_integrity_csum_offset(iter);
+ 	pbv = bvec_iter_bvec(iter->bip->bip_vec, iter->prot_iter);
+ 	if (pbv.bv_len >= iter->bi->pi_tuple_size) {
+ 		ptuple = bvec_kmap_local(&pbv);
+ 		bvec_iter_advance_single(iter->bip->bip_vec, &iter->prot_iter,
+ 				iter->bi->metadata_size - iter->bi->pi_offset);
+ 	} else if (verify) {
+ 		blk_integrity_copy_to_tuple(iter->bip, &iter->prot_iter,
+ 				ptuple, iter->bi->pi_tuple_size);
+ 	}
+ 
+ 	if (verify)
+ 		ret = blk_integrity_verify(iter, ptuple);
+ 	else
+ 		blk_integrity_set(iter, ptuple);
+ 
+ 	if (likely(ptuple != &tuple)) {
+ 		kunmap_local(ptuple);
+ 	} else if (!verify) {
+ 		blk_integrity_copy_from_tuple(iter->bip, &iter->prot_iter,
+ 				ptuple, iter->bi->pi_tuple_size);
+ 	}
+ 
+ 	iter->interval_remaining = 1 << iter->bi->interval_exp;
+ 	iter->csum = 0;
+ 	iter->seed++;
+ 	return ret;
+ }
+ 
 -static void blk_integrity_iterate(struct bio *bio, struct bvec_iter *data_iter,
 -				  bool verify)
++static blk_status_t blk_integrity_iterate(struct bio *bio, struct bvec_iter *data_iter,
++					  bool verify)
+ {
+ 	struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
+ 	struct bio_integrity_payload *bip = bio_integrity(bio);
+ 	struct blk_integrity_iter iter = {
+ 		.bio = bio,
+ 		.bip = bip,
+ 		.bi = bi,
+ 		.data_iter = *data_iter,
+ 		.prot_iter = bip->bip_iter,
+ 		.interval_remaining = 1 << bi->interval_exp,
+ 		.seed = data_iter->bi_sector,
+ 		.csum = 0,
+ 	};
+ 	blk_status_t ret = BLK_STS_OK;
+ 
+ 	while (iter.data_iter.bi_size && ret == BLK_STS_OK) {
+ 		struct bio_vec bv = bvec_iter_bvec(iter.bio->bi_io_vec,
+ 						   iter.data_iter);
+ 		void *kaddr = bvec_kmap_local(&bv);
+ 		void *data = kaddr;
+ 		unsigned int len;
+ 
+ 		bvec_iter_advance_single(iter.bio->bi_io_vec, &iter.data_iter,
+ 					 bv.bv_len);
+ 		while (bv.bv_len && ret == BLK_STS_OK) {
+ 			len = min(iter.interval_remaining, bv.bv_len);
+ 			blk_calculate_guard(&iter, data, len);
+ 			bv.bv_len -= len;
+ 			data += len;
+ 			iter.interval_remaining -= len;
+ 			if (!iter.interval_remaining)
+ 				ret = blk_integrity_interval(&iter, verify);
+ 		}
+ 		kunmap_local(kaddr);
+ 	}
+ 
 -	if (ret)
 -		bio->bi_status = ret;
++	return ret;
+ }
+ 
 -void blk_integrity_generate(struct bio *bio)
 +void bio_integrity_generate(struct bio *bio)
  {
  	struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
- 	struct bio_integrity_payload *bip = bio_integrity(bio);
- 	struct blk_integrity_iter iter;
- 	struct bvec_iter bviter;
- 	struct bio_vec bv;
  
- 	iter.disk_name = bio->bi_bdev->bd_disk->disk_name;
- 	iter.interval = 1 << bi->interval_exp;
- 	iter.seed = bio->bi_iter.bi_sector;
- 	iter.prot_buf = bvec_virt(bip->bip_vec);
- 	bio_for_each_segment(bv, bio, bviter) {
- 		void *kaddr = bvec_kmap_local(&bv);
- 
- 		iter.data_buf = kaddr;
- 		iter.data_size = bv.bv_len;
- 		switch (bi->csum_type) {
- 		case BLK_INTEGRITY_CSUM_CRC64:
- 			ext_pi_crc64_generate(&iter, bi);
- 			break;
- 		case BLK_INTEGRITY_CSUM_CRC:
- 		case BLK_INTEGRITY_CSUM_IP:
- 			t10_pi_generate(&iter, bi);
- 			break;
- 		default:
- 			break;
- 		}
- 		kunmap_local(kaddr);
+ 	switch (bi->csum_type) {
+ 	case BLK_INTEGRITY_CSUM_CRC64:
+ 	case BLK_INTEGRITY_CSUM_CRC:
+ 	case BLK_INTEGRITY_CSUM_IP:
+ 		blk_integrity_iterate(bio, &bio->bi_iter, false);
+ 		break;
+ 	default:
+ 		break;
  	}
  }
  
 -void blk_integrity_verify_iter(struct bio *bio, struct bvec_iter *saved_iter)
 +blk_status_t bio_integrity_verify(struct bio *bio, struct bvec_iter *saved_iter)
  {
  	struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
- 	struct bio_integrity_payload *bip = bio_integrity(bio);
- 	struct blk_integrity_iter iter;
- 	struct bvec_iter bviter;
- 	struct bio_vec bv;
  
- 	/*
- 	 * At the moment verify is called bi_iter has been advanced during split
- 	 * and completion, so use the copy created during submission here.
- 	 */
- 	iter.disk_name = bio->bi_bdev->bd_disk->disk_name;
- 	iter.interval = 1 << bi->interval_exp;
- 	iter.seed = saved_iter->bi_sector;
- 	iter.prot_buf = bvec_virt(bip->bip_vec);
- 	__bio_for_each_segment(bv, bio, bviter, *saved_iter) {
- 		void *kaddr = bvec_kmap_local(&bv);
- 		blk_status_t ret = BLK_STS_OK;
- 
- 		iter.data_buf = kaddr;
- 		iter.data_size = bv.bv_len;
- 		switch (bi->csum_type) {
- 		case BLK_INTEGRITY_CSUM_CRC64:
- 			ret = ext_pi_crc64_verify(&iter, bi);
- 			break;
- 		case BLK_INTEGRITY_CSUM_CRC:
- 		case BLK_INTEGRITY_CSUM_IP:
- 			ret = t10_pi_verify(&iter, bi);
- 			break;
- 		default:
- 			break;
- 		}
- 		kunmap_local(kaddr);
- 
- 		if (ret)
- 			return ret;
+ 	switch (bi->csum_type) {
+ 	case BLK_INTEGRITY_CSUM_CRC64:
+ 	case BLK_INTEGRITY_CSUM_CRC:
+ 	case BLK_INTEGRITY_CSUM_IP:
 -		blk_integrity_iterate(bio, saved_iter, true);
++		return blk_integrity_iterate(bio, saved_iter, true);
+ 		break;
+ 	default:
+ 		break;
  	}
 +
 +	return BLK_STS_OK;
  }
  
- void blk_integrity_prepare(struct request *rq)
+ /*
+  * Advance @iter past the protection offset for protection formats that
+  * contain front padding on the metadata region.
+  */
+ static void blk_pi_advance_offset(struct blk_integrity *bi,
+ 				  struct bio_integrity_payload *bip,
+ 				  struct bvec_iter *iter)
+ {
+ 	unsigned int offset = bi->pi_offset;
+ 
+ 	while (offset > 0) {
+ 		struct bio_vec bv = mp_bvec_iter_bvec(bip->bip_vec, *iter);
+ 		unsigned int len = min(bv.bv_len, offset);
+ 
+ 		bvec_iter_advance_single(bip->bip_vec, iter, len);
+ 		offset -= len;
+ 	}
+ }
+ 
+ static void *blk_tuple_remap_begin(union pi_tuple *tuple,
+ 				   struct blk_integrity *bi,
+ 				   struct bio_integrity_payload *bip,
+ 				   struct bvec_iter *iter)
+ {
+ 	struct bvec_iter titer;
+ 	struct bio_vec pbv;
+ 
+ 	blk_pi_advance_offset(bi, bip, iter);
+ 	pbv = bvec_iter_bvec(bip->bip_vec, *iter);
+ 	if (likely(pbv.bv_len >= bi->pi_tuple_size))
+ 		return bvec_kmap_local(&pbv);
+ 
+ 	/*
+ 	 * We need to preserve the state of the original iter for the
+ 	 * copy_from_tuple at the end, so make a temp iter for here.
+ 	 */
+ 	titer = *iter;
+ 	blk_integrity_copy_to_tuple(bip, &titer, tuple, bi->pi_tuple_size);
+ 	return tuple;
+ }
+ 
+ static void blk_tuple_remap_end(union pi_tuple *tuple, void *ptuple,
+ 				struct blk_integrity *bi,
+ 				struct bio_integrity_payload *bip,
+ 				struct bvec_iter *iter)
+ {
+ 	unsigned int len = bi->metadata_size - bi->pi_offset;
+ 
+ 	if (likely(ptuple != tuple)) {
+ 		kunmap_local(ptuple);
+ 	} else {
+ 		blk_integrity_copy_from_tuple(bip, iter, ptuple,
+ 				bi->pi_tuple_size);
+ 		len -= bi->pi_tuple_size;
+ 	}
+ 
+ 	bvec_iter_advance(bip->bip_vec, iter, len);
+ }
+ 
+ static void blk_set_ext_unmap_ref(struct crc64_pi_tuple *pi, u64 virt,
+ 				  u64 ref_tag)
+ {
+ 	u64 ref = get_unaligned_be48(&pi->ref_tag);
+ 
+ 	if (ref == lower_48_bits(ref_tag) && ref != lower_48_bits(virt))
+ 		put_unaligned_be48(virt, pi->ref_tag);
+ }
+ 
+ static void blk_set_t10_unmap_ref(struct t10_pi_tuple *pi, u32 virt,
+ 				  u32 ref_tag)
+ {
+ 	u32 ref = get_unaligned_be32(&pi->ref_tag);
+ 
+ 	if (ref == ref_tag && ref != virt)
+ 		put_unaligned_be32(virt, &pi->ref_tag);
+ }
+ 
+ static void blk_reftag_remap_complete(struct blk_integrity *bi,
+ 				      union pi_tuple *tuple, u64 virt, u64 ref)
+ {
+ 	switch (bi->csum_type) {
+ 	case BLK_INTEGRITY_CSUM_CRC64:
+ 		blk_set_ext_unmap_ref(&tuple->crc64_pi, virt, ref);
+ 		break;
+ 	case BLK_INTEGRITY_CSUM_CRC:
+ 	case BLK_INTEGRITY_CSUM_IP:
+ 		blk_set_t10_unmap_ref(&tuple->t10_pi, virt, ref);
+ 		break;
+ 	default:
+ 		WARN_ON_ONCE(1);
+ 		break;
+ 	}
+ }
+ 
+ static void blk_set_ext_map_ref(struct crc64_pi_tuple *pi, u64 virt,
+ 				u64 ref_tag)
+ {
+ 	u64 ref = get_unaligned_be48(&pi->ref_tag);
+ 
+ 	if (ref == lower_48_bits(virt) && ref != ref_tag)
+ 		put_unaligned_be48(ref_tag, pi->ref_tag);
+ }
+ 
+ static void blk_set_t10_map_ref(struct t10_pi_tuple *pi, u32 virt, u32 ref_tag)
+ {
+ 	u32 ref = get_unaligned_be32(&pi->ref_tag);
+ 
+ 	if (ref == virt && ref != ref_tag)
+ 		put_unaligned_be32(ref_tag, &pi->ref_tag);
+ }
+ 
+ static void blk_reftag_remap_prepare(struct blk_integrity *bi,
+ 				     union pi_tuple *tuple,
+ 				     u64 virt, u64 ref)
+ {
+ 	switch (bi->csum_type) {
+ 	case BLK_INTEGRITY_CSUM_CRC64:
+ 		blk_set_ext_map_ref(&tuple->crc64_pi, virt, ref);
+ 		break;
+ 	case BLK_INTEGRITY_CSUM_CRC:
+ 	case BLK_INTEGRITY_CSUM_IP:
+ 		blk_set_t10_map_ref(&tuple->t10_pi, virt, ref);
+ 		break;
+ 	default:
+ 		WARN_ON_ONCE(1);
+ 		break;
+ 	}
+ }
+ 
+ static void __blk_reftag_remap(struct bio *bio, struct blk_integrity *bi,
+ 			       unsigned *intervals, u64 *ref, bool prep)
+ {
+ 	struct bio_integrity_payload *bip = bio_integrity(bio);
+ 	struct bvec_iter iter = bip->bip_iter;
+ 	u64 virt = bip_get_seed(bip);
+ 	union pi_tuple *ptuple;
+ 	union pi_tuple tuple;
+ 
+ 	if (prep && bip->bip_flags & BIP_MAPPED_INTEGRITY) {
+ 		*ref += bio->bi_iter.bi_size >> bi->interval_exp;
+ 		return;
+ 	}
+ 
+ 	while (iter.bi_size && *intervals) {
+ 		ptuple = blk_tuple_remap_begin(&tuple, bi, bip, &iter);
+ 
+ 		if (prep)
+ 			blk_reftag_remap_prepare(bi, ptuple, virt, *ref);
+ 		else
+ 			blk_reftag_remap_complete(bi, ptuple, virt, *ref);
+ 
+ 		blk_tuple_remap_end(&tuple, ptuple, bi, bip, &iter);
+ 		(*intervals)--;
+ 		(*ref)++;
+ 		virt++;
+ 	}
+ 
+ 	if (prep)
+ 		bip->bip_flags |= BIP_MAPPED_INTEGRITY;
+ }
+ 
+ static void blk_integrity_remap(struct request *rq, unsigned int nr_bytes,
+ 				bool prep)
  {
  	struct blk_integrity *bi = &rq->q->limits.integrity;
+ 	u64 ref = blk_rq_pos(rq) >> (bi->interval_exp - SECTOR_SHIFT);
+ 	unsigned intervals = nr_bytes >> bi->interval_exp;
+ 	struct bio *bio;
  
  	if (!(bi->flags & BLK_INTEGRITY_REF_TAG))
  		return;