From patchwork Tue May 14 14:33:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stewart Hildebrand X-Patchwork-Id: 13664202 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 D1994C04FFE for ; Tue, 14 May 2024 14:34:39 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.721580.1125112 (Exim 4.92) (envelope-from ) id 1s6tEe-0004y2-N2; Tue, 14 May 2024 14:34:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 721580.1125112; Tue, 14 May 2024 14:34:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s6tEe-0004xv-KM; Tue, 14 May 2024 14:34:32 +0000 Received: by outflank-mailman (input) for mailman id 721580; Tue, 14 May 2024 14:34:31 +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 1s6tEd-0004xK-7p for xen-devel@lists.xenproject.org; Tue, 14 May 2024 14:34:31 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20600.outbound.protection.outlook.com [2a01:111:f403:2418::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 11bd1953-11ff-11ef-909d-e314d9c70b13; Tue, 14 May 2024 16:34:29 +0200 (CEST) Received: from BY5PR16CA0033.namprd16.prod.outlook.com (2603:10b6:a03:1a0::46) by DM6PR12MB4057.namprd12.prod.outlook.com (2603:10b6:5:213::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55; Tue, 14 May 2024 14:34:25 +0000 Received: from CO1PEPF000066EB.namprd05.prod.outlook.com (2603:10b6:a03:1a0:cafe::42) by BY5PR16CA0033.outlook.office365.com (2603:10b6:a03:1a0::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55 via Frontend Transport; Tue, 14 May 2024 14:34:25 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1PEPF000066EB.mail.protection.outlook.com (10.167.249.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7587.21 via Frontend Transport; Tue, 14 May 2024 14:34:24 +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; Tue, 14 May 2024 09:34:23 -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; Tue, 14 May 2024 09:34:21 -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: 11bd1953-11ff-11ef-909d-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T9xWYeEt/y4M2g1Rse67Wb5ca6ptMjIns5y2zTje/+qy5Spkml49G3GuqYnRSrIyx2OR86fKLTW1XqjMeoANHt4rSJqoVUrktFbfoxwop0ZtTZKrp+WJX34nEU/mQqxPS3viCqLdrVz5YjnfK7k5niWdV08SZEjtXfcw6/r0JcpyPFBmOulboPSkmufmiU1y5KNvO89slSvo7RJrtLQG4kGN2nZAaQbjGmErPTxQBAwnMg/YgwIqqonNUjh0q3bJ4ZkuAwT97MWOqC4eTFcxkU5IxYGhQP+anlDt4a1IDR88rE6yS3lhrB4znwyjH7/Bxt6cPe+S5CAoC68T62OyVQ== 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=zUwBnsMoww8f8q0OFnkTt7/zeC8tzJGFYO6woXqxVXg=; b=VWgoFIpP8ruzJEm2eTp2Vo315U4r7BOWxnZmw+xOCyNB/gexT0Pdg1ft+yRnlhzR1LY8DXWUrEL2kkiThUrhoAkZEDDE5ZIKgGSRTTuvojYI0297veqo4uG0iJFtHGig8I704jQHv3gDYqPCodYonBXSq3c1jAZsQwgRULlYzajAfYfBSQcgYMfNtK69DF3URVHUWjqNgiQT/ej+Kj24dM1EOa+DksFbIbFAgm2QAgvwfEa/VXjiKc1lqhfX9ZS6Zcl7T1jTYXX8jD+8xY6HFibyDqjw1i0uy79Ubj03JKPMmf2TEBbaXp0ykksIaeIvzR53m8nLJs16Y5yyfw+sAA== 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=zUwBnsMoww8f8q0OFnkTt7/zeC8tzJGFYO6woXqxVXg=; b=UwfE0G3R4vCNPgoz90RetIJrgQ/ceeqNn0fW2CU9UYs8//3Mwek02W9q8fLK5qfePXp+yHrmsX5Bzvd/cFtL2C5ccHpwC1Y3GGLXL+9dOTaCCbL3zyd69y8DF2pZrT9OHDHhCwMLhtQn7VNzcbcQZ+/y1IrhdoUtD1Ycrk98kxM= 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 , =?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 v14 1/5] vpci/header: emulate PCI_COMMAND register for guests Date: Tue, 14 May 2024 10:33:53 -0400 Message-ID: <20240514143400.152280-2-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240514143400.152280-1-stewart.hildebrand@amd.com> References: <20240514143400.152280-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: CO1PEPF000066EB:EE_|DM6PR12MB4057:EE_ X-MS-Office365-Filtering-Correlation-Id: 364e5c62-d5e9-4e98-1028-08dc7422f3bb 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: GtlWqU/re/zNBjVbhxZxiAoBPlVmZCANJkh6QxhvBUeEiljp51+ct6ltLQQSY/I3wKJmgjyeArBM1eUrJey6uMkMw9pnqhLewfpGhvvCmWKev+6D0/QiwWZ/o7xKXsURKAH8Kfi8+ZIHdl2eZ7cyPh3BIO+gzh+C81qk3253a6Ru1veL9jPQE8RzSmH4XmIcDrkmJ5RYRmuIFaSh4tyuDIIjwfiyj//QpHFiut2fi80GLf8sYBIQ0DM06cwiFPGpdBhH9L1C17SBJjNdFqgo1wYieYbntMLo6lwsybFf+8FkXdizuwkQkWeShl43Mgodr0lf6cXbFNd1NgzYp/P5xeGlq4xJBxb1VyWGry+EJVa6HSAVsBgmE6xaPgCnBoc10iFexgoLmM8ThWWW7WgG+pRvT3fxW7+r+5K4IqG1iacaeUhjZLJ8x2qvNyECViHMJHPv/TcGrm9kFErkTE2soZlJ7i2tOrLSRjKOfHBsx3K0v4blxX7lPNpve92zyGVe5NgNvexsgNR4x7hNWzbilfEn4IJSWAz1xq2CxvkvPikdhg35mdryg+0IquP63HcYk70/F60pucrkxQc3OykOfw1vVTDbV8Ph1EknQ/Pvp5RwHZAymoOSCapTjmAFRuKkK/XgBPCdTZKFfEFmzuGKByMjHJdLRxy4EVAYqFFG1+ZeM+Aht6FGnFAcwO8lgKglHrWDs+acyUf7yABnbfcNHcZlb9ntPr5hobgmhYQjLOIMDzPW8xntdYhGcA/s5UvQ83AWf+EMnGZtmHS3c/++XJcYfh5QpwL6vSxdpDgZrFYWFFHTGnpp6MJHr0pcX+LNkVcj6wP32v2aE11hMiCCaeTvcJpHHqISmSt+jmqpWhtt4uB/ccDyVzvBjRmUHOW0G2YTGoRXEGBLu+nPkuExaF+R23mL5Lw+1a0i6vIDaVc31UbB+wona8tMN01TBIKT+YUbQGRoULMsCqdt2G3ojZ38eE5hlSk3tkARPPgmMtnB8L8g2NmDU1OtGQxubkbn5OSYJs9HIiH9pjLhCf18588/dxmaZiyS7/wKdC7lTa240C5h0nFLnqlHIDDsO7za63NdwgxIefiHM3ma5f2GpTnyZJsDyZluoWB2cXlLGgdeeERWslMn6ZR3ovikf0YWVFHceuXL9PrSvTXuiOKI3cTRP8SYQ9fXjD/mCMXYUuYuyfMMwrZ0s0oyJGrvSgQ3x0vHZrRxVlADcZZyjtnQv3B3/FDKc9Ur59DDC810zw8yUOrEeKQ7x9W1KqR7T8+j/bFI6e8lFouplEE8kVhyRfVD/0RhkTQgS/xOKx+9yrFqgwowzTKvHIFahUHGVDnW 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)(36860700004)(376005)(1800799015)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2024 14:34:24.5194 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 364e5c62-d5e9-4e98-1028-08dc7422f3bb 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: CO1PEPF000066EB.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4057 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/dom0: rsvdp_mask Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Volodymyr Babchuk Signed-off-by: Stewart Hildebrand Reviewed-by: Jan Beulich --- RFC: There is an unaddressed question for Roger: should we update the guest view of the PCI_COMMAND_INTX_DISABLE bit in msi.c/msix.c:control_write()? See prior discussion at [1]. In my opinion, I think we should make sure that hardware state and the guest view are consistent (i.e. don't lie to the guest). [1] https://lore.kernel.org/xen-devel/86b25777-788c-4b9a-8166-a6f8174bedc9@suse.com/ 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 | 8 +++++ xen/drivers/vpci/msix.c | 7 +++++ xen/include/xen/pci_regs.h | 1 + xen/include/xen/vpci.h | 3 ++ 5 files changed, 73 insertions(+), 6 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 47648c395132..2491dbae8901 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, + PCI_COMMAND_RSVDP_MASK | + (is_hwdom ? 0 + : 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..3e414e69a432 100644 --- a/xen/drivers/vpci/msi.c +++ b/xen/drivers/vpci/msi.c @@ -57,6 +57,7 @@ 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 +71,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 Tue May 14 14:33:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stewart Hildebrand X-Patchwork-Id: 13664203 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 DAC25C04FFE for ; Tue, 14 May 2024 14:34:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.721582.1125122 (Exim 4.92) (envelope-from ) id 1s6tEp-0005Kl-4s; Tue, 14 May 2024 14:34:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 721582.1125122; Tue, 14 May 2024 14:34:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s6tEp-0005Ke-1B; Tue, 14 May 2024 14:34:43 +0000 Received: by outflank-mailman (input) for mailman id 721582; Tue, 14 May 2024 14:34:42 +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 1s6tEo-0004xK-IB for xen-devel@lists.xenproject.org; Tue, 14 May 2024 14:34:42 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20601.outbound.protection.outlook.com [2a01:111:f403:2412::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 18ab5345-11ff-11ef-909d-e314d9c70b13; Tue, 14 May 2024 16:34:41 +0200 (CEST) Received: from MW4PR03CA0105.namprd03.prod.outlook.com (2603:10b6:303:b7::20) by SN7PR12MB6911.namprd12.prod.outlook.com (2603:10b6:806:261::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55; Tue, 14 May 2024 14:34:36 +0000 Received: from CO1PEPF000066E8.namprd05.prod.outlook.com (2603:10b6:303:b7:cafe::a) by MW4PR03CA0105.outlook.office365.com (2603:10b6:303:b7::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55 via Frontend Transport; Tue, 14 May 2024 14:34:36 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1PEPF000066E8.mail.protection.outlook.com (10.167.249.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7587.21 via Frontend Transport; Tue, 14 May 2024 14:34:35 +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; Tue, 14 May 2024 09:34:34 -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; Tue, 14 May 2024 09:34:32 -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: 18ab5345-11ff-11ef-909d-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C86yrNUpMdZq+nJsTt1XuYh0Fw3MoV5MPVmkSU+eSZd3qBjQicV3Aj1B+FAh1UqEDM6EXvBnhYyLFL+Aeo3ETXB0iZgrifM0wsnbmeHswoilLKYG5fK/coeMSfXZ7msjPZ+NlWAHA5MoJW6ubZTjGWXTnzJkgx9+fWviRuHrqIVQyLDoRdEVW2dDBqEbbGp1LjQKXRSMG01fL0Mq23ZbiB4RJJ00yDef4G6GfWobaVNg5A1ju7deJjFOK7hDzjMX6uwr4Fj+Og3wiTy8/3bWTgLYoCc0hAW/qwjfAnLv785vfJ/K97wfAtjk01lgZEiOfwfgi34ICWesOmxfqkYB5A== 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=snqZUZKvXcG+0ruyZzznMKpfTsrySOP3X8wsZHFKOLM=; b=P6CdCkh81NS3syoOwydVTeCj8ee0kUJRzIGeDnHBWhwgoN2CdATaH7JO6aXvudqM6BjidbOfj9zyCVDUWLtei98fVo9i3HixE2ecoMipHlrTx52pRotgsclYJI3Fh8yyAk9A939XCSN5Mwm3ZkSgaU6kU/8g3U7AAXhejAt7zVHkews1oLh4hrkl9AOou2XooHOxHE31/9ORTIU1gUwMOJT1YWPu8ek9IxoujMDFx/rZDHahhWxfdkukKBNLqWtZ5jIG/cJ3mMfaXfLdTttQe4l18XbIcXrgqE1PcBZCvPtphY243yZvAgh+A2OkDe17Qwz63gh/v/rsT6x2V+Uxdg== 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=snqZUZKvXcG+0ruyZzznMKpfTsrySOP3X8wsZHFKOLM=; b=0TzH70P4RSpzIkBQp5+G6QXIJwjSp0cGsz4MrfjkZNOWHfioeURCRq0MgOdqva5UkKsqwBnLeSdrW+uO0gdqOAmzh5xDsGAYVdtEvj0bkxbO5xmXEXSVO6NaA5792OW94WttjLqoIQftPUVdqoqxPdf86zyFa/rJF/qaTeBq0ww= 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 , Andrew Cooper , George Dunlap , "Jan Beulich" , Julien Grall , "Stefano Stabellini" , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stewart Hildebrand , Volodymyr Babchuk Subject: [PATCH v14 2/5] vpci: add initial support for virtual PCI bus topology Date: Tue, 14 May 2024 10:33:54 -0400 Message-ID: <20240514143400.152280-3-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240514143400.152280-1-stewart.hildebrand@amd.com> References: <20240514143400.152280-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: CO1PEPF000066E8:EE_|SN7PR12MB6911:EE_ X-MS-Office365-Filtering-Correlation-Id: e10c92a1-2e7c-4b8d-d914-08dc7422fa4f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|1800799015|36860700004|376005; X-Microsoft-Antispam-Message-Info: IVwIASX5u+qR4utHccDLFQXnE7EQsaXNuJJvMcW01gKTsrAeVg+VwWsFk7S1ASnNDy9K8ELwSgG7qHzfC+RsPbOjXobOf4pIf1wPx6Q+phTCIDUoq7NT8p3QHYJ1zYbMpr/nVIQ5/DsRD5GkglS2i1s6KjLCzZmNJPkzvf27DZBRPhf3L/Cc8dCemJ5FOnSgrb4kVDDLEvYCasMfrWGrAdegQ3VF/gfRhfE+RrLQNShU4l9ozuefA6JS9aJ/FCGMNWVnexC/cK39oPUszlTf3zIKm43aKJ+G5MQDzcglxKOL1qe7UP6pKDON0AO41qtNcu+ZhEb19scbSuLPMOJoNFAByjcQxtcsCmQOmtjA08Bk1cadOcLaXUFq9iFr5D7RBV5FDqyR2YzGNIJSOiPODqgbRfUCU8Zzerlb7VIMlADsS41fgaIyl1abfB8EjNagV+N9pyHcptHVjHOusapZfnhVkeOJTCevCbaZhACPLgwb0PKBE0yFA80NXW/3bWIdrXUNouDVu4PNOAYKcNXPi00mjru8qrx3aCJ4Y4JFq3wiJSqomc2DtJjgA4Q1hzRkFRpcb5qoXr/Sk2fmUdP84SXNQ31xxqS0TtTqHCHXLUo0x1PBQBaZiditXGHNrfKTnd8dvdF+wWcOCEWXbOWDC+lBEDTAy4+ckcJKDZWj1fqOXUR6MCVcWLmJ6bXzasBVIFb7yzJNYjY/PP4T2BwSWByxNFtnLcyGRf4We3ZZ1kYG9FVo0R5K/HuR5ddSqqyUq9lpF5Te7ZdCJvKeZJ6jKl1ncJu14RHCbydrMpMtpwdR7UpzU7VFGTBkqB4vL5+yJjvODMxanbyiTw5NviUjWRr5jfktifNs1kFbTwMucI9kgbbJmNWRrnq6eXXhN+KxrX52Jis91/kGxvK1LWukTTOEJpi2QcJXyEN3p9xPbNIGTXQklKzATho1RxwK3bFmKZTmv0qUfeHFdjponjJVB6dOJ9HVMLDWuajvLJKtfy2d/sbtnKe4Ese0cXc4GKhoaAw/2qHfYGNoOzLH1e7uPTL9ybb0Y8kpZfuBYlaOzQnOwSWba4Hp+uvKKSlpbLofmY4CHijO7mABJBdnJ62UHUdn2VuyGD0RnwTEbHUfoUFjzZy4GPIhUccAFIyzgIWK8yaW4RRrPSvkfe9s+coD40KMWlyd6xUSIf8Vr1lCRnLSEjg1/vNbzO5pVvuNDyo5jYWolcDL0zrhphtiwpulO7188oL5NwV9jAiUjys0XAYH6qNS2u3jyiS/K5V4+PQquuJfx38Tqi7BzVTaZiY64rZHqo+As9vpFx07awU8bRTLujb+orULpK2hPI6KFg0gdneV/ImkOVItcpB3Th5gIaKyuWMOuqiIHhR2Vqkju58= 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)(1800799015)(36860700004)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2024 14:34:35.5296 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e10c92a1-2e7c-4b8d-d914-08dc7422fa4f 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: CO1PEPF000066E8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6911 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 --- 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 | 12 +++++++++ 4 files changed, 82 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..23722634d50b 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 add_virtual_device(struct pci_dev *pdev) +{ + struct domain *d = pdev->domain; + unsigned int new_dev_number; + + if ( is_hardware_domain(d) ) + return 0; + + ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); + + /* + * 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.sbdf = ~0; + rc = add_virtual_device(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..980aded26fc1 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,10 @@ struct vpci { struct vpci_arch_msix_entry arch; } entries[]; } *msix; +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT + /* Guest SBDF of the device. */ + pci_sbdf_t guest_sbdf; +#endif #endif }; From patchwork Tue May 14 14:33:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stewart Hildebrand X-Patchwork-Id: 13664204 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 18F69C04FFE for ; Tue, 14 May 2024 14:35:07 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.721586.1125131 (Exim 4.92) (envelope-from ) id 1s6tF6-0005yo-CZ; Tue, 14 May 2024 14:35:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 721586.1125131; Tue, 14 May 2024 14:35:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s6tF6-0005yf-9o; Tue, 14 May 2024 14:35:00 +0000 Received: by outflank-mailman (input) for mailman id 721586; Tue, 14 May 2024 14:34:59 +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 1s6tF4-0005tT-VJ for xen-devel@lists.xenproject.org; Tue, 14 May 2024 14:34:59 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20601.outbound.protection.outlook.com [2a01:111:f403:2412::601]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2214bc5a-11ff-11ef-b4bb-af5377834399; Tue, 14 May 2024 16:34:57 +0200 (CEST) Received: from CH2PR07CA0022.namprd07.prod.outlook.com (2603:10b6:610:20::35) by MN2PR12MB4254.namprd12.prod.outlook.com (2603:10b6:208:1d0::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.27; Tue, 14 May 2024 14:34:50 +0000 Received: from DS3PEPF000099DB.namprd04.prod.outlook.com (2603:10b6:610:20:cafe::ad) by CH2PR07CA0022.outlook.office365.com (2603:10b6:610:20::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.26 via Frontend Transport; Tue, 14 May 2024 14:34:50 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099DB.mail.protection.outlook.com (10.167.17.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7587.21 via Frontend Transport; Tue, 14 May 2024 14:34:49 +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; Tue, 14 May 2024 09:34:49 -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; Tue, 14 May 2024 09:34:42 -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: 2214bc5a-11ff-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dvK8YW3OdSTp7BR35H5WYReHmVXCDzjxy/jatDpZ89ZsyNf2PvJ4pD+aYBareE2t/Ucifc+fFNDudN+P/wiGvl/q6ZJyzhV2mByNVr2W82H5NbW6RftrUf6aOMAM+KpDVl1YUtFg0RY94ZiFuQPYWKlEJ1MIraQgNZvRwVUR/lkwYcV9H2ZLVmNMc2UuT583mi0IbKgyj1YyJOCNQSmaF3oEAxz/NdQt5pVX7XBvLsvY3JryAINVIdqr3b0ilz+UOi8B94A6/aKF2tQ8/vyeXDHzfDy03vsMa1GGwH9AEl3Rzp8p8x83S6pvaMhW55TW587yo4JnvSdBaJ7lreeQ1A== 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=Fz5VFWknMZx6HHUaDNZrtZ7oahJwlLDFqbFpBhGUT+E=; b=F3nkW1OkQV5weYKJ4cf3BBBveZcM3DjcvqszT9p/6Fzpsjv8EpBgeuOZrRqq4Etb7kVTCV5XGddGegSEQk1QJqCwK4YxviyYoixNxNXPwN6WliK8u4zjOnLBtvFoOL5YgExWmB+JtUm710eaCHpezEDq1yf8NUrbSEzmLBWsnQWxX0cuW/IcHJAhc8/8oR047XG5uLfQ5/fe1ZFiaOtH2VOpkpfd9QQvrxqkU24TLK4ZUT60R0W/oQ3NjpXgP3fwrpCFznrdOLZk4BPwvzEdUgtVSRe8h0W1UebPaXyNx4M52jfHll42f8b6KGnMJyMpi0BWrHBw7mja0dao/hWdGA== 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=Fz5VFWknMZx6HHUaDNZrtZ7oahJwlLDFqbFpBhGUT+E=; b=ijabFWS0YQIN1JvxDvuN7H+NOOrwD0hV5HSpXRs0XgI3RTSEpPbt8hY9n9Oempobwbc158gdlaC+zgq4IoYciVAa1dVRweIN+BYdOBjF1g0IdCjAWK4G5KB6cO5qyjFPImmMfn54hG7c8FTh/k5NTmO7kwgl8YVGSgjsf5oC3GE= 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 , "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 v14 3/5] xen/arm: translate virtual PCI bus topology for guests Date: Tue, 14 May 2024 10:33:55 -0400 Message-ID: <20240514143400.152280-4-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240514143400.152280-1-stewart.hildebrand@amd.com> References: <20240514143400.152280-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: DS3PEPF000099DB:EE_|MN2PR12MB4254:EE_ X-MS-Office365-Filtering-Correlation-Id: 021f1f9e-2393-4caf-2263-08dc742302d9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|36860700004|376005|82310400017|1800799015; X-Microsoft-Antispam-Message-Info: 72aDNwaCEi4ACEL7T6eSjo5aP4gesI8fE2UiN3kfdRYI1V23X4RabeFLe5VyRJnmkfln5SvXuu8IoihBb6XMAJ9swBHE3VtwZXMTnyOD5J9ZzwRYOR9NENFMCUiLbDzXHHJjvByYBxKRH5NLxtzqxGrq56WJ4xj/0NVqOrkyRmZPXDKXDiXIjyF+Sr8LLSYLJui2DdJKEAt6RwHGrK0WkRdfIFRv5WNpGck1A5/7QeDLFzH7FjMMQ7NZLhn/poZzHaKcZJOfamqNDDlCv2qpDLYdqDAiNOnep8Kq4xLjN5ovWr409cFWcw/sDPlaNlqTjaZIKTv24UTMTjKTV+8xJEV6qCHUzGTy19TmasxivStIh9CHfVN8WjRaXwEGWPJ4wGh6xn4rsZnteXGTiXQ9odLAtu0874O4QrWEihEsZG302Lf8QTRYoC2bYyBnuB07S1ro3RE7mednQQ3+O9mhMlNNMr6W8Civsa2Ylod0tiAmJhaIKLUMr29dlAx+z487aFTeEXpnL6GBNqRePBzRD/i7YXz487WeMmf/LLwo+WV6WdRqFmlQ5fGu+JRojJYFLA5kZ+vw+4+UMsz2nATT/2WVTdXwCXIUBzzy6Y5Y0WW0iZZkI912Fg36YhInF4N5Id7cLd4S9scouRfxukfO0bOPcjQEfQOCCZbhtTZH+FvkMK/R3pt2M3AsOqcomwelmD+BFILrmezC2nb4KQ/jMtVvMn/KIqBYs9acZita64WfJSgQE0fPwBgqQ7VqlE6Xz1L3BJrG33MJgwJFQvGO2hZIwGWDV4svdzZ3GQqr3ppVMY3hjpRC5Eaqd2x9keohdZxYu1Kb+DrN5VTT0raYl6kqQ1SpbxJKqoJ7iLjbl6u8NsEM6Qlm83zfyOQF22CQg9fkHOv7iufP6opKwXqZrQ7RLf6uqg7Wr+NIpg7M4fR2jvdRRQORovI5P2cavAQzr3NwNBBZZlWeuj34VDzdzbC2tdJUujsUtvocecVY02N7mSZ8CPmzooxk+TWJqNNFqWEm6V+fS+vTa8c7yJkZKzTCSPZl3v8Fwhq9veqaiE5MZgzN90by5qd+cPIXbgOjxG7GZ0EWwCpDgjJjLhBS60HV0t5LbJtvncfJOL+opTyETcHb2DH6BOqWQjzb/Rm2ewYmyj2v/aifqUwpgB76UVNZOUnjpwxKqIWrwGPJJwJe7wjY1aSE5aiOSwL4tIWr88xSTOq3PoMMiiZkRNh0DpA2+7a89oKZYmP1agMsAfQU6R+7PSyTDTOQJELFF2UymR4sfKbErd3AICFfN9I7KtF1fvIFR/ucN/YSVteLXozmcQFufmPZ4u+hN8CLDZYsTD25GlKFZIY6RI5UefsitVpzEXGqNWTLggq3y8pbD/wbtHv38fMoUNGV2im9MLEw 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)(82310400017)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2024 14:34:49.9292 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 021f1f9e-2393-4caf-2263-08dc742302d9 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: DS3PEPF000099DB.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4254 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 --- 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 | 47 +++++++++++++++++++++++++++++++---------- xen/drivers/vpci/vpci.c | 24 +++++++++++++++++++++ xen/include/xen/vpci.h | 12 +++++++++++ 3 files changed, 72 insertions(+), 11 deletions(-) diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index 3bc4bb55082a..7a6a0017d132 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -7,31 +7,51 @@ #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; /* 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 = ~0UL; + return 1; + } + if ( vpci_ecam_read(sbdf, ECAM_REG_OFFSET(info->gpa), 1U << info->dabt.size, &data) ) { @@ -39,7 +59,7 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, return 1; } - *r = ~0ul; + *r = ~0UL; return 0; } @@ -48,7 +68,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 23722634d50b..98b294f09688 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -81,6 +81,30 @@ static int add_virtual_device(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 980aded26fc1..7e5a0f0c50c1 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -303,6 +303,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 Tue May 14 14:33:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stewart Hildebrand X-Patchwork-Id: 13664205 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 7962BC25B75 for ; Tue, 14 May 2024 14:35:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.721588.1125142 (Exim 4.92) (envelope-from ) id 1s6tFG-0006R3-RX; Tue, 14 May 2024 14:35:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 721588.1125142; Tue, 14 May 2024 14:35: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 1s6tFG-0006Qr-O9; Tue, 14 May 2024 14:35:10 +0000 Received: by outflank-mailman (input) for mailman id 721588; Tue, 14 May 2024 14:35: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 1s6tFF-0004xK-Pe for xen-devel@lists.xenproject.org; Tue, 14 May 2024 14:35:09 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20601.outbound.protection.outlook.com [2a01:111:f403:2415::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 295e54c2-11ff-11ef-909d-e314d9c70b13; Tue, 14 May 2024 16:35:09 +0200 (CEST) Received: from DM6PR06CA0074.namprd06.prod.outlook.com (2603:10b6:5:336::7) by CY8PR12MB7610.namprd12.prod.outlook.com (2603:10b6:930:9a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.52; Tue, 14 May 2024 14:35:04 +0000 Received: from DS3PEPF000099DC.namprd04.prod.outlook.com (2603:10b6:5:336:cafe::3c) by DM6PR06CA0074.outlook.office365.com (2603:10b6:5:336::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55 via Frontend Transport; Tue, 14 May 2024 14:35:04 +0000 Received: from SATLEXMB04.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.7587.21 via Frontend Transport; Tue, 14 May 2024 14:35:04 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) 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; Tue, 14 May 2024 09:35:03 -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; Tue, 14 May 2024 09:35:03 -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; Tue, 14 May 2024 09:34:56 -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: 295e54c2-11ff-11ef-909d-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PcftE2FfCPHS65k20P2jyZcy626YJ3HQ3xqs0aSFk9K9qBttw7Y0pKxHVyGfP1uCaZYF6rdbg9JE+PHPSCfn17e0kRTBy/rUbIJTWboGcSG7yMEJ7A+XxbVZqZkxDy9Og5DqzHwm198fxDEpx2tVgF2x8YZOLG9VXm/sDKr2ZSzDmw1oiH9WXk3Tw0Aupm5xaVbJPwi5g5Om/XejX4G2x1GY4ND82YO2yrTeymkgDoDzFc6CNd1p2ZGhfo0kmWRKqfaPG7ykSD7+WsS0WMhXz6SB8CfovpJ6FuqX1xGlQhyw7I0/pCLDYDg3vjBobUIfDQ6vZ/if1y+4TBUnrr65mQ== 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=jSDIS7u8FBArnwQtMGorD6BVCk5kKDuvtvaxFhhABr0=; b=kUGTCcx+SNxWuYZ4AKNqHLogxzCOGNc0KD0WltYihxdUzkLF0kNxPgHQEHNYuePI5C9l1H5PlF+McPBHTIR3xYzXjARpavkhDtrw1Y/tDoyCmvmdbMtJigo7QkYGlyIHhq0/m8NIoW6peRzr5XHkK24YFMiC37baVLV++tJvpl1/4u25NuGFuJX5fR1rNXUfskRjQZeQ/0sjF1T8blC8K8wkRHjvVR3OXG7afSakmkirpPzUvAyz71eLhQFefB/hBCtuvH1qMEjHdRlzYMNGFCLL2WxyheDUzZfRdoU5YA0F9REPC3M8UIj5ok3dCag2M58GJn5GqMvCK235RehJWQ== 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=jSDIS7u8FBArnwQtMGorD6BVCk5kKDuvtvaxFhhABr0=; b=chB9KdJWptuT+nuuJb1FQmOKU/98g3cPsIAfwqYSJcJvJW3gmkq3YjucMELJsyg9TJJ6gew9wjxILp2pliuLOYXOwMyLxTKk0u1rehgjrEJsBtIDfgySn+LM3OSxjfYISfAiDTtKLlzbup+HaXjRAZDbH/BX9DHMnk2hBt4/UXA= 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 , "Stewart Hildebrand" , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" , Julien Grall , Volodymyr Babchuk Subject: [PATCH v14 4/5] xen/arm: account IO handlers for emulated PCI MSI-X Date: Tue, 14 May 2024 10:33:56 -0400 Message-ID: <20240514143400.152280-5-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240514143400.152280-1-stewart.hildebrand@amd.com> References: <20240514143400.152280-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: DS3PEPF000099DC:EE_|CY8PR12MB7610:EE_ X-MS-Office365-Filtering-Correlation-Id: 054dbf8b-0e00-4edc-a5e0-08dc74230b3f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|376005|1800799015|36860700004; X-Microsoft-Antispam-Message-Info: lqUVDnFTdJhmX13chB8ahkNu+P3fLDVWZ3mcOm7ftOGSTPQ8BgJXUJd/G8+8/+tsUSTJJVtiQpfURGSMaN2Tg0HfxyQO8SDPSmNZoI62djYolbftaz8TTKXMqvIOXZ3ADZaPjBCukC6exT9YHxxwNQRPmGHWhnYtlFwyWNYCGFR9zoeO+Q7a6qgflUzj0bcgROQjNU4+bAC/rsADv1qHTMIiDblMRmF9M56h50nICIzFZsdYGsooMFaaY7dK5UNVlXNMGSJPtjRKcxEOho9YiUNQHHgkkv7Hk1eS3+SZaIjSov+Bgd7zMozN+qAR10Lr+r4g/Nh3tPJf/eR3hWLFrLoaVKIVVEZjjdxbEuhLER1Mpdsxz3XSs2aV5HWyY7pO/QdmjNwVfIj5X57dcfPpEdzY7wg9p58U33SS8fSK8Ct6XnRv2Ii5N8zB4E41eoNKDUucH9bImNJwuhgMKY+LakowOciFZBig9jprNAQPZFpbgpcOlxC6yIOLlUUu+6xmrUhZcGRjv8yH3rjCLebNEEV7S3mcTw+dG/RWCH8Q138w5jdAyGDOaCMbRjl6QmEv2lJoXWWVc1AdsF+HsrNpN4qA59ixPbjaNrEVAZoblqd4N+wNqbTku1Rgh9K4TkzhtMhjUmL6Dp2kgV/bf9nWrXn4a/ggVgHu3W/+yfkP1dzTjsiqc94akNK32DWCSvQT0UD9alpxtKGdfbj/8re3dmp+YHRGDJnO1p24WDINEMD7duEf3JIjsqfWGbMZrMLX0Rm5B7i5WcbspqHW8kP2ya7L2s+YZ1DJWsTJyFXMluS66VJDANg/UifPVY7Vp5s/gktEpMlP/XL8XhnULgIeU2Qg5Rv6yPlcScCS/umth/qAC+2YRUkmFKfZdPR4geu+IQnI7xl762tB6X0DqlI/FEfSZGLaUGp/hrHH1pLNBiEW5nrTaBKwQnU2aoa7Iybp7k4jt0i6rIUg4KU50vwMvGYJ9xxr9G6o6x9bhaq0kNwcnDCMPyVLwHi+zh+E444RAosHkAGdQOJJeYp/im9olnbTwNficeWf/0UxG8MAy8IjAox6YP1jM31zIZeLBCLhUcID1tdEwHLSpfICisPg/MbPYTu6fX+wAtBuoA+nkjHxrYyTw9Ek/eU3HR0bvcv3CRIuANTXlldemxRZCcNPxBDCnWfVrdrWWtdnYyBxb1yECd9bT4ZJ4HslTuw6/NVc9SJKa596T7i3Yon8mNahrlFcdvzq15COsslCoOglTjZR/rmGKX8Rsq6gSYMFNT4nAgHsV3h28Z1druvxPRoW85uFi/4GXRvwFd+wD5PbNY1TUhrLWa2LeKbD4YMI3FErgl86i/0+DsU1fbQIOHbG9deYkUWFtSuj1l+49+74Jf0Pkr/oshYy7IrKnx93J+PT 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)(376005)(1800799015)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2024 14:35:04.0384 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 054dbf8b-0e00-4edc-a5e0-08dc74230b3f 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: DS3PEPF000099DC.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7610 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 actually moved here from the part 2 of the prep work for PCI passthrough on Arm as it seems to be the proper place for it. 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 7a6a0017d132..348ba0fbc860 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -130,6 +130,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; @@ -150,7 +152,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; } /* From patchwork Tue May 14 14:33:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stewart Hildebrand X-Patchwork-Id: 13664206 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 85D31C04FFE for ; Tue, 14 May 2024 14:35:35 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.721593.1125152 (Exim 4.92) (envelope-from ) id 1s6tFV-00070s-3y; Tue, 14 May 2024 14:35:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 721593.1125152; Tue, 14 May 2024 14:35:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s6tFV-00070i-1D; Tue, 14 May 2024 14:35:25 +0000 Received: by outflank-mailman (input) for mailman id 721593; Tue, 14 May 2024 14:35:23 +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 1s6tFT-0004xK-Q3 for xen-devel@lists.xenproject.org; Tue, 14 May 2024 14:35:23 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2060e.outbound.protection.outlook.com [2a01:111:f400:7e88::60e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 31c564ed-11ff-11ef-909d-e314d9c70b13; Tue, 14 May 2024 16:35:23 +0200 (CEST) Received: from MW3PR06CA0002.namprd06.prod.outlook.com (2603:10b6:303:2a::7) by SN7PR12MB7977.namprd12.prod.outlook.com (2603:10b6:806:340::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55; Tue, 14 May 2024 14:35:18 +0000 Received: from SJ5PEPF000001CC.namprd05.prod.outlook.com (2603:10b6:303:2a:cafe::c2) by MW3PR06CA0002.outlook.office365.com (2603:10b6:303:2a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55 via Frontend Transport; Tue, 14 May 2024 14:35:17 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by SJ5PEPF000001CC.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7587.21 via Frontend Transport; Tue, 14 May 2024 14:35:16 +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; Tue, 14 May 2024 09:35:15 -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; Tue, 14 May 2024 09:35:15 -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; Tue, 14 May 2024 09:35:09 -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: 31c564ed-11ff-11ef-909d-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bgo3z8RKUAeMa3//VZ3E6/Ae26SG+P7cyiZBEFk3moTngK7Bz0Ag3Gzsi2adNamwxPM7HvBikDOT9SJ3mR9eTUSGc++JyrwHhox62XVHkS2Fav/9XKXUlmwOO5yTtfO7WxGyohe8r46FaXBrd4ZtqNfzChPjKVnAN+vILRao3J+NYa37Er5+t3nAZSVt4YG+NT4EYZrbBg0ywJ/uevMz0v+/grPbcDY7KfRLhGCEQOU8lKQAo5kzQZNAa1IdyFarz+X9HPIoow5svG/GGtLuH29osMf4vX05egH5VWuhTUSeceBXhHfWiDrNHKsKt1n9z3EZMdSaUS1GYCAcudcemw== 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=RhlHUD9Uu3FrjzdtnmRTwtlA65attPhQDXfrRmCx33g=; b=WLMXxnfJwS3y8MFsQlfqpi4x4s4vPKNJrzd5ayzyobaOpFUfRdQZmmfzS25LsXc/Iaoj2Q+WDkppJyDdsy31gYgrFE6j8NSszLb1EKPVoh6EzYnO3P69EA/TjL8RHWhEzI5cNmP6cgMOZvDpiTLhtI76PJq9IslSLyTGO1m9ISWzdAgCw0nNbKKX4csT5g5sx3YqlNWxXX7fGVuXeeC0wMi83HdjHumcgbRGHVJxb2l3+VspNNGgoys7t8ktwamSMfV3Esq76xIlN4Y0DnXIEsb7YHA7TINn07HgvjOtO6b7u6uP7qvJZZxkircuNIyhEsvVScfbG7qPW9L/nC53Bg== 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=RhlHUD9Uu3FrjzdtnmRTwtlA65attPhQDXfrRmCx33g=; b=oZ2V6bMennaAUQdIMkXrd8Z40e1W+DZlj9XdxEG57oVnuhpmT3RjykTbjOrEyrnyWP1OwqXiLR14q/8L4YNTp1HNzW58jCI/3C2moJ++X9Lyyj8Ms5GdgtOBGF86kCw5lIVgC0q36njeGuj200/NfNhTAjAS4BVtKj2LnzgA7ak= 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 v14 5/5] arm/vpci: honor access size when returning an error Date: Tue, 14 May 2024 10:33:57 -0400 Message-ID: <20240514143400.152280-6-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240514143400.152280-1-stewart.hildebrand@amd.com> References: <20240514143400.152280-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: SJ5PEPF000001CC:EE_|SN7PR12MB7977:EE_ X-MS-Office365-Filtering-Correlation-Id: b0ef63ab-8853-4624-2182-08dc742312ce 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: IRQdCSQ76CNm6BAyrpNWu5W0Gq18D7L2QRGuVj/HmSj/CzJC4jYK+lHewJNV3Hs8qrW5bw2bfysC+foYio+wSwdyR00iSU04q6j1+Hc1sX2X2jzUytJHyJLxgW7dVIyP+bag4ZBUBxMVcADEAiSs3RrPnsvZEIq0JP+UV+suf/LGZkzoIkPfS6QxOk6ALoB3eH5Jk8pUuvMy3e90hT4exui8/iBSeTT3C4kWPsTyx48NmNB04VxOKrbK/vb7pGeSr2c+yIsJoZt3PqpOd0qBx+Z5rXYCFfN154T5XKRxKTnMnYMJYcttO46TS8zBqB9BqKmITd/NEhYVToRZYNkLXLLqDu2p7dcSowzFI0mbkoP94USOU592ipnRLywEbvmygRezWq1amjayu1yNRk7nK+0u5WkmwWJG3p6m4T3H8DOfcT2o9yzCbaKLsY5NR5ENRrON+R6qo4Bti31bcoGNUp2rv8mkAYqHuA6IL3svTEDmxcfQEsZPLupFPm5oYNLDGKITcb3y83v3eE2iGzoFNaBRMC4cRP6w1zSE9xoRwuBNDd4/v5oK2O99EUOM/BnqhjnU70FfmA1xozo3//Q36umcghy+x9sXELvjX3gOW6EPmQBtxto4KNbxdhy+tU26BykBsqnVNm/b6ZqV7cqwGfgrgyFPPMYNNlIFNaP+CpSyiQ4PqQAszP7MZKieC8bDjAury1gtLU2JX5EzwH4TCQZ2Bbs4JBKHugGN+pI5oFQMUwlACJwWvIAf0qdots9GEDqDh0Q0bgCX7J2AFiYG+MQ/zqZNgN6grXY2UCJ37dNOCzV6pK+5073+POfBs6UPF1/ffgUw1yp2S1c0PM+ZoQDmDoiSbjnv3+haJ1ma/RKNajqRpXv/Lw+rd0zJ+KRn0IJPqPc1/9slHeDj4EDH6OeK7o/5B/XicthcsON4g0KbEwWgp7cWdeeCa+xrnk8POs2hjyBVU8SpGKapdIsunQoJLEWK91c0AAecqSTsqzlEBzb2522+2mpzkcNv9iRqV3dKhGYW+SFEIMxBHkRZHuJV4m9bKoeR3NzXDMaIxb4q+YtcuwVfFTEwRjDhNqkYOKw0z8z7DlVwxPAy40KLieAIEckLM8FR3n96PMQDPnBaBe5TRDzfXx4N3VCl11FFtcBtaLfIOPzopF/ecGeND0sZCbJB1xo822faNOgTOM18SyJNZbM4Wz/lKvo34oZ7Kgu25AxVjo8ulytX55hmVFDWm3NuEkJGP43afHgZUjgYjVP8iZ+sB00YHinpFPBPv4HXaFcfLjPWxIAi0uoPKYLvFovlxYQca7sJVDqBxSMWNrPddZ9hirmZ4Q6OQPD5w+l9vkeBob5sYaftr9nE7pcn6/fNIaERq3hM3sDw4nMLJBL+As1P2HEZIJkWBt7U 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)(36860700004)(376005)(1800799015)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2024 14:35:16.6850 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b0ef63ab-8853-4624-2182-08dc742312ce 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: SJ5PEPF000001CC.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7977 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 Acked-by: Julien Grall --- v9->10: * New patch in v10. --- xen/arch/arm/vpci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index 348ba0fbc860..aaf9d9120c3d 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -41,6 +41,8 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, { struct pci_host_bridge *bridge = p; pci_sbdf_t sbdf; + const uint8_t access_size = (1 << info->dabt.size) * 8; + const uint64_t access_mask = GENMASK_ULL(access_size - 1, 0); /* data is needed to prevent a pointer cast on 32bit */ unsigned long data; @@ -48,7 +50,7 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, if ( !vpci_sbdf_from_gpa(v->domain, bridge, info->gpa, &sbdf) ) { - *r = ~0UL; + *r = access_mask; return 1; } @@ -59,7 +61,7 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, return 1; } - *r = ~0UL; + *r = access_mask; return 0; }