From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C4B1606A32F for ; Fri, 4 Dec 2026 12:52:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ce9Lu7MV Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xZSl0-0007Ck-Eg; Fri, 04 Dec 2026 07:51:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xZSku-0007CQ-9z for qemu-devel@nongnu.org; Fri, 04 Dec 2026 07:51:16 -0500 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xZSkr-0006YK-Q6 for qemu-devel@nongnu.org; Fri, 04 Dec 2026 07:51:15 -0500 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4a35ac4475dso6083165e9.2 for ; Fri, 04 Dec 2026 04:51:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1796388672; x=1796993472; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :user-agent:references:in-reply-to:subject:cc:to:from:from:to:cc :subject:date:message-id:reply-to:content-type; bh=OP5me6OR5K4SVELeH1FBdI4pjaAuycycq/lnV721r10=; b=ce9Lu7MVmrrgxeeMrrDO+A4kS9hQmygBcPFR/PytQlVvwgpqSr5cptWjrEGq5g80rk m1a5wWRBgJ7AYMAcYl25CWqNAgR1mMetFC2xF6d6TZoEscDv62YTGfJ4bzsN8q4wy0Or 8CNQ3WnpdinsujHUcA1tY56/iPpb2j5a8G4C30bn+l6Fr5+D3n3Lq00U6P9lMxLclhYp 7aciCIxxs3pM/6W+WP/xdlr2moMMDxOml8lgkdV4MzYIfRE4/AHNaoRNlBJXOGO2gkPj z5j1UpZtIYjKVFtozWFvJYgD3AIpbmurMvowUz1gAiGJkGmiQS3QPwI+KWag7fzRiA7D oRuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796388672; x=1796993472; h=content-transfer-encoding:content-type:mime-version:message-id:date :user-agent:references:in-reply-to:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=OP5me6OR5K4SVELeH1FBdI4pjaAuycycq/lnV721r10=; b=epxVwrLb114NbTrlgMLMnikFUv16bHauSGeB4XAgu5qzPcY6xm1aIjF1LUXtZRMD25 1mRET101dCrLNs5om/v+9otQmoD0QDZjQuK5HYVQhsNDS9rxPc+/q+xrscfuvrqufCvE ut3qi6BWrnNHY0LpXJAyf/tVNR7XEt2pQEMtzHSl0RfEblkw0EoPbXyGAq3xMwZNG3kK /23ObYsSDN8WM4ZHHndVc6517D9fhX2dff69+YSk90loPJ5j1gdlR8/EvE/qu2OiFhgM 89RNqqOM/FRxMmya5EumFJKO4U5i4FHeB+wzM8En2+qrkc20YSfarU2RrZ5tky2mdF4N +byg== X-Forwarded-Encrypted: i=1; AL+hErG2qGU2egtr61ajvR+xzVATq+ftePs1YucQV0LwHD48luoVnMeX3QjeKyvfqpMb0G3eSDTBIeJznB3J@nongnu.org X-Gm-Message-State: APuU4Z/8xRsJtQ2YYYKhPVds8ytEt2Ax4fOmfoORcAiAvKX7Tw2xetXn NXher9joLKw7RUtNWb/Q26Df+tYhtcsm4zZuDuemwkAGrYNEta6zCTDaVezsEphxJiw= X-Gm-Gg: AZFdTZeueD2DDbdJ+jTDKUnSTGjIQ1HSwVoZbu+G8revCzWjwArpD6ednLEZhXzGGYd MnOOXiaXEosuOmLrnYUdLAl5WoaqzRkLp2aXepHkITCU2YHrK7l/diMnqygKsUlOrnFEHgaNm1z mOQG9f5sPNtKBgl+7jNE8kQD0EW1Dh04xaL5L+1xVPBhdSyqDuH6jA+IvtKuf74oHHiXyehONY/ UuLZ1BXa06O5UMp7nmoXEfV25VwWgyGiLVfy4uN5Vw50311bQGd483DtxirW87NsKRYRpW9CBaY RrGwafT4ilUmSUoc/g/55MAf/p70uR0fYVgYlQIxLs1qiwXsYhJbEjrMxrJTjB6n+bAaipx4ZEM lH8NgtVT5qThHoWuJHE3ov7J4WNu6ks8KY8ZiRwmeVtQwQt+VNyWjinsyJCAduTe4XbdDSwPsFW SAN2hDPvzMFWW9hjqSRJNB+QwJ7noywG5FPY1rePDWHnQgfkReEszVLQWlYaqAg6bedMGXPPAAw U0ZBTe5dLOEMCOvknYR2b7QKnFTLUJlqv152EGhkeFsgnvRu9govrxAsnzYPAWyhRi4BJX3QgEC g7N0YN9SFyV+eL+jmRQYfLfdTl/m X-Received: by 2002:a05:600c:8b5c:b0:4a1:7e77:c382 with SMTP id 5b1f17b1804b1-4bbeb8bd7c1mr34186205e9.5.1796388671681; Fri, 04 Dec 2026 04:51:11 -0800 (PST) Received: from draig.lan ([185.124.0.158]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbeb700675sm30975885e9.5.2026.12.04.04.51.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 04:51:11 -0800 (PST) Received: from draig (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id D29E95F8D7; Fri, 04 Dec 2026 12:51:09 +0000 (GMT) From: =?utf-8?Q?Alex_Benn=C3=A9e?= To: Honglei Huang Cc: , , , , , , Subject: Re: [RFC PATCH v8 3/5] virtio-gpu: remove the artificial IOV mapping limit In-Reply-To: <20261203014352.1792475-4-honghuan@amd.com> (Honglei Huang's message of "Thu, 3 Dec 2026 09:43:50 +0800") References: <20261203014352.1792475-1-honghuan@amd.com> <20261203014352.1792475-4-honghuan@amd.com> User-Agent: mu4e 1.14.5-pre2; emacs 30.1 Date: Fri, 04 Dec 2026 12:51:09 +0000 Message-ID: <87o6b1xl8i.fsf@draig.linaro.org> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Honglei Huang 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 > --- > 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; >=20=20 > - 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 =3D sizeof(*ents) * nr_entries; > ents =3D 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 m= emory 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; > } --=20 Alex Benn=C3=A9e Virtualisation Tech Lead @ Linaro