From patchwork Fri Sep 6 19:49:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1982071 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 4X0myx1hZ4z1y1G for ; Sat, 7 Sep 2024 05:49:45 +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 1smexc-0002NB-IE; Fri, 06 Sep 2024 19:49:36 +0000 Received: from mail-dm6nam12on2062.outbound.protection.outlook.com ([40.107.243.62] helo=NAM12-DM6-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 1smexb-0002Lk-8k for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 19:49:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qSMj/eBaLT43I7rMLhkPrB6DUvP243B8aOI667wXDMyCtIDA07Qa/LvlqYm/fG9IycfNi2xG8qNtRyQc5+zDkOlX/QywTLr3frSDJhmWGA16PxiovQ3HUUGKM47nT1qNjYHPa4mK7I5E5P5D+TH0nQNuX2GQG8QvnEHr3HqJ8qFC21s4+u1oapYIBOd82z72X1W/EteqtQcQQeAnpHukySYWLf0GyUUilwAGKjigv3XqVhRqlXmdT0kvDelPmbofB6zOH/pYRVURSl8dJD2a8tBhB0DA8ktY03qkAXog0JhCwf+UVhplTafj53J1ncrrjVGDsFPJYyQCEyO1ZO+eCg== 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=m2G/P99pVQik1wlMWEET+/Mjy1re1kCvd/vvnwJglj8=; b=PYaEF2hy2qJooJQ2TGgM+cfLoqMWxmcF12r/oAj3fxVT/YZLRsAjS5JZkkrvorRUn/YT4UzXnOBK+V95cI1LdBWi9uqz+kDgVBhLcgI1RBlm+IjY/sqTuLhjrGMKQ26ZSMbKl4Qloo0nGbIzxC83FRHQN7DKPOfRvbBB8Jq+UlloJHApsfSkBKPX9nDvWMtvu/uk7mzoFW4wYh9QRbWM6/3roVEA2olRxGTSlgY9zFfuvpip1dFuBH0f8C3Nf3YIpln+NJyNiOfeJYhdmxtp+QZ0tFyZCbrGsDv2WlTnhvxhGujBFbvxVXBKV4NaWn8M61GbuR6DtfD3rs9khg4M7A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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 SN7PR04CA0063.namprd04.prod.outlook.com (2603:10b6:806:121::8) by LV8PR12MB9261.namprd12.prod.outlook.com (2603:10b6:408:1ed::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Fri, 6 Sep 2024 19:49:28 +0000 Received: from SN1PEPF0002636A.namprd02.prod.outlook.com (2603:10b6:806:121:cafe::2a) by SN7PR04CA0063.outlook.office365.com (2603:10b6:806:121::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.19 via Frontend Transport; Fri, 6 Sep 2024 19:49:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SN1PEPF0002636A.mail.protection.outlook.com (10.167.241.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 6 Sep 2024 19:49:27 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 6 Sep 2024 12:49:16 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 6 Sep 2024 12:49:15 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 6 Sep 2024 12:49:15 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v3 3/6] UBUNTU: SAUCE: vfio_pci: Do not open code pci_try_reset_function() Date: Fri, 6 Sep 2024 19:49:05 +0000 Message-ID: <20240906194908.1127733-4-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240906194908.1127733-1-witu@nvidia.com> References: <20240906194908.1127733-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636A:EE_|LV8PR12MB9261:EE_ X-MS-Office365-Filtering-Correlation-Id: c99778a2-eba9-432a-5e2c-08dccead0475 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: FugRTXxjT3EARsjeTDcZr1TtuNtJJbNG/wa1fACrDaQFsTdoctAipiH2CrXmcV9w8nyghIe/OlC7RLYTzc2h8C5prFSndZ3GXpvpBpeuIg/6MBLaLIkoF9WGiSgkR7MhyybmDXSpdi3t2bpFm6szZ/H9rC1Hutueh2cheXw5JDn5qX6CAqxbxNPSzLKyIpu9iG1/b8waIN4CNJ7jKxnpiaegHunVk7hJLvekemHpMKv+yDLbbaNAeSkud5EcoOaetqKhOhMGnA3eltUc64rPSSHJl6S0L76Uaf+B5wGOLBo/tV7/7qVQ3A2FS0qhJMeluQ/UBjclnbAlb26lE3zvhj0fPa5oKd1HJZ0M8zxEbB/2+65LXUTuF92kFwYPads29aQ18L1FJJWnPeBrvwgcHHqgFvrN0zSNVeUQAGbamTP6e7+NGlGQc+VZiMr6LPIqw/zSKSr8KlcKInA8MhZSaXOJPCofNxTL7ycZSGKNJZlcUEUL45bHzyXTKJjEM1+Ld74FuYuhB6CE+6URmwoR6CCDPWebaltLvjDDsyVEpJXSbr4KWA6Ms+QBuhVQqhKnCnVIVK5piNN7Li6aG8W7ia+eNfMzz8d5y/VAwzjRkv7Tb+zzgWBjQWpfzxZKf6M/3tHyoJYKGADVSc76qDhACnO8KzuYk1TZerViLlZ+XR7BEanB8oj/WK46peoI8Mkc7Eng3FzoDqfkcnBqnjKD3k/pAlba1phjlrjJeb9lbu1RW1oBL8og1Qkv21w4NRjQU08h+qQK9/4NrU0DJTmorDG6WnNuUFMKLvYELXrpBgQVQL6UfCkotdwnxabtriC7YfeLWH4f5gDqn1KrMl2KlU50tt+IJ9SAldwZsTQHNbc8yw/xbXTfwYW4FR9+pTReXMTb4WwZpribAtwYS2c/EYFr8wHC+JZcJUIM9EZ0ajlEj57ZQ6Jqg8iCMTsZklLQ6T75paM1fkDrYa6KUGX7w4/9Wcyyy8iuzv0gnfQwwNsXXfiGi1WK8f5Dv8YRVgzAU/w5+sWHEY1FTzimZoMKv7VbyILd0FF62BtaJ8PL+GXGTzCdL/X3fvtKpAV/H7DFAE34iPkmpQ6cCWrPB1IkBJKVwXXcFTmMbyvjWA3tJcuwq/WPPmTiqgxOA7Ft88watTzudrNdtFY9K3CWZXGi8czFDbi6l5kIqK19EmWDaAgR1YeKbFu4CyTWJ5rENYXo1zTeUM7FlsQNeoPuC0/f4+a/pFiQV3+ENg6JQZ8jQiPHj8pcitb8qA8PiQ2KUQ3M4C3Scw2RtZnaQFEIPxHiPOS1AMn3oB+rpuRu0efzqH9P3BFuMxn9dMf+0mmAqDv0a2cLc5BYvW6O3a83XXef50j+eWKyxv6g55/JxNTt5L0PqnmDYph4Tn6FS0NdWzkAYRbwQuAf3DVfgX0nc6yNRaIOVJ8wEVZOS4Fu0CmN5uyATrv7h2N2stgv8KxI2wui X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230040)(82310400026)(376014)(36860700013)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 19:49:27.7982 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c99778a2-eba9-432a-5e2c-08dccead0475 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002636A.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9261 Received-SPF: softfail client-ip=40.107.243.62; envelope-from=witu@nvidia.com; helo=NAM12-DM6-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 | 41 +++++++++++++----------------- drivers/vfio/pci/vfio_pci_priv.h | 7 +++++ 3 files changed, 28 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..5904801f6f77 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,20 @@ 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); + 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 +945,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