From nobody Sat Nov 30 04:37:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1726133108; cv=pass; d=zohomail.com; s=zohoarc; b=VA6ES7TPT48jqJkcXMH8TlftllaAQwSTCVzPAJAGMZlE+QZOqSWNkia3K4aI25WkAuU+EFcBdv6LnZv6mh3KccsI5m6pBLJgffXnXqEGcZRoTHjgCd80sBZVruGC0iMsWVdL9LwKS8yp2aeM5dEU11+qtl7V82U9GoR8UGLGsuQ= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726133108; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=K/LBDOvtpcnz21DnY0VeKywIgWINhOaisJwaW9jtGw4=; b=JUT0WCQw2MKWy5tSdai2ukCEftByoL5JtlH88x/uYb/Ne/dfwOtem9C0QbUpRYktLrG7HyLVeoWk0Z48lVori6ICX+fuX3jSfXVaIHNAbr2VYkVv5nwbjrv5c2RyS/PXRH88ag2ssR3APC+O3Bm6inzI2cTleVqQGNpMrnghVB4= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1726133108235458.09508171414893; Thu, 12 Sep 2024 02:25:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.797106.1206929 (Exim 4.92) (envelope-from ) id 1sog40-0004xk-B2; Thu, 12 Sep 2024 09:24:32 +0000 Received: by outflank-mailman (output) from mailman id 797106.1206929; Thu, 12 Sep 2024 09:24:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sog40-0004xd-83; Thu, 12 Sep 2024 09:24:32 +0000 Received: by outflank-mailman (input) for mailman id 797106; Thu, 12 Sep 2024 09:24:29 +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 1sog3x-0004ii-TJ for xen-devel@lists.xenproject.org; Thu, 12 Sep 2024 09:24:29 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20610.outbound.protection.outlook.com [2a01:111:f403:2414::610]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cf3c3753-70e8-11ef-a0b5-8be0dac302b0; Thu, 12 Sep 2024 11:24:29 +0200 (CEST) Received: from BYAPR05CA0104.namprd05.prod.outlook.com (2603:10b6:a03:e0::45) by SA1PR12MB6947.namprd12.prod.outlook.com (2603:10b6:806:24e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.33; Thu, 12 Sep 2024 09:24:23 +0000 Received: from CO1PEPF000044F0.namprd05.prod.outlook.com (2603:10b6:a03:e0:cafe::a5) by BYAPR05CA0104.outlook.office365.com (2603:10b6:a03:e0::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24 via Frontend Transport; Thu, 12 Sep 2024 09:24:23 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000044F0.mail.protection.outlook.com (10.167.241.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Thu, 12 Sep 2024 09:24:22 +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.39; Thu, 12 Sep 2024 04:24:18 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: cf3c3753-70e8-11ef-a0b5-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IEFK4/MYIlMH1Dks/krt6KVpWrrMGH1mJPnxIWLWZ0ZU3W/kmlzsUURrvaa9LpSYF+w498cW8lEvbE7NDPRB/nPThJorTqNt0hrtzLoxmylEv2QwHmq1lMqrFcpT0FpSey+LJIO8csWVNWHilg22Il9+l6uXewlUOjOppUuEE32Vf2LAitoNtrC402xCa3EzGSARxBmEBB3mO/NQecvc16wQIbWieksd+N3fkLiWBZZGTHx5hX3M4WPeYdFwg4eVN+vTzQ8L2H2SM3E5Y6QyXNMIUUNMn/VOvw0g9D15C5BdUbfnFvYBLkNC7pgkRdZAGfiCYS+t7QQQantfuSC3dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=K/LBDOvtpcnz21DnY0VeKywIgWINhOaisJwaW9jtGw4=; b=vBAOUidjPneTj2FiCmSzwvGuoLjgFCWipI1YJhNQV/hfAtkD7V3DMuML8b69RPhR3VEhOdidCUFM04/nwr/dHry1HtUrXhiCL4Ga+vMWJNW0J39DNzNGqU7/2C2uu2/chf3al7PAFCVlH+ACrSXCWce/fRuC5X37J1cWAyBP1OCjddlP+c6hLrYl+vaFLWR5HAuLhWGJn1utwpxbUB5+SQ5/a5kIkV0iWUygroHU6W+5afRy0wmMWVydo2rAqB44sIT5nLatS0NinsGJnm75nesAEI99wtP6+x2Ii7KkzfaI1MKA3Lu+1YyOoY5g1IdmL8QKkPAttKXadgpWco2Ptw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com 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=K/LBDOvtpcnz21DnY0VeKywIgWINhOaisJwaW9jtGw4=; b=VXhxCrW5THFYFmNNr/v6U5q9Sb4BpB7DQaTC8Ch9uE69AXHhidRGPRrVLaDBahFyJnf8hjdhhOxj/G1QbtJvVJxUQoVf8J8zwPrjASMb3xGM89QobdDLgePX5z0dDUPnFIW8XdpLGtoaGYlJAgt/BLNCWRjnY8nhc1eozPLYG2E= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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: Juergen Gross , Stefano Stabellini , Bjorn Helgaas , "Rafael J . Wysocki" CC: , , , , Jiqian Chen , Huang Rui Subject: [KERNEL PATCH v9 1/3] xen/pci: Add a function to reset device for xen Date: Thu, 12 Sep 2024 17:23:49 +0800 Message-ID: <20240912092352.1602724-2-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240912092352.1602724-1-Jiqian.Chen@amd.com> References: <20240912092352.1602724-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: CO1PEPF000044F0:EE_|SA1PR12MB6947:EE_ X-MS-Office365-Filtering-Correlation-Id: 1ff64c50-b8a6-42b4-b8ae-08dcd30cb04a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?+0Q6Mxj8CLJadwy6YzjJ2CBU603BXSocKkdBsduqgSj4pSWWY34lqJajyS8U?= =?us-ascii?Q?pe/G0z66BItCIYCQvXiLz/PYbTqtH+2toN6c+UMhxnwPsfCCom+Nj8fGRXGE?= =?us-ascii?Q?pgosxU+e4LzxyJm3icBcI+HNZ1sJ4FVNgV7vJBwiHpFZcOVflS0FiztDmeXr?= =?us-ascii?Q?6MLgkAxe/CuKga46COrsxW3bLijRmFb/c/IXa27MaoAlG9DlTTbOXHyL9TkN?= =?us-ascii?Q?Xqv5Ntz/3leSmHXKQeikig7QHGoeb/HglrjdugDUlmc4g2vGoWED0FkxhEu4?= =?us-ascii?Q?tKQLKFlK8ya0hlp05oJkbq8wf1BrRYS7boYHSPcSECoStx8GV+D5Cb05DLVn?= =?us-ascii?Q?z0XBXG5UJRBKl+9MID7e2kQ9ib3Qqkp8IKGT3KHleteyKI332YgIOLfe3BaM?= =?us-ascii?Q?mNVABh82d0mLcG2EUn2EzsxIJITlEeLgb7iDJ6GZGSaeVhe7NTql0GZ1z2UX?= =?us-ascii?Q?ncrkoeUy+ymz+VzT+LNbdhSk6/VsGxTqyshe4hz6yOrqrsT0vh+Lmr5XaZjG?= =?us-ascii?Q?9ccP/cXcbadss8hOKtJ37DLeRjgob7ZH96AM+mwNrfPaYB6zq9jKJAc0inq4?= =?us-ascii?Q?34mp3K3Dm0eseJC5qWd8LSaDLUKbxhAQC4F6DsFxjzb1nmmPG3RYWpQwepdy?= =?us-ascii?Q?KyZVRHeM6D+7idHDxEQ1dk146T1b/ntNgF8lOMfo6OGJREKYVkNJ6QW5OvI9?= =?us-ascii?Q?57OzczWB/eaPN2U/I4Hlb3n+5XgD07AcsNODlM3gf9FXPABfe1H5r1ZSe0lV?= =?us-ascii?Q?MeEIjxhohQXWKZqFRFO+dOfyrjkc0ChDruoRpUcx6sBps3sloKBurLj3ExQf?= =?us-ascii?Q?UILlyoq++zVUDN7ZdSAPX8IiAWTL+5te86qLwQCo3yAcfZKmo15sXwBbEjCZ?= =?us-ascii?Q?Fjx/uZfFb5Jmnpxxoo4UBPFam5BxPlqYuNh8Q6LxpddfGNsFagaihKiuPJCI?= =?us-ascii?Q?Qb8GwUHauIdMDDtZgHxqW/jvT6KHtXL5rgi3DB3bl2aQ+/vDVVDpSPIJT8gd?= =?us-ascii?Q?bZJ3QnUv3wlfoBEb27TPe+7udDtF//8GhoKFEbSwIlRKVG2ci+Ofe1ewnA68?= =?us-ascii?Q?bKt1XCcy0hEO7F4/7VAwKoOeLWnHGU+lySOTd7hcaPtJ4hQDVF8Vk65+Ba41?= =?us-ascii?Q?mFo9niDNLM6hpJGhO/H5Xv2xuHtTnAkqYdF3+sWAo7teSr+kvVffesMOQVAE?= =?us-ascii?Q?kDZ0NmaJuUKlsp8I9FPK8eQVgiuQxhILu/PssRqKlTIUeSeLdhsLn1ePyzby?= =?us-ascii?Q?fRLKN0SkbtWQrbitY7rrx+oWy5y5WJsadBuYMIP9zjQGwvnYjRvoWPwghvK8?= =?us-ascii?Q?jY3FMUH4Cv0+eqqxWjN31wOTjh1ww6KyX8FowspvgoriTq0BifdWrsb6CWJi?= =?us-ascii?Q?diMvmKNPQLY4wl+klLlaS6dkkHrrbwK3hH/seF0H9pPPQggepx8ig70W3RBR?= =?us-ascii?Q?oPHqPAofVaqRXav5A8+GHshX/+ygrRQm?= 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:(13230040)(82310400026)(376014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2024 09:24:22.8804 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1ff64c50-b8a6-42b4-b8ae-08dcd30cb04a 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: CO1PEPF000044F0.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6947 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1726133108742116600 Content-Type: text/plain; charset="utf-8" When device on dom0 side has been reset, the vpci on Xen side won't get notification, so that the cached state in vpci is all out of date with the real device state. To solve that problem, add a new function to clear all vpci device state when device is reset on dom0 side. And call that function in pcistub_init_device. Because when using "pci-assignable-add" to assign a passthrough device in Xen, it will reset passthrough device and the vpci state will out of date, and then device will fail to restore bar state. Signed-off-by: Jiqian Chen Signed-off-by: Huang Rui Signed-off-by: Jiqian Chen Reviewed-by: Stefano Stabellini --- v8->v9 changes: Due to the struct and name of the hypercall changed on Xen side, I did the = corresponding changes, so removed the Reviewed-by of Stefano. But no functi= on changes actually. v5->v8 changes: No. v4->v5 changes: Added Reviewed-by of Stefano. v3->v4 changes: Changed the code comment of PHYSDEVOP_pci_device_state_reset. Used a new function pcistub_reset_device_state to wrap __pci_reset_function= _locked and xen_reset_device_state, and called pcistub_reset_device_state i= n pci_stub.c. v2->v3 changes: Added condition to limit do xen_reset_device_state for no-pv domain in pcis= tub_init_device. v1->v2 changes: New patch to add a new function to call reset hypercall. --- drivers/xen/pci.c | 13 +++++++++++++ drivers/xen/xen-pciback/pci_stub.c | 18 +++++++++++++++--- include/xen/interface/physdev.h | 17 +++++++++++++++++ include/xen/pci.h | 6 ++++++ 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/drivers/xen/pci.c b/drivers/xen/pci.c index 72d4e3f193af..bb59524b8bbd 100644 --- a/drivers/xen/pci.c +++ b/drivers/xen/pci.c @@ -177,6 +177,19 @@ static int xen_remove_device(struct device *dev) return r; } =20 +int xen_reset_device(const struct pci_dev *dev) +{ + struct pci_device_reset device =3D { + .dev.seg =3D pci_domain_nr(dev->bus), + .dev.bus =3D dev->bus->number, + .dev.devfn =3D dev->devfn, + .flags =3D PCI_DEVICE_RESET_FLR, + }; + + return HYPERVISOR_physdev_op(PHYSDEVOP_pci_device_reset, &device); +} +EXPORT_SYMBOL_GPL(xen_reset_device); + static int xen_pci_notifier(struct notifier_block *nb, unsigned long action, void *data) { diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/p= ci_stub.c index 4faebbb84999..3e162c1753e2 100644 --- a/drivers/xen/xen-pciback/pci_stub.c +++ b/drivers/xen/xen-pciback/pci_stub.c @@ -89,6 +89,16 @@ static struct pcistub_device *pcistub_device_alloc(struc= t pci_dev *dev) return psdev; } =20 +static int pcistub_reset_device_state(struct pci_dev *dev) +{ + __pci_reset_function_locked(dev); + + if (!xen_pv_domain()) + return xen_reset_device(dev); + else + return 0; +} + /* Don't call this directly as it's called by pcistub_device_put */ static void pcistub_device_release(struct kref *kref) { @@ -107,7 +117,7 @@ static void pcistub_device_release(struct kref *kref) /* Call the reset function which does not take lock as this * is called from "unbind" which takes a device_lock mutex. */ - __pci_reset_function_locked(dev); + pcistub_reset_device_state(dev); if (dev_data && pci_load_and_free_saved_state(dev, &dev_data->pci_saved_state)) dev_info(&dev->dev, "Could not reload PCI state\n"); @@ -284,7 +294,7 @@ void pcistub_put_pci_dev(struct pci_dev *dev) * (so it's ready for the next domain) */ device_lock_assert(&dev->dev); - __pci_reset_function_locked(dev); + pcistub_reset_device_state(dev); =20 dev_data =3D pci_get_drvdata(dev); ret =3D pci_load_saved_state(dev, dev_data->pci_saved_state); @@ -420,7 +430,9 @@ static int pcistub_init_device(struct pci_dev *dev) dev_err(&dev->dev, "Could not store PCI conf saved state!\n"); else { dev_dbg(&dev->dev, "resetting (FLR, D3, etc) the device\n"); - __pci_reset_function_locked(dev); + err =3D pcistub_reset_device_state(dev); + if (err) + goto config_release; pci_restore_state(dev); } /* Now disable the device (this also ensures some private device diff --git a/include/xen/interface/physdev.h b/include/xen/interface/physde= v.h index a237af867873..df74e65a884b 100644 --- a/include/xen/interface/physdev.h +++ b/include/xen/interface/physdev.h @@ -256,6 +256,13 @@ struct physdev_pci_device_add { */ #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_reset 32 + struct physdev_pci_device { /* IN */ uint16_t seg; @@ -263,6 +270,16 @@ struct physdev_pci_device { uint8_t devfn; }; =20 +struct pci_device_reset { + struct physdev_pci_device dev; +#define PCI_DEVICE_RESET_COLD 0x0 +#define PCI_DEVICE_RESET_WARM 0x1 +#define PCI_DEVICE_RESET_HOT 0x2 +#define PCI_DEVICE_RESET_FLR 0x3 +#define PCI_DEVICE_RESET_MASK 0x3 + uint32_t flags; +}; + #define PHYSDEVOP_DBGP_RESET_PREPARE 1 #define PHYSDEVOP_DBGP_RESET_DONE 2 =20 diff --git a/include/xen/pci.h b/include/xen/pci.h index b8337cf85fd1..424b8ea89ca8 100644 --- a/include/xen/pci.h +++ b/include/xen/pci.h @@ -4,10 +4,16 @@ #define __XEN_PCI_H__ =20 #if defined(CONFIG_XEN_DOM0) +int xen_reset_device(const struct pci_dev *dev); int xen_find_device_domain_owner(struct pci_dev *dev); int xen_register_device_domain_owner(struct pci_dev *dev, uint16_t domain); int xen_unregister_device_domain_owner(struct pci_dev *dev); #else +static inline int xen_reset_device(const struct pci_dev *dev) +{ + return -1; +} + static inline int xen_find_device_domain_owner(struct pci_dev *dev) { return -1; --=20 2.34.1 From nobody Sat Nov 30 04:37:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1726133110; cv=pass; d=zohomail.com; s=zohoarc; b=itt5UbBtbyjy2idlenXhsqFKP019hRUMmUbhgLKo/DSmlXv/0LQLHF+NNPjNVJ9Ack3pFh3+mRn0HD4rAs0PLEfESxxqQjH+U9Y44DQMtM4f7WHZ5L07+W6UHEbvzLZ4KYf5eh4CbIDHW3oIewL0tkKQJaisabUAb3ujd2Hc7r8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726133110; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VoRjaM5eHB5wA0PEqYUhMxGvKJWObMEd8EVOz5Lzs3k=; b=D0tmhlA8MqfckImwziBDaRg28bLgJJOaF/IiAeeoLjGn8DrqTS+QKq7OFP3LVoxoMr/pc2VQqvJXoZjmj3y5sC2JanlYgRZuoDEkeeZjrjBgL7BuLbiMS/zVI80DdgOW1JElfmJuoyyU6e9eFnWnubcCTc7fv7rlHXEsuZWV+Mw= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 172613311017869.53277165375891; Thu, 12 Sep 2024 02:25:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.797107.1206938 (Exim 4.92) (envelope-from ) id 1sog42-0005DY-HR; Thu, 12 Sep 2024 09:24:34 +0000 Received: by outflank-mailman (output) from mailman id 797107.1206938; Thu, 12 Sep 2024 09:24: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 1sog42-0005DH-EP; Thu, 12 Sep 2024 09:24:34 +0000 Received: by outflank-mailman (input) for mailman id 797107; Thu, 12 Sep 2024 09:24:33 +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 1sog41-0004ii-Ay for xen-devel@lists.xenproject.org; Thu, 12 Sep 2024 09:24:33 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2062d.outbound.protection.outlook.com [2a01:111:f400:7e88::62d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d1236f61-70e8-11ef-a0b5-8be0dac302b0; Thu, 12 Sep 2024 11:24:32 +0200 (CEST) Received: from BYAPR05CA0075.namprd05.prod.outlook.com (2603:10b6:a03:e0::16) by DM4PR12MB6423.namprd12.prod.outlook.com (2603:10b6:8:bd::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.17; Thu, 12 Sep 2024 09:24:25 +0000 Received: from CO1PEPF000044F0.namprd05.prod.outlook.com (2603:10b6:a03:e0:cafe::ad) by BYAPR05CA0075.outlook.office365.com (2603:10b6:a03:e0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24 via Frontend Transport; Thu, 12 Sep 2024 09:24:25 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000044F0.mail.protection.outlook.com (10.167.241.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Thu, 12 Sep 2024 09:24:25 +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.39; Thu, 12 Sep 2024 04:24:22 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d1236f61-70e8-11ef-a0b5-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=soF/7JbsPYs2FiECj6WzDRWVx8CW4G8CmveZIVeTw9g9zIQ919sqBvqF/ue2NZnZgkNjM2vBX/DvomeNWNlz5abA9x3eWR/ILdZaYMnNHSHt42ge62ElUHCgCWBziadrKeRWLZu4oiCfgK4fBEQOgAYvWbLMNzdmIAN6PFwMbGT3YU0MPftKgwGgaCaXBM/5nySykMCjPobr+08KN4cXVL6ZaZmjVowUWaoeQtPji/Do9slflCidzQDcJCsyRt+YGlFsdMH2fGKfciMnJ+zpQdB/qPgmT2f0MOm8O7evAwokxNrguRZRnkRE35ddw3TXeGNH5+531cZ843QiD82IvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=VoRjaM5eHB5wA0PEqYUhMxGvKJWObMEd8EVOz5Lzs3k=; b=UFecN9xItaFZH+fSVIs/K7EHVy9jPEbo/+CKBrVX/MVAWmxRIHNzhcXoF/wO5/wCEDeLY0seFjV2jJ9hcPqp++h45+VOeOgRu0t1ueCsu1xvVB7DhU/wkSRnn5YausLisN7kOVmipYSSgq9ZzNDTlsZlAt9wiNuqm/cng+RPVGBL5QCKVBJuPd/rFP0STb7bzxQhWNzFG/4mrOjScKyp3qleMHcNhCSri+2ZT1bxrBB8fXOfHm3rXjnbMguGLOntdibOoVBVzS+Vq1UNRrmVlRQN7b7I9MD3jMSNs3gIMfJPbiHPSrzmy55RvIGWB0cqvWx91noCuw6L9oQnUb8djA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com 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=VoRjaM5eHB5wA0PEqYUhMxGvKJWObMEd8EVOz5Lzs3k=; b=w6YTj2W/D5kduozQt5c7pURNhVL/LEE4Kg7HEqwdtJZDjELHysyaPkcUxn7DG8ZDU7sorDdLgLb7LdtvmDdRXh7Lp11IztLB1QOldz9xvxU7Po56dlTlvWcQVDyVxIHrmMa0TW10Ixzw8aHOFsxMYC0JM8izkmCBjSyfCeZJn9A= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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: Juergen Gross , Stefano Stabellini , Bjorn Helgaas , "Rafael J . Wysocki" CC: , , , , Jiqian Chen , Huang Rui Subject: [KERNEL PATCH v9 2/3] xen/pvh: Setup gsi for passthrough device Date: Thu, 12 Sep 2024 17:23:50 +0800 Message-ID: <20240912092352.1602724-3-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240912092352.1602724-1-Jiqian.Chen@amd.com> References: <20240912092352.1602724-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: CO1PEPF000044F0:EE_|DM4PR12MB6423:EE_ X-MS-Office365-Filtering-Correlation-Id: 8d4ca877-9c35-4470-0c2f-08dcd30cb1a2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?DcL9Jj+YqAGZLbISZFgvW5+WNbOD9b2Q3jbTBY4A9gIUWHLZDRRIFYBBT1zK?= =?us-ascii?Q?rXZs1e1O3JjX/8E+LVf4/Sa1g7CxIGI8TKl2QL0TOpteIuLxZI+AOViY2ToC?= =?us-ascii?Q?i5zL7YhvPbpfo92EqTBiIfSdN9tV5Rs8HxK5APZOSU9eUqhljPNaBLVKHcCP?= =?us-ascii?Q?BE4XmiuBsd6bR0icI9x1uKTGXe8UztTU1FjOJkTC81GugyecKPs5ZTdvWcXb?= =?us-ascii?Q?vUiyH/H61SO8zGpoqxSqUuvsHB13TlsLkZwBPPuyjI5rEIYGULr1am/T5Dq2?= =?us-ascii?Q?VdKcLb/Nmt8qmDtVYRIdt3wxlFOoW76kslcom7+FfvVKKVajfV2SUBtvin/5?= =?us-ascii?Q?/wDuwlO92ZFtU4lDfRc81UOt+PWoKCW4Yn3rBK4mEEZ9BpLbbi/foUH0/3pT?= =?us-ascii?Q?TVTPl50hENEuuVM+QpxSdNy2HkvkIlAm0KM84mlbIgSqcssD/SO2/Jpyepnf?= =?us-ascii?Q?SG/iQOYeJk2RPe/6HVxYWrYwU1uT5GCmKa5RVTnI137ntHgmAIMHuP/dmJQh?= =?us-ascii?Q?oOyUol9XYzbyLCOACdhk07D0Ybi6kijlnzov36yNdfhaD12huDEAJMFSz8ZS?= =?us-ascii?Q?sP7q3nsViyNiWeela5vTPkU2pItHYxQZ6f3lMw/AZxJlpdgnQfSoZn1hXVrT?= =?us-ascii?Q?kkYAfoIuR89V7bceOU2190eLUazXgZyb0d+iwhWs8G2LGgm50BqpjH6MYc/+?= =?us-ascii?Q?gTkVCuErN/Em2mjFxQpIynf00wKGrGSfpY1tTuKqQfhvg4rghtzhCvMJrwdy?= =?us-ascii?Q?POLYkZVbLa2VVQn8JKdZTnPfDknEeHisIKDtcY7/CMLBlf9UPk9tIQ6Inkm6?= =?us-ascii?Q?GzlpxeNOMLN8u/fwArvPBogEARSAZIA0dIEKhAxGthoKttGZUtX7lNni9MBx?= =?us-ascii?Q?opAu1sc8IH1AxXvvX13547BW7k8YfFU/IIExsJsC+wH/j+i1qqe0y9nNZYZH?= =?us-ascii?Q?No7M4S1EHLhzN12Fx6GNUeXwZIdCiHMzAtQSlmpA0PICxHOCveH4vKE4Gkuj?= =?us-ascii?Q?59R9AWhW90zhVMNsAaXMBZohidSGt3kpiD3ZDxVhg/oA0GBRfDSARqAlYEn8?= =?us-ascii?Q?69T04AIa5wy49FJTO7v4WouZdwIFOYYbIg9cZtmM8uM9u7cWeyYfayIwaKNt?= =?us-ascii?Q?1sknlsYH52VHnXslR8bH0pYty3QxmqzoOmzHkciRI8LAObI0v9SkRBsMas+n?= =?us-ascii?Q?ST+3J1EJqeGWeQ6UwWkrmhBaen8BU334PlSAe+Q2kYHWmrB7TfajWPcXryTQ?= =?us-ascii?Q?jqQ5Xg8lDcIwESrEd4GgVOUvlM7t7H5rUoiAyOTzQfeo/3BeV/oGJU552Hm3?= =?us-ascii?Q?CDAH3ETcWXyX+m0tbE5BvYVqUhB7O9w9Pkm7XwYwpRBD84ZzYpFOHsLSr2L+?= =?us-ascii?Q?xM7TeLtePNyt9O4lXg/lYot76gQx5CTDzQ57toSbK6XIuVh1gUYCLbEr5AtF?= =?us-ascii?Q?mVvY+Wn0LBE18Lq9z3o2c1bWH2Oz3iWb6nPCHONNpER6Hiw0Hae00g=3D=3D?= 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:(13230040)(36860700013)(1800799024)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2024 09:24:25.0523 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8d4ca877-9c35-4470-0c2f-08dcd30cb1a2 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: CO1PEPF000044F0.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6423 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1726133110851116600 Content-Type: text/plain; charset="utf-8" In 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 domU. When assigning a device to passthrough, proactively setup the gsi of the device during that process. Signed-off-by: Jiqian Chen Signed-off-by: Huang Rui Signed-off-by: Jiqian Chen Reviewed-by: Stefano Stabellini --- v8->v9 changes: Moved the calling of xen_acpi_get_gsi_info under check "if (xen_initial_dom= ain() && xen_pvh_domain())" to prevent it is called in PV dom0. Removed Reviewed-by of Stefano. v7->v8 changes: Used CONFIG_XEN_ACPI instead of CONFIG_ACPI to wrap codes. v6->v7 changes: Moved the implementation of function xen_acpi_get_gsi_info to file drivers/= xen/acpi.c, that modification is more convenient for the subsequent patch t= o obtain gsi. v5->v6 changes: No. v4->v5 changes: Added Reviewed-by of Stefano. v3->v4 changes: Removed map_pirq from xen_pvh_passthrough_gsi since let pvh calls map_pirq = here is not right. v2->v3 changes: Abandoned previous implementations that called unmask_irq, and change to do= setup_gsi and map_pirq for passthrough device in pcistub_init_device. --- | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202406090859.KW3eeESv-lkp@i= ntel.com/ --- | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202405172132.TazuVpPo-lkp@i= ntel.com/ --- arch/x86/xen/enlighten_pvh.c | 23 ++++++++++++++ drivers/acpi/pci_irq.c | 2 +- drivers/xen/acpi.c | 50 ++++++++++++++++++++++++++++++ drivers/xen/xen-pciback/pci_stub.c | 20 ++++++++++++ include/linux/acpi.h | 1 + include/xen/acpi.h | 18 +++++++++++ 6 files changed, 113 insertions(+), 1 deletion(-) diff --git a/arch/x86/xen/enlighten_pvh.c b/arch/x86/xen/enlighten_pvh.c index 728a4366ca85..bf68c329fc01 100644 --- a/arch/x86/xen/enlighten_pvh.c +++ b/arch/x86/xen/enlighten_pvh.c @@ -4,6 +4,7 @@ #include =20 #include +#include =20 #include #include @@ -28,6 +29,28 @@ bool __ro_after_init xen_pvh; EXPORT_SYMBOL_GPL(xen_pvh); =20 +#ifdef CONFIG_XEN_DOM0 +int xen_pvh_setup_gsi(int gsi, int trigger, int polarity) +{ + int ret; + struct physdev_setup_gsi setup_gsi; + + setup_gsi.gsi =3D gsi; + setup_gsi.triggering =3D (trigger =3D=3D ACPI_EDGE_SENSITIVE ? 0 : 1); + setup_gsi.polarity =3D (polarity =3D=3D ACPI_ACTIVE_HIGH ? 0 : 1); + + ret =3D HYPERVISOR_physdev_op(PHYSDEVOP_setup_gsi, &setup_gsi); + if (ret =3D=3D -EEXIST) { + xen_raw_printk("Already setup the GSI :%d\n", gsi); + ret =3D 0; + } else if (ret) + xen_raw_printk("Fail to setup GSI (%d)!\n", gsi); + + return ret; +} +EXPORT_SYMBOL_GPL(xen_pvh_setup_gsi); +#endif + /* * Reserve e820 UNUSABLE regions to inflate the memory balloon. * diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c index ff30ceca2203..630fe0a34bc6 100644 --- a/drivers/acpi/pci_irq.c +++ b/drivers/acpi/pci_irq.c @@ -288,7 +288,7 @@ static int acpi_reroute_boot_interrupt(struct pci_dev *= dev, } #endif /* CONFIG_X86_IO_APIC */ =20 -static struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int= pin) +struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int pin) { struct acpi_prt_entry *entry =3D NULL; struct pci_dev *bridge; diff --git a/drivers/xen/acpi.c b/drivers/xen/acpi.c index 6893c79fd2a1..9e2096524fbc 100644 --- a/drivers/xen/acpi.c +++ b/drivers/xen/acpi.c @@ -30,6 +30,7 @@ * IN THE SOFTWARE. */ =20 +#include #include #include #include @@ -75,3 +76,52 @@ int xen_acpi_notify_hypervisor_extended_sleep(u8 sleep_s= tate, return xen_acpi_notify_hypervisor_state(sleep_state, val_a, val_b, true); } + +struct acpi_prt_entry { + struct acpi_pci_id id; + u8 pin; + acpi_handle link; + u32 index; +}; + +int xen_acpi_get_gsi_info(struct pci_dev *dev, + int *gsi_out, + int *trigger_out, + int *polarity_out) +{ + int gsi; + u8 pin; + struct acpi_prt_entry *entry; + int trigger =3D ACPI_LEVEL_SENSITIVE; + int polarity =3D acpi_irq_model =3D=3D ACPI_IRQ_MODEL_GIC ? + ACPI_ACTIVE_HIGH : ACPI_ACTIVE_LOW; + + if (!dev || !gsi_out || !trigger_out || !polarity_out) + return -EINVAL; + + pin =3D dev->pin; + if (!pin) + return -EINVAL; + + entry =3D acpi_pci_irq_lookup(dev, pin); + if (entry) { + if (entry->link) + gsi =3D acpi_pci_link_allocate_irq(entry->link, + entry->index, + &trigger, &polarity, + NULL); + else + gsi =3D entry->index; + } else + gsi =3D -1; + + if (gsi < 0) + return -EINVAL; + + *gsi_out =3D gsi; + *trigger_out =3D trigger; + *polarity_out =3D polarity; + + return 0; +} +EXPORT_SYMBOL_GPL(xen_acpi_get_gsi_info); diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/p= ci_stub.c index 3e162c1753e2..8ce27333f54b 100644 --- a/drivers/xen/xen-pciback/pci_stub.c +++ b/drivers/xen/xen-pciback/pci_stub.c @@ -21,6 +21,9 @@ #include #include #include +#ifdef CONFIG_XEN_ACPI +#include +#endif #include #include #include "pciback.h" @@ -367,6 +370,9 @@ static int pcistub_match(struct pci_dev *dev) static int pcistub_init_device(struct pci_dev *dev) { struct xen_pcibk_dev_data *dev_data; +#ifdef CONFIG_XEN_ACPI + int gsi, trigger, polarity; +#endif int err =3D 0; =20 dev_dbg(&dev->dev, "initializing...\n"); @@ -435,6 +441,20 @@ static int pcistub_init_device(struct pci_dev *dev) goto config_release; pci_restore_state(dev); } + +#ifdef CONFIG_XEN_ACPI + if (xen_initial_domain() && xen_pvh_domain()) { + err =3D xen_acpi_get_gsi_info(dev, &gsi, &trigger, &polarity); + if (err) { + dev_err(&dev->dev, "Fail to get gsi info!\n"); + goto config_release; + } + err =3D xen_pvh_setup_gsi(gsi, trigger, polarity); + if (err) + goto config_release; + } +#endif + /* Now disable the device (this also ensures some private device * data is setup before we export) */ diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 0687a442fec7..02ded9f53a6b 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -362,6 +362,7 @@ void acpi_unregister_gsi (u32 gsi); =20 struct pci_dev; =20 +struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int pin); int acpi_pci_irq_enable (struct pci_dev *dev); void acpi_penalize_isa_irq(int irq, int active); bool acpi_isa_irq_available(int irq); diff --git a/include/xen/acpi.h b/include/xen/acpi.h index b1e11863144d..3bcfe82d9078 100644 --- a/include/xen/acpi.h +++ b/include/xen/acpi.h @@ -67,10 +67,28 @@ static inline void xen_acpi_sleep_register(void) acpi_suspend_lowlevel =3D xen_acpi_suspend_lowlevel; } } +int xen_pvh_setup_gsi(int gsi, int trigger, int polarity); +int xen_acpi_get_gsi_info(struct pci_dev *dev, + int *gsi_out, + int *trigger_out, + int *polarity_out); #else static inline void xen_acpi_sleep_register(void) { } + +static inline int xen_pvh_setup_gsi(int gsi, int trigger, int polarity) +{ + return -1; +} + +static inline int xen_acpi_get_gsi_info(struct pci_dev *dev, + int *gsi_out, + int *trigger_out, + int *polarity_out) +{ + return -1; +} #endif =20 #endif /* _XEN_ACPI_H */ --=20 2.34.1 From nobody Sat Nov 30 04:37:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1726133111; cv=pass; d=zohomail.com; s=zohoarc; b=c2X8PoPSaP59fIo8uN+7aej4GlfCzhptSH73156L5txtsF/lZxXZLsPmSOrnWVprxbn6Xdm2Q/wWmETqWGl+0owesk471bhzMT0PX1/nbnFgnjrAseRNHv3+YWcxV0Jl04KNCBdfMru3zvKmtZpmdvvO2SMbL9POIHqxM3bmB3o= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726133111; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mku7qe9Kp1BSDdWMSj+vWw+ZdWEAPFHw4jIoXDID1VI=; b=X743W1eHjmbuuwMFAgT0IIuMObQ+6vzs3zzQB7O8emy4CziIcd9p5mzYsnRfrlIphQ+q8dMkW8uhZdTlPdqDlGG0bt3jgxqiwc1MlayTbGAk6/dKmKvwzILfma6cZZQ7vQAytX9QUEXDwqgtbcaeJyUiWwXidA2Yuy6ENrmzRKs= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1726133111016837.2710921164205; Thu, 12 Sep 2024 02:25:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.797108.1206949 (Exim 4.92) (envelope-from ) id 1sog46-0005Wl-T5; Thu, 12 Sep 2024 09:24:38 +0000 Received: by outflank-mailman (output) from mailman id 797108.1206949; Thu, 12 Sep 2024 09:24:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sog46-0005WY-QC; Thu, 12 Sep 2024 09:24:38 +0000 Received: by outflank-mailman (input) for mailman id 797108; Thu, 12 Sep 2024 09:24:38 +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 1sog46-0004ii-Be for xen-devel@lists.xenproject.org; Thu, 12 Sep 2024 09:24:38 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2060c.outbound.protection.outlook.com [2a01:111:f403:200a::60c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d3ec30f7-70e8-11ef-a0b5-8be0dac302b0; Thu, 12 Sep 2024 11:24:37 +0200 (CEST) Received: from MW4PR03CA0160.namprd03.prod.outlook.com (2603:10b6:303:8d::15) by SJ0PR12MB7036.namprd12.prod.outlook.com (2603:10b6:a03:483::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.20; Thu, 12 Sep 2024 09:24:28 +0000 Received: from CO1PEPF000044EE.namprd05.prod.outlook.com (2603:10b6:303:8d:cafe::df) by MW4PR03CA0160.outlook.office365.com (2603:10b6:303:8d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24 via Frontend Transport; Thu, 12 Sep 2024 09:24:28 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000044EE.mail.protection.outlook.com (10.167.241.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Thu, 12 Sep 2024 09:24: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.39; Thu, 12 Sep 2024 04:24:24 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d3ec30f7-70e8-11ef-a0b5-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WnUDC0M70Z/MGHXClhtnA0uz1Lx7jsPnI2ayVK8xkLp5B7vBN3Tx1INCdp9S2WFDP2KHxdFynCn1Bp28SawWtw2fpHySwei5VMCSQYalnhE6V1L9Yt9DV3R7rXHsc+XVHYOc+YYVU9cOvCLOwNT6Lj0CLL628jroyqSKHHDOv030e4ryHi9f5uFWTqDRRQqpGo9GVdhLof3DZDCcEZY8bd3g1E4+oGtGtSoXfBAbsC4CM/C/n5qVYuF0WYF54O8p5yALmMCBKY/VI04kFgwinmtQTig4i+qn0naJKLC4zG1BejlWbisfT+l9sA74IJczWQjejjJVQ1PLpDapiqNQdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=mku7qe9Kp1BSDdWMSj+vWw+ZdWEAPFHw4jIoXDID1VI=; b=YX0LsJHB0i3KLLS1KLbibaTJt4cfvfCauDdRGz404ih+R7XNlhcW4SfmxdWI/m/sN2ZawEf4qu6mE4ZcZdAeM4oNZh8viyz0fHAtcYpumBw8awded2obOt1miNmgKVckpMEw/xdVU9zTWEuuhtgPZbi8HTRiNuEW0Tmj/z5mHZm3zvxnvKZozxQuFGx61fBLfDucoZHYbKM322O8OkBvE/PHI8opssejJP1C6D2KkSKgCjBfO1HlxhkwVNObDexaA9HoyZmBUeCCl0r/ImrJorRH5I6idxLLFu9EecAl+srb2JjpIT0mKz2NxjPSjIM+DuwBUAjS7F6WSbgekzENNg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com 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=mku7qe9Kp1BSDdWMSj+vWw+ZdWEAPFHw4jIoXDID1VI=; b=yVLT5uInvTHJkQ5L4Y3CCJ927uq0rvOjpwno+5Lmc0AOsTs1f+KODTtBUfvocXZCysuzK3qBL5eqZ82Ze5gvue27vVa8jFSbspPoF9dXqwhfn3SuuqxZi5ZV0zQ5x0ahbe4wlrubePVOiZnoGcH2BTl+oyNuGfXgLo1TqILGtIg= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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: Juergen Gross , Stefano Stabellini , Bjorn Helgaas , "Rafael J . Wysocki" CC: , , , , Jiqian Chen , Huang Rui Subject: [KERNEL PATCH v9 3/3] xen/privcmd: Add new syscall to get gsi from dev Date: Thu, 12 Sep 2024 17:23:51 +0800 Message-ID: <20240912092352.1602724-4-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240912092352.1602724-1-Jiqian.Chen@amd.com> References: <20240912092352.1602724-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: CO1PEPF000044EE:EE_|SJ0PR12MB7036:EE_ X-MS-Office365-Filtering-Correlation-Id: d65e261d-e99c-4ebe-75c0-08dcd30cb37e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?qDRus6H+BxtgcAJRwcQmtzYlphPBWdk2FWQ35sQ9mu8307oF/GrGEg6OCd+N?= =?us-ascii?Q?0Tg+LiQIqAKkes5zL4ZlEbBZBlrlkVmhFuGMzdmCmrxjbVGSlA5D+iywwacU?= =?us-ascii?Q?LJ24agM8xGH9cbbJ0AIDS/ltUmKuwHpNbxegGB4VZs0IW00mU1O5F/SNZRow?= =?us-ascii?Q?PtPDzIGP42CevjEgDSrzMU+VyAWehBc5GIyGmKxplE5IkYIsiLJvpBGxZ7pr?= =?us-ascii?Q?mBTUyE8TjfK1luMaQVmZU40weoUhiIvqHG4vn607n9wzMs4c6rNdyvo1O5qX?= =?us-ascii?Q?jPclOtW3KEcCuWTGWV8A099E/RIPxQoTMPso3aQuktkmB+Rjq3N5TPqjyGVr?= =?us-ascii?Q?RaRVt1yJYCIQsU+frO2IUIAzOXcnAv0OtGV3lekyuAQoKz9d+Y2TlRxCcL0E?= =?us-ascii?Q?+xsov6lLZu0qC2B9TH4EpRVyXCHqVU5VKGGUT3AjdAPA9cShQEyrfk9zUBPb?= =?us-ascii?Q?qqfvVvTftWu3hr9NHtB0D1kWXD3A58nue71OTSRjFdRdU7+Bd22wlCCqp9iw?= =?us-ascii?Q?Oc6/7Asfvubh5Vn3ARCGXGMbf0VM3fB4Svs8fUO/apinqWZOZ/+KnrJpvFG5?= =?us-ascii?Q?myPcqGGTWMzhLyW+/wHszAx4ZOrg3OvxJlDslIdLOhm3gUg/VDVO6sokBsv3?= =?us-ascii?Q?EmdauI6ueZ2Gx78FpftidX5EI2DG/lExBrP5u28ACsuFBWEZtU5VMRNshuBC?= =?us-ascii?Q?MFXL4nXGIBF0pJ6c6sgIFftdYKInzS6KclicpGJH0Qc8+N5QoQCArFEyx4tx?= =?us-ascii?Q?FxXYtNJJfv7rw4VW2ImbwWevxnMTTSu8sLRja8KgCtjgwFgtoK9sbHdo7iWF?= =?us-ascii?Q?rPK67M6wYx6EX7WshV3A0y2iVx9JGPyB5wn2XFyu1sGraSt1gTsAiRvX+pYg?= =?us-ascii?Q?oELO5D246wkvH94rrkJdNmoaWuz3kSgg4uE0GFB2F9mo0zJEdzrQ49GbxMhT?= =?us-ascii?Q?i/6zgc84Chtz4dobJkmBTKCuvHNZnsHtFzue1i5Efmdyrxv2TTobEfcundn2?= =?us-ascii?Q?OkPvmX+H283QwnoQQk2K64Siz1xcwU+4MEu+EyLTEBZoOL3y32AtVFVenBXY?= =?us-ascii?Q?Ze+/CaBkNDDYssd6wz4TQ07ddY5JdtB2aEH8JBsxwWA9/7+RTWbuiCmwJvei?= =?us-ascii?Q?+AAQuOTPrwzXAogTtXIoRkSghy/G3jbOtxfDcKAmlBo+YRDLY5OSdS7UJfvU?= =?us-ascii?Q?4l2diUK2Oy4hlKy13XET2b3VEUrq7ZZgdAzbgg+O+xhdXAsZUkphMvlMk9Ep?= =?us-ascii?Q?W5uLB4NciDBUG4NwmbcRY3xhg/mNnY/nZixOKLsNvMs6Unb1vkNAL+4/Db+9?= =?us-ascii?Q?FNYtlUg3eYkoCe384SH1qhi3gIFiPMRhm6fBPA/IFyqvJglLPS3tkmwqvaBM?= =?us-ascii?Q?YBGIxF/wO/jl9P63156xKIgOrNpeR8xjJkh11J5iZZWuGFRib9uBKu+inxsR?= =?us-ascii?Q?HeshSZn9o5Jq9KqlQTpGylBprjJPQBC3SNfKcmX5L/3wAjWbb+0tcw=3D=3D?= 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:(13230040)(376014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2024 09:24:28.2370 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d65e261d-e99c-4ebe-75c0-08dcd30cb37e 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: CO1PEPF000044EE.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB7036 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1726133112867116600 Content-Type: text/plain; charset="utf-8" On PVH dom0, when passthrough a device to domU, QEMU and xl tools want to use gsi number to do pirq mapping, see QEMU code xen_pt_realize->xc_physdev_map_pirq, and xl code pci_add_dm_done->xc_physdev_map_pirq, but in current codes, the gsi number is got from file /sys/bus/pci/devices//irq, that is wrong, because irq is not equal with gsi, they are in different spaces, so pirq mapping fails. And in current linux codes, there is no method to get gsi for userspace. For above purpose, record gsi of pcistub devices when init pcistub and add a new syscall into privcmd to let userspace can get gsi when they have a need. Signed-off-by: Jiqian Chen Signed-off-by: Huang Rui Signed-off-by: Jiqian Chen --- v8->v9 changes: Changed the syscall name from "IOCTL_PRIVCMD_GSI_FROM_DEV" to "IOCTL_PRIVCM= D_PCIDEV_GET_GSI". Also changed the other functions name. Changed the macro wrapping "pcistub_get_gsi_from_sbdf" from "CONFIG_XEN_ACP= I" to "CONFIG_XEN_PCIDEV_BACKEND" to fix compile errors reported by CI robo= t. Changed the parameter gsi of struct privcmd_pcidev_get_gsi from int to u32. v7->v8 changes: In function privcmd_ioctl_gsi_from_dev, return -EINVAL when not confige CON= FIG_XEN_ACPI. Used PCI_BUS_NUM PCI_SLOT PCI_FUNC instead of open coding. v6->v7 changes: Changed implementation to add a new parameter "gsi" to struct pcistub_devic= e and set gsi when pcistub initialize device. Then when userspace wants to = get gsi and pass sbdf, we can return that gsi. v5->v6 changes: Changed implementation to add a new syscall to translate irq to gsi, instea= d adding a new gsi sysfs node, because the pci Maintainer didn't allow to a= dd that sysfs node. v3->v5 changes: No. v2->v3 changes: Suggested by Roger: Abandoned previous implementations that added new sysca= ll to get gsi from irq and changed to add a new sysfs node for gsi, then us= erspace can get gsi number from sysfs node. --- | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202406090826.whl6Cb7R-lkp@i= ntel.com/ --- | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202405171113.T431PC8O-lkp@i= ntel.com/ --- drivers/xen/privcmd.c | 30 +++++++++++++++++++++++ drivers/xen/xen-pciback/pci_stub.c | 38 +++++++++++++++++++++++++++--- include/uapi/xen/privcmd.h | 7 ++++++ include/xen/acpi.h | 9 +++++++ 4 files changed, 81 insertions(+), 3 deletions(-) diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c index 9563650dfbaf..1ed612d21543 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -46,6 +46,9 @@ #include #include #include +#ifdef CONFIG_XEN_ACPI +#include +#endif =20 #include "privcmd.h" =20 @@ -844,6 +847,29 @@ static long privcmd_ioctl_mmap_resource(struct file *f= ile, return rc; } =20 +static long privcmd_ioctl_pcidev_get_gsi(struct file *file, void __user *u= data) +{ +#ifdef CONFIG_XEN_ACPI + int rc; + struct privcmd_pcidev_get_gsi kdata; + + if (copy_from_user(&kdata, udata, sizeof(kdata))) + return -EFAULT; + + rc =3D pcistub_get_gsi_from_sbdf(kdata.sbdf); + if (rc < 0) + return rc; + + kdata.gsi =3D rc; + if (copy_to_user(udata, &kdata, sizeof(kdata))) + return -EFAULT; + + return 0; +#else + return -EINVAL; +#endif +} + #ifdef CONFIG_XEN_PRIVCMD_EVENTFD /* Irqfd support */ static struct workqueue_struct *irqfd_cleanup_wq; @@ -1543,6 +1569,10 @@ static long privcmd_ioctl(struct file *file, ret =3D privcmd_ioctl_ioeventfd(file, udata); break; =20 + case IOCTL_PRIVCMD_PCIDEV_GET_GSI: + ret =3D privcmd_ioctl_pcidev_get_gsi(file, udata); + break; + default: break; } diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/p= ci_stub.c index 8ce27333f54b..2ea8e4075adc 100644 --- a/drivers/xen/xen-pciback/pci_stub.c +++ b/drivers/xen/xen-pciback/pci_stub.c @@ -56,6 +56,9 @@ struct pcistub_device { =20 struct pci_dev *dev; struct xen_pcibk_device *pdev;/* non-NULL if struct pci_dev is in use */ +#ifdef CONFIG_XEN_ACPI + int gsi; +#endif }; =20 /* Access to pcistub_devices & seized_devices lists and the initialize_dev= ices @@ -88,6 +91,9 @@ static struct pcistub_device *pcistub_device_alloc(struct= pci_dev *dev) =20 kref_init(&psdev->kref); spin_lock_init(&psdev->lock); +#ifdef CONFIG_XEN_ACPI + psdev->gsi =3D -1; +#endif =20 return psdev; } @@ -220,6 +226,25 @@ static struct pci_dev *pcistub_device_get_pci_dev(stru= ct xen_pcibk_device *pdev, return pci_dev; } =20 +#ifdef CONFIG_XEN_PCIDEV_BACKEND +int pcistub_get_gsi_from_sbdf(unsigned int sbdf) +{ + struct pcistub_device *psdev; + int domain =3D (sbdf >> 16) & 0xffff; + int bus =3D PCI_BUS_NUM(sbdf); + int slot =3D PCI_SLOT(sbdf); + int func =3D PCI_FUNC(sbdf); + + psdev =3D pcistub_device_find(domain, bus, slot, func); + + if (!psdev) + return -ENODEV; + + return psdev->gsi; +} +EXPORT_SYMBOL_GPL(pcistub_get_gsi_from_sbdf); +#endif + struct pci_dev *pcistub_get_pci_dev_by_slot(struct xen_pcibk_device *pdev, int domain, int bus, int slot, int func) @@ -367,14 +392,20 @@ static int pcistub_match(struct pci_dev *dev) return found; } =20 -static int pcistub_init_device(struct pci_dev *dev) +static int pcistub_init_device(struct pcistub_device *psdev) { struct xen_pcibk_dev_data *dev_data; + struct pci_dev *dev; #ifdef CONFIG_XEN_ACPI int gsi, trigger, polarity; #endif int err =3D 0; =20 + if (!psdev) + return -EINVAL; + + dev =3D psdev->dev; + dev_dbg(&dev->dev, "initializing...\n"); =20 /* The PCI backend is not intended to be a module (or to work with @@ -452,6 +483,7 @@ static int pcistub_init_device(struct pci_dev *dev) err =3D xen_pvh_setup_gsi(gsi, trigger, polarity); if (err) goto config_release; + psdev->gsi =3D gsi; } #endif =20 @@ -494,7 +526,7 @@ static int __init pcistub_init_devices_late(void) =20 spin_unlock_irqrestore(&pcistub_devices_lock, flags); =20 - err =3D pcistub_init_device(psdev->dev); + err =3D pcistub_init_device(psdev); if (err) { dev_err(&psdev->dev->dev, "error %d initializing device\n", err); @@ -564,7 +596,7 @@ static int pcistub_seize(struct pci_dev *dev, spin_unlock_irqrestore(&pcistub_devices_lock, flags); =20 /* don't want irqs disabled when calling pcistub_init_device */ - err =3D pcistub_init_device(psdev->dev); + err =3D pcistub_init_device(psdev); =20 spin_lock_irqsave(&pcistub_devices_lock, flags); =20 diff --git a/include/uapi/xen/privcmd.h b/include/uapi/xen/privcmd.h index 8b8c5d1420fe..8e2c8fd44764 100644 --- a/include/uapi/xen/privcmd.h +++ b/include/uapi/xen/privcmd.h @@ -126,6 +126,11 @@ struct privcmd_ioeventfd { __u8 pad[2]; }; =20 +struct privcmd_pcidev_get_gsi { + __u32 sbdf; + __u32 gsi; +}; + /* * @cmd: IOCTL_PRIVCMD_HYPERCALL * @arg: &privcmd_hypercall_t @@ -157,5 +162,7 @@ struct privcmd_ioeventfd { _IOW('P', 8, struct privcmd_irqfd) #define IOCTL_PRIVCMD_IOEVENTFD \ _IOW('P', 9, struct privcmd_ioeventfd) +#define IOCTL_PRIVCMD_PCIDEV_GET_GSI \ + _IOC(_IOC_NONE, 'P', 10, sizeof(struct privcmd_pcidev_get_gsi)) =20 #endif /* __LINUX_PUBLIC_PRIVCMD_H__ */ diff --git a/include/xen/acpi.h b/include/xen/acpi.h index 3bcfe82d9078..393a73bfda24 100644 --- a/include/xen/acpi.h +++ b/include/xen/acpi.h @@ -91,4 +91,13 @@ static inline int xen_acpi_get_gsi_info(struct pci_dev *= dev, } #endif =20 +#ifdef CONFIG_XEN_PCIDEV_BACKEND +int pcistub_get_gsi_from_sbdf(unsigned int sbdf); +#else +static inline int pcistub_get_gsi_from_sbdf(unsigned int sbdf) +{ + return -1; +} +#endif + #endif /* _XEN_ACPI_H */ --=20 2.34.1