git: bcf4600a0c0b - stable/14 - nvme: Restore the host memory buffer size calculation

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

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

commit bcf4600a0c0beaaf66090d0aa8fe16269e372889
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 21:00:06 +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 2f593ed7abaf..414b7041870b 100644
--- a/sys/dev/nvme/nvme_ctrlr.c
+++ b/sys/dev/nvme/nvme_ctrlr.c
@@ -1057,7 +1057,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);