From patchwork Sun Oct 24 08:30: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: 12580069 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 3326BC433EF for ; Sun, 24 Oct 2021 08:31:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1AF7C60E9B for ; Sun, 24 Oct 2021 08:31:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231172AbhJXIeB (ORCPT ); Sun, 24 Oct 2021 04:34:01 -0400 Received: from mail-dm6nam12on2068.outbound.protection.outlook.com ([40.107.243.68]:27360 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229844AbhJXIeA (ORCPT ); Sun, 24 Oct 2021 04:34:00 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e62/isbjChHv5CHnU/hoV2Nm9OKo7s+AqlG63TBI6CnYUV+9hxNSCEGVjZL6ZN0NyvYwfnMHu4YFKLxRXAmAg29jIb+osHvbwD99Q2Q/6f47ZIE1MY1CCPs0A4NmgElHTN6t77hpePSat0fIPgS1KWlZcQBd0suUXrdALKhpGeGSV4SHM3vBVZj3WKN4uu/5JYJ7lTSwW4bGabVrrksgJfLE1QtmQHr3vBkOS5gbd7VqVBN8KxcUoXOpZ2clT0ivAjq4eqHJ4zO4qjsRiAjLFoxw6SE3U8igbhy15wMJAVCPXtD9qHdwNMuHGpTsVupp4Czm5PHZceZUB/J28H7+nA== 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=4WQC7MbzY4SkKjUkPCgiLuU12kLGzfDWQ2BT0ZKYN6s=; b=btkj9FphTdBeObOjdIuUwMZSscl8c9zOmqLnHkN7kDv77zFROsUeUfTZoghLniqPywcvjtjTr3tuvFJdqgNIzX//p3ziBbZX+/lg5kShy/QpWGRwSQ1bi+ZqS+0eO624sGIy+UcmXP8S7hW9pHX0xmBqDDjOdMP2jeMb19EVfjmYMv4+fUDuduJEoP74tLV/I8jCc3PLJxHXMwrezIrO47r9RX3w8YVJXjdSZPRn4eELHLzJc0WpSyMw0KfcSTE7cMilHuYOyE63XfUvCEaWAc8chrrt9NITacKJiQoLt5xqiK1xV8IhCcKdmi5E4zOv80nxowLzItsQReg7eUuC2Q== 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=4WQC7MbzY4SkKjUkPCgiLuU12kLGzfDWQ2BT0ZKYN6s=; b=Xws+8MU8/H4JWndIWbwNYOOCBiSiEBoHQVjgybO0X4J38GIA7S1oU5Yd/Q6p+vJM2EM9ukBNZmZ+PG7RCnjfTSTifLQ2MNHqL97UPYNJmReNP4fMgOtpsRFjRLCizzHxdn3yt5BXjxBz8HCVQ7WPwhGJmPbnwgRpd5VGFscl2VRX25LLHKqX52GY7Pj4Q3FBtL/h+zhgNr+7ndUXKKxHm1sTqXvBtj9gul1dm83TxiZzjsbohaPx+uiX0j2lwp3UOZRe6Id02TfRGU1sVxtwyEifFs2mP2Gg3RWIfLzggTHwT68R8utwUFBHJWKa2Qgyp5s+hjbnAS6o5nOICObTeA== Received: from BN8PR15CA0011.namprd15.prod.outlook.com (2603:10b6:408:c0::24) by MW3PR12MB4506.namprd12.prod.outlook.com (2603:10b6:303:53::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 08:31:38 +0000 Received: from BN8NAM11FT037.eop-nam11.prod.protection.outlook.com (2603:10b6:408:c0:cafe::59) by BN8PR15CA0011.outlook.office365.com (2603:10b6:408:c0::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sun, 24 Oct 2021 08:31:37 +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 BN8NAM11FT037.mail.protection.outlook.com (10.13.177.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4628.16 via Frontend Transport; Sun, 24 Oct 2021 08:31:37 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 24 Oct 2021 01:31:36 -0700 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sun, 24 Oct 2021 01:31:33 -0700 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V3 mlx5-next 01/13] PCI/IOV: Add pci_iov_vf_id() to get VF index Date: Sun, 24 Oct 2021 11:30:07 +0300 Message-ID: <20211024083019.232813-2-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211024083019.232813-1-yishaih@nvidia.com> References: <20211024083019.232813-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c8203ec9-6178-4393-acf4-08d996c8b258 X-MS-TrafficTypeDiagnostic: MW3PR12MB4506: 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: dpT14LwDUo11zj7Boh3kT7CO444V6oPkpfX9yzukqakMNjczrnayCbSJnt8LglDAAlnKxGN6cpPD+6AG6LyCtN2zKBMGRHC3VfT0z4eoYf+F/6fxIblBNzbNM33n3Jot8A1/9vNDZ5jJ0SaUeWNHyVJsmyqgrCBOEaLzVggh7mqQrfFuzddAIhMU/sJcrctmzN1EWPF826jdlJ+zJdOpvn28IHPtt/LkE4MSxSMNbUp6pZ5/4HCmlqozlQjRFcpuAbJ+wJvlTpp0FCK3xjUDwZoTWFVK1LaseGPJxoZ/7/Yssq8sitWndaq2Ahz7dLRievVf1vvB/aGnXOITW1JpiSR0/dSMZo8Nbpgz+M16WuYKjJGeJFTmcM++aDNoL2wjgDPXGbZlEH3TQrKHT0EhgIUFoX7AM43d2Mfa00QsMphv2BY6LlrK8wlWYmzp+4K9O7gNNoPBHe38s9g7uxOxvkqc8Yv0umYaDexkUe4GoSjlOoPExJrRRkrmTee04F2m7Y64z/lIB7EnaO3ishCLW1thuP3ObT9A/8N6FFkPtysWfXqqoE2/y+SLzCnEsECT1VcVJyFEPcVUAnROvnwh8MRUDAHncYGAE2BtLffSzqJSjv6s/LkT5yMRi5FfYZpJ4jywZa89Ez364KQXK1tcrdF8zU4Vl0Jxy3KSo1iSdhBzQo8ijybPsdRhXpV6eQid+fOHOIgYuCxc599qLH/oWw== 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)(26005)(6666004)(82310400003)(54906003)(7636003)(107886003)(356005)(186003)(5660300002)(8676002)(2906002)(2616005)(36756003)(7696005)(508600001)(110136005)(83380400001)(4326008)(1076003)(426003)(6636002)(47076005)(8936002)(70586007)(70206006)(336012)(36860700001)(86362001)(316002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 08:31:37.7628 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c8203ec9-6178-4393-acf4-08d996c8b258 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: BN8NAM11FT037.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4506 Precedence: bulk List-ID: X-Mailing-List: kvm@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 Acked-by: Bjorn Helgaas 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 Sun Oct 24 08:30:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12580071 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 14418C433FE for ; Sun, 24 Oct 2021 08:31:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F2B8F60F6F for ; Sun, 24 Oct 2021 08:31:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231486AbhJXIeH (ORCPT ); Sun, 24 Oct 2021 04:34:07 -0400 Received: from mail-bn8nam12on2048.outbound.protection.outlook.com ([40.107.237.48]:46176 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230300AbhJXIeH (ORCPT ); Sun, 24 Oct 2021 04:34:07 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nE02L6HKKfbc1Guu0R0ZvlqA60sbIT33Z0HXg2oLzgqwkfEnpVmqSvURERM6DBDKJP+1wxfaSfZxhSuezxpXN/w4OzvFZYI8SfkiWl1ZwUYa51F7Olhnct0lOSnzets1PLzcr0/VIgihkNI+7+eIdEqS142cmlPTTzwhLBmoOjslpEM6f42hc1Eoo++VDWvAmecpxI5PF65mqdDGKNuf32Brze0IWYngmpJvN8QhHKQtyl6n6E2tiFpKGUTODNh8nOb/w98rquS1TEOzZYNAW9NmjuZEuM8QL7lb55A1JbJycqb6YXTTwX7pWZtn4fUZpen4BapQAe34hnfeqq2pUw== 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=NWVhBi2yZESzlGh5fi74QPXdUj33UqYeAB7tLhCgTKo5TJM8FnoMbjxgkF9mXUdZWl60a9pK0b8Jtz3XXZt2xKItAitkjeLl3JSdkCNYZ3QrK4AurCfn+6Kedtysd26LJpm2FC7Qx+ISwlvI3u8BPw5jy4oJK7mYdx+4pMCldqyGaU1GgA0IunImJNkgsvSTqjiInWYctiNTgwt70dixrakaTd3EwotZiMkFyU6L50qL9Gh6f9XOu6/p9kbEW8r4wlk1/8uOwiusvcwLSFjon5/pbpPUDapSdNy8bCbnS+nKBQ6Nl3kJnSdkpM83bOb8XMp0/CI7oUhOxquk2+UgUg== 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=eawxF+jFRBAH1P9hWq5BE145QVmYPfYNp1U9MJCuY0E=; b=fCOVMOxNTzYQ63js3m4wJVEosZ8/dBgw8kydzyZKn4SX4lNMjl41A2WDHqXNVre6HvKVETaRLrKCSWSU6AZ5RVHf5aeiU93W52sD0LYQKvbk7GQGbtC8GXxKPI7sdBh2ROZSZC6XvYRA5zxUEUJOyqxlA0pd86BvubciQjGe3r/8EQ04XB4F1irBh9pjNi4VXPr9U5SLITCvKuAAG+wbvbhAKv1Boe2X0Rm6AaWwV8jCcgVchK7HNIKCiaI7Vwwua0qotWnv1wzYdGD6Kt09ZE1c+l2XfBKg9owHUChoYX0CPalJeHYlKFZCl4qqt2bXtDsZI3hTdNsigHH3Sty0kA== Received: from BN9PR03CA0145.namprd03.prod.outlook.com (2603:10b6:408:fe::30) by MN2PR12MB4238.namprd12.prod.outlook.com (2603:10b6:208:199::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 08:31:44 +0000 Received: from BN8NAM11FT022.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fe:cafe::f0) by BN9PR03CA0145.outlook.office365.com (2603:10b6:408:fe::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 via Frontend Transport; Sun, 24 Oct 2021 08:31:44 +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 BN8NAM11FT022.mail.protection.outlook.com (10.13.176.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4628.16 via Frontend Transport; Sun, 24 Oct 2021 08:31:43 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 24 Oct 2021 08:31:40 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sun, 24 Oct 2021 01:31:37 -0700 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V3 mlx5-next 02/13] net/mlx5: Reuse exported virtfn index function call Date: Sun, 24 Oct 2021 11:30:08 +0300 Message-ID: <20211024083019.232813-3-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211024083019.232813-1-yishaih@nvidia.com> References: <20211024083019.232813-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3df2d594-e910-445d-7d64-08d996c8b5f0 X-MS-TrafficTypeDiagnostic: MN2PR12MB4238: 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: 83728EU8iUEVmb0Pp0ghzzpyVG6zJaPPQkJkcecQThIMoY/vAhS7DtJuzbw0Tg2sbM1BDMgrGeoJychQzNzTRHABVtYJM3LmAXsfRQScY3LE86G2F9Z91yqQRl3+VTz0GuZOBTsxSrh3FYWt/HHt5KQEMMi59jEU+CLlQoILk2ixr5bgYIw1gt8a/qDh8NPAD8s664ODWVgH8KNIhZ1vjw+vrrpYhCE/kszmNj6QpzQFJLbe9K21uuz1OWZIVe4zKL2ntYfqqjZVA0VK10tqgD9oxttaQu349Z+xoOfwJbfzhMusFDCLMq/vCp36HGsPN+ZiGQ2JT7+fPvOeO/BGD1k82rQw+/L5OkmTfTDLaMY7xKTLvZ1EySI3rccbCo7u39eUPpjpO5XQwpZ1qjWWoP825ttBaV9p6fgL5HIYUP90k7CXbQR3gNqU+BRnF+gu3bYjU8P7w/ZuhSonjgN2vj0Xh2fLRq8lQ3z+QNMhfqo0CFwlJywNO6CiOCGJrozLVBs9DKQ+ysF0dwhKCMloEZF+ML+A78MCzO1h4T21qmdmgpZ1u8yQ0P2hAfclybGH5WjXOBpGLII7NtR96NMhQilYvnODZ9nGL7gMA6SXrruVcvduQaHz/2UJl8eOkcMXHkI85GHLABMxxWWIcBh5GWKhTxkNms1YC3w0gQaSFivnZBNk+75hl9ld5/Ep8WflkhiYIqpdlw1TZ9nzSyqXNw== 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)(8936002)(26005)(47076005)(4326008)(5660300002)(70206006)(83380400001)(1076003)(508600001)(36860700001)(70586007)(186003)(8676002)(356005)(86362001)(36756003)(2906002)(82310400003)(110136005)(54906003)(316002)(426003)(2616005)(7696005)(107886003)(336012)(6666004)(7636003)(6636002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 08:31:43.7849 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3df2d594-e910-445d-7d64-08d996c8b5f0 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: BN8NAM11FT022.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4238 Precedence: bulk List-ID: X-Mailing-List: kvm@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 Sun Oct 24 08:30:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12580073 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 6D0C0C43217 for ; Sun, 24 Oct 2021 08:31:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5692260F0F for ; Sun, 24 Oct 2021 08:31:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231574AbhJXIeJ (ORCPT ); Sun, 24 Oct 2021 04:34:09 -0400 Received: from mail-bn1nam07on2052.outbound.protection.outlook.com ([40.107.212.52]:64064 "EHLO NAM02-BN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231290AbhJXIeH (ORCPT ); Sun, 24 Oct 2021 04:34:07 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xu1HpVUdIlQn1lnxNNr2aFJ8kFyhzAHzS3GWWlxo5OFeDayBTLtLhYdahPYYCu7ItalrSbkMiW7wDPmkj7AEewCVLmGRK208GCKXGOyg1HTYEtc8XtDC65XxcCZjFU9jo1xbWkagWGwThUD9DpqaqHh87Xn5pzjek0mW6/PjdDKsy7eZGe4DJr95ymXwm0d/2VNu/zeQ2DWN1lwNckZP8W3+JRZEkkUB9M7M5qEfWDT86fTggkomJ07gHXa18mJzFzlVhTgBHzDcMDb9xtEH7PbeJTeB0OqWHAHOAUYmPOSPVuJ1KJnAMtIqHT3VUhPjUlvigvo8dCBF7vj/l9N/uw== 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=UxwEGb1Tq9GCbfjoAuRX3+IQRB0eRF1folS+IMW7dnSiCw/O/NiP/Sd8RrCvcaJka7tb9JzVxESbSG+bIxi99chz+3Q0gjHyREAYDSCWmJ5jYhj34jon930bvF7mkHuzgwhlemtOyoeZLEbd9pX1fTpSSXJFIhWVg9wseVvQbbG8WDwXLEgstTyQUsLRzM41azQVnTxo+qyQnwIYvBuIGk1imGZVoPF/b0YbX7jFslpqRTAjx2rZ5wkYbu0Qdt6Cz7THx+0wXwdUhb064VG6oU5zFTgqPKCRvkODJbwzly0PnRgYEjTEvJBrHwizSXKQRUU1QWClI1EPXbrhoQymOA== 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=ATQOdGVF4dTjbvMJ1bmmazMNjFwWqMg4M5PKqHqf20k=; b=E9719So0twS2RaXsq+pIDX3vriPnVdeqaa/Iy7b2jfcQPet+PmiLy3LiV/21Kogq2M2XEZ0d/XMT+67Gv+9UXq3z3dRR7E8Mv98cHZfI/GGxOAUDmz/Xyq2DIGb1qdPOwo7qCLtXtTfl73GYosaj5Opm+qxr2eksO9vlR/3FXsT8rQxLxRkmv6MSAjNdMBGoKSkWNe+XfpRHe6nBaFdl4F6F+JMXX7B/SooqaS6Uo4TIqgfOm7O3GPnS0Nraj4/7iGtLH8Ll+cvpKuBlgzxXcLiSlYxSMX71JSAEWwtYHeQpG+84PnIqxADlzT8A+N7EvyXOphO3uWV0vf8KeVFWCw== Received: from BN6PR13CA0054.namprd13.prod.outlook.com (2603:10b6:404:11::16) by SA0PR12MB4432.namprd12.prod.outlook.com (2603:10b6:806:98::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 08:31:45 +0000 Received: from BN8NAM11FT034.eop-nam11.prod.protection.outlook.com (2603:10b6:404:11:cafe::81) by BN6PR13CA0054.outlook.office365.com (2603:10b6:404:11::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.10 via Frontend Transport; Sun, 24 Oct 2021 08:31:45 +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 BN8NAM11FT034.mail.protection.outlook.com (10.13.176.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4628.16 via Frontend Transport; Sun, 24 Oct 2021 08:31:45 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 24 Oct 2021 08:31:43 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sun, 24 Oct 2021 01:31:40 -0700 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V3 mlx5-next 03/13] net/mlx5: Disable SRIOV before PF removal Date: Sun, 24 Oct 2021 11:30:09 +0300 Message-ID: <20211024083019.232813-4-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211024083019.232813-1-yishaih@nvidia.com> References: <20211024083019.232813-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 541e3490-0498-4d3f-fcfa-08d996c8b6dc X-MS-TrafficTypeDiagnostic: SA0PR12MB4432: 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: VBpqrp2zkjMt3cMg3inqRKF4QUNPTvRYk2DBt9LiFnWKHwZQuwjen3Ae2n9mkogWNzfZVy8JylP6KZs7dQgc/Gr/89peovHqxRtDoi5um+mHKTDwDGcr1nms75DscpEqrmrUYv5Yj+y+yXtwak9v4JYcsRm0IdKiTuzAXLE+f08WDUTJnOzBE2q8hsyv6MH5s7h0FRiiYyULvKA0lMfDLcBjwHFcwpGx0UVKUs50ZKxC6G52DWtR07Ca7XvrjjCriYgKCuC7i+c1GWtNDIX1tB9Wcy6XyJ97wm4H97oxnJGXSF6Mi3GBAKD9BmELFNDLopaDDo6UqWtV3QQmo/6a/iFov5+NcYtWLD29GMHz468Tpp428+8k2QFn902I7yG/0NNmXa3VfiKj/NJ2lKd9tNM7nwjsQW5x0Uk7S3Zue5l51SroyF+Enqo30w/6vV7e1n9AdsYcfdbRrpPHmI1P95mWhE+I2xwWOEiENpO1hYl/uNVxkIV/fP16H23K48AtnY9qg3mSmh59cfjKTAFjrMTOJAtH78T0mWrnVerCQszHIcf0RRyGmgNIdUMV12lBRa7WDQpgZZT/VnsrV/XgH1L/zuH+sx8xbXIy0Fp/pSQeyeTASwdeY1Eaui4RfJujvinqq3zYJcaYye9LscQ6utLNch87XYJF+EYQSq9COldGKTwzCZQk2qvtuW7to1o/XM8Zlm+/mK9igcnyNprACA== 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)(46966006)(36840700001)(426003)(36756003)(83380400001)(70586007)(47076005)(70206006)(2616005)(7696005)(6666004)(336012)(8676002)(4326008)(82310400003)(8936002)(110136005)(54906003)(7636003)(36906005)(186003)(316002)(356005)(1076003)(508600001)(6636002)(5660300002)(26005)(86362001)(2906002)(107886003)(36860700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 08:31:45.0390 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 541e3490-0498-4d3f-fcfa-08d996c8b6dc 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: BN8NAM11FT034.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4432 Precedence: bulk List-ID: X-Mailing-List: kvm@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 Sun Oct 24 08:30:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12580075 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 1B44DC433FE for ; Sun, 24 Oct 2021 08:31:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F18A260F0F for ; Sun, 24 Oct 2021 08:31:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231540AbhJXIeR (ORCPT ); Sun, 24 Oct 2021 04:34:17 -0400 Received: from mail-bn8nam12on2048.outbound.protection.outlook.com ([40.107.237.48]:15457 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231670AbhJXIeM (ORCPT ); Sun, 24 Oct 2021 04:34:12 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G6blWuZR5izm0cd9TmiN65UmmqiXlRDtcl/SNfYBuAXDxs7tffIvt567aa1bCbX//pwXfVOKjY2UoiQQ9tnCbRv10X+1UhU5QrKE/pD6xZnhR2l5aek6NpdbGkwxlFUPRuEihlpef/NgPTl8piIMx+ki8aEt9pkun2siUwx0U292u6a5gJsfJ9pNYHxUw8eQKbx21xVHeZLdaKRU8UsBaJPitVWE9SuiM5SXPjXgV8uIK+4a/XJ6g/H7A9D7XyosL+d/DSAIfSJq/PfivAN9oMzAZOIwIUvT8Mu9j/URG1YIVVWNU2BkQKMqgpy55B7hY6jD1E4mCdeL96WhtWbV4w== 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=PX8vNibUQ+77tQfzz+YEsNNh/fZeI9f68zyWZiZWxw8=; b=jAxGj5RzKLS3Fcmo6tOiRlnW2OrzI+5vdMTJVMx9z5i/VAKI6HvHjknqvE6mXp5efsr0JEEaDtnyExGiDwsOvUzS8WFHLCvO7d4xilWVChYJ/vGvt5q9ne2TqEDh4nc5Kqwh77d3KKY+tYNu/rZPBzEZQkNcGlA4nvrsAUzUSGEQJowqhooLCO3A1Q4VpH6uz0e3OaH+3/Z8C5z9/5CW/XBiAND4QFVuiJCnbiueaLtqDdZ/MF2Q/yGHPPdN5XomoRmLqBJFfKF5rVT1BxXu1W3oj5Ki3xgWyRw1TczUJBYKTqA53B79SPyaV9znen6PDQIL+HS6/n4rN5JYz1t9wg== 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=PX8vNibUQ+77tQfzz+YEsNNh/fZeI9f68zyWZiZWxw8=; b=YJl6h6ZPWxaf5bTWu3yi2IibT2a8MrYSHukvmwTfnj7mQcGzr7krKtrAE4aV3Tg7ExsIYLo9PiWMfxhAMIucpvXRGWYgKGTGPp5+GoRHl1WwIYcloqhiK5XIgBbUx1IVygjH8b49nEsBTefjHZ9PeglJR0iWFNNwzacfAjrPGRfCp+WYQ6kIX8XIoxChNsbeBQHOPekEbTFu5Wpil13YQG0Y0K7iR8AdqqzpazCPHeHAgZFSKFKlkgS1z2bAdtag11YAkj7pc3MAIb9N+HiV6cmgCuHYEkz3jdHp5V7wV1s00Eqz1Z5+Xf/cj4HG92tcjwD56bIlAN015jUuo76UQQ== Received: from BN6PR13CA0067.namprd13.prod.outlook.com (2603:10b6:404:11::29) by SA0PR12MB4383.namprd12.prod.outlook.com (2603:10b6:806:94::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Sun, 24 Oct 2021 08:31:50 +0000 Received: from BN8NAM11FT034.eop-nam11.prod.protection.outlook.com (2603:10b6:404:11:cafe::96) by BN6PR13CA0067.outlook.office365.com (2603:10b6:404:11::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.10 via Frontend Transport; Sun, 24 Oct 2021 08:31:50 +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 BN8NAM11FT034.mail.protection.outlook.com (10.13.176.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4628.16 via Frontend Transport; Sun, 24 Oct 2021 08:31:49 +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; Sun, 24 Oct 2021 08:31:47 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 24 Oct 2021 08:31:47 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sun, 24 Oct 2021 01:31:44 -0700 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V3 mlx5-next 04/13] PCI/IOV: Add pci_iov_get_pf_drvdata() to allow VF reaching the drvdata of a PF Date: Sun, 24 Oct 2021 11:30:10 +0300 Message-ID: <20211024083019.232813-5-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211024083019.232813-1-yishaih@nvidia.com> References: <20211024083019.232813-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 423a5e5e-94b5-4ec5-c97f-08d996c8b991 X-MS-TrafficTypeDiagnostic: SA0PR12MB4383: 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: EQqejJx+S0nPR1Ts7gRY9bg+ZpeiIFPdgy0gpS1+YzJvZh4++NwtfjSCD9OFTfy5W6cSLHf2mZesXH5XytVXzq8sfWK4KKyj9ai6ymxx8CpXPyrtBfZht64D+7/UjC7LfInvQwG3oYQh/4ZgvvkJ+g/XlULBTeFMjKW9Y3Y+6QY67v3ZmGatXRMZyOMTzOiRojVFRnyrBfpR9Fa11VObUkxkFBnl4j3qPCN4j8f7O8Ibaj9OKwUHwgdXmt/lrqsNNjvhlYoB2OClX0b2pn+FA5QJ2vBYv1VdXuADQzFOOOk6RqPlNihafeTr7DViON5JDYRkwMKvi3ggiJY5UP4t2AOT2Gm/LtZSx9ce8O+J9jU3enNNfnOksG1OfHsB8DiY+1o5soB1XvPRQQLleMtAALg+0m+/TYnb+wlysRnePi2g1fFX0C8MoEj+qcikO2AzzHc482T4WMPhrzERQ538nrjLqto4n3DmKAXpWaGz3Avf7YID0GqdWqvIAautjWb3vYebvJYtdC//tq0kj44Cc1KQ3dCFawJKR3nl5BV8dKH/kid0ajICzn/mFzdykoEqz/0PyUhvco/+TV+Zh53rr2Ptn3iE2P6yqFT0WO/jeA86TrdzEGjiWhax7XDfxEhXX5NgcLpMhlnE9WQTGaGSOtvFGTbPBP89KeiA1apl+5tL6AhAQPIyc1s00/Qu9TwDoqG0fmPJXi8X+h6/utioIg== 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)(36906005)(7696005)(316002)(86362001)(82310400003)(36860700001)(356005)(26005)(6636002)(36756003)(508600001)(5660300002)(47076005)(186003)(83380400001)(70586007)(54906003)(70206006)(6666004)(4326008)(7636003)(8676002)(1076003)(336012)(426003)(2906002)(2616005)(110136005)(107886003)(8936002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 08:31:49.8851 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 423a5e5e-94b5-4ec5-c97f-08d996c8b991 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: BN8NAM11FT034.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4383 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Jason Gunthorpe There are some cases where a SR-IOV 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 Acked-by: Bjorn Helgaas Signed-off-by: Leon Romanovsky Signed-off-by: Yishai Hadas --- 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..8c724bc134c7 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_virtfn) + 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 Sun Oct 24 08:30:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12580077 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 3D91BC433FE for ; Sun, 24 Oct 2021 08:32:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2D61760C4D for ; Sun, 24 Oct 2021 08:32:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231859AbhJXIeV (ORCPT ); Sun, 24 Oct 2021 04:34:21 -0400 Received: from mail-dm6nam12on2059.outbound.protection.outlook.com ([40.107.243.59]:16865 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231564AbhJXIeP (ORCPT ); Sun, 24 Oct 2021 04:34:15 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j10VRmCf3xGUTRvmVke+JNJ9vSIrLTJUFmwKejAjfkEhGh/vYn43HLSn/oOk7OQhKKrfPQTihNftqrNUIUIgwVge8Qh7Y0C/LkHhJaPjzg39fErUA3Yst1hOEZLbpPJUMRAOS4fCXJVClA5MJeFavfwhkjSwdG2n+PBwRupEkMwv1A5Jhs5b523HBt6iMZB1vzcFpFjmuFLcM6/5vLwzrwo65fY52dKuykMqF3hA2W9DmznT4Bo4tEhBAqqOzRdo/uMp8d95htLiU0cYoMSyb2lHgAG+ml/o6RxR62DjECB1ykJP8y+ogJdF9o5UZBa9TrQ+Yt2RYS5BpCr+QIodKQ== 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=SGM/5WyQiFedKLhgRGeSt51bs8U3p9iwIg62/gXzWEExN2b/C9Qf45DCkEm4R06eFM0U7bNDWN3OYG65m1KcVX96pUxhMaQdjCJ9IqGwhRiI+h5W3CZQ5hWxQPYuETE3+gEVYftdl66JYcrhBzFrkf8Zl5HUAUn7jXHZXf97CBktvM2SWHvEEgPiA1PbCh4y1ZjvHN4gspy72hvCPhxVHalGT0YNtYlB6IZobBUcdEd1BKLOjoOWEsLy/Afd4hXNpWjjJ2zB2/3XcEjDKDyGmA/2/W6AgXp65uw0eznxpD8q3HS1Zf2yvabMnS29y8esWxTaeo8AJLI6gmOuXnDvsg== 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=rxrDpXNKpSErQ7TUV+yNIUWngZm0TVMYim07zMmg6r7TnrVt5Ago8q22diPVRJSdTsVSnGEdyeLsL863TuQ5YxxoO5I2Kv1I83h9jiKubLCv7Wgwmt6bg9YzwhcnkvOMTZlfXcN1rZaUnhIVdFJSUA/r4lMOtlqvK/EF4C1Vs7qrP9dw/BDm+lJn/Ry2KagLTBc3hVALHMAuhnL1WUQnpvxgzS9YihMRqBA86geGLh7ltfKRlw0CC918iCz9KkfKdGCM4yBo777RzOwoZsrrm6fOhksVfxoBmw04DxSXfImeuDOqGy8VdBZxayO6ViKbZ8oOWAxnFucZmLB12bEqCw== Received: from BN9PR03CA0276.namprd03.prod.outlook.com (2603:10b6:408:f5::11) by BN8PR12MB3508.namprd12.prod.outlook.com (2603:10b6:408:6b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16; Sun, 24 Oct 2021 08:31:52 +0000 Received: from BN8NAM11FT052.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f5:cafe::6e) by BN9PR03CA0276.outlook.office365.com (2603:10b6:408:f5::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sun, 24 Oct 2021 08:31:52 +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.4628.16 via Frontend Transport; Sun, 24 Oct 2021 08:31:51 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 24 Oct 2021 01:31:50 -0700 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sun, 24 Oct 2021 01:31:47 -0700 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V3 mlx5-next 05/13] net/mlx5: Expose APIs to get/put the mlx5 core device Date: Sun, 24 Oct 2021 11:30:11 +0300 Message-ID: <20211024083019.232813-6-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211024083019.232813-1-yishaih@nvidia.com> References: <20211024083019.232813-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f7ba1389-37bd-4281-9bf2-08d996c8bad0 X-MS-TrafficTypeDiagnostic: BN8PR12MB3508: 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: zsHJpSWvEhJeeOi/TPVqnBveQ6/fX4zcCtpby6pLSyYutFD8+UllGmhbUlTRqcY9ZF5fgpODeBZcRZxwLZ9yDkvBwLHJViv3qU6p14DJcm09t4RHhkT3ZgtkwzfhyxeK/NOgETODUUvVcVrH9pp+6bCRbwWgNEnRZl5Ki9qmktrKD4th33yX1B+VoF1zCYHW+kqTB5hiyaLhEfpjUkJYY0/44Ua6LG2B7U4H+5/xq7jeCgEYrUvmmqmDbKElPtpljFZb4+ca6SLMkJzgkQx5cruMH/Cw8AHGtKlR/FqdsKD3lWzfySHqYBlJ2XQ98jdEKEZZN1YlT+5f91aD5peYZjCGagCyqvlY6fY3uE2d9LrWowldPcAtg0T/WfyRPAM5EAnyTrTHNymq17eYXfObgKVtaaVkBHjpZ73UJXpRP2QMlh3XQc/uHD83PFJNiyueSlSW3h8qpbRdgNcK0AJvUlJU4AyAJUPgRFQVyTpAywJSHpTNc7YagO1TdF1Z8+3Oy8GbVhEn1I9zMr9PkIhYvoXQslW968YoZeP57HZ/GIpH5Kkhp3reFZ6iaK7Aznvs+15isQLRoMU2cDf25rNuK85zZjUsaf5GYayFLsHK6RbEdXBCRewTH9p3KyxMGmZkqiFkYEgzGY638Z6wFsrRNlUrzCvbhl25cwvRDHv3YIdwnbYQMNap9diSOeBi37JfJlfL8y+cjsT30nUxG6hWqw== 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)(54906003)(1076003)(5660300002)(2616005)(8676002)(86362001)(316002)(110136005)(508600001)(36756003)(7636003)(8936002)(36860700001)(82310400003)(6636002)(426003)(6666004)(336012)(70206006)(70586007)(356005)(26005)(186003)(4326008)(47076005)(83380400001)(7696005)(107886003)(2906002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 08:31:51.9865 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f7ba1389-37bd-4281-9bf2-08d996c8bad0 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: BN8PR12MB3508 Precedence: bulk List-ID: X-Mailing-List: kvm@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 Sun Oct 24 08:30:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12580079 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 D7F8AC433F5 for ; Sun, 24 Oct 2021 08:32:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C29BF60E9B for ; Sun, 24 Oct 2021 08:32:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229868AbhJXIe0 (ORCPT ); Sun, 24 Oct 2021 04:34:26 -0400 Received: from mail-dm6nam08on2084.outbound.protection.outlook.com ([40.107.102.84]:30337 "EHLO NAM04-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231708AbhJXIeR (ORCPT ); Sun, 24 Oct 2021 04:34:17 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B90N/aIlizrjj1zUB6nzK5Iw1Sxy1RmHs2FZiE8scQiFhCJG7hAh8fEhkWH4bbcuraQ/staD5idW07RfLQD7TkEPrhbfBhPJtK0Oy5VMNBIt5hmFE+GRgSQWUShbZ8c+KonQdbObla5z+X1rZx/A1uaYsSB8d+5najsOYwiEpaff1Htx8tougdi9nKXrR5OKlf4AyF/YbwnvOm4+q6qOQR9OtsAwyUl5hUw5GncO9rfoxwIc/gwOoOF1YsDklJXQQdVDgR3cNvPWkR3cV6oeoUDg58osGx/aBKOvPAVx4tGYZymKd6Lu/QvBS0w6nJjS0J0ttV1K5LMfhxZ3ChHv8g== 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=6JQIq0W3l53X1SP4Yfz2n4wvIoj4KiKObvdNUB8PnJI=; b=hjy+wjL6C54kDBUG6+MR2zZ8Y5gFBtZL/B6/ey9LWi0bA5qsBMqk2/O0NCQfskYYNYsD7KHfunzpVRElvqrfEh5+aMpJBPuf8WtqA3OHp6FuKRVwAQVNdZhUywN/caD1pM5K7Q/VyqiRp5VwO4r2EFMiE+xIIhm1gaR/ElVMnMtIjvI2lFtt99o9gJGp1PKimrdFFm6fsY8HTbQTfpaYPlC9/06CGOtj74qgeI70Dxrnr1VsPsY61qMEpxlcOL2RBQ2i3meIqmeOI9Ng7FlGCTqOXgQn/YbcYoSt0/N0WuyuEJh17kmvwazk0hp/fhLofXYYrfAoGbg7JqElJuyQYw== 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=6JQIq0W3l53X1SP4Yfz2n4wvIoj4KiKObvdNUB8PnJI=; b=YvVD8TGHHgv5xPbaSXNkKMCxHkJEq5hAfEjt9OsB9TLfDOkv8WDgb3QP6ndfSMRsyg+h0An6YYnMf1+mgTuKWjBBSjSa74ud3AVVxA2dq5GAescMYGM0mVdumP6sLM18leDfmjbqHFevTRZuJabA95OIFXPmq+toAZvNo82LkpDbKrjpls+8oz5e7wQPUkpoiIyKRXpr/2NqOVn1wKcV68O+aWOvJy4cNXS9ljgdvQr5FHEJfhJdyz3o132a+K7USFFPN1k7uUzBq/tAr+Y4leJjki5ef/eJi5ArrC7bbWg1CIOB3s2ubCi35M4skdOIJnZgV+ct++LHR0IpTDj0GA== Received: from BN6PR1101CA0007.namprd11.prod.outlook.com (2603:10b6:405:4a::17) by MWHPR1201MB2479.namprd12.prod.outlook.com (2603:10b6:300:df::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 08:31:54 +0000 Received: from BN8NAM11FT022.eop-nam11.prod.protection.outlook.com (2603:10b6:405:4a:cafe::41) by BN6PR1101CA0007.outlook.office365.com (2603:10b6:405:4a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sun, 24 Oct 2021 08:31:54 +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 BN8NAM11FT022.mail.protection.outlook.com (10.13.176.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4628.16 via Frontend Transport; Sun, 24 Oct 2021 08:31:54 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 24 Oct 2021 08:31:53 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sun, 24 Oct 2021 01:31:50 -0700 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V3 mlx5-next 06/13] vfio: Fix VFIO_DEVICE_STATE_SET_ERROR macro Date: Sun, 24 Oct 2021 11:30:12 +0300 Message-ID: <20211024083019.232813-7-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211024083019.232813-1-yishaih@nvidia.com> References: <20211024083019.232813-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e1004236-4214-499b-fc1c-08d996c8bc1a X-MS-TrafficTypeDiagnostic: MWHPR1201MB2479: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2657; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EEdPjkFrd2y/79Dwsm7Kwykqva/TxKDuaw02z0MvaaRHyF/TqbzLrxML2UxYg0vw0DyiCrsn7f1O4+aoVD9K5cvW19FBxvuKwb7TCmnaBKgctLENstV0B75Y4+cpjaatQwkrBER5olkBsXjEcY3O0rd94aBPS6wPfEnH25pZ/D7WrX01QUmub23IOxJq+bKKBXnY5QNiB6ky+KfFrpIplNJKh9p2YMuUzQtt12l4uCDVN3hLJ/+gJT8fRpZEwIqVa8IflRkFs4My2hG9Ahx/VWvZSwLVld5BOLx4llxyYkfnNQdEPPKiUCkIZz049kZSfDSIa3QXu12b97lE2ZLBVZCZtYnV4So/Jg4UrHQVXWW9cXAZu4KkphB+ur7MszU17OKWZdOE2wdW9wYpv/65q/ruOrRQT2ouT/5av5+REAPjgyHsTOv+ZIAMjysmSLReMs4/tdLYhGkxL/xOcgfX5vuuwBjusFDVMBcnlx2UDTC9fiwMiXcNv2TtWCc6qAjP6QydJeLfHBiLlPw2lf9TRyalsaB0szh0uP7rzdcjK7hO3uB6Gzx8MNYM+kCFVPOjFMpEVQwNnf33Hfk3AWRTOFks6GS+SK6Sxr/HjdDmDo6leiSsxWbLUzplewCDWKwzbdsRdDAAxwAG+UkPydbdjWaMHNOJ5HUWL0q9lzkynO/MmieMX0Kc2Uji5Cxe6r2EjT0wWN9DIhggtotfz0vwCg== 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)(2906002)(508600001)(110136005)(83380400001)(4744005)(2616005)(4326008)(47076005)(7636003)(1076003)(6636002)(26005)(86362001)(186003)(316002)(107886003)(426003)(70586007)(336012)(82310400003)(6666004)(356005)(36756003)(70206006)(5660300002)(8936002)(54906003)(36860700001)(7696005)(8676002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 08:31:54.1407 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e1004236-4214-499b-fc1c-08d996c8bc1a 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: BN8NAM11FT022.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB2479 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Fixed the non-compiled macro VFIO_DEVICE_STATE_SET_ERROR (i.e. SATE instead of STATE). Fixes: a8a24f3f6e38 ("vfio: UAPI for migration interface for device state") Signed-off-by: Yishai Hadas Signed-off-by: Leon Romanovsky --- include/uapi/linux/vfio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index ef33ea002b0b..114ffcefe437 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -622,7 +622,7 @@ struct vfio_device_migration_info { VFIO_DEVICE_STATE_RESUMING)) #define VFIO_DEVICE_STATE_SET_ERROR(state) \ - ((state & ~VFIO_DEVICE_STATE_MASK) | VFIO_DEVICE_SATE_SAVING | \ + ((state & ~VFIO_DEVICE_STATE_MASK) | VFIO_DEVICE_STATE_SAVING | \ VFIO_DEVICE_STATE_RESUMING) __u32 reserved; From patchwork Sun Oct 24 08:30:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12580081 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 459BDC433EF for ; Sun, 24 Oct 2021 08:32:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 323F760EFE for ; Sun, 24 Oct 2021 08:32:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231765AbhJXIe1 (ORCPT ); Sun, 24 Oct 2021 04:34:27 -0400 Received: from mail-mw2nam10on2051.outbound.protection.outlook.com ([40.107.94.51]:46081 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231822AbhJXIeT (ORCPT ); Sun, 24 Oct 2021 04:34:19 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FRWJ/G1lKPEungoe9IuTpRvnc5xn04QEob+bT0vezV08q8qUxhXNqxDRcUTIZg4WtH634hXAeiIhC3NorvPJk2jSLNJK5nrv1iaUnOOQxULq9M8LiZI/2JQE6HmXtShuZOzyt1vn/IJFUcZJtDylVycMdNMZ8adrwvPuSiHUiEubEcEQvCsN+4OZekSbAKeYm9I6ryhVzuTNn9c/Hg55OlEz+7hWrhd84AOckMl5ko7njgbIjj8a9hK666o8YOZLzxjrhc1b5ST3MdJsPotyFBwP511ykHQOuJxEviwoA9DIKcGXaCC4fpIDgTJRtUJQ/wEj2MGcHZhUHaEvgQvQQA== 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=A6cqDSd3/TvsRnCwVTJ73QVeAyquuhOTjwxlfWJx72Y=; b=lPx0xuc6P15uUIungHGjezCT0Y8zxpmEQ5n/k5vEWcFf3iwNjEvGkQeYWrMg5bXYnOG2kgbOWLA+iDH8kzNE1fCLU6qq9INpGSftuHyFLd6zWSUKmU6OsvsAT+2N3xBRRRZM1AO7MDKGsNe7/GR8SDm+nJsK8/r4BrXG87X9AYZKcIM6d6fvPwn8BHIPzOJlTjpsuvgHJXaxFaUqBMVQCe/AbrUxVNQl+xWk6bwCC3cM3KbCbm8wkgrPglY8a3PL+7NXFv1ScOYPPK1ryeVV9PsTPH8oYBqi8wGiqUlKHIfCDpz+h/9X1uF325dctLEJHkobsTCUqz8pq3myBVhLwQ== 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=A6cqDSd3/TvsRnCwVTJ73QVeAyquuhOTjwxlfWJx72Y=; b=OBv7pIeamJ1NRo95/vKBefTPurN/+OqMCEtEfhlogp7f8Y0D4kiH7Tez4BQQXDxaHJHt4mpckuJ+SYdqgDXtx7d+wS2EhctkNnSrHoj8Y6koElncT+A5QfMUPtVo43kbV1hW4yMYHh/lz0U6OUxrUBhTEwCI3WAaI70JFZfcV7/a3ifBl8aKOKT50zqjBhT7EAGB4ONyO+zEPkBvg45JlP5fSQTNhQgpr+CTpb7RAu1+mFILRmfC253l2ga/RozxxK8elahq+RlXkdXy2Gw9RmmRALwIwLoidxC8Kfdw04ou0HT/447r/0bu1prEwFBWTFWJsirJfoAMlipbd48W1A== Received: from BN6PR13CA0069.namprd13.prod.outlook.com (2603:10b6:404:11::31) by MN2PR12MB4335.namprd12.prod.outlook.com (2603:10b6:208:1d4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 08:31:57 +0000 Received: from BN8NAM11FT034.eop-nam11.prod.protection.outlook.com (2603:10b6:404:11:cafe::4a) by BN6PR13CA0069.outlook.office365.com (2603:10b6:404:11::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.11 via Frontend Transport; Sun, 24 Oct 2021 08:31:57 +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 BN8NAM11FT034.mail.protection.outlook.com (10.13.176.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4628.16 via Frontend Transport; Sun, 24 Oct 2021 08:31:57 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 24 Oct 2021 08:31:57 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sun, 24 Oct 2021 01:31:54 -0700 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V3 mlx5-next 07/13] vfio: Add a macro for VFIO_DEVICE_STATE_ERROR Date: Sun, 24 Oct 2021 11:30:13 +0300 Message-ID: <20211024083019.232813-8-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211024083019.232813-1-yishaih@nvidia.com> References: <20211024083019.232813-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4462a0d3-6a70-4642-170a-08d996c8be29 X-MS-TrafficTypeDiagnostic: MN2PR12MB4335: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2449; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Sz6ePiissbXHTme8xHdrme7uL7lChNUbZdoIaxCeAaC/9z/DuLJRhDr/K0zOoq+zJNtqGKJHgkg8OccvMwHoWDR1M7b9at8vh15IKqc11oRgcaqQhKmPyZHXfgdF3Wy0rduuNOetJWsEccKf0QE0YGibYqd17LVaDt9gAdk7FYrMFXicVAdEKVfZBDpNXdbbQ0FgqYRrNB0rqYaSJrhFTNqH/UnDKXNBm8xgwOt2T1ve1Ymy3CRMCKHO++tl/4KBRsQR61NLvfXKDZCyH6H9rUXgnv+db+/5TXPOUC7KK0tg5oGmv1zZ95t0eXMedemT7Z7LDUyIZrk0pq9CS8hZ5rs4Nj3wmoLkFv08FaHkAa+CHRMiYbg+hMx6g0MWM1QM/jGmR0ZKOodalOuMB7npbCBW/Pv/cHE0XHxWthaefa2xIu533WlFIOzFdufYskn7wOxdKcn7v7EydO6NobSmktU3UTb5CXeecGX07bpVVgnIKHTpcdGNQzo3PJh6spV9KCb7jgVoaTw72RuBcmU1oAX3jMOxp4MoFedvmL/GDNpt10XzvCnBli7dFia7jT9y0xt+7JD+XJ0Evf+aCiBEvIZfZR++TmscCJe0o8mExrXOdFvyCXh7BH8fXeEMW6xdL+x8nCCm89Meb9XIQyG25uRqEgck8ukZLxJIyjI5qi6Gi8FGWR9wYJZDJ+AtUzOZmVrTNgualzaevyH6PGP8Dw== 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)(46966006)(36840700001)(336012)(426003)(7696005)(36756003)(26005)(2616005)(186003)(47076005)(54906003)(83380400001)(6666004)(316002)(8936002)(8676002)(4326008)(110136005)(82310400003)(1076003)(36906005)(5660300002)(6636002)(70206006)(70586007)(2906002)(36860700001)(107886003)(7636003)(86362001)(508600001)(356005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 08:31:57.5826 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4462a0d3-6a70-4642-170a-08d996c8be29 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: BN8NAM11FT034.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4335 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add a macro for VFIO_DEVICE_STATE_ERROR to be used to set/check an error state. In addition, update existing macros that include _SAVING | _RESUMING to use it. Signed-off-by: Yishai Hadas --- include/uapi/linux/vfio.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 114ffcefe437..63ab0b9abd94 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -609,6 +609,8 @@ 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_ERROR (VFIO_DEVICE_STATE_SAVING | \ + VFIO_DEVICE_STATE_RESUMING) #define VFIO_DEVICE_STATE_MASK (VFIO_DEVICE_STATE_RUNNING | \ VFIO_DEVICE_STATE_SAVING | \ VFIO_DEVICE_STATE_RESUMING) @@ -618,12 +620,10 @@ struct vfio_device_migration_info { (state & VFIO_DEVICE_STATE_MASK) == VFIO_DEVICE_STATE_RESUMING : 1) #define VFIO_DEVICE_STATE_IS_ERROR(state) \ - ((state & VFIO_DEVICE_STATE_MASK) == (VFIO_DEVICE_STATE_SAVING | \ - VFIO_DEVICE_STATE_RESUMING)) + ((state & VFIO_DEVICE_STATE_MASK) == (VFIO_DEVICE_STATE_ERROR)) #define VFIO_DEVICE_STATE_SET_ERROR(state) \ - ((state & ~VFIO_DEVICE_STATE_MASK) | VFIO_DEVICE_STATE_SAVING | \ - VFIO_DEVICE_STATE_RESUMING) + ((state & ~VFIO_DEVICE_STATE_MASK) | VFIO_DEVICE_STATE_ERROR) __u32 reserved; __u64 pending_bytes; From patchwork Sun Oct 24 08:30:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12580083 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 D3F13C433F5 for ; Sun, 24 Oct 2021 08:32:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD14E60E9B for ; Sun, 24 Oct 2021 08:32:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231869AbhJXIed (ORCPT ); Sun, 24 Oct 2021 04:34:33 -0400 Received: from mail-bn1nam07on2053.outbound.protection.outlook.com ([40.107.212.53]:14961 "EHLO NAM02-BN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231516AbhJXIeX (ORCPT ); Sun, 24 Oct 2021 04:34:23 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cndv4n24756nfbbXfNmRdmr5uZJ71ca3UXIGrcUJ90QO0mShkCHCCeLHzjvWOprF+4fTXhGLhVX02U9Amvkvu0Gm7sDLiph/OQC+hKoWK8QOaQEYdGaPnhvFlp4ywx2iK5F9Jt5U5WT2yAaznffi+Tml7EsV4Q7tFra5dEFunl8bMK4qhCmFJdda5c5wsF4FmgkiaDMtwVl6wLQgYTx5oPUCBEg0I1breS3UZ3pfkqa2xJCZ1VFmWGYHw8HvvfRSiBoktlItXKPE4i07revZ4OR1vic7KS4brzoqQ+yb/W+QoKsn9igBPdnzh+RAObM/YBX/OoLjhaj+hifaC7vgYw== 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=MuxNrPNXKipW6LOpRWkhJG9B6OZtU+OWWOPUiQ9Qg+Pec5ZzUsWTR79GAwpMo+dHQSzfzzteZmS9bdhAlOldFLeKBnmIutP69tc8jJC2WfCnAs7L/yS/q+HgbIvA51n59bNpXa38r/JNOqN9+XFRovF3+EPrt3APWNph6eHtVuJPD9ZTDzVc4sW3uJFl62MOAAcIrIya2n8UYpZZDNrxLq+SIMtp/JIoV4SuTMUOAJRCnKzlSgMVIiQ0WoSRDX1+uKGPyvtyb3cTDp1O0NCX361LIa8qpjdrIN4VrfLUZ+WFptkjn8SFW78rsKfDXDETfqu5YUpGCpHAVItnw9/4Ng== 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=DOcFU6eSD++XS6aHs3kXEvGIdsHFeir924wVdQSptkg=; b=hijrW330gNnKgG+Uwm1VoOOk2B2zg9t0bDCTXLpnnYJA9ahXgaSKp6pi2i/MtaCfZwo1TcScpV0Ic5bCRtMsTouZXZPifJrR0vAqD/Mb55alP3c3G4cN/AqOrQeEjdYHw/BCxdYtgWxF85vz8NgijWHcrYOlC6XJK85ZUx2mrIJu434ZZzgVzP/nphW58cUWj40XoDlBIOZvTmd6Ke1DyRQut6xHdatsTojlB5oBHlp8ihhBjj0A5paAZwyqoGBORJRYR1suxvfB99a8uKqJrV02PIJyyiYW014Urr8iW9/acg5oTfPgqOtBs462OskvqgbVQis9uj78dSG64SK69w== Received: from BN6PR13CA0050.namprd13.prod.outlook.com (2603:10b6:404:11::12) by BYAPR12MB3238.namprd12.prod.outlook.com (2603:10b6:a03:13b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 08:32:01 +0000 Received: from BN8NAM11FT034.eop-nam11.prod.protection.outlook.com (2603:10b6:404:11:cafe::94) by BN6PR13CA0050.outlook.office365.com (2603:10b6:404:11::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.11 via Frontend Transport; Sun, 24 Oct 2021 08:32:01 +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 BN8NAM11FT034.mail.protection.outlook.com (10.13.176.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4628.16 via Frontend Transport; Sun, 24 Oct 2021 08:32:00 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 24 Oct 2021 08:32:00 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sun, 24 Oct 2021 01:31:57 -0700 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V3 mlx5-next 08/13] vfio/pci_core: Make the region->release() function optional Date: Sun, 24 Oct 2021 11:30:14 +0300 Message-ID: <20211024083019.232813-9-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211024083019.232813-1-yishaih@nvidia.com> References: <20211024083019.232813-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8347b64f-bbff-4041-b9f6-08d996c8c016 X-MS-TrafficTypeDiagnostic: BYAPR12MB3238: 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: P/Xdb6PUX1Ak9YpCxJkJ6qSjh5RClaS/5suwObg4HBRRx/xkG8atEPBXVrt5UCbj2JbZJtjnSOxtiFxhAuxqpQQWi5Bf+XUjjHSD/CFLocoR8cQIDgSsYa9zxCI+f/iX1gG3PnzZsc6YmHDN4k45GkdLqD1uald82ZAY3Y6089hf1hMOAHI/2kLUv8sSBsxIr7jSO48NYGz1nzOoZmMxSOLGqZBe0hpN8Db4SsouFLycMNUBNJoaDtxiVHNQ5Yr0R+5idGCAlu8Vni9QMWeRBdL3K4ItEg+pUJUx6byG9mozjXrmNoKBNsYK1WLjoYyu+uSguXa1cDCySlddYfoQ9ZpNM8zI/C1RrjEXe3oQL5C0pGNUIboHpwSw8ddiFy7uMUgH4VwJNECUt7lyeoOH8TEADvIqdN6a80MzBEBA2xZ7jDPybjWM/aVwUpzco3K+SY1Cy0/TJfJhwcqGT7SSYjMyS+oPr7PNvfJW8bHU8ocieft2xjlwH3nLoYl/ldTmRHY81ExNynegW+zap1n8XcvNGyEwBDJ9NI6OxnB4OWyPSbInvFK3Pkn7IP4E1QbA3nVN2pqB8ZpGYs4S9/uYgcEHC0Q0Ylo3NHvt8QKlaJiQwsd5cLkO0FlJx8SACX/rPDer/71A04yx6Xip2AUVI2/wP/szaP2oMUAkmb5wBnRJTUKhbVVGY8RHpxHgYlXDQV/Uu8MATRp3C1zV1rz5YQ== 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)(5660300002)(36906005)(8936002)(316002)(4326008)(6636002)(7696005)(6666004)(26005)(47076005)(8676002)(70206006)(54906003)(36860700001)(508600001)(83380400001)(356005)(2616005)(7636003)(70586007)(110136005)(107886003)(1076003)(186003)(36756003)(82310400003)(426003)(2906002)(86362001)(336012);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 08:32:00.8157 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8347b64f-bbff-4041-b9f6-08d996c8c016 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: BN8NAM11FT034.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3238 Precedence: bulk List-ID: X-Mailing-List: kvm@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 Sun Oct 24 08:30:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12580085 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 31F3EC433F5 for ; Sun, 24 Oct 2021 08:32:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D09860F11 for ; Sun, 24 Oct 2021 08:32:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231883AbhJXIel (ORCPT ); Sun, 24 Oct 2021 04:34:41 -0400 Received: from mail-bn7nam10on2055.outbound.protection.outlook.com ([40.107.92.55]:16033 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231564AbhJXIe3 (ORCPT ); Sun, 24 Oct 2021 04:34:29 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CQEf6VXwKqQMWVzLn+xL/7ItWMhTxmvTcYkzISxF24OCWl+YPnIPRboqNrA6dpPoqqpqLl1+MCyxvRwmB9ZcykVvtJtW/zyi2Va0Dbfk7AjnEjudmDSzsU08jI/WxR6Yp4LHVZOaVyG1w1FIvXZTpyiNY6T91ITL08EpwQL/UydxPoiJsLVIdX7f2QEXP52US7vSye/wcPMKEzOGBJFAWCiuoJ7SU9V3Vim/43wwC3LDqIEcqJH/E1p9xQ8wHiezsohvo1vvu2bKo0inutkYFRnCiUvArJYvN+5id02W0HrExIA2RUVj7TCHpfABLhe4gpivrKPgiYcpBDjGl7TaTA== 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=8EiLFCfX1BIiCoBhJcg49k8D+4oAajiiGkB0J2YJXL4=; b=d1REDX5ba2JZjKVCM8VkohJC4RiOTTBN9GhAcvWnw8OFklH9PlNKJ3khqtQ4+4BUB3gomXKwt2wEevmiRXRIMFMo2cY0GVrej0GBxfdbv/kFc23osVz+Unu0ZRm27RjOAuamjMPH2cjkp1oH0RgPybU36bInI4dhMjoQ0vayiGlIt99UOdBOW0GOjdmQsdPqE8w88FiLzvrTkUGQwvBN39EzX02+kkCtDmjyyseAMzNw3//soydj3vTYEKLwzIyY6JsxmYrftl9qLi9furN9pS/eWLCK00uxrCNvpGzW2W0y3rm8AGI9ChZ2KH80P0X6iEp1aYm8HFaqt+muVq+VPQ== 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=8EiLFCfX1BIiCoBhJcg49k8D+4oAajiiGkB0J2YJXL4=; b=PNGVfSRxOJ4gBHDBbDM3I+HSThi2Ulx77drVSfCevSZJGUkAXiJIpREpURx09P9siRJ7y9ul9N3AtJZhEqSxxWNUoFHUKfGFy+xgxzfHz31ZLoBCfRMz7jU0Llx0BUVWoh39jr5XG1M6nixeSIwXqUB/kyjMlIzpywrksV5OJnJKFSdR7V5kuM276JPTgC7n8UTHicxWRqTqKeSh34ADhhvfImJTkLi7gJXakok47MmPUQD6q1lhUv6YSGzjc/H27PIbI69lxkE2EgjNlPwW+l/jiyJBe4VrjP6V2ZVHaoSDSz4HlPQMEbUeSm4HUwRFZna4wmXEXmqkyX0riZVDeQ== Received: from BN6PR13CA0068.namprd13.prod.outlook.com (2603:10b6:404:11::30) by CH2PR12MB4874.namprd12.prod.outlook.com (2603:10b6:610:64::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 08:32:07 +0000 Received: from BN8NAM11FT034.eop-nam11.prod.protection.outlook.com (2603:10b6:404:11:cafe::f9) by BN6PR13CA0068.outlook.office365.com (2603:10b6:404:11::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.11 via Frontend Transport; Sun, 24 Oct 2021 08:32:07 +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 BN8NAM11FT034.mail.protection.outlook.com (10.13.176.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4628.16 via Frontend Transport; Sun, 24 Oct 2021 08:32:05 +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; Sun, 24 Oct 2021 08:32:04 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 24 Oct 2021 08:32:03 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sun, 24 Oct 2021 01:32:00 -0700 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V3 mlx5-next 09/13] net/mlx5: Introduce migration bits and structures Date: Sun, 24 Oct 2021 11:30:15 +0300 Message-ID: <20211024083019.232813-10-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211024083019.232813-1-yishaih@nvidia.com> References: <20211024083019.232813-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6c1084cf-86f8-40ef-d8f7-08d996c8c3b4 X-MS-TrafficTypeDiagnostic: CH2PR12MB4874: 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: 9ueb5+Dx5Nf4FWi88inkmpH7YQmb2IDv0dAM2ciM8U570qLio5Qq26qD0sVzPqdVkxed9d3gLSQqNOojOws4u9pif/09Cau06Y4TWV9WwQ5R0NHXQE+g41MG6aZEriNmZ2SkMaMwnX2tMmtlf992Wn8PkmCQUCYJMi+GV+HA6tVI/htuaWyaTWPl6KyDEn37W790qVVnUBLvaj88fQc4SBmAFKxDLAsEpn3Ygpul6QYFiaXSVtcpKytxI7dU6X27w8K+WE86JZSXy/RXRLb/zdc2AOgl2ABj9Bi5nbRAJRQNOj2mm48X7p8vKqp0PaP8PnXciVBVfxfMKK4Jw4e5+wzmuwu5+I9V0gIne5DCgutrMiB//nigHWn79Khy5gpedunqOXwxM+R3wsN9R2JDF9hCepUCFDdBI1kDKY/jiOIMiSPDiaev77st4RW6ngBIp4guz7BUgkr9fiwY2NOqMb93Ixsh3Kwes0TfJ2cHruTYDWH76BCELU6GKpO04kORd4fWOdVwHNrQdCbqTnDBkT+6GYMD122hAst8xVIXfq6FIF6bl61r6CA8Kf/A3Qj2rwkBRFn5AZD7Kj+2xqM99JfiRllub4EuU4c7tOo4KTlzy1/tDNxmOd4pKhNmCJlep6Qo2Gp+pgTsBd3zNDu8453UTji/R1aXu/EWdsI4VDH49rfPg4dwzaC0frFe/EkfXyjha0kjI7o9AzO/cq5S+w== 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)(508600001)(6666004)(6636002)(356005)(4326008)(54906003)(186003)(70586007)(26005)(8936002)(8676002)(70206006)(36756003)(36906005)(82310400003)(110136005)(316002)(2906002)(5660300002)(336012)(2616005)(36860700001)(86362001)(1076003)(7696005)(47076005)(426003)(107886003)(7636003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 08:32:05.0412 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6c1084cf-86f8-40ef-d8f7-08d996c8c3b4 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: BN8NAM11FT034.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4874 Precedence: bulk List-ID: X-Mailing-List: kvm@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 | 147 +++++++++++++++++++++++++++++++++- 1 file changed, 146 insertions(+), 1 deletion(-) diff --git a/include/linux/mlx5/mlx5_ifc.h b/include/linux/mlx5/mlx5_ifc.h index 864fc6b99b44..fe5566bb00b1 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]; @@ -11152,4 +11159,142 @@ 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 actual_image_size[0x20]; + + u8 reserved_at_60[0x20]; +}; + +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 Sun Oct 24 08:30:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12580087 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 6BED1C43219 for ; Sun, 24 Oct 2021 08:32:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5409860F0F for ; Sun, 24 Oct 2021 08:32:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231929AbhJXIem (ORCPT ); Sun, 24 Oct 2021 04:34:42 -0400 Received: from mail-co1nam11on2077.outbound.protection.outlook.com ([40.107.220.77]:34144 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231844AbhJXIed (ORCPT ); Sun, 24 Oct 2021 04:34:33 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BJxgEQmN91tJJTv+88SJ2K/k+BT5fCqf+DLs1cPiCV2wwTV6yRo1TqKuLhvqtWcRY9dHSKDV5dlQJ7VR1mPoFiFOpOBM09yfNUvjIaBRMp1nTylyWrLtfG6FaQ/b+u0uYN76/GC3ukIenVqL9Ws+SORjg5ged7yx9C8FfBI2HKIxnxtxJbN4qBBjHMflLu/Eeeb24LeFDf0WBk4SGd39/4Jp9aV98KVXMC2FyF95rZCEGkGQ0rx/jHdtd6Y1lY5ZXaGn8CptirigcNAeoPenlvvdoYiyrAw46M4s8/qckNdwpxSRGuDzXzvnPsKLSjinNTsULQtXKYx4odXeLuTWYA== 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=ZtEgqlk1th+fPXALjztdnvZiUAZroeuNvQQNlDHqroA=; b=jZIottsKNSbDy5oNgGdnRtwmT4kcYpZmICdm01SnMo5ZA5mbOq5aJXdJoq8j7kIs2ALb2CJ0WEcAWD+P1uSv/P8D54pC2XtG03YzmPazacHA7Z+YVJydSPM3VGOzfanmAsiI3KYOnoWIKjV3OWII0zp8Hr4xIyxAPc4foquo76M5dj8Ju22SpkxdVFIHDKD892p8ah9v1aG8NL+p0JBHQTdnaZQfYGAjUo1GvZhHOqyJ0SxVt+7d+2xw+wIp9xG+MmxFN2xyP/WujJOLePQwiLjy+Uum+JUCNV1Cxe2puYQtPpc04kdr0v2qNc70nt/8wqjvg6nT9C+YtNvaYhkCtw== 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=ZtEgqlk1th+fPXALjztdnvZiUAZroeuNvQQNlDHqroA=; b=aeFMqEoP5VstFbXJ2buRZMO00Jqis+F2r/5PhzjaoidRqk/Clu3iXIl8moUOdaTXSC6DDPh9Tz07dhMT23cpwo/KU6bRu4oNKcwALC1p1YiWnOf/Vb+HjATaFVB1AfrLZrDjseCanuywzkMny6NlepaWgyZZ/MICbw+llnMIdm+1SYD3CgwfwlNywEtGxv7OMpp/cQvN/H+XBxdkcIUuXEotgzHB0Luy1mBsSKLBwcUsKEIGDwJ8wKl5hRuaPPTaE+ZVWjOC1JBdSVyOZCPTQMqNZv3IMtNpkX2zKj35GOX19gLaxZD23fcZQBAUKR7fXDzjVwozq86/xgv7FOfLUQ== Received: from BN6PR19CA0106.namprd19.prod.outlook.com (2603:10b6:404:a0::20) by DM6PR12MB3322.namprd12.prod.outlook.com (2603:10b6:5:119::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16; Sun, 24 Oct 2021 08:32:10 +0000 Received: from BN8NAM11FT019.eop-nam11.prod.protection.outlook.com (2603:10b6:404:a0:cafe::84) by BN6PR19CA0106.outlook.office365.com (2603:10b6:404:a0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16 via Frontend Transport; Sun, 24 Oct 2021 08:32:10 +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 BN8NAM11FT019.mail.protection.outlook.com (10.13.176.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4628.16 via Frontend Transport; Sun, 24 Oct 2021 08:32:10 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 24 Oct 2021 08:32:07 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sun, 24 Oct 2021 01:32:03 -0700 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V3 mlx5-next 10/13] vfio/mlx5: Expose migration commands over mlx5 device Date: Sun, 24 Oct 2021 11:30:16 +0300 Message-ID: <20211024083019.232813-11-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211024083019.232813-1-yishaih@nvidia.com> References: <20211024083019.232813-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f9c4675c-c294-4c7b-6f13-08d996c8c5b9 X-MS-TrafficTypeDiagnostic: DM6PR12MB3322: 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: 7z1zjAF1RjclAT8uQpdeObKU+2SyBJ0K7Sbj7bTiS7kuhaXjizOs42kssML9TVSePi/ODSZDjgb+nufY+uwAFadFctKN+aNaDr4qi4loZYTV0GFu+Hrj51xbtzPqADF+0VoeNXcXRgAqfDBM73RAJ6gzElbG9LSuejIE8LflWjpHhA2/lfc6wk6iIj9VQDSwc6SCAoQ+a4dYoyOTANrLsSUU4Jy5m69zILALiSEfdPsCJD/jfvqNPM/X/oJ85MSKJqhDgu40E+H0Td0xEAuPZCTSc7ujEIF5Mp7SOoU7UbcbO1oDIKsmG0Eh8PIDPY9vZTuVnK6FDykRUeZVo02/kqnBcEfcCfdKJAbLCLCHAphahwdNCe05LDFn27CR5FUgKEEFNa0HmQ5AJrS/GJIF1utczSOEGY1hDFFuItxlGAnobN0R5J4VLwvpLyLJAY3zsc0kBgmu1kQdO9n9ND8cVOQl14X25jKJfsRFc0GwMRSNBM89IAH24PMNnb3/v8cC3ybP05P066dI4aUxl2Hhtv8mfjzWXovh6XTWrh2Dvs2i2NIvobucxjTp6I00SPiYKrx0sEEJtHYoryZngcnvuu3OBVmTLtkWnTe6+BR6eaQNV4xNVY2kU9s7wm8AgO33yFiV0YtEhsrOkBQGM3A9cPoz7SbH288LynudmZJt/5I51ySC+5U/efwg+QWDpFnYyJP/e8t/0+N/z1cddDpSvw== 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)(86362001)(4326008)(8676002)(26005)(30864003)(36756003)(2906002)(107886003)(426003)(7636003)(110136005)(8936002)(54906003)(186003)(6636002)(36906005)(82310400003)(336012)(316002)(1076003)(508600001)(5660300002)(47076005)(7696005)(36860700001)(83380400001)(2616005)(6666004)(70586007)(70206006)(356005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 08:32:10.2036 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f9c4675c-c294-4c7b-6f13-08d996c8c5b9 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: BN8NAM11FT019.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3322 Precedence: bulk List-ID: X-Mailing-List: kvm@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 | 354 ++++++++++++++++++++++++++++++++++++ drivers/vfio/pci/mlx5/cmd.h | 43 +++++ 2 files changed, 397 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..98ec320c8c57 --- /dev/null +++ b/drivers/vfio/pci/mlx5/cmd.c @@ -0,0 +1,354 @@ +// 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 = MLX5_GET(save_vhca_state_out, out, + actual_image_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 Sun Oct 24 08:30:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12580091 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 F14AFC433EF for ; Sun, 24 Oct 2021 08:32:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D86A760F11 for ; Sun, 24 Oct 2021 08:32:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231812AbhJXIeo (ORCPT ); Sun, 24 Oct 2021 04:34:44 -0400 Received: from mail-bn8nam12on2052.outbound.protection.outlook.com ([40.107.237.52]:62198 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231726AbhJXIef (ORCPT ); Sun, 24 Oct 2021 04:34:35 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cYwhSZwskxxJoQGxXM1ogF6AFzwpVczgsegv8b+uK2EbUT/0RJ4pdnN/NTqxKPz/4J675DsEcJGBP4jpdcoDTJPC2rwVQkUwiustfWaQAZ2kXHEyDVBw33YB9TH1bl5dBjc7ytffAc2la5l5AJzhkVK5FwP621Wg15TC5+5RVOc51t3hS7qTD9Sq/76BzS249A4zCGV3jnPFOi+glWG0QQ6EWzLVZ194qFmI9U1rvKTdWRLLFp7fp9mxFlyHjGut7cHKc1G3UyHR9PmeP+hsg6RIa4P1srk/NqsH6zjKhHS9DXwRjBvKcDROHVm9se+PmVgCxSpZxQ76LVs9x3KqbA== 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=XSPtgyu5UWGXwpy6/czK9zxXoTqLP8dCLxbtEBg9en8=; b=KHGtqWYL2o7r3UTXViu6tUEfdQk6Zrm6jOeZqq4V+n09FCdc0FU2xcxsM98Tv5FB8HLEjz5uZ/cFDdQYLbfWQ0MUA9II7u7BZ1B8GwgxjvSPMAhsLVp5h9bMTX8TL5slvbFZ7GoeijffV8qxm06sGgWjx1SIXUZvdadDES6i0X9DMphddEvQSU+/YlXWNfsPkeePm0Dc1RnLf7JsTnr1eQH1mWnu5x5t4iNQiwT0jUoRwiZwwQH/D4YucFxN1yY3UXQM+sFLwfE5R1DTxibiRMTE7aAnpEap5KEEbKEJa+i1pmkuHWrmQ5ICAuxm0xE9TcRFkBVkanHQUlfw3jKetw== 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=XSPtgyu5UWGXwpy6/czK9zxXoTqLP8dCLxbtEBg9en8=; b=dHq/xJgZRmPdfeWTiY/ZMiw2kTtpM4u739gTQ7vAdOw0vfpXRDIjP0N2IW6af9W2KXIxhxxVLpy5S2iUFNvreeYu42jb1HF+Vzfu5x5oozf24bjl4ezWNn8H3f6yengi6P5GGppsq7CoIQJ3mkabORR1xLKhYDftFIUEX9iB2JlM9FKR/lfas7y1utr7ydsONzmOk4QcvHEgzz1wufDsCY99A0s5hF3mDQtZ0JTQCR3ddVY7FYAN8EjmHDixOABewShFcXDR7Eg8i2eyVjMhdN4mNw0Yj18JLCA9hpnx/xMkH5Ne5L0U4QQMLVztHFvW9ngh1FEoaS0fIcP0bO0u3w== Received: from BN9PR03CA0300.namprd03.prod.outlook.com (2603:10b6:408:f5::35) by DM4PR12MB5392.namprd12.prod.outlook.com (2603:10b6:5:39a::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 08:32:12 +0000 Received: from BN8NAM11FT052.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f5:cafe::ff) by BN9PR03CA0300.outlook.office365.com (2603:10b6:408:f5::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sun, 24 Oct 2021 08:32:12 +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.4628.16 via Frontend Transport; Sun, 24 Oct 2021 08:32:11 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 24 Oct 2021 01:32:10 -0700 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sun, 24 Oct 2021 01:32:07 -0700 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V3 mlx5-next 11/13] vfio/mlx5: Implement vfio_pci driver for mlx5 devices Date: Sun, 24 Oct 2021 11:30:17 +0300 Message-ID: <20211024083019.232813-12-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211024083019.232813-1-yishaih@nvidia.com> References: <20211024083019.232813-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e0bacb42-fc8b-4a14-22bf-08d996c8c6cc X-MS-TrafficTypeDiagnostic: DM4PR12MB5392: 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: /5dW05yps77QLWJA0Hu+txf4JLjGK8dI/RU+PGz9i7va/BwrSgVb0pES6badS8uTusvGj0x5bJHqgIpwgnK7dKInQASAW2aCMP54vlc682qpfb9LN+sR1YgTbtXU1le3HET2NznyuF/x99fs214B+8R4vOqAJ2R2UKijOFoT0PIT/yLT9CtWwKFkhjFCzpkQZnzCUA21hAF8+d3bX6bykR4Q8gaIVrG38moBGhCPpKY0vV/jtM86V+4yzuK8xEUQqASXuDto+vC12WbmceOePqj4Lk48kfUdXCii4nVFnz1YIX3go8z5P6zph+s0702Db3KU8HspHZy3qZDArHdeV44AoFDSG2EOLu7AC1giRvGfk3fJcpQPohnFU7lQm/sclzYP+erT3PgTNY7sv1ASMK6SQVYusMiO5eWbuAn9Z5aymjKustkJsOIu/cyJso0bE5nQx0/2uUWIEcNJfSxIfrxi0UWtv7XcGHXUbzoKDRwGmOaw62xz9QJnWcVn4gw94kJ+FczZuKwQx7DTIj3OljJpw9Nh+VqSw4WkZQmFDf26ZHjEjrymxvobmO81TdNSTLXPOTiCgzvOc1Pb/RhGF4b+IzANo5mim0zTRzpOzHkeFK3ZCWqUtDfQmcAwTph3S+/DrMgq3uKZSExoZwpbqv/R7uyszQkNS67mXacyUDprcoJQAhMJVZpUIpElJCZdXosvyOBVOtpsF9SgHcENl20CoD2dkHZjNnCfykEBaiY= 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)(7636003)(2616005)(5660300002)(7696005)(426003)(508600001)(316002)(54906003)(26005)(6636002)(70206006)(2906002)(86362001)(70586007)(47076005)(36756003)(30864003)(8936002)(83380400001)(1076003)(356005)(8676002)(186003)(36860700001)(6666004)(107886003)(82310400003)(110136005)(4326008)(336012)(21314003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 08:32:11.3273 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e0bacb42-fc8b-4a14-22bf-08d996c8c6cc 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: DM4PR12MB5392 Precedence: bulk List-ID: X-Mailing-List: kvm@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 | 10 + drivers/vfio/pci/mlx5/Makefile | 4 + drivers/vfio/pci/mlx5/main.c | 696 +++++++++++++++++++++++++++++++++ 6 files changed, 721 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 8d118d7957d2..3689d452b0ed 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19703,6 +19703,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..7088edc4fb28 --- /dev/null +++ b/drivers/vfio/pci/mlx5/Kconfig @@ -0,0 +1,10 @@ +# 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 migration support for MLX5 devices using the VFIO + framework. + + 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..4b21b388dcc5 --- /dev/null +++ b/drivers/vfio/pci/mlx5/main.c @@ -0,0 +1,696 @@ +// 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, +}; + +enum { + MLX5VF_SUPPORTED_DEVICE_STATES = VFIO_DEVICE_STATE_RUNNING | + VFIO_DEVICE_STATE_SAVING | + VFIO_DEVICE_STATE_RESUMING, +}; + +#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 migration 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; + u32 flipped_bits = old_state ^ state; + int ret = 0; + + if (old_state == VFIO_DEVICE_STATE_ERROR || + !VFIO_DEVICE_STATE_VALID(state) || + (state & ~MLX5VF_SUPPORTED_DEVICE_STATES)) + return -EINVAL; + + /* Running switches off */ + if ((flipped_bits & VFIO_DEVICE_STATE_RUNNING) && + !(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_ERROR; + return ret; + } + } + + /* Saving switches on and not running */ + if ((flipped_bits & + (VFIO_DEVICE_STATE_RUNNING | VFIO_DEVICE_STATE_SAVING)) && + ((state & (VFIO_DEVICE_STATE_RUNNING | + VFIO_DEVICE_STATE_SAVING)) == VFIO_DEVICE_STATE_SAVING)) { + ret = mlx5vf_pci_save_device_data(mvdev); + if (ret) + return ret; + } + + /* Resuming switches on */ + if ((flipped_bits & 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; + } + + /* Resuming switches off */ + if ((flipped_bits & VFIO_DEVICE_STATE_RESUMING) && + !(state & VFIO_DEVICE_STATE_RESUMING)) { + /* deserialize state into the device */ + ret = mlx5vf_load_state(mvdev); + if (ret) { + vmig->vfio_dev_state = VFIO_DEVICE_STATE_ERROR; + return ret; + } + } + + /* Running switches on */ + if ((flipped_bits & 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_ERROR; + 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; + + 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; + mutex_init(&mvdev->state_mutex); + } + 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 Sun Oct 24 08:30:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12580089 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 3EA25C4332F for ; Sun, 24 Oct 2021 08:32:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2AFE860C4D for ; Sun, 24 Oct 2021 08:32:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231969AbhJXIep (ORCPT ); Sun, 24 Oct 2021 04:34:45 -0400 Received: from mail-dm6nam10on2053.outbound.protection.outlook.com ([40.107.93.53]:4608 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231792AbhJXIek (ORCPT ); Sun, 24 Oct 2021 04:34:40 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QZJy76FdgdN8xOf+X1P9p/9ABL30Ic4IYrfE3ZRo0vZ07BXuLnWqBphQVpSxExDIyrJgR+BCnO4Jjp3JrzOTbSlcINqF6v0+VgwaAs7kOv+/xmONyiiekt7bBpxQrIjZOni5AyPxTsZUPWacIufbc2jMiCzIrlomKWDRbi0NUJdJjfpKes0q13AJAtYNc9202vSn5bE+MwVerURMsX8i9wC0M5AU/1sJmWIQDvTYIBg5S//ksG3ET2U4EyoTE0En8A4tJV+7i0SAAm3T1js3h5Wqv/UPqZz5AnVSd2baFeQkO+V93//YMFC9jchnZP0z8SstW6ydm32zAVNcAQsLVA== 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=eLKFU+sGvBKXZ6cjTNa+FhQ1WxILKlXRvDl9qJoQPqQ=; b=X8NtKFJIoF2rtC/3XRfPitInisFdx9QT+Psyw38ecAEmzOw7vedhyvVYbL+VUeUgBURcf1VR279p3FT5FjIMv0XV61HhAyav6VVnc1ek1YX1dN8KcrLTJ83kgKl+jYiQRjgcM3xZmnR4aQcQYTHuh985oZ/AgqLRPgPvANaBfMzN0lK7TX1emndUn4FW2EyxbvlGNCmGRloHy/VVWkP7xffx0AjJsabvlZne7EN+4xii9yGAIkZ97hxWfX3p0ZLfzdqYVI0hQtDqF6gEB8OBkrarq/G5cmKS7Beyf3ocRNQESisWabBVfSKZUqWEdEkCcho5uTpqyPafhcVwnHhlGA== 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=eLKFU+sGvBKXZ6cjTNa+FhQ1WxILKlXRvDl9qJoQPqQ=; b=FOwHcbd8of2eMeOK1j9e2lPrQF3ermLe3uvH98vvcZkJsjAgBQACWko7+ZyXYw2egv035eOjxbpRdHVudYSqlUcJIDuMMaZ+Cdiprjqrj5Tsqv9TywjnRxn0T6ql7116XyK8u4UYkpqSRBycdxUkfjmEyPIydKLowFAvRVvkvj2NbtKQpgFIoinGSGCUkeYzfd87jqxRS5cS5mQ1G6MIqDvIAm7L5NIIOj7URm45mBBoN0kJliU85ZBE6TWP0AIWYqW7Ud8GcxwAAL7sDLeSOSaKSIcWtFWz7Aemz6x7zrvO55lYsAoIXrYJdEBwq47dFncsPxV5BKkB+8hynV4c+g== Received: from BN9PR03CA0287.namprd03.prod.outlook.com (2603:10b6:408:f5::22) by BY5PR12MB3955.namprd12.prod.outlook.com (2603:10b6:a03:1a2::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Sun, 24 Oct 2021 08:32:18 +0000 Received: from BN8NAM11FT052.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f5:cafe::73) by BN9PR03CA0287.outlook.office365.com (2603:10b6:408:f5::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.20 via Frontend Transport; Sun, 24 Oct 2021 08:32:17 +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.4628.16 via Frontend Transport; Sun, 24 Oct 2021 08:32:14 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 24 Oct 2021 01:32:13 -0700 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sun, 24 Oct 2021 01:32:10 -0700 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V3 mlx5-next 12/13] vfio/pci: Expose vfio_pci_aer_err_detected() Date: Sun, 24 Oct 2021 11:30:18 +0300 Message-ID: <20211024083019.232813-13-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211024083019.232813-1-yishaih@nvidia.com> References: <20211024083019.232813-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cc7a1c39-3a41-4f7f-4b50-08d996c8c867 X-MS-TrafficTypeDiagnostic: BY5PR12MB3955: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3968; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VG2qmww9Cmcx/vlQuKZdST+ofLCZCbf2qeZoNQ0iwRsuLk34lvKpi/vgLd2++nsAJVxyyWFfUKKfpyE7JV/eYakFTbzygkd8XOT9hJG5ek3nUHtLmyct2OxQ9wRlqpYn3YPInhWfohT4IKJN3Csu1b1cBKNQPLFZVVq65UfvVd+48a4g6r7J2NdIneo3Q46/vuDui0nHCrGiZp2/rAr7k7bNjAyUCXVnxTpdi+DFeHnShUhhS5oE+9F385JFyNs609McnEENAtwE7aklogXUPgATIvLob3hN5ekzzm+oT9/QRjd3XLzTWh1j881gfJRfLY5g9fpW5B4xF95Q1MV7dtLqoctqfScoY4TH/pxK4GaBfxC4gkQ7XOVr23ivkRe86BBKozzBCRrtrC1STZPkzU6aQ5gSWGr5r1kCnhyzLB4CFGLXs9CztJVONncK27EP4h1x6/EfjDm75LynmF3sp3RWHedLfkYf1nTXhFgGwfhSRfvg/Pvp7Nh2V+sJ1cBiGlKAwpCngm8ImOkZokKpiVbR1egWR1z/GS66ypXZW8xqV/4muw79LK9uOn2K2M/fwRZ6veA0+Goem6K2BWJsdjKDQgvba0z/6rqTPLPRfl81UWDREPZfOSayGeHU6jj2IpxhGpoGt0qfbbUk+hb7bnOAR3wwO191+RTivKoV8J3/u3VeCdgsa4FANiSOvC2tYC8lAr4WMVApZsWC/raNNA== 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)(7696005)(5660300002)(47076005)(86362001)(316002)(356005)(36860700001)(26005)(6636002)(36756003)(508600001)(186003)(83380400001)(107886003)(8936002)(54906003)(70206006)(70586007)(4326008)(8676002)(7636003)(1076003)(426003)(336012)(2906002)(2616005)(82310400003)(110136005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 08:32:14.7795 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cc7a1c39-3a41-4f7f-4b50-08d996c8c867 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: BY5PR12MB3955 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Expose vfio_pci_aer_err_detected() to be used by drivers as part of their pci_error_handlers structure. Next patch for mlx5 driver will use it. Signed-off-by: Yishai Hadas --- drivers/vfio/pci/vfio_pci_core.c | 5 +++-- include/linux/vfio_pci_core.h | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index e581a327f90d..0f4a50de913f 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -1901,8 +1901,8 @@ void vfio_pci_core_unregister_device(struct vfio_pci_core_device *vdev) } EXPORT_SYMBOL_GPL(vfio_pci_core_unregister_device); -static pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev, - pci_channel_state_t state) +pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev, + pci_channel_state_t state) { struct vfio_pci_core_device *vdev; struct vfio_device *device; @@ -1924,6 +1924,7 @@ static pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev, return PCI_ERS_RESULT_CAN_RECOVER; } +EXPORT_SYMBOL_GPL(vfio_pci_aer_err_detected); int vfio_pci_core_sriov_configure(struct pci_dev *pdev, int nr_virtfn) { diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h index ef9a44b6cf5d..768336b02fd6 100644 --- a/include/linux/vfio_pci_core.h +++ b/include/linux/vfio_pci_core.h @@ -230,6 +230,8 @@ int vfio_pci_core_match(struct vfio_device *core_vdev, char *buf); int vfio_pci_core_enable(struct vfio_pci_core_device *vdev); void vfio_pci_core_disable(struct vfio_pci_core_device *vdev); void vfio_pci_core_finish_enable(struct vfio_pci_core_device *vdev); +pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev, + pci_channel_state_t state); static inline bool vfio_pci_is_vga(struct pci_dev *pdev) { From patchwork Sun Oct 24 08:30:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 12580093 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 CF2F9C433F5 for ; Sun, 24 Oct 2021 08:32:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BCB8460C4D for ; Sun, 24 Oct 2021 08:32:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231994AbhJXIeq (ORCPT ); Sun, 24 Oct 2021 04:34:46 -0400 Received: from mail-bn8nam12on2064.outbound.protection.outlook.com ([40.107.237.64]:2241 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231837AbhJXIel (ORCPT ); Sun, 24 Oct 2021 04:34:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jbt6QkBRvvCDYkgJpYopV1OvRhZLVROVKJh5E5oau+koEFOOhLAHM0y8HEEeEeiHxANH7GAZdj2kRpJ0+L3QPvphvUtdAPGxgU0a3hbGr83WlWNeD/Ho2btYZ7aInveCGVjj+4zTDgVRK+F5MjITJscb/Z6j+Eoo2XIEAovp/AS+I34eEYz4IDm141gqgJQ2pADxIlIgvyTRYyvpUqjdiEgPRAH0VEwY9NOco+fLPlMDVaFJLnY8+F1oY1oAB8kIh8yApOtI4vyQWHN08+1ILt8riws3L+z9sCwrw4e15uEUdThtMIcAhICx06uLLIWEvsvxr8LIpFZjtHM/t9i/8Q== 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=u3KOUx0jSz7QZczP3nf+xaTthk7sMn9JiO4/y8JK+/4=; b=k66Qw8zgxNP8zCYUgmJtRauBcxUamKrzYcDz5k2Gcegx394tqU+iFmuU1pUPMySzmtJv8oalTck7Q6C8Db0rlaFFC/3dM58G3EHD1xt74EhyEE6CwZ6ZHJuCVVjP/WRU9I8KpDnXCquA1Wen8wZmnSBkgSA64hzR3pXuCW3Btqr0r7nvEX4JMsg3hGFB//vyWL16sMp/o+jJXgLVb87XiGgcAvX9wA4GvvZzFTioTE2bIhppyLX7UIVEJI1vMOjdQ+yB/DbFQ1xmnLzgnV6Ew54HBfrd7VWkOMaqIsFX/3vJxRlNyurDNo1suG4KBkte3X8Muy7d50G8BgNWQN1Ajw== 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=u3KOUx0jSz7QZczP3nf+xaTthk7sMn9JiO4/y8JK+/4=; b=uMmGfyb88Lxy/GPGPdMF/WwDZjGC32p9BsOE2WnveERg2sHbz2Bb3/x8Z4A/bjMKkAGsJdr0rMXdLU/8FATRXFimgWQ6fAheTByKNkZdStK2gcCJssj7zGL96XhMsmEC7f+9bumhnjTxcH//RTnxY5BwdhmIHc1nv9J5zNxyzk0KlFqe5CepTuK0C7FmzOdUoSpj2+m5HdmFHHyr42k7imC/3jiHSFPzyqe5XXzub8dG1U0g9R2qKIPtYvF7gDw3F2MU35St6ahwC4A8BF4/4pzAhG4Q1X+c8QeCWq9izoNM6DD51tgnbjFVgSzGta2r1PMnDmR6W8dXa7FNZ/owHA== Received: from BN9PR03CA0274.namprd03.prod.outlook.com (2603:10b6:408:f5::9) by SA0PR12MB4557.namprd12.prod.outlook.com (2603:10b6:806:9d::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sun, 24 Oct 2021 08:32:19 +0000 Received: from BN8NAM11FT052.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f5:cafe::2a) by BN9PR03CA0274.outlook.office365.com (2603:10b6:408:f5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sun, 24 Oct 2021 08:32:19 +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.4628.16 via Frontend Transport; Sun, 24 Oct 2021 08:32:18 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 24 Oct 2021 01:32:16 -0700 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sun, 24 Oct 2021 01:32:13 -0700 From: Yishai Hadas To: , , , CC: , , , , , , , , Subject: [PATCH V3 mlx5-next 13/13] vfio/mlx5: Use its own PCI reset_done error handler Date: Sun, 24 Oct 2021 11:30:19 +0300 Message-ID: <20211024083019.232813-14-yishaih@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20211024083019.232813-1-yishaih@nvidia.com> References: <20211024083019.232813-1-yishaih@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a42e7dc8-e167-4755-d7ad-08d996c8cadc X-MS-TrafficTypeDiagnostic: SA0PR12MB4557: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GQLOq7kvD7UzwGHgaReJB/QDL+y8JDN8OjF0Mvxwm4rz7MbgyLM2V+8lkTCs2ij00iL27BMr1ns7DeEeNERfvgkomfZOECdFgLZxr1D2ojTwmZE2M6JMNLm8WN9wcFSdBBcJ7/QAcgMMdp5HRjXJ3UknVoAJBRAVLCJ+ru58sTmOFKTHblaRZDe1WQAV3coBq2aopstbwF/TLTIgAFcWMqDtvQKdtkTTMaVyDGquBqcG6Ezolzzo4XcQd//q9IXnC/XcqmsYdrb5y3Q+GT71cXHf2Hd4qtcZjINmnTUwWQV5RXYRP3LrZEebDUnQbHvbwpRpfqBHxhsL9O5vxnprHIjGH1tzWaJRpgGQk7yspiOpDAT7fz59mOBCCZeeyRxxC5r9cay7MvYqKkCfiTLxrJT4n5O4QWiuVPgmTFD2J0x4TIJMUQsZUFUoP1VcU3zDWq3PyX1ImG0HYeLMiiqCfwbi70h5k+XOyU2MdHyiQiCHJR8RRL3qyxUu+bTIHKvejZL1E4J6EjoqBlmHFcc7X05hniLskB73/Jc4ZD0k6boCI9KWwmX+EuiGmJ5J4987AnpmNwvbVhTXKpaBqQRDO0GpSPDHyzaQb/XEnl5S3mAf9OQgLfON6MtBvznU1KlZQlTDr7FyHxNh+qnAVQwShY+odd2dGJo9sO2zQqaji/JEcjayVLPRaJnj9/ULdlgmgyC+ieIt8+awHbwhO7T2Sw== 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)(8936002)(36756003)(70586007)(47076005)(82310400003)(107886003)(336012)(110136005)(4326008)(1076003)(356005)(83380400001)(186003)(36860700001)(8676002)(508600001)(54906003)(316002)(2616005)(5660300002)(7636003)(7696005)(426003)(86362001)(2906002)(26005)(70206006)(6636002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2021 08:32:18.8403 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a42e7dc8-e167-4755-d7ad-08d996c8cadc 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: SA0PR12MB4557 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Register its own handler for pci_error_handlers.reset_done and update state accordingly. Signed-off-by: Yishai Hadas Signed-off-by: Leon Romanovsky --- drivers/vfio/pci/mlx5/main.c | 54 ++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/pci/mlx5/main.c b/drivers/vfio/pci/mlx5/main.c index 4b21b388dcc5..ca7e5692a7ff 100644 --- a/drivers/vfio/pci/mlx5/main.c +++ b/drivers/vfio/pci/mlx5/main.c @@ -55,8 +55,11 @@ struct mlx5vf_pci_migration_info { struct mlx5vf_pci_core_device { struct vfio_pci_core_device core_device; u8 migrate_cap:1; + u8 defered_reset:1; /* protect migration state */ struct mutex state_mutex; + /* protect the reset_done flow */ + spinlock_t reset_lock; struct mlx5vf_pci_migration_info vmig; }; @@ -471,6 +474,47 @@ mlx5vf_pci_migration_data_rw(struct mlx5vf_pci_core_device *mvdev, return count; } +/* This function is called in all state_mutex unlock cases to + * handle a 'defered_reset' if exists. + */ +static void mlx5vf_state_mutex_unlock(struct mlx5vf_pci_core_device *mvdev) +{ +again: + spin_lock(&mvdev->reset_lock); + if (mvdev->defered_reset) { + mvdev->defered_reset = false; + spin_unlock(&mvdev->reset_lock); + mlx5vf_reset_mig_state(mvdev); + mvdev->vmig.vfio_dev_state = VFIO_DEVICE_STATE_RUNNING; + goto again; + } + spin_unlock(&mvdev->reset_lock); + mutex_unlock(&mvdev->state_mutex); +} + +static void mlx5vf_pci_aer_reset_done(struct pci_dev *pdev) +{ + struct mlx5vf_pci_core_device *mvdev = dev_get_drvdata(&pdev->dev); + + if (!mvdev->migrate_cap) + return; + + /* As the higher VFIO layers are holding locks across reset and using + * those same locks with the mm_lock we need to prevent ABBA deadlock + * with the state_mutex and mm_lock. + * In case the state_mutex was taken alreday we differ the cleanup work + * to the unlock flow of the other running context. + */ + spin_lock(&mvdev->reset_lock); + mvdev->defered_reset = true; + if (!mutex_trylock(&mvdev->state_mutex)) { + spin_unlock(&mvdev->reset_lock); + return; + } + spin_unlock(&mvdev->reset_lock); + mlx5vf_state_mutex_unlock(mvdev); +} + static ssize_t mlx5vf_pci_mig_rw(struct vfio_pci_core_device *vdev, char __user *buf, size_t count, loff_t *ppos, bool iswrite) @@ -539,7 +583,7 @@ static ssize_t mlx5vf_pci_mig_rw(struct vfio_pci_core_device *vdev, } end: - mutex_unlock(&mvdev->state_mutex); + mlx5vf_state_mutex_unlock(mvdev); return ret; } @@ -634,6 +678,7 @@ static int mlx5vf_pci_probe(struct pci_dev *pdev, if (MLX5_CAP_GEN(mdev, migration)) { mvdev->migrate_cap = 1; mutex_init(&mvdev->state_mutex); + spin_lock_init(&mvdev->reset_lock); } mlx5_vf_put_core_dev(mdev); } @@ -668,12 +713,17 @@ static const struct pci_device_id mlx5vf_pci_table[] = { MODULE_DEVICE_TABLE(pci, mlx5vf_pci_table); +const struct pci_error_handlers mlx5vf_err_handlers = { + .reset_done = mlx5vf_pci_aer_reset_done, + .error_detected = vfio_pci_aer_err_detected, +}; + 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, + .err_handler = &mlx5vf_err_handlers, }; static void __exit mlx5vf_pci_cleanup(void)