hw/nvme: bug fixes and doc update
A message that is not in the archive (sent off-list or not yet received): CGME20230807160836epcas5p34398954fecd7388469012404b09b78f9@epcas5p3.samsung.com
cover hw/nvme: bug fixes and doc update
This series fixes two bugs
1. CRC64 generation when metadata buffer is used.
2. Protection information disable check for Type 3 protection.
This series also updates the documentaion for pi (protection information), and adds missing pif (protection information format) entry.
Ankit Kumar (3):
hw/nvme: fix CRC64 for guard tag
hw/nvme: fix disable pi checks for Type 3 protection
docs: update hw/nvme documentation for protection information
docs/system/devices/nvme.rst | 10 +++++++--- hw/nvme/dif.c | 9 +++++---- 2 files changed, 12 insertions(+), 7 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/3 hw/nvme: fix CRC64 for guard tag
The nvme CRC64 generator expects the caller to pass inverted seed value. Pass inverted crc value for metadata buffer.
--- hw/nvme/dif.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/nvme/dif.c +2 -2
@@ -115,7 +115,7 @@ static void nvme_dif_pract_generate_dif_crc64(NvmeNamespace *ns, uint8_t *buf,uint64_t crc =crc64_nvme (~0ULL , buf, ns->lbasz);if (pil) { - crc =crc64_nvme (crc, mbuf, pil); + crc =crc64_nvme (~crc, mbuf, pil); } dif->g64.guard =cpu_to_be64 (crc);
@@ -246,7 +246,7 @@ static uint16_t nvme_dif_prchk_crc64(NvmeNamespace *ns, NvmeDifTuple *dif,uint64_t crc =crc64_nvme (~0ULL , buf, ns->lbasz);if (pil) { - crc =crc64_nvme (crc, mbuf, pil); + crc =crc64_nvme (~crc, mbuf, pil); }trace_pci_nvme_dif_prchk_guard_crc64 (be64_to_cpu (dif->g64.guard), crc);
Signature · 1 line
2.25.1
Re: [PATCH 1/3] hw/nvme: fix CRC64 for guard tag
Quoted 33 lines · Ankit Kumar
The nvme CRC64 generator expects the caller to pass inverted seed value. Pass inverted crc value for metadata buffer.
Signed-off-by Ankit Kumar <[email protected]>--- hw/nvme/dif.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/nvme/dif.c +2
-2@@ -115,7 +115,7 @@ static void nvme_dif_pract_generate_dif_crc64(NvmeNamespace *ns, uint8_t *buf,uint64_t crc =crc64_nvme (~0ULL , buf, ns->lbasz);if (pil) { - crc =crc64_nvme (crc, mbuf, pil); + crc =crc64_nvme (~crc, mbuf, pil); } dif->g64.guard =cpu_to_be64 (crc);@@ -246,7 +246,7 @@ static uint16_t nvme_dif_prchk_crc64(NvmeNamespace *ns, NvmeDifTuple *dif,uint64_t crc =crc64_nvme (~0ULL , buf, ns->lbasz);if (pil) { - crc =crc64_nvme (crc, mbuf, pil); + crc =crc64_nvme (~crc, mbuf, pil); }trace_pci_nvme_dif_prchk_guard_crc64 (be64_to_cpu (dif->g64.guard), crc);Signature · 1 line
2.25.1
Good catch, thanks!
PATCH 2/3 hw/nvme: fix disable pi checks for Type 3 protection
In reply to Ankit KumarAs per the NVM command set specification, the protection information checks for Type 3 protection are disabled, only when both application and reference tag have all bits set to 1.
--- hw/nvme/dif.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/nvme/dif.c +3 -2
@@ -157,7 +157,8 @@ static uint16_t nvme_dif_prchk_crc16(NvmeNamespace *ns, NvmeDifTuple *dif, {switch (NVME_ID_NS_DPS_TYPE (ns->id_ns.dps)) {case NVME_ID_NS_DPS_TYPE_3 : -if (be32_to_cpu (dif->g16.reftag) !=0xffffffff ) { +if ((be32_to_cpu (dif->g16.reftag) !=0xffffffff ) || + (be16_to_cpu (dif->g16.apptag) !=0xffff )) {break ; }
@@ -225,7 +226,7 @@ static uint16_t nvme_dif_prchk_crc64(NvmeNamespace *ns, NvmeDifTuple *dif,switch (NVME_ID_NS_DPS_TYPE (ns->id_ns.dps)) {case NVME_ID_NS_DPS_TYPE_3 : -if (r !=0xffffffffffff ) { +if (r !=0xffffffffffff || (be16_to_cpu (dif->g64.apptag) !=0xffff )) {break ; }
Signature · 1 line
2.25.1
Re: [PATCH 2/3] hw/nvme: fix disable pi checks for Type 3 protection
Quoted 14 lines · Ankit Kumar
As per the NVM command set specification, the protection information checks for Type 3 protection are disabled, only when both application and reference tag have all bits set to 1.
Signed-off-by Ankit Kumar <[email protected]>--- hw/nvme/dif.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/nvme/dif.c +0
-0
hw/nvme/dif.c static uint16_t nvme_dif_prchk_crc16(NvmeNamespace *ns, NvmeDifTuple *dif, · line 163
Quoted 8 lines
hw/nvme/dif.c +2
-1@@ -157,7 +157,8 @@ static uint16_t nvme_dif_prchk_crc16(NvmeNamespace *ns, NvmeDifTuple *dif, {switch (NVME_ID_NS_DPS_TYPE (ns->id_ns.dps)) {case NVME_ID_NS_DPS_TYPE_3 : -if (be32_to_cpu (dif->g16.reftag) !=0xffffffff ) { +if ((be32_to_cpu (dif->g16.reftag) !=0xffffffff ) || + (be16_to_cpu (dif->g16.apptag) !=0xffff )) {break ; }
For type 3, if reftag is 0xffffffff the NVME_ID_NS_DPS_TYPE_3 case will fallthrough to the next cases (_TYPE_1 and _TYPE_2), checking if apptag is 0xffff, and disable checking if so.
hw/nvme/dif.c static uint16_t nvme_dif_prchk_crc64(NvmeNamespace *ns, NvmeDifTuple *dif, · line 231
Quoted 9 lines
hw/nvme/dif.c +1
-1@@ -225,7 +226,7 @@ static uint16_t nvme_dif_prchk_crc64(NvmeNamespace *ns, NvmeDifTuple *dif,switch (NVME_ID_NS_DPS_TYPE (ns->id_ns.dps)) {case NVME_ID_NS_DPS_TYPE_3 : -if (r !=0xffffffffffff ) { +if (r !=0xffffffffffff || (be16_to_cpu (dif->g64.apptag) !=0xffff )) {break ; }
Same here.
PATCH 3/3 docs: update hw/nvme documentation for protection information
In reply to Ankit KumarAdd missing entry for pif ("protection information format"). Protection information size can be 8 or 16 bytes, Update the pil entry as per the NVM command set specification.
--- docs/system/devices/nvme.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
docs/system/devices/nvme.rst +7 -3
@@ -271,9 +271,13 @@ The virtual namespace device supports DIF- and DIX-based protection information ``pil=UINT8`` (default: ``0``) Controls the location of the protection information within the metadata. Set - to ``1`` to transfer protection information as the first eight bytes of - metadata. Otherwise, the protection information is transferred as the last - eight bytes. + to ``1`` to transfer protection information as the first bytes of metadata. + Otherwise, the protection information is transferred as the last bytes of + metadata. + +``pif=UINT8`` (default: ``0``) + By default, the namespace device uses 16 bit guard protection information + format. Set to ``2`` to enable 64 bit guard protection information format. Virtualization Enhancements and SR-IOV (Experimental Support) -------------------------------------------------------------
Signature · 1 line
2.25.1
Re: [PATCH 3/3] docs: update hw/nvme documentation for protection information
Quoted 18 lines · Ankit Kumar
Add missing entry for pif ("protection information format"). Protection information size can be 8 or 16 bytes, Update the pil entry as per the NVM command set specification.
Signed-off-by Ankit Kumar <[email protected]>--- docs/system/devices/nvme.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)docs/system/devices/nvme.rst +0
-1@@ -271,9 +271,13 @@ The virtual namespace device supports DIF- and DIX-based protection information ``pil=UINT8`` (default: ``0``) Controls the location of the protection information within the metadata. Set - to ``1`` to transfer protection information as the first eight bytes of
docs/system/devices/nvme.rst The virtual namespace device supports DIF- and DIX-based protection information · line 281
Quoted 10 lines
docs/system/devices/nvme.rst +7
-2- metadata. Otherwise, the protection information is transferred as the last - eight bytes. + to ``1`` to transfer protection information as the first bytes of metadata. + Otherwise, the protection information is transferred as the last bytes of + metadata. + +``pif=UINT8`` (default: ``0``) + By default, the namespace device uses 16 bit guard protection information + format. Set to ``2`` to enable 64 bit guard protection information format.
I'll add a small note that pif=1 (32b guard) is not supported.
Thanks,
Quoted 11 lines · Ankit Kumar
This series fixes two bugs
1. CRC64 generation when metadata buffer is used.
2. Protection information disable check for Type 3 protection.This series also updates the documentaion for pi (protection information), and adds missing pif (protection information format) entry.
Ankit Kumar (3):
hw/nvme: fix CRC64 for guard tag
hw/nvme: fix disable pi checks for Type 3 protection
docs: update hw/nvme documentation for protection information
At least the CRC64 change smells like a -stable material, - the bug is present in, for example, qemu-7.2 too. But I don't know how important it is to keep nvme updated in 8.0 or before, and what the outcome of this bug is, to begin with. Somehow I think nvme was in preliminary shape before 8.0.
Are the other changes also relevant for -stable?
Please keep Cc: [email protected] for anything you think is worth to have in previous/stable releases.
Thanks,
/mjt
Quoted 19 lines · Michael Tokarev
Quoted 11 lines · Ankit Kumar
This series fixes two bugs
1. CRC64 generation when metadata buffer is used.
2. Protection information disable check for Type 3 protection.This series also updates the documentaion for pi (protection information), and adds missing pif (protection information format) entry.
Ankit Kumar (3):
hw/nvme: fix CRC64 for guard tag
hw/nvme: fix disable pi checks for Type 3 protection
docs: update hw/nvme documentation for protection informationAt least the CRC64 change smells like a -stable material, - the bug is present in, for example, qemu-7.2 too. But I don't know how important it is to keep nvme updated in 8.0 or before, and what the outcome of this bug is, to begin with. Somehow I think nvme was in preliminary shape before 8.0.
Quoted 5 lines
Are the other changes also relevant for -stable?
Please keep Cc: [email protected] for anything you think is worth to have in previous/stable releases.
Hi Michael,
Yes, this is stable worthy.
I'll add Cc: stable and fixes tags on relevant patches on the pull.
Thanks for the heads up!