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

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);
         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);
                 goto err;
             }
 
-- 
2.34.1



  parent reply	other threads:[~2026-12-03  1:45 UTC|newest]

Thread overview: 6+ 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 ` Honglei Huang [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-03  1:43 ` [RFC PATCH v8 5/5] virtio-gpu: advertise readonly blobs Honglei Huang

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=20261203014352.1792475-4-honghuan@amd.com \
    --to=honghuan@amd.com \
    --cc=Ray.Huang@amd.com \
    --cc=alex.bennee@linaro.org \
    --cc=cohuck@redhat.com \
    --cc=dmitry.osipenko@collabora.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.