git: 97a9a62d0ffe - stable/15 - nvme: Restore the host memory buffer size calculation

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

URL: https://cgit.FreeBSD.org/src/commit/?id=97a9a62d0ffeed4c2d0a22ef649daed2b9b8b154

commit 97a9a62d0ffeed4c2d0a22ef649daed2b9b8b154
Author:     Kenneth D. Merry <ken@FreeBSD.org>
AuthorDate: 2026-11-09 18:46:59 +0000
Commit:     Kenneth D. Merry <ken@FreeBSD.org>
CommitDate: 2026-11-16 16:12:40 +0000

    nvme: Restore the host memory buffer size calculation
    
    When the nvme_ctrlr_cmd_set_feature() call in
    nvme_ctrlr_hmb_enable() was rewritten for the widened Set Features
    API, the HSIZE calculation reverted to dividing by a hard coded
    4096 instead of the controller page size, undoing commit
    3740a8db13ba.  The Host Memory Buffer Size field is in units of
    the current memory page size (CC.MPS), so the wrong size would be
    programmed on controllers configured with a page size other than
    4KB.
    
    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 f262bdcf24f1f946edcd01f5eb5dfa2910da9e7b)
---
 sys/dev/nvme/nvme_ctrlr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c
index cb88b8b1c28c..7c467b01f2f8 100644
--- a/sys/dev/nvme/nvme_ctrlr.c
+++ b/sys/dev/nvme/nvme_ctrlr.c
@@ -972,7 +972,7 @@ nvme_ctrlr_hmb_enable(struct nvme_controller *ctrlr, bool enable, bool memret)
 		cdw11 |= 2;
 	status.done = 0;
 	nvme_ctrlr_cmd_set_feature(ctrlr, 0, 0, NVME_FEAT_HOST_MEMORY_BUFFER,
-	    cdw11, ctrlr->hmb_nchunks * ctrlr->hmb_chunk / 4096,
+	    cdw11, ctrlr->hmb_nchunks * ctrlr->hmb_chunk / ctrlr->page_size,
 	    ctrlr->hmb_desc_paddr, ctrlr->hmb_desc_paddr >> 32,
 	    ctrlr->hmb_nchunks, NULL, 0, nvme_completion_poll_cb, &status);
 	nvme_completion_poll(&status);