All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Honglei Huang <honghuan@amd.com>
Cc: <dmitry.osipenko@collabora.com>,  <odaki@rsg.ci.i.u-tokyo.ac.jp>,
	<Ray.Huang@amd.com>,  <mst@redhat.com>,  <cohuck@redhat.com>,
	<pbonzini@redhat.com>,  <qemu-devel@nongnu.org>
Subject: Re: [RFC PATCH v8 3/5] virtio-gpu: remove the artificial IOV mapping limit
Date: Fri, 04 Dec 2026 12:51:09 +0000	[thread overview]
Message-ID: <87o6b1xl8i.fsf@draig.linaro.org> (raw)
In-Reply-To: <20261203014352.1792475-4-honghuan@amd.com> (Honglei Huang's message of "Thu, 3 Dec 2026 09:43:50 +0800")

Honglei Huang <honghuan@amd.com> writes:

> Userptr-backed blobs can require a very large number of
> virtio_gpu_mem_entry elements when their pages are not contiguous. The
> guest virtio-gpu frontend forwards that entry count and does not impose
> the 16384-entry cap previously enforced by
> virtio_gpu_create_mapping_iov().
>
> Replace that QEMU-only limit with a check that the entry array size
> does not overflow size_t, which can happen on 32-bit hosts. Make the
> entry loop counter unsigned like nr_entries so it cannot overflow
> either. Keep the existing allocation, copy-size, and DMA mapping checks.
>
> Signed-off-by: Honglei Huang <honghuan@amd.com>
> ---
>  hw/display/virtio-gpu.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
> index d248e50abcb..79968dcf12f 100644
> --- a/hw/display/virtio-gpu.c
> +++ b/hw/display/virtio-gpu.c
> @@ -988,16 +988,14 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g,
>  {
>      struct virtio_gpu_mem_entry *ents;
>      size_t esize, s;
> -    int e, v;
> +    uint32_t e;
> +    int v;
>  
> -    if (nr_entries > 16384) {
> -        qemu_log_mask(LOG_GUEST_ERROR,
> -                      "%s: nr_entries is too big (%d > 16384)\n",
> +    if (__builtin_mul_overflow(sizeof(*ents), nr_entries, &esize)) {
> +        qemu_log_mask(LOG_GUEST_ERROR, "%s: entry count is too large (%u)\n",
>                        __func__, nr_entries);

I guess we don't have a size_t equivalent of the [su]mul[32|64]_overflow
in host_utils?

I wonder if it's worth adding? The only other place that uses the
__builtin directly is the pixman code but usually __builtin use is
hidden in compiler.h to deal with potential differences amongst the
compilers we support.

>          return -1;
>      }
> -
> -    esize = sizeof(*ents) * nr_entries;
>      ents = g_try_malloc(esize);
>      if (!ents && esize) {
>          return -1;
> @@ -1030,7 +1028,7 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g,
>                                   MEMTXATTRS_UNSPECIFIED);
>              if (!map) {
>                  qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to map MMIO memory for"
> -                              " element %d\n", __func__, e);
> +                              " element %u\n", __func__, e);

If e is uint32_t we should use "%"PRIu32"\n" instead for cleanliness
even though we don't have to deal with 32 bit hosts anymore.

>                  goto err;
>              }

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


  reply	other threads:[~2026-12-04 12:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  1:43 [RFC PATCH v8 0/5] virtio-gpu: Add userptr support and ROCm capability Honglei Huang
2026-12-03  1:43 ` [RFC PATCH v8 1/5] linux-headers: Update to v7.4-rc2-userptr-v11 for ROCm capset (!UPSTREAM) Honglei Huang
2026-12-03  1:43 ` [RFC PATCH v8 2/5] virtio-gpu: Add ROCm capability support Honglei Huang
2026-12-03  1:43 ` [RFC PATCH v8 3/5] virtio-gpu: remove the artificial IOV mapping limit Honglei Huang
2026-12-04 12:51   ` Alex Bennée [this message]
2026-12-03  1:43 ` [RFC PATCH v8 4/5] linux-headers: Update to v7.4-rc2-userptr-v11 for readonly blob (!UPSTREAM) Honglei Huang
2026-12-04 12:51   ` Alex Bennée
2026-12-03  1:43 ` [RFC PATCH v8 5/5] virtio-gpu: advertise readonly blobs Honglei Huang
2026-12-04  6:50 ` [RFC PATCH v8 0/5] virtio-gpu: Add userptr support and ROCm capability Huang, Honglei1
2026-12-04 12:56   ` Alex Bennée

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=87o6b1xl8i.fsf@draig.linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=Ray.Huang@amd.com \
    --cc=cohuck@redhat.com \
    --cc=dmitry.osipenko@collabora.com \
    --cc=honghuan@amd.com \
    --cc=mst@redhat.com \
    --cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
    --cc=pbonzini@redhat.com \
    --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.