block: introduce BIP_CHECK_GUARD/REFTAG/APPTAG bip_flags
authorAnuj Gupta <anuj20.g@samsung.com>
Thu, 28 Nov 2024 11:22:37 +0000 (16:52 +0530)
committerJens Axboe <axboe@kernel.dk>
Mon, 23 Dec 2024 15:17:16 +0000 (08:17 -0700)
This patch introduces BIP_CHECK_GUARD/REFTAG/APPTAG bip_flags which
indicate how the hardware should check the integrity payload.
BIP_CHECK_GUARD/REFTAG are conversion of existing semantics, while
BIP_CHECK_APPTAG is a new flag. The driver can now just rely on block
layer flags, and doesn't need to know the integrity source. Submitter
of PI decides which tags to check. This would also give us a unified
interface for user and kernel generated integrity.

Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Kanchan Joshi <joshi.k@samsung.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Link: https://lore.kernel.org/r/20241128112240.8867-8-anuj20.g@samsung.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/bio-integrity.c
drivers/nvme/host/core.c
include/linux/bio-integrity.h

index f56d01cec689d596510dc7f01300d2cfdc5307b3..3bee43b87001832c67f5e6b92486b9b2585fe97a 100644 (file)
@@ -434,6 +434,11 @@ bool bio_integrity_prep(struct bio *bio)
        if (bi->csum_type == BLK_INTEGRITY_CSUM_IP)
                bip->bip_flags |= BIP_IP_CHECKSUM;
 
+       /* describe what tags to check in payload */
+       if (bi->csum_type)
+               bip->bip_flags |= BIP_CHECK_GUARD;
+       if (bi->flags & BLK_INTEGRITY_REF_TAG)
+               bip->bip_flags |= BIP_CHECK_REFTAG;
        if (bio_integrity_add_page(bio, virt_to_page(buf), len,
                        offset_in_page(buf)) < len) {
                printk(KERN_ERR "could not attach integrity payload\n");
index a970168a3014e665006ed5576017bd764652eaa8..766df130cd824aa26d3461e68cee8770fb0224f4 100644 (file)
@@ -1017,18 +1017,13 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
                        control |= NVME_RW_PRINFO_PRACT;
                }
 
-               switch (ns->head->pi_type) {
-               case NVME_NS_DPS_PI_TYPE3:
+               if (bio_integrity_flagged(req->bio, BIP_CHECK_GUARD))
                        control |= NVME_RW_PRINFO_PRCHK_GUARD;
-                       break;
-               case NVME_NS_DPS_PI_TYPE1:
-               case NVME_NS_DPS_PI_TYPE2:
-                       control |= NVME_RW_PRINFO_PRCHK_GUARD |
-                                       NVME_RW_PRINFO_PRCHK_REF;
+               if (bio_integrity_flagged(req->bio, BIP_CHECK_REFTAG)) {
+                       control |= NVME_RW_PRINFO_PRCHK_REF;
                        if (op == nvme_cmd_zone_append)
                                control |= NVME_RW_APPEND_PIREMAP;
                        nvme_set_ref_tag(ns, cmnd, req);
-                       break;
                }
        }
 
index 58ff9988433a9581eaa7a0f9909e24297648fac8..fe2bfe122db2bcd2aeb43d5efc711433037c71bc 100644 (file)
@@ -11,6 +11,9 @@ enum bip_flags {
        BIP_DISK_NOCHECK        = 1 << 3, /* disable disk integrity checking */
        BIP_IP_CHECKSUM         = 1 << 4, /* IP checksum */
        BIP_COPY_USER           = 1 << 5, /* Kernel bounce buffer in use */
+       BIP_CHECK_GUARD         = 1 << 6, /* guard check */
+       BIP_CHECK_REFTAG        = 1 << 7, /* reftag check */
+       BIP_CHECK_APPTAG        = 1 << 8, /* apptag check */
 };
 
 struct bio_integrity_payload {
@@ -31,7 +34,8 @@ struct bio_integrity_payload {
 };
 
 #define BIP_CLONE_FLAGS (BIP_MAPPED_INTEGRITY | BIP_CTRL_NOCHECK | \
-                        BIP_DISK_NOCHECK | BIP_IP_CHECKSUM)
+                        BIP_DISK_NOCHECK | BIP_IP_CHECKSUM | \
+                        BIP_CHECK_GUARD | BIP_CHECK_REFTAG | BIP_CHECK_APPTAG)
 
 #ifdef CONFIG_BLK_DEV_INTEGRITY