From patchwork Wed Sep 25 17:22:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1989495 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XDNpx32wFz1xt5 for ; Thu, 26 Sep 2024 03:23:05 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1stVip-0007AQ-F3; Wed, 25 Sep 2024 17:22:39 +0000 Received: from mail-mw2nam10on2071.outbound.protection.outlook.com ([40.107.94.71] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1stVim-00079m-VU for kernel-team@lists.ubuntu.com; Wed, 25 Sep 2024 17:22:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=p/DfQF0casLBBEv+m7dbOraKVQyJJ5wWA0p6u9phobCGcfWsPP8oqoo8bcNtcPJx2hdG2syJMvaAJ+1WX4EEWbSuVpkl+plKwR+nUpeYkgFeVF03G+8Gks739Nj9+MSI0A+0vP1/xaHTJG+XM5VZj81IUTYveVMdYnbxgy1kwCyzobWnB3OeK9b+T15tIdhLPeFZyMTWAXPj4ZLbCQ/J9Fib7CHx23Yu0BAUS6YvbPk3+O32PngsGiAQ26iu+aHUodzxiE5Tcg3vqNN5ThPtmElZITNLCglFVTniEoTqNuJUf5nq9LI+QNdK8D+URJeGkZEHSxB6Gj2gJboQ9xporg== 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=Y1WVJVRnQpmze+qdR8SVbpjNX2k4p9x/BrnTwN5LLXg=; b=IZxw55QwD9jPu2xaME4y7POhdfVdg0U4T27j/8n10Sr47BYqtv0YtTllUcMdv8HZ0uwez/nYvCP0uqCLi1mABQEPbIAuf1Pzy9Kznpm29KOutFqFlvV5NCCRvKj6NoanGlSgYzHY6FdJseKMQtGi+53U5vEF+2kSfBFRX6jA+LzDZLRjohMCwRoYryYAgODU03etcBO09r9IxJEBCDgIb+kiSvjlb9zdjKKBJUDCpp8oIQn0ibmY+xLxW6o8h5kHGzDeHDKqv2z+N64KzNc1N+5v6NvR4hwklGDqKjMRlh2NFubC5rgi82i+NRygseeMWHQ4y7/kx3nATHcwfY8C3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) Received: from SN1PR12CA0075.namprd12.prod.outlook.com (2603:10b6:802:20::46) by DS0PR12MB7748.namprd12.prod.outlook.com (2603:10b6:8:130::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.28; Wed, 25 Sep 2024 17:22:31 +0000 Received: from SN1PEPF000252A3.namprd05.prod.outlook.com (2603:10b6:802:20:cafe::35) by SN1PR12CA0075.outlook.office365.com (2603:10b6:802:20::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.17 via Frontend Transport; Wed, 25 Sep 2024 17:22:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SN1PEPF000252A3.mail.protection.outlook.com (10.167.242.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.15 via Frontend Transport; Wed, 25 Sep 2024 17:22:31 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 25 Sep 2024 10:22:21 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 25 Sep 2024 10:22:21 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 25 Sep 2024 10:22:20 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v7 3/6] UBUNTU: SAUCE: vfio_pci: Do not open code pci_try_reset_function() Date: Wed, 25 Sep 2024 17:22:11 +0000 Message-ID: <20240925172214.1511114-4-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925172214.1511114-1-witu@nvidia.com> References: <20240925172214.1511114-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF000252A3:EE_|DS0PR12MB7748:EE_ X-MS-Office365-Filtering-Correlation-Id: 959b1abe-28d9-486d-3bd5-08dcdd86a374 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|36860700013|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: zx+O9yjcTb2/doRSqQvy2BMuWvSDdG3Sh7wKzhUnNLofB9MeSjjLP3WW/Bm4506tvqzUSI8qHyj2RA0VgqDxrFedo3ir+Gp1PjI5L2jWGI2KBiQhVSEv8WnHh9C3MaLn0H25h32SKND/lBftdA4+ZNweqzI0BGVGFg817qZIAS5wn6o/lubKL8AIDn4yE9mVplqyHckBd7xVmPI5cbu4V0KsqWuxTH1ZpiSD4lHjJMhgBtNbv6s7hL7y490t7yKuWM81fzmO9qnRw0BaFbpKUftJ0IBKBT/lO4goBa7qs7Kncd0EzkoPneGE1Px+uFIklVuPfhEcW5OUM4ig7BcOEPiNDxynvJS/yuAA1WMjF4uTYkALZpsHeHSv9+hiEMF2PfgxPF0jMO9FUip6TElaEEkGVjEbvrQlk+/p88cIfiINN4RwjicpmTkTBBcshN/26B0gruHaATTZi6vyiZCiF2y5zzcGkR2fSfjO9MBbyZg4wEtm6mnyssKiUHl+cokFTkCApVyIJwi23TI/S/ifn02Ubzvjo4jjaE5YwEvws0/0Kudvs1XP+TmBoMqr05laNyaMIksrS2lCuVsGIGl3gj2hMdpuXIi0ZOnyLrOo0O54FZ95LR5UMrkNin+vvxFw12Plgd3rEhTPvn4y4VOFaRqSsNxWr5fy2T9YM86SrHtcw6L7Jlx83p4QRBlPlJrOzYQBuRuZCrcjLhARGNmmzgWboV6bSHUbJbbEye30hA/vxld0h1Z5mc+tdZxJ2rpUMm754nbs0PAAYxrUAi23OtkWV2e+wWGeQYORIOal95KJHsD6rZgz8ywev1DapSuP4gz9wvraPqQX+nIufYbhbSOjbUqltGNon37VnREVhecETSgwCt2Lssfx1/S9MoozPYNPb58zFBF4zrRBIlotliXlWF8rVMjRVHJ4Y15Netf2YXHglrjWKJYHlqAK4wO89cNVsVrByPN7fIG8GNZNNWaprghThQsaKgbhZrjvmr1lTuQLh7XTkWBE2355AkSOKnkItyudLPPERdqPei/ukOlrwTxyQYhmy1wDbX6gvVszx+EYoDS5QxdpLgHWr6BX2qkBYenmQPlROGv0qk53+Na4iJyCpSlvCQoPFJYsFa2bcs8I9viv/sQjiMN7NNtqiVjSz2wWlramZihmTQsGC2nGqaSRfuzxdDCB0DvAlPshpwA8gJKjEG+m931wIxlfVFQtw6MD8tstxBei6n+FxxHsxJmUG/cnKD3QIoOXUX23M2MU3i+vYrIK9iMpXjw9GSBINjfxUQUnrchPRE73Qaq1zefvyZMEKP7Qpt2//gDaSKtpZoPNcfxR3pg0cQUZ1fncTNgoq6BnwmpOqRai7/JvFnT0WJgSuN0xWUSn9CIzwGHN045BHE9PLsJPSomhktyg+3cqv5CwVcMTK5KtNAz0FT+lIdFTMnM5PhUZPv8= X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(376014)(36860700013)(82310400026)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Sep 2024 17:22:31.6177 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 959b1abe-28d9-486d-3bd5-08dcdd86a374 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF000252A3.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7748 Received-SPF: softfail client-ip=40.107.94.71; envelope-from=witu@nvidia.com; helo=NAM10-MW2-obe.outbound.protection.outlook.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad@nvidia.com, bodong@nvidia.com, sergeygo@nvidia.com, jgg@nvidia.com, zwaksman@nvidia.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jason Gunthorpe BugLink: https://bugs.launchpad.net/bugs/2077887 FLR triggered by an emulated config space write should not behave differently from a FLR triggered by VFIO_DEVICE_RESET, currently the config space path misses the power management. Consolidate all the call sites to invoke a single function. Signed-off-by: Jason Gunthorpe Signed-off-by: William Tu --- drivers/vfio/pci/vfio_pci_config.c | 14 +++----- drivers/vfio/pci/vfio_pci_core.c | 54 +++++++++++++++++------------- drivers/vfio/pci/vfio_pci_priv.h | 7 ++++ 3 files changed, 41 insertions(+), 34 deletions(-) create mode 100644 drivers/vfio/pci/vfio_pci_priv.h diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c index 6e58b4bf7a60..78c626b8907d 100644 --- a/drivers/vfio/pci/vfio_pci_config.c +++ b/drivers/vfio/pci/vfio_pci_config.c @@ -857,11 +857,8 @@ static int vfio_exp_config_write(struct vfio_pci_core_device *vdev, int pos, pos - offset + PCI_EXP_DEVCAP, &cap); - if (!ret && (cap & PCI_EXP_DEVCAP_FLR)) { - vfio_pci_zap_and_down_write_memory_lock(vdev); - pci_try_reset_function(vdev->pdev); - up_write(&vdev->memory_lock); - } + if (!ret && (cap & PCI_EXP_DEVCAP_FLR)) + vfio_pci_try_reset_function(vdev); } /* @@ -939,11 +936,8 @@ static int vfio_af_config_write(struct vfio_pci_core_device *vdev, int pos, pos - offset + PCI_AF_CAP, &cap); - if (!ret && (cap & PCI_AF_CAP_FLR) && (cap & PCI_AF_CAP_TP)) { - vfio_pci_zap_and_down_write_memory_lock(vdev); - pci_try_reset_function(vdev->pdev); - up_write(&vdev->memory_lock); - } + if (!ret && (cap & PCI_AF_CAP_FLR) && (cap & PCI_AF_CAP_TP)) + vfio_pci_try_reset_function(vdev); } return count; diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 4f1aceadd4fb..a45cdd3cfb84 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -29,6 +29,8 @@ #include +#include "vfio_pci_priv.h" + #define DRIVER_AUTHOR "Alex Williamson " #define DRIVER_DESC "core driver for VFIO based PCI devices" @@ -648,6 +650,33 @@ int vfio_pci_register_dev_region(struct vfio_pci_core_device *vdev, } EXPORT_SYMBOL_GPL(vfio_pci_register_dev_region); +int vfio_pci_try_reset_function(struct vfio_pci_core_device *vdev) +{ + int ret; + + if (!vdev->reset_works) + return -EINVAL; + + vfio_pci_zap_and_down_write_memory_lock(vdev); + + /* + * This function can be invoked while the power state is non-D0. + * If pci_try_reset_function() has been called while the power + * state is non-D0, then pci_try_reset_function() will + * internally set the power state to D0 without vfio driver + * involvement. For the devices which have NoSoftRst-, the + * reset function can cause the PCI config space reset without + * restoring the original state (saved locally in + * 'vdev->pm_save'). + */ + vfio_pci_set_power_state(vdev, PCI_D0); + + ret = pci_try_reset_function(vdev->pdev); + up_write(&vdev->memory_lock); + + return ret; +} + long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, unsigned long arg) { @@ -929,30 +958,7 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, return ret; } else if (cmd == VFIO_DEVICE_RESET) { - int ret; - - if (!vdev->reset_works) - return -EINVAL; - - vfio_pci_zap_and_down_write_memory_lock(vdev); - - /* - * This function can be invoked while the power state is non-D0. - * If pci_try_reset_function() has been called while the power - * state is non-D0, then pci_try_reset_function() will - * internally set the power state to D0 without vfio driver - * involvement. For the devices which have NoSoftRst-, the - * reset function can cause the PCI config space reset without - * restoring the original state (saved locally in - * 'vdev->pm_save'). - */ - vfio_pci_set_power_state(vdev, PCI_D0); - - ret = pci_try_reset_function(vdev->pdev); - up_write(&vdev->memory_lock); - - return ret; - + return vfio_pci_try_reset_function(vdev); } else if (cmd == VFIO_DEVICE_GET_PCI_HOT_RESET_INFO) { struct vfio_pci_hot_reset_info hdr; struct vfio_pci_fill_info fill = { 0 }; diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_priv.h new file mode 100644 index 000000000000..4971cd95b431 --- /dev/null +++ b/drivers/vfio/pci/vfio_pci_priv.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef VFIO_PCI_PRIV_H +#define VFIO_PCI_PRIV_H + +int vfio_pci_try_reset_function(struct vfio_pci_core_device *vdev); + +#endif