From patchwork Fri Nov 24 10:41:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13467509 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 5BFB1C61D97 for ; Fri, 24 Nov 2023 10:42:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.640461.998743 (Exim 4.92) (envelope-from ) id 1r6TdV-0004NV-LJ; Fri, 24 Nov 2023 10:42:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 640461.998743; Fri, 24 Nov 2023 10:42:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r6TdV-0004NO-Ia; Fri, 24 Nov 2023 10:42:13 +0000 Received: by outflank-mailman (input) for mailman id 640461; Fri, 24 Nov 2023 10:42:12 +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 1r6TdU-00044J-Nx for xen-devel@lists.xenproject.org; Fri, 24 Nov 2023 10:42:12 +0000 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on20608.outbound.protection.outlook.com [2a01:111:f400:7ea9::608]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1f2ff031-8ab6-11ee-98e2-6d05b1d4d9a1; Fri, 24 Nov 2023 11:42:12 +0100 (CET) Received: from DM6PR07CA0039.namprd07.prod.outlook.com (2603:10b6:5:74::16) by MN2PR12MB4223.namprd12.prod.outlook.com (2603:10b6:208:1d3::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.22; Fri, 24 Nov 2023 10:42:07 +0000 Received: from CY4PEPF0000EE3F.namprd03.prod.outlook.com (2603:10b6:5:74:cafe::3d) by DM6PR07CA0039.outlook.office365.com (2603:10b6:5:74::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.19 via Frontend Transport; Fri, 24 Nov 2023 10:42:07 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE3F.mail.protection.outlook.com (10.167.242.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7025.13 via Frontend Transport; Fri, 24 Nov 2023 10:42:07 +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.34; Fri, 24 Nov 2023 04:42:00 -0600 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: 1f2ff031-8ab6-11ee-98e2-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NsocfJreJb8/9aIvuBFnd0/DEaFNj3nJ9MMR9O2Chlk5WiwLEkEDe3CIR5NFlz1hkUJuO/RH5px+icwXBjLJFw3T2AKmQh+OE7TEdj0Bbs+d1nX0vM+ZioKEyaezJDkSNr5yXqY0TjihZjc8WstffTuSse2IlmBzjfiGo8NxCUBbRyUfwF9DGi5B9lUqYMqaE0/DUdlAsy8e1FEn7wxDYW9lUtYJpBXrQcvvkRTVrtoPDsOU3GoIzuiNGv1GYr45wsNL4rjhVsotVvBEF2Jo5E+Dn1G+2uhq5pV+ot63YxbJk1hqXmQn/G0espToH6tkk9iaGDh2yVg+JytoMPgbjA== 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=GhtwSm2oYJ6b4otDJUCImvCv/KA43CPhTpF6V9Sflpc=; b=UY28OZoRPbHbsmqZ/QFpVvEmf7lOhBoDpfDdaz0m+toceZQWRN97L8s+gG2EzktoqqsYDjv7wxw75t0SOAGJ08czeFG5qg9A3v/cS3BRV1kmvCvh7MffmTuA+MMDfEW+L8YnIxMSYNJC6zUVFC/siRVi7PFCZp8ufqnpldAH9V53UcT/QzSxybVEDbQJK6pNClBePMEW1GK2uLhOXNJAIFwJ2t7azZWdJhW7Cd3RVG9T4zC1fegbtkPHznqE0bWlYrjbuG62m2odaXbwrTkzYaUdHlfPvGpYl9VX+88snEzqSVBTFUW/IaNCvx1JdNv311g8mb7PB9KJlqcfGRusfA== 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=GhtwSm2oYJ6b4otDJUCImvCv/KA43CPhTpF6V9Sflpc=; b=CN13uWox9qX8B8vTAqjKH2Sp4aZdeUTboCFN8Wc0VWZQSVXd6d5Ofby8G3YAbAmlg/Dv4liWD+Spy56r1z/YtCoe7V5klhr+IV0CEQOs6qRO2PBB/2swXXJHrSfHixBlMnDeayyVAThubIKiDiqayMfAVLkTrE1AvB4bYyUcm20= 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: Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Anthony PERARD , Juergen Gross , "Stefano Stabellini" , CC: Stewart Hildebrand , Alex Deucher , Xenia Ragiadakou , Stefano Stabellini , Huang Rui , Honglei Huang , Julia Zhang , Jiqian Chen , Huang Rui Subject: [RFC XEN PATCH v2 1/3] xen/vpci: Clear all vpci status of device Date: Fri, 24 Nov 2023 18:41:34 +0800 Message-ID: <20231124104136.3263722-2-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231124104136.3263722-1-Jiqian.Chen@amd.com> References: <20231124104136.3263722-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: CY4PEPF0000EE3F:EE_|MN2PR12MB4223:EE_ X-MS-Office365-Filtering-Correlation-Id: 8a329ae5-16cc-4c5d-69b5-08dbecda0143 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jZX2ssXVxzVCtAp2pOHz1nqLUfud6sEbBXOit6RZ2y4yC0cJiq6hn6ygxt9+hrezbUa0ZEo4yrjR/Q/vNCK/4l9O0eDRKN5pwRargNsKs8bzI1BTIJgRagzG5ly8czKYAmyTZJL49QM1vKYoKStFXyHXvu8004LyADN1E/bXvSuhNLLTm/CFHDN6TDbaooOEQt0WW3bynMFY320lJ/jfgO/dzVDHifvAd6bVMzgF1P9SILd0RTFSdrm4B+k7oMQni68UNgkVZzOO2R/ZXVoBrfPmFf99nUMePPYm0gcPsz92I4f1BfUvuNUCysyKK4krPPN5KDnMkl47ODPEFa4K4TD+dDrDukA7qwdUTTtHmVf4k3z1jXt0dTk4Vexp9hLwZRlZpqhwfEiNz7JLdHkMxn7VRIdTmU/HXEI7dlrWKxCQOezEVmPQZLbT9PUkEBfCA7ixgcG/Eab9fv9eCIU9lz4BuFGxoq5KpIgK9E+H+VOm2P/VwOLIPexZa2ccc7hAslEIBwc0eZjdV+fcdv6jz0sIc9hce8w21dx2kzPFq2ujcAJZ5hSzAqooF793i9WTmXeEPykL1hpdp2GoEkNR+NxgAwQPAX7rqs9p5bqmvZQGXzRcCngwCQbkafMh1S6MY33/PJLsxBeALkcmVtqqZJBdtE20JdDTjXJBXW5TM5bYZ8xmfRojkH8OtnPJDZM4jBBhjlNfWLsmXT2soQugVOEFtaOQnSQwxg9qh4BvhvS5q5yhM6KjiJWWlraW8FIiGAfXA9igibahGdMBqfUOOA== 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)(4636009)(346002)(136003)(39860400002)(396003)(376002)(230922051799003)(82310400011)(1800799012)(186009)(451199024)(64100799003)(46966006)(40470700004)(36840700001)(2906002)(5660300002)(40480700001)(40460700003)(36860700001)(6666004)(36756003)(478600001)(86362001)(4326008)(8676002)(8936002)(41300700001)(356005)(81166007)(82740400003)(336012)(426003)(47076005)(2616005)(83380400001)(7696005)(316002)(54906003)(70586007)(110136005)(70206006)(1076003)(26005)(16526019)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Nov 2023 10:42:07.0184 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8a329ae5-16cc-4c5d-69b5-08dbecda0143 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: CY4PEPF0000EE3F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4223 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, this patch add new hypercall to clear all vpci device state. And when reset device happens on dom0 side, dom0 can call this hypercall to notify vpci. Signed-off-by: Jiqian Chen Signed-off-by: Huang Rui --- xen/arch/x86/hvm/hypercall.c | 1 + xen/drivers/passthrough/pci.c | 21 +++++++++++++++++++++ xen/drivers/pci/physdev.c | 14 ++++++++++++++ xen/drivers/vpci/vpci.c | 9 +++++++++ xen/include/public/physdev.h | 2 ++ xen/include/xen/pci.h | 1 + xen/include/xen/vpci.h | 6 ++++++ 7 files changed, 54 insertions(+) diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c index eeb73e1aa5..6ad5b4d5f1 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/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 04d00c7c37..f871715585 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -824,6 +824,27 @@ int pci_remove_device(u16 seg, u8 bus, u8 devfn) return ret; } +int pci_reset_device_state(u16 seg, u8 bus, u8 devfn) +{ + struct pci_dev *pdev; + int ret = -ENODEV; + + pcidevs_lock(); + + pdev = pci_get_pdev(NULL, PCI_SBDF(seg, bus, devfn)); + if ( !pdev ) + goto error; + + ret = vpci_reset_device_state(pdev); + if (ret) + printk(XENLOG_ERR "PCI reset device %pp state failed\n", &pdev->sbdf); + +error: + pcidevs_unlock(); + + return ret; +} + /* Caller should hold the pcidevs_lock */ static int deassign_device(struct domain *d, uint16_t seg, uint8_t bus, uint8_t devfn) diff --git a/xen/drivers/pci/physdev.c b/xen/drivers/pci/physdev.c index 42db3e6d13..cfdb545654 100644 --- a/xen/drivers/pci/physdev.c +++ b/xen/drivers/pci/physdev.c @@ -67,6 +67,20 @@ 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; + + if ( !is_pci_passthrough_enabled() ) + return -EOPNOTSUPP; + + ret = -EFAULT; + if ( copy_from_guest(&dev, arg, 1) != 0 ) + break; + + ret = pci_reset_device_state(dev.seg, dev.bus, dev.devfn); + break; + } + default: ret = -ENOSYS; break; diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 3bec9a4153..e9c3eb1cd6 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -103,6 +103,15 @@ int vpci_add_handlers(struct pci_dev *pdev) return rc; } + +int vpci_reset_device_state(struct pci_dev *pdev) +{ + ASSERT(pcidevs_locked()); + + vpci_remove_device(pdev); + return vpci_add_handlers(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 f0c0d4727c..4156948903 100644 --- a/xen/include/public/physdev.h +++ b/xen/include/public/physdev.h @@ -305,6 +305,8 @@ struct physdev_pci_device { typedef struct physdev_pci_device physdev_pci_device_t; DEFINE_XEN_GUEST_HANDLE(physdev_pci_device_t); +#define PHYSDEVOP_pci_device_state_reset 32 + #define PHYSDEVOP_DBGP_RESET_PREPARE 1 #define PHYSDEVOP_DBGP_RESET_DONE 2 diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index 50d7dfb2a2..a0c28c5e6c 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -186,6 +186,7 @@ const unsigned long *pci_get_ro_map(u16 seg); int pci_add_device(u16 seg, u8 bus, u8 devfn, const struct pci_dev_info *info, nodeid_t node); int pci_remove_device(u16 seg, u8 bus, u8 devfn); +int pci_reset_device_state(u16 seg, u8 bus, u8 devfn); int pci_ro_device(int seg, int bus, int devfn); int pci_hide_device(unsigned int seg, unsigned int bus, unsigned int devfn); struct pci_dev *pci_get_pdev(const struct domain *d, pci_sbdf_t sbdf); diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index d743d96a10..e2d6cd5fa3 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -30,6 +30,7 @@ int __must_check vpci_add_handlers(struct pci_dev *pdev); /* Remove all handlers and free vpci related structures. */ void vpci_remove_device(struct pci_dev *pdev); +int vpci_reset_device_state(struct pci_dev *pdev); /* Add/remove a register handler. */ int __must_check vpci_add_register(struct vpci *vpci, @@ -242,6 +243,11 @@ static inline int vpci_add_handlers(struct pci_dev *pdev) static inline void vpci_remove_device(struct pci_dev *pdev) { } +static inline int vpci_reset_device_state(struct pci_dev *pdev) +{ + return 0; +} + static inline void vpci_dump_msi(void) { } static inline uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, From patchwork Fri Nov 24 10:41:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13467512 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 6B843C61D97 for ; Fri, 24 Nov 2023 10:42:34 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.640467.998773 (Exim 4.92) (envelope-from ) id 1r6Tdi-0005PV-Mh; Fri, 24 Nov 2023 10:42:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 640467.998773; Fri, 24 Nov 2023 10:42:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r6Tdi-0005PJ-Jt; Fri, 24 Nov 2023 10:42:26 +0000 Received: by outflank-mailman (input) for mailman id 640467; Fri, 24 Nov 2023 10:42:25 +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 1r6Tdh-00044J-Kc for xen-devel@lists.xenproject.org; Fri, 24 Nov 2023 10:42:25 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20611.outbound.protection.outlook.com [2a01:111:f400:fe5a::611]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 26ce204a-8ab6-11ee-98e2-6d05b1d4d9a1; Fri, 24 Nov 2023 11:42:25 +0100 (CET) Received: from DM6PR07CA0054.namprd07.prod.outlook.com (2603:10b6:5:74::31) by MN2PR12MB4254.namprd12.prod.outlook.com (2603:10b6:208:1d0::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.21; Fri, 24 Nov 2023 10:42:19 +0000 Received: from CY4PEPF0000EE3F.namprd03.prod.outlook.com (2603:10b6:5:74:cafe::f4) by DM6PR07CA0054.outlook.office365.com (2603:10b6:5:74::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.20 via Frontend Transport; Fri, 24 Nov 2023 10:42:19 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE3F.mail.protection.outlook.com (10.167.242.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7025.13 via Frontend Transport; Fri, 24 Nov 2023 10:42:19 +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.34; Fri, 24 Nov 2023 04:42:04 -0600 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: 26ce204a-8ab6-11ee-98e2-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VGaOgSwxxQm/or+BI44ULByzxJAk5Eh4iExtCJfkqzUmYig+o7ynzicPK0Jw2ECQPuaYIr9Ftj2qr8AiCrQCCWmoRdizaptNlaj6KzYbKxhVYLHrCVrQpeIpQY/MGyx8bcO+Oml9iRmj+CAx+sTpFY8khPsFh3V0aLJtgIF7HM1qF1zgouPaUE2pE9Hl7I2Wzi93mzeHPCUy36mPEzqzlLszQKcFK5R4xnSk/h9nWvjHcOX7OeStJxy1/mOwArOy03Y/1KbVv26Moz0QH8QadhYhr+pg8zDc1D65hn3N91dXYpnox5TAo4qg98b40h066kCnMnRCv1JJ5reiMS8wdw== 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=z9hbAL4FWPfGgAGtUKX3DPgojoAEwTsd0FUOkaqhexU=; b=WrZ4QFP0FhJ0RvwmJ6BsmegM9C1TJ3wR8hNUiuzhru+fSfpIqlmVZdNHEmnzk2VfVIqYGlCRJVpdMP81jac282iyMXToQtqPrUaGV9uRtL/2q485lI5gai2HxmUWt9rQf2d4kKWATEHGQjZb2enISkbBrGnRcPPasU+/5aKZPQIGaHMa8ypxyrrHmAiBcappEx4+qfTR1oracvx7cUBFtjxURdUZAQB8rUZZDIHDLMcMgKYnXBbk+UVI9qEfR1QlFOJbbew8KYrTig42b8bzlX/PaMn6MhGv9YwGt9BsG7DY5lmf+3M3hdKHgPlt419zaZ6kOPMw9bpfjrRIdisGUw== 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=z9hbAL4FWPfGgAGtUKX3DPgojoAEwTsd0FUOkaqhexU=; b=Eqo7CNbaVgLsXxohpg3xuDxQd1Lw+fdLmZqgPT80naBcxa2Yq89DO31L/Jr0uhQeSobD6AmCMryBPQfMll6OR5JhWbU4IWRnIqr1ZKzAbjYNOKarL94BvX/MXMTDtQ+YCaYyQRLIpFz2Qc4Fbv0mlKU9imGX3MDytE89p6+Nais= 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: Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Anthony PERARD , Juergen Gross , "Stefano Stabellini" , CC: Stewart Hildebrand , Alex Deucher , Xenia Ragiadakou , Stefano Stabellini , Huang Rui , Honglei Huang , Julia Zhang , Jiqian Chen , Huang Rui Subject: [RFC XEN PATCH v2 2/3] x86/pvh: Open PHYSDEVOP_map_pirq for PVH dom0 Date: Fri, 24 Nov 2023 18:41:35 +0800 Message-ID: <20231124104136.3263722-3-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231124104136.3263722-1-Jiqian.Chen@amd.com> References: <20231124104136.3263722-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: CY4PEPF0000EE3F:EE_|MN2PR12MB4254:EE_ X-MS-Office365-Filtering-Correlation-Id: 6690d394-d83f-4179-5f91-08dbecda08b4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eRQJ47bDpkfGWdU+d13CEBGmsBd3430lptsrbg7tqpfekFzbFEV4F9QmJOMNiEfA9vwdmyj5IpYI2eVjn3+uaQS3WxNAHI2fjzf70IG428TwjVBJZ7JQXHsoRENXYx8gP1ZjJkgh5Eoo2JdFjM64UUNtnOpfwZLzO5ohpfNO8XgeoB/MU/AOWJ1nKat9OZbI0o3QROx+eL51HGhhe9YocWPLRNZDdbi2oKySJr2Jq3w3QriWb+8QgwZLiyxSDM+lD5pGZXP+gQTa3N34ruqfPIqAWPyAeCf21q99O8lWfJUIPxxSWnM7ITg2ipbu/iOEQ+k70Ykvuqdz0ZYJNVfGh8lT5/DcR4rsgaaWXz3gB3jHIx67YIzDYfKPBvHCy3q0ZyT6XqUh1sckciWBKrcFklCOz0COsKIEGN87r2toFRurddANPBNqp1/2ne6ZUqGdAFVeqgHeDOOtS2NEJAei4NvHQ8q5jRgqaveQ4Cx2SyOZmUYBl0YLPN0WOXMm8+m/L+CxtEuFMFR0o2lShkcsXqYKmh6/5we90oNMDjmEExD4pACDoMCn5hjQCITGMAxQ91lGZVrTjrITVRppN/eCNWqy6hDzahHscrvKN73Dvxj/i+qE46sBoBmkeR8gQzNFL/hCtMAJ5ZxaouXL0LgHGkrBS96xPE4QP9RWQREz6H82cYSndnVcIwY59t4gFxVPlZ8d2QCy38F7RCLQQap/PaMRmWT7kOWIb9Zma4YVQiuBIiSMb/7TsYsGQslB1s1yCqPjlCEHj5X+6WSA6OEK8g== 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)(4636009)(376002)(39860400002)(136003)(346002)(396003)(230922051799003)(186009)(451199024)(64100799003)(1800799012)(82310400011)(40470700004)(36840700001)(46966006)(316002)(70206006)(70586007)(54906003)(110136005)(40460700003)(82740400003)(2906002)(5660300002)(36756003)(356005)(81166007)(8676002)(8936002)(4326008)(26005)(16526019)(7696005)(86362001)(36860700001)(6666004)(336012)(426003)(1076003)(41300700001)(47076005)(478600001)(2616005)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Nov 2023 10:42:19.5027 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6690d394-d83f-4179-5f91-08dbecda08b4 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: CY4PEPF0000EE3F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4254 If we 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, I think we may need to allow PHYSDEVOP_map_pirq when currd is dom0 (at present dom0 is PVH). Signed-off-by: Jiqian Chen Signed-off-by: Huang Rui --- xen/arch/x86/hvm/hypercall.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c index 6ad5b4d5f1..f9c4a2243a 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: + if (is_hardware_domain(currd)) + break; case PHYSDEVOP_eoi: case PHYSDEVOP_irq_status_query: case PHYSDEVOP_get_free_pirq: From patchwork Fri Nov 24 10:41:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13467514 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 6681BC61DF4 for ; Fri, 24 Nov 2023 10:42:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.640472.998783 (Exim 4.92) (envelope-from ) id 1r6Tdn-0005tx-0q; Fri, 24 Nov 2023 10:42:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 640472.998783; Fri, 24 Nov 2023 10:42:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r6Tdm-0005tm-Sq; Fri, 24 Nov 2023 10:42:30 +0000 Received: by outflank-mailman (input) for mailman id 640472; Fri, 24 Nov 2023 10:42:29 +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 1r6Tdl-00050M-JU for xen-devel@lists.xenproject.org; Fri, 24 Nov 2023 10:42:29 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20628.outbound.protection.outlook.com [2a01:111:f400:fe5a::628]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 28b1b3d2-8ab6-11ee-9b0e-b553b5be7939; Fri, 24 Nov 2023 11:42:28 +0100 (CET) Received: from CYZPR10CA0023.namprd10.prod.outlook.com (2603:10b6:930:8a::16) by MW4PR12MB7288.namprd12.prod.outlook.com (2603:10b6:303:223::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.26; Fri, 24 Nov 2023 10:42:23 +0000 Received: from CY4PEPF0000EE3E.namprd03.prod.outlook.com (2603:10b6:930:8a:cafe::2b) by CYZPR10CA0023.outlook.office365.com (2603:10b6:930:8a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.21 via Frontend Transport; Fri, 24 Nov 2023 10:42:23 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE3E.mail.protection.outlook.com (10.167.242.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7025.12 via Frontend Transport; Fri, 24 Nov 2023 10:42: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.34; Fri, 24 Nov 2023 04:42:18 -0600 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: 28b1b3d2-8ab6-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FZmPU04rh3WjDn+Lz9y4l4uLaoTnTwMn0WZvoz/2a26ttsUrMz7/IQcf3cy7mnZo/B/QCgXzFBPcbzPD/m3eltsJbhPprB9eU6cfzk8lUlEVArojmwDday7lYkZ1XXviMUgd1Mk3lQt6cvJKYL4TzL6EEsXZShgF8ZGh080RmafzjHeVQ3xW1nXwnXb1lNrYiS8hZ11uCdhbFZ+NkbNvWAWL9A5ZpSeRBD1y31qmpkeSsnFPacqrKp12s2V0vpa8ROXYUEQ/YwuxMDoW1tbwcOfAPzb8AoRadj6OV0c6moUGo1POS6mdcwhilURg81Pvm8lvFFu+9NNiABEbLi1Luw== 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=JT9k6v3Ouj/9uRO3GuzjBHyy8hdEspun9TdFDzOpiAo=; b=d+zrMwjNBqj8g8ha/PNa6uTI8fJlbzv9IzJxIIVEbmlp+2LnBPO06JXRYsV3xksP6Dl9MFZFYg6jAjthFI2OE2LdLGldr9AUvUoJrc2KDxdseunCkWtMqNXUZpbdagzXxurhUskbohQOg04YL2lvwSQL/eWDkm4InwGIUQIzJNBfSsQbDIQTGWo5BauqH4R2w6GT1uy2SUC4TSSlBFYdnsKf5+8UDD3hX0IZ4cU2AHc5qXWqVbM7C6qeSBcCe27+4ufREzQA4iW3RgRMlJejxzc+NPUbRfnVv/MV1MweqB2VLJVcRSo6V3rUcc3atFVcjO+3zgIAbhVWtHIrfavCbA== 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=JT9k6v3Ouj/9uRO3GuzjBHyy8hdEspun9TdFDzOpiAo=; b=vWN6w/yCvubKA+7kTTzBq9OIZ4ORZdX9BRCzDBfHihqyiaPEcU3dJ6fXOnO29v1LM7VwQafpya+Er/SaMFq4PAswlGJPtM9LEl9f3A25nDlsx5yzZ8ZeAJ6jh1rBAEEasze5m1HmeEJsyPK1Bqkyv4AptdphuTCzagm8y5qkQrA= 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: Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Anthony PERARD , Juergen Gross , "Stefano Stabellini" , CC: Stewart Hildebrand , Alex Deucher , Xenia Ragiadakou , Stefano Stabellini , Huang Rui , Honglei Huang , Julia Zhang , Jiqian Chen , Huang Rui Subject: [RFC XEN PATCH v2 3/3] tools: Add new function to get gsi from irq Date: Fri, 24 Nov 2023 18:41:36 +0800 Message-ID: <20231124104136.3263722-4-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231124104136.3263722-1-Jiqian.Chen@amd.com> References: <20231124104136.3263722-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: CY4PEPF0000EE3E:EE_|MW4PR12MB7288:EE_ X-MS-Office365-Filtering-Correlation-Id: 29775db9-f6a3-4a8f-6ee7-08dbecda0ac0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u9nlbqm2ySNAzk0g3bVrtw5ufrGPGNl3yScyi6clff92PnhvGQDUCBdcX5BUVPK/V83fIRpTEBeUdWXzudg5lGDnaB70bNbr5PX/sONHPbGp2svJB7wP6X6kFCTBH+QUg2NUo5sbKoYsh8kqCyjiFKBf2iswLwUc8ndtgw1PRI2OhK8E8LV9hYygveFoHvqNQMFgUJVNRsoaOyIsfi8YxkHxaIh9v0HOChPXeMuCTOBN/sqHNcUHzVFjaAoDUq9x3x+0BUvJOkn4hz7F52yIVUB1ga2jQRIgWnuoYoRmiMW+BstulIp/DVu1Qb7VDd6GoVDog8lxt7UUQWvyRXnoZvWWl8aTGXq1xZTrGaLFWckKozILnAa2naa6Y6VuDxhN6pmmb47wfTLgZqhIDSVGYM/en5V6N1pHsejMDnwqSxTcqJjFCD567F6Eb4gZXZ5RCP+g9SNQUBvuVImoZ5izb85wOmYCy5L02Dy12Sf1lY/ijXm5CiV29tO3DsR6llDus1cisXZP1zy4e5N7WWYqThxp8ipXclW8fYcEgkQqADu1RDpCumWg/Bjx0UvZPETxhEgUjuFR7fRYjUdli7eHZle992THB9opnicmsHHLmmz6SWd52dJr6x2au5/YGG1hvqBISNxQXG8V+1JtQdMlPqL/rPuv3/QjdzN57bqaC5gXk50C6wuIReZ5uFM9PaASDlGQX88ZSvbrF+6m0FODMDZxD6NMRywFxycbSg0OLpfNh5PVbRmIw4jw7ojo71y+eRetJzNok++kjcmm66hsZw== 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)(4636009)(39860400002)(136003)(346002)(376002)(396003)(230922051799003)(186009)(64100799003)(1800799012)(82310400011)(451199024)(46966006)(40470700004)(36840700001)(40480700001)(16526019)(2616005)(7696005)(81166007)(356005)(47076005)(1076003)(110136005)(316002)(8676002)(36860700001)(8936002)(70586007)(54906003)(70206006)(26005)(426003)(6666004)(83380400001)(336012)(478600001)(82740400003)(86362001)(40460700003)(4326008)(41300700001)(5660300002)(36756003)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Nov 2023 10:42:22.9060 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 29775db9-f6a3-4a8f-6ee7-08dbecda0ac0 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: CY4PEPF0000EE3E.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7288 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 if you debug the kernel codes, you will find the irq number is alloced from small to large, but the applying gsi number is not, may gsi 38 comes before gsi 28, that causes the irq number is not equal with the gsi number. And when we passthrough a device, QEMU will use its gsi number to do mapping actions, see xen_pt_realize-> xc_physdev_map_pirq, but the gsi number is got from file /sys/bus/pci/devices/xxxx:xx:xx.x/irq in current code, so it will fail when mapping. And in current codes, there is no method to translate irq to gsi for userspace. For above purpose, this patch adds new function to get that translation. And then we can use the correct gsi number to do map_pirq. And call this function before xc_physdev_map_pirq Signed-off-by: Jiqian Chen Signed-off-by: Huang Rui --- 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 | 14 ++++++++++++++ tools/libs/call/private.h | 9 +++++++++ tools/libs/ctrl/xc_physdev.c | 4 ++++ tools/libs/light/libxl_pci.c | 1 + 9 files changed, 46 insertions(+) diff --git a/tools/include/xen-sys/Linux/privcmd.h b/tools/include/xen-sys/Linux/privcmd.h index bc60e8fd55..ba4b8c3054 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_irq { + __u32 irq; + __u32 gsi; +} privcmd_gsi_from_irq_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_IRQ \ + _IOC(_IOC_NONE, 'P', 10, sizeof(privcmd_gsi_from_irq_t)) #define IOCTL_PRIVCMD_UNIMPLEMENTED \ _IOC(_IOC_NONE, 'P', 0xFF, 0) diff --git a/tools/include/xencall.h b/tools/include/xencall.h index fc95ed0fe5..962cb45e1f 100644 --- a/tools/include/xencall.h +++ b/tools/include/xencall.h @@ -113,6 +113,8 @@ int xencall5(xencall_handle *xcall, unsigned int op, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5); +int xen_oscall_gsi_from_irq(xencall_handle *xcall, int irq); + /* Variant(s) of the above, as needed, returning "long" instead of "int". */ long xencall2L(xencall_handle *xcall, unsigned int op, uint64_t arg1, uint64_t arg2); diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 2ef8b4e054..2b9d55d2c6 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1641,6 +1641,8 @@ int xc_physdev_unmap_pirq(xc_interface *xch, uint32_t domid, int pirq); +int xc_physdev_gsi_from_irq(xc_interface *xch, int irq); + /* * LOGGING AND ERROR REPORTING */ diff --git a/tools/libs/call/core.c b/tools/libs/call/core.c index 02c4f8e1ae..6f79f3babd 100644 --- a/tools/libs/call/core.c +++ b/tools/libs/call/core.c @@ -173,6 +173,11 @@ int xencall5(xencall_handle *xcall, unsigned int op, return osdep_hypercall(xcall, &call); } +int xen_oscall_gsi_from_irq(xencall_handle *xcall, int irq) +{ + return osdep_oscall(xcall, irq); +} + /* * Local variables: * mode: C diff --git a/tools/libs/call/libxencall.map b/tools/libs/call/libxencall.map index d18a3174e9..6cde8eda05 100644 --- a/tools/libs/call/libxencall.map +++ b/tools/libs/call/libxencall.map @@ -10,6 +10,8 @@ VERS_1.0 { xencall4; xencall5; + xen_oscall_gsi_from_irq; + xencall_alloc_buffer; xencall_free_buffer; xencall_alloc_buffer_pages; diff --git a/tools/libs/call/linux.c b/tools/libs/call/linux.c index 6d588e6bea..5267bceabf 100644 --- a/tools/libs/call/linux.c +++ b/tools/libs/call/linux.c @@ -85,6 +85,20 @@ long osdep_hypercall(xencall_handle *xcall, privcmd_hypercall_t *hypercall) return ioctl(xcall->fd, IOCTL_PRIVCMD_HYPERCALL, hypercall); } +long osdep_oscall(xencall_handle *xcall, int irq) +{ + privcmd_gsi_from_irq_t gsi_irq = { + .irq = irq, + .gsi = -1, + }; + + if (ioctl(xcall->fd, IOCTL_PRIVCMD_GSI_FROM_IRQ, &gsi_irq)) { + return gsi_irq.irq; + } + + return gsi_irq.gsi; +} + static void *alloc_pages_bufdev(xencall_handle *xcall, size_t npages) { void *p; diff --git a/tools/libs/call/private.h b/tools/libs/call/private.h index 9c3aa432ef..01a1f5076a 100644 --- a/tools/libs/call/private.h +++ b/tools/libs/call/private.h @@ -57,6 +57,15 @@ int osdep_xencall_close(xencall_handle *xcall); long osdep_hypercall(xencall_handle *xcall, privcmd_hypercall_t *hypercall); +#if defined(__linux__) +long osdep_oscall(xencall_handle *xcall, int irq); +#else +static inline long osdep_oscall(xencall_handle *xcall, int irq) +{ + return irq; +} +#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 460a8e779c..4d3b138ebd 100644 --- a/tools/libs/ctrl/xc_physdev.c +++ b/tools/libs/ctrl/xc_physdev.c @@ -111,3 +111,7 @@ int xc_physdev_unmap_pirq(xc_interface *xch, return rc; } +int xc_physdev_gsi_from_irq(xc_interface *xch, int irq) +{ + return xen_oscall_gsi_from_irq(xch->xcall, irq); +} diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 96cb4da079..ba8803dab4 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -1486,6 +1486,7 @@ static void pci_add_dm_done(libxl__egc *egc, goto out_no_irq; } if ((fscanf(f, "%u", &irq) == 1) && irq) { + irq = xc_physdev_gsi_from_irq(ctx->xch, irq); r = xc_physdev_map_pirq(ctx->xch, domid, irq, &irq); if (r < 0) { LOGED(ERROR, domainid, "xc_physdev_map_pirq irq=%d (error=%d)",