From nobody Sat May 30 17:31:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1779921271; cv=pass; d=zohomail.com; s=zohoarc; b=dyR9Riu2WHPpeuUm5lHdi0ku8l/LeMTYmmNtYvm3jsroIYXGs/RifrYPf5RfVg/YqZkzcNTqgFE+0ygn3RJvGzZnYmDARlzGcpuHnRpM/uVFz5IbghNdCGGy1pcLM3eZN9OHlh1+BOfqr26SmQ/fIjhs0u1iL7RJw/1igBklmCQ= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779921271; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8Sv8ro5aoDR/R26arscjZRg3DmMdkac/V5TGynVGHjI=; b=hFKDyUSqHt1CGocdjyuEYgaS+rFFYYLmNZBFnS3gbMKTAzcsHNDbba0Qbc1/4YgJ/W3ZP+cFPvNARRacUvMOgi1250ppvEqZoytr/TZ+L24Uo/a+cIwZ05OSELLVbutzdBWmvmmnCjRpA5zQuypOn1JHiGQS6rEYOza437r+/8Q= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779921271496391.8308240342459; Wed, 27 May 2026 15:34:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSMor-0007O4-96; Wed, 27 May 2026 18:33:45 -0400 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 1wSMon-0007Ne-9o for qemu-devel@nongnu.org; Wed, 27 May 2026 18:33:41 -0400 Received: from mail-westus3azlp170120001.outbound.protection.outlook.com ([2a01:111:f403:c107::1] helo=PH8PR06CU001.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 1wSMoj-000063-Qd for qemu-devel@nongnu.org; Wed, 27 May 2026 18:33:40 -0400 Received: from BYAPR21CA0009.namprd21.prod.outlook.com (2603:10b6:a03:114::19) by MN0PR12MB5811.namprd12.prod.outlook.com (2603:10b6:208:377::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.12; Wed, 27 May 2026 22:33:21 +0000 Received: from SJ1PEPF00001CE6.namprd03.prod.outlook.com (2603:10b6:a03:114:cafe::7c) by BYAPR21CA0009.outlook.office365.com (2603:10b6:a03:114::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.92.4 via Frontend Transport; Wed, 27 May 2026 22:33:21 +0000 Received: from satlexmb07.amd.com (165.204.84.17) by SJ1PEPF00001CE6.mail.protection.outlook.com (10.167.242.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Wed, 27 May 2026 22:33:20 +0000 Received: from localhost (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.41; Wed, 27 May 2026 17:33:20 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=huJunUiyZ2SnbCXurojc0MtHp72EXAO41TvKt4HVCOITJ8JnNHDptaTVBRIG64B0GIBzDIf5OhUPG6SaxTSkIO47fylFZyh/QCdaxVRELDMX8SmHg7ekbDQ2BfnngHOi8cAbSkcEqGzO/IQUs/x8NRlt4gx0NuhBatNN0OFF1A4UW9RReRpUrb9+5xHq05nu9aklplG3vnDbInPLffowgJdIDYbIQTgZb1YdZdTRaA2rcY/o2Fp3kK4HWFzCTq71Rr4JuV5SWB3OjdTOSfWV0FHK2ImYq+gg1vmGQ0aMl48Rf01rtlK+CwX3uh+PgBzNDpnX1vzwqB1A8d4ho8JBFQ== 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=8Sv8ro5aoDR/R26arscjZRg3DmMdkac/V5TGynVGHjI=; b=D/tR64b5+QpmC6oDTE1ht5BAjBw6oDMEFQEpA0tRJqJirvv3AeI0hmTjc02gkuuaK9NI7yNtlc+Bfc45m/sqYQYQ+SpFJXUyLNMeneRbvhlSAG60I/xtIDOF5CHXcMxnU+51Mmx7wSAC7cuQHmST7DTFFN2Gj9fGjdUky4TAC61v0tjuSxR7BopEeqOY0a2gEMwPXEBZDIjq+BWr89aRaxX2y+ZxPmhP21bpHyMlMJBGho/qN+5qQyQV0eGUjvwDaQhfUKe6Nu/y2c8/xMmudg9wUYUB7AoGQT9ouoT+Byh++pPDrYCjujDsN518gIEAuMXcFSpBNbCFyJLVVsfiNA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nongnu.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=8Sv8ro5aoDR/R26arscjZRg3DmMdkac/V5TGynVGHjI=; b=UC+M6L6/qedTXnDmMDSXlKu0DoCRstWHVm8rd4/prUMgbpi17TFAg+8yFi5p3MxjHq/7+3SVuAq53mKgtj+UhNWbzPh8/nnQxd5+jDU23Q2Tis2VEJhRkgwSEWZ0LLnCtGaAxi8YmjtduLudEls9LVhGZiaUNp3Kozl1V4loKh0= X-MS-Exchange-Authentication-Results: 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 (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; 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 From: Michael Roth To: CC: , , , , , , , , Subject: [PATCH v1 1/4] accel/kvm: Add helper for handling conversions of MMIO holes Date: Wed, 27 May 2026 17:28:24 -0500 Message-ID: <20260527223036.4614-2-michael.roth@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260527223036.4614-1-michael.roth@amd.com> References: <20260527223036.4614-1-michael.roth@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE6:EE_|MN0PR12MB5811:EE_ X-MS-Office365-Filtering-Correlation-Id: a43d4964-19a7-464d-1aac-08debc3ff4c5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|376014|36860700016|18002099003|22082099003|11063799006|56012099006; X-Microsoft-Antispam-Message-Info: eWds9xAueLas9CjGAX3jH9HAPhBK4TZOko9UdBcynshevL2wY1iarbPKIMWMTE4W41Kq4wIulgLerQUUIED+EZiKOt6tvjFlelGtta3ubfm53BJDzsinpHJgBi39Sx02yQ1N08hM7sxOg5Dt0Je/13rqDh7mx7Uj//JGJ7MgvoruepOTAf4lj4eKOC1oVniYMTSNCwWpSc4JX1LWzfILBlEtQLLEp1NL3vppZHJQsZX46P0VhGl0F3jk3IhGIWkSp5xYY5h5iFYip6mv9qCCXqWP8hC4jZyzOnowIhFuWI09Dn145GN0AgVf4WtT4yrC1lTnxXgaORFvLjmO0iMarDftI6FauSnL8I2ZRtUTZEWS4QkebVH34GMx2lkxoE//fHDP5Ck2nQ4oyiaac7g6t+Acepk97VDvngoMOMwNYVH9IEk4taAC8tLpb9MFsN1dkM5cpRUylLsEuLDH5bKIvVn1BWUzNZGfcB9t78AEue2+GSGAZpXMoT0gVLF1Z6nTXYFY2sLPGV3a8G/IUK7U+nT+MC79+8FNBZMrvALTk0xkn6cSWrL11UxIJwIqzslTc6cjWUtfR8/6a8/oddMxzsKgL5eita/BmnnzRQvlP0zUQ2UJSnR+CmC5l316vm5JknC/a+vmW2KiNHv/b5Mi4q1lkHGYcvO2vM5ZiqX5gsG5Msq+dy4hKUambnEnMb2tEncSvT2bh4wlm+3+86rSuKmExzKQwuaIzPKS2czjw+g= 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)(82310400026)(1800799024)(376014)(36860700016)(18002099003)(22082099003)(11063799006)(56012099006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cYPbsgV83Uqf65zMDA40piEqEKOjSs+vw46D03MTgwa9il8KnwpWHWbqThrfX1WaJ7A6koIQbrntf4dk17Pe5WHi6yCqf9irR0BKS+fSj8JVzrynotvWB/RDB4JlG71yk+3x1eVfMSZiVFz1XVx+y3twTzmBefpTxP/sUK1hKOvfHmZE4NO91tEeKo7U6Ck+VmucG4QEM4VrLSl678/PcK9Y53sZmFtdP36xuPJT4TTwhJENlZuWw5vJ38JGd9KeDEECoFvITTwtVeG0NL+sCy9qKCwne2Qk64kt8GUCCxiiX9xOZFDARP1AuLFmTDwmoegXKIEvrsaHhXJ+zwCzczQF0AvZ7wP1K7yFvU0/+SAJonUffmqzEOf00PLT1citNBBWRc56Xw7RwF37FLMpTBAZO6citUjy7Irk2+hXE5ia4Zmqa1QeALmA8QnyUoXK X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2026 22:33:20.7683 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a43d4964-19a7-464d-1aac-08debc3ff4c5 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: SJ1PEPF00001CE6.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5811 Received-SPF: permerror client-ip=2a01:111:f403:c107::1; envelope-from=Michael.Roth@amd.com; helo=PH8PR06CU001.outbound.protection.outlook.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, 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-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1779921274282154101 Content-Type: text/plain; charset="utf-8" When converting GPA ranges containing MMIO holes, the general intended logic is to skip MMIO ranges as long as it is a private->shared conversion, and to fail otherwise. To better enable some future refactorings to address bugs in the current code, go ahead and consolidate all of the MMIO handling to a self-contained helper. The only intended functional change is that the error message for shared->private conversion of MMIO ranges corresponding to a non-RAM/non-ROM region now report the range of the region that specifically caused the failure, as opposed to reporting the entire conversion range. Signed-off-by: Michael Roth --- accel/kvm/kvm-all.c | 96 ++++++++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 32 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 96f90ebb24..24117b4634 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -3339,6 +3339,67 @@ static void kvm_eat_signals(CPUState *cpu) } while (sigismember(&chkset, SIG_IPI)); } =20 +/* + * This handles checking whether a conversion overlaps with any holes in + * the given section/range, and indicates whether or not the section/range + * can be safely skipped (which is generally allowed as long as the + * conversion is private->shared and not the other way around). + * + * Returns 0 if section is normal guest-memfd-backed memory, or is a hole = or + * non-RAM/ROM region that should be skipped as MMIO. In the latter case, = the + * 'skip' parameter will be set. Returns < 0 if the conversion request is = not + * valid. + */ +static int handle_memory_hole(MemoryRegionSection *section, bool to_privat= e, + bool *skip) +{ + MemoryRegion *mr =3D section->mr; + + if (!mr) { + /* + * TDX requires vMMIO region to be shared to inject #VE to guest. + * OVMF issues conservatively MapGPA(shared) on 32bit PCI MMIO + * region, and vIO-APIC 0xFEC00000 4K page. + * OVMF assigns 32bit PCI MMIO region to + * [top of low memory: typically 2GB=3D0xC000000, 0xFC00000) + * + * If the current lookup failed to find any regions, then skip the + * entire remaining range as a hole/MMIO. + */ + if (!to_private) { + *skip =3D true; + return 0; + } + return -EINVAL; + } + + /* + * Because vMMIO region must be shared, guest TD may convert vMMIO + * region to shared explicitly. Don't complain such case. See + * memory_region_type() for checking if the region is MMIO region. + */ + if (!memory_region_has_guest_memfd(mr)) { + if (!to_private && + !memory_region_is_ram(mr) && + !memory_region_is_ram_device(mr) && + !memory_region_is_rom(mr) && + !memory_region_is_romd(mr)) { + *skip =3D true; + return 0; + } else { + error_report("Convert non guest_memfd backed memory region " + "(0x%"HWADDR_PRIx" + 0x%"HWADDR_PRIx") to %s", + section->offset_within_address_space, + int128_get64(section->size), + to_private ? "private" : "shared"); + return -EINVAL; + } + } + + *skip =3D false; + return 0; +} + int kvm_convert_memory(hwaddr start, hwaddr size, bool to_private) { MemoryRegionSection section; @@ -3346,6 +3407,7 @@ int kvm_convert_memory(hwaddr start, hwaddr size, boo= l to_private) MemoryRegion *mr; RAMBlock *rb; void *addr; + bool skip; int ret =3D -EINVAL; =20 trace_kvm_convert_memory(start, size, to_private ? "shared_to_private"= : "private_to_shared"); @@ -3361,39 +3423,9 @@ int kvm_convert_memory(hwaddr start, hwaddr size, bo= ol to_private) =20 section =3D memory_region_find(get_system_memory(), start, size); mr =3D section.mr; - if (!mr) { - /* - * Ignore converting non-assigned region to shared. - * - * TDX requires vMMIO region to be shared to inject #VE to guest. - * OVMF issues conservatively MapGPA(shared) on 32bit PCI MMIO reg= ion, - * and vIO-APIC 0xFEC00000 4K page. - * OVMF assigns 32bit PCI MMIO region to - * [top of low memory: typically 2GB=3D0xC000000, 0xFC00000) - */ - if (!to_private) { - return 0; - } - return ret; - } =20 - if (!memory_region_has_guest_memfd(mr)) { - /* - * Because vMMIO region must be shared, guest TD may convert vMMIO - * region to shared explicitly. Don't complain such case. See - * memory_region_type() for checking if the region is MMIO region. - */ - if (!to_private && - !memory_region_is_ram(mr) && - !memory_region_is_ram_device(mr) && - !memory_region_is_rom(mr) && - !memory_region_is_romd(mr)) { - ret =3D 0; - } else { - error_report("Convert non guest_memfd backed memory region " - "(0x%"HWADDR_PRIx" ,+ 0x%"HWADDR_PRIx") to %s", - start, size, to_private ? "private" : "shared"); - } + ret =3D handle_memory_hole(§ion, to_private, &skip); + if (ret || skip) { goto out_unref; } =20 --=20 2.43.0 From nobody Sat May 30 17:31:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1779921271; cv=pass; d=zohomail.com; s=zohoarc; b=NudsHXDYRuCqK25kjwBshROGGKVermbxklvntVzf0jRebq/dy9VmoO0k/4gpTLMCjpq+kEPerveyesGGnRfgcmpsRRVXECAWrmqyzZfGOiTfUyikazqCJXFaX1m9DbIlfHZGD2cuW1GjBBmCh1dGHRjJihGCg6RBTye7UnQFFF4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779921271; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fPDQcaDDcFtgLoG0zoHjVcSmbXW9MRa9/4MFQJObqbA=; b=ENcauHYRw86S0mbcW9A7xOjksEtDlmo2xG5Kbf4K2O1b68Mqt1Pk+wVbnEB+6u4glsPcz3yAwzZnJ0Z+vB9+pGCbHMfveKvUr5KkYwzN5mMnrDzHWeHV9BpusqkxC9lURZ45sZpWXzNFCH/TWVJB7o2BgvGbxo6Wv+5t3vDD/3U= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779921271242865.15845415267; Wed, 27 May 2026 15:34:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSMoz-0007Pp-Cq; Wed, 27 May 2026 18:33:53 -0400 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 1wSMox-0007OX-4k for qemu-devel@nongnu.org; Wed, 27 May 2026 18:33:51 -0400 Received: from mail-southcentralusazlp170120001.outbound.protection.outlook.com ([2a01:111:f403:c10d::1] helo=SN4PR2101CU001.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 1wSMov-0000By-36 for qemu-devel@nongnu.org; Wed, 27 May 2026 18:33:50 -0400 Received: from BY3PR04CA0011.namprd04.prod.outlook.com (2603:10b6:a03:217::16) by MN6PR12MB8565.namprd12.prod.outlook.com (2603:10b6:208:47d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.12; Wed, 27 May 2026 22:33:42 +0000 Received: from SJ1PEPF00001CE9.namprd03.prod.outlook.com (2603:10b6:a03:217:cafe::87) by BY3PR04CA0011.outlook.office365.com (2603:10b6:a03:217::16) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.71.13 via Frontend Transport; Wed, 27 May 2026 22:33:42 +0000 Received: from satlexmb07.amd.com (165.204.84.17) by SJ1PEPF00001CE9.mail.protection.outlook.com (10.167.242.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Wed, 27 May 2026 22:33:41 +0000 Received: from localhost (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.41; Wed, 27 May 2026 17:33:41 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QxjiVqNB3Fq074lMehk35FguJFosWbWanCH405YbkVvSwnw3JGQDj7XWmeXd/eYBybqPyb8+zKhCpDt1nAzjk10kUjjOVL8MNpKl5WOWZkMnCFlKehl7x4NZVdVDiolFmzL2P9qg82xYUKAeskx7oQh1dPFNGBlaYQAf/gfgCscpSygrC7+uDkYJSotyWek5ojf/8NpCtO91qIHAl3tJTOTCwE/yU301NkR6CQYxaTtd6+SYDx7Myv10vGvpyzW8x44uSFX9EHIbr4gQRv1zi10ycLE42Ss+qV+LTaRxrxtsu9P/7xwSi4N57nY0s0ay+u3Uo16kraLMH0msWFS8EQ== 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=fPDQcaDDcFtgLoG0zoHjVcSmbXW9MRa9/4MFQJObqbA=; b=hqX2LmQ94MNp/oBgnwBHkbyFABIvzsMKdouEamnKsbUQUidGJkOLQKsSe9XZRm2u+XKp2Nhwa0mDD4TsFXk1keZ/KFjbEVVY0gPE6PWhaAP2Q6nCb2mNZqtY/EWFk4GfqTWHKw1Nj2s2Qv/A8sSHtqqhaQRiQmF0jA43CzTICyWRD9bJs2g1zLEr5EmdPWjsrV2h6lCvgyMS3C+XphRXoRKizmGc384Tv2hG4gU0EBr2JtVRKj5tig7Sh9cPYpQDuqaJ69xyvEY0RaPDmiwvN0dlqFv4oBHHE4o0gd4IIzy1ZqQ9Vl66D3HEddtlqJkfOUVr1lUPCMNFKOPTf4Q+eA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nongnu.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=fPDQcaDDcFtgLoG0zoHjVcSmbXW9MRa9/4MFQJObqbA=; b=e9N2GVFK6RHEdcmh662wqpCpAQt3z1OaG/jlxqTEa1GgcwqWovIe5rGDboq8M/4j0baXBRz6iFF9givTqzxZmnw8LTpOOhhuTfy1qvOEjnba+XIB7UDco/F1gwKzxlT1t398Hl2O5U0PUVX/O5BkzIk5bVfDLh0x1a5pi0ZJYJ4= X-MS-Exchange-Authentication-Results: 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 (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; 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 From: Michael Roth To: CC: , , , , , , , , Subject: [PATCH v1 2/4] accel/kvm: Fix kvm_convert_memory() calls crossing memory regions Date: Wed, 27 May 2026 17:28:25 -0500 Message-ID: <20260527223036.4614-3-michael.roth@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260527223036.4614-1-michael.roth@amd.com> References: <20260527223036.4614-1-michael.roth@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE9:EE_|MN6PR12MB8565:EE_ X-MS-Office365-Filtering-Correlation-Id: e85a7ee2-f5e5-4412-f9fc-08debc400149 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|36860700016|376014|1800799024|11063799006|56012099006|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: ZpqEQ0kT4EIcCfLSSCpzcvl36kCnrETxpUnEgeXml9GR289hpZ1cX+XGZpEuE1s5+bQVoLq7xyeOJoEALnO6XlRE8M93XHD+gvLnYI0T58SkNTUxr4fl4wH4mpmFF4cRZOZY/CRYxU5SiF1ofk7aBNvBI/F0w3qonmcRgnXa2OQn/rCJsoKJLfPx/oZ9NXfDFVL4Y+u3ArkgC0iOUqjk+m4kzfCn1lJIxybf1FEUrdKMjGIpIvfmd0kn41SaTxyONfSV3efUsmqAWaMW4830T/vC6EQc/MVxOiT7/n2n5d6nS5zBCJrX+A6qk2+yqAVaAVyTkiAl7XXKawZ+HW9KLMqk3D7Z0rgUX0KnAd3aqyKkU8Bxb7aMFSdIW446fkXo/GGGI8B0UIqm2AajweWLNYY0iA6uUyAxOlUJwJPnuFxNtX7p7RzcX/3H2s7PjncUVmiDtDn2XdZ0Tjwo8ohPHMy8tEha5gyOL22Uw9hBfiwmCBoinHm+z0G1mXJcyleyg+t4P3vj5nHbhrIMPgfbIqFSyKNbpMPkyPp8jcDW61Wir5xg9rAYd/C/7x7ib/kJ8nZ6dzTN+gtiYM+oNaQC+pkvDN3aCJnBqtSwFs/56IE/2FCyRqHa9FRETPTYOIyH8ApXwX8F+M21Io26PaTiRxJ5MGP5JASWez/W0jFRIkRWVfx+0yLy6Z4yFdAvQ+B7xdcYiaZLOkqxLY+iybXfWvSPa1miOb6XjdyP7TWgB1w= 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)(82310400026)(36860700016)(376014)(1800799024)(11063799006)(56012099006)(18002099003)(22082099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: iDGts0vaYRwkSj25evIJsIDYeAvUB1PJnP/snveHGhNru24vObMfKrEhyw0vI0Z/vXW8TRMWgbKWzq6Fh8DOk9NF0GFQta06rbh53zdJ2QayT4QSB7vccpz5VJeef692eIiFh6fLlcp1k7eH6BdGGocW4zrekm3ccC0MaxqeAAFW+9V4fjrzaENRmjtfIGSTsXCF4fCgiC7w2opidhXCeYAp3KL1xfo+qF+SfjSYXKJZNSHJfvEgOLBgNJ1OUaJG9VNSFFcgj5v10NcnR8JGU/fey5XEWAJUQeVIynsYW+SMBDPxnt5udKQxRgzAy20gk+yU3pYg94RI4BvA/QsFZaPqf2ZSvfLciz+ntC3bUsYiEfRQo1x6XfzNUcy3ovKm0NfbpbdIXDvkMo7/7aFV8mR+grgm6cP1EStFqhIM8mKwzQiUizTIFBaPSx+Sk7Ea X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2026 22:33:41.7472 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e85a7ee2-f5e5-4412-f9fc-08debc400149 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: SJ1PEPF00001CE9.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8565 Received-SPF: permerror client-ip=2a01:111:f403:c10d::1; envelope-from=Michael.Roth@amd.com; helo=SN4PR2101CU001.outbound.protection.outlook.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-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-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1779921274282154100 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra Page conversion calls can span multiple memory regions, potentially resulting in a conversion failure if the memory range being converted extends beyond the boundaries of the referenced memory region. Handle the case of page conversion calls straddling across memory regions by looping through the subregions and handling conversions and related work section by section. Fixes: c15e5684071d ("kvm: handle KVM_EXIT_MEMORY_FAULT") Signed-off-by: Ashish Kalra Co-developed-by: Michael Roth Signed-off-by: Michael Roth --- accel/kvm/kvm-all.c | 94 ++++++++++++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 31 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 24117b4634..21e8404e61 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -3400,54 +3400,35 @@ static int handle_memory_hole(MemoryRegionSection *= section, bool to_private, return 0; } =20 -int kvm_convert_memory(hwaddr start, hwaddr size, bool to_private) +static int kvm_convert_section(MemoryRegionSection *section, bool to_priva= te) { - MemoryRegionSection section; + hwaddr start =3D section->offset_within_address_space; + hwaddr size =3D int128_get64(section->size); + MemoryRegion *mr =3D section->mr; ram_addr_t offset; - MemoryRegion *mr; RAMBlock *rb; void *addr; - bool skip; int ret =3D -EINVAL; =20 - trace_kvm_convert_memory(start, size, to_private ? "shared_to_private"= : "private_to_shared"); - - if (!QEMU_PTR_IS_ALIGNED(start, qemu_real_host_page_size()) || - !QEMU_PTR_IS_ALIGNED(size, qemu_real_host_page_size())) { - return ret; - } - - if (!size) { - return ret; - } - - section =3D memory_region_find(get_system_memory(), start, size); - mr =3D section.mr; - - ret =3D handle_memory_hole(§ion, to_private, &skip); - if (ret || skip) { - goto out_unref; - } - if (to_private) { ret =3D kvm_set_memory_attributes_private(start, size); } else { ret =3D kvm_set_memory_attributes_shared(start, size); } if (ret) { - goto out_unref; + return ret; } =20 - addr =3D memory_region_get_ram_ptr(mr) + section.offset_within_region; + addr =3D memory_region_get_ram_ptr(mr) + section->offset_within_region; rb =3D qemu_ram_block_from_host(addr, false, &offset); =20 ret =3D ram_block_attributes_state_change(rb->attributes, offset, size, to_private); if (ret) { error_report("Failed to notify the listener the state change of " - "(0x%"HWADDR_PRIx" + 0x%"HWADDR_PRIx") to %s", - start, size, to_private ? "private" : "shared"); - goto out_unref; + "(0x%"HWADDR_PRIx" + 0x%"HWADDR_PRIx") to %s, ret %d", + start, size, to_private ? "private" : "shared", ret); + return ret; } =20 if (to_private) { @@ -3456,15 +3437,66 @@ int kvm_convert_memory(hwaddr start, hwaddr size, b= ool to_private) * shared memory is backed by hugetlb, which is supposed to be * pre-allocated and doesn't need to be discarded */ - goto out_unref; + return 0; } ret =3D ram_block_discard_range(rb, offset, size); } else { ret =3D ram_block_discard_guest_memfd_range(rb, offset, size); } =20 -out_unref: - memory_region_unref(mr); + return ret; +} + +int kvm_convert_memory(hwaddr start, hwaddr size, bool to_private) +{ + int ret =3D -EINVAL; + + trace_kvm_convert_memory(start, size, to_private ? "shared_to_private"= : "private_to_shared"); + + if (!QEMU_PTR_IS_ALIGNED(start, qemu_real_host_page_size()) || + !QEMU_PTR_IS_ALIGNED(size, qemu_real_host_page_size())) { + return ret; + } + + /* + * Page conversions can span multiple memory regions, for example, if = two + * memory backends are added to support two different NUMA nodes/polic= ies. + * Handle the covered sections accordingly. + */ + while (size) { + MemoryRegionSection section =3D memory_region_find(get_system_memo= ry(), + start, size); + hwaddr section_end; + bool skip; + + /* + * If there's no region present, then the current hole "section" + * consumes the entire remaining range. In that case, update the + * relevant indices to terminate the loop after this iteration. + */ + section_end =3D section.mr + ? section.offset_within_address_space + int128_get64(section.s= ize) + : start + size; + assert(section_end > start); + assert(section_end - start <=3D size); + + ret =3D handle_memory_hole(§ion, to_private, &skip); + if (ret || skip) { + memory_region_unref(section.mr); + break; + } + + ret =3D kvm_convert_section(§ion, to_private); + memory_region_unref(section.mr); + + if (ret) { + break; + } + + size -=3D section_end - start; + start =3D section_end; + } + return ret; } =20 --=20 2.43.0 From nobody Sat May 30 17:31:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1779921271; cv=pass; d=zohomail.com; s=zohoarc; b=FWTskJcY9p4jGZH7O6WT0eiJHUPeoJA5eDtpujq3q3XMWy3GtLEC9NPT0qGG42QLT0B6FdiD0d8uu98lYR8JXYvPqg3rkDZUCoyYBBfzGnt0/fgqY2kgTtxmlGpp2gsay2tmwvYR0QKdaK48kkG5bHNHZNyr4OGtbqIUn87xQE4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779921271; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=R5Pj4K1CTPVwSoBdlQ1uR/NenHacWMMO2apNTiaUVu4=; b=VDiy4Jj3ycNFJgUJZY6V6/STYbvkk7o8knNkFJm52yUGDB/Wsajsg3sqs0aqSdC0A+oAGIavdbWyG3rs28GjAi8ds82xl9bHZClhiw0nX8n4M2dZLi/jzkzbjylduk5xhQr3JKYMbLvk50QM2Y/JOxknRl9dO2h9NIB51WAHQ4k= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779921271331171.18298163231577; Wed, 27 May 2026 15:34:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSMpI-0007Xf-TS; Wed, 27 May 2026 18:34:12 -0400 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 1wSMpH-0007XU-Ei for qemu-devel@nongnu.org; Wed, 27 May 2026 18:34:11 -0400 Received: from mail-northcentralusazlp170130007.outbound.protection.outlook.com ([2a01:111:f403:c105::7] helo=CH4PR04CU002.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 1wSMpF-0000Gk-ET for qemu-devel@nongnu.org; Wed, 27 May 2026 18:34:11 -0400 Received: from BYAPR21CA0024.namprd21.prod.outlook.com (2603:10b6:a03:114::34) by DS7PR12MB5935.namprd12.prod.outlook.com (2603:10b6:8:7e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.12; Wed, 27 May 2026 22:34:02 +0000 Received: from SJ1PEPF00001CE6.namprd03.prod.outlook.com (2603:10b6:a03:114:cafe::3d) by BYAPR21CA0024.outlook.office365.com (2603:10b6:a03:114::34) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.92.4 via Frontend Transport; Wed, 27 May 2026 22:34:02 +0000 Received: from satlexmb07.amd.com (165.204.84.17) by SJ1PEPF00001CE6.mail.protection.outlook.com (10.167.242.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Wed, 27 May 2026 22:34:01 +0000 Received: from localhost (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.41; Wed, 27 May 2026 17:34:01 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EUZy9pEhf84gYNbcV1CPi/V7QyFF6GWfbqBcfBP+ToegD4J+evkw8b46s3vhCA0wAjTmYs5P/U6+Nesz6OGrn882zwsB4adGncRzuDUFmirZPPyC/GVztAGXmdCev7PiBXhUHC1s/VozNAWSKbOm0FkuzUj7mPz/hDkJXT6SZBza0BHB99JynHRjG8bqSjk64Ijpp0cLrwSyAW/e7cvNlyZ6nWdGXHGqHrd2YEoJdRH+1mcPtqqjP9gOcMexyCd91+CTDxUGd9v/FIe9UEfYVESnSXkY49rKavNDe0FJK7Z1CIOtNVLRRgowo1icQnDFLEc7Pge6ifFxY9enM1pExw== 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=R5Pj4K1CTPVwSoBdlQ1uR/NenHacWMMO2apNTiaUVu4=; b=XML1MA4m+02YLr9jJJENtdrbEs5ju2SQN/xdy+R9AkoB8q0PZQFChemADZoSrzWvd8sMh2GPo4QyMkaSjdQ6dp6dXRFWXzMDlUvU/OR1AKo9wfkccJxHQI4OfOoyNhjlxZcXraYJFZBinDdpqrwTy/gWaLE1nsWUXBgDrO/fckVO8r225BFpJ6JqfLMbIKZggxpesCro7hn0O2uyHvqRWsiZrAtxnvmwxwRdW1osR/Xt7YrF6gKDRQnQgRqCi1wudJYflipdNbZaOGuq5nQiz24AcqkJwM2CdXuEzYWzWlb0iNGyijHGp3Sgg4SdmhM/6ju/VF+Ot9C4NW2CjBb9Xg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nongnu.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=R5Pj4K1CTPVwSoBdlQ1uR/NenHacWMMO2apNTiaUVu4=; b=A8RdAZONqhK6d+aB1H+VIMlYUeP4vTHtlFGwyxNWy+1kpdVSJzdz3dCEWAi3Sbbl/jV2O8+2Z0+lP/8QPGVOSyWJCsHcrJegdgXa5dUx86pL6IFwUp0frOCJMcp6emtezt2NFIzId4EhBRTIBGddBiLYqQHHV2tv3n7+dyLv1gY= X-MS-Exchange-Authentication-Results: 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 (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; 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 From: Michael Roth To: CC: , , , , , , , , Subject: [PATCH v1 3/4] accel/kvm: Fix handling of MMIO holes at start of conversion ranges Date: Wed, 27 May 2026 17:28:26 -0500 Message-ID: <20260527223036.4614-4-michael.roth@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260527223036.4614-1-michael.roth@amd.com> References: <20260527223036.4614-1-michael.roth@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE6:EE_|DS7PR12MB5935:EE_ X-MS-Office365-Filtering-Correlation-Id: a1d098dd-62fb-4380-51b0-08debc400d57 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|36860700016|1800799024|82310400026|22082099003|18002099003|11063799006|56012099006; X-Microsoft-Antispam-Message-Info: PmrM33son+4B4w2V0gfUmX0jWHG4v4pLi3sexFbvMIYQeK1ClpwzwpNmD1kNXFoC/P1ejL9nxLd6Hc27ifpAVpKvwMUL/aFY4hm3CzU7NOpULP/AfdnLmmpEAcpID+NXt9HyYyxO+Ymj2+vPs5uK02o3eidMHkQ3nmqBVLrOyTJHaOZKsxYec2cOOC3naQ16uKlg7fHVr5nB5mrJ+6QjRO2w/sGitqyUvCH+V3gmX03xognVdXm2ZVBgjh3xZnekpK6n4oSvEq3VC8hqmtRoUL8kwTMP7vL77FkzIWqY3LWIbY6MaX6+63RbuwPGsdXLM6J8zLdnViHpV+DyES9pL5KwTNMJAwjWrVfdoj6BPhUmV3XZDtWMnphcMHbmlT4E+FPhmnPVC/9nnygaocsYEK2bdIUG18cgH/Us1tREA9hoUQr91qSqUHTYw3uzTJU2g+w/AGlknvD0cFOOIXNsmKa8TVUqhJ54XRGxuAJPrklbGI9Cd7rjpPjT6NmhYHzVMwLMStr3guQJtnV0zQdarv5jzJNwouwKHBGoOb/yD54ZsGUA0AmSG44cVvqcyXOGgPfP14pd6znqUjl4gX+ok6cupFYOC6ussPGMdnEkZsq9U8/9LulhotX1HOqdkn8Sg+JBsFuiGRESTK94mzz2Bart6vXeBwGipenWtcQPKCNRg1g8+LJfTmshE6tCdDenyS22c0oUkq6egha+l6GNrexcffob3v0cvkW6W6eXMzI= 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)(376014)(36860700016)(1800799024)(82310400026)(22082099003)(18002099003)(11063799006)(56012099006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dkhzeFi74FYGoooGUmTyFNys1rPWkqmltiTCFTwhPbOHxbc7Uh/H3TZ8ECTSyeIrzzdlgsBqaA06hFzM9Xku1t8h/1IHR5vGRmjZFlbXoWEJ56Y2CAn5x9Z219VSqP9kmrRAZCp7bSHiDBI1fWl/SUTITcdcFELJXHZNteQRYsZsgnTViyRhjY678AaQEy163ovNN++n+qidIgR8OnwqaraC7XSHUt9OgT0oyhaYtypO3P0DXfyNcI0YXyZ28V+GrESqrYpS27GUV5l1FvKsU5JIh/AOZXYMjt5v4Ck4Du3kyAPb6JgsXj27sJmcVCXpWnQUhgfTYl63KHekzQjedft5C/aTgFPSIeEjoqT2+hVuVLH2b1OCNLYPNskSDpJpMfEF3mKc5WeQyc6SdqlPC9r1M31z/a62sczyNookWbbOondrmbXF8Y4qYjDZV4B1 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2026 22:34:01.9910 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a1d098dd-62fb-4380-51b0-08debc400d57 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: SJ1PEPF00001CE6.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5935 Received-SPF: permerror client-ip=2a01:111:f403:c105::7; envelope-from=Michael.Roth@amd.com; helo=CH4PR04CU002.outbound.protection.outlook.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, 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_PASS=-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-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1779921273758158500 Content-Type: text/plain; charset="utf-8" Currently MMIO checks are done for ranges where memory_region_find() finds no regions within the entire range, or for cases where non-RAM/ROM regions at the beginning of the range. However, if the first region in the range is a normal RAM/ROM region, then the portion of the conversion range that overlaps the region is processed normally, but any MMIO holes that might be present at the beginning are ignored, so the checks are bypassed for those ranges. Plumb the 'start' GPA that was used to query memory_region_find(), and pass that into the MMIO-processing helper so that these gaps can be detected and MMIO checks can be applied appropriately. Fixes: c5d9425ef4da ("kvm/tdx: Don't complain when converting vMMIO region = to shared") Signed-off-by: Michael Roth --- accel/kvm/kvm-all.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 21e8404e61..609126b847 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -3349,9 +3349,14 @@ static void kvm_eat_signals(CPUState *cpu) * non-RAM/ROM region that should be skipped as MMIO. In the latter case, = the * 'skip' parameter will be set. Returns < 0 if the conversion request is = not * valid. + * + * 'start' corresponds to the starting range memory_region_find() was + * called for, and is used to determine if there are any MMIO holes preced= ing + * the region passed in so the appropriate checks can be made on those + * ranges. */ static int handle_memory_hole(MemoryRegionSection *section, bool to_privat= e, - bool *skip) + hwaddr start, bool *skip) { MemoryRegion *mr =3D section->mr; =20 @@ -3396,6 +3401,15 @@ static int handle_memory_hole(MemoryRegionSection *s= ection, bool to_private, } } =20 + /* + * In this case the region should be processed as normal + * guest_memfd-backed RAM/ROM, but still need to check if there are + * preceding holes to apply the MMIO checks against. + */ + if (start < section->offset_within_address_space && to_private) { + return -EINVAL; + } + *skip =3D false; return 0; } @@ -3480,7 +3494,7 @@ int kvm_convert_memory(hwaddr start, hwaddr size, boo= l to_private) assert(section_end > start); assert(section_end - start <=3D size); =20 - ret =3D handle_memory_hole(§ion, to_private, &skip); + ret =3D handle_memory_hole(§ion, to_private, start, &skip); if (ret || skip) { memory_region_unref(section.mr); break; --=20 2.43.0 From nobody Sat May 30 17:31:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1779921282; cv=pass; d=zohomail.com; s=zohoarc; b=BXK8lP7gWE+EgLFFcKbf/Des88PPKLRB+fZ4p0JK+/PnNgP9NZu5+1CERbohU7kOfk93/cOjQArFbFpZTfazHwYBdWpp2C3xMVAfuyXpSh1qbkPO8gYUVp/MIqNStSKMsQ7+2jBwz2dC9ir+2ErNkaz7d9JRh59nJmVh+0Dt5y4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779921282; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Jn0QaOHgfxFEwNtaDZU6DdicPc1tgKHeaBD3g/nw2AE=; b=PwlzmfFqI+b4kR5nEP/+cFEacMZvHlPfv5+sb9jfO6brm+tFc7N4QJZFfVg2eVHlprkOJipnndMVITFeqcgIRLJ/NjgTu0i6AxoacV32iAbSgiG4AKsluipxN45Kbij6l9qRZorPACEF17DYtvupocRe0HmK/fOLDIutmsJ5qT0= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779921282618360.7873404031267; Wed, 27 May 2026 15:34:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSMpa-0007dO-Qh; Wed, 27 May 2026 18:34:30 -0400 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 1wSMpZ-0007Yl-BV for qemu-devel@nongnu.org; Wed, 27 May 2026 18:34:29 -0400 Received: from mail-southcentralusazlp170120001.outbound.protection.outlook.com ([2a01:111:f403:c10d::1] helo=SN4PR2101CU001.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 1wSMpX-0000u2-Sf for qemu-devel@nongnu.org; Wed, 27 May 2026 18:34:29 -0400 Received: from DS0PR17CA0019.namprd17.prod.outlook.com (2603:10b6:8:191::8) by BL3PR12MB6475.namprd12.prod.outlook.com (2603:10b6:208:3bb::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.13; Wed, 27 May 2026 22:34:23 +0000 Received: from SN1PEPF0002BA51.namprd03.prod.outlook.com (2603:10b6:8:191:cafe::93) by DS0PR17CA0019.outlook.office365.com (2603:10b6:8:191::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.71.13 via Frontend Transport; Wed, 27 May 2026 22:34:23 +0000 Received: from satlexmb07.amd.com (165.204.84.17) by SN1PEPF0002BA51.mail.protection.outlook.com (10.167.242.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.7 via Frontend Transport; Wed, 27 May 2026 22:34:22 +0000 Received: from localhost (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.41; Wed, 27 May 2026 17:34:22 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Pc0/eV6qsSNwhYXJ7x9k7mFQFtoTUuImkEIJNMk3nDufK+g9TDG5R0AyjBP/RYFvW/HH0X83UTB8D+wvUoXPZ08im/uwCR8J799z82DJIJRa06k3nHsq1q2F911I9s7q4msX4v82HCwhOaAe0jDj+T+D1uhgXI+3toLhOLwmceMY6hMgkHI2umBGSMvSN6hgn+7Ow1eE67JUR4pOw3X6rwDj9c5F3PyT6ZnWYB2PRTwMO5u1to2E4+bvIIze/+pxsuAOiFbECkOf81bE3+xvuhA9J4GXLtMqwRHN71VZINOndYroYfQBzdvttdUHlcZZ9Fw8KzRjCzn3qmT5xcbUnQ== 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=Jn0QaOHgfxFEwNtaDZU6DdicPc1tgKHeaBD3g/nw2AE=; b=pmRIq9TcGDkt/IlBhP1XAtZ566+eR0Z0N6y2olKPyosi3fBON+QUMxJ96UXSCigGVxrD7XmLFEu51+M2Pi5sLvX+JX2ttC1Lz3S+kOH+iWu6WLbuthglDzDMtMjPeyXtLXAO2aC5eZEFzWpjoKzyvlPXxJ7x/R/M/Y4L6QpRIAydETst6uz6ml11niYRHUyvAvX3TOQgLedhs+edYbOfDsI5FFH/3qmioMrcOg33FXZyaRmyutSjVvjMBJCpUUnpX0RUIQM8RROUMQxL6QKmSFlZPJPgiiRfjCHrKy+XszIfishNjEmdFqDfmFtQ/zT7/U0IAd2Z1G5Kt203LAwM8A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nongnu.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=Jn0QaOHgfxFEwNtaDZU6DdicPc1tgKHeaBD3g/nw2AE=; b=0wqroaWVt8jJ0j940cczn5qAVRjFMz/EyVMkUMu4UKPnJOoSLd88JxL2LWx6GpZACR9pMyQHVAHQ4vU5o597o8QFJrlKbXcXuT1kMCcj88FafXeW74o0Frp5wqwcoruUZm9dHpuy/Sv815M5SNcpZ9drddG2F1d3yTQ8DOQXyhA= X-MS-Exchange-Authentication-Results: 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 (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; 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 From: Michael Roth To: CC: , , , , , , , , Subject: [PATCH v1 4/4] accel/kvm: Fix handling of conversion ranges with multiple MMIO holes Date: Wed, 27 May 2026 17:28:27 -0500 Message-ID: <20260527223036.4614-5-michael.roth@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260527223036.4614-1-michael.roth@amd.com> References: <20260527223036.4614-1-michael.roth@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA51:EE_|BL3PR12MB6475:EE_ X-MS-Office365-Filtering-Correlation-Id: be54258b-4504-422e-dc1b-08debc40199e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|82310400026|36860700016|1800799024|18002099003|22082099003|11063799006|56012099006; X-Microsoft-Antispam-Message-Info: pa5bY5WzIWrZqqIiK6ld9A3sKJ8rXSEhgl0JghPtPYgCn83ps9I15qFKWseV0k4uvE5Vtqo2N+a2rBATFHFmxt7GarG+kLB3Alj5zKGE5HWO+AmGIT3E0l4DFNIyuP3Dwv0woCRM4BGvj1KX7ct4K1I2yvvAZN3CYsi9wmYfTOBikrOGaAQg5bG9qAprYjTEJOh0HvDC9LvBZ1r2x+O/YQuNw8brSKFg5QOqku/RnayseF1sKjPBOdJzojrChzigh2HMMciyOt+QFgaQtwh6XNgaxKW63t9Dw1bsk/Ez4cpv9s7HQFCn14MRCZs/IiOt8bu8BwQ00Jt78Y1AEu8Dkw8ed27/V+lqS+p5zzl65rdRa/AXbiki3ihbMDit/I3fgBiglvM2ZTuiPy7g9wnRInNBI+wqU+gLBUcb2VLC+ZjSEClTLNfC/roqGO9Wm97f6xuaDhOSlOgKS7taqkumxolvMaDIMceKjch6q5uFWpkPzfVgqLsM506X4nWYGf6C+pY9VbZrUPUP6J2V/+92Kh4eqYBipifuOUFoBErcTAtXtYUc22yZYGTZK9tQjqkgdQJ0lEHH1ARpnbc7s+zSUA86FFPWnjeL5aAafoLVTzeRH/jGA+jRiGUx28t+BwH6LC9nPEAF9quyWO/SLKY8bowDH+DSkpodwHJ76ouU9YmEi6iVzbCZHlBr6BZr7+PTCRFX2nwq/1gJUWT29tWfp+jhxANNB598DCIDk+O/9w4= 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)(376014)(82310400026)(36860700016)(1800799024)(18002099003)(22082099003)(11063799006)(56012099006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jL5PtM55Fqb4ymY9Dk5RLemWLiw4WFD3ART1p427fSrHw8QdVticW1HGCtwgWP39rrE20qBf9tY8LnJSvqJNzv2YXFtAUfBa577QbVvCRtiz6LSH9BjgOxKeYOYaLxtYnnei8PLzy+PmYyzbPm7lRScdXU+4/myHqGw18EfcVjulErK2o+kC2KTAVBHfDUNcdNof/PR6lMStDlDmI2wnKKjEIu8f9LISh6h7qcMZyaJ88hWndIlLl2AKEoyoFifAkUG7unnSc9gBazXpgebaAa4IBVyTfuBjSYLd6J3plr8gclSnhTHvekVIE+HkAqrmpQRE0lz2anzD1Aum6zeg1wY3AjFAcNyP1V7y4wn6KUohuZEKj7CuAgqlsGYA3Z+LLNkFwFLlKbfAxPl/B2r609mt34uzSmitW0+u7QWoeYFrDlYMIjSSprYF4U28Skm4 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2026 22:34:22.6611 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: be54258b-4504-422e-dc1b-08debc40199e 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: SN1PEPF0002BA51.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6475 Received-SPF: permerror client-ip=2a01:111:f403:c10d::1; envelope-from=Michael.Roth@amd.com; helo=SN4PR2101CU001.outbound.protection.outlook.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-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-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1779921284989158500 Content-Type: text/plain; charset="utf-8" The current handling will properly handle MMIO checks for holes anchored at the beginning of the conversion range, but misses subsequent holes. The current handle_memory_hole() helper already processes all MMIO ranges up to and including the sections found at each iteration, so handle this by simply calling handle_memory_hole() for each additional section/sub-range. Fixes: c5d9425ef4da ("kvm/tdx: Don't complain when converting vMMIO region = to shared") Signed-off-by: Michael Roth --- accel/kvm/kvm-all.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 609126b847..585f1cea35 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -3497,7 +3497,12 @@ int kvm_convert_memory(hwaddr start, hwaddr size, bo= ol to_private) ret =3D handle_memory_hole(§ion, to_private, start, &skip); if (ret || skip) { memory_region_unref(section.mr); - break; + if (ret) { + break; + } + size -=3D section_end - start; + start =3D section_end; + continue; } =20 ret =3D kvm_convert_section(§ion, to_private); --=20 2.43.0