public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] t10-pi: reduce ref tag code duplication
@ 2026-04-03 18:51 Caleb Sander Mateos
  2026-04-05 23:43 ` Anuj gupta
  2026-04-06  6:24 ` Christoph Hellwig
  0 siblings, 2 replies; 3+ messages in thread
From: Caleb Sander Mateos @ 2026-04-03 18:51 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Caleb Sander Mateos, linux-kernel

t10_pi_ref_tag() and ext_pi_ref_tag() are identical except for the final
truncation of the ref tag to 32 or 48 bits. Factor out a helper
full_pi_ref_tag() to return the untruncated ref tag and use it in
t10_pi_ref_tag() and ext_pi_ref_tag().

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
---
 include/linux/t10-pi.h | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/linux/t10-pi.h b/include/linux/t10-pi.h
index 2c59fe3efcd4..c6fe5db47c7a 100644
--- a/include/linux/t10-pi.h
+++ b/include/linux/t10-pi.h
@@ -35,18 +35,23 @@ struct t10_pi_tuple {
 };
 
 #define T10_PI_APP_ESCAPE cpu_to_be16(0xffff)
 #define T10_PI_REF_ESCAPE cpu_to_be32(0xffffffff)
 
-static inline u32 t10_pi_ref_tag(struct request *rq)
+static inline u64 full_pi_ref_tag(struct request *rq)
 {
 	unsigned int shift = ilog2(queue_logical_block_size(rq->q));
 
 	if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) &&
 	    rq->q->limits.integrity.interval_exp)
 		shift = rq->q->limits.integrity.interval_exp;
-	return blk_rq_pos(rq) >> (shift - SECTOR_SHIFT) & 0xffffffff;
+	return blk_rq_pos(rq) >> (shift - SECTOR_SHIFT);
+}
+
+static inline u32 t10_pi_ref_tag(struct request *rq)
+{
+	return full_pi_ref_tag(rq) & 0xffffffff;
 }
 
 struct crc64_pi_tuple {
 	__be64 guard_tag;
 	__be16 app_tag;
@@ -62,14 +67,9 @@ static inline u64 lower_48_bits(u64 n)
 	return n & ((1ull << 48) - 1);
 }
 
 static inline u64 ext_pi_ref_tag(struct request *rq)
 {
-	unsigned int shift = ilog2(queue_logical_block_size(rq->q));
-
-	if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) &&
-	    rq->q->limits.integrity.interval_exp)
-		shift = rq->q->limits.integrity.interval_exp;
-	return lower_48_bits(blk_rq_pos(rq) >> (shift - SECTOR_SHIFT));
+	return lower_48_bits(full_pi_ref_tag(rq));
 }
 
 #endif
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] t10-pi: reduce ref tag code duplication
  2026-04-03 18:51 [PATCH] t10-pi: reduce ref tag code duplication Caleb Sander Mateos
@ 2026-04-05 23:43 ` Anuj gupta
  2026-04-06  6:24 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Anuj gupta @ 2026-04-05 23:43 UTC (permalink / raw)
  To: Caleb Sander Mateos; +Cc: Jens Axboe, linux-block, linux-kernel

Reviewed-by: Anuj Gupta <anuj20.g@samsung.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] t10-pi: reduce ref tag code duplication
  2026-04-03 18:51 [PATCH] t10-pi: reduce ref tag code duplication Caleb Sander Mateos
  2026-04-05 23:43 ` Anuj gupta
@ 2026-04-06  6:24 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2026-04-06  6:24 UTC (permalink / raw)
  To: Caleb Sander Mateos; +Cc: Jens Axboe, linux-block, linux-kernel

On Fri, Apr 03, 2026 at 12:51:00PM -0600, Caleb Sander Mateos wrote:
> t10_pi_ref_tag() and ext_pi_ref_tag() are identical except for the final
> truncation of the ref tag to 32 or 48 bits. Factor out a helper
> full_pi_ref_tag() to return the untruncated ref tag and use it in
> t10_pi_ref_tag() and ext_pi_ref_tag().
> 
> Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
> ---
>  include/linux/t10-pi.h | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/include/linux/t10-pi.h b/include/linux/t10-pi.h
> index 2c59fe3efcd4..c6fe5db47c7a 100644
> --- a/include/linux/t10-pi.h
> +++ b/include/linux/t10-pi.h
> @@ -35,18 +35,23 @@ struct t10_pi_tuple {
>  };
>  
>  #define T10_PI_APP_ESCAPE cpu_to_be16(0xffff)
>  #define T10_PI_REF_ESCAPE cpu_to_be32(0xffffffff)
>  
> -static inline u32 t10_pi_ref_tag(struct request *rq)
> +static inline u64 full_pi_ref_tag(struct request *rq)
>  {
>  	unsigned int shift = ilog2(queue_logical_block_size(rq->q));
>  
>  	if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) &&
>  	    rq->q->limits.integrity.interval_exp)
>  		shift = rq->q->limits.integrity.interval_exp;
> -	return blk_rq_pos(rq) >> (shift - SECTOR_SHIFT) & 0xffffffff;
> +	return blk_rq_pos(rq) >> (shift - SECTOR_SHIFT);
> +}

This should probably move abouve the struct t10_pi_tuple definition
so that we keep clear blocks for classic vs extended PI.

> +
> +static inline u32 t10_pi_ref_tag(struct request *rq)
> +{
> +	return full_pi_ref_tag(rq) & 0xffffffff;

Use lower_32_bits here to make it more clear and mirror the ext version?

Otherwise looks good.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-06  6:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-03 18:51 [PATCH] t10-pi: reduce ref tag code duplication Caleb Sander Mateos
2026-04-05 23:43 ` Anuj gupta
2026-04-06  6:24 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox