git: 78470b4a8068 - stable/15 - nvme: Fix the data length in the Reservation Report command builder

From: Kenneth D. Merry <ken_at_FreeBSD.org>
Date: Mon, 16 Nov 2026 21:00:41 UTC
The branch stable/15 has been updated by ken:

URL: https://cgit.FreeBSD.org/src/commit/?id=78470b4a806859868aa5a6667464b3abe4ae0069

commit 78470b4a806859868aa5a6667464b3abe4ae0069
Author:     Kenneth D. Merry <ken@FreeBSD.org>
AuthorDate: 2026-11-09 18:46:58 +0000
Commit:     Kenneth D. Merry <ken@FreeBSD.org>
CommitDate: 2026-11-16 16:12:38 +0000

    nvme: Fix the data length in the Reservation Report command builder
    
    nvme_ns_resv_report_cmd() put its length argument, which callers
    supply in bytes, directly into cdw10.  The NUMD field is a 0's
    based count of dwords, so the command asked the controller to
    transfer nearly four times the size of the supplied data buffer.
    In practice controllers limit the transfer to the length described
    by the PRP entries, which is why this worked in testing, but the
    command was incorrect.
    
    Convert the byte count to a 0's based dword count in the builder.
    
    Reported by:    llm-postcr
    Fixes:          7a9e4375316b
    MFC after:      1 week
    Sponsored by:   Spectra Logic
    Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
    
    (cherry picked from commit 86b9d629c68f6dc63543b9c0a6da6c96c857f3bc)
---
 sys/dev/nvme/nvme.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sys/dev/nvme/nvme.h b/sys/dev/nvme/nvme.h
index 0c6886fde275..31b00fb2bdca 100644
--- a/sys/dev/nvme/nvme.h
+++ b/sys/dev/nvme/nvme.h
@@ -2205,7 +2205,8 @@ void	nvme_ns_resv_report_cmd(struct nvme_command *cmd, uint32_t nsid,
 {
 	cmd->opc = NVME_OPC_RESERVATION_REPORT;
 	cmd->nsid = htole32(nsid);
-	cmd->cdw10 = htole32(length);
+	/* NUMD is a 0's based count of dwords; length is in bytes. */
+	cmd->cdw10 = htole32(length / 4 - 1);
 	cmd->cdw11 = htole32(report_type);
 }