From 1b6c704195758d0bb5113ffef7e53d9dbaae4ce2 Mon Sep 17 00:00:00 2001 From: Hailiang Ma Date: Fri, 27 Nov 2026 11:37:00 +0800 Subject: [PATCH] nvme-cli: decode the 32-bit EDLEN field of EOM lane descriptors The EOM Lane Descriptor field EDLEN is 32 bits wide in the NVMe specification, but struct nvme_eom_lane_desc describes it as __le16 followed by 14 reserved bytes. Eye data lengths above 0xffff are truncated when printed, and the upper half of the field is mistaken for reserved bytes. Widen edlen to __le32 with 12 reserved bytes, and read it with le32_to_cpu() in the walker and in both output formats. Keep the vendor specific data length in a 32-bit type so the bounds check and the hex dump see the full value. A mock log with EDLEN 0x10000 shows 65536 in the text output and in JSON. Signed-off-by: Hailiang Ma --- libnvme/src/nvme/nvme-types-base.h | 6 +++--- plugins/cmds-log/log-print-json.c | 8 ++++---- plugins/cmds-log/log-print-stdout.c | 4 ++-- plugins/cmds-log/log-print.h | 4 ++-- tests/cli/nvme_print_test.py | 25 +++++++++++++++++++++++++ 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/libnvme/src/nvme/nvme-types-base.h b/libnvme/src/nvme/nvme-types-base.h index 4c8d1cbc63..fa1089c9ff 100644 --- a/libnvme/src/nvme/nvme-types-base.h +++ b/libnvme/src/nvme/nvme-types-base.h @@ -7006,7 +7006,7 @@ struct nvme_mgmt_addr_list_log { * @nrows: Number of Rows * @ncols: Number of Columns * @edlen: Eye Data Length - * @rsvd18: Reserved + * @rsvd20: Reserved * @eye_desc: Printable Eye, Eye Data, and any Padding */ struct nvme_eom_lane_desc { @@ -7020,8 +7020,8 @@ struct nvme_eom_lane_desc { __le16 right; __le16 nrows; __le16 ncols; - __le16 edlen; - __u8 rsvd18[14]; + __le32 edlen; + __u8 rsvd20[12]; __u8 eye_desc[]; }; diff --git a/plugins/cmds-log/log-print-json.c b/plugins/cmds-log/log-print-json.c index 1cbe92d8d7..2076cbdb98 100644 --- a/plugins/cmds-log/log-print-json.c +++ b/plugins/cmds-log/log-print-json.c @@ -1344,7 +1344,7 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log, int idx = i++; __cleanup_free char *hexstr = NULL; unsigned char *vsdata; - uint16_t vsdatalen; + uint32_t vsdatalen; struct json_object *jdesc; char *hexdata; @@ -1361,7 +1361,7 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log, obj_add_uint(jdesc, "right", le16_to_cpu(desc.right)); obj_add_uint(jdesc, "nrows", le16_to_cpu(desc.nrows)); obj_add_uint(jdesc, "ncols", le16_to_cpu(desc.ncols)); - obj_add_uint(jdesc, "edlen", le16_to_cpu(desc.edlen)); + obj_add_uint(jdesc, "edlen", le32_to_cpu(desc.edlen)); vsdata = eom_desc_iter_vsdata(&it, &desc, &vsdatalen); if (!vsdata) { @@ -1379,7 +1379,7 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log, } /* 2 hex chars + space per byte */ - hexstr = malloc(vsdatalen * 3 + 1); + hexstr = malloc((size_t)vsdatalen * 3 + 1); if (!hexstr) { json_free_object(jdesc); @@ -1389,7 +1389,7 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log, /* Hex dump Vendor Specific Eye Data */ hexdata = hexstr; - for (int offset = 0; offset < vsdatalen; offset++) + for (uint32_t offset = 0; offset < vsdatalen; offset++) hexdata += sprintf(hexdata, "%02X ", vsdata[offset]); /* remove trailing space */ *(hexdata - 1) = '\0'; diff --git a/plugins/cmds-log/log-print-stdout.c b/plugins/cmds-log/log-print-stdout.c index 4e711129fa..614da12ee8 100644 --- a/plugins/cmds-log/log-print-stdout.c +++ b/plugins/cmds-log/log-print-stdout.c @@ -1148,7 +1148,7 @@ static void stdout_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log, size_t len) while (eom_desc_iter_next(&it, &desc)) { unsigned char *vsdata; - uint16_t vsdatalen; + uint32_t vsdatalen; struct shr_table *t; t = stdout_kv_table_create(); @@ -1168,7 +1168,7 @@ static void stdout_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log, size_t len) stdout_kv_add(t, "Number of Columns", "%u", le16_to_cpu(desc.ncols)); stdout_kv_add(t, "Eye Data Length", "%u", - le16_to_cpu(desc.edlen)); + le32_to_cpu(desc.edlen)); stdout_kv_table_finish(t, "phy-rx-eom-descs"); diff --git a/plugins/cmds-log/log-print.h b/plugins/cmds-log/log-print.h index fcb2ed157b..efda8b97cb 100644 --- a/plugins/cmds-log/log-print.h +++ b/plugins/cmds-log/log-print.h @@ -248,11 +248,11 @@ static inline unsigned char *eom_desc_iter_eye(struct eom_desc_iter *it) * *vsdatalen == 0 if it doesn't fit. */ static inline unsigned char *eom_desc_iter_vsdata(struct eom_desc_iter *it, - const struct nvme_eom_lane_desc *desc, uint16_t *vsdatalen) + const struct nvme_eom_lane_desc *desc, uint32_t *vsdatalen) { uint16_t nrows = le16_to_cpu(desc->nrows); uint16_t ncols = le16_to_cpu(desc->ncols); - uint16_t edlen = le16_to_cpu(desc->edlen); + uint32_t edlen = le32_to_cpu(desc->edlen); size_t vsdataoffset = (size_t)nrows * ncols + sizeof(*desc); if (vsdataoffset > it->dsize || edlen > it->dsize - vsdataoffset || diff --git a/tests/cli/nvme_print_test.py b/tests/cli/nvme_print_test.py index 71acec13d3..6c17f8c3bc 100644 --- a/tests/cli/nvme_print_test.py +++ b/tests/cli/nvme_print_test.py @@ -46,6 +46,7 @@ _LID_PERSISTENT_EVENT = 0x0d _LID_MEDIA_UNIT_STATUS = 0x10 _LID_SUPPORTED_CAP_CONFIG = 0x11 +_LID_PHY_RX_EOM = 0x19 def _put(buf, fmt, offset, value): @@ -240,6 +241,30 @@ def test_id(self): def test_log(self): self._run_all([['log', c, self.ctrl] for c in _LOG]) + def test_phy_rx_eom_edlen(self): + # EDLEN is 32 bits, so 0x10000 must not be truncated. + edlen = 0x10000 + desc = bytearray(32 + edlen) + desc[1] = 1 + struct.pack_into('