From nobody Sun May 19 03:12:43 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=1704438627; cv=pass; d=zohomail.com; s=zohoarc; b=g0cP6nNamBNjxwLnrbSCsxyPSlzdd30DnfyAkgVypfN9say34s8gmNks20n4fhJ9IVO6KwBnMsWm/HtEQTH+kwZyL+km45oIpOX9ma5el8k/dY0IR/r2i+c7M6Wfv0BF01FmBbNj0TCUce8ai4n4DDavGtgAoRpo5wldxwJGM8s= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704438627; 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=U2J87t3smH/+PmMBxkixHyu6GZJYqDWtA3ECUIAzmcM=; b=PG6NOqKAVQIEkatW88Ht7ceqlq92NQG4/gKY69SLLUmjyVj5/H7dfMyAoOXnGVFS+72hA8ps7LfGB/3oA37OSiL/Auj6MqUCXCJNHDbGd91ZrHcUqF63mZ1M4PyGznJvgQwWOB05l57vye3YSTquXN3VB1gd/sx3ZE+wRpe0weg= 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 1704438627225500.9327989706875; Thu, 4 Jan 2024 23:10:27 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.661981.1031842 (Exim 4.92) (envelope-from ) id 1rLeL8-00010B-Tz; Fri, 05 Jan 2024 07:09:58 +0000 Received: by outflank-mailman (output) from mailman id 661981.1031842; Fri, 05 Jan 2024 07:09: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 1rLeL8-000104-RH; Fri, 05 Jan 2024 07:09:58 +0000 Received: by outflank-mailman (input) for mailman id 661981; Fri, 05 Jan 2024 07:09:57 +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 1rLeL7-0000zs-H5 for xen-devel@lists.xenproject.org; Fri, 05 Jan 2024 07:09:57 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20630.outbound.protection.outlook.com [2a01:111:f400:7eaa::630]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6dd838f0-ab99-11ee-98ef-6d05b1d4d9a1; Fri, 05 Jan 2024 08:09:55 +0100 (CET) Received: from PH7PR17CA0030.namprd17.prod.outlook.com (2603:10b6:510:323::25) by SA1PR12MB6996.namprd12.prod.outlook.com (2603:10b6:806:24f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.16; Fri, 5 Jan 2024 07:09:49 +0000 Received: from SA2PEPF000015CA.namprd03.prod.outlook.com (2603:10b6:510:323:cafe::dd) by PH7PR17CA0030.outlook.office365.com (2603:10b6:510:323::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.16 via Frontend Transport; Fri, 5 Jan 2024 07:09:49 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF000015CA.mail.protection.outlook.com (10.167.241.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7159.9 via Frontend Transport; Fri, 5 Jan 2024 07:09: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.34; Fri, 5 Jan 2024 01:09:43 -0600 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: 6dd838f0-ab99-11ee-98ef-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f0iEb1x4ldfMMxtR2mgjY2jz+/Pi8NNpStXYYxUPJpGtX/lI2sdkrlKNJmS3YpI62Pdi6ZBIdZgfyPUtB3qdCUVADrtK+0Dqf+n4ozO8UGsUUguhQhdunG18yXcwPX0KnzRISWJ5enqWQrCZM4pIO7A6xIj2fJkyQzK5Ebrkgg92yjSeWqqPNcovT+Ibd5koisQeezZdnnbh/IwWSOfGbTpOL3UIqqiuM3RvI518wz2cGIOOPpgWJg6sIoJt0qSFdhoGpclKN4fXfXTdbOBBKisWvREL3T97fDaEwTfdSJ8DULp3RESsQCrw1W9LwIw8qw4Bp9f67L3DGhYM9oFrHA== 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=U2J87t3smH/+PmMBxkixHyu6GZJYqDWtA3ECUIAzmcM=; b=gbCdnQZJJbxtUzXfv5LmkodRj6d1Y/JhT83/1LVcxYIB/E79eezj1xmzZ9hBMQZPyJTo+dU05cEW+VPTTHeyIwoNEFuiF1Ym7fzg97w6wilRt+LuRyTgK5RzhcxQFIqdGaurIWt9fR3/fpK9WbsJUYopd0UKzXh7V2/8w5xAiDcCvV8oO+kN0iSmO+e0FMPjmOHwgNEgT2qUX9vPGBANhGcTAhsp1aeoP2WBPU1G3dHtBeqSSplPrSZEqILKhpt2kfT66LhI34vwASdSG75gC38XHq+NxxeV6PJ17UgbJqZ7VOswgz741LEqb1/8npmM41otMpnZJBcjwcH9f7lY4w== 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=U2J87t3smH/+PmMBxkixHyu6GZJYqDWtA3ECUIAzmcM=; b=kPMqy7Ev23UulccbYQhsi4fYDrOvenrLZLhme7SELsSVS7TMtMdENpKwJcBNuqIob5LC5I84EHqfBsxe+aAbv5a7Pf8flD01NOoeIthnhcZZV1UsqtxPIDFqF3hHA+TBQ3gFe1RUFbrdm0slPa18S9WA/bbeupCoO1AxBKfiAhs= 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?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini , Anthony PERARD , "Juergen Gross" , Stewart Hildebrand , Huang Rui , Jiqian Chen , Huang Rui Subject: [RFC XEN PATCH v4 1/5] xen/vpci: Clear all vpci status of device Date: Fri, 5 Jan 2024 15:09:16 +0800 Message-ID: <20240105070920.350113-2-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240105070920.350113-1-Jiqian.Chen@amd.com> References: <20240105070920.350113-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: SA2PEPF000015CA:EE_|SA1PR12MB6996:EE_ X-MS-Office365-Filtering-Correlation-Id: 52780fa8-e3d5-457d-c054-08dc0dbd4ded X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +uhmnsT5KZfNHTl4eT286/zcPLQ/AuUgISn900gKbopJzdEOOXb6TsGsUi0ptxWeJy/BU7b5qY9Cr1orgqKQP5Q2J6t5pbcb0dN+teOrwfZiHo2HZsUPgQeWgLFcDMUW+3SIeWmli58wUooJ81vq9Zne1YheNoOHK1rGb907v2H2n5EQrY9DGy3cGudynyN1d/zWYZJV/LJP8bTXu4XWbh5iaLNyDA16WYecpqNAvZz53OX+HNvyE7QXzJc47MW/azM/VVSbhSV2kE8pCbQ4u34DAEC2N4EFPYAs47MHzVBJmPTLu7NtloRK113nK2O7PfRp79pQao6tFBlx7WzCEd+WOA/u9JP5y1MaNz+l7aPvgXQuxmjD4ZkKV8FN2ZDZHMDw3JHsFlinafgHw9do6USxQmsid1C9KTqU1rWNPAI7DfreG0UYyC9BeNIGM3aP1AF7I+4RiDLXK13Dfj19wOIaK2EbFjzXlr++3lhy+7D2tjG90+Gk4+nxo+5i/8vwntXB7804bk9bMmYBUwlgY5DS54wZ1ovOwUIpkDvJcDhbIVSId49EbX34JeHsgGUzyl1Lbs/Jp0LR+V3Jap+I5v3vei+9iA8CPuj4QhBfvPvZ8o/USFTFIOOYt5ZaysB7vjaZJ/Mq5d2yjprOTVoeBUoEtm02GfCvz0w8DeMawpAB3q8QitIbeQqtMo5yLQeXUMWjjYkV2NpvRkVsUCQs2uBX0dlS7fwktzrmSDCaVFOB4kEiPbjKCmKFudtCbTCLq++9FVAtS7hkdT4I7dHwJg== 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)(136003)(376002)(346002)(39860400002)(396003)(230922051799003)(82310400011)(186009)(64100799003)(1800799012)(451199024)(36840700001)(46966006)(40470700004)(40480700001)(40460700003)(2906002)(478600001)(5660300002)(7416002)(6666004)(81166007)(356005)(4326008)(41300700001)(316002)(54906003)(70586007)(6916009)(36756003)(70206006)(7696005)(8676002)(8936002)(86362001)(2616005)(426003)(336012)(26005)(1076003)(83380400001)(82740400003)(16526019)(47076005)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2024 07:09:48.6393 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 52780fa8-e3d5-457d-c054-08dc0dbd4ded 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: SA2PEPF000015CA.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6996 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1704438628787100005 Content-Type: text/plain; charset="utf-8" When a device has been reset on dom0 side, the vpci on Xen side won't get notification, so the cached state in vpci is all out of date compare with the real device state. To solve that problem, add a new hypercall to clear all vpci device state. When the state of device is reset on dom0 side, dom0 can call this hypercall to notify vpci. Co-developed-by: Huang Rui Signed-off-by: Jiqian Chen --- xen/arch/x86/hvm/hypercall.c | 1 + xen/drivers/pci/physdev.c | 34 ++++++++++++++++++++++++++++++++++ xen/drivers/vpci/vpci.c | 9 +++++++++ xen/include/public/physdev.h | 7 +++++++ xen/include/xen/vpci.h | 6 ++++++ 5 files changed, 57 insertions(+) diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c index eeb73e1aa5d0..6ad5b4d5f11f 100644 --- a/xen/arch/x86/hvm/hypercall.c +++ b/xen/arch/x86/hvm/hypercall.c @@ -84,6 +84,7 @@ long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void)= arg) case PHYSDEVOP_pci_mmcfg_reserved: case PHYSDEVOP_pci_device_add: case PHYSDEVOP_pci_device_remove: + case PHYSDEVOP_pci_device_state_reset: case PHYSDEVOP_dbgp_op: if ( !is_hardware_domain(currd) ) return -ENOSYS; diff --git a/xen/drivers/pci/physdev.c b/xen/drivers/pci/physdev.c index 42db3e6d133c..552ccbf747cb 100644 --- a/xen/drivers/pci/physdev.c +++ b/xen/drivers/pci/physdev.c @@ -2,6 +2,7 @@ #include #include #include +#include =20 #ifndef COMPAT typedef long ret_t; @@ -67,6 +68,39 @@ ret_t pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(voi= d) arg) break; } =20 + case PHYSDEVOP_pci_device_state_reset: { + struct physdev_pci_device dev; + struct pci_dev *pdev; + pci_sbdf_t sbdf; + + if ( !is_pci_passthrough_enabled() ) + return -EOPNOTSUPP; + + ret =3D -EFAULT; + if ( copy_from_guest(&dev, arg, 1) !=3D 0 ) + break; + sbdf =3D PCI_SBDF(dev.seg, dev.bus, dev.devfn); + + ret =3D xsm_resource_setup_pci(XSM_PRIV, sbdf.sbdf); + if ( ret ) + break; + + pcidevs_lock(); + pdev =3D pci_get_pdev(NULL, sbdf); + if ( !pdev ) + { + pcidevs_unlock(); + ret =3D -ENODEV; + break; + } + + ret =3D vpci_reset_device_state(pdev); + pcidevs_unlock(); + if ( ret ) + printk(XENLOG_ERR "%pp: failed to reset PCI device state\n", &= sbdf); + break; + } + default: ret =3D -ENOSYS; break; diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 72ef277c4f8e..3c64cb10ccbb 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -107,6 +107,15 @@ int vpci_add_handlers(struct pci_dev *pdev) =20 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__ */ =20 static int vpci_register_cmp(const struct vpci_register *r1, diff --git a/xen/include/public/physdev.h b/xen/include/public/physdev.h index f0c0d4727c0b..f5bab1f29779 100644 --- a/xen/include/public/physdev.h +++ b/xen/include/public/physdev.h @@ -296,6 +296,13 @@ DEFINE_XEN_GUEST_HANDLE(physdev_pci_device_add_t); */ #define PHYSDEVOP_prepare_msix 30 #define PHYSDEVOP_release_msix 31 +/* + * Notify the hypervisor that a PCI device has been reset, so that any + * internally cached state is regenerated. Should be called after any + * device reset performed by the hardware domain. + */ +#define PHYSDEVOP_pci_device_state_reset 32 + struct physdev_pci_device { /* IN */ uint16_t seg; diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index d20c301a3db3..6ec83ce9ae13 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); =20 /* Remove all handlers and free vpci related structures. */ void vpci_remove_device(struct pci_dev *pdev); +int __must_check vpci_reset_device_state(struct pci_dev *pdev); =20 /* Add/remove a register handler. */ int __must_check vpci_add_register_mask(struct vpci *vpci, @@ -262,6 +263,11 @@ static inline int vpci_add_handlers(struct pci_dev *pd= ev) =20 static inline void vpci_remove_device(struct pci_dev *pdev) { } =20 +static inline int __must_check vpci_reset_device_state(struct pci_dev *pde= v) +{ + return 0; +} + static inline void vpci_dump_msi(void) { } =20 static inline uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, --=20 2.34.1 From nobody Sun May 19 03:12:43 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=1704438624; cv=pass; d=zohomail.com; s=zohoarc; b=FXymEerOixKYWXHlSXzAoIL1ta8wWlJ4qffRS5NYz+PMg2x0dn7c1zAhcV6LI89gtkb5I4t6FlrJJJ2OZq+7oSa//LYZkL277w4PZn60aIBxcLsyT4s7h5gnxFKJjtePAuGAPK5B7rR2fd7ve2OYWXcHxRX9M2EQRL0dv0i7bPM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704438624; 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=oxn0adhoslWIcg9D/tXdZK/xxeNrhrHf6QBk9BQZz0A=; b=i0UmslkEPrXAwpvQtt8sIhz3g8lXD/MMlQr/sLCdCMT+i5H2qWoc1gfjp388fNFmRgvZ1f0nJHg2yKrcV3Vq2ZbdzgPhvepty6ZJmyEtoGLDGSLM5+3YE95juCryRorQ0MUrBquZf8Bo7IJRni+tDAK5rp0WV/e/WOkojSghhRA= 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 1704438624949397.43491711714887; Thu, 4 Jan 2024 23:10:24 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.661983.1031862 (Exim 4.92) (envelope-from ) id 1rLeLD-0001u5-JZ; Fri, 05 Jan 2024 07:10:03 +0000 Received: by outflank-mailman (output) from mailman id 661983.1031862; Fri, 05 Jan 2024 07:10:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rLeLD-0001tX-G6; Fri, 05 Jan 2024 07:10:03 +0000 Received: by outflank-mailman (input) for mailman id 661983; Fri, 05 Jan 2024 07:10:01 +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 1rLeLB-0000zx-G0 for xen-devel@lists.xenproject.org; Fri, 05 Jan 2024 07:10:01 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2060a.outbound.protection.outlook.com [2a01:111:f400:7e88::60a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6ce5f08e-ab99-11ee-9b0f-b553b5be7939; Fri, 05 Jan 2024 08:09:55 +0100 (CET) Received: from PH7PR17CA0028.namprd17.prod.outlook.com (2603:10b6:510:323::8) by LV2PR12MB5821.namprd12.prod.outlook.com (2603:10b6:408:17a::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.15; Fri, 5 Jan 2024 07:09:51 +0000 Received: from SA2PEPF000015CA.namprd03.prod.outlook.com (2603:10b6:510:323:cafe::f0) by PH7PR17CA0028.outlook.office365.com (2603:10b6:510:323::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.16 via Frontend Transport; Fri, 5 Jan 2024 07:09:50 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF000015CA.mail.protection.outlook.com (10.167.241.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7159.9 via Frontend Transport; Fri, 5 Jan 2024 07:09:50 +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, 5 Jan 2024 01:09:46 -0600 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: 6ce5f08e-ab99-11ee-9b0f-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f6tqJ1o0BJp7rd1FHwuK016caGGlEZSBy91owYqcZEeoH3A6gijdN69nYBtDNbrbNrYkojKFGIsPPukFefQMgr6MjI9DXkA1GYtwffMuGw3cBjCOR84TghDTMbAJXEL0hq0By59ZdJ7qoW6OJKgSQYBNShZafFxR5Ri/O25LT92sKQzLWsXHCjhNkYkmGg0NodMd+a80M9bYyEeVPVq/YBs/vg08g3W1pmzF9DkjGbg4XCffeQ8SQpeRY9bTkS4hTqEvO/zPyF0MBtvm4kd1lBm0AnGchFujmdkQnBITVZ1f8txHKl7r+kwr1nLffMaiQrZJiin+YLM0TKCwlhj5pw== 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=oxn0adhoslWIcg9D/tXdZK/xxeNrhrHf6QBk9BQZz0A=; b=nsIYaKCSI6Z6wnHX8Piu35RZe28lZNJKZjQ5ZD01AqOHe5ZnoHJyIYqZjvmCDnaRjAEPobt7syR6HF+e35odRVqdoU4Stfoh/5fNzQ4nB5oa61+KSqDt6IdSlMrhU1cYx/0Cp8IdUdo7qBFQ8TUiaiYt6F9g2ym0Xi5meyKVAqX9AJcAANcfmyTreOXKL2tx6PabjQVj66fdMzUuEZ+outbr6I7xpvPCu0IgdgpJmQUp2WHgfD+tQyGwdnJHpyTfbtnAYI1XZItcch+MKLqNYab7DUQ6WncaWnj2+wlSm/bxXJQICBp9Gw2nHhBHafYR8yKO+SeAmKK2cL7ZGOU23A== 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=oxn0adhoslWIcg9D/tXdZK/xxeNrhrHf6QBk9BQZz0A=; b=tT/wugzSZ61MPH3iEELpzScqjEdsuF0MHBujxTCrYAfOSTleYgWxxZ4RPG+v/q39l/Dlnf39Lpd/y1f0/RRfrJivRw2gnGOGWJmiillhgZZSj04LZ/dDAiucBwHAeFiS3Ob9jAtaCYqVfmUwb2Purs4OA7Fv8S0KpmjVtN0dDys= 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?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini , Anthony PERARD , "Juergen Gross" , Stewart Hildebrand , Huang Rui , Jiqian Chen , Huang Rui Subject: [RFC XEN PATCH v4 2/5] x86/pvh: Allow (un)map_pirq when caller isn't DOMID_SELF Date: Fri, 5 Jan 2024 15:09:17 +0800 Message-ID: <20240105070920.350113-3-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240105070920.350113-1-Jiqian.Chen@amd.com> References: <20240105070920.350113-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: SA2PEPF000015CA:EE_|LV2PR12MB5821:EE_ X-MS-Office365-Filtering-Correlation-Id: 93b343a8-97bf-4c6c-9e04-08dc0dbd4f2f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UVcaDDInTWyOMMhUoc0J6PcykjQ1/GRev4KGyp4EIfbwmia74RAEGv9cz1TG/1SgDQ99iDpcuArn0U3BOjN+PpA0X3lPHsj1KZXhglLmtkWPz8nh8fzPLHzg2sZHwXsCKBqby4M1lUZi0Vcbb80A0hsaSsS6Vm+p67YuaugPaHSjVqdpB5YFik1OPE+OIuvtBF6PUkxb9WbMdwRUvL9gU3lPSgCLWI/jqDN2+DlcNOMmWOdEWpG1zy1ww9mT1M+I8N+HqmaW0CyRqORuB21AytlhEM+bAYDoryZdxyb8/pbuAqYvCL5yRr/NqyfESe1LdoUqQ222VoLtlT0AiUOUUkF9leV3rSChFuLztleOpl2WfwGt4O5+cgSKDoO0nXc3niSE61RU9Dkk3rb06KGy9zXwm5D013ayJ92u9OwynZMHmJljZK8kFsfHd7Q14TrUd8aejAqyoGEVyuupOXWJiKwsl/XM+LMUx/xQ9n0lB/QQQblu7Ik53HyRt4r8ALC1/bl4eR9U+kEQRMnvQ6NYKRmQHT0OQ783H2SOySSSoRpsCqdc/rh4LARoCCTJPC706Dmfcg/OXny2lgJEe5dk4Tw5MgN9MfEFZTzgEttryTsM0XPHTtA4EGIk+6cd1tGkFzQdukGy+ZP6JlDYzvh/z1uzDd+BSFNaH0R1n61GCsg5FPUVmXkpEfDoM46q89fqT1YWfQbe7bGeXByIXulLWQaSqq7NNR6PNaGsHqaxbRDuuqcrw1h+bKc2m27ileQkzfeDaNAoydeyF/rkVSoHVQ== 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)(396003)(39860400002)(346002)(376002)(136003)(230922051799003)(82310400011)(64100799003)(451199024)(186009)(1800799012)(40470700004)(36840700001)(46966006)(40480700001)(40460700003)(426003)(26005)(336012)(7696005)(478600001)(6666004)(82740400003)(36860700001)(86362001)(36756003)(81166007)(356005)(83380400001)(2906002)(16526019)(70206006)(5660300002)(54906003)(7416002)(41300700001)(2616005)(47076005)(1076003)(70586007)(6916009)(8936002)(316002)(4326008)(8676002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2024 07:09:50.7487 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 93b343a8-97bf-4c6c-9e04-08dc0dbd4f2f 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: SA2PEPF000015CA.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5821 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1704438626917100002 Content-Type: text/plain; charset="utf-8" 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 domid of the caller is not DOMID_SELF no matter whether currd has X86_EMU_USE_PIRQ flag and also allow PHYSDEVOP_unmap_pirq for the failed path to unmap pirq. Co-developed-by: Huang Rui Signed-off-by: Jiqian Chen --- xen/arch/x86/hvm/hypercall.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c index 6ad5b4d5f11f..632a68be3cc4 100644 --- a/xen/arch/x86/hvm/hypercall.c +++ b/xen/arch/x86/hvm/hypercall.c @@ -10,6 +10,7 @@ #include #include #include +#include =20 #include #include @@ -72,8 +73,30 @@ long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void= ) arg) =20 switch ( cmd ) { - case PHYSDEVOP_map_pirq: - case PHYSDEVOP_unmap_pirq: + case PHYSDEVOP_map_pirq: { + physdev_map_pirq_t map; + + if ( copy_from_guest(&map, arg, 1) !=3D 0 ) + return -EFAULT; + + if ( !has_pirq(currd) && map.domid =3D=3D DOMID_SELF ) + return -ENOSYS; + + break; + } + + case PHYSDEVOP_unmap_pirq: { + physdev_unmap_pirq_t unmap; + + if ( copy_from_guest(&unmap, arg, 1) !=3D 0 ) + return -EFAULT; + + if ( !has_pirq(currd) && unmap.domid =3D=3D DOMID_SELF ) + return -ENOSYS; + + break; + } + case PHYSDEVOP_eoi: case PHYSDEVOP_irq_status_query: case PHYSDEVOP_get_free_pirq: --=20 2.34.1 From nobody Sun May 19 03:12:43 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=1704438630; cv=pass; d=zohomail.com; s=zohoarc; b=dGbQCLZ9SD6b67Li0RA0dDTExut+5Fhw2VDHcYUlQU8fElwmpD9EqhDyu4PgxYcs/GxeD0mnyUXCtN5bnajwxB04HwEwrK1UcJnOmp85qny/j6l9wVuBki3T5SA9QYYuYS4Zc+FzPtGT9x0UR6Ef8+FcbcGefTvoH7sj3ECUklc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704438630; 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=OmRlmS0ceKu4lnk3o9j1hrAbxc9dIx9eF+B0pjAKXWo=; b=AMgbapKdjFQur/1DXkYXlF2wRwkFn7zoQW3HAOkhuWlmfnX68JMM7+QnVL0D0tyw/ZGVCDaJOarrHjRBUUA+NEePiUBy0u5F54PFG8uNOBKHQlG/JaEuLPLNy4b9dm3SCtUXZM9HAIV3OtNdI1e59uLPsAASSgQJFy+iclsff6U= 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 1704438630132279.60909976359596; Thu, 4 Jan 2024 23:10:30 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.661984.1031867 (Exim 4.92) (envelope-from ) id 1rLeLD-0001zB-VA; Fri, 05 Jan 2024 07:10:03 +0000 Received: by outflank-mailman (output) from mailman id 661984.1031867; Fri, 05 Jan 2024 07:10:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rLeLD-0001yP-Ov; Fri, 05 Jan 2024 07:10:03 +0000 Received: by outflank-mailman (input) for mailman id 661984; Fri, 05 Jan 2024 07:10:01 +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 1rLeLB-0000zx-ND for xen-devel@lists.xenproject.org; Fri, 05 Jan 2024 07:10:01 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2061f.outbound.protection.outlook.com [2a01:111:f400:fe5b::61f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6fe59fe5-ab99-11ee-9b0f-b553b5be7939; Fri, 05 Jan 2024 08:09:59 +0100 (CET) Received: from PA7P264CA0365.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:37c::18) by MN0PR12MB6272.namprd12.prod.outlook.com (2603:10b6:208:3c0::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.13; Fri, 5 Jan 2024 07:09:56 +0000 Received: from SA2PEPF000015C9.namprd03.prod.outlook.com (2603:10a6:102:37c:cafe::d5) by PA7P264CA0365.outlook.office365.com (2603:10a6:102:37c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.16 via Frontend Transport; Fri, 5 Jan 2024 07:09:55 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF000015C9.mail.protection.outlook.com (10.167.241.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7159.9 via Frontend Transport; Fri, 5 Jan 2024 07:09:54 +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, 5 Jan 2024 01:09:50 -0600 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: 6fe59fe5-ab99-11ee-9b0f-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cWNNWv8hN34QhIJMkKPtzV0FPc7MvzmLSMCmy9gPv+Nxjj/xFJKoVIkdm1HOp+TQpHp1srsmu7wUZPQK0vgbAG/hjEnjt8xnWjyPe0xema9kAtjRyjtOtCZqZXNn4Ro076uZnlJMZxUVZ5mzl+NDNKb0YEKpwOsONjjc60fEPrh/K79hvyUcLZZS1Ud813WuHdqy+sCpSrriXhwi49l4IxfHDc21DeseuraMYJwbMUXjWw3bNmqjUXam7mxNGZHYa//QFri4nnnHs2SK1bvrL4lhJr3LLMZ90DywXbtncgvPfju40mcS+ZzuCqEE1b7dv9qlG06bCPJLu+ZA92Ul+Q== 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=OmRlmS0ceKu4lnk3o9j1hrAbxc9dIx9eF+B0pjAKXWo=; b=VYnTDX+t8pHDViXX3/gxOpVYMMaCULWa8vfADn3jhZ+jnihCg9xasSU/ftjq8B8pYnJKt+DYfPQn632f+gpx4hWx5NK0hqJ/oR59rDkJbQMXSkwqT715KHMY67WH37gTW3H0VcVgvA6eJsym+vMqtYDYm0f30v5iK9ALwE0ULokdieLPHvYqs3+7XJSTBUIQTDRSZYyiCd9s2oTibnDZsN/73RQ1KFxroNb1qPqGtpYkd0DviGVTvqAcSSEeT97ILRVJcemYSFnVj+7ztXwjIEQtRwUpUlia7ZkiQsZYdxfGeyeQ5oO3dqO4gilGtgIXapHyFGe9k9SmqfpTgyUk/w== 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=OmRlmS0ceKu4lnk3o9j1hrAbxc9dIx9eF+B0pjAKXWo=; b=V+4voI1EvakpvS8FjJwV/9Q7Y7svzjNG15EpjTFDpuSCsJcKyQLjcWg++yKPIDb2hIn0hRd15K1s/cGdrdKaOvLxuRtTBLNWmoYK9CZ79WXpKS8V7GUOChBWCMruuXIKrAJcnJfhnujS4JJETQJgUo5pwVbwsbfx3OxCjBUMZrE= 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?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini , Anthony PERARD , "Juergen Gross" , Stewart Hildebrand , Huang Rui , Jiqian Chen , Huang Rui Subject: [RFC XEN PATCH v4 3/5] x86/pvh: Add PHYSDEVOP_setup_gsi for PVH dom0 Date: Fri, 5 Jan 2024 15:09:18 +0800 Message-ID: <20240105070920.350113-4-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240105070920.350113-1-Jiqian.Chen@amd.com> References: <20240105070920.350113-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: SA2PEPF000015C9:EE_|MN0PR12MB6272:EE_ X-MS-Office365-Filtering-Correlation-Id: 11e9be3b-8632-454d-3bc8-08dc0dbd519f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kRj9lZv7kay1ZNy7vv1QeyUVVO66pwZagvLjbuXKh8uIfXj4ZKGCBRRCoq+ndZ/lm0KQu6gZbV4/X8vP1z/JOK1lh7oXES4OzVjYQM8qifFqC0mT0cuHlSerf4UAV9OCs46lpiYcpJP7GnkwoferMD+h28y9vj3fIk477nRzCRayOg+GL3upJvu3bfVTdVbX1HWX4lG7+ucP6+mXvmlBaG8sSbVUBRSlAhHpAQoMkO3ArmC7PsObGz/YfUV9YRiZpWe1wgxj35ojOfIfmeMgREoML40yT9zVfR8NWanDJmmXA54LTXcbiyu9435DgEdFl4l3/1OZQ4GX0VgDZtIp9PiYi9EtXXSqt6UzWAJnEzV9aybZr0V2BXONkV0TkQSn27KT1EMt5Cy/d740dym7FWDsdEd17g/p+rR7Ub6mF4mnqUf4N3g0XajQN1OjcmObmEFch+qbK9u8Rrr5rhRqShg8XEstFoHOMnZWYKRKFso5VE0O6iL3ZCWF3imLuBEqoso5HpEb34u1oewy9z14ROBTyU8vtqQiQxBsN4IbBmnM+Ypq3Nc9XkNnFDHkXI7u/VRp3+FRRYzC3SdRoaxqeY9F3rRUBth9vtpVspCCAnmDax9mWUH8JdfHgb8nH7iO42GuHPjGHls7AR9p3Dql/N2TMYPklsGEwnJZQ3WKqDPz6oRL9oveQ/PKB//DU1vSpq3e7kuireGyVuS/X+Ceke26bTGdYyjRG4Lr76/GkSSVFwPutW2oiE5CWqQAOZPszwIUfsDcFdpK+9v0+Y6srw== 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)(396003)(136003)(346002)(376002)(230922051799003)(1800799012)(64100799003)(82310400011)(186009)(451199024)(46966006)(40470700004)(36840700001)(82740400003)(478600001)(7696005)(6666004)(356005)(8936002)(36860700001)(26005)(336012)(426003)(16526019)(8676002)(1076003)(47076005)(316002)(4326008)(6916009)(81166007)(86362001)(70586007)(70206006)(54906003)(40480700001)(2906002)(40460700003)(4744005)(7416002)(5660300002)(36756003)(41300700001)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2024 07:09:54.7419 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 11e9be3b-8632-454d-3bc8-08dc0dbd519f 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: SA2PEPF000015C9.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6272 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1704438630779100007 Content-Type: text/plain; charset="utf-8" On PVH dom0, the gsis don't get registered, but the gsi of a passthrough device must be configured for it to be able to be mapped into a hvm domU. On Linux kernel side, it calles PHYSDEVOP_setup_gsi for passthrough devices to register gsi when dom0 is PVH. So, add PHYSDEVOP_setup_gsi for above purpose. Co-developed-by: Huang Rui Signed-off-by: Jiqian Chen --- xen/arch/x86/hvm/hypercall.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c index 632a68be3cc4..e27d3ca15185 100644 --- a/xen/arch/x86/hvm/hypercall.c +++ b/xen/arch/x86/hvm/hypercall.c @@ -97,6 +97,12 @@ long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void= ) arg) break; } =20 + case PHYSDEVOP_setup_gsi: + if ( is_hardware_domain(currd) && !has_pirq(currd) ) + break; + else + return -ENOSYS; + case PHYSDEVOP_eoi: case PHYSDEVOP_irq_status_query: case PHYSDEVOP_get_free_pirq: --=20 2.34.1 From nobody Sun May 19 03:12:43 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=1704438626; cv=pass; d=zohomail.com; s=zohoarc; b=A00nkJRJhkvamzaEGge24TWBXATVM8JuTKSPA88wF8kqeHYAqRan23p2g5EtymoQSrIPz0UBHvUR2xykKeBdFSTcY4tv4E9ooRzZE26wxDqCJ0Prv63Z/jQkNtHST7hM8i5+SkLNNEIB7F+ASzfZVoMO86fxkDnpVUGRUTSbmwc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704438626; 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=rf4Pu/sqcMtXSsRIZdrBWFvuz03FcIxT/N0cvVCw+TI=; b=mX0tR5PflE5eEp7LnHJin8/4F5/KTqSwCZKFoQF1ePWpWVe+SZJ023NytgKYUrHjoAsNVk7m0yP+JzcPyPL2Y/qGrksubVtvjzYQiwnsWPp8rqy3F9RfKAs65GpnsZzL0N4N/z8EVsNrfNgVDzxHjdHG1VSljY3LnW0gQeZ7bZ8= 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 1704438626125272.3905646958375; Thu, 4 Jan 2024 23:10:26 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.661985.1031881 (Exim 4.92) (envelope-from ) id 1rLeLH-0002t0-6P; Fri, 05 Jan 2024 07:10:07 +0000 Received: by outflank-mailman (output) from mailman id 661985.1031881; Fri, 05 Jan 2024 07:10:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rLeLH-0002sS-3J; Fri, 05 Jan 2024 07:10:07 +0000 Received: by outflank-mailman (input) for mailman id 661985; Fri, 05 Jan 2024 07:10:06 +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 1rLeLG-0000zs-6H for xen-devel@lists.xenproject.org; Fri, 05 Jan 2024 07:10:06 +0000 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2060e.outbound.protection.outlook.com [2a01:111:f400:7e8d::60e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 73a42acc-ab99-11ee-98ef-6d05b1d4d9a1; Fri, 05 Jan 2024 08:10:05 +0100 (CET) Received: from PH8PR02CA0015.namprd02.prod.outlook.com (2603:10b6:510:2d0::7) by MW4PR12MB5666.namprd12.prod.outlook.com (2603:10b6:303:188::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.16; Fri, 5 Jan 2024 07:09:59 +0000 Received: from SA2PEPF000015CC.namprd03.prod.outlook.com (2603:10b6:510:2d0:cafe::77) by PH8PR02CA0015.outlook.office365.com (2603:10b6:510:2d0::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.16 via Frontend Transport; Fri, 5 Jan 2024 07:09:59 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF000015CC.mail.protection.outlook.com (10.167.241.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7159.9 via Frontend Transport; Fri, 5 Jan 2024 07:09:58 +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, 5 Jan 2024 01:09:54 -0600 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: 73a42acc-ab99-11ee-98ef-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A8w/ryduOw+w0uWbyaulW8uccfBuvNqqEbWnNjhe+tdzfdGifbjC3aB0T06MvQ07g3x+hH4rWikJFWNZkP5N/UorbtU/KuxpObwfLmMlVGEPf0e7ta/y7piR2WfoGzCvNSneiuj8KC/jpElCIxj7OIiPSPSILSHGENr59xiYJC3AVLYOOsKdgRnqAkbVPiW1AGlRJLxgUdcEs758O+ZXLhiA6pqvfiYZOXXlQc7rao/Pj7mB+CP+BPFPfzLRORX3myD3wHRy6050IRge2txNV1I7MJMWVnDAbEJuDu9J4HL0l6X8FkRixcYZFGa232v5glUcIfJwmXr8ed+J0K/qkQ== 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=rf4Pu/sqcMtXSsRIZdrBWFvuz03FcIxT/N0cvVCw+TI=; b=GTpRtNlGgCvORdOnvv+S+i/G18XL313ASrOuoTd8bdFKT4nqmpQ85Fwe2ahUDFhLiRsDbzX2ZvdmaoHh0yY9zElWIVHkY9X2HlBkGPz5eZOTfSF2oDyrLaaPmHJ0xDt1WE0hCXHBwVfjNn+7vIk5vJW2DeuCzVcsfyjuO+uMofh46saspo/QeOVmOuaS4adGZ6v602t4iGCI8ZkWNKjp5JH0EzI40Eac0NKRFWaJe/FmTSlEXdLNRGwKM82M0KoxeMMY/Ta2AKw9BLoG1Sqzj+NNL8QJTDAVhYBy0bo+AjRFnaxLHSi090j1mkrm0dtRBiMlsS+Ms5e3xUrPbd3RCg== 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=rf4Pu/sqcMtXSsRIZdrBWFvuz03FcIxT/N0cvVCw+TI=; b=DfgE6hLlaNKb8qAmCo6YglFTeU6CKAoscyCLoyR83rI1zBV0JHizmSRYsiC22jhTldX3swp9jL3R8KWARyScSSm3f8wZvuSHWU6POmNwEfILg71i+40LvxftiM2BpqLE7MFh5915JaHUMyqrgORb7Y/73plJhHW2BFCs1G+YWfw= 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?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini , Anthony PERARD , "Juergen Gross" , Stewart Hildebrand , Huang Rui , Jiqian Chen , Huang Rui Subject: [RFC XEN PATCH v4 4/5] domctl: Use gsi to grant/revoke irq permission Date: Fri, 5 Jan 2024 15:09:19 +0800 Message-ID: <20240105070920.350113-5-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240105070920.350113-1-Jiqian.Chen@amd.com> References: <20240105070920.350113-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: SA2PEPF000015CC:EE_|MW4PR12MB5666:EE_ X-MS-Office365-Filtering-Correlation-Id: d5ab51ce-7600-4170-774d-08dc0dbd53f8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9j3sB6Xb1ShR5vObfhkbmDTD3xOOHvJ7Qa/FkkoIG80L1G9SRA0VqGTcsR6ph+P6rXvE6b3RfsUWzdfypYMIiXjm2ape+06Z+ZwQgEA5dtHbGT66aymSCtG7b2QoqhLQ2B8m/TTXz1jnVELoZ+525yN0heJbC5D16BRwmdQ0nLUkJ58M5axDNCJOWv33rjnWkXyqtLN8LAFOzVd+8Dfirb/KTRAbZHDdnw3r7bFntbeO0P7PrMGhY8VUsi3ehRJhao+tm1GRR/5BN22ym785SWDLQ0VCsZkxHn664wFf9o0PNgyHUeRAwajQLr1xK0evCm3Qs49Rdui69bxr8nVy/HGoVx6MSAekzmZj88+fDDkrSB4/DfVRoguag5s09EEdLyIQ5qacKp/31rYkDCJpuhe3w4OUYQX5VbusK4YIamn5niDayjYytEyMrWyUL7HIUg7Xr7Ez6N9ruqcx/CrANh3UUZXjdkcQ0jq/xbLNGD7ckSwoneyA7+4guUyMicge/3teyygGA9XDlTC5EPp7RD06r19tKETWSwlD99UJNIsbh5BUblbA1vGHcRRJrnXEup2V8sRuhYiVRxyol58hGUCuNN88oiUgMJIjHjwTC9VoNVs6oLFLCTscV1W+CDGAglUY+wcuxJj7hrOajFGVxx2+MFg5kupIujzVadyR7JpWHeoF/JM1cFGWAe/xCUxgKVMRbeXhJ+SUsajcX1JgOa25C8nU8eys4VAY06Qr26MxS3Ij6EaAgyNneuV4zhMxQO7rTDMP4CKWSIxrY5Iy0g== 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)(346002)(396003)(376002)(136003)(230922051799003)(186009)(64100799003)(82310400011)(451199024)(1800799012)(36840700001)(46966006)(40470700004)(40480700001)(40460700003)(83380400001)(41300700001)(70586007)(70206006)(81166007)(356005)(36756003)(86362001)(316002)(82740400003)(36860700001)(47076005)(16526019)(26005)(426003)(336012)(2616005)(1076003)(5660300002)(6666004)(2906002)(478600001)(6916009)(54906003)(7696005)(8936002)(8676002)(7416002)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2024 07:09:58.7602 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d5ab51ce-7600-4170-774d-08dc0dbd53f8 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: SA2PEPF000015CC.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB5666 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1704438626891100001 Content-Type: text/plain; charset="utf-8" Some type of domain don't have PIRQ, like PVH, current implementation is not suitable for those domain. When passthrough a device to guest on PVH dom0, this pci_add_dm_done->XEN_DOMCTL_irq_permission will failed at domain_pirq_to_irq. So, change it to use gsi to grant/revoke irq permission. And change the caller of XEN_DOMCTL_irq_permission to pass gsi to it instead of pirq. Co-developed-by: Huang Rui Signed-off-by: Jiqian Chen --- tools/libs/light/libxl_pci.c | 6 ++++-- tools/libs/light/libxl_x86.c | 5 ++++- xen/common/domctl.c | 12 ++++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 96cb4da0794e..e1341d1e9850 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -1418,6 +1418,7 @@ static void pci_add_dm_done(libxl__egc *egc, unsigned long long start, end, flags, size; int irq, i; int r; + int gsi; uint32_t flag =3D XEN_DOMCTL_DEV_RDM_RELAXED; uint32_t domainid =3D domid; bool isstubdom =3D libxl_is_stubdom(ctx, domid, &domainid); @@ -1486,6 +1487,7 @@ static void pci_add_dm_done(libxl__egc *egc, goto out_no_irq; } if ((fscanf(f, "%u", &irq) =3D=3D 1) && irq) { + gsi =3D 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)", @@ -1494,10 +1496,10 @@ static void pci_add_dm_done(libxl__egc *egc, rc =3D ERROR_FAIL; goto out; } - r =3D xc_domain_irq_permission(ctx->xch, domid, irq, 1); + r =3D xc_domain_irq_permission(ctx->xch, domid, gsi, 1); if (r < 0) { LOGED(ERROR, domainid, - "xc_domain_irq_permission irq=3D%d (error=3D%d)", irq, r= ); + "xc_domain_irq_permission irq=3D%d (error=3D%d)", gsi, r= ); fclose(f); rc =3D ERROR_FAIL; goto out; diff --git a/tools/libs/light/libxl_x86.c b/tools/libs/light/libxl_x86.c index d16573e72cd4..88ad50cf6360 100644 --- a/tools/libs/light/libxl_x86.c +++ b/tools/libs/light/libxl_x86.c @@ -654,12 +654,15 @@ out: int libxl__arch_domain_map_irq(libxl__gc *gc, uint32_t domid, int irq) { int ret; + int gsi; + + gsi =3D irq; =20 ret =3D xc_physdev_map_pirq(CTX->xch, domid, irq, &irq); if (ret) return ret; =20 - ret =3D xc_domain_irq_permission(CTX->xch, domid, irq, 1); + ret =3D xc_domain_irq_permission(CTX->xch, domid, gsi, 1); =20 return ret; } diff --git a/xen/common/domctl.c b/xen/common/domctl.c index f5a71ee5f78d..eeb975bd0194 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -653,12 +653,20 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u= _domctl) unsigned int pirq =3D op->u.irq_permission.pirq, irq; int allow =3D op->u.irq_permission.allow_access; =20 - if ( pirq >=3D current->domain->nr_pirqs ) + if ( pirq >=3D nr_irqs_gsi ) { ret =3D -EINVAL; break; } - irq =3D pirq_access_permitted(current->domain, pirq); + + if ( irq_access_permitted(current->domain, pirq) ) + irq =3D pirq; + else + { + ret =3D -EPERM; + break; + } + if ( !irq || xsm_irq_permission(XSM_HOOK, d, irq, allow) ) ret =3D -EPERM; else if ( allow ) --=20 2.34.1 From nobody Sun May 19 03:12:43 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=1704438630; cv=pass; d=zohomail.com; s=zohoarc; b=UHXVHcuxy1Yz69Qpi31afRLT3VqjSpnK8U9qfRU80xAfs2yA5ma8ZtHdTfVbp+o/Oy2q0ipYsP6VqShVdy/4Lm0bqQG9EYst0fftr4S8KJxBfnizPtJFkJU2S+kex6c0aSs+VuYLRgnwlZjB5G43UtCoCCvI8STMPXhkUKU50vA= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704438630; 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=XUq05x2O7uEZgBZIRC0Zh7w0rJnudKOWKK8/cz1mH6c=; b=EEXN4h8Ni+98Rf/rh6a1cFu/UdzvRa9Cq41223qf8GhKm1XLRr9QKoMYqufOZWP4ZbjwcsxZ8+J7fHZ9plq32CLch7j1ANCc9W9uBo22LPig8wymxgKRJB7YaNYgwd3BVgk00rXAcgDzTcJFmVp70rhUvqgN31c2n+qm8lCbEMI= 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 1704438630197942.730121795924; Thu, 4 Jan 2024 23:10:30 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.661986.1031892 (Exim 4.92) (envelope-from ) id 1rLeLI-0003CR-L7; Fri, 05 Jan 2024 07:10:08 +0000 Received: by outflank-mailman (output) from mailman id 661986.1031892; Fri, 05 Jan 2024 07:10:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rLeLI-0003CC-GS; Fri, 05 Jan 2024 07:10:08 +0000 Received: by outflank-mailman (input) for mailman id 661986; Fri, 05 Jan 2024 07:10:07 +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 1rLeLH-0000zs-6J for xen-devel@lists.xenproject.org; Fri, 05 Jan 2024 07:10:07 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20623.outbound.protection.outlook.com [2a01:111:f400:7eaa::623]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 73a1e0ba-ab99-11ee-98ef-6d05b1d4d9a1; Fri, 05 Jan 2024 08:10:06 +0100 (CET) Received: from PH8PR02CA0014.namprd02.prod.outlook.com (2603:10b6:510:2d0::6) by BY5PR12MB4275.namprd12.prod.outlook.com (2603:10b6:a03:20a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.16; Fri, 5 Jan 2024 07:10:03 +0000 Received: from SA2PEPF000015CC.namprd03.prod.outlook.com (2603:10b6:510:2d0:cafe::ba) by PH8PR02CA0014.outlook.office365.com (2603:10b6:510:2d0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.16 via Frontend Transport; Fri, 5 Jan 2024 07:10:03 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF000015CC.mail.protection.outlook.com (10.167.241.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7159.9 via Frontend Transport; Fri, 5 Jan 2024 07:10:02 +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, 5 Jan 2024 01:09:58 -0600 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: 73a1e0ba-ab99-11ee-98ef-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B3C+oTNhuBwj3rsR7miV3w+HLziQBdXp4DsiuaYVP7tsvlX9uIiusqVowmM6aUiu2bHvTbBmcc3b181styYKoEtu5pBgTYh8o8foJtOi0AKqygIEFIAR577QBmNDLV2Gg7EFXEUDNoFPQCCI+NVWbJvU0z2Td4fs7ioj7w267i+zNzxni0Bep59lP80SmcM1IrJNtPoNiudmWCpLSlL3uX00jjkBlhM8+1iRYFEpOEc6yRr7cZ5HPAKnHqxgT4CYKredrb4Lui9WC7X9kUWU/wC0c483cDTwOk0UXUKSKOytuPd/cr8OTa08WHVeNxroMJ4ZssWOhFmLN39rXRegrg== 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=XUq05x2O7uEZgBZIRC0Zh7w0rJnudKOWKK8/cz1mH6c=; b=d3I75IWvfiL4DdrWIWW63HxL89rCgfmVm27OyVIJi4QB81cnJgJgY2Hh6HMuCPKVu1gCbop/EU6oiq9+75hzVRJUiU9Qpizsjk1Y6FwnSuELrwJ5Eo7AteFS2Wj1BKvdk7stxt1eCHPvWDj07LYDDp8I/i7TEtb8CNosRbztH0ej2CkKnAkbOjkKOPFEsLaCnkj1OgaMB7q/ox5hK+hgtqxnMyqSylLGyp/mP9Pt04cKoa/fsG3tY9QzqfhEJn2nPDPMtfulP3gMNpuqneGzoAZgMKNLvinXT5XhhOgqwDSkI1aZYVgGrRGucKqdZ6ZktwY8U3kf8PYZhW1BoxO5bg== 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=XUq05x2O7uEZgBZIRC0Zh7w0rJnudKOWKK8/cz1mH6c=; b=JGCakPB634yiCJzhF7Y8rbzZjptLPnYwqdehwNeeDahBs5qkDbNZm3Ceyjr7Sk3PnyevQNIb66bl+3fUQePeEh1YtV+Ci1Ob17gdYxlp2t8afdCYsizlVF4bPByESSTFFQkXFy6TSNYcbG4U+Tc0SCVa34mVmK7AbcH+haPTRhk= 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?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini , Anthony PERARD , "Juergen Gross" , Stewart Hildebrand , Huang Rui , Jiqian Chen , Huang Rui Subject: [RFC XEN PATCH v4 5/5] libxl: Use gsi instead of irq for mapping pirq Date: Fri, 5 Jan 2024 15:09:20 +0800 Message-ID: <20240105070920.350113-6-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240105070920.350113-1-Jiqian.Chen@amd.com> References: <20240105070920.350113-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: SA2PEPF000015CC:EE_|BY5PR12MB4275:EE_ X-MS-Office365-Filtering-Correlation-Id: 7d409d16-f7fe-4b58-e408-08dc0dbd566d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 36h4mVC2Nan1+C+2eYJ7p9MNUGORmlQ9ywT07P0INSXpHhWEI8a/6DKMIiHfvMm3EdtKtiLgBqy2K0QiEWkQDLqAcuPZm1xQ+YOIt31bXfG9Z+WFfT4GfxXbHBpxQOhQJ0/POt5zwRcCAN0sdeQ0fil51h2V0vnbgBOqwEqEa+9wydC7+WxLo/WJeQcHq1v4vEpHlmNTp/GmJIgmlROLvRfG07azK/BdlFRWSau5TTEEnD2Qiwq+lP1uz0VhGHOccj5i/JL814YCvnD20A2kmLb3qQ6oaY3FMa+5xWrM7X3YSYnX6BJh+KpEBhfq2sXn56n3gHLSdeE76Xj3eUCR3CxbzQDPBblmeTDqZRAmRabIyD7MVHHrnwJ3sFXVlVeRZyYWu8oMCgDDX4bTO4ciAy2Lu1WMXxgfsQKzi5ET9xGvTC9LrsxMav8cpSzQVG2m9bCAo8p8ygQIusX4hC6AVBoruzphakJ482p6nb+31bnLKLWBoGO69gHVbgZrWFSlsn7vjmK37Ihki6f7j7h0mwcKUyQpfEHSF6zzLgwKhFKM7FpsH8boXZNTC+GOz8fP63R6K3dbYTIO/qU6mD4CFWC60s/EiewSgOaAr/hC2UhmYhMxDYDeTdehOi7kTJEtDsDDp1brczGa1TH/Vlogq/1zvXOvsMxozL6aR4QoCNYbwVZyNKWWW1b+/uk7x5Z9YZ2WGL1WO+BArQwse3zt5AExFGiRSVuVvj8KWr2OJ7TZWnil+Ctsi8JxyBEzlfRmhmKk2jw+cY1gZURCExqXxQ== 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)(136003)(396003)(39860400002)(346002)(230922051799003)(1800799012)(451199024)(186009)(64100799003)(82310400011)(40470700004)(36840700001)(46966006)(82740400003)(6916009)(70586007)(86362001)(36860700001)(356005)(47076005)(81166007)(70206006)(16526019)(6666004)(26005)(2616005)(1076003)(7696005)(426003)(336012)(5660300002)(7416002)(2906002)(36756003)(478600001)(83380400001)(54906003)(316002)(8936002)(8676002)(4326008)(40460700003)(40480700001)(41300700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2024 07:10:02.9165 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7d409d16-f7fe-4b58-e408-08dc0dbd566d 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: SA2PEPF000015CC.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4275 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1704438630787100008 Content-Type: text/plain; charset="utf-8" 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 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 passthrough a device, xl wants to use gsi to map pirq, see pci_add_dm_done->xc_physdev_map_pirq, but the gsi number is got from file /sys/bus/pci/devices//irq in current code, so it will fail when mapping. So, use real gsi number read from gsi sysfs. Co-developed-by: Huang Rui Signed-off-by: Jiqian Chen Reviewed-by: Stefano Stabellini --- tools/libs/light/libxl_pci.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index e1341d1e9850..ab51dc099725 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -1479,8 +1479,14 @@ 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, + sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/gsi", pci->domain, pci->bus, pci->dev, pci->func); + + if (access(sysfs_path, F_OK) !=3D 0) { + 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); @@ -2231,9 +2237,14 @@ skip_bar: if (!pci_supp_legacy_irq()) goto skip_legacy_irq; =20 - sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/irq", pci->domain, + sysfs_path =3D GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/gsi", pci->domain, pci->bus, pci->dev, pci->func); =20 + if (access(sysfs_path, F_OK) !=3D 0) { + 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, domid, "Couldn't open %s", sysfs_path); --=20 2.34.1