64-bit data integrity field support
Subsystems (5)
Keith Busch
maintainerRFC 1/7 block: support pi with extended metadata
In reply to Keith BuschThe nvme spec allows protection information formats with metadata extending beyond the pi field. Use the actual size of the metadata field for incrementing the protection buffer.
--- block/bio-integrity.c | 1 + block/t10-pi.c | 4 ++-- include/linux/blk-integrity.h | 1 + 3 files changed, 4 insertions(+), 2 deletions(-)
block/bio-integrity.c +1 -0
@@ -165,6 +165,7 @@ static blk_status_t bio_integrity_process(struct bio *bio, iter.disk_name = bio->bi_bdev->bd_disk->disk_name; iter.interval =1 << bi->interval_exp; + iter.tuple_size = bi->tuple_size; iter.seed = proc_iter->bi_sector; iter.prot_buf =bvec_virt (bip->bip_vec);
block/t10-pi.c +2 -2
@@ -44,7 +44,7 @@ static blk_status_t t10_pi_generate(struct blk_integrity_iter *iter, pi->ref_tag =0 ; iter->data_buf += iter->interval; - iter->prot_buf +=sizeof (struct t10_pi_tuple ); + iter->prot_buf += iter->tuple_size; iter->seed++; }
@@ -93,7 +93,7 @@ static blk_status_t t10_pi_verify(struct blk_integrity_iter *iter, next: iter->data_buf += iter->interval; - iter->prot_buf +=sizeof (struct t10_pi_tuple ); + iter->prot_buf += iter->tuple_size; iter->seed++; }
include/linux/blk-integrity.h +1 -0
@@ -19,6 +19,7 @@ struct blk_integrity_iter {sector_t seed;unsigned int data_size;unsigned short interval; +unsigned char tuple_size;const char *disk_name; };
Signature · 1 line
2.25.4
Keith Busch
maintainercover 64-bit data integrity field support
The NVM Express protocol added enhancements to the data integrity field formats beyond the T10 defined protection information. A detailed description of the new formats can be found in the NVMe's NVM Command Set Specification, section 5.2, available at:
https://nvmexpress.org/wp-content/uploads/NVM-Command-Set-Specification-1.0b-2021.12.18-Ratified.pdf
This series implements one possible new format: the CRC64 guard with 48-bit reference tags. This does not add support for the variable "storage tag" field.
The NVMe CRC64 parameters (from Rocksoft) were not implemented in the kernel, so a software implementation is included in this series based on the generated table. This series does not include any possible hardware excelleration (ex: x86's pclmulqdq), so it's not very high performant right now.
Keith Busch (7):
block: support pi with extended metadata
nvme: allow integrity on extended metadata formats
lib: add rocksoft model crc64
lib: add crc64 tests
asm-generic: introduce be48 unaligned accessors
block: add pi for nvme enhanced integrity
nvme: add support for enhanced metadata
block/Kconfig | 1 + block/bio-integrity.c | 1 + block/t10-pi.c | 198 +++++++++++++++++++++++++++++++- drivers/nvme/host/core.c | 167 ++++++++++++++++++++++----- drivers/nvme/host/nvme.h | 1 + include/asm-generic/unaligned.h | 26 +++++ include/linux/blk-integrity.h | 1 + include/linux/crc64.h | 2 + include/linux/nvme.h | 53 ++++++++- include/linux/t10-pi.h | 20 ++++ lib/Kconfig.debug | 3 + lib/Makefile | 1 + lib/crc64.c | 79 +++++++++++++ lib/gen_crc64table.c | 33 ++++-- lib/test_crc64.c | 68 +++++++++++ 15 files changed, 608 insertions(+), 46 deletions(-) create mode 100644 lib/test_crc64.c
Signature · 1 line
2.25.4
Keith Busch
maintainerRFC 2/7 nvme: allow integrity on extended metadata formats
The block integrity subsystem knows how to construct protection information buffers with metadata beyond the protection information fields. Remove the driver restriction.
Note, this can only work if the PI field appears first in the metadata, as the integrity subsystem doesn't update guard tags on preceding metadata.
--- drivers/nvme/host/core.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/nvme/host/core.c +2 -5
@@ -1726,12 +1726,9 @@ static int nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id) {struct nvme_ctrl *ctrl = ns->ctrl; -/* -* The PI implementation requires the metadata size to be equal to the -* t10 pi tuple size. -*/ ns->ms =le16_to_cpu (id->lbaf[id->flbas &NVME_NS_FLBAS_LBA_MASK ].ms); -if (ns->ms ==sizeof (struct t10_pi_tuple )) +if (id->dps &NVME_NS_DPS_PI_FIRST || + ns->ms ==sizeof (struct t10_pi_tuple )) ns->pi_type = id->dps &NVME_NS_DPS_PI_MASK ;else ns->pi_type =0 ;
Signature · 1 line
2.25.4
Keith Busch
maintainerRFC 4/7 lib: add crc64 tests
In reply to Keith BuschProvide a module to test the rocksoft crc64 calculations with well known inputs and exepected values.
--- lib/Kconfig.debug | 3 +++ lib/Makefile | 1 + lib/test_crc64.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 lib/test_crc64.c
lib/Kconfig.debug +3 -0
@@ -2212,6 +2212,9 @@ config TEST_UUID config TEST_XARRAY tristate "Test the XArray code at runtime" +config TEST_CRC64 + tristate "Test the crc64 code at runtime" + config TEST_OVERFLOW tristate "Test check_*_overflow() functions at runtime"
lib/Makefile +1 -0
@@ -102,6 +102,7 @@ obj-$(CONFIG_TEST_HMM) += test_hmm.o obj-$(CONFIG_TEST_FREE_PAGES) += test_free_pages.o obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o obj-$(CONFIG_TEST_REF_TRACKER) += test_ref_tracker.o +obj-$(CONFIG_TEST_CRC64) += test_crc64.o # # CFLAGS for compiling floating point code inside the kernel. x86/Makefile turns # off the generation of FPU/SSE* instructions for kernel proper but FPU_FLAGS
lib/test_crc64.c new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.25.4
Keith Busch
maintainerRFC 3/7 lib: add rocksoft model crc64
In reply to Keith BuschThe NVM Express specification extended data integrity fields to 64 bits using the Rocksoft^TM parameters. Add the poly (0xad93d23594c93659) to the crc64 table generation, and provide a library routine implementing the algorithm.
Since this model reflects inputs and outputs, a helper table and function are added to reverse bits of 8 and 64 bit values.
--- include/linux/crc64.h | 2 ++ lib/crc64.c | 79 +++++++++++++++++++++++++++++++++++++++++++ lib/gen_crc64table.c | 33 ++++++++++++------ 3 files changed, 103 insertions(+), 11 deletions(-)
include/linux/crc64.h +2 -0
@@ -8,4 +8,6 @@#include <linux/types.h> u64 __pure crc64_be (u64 crc,const void *p,size_t len); +u64 __pure crc64_rocksoft (u64 crc,const void *p,size_t len); +#endif /* _LINUX_CRC64_H */
lib/crc64.c +79 -0
88 lines not on this page · raw message
lib/gen_crc64table.c +22 -11
@@ -17,10 +17,12 @@#include <stdio.h> #define CRC64_ECMA182_POLY 0x42F0E1EBA9EA3693ULL +#define CRC64_ROCKSOFT_POLY 0xAD93D23594C93659ULLstatic uint64_t crc64_table[256 ] = {0 }; +static uint64_t crc64_rocksoft_table[256 ] = {0 }; -static void generate_crc64_table (void ) +static void generate_crc64_table (uint64_t table[256 ],uint64_t poly) {uint64_t i, j, c, crc;
@@ -30,26 +32,22 @@ static void generate_crc64_table(void)for (j =0 ; j <8 ; j++) {if ((crc ^ c) &0x8000000000000000ULL ) - crc = (crc <<1 ) ^CRC64_ECMA182_POLY ; + crc = (crc <<1 ) ^ poly;else crc <<=1 ; c <<=1 ; } - crc64_table[i] = crc; + table[i] = crc; } } -static void print_crc64_table (void ) +static void output_table (uint64_t table[256 ]) {int i; -printf ("/* this file is generated - do not edit */\n\n" ); -printf ("#include <linux/types.h>\n" ); -printf ("#include <linux/cache.h>\n\n" ); -printf ("static const u64 ____cacheline_aligned crc64table[256] = {\n" );for (i =0 ; i <256 ; i++) { -printf ("\t0x%016" PRIx64"ULL" , crc64_table[i]); +printf ("\t0x%016" PRIx64"ULL" , table[i]);if (i &0x1 )printf (",\n" );else
@@ -58,9 +56,22 @@ static void print_crc64_table(void)printf ("};\n" ); } +static void print_crc64_tables (void ) +{ +printf ("/* this file is generated - do not edit */\n\n" ); +printf ("#include <linux/types.h>\n" ); +printf ("#include <linux/cache.h>\n\n" ); +printf ("static const u64 ____cacheline_aligned crc64table[256] = {\n" ); +output_table (crc64_table); + +printf ("\nstatic const u64 ____cacheline_aligned crc64rocksofttable[256] = {\n" ); +output_table (crc64_rocksoft_table); +} +int main (int argc,char *argv[]) { -generate_crc64_table (); -print_crc64_table (); +generate_crc64_table (crc64_table,CRC64_ECMA182_POLY ); +generate_crc64_table (crc64_rocksoft_table,CRC64_ROCKSOFT_POLY ); +print_crc64_tables ();return 0 ; }
Signature · 1 line
2.25.4
Keith Busch
maintainerRFC 5/7 asm-generic: introduce be48 unaligned accessors
In reply to Keith BuschThe NVMe protocol extended data integrity fields with unaligned 48-bit reference tags. Provide some helper accessors in preparation for these.
--- include/asm-generic/unaligned.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
include/asm-generic/unaligned.h +26 -0
@@ -126,4 +126,30 @@ static inline void put_unaligned_le24(const u32 val, void *p)__put_unaligned_le24 (val, p); } +static inline void __put_unaligned_be48 (const u64 val,__u8 *p) +{ + *p++ = val >>40 ; + *p++ = val >>32 ; + *p++ = val >>24 ; + *p++ = val >>16 ; + *p++ = val >>8 ; + *p++ = val; +} + +static inline void put_unaligned_be48 (const u64 val,void *p) +{ +__put_unaligned_be48 (val, p); +} + +static inline u64 __get_unaligned_be48 (const u8 *p) +{ +return (u64 )p[0 ] <<40 | (u64 )p[1 ] <<32 | p[2 ] <<24 | + p[3 ] <<16 | p[4 ] <<8 | p[5 ]; +} + +static inline u64 get_unaligned_be48 (const void *p) +{ +return __get_unaligned_be48 (p); +} +#endif /* __ASM_GENERIC_UNALIGNED_H */
Signature · 1 line
2.25.4
Keith Busch
maintainerRFC 6/7 block: add pi for nvme enhanced integrity
In reply to Keith BuschThe NVMe specification defines larger data integrity formats beyond the t10 tuple. Add support for the specification defined CRC64 formats, assuming the reference tag does not need to be split with the "storage tag".
--- block/Kconfig | 1 + block/t10-pi.c | 194 +++++++++++++++++++++++++++++++++++++++++ include/linux/t10-pi.h | 20 +++++ 3 files changed, 215 insertions(+)
block/Kconfig +1 -0
@@ -63,6 +63,7 @@ config BLK_DEV_INTEGRITY_T10 tristate depends on BLK_DEV_INTEGRITY select CRC_T10DIF + select CRC64 config BLK_DEV_ZONED bool "Zoned block device support"
block/t10-pi.c +194 -0
206 lines not on this page · raw message
include/linux/t10-pi.h +20 -0
@@ -53,4 +53,24 @@ extern const struct blk_integrity_profile t10_pi_type1_ip;extern const struct blk_integrity_profile t10_pi_type3_crc;extern const struct blk_integrity_profile t10_pi_type3_ip; +struct nvme_crc64_pi_tuple { +__be64 guard_tag; +__be16 app_tag; +__u8 ref_tag[6 ]; +}; + +static inline u64 nvme_pi_extended_ref_tag (struct request *rq) +{ +unsigned int shift =ilog2 (queue_logical_block_size (rq->q)); + +#ifdef CONFIG_BLK_DEV_INTEGRITY +if (rq->q->integrity.interval_exp) + shift = rq->q->integrity.interval_exp; +#endif +return blk_rq_pos (rq) >> (shift -SECTOR_SHIFT ) &0xffffffffffffull ; +} + +extern const struct blk_integrity_profile nvme_pi_type1_crc64; +extern const struct blk_integrity_profile nvme_pi_type3_crc64; +#endif
Signature · 1 line
2.25.4
Keith Busch
maintainerRFC 7/7 nvme: add support for enhanced metadata
In reply to Keith BuschNVM Express ratified TP 4069 defines new protection information formats. Implement support for the CRC64 guard tags.
Since the block layer doesn't support variable length reference tags, driver support for the Storage Tag space is not supported at this time.
--- drivers/nvme/host/core.c | 164 +++++++++++++++++++++++++++++++++------ drivers/nvme/host/nvme.h | 1 + include/linux/nvme.h | 53 +++++++++++-- 3 files changed, 188 insertions(+), 30 deletions(-)
drivers/nvme/host/core.c +140 -24
@@ -882,6 +882,30 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req,return BLK_STS_OK ; } +static inline void nvme_set_ref_tag (struct nvme_ns *ns,struct nvme_command *cmnd, +struct request *req) +{ +u32 upper, lower; +u64 ref48; + +/* both rw and write zeroes share the same reftag format */ +switch (ns->guard_type) { +case NVME_NVM_NS_16B_GUARD : + cmnd->rw.reftag =cpu_to_le32 (t10_pi_ref_tag (req)); +break ; +case NVME_NVM_NS_64B_GUARD : + ref48 =nvme_pi_extended_ref_tag (req); + lower =lower_32_bits (ref48); + upper =upper_32_bits (ref48); + + cmnd->rw.reftag =cpu_to_le32 (lower); + cmnd->rw.cdw3 =cpu_to_le32 (upper); +break ; +default : +break ; + } +} +static inline blk_status_t nvme_setup_write_zeroes (struct nvme_ns *ns,struct request *req,struct nvme_command *cmnd) {
@@ -903,8 +927,7 @@ static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns,switch (ns->pi_type) {case NVME_NS_DPS_PI_TYPE1 :case NVME_NS_DPS_PI_TYPE2 : - cmnd->write_zeroes.reftag = -cpu_to_le32 (t10_pi_ref_tag (req)); +nvme_set_ref_tag (ns, cmnd, req);break ; } }
@@ -931,7 +954,8 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, cmnd->rw.opcode = op; cmnd->rw.flags =0 ; cmnd->rw.nsid =cpu_to_le32 (ns->head->ns_id); - cmnd->rw.rsvd2 =0 ; + cmnd->rw.cdw2 =0 ; + cmnd->rw.cdw3 =0 ; cmnd->rw.metadata =0 ; cmnd->rw.slba =cpu_to_le64 (nvme_sect_to_lba (ns,blk_rq_pos (req))); cmnd->rw.length =cpu_to_le16 ((blk_rq_bytes (req) >> ns->lba_shift) -1 );
@@ -965,7 +989,7 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,NVME_RW_PRINFO_PRCHK_REF ;if (op == nvme_cmd_zone_append) control |=NVME_RW_APPEND_PIREMAP ; - cmnd->rw.reftag =cpu_to_le32 (t10_pi_ref_tag (req)); +nvme_set_ref_tag (ns, cmnd, req);break ; } }
@@ -1619,33 +1643,58 @@ int nvme_getgeo(struct block_device *bdev, struct hd_geometry *geo) }#ifdef CONFIG_BLK_DEV_INTEGRITY -static void nvme_init_integrity (struct gendisk *disk,u16 ms,u8 pi_type, +static void nvme_init_integrity (struct gendisk *disk,struct nvme_ns *ns,u32 max_integrity_segments) {struct blk_integrity integrity = { }; -switch (pi_type) { +switch (ns->pi_type) {case NVME_NS_DPS_PI_TYPE3 : - integrity.profile = &t10_pi_type3_crc; - integrity.tag_size =sizeof (u16) +sizeof (u32); - integrity.flags |=BLK_INTEGRITY_DEVICE_CAPABLE ; +switch (ns->guard_type) { +case NVME_NVM_NS_16B_GUARD : + integrity.profile = &t10_pi_type3_crc; + integrity.tag_size =sizeof (u16) +sizeof (u32); + integrity.flags |=BLK_INTEGRITY_DEVICE_CAPABLE ; +break ; +case NVME_NVM_NS_64B_GUARD : + integrity.profile = &nvme_pi_type1_crc64; + integrity.tag_size =sizeof (u16) +6 ; + integrity.flags |=BLK_INTEGRITY_DEVICE_CAPABLE ; +break ; +default : + integrity.profile =NULL ; +break ; + }break ;case NVME_NS_DPS_PI_TYPE1 :case NVME_NS_DPS_PI_TYPE2 : - integrity.profile = &t10_pi_type1_crc; - integrity.tag_size =sizeof (u16); - integrity.flags |=BLK_INTEGRITY_DEVICE_CAPABLE ; +switch (ns->guard_type) { +case NVME_NVM_NS_16B_GUARD : + integrity.profile = &t10_pi_type1_crc; + integrity.tag_size =sizeof (u16); + integrity.flags |=BLK_INTEGRITY_DEVICE_CAPABLE ; +break ; +case NVME_NVM_NS_64B_GUARD : + integrity.profile = &nvme_pi_type1_crc64; + integrity.tag_size =sizeof (u16); + integrity.flags |=BLK_INTEGRITY_DEVICE_CAPABLE ; +break ; +default : + integrity.profile =NULL ; +break ; + }break ;default : integrity.profile =NULL ;break ; } - integrity.tuple_size = ms; + + integrity.tuple_size = ns->ms;blk_integrity_register (disk, &integrity);blk_queue_max_integrity_segments (disk->queue, max_integrity_segments); }#else -static void nvme_init_integrity (struct gendisk *disk,u16 ms,u8 pi_type, +static void nvme_init_integrity (struct gendisk *disk,struct nvme_ns *ns,u32 max_integrity_segments) { }
@@ -1722,17 +1771,75 @@ static int nvme_setup_streams_ns(struct nvme_ctrl *ctrl, struct nvme_ns *ns,return 0 ; } -static int nvme_configure_metadata (struct nvme_ns *ns,struct nvme_id_ns *id) +static int nvme_init_ms (struct nvme_ns *ns,struct nvme_id_ns *id) { +bool first = id->dps &NVME_NS_DPS_PI_FIRST ; +unsigned lbaf =nvme_lbaf_index (id->flbas);struct nvme_ctrl *ctrl = ns->ctrl; +struct nvme_command c = { }; +struct nvme_id_ns_nvm *nvm; +u8 pi_size =0 ; +int ret =0 ; +u32 elbaf; + + ns->ms =le16_to_cpu (id->lbaf[lbaf].ms); +if (!(ctrl->ctratt &NVME_CTRL_ATTR_ELBAS )) { + pi_size =sizeof (struct t10_pi_tuple ); + ns->guard_type =NVME_NVM_NS_16B_GUARD ; + goto set_pi; + } + + nvm =kzalloc (sizeof (*nvm),GFP_KERNEL ); +if (!nvm) +return -ENOMEM ; - ns->ms =le16_to_cpu (id->lbaf[id->flbas &NVME_NS_FLBAS_LBA_MASK ].ms); -if (id->dps &NVME_NS_DPS_PI_FIRST || - ns->ms ==sizeof (struct t10_pi_tuple )) + c.identify.opcode = nvme_admin_identify; + c.identify.nsid =cpu_to_le32 (ns->head->ns_id); + c.identify.cns =NVME_ID_CNS_CS_NS ; + c.identify.csi =NVME_CSI_NVM ; + + ret =nvme_submit_sync_cmd (ns->ctrl->admin_q, &c, nvm,sizeof (*nvm)); +if (ret) + goto free_data; + + elbaf =cpu_to_le32 (nvm->elbaf[lbaf]); + +/* no support for storage tag formats right now */ +if (nvme_elbaf_sts (elbaf)) + goto free_data; + + ns->guard_type =nvme_elbaf_guard_type (elbaf); +switch (ns->guard_type) { +case NVME_NVM_NS_64B_GUARD : + pi_size =sizeof (struct nvme_crc64_pi_tuple ); +break ; +case NVME_NVM_NS_16B_GUARD : + pi_size =sizeof (struct t10_pi_tuple ); +break ; +default : +break ; + } + +free_data: +kfree (nvm); +set_pi: +if (pi_size && (first || ns->ms == pi_size)) ns->pi_type = id->dps &NVME_NS_DPS_PI_MASK ;else ns->pi_type =0 ; +return ret; +} + +static int nvme_configure_metadata (struct nvme_ns *ns,struct nvme_id_ns *id) +{ +struct nvme_ctrl *ctrl = ns->ctrl; +int ret; + + ret =nvme_init_ms (ns, id); +if (ret) +return ret; + ns->features &= ~(NVME_NS_METADATA_SUPPORTED |NVME_NS_EXT_LBAS );if (!ns->ms || !(ctrl->ops->flags &NVME_F_METADATA_SUPPORTED ))return 0 ;
@@ -1850,7 +1957,7 @@ static void nvme_update_disk_info(struct gendisk *disk,if (ns->ms) {if (IS_ENABLED (CONFIG_BLK_DEV_INTEGRITY ) && (ns->features &NVME_NS_METADATA_SUPPORTED )) -nvme_init_integrity (disk, ns->ms, ns->pi_type, +nvme_init_integrity (disk, ns, ns->ctrl->max_integrity_segments);else if (!nvme_ns_has_pi (ns)) capacity =0 ;
@@ -1905,7 +2012,7 @@ static void nvme_set_chunk_sectors(struct nvme_ns *ns, struct nvme_id_ns *id)static int nvme_update_ns_info (struct nvme_ns *ns,struct nvme_id_ns *id) { -unsigned lbaf = id->flbas &NVME_NS_FLBAS_LBA_MASK ; +unsigned lbaf =nvme_lbaf_index (id->flbas);int ret;blk_mq_freeze_queue (ns->disk->queue);
@@ -2252,20 +2359,27 @@ static int nvme_configure_timestamp(struct nvme_ctrl *ctrl)return ret; } -static int nvme_configure_acre (struct nvme_ctrl *ctrl) +static int nvme_configure_host_options (struct nvme_ctrl *ctrl) {struct nvme_feat_host_behavior *host; +u8 acre =0 , lbafee =0 ;int ret;/* Don't bother enabling the feature if retry delay is not reported */ -if (!ctrl->crdt[0 ]) +if (ctrl->crdt[0 ]) + acre =NVME_ENABLE_ACRE ; +if (ctrl->ctratt &NVME_CTRL_ATTR_ELBAS ) + lbafee =NVME_ENABLE_LBAFEE ; + +if (!acre && !lbafee)return 0 ; host =kzalloc (sizeof (*host),GFP_KERNEL );if (!host)return 0 ; - host->acre =NVME_ENABLE_ACRE ; + host->acre = acre; + host->lbafee = lbafee; ret =nvme_set_features (ctrl,NVME_FEAT_HOST_BEHAVIOR ,0 , host,sizeof (*host),NULL );kfree (host);
@@ -3104,7 +3218,7 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl)if (ret <0 )return ret; - ret =nvme_configure_acre (ctrl); + ret =nvme_configure_host_options (ctrl);if (ret <0 )return ret;
@@ -4725,12 +4839,14 @@ static inline void _nvme_check_size(void)BUILD_BUG_ON (sizeof (struct nvme_id_ctrl ) !=NVME_IDENTIFY_DATA_SIZE );BUILD_BUG_ON (sizeof (struct nvme_id_ns ) !=NVME_IDENTIFY_DATA_SIZE );BUILD_BUG_ON (sizeof (struct nvme_id_ns_zns ) !=NVME_IDENTIFY_DATA_SIZE ); +BUILD_BUG_ON (sizeof (struct nvme_id_ns_nvm ) !=NVME_IDENTIFY_DATA_SIZE );BUILD_BUG_ON (sizeof (struct nvme_id_ctrl_zns ) !=NVME_IDENTIFY_DATA_SIZE );BUILD_BUG_ON (sizeof (struct nvme_id_ctrl_nvm ) !=NVME_IDENTIFY_DATA_SIZE );BUILD_BUG_ON (sizeof (struct nvme_lba_range_type ) !=64 );BUILD_BUG_ON (sizeof (struct nvme_smart_log ) !=512 );BUILD_BUG_ON (sizeof (struct nvme_dbbuf ) !=64 );BUILD_BUG_ON (sizeof (struct nvme_directive_cmd ) !=64 ); +BUILD_BUG_ON (sizeof (struct nvme_feat_host_behavior ) !=512 ); }
drivers/nvme/host/nvme.h +1 -0
@@ -455,6 +455,7 @@ struct nvme_ns {u16 sgs;u32 sws;u8 pi_type; +u8 guard_type;#ifdef CONFIG_BLK_DEV_ZONED u64 zsze;#endif
include/linux/nvme.h +47 -6
105 lines not on this page · raw message
Signature · 1 line
2.25.4
Re: [RFC 5/7] asm-generic: introduce be48 unaligned accessors
In reply to Keith BuschQuoted 6 lines · Keith Busch
The NVMe protocol extended data integrity fields with unaligned 48-bit reference tags. Provide some helper accessors in preparation for these.
Cc Arnd Bergmann <[email protected]>Signed-off-by Keith Busch <[email protected]>
For asm-generic:
I assume you are keeping this together with the rest of the series.
kernel test robot
build botRe: [RFC 7/7] nvme: add support for enhanced metadata
In reply to Keith Busch[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Keith,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on axboe-block/for-next]
[also build test WARNING on linux/master linus/master v5.17-rc1 next-20220124] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Keith-Busch/64-bit-data-integrity-field-support/20220125-000232 base: https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next config: x86_64-randconfig-s021-20220124 (https://download.01.org/0day-ci/archive/20220125/202201250552.LY0QkQNT-lkp(a)intel.com/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.4-dirty # https://github.com/0day-ci/linux/commit/15e965a414da565fcf7d7aa958a9850bb714db17 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Keith-Busch/64-bit-data-integrity-field-support/20220125-000232 git checkout 15e965a414da565fcf7d7aa958a9850bb714db17 # save the config file to linux build tree mkdir build_dir make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/nvme/host/
If you fix the issue, kindly add following tag as appropriate
sparse warnings: (new ones prefixed by >>)
>> drivers/nvme/host/core.c:1805:17: sparse: sparse: cast from restricted __le32 >> drivers/nvme/host/core.c:1805:15: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int [usertype] elbaf @@ got restricted __le32 [usertype] @@
drivers/nvme/host/core.c:1805:15: sparse: expected unsigned int [usertype] elbaf
drivers/nvme/host/core.c:1805:15: sparse: got restricted __le32 [usertype]
vim +1805 drivers/nvme/host/core.c
1773
1774 static int nvme_init_ms(struct nvme_ns *ns, struct nvme_id_ns *id)
1775 {
1776 bool first = id->dps & NVME_NS_DPS_PI_FIRST;
1777 unsigned lbaf = nvme_lbaf_index(id->flbas);
1778 struct nvme_ctrl *ctrl = ns->ctrl;
1779 struct nvme_command c = { };
1780 struct nvme_id_ns_nvm *nvm;
1781 u8 pi_size = 0;
1782 int ret = 0;
1783 u32 elbaf;
1784
1785 ns->ms = le16_to_cpu(id->lbaf[lbaf].ms);
1786 if (!(ctrl->ctratt & NVME_CTRL_ATTR_ELBAS)) {
1787 pi_size = sizeof(struct t10_pi_tuple);
1788 ns->guard_type = NVME_NVM_NS_16B_GUARD;
1789 goto set_pi;
1790 }
1791
1792 nvm = kzalloc(sizeof(*nvm), GFP_KERNEL);
1793 if (!nvm)
1794 return -ENOMEM;
1795
1796 c.identify.opcode = nvme_admin_identify;
1797 c.identify.nsid = cpu_to_le32(ns->head->ns_id);
1798 c.identify.cns = NVME_ID_CNS_CS_NS;
1799 c.identify.csi = NVME_CSI_NVM;
1800
1801 ret = nvme_submit_sync_cmd(ns->ctrl->admin_q, &c, nvm, sizeof(*nvm));
1802 if (ret)
1803 goto free_data;
1804
> 1805 elbaf = cpu_to_le32(nvm->elbaf[lbaf]);
1806
1807 /* no support for storage tag formats right now */
1808 if (nvme_elbaf_sts(elbaf))
1809 goto free_data;
1810
1811 ns->guard_type = nvme_elbaf_guard_type(elbaf);
1812 switch (ns->guard_type) {
1813 case NVME_NVM_NS_64B_GUARD:
1814 pi_size = sizeof(struct nvme_crc64_pi_tuple);
1815 break;
1816 case NVME_NVM_NS_16B_GUARD:
1817 pi_size = sizeof(struct t10_pi_tuple);
1818 break;
1819 default:
1820 break;
1821 }
1822
1823 free_data:
1824 kfree(nvm);
1825 set_pi:
1826 if (pi_size && (first || ns->ms == pi_size))
1827 ns->pi_type = id->dps & NVME_NS_DPS_PI_MASK;
1828 else
1829 ns->pi_type = 0;
1830
1831 return ret;
1832 }
1833
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Eric Biggers
maintainerRe: [RFC 3/7] lib: add rocksoft model crc64
In reply to Keith BuschQuoted 2 lines · Keith Busch
Since this model reflects inputs and outputs, a helper table and function are added to reverse bits of 8 and 64 bit values.
That's a silly way to do a bit-reflected CRC. The proper way to do it is to reflect the bytes too, so that the bits and bytes are ordered consistently, so explicitly reflecting the bits isn't needed. Most CRC-32's are bit-reflected, and they are usually implemented this way. E.g., see crc32_le() in lib/crc32.c.
Here's a Python script that shows that the Rocksoft CRC-64 can be computed without explicitly reversing the bits. It passes the tests from your patch 4:
COEFFS = [63, 61, 59, 58, 56, 55, 52, 49, 48, 47, 46, 44, 41, 37, 36, 34, 32,
31, 28, 26, 23, 22, 19, 16, 13, 12, 10, 9, 6, 4, 3, 0]
POLY = sum(1 << (63 - coeff) for coeff in COEFFS)
# Generate the table.
table = [0] * 256
for i in range(256):
crc = 0
byte = i
for j in range(8):
if ((crc ^ (byte >> j)) & 1) == 1:
crc = (crc >> 1) ^ POLY
else:
crc = crc >> 1
table[i] = crc# Compute the CRC-64 one byte at a time using the table. def crc64_rocksoft(data):
crc = 0xffffffffffffffff
for byte in data:
crc = (crc >> 8) ^ table[(crc & 0xff) ^ byte]
return crc ^ 0xffffffffffffffff# Tests
assert crc64_rocksoft(bytearray([0] * 4096)) == 0x6482D367EB22B64E
assert crc64_rocksoft(bytearray([255] * 4096)) == 0xC0DDBA7302ECA3AC
assert crc64_rocksoft(bytearray([i % 256 for i in range(4096)])) == 0x3E729F5F6750449C assert crc64_rocksoft(bytearray([(255-i) % 256 for i in range(4096)])) == 0x9A2DF64B8E9E517E
# Print the table.print(f'#define CRC64_ROCKSOFT_POLY 0x{POLY:016x}ULL') print('')print('static const u64 crc64_rocksoft_tab[] = {') for i in range(0, 256, 2):
print('\t', end='')
for j in range(i, i + 2):
print(f'0x{table[j]:016x}ULL,', end='')
if j != 1:
print(' ', end='')
print('')print('};')
kernel test robot
build botRe: [RFC 4/7] lib: add crc64 tests
In reply to Keith Busch[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Keith,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on axboe-block/for-next]
[also build test ERROR on linux/master linus/master v5.17-rc1 next-20220125] [cannot apply to arnd-asm-generic/master linux-nvme/for-next] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Keith-Busch/64-bit-data-integrity-field-support/20220125-000232 base: https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next config: nios2-randconfig-r015-20220125 (https://download.01.org/0day-ci/archive/20220125/202201252238.BlrXAZDf-lkp(a)intel.com/config) compiler: nios2-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/d45974b2937922cef5c20b3d5589364bc2d6cd8d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Keith-Busch/64-bit-data-integrity-field-support/20220125-000232 git checkout d45974b2937922cef5c20b3d5589364bc2d6cd8d
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=nios2 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
nios2-linux-ld: lib/test_crc64.o: in function `crc_tests':
>> test_crc64.c:(.text+0x78): undefined reference to `crc64_rocksoft' test_crc64.c:(.text+0x78): relocation truncated to fit: R_NIOS2_CALL26 against `crc64_rocksoft' >> nios2-linux-ld: test_crc64.c:(.text+0xe4): undefined reference to `crc64_rocksoft'
test_crc64.c:(.text+0xe4): relocation truncated to fit: R_NIOS2_CALL26 against `crc64_rocksoft'
nios2-linux-ld: test_crc64.c:(.text+0x158): undefined reference to crc64_rocksoft' test_crc64.c:(.text+0x158): relocation truncated to fit: R_NIOS2_CALL26 against crc64_rocksoft'
nios2-linux-ld: test_crc64.c:(.text+0x1c8): undefined reference to crc64_rocksoft' test_crc64.c:(.text+0x1c8): relocation truncated to fit: R_NIOS2_CALL26 against crc64_rocksoft'
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Keith Busch
maintainerRe: [RFC 3/7] lib: add rocksoft model crc64
In reply to Eric BiggersQuoted 11 lines · Eric Biggers
Quoted 2 lines · Keith Busch
Since this model reflects inputs and outputs, a helper table and function are added to reverse bits of 8 and 64 bit values.
That's a silly way to do a bit-reflected CRC. The proper way to do it is to reflect the bytes too, so that the bits and bytes are ordered consistently, so explicitly reflecting the bits isn't needed. Most CRC-32's are bit-reflected, and they are usually implemented this way. E.g., see
crc32_le()inlib/crc32.c.Here's a Python script that shows that the Rocksoft CRC-64 can be computed without explicitly reversing the bits. It passes the tests from your patch 4:
Thanks for the tip! I'll use that for the next version.
Quoted 11 lines · Keith Busch
The NVM Express protocol added enhancements to the data integrity field formats beyond the T10 defined protection information. A detailed description of the new formats can be found in the NVMe's NVM Command Set Specification, section 5.2, available at:
https://nvmexpress.org/wp-content/uploads/NVM-Command-Set-Specification-1.0b-2021.12.18-Ratified.pdf
This series implements one possible new format: the CRC64 guard with 48-bit reference tags. This does not add support for the variable "storage tag" field.
Quoted 6 lines
The NVMe CRC64 parameters (from Rocksoft) were not implemented in the kernel, so a software implementation is included in this series based on the generated table. This series does not include any possible hardware excelleration (ex: x86's pclmulqdq), so it's not very high performant right now.
Hi Keith,
Tested this on QEMU and (assuming we didnt implement the same bugs) it looks good functionally for separate metadata. However, it should also be able to support PRACT (i.e. pi strip/insert device-side) if nvme_ns_has_pi() is updated to also match on the 16 byte pi tuple. I made it work by just hitting it with a hammer and changing the comparison to hard-coded 16 bytes, but it should of course handle both cases.
Naveen and I will post the emulated implementation (that certainly isnt very high performant either) on qemu-block ASAP if others are interested in giving this a spin without having hardware available.
Keith Busch
maintainerQuoted 21 lines · Klaus Jensen
Quoted 11 lines · Keith Busch
The NVM Express protocol added enhancements to the data integrity field formats beyond the T10 defined protection information. A detailed description of the new formats can be found in the NVMe's NVM Command Set Specification, section 5.2, available at:
https://nvmexpress.org/wp-content/uploads/NVM-Command-Set-Specification-1.0b-2021.12.18-Ratified.pdf
This series implements one possible new format: the CRC64 guard with 48-bit reference tags. This does not add support for the variable "storage tag" field.
Quoted 6 lines
The NVMe CRC64 parameters (from Rocksoft) were not implemented in the kernel, so a software implementation is included in this series based on the generated table. This series does not include any possible hardware excelleration (ex: x86's pclmulqdq), so it's not very high performant right now.
Hi Keith,
Quoted 7 lines
Tested this on QEMU and (assuming we didnt implement the same bugs) it looks good functionally for separate metadata. However, it should also be able to support PRACT (i.e. pi strip/insert device-side) if
nvme_ns_has_pi()is updated to also match on the 16 byte pi tuple. I made it work by just hitting it with a hammer and changing the comparison to hard-coded 16 bytes, but it should of course handle both cases.
Thanks for checking with the qemu device!
I'll add the PRACT support for the next version, but will wait till next week to post it in case there's more feedback to consider.
Quoted 3 lines
Naveen and I will post the emulated implementation (that certainly isnt very high performant either) on qemu-block ASAP if others are interested in giving this a spin without having hardware available.
There are more features with this TP than are implemented here. I'm just enabling a product that only supports the 64-bit CRC with 0 STS, but I'm assuming your QEMU implementation may be more feature complete. If anyone is interested in 32-bit CRC or >0 STS, there's more work to follow on from here, but I currently don't have such a target to test against.