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 22414606A32C for ; Thu, 3 Dec 2026 01:45:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=nm6sSVMT Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xYvsM-0002eH-7g; Wed, 02 Dec 2026 20:44:47 -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 1xYvsC-0002d0-H2 for qemu-devel@nongnu.org; Wed, 02 Dec 2026 20:44:36 -0500 Received: from mail-westus2azlp170120002.outbound.protection.outlook.com ([2a01:111:f403:c007::2] helo=MW6PR02CU001.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xYvsA-0003nE-FQ for qemu-devel@nongnu.org; Wed, 02 Dec 2026 20:44:36 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sLD2LtLQ8ucbMZVIGO5XXtyqQu63s0FF/QtUH1ud83Uj1yxreLlRmacEnmY1qG5Pvi4nx4MI7s2FT8ojXIyLpoJDFIb9kTpptUvE1guOuQM9PomFqpsrl9fD46TTflgaH2AV3cvDdZS3n3N/nJsVQUvIe5NeeYmZ4axzYzGNayHTduOSumKZg3hmKOk+fN8eiUw5wFGPxoTwK4AF/j3Ho9KOIaNK1AaOhUUkhZn6HA9bV1ERRkQymSbLNeIxKlThPsaTpeSifL7Kj5z2WP+h/05mSdQ0N7+zpmu31T3ccCl16rKIQLNKcuu3GDxTNOCxiEkPNm6Df7RTS7a2Jwnqjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mqVhiy+MFBLokAbG+LL65Pd1+E/ku0s5/u4Px3qXxZ0=; b=bXYp0/BDQqNSFrfAf4yMhsQO7KRsZHb4gJZ2+csxlNp+tM8lX5pUkPczsJqebJ7BVazpUp4S3JZKaW+mpSeDsQt/o93qY/On41s2/1ZQjkUff8yf8wjmzEp62s8FixCCbE8rffgRMxAovdKuqOmKK9XpgZIHT2CVlO6Qmt8l93+fXFDt4p7GdgyUKS0KejlV4tNgYzvLeKRpU0dz5QQbo/V47ud+W/Qfd4Z1B0rd8EYy+sC8ni+k8erxqw82PRDHl7/osaUsjjCabVfJcImEev7mai1quh5v6CkztYyDt47Uwy49rNP4d7Kvsn+8Zx2p2VRbc3k8m1aDFdl6bjsKxw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linaro.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mqVhiy+MFBLokAbG+LL65Pd1+E/ku0s5/u4Px3qXxZ0=; b=nm6sSVMT7WH5AdzYhKR114L+vgTNT8N10HoZ9r1ySVWrrfMRb17j/SgVkU/SnQpJSZVDPhtvXO+fz/QUNdkhzm4f5qF/ZXgw5sK4Ytzexj4PXRK0I/sjXno6WkP51CQev/A4SXyBV9vPZHIF+vJQXInTUwR0FuTvbBcj3RprImE= Received: from SJ0PR03CA0036.namprd03.prod.outlook.com (2603:10b6:a03:33e::11) by MW6PR12MB8760.namprd12.prod.outlook.com (2603:10b6:303:23a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Thu, 3 Dec 2026 01:44:27 +0000 Received: from MW1PEPF00018891.namprd03.prod.outlook.com (2603:10b6:a03:33e:cafe::46) by SJ0PR03CA0036.outlook.office365.com (2603:10b6:a03:33e::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.662.7 via Frontend Transport; Thu, 3 Dec 2026 01:44:26 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by MW1PEPF00018891.mail.protection.outlook.com (10.167.249.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Thu, 3 Dec 2026 01:44:26 +0000 Received: from honglei-remote.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 19:44:24 -0600 From: Honglei Huang To: , , , CC: , , , , Subject: [RFC PATCH v8 3/5] virtio-gpu: remove the artificial IOV mapping limit Date: Thu, 3 Dec 2026 09:43:50 +0800 Message-ID: <20261203014352.1792475-4-honghuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261203014352.1792475-1-honghuan@amd.com> References: <20261203014352.1792475-1-honghuan@amd.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW1PEPF00018891:EE_|MW6PR12MB8760:EE_ X-MS-Office365-Filtering-Correlation-Id: ecee597b-c55c-4096-1503-08df50def71f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700016|376014|23010399003|1800799024|82310400026|10067099003|56012099006|261026121527099003|261021121427099003|261028144727099003|261021123027099003|261022105027099003|261026140227099003|261102123227099003|261009223027099003|18002099003|22082099003|11063799006; X-Microsoft-Antispam-Message-Info: i0xOcAesjBHoZBJ/Lt7m0DMrXZaXx0HweszjpqMrITlXWlqqcsdQGBveRhy+5xin/gSd2OSdXViTTgPbf86yVOVnuhdg4mc6hzuYlRXClsXuFlpmBGwEOwYHoFTs833Mklz9Ka8nksOOrjDsL50WY7GRVAcHM/rteVutjBLoWjtZBMEeft//EEjeeS+5RP8diqR3c592eb6WSRoiwDWdxXN8s+JaZ0P1D/EPwyJuQXHmr0ZSlBvq44a6uJxuaaTFF9BRPyIaAa0j4J+KfABvqZSWnsBEpcQsrFlpKqKN49bT/MT6ygfxXpqapYevv/22ZoDZPasLpweh5hTuPw1Be5s7hcjg9hxv2FsM4Bkt95gD9YB4hvS53ZsbLuiWLiLNdXSscF+9kF1BUszElWbYKytG66ZF+5bThI/yQxHeD73coZ+gUdRaogVyRJp17RNWCm6hfpvI/UhChSdacwr5tVOaBG+XYfk+5TFsB65GCezc5F8144ZLsWTcbsddYMuvvK/MhZ99S3tUHX6rjFScBdiJqjzBTDdEIdK2q8dzTfB+dkWyw85z6+eXxC5FfTQYUGdFKC93a1RBp/dVtDnL33Kfm+1ROmUJ4olfSD6eaAwPjaeO5QW8zgXkclG7Ltl/e/bCr0NMLkB+WgfBK+hK69I7efikLqDCJbmrW5lHcaPNTYlD8sOhy9SziI8q0oJoqhuHdY3ExgZwMgXHSJGr3A== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:satlexmb07.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(36860700016)(376014)(23010399003)(1800799024)(82310400026)(10067099003)(56012099006)(261026121527099003)(261021121427099003)(261028144727099003)(261021123027099003)(261022105027099003)(261026140227099003)(261102123227099003)(261009223027099003)(18002099003)(22082099003)(11063799006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: egNiGFQaI0LcoNo2z1yPQxt7lahk4602PlZw8MqHPw66SaF5npFoL9I7L8m3wiJxecI+WqOX8cSbm69gwDcGIKSEUeoAiLI1c2Blerd5CxZWGe5gIaL/4JN513StHnloReUE4BRVAq5SJCWtCXHMlUAGXEQwoCv3QGWN4HSll/I6h6FNzl/+dUuGT8pUUbX4NaG+avRi/GbG5NwYMXiXlsTf+CyhwNrzmmqpjYuISECIVLBBuS4o1K7s8gfQk64dCuDOP9MYJ2KVmwtS1E5tLF2zpMo1FUkZLOlVmDlN6YgfRCf1f/i12wpGwyeSmWdnPk1gE1I/6P0XANKNstYi5s7soJZIiAEaWMci/ayv+pb8Jyl0eOvfoOHByKCQfflZTk8cnpVztDl29nDipi3hK7DxYgVG7mpUGD6pTA+epOGp7hpwGn4X8tj5LoNU1pS2 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2026 01:44:26.7515 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ecee597b-c55c-4096-1503-08df50def71f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MW1PEPF00018891.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8760 Received-SPF: pass client-ip=2a01:111:f403:c007::2; envelope-from=Honglei1.Huang@amd.com; helo=MW6PR02CU001.outbound.protection.outlook.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_GIT 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 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; - 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