From patchwork Wed Aug 31 23:12:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12961501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9702C6FA82 for ; Wed, 31 Aug 2022 23:13:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232114AbiHaXNB (ORCPT ); Wed, 31 Aug 2022 19:13:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230510AbiHaXM4 (ORCPT ); Wed, 31 Aug 2022 19:12:56 -0400 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2060.outbound.protection.outlook.com [40.107.212.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A43EF8FD9; Wed, 31 Aug 2022 16:12:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TeqOLUCESowoVd/if+CxC3rlSKbfWx+dAp/ltGaRjLZ0h4wZdpq1grVleGUe4dHA014Jk2BSrbVX+TG1Ickb0XnshpGoYPp6sXURfyPwC2rpodsFTr1OuuXJXezsI0sH4EQhpYWIVJCt/Szk1I9SpxVI9Iiasp9yIf6manqh3uFnAZdVpPHKFylNOzrNHO/1w/uDxqlvIljaRKYSLYQB6avER/MIyhhjuuv4KWeVqR0Ihons/7aNsrTetF+gQmMFj4uUMXWnPL7BnzIorL0cFpySbhdcx1IN5Y2APha54qBwIfA7dVaUEL+Xnezl4D3sO2RbTy05VamJwoeghY2oGQ== 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=z/6rbubLVDxVZJcotZ/eUCpfQERM89cbqN7lY3YK9CU=; b=fsWn9tapkbfT3rc54VqwXgqKNd7G1C9uQux/N+39CkNfqmdKxCmggKK9aN9TFsqEC6pwK3rrnY0oWLtJUwbKD6eff6HQVnDNn5fS8oTwSL1SNPNzDx1zSaIKkKgrgoO6FkPT0Kh1N0ROFD9SLCuOLWlmEgz0v1p+IE0ILeI2yuw+HPe8gjnfLzwZYVuXYwCVtHJjNcKvxdSmHwT7SKtmhLIT/+bTo++xJ1KPxLKc2urKjwbP5NHtbcdpGc7NGqdKbaRsIPo4aKVFWOj9ZcBSz4AJ3dfycUidKmlXvU7HgxZRv2wjWmERqDzBbdQOJKOv8PSXUWBjuikOLKoFDxhVpA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=z/6rbubLVDxVZJcotZ/eUCpfQERM89cbqN7lY3YK9CU=; b=erNTCBZSPiJYdSThDQgZ8MeO9SYGuWXKu1Su6CXJUIkzgsdCRvhLvT6/SIP3y8n5BbawAEZa2aU8Tb8RGfOfLFf/ZjHm8dJOVBUm2aQkIL7N33OS7kJxNsBikjkefrH7vcd6hiXDzxjW0me/B6Zsm2rT3WikErIikbHgrcdgKjpLzACgooPorrHIbirUU+B6r1ZiUWoltx2zlL9D+4G555yhJ/AdKRKk0vAuIY65hRqKEKxpuRBdhyIpdAeFDRz1JvwWOcZ+a3Ja0GDnNJB1EwZk7b1F6dED/nPz3G5svIZkvkWE9YrOfU5z/IVcIWeiVAViUWtKih19nD99hQipaA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) by DS0PR12MB6535.namprd12.prod.outlook.com (2603:10b6:8:c0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.15; Wed, 31 Aug 2022 23:12:46 +0000 Received: from MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::462:7fe:f04f:d0d5]) by MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::462:7fe:f04f:d0d5%7]) with mapi id 15.20.5588.010; Wed, 31 Aug 2022 23:12:46 +0000 From: Jason Gunthorpe To: Alex Williamson , =?utf-8?q?Christian_K?= =?utf-8?q?=C3=B6nig?= , Cornelia Huck , dri-devel@lists.freedesktop.org, kvm@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, Sumit Semwal Cc: Daniel Vetter , Leon Romanovsky , linux-rdma@vger.kernel.org, Maor Gottlieb , Oded Gabbay Subject: [PATCH v2 3/4] vfio_pci: Do not open code pci_try_reset_function() Date: Wed, 31 Aug 2022 20:12:43 -0300 Message-Id: <3-v2-472615b3877e+28f7-vfio_dma_buf_jgg@nvidia.com> In-Reply-To: <0-v2-472615b3877e+28f7-vfio_dma_buf_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR10CA0035.namprd10.prod.outlook.com (2603:10b6:208:120::48) To MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4817c742-1f29-4ed9-576c-08da8ba65026 X-MS-TrafficTypeDiagnostic: DS0PR12MB6535:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rf2f2pLLdflDTOtQBuKO3sznnIIYeMovzmTT40qmxvDyx8hPGPu7yBuPTWtmueUOnrtzvMR56FhAcE4wt3cF266/JnvugVYqd9RaqZ5wC+O07MMx4BMwgvqqkYDZNiuju0ENH0xGAUFu0n+3iK+KB0JLY8JdMVZ9Pb02MQD2CQe3NxKBSe0uKlhgQqNFqpJjRYfzdTFT/c2alki6i2JyWXqoQW5OeSAfoMeaWNDY9kXftahgbIK0+25WnF3805cVNDZh3bPeQ/Au3/DB8qqKd7f5QU3h++DbVvspCP/cIyTGjIhQCM/gPxdubzxZjvLKtetuTczVApPLueRxw8r7/9ZILvp2iT3VO6SDfJ9WQuR4EJWZTBXUk7lGKhk3p0qYPSj/QcyS0jagHwoEhxHa3INa379pgY7iXsZrohBuboHlI9mz0YgjFZ/przPQ/ByLfPCu0lp6kekpa6fNsK+iyCG7qAKqhnbH1dyYQg36UL7I0RNzXTZumoRJLb8GEjXZViuFg3IXTAZ1igPteBPsQodtSCCwYRWKQpokjOBbNimu+Dh3xIPrtLp3+ZNX/dA4tI9FzBbH6uBsviiT1jWWQM+/2Hx1lA9BJKi7g+vHLzRN9Qv+kfNfLM1EKp8GzOAO+zyOtqAZsF0Fcftzk+B/oFNGaxgSjlqMdMLe0fceagd3obQ4zz0ExCy0kAtVtqZdt/Hx+PghxlJOmrwUA25adMIZzd5Ff/LsqF7ALj+SK2rlHBngNS3pkM/IlhjySFqp X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB4192.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(136003)(396003)(39860400002)(376002)(366004)(346002)(186003)(2906002)(5660300002)(8936002)(7416002)(6506007)(2616005)(6666004)(6512007)(36756003)(6486002)(86362001)(41300700001)(26005)(478600001)(38100700002)(83380400001)(110136005)(4326008)(316002)(54906003)(66476007)(8676002)(66556008)(66946007)(4216001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tmou877ef0BDKEiGsQCZPh0v5kGKl4vkD43U20K0U3fquT1lpqmHy2Qm3IDVnV3shVmJfkxqzCeR83c0RHx1iSVbM2WyKGpt4kOdpRK4fc775tIPpYm9UhngXZeWhvgL++N0yAhr+gD2ZHxdLe15ymradE65+aVyQgLIXD6IbDTJBbWAbbbIcm+v6ZDnwF44EWmDXgFMwY+87QHT2ZM8nQ0lFrC0I9fL7J1up0BOTbx98PrIXzgOGyiF8Lu/ZqWqJEe2AE4tTAUB9NQnengYnBqkPgQQLueF7uE+8Log/+VSng8TZzq/o1AGXMLQI4o/cXdfXFILfkY7LFbKv4mZXY8AuzLsxeLEKtjijQAUbgGL0ouN4u+LtII6cmrmoE6XZ4YjSF8AzlbyZOVH7Z8Kj4R9BmFe5XkgZZ4aNPIsEjrmfUmX2wsG//ql8yu9dGXrBLfuIZkNyKL4nT4Nje2B8KNejv7lmbFCGjOsT+gC5Q0HwIyNRgd/o1wpBnp8GJjh3RzGvTCXGLgn5KZvy2l/2uC5/98P16Q9mpeR0XL8GsvUsybQNUAl/nG1IwpdoeC4T53lZCk7aurFDy X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4817c742-1f29-4ed9-576c-08da8ba65026 X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4192.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Aug 2022 23:12:45.3586 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fDooWtpdc70DHJ4gM/0i2RBZFVblqtc1Plh2CLj4szJOHZ/FVhuBfWmpOLNMXtgt X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6535 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 --- drivers/vfio/pci/vfio_pci_config.c | 14 ++++---------- drivers/vfio/pci/vfio_pci_core.c | 5 ++--- drivers/vfio/pci/vfio_pci_priv.h | 1 + 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c index 4a350421c5f62a..d22921efa25987 100644 --- a/drivers/vfio/pci/vfio_pci_config.c +++ b/drivers/vfio/pci/vfio_pci_config.c @@ -893,11 +893,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); } /* @@ -975,11 +972,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 9273f1ffd0ddd0..885706944e4d96 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -960,8 +960,7 @@ static int vfio_pci_ioctl_set_irqs(struct vfio_pci_core_device *vdev, return ret; } -static int vfio_pci_ioctl_reset(struct vfio_pci_core_device *vdev, - void __user *arg) +int vfio_pci_try_reset_function(struct vfio_pci_core_device *vdev) { int ret; @@ -1202,7 +1201,7 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, case VFIO_DEVICE_PCI_HOT_RESET: return vfio_pci_ioctl_pci_hot_reset(vdev, uarg); case VFIO_DEVICE_RESET: - return vfio_pci_ioctl_reset(vdev, uarg); + return vfio_pci_try_reset_function(vdev); case VFIO_DEVICE_SET_IRQS: return vfio_pci_ioctl_set_irqs(vdev, uarg); default: diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_priv.h index 58b8d34c162cd6..5b1cb9a9838442 100644 --- a/drivers/vfio/pci/vfio_pci_priv.h +++ b/drivers/vfio/pci/vfio_pci_priv.h @@ -60,6 +60,7 @@ void vfio_config_free(struct vfio_pci_core_device *vdev); int vfio_pci_set_power_state(struct vfio_pci_core_device *vdev, pci_power_t state); +int vfio_pci_try_reset_function(struct vfio_pci_core_device *vdev); bool __vfio_pci_memory_enabled(struct vfio_pci_core_device *vdev); void vfio_pci_zap_and_down_write_memory_lock(struct vfio_pci_core_device *vdev); u16 vfio_pci_memory_lock_and_enable(struct vfio_pci_core_device *vdev);