Repository navigation
mi: add nvme_mi_mi_controller_health_status_poll - #1144
Conversation
edeb856 to
e97d8c6
Compare
|
Hi @jk-ozlabs, Can you help review this PR? |
|
Would you mind to rebase it, there is a conflict due to changes I merged before this one? And could you check if the libnvme3 has also all bits? I think I added this change but better to double check. Thanks! |
3c9dee1 to
7352bd4
Compare
|
Hi @igaw I rebased the code and created a similar PR for the libnvme3 |
Thanks! The v3 has been released, do you really need this for v1? I'd rather not add new features to the libnvme v1 library at this piont. |
Currently our nvme (mi) daemon is built upon the libnvme. We haven't upgraded to the libnvme3 yet and we are adding the nvme event (by health status polling) support for some NVMe-MI 1.2 devices. |
Alright, I don't want to make your life harder for no reason. I am fine taking this for libnvme 1. This gives you time for the migration and you don't have to deal with two things at the same time. Just don't expect that libnvme 1 will be actively maintainer for ever. |
7352bd4 to
8241fc2
Compare
jk-ozlabs
left a comment
There was a problem hiding this comment.
Mostly look good, just a few comments inline.
Main concern is the caller-visible representation of chscf, but other things are pretty trivial.
| __u8 spare; | ||
| __u8 cwarn; | ||
| __u8 rsvd9[7]; | ||
| __u8 chscf[2]; |
There was a problem hiding this comment.
This is a bit odd representing it as an array of u8, whereas the spec defines a bit-set over a 16-bit field (which you have replicated in nvme_mi_chscf) meaning that users of the field need to split the bitmask over the array entries.
There was a problem hiding this comment.
The reason chscf was declared as __u8 chscf[2] is that it sits at byte offset 9 (an odd byte offset immediately following __u8 cwarn at offset 8):
ctlid(__le16, bytes 0..1)csts(__le16, bytes 2..3)ctemp(__le16, bytes 4..5)pdlu(__u8, byte 6)spare(__u8, byte 7)cwarn(__u8, byte 8)chscf(bytes 9..10)
Because struct nvme_mi_ctrl_health_status is not marked __attribute__((packed)), declaring __le16 chscf; causes the compiler to insert 1 byte of alignment padding at offset 9, shifting chscf to bytes 10..11 and inflating sizeof(struct nvme_mi_ctrl_health_status) from 16 to 18 bytes. We followed the existing pattern in types.h for unaligned 16-bit fields in unpacked structs (such as __u8 temperature[2] at offset 1 in struct nvme_smart_log and __u8 regctl[2] at offset 5 in struct nvme_resv_status).
If you prefer exposing it directly as a 16-bit type, we can either:
- Add
__attribute__((packed))tostruct nvme_mi_ctrl_health_statusand change the field to__le16 chscf;(matching the packed wire structs inmi.h), or - Keep
__u8 chscf[2]and add astatic inline __u16helper to extract the 16-bit bitmask.
Happy to switch to __le16 chscf with __attribute__((packed)) if you prefer!
There was a problem hiding this comment.
I think packed would be preferable here; the downside is an API change, but all existing fields should be binary compatible with the old struct.
There was a problem hiding this comment.
FWIW, since the nvme spec tends to ignore API/ABI stability, we can also ignore it for the nvme spec part. That means I am fine with changing the data structs, this will only break on source code level. The approach is to notify users by adding an entry in NEWS.md. Obviously NEWS.md is only available in nvme-cli 3. libnvme1 users will notice when the compiler starts complaining :)
There was a problem hiding this comment.
OK, packed sounds like the best approach here then.
There was a problem hiding this comment.
Thanks both! Switched to __le16 chscf with __attribute__((packed)) on struct nvme_mi_ctrl_health_status. The struct stays 16 bytes and all existing fields keep their offsets; I added asserts in test/mi.c for sizeof() == 16 and offsetof(chscf) == 9. examples/mi-mctp.c now just uses le16_to_cpu(chs->chscf).
| nvme_mi_ep_t ep, __u16 start_ctrl_id, bool clear, __u32 dw0_flags, | ||
| __u32 dw1_flags, struct nvme_mi_ctrl_health_status *entries, | ||
| unsigned int *num_entries) | ||
| { |
There was a problem hiding this comment.
Minor, but some inconsistent indentation here, and a couple of sites below for similar function declarations.
There was a problem hiding this comment.
Ack, updated the function signatures and call sites in src/nvme/mi.h, src/nvme/mi.c, and test/mi.c to align wrapped parameters with the opening parenthesis.
| rc = nvme_mi_submit(ep, &req, &resp); | ||
| if (rc) { | ||
| *num_entries = total; | ||
| return rc; |
There was a problem hiding this comment.
The function semantics regarding partial results (and hence a truncated num_entries) isn't super clear. Are you intending to always set num_entries (and return a partial result) including on error return values?
This would be good to clarify on the function doc.
There was a problem hiding this comment.
Good catch. Originally *num_entries = total; was set on error to indicate how many entries were populated if a later chunk failed mid-transfer, but mutating the caller's input capacity on error is surprising (especially if chunk 1 fails and overwrites *num_entries with 0).
I have updated the implementation so *num_entries is only updated on success (return 0), and clarified this in the kernel-doc comment in src/nvme/mi.h.
| (dw0_flags & (NVME_MI_CHSP_DW0_ALL | | ||
| NVME_MI_CHSP_DW0_INCVF | | ||
| NVME_MI_CHSP_DW0_INCPF | | ||
| NVME_MI_CHSP_DW0_INCF)); |
There was a problem hiding this comment.
Minor, but might be neater to mask the dw0_flags and dw1_flags before constructing the cdw0 / cdw1 values, and you would no longer need to do that on every iteration.
There was a problem hiding this comment.
Agreed, moved the dw0_flags masking and cdw1 construction outside the while loop so they are only computed once.
| break; | ||
|
|
||
| if (le16_to_cpu(entries[total - 1].ctlid) == 0xffff) | ||
| break; |
There was a problem hiding this comment.
I am not clear on what this is indicating, as there is no specific mention of this case in the spec. Can you add a comment?
There was a problem hiding this comment.
Since SCTLID in Dword 0 is a 16-bit field (0x0000–0xffff), if the last returned entry has ctlid == 0xffff, there can be no higher Controller IDs to poll, and advancing current_sctlid = last_ctlid + 1 would wrap current_sctlid & 0xffff back to 0. Added an inline comment explaining this guard.
|
What's the status here? |
8241fc2 to
f2b07dd
Compare
|
Hi @igaw and @jk-ozlabs, Sincere apologies for the long delay in getting back to this PR—I was pulled away by other higher-priority tasks over the past few weeks, and I finally have the bandwidth to come back and wrap this up. Thank you both for your patience and thorough reviews! I have replied to the inline comments, updated the code accordingly, and rebased the branch onto the latest |
|
Looks good, just a follow-up to the struct layout below. |
f2b07dd to
46f9717
Compare
jk-ozlabs
left a comment
There was a problem hiding this comment.
OK, this looks good to me now.
If you feel like it, you could move the struct-size asserts out of the test case and into build-time static assertions of the library, but we'd need to work carefully with compiler coverage to do that. That's also fine as a future change too, if you prefer.
|
FWIW, ccan ships build_assert |
Implement Controller Health Status Poll (Opcode 02h) defined in NVMe-MI 2.0 (Section 5.3 & 5.3.1). - Add enum nvme_mi_chsp_dw0 and enum nvme_mi_chsp_dw1 matching Figures 94 and 95 of the specification. - Add nvme_mi_mi_controller_health_status_poll() with direct parameters and an auto-paging multi-submit loop when num_entries > 255 (up to 255 entries per submit, advancing SCTLID = last_ctlid + 1). - Add convenience inline helper nvme_mi_mi_controller_health_status_poll_all() for querying all controllers starting from ID 0. - Update struct nvme_mi_ctrl_health_status (CHDS) to include the 16-bit chscf[2] (Controller Health Status Changed Flags) at offset 9 and rsvd11[5]. - Add enum nvme_mi_chscf and update enum nvme_mi_csts with TCIDA. - Export nvme_mi_mi_controller_health_status_poll in libnvme-mi.map. - Add unit tests in test/mi.c covering single-entry query, selective flags, auto-paging across chunk boundaries, and error handling. Signed-off-by: Hao Jiang <jianghao@google.com>
Update the controllers subcommand in mi-mctp to display controller health status alongside controller topology and PCI configuration. - Poll all controller health entries using nvme_mi_mi_controller_health_status_poll_all(). - Group health information by controller ID inside show_ctrl(). - Add show_chscf_flags() to decode active Controller Health Status Changed Flags (CHSCF) whenever the status changed field is non-zero. Signed-off-by: Hao Jiang <jianghao@google.com>
46f9717 to
1f8c931
Compare
|
Thanks for the approval, and thanks @igaw for the pointer! I moved the size/offset checks out of the test into _Static_assert(sizeof(struct nvme_mi_ctrl_health_status) == 16,
"size_of_nvme_mi_ctrl_health_status_is_not_16_bytes");
_Static_assert(offsetof(struct nvme_mi_ctrl_health_status, chscf) == 9,
"offset_of_nvme_mi_ctrl_health_status_chscf_is_not_9");I kept them out of the public headers since those are also included from C++. I considered ccan's |
|
Ah know I remember, |
|
Thanks everyone! |
Implement Controller Health Status Poll (Opcode 02h) defined in NVMe-MI 2.0 (Section 5.3 & 5.3.1).