All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jesper Wendel Devantier <foss@defmacro.it>
To: Daniel Gomez <da.gomez@kernel.org>
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Peter Xu <peterx@redhat.com>,
	Philippe Mathieu-Daudé <philmd@mailo.com>,
	Keith Busch <kbusch@kernel.org>, Klaus Jensen <its@irrelevant.dk>,
	Klaus Jensen <k.jensen@samsung.com>,
	qemu-block@nongnu.org, Daniel Gomez <da.gomez@samsung.com>,
	GOST <gost.dev@samsung.com>
Subject: Re: [PATCH v2 5/7] hw/nvme: clamp mdts and zasl shifts
Date: Fri, 4 Sep 2026 23:58:45 +0200	[thread overview]
Message-ID: <20260904235834.5-foss@defmacro.it> (raw)
In-Reply-To: <20260819-align-nvme-mdts-with-linux-v2-5-351ac2dfed64@samsung.com>



On 2026-08-19T17:24:07+02:00, Daniel Gomez <da.gomez@kernel.org> wrote:
> From: Daniel Gomez <da.gomez@samsung.com>
>
> Once dma_blk_cb() chunks at IOV_MAX, a later patch drops the current
> mdts 2 MiB cap, allowing mdts (and zasl, which may be as large as mdts)
> to essentially be 32 or more. Ensure shifting doesn't go out of range
> by adding a static inline helper that clamps to UINT64_MAX when mdts or
> zasl shift operations exceed uint64_t width.
>
> Fixes error with ubsan enabled and large mdts:
> ../hw/nvme/ctrl.c:1685:36: runtime error: shift exponent 32 is too large
> for 32-bit type 'unsigned int'
>
> Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
> ---
>  hw/nvme/ctrl.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
> index 4893cf7e741..a24a674a4c5 100644
> --- a/hw/nvme/ctrl.c
> +++ b/hw/nvme/ctrl.c
> @@ -1713,11 +1713,18 @@ static void nvme_clear_events(NvmeCtrl *n, uint8_t event_type)
>      }
>  }
>  
> +static inline uint64_t nvme_max_data_transfer_size(NvmeCtrl *n, uint8_t exp)
> +{
> +    unsigned shift = n->page_bits + exp;
> +
> +    return shift >= 64 ? UINT64_MAX : 1ULL << shift;
> +}
> +
>  static inline uint16_t nvme_check_mdts(NvmeCtrl *n, size_t len)
>  {
>      uint8_t mdts = n->params.mdts;
>  
> -    if (mdts && len > n->page_size << mdts) {
> +    if (mdts && len > nvme_max_data_transfer_size(n, mdts)) {
>          trace_pci_nvme_err_mdts(len);
>          return NVME_INVALID_FIELD | NVME_DNR;
>      }
> @@ -3809,7 +3816,7 @@ static uint16_t nvme_do_write(NvmeCtrl *n, NvmeRequest *req, bool append,
>              }
>  
>              if (n->params.zasl &&
> -                data_size > (uint64_t)n->page_size << n->params.zasl) {
> +                data_size > nvme_max_data_transfer_size(n, n->params.zasl)) {
>                  trace_pci_nvme_err_zasl(data_size);
>                  return NVME_INVALID_FIELD | NVME_DNR;
>              }
>
> -- 
> 2.55.0
>
>
>

Reviewed-by: Jesper Wendel Devantier <foss@defmacro.it>





  reply	other threads:[~2026-09-04 22:03 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-19 15:24 [PATCH v2 0/7] hw/nvme: lift IOV_MAX limit in DMA path Daniel Gomez
2026-08-19 15:24 ` [PATCH v2 1/7] dma-helpers: fix unaligned discard_back Daniel Gomez
2026-09-04 21:57   ` Jesper Wendel Devantier
2026-09-09 12:17     ` Daniel Gomez
2026-08-19 15:24 ` [PATCH v2 2/7] dma-helpers: ensure IOV_MAX chunks end aligned Daniel Gomez
2026-08-19 15:24 ` [PATCH v2 3/7] dma-helpers: cap iovec allocation at IOV_MAX Daniel Gomez
2026-09-04 21:57   ` Jesper Wendel Devantier
2026-08-19 15:24 ` [PATCH v2 4/7] dma-helpers: chunk dma_blk_cb " Daniel Gomez
2026-09-04 21:58   ` Jesper Wendel Devantier
2026-08-19 15:24 ` [PATCH v2 5/7] hw/nvme: clamp mdts and zasl shifts Daniel Gomez
2026-09-04 21:58   ` Jesper Wendel Devantier [this message]
2026-08-19 15:24 ` [PATCH v2 6/7] hw/nvme: drop DMA-path IOV_MAX guard Daniel Gomez
2026-09-04 21:59   ` Jesper Wendel Devantier
2026-08-19 15:24 ` [PATCH v2 7/7] hw/nvme: cap mdts for CMB/PMR-only Daniel Gomez
2026-09-04 22:02   ` Jesper Wendel Devantier
2026-09-09 12:35     ` Daniel Gomez
2026-09-04 22:00 ` [PATCH v2 0/7] hw/nvme: lift IOV_MAX limit in DMA path Keith Busch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260904235834.5-foss@defmacro.it \
    --to=foss@defmacro.it \
    --cc=da.gomez@kernel.org \
    --cc=da.gomez@samsung.com \
    --cc=gost.dev@samsung.com \
    --cc=its@irrelevant.dk \
    --cc=k.jensen@samsung.com \
    --cc=kbusch@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@mailo.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.