From patchwork Fri Apr 19 03:53:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13635646 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 06316C4345F for ; Fri, 19 Apr 2024 03:54:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.708681.1107721 (Exim 4.92) (envelope-from ) id 1rxfKa-00021h-42; Fri, 19 Apr 2024 03:54:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 708681.1107721; Fri, 19 Apr 2024 03:54: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 1rxfKa-000212-15; Fri, 19 Apr 2024 03:54:32 +0000 Received: by outflank-mailman (input) for mailman id 708681; Fri, 19 Apr 2024 03:54: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 1rxfKZ-0001xW-F3 for xen-devel@lists.xenproject.org; Fri, 19 Apr 2024 03:54:31 +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 84a366c7-fe00-11ee-b909-491648fe20b8; Fri, 19 Apr 2024 05:54:28 +0200 (CEST) Received: from CH2PR15CA0027.namprd15.prod.outlook.com (2603:10b6:610:51::37) by IA0PR12MB7697.namprd12.prod.outlook.com (2603:10b6:208:433::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.39; Fri, 19 Apr 2024 03:54:25 +0000 Received: from CH2PEPF00000148.namprd02.prod.outlook.com (2603:10b6:610:51:cafe::17) by CH2PR15CA0027.outlook.office365.com (2603:10b6:610:51::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.29 via Frontend Transport; Fri, 19 Apr 2024 03:54:25 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH2PEPF00000148.mail.protection.outlook.com (10.167.244.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7452.22 via Frontend Transport; Fri, 19 Apr 2024 03:54:24 +0000 Received: from cjq-desktop.amd.com (10.180.168.240) 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; Thu, 18 Apr 2024 22:54:20 -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: 84a366c7-fe00-11ee-b909-491648fe20b8 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=euBBfXiJ13SjbyoRcTG65bAOaVG1ZoRdvxLY3Gnoiz3gCdZYuFPaDIcPzXMqnESDkVBhUYjAJYIB2R/bDRXgMVhMy7Cy6rAbrmkvhR9tLTEdAdM7kdYnWMT4C+KLXpxPh5udtzvBfUd/xP7VdDPLOWaIKd40bigG+N5VaXxK984y0csM6m5KEhtik2olnSM+mHA1uhKYTexMTQHYloP5f5vBhDY8KR9FgTQ3f1vxfGC59LDvwCYJfVx9oKO3SzqiyolYl7weSSfXTZXjZD0nRf/Tef2eUS2USodRN01aZ/Xc0igjWemsjRFMAGPSgj2ZSx/+N74RnTFngibws38N2w== 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=Caez2gc/3ChE8xxdCxSMDIEO2s0uO1VlEDaIPNm06/A=; b=gorykBmmuroSo1zLYGCyO7YGxYoqZuhCau1bljv1NIA+NLvuv3DXVHPlaSvSCnJmVdmF72qBJAm/cUzBv1e/furONPyyC58/F97mjsznzkJzIReGrFnlN//1a5beDvbrFH0DzgGgrFy9JRBKEkqPmfw3zBeIKUZy4ouKgncW8/O4CgKdW8R31S0zxgLdOlmgEtCFtvnxfolTWtTovVv/5dy976WA75rlrpT9pHfD+raYBE1vN9zQUhrl07qEUxEFjeRy22tR7HxVzX6m8Odsu7f4V4SrcFqJicTawal2d3RiVATQc62EBhBS1oLUYz3/Xx0lMpDtrkhJu1t67yuN+Q== 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=Caez2gc/3ChE8xxdCxSMDIEO2s0uO1VlEDaIPNm06/A=; b=HVRJ1aHJn6YNd7MVNNjLiJHfiNuc9SZlKycXimNCbmIK/pGcGCBgdRcmh0npNUitDuIVB7OjrZlPT0BDATHs3mAoAHajmgPgLNYpGZozlgM7N+gS6dg0+zL8j/Jp5pwFn76JWNK6J7pGBJBclS2DHcWf2VSallnyBzyG9K6z/Xg= 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: Jiqian Chen To: CC: Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini , Anthony PERARD , "Juergen Gross" , "Daniel P . Smith" , Stewart Hildebrand , Huang Rui , Jiqian Chen , Huang Rui , Stewart Hildebrand Subject: [XEN PATCH v7 1/5] xen/vpci: Clear all vpci status of device Date: Fri, 19 Apr 2024 11:53:36 +0800 Message-ID: <20240419035340.608833-2-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240419035340.608833-1-Jiqian.Chen@amd.com> References: <20240419035340.608833-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000148:EE_|IA0PR12MB7697:EE_ X-MS-Office365-Filtering-Correlation-Id: defb5ace-d058-43ed-20a7-08dc60246741 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5tK/cDJLU96HD0aXPZscow//1pFyQNOSHHmlAMqdGM9TOGw7IsrAgvIxNlYYXqbdtQ6erPiU6gTjcpY7PrTOucnrq4RfXVlcn9cMFxDSwfzx2LB3A3OgJeJKEwcZVoEFd4IZ6vrajgzGAjlhkA3KPT++zJzTCYXwrr0m7dFOYvE5qZU5zwPy6ITUs+sxN2l9pceLeOOBaXgpbV0ubz92vniNCOKZOAjczolq/SzIG9/bmg8/CzmLfKDpkAMJZt89sCBSJY5j5hh9peXVS7DJQcU9q/FdqeT27wGwN5EkfOi8hMfo2cJE4n1YD3ZnE52SnrFdyTR1+NxiKapsQUK25QH5VLdcIcf08qu0ToAnnMEAWzO/7Cvx5IhJybm4bNj+ZBVhJ53CWvL7yogpnl+JzF1EvorRy0rUj6PotRJBuFuxOHSrQ7ph413oltJqhko5pWNSnlbSrjDr+APd01HYJMn96hEo2qeN4WeAkMauTsIFdu2Crg3KgJZYQmmWw7eFnQt7s+QduGa1wLhQ25iquDCCdhkclQzTdy0/pHllPrlSzKuC+WayBxT8FDgi7lzRQw7UCTYv6iXmggpac1aFUy6ZovQOrz0juR81FZHdb6MHXXJV9dovbtR0E/zkKKMFlicrYF1TLpQiN1kNS3QlTNYGhvCh3Gu0W1rFf/i+EGmgMyxDK8NhE6WQEHK2W8SCpw+H4S88are0a4Qqv8k0AVUFJKSnn5e17kbOVwAnL45iVuVl1dvBxS/JTViW7Nt9 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)(82310400014)(376005)(1800799015)(36860700004)(7416005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2024 03:54:24.6709 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: defb5ace-d058-43ed-20a7-08dc60246741 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: CH2PEPF00000148.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7697 When a device has been reset on dom0 side, the vpci on Xen side won't get notification, so the cached state in vpci is all out of date compare with the real device state. To solve that problem, add a new hypercall to clear all vpci device state. When the state of device is reset on dom0 side, dom0 can call this hypercall to notify vpci. Signed-off-by: Huang Rui Signed-off-by: Jiqian Chen Reviewed-by: Stewart Hildebrand Reviewed-by: Stefano Stabellini --- xen/arch/x86/hvm/hypercall.c | 1 + xen/drivers/pci/physdev.c | 36 ++++++++++++++++++++++++++++++++++++ xen/drivers/vpci/vpci.c | 10 ++++++++++ xen/include/public/physdev.h | 7 +++++++ xen/include/xen/vpci.h | 6 ++++++ 5 files changed, 60 insertions(+) diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c index 14679dd82971..56fbb69ab201 100644 --- a/xen/arch/x86/hvm/hypercall.c +++ b/xen/arch/x86/hvm/hypercall.c @@ -84,6 +84,7 @@ long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) case PHYSDEVOP_pci_mmcfg_reserved: case PHYSDEVOP_pci_device_add: case PHYSDEVOP_pci_device_remove: + case PHYSDEVOP_pci_device_state_reset: case PHYSDEVOP_dbgp_op: if ( !is_hardware_domain(currd) ) return -ENOSYS; diff --git a/xen/drivers/pci/physdev.c b/xen/drivers/pci/physdev.c index 42db3e6d133c..73dc8f058b0e 100644 --- a/xen/drivers/pci/physdev.c +++ b/xen/drivers/pci/physdev.c @@ -2,6 +2,7 @@ #include #include #include +#include #ifndef COMPAT typedef long ret_t; @@ -67,6 +68,41 @@ ret_t pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) break; } + case PHYSDEVOP_pci_device_state_reset: { + struct physdev_pci_device dev; + struct pci_dev *pdev; + pci_sbdf_t sbdf; + + if ( !is_pci_passthrough_enabled() ) + return -EOPNOTSUPP; + + ret = -EFAULT; + if ( copy_from_guest(&dev, arg, 1) != 0 ) + break; + sbdf = PCI_SBDF(dev.seg, dev.bus, dev.devfn); + + ret = xsm_resource_setup_pci(XSM_PRIV, sbdf.sbdf); + if ( ret ) + break; + + pcidevs_lock(); + pdev = pci_get_pdev(NULL, sbdf); + if ( !pdev ) + { + pcidevs_unlock(); + ret = -ENODEV; + break; + } + + write_lock(&pdev->domain->pci_lock); + ret = vpci_reset_device_state(pdev); + write_unlock(&pdev->domain->pci_lock); + pcidevs_unlock(); + if ( ret ) + printk(XENLOG_ERR "%pp: failed to reset PCI device state\n", &sbdf); + break; + } + default: ret = -ENOSYS; break; diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 97e115dc5798..424aec2d5c46 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -115,6 +115,16 @@ int vpci_assign_device(struct pci_dev *pdev) return rc; } + +int vpci_reset_device_state(struct pci_dev *pdev) +{ + ASSERT(pcidevs_locked()); + ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); + + vpci_deassign_device(pdev); + return vpci_assign_device(pdev); +} + #endif /* __XEN__ */ static int vpci_register_cmp(const struct vpci_register *r1, diff --git a/xen/include/public/physdev.h b/xen/include/public/physdev.h index f0c0d4727c0b..f5bab1f29779 100644 --- a/xen/include/public/physdev.h +++ b/xen/include/public/physdev.h @@ -296,6 +296,13 @@ DEFINE_XEN_GUEST_HANDLE(physdev_pci_device_add_t); */ #define PHYSDEVOP_prepare_msix 30 #define PHYSDEVOP_release_msix 31 +/* + * Notify the hypervisor that a PCI device has been reset, so that any + * internally cached state is regenerated. Should be called after any + * device reset performed by the hardware domain. + */ +#define PHYSDEVOP_pci_device_state_reset 32 + struct physdev_pci_device { /* IN */ uint16_t seg; diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index e89c571890b2..ea64d94e818b 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -30,6 +30,7 @@ int __must_check vpci_assign_device(struct pci_dev *pdev); /* Remove all handlers and free vpci related structures. */ void vpci_deassign_device(struct pci_dev *pdev); +int __must_check vpci_reset_device_state(struct pci_dev *pdev); /* Add/remove a register handler. */ int __must_check vpci_add_register_mask(struct vpci *vpci, @@ -266,6 +267,11 @@ static inline int vpci_assign_device(struct pci_dev *pdev) static inline void vpci_deassign_device(struct pci_dev *pdev) { } +static inline int __must_check vpci_reset_device_state(struct pci_dev *pdev) +{ + return 0; +} + static inline void vpci_dump_msi(void) { } static inline uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, From patchwork Fri Apr 19 03:53:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13635648 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 B9669C41513 for ; Fri, 19 Apr 2024 03:54:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.708682.1107732 (Exim 4.92) (envelope-from ) id 1rxfKc-0002HW-Ge; Fri, 19 Apr 2024 03:54:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 708682.1107732; Fri, 19 Apr 2024 03:54:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rxfKc-0002HD-Cl; Fri, 19 Apr 2024 03:54:34 +0000 Received: by outflank-mailman (input) for mailman id 708682; Fri, 19 Apr 2024 03:54:32 +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 1rxfKa-0001xW-PW for xen-devel@lists.xenproject.org; Fri, 19 Apr 2024 03:54:32 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20601.outbound.protection.outlook.com [2a01:111:f403:2009::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 86fada77-fe00-11ee-b909-491648fe20b8; Fri, 19 Apr 2024 05:54:32 +0200 (CEST) Received: from CH5P223CA0003.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:1f3::19) by SA1PR12MB6797.namprd12.prod.outlook.com (2603:10b6:806:259::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.37; Fri, 19 Apr 2024 03:54:29 +0000 Received: from CH2PEPF0000014A.namprd02.prod.outlook.com (2603:10b6:610:1f3:cafe::1d) by CH5P223CA0003.outlook.office365.com (2603:10b6:610:1f3::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.30 via Frontend Transport; Fri, 19 Apr 2024 03:54:28 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH2PEPF0000014A.mail.protection.outlook.com (10.167.244.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7452.22 via Frontend Transport; Fri, 19 Apr 2024 03:54:28 +0000 Received: from cjq-desktop.amd.com (10.180.168.240) 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; Thu, 18 Apr 2024 22:54:24 -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: 86fada77-fe00-11ee-b909-491648fe20b8 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pj+AfPkUWWBncosJbyimhuLLuK/Pfztvz6j79HwaLgG9OCoqZ19MQySQNhXUyu3DPgU2BPswKgW+svPv1iC9GkhNiE76mW+XEKi1jmG0mTvi4SKz/7EBXiYNRCKV7IjsYgCceLU+nuLghlTOl/7YJWDafF1mL6H59RD2w+oZAv5d0lgOyOFwUqWyWCQTzKc7pKg0+Yw/NuH78rx5IIAM9ODUBaj0aBSnu6p4sL0u+QMSKvAuh77i5X4EX0aRc8/S+tyILKg8oir7IV5NPMyuY30+bY8jfBDmM53falS+ligKAWdU+ZeiE2KK4RJLrDOe0clj5l9prCHM0dytUgkmsQ== 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=BWMKhG5lVTeKf+NSXNTQ2LT4bcOahI5fL1ibq4Lk0AQ=; b=edTiBj/Lvit3XD6tOxLu288Do9uY6sq10PosakILlmswGkE2UEQv1Bjytqnbz7H4NCkEpQKME80dAXaizQrE0J+txvjkYBBMjGAgXgE8aq1DCYj2HB/8D3wqv+4fAcQ1JHXGeV7UZejd7pjIMRvsx21HNS3WkUqIEknhT7myjKW2DKb4LfinGbBqnVhGn8EYbmOq6OOf6toMHpvCcz4sqSdsPlzX6XtZR3DbqnaO8N/CWBvjT84Uya57ZoQ/3z0bFYERwnjomybZYVtwWMBnntYofr/pwPDkilwW8wQ/gE4L7SK+9jJbD3AY/GQ6QiuTfmYa9U4jjlvgLb7AewuOsQ== 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=BWMKhG5lVTeKf+NSXNTQ2LT4bcOahI5fL1ibq4Lk0AQ=; b=Wf+LitCf2Fy48R9gVxkIH4/CgYrOss9EidCXgm2bouXjr0Qv6Maa7NmNU4UYQA5lHGls3vMLY6EnuAJAnL75r2wyAB1LrPlau5Ci/FQarGXLrtXs1N6MHnYfzTAgfYaEvNiWtA0yoI5Ajm1nahMJaWMF8kcLvdx9slXUdY/6Nbg= 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: Jiqian Chen To: CC: Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini , Anthony PERARD , "Juergen Gross" , "Daniel P . Smith" , Stewart Hildebrand , Huang Rui , Jiqian Chen , Huang Rui Subject: [XEN PATCH v7 2/5] x86/pvh: Allow (un)map_pirq when dom0 is PVH Date: Fri, 19 Apr 2024 11:53:37 +0800 Message-ID: <20240419035340.608833-3-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240419035340.608833-1-Jiqian.Chen@amd.com> References: <20240419035340.608833-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000014A:EE_|SA1PR12MB6797:EE_ X-MS-Office365-Filtering-Correlation-Id: 44055d54-b656-42a9-3868-08dc6024696d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZUuJruOBAT3DzK9xSG9b0d6lyFL/wV6b5/tLZfHez7v3RCfu4bhv9JYGg7bacrggzs5E+XlIlI7RTP0XyNSdtS/jMvRhIbc8Ht//yJg/Re7v3BQjMqqDBxg+NyFNMcrD7wzBB2FLxmNODnQabyEVZm6/6khM22t7MccXOEK5Qq8qtGW8zj37k3tDzkbP9n38ZOmuYvbhtMCQgklx1rTmi5f33B7mfTZL8bLsNrdKHMkxgalK28YJiZt4ewurzG6t0BAkouVUsdY0BiS9HnHbNsUcCrCJ249fCPCfg0nUgrLpusRLqRP0o86OaSK3e6wgBkzGQaesv5PnaRrquMALOs/VsjNod5WUbr8HQMv0hfuHuoWL6Cz/YnIxaoF24tS3XkxjiAsuessMb96bJSHpCz1DQ7ac/8unzzGO7ep+Xb3bz+nw4XfrirNPhDG+fMUxNV4KjGMx+OaCpJVr06HLx/M03hxZ9QyteSiV4izBd/zhoFfVZuxC7cJS6CBtyPSwtMdIHWdRomRdirPNJgQShd38q6hKuW2rR5dx9wdiOvB6NCRoXGNrrhBMVJH5vBRQjbiNQkFWoZ0giuN1bs1KTyHhLkwAI0lgBueDl/UPjnFfSYF9kgjloNSlp7ZRvmyKf2ZW371UCXXWCB3Yu5UyQ1P0Qz1VUGp+zoR6bv0yA+PUzN3tLf37Ue2oBzhDJ+9w6FzS2dyXkpS+A1/tKMVOBJ66BFgrTZecchDmCOS8xx0+na6IIaSysS6QvE3B+dN4G5cSbtYDihQFXxhWOk+Imc/12NB+K54CTNSMkZ8Mc+fNMzDHx5f3nVXIwqlBfqtOvk08AqXr8Rgjnbj2DWXi0xJfmKkAv+6DT+EZLIT371qEOKYzNFGfo39dFCd5mmY/PK8ZXjJQrPw+K5fFDIVhLnBVOVhMrKS8LEphoefHQIlLg6Wu622l491OFpPiq8tthhUueU8Fo43xzqU/inrJF7IAATFXtCqIJ7tOHC/iukl6g4QyIsggIkpzTGj/AW9KwJDg1ZV/WgZILWFsafFWlJLUKTjcZal57yBUOJsMNKJrcvYitq7bHemrhaRhfTxMzDN30U0sx81NFWs6npJ9Lsrkn1sePGSS5m1sSt3fzuTP8PVpzURIaMsR7cKa8gDemWmq9otOpSY/4PELLeU1CT2vKmreC4mrBhs6DAeqMmLa5P+BCZZI0uXIO1MYT7gSPnatYdPH4C9fIenfT1BCC2/EX04RWVt6VJ2bYIKISF+4H4x9TtiQtbMzRjccB/cb7/NBxZpph/L+ulQ21BK6Bh1aW29WGwcWOVINdxsxaQHNRm6qX/VHljOq/A493EzG2D1iEFwQOexasjMMUzEtVWffcb5Ja9+h4ojQQpDP5tI/v+DTsSi9xab2pq541sGr 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)(7416005)(376005)(36860700004)(1800799015)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2024 03:54:28.2997 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 44055d54-b656-42a9-3868-08dc6024696d 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: CH2PEPF0000014A.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6797 If run Xen with PVH dom0 and hvm domU, hvm will map a pirq for a passthrough device by using gsi, see xen_pt_realize->xc_physdev_map_pirq and pci_add_dm_done->xc_physdev_map_pirq. Then xc_physdev_map_pirq will call into Xen, but in hvm_physdev_op, PHYSDEVOP_map_pirq is not allowed because currd is PVH dom0 and PVH has no X86_EMU_USE_PIRQ flag, it will fail at has_pirq check. So, allow PHYSDEVOP_map_pirq when dom0 is PVH and also allow PHYSDEVOP_unmap_pirq for the failed path to unmap pirq. And add a new check to prevent self map when caller has no PIRQ flag. Signed-off-by: Huang Rui Signed-off-by: Jiqian Chen Reviewed-by: Stefano Stabellini --- xen/arch/x86/hvm/hypercall.c | 2 ++ xen/arch/x86/physdev.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c index 56fbb69ab201..d49fb8b548a3 100644 --- a/xen/arch/x86/hvm/hypercall.c +++ b/xen/arch/x86/hvm/hypercall.c @@ -74,6 +74,8 @@ long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { case PHYSDEVOP_map_pirq: case PHYSDEVOP_unmap_pirq: + break; + case PHYSDEVOP_eoi: case PHYSDEVOP_irq_status_query: case PHYSDEVOP_get_free_pirq: diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c index 7efa17cf4c1e..1367abc61e54 100644 --- a/xen/arch/x86/physdev.c +++ b/xen/arch/x86/physdev.c @@ -305,11 +305,23 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) case PHYSDEVOP_map_pirq: { physdev_map_pirq_t map; struct msi_info msi; + struct domain *d; ret = -EFAULT; if ( copy_from_guest(&map, arg, 1) != 0 ) break; + d = rcu_lock_domain_by_any_id(map.domid); + if ( d == NULL ) + return -ESRCH; + /* If it is an HVM guest, check if it has PIRQs */ + if ( !is_pv_domain(d) && !has_pirq(d) ) + { + rcu_unlock_domain(d); + return -EOPNOTSUPP; + } + rcu_unlock_domain(d); + switch ( map.type ) { case MAP_PIRQ_TYPE_MSI_SEG: @@ -343,11 +355,23 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) case PHYSDEVOP_unmap_pirq: { struct physdev_unmap_pirq unmap; + struct domain *d; ret = -EFAULT; if ( copy_from_guest(&unmap, arg, 1) != 0 ) break; + d = rcu_lock_domain_by_any_id(unmap.domid); + if ( d == NULL ) + return -ESRCH; + /* If it is an HVM guest, check if it has PIRQs */ + if ( !is_pv_domain(d) && !has_pirq(d) ) + { + rcu_unlock_domain(d); + return -EOPNOTSUPP; + } + rcu_unlock_domain(d); + ret = physdev_unmap_pirq(unmap.domid, unmap.pirq); break; } From patchwork Fri Apr 19 03:53:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13635647 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 767F7C0650F for ; Fri, 19 Apr 2024 03:54:46 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.708683.1107742 (Exim 4.92) (envelope-from ) id 1rxfKg-0002b7-Om; Fri, 19 Apr 2024 03:54:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 708683.1107742; Fri, 19 Apr 2024 03:54:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rxfKg-0002b0-Kz; Fri, 19 Apr 2024 03:54:38 +0000 Received: by outflank-mailman (input) for mailman id 708683; Fri, 19 Apr 2024 03:54:36 +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 1rxfKe-0001xW-R4 for xen-devel@lists.xenproject.org; Fri, 19 Apr 2024 03:54:36 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20601.outbound.protection.outlook.com [2a01:111:f403:200a::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 88c1043a-fe00-11ee-b909-491648fe20b8; Fri, 19 Apr 2024 05:54:36 +0200 (CEST) Received: from CH5P223CA0024.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:1f3::14) by SA0PR12MB4479.namprd12.prod.outlook.com (2603:10b6:806:95::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.43; Fri, 19 Apr 2024 03:54:32 +0000 Received: from CH2PEPF0000014A.namprd02.prod.outlook.com (2603:10b6:610:1f3:cafe::3) by CH5P223CA0024.outlook.office365.com (2603:10b6:610:1f3::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.29 via Frontend Transport; Fri, 19 Apr 2024 03:54:31 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH2PEPF0000014A.mail.protection.outlook.com (10.167.244.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7452.22 via Frontend Transport; Fri, 19 Apr 2024 03:54:31 +0000 Received: from cjq-desktop.amd.com (10.180.168.240) 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; Thu, 18 Apr 2024 22:54:28 -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: 88c1043a-fe00-11ee-b909-491648fe20b8 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ncl4CsZ+fl/HWOKsSp7YSU9XocqxKQeoOYdugeZrnJgRqHXv6/v8ApNIbCCuRE5kDS+Zj2ZRpPUDA8lqeaxWBiQMa6/BnAWsPzwGAuXtO2CFGR8A+tWEdLAnb0okeRWVRscaTzCON9k2lor8x5SP6TdOSJlng0xztbMpKyxGq5/1TnqbleXQvPzyDYhtPMxAJkccwXMG+KvswFSCFM1jQHZ3h44ovmQFID7XyOlzgB9D+AUuzy2SusGPFCnw5Z1Nwo/TfS451DLv9YHn+W4eY7ANAWJawtKALmhiFh4mh+3DqFS1/sM2iPGUzFD0mFJ4uZ7Bw6rmfQA3niS0LyIYrQ== 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=cppfuA3qPefeFbRlxjFzL7F92H5/rzEberk3T4m9jZg=; b=fpFEUKq8FBX2rq/0BUyjXDTyt7IYl2a6+4fzGhCNG17Yew2jkyZLIX3xyYQXYM1b4ct41t4tYW4ykkY8jsfk/py74T2LdwhZmHnD5ZB+gbBS1uHjMG1lEmfwn6nCdTdrsQ7YJPhSf3JM1vA6AwqHjvCtPE7/AdYAWUly3pibviazhNCLcNzt5fMDrM0rqserR1L0elVZUT/WQ9rrMldcnVWz2NtsJSeVZNVfvfwmQdPl3suemY8pmsfE080YEVlnpDxB2aMz/s4Zh8NAdPw5ielLu64Xmd5/Rh9i9fv0GQKHSUbZkzbfbjPMD3bVh/m6qTwW45WKeZh01qnSWIy28A== 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=cppfuA3qPefeFbRlxjFzL7F92H5/rzEberk3T4m9jZg=; b=eTAnLn7PmpnD1SrXaQ+WPiELOWffjGuqJgykMBTX5DdseW6FktWpv2pxeBT+xxLFAaSmWfQYrhpjHChbRizBHGNYSrS7uyseDUb5x2Z0OV2pIyywqF+R01+2ILdVHHBBIw7eHDRIKLTn9UWaF7u0sKUN6RvXTsRF+003rkgY91w= 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: Jiqian Chen To: CC: Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini , Anthony PERARD , "Juergen Gross" , "Daniel P . Smith" , Stewart Hildebrand , Huang Rui , Jiqian Chen , Huang Rui Subject: [RFC XEN PATCH v7 3/5] x86/pvh: Add PHYSDEVOP_setup_gsi for PVH dom0 Date: Fri, 19 Apr 2024 11:53:38 +0800 Message-ID: <20240419035340.608833-4-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240419035340.608833-1-Jiqian.Chen@amd.com> References: <20240419035340.608833-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000014A:EE_|SA0PR12MB4479:EE_ X-MS-Office365-Filtering-Correlation-Id: 2e8c7bec-8562-4b10-d303-08dc60246b8c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EoMBLbmlBGSW/IulxGkFxgv0C6DxTW/Dcpm+ROqQ5xie0deFe9MdEDKyi9BH40iHH2/sobbx5g2h/Dk0x6FzRMtPtg8p3enJgykxjyiAdiLmHbkkhf79pJzB8EpsHZVup+8WiEvRArRZRU43seo1WND7Zz078UFa6dex6SNfsBMaP2KEDCXknSGzMR1swN6FxbHtVCL6guSE5fK/YXv5Mvma0dHmM0pk7MSh0v9Oap+uHjtoDxTDygBpT+1FqD0rN0bRpMTJeYI0VizXvZML1w7JoQmRcoeN/Z+po4jIWeeiKdq8FjLvor0VgDXusEdyeCH3dD2SeNbEse8YjNvv0aZKLfk+01nbgK7op7wCjlicHpT50OxiU2gkEsx+zelgH0rGBZSwdAOBNFiDURwpaOYfCO3sadcCovTb0bTU6gbeD+IG1lje6wXB6NIoXi8XBUSfPzFmv2XgKZMZE5Q3Zli26Wf9/Mw+OKf8qfaKhGmp1ziUSeFQ76f3E5gDl+wu6q/b2Q3Wk7wZTg2/RWhCGC4CgxHqwKpgshlD2ZirHsww4WVqEBWG1qZFKGnQJBzAwaMwJasHmb2XfB1PKvSZxw8cn4t8IujqI9cY5SZVqbbQX5hjg9I4ibRUUqq7Rbl98HQqLk41hlTkJz7NQSIoJUy7fdydsQbCCAYZXnEJk1yflEb6gbIPsLWPwvALYq1cy+j+wy62+gfEXqcGZtyNrpdRQNxjPhzRZSOPFnG6pYdO41hyMuiVWzOpJY5Jg+Br 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)(7416005)(1800799015)(36860700004)(82310400014)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2024 03:54:31.8623 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2e8c7bec-8562-4b10-d303-08dc60246b8c 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: CH2PEPF0000014A.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4479 On PVH dom0, the gsis don't get registered, but the gsi of a passthrough device must be configured for it to be able to be mapped into a hvm domU. On Linux kernel side, it calles PHYSDEVOP_setup_gsi for passthrough devices to register gsi when dom0 is PVH. So, add PHYSDEVOP_setup_gsi for above purpose. Signed-off-by: Huang Rui Signed-off-by: Jiqian Chen --- xen/arch/x86/hvm/hypercall.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c index d49fb8b548a3..98e3c6b176ff 100644 --- a/xen/arch/x86/hvm/hypercall.c +++ b/xen/arch/x86/hvm/hypercall.c @@ -76,6 +76,11 @@ long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) case PHYSDEVOP_unmap_pirq: break; + case PHYSDEVOP_setup_gsi: + if ( !is_hardware_domain(currd) ) + return -EOPNOTSUPP; + break; + case PHYSDEVOP_eoi: case PHYSDEVOP_irq_status_query: case PHYSDEVOP_get_free_pirq: From patchwork Fri Apr 19 03:53:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13635650 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 E78FAC4345F for ; Fri, 19 Apr 2024 03:54:50 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.708684.1107752 (Exim 4.92) (envelope-from ) id 1rxfKl-0002xS-1o; Fri, 19 Apr 2024 03:54:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 708684.1107752; Fri, 19 Apr 2024 03:54: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 1rxfKk-0002xJ-Tu; Fri, 19 Apr 2024 03:54:42 +0000 Received: by outflank-mailman (input) for mailman id 708684; Fri, 19 Apr 2024 03:54:41 +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 1rxfKj-0001ls-QF for xen-devel@lists.xenproject.org; Fri, 19 Apr 2024 03:54:41 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20601.outbound.protection.outlook.com [2a01:111:f403:2416::601]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8b50d87a-fe00-11ee-94a3-07e782e9044d; Fri, 19 Apr 2024 05:54:40 +0200 (CEST) Received: from CH5P220CA0004.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:1ef::16) by DM4PR12MB6664.namprd12.prod.outlook.com (2603:10b6:8:bb::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.53; Fri, 19 Apr 2024 03:54:36 +0000 Received: from CH2PEPF00000143.namprd02.prod.outlook.com (2603:10b6:610:1ef:cafe::a5) by CH5P220CA0004.outlook.office365.com (2603:10b6:610:1ef::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.30 via Frontend Transport; Fri, 19 Apr 2024 03:54:35 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH2PEPF00000143.mail.protection.outlook.com (10.167.244.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7452.22 via Frontend Transport; Fri, 19 Apr 2024 03:54:35 +0000 Received: from cjq-desktop.amd.com (10.180.168.240) 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; Thu, 18 Apr 2024 22:54:31 -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: 8b50d87a-fe00-11ee-94a3-07e782e9044d ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UAFTr1I08cg4up1uHvs1bYXUmcOZVDsICbE43HmwT5OzTgsz3Ra04kXtQMQvNnSRiXh9uEQMHAZm8aO0gJ+YdIvvzMd0MtNlxtArt7222yUMjpK+CLGf2RJyGuocju9CjY+QV1M0rDwRn1mwJ4s29zO3CiB8+N20ozJnl/354CiexMbsOAZ6XDURC5240+3waOakXpXEMh+FGMSgve2lNACicPCu0JCTOdK+l5yZCTwZlAUMquyxmvg9uLDfbRUwPEguFjYguluoR+AJZqAGw7aFZ1+EINSdjdwix/fOj4Zyibie6G2NR3PsHGYdFl8LaR+/jBtD4xjVxNsDY1kl+Q== 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=88JcE9Ad2syAQsm9w3u6rHe4+iMIG9q0VZLeMKdweWo=; b=B0hD2qWvQTamXzWu8SxLJcH8h4n/1FvPHpBWOyptY5v2hoOlXpTIl7jaQgV40OU40eiaYUSr/gGGB6GDCI0Rp+1W2muFo62NKi+UHy7Nwe7e0jwvx43IwMSFrv8BadMr30dgVLmcxFDCFQWhJ1OrCHndnLPdGeyv/T9oWfgh0+4yc70nSju95Iq4wYOC2uOd4O7uBWNL8MXqPkaG9kVmBmmnH21ldbOSBWRkniVfSEh4LApIAGlQPyvFa34xppYdfxHZQ72rFT0sJETUE4OIX1yLnAez2SzBqe+eIojsX0cA2n+jjfcKhtgILbuKN0ivHMWxhUfcEscVdRru5znC9g== 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=88JcE9Ad2syAQsm9w3u6rHe4+iMIG9q0VZLeMKdweWo=; b=39myrN8fKW9k66S8sMxbteM2YYyUfchutdACvGlGvU4xQQ43oNSM+EPA+VpXDztlPiAyhtcIL0FgpXHuK9kUhoSoTWzj7buNLGCi5KdP9C/m5s1sNMilJqj7O62rLEDrXYz6Hkj2TQ1kU0ZVGflUKvGaRnDzOKneymlldOaJay4= 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: Jiqian Chen To: CC: Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini , Anthony PERARD , "Juergen Gross" , "Daniel P . Smith" , Stewart Hildebrand , Huang Rui , Jiqian Chen , Huang Rui Subject: [RFC XEN PATCH v7 4/5] tools: Add new function to get gsi from irq Date: Fri, 19 Apr 2024 11:53:39 +0800 Message-ID: <20240419035340.608833-5-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240419035340.608833-1-Jiqian.Chen@amd.com> References: <20240419035340.608833-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000143:EE_|DM4PR12MB6664:EE_ X-MS-Office365-Filtering-Correlation-Id: 33eeb739-1744-4e7c-c3d7-08dc60246db1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UmCgM4m0rNACDsVvP8oA0XkjJKXEOtiaSO2uF6gPf9TxuwlcE5jUcxN6ZirHIDOMH/PaVumSg+YVojKDMGJ7sj63BifBtOAgXdUOiSt8nKmMJ5ACyPWV+CtqUEUJCHo4c7Ukii2lxskpaudfsQdW0/2/sLgyMpA66Al01gkyVeCgMQ/Y7b3i1Lb4fHhaFAQtN17U6HWtscKCmFqti8EqWpSQ/WOWnCEJJ3HP+0DdT76E57Oyz/7BXTTnG5959JLVVG1ikqpkS10n8zk+gnHqYZ4uFYaFxh4J3qPT/kMEQhIG65JobXdEjyfft6aKA4GPPz3qg2B+ooMtAXR1AlRUXhEERsGZ6UkHjvuFDi4CET4wjMqGJD8vH+NAQhJlDdxIxs/iaJTgSISnaWCMnEptHWTIqpPu+VtjS8dWNXzkMeExWuhKk4l3ZuDNG6gmZ7MTNKxIhj3qY1JiTkusvTUs9WLnXRU/swttpE99/46/dl+OackhKDR7wmgHf2q/j+qF2pFDl88KwHgsA7JRc2Wke6mWjw6VxpKwN06yTHMCe4rAM0gcg6wLBP0xaHis1QJ0KctWWSGn3eckC8Js7LWt1i077pQfa1B1eoASmiOhjJ2QQaQGtbeSuMC6VoEghFJ169uHeQTtbuMZwXioCkAVnxdY0bzwI5ktIdHgFn5SMxRkxb0VJnDSO2i5RStGJtGoq9IslBYHizs5ZbxUcIsALQ2pALlxFUG/kogudJ603ZTQhGEnFPDYCl2pNLFA4Tr1/20UdXHYzK3iTvXYlz6A9iLnMgEh8wxWkwh7+nLjaQv8s5rgwiiKg8LT71ZkNsSposuwgqJ5d9+PvAQaOBY7GT0QFJGELTcQNYdGxT9aXqk1zgNndMtsFRxT4HyVoN1IO4gDLYoZxpwEzZIhHNVlZ+xKn3pJYMXrzRB5x1p96Ul/aoTC/RSrpHBEVUqT2gxmyhf54UOT6kbGWW3VcQfPWwVydBzfAoBJq3uimjbzo30FnYD4EqzoV9fig80UUgi+skP6r3UZKJUGvmKJ9S/EGI6N+eGTP84O6KifBDNVBa9IHwW8u+Jj4fRvzWqOAZKMRngfO8QyeMYttpIoDSWMeI4WBVlV2t0V5lPOsLmxiQq7k8edOCwfzcUPRofGUdbrFztJYTiTqNLiKH7YPCryDwMle4Tbb/N2DE+Fw62Tha6BScpkSUI9tFj+ST20BqxSQKU0L9vn2jmlqyOeUJ7Jdne3WWPci7ny4sr7PmzymlNgrlCbuVjCef2EF5ZBwqsEtazmzkSWc6enIiweOdCkbqIHVwZiTdY0lXB2g0A4Wc7Y0ZDtVJQh6hAP4h88FbylcWknnUYZBh9xP6oOGAnHYxnGipVNMSDBNYmLTXWnnBI= 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)(1800799015)(82310400014)(376005)(7416005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2024 03:54:35.4598 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 33eeb739-1744-4e7c-c3d7-08dc60246db1 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: CH2PEPF00000143.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6664 In PVH dom0, it uses the linux local interrupt mechanism, when it allocs irq for a gsi, it is dynamic, and follow the principle of applying first, distributing first. And irq number is alloced from small to large, but the applying gsi number is not, may gsi 38 comes before gsi 28, that causes the irq number is not equal with the gsi number. And when passthrough a device, QEMU will use its gsi number to do pirq mapping, see xen_pt_realize->xc_physdev_map_pirq, but the gsi number is got from file /sys/bus/pci/devices//irq, so it will fail when mapping. And in current codes, there is no method to translate irq to gsi for userspace. For above purpose, add new function to get that translation. And call this function before xc_physdev_(un)map_pirq Signed-off-by: Huang Rui Signed-off-by: Chen Jiqian --- tools/include/xencall.h | 2 ++ tools/include/xenctrl.h | 2 ++ tools/libs/call/core.c | 5 +++++ tools/libs/call/libxencall.map | 2 ++ tools/libs/call/linux.c | 15 +++++++++++++++ tools/libs/call/private.h | 9 +++++++++ tools/libs/ctrl/xc_physdev.c | 4 ++++ tools/libs/light/libxl_pci.c | 11 +++++++++++ 8 files changed, 50 insertions(+) diff --git a/tools/include/xencall.h b/tools/include/xencall.h index fc95ed0fe58e..962cb45e1f1b 100644 --- a/tools/include/xencall.h +++ b/tools/include/xencall.h @@ -113,6 +113,8 @@ int xencall5(xencall_handle *xcall, unsigned int op, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5); +int xen_oscall_gsi_from_irq(xencall_handle *xcall, int irq); + /* Variant(s) of the above, as needed, returning "long" instead of "int". */ long xencall2L(xencall_handle *xcall, unsigned int op, uint64_t arg1, uint64_t arg2); diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 2ef8b4e05422..2b9d55d2c6d7 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1641,6 +1641,8 @@ int xc_physdev_unmap_pirq(xc_interface *xch, uint32_t domid, int pirq); +int xc_physdev_gsi_from_irq(xc_interface *xch, int irq); + /* * LOGGING AND ERROR REPORTING */ diff --git a/tools/libs/call/core.c b/tools/libs/call/core.c index 02c4f8e1aefa..6f79f3babd19 100644 --- a/tools/libs/call/core.c +++ b/tools/libs/call/core.c @@ -173,6 +173,11 @@ int xencall5(xencall_handle *xcall, unsigned int op, return osdep_hypercall(xcall, &call); } +int xen_oscall_gsi_from_irq(xencall_handle *xcall, int irq) +{ + return osdep_oscall(xcall, irq); +} + /* * Local variables: * mode: C diff --git a/tools/libs/call/libxencall.map b/tools/libs/call/libxencall.map index d18a3174e9dc..6cde8eda05e2 100644 --- a/tools/libs/call/libxencall.map +++ b/tools/libs/call/libxencall.map @@ -10,6 +10,8 @@ VERS_1.0 { xencall4; xencall5; + xen_oscall_gsi_from_irq; + xencall_alloc_buffer; xencall_free_buffer; xencall_alloc_buffer_pages; diff --git a/tools/libs/call/linux.c b/tools/libs/call/linux.c index 6d588e6bea8f..32b60c8b403e 100644 --- a/tools/libs/call/linux.c +++ b/tools/libs/call/linux.c @@ -85,6 +85,21 @@ long osdep_hypercall(xencall_handle *xcall, privcmd_hypercall_t *hypercall) return ioctl(xcall->fd, IOCTL_PRIVCMD_HYPERCALL, hypercall); } +long osdep_oscall(xencall_handle *xcall, int irq) +{ + privcmd_gsi_from_irq_t gsi_irq = { + .irq = irq, + .gsi = -1, + }; + + if (ioctl(xcall->fd, IOCTL_PRIVCMD_GSI_FROM_IRQ, &gsi_irq)) { + PERROR("failed to get gsi from irq"); + return -1; + } + + return gsi_irq.gsi; +} + static void *alloc_pages_bufdev(xencall_handle *xcall, size_t npages) { void *p; diff --git a/tools/libs/call/private.h b/tools/libs/call/private.h index 9c3aa432efe2..2d86cfb1e099 100644 --- a/tools/libs/call/private.h +++ b/tools/libs/call/private.h @@ -57,6 +57,15 @@ int osdep_xencall_close(xencall_handle *xcall); long osdep_hypercall(xencall_handle *xcall, privcmd_hypercall_t *hypercall); +#if defined(__linux__) +long osdep_oscall(xencall_handle *xcall, int irq); +#else +static inline long osdep_oscall(xencall_handle *xcall, int irq) +{ + return -1; +} +#endif + void *osdep_alloc_pages(xencall_handle *xcall, size_t nr_pages); void osdep_free_pages(xencall_handle *xcall, void *p, size_t nr_pages); diff --git a/tools/libs/ctrl/xc_physdev.c b/tools/libs/ctrl/xc_physdev.c index 460a8e779ce8..4d3b138ebd0e 100644 --- a/tools/libs/ctrl/xc_physdev.c +++ b/tools/libs/ctrl/xc_physdev.c @@ -111,3 +111,7 @@ int xc_physdev_unmap_pirq(xc_interface *xch, return rc; } +int xc_physdev_gsi_from_irq(xc_interface *xch, int irq) +{ + return xen_oscall_gsi_from_irq(xch->xcall, irq); +} diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 96cb4da0794e..d4313e196ebd 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -1486,6 +1486,11 @@ static void pci_add_dm_done(libxl__egc *egc, goto out_no_irq; } if ((fscanf(f, "%u", &irq) == 1) && irq) { + /* if fail, keep using irq; if success, r is gsi, use gsi. */ + r = xc_physdev_gsi_from_irq(ctx->xch, irq); + if (r != -1) { + irq = r; + } r = xc_physdev_map_pirq(ctx->xch, domid, irq, &irq); if (r < 0) { LOGED(ERROR, domainid, "xc_physdev_map_pirq irq=%d (error=%d)", @@ -2174,6 +2179,7 @@ static void pci_remove_detached(libxl__egc *egc, FILE *f; uint32_t domainid = prs->domid; bool isstubdom; + int r; /* Convenience aliases */ libxl_device_pci *const pci = &prs->pci; @@ -2239,6 +2245,11 @@ skip_bar: } if ((fscanf(f, "%u", &irq) == 1) && irq) { + /* if fail, keep using irq; if success, r is gsi, use gsi. */ + r = xc_physdev_gsi_from_irq(ctx->xch, irq); + if (r != -1) { + irq = r; + } rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq); if (rc < 0) { /* From patchwork Fri Apr 19 03:53:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13635651 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 2FC39C4345F for ; Fri, 19 Apr 2024 03:54:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.708685.1107762 (Exim 4.92) (envelope-from ) id 1rxfKn-0003HI-Ff; Fri, 19 Apr 2024 03:54:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 708685.1107762; Fri, 19 Apr 2024 03:54:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rxfKn-0003H6-BJ; Fri, 19 Apr 2024 03:54:45 +0000 Received: by outflank-mailman (input) for mailman id 708685; Fri, 19 Apr 2024 03:54:44 +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 1rxfKm-0001xW-Bf for xen-devel@lists.xenproject.org; Fri, 19 Apr 2024 03:54:44 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20600.outbound.protection.outlook.com [2a01:111:f403:2009::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8dae33da-fe00-11ee-b909-491648fe20b8; Fri, 19 Apr 2024 05:54:43 +0200 (CEST) Received: from CH5P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:1ef::27) by SJ1PR12MB6241.namprd12.prod.outlook.com (2603:10b6:a03:458::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Fri, 19 Apr 2024 03:54:39 +0000 Received: from CH2PEPF00000143.namprd02.prod.outlook.com (2603:10b6:610:1ef:cafe::21) by CH5P220CA0013.outlook.office365.com (2603:10b6:610:1ef::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.30 via Frontend Transport; Fri, 19 Apr 2024 03:54:39 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH2PEPF00000143.mail.protection.outlook.com (10.167.244.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7452.22 via Frontend Transport; Fri, 19 Apr 2024 03:54:39 +0000 Received: from cjq-desktop.amd.com (10.180.168.240) 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; Thu, 18 Apr 2024 22:54:35 -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: 8dae33da-fe00-11ee-b909-491648fe20b8 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VlDsUKlKei7n//oNTPMikpBFamIJsK//ttUee/5JXckFvc1JkSusZDiAZMiazYmZ6RG0eOlkjpTkVnJHZF9lcEBLE+eUTf2OhsxYGcTNhvqGzvD8qeIR3o80ZFnN0r0VoyPg9cfsAgSJpDbsogYBEvaXyfcFUC5U3dz16/MEGb5MY339krYF/UsqLBl0ZWelTEh/lW3CLvvOQ4QrPisy3SDQM3B8+1HLdtl9SdQVyRFmNhEl1R/X8RAans85hxAGHv/3Tg49YqCb1+6IrIcSDUrw53+oLKmpzFrEOPLT0dFp7PkOtA1NgsW0iPx29nsIeaiRFpv7aDgWNP2WIDm4gw== 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=N9ITGTvJFNB2j4xLy9eNOmtDYVp8M9SoBRDzPUxldn0=; b=KFhIJzOC9BXqsX5MdrDlwoNsjM2ndYDewZojggevX0o9qXjzpengRo2+hMpXO1LVwjSzogH90cgMOftGa5vodMmO5pu5OLqh2ybxJtjMW2h0adcuQu/2xKTrPbT96N+4LUjyk3s2YyGX3o6Fm0iKahuXGSJ8lg0VVC/FXKTfsBWej0y9wspdanaY1xHtm8ghQhFRPYr5ZuP4uGTe9RDh/wuTtCNUgbuIAlAF5XCJoGLrAXBqnET+CAd9v2kIkUg1zVQU4I0JfR3Eslan7VR+ICuFhhHJYCyfJXRZd4QL3W5Lo4ac3wVyYl1ljZgprpOOcyLqdikvY8pES+K1zH8KVg== 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=N9ITGTvJFNB2j4xLy9eNOmtDYVp8M9SoBRDzPUxldn0=; b=Rk/+PewjdC9U+qd5feMoYxHUuCmAYMAeJ3w6eR7es1xcIRuBK6U/9DC6U2GiwouZWed+2hQbvS0HI1IHA2g0V/xdgJz9y0l2YBfIzXiOtUJmGF/oI5khL19jplRW2R6sNyRZiQqzc/rKQ/0i7Oq+geE6koc+WoC4n+nFB0eQuFs= 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: Jiqian Chen To: CC: Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini , Anthony PERARD , "Juergen Gross" , "Daniel P . Smith" , Stewart Hildebrand , Huang Rui , Jiqian Chen , Huang Rui Subject: [RFC XEN PATCH v7 5/5] domctl: Add XEN_DOMCTL_gsi_permission to grant gsi Date: Fri, 19 Apr 2024 11:53:40 +0800 Message-ID: <20240419035340.608833-6-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240419035340.608833-1-Jiqian.Chen@amd.com> References: <20240419035340.608833-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000143:EE_|SJ1PR12MB6241:EE_ X-MS-Office365-Filtering-Correlation-Id: 476b92d3-9f9c-45bf-4710-08dc60246fdd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yCMkr+CN+6ERLnwU+MJ7MVn2tQelGTftT31njxYLeNogkEj7wiX2uPpuuRMrbysMoyKB0GZUrj5F7rbxfN1yIzkkIwFFOR4dHNZAI0HgQ98cMt92DVNrPFfGLergtbdi6e6eeCgFjQyeIHmpYirj51+KqiKyHHeELOK3uKmF5wlqYU/g3RKVkoCjx7+NZYFh1PBk7Dbt4JTbGFOcmErnogEWHMxfZwXvnO1if2gy7KHe1zA/Q97QxD6i4kKuoxfAPjll0RvyYIxUemobIbD+FOk48oqgp/twp517jMuMUIHy/agBUOTcvSlrnco60Jo7InhnXpyoQ7vNESEAZTmmQ3LsK7tfqTMOzbDTOeDMsdaA0eTkfBAUW4ADbSWAMaFRGBGMNUXFbhNvWFv0ddjfVr6Z6SxCq4xpiBtx6weqk2mwI2ssUAu7LGv3Og5fDw+mRdmmjb+BxrBNmimxldgUpGtgIAp659MMW9jA9byhx8kO5P14uef1+JLbGHFwHHdrITjedo/+YYjEtaQzsH2p09nQh0SbY7T+qBZWIC3Veef53xpYyT9a5pbYhTBaEmwx4XVGjEuwuHw9EQlu3t3Y1Ru0PYdnwvWU+xJOzxj78JKzgwyZgarVZsMQAnWIqYNOwC5hJ2r6dKyq8C7cJOHZ1yPIOIkXlRJtzNIKsr3feJFXekrhYNOYktFiOTDcCP9G0IWJJ3dO65IPM/tpy2sTYs1pB6Pd/p4ASn3A4FQaMYt2hlFjY5sNTKz9oZgNDrLCDqbNColKk4FY0BXhufU2k5YDnTH7yWhACl+SpV+CRZOZnw1oVdnrst/gQM5Jlnkgr0SzbxErioqIEEBg85ApXb80JwD0CTOs5EB/sWDACA4Mz6KwZ+/6WRYOyqrzAniqbf+KlWwoi39XMwLBUzqd/CpAH5XA+uHabnG+nzWAP1q+lmQu4UXgL6C5yAlH6d1TbZGTBm0x1dftdZMq+sZUP96bJYQvFzkHWAzBxuf+2IN1Z59hr9hvAPbsWQSi8AAC5X/Ay4UFuuxcQmZoVEUzVlNy41k4KOHR1dOd1LmA35AD9YUpI/LcoJeAyrG9qIuzi44moNrdDVWqekWScBDCEL65Q+St5LTD+AK0LsYxMJixu9XQklhSKXryzID+KDeKQ05VJotFR4JY34ovoT2asPDWwfkNbXqO6tQ+l55CbPvz6D4C4Zj0dbANoPgjPkN7x5m/oaJOnJ4TTdUz+1S5J6HMqLqjaic4uFPg8K47azNvwv0T4bZYyxFyHYr3x1xZVrWLVY4mg+niRqLYVq/vqs1vgm3/H4531K3of8ucg9NgO2YglXYKrRD8Vu6uqyEkMEW2wQ8runz/V2lPm6kZpURCrnzk8mMqax9/XWLe0z8= 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)(82310400014)(36860700004)(7416005)(376005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2024 03:54:39.1004 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 476b92d3-9f9c-45bf-4710-08dc60246fdd 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: CH2PEPF00000143.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6241 Some type of domain don't have PIRQ, like PVH, when passthrough a device to guest on PVH dom0, callstack pci_add_dm_done->XEN_DOMCTL_irq_permission will failed at domain_pirq_to_irq. So, add a new hypercall to grant/revoke gsi permission when dom0 is not PV or dom0 has not PIRQ flag. Signed-off-by: Huang Rui Signed-off-by: Jiqian Chen --- tools/include/xenctrl.h | 5 ++++ tools/libs/ctrl/xc_domain.c | 15 ++++++++++++ tools/libs/light/libxl_pci.c | 46 ++++++++++++++++++++++++++++-------- xen/arch/x86/domctl.c | 31 ++++++++++++++++++++++++ xen/include/public/domctl.h | 9 +++++++ xen/xsm/flask/hooks.c | 1 + 6 files changed, 97 insertions(+), 10 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 2b9d55d2c6d7..adeaab93d0f7 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1382,6 +1382,11 @@ int xc_domain_irq_permission(xc_interface *xch, uint32_t pirq, bool allow_access); +int xc_domain_gsi_permission(xc_interface *xch, + uint32_t domid, + uint32_t gsi, + bool allow_access); + int xc_domain_iomem_permission(xc_interface *xch, uint32_t domid, unsigned long first_mfn, diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c index f2d9d14b4d9f..8540e84fda93 100644 --- a/tools/libs/ctrl/xc_domain.c +++ b/tools/libs/ctrl/xc_domain.c @@ -1394,6 +1394,21 @@ int xc_domain_irq_permission(xc_interface *xch, return do_domctl(xch, &domctl); } +int xc_domain_gsi_permission(xc_interface *xch, + uint32_t domid, + uint32_t gsi, + bool allow_access) +{ + struct xen_domctl domctl = { + .cmd = XEN_DOMCTL_gsi_permission, + .domain = domid, + .u.gsi_permission.gsi = gsi, + .u.gsi_permission.allow_access = allow_access, + }; + + return do_domctl(xch, &domctl); +} + int xc_domain_iomem_permission(xc_interface *xch, uint32_t domid, unsigned long first_mfn, diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index d4313e196ebd..7e82f31ffc4f 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -1421,6 +1421,8 @@ static void pci_add_dm_done(libxl__egc *egc, uint32_t flag = XEN_DOMCTL_DEV_RDM_RELAXED; uint32_t domainid = domid; bool isstubdom = libxl_is_stubdom(ctx, domid, &domainid); + int gsi; + bool is_gsi = false; /* Convenience aliases */ bool starting = pas->starting; @@ -1490,6 +1492,8 @@ static void pci_add_dm_done(libxl__egc *egc, r = xc_physdev_gsi_from_irq(ctx->xch, irq); if (r != -1) { irq = r; + gsi = r; + is_gsi = true; } r = xc_physdev_map_pirq(ctx->xch, domid, irq, &irq); if (r < 0) { @@ -1499,13 +1503,25 @@ static void pci_add_dm_done(libxl__egc *egc, rc = ERROR_FAIL; goto out; } - r = xc_domain_irq_permission(ctx->xch, domid, irq, 1); - if (r < 0) { - LOGED(ERROR, domainid, - "xc_domain_irq_permission irq=%d (error=%d)", irq, r); - fclose(f); - rc = ERROR_FAIL; - goto out; + if (is_gsi) { + r = xc_domain_gsi_permission(ctx->xch, domid, gsi, 1); + if (r < 0 && errno != -EOPNOTSUPP) { + LOGED(ERROR, domainid, + "xc_domain_gsi_permission gsi=%d (error=%d)", gsi, errno); + fclose(f); + rc = ERROR_FAIL; + goto out; + } + } + if (!is_gsi || errno == -EOPNOTSUPP) { + r = xc_domain_irq_permission(ctx->xch, domid, irq, 1); + if (r < 0) { + LOGED(ERROR, domainid, + "xc_domain_irq_permission irq=%d (error=%d)", irq, errno); + fclose(f); + rc = ERROR_FAIL; + goto out; + } } } fclose(f); @@ -2180,6 +2196,7 @@ static void pci_remove_detached(libxl__egc *egc, uint32_t domainid = prs->domid; bool isstubdom; int r; + bool is_gsi = false; /* Convenience aliases */ libxl_device_pci *const pci = &prs->pci; @@ -2249,6 +2266,7 @@ skip_bar: r = xc_physdev_gsi_from_irq(ctx->xch, irq); if (r != -1) { irq = r; + is_gsi = true; } rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq); if (rc < 0) { @@ -2260,9 +2278,17 @@ skip_bar: */ LOGED(ERROR, domid, "xc_physdev_unmap_pirq irq=%d", irq); } - rc = xc_domain_irq_permission(ctx->xch, domid, irq, 0); - if (rc < 0) { - LOGED(ERROR, domid, "xc_domain_irq_permission irq=%d", irq); + if (is_gsi) { + r = xc_domain_gsi_permission(ctx->xch, domid, irq, 0); + if (r < 0 && errno != -EOPNOTSUPP) { + LOGED(ERROR, domid, "xc_domain_gsi_permission gsi=%d", irq); + } + } + if (!is_gsi || errno == -EOPNOTSUPP) { + r = xc_domain_irq_permission(ctx->xch, domid, irq, 0); + if (r < 0) { + LOGED(ERROR, domid, "xc_domain_irq_permission irq=%d", irq); + } } } diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 9a72d57333e9..9b8a08b2a81d 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -237,6 +237,37 @@ long arch_do_domctl( break; } + case XEN_DOMCTL_gsi_permission: + { + unsigned int gsi = domctl->u.gsi_permission.gsi; + int allow = domctl->u.gsi_permission.allow_access; + + if ( is_pv_domain(current->domain) || has_pirq(current->domain) ) + { + ret = -EOPNOTSUPP; + break; + } + + if ( gsi >= nr_irqs_gsi ) + { + ret = -EINVAL; + break; + } + + if ( !irq_access_permitted(current->domain, gsi) || + xsm_irq_permission(XSM_HOOK, d, gsi, allow) ) + { + ret = -EPERM; + break; + } + + if ( allow ) + ret = irq_permit_access(d, gsi); + else + ret = irq_deny_access(d, gsi); + break; + } + case XEN_DOMCTL_getpageframeinfo3: { unsigned int num = domctl->u.getpageframeinfo3.num; diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index a33f9ec32b08..47e95f9ee824 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -447,6 +447,13 @@ struct xen_domctl_irq_permission { }; +/* XEN_DOMCTL_gsi_permission */ +struct xen_domctl_gsi_permission { + uint32_t gsi; + uint8_t allow_access; /* flag to specify enable/disable of x86 gsi access */ +}; + + /* XEN_DOMCTL_iomem_permission */ struct xen_domctl_iomem_permission { uint64_aligned_t first_mfn;/* first page (physical page number) in range */ @@ -1277,6 +1284,7 @@ struct xen_domctl { #define XEN_DOMCTL_vmtrace_op 84 #define XEN_DOMCTL_get_paging_mempool_size 85 #define XEN_DOMCTL_set_paging_mempool_size 86 +#define XEN_DOMCTL_gsi_permission 87 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1299,6 +1307,7 @@ struct xen_domctl { struct xen_domctl_setdomainhandle setdomainhandle; struct xen_domctl_setdebugging setdebugging; struct xen_domctl_irq_permission irq_permission; + struct xen_domctl_gsi_permission gsi_permission; struct xen_domctl_iomem_permission iomem_permission; struct xen_domctl_ioport_permission ioport_permission; struct xen_domctl_hypercall_init hypercall_init; diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index 78225f68c15c..376076865198 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -685,6 +685,7 @@ static int cf_check flask_domctl(struct domain *d, int cmd) case XEN_DOMCTL_shadow_op: case XEN_DOMCTL_ioport_permission: case XEN_DOMCTL_ioport_mapping: + case XEN_DOMCTL_gsi_permission: #endif #ifdef CONFIG_HAS_PASSTHROUGH /*