From patchwork Thu Jun 3 16:07:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Gurtovoy X-Patchwork-Id: 12297521 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BCB0C47096 for ; Thu, 3 Jun 2021 16:08:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 167B5613EE for ; Thu, 3 Jun 2021 16:08:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230100AbhFCQKI (ORCPT ); Thu, 3 Jun 2021 12:10:08 -0400 Received: from mail-mw2nam10on2089.outbound.protection.outlook.com ([40.107.94.89]:23236 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230055AbhFCQKH (ORCPT ); Thu, 3 Jun 2021 12:10:07 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RZkQRu67Pd6bLrL7JGgQzoPVoowTp2C01fjTHDfrvzHnKh5IFjETcD1zRhVHBU4UVGmg1W65X8yq3g+Oqu2Ig0xLdzARnINpBhh4TAJ4To3X65rzToZttUeAmhFOa5Aii5i1f4pqgOdEboL8vEA08wXOR4KR4CP55tpxQMGyQvDDa0eVNXw6uFxR+msHstI4njSh2R/75L/dZelvizUfyqRwjJZ8DS21XutZBoWpsRSU/NxXbN3JGRgtmvIMNuFVZpw/XUlQW6yCUNcGOKfFWlRDsbjBoPoY9PzGG07braBwq6ZsFjVQ2SZ8zpNjclbvZ4hSesUqtLm7HyPHEzuhtg== 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-SenderADCheck; bh=RwPmXRYdRXPn/RiDuZ1iZuOwaa54zlsGBBi1DjxxJEE=; b=Vr2qwVlrWEGFh7LTEYR0ZctYNQz8EZ3QDpx5nWNKTGZD+kmSpjmhJVVBzvLIcs4kehMR8bu9uGXnUc0i2eXiTSG0CEV6QM81Rvr67EkmYVgR4zAUF/N0P9H9iM2TXqfNT1cGkZ4/YQiDFIdZ+PUu89EaUE7NmwhLAZTfcM9f6NRfJqblpYhoegeAo1SL+XmDgApdjvxcapIApnEvyiJSbJ0fpOuPg73z0byYTpiHwZTSjIfTJWSSigXCyyN5pQ5XP2ZkaE/IlY1cgsT6wxR7H7XTK0Nr54erqe/7OrrVcyRbxd5bjY9MU3yQa+KL71mR2JVckn0nlNw2egN/OE3+kQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none 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=RwPmXRYdRXPn/RiDuZ1iZuOwaa54zlsGBBi1DjxxJEE=; b=Z/lfKI8CPA7gn0YhirArB+FTchZYwP0i/SEdwXdDutNqOEWVhjmoiboOw0eTDx5nU/mx3rP69mNSCwm4YbFvwZZF8SVIHVhgc4IL0BpThsg4L0ikXzluDx2oUceFdPuHwU7U88kDud0rjWs3X4aRGgLMWS3z/yXlDuuGcROKlurmJVmlQh3z1F8/Ll5zdLOwsjx2ekLsE3Y6ZT3VCJWlaBR7iDgExiSSJ9cUAKr12NTrNM6pgmu8kIDxG9MDKxD5HXwLMEVwHQD3uv271KA3WGbk/TAnjI8IkCgeXQAz6SXSlSAYFeow3DDz6sifX0seTsFwXymcpsfT0yJl3tE+dw== Received: from CO1PR15CA0046.namprd15.prod.outlook.com (2603:10b6:101:1f::14) by DM5PR12MB2469.namprd12.prod.outlook.com (2603:10b6:4:af::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20; Thu, 3 Jun 2021 16:08:21 +0000 Received: from CO1NAM11FT028.eop-nam11.prod.protection.outlook.com (2603:10b6:101:1f:cafe::3) by CO1PR15CA0046.outlook.office365.com (2603:10b6:101:1f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.15 via Frontend Transport; Thu, 3 Jun 2021 16:08:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; huawei.com; dkim=none (message not signed) header.d=none;huawei.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 CO1NAM11FT028.mail.protection.outlook.com (10.13.175.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4195.22 via Frontend Transport; Thu, 3 Jun 2021 16:08:21 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 3 Jun 2021 16:08:20 +0000 Received: from r-arch-stor02.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 3 Jun 2021 16:08:15 +0000 From: Max Gurtovoy To: , , , , CC: , , , , , , , , , , , , , , , Max Gurtovoy Subject: [PATCH 01/11] vfio-pci: rename vfio_pci.c to vfio_pci_core.c Date: Thu, 3 Jun 2021 19:07:59 +0300 Message-ID: <20210603160809.15845-2-mgurtovoy@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210603160809.15845-1-mgurtovoy@nvidia.com> References: <20210603160809.15845-1-mgurtovoy@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5ff0d18d-9851-4725-03d4-08d926a9cf04 X-MS-TrafficTypeDiagnostic: DM5PR12MB2469: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tFdkMhJEU2gvlEGz2ZI1jeoBi5PBFsd1nFxrvqJh5Fo4OKoaAZ3joJ8PhbNLD7riz1Ch7YmvSl85Z9JozS2aUwdsbSbZkwxeJkPZ8Bg4LMB/bffO6WSysEbhN3B2VuE1EQllERN9dNaR/PVBxdJxJF3Mcd4YADb2jJBh8c6a+fpFShmDd8e/0Ec3jNk3mUn2pZz7r6X9KB7HKpnUvzO/xwnFucsWiYn+FxAtBt6j6V29yJDpKHnMCDZ/Mj0/mbg6Ke2pEyz7IZqE9I5KTLUdw+04j/jBGiAx9BSs938gCB7P60QmawJqBWNmP56jC/pJfnFGJ0UiOFclX0L58XrYNF1gRHRpCsmyaApnOtea1FFRpfO0y3CcfVtVaPLvA4dru8bZtj/jMqTO3Vbi3D4yOLSpE+ttsHYEV9OF/cQLcYLvlCB4RAqAk+ezb0LUqlCyB3WNXCuFLWQRYgcG6FmEKEMBV8ZSMK4RSfTAPaRsdCqU5B3zsZzpyZHW8d8X0+79sOMMph68xVjd1Ze/DqJswhxAqVsyjK2MXXlKHXuumzcuHizLq2k+U/xKapa9Y4/8N7GRyeb1/a3JJfnyQ7bGKfRQYkDdvwoFWKUR2YzaI/lkfoVpRnFJPUs8zB22aohP9rJPRNNFuwADcG7THzCF1g== 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)(39860400002)(136003)(396003)(346002)(376002)(36840700001)(46966006)(1076003)(478600001)(36906005)(356005)(316002)(107886003)(82310400003)(36860700001)(47076005)(36756003)(110136005)(82740400003)(86362001)(7636003)(8936002)(70206006)(2906002)(70586007)(4326008)(6666004)(186003)(5660300002)(8676002)(336012)(6636002)(26005)(2616005)(83380400001)(426003)(54906003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2021 16:08:21.2072 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5ff0d18d-9851-4725-03d4-08d926a9cf04 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: CO1NAM11FT028.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2469 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is a preparation patch for separating the vfio_pci driver to a subsystem driver and a generic pci driver. This patch doesn't change any logic. Signed-off-by: Max Gurtovoy --- drivers/vfio/pci/Makefile | 2 +- drivers/vfio/pci/{vfio_pci.c => vfio_pci_core.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename drivers/vfio/pci/{vfio_pci.c => vfio_pci_core.c} (100%) diff --git a/drivers/vfio/pci/Makefile b/drivers/vfio/pci/Makefile index 3ff42093962f..66a40488e967 100644 --- a/drivers/vfio/pci/Makefile +++ b/drivers/vfio/pci/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only -vfio-pci-y := vfio_pci.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o +vfio-pci-y := vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o vfio-pci-$(CONFIG_VFIO_PCI_IGD) += vfio_pci_igd.o vfio-pci-$(CONFIG_S390) += vfio_pci_zdev.o diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci_core.c similarity index 100% rename from drivers/vfio/pci/vfio_pci.c rename to drivers/vfio/pci/vfio_pci_core.c From patchwork Thu Jun 3 16:08:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Gurtovoy X-Patchwork-Id: 12297523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64C07C47096 for ; Thu, 3 Jun 2021 16:08:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 47252613E4 for ; Thu, 3 Jun 2021 16:08:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230019AbhFCQKQ (ORCPT ); Thu, 3 Jun 2021 12:10:16 -0400 Received: from mail-bn8nam11on2042.outbound.protection.outlook.com ([40.107.236.42]:32453 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229755AbhFCQKP (ORCPT ); Thu, 3 Jun 2021 12:10:15 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h3r5WXZ/rqLCbQ+XMeyW3OF194qOuK78mgwwkHW3BPV/h/p5Vk1mOhPiE2P2XSeAdg2uKUfrdFl90z9/fh6jelXJ1gpKuxB15EpKIlLT+ZG+53tM8E1z3yUW8B8VpL6kYY1ID7jKxmO6LYFIbzjIOujOeSfZFR2kLmiGjp/QzjvOzM2S+ytXmdWQ1x42s2bS6KwAhmeRk4PskVjyyBktx8FD19TWmk5hdtwsu6gmy171+sh/ozy0bgEluUAUCO/thmCk2wMdmbzo7EJ3L0zu4aSipuXHQL2mqb3J5qpDnJXPiCLRYH4jkW0x/eOj0UHumxAVrro/v+Yp5PEx9H616A== 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-SenderADCheck; bh=xKdwbCTb/KGQH+rz3WFnJ8z0CToEmzY+m3yOzLLiefw=; b=nErerJRHN5kK5fWvcFwS8WWA3rzPVOENdW60tDY9YWE9Df3nWNkTccUcowUDfmXYvzibcw5AVs8DCK1NYNR14w0DA5CkI/E5GvBKLl2mSgGfHaeFTEJFzQBk3QejfF92/D45F0HDtB04radvcVXHQ4hxjwUsS/lY19ECy0Nzdx4Dte7tjHEun2Az0R6RwLITPTRTTWv4JdcUDBeQsz+iNON7RLiQc1pdUSb0YTlAdCc/yeHRZquBlGY71RuxNPJNq7WIBPrqWdgbr0jZMFe77X71JMZZZUptilS4c6EpmeOy01jOJRj49cizLEwTMmdfxV/ob9TpVjOaUJPVJHUQeg== 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=none sp=none 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=xKdwbCTb/KGQH+rz3WFnJ8z0CToEmzY+m3yOzLLiefw=; b=hR6qZr2dFSDuWf0x+//EVS48NscGDmWahYfNnzj/mBlTqI46Et5z9iFJKJPCQLZj5CNEy/Uy8ic0nAgkvzlZzhzmkg1kUlnBFRY3O59xHi16K2N0W0zUk+3RIQwKc3kv+TplzcBSBCLUFUKv1olcUjJsKCM/NZ3dr0/pTl8uni+5STziemvxEcgnIxPuvdcJha1JmbobE5vkz1YzenFXang9VauqK3mFfGy36dj//CCH1TUl3DUsuuPfYsohnLYO7wKoTAKN6Hdl1v86DAt1DUnXq2TFuu6URow/7+OsrURheN4qQEQ2lfjztd1X/zGypMEXk+SP0lZ+J3sdtjg4rQ== Received: from MW4PR03CA0208.namprd03.prod.outlook.com (2603:10b6:303:b8::33) by SJ0PR12MB5456.namprd12.prod.outlook.com (2603:10b6:a03:3ae::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.22; Thu, 3 Jun 2021 16:08:27 +0000 Received: from CO1NAM11FT040.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b8:cafe::54) by MW4PR03CA0208.outlook.office365.com (2603:10b6:303:b8::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.15 via Frontend Transport; Thu, 3 Jun 2021 16:08:27 +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 CO1NAM11FT040.mail.protection.outlook.com (10.13.174.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4195.22 via Frontend Transport; Thu, 3 Jun 2021 16:08:27 +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.2; Thu, 3 Jun 2021 16:08:26 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 3 Jun 2021 16:08:25 +0000 Received: from r-arch-stor02.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 3 Jun 2021 16:08:21 +0000 From: Max Gurtovoy To: , , , , CC: , , , , , , , , , , , , , , , Max Gurtovoy Subject: [PATCH 02/11] vfio-pci: rename vfio_pci_private.h to vfio_pci_core.h Date: Thu, 3 Jun 2021 19:08:00 +0300 Message-ID: <20210603160809.15845-3-mgurtovoy@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210603160809.15845-1-mgurtovoy@nvidia.com> References: <20210603160809.15845-1-mgurtovoy@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b5b50715-5417-45d6-7883-08d926a9d283 X-MS-TrafficTypeDiagnostic: SJ0PR12MB5456: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1824; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dyzbj0bT/3krxDFC564EZt6gHZsUX19HHdPBEidRIENXVa+83rY8UAG2psGwkTcTgwqJ6ZKPI7CaZqYNQoV8v6MxAmGA8HQ88z1DjlY5hFt0RSLQCAQMJ3dfw3eI7XfqrlPSUchS4aeQZ2Zvo85Gjv/OW2OGevODZGrVYUW0ydxlnzANmZ0YUnBgaGrk2nMbNuACvq30vEPDG+HBj9VZs3fDLyIgi6KEKQORikpjwqz1z/aiqaEWKSJF7Op/KgYRQi2grwDbk9m87fF5S5tfLt9NHpzX3dd43HEdTyH+JSvCxET3G/Bm9wnzr1ACAa2nAEQTtwyazP7YI1cKJhmFrBQ/axlyG7m1i13GYoicQVBLpvaFf+zPx/WT3NvM3eG6jP9+3cJ48Y1PVkThcIjzjj7yEz8DWGVHhWSiamV1LICjt+2QirJM49d+1P/NnsmJyaY2hPQKyimUVUzNjcbLxKxFuuAMoprmUeMS2v8bntT4xHBbsqTAwCUVQoj3NnsNMnR+5GCn9f619CQCFatqloYHQExL/gTO0crm3LykPZcTrltxhsCBZqdz+Ol0ZolN99P6kNVR0R4olOTzok0GQ7LBdAF3jMnN+c6Hp9akPKBtNHpY2Mv8Mmgij7tgwM63K094Z7Hxg8FIdR/37VpWBf4bidvrMHGAlGnL7QAOulA= 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)(396003)(136003)(376002)(346002)(39860400002)(46966006)(36840700001)(36860700001)(2616005)(8676002)(36756003)(8936002)(478600001)(110136005)(54906003)(83380400001)(1076003)(6666004)(82310400003)(5660300002)(70586007)(2906002)(70206006)(4326008)(356005)(316002)(426003)(86362001)(336012)(186003)(7636003)(6636002)(82740400003)(47076005)(36906005)(26005)(107886003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2021 16:08:27.1696 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b5b50715-5417-45d6-7883-08d926a9d283 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: CO1NAM11FT040.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5456 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is a preparation patch for separating the vfio_pci driver to a subsystem driver and a generic pci driver. This patch doesn't change any logic. Signed-off-by: Max Gurtovoy --- drivers/vfio/pci/vfio_pci_config.c | 2 +- drivers/vfio/pci/vfio_pci_core.c | 2 +- drivers/vfio/pci/{vfio_pci_private.h => vfio_pci_core.h} | 6 +++--- drivers/vfio/pci/vfio_pci_igd.c | 2 +- drivers/vfio/pci/vfio_pci_intrs.c | 2 +- drivers/vfio/pci/vfio_pci_rdwr.c | 2 +- drivers/vfio/pci/vfio_pci_zdev.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) rename drivers/vfio/pci/{vfio_pci_private.h => vfio_pci_core.h} (98%) diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c index 70e28efbc51f..0bc269c0b03f 100644 --- a/drivers/vfio/pci/vfio_pci_config.c +++ b/drivers/vfio/pci/vfio_pci_config.c @@ -26,7 +26,7 @@ #include #include -#include "vfio_pci_private.h" +#include "vfio_pci_core.h" /* Fake capability ID for standard config space */ #define PCI_CAP_ID_BASIC 0 diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index b87fefc475c7..dc99a546ffe5 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -28,7 +28,7 @@ #include #include -#include "vfio_pci_private.h" +#include "vfio_pci_core.h" #define DRIVER_VERSION "0.2" #define DRIVER_AUTHOR "Alex Williamson " diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_core.h similarity index 98% rename from drivers/vfio/pci/vfio_pci_private.h rename to drivers/vfio/pci/vfio_pci_core.h index ae83c2eada3a..b73abba881e9 100644 --- a/drivers/vfio/pci/vfio_pci_private.h +++ b/drivers/vfio/pci/vfio_pci_core.h @@ -15,8 +15,8 @@ #include #include -#ifndef VFIO_PCI_PRIVATE_H -#define VFIO_PCI_PRIVATE_H +#ifndef VFIO_PCI_CORE_H +#define VFIO_PCI_CORE_H #define VFIO_PCI_OFFSET_SHIFT 40 @@ -205,4 +205,4 @@ static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_device *vdev, } #endif -#endif /* VFIO_PCI_PRIVATE_H */ +#endif /* VFIO_PCI_CORE_H */ diff --git a/drivers/vfio/pci/vfio_pci_igd.c b/drivers/vfio/pci/vfio_pci_igd.c index 228df565e9bc..214b6d629b21 100644 --- a/drivers/vfio/pci/vfio_pci_igd.c +++ b/drivers/vfio/pci/vfio_pci_igd.c @@ -15,7 +15,7 @@ #include #include -#include "vfio_pci_private.h" +#include "vfio_pci_core.h" #define OPREGION_SIGNATURE "IntelGraphicsMem" #define OPREGION_SIZE (8 * 1024) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 869dce5f134d..df1e8c8c274c 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -20,7 +20,7 @@ #include #include -#include "vfio_pci_private.h" +#include "vfio_pci_core.h" /* * INTx diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c index a0b5fc8e46f4..667e82726e75 100644 --- a/drivers/vfio/pci/vfio_pci_rdwr.c +++ b/drivers/vfio/pci/vfio_pci_rdwr.c @@ -17,7 +17,7 @@ #include #include -#include "vfio_pci_private.h" +#include "vfio_pci_core.h" #ifdef __LITTLE_ENDIAN #define vfio_ioread64 ioread64 diff --git a/drivers/vfio/pci/vfio_pci_zdev.c b/drivers/vfio/pci/vfio_pci_zdev.c index 7b011b62c766..ecae0c3d95a0 100644 --- a/drivers/vfio/pci/vfio_pci_zdev.c +++ b/drivers/vfio/pci/vfio_pci_zdev.c @@ -19,7 +19,7 @@ #include #include -#include "vfio_pci_private.h" +#include "vfio_pci_core.h" /* * Add the Base PCI Function information to the device info region. From patchwork Thu Jun 3 16:08:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Gurtovoy X-Patchwork-Id: 12297525 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A26EC47082 for ; Thu, 3 Jun 2021 16:08:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B5266121D for ; Thu, 3 Jun 2021 16:08:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230111AbhFCQKU (ORCPT ); Thu, 3 Jun 2021 12:10:20 -0400 Received: from mail-dm6nam12on2087.outbound.protection.outlook.com ([40.107.243.87]:29536 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229755AbhFCQKT (ORCPT ); Thu, 3 Jun 2021 12:10:19 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ql79Bhxnx24E/mo96soyRE7kQJ5T7TjgVRRt6u8RRtS/lIrMvACzSN6rVIM3hmzVyZzdtssd4ls9rwu2l8YeWVNW3gcSjsmhNYACUCJlWV/AanywAH5sbzUJjthjMHdbZeIY0P894RC4FL+Ida5NeByo+WzR3OKOz6TE58dqPr0Zyl5sBm7dPUo0xqby2/5xA8sohHWjiT7ZOH/i4tC7UdlYE7uvSK0d1h8NfBu4h2nnV5xArZYxdrjo+IazbBXmQoJdko7uH9tndejVLsUzvMBcsoyO4dpt+cYu0gM1PogfGK16iEgVS2xTvFp9WuwfGng8wXbsD9KqhRwRL+Zlsg== 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-SenderADCheck; bh=pT1DOCVRnDbD+ab2hVPUlWGoaHZ0ZRtAQuYk1dMeN8A=; b=F2o0npuzEDxeM7OqxSVdt7oSuzAxABIz0241LjXBAM3CFr76kL3lnCRCv5bCTkd97W+zoW5rVsOuw1YFPWso73xSaA+D9C+BwhhABEqBVd/6rfaDC17PGospeLFACxo1UuhNl8ia34jkK+JJl0krlYgeMLzrIOo3In5wSexbHSKOLOVOdSoCCI8paawEEAgQ6R45OQyE9hQ7OUueaODXZS1qCEEGaR0asGVToGuIxhlKvTQ89d4YVnMUxxahAWe692NFjaZHAz7D8J1Qz7zHR9I2O3SJmR6jc7p9vY0yteFxgFQ7iwJ3mLwcurfCnlfaq1zMxa5+UKCbQ7FnowkE8Q== 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=none sp=none 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=pT1DOCVRnDbD+ab2hVPUlWGoaHZ0ZRtAQuYk1dMeN8A=; b=U3P3h5wdv+4PHHGj+b9Ru8WEbNotg4gg5xR6McoKwsHQcq5t0g5pCshAxSW44DfmyLteZEQnlpbIibFQdrR6nQBlUl+DNBW5JFT917yQBgYTINjpL/z4gaGx29EK1fFpUWjN8k1Cdx4QFnG7YKeCwEtKBnn1jHCFERH3mZrpoZHbA2OVjvBaMWVu8OMQxiDrarzmtk4gsgZnj9eweq45XOzVlLK27F7+mYjOXwFC6TxGt/WtHaF5Vu4cwAzQZrIFvc8Vw8lSoflUQpDWmdxdVqE38KfVY4j2OZhjzYI6cvykwi646M3BRhN+zVN9mv2uMUjhGjTcFepJJoIa/pet8Q== Received: from BN9PR03CA0025.namprd03.prod.outlook.com (2603:10b6:408:fa::30) by CH2PR12MB4071.namprd12.prod.outlook.com (2603:10b6:610:7b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.22; Thu, 3 Jun 2021 16:08:32 +0000 Received: from BN8NAM11FT059.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fa:cafe::96) by BN9PR03CA0025.outlook.office365.com (2603:10b6:408:fa::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.22 via Frontend Transport; Thu, 3 Jun 2021 16:08:32 +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 BN8NAM11FT059.mail.protection.outlook.com (10.13.177.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4195.22 via Frontend Transport; Thu, 3 Jun 2021 16:08:32 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 3 Jun 2021 09:08:31 -0700 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 3 Jun 2021 16:08:31 +0000 Received: from r-arch-stor02.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 3 Jun 2021 16:08:26 +0000 From: Max Gurtovoy To: , , , , CC: , , , , , , , , , , , , , , , Max Gurtovoy Subject: [PATCH 03/11] vfio-pci: rename vfio_pci_device to vfio_pci_core_device Date: Thu, 3 Jun 2021 19:08:01 +0300 Message-ID: <20210603160809.15845-4-mgurtovoy@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210603160809.15845-1-mgurtovoy@nvidia.com> References: <20210603160809.15845-1-mgurtovoy@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 996e322f-354e-49d6-a1ee-08d926a9d590 X-MS-TrafficTypeDiagnostic: CH2PR12MB4071: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jDPqIPlau+xbK9C5UXEgwxyGBsNu4Z6Rm8m4LqdwowA7Pu7ssjQfp/hy/jWGNQJ+/sivp/Chd4igbBtat69sWO2cCsrchhMTx7gO+wLYxX+compqyBvHcUIiTNk1I/GWLwQYuyhR1Kjv5nJt/zEdKTQe/5DL4IVywR94JfWZl/vZB4PiLmxMcdmiar/hcsrUy6x5yQCnEN1Sm55OZGcadwWSJrIBSaTk+h7L0w26pky8zuUhp0bHjrUCofC5OvYe9nNQP4YmtSx0fjynhkIVdP1dVQb0RE52NOkICvM2rPOBAJj+1SEBDoliBukEf3MN0K1lfBPtRzgTETy/w4fYE3PytYSG2AwMhB6RbFWcPUDewO43+iuVnGsK4nOb6zv+DSYSDN/u6b3YN+a7U7sewLzo3HzDlnViTQo1lrUrLmzUuduMee2o6B6zo7EFGZX7BGfs80zrEv3coPyegwmnmqHZyKto1JOqtaz9Ej9c6t4hF5Ydvyiw4Tmu/wPnY7i4m8YjUhDHox7fHOVoyUFBeB03THz5H2EGQp/kAu014EXHnT4ySedIxbFZAteWOhYTv9dZjACfxsxVniB+aUgCXjJot7mHWLCK9DOixuOH7CKQSKq3LtcHzDd40RELb0rM1cC8R/PaXh2mIjAjXUFzn2tFu79kbUeqQctTljcIowI= 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)(346002)(376002)(39850400004)(136003)(396003)(36840700001)(46966006)(7636003)(186003)(6636002)(356005)(316002)(4326008)(426003)(86362001)(336012)(82740400003)(107886003)(26005)(47076005)(36756003)(8936002)(2616005)(8676002)(110136005)(54906003)(83380400001)(478600001)(30864003)(36860700001)(82310400003)(5660300002)(6666004)(70586007)(2906002)(70206006)(1076003)(579004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2021 16:08:32.1551 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 996e322f-354e-49d6-a1ee-08d926a9d590 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: BN8NAM11FT059.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4071 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is a preparation patch for separating the vfio_pci driver to a subsystem driver and a generic pci driver. This patch doesn't change any logic. The new vfio_pci_core_device structure will be the main structure of the core driver and later on vfio_pci_device structure will be the main structure of the generic vfio_pci driver. Signed-off-by: Max Gurtovoy --- drivers/vfio/pci/vfio_pci_config.c | 68 ++++++++-------- drivers/vfio/pci/vfio_pci_core.c | 124 ++++++++++++++--------------- drivers/vfio/pci/vfio_pci_core.h | 52 ++++++------ drivers/vfio/pci/vfio_pci_igd.c | 14 ++-- drivers/vfio/pci/vfio_pci_intrs.c | 40 +++++----- drivers/vfio/pci/vfio_pci_rdwr.c | 16 ++-- drivers/vfio/pci/vfio_pci_zdev.c | 2 +- 7 files changed, 158 insertions(+), 158 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c index 0bc269c0b03f..1f034f768a27 100644 --- a/drivers/vfio/pci/vfio_pci_config.c +++ b/drivers/vfio/pci/vfio_pci_config.c @@ -108,9 +108,9 @@ static const u16 pci_ext_cap_length[PCI_EXT_CAP_ID_MAX + 1] = { struct perm_bits { u8 *virt; /* read/write virtual data, not hw */ u8 *write; /* writeable bits */ - int (*readfn)(struct vfio_pci_device *vdev, int pos, int count, + int (*readfn)(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 *val); - int (*writefn)(struct vfio_pci_device *vdev, int pos, int count, + int (*writefn)(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 val); }; @@ -171,7 +171,7 @@ static int vfio_user_config_write(struct pci_dev *pdev, int offset, return ret; } -static int vfio_default_config_read(struct vfio_pci_device *vdev, int pos, +static int vfio_default_config_read(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 *val) { @@ -197,7 +197,7 @@ static int vfio_default_config_read(struct vfio_pci_device *vdev, int pos, return count; } -static int vfio_default_config_write(struct vfio_pci_device *vdev, int pos, +static int vfio_default_config_write(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 val) { @@ -244,7 +244,7 @@ static int vfio_default_config_write(struct vfio_pci_device *vdev, int pos, } /* Allow direct read from hardware, except for capability next pointer */ -static int vfio_direct_config_read(struct vfio_pci_device *vdev, int pos, +static int vfio_direct_config_read(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 *val) { @@ -269,7 +269,7 @@ static int vfio_direct_config_read(struct vfio_pci_device *vdev, int pos, } /* Raw access skips any kind of virtualization */ -static int vfio_raw_config_write(struct vfio_pci_device *vdev, int pos, +static int vfio_raw_config_write(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 val) { @@ -282,7 +282,7 @@ static int vfio_raw_config_write(struct vfio_pci_device *vdev, int pos, return count; } -static int vfio_raw_config_read(struct vfio_pci_device *vdev, int pos, +static int vfio_raw_config_read(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 *val) { @@ -296,7 +296,7 @@ static int vfio_raw_config_read(struct vfio_pci_device *vdev, int pos, } /* Virt access uses only virtualization */ -static int vfio_virt_config_write(struct vfio_pci_device *vdev, int pos, +static int vfio_virt_config_write(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 val) { @@ -304,7 +304,7 @@ static int vfio_virt_config_write(struct vfio_pci_device *vdev, int pos, return count; } -static int vfio_virt_config_read(struct vfio_pci_device *vdev, int pos, +static int vfio_virt_config_read(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 *val) { @@ -396,7 +396,7 @@ static inline void p_setd(struct perm_bits *p, int off, u32 virt, u32 write) } /* Caller should hold memory_lock semaphore */ -bool __vfio_pci_memory_enabled(struct vfio_pci_device *vdev) +bool __vfio_pci_memory_enabled(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev = vdev->pdev; u16 cmd = le16_to_cpu(*(__le16 *)&vdev->vconfig[PCI_COMMAND]); @@ -413,7 +413,7 @@ bool __vfio_pci_memory_enabled(struct vfio_pci_device *vdev) * Restore the *real* BARs after we detect a FLR or backdoor reset. * (backdoor = some device specific technique that we didn't catch) */ -static void vfio_bar_restore(struct vfio_pci_device *vdev) +static void vfio_bar_restore(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev = vdev->pdev; u32 *rbar = vdev->rbar; @@ -460,7 +460,7 @@ static __le32 vfio_generate_bar_flags(struct pci_dev *pdev, int bar) * Pretend we're hardware and tweak the values of the *virtual* PCI BARs * to reflect the hardware capabilities. This implements BAR sizing. */ -static void vfio_bar_fixup(struct vfio_pci_device *vdev) +static void vfio_bar_fixup(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev = vdev->pdev; int i; @@ -514,7 +514,7 @@ static void vfio_bar_fixup(struct vfio_pci_device *vdev) vdev->bardirty = false; } -static int vfio_basic_config_read(struct vfio_pci_device *vdev, int pos, +static int vfio_basic_config_read(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 *val) { @@ -536,7 +536,7 @@ static int vfio_basic_config_read(struct vfio_pci_device *vdev, int pos, } /* Test whether BARs match the value we think they should contain */ -static bool vfio_need_bar_restore(struct vfio_pci_device *vdev) +static bool vfio_need_bar_restore(struct vfio_pci_core_device *vdev) { int i = 0, pos = PCI_BASE_ADDRESS_0, ret; u32 bar; @@ -552,7 +552,7 @@ static bool vfio_need_bar_restore(struct vfio_pci_device *vdev) return false; } -static int vfio_basic_config_write(struct vfio_pci_device *vdev, int pos, +static int vfio_basic_config_write(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 val) { @@ -692,7 +692,7 @@ static int __init init_pci_cap_basic_perm(struct perm_bits *perm) return 0; } -static int vfio_pm_config_write(struct vfio_pci_device *vdev, int pos, +static int vfio_pm_config_write(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 val) { @@ -747,7 +747,7 @@ static int __init init_pci_cap_pm_perm(struct perm_bits *perm) return 0; } -static int vfio_vpd_config_write(struct vfio_pci_device *vdev, int pos, +static int vfio_vpd_config_write(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 val) { @@ -829,7 +829,7 @@ static int __init init_pci_cap_pcix_perm(struct perm_bits *perm) return 0; } -static int vfio_exp_config_write(struct vfio_pci_device *vdev, int pos, +static int vfio_exp_config_write(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 val) { @@ -913,7 +913,7 @@ static int __init init_pci_cap_exp_perm(struct perm_bits *perm) return 0; } -static int vfio_af_config_write(struct vfio_pci_device *vdev, int pos, +static int vfio_af_config_write(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 val) { @@ -1072,7 +1072,7 @@ int __init vfio_pci_init_perm_bits(void) return ret; } -static int vfio_find_cap_start(struct vfio_pci_device *vdev, int pos) +static int vfio_find_cap_start(struct vfio_pci_core_device *vdev, int pos) { u8 cap; int base = (pos >= PCI_CFG_SPACE_SIZE) ? PCI_CFG_SPACE_SIZE : @@ -1089,7 +1089,7 @@ static int vfio_find_cap_start(struct vfio_pci_device *vdev, int pos) return pos; } -static int vfio_msi_config_read(struct vfio_pci_device *vdev, int pos, +static int vfio_msi_config_read(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 *val) { @@ -1109,7 +1109,7 @@ static int vfio_msi_config_read(struct vfio_pci_device *vdev, int pos, return vfio_default_config_read(vdev, pos, count, perm, offset, val); } -static int vfio_msi_config_write(struct vfio_pci_device *vdev, int pos, +static int vfio_msi_config_write(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 val) { @@ -1189,7 +1189,7 @@ static int init_pci_cap_msi_perm(struct perm_bits *perm, int len, u16 flags) } /* Determine MSI CAP field length; initialize msi_perms on 1st call per vdev */ -static int vfio_msi_cap_len(struct vfio_pci_device *vdev, u8 pos) +static int vfio_msi_cap_len(struct vfio_pci_core_device *vdev, u8 pos) { struct pci_dev *pdev = vdev->pdev; int len, ret; @@ -1222,7 +1222,7 @@ static int vfio_msi_cap_len(struct vfio_pci_device *vdev, u8 pos) } /* Determine extended capability length for VC (2 & 9) and MFVC */ -static int vfio_vc_cap_len(struct vfio_pci_device *vdev, u16 pos) +static int vfio_vc_cap_len(struct vfio_pci_core_device *vdev, u16 pos) { struct pci_dev *pdev = vdev->pdev; u32 tmp; @@ -1263,7 +1263,7 @@ static int vfio_vc_cap_len(struct vfio_pci_device *vdev, u16 pos) return len; } -static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos) +static int vfio_cap_len(struct vfio_pci_core_device *vdev, u8 cap, u8 pos) { struct pci_dev *pdev = vdev->pdev; u32 dword; @@ -1338,7 +1338,7 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos) return 0; } -static int vfio_ext_cap_len(struct vfio_pci_device *vdev, u16 ecap, u16 epos) +static int vfio_ext_cap_len(struct vfio_pci_core_device *vdev, u16 ecap, u16 epos) { struct pci_dev *pdev = vdev->pdev; u8 byte; @@ -1412,7 +1412,7 @@ static int vfio_ext_cap_len(struct vfio_pci_device *vdev, u16 ecap, u16 epos) return 0; } -static int vfio_fill_vconfig_bytes(struct vfio_pci_device *vdev, +static int vfio_fill_vconfig_bytes(struct vfio_pci_core_device *vdev, int offset, int size) { struct pci_dev *pdev = vdev->pdev; @@ -1459,7 +1459,7 @@ static int vfio_fill_vconfig_bytes(struct vfio_pci_device *vdev, return ret; } -static int vfio_cap_init(struct vfio_pci_device *vdev) +static int vfio_cap_init(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev = vdev->pdev; u8 *map = vdev->pci_config_map; @@ -1549,7 +1549,7 @@ static int vfio_cap_init(struct vfio_pci_device *vdev) return 0; } -static int vfio_ecap_init(struct vfio_pci_device *vdev) +static int vfio_ecap_init(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev = vdev->pdev; u8 *map = vdev->pci_config_map; @@ -1669,7 +1669,7 @@ static const struct pci_device_id known_bogus_vf_intx_pin[] = { * for each area requiring emulated bits, but the array of pointers * would be comparable in size (at least for standard config space). */ -int vfio_config_init(struct vfio_pci_device *vdev) +int vfio_config_init(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev = vdev->pdev; u8 *map, *vconfig; @@ -1773,7 +1773,7 @@ int vfio_config_init(struct vfio_pci_device *vdev) return pcibios_err_to_errno(ret); } -void vfio_config_free(struct vfio_pci_device *vdev) +void vfio_config_free(struct vfio_pci_core_device *vdev) { kfree(vdev->vconfig); vdev->vconfig = NULL; @@ -1790,7 +1790,7 @@ void vfio_config_free(struct vfio_pci_device *vdev) * Find the remaining number of bytes in a dword that match the given * position. Stop at either the end of the capability or the dword boundary. */ -static size_t vfio_pci_cap_remaining_dword(struct vfio_pci_device *vdev, +static size_t vfio_pci_cap_remaining_dword(struct vfio_pci_core_device *vdev, loff_t pos) { u8 cap = vdev->pci_config_map[pos]; @@ -1802,7 +1802,7 @@ static size_t vfio_pci_cap_remaining_dword(struct vfio_pci_device *vdev, return i; } -static ssize_t vfio_config_do_rw(struct vfio_pci_device *vdev, char __user *buf, +static ssize_t vfio_config_do_rw(struct vfio_pci_core_device *vdev, char __user *buf, size_t count, loff_t *ppos, bool iswrite) { struct pci_dev *pdev = vdev->pdev; @@ -1885,7 +1885,7 @@ static ssize_t vfio_config_do_rw(struct vfio_pci_device *vdev, char __user *buf, return ret; } -ssize_t vfio_pci_config_rw(struct vfio_pci_device *vdev, char __user *buf, +ssize_t vfio_pci_config_rw(struct vfio_pci_core_device *vdev, char __user *buf, size_t count, loff_t *ppos, bool iswrite) { size_t done = 0; diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index dc99a546ffe5..a6a9d1aaa185 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -121,7 +121,7 @@ static bool vfio_pci_is_denylisted(struct pci_dev *pdev) */ static unsigned int vfio_pci_set_vga_decode(void *opaque, bool single_vga) { - struct vfio_pci_device *vdev = opaque; + struct vfio_pci_core_device *vdev = opaque; struct pci_dev *tmp = NULL, *pdev = vdev->pdev; unsigned char max_busnr; unsigned int decodes; @@ -155,7 +155,7 @@ static inline bool vfio_pci_is_vga(struct pci_dev *pdev) return (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA; } -static void vfio_pci_probe_mmaps(struct vfio_pci_device *vdev) +static void vfio_pci_probe_mmaps(struct vfio_pci_core_device *vdev) { struct resource *res; int i; @@ -223,8 +223,8 @@ static void vfio_pci_probe_mmaps(struct vfio_pci_device *vdev) } } -static void vfio_pci_try_bus_reset(struct vfio_pci_device *vdev); -static void vfio_pci_disable(struct vfio_pci_device *vdev); +static void vfio_pci_try_bus_reset(struct vfio_pci_core_device *vdev); +static void vfio_pci_disable(struct vfio_pci_core_device *vdev); static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data); /* @@ -258,7 +258,7 @@ static bool vfio_pci_nointx(struct pci_dev *pdev) return false; } -static void vfio_pci_probe_power_state(struct vfio_pci_device *vdev) +static void vfio_pci_probe_power_state(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev = vdev->pdev; u16 pmcsr; @@ -278,7 +278,7 @@ static void vfio_pci_probe_power_state(struct vfio_pci_device *vdev) * by PM capability emulation and separately from pci_dev internal saved state * to avoid it being overwritten and consumed around other resets. */ -int vfio_pci_set_power_state(struct vfio_pci_device *vdev, pci_power_t state) +int vfio_pci_set_power_state(struct vfio_pci_core_device *vdev, pci_power_t state) { struct pci_dev *pdev = vdev->pdev; bool needs_restore = false, needs_save = false; @@ -309,7 +309,7 @@ int vfio_pci_set_power_state(struct vfio_pci_device *vdev, pci_power_t state) return ret; } -static int vfio_pci_enable(struct vfio_pci_device *vdev) +static int vfio_pci_enable(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev = vdev->pdev; int ret; @@ -397,7 +397,7 @@ static int vfio_pci_enable(struct vfio_pci_device *vdev) return ret; } -static void vfio_pci_disable(struct vfio_pci_device *vdev) +static void vfio_pci_disable(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev = vdev->pdev; struct vfio_pci_dummy_resource *dummy_res, *tmp; @@ -498,7 +498,7 @@ static void vfio_pci_disable(struct vfio_pci_device *vdev) static struct pci_driver vfio_pci_driver; -static struct vfio_pci_device *get_pf_vdev(struct vfio_pci_device *vdev) +static struct vfio_pci_core_device *get_pf_vdev(struct vfio_pci_core_device *vdev) { struct pci_dev *physfn = pci_physfn(vdev->pdev); struct vfio_device *pf_dev; @@ -515,12 +515,12 @@ static struct vfio_pci_device *get_pf_vdev(struct vfio_pci_device *vdev) return NULL; } - return container_of(pf_dev, struct vfio_pci_device, vdev); + return container_of(pf_dev, struct vfio_pci_core_device, vdev); } -static void vfio_pci_vf_token_user_add(struct vfio_pci_device *vdev, int val) +static void vfio_pci_vf_token_user_add(struct vfio_pci_core_device *vdev, int val) { - struct vfio_pci_device *pf_vdev = get_pf_vdev(vdev); + struct vfio_pci_core_device *pf_vdev = get_pf_vdev(vdev); if (!pf_vdev) return; @@ -535,8 +535,8 @@ static void vfio_pci_vf_token_user_add(struct vfio_pci_device *vdev, int val) static void vfio_pci_release(struct vfio_device *core_vdev) { - struct vfio_pci_device *vdev = - container_of(core_vdev, struct vfio_pci_device, vdev); + struct vfio_pci_core_device *vdev = + container_of(core_vdev, struct vfio_pci_core_device, vdev); lockdep_assert_held(&core_vdev->reflck->lock); @@ -558,8 +558,8 @@ static void vfio_pci_release(struct vfio_device *core_vdev) static int vfio_pci_open(struct vfio_device *core_vdev) { - struct vfio_pci_device *vdev = - container_of(core_vdev, struct vfio_pci_device, vdev); + struct vfio_pci_core_device *vdev = + container_of(core_vdev, struct vfio_pci_core_device, vdev); int ret; lockdep_assert_held(&core_vdev->reflck->lock); @@ -573,7 +573,7 @@ static int vfio_pci_open(struct vfio_device *core_vdev) return ret; } -static int vfio_pci_get_irq_count(struct vfio_pci_device *vdev, int irq_type) +static int vfio_pci_get_irq_count(struct vfio_pci_core_device *vdev, int irq_type) { if (irq_type == VFIO_PCI_INTX_IRQ_INDEX) { u8 pin; @@ -720,7 +720,7 @@ static int vfio_pci_for_each_slot_or_bus(struct pci_dev *pdev, return walk.ret; } -static int msix_mmappable_cap(struct vfio_pci_device *vdev, +static int msix_mmappable_cap(struct vfio_pci_core_device *vdev, struct vfio_info_cap *caps) { struct vfio_info_cap_header header = { @@ -731,7 +731,7 @@ static int msix_mmappable_cap(struct vfio_pci_device *vdev, return vfio_info_add_capability(caps, &header, sizeof(header)); } -int vfio_pci_register_dev_region(struct vfio_pci_device *vdev, +int vfio_pci_register_dev_region(struct vfio_pci_core_device *vdev, unsigned int type, unsigned int subtype, const struct vfio_pci_regops *ops, size_t size, u32 flags, void *data) @@ -758,7 +758,7 @@ int vfio_pci_register_dev_region(struct vfio_pci_device *vdev, } struct vfio_devices { - struct vfio_pci_device **devices; + struct vfio_pci_core_device **devices; int cur_index; int max_index; }; @@ -766,8 +766,8 @@ struct vfio_devices { static long vfio_pci_ioctl(struct vfio_device *core_vdev, unsigned int cmd, unsigned long arg) { - struct vfio_pci_device *vdev = - container_of(core_vdev, struct vfio_pci_device, vdev); + struct vfio_pci_core_device *vdev = + container_of(core_vdev, struct vfio_pci_core_device, vdev); unsigned long minsz; if (cmd == VFIO_DEVICE_GET_INFO) { @@ -1247,7 +1247,7 @@ static long vfio_pci_ioctl(struct vfio_device *core_vdev, goto hot_reset_release; for (; mem_idx < devs.cur_index; mem_idx++) { - struct vfio_pci_device *tmp = devs.devices[mem_idx]; + struct vfio_pci_core_device *tmp = devs.devices[mem_idx]; ret = down_write_trylock(&tmp->memory_lock); if (!ret) { @@ -1262,7 +1262,7 @@ static long vfio_pci_ioctl(struct vfio_device *core_vdev, hot_reset_release: for (i = 0; i < devs.cur_index; i++) { - struct vfio_pci_device *tmp = devs.devices[i]; + struct vfio_pci_core_device *tmp = devs.devices[i]; if (i < mem_idx) up_write(&tmp->memory_lock); @@ -1363,7 +1363,7 @@ static long vfio_pci_ioctl(struct vfio_device *core_vdev, return -ENOTTY; } -static ssize_t vfio_pci_rw(struct vfio_pci_device *vdev, char __user *buf, +static ssize_t vfio_pci_rw(struct vfio_pci_core_device *vdev, char __user *buf, size_t count, loff_t *ppos, bool iswrite) { unsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos); @@ -1397,8 +1397,8 @@ static ssize_t vfio_pci_rw(struct vfio_pci_device *vdev, char __user *buf, static ssize_t vfio_pci_read(struct vfio_device *core_vdev, char __user *buf, size_t count, loff_t *ppos) { - struct vfio_pci_device *vdev = - container_of(core_vdev, struct vfio_pci_device, vdev); + struct vfio_pci_core_device *vdev = + container_of(core_vdev, struct vfio_pci_core_device, vdev); if (!count) return 0; @@ -1409,8 +1409,8 @@ static ssize_t vfio_pci_read(struct vfio_device *core_vdev, char __user *buf, static ssize_t vfio_pci_write(struct vfio_device *core_vdev, const char __user *buf, size_t count, loff_t *ppos) { - struct vfio_pci_device *vdev = - container_of(core_vdev, struct vfio_pci_device, vdev); + struct vfio_pci_core_device *vdev = + container_of(core_vdev, struct vfio_pci_core_device, vdev); if (!count) return 0; @@ -1419,7 +1419,7 @@ static ssize_t vfio_pci_write(struct vfio_device *core_vdev, const char __user * } /* Return 1 on zap and vma_lock acquired, 0 on contention (only with @try) */ -static int vfio_pci_zap_and_vma_lock(struct vfio_pci_device *vdev, bool try) +static int vfio_pci_zap_and_vma_lock(struct vfio_pci_core_device *vdev, bool try) { struct vfio_pci_mmap_vma *mmap_vma, *tmp; @@ -1507,14 +1507,14 @@ static int vfio_pci_zap_and_vma_lock(struct vfio_pci_device *vdev, bool try) } } -void vfio_pci_zap_and_down_write_memory_lock(struct vfio_pci_device *vdev) +void vfio_pci_zap_and_down_write_memory_lock(struct vfio_pci_core_device *vdev) { vfio_pci_zap_and_vma_lock(vdev, false); down_write(&vdev->memory_lock); mutex_unlock(&vdev->vma_lock); } -u16 vfio_pci_memory_lock_and_enable(struct vfio_pci_device *vdev) +u16 vfio_pci_memory_lock_and_enable(struct vfio_pci_core_device *vdev) { u16 cmd; @@ -1527,14 +1527,14 @@ u16 vfio_pci_memory_lock_and_enable(struct vfio_pci_device *vdev) return cmd; } -void vfio_pci_memory_unlock_and_restore(struct vfio_pci_device *vdev, u16 cmd) +void vfio_pci_memory_unlock_and_restore(struct vfio_pci_core_device *vdev, u16 cmd) { pci_write_config_word(vdev->pdev, PCI_COMMAND, cmd); up_write(&vdev->memory_lock); } /* Caller holds vma_lock */ -static int __vfio_pci_add_vma(struct vfio_pci_device *vdev, +static int __vfio_pci_add_vma(struct vfio_pci_core_device *vdev, struct vm_area_struct *vma) { struct vfio_pci_mmap_vma *mmap_vma; @@ -1560,7 +1560,7 @@ static void vfio_pci_mmap_open(struct vm_area_struct *vma) static void vfio_pci_mmap_close(struct vm_area_struct *vma) { - struct vfio_pci_device *vdev = vma->vm_private_data; + struct vfio_pci_core_device *vdev = vma->vm_private_data; struct vfio_pci_mmap_vma *mmap_vma; mutex_lock(&vdev->vma_lock); @@ -1577,7 +1577,7 @@ static void vfio_pci_mmap_close(struct vm_area_struct *vma) static vm_fault_t vfio_pci_mmap_fault(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; - struct vfio_pci_device *vdev = vma->vm_private_data; + struct vfio_pci_core_device *vdev = vma->vm_private_data; vm_fault_t ret = VM_FAULT_NOPAGE; mutex_lock(&vdev->vma_lock); @@ -1614,8 +1614,8 @@ static const struct vm_operations_struct vfio_pci_mmap_ops = { static int vfio_pci_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma) { - struct vfio_pci_device *vdev = - container_of(core_vdev, struct vfio_pci_device, vdev); + struct vfio_pci_core_device *vdev = + container_of(core_vdev, struct vfio_pci_core_device, vdev); struct pci_dev *pdev = vdev->pdev; unsigned int index; u64 phys_len, req_len, pgoff, req_start; @@ -1685,8 +1685,8 @@ static int vfio_pci_mmap(struct vfio_device *core_vdev, struct vm_area_struct *v static void vfio_pci_request(struct vfio_device *core_vdev, unsigned int count) { - struct vfio_pci_device *vdev = - container_of(core_vdev, struct vfio_pci_device, vdev); + struct vfio_pci_core_device *vdev = + container_of(core_vdev, struct vfio_pci_core_device, vdev); struct pci_dev *pdev = vdev->pdev; mutex_lock(&vdev->igate); @@ -1705,7 +1705,7 @@ static void vfio_pci_request(struct vfio_device *core_vdev, unsigned int count) mutex_unlock(&vdev->igate); } -static int vfio_pci_validate_vf_token(struct vfio_pci_device *vdev, +static int vfio_pci_validate_vf_token(struct vfio_pci_core_device *vdev, bool vf_token, uuid_t *uuid) { /* @@ -1737,7 +1737,7 @@ static int vfio_pci_validate_vf_token(struct vfio_pci_device *vdev, return 0; /* No VF token provided or required */ if (vdev->pdev->is_virtfn) { - struct vfio_pci_device *pf_vdev = get_pf_vdev(vdev); + struct vfio_pci_core_device *pf_vdev = get_pf_vdev(vdev); bool match; if (!pf_vdev) { @@ -1801,8 +1801,8 @@ static int vfio_pci_validate_vf_token(struct vfio_pci_device *vdev, static int vfio_pci_match(struct vfio_device *core_vdev, char *buf) { - struct vfio_pci_device *vdev = - container_of(core_vdev, struct vfio_pci_device, vdev); + struct vfio_pci_core_device *vdev = + container_of(core_vdev, struct vfio_pci_core_device, vdev); bool vf_token = false; uuid_t uuid; int ret; @@ -1876,8 +1876,8 @@ static int vfio_pci_reflck_find(struct pci_dev *pdev, void *data) static int vfio_pci_reflck_attach(struct vfio_device *core_vdev) { - struct vfio_pci_device *vdev = - container_of(core_vdev, struct vfio_pci_device, vdev); + struct vfio_pci_core_device *vdev = + container_of(core_vdev, struct vfio_pci_core_device, vdev); bool slot = !pci_probe_reset_slot(vdev->pdev->slot); if (pci_is_root_bus(vdev->pdev->bus) || @@ -1904,8 +1904,8 @@ static const struct vfio_device_ops vfio_pci_ops = { static int vfio_pci_bus_notifier(struct notifier_block *nb, unsigned long action, void *data) { - struct vfio_pci_device *vdev = container_of(nb, - struct vfio_pci_device, nb); + struct vfio_pci_core_device *vdev = container_of(nb, + struct vfio_pci_core_device, nb); struct device *dev = data; struct pci_dev *pdev = to_pci_dev(dev); struct pci_dev *physfn = pci_physfn(pdev); @@ -1929,7 +1929,7 @@ static int vfio_pci_bus_notifier(struct notifier_block *nb, return 0; } -static int vfio_pci_vf_init(struct vfio_pci_device *vdev) +static int vfio_pci_vf_init(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev = vdev->pdev; int ret; @@ -1953,7 +1953,7 @@ static int vfio_pci_vf_init(struct vfio_pci_device *vdev) return 0; } -static void vfio_pci_vf_uninit(struct vfio_pci_device *vdev) +static void vfio_pci_vf_uninit(struct vfio_pci_core_device *vdev) { if (!vdev->vf_token) return; @@ -1964,7 +1964,7 @@ static void vfio_pci_vf_uninit(struct vfio_pci_device *vdev) kfree(vdev->vf_token); } -static int vfio_pci_vga_init(struct vfio_pci_device *vdev) +static int vfio_pci_vga_init(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev = vdev->pdev; int ret; @@ -1979,7 +1979,7 @@ static int vfio_pci_vga_init(struct vfio_pci_device *vdev) return 0; } -static void vfio_pci_vga_uninit(struct vfio_pci_device *vdev) +static void vfio_pci_vga_uninit(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev = vdev->pdev; @@ -1993,7 +1993,7 @@ static void vfio_pci_vga_uninit(struct vfio_pci_device *vdev) static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) { - struct vfio_pci_device *vdev; + struct vfio_pci_core_device *vdev; struct iommu_group *group; int ret; @@ -2086,7 +2086,7 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) static void vfio_pci_remove(struct pci_dev *pdev) { - struct vfio_pci_device *vdev = dev_get_drvdata(&pdev->dev); + struct vfio_pci_core_device *vdev = dev_get_drvdata(&pdev->dev); pci_disable_sriov(pdev); @@ -2110,14 +2110,14 @@ static void vfio_pci_remove(struct pci_dev *pdev) static pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev, pci_channel_state_t state) { - struct vfio_pci_device *vdev; + struct vfio_pci_core_device *vdev; struct vfio_device *device; device = vfio_device_get_from_dev(&pdev->dev); if (device == NULL) return PCI_ERS_RESULT_DISCONNECT; - vdev = container_of(device, struct vfio_pci_device, vdev); + vdev = container_of(device, struct vfio_pci_core_device, vdev); mutex_lock(&vdev->igate); @@ -2172,7 +2172,7 @@ static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data) { struct vfio_devices *devs = data; struct vfio_device *device; - struct vfio_pci_device *vdev; + struct vfio_pci_core_device *vdev; if (devs->cur_index == devs->max_index) return -ENOSPC; @@ -2186,7 +2186,7 @@ static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data) return -EBUSY; } - vdev = container_of(device, struct vfio_pci_device, vdev); + vdev = container_of(device, struct vfio_pci_core_device, vdev); /* Fault if the device is not unused */ if (device->refcnt) { @@ -2202,7 +2202,7 @@ static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data) { struct vfio_devices *devs = data; struct vfio_device *device; - struct vfio_pci_device *vdev; + struct vfio_pci_core_device *vdev; if (devs->cur_index == devs->max_index) return -ENOSPC; @@ -2216,7 +2216,7 @@ static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data) return -EBUSY; } - vdev = container_of(device, struct vfio_pci_device, vdev); + vdev = container_of(device, struct vfio_pci_core_device, vdev); /* * Locking multiple devices is prone to deadlock, runaway and @@ -2247,12 +2247,12 @@ static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data) * to be bound to vfio_pci since that's the only way we can be sure they * stay put. */ -static void vfio_pci_try_bus_reset(struct vfio_pci_device *vdev) +static void vfio_pci_try_bus_reset(struct vfio_pci_core_device *vdev) { struct vfio_devices devs = { .cur_index = 0 }; int i = 0, ret = -EINVAL; bool slot = false; - struct vfio_pci_device *tmp; + struct vfio_pci_core_device *tmp; if (!pci_probe_reset_slot(vdev->pdev->slot)) slot = true; diff --git a/drivers/vfio/pci/vfio_pci_core.h b/drivers/vfio/pci/vfio_pci_core.h index b73abba881e9..9aa558672b83 100644 --- a/drivers/vfio/pci/vfio_pci_core.h +++ b/drivers/vfio/pci/vfio_pci_core.h @@ -33,7 +33,7 @@ struct vfio_pci_ioeventfd { struct list_head next; - struct vfio_pci_device *vdev; + struct vfio_pci_core_device *vdev; struct virqfd *virqfd; void __iomem *addr; uint64_t data; @@ -52,18 +52,18 @@ struct vfio_pci_irq_ctx { struct irq_bypass_producer producer; }; -struct vfio_pci_device; +struct vfio_pci_core_device; struct vfio_pci_region; struct vfio_pci_regops { - size_t (*rw)(struct vfio_pci_device *vdev, char __user *buf, + size_t (*rw)(struct vfio_pci_core_device *vdev, char __user *buf, size_t count, loff_t *ppos, bool iswrite); - void (*release)(struct vfio_pci_device *vdev, + void (*release)(struct vfio_pci_core_device *vdev, struct vfio_pci_region *region); - int (*mmap)(struct vfio_pci_device *vdev, + int (*mmap)(struct vfio_pci_core_device *vdev, struct vfio_pci_region *region, struct vm_area_struct *vma); - int (*add_capability)(struct vfio_pci_device *vdev, + int (*add_capability)(struct vfio_pci_core_device *vdev, struct vfio_pci_region *region, struct vfio_info_cap *caps); }; @@ -94,7 +94,7 @@ struct vfio_pci_mmap_vma { struct list_head vma_next; }; -struct vfio_pci_device { +struct vfio_pci_core_device { struct vfio_device vdev; struct pci_dev *pdev; void __iomem *barmap[PCI_STD_NUM_BARS]; @@ -144,61 +144,61 @@ struct vfio_pci_device { #define is_irq_none(vdev) (!(is_intx(vdev) || is_msi(vdev) || is_msix(vdev))) #define irq_is(vdev, type) (vdev->irq_type == type) -extern void vfio_pci_intx_mask(struct vfio_pci_device *vdev); -extern void vfio_pci_intx_unmask(struct vfio_pci_device *vdev); +extern void vfio_pci_intx_mask(struct vfio_pci_core_device *vdev); +extern void vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev); -extern int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev, +extern int vfio_pci_set_irqs_ioctl(struct vfio_pci_core_device *vdev, uint32_t flags, unsigned index, unsigned start, unsigned count, void *data); -extern ssize_t vfio_pci_config_rw(struct vfio_pci_device *vdev, +extern ssize_t vfio_pci_config_rw(struct vfio_pci_core_device *vdev, char __user *buf, size_t count, loff_t *ppos, bool iswrite); -extern ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf, +extern ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf, size_t count, loff_t *ppos, bool iswrite); -extern ssize_t vfio_pci_vga_rw(struct vfio_pci_device *vdev, char __user *buf, +extern ssize_t vfio_pci_vga_rw(struct vfio_pci_core_device *vdev, char __user *buf, size_t count, loff_t *ppos, bool iswrite); -extern long vfio_pci_ioeventfd(struct vfio_pci_device *vdev, loff_t offset, +extern long vfio_pci_ioeventfd(struct vfio_pci_core_device *vdev, loff_t offset, uint64_t data, int count, int fd); extern int vfio_pci_init_perm_bits(void); extern void vfio_pci_uninit_perm_bits(void); -extern int vfio_config_init(struct vfio_pci_device *vdev); -extern void vfio_config_free(struct vfio_pci_device *vdev); +extern int vfio_config_init(struct vfio_pci_core_device *vdev); +extern void vfio_config_free(struct vfio_pci_core_device *vdev); -extern int vfio_pci_register_dev_region(struct vfio_pci_device *vdev, +extern int vfio_pci_register_dev_region(struct vfio_pci_core_device *vdev, unsigned int type, unsigned int subtype, const struct vfio_pci_regops *ops, size_t size, u32 flags, void *data); -extern int vfio_pci_set_power_state(struct vfio_pci_device *vdev, +extern int vfio_pci_set_power_state(struct vfio_pci_core_device *vdev, pci_power_t state); -extern bool __vfio_pci_memory_enabled(struct vfio_pci_device *vdev); -extern void vfio_pci_zap_and_down_write_memory_lock(struct vfio_pci_device +extern bool __vfio_pci_memory_enabled(struct vfio_pci_core_device *vdev); +extern void vfio_pci_zap_and_down_write_memory_lock(struct vfio_pci_core_device *vdev); -extern u16 vfio_pci_memory_lock_and_enable(struct vfio_pci_device *vdev); -extern void vfio_pci_memory_unlock_and_restore(struct vfio_pci_device *vdev, +extern u16 vfio_pci_memory_lock_and_enable(struct vfio_pci_core_device *vdev); +extern void vfio_pci_memory_unlock_and_restore(struct vfio_pci_core_device *vdev, u16 cmd); #ifdef CONFIG_VFIO_PCI_IGD -extern int vfio_pci_igd_init(struct vfio_pci_device *vdev); +extern int vfio_pci_igd_init(struct vfio_pci_core_device *vdev); #else -static inline int vfio_pci_igd_init(struct vfio_pci_device *vdev) +static inline int vfio_pci_igd_init(struct vfio_pci_core_device *vdev) { return -ENODEV; } #endif #ifdef CONFIG_S390 -extern int vfio_pci_info_zdev_add_caps(struct vfio_pci_device *vdev, +extern int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, struct vfio_info_cap *caps); #else -static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_device *vdev, +static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, struct vfio_info_cap *caps) { return -ENODEV; diff --git a/drivers/vfio/pci/vfio_pci_igd.c b/drivers/vfio/pci/vfio_pci_igd.c index 214b6d629b21..2295eaac4bc9 100644 --- a/drivers/vfio/pci/vfio_pci_igd.c +++ b/drivers/vfio/pci/vfio_pci_igd.c @@ -25,7 +25,7 @@ #define OPREGION_RVDS 0x3c2 #define OPREGION_VERSION 0x16 -static size_t vfio_pci_igd_rw(struct vfio_pci_device *vdev, char __user *buf, +static size_t vfio_pci_igd_rw(struct vfio_pci_core_device *vdev, char __user *buf, size_t count, loff_t *ppos, bool iswrite) { unsigned int i = VFIO_PCI_OFFSET_TO_INDEX(*ppos) - VFIO_PCI_NUM_REGIONS; @@ -45,7 +45,7 @@ static size_t vfio_pci_igd_rw(struct vfio_pci_device *vdev, char __user *buf, return count; } -static void vfio_pci_igd_release(struct vfio_pci_device *vdev, +static void vfio_pci_igd_release(struct vfio_pci_core_device *vdev, struct vfio_pci_region *region) { memunmap(region->data); @@ -56,7 +56,7 @@ static const struct vfio_pci_regops vfio_pci_igd_regops = { .release = vfio_pci_igd_release, }; -static int vfio_pci_igd_opregion_init(struct vfio_pci_device *vdev) +static int vfio_pci_igd_opregion_init(struct vfio_pci_core_device *vdev) { __le32 *dwordp = (__le32 *)(vdev->vconfig + OPREGION_PCI_ADDR); u32 addr, size; @@ -160,7 +160,7 @@ static int vfio_pci_igd_opregion_init(struct vfio_pci_device *vdev) return ret; } -static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev, +static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_core_device *vdev, char __user *buf, size_t count, loff_t *ppos, bool iswrite) { @@ -253,7 +253,7 @@ static size_t vfio_pci_igd_cfg_rw(struct vfio_pci_device *vdev, return count; } -static void vfio_pci_igd_cfg_release(struct vfio_pci_device *vdev, +static void vfio_pci_igd_cfg_release(struct vfio_pci_core_device *vdev, struct vfio_pci_region *region) { struct pci_dev *pdev = region->data; @@ -266,7 +266,7 @@ static const struct vfio_pci_regops vfio_pci_igd_cfg_regops = { .release = vfio_pci_igd_cfg_release, }; -static int vfio_pci_igd_cfg_init(struct vfio_pci_device *vdev) +static int vfio_pci_igd_cfg_init(struct vfio_pci_core_device *vdev) { struct pci_dev *host_bridge, *lpc_bridge; int ret; @@ -314,7 +314,7 @@ static int vfio_pci_igd_cfg_init(struct vfio_pci_device *vdev) return 0; } -int vfio_pci_igd_init(struct vfio_pci_device *vdev) +int vfio_pci_igd_init(struct vfio_pci_core_device *vdev) { int ret; diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index df1e8c8c274c..945ddbdf4d11 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -27,13 +27,13 @@ */ static void vfio_send_intx_eventfd(void *opaque, void *unused) { - struct vfio_pci_device *vdev = opaque; + struct vfio_pci_core_device *vdev = opaque; if (likely(is_intx(vdev) && !vdev->virq_disabled)) eventfd_signal(vdev->ctx[0].trigger, 1); } -void vfio_pci_intx_mask(struct vfio_pci_device *vdev) +void vfio_pci_intx_mask(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev = vdev->pdev; unsigned long flags; @@ -73,7 +73,7 @@ void vfio_pci_intx_mask(struct vfio_pci_device *vdev) */ static int vfio_pci_intx_unmask_handler(void *opaque, void *unused) { - struct vfio_pci_device *vdev = opaque; + struct vfio_pci_core_device *vdev = opaque; struct pci_dev *pdev = vdev->pdev; unsigned long flags; int ret = 0; @@ -107,7 +107,7 @@ static int vfio_pci_intx_unmask_handler(void *opaque, void *unused) return ret; } -void vfio_pci_intx_unmask(struct vfio_pci_device *vdev) +void vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev) { if (vfio_pci_intx_unmask_handler(vdev, NULL) > 0) vfio_send_intx_eventfd(vdev, NULL); @@ -115,7 +115,7 @@ void vfio_pci_intx_unmask(struct vfio_pci_device *vdev) static irqreturn_t vfio_intx_handler(int irq, void *dev_id) { - struct vfio_pci_device *vdev = dev_id; + struct vfio_pci_core_device *vdev = dev_id; unsigned long flags; int ret = IRQ_NONE; @@ -139,7 +139,7 @@ static irqreturn_t vfio_intx_handler(int irq, void *dev_id) return ret; } -static int vfio_intx_enable(struct vfio_pci_device *vdev) +static int vfio_intx_enable(struct vfio_pci_core_device *vdev) { if (!is_irq_none(vdev)) return -EINVAL; @@ -168,7 +168,7 @@ static int vfio_intx_enable(struct vfio_pci_device *vdev) return 0; } -static int vfio_intx_set_signal(struct vfio_pci_device *vdev, int fd) +static int vfio_intx_set_signal(struct vfio_pci_core_device *vdev, int fd) { struct pci_dev *pdev = vdev->pdev; unsigned long irqflags = IRQF_SHARED; @@ -223,7 +223,7 @@ static int vfio_intx_set_signal(struct vfio_pci_device *vdev, int fd) return 0; } -static void vfio_intx_disable(struct vfio_pci_device *vdev) +static void vfio_intx_disable(struct vfio_pci_core_device *vdev) { vfio_virqfd_disable(&vdev->ctx[0].unmask); vfio_virqfd_disable(&vdev->ctx[0].mask); @@ -244,7 +244,7 @@ static irqreturn_t vfio_msihandler(int irq, void *arg) return IRQ_HANDLED; } -static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix) +static int vfio_msi_enable(struct vfio_pci_core_device *vdev, int nvec, bool msix) { struct pci_dev *pdev = vdev->pdev; unsigned int flag = msix ? PCI_IRQ_MSIX : PCI_IRQ_MSI; @@ -285,7 +285,7 @@ static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix) return 0; } -static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev, +static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, int vector, int fd, bool msix) { struct pci_dev *pdev = vdev->pdev; @@ -364,7 +364,7 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev, return 0; } -static int vfio_msi_set_block(struct vfio_pci_device *vdev, unsigned start, +static int vfio_msi_set_block(struct vfio_pci_core_device *vdev, unsigned start, unsigned count, int32_t *fds, bool msix) { int i, j, ret = 0; @@ -385,7 +385,7 @@ static int vfio_msi_set_block(struct vfio_pci_device *vdev, unsigned start, return ret; } -static void vfio_msi_disable(struct vfio_pci_device *vdev, bool msix) +static void vfio_msi_disable(struct vfio_pci_core_device *vdev, bool msix) { struct pci_dev *pdev = vdev->pdev; int i; @@ -417,7 +417,7 @@ static void vfio_msi_disable(struct vfio_pci_device *vdev, bool msix) /* * IOCTL support */ -static int vfio_pci_set_intx_unmask(struct vfio_pci_device *vdev, +static int vfio_pci_set_intx_unmask(struct vfio_pci_core_device *vdev, unsigned index, unsigned start, unsigned count, uint32_t flags, void *data) { @@ -444,7 +444,7 @@ static int vfio_pci_set_intx_unmask(struct vfio_pci_device *vdev, return 0; } -static int vfio_pci_set_intx_mask(struct vfio_pci_device *vdev, +static int vfio_pci_set_intx_mask(struct vfio_pci_core_device *vdev, unsigned index, unsigned start, unsigned count, uint32_t flags, void *data) { @@ -464,7 +464,7 @@ static int vfio_pci_set_intx_mask(struct vfio_pci_device *vdev, return 0; } -static int vfio_pci_set_intx_trigger(struct vfio_pci_device *vdev, +static int vfio_pci_set_intx_trigger(struct vfio_pci_core_device *vdev, unsigned index, unsigned start, unsigned count, uint32_t flags, void *data) { @@ -507,7 +507,7 @@ static int vfio_pci_set_intx_trigger(struct vfio_pci_device *vdev, return 0; } -static int vfio_pci_set_msi_trigger(struct vfio_pci_device *vdev, +static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev, unsigned index, unsigned start, unsigned count, uint32_t flags, void *data) { @@ -613,7 +613,7 @@ static int vfio_pci_set_ctx_trigger_single(struct eventfd_ctx **ctx, return -EINVAL; } -static int vfio_pci_set_err_trigger(struct vfio_pci_device *vdev, +static int vfio_pci_set_err_trigger(struct vfio_pci_core_device *vdev, unsigned index, unsigned start, unsigned count, uint32_t flags, void *data) { @@ -624,7 +624,7 @@ static int vfio_pci_set_err_trigger(struct vfio_pci_device *vdev, count, flags, data); } -static int vfio_pci_set_req_trigger(struct vfio_pci_device *vdev, +static int vfio_pci_set_req_trigger(struct vfio_pci_core_device *vdev, unsigned index, unsigned start, unsigned count, uint32_t flags, void *data) { @@ -635,11 +635,11 @@ static int vfio_pci_set_req_trigger(struct vfio_pci_device *vdev, count, flags, data); } -int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev, uint32_t flags, +int vfio_pci_set_irqs_ioctl(struct vfio_pci_core_device *vdev, uint32_t flags, unsigned index, unsigned start, unsigned count, void *data) { - int (*func)(struct vfio_pci_device *vdev, unsigned index, + int (*func)(struct vfio_pci_core_device *vdev, unsigned index, unsigned start, unsigned count, uint32_t flags, void *data) = NULL; diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c index 667e82726e75..8fff4689dd44 100644 --- a/drivers/vfio/pci/vfio_pci_rdwr.c +++ b/drivers/vfio/pci/vfio_pci_rdwr.c @@ -38,7 +38,7 @@ #define vfio_iowrite8 iowrite8 #define VFIO_IOWRITE(size) \ -static int vfio_pci_iowrite##size(struct vfio_pci_device *vdev, \ +static int vfio_pci_iowrite##size(struct vfio_pci_core_device *vdev, \ bool test_mem, u##size val, void __iomem *io) \ { \ if (test_mem) { \ @@ -65,7 +65,7 @@ VFIO_IOWRITE(64) #endif #define VFIO_IOREAD(size) \ -static int vfio_pci_ioread##size(struct vfio_pci_device *vdev, \ +static int vfio_pci_ioread##size(struct vfio_pci_core_device *vdev, \ bool test_mem, u##size *val, void __iomem *io) \ { \ if (test_mem) { \ @@ -94,7 +94,7 @@ VFIO_IOREAD(32) * reads with -1. This is intended for handling MSI-X vector tables and * leftover space for ROM BARs. */ -static ssize_t do_io_rw(struct vfio_pci_device *vdev, bool test_mem, +static ssize_t do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem, void __iomem *io, char __user *buf, loff_t off, size_t count, size_t x_start, size_t x_end, bool iswrite) @@ -200,7 +200,7 @@ static ssize_t do_io_rw(struct vfio_pci_device *vdev, bool test_mem, return done; } -static int vfio_pci_setup_barmap(struct vfio_pci_device *vdev, int bar) +static int vfio_pci_setup_barmap(struct vfio_pci_core_device *vdev, int bar) { struct pci_dev *pdev = vdev->pdev; int ret; @@ -224,7 +224,7 @@ static int vfio_pci_setup_barmap(struct vfio_pci_device *vdev, int bar) return 0; } -ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf, +ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf, size_t count, loff_t *ppos, bool iswrite) { struct pci_dev *pdev = vdev->pdev; @@ -288,7 +288,7 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf, return done; } -ssize_t vfio_pci_vga_rw(struct vfio_pci_device *vdev, char __user *buf, +ssize_t vfio_pci_vga_rw(struct vfio_pci_core_device *vdev, char __user *buf, size_t count, loff_t *ppos, bool iswrite) { int ret; @@ -384,7 +384,7 @@ static void vfio_pci_ioeventfd_do_write(struct vfio_pci_ioeventfd *ioeventfd, static int vfio_pci_ioeventfd_handler(void *opaque, void *unused) { struct vfio_pci_ioeventfd *ioeventfd = opaque; - struct vfio_pci_device *vdev = ioeventfd->vdev; + struct vfio_pci_core_device *vdev = ioeventfd->vdev; if (ioeventfd->test_mem) { if (!down_read_trylock(&vdev->memory_lock)) @@ -410,7 +410,7 @@ static void vfio_pci_ioeventfd_thread(void *opaque, void *unused) vfio_pci_ioeventfd_do_write(ioeventfd, ioeventfd->test_mem); } -long vfio_pci_ioeventfd(struct vfio_pci_device *vdev, loff_t offset, +long vfio_pci_ioeventfd(struct vfio_pci_core_device *vdev, loff_t offset, uint64_t data, int count, int fd) { struct pci_dev *pdev = vdev->pdev; diff --git a/drivers/vfio/pci/vfio_pci_zdev.c b/drivers/vfio/pci/vfio_pci_zdev.c index ecae0c3d95a0..2ffbdc11f089 100644 --- a/drivers/vfio/pci/vfio_pci_zdev.c +++ b/drivers/vfio/pci/vfio_pci_zdev.c @@ -114,7 +114,7 @@ static int zpci_pfip_cap(struct zpci_dev *zdev, struct vfio_info_cap *caps) /* * Add all supported capabilities to the VFIO_DEVICE_GET_INFO capability chain. */ -int vfio_pci_info_zdev_add_caps(struct vfio_pci_device *vdev, +int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, struct vfio_info_cap *caps) { struct zpci_dev *zdev = to_zpci(vdev->pdev); From patchwork Thu Jun 3 16:08:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Gurtovoy X-Patchwork-Id: 12297527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AD1AC47082 for ; Thu, 3 Jun 2021 16:08:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E1CD6121D for ; Thu, 3 Jun 2021 16:08:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230094AbhFCQK1 (ORCPT ); Thu, 3 Jun 2021 12:10:27 -0400 Received: from mail-co1nam11on2040.outbound.protection.outlook.com ([40.107.220.40]:13440 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230022AbhFCQKZ (ORCPT ); Thu, 3 Jun 2021 12:10:25 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PdOL5DefL6nqzsYdEmYX2clDeqIM1J3g5ZaPHR/Fl9GKon938WMuejotQbCaXWEC4RbDd6UELQdh+ufPwj3ZLEY6ASM3V5VewpIziqdpkCnwD1LIz8C0/h8d5MRiwLb6BYY84NwJk8ktrDFdXEmUnMmytZb9qJYQe84RhEiQa4SdxNwnSZcSqN72lUN9cq+VZZhARznOOArn8bsQGdQeJkvzj2rpoNdwza9APU13IySs/GYswxgkvK895pn80Lomsxr0/0trWc+7+0mAc0JEdLe8Xui0eYBvbBBi/j2UUXESAPoKB16Mfa+f4J6YNsdpgu9+elyVPI5r1Dgf7TJz7w== 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-SenderADCheck; bh=8C9U6RTln0jtK1b/i+9I7vpdJgGLcvqg9uCg+rFw2Ec=; b=kTysWUCdNICenDfmLnD4agUUANsSnb7G10ecbtaqiNnvwirLsKroBpbINcMPRCiQtw9KOUxVy6LyEYsSj8fVlVHU4XazMPAfZ9snKlT51YRGDjm+tVqiJPQubSqID5/V8NmoVMCdRPYQ+meDPoTGfHFZUZ94eoflT34IweUodoKqSa8MOnj3CAsiuzH+muFtKm1k7YHCEfQ6cIxcoQtUzWfhXYwCMNtF8sUppaPTCFEwDouXA28J8F/UhaWd1Si2IPl9Bx1QjPiv3a3LW0+B9yPe9n2kJlh4JH1wUWbomTfRy9Tp+ntdEFNLhOVvSmWQyK+XJV5QErf8npjvpoTfQA== 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=none sp=none 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=8C9U6RTln0jtK1b/i+9I7vpdJgGLcvqg9uCg+rFw2Ec=; b=rO/3Aeky9hRusgtt2KGJplPrbNn6HWngU0vfa5Z4zRiInCrW8UzXmRxozII46SPFgvGWGAbbKDOEh57WsyKCLM0O9uAY5u5KaRiqUMACZ2wCrM/iXPFSZgny/7l1Xnp25VWqAB9WTvH2EkD4gGyeasSlEbdKm3xpp6uPyrF4J6qwSxQ43g2GehrNjw4/rsvnGHcePuT1Kg0hSsW/PiUhpmcuhyUxTJwlzqGqE9fdC269ZVGgsozueS0NwnMZFeGl/f17XILpuUmyfWg0I9zF5Vh7qqA8DERzx+WCe+cNMUzTjrDXW7OOapSeXuRIWIj26QipV8l635LqxAH6KsSz5Q== Received: from CO1PR15CA0080.namprd15.prod.outlook.com (2603:10b6:101:20::24) by DM6PR12MB2793.namprd12.prod.outlook.com (2603:10b6:5:4f::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.29; Thu, 3 Jun 2021 16:08:37 +0000 Received: from CO1NAM11FT017.eop-nam11.prod.protection.outlook.com (2603:10b6:101:20:cafe::e1) by CO1PR15CA0080.outlook.office365.com (2603:10b6:101:20::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.21 via Frontend Transport; Thu, 3 Jun 2021 16:08:37 +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 CO1NAM11FT017.mail.protection.outlook.com (10.13.175.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4195.22 via Frontend Transport; Thu, 3 Jun 2021 16:08:37 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 3 Jun 2021 16:08:36 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 3 Jun 2021 16:08:36 +0000 Received: from r-arch-stor02.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 3 Jun 2021 16:08:31 +0000 From: Max Gurtovoy To: , , , , CC: , , , , , , , , , , , , , , , Max Gurtovoy Subject: [PATCH 04/11] vfio-pci: rename ops functions to fit core namings Date: Thu, 3 Jun 2021 19:08:02 +0300 Message-ID: <20210603160809.15845-5-mgurtovoy@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210603160809.15845-1-mgurtovoy@nvidia.com> References: <20210603160809.15845-1-mgurtovoy@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b5decf16-f7aa-4809-0097-08d926a9d867 X-MS-TrafficTypeDiagnostic: DM6PR12MB2793: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2958; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0gAVHt2kBOS3gSjoWCAks9vE3j9Y+h8NoTckpK22C16P9kk8wJRHZ67lOVxDCaNfxW47w1tLvYX6m5K2KPVLgV8+aZ6hGJYqFSafm2PURVmT3gCsGFy3hpxqQq0cTxD8S2b7J17r/j5ugc+ku4gWa9URatogMm5210MXXmEWShhLCZWD9wV6I/xljFBJIF1tvTQo5/EecGlsVTRB3SHjoauiAgqewjUgMDeecwCydHCjLR8JyeJZaFRNz28mPFl83MG2Am6iI4NDTn6q/tCpsye8ps4Sx4rC3HPPJR+Lu2zSo0uO6DNPnn2Ukk5jWU/N7AUu5DZeIIHgzLP5gKyxe9zuB9hWqQlr137BQu+0bgb+naDl9duSMyoOI7g3HKT94bpYboHEve180Rpi3IGPcuT5rXasBvLqZ4xVXljf21mFJnGu8UYNWvps/iOhczxC7m0eHRxOxECkAQyol+OlAzq5lLtojXEy8coFFMZWiSTiT60mHzf498jGOLIf9YqFxj8bTjVhQePptlhFRmL5gnZtVxuHYlv/M4vW2wnEtRfvOky7p5VX1783J3LilbpNvB+ptsgV9oUFmOLqYIjZGOedxnvaYos3CHWOps17uRbpA7GxYhvAZFne9Fa98rM4rEZBJO68wCHiSo/VJI8uOCk9rBuusYqw8xnx2zsUlX4= 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)(376002)(39860400002)(136003)(346002)(396003)(46966006)(36840700001)(4326008)(36860700001)(26005)(8936002)(70586007)(110136005)(54906003)(356005)(8676002)(82740400003)(2616005)(336012)(6666004)(7636003)(1076003)(70206006)(47076005)(82310400003)(6636002)(5660300002)(36756003)(83380400001)(36906005)(478600001)(316002)(107886003)(426003)(86362001)(2906002)(186003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2021 16:08:37.0813 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b5decf16-f7aa-4809-0097-08d926a9d867 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: CO1NAM11FT017.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2793 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is another preparation patch for separating the vfio_pci driver to a subsystem driver and a generic pci driver. This patch doesn't change any logic. Signed-off-by: Max Gurtovoy --- drivers/vfio/pci/vfio_pci_core.c | 36 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index a6a9d1aaa185..2d2fa64cc8a0 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -533,7 +533,7 @@ static void vfio_pci_vf_token_user_add(struct vfio_pci_core_device *vdev, int va vfio_device_put(&pf_vdev->vdev); } -static void vfio_pci_release(struct vfio_device *core_vdev) +static void vfio_pci_core_release(struct vfio_device *core_vdev) { struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev); @@ -556,7 +556,7 @@ static void vfio_pci_release(struct vfio_device *core_vdev) mutex_unlock(&vdev->igate); } -static int vfio_pci_open(struct vfio_device *core_vdev) +static int vfio_pci_core_open(struct vfio_device *core_vdev) { struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev); @@ -763,7 +763,7 @@ struct vfio_devices { int max_index; }; -static long vfio_pci_ioctl(struct vfio_device *core_vdev, +static long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, unsigned long arg) { struct vfio_pci_core_device *vdev = @@ -1394,7 +1394,7 @@ static ssize_t vfio_pci_rw(struct vfio_pci_core_device *vdev, char __user *buf, return -EINVAL; } -static ssize_t vfio_pci_read(struct vfio_device *core_vdev, char __user *buf, +static ssize_t vfio_pci_core_read(struct vfio_device *core_vdev, char __user *buf, size_t count, loff_t *ppos) { struct vfio_pci_core_device *vdev = @@ -1406,7 +1406,7 @@ static ssize_t vfio_pci_read(struct vfio_device *core_vdev, char __user *buf, return vfio_pci_rw(vdev, buf, count, ppos, false); } -static ssize_t vfio_pci_write(struct vfio_device *core_vdev, const char __user *buf, +static ssize_t vfio_pci_core_write(struct vfio_device *core_vdev, const char __user *buf, size_t count, loff_t *ppos) { struct vfio_pci_core_device *vdev = @@ -1612,7 +1612,7 @@ static const struct vm_operations_struct vfio_pci_mmap_ops = { .fault = vfio_pci_mmap_fault, }; -static int vfio_pci_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma) +static int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma) { struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev); @@ -1683,7 +1683,7 @@ static int vfio_pci_mmap(struct vfio_device *core_vdev, struct vm_area_struct *v return 0; } -static void vfio_pci_request(struct vfio_device *core_vdev, unsigned int count) +static void vfio_pci_core_request(struct vfio_device *core_vdev, unsigned int count) { struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev); @@ -1799,7 +1799,7 @@ static int vfio_pci_validate_vf_token(struct vfio_pci_core_device *vdev, #define VF_TOKEN_ARG "vf_token=" -static int vfio_pci_match(struct vfio_device *core_vdev, char *buf) +static int vfio_pci_core_match(struct vfio_device *core_vdev, char *buf) { struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev); @@ -1874,7 +1874,7 @@ static int vfio_pci_reflck_find(struct pci_dev *pdev, void *data) return 0; } -static int vfio_pci_reflck_attach(struct vfio_device *core_vdev) +static int vfio_pci_core_reflck_attach(struct vfio_device *core_vdev) { struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev); @@ -1890,15 +1890,15 @@ static int vfio_pci_reflck_attach(struct vfio_device *core_vdev) static const struct vfio_device_ops vfio_pci_ops = { .name = "vfio-pci", - .open = vfio_pci_open, - .release = vfio_pci_release, - .ioctl = vfio_pci_ioctl, - .read = vfio_pci_read, - .write = vfio_pci_write, - .mmap = vfio_pci_mmap, - .request = vfio_pci_request, - .match = vfio_pci_match, - .reflck_attach = vfio_pci_reflck_attach, + .open = vfio_pci_core_open, + .release = vfio_pci_core_release, + .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, + .reflck_attach = vfio_pci_core_reflck_attach, }; static int vfio_pci_bus_notifier(struct notifier_block *nb, From patchwork Thu Jun 3 16:08:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Gurtovoy X-Patchwork-Id: 12297529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C09A7C47097 for ; Thu, 3 Jun 2021 16:08:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A613E613F8 for ; Thu, 3 Jun 2021 16:08:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230163AbhFCQKa (ORCPT ); Thu, 3 Jun 2021 12:10:30 -0400 Received: from mail-bn7nam10on2055.outbound.protection.outlook.com ([40.107.92.55]:28416 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230138AbhFCQK3 (ORCPT ); Thu, 3 Jun 2021 12:10:29 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fEvWKW43fawI4t4xAlTltv29NO6LzZIVfAq345y48DPfdXwF79VaJzSqwHe3gJPqijIteL4AYuWxI5Eeg9ARMrRnPt8Xf+Sh5911rSUiLia+SsumgQTd8k0NxfzjfI/Xcak9vbh1ZD4FaBwxHQrAGd74xMM1NWR9DZuHaFnUE23Ca6pgOpfHqJIFpUZL2FVhE+wQCjtUuIeCf8U+MP6Y2fdDoPTfRg4DOOTnD2J12XdKdx9PU+ArbmBPQoNS2PRBtZPbGmBzcTB05wZUYCsRdgOa8Ujchgz3WRhLemd9B/d9KSr827Ax635xCSAWzSymvI4LP70N+fCSF2fhC+omCg== 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-SenderADCheck; bh=XNNy0w3qmBeWzCWsJs7/vAbXPuVBX+0TqT6TMURXvTg=; b=m5NaU0bFQxMqJS2nDlBDlY+hH+LwDvmhOnakOqNohqm326LB32ofOqzinfmM644IZ2LQBqlHsfUF9MwXiDeuiKlTSQA7hX3Df7tdib/CKoT71XC6F+AwHvvrghEWOFwUJDOmaAtkLq1AW58StUkDUNjIQodptSZN9p04ifz6IntmO/2vHjhOIliKJKEJ4cfg0mJitW9pyVST9rZUJWs5QyJqWWYY2kXV8D4YgJez6F6dEzKy5BlZAfq70tEGdVIaMTfq6wDZC5Op5qXAsTstk0t/LPHHWmzF1P6aYyeWhQjNcef/lBZmKkziWogCKKPUo3nognmwf4JaEjdS4xzpkQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none 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=XNNy0w3qmBeWzCWsJs7/vAbXPuVBX+0TqT6TMURXvTg=; b=B89k9F3Qp4ylQIMBxF8rUpEK65+sO7mfpKFA16RlqteOBmaY97ahVTdUwV0hqsrr5G80j06VrJyUIk64k8svsWUGkZptUBmSwftnoBIJZYP6b3feA/mn8wokbQoMycM53Vj2358jbhmEyODwdOhVAdlBWU/t/gg9M3QA+ASwRD0nd2olyon40fjytmHrdKRVguu6toReX1/WqnklGkf6NdT9hcCqp0rIUuxh+9vTc3ozv0fIrR2F1mIB+RYQbmgV/5Eg2Tztlwa4JPI8ZD9W17p5MAKZCWeGdMmJsiXFk1v4grgesn2/U/5OakX/x5TWk3Tk4eIFfyLiMyEiaJ/+Sw== Received: from MWHPR04CA0026.namprd04.prod.outlook.com (2603:10b6:300:ee::12) by DM6PR12MB3275.namprd12.prod.outlook.com (2603:10b6:5:185::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.27; Thu, 3 Jun 2021 16:08:43 +0000 Received: from CO1NAM11FT042.eop-nam11.prod.protection.outlook.com (2603:10b6:300:ee:cafe::2b) by MWHPR04CA0026.outlook.office365.com (2603:10b6:300:ee::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.20 via Frontend Transport; Thu, 3 Jun 2021 16:08:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; huawei.com; dkim=none (message not signed) header.d=none;huawei.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 CO1NAM11FT042.mail.protection.outlook.com (10.13.174.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4195.22 via Frontend Transport; Thu, 3 Jun 2021 16:08:42 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 3 Jun 2021 16:08:41 +0000 Received: from r-arch-stor02.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 3 Jun 2021 16:08:36 +0000 From: Max Gurtovoy To: , , , , CC: , , , , , , , , , , , , , , , Max Gurtovoy Subject: [PATCH 05/11] vfio-pci: include vfio header in vfio_pci_core.h Date: Thu, 3 Jun 2021 19:08:03 +0300 Message-ID: <20210603160809.15845-6-mgurtovoy@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210603160809.15845-1-mgurtovoy@nvidia.com> References: <20210603160809.15845-1-mgurtovoy@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 937e99eb-8048-4a45-7270-08d926a9dbd3 X-MS-TrafficTypeDiagnostic: DM6PR12MB3275: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oLZ3XvRoO7LxfbkOnfXqH3i0+/wOi5fHh1CO187iR2EZchQOZnWP1KZnkP7nggW5k6zq+LLzijfeptMND43TRf/ZFC90yqWMVWubHa7WLMIQt+HeKy1lZS7zNlERGsZNS2RyYLdqKXJwmduEs/gJRICByiPG5rdyUcl5p0rdJx1gRxBoQkV3khvhlSYvT8xvdj4M3VYnfcWzGLTOAvJw291YkDEfAPg3K8zSpf+zShav/BIWGVZ6O86/JpmJhgZgFLVWJNP8BsBdzqV9DiBntMACM0LcwWljH/sjbPeOzEeu20f8lBClKrqyThAAReCtEGySx4u7IDISuirPj+jlftyncHEnLwe/iWUrCxFa9Cadatq1CKfYwb0Jmbq8wcUZF2qZfviT4BWqZsYP9FzM1rKi9enWAP9n0NWSzSNyWDcQ9lLPQ0yTY33qf4tZUj24wA9G9aUpriG4EUrnXnumeJTzz5Ljibul1SpqTtLKptD5jzPaDisK+sIAERvJ7OWa03ZJ+Im7EuMj35e+Bf8BsjO9OTv5p44A9BLSsiESpNUbB6JTHPhIV67Onn+UxGPQMm4DMYaqDy0kH1R2R8/AvzTM8DXX2koBOBI6PsKDM3sSxvUytWL5+OtYlWnYCJE7A7F9tHppslIuoWJA8BpYzg== 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)(346002)(376002)(39860400002)(396003)(136003)(36840700001)(46966006)(70206006)(336012)(70586007)(36860700001)(8936002)(26005)(54906003)(82740400003)(4326008)(186003)(316002)(5660300002)(8676002)(6636002)(86362001)(2906002)(356005)(47076005)(478600001)(7636003)(36756003)(2616005)(110136005)(426003)(1076003)(83380400001)(107886003)(6666004)(82310400003)(36906005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2021 16:08:42.7849 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 937e99eb-8048-4a45-7270-08d926a9dbd3 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: CO1NAM11FT042.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3275 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The vfio_device structure is embedded into the vfio_pci_core_device structure, so there is no reason for not including the header file in the vfio_pci_core header as well. Signed-off-by: Max Gurtovoy --- drivers/vfio/pci/vfio_pci_core.c | 1 - drivers/vfio/pci/vfio_pci_core.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 2d2fa64cc8a0..61cd785c80e8 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include diff --git a/drivers/vfio/pci/vfio_pci_core.h b/drivers/vfio/pci/vfio_pci_core.h index 9aa558672b83..cb24d229df66 100644 --- a/drivers/vfio/pci/vfio_pci_core.h +++ b/drivers/vfio/pci/vfio_pci_core.h @@ -10,6 +10,7 @@ #include #include +#include #include #include #include From patchwork Thu Jun 3 16:08:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Gurtovoy X-Patchwork-Id: 12297531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3559EC47096 for ; Thu, 3 Jun 2021 16:08:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1822A613E7 for ; Thu, 3 Jun 2021 16:08:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230227AbhFCQKg (ORCPT ); Thu, 3 Jun 2021 12:10:36 -0400 Received: from mail-mw2nam10on2060.outbound.protection.outlook.com ([40.107.94.60]:46017 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230097AbhFCQKf (ORCPT ); Thu, 3 Jun 2021 12:10:35 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ALZVoyZ1UFIHA5TBZlqL2NAfEDy0rBednpH+vDeWXXLLx0MjL6GwQ4rOseUAZCo2YYyQPQM+Ifm31ePbT0iDX82xjjLzcrhpPw9RzdJMBVoNX+xLrRZKseCewlxRXe/REhg4vzTVqmDqYxyEFkT1ZINT733ReGyzDPCqwRy+suxa9YFssbldChxUZRsnGF4esvB6OsC9iSylRrz3nnC/mdR0P+XRWfPgJqKhY/Ji//Ouv1I97VCXYdIh0x01hyYlDKd3k0bGUlXDhW6d2kK3UzgQwHrGVrx+8BVecj4zeXMyW0aE9l0dLEK2yaeJ0aElNtq9mv7BLAPLWgg5cu9Rwg== 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-SenderADCheck; bh=6tdlcuXhKsuG5a+WszNVrHfdRSZ3W1LraCtS7l+xOHo=; b=MPuJlOon2GIwl8+NIDjEFEv97GVq3WxuWbUmqXNoV5nINXFnTCythLcm1mtHRc9eFrjXvgVOVhtZi7OgFQtutcPU4rr3pHvl0auZFbKNmHbbS622E6KHg3uuUIKiv8KCRhvtloHiR9yKuVfspCwYJS4NLY3HQnhOmhHk64T9/OemnTM5qv8KMr4pUFTGsUWTo9xjCUZHuFcQvOZdRk0vodqgNxUgniR6VwxqCLAteq+duIcnHxXT7XG6GTXcIdsc0weUTCufr+nXogJJCAtD5BqfWB9bmrRY+4XV5RgneWmuST4PjHa25Iqq/q4DrGB8CjyxLhmOgM7H94cMExeDLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none 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=6tdlcuXhKsuG5a+WszNVrHfdRSZ3W1LraCtS7l+xOHo=; b=ugUySHkg3jWUsVpdiWEzXieYeKxz8266ZZWPEOl/1lk7Zy1+L2izYRvgsqGyDm7tUq2LVeafFnXsshDk6bThFF0SqlSZoGhuuarJV8P0nIEED7n+rwwRZy5xvbL119hFYqh6UD2oTMgesH8fSQ4eVgHamLSBA9UKdIx8KVfO777iuye+Hexolsmk2gmueQP8mPKQTi00Wd5GJYMck6AV9qEaCTbvoIDop2B/yhefUzFaPcdRYzOQeQ6O91IzQiEOCvJxz/cA9StP4k07+0sG+vkh0up0z+5pmFJFl8l5g+6n4AwlKxYVbbrlbKzx4LJSp1wM/ivkThs6lJWrEe2Mow== Received: from BN9PR03CA0192.namprd03.prod.outlook.com (2603:10b6:408:f9::17) by BY5PR12MB3873.namprd12.prod.outlook.com (2603:10b6:a03:1a3::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.24; Thu, 3 Jun 2021 16:08:48 +0000 Received: from BN8NAM11FT051.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f9:cafe::68) by BN9PR03CA0192.outlook.office365.com (2603:10b6:408:f9::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.23 via Frontend Transport; Thu, 3 Jun 2021 16:08:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; huawei.com; dkim=none (message not signed) header.d=none;huawei.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT051.mail.protection.outlook.com (10.13.177.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4195.22 via Frontend Transport; Thu, 3 Jun 2021 16:08:47 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 3 Jun 2021 09:08:46 -0700 Received: from r-arch-stor02.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 3 Jun 2021 16:08:41 +0000 From: Max Gurtovoy To: , , , , CC: , , , , , , , , , , , , , , , Max Gurtovoy Subject: [PATCH 06/11] vfio-pci: introduce vfio_pci.c Date: Thu, 3 Jun 2021 19:08:04 +0300 Message-ID: <20210603160809.15845-7-mgurtovoy@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210603160809.15845-1-mgurtovoy@nvidia.com> References: <20210603160809.15845-1-mgurtovoy@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2e66eef2-632e-4293-b0f2-08d926a9dec6 X-MS-TrafficTypeDiagnostic: BY5PR12MB3873: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2958; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Pw/F8OcZvz5nv8WjWtS25pKW8zIdv3+mCgkvS0vhDsTEUJ5xRV1DY391WmrxWVCAACz0syqFUj6xp4g2BOaKi2shclcAJhLE69zv7t6ah6xlQ5Btf2Iqk840LffPXl576Cjf9qhEzURxjq7jyCMGSB05lJ0tU8aHK9wSHc0x4+T71cCdsmWF8FxCsqtktNCak7A34ndfxAjVOP1ZV31LrsTNVhuu1b1A2gHAe/pAlemXzfQXLGErV1PTuJQKrr4dd4J6zrpUG3v7/0YyE4owsXKxuHksV7wbZVNNGklDmzUxfRCN0l7/jrEKYq1WmDeoJiMoQXIjuKrjOEhAh66swVdXCW+VARmgY6qwq24P4naPi3KlDKGFxE587dqUVPkY6J5vnqreWY9bG6uXr/6lFzKo5xrVNo9aRFBY4CYhPJakKbkSQSBP7PLELqbM9aQ1mKiOEMM1cBEaNHQh7WyDLotyf8Pj2u0wHmy/atg/9ikB3SjBLdLPxHauEYcvrW5feaKWhXj8cCq6zUpJ9vbWbE0Hg7Stc1lv6ZvQquBFr/qdnXhzOwIszsAqRdwCLcVCPBK5exxLCVVsNVaUpp80B1l5kCzR1PjhtT+Vs9Q5RUhOy9/izgQJXh+xHeZccVlLgTp7VGtyjLdUEAiSjz90wvfInXN7ML9kYwoQ/Dx8j3Y= 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)(346002)(376002)(396003)(39860400002)(136003)(46966006)(36840700001)(6636002)(26005)(426003)(70586007)(2906002)(4326008)(107886003)(36756003)(36860700001)(8676002)(186003)(83380400001)(8936002)(86362001)(1076003)(47076005)(82310400003)(110136005)(2616005)(478600001)(7636003)(6666004)(30864003)(356005)(82740400003)(5660300002)(54906003)(70206006)(336012)(316002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2021 16:08:47.5719 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2e66eef2-632e-4293-b0f2-08d926a9dec6 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: BN8NAM11FT051.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB3873 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Split the vfio_pci driver into two logical parts, the 'struct pci_driver' (vfio_pci.c) and a library of code (vfio_pci_core.c) that helps creating a VFIO device on top of a PCI device. As before vfio_pci.ko continues to present the same interface under sysfs and this change should have no functional impact. vfio_pci_core.c exposes an interface that is similar to a typical Linux subsystem (and in the future it will become a separate module), in that a pci_driver doing probe() can setup a number of details and then register and create the VFIO char device. This is a preparation for allowing another module to provide the pci_driver and allow that module to customize how VFIO is setup, inject its own operations, and easily extend vendor specific functionality. Signed-off-by: Max Gurtovoy --- drivers/vfio/pci/Makefile | 2 +- drivers/vfio/pci/vfio_pci.c | 227 ++++++++++++++++++++++++++++++ drivers/vfio/pci/vfio_pci_core.c | 234 +++++-------------------------- drivers/vfio/pci/vfio_pci_core.h | 22 +++ 4 files changed, 286 insertions(+), 199 deletions(-) create mode 100644 drivers/vfio/pci/vfio_pci.c diff --git a/drivers/vfio/pci/Makefile b/drivers/vfio/pci/Makefile index 66a40488e967..8aa517b4b671 100644 --- a/drivers/vfio/pci/Makefile +++ b/drivers/vfio/pci/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only -vfio-pci-y := vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o +vfio-pci-y := vfio_pci.o vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o vfio-pci-$(CONFIG_VFIO_PCI_IGD) += vfio_pci_igd.o vfio-pci-$(CONFIG_S390) += vfio_pci_zdev.o diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c new file mode 100644 index 000000000000..23a21ecbc674 --- /dev/null +++ b/drivers/vfio/pci/vfio_pci.c @@ -0,0 +1,227 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2021, Mellanox Technologies, Ltd. All rights reserved. + * + * Copyright (C) 2012 Red Hat, Inc. All rights reserved. + * Author: Alex Williamson + * + * Derived from original vfio: + * Copyright 2010 Cisco Systems, Inc. All rights reserved. + * Author: Tom Lyon, pugs@cisco.com + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "vfio_pci_core.h" + +#define DRIVER_VERSION "0.2" +#define DRIVER_AUTHOR "Alex Williamson " +#define DRIVER_DESC "VFIO PCI - User Level meta-driver" + +static char ids[1024] __initdata; +module_param_string(ids, ids, sizeof(ids), 0); +MODULE_PARM_DESC(ids, "Initial PCI IDs to add to the vfio driver, format is \"vendor:device[:subvendor[:subdevice[:class[:class_mask]]]]\" and multiple comma separated entries can be specified"); + +static bool enable_sriov; +#ifdef CONFIG_PCI_IOV +module_param(enable_sriov, bool, 0644); +MODULE_PARM_DESC(enable_sriov, "Enable support for SR-IOV configuration. Enabling SR-IOV on a PF typically requires support of the userspace PF driver, enabling VFs without such support may result in non-functional VFs or PF."); +#endif + +static bool disable_denylist; +module_param(disable_denylist, bool, 0444); +MODULE_PARM_DESC(disable_denylist, "Disable use of device denylist. Disabling the denylist allows binding to devices with known errata that may lead to exploitable stability or security issues when accessed by untrusted users."); + +static bool vfio_pci_dev_in_denylist(struct pci_dev *pdev) +{ + switch (pdev->vendor) { + case PCI_VENDOR_ID_INTEL: + switch (pdev->device) { + case PCI_DEVICE_ID_INTEL_QAT_C3XXX: + case PCI_DEVICE_ID_INTEL_QAT_C3XXX_VF: + case PCI_DEVICE_ID_INTEL_QAT_C62X: + case PCI_DEVICE_ID_INTEL_QAT_C62X_VF: + case PCI_DEVICE_ID_INTEL_QAT_DH895XCC: + case PCI_DEVICE_ID_INTEL_QAT_DH895XCC_VF: + return true; + default: + return false; + } + } + + return false; +} + +static bool vfio_pci_is_denylisted(struct pci_dev *pdev) +{ + if (!vfio_pci_dev_in_denylist(pdev)) + return false; + + if (disable_denylist) { + pci_warn(pdev, + "device denylist disabled - allowing device %04x:%04x.\n", + pdev->vendor, pdev->device); + return false; + } + + pci_warn(pdev, "%04x:%04x exists in vfio-pci device denylist, driver probing disallowed.\n", + pdev->vendor, pdev->device); + + return true; +} + +static const struct vfio_device_ops vfio_pci_ops = { + .name = "vfio-pci", + .open = vfio_pci_core_open, + .release = vfio_pci_core_release, + .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, + .reflck_attach = vfio_pci_core_reflck_attach, +}; + +static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) +{ + struct vfio_pci_core_device *vdev; + int ret; + + if (vfio_pci_is_denylisted(pdev)) + return -EINVAL; + + vdev = kzalloc(sizeof(*vdev), GFP_KERNEL); + if (!vdev) + return -ENOMEM; + + ret = vfio_pci_core_register_device(vdev, pdev, &vfio_pci_ops); + if (ret) + goto out_free; + + return 0; + +out_free: + kfree(vdev); + return ret; +} + +static void vfio_pci_remove(struct pci_dev *pdev) +{ + struct vfio_pci_core_device *vdev = dev_get_drvdata(&pdev->dev); + + vfio_pci_core_unregister_device(vdev); + kfree(vdev); +} + +static int vfio_pci_sriov_configure(struct pci_dev *pdev, int nr_virtfn) +{ + might_sleep(); + + if (!enable_sriov) + return -ENOENT; + + return vfio_pci_core_sriov_configure(pdev, nr_virtfn); +} + +static struct pci_driver vfio_pci_driver = { + .name = "vfio-pci", + .id_table = NULL, /* only dynamic ids */ + .probe = vfio_pci_probe, + .remove = vfio_pci_remove, + .sriov_configure = vfio_pci_sriov_configure, + .err_handler = &vfio_pci_core_err_handlers, +}; + +static void __exit vfio_pci_cleanup(void) +{ + pci_unregister_driver(&vfio_pci_driver); + vfio_pci_core_cleanup(); +} + +static void __init vfio_pci_fill_ids(void) +{ + char *p, *id; + int rc; + + /* no ids passed actually */ + if (ids[0] == '\0') + return; + + /* add ids specified in the module parameter */ + p = ids; + while ((id = strsep(&p, ","))) { + unsigned int vendor, device, subvendor = PCI_ANY_ID, + subdevice = PCI_ANY_ID, class = 0, class_mask = 0; + int fields; + + if (!strlen(id)) + continue; + + fields = sscanf(id, "%x:%x:%x:%x:%x:%x", + &vendor, &device, &subvendor, &subdevice, + &class, &class_mask); + + if (fields < 2) { + pr_warn("invalid id string \"%s\"\n", id); + continue; + } + + rc = pci_add_dynid(&vfio_pci_driver, vendor, device, + subvendor, subdevice, class, class_mask, 0); + if (rc) + pr_warn("failed to add dynamic id [%04x:%04x[%04x:%04x]] class %#08x/%08x (%d)\n", + vendor, device, subvendor, subdevice, + class, class_mask, rc); + else + pr_info("add [%04x:%04x[%04x:%04x]] class %#08x/%08x\n", + vendor, device, subvendor, subdevice, + class, class_mask); + } +} + +static int __init vfio_pci_init(void) +{ + int ret; + + ret = vfio_pci_core_init(); + if (ret) + return ret; + + /* Register and scan for devices */ + ret = pci_register_driver(&vfio_pci_driver); + if (ret) + goto out; + + vfio_pci_fill_ids(); + + if (disable_denylist) + pr_warn("device denylist disabled.\n"); + + return 0; + +out: + vfio_pci_core_cleanup(); + return ret; +} + +module_init(vfio_pci_init); +module_exit(vfio_pci_cleanup); + +MODULE_VERSION(DRIVER_VERSION); +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR(DRIVER_AUTHOR); +MODULE_DESCRIPTION(DRIVER_DESC); diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 61cd785c80e8..12d5392c78cc 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -8,8 +8,6 @@ * Author: Tom Lyon, pugs@cisco.com */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - #include #include #include @@ -29,14 +27,6 @@ #include "vfio_pci_core.h" -#define DRIVER_VERSION "0.2" -#define DRIVER_AUTHOR "Alex Williamson " -#define DRIVER_DESC "VFIO PCI - User Level meta-driver" - -static char ids[1024] __initdata; -module_param_string(ids, ids, sizeof(ids), 0); -MODULE_PARM_DESC(ids, "Initial PCI IDs to add to the vfio driver, format is \"vendor:device[:subvendor[:subdevice[:class[:class_mask]]]]\" and multiple comma separated entries can be specified"); - static bool nointxmask; module_param_named(nointxmask, nointxmask, bool, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(nointxmask, @@ -53,16 +43,6 @@ module_param(disable_idle_d3, bool, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(disable_idle_d3, "Disable using the PCI D3 low power state for idle, unused devices"); -static bool enable_sriov; -#ifdef CONFIG_PCI_IOV -module_param(enable_sriov, bool, 0644); -MODULE_PARM_DESC(enable_sriov, "Enable support for SR-IOV configuration. Enabling SR-IOV on a PF typically requires support of the userspace PF driver, enabling VFs without such support may result in non-functional VFs or PF."); -#endif - -static bool disable_denylist; -module_param(disable_denylist, bool, 0444); -MODULE_PARM_DESC(disable_denylist, "Disable use of device denylist. Disabling the denylist allows binding to devices with known errata that may lead to exploitable stability or security issues when accessed by untrusted users."); - static inline bool vfio_vga_disabled(void) { #ifdef CONFIG_VFIO_PCI_VGA @@ -72,44 +52,6 @@ static inline bool vfio_vga_disabled(void) #endif } -static bool vfio_pci_dev_in_denylist(struct pci_dev *pdev) -{ - switch (pdev->vendor) { - case PCI_VENDOR_ID_INTEL: - switch (pdev->device) { - case PCI_DEVICE_ID_INTEL_QAT_C3XXX: - case PCI_DEVICE_ID_INTEL_QAT_C3XXX_VF: - case PCI_DEVICE_ID_INTEL_QAT_C62X: - case PCI_DEVICE_ID_INTEL_QAT_C62X_VF: - case PCI_DEVICE_ID_INTEL_QAT_DH895XCC: - case PCI_DEVICE_ID_INTEL_QAT_DH895XCC_VF: - return true; - default: - return false; - } - } - - return false; -} - -static bool vfio_pci_is_denylisted(struct pci_dev *pdev) -{ - if (!vfio_pci_dev_in_denylist(pdev)) - return false; - - if (disable_denylist) { - pci_warn(pdev, - "device denylist disabled - allowing device %04x:%04x.\n", - pdev->vendor, pdev->device); - return false; - } - - pci_warn(pdev, "%04x:%04x exists in vfio-pci device denylist, driver probing disallowed.\n", - pdev->vendor, pdev->device); - - return true; -} - /* * Our VGA arbiter participation is limited since we don't know anything * about the device itself. However, if the device is the only VGA device @@ -495,8 +437,6 @@ static void vfio_pci_disable(struct vfio_pci_core_device *vdev) vfio_pci_set_power_state(vdev, PCI_D3hot); } -static struct pci_driver vfio_pci_driver; - static struct vfio_pci_core_device *get_pf_vdev(struct vfio_pci_core_device *vdev) { struct pci_dev *physfn = pci_physfn(vdev->pdev); @@ -509,7 +449,7 @@ static struct vfio_pci_core_device *get_pf_vdev(struct vfio_pci_core_device *vde if (!pf_dev) return NULL; - if (pci_dev_driver(physfn) != &vfio_pci_driver) { + if (pci_dev_driver(physfn) != pci_dev_driver(vdev->pdev)) { vfio_device_put(pf_dev); return NULL; } @@ -532,7 +472,7 @@ static void vfio_pci_vf_token_user_add(struct vfio_pci_core_device *vdev, int va vfio_device_put(&pf_vdev->vdev); } -static void vfio_pci_core_release(struct vfio_device *core_vdev) +void vfio_pci_core_release(struct vfio_device *core_vdev) { struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev); @@ -555,7 +495,7 @@ static void vfio_pci_core_release(struct vfio_device *core_vdev) mutex_unlock(&vdev->igate); } -static int vfio_pci_core_open(struct vfio_device *core_vdev) +int vfio_pci_core_open(struct vfio_device *core_vdev) { struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev); @@ -762,8 +702,8 @@ struct vfio_devices { int max_index; }; -static long vfio_pci_core_ioctl(struct vfio_device *core_vdev, - unsigned int cmd, unsigned long arg) +long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, + unsigned long arg) { struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev); @@ -1393,8 +1333,8 @@ static ssize_t vfio_pci_rw(struct vfio_pci_core_device *vdev, char __user *buf, return -EINVAL; } -static ssize_t vfio_pci_core_read(struct vfio_device *core_vdev, char __user *buf, - size_t count, loff_t *ppos) +ssize_t vfio_pci_core_read(struct vfio_device *core_vdev, char __user *buf, + size_t count, loff_t *ppos) { struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev); @@ -1405,8 +1345,8 @@ static ssize_t vfio_pci_core_read(struct vfio_device *core_vdev, char __user *bu return vfio_pci_rw(vdev, buf, count, ppos, false); } -static ssize_t vfio_pci_core_write(struct vfio_device *core_vdev, const char __user *buf, - size_t count, loff_t *ppos) +ssize_t vfio_pci_core_write(struct vfio_device *core_vdev, const char __user *buf, + size_t count, loff_t *ppos) { struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev); @@ -1611,7 +1551,7 @@ static const struct vm_operations_struct vfio_pci_mmap_ops = { .fault = vfio_pci_mmap_fault, }; -static int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma) +int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma) { struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev); @@ -1682,7 +1622,7 @@ static int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_stru return 0; } -static void vfio_pci_core_request(struct vfio_device *core_vdev, unsigned int count) +void vfio_pci_core_request(struct vfio_device *core_vdev, unsigned int count) { struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev); @@ -1798,7 +1738,7 @@ static int vfio_pci_validate_vf_token(struct vfio_pci_core_device *vdev, #define VF_TOKEN_ARG "vf_token=" -static int vfio_pci_core_match(struct vfio_device *core_vdev, char *buf) +int vfio_pci_core_match(struct vfio_device *core_vdev, char *buf) { struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev); @@ -1852,12 +1792,14 @@ static int vfio_pci_reflck_find(struct pci_dev *pdev, void *data) { struct vfio_reflck **preflck = data; struct vfio_device *device; + struct vfio_pci_core_device *vdev; device = vfio_device_get_from_dev(&pdev->dev); if (!device) return 0; - if (pci_dev_driver(pdev) != &vfio_pci_driver) { + vdev = container_of(device, struct vfio_pci_core_device, vdev); + if (pci_dev_driver(pdev) != pci_dev_driver(vdev->pdev)) { vfio_device_put(device); return 0; } @@ -1873,7 +1815,7 @@ static int vfio_pci_reflck_find(struct pci_dev *pdev, void *data) return 0; } -static int vfio_pci_core_reflck_attach(struct vfio_device *core_vdev) +int vfio_pci_core_reflck_attach(struct vfio_device *core_vdev) { struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev); @@ -1887,19 +1829,6 @@ static int vfio_pci_core_reflck_attach(struct vfio_device *core_vdev) return PTR_ERR_OR_ZERO(core_vdev->reflck); } -static const struct vfio_device_ops vfio_pci_ops = { - .name = "vfio-pci", - .open = vfio_pci_core_open, - .release = vfio_pci_core_release, - .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, - .reflck_attach = vfio_pci_core_reflck_attach, -}; - static int vfio_pci_bus_notifier(struct notifier_block *nb, unsigned long action, void *data) { @@ -1914,12 +1843,12 @@ static int vfio_pci_bus_notifier(struct notifier_block *nb, pci_info(vdev->pdev, "Captured SR-IOV VF %s driver_override\n", pci_name(pdev)); pdev->driver_override = kasprintf(GFP_KERNEL, "%s", - vfio_pci_ops.name); + vdev->vdev.ops->name); } else if (action == BUS_NOTIFY_BOUND_DRIVER && pdev->is_virtfn && physfn == vdev->pdev) { struct pci_driver *drv = pci_dev_driver(pdev); - if (drv && drv != &vfio_pci_driver) + if (drv && drv != pci_dev_driver(vdev->pdev)) pci_warn(vdev->pdev, "VF %s bound to driver %s while PF bound to vfio-pci\n", pci_name(pdev), drv->name); @@ -1990,15 +1919,13 @@ static void vfio_pci_vga_uninit(struct vfio_pci_core_device *vdev) VGA_RSRC_LEGACY_MEM); } -static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) +int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev, + struct pci_dev *pdev, + const struct vfio_device_ops *vfio_pci_ops) { - struct vfio_pci_core_device *vdev; struct iommu_group *group; int ret; - if (vfio_pci_is_denylisted(pdev)) - return -EINVAL; - if (pdev->hdr_type != PCI_HEADER_TYPE_NORMAL) return -EINVAL; @@ -2019,12 +1946,6 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (!group) return -EINVAL; - vdev = kzalloc(sizeof(*vdev), GFP_KERNEL); - if (!vdev) { - ret = -ENOMEM; - goto out_group_put; - } - vdev->pdev = pdev; vdev->irq_type = VFIO_PCI_NUM_IRQS; mutex_init(&vdev->igate); @@ -2036,9 +1957,9 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) INIT_LIST_HEAD(&vdev->vma_list); init_rwsem(&vdev->memory_lock); - ret = vfio_init_group_dev(&vdev->vdev, &pdev->dev, &vfio_pci_ops); + ret = vfio_init_group_dev(&vdev->vdev, &pdev->dev, vfio_pci_ops); if (ret) - goto out_free; + goto out_group_put; ret = vfio_pci_vf_init(vdev); if (ret) goto out_uninit; @@ -2075,17 +1996,15 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) vfio_pci_vf_uninit(vdev); out_uninit: vfio_uninit_group_dev(&vdev->vdev); -out_free: kfree(vdev->pm_save); - kfree(vdev); out_group_put: vfio_iommu_group_put(group, &pdev->dev); return ret; } -static void vfio_pci_remove(struct pci_dev *pdev) +void vfio_pci_core_unregister_device(struct vfio_pci_core_device *vdev) { - struct vfio_pci_core_device *vdev = dev_get_drvdata(&pdev->dev); + struct pci_dev *pdev = vdev->pdev; pci_disable_sriov(pdev); @@ -2103,7 +2022,6 @@ static void vfio_pci_remove(struct pci_dev *pdev) mutex_destroy(&vdev->ioeventfds_lock); kfree(vdev->region); kfree(vdev->pm_save); - kfree(vdev); } static pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev, @@ -2130,16 +2048,13 @@ static pci_ers_result_t vfio_pci_aer_err_detected(struct pci_dev *pdev, return PCI_ERS_RESULT_CAN_RECOVER; } -static int vfio_pci_sriov_configure(struct pci_dev *pdev, int nr_virtfn) +int vfio_pci_core_sriov_configure(struct pci_dev *pdev, int nr_virtfn) { struct vfio_device *device; int ret = 0; might_sleep(); - if (!enable_sriov) - return -ENOENT; - device = vfio_device_get_from_dev(&pdev->dev); if (!device) return -ENODEV; @@ -2154,19 +2069,10 @@ static int vfio_pci_sriov_configure(struct pci_dev *pdev, int nr_virtfn) return ret < 0 ? ret : nr_virtfn; } -static const struct pci_error_handlers vfio_err_handlers = { +const struct pci_error_handlers vfio_pci_core_err_handlers = { .error_detected = vfio_pci_aer_err_detected, }; -static struct pci_driver vfio_pci_driver = { - .name = "vfio-pci", - .id_table = NULL, /* only dynamic ids */ - .probe = vfio_pci_probe, - .remove = vfio_pci_remove, - .sriov_configure = vfio_pci_sriov_configure, - .err_handler = &vfio_err_handlers, -}; - static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data) { struct vfio_devices *devs = data; @@ -2180,12 +2086,12 @@ static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data) if (!device) return -EINVAL; - if (pci_dev_driver(pdev) != &vfio_pci_driver) { + vdev = container_of(device, struct vfio_pci_core_device, vdev); + if (pci_dev_driver(pdev) != pci_dev_driver(vdev->pdev)) { vfio_device_put(device); return -EBUSY; } - vdev = container_of(device, struct vfio_pci_core_device, vdev); /* Fault if the device is not unused */ if (device->refcnt) { @@ -2210,12 +2116,12 @@ static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data) if (!device) return -EINVAL; - if (pci_dev_driver(pdev) != &vfio_pci_driver) { + vdev = container_of(device, struct vfio_pci_core_device, vdev); + if (pci_dev_driver(pdev) != pci_dev_driver(vdev->pdev)) { vfio_device_put(device); return -EBUSY; } - vdev = container_of(device, struct vfio_pci_core_device, vdev); /* * Locking multiple devices is prone to deadlock, runaway and @@ -2305,83 +2211,15 @@ static void vfio_pci_try_bus_reset(struct vfio_pci_core_device *vdev) kfree(devs.devices); } -static void __exit vfio_pci_cleanup(void) +/* This will become the __exit function of vfio_pci_core.ko */ +void vfio_pci_core_cleanup(void) { - pci_unregister_driver(&vfio_pci_driver); vfio_pci_uninit_perm_bits(); } -static void __init vfio_pci_fill_ids(void) +/* This will become the __init function of vfio_pci_core.ko */ +int __init vfio_pci_core_init(void) { - char *p, *id; - int rc; - - /* no ids passed actually */ - if (ids[0] == '\0') - return; - - /* add ids specified in the module parameter */ - p = ids; - while ((id = strsep(&p, ","))) { - unsigned int vendor, device, subvendor = PCI_ANY_ID, - subdevice = PCI_ANY_ID, class = 0, class_mask = 0; - int fields; - - if (!strlen(id)) - continue; - - fields = sscanf(id, "%x:%x:%x:%x:%x:%x", - &vendor, &device, &subvendor, &subdevice, - &class, &class_mask); - - if (fields < 2) { - pr_warn("invalid id string \"%s\"\n", id); - continue; - } - - rc = pci_add_dynid(&vfio_pci_driver, vendor, device, - subvendor, subdevice, class, class_mask, 0); - if (rc) - pr_warn("failed to add dynamic id [%04x:%04x[%04x:%04x]] class %#08x/%08x (%d)\n", - vendor, device, subvendor, subdevice, - class, class_mask, rc); - else - pr_info("add [%04x:%04x[%04x:%04x]] class %#08x/%08x\n", - vendor, device, subvendor, subdevice, - class, class_mask); - } -} - -static int __init vfio_pci_init(void) -{ - int ret; - /* Allocate shared config space permission data used by all devices */ - ret = vfio_pci_init_perm_bits(); - if (ret) - return ret; - - /* Register and scan for devices */ - ret = pci_register_driver(&vfio_pci_driver); - if (ret) - goto out_driver; - - vfio_pci_fill_ids(); - - if (disable_denylist) - pr_warn("device denylist disabled.\n"); - - return 0; - -out_driver: - vfio_pci_uninit_perm_bits(); - return ret; + return vfio_pci_init_perm_bits(); } - -module_init(vfio_pci_init); -module_exit(vfio_pci_cleanup); - -MODULE_VERSION(DRIVER_VERSION); -MODULE_LICENSE("GPL v2"); -MODULE_AUTHOR(DRIVER_AUTHOR); -MODULE_DESCRIPTION(DRIVER_DESC); diff --git a/drivers/vfio/pci/vfio_pci_core.h b/drivers/vfio/pci/vfio_pci_core.h index cb24d229df66..245862d5d6e4 100644 --- a/drivers/vfio/pci/vfio_pci_core.h +++ b/drivers/vfio/pci/vfio_pci_core.h @@ -206,4 +206,26 @@ static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, } #endif +/* Will be exported for vfio pci drivers usage */ +void vfio_pci_core_cleanup(void); +int vfio_pci_core_init(void); +void vfio_pci_core_release(struct vfio_device *core_vdev); +int vfio_pci_core_open(struct vfio_device *core_vdev); +int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev, + struct pci_dev *pdev, + const struct vfio_device_ops *vfio_pci_ops); +void vfio_pci_core_unregister_device(struct vfio_pci_core_device *vdev); +int vfio_pci_core_sriov_configure(struct pci_dev *pdev, int nr_virtfn); +extern const struct pci_error_handlers vfio_pci_core_err_handlers; +long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, + unsigned long arg); +ssize_t vfio_pci_core_read(struct vfio_device *core_vdev, char __user *buf, + size_t count, loff_t *ppos); +ssize_t vfio_pci_core_write(struct vfio_device *core_vdev, const char __user *buf, + size_t count, loff_t *ppos); +int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma); +void vfio_pci_core_request(struct vfio_device *core_vdev, unsigned int count); +int vfio_pci_core_match(struct vfio_device *core_vdev, char *buf); +int vfio_pci_core_reflck_attach(struct vfio_device *core_vdev); + #endif /* VFIO_PCI_CORE_H */ From patchwork Thu Jun 3 16:08:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Gurtovoy X-Patchwork-Id: 12297533 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00D56C47096 for ; Thu, 3 Jun 2021 16:09:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DEBE1613F3 for ; Thu, 3 Jun 2021 16:08:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229845AbhFCQKn (ORCPT ); Thu, 3 Jun 2021 12:10:43 -0400 Received: from mail-bn7nam10on2089.outbound.protection.outlook.com ([40.107.92.89]:63457 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230097AbhFCQKk (ORCPT ); Thu, 3 Jun 2021 12:10:40 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EmUcG8ZyPDYfn9GM5Tu8qfQd3pRignaJ5FpTDpnK0Wb+vLHu2qfG2KiyoQlRns08dXhxU49l4QsMWSAeAQ+wtpA88zGaWat5jrX1GBYv5QIm5Tmqbm9KTsKf31caiDPATq1fCGZClCYVgIMUbjeAIz1xBJ03MisBdRtpt96OWmXVlsDyQwTeSGTTGRjl7WVdIURa8GtXqF01v0ULmj9SxruU1/vZN3JYHBCxT2uV7WTYPAK5Jauy60Wk5NiF0QFWz/aEliaFm1bbH0U/UhOkFjlDNaD2NXfnKSmkHG2EbTwjiYMurUxeQ4aDTk8O+xekc3zj5zBKbj43VbuuNbPjsw== 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-SenderADCheck; bh=sEHiwdaurHYJn0FoiiuZooTSByuH6O61okuZ1PXUgx8=; b=QIK1WALfeirLuDuxxvahU7d4+iUHV1pWLlf1oLOuCr/ZeBlyd321P+zUIsbl2oDmC7SMXZ7GNAx90BEXFeURrEUAkiMaaXbwujnipSJCjXf9vJwnZ9m7EK9axWkuU9tkc/hUep07qOBf3bzL5ga7Na/dNuXlisyNXBSlNS8A2J3I9ag0EzHTu5GWgMsgjtbFGDopEf62qYn67KddN06V7x8jLT0aPcNbHo4I86/Qj9Dz8lnr86ib8FLQ42QMiZ3hL/izk5Z1vXWpOss5TAn2YfAagjedZBPXK0mpPcXC25jBMwFumEK13AoH1qp++6WCMgmsnUTxtWbQ6W36icnCZw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none 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=sEHiwdaurHYJn0FoiiuZooTSByuH6O61okuZ1PXUgx8=; b=EVXSnb/ly9mB7kofdKM/XsNuIn9sNor4llXjTOybWtLNChE9g83pcwuUPvjlY3iLAwn9OxUQ3bfvlYnTAKnM4vw6vmXs2wvlkHY1FTYNfLDHOxZDHxt6mKlEDGx8MwfOUtUTsZVn1ObjYxYqPYqjzoGhzadRb/hNZ5Ed00tiqwOUtRcWhXZzqtUuutlKW64iDolibcIAy4+kl5Krh57OWY380KlzrH1goHTl29k5ipjrEL06n+u0J1T0F6QCipUrVC8N4keyvBAYYrQ1HmF8GAGbqkfd7pqHmeNT7EIwmknNTpTVNjsHlyy8ESePVUKLjlJE2y5e81brxGRc57VdzQ== Received: from CO1PR15CA0059.namprd15.prod.outlook.com (2603:10b6:101:1f::27) by DM6PR12MB3465.namprd12.prod.outlook.com (2603:10b6:5:3a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.21; Thu, 3 Jun 2021 16:08:53 +0000 Received: from CO1NAM11FT044.eop-nam11.prod.protection.outlook.com (2603:10b6:101:1f:cafe::e4) by CO1PR15CA0059.outlook.office365.com (2603:10b6:101:1f::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.21 via Frontend Transport; Thu, 3 Jun 2021 16:08:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; huawei.com; dkim=none (message not signed) header.d=none;huawei.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 CO1NAM11FT044.mail.protection.outlook.com (10.13.175.188) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4195.22 via Frontend Transport; Thu, 3 Jun 2021 16:08:52 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 3 Jun 2021 16:08:51 +0000 Received: from r-arch-stor02.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 3 Jun 2021 16:08:47 +0000 From: Max Gurtovoy To: , , , , CC: , , , , , , , , , , , , , , , Max Gurtovoy Subject: [PATCH 07/11] vfio-pci: move igd initialization to vfio_pci.c Date: Thu, 3 Jun 2021 19:08:05 +0300 Message-ID: <20210603160809.15845-8-mgurtovoy@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210603160809.15845-1-mgurtovoy@nvidia.com> References: <20210603160809.15845-1-mgurtovoy@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a1c3a357-799a-4821-2801-08d926a9e19c X-MS-TrafficTypeDiagnostic: DM6PR12MB3465: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1247; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6+YphYz8LwV9uaryMa7NYguDveLZWxbLPKhLgHgKa3f4gXr3h/JXZz1l4l8nhU02zKMq8aHvegNWf8zw3/HaHqLdkiZi+pWesFgcSKW3rA4ZshAwWoyoE/St/pZk6FBA907eeuA7PMKpCxeepIDvx+FRBfyWr1J5u49Qyl2as9VfW1vIKO3WlONq2x6zaQBZ3oyNAlpXH9qouK0tckPGcl49Zthf5CF4Np+PR54wzoiXvS/nd8SgZTI+ITIAAt7XTUp2JtD7TJLy0n6z22S9+ICKZdmVt9fCoE+rAbbssymbzZSsHzfYYndR8HZQdWc72qjyQV/T3l3fj41o1TwAlL1F1NgJAbtLO7dHzYBmjK5BoNLUHLiTr+YkZ3418OOTBT9xT2S5pgwL4RWovAlub3W7CZ2thiFBl3oQJW6qax1v5cfyPLY3rkRHHGVtusheEApnXONlBLEqTV1TgLtcDPTjr8gJ1znX7DAkeKmtFWfcf5EcQA5B/ERcNigQPmJHp//6+VIpNBN4AGmEl7UwQfL9PhnRKjkHjIhNZ1+taMrW6lfkr2WlmdS3/HPoIYrCrY4z9KmLoro5sowmgzPh45J+XhqepZXjGsXNyWlIu/ZwQZmZMaZyUNuogN2H+Eq11SQb71f8blisqNp66P29LY4OJ6A8ZZ0u3rCIkT7VNQE= 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)(39860400002)(376002)(396003)(136003)(346002)(36840700001)(46966006)(1076003)(336012)(36756003)(6666004)(186003)(478600001)(54906003)(110136005)(4326008)(36906005)(70206006)(70586007)(5660300002)(2616005)(316002)(426003)(107886003)(6636002)(7636003)(356005)(86362001)(47076005)(82310400003)(8936002)(82740400003)(8676002)(36860700001)(26005)(2906002)(83380400001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2021 16:08:52.5028 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a1c3a357-799a-4821-2801-08d926a9e19c 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: CO1NAM11FT044.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3465 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is a preparation before splitting vfio_pci.ko to 2 drivers. Move the vendor specific igd initialization from the core part to pci_driver part. Signed-off-by: Max Gurtovoy --- drivers/vfio/pci/vfio_pci.c | 31 ++++++++++++++++++++- drivers/vfio/pci/vfio_pci_core.c | 46 +++++++++++--------------------- drivers/vfio/pci/vfio_pci_core.h | 8 ++++++ 3 files changed, 54 insertions(+), 31 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 23a21ecbc674..850ea3a94e28 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -83,9 +83,38 @@ static bool vfio_pci_is_denylisted(struct pci_dev *pdev) return true; } +static int vfio_pci_open(struct vfio_device *core_vdev) +{ + struct vfio_pci_core_device *vdev = + container_of(core_vdev, struct vfio_pci_core_device, vdev); + struct pci_dev *pdev = vdev->pdev; + int ret; + + lockdep_assert_held(&core_vdev->reflck->lock); + + ret = vfio_pci_core_enable(vdev); + if (ret) + return ret; + + if (vfio_pci_is_vga(pdev) && + pdev->vendor == PCI_VENDOR_ID_INTEL && + IS_ENABLED(CONFIG_VFIO_PCI_IGD)) { + ret = vfio_pci_igd_init(vdev); + if (ret && ret != -ENODEV) { + pci_warn(pdev, "Failed to setup Intel IGD regions\n"); + vfio_pci_core_disable(vdev); + return ret; + } + } + + vfio_pci_core_finish_enable(vdev); + + return 0; +} + static const struct vfio_device_ops vfio_pci_ops = { .name = "vfio-pci", - .open = vfio_pci_core_open, + .open = vfio_pci_open, .release = vfio_pci_core_release, .ioctl = vfio_pci_core_ioctl, .read = vfio_pci_core_read, diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 12d5392c78cc..39a3f18bbc08 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -91,11 +91,6 @@ static unsigned int vfio_pci_set_vga_decode(void *opaque, bool single_vga) return decodes; } -static inline bool vfio_pci_is_vga(struct pci_dev *pdev) -{ - return (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA; -} - static void vfio_pci_probe_mmaps(struct vfio_pci_core_device *vdev) { struct resource *res; @@ -165,7 +160,6 @@ static void vfio_pci_probe_mmaps(struct vfio_pci_core_device *vdev) } static void vfio_pci_try_bus_reset(struct vfio_pci_core_device *vdev); -static void vfio_pci_disable(struct vfio_pci_core_device *vdev); static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data); /* @@ -250,7 +244,7 @@ int vfio_pci_set_power_state(struct vfio_pci_core_device *vdev, pci_power_t stat return ret; } -static int vfio_pci_enable(struct vfio_pci_core_device *vdev) +int vfio_pci_core_enable(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev = vdev->pdev; int ret; @@ -319,26 +313,11 @@ static int vfio_pci_enable(struct vfio_pci_core_device *vdev) if (!vfio_vga_disabled() && vfio_pci_is_vga(pdev)) vdev->has_vga = true; - if (vfio_pci_is_vga(pdev) && - pdev->vendor == PCI_VENDOR_ID_INTEL && - IS_ENABLED(CONFIG_VFIO_PCI_IGD)) { - ret = vfio_pci_igd_init(vdev); - if (ret && ret != -ENODEV) { - pci_warn(pdev, "Failed to setup Intel IGD regions\n"); - goto disable_exit; - } - } - - vfio_pci_probe_mmaps(vdev); return 0; - -disable_exit: - vfio_pci_disable(vdev); - return ret; } -static void vfio_pci_disable(struct vfio_pci_core_device *vdev) +void vfio_pci_core_disable(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev = vdev->pdev; struct vfio_pci_dummy_resource *dummy_res, *tmp; @@ -481,7 +460,7 @@ void vfio_pci_core_release(struct vfio_device *core_vdev) vfio_pci_vf_token_user_add(vdev, -1); vfio_spapr_pci_eeh_release(vdev->pdev); - vfio_pci_disable(vdev); + vfio_pci_core_disable(vdev); mutex_lock(&vdev->igate); if (vdev->err_trigger) { @@ -495,6 +474,13 @@ void vfio_pci_core_release(struct vfio_device *core_vdev) mutex_unlock(&vdev->igate); } +void vfio_pci_core_finish_enable(struct vfio_pci_core_device *vdev) +{ + vfio_pci_probe_mmaps(vdev); + vfio_spapr_pci_eeh_open(vdev->pdev); + vfio_pci_vf_token_user_add(vdev, 1); +} + int vfio_pci_core_open(struct vfio_device *core_vdev) { struct vfio_pci_core_device *vdev = @@ -503,13 +489,13 @@ int vfio_pci_core_open(struct vfio_device *core_vdev) lockdep_assert_held(&core_vdev->reflck->lock); - ret = vfio_pci_enable(vdev); + ret = vfio_pci_core_enable(vdev); if (ret) - goto error; - vfio_spapr_pci_eeh_open(vdev->pdev); - vfio_pci_vf_token_user_add(vdev, 1); -error: - return ret; + return ret; + + vfio_pci_core_finish_enable(vdev); + + return 0; } static int vfio_pci_get_irq_count(struct vfio_pci_core_device *vdev, int irq_type) diff --git a/drivers/vfio/pci/vfio_pci_core.h b/drivers/vfio/pci/vfio_pci_core.h index 245862d5d6e4..406e934e23b2 100644 --- a/drivers/vfio/pci/vfio_pci_core.h +++ b/drivers/vfio/pci/vfio_pci_core.h @@ -227,5 +227,13 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma void vfio_pci_core_request(struct vfio_device *core_vdev, unsigned int count); int vfio_pci_core_match(struct vfio_device *core_vdev, char *buf); int vfio_pci_core_reflck_attach(struct vfio_device *core_vdev); +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); + +static inline bool vfio_pci_is_vga(struct pci_dev *pdev) +{ + return (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA; +} #endif /* VFIO_PCI_CORE_H */ From patchwork Thu Jun 3 16:08:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Gurtovoy X-Patchwork-Id: 12297535 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3221BC47082 for ; Thu, 3 Jun 2021 16:09:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C3E5613E4 for ; Thu, 3 Jun 2021 16:09:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230282AbhFCQKq (ORCPT ); Thu, 3 Jun 2021 12:10:46 -0400 Received: from mail-sn1anam02on2084.outbound.protection.outlook.com ([40.107.96.84]:42924 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230247AbhFCQKo (ORCPT ); Thu, 3 Jun 2021 12:10:44 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a05eGUxToBlDT5aXMynj0QtEqe+nJ4cz8cmkq++pE8eb3gHtYK2i0bqDz52X2a8VyJ4Onk1C4Jb1nfVBSQHG6KJbiAoi4Sifrrlc2LuEPfh666Ve5y4U9uIsGetzhtcjD2BN9UxVmM1WGu6Q9LSkAJDUpRRaDuRF4/sfMLtLLC39tkPowL24zeNMQhu+IVYaQssJHKkm0gHBCJTVNmi5KxfPDr/Z8kSe+l46cOSSpmQWsJySZEXoJ+nruMp6xy+23tyxQMbywgIfKhriIYHynuSifulj+FzF86CkE+LPSm+hrRwTUgYoHmECZ7rOiPsL05ZKX42ogB6UwqprGntyNw== 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-SenderADCheck; bh=9XeIWBMvjjxEnGRUf1h5uJtIdeEaaeXaLM5bCkodPmk=; b=NCidFwgsPmL8eXHCRShaR5HFqM4Ua7C2YeUFsJZBCf5kS/0VitZiiqmGO+0DcrD0MfdLcC/yOXu8JllcAzOMJVrQE8U3MZtqfNNZCuWwZy9+3xTo+jmNJZTKew9GFSdn6pOL0eXaIl4etyn+5WSvJ+BEGNvm3ANACojjpHUiCxG6ZyaHUvIwb11eEi5GBh7iIZAHBd7lVT5SbG8H4mqhTUhnDC65D4TQPeLAk40GX+4K6RuYQgUxA0T5BUTRKlfGcTZu2uY6SnXR3HbBthlUcfMa9+EfBZ2jRo8ACg1/hgIP2J1DLFH3xTh0JVKzuXG2/TGbST5P2ALhEdqsrMdSdw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none 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=9XeIWBMvjjxEnGRUf1h5uJtIdeEaaeXaLM5bCkodPmk=; b=KogviuUPtcx4MkUFmmZ8LVB+I1bUSLbZ1P/fjzAVkBHGZ4FufVU2kw/HybZ+GpVvrEfTLAhC3a9XriAP+qBjcPcbBfa5R4gnwobd2WqdkX8Fvi0bhm+lrjlIxOHoFUl4HJzBonHan0KHazpeAJ9Piv7PBQhCglb2OVhUm5QUcevw7z0luGJsp4qbufRY3O/Wq77DZc4ncJZSsO1Cv7FfBgKvIlUODNsCs22hbNee0u+iwRv+r/Hu1UkLt1U+k5o0oOdt7anCmsHlQEBZzX3XWSSMTWmQmIzakW9l37sz46716OPdYDnnhDaCCP3jcReP511mzFIF4Z2/GDONBWfGNA== Received: from BN6PR11CA0043.namprd11.prod.outlook.com (2603:10b6:404:4b::29) by DM4PR12MB5344.namprd12.prod.outlook.com (2603:10b6:5:39f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.22; Thu, 3 Jun 2021 16:08:58 +0000 Received: from BN8NAM11FT057.eop-nam11.prod.protection.outlook.com (2603:10b6:404:4b:cafe::5a) by BN6PR11CA0043.outlook.office365.com (2603:10b6:404:4b::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.20 via Frontend Transport; Thu, 3 Jun 2021 16:08:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; huawei.com; dkim=none (message not signed) header.d=none;huawei.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT057.mail.protection.outlook.com (10.13.177.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4195.22 via Frontend Transport; Thu, 3 Jun 2021 16:08:58 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 3 Jun 2021 09:08:57 -0700 Received: from r-arch-stor02.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 3 Jun 2021 16:08:52 +0000 From: Max Gurtovoy To: , , , , CC: , , , , , , , , , , , , , , , Max Gurtovoy Subject: [PATCH 08/11] PCI: add flags field to pci_device_id structure Date: Thu, 3 Jun 2021 19:08:06 +0300 Message-ID: <20210603160809.15845-9-mgurtovoy@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210603160809.15845-1-mgurtovoy@nvidia.com> References: <20210603160809.15845-1-mgurtovoy@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d4c95ec2-3ecb-421b-a841-08d926a9e503 X-MS-TrafficTypeDiagnostic: DM4PR12MB5344: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: N0TkoCWBThi4cSbxwNBQ7S5v3JG+8g31NDa0oshA58fDgS7XbCNtaOmCq26IeAmZl3JZjs1C1wRn9GEZcspzlWsY6cJi7dNL6COrDu8dVli0fgK5QpegoB5SL4G2tcjWSPHZY93S+u472RERFYOmHXe9rvWm7F/qyG5k+cGNeSAoaGLBXhkGgqn9SdNObl4tKwpsQSeig2q4M7ltIPe3KbsjuA9GlpTCVcICVZ4EfD9UBBPdMaO7v/BxHu2SAzk8L3qWwSGpf3mqIHECmYaeJ0vh1cZ5wpfPTXG4cF3ugRkU6Krfk9vkFbv4+T5c1ZvWJbyFe2InqYDKoTUs8hjriOSy8tMBPSWUOIJdogD3kJViV77dqNU7PY9eSNUMGVL9/BsAR7DoyizLh43oLH+0wD2R6deGBa8m41ZujzGmNPT5iR+YZnpXO0G5GgTvpPyiWoFR5cj+/09BcEPxhJ+OxaJtdwDE20g5Z8MZi/o67/sfNJyT5ug8nfxAkWOJuf0pyEnKqi9nnCn53R+Xr6DROuE6TT8Ha5dC662Azla60GLY8QYC2HmMzgtybJPnLj27IoQZd3l5UXxSB8HGcPOUvY8tlScCoH02qiNLSnxKnfiXF1ykLYxHbgp8fGPnwCRxXs2sVz5zITFvaLbFxphJh7P/c/LsAdniiagGgnXh2Fk= 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)(110136005)(54906003)(107886003)(36756003)(8936002)(8676002)(186003)(26005)(6666004)(5660300002)(2906002)(336012)(426003)(1076003)(2616005)(498600001)(36860700001)(6636002)(82310400003)(47076005)(83380400001)(356005)(4326008)(70206006)(86362001)(70586007)(7636003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2021 16:08:58.0611 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d4c95ec2-3ecb-421b-a841-08d926a9e503 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.32];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT057.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5344 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This field will be used to allow pci modules to set some specific data that can be used for matching, aliases and other hints. Add example for "driver_override" pci drivers that will set a special prefix in the modules.alias table. In the future, this flag will enforce "driver_override" to work on drivers that specifically opt into this feature. The udev utility will not try to load these drivers automatically in order to bind to new discovered devices. This will be because the modalias tables populated by those drivers will be different from "regular" pci modalias tables. Userspace utilities, such as libvirt, will need to adjust and bind devices according to new matching mechanism with taking "driver_override" enforcement into consideration. Signed-off-by: Max Gurtovoy --- Documentation/PCI/pci.rst | 1 + include/linux/mod_devicetable.h | 9 +++++++++ include/linux/pci.h | 27 +++++++++++++++++++++++++++ scripts/mod/devicetable-offsets.c | 1 + scripts/mod/file2alias.c | 8 ++++++-- 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Documentation/PCI/pci.rst b/Documentation/PCI/pci.rst index 814b40f8360b..0855657daf93 100644 --- a/Documentation/PCI/pci.rst +++ b/Documentation/PCI/pci.rst @@ -103,6 +103,7 @@ need pass only as many optional fields as necessary: - subvendor and subdevice fields default to PCI_ANY_ID (FFFFFFFF) - class and classmask fields default to 0 - driver_data defaults to 0UL. + - flags field defaults to 0. Note that driver_data must match the value used by any of the pci_device_id entries defined in the driver. This makes the driver_data field mandatory diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h index 7d45b5f989b0..0f5c0355992c 100644 --- a/include/linux/mod_devicetable.h +++ b/include/linux/mod_devicetable.h @@ -16,6 +16,13 @@ typedef unsigned long kernel_ulong_t; #define PCI_ANY_ID (~0) + +enum pci_id_flags { + PCI_ID_F_VFIO_DRIVER_OVERRIDE = 1 << 0, +}; + +#define PCI_ID_F_DRIVER_OVERRIDE PCI_ID_F_VFIO_DRIVER_OVERRIDE + /** * struct pci_device_id - PCI device ID structure * @vendor: Vendor ID to match (or PCI_ANY_ID) @@ -34,12 +41,14 @@ typedef unsigned long kernel_ulong_t; * Best practice is to use driver_data as an index * into a static list of equivalent device types, * instead of using it as a pointer. + * @flags: PCI flags of the driver. Bitmap of pci_id_flags enum. */ struct pci_device_id { __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/ __u32 subvendor, subdevice; /* Subsystem ID's or PCI_ANY_ID */ __u32 class, class_mask; /* (class,subclass,prog-if) triplet */ kernel_ulong_t driver_data; /* Data private to the driver */ + __u32 flags; }; diff --git a/include/linux/pci.h b/include/linux/pci.h index c20211e59a57..602603526327 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -898,6 +898,33 @@ struct pci_driver { .vendor = (vend), .device = (dev), \ .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID +/** + * PCI_DEVICE_FLAGS - macro used to describe a PCI device with specific flags. + * @vend: the 16 bit PCI Vendor ID + * @dev: the 16 bit PCI Device ID + * @flags: PCI Device flags as a bitmap of pci_id_flags enum + * + * This macro is used to create a struct pci_device_id that matches a + * specific device. The subvendor and subdevice fields will be set to + * PCI_ANY_ID. + */ +#define PCI_DEVICE_FLAGS(vend, dev, fl) \ + .vendor = (vend), .device = (dev), .subvendor = PCI_ANY_ID, \ + .subdevice = PCI_ANY_ID, .flags = (fl) + +/** + * PCI_DRIVER_OVERRIDE_DEVICE_VFIO - macro used to describe a VFIO + * "driver_override" PCI device. + * @vend: the 16 bit PCI Vendor ID + * @dev: the 16 bit PCI Device ID + * + * This macro is used to create a struct pci_device_id that matches a + * specific device. The subvendor and subdevice fields will be set to + * PCI_ANY_ID and the flags will be set to PCI_ID_F_VFIO_DRIVER_OVERRIDE. + */ +#define PCI_DRIVER_OVERRIDE_DEVICE_VFIO(vend, dev) \ + PCI_DEVICE_FLAGS(vend, dev, PCI_ID_F_VFIO_DRIVER_OVERRIDE) + /** * PCI_DEVICE_SUB - macro used to describe a specific PCI device with subsystem * @vend: the 16 bit PCI Vendor ID diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-offsets.c index 9bb6c7edccc4..b927c36b8333 100644 --- a/scripts/mod/devicetable-offsets.c +++ b/scripts/mod/devicetable-offsets.c @@ -42,6 +42,7 @@ int main(void) DEVID_FIELD(pci_device_id, subdevice); DEVID_FIELD(pci_device_id, class); DEVID_FIELD(pci_device_id, class_mask); + DEVID_FIELD(pci_device_id, flags); DEVID(ccw_device_id); DEVID_FIELD(ccw_device_id, match_flags); diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 7c97fa8e36bc..b0add27de795 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -426,7 +426,7 @@ static int do_ieee1394_entry(const char *filename, return 1; } -/* Looks like: pci:vNdNsvNsdNbcNscNiN. */ +/* Looks like: pci:vNdNsvNsdNbcNscNiN or driver_override_pci:vNdNsvNsdNbcNscNiN. */ static int do_pci_entry(const char *filename, void *symval, char *alias) { @@ -440,8 +440,12 @@ static int do_pci_entry(const char *filename, DEF_FIELD(symval, pci_device_id, subdevice); DEF_FIELD(symval, pci_device_id, class); DEF_FIELD(symval, pci_device_id, class_mask); + DEF_FIELD(symval, pci_device_id, flags); - strcpy(alias, "pci:"); + if (flags & PCI_ID_F_VFIO_DRIVER_OVERRIDE) + strcpy(alias, "vfio_pci:"); + else + strcpy(alias, "pci:"); ADD(alias, "v", vendor != PCI_ANY_ID, vendor); ADD(alias, "d", device != PCI_ANY_ID, device); ADD(alias, "sv", subvendor != PCI_ANY_ID, subvendor); From patchwork Thu Jun 3 16:08:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Gurtovoy X-Patchwork-Id: 12297539 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDF26C47096 for ; Thu, 3 Jun 2021 16:09:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C88AF613EE for ; Thu, 3 Jun 2021 16:09:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229753AbhFCQK5 (ORCPT ); Thu, 3 Jun 2021 12:10:57 -0400 Received: from mail-bn8nam12on2085.outbound.protection.outlook.com ([40.107.237.85]:47201 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230329AbhFCQKy (ORCPT ); Thu, 3 Jun 2021 12:10:54 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WT8lqrriDdlmoXR/tblJc7+VIXchOd6u8K41Y0/ILV0VCSzUQ4lMdJDnMBanV+FmlTL9nrra7nGVsU/IdkI5gMf1jRC/Tkg2+ipONt+99VZK6l1urlDnIbRJ7MabNmplD43mdZof4gA6srwQD7p2oPLip18xU44ngWz3rDRYQAcNhg/5x1LdqZOqwzXK/qOD0nxu+ztzGD/8DbTYvqgEIM4aqeSu2dpynykvEOmLzUcDfDg+NKmMySfucigjy/7aHB/ysCWEpty0pjAPfUlRNXn3Xdyc6tIHw7DYCWOLLOo8hO4Vpmhb2vFlI0dLW1X0+9eZvrw1lKYgY5w0Gu8xAg== 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-SenderADCheck; bh=XHErFZdmeWBERuCyLPF7f7NhUfBS8lsQWkNRfjOOMvo=; b=fTZUJfzlw4POm80iEDW2EMSvy0ASFWkYl+hbRVS73G65bXvRjedIOhUaTMiy4nJhPzw/k3QEjLHJImz+lDlvRZ0ZujBN06DfjbFTfoRACjkfHhd8WSoH+/XWtDRLydxW61mPQsEoZ3MSc/1/mO5OAYcR/G/7EmH4OnOPkVk6Ii8+nX0fMBbphfFyCuqm9yoSs2J/YAUwTyEX4w/3brnkd4oBWxW0MWINk1fKOWpRSNCxDV7WsFkIOI1hkVyWksJ/3t09n6wka+6Ksxwdq8wWopeXo834/UEh0jWXeVGcFhU+Ih72kYggxiOZ9efOue4cRjPlaIpQJnHCx4LgD/SBmg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none 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=XHErFZdmeWBERuCyLPF7f7NhUfBS8lsQWkNRfjOOMvo=; b=Z2Od/6yBIF/oL4YeQ1l/vANzE/S2Dz+j8zAaTNcRQu2M4FNQvPmho8npW6DrpFOi6kcl4AQm1iYxIY2x5W3XXTbmu2RtHc8+gQJeTUxcY20zWt53Bu5yfZ73uz2p/5MDGETyk35FBSSMUW3jbzuaVKLCb0Q/MYyjmdBn5m9ztNMLB6OXGXwhrzVUGVGy5NFd4/XDqmSk0yokvXbA3NBHOxgcgShftZGIhFW7+R7ijyA7HCHCitBJLra+anjvzqhbo8umxgVJvaXLkrINTa4uF6yCbHNUxP2Y2SfbazFeCXZkmZ6d47DjWIv/BFqIDoH9yvCtSgs51hJBPpRojfTBew== Received: from MW4PR03CA0031.namprd03.prod.outlook.com (2603:10b6:303:8e::6) by MWHPR12MB1615.namprd12.prod.outlook.com (2603:10b6:301:10::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.27; Thu, 3 Jun 2021 16:09:06 +0000 Received: from CO1NAM11FT006.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8e:cafe::44) by MW4PR03CA0031.outlook.office365.com (2603:10b6:303:8e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.15 via Frontend Transport; Thu, 3 Jun 2021 16:09:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; huawei.com; dkim=none (message not signed) header.d=none;huawei.com; 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 CO1NAM11FT006.mail.protection.outlook.com (10.13.174.246) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4195.22 via Frontend Transport; Thu, 3 Jun 2021 16:09:03 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 3 Jun 2021 16:09:02 +0000 Received: from r-arch-stor02.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 3 Jun 2021 16:08:57 +0000 From: Max Gurtovoy To: , , , , CC: , , , , , , , , , , , , , , , Max Gurtovoy Subject: [PATCH 09/11] PCI: add matching checks for driver_override binding Date: Thu, 3 Jun 2021 19:08:07 +0300 Message-ID: <20210603160809.15845-10-mgurtovoy@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210603160809.15845-1-mgurtovoy@nvidia.com> References: <20210603160809.15845-1-mgurtovoy@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e1c03cc3-0dc5-48fd-854a-08d926a9e805 X-MS-TrafficTypeDiagnostic: MWHPR12MB1615: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LsjRjNVGy+Kwi4BCUfDmijghYGIyB9yYl/g109myCfTLmj9rmHZEPEE+ynUYr7Zjpc+vLmh7WrRqvu7b90sh4FR5y+rjvxkL4OAmOwGJeUIRIsdx9Od9jAWt/qML/76zEojvXMIj4b6NK/XwPbEKGEt/hHt+fe2StCKSh+QzuhnkMk4ehs5n33nbGb3esPsH9Dot/n7agCSqiwZC70u168JpTJMqmtOVSu3fAAbiQfF3Zv9cJagvkk09Sodm+xMDlRky1lSLVbdpSQW1qbyCVM4HyWRCifxWRK5eQChj95UeNgNAlvS+RsEUgN6X2meRQ75g6BJAytR1rCGXi6UIrVinh4aqnDfAlRR1kJlbOhwnkDE5X/4BYOOEHta12pqilv4H9eah7lYafiSI8bzjnIdLAk0iVIE97R+aPVma5Pe8W/MH781hyaigAuIw01EiOanLJy24t2JnMCr2jdg+o8Ydi5pv9LUBCnO4WdrTJQTZw4CLYp7Fmu4ChyWKuAhSaJK+kI2cF0olVK2RA/XDmezyUyGZkHZ1nksGrxEEd9PKZzW4KDP47Hf9aZ46U9Rp+z8KQK0QJkyMGRhdzxO5yH9ONB7+He+rEpMR0rLfSOfQ30A59BbmFjA6kEfRR32cXbaPjRBuNETANcqzy2IXVNTPyfcukzbz75UAsEzn04c= 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)(136003)(396003)(346002)(376002)(39860400002)(46966006)(36840700001)(8936002)(6636002)(82310400003)(8676002)(36860700001)(5660300002)(86362001)(47076005)(83380400001)(4326008)(107886003)(1076003)(356005)(316002)(36906005)(426003)(110136005)(54906003)(478600001)(82740400003)(36756003)(2616005)(336012)(2906002)(186003)(70206006)(7636003)(26005)(6666004)(70586007);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2021 16:09:03.2530 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e1c03cc3-0dc5-48fd-854a-08d926a9e805 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: CO1NAM11FT006.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1615 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Allowing any driver in the system to be unconditionally bound to any PCI HW is dangerous. Connecting a driver to a physical HW device it was never intended to operate may trigger exploitable kernel bugs, or worse. It also allows userspace to load and run kernel code that otherwise would never be runnable on the system. driver_override was designed to make it easier to load vfio_pci, so focus it on that single use case. driver_override will only work on drivers that specifically opt into this feature and the driver now has the opportunity to provide a proper match table that indicates what HW it can properly support. vfio-pci continues to support everything. This also causes the modalias tables to be populated with dedicated match table and userspace now becomes aware that vfio-pci can be loaded against any PCI device using driver_override. Signed-off-by: Max Gurtovoy Signed-off-by: Max Gurtovoy Signed-off-by: Max Gurtovoy --- Documentation/ABI/testing/sysfs-bus-pci | 6 +++++- drivers/pci/pci-driver.c | 22 ++++++++++++---------- drivers/vfio/pci/vfio_pci.c | 9 ++++++++- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci index ef00fada2efb..6d78970b1c69 100644 --- a/Documentation/ABI/testing/sysfs-bus-pci +++ b/Documentation/ABI/testing/sysfs-bus-pci @@ -289,7 +289,11 @@ Description: will not bind to any driver. This also allows devices to opt-out of driver binding using a driver_override name such as "none". Only a single driver may be specified in the override, - there is no support for parsing delimiters. + there is no support for parsing delimiters. The binding to the + device is allowed if and only if the matching driver has + enabled the driver_override alias in the ID table (by setting + a suitable bit in the "flags" field of pci_device_id + structure). What: /sys/bus/pci/devices/.../numa_node Date: Oct 2014 diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index ec44a79e951a..e4037db817da 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -115,13 +115,6 @@ const struct pci_device_id *pci_match_id(const struct pci_device_id *ids, } EXPORT_SYMBOL(pci_match_id); -static const struct pci_device_id pci_device_id_any = { - .vendor = PCI_ANY_ID, - .device = PCI_ANY_ID, - .subvendor = PCI_ANY_ID, - .subdevice = PCI_ANY_ID, -}; - /** * pci_match_device - See if a device matches a driver's list of IDs * @drv: the PCI driver to match against @@ -137,6 +130,7 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv, { struct pci_dynid *dynid; const struct pci_device_id *found_id = NULL; + bool is_driver_override; /* When driver_override is set, only bind to the matching driver */ if (dev->driver_override && strcmp(dev->driver_override, drv->name)) @@ -155,9 +149,17 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv, if (!found_id) found_id = pci_match_id(drv->id_table, dev); - /* driver_override will always match, send a dummy id */ - if (!found_id && dev->driver_override) - found_id = &pci_device_id_any; + /* + * if and only if PCI_ID_F_DRIVER_OVERRIDE flag is set, driver_override + * should be provided. + */ + if (found_id) { + is_driver_override = + (found_id->flags & PCI_ID_F_DRIVER_OVERRIDE) != 0; + if ((is_driver_override && !dev->driver_override) || + (dev->driver_override && !is_driver_override)) + return NULL; + } return found_id; } diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 850ea3a94e28..9beb4b841945 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -166,9 +166,16 @@ static int vfio_pci_sriov_configure(struct pci_dev *pdev, int nr_virtfn) return vfio_pci_core_sriov_configure(pdev, nr_virtfn); } +static const struct pci_device_id vfio_pci_table[] = { + { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_ANY_ID, PCI_ANY_ID) }, /* match all by default */ + { 0, } +}; + +MODULE_DEVICE_TABLE(pci, vfio_pci_table); + static struct pci_driver vfio_pci_driver = { .name = "vfio-pci", - .id_table = NULL, /* only dynamic ids */ + .id_table = vfio_pci_table, .probe = vfio_pci_probe, .remove = vfio_pci_remove, .sriov_configure = vfio_pci_sriov_configure, From patchwork Thu Jun 3 16:08:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Gurtovoy X-Patchwork-Id: 12297537 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69428C47082 for ; Thu, 3 Jun 2021 16:09:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 45624613F3 for ; Thu, 3 Jun 2021 16:09:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230331AbhFCQK6 (ORCPT ); Thu, 3 Jun 2021 12:10:58 -0400 Received: from mail-dm3nam07on2061.outbound.protection.outlook.com ([40.107.95.61]:64481 "EHLO NAM02-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230284AbhFCQK4 (ORCPT ); Thu, 3 Jun 2021 12:10:56 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y1H6xWbGcuoDDMIYB77OgKgWkbvZNUGqneWchR+xyP+LyeFfZsXCiArg9N3h4GhImJviCBFbYxlGgaadaQTuAb2yhk9jlhZhY5Chu2a/KmLfwV6S2yUHl9YfGtAfA2a9UqUN8dumOAYxPzMqj9aWgMHjSHSeIAzqtWKE+FAPu4DPDwn/R1m/5UEm6m2/BfRZgUxV+22HkeGNa0hMWyjjMQv7/SEssvr4PVo9xnt+fgJDQURrgh50SLIYYekWHbhGCr4/22cfjUkbjUHG4wkqS9FkIfchYRzjInBlMcNDtfB17gLL9K10TbtKo+SWU/qvx9NjIepxcEcZNmjjqgsaiw== 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-SenderADCheck; bh=lyIz480FSUC4OW/wskj6QchUea2/SO/0meplgDdTlto=; b=VaTg81EgJAe8meGDGDNVUv3zjNaZh/Fr2oPeESQO987wciS5fwDkZ9Zov07yn5X1fjj27uzyViU5zGIwsEfdQ7ihYESps/ec3DtGiPNezfE4kOnhp9djH45fhF5//bw6sF3j57cAhRUh8eRuPjCo00NH3hAiQ0IreXCfzkB21adnd64kdAWYMqx2L17cyNb0raM66B24RqmbyM4fcDPppa8uGEr0rMz+eqL9BH3FA1MRemyFDHK634YTU4K6aeLWVpSMLfgdM68sDMTuVyECDQyKntmuotZGJpsgezCcJMm0kQgfHLregSr11jNgJCmH+cO/N//q16gI2Ze69uTjTg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none 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=lyIz480FSUC4OW/wskj6QchUea2/SO/0meplgDdTlto=; b=OJMpWTj6Ov+5vdds981jZXuaImef304PDmFaOSPrhSipNBm40l4F1dijRBork4uhLJ32L7J0iC8iB6GSGIkn4Xi/oNaCwXr6fniuo6nyiSTY/5/DZVqX7MJxmzIRDWVWW9I4p4jhY6fnJjFQB9HQx6ItMCTpXYedPgEs0nGNy0jfZN7W22Xz9S8QgSWbDGU1iLw4fQ+cb+JWJ0St6Ks4oYF8nfSurdDRlkVSwtRKmZ6eKh9JFTFFqutcio/1QbrGUE1bvY3pGZoN81fcqFwMhanZHkJ/GSlAG2j4wu3CXrTvSxjmToEkr0gZzXFmoF2j3cyxotpYLfgtAuhbXE4O8A== Received: from BN6PR21CA0024.namprd21.prod.outlook.com (2603:10b6:404:8e::34) by BN6PR12MB1844.namprd12.prod.outlook.com (2603:10b6:404:fc::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.21; Thu, 3 Jun 2021 16:09:09 +0000 Received: from BN8NAM11FT007.eop-nam11.prod.protection.outlook.com (2603:10b6:404:8e:cafe::ab) by BN6PR21CA0024.outlook.office365.com (2603:10b6:404:8e::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.3 via Frontend Transport; Thu, 3 Jun 2021 16:09:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; huawei.com; dkim=none (message not signed) header.d=none;huawei.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT007.mail.protection.outlook.com (10.13.177.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4195.22 via Frontend Transport; Thu, 3 Jun 2021 16:09:09 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 3 Jun 2021 09:09:07 -0700 Received: from r-arch-stor02.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 3 Jun 2021 16:09:02 +0000 From: Max Gurtovoy To: , , , , CC: , , , , , , , , , , , , , , , Max Gurtovoy Subject: [PATCH 10/11] vfio-pci: introduce vfio_pci_core subsystem driver Date: Thu, 3 Jun 2021 19:08:08 +0300 Message-ID: <20210603160809.15845-11-mgurtovoy@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210603160809.15845-1-mgurtovoy@nvidia.com> References: <20210603160809.15845-1-mgurtovoy@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7c2788eb-feb3-476f-60ba-08d926a9ebb2 X-MS-TrafficTypeDiagnostic: BN6PR12MB1844: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2803; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Agg1b8PnBJEDoIVFn5066QZsTPGSH+0vsEhyLEKQh/3zWpOirdpWjC1NFJmyFN0ypQy0Z9B7ipkPZJdPCrHl5sfR/wEhBS7H5jaFYiFqjs+CG635+KrRvjvlVlANVjBG/7A+ir+XkyIdMILbYudqhSd31vPQJEHbJWrT+kGVM3lthhE46xuzCQPzRT4AyuoZ9ToEhC9iOIFfiHh3LtUx6I5Nc/4cH9eV1BSjAVkdqECCisR614AS/pZdxtASpLsgPI7djuKBJvhYgWrntT/vFq59hL9vkrk5Urx1dG6nCwLurHO32/9MVKmoLg9aV45EKpxKdpsgCxk0YaSs96zDfykLF38WIchmBHLfskQNnUIfj4lCMcV0Xyp4Zjl7mjSY6jDI2WBIUFvRCRelAMZoVQUpyAiEvlCsN373gz5vIyBWJNqExURu8jZFLgAnO69ndApIh9MI2TarWGMsgdcrdz2EvQzydpHLkAr0pRTx0KRzWxtkBdkG9WR7DOR0GzqZp70s4ge7D4diIGQFqbYNHGuxygrCS8TbIG4hcZBQovwc0B1acA1fpXHNbAcg+j6HqhkDLqtsLkwiCIwMw8Tjm8Br2stbAR4EKMlVvkCrwePgMwC1ZeW5kl5HCmPDabHG4kdEwfhNhRdm/1otidoYYA3d2hIZStr/3Hakt7ZvLwc= 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)(36756003)(1076003)(30864003)(5660300002)(4326008)(7636003)(6636002)(356005)(86362001)(8936002)(8676002)(107886003)(498600001)(70586007)(47076005)(186003)(36860700001)(2616005)(2906002)(70206006)(26005)(82310400003)(426003)(336012)(83380400001)(110136005)(54906003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2021 16:09:09.3401 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7c2788eb-feb3-476f-60ba-08d926a9ebb2 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: BN8NAM11FT007.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1844 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Now that vfio_pci has been split into two source modules, one focusing on the "struct pci_driver" (vfio_pci.c) and a toolbox library of code (vfio_pci_core.c), complete the split and move them into two different modules. As before vfio_pci.ko continues to present the same interface under sysfs and this change will have no functional impact. Below is an example for adding new driver that will use vfio pci subsystem: +---------------------------------------------------+ | | | VFIO | | | +---------------------------------------------------+ +---------------------------------------------------+ | | | VFIO_PCI_CORE | | | +---------------------------------------------------+ +----------+ +---------------+ +--------------------+ | | | | | | | VFIO_PCI | | MLX5_VFIO_PCI | | HISILICON_VFIO_PCI | | | | | | | +----------+ +---------------+ +--------------------+ Splitting into another module and adding exports allows creating new HW specific vfio_pci drivers that can implement device specific functionality, such as VFIO migration interfaces or specialized device requirements. Signed-off-by: Max Gurtovoy --- drivers/vfio/pci/Kconfig | 18 ++++++--- drivers/vfio/pci/Makefile | 11 +++-- drivers/vfio/pci/vfio_pci.c | 14 ++----- drivers/vfio/pci/vfio_pci_config.c | 2 +- drivers/vfio/pci/vfio_pci_core.c | 40 ++++++++++++++++--- drivers/vfio/pci/vfio_pci_igd.c | 2 +- drivers/vfio/pci/vfio_pci_intrs.c | 2 +- drivers/vfio/pci/vfio_pci_rdwr.c | 2 +- drivers/vfio/pci/vfio_pci_zdev.c | 2 +- .../pci => include/linux}/vfio_pci_core.h | 10 ++--- 10 files changed, 66 insertions(+), 37 deletions(-) rename {drivers/vfio/pci => include/linux}/vfio_pci_core.h (96%) diff --git a/drivers/vfio/pci/Kconfig b/drivers/vfio/pci/Kconfig index 5e2e1b9a9fd3..384d06661f30 100644 --- a/drivers/vfio/pci/Kconfig +++ b/drivers/vfio/pci/Kconfig @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only -config VFIO_PCI - tristate "VFIO support for PCI devices" +config VFIO_PCI_CORE + tristate "VFIO core support for PCI devices" depends on VFIO && PCI && EVENTFD depends on MMU select VFIO_VIRQFD @@ -11,9 +11,17 @@ config VFIO_PCI If you don't know what to do here, say N. +config VFIO_PCI + tristate "VFIO support for PCI devices" + depends on VFIO_PCI_CORE + help + This provides a generic PCI support using the VFIO framework. + + If you don't know what to do here, say N. + config VFIO_PCI_VGA bool "VFIO PCI support for VGA devices" - depends on VFIO_PCI && X86 && VGA_ARB + depends on VFIO_PCI_CORE && X86 && VGA_ARB help Support for VGA extension to VFIO PCI. This exposes an additional region on VGA devices for accessing legacy VGA addresses used by @@ -22,11 +30,11 @@ config VFIO_PCI_VGA If you don't know what to do here, say N. config VFIO_PCI_MMAP - depends on VFIO_PCI + depends on VFIO_PCI_CORE def_bool y if !S390 config VFIO_PCI_INTX - depends on VFIO_PCI + depends on VFIO_PCI_CORE def_bool y if !S390 config VFIO_PCI_IGD diff --git a/drivers/vfio/pci/Makefile b/drivers/vfio/pci/Makefile index 8aa517b4b671..ddba4759cde7 100644 --- a/drivers/vfio/pci/Makefile +++ b/drivers/vfio/pci/Makefile @@ -1,7 +1,10 @@ # SPDX-License-Identifier: GPL-2.0-only -vfio-pci-y := vfio_pci.o vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o -vfio-pci-$(CONFIG_VFIO_PCI_IGD) += vfio_pci_igd.o -vfio-pci-$(CONFIG_S390) += vfio_pci_zdev.o - +obj-$(CONFIG_VFIO_PCI_CORE) += vfio-pci-core.o obj-$(CONFIG_VFIO_PCI) += vfio-pci.o + +vfio-pci-core-y := vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o +vfio-pci-core-$(CONFIG_S390) += vfio_pci_zdev.o + +vfio-pci-y := vfio_pci.o +vfio-pci-$(CONFIG_VFIO_PCI_IGD) += vfio_pci_igd.o diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 9beb4b841945..56870a6540d7 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -25,7 +25,7 @@ #include #include -#include "vfio_pci_core.h" +#include #define DRIVER_VERSION "0.2" #define DRIVER_AUTHOR "Alex Williamson " @@ -141,6 +141,7 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (ret) goto out_free; + dev_set_drvdata(&pdev->dev, vdev); return 0; out_free: @@ -185,7 +186,6 @@ static struct pci_driver vfio_pci_driver = { static void __exit vfio_pci_cleanup(void) { pci_unregister_driver(&vfio_pci_driver); - vfio_pci_core_cleanup(); } static void __init vfio_pci_fill_ids(void) @@ -233,14 +233,10 @@ static int __init vfio_pci_init(void) { int ret; - ret = vfio_pci_core_init(); - if (ret) - return ret; - /* Register and scan for devices */ ret = pci_register_driver(&vfio_pci_driver); if (ret) - goto out; + return ret; vfio_pci_fill_ids(); @@ -248,10 +244,6 @@ static int __init vfio_pci_init(void) pr_warn("device denylist disabled.\n"); return 0; - -out: - vfio_pci_core_cleanup(); - return ret; } module_init(vfio_pci_init); diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c index 1f034f768a27..6e58b4bf7a60 100644 --- a/drivers/vfio/pci/vfio_pci_config.c +++ b/drivers/vfio/pci/vfio_pci_config.c @@ -26,7 +26,7 @@ #include #include -#include "vfio_pci_core.h" +#include /* Fake capability ID for standard config space */ #define PCI_CAP_ID_BASIC 0 diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 39a3f18bbc08..a1ce79160f6f 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -8,6 +8,8 @@ * Author: Tom Lyon, pugs@cisco.com */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include #include #include @@ -25,7 +27,11 @@ #include #include -#include "vfio_pci_core.h" +#include + +#define DRIVER_VERSION "0.2" +#define DRIVER_AUTHOR "Alex Williamson " +#define DRIVER_DESC "core driver for VFIO based PCI devices" static bool nointxmask; module_param_named(nointxmask, nointxmask, bool, S_IRUGO | S_IWUSR); @@ -316,6 +322,7 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev) return 0; } +EXPORT_SYMBOL_GPL(vfio_pci_core_enable); void vfio_pci_core_disable(struct vfio_pci_core_device *vdev) { @@ -415,6 +422,7 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev) if (!disable_idle_d3) vfio_pci_set_power_state(vdev, PCI_D3hot); } +EXPORT_SYMBOL_GPL(vfio_pci_core_disable); static struct vfio_pci_core_device *get_pf_vdev(struct vfio_pci_core_device *vdev) { @@ -473,6 +481,7 @@ void vfio_pci_core_release(struct vfio_device *core_vdev) } mutex_unlock(&vdev->igate); } +EXPORT_SYMBOL_GPL(vfio_pci_core_release); void vfio_pci_core_finish_enable(struct vfio_pci_core_device *vdev) { @@ -480,6 +489,7 @@ void vfio_pci_core_finish_enable(struct vfio_pci_core_device *vdev) vfio_spapr_pci_eeh_open(vdev->pdev); vfio_pci_vf_token_user_add(vdev, 1); } +EXPORT_SYMBOL_GPL(vfio_pci_core_finish_enable); int vfio_pci_core_open(struct vfio_device *core_vdev) { @@ -497,6 +507,7 @@ int vfio_pci_core_open(struct vfio_device *core_vdev) return 0; } +EXPORT_SYMBOL_GPL(vfio_pci_core_open); static int vfio_pci_get_irq_count(struct vfio_pci_core_device *vdev, int irq_type) { @@ -681,6 +692,7 @@ int vfio_pci_register_dev_region(struct vfio_pci_core_device *vdev, return 0; } +EXPORT_SYMBOL_GPL(vfio_pci_register_dev_region); struct vfio_devices { struct vfio_pci_core_device **devices; @@ -1287,6 +1299,7 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, return -ENOTTY; } +EXPORT_SYMBOL_GPL(vfio_pci_core_ioctl); static ssize_t vfio_pci_rw(struct vfio_pci_core_device *vdev, char __user *buf, size_t count, loff_t *ppos, bool iswrite) @@ -1330,6 +1343,7 @@ ssize_t vfio_pci_core_read(struct vfio_device *core_vdev, char __user *buf, return vfio_pci_rw(vdev, buf, count, ppos, false); } +EXPORT_SYMBOL_GPL(vfio_pci_core_read); ssize_t vfio_pci_core_write(struct vfio_device *core_vdev, const char __user *buf, size_t count, loff_t *ppos) @@ -1342,6 +1356,7 @@ ssize_t vfio_pci_core_write(struct vfio_device *core_vdev, const char __user *bu return vfio_pci_rw(vdev, (char __user *)buf, count, ppos, true); } +EXPORT_SYMBOL_GPL(vfio_pci_core_write); /* Return 1 on zap and vma_lock acquired, 0 on contention (only with @try) */ static int vfio_pci_zap_and_vma_lock(struct vfio_pci_core_device *vdev, bool try) @@ -1607,6 +1622,7 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma return 0; } +EXPORT_SYMBOL_GPL(vfio_pci_core_mmap); void vfio_pci_core_request(struct vfio_device *core_vdev, unsigned int count) { @@ -1629,6 +1645,7 @@ void vfio_pci_core_request(struct vfio_device *core_vdev, unsigned int count) mutex_unlock(&vdev->igate); } +EXPORT_SYMBOL_GPL(vfio_pci_core_request); static int vfio_pci_validate_vf_token(struct vfio_pci_core_device *vdev, bool vf_token, uuid_t *uuid) @@ -1773,6 +1790,7 @@ int vfio_pci_core_match(struct vfio_device *core_vdev, char *buf) return 1; /* Match */ } +EXPORT_SYMBOL_GPL(vfio_pci_core_match); static int vfio_pci_reflck_find(struct pci_dev *pdev, void *data) { @@ -1814,6 +1832,7 @@ int vfio_pci_core_reflck_attach(struct vfio_device *core_vdev) return PTR_ERR_OR_ZERO(core_vdev->reflck); } +EXPORT_SYMBOL_GPL(vfio_pci_core_reflck_attach); static int vfio_pci_bus_notifier(struct notifier_block *nb, unsigned long action, void *data) @@ -1972,7 +1991,6 @@ int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev, ret = vfio_register_group_dev(&vdev->vdev); if (ret) goto out_power; - dev_set_drvdata(&pdev->dev, vdev); return 0; out_power: @@ -1987,6 +2005,7 @@ int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev, vfio_iommu_group_put(group, &pdev->dev); return ret; } +EXPORT_SYMBOL_GPL(vfio_pci_core_register_device); void vfio_pci_core_unregister_device(struct vfio_pci_core_device *vdev) { @@ -2009,6 +2028,7 @@ void vfio_pci_core_unregister_device(struct vfio_pci_core_device *vdev) kfree(vdev->region); kfree(vdev->pm_save); } +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) @@ -2054,10 +2074,12 @@ int vfio_pci_core_sriov_configure(struct pci_dev *pdev, int nr_virtfn) return ret < 0 ? ret : nr_virtfn; } +EXPORT_SYMBOL_GPL(vfio_pci_core_sriov_configure); const struct pci_error_handlers vfio_pci_core_err_handlers = { .error_detected = vfio_pci_aer_err_detected, }; +EXPORT_SYMBOL_GPL(vfio_pci_core_err_handlers); static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data) { @@ -2197,15 +2219,21 @@ static void vfio_pci_try_bus_reset(struct vfio_pci_core_device *vdev) kfree(devs.devices); } -/* This will become the __exit function of vfio_pci_core.ko */ -void vfio_pci_core_cleanup(void) +static void vfio_pci_core_cleanup(void) { vfio_pci_uninit_perm_bits(); } -/* This will become the __init function of vfio_pci_core.ko */ -int __init vfio_pci_core_init(void) +static int __init vfio_pci_core_init(void) { /* Allocate shared config space permission data used by all devices */ return vfio_pci_init_perm_bits(); } + +module_init(vfio_pci_core_init); +module_exit(vfio_pci_core_cleanup); + +MODULE_VERSION(DRIVER_VERSION); +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR(DRIVER_AUTHOR); +MODULE_DESCRIPTION(DRIVER_DESC); diff --git a/drivers/vfio/pci/vfio_pci_igd.c b/drivers/vfio/pci/vfio_pci_igd.c index 2295eaac4bc9..f04774cd3a7f 100644 --- a/drivers/vfio/pci/vfio_pci_igd.c +++ b/drivers/vfio/pci/vfio_pci_igd.c @@ -15,7 +15,7 @@ #include #include -#include "vfio_pci_core.h" +#include #define OPREGION_SIGNATURE "IntelGraphicsMem" #define OPREGION_SIZE (8 * 1024) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 945ddbdf4d11..6069a11fb51a 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -20,7 +20,7 @@ #include #include -#include "vfio_pci_core.h" +#include /* * INTx diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c index 8fff4689dd44..57d3b2cbbd8e 100644 --- a/drivers/vfio/pci/vfio_pci_rdwr.c +++ b/drivers/vfio/pci/vfio_pci_rdwr.c @@ -17,7 +17,7 @@ #include #include -#include "vfio_pci_core.h" +#include #ifdef __LITTLE_ENDIAN #define vfio_ioread64 ioread64 diff --git a/drivers/vfio/pci/vfio_pci_zdev.c b/drivers/vfio/pci/vfio_pci_zdev.c index 2ffbdc11f089..fe4def9ffffb 100644 --- a/drivers/vfio/pci/vfio_pci_zdev.c +++ b/drivers/vfio/pci/vfio_pci_zdev.c @@ -19,7 +19,7 @@ #include #include -#include "vfio_pci_core.h" +#include /* * Add the Base PCI Function information to the device info region. diff --git a/drivers/vfio/pci/vfio_pci_core.h b/include/linux/vfio_pci_core.h similarity index 96% rename from drivers/vfio/pci/vfio_pci_core.h rename to include/linux/vfio_pci_core.h index 406e934e23b2..5a48c3c552b1 100644 --- a/drivers/vfio/pci/vfio_pci_core.h +++ b/include/linux/vfio_pci_core.h @@ -171,10 +171,10 @@ extern void vfio_pci_uninit_perm_bits(void); extern int vfio_config_init(struct vfio_pci_core_device *vdev); extern void vfio_config_free(struct vfio_pci_core_device *vdev); -extern int vfio_pci_register_dev_region(struct vfio_pci_core_device *vdev, - unsigned int type, unsigned int subtype, - const struct vfio_pci_regops *ops, - size_t size, u32 flags, void *data); +int vfio_pci_register_dev_region(struct vfio_pci_core_device *vdev, + unsigned int type, unsigned int subtype, + const struct vfio_pci_regops *ops, + size_t size, u32 flags, void *data); extern int vfio_pci_set_power_state(struct vfio_pci_core_device *vdev, pci_power_t state); @@ -207,8 +207,6 @@ static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, #endif /* Will be exported for vfio pci drivers usage */ -void vfio_pci_core_cleanup(void); -int vfio_pci_core_init(void); void vfio_pci_core_release(struct vfio_device *core_vdev); int vfio_pci_core_open(struct vfio_device *core_vdev); int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev, From patchwork Thu Jun 3 16:08:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Gurtovoy X-Patchwork-Id: 12297541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC92DC47082 for ; Thu, 3 Jun 2021 16:09:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B1E09613EE for ; Thu, 3 Jun 2021 16:09:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230351AbhFCQLD (ORCPT ); Thu, 3 Jun 2021 12:11:03 -0400 Received: from mail-dm6nam11on2070.outbound.protection.outlook.com ([40.107.223.70]:21888 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230048AbhFCQLC (ORCPT ); Thu, 3 Jun 2021 12:11:02 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AAry6ZJRz2+T58CUqWKFW9e9GRNbtPSLNZ9qsyF9YljRaOzIcnXIUs4btXS7Vx+CNMSYPJ82qbPz9wXeQRbfjyfnGk6UqZtKU/qghHp12vctmxJyFZI880wuFYqQ00kyfwfBQ1nz5/7B0HqALzyp3U+GEi1q6UziPGrtXufgjEo6csmV3wXLWowPAeZGd+ClU2cUbN37UdUlauNvGwpdvSm9EHcEvvJPg6fg4OgVg7tyM0+ii/5qrqsu1nRzgGj+fJWtuLU1/vSWFkmnnqUWDn/WRHilZFD9wefBXZIQ78y59j08tHrjDkeWsmRjFblM0CA0I3/FChY/6nMa6fEAsg== 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-SenderADCheck; bh=ubKKbABrpeG97j71RniAQ+2O6fSno18o9dpWL7ZMEF8=; b=Y/SU1QG09flVWyyOzVQTOvzm7SyLufDZuH+YRKaMyYDEhGLCzbOTjV7g/DzmzkBY9m4U1i7kPdKi6Pln8bEZ7DKLVqpqqX1APYuq/3ZttvSfhYGz3uWbzdz+yMjVl4zRFcdRGi8cvnw/npEdbAgQqfkexOEsC0SVl5vAOL3NSBpkpsuor/5Zu6Yy7xIzzB9qJQhAB/5H1oBJ4+iIQa+vLjw5Kc8MLoWcXNKhZJXyevnxLTSIA/IA1AwpZcMN0EmFC2uzzyXpVy/K8JZxIP2v7p4lKCcsBG/hRuyVnkTpLijWir4kCC7h27qbTpy50MQuyK3Qs31yVfAx/mnxEhCgnA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none 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=ubKKbABrpeG97j71RniAQ+2O6fSno18o9dpWL7ZMEF8=; b=L61lvj0+W83/nAIGnEkv2su9w2+fgRdCMyz0pE05RmfhMuYSOouVf3tBoY8DIT4i7Ntu19caIXZXjIujl/eZpuC4lpZlyOOAjUx3dNB85UDpd31FMW2GQqEwA8gm8Bepc9S2l0M0sCz1s4rgJ29h8bikOWvNMwLHfNUmGaKcXrcfXiD2wUj2nXOPByjSg60zG/PEfU2Ay46cSNyV5e8eWVHeuWD6LNtC33wT62r51vtZ5JSNTsu5TwX9sTHKkxuU8dwHd8kIRL94R5fY1Er9mOebxTqfV7xphjnsAt6sDYqmvowi4AD3PJzsN6IfmLJmRGLmjdTEZG+6nad92TJnKg== Received: from BN6PR21CA0018.namprd21.prod.outlook.com (2603:10b6:404:8e::28) by SN6PR12MB4751.namprd12.prod.outlook.com (2603:10b6:805:df::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.24; Thu, 3 Jun 2021 16:09:15 +0000 Received: from BN8NAM11FT007.eop-nam11.prod.protection.outlook.com (2603:10b6:404:8e:cafe::a8) by BN6PR21CA0018.outlook.office365.com (2603:10b6:404:8e::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.3 via Frontend Transport; Thu, 3 Jun 2021 16:09:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; huawei.com; dkim=none (message not signed) header.d=none;huawei.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT007.mail.protection.outlook.com (10.13.177.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4195.22 via Frontend Transport; Thu, 3 Jun 2021 16:09:15 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 3 Jun 2021 09:09:12 -0700 Received: from r-arch-stor02.mtr.labs.mlnx (172.20.187.5) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 3 Jun 2021 16:09:08 +0000 From: Max Gurtovoy To: , , , , CC: , , , , , , , , , , , , , , , Max Gurtovoy Subject: [PATCH 11/11] mlx5-vfio-pci: add new vfio_pci driver for mlx5 devices Date: Thu, 3 Jun 2021 19:08:09 +0300 Message-ID: <20210603160809.15845-12-mgurtovoy@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210603160809.15845-1-mgurtovoy@nvidia.com> References: <20210603160809.15845-1-mgurtovoy@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 91c72f39-a076-4633-4bdd-08d926a9ef7a X-MS-TrafficTypeDiagnostic: SN6PR12MB4751: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +gKxEFzRogquxedIutc1BPA0hQFxO7hEWYtRYclzAI15OS84vEh7ASOBowqYZTT9+qLc5SlcWgxUIelL687w2AlYtl2kTqfxTf/c4DjsOrD9f29kz9kv+4SxqF+SXMRxVcZl2v6UaKKvjDl7lmbDbTgw4PZ4KQ5bv/ArRS6J24+Mdm84PiATAaBZTcn8ajMslwLce5N0rmVPRxhrOiC/EofbW0jasWAzq6z260S3+jVj20vkfUgKgYjSN9J5c8IQ4lVZ40WrjgHJ4F5CyPq7TiP4zMb9y0SNgyyol+tYI29hawFXDVt7CX6ZWZL7qika66aw+IXqIgLeu/H18YrCE+vn6hxmRjWlOU+fs2NYyeOEkv437aHUT42deI2J6j2wz4Wn8UzIuuwGGwJRu+GDXmMV1bjoiiAdPPAo7tUwEm4xQhNm2Ap/gcuVky2BAj1U9KFMu5ToUCFs7a6RsIRQQ7u80YMIME/cxgvXeEP+nNzwcya2IMfabjoSimiRDGVASSC/oNE7ZtW8OXiFCnp5k2HTNk9VR8grDEfY6T3RxnVBQVygC0RXmKI9pQwF9jsZ89iKSZE41Uu8yPXHtWgAhkdlej04EQWPuKevlha5COgXmnJHwF1orG85it77tDb8vMLyE3N7AbX5lFqgIifTj8Kv9OPMHmSMoI3cW5Z7TSw= 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)(39860400002)(396003)(136003)(376002)(346002)(36840700001)(46966006)(2906002)(107886003)(478600001)(36860700001)(110136005)(83380400001)(54906003)(82310400003)(26005)(316002)(4326008)(36756003)(86362001)(47076005)(426003)(82740400003)(7636003)(1076003)(8936002)(6636002)(356005)(8676002)(70586007)(2616005)(186003)(5660300002)(70206006)(336012);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2021 16:09:15.6894 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 91c72f39-a076-4633-4bdd-08d926a9ef7a 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: BN8NAM11FT007.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB4751 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is the initial step for adding vendor specific vfio_pci driver for mlx5 devices. mlx5_vfio_pci use vfio_pci_core to register to the VFIO subsystem and also to implement the basic functionality of a pci device. It will also extend this basic functionality and add mlx5 specific logic for various features (such as live migration, for example). Note: Although we've created the mlx5-vfio-pci.ko, the binding to vfio-pci.ko will still work as before. It's fully backward compatible. Of course, the extended vendor functionality will not exist in case one will bind the device to the generic vfio_pci.ko. Signed-off-by: Max Gurtovoy --- drivers/vfio/pci/Kconfig | 9 +++ drivers/vfio/pci/Makefile | 3 + drivers/vfio/pci/mlx5_vfio_pci.c | 130 +++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 drivers/vfio/pci/mlx5_vfio_pci.c diff --git a/drivers/vfio/pci/Kconfig b/drivers/vfio/pci/Kconfig index 384d06661f30..9cdef46dd299 100644 --- a/drivers/vfio/pci/Kconfig +++ b/drivers/vfio/pci/Kconfig @@ -48,3 +48,12 @@ config VFIO_PCI_IGD and LPC bridge config space. To enable Intel IGD assignment through vfio-pci, say Y. + +config MLX5_VFIO_PCI + tristate "VFIO support for MLX5 PCI devices" + depends on VFIO_PCI_CORE && MLX5_CORE + help + This provides a generic PCI 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/Makefile b/drivers/vfio/pci/Makefile index ddba4759cde7..a0df9c2a4bd9 100644 --- a/drivers/vfio/pci/Makefile +++ b/drivers/vfio/pci/Makefile @@ -2,9 +2,12 @@ obj-$(CONFIG_VFIO_PCI_CORE) += vfio-pci-core.o obj-$(CONFIG_VFIO_PCI) += vfio-pci.o +obj-$(CONFIG_MLX5_VFIO_PCI) += mlx5-vfio-pci.o vfio-pci-core-y := vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o vfio-pci-core-$(CONFIG_S390) += vfio_pci_zdev.o vfio-pci-y := vfio_pci.o vfio-pci-$(CONFIG_VFIO_PCI_IGD) += vfio_pci_igd.o + +mlx5-vfio-pci-y := mlx5_vfio_pci.o diff --git a/drivers/vfio/pci/mlx5_vfio_pci.c b/drivers/vfio/pci/mlx5_vfio_pci.c new file mode 100644 index 000000000000..0153682a3d3f --- /dev/null +++ b/drivers/vfio/pci/mlx5_vfio_pci.c @@ -0,0 +1,130 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2021, Mellanox Technologies. All rights reserved. + * Author: Max Gurtovoy + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +static int mlx5_vfio_pci_open(struct vfio_device *core_vdev) +{ + struct vfio_pci_core_device *vdev = + container_of(core_vdev, struct vfio_pci_core_device, vdev); + int ret; + + lockdep_assert_held(&core_vdev->reflck->lock); + + ret = vfio_pci_core_enable(vdev); + if (ret) + return ret; + + /* TODO: register migration region here for capable devices */ + + vfio_pci_core_finish_enable(vdev); + + return 0; +} + +static const struct vfio_device_ops mlx5_vfio_pci_ops = { + .name = "mlx5-vfio-pci", + .open = mlx5_vfio_pci_open, + .release = vfio_pci_core_release, + .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, + .reflck_attach = vfio_pci_core_reflck_attach, +}; + +static int mlx5_vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) +{ + struct vfio_pci_core_device *vdev; + int ret; + + vdev = kzalloc(sizeof(*vdev), GFP_KERNEL); + if (!vdev) + return -ENOMEM; + + ret = vfio_pci_core_register_device(vdev, pdev, &mlx5_vfio_pci_ops); + if (ret) + goto out_free; + + dev_set_drvdata(&pdev->dev, vdev); + return 0; + +out_free: + kfree(vdev); + return ret; +} + +static void mlx5_vfio_pci_remove(struct pci_dev *pdev) +{ + struct vfio_pci_core_device *vdev = dev_get_drvdata(&pdev->dev); + + vfio_pci_core_unregister_device(vdev); + kfree(vdev); +} + +static const struct pci_device_id mlx5_vfio_pci_table[] = { + { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_MELLANOX, 0x101b) }, /* ConnectX-6 */ + { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_MELLANOX, 0x101c) }, /* ConnectX-6 VF */ + { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_MELLANOX, 0x101d) }, /* ConnectX-6 Dx */ + { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_MELLANOX, 0x101e) }, /* ConnectX Family mlx5Gen Virtual Function */ + { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_MELLANOX, 0x101f) }, /* ConnectX-6 LX */ + { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_MELLANOX, 0x1021) }, /* ConnectX-7 */ + { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_MELLANOX, 0xa2d2) }, /* BlueField integrated ConnectX-5 network controller */ + { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_MELLANOX, 0xa2d3) }, /* BlueField integrated ConnectX-5 network controller VF */ + { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_MELLANOX, 0xa2d6) }, /* BlueField-2 integrated ConnectX-6 Dx network controller */ + { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_MELLANOX, 0xa2dc) }, /* BlueField-3 integrated ConnectX-7 network controller */ + { 0, } +}; + +MODULE_DEVICE_TABLE(pci, mlx5_vfio_pci_table); + +static struct pci_driver mlx5_vfio_pci_driver = { + .name = "mlx5-vfio-pci", + .id_table = mlx5_vfio_pci_table, + .probe = mlx5_vfio_pci_probe, + .remove = mlx5_vfio_pci_remove, +#ifdef CONFIG_PCI_IOV + .sriov_configure = vfio_pci_core_sriov_configure, +#endif + .err_handler = &vfio_pci_core_err_handlers, +}; + +static void __exit mlx5_vfio_pci_cleanup(void) +{ + pci_unregister_driver(&mlx5_vfio_pci_driver); +} + +static int __init mlx5_vfio_pci_init(void) +{ + return pci_register_driver(&mlx5_vfio_pci_driver); +} + +module_init(mlx5_vfio_pci_init); +module_exit(mlx5_vfio_pci_cleanup); + +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Max Gurtovoy "); +MODULE_DESCRIPTION("MLX5 VFIO PCI - User Level meta-driver for MLX5 device family");