From patchwork Wed Oct 13 09:46:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12555309 X-Patchwork-Delegate: bhelgaas@google.com 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75795C433F5 for ; Wed, 13 Oct 2021 09:48:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5BBD760F4A for ; Wed, 13 Oct 2021 09:48:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238186AbhJMJue (ORCPT ); Wed, 13 Oct 2021 05:50:34 -0400 Received: from mail-mw2nam10on2044.outbound.protection.outlook.com ([40.107.94.44]:35744 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S237993AbhJMJuc (ORCPT ); Wed, 13 Oct 2021 05:50:32 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dE5DlpXThmeMEAcgXVhdSX0KSKjAaTHCKn+Avl/IELcJoKX207cc9/wBGkJTfTuvGb9IWtxQ7OziLOrjgnYL1LWHq210geOKZUvqAnhHoukJHtWFSpHi1PyWte45NzqCLprF0gzxhnk5G9pO/JKkhAzxCErIdQF+S+AB/ThkR89xkInv2zTj8BlwBXJ5sdgdRfOFNpcGG6W9YF3l4TxC7OrtJOAh8k69te86dxR+UkJqNvcGOf20CFCSemmeZTA3ykObRf6zzz6OXtyIkPVEMxdJ9vZPXSdQFsVJlpXVNurbP/2SXUPH08QG8iORFXapjmZ3dsZuUHA4m8e4H8rG1A== 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=/bSabJTod8iBa7Cd2YyvY1nY5RPLeJ9SxAs01AZMaXQ=; b=bAiEL91Dx5P0yPevhHf7anIcjMALDheL2WyHbmThEJtxr9/uCX3LrG0LB0AMRlaR+Ds3uGKk6TnpcYSm31BOMsmnNLZ0bz4kFjcxFVnjzvKLQO4F/EK4Wdar7NsFOTZwe0dUdFImdr7et1nNS6w+bGqDDkG5dZi+7K0z87ByzfJBhSYSL058KsB86r+VTm1OY3WBDSqjitY0gOFckM69tO3XjItc0yTlClVXTfHjNAzt5U4xKOodddTy6J38FtKtodkHVaGwVIThnYoR6sMmv//V3DlJB+CwBePL2ro0n6Pz8nVXmTERNDLB0S+d+o2Um+iBFPQiWp6sl9zrQKscRQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=/bSabJTod8iBa7Cd2YyvY1nY5RPLeJ9SxAs01AZMaXQ=; b=IogHAm5dejT342+oL9J8Xnv9QL2XnOKiPfQL9Upy0jzrcNM9I9WVBQnMyfuOSKsbnmPcPUQUqTg4YN5twOzgasoA+VcmJgBH4dQsduIa1aUEVuHoNkJsQ/FdJUbGynhQMyj7qwvKXqE8uHSZe5Wox9wNRTlYGN4dw8V63H1mQtHsxj7o0LAgyjviioSzEFaKsAmN7FxNKuBGSog3GBYtSBccA32W+FcyXREGWgztT3tPIkW+IfzTPu/F9YnXfYhOcsxJlrit4bRNwU+IzHAUnlutguiJg28tY+Gn3crsOtL8urCm+fR4SaVaGByxq1kQv9xQChMm3jZ6Bck2cJky+g== Received: from MW4PR04CA0156.namprd04.prod.outlook.com (2603:10b6:303:85::11) by MN2PR12MB3966.namprd12.prod.outlook.com (2603:10b6:208:165::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.24; Wed, 13 Oct 2021 09:48:27 +0000 Received: from CO1NAM11FT007.eop-nam11.prod.protection.outlook.com (2603:10b6:303:85:cafe::f4) by MW4PR04CA0156.outlook.office365.com (2603:10b6:303:85::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25 via Frontend Transport; Wed, 13 Oct 2021 09:48:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by CO1NAM11FT007.mail.protection.outlook.com (10.13.174.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:48:27 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 13 Oct 2021 09:48:26 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Wed, 13 Oct 2021 09:48:23 +0000 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V1 mlx5-next 01/13] PCI/IOV: Provide internal VF index Date: Wed, 13 Oct 2021 12:46:55 +0300 Message-ID: <20211013094707.163054-2-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211013094707.163054-1-yishaih@nvidia.com> References: <20211013094707.163054-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 664ee17c-2a77-4e8f-1ac2-08d98e2e9b36 X-MS-TrafficTypeDiagnostic: MN2PR12MB3966: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4M+hhRcO8VA9P6X9mPqoLwsR0g7Dg9sif0Z0aK9mHf/a2QYOD3oSZ/OfeNx4FI78PBpM999bB0YiU8joxWivjLnOm2Lmy2IBKQc4k9/ge0y4a12ducfibSPnUdskuMFZxwbYyrTciWSgzwETXwXzE0E38Ezt9xMO5maQOjcLKXR4wKSLAyhTtZLPNVZauYTZdWBRqLwNpRGPJqenQbwUnOYFaTpyA/mlqdgNdUr29nzi9mHZOQA1bnDbR36U4/dFMIeifaANe5k4q80me5m29yL7QMg70aQCrn/zj9rePqhHwCSgOsqEgU6xPiCEjjWuLtQI7QOAZpU0gC+/tuXCRW+GPBap52yhpBN9Ro3PzhfZsUL381F6rkckR6J6tcsF4AD2HMonrHKi6ogMCGHdhg7uHTEuIaZrnXwvEEIHxFbiTZyuBJfxa42LP4IiZ413guheTrdvSLJclxNMQjq6Nu3mvgcyt19u8YlZgZHn0UlMzXqGJAWW7hkd8EiOUuUCsIe4jSFnt7FjVa8y6peahjh8z3lFaMspTF5RfEO6EWc+E6uygo/B7o8euCLLariG200IZdPpmrFvCeh3Bq+WlTqwuQuwUJjyGwmBreS+T8RKnvQZ2Opfkb+nXdX8YgRfSC+2phWNx+X6cC2vXyXf5QwdFvL25aZpGygD9DZENTaQ+efqX/lRE5zO1Hb/Oc737H7U6ip9htJPDMkAT77dpw== X-Forefront-Antispam-Report: CIP:216.228.112.36;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid05.nvidia.com;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(70206006)(82310400003)(6636002)(47076005)(26005)(1076003)(7636003)(5660300002)(36756003)(86362001)(70586007)(508600001)(83380400001)(7696005)(8676002)(2906002)(8936002)(186003)(426003)(110136005)(356005)(2616005)(4326008)(107886003)(336012)(6666004)(316002)(54906003)(36860700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 09:48:27.2270 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 664ee17c-2a77-4e8f-1ac2-08d98e2e9b36 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.36];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT007.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3966 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Jason Gunthorpe The PCI core uses the VF index internally, often called the vf_id, during the setup of the VF, eg pci_iov_add_virtfn(). This index is needed for device drivers that implement live migration for their internal operations that configure/control their VFs. Specifically, mlx5_vfio_pci driver that is introduced in coming patches from this series needs it and not the bus/device/function which is exposed today. Add pci_iov_vf_id() which computes the vf_id by reversing the math that was used to create the bus/device/function. Signed-off-by: Yishai Hadas Signed-off-by: Jason Gunthorpe Signed-off-by: Leon Romanovsky --- drivers/pci/iov.c | 14 ++++++++++++++ include/linux/pci.h | 8 +++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index dafdc652fcd0..e7751fa3fe0b 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -33,6 +33,20 @@ int pci_iov_virtfn_devfn(struct pci_dev *dev, int vf_id) } EXPORT_SYMBOL_GPL(pci_iov_virtfn_devfn); +int pci_iov_vf_id(struct pci_dev *dev) +{ + struct pci_dev *pf; + + if (!dev->is_virtfn) + return -EINVAL; + + pf = pci_physfn(dev); + return (((dev->bus->number << 8) + dev->devfn) - + ((pf->bus->number << 8) + pf->devfn + pf->sriov->offset)) / + pf->sriov->stride; +} +EXPORT_SYMBOL_GPL(pci_iov_vf_id); + /* * Per SR-IOV spec sec 3.3.10 and 3.3.11, First VF Offset and VF Stride may * change when NumVFs changes. diff --git a/include/linux/pci.h b/include/linux/pci.h index cd8aa6fce204..2337512e67f0 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2153,7 +2153,7 @@ void __iomem *pci_ioremap_wc_bar(struct pci_dev *pdev, int bar); #ifdef CONFIG_PCI_IOV int pci_iov_virtfn_bus(struct pci_dev *dev, int id); int pci_iov_virtfn_devfn(struct pci_dev *dev, int id); - +int pci_iov_vf_id(struct pci_dev *dev); int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn); void pci_disable_sriov(struct pci_dev *dev); @@ -2181,6 +2181,12 @@ static inline int pci_iov_virtfn_devfn(struct pci_dev *dev, int id) { return -ENOSYS; } + +static inline int pci_iov_vf_id(struct pci_dev *dev) +{ + return -ENOSYS; +} + static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn) { return -ENODEV; } From patchwork Wed Oct 13 09:46:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12555311 X-Patchwork-Delegate: bhelgaas@google.com 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0500C43217 for ; Wed, 13 Oct 2021 09:48:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D66CD60C40 for ; Wed, 13 Oct 2021 09:48:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237993AbhJMJug (ORCPT ); Wed, 13 Oct 2021 05:50:36 -0400 Received: from mail-dm6nam10on2058.outbound.protection.outlook.com ([40.107.93.58]:34945 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S238054AbhJMJuf (ORCPT ); Wed, 13 Oct 2021 05:50:35 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f3DjYJ+StX7/dp5hDhNa4wrygcS+FEKH2wwEIA4w3Yk8xrs315T4pbGjTl0mvg20Is1iKEvrQRJv+37RA9fxRgifRhfotF1Y9oVnUUrO8/rKNvzrpbFK+tS2aHwAFg20YlG/9DfDgrtK49NA42/eY7QOypal07YQf2bseqb4KnNFRBhQHtZXhShKdIsEDy49gjTFuqMxDhivyFAt3aDiV0f/u68bRiA/5qXlJmiJJLBWxuP+cAoV80rxRRAddodC3PZmnliH+ckBEIKVwvfKkK0slvOFqG78CFPbktoijynIGQfSe2Yb9EUwAaUpUuQN8ZtYdjQJXzPOGqbcOgRFng== 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=eawxF+jFRBAH1P9hWq5BE145QVmYPfYNp1U9MJCuY0E=; b=m0fD2JPx026KRYbjawSEeKI7AtIMm+XhqXgdI6L3UYOngIX9PviP8BG43rNkR1wtIiPCzOEIBzKH02Zzog5vSRdL6yUoWLu6sqdWwZVeR1fXm+FQZLS2t/Zn65zeAKrrYjrqIbVj+NGMRHubEHf4q+dsLcFMO8gObGoTs7/TQpzor4HqB84m8fXZBc5BbLH0C/HL7TQjOQHJcknKSGDIM8hLs7McP8BvO9GcSinlJwtCic70l9cZi6NnHUKttPYC6U5L3K50krJciSCoztM5sQfCTFnb6UwxDKVjA6JGM8kBA9wcqXLnPhJNjVRL4OfuTg3VMdwg3P9uvkOsNzBFYg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=eawxF+jFRBAH1P9hWq5BE145QVmYPfYNp1U9MJCuY0E=; b=U4/0ReJp2fO7wu4M7wJAzZ9zSX4MjyOAGLDbZ7wzu8LzEm59tQt471GFklE8JVdLWKJ4okd2eM4peEMjmgrzR/IhlWgyu0QZG/rVMKEjfPKbtshvn14g/Nif1ACkFY152/sv6oIzvKUKGSa+qJnG9sRRGlSMjyE5WXlofE9HH4GoL2fnA3Q/67PUfgr+C/JU/dPNhdyrQYMm/e2EwGf0jfVZHWowLfKJ7sJRDZHYDSrJCtAk9jl5RImESeAJ6rjlg5SbMDAQmNsoNnSQkcZs3BmJmX49CAeHakR1Hs8EpeTXWNm4vnnDFZhqXxV3Y1oahwd9jAbjZMiXdgCfJdx6Gg== Received: from DM3PR12CA0089.namprd12.prod.outlook.com (2603:10b6:0:57::33) by BN6PR1201MB0227.namprd12.prod.outlook.com (2603:10b6:405:4e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Wed, 13 Oct 2021 09:48:31 +0000 Received: from DM6NAM11FT051.eop-nam11.prod.protection.outlook.com (2603:10b6:0:57:cafe::76) by DM3PR12CA0089.outlook.office365.com (2603:10b6:0:57::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Wed, 13 Oct 2021 09:48:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT051.mail.protection.outlook.com (10.13.172.243) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:48:30 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 13 Oct 2021 09:48:29 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Wed, 13 Oct 2021 09:48:26 +0000 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V1 mlx5-next 02/13] net/mlx5: Reuse exported virtfn index function call Date: Wed, 13 Oct 2021 12:46:56 +0300 Message-ID: <20211013094707.163054-3-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211013094707.163054-1-yishaih@nvidia.com> References: <20211013094707.163054-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3bef8b47-4308-4664-aa37-08d98e2e9d4b X-MS-TrafficTypeDiagnostic: BN6PR1201MB0227: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TN1FiAeem9aNKm6QcMf+VHfSoQk5FjCZi7hoKjI0NnsZRBQNHeW/Pk3WJjbw8ZxiIy9rVuVBnzvLVDnSXW3qidYLtnOGhgp7VN4HhYz7caLegrKGEvoVLuWJ3U0U9QFnfgfrGty48+Bz2WM88Vku1FzsCGHMwKu/l6vZUv7RjEdslov96RrwvQ2I8oW5XONgMpLPh39bn+Tfyo3oao6hgzvNGBn+5A5QYW3XtEbSMFJn56MjaRfx7AbUDVdhtDr6+nWVjvNsXkSfhnTAa3wJhkZ+FfzBkRqQUxd9z+BGPO3L80l3wfoOyFYIcW2zqbkWp/s0nkKfjY4p0sED9QBRRb138XZnYPBBoGQemcXpdaJUW8YuZRx1IIAuD6a71km1IVzJbn+pbc/IaaX/jRR4RSnyj3OnpML/nlk47/oQDuh17JewOaGd78SGt3mV2drIcRPYNJ8z81vRAEkQOKihSvNf27xIvX0KcZcXXhp0Vreggz9CfIXA7obDb/SEx12HhpsRH0wxIj/hUrsqmtGcFnUtW/TL5l1Zdt07T+eDCHmaOlYWrxTdODcr/LpK1D59xkYORn1XT/t7I+TIUfIXmMAnGyCazOicbjyD2OuxZirXRb+gu1WHX4MdjV/Vn6u1w/Z9zCoLPMw1dqcW6BEKAlSe8/aqC+JD0/0l8sYdZwBuyNcnUTx8fpIJlOw3NPKfAKzWvzGKVRaCM98oB5XTBg== X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(83380400001)(70206006)(6636002)(1076003)(82310400003)(2906002)(508600001)(26005)(107886003)(336012)(356005)(7636003)(54906003)(6666004)(426003)(70586007)(36756003)(86362001)(8676002)(110136005)(316002)(5660300002)(47076005)(2616005)(4326008)(8936002)(36860700001)(186003)(7696005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 09:48:30.7147 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3bef8b47-4308-4664-aa37-08d98e2e9d4b X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT051.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1201MB0227 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Leon Romanovsky Instead open-code iteration to compare virtfn internal index, use newly introduced pci_iov_vf_id() call. Signed-off-by: Leon Romanovsky Signed-off-by: Yishai Hadas --- drivers/net/ethernet/mellanox/mlx5/core/sriov.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sriov.c b/drivers/net/ethernet/mellanox/mlx5/core/sriov.c index e8185b69ac6c..24c4b4f05214 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/sriov.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/sriov.c @@ -205,19 +205,8 @@ int mlx5_core_sriov_set_msix_vec_count(struct pci_dev *vf, int msix_vec_count) mlx5_get_default_msix_vec_count(dev, pci_num_vf(pf)); sriov = &dev->priv.sriov; - - /* Reversed translation of PCI VF function number to the internal - * function_id, which exists in the name of virtfn symlink. - */ - for (id = 0; id < pci_num_vf(pf); id++) { - if (!sriov->vfs_ctx[id].enabled) - continue; - - if (vf->devfn == pci_iov_virtfn_devfn(pf, id)) - break; - } - - if (id == pci_num_vf(pf) || !sriov->vfs_ctx[id].enabled) + id = pci_iov_vf_id(vf); + if (id < 0 || !sriov->vfs_ctx[id].enabled) return -EINVAL; return mlx5_set_msix_vec_count(dev, id + 1, msix_vec_count); From patchwork Wed Oct 13 09:46:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12555313 X-Patchwork-Delegate: bhelgaas@google.com 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 077F5C433F5 for ; Wed, 13 Oct 2021 09:48:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E719560F4A for ; Wed, 13 Oct 2021 09:48:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239137AbhJMJul (ORCPT ); Wed, 13 Oct 2021 05:50:41 -0400 Received: from mail-bn7nam10on2079.outbound.protection.outlook.com ([40.107.92.79]:3739 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S238054AbhJMJul (ORCPT ); Wed, 13 Oct 2021 05:50:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VZMeezSSpNCqyLqtGHiyLB0+QPtvEd9laSJPRkwQay+u7xg9yrwOiGbs8fkHsDvsZWKY5EpexTLYmXRdelMcEEd12+ioBnsEelxEl9JyxtmzCpyFgb+8Etc+Q9DpFkEMnDhicl58KqzUztU54Dee38dciB9AmE8OuljMSjvv/Jo9h0bi4i/71a5jej6AxLnUOeEgGaMs27wy458lj/MUgiiOiW1W4LH6DI6lhU8Wq07dTvsT3aUExri4u21Zo3NwrD1fPASkLxhHWH0hSHExmJ63DMtT7CIeE3wLKmeqsff3edNDdm6GvQj10SeZ8cz+4S0dQZ/LAZY77T6o/TFMQQ== 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=ATQOdGVF4dTjbvMJ1bmmazMNjFwWqMg4M5PKqHqf20k=; b=ENq/hsvIygegJGnDVqaf+qWYtYgHeAsAfs0e9NA9RsgSKBrahdbrjGFzVAVkLChi51FlbUDR+6rXTmYcqmIoRE+Eut+Ow2Gyfj1SfGdhXlnNUDGEYGb2f3qI1Wm5HqqA+150EqvIjKqQ3nz7sWrZvZNfCDpcumeBblthU6ZmeoMF/cRiUr4ut9VFDl8jr71ECMtfNApvLOjAsyxTTcEzGVVwP3sa35Zmk/BUuyggAFge+tK7mgvFrQJCaNoae7xfXEG4FoXYZxtlV1uggoEAPKe/bpHccXlsAlCHkpPX6/KO9Z9DsQJfIUoSXSRpVDk7uBr039rh9/7WUfmoCGyAAA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=ATQOdGVF4dTjbvMJ1bmmazMNjFwWqMg4M5PKqHqf20k=; b=RWuFkJW9nkvhZ5TZ+4sLkDIsjGq1yKHvWz2dwOhl2lcEfUtok7EGuw6bmfXFGjKCtSPdvIoODeMp/kwtDG893R7bLDjhMGD3sSo7vLENluc+5vfa84yoSUgF6aW9H/HOAtSzPdSEx9xEUvoxL3IUSP6mX6N7wNmIiQ28WB2c+FAgW0+unwygk3a5OpiUE7v3ez227XdioKUKBObG+x5WJWTGPC6vtAF/dYGVmKig02ME1dP4Q7k7yOF3nN/mxy7L71sFs70DmBWtTzMVwaZsbFPNV8wh0h8o8nCQshqH0bGk1nENW9phWdhQwD8lIKIgFTYJbmn3+NSOqOh6mbAJCQ== Received: from MW4PR03CA0357.namprd03.prod.outlook.com (2603:10b6:303:dc::32) by DM6PR12MB4636.namprd12.prod.outlook.com (2603:10b6:5:161::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Wed, 13 Oct 2021 09:48:36 +0000 Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:303:dc:cafe::b6) by MW4PR03CA0357.outlook.office365.com (2603:10b6:303:dc::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:48:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by CO1NAM11FT060.mail.protection.outlook.com (10.13.175.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:48:35 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 13 Oct 2021 09:48:33 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Wed, 13 Oct 2021 09:48:29 +0000 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V1 mlx5-next 03/13] net/mlx5: Disable SRIOV before PF removal Date: Wed, 13 Oct 2021 12:46:57 +0300 Message-ID: <20211013094707.163054-4-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211013094707.163054-1-yishaih@nvidia.com> References: <20211013094707.163054-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6eed1d71-9118-4a3a-73e2-08d98e2ea04d X-MS-TrafficTypeDiagnostic: DM6PR12MB4636: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: K/8WXcu5JMewWlP4zPze8NwceZczgO+EJT1AVwWlmh9dzATuFHCyqp3+/Ndoay1AQBJB449mDA74x6YafyhUUs86sU/1DaAPhucIlS7DHrOXVvwRdhj2MBYbtHZeoju3AGri8p6wTEhViEO7N7ARShByN29JfgRKFdf4WfFpoU9mKMnZ1KjFDv8cwx09TvQqzYSjiMkU8Mb0+g0Me8chpCK5JUti9E++6osbTVVnL7vKgB0tWvzFSYSJt7NxS91D+ME0LNx33HGaZkacwhML9wsUAcQcK5Flw8edH7W1TZRMVh+VPqFbD+NSYfIxiJGqAWzxAr8nc1lDtgpybog+VxxJ0nNpDDwA4X08wnRGWBmD0I1UARHYdJnvHCfvY/UXJ3b7PVcOYBQxkVOLXgmvVZTPaUSgL4g59ShtOBDoP06iz3WFkjFhj6QuOK0hgR0xEeSGCr6401KsakTb9Y3iIG3DqYY/4YcWpv/IUIS1vUP+X8AB4mEaSSAhtrkJ1TwQvM4+kcfQK060keBj4kW37U1LvDKULEzzqPJmbJxKM5DkJT3uT7MHdSbxIEVDm2UK36DHSmeFc8MCSHmVzW54HW3vIjVJx1DUEGuyEeiKOCBrcdONViUtNFpCqT6w8gJncm9soF8mVdsCTefMR2w/qWZgxfNjKkDo1yjob5vMr5KoIkAJlNazjjV1aQlgl+sr2x2hL6eQ8LcszpX/xxnrow== X-Forefront-Antispam-Report: CIP:216.228.112.36;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid05.nvidia.com;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(82310400003)(36756003)(8936002)(426003)(36860700001)(83380400001)(54906003)(7636003)(356005)(4326008)(5660300002)(26005)(336012)(186003)(110136005)(86362001)(47076005)(70586007)(107886003)(70206006)(2906002)(6666004)(508600001)(7696005)(1076003)(2616005)(6636002)(316002)(8676002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 09:48:35.7553 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6eed1d71-9118-4a3a-73e2-08d98e2ea04d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.36];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4636 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Virtual functions depend on physical function for device access (for example firmware host PAGE management), so make sure to disable SRIOV once PF is gone. This will prevent also the below warning if PF has gone before disabling SRIOV. "driver left SR-IOV enabled after remove" Next patch from this series will rely on that when the VF may need to access safely the PF 'driver data'. Signed-off-by: Yishai Hadas Signed-off-by: Leon Romanovsky --- drivers/net/ethernet/mellanox/mlx5/core/main.c | 1 + drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h | 1 + drivers/net/ethernet/mellanox/mlx5/core/sriov.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c index 79482824c64f..0b9a911acfc1 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c @@ -1558,6 +1558,7 @@ static void remove_one(struct pci_dev *pdev) struct mlx5_core_dev *dev = pci_get_drvdata(pdev); struct devlink *devlink = priv_to_devlink(dev); + mlx5_sriov_disable(pdev); devlink_reload_disable(devlink); mlx5_crdump_disable(dev); mlx5_drain_health_wq(dev); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h b/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h index 230eab7e3bc9..f21d64416f7f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h @@ -140,6 +140,7 @@ void mlx5_sriov_cleanup(struct mlx5_core_dev *dev); int mlx5_sriov_attach(struct mlx5_core_dev *dev); void mlx5_sriov_detach(struct mlx5_core_dev *dev); int mlx5_core_sriov_configure(struct pci_dev *dev, int num_vfs); +void mlx5_sriov_disable(struct pci_dev *pdev); int mlx5_core_sriov_set_msix_vec_count(struct pci_dev *vf, int msix_vec_count); int mlx5_core_enable_hca(struct mlx5_core_dev *dev, u16 func_id); int mlx5_core_disable_hca(struct mlx5_core_dev *dev, u16 func_id); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sriov.c b/drivers/net/ethernet/mellanox/mlx5/core/sriov.c index 24c4b4f05214..887ee0f729d1 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/sriov.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/sriov.c @@ -161,7 +161,7 @@ static int mlx5_sriov_enable(struct pci_dev *pdev, int num_vfs) return err; } -static void mlx5_sriov_disable(struct pci_dev *pdev) +void mlx5_sriov_disable(struct pci_dev *pdev) { struct mlx5_core_dev *dev = pci_get_drvdata(pdev); int num_vfs = pci_num_vf(dev->pdev); From patchwork Wed Oct 13 09:46:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12555315 X-Patchwork-Delegate: bhelgaas@google.com 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4919C433FE for ; Wed, 13 Oct 2021 09:48:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BDF8560F4A for ; Wed, 13 Oct 2021 09:48:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239161AbhJMJum (ORCPT ); Wed, 13 Oct 2021 05:50:42 -0400 Received: from mail-bn7nam10on2079.outbound.protection.outlook.com ([40.107.92.79]:16544 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S239088AbhJMJul (ORCPT ); Wed, 13 Oct 2021 05:50:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oGhCoGTrs0Ywgr6I/vtO11luWYntUKB2XGkSYdqOSLjOBsY62Tew+F/SbZ15eu8ZZzeOFuUT7tUlRx9vu+sZUyhG3+t91qz3aYLPcePVN5pSd5PK+wYM3dAGApgcgaaUrVMguTtb/78TpF78nuwKm8B91CUivPvPN5oun5ZkLbPrhq8+uM77PYzX0i+NcHMsMg3r+u3NWqF/rLSVJtZjKki9VaaErZU/a203M7I8h0ieCb0sMofyEtMrH9SBk0O6d2OI9l5LX/jA8iWdl7VU+n0sv6UdNdfkhWTps73SOLEXXlY4uWBqsZeBgCFepwA3OzvhVWUqeSgY4WZnzym4nA== 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=cv9rIA1aETU/Br6Z1NTt9bnAf2Pupu0QwloBKZrPakY=; b=BtAm8psB2Bz+qYcXYhm9tb0wU/a0AQmTfx/vDsXCuPkCHCpOuXu5ct1w1VY0223+xIJ4BkvAJzjWVLfBLpG1KplMgz1KwwhcE37Rwd0kbBvRs1HUBJTJJzLvLq+blS36KgkbKZ2ZCjrsRH2QHqG98UtmfRe+4dQXoWV2uYnJ2Fu6+0G4i4eDsDzME/WedjL4+OJ+3QTE9FJN5hv5fJKU2/bBf+fA8QCNL1AMkzQd5pVL719GFPpI11WSqIc4ISSbLsnBCMUao0TI8ZlVM8bAH3HardyqgHCwAPFMMMO1APQsYdyaprzW4AlNlK0W2n60RVzsYwAZTKqrQhphMNdnnQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=cv9rIA1aETU/Br6Z1NTt9bnAf2Pupu0QwloBKZrPakY=; b=NryLKTHv8aepXol5wgPZEkdXXrgG8wcKjWR3rJEFdfRbAagRdI122RHQvBezmzK/XGDbkuE/KYhXQ3NxXnxC1Gza0gfTfCZMfGGI2tz5EER0dIX1q6QCTgwijOsB9txkSjUA60M9oj3YNaamfyAQZhQXYkEndRNjnhWUzSnnpYYeSDRH1Bg9hNJAeJy2kYzUjMsJjWp5exzMah5EvC4hC9z/ezjmF4XAjzlhn+nlAFjBJd5ywOp4Rx+8g0hVa0ZxOBRB9Nk19PgK58VI1tK0nFSW+A3QxuVWC81Kan85LhPB4ppx/3LZ/TZizDOf6B0mMdcD+vgpDtnycIJBjofZcg== Received: from DM5PR20CA0037.namprd20.prod.outlook.com (2603:10b6:3:13d::23) by BN8PR12MB3378.namprd12.prod.outlook.com (2603:10b6:408:61::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25; Wed, 13 Oct 2021 09:48:37 +0000 Received: from DM6NAM11FT032.eop-nam11.prod.protection.outlook.com (2603:10b6:3:13d:cafe::89) by DM5PR20CA0037.outlook.office365.com (2603:10b6:3:13d::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Wed, 13 Oct 2021 09:48:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT032.mail.protection.outlook.com (10.13.173.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:48:37 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 13 Oct 2021 09:48:36 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 13 Oct 2021 09:48:36 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Wed, 13 Oct 2021 09:48:33 +0000 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V1 mlx5-next 04/13] PCI/IOV: Allow SRIOV VF drivers to reach the drvdata of a PF Date: Wed, 13 Oct 2021 12:46:58 +0300 Message-ID: <20211013094707.163054-5-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211013094707.163054-1-yishaih@nvidia.com> References: <20211013094707.163054-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 31490a3d-8463-47be-389b-08d98e2ea118 X-MS-TrafficTypeDiagnostic: BN8PR12MB3378: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ie+kPxsQKWKJ4UlP4jZm32Rbz2FCNErcDbydfi73bd/FEz+CeymF9C48jSuDmXaauPo4O1PXklO3aSMzV8G0aDj1xEmSwpjoenIwFP4WQw/cTRS9g8Asbo0SVRbUjDJggmoGH7LJ7GtcJBFMDqlc4XrNNRMfT/Xh0T7oHITsCp/LBK1RJvLCVzmP4Gsr1dudKOc2uT3CuJgEHJRYG3OD10nZN3Wefljf5FehUaQjPGMXKFDOh8CmSbsyRVMhGeNajKG1qocTC0ew57flL9UaOhSiRgy2ntiTR6Be7dxVqh5aXuf6rryR4u/9KG34s7/dgCoONHbqLMy26dbsfYaSa10hgsEc7suzErqh5Tfva8/qhX/BCjNWZEgyf5yyZv06DNkUfLQbPP9A8re1VlLx19j/X9MYUbqMsgZ5JaktUt3Wx9/qQz61/MfiG+lpcoWZq+DzXq+Lg6fFyQ6gux8u/sXfWIwDjadWgYazwZY476nc32elKJjKVkHHGphKRtLkjtO/fJ3WYD0mO2S9ctUg73xJB3VYs420Z1wkgjvyK3vA98saViE7zxUuKQ9Hdl7a+FGeBL6LHAbGJG1ogspm9MVlCufkxa04NzBlvlzkXS+RlG9HLeoV+6sGjSIzkpaoEFNjNOwh/F1N0mv/CTOzsVijWiN7rqqH6CFlruyytl8HizD7MC9j9YxAuYS1SSruxtg2rcazfe/hr70D0DFF3A== X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(316002)(36860700001)(7636003)(8676002)(4326008)(356005)(36756003)(5660300002)(2906002)(8936002)(110136005)(82310400003)(7696005)(1076003)(86362001)(107886003)(54906003)(47076005)(26005)(70206006)(70586007)(508600001)(426003)(6636002)(2616005)(186003)(83380400001)(336012)(6666004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 09:48:37.0875 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 31490a3d-8463-47be-389b-08d98e2ea118 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT032.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3378 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Jason Gunthorpe There are some cases where a SRIOV VF driver will need to reach into and interact with the PF driver. This requires accessing the drvdata of the PF. Provide a function pci_iov_get_pf_drvdata() to return this PF drvdata in a safe way. Normally accessing a drvdata of a foreign struct device would be done using the device_lock() to protect against device driver probe()/remove() races. However, due to the design of pci_enable_sriov() this will result in a ABBA deadlock on the device_lock as the PF's device_lock is held during PF sriov_configure() while calling pci_enable_sriov() which in turn holds the VF's device_lock while calling VF probe(), and similarly for remove. This means the VF driver can never obtain the PF's device_lock. Instead use the implicit locking created by pci_enable/disable_sriov(). A VF driver can access its PF drvdata only while its own driver is attached, and the PF driver can control access to its own drvdata based on when it calls pci_enable/disable_sriov(). To use this API the PF driver will setup the PF drvdata in the probe() function. pci_enable_sriov() is only called from sriov_configure() which cannot happen until probe() completes, ensuring no VF races with drvdata setup. For removal, the PF driver must call pci_disable_sriov() in its remove function before destroying any of the drvdata. This ensures that all VF drivers are unbound before returning, fencing concurrent access to the drvdata. The introduction of a new function to do this access makes clear the special locking scheme and the documents the requirements on the PF/VF drivers using this. Signed-off-by: Jason Gunthorpe Signed-off-by: Leon Romanovsky Signed-off-by: Yishai Hadas Acked-by: Bjorn Helgaas --- drivers/pci/iov.c | 29 +++++++++++++++++++++++++++++ include/linux/pci.h | 7 +++++++ 2 files changed, 36 insertions(+) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index e7751fa3fe0b..ca696730f761 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -47,6 +47,35 @@ int pci_iov_vf_id(struct pci_dev *dev) } EXPORT_SYMBOL_GPL(pci_iov_vf_id); +/** + * pci_iov_get_pf_drvdata - Return the drvdata of a PF + * @dev - VF pci_dev + * @pf_driver - Device driver required to own the PF + * + * This must be called from a context that ensures that a VF driver is attached. + * The value returned is invalid once the VF driver completes its remove() + * callback. + * + * Locking is achieved by the driver core. A VF driver cannot be probed until + * pci_enable_sriov() is called and pci_disable_sriov() does not return until + * all VF drivers have completed their remove(). + * + * The PF driver must call pci_disable_sriov() before it begins to destroy the + * drvdata. + */ +void *pci_iov_get_pf_drvdata(struct pci_dev *dev, struct pci_driver *pf_driver) +{ + struct pci_dev *pf_dev; + + if (dev->is_physfn) + return ERR_PTR(-EINVAL); + pf_dev = dev->physfn; + if (pf_dev->driver != pf_driver) + return ERR_PTR(-EINVAL); + return pci_get_drvdata(pf_dev); +} +EXPORT_SYMBOL_GPL(pci_iov_get_pf_drvdata); + /* * Per SR-IOV spec sec 3.3.10 and 3.3.11, First VF Offset and VF Stride may * change when NumVFs changes. diff --git a/include/linux/pci.h b/include/linux/pci.h index 2337512e67f0..639a0a239774 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2154,6 +2154,7 @@ void __iomem *pci_ioremap_wc_bar(struct pci_dev *pdev, int bar); int pci_iov_virtfn_bus(struct pci_dev *dev, int id); int pci_iov_virtfn_devfn(struct pci_dev *dev, int id); int pci_iov_vf_id(struct pci_dev *dev); +void *pci_iov_get_pf_drvdata(struct pci_dev *dev, struct pci_driver *pf_driver); int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn); void pci_disable_sriov(struct pci_dev *dev); @@ -2187,6 +2188,12 @@ static inline int pci_iov_vf_id(struct pci_dev *dev) return -ENOSYS; } +static inline void *pci_iov_get_pf_drvdata(struct pci_dev *dev, + struct pci_driver *pf_driver) +{ + return ERR_PTR(-EINVAL); +} + static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn) { return -ENODEV; } From patchwork Wed Oct 13 09:46:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12555317 X-Patchwork-Delegate: bhelgaas@google.com 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDC4CC433FE for ; Wed, 13 Oct 2021 09:48:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C780F60C40 for ; Wed, 13 Oct 2021 09:48:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239174AbhJMJuq (ORCPT ); Wed, 13 Oct 2021 05:50:46 -0400 Received: from mail-dm6nam10on2068.outbound.protection.outlook.com ([40.107.93.68]:48044 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S239088AbhJMJup (ORCPT ); Wed, 13 Oct 2021 05:50:45 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kflvq7wvoFGOKlF9APtW/MLy+MHHIVY0KUMkxUgUgWXJA89N2V8TO1JavP+j+yzY3HLFwsOtQRBt9r5WKDWoApWkirUXFvn9sEcyX9Qkvn0+mI1cdEEmsMa4Os03uv7d5wxIzxGkjPvpBrQYbumWJKC+iqEGJIl3G/qjMq1tVuswDR0/oUXxi2TUOzWDBVPq+sfZ9YONndcv0xf7Y33FnDctxcyDzhtKI1azm4h81tuxgPbKVTyAW3YaOyq9atRi25rXL++YXlCAx4EEpoz+a6/9XZfEQwHxIwrIxANgU67MqAHY0mNgEivMlgBuqwO65u8BiRrO+spjMRwYkYU/YA== 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=0Rg93GuPxk5N0KtlMyEKO/efa5SGHQlpbOGoEZBLbxs=; b=dYsRC7zbm78bU6I+4BrINBTkznDMQALnIhAPz393APClsFyZqobbc3BKtcut4w3QIN/SVFc/cxrHUWO4U64NbT/vIPTCyHC0jWQpY2vXhh8f+zmK10CD5/cnSUHk8A/8FXh3Baqs+PkR22GN/K2eu8o+HnuZBjfwNSiynPQTiBzqjbmE+lhzmbceY0NmSL9PsczygxZeNQND314ISGwPuECiJiEcMPYqbD/thB6cJXcIGIzGshjgpV6jAv6iMS1ZN+g8aZt4y4Lwj42T6Nbit4Rqe1CvVRnVOwiwCy9xHZ8vrH1hCZnPkCAHyPt/DEW4BvMpJ45SLKzoDpjIxgWTeA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=0Rg93GuPxk5N0KtlMyEKO/efa5SGHQlpbOGoEZBLbxs=; b=IgQAQnWJYflGp8iLMOL5IgVUe+gMtEydEdafSQsalKZkr8zqPDkKU+PoCHp478B4hP1Yw9zNZntI9DSqrNXb4eXdvqWpX2ihkVxpjmOGA8Z+6Rm63ngf//s/l0zp3fbdTnIa7UYy/dETS9jtTuNhBzPZXBqha/Fb9OS+/OFWt4XYl/CalOoEbjmpnCMwEcVTVYkJZ0Ay16Y/LydXi9vsZtw/7fPZmbRAr/gfAxLPQJTsRrnscwIxGEE16DXJO6ONo0jlRT0G24YPwjCN7yYMcPRTEXNI9KdsZa6w+v2tjnE1TmoC3p6oWy8aZc5W5gyQk0FcPhkLZH2y1s8pi+y3gg== Received: from BN0PR04CA0146.namprd04.prod.outlook.com (2603:10b6:408:ed::31) by BN6PR12MB1235.namprd12.prod.outlook.com (2603:10b6:404:20::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15; Wed, 13 Oct 2021 09:48:40 +0000 Received: from BN8NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ed:cafe::65) by BN0PR04CA0146.outlook.office365.com (2603:10b6:408:ed::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.24 via Frontend Transport; Wed, 13 Oct 2021 09:48:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT063.mail.protection.outlook.com (10.13.177.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:48:40 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 13 Oct 2021 02:48:39 -0700 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Wed, 13 Oct 2021 09:48:36 +0000 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V1 mlx5-next 05/13] net/mlx5: Expose APIs to get/put the mlx5 core device Date: Wed, 13 Oct 2021 12:46:59 +0300 Message-ID: <20211013094707.163054-6-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211013094707.163054-1-yishaih@nvidia.com> References: <20211013094707.163054-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1e37f6da-7c9c-4381-9906-08d98e2ea34d X-MS-TrafficTypeDiagnostic: BN6PR12MB1235: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZEczcYr2QqtNBG76yo2TnshSfGpttvv/mddVwXRfvEjDxA7rGDH8CCG/hDIZS6wwSAMMzVLV4XrdYUSY7/wIMbbu0coktk41QTpjA3k+XaVvU2relH0Fb4CauGRT0XZqmQZNy4J0e7KKH2oU9EIihS+Mt7gT11sfJNRMsLwZ+eH815ZfOabmWPeHQHEi/NZWVt0aTeAh8BYXa6Vkhh9zlw8gO7VM3Y/MwgBAmVz89onzOfdMPnXRj8FaFMFfJl9F5HNG3mbUGSkdMmOdTNgubyR3zX4pHmsnLDZYdRBMaO989Ov9vPwB3oTvLrgPvdIMyr9Mf767CoEQM8aUVEvl9YTQgewzkfemjDH6ffcFD1C7/Rg88MPNzkwZnfncynlLfPOkibsIJeU0mKmAah7vToQAjo0xA4oPTFEhNXCtaXVAdB0vuWO/dcSaA5mFVB8RoO5UEEJX4fU86ihav/F2K32at2WVGoqWeTwdz03R7VZkoBPurfmwSD/yU9ykUGKaVyzqTCbTJRFk1PwpnkMH6j5/XrA5BuhJppjo9gxO5RX2jy13XDFl6j4Lijp+8rMkDxD3iQofXdplEoYlfX1Qk/cqS436tqMXPwQNTe4jrq/+OWGp5EslyCIwaw3uPuIOVuiPoSGEzcjt8So+B6M9Yzam7qskolE0X4/TWUHYwE5iAQa+0VPHDbHL9Aqw1uzw7jZk9Tp7DIrLA4O5UU9tzQ== X-Forefront-Antispam-Report: CIP:216.228.112.32;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid01.nvidia.com;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(47076005)(83380400001)(54906003)(1076003)(508600001)(316002)(110136005)(356005)(2906002)(86362001)(6666004)(8936002)(36756003)(186003)(26005)(70206006)(36860700001)(107886003)(82310400003)(426003)(6636002)(70586007)(7636003)(5660300002)(4326008)(336012)(8676002)(2616005)(7696005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 09:48:40.7230 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1e37f6da-7c9c-4381-9906-08d98e2ea34d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.32];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT063.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1235 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Expose an API to get the mlx5 core device from a given VF PCI device if mlx5_core is its driver. Upon the get API we stay with the intf_state_mutex locked to make sure that the device can't be gone/unloaded till the caller will complete its job over the device, this expects to be for a short period of time for any flow that the lock is taken. Upon the put API we unlock the intf_state_mutex. The use case for those APIs is the migration flow of a VF over VFIO PCI. In that case the VF doesn't ride on mlx5_core, because the device is driving *two* different PCI devices, the PF owned by mlx5_core and the VF owned by the vfio driver. The mlx5_core of the PF is accessed only during the narrow window of the VF's ioctl that requires its services. This allows the PF driver to be more independent of the VF driver, so long as it doesn't reset the FW. Signed-off-by: Yishai Hadas Signed-off-by: Leon Romanovsky --- .../net/ethernet/mellanox/mlx5/core/main.c | 43 +++++++++++++++++++ include/linux/mlx5/driver.h | 3 ++ 2 files changed, 46 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c index 0b9a911acfc1..38e7c692e733 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c @@ -1796,6 +1796,49 @@ static struct pci_driver mlx5_core_driver = { .sriov_set_msix_vec_count = mlx5_core_sriov_set_msix_vec_count, }; +/** + * mlx5_vf_get_core_dev - Get the mlx5 core device from a given VF PCI device if + * mlx5_core is its driver. + * @pdev: The associated PCI device. + * + * Upon return the interface state lock stay held to let caller uses it safely. + * Caller must ensure to use the returned mlx5 device for a narrow window + * and put it back with mlx5_vf_put_core_dev() immediately once usage was over. + * + * Return: Pointer to the associated mlx5_core_dev or NULL. + */ +struct mlx5_core_dev *mlx5_vf_get_core_dev(struct pci_dev *pdev) + __acquires(&mdev->intf_state_mutex) +{ + struct mlx5_core_dev *mdev; + + mdev = pci_iov_get_pf_drvdata(pdev, &mlx5_core_driver); + if (IS_ERR(mdev)) + return NULL; + + mutex_lock(&mdev->intf_state_mutex); + if (!test_bit(MLX5_INTERFACE_STATE_UP, &mdev->intf_state)) { + mutex_unlock(&mdev->intf_state_mutex); + return NULL; + } + + return mdev; +} +EXPORT_SYMBOL(mlx5_vf_get_core_dev); + +/** + * mlx5_vf_put_core_dev - Put the mlx5 core device back. + * @mdev: The mlx5 core device. + * + * Upon return the interface state lock is unlocked and caller should not + * access the mdev any more. + */ +void mlx5_vf_put_core_dev(struct mlx5_core_dev *mdev) +{ + mutex_unlock(&mdev->intf_state_mutex); +} +EXPORT_SYMBOL(mlx5_vf_put_core_dev); + static void mlx5_core_verify_params(void) { if (prof_sel >= ARRAY_SIZE(profile)) { diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h index 441a2f8715f8..197a76ea3f0f 100644 --- a/include/linux/mlx5/driver.h +++ b/include/linux/mlx5/driver.h @@ -1138,6 +1138,9 @@ int mlx5_dm_sw_icm_alloc(struct mlx5_core_dev *dev, enum mlx5_sw_icm_type type, int mlx5_dm_sw_icm_dealloc(struct mlx5_core_dev *dev, enum mlx5_sw_icm_type type, u64 length, u16 uid, phys_addr_t addr, u32 obj_id); +struct mlx5_core_dev *mlx5_vf_get_core_dev(struct pci_dev *pdev); +void mlx5_vf_put_core_dev(struct mlx5_core_dev *mdev); + #ifdef CONFIG_MLX5_CORE_IPOIB struct net_device *mlx5_rdma_netdev_alloc(struct mlx5_core_dev *mdev, struct ib_device *ibdev, From patchwork Wed Oct 13 09:47:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12555319 X-Patchwork-Delegate: bhelgaas@google.com 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A850FC433EF for ; Wed, 13 Oct 2021 09:48:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9268A60C40 for ; Wed, 13 Oct 2021 09:48:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239171AbhJMJuu (ORCPT ); Wed, 13 Oct 2021 05:50:50 -0400 Received: from mail-dm6nam12on2075.outbound.protection.outlook.com ([40.107.243.75]:57441 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S239088AbhJMJus (ORCPT ); Wed, 13 Oct 2021 05:50:48 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dpBrmjHGleRlZ2VAW4oosuSwWEaWRx6RNu0qBJETV1rwuFUhUZfKMNtLKPsiCLpdGoRdBpifE2fiTiDNYTHaZo3l3n67Cvheq0LE+XKN6uBeFPwgSZYE3wbIze0z5msRHxuuY2ZHhjw+oZ7aCK1QCB/y/0nw4OWV8jDV4aTLNzEMr7Au3qLca3AQe3qF5NEY6qIlSBS6chR2pJc7a7VFJcRsLSnyZnsy5agJJnC4stGSb9YWRxJ83c1aZBirNVTRDtbUOWx5oCGMZuj347QI9y6PHPut21UkPCMstONBGZDiDBBaQ89ShcVEAR4FP55puV/KaeUMRK9jTLI2QZx7Dg== 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=C89Jlk8BDEI17QHQ1FU/2vPIIO2h4K4F/VMusgvFzJI=; b=nj81+8yJWetqS5d4jb6eUnCpyVPqj1N0EH0oyQvik7mYX0RV13AqYkSuG+3IRlqDRRMODgns3wYwKoGu4PxXnN4t77K5RO61d6H9KXJFctJVmG9NPcknrWBUFXynkxpAc6HeQWEqcyAuLzhTB0egTkRWgz7M62i/RavGL1orkdWcnyiwC+ycuNBcShzHTd2AzsDVYxyM3ebWlf0ihwHTU+sSjxJThSuLLbW6E7N6i1XPipkdKKs5veZyydA1Zs36S+YA51bbU6GGOFEew63y6tRqgj1+5n4x2uAsAJIAUqHjr3sq0Ebz4UtjjaLAYUe1yfE3RqHgHJDjAkYnpKyang== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=C89Jlk8BDEI17QHQ1FU/2vPIIO2h4K4F/VMusgvFzJI=; b=fzVLkTKbHC0fiHcwFX+szjF5ovXSC3Xi5iZ396EXJiHACMXwqX/MPAqrwYP0M5IffxC0rU/nYwnpQlK7JF/j/VwEHhFWN5gK7nXKElvzpkPkDhtkWrR7n8TCbkwdeZPMJp2JdEuZi3nKgOwAR8H2ueBby2RMllPyA87dfccPh4Zk8KhJAWA24dpPUxoNKFZLtXw9HPw966Gf5Q6shODdIsZkwuR26l+8ymjoinQBHI/J8+6T8ELh3CWmjm9vUi+fc9SLuytu8tqzxLS0/5vC0xIRupbKPLgD5HwVZh0AoNPstSqA6oBRGO9tGk03ae9BEZYkXlOQp/LKjz9FyeJ2lA== Received: from MW4PR04CA0184.namprd04.prod.outlook.com (2603:10b6:303:86::9) by SN6PR12MB2766.namprd12.prod.outlook.com (2603:10b6:805:78::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25; Wed, 13 Oct 2021 09:48:43 +0000 Received: from CO1NAM11FT020.eop-nam11.prod.protection.outlook.com (2603:10b6:303:86:cafe::2a) by MW4PR04CA0184.outlook.office365.com (2603:10b6:303:86::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25 via Frontend Transport; Wed, 13 Oct 2021 09:48:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by CO1NAM11FT020.mail.protection.outlook.com (10.13.174.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:48:43 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 13 Oct 2021 09:48:43 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Wed, 13 Oct 2021 09:48:39 +0000 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V1 mlx5-next 06/13] vdpa/mlx5: Use mlx5_vf_get_core_dev() to get PF device Date: Wed, 13 Oct 2021 12:47:00 +0300 Message-ID: <20211013094707.163054-7-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211013094707.163054-1-yishaih@nvidia.com> References: <20211013094707.163054-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 61371716-5dd2-4c9c-3df5-08d98e2ea4d8 X-MS-TrafficTypeDiagnostic: SN6PR12MB2766: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3173; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: F89HwVCRef7agAr4DMDTr8OtSqMZ03HNg8mhtsf3Nbpf7l9HiZD3INntW5k1Mve20C1V/40nWcOTgZkEiyPsIKohxpL3dDGcqPq8Fgv6FmBygfnuyTK/XQSLGgLp1wHjcUnHRzvOxJoiJsxeaCr82/l+Cva+YpdBwlMzPHzy9TVnffVT2LD7QnKyM65XLqmAts6ByJCBe69wz2sBlvyWwLKKVzt9TkCP2eag/WPZdbzFQmHT1LBQl/dqYc2pvEgfpNyUj/Bum/sYpzAc35QUggrB9kbzSIepTEz9SvHJPKnax74nPL4TDnRpPWdIYFdQFZjCcRkYddyscTU4AB0uSoEoBUWv1/KvQhC/nwwwkxu1ylEFSmg1pz72OazggGeN/9I9FLtqCkmUoCdm0rMNOuaqGeyXmju9N0ZY/3qoTtk+7aPo746/YMissL0+c+gVwdh2NJMDON6g/FF+LUvDyeqqRExyUBmFkAt6NWkhxCG3M3i5DHoKP8+TjEiSpajOyFunUZDUVBjurk5ApilMFQFfOrdIPkQy+CbiLGC4WsWEr2wUh+GurK8uxjg1w9h4zZpOZOgtyrhNI9IZlKT0RIftI9qlXaLG+LH68Q0QsJ9lUYCdFzsTPNGic+DlYnuCVDNg9QNbzcOOlxBBl+/1sDgAavFJ60zxhym/pk4f+ryK5g6uNn+8pzlG3wtFMD//L+VKG6uYEgziq7idFgR/MA== X-Forefront-Antispam-Report: CIP:216.228.112.36;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid05.nvidia.com;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(2616005)(7636003)(86362001)(8936002)(70206006)(70586007)(54906003)(336012)(2906002)(6666004)(110136005)(316002)(426003)(8676002)(6636002)(83380400001)(4326008)(26005)(7696005)(36860700001)(1076003)(508600001)(82310400003)(356005)(186003)(47076005)(107886003)(5660300002)(36756003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 09:48:43.3581 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 61371716-5dd2-4c9c-3df5-08d98e2ea4d8 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.36];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT020.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2766 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Use mlx5_vf_get_core_dev() to get PF device instead of accessing directly the PF data structure from the VF one. The mlx5_vf_get_core_dev() API in its turn uses the generic PCI API (i.e. pci_iov_get_pf_drvdata) to get it. Signed-off-by: Yishai Hadas Signed-off-by: Leon Romanovsky --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 5c7d2a953dbd..97b8917bc34d 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -1445,7 +1445,10 @@ static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd) size_t read; u8 mac[ETH_ALEN]; - pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev)); + pfmdev = mlx5_vf_get_core_dev(mvdev->mdev->pdev); + if (!pfmdev) + return status; + switch (cmd) { case VIRTIO_NET_CTRL_MAC_ADDR_SET: read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->riov, (void *)mac, ETH_ALEN); @@ -1479,6 +1482,7 @@ static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd) break; } + mlx5_vf_put_core_dev(pfmdev); return status; } @@ -2261,8 +2265,11 @@ static void mlx5_vdpa_free(struct vdpa_device *vdev) free_resources(ndev); mlx5_vdpa_destroy_mr(mvdev); if (!is_zero_ether_addr(ndev->config.mac)) { - pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev)); - mlx5_mpfs_del_mac(pfmdev, ndev->config.mac); + pfmdev = mlx5_vf_get_core_dev(mvdev->mdev->pdev); + if (pfmdev) { + mlx5_mpfs_del_mac(pfmdev, ndev->config.mac); + mlx5_vf_put_core_dev(pfmdev); + } } mlx5_vdpa_free_resources(&ndev->mvdev); mutex_destroy(&ndev->reslock); @@ -2449,8 +2456,11 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name) goto err_mtu; if (!is_zero_ether_addr(config->mac)) { - pfmdev = pci_get_drvdata(pci_physfn(mdev->pdev)); + pfmdev = mlx5_vf_get_core_dev(mdev->pdev); + if (!pfmdev) + goto err_mtu; err = mlx5_mpfs_add_mac(pfmdev, config->mac); + mlx5_vf_put_core_dev(pfmdev); if (err) goto err_mtu; @@ -2497,8 +2507,13 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name) err_res: mlx5_vdpa_free_resources(&ndev->mvdev); err_mpfs: - if (!is_zero_ether_addr(config->mac)) - mlx5_mpfs_del_mac(pfmdev, config->mac); + if (!is_zero_ether_addr(config->mac)) { + pfmdev = mlx5_vf_get_core_dev(mdev->pdev); + if (pfmdev) { + mlx5_mpfs_del_mac(pfmdev, config->mac); + mlx5_vf_put_core_dev(pfmdev); + } + } err_mtu: mutex_destroy(&ndev->reslock); put_device(&mvdev->vdev.dev); From patchwork Wed Oct 13 09:47:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12555321 X-Patchwork-Delegate: bhelgaas@google.com 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57EDCC433F5 for ; Wed, 13 Oct 2021 09:48:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 41F736008E for ; Wed, 13 Oct 2021 09:48:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239182AbhJMJu5 (ORCPT ); Wed, 13 Oct 2021 05:50:57 -0400 Received: from mail-bn8nam11on2040.outbound.protection.outlook.com ([40.107.236.40]:22625 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S238054AbhJMJuw (ORCPT ); Wed, 13 Oct 2021 05:50:52 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HlWVxy9vArmiSzag5pQPEU6sACLAiid9Kiyopapik48SdSA2eWI/yDeg4yGaC3BPvJ3F2ophMoxEribtjF7MiSoGmwN1NcAKoD7p+vZ2VLY95RXvO3tKG08O4XtIms1xxz2ZL54mQRhXcuVhn2TZe1FRhrlsc5KvAOJnXESSLaUzrnyB3y83kT7ACaYe7gL/WspN235zryFzkFg5amvCDIe2AUoOOqtAIutKHj9jbYVulu22XhSXQYMr+pdwcc/NFxBu+/aUXQhit1JYOGyhA4BAGUWFH17fji7tCDiVyfhpyiUHtuISQH8v4IdB59UAhG4EzDqWcrWSzQm6mg32Vg== 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=7NbaxVIHev3mJq8019+LcbPy1A6au682iKmTvV+19xA=; b=MGuE8H3e/q0D5ifxgjrMNNvxnQYTiTyotO4bFoFAwM4N6yhjuljLQExNaRYJ/NhtEIeKxj8xd8jUWk8x8BRvPg6JZvxP7IJQMyBlXJAxvTDjoLCNMMDQAyxdGMcH9gZfEG/P80KiaznR5dm8aOvex9luZCiPCXYjsjx5++YhvkSiOTm88XB+XJ8LW0QhXJ0KltpX5RTefBDP0/Ueae9VYl/RYLQpUS4PumouJYmLO4X08qWO2Mj4A8AhgZzFI7Yt7UNB6hdnfOT1TYs4P12FRSdve1+IOd5vbY3DE7Z7WkjkagJCh3DQ+LjEBkTLFvdsx+eAMTi1svJ43V7meA0JrQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=7NbaxVIHev3mJq8019+LcbPy1A6au682iKmTvV+19xA=; b=lfP0tK7BD+uKtG/QilruHKmNHJKxy3yQ3Es3wB4fw+5JCCShn5RoJbVjJAif+NgxFBGmNIbZ2d/sNgdt0uXSagZWpyVQkq+BsZehnuDGuf5XDSrcID+L6Icv3vn/BLeDgKDzKqsG7JdI3eLOqMVJQyW8JS5CElhgsl8pAUQSflzsF0gcO6nfDULM10B9NnXYgetr8FV9Ppbej1Z5R/9R0g6ssLGGBR7dagXDy+jx5FMfcuPiKfMVzXpJ+M76bRhjh9zpLyy4ODQ+XVjbMOG/7A59DJeye0DWRoroA9+T+ik1ezPjn2OU65hcM6X8UoUjR8d6cyYbi8jfEkBQQ6FDfw== Received: from MW4PR03CA0226.namprd03.prod.outlook.com (2603:10b6:303:b9::21) by BN9PR12MB5177.namprd12.prod.outlook.com (2603:10b6:408:11a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.20; Wed, 13 Oct 2021 09:48:47 +0000 Received: from CO1NAM11FT057.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b9:cafe::c3) by MW4PR03CA0226.outlook.office365.com (2603:10b6:303:b9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:48:47 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by CO1NAM11FT057.mail.protection.outlook.com (10.13.174.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:48:47 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 13 Oct 2021 09:48:46 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Wed, 13 Oct 2021 09:48:43 +0000 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V1 mlx5-next 07/13] vfio: Add 'invalid' state definitions Date: Wed, 13 Oct 2021 12:47:01 +0300 Message-ID: <20211013094707.163054-8-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211013094707.163054-1-yishaih@nvidia.com> References: <20211013094707.163054-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2d31da9e-ed47-4c70-9427-08d98e2ea70b X-MS-TrafficTypeDiagnostic: BN9PR12MB5177: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Lk/jgtiFQ9i8VQnvYzoHW46gHuTUixLYK6aJcrUs1YYcFb/59xvAhA97JWB+sM29nehuNq5PeSsPaEvaS0cpjcuTmc+wVwyqxfxdKnktvn2E7acjGfA5kUJsIhhhZ21YxqhUJfKOfNgy6XAgC7dQTpYMrTb0vLzy9JIG8rcpwMokz87Zy2/W6mJBfX4ZS0r3PmfNAyizZfIyTNkwhBS3YG9gPHmHs4JO88Sx5VaFJZiJ3rf0gy5JOF9dr2akXZigkw09/c7Wvr/rSyO1af+m5YqAoGLTzoyhDdLv8H+1/LO6/ynADnGIVvrUZPw2c89n9IkKJsIfIJR34jL5X9p5Ykz6jEIaoaUs+ojwQR1yDLIt6LQZR3rxUFnBpduEuPiTgtY5IJWtpfHTy73gIfDQL9ZzAEWro1ciR5HTDPlNsFDHyZpRXNXbTpu47YKmBtxYjUyRjEbCJDvZ1tgygxql9os4L5T+DN3VxSdCS0H1rMenP39+1jP1IRjQvEwP3sR4TfHnSiS512xQR2FPTKnY48mlSEMf60K4yURJtWGTf5dIWMj9uiFzRTaEDbQXguczAEQ+0QcV0+wRrBBcTUzRWJ+dRUNZv9Ok/0cbDQCUfPBFMxZCulykVfc+ehluBCrR8ndZihCqWRBwJ17zgK7uoQjLWAPyJqNGQIBpd9OekFMgCDTIssqRBeFOOayopWqGmM8mAXpbqcFwgg2btow5Kg== X-Forefront-Antispam-Report: CIP:216.228.112.36;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid05.nvidia.com;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(4326008)(356005)(7696005)(70586007)(2906002)(2616005)(36756003)(26005)(6636002)(70206006)(47076005)(54906003)(8936002)(1076003)(36860700001)(82310400003)(316002)(110136005)(107886003)(186003)(83380400001)(508600001)(86362001)(426003)(336012)(8676002)(5660300002)(7636003)(6666004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 09:48:47.0730 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2d31da9e-ed47-4c70-9427-08d98e2ea70b X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.36];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT057.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5177 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Add 'invalid' state definition to be used by drivers to set/check invalid state. In addition dropped the non complied macro VFIO_DEVICE_STATE_SET_ERROR (i.e SATE instead of STATE) which seems unusable. Fixes: a8a24f3f6e38 ("vfio: UAPI for migration interface for device state") Signed-off-by: Yishai Hadas Signed-off-by: Leon Romanovsky --- include/linux/vfio.h | 5 +++++ include/uapi/linux/vfio.h | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/linux/vfio.h b/include/linux/vfio.h index b53a9557884a..6a8cf6637333 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -252,4 +252,9 @@ extern int vfio_virqfd_enable(void *opaque, void *data, struct virqfd **pvirqfd, int fd); extern void vfio_virqfd_disable(struct virqfd **pvirqfd); +static inline bool vfio_is_state_invalid(u32 state) +{ + return state >= VFIO_DEVICE_STATE_INVALID; +} + #endif /* VFIO_H */ diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index ef33ea002b0b..7f8fdada5eb3 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -609,6 +609,7 @@ struct vfio_device_migration_info { #define VFIO_DEVICE_STATE_RUNNING (1 << 0) #define VFIO_DEVICE_STATE_SAVING (1 << 1) #define VFIO_DEVICE_STATE_RESUMING (1 << 2) +#define VFIO_DEVICE_STATE_INVALID (VFIO_DEVICE_STATE_RESUMING + 1) #define VFIO_DEVICE_STATE_MASK (VFIO_DEVICE_STATE_RUNNING | \ VFIO_DEVICE_STATE_SAVING | \ VFIO_DEVICE_STATE_RESUMING) @@ -621,9 +622,6 @@ struct vfio_device_migration_info { ((state & VFIO_DEVICE_STATE_MASK) == (VFIO_DEVICE_STATE_SAVING | \ VFIO_DEVICE_STATE_RESUMING)) -#define VFIO_DEVICE_STATE_SET_ERROR(state) \ - ((state & ~VFIO_DEVICE_STATE_MASK) | VFIO_DEVICE_SATE_SAVING | \ - VFIO_DEVICE_STATE_RESUMING) __u32 reserved; __u64 pending_bytes; From patchwork Wed Oct 13 09:47:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12555323 X-Patchwork-Delegate: bhelgaas@google.com 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71C92C433EF for ; Wed, 13 Oct 2021 09:49:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 528156008E for ; Wed, 13 Oct 2021 09:49:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239225AbhJMJvQ (ORCPT ); Wed, 13 Oct 2021 05:51:16 -0400 Received: from mail-mw2nam08on2048.outbound.protection.outlook.com ([40.107.101.48]:62144 "EHLO NAM04-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S239226AbhJMJuz (ORCPT ); Wed, 13 Oct 2021 05:50:55 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gWNddMr4S+BvcU0KV1mbTNGK0smTw/CSOyLNc5Rb9UTCJujv6t/jO36Xsqqey6YsUF8cWHvpTUn5t0g0b+TPYFsDxt61a5S+auaIFWsUrfrBhQI5+n6j3YAVXyievJkIsg7DXaGJ23YVF4pvvY8+uuEUHR4RAgBTvUrJV+bjVqzlE8/JB0x1+RiS90sa/3p+eMizzoID/hwrM/+qc9Bsw+0TLQ0QUYPhz4ANk15KEnyOwVHdlni75Fj7CkGLi/WZUw19wEKaFpCOCcOV11peip/XOYGNWz7Eh2muyWE5ww7k1bnFYHIBluI6JsGR4m7qLWyx9u1PKxInOyN4eO1n4g== 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=DOcFU6eSD++XS6aHs3kXEvGIdsHFeir924wVdQSptkg=; b=OiPWjAKxzai4Hlb9v8nWKeVhB5nmqwZIOTE8MOgSVARTmgnrmQ4ry1PwkvtO21SVfoEB+7cOyDqYKkodSSwMxBVnYjP9BqF4ThI+1ciGcswTbq6aTOS1Vzi0DuzuE+G6VytL0G73Kqx52ct+hJS1FBE/424Angtb65HL5XoW4clJUaZrWlhZp/qST5XfnFdGpFsRktojVEay3IYN4Wj/w9KSAVejLdNmaR0ZmP0Io5jDl0gEnhxdXY/izHpUWrTUUrWxzAcrDuRLuE0zLv8TIkYcVbNzwEBm07O+r95wMn1kSsGe0VpiPbMdG8AbaKKKEkwd2i2R5qVE+IHpPJb8Ew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=DOcFU6eSD++XS6aHs3kXEvGIdsHFeir924wVdQSptkg=; b=Z0bE2BR4eKugUGLi0tFkNVGh+zBWwOGev129IKBx84AYSQpXygnEI8GHpjewq0AFBgkxJSGkQP+uF7KCDKJJQ46wAyNJv1mQJiwXO2dQk/FW930buQygK1DY1ax3AtPFsKkggTR/TPx3huE+qcEksPTsD+cf02xD3RbYkTAfzGwHv9BsZQU4HBDe1bpSsLDAakr/Z05hb0STUY9Ud4F9qxAoe0Jf7Fq7Q6Nhp8Q7ALOcKLVrfzgbaZjC6qHi4KCbTo/cYyg0uVY6nkFZjSdfYecWlAHE142l3mIZ+g7QF6HkI60NCmbPsIcWbsFWl5d6jKqGBTuiHzduRgxaNEPw9A== Received: from BN9PR03CA0478.namprd03.prod.outlook.com (2603:10b6:408:139::33) by MW2PR12MB2474.namprd12.prod.outlook.com (2603:10b6:907:9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25; Wed, 13 Oct 2021 09:48:51 +0000 Received: from BN8NAM11FT041.eop-nam11.prod.protection.outlook.com (2603:10b6:408:139:cafe::73) by BN9PR03CA0478.outlook.office365.com (2603:10b6:408:139::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25 via Frontend Transport; Wed, 13 Oct 2021 09:48:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT041.mail.protection.outlook.com (10.13.177.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:48:50 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 13 Oct 2021 02:48:49 -0700 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Wed, 13 Oct 2021 09:48:46 +0000 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V1 mlx5-next 08/13] vfio/pci_core: Make the region->release() function optional Date: Wed, 13 Oct 2021 12:47:02 +0300 Message-ID: <20211013094707.163054-9-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211013094707.163054-1-yishaih@nvidia.com> References: <20211013094707.163054-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0f4491e2-2970-4796-6f6b-08d98e2ea96a X-MS-TrafficTypeDiagnostic: MW2PR12MB2474: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VUvdaRh1lo9iawjO2tdE8Q0kt5IIO9mVxxY8836DA7d5750GEc2qj2dofvFNkfTRIlO+lty+c5EO6i6t8DEZkQoD4XoC0Sa5IFqY0F5B6eQI55YQwjWVnVGrVSrCzuhfUXGge/jzekRVxs4fS+VTD/i1Z/dRNEMFEL/vDlgQYaKtVj/Hhu5dfhft/lOPkzzZMZWi9XBZIZ2+A9ktqHGeSagQrcNzVaKYhb/pXSW2VoBZZM353sY+awv1trlaR9f8ytDn0zmLbLqzfLAJiTTjQ0M/m1I3yJ1qHHxDtUFsqhS0U5HIsUNpxBubF4VsVKNttTiHwO9JrplGASWHg0PG8tmofOxjVboaTtJVopEEQxPGW2Wwxj//jvNCknArWsfyMWabs6SoBHG7HHuU4s+VtAbyRLcdzz6mdouVe9k6BKSHyjsyEKwYIUh3Z9GE2PsrhPFlj1thv7uWHkbGhp4qCCh2NMp/qrtzr9m7Ki89oyJmRlRGC4jkAalYe5IAHxaX2lylwrXLH5+8EsyMLf8BVGTuFqlfeLWHIJEYinG7BC1E3rwmX94AS4x9pB79ImPPcxaaIqOejIFisSsQeVS7uCilSqEKHVdsfC1/2d3I0w20O0cycmqJK8ha1q6CYs1RUneis9IAo1XWaD1XremoIgLfZB/C1IwV6ylj/aj+OErwWo+sttoHol35g1fhj4JSvUePtarwbsaISNMrSyEmLg== X-Forefront-Antispam-Report: CIP:216.228.112.32;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid01.nvidia.com;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(186003)(2906002)(5660300002)(8676002)(70586007)(110136005)(316002)(86362001)(83380400001)(6666004)(54906003)(107886003)(1076003)(8936002)(36860700001)(82310400003)(336012)(356005)(70206006)(47076005)(6636002)(7696005)(426003)(36756003)(26005)(7636003)(508600001)(4326008)(2616005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 09:48:50.9861 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0f4491e2-2970-4796-6f6b-08d98e2ea96a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.32];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT041.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR12MB2474 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Make the region->release() function optional as in some cases there is nothing to do by driver as part of it. This is needed for coming patch from this series once we add mlx5_vfio_pci driver to support live migration but we don't need a migration release function. Signed-off-by: Yishai Hadas Signed-off-by: Leon Romanovsky --- drivers/vfio/pci/vfio_pci_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index a03b5a99c2da..e581a327f90d 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -341,7 +341,8 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev) vdev->virq_disabled = false; for (i = 0; i < vdev->num_regions; i++) - vdev->region[i].ops->release(vdev, &vdev->region[i]); + if (vdev->region[i].ops->release) + vdev->region[i].ops->release(vdev, &vdev->region[i]); vdev->num_regions = 0; kfree(vdev->region); From patchwork Wed Oct 13 09:47:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12555325 X-Patchwork-Delegate: bhelgaas@google.com 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75BD0C433EF for ; Wed, 13 Oct 2021 09:49:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5494060F4A for ; Wed, 13 Oct 2021 09:49:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239207AbhJMJvj (ORCPT ); Wed, 13 Oct 2021 05:51:39 -0400 Received: from mail-bn8nam11on2063.outbound.protection.outlook.com ([40.107.236.63]:19392 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S239189AbhJMJu7 (ORCPT ); Wed, 13 Oct 2021 05:50:59 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ECPoXST55l+Y8WAxSoh/mXlJkwNIguRc1XJCBOH4WWTI5oSiO3LpoE+cft/HBkXB1/d5HZAgjsJuNv9oLp97UxidADv2dyElLs73Ir7aqa/Uy0jXvuWeSv/uUyYURMxQhSWKz/sI4ABYygUv4k54oHdwz+DfzsmW6kH+3oJvwQHmML3blGXq+KAaofXVsodvJ67FTObGkL8slUJaKTLOOmRUpJEsvd0ATENUkw5atrciAum5uqVZXvA3Dldvg9UnF44AlEkFDc/v7uZ1VwaJVKKmwOeOmdxVQkZ/JgJ8/9CNi9FIA/YXhuyuWAgOA8HRWuGRT8b8+1/2LvuevRy0Tg== 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=R7DbtBQIcZF4LUA2VaUaiDzMK1m8SVbr7xND56mts4w=; b=IpvpOHZfrnRUfbxVwkr0LV1vy7Q0WZektc9FyrBmbv+U8aAXfJCJh6LFl1iR7ncFXSIdU4KWMueDkQlLVcv7iANHbRl+y36yiXsKdrkIzRcBTBmM/vddIrgcPm5Il3CHhrwfFkzD7Pa2qG92Rn4Ef8eo8Jo0MIJgcQW0HciI+LIFcAvlOY0dIpOpKaAM8xpG6ahZJ/1XC2CZLW5oAAaPwXIuJJ4A7QKanny9g4sjVJMG0eoxncOZryXpIzjY4zQSqkHESzkjvrZs1g9uFY72d0PmWDAqN5Wes4KTp+5y/KLHVJxNC7SZ/1wVdtUep9ZvKjKk/eTFDojnreJaxyz/mA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=R7DbtBQIcZF4LUA2VaUaiDzMK1m8SVbr7xND56mts4w=; b=HSC6t3DjjG9mgnBXB+2Bjgig+PlIHP1yMQJF4jC4r4ZjUXR3I8klb8mB0on624aR5CGGAT0jURl7oqOWJtZ+Kln/b91VITlEchsQMjx82cfehTazSVj8lGhCcYrgUtAH4TITPg7Qgv+S6vbmGL/hrijplX79e6wwmHwycyefcWk8/SpmjJJ/HaOZ/FMO8CajwiA1qir9ip1mnkDbgF9341SC6Y8QJ0JK78YTUXALUo3BDYxhcTv20ZxENqlLQ2Gj5kDAJfoRKfcc6HwebEdC+9EhGqvnji3Kt0f/Cx3JTh/eAwBesQdBarOQVblNKVR0iMkrs8TaWtQV83SXTbaGkA== Received: from MWHPR14CA0007.namprd14.prod.outlook.com (2603:10b6:300:ae::17) by MWHPR12MB1535.namprd12.prod.outlook.com (2603:10b6:301:5::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.19; Wed, 13 Oct 2021 09:48:53 +0000 Received: from CO1NAM11FT064.eop-nam11.prod.protection.outlook.com (2603:10b6:300:ae:cafe::db) by MWHPR14CA0007.outlook.office365.com (2603:10b6:300:ae::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:48:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by CO1NAM11FT064.mail.protection.outlook.com (10.13.175.77) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:48:53 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 13 Oct 2021 09:48:53 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Wed, 13 Oct 2021 09:48:49 +0000 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V1 mlx5-next 09/13] net/mlx5: Introduce migration bits and structures Date: Wed, 13 Oct 2021 12:47:03 +0300 Message-ID: <20211013094707.163054-10-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211013094707.163054-1-yishaih@nvidia.com> References: <20211013094707.163054-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d814046d-d7df-4292-3b41-08d98e2eaae9 X-MS-TrafficTypeDiagnostic: MWHPR12MB1535: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mPnb+DhHhupLwgoITXEENL9VhwrT2a+AitWROGVbSKBLjhcwIM9RM+Mrzid8LI4CoKvziN3I56YBxZoq5u5FokpTvPPciPI1EHxkucwtcCbPL9zkuLTLggZ0/iwWP07PicxY87BaLsIisDtOIAqxzr4ASPccWEepuTqYzPX2NDvWKrpEgqJPSUH9/pLwfi6WVqL1bBVk5WhJ9c3W1e1qx2TncBcj0CbQdJFFvl/GYdKYhtifPNC9tfiLrD9RxIpoUGAcHAsbHmsqeJT6jC9ia9CSIkJcaTjq+MclYvMm0xaHUwdsOB51d2sSFqc2gJA3OTiIDGgyQcWq3IQlkhoowosKpYHt0WGnS4d/v//uDgMd5SdIYOYQ5NAVRwkwBvAMZZtPao7CbHHX/TEihWdi9iuJ/xR4tJGWN/tMR0ni/nce2dHivAWj0oGMDbX4ZCB4xKSxJpWOhOI3fxyIwDjPVt90Q3m9GTwIL9MvXTFbn8z4o3392WYgHA4OFp1QTMhjRw7MoBAxca+nsAmK7LstgiCbztUNfJ7tSptilZV/MYKSXhGFr7eHxvymC2OUTFVfg+29i53NM2vVsSJClGmQvV3FYuXATJ30aB4TCA7Nj0/5rIUo+FrGPEB6YqiMNE63PrAES+MtCO0JHzD+V3QRusiBIiQPTg63BIF5R9AyV3widuoruDn5CGhQ0nKw+yg/OA18MceTkVtAaXBGyQYosw== X-Forefront-Antispam-Report: CIP:216.228.112.36;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid05.nvidia.com;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(2906002)(36756003)(356005)(86362001)(508600001)(7696005)(36860700001)(5660300002)(110136005)(47076005)(316002)(36906005)(54906003)(7636003)(2616005)(4326008)(6666004)(70206006)(70586007)(82310400003)(26005)(426003)(6636002)(8936002)(1076003)(83380400001)(8676002)(186003)(336012)(107886003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 09:48:53.5584 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d814046d-d7df-4292-3b41-08d98e2eaae9 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.36];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT064.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1535 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Introduce migration IFC related stuff to enable migration commands. Signed-off-by: Yishai Hadas Signed-off-by: Leon Romanovsky --- include/linux/mlx5/mlx5_ifc.h | 145 +++++++++++++++++++++++++++++++++- 1 file changed, 144 insertions(+), 1 deletion(-) diff --git a/include/linux/mlx5/mlx5_ifc.h b/include/linux/mlx5/mlx5_ifc.h index 399ea52171fe..f7bad4ccc24f 100644 --- a/include/linux/mlx5/mlx5_ifc.h +++ b/include/linux/mlx5/mlx5_ifc.h @@ -126,6 +126,11 @@ enum { MLX5_CMD_OP_QUERY_SF_PARTITION = 0x111, MLX5_CMD_OP_ALLOC_SF = 0x113, MLX5_CMD_OP_DEALLOC_SF = 0x114, + MLX5_CMD_OP_SUSPEND_VHCA = 0x115, + MLX5_CMD_OP_RESUME_VHCA = 0x116, + MLX5_CMD_OP_QUERY_VHCA_MIGRATION_STATE = 0x117, + MLX5_CMD_OP_SAVE_VHCA_STATE = 0x118, + MLX5_CMD_OP_LOAD_VHCA_STATE = 0x119, MLX5_CMD_OP_CREATE_MKEY = 0x200, MLX5_CMD_OP_QUERY_MKEY = 0x201, MLX5_CMD_OP_DESTROY_MKEY = 0x202, @@ -1719,7 +1724,9 @@ struct mlx5_ifc_cmd_hca_cap_bits { u8 reserved_at_682[0x1]; u8 log_max_sf[0x5]; u8 apu[0x1]; - u8 reserved_at_689[0x7]; + u8 reserved_at_689[0x4]; + u8 migration[0x1]; + u8 reserved_at_68e[0x2]; u8 log_min_sf_size[0x8]; u8 max_num_sf_partitions[0x8]; @@ -11146,4 +11153,140 @@ enum { MLX5_MTT_PERM_RW = MLX5_MTT_PERM_READ | MLX5_MTT_PERM_WRITE, }; +enum { + MLX5_SUSPEND_VHCA_IN_OP_MOD_SUSPEND_MASTER = 0x0, + MLX5_SUSPEND_VHCA_IN_OP_MOD_SUSPEND_SLAVE = 0x1, +}; + +struct mlx5_ifc_suspend_vhca_in_bits { + u8 opcode[0x10]; + u8 uid[0x10]; + + u8 reserved_at_20[0x10]; + u8 op_mod[0x10]; + + u8 reserved_at_40[0x10]; + u8 vhca_id[0x10]; + + u8 reserved_at_60[0x20]; +}; + +struct mlx5_ifc_suspend_vhca_out_bits { + u8 status[0x8]; + u8 reserved_at_8[0x18]; + + u8 syndrome[0x20]; + + u8 reserved_at_40[0x40]; +}; + +enum { + MLX5_RESUME_VHCA_IN_OP_MOD_RESUME_SLAVE = 0x0, + MLX5_RESUME_VHCA_IN_OP_MOD_RESUME_MASTER = 0x1, +}; + +struct mlx5_ifc_resume_vhca_in_bits { + u8 opcode[0x10]; + u8 uid[0x10]; + + u8 reserved_at_20[0x10]; + u8 op_mod[0x10]; + + u8 reserved_at_40[0x10]; + u8 vhca_id[0x10]; + + u8 reserved_at_60[0x20]; +}; + +struct mlx5_ifc_resume_vhca_out_bits { + u8 status[0x8]; + u8 reserved_at_8[0x18]; + + u8 syndrome[0x20]; + + u8 reserved_at_40[0x40]; +}; + +struct mlx5_ifc_query_vhca_migration_state_in_bits { + u8 opcode[0x10]; + u8 uid[0x10]; + + u8 reserved_at_20[0x10]; + u8 op_mod[0x10]; + + u8 reserved_at_40[0x10]; + u8 vhca_id[0x10]; + + u8 reserved_at_60[0x20]; +}; + +struct mlx5_ifc_query_vhca_migration_state_out_bits { + u8 status[0x8]; + u8 reserved_at_8[0x18]; + + u8 syndrome[0x20]; + + u8 reserved_at_40[0x40]; + + u8 required_umem_size[0x20]; + + u8 reserved_at_a0[0x160]; +}; + +struct mlx5_ifc_save_vhca_state_in_bits { + u8 opcode[0x10]; + u8 uid[0x10]; + + u8 reserved_at_20[0x10]; + u8 op_mod[0x10]; + + u8 reserved_at_40[0x10]; + u8 vhca_id[0x10]; + + u8 reserved_at_60[0x20]; + + u8 va[0x40]; + + u8 mkey[0x20]; + + u8 size[0x20]; +}; + +struct mlx5_ifc_save_vhca_state_out_bits { + u8 status[0x8]; + u8 reserved_at_8[0x18]; + + u8 syndrome[0x20]; + + u8 reserved_at_40[0x40]; +}; + +struct mlx5_ifc_load_vhca_state_in_bits { + u8 opcode[0x10]; + u8 uid[0x10]; + + u8 reserved_at_20[0x10]; + u8 op_mod[0x10]; + + u8 reserved_at_40[0x10]; + u8 vhca_id[0x10]; + + u8 reserved_at_60[0x20]; + + u8 va[0x40]; + + u8 mkey[0x20]; + + u8 size[0x20]; +}; + +struct mlx5_ifc_load_vhca_state_out_bits { + u8 status[0x8]; + u8 reserved_at_8[0x18]; + + u8 syndrome[0x20]; + + u8 reserved_at_40[0x40]; +}; + #endif /* MLX5_IFC_H */ From patchwork Wed Oct 13 09:47:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12555327 X-Patchwork-Delegate: bhelgaas@google.com 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2077EC433F5 for ; Wed, 13 Oct 2021 09:49:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 095AC6008E for ; Wed, 13 Oct 2021 09:49:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239208AbhJMJvo (ORCPT ); Wed, 13 Oct 2021 05:51:44 -0400 Received: from mail-sn1anam02on2062.outbound.protection.outlook.com ([40.107.96.62]:18985 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S239253AbhJMJvD (ORCPT ); Wed, 13 Oct 2021 05:51:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eHf4ho0BZ2SYU89aoCZATXAXyCUk0BxpyPZZr1PE+LNllUns4qdoK8CzRnbQNXvWG99KodLEstzgubcqlJ8h3CfxdCMLwrNWor6dni06/o59Rh7aIHDHt4E8bs7Q07K6hZb3Iz/EryZ3MXtKo2cA+zSdf55MHxaS/nBeQcxfWzYz/B8ZxAwaXDnRcaT8/6V5tYGscxwrsoP4Ho43lHFA2T58IErd24hnPa4ucDrLrC+39j0rLZX+xtuj9juCycQeVVVb/co+EfKEZkWrT8BCH/EJaRV3UBgjNt2K1F15OT6gxN30a91a3+962zeC0gRdO63d5VFEIgQHD1zIiXx7rQ== 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=SDzDerJ8BHTpflGMC1W6xDcWZWOCwERj9bPjORhyA/I=; b=oHcEUDbLIEa0G12G+FHii7O7gjByLWafu71Yxh2f2clEFt69cm9lD5q3jRx7MyH0bKkhCgT1kNKGZL8Nekbu3DmKQ4rxLXzliSLmsvZHA6bceKyc3ncXq+52DmlkUtmU7HtG2iL+K710RN4nKVUyH5/nw5J68EhSEc0unGV1E3i3Q3qayz+401sT82VyzdToXK8sarwcIOV6kAtIDyqcmJoJZnvzXaiBsPX0AKlD/aTGB+BNP7uR0wKoQcVB/tRuwU5WXimNd8/AmgFSLF9BP+x4IY5H3ettpfRlYXP8StlfLkNj6clWC4Ud3SUNB76hCW481mMZ3bEx/tBxj7Tkng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=SDzDerJ8BHTpflGMC1W6xDcWZWOCwERj9bPjORhyA/I=; b=MBv45fdsVzyNekJbTF8edZKyX44YtLgj1IGgH36uWyi67DWDARW9cqiGRlS0+4E6ZREF2n1HtLEC3SgWDi946fL3il9FCg37m7VuO771KSSvP3cdQ6oYPAD3pQV9DDMaiXsl7fUhQxO1yl80WGMFuJoNAOcqrqmILR6oAPHnt+GdvIATS9FzK3O0akW2VnJ/A52PCtqpjXIi+/uLKWzqr2lNSv5X55DWUx3x/6WSF4NDsviv3S8KC7IjWWWtytiWOjMRbpRW772CC/DZ+ca4sTx/O7PX58laMZg6nNUCjsWRaqXxyg0Kab4Rs8LlYeyWconyutATpx9S43BHfryKqQ== Received: from BN0PR03CA0014.namprd03.prod.outlook.com (2603:10b6:408:e6::19) by MW3PR12MB4377.namprd12.prod.outlook.com (2603:10b6:303:55::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.19; Wed, 13 Oct 2021 09:48:58 +0000 Received: from BN8NAM11FT046.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e6:cafe::70) by BN0PR03CA0014.outlook.office365.com (2603:10b6:408:e6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Wed, 13 Oct 2021 09:48:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT046.mail.protection.outlook.com (10.13.177.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:48:57 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 13 Oct 2021 02:48:56 -0700 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Wed, 13 Oct 2021 09:48:53 +0000 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V1 mlx5-next 10/13] vfio/mlx5: Expose migration commands over mlx5 device Date: Wed, 13 Oct 2021 12:47:04 +0300 Message-ID: <20211013094707.163054-11-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211013094707.163054-1-yishaih@nvidia.com> References: <20211013094707.163054-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1b3a7f4d-640d-43a8-9920-08d98e2ead31 X-MS-TrafficTypeDiagnostic: MW3PR12MB4377: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Qb6cFwTNGnmwpLT8YbNrZbJRHoLvUPYMGl6n2URgvsMimimx4rLs8f1FXdGruSFzJklPF4IU+UorvDNm6bivUzjNm2GLas6OCucQH4aUU9NpjXVyYMQWq9Ghs807dfXvOJymqvgj0Ar7HvFKsBtM5022VSylg+lGPiW8Un33DhzOnRH/DLc32ES7WYOiLhuy6EFeXnB9YSIvEaeWv9JL+B0xcbYN39uPIUAR+T+P2CPMr6mPYmnuU8PZtT33jo6ZZwDvMqNRNVYpQ0Ggw2VXmv4JKBdlZegy+Zyp4D7Sycw4NJ9OPs4VzDA1sigZBu4Gk7q7GsNnqYjtPzfshF/Uvm8AxzyafBX9PPQbH8YKPZCSXa/Z4qiNN7ftWg6drhCpf3XQtINbR7wZDixPQTv2p+aug33QuyIQ1t/GVIqweRuqEvgadkFmHpo3pvFgYj8u8LWPkhBN2e5tFX2ns49pR8TQi4vMsKIbQ2QlAbk9dQAoR5W7KQqtR+mB2Wzwc6bgiAnzResVZPA5oCh6ss27RJpv3PYsjU564+mYhDs6X50SeAnufdWliyMlnoSRsPbJ8tRh6BuItJAfUvzvFLnCZqmap9SamPhvPtksm0mOXXdUgSYMmTSbiDlEY5+Wrg65AeO0SEj3p/WT06PJjS90xu6JIeNb7OnJHz4RWXArY7P3ZfnV5Wt/NdXcSNGYS9WgCsxilYXokaHXk3a47STt8g== X-Forefront-Antispam-Report: CIP:216.228.112.32;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid01.nvidia.com;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(36860700001)(47076005)(7636003)(110136005)(4326008)(7696005)(8676002)(356005)(5660300002)(6636002)(508600001)(316002)(54906003)(83380400001)(82310400003)(70586007)(26005)(86362001)(426003)(8936002)(6666004)(2906002)(186003)(1076003)(2616005)(36756003)(30864003)(107886003)(336012)(70206006);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 09:48:57.3315 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1b3a7f4d-640d-43a8-9920-08d98e2ead31 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.32];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT046.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4377 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Expose migration commands over the device, it includes: suspend, resume, get vhca id, query/save/load state. As part of this adds the APIs and data structure that are needed to manage the migration data. Signed-off-by: Yishai Hadas Signed-off-by: Leon Romanovsky --- drivers/vfio/pci/mlx5/cmd.c | 353 ++++++++++++++++++++++++++++++++++++ drivers/vfio/pci/mlx5/cmd.h | 43 +++++ 2 files changed, 396 insertions(+) create mode 100644 drivers/vfio/pci/mlx5/cmd.c create mode 100644 drivers/vfio/pci/mlx5/cmd.h diff --git a/drivers/vfio/pci/mlx5/cmd.c b/drivers/vfio/pci/mlx5/cmd.c new file mode 100644 index 000000000000..5b24a7625b8a --- /dev/null +++ b/drivers/vfio/pci/mlx5/cmd.c @@ -0,0 +1,353 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB +/* + * Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved + */ + +#include "cmd.h" + +int mlx5vf_cmd_suspend_vhca(struct pci_dev *pdev, u16 vhca_id, u16 op_mod) +{ + struct mlx5_core_dev *mdev = mlx5_vf_get_core_dev(pdev); + u32 out[MLX5_ST_SZ_DW(suspend_vhca_out)] = {}; + u32 in[MLX5_ST_SZ_DW(suspend_vhca_in)] = {}; + int ret; + + if (!mdev) + return -ENOTCONN; + + MLX5_SET(suspend_vhca_in, in, opcode, MLX5_CMD_OP_SUSPEND_VHCA); + MLX5_SET(suspend_vhca_in, in, vhca_id, vhca_id); + MLX5_SET(suspend_vhca_in, in, op_mod, op_mod); + + ret = mlx5_cmd_exec_inout(mdev, suspend_vhca, in, out); + mlx5_vf_put_core_dev(mdev); + return ret; +} + +int mlx5vf_cmd_resume_vhca(struct pci_dev *pdev, u16 vhca_id, u16 op_mod) +{ + struct mlx5_core_dev *mdev = mlx5_vf_get_core_dev(pdev); + u32 out[MLX5_ST_SZ_DW(resume_vhca_out)] = {}; + u32 in[MLX5_ST_SZ_DW(resume_vhca_in)] = {}; + int ret; + + if (!mdev) + return -ENOTCONN; + + MLX5_SET(resume_vhca_in, in, opcode, MLX5_CMD_OP_RESUME_VHCA); + MLX5_SET(resume_vhca_in, in, vhca_id, vhca_id); + MLX5_SET(resume_vhca_in, in, op_mod, op_mod); + + ret = mlx5_cmd_exec_inout(mdev, resume_vhca, in, out); + mlx5_vf_put_core_dev(mdev); + return ret; +} + +int mlx5vf_cmd_query_vhca_migration_state(struct pci_dev *pdev, u16 vhca_id, + u32 *state_size) +{ + struct mlx5_core_dev *mdev = mlx5_vf_get_core_dev(pdev); + u32 out[MLX5_ST_SZ_DW(query_vhca_migration_state_out)] = {}; + u32 in[MLX5_ST_SZ_DW(query_vhca_migration_state_in)] = {}; + int ret; + + if (!mdev) + return -ENOTCONN; + + MLX5_SET(query_vhca_migration_state_in, in, opcode, + MLX5_CMD_OP_QUERY_VHCA_MIGRATION_STATE); + MLX5_SET(query_vhca_migration_state_in, in, vhca_id, vhca_id); + MLX5_SET(query_vhca_migration_state_in, in, op_mod, 0); + + ret = mlx5_cmd_exec_inout(mdev, query_vhca_migration_state, in, out); + if (ret) + goto end; + + *state_size = MLX5_GET(query_vhca_migration_state_out, out, + required_umem_size); + +end: + mlx5_vf_put_core_dev(mdev); + return ret; +} + +int mlx5vf_cmd_get_vhca_id(struct pci_dev *pdev, u16 function_id, u16 *vhca_id) +{ + struct mlx5_core_dev *mdev = mlx5_vf_get_core_dev(pdev); + u32 in[MLX5_ST_SZ_DW(query_hca_cap_in)] = {}; + int out_size; + void *out; + int ret; + + if (!mdev) + return -ENOTCONN; + + out_size = MLX5_ST_SZ_BYTES(query_hca_cap_out); + out = kzalloc(out_size, GFP_KERNEL); + if (!out) { + ret = -ENOMEM; + goto end; + } + + MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP); + MLX5_SET(query_hca_cap_in, in, other_function, 1); + MLX5_SET(query_hca_cap_in, in, function_id, function_id); + MLX5_SET(query_hca_cap_in, in, op_mod, + MLX5_SET_HCA_CAP_OP_MOD_GENERAL_DEVICE << 1 | + HCA_CAP_OPMOD_GET_CUR); + + ret = mlx5_cmd_exec_inout(mdev, query_hca_cap, in, out); + if (ret) + goto err_exec; + + *vhca_id = MLX5_GET(query_hca_cap_out, out, + capability.cmd_hca_cap.vhca_id); + +err_exec: + kfree(out); +end: + mlx5_vf_put_core_dev(mdev); + return ret; +} + +static int _create_state_mkey(struct mlx5_core_dev *mdev, u32 pdn, + struct mlx5_vhca_state_data *state, u32 *mkey) +{ + struct sg_dma_page_iter dma_iter; + int err = 0, inlen; + __be64 *mtt; + void *mkc; + u32 *in; + + inlen = MLX5_ST_SZ_BYTES(create_mkey_in) + + sizeof(*mtt) * round_up(state->num_pages, 2); + + in = kvzalloc(inlen, GFP_KERNEL); + if (!in) + return -ENOMEM; + + MLX5_SET(create_mkey_in, in, translations_octword_actual_size, + DIV_ROUND_UP(state->num_pages, 2)); + mtt = (__be64 *)MLX5_ADDR_OF(create_mkey_in, in, klm_pas_mtt); + + for_each_sgtable_dma_page(&state->mig_data.table.sgt, &dma_iter, 0) + *mtt++ = cpu_to_be64(sg_page_iter_dma_address(&dma_iter)); + + mkc = MLX5_ADDR_OF(create_mkey_in, in, memory_key_mkey_entry); + MLX5_SET(mkc, mkc, access_mode_1_0, MLX5_MKC_ACCESS_MODE_MTT); + MLX5_SET(mkc, mkc, lr, 1); + MLX5_SET(mkc, mkc, lw, 1); + MLX5_SET(mkc, mkc, pd, pdn); + MLX5_SET(mkc, mkc, bsf_octword_size, 0); + MLX5_SET(mkc, mkc, qpn, 0xffffff); + MLX5_SET(mkc, mkc, log_page_size, PAGE_SHIFT); + MLX5_SET(mkc, mkc, translations_octword_size, + DIV_ROUND_UP(state->num_pages, 2)); + MLX5_SET64(mkc, mkc, len, state->num_pages * PAGE_SIZE); + err = mlx5_core_create_mkey(mdev, mkey, in, inlen); + + kvfree(in); + + return err; +} + +struct page *mlx5vf_get_migration_page(struct migration_data *data, + unsigned long offset) +{ + unsigned long cur_offset = 0; + struct scatterlist *sg; + unsigned int i; + + if (offset < data->last_offset || !data->last_offset_sg) { + data->last_offset = 0; + data->last_offset_sg = data->table.sgt.sgl; + data->sg_last_entry = 0; + } + + cur_offset = data->last_offset; + + for_each_sg(data->last_offset_sg, sg, + data->table.sgt.orig_nents - data->sg_last_entry, i) { + if (offset < sg->length + cur_offset) { + data->last_offset_sg = sg; + data->sg_last_entry += i; + data->last_offset = cur_offset; + return nth_page(sg_page(sg), + (offset - cur_offset) / PAGE_SIZE); + } + cur_offset += sg->length; + } + return NULL; +} + +void mlx5vf_reset_vhca_state(struct mlx5_vhca_state_data *state) +{ + struct migration_data *data = &state->mig_data; + struct sg_page_iter sg_iter; + + if (!data->table.prv) + goto end; + + /* Undo alloc_pages_bulk_array() */ + for_each_sgtable_page(&data->table.sgt, &sg_iter, 0) + __free_page(sg_page_iter_page(&sg_iter)); + sg_free_append_table(&data->table); +end: + memset(state, 0, sizeof(*state)); +} + +int mlx5vf_add_migration_pages(struct mlx5_vhca_state_data *state, + unsigned int npages) +{ + unsigned int to_alloc = npages; + struct page **page_list; + unsigned long filled; + unsigned int to_fill; + int ret = 0; + + to_fill = min_t(unsigned int, npages, PAGE_SIZE / sizeof(*page_list)); + page_list = kvzalloc(to_fill * sizeof(*page_list), GFP_KERNEL); + if (!page_list) + return -ENOMEM; + + do { + filled = alloc_pages_bulk_array(GFP_KERNEL, to_fill, + page_list); + if (!filled) { + ret = -ENOMEM; + goto err; + } + to_alloc -= filled; + ret = sg_alloc_append_table_from_pages( + &state->mig_data.table, page_list, filled, 0, + filled << PAGE_SHIFT, UINT_MAX, SG_MAX_SINGLE_ALLOC, + GFP_KERNEL); + + if (ret) + goto err; + /* clean input for another bulk allocation */ + memset(page_list, 0, filled * sizeof(*page_list)); + to_fill = min_t(unsigned int, to_alloc, + PAGE_SIZE / sizeof(*page_list)); + } while (to_alloc > 0); + + kvfree(page_list); + state->num_pages += npages; + + return 0; + +err: + kvfree(page_list); + return ret; +} + +int mlx5vf_cmd_save_vhca_state(struct pci_dev *pdev, u16 vhca_id, + u64 state_size, + struct mlx5_vhca_state_data *state) +{ + struct mlx5_core_dev *mdev = mlx5_vf_get_core_dev(pdev); + u32 out[MLX5_ST_SZ_DW(save_vhca_state_out)] = {}; + u32 in[MLX5_ST_SZ_DW(save_vhca_state_in)] = {}; + u32 pdn, mkey; + int err; + + if (!mdev) + return -ENOTCONN; + + err = mlx5_core_alloc_pd(mdev, &pdn); + if (err) + goto end; + + err = mlx5vf_add_migration_pages(state, + DIV_ROUND_UP_ULL(state_size, PAGE_SIZE)); + if (err < 0) + goto err_alloc_pages; + + err = dma_map_sgtable(mdev->device, &state->mig_data.table.sgt, + DMA_FROM_DEVICE, 0); + if (err) + goto err_reg_dma; + + err = _create_state_mkey(mdev, pdn, state, &mkey); + if (err) + goto err_create_mkey; + + MLX5_SET(save_vhca_state_in, in, opcode, + MLX5_CMD_OP_SAVE_VHCA_STATE); + MLX5_SET(save_vhca_state_in, in, op_mod, 0); + MLX5_SET(save_vhca_state_in, in, vhca_id, vhca_id); + MLX5_SET(save_vhca_state_in, in, mkey, mkey); + MLX5_SET(save_vhca_state_in, in, size, state_size); + + err = mlx5_cmd_exec_inout(mdev, save_vhca_state, in, out); + if (err) + goto err_exec; + + state->state_size = state_size; + + mlx5_core_destroy_mkey(mdev, mkey); + mlx5_core_dealloc_pd(mdev, pdn); + dma_unmap_sgtable(mdev->device, &state->mig_data.table.sgt, + DMA_FROM_DEVICE, 0); + mlx5_vf_put_core_dev(mdev); + + return 0; + +err_exec: + mlx5_core_destroy_mkey(mdev, mkey); +err_create_mkey: + dma_unmap_sgtable(mdev->device, &state->mig_data.table.sgt, + DMA_FROM_DEVICE, 0); +err_reg_dma: + mlx5vf_reset_vhca_state(state); +err_alloc_pages: + mlx5_core_dealloc_pd(mdev, pdn); +end: + mlx5_vf_put_core_dev(mdev); + return err; +} + +int mlx5vf_cmd_load_vhca_state(struct pci_dev *pdev, u16 vhca_id, + struct mlx5_vhca_state_data *state) +{ + struct mlx5_core_dev *mdev = mlx5_vf_get_core_dev(pdev); + u32 out[MLX5_ST_SZ_DW(save_vhca_state_out)] = {}; + u32 in[MLX5_ST_SZ_DW(save_vhca_state_in)] = {}; + u32 pdn, mkey; + int err; + + if (!mdev) + return -ENOTCONN; + + err = mlx5_core_alloc_pd(mdev, &pdn); + if (err) + goto end; + + err = dma_map_sgtable(mdev->device, &state->mig_data.table.sgt, + DMA_TO_DEVICE, 0); + if (err) + goto err_reg; + + err = _create_state_mkey(mdev, pdn, state, &mkey); + if (err) + goto err_mkey; + + MLX5_SET(load_vhca_state_in, in, opcode, + MLX5_CMD_OP_LOAD_VHCA_STATE); + MLX5_SET(load_vhca_state_in, in, op_mod, 0); + MLX5_SET(load_vhca_state_in, in, vhca_id, vhca_id); + MLX5_SET(load_vhca_state_in, in, mkey, mkey); + MLX5_SET(load_vhca_state_in, in, size, state->state_size); + + err = mlx5_cmd_exec_inout(mdev, load_vhca_state, in, out); + + mlx5_core_destroy_mkey(mdev, mkey); +err_mkey: + dma_unmap_sgtable(mdev->device, &state->mig_data.table.sgt, + DMA_TO_DEVICE, 0); +err_reg: + mlx5_core_dealloc_pd(mdev, pdn); +end: + mlx5_vf_put_core_dev(mdev); + return err; +} diff --git a/drivers/vfio/pci/mlx5/cmd.h b/drivers/vfio/pci/mlx5/cmd.h new file mode 100644 index 000000000000..66221df24b19 --- /dev/null +++ b/drivers/vfio/pci/mlx5/cmd.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ +/* + * Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + */ + +#ifndef MLX5_VFIO_CMD_H +#define MLX5_VFIO_CMD_H + +#include +#include + +struct migration_data { + struct sg_append_table table; + + struct scatterlist *last_offset_sg; + unsigned int sg_last_entry; + unsigned long last_offset; +}; + +/* state data of vhca to be used as part of migration flow */ +struct mlx5_vhca_state_data { + u64 state_size; + u64 num_pages; + u32 win_start_offset; + struct migration_data mig_data; +}; + +int mlx5vf_cmd_suspend_vhca(struct pci_dev *pdev, u16 vhca_id, u16 op_mod); +int mlx5vf_cmd_resume_vhca(struct pci_dev *pdev, u16 vhca_id, u16 op_mod); +int mlx5vf_cmd_query_vhca_migration_state(struct pci_dev *pdev, u16 vhca_id, + uint32_t *state_size); +int mlx5vf_cmd_get_vhca_id(struct pci_dev *pdev, u16 function_id, u16 *vhca_id); +int mlx5vf_cmd_save_vhca_state(struct pci_dev *pdev, u16 vhca_id, + u64 state_size, + struct mlx5_vhca_state_data *state); +void mlx5vf_reset_vhca_state(struct mlx5_vhca_state_data *state); +int mlx5vf_cmd_load_vhca_state(struct pci_dev *pdev, u16 vhca_id, + struct mlx5_vhca_state_data *state); +int mlx5vf_add_migration_pages(struct mlx5_vhca_state_data *state, + unsigned int npages); +struct page *mlx5vf_get_migration_page(struct migration_data *data, + unsigned long offset); +#endif /* MLX5_VFIO_CMD_H */ From patchwork Wed Oct 13 09:47:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12555329 X-Patchwork-Delegate: bhelgaas@google.com 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42358C43219 for ; Wed, 13 Oct 2021 09:49:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 295CD60C40 for ; Wed, 13 Oct 2021 09:49:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239252AbhJMJvq (ORCPT ); Wed, 13 Oct 2021 05:51:46 -0400 Received: from mail-bn1nam07on2069.outbound.protection.outlook.com ([40.107.212.69]:15015 "EHLO NAM02-BN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S239260AbhJMJvG (ORCPT ); Wed, 13 Oct 2021 05:51:06 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cFRYKjeCEp5BK5iax9rPgnSb+//6ZQyTJu/ch4EcXg5saunOANcL1pgUlSMqTaZkXVztDOjTEqKdeMMs19TTXDlegtSfBX+XOaSrdalEpylfgAOQuhAtyXMxUrShSSrTeRSaic+zAQ0DA7UYQkBzJVfJr863eWS616mnwbrvz+wvYly/zDE0accKFQdihG7Rih5zBZco1jbYMrogltuOd6OxsY3GiVR1pBL+HEtANb6GgiQxx58zvLkjcg5nVin+FkcYrQOEdlCBMmkUP4Nc9qFbDyOohD/y4NjgjTlmF5CNPxp3YI3GSkuwgx2b8pDEKVEx3a3as3jI6MQCs/937Q== 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=n22Th2/F/PJwd0vhcjAyaJGw72j0uNeSfFfsZq/iOD8=; b=WVsuXytV2OsJmiAUZTd5S5XUSBFUjwEodBks7LE1jPFusZdXyuj8ob9lPoG2ecGGQzY2jH1gWaO2588S6RVb08azGAufowpxR6eI8LQKFiAdmCwVtAzkj7cv9s/WKllsGqt7zRIgbfWnzXaf/zXuPdBR4JgKBDwTi/Y6AzYl9Idc+4yBF8qffmPW17eSVa4AD+hkUWzxVBwVE7RhwN0sl7ny8deqzdxDbk+U3vxf6Fxd/7KG9llzdk+rWYltTXUbj5NugCYlMZ75X7kMU0El15wS1KeMLJqQ2eyWWJ5Go21woLrzRXBzvgE0v1BRuZHkaezZ7qgpK8OTuRvH/KLe5A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=n22Th2/F/PJwd0vhcjAyaJGw72j0uNeSfFfsZq/iOD8=; b=qx/H6+7M8wJKDHRiOxyFK9q7XFZPr6e7/E3o0L7TVYk8BCgHXPvuhuISOPruIr7VloGAJQhCpVvgalZN1UDe+kns8dFG5AROCMik+xoGW+SgILzlVxJt3CSaSeFQq8yKXx7rtyG2uedkyIp1dynYlK+6NHpodTLb6nLZU+3p0yodQUTUnUb+WOvXeI8Cs9rOyU6+fKToO1Mc1fPesMzQGUE2fd3Zk44XdapAIFiCAKdP2d6zhcyVwezFjtwjSmrgeGZwyuTo/znxKb/R1c+Mym5ezVYXtKm1i7o3W6poUGkNUtHf6i7wN4zZ9rLTEvIiNMwambJRQcRUkyWL/i1FTg== Received: from BN8PR04CA0038.namprd04.prod.outlook.com (2603:10b6:408:d4::12) by DM4PR12MB5263.namprd12.prod.outlook.com (2603:10b6:5:39b::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Wed, 13 Oct 2021 09:49:01 +0000 Received: from BN8NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:408:d4:cafe::a1) by BN8PR04CA0038.outlook.office365.com (2603:10b6:408:d4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:49:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT035.mail.protection.outlook.com (10.13.177.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:49:00 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 13 Oct 2021 02:48:59 -0700 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Wed, 13 Oct 2021 09:48:56 +0000 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V1 mlx5-next 11/13] vfio/mlx5: Implement vfio_pci driver for mlx5 devices Date: Wed, 13 Oct 2021 12:47:05 +0300 Message-ID: <20211013094707.163054-12-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211013094707.163054-1-yishaih@nvidia.com> References: <20211013094707.163054-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d6f311af-dbad-4243-d027-08d98e2eaf51 X-MS-TrafficTypeDiagnostic: DM4PR12MB5263: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dK30rYm/0+zHl0CWh1cyIBSNwJmu5wDsfoLm4izZTZ6hljdQRPV/y719OsoFCVSOIsrZ4oT2fVZqZzTK4mZ/whUcOZPUXCzEBW0pf56KkmjU7Pjv6cGiG5dAp+1mKrat76i5wrYvwBuIZ1kpEaD3eztxUEarKPmFTDacdvQNDsY3hWcORou7ag1uQDUrowo095Ord/P7YPu7D3tFXqG33vIukSQxDodgvYRzZpJ9TVJyZLBgDGhMuyNqXuUqi5UerG622dmZ3BcgNpgWawzLiexroisqVQaNGS5QwHnA6GOH7YD7yT0X/tl6zyTuRREs5lcHxZOIj7DM8pU7PeLbbgjUy+J+YTvkh4Ptk4XYbGftH18n+OJgxGFyx8UOHQ6V822aEUj3Y2rk8OFe4Z1fxroCFNmH43gGqGTEilvCv2JneRwLJr8SNRaLqmU2b16BkOnMuEZ5X3RinE5dtzURDj5mcK+kN1GS9bob3r7c9pzKXJJgtxhuvWziMGxOMo6JACc0uUWoMbki+kA6Nnkmrb6g9LufU4TZZlJYK/rSH/eNpMDvwbsQRVVKk3UY252jFjjv+uVoFxITeFBqp4qyvgagxI0gb6HC1qvPwAK3xjTS+wWVnQQAD/AN3GLcSQQ8qqMxiMZeCjPMv4HZhZkdUKgnpFD9it9h06peNBX8B4yI0Ccu7O5Z9Cxcd1A808lW0e5mYacxI8YXBWHE6y+v3PXEDkHM/CZneoYlt1Lk4TM= X-Forefront-Antispam-Report: CIP:216.228.112.32;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid01.nvidia.com;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(5660300002)(70206006)(8936002)(70586007)(6666004)(8676002)(316002)(508600001)(36860700001)(7696005)(82310400003)(2906002)(1076003)(107886003)(30864003)(36756003)(83380400001)(47076005)(26005)(186003)(7636003)(54906003)(426003)(336012)(4326008)(6636002)(110136005)(2616005)(356005)(86362001)(21314003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 09:49:00.8291 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d6f311af-dbad-4243-d027-08d98e2eaf51 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.32];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5263 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org This patch adds support for vfio_pci driver for mlx5 devices. It uses vfio_pci_core to register to the VFIO subsystem and then implements the mlx5 specific logic in the migration area. The migration implementation follows the definition from uapi/vfio.h and uses the mlx5 VF->PF command channel to achieve it. This patch implements the suspend/resume flows. Signed-off-by: Yishai Hadas Signed-off-by: Leon Romanovsky --- MAINTAINERS | 6 + drivers/vfio/pci/Kconfig | 3 + drivers/vfio/pci/Makefile | 2 + drivers/vfio/pci/mlx5/Kconfig | 11 + drivers/vfio/pci/mlx5/Makefile | 4 + drivers/vfio/pci/mlx5/main.c | 692 +++++++++++++++++++++++++++++++++ 6 files changed, 718 insertions(+) create mode 100644 drivers/vfio/pci/mlx5/Kconfig create mode 100644 drivers/vfio/pci/mlx5/Makefile create mode 100644 drivers/vfio/pci/mlx5/main.c diff --git a/MAINTAINERS b/MAINTAINERS index abdcbcfef73d..e824bfab4a01 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19699,6 +19699,12 @@ L: kvm@vger.kernel.org S: Maintained F: drivers/vfio/platform/ +VFIO MLX5 PCI DRIVER +M: Yishai Hadas +L: kvm@vger.kernel.org +S: Maintained +F: drivers/vfio/pci/mlx5/ + VGA_SWITCHEROO R: Lukas Wunner S: Maintained diff --git a/drivers/vfio/pci/Kconfig b/drivers/vfio/pci/Kconfig index 860424ccda1b..187b9c259944 100644 --- a/drivers/vfio/pci/Kconfig +++ b/drivers/vfio/pci/Kconfig @@ -43,4 +43,7 @@ config VFIO_PCI_IGD To enable Intel IGD assignment through vfio-pci, say Y. endif + +source "drivers/vfio/pci/mlx5/Kconfig" + endif diff --git a/drivers/vfio/pci/Makefile b/drivers/vfio/pci/Makefile index 349d68d242b4..ed9d6f2e0555 100644 --- a/drivers/vfio/pci/Makefile +++ b/drivers/vfio/pci/Makefile @@ -7,3 +7,5 @@ obj-$(CONFIG_VFIO_PCI_CORE) += vfio-pci-core.o vfio-pci-y := vfio_pci.o vfio-pci-$(CONFIG_VFIO_PCI_IGD) += vfio_pci_igd.o obj-$(CONFIG_VFIO_PCI) += vfio-pci.o + +obj-$(CONFIG_MLX5_VFIO_PCI) += mlx5/ diff --git a/drivers/vfio/pci/mlx5/Kconfig b/drivers/vfio/pci/mlx5/Kconfig new file mode 100644 index 000000000000..a3ce00add4fe --- /dev/null +++ b/drivers/vfio/pci/mlx5/Kconfig @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only +config MLX5_VFIO_PCI + tristate "VFIO support for MLX5 PCI devices" + depends on MLX5_CORE + select VFIO_PCI_CORE + help + This provides a PCI support for MLX5 devices using the VFIO + framework. The device specific driver supports suspend/resume + of the MLX5 device. + + If you don't know what to do here, say N. diff --git a/drivers/vfio/pci/mlx5/Makefile b/drivers/vfio/pci/mlx5/Makefile new file mode 100644 index 000000000000..689627da7ff5 --- /dev/null +++ b/drivers/vfio/pci/mlx5/Makefile @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_MLX5_VFIO_PCI) += mlx5-vfio-pci.o +mlx5-vfio-pci-y := main.o cmd.o + diff --git a/drivers/vfio/pci/mlx5/main.c b/drivers/vfio/pci/mlx5/main.c new file mode 100644 index 000000000000..e36302b444a6 --- /dev/null +++ b/drivers/vfio/pci/mlx5/main.c @@ -0,0 +1,692 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cmd.h" + +enum { + MLX5VF_PCI_FREEZED = 1 << 0, +}; + +enum { + MLX5VF_REGION_PENDING_BYTES = 1 << 0, + MLX5VF_REGION_DATA_SIZE = 1 << 1, +}; + +#define MLX5VF_MIG_REGION_DATA_SIZE SZ_128K +/* Data section offset from migration region */ +#define MLX5VF_MIG_REGION_DATA_OFFSET \ + (sizeof(struct vfio_device_migration_info)) + +#define VFIO_DEVICE_MIGRATION_OFFSET(x) \ + (offsetof(struct vfio_device_migration_info, x)) + +struct mlx5vf_pci_migration_info { + u32 vfio_dev_state; /* VFIO_DEVICE_STATE_XXX */ + u32 dev_state; /* device migration state */ + u32 region_state; /* Use MLX5VF_REGION_XXX */ + u16 vhca_id; + struct mlx5_vhca_state_data vhca_state_data; +}; + +struct mlx5vf_pci_core_device { + struct vfio_pci_core_device core_device; + u8 migrate_cap:1; + /* protect migartion state */ + struct mutex state_mutex; + struct mlx5vf_pci_migration_info vmig; +}; + +static int mlx5vf_pci_unquiesce_device(struct mlx5vf_pci_core_device *mvdev) +{ + return mlx5vf_cmd_resume_vhca(mvdev->core_device.pdev, + mvdev->vmig.vhca_id, + MLX5_RESUME_VHCA_IN_OP_MOD_RESUME_MASTER); +} + +static int mlx5vf_pci_quiesce_device(struct mlx5vf_pci_core_device *mvdev) +{ + return mlx5vf_cmd_suspend_vhca( + mvdev->core_device.pdev, mvdev->vmig.vhca_id, + MLX5_SUSPEND_VHCA_IN_OP_MOD_SUSPEND_MASTER); +} + +static int mlx5vf_pci_unfreeze_device(struct mlx5vf_pci_core_device *mvdev) +{ + int ret; + + ret = mlx5vf_cmd_resume_vhca(mvdev->core_device.pdev, + mvdev->vmig.vhca_id, + MLX5_RESUME_VHCA_IN_OP_MOD_RESUME_SLAVE); + if (ret) + return ret; + + mvdev->vmig.dev_state &= ~MLX5VF_PCI_FREEZED; + return 0; +} + +static int mlx5vf_pci_freeze_device(struct mlx5vf_pci_core_device *mvdev) +{ + int ret; + + ret = mlx5vf_cmd_suspend_vhca( + mvdev->core_device.pdev, mvdev->vmig.vhca_id, + MLX5_SUSPEND_VHCA_IN_OP_MOD_SUSPEND_SLAVE); + if (ret) + return ret; + + mvdev->vmig.dev_state |= MLX5VF_PCI_FREEZED; + return 0; +} + +static int mlx5vf_pci_save_device_data(struct mlx5vf_pci_core_device *mvdev) +{ + u32 state_size = 0; + int ret; + + if (!(mvdev->vmig.dev_state & MLX5VF_PCI_FREEZED)) + return -EFAULT; + + /* If we already read state no reason to re-read */ + if (mvdev->vmig.vhca_state_data.state_size) + return 0; + + ret = mlx5vf_cmd_query_vhca_migration_state( + mvdev->core_device.pdev, mvdev->vmig.vhca_id, &state_size); + if (ret) + return ret; + + return mlx5vf_cmd_save_vhca_state(mvdev->core_device.pdev, + mvdev->vmig.vhca_id, state_size, + &mvdev->vmig.vhca_state_data); +} + +static int mlx5vf_pci_new_write_window(struct mlx5vf_pci_core_device *mvdev) +{ + struct mlx5_vhca_state_data *state_data = &mvdev->vmig.vhca_state_data; + u32 num_pages_needed; + u64 allocated_ready; + u32 bytes_needed; + + /* Check how many bytes are available from previous flows */ + WARN_ON(state_data->num_pages * PAGE_SIZE < + state_data->win_start_offset); + allocated_ready = (state_data->num_pages * PAGE_SIZE) - + state_data->win_start_offset; + WARN_ON(allocated_ready > MLX5VF_MIG_REGION_DATA_SIZE); + + bytes_needed = MLX5VF_MIG_REGION_DATA_SIZE - allocated_ready; + if (!bytes_needed) + return 0; + + num_pages_needed = DIV_ROUND_UP_ULL(bytes_needed, PAGE_SIZE); + return mlx5vf_add_migration_pages(state_data, num_pages_needed); +} + +static ssize_t +mlx5vf_pci_handle_migration_data_size(struct mlx5vf_pci_core_device *mvdev, + char __user *buf, bool iswrite) +{ + struct mlx5vf_pci_migration_info *vmig = &mvdev->vmig; + u64 data_size; + int ret; + + if (iswrite) { + /* data_size is writable only during resuming state */ + if (vmig->vfio_dev_state != VFIO_DEVICE_STATE_RESUMING) + return -EINVAL; + + ret = copy_from_user(&data_size, buf, sizeof(data_size)); + if (ret) + return -EFAULT; + + vmig->vhca_state_data.state_size += data_size; + vmig->vhca_state_data.win_start_offset += data_size; + ret = mlx5vf_pci_new_write_window(mvdev); + if (ret) + return ret; + + } else { + if (vmig->vfio_dev_state != VFIO_DEVICE_STATE_SAVING) + return -EINVAL; + + data_size = min_t(u64, MLX5VF_MIG_REGION_DATA_SIZE, + vmig->vhca_state_data.state_size - + vmig->vhca_state_data.win_start_offset); + ret = copy_to_user(buf, &data_size, sizeof(data_size)); + if (ret) + return -EFAULT; + } + + vmig->region_state |= MLX5VF_REGION_DATA_SIZE; + return sizeof(data_size); +} + +static ssize_t +mlx5vf_pci_handle_migration_data_offset(struct mlx5vf_pci_core_device *mvdev, + char __user *buf, bool iswrite) +{ + static const u64 data_offset = MLX5VF_MIG_REGION_DATA_OFFSET; + int ret; + + /* RO field */ + if (iswrite) + return -EFAULT; + + ret = copy_to_user(buf, &data_offset, sizeof(data_offset)); + if (ret) + return -EFAULT; + + return sizeof(data_offset); +} + +static ssize_t +mlx5vf_pci_handle_migration_pending_bytes(struct mlx5vf_pci_core_device *mvdev, + char __user *buf, bool iswrite) +{ + struct mlx5vf_pci_migration_info *vmig = &mvdev->vmig; + u64 pending_bytes; + int ret; + + /* RO field */ + if (iswrite) + return -EFAULT; + + if (vmig->vfio_dev_state == (VFIO_DEVICE_STATE_SAVING | + VFIO_DEVICE_STATE_RUNNING)) { + /* In pre-copy state we have no data to return for now, + * return 0 pending bytes + */ + pending_bytes = 0; + } else { + if (!vmig->vhca_state_data.state_size) + return 0; + pending_bytes = vmig->vhca_state_data.state_size - + vmig->vhca_state_data.win_start_offset; + } + + ret = copy_to_user(buf, &pending_bytes, sizeof(pending_bytes)); + if (ret) + return -EFAULT; + + /* Window moves forward once data from previous iteration was read */ + if (vmig->region_state & MLX5VF_REGION_DATA_SIZE) + vmig->vhca_state_data.win_start_offset += + min_t(u64, MLX5VF_MIG_REGION_DATA_SIZE, pending_bytes); + + WARN_ON(vmig->vhca_state_data.win_start_offset > + vmig->vhca_state_data.state_size); + + /* New iteration started */ + vmig->region_state = MLX5VF_REGION_PENDING_BYTES; + return sizeof(pending_bytes); +} + +static int mlx5vf_load_state(struct mlx5vf_pci_core_device *mvdev) +{ + if (!mvdev->vmig.vhca_state_data.state_size) + return 0; + + return mlx5vf_cmd_load_vhca_state(mvdev->core_device.pdev, + mvdev->vmig.vhca_id, + &mvdev->vmig.vhca_state_data); +} + +static void mlx5vf_reset_mig_state(struct mlx5vf_pci_core_device *mvdev) +{ + struct mlx5vf_pci_migration_info *vmig = &mvdev->vmig; + + vmig->region_state = 0; + mlx5vf_reset_vhca_state(&vmig->vhca_state_data); +} + +static int mlx5vf_pci_set_device_state(struct mlx5vf_pci_core_device *mvdev, + u32 state) +{ + struct mlx5vf_pci_migration_info *vmig = &mvdev->vmig; + u32 old_state = vmig->vfio_dev_state; + int ret = 0; + + if (vfio_is_state_invalid(state) || vfio_is_state_invalid(old_state)) + return -EINVAL; + + /* Running switches off */ + if ((old_state & VFIO_DEVICE_STATE_RUNNING) != + (state & VFIO_DEVICE_STATE_RUNNING) && + (old_state & VFIO_DEVICE_STATE_RUNNING)) { + ret = mlx5vf_pci_quiesce_device(mvdev); + if (ret) + return ret; + ret = mlx5vf_pci_freeze_device(mvdev); + if (ret) { + vmig->vfio_dev_state = VFIO_DEVICE_STATE_INVALID; + return ret; + } + } + + /* Resuming switches off */ + if ((old_state & VFIO_DEVICE_STATE_RESUMING) != + (state & VFIO_DEVICE_STATE_RESUMING) && + (old_state & VFIO_DEVICE_STATE_RESUMING)) { + /* deserialize state into the device */ + ret = mlx5vf_load_state(mvdev); + if (ret) { + vmig->vfio_dev_state = VFIO_DEVICE_STATE_INVALID; + return ret; + } + } + + /* Resuming switches on */ + if ((old_state & VFIO_DEVICE_STATE_RESUMING) != + (state & VFIO_DEVICE_STATE_RESUMING) && + (state & VFIO_DEVICE_STATE_RESUMING)) { + mlx5vf_reset_mig_state(mvdev); + ret = mlx5vf_pci_new_write_window(mvdev); + if (ret) + return ret; + } + + /* Saving switches on */ + if ((old_state & VFIO_DEVICE_STATE_SAVING) != + (state & VFIO_DEVICE_STATE_SAVING) && + (state & VFIO_DEVICE_STATE_SAVING)) { + if (!(state & VFIO_DEVICE_STATE_RUNNING)) { + /* serialize post copy */ + ret = mlx5vf_pci_save_device_data(mvdev); + if (ret) + return ret; + } + } + + /* Running switches on */ + if ((old_state & VFIO_DEVICE_STATE_RUNNING) != + (state & VFIO_DEVICE_STATE_RUNNING) && + (state & VFIO_DEVICE_STATE_RUNNING)) { + ret = mlx5vf_pci_unfreeze_device(mvdev); + if (ret) + return ret; + ret = mlx5vf_pci_unquiesce_device(mvdev); + if (ret) { + vmig->vfio_dev_state = VFIO_DEVICE_STATE_INVALID; + return ret; + } + } + + vmig->vfio_dev_state = state; + return 0; +} + +static ssize_t +mlx5vf_pci_handle_migration_device_state(struct mlx5vf_pci_core_device *mvdev, + char __user *buf, bool iswrite) +{ + size_t count = sizeof(mvdev->vmig.vfio_dev_state); + int ret; + + if (iswrite) { + u32 device_state; + + ret = copy_from_user(&device_state, buf, count); + if (ret) + return -EFAULT; + + ret = mlx5vf_pci_set_device_state(mvdev, device_state); + if (ret) + return ret; + } else { + ret = copy_to_user(buf, &mvdev->vmig.vfio_dev_state, count); + if (ret) + return -EFAULT; + } + + return count; +} + +static ssize_t +mlx5vf_pci_copy_user_data_to_device_state(struct mlx5vf_pci_core_device *mvdev, + char __user *buf, size_t count, + u64 offset) +{ + struct mlx5_vhca_state_data *state_data = &mvdev->vmig.vhca_state_data; + char __user *from_buff = buf; + u32 curr_offset; + u32 win_page_offset; + u32 copy_count; + struct page *page; + char *to_buff; + int ret; + + curr_offset = state_data->win_start_offset + offset; + + do { + page = mlx5vf_get_migration_page(&state_data->mig_data, + curr_offset); + if (!page) + return -EINVAL; + + win_page_offset = curr_offset % PAGE_SIZE; + copy_count = min_t(u32, PAGE_SIZE - win_page_offset, count); + + to_buff = kmap_local_page(page); + ret = copy_from_user(to_buff + win_page_offset, from_buff, + copy_count); + kunmap_local(to_buff); + if (ret) + return -EFAULT; + + from_buff += copy_count; + curr_offset += copy_count; + count -= copy_count; + } while (count > 0); + + return 0; +} + +static ssize_t +mlx5vf_pci_copy_device_state_to_user(struct mlx5vf_pci_core_device *mvdev, + char __user *buf, u64 offset, size_t count) +{ + struct mlx5_vhca_state_data *state_data = &mvdev->vmig.vhca_state_data; + char __user *to_buff = buf; + u32 win_available_bytes; + u32 win_page_offset; + u32 copy_count; + u32 curr_offset; + char *from_buff; + struct page *page; + int ret; + + win_available_bytes = + min_t(u64, MLX5VF_MIG_REGION_DATA_SIZE, + mvdev->vmig.vhca_state_data.state_size - + mvdev->vmig.vhca_state_data.win_start_offset); + + if (count + offset > win_available_bytes) + return -EINVAL; + + curr_offset = state_data->win_start_offset + offset; + + do { + page = mlx5vf_get_migration_page(&state_data->mig_data, + curr_offset); + if (!page) + return -EINVAL; + + win_page_offset = curr_offset % PAGE_SIZE; + copy_count = min_t(u32, PAGE_SIZE - win_page_offset, count); + + from_buff = kmap_local_page(page); + ret = copy_to_user(buf, from_buff + win_page_offset, + copy_count); + kunmap_local(from_buff); + if (ret) + return -EFAULT; + + curr_offset += copy_count; + count -= copy_count; + to_buff += copy_count; + } while (count); + + return 0; +} + +static ssize_t +mlx5vf_pci_migration_data_rw(struct mlx5vf_pci_core_device *mvdev, + char __user *buf, size_t count, u64 offset, + bool iswrite) +{ + int ret; + + if (offset + count > MLX5VF_MIG_REGION_DATA_SIZE) + return -EINVAL; + + if (iswrite) + ret = mlx5vf_pci_copy_user_data_to_device_state(mvdev, buf, + count, offset); + else + ret = mlx5vf_pci_copy_device_state_to_user(mvdev, buf, offset, + count); + if (ret) + return ret; + return count; +} + +static ssize_t mlx5vf_pci_mig_rw(struct vfio_pci_core_device *vdev, + char __user *buf, size_t count, loff_t *ppos, + bool iswrite) +{ + struct mlx5vf_pci_core_device *mvdev = + container_of(vdev, struct mlx5vf_pci_core_device, core_device); + u64 pos = *ppos & VFIO_PCI_OFFSET_MASK; + int ret; + + mutex_lock(&mvdev->state_mutex); + /* Copy to/from the migration region data section */ + if (pos >= MLX5VF_MIG_REGION_DATA_OFFSET) { + ret = mlx5vf_pci_migration_data_rw( + mvdev, buf, count, pos - MLX5VF_MIG_REGION_DATA_OFFSET, + iswrite); + goto end; + } + + switch (pos) { + case VFIO_DEVICE_MIGRATION_OFFSET(device_state): + /* This is RW field. */ + if (count != sizeof(mvdev->vmig.vfio_dev_state)) { + ret = -EINVAL; + break; + } + ret = mlx5vf_pci_handle_migration_device_state(mvdev, buf, + iswrite); + break; + case VFIO_DEVICE_MIGRATION_OFFSET(pending_bytes): + /* + * The number of pending bytes still to be migrated from the + * vendor driver. This is RO field. + * Reading this field indicates on the start of a new iteration + * to get device data. + * + */ + ret = mlx5vf_pci_handle_migration_pending_bytes(mvdev, buf, + iswrite); + break; + case VFIO_DEVICE_MIGRATION_OFFSET(data_offset): + /* + * The user application should read data_offset field from the + * migration region. The user application should read the + * device data from this offset within the migration region + * during the _SAVING mode or write the device data during the + * _RESUMING mode. This is RO field. + */ + ret = mlx5vf_pci_handle_migration_data_offset(mvdev, buf, + iswrite); + break; + case VFIO_DEVICE_MIGRATION_OFFSET(data_size): + /* + * The user application should read data_size to get the size + * in bytes of the data copied to the migration region during + * the _SAVING state by the device. The user application should + * write the size in bytes of the data that was copied to + * the migration region during the _RESUMING state by the user. + * This is RW field. + */ + ret = mlx5vf_pci_handle_migration_data_size(mvdev, buf, + iswrite); + break; + default: + ret = -EFAULT; + break; + } + +end: + mutex_unlock(&mvdev->state_mutex); + return ret; +} + +static struct vfio_pci_regops migration_ops = { + .rw = mlx5vf_pci_mig_rw, +}; + +static int mlx5vf_pci_open_device(struct vfio_device *core_vdev) +{ + struct mlx5vf_pci_core_device *mvdev = container_of( + core_vdev, struct mlx5vf_pci_core_device, core_device.vdev); + struct vfio_pci_core_device *vdev = &mvdev->core_device; + int vf_id; + int ret; + + ret = vfio_pci_core_enable(vdev); + if (ret) + return ret; + + if (!mvdev->migrate_cap) { + vfio_pci_core_finish_enable(vdev); + return 0; + } + + vf_id = pci_iov_vf_id(vdev->pdev); + if (vf_id < 0) { + ret = vf_id; + goto out_disable; + } + + ret = mlx5vf_cmd_get_vhca_id(vdev->pdev, vf_id + 1, + &mvdev->vmig.vhca_id); + if (ret) + goto out_disable; + + ret = vfio_pci_register_dev_region(vdev, VFIO_REGION_TYPE_MIGRATION, + VFIO_REGION_SUBTYPE_MIGRATION, + &migration_ops, + MLX5VF_MIG_REGION_DATA_OFFSET + + MLX5VF_MIG_REGION_DATA_SIZE, + VFIO_REGION_INFO_FLAG_READ | + VFIO_REGION_INFO_FLAG_WRITE, + NULL); + if (ret) + goto out_disable; + + mutex_init(&mvdev->state_mutex); + mvdev->vmig.vfio_dev_state = VFIO_DEVICE_STATE_RUNNING; + vfio_pci_core_finish_enable(vdev); + return 0; +out_disable: + vfio_pci_core_disable(vdev); + return ret; +} + +static void mlx5vf_pci_close_device(struct vfio_device *core_vdev) +{ + struct mlx5vf_pci_core_device *mvdev = container_of( + core_vdev, struct mlx5vf_pci_core_device, core_device.vdev); + + vfio_pci_core_close_device(core_vdev); + mlx5vf_reset_mig_state(mvdev); +} + +static const struct vfio_device_ops mlx5vf_pci_ops = { + .name = "mlx5-vfio-pci", + .open_device = mlx5vf_pci_open_device, + .close_device = mlx5vf_pci_close_device, + .ioctl = vfio_pci_core_ioctl, + .read = vfio_pci_core_read, + .write = vfio_pci_core_write, + .mmap = vfio_pci_core_mmap, + .request = vfio_pci_core_request, + .match = vfio_pci_core_match, +}; + +static int mlx5vf_pci_probe(struct pci_dev *pdev, + const struct pci_device_id *id) +{ + struct mlx5vf_pci_core_device *mvdev; + int ret; + + mvdev = kzalloc(sizeof(*mvdev), GFP_KERNEL); + if (!mvdev) + return -ENOMEM; + vfio_pci_core_init_device(&mvdev->core_device, pdev, &mlx5vf_pci_ops); + + if (pdev->is_virtfn) { + struct mlx5_core_dev *mdev = + mlx5_vf_get_core_dev(pdev); + + if (mdev) { + if (MLX5_CAP_GEN(mdev, migration)) + mvdev->migrate_cap = 1; + mlx5_vf_put_core_dev(mdev); + } + } + + ret = vfio_pci_core_register_device(&mvdev->core_device); + if (ret) + goto out_free; + + dev_set_drvdata(&pdev->dev, mvdev); + return 0; + +out_free: + vfio_pci_core_uninit_device(&mvdev->core_device); + kfree(mvdev); + return ret; +} + +static void mlx5vf_pci_remove(struct pci_dev *pdev) +{ + struct mlx5vf_pci_core_device *mvdev = dev_get_drvdata(&pdev->dev); + + vfio_pci_core_unregister_device(&mvdev->core_device); + vfio_pci_core_uninit_device(&mvdev->core_device); + kfree(mvdev); +} + +static const struct pci_device_id mlx5vf_pci_table[] = { + { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_MELLANOX, 0x101e) }, /* ConnectX Family mlx5Gen Virtual Function */ + {} +}; + +MODULE_DEVICE_TABLE(pci, mlx5vf_pci_table); + +static struct pci_driver mlx5vf_pci_driver = { + .name = KBUILD_MODNAME, + .id_table = mlx5vf_pci_table, + .probe = mlx5vf_pci_probe, + .remove = mlx5vf_pci_remove, + .err_handler = &vfio_pci_core_err_handlers, +}; + +static void __exit mlx5vf_pci_cleanup(void) +{ + pci_unregister_driver(&mlx5vf_pci_driver); +} + +static int __init mlx5vf_pci_init(void) +{ + return pci_register_driver(&mlx5vf_pci_driver); +} + +module_init(mlx5vf_pci_init); +module_exit(mlx5vf_pci_cleanup); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Max Gurtovoy "); +MODULE_AUTHOR("Yishai Hadas "); +MODULE_DESCRIPTION( + "MLX5 VFIO PCI - User Level meta-driver for MLX5 device family"); From patchwork Wed Oct 13 09:47:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12555331 X-Patchwork-Delegate: bhelgaas@google.com 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14125C433F5 for ; Wed, 13 Oct 2021 09:49:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE4E260C40 for ; Wed, 13 Oct 2021 09:49:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239330AbhJMJvv (ORCPT ); Wed, 13 Oct 2021 05:51:51 -0400 Received: from mail-bn1nam07on2047.outbound.protection.outlook.com ([40.107.212.47]:26593 "EHLO NAM02-BN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S239270AbhJMJvK (ORCPT ); Wed, 13 Oct 2021 05:51:10 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IeYI4dt69IRIHiDbYdRKc2b20AnAAPrrTI56/8oVLhUkyF3en96y7O27RHM8xp7n1GGZW5uXutsomI5yLqwIETOyuEgmom8kH+4ruwrgtEhHIpwxOHgJdxfz1WOOgZxV1WdNn4dY/w0K7CVwp4dhIQpXHc4PEDGSy6aUKIGAZcOMyfJGKrEVDbITwCKoiJTWWDux+WB5c1WgAK/02SA6LG4v4dvYY+r3+RpZTlWRYGicLZRzVoObfxd03FIZzkve+aPGY9RqN6f+UvXbRWSqKR34T2C5Na0Mc6A+EkmgcC7c8rNcnX5l8/jdHVe9PyQvMlQPfGIcxJLrtOi6k2UdlQ== 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=xSIOmvEoHKRIcrswq83VuBpV0kREeMLLxaSFn8uc5u0=; b=FrkOAL9pkRk76aDTIcdzb50zdpfnXHzC7y8uGtShrxxc7egaG/2hNOX4cGg0hkRkjhKJydHl0F906+TF876MrstbEMthEn+5z2NGqRvhrSqzugezoNoZ8LG5nti1TONP81Fs09g77nPTZysNLgDl40Dyn76GSYOwHxQBtBj8eqVkIo4vD90ac0bUhO6fMcm921xzuVec+97gC/dIISEDZFET4+vObV1seTBUc8vWfayDHf0Ff9TA24nd4q0Q79OoMh7U2OGzPfLX6iz5W4Rw/ZYgXvnZa56oi2FrVWa820Z5YYK7yWZlre05y5teKrbjYbzqCPQxonlymYKCTN800Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=xSIOmvEoHKRIcrswq83VuBpV0kREeMLLxaSFn8uc5u0=; b=W2sabPelrNFQq8KrzBeG8YcwDXLWebaIFXZyLWDkb/4Cod4IvC4ktr1311+wUh3QFc5UTs1gwJxB4hqV/ig4+GPuSPsqbQ8P/riMmMnq5NNDURQKIkzNZgAT29u6WWM7CQcKIiEYp2hXcgIl6tI9H5mdrt1pbYXrsf4lJ+g7MwMGpiPpkeR9Mp/X4SGdzwz42TrVr4bNWzueVxiPFHGED6SJTv2cA1m4sp5jOO3Ao1yxSww1NPSu+ILnULvPrFHjrPBGTi20n4dlJ9tYA+sgiMavgS6Hr81aVRPXTKz6lCshTRYu+2+Dz9Nhg3QVApdrmL3PpS2+4c5+N39n3VM9ww== Received: from BN0PR03CA0056.namprd03.prod.outlook.com (2603:10b6:408:e7::31) by MN2PR12MB3200.namprd12.prod.outlook.com (2603:10b6:208:102::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.20; Wed, 13 Oct 2021 09:49:04 +0000 Received: from BN8NAM11FT052.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e7:cafe::36) by BN0PR03CA0056.outlook.office365.com (2603:10b6:408:e7::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:49:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT052.mail.protection.outlook.com (10.13.177.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:49:04 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 13 Oct 2021 02:49:02 -0700 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Wed, 13 Oct 2021 09:48:59 +0000 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V1 mlx5-next 12/13] vfio/pci: Add infrastructure to let vfio_pci_core drivers trap device RESET Date: Wed, 13 Oct 2021 12:47:06 +0300 Message-ID: <20211013094707.163054-13-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211013094707.163054-1-yishaih@nvidia.com> References: <20211013094707.163054-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 63525b10-d92e-4896-99fc-08d98e2eb17d X-MS-TrafficTypeDiagnostic: MN2PR12MB3200: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OGU5wc4tE+lhH2LsGbB/Y+uYI3LzhqjYmFw8uEsTaZjXiZurkZhSDZquQgMrU26GWum8Mp/X6VtLuqqXjPIXOHW6T2ksLzdNoZvfQEgoyZXgQZaA7U5NeHCmfcxS+IHeRgtw8CWQpSb370OO8LKCRhfvmsICNAY0Rjn9vcnogCK3rWXARTBsJxNG62q4sa3qUtvpn0gh4Our+np15xBIqrzniLsLw6akm0mqGDBaMxeLfl4ttny39MrgrQZ3ZtCDvesteRuqG9u4ka6qkhDwxOBWEEaZFNnlZSB28EU85dXwkJTxeZ0Hm1Dh6ukywDl9oIaHzpEOZauv7icj+LHqWoGth3vcwvKIIzRD0ukWldQpPE1QsiEO3zad1YPF1zoIhsUGfhnzHoOILmAMVLHTl+dcvcHu4TqYiC1eBzbTrjp4Rayp8LNJ+cQce8wqJuDop1xITBedvn3eBzc7RarJChGGr9YelCzrY47EmBYUzLVl9UMXhMS+qHd5321RqMX9NsU9sY1CIRVj+mdOSXMA1I5CjxwyyFD3ePpf1HmGzij6umpRE2/OyZqrsDx+KK+3CKDGrKTkYrwE4h60Fo2jdRNaF/p7FqJi5kZuoU+NA16aPYm1dvh8ExrFvmOAopROvjCIeUIloIulwQhuKgKC4+28r+tA9fB5vxlB7RTlrEfobtPHNR1C/nNlzua7JTDLyOmgLFQ8C9KO4/7HSr+8iQ== X-Forefront-Antispam-Report: CIP:216.228.112.32;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid01.nvidia.com;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(316002)(110136005)(5660300002)(54906003)(6666004)(1076003)(6636002)(2906002)(36860700001)(36756003)(47076005)(7696005)(356005)(107886003)(336012)(70586007)(86362001)(4326008)(8676002)(8936002)(508600001)(7636003)(82310400003)(83380400001)(186003)(426003)(70206006)(2616005)(26005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 09:49:04.5225 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 63525b10-d92e-4896-99fc-08d98e2eb17d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.32];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT052.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3200 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Add infrastructure to let vfio_pci_core drivers trap device RESET. The motivation for this is to let the underlay driver be aware that reset was done and set its internal state accordingly. Signed-off-by: Yishai Hadas Signed-off-by: Leon Romanovsky --- drivers/vfio/pci/vfio_pci_config.c | 8 ++++++-- drivers/vfio/pci/vfio_pci_core.c | 2 ++ include/linux/vfio_pci_core.h | 10 ++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c index 6e58b4bf7a60..002198376f43 100644 --- a/drivers/vfio/pci/vfio_pci_config.c +++ b/drivers/vfio/pci/vfio_pci_config.c @@ -859,7 +859,9 @@ static int vfio_exp_config_write(struct vfio_pci_core_device *vdev, int pos, if (!ret && (cap & PCI_EXP_DEVCAP_FLR)) { vfio_pci_zap_and_down_write_memory_lock(vdev); - pci_try_reset_function(vdev->pdev); + ret = pci_try_reset_function(vdev->pdev); + if (!ret && vdev->ops && vdev->ops->reset_done) + vdev->ops->reset_done(vdev); up_write(&vdev->memory_lock); } } @@ -941,7 +943,9 @@ static int vfio_af_config_write(struct vfio_pci_core_device *vdev, int pos, 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); + ret = pci_try_reset_function(vdev->pdev); + if (!ret && vdev->ops && vdev->ops->reset_done) + vdev->ops->reset_done(vdev); up_write(&vdev->memory_lock); } } diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index e581a327f90d..d2497a8ed7f1 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -923,6 +923,8 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, vfio_pci_zap_and_down_write_memory_lock(vdev); ret = pci_try_reset_function(vdev->pdev); + if (!ret && vdev->ops && vdev->ops->reset_done) + vdev->ops->reset_done(vdev); up_write(&vdev->memory_lock); return ret; diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h index ef9a44b6cf5d..6ccf5824f098 100644 --- a/include/linux/vfio_pci_core.h +++ b/include/linux/vfio_pci_core.h @@ -95,6 +95,15 @@ struct vfio_pci_mmap_vma { struct list_head vma_next; }; +/** + * struct vfio_pci_core_device_ops - VFIO PCI driver device callbacks + * + * @reset_done: Called when the device was reset + */ +struct vfio_pci_core_device_ops { + void (*reset_done)(struct vfio_pci_core_device *vdev); +}; + struct vfio_pci_core_device { struct vfio_device vdev; struct pci_dev *pdev; @@ -137,6 +146,7 @@ struct vfio_pci_core_device { struct mutex vma_lock; struct list_head vma_list; struct rw_semaphore memory_lock; + const struct vfio_pci_core_device_ops *ops; }; #define is_intx(vdev) (vdev->irq_type == VFIO_PCI_INTX_IRQ_INDEX) From patchwork Wed Oct 13 09:47:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12555333 X-Patchwork-Delegate: bhelgaas@google.com 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BE24C43217 for ; Wed, 13 Oct 2021 09:49:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F18E260C40 for ; Wed, 13 Oct 2021 09:49:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239340AbhJMJvx (ORCPT ); Wed, 13 Oct 2021 05:51:53 -0400 Received: from mail-mw2nam10on2053.outbound.protection.outlook.com ([40.107.94.53]:48001 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S239276AbhJMJvM (ORCPT ); Wed, 13 Oct 2021 05:51:12 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KxTFhrKZeNySGFtQk93SFCil8VqccG0uWcXs+4LKRpczGoE7VDfjIlF6+PLG0Rqw/FEItH5mNfaG5r5ZpJFyD1WvEYa/fWmdSO14uQbOCPcMKbA8DQTeqAuTE04syMu7QLgCDTDsnP1thgenTzoAApFwX8sBgOLgcaJUAoR88xfYLQ0PnUyMzO3h411aHayUDTHcGfsWcW6Ofv7GoPyqas1/9VCsw6uknRakLXQHYhhDsPBrZ9VWqXSXnxtnsFt/OpIQu6hCyrN6xWVne3glIgPBDnoeljl2nda6Sq1mmXCEOMHaF15TrcgjGxopQwUnmv3ItCvpcVUD8OkdOS6PcA== 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=nKZ06M5DEgvv5Hcnlj5KjV4W4F5oErEUIFUptUE7ncA=; b=Ds+S4eciEF5P0AjQFB+3pZ64apkiPsjP6rOOvYPV1hAZUwjhP22YBwq5AC4U/hA1jmHpJ4nvvcDYpzPWuVYU30tG7YVuQ6jTzBegOR9lehmPviFP5n3VZ5cQpAWNqd81raVUVGzXyl6MXI/H/N4y5sr82+h4aZT6uQ5QWrWk8kOIzGYjx4jqvvNq6pVxkyzHMXFHbFM8rWA3NUIntI+IAEywyLxbV1b3JIY4e/7G40pIT6IZnGc4spbYu73+fzlZJydQgje628c3ftG5RuDCPerWpjAgUUgYHn9FZKpVKvijvUGhLlabb2Hn70jYBqJtCZFsMTgQbzR2Dfv6ZsHoTQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=nKZ06M5DEgvv5Hcnlj5KjV4W4F5oErEUIFUptUE7ncA=; b=JrU6SCNlLAijcrMN/eb2eoqeDIaHB09T6MNVuG1IXKJQ8sf806nFUhzlzYEkzxuHL18/5MCy+BFGod239G0XTVnr1/Hqfuhk1GdOp4B0zjpH+wGvxEKWc0kMyUs+cDwNhwwvnIXfKIRFznTKM9cr/iPBmTRRb+YdPDSlntXKSfh4p9mJ/SS18pIqmLYVKqSJ+ycCenEcwPmOStGTzu2PyemvAoVAOD1vv5GFuL2Yi5atm0fMkaVuFCOPOV8xHN8JwGrlFq8bTneMQYgT9HXLRPcjb5Zi7XEHweX89tvbHNGLhL45CX/FZfJBWDOk5fNOesaWlN/zSyBRtuKfQuQbBQ== Received: from BN1PR10CA0015.namprd10.prod.outlook.com (2603:10b6:408:e0::20) by BYAPR12MB2856.namprd12.prod.outlook.com (2603:10b6:a03:136::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Wed, 13 Oct 2021 09:49:07 +0000 Received: from BN8NAM11FT057.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e0:cafe::8a) by BN1PR10CA0015.outlook.office365.com (2603:10b6:408:e0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25 via Frontend Transport; Wed, 13 Oct 2021 09:49:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT057.mail.protection.outlook.com (10.13.177.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 09:49:07 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 13 Oct 2021 02:49:06 -0700 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 13 Oct 2021 09:49:06 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Wed, 13 Oct 2021 09:49:03 +0000 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V1 mlx5-next 13/13] vfio/mlx5: Trap device RESET and update state accordingly Date: Wed, 13 Oct 2021 12:47:07 +0300 Message-ID: <20211013094707.163054-14-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211013094707.163054-1-yishaih@nvidia.com> References: <20211013094707.163054-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 81131ce4-bd74-413e-d1d1-08d98e2eb34e X-MS-TrafficTypeDiagnostic: BYAPR12MB2856: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:883; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EWHUVaRj5D6uMMWJo3p/mDDuLzzdRu0/tJaCSbYemmN10Ya/+ZI38c3YYGPV1+oxOfwlxDFTuiYuU65rvgbzz/WyizPWFh4n+LthESannaQU/ZKCRbR9vCMPUskXhXq1r3DBSBpuEWCnorwQeH6ExY6rd9DMdDTu6jp331bCVPqZnPyhXuNZ2zGw0BQLQE9fpbgLpR+1A4Wq3eWrJmCpIZr0eYczWay+20G0ir0vdLyQ0YzfR+9WVcC3u8Rs2EJxx3EGb+MWg/M2OZJDDEuQSVKYkA2Pmk4pD5HV/CAiyabO0rn6rS68uUPTjySKgRwJ9LGwF+5KqOgNpiT1MfKXXrK3wi+GloryXcgKvVcYAcmS3efBwlYInnepX5Qakqr6T+sIUtOcVahZEzOZH/ymCHmn5hdIQTXVAiB1X0KmWYBNFL/7GRUQeXx7Jp9Fe9nalSGXj7vVKj7ClCS3w+HuEKSjrstnH6agZet1AyjeZ9KSdKU+S7g51mPI0Ajs6sB6pLNbsF6CjtUv+cA6niigkRHPvvv0NGYqxyJqRbOur6UVfFFK/BpBXMicfqscENE7+wP2Y0yx7YBf/dmODVmzez5hkrs2S+iyxCCPVTOnAvsRIFciVXsYs6ovqpZ0vXB0raw2kHhmWN9+boQhH/7zlHxbS6Q5h+/2RgjOeITduEKwvWUNjBbKdi/hfHCXgLx1RtbrvslooSFHjDMve09WCA== X-Forefront-Antispam-Report: CIP:216.228.112.32;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid01.nvidia.com;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(70206006)(36756003)(82310400003)(508600001)(8936002)(316002)(2906002)(36860700001)(2616005)(7696005)(8676002)(426003)(110136005)(4326008)(54906003)(6636002)(70586007)(5660300002)(83380400001)(86362001)(1076003)(26005)(356005)(7636003)(336012)(186003)(15650500001)(47076005)(107886003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 09:49:07.5776 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 81131ce4-bd74-413e-d1d1-08d98e2eb34e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.32];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT057.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB2856 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Trap device RESET and update state accordingly, it's done by registering the matching callbacks. Signed-off-by: Yishai Hadas Signed-off-by: Leon Romanovsky --- drivers/vfio/pci/mlx5/main.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/pci/mlx5/main.c b/drivers/vfio/pci/mlx5/main.c index e36302b444a6..8fe44ed13552 100644 --- a/drivers/vfio/pci/mlx5/main.c +++ b/drivers/vfio/pci/mlx5/main.c @@ -613,6 +613,19 @@ static const struct vfio_device_ops mlx5vf_pci_ops = { .match = vfio_pci_core_match, }; +static void mlx5vf_reset_done(struct vfio_pci_core_device *core_vdev) +{ + struct mlx5vf_pci_core_device *mvdev = container_of( + core_vdev, struct mlx5vf_pci_core_device, + core_device); + + mvdev->vmig.vfio_dev_state = VFIO_DEVICE_STATE_RUNNING; +} + +static const struct vfio_pci_core_device_ops mlx5vf_pci_core_ops = { + .reset_done = mlx5vf_reset_done, +}; + static int mlx5vf_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) { @@ -629,8 +642,10 @@ static int mlx5vf_pci_probe(struct pci_dev *pdev, mlx5_vf_get_core_dev(pdev); if (mdev) { - if (MLX5_CAP_GEN(mdev, migration)) + if (MLX5_CAP_GEN(mdev, migration)) { mvdev->migrate_cap = 1; + mvdev->core_device.ops = &mlx5vf_pci_core_ops; + } mlx5_vf_put_core_dev(mdev); } }