block: introduce BIP_CHECK_GUARD/REFTAG/APPTAG bip_flags

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>
This commit is contained in:
Anuj Gupta 2024-11-28 16:52:37 +05:30 committed by Jens Axboe
parent 4dde0cc445
commit 2ce55b4955
3 changed files with 13 additions and 9 deletions

View File

@ -434,6 +434,11 @@ bool bio_integrity_prep(struct bio *bio)
if (bi->csum_type == BLK_INTEGRITY_CSUM_IP) if (bi->csum_type == BLK_INTEGRITY_CSUM_IP)
bip->bip_flags |= BIP_IP_CHECKSUM; 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, if (bio_integrity_add_page(bio, virt_to_page(buf), len,
offset_in_page(buf)) < len) { offset_in_page(buf)) < len) {
printk(KERN_ERR "could not attach integrity payload\n"); printk(KERN_ERR "could not attach integrity payload\n");

View File

@ -1017,18 +1017,13 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
control |= NVME_RW_PRINFO_PRACT; control |= NVME_RW_PRINFO_PRACT;
} }
switch (ns->head->pi_type) { if (bio_integrity_flagged(req->bio, BIP_CHECK_GUARD))
case NVME_NS_DPS_PI_TYPE3:
control |= NVME_RW_PRINFO_PRCHK_GUARD; control |= NVME_RW_PRINFO_PRCHK_GUARD;
break; if (bio_integrity_flagged(req->bio, BIP_CHECK_REFTAG)) {
case NVME_NS_DPS_PI_TYPE1: control |= NVME_RW_PRINFO_PRCHK_REF;
case NVME_NS_DPS_PI_TYPE2:
control |= NVME_RW_PRINFO_PRCHK_GUARD |
NVME_RW_PRINFO_PRCHK_REF;
if (op == nvme_cmd_zone_append) if (op == nvme_cmd_zone_append)
control |= NVME_RW_APPEND_PIREMAP; control |= NVME_RW_APPEND_PIREMAP;
nvme_set_ref_tag(ns, cmnd, req); nvme_set_ref_tag(ns, cmnd, req);
break;
} }
} }

View File

@ -11,6 +11,9 @@ enum bip_flags {
BIP_DISK_NOCHECK = 1 << 3, /* disable disk integrity checking */ BIP_DISK_NOCHECK = 1 << 3, /* disable disk integrity checking */
BIP_IP_CHECKSUM = 1 << 4, /* IP checksum */ BIP_IP_CHECKSUM = 1 << 4, /* IP checksum */
BIP_COPY_USER = 1 << 5, /* Kernel bounce buffer in use */ 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 { struct bio_integrity_payload {
@ -31,7 +34,8 @@ struct bio_integrity_payload {
}; };
#define BIP_CLONE_FLAGS (BIP_MAPPED_INTEGRITY | BIP_CTRL_NOCHECK | \ #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 #ifdef CONFIG_BLK_DEV_INTEGRITY