[PATCH nvme-cli] nvme: check MUD support before firmware commit

guzebing guzebing1612 at gmail.com
Tue May 19 06:45:42 PDT 2026


From: Guzebing <guzebing at bytedance.com>

Firmware Commit returns the Multiple Update Detected value in the command
completion. nvme-cli currently identifies the controller after the
command completes to decide whether to print that value.

That post-command Identify is fragile for immediate activation. A possible
Linux race looks like:

  nvme-cli thread              nvme driver AEN work
  ---------------              --------------------
  libnvme_exec_admin_passthru()
    -> Firmware Commit succeeds
                               nvme_handle_aen_notice()
                                 -> FW_ACT_STARTING
                                 -> nvme_change_ctrl_state(RESETTING)
                                 -> nvme_fw_act_work()
                                    -> nvme_quiesce_io_queues()
                                    -> wait for activation
  fw_commit_print_mud()
    -> fw_commit_support_mud()
       -> nvme_identify_ctrl()
          -> admin ioctl passthru
          -> nvme_user_cmd*()
          -> blk_mq_alloc_request()
          -> __nvme_check_ready()
             rejects user admin command while resetting

nvme-cli then prints "identify-ctrl: ..." after the successful
fw-commit output. The extra error makes it unclear whether Firmware
Commit itself failed, even though the command completion was already
successful.

The post-command Identify can also observe the wrong capability. MUD is
a bit in the Firmware Commit completion, so it should be interpreted
using the controller capability that applied when that command was
processed. If the old firmware does not report support for firmware
image overlap but the new firmware does, a post-activation Identify can
make nvme-cli interpret the old command completion using the new
firmware capability.

Read and cache SMUD before submitting Firmware Commit, and use the
cached value to decide whether to print the completion MUD value. This
ties MUD reporting to the firmware revision that accepted the command
and avoids a post-success Identify during firmware activation.

Fixes: b44729257 ("nvme: Check fw-commit command support MUD")
Signed-off-by: Guzebing <guzebing at bytedance.com>
---
 nvme.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/nvme.c b/nvme.c
index 6a8350b9a..560ca7b7f 100644
--- a/nvme.c
+++ b/nvme.c
@@ -5341,9 +5341,9 @@ static bool fw_commit_support_mud(struct libnvme_transport_handle *hdl)
 	return false;
 }
 
-static void fw_commit_print_mud(struct libnvme_transport_handle *hdl, __u64 result)
+static void fw_commit_print_mud(bool mud_supported, __u64 result)
 {
-	if (!fw_commit_support_mud(hdl))
+	if (!mud_supported)
 		return;
 
 	printf("Multiple Update Detected (MUD) Value: %#" PRIx64 "\n",
@@ -5403,6 +5403,7 @@ static int fw_commit(int argc, char **argv, struct command *acmd, struct plugin
 	struct libnvme_passthru_cmd cmd;
 	int err;
 	nvme_print_flags_t flags;
+	bool mud_supported;
 
 	struct config {
 		bool	ish;
@@ -5471,6 +5472,8 @@ static int fw_commit(int argc, char **argv, struct command *acmd, struct plugin
 		return -EINVAL;
 	}
 
+	mud_supported = fw_commit_support_mud(hdl);
+
 	nvme_init_fw_commit(&cmd, cfg.slot, cfg.action, cfg.bpid);
 	if (cfg.ish) {
 		if (libnvme_transport_handle_is_mi(hdl))
@@ -5489,7 +5492,7 @@ static int fw_commit(int argc, char **argv, struct command *acmd, struct plugin
 	if (cfg.action == 6 || cfg.action == 7)
 		printf(" bpid:%d", cfg.bpid);
 	printf("\n");
-	fw_commit_print_mud(hdl, cmd.result);
+	fw_commit_print_mud(mud_supported, cmd.result);
 
 	return err;
 }
-- 
2.20.1




More information about the Linux-nvme mailing list