From nobody Fri Nov 22 13:14:22 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=1718614889; cv=pass; d=zohomail.com; s=zohoarc; b=GA4g0kZl6M5la4VGhPMfD+8cxgqjs4JD7Ef0NpDns47I3knWShQjYaNGC98Vd0ewiJOHKmAshpFfqrfeKHyWdMjWhzDT1VGjrOEq2gKe6BWU3/y5IEhhItp44x42+jctyXE4lR+CLTrzzCfFUid6hbWrqd8JyludPyWX5/PKYJM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718614889; 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=AjVitUbIkh6X7zuVbHNzZlFo2M2H+RQ3FnoFSkKO2gs=; b=mR9dGuKRk69Tpk0eswqWx9RP5xBhHp5eb8P2S+98eZ3xZqTNzvVLo8nFK5mOubezHfGUSqsCL//l9i2FPVd+5i3Y/O9W7ZEotdfcds5qNOuVtRBAAGSNj0xd4lyarxaO6QL44hwVRCWU0SDLCcbTU6AghD9GgNi5sr3TAYMwuPE= 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 1718614889249979.2449052011633; Mon, 17 Jun 2024 02:01:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.741966.1148668 (Exim 4.92) (envelope-from ) id 1sJ8Ee-00029J-6I; Mon, 17 Jun 2024 09:01:08 +0000 Received: by outflank-mailman (output) from mailman id 741966.1148668; Mon, 17 Jun 2024 09:01: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 1sJ8Ee-00029B-2i; Mon, 17 Jun 2024 09:01:08 +0000 Received: by outflank-mailman (input) for mailman id 741966; Mon, 17 Jun 2024 09:01:06 +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 1sJ8Ec-0001sw-GB for xen-devel@lists.xenproject.org; Mon, 17 Jun 2024 09:01:06 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20613.outbound.protection.outlook.com [2a01:111:f403:2009::613]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1ffbf5d6-2c88-11ef-b4bb-af5377834399; Mon, 17 Jun 2024 11:01:04 +0200 (CEST) Received: from MN2PR01CA0008.prod.exchangelabs.com (2603:10b6:208:10c::21) by PH0PR12MB7094.namprd12.prod.outlook.com (2603:10b6:510:21d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.30; Mon, 17 Jun 2024 09:00:59 +0000 Received: from BN2PEPF00004FC1.namprd04.prod.outlook.com (2603:10b6:208:10c:cafe::a6) by MN2PR01CA0008.outlook.office365.com (2603:10b6:208:10c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.26 via Frontend Transport; Mon, 17 Jun 2024 09:00:59 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN2PEPF00004FC1.mail.protection.outlook.com (10.167.243.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Mon, 17 Jun 2024 09:00: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.39; Mon, 17 Jun 2024 04:00:53 -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: 1ffbf5d6-2c88-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NRjLJhaBRyDq+5cnyIt3BhRt5KVluu2NxTVNPUGwJlKw1InukZqCBywBXC18BwEFkrXFGbCC3g6cNQnWxFrehSETN3mT1Irb/yd2x3sqXuZWi+9fz7AGOq2gei8/tsIjSPExMas+ys7AsqBMw3DLkSq1pNaAUnur7/nK8K0tO5X/zJJR8U0P04goAgKeu6P8efTmWjLV9luOhudDkuI7rluIDwqwCFb92n904MOk9xT9zFbWRaIn1pGcwjwjT8IlXt2sfyBT0AwzPktnjGTI7URhe2LdXqeY7roaotSorspQKDsXP99YZ4mS5FhgeVMXXZSmysD6R0UunMtT3FkUVA== 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=AjVitUbIkh6X7zuVbHNzZlFo2M2H+RQ3FnoFSkKO2gs=; b=A1Ntup4jSkAYzLUqnGCMumzFl18Au7QEguno3hubW9WvG08qwk9kxbp4MjyunommKBCtNEaWS9+m6f/1ECbkvFpPtFFPqic6juGzrMbdfSQCQsCtf7WeDf8K+th4u/lNsY0vOFxJhu4u6g6O6MIWr7IvByZk9Gl++RIdQ2KMYokjaZ2AtQELoA3Sd5Xr1OKXt3XibJnVHIJWSctB9h0r0jsz/q9VqyEJTMbkHJCsO4IQ4d4kEmruu/eRcK0IkQTUIiinnRfOb7EvkdCuX7jUyRKuR9mlAB8N67bKKOaTydjXVxDC5OHc1Ecqjb3wKubVfW9rzx+q2JSRP46Kn4vEhw== 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=AjVitUbIkh6X7zuVbHNzZlFo2M2H+RQ3FnoFSkKO2gs=; b=BcUStHgYHssKuWcHCfU9KTKx6PCYFsjKSoQtlXIbRSY7wzWpwmN67sBtBf6e9rUE9GMDULa9NSwF2an9Mne87OeJMHlPPDR2yOPNz86s2+RnqIEBIg4/NK+QtUZmLTyoWNqBGylyw8k0XdZVYqIRbCHt/FSYHB26byivzDzd19Q= 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" , "Daniel P . Smith" , Stewart Hildebrand , Huang Rui , Jiqian Chen , Huang Rui , Stewart Hildebrand Subject: [XEN PATCH v10 1/5] xen/vpci: Clear all vpci status of device Date: Mon, 17 Jun 2024 17:00:31 +0800 Message-ID: <20240617090035.839640-2-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617090035.839640-1-Jiqian.Chen@amd.com> References: <20240617090035.839640-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: BN2PEPF00004FC1:EE_|PH0PR12MB7094:EE_ X-MS-Office365-Filtering-Correlation-Id: ff1566a5-fe34-4277-0ece-08dc8eac0147 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|36860700010|376011|7416011|82310400023|1800799021; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?6RPTYonk2L2i5ysRafTrcPq/HKcR17Hqdf30Osu6YVx/iTiMrl+P/PvTnsxp?= =?us-ascii?Q?hz1dAKZMjIM5KVL05ZfQ9qOW42+Ctk++V/nFKj+g3Sh/UU51sr467VcPSE3n?= =?us-ascii?Q?redB53M8i/azOd4bpYSwW+R9z8yaM7Q2D0dXuI8+FQmjtJJ52SV6B7ZnDkvo?= =?us-ascii?Q?8IUCZEDoW2SL2+4MoDF3JH03kaDbW70rFzhClGaOGryaW5DYjoALNseXkv2j?= =?us-ascii?Q?Hbo4yp5/ym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t3GiFdb?= =?us-ascii?Q?H5NL/31QRYUucxYovScjUHEiMou9j1McSOD2XoyP7BLzMYpysoQrAS3+fxPo?= =?us-ascii?Q?wWcjsboTrEkdiHg4YFGyn7vxC/SUhNsVdoEOhNEY+VYcXTv3RyEhBK2hAmbT?= =?us-ascii?Q?VOOJJjalO5k6hm6rMLjv/lNnfdgMO4VKt1B+Zq4vwNfztsOaMoL9iKIjAY8D?= =?us-ascii?Q?Kje67HxwbfgDgUteR/Ry2oIBJVGW0m41Yrb6DaRzvhWkZlOT4oJulS/7XT3L?= =?us-ascii?Q?PGo0Cmna1MNAnPSVaNfYp1LOn4XotpSjNA41c7s61QsksHMzrA=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230037)(36860700010)(376011)(7416011)(82310400023)(1800799021);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2024 09:00:58.6095 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ff1566a5-fe34-4277-0ece-08dc8eac0147 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: BN2PEPF00004FC1.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7094 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1718614891142100002 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. Signed-off-by: Jiqian Chen Signed-off-by: Huang Rui Signed-off-by: Jiqian Chen Reviewed-by: Stewart Hildebrand Reviewed-by: Stefano Stabellini --- xen/arch/x86/hvm/hypercall.c | 1 + xen/drivers/pci/physdev.c | 43 ++++++++++++++++++++++++++++++++++++ xen/drivers/vpci/vpci.c | 9 ++++++++ xen/include/public/physdev.h | 7 ++++++ xen/include/xen/pci.h | 16 ++++++++++++++ xen/include/xen/vpci.h | 6 +++++ 6 files changed, 82 insertions(+) diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c index 7fb3136f0c7c..0fab670a4871 100644 --- a/xen/arch/x86/hvm/hypercall.c +++ b/xen/arch/x86/hvm/hypercall.c @@ -83,6 +83,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..1cce508a73b1 100644 --- a/xen/drivers/pci/physdev.c +++ b/xen/drivers/pci/physdev.c @@ -2,11 +2,17 @@ #include #include #include +#include =20 #ifndef COMPAT typedef long ret_t; #endif =20 +static const struct pci_device_state_reset_method + pci_device_state_reset_methods[] =3D { + [ DEVICE_RESET_FLR ].reset_fn =3D vpci_reset_device_state, +}; + ret_t pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { ret_t ret; @@ -67,6 +73,43 @@ ret_t pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(voi= d) arg) break; } =20 + case PHYSDEVOP_pci_device_state_reset: { + struct pci_device_state_reset dev_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_reset, arg, 1) !=3D 0 ) + break; + dev =3D &dev_reset.dev; + 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; + } + + write_lock(&pdev->domain->pci_lock); + pcidevs_unlock(); + ret =3D pci_device_state_reset_methods[dev_reset.reset_type].reset= _fn(pdev); + write_unlock(&pdev->domain->pci_lock); + if ( ret ) + printk(XENLOG_ERR "%pp: failed to reset vPCI 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 1e6aa5d799b9..ff67c2550ccb 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -172,6 +172,15 @@ int vpci_assign_device(struct pci_dev *pdev) =20 return rc; } + +int vpci_reset_device_state(struct pci_dev *pdev) +{ + ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); + + vpci_deassign_device(pdev); + return vpci_assign_device(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..a71da5892e5f 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/pci.h b/xen/include/xen/pci.h index 63e49f0117e9..376981f9da98 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -156,6 +156,22 @@ struct pci_dev { struct vpci *vpci; }; =20 +struct pci_device_state_reset_method { + int (*reset_fn)(struct pci_dev *pdev); +}; + +enum pci_device_state_reset_type { + DEVICE_RESET_FLR, + DEVICE_RESET_COLD, + DEVICE_RESET_WARM, + DEVICE_RESET_HOT, +}; + +struct pci_device_state_reset { + struct physdev_pci_device dev; + enum pci_device_state_reset_type reset_type; +}; + #define for_each_pdev(domain, pdev) \ list_for_each_entry(pdev, &(domain)->pdev_list, domain_list) =20 diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index da8d0f41e6f4..b230fd374de5 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -38,6 +38,7 @@ int __must_check vpci_assign_device(struct pci_dev *pdev); =20 /* Remove all handlers and free vpci related structures. */ void vpci_deassign_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, @@ -282,6 +283,11 @@ static inline int vpci_assign_device(struct pci_dev *p= dev) =20 static inline void vpci_deassign_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