From nobody Wed Dec 4 08:32:27 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=1727667871; cv=pass; d=zohomail.com; s=zohoarc; b=dQ3S1U9YabX7uVnTqajZYgkY0gPSCX/EF1Z7wdvZ3y2lKunIwAwwZukD04RK9a4jRKdgyA3uQwkIhV/3V7TVroC08xefRptPp6wblXq8WtgJFGqiLjKstLBdT1QMeBNERlUQTssL08FGfNM1TayuJG7mwbM1hQdu2nIA2eh/brg= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727667871; 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=O+E/4LTDdAPpk3VRH9HmbFsNt4PqAVxVThrYLen9wv0=; b=RqK4szmes2oh4xV+WN0hGd94QX2uccyouU3Oq5IpmxH9OmVxUE+OwFgs41BGAoxtu5HhrSruSopYTdujJ6YnUsgDXDnao8m2evUWfP2uKP0ilUNHEniuajrc0lSps3SwEyCWUVW/XgNJ8jaG9hS5RErKc+6uKx8axUkZJ592iqY= 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 1727667871537914.0443226197044; Sun, 29 Sep 2024 20:44:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.806958.1218093 (Exim 4.92) (envelope-from ) id 1sv7KG-0004Mj-Ey; Mon, 30 Sep 2024 03:43:56 +0000 Received: by outflank-mailman (output) from mailman id 806958.1218093; Mon, 30 Sep 2024 03:43:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sv7KG-0004Mb-CN; Mon, 30 Sep 2024 03:43:56 +0000 Received: by outflank-mailman (input) for mailman id 806958; Mon, 30 Sep 2024 03:43:55 +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 1sv7KF-0004MQ-OI for xen-devel@lists.xenproject.org; Mon, 30 Sep 2024 03:43:55 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20626.outbound.protection.outlook.com [2a01:111:f403:2415::626]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 363cf05e-7ede-11ef-a0ba-8be0dac302b0; Mon, 30 Sep 2024 05:43:54 +0200 (CEST) Received: from BL0PR05CA0010.namprd05.prod.outlook.com (2603:10b6:208:91::20) by LV8PR12MB9083.namprd12.prod.outlook.com (2603:10b6:408:18c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.26; Mon, 30 Sep 2024 03:43:48 +0000 Received: from BN2PEPF00004FBD.namprd04.prod.outlook.com (2603:10b6:208:91:cafe::e4) by BL0PR05CA0010.outlook.office365.com (2603:10b6:208:91::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.14 via Frontend Transport; Mon, 30 Sep 2024 03:43:48 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN2PEPF00004FBD.mail.protection.outlook.com (10.167.243.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Mon, 30 Sep 2024 03:43:48 +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; Sun, 29 Sep 2024 22:43:42 -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: 363cf05e-7ede-11ef-a0ba-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rpa0BdW2u0eDVa/PWy+kxcJJxmQpMdhdGHgboPgXjLVkVEp22CRyvp25vuwufff1C9WsNh5gn+ixShvWWKrsNk5Vg5I702cxEKMzGM9JRyZZUoY2c+9oh3VuQy9+EYhZelxPvyylcmJDSJ220CVPfZAWiLG0skzMs9zG4V/W3xDukO+jFR0nw0zigY03csIZh4065jpmXudH5/CArF37lp7n/JMByEOVIBP53sstLfDoHpa0UkP6WeJfTbW1ythJ28ytp1z6VGc6A60kHjfld+Me/WJslOMZEgCfsX0jdo+Yloge9Mzd+I6RedZwD8NrLbdX0sBWONRiskAwQcGIGA== 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=O+E/4LTDdAPpk3VRH9HmbFsNt4PqAVxVThrYLen9wv0=; b=JIVrsqUMsz5ja5/yIlRjxM6ZSQlBCmWXjzqBCt6rWhrrXxFQ/i0eGknahY0FDSsHrrD93kj7VFD+5dF39DAV1x5qzngSlVDv+zpaj/66zp/yUjHCc15JYxoYEE0/R6mrz6hmGrSdSsTuvf1TND6z6KWNNqmlKZWm2aHYlBy7fswIQQZDfgrw349fw5KDvH4+QKVAKpTvHgKvjgI6Z04SxwF9r+zqfwoxF/NL1lCKwrZgwl02yek31BsqktiAVne4lWradpifTdOafgzDkUzKpppo1r2dhhXv0S+t1vKPGUNWddJZYmJZJQRuqvxxVpyZrJNmXbWs1/lzNXBYp2wqsg== 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=O+E/4LTDdAPpk3VRH9HmbFsNt4PqAVxVThrYLen9wv0=; b=dBlQ5p0vIrO1605qLo10Zavo01XwasyGvn2zHmzW97eWFAt7WiPJo8k2cLuBhxEWFFLJ2r7prpVKbP6OcevtuhAf9jHYRI55CZ+X/S5gpvUXSaovA1nSX7FpP7deKGSDX0qbeLbi0YXJvY51eIk+pkSe8/kYurRaJpV1X/HSHtY= 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: CC: Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Julien Grall , Stefano Stabellini , Anthony PERARD , "Juergen Gross" , "Daniel P . Smith" , Jiqian Chen , Huang Rui Subject: [XEN PATCH v16 1/3] x86/irq: allow setting IRQ permissions from GSI instead of pIRQ Date: Mon, 30 Sep 2024 11:42:48 +0800 Message-ID: <20240930034250.2682265-2-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240930034250.2682265-1-Jiqian.Chen@amd.com> References: <20240930034250.2682265-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: BN2PEPF00004FBD:EE_|LV8PR12MB9083:EE_ X-MS-Office365-Filtering-Correlation-Id: c57dfba8-9e00-4837-707d-08dce10217c9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?eZBKTd1vpfklnL2GnVSUqsEFC11Fx+lvg19jwmwxfG8+es9ci1rh4owrVkYg?= =?us-ascii?Q?Ur1wRZ1Gcv0XWYAdquZ5S+lMNgAfuGN32fMt2oTe/JPOdFzMAUK8mmNkPWX/?= =?us-ascii?Q?hv/AuIjg026XviFiffBtn6X3ss3qDR2PtRa0ZbImU5BJ+RpLlYuDrTmliC/C?= =?us-ascii?Q?rrzFDjXJ6eLR6fVf/68ICet6jx9F2P060icThYpVUoY/4fq9wmGzlt95m6Y3?= =?us-ascii?Q?jFJ6a+VPLXOA3Sl3ZbAR/th/0tRR4FzUTDhdMFIHgaWSV54qpcGVKhELm06m?= =?us-ascii?Q?oQ8eG/i7yZbzTNUGzWgGWcA1p/z3iKhFTE/18tC8NPTaUodR0E6dze3Ma5Gs?= =?us-ascii?Q?ViDLYWJm3OMV5g4ND0ldk2GoScy7hX6DGk9Sd2SRdUYhDBl95Wf4mchmDLJ3?= =?us-ascii?Q?P0Du2TMvZy5GztZRqYYSxij/SNdjgPeBluf5qAvIuHLG80CvL5qby94qzu7o?= =?us-ascii?Q?Nt+lOISxXStHVCN0iC5yn+AEiPTqEuHJiYpEBwJG3KKQZPFeqB9F3gHHz1B3?= =?us-ascii?Q?v51JiRye+xurzeZwuqzDU/UrS+eYzw0dJJZ+43eDELESQ9KZs0vYtUvx8igM?= =?us-ascii?Q?wHqD0uhGdUXpHmrH9aG6rbK1ii5kcBsP/eHYOZJ763bBSv1BWAM+AfNHKLVQ?= =?us-ascii?Q?4p2DNbf1mdWsqwp7PFRa2mw9LKpV2y8YOMc3vSb6ZaXtBMtai3fxMITtnzmt?= =?us-ascii?Q?+mMwEekwnTDc4/zAWTMzZqyNE7R0k1AT7tTOVx8S7IedlnHtwZ8uvFbJJ5Zs?= =?us-ascii?Q?B0vUMHx+F2MJGtFPVRBvO/s3zDABKAcilFI4+HQQYkcMvoldQKtnUQlM+F0J?= =?us-ascii?Q?Xdlch5cUH7ZRczJhL513p4rdAIBqhAkjGOI1NnTlJua3HpdKK3swO58iqaR+?= =?us-ascii?Q?otbQyYP7sv8utOGT8SChRbLyzws2NRxwkI5KLJS70E/NlByVMCjYPewrdLHY?= =?us-ascii?Q?42Gs1BBLLDRDx8b+ku3VJETownphbZdHhfCRi6AbVy8dhwKgPn52of1B8IyW?= =?us-ascii?Q?g8SamXGdtwCEgz4lC+iogtcWT/n5l0BVns9scJNRyG8r6q2FWEc2svTz+z0f?= =?us-ascii?Q?CGcNFne2EzCuH4l49YRw1MtFN09L9pYjiRWJ4Vvix+hZyJE+T2uAIngFGJC1?= =?us-ascii?Q?QZAdn3TjSgihPn5pQAfM9d4L0HL9bqGp7n2BDvTM+8uLvHHJpqZd8cUMvghP?= =?us-ascii?Q?xlLESYEHhm45162vQCZFkRWbhcv9UmNNlVSkyCR9Oc8BzAoMRe+nIpoDKDE0?= =?us-ascii?Q?lwZAjpwrpunKYy8LjcuBoZOFIkjLPb3bwt0DFKneuZMb5eBu4LzmEa0y+LFJ?= =?us-ascii?Q?TpUpYp76bmcSk+23/ckd16P6iRkOxCEyvheT00O1lS6JvXYXNV6fj/1/8hcU?= =?us-ascii?Q?hXZfjXlL9zcODH9hg8j86rL4+KE4FlaVQJZgCGI1mWzf5CzuJnOMpR+Mo2Cu?= =?us-ascii?Q?SlP8F7Q3lMwEtbQ+dPRJ8f9JGDfdL0gD?= 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)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2024 03:43:48.4404 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c57dfba8-9e00-4837-707d-08dce10217c9 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: BN2PEPF00004FBD.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9083 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1727667872335116600 Content-Type: text/plain; charset="utf-8" Some domains are not aware of the pIRQ abstraction layer that maps interrupt sources into Xen space interrupt numbers. pIRQs values are only exposed to domains that have the option to route physical interrupts over event channels. This creates issues for PCI-passthrough from a PVH domain, as some of the passthrough related hypercalls use pIRQ as references to physical interrupts on the system. One of such interfaces is XEN_DOMCTL_irq_permission, used to grant or revoke access to interrupts, takes a pIRQ as the reference to the interrupt to be adjusted. Since PVH doesn't manage interrupts in terms of pIRQs, introduce a new hypercall that allows setting interrupt permissions based on GSI value rather than pIRQ. Note the GSI hypercall parameters is translated to an IRQ value (in case there are ACPI overrides) before doing the checks. Signed-off-by: Jiqian Chen Signed-off-by: Huang Rui Signed-off-by: Jiqian Chen Reviewed-by: Daniel P. Smith Acked-by: Jan Beulich --- v15->v16 changes: Change the code "ret =3D irq =3D gsi_2_irq(gsi);" to be MISRA compliant. Add Reviewed-by of Daniel P. Smith v13->v15 changes: Change to use the commit message wrote by Roger. Change the code comment from "Check all bits are zero except lowest bit" to= "Check only valid bits are set". Change the end return sentence of gsi_2_irq to "return irq ?: -EINVAL;" to = preserve the error code from apic_pin_2_gsi_irq(). v12->v13 changes: For struct xen_domctl_gsi_permission, rename "access_flag" to "flags", chan= ge its type from uint8_t to uint32_t, delete "pad", add XEN_DOMCTL_GSI_REVO= KE and XEN_DOMCTL_GSI_GRANT macros. Move "gsi > highest_gsi()" into function gsi_2_irq. Modify parameter gsi in function gsi_2_irq and mp_find_ioapic to unsigned i= nt type. Delete unnecessary spaces and brackets around "~XEN_DOMCTL_GSI_ACTION_MASK". Delete unnecessary goto statements and change to direct break. Add description in commit message to explain how gsi to irq isconverted. v11->v12 changes: Change nr_irqs_gsi to highest_gsi() to check gsi boundary, then need to rem= ove "__init" of highest_gsi function. Change the check of irq boundary from <0 to <=3D0, and remove unnecessary s= pace. Add #define XEN_DOMCTL_GSI_PERMISSION_MASK 1 to get lowest bit. v10->v11 changes: Extracted from patch#5 of v10 into a separate patch. Add non-zero judgment for other bits of allow_access. Delete unnecessary judgment "if ( is_pv_domain(currd) || has_pirq(currd) )". Change the error exit path identifier "out" to "gsi_permission_out". Use ARRAY_SIZE() instead of open coed. v9->v10 changes: Modified the commit message to further describe the purpose of adding XEN_D= OMCTL_gsi_permission. Added a check for all zeros in the padding field in XEN_DOMCTL_gsi_permissi= on, and used currd instead of current->domain. In the function gsi_2_irq, apic_pin_2_gsi_irq was used instead of the origi= nal new code, and error handling for irq0 was added. Deleted the extra spaces in the upper and lower lines of the struct xen_dom= ctl_gsi_permission definition. v8->v9 changes: Change the commit message to describe more why we need this new hypercall. Add comment above "if ( is_pv_domain(current->domain) || has_pirq(current->= domain) )" to explain why we need this check. Add gsi_2_irq to transform gsi to irq, instead of considering gsi =3D=3D ir= q. Add explicit padding to struct xen_domctl_gsi_permission. v5->v8 changes: Nothing. v4->v5 changes: New implementation to add new hypercall XEN_DOMCTL_gsi_permission to grant = gsi. --- xen/arch/x86/domctl.c | 32 ++++++++++++++++++++++++++++++ xen/arch/x86/include/asm/io_apic.h | 2 ++ xen/arch/x86/io_apic.c | 19 ++++++++++++++++++ xen/arch/x86/mpparse.c | 7 +++---- xen/include/public/domctl.h | 10 ++++++++++ xen/xsm/flask/hooks.c | 1 + 6 files changed, 67 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 68b5b46d1a83..d9e8252d74d4 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -36,6 +36,7 @@ #include #include #include +#include =20 static int update_domain_cpu_policy(struct domain *d, xen_domctl_cpu_policy_t *xdpc) @@ -237,6 +238,37 @@ long arch_do_domctl( break; } =20 + case XEN_DOMCTL_gsi_permission: + { + int irq; + unsigned int gsi =3D domctl->u.gsi_permission.gsi; + uint32_t flags =3D domctl->u.gsi_permission.flags; + + /* Check only valid bits are set */ + ret =3D -EINVAL; + if ( flags & ~XEN_DOMCTL_GSI_ACTION_MASK ) + break; + + irq =3D gsi_2_irq(gsi); + if ( irq <=3D 0 ) + { + ret =3D irq ?: -EACCES; + break; + } + + ret =3D -EPERM; + if ( !irq_access_permitted(currd, irq) || + xsm_irq_permission(XSM_HOOK, d, irq, flags) ) + break; + + if ( flags ) + ret =3D irq_permit_access(d, irq); + else + ret =3D irq_deny_access(d, irq); + + break; + } + case XEN_DOMCTL_getpageframeinfo3: { unsigned int num =3D domctl->u.getpageframeinfo3.num; diff --git a/xen/arch/x86/include/asm/io_apic.h b/xen/arch/x86/include/asm/= io_apic.h index 78268ea8f666..62456806c7af 100644 --- a/xen/arch/x86/include/asm/io_apic.h +++ b/xen/arch/x86/include/asm/io_apic.h @@ -213,5 +213,7 @@ unsigned highest_gsi(void); =20 int ioapic_guest_read( unsigned long physbase, unsigned int reg, u32 *pval= ); int ioapic_guest_write(unsigned long physbase, unsigned int reg, u32 val); +int mp_find_ioapic(unsigned int gsi); +int gsi_2_irq(unsigned int gsi); =20 #endif diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c index 772700584639..e40d2f7dbd75 100644 --- a/xen/arch/x86/io_apic.c +++ b/xen/arch/x86/io_apic.c @@ -955,6 +955,25 @@ static int pin_2_irq(int idx, int apic, int pin) return irq; } =20 +int gsi_2_irq(unsigned int gsi) +{ + int ioapic, irq; + unsigned int pin; + + if ( gsi > highest_gsi() ) + return -ERANGE; + + ioapic =3D mp_find_ioapic(gsi); + if ( ioapic < 0 ) + return -EINVAL; + + pin =3D gsi - io_apic_gsi_base(ioapic); + + irq =3D apic_pin_2_gsi_irq(ioapic, pin); + + return irq ?: -EINVAL; +} + static inline int IO_APIC_irq_trigger(int irq) { int apic, idx, pin; diff --git a/xen/arch/x86/mpparse.c b/xen/arch/x86/mpparse.c index 306d8ed97a83..e13b83bbe9dd 100644 --- a/xen/arch/x86/mpparse.c +++ b/xen/arch/x86/mpparse.c @@ -842,8 +842,7 @@ static struct mp_ioapic_routing { } mp_ioapic_routing[MAX_IO_APICS]; =20 =20 -static int mp_find_ioapic ( - int gsi) +int mp_find_ioapic(unsigned int gsi) { unsigned int i; =20 @@ -854,7 +853,7 @@ static int mp_find_ioapic ( return i; } =20 - printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi); + printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %u\n", gsi); =20 return -1; } @@ -915,7 +914,7 @@ void __init mp_register_ioapic ( return; } =20 -unsigned __init highest_gsi(void) +unsigned highest_gsi(void) { unsigned x, res =3D 0; for (x =3D 0; x < nr_ioapics; x++) diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 2a49fe46ce25..e1028fc524cf 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -464,6 +464,14 @@ struct xen_domctl_irq_permission { uint8_t pad[3]; }; =20 +/* XEN_DOMCTL_gsi_permission */ +struct xen_domctl_gsi_permission { + uint32_t gsi; +#define XEN_DOMCTL_GSI_REVOKE 0 +#define XEN_DOMCTL_GSI_GRANT 1 +#define XEN_DOMCTL_GSI_ACTION_MASK 1 + uint32_t flags; +}; =20 /* XEN_DOMCTL_iomem_permission */ struct xen_domctl_iomem_permission { @@ -1306,6 +1314,7 @@ struct xen_domctl { #define XEN_DOMCTL_get_paging_mempool_size 85 #define XEN_DOMCTL_set_paging_mempool_size 86 #define XEN_DOMCTL_dt_overlay 87 +#define XEN_DOMCTL_gsi_permission 88 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1328,6 +1337,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 278ad38c2af3..dfa23738cd8a 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -695,6 +695,7 @@ static int cf_check flask_domctl(struct domain *d, unsi= gned 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 /* --=20 2.34.1 From nobody Wed Dec 4 08:32:27 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=1727667869; cv=pass; d=zohomail.com; s=zohoarc; b=HvWxSR3Ej8/j1Gpf3zVNBodl26Gt3DnAj4tlrTEX+69wVR/CnZyZoF+wXusfh4LiA1OywzCVhR7vCwYXYm20iUDopuHNvm/9BYPhqsAoDojNRU0zWF2Q9/6FPtcpLlWMpoe3NdCD8Q46e/rxpjd96pf2XAEr3pIuhY68OYRIR00= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727667869; 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=/RuohG9icSgVUYVW6MN1en3ZCkZNi5BlBBb8+3ZcRWY=; b=d0+JQQRdnAvTrb5/zAUMW5WdNU/zUI/UWxWAjbM8iHg0GbfyOB+YdIYVTJ4Fn0yJgiOtXKL4DYWjJcGnNg2IrjVis0TIlzZjggn6DyhLHKp3OmReYLmkfjr7uydzrvEH3N0nEFzPQmZJCUqEgWImy2S7uP/y1j6YRWSUeL933rs= 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 1727667869385592.9339604772756; Sun, 29 Sep 2024 20:44:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.806960.1218113 (Exim 4.92) (envelope-from ) id 1sv7KJ-0004pL-1G; Mon, 30 Sep 2024 03:43:59 +0000 Received: by outflank-mailman (output) from mailman id 806960.1218113; Mon, 30 Sep 2024 03:43:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sv7KI-0004p9-UD; Mon, 30 Sep 2024 03:43:58 +0000 Received: by outflank-mailman (input) for mailman id 806960; Mon, 30 Sep 2024 03:43:58 +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 1sv7KI-0004MV-09 for xen-devel@lists.xenproject.org; Mon, 30 Sep 2024 03:43:58 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20629.outbound.protection.outlook.com [2a01:111:f403:2418::629]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 36096aeb-7ede-11ef-99a2-01e77a169b0f; Mon, 30 Sep 2024 05:43:53 +0200 (CEST) Received: from BL0PR05CA0005.namprd05.prod.outlook.com (2603:10b6:208:91::15) by PH7PR12MB7872.namprd12.prod.outlook.com (2603:10b6:510:27c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.25; Mon, 30 Sep 2024 03:43:48 +0000 Received: from BN2PEPF00004FBD.namprd04.prod.outlook.com (2603:10b6:208:91:cafe::36) by BL0PR05CA0005.outlook.office365.com (2603:10b6:208:91::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.13 via Frontend Transport; Mon, 30 Sep 2024 03:43:48 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN2PEPF00004FBD.mail.protection.outlook.com (10.167.243.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Mon, 30 Sep 2024 03:43:48 +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; Sun, 29 Sep 2024 22:43:45 -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: 36096aeb-7ede-11ef-99a2-01e77a169b0f ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VTTsR7Bw2tDis3VwPh3/BIgmUtuv0w3ra3Ls7w4GxF6SiMmCsCN7PwWGhCon5+cJZVYaQoDuD3KcU7Ln3dsd4ksTUzBV3FZD+t9Z8rAzAj+L8amIoM+plbsVxzeF9doHSKRoGu3GfinVNb0strx4d9DTO3BZMn+IcBy8u5JsGleFpBVBT9XceRl2DNOTQpsecVperV7FrAH/bNyN1soh9MqrS4ngLhgPUhYlkxX/OBRIcpHxfdQ3HHc9HQfBYYQgwJmwwPss5L5iDM9ELoiZvlVlQYZ71GCdeHN9EGFVv82rUR78Hdnr8MAOqtIhkeWvQnzi51kHBdOvO9bzJN2Exw== 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=/RuohG9icSgVUYVW6MN1en3ZCkZNi5BlBBb8+3ZcRWY=; b=Slbx+r/Vk3rKFz22Daa59lDxezJ7yR9btgTkGm6SPy9cMH+ddoyzqVThxOwhggWkXNfkAW7KBz5/N2S3lJg4jlfQyC3v5bqaryvyscptEzsP0gkm0XXdLmzx3lKl4MNsKUCm+ln0DEEFIBaiA23NUVqGYfTqud9Ay7IRc4Y6wsar6BlSEM+gOAEz5dSOLQSszHZmmCxWcxa5qjvdCwWor1ND3K/g3rTna39xjIz9QbX6sC9Y3AlR+z+4PVljxOYMrii1t8pSUXFj2eMx97FLZJ2rQPgdcrOePKfPrpKgy7D1Y8RFL97tyWAccJiSksRHS0qJK7IE5DF1LYN0G1SCHQ== 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=/RuohG9icSgVUYVW6MN1en3ZCkZNi5BlBBb8+3ZcRWY=; b=cagrb3oefKVPgNHX0plY99+EwUBLvdlJBUf8K/At/1kWlYbIBVUi6/+n1JSvktbnpFX/I027z4Nk6EW5gSP9iLaVWUeCVzG/F1608OkxqzJGDU39DWFqN5YJ3CdzQbO/wwn+NxACCHnfKVNk/xM+nQ9wkgaBLW97/ohZjrCsCTQ= 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: CC: Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Julien Grall , Stefano Stabellini , Anthony PERARD , "Juergen Gross" , "Daniel P . Smith" , Jiqian Chen , Huang Rui , "Anthony PERARD" Subject: [XEN PATCH v16 2/3] tools: Add new function to get gsi from dev Date: Mon, 30 Sep 2024 11:42:49 +0800 Message-ID: <20240930034250.2682265-3-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240930034250.2682265-1-Jiqian.Chen@amd.com> References: <20240930034250.2682265-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: BN2PEPF00004FBD:EE_|PH7PR12MB7872:EE_ X-MS-Office365-Filtering-Correlation-Id: 6a5ad7fb-4e47-419c-33d3-08dce10217ed X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?/mjMnCRR9NRiDvV/iu6zZuQfE+MUm1AJKd9KmUmKC5JW2R18+Tb+1AGVNpzW?= =?us-ascii?Q?nby0ugL9B0mah1U68AVeKREXWnWDmTcpV7w7NW8pVvQ3BEc3GstasDD8s4kc?= =?us-ascii?Q?AdvzkakS7MTh1GaS/fwaM86U4FTwfnTlO+5BicknaS0ZYKUxFH+xm3K7HIyW?= =?us-ascii?Q?d34dRV1Pd/OPZuEAEZrHns2sk9Zn+6ZEj3T+yV9wIy/u7G3WP0HYd7RQQbs4?= =?us-ascii?Q?LeCZ4pTei4uqmefqnybheTe1xP411uphRi0WlJrT24ySbZqoKBSVQWSMmg63?= =?us-ascii?Q?8YWVmDG0FAnw4SGJl6t/KOwkYFf94UgCiNmlhVAVwHvQ/TMb2dMEkp8/rGV2?= =?us-ascii?Q?VXqSbl+TCGuX6jS8P5F+UgHQXwO1dC7JeSalbp06vio2N5quCsVU2v52H6eG?= =?us-ascii?Q?xpGe62f5bpdYxRFPtmi1ar1+jZEkamUfdJL66QSD3j8GzPSLtVgvQ5v3jgzN?= =?us-ascii?Q?iEovnTZHzEodDiXLa6qCv/MtA9DkLr5zl3pgcj2w+gafd/tebPfPZUY3Jp5a?= =?us-ascii?Q?U8yJNhUT03da0YFXNZWfmBwQvCNxdH77wQaECeM49RkFpptULecVgoihdcIY?= =?us-ascii?Q?manR5Wtps9qBpjnCtsJZUOUcLYVAGQnZDRM2OJTLpm1lYSLyPQTHy94s+i/z?= =?us-ascii?Q?BaBzHDzudY10gMjZLYdku4ZGxglhQul2GlbnNnb/6wHWy4ZR9lWGzeH8NVU4?= =?us-ascii?Q?RFMDcZeISEJFO5A0LYSyXG7LKsew+zSp0W44g4WUUwBMCKvyDOk7r3x5dUvg?= =?us-ascii?Q?rIZoXcLmw5CHpzN9nwk6j6w+40nmwGfzaQORpSZMX6kAd5jNDpvZsHVOlrIN?= =?us-ascii?Q?Ls1f4WctJdMBGiJrUKjP9LuPpmYDbRHaI6pGA+S2hHIo9XuSp01gFUR0WaCh?= =?us-ascii?Q?KJoc9YRxs61CEPCrbtbB63pevqX69JfxIhy+S7Km0lMWGavZThZIeeI64q09?= =?us-ascii?Q?riKhGVKAL6gIUsC1ErrUX47rNcP09XSGzZ6mC427RfbFLfkTCXUfyMyffeJm?= =?us-ascii?Q?rK5a7n7nVH8n+MCN6Os2YIdp2Lm5EZ4Fx0L8/+04vM6Ccl4PcS4t5Majrgs/?= =?us-ascii?Q?jQVcLuQzYTcX1epKF5G1R1rMbVtMsikBnKsfHYqER2BxI5183nuHk8SX7lIz?= =?us-ascii?Q?Yu51IxcdhmOcuc6nIzvIbWtCPFp7/m3mSCbGhzZEkRDDSJT0ssGFgyOaafTJ?= =?us-ascii?Q?ptutdXFPGmBZ87SrMpwsvHgvftrLtpGZUK2kfTGaarbFaw9bSyq0ZAs4YckP?= =?us-ascii?Q?ZzYsV9XCe9h/ZIq/UTzBNeY7M+0alGDw8Ul8kXyrgjHPYJZ0Y3OhOxHe8HXL?= =?us-ascii?Q?FGfPIXDT95vjxrhyMPUI6cg0lDbbHnIRUYav+6GNJuNuksub1CvvwkT60rj+?= =?us-ascii?Q?CKadWZw=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)(82310400026)(36860700013)(1800799024)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2024 03:43:48.6748 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6a5ad7fb-4e47-419c-33d3-08dce10217ed 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: BN2PEPF00004FBD.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7872 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1727667870146116600 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 codes, there is no method to get gsi for userspace. For above purpose, add new function to get gsi, and the corresponding ioctl is implemented on linux kernel side. Signed-off-by: Jiqian Chen Signed-off-by: Huang Rui Signed-off-by: Chen Jiqian Reviewed-by: Anthony PERARD --- v15->v16 changes: No. And the dependent patches on kernel side were merged, so removed the RFC ta= g of this patch. v13->v15 changes: Add "Reviewed-by: Anthony PERARD " v12->v13 changes: Rename the function xc_physdev_gsi_from_pcidev to xc_pcidev_get_gsi to avoi= d confusion with physdev namesapce. Move the implementation of xc_pcidev_get_gsi into xc_linux.c. Directly use xencall_fd(xch->xcall) in the function xc_pcidev_get_gsi inste= ad of opening "privcmd". v11->v12 changes: Nothing. v10->v11 changes: Patch#4 of v10, directly open "/dev/xen/privcmd" in the function xc_physdev= _gsi_from_dev instead of adding unnecessary functions to libxencall. Change the type of gsi in the structure privcmd_gsi_from_dev from int to u3= 2. v9->v10 changes: Extract the implementation of xc_physdev_gsi_from_dev to be a new patch. --- tools/include/xen-sys/Linux/privcmd.h | 7 +++++++ tools/include/xenctrl.h | 2 ++ tools/libs/ctrl/xc_freebsd.c | 6 ++++++ tools/libs/ctrl/xc_linux.c | 20 ++++++++++++++++++++ tools/libs/ctrl/xc_minios.c | 6 ++++++ tools/libs/ctrl/xc_netbsd.c | 6 ++++++ tools/libs/ctrl/xc_solaris.c | 6 ++++++ 7 files changed, 53 insertions(+) diff --git a/tools/include/xen-sys/Linux/privcmd.h b/tools/include/xen-sys/= Linux/privcmd.h index bc60e8fd55eb..607dfa2287bc 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; =20 +typedef struct privcmd_pcidev_get_gsi { + __u32 sbdf; + __u32 gsi; +} privcmd_pcidev_get_gsi_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_PCIDEV_GET_GSI \ + _IOC(_IOC_NONE, 'P', 10, sizeof(privcmd_pcidev_get_gsi_t)) #define IOCTL_PRIVCMD_UNIMPLEMENTED \ _IOC(_IOC_NONE, 'P', 0xFF, 0) =20 diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 2c4608c09ab0..924f9a35f790 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1642,6 +1642,8 @@ int xc_physdev_unmap_pirq(xc_interface *xch, uint32_t domid, int pirq); =20 +int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf); + /* * LOGGING AND ERROR REPORTING */ diff --git a/tools/libs/ctrl/xc_freebsd.c b/tools/libs/ctrl/xc_freebsd.c index 9dd48a3a08bb..9019fc663361 100644 --- a/tools/libs/ctrl/xc_freebsd.c +++ b/tools/libs/ctrl/xc_freebsd.c @@ -60,6 +60,12 @@ void *xc_memalign(xc_interface *xch, size_t alignment, s= ize_t size) return ptr; } =20 +int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf) +{ + errno =3D ENOSYS; + return -1; +} + /* * Local variables: * mode: C diff --git a/tools/libs/ctrl/xc_linux.c b/tools/libs/ctrl/xc_linux.c index c67c71c08be3..92591e49a1c8 100644 --- a/tools/libs/ctrl/xc_linux.c +++ b/tools/libs/ctrl/xc_linux.c @@ -66,6 +66,26 @@ void *xc_memalign(xc_interface *xch, size_t alignment, s= ize_t size) return ptr; } =20 +int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf) +{ + int ret; + privcmd_pcidev_get_gsi_t dev_gsi =3D { + .sbdf =3D sbdf, + .gsi =3D 0, + }; + + ret =3D ioctl(xencall_fd(xch->xcall), + IOCTL_PRIVCMD_PCIDEV_GET_GSI, &dev_gsi); + + if (ret < 0) { + PERROR("Failed to get gsi from dev"); + } else { + ret =3D dev_gsi.gsi; + } + + return ret; +} + /* * Local variables: * mode: C diff --git a/tools/libs/ctrl/xc_minios.c b/tools/libs/ctrl/xc_minios.c index 3dea7a78a576..462af827b33c 100644 --- a/tools/libs/ctrl/xc_minios.c +++ b/tools/libs/ctrl/xc_minios.c @@ -47,6 +47,12 @@ void *xc_memalign(xc_interface *xch, size_t alignment, s= ize_t size) return memalign(alignment, size); } =20 +int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf) +{ + errno =3D ENOSYS; + return -1; +} + /* * Local variables: * mode: C diff --git a/tools/libs/ctrl/xc_netbsd.c b/tools/libs/ctrl/xc_netbsd.c index 31979937621e..1318d4d90608 100644 --- a/tools/libs/ctrl/xc_netbsd.c +++ b/tools/libs/ctrl/xc_netbsd.c @@ -63,6 +63,12 @@ void *xc_memalign(xc_interface *xch, size_t alignment, s= ize_t size) return valloc(size); } =20 +int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf) +{ + errno =3D ENOSYS; + return -1; +} + /* * Local variables: * mode: C diff --git a/tools/libs/ctrl/xc_solaris.c b/tools/libs/ctrl/xc_solaris.c index 5128f3f0f490..049e28d55ccd 100644 --- a/tools/libs/ctrl/xc_solaris.c +++ b/tools/libs/ctrl/xc_solaris.c @@ -32,6 +32,12 @@ void *xc_memalign(xc_interface *xch, size_t alignment, s= ize_t size) return memalign(alignment, size); } =20 +int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf) +{ + errno =3D ENOSYS; + return -1; +} + /* * Local variables: * mode: C --=20 2.34.1 From nobody Wed Dec 4 08:32:27 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=1727667867; cv=pass; d=zohomail.com; s=zohoarc; b=PNoiuKyNNQUs5M71XAqSPwK/tua4eRnVESh2Y+tUnJHKGFS51cp/Gw672/dkCHTfwqYPgqKHGDPb50VHPwO/vmDsYVgIgnPsWFpnPwXakAeBogP0LAShvyJsG2x2IJSIHfYGeomws+Ouvkjm27a8z67QTpzyPTSmk3HcIdvMPN0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727667867; 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=NLF41WJtSVPF+fX/Xak9jnw8Lh+HUu0aQgL/Ovafjck=; b=i4vTjEMxTfQ4kpDf8vQroaWdWH3jr7eCgyRDYT23jrKV/zlihZgIWPQTDV0JrRWhJNnW2AXuNH7OoFHXB8Re16SGyJXDbT1pDg4LVW8Vr32WACRQqc7kIZ0eUk2Lei6wE5q+nxITx7GiI5Z30aHee0jH+4rc2uG5OGZx5Qv5eNE= 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 1727667867275711.3579521147902; Sun, 29 Sep 2024 20:44:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.806961.1218123 (Exim 4.92) (envelope-from ) id 1sv7KO-00057H-7R; Mon, 30 Sep 2024 03:44:04 +0000 Received: by outflank-mailman (output) from mailman id 806961.1218123; Mon, 30 Sep 2024 03:44:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sv7KO-00057A-4R; Mon, 30 Sep 2024 03:44:04 +0000 Received: by outflank-mailman (input) for mailman id 806961; Mon, 30 Sep 2024 03:44:02 +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 1sv7KM-0004MV-F2 for xen-devel@lists.xenproject.org; Mon, 30 Sep 2024 03:44:02 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20607.outbound.protection.outlook.com [2a01:111:f403:2415::607]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 39fd9da1-7ede-11ef-99a2-01e77a169b0f; Mon, 30 Sep 2024 05:44:00 +0200 (CEST) Received: from BN9PR03CA0862.namprd03.prod.outlook.com (2603:10b6:408:13d::27) by MN2PR12MB4272.namprd12.prod.outlook.com (2603:10b6:208:1de::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.26; Mon, 30 Sep 2024 03:43:52 +0000 Received: from BN2PEPF00004FBA.namprd04.prod.outlook.com (2603:10b6:408:13d:cafe::58) by BN9PR03CA0862.outlook.office365.com (2603:10b6:408:13d::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.26 via Frontend Transport; Mon, 30 Sep 2024 03:43:51 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN2PEPF00004FBA.mail.protection.outlook.com (10.167.243.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Mon, 30 Sep 2024 03:43:51 +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; Sun, 29 Sep 2024 22:43:48 -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: 39fd9da1-7ede-11ef-99a2-01e77a169b0f ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BtYd+vED7dHBsaN+u7u5R/nTt2BZwfi4Nzk0i2L+ApKDCKuRKteuQ90w4e/LlnLTJtwHxczSBE0FsZ1cm3iMr1zzdzrYBsR87HG8CbcgMwmquDtRV35McNnL6hLmeUFAdKmggy7gyA2yMRJPzQzdEfOL+Q3/yfSnxv9pMNbHWu7awUW8TiNdFFR+JXiMfCbPcrHYBiBmv9zFZQChhPY0Btm59uGgRKWaoxhMOCWt9UnlcVWwpZ8FkrJCrKSLsHSUGZdpIg2yLq/RrhpzRsiYwGQ7HKoSEk7h+Qmf2BoTjxq8/hMV4bTggZtf/F1z3apGTNQlPECK1fwHl3AqtFhvWg== 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=NLF41WJtSVPF+fX/Xak9jnw8Lh+HUu0aQgL/Ovafjck=; b=JzoJ0AyeOwSdsSuqb08XqZ+I5R/SfHKMrC2OHxfHyEpAg/UBfmBVUGa1z2qdC9UlOtbSPSR+dHQ5B8WpLjTXaeVcn/aUIZCj2Y6+GciNe5fxtEni2HHB/8b9+f/29MVHyQuigusRx8QjKjBLaPoCOiY2B+Xy8YfnF5ZEyMPqRlCHVzpiiaVGsB7S5h2yGMVhaY9KMP+Yl/+V4MT43Q3N18tlGvHLsU39JXmeMW06tLcOhPA/5Gvq26V6z9EnXG3DJDTEpduuiBWfaTs55N5U12Xz+xB6wGVp3D4cfB4Kf/2/LEapG7qxMRQ4+dLUn7S2F9/y/kDSdx04fGVVq1JpwQ== 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=NLF41WJtSVPF+fX/Xak9jnw8Lh+HUu0aQgL/Ovafjck=; b=VPAnisSGwalCE3zjPN/W9fgZLvgzkCWQhiPX1IESioBdRLS9fO1H6+vzEiY1uENPDU/st+TepkOF0ckEBSBnudUb+ZsgxSzOidreb1wcdZeqrBzrxjoh5J6rPvwLZAfu5d+xmQc5et0Nzd/H6lNUB5y7AXfbhgjpnXdVKZIFBD8= 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: CC: Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Julien Grall , Stefano Stabellini , Anthony PERARD , "Juergen Gross" , "Daniel P . Smith" , Jiqian Chen , Huang Rui , "Anthony PERARD" Subject: [XEN PATCH v16 3/3] tools: Add new function to do PIRQ (un)map on PVH dom0 Date: Mon, 30 Sep 2024 11:42:50 +0800 Message-ID: <20240930034250.2682265-4-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240930034250.2682265-1-Jiqian.Chen@amd.com> References: <20240930034250.2682265-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: BN2PEPF00004FBA:EE_|MN2PR12MB4272:EE_ X-MS-Office365-Filtering-Correlation-Id: 309c01ad-f11e-4232-0040-08dce10219bc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?DXarSAUFHUDJ2dzVG0sFDK7CmgweGhxCbXjnq8dKVFXJrLIYDdoIwt/WBr95?= =?us-ascii?Q?WSiu76o0lw912S+D9hPXer9i3dRQ0+23NtOkh33doyjfSBwdoZkyU/s4Cn2B?= =?us-ascii?Q?wcL+K/YUmfC6kTY+GHjRbQEzDJAWJ68AZzUpkdTi8mYSSIls03aN3dxcRjYi?= =?us-ascii?Q?cQDY0mT2jqt2iY/qy0u7MPReqwaX1QcA8ioMv/yiuVeRF8LGbphEKlQrJZ5A?= =?us-ascii?Q?oaCkttDb/QnLv/bEOVUfH8bAq2ZR+4HR7aX+kvxoOd6wUi2EJK9NM7efhjiV?= =?us-ascii?Q?M/T77fX9Z7dwWDKpMmggQaLRRPP+IVuSvW+G3ph1+G5AJSeI5BBtX+TKAtD3?= =?us-ascii?Q?HGHK9DXhv3VPeD2Sqw+t/0bBcOOqZsHQKsV2H+jdB0L8gUJbldlR4S+ziFaD?= =?us-ascii?Q?hwh/oH+GqnFOmCOJUaNUjiqk53iIVHZ+l2f2hI4bBoNFEmaNCRbsvdGI+sMN?= =?us-ascii?Q?ftifnu0I2HXRpamw1nQV9KSbmeehUI4szK3WDKKrsu2SV8u7Q2n9SHteCX3Q?= =?us-ascii?Q?ZWCWq2XxDHLH/gPppd8K9XIz+YK3d7SQtWioL6KkjstWqjllQYtcnE4avK1i?= =?us-ascii?Q?Kzy+whQGKJHi+sxaMqN9zvUX08wY63jrBSsNXgcl+SlggjaQkBvZP3KM2mpf?= =?us-ascii?Q?13U/W5xG7bsmRV1S6PbprYdW8GLIwMImOkAB/c6TM8bzsmM9uRpWX/l+NMAT?= =?us-ascii?Q?r/5pfuS+g81i3Gbgly4DVhZFNXIh0VB9xBy77mO2bOZUM05f2a2qhQkXHxKU?= =?us-ascii?Q?B68cDax+gG2K6BbKpmLABqhUZLOCXOfXUeHp6YsMGq4M2HGAgz4sN7bOaDS3?= =?us-ascii?Q?mO0Ho+kHgaufETw88650FbsbfGBd3zIpnl8Q2/d9bBF3SLI+NK196N9VOHx6?= =?us-ascii?Q?Gwu2wmZj2kWbFpicFCvKX4I2MC4biun2lWuvC/Pkz2hzU95l1ZjIvpChSaBo?= =?us-ascii?Q?8kf06a6m3gxtJBcsc4+9eN2V9LGwAQemAocS9klDOLiVv4tkI7mtCBSeJ59+?= =?us-ascii?Q?QzL2WzZeE7fcCeOK+lEOGGVU6S/TyItw0loexnA5bY04UquJNivsZUGQFvio?= =?us-ascii?Q?OdJ8MKnmX7CityQ5wJCcPcG05Sqw0eCX4awHZ5tJk+is7t6h+DOlsQR0a6Q9?= =?us-ascii?Q?i977Hs4xypfMwIIWRu+VC7bgvtBtPMmOq04J8O9QOfVHTHzAceEHBKIFLCmV?= =?us-ascii?Q?q7oJvIuizqpoTuqf65vknJZT8u6ppb38x0NOQN3eS1u/YJwCrI85O3W2wAq3?= =?us-ascii?Q?sY4fdh2ab83mTFK6FyfMSn51Qdz3qgffwGtkljbuwFimlARTBI5945T9ledS?= =?us-ascii?Q?o7wbqqAD+du3xe7lIkmczM1sJu7Ir2to68rBOOn+pMyvgHmTeUu9NnoKibry?= =?us-ascii?Q?518YV4IlfCDNYpo1fB7THRav1ev5gXLfh/NwPAN8LA35XNfq8o0+E3Bu9A73?= =?us-ascii?Q?xu0/26qyyLg=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)(1800799024)(7416014)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2024 03:43:51.7078 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 309c01ad-f11e-4232-0040-08dce10219bc 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: BN2PEPF00004FBA.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4272 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1727667868210116600 Content-Type: text/plain; charset="utf-8" When dom0 is PVH, and passthrough a device to dumU, xl will use the gsi number of device to do a pirq mapping, see pci_add_dm_done->xc_physdev_map_pirq, but the gsi number is got from file /sys/bus/pci/devices//irq, that confuses irq and gsi, they are in different space and are not equal, so it will fail when mapping. To solve this issue, to get the real gsi and add a new function xc_physdev_map_pirq_gsi to get a free pirq for gsi. Note: why not use current function xc_physdev_map_pirq, because it doesn't support to allocate a free pirq, what's more, to prevent changing it and affecting its callers, so add xc_physdev_map_pirq_gsi. Besides, PVH dom0 doesn't have PIRQs flag, it doesn't do PHYSDEVOP_map_pirq for each gsi. So grant function callstack pci_add_dm_done->XEN_DOMCTL_irq_permission will fail at function domain_pirq_to_irq. And old hypercall XEN_DOMCTL_irq_permission requires passing in pirq, it is not suitable for PVH dom0 that doesn't have PIRQs to grant irq permission. To solve this issue, use the another hypercall XEN_DOMCTL_gsi_permission to grant the permission of irq( translate from gsi) to dumU when dom0 has no PIRQs. Signed-off-by: Jiqian Chen Signed-off-by: Huang Rui Signed-off-by: Chen Jiqian Reviewed-by: Anthony PERARD --- v15->v16 changes: Added Reviewed-by of Anthony PERARD. And the dependent patches on kernel side were merged, so removed the RFC ta= g of this patch. v13->v15 changes: Change the initialization way of "struct physdev_map_pirq map" in function = xc_physdev_map_pirq_gsi to be definition and set value directly. Change code from "rc =3D libxl__arch_local_domain_has_pirq_notion(gc); if (= !rc) {}" to "if (libxl__arch_local_domain_has_pirq_notion(gc) =3D=3D false)= {}" Modified some log prints codes. v12->v13 changes: Deleted patch #6 of v12, and added function xc_physdev_map_pirq_gsi to map = pirq for gsi. For functions that generate libxl error, changed the return value from -1 t= o ERROR_*. Instead of declaring "ctx", use the macro "CTX". Add the function libxl__arch_local_romain_ has_pirq_notion to determine if = there is a concept of pirq in the domain where xl is located. In the function libxl__arch_hvm_unmap_gsi, before unmap_pirq, use map_pirq = to obtain the pirq corresponding to gsi. v11->v12 changes: Nothing. v10->v11 changes: New patch Modification of the tools part of patches#4 and #5 of v10, use privcmd_gsi_= from_dev to get gsi, and use XEN_DOMCTL_gsi_permission to grant gsi. Change the hard-coded 0 to use LIBXL_TOOLSTACK_DOMID. Add libxl__arch_hvm_map_gsi to distinguish x86 related implementations. Add a list pcidev_pirq_list to record the relationship between sbdf and pir= q, which can be used to obtain the corresponding pirq when unmap PIRQ. --- tools/include/xenctrl.h | 10 ++++ tools/libs/ctrl/xc_domain.c | 15 +++++ tools/libs/ctrl/xc_physdev.c | 27 +++++++++ tools/libs/light/libxl_arch.h | 6 ++ tools/libs/light/libxl_arm.c | 15 +++++ tools/libs/light/libxl_pci.c | 110 ++++++++++++++++++++-------------- tools/libs/light/libxl_x86.c | 72 ++++++++++++++++++++++ 7 files changed, 210 insertions(+), 45 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 924f9a35f790..29617585c535 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1383,6 +1383,11 @@ int xc_domain_irq_permission(xc_interface *xch, uint32_t pirq, bool allow_access); =20 +int xc_domain_gsi_permission(xc_interface *xch, + uint32_t domid, + uint32_t gsi, + uint32_t flags); + int xc_domain_iomem_permission(xc_interface *xch, uint32_t domid, unsigned long first_mfn, @@ -1638,6 +1643,11 @@ int xc_physdev_map_pirq_msi(xc_interface *xch, int entry_nr, uint64_t table_base); =20 +int xc_physdev_map_pirq_gsi(xc_interface *xch, + uint32_t domid, + int gsi, + int *pirq); + int xc_physdev_unmap_pirq(xc_interface *xch, uint32_t domid, int pirq); diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c index f2d9d14b4d9f..e3538ec0ba80 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); } =20 +int xc_domain_gsi_permission(xc_interface *xch, + uint32_t domid, + uint32_t gsi, + uint32_t flags) +{ + struct xen_domctl domctl =3D { + .cmd =3D XEN_DOMCTL_gsi_permission, + .domain =3D domid, + .u.gsi_permission.gsi =3D gsi, + .u.gsi_permission.flags =3D flags, + }; + + 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/ctrl/xc_physdev.c b/tools/libs/ctrl/xc_physdev.c index 460a8e779ce8..25e686d7b389 100644 --- a/tools/libs/ctrl/xc_physdev.c +++ b/tools/libs/ctrl/xc_physdev.c @@ -95,6 +95,33 @@ int xc_physdev_map_pirq_msi(xc_interface *xch, return rc; } =20 +int xc_physdev_map_pirq_gsi(xc_interface *xch, + uint32_t domid, + int gsi, + int *pirq) +{ + int rc; + struct physdev_map_pirq map =3D { + .domid =3D domid, + .type =3D MAP_PIRQ_TYPE_GSI, + .index =3D gsi, + }; + + if ( !pirq ) + { + errno =3D EINVAL; + return -1; + } + map.pirq =3D *pirq; + + rc =3D do_physdev_op(xch, PHYSDEVOP_map_pirq, &map, sizeof(map)); + + if ( !rc ) + *pirq =3D map.pirq; + + return rc; +} + int xc_physdev_unmap_pirq(xc_interface *xch, uint32_t domid, int pirq) diff --git a/tools/libs/light/libxl_arch.h b/tools/libs/light/libxl_arch.h index f88f11d6de1d..c8ef52ddbe7f 100644 --- a/tools/libs/light/libxl_arch.h +++ b/tools/libs/light/libxl_arch.h @@ -91,6 +91,12 @@ void libxl__arch_update_domain_config(libxl__gc *gc, libxl_domain_config *dst, const libxl_domain_config *src); =20 +_hidden +int libxl__arch_hvm_map_gsi(libxl__gc *gc, uint32_t sbdf, uint32_t domid); +_hidden +int libxl__arch_hvm_unmap_gsi(libxl__gc *gc, uint32_t sbdf, uint32_t domid= ); +_hidden +bool libxl__arch_local_domain_has_pirq_notion(libxl__gc *gc); #if defined(__i386__) || defined(__x86_64__) =20 #define LAPIC_BASE_ADDRESS 0xfee00000 diff --git a/tools/libs/light/libxl_arm.c b/tools/libs/light/libxl_arm.c index a4029e3ac810..5a9db5e85f6f 100644 --- a/tools/libs/light/libxl_arm.c +++ b/tools/libs/light/libxl_arm.c @@ -1774,6 +1774,21 @@ void libxl__arch_update_domain_config(libxl__gc *gc, { } =20 +int libxl__arch_hvm_map_gsi(libxl__gc *gc, uint32_t sbdf, uint32_t domid) +{ + return ERROR_INVAL; +} + +int libxl__arch_hvm_unmap_gsi(libxl__gc *gc, uint32_t sbdf, uint32_t domid) +{ + return ERROR_INVAL; +} + +bool libxl__arch_local_domain_has_pirq_notion(libxl__gc *gc) +{ + return true; +} + /* * Local variables: * mode: C diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 96cb4da0794e..8ef6a7b5fe3a 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -17,6 +17,7 @@ #include "libxl_osdeps.h" /* must come before any other headers */ =20 #include "libxl_internal.h" +#include "libxl_arch.h" =20 #define PCI_BDF "%04x:%02x:%02x.%01x" #define PCI_BDF_SHORT "%02x:%02x.%01x" @@ -1478,32 +1479,42 @@ static void pci_add_dm_done(libxl__egc *egc, fclose(f); if (!pci_supp_legacy_irq()) goto out_no_irq; - sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domain, - pci->bus, pci->dev, pci->func); - f =3D fopen(sysfs_path, "r"); - if (f =3D=3D NULL) { - LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path); - goto out_no_irq; - } - if ((fscanf(f, "%u", &irq) =3D=3D 1) && irq) { - r =3D xc_physdev_map_pirq(ctx->xch, domid, irq, &irq); - if (r < 0) { - LOGED(ERROR, domainid, "xc_physdev_map_pirq irq=3D%d (error=3D= %d)", - irq, r); - fclose(f); - rc =3D ERROR_FAIL; + + /* When dom0 is PVH, should use gsi to map pirq and grant permission */ + if (libxl__arch_local_domain_has_pirq_notion(gc) =3D=3D false) { + rc =3D libxl__arch_hvm_map_gsi(gc, pci_encode_bdf(pci), domid); + if (rc) { + LOGD(ERROR, domainid, "libxl__arch_hvm_map_gsi failed"); goto out; } - r =3D xc_domain_irq_permission(ctx->xch, domid, irq, 1); - if (r < 0) { - LOGED(ERROR, domainid, - "xc_domain_irq_permission irq=3D%d (error=3D%d)", irq, r= ); - fclose(f); - rc =3D ERROR_FAIL; - goto out; + } else { + sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domai= n, + pci->bus, pci->dev, pci->func); + f =3D fopen(sysfs_path, "r"); + if (f =3D=3D NULL) { + LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path); + goto out_no_irq; + } + if ((fscanf(f, "%u", &irq) =3D=3D 1) && irq) { + r =3D xc_physdev_map_pirq(ctx->xch, domid, irq, &irq); + if (r < 0) { + LOGED(ERROR, domainid, "xc_physdev_map_pirq irq=3D%d (erro= r=3D%d)", + irq, r); + fclose(f); + rc =3D ERROR_FAIL; + goto out; + } + r =3D xc_domain_irq_permission(ctx->xch, domid, irq, 1); + if (r < 0) { + LOGED(ERROR, domainid, + "xc_domain_irq_permission irq=3D%d (error=3D%d)", irq,= r); + fclose(f); + rc =3D ERROR_FAIL; + goto out; + } } + fclose(f); } - fclose(f); =20 /* Don't restrict writes to the PCI config space from this VM */ if (pci->permissive) { @@ -2229,33 +2240,42 @@ skip_bar: if (!pci_supp_legacy_irq()) goto skip_legacy_irq; =20 - sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domain, - pci->bus, pci->dev, pci->func); - - f =3D fopen(sysfs_path, "r"); - if (f =3D=3D NULL) { - LOGED(ERROR, domid, "Couldn't open %s", sysfs_path); - goto skip_legacy_irq; - } + /* When dom0 is PVH, should use gsi to unmap pirq and deny permission = */ + if (libxl__arch_local_domain_has_pirq_notion(gc) =3D=3D false) { + rc =3D libxl__arch_hvm_unmap_gsi(gc, pci_encode_bdf(pci), domid); + if (rc) { + LOGD(ERROR, domid, "libxl__arch_hvm_unmap_gsi failed"); + goto out; + } + } else { + sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domai= n, + pci->bus, pci->dev, pci->func); =20 - if ((fscanf(f, "%u", &irq) =3D=3D 1) && irq) { - rc =3D xc_physdev_unmap_pirq(ctx->xch, domid, irq); - if (rc < 0) { - /* - * QEMU may have already unmapped the IRQ. So the error - * may be spurious. For now, still print an error message as - * it is not easy to distinguished between valid and - * spurious error. - */ - LOGED(ERROR, domid, "xc_physdev_unmap_pirq irq=3D%d", irq); + f =3D fopen(sysfs_path, "r"); + if (f =3D=3D NULL) { + LOGED(ERROR, domid, "Couldn't open %s", sysfs_path); + goto skip_legacy_irq; } - rc =3D xc_domain_irq_permission(ctx->xch, domid, irq, 0); - if (rc < 0) { - LOGED(ERROR, domid, "xc_domain_irq_permission irq=3D%d", irq); + + if ((fscanf(f, "%u", &irq) =3D=3D 1) && irq) { + rc =3D xc_physdev_unmap_pirq(ctx->xch, domid, irq); + if (rc < 0) { + /* + * QEMU may have already unmapped the IRQ. So the error + * may be spurious. For now, still print an error message = as + * it is not easy to distinguished between valid and + * spurious error. + */ + LOGED(ERROR, domid, "xc_physdev_unmap_pirq irq=3D%d", irq); + } + rc =3D xc_domain_irq_permission(ctx->xch, domid, irq, 0); + if (rc < 0) { + LOGED(ERROR, domid, "xc_domain_irq_permission irq=3D%d", i= rq); + } } - } =20 - fclose(f); + fclose(f); + } =20 skip_legacy_irq: =20 diff --git a/tools/libs/light/libxl_x86.c b/tools/libs/light/libxl_x86.c index 60643d6f5376..a3164a3077fe 100644 --- a/tools/libs/light/libxl_x86.c +++ b/tools/libs/light/libxl_x86.c @@ -879,6 +879,78 @@ void libxl__arch_update_domain_config(libxl__gc *gc, libxl_defbool_val(src->b_info.u.hvm.pirq)= ); } =20 +bool libxl__arch_local_domain_has_pirq_notion(libxl__gc *gc) +{ + int r; + xc_domaininfo_t info; + + r =3D xc_domain_getinfo_single(CTX->xch, LIBXL_TOOLSTACK_DOMID, &info); + if (r =3D=3D 0) { + if (!(info.flags & XEN_DOMINF_hvm_guest) || + (info.arch_config.emulation_flags & XEN_X86_EMU_USE_PIRQ)) + return true; + } else { + LOGE(ERROR, "getdomaininfo failed ret=3D%d", r); + } + + return false; +} + +int libxl__arch_hvm_map_gsi(libxl__gc *gc, uint32_t sbdf, uint32_t domid) +{ + int pirq =3D -1, gsi, r; + + gsi =3D xc_pcidev_get_gsi(CTX->xch, sbdf); + if (gsi < 0) { + return ERROR_FAIL; + } + + r =3D xc_physdev_map_pirq_gsi(CTX->xch, domid, gsi, &pirq); + if (r < 0) { + LOGED(ERROR, domid, "xc_physdev_map_pirq_gsi gsi=3D%d", gsi); + return ERROR_FAIL; + } + + r =3D xc_domain_gsi_permission(CTX->xch, domid, gsi, XEN_DOMCTL_GSI_GR= ANT); + if (r < 0) { + LOGED(ERROR, domid, "xc_domain_gsi_permission gsi=3D%d", gsi); + return ERROR_FAIL; + } + + return 0; +} + +int libxl__arch_hvm_unmap_gsi(libxl__gc *gc, uint32_t sbdf, uint32_t domid) +{ + int pirq =3D -1, gsi, r; + + gsi =3D xc_pcidev_get_gsi(CTX->xch, sbdf); + if (gsi < 0) { + return ERROR_FAIL; + } + + /* Before unmapping, use mapping to get the already mapped pirq first = */ + r =3D xc_physdev_map_pirq_gsi(CTX->xch, domid, gsi, &pirq); + if (r < 0) { + LOGED(ERROR, domid, "xc_physdev_map_pirq_gsi gsi=3D%d", gsi); + return ERROR_FAIL; + } + + r =3D xc_physdev_unmap_pirq(CTX->xch, domid, pirq); + if (r < 0) { + LOGED(ERROR, domid, "xc_physdev_unmap_pirq gsi=3D%d", gsi); + return ERROR_FAIL; + } + + r =3D xc_domain_gsi_permission(CTX->xch, domid, gsi, XEN_DOMCTL_GSI_RE= VOKE); + if (r < 0) { + LOGED(ERROR, domid, "xc_domain_gsi_permission gsi=3D%d", gsi); + return ERROR_FAIL; + } + + return 0; +} + /* * Local variables: * mode: C --=20 2.34.1