From: Caleb Sander Mateos <csander@purestorage.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
Christoph Hellwig <hch@infradead.org>,
Caleb Sander Mateos <csander@purestorage.com>,
Anuj Gupta <anuj20.g@samsung.com>
Subject: [PATCH v2] t10-pi: reduce ref tag code duplication
Date: Wed, 15 Apr 2026 15:08:47 -0600 [thread overview]
Message-ID: <20260415210847.1730016-1-csander@purestorage.com> (raw)
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>
Reviewed-by: Anuj Gupta <anuj20.g@samsung.com>
---
v2:
- Move full_pi_ref_tag() earlier (Christoph)
- Use lower_32_bits() (Christoph)
include/linux/t10-pi.h | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/include/linux/t10-pi.h b/include/linux/t10-pi.h
index 2c59fe3efcd4..b6c2496866ea 100644
--- a/include/linux/t10-pi.h
+++ b/include/linux/t10-pi.h
@@ -2,10 +2,11 @@
#ifndef _LINUX_T10_PI_H
#define _LINUX_T10_PI_H
#include <linux/types.h>
#include <linux/blk-mq.h>
+#include <linux/wordpart.h>
/*
* A T10 PI-capable target device can be formatted with different
* protection schemes. Currently 0 through 3 are defined:
*
@@ -23,10 +24,20 @@ enum t10_dif_type {
T10_PI_TYPE1_PROTECTION = 0x1,
T10_PI_TYPE2_PROTECTION = 0x2,
T10_PI_TYPE3_PROTECTION = 0x3,
};
+static inline u64 full_pi_ref_tag(const 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);
+}
+
/*
* T10 Protection Information tuple.
*/
struct t10_pi_tuple {
__be16 guard_tag; /* Checksum */
@@ -37,16 +48,11 @@ 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)
{
- 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 lower_32_bits(full_pi_ref_tag(rq));
}
struct crc64_pi_tuple {
__be64 guard_tag;
__be16 app_tag;
@@ -62,14 +68,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
next reply other threads:[~2026-04-15 21:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 21:08 Caleb Sander Mateos [this message]
2026-04-16 5:18 ` [PATCH v2] t10-pi: reduce ref tag code duplication Christoph Hellwig
2026-04-16 15:38 ` Caleb Sander Mateos
2026-04-17 7:56 ` Christoph Hellwig
2026-04-17 15:34 ` Caleb Sander Mateos
2026-04-17 16:52 ` Keith Busch
2026-04-17 20:39 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260415210847.1730016-1-csander@purestorage.com \
--to=csander@purestorage.com \
--cc=anuj20.g@samsung.com \
--cc=axboe@kernel.dk \
--cc=hch@infradead.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox