From patchwork Thu Mar 28 06:33:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13608028 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 6D471CD11DD for ; Thu, 28 Mar 2024 06:34:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.698787.1090914 (Exim 4.92) (envelope-from ) id 1rpjLK-0005Fu-VV; Thu, 28 Mar 2024 06:34:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 698787.1090914; Thu, 28 Mar 2024 06:34:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rpjLK-0005Fn-ST; Thu, 28 Mar 2024 06:34:30 +0000 Received: by outflank-mailman (input) for mailman id 698787; Thu, 28 Mar 2024 06:34:30 +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 1rpjLK-00050u-1K for xen-devel@lists.xenproject.org; Thu, 28 Mar 2024 06:34:30 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20600.outbound.protection.outlook.com [2a01:111:f403:2416::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 39cdb8f5-eccd-11ee-afe3-a90da7624cb6; Thu, 28 Mar 2024 07:34:29 +0100 (CET) Received: from CH0PR03CA0100.namprd03.prod.outlook.com (2603:10b6:610:cd::15) by IA1PR12MB6260.namprd12.prod.outlook.com (2603:10b6:208:3e4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Thu, 28 Mar 2024 06:34:25 +0000 Received: from CH1PEPF0000A34C.namprd04.prod.outlook.com (2603:10b6:610:cd:cafe::c0) by CH0PR03CA0100.outlook.office365.com (2603:10b6:610:cd::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.25 via Frontend Transport; Thu, 28 Mar 2024 06:34:25 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH1PEPF0000A34C.mail.protection.outlook.com (10.167.244.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Thu, 28 Mar 2024 06:34: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, 28 Mar 2024 01:34: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: 39cdb8f5-eccd-11ee-afe3-a90da7624cb6 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hgMdqZoIFyzvcLSnGCLx/7HONHgwmhpuc0sfUlgmurKsHfls3K5LgEjb4o6N3qdK6NZQW392diyllmkVuBDEZYH1OlrizMZiqM/ZU/+0gQR6c4Hf1YaVAOlbR6SAp9LGtNqmn0h313O/HNT2ATaQPT3HiDMXjeJMGjUS7n2957DV0AHiaL4lezKnnnMtQH74yD5yAub/j07wh/P8ZALWPD4AGlaunMDcxklvLaikXskBnZPe7RoZ4SxrY2yIwYdh+Fg49HpQeuEoDjEfW6uS30IstM4KkcX3ignGO7gQmM65Ju9LufHwyNNhv8xBXUr55ELpQYTaFnSpKfITdY/Yeg== 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=sGh6+DBUR12UnhAId2zcgyQdtB6rlh4Opu5QWVMJXa4=; b=TLhJQxsz2Xew5YykrCfJHyq7hBwrDuI624CTyRacovEnZp7jdE3sPXeSxIQCPO6BblErJzpIMBXyJxeDgF6/UhDBWfbnvmkZGEsRvmQk2vLVbVHaTKijNqy+ChiqsBZ23mlxL7HV14XhUqU8CFBGY52PuA2U3aKZiWvZif38xSGxj5iVJDwyv+jTAFCjMWtNeQZ07QnMovHFZ2OKLfNl5G5Q1IRoBFn52MVBJoo8aWi6RYrqtPotVgIP2VR9dk1O5movkm3ScZdSpuSJFTNtAKBaQ8O9fH7Wju9Xod+HoiuVAhMbQpNRl3QRQyWMJn0qecM+2fu10DordPSPUVb5vw== 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=sGh6+DBUR12UnhAId2zcgyQdtB6rlh4Opu5QWVMJXa4=; b=XWCFdmcuxhMUHonDFLCY2kEf877m2QJnCik/vkHVrLlJf+VTfl1nSuVUTa7qkuGd5LUTVTy7UEb2kNFbmsQENPBrIIbfIfhY4+tr3UNd9MDzNa1zvb4uyB4ZovyIpEnVfN48BuXZPeF3Js+rJxORBQ2wpUcincI1cFlhXRvnKfQ= 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 v6 1/5] xen/vpci: Clear all vpci status of device Date: Thu, 28 Mar 2024 14:33:58 +0800 Message-ID: <20240328063402.354496-2-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240328063402.354496-1-Jiqian.Chen@amd.com> References: <20240328063402.354496-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: CH1PEPF0000A34C:EE_|IA1PR12MB6260:EE_ X-MS-Office365-Filtering-Correlation-Id: 98df1f78-2d36-4327-2034-08dc4ef11c24 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +mzOqEtOKuHfgxPtFet6T7OJsUrtO7mBJrJzBKaBv6EjZojLPB//IkWq5mm++PRbnvyOTZ8SLlR8DYCIJVPAnxu04lLE6Raix/4LgtWnW11rEMG1OtMmRTtMEGGljek5XFxxs9cdUBtVCOLumx6o33HJlwHIG9nZGwFIA2AmWZqnxlAYU0MwIdGQE830EFXk5Jbfu/6Z5umW434zQtvQtzA1g82T5TORUmWJd5X10e/APv046RUpu8RX4h5DLcGERdfSmV3QCLnBdgFxe4tRLUYwLIkxEz76bepxIlV8FAyT6YeyDCXMlfAO4wu+SE3JXXCnWfYu0HtJpIkIVgWpXHYolI0NMc2nJHOME8YqGm/UNWkaV6vA+I3sUFjrokueG3e8sTySW/GGfI+vaJWnSOOL0/g9jcuLkXIJcZ3CSHgpneKSpLEuivi0yRK4q8oeMIHbh/s6BsEmSC7awF+1lUFYZ7oHE/cea5ZVDFAw1hioRXmIUxj2yn1t9xEWxohDON3sMlXQSPTs883wYxuJHvAoL42ZVhywoEbZ4sNvtTdjVNjR+zxoJrDCuFXBdlmMP96LAxaIBksRHncvwAUPTlLPxIS9XPUiqRxwuqhv0YSamaaRS+mC8reKzHwwj1H51Cr+jtWVIYlIlD31S9N6GYrJjhKwg9vbGTMOnpa79v+FrFgypVEUbs9I37IBlDYjtCFO10xWifflrzqV5NPPRtFCjb7sTrQwKgXBuwJefwyLwCqqWIgX/rLMBPwJRET+ 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)(376005)(7416005)(82310400014)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2024 06:34:24.5357 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 98df1f78-2d36-4327-2034-08dc4ef11c24 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: CH1PEPF0000A34C.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6260 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 eeb73e1aa5d0..6ad5b4d5f11f 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 260b72875ee1..310700c1e775 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -117,6 +117,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 Thu Mar 28 06:33:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13608030 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 E67B0C54E67 for ; Thu, 28 Mar 2024 06:34:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.698788.1090924 (Exim 4.92) (envelope-from ) id 1rpjLO-0005Wy-9W; Thu, 28 Mar 2024 06:34:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 698788.1090924; Thu, 28 Mar 2024 06:34: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 1rpjLO-0005Wj-6O; Thu, 28 Mar 2024 06:34:34 +0000 Received: by outflank-mailman (input) for mailman id 698788; Thu, 28 Mar 2024 06:34: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 1rpjLM-00050u-E8 for xen-devel@lists.xenproject.org; Thu, 28 Mar 2024 06:34:32 +0000 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on20600.outbound.protection.outlook.com [2a01:111:f403:2405::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3b92d407-eccd-11ee-afe3-a90da7624cb6; Thu, 28 Mar 2024 07:34:31 +0100 (CET) Received: from CH0P221CA0033.NAMP221.PROD.OUTLOOK.COM (2603:10b6:610:11d::16) by CH3PR12MB7643.namprd12.prod.outlook.com (2603:10b6:610:152::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.32; Thu, 28 Mar 2024 06:34:28 +0000 Received: from CH1PEPF0000A34B.namprd04.prod.outlook.com (2603:10b6:610:11d:cafe::7a) by CH0P221CA0033.outlook.office365.com (2603:10b6:610:11d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Thu, 28 Mar 2024 06:34:28 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH1PEPF0000A34B.mail.protection.outlook.com (10.167.244.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Thu, 28 Mar 2024 06:34: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, 28 Mar 2024 01:34: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: 3b92d407-eccd-11ee-afe3-a90da7624cb6 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SDnsY0AKH6681xE1EPsFzdjCiSH06dzGs4PjsqGDcmzV85WOc5NAfMUgV/w/xyHhjOTWo4jy6MAM2xRNdAo/ZvXDWPec2xf96uRkf4o/tM0QwXkxMJMQEPQd4yndA3qu0KPgKCDGy3nWx6dFutWLyP+QNehlZ0XWrnZPAquMt5oOolLL3qd5sPI3qBhlFnFhTRrfK6nh31RB6+wXDs9QFAhnHyDP9vr5QUfVZp8G5/xDJM9E+OPc+TJZhvcaNWKXWiF28c1kwsTbwBeNHWKqJlwHm6XfyaSwt08+uoIcTOBeWzkx6j5aHvaXYNtzI3BajV13gfGtdIcjaGU8+1PGdg== 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=QTeOXa1ofsJQ5UT1Y6+HKhMws9Udhj7EK29Ce+m9250=; b=KaAwV+R0RXIilfP4Vh9JraPN1lqiiIQ2KcrX6sF0nIH4Wo4vw4SmtfUgL7DUT/bXJHi3QTubCaUybXkH9wKBlpgeWaQw829qGdyeriRw1doF6+zP+4XAtDKJKr3Yn+dwdYEEirV/Cz3O7yBzrs8UnHeXKUQMEBDfjbDVXCZ1Dfq0ebjnt8FfmKYtruV7EeCVCfxbhUyikzVEIhbFJ8XFhSXTkq3yHZo2G0AlnGPYoStQl9PNjXkLthsX6VyBah6q6ExYgiT/+6bbquB3IVh9VM2tERweKxconn+WO/AeTo5etoMhOgnigqyzWmen0S4SiQAaOsJSROBN/IqbNZA7UA== 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=QTeOXa1ofsJQ5UT1Y6+HKhMws9Udhj7EK29Ce+m9250=; b=yyPk4irt0W9Owz9a/FOQK8d4cBc0MYy6GUHTBrVTojEOwB7oAqXkgkjrEhjSCmIjHbldk6huK/BZC90K0m+AaVLfOLwdfSgAB2J1fsNELcSsdmtjCG3NKOJJF2GyeDU5C4oaH3dw7otCZ0kEbj3kp+BS04+WI0EjTMeCjH1XVko= 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 v6 2/5] x86/pvh: Allow (un)map_pirq when dom0 is PVH Date: Thu, 28 Mar 2024 14:33:59 +0800 Message-ID: <20240328063402.354496-3-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240328063402.354496-1-Jiqian.Chen@amd.com> References: <20240328063402.354496-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: CH1PEPF0000A34B:EE_|CH3PR12MB7643:EE_ X-MS-Office365-Filtering-Correlation-Id: 50a6572a-c32c-42ba-f968-08dc4ef11e6c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: I4jGdZ8Ja8Pzf+GgJioj731p/MNNzzHTDgKIAn3rjmC/NjwEsAwbyGuwFnaWrsYfo36yDCh8HUaqlBScmMy3/T8E4hlMcaCo/xvcaQl5WFV6j6UPXpHqt/y7O/v5t+A62dLje1nVP4MAxc3IAc/rZ/MOc1Uw6lanvRc4eE5/HBhOAJBEfaXqjvviZzNAzTp1/aISfIHR26ee1WN0rmcqMcnsWEwvUJGFthYsD07Rhyg5BNC7jWVnuXMy+KcccDCXQHdnVpHvrEgWIm79xRn46NvhtTTG4CY7wJ/YmRevGHfnYb24+FKIVY2aNqGvUm3yJPgef1u4wk7smhK8dPzwXntOo5coSk1j1f4cvcX+68MR6HPUOBO6G0LqwANgoABuyTluceASkgbVlSdB9gutmyTWNwEwoI5d4j+7hkhGGZCCeOVbEsRWuNsmKqegD4zdZ98q0Ymt67dqNQg4yHlX44YCGh3JZPJ/fZgR6ucctA1FaDJpA/RV3M3ixd7Hy9mjdWOZW0AJk8MZiPHX70suNStHTsG7fd73Ea/IAP/GaZ/cDIRZBEq2E8hLmuEdulUsr3MpAOcPKFpFgGDYgEoFQ9kRRj9rH1MbqvVZy486TCRDl3WiUosy8Dy+fYKuLHxdFTzey1eLXqB0M2sOpsRYx/E3qgoo6F87Q1AXOAJsZOrfaO/WxHe4fpL3ZZUIWVixlHlJJpKDViSblFB0Bo6tlNDdCz4sWFzUbuQKOVmuB0O4MaOgjTMjJ3dXNe/qs4I7 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)(7416005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2024 06:34:28.3685 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 50a6572a-c32c-42ba-f968-08dc4ef11e6c 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: CH1PEPF0000A34B.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7643 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 6ad5b4d5f11f..493998b42ec5 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 Thu Mar 28 06:34:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13608031 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 924FBC54E64 for ; Thu, 28 Mar 2024 06:34:47 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.698789.1090934 (Exim 4.92) (envelope-from ) id 1rpjLT-0005rd-G0; Thu, 28 Mar 2024 06:34:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 698789.1090934; Thu, 28 Mar 2024 06:34:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rpjLT-0005rU-D5; Thu, 28 Mar 2024 06:34:39 +0000 Received: by outflank-mailman (input) for mailman id 698789; Thu, 28 Mar 2024 06:34:37 +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 1rpjLR-0005pJ-S1 for xen-devel@lists.xenproject.org; Thu, 28 Mar 2024 06:34:37 +0000 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on20601.outbound.protection.outlook.com [2a01:111:f403:2407::601]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 3e28000b-eccd-11ee-a1ef-f123f15fe8a2; Thu, 28 Mar 2024 07:34:36 +0100 (CET) Received: from CH2PR04CA0011.namprd04.prod.outlook.com (2603:10b6:610:52::21) by DM6PR12MB4107.namprd12.prod.outlook.com (2603:10b6:5:218::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.38; Thu, 28 Mar 2024 06:34:32 +0000 Received: from CH1PEPF0000A348.namprd04.prod.outlook.com (2603:10b6:610:52:cafe::ef) by CH2PR04CA0011.outlook.office365.com (2603:10b6:610:52::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Thu, 28 Mar 2024 06:34:32 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH1PEPF0000A348.mail.protection.outlook.com (10.167.244.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Thu, 28 Mar 2024 06:34:32 +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, 28 Mar 2024 01:34: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: 3e28000b-eccd-11ee-a1ef-f123f15fe8a2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cRD5/CNo8tEudCDKDsIuQIcWFFaQUnVDVi/iXBdPM+NWzo65vVR57KqiFEzk9Cn+b+vSXOuoWjp0H/xw7BdWuRC1OMKeikZ8ffYTsl99a/iTCvJ/87vDIDF+E0gxSfhUfoeCjwWIyU27Vd1M9URAsJKf6JdXVP2yUd2yc5vP9ykJmbNS81mzSpw7IpbD+iyxY/M6CFsrE4YU9ZyaqXTeOMzaedAHDsrEPHXNIHC5zDz4UQZoExkfXYgRUJ1qOsP4R0XTMHx7r12FnCAEQakgp8zomuGE1uCUy/l7m+lhrxrSSeT2eKAJxskW9ehglO1Sg1KYnckKPWjDByG2aEDlcw== 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=Be2hEGsTRGFzCRd5+cpODeHi2HnqaMir4kjvUmtAU34=; b=Ja3LQ4mG6J+ADzJ1/dZ3KQ3pmOxNBM5OjCVLdsRh83oKv5y6r6UmggAK+92a4rTu/PUD3jHWsdwTfaiZQBDAE7bHfD+nCr7hNgF9iz6bBsSQE6xUioaTYjNr1aLF5SS6mcn+K3G8GBilv6dF9D2SMXrkko1lJ0s5uQb8i3539fsAcrCEfBflvRrEo65dXZH7UkSwzyxy8Cj9R10BYANcverfoo1NdICAh+P+lvnmLN5HChhJxzGRkkXjKPWi4ZKux2lXp1CKv3X1hxJt1g4sTzRkZrQVEitWZ7e7LHnMbhhga5RLGX53l9ZopkS/5S3TtQ4I1gFIL3aJsv5IMrImNg== 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=Be2hEGsTRGFzCRd5+cpODeHi2HnqaMir4kjvUmtAU34=; b=C7KuzfIimxpNZgkJQp5NVOZvd5NeHzt6JGIJ5rpRRoO85cew8XMo4GR4ouXUiFLoSZefYMXu4rxCY1wnGJHzfBmNQ5Un7dfsDj4zpVJ9l1vMYevHorqRCXXtfNq3M+LENAt7yRR2KsRJ6qTn8MTuqQu5urweEpTHqgvAkSOdtwk= 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 v6 3/5] x86/pvh: Add PHYSDEVOP_setup_gsi for PVH dom0 Date: Thu, 28 Mar 2024 14:34:00 +0800 Message-ID: <20240328063402.354496-4-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240328063402.354496-1-Jiqian.Chen@amd.com> References: <20240328063402.354496-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: CH1PEPF0000A348:EE_|DM6PR12MB4107:EE_ X-MS-Office365-Filtering-Correlation-Id: 10bad40a-388b-4725-e293-08dc4ef120e1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e9AShgNFlrKvWWSwwtR+kmyhcjxD0+DxjV/YFBbvoiPMzCqTxxbbj77mVG1SFirgVB6ioJ0DYHtc9DBESATxWVpep8hCMna5onDYXH7cZ3KHjyXJ5DUKVpZscJUgPhb+DrOzDVQbh8V9Ay8ywwNDzm+WgORs0cbcudC7FmPnvJ/uBbS6FGh7cDXTTPIJ0Jt0BN9R3ILBXlgcfvLDcy3ywQdbL+myoo2LugJYd8kNGHi9BU6lCjE1gA4mszX95JnnguMHD8N4dtQIJK4Y5o/WtHNrerUknBYxvxNsJKWZa6lN6y1ybuR5w+krRaJB5myO7kWlDX5Bk80JDMLmy4sJTNSWRwrb+e6OCxl7GKTdDBPast9eR1+KsXd/PNviH0VXCxrSxX3xyd44geutveCkNbPNOqdiV/dz1+oWAlbyZ72kHPAKeCrG+ZxjrBrvrhoHyiROr0Xo+tO+v8gltxe12QomQ259BUVI/1uvJaBVyovzizMMssUdbr2Ww1/jiJvCIIDhCH1j5AugxkTFgtmT23mtIl4yVr5pfQ//ztwmhOpoZns7P3VxE999WZRbQNx87jLls3gin9uijdymkQttqiSYgEun43ppHfQRXtOLStzwER2XDzFqbl86krkGTAkGCj+3zfDWalnIy7JGbr1weH8ySn2gU5wgKyFyRMl958Ri+tVpK2fxAcEtmY8i0289q8Uwc5gC9Z98N77y2IZ9cqHY6JIhrSOuJGUluEGNoxFJyNGZB1+u6tJYu0nOQW4D 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)(82310400014)(376005)(7416005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2024 06:34:32.4902 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 10bad40a-388b-4725-e293-08dc4ef120e1 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: CH1PEPF0000A348.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4107 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 493998b42ec5..7d4e41f66885 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 Thu Mar 28 06:34:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13608032 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 CF248C54E64 for ; Thu, 28 Mar 2024 06:34:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.698790.1090944 (Exim 4.92) (envelope-from ) id 1rpjLV-0006Aj-O7; Thu, 28 Mar 2024 06:34:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 698790.1090944; Thu, 28 Mar 2024 06:34:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rpjLV-0006Ac-Kp; Thu, 28 Mar 2024 06:34:41 +0000 Received: by outflank-mailman (input) for mailman id 698790; Thu, 28 Mar 2024 06:34:39 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rpjLT-00050u-MS for xen-devel@lists.xenproject.org; Thu, 28 Mar 2024 06:34:39 +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 3ffe7145-eccd-11ee-afe3-a90da7624cb6; Thu, 28 Mar 2024 07:34:39 +0100 (CET) Received: from CH0P221CA0038.NAMP221.PROD.OUTLOOK.COM (2603:10b6:610:11d::24) by PH7PR12MB7164.namprd12.prod.outlook.com (2603:10b6:510:203::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.32; Thu, 28 Mar 2024 06:34:36 +0000 Received: from CH1PEPF0000A34B.namprd04.prod.outlook.com (2603:10b6:610:11d:cafe::cf) by CH0P221CA0038.outlook.office365.com (2603:10b6:610:11d::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Thu, 28 Mar 2024 06:34:36 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH1PEPF0000A34B.mail.protection.outlook.com (10.167.244.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Thu, 28 Mar 2024 06:34:36 +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, 28 Mar 2024 01: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: 3ffe7145-eccd-11ee-afe3-a90da7624cb6 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kaVqPSsWHdUtxjhkqgN0WT+cqpQbtvozgcZ3W5daCUv5GeOyJBGT5+AF8paYADyKuxAvF7+QTIpjXF69tH5zahoM3NpQYFrm5jtzfV1v/VbP7Ngt3UAvDmHmj/eclpfNQQpPRXoMP29mqSVhr6rdwVbfn+eBHXIvb40O1aVzetg/da9VG37s2KENTL1brOWJpaQTeTA88vceMd/teqpFWYBNvC8BGu8ibI2uwMM5XlfN+65O0zr3FwuGRLkZwtHz8a8xQYc8cNLNb2e2B6+RfTx+ylGwAse7rK1FZLRRHFswfnlfGR867vCEaxKBc4UZIn+M+lckOkGEaXLqwAj3pQ== 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=/ZL0xK3Pv/stc/fF301pIcUEWskFlD6vojcmINMIZc4=; b=FGKnYxp7PH1rOHJdgYPYt9Ua+vTMfVreIKvrWsRfXNZjjM5zuLZLd+lI6mMAJoys6uCB0b8lXepGmZt2ifaz7ySk/rYhFVoRagOXWU35ofjR6F0ttqBoQ5hZHfIu8Xdo1lSrlAqjabtj2IxR1Oro+Ehag+igLwdShWaJ0zBsTzMP5ZmnNOT6K1vGhY8cNle16AuZIBhRD1TZ3pTzT9QcCN7OfWCSph2vDKRGgUMCEiKiMy042bv0Db6Z7BZH8iOAC+1+BWsPPaktDPCxZzsJhvmnpMHe0ALI9ldGrBUPKTJjfUBWge9QYHJhh9JSWmQx49D5RxeIfgOpOpqtg1skPA== 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=/ZL0xK3Pv/stc/fF301pIcUEWskFlD6vojcmINMIZc4=; b=1QiEkZKnWr61YZ/sQ/EZ8mq1Kp2Hlj3yczVg5wEzkNAFDtzhGZ9FqwfszNI3KE48Ou7aIsXQRaxIEui58LiaN42QNMj+PWLAeMCccg9AKhNwZSY4ueUMnd+WKrF2kjkYeY9Vy3MkN/MSjLexd2hlfBdfKnmBN9ulegbx7aooK3U= 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 v6 4/5] libxl: Use gsi instead of irq for mapping pirq Date: Thu, 28 Mar 2024 14:34:01 +0800 Message-ID: <20240328063402.354496-5-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240328063402.354496-1-Jiqian.Chen@amd.com> References: <20240328063402.354496-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: CH1PEPF0000A34B:EE_|PH7PR12MB7164:EE_ X-MS-Office365-Filtering-Correlation-Id: 8504107b-0e85-4fa5-d7e6-08dc4ef122fa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wTj2gMa6OPXvnTocvYNN8u+jeyJ6TJnFca7Y/DJfyHg3gBhLJ6HtqLoXX638ekSx4EmghOEElE8yJl8WNtMseWuZTr4dy/KqmAnVk5NkVzZdgZlNrp+KZPmd8fBo5mZHs3hWQp5pUcy57insiet0cuJbpH+ee8c8eT/P2hzt2lllhRv7eTYx/6HJftasRSRJ0OzWmKkejrCCXNoP545jr6zTyx1YsGq5KRXgwfRUOMvJ+2PVei8yrWknhO+khQj++hMmq5RGvHJ4YawNHEuI7jOEJNAUbZkLeJvUwW40RmGMlRK/VQjUwDFc9QSaNC0TF/UMqt+g8Ch9LBtSeHtXbJmbAg/tM3f0QSwH79f3ccnIwhsU0d2qZxY2xJ4mpkQX5FmWk9EZ0IBzsY68IkG1eg5KaDCzXzjG598fFXreObHfjY/8FRim4MY73KdmTvqFI3KSXS9wAXZpUOziBZHUIBZakAnsqE5H8ysqxWciIhzKE6/snyLz4yU6TacXeXDCZoF8UmSo/T+0UDO/pkhSvr8naaGd/OoaZo5q9cwMUWRb9iMk4NQUTGkS2fNMhJyvl6INQLWO5So9v1lisGJfAeJ404SYqbnl3yadvASL2KVTYlTHpLa9wbJkQSkC/+lDVZ6CbaxN657DvQNVNlJzsukeT2TtfXdX9VVPo5WrUYevPsBbPrgl/w/nDcyMXLWOGWderTulT+9pLZOyN+GTjcL/lR5OtpdkkIi7YDrXYlLtxAZ/rpiJeg52IV4sDlkl 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)(36860700004)(82310400014)(7416005)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2024 06:34:36.0092 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8504107b-0e85-4fa5-d7e6-08dc4ef122fa 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: CH1PEPF0000A34B.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7164 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 the 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, xl wants to use gsi to map pirq, see pci_add_dm_done->xc_physdev_map_pirq, but the gsi number is got from file /sys/bus/pci/devices//irq in current code, so it will fail when mapping. So, use real gsi number read from gsi sysfs. Signed-off-by: Huang Rui Signed-off-by: Jiqian Chen Reviewed-by: Stefano Stabellini --- RFC: discussions ongoing on the Linux side where/how to expose the gsi --- tools/libs/light/libxl_pci.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 96cb4da0794e..2cec83e0b734 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -1478,8 +1478,14 @@ static void pci_add_dm_done(libxl__egc *egc, fclose(f); if (!pci_supp_legacy_irq()) goto out_no_irq; - sysfs_path = GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domain, + sysfs_path = GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/gsi", pci->domain, pci->bus, pci->dev, pci->func); + r = access(sysfs_path, F_OK); + if (r && errno == ENOENT) { + /* To compitable with old version of kernel, still need to use irq */ + sysfs_path = GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domain, + pci->bus, pci->dev, pci->func); + } f = fopen(sysfs_path, "r"); if (f == NULL) { LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path); @@ -2229,9 +2235,15 @@ skip_bar: if (!pci_supp_legacy_irq()) goto skip_legacy_irq; - sysfs_path = GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domain, + sysfs_path = GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/gsi", pci->domain, pci->bus, pci->dev, pci->func); + rc = access(sysfs_path, F_OK); + if (rc && errno == ENOENT) { + /* To compitable with old version of kernel, still need to use irq */ + sysfs_path = GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domain, + pci->bus, pci->dev, pci->func); + } f = fopen(sysfs_path, "r"); if (f == NULL) { LOGED(ERROR, domid, "Couldn't open %s", sysfs_path); From patchwork Thu Mar 28 06:34:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13608033 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 13D8CC54E64 for ; Thu, 28 Mar 2024 06:34:53 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.698791.1090954 (Exim 4.92) (envelope-from ) id 1rpjLZ-0006ZA-0w; Thu, 28 Mar 2024 06:34:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 698791.1090954; Thu, 28 Mar 2024 06:34:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rpjLY-0006Z3-Th; Thu, 28 Mar 2024 06:34:44 +0000 Received: by outflank-mailman (input) for mailman id 698791; Thu, 28 Mar 2024 06:34: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 1rpjLY-00050u-9n for xen-devel@lists.xenproject.org; Thu, 28 Mar 2024 06:34:44 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20624.outbound.protection.outlook.com [2a01:111:f400:7e88::624]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 42a37dcb-eccd-11ee-afe3-a90da7624cb6; Thu, 28 Mar 2024 07:34:43 +0100 (CET) Received: from CH2PR16CA0004.namprd16.prod.outlook.com (2603:10b6:610:50::14) by LV3PR12MB9188.namprd12.prod.outlook.com (2603:10b6:408:19b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.33; Thu, 28 Mar 2024 06:34:40 +0000 Received: from CH1PEPF0000A349.namprd04.prod.outlook.com (2603:10b6:610:50:cafe::cf) by CH2PR16CA0004.outlook.office365.com (2603:10b6:610:50::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.39 via Frontend Transport; Thu, 28 Mar 2024 06:34:40 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH1PEPF0000A349.mail.protection.outlook.com (10.167.244.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Thu, 28 Mar 2024 06:34: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, 28 Mar 2024 01:34: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: 42a37dcb-eccd-11ee-afe3-a90da7624cb6 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TeB0gOXfEDmfiUZVoLSTLEiLfXliEtDMvm+BI4TMzOgR2wz/OsUhIxO3IFn7eeKgd3o8JR2CHEJUAPBIT6tqiOmW2UICJTil+lFfldZw9izf0aj3XsmfJI838f8FrP7RWrQcA4oDlPjdsLDbPpQ0j2sO9uXKKYua8iRv6fiw/x4945JNTD8Fo1sjmpk9oFsH0jvDbDkqLhVa19JaNMT9q6frU8MAtjDf/VZYPkUealvVRB5TitKB1COMcrdUEcD09A1BQZnUJLFqPVmmsoCT8aHI5FGTQ0HNAgBanvZ87TDhnRhCQ3tW4BGt3zSm62mbVngwsN/yLVRee5351IQnew== 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=AYVEVM14U5UZ2YEi1dg7K9xI2Fd7nuSqWrGJlbiocK8=; b=WNUpsOedxHeTLLGnGBop8pnvUc9PrYLtTdn5HHNeHBzqFIaw5ql/eEIb9FbSq03kj0wMZ5kbB0y+zogTFy56q9wjTgJQaqhQmmDgUTvyGN5US+fJwSmkJWReQVHPSYCEXQW8RHQB/36QQaLJ9NFm366tThGvJ5G6YT9KRNqP96/c9rsFths8hWi692z5awdAXOBvFfDKF87NkUHsJJL0gHUQ3b58lqx/9bqDzKvS1QRvkn1jDt/99jriXNawFFuu+OMUjUAiYMI91CFbJax5MI+RVnO6D+6LewHBGUfN/2925kafyn067codD45xb7cHgrqKzw3y9kUW6nE2IvTKaQ== 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=AYVEVM14U5UZ2YEi1dg7K9xI2Fd7nuSqWrGJlbiocK8=; b=FM00paNZJ1UhckIbrDM0UTNDlVZ8U1YhkeRfqJL07ZVZZ3eLI2fFliXyGyH68X9JA2imW89yV4byb/EGWjdx1944Rs6GmnLuAvBcsS/bng9sXFyb/IHWWhBSz5FleSAfItZyix23+EDDdVUraZtcCCaARbznnosXMYOjd+eV3yk= 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 v6 5/5] domctl: Add XEN_DOMCTL_gsi_permission to grant gsi Date: Thu, 28 Mar 2024 14:34:02 +0800 Message-ID: <20240328063402.354496-6-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240328063402.354496-1-Jiqian.Chen@amd.com> References: <20240328063402.354496-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: CH1PEPF0000A349:EE_|LV3PR12MB9188:EE_ X-MS-Office365-Filtering-Correlation-Id: b354861a-c49f-4c92-f056-08dc4ef1254a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IOAuaYrNBz1VtmJNNXerVNOzHHRK6fX1ObcRPA9SzfrWOH4dOf7/qqPF3r02OMa4QErozETSPhrCxNfYNJuH1lm214aX6zDqfL/Y1qpK8w+otb9eAd3DuT4cgNdTXdoSs70ov6kuwXR7XBo0bOqBA0Ka77W9636wqoV/3HM84LI0m/0ugjAz5Daz9pm4dgBm14onCR1S+fWpt7u+zPUK9ZOzS9Dhk9/bA5gsE7x82D9290yV3TqTDHkbwW9m0McfdeTgV+BryV0DEvhOMtBpAN1lGPLGnqf2wrFOHSlCjbOqviQ7emZxG2KV+2HPA4HlYMGq+S+/u1pawyKPTkY9eCcH51QVGLf31NgVaBqg3cc10YOVmpd/99AjR9TVlb+wQLs+Cc5K6t8LR0JC1/Bu71zCs6b5M7jY+JDbwLpxTkqbD4GNitiv7f8NAhgy/fxkqf2HZR4EHtgmWsW1l1y6yy1juj9jtRLQE0Xn25GOPLZW/MTLGk4UMt5NlJpzooe9bwx8zxK0sr1iQl3VX+KqbCOBlAZhgGthDKijxdkXIEQtKxIUOuB1YMVJWeX55TJsuldy3iaBjwo+xcRAE6QsD43seGdaZKqRLxght/yMfiFtUZn7jV/gloZMlqIfVJgk2xNDQV5Mq3FIoTKl4yRRwYHCU4Jw2WW1SFHQhcYQ3dGxf+mA1d9nHNrIuI7SORkf5lvHwogADtAN01BUSRKZQJNkIHNRU9caB4UHhaoXORqE3eY0nvXO6qrs4DZIXgbh 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)(1800799015)(82310400014)(376005)(7416005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2024 06:34:39.8895 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b354861a-c49f-4c92-f056-08dc4ef1254a 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: CH1PEPF0000A349.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9188 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 | 52 +++++++++++++++++++++++++++++------- xen/arch/x86/domctl.c | 31 +++++++++++++++++++++ xen/include/public/domctl.h | 9 +++++++ xen/xsm/flask/hooks.c | 1 + 6 files changed, 103 insertions(+), 10 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 2ef8b4e05422..519c860a00d5 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 2cec83e0b734..debf6ec6ddc7 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 = true; /* Convenience aliases */ bool starting = pas->starting; @@ -1485,6 +1487,7 @@ static void pci_add_dm_done(libxl__egc *egc, /* To compitable with old version of kernel, still need to use irq */ sysfs_path = GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domain, pci->bus, pci->dev, pci->func); + is_gsi = false; } f = fopen(sysfs_path, "r"); if (f == NULL) { @@ -1492,6 +1495,13 @@ static void pci_add_dm_done(libxl__egc *egc, goto out_no_irq; } if ((fscanf(f, "%u", &irq) == 1) && irq) { + /* + * If use gsi, save the value, because the value of irq + * will be changed by function xc_physdev_map_pirq + */ + if (is_gsi) { + gsi = irq; + } r = xc_physdev_map_pirq(ctx->xch, domid, irq, &irq); if (r < 0) { LOGED(ERROR, domainid, "xc_physdev_map_pirq irq=%d (error=%d)", @@ -1500,13 +1510,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 && r != -EOPNOTSUPP) { + LOGED(ERROR, domainid, + "xc_domain_gsi_permission gsi=%d (error=%d)", gsi, r); + fclose(f); + rc = ERROR_FAIL; + goto out; + } + } + if (!is_gsi || r == -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, r); + fclose(f); + rc = ERROR_FAIL; + goto out; + } } } fclose(f); @@ -2180,6 +2202,7 @@ static void pci_remove_detached(libxl__egc *egc, FILE *f; uint32_t domainid = prs->domid; bool isstubdom; + bool is_gsi = true; /* Convenience aliases */ libxl_device_pci *const pci = &prs->pci; @@ -2243,6 +2266,7 @@ skip_bar: /* To compitable with old version of kernel, still need to use irq */ sysfs_path = GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domain, pci->bus, pci->dev, pci->func); + is_gsi = false; } f = fopen(sysfs_path, "r"); if (f == NULL) { @@ -2261,9 +2285,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) { + rc = xc_domain_gsi_permission(ctx->xch, domid, irq, 0); + if (rc < 0 && rc != -EOPNOTSUPP) { + LOGED(ERROR, domid, "xc_domain_gsi_permission gsi=%d", irq); + } + } + if (!is_gsi || rc == -EOPNOTSUPP) { + rc = xc_domain_irq_permission(ctx->xch, domid, irq, 0); + if (rc < 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 /*