From nobody Sun Dec 22 08:51:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1733963302789745.2543324661403; Wed, 11 Dec 2024 16:28:22 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id B243812DC; Wed, 11 Dec 2024 19:28:21 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 617741273; Wed, 11 Dec 2024 19:25:21 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8248F1273; Wed, 11 Dec 2024 19:25:15 -0500 (EST) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2057.outbound.protection.outlook.com [40.107.236.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 89C36128C for ; Wed, 11 Dec 2024 19:24:58 -0500 (EST) Received: from SN7PR12MB6838.namprd12.prod.outlook.com (2603:10b6:806:266::18) by PH0PR12MB7791.namprd12.prod.outlook.com (2603:10b6:510:280::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Thu, 12 Dec 2024 00:24:54 +0000 Received: from SN7PR12MB6838.namprd12.prod.outlook.com ([fe80::529d:478:bc5d:b400]) by SN7PR12MB6838.namprd12.prod.outlook.com ([fe80::529d:478:bc5d:b400%6]) with mapi id 15.20.8251.008; Thu, 12 Dec 2024 00:24:54 +0000 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, FORGED_SPF_HELO,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS autolearn=no autolearn_force=no version=3.4.4 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gbX+z9w4l0nrtYVqlAHFxy75UnQldAymsBIHv2Nd5smbCpm+LHH6a/ZJ1ZmjqAnHxCb2vfFtHOXZvffRl1FjYkSUf45EXB43E0PLDRx3239xC5Vy19d6JOw25mt5mwF8Bq4Kf8o4oWlN6mVefO3Ptvmg/fyu0JqOZjZp+hRRuW3t8sVCGh0H5GUmwV2M5HSn/REyrsQeMmY+LA/4DwuUxShhD1Ff6Vpr/yHAGiBL26ZQ1rKZAxR60hWq2QFlwvH/MtaQXOgwVowTn3s7EbVbHXUZqyBPhdWlyFJOyBij6fH3/04qc6cYk6iRz5IGUjgU2f88bA+O9gEpy5cTNKKl8A== 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=12DpWZnQeZGu6pGoGhDNjI11hW7+UUSHficQK5tMZiE=; b=S41mqPotB1bNGZ6zQoyBL2QKnlcr/g0q5yzMtWMSXe7vzL2jA32x2J6l+x9pRWOd8SSrPIlsQoj4gny6cpmGPl+1HIvoebJfL24z2Nn2kH1JmXkgHVkqeG5T5h1OsX3EODhbC2iDarWzV3/9w/EnnqtpD9rwVF6Wlqn9Gk4n5dgURii6hbTkocWDPjmCa47A+9MNVjuiKRj1Fx3ka2Ynlg0vp9EFtEAv1Jsh5c1BayWhVswlqmqG/wxZdn7Fs1/rkEVyYOtTBtoHR48VYdnvfsady7Wes7AwRFwdEhLHgdnLsyQ5q4CrTd09a0osdKkYnNDnxikMvjg0zqY0oO2mcA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=12DpWZnQeZGu6pGoGhDNjI11hW7+UUSHficQK5tMZiE=; b=RRG81AuZs9eHjHeHBJIjF0u29e3K2HMbnXKsy2aAODUE45XivmBup26NRElda2rvNRR96udiDrWDtT+rsaCD3lK0YCuNeRr7JFPKzlejmO53xqA0fEo4hVFhKJFL/D6ciEV9iHCDs/Hmr2ex2rFpBQfkHCs7R4I4NFdIA+UJNu7Gy5K24kftpZtcVSSeQTW5l3QkZ7ctAewWlXy4MxvMki6ypr7YDirRjkh7zHQHKbj6bb3ISuw2c8/q2+fzyBfffDOKbsHUmIg7BcWV55RT8++X0UtUd09bgC8Bbl6VG+JJ4tdMpuxPLKeJ8C4jVPN7yV9o0TI8OY0tw8l6QXXcpQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; To: devel@lists.libvirt.org Subject: [RFC PATCH 4/5] qemu: Update PXB busNr for nestedSmmuv3 controllers Date: Wed, 11 Dec 2024 16:24:22 -0800 Message-Id: <20241212002423.1050892-5-nathanc@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241212002423.1050892-1-nathanc@nvidia.com> References: <20241212002423.1050892-1-nathanc@nvidia.com> X-ClientProxiedBy: BYAPR05CA0023.namprd05.prod.outlook.com (2603:10b6:a03:c0::36) To SN7PR12MB6838.namprd12.prod.outlook.com (2603:10b6:806:266::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN7PR12MB6838:EE_|PH0PR12MB7791:EE_ X-MS-Office365-Filtering-Correlation-Id: 1e4f9cfe-99b8-46da-e885-08dd1a436676 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?hXZrOrl1Wh2q+1rl6LyQ6jxjRyYPW8MeRT50y0+QB00h5e8it+8djfM8g4b6?= =?us-ascii?Q?0ImkORh3hqo2LJfDDdPzadWY3tCYWl36qL/1/eofc3Dw5sF8CjvCeXNey2XY?= =?us-ascii?Q?OigjgcYgXl2I+YTvPCFLnvlHBOQHx9i7Av3ixjmCxXQEMy5P/4+9jFiHnVvK?= =?us-ascii?Q?9AycET3sZO2UeIKf3Qc3XOlL1iiKMy03AKR6rmMLkGDqm/CtFVXntv9cTFzn?= =?us-ascii?Q?TjOWe7enaw4Q7wdGrnjuqwi6KpNbJ5M4gwxlaow/pWHT5MMnCzpyOrwRRn3d?= =?us-ascii?Q?bQV2dn/U+ohAKwlBPo6NLQollfHHuwxyqV/nrLyKETuGJK24a53KrFP1Evd3?= =?us-ascii?Q?HV1s+v2e0kom8CKAMgeLJWKNH4KRtmjsQ3nzLOxZfoUq07IVn2Qs2832Ta51?= =?us-ascii?Q?TkcX51UQ9bIm54wUnHNOU28nkxZ2NWt87NgXvoSxf/3KFq3+6kaM4AWCg4gC?= =?us-ascii?Q?dLBSUsUObkNwXs/jg1gJmmvT9Kn+nZUXEw8+qdgDikqprmAWe/lmxZA2bjFr?= =?us-ascii?Q?LlgSpjhCTNIIVQ1dbbsL4iC6FvoPy0nS6JiHmTy/i5qON3MobIvNazu+Y1QN?= =?us-ascii?Q?wB44N6S3nqPFn5va2tGNTEByCCOEwQkHzYSds+40tsCVdfdL5pfnP68RIDVV?= =?us-ascii?Q?ENt62u46XPMf4VQsQkXdxx4fNNOYKWrvK2ycqhXQU76GeN/K0gdrEjJ2dIbK?= =?us-ascii?Q?8CLwErsXnGY5ul97QEgKMRl5QDkcEqoGw3lCmnj9I46QWeF+0yPS4ddmrmeJ?= =?us-ascii?Q?XijetGcUQbsgb937evxYAFTYKPIlM5GPHBD1J9LNDkP7cCG7YgoGvtdDmJbp?= =?us-ascii?Q?tXNOGmm5Pc3bamqnK7mSKUPZDD1A2sDeYDfmnc/f206c6GEU7i2BcLL+1+vB?= =?us-ascii?Q?gQuJXxG0L45BI0X4PA12AqS2gOzXTM5NXguwcHRy4Cg2836xmbScCvuU226/?= =?us-ascii?Q?Ierp7jldm9xAv3xo1nSkwMXD/0LayMYyygCh+SNNDlwX3U0ZUNwH+zaKz5DQ?= =?us-ascii?Q?9exXhwBjD5KVyrYCjnwmufSW5Za50x72elxN14JvRGdHzZAB/7h2i7EyyDCh?= =?us-ascii?Q?UgxjUEwF7Qecnf0Ei1zmyUvPK3BDPVyw0d3Qsm9fwFA4cbRDlosOKXfk/SI9?= =?us-ascii?Q?wXYGjpV09EgI2bvHNlcCJX99uI7RCoMYLeTamg0sUs3Eb+93ff8631T42Ze2?= =?us-ascii?Q?vFv4QIVTnqHyfBN3c2Jv38mfhyyvq7Yh6lPZuyBduK6J5zpEAPY5tR+6AEkg?= =?us-ascii?Q?PXZ7oDbz8c7+/TH4q++u+6mJ6JgfREtLKWMGdHJMiyVrG/YS99kDFaWoCf1/?= =?us-ascii?Q?EPjo5hfe3f3/qPeDsZ1heh23oFH/wcI9Sz3WbYS9jcBdpQ=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN7PR12MB6838.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSp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egUqO?= =?us-ascii?Q?sQqrQg+rd/+7l1C+YM2F3gYHICS+f1drIVJ26OZ11Uz+D17Bi4tExPef9A77?= =?us-ascii?Q?rXC30S1piTf7Orm/ZHE5XRT4S+6DpVCftudVYzS3Ry8tXuhYHSAuKd+pAXij?= =?us-ascii?Q?c3CdB84W3raFR/zgTSoFMFGR2j7QHQX0rR264WXDTEFN0X0mHWONDOC1I27Z?= =?us-ascii?Q?8Cc8My+9O7fgX+iM04olPwFFeqkvRS0feNnocePfK56MvFfTIFB/FWDFkbo3?= =?us-ascii?Q?0yaCJ4OKFEf6lha4H5lvw/QamCeLJqNVdS7KbusmWR4sdkdYTfcLEiJIO6pa?= =?us-ascii?Q?1EM8liXUhk2qxu23JcgsenCKjrRMRqgcNEOS2Cco0aFPtLNn7UEgGDn41aoW?= =?us-ascii?Q?Rlu7iRpb20wuOx4lZl/qJcI1rFtMe+jRqd4bR1tYWpWBp8lUbSwVdOGf7aLo?= =?us-ascii?Q?2GGc9vX9savlQ3uOpjx9h0vNAQVl2mXNEAhSv48R7HCbGGyUsdBsMlmDrN0C?= =?us-ascii?Q?bhFvf7kZxxdxbEeb9oR19PLshO9vzYknTahXVSEd4isU/CF8X7xD3Zpf+iCQ?= =?us-ascii?Q?gwE87crMMUXtZz+zb/3XtkBvE4wK+/YWzZnLdoJIc3dOd/v6FjEY9sHT6qMr?= =?us-ascii?Q?ilhl7IHnt6cKpxU/h3aQOHpB7S57ylW8Z4TwadUukWuBDlvUhVtm1pB+0jRs?= =?us-ascii?Q?rm/nRctggYlw8bOe0KDfxVxXogSSNeL2y6GjO6T7A2JSk79DoFjcPoJ+AmId?= =?us-ascii?Q?+KIEnGwhXJyNeurUa3Wt2aq1Xet3kZwTOc8Wmr2q?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1e4f9cfe-99b8-46da-e885-08dd1a436676 X-MS-Exchange-CrossTenant-AuthSource: SN7PR12MB6838.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2024 00:24:54.1644 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qckdc7tl3JCbcAF3r+IezUtSiPzipJErhF0itgqr8sx5/zLmfmHhYek36fZxRaZqpYIQtSSmFh2sGvt7hHrVrQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7791 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: FTGPNKMYQKQG42LK7HPBUZDX5TVZPSMB X-Message-ID-Hash: FTGPNKMYQKQG42LK7HPBUZDX5TVZPSMB X-MailFrom: nathanc@nvidia.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Nicolin Chen , Shameerali Kolothum Thodi , Nathan Chen X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Nathan Chen via Devel Reply-To: Nathan Chen X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1733963304364116600 Content-Type: text/plain; charset="utf-8" Update the PXB controller busNrs to account for devices we attached in the previous commit, ensuring there are enough VM bus numbers to be assigned for each device attached downstream from each PXB controller. Signed-off-by: Nathan Chen --- src/qemu/qemu_domain_address.c | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index dee198a7d2..001d1ec0b9 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -2678,6 +2678,23 @@ qemuDomainAddressFindNewTargetIndex(virDomainDef *de= f) } =20 =20 +static int +qemuDomainFindAttachedDevicesBusNr(virDomainDef *def, + int lowestBusNr, + unsigned int contIdx) +{ + size_t i; + for (i =3D 0; i < def->ncontrollers; i++) { + virDomainControllerDef *cont =3D def->controllers[i]; + if (cont->info.addr.pci.bus =3D=3D contIdx && cont->idx !=3D 0) + lowestBusNr =3D qemuDomainFindAttachedDevicesBusNr(def, lowest= BusNr - 1, cont->idx); + if (lowestBusNr <=3D 2) + return -1; + } + return lowestBusNr; +} + + static int qemuDomainAddressFindNewBusNr(virDomainDef *def) { @@ -2725,8 +2742,43 @@ qemuDomainAddressFindNewBusNr(virDomainDef *def) */ =20 size_t i; + size_t lowestBusNrContIdx =3D 0; int lowestBusNr =3D 256; =20 + if (def->iommu && def->iommu->model && + def->iommu->model =3D=3D VIR_DOMAIN_IOMMU_MODEL_NESTED_SMMUV3) { + for (i =3D 0; i < def->ncontrollers; i++) { + virDomainControllerDef *cont =3D def->controllers[i]; + if (cont->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) { + int thisBusNr =3D cont->opts.pciopts.busNr; + if (thisBusNr >=3D 0 && thisBusNr < lowestBusNr) { + lowestBusNr =3D thisBusNr; + lowestBusNrContIdx =3D i; + } + } + } + if (lowestBusNr <=3D 2) + return -1; + if (lowestBusNrContIdx =3D=3D 0) { + for (i =3D 0; i < def->ncontrollers; i++) { + if (def->controllers[i]->model =3D=3D VIR_DOMAIN_CONTROLLE= R_MODEL_PCIE_EXPANDER_BUS) { + lowestBusNrContIdx =3D i; + break; + } + } + } else { + for (i =3D lowestBusNrContIdx + 1; i < def->ncontrollers; i++)= { + if (def->controllers[i]->model =3D=3D VIR_DOMAIN_CONTROLLE= R_MODEL_PCIE_EXPANDER_BUS) { + lowestBusNrContIdx =3D i; + break; + } + } + } + lowestBusNr =3D qemuDomainFindAttachedDevicesBusNr(def, lowestBusN= r, + def->controllers[= lowestBusNrContIdx]->idx); + return lowestBusNr - 2; + } + for (i =3D 0; i < def->ncontrollers; i++) { virDomainControllerDef *cont =3D def->controllers[i]; =20 --=20 2.34.1