From patchwork Thu May 16 09:52:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13665960 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 57985C25B74 for ; Thu, 16 May 2024 09:53:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.722960.1127389 (Exim 4.92) (envelope-from ) id 1s7XnQ-0007qS-Bf; Thu, 16 May 2024 09:53:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 722960.1127389; Thu, 16 May 2024 09:53:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s7XnQ-0007qL-8s; Thu, 16 May 2024 09:53:08 +0000 Received: by outflank-mailman (input) for mailman id 722960; Thu, 16 May 2024 09:53:07 +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 1s7XnP-0007bz-5C for xen-devel@lists.xenproject.org; Thu, 16 May 2024 09:53:07 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20601.outbound.protection.outlook.com [2a01:111:f403:2415::601]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 177c4865-136a-11ef-b4bb-af5377834399; Thu, 16 May 2024 11:53:05 +0200 (CEST) Received: from PA7P264CA0360.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:37c::15) by SJ2PR12MB8882.namprd12.prod.outlook.com (2603:10b6:a03:537::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.27; Thu, 16 May 2024 09:53:02 +0000 Received: from SN1PEPF00036F42.namprd05.prod.outlook.com (2603:10a6:102:37c:cafe::f5) by PA7P264CA0360.outlook.office365.com (2603:10a6:102:37c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.28 via Frontend Transport; Thu, 16 May 2024 09:53:00 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00036F42.mail.protection.outlook.com (10.167.248.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7587.21 via Frontend Transport; Thu, 16 May 2024 09:52:59 +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, 16 May 2024 04:52:53 -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: 177c4865-136a-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PrA0excvJ2pqALielsNgWFp/2jOmQkCzIiCYFjKpwkjcgqP5H1h1JrBXBA9BOa4rOYq7NvhKmE5r539Z2bg/ByK7TntGg7/WjB5j6pcvFsj0No2LCaz2RPbO0H98VtNwziITbGIMdOPNYka1vRzdJ+iN90uN3rUq/zg53INJYV0oI3c3FQ4KoRQq4tk4j0Kk3PIpRk1mMZHA7tnUGOBfWyqQvH1Zwh8y0Dp3NuMhBtFdkAkDjyju3LIwStXfI2jV37Q6SCA7nAIPoLH5ITH7R7LWckUZlUj5noa8JVskPD/lkw7FWOGeZQN/vDC7tCUsE/bnW/rdRwLvVdJ7NSmmmg== 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=EeE3uZCJJMp49WYoeMdmwPSgIvA5T34m4ty5QgqPjT4=; b=FVLssQnpJpUCsNWsnLavxEBjiJy+/eduVP4dEYeBEkvvSjzU16az8gi1TYdWrzQ9o70is0CAOrz1i/uTb5nLl1y3GUlahIiTk4EPP1nHn2+H4wfCk+YwviBSL5RS1yobYfF98wzmiTRm+eSUcRJe2aLPnF0KI4Q/ef+IAtIcaBZ5DvjCsUNS78l0w1daux3ocdPhV0FH2ROdSXyEb17UrDC5vm7W+6WFi2PEbGiWKvpw0uAaPxJwKULGUgGouFQEXdraz87h6SFr0rXQS9OCo0KqVK7zMfWkwKLGButGMQSnLZMiP7W+iKcBsR2YndLHZugqrgVw9VyGfrCHikq/Nw== 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=EeE3uZCJJMp49WYoeMdmwPSgIvA5T34m4ty5QgqPjT4=; b=vZFOWLw95jpRblQDWifxdc/V3tJiK/RKNa9bOKLPOC3xSynMXH1oUL8sOhwA3p/MWAuJP708RFqSoFVNicyDtKKB7HXKU95CopsnD+iPCjPwtJY5+zeaHpacP1MT6ydastwh+WwXvuuW0wCUNbcQcgdKc+WeIBGguyAcnPKPHoE= 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 , "Anthony PERARD" , Juergen Gross , "Daniel P . Smith" , Stewart Hildebrand , Huang Rui , Jiqian Chen , Huang Rui , Stewart Hildebrand Subject: [XEN PATCH v8 1/5] xen/vpci: Clear all vpci status of device Date: Thu, 16 May 2024 17:52:31 +0800 Message-ID: <20240516095235.64128-2-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240516095235.64128-1-Jiqian.Chen@amd.com> References: <20240516095235.64128-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F42:EE_|SJ2PR12MB8882:EE_ X-MS-Office365-Filtering-Correlation-Id: d2294fa0-b2b6-40cb-ba57-08dc758df88e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|36860700004|1800799015|7416005|376005|82310400017; X-Microsoft-Antispam-Message-Info: aweMeH+AuoZeRE7AOJeeE25yBGx4nXT8hHQ8PX9jO5DnTSSD5zboUnRvJSiWTMoR88kh69AIHAiWFZRDmqg6D9mwNKB6XReFimdRUqsnx0JQm/JMMTwh5OhGW+SXkdos39POZvNrA8F0eBAl7j9Eh8FA3TnEUkTKOtwQ9o1n2lWhx0KhyN+ST7al16IjVOF08aLOR7YaENY7OCn6G/dOEEZrup/gcwWqTX6txETGcKE5YeZk5zaRP95VjcJVmNYFgNwFGNIjenOFjDg5u+ZoH0d7OPm5KsRjf30SK8At5Nfu+F2zhOtSfKaPGiDMXwGGhZFOHlIQ5CYdgGXB4K4MdOh6Q6dRba6fUG2et6evE47lbOuG0Z8n2mpWZl0degbInepfEVrqn+R68o15AyjGYXnKdE6LgtdB1lJ/xA3dqGQDitJRuxgVlImc09w5qehKXHdPw2iCX57gLoaIvgIRYEL0HwZHKt7r+Ofz9fo01K9DX1XbLRh7wg1hbUdTFW8MveVnCe6RGd8vFtEw4VWtmhCpng9dKn5eknYbtAZZDYo8+bszIGVW02qRCXshCMvtaZZlepFNN/J55O+MEduIrTdSXuKiSioii7DPSVMJ+o2k0RMfiGRe3KFuOiU352pblvh519ueRQAFTCnXLRUBDKRWx/0DRiiR/r5eg109SHziOZ6OCRj7atAXZJjENw8YkLZBKIKxcpqupnZEtekxcXOhobwiRgkqa+cEYfmSyVq5PqpHduI2ioTPwMcKBFs5xTY1V13k0/igFZxK6bOVttohp52UHqRPYe13RrZGwS6MpTvaS1tcmQHylMvSb1eJF6Ry5YIp6BtgHSy71qfdFZFQwWEaq52adUTmYfyh1P9LqmWQJ8oJuo7UqFo3FyvMIijl4sSsUafztb/vXoXs8I6RdDtDE1G78yM1J/x4ZAhIvAxr+2hi5sagNp3bGivgWxgBamTfuPwejI2dsEIUMnsWLCFgiENB6tqI0ZruIbbp6PPqfG0SLAcUnzDdlC+jg/BLWDfLeKaHaVF9zLGj7Ym2zB8TLvu4DUhsERYjsFYB/trnx708laGDc80c1IhEFcIhf1WyHDtY/oLYmSuUrc1/zlmXiyeu22reqnRiLFNGXsb7tiR63uC1/piueFTul3ZARgr1NjK7ODemj25b/tlr6BhVytKziOEa6+J7zPem5ljxQCee847rcsg6Kv4F4s8B2m7mtKzWbHB6/Mbz1WCRMsJhc6Xmb9rQ7j8D00HQUM3J/FjwwDWQ2xDL/VNBwvO3tM++l4ogYNo9hpViCzcynKqtA1BEqRPzkXn8GBJ8ma8wIKnC6E6+A3lrjCyWLVT8Y9g/vNq5GPJj78jYEcL8s5eMq4xJcKTWpW5WDAw2RtxSeFgEz155U/5puagN 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)(7416005)(376005)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2024 09:52:59.9928 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d2294fa0-b2b6-40cb-ba57-08dc758df88e 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: SN1PEPF00036F42.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8882 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 6e4c972f35ed..93b1c1d72c05 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 May 16 09:52:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13665962 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 876F4C25B74 for ; Thu, 16 May 2024 09:53:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.722961.1127399 (Exim 4.92) (envelope-from ) id 1s7XnY-0008Ae-P9; Thu, 16 May 2024 09:53:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 722961.1127399; Thu, 16 May 2024 09:53:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s7XnY-0008AW-Kn; Thu, 16 May 2024 09:53:16 +0000 Received: by outflank-mailman (input) for mailman id 722961; Thu, 16 May 2024 09:53:15 +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 1s7XnX-0007bz-Be for xen-devel@lists.xenproject.org; Thu, 16 May 2024 09:53:15 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20615.outbound.protection.outlook.com [2a01:111:f400:7e88::615]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1bc561bf-136a-11ef-b4bb-af5377834399; Thu, 16 May 2024 11:53:13 +0200 (CEST) Received: from PA7P264CA0355.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:37c::24) by DS0PR12MB8271.namprd12.prod.outlook.com (2603:10b6:8:fb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.28; Thu, 16 May 2024 09:53:09 +0000 Received: from SN1PEPF00036F42.namprd05.prod.outlook.com (2603:10a6:102:37c:cafe::34) by PA7P264CA0355.outlook.office365.com (2603:10a6:102:37c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.27 via Frontend Transport; Thu, 16 May 2024 09:53:07 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00036F42.mail.protection.outlook.com (10.167.248.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7587.21 via Frontend Transport; Thu, 16 May 2024 09:53:06 +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, 16 May 2024 04:52:57 -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: 1bc561bf-136a-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iAPRRoU7/BI9Gf3JPfgkdkgwy3bwou0kOM/nRVxchVReYBxKuZV+vfQvDcf1hU5YR57akyl/Iuz1EfKuKUJs+vcw25tpa/R/SkrtU1MzkTb7baH53plRocShpxTeGOgOawy0NF+vv15woPQ7ORsh4yF7vvOXJFOmO8f1BV2yWxNQJBBPpMrQYiNL/rJZEc4QiBZ2KCmRIOfonpdIZ+W5T/bPBrchBWgwJ57VnZlvdzpIwdPfpF9E0d4uEhgk+teSjwsCgzPWNukeX3L37r0irkHmfoyQhdb+ufmLM0kRNVsURMpWI3jahbcnSnO/hetqnFeeAIRLufveghBZ7PwVEg== 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=S/Ec9q5A5ur4le3zKaKlsOkcz/0csbeUoraafjUCch8=; b=Dz20fxenNZRTWAAHnTqI8/3y4Z/wKVXKJYv4QhuxgjVF52jOUeLobwSRc4CPKn402hVzUD6Xa5DOokzeAo1hM6lTQlaMMzChgD/HPbq0CHBJmgTC9zT4t0kyC6NbkEGSC1aNKJGMcfFEZ9w6Wfg11DHK+P4Es+5s+rdGscltN2+UbOXppDaxjwJt7tlf6l6iX83Q6uYNqDPPt6tZP29PXX5f7DLborndzKwjsqj6MmP/a+Cb+vJFKfVmo7KcpNsz97A6+vp6MZkoLc6JS2XTBRZybYTLB3bk6BlFOuHckZ87toZQT/SiajJgBBzFHHIwoqZpkvSIQy1X1IJtXq6z4Q== 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=S/Ec9q5A5ur4le3zKaKlsOkcz/0csbeUoraafjUCch8=; b=yBRpxeUbTxZI4eXn66FP5RuU2ZJTRdnp5rkKbeQYlCu0e7cjh49VrEtVcgwECa/iyDrnplbr0UoUzj2QwZLzwKKPln0xu6gyyO0K5rCmL5qs1Hk50bIX/Vxqk6YMlEA97eDR82U0wC5kecXgCv9qjFisx/qUXred7NYkeB+1hOM= 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 , "Anthony PERARD" , Juergen Gross , "Daniel P . Smith" , Stewart Hildebrand , Huang Rui , Jiqian Chen , Huang Rui Subject: [XEN PATCH v8 2/5] x86/pvh: Allow (un)map_pirq when dom0 is PVH Date: Thu, 16 May 2024 17:52:32 +0800 Message-ID: <20240516095235.64128-3-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240516095235.64128-1-Jiqian.Chen@amd.com> References: <20240516095235.64128-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F42:EE_|DS0PR12MB8271:EE_ X-MS-Office365-Filtering-Correlation-Id: 54ecdb5b-a85e-4e4a-c7e5-08dc758dfc88 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|1800799015|36860700004|376005|82310400017; X-Microsoft-Antispam-Message-Info: 3PDSWubrASEYM7A8ism4geb92zMjOFvEBobGcGuHDpkpg7UBAUp5bzQ1Tddu7hijW5JmvmARZkIPyEeKj6ujGrBg87v0D2IgUze9VKA7RXShlmzEhPLShTQ65e62LtZQPuKh3Dqzy1WDqJRxoPfWuzl2WspspxhZZtttXe6FD+Oj785Su5HEcPGfATvF508MQ2XwIW1b0FModtodLh3PYQIVl8YmxQ9ZKjyt9dF1h2Ajd+hZYtElcC+1DbsXmzC6+OOyVQKpis/AfCWSOzkQ6Pu328FtxDdm0YXGuU2EO4MaF08TRlrq9Wqgpq7rH4beZsaE4bB9NPu/IZOCHakBx8L893ssUqXruRv7Ad84vO+XsZTw05HbfEX2B5sh8Gla3cFqo2Gqs1JvH6731NwyUUb6rQCVKvinFGKF6ggRxsXYsYcYzoqPvVLBxqT6Y7VB0b4H1ZUBlyDC61VAgRaMczX9nFiAub2Zrr72kI9IlcYD7kEOJhPr5w7oVVfCJYdfK+fbzWeI3/lxAGQt3BvKTjcJr2+8JkNtMC/nPh9mvCxYUE1PlMdLUe/9aekl3nuBwuVhInnHn+2IPUZpgxpejacDnFtIKmeyBLxM9GbNZpUAoioHSCBrMc82ILSH+dNV83/GtVmoOq24Nz4gpLWPxz3wb0BkmaKwNBpoIMycFUd61QZJmL/7OVDrxK580iCNQUpadnkGDD38nraGADwU56HmfIZK5BIub9j7b47LuHCH+XPxnvnFxz84AZr+EFGbTzdywB75JXRw39proVguhmQr2NbuD05DGkprL7vyx29akRSsm/Rs6OdrIk4iD4lhgSL8guEMXcqo2CziGdkd050qppSQpFj8NuUPfS9QIiCvVaWAlR2053sJpTD0rrEuHYdrc1+mRi6dSyuaGASUY0yV9LL83aK9393k5iLUFf6hAuqAo88fP/9SEKFTebiDpMWjwvXUzCoewdPawkQEMtfYnOqXroZoss5pZ4NdxY776Db+Sf0B0xWCSeO4cBuKr0Cl7BCeb9Mz0o/lwszBLa0IIcoH9Ezyy+SGC0Mtpxkm/BZn7D2eqylYGPGdXw6wFqHGcv1Qo70KXAbYbHscdO51jdexPbJWyKk5rY9KdSadgkwrc6lOxjUCHK9E2XC2p9CNPhHppnC6ZqnOLBIErv8QJ1x1rZANZRp5pPm/r7vrBFJF0SMv4HI/vCbDRDgNyZz6aUDFgpvyCOILnQAe4fNOhMuuxKq/i02GIOzVmBRYrVTZUfPm7yulqycTUKJVsOqq1RLY+jHSI1I4//mkrIjv4umM8mQehMDR4CJQ7pMRDJii/NDsQjsc9D6HdI8P7cYZZVNgqWQ+GkxR/04sxdEPjzC2yFZTItcLhUHnEpwCWMGMdxB8zAyIUHNjeiJn 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)(376005)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2024 09:53:06.6803 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 54ecdb5b-a85e-4e4a-c7e5-08dc758dfc88 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: SN1PEPF00036F42.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8271 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..1337f95171cd 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 caller is the same HVM guest as current, check pirq flag */ + if ( !is_pv_domain(d) && !has_pirq(d) && map.domid == DOMID_SELF ) + { + 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 caller is the same HVM guest as current, check pirq flag */ + if ( !is_pv_domain(d) && !has_pirq(d) && unmap.domid == DOMID_SELF ) + { + rcu_unlock_domain(d); + return -EOPNOTSUPP; + } + rcu_unlock_domain(d); + ret = physdev_unmap_pirq(unmap.domid, unmap.pirq); break; } From patchwork Thu May 16 09:52:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13665964 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 7BA2BC25B74 for ; Thu, 16 May 2024 09:53:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.722963.1127419 (Exim 4.92) (envelope-from ) id 1s7Xnc-0000HQ-98; Thu, 16 May 2024 09:53:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 722963.1127419; Thu, 16 May 2024 09:53:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s7Xnc-0000HD-4s; Thu, 16 May 2024 09:53:20 +0000 Received: by outflank-mailman (input) for mailman id 722963; Thu, 16 May 2024 09:53:17 +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 1s7XnZ-0007bz-T2 for xen-devel@lists.xenproject.org; Thu, 16 May 2024 09:53:17 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20601.outbound.protection.outlook.com [2a01:111:f403:2418::601]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1d203c57-136a-11ef-b4bb-af5377834399; Thu, 16 May 2024 11:53:15 +0200 (CEST) Received: from PA7P264CA0370.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:37c::26) by PH7PR12MB6420.namprd12.prod.outlook.com (2603:10b6:510:1fc::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55; Thu, 16 May 2024 09:53:12 +0000 Received: from SN1PEPF00036F42.namprd05.prod.outlook.com (2603:10a6:102:37c:cafe::39) by PA7P264CA0370.outlook.office365.com (2603:10a6:102:37c::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.28 via Frontend Transport; Thu, 16 May 2024 09:53:11 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00036F42.mail.protection.outlook.com (10.167.248.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7587.21 via Frontend Transport; Thu, 16 May 2024 09:53:10 +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, 16 May 2024 04:53:01 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1d203c57-136a-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y1rE27mHKPAIUX1BJpa/4cvELdUqOIcj4+RK8KkrnIEyHhS92dq8wtrydkYWfKjgLRiMulJwyYEN5PkKSQHlNnrBL/yB6TwYURfuyaBraPcEGXhnASh++0hL6ds1lbOAY0D8uQ26TNXjKw64X16SDnDihY3VqCxDLMr8mg86qPfVQbMh1e7+xJVInUqXHit8SdE5BKoMcWfDkm/g1iEPUAj9Rq6Gqz0oLWZK26O/vphuFWjE381flI64HY5Ma1r1nYF56Tul57UYKDoob/cacAgHBsLGNOL1GjYqecjFXiRxPFxkRWoW7OSgDNbzL2/KbQAxkvfu5zJ/CRf5o6dkUg== 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=fcm4xvMIShHbeX96S0BHoIqkBm0YWyC8e+8Ug8tNRfBtc03MQa3Wrk2KHZVnX+kI6QoFvdqXOahE7BiLygYfz21BIq9pAM3A9XAsoao7zlMqmtS16LRKsnnf8uLVIyw/kyZTT4hZMwMeykJvORDT5kozHlcIl2S+oyVnBQ3BdWQcXON+fjhgQhDwMKFUSVKWonpXvCnVqjnHR+VAnEz2N3yWFPwJ+4/EFUo4OtpbMd7MLIdLDKfyKGnl3hnmUCq4lWCIf31fxYzQrPG7ApVv9c9bg0dbhqP6bTMd1wysdlV1DN6aBq4+dfF025GaUcjDiwyUgK3NdQco/IYjR+yJrQ== 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=xWXWI5fIIGkwBGQxGEcLOX6B7MVYi09ZSUHxS7kcOvKVHNoXIg3MqqgBvv9dfWyBmpqnCCibRdupi/djZ0jVodEW2Fuz1wiEGO3f0GwauWlilSK9Ois2zrgBtdL1tZWEwHMlzXDQDB1HShfVVLQtu+21SqeXHVKk7BwKhbYhOgU= 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 , "Anthony PERARD" , Juergen Gross , "Daniel P . Smith" , Stewart Hildebrand , Huang Rui , Jiqian Chen , Huang Rui Subject: [XEN PATCH v8 3/5] x86/pvh: Add PHYSDEVOP_setup_gsi for PVH dom0 Date: Thu, 16 May 2024 17:52:33 +0800 Message-ID: <20240516095235.64128-4-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240516095235.64128-1-Jiqian.Chen@amd.com> References: <20240516095235.64128-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F42:EE_|PH7PR12MB6420:EE_ X-MS-Office365-Filtering-Correlation-Id: 7f640649-82d3-4fd6-c0d1-08dc758dfee8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|36860700004|7416005|82310400017|1800799015; X-Microsoft-Antispam-Message-Info: 3jq60muSCtN8IshWF/GnKWzVw89ox2+Mdddu/BemG+6m1WzKWwIvquQNPp1gh/nW0U/t82uLkQcitKlATvcUX2gPHimkKFZKbKhuVfiDtZnmgclhRCmBvDF/2Xujc8IXLZZGLtUhe05XPshI7IfnfyTnyFd2oSapBJC8ujfXTDX4FtWXI2w5WC5S23fJ83ZjkwZIeQvi97lFyFDA4UGyMY17RMF49bnGkTcoXwq5CTtkrF46gdYLsZzbGgehBqb5IqJEEnyTThICO6wGojK2ye2e3c7QzaGTHQHNgiPcdmIdzO8l1S/CXqLSjj+cX2JzC8MJRzQwdBd+RgSfJ3O4GQ+lT3EhUunBWdveomRVr5JfZ+9E3ll8N6RZstFiyth81pd3B4gk34wjrYg2d3HBzYIg+1aoD8zHu1+kyICHHhh/m6MNA69lJmYkI/0rqV5A8LUDHgOfuuiGGmFOCNuenJJRPNYmDnn0fCq755yWU7VhI6jgaagtPLesaEtR4SFcN86ANPR0rjM59mlkocRj+3hzGlLBYUNZdpOvgnor6u4IyqKGKEFh1KzXBglf/eeeU6dZ2BAfRZDC5MRWTaT7FImTqn00h4ucms/gZI49nVPPiqQGqxHtsaRBmWuNl+726vTXAP/EtzZwayBvAfoc5xxcC/iNJ5saWm0eNaOxPONJyQcL0WlD89ApBzKrG1HJMHeZVcFRtmaPh5SU2PQO9RU5Rn3R040aMyhvG/2PMJZLgtwGEIjMS3l6KV/uqilqLuG0Ez+/pqP1e8U86qmp2U4e9r/QS3N6BFKd+i+xDPPyKOtgVZe9HodlaEtT+j8kDGL0pSpfXaQdvfb9UP7W9wMiKFujZ8ZsqNeMjX3J2f2rNVPDbZxS/zKd6QlPJSEoaBD5D7wzIy9W1xDAINLpSN0m3ZMNAHBG/B61ibr1n7C57wz5CAB5TlJyMbyVy03lboEo768ERjd2OlcqbKFAkx5908dMF8dGZIsn8cAs0v/cywccmrRCDQThamKMlmXBr2Cj0J+1F6gYdDaPqSno5rkVjMCp/A+EtkFGAdSDjiGz/7BZOKdwjw+rMrzFEsUz28Rw1UVZp0J5IAD/olqNGMFGAQU229a1XvBLREwE4qdjL1rCc8d/TzJ+Zyh1mdvI6gz9CrMiX6XWdG6pJDt8s3qgq7GIsj+JQ7GWUzTpnAfo2OSBAnFihhrNZBPXJF4J8Iz7hUhYyW7h9rHWSEnb0J6rzkwrl5D2esyGLuYLm++treC8MTSkY9N5MmdMXuY+PoOWtzoEoYK9RHlrtLgnB9Y/ZrSYFHQlR52GI36n+W5aIB3lpwykEtPz1u80S9kCcKpDZteOWgeKe3cLVCv2VlpH5seKbgSTdIP2Ht+Z//1yZRQIH5GaNFZR8RHfH9U0 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)(36860700004)(7416005)(82310400017)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2024 09:53:10.6647 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7f640649-82d3-4fd6-c0d1-08dc758dfee8 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: SN1PEPF00036F42.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6420 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 Thu May 16 09:52:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13665963 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 E8D47C25B79 for ; Thu, 16 May 2024 09:53:27 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.722962.1127410 (Exim 4.92) (envelope-from ) id 1s7Xnb-0008Rl-1B; Thu, 16 May 2024 09:53:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 722962.1127410; Thu, 16 May 2024 09:53:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s7Xna-0008Re-S9; Thu, 16 May 2024 09:53:18 +0000 Received: by outflank-mailman (input) for mailman id 722962; Thu, 16 May 2024 09:53:17 +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 1s7XnZ-0007bz-Iq for xen-devel@lists.xenproject.org; Thu, 16 May 2024 09:53:17 +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 1d984174-136a-11ef-b4bb-af5377834399; Thu, 16 May 2024 11:53:15 +0200 (CEST) Received: from SA1P222CA0195.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c4::8) by BL1PR12MB5873.namprd12.prod.outlook.com (2603:10b6:208:395::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.30; Thu, 16 May 2024 09:53:11 +0000 Received: from SN1PEPF00036F3E.namprd05.prod.outlook.com (2603:10b6:806:3c4:cafe::e2) by SA1P222CA0195.outlook.office365.com (2603:10b6:806:3c4::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.27 via Frontend Transport; Thu, 16 May 2024 09:53:11 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00036F3E.mail.protection.outlook.com (10.167.248.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7587.21 via Frontend Transport; Thu, 16 May 2024 09:53:10 +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, 16 May 2024 04:53:06 -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: 1d984174-136a-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CNWcmJsw83un9TlRBUhAEexfgDypF8G1MUZfJeCoP4gRVoYp7/wVacMEB5SorwT25b+OlRl1+BoXZF7JpCZfEGcjuW7ooJ3ICEd7SoXnzFMGWhE2I7l76ydjY8EDRZ/sFTiTY7Fb0l6CvDskWFRcI7VWB51Lqkv4r4HdmGB/e4xCVxbWB2A5MVuem6+Hbs0sBAuhlS2P7G5rSNIEqXtX71wYbbI7/JyJj3622W7AuQWkitDXnLrMWMiHfpD6rE4129+B+/7UGIkSIqrI/zrmubUs7tJ9sHPyc0CZGU5HicHIbIZ4ehZyWzrLo/d35CaUMBVz4Fcz4q6DSEQKHoEDaw== 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=5Ljn9VtnUEyifgNA3cosOzMocDUuiDW1at9hMSJ3P5c=; b=ZaMRj0I8SqBiB/fX2KVEtQ+JmnxhBjX4Ql4zUUvS3L37kKWrIM0ohTQYTQSOxgFrmXeRCpXUf4RwNdhnavg+pcpj5URDwwKPFnYDkjw+afNr2ANzFG2ZN0zGYYtQqfBVVYOzLDn1nTPZ89fIhb+L3rbzfd29Joi6Ysgs4baSrsSZ/OCR+t1bPMjP7nAYrgFmEw1SUku1YSA7wz6pMUHJJndczOESdjAE4DeqNQb+fj3r++sDjsSy8NOa3gFpnpAr0ZmPxLCs9xqQa3hLeHVEjEX5JinaJk8Iqb4VDJfYLK0rr+mOsrjx5SQQ2wwiqEfa28zWuhfO5/mkblqZaa3jGQ== 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=5Ljn9VtnUEyifgNA3cosOzMocDUuiDW1at9hMSJ3P5c=; b=qv0ambQ0qHDP+5KxBE/c6ZUD7Y4mdflJLkN4p8quBstHdh1c76NNPrMUOuaoz8TnOO7lTATODgT2Xh2Zh+VPnwaBWx9cE6/yT+FVVFNSPF/fRDoShPxqRxnqZ0aLCcMpWYAp/JbsqXVvzGUVq/QwzieA/J7PWu9jNLL90KiRB2M= 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 , "Anthony PERARD" , Juergen Gross , "Daniel P . Smith" , Stewart Hildebrand , Huang Rui , Jiqian Chen , Huang Rui Subject: [RFC XEN PATCH v8 4/5] tools: Add new function to get gsi from dev Date: Thu, 16 May 2024 17:52:34 +0800 Message-ID: <20240516095235.64128-5-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240516095235.64128-1-Jiqian.Chen@amd.com> References: <20240516095235.64128-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F3E:EE_|BL1PR12MB5873:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ddf47c0-3f80-49be-9d42-08dc758dff0f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|36860700004|1800799015|376005|7416005; X-Microsoft-Antispam-Message-Info: 8U0MbQPC05dg2ofgPqGVAyNxFTAehg15x6J1n1U5HjFfX+z0un4u1tNpeoXSjxboY/GgEGqVJss1DuO5VsKsP52K/eMx+lR0com+fykk5rbMZHrNgkiLYuxgrpd1ZzAvwq8qRWEji+/AZeLwWFBUCR425GLIingZ1BjD+EoQyNgTdt/uXcV9BcOWRb/q7UoxnNhEZJgK9Gq92QvPSRkggEAn2KO8T7qp7K7DzugKNFwK0QNrodAX7duhrQYyfIxxRq3YRH30RLKRIS544jMzC7afL2wg8Qvx4/YGlwpImf1zpJO3WpSsbsWFQTy3N53SJQjoWJCwVzoL6gZE7ytQhFEDMIfsxGX9exf1/kQtxNfF2nVKgjzhhhdC7qacnZvmMSh3XTvxZ7YYDw92BqF5DqPgfKr97JW7mq32optisaHfkDFsz8X6XBjZ0fICk+CeoGuXisP2hc+OJOQbn75F3+E2D9g8Rf++TqEwft9Ua0fn+GfE/xrRqmGtXFhTwXfvqALFORowGw6mSQGhQ9lXHLGlBI6bw4kXwt/njoen+TIHv/f3bKW6J3t/QzXvxgHJBu5ubqxcNdXHNN9kxf1cN4pKnJ0AIgGTnK4FpU5qyrcDaPWHHZmia6WQO2g36Bg3+qvyZOeGULkBWc2tg7oq35VA1yN946ANoE9FDQ3M/mnz6c08HY+OcMH8azAig6lisckUe6I7MSuArlPCUqU+3h9HM3TxRqw13VQpZIXAxmnW8yBV+5aPnb/1jhY5AVOYObnkSlwhPAyW8BZ1dndGjANGBMR59Oqyj/B+0qjpHns+aqho27LetEFo1ILXUt7FoQ7cGq+GK62/FtejCcoms6OkntdXyW73KJ7q70iMIaI94PAjOFdkluyZVWmqMZt1JLbmXnS0XArCGy1+d1qQEwILXp5f33MuVOz1cRs010JgYIFIJluU7TEpTs3OOeBT1XyUEX/eOkiJjuQRpedbkWnyZ7uVM36v8XLlvA8YUBOi3GZKyB8zRSowNTEJEtIUIWeyPUdvYRGJdwfDU/oCXaBLhkRyGkfS7IPtPyrlPhquqkVVQElJd7tJuJJIS2Uhp6tLLmY9rBf6sQ+TzMnW0iq+ScDD0TsyXDU79mlNQJes8t99Yc+ne04X+LbEvJaouVUqn+M2nMzia3QpxQWvBHObzLw039hs25uQGH3754tEE/ZRazxW77+I8Ntrq+3+Dq4Na4I/4+6Adnj0sGYuxMbxk2AQZFUShX/mcU3F2vGjEnCckLXefh7BD5LyXlGjrHN2Kf4WtcwRksYZTryqPs/8lFlsPxltbwGcNO7GcmnzEVM/7wrCzq+uV19YEWgm1OwP4PWuItfyiM7TodFUcdh00O2Wa1y75LAPgG+devM= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(82310400017)(36860700004)(1800799015)(376005)(7416005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2024 09:53:10.9350 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ddf47c0-3f80-49be-9d42-08dc758dff0f 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: SN1PEPF00036F3E.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5873 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 get gsi for userspace. For above purpose, add new function to get gsi. And call this function before xc_physdev_(un)map_pirq Signed-off-by: Huang Rui Signed-off-by: Chen Jiqian --- tools/include/xen-sys/Linux/privcmd.h | 7 +++++++ 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 | 23 +++++++++++++++++++++++ 9 files changed, 69 insertions(+) diff --git a/tools/include/xen-sys/Linux/privcmd.h b/tools/include/xen-sys/Linux/privcmd.h index bc60e8fd55eb..977f1a058797 100644 --- a/tools/include/xen-sys/Linux/privcmd.h +++ b/tools/include/xen-sys/Linux/privcmd.h @@ -95,6 +95,11 @@ typedef struct privcmd_mmap_resource { __u64 addr; } privcmd_mmap_resource_t; +typedef struct privcmd_gsi_from_dev { + __u32 sbdf; + int gsi; +} privcmd_gsi_from_dev_t; + /* * @cmd: IOCTL_PRIVCMD_HYPERCALL * @arg: &privcmd_hypercall_t @@ -114,6 +119,8 @@ typedef struct privcmd_mmap_resource { _IOC(_IOC_NONE, 'P', 6, sizeof(domid_t)) #define IOCTL_PRIVCMD_MMAP_RESOURCE \ _IOC(_IOC_NONE, 'P', 7, sizeof(privcmd_mmap_resource_t)) +#define IOCTL_PRIVCMD_GSI_FROM_DEV \ + _IOC(_IOC_NONE, 'P', 10, sizeof(privcmd_gsi_from_dev_t)) #define IOCTL_PRIVCMD_UNIMPLEMENTED \ _IOC(_IOC_NONE, 'P', 0xFF, 0) diff --git a/tools/include/xencall.h b/tools/include/xencall.h index fc95ed0fe58e..750aab070323 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_dev(xencall_handle *xcall, unsigned int sbdf); + /* 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 499685594427..841db41ad7e4 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_dev(xc_interface *xch, uint32_t sbdf); + /* * LOGGING AND ERROR REPORTING */ diff --git a/tools/libs/call/core.c b/tools/libs/call/core.c index 02c4f8e1aefa..6dae50c9a6ba 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_dev(xencall_handle *xcall, unsigned int sbdf) +{ + return osdep_oscall(xcall, sbdf); +} + /* * Local variables: * mode: C diff --git a/tools/libs/call/libxencall.map b/tools/libs/call/libxencall.map index d18a3174e9dc..b92a0b5dc12c 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_dev; + 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..92c740e176f2 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); } +int osdep_oscall(xencall_handle *xcall, unsigned int sbdf) +{ + privcmd_gsi_from_dev_t dev_gsi = { + .sbdf = sbdf, + .gsi = -1, + }; + + if (ioctl(xcall->fd, IOCTL_PRIVCMD_GSI_FROM_DEV, &dev_gsi)) { + PERROR("failed to get gsi from dev"); + return -1; + } + + return dev_gsi.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..cd6eb5a3e66f 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__) +int osdep_oscall(xencall_handle *xcall, unsigned int sbdf); +#else +static inline int osdep_oscall(xencall_handle *xcall, unsigned int sbdf) +{ + 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..c1458f3a38b5 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_dev(xc_interface *xch, uint32_t sbdf) +{ + return xen_oscall_gsi_from_dev(xch->xcall, sbdf); +} diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 96cb4da0794e..7e44d4c3ae2b 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -1406,6 +1406,12 @@ static bool pci_supp_legacy_irq(void) #endif } +#define PCI_DEVID(bus, devfn)\ + ((((uint16_t)(bus)) << 8) | ((devfn) & 0xff)) + +#define PCI_SBDF(seg, bus, devfn) \ + ((((uint32_t)(seg)) << 16) | (PCI_DEVID(bus, devfn))) + static void pci_add_dm_done(libxl__egc *egc, pci_add_state *pas, int rc) @@ -1418,6 +1424,7 @@ static void pci_add_dm_done(libxl__egc *egc, unsigned long long start, end, flags, size; int irq, i; int r; + uint32_t sbdf; uint32_t flag = XEN_DOMCTL_DEV_RDM_RELAXED; uint32_t domainid = domid; bool isstubdom = libxl_is_stubdom(ctx, domid, &domainid); @@ -1486,6 +1493,13 @@ static void pci_add_dm_done(libxl__egc *egc, goto out_no_irq; } if ((fscanf(f, "%u", &irq) == 1) && irq) { + sbdf = PCI_SBDF(pci->domain, pci->bus, + (PCI_DEVFN(pci->dev, pci->func))); + r = xc_physdev_gsi_from_dev(ctx->xch, sbdf); + /* if fail, keep using irq; if success, r is gsi, use gsi */ + 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)", @@ -2172,8 +2186,10 @@ static void pci_remove_detached(libxl__egc *egc, int irq = 0, i, stubdomid = 0; const char *sysfs_path; FILE *f; + uint32_t sbdf; uint32_t domainid = prs->domid; bool isstubdom; + int r; /* Convenience aliases */ libxl_device_pci *const pci = &prs->pci; @@ -2239,6 +2255,13 @@ skip_bar: } if ((fscanf(f, "%u", &irq) == 1) && irq) { + sbdf = PCI_SBDF(pci->domain, pci->bus, + (PCI_DEVFN(pci->dev, pci->func))); + r = xc_physdev_gsi_from_dev(ctx->xch, sbdf); + /* if fail, keep using irq; if success, r is gsi, use gsi */ + if (r != -1) { + irq = r; + } rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq); if (rc < 0) { /* From patchwork Thu May 16 09:52:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13665965 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 D29A8C25B79 for ; Thu, 16 May 2024 09:53:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.722964.1127429 (Exim 4.92) (envelope-from ) id 1s7Xnf-0000dg-OK; Thu, 16 May 2024 09:53:23 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 722964.1127429; Thu, 16 May 2024 09:53:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s7Xnf-0000dT-KY; Thu, 16 May 2024 09:53:23 +0000 Received: by outflank-mailman (input) for mailman id 722964; Thu, 16 May 2024 09:53:22 +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 1s7Xne-0007bz-3w for xen-devel@lists.xenproject.org; Thu, 16 May 2024 09:53:22 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20601.outbound.protection.outlook.com [2a01:111:f403:200a::601]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1fa43e0b-136a-11ef-b4bb-af5377834399; Thu, 16 May 2024 11:53:20 +0200 (CEST) Received: from PH0PR07CA0076.namprd07.prod.outlook.com (2603:10b6:510:f::21) by SA3PR12MB8438.namprd12.prod.outlook.com (2603:10b6:806:2f6::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.28; Thu, 16 May 2024 09:53:14 +0000 Received: from SN1PEPF00036F3D.namprd05.prod.outlook.com (2603:10b6:510:f:cafe::54) by PH0PR07CA0076.outlook.office365.com (2603:10b6:510:f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.30 via Frontend Transport; Thu, 16 May 2024 09:53:14 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00036F3D.mail.protection.outlook.com (10.167.248.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7587.21 via Frontend Transport; Thu, 16 May 2024 09:53:13 +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, 16 May 2024 04:53:09 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1fa43e0b-136a-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=en+yW7As1fcorNDSSKNdqp/lo4/ntiAwgEZsAEfxu0oUpnPGcGuk3Id5RiUJzn7deIGBXY/HTE+qGwWk360k8s4sawPgUgTtpaHnkwjaXp/jH13smz72YSrH6VwZWlHAEkW0qB0PJh0ugH2LTP+OoR2xzqkPVi5sB2yX9O68x3lRDerAYDBl5ULvZGexurbgFh0BXKJdD1BtWkb0GA64nRwoFh2tTU1T39AF3xePURCyPlQ9yf5Qi9uNitfZVCO2dkMLcKktXc/+GslO2xNP4JQGu3LBNtuaOeG16VJjSli7th3zVGFed2bbpy7gowTVJl1pDdQozr1CQeYC5cV0XQ== 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=+PVXKQu58hDwgfbrYDE/kcfnEXNdd+32q921wt8QLfU=; b=lHkeH8k6mbKH92U2607Xz0G2Hjm42ShQQYelsYxbjn6wCRdReEaLGMApvNtyIKo/jISMHhEtdkNOnoGrEBeEkkv/C/SaO+umcwtawEas/ssS/a9H0yWqpQL7xF26yxLcXWU4KDlzkA1d4bIS61Me3VKtUk9EkfR/rykS+sBUWwaJwWNYS4dOxxv1auaJPpWYPwcRCK7wozrY26oOev5TpXVSEUVP3TrzVTOu/B1xky3DmwnBqBjCqr1rq3PfJWwInCPQivIX4+zOQEt9hDyEWSi1MexxwvLf628As2tKU+u9FxQpK4fVzS1WMl/IIhhvUackp4A65IXP4KLhs3vbDg== 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=+PVXKQu58hDwgfbrYDE/kcfnEXNdd+32q921wt8QLfU=; b=ZaHjO+b19cD9IVru6l5lmSlLGZJ6CY/Gt/u/86G7RLUdttvyIN7pZrdKo4VMrbltn12lRAs2s3u8Hd6q1+QAqg0MkCALMXVKRS7/qy74Tms3yecnUTI+BtrkguMUArhLKMBKql2NjlgqjZltzokQHA1wT2ovTadqkYbf0MQmgGM= 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 , "Anthony PERARD" , Juergen Gross , "Daniel P . Smith" , Stewart Hildebrand , Huang Rui , Jiqian Chen , Huang Rui Subject: [RFC XEN PATCH v8 5/5] domctl: Add XEN_DOMCTL_gsi_permission to grant gsi Date: Thu, 16 May 2024 17:52:35 +0800 Message-ID: <20240516095235.64128-6-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240516095235.64128-1-Jiqian.Chen@amd.com> References: <20240516095235.64128-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F3D:EE_|SA3PR12MB8438:EE_ X-MS-Office365-Filtering-Correlation-Id: 6e1f936c-5b6c-4433-bbde-08dc758e00dd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|1800799015|7416005|36860700004|82310400017; X-Microsoft-Antispam-Message-Info: PTOxP3HXRO/oXx3ZfDWkb+W12ioUwyLKMwH2Su8T48UTKyDOU7IeoDOmesBZnAqZzMLWEx8SkewNpInH5oQhZqPyA3b/mm3LJih/oxWY1B3jHQSIqdlUIZ2pkBZfZ7+doHTtlMeKCqx3i365RjD1Po0qc/6aEd6UhwPhHeVMjHY7F3U6i1IyL+XB1PDkuwZgCaeZf3EED5DLDH+aw/xf0mC5iZEcl1cHAXrd68rRFjZ6JkX8wj3XZpWrx5Pw7P52RwerxWWP4z9p/v3ZsXwVfMdeTf6qZ8mndSF3lusvXAHaREQiqNw8DuWIZWp3XgaKMekxYp717N2XIX2QGWkcyl3vcLzK1d7050JH5MwXF+HX+Q0vwc55bDKFvwOR0N8hQcvmKizM8GT8yfui24e7j3nlaSYFl3hxeVUyqq/hA17aFCMk/HA7ux9SSNqv9nV4TAbKeb/PR19PucSaMk8UEL4VBrxM10Y1ncKzdu4Oaq51Q9jhgQyv1G/YgoDMxpiS1ICnFiR8eADetaGpA3M4u0FuG/Lxp3bOVDQPix7XrAIHkZ+y74AEYOCvaDbzqd3TYu14L1xH95VkrnzQBwWO6Nxs6PofegC99j25FoX74FsDTMDxcgZbNsKl9fPPCZcxq8wFlA4fDH5h5MP//hwQyz41K4+hkstjaLU0DQtZWyPHz7utsP6tQx6oagoIkMkR7HxqbZga2jWU6SGD6YIFGR6/xygul93PgSxbMcQvEEaZWxPEotxyY8HH6V10qSpDzixbVydLOqF+nm5lwJR3zUbb7NfcYAhLB4KtxU98L0Chn2jkFh6hmL5Eh5c6O+873NZ8NkR7N7Ki8efBSjYhSaC2L625s0blxh/wh7UWL/+umwMUWK6HL5jYIjKKIS6qi4YIqKPYgrjd0s1N3D7a6g+cwBbQNn/6mXsNGHSv4l+nZDNLxAFyDmVIdCmD0EgnCaTUYeROEw9Rjt4r1RmR5E/31pPhfaTwlLgfQjqblJvhDakXfF/ltqr7jEtjFCgBbHv8/+4AUcKLAEcSUeDiFH7K18bS8lC0dZHVWkA6sw3nEqnrF1INRPMqrbv3KWJ+8Vrq7qaU2tMUbzvhE42+u65qYukyFnfQNv/3+xWMCNt9It6vHh2+r5rjgCmD+1XhKnin7JrvBv3JhzeRrr6hHqu9n7VY6a73wW3jKzUBIUUKoLFaZbl1rZIKSZYNGB2L4TTlU5fXXYVQfyj7kVj6xhqETlk3BUotVw5cCIco99ce0hDiJqVSw1Rn18YYg0OgJ3jQV6oU0JXAVg/AzLoRHMRMCEmJXf2NyVk4+yy8ZcvSysWnQHyNTjMRvWQFT24fJ5Bqta91pktxZdUtwxCawfMNaIyhEUfEunYLerJ5kFQ= 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)(1800799015)(7416005)(36860700004)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2024 09:53:13.9480 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6e1f936c-5b6c-4433-bbde-08dc758e00dd 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: SN1PEPF00036F3D.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB8438 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 | 72 ++++++++++++++++++++++++++++-------- xen/arch/x86/domctl.c | 31 ++++++++++++++++ xen/include/public/domctl.h | 9 +++++ xen/xsm/flask/hooks.c | 1 + 6 files changed, 117 insertions(+), 16 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 841db41ad7e4..c21a79d74be3 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 7e44d4c3ae2b..1d1b81dd2844 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -1412,6 +1412,37 @@ static bool pci_supp_legacy_irq(void) #define PCI_SBDF(seg, bus, devfn) \ ((((uint32_t)(seg)) << 16) | (PCI_DEVID(bus, devfn))) +static int pci_device_set_gsi(libxl_ctx *ctx, + libxl_domid domid, + libxl_device_pci *pci, + bool map, + int *gsi_back) +{ + int r, gsi, pirq; + uint32_t sbdf; + + sbdf = PCI_SBDF(pci->domain, pci->bus, (PCI_DEVFN(pci->dev, pci->func))); + r = xc_physdev_gsi_from_dev(ctx->xch, sbdf); + *gsi_back = r; + if (r < 0) + return r; + + gsi = r; + pirq = r; + if (map) + r = xc_physdev_map_pirq(ctx->xch, domid, gsi, &pirq); + else + r = xc_physdev_unmap_pirq(ctx->xch, domid, pirq); + if (r) + return r; + + r = xc_domain_gsi_permission(ctx->xch, domid, gsi, map); + if (r && errno == EOPNOTSUPP) + r = xc_domain_irq_permission(ctx->xch, domid, gsi, map); + + return r; +} + static void pci_add_dm_done(libxl__egc *egc, pci_add_state *pas, int rc) @@ -1424,10 +1455,10 @@ static void pci_add_dm_done(libxl__egc *egc, unsigned long long start, end, flags, size; int irq, i; int r; - uint32_t sbdf; uint32_t flag = XEN_DOMCTL_DEV_RDM_RELAXED; uint32_t domainid = domid; bool isstubdom = libxl_is_stubdom(ctx, domid, &domainid); + int gsi; /* Convenience aliases */ bool starting = pas->starting; @@ -1485,6 +1516,19 @@ static void pci_add_dm_done(libxl__egc *egc, fclose(f); if (!pci_supp_legacy_irq()) goto out_no_irq; + + r = pci_device_set_gsi(ctx, domid, pci, 1, &gsi); + if (gsi >= 0) { + if (r < 0) { + rc = ERROR_FAIL; + LOGED(ERROR, domainid, + "pci_device_set_gsi gsi=%d (error=%d)", gsi, errno); + goto out; + } else { + goto process_permissive; + } + } + /* if gsi < 0, keep using irq */ sysfs_path = GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domain, pci->bus, pci->dev, pci->func); f = fopen(sysfs_path, "r"); @@ -1493,13 +1537,6 @@ static void pci_add_dm_done(libxl__egc *egc, goto out_no_irq; } if ((fscanf(f, "%u", &irq) == 1) && irq) { - sbdf = PCI_SBDF(pci->domain, pci->bus, - (PCI_DEVFN(pci->dev, pci->func))); - r = xc_physdev_gsi_from_dev(ctx->xch, sbdf); - /* if fail, keep using irq; if success, r is gsi, use gsi */ - 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)", @@ -1519,6 +1556,7 @@ static void pci_add_dm_done(libxl__egc *egc, } fclose(f); +process_permissive: /* Don't restrict writes to the PCI config space from this VM */ if (pci->permissive) { if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/permissive", @@ -2186,10 +2224,10 @@ static void pci_remove_detached(libxl__egc *egc, int irq = 0, i, stubdomid = 0; const char *sysfs_path; FILE *f; - uint32_t sbdf; uint32_t domainid = prs->domid; bool isstubdom; int r; + int gsi; /* Convenience aliases */ libxl_device_pci *const pci = &prs->pci; @@ -2245,6 +2283,15 @@ skip_bar: if (!pci_supp_legacy_irq()) goto skip_legacy_irq; + r = pci_device_set_gsi(ctx, domid, pci, 0, &gsi); + if (gsi >= 0) { + if (r < 0) { + LOGED(ERROR, domainid, + "pci_device_set_gsi gsi=%d (error=%d)", gsi, errno); + } + goto skip_legacy_irq; + } + /* if gsi < 0, keep using irq */ sysfs_path = GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domain, pci->bus, pci->dev, pci->func); @@ -2255,13 +2302,6 @@ skip_bar: } if ((fscanf(f, "%u", &irq) == 1) && irq) { - sbdf = PCI_SBDF(pci->domain, pci->bus, - (PCI_DEVFN(pci->dev, pci->func))); - r = xc_physdev_gsi_from_dev(ctx->xch, sbdf); - /* if fail, keep using irq; if success, r is gsi, use gsi */ - if (r != -1) { - irq = r; - } rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq); if (rc < 0) { /* 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 5e88c71b8e22..a5b134c91101 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 /*