From patchwork Fri Apr 19 03:53:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13635648 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 B9669C41513 for ; Fri, 19 Apr 2024 03:54:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.708682.1107732 (Exim 4.92) (envelope-from ) id 1rxfKc-0002HW-Ge; Fri, 19 Apr 2024 03:54:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 708682.1107732; Fri, 19 Apr 2024 03:54:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rxfKc-0002HD-Cl; Fri, 19 Apr 2024 03:54:34 +0000 Received: by outflank-mailman (input) for mailman id 708682; Fri, 19 Apr 2024 03:54:32 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rxfKa-0001xW-PW for xen-devel@lists.xenproject.org; Fri, 19 Apr 2024 03:54:32 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20601.outbound.protection.outlook.com [2a01:111:f403:2009::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 86fada77-fe00-11ee-b909-491648fe20b8; Fri, 19 Apr 2024 05:54:32 +0200 (CEST) Received: from CH5P223CA0003.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:1f3::19) by SA1PR12MB6797.namprd12.prod.outlook.com (2603:10b6:806:259::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.37; Fri, 19 Apr 2024 03:54:29 +0000 Received: from CH2PEPF0000014A.namprd02.prod.outlook.com (2603:10b6:610:1f3:cafe::1d) by CH5P223CA0003.outlook.office365.com (2603:10b6:610:1f3::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.30 via Frontend Transport; Fri, 19 Apr 2024 03:54:28 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CH2PEPF0000014A.mail.protection.outlook.com (10.167.244.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7452.22 via Frontend Transport; Fri, 19 Apr 2024 03:54:28 +0000 Received: from cjq-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 18 Apr 2024 22:54:24 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 86fada77-fe00-11ee-b909-491648fe20b8 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pj+AfPkUWWBncosJbyimhuLLuK/Pfztvz6j79HwaLgG9OCoqZ19MQySQNhXUyu3DPgU2BPswKgW+svPv1iC9GkhNiE76mW+XEKi1jmG0mTvi4SKz/7EBXiYNRCKV7IjsYgCceLU+nuLghlTOl/7YJWDafF1mL6H59RD2w+oZAv5d0lgOyOFwUqWyWCQTzKc7pKg0+Yw/NuH78rx5IIAM9ODUBaj0aBSnu6p4sL0u+QMSKvAuh77i5X4EX0aRc8/S+tyILKg8oir7IV5NPMyuY30+bY8jfBDmM53falS+ligKAWdU+ZeiE2KK4RJLrDOe0clj5l9prCHM0dytUgkmsQ== 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=BWMKhG5lVTeKf+NSXNTQ2LT4bcOahI5fL1ibq4Lk0AQ=; b=edTiBj/Lvit3XD6tOxLu288Do9uY6sq10PosakILlmswGkE2UEQv1Bjytqnbz7H4NCkEpQKME80dAXaizQrE0J+txvjkYBBMjGAgXgE8aq1DCYj2HB/8D3wqv+4fAcQ1JHXGeV7UZejd7pjIMRvsx21HNS3WkUqIEknhT7myjKW2DKb4LfinGbBqnVhGn8EYbmOq6OOf6toMHpvCcz4sqSdsPlzX6XtZR3DbqnaO8N/CWBvjT84Uya57ZoQ/3z0bFYERwnjomybZYVtwWMBnntYofr/pwPDkilwW8wQ/gE4L7SK+9jJbD3AY/GQ6QiuTfmYa9U4jjlvgLb7AewuOsQ== 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=BWMKhG5lVTeKf+NSXNTQ2LT4bcOahI5fL1ibq4Lk0AQ=; b=Wf+LitCf2Fy48R9gVxkIH4/CgYrOss9EidCXgm2bouXjr0Qv6Maa7NmNU4UYQA5lHGls3vMLY6EnuAJAnL75r2wyAB1LrPlau5Ci/FQarGXLrtXs1N6MHnYfzTAgfYaEvNiWtA0yoI5Ajm1nahMJaWMF8kcLvdx9slXUdY/6Nbg= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Jiqian Chen To: CC: Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini , Anthony PERARD , "Juergen Gross" , "Daniel P . Smith" , Stewart Hildebrand , Huang Rui , Jiqian Chen , Huang Rui Subject: [XEN PATCH v7 2/5] x86/pvh: Allow (un)map_pirq when dom0 is PVH Date: Fri, 19 Apr 2024 11:53:37 +0800 Message-ID: <20240419035340.608833-3-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240419035340.608833-1-Jiqian.Chen@amd.com> References: <20240419035340.608833-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000014A:EE_|SA1PR12MB6797:EE_ X-MS-Office365-Filtering-Correlation-Id: 44055d54-b656-42a9-3868-08dc6024696d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZUuJruOBAT3DzK9xSG9b0d6lyFL/wV6b5/tLZfHez7v3RCfu4bhv9JYGg7bacrggzs5E+XlIlI7RTP0XyNSdtS/jMvRhIbc8Ht//yJg/Re7v3BQjMqqDBxg+NyFNMcrD7wzBB2FLxmNODnQabyEVZm6/6kh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1BCC2/EX04RWVt6VJ2bYIKISF+4H4x9TtiQtbMzRjccB/cb7/NBxZpph/L+ulQ21BK6Bh1aW29WGwcWOVINdxsxaQHNRm6qX/VHljOq/A493EzG2D1iEFwQOexasjMMUzEtVWffcb5Ja9+h4ojQQpDP5tI/v+DTsSi9xab2pq541sGr X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(7416005)(376005)(36860700004)(1800799015)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2024 03:54:28.2997 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 44055d54-b656-42a9-3868-08dc6024696d 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: CH2PEPF0000014A.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6797 If run Xen with PVH dom0 and hvm domU, hvm will map a pirq for a passthrough device by using gsi, see xen_pt_realize->xc_physdev_map_pirq and pci_add_dm_done->xc_physdev_map_pirq. Then xc_physdev_map_pirq will call into Xen, but in hvm_physdev_op, PHYSDEVOP_map_pirq is not allowed because currd is PVH dom0 and PVH has no X86_EMU_USE_PIRQ flag, it will fail at has_pirq check. So, allow PHYSDEVOP_map_pirq when dom0 is PVH and also allow PHYSDEVOP_unmap_pirq for the failed path to unmap pirq. And add a new check to prevent self map when caller has no PIRQ flag. Signed-off-by: Huang Rui Signed-off-by: Jiqian Chen Reviewed-by: Stefano Stabellini --- xen/arch/x86/hvm/hypercall.c | 2 ++ xen/arch/x86/physdev.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c index 56fbb69ab201..d49fb8b548a3 100644 --- a/xen/arch/x86/hvm/hypercall.c +++ b/xen/arch/x86/hvm/hypercall.c @@ -74,6 +74,8 @@ long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { case PHYSDEVOP_map_pirq: case PHYSDEVOP_unmap_pirq: + break; + case PHYSDEVOP_eoi: case PHYSDEVOP_irq_status_query: case PHYSDEVOP_get_free_pirq: diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c index 7efa17cf4c1e..1367abc61e54 100644 --- a/xen/arch/x86/physdev.c +++ b/xen/arch/x86/physdev.c @@ -305,11 +305,23 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) case PHYSDEVOP_map_pirq: { physdev_map_pirq_t map; struct msi_info msi; + struct domain *d; ret = -EFAULT; if ( copy_from_guest(&map, arg, 1) != 0 ) break; + d = rcu_lock_domain_by_any_id(map.domid); + if ( d == NULL ) + return -ESRCH; + /* If it is an HVM guest, check if it has PIRQs */ + if ( !is_pv_domain(d) && !has_pirq(d) ) + { + rcu_unlock_domain(d); + return -EOPNOTSUPP; + } + rcu_unlock_domain(d); + switch ( map.type ) { case MAP_PIRQ_TYPE_MSI_SEG: @@ -343,11 +355,23 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) case PHYSDEVOP_unmap_pirq: { struct physdev_unmap_pirq unmap; + struct domain *d; ret = -EFAULT; if ( copy_from_guest(&unmap, arg, 1) != 0 ) break; + d = rcu_lock_domain_by_any_id(unmap.domid); + if ( d == NULL ) + return -ESRCH; + /* If it is an HVM guest, check if it has PIRQs */ + if ( !is_pv_domain(d) && !has_pirq(d) ) + { + rcu_unlock_domain(d); + return -EOPNOTSUPP; + } + rcu_unlock_domain(d); + ret = physdev_unmap_pirq(unmap.domid, unmap.pirq); break; }