From patchwork Wed May 22 22:59:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stewart Hildebrand X-Patchwork-Id: 13671159 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D5E1EC25B7C for ; Wed, 22 May 2024 23:00:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.727904.1132600 (Exim 4.92) (envelope-from ) id 1s9uw5-0007ea-JD; Wed, 22 May 2024 22:59:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 727904.1132600; Wed, 22 May 2024 22:59:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9uw5-0007eT-GT; Wed, 22 May 2024 22:59:53 +0000 Received: by outflank-mailman (input) for mailman id 727904; Wed, 22 May 2024 22:59:52 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9uw4-0007HJ-7G for xen-devel@lists.xenproject.org; Wed, 22 May 2024 22:59:52 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20600.outbound.protection.outlook.com [2a01:111:f403:200a::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fe6007c1-188e-11ef-90a1-e314d9c70b13; Thu, 23 May 2024 00:59:51 +0200 (CEST) Received: from MN2PR04CA0035.namprd04.prod.outlook.com (2603:10b6:208:d4::48) by IA1PR12MB6649.namprd12.prod.outlook.com (2603:10b6:208:3a2::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.36; Wed, 22 May 2024 22:59:45 +0000 Received: from BL6PEPF0001AB56.namprd02.prod.outlook.com (2603:10b6:208:d4:cafe::11) by MN2PR04CA0035.outlook.office365.com (2603:10b6:208:d4::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.36 via Frontend Transport; Wed, 22 May 2024 22:59:45 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL6PEPF0001AB56.mail.protection.outlook.com (10.167.241.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Wed, 22 May 2024 22:59:45 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 22 May 2024 17:59:44 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 22 May 2024 17:59:44 -0500 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Wed, 22 May 2024 17:59:38 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: fe6007c1-188e-11ef-90a1-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kSWqwj34lnSTz24C5X/+EHE/FPg2TljQtm89RzfiE1VKHedCnedBCw8ut4lHusSeYPRK6Ps/vDPnTm3xQAe9pEQqpe5tSD+NI5KGYK8re6VP9FbEiJNEZGxVGdIIueDqcyGow7oi1l0WNwxb3MIuA6X0F4RVXbvhmGbFrnPOFzhVMeKTibKg0Pal1Xy4IOnp69nVrIclj3mFdGEfz/cgenj7hvMnUyvamCjh2XuNpZZ9Ge0JuUGXsT6CLmf8d5Jr4oT4dWV9O8rcwlFetzIrPIWXDUKcyMt8mCBd8lgawi8+nYgfBZs2ymNSjO0I7So1Bc8Le1yC5XX7TUBOezYw3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=k8+/xJpZRZsK6+RKr2c/38/ePPkO2ljT1mguCOagC4g=; b=Z9ZfhUPdEEEFkmrZExIslnLi2/EYu5qEpVyaQoxlo/UwEEBUFO+oz13p6lExGxOo2j1rORaU1MAdqFBK5jqpI0X6ZWNVQEB8oL2EZWmcagnkpm2GgAUTJG+xEIjWeeG8qEhdC9Y2U/J8/WQaUPkaFj+fXjUIvZqWl134mVvwM/BVE1Wn+tl69RQN2Upyfkh5GGjCyInRvjYt8PT8ZliaSJywl1UsO+hMTVKBCA+km/FJ9OIrmofegy+UwuhZV69seuHFbIaFAhCs8zwbKwQg586X7OOb8ft0yB6pVYI77YqP0jlPzHuC1gBOQBti6RRFlFBj5hZbCevzJvwWJuUOwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.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=k8+/xJpZRZsK6+RKr2c/38/ePPkO2ljT1mguCOagC4g=; b=F8xSekaFfvRxCBuE4BX5RQahAK8ZR/fBn72L/nuol54TDUUfQbOAwSQVtpWKa9CDOr8kRAjmqoieCMsHSQhjVJYfVn2TUt+Q0GIwqogx7bPZBqwIKV8yFroHHyf5o6E5YXmDZlkjQ0+V639DFe4VnzHuXAHLpuBESWJ0WSuoB9o= 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 (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=SATLEXMB03.amd.com; pr=C From: Stewart Hildebrand To: CC: Volodymyr Babchuk , Stewart Hildebrand , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v16 1/5] arm/vpci: honor access size when returning an error Date: Wed, 22 May 2024 18:59:20 -0400 Message-ID: <20240522225927.77398-2-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240522225927.77398-1-stewart.hildebrand@amd.com> References: <20240522225927.77398-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: stewart.hildebrand@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB56:EE_|IA1PR12MB6649:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ffd48ec-c467-4d07-6ea5-08dc7ab2df95 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|36860700004|1800799015|376005; X-Microsoft-Antispam-Message-Info: ngdG/B6/V0+aQxwTnZmyampS69xAgxf0RITFUzCdtvnbpqKPFLIB5KOYHe6Bc6BOJTM3bL4z5wN3ern9RKVPRTkXSEwQbx/klzQdmCMUWlkkUgsajFhMGR0gY1JfwYi4Tqd0jTTclXR53b33XPHx0R87MluOoGG8D1M7WUWnI5LCxfaHMKMOLtLET4D7ixKK8DwoRodnYCAXcRZccesxIHTohZgESW6c/oOI/IvrtXNhQFS15WMLssChU0r39DcVgFs8+xDuMLiclMrKxwOHI+Ct3gNg46pXvWMQpaK35i/C9OsSR+dZ5NG563QXty2AQUcD0peU29brq7c2vpzZMV0K3RKavw8lhSD7xjKkiog/fvGnngTBfZqV7gKiZSx87r9JzcDgeAAt8bsMgxfZUYXNeZ3Djl5HEjgH0yrR8DglBlTg82w3SO0P8/SSgc4iu9/LSbkf7bYNaEgS+VHiLS5s5pglT73Ydbw4sTKg0pmIXUYj/1kPantHg/BqFYIBXHbZ/sNH4/XP43t7Ntu7uDwcr/qwiqeYlfCnIov83B4DgVKJuGY03sKBGi+c+QxiYpQN8QdEQpFBmuXR21TWqSlxq16UC8J9lUogorgtsKYlswA+vhsdORtuyMeSmcHgbvWioebscMxn0LoQFHoeHSnLkpAsIZ/HlXy6m8zm/XnCgOfMZvoZ1G+i5mkDXqXv4UW0+55Aoesx9lfiIApk10yBAFj4m9dzZ3+gsWwGQVRE29gISLamqxHJMbwYI9giDAJJyAoVLE/h0najPYzC7+ku1icdugIvtHMIMStGuMPSkIWcg6GnoQD2jOzG9hVSswbqw0ozuNX8UM/HnyXTM4aEnFr9hCpTw6GU0qG06+3NmSn5E0DWMbhInyxC/R3flQdXmkkD/3C1cL2djnb1QwJoyNRsYh5AV/IPKVAqjLVnI4LrhLw9f/xO3yxUq/e2fjVGq4BvB2TIhvDnBtMPqAiXyBzZAzxlAQi5G6EeB1IB4QXf3Fu9ifwkFfwZYlCftC+6eviuQ1AOTuQpXDJcHZftJ9sOyDArAYfe9SR28dSaE1uDwJSef1PUE2PBzBya8xKLuIgYAxqeqAL4E+SKd0eaflIJJdu39ih1oKJiApIRpLEijz7fVZmsG/csNGVSzFnronDM0/qlz8IBiEkSxW94/2x4T1K69ZyDvdPRFl087VZ218oy/j33F7fjstDzoOoYNjK/dlaEg4W1Mc6DG/ACnxh3KqzxKSQ+2flLmlvUowxq5YSuYrMKzV5AU2tPXkxYhsSbYlwjxwsD2G055QWlD2vsRmRXGc0qMlpnQ7UFE6HepFOsnDe7ZFAjZvLweF4BOZQsu9h1G6OUYXhXL8kVpyJJey/z59YXBy3opQ/fK9u7RbSYVLhP7iZglIit X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(82310400017)(36860700004)(1800799015)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2024 22:59:45.3178 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ffd48ec-c467-4d07-6ea5-08dc7ab2df95 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB56.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6649 From: Volodymyr Babchuk Guest can try to read config space using different access sizes: 8, 16, 32, 64 bits. We need to take this into account when we are returning an error back to MMIO handler, otherwise it is possible to provide more data than requested: i.e. guest issues LDRB instruction to read one byte, but we are writing 0xFFFFFFFFFFFFFFFF in the target register. Signed-off-by: Volodymyr Babchuk Signed-off-by: Stewart Hildebrand --- v14->v15: * re-order so this patch comes before ("xen/arm: translate virtual PCI bus topology for guests") * s/access_mask/invalid/ * add U suffix to 1 * s/uint8_t/unsigned int/ * s/uint64_t/register_t/ * although Julien gave an Acked-by on v14, I omitted it due to the changes made in v15 v9->10: * New patch in v10. --- xen/arch/arm/vpci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index 3bc4bb55082a..b63a356bb4a8 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -29,6 +29,8 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, { struct pci_host_bridge *bridge = p; pci_sbdf_t sbdf = vpci_sbdf_from_gpa(bridge, info->gpa); + const unsigned int access_size = (1U << info->dabt.size) * 8; + const register_t invalid = GENMASK_ULL(access_size - 1, 0); /* data is needed to prevent a pointer cast on 32bit */ unsigned long data; @@ -39,7 +41,7 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, return 1; } - *r = ~0ul; + *r = invalid; return 0; } From patchwork Wed May 22 22:59:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stewart Hildebrand X-Patchwork-Id: 13671160 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DA995C25B7C for ; Wed, 22 May 2024 23:00:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.727908.1132611 (Exim 4.92) (envelope-from ) id 1s9uwF-0008Sv-VT; Wed, 22 May 2024 23:00:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 727908.1132611; Wed, 22 May 2024 23:00:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9uwF-0008Sl-Pv; Wed, 22 May 2024 23:00:03 +0000 Received: by outflank-mailman (input) for mailman id 727908; Wed, 22 May 2024 23:00:02 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9uwD-00085F-UR for xen-devel@lists.xenproject.org; Wed, 22 May 2024 23:00:02 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20600.outbound.protection.outlook.com [2a01:111:f403:2416::600]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 02b82ec6-188f-11ef-b4bb-af5377834399; Thu, 23 May 2024 00:59:59 +0200 (CEST) Received: from SA9PR13CA0006.namprd13.prod.outlook.com (2603:10b6:806:21::11) by LV8PR12MB9133.namprd12.prod.outlook.com (2603:10b6:408:188::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.19; Wed, 22 May 2024 22:59:54 +0000 Received: from SN1PEPF0002BA4C.namprd03.prod.outlook.com (2603:10b6:806:21:cafe::57) by SA9PR13CA0006.outlook.office365.com (2603:10b6:806:21::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.19 via Frontend Transport; Wed, 22 May 2024 22:59:54 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF0002BA4C.mail.protection.outlook.com (10.167.242.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Wed, 22 May 2024 22:59:53 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 22 May 2024 17:59:53 -0500 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Wed, 22 May 2024 17:59:51 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 02b82ec6-188f-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OLwmS6ciPK4yUCw0wRhDKnGjjhzZjz0hp0ifIJLcg9rUv02fF0DTiadQNkJIwEbdTSCDpWKCsUbwkcmYIBh6/cpV81zgSmcNMMyCisp69TJUMDnJpGZmr5jJxKqmbSYLySlyga3dQsjipwPgSI1T1QPKwaT2QuJ+NOqMju4nxqZxyk28FXpJSfMs/Wg3wI03/6+01j5xfgTvd5c/RCGsQedApk+9hSQaXNPRCLSNTJnLFWENjcOciOt0yI/x5MausQ8jO5aQpghuYEDcxijcno9uFUT4WqYoVoIRcipEpDezuyyBfPYxgaJqZMI5jh1jyVlmxdfV2JP/VtoZnCRDmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=pOnJWNfrhJ3Efv0BMkAnX4PfL/TY+zGAVYbpOc2ZfC8=; b=AKGmZa1jlzyD0w9esu1cSMwMrEEfdpGU3RZF0IgBCfjQ1u0w1sBWG0NM+7dAvdejPFDPsu4TOUCNMWW6QGREFyWmdxnw4hJXZ5xwQRk6ey+aLPZz5n0SbdexrLPVFuFkW/gPrAUJYS0fYYDzD1Zw775A7KldQHDzrGEJT3nEHZ8euj1gnXPG+dqxXQdLrwxywtpcS95hLCfBQZZBxOkdwoHirJYlDMePlvqGwcSFGR8Ybp/nwpaVL4Wrwfe26Zot/p6ibPVyHRJyccjKA2qYAr0ZUlNykOFiPyQjQKiZm9VbugdLsLS+8Ht9RLIr8p3uTYIk1c6k+YeZAC6to3lgTw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.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=pOnJWNfrhJ3Efv0BMkAnX4PfL/TY+zGAVYbpOc2ZfC8=; b=jV8F2kLA7ntBg3SHg5q2WDOmhI4OWfp47BHLr2dX1e0ogNVGZFxFr+R6I/3yMVeTG0k45XdRPWa3Z6cwiXAS1Vw0QK2cVOj2u5qtev+ON2oWl9JvrHFYn0XUxJZuFhbnCu3WcRz5qTxNCS1riEQljvre4GD3jetVUPY2NwlBkY8= 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 (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=SATLEXMB04.amd.com; pr=C From: Stewart Hildebrand To: CC: Oleksandr Andrushchenko , =?utf-8?q?Ro?= =?utf-8?q?ger_Pau_Monn=C3=A9?= , "Stewart Hildebrand" , Andrew Cooper , George Dunlap , "Jan Beulich" , Julien Grall , "Stefano Stabellini" , Volodymyr Babchuk Subject: [PATCH v16 2/5] vpci/header: emulate PCI_COMMAND register for guests Date: Wed, 22 May 2024 18:59:21 -0400 Message-ID: <20240522225927.77398-3-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240522225927.77398-1-stewart.hildebrand@amd.com> References: <20240522225927.77398-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB04.amd.com: stewart.hildebrand@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4C:EE_|LV8PR12MB9133:EE_ X-MS-Office365-Filtering-Correlation-Id: 151bd5f9-2278-4276-0408-08dc7ab2e48a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|36860700004|1800799015|376005; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Jaz3g3IOXeNxAoB9SsdQcaAQKIS7u8N?= =?utf-8?q?SQ7dnUCh5osV8Svkw6wpcKfNdqSBft6Fyol01X0bYxVfocwQaDgotKc6u2Pk5jJbq?= =?utf-8?q?keugE36iE+b396t/cg5pC0+78FYRbGVNfYRaEHMZdO9/lNKFwQLQu5iO4rHDo9tfL?= =?utf-8?q?S3IS9AfgMkYRxk6XDWjyDU8k1XTznODi+YjSlDTDPSWjwPcINOgxnuqQmFAjhos/p?= =?utf-8?q?YWvr/mOmdoMwbYLATgyhpaUJta5izsgqUE0jSixbU8unpEH3E1HA5Wk1R/iDrZHup?= =?utf-8?q?rtB7X4sNkeH9+X0tUxQdN1nMtQvOFBticlCiFSaFaaM8uB9iOG6fJs1JI4ZzDyE32?= =?utf-8?q?JMfJBEtCtwk6uWnlPmaOsDTWkWDRgyCAfczxSk8HotyTwg9L7/MZSaBo8X7BmLrAQ?= =?utf-8?q?Y/63Qk+prCq9u0vWiZIi4GvLStkJUft42++q76lwdn5EMJNOogigdjSYB2/2efH5U?= =?utf-8?q?i+xrC9kx+E7fnOf7rUi7derTC9WFgvz3t4xeJ9LCnJogx9Ggvi2OfdhGBhZduoUZs?= =?utf-8?q?IUWyU2oFe5nTtJn+scx575Naa0+trE42uw4ra34oIHgV+j29MUwLURvRsKoDHiMeN?= =?utf-8?q?29rJfHoEsha5AIrkFJCCY5XHgeuwIP0pQpNeiRURv0HrTfQY9IwW0CUkdPfwVgSSU?= =?utf-8?q?exjSFtwsou9Hb5TQwQ2NQBdXVm8mt1T/+jViPDNghuhw2bvkqk36a6syUhVv9VZHl?= =?utf-8?q?lbz08YUJ4GWOprgqYI9iNiUbvR6kxHRIg6WJUJjWvztVtuOULf8kshQqa9XLuc08R?= =?utf-8?q?m27LuxuUNfckuyr5BnS1wUYQx1+5GH+7S9MajVmmVbx8x8ZmZe2S/z5bzoRQXs54g?= =?utf-8?q?DhR9pocgAeBJJs6UjMxQnviqc/MIuU0zW1co8r4nyJqEfZGcL0XRIoI6U426lmTzC?= =?utf-8?q?haS94TFx5ukFI0D8RdxpIBLayeikUz7r1FOclcOTNiYOqu+JeWSjPc4HWe3i5/Oql?= =?utf-8?q?1/8RyQQmkhrb7YltQvaolQ5zOGzLUIsWDu0SzNRfu+IHExQBBtUSIcOnKVISw9QgS?= =?utf-8?q?fKI8+YLeydFvOQ12qLg1fSwReDG+/POKp39w3fBntJNKEg2R+BDMnzihH6rj1/gcV?= =?utf-8?q?2i+rBpuxJzbmh3MJjYIfoWZOP4nmRUL9vNnJPT5IPWVL7vRMxl9ebqARHdwgup37B?= =?utf-8?q?ySadhWyL8yIKbwQ8XlIIEjzEZ7icL87I4NCsKRvQO0yLs3d2tVaAD6og2dnSRzudy?= =?utf-8?q?NmeYp6p9rCBEVvveldqB7GLP31zvJgJIX+E9lnbAee0fDqYwCSC/h6LRw1Vk4u/mY?= =?utf-8?q?1/5pXadqvjSfgA4Iz0dcLhFVoSbksbz2qa/Z1Lb6uCSzDvT9hTLM9E3kv99FGduC9?= =?utf-8?q?ZatuV2f1fTlU?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(82310400017)(36860700004)(1800799015)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2024 22:59:53.6160 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 151bd5f9-2278-4276-0408-08dc7ab2e48a 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002BA4C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9133 From: Oleksandr Andrushchenko Xen and/or Dom0 may have put values in PCI_COMMAND which they expect to remain unaltered. PCI_COMMAND_SERR bit is a good example: while the guest's (domU) view of this will want to be zero (for now), the host having set it to 1 should be preserved, or else we'd effectively be giving the domU control of the bit. Thus, PCI_COMMAND register needs proper emulation in order to honor host's settings. According to "PCI LOCAL BUS SPECIFICATION, REV. 3.0", section "6.2.2 Device Control" the reset state of the command register is typically 0, so when assigning a PCI device use 0 as the initial state for the guest's (domU) view of the command register. Here is the full list of command register bits with notes about PCI/PCIe specification, and how Xen handles the bit. QEMU's behavior is also documented here since that is our current reference implementation for PCI passthrough. PCI_COMMAND_IO (bit 0) PCIe 6.1: RW PCI LB 3.0: RW QEMU: (emu_mask) QEMU provides an emulated view of this bit. Guest writes do not propagate to hardware. QEMU sets this bit to 1 in hardware if an I/O BAR is exposed to the guest. Xen domU: (rsvdp_mask) We treat this bit as RsvdP for now since we don't yet support I/O BARs for domUs. Xen dom0: We allow dom0 to control this bit freely. PCI_COMMAND_MEMORY (bit 1) PCIe 6.1: RW PCI LB 3.0: RW QEMU: (emu_mask) QEMU provides an emulated view of this bit. Guest writes do not propagate to hardware. QEMU sets this bit to 1 in hardware if a Memory BAR is exposed to the guest. Xen domU/dom0: We handle writes to this bit by mapping/unmapping BAR regions. Xen domU: For devices assigned to DomUs, memory decoding will be disabled at the time of initialization. PCI_COMMAND_MASTER (bit 2) PCIe 6.1: RW PCI LB 3.0: RW QEMU: Pass through writes to hardware. Xen domU/dom0: Pass through writes to hardware. PCI_COMMAND_SPECIAL (bit 3) PCIe 6.1: RO, hardwire to 0 PCI LB 3.0: RW QEMU: Pass through writes to hardware. Xen domU/dom0: Pass through writes to hardware. PCI_COMMAND_INVALIDATE (bit 4) PCIe 6.1: RO, hardwire to 0 PCI LB 3.0: RW QEMU: Pass through writes to hardware. Xen domU/dom0: Pass through writes to hardware. PCI_COMMAND_VGA_PALETTE (bit 5) PCIe 6.1: RO, hardwire to 0 PCI LB 3.0: RW QEMU: Pass through writes to hardware. Xen domU/dom0: Pass through writes to hardware. PCI_COMMAND_PARITY (bit 6) PCIe 6.1: RW PCI LB 3.0: RW QEMU: (emu_mask) QEMU provides an emulated view of this bit. Guest writes do not propagate to hardware. Xen domU: (rsvdp_mask) We treat this bit as RsvdP. Xen dom0: We allow dom0 to control this bit freely. PCI_COMMAND_WAIT (bit 7) PCIe 6.1: RO, hardwire to 0 PCI LB 3.0: hardwire to 0 QEMU: res_mask Xen domU: (rsvdp_mask) We treat this bit as RsvdP. Xen dom0: We allow dom0 to control this bit freely. PCI_COMMAND_SERR (bit 8) PCIe 6.1: RW PCI LB 3.0: RW QEMU: (emu_mask) QEMU provides an emulated view of this bit. Guest writes do not propagate to hardware. Xen domU: (rsvdp_mask) We treat this bit as RsvdP. Xen dom0: We allow dom0 to control this bit freely. PCI_COMMAND_FAST_BACK (bit 9) PCIe 6.1: RO, hardwire to 0 PCI LB 3.0: RW QEMU: (emu_mask) QEMU provides an emulated view of this bit. Guest writes do not propagate to hardware. Xen domU: (rsvdp_mask) We treat this bit as RsvdP. Xen dom0: We allow dom0 to control this bit freely. PCI_COMMAND_INTX_DISABLE (bit 10) PCIe 6.1: RW PCI LB 3.0: RW QEMU: (emu_mask) QEMU provides an emulated view of this bit. Guest writes do not propagate to hardware. QEMU checks if INTx was mapped for a device. If it is not, then guest can't control PCI_COMMAND_INTX_DISABLE bit. Xen domU: We prohibit a guest from enabling INTx if MSI(X) is enabled. Xen dom0: We allow dom0 to control this bit freely. Bits 11-15 PCIe 6.1: RsvdP PCI LB 3.0: Reserved QEMU: res_mask Xen domU: rsvdp_mask Xen dom0: We allow dom0 to control these bits freely. Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Volodymyr Babchuk Signed-off-by: Stewart Hildebrand Reviewed-by: Jan Beulich Reviewed-by: Roger Pau Monné --- In v16: - allow dom0 to freely control RsvdP bits (11-15) - add Roger's R-b In v15: - add Jan's R-b - add blank line after declaration in msi.c:control_write() In v14: - check for 0->1 transition in INTX_DISABLE-setting logic in msi.c:control_write() to match msix.c:control_write() - clear domU-controllable bits in header.c:init_header() In v13: - Update right away (don't defer) PCI_COMMAND_MEMORY bit in guest_cmd variable in cmd_write() - Make comment single line in xen/drivers/vpci/msi.c:control_write() - Rearrange memory decoding disabling snippet in init_header() In v12: - Rework patch using vpci_add_register_mask() - Add bitmask #define in pci_regs.h according to PCIe 6.1 spec, except don't add the RO bits because they were RW in PCI LB 3.0 spec. - Move and expand TODO comment about properly emulating bits - Update guest_cmd in msi.c/msix.c:control_write() - Simplify cmd_write(), thanks to rsvdp_mask - Update commit description In v11: - Fix copy-paste mistake: vpci->msi should be vpci->msix - Handle PCI_COMMAND_IO - Fix condition for disabling INTx in the MSI-X code - Show domU changes to only allowed bits - Show PCI_COMMAND_MEMORY write only after P2M was altered - Update comments in the code In v10: - Added cf_check attribute to guest_cmd_read - Removed warning about non-zero cmd - Updated comment MSI code regarding disabling INTX - Used ternary operator in vpci_add_register() call - Disable memory decoding for DomUs in init_bars() In v9: - Reworked guest_cmd_read - Added handling for more bits Since v6: - fold guest's logic into cmd_write - implement cmd_read, so we can report emulated INTx state to guests - introduce header->guest_cmd to hold the emulated state of the PCI_COMMAND register for guests Since v5: - add additional check for MSI-X enabled while altering INTX bit - make sure INTx disabled while guests enable MSI/MSI-X Since v3: - gate more code on CONFIG_HAS_MSI - removed logic for the case when MSI/MSI-X not enabled --- xen/drivers/vpci/header.c | 60 ++++++++++++++++++++++++++++++++++---- xen/drivers/vpci/msi.c | 9 ++++++ xen/drivers/vpci/msix.c | 7 +++++ xen/include/xen/pci_regs.h | 1 + xen/include/xen/vpci.h | 3 ++ 5 files changed, 74 insertions(+), 6 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 47648c395132..ef6c965c081c 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -524,9 +524,21 @@ static void cf_check cmd_write( { struct vpci_header *header = data; + if ( !is_hardware_domain(pdev->domain) ) + { + const struct vpci *vpci = pdev->vpci; + + if ( (vpci->msi && vpci->msi->enabled) || + (vpci->msix && vpci->msix->enabled) ) + cmd |= PCI_COMMAND_INTX_DISABLE; + + header->guest_cmd = cmd; + } + /* * Let Dom0 play with all the bits directly except for the memory - * decoding one. + * decoding one. Bits that are not allowed for DomU are already + * handled above and by the rsvdp_mask. */ if ( header->bars_mapped != !!(cmd & PCI_COMMAND_MEMORY) ) /* @@ -540,6 +552,14 @@ static void cf_check cmd_write( pci_conf_write16(pdev->sbdf, reg, cmd); } +static uint32_t cf_check guest_cmd_read( + const struct pci_dev *pdev, unsigned int reg, void *data) +{ + const struct vpci_header *header = data; + + return header->guest_cmd; +} + static void cf_check bar_write( const struct pci_dev *pdev, unsigned int reg, uint32_t val, void *data) { @@ -754,9 +774,23 @@ static int cf_check init_header(struct pci_dev *pdev) return -EOPNOTSUPP; } - /* Setup a handler for the command register. */ - rc = vpci_add_register(pdev->vpci, vpci_hw_read16, cmd_write, PCI_COMMAND, - 2, header); + /* + * Setup a handler for the command register. + * + * TODO: If support for emulated bits is added, re-visit how to handle + * PCI_COMMAND_PARITY, PCI_COMMAND_SERR, and PCI_COMMAND_FAST_BACK. + */ + rc = vpci_add_register_mask(pdev->vpci, + is_hwdom ? vpci_hw_read16 : guest_cmd_read, + cmd_write, PCI_COMMAND, 2, header, 0, 0, + is_hwdom ? 0 + : PCI_COMMAND_RSVDP_MASK | + PCI_COMMAND_IO | + PCI_COMMAND_PARITY | + PCI_COMMAND_WAIT | + PCI_COMMAND_SERR | + PCI_COMMAND_FAST_BACK, + 0); if ( rc ) return rc; @@ -836,9 +870,23 @@ static int cf_check init_header(struct pci_dev *pdev) if ( pdev->ignore_bars ) return 0; - /* Disable memory decoding before sizing. */ cmd = pci_conf_read16(pdev->sbdf, PCI_COMMAND); - if ( cmd & PCI_COMMAND_MEMORY ) + + /* + * For DomUs, clear PCI_COMMAND_{MASTER,MEMORY,IO} and other + * DomU-controllable bits in PCI_COMMAND. Devices assigned to DomUs will + * start with memory decoding disabled, and modify_bars() will not be called + * at the end of this function. + */ + if ( !is_hwdom ) + cmd &= ~(PCI_COMMAND_VGA_PALETTE | PCI_COMMAND_INVALIDATE | + PCI_COMMAND_SPECIAL | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | + PCI_COMMAND_IO); + + header->guest_cmd = cmd; + + /* Disable memory decoding before sizing. */ + if ( !is_hwdom || (cmd & PCI_COMMAND_MEMORY) ) pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd & ~PCI_COMMAND_MEMORY); for ( i = 0; i < num_bars; i++ ) diff --git a/xen/drivers/vpci/msi.c b/xen/drivers/vpci/msi.c index 30adcf7df05d..dd6620ec5674 100644 --- a/xen/drivers/vpci/msi.c +++ b/xen/drivers/vpci/msi.c @@ -57,6 +57,8 @@ static void cf_check control_write( if ( new_enabled ) { + bool old_enabled = msi->enabled; + /* * If the device is already enabled it means the number of * enabled messages has changed. Disable and re-enable the @@ -70,6 +72,13 @@ static void cf_check control_write( if ( vpci_msi_arch_enable(msi, pdev, vectors) ) return; + + /* Make sure domU doesn't enable INTx while enabling MSI. */ + if ( !old_enabled && !is_hardware_domain(pdev->domain) ) + { + pci_intx(pdev, false); + pdev->vpci->header.guest_cmd |= PCI_COMMAND_INTX_DISABLE; + } } else vpci_msi_arch_disable(msi, pdev); diff --git a/xen/drivers/vpci/msix.c b/xen/drivers/vpci/msix.c index 58c16ebdf283..fbe710ab92ef 100644 --- a/xen/drivers/vpci/msix.c +++ b/xen/drivers/vpci/msix.c @@ -135,6 +135,13 @@ static void cf_check control_write( } } + /* Make sure domU doesn't enable INTx while enabling MSI-X. */ + if ( new_enabled && !msix->enabled && !is_hardware_domain(pdev->domain) ) + { + pci_intx(pdev, false); + pdev->vpci->header.guest_cmd |= PCI_COMMAND_INTX_DISABLE; + } + msix->masked = new_masked; msix->enabled = new_enabled; diff --git a/xen/include/xen/pci_regs.h b/xen/include/xen/pci_regs.h index 0bc18efabb74..250ba106dbd3 100644 --- a/xen/include/xen/pci_regs.h +++ b/xen/include/xen/pci_regs.h @@ -48,6 +48,7 @@ #define PCI_COMMAND_SERR 0x100 /* Enable SERR */ #define PCI_COMMAND_FAST_BACK 0x200 /* Enable back-to-back writes */ #define PCI_COMMAND_INTX_DISABLE 0x400 /* INTx Emulation Disable */ +#define PCI_COMMAND_RSVDP_MASK 0xf800 #define PCI_STATUS 0x06 /* 16 bits */ #define PCI_STATUS_IMM_READY 0x01 /* Immediate Readiness */ diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 6e4c972f35ed..2064d9354f5b 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -107,6 +107,9 @@ struct vpci { } bars[PCI_HEADER_NORMAL_NR_BARS + 1]; /* At most 6 BARS + 1 expansion ROM BAR. */ + /* Guest (domU only) view of the PCI_COMMAND register. */ + uint16_t guest_cmd; + /* * Store whether the ROM enable bit is set (doesn't imply ROM BAR * is mapped into guest p2m) if there's a ROM BAR on the device. From patchwork Wed May 22 22:59:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stewart Hildebrand X-Patchwork-Id: 13671161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7675AC25B78 for ; Wed, 22 May 2024 23:00:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.727912.1132620 (Exim 4.92) (envelope-from ) id 1s9uwM-0000wN-BW; Wed, 22 May 2024 23:00:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 727912.1132620; Wed, 22 May 2024 23:00:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9uwM-0000w5-8B; Wed, 22 May 2024 23:00:10 +0000 Received: by outflank-mailman (input) for mailman id 727912; Wed, 22 May 2024 23:00:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9uwL-0007HJ-Om for xen-devel@lists.xenproject.org; Wed, 22 May 2024 23:00:09 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20600.outbound.protection.outlook.com [2a01:111:f403:2412::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 089cad80-188f-11ef-90a1-e314d9c70b13; Thu, 23 May 2024 01:00:09 +0200 (CEST) Received: from PH8PR07CA0015.namprd07.prod.outlook.com (2603:10b6:510:2cd::20) by DS7PR12MB5959.namprd12.prod.outlook.com (2603:10b6:8:7e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.35; Wed, 22 May 2024 23:00:04 +0000 Received: from SN1PEPF0002BA4B.namprd03.prod.outlook.com (2603:10b6:510:2cd:cafe::69) by PH8PR07CA0015.outlook.office365.com (2603:10b6:510:2cd::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.21 via Frontend Transport; Wed, 22 May 2024 23:00:03 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF0002BA4B.mail.protection.outlook.com (10.167.242.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Wed, 22 May 2024 23:00:03 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 22 May 2024 18:00:03 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 22 May 2024 18:00:02 -0500 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Wed, 22 May 2024 18:00:01 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 089cad80-188f-11ef-90a1-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VCb1Jg5weSlF7ymph+4mnXbVHH52neQ8HxIphgiqeUC1nTyEzXEBdb2IEGrUJr3OrGT4nERAU9SOvLFs+u2de8U0tSeVlpQo5kWpfiKThUEURakGQmAQpypxjPXmIYkvVqCqtb9bSg3TgTgPhMTBqw//zY7+DE+cF9MybQLTQx5dIWxLtwms9PitwjBJJhWG9vsNjpZ17UBxkCEC2P8XJ+cl5EFwbHSV+lAbm1RnzAL7UC7/MITtPQGSWkXEslhak5hcZJwX47e/IKMNStdwCWHbjlrocIlXTm4okiwbGvpazRBn2DDm7ecvJ13jJHLy04gsEwbfF0jemfelstkQrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=91z7nZP+Kt+sNbijuSvMEIgPYCMJ9j1zgXB7s2O6sEQ=; b=og2OV92dLpYsp9J64GHz2H2Q96S3uwXHDfmxxpXxVAgTs8CVGQKYhjAJwI5uI9oURm16wJIBCdvKFLCpVjoBqS3kkppBzbdBFaM7iv46uZZZp0HKAZkhXzaWquW77PAc0J9i4pA1Dy/l2aI8HlGcJe5dBK2JXE5/zmyiZkZf8UgLt3h7a+puXWmzti10lCkyvnKecn4W3Q/hlB7pCl9EykcZv9NbXCtTRDdkM6L1Rqs99OG2co4AkpmXhpFyys7KBc/r6lEQw/UgN3EBAizMAQx5pfiUxqJkPf8oXiootOqKyBoBiKEPUBRt3BVf/CoZq8aTn8fwrDIcMlfM683deQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.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=91z7nZP+Kt+sNbijuSvMEIgPYCMJ9j1zgXB7s2O6sEQ=; b=RNZFhMhSaBudPjYAYP1zM0OkfmvRZoms4Sr+kRv94c0R0dMRzm4P8euQnwdD3StHsrLoc5r9FCVywhqoTb75seWCcgta5lvJu7ojUP9h82B/cAnQxRZjc+ewiqwaIyDCQYsbXXYogXPxOiFe+y/t3KHNp9rYtpHsHFFM3zln5pU= 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 (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=SATLEXMB04.amd.com; pr=C From: Stewart Hildebrand To: CC: Oleksandr Andrushchenko , Andrew Cooper , George Dunlap , "Jan Beulich" , Julien Grall , "Stefano Stabellini" , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stewart Hildebrand , Volodymyr Babchuk Subject: [PATCH v16 3/5] vpci: add initial support for virtual PCI bus topology Date: Wed, 22 May 2024 18:59:22 -0400 Message-ID: <20240522225927.77398-4-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240522225927.77398-1-stewart.hildebrand@amd.com> References: <20240522225927.77398-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4B:EE_|DS7PR12MB5959:EE_ X-MS-Office365-Filtering-Correlation-Id: 3882d1c7-f221-4ec9-c588-08dc7ab2ea80 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|36860700004|376005|1800799015|82310400017; X-Microsoft-Antispam-Message-Info: Fcj013H94GzpQGmy8lHng1XcpRo2lzRsJ6evaN1+TWJ81nxgt14dWo50z6zVmavcrcnSBVCG3qhIjzJv9lusbvsM8mRmy+nKNg8vvMC/ymOUX80ZOnJ3qIkSAVLUfiLqcOkeOGNNU76099uJa8Oc6i8ZAeGW50+0qADE51V5zBqQfvWjtrnKig459zMPHsajQl8F15YcKIWi9QkZ7wiVsOgZlKNcyVPr1+6V+Uo5YgVIRSEt+CkunmPX0K967Qik9NKFmCHQH4hB06P1O7Eud/TfBbKg1Golt7Y38TuXeoxOiXCraScHuBYSOv6G5sj7ybodC5JfBplNwTNzbWPvLLoBkJayf/BJmoAAdAilz0ROZZdB9k2lGOzVmSk24ck/r3ihS5ybGfoJgHNZtu1Ae1oaIax8YazBkxR4Wcbli7SkM7Ym1D4aKBxSy3RNk5xXgjr+eexz0PkwGpUovCpU3m6gkOY8ayq4IeEyBIxk7XGFMiw0RbhmYw6M3BFwOPj2rwg90sl06h63w2w/ie0+8zmfrWmMzzM5+bdi7LabiRLfqzhr7ncxmaI7XIz+v5R48M9QpmEJq59Wz3FH0Cj1YNmBk/FKX36JLsDtiimIMI6EANM+UCERYq8zU/OSXE1I4luiuC8Emr+57w8+lIS4LdZZuJTcA9NngD+j5Pm+R38222UvwPcWhI2cal4Rn0vSy4QhAMeN1EzaHt8cnaBLPXQ64YcvtAQPUxzbhpylGBKLTZ1Q9POvLuMbKstHiOjaB7Cs73nU1Q/a9Egv2vNV4534K3MFVN1JEhZn91bXpugwO3vm3kpIVKBtcn1r3u3FwQ7hk/aKjx5U5VxvepK8spUZhxCllr4ShYFCgO0O0zyv1cLAw1yJpKpdqP4DbkZb9eoGZXwjrelUqKWb6DgqrsF3SJyyBhVyLJZ64AbTric0RK5Bv6l28XReoQyx+VpQA9jC+n3jwj+5uTZMdA/g5aK7iSdOrcl1HWZBi/qg9ywaxVsdjKaefkME0SFqQwXixwhOh+O5LVCgDlkKu+CfgFNLPCVogcKv+7nfe5qJdjy7lFf6m3WT/lK1Drv5LI8YVXsemg9vyWUEDXXcLXbqLqjwPfa/SgWf4Q+jXD+3Y6BgQJGqi8q01kqRES1WB2s+At6J81moqlljy8sKAsUFfHUZ0zXYkZNEpMJvZUnECwEmMRjosAFIyKaLE6pZbt0hSP3lEyK4miIagSm8nVCOPc5nq+GI1k8QxDJqGO5wQHisEcCoKEqnl/XNOPVFnXI1QaT4xgdNm0COd/2u1YgOgCnJyDNwjv3VeO5MlWN7RUhb1qkR9tVPWbbd0AXcUQsYpkBFgHZZsk6cacJmCehZJT5NNGXBAYqe4WHL3WkGzXA= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(36860700004)(376005)(1800799015)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2024 23:00:03.6217 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3882d1c7-f221-4ec9-c588-08dc7ab2ea80 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002BA4B.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5959 From: Oleksandr Andrushchenko Assign SBDF to the PCI devices being passed through with bus 0. The resulting topology is where PCIe devices reside on the bus 0 of the root complex itself (embedded endpoints). This implementation is limited to 32 devices which are allowed on a single PCI bus. Please note, that at the moment only function 0 of a multifunction device can be passed through. Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Volodymyr Babchuk Signed-off-by: Stewart Hildebrand Acked-by: Jan Beulich Acked-by: Roger Pau Monné --- In v16: - s/add_virtual_device/assign_virtual_sbdf/ - move ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)) earlier - add #define INVALID_GUEST_SBDF In v15: - add Jan's A-b In v13: - s/depends on/select/ in Kconfig - check pdev->sbdf.fn instead of two booleans in add_virtual_device() - comment #endifs in sched.h - clarify comment about limits in vpci.h with seg/bus limit In v11: - Fixed code formatting - Removed bogus write_unlock() call - Fixed type for new_dev_number In v10: - Removed ASSERT(pcidevs_locked()) - Removed redundant code (local sbdf variable, clearing sbdf during device removal, etc) - Added __maybe_unused attribute to "out:" label - Introduced HAS_VPCI_GUEST_SUPPORT Kconfig option, as this is the first patch where it is used (previously was in "vpci: add hooks for PCI device assign/de-assign") In v9: - Lock in add_virtual_device() replaced with ASSERT (thanks, Stewart) In v8: - Added write lock in add_virtual_device Since v6: - re-work wrt new locking scheme - OT: add ASSERT(pcidevs_write_locked()); to add_virtual_device() Since v5: - s/vpci_add_virtual_device/add_virtual_device and make it static - call add_virtual_device from vpci_assign_device and do not use REGISTER_VPCI_INIT machinery - add pcidevs_locked ASSERT - use DECLARE_BITMAP for vpci_dev_assigned_map Since v4: - moved and re-worked guest sbdf initializers - s/set_bit/__set_bit - s/clear_bit/__clear_bit - minor comment fix s/Virtual/Guest/ - added VPCI_MAX_VIRT_DEV constant (PCI_SLOT(~0) + 1) which will be used later for counting the number of MMIO handlers required for a guest (Julien) Since v3: - make use of VPCI_INIT - moved all new code to vpci.c which belongs to it - changed open-coded 31 to PCI_SLOT(~0) - added comments and code to reject multifunction devices with functions other than 0 - updated comment about vpci_dev_next and made it unsigned int - implement roll back in case of error while assigning/deassigning devices - s/dom%pd/%pd Since v2: - remove casts that are (a) malformed and (b) unnecessary - add new line for better readability - remove CONFIG_HAS_VPCI_GUEST_SUPPORT ifdef's as the relevant vPCI functions are now completely gated with this config - gate common code with CONFIG_HAS_VPCI_GUEST_SUPPORT New in v2 --- xen/drivers/Kconfig | 4 +++ xen/drivers/vpci/vpci.c | 57 +++++++++++++++++++++++++++++++++++++++++ xen/include/xen/sched.h | 10 +++++++- xen/include/xen/vpci.h | 13 ++++++++++ 4 files changed, 83 insertions(+), 1 deletion(-) diff --git a/xen/drivers/Kconfig b/xen/drivers/Kconfig index db94393f47a6..20050e9bb8b3 100644 --- a/xen/drivers/Kconfig +++ b/xen/drivers/Kconfig @@ -15,4 +15,8 @@ source "drivers/video/Kconfig" config HAS_VPCI bool +config HAS_VPCI_GUEST_SUPPORT + bool + select HAS_VPCI + endmenu diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 97e115dc5798..1e6aa5d799b9 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -40,6 +40,49 @@ extern vpci_register_init_t *const __start_vpci_array[]; extern vpci_register_init_t *const __end_vpci_array[]; #define NUM_VPCI_INIT (__end_vpci_array - __start_vpci_array) +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT +static int assign_virtual_sbdf(struct pci_dev *pdev) +{ + struct domain *d = pdev->domain; + unsigned int new_dev_number; + + ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); + + if ( is_hardware_domain(d) ) + return 0; + + /* + * Each PCI bus supports 32 devices/slots at max or up to 256 when + * there are multi-function ones which are not yet supported. + */ + if ( pdev->sbdf.fn ) + { + gdprintk(XENLOG_ERR, "%pp: only function 0 passthrough supported\n", + &pdev->sbdf); + return -EOPNOTSUPP; + } + new_dev_number = find_first_zero_bit(d->vpci_dev_assigned_map, + VPCI_MAX_VIRT_DEV); + if ( new_dev_number == VPCI_MAX_VIRT_DEV ) + return -ENOSPC; + + __set_bit(new_dev_number, &d->vpci_dev_assigned_map); + + /* + * Both segment and bus number are 0: + * - we emulate a single host bridge for the guest, e.g. segment 0 + * - with bus 0 the virtual devices are seen as embedded + * endpoints behind the root complex + * + * TODO: add support for multi-function devices. + */ + pdev->vpci->guest_sbdf = PCI_SBDF(0, 0, new_dev_number, 0); + + return 0; +} + +#endif /* CONFIG_HAS_VPCI_GUEST_SUPPORT */ + void vpci_deassign_device(struct pci_dev *pdev) { unsigned int i; @@ -49,6 +92,12 @@ void vpci_deassign_device(struct pci_dev *pdev) if ( !has_vpci(pdev->domain) || !pdev->vpci ) return; +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT + if ( pdev->vpci->guest_sbdf.sbdf != ~0 ) + __clear_bit(pdev->vpci->guest_sbdf.dev, + &pdev->domain->vpci_dev_assigned_map); +#endif + spin_lock(&pdev->vpci->lock); while ( !list_empty(&pdev->vpci->handlers) ) { @@ -103,6 +152,13 @@ int vpci_assign_device(struct pci_dev *pdev) INIT_LIST_HEAD(&pdev->vpci->handlers); spin_lock_init(&pdev->vpci->lock); +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT + pdev->vpci->guest_sbdf = INVALID_GUEST_SBDF; + rc = assign_virtual_sbdf(pdev); + if ( rc ) + goto out; +#endif + for ( i = 0; i < NUM_VPCI_INIT; i++ ) { rc = __start_vpci_array[i](pdev); @@ -110,6 +166,7 @@ int vpci_assign_device(struct pci_dev *pdev) break; } + out: __maybe_unused; if ( rc ) vpci_deassign_device(pdev); diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 132b84199598..2dcd1d1a4f8a 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -486,7 +486,15 @@ struct domain * 2. pdev->vpci->lock */ rwlock_t pci_lock; -#endif +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT + /* + * The bitmap which shows which device numbers are already used by the + * virtual PCI bus topology and is used to assign a unique SBDF to the + * next passed through virtual PCI device. + */ + DECLARE_BITMAP(vpci_dev_assigned_map, VPCI_MAX_VIRT_DEV); +#endif /* CONFIG_HAS_VPCI_GUEST_SUPPORT */ +#endif /* CONFIG_HAS_PCI */ #ifdef CONFIG_HAS_PASSTHROUGH struct domain_iommu iommu; diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 2064d9354f5b..da8d0f41e6f4 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -21,6 +21,14 @@ typedef int vpci_register_init_t(struct pci_dev *dev); #define VPCI_ECAM_BDF(addr) (((addr) & 0x0ffff000) >> 12) +/* + * Maximum number of devices supported by the virtual bus topology: + * each PCI bus supports 32 devices/slots at max or up to 256 when + * there are multi-function ones which are not yet supported. + * This limit implies only segment 0, bus 0 is supported. + */ +#define VPCI_MAX_VIRT_DEV (PCI_SLOT(~0) + 1) + #define REGISTER_VPCI_INIT(x, p) \ static vpci_register_init_t *const x##_entry \ __used_section(".data.vpci." p) = (x) @@ -175,6 +183,11 @@ struct vpci { struct vpci_arch_msix_entry arch; } entries[]; } *msix; +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT + /* Guest SBDF of the device. */ +#define INVALID_GUEST_SBDF ((pci_sbdf_t){ .sbdf = ~0U }) + pci_sbdf_t guest_sbdf; +#endif #endif }; From patchwork Wed May 22 22:59:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stewart Hildebrand X-Patchwork-Id: 13671162 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 86CDBC25B78 for ; Wed, 22 May 2024 23:00:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.727916.1132630 (Exim 4.92) (envelope-from ) id 1s9uwg-0001cl-LY; Wed, 22 May 2024 23:00:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 727916.1132630; Wed, 22 May 2024 23:00:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9uwg-0001ce-HR; Wed, 22 May 2024 23:00:30 +0000 Received: by outflank-mailman (input) for mailman id 727916; Wed, 22 May 2024 23:00:29 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9uwf-00085F-FS for xen-devel@lists.xenproject.org; Wed, 22 May 2024 23:00:29 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20601.outbound.protection.outlook.com [2a01:111:f403:2417::601]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 13f89e88-188f-11ef-b4bb-af5377834399; Thu, 23 May 2024 01:00:27 +0200 (CEST) Received: from CH2PR19CA0009.namprd19.prod.outlook.com (2603:10b6:610:4d::19) by DM4PR12MB5866.namprd12.prod.outlook.com (2603:10b6:8:65::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.20; Wed, 22 May 2024 23:00:18 +0000 Received: from DS3PEPF000099DC.namprd04.prod.outlook.com (2603:10b6:610:4d:cafe::30) by CH2PR19CA0009.outlook.office365.com (2603:10b6:610:4d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.35 via Frontend Transport; Wed, 22 May 2024 23:00:18 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by DS3PEPF000099DC.mail.protection.outlook.com (10.167.17.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Wed, 22 May 2024 23:00:18 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 22 May 2024 18:00:17 -0500 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Wed, 22 May 2024 18:00:10 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 13f89e88-188f-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jt1/NlIeAv8OkqunZeZ/Wscjincc4KRRgJInrNPAUejv4X6DMD3TLTWMiOE9a+Ay0NySuA0oXUtgHsx8CEoZr5ex++Rrd+3v3YoonDhHg7lxCPFngzq/8YvkQoG44GHkRyCPDjmUmjwo9jQ+0HYQD3jfKru9EXQ3/pR/Bf4v0jfPHppqMt0ck8xSqLE8A1wNB7BUQyAjFQTN9s11hR7mcK9OdYn6Xn81djzx01sj37QTIV3lsQvNR2Gt5P0ThjcO79PPT78W3XG+2N/4JUG6SuWa+qsq6lHqAVnE9ywrZAUcqaCrKs9pxAAwThqXQ/qSWQPB8IKOM9NLk0fW9gbYDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=uF7c5zavGjbbV/lkf4o6jybYZmZIylb5HcpXyWKE0tU=; b=MYpVIT0k9nyTpewe3mehTh6ec7igXTVVw9ksR4WGvv34qTMEHEMeP/+XdF/NlLNatf/fmihIY2XrgL1U7n70uBbMfgwragZDglnHc7dURCqbxHIDrZMqY15wCIApCgCb/6R2Oda7WTHhJUyA9Qo45db4WsVgYpjzh4L2gIq0IarIigFvCjyaraB3P9xn/IDBxUoLSE01keczMGRp1COSMczcTHLAgANgyGNNBXCfMdZsQ6NaXCasSxZ3IFovE4MOYcTRHYxTcuOyLesl/7EtxWIAiqMOirc29MUpODODqGpp3qawGk81+tKW/XvYXBbNxDPGUtbgtIkYIGhhf8y8hQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.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=uF7c5zavGjbbV/lkf4o6jybYZmZIylb5HcpXyWKE0tU=; b=zKO+HHUqN7nTUyl43gWACKGXwoDhtm+2MCYOLBu3jow+IgB5f4mQVLnNRLwG5AGrWeCI/4rA0HPqZOK/GcjVuuc9kAyQ+nEBeIDmiIk8eqNKE5hc1d/C3Pv4eSZ1pQD0fxrmcpkrUyiTISkXMgzAaYqTXJauJ7pnxzwgPdoh9w0= 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 (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=SATLEXMB03.amd.com; pr=C From: Stewart Hildebrand To: CC: Oleksandr Andrushchenko , "Stewart Hildebrand" , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= , Volodymyr Babchuk Subject: [PATCH v16 4/5] xen/arm: translate virtual PCI bus topology for guests Date: Wed, 22 May 2024 18:59:23 -0400 Message-ID: <20240522225927.77398-5-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240522225927.77398-1-stewart.hildebrand@amd.com> References: <20240522225927.77398-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB03.amd.com: stewart.hildebrand@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DC:EE_|DM4PR12MB5866:EE_ X-MS-Office365-Filtering-Correlation-Id: 2e0fa9ef-0ac7-4e54-32a9-08dc7ab2f337 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|36860700004|1800799015|376005; X-Microsoft-Antispam-Message-Info: fnZLKv+SGJt4vX2RMtcs9tiwjbyCahC6JTuuxvTAgkdpjbAsShlbm2pV6t9bqcFm0uIXmjIFo3TwKM5+j5IIzoh0GwI4GqmV7QRC0qglEmsNkD0X8KSP6ch4DQkAEC3fiP8RExYNNY0+DoEn1Wb1pwq14DxfHfucR2mKEdccizIgHbETCv5kSoEDe/pL8WXo5VFE/U6ZxUEFZSyDTfkP/yqNe8NApZP1mf0KX6DblgTGdsrtJXRwcTh/CW7IUq3GFwQsKk9I3ldsG258cdjlbsGuGpPof6JHYPfDWDTh65dj7Y1HMEHBA0chpSDmnw3Lh+BSknn/RkER5CTvkmnoXw1CuEvJzjp0Ux9rie9PNt/lC0qMCfUexD1xj0KiCygIZAzyjgC6L6xeGq/+JneN4jZbdXVfLr8uKWE4Hxr2jjI3eIE6mz4jkSRZvLpwVCI9Op63lx09jP6g8O3cnYG8tBFffrvGMaAtwBMM1Mk2HKg0VlzblV0jpr2CNWQWVOQ4nyYH2JzQcYeG6Z4ynlv90VGfjCE48F/0nlQLEOOQTlCNDqT9OOzsnSRKO/yNgHm8NKqsLReMHxUU7NfC5qLiHd+VSLfbGipts4gYgJDO/a0eTWaJ6ubeh3KyF1o4ohiBW4ZjNDz89dY30+m4q/akFfpENwYmT83Gg7CgI1VRfD/uq2KWivyh1OxPgvsHDxWL5b+MEfOS4HW7teIgoPAIx4+ZLA0dTMUsydaYfHnmJ0hz722MYKKEKx/uA9M28UP8snvET5h3HVnGPsWRoE6wtewOavtBBfV6ob7QWydj7VRJBUQODGkTJHDvCsTnCGjip+vJptXuI7tpyqVt7WQiAb8GIKBWdkyY+SB0GapM+AqzXE5WwgNytlK7WnVeXCZeRWh0DTIEIgBV/gaSI3SF8baSKDSWe5x4izWqV293gvR03XLJY8XqRoInioQwd31TB1I/ZRnNdetzpsZpi3TgrnZR5tm2h2j+dXQOshUC1orGdLA7REYAQvqxL3/JgC4w72Mix82EVp5t2MeoT5pRhzVszh4OALCpfYsD5DhaR8egojIuLPmyG/tagktwVQXX6L2MFiNYze2Nq/hOQBbiC7G7bRrzuFQVtL0o2x842baNPb+I9GYAKqVcYL4F2LqA/BAmGYNAWVD1Nqs5JJNGo4bkJrEMcwQQk65IG7POQs/RG+AYfHzAF0Zk4Rf6Y27farg/sBDSZ8cfv8UddOq0SygLxQ/JhTL2AJdSlAq5aJyr+GBbzWIv78U7ZMPP13RN8S8/r7IOYnXmpcjRxumk/xtRfd6lFDa+faAewO69Em4wCWut1UXKPQxBKGyblQ9S2WbR4ARxc59SiriOMjlSgbNRk1UCC9CvZhpeolZFSEU= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(82310400017)(36860700004)(1800799015)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2024 23:00:18.2078 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2e0fa9ef-0ac7-4e54-32a9-08dc7ab2f337 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099DC.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5866 From: Oleksandr Andrushchenko There are three originators for the PCI configuration space access: 1. The domain that owns physical host bridge: MMIO handlers are there so we can update vPCI register handlers with the values written by the hardware domain, e.g. physical view of the registers vs guest's view on the configuration space. 2. Guest access to the passed through PCI devices: we need to properly map virtual bus topology to the physical one, e.g. pass the configuration space access to the corresponding physical devices. 3. Emulated host PCI bridge access. It doesn't exist in the physical topology, e.g. it can't be mapped to some physical host bridge. So, all access to the host bridge itself needs to be trapped and emulated. Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Volodymyr Babchuk Signed-off-by: Stewart Hildebrand Acked-by: Roger Pau Monné Acked-by: Julien Grall --- In v15: - base on top of ("arm/vpci: honor access size when returning an error") In v11: - Fixed format issues - Added ASSERT_UNREACHABLE() to the dummy implementation of vpci_translate_virtual_device() - Moved variable in vpci_sbdf_from_gpa(), now it is easier to follow the logic in the function Since v9: - Commend about required lock replaced with ASSERT() - Style fixes - call to vpci_translate_virtual_device folded into vpci_sbdf_from_gpa Since v8: - locks moved out of vpci_translate_virtual_device() Since v6: - add pcidevs locking to vpci_translate_virtual_device - update wrt to the new locking scheme Since v5: - add vpci_translate_virtual_device for #ifndef CONFIG_HAS_VPCI_GUEST_SUPPORT case to simplify ifdefery - add ASSERT(!is_hardware_domain(d)); to vpci_translate_virtual_device - reset output register on failed virtual SBDF translation Since v4: - indentation fixes - constify struct domain - updated commit message - updates to the new locking scheme (pdev->vpci_lock) Since v3: - revisit locking - move code to vpci.c Since v2: - pass struct domain instead of struct vcpu - constify arguments where possible - gate relevant code with CONFIG_HAS_VPCI_GUEST_SUPPORT New in v2 --- xen/arch/arm/vpci.c | 45 ++++++++++++++++++++++++++++++++--------- xen/drivers/vpci/vpci.c | 24 ++++++++++++++++++++++ xen/include/xen/vpci.h | 12 +++++++++++ 3 files changed, 71 insertions(+), 10 deletions(-) diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index b63a356bb4a8..516933bebfb3 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -7,33 +7,53 @@ #include -static pci_sbdf_t vpci_sbdf_from_gpa(const struct pci_host_bridge *bridge, - paddr_t gpa) +static bool vpci_sbdf_from_gpa(struct domain *d, + const struct pci_host_bridge *bridge, + paddr_t gpa, pci_sbdf_t *sbdf) { - pci_sbdf_t sbdf; + bool translated = true; + + ASSERT(sbdf); if ( bridge ) { - sbdf.sbdf = VPCI_ECAM_BDF(gpa - bridge->cfg->phys_addr); - sbdf.seg = bridge->segment; - sbdf.bus += bridge->cfg->busn_start; + sbdf->sbdf = VPCI_ECAM_BDF(gpa - bridge->cfg->phys_addr); + sbdf->seg = bridge->segment; + sbdf->bus += bridge->cfg->busn_start; } else - sbdf.sbdf = VPCI_ECAM_BDF(gpa - GUEST_VPCI_ECAM_BASE); + { + /* + * For the passed through devices we need to map their virtual SBDF + * to the physical PCI device being passed through. + */ + sbdf->sbdf = VPCI_ECAM_BDF(gpa - GUEST_VPCI_ECAM_BASE); + read_lock(&d->pci_lock); + translated = vpci_translate_virtual_device(d, sbdf); + read_unlock(&d->pci_lock); + } - return sbdf; + return translated; } static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, register_t *r, void *p) { struct pci_host_bridge *bridge = p; - pci_sbdf_t sbdf = vpci_sbdf_from_gpa(bridge, info->gpa); + pci_sbdf_t sbdf; const unsigned int access_size = (1U << info->dabt.size) * 8; const register_t invalid = GENMASK_ULL(access_size - 1, 0); /* data is needed to prevent a pointer cast on 32bit */ unsigned long data; + ASSERT(!bridge == !is_hardware_domain(v->domain)); + + if ( !vpci_sbdf_from_gpa(v->domain, bridge, info->gpa, &sbdf) ) + { + *r = invalid; + return 1; + } + if ( vpci_ecam_read(sbdf, ECAM_REG_OFFSET(info->gpa), 1U << info->dabt.size, &data) ) { @@ -50,7 +70,12 @@ static int vpci_mmio_write(struct vcpu *v, mmio_info_t *info, register_t r, void *p) { struct pci_host_bridge *bridge = p; - pci_sbdf_t sbdf = vpci_sbdf_from_gpa(bridge, info->gpa); + pci_sbdf_t sbdf; + + ASSERT(!bridge == !is_hardware_domain(v->domain)); + + if ( !vpci_sbdf_from_gpa(v->domain, bridge, info->gpa, &sbdf) ) + return 1; return vpci_ecam_write(sbdf, ECAM_REG_OFFSET(info->gpa), 1U << info->dabt.size, r); diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 1e6aa5d799b9..86a89adb63b8 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -81,6 +81,30 @@ static int assign_virtual_sbdf(struct pci_dev *pdev) return 0; } +/* + * Find the physical device which is mapped to the virtual device + * and translate virtual SBDF to the physical one. + */ +bool vpci_translate_virtual_device(const struct domain *d, pci_sbdf_t *sbdf) +{ + const struct pci_dev *pdev; + + ASSERT(!is_hardware_domain(d)); + ASSERT(rw_is_locked(&d->pci_lock)); + + for_each_pdev ( d, pdev ) + { + if ( pdev->vpci && (pdev->vpci->guest_sbdf.sbdf == sbdf->sbdf) ) + { + /* Replace guest SBDF with the physical one. */ + *sbdf = pdev->sbdf; + return true; + } + } + + return false; +} + #endif /* CONFIG_HAS_VPCI_GUEST_SUPPORT */ void vpci_deassign_device(struct pci_dev *pdev) diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index da8d0f41e6f4..533a319406b1 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -304,6 +304,18 @@ static inline bool __must_check vpci_process_pending(struct vcpu *v) } #endif +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT +bool vpci_translate_virtual_device(const struct domain *d, pci_sbdf_t *sbdf); +#else +static inline bool vpci_translate_virtual_device(const struct domain *d, + pci_sbdf_t *sbdf) +{ + ASSERT_UNREACHABLE(); + + return false; +} +#endif + #endif /* From patchwork Wed May 22 22:59:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stewart Hildebrand X-Patchwork-Id: 13671163 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 79AEFC25B78 for ; Wed, 22 May 2024 23:00:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.727922.1132640 (Exim 4.92) (envelope-from ) id 1s9uwq-00022O-0b; Wed, 22 May 2024 23:00:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 727922.1132640; Wed, 22 May 2024 23:00:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9uwp-00022H-TT; Wed, 22 May 2024 23:00:39 +0000 Received: by outflank-mailman (input) for mailman id 727922; Wed, 22 May 2024 23:00:39 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9uwo-0007HJ-Uu for xen-devel@lists.xenproject.org; Wed, 22 May 2024 23:00:38 +0000 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on20600.outbound.protection.outlook.com [2a01:111:f403:2409::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 18087c7d-188f-11ef-90a1-e314d9c70b13; Thu, 23 May 2024 01:00:38 +0200 (CEST) Received: from DM6PR03CA0057.namprd03.prod.outlook.com (2603:10b6:5:100::34) by SA0PR12MB7461.namprd12.prod.outlook.com (2603:10b6:806:24b::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.19; Wed, 22 May 2024 23:00:31 +0000 Received: from DS3PEPF000099E2.namprd04.prod.outlook.com (2603:10b6:5:100:cafe::59) by DM6PR03CA0057.outlook.office365.com (2603:10b6:5:100::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.19 via Frontend Transport; Wed, 22 May 2024 23:00:31 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by DS3PEPF000099E2.mail.protection.outlook.com (10.167.17.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Wed, 22 May 2024 23:00:31 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 22 May 2024 18:00:30 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 22 May 2024 18:00:30 -0500 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Wed, 22 May 2024 18:00:23 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 18087c7d-188f-11ef-90a1-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gd2Ybzmvg/1MIYTk7SOkvkxrXKIFu4+2/cgqFm2VEqs/WTypJ+XGibpbbeoFzTVLCUtaCbbICcEmm0l2V45kOYn3saYaWG+MQAFMcIgvrHRom8ZY98QXG3+CV9ES1dyvqYBy5mpUzfTvf3Wuxui7bLmKy0g2sQRWdgQmJjWO2ruGpef96OYVAcUGtxx2Nhib55HKDM5u3wkH9XmntzEKQkQcMp87CGrwY1SszGRmqh1IlZERfCEkaWjjeVf6Jh0jN9OkY6M1XnxgpBdMRdu7gRQc59sKwRM/qzlyJSxDvQp+TFhm7Uv8HwPrY9tVVAWGfUG5bNDjRxJrjLDXSmdJBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=wg1lIYFsxCkrbMSdoPQQCZQ7ozFKfKSY7zA6PHJCXCc=; b=Ei4v0t+5iSUYlVRq4f0kyy5WD+V7a2sl6gJrvwnVSW+je3AGLIkbIbYnzJ/qRidXf+8ETA9R2dUibX81jsyyrWtJzyVUoNYQrUTjU+z+hecz30XWA5d0AShgVeIYkkkpN3rWSNsIJ+Oy4KJkg9I1nWqwZEZVhby4G9Jjo3YDywHJ+ewDDOCHe7eihqc14AGksxoz9WwZwJeprjJKxgetNcbB+/w67SgqQjhy2GBeSSQ219riyjTDvAE2WOoMND8itqJ8rI/tzb39fFhCNviryHBKlJArNkI/UFJlRUNnOozWQVMxXuU3VhFkaL/d9bNGk/yOOpIWcoUcBzKynyF4bw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.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=wg1lIYFsxCkrbMSdoPQQCZQ7ozFKfKSY7zA6PHJCXCc=; b=tlY1/bVaMY4/LpD5YxM+o85FZB1KQroOYHN/F3Bq7bi6WhPtwspq++/Cr3FSJP0anZWmjhxRZRcbaB7w3iabJHDkCJFd4KqeBcChiOPqO8zSKZpsvsGE2ZwOY71t8WVYuhw3UFON6w13FratC0+n+QVO19pU9NGm18tGf1r4eCw= 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 (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=SATLEXMB03.amd.com; pr=C From: Stewart Hildebrand To: CC: Oleksandr Andrushchenko , "Stewart Hildebrand" , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" , Julien Grall , Volodymyr Babchuk Subject: [PATCH v16 5/5] xen/arm: account IO handlers for emulated PCI MSI-X Date: Wed, 22 May 2024 18:59:24 -0400 Message-ID: <20240522225927.77398-6-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240522225927.77398-1-stewart.hildebrand@amd.com> References: <20240522225927.77398-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: stewart.hildebrand@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099E2:EE_|SA0PR12MB7461:EE_ X-MS-Office365-Filtering-Correlation-Id: 3400ac04-c933-4df0-d5d3-08dc7ab2fafe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|36860700004|82310400017|1800799015; X-Microsoft-Antispam-Message-Info: TLhkC9k/W5n731QommvrKtoFE5n2rWV9SKXCaE6U3kQE/0LjRzWJy2Wy+DYmkfnHEhe5g6m/9h5rpeI9jesP+07czC74A/ruFqHrVcRQX7G0Ovb3mwooVg67UbbbGHN11eQBgpH2ju3QM3l61xoXsqxNzdULEkEBtDHTj9JirczEdNHbvTuGpakw53v3D21X1J921dZCpybK9QmSyZwov2+FA59zCCOZJ3SDXdg1ffa+QHo3uGJqzF9O/aUEsBdcBHHEeVPzjp/yfpIOVoWmSqLHudN5UiQVYRQ9BAtDQAY5T7k4EuOG24gSUqUqQ8jBn1UJX5bWSyYzGuOsOUnwQ+M38aSF87gI11fVnESvmgnuiGV9+MMNkVrayt+eDcsmpYHTvHUTPlaunNoOnDU9rGZLo6T1+6F0rt4GyOk4DLz0gDh2bzKVvLrMNnsQajhrWbF0QKhUdqZNvaKa1Eeb5WWiuFJSAtWJGqKpxxeigLSaR76mPZmH0cHGukHp+CUzfWyqTjqmzijZwxQStjW71EMHVePZa1aIgjutX05G/OPsxYUZs9O0YdC3D7OYMN0aJdA+FMGhfBuV9i+0Cn91ICzFb2ZAUbHFAiE6j77OsUtI/ex3rvIiog2blcsLuAecvho79XQv1QugGuVsAgzd1LRmqHr59MDu4YeIJnm1sa4cFPv6MJDrAsUQNax8viXtWg5UaX5YTbQKxStooA7AH4Z5H8ny/gok3gzZmyYaWCcWEQ2dMeMNSmLyglXevlVkXoNrEj+UZ2EsLTF8solADg6tmtr5/NtoF3z65rRNv7o5p5ZwXORiUVucroU034h2i6+Z2O0vgc7ayVVbBbeGMRlF/+76VVbKTbWghVowyZsL7ANcuidkvlsI/cBwfgjeW8JvA57+tWgsFKlBwQx9G8ObJ2zVvVAf2eTPuNNmZ5rORi4YaG9yZZQFIMYrv8NNXtYqwuEC9YQCdtHioox6wtcy4Wh5Ka3x7eB+Y6BVPwosu7gEOsLNenqp2JNivFqWv5MWe/VUgg6hc/v6GBQbNK6pKt2wLwFJT9NJizmabMP7NvJ/ZIsT+/4WVu55rAP1otbaEItcwLvjYIwCUqge+cuJgRfFnTGyPjEnD9fZ8GDEYFzubBMILouvOwQPQ5ltR0fi10xlMC3/Jvp2MUKaLKixde4KhzxVtjw+UFFpDikzlp8/sib7aZfWJh2/r6JAEKLjts9EnbNDgL25Z+ieg3LN0yd3E5hB0t1De32Lm4goviXrt0BgL5o9+0zqbTTKaDuWpOSjpLaBq7t++kKRUMp+LmEYxoRxgX87uBuTqwPjTY/bMKHVojk72gqlV5ueO4Pe/mfBnncWMRGWvQMBZatPLN55P9V+IcNQqVD6i6bEe6HRXyLRkZ6xlprHd7tf X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(376005)(36860700004)(82310400017)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2024 23:00:31.2602 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3400ac04-c933-4df0-d5d3-08dc7ab2fafe 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB7461 From: Oleksandr Andrushchenko At the moment, we always allocate an extra 16 slots for IO handlers (see MAX_IO_HANDLER). So while adding IO trap handlers for the emulated MSI-X registers we need to explicitly tell that we have additional IO handlers, so those are accounted. Signed-off-by: Oleksandr Andrushchenko Acked-by: Julien Grall Signed-off-by: Volodymyr Babchuk Signed-off-by: Stewart Hildebrand --- This depends on a constant defined in ("vpci: add initial support for virtual PCI bus topology"), so cannot be committed without the dependency. Since v5: - optimize with IS_ENABLED(CONFIG_HAS_PCI_MSI) since VPCI_MAX_VIRT_DEV is defined unconditionally New in v5 --- xen/arch/arm/vpci.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index 516933bebfb3..4779bbfa9be3 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -132,6 +132,8 @@ static int vpci_get_num_handlers_cb(struct domain *d, unsigned int domain_vpci_get_num_mmio_handlers(struct domain *d) { + unsigned int count; + if ( !has_vpci(d) ) return 0; @@ -152,7 +154,17 @@ unsigned int domain_vpci_get_num_mmio_handlers(struct domain *d) * For guests each host bridge requires one region to cover the * configuration space. At the moment, we only expose a single host bridge. */ - return 1; + count = 1; + + /* + * There's a single MSI-X MMIO handler that deals with both PBA + * and MSI-X tables per each PCI device being passed through. + * Maximum number of emulated virtual devices is VPCI_MAX_VIRT_DEV. + */ + if ( IS_ENABLED(CONFIG_HAS_PCI_MSI) ) + count += VPCI_MAX_VIRT_DEV; + + return count; } /*