From patchwork Mon Apr 26 20:00:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12225001 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=-16.0 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,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 2D1F6C43461 for ; Mon, 26 Apr 2021 20:00:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F2F01613AB for ; Mon, 26 Apr 2021 20:00:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241779AbhDZUBH (ORCPT ); Mon, 26 Apr 2021 16:01:07 -0400 Received: from mail-bn8nam08on2069.outbound.protection.outlook.com ([40.107.100.69]:56800 "EHLO NAM04-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236419AbhDZUBE (ORCPT ); Mon, 26 Apr 2021 16:01:04 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j+ukxqcu7nU3LVgjmkbi9PlwFDALK6x8agUkHlWzXp3BPBb/P5eDHaczlx5AAlmDJ/rHg16o7SBIRxCNIoDI6TS3ZUlWw53luJ5RgrWoCMynClnSjHOFYrbO1Mt4/nQ1sL2mVky9uuticmRS5Ps6xPSUyZVrAea/fmCuth6nwMjw54Ar4nuxfShR63QVw+LqhBym8Dp88jqX9efr+uACnBhfs8dGIXQNita13d61WMycpXaA66m42OMjefIcfLmDRtUaoSjLluLUAxah0xi0GHdMNOuBAhcWCRHvKJ7Ja91sgEhsjQbQm9WcwrNfjm/nuJB1D6tn1mjfJjVmiR4SPQ== 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=jtA9wwpcl5JsAiPwSoFC0d2L/Z2niX9OyeZRyPl5MMU=; b=UXVf/ig2+rDcP+p4A57xmHmD0MEP5LsS5jgo23eXhTDO0x9tSLXNptvx8J0vEK6MRLESLItnnMOH52oZhQMFmvNQmvpsXD0a/3NNRjnoaGI6KtOufKQySoMNYmTlLoRoe+yEOon9PAXOdK77Uo1ZSyR6bM0OUlMZtBqIKgzzxT2dkIJ0yTgDhKTAnDAVDhMH8+/q0qv4XkYZkM0hAikXFszXdXMqjDmEd7mqAlAusLw+ko+qWUeKdlu7IVn91D2sSEtrAryDHvNvKkUTWa2J1eqmXSOsuqGuXs2uBsS8QStbU1594cJVb9Zgo6T0p7JNcCPZYIP/UjkRYmIerhF80A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jtA9wwpcl5JsAiPwSoFC0d2L/Z2niX9OyeZRyPl5MMU=; b=jlQhxHbmtQRvFq52UaPfBa3oLZvvqrlyB1viVjI2goU8Xg9ZuA/p2e9nxVCtr9jMsdRZid7kZghwwZ8c3ZtU3s8lhOaqZ8VGdhPTvsLhcvUMtWfblcgkuyMU0oWeydvY831KkR/Wop3g6s2mj3n18oES6u3D2BqyRqWJ4xml87lqdJAVFAbcrOmaneb4FhnQi9R5n6XEuU3YXA5LVi1Un499PPKcq2E94VVy2tuJxch3S3ed9v4Bw/VOONJo+10fltW0KlFRcBmMevQVE6h8g+l+ic22Cep7O+SapU6sSs2EBXQ+htC7/7uIoFm9fS8n9yGtxHEKrnqnJa4SlsOuOA== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3740.namprd12.prod.outlook.com (2603:10b6:5:1c3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.24; Mon, 26 Apr 2021 20:00:17 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.4065.026; Mon, 26 Apr 2021 20:00:17 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , dri-devel@lists.freedesktop.org, Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, Jani Nikula , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-doc@vger.kernel.org, linux-s390@vger.kernel.org, Halil Pasic , Pierre Morel , Rodrigo Vivi Cc: "Raj, Ashok" , Dan Williams , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 01/13] vfio/mdev: Remove CONFIG_VFIO_MDEV_DEVICE Date: Mon, 26 Apr 2021 17:00:03 -0300 Message-Id: <1-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> In-Reply-To: <0-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: MN2PR03CA0017.namprd03.prod.outlook.com (2603:10b6:208:23a::22) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by MN2PR03CA0017.namprd03.prod.outlook.com (2603:10b6:208:23a::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21 via Frontend Transport; Mon, 26 Apr 2021 20:00:16 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lb7Ox-00DFZ1-Nc; Mon, 26 Apr 2021 17:00:15 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b17b8c4c-bd39-4092-1806-08d908ede983 X-MS-TrafficTypeDiagnostic: DM6PR12MB3740: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IGsk/G6BFzdQ/d66UubgFTPbSA0Ofp8xyI+upAcv+BiKwlKrCuztEE1H9Cuq7z+8Ad2Wo1hY9KWTPXwnqzSLklCTJdZxEeyTJfg6vxHjFbB6K/1YrS3rMceKN7RX/NV9N3V1XGuU4k2/30UgBMgrppKyxkwhXfb5f58uC2x8bR4K3YYCDiweTryig/aYPRK+I3cE+4+O4y/EOqpGYXa+RoEDnv/b1REJgExaxiiE2EJHNVAbCpLXEbghnNlPRp/W43btTP35vRp8QmvOx9qtMY50efDA8+3JnrIX8/G07qFEgUx3zQmKf39g8+BAEsJl95mg0JMrYgkWpqPN+H4VNoluS23caBSNMiEvcgxLhjCN7HjOVZgZq8+yfcF44pDmPdPMWOzwbUdAEtT1xc/owIiGlDpGrLLJ337O5UmYdZ/V/GpGWNoBfMG4uSzAOWVAKqwKIpQg9ZvTOVDnlBm5JopKuouOaAtrQjHiaZnlELul3REQQmTJyzElKDZBwYOV1uJR4KN75bouCYiSICJjBmM6BpG3LvKUtIzxmYINAkYezV5Z2OUvaLRAnd5V34HDnEOrNwD1IcorMCdvAhapQjxJktfne5sAqYcgOoGz8pN3ee0lcJgKzb1TOMR/4DYPo6an3BCRNZBiDD+BAAOWag6yfDWDgNCYIJs9ymgBz2I= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(39860400002)(346002)(136003)(396003)(376002)(66476007)(66556008)(9746002)(54906003)(426003)(110136005)(107886003)(186003)(26005)(921005)(6666004)(36756003)(316002)(2906002)(2616005)(478600001)(9786002)(8936002)(83380400001)(38100700002)(86362001)(8676002)(5660300002)(7416002)(4326008)(66946007)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 4668C+mMB/GSGBx2Op/LyjMn0yWxu6ae6SEfv+tyX++o6c6pp5IZZVyh1YayThMSstglxJW+eKHKPiN2mOZWZHNAj/xETqCjDHt2FxdOZ8nfoeKTZgUHoi1VSJZKBJ+qpsBjr1yquUNLds6Kt/lYaD5hlYGDITtJj60kv4wcJ5EMcIxVPUVErXothW/PNIEvtzwmIMK872wKTyRrVPcX/C+0dX5f6vpDK2tnrN4W7wJssTx9WgRZqdr44ozqAOQAQWuDWdkgkJcKrnA76O4vkUI+s276rm5CYzTt/kfcNtHnvpezTdQhJA6sJ0UMd2YdpT96Q6/rVt8eYxV3RG8J7Mlzu4XGtYIuu3LHQwPKEiyEUbF5y1UbZzqxVQpKmBZVBFUIY+iH0SDAoZuXf6B+YXTz35i/ulMmmMA00MCtV5ooTvI/MJDFBFfptPB+8cpieLCcWR2bIM19mnuhPuNdmVbiiknYa5dgtcb/dKunBXQs6j+T4b8q9yzAhTXRrz4vGfUHDPJh8Hh1+860a+ILIqx+2fjxHoMhtMVBYc/99qmRIAOZyzJxCe5ZGz6hIuSDbi1kDymzEoNkgC677L6Xlv464GRvBcCGAAeoOidZNBz6mL2CrPt1eJE4BhxPGucmYyPA1NG/b6WD2qoMjSuESVmk9bCMOuv1E/H9yOeeuIgYek1ZMdnN936bdK8wqCsT/rPnChi0vCkljY40wJ+2s3iMZPW82yYux6oKF3Ai+iIhEwaBmUvwGWim+Fy6FLAGZP4DYe6og7spOgxEh03/dpYqImDTSJzHnXRGgKcZZRN4mzp0cUbVaJ868KZM7bDci83H1hgeS9nBJgnt5ePsd2j1ERoTRnNIDCkwi63/pab3Rcg/mVZjhTSeoAGrigpBOfkqvvwSi8t/vpk9uv/3vglf8wysL2kWV/uHlrGLxtbyuXlY1nQS9rAUPvCRvYmSWDu0RPLaFInzdWqvB1fj+1yT7tQNXQHZLGlWSdbUvKau1YQB5/ENtSjg4sXoIFdSFyulfgQXAH3Kt2aXCNDnOp+LTCkMRf8TQuLpADn1XY0Q2/jHJRW0JjnkcFoZWvMa0J8e1VQ+bScDf5Hp0KwDCowPL9ylzPMJ3fnoH4NFG2PfrokKOo3AwNY9RFQBq8E7G253N/aufIHiKHhk/OH/xoR5PYeSUih3wdo81b6jhgk6D+WizkVy0n8I5GiAazJ5qymkiQcaUthRVvbiTWGYpR4m0xD6FESXYofqEuACIeYeNEMk4SuV0ZLi9r/yE9QyHvKumCoTOTgzXso36xnx6kbJWqxfNHsvRcUrGUc65SkJQEIsaQ9VqtO2E0wPZJow X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b17b8c4c-bd39-4092-1806-08d908ede983 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2021 20:00:17.1567 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /yVSitDYXtdMgF8tlUDHEN2jM1cKvm0Y606CkejsWT49Zi2ZHdOvYsLqtVih7d/t X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3740 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org For some reason the vfio_mdev shim mdev_driver has its own module and kconfig. As the next patch requires access to it from mdev.ko merge the two modules together and remove VFIO_MDEV_DEVICE. A later patch deletes this driver entirely. Signed-off-by: Jason Gunthorpe Reviewed-by: Cornelia Huck --- Documentation/s390/vfio-ap.rst | 1 - arch/s390/Kconfig | 2 +- drivers/gpu/drm/i915/Kconfig | 2 +- drivers/vfio/mdev/Kconfig | 7 ------- drivers/vfio/mdev/Makefile | 3 +-- drivers/vfio/mdev/mdev_core.c | 16 ++++++++++++++-- drivers/vfio/mdev/mdev_private.h | 2 ++ drivers/vfio/mdev/vfio_mdev.c | 24 +----------------------- samples/Kconfig | 6 +++--- 9 files changed, 23 insertions(+), 40 deletions(-) diff --git a/Documentation/s390/vfio-ap.rst b/Documentation/s390/vfio-ap.rst index e15436599086b7..f57ae621f33e89 100644 --- a/Documentation/s390/vfio-ap.rst +++ b/Documentation/s390/vfio-ap.rst @@ -514,7 +514,6 @@ These are the steps: * S390_AP_IOMMU * VFIO * VFIO_MDEV - * VFIO_MDEV_DEVICE * KVM If using make menuconfig select the following to build the vfio_ap module:: diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index c1ff874e6c2e63..dc7928e37fa409 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -773,7 +773,7 @@ config VFIO_CCW config VFIO_AP def_tristate n prompt "VFIO support for AP devices" - depends on S390_AP_IOMMU && VFIO_MDEV_DEVICE && KVM + depends on S390_AP_IOMMU && VFIO_MDEV && KVM depends on ZCRYPT help This driver grants access to Adjunct Processor (AP) devices diff --git a/drivers/gpu/drm/i915/Kconfig b/drivers/gpu/drm/i915/Kconfig index 483e9ff8ca1d23..388bc41aa1a75b 100644 --- a/drivers/gpu/drm/i915/Kconfig +++ b/drivers/gpu/drm/i915/Kconfig @@ -125,7 +125,7 @@ config DRM_I915_GVT_KVMGT tristate "Enable KVM/VFIO support for Intel GVT-g" depends on DRM_I915_GVT depends on KVM - depends on VFIO_MDEV && VFIO_MDEV_DEVICE + depends on VFIO_MDEV default n help Choose this option if you want to enable KVMGT support for diff --git a/drivers/vfio/mdev/Kconfig b/drivers/vfio/mdev/Kconfig index 5da27f2100f9bd..763c877a1318bc 100644 --- a/drivers/vfio/mdev/Kconfig +++ b/drivers/vfio/mdev/Kconfig @@ -9,10 +9,3 @@ config VFIO_MDEV See Documentation/driver-api/vfio-mediated-device.rst for more details. If you don't know what do here, say N. - -config VFIO_MDEV_DEVICE - tristate "VFIO driver for Mediated devices" - depends on VFIO && VFIO_MDEV - default n - help - VFIO based driver for Mediated devices. diff --git a/drivers/vfio/mdev/Makefile b/drivers/vfio/mdev/Makefile index 101516fdf3753e..ff9ecd80212503 100644 --- a/drivers/vfio/mdev/Makefile +++ b/drivers/vfio/mdev/Makefile @@ -1,6 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o +mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o vfio_mdev.o obj-$(CONFIG_VFIO_MDEV) += mdev.o -obj-$(CONFIG_VFIO_MDEV_DEVICE) += vfio_mdev.o diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 2a85d6fcb7ddd0..ff8c1a84516698 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -360,11 +360,24 @@ int mdev_device_remove(struct mdev_device *mdev) static int __init mdev_init(void) { - return mdev_bus_register(); + int rc; + + rc = mdev_bus_register(); + if (rc) + return rc; + rc = mdev_register_driver(&vfio_mdev_driver); + if (rc) + goto err_bus; + return 0; +err_bus: + mdev_bus_unregister(); + return rc; } static void __exit mdev_exit(void) { + mdev_unregister_driver(&vfio_mdev_driver); + if (mdev_bus_compat_class) class_compat_unregister(mdev_bus_compat_class); @@ -378,4 +391,3 @@ MODULE_VERSION(DRIVER_VERSION); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); -MODULE_SOFTDEP("post: vfio_mdev"); diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h index a656cfe0346c33..5461b67582289f 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -37,6 +37,8 @@ struct mdev_type { #define to_mdev_type(_kobj) \ container_of(_kobj, struct mdev_type, kobj) +extern struct mdev_driver vfio_mdev_driver; + int parent_create_sysfs_files(struct mdev_parent *parent); void parent_remove_sysfs_files(struct mdev_parent *parent); diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c index 922729071c5a8e..d5b4eede47c1a5 100644 --- a/drivers/vfio/mdev/vfio_mdev.c +++ b/drivers/vfio/mdev/vfio_mdev.c @@ -17,10 +17,6 @@ #include "mdev_private.h" -#define DRIVER_VERSION "0.1" -#define DRIVER_AUTHOR "NVIDIA Corporation" -#define DRIVER_DESC "VFIO based driver for Mediated device" - static int vfio_mdev_open(struct vfio_device *core_vdev) { struct mdev_device *mdev = to_mdev_device(core_vdev->dev); @@ -151,7 +147,7 @@ static void vfio_mdev_remove(struct mdev_device *mdev) kfree(vdev); } -static struct mdev_driver vfio_mdev_driver = { +struct mdev_driver vfio_mdev_driver = { .driver = { .name = "vfio_mdev", .owner = THIS_MODULE, @@ -160,21 +156,3 @@ static struct mdev_driver vfio_mdev_driver = { .probe = vfio_mdev_probe, .remove = vfio_mdev_remove, }; - -static int __init vfio_mdev_init(void) -{ - return mdev_register_driver(&vfio_mdev_driver); -} - -static void __exit vfio_mdev_exit(void) -{ - mdev_unregister_driver(&vfio_mdev_driver); -} - -module_init(vfio_mdev_init) -module_exit(vfio_mdev_exit) - -MODULE_VERSION(DRIVER_VERSION); -MODULE_LICENSE("GPL v2"); -MODULE_AUTHOR(DRIVER_AUTHOR); -MODULE_DESCRIPTION(DRIVER_DESC); diff --git a/samples/Kconfig b/samples/Kconfig index e76cdfc50e257d..5708abcc55c4df 100644 --- a/samples/Kconfig +++ b/samples/Kconfig @@ -147,14 +147,14 @@ config SAMPLE_UHID config SAMPLE_VFIO_MDEV_MTTY tristate "Build VFIO mtty example mediated device sample code -- loadable modules only" - depends on VFIO_MDEV_DEVICE && m + depends on VFIO_MDEV && m help Build a virtual tty sample driver for use as a VFIO mediated device config SAMPLE_VFIO_MDEV_MDPY tristate "Build VFIO mdpy example mediated device sample code -- loadable modules only" - depends on VFIO_MDEV_DEVICE && m + depends on VFIO_MDEV && m help Build a virtual display sample driver for use as a VFIO mediated device. It is a simple framebuffer and supports @@ -171,7 +171,7 @@ config SAMPLE_VFIO_MDEV_MDPY_FB config SAMPLE_VFIO_MDEV_MBOCHS tristate "Build VFIO mdpy example mediated device sample code -- loadable modules only" - depends on VFIO_MDEV_DEVICE && m + depends on VFIO_MDEV && m select DMA_SHARED_BUFFER help Build a virtual display sample driver for use as a VFIO From patchwork Mon Apr 26 20:00:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12225013 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=-16.0 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,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS 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 5728FC43461 for ; Mon, 26 Apr 2021 20:00:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34334613AA for ; Mon, 26 Apr 2021 20:00:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241811AbhDZUBV (ORCPT ); Mon, 26 Apr 2021 16:01:21 -0400 Received: from mail-bn8nam08on2069.outbound.protection.outlook.com ([40.107.100.69]:56800 "EHLO NAM04-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S241784AbhDZUBJ (ORCPT ); Mon, 26 Apr 2021 16:01:09 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a/JzRD0041+Boo3f8smrP8M+Jmf8K4i2hXoRKZD+EVjK/MlOatMhuUo+ycgpWb0Oj2qEIkCBVL+RHnwp7PLk7DbgXPLHHwE1G7n+0a0+jyeX8NJfBDWhMIC/dOFJRsFa06FcFDevDg9Jv/eirJnEO5sMRjlDmHxm/fU3ww+DdoRbfR/oc0qIeIBdWkEQ9GV4t76OuRwH3SN/gQD/xeQ7dpxl925UZ+UUI+LY3GRcdMGnc517CIc7ovSeuZJhnDs6KgUHYQRiGl9tQe89c23ptw48ISnJ1A6suIHy3Hjf2w9y0b6Q80xHrnFAuWJuGNgylwt4VfwUYP35OWnW/PKQ5g== 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=frizBgNx1wYm+8kzECYvDIwb+hKH4+nzEO3MVHrVWlQ=; b=hyivz3hwc8ejZP7mwnQyMnLCFp/dsHLleO5vplxcSMz2LKRPosI1s6x+BzqF3SCEh3AxVNUA5EuDWW4lItfrl0H34/EvINBWXOXbDDAH+cN6z3oE1inmTLdl1UW20HKtE9KBBHyUNOBNM4AjG/6MtQZLm6OZ7I5xgr1wlP4v8iobC0qJDWjpmKfogSiPEHTMvPnqAqHOuXBIGBjQsiHEHAKY5B75g0/Gl7KCcETFRSQfRjGYVQ0BeAdtjP8+l3PBXdAp1gnov/g8aoJ/HL0gkEglzcylfL5jvFoKSqnDoA4t3Y+FmajCTNypmeyYMJCumaUAQOoPEEjHowgDpUCntw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=frizBgNx1wYm+8kzECYvDIwb+hKH4+nzEO3MVHrVWlQ=; b=WTmWTStNhMTbeM9mKHdpQ+Diugsxf/wXrfb5oLYIKhpHfXMEO1dtaot+SQ00kFbfzy0Y4EmwmRZnhaYJ3H3MX8Em2wSWA/EoX9aRv/SPfU0Cka+sRYWHgIW167GWTOfnrRzqh06kD5YDuOhMCcN7ZVK8f9gz+4XwJkUvclz4QbjyBTS0JMr5+iYm87yIk/IwIVUbvy7cw0PsAG3Ov3rmi9SWCDJsW08vYpYXUSCts1y+pmQMQ9LxGw3s3tVFE89X+hNQJH6N9YlKZpvSuqz2SdAmbyYAqZxEMgFwqJjeeOGSKFSUI624XU6z9xuHqszKe2Y6mB21SyfFxYuJ9HoqAw== Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3740.namprd12.prod.outlook.com (2603:10b6:5:1c3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.24; Mon, 26 Apr 2021 20:00:21 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.4065.026; Mon, 26 Apr 2021 20:00:21 +0000 From: Jason Gunthorpe To: Alex Williamson , Cornelia Huck , kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Dan Williams , Daniel Vetter , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 02/13] vfio/mdev: Allow the mdev_parent_ops to specify the device driver to bind Date: Mon, 26 Apr 2021 17:00:04 -0300 Message-Id: <2-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> In-Reply-To: <0-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: MN2PR20CA0043.namprd20.prod.outlook.com (2603:10b6:208:235::12) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by MN2PR20CA0043.namprd20.prod.outlook.com (2603:10b6:208:235::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20 via Frontend Transport; Mon, 26 Apr 2021 20:00:18 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lb7Ox-00DFZ4-Oq; Mon, 26 Apr 2021 17:00:15 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9a3ebf6f-6d82-478e-5fb1-08d908edea60 X-MS-TrafficTypeDiagnostic: DM6PR12MB3740: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FLCkflvJg2rSo5mkeaStXMkq3OqNKxVdy18DjQPmQ5tf+JBrfnATBXsIxhDPZKfvR1nQdbSIsOIdflG0bPtMpfOqX23Dy7QbXEIAcJMKCmkRY4+v5MRvsBRFmpt53kmdrkRcvloxsm22EMvt16seoueAe9tlU13+yKq/0LWy89n3FNAqUKm/hAtvvILm/7L7maEK1uLC/KhaNrIVM7TjyGYFwr5/JrtlvNbJUNyGNF6NxA2+nJQvnfoNK+0VjvDd41Vlgao8KSly1TujR9dlDvbk9maZ32xEhIOSNe8GpsPbzfhbGhcJP67gFper1eJXNnKBA08WVpDVYEqHSKy6Shrob84g7mquuj9Bqzvyo0lEGpy8JOVpIINkSuJdsaBGnezVU5lvg/tLQpeVYSU25KaFaY2uI3v+SETIphVQuPa0crRBQQKi9vzFgAxWG95e5XW7OGiqEmS/Pm/ULDUbaoGIEycIIT1NIpf16/ku9p28dHbth8a7WhQP/s4BWQB+3eDOncZFln5aLG83D1DOHZL1saxVDahFcshvIcrsfdB17r7z2fB6GGTN2JkWC51vSFa3s7vtcL3ldE1jMilt/m6IUD1wPe9piPCJyLGlI4eUbASYbLN+LDNPi9XoOkd+kl8u7Vh1NwGug3k8rPmknw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(39860400002)(346002)(136003)(396003)(376002)(66476007)(66556008)(9746002)(54906003)(426003)(110136005)(107886003)(186003)(26005)(6666004)(36756003)(316002)(2906002)(2616005)(478600001)(6636002)(9786002)(8936002)(83380400001)(38100700002)(86362001)(8676002)(5660300002)(4326008)(66946007)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: t6u/k8qDMbMARIyN8wdb+zXzON6M8+RI+R7KdAdToD2nEFYEgUBOJq+geh0SASJ5mF3Xd+jXGtaMVeEHIAm0jxsmMQd/cwluEqY+JKwXrdenv790K+d5Uf+OM1PVzl0XKprgjZoejsgBufGxAyci0Vj6novwft+JoJcFdzA9ROBnvvWGmMDHUKpUfaTHDJpizHukEPD/PImWkLfAEKHEIo/NQeU8AdlZ/jQnZkfoieG6wGbThXbnoX5xndZtMVoQaP2vOvE7RyuLzLKglLjRem5mnvzEgqGTonpkETCEnIZ2rPwZGYwEQfXr+VmE1lZbOXb5MTHvx7qByO0alzJliQ67M8MReNFUEGVsrl/34NGWksTJsN+ERai9MPao4I+hdCOu+aOgoLHQn9EXMDiFR8iHtjkJt3gZWR8C7jUiCNjEDfMxwYaNr6hPI/oGEgg52N30rHPE2tlCb+sF7HAvKriLlWotNZAJRV1pz89U8ogRJOb76NaiKIlSdluC+5Ew5Ae4YbrJmJVc7mA3Bsamf3leayzocUUoaaL5uKfE3dwMBn8yVxqe3A0L8Ww4KoiMl2yM5Oy13ONpsvSbz7fmqVZPVxc1eGvwi47sGvyR8bS6m3Zz1i4Beyyk0sIK3zWTbktikvmnymrPBDiAZDwG3LNipVGF/QuTITz0I8o5wkGNz91H6tarA0m5YhDYGGoTjuoz0+h1XntoxqUjwqapZ3btm6HzsFo/VZVZR9AzB3JYRg934E1t+4UxaHdI3UowW7i7r0mwUhO/pHD2ilZqPyhWqSUv5Hbz4/YziyT9CVXeg/QI3D2dmy6CEOD8/IWFzqy5KcCtcwPXmcUYYhNOE94yh7PjGs+sWzkJac6r1p+lDuxBH/RgS9S6mn2hxDxAcxAn3RNyI5qKe6UVIqNhnbcJvqpN8QhOliBIXsfDcIYwYrA3RYrWJFJqAmzOzQClnYQRkZpt3YXETkapxwgo8xJB8mLSCFcUDUuIoANeSJHjAUjO16teipkXZXfx1LloaVIGZ5mVXDOCJyZM1ypQnU73uMLTeQRs0rRy6hQOHgnEcZbI8VAnAjcATu4mCoVu066+w6Rt00I/+UuQLKT3P+JjRF6Dx5hZFQRfWiCuE/et7bc8Fa5caHWBn4USRD1y037eNLiozpwgislCwVzDqL6x7GAz0x82zj92XHVrqN2E7oKRnv6f5OlqROc/XVEKDdByGISYk0uVCdbTEyVlW2Vi7NH8DK5Verk11W9SxpDC9XK12zYIxmMx5IEfdo+677aJj8SpilwzsB6TZRDrIRURXiuymGPU+6poKYA5TQ58yAuCkXa6kkyCnEIVZYAt X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9a3ebf6f-6d82-478e-5fb1-08d908edea60 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2021 20:00:18.3810 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mib3lEEIjgqlr5APBiiG3dDZT8wMlyuwHIHWivyY4Y2ufGOGQGKW6RO3eD2vhEjU X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3740 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This allows a mdev driver to opt out of using vfio_mdev.c, instead the driver will provide a 'struct mdev_driver' and register directly with the driver core. Much of mdev_parent_ops becomes unused in this mode: - create()/remove() are done via the mdev_driver probe()/remove() - mdev_attr_groups becomes mdev_driver driver.dev_groups - Wrapper function callbacks are replaced with the same ones from struct vfio_device_ops Following patches convert all the drivers. Signed-off-by: Jason Gunthorpe --- drivers/vfio/mdev/mdev_core.c | 64 ++++++++++++++++++++++++++++----- drivers/vfio/mdev/mdev_driver.c | 17 ++++++++- include/linux/mdev.h | 3 ++ 3 files changed, 75 insertions(+), 9 deletions(-) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index ff8c1a84516698..51b8a9fcf866ad 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -94,9 +94,11 @@ static void mdev_device_remove_common(struct mdev_device *mdev) mdev_remove_sysfs_files(mdev); device_del(&mdev->dev); lockdep_assert_held(&parent->unreg_sem); - ret = parent->ops->remove(mdev); - if (ret) - dev_err(&mdev->dev, "Remove failed: err=%d\n", ret); + if (parent->ops->remove) { + ret = parent->ops->remove(mdev); + if (ret) + dev_err(&mdev->dev, "Remove failed: err=%d\n", ret); + } /* Balances with device_initialize() */ put_device(&mdev->dev); @@ -127,7 +129,9 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops) char *envp[] = { env_string, NULL }; /* check for mandatory ops */ - if (!ops || !ops->create || !ops->remove || !ops->supported_type_groups) + if (!ops || !ops->supported_type_groups) + return -EINVAL; + if (!ops->device_driver && (!ops->create || !ops->remove)) return -EINVAL; dev = get_device(dev); @@ -251,6 +255,43 @@ static void mdev_device_release(struct device *dev) kfree(mdev); } +/* + * mdev drivers can refuse to bind during probe(), in this case we want to fail + * the creation of the mdev all the way back to sysfs. This is a weird model + * that doesn't fit in the driver core well, nor does it seem to appear any + * place else in the kernel, so use a simple hack. + */ +static int mdev_bind_driver(struct mdev_device *mdev) +{ + struct mdev_driver *drv = mdev->type->parent->ops->device_driver; + int ret; + + if (!drv) + drv = &vfio_mdev_driver; + + while (1) { + device_lock(&mdev->dev); + if (mdev->dev.driver == &drv->driver) { + ret = 0; + goto out_unlock; + } + if (mdev->probe_err) { + ret = mdev->probe_err; + goto out_unlock; + } + device_unlock(&mdev->dev); + ret = device_attach(&mdev->dev); + if (ret) + return ret; + mdev->probe_err = -EINVAL; + } + return 0; + +out_unlock: + device_unlock(&mdev->dev); + return ret; +} + int mdev_device_create(struct mdev_type *type, const guid_t *uuid) { int ret; @@ -296,14 +337,20 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) goto out_put_device; } - ret = parent->ops->create(mdev); - if (ret) - goto out_unlock; + if (parent->ops->create) { + ret = parent->ops->create(mdev); + if (ret) + goto out_unlock; + } ret = device_add(&mdev->dev); if (ret) goto out_remove; + ret = mdev_bind_driver(mdev); + if (ret) + goto out_del; + ret = mdev_create_sysfs_files(mdev); if (ret) goto out_del; @@ -317,7 +364,8 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) out_del: device_del(&mdev->dev); out_remove: - parent->ops->remove(mdev); + if (parent->ops->remove) + parent->ops->remove(mdev); out_unlock: up_read(&parent->unreg_sem); out_put_device: diff --git a/drivers/vfio/mdev/mdev_driver.c b/drivers/vfio/mdev/mdev_driver.c index 041699571b7e55..6e96c023d7823d 100644 --- a/drivers/vfio/mdev/mdev_driver.c +++ b/drivers/vfio/mdev/mdev_driver.c @@ -49,7 +49,7 @@ static int mdev_probe(struct device *dev) return ret; if (drv->probe) { - ret = drv->probe(mdev); + ret = mdev->probe_err = drv->probe(mdev); if (ret) mdev_detach_iommu(mdev); } @@ -71,10 +71,25 @@ static int mdev_remove(struct device *dev) return 0; } +static int mdev_match(struct device *dev, struct device_driver *drv) +{ + struct mdev_device *mdev = to_mdev_device(dev); + struct mdev_driver *target = mdev->type->parent->ops->device_driver; + + /* + * The ops specify the device driver to connect, fall back to the old + * shim driver if the driver hasn't been converted. + */ + if (!target) + target = &vfio_mdev_driver; + return drv == &target->driver; +} + struct bus_type mdev_bus_type = { .name = "mdev", .probe = mdev_probe, .remove = mdev_remove, + .match = mdev_match, }; EXPORT_SYMBOL_GPL(mdev_bus_type); diff --git a/include/linux/mdev.h b/include/linux/mdev.h index 1fb34ea394ad46..49cc4f65120d57 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -19,6 +19,7 @@ struct mdev_device { struct list_head next; struct mdev_type *type; struct device *iommu_device; + int probe_err; bool active; }; @@ -55,6 +56,7 @@ struct device *mtype_get_parent_dev(struct mdev_type *mtype); * register the device to mdev module. * * @owner: The module owner. + * @device_driver: Which device driver to probe() on newly created devices * @dev_attr_groups: Attributes of the parent device. * @mdev_attr_groups: Attributes of the mediated device. * @supported_type_groups: Attributes to define supported types. It is mandatory @@ -103,6 +105,7 @@ struct device *mtype_get_parent_dev(struct mdev_type *mtype); **/ struct mdev_parent_ops { struct module *owner; + struct mdev_driver *device_driver; const struct attribute_group **dev_attr_groups; const struct attribute_group **mdev_attr_groups; struct attribute_group **supported_type_groups; From patchwork Mon Apr 26 20:00:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12225019 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=-16.0 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,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS 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 44B4FC433ED for ; Mon, 26 Apr 2021 20:00:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1FE146135D for ; Mon, 26 Apr 2021 20:00:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241834AbhDZUB0 (ORCPT ); Mon, 26 Apr 2021 16:01:26 -0400 Received: from mail-bn8nam08on2048.outbound.protection.outlook.com ([40.107.100.48]:25530 "EHLO NAM04-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S241806AbhDZUBN (ORCPT ); Mon, 26 Apr 2021 16:01:13 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=br/akAnN08mBcciuBq08EnCp7LbS3pOVlQBz6Y2uEZsEmau95HzsxMryuXFE4BkMG7GXR0d8TFsk+x+7Cp5eXlGNbcmzS45Xvkhvsj2qP+KDZraSWh8GG1Mqn+TzmTW0XLWemyYSkhfmJRvlCDwB+X9I1BJRKSfH2hX65Vt4r+fHQitZzpCT7iHyY3u06iaqSx5bLOC16ZyyTASRGMk1XINOShAnKJDFt/VoSPEjqxlRnI9H1+FTSDHlhfE9fVeLYqoUjMzmEmb+XgoLF81LdD5zrJ0DN4D7I1wlsw/9kCP4aK5iKIqhB7/vOn4owCpVLiFlLtliEWY1ic9/n91D2Q== 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=6NiwbjTB/rf9sR4ZC2VUsBPwx5YVyjuS3PbGxjNeKkA=; b=jJjEwe+pIWWtqZOU/gt86Rua9enyHLDKqsK3ClTdmjdPkugwUL/MwacevlHlQN3y+doYuei2bohCmjK/XqurCMIwVpnwG4M82fvttqKFvxp8jXcTJ6sBIbo0RJ2JaONu1IcumNaWf3PQ7TW5TJZixT4dhePeUo1LkXebEC+ZNONfLYGvApkWsCvz5xYZ8A7+Bb3l4V62MGLsHsqNvZNUOanMgak3UqJi3/4SjPSiJZUqDw4ssXHLVn+WADtITZAmJz7gEBBeQJZ3oQOWPdFulDjWZ8sJ6eme5HTfQBnxUqF2LX4VfPuoFiWU1yPLuuljVAbfHSCOm/1iQW5dsLodYA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6NiwbjTB/rf9sR4ZC2VUsBPwx5YVyjuS3PbGxjNeKkA=; b=O+YgTjJm2Hq067ehDrZVosiKUyrIt7SnZ5WgxUgX0C9kA+ZNZ4yBzSWjM4LwNHqX85GmM1QQ/SAFYzUKNDKSk+BwZ8zlhWaMM8j3KlUqmZprenX01THkA2h5CGCfS5wtUb86Q6i8aGevvPICcckKxEUafpTVGp7joaX7xFASt4drIb3/qi1Bv27umpyeFFWxSYv+CNWfpJ5z1/B5TIqvcLF462hmWGVMLSiDLlMiuBOIfwuz4E837VGmUPA3MlcR00R63HAmYnNOG536yIFrlGneIAjPTWglMjT/10hD91cKwUTJSC8YtWevi2dF1srG6ms6Tt+n6gYkfNMWEBy2Cg== Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3740.namprd12.prod.outlook.com (2603:10b6:5:1c3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.24; Mon, 26 Apr 2021 20:00:23 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.4065.026; Mon, 26 Apr 2021 20:00:23 +0000 From: Jason Gunthorpe To: kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Dan Williams , Daniel Vetter , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 03/13] vfio/mtty: Convert to use vfio_register_group_dev() Date: Mon, 26 Apr 2021 17:00:05 -0300 Message-Id: <3-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> In-Reply-To: <0-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: BL0PR02CA0069.namprd02.prod.outlook.com (2603:10b6:207:3d::46) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by BL0PR02CA0069.namprd02.prod.outlook.com (2603:10b6:207:3d::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21 via Frontend Transport; Mon, 26 Apr 2021 20:00:19 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lb7Ox-00DFZ8-Q3; Mon, 26 Apr 2021 17:00:15 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 95c925d0-30e0-4b6c-e628-08d908edeb5e X-MS-TrafficTypeDiagnostic: DM6PR12MB3740: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:431; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SRyEEMxGVJ3ZVxXz7XNUEsDZPHkdXTR6Ulb3nUNakawSqq0A7ExRLYLVtFoyWVM7yYhth6KiCPs3TYB1XmqqGEDiaQCpFq6HpqW5jyirs3GvRxQXgR1TxRM/teLroi9mzc8LA3EanFL7+D/9WgvKusgeI7kLOrBhjCuWPIVZJxjVWgyDVBSb0JUgMGP1rbsXCW3kDqpldhsRJi1Oj/XS7g2FBns6NjASYFI/WYnyuiDjxAWUcp8TWaSBtXG4a/s1bBYBwiW+ZqQHlMzATzWJszOhr2po1Gnnnf0dtCbveZlXRBU1MNkjaFUywvE9ywqkOQrGiZx8LPuICLQ8W9G5LcWWSlPjzYA9w7k/eS0NvtXYH9iQ10hksFVNewFOUm0p4Ix274M6x5hFHURuNLrUSXdGHVesNRNjZ/IFnsgFSqeO8a8M5LGmpyeOzzUE0vMlBxWJIWziP+59QSUV0NqvQitPI5k6csvw2M+YZ8ksck38QNo4VPWFZDBWwFbE7yM90RF2wx0/WpVkCdTg5x1gkLYYrc+6+dhrpiol1e0nOsix8wHkZcSII4FdhJW/ulWKpAmwZZa1v274RE8QDOMcUJYMmHXwHJZLKvguZxcltGvdw9FhKwiEmjmWieWK4sdySbdFI8GOlrz5Lq0u2ZlR0A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(39860400002)(346002)(136003)(396003)(376002)(66476007)(66556008)(9746002)(6862004)(54906003)(426003)(37006003)(107886003)(186003)(26005)(6666004)(36756003)(316002)(2906002)(30864003)(2616005)(478600001)(6636002)(9786002)(8936002)(83380400001)(38100700002)(86362001)(8676002)(5660300002)(4326008)(66946007)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 0xu5M6nVAjs8EZWutocx66ywZKhAEJhrkT8Nxw9JT23UNRqFUGvbjvPhjFkbEUppU1dcFj3675Lzko66pVKnejtg+0MVeBpO3sLsI5/oNiXDWIoHjf45EOm1BI4M9gWqlcOCw0psgHkiLUeAyysOxIKw4l4CrnnQ+E/hNJM0oVfJAtemek36HPu1kxO1b9SBoGd2ZgrDNhgmK3ssHJUOkV1ZP5zj0dlfZide5RCIuQmRT2IJv54ns042XWToAQAhOXLlYx6Tu9SiFwxuGgujjdw8SFOshIEvNJ+LK4n1mXjBjn+ik/6zI7XYEDOReZ94j+nC0f8C2kzB2Qc69tn2eXdxR3ezOCUDs4bkWIHzpn8FzzHzbVDzCpUDK0dTXCRYvMUDw8YI5xL0iTeLkUhcaRL9KpmDW5GA+GIsOTsFoj7Wm4YVbii9PnBcPU8aBvisWmjI9oBvC0j2o2kLfBbIRX6by3OrmUR7h1B1EtO8McXh2Md+6ICnKhZifUcE0pUH3752F6Os3HLTT09Upj2wD4gqw03Q/WM5LcUmEwPlMFmvju2oXxv09xoWAILKkaFGIrvqkmUzt2VTfOCrXUnn5OmwB7LID2cchjG8B10+qpIZ63+lzybitWpNKKU0FK2bdcWTxCY2w9Kju6FiXNB1BX/PQE5dTRIHX8u1IPbXva43n/r2apRof64ClScYEpZRFv6tLp8ZypiHUIQdWndj3KfHqcr71FM0hdrmjKJMzQaLT5Lc2Bqn1LPoeSMOU1loFxdYlklAoGJPGdcU3B5r9cVgbfZlcax6BGL2fU2q07448Pcw0TWCnzlWix+9aI7BKn5v0CbfEsIiqp2QYjCc9BzvzuPwDqkHZi5YI+HJOjbLqcxaaGlApFabtf+/oiAI3OS3ZDAApg4G7SPeSFd+5HEh1NelWMn97brbeZMEtP7RHChSNf1tmLd5p3AeIbBDAHahmsUMl8l0JQmxwu5IQGKHIQ7TG7BQTOHMKphoEb9QyJ5Jfy0mLm0ZxZr2bLZLRgy2rY0d9XFLFm1OUmFeL4zgcwHfFiKlqRIhPq/NoBvwXYB8R6UIsgq7eONz00/ECNe9cZHw9LTwBuK/DBHBfCXoGufuYAL/MdAxeBgzxWFKFSRlO4TrMqdU9pV7A6XXTRZf8Mz0Y6Tiw073autle0X7L5ywWHwrnHLuyF2Uv7k+JvAgIy5FraWiHtgW+aSeQdasUBxai9uiBR+Um+UAIT+ZiyxD3DAKk+DkR9MRrODTG1iNz4s2hiiS7X94sgiuhAUz3KVOfUSORI5Dx4quwByBbBMBdW3YO023fHbPse818RYBiqaOKnFttAZFKz54 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95c925d0-30e0-4b6c-e628-08d908edeb5e X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2021 20:00:20.0911 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 66p/zIlBk3jOJaCtHiNr+MvwZoKyscCrFu1D4tjaVE1c0IzY09ucPUCt3gYeIt9X X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3740 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is straightforward conversion, the mdev_state is actually serving as the vfio_device and we can replace all the mdev_get_drvdata()'s and the wonky dead code with a simple container_of() Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- samples/vfio-mdev/mtty.c | 185 ++++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 102 deletions(-) diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index b9b24be4abdab7..d2a168420b775d 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c @@ -127,6 +127,7 @@ struct serial_port { /* State of each mdev device */ struct mdev_state { + struct vfio_device vdev; int irq_fd; struct eventfd_ctx *intx_evtfd; struct eventfd_ctx *msi_evtfd; @@ -150,6 +151,8 @@ static const struct file_operations vd_fops = { .owner = THIS_MODULE, }; +static const struct vfio_device_ops mtty_dev_ops; + /* function prototypes */ static int mtty_trigger_interrupt(struct mdev_state *mdev_state); @@ -631,22 +634,15 @@ static void mdev_read_base(struct mdev_state *mdev_state) } } -static ssize_t mdev_access(struct mdev_device *mdev, u8 *buf, size_t count, +static ssize_t mdev_access(struct mdev_state *mdev_state, u8 *buf, size_t count, loff_t pos, bool is_write) { - struct mdev_state *mdev_state; unsigned int index; loff_t offset; int ret = 0; - if (!mdev || !buf) - return -EINVAL; - - mdev_state = mdev_get_drvdata(mdev); - if (!mdev_state) { - pr_err("%s mdev_state not found\n", __func__); + if (!buf) return -EINVAL; - } mutex_lock(&mdev_state->ops_lock); @@ -708,15 +704,18 @@ static ssize_t mdev_access(struct mdev_device *mdev, u8 *buf, size_t count, return ret; } -static int mtty_create(struct mdev_device *mdev) +static int mtty_probe(struct mdev_device *mdev) { struct mdev_state *mdev_state; int nr_ports = mdev_get_type_group_id(mdev) + 1; + int ret; mdev_state = kzalloc(sizeof(struct mdev_state), GFP_KERNEL); if (mdev_state == NULL) return -ENOMEM; + vfio_init_group_dev(&mdev_state->vdev, &mdev->dev, &mtty_dev_ops); + mdev_state->nr_ports = nr_ports; mdev_state->irq_index = -1; mdev_state->s[0].max_fifo_size = MAX_FIFO_SIZE; @@ -731,7 +730,6 @@ static int mtty_create(struct mdev_device *mdev) mutex_init(&mdev_state->ops_lock); mdev_state->mdev = mdev; - mdev_set_drvdata(mdev, mdev_state); mtty_create_config_space(mdev_state); @@ -739,50 +737,40 @@ static int mtty_create(struct mdev_device *mdev) list_add(&mdev_state->next, &mdev_devices_list); mutex_unlock(&mdev_list_lock); + ret = vfio_register_group_dev(&mdev_state->vdev); + if (ret) { + kfree(mdev_state); + return ret; + } + dev_set_drvdata(&mdev->dev, mdev_state); return 0; } -static int mtty_remove(struct mdev_device *mdev) +static void mtty_remove(struct mdev_device *mdev) { - struct mdev_state *mds, *tmp_mds; - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); - int ret = -EINVAL; + struct mdev_state *mdev_state = dev_get_drvdata(&mdev->dev); + vfio_unregister_group_dev(&mdev_state->vdev); mutex_lock(&mdev_list_lock); - list_for_each_entry_safe(mds, tmp_mds, &mdev_devices_list, next) { - if (mdev_state == mds) { - list_del(&mdev_state->next); - mdev_set_drvdata(mdev, NULL); - kfree(mdev_state->vconfig); - kfree(mdev_state); - ret = 0; - break; - } - } + list_del(&mdev_state->next); mutex_unlock(&mdev_list_lock); - return ret; + kfree(mdev_state->vconfig); + kfree(mdev_state); } -static int mtty_reset(struct mdev_device *mdev) +static int mtty_reset(struct mdev_state *mdev_stte) { - struct mdev_state *mdev_state; - - if (!mdev) - return -EINVAL; - - mdev_state = mdev_get_drvdata(mdev); - if (!mdev_state) - return -EINVAL; - pr_info("%s: called\n", __func__); return 0; } -static ssize_t mtty_read(struct mdev_device *mdev, char __user *buf, +static ssize_t mtty_read(struct vfio_device *vdev, char __user *buf, size_t count, loff_t *ppos) { + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); unsigned int done = 0; int ret; @@ -792,7 +780,7 @@ static ssize_t mtty_read(struct mdev_device *mdev, char __user *buf, if (count >= 4 && !(*ppos % 4)) { u32 val; - ret = mdev_access(mdev, (u8 *)&val, sizeof(val), + ret = mdev_access(mdev_state, (u8 *)&val, sizeof(val), *ppos, false); if (ret <= 0) goto read_err; @@ -804,7 +792,7 @@ static ssize_t mtty_read(struct mdev_device *mdev, char __user *buf, } else if (count >= 2 && !(*ppos % 2)) { u16 val; - ret = mdev_access(mdev, (u8 *)&val, sizeof(val), + ret = mdev_access(mdev_state, (u8 *)&val, sizeof(val), *ppos, false); if (ret <= 0) goto read_err; @@ -816,7 +804,7 @@ static ssize_t mtty_read(struct mdev_device *mdev, char __user *buf, } else { u8 val; - ret = mdev_access(mdev, (u8 *)&val, sizeof(val), + ret = mdev_access(mdev_state, (u8 *)&val, sizeof(val), *ppos, false); if (ret <= 0) goto read_err; @@ -839,9 +827,11 @@ static ssize_t mtty_read(struct mdev_device *mdev, char __user *buf, return -EFAULT; } -static ssize_t mtty_write(struct mdev_device *mdev, const char __user *buf, +static ssize_t mtty_write(struct vfio_device *vdev, const char __user *buf, size_t count, loff_t *ppos) { + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); unsigned int done = 0; int ret; @@ -854,7 +844,7 @@ static ssize_t mtty_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (u8 *)&val, sizeof(val), + ret = mdev_access(mdev_state, (u8 *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -866,7 +856,7 @@ static ssize_t mtty_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (u8 *)&val, sizeof(val), + ret = mdev_access(mdev_state, (u8 *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -878,7 +868,7 @@ static ssize_t mtty_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (u8 *)&val, sizeof(val), + ret = mdev_access(mdev_state, (u8 *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -896,19 +886,11 @@ static ssize_t mtty_write(struct mdev_device *mdev, const char __user *buf, return -EFAULT; } -static int mtty_set_irqs(struct mdev_device *mdev, uint32_t flags, +static int mtty_set_irqs(struct mdev_state *mdev_state, uint32_t flags, unsigned int index, unsigned int start, unsigned int count, void *data) { int ret = 0; - struct mdev_state *mdev_state; - - if (!mdev) - return -EINVAL; - - mdev_state = mdev_get_drvdata(mdev); - if (!mdev_state) - return -EINVAL; mutex_lock(&mdev_state->ops_lock); switch (index) { @@ -1024,21 +1006,13 @@ static int mtty_trigger_interrupt(struct mdev_state *mdev_state) return ret; } -static int mtty_get_region_info(struct mdev_device *mdev, +static int mtty_get_region_info(struct mdev_state *mdev_state, struct vfio_region_info *region_info, u16 *cap_type_id, void **cap_type) { unsigned int size = 0; - struct mdev_state *mdev_state; u32 bar_index; - if (!mdev) - return -EINVAL; - - mdev_state = mdev_get_drvdata(mdev); - if (!mdev_state) - return -EINVAL; - bar_index = region_info->index; if (bar_index >= VFIO_PCI_NUM_REGIONS) return -EINVAL; @@ -1073,8 +1047,7 @@ static int mtty_get_region_info(struct mdev_device *mdev, return 0; } -static int mtty_get_irq_info(struct mdev_device *mdev, - struct vfio_irq_info *irq_info) +static int mtty_get_irq_info(struct vfio_irq_info *irq_info) { switch (irq_info->index) { case VFIO_PCI_INTX_IRQ_INDEX: @@ -1098,8 +1071,7 @@ static int mtty_get_irq_info(struct mdev_device *mdev, return 0; } -static int mtty_get_device_info(struct mdev_device *mdev, - struct vfio_device_info *dev_info) +static int mtty_get_device_info(struct vfio_device_info *dev_info) { dev_info->flags = VFIO_DEVICE_FLAGS_PCI; dev_info->num_regions = VFIO_PCI_NUM_REGIONS; @@ -1108,19 +1080,13 @@ static int mtty_get_device_info(struct mdev_device *mdev, return 0; } -static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd, +static long mtty_ioctl(struct vfio_device *vdev, unsigned int cmd, unsigned long arg) { + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); int ret = 0; unsigned long minsz; - struct mdev_state *mdev_state; - - if (!mdev) - return -EINVAL; - - mdev_state = mdev_get_drvdata(mdev); - if (!mdev_state) - return -ENODEV; switch (cmd) { case VFIO_DEVICE_GET_INFO: @@ -1135,7 +1101,7 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd, if (info.argsz < minsz) return -EINVAL; - ret = mtty_get_device_info(mdev, &info); + ret = mtty_get_device_info(&info); if (ret) return ret; @@ -1160,7 +1126,7 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd, if (info.argsz < minsz) return -EINVAL; - ret = mtty_get_region_info(mdev, &info, &cap_type_id, + ret = mtty_get_region_info(mdev_state, &info, &cap_type_id, &cap_type); if (ret) return ret; @@ -1184,7 +1150,7 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd, (info.index >= mdev_state->dev_info.num_irqs)) return -EINVAL; - ret = mtty_get_irq_info(mdev, &info); + ret = mtty_get_irq_info(&info); if (ret) return ret; @@ -1218,25 +1184,25 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd, return PTR_ERR(data); } - ret = mtty_set_irqs(mdev, hdr.flags, hdr.index, hdr.start, + ret = mtty_set_irqs(mdev_state, hdr.flags, hdr.index, hdr.start, hdr.count, data); kfree(ptr); return ret; } case VFIO_DEVICE_RESET: - return mtty_reset(mdev); + return mtty_reset(mdev_state); } return -ENOTTY; } -static int mtty_open(struct mdev_device *mdev) +static int mtty_open(struct vfio_device *vdev) { pr_info("%s\n", __func__); return 0; } -static void mtty_close(struct mdev_device *mdev) +static void mtty_close(struct vfio_device *mdev) { pr_info("%s\n", __func__); } @@ -1351,18 +1317,31 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; +static const struct vfio_device_ops mtty_dev_ops = { + .name = "vfio-mdev", + .open = mtty_open, + .release = mtty_close, + .read = mtty_read, + .write = mtty_write, + .ioctl = mtty_ioctl, +}; + +static struct mdev_driver mtty_driver = { + .driver = { + .name = "mtty", + .owner = THIS_MODULE, + .mod_name = KBUILD_MODNAME, + .dev_groups = mdev_dev_groups, + }, + .probe = mtty_probe, + .remove = mtty_remove, +}; + static const struct mdev_parent_ops mdev_fops = { .owner = THIS_MODULE, + .device_driver = &mtty_driver, .dev_attr_groups = mtty_dev_groups, - .mdev_attr_groups = mdev_dev_groups, .supported_type_groups = mdev_type_groups, - .create = mtty_create, - .remove = mtty_remove, - .open = mtty_open, - .release = mtty_close, - .read = mtty_read, - .write = mtty_write, - .ioctl = mtty_ioctl, }; static void mtty_device_release(struct device *dev) @@ -1393,12 +1372,16 @@ static int __init mtty_dev_init(void) pr_info("major_number:%d\n", MAJOR(mtty_dev.vd_devt)); + ret = mdev_register_driver(&mtty_driver); + if (ret) + goto err_cdev; + mtty_dev.vd_class = class_create(THIS_MODULE, MTTY_CLASS_NAME); if (IS_ERR(mtty_dev.vd_class)) { pr_err("Error: failed to register mtty_dev class\n"); ret = PTR_ERR(mtty_dev.vd_class); - goto failed1; + goto err_driver; } mtty_dev.dev.class = mtty_dev.vd_class; @@ -1407,28 +1390,25 @@ static int __init mtty_dev_init(void) ret = device_register(&mtty_dev.dev); if (ret) - goto failed2; + goto err_class; ret = mdev_register_device(&mtty_dev.dev, &mdev_fops); if (ret) - goto failed3; + goto err_device; mutex_init(&mdev_list_lock); INIT_LIST_HEAD(&mdev_devices_list); + return 0; - goto all_done; - -failed3: - +err_device: device_unregister(&mtty_dev.dev); -failed2: +err_class: class_destroy(mtty_dev.vd_class); - -failed1: +err_driver: + mdev_unregister_driver(&mtty_driver); +err_cdev: cdev_del(&mtty_dev.vd_cdev); unregister_chrdev_region(mtty_dev.vd_devt, MINORMASK + 1); - -all_done: return ret; } @@ -1439,6 +1419,7 @@ static void __exit mtty_dev_exit(void) device_unregister(&mtty_dev.dev); idr_destroy(&mtty_dev.vd_idr); + mdev_unregister_driver(&mtty_driver); cdev_del(&mtty_dev.vd_cdev); unregister_chrdev_region(mtty_dev.vd_devt, MINORMASK + 1); class_destroy(mtty_dev.vd_class); From patchwork Mon Apr 26 20:00:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12225015 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=-13.2 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,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY 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 527D9C433ED for ; Mon, 26 Apr 2021 20:00:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 370886135D for ; Mon, 26 Apr 2021 20:00:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241840AbhDZUBX (ORCPT ); Mon, 26 Apr 2021 16:01:23 -0400 Received: from mail-bn8nam08on2048.outbound.protection.outlook.com ([40.107.100.48]:25530 "EHLO NAM04-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S241751AbhDZUBJ (ORCPT ); Mon, 26 Apr 2021 16:01:09 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A9HhP0AyzDFQ3n41Ogtww5sS/I62ec8YbjutkrtztEdFE+6+M+p3jFZyEU/nbEgV1dSHyp3DcuOJsGq0mndpPu+fHVxr8Q8xphknR9dGKKT1mk19+kA2gOmydojv+CBFGUCeVvO1sxVwtzA4HjDuD/aqeXUKIs62IC6z3RMf+PCIuahRNV7qO386bRvev+G4JAyMY32mHgW8XBFg1nSzog+0QZzbmf18RxpPCvEejcv6jdUiaUi2BJiZsU7rBKeHJkkCH8ScN6GFK9G9TNC0RknCMMAbT7D4/s33bmR/ygYz/xAX3okYw9y8tm+bZ8WZNhMmFh121BwZXU+xW/I3rw== 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=9nc+DIr0N8cUIB4/Mq+dyr9kmNs+u6iPfXLV8Mx51HE=; b=fssOjO0aReJNs2AjZtAdz1PKzx/BqoEaeuqSwkzAok0/SvaostdrAro1tjcPFp3Dz1ZH0lPfFhvy3viijexXJiQQF8qr4vL4xTBJX+9MD92nkvAtHhXXMy3x80+wjd9VTP1kO8ioUGMNQLjE3Ra7QkZV/h1gQkoqy0Y91uZShS87Yz1QGdc3uypmOcgLQWn93WL9n4y9A4ct17xA3jSMUS0Sm3Gi2snpfEHkemWd3FzRFxUKDQGqajXOov6dSMV72WAyRtZq8tYfI/mBF54hVBeoO1iCH+CX1T57AUX0o+8mdp5b1LCuZ2aad+capdQ+XerwlY2p8b1kv0SVejgN8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9nc+DIr0N8cUIB4/Mq+dyr9kmNs+u6iPfXLV8Mx51HE=; b=cH3RQhPNXIsYvDU/aNMNnEX8LBIosVxbgzxFnKdn/naHtDnaKj3pP65nYNkhUtXXw/vDMyvjx77II1QiRV8Zr3WpEYes1mFyktRtz0YW6tfPucUd3P789BJENphTdy5LpEW0DQX57s98Ngdw+rhew/nnCtNSTXicb3Vg8uIfwIf8N4M4DRrY6pvnq6pqbMuV9u8Y9J8+3hV3dt7Vjmn+PWjhPOJ9kNYLdYkOvKWRf7ktgNXGSenLxdjByeyOAJcO6HhWWzYn/lvEo45Vvs6GAwIhCcXkCUeuUB+TX415clLcg7hUQvrv+Mlru/ZZH2BiFXf1ecRrz1QE+OxcazB3Vg== Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3740.namprd12.prod.outlook.com (2603:10b6:5:1c3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.24; Mon, 26 Apr 2021 20:00:22 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.4065.026; Mon, 26 Apr 2021 20:00:22 +0000 From: Jason Gunthorpe To: kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Dan Williams , Daniel Vetter , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 04/13] vfio/mdpy: Convert to use vfio_register_group_dev() Date: Mon, 26 Apr 2021 17:00:06 -0300 Message-Id: <4-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> In-Reply-To: <0-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: MN2PR03CA0025.namprd03.prod.outlook.com (2603:10b6:208:23a::30) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by MN2PR03CA0025.namprd03.prod.outlook.com (2603:10b6:208:23a::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20 via Frontend Transport; Mon, 26 Apr 2021 20:00:18 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lb7Ox-00DFZD-S3; Mon, 26 Apr 2021 17:00:15 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5a2c3c47-85fd-47b5-88e8-08d908edeabf X-MS-TrafficTypeDiagnostic: DM6PR12MB3740: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:126; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ULHO86FevKUeEs7uP9i0dIaKqOFryUk7ccFMrSkBcR7jCkl7OuW58iWijVcM6nsqoI1Ak1My8hfS6DDw5y+jkpoCsruQy3UAAnQNDAemXgZoOI8OEppGdo9l1fh4q0j21kovRT25YOGZOSai8X8/cHGerBCV9JokMiuf+lql1DvZ3QkHRLkV81QanxzwggAfOribEOpXq2tI6LEgRf7J+XptpeSh+EKqLodOhjYsNxf+YmRlQ7pRVAD2oVrYgA2+qb24eEDhugQ7UkCQZ6snTqEzmapuCHlQC/I+HfR/K2rqJi8ngLZGw6SZpQ4CZr5zSi+ltb7iX9ID/7jgnqBdICuQWyArKRRC4YdA9o5hiKNZ9/KhhT8FE6vXmHa/ZU6wi7WAsITySNbn22K3aX/ODV7T+29ol4WvgYpH6V/DW3n9I5R6i3z3hhY5Y06B6CJWTaTWJXr+kL2GPeSjzUVgzBNuWnRTvHPuDlw7rTvyh+ZcR2rOFjCpDxUzidyhnuYcBQUDoiivGuL8AGT2G9OoI9w3KqbzltpdVwKNghu+Xs+tzl3C7A1PmtOEm8kbZJ+0RJArTrJb7ivOKUHxnebENKg7gmeQjmshffc/I1NBA3Vg4PPOIbSLPVxWyIeFeJkGxcyYtGPFe0jy+U4jDp6V7g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(39860400002)(346002)(136003)(396003)(376002)(66476007)(66556008)(9746002)(6862004)(54906003)(426003)(37006003)(107886003)(186003)(26005)(6666004)(36756003)(316002)(2906002)(30864003)(2616005)(478600001)(6636002)(9786002)(8936002)(83380400001)(38100700002)(86362001)(8676002)(5660300002)(4326008)(66946007)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: w1J18/waxHhWXQebzayaROO/gXFXQMbl0Szu+45weWSDj7rYWePZU80HKYNpsAxuIUp8yzGZTHY6/bjiCHQqO1lHDeVNrwcvolihuOm9IzqLcNHOmXlDlwXK5Ju/gM5UTn72xgG987WYKCOOhp1h7l2JJBFfPPpdSOZGKJMKkIuw3fLOBSMiHc/t2c4nEGwXYmkQ+viOGMi3nNTlcM5MjtvueZc/nro7QAcZ//dDKAcD7ZDQQpBcUvxgeC+7rMfR3Z7J9KHohLkfCLGlIT/CdKt5bUoHvfNGnscAJLuAB1fSpZi+QrJzYV4vLKc+KcRLsyPZEcU7IlBOj1TYrQvWFRXGuQEr35eOHk6mplHhxZhjwEKwMCDyNX50JnmjzPEnTeB4A2zUzB/ipFK/FDhgI4A3eiRM1X9snIRoAUQEWE0Tb+MBUxCJcXqVeLsiShEk80ffaIujEGN59GqQK6GL3nrqQRpEcayT7Wg320Kmje8Q0cBaoU3U/FrgJftiMZ9lVXNcFJ0Cshn1XPCmF6RV4ExbQ30mr1j24hHU1qqyoy9KTNPZHeABxBOh5E+rN7wQ0CNTqj9rSyWmmcR1O6bb4QM30M+BipMa9428offPrMtgdHXk/I/xhAATu1S4ugyopAjiLwkFhCAGEK+ojVu8Uap5W6xK5Q+kmX9sNn2kn5VjcmKJFXSn+WoNMbLlj9eHr7nC5recJ2iB6JTOqvDV3pB9VUvhl99OTlO4N+/dskhv5IAxueLcD95a2RkDJrTbUcnivOs9796Hsm/WSwBUpHYh4seIiqdt+5opnQ7V2fa4ETtvAbod2Ji5TAk1cSIDi0hk/tq+kYA1rJyBQuOhZRMHmgmISdeyBVFTi8DRoox+FQJIJX1O9jZR8J9OTQ82tOR6vE6yIWdJSYokjb1jH5l0GKiCPQ+ny9U2mWlvGWzVVMeJRpv4JtfQvknRp+QoEw3yPvHWW7rP0BwQ/yeDHvg9N5jNiLPEW1swOJTsxJuOOb5Dhz8YH7BegaTGPZvBZwML0EXTXtPx/tpSPZ/wFv/SEPumpC0KNrsHlaWoGNfATOJ5g28EgzGbDM8sLwqAclbpjqSw3Mj9JMjg4hoIRPtuumjWwn0PuWg5ZXG9mc8QrWf64sx/iNVPkH63Hn2kZ8hqIfJCQhc996z8JX/eGq0bgJgrQ7KXEsyNJ0qnMQU7G2Kv2AH55Po3EYWWc/N7WGYh+gkEyZCYEi5/5f652liaIC0PeMPSh7vTwZ9U9G9Mf2zhWvtcUs7U4O2qXwgkQhRFieBk95dUCDRLRL4bRCHtitbC14wqbsiVtjfPwNtZxoNFH8MiY4NwDcAitTY5 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5a2c3c47-85fd-47b5-88e8-08d908edeabf X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2021 20:00:19.0776 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rtBs+6spffBv9PMzeetoTqKHonP0hAqxO8Qy0Vqfznb/EISP7Gaks4Tb7dbF8vtH X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3740 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is straightforward conversion, the mdev_state is actually serving as the vfio_device and we can replace all the mdev_get_drvdata()'s and the wonky dead code with a simple container_of(). Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- samples/vfio-mdev/mdpy.c | 159 ++++++++++++++++++++++----------------- 1 file changed, 88 insertions(+), 71 deletions(-) diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c index 885b88ea20e234..82638de333330d 100644 --- a/samples/vfio-mdev/mdpy.c +++ b/samples/vfio-mdev/mdpy.c @@ -85,9 +85,11 @@ static struct class *mdpy_class; static struct cdev mdpy_cdev; static struct device mdpy_dev; static u32 mdpy_count; +static const struct vfio_device_ops mdpy_dev_ops; /* State of each mdev device */ struct mdev_state { + struct vfio_device vdev; u8 *vconfig; u32 bar_mask; struct mutex ops_lock; @@ -162,11 +164,9 @@ static void handle_pci_cfg_write(struct mdev_state *mdev_state, u16 offset, } } -static ssize_t mdev_access(struct mdev_device *mdev, char *buf, size_t count, - loff_t pos, bool is_write) +static ssize_t mdev_access(struct mdev_state *mdev_state, char *buf, + size_t count, loff_t pos, bool is_write) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); - struct device *dev = mdev_dev(mdev); int ret = 0; mutex_lock(&mdev_state->ops_lock); @@ -187,8 +187,9 @@ static ssize_t mdev_access(struct mdev_device *mdev, char *buf, size_t count, memcpy(buf, mdev_state->memblk, count); } else { - dev_info(dev, "%s: %s @0x%llx (unhandled)\n", - __func__, is_write ? "WR" : "RD", pos); + dev_info(mdev_state->vdev.dev, + "%s: %s @0x%llx (unhandled)\n", __func__, + is_write ? "WR" : "RD", pos); ret = -1; goto accessfailed; } @@ -202,9 +203,8 @@ static ssize_t mdev_access(struct mdev_device *mdev, char *buf, size_t count, return ret; } -static int mdpy_reset(struct mdev_device *mdev) +static int mdpy_reset(struct mdev_state *mdev_state) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); u32 stride, i; /* initialize with gray gradient */ @@ -216,13 +216,14 @@ static int mdpy_reset(struct mdev_device *mdev) return 0; } -static int mdpy_create(struct mdev_device *mdev) +static int mdpy_probe(struct mdev_device *mdev) { const struct mdpy_type *type = &mdpy_types[mdev_get_type_group_id(mdev)]; struct device *dev = mdev_dev(mdev); struct mdev_state *mdev_state; u32 fbsize; + int ret; if (mdpy_count >= max_devices) return -ENOMEM; @@ -230,6 +231,7 @@ static int mdpy_create(struct mdev_device *mdev) mdev_state = kzalloc(sizeof(struct mdev_state), GFP_KERNEL); if (mdev_state == NULL) return -ENOMEM; + vfio_init_group_dev(&mdev_state->vdev, &mdev->dev, &mdpy_dev_ops); mdev_state->vconfig = kzalloc(MDPY_CONFIG_SPACE_SIZE, GFP_KERNEL); if (mdev_state->vconfig == NULL) { @@ -250,36 +252,41 @@ static int mdpy_create(struct mdev_device *mdev) mutex_init(&mdev_state->ops_lock); mdev_state->mdev = mdev; - mdev_set_drvdata(mdev, mdev_state); - mdev_state->type = type; mdev_state->memsize = fbsize; mdpy_create_config_space(mdev_state); - mdpy_reset(mdev); + mdpy_reset(mdev_state); mdpy_count++; + + ret = vfio_register_group_dev(&mdev_state->vdev); + if (ret) { + kfree(mdev_state); + return ret; + } + dev_set_drvdata(&mdev->dev, mdev_state); return 0; } -static int mdpy_remove(struct mdev_device *mdev) +static void mdpy_remove(struct mdev_device *mdev) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); - struct device *dev = mdev_dev(mdev); + struct mdev_state *mdev_state = dev_get_drvdata(&mdev->dev); - dev_info(dev, "%s\n", __func__); + dev_info(&mdev->dev, "%s\n", __func__); - mdev_set_drvdata(mdev, NULL); + vfio_unregister_group_dev(&mdev_state->vdev); vfree(mdev_state->memblk); kfree(mdev_state->vconfig); kfree(mdev_state); mdpy_count--; - return 0; } -static ssize_t mdpy_read(struct mdev_device *mdev, char __user *buf, +static ssize_t mdpy_read(struct vfio_device *vdev, char __user *buf, size_t count, loff_t *ppos) { + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); unsigned int done = 0; int ret; @@ -289,8 +296,8 @@ static ssize_t mdpy_read(struct mdev_device *mdev, char __user *buf, if (count >= 4 && !(*ppos % 4)) { u32 val; - ret = mdev_access(mdev, (char *)&val, sizeof(val), - *ppos, false); + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), + *ppos, false); if (ret <= 0) goto read_err; @@ -301,7 +308,7 @@ static ssize_t mdpy_read(struct mdev_device *mdev, char __user *buf, } else if (count >= 2 && !(*ppos % 2)) { u16 val; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, false); if (ret <= 0) goto read_err; @@ -313,7 +320,7 @@ static ssize_t mdpy_read(struct mdev_device *mdev, char __user *buf, } else { u8 val; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, false); if (ret <= 0) goto read_err; @@ -336,9 +343,11 @@ static ssize_t mdpy_read(struct mdev_device *mdev, char __user *buf, return -EFAULT; } -static ssize_t mdpy_write(struct mdev_device *mdev, const char __user *buf, +static ssize_t mdpy_write(struct vfio_device *vdev, const char __user *buf, size_t count, loff_t *ppos) { + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); unsigned int done = 0; int ret; @@ -351,7 +360,7 @@ static ssize_t mdpy_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -363,7 +372,7 @@ static ssize_t mdpy_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -375,7 +384,7 @@ static ssize_t mdpy_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -393,9 +402,10 @@ static ssize_t mdpy_write(struct mdev_device *mdev, const char __user *buf, return -EFAULT; } -static int mdpy_mmap(struct mdev_device *mdev, struct vm_area_struct *vma) +static int mdpy_mmap(struct vfio_device *vdev, struct vm_area_struct *vma) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); if (vma->vm_pgoff != MDPY_MEMORY_BAR_OFFSET >> PAGE_SHIFT) return -EINVAL; @@ -411,16 +421,10 @@ static int mdpy_mmap(struct mdev_device *mdev, struct vm_area_struct *vma) vma->vm_end - vma->vm_start); } -static int mdpy_get_region_info(struct mdev_device *mdev, +static int mdpy_get_region_info(struct mdev_state *mdev_state, struct vfio_region_info *region_info, u16 *cap_type_id, void **cap_type) { - struct mdev_state *mdev_state; - - mdev_state = mdev_get_drvdata(mdev); - if (!mdev_state) - return -EINVAL; - if (region_info->index >= VFIO_PCI_NUM_REGIONS && region_info->index != MDPY_DISPLAY_REGION) return -EINVAL; @@ -449,15 +453,13 @@ static int mdpy_get_region_info(struct mdev_device *mdev, return 0; } -static int mdpy_get_irq_info(struct mdev_device *mdev, - struct vfio_irq_info *irq_info) +static int mdpy_get_irq_info(struct vfio_irq_info *irq_info) { irq_info->count = 0; return 0; } -static int mdpy_get_device_info(struct mdev_device *mdev, - struct vfio_device_info *dev_info) +static int mdpy_get_device_info(struct vfio_device_info *dev_info) { dev_info->flags = VFIO_DEVICE_FLAGS_PCI; dev_info->num_regions = VFIO_PCI_NUM_REGIONS; @@ -465,11 +467,9 @@ static int mdpy_get_device_info(struct mdev_device *mdev, return 0; } -static int mdpy_query_gfx_plane(struct mdev_device *mdev, +static int mdpy_query_gfx_plane(struct mdev_state *mdev_state, struct vfio_device_gfx_plane_info *plane) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); - if (plane->flags & VFIO_GFX_PLANE_TYPE_PROBE) { if (plane->flags == (VFIO_GFX_PLANE_TYPE_PROBE | VFIO_GFX_PLANE_TYPE_REGION)) @@ -498,14 +498,13 @@ static int mdpy_query_gfx_plane(struct mdev_device *mdev, return 0; } -static long mdpy_ioctl(struct mdev_device *mdev, unsigned int cmd, +static long mdpy_ioctl(struct vfio_device *vdev, unsigned int cmd, unsigned long arg) { int ret = 0; unsigned long minsz; - struct mdev_state *mdev_state; - - mdev_state = mdev_get_drvdata(mdev); + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); switch (cmd) { case VFIO_DEVICE_GET_INFO: @@ -520,7 +519,7 @@ static long mdpy_ioctl(struct mdev_device *mdev, unsigned int cmd, if (info.argsz < minsz) return -EINVAL; - ret = mdpy_get_device_info(mdev, &info); + ret = mdpy_get_device_info(&info); if (ret) return ret; @@ -545,7 +544,7 @@ static long mdpy_ioctl(struct mdev_device *mdev, unsigned int cmd, if (info.argsz < minsz) return -EINVAL; - ret = mdpy_get_region_info(mdev, &info, &cap_type_id, + ret = mdpy_get_region_info(mdev_state, &info, &cap_type_id, &cap_type); if (ret) return ret; @@ -569,7 +568,7 @@ static long mdpy_ioctl(struct mdev_device *mdev, unsigned int cmd, (info.index >= mdev_state->dev_info.num_irqs)) return -EINVAL; - ret = mdpy_get_irq_info(mdev, &info); + ret = mdpy_get_irq_info(&info); if (ret) return ret; @@ -592,7 +591,7 @@ static long mdpy_ioctl(struct mdev_device *mdev, unsigned int cmd, if (plane.argsz < minsz) return -EINVAL; - ret = mdpy_query_gfx_plane(mdev, &plane); + ret = mdpy_query_gfx_plane(mdev_state, &plane); if (ret) return ret; @@ -606,12 +605,12 @@ static long mdpy_ioctl(struct mdev_device *mdev, unsigned int cmd, return -EINVAL; case VFIO_DEVICE_RESET: - return mdpy_reset(mdev); + return mdpy_reset(mdev_state); } return -ENOTTY; } -static int mdpy_open(struct mdev_device *mdev) +static int mdpy_open(struct vfio_device *vdev) { if (!try_module_get(THIS_MODULE)) return -ENODEV; @@ -619,7 +618,7 @@ static int mdpy_open(struct mdev_device *mdev) return 0; } -static void mdpy_close(struct mdev_device *mdev) +static void mdpy_close(struct vfio_device *vdev) { module_put(THIS_MODULE); } @@ -628,8 +627,7 @@ static ssize_t resolution_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct mdev_device *mdev = mdev_from_dev(dev); - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); + struct mdev_state *mdev_state = dev_get_drvdata(dev); return sprintf(buf, "%dx%d\n", mdev_state->type->width, @@ -719,18 +717,30 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; +static const struct vfio_device_ops mdpy_dev_ops = { + .open = mdpy_open, + .release = mdpy_close, + .read = mdpy_read, + .write = mdpy_write, + .ioctl = mdpy_ioctl, + .mmap = mdpy_mmap, +}; + +static struct mdev_driver mdpy_driver = { + .driver = { + .name = "mdpy", + .owner = THIS_MODULE, + .mod_name = KBUILD_MODNAME, + .dev_groups = mdev_dev_groups, + }, + .probe = mdpy_probe, + .remove = mdpy_remove, +}; + static const struct mdev_parent_ops mdev_fops = { .owner = THIS_MODULE, - .mdev_attr_groups = mdev_dev_groups, + .device_driver = &mdpy_driver, .supported_type_groups = mdev_type_groups, - .create = mdpy_create, - .remove = mdpy_remove, - .open = mdpy_open, - .release = mdpy_close, - .read = mdpy_read, - .write = mdpy_write, - .ioctl = mdpy_ioctl, - .mmap = mdpy_mmap, }; static const struct file_operations vd_fops = { @@ -755,11 +765,15 @@ static int __init mdpy_dev_init(void) cdev_add(&mdpy_cdev, mdpy_devt, MINORMASK + 1); pr_info("%s: major %d\n", __func__, MAJOR(mdpy_devt)); + ret = mdev_register_driver(&mdpy_driver); + if (ret) + goto err_cdev; + mdpy_class = class_create(THIS_MODULE, MDPY_CLASS_NAME); if (IS_ERR(mdpy_class)) { pr_err("Error: failed to register mdpy_dev class\n"); ret = PTR_ERR(mdpy_class); - goto failed1; + goto err_driver; } mdpy_dev.class = mdpy_class; mdpy_dev.release = mdpy_device_release; @@ -767,19 +781,21 @@ static int __init mdpy_dev_init(void) ret = device_register(&mdpy_dev); if (ret) - goto failed2; + goto err_class; ret = mdev_register_device(&mdpy_dev, &mdev_fops); if (ret) - goto failed3; + goto err_device; return 0; -failed3: +err_device: device_unregister(&mdpy_dev); -failed2: +err_class: class_destroy(mdpy_class); -failed1: +err_driver: + mdev_unregister_driver(&mdpy_driver); +err_cdev: cdev_del(&mdpy_cdev); unregister_chrdev_region(mdpy_devt, MINORMASK + 1); return ret; @@ -791,6 +807,7 @@ static void __exit mdpy_dev_exit(void) mdev_unregister_device(&mdpy_dev); device_unregister(&mdpy_dev); + mdev_unregister_driver(&mdpy_driver); cdev_del(&mdpy_cdev); unregister_chrdev_region(mdpy_devt, MINORMASK + 1); class_destroy(mdpy_class); From patchwork Mon Apr 26 20:00:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12225003 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=-16.0 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,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS 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 495B3C43470 for ; Mon, 26 Apr 2021 20:00:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F6FA613AB for ; Mon, 26 Apr 2021 20:00:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241776AbhDZUBH (ORCPT ); Mon, 26 Apr 2021 16:01:07 -0400 Received: from mail-dm6nam11on2085.outbound.protection.outlook.com ([40.107.223.85]:3982 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S241751AbhDZUBF (ORCPT ); Mon, 26 Apr 2021 16:01:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RT1GEBkslHBB2KGtqwsIZEB/rh+PBpkXku3JD3R0VzEfoKhsT7j7xQxbjknSJ1dHfZAhQjqa1PC1KK2NVEj0/gl8F61sei6nlz1CExNrxIR5dALZop6J7hgRkb8dqeQr0AxHoBAw+2l0j6F1vBvKfkj+phKveHSudv0BoUfp+lIzztQ3e6zEmRiteSfz93QBfLU2NVwJpBEStqy3PqwWe+ip6/JdefqY1DDQ6d+Trlc83//fky3MNRp7SA9MXTLwpUouAKYSK6IdIb/zgcmX+0CPiyuCrKqwOY9quJyMWdSCUinowzPwlT0ST1mmNghATp3RCb9/Pla152jszuS1cA== 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=bPmWwfiY76LrNjwW05YwP7QvqV3Mr1EaO2sh4Dhq21o=; b=nW/Q0ZhuJiW4x0hYYKOCiyAWq7V7q0z1p/o1ACg4AqqsvmuU9JSnO22sYMvhczFa7EuHThxbenm1tt8jGi4/2YkERNPAwV58PC5cOp6876tzp7/H10CWdwb5WvRWym8HuKFe2nRZyMVmXvPsSdk6badRAKTrjPe3+KLaR6CfPUoJSDrJwR3Ttn7uZvSHMJVgmWrzwkQk7K12p7HJaVj/TDxoeMxlj7l0U9FzFi+zOtkZIlDFWU5UtYYnKXiHjBu3aGieTSS9sB76FLa3Khu/eoaa9hnQ2+DLo2C4Kz0lZqf6d720ezkVX8j6UCV0gSt5YNBbvU+W8qiV+ZlXLLr0JQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bPmWwfiY76LrNjwW05YwP7QvqV3Mr1EaO2sh4Dhq21o=; b=YPoueLP30IuF4K1zdgYa+nzpKQ6H2F+34d/rrN2F2AvvMOeE/oRia7+sAFk3bsfmlOCZ6Ar2w8R9t/XMcNI54P8+VGnZCvVLtCzK/V3CDLgk2ufyFEZg3R/lL4REupaE6jQncVDjtKlVI7imx5MGJx8phR5SRRBSU1FQ+rqf+fxr7qj+LooRK0xuLMPOKKu9Si6Oph43scSMRkCgY64CjSPsmnFA/i7CoMurpvEM1MrSM72Zyshw/JFIQbDT7hTZGvvpfeg5sM6N3/wSwSK8QVMRa6Uj9HppPR0GtmhuNHOgEALwcxF5IY8SVY0/IV9dbv/LpGdoOpyTSC7d/0bjGA== Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM5PR12MB1659.namprd12.prod.outlook.com (2603:10b6:4:11::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Mon, 26 Apr 2021 20:00:20 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.4065.026; Mon, 26 Apr 2021 20:00:20 +0000 From: Jason Gunthorpe To: kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Dan Williams , Daniel Vetter , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 05/13] vfio/mbochs: Convert to use vfio_register_group_dev() Date: Mon, 26 Apr 2021 17:00:07 -0300 Message-Id: <5-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> In-Reply-To: <0-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: MN2PR15CA0014.namprd15.prod.outlook.com (2603:10b6:208:1b4::27) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by MN2PR15CA0014.namprd15.prod.outlook.com (2603:10b6:208:1b4::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20 via Frontend Transport; Mon, 26 Apr 2021 20:00:18 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lb7Ox-00DFZH-U9; Mon, 26 Apr 2021 17:00:15 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 24aea0a6-5d7e-45a8-1374-08d908edea45 X-MS-TrafficTypeDiagnostic: DM5PR12MB1659: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:198; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: R1mvTpNMhjpOYMF67SAgVll5fLEPgNxzIVczSGrW4dnbAGDBRYohj1+kFwpgQrqHB4wf3fpplpH+Y0tFnGm1OJqW1y7J8imTvxc6We3gJa/a8w25pNK+OeA7hnAEYvCRaoL8IIIEdmZ/iwGrGpLmUX6r3B65kZViOi4/z93fj49624kcJe4GOgWqM3C7WpScNR/ly460OPbylC1X7Ptg7nLcbwnUArVGzBFl6LWTijcltjXeyPe1GP7JVVZr22dXUYuZZu++F89ySOH9FErgNvjVuAUTeTp4OIjTqbqGTBdjsenORQLI7WV5TN8ny6FurwYpoYqTTp6KPT84k8RQ629UEtX4U2WSvcJmzaq9IJ4lNCLbOBZG4f7KeMg3f9WaH8f3WkaVxbQ0NN94T6/OhSyL3FV/96lKxmD+O7Y1K1EF0lnBCeB8UXhoRVVrxe9uBRnK+HvNhVcw2Y2DGcWgA4hpqdlfqe2RVjUVkDoTAndJrRMfbg+L1lahQqON52qyfIxz88ZOWPfzrDrgQlNezt042YBWFZ/4hT8TwtIWDVbWMFC641+3KEBW60N2U+KVFjAVFIa4+Fk5Z9vJ44YxHefWByfUUXFeierZjsQ6uPQKLeQiixYW5/lG44KuOWTRdH1zme3tuS4cvyLmg/l++g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(136003)(396003)(366004)(39860400002)(376002)(66946007)(36756003)(66556008)(66476007)(8676002)(2906002)(86362001)(6666004)(6636002)(2616005)(8936002)(478600001)(30864003)(426003)(83380400001)(5660300002)(4326008)(38100700002)(9786002)(107886003)(37006003)(9746002)(6862004)(186003)(316002)(54906003)(26005)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: k7SMTQVRbF0Dg72vsbY8u7CRXtu+NMaCy257X0+FK6iTmNu28O1yP8+DhpgfwdCrgudvgYr8gNYBfkxzi4d80u2Vls3t2NHPYHb1AWjX93FfOSroQt5jIgolxC8Dm4RSyfmoJPjGWpwqYVz2An0rX7IiYm3WwpaImIAOHz90qpr4ecg2nRoyFWmDibYWaOHrkSDFoU6uqXJq5BTlO/5Pw1bJPl3SMfx1FACl653HrUJ9jTRIJUBcIwAKlet4Spo/tOML6JM82rJIzoA0+SqRgpKC4vMhYCpXM5PAUs+pPE9+Gpli4b4fnWApLWksJTgRsCyF3jkDFI4loXA2im7I1+cVJ7hxtm0CueG7xLia1Ttf7XTmZND/j6KJUwC1hVzclmKQLlPqBqJh7ZvrQDlKRkr7ffu9T27yQajRUkYkVXxFM46FbH7tfyFLdUGCzaXpbOlzTxAvT+q88oGyn/wY2WdknFb0IOG2gV111r53x4qozB9uty1LachHKMwV7ngZ8oJeBT9knnR4G39P8G46GnobLtyeshqdfUz1ShKMzFJAw3pxOzxzAFAZCCc+0s0iH03hTqRJCnbK6yVoracfMpu15857Uo6cYDt5ODQsxuQ74KVXbZyHHNxfHua4/4W85ftMYb28Vx9e9fOypt4WBvfQHevBgSb5jwaLJDd/4c9tjtXMlK72e/26Ia12ocqrr9N1vj+A5am3CzdTzp1hz1RC/LmICunCwziIl/LWK4e9lg5cadOS5ahjYenai68C1405XCcKnGZyCeoBpGV2uB+FSvRqs8gWLmOLOusYnrPi40h6xy2/intElEFF0xr2ykKesoArLwT/iwJCWLgMl5j6DhuQB/QwLj2fFPOP0yUoH9WtNNUINOjVhtZYO/ag53oxp9bU47th1ZnIBLSXn/xJ9tofrZoGSeNnUHiiyPVn+ofMz5ncWnYskgbDvFsL1HdK9nxBiuMfpZAoAUqJPAMKl1YhJ0G70IEwvRsWhqXbXNKEK3Dn14ovIHHvKCgNnel5WVYe8iwQoRRYKQKYvLvaQ9XfGbSuuuh04+YUeBLywOGVTENRLpjq8n/W6guSO8N9AH6BltygLRXz0j8VOQ/PYoRHehiKTpKD2eT98R5SeZI/kDx+xjhI48GZw/hbmDe07cCiMFdidPuIhAHeiGdJWKuvJCfwIbsYLUOfRXHeNWeQCuoonshwg1j+67wu8w9xywHIJCe48bdE4DcGHc2QZdBOrZbXFdI4XuZzQ9zkRjJj6d/FXP1+EVhE4+lN0pgrtFoticsgSa2GzOFm6m+pTHk6Zu4x2Dh75j5DKtp4noykvIuEFCTLDv29Nfyd X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 24aea0a6-5d7e-45a8-1374-08d908edea45 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2021 20:00:18.2531 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: D0GCFbShHF3xewAsQLpcqSFPHfgcDc6BCcNcplF9vtoeFD/GDbkWZt38+OqnXdsM X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1659 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is straightforward conversion, the mdev_state is actually serving as the vfio_device and we can replace all the mdev_get_drvdata()'s and the wonky dead code with a simple container_of(). Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- samples/vfio-mdev/mbochs.c | 163 +++++++++++++++++++++---------------- 1 file changed, 91 insertions(+), 72 deletions(-) diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index 861c76914e7639..e18821a8a6beb8 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -130,6 +130,7 @@ static struct class *mbochs_class; static struct cdev mbochs_cdev; static struct device mbochs_dev; static int mbochs_used_mbytes; +static const struct vfio_device_ops mbochs_dev_ops; struct vfio_region_info_ext { struct vfio_region_info base; @@ -160,6 +161,7 @@ struct mbochs_dmabuf { /* State of each mdev device */ struct mdev_state { + struct vfio_device vdev; u8 *vconfig; u64 bar_mask[3]; u32 memory_bar_mask; @@ -425,11 +427,9 @@ static void handle_edid_blob(struct mdev_state *mdev_state, u16 offset, memcpy(buf, mdev_state->edid_blob + offset, count); } -static ssize_t mdev_access(struct mdev_device *mdev, char *buf, size_t count, - loff_t pos, bool is_write) +static ssize_t mdev_access(struct mdev_state *mdev_state, char *buf, + size_t count, loff_t pos, bool is_write) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); - struct device *dev = mdev_dev(mdev); struct page *pg; loff_t poff; char *map; @@ -478,7 +478,7 @@ static ssize_t mdev_access(struct mdev_device *mdev, char *buf, size_t count, put_page(pg); } else { - dev_dbg(dev, "%s: %s @0x%llx (unhandled)\n", + dev_dbg(mdev_state->vdev.dev, "%s: %s @0x%llx (unhandled)\n", __func__, is_write ? "WR" : "RD", pos); ret = -1; goto accessfailed; @@ -493,9 +493,8 @@ static ssize_t mdev_access(struct mdev_device *mdev, char *buf, size_t count, return ret; } -static int mbochs_reset(struct mdev_device *mdev) +static int mbochs_reset(struct mdev_state *mdev_state) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); u32 size64k = mdev_state->memsize / (64 * 1024); int i; @@ -506,12 +505,13 @@ static int mbochs_reset(struct mdev_device *mdev) return 0; } -static int mbochs_create(struct mdev_device *mdev) +static int mbochs_probe(struct mdev_device *mdev) { const struct mbochs_type *type = &mbochs_types[mdev_get_type_group_id(mdev)]; struct device *dev = mdev_dev(mdev); struct mdev_state *mdev_state; + int ret = -ENOMEM; if (!type) type = &mbochs_types[0]; @@ -521,6 +521,7 @@ static int mbochs_create(struct mdev_device *mdev) mdev_state = kzalloc(sizeof(struct mdev_state), GFP_KERNEL); if (mdev_state == NULL) return -ENOMEM; + vfio_init_group_dev(&mdev_state->vdev, &mdev->dev, &mbochs_dev_ops); mdev_state->vconfig = kzalloc(MBOCHS_CONFIG_SPACE_SIZE, GFP_KERNEL); if (mdev_state->vconfig == NULL) @@ -539,7 +540,6 @@ static int mbochs_create(struct mdev_device *mdev) mutex_init(&mdev_state->ops_lock); mdev_state->mdev = mdev; - mdev_set_drvdata(mdev, mdev_state); INIT_LIST_HEAD(&mdev_state->dmabufs); mdev_state->next_id = 1; @@ -549,32 +549,38 @@ static int mbochs_create(struct mdev_device *mdev) mdev_state->edid_regs.edid_offset = MBOCHS_EDID_BLOB_OFFSET; mdev_state->edid_regs.edid_max_size = sizeof(mdev_state->edid_blob); mbochs_create_config_space(mdev_state); - mbochs_reset(mdev); + mbochs_reset(mdev_state); mbochs_used_mbytes += type->mbytes; + + ret = vfio_register_group_dev(&mdev_state->vdev); + if (ret) + goto err_mem; + dev_set_drvdata(&mdev->dev, mdev_state); return 0; err_mem: kfree(mdev_state->vconfig); kfree(mdev_state); - return -ENOMEM; + return ret; } -static int mbochs_remove(struct mdev_device *mdev) +static void mbochs_remove(struct mdev_device *mdev) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); + struct mdev_state *mdev_state = dev_get_drvdata(&mdev->dev); mbochs_used_mbytes -= mdev_state->type->mbytes; - mdev_set_drvdata(mdev, NULL); + vfio_unregister_group_dev(&mdev_state->vdev); kfree(mdev_state->pages); kfree(mdev_state->vconfig); kfree(mdev_state); - return 0; } -static ssize_t mbochs_read(struct mdev_device *mdev, char __user *buf, +static ssize_t mbochs_read(struct vfio_device *vdev, char __user *buf, size_t count, loff_t *ppos) { + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); unsigned int done = 0; int ret; @@ -584,7 +590,7 @@ static ssize_t mbochs_read(struct mdev_device *mdev, char __user *buf, if (count >= 4 && !(*ppos % 4)) { u32 val; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, false); if (ret <= 0) goto read_err; @@ -596,7 +602,7 @@ static ssize_t mbochs_read(struct mdev_device *mdev, char __user *buf, } else if (count >= 2 && !(*ppos % 2)) { u16 val; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, false); if (ret <= 0) goto read_err; @@ -608,7 +614,7 @@ static ssize_t mbochs_read(struct mdev_device *mdev, char __user *buf, } else { u8 val; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, false); if (ret <= 0) goto read_err; @@ -631,9 +637,11 @@ static ssize_t mbochs_read(struct mdev_device *mdev, char __user *buf, return -EFAULT; } -static ssize_t mbochs_write(struct mdev_device *mdev, const char __user *buf, +static ssize_t mbochs_write(struct vfio_device *vdev, const char __user *buf, size_t count, loff_t *ppos) { + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); unsigned int done = 0; int ret; @@ -646,7 +654,7 @@ static ssize_t mbochs_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -658,7 +666,7 @@ static ssize_t mbochs_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -670,7 +678,7 @@ static ssize_t mbochs_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -756,9 +764,10 @@ static const struct vm_operations_struct mbochs_region_vm_ops = { .fault = mbochs_region_vm_fault, }; -static int mbochs_mmap(struct mdev_device *mdev, struct vm_area_struct *vma) +static int mbochs_mmap(struct vfio_device *vdev, struct vm_area_struct *vma) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); if (vma->vm_pgoff != MBOCHS_MEMORY_BAR_OFFSET >> PAGE_SHIFT) return -EINVAL; @@ -965,7 +974,7 @@ mbochs_dmabuf_find_by_id(struct mdev_state *mdev_state, u32 id) static int mbochs_dmabuf_export(struct mbochs_dmabuf *dmabuf) { struct mdev_state *mdev_state = dmabuf->mdev_state; - struct device *dev = mdev_dev(mdev_state->mdev); + struct device *dev = mdev_state->vdev.dev; DEFINE_DMA_BUF_EXPORT_INFO(exp_info); struct dma_buf *buf; @@ -993,15 +1002,10 @@ static int mbochs_dmabuf_export(struct mbochs_dmabuf *dmabuf) return 0; } -static int mbochs_get_region_info(struct mdev_device *mdev, +static int mbochs_get_region_info(struct mdev_state *mdev_state, struct vfio_region_info_ext *ext) { struct vfio_region_info *region_info = &ext->base; - struct mdev_state *mdev_state; - - mdev_state = mdev_get_drvdata(mdev); - if (!mdev_state) - return -EINVAL; if (region_info->index >= MBOCHS_NUM_REGIONS) return -EINVAL; @@ -1049,15 +1053,13 @@ static int mbochs_get_region_info(struct mdev_device *mdev, return 0; } -static int mbochs_get_irq_info(struct mdev_device *mdev, - struct vfio_irq_info *irq_info) +static int mbochs_get_irq_info(struct vfio_irq_info *irq_info) { irq_info->count = 0; return 0; } -static int mbochs_get_device_info(struct mdev_device *mdev, - struct vfio_device_info *dev_info) +static int mbochs_get_device_info(struct vfio_device_info *dev_info) { dev_info->flags = VFIO_DEVICE_FLAGS_PCI; dev_info->num_regions = MBOCHS_NUM_REGIONS; @@ -1065,11 +1067,9 @@ static int mbochs_get_device_info(struct mdev_device *mdev, return 0; } -static int mbochs_query_gfx_plane(struct mdev_device *mdev, +static int mbochs_query_gfx_plane(struct mdev_state *mdev_state, struct vfio_device_gfx_plane_info *plane) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); - struct device *dev = mdev_dev(mdev); struct mbochs_dmabuf *dmabuf; struct mbochs_mode mode; int ret; @@ -1123,18 +1123,16 @@ static int mbochs_query_gfx_plane(struct mdev_device *mdev, done: if (plane->drm_plane_type == DRM_PLANE_TYPE_PRIMARY && mdev_state->active_id != plane->dmabuf_id) { - dev_dbg(dev, "%s: primary: %d => %d\n", __func__, - mdev_state->active_id, plane->dmabuf_id); + dev_dbg(mdev_state->vdev.dev, "%s: primary: %d => %d\n", + __func__, mdev_state->active_id, plane->dmabuf_id); mdev_state->active_id = plane->dmabuf_id; } mutex_unlock(&mdev_state->ops_lock); return 0; } -static int mbochs_get_gfx_dmabuf(struct mdev_device *mdev, - u32 id) +static int mbochs_get_gfx_dmabuf(struct mdev_state *mdev_state, u32 id) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); struct mbochs_dmabuf *dmabuf; mutex_lock(&mdev_state->ops_lock); @@ -1156,9 +1154,11 @@ static int mbochs_get_gfx_dmabuf(struct mdev_device *mdev, return dma_buf_fd(dmabuf->buf, 0); } -static long mbochs_ioctl(struct mdev_device *mdev, unsigned int cmd, - unsigned long arg) +static long mbochs_ioctl(struct vfio_device *vdev, unsigned int cmd, + unsigned long arg) { + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); int ret = 0; unsigned long minsz, outsz; @@ -1175,7 +1175,7 @@ static long mbochs_ioctl(struct mdev_device *mdev, unsigned int cmd, if (info.argsz < minsz) return -EINVAL; - ret = mbochs_get_device_info(mdev, &info); + ret = mbochs_get_device_info(&info); if (ret) return ret; @@ -1199,7 +1199,7 @@ static long mbochs_ioctl(struct mdev_device *mdev, unsigned int cmd, if (outsz > sizeof(info)) return -EINVAL; - ret = mbochs_get_region_info(mdev, &info); + ret = mbochs_get_region_info(mdev_state, &info); if (ret) return ret; @@ -1222,7 +1222,7 @@ static long mbochs_ioctl(struct mdev_device *mdev, unsigned int cmd, (info.index >= VFIO_PCI_NUM_IRQS)) return -EINVAL; - ret = mbochs_get_irq_info(mdev, &info); + ret = mbochs_get_irq_info(&info); if (ret) return ret; @@ -1245,7 +1245,7 @@ static long mbochs_ioctl(struct mdev_device *mdev, unsigned int cmd, if (plane.argsz < minsz) return -EINVAL; - ret = mbochs_query_gfx_plane(mdev, &plane); + ret = mbochs_query_gfx_plane(mdev_state, &plane); if (ret) return ret; @@ -1262,19 +1262,19 @@ static long mbochs_ioctl(struct mdev_device *mdev, unsigned int cmd, if (get_user(dmabuf_id, (__u32 __user *)arg)) return -EFAULT; - return mbochs_get_gfx_dmabuf(mdev, dmabuf_id); + return mbochs_get_gfx_dmabuf(mdev_state, dmabuf_id); } case VFIO_DEVICE_SET_IRQS: return -EINVAL; case VFIO_DEVICE_RESET: - return mbochs_reset(mdev); + return mbochs_reset(mdev_state); } return -ENOTTY; } -static int mbochs_open(struct mdev_device *mdev) +static int mbochs_open(struct vfio_device *vdev) { if (!try_module_get(THIS_MODULE)) return -ENODEV; @@ -1282,9 +1282,10 @@ static int mbochs_open(struct mdev_device *mdev) return 0; } -static void mbochs_close(struct mdev_device *mdev) +static void mbochs_close(struct vfio_device *vdev) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); struct mbochs_dmabuf *dmabuf, *tmp; mutex_lock(&mdev_state->ops_lock); @@ -1308,8 +1309,7 @@ static ssize_t memory_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct mdev_device *mdev = mdev_from_dev(dev); - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); + struct mdev_state *mdev_state = dev_get_drvdata(dev); return sprintf(buf, "%d MB\n", mdev_state->type->mbytes); } @@ -1400,18 +1400,30 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; +static const struct vfio_device_ops mbochs_dev_ops = { + .open = mbochs_open, + .release = mbochs_close, + .read = mbochs_read, + .write = mbochs_write, + .ioctl = mbochs_ioctl, + .mmap = mbochs_mmap, +}; + +static struct mdev_driver mbochs_driver = { + .driver = { + .name = "mbochs", + .owner = THIS_MODULE, + .mod_name = KBUILD_MODNAME, + .dev_groups = mdev_dev_groups, + }, + .probe = mbochs_probe, + .remove = mbochs_remove, +}; + static const struct mdev_parent_ops mdev_fops = { .owner = THIS_MODULE, - .mdev_attr_groups = mdev_dev_groups, + .device_driver = &mbochs_driver, .supported_type_groups = mdev_type_groups, - .create = mbochs_create, - .remove = mbochs_remove, - .open = mbochs_open, - .release = mbochs_close, - .read = mbochs_read, - .write = mbochs_write, - .ioctl = mbochs_ioctl, - .mmap = mbochs_mmap, }; static const struct file_operations vd_fops = { @@ -1436,11 +1448,15 @@ static int __init mbochs_dev_init(void) cdev_add(&mbochs_cdev, mbochs_devt, MINORMASK + 1); pr_info("%s: major %d\n", __func__, MAJOR(mbochs_devt)); + ret = mdev_register_driver(&mbochs_driver); + if (ret) + goto err_cdev; + mbochs_class = class_create(THIS_MODULE, MBOCHS_CLASS_NAME); if (IS_ERR(mbochs_class)) { pr_err("Error: failed to register mbochs_dev class\n"); ret = PTR_ERR(mbochs_class); - goto failed1; + goto err_driver; } mbochs_dev.class = mbochs_class; mbochs_dev.release = mbochs_device_release; @@ -1448,19 +1464,21 @@ static int __init mbochs_dev_init(void) ret = device_register(&mbochs_dev); if (ret) - goto failed2; + goto err_class; ret = mdev_register_device(&mbochs_dev, &mdev_fops); if (ret) - goto failed3; + goto err_device; return 0; -failed3: +err_device: device_unregister(&mbochs_dev); -failed2: +err_class: class_destroy(mbochs_class); -failed1: +err_driver: + mdev_unregister_driver(&mbochs_driver); +err_cdev: cdev_del(&mbochs_cdev); unregister_chrdev_region(mbochs_devt, MINORMASK + 1); return ret; @@ -1472,6 +1490,7 @@ static void __exit mbochs_dev_exit(void) mdev_unregister_device(&mbochs_dev); device_unregister(&mbochs_dev); + mdev_unregister_driver(&mbochs_driver); cdev_del(&mbochs_cdev); unregister_chrdev_region(mbochs_devt, MINORMASK + 1); class_destroy(mbochs_class); From patchwork Mon Apr 26 20:00:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12225017 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=-16.0 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,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 68EC7C433B4 for ; Mon, 26 Apr 2021 20:00:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F451613AA for ; Mon, 26 Apr 2021 20:00:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241842AbhDZUBZ (ORCPT ); Mon, 26 Apr 2021 16:01:25 -0400 Received: from mail-bn8nam08on2069.outbound.protection.outlook.com ([40.107.100.69]:56800 "EHLO NAM04-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S241741AbhDZUBM (ORCPT ); Mon, 26 Apr 2021 16:01:12 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aQ1fqIqVXM2fs9AWIW3qyaf078qX5LPVe7hYiJe2ZtyqpFDf4kJZhJcGlxGEfPEw8HO4BgDM3zADSTsdVEQ8aX3gayjLaPFCXkoQPHuwWDlbeTj9y68mNHsZbhE+da/LfUs/Lz5ftIl+X3+kzbm2JOX/VoxQB9OQ613nnmjgnqOwiXvlntANB9Jd4UNPvat1qqESpSHt/b6e6TNqjdpfmXJLE1Vayz7ASmK+S0AkVfu1QrHVGV6jTnNL/I9BcGsnbcDe6gVlPnF0CNPoRj0OKhZsm/L/Wble3R6NCNIdQyIZiDOvpnMjvwX48xJZwjxvES880/7MdNb6VZKHiU95gQ== 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=+blPFGMVcfu3GVQnP/CsQ3xqCUZpm3zrg0rg5IwplDs=; b=hmuzR+U7fVEEN0NbVTBLDubFkspf1kI6ADRhvk5Jfdq6fB+8+ibMIhOE+Y8NhgiInrGKIgjyA0/gYCYR/EPwNKAMHUWnW5ohlfMH0QnFRw2IXM3GqBp1E7kq3vuwGwMCFpeXKJAluh/uqJdhZoLp6nZtEDtUwYNhLnHHYkvgMiJ0wrDTvWYqbqQKoMMW6BCtVSasAKDOnaWSvolIjG6VZwe04/y4R22ygAhVJezRzGUj7GUVzNE6oKKv63FblX5/DQVQEiMZpDXmjI0gLto1HGaX+LGsF+I6YfM5TfPYxMlZ2fpmR9djWCxvNmynxVqFO+5VuIL/B3lZmcNkdokZNw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+blPFGMVcfu3GVQnP/CsQ3xqCUZpm3zrg0rg5IwplDs=; b=Bizbyv/xTpSkywdlAQXwAZ7rNunwvRWUDethR5s/ohXyltm5aEZEdYn0eSqlZnNTOz0idi6aLwdEKTqTYmy9Kcn/NYMYSv4vH/Lyi+SqGnhrytbGYYCfPXvFAKJe8af8pQycKdaEci1tRpJiZu+r5SE86sBdd2LcqB8r55I6GiemteAy0skvrhlTGVeCnS+82CyDjg+dWM6PdUofLQOj4VNok3JHO1c2S9xwiIDYU4nrdYdjN2EXUpTTl8u3lUe2kaB3cdR04uSnYfsn71DM17Xc+smgMn0xN1+6EnA1JsVJNQ2v4WnBWlBusQMhVTJazKS1oNV0+aho46GeGui/4A== Authentication-Results: de.ibm.com; dkim=none (message not signed) header.d=none;de.ibm.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3740.namprd12.prod.outlook.com (2603:10b6:5:1c3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.24; Mon, 26 Apr 2021 20:00:23 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.4065.026; Mon, 26 Apr 2021 20:00:23 +0000 From: Jason Gunthorpe To: Christian Borntraeger , Cornelia Huck , Eric Farman , Vasily Gorbik , Heiko Carstens , kvm@vger.kernel.org, linux-s390@vger.kernel.org, Peter Oberparleiter , Halil Pasic , Vineeth Vijayan Cc: "Raj, Ashok" , Dan Williams , Daniel Vetter , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 07/13] vfio/ccw: Convert to use vfio_register_group_dev() Date: Mon, 26 Apr 2021 17:00:09 -0300 Message-Id: <7-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> In-Reply-To: <0-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: MN2PR01CA0041.prod.exchangelabs.com (2603:10b6:208:23f::10) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by MN2PR01CA0041.prod.exchangelabs.com (2603:10b6:208:23f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20 via Frontend Transport; Mon, 26 Apr 2021 20:00:19 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lb7Oy-00DFZQ-0e; Mon, 26 Apr 2021 17:00:16 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 070cd515-ca8f-4636-5e57-08d908edeb32 X-MS-TrafficTypeDiagnostic: DM6PR12MB3740: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nMGqygIcZ9bXyvDZmqEIu5NOfGqnW7rwgay6TRFVfautPqWE9+50A5R+O+p+lMOGs9XjB9IYDoeIJbEkVRjWzXlnOCnDEuEeBcL5RdU10rcXZDahS5Wz6urzDZWbfEHLVxDCRqSnFFgIaf1FfrBJRgHEQct7WACseCY4wNPvNpLoY1fKNQ38uDwNmE09XJdOp4KYYmWiPSrtGx6Ff+VTtr4hUfK188nvPziArGDOvIFvxF1b6Q4mh7Fd5e5qfb3s9fpNvV7R3LPteQ9Os6x6QxLmQYgemRKCxzWXjoVLb5+9uoOu3zDnTq+eaO3RnGXxJCUMUZKdvW1T18ug0T2g0x/Gz3OZ5q+BaTgtgxfmhVDbIxbsBYeVov3BvY89WgBuL8oy+TsPeldybeVchQvIke2qNWiTnRnKQEwzjKLjb9UixkdxBInfAx7NFI9OJoF8pK+rHAWnnVfCA8WvTJSJ+gPRBXX3kIEtAX8W9tNdTcUbTPnzBmCDTR233gAFa9jXQ37lYVfwOairYSbB1ExxkEQJJoqumdJFxlilrRwdtYphRRIp4uXocK7XoJVBSt7hbHJpX5ijTq/gPfiTOee9Ks2kxVjvupyVoaZaajmZVUJvaF/7IAWnDQmD70TG4DXDNBUwtp+evQk3rVqbOcyHTE6vwruoe3xNYPOo3QHNtj4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(39860400002)(346002)(136003)(396003)(376002)(66476007)(66556008)(9746002)(54906003)(426003)(110136005)(107886003)(186003)(26005)(921005)(6666004)(36756003)(316002)(2906002)(30864003)(2616005)(478600001)(9786002)(8936002)(83380400001)(38100700002)(86362001)(8676002)(5660300002)(7416002)(4326008)(66946007)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: +JxuKjXHny5YC5O2z7gv7e+/mo/Lo0SxJK8TloeRU2+xGzd19gEunon3F0wXEzTSbTCUs9qCkAO19uYvocJoqwbiyPv6a1yvAVn2iBAcHBDuTJ3r10lxa3mybtw/ru+WwDQLbTgnhg3V1OCglIPM57EWMCKHr6i0ySvusBotf9YdaR5hwo2q5F1N9ecNQOPhDMKz9OOkH3spmI2tjH53IGnrdE+lmudJPbe/Be15sA+wbFeVW1+YqY7U4Pga18T/ExtQAUmyMNuiDL+jh+444TB+KWM7w7SrWfqn4guGB51FNm160p+6z3zrHIffYeFJuTMS5hg69meD+zum0+kR6dM2YR6u1gr87ARAOo834BeaaSCTJOw1Y0izJGvnHqKwu/yFCziqrCQAb4mQ6n94YpsukO3AXMq1/mMw/J4au3n3+1/VzSiI2ljVp/bxuDo9sfxWqs9mv7s475jHW8Zjvc/RyH6/Nw0iZHkeWD3p0LzTGB/lIgF896fjf37YNyBL870/rj7mrFzLwdYKwhdBNxib0eLfqLIXxJqrC4+V02zwi/OaIwjMc9LsoMVkharR5WUQmnRxEfn/yGADbHWTea2hgcfQDIj22LkE0m3jl/Sx6ykQ6+zNI+Gf5hz9iohR2VFSDgz3HRLDQPu6b1KfaKO9eKd8MofYexugiQ7kjYnGfiLYQdvaw6kc+/1Dg4IpGOWGKDQ12NCSvT4l6OrBxmDWu5K63vVjQkiH/aaTahQCJ8ntWPK1Bo1Lr7/KtuEqC4owTYks0GVmwhx6CW4FROZTTdGWryNa3p5csYGnsUpFnxCInPk9cmgwRWG7zKGi4NBUi9B2Uykz2Sw1e3RSR/yHtERiqxXcp9ZprbkZWBfSyQ53/EhaKz1s9WLv2mILWBLZy83MKSmoR9145xe23V3AXWl94cVVknh6pINC4MuNPdxYRkYFGk7s86cMciE5tPHWdyNIoDC+vUQU+irwXAq56cHzyWhKqIRcf4w/ksxCihuesICSg6GkkaG+LuMZSmzSi7FYlPcuNvkGLFjQdV/UJtMMe0g9I/HAQzlWFc0z+S/issgmsfw1eyBDG8LWCob84KiQ0jc7joAAl+yaF29KKzn8lReHBKjZ2lXht+7/I1XMKBBOsVqy1m71WY6p7lDlOIyY7W0NxXRt32Bae9d+jmfzFQOiGAKQql4E3Z2HWAJ7NyZcirvccX2RogbjB/sYAUBamR57p+b8vUAbINI60MTdALO6EMlqUQeUVaefzpt7FX9BNq65fNBPJ+Q1APR6xxwzHm5shwR/6H0+px56upi/h1qJ0/f3FwE9sLmkP7mS8TdnDSjDyBdrb88W X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 070cd515-ca8f-4636-5e57-08d908edeb32 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2021 20:00:19.8032 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /zQRtW98vuIhuIlrjLCGMcmhAKkBnlfFb/v6SsSsVx7+6VVL6tQBBL7Z6NoGmQpq X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3740 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is more complicated because vfio_ccw is sharing the vfio_device between both the mdev_device and its vfio_device and the css_driver. The mdev is a singleton, and the reason for this sharing appears to be to allow the extra css_driver function callbacks to be delivered to the vfio_device. This keeps things as they were, with the css_driver allocating the singleton, not the mdev_driver, this is pretty confusing. I'm also uncertain how the lifetime model for the mdev works in the css_driver callbacks. At this point embed the vfio_device in the vfio_ccw_private and instantiate it as a vfio_device when the mdev probes. The drvdata of both the css_device and the mdev_device point at the private, and container_of is used to get it back from the vfio_device. Signed-off-by: Jason Gunthorpe --- drivers/s390/cio/vfio_ccw_drv.c | 21 +++-- drivers/s390/cio/vfio_ccw_ops.c | 135 +++++++++++++++------------- drivers/s390/cio/vfio_ccw_private.h | 5 ++ 3 files changed, 94 insertions(+), 67 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index 8c625b530035f5..55c4876dfd139d 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -442,7 +442,7 @@ static int __init vfio_ccw_sch_init(void) vfio_ccw_work_q = create_singlethread_workqueue("vfio-ccw"); if (!vfio_ccw_work_q) { ret = -ENOMEM; - goto out_err; + goto out_regions; } vfio_ccw_io_region = kmem_cache_create_usercopy("vfio_ccw_io_region", @@ -451,7 +451,7 @@ static int __init vfio_ccw_sch_init(void) sizeof(struct ccw_io_region), NULL); if (!vfio_ccw_io_region) { ret = -ENOMEM; - goto out_err; + goto out_regions; } vfio_ccw_cmd_region = kmem_cache_create_usercopy("vfio_ccw_cmd_region", @@ -460,7 +460,7 @@ static int __init vfio_ccw_sch_init(void) sizeof(struct ccw_cmd_region), NULL); if (!vfio_ccw_cmd_region) { ret = -ENOMEM; - goto out_err; + goto out_regions; } vfio_ccw_schib_region = kmem_cache_create_usercopy("vfio_ccw_schib_region", @@ -470,7 +470,7 @@ static int __init vfio_ccw_sch_init(void) if (!vfio_ccw_schib_region) { ret = -ENOMEM; - goto out_err; + goto out_regions; } vfio_ccw_crw_region = kmem_cache_create_usercopy("vfio_ccw_crw_region", @@ -480,19 +480,25 @@ static int __init vfio_ccw_sch_init(void) if (!vfio_ccw_crw_region) { ret = -ENOMEM; - goto out_err; + goto out_regions; } + ret = mdev_register_driver(&vfio_ccw_mdev_driver); + if (ret) + goto out_regions; + isc_register(VFIO_CCW_ISC); ret = css_driver_register(&vfio_ccw_sch_driver); if (ret) { isc_unregister(VFIO_CCW_ISC); - goto out_err; + goto out_driver; } return ret; -out_err: +out_driver: + mdev_unregister_driver(&vfio_ccw_mdev_driver); +out_regions: vfio_ccw_destroy_regions(); destroy_workqueue(vfio_ccw_work_q); vfio_ccw_debug_exit(); @@ -501,6 +507,7 @@ static int __init vfio_ccw_sch_init(void) static void __exit vfio_ccw_sch_exit(void) { + mdev_unregister_driver(&vfio_ccw_mdev_driver); css_driver_unregister(&vfio_ccw_sch_driver); isc_unregister(VFIO_CCW_ISC); vfio_ccw_destroy_regions(); diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index 491a64c61fff1a..0fcf46031d3821 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -17,13 +17,13 @@ #include "vfio_ccw_private.h" -static int vfio_ccw_mdev_reset(struct mdev_device *mdev) +static const struct vfio_device_ops vfio_ccw_dev_ops; + +static int vfio_ccw_mdev_reset(struct vfio_ccw_private *private) { - struct vfio_ccw_private *private; struct subchannel *sch; int ret; - private = dev_get_drvdata(mdev_parent_dev(mdev)); sch = private->sch; /* * TODO: @@ -61,7 +61,7 @@ static int vfio_ccw_mdev_notifier(struct notifier_block *nb, if (!cp_iova_pinned(&private->cp, unmap->iova)) return NOTIFY_OK; - if (vfio_ccw_mdev_reset(private->mdev)) + if (vfio_ccw_mdev_reset(private)) return NOTIFY_BAD; cp_free(&private->cp); @@ -113,10 +113,11 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; -static int vfio_ccw_mdev_create(struct mdev_device *mdev) +static int vfio_ccw_mdev_probe(struct mdev_device *mdev) { struct vfio_ccw_private *private = dev_get_drvdata(mdev_parent_dev(mdev)); + int ret; if (private->state == VFIO_CCW_STATE_NOT_OPER) return -ENODEV; @@ -124,6 +125,10 @@ static int vfio_ccw_mdev_create(struct mdev_device *mdev) if (atomic_dec_if_positive(&private->avail) < 0) return -EPERM; + memset(&private->vdev, 0, sizeof(private->vdev)); + vfio_init_group_dev(&private->vdev, &mdev->dev, + &vfio_ccw_dev_ops); + private->mdev = mdev; private->state = VFIO_CCW_STATE_IDLE; @@ -132,19 +137,28 @@ static int vfio_ccw_mdev_create(struct mdev_device *mdev) private->sch->schid.ssid, private->sch->schid.sch_no); + ret = vfio_register_group_dev(&private->vdev); + if (ret) + goto err_atomic; + dev_set_drvdata(&mdev->dev, private); return 0; + +err_atomic: + atomic_inc(&private->avail); + return ret; } -static int vfio_ccw_mdev_remove(struct mdev_device *mdev) +static void vfio_ccw_mdev_remove(struct mdev_device *mdev) { - struct vfio_ccw_private *private = - dev_get_drvdata(mdev_parent_dev(mdev)); + struct vfio_ccw_private *private = dev_get_drvdata(&mdev->dev); VFIO_CCW_MSG_EVENT(2, "mdev %pUl, sch %x.%x.%04x: remove\n", mdev_uuid(mdev), private->sch->schid.cssid, private->sch->schid.ssid, private->sch->schid.sch_no); + vfio_unregister_group_dev(&private->vdev); + if ((private->state != VFIO_CCW_STATE_NOT_OPER) && (private->state != VFIO_CCW_STATE_STANDBY)) { if (!vfio_ccw_sch_quiesce(private->sch)) @@ -155,20 +169,18 @@ static int vfio_ccw_mdev_remove(struct mdev_device *mdev) cp_free(&private->cp); private->mdev = NULL; atomic_inc(&private->avail); - - return 0; } -static int vfio_ccw_mdev_open(struct mdev_device *mdev) +static int vfio_ccw_mdev_open(struct vfio_device *vdev) { struct vfio_ccw_private *private = - dev_get_drvdata(mdev_parent_dev(mdev)); + container_of(vdev, struct vfio_ccw_private, vdev); unsigned long events = VFIO_IOMMU_NOTIFY_DMA_UNMAP; int ret; private->nb.notifier_call = vfio_ccw_mdev_notifier; - ret = vfio_register_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY, + ret = vfio_register_notifier(vdev->dev, VFIO_IOMMU_NOTIFY, &events, &private->nb); if (ret) return ret; @@ -189,27 +201,26 @@ static int vfio_ccw_mdev_open(struct mdev_device *mdev) out_unregister: vfio_ccw_unregister_dev_regions(private); - vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY, + vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY, &private->nb); return ret; } -static void vfio_ccw_mdev_release(struct mdev_device *mdev) +static void vfio_ccw_mdev_release(struct vfio_device *vdev) { struct vfio_ccw_private *private = - dev_get_drvdata(mdev_parent_dev(mdev)); + container_of(vdev, struct vfio_ccw_private, vdev); if ((private->state != VFIO_CCW_STATE_NOT_OPER) && (private->state != VFIO_CCW_STATE_STANDBY)) { - if (!vfio_ccw_mdev_reset(mdev)) + if (!vfio_ccw_mdev_reset(private)) private->state = VFIO_CCW_STATE_STANDBY; /* The state will be NOT_OPER on error. */ } cp_free(&private->cp); vfio_ccw_unregister_dev_regions(private); - vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY, - &private->nb); + vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY, &private->nb); } static ssize_t vfio_ccw_mdev_read_io_region(struct vfio_ccw_private *private, @@ -233,15 +244,14 @@ static ssize_t vfio_ccw_mdev_read_io_region(struct vfio_ccw_private *private, return ret; } -static ssize_t vfio_ccw_mdev_read(struct mdev_device *mdev, +static ssize_t vfio_ccw_mdev_read(struct vfio_device *vdev, char __user *buf, size_t count, loff_t *ppos) { + struct vfio_ccw_private *private = + container_of(vdev, struct vfio_ccw_private, vdev); unsigned int index = VFIO_CCW_OFFSET_TO_INDEX(*ppos); - struct vfio_ccw_private *private; - - private = dev_get_drvdata(mdev_parent_dev(mdev)); if (index >= VFIO_CCW_NUM_REGIONS + private->num_regions) return -EINVAL; @@ -288,15 +298,14 @@ static ssize_t vfio_ccw_mdev_write_io_region(struct vfio_ccw_private *private, return ret; } -static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev, +static ssize_t vfio_ccw_mdev_write(struct vfio_device *vdev, const char __user *buf, size_t count, loff_t *ppos) { + struct vfio_ccw_private *private = + container_of(vdev, struct vfio_ccw_private, vdev); unsigned int index = VFIO_CCW_OFFSET_TO_INDEX(*ppos); - struct vfio_ccw_private *private; - - private = dev_get_drvdata(mdev_parent_dev(mdev)); if (index >= VFIO_CCW_NUM_REGIONS + private->num_regions) return -EINVAL; @@ -313,12 +322,9 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev, return -EINVAL; } -static int vfio_ccw_mdev_get_device_info(struct vfio_device_info *info, - struct mdev_device *mdev) +static int vfio_ccw_mdev_get_device_info(struct vfio_ccw_private *private, + struct vfio_device_info *info) { - struct vfio_ccw_private *private; - - private = dev_get_drvdata(mdev_parent_dev(mdev)); info->flags = VFIO_DEVICE_FLAGS_CCW | VFIO_DEVICE_FLAGS_RESET; info->num_regions = VFIO_CCW_NUM_REGIONS + private->num_regions; info->num_irqs = VFIO_CCW_NUM_IRQS; @@ -326,14 +332,12 @@ static int vfio_ccw_mdev_get_device_info(struct vfio_device_info *info, return 0; } -static int vfio_ccw_mdev_get_region_info(struct vfio_region_info *info, - struct mdev_device *mdev, +static int vfio_ccw_mdev_get_region_info(struct vfio_ccw_private *private, + struct vfio_region_info *info, unsigned long arg) { - struct vfio_ccw_private *private; int i; - private = dev_get_drvdata(mdev_parent_dev(mdev)); switch (info->index) { case VFIO_CCW_CONFIG_REGION_INDEX: info->offset = 0; @@ -408,19 +412,16 @@ static int vfio_ccw_mdev_get_irq_info(struct vfio_irq_info *info) return 0; } -static int vfio_ccw_mdev_set_irqs(struct mdev_device *mdev, +static int vfio_ccw_mdev_set_irqs(struct vfio_ccw_private *private, uint32_t flags, uint32_t index, void __user *data) { - struct vfio_ccw_private *private; struct eventfd_ctx **ctx; if (!(flags & VFIO_IRQ_SET_ACTION_TRIGGER)) return -EINVAL; - private = dev_get_drvdata(mdev_parent_dev(mdev)); - switch (index) { case VFIO_CCW_IO_IRQ_INDEX: ctx = &private->io_trigger; @@ -522,10 +523,12 @@ void vfio_ccw_unregister_dev_regions(struct vfio_ccw_private *private) private->region = NULL; } -static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, +static ssize_t vfio_ccw_mdev_ioctl(struct vfio_device *vdev, unsigned int cmd, unsigned long arg) { + struct vfio_ccw_private *private = + container_of(vdev, struct vfio_ccw_private, vdev); int ret = 0; unsigned long minsz; @@ -542,7 +545,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, if (info.argsz < minsz) return -EINVAL; - ret = vfio_ccw_mdev_get_device_info(&info, mdev); + ret = vfio_ccw_mdev_get_device_info(private, &info); if (ret) return ret; @@ -560,7 +563,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, if (info.argsz < minsz) return -EINVAL; - ret = vfio_ccw_mdev_get_region_info(&info, mdev, arg); + ret = vfio_ccw_mdev_get_region_info(private, &info, arg); if (ret) return ret; @@ -605,47 +608,59 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, return ret; data = (void __user *)(arg + minsz); - return vfio_ccw_mdev_set_irqs(mdev, hdr.flags, hdr.index, data); + return vfio_ccw_mdev_set_irqs(private, hdr.flags, hdr.index, + data); } case VFIO_DEVICE_RESET: - return vfio_ccw_mdev_reset(mdev); + return vfio_ccw_mdev_reset(private); default: return -ENOTTY; } } /* Request removal of the device*/ -static void vfio_ccw_mdev_request(struct mdev_device *mdev, unsigned int count) +static void vfio_ccw_mdev_request(struct vfio_device *vdev, unsigned int count) { - struct vfio_ccw_private *private = dev_get_drvdata(mdev_parent_dev(mdev)); - - if (!private) - return; + struct vfio_ccw_private *private = + container_of(vdev, struct vfio_ccw_private, vdev); + struct device *dev = private->vdev.dev; if (private->req_trigger) { if (!(count % 10)) - dev_notice_ratelimited(mdev_dev(private->mdev), + dev_notice_ratelimited(dev, "Relaying device request to user (#%u)\n", count); eventfd_signal(private->req_trigger, 1); } else if (count == 0) { - dev_notice(mdev_dev(private->mdev), + dev_notice(dev, "No device request channel registered, blocked until released by user\n"); } } +static const struct vfio_device_ops vfio_ccw_dev_ops = { + .open = vfio_ccw_mdev_open, + .release = vfio_ccw_mdev_release, + .read = vfio_ccw_mdev_read, + .write = vfio_ccw_mdev_write, + .ioctl = vfio_ccw_mdev_ioctl, + .request = vfio_ccw_mdev_request, +}; + +struct mdev_driver vfio_ccw_mdev_driver = { + .driver = { + .name = "vfio_ccw_mdev", + .owner = THIS_MODULE, + .mod_name = KBUILD_MODNAME, + }, + .probe = vfio_ccw_mdev_probe, + .remove = vfio_ccw_mdev_remove, +}; + static const struct mdev_parent_ops vfio_ccw_mdev_ops = { .owner = THIS_MODULE, + .device_driver = &vfio_ccw_mdev_driver, .supported_type_groups = mdev_type_groups, - .create = vfio_ccw_mdev_create, - .remove = vfio_ccw_mdev_remove, - .open = vfio_ccw_mdev_open, - .release = vfio_ccw_mdev_release, - .read = vfio_ccw_mdev_read, - .write = vfio_ccw_mdev_write, - .ioctl = vfio_ccw_mdev_ioctl, - .request = vfio_ccw_mdev_request, }; int vfio_ccw_mdev_reg(struct subchannel *sch) diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h index b2c762eb42b9bb..7272eb78861244 100644 --- a/drivers/s390/cio/vfio_ccw_private.h +++ b/drivers/s390/cio/vfio_ccw_private.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -67,6 +68,7 @@ struct vfio_ccw_crw { /** * struct vfio_ccw_private + * @vdev: Embedded VFIO device * @sch: pointer to the subchannel * @state: internal state of the device * @completion: synchronization helper of the I/O completion @@ -90,6 +92,7 @@ struct vfio_ccw_crw { * @crw_work: work for deferral process of CRW handling */ struct vfio_ccw_private { + struct vfio_device vdev; struct subchannel *sch; int state; struct completion *completion; @@ -121,6 +124,8 @@ extern void vfio_ccw_mdev_unreg(struct subchannel *sch); extern int vfio_ccw_sch_quiesce(struct subchannel *sch); +extern struct mdev_driver vfio_ccw_mdev_driver; + /* * States of the device statemachine. */ From patchwork Mon Apr 26 20:00:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12225011 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=-16.0 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,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 C0DDFC43460 for ; Mon, 26 Apr 2021 20:00:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9771A6135D for ; Mon, 26 Apr 2021 20:00:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241835AbhDZUBT (ORCPT ); Mon, 26 Apr 2021 16:01:19 -0400 Received: from mail-bn8nam08on2048.outbound.protection.outlook.com ([40.107.100.48]:25530 "EHLO NAM04-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S241780AbhDZUBI (ORCPT ); Mon, 26 Apr 2021 16:01:08 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ldEwvOMohGp/7CBe/j3q4ytsByvWfm//0v4deytxdUm6cS1E6F9OMJecynt+O8pZPWZpeYuaQPbQT0PrPiHchDTY2R45LvkCFpaykH5INWpB5T7RjSD1k9vs5kHKPiHSL9Dw8z9oOjIqltxSJpvD8qaYxo1u3ezVxwpdWcjKdsv5nzP1R8pJDExqyMoM3wu5fA4ZC+4aqnT5tPV740DP5gB1BP8iQpLoc2SZ/OxgWgHhkyrzSmqBxYTKeB6VZZaaUUkRMB114eAdxSkS8UVUGUP6BW9XqQXOro0/Clo/fNMJzeaHVUhoFHtUNkfImX6Bf9wiahjRG90uhw4EGySXSA== 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=xJ2UbYUG6kpAcHGol5HZRiz/M3q/Jljm82+hlGYKWUM=; b=nFqNs1n0ccNZvqlelll034XAikUOdjEcD6FW50mXnz2avegjDCJruhPWP4qwguCV1+tK8Sr5ErGEEbDfy+/pltDPxBIW+TdM1wIrN49/BfHfsSv/k7Ve1/CBHNt1oobp0/RkcE5AlB0x0IUpxtEoDTHTTBwIl1M7MyisoDe2w1DfPiSxvmxh3tmUkMjni0Bs7XCQfktB3bJAZpIRs1HH4WTJoXM4XNapLnWOWiY1yQeFIM1nnDFiHmJniksj0jk1sQKmt2UJEhUOWLZDNdkamslLzGdluO0jifIDlnrFAkzyP7zz4XQQ56YVQRLE5+F7FvMFPFmD4TpS26Rqapm8bQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xJ2UbYUG6kpAcHGol5HZRiz/M3q/Jljm82+hlGYKWUM=; b=BIVdTBNtQ/FtY9qdDEGHZJwNyWZu/j+hemxfV1Rbg5ccdTXkurjOlVwtQ2ngf1ItiT9cCow/6GVd5Z4wQVoDD9KIvxxahKd1cPXHSnB0FAiGJNeEXswVVo3VwLArYL2+5nLvcykfAkF23vjnlCOIjwyEGdu0OnAwZTPLNw1BC7FtuaTiJgnS1KsBnYIK4sq8btxR4vxbhfgqHu6fXMZMdrrUIxajezsIKOfU+hyhzMgOflpYe2iE4+94cpAAF172EUpTvYMtgTu/8W6dOeE1dejHMkyoi8ysbEVryB4WolU/GNJSK5v/kYfMOSCCJ6LYYsG2/wxvXr8lHJcIWMV77A== Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3740.namprd12.prod.outlook.com (2603:10b6:5:1c3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.24; Mon, 26 Apr 2021 20:00:19 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.4065.026; Mon, 26 Apr 2021 20:00:19 +0000 From: Jason Gunthorpe To: Alex Williamson , Cornelia Huck , Jonathan Corbet , kvm@vger.kernel.org, Kirti Wankhede , linux-doc@vger.kernel.org Cc: "Raj, Ashok" , Dan Williams , Daniel Vetter , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 09/13] vfio/mdev: Remove vfio_mdev.c Date: Mon, 26 Apr 2021 17:00:11 -0300 Message-Id: <9-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> In-Reply-To: <0-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: BLAPR03CA0024.namprd03.prod.outlook.com (2603:10b6:208:32b::29) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by BLAPR03CA0024.namprd03.prod.outlook.com (2603:10b6:208:32b::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.22 via Frontend Transport; Mon, 26 Apr 2021 20:00:17 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lb7Oy-00DFZX-2w; Mon, 26 Apr 2021 17:00:16 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fb9fc3fe-2c9a-47bf-7e0d-08d908ede9e1 X-MS-TrafficTypeDiagnostic: DM6PR12MB3740: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bh9M9hCmC8VgW2MlqS/xaQP22/nYRubBciEzwunzEJAySttc1dZ6HRQ4Qbyc/i1f+vy1PIDkSOrJqV2y1CL2gz3LAw+ySpkwR4KxJQn4ZMCxoIwzYAxuD0wPLmGDtHFCI1/75AW7f9V9BZfExVxeB/kDM0euNg2kL1aY+m74XOdEi50n+tqjldIRH46BTQ4YKZ3Yyk1UfSYtr7bhghblDfCEEt4xUt7TGx2eFeBSq8EgqecHMvYUhclo4wR3i3AUwJL7PZHDNZjjorjUdg1R1Z6vijfsNVsnnancVWpZHn/xYxhU2CAnCxUhh3YB9hV5++OwcB3IQJtZUrMdLRmEVwDH51+ejzp8/vDpVWyFYcYmn5PtEekFToZOhWHwT1AwKnOhFVAx8YssLGRsV4D5gzB564KptM2GoCK7dEQCTPi+pGlRHxHoxUun5SB/ynsH1/9VW+Dd0CXvVfxNruuzBDytWp8VbPQeg5V+8yq3d76QzUxQmHWPH4Syo0oJaiE6njSDEA6hF50l7f0Z0ljvCGDC5WZEZ13XKxD+Sfp1o7eGwBCyHHXaW5WIxPd933iSirfdXB5b4FGIqS8QgsGyuRqMktvIS+Fyy/MAdlGNdFGXN/Oy+BUE8fr9B8zO2orSQ8KtGoF8vkBAIoSjXNpyzw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(39860400002)(346002)(136003)(396003)(376002)(66476007)(66556008)(9746002)(54906003)(426003)(110136005)(107886003)(186003)(26005)(6666004)(36756003)(316002)(2906002)(30864003)(2616005)(478600001)(9786002)(8936002)(83380400001)(38100700002)(86362001)(8676002)(5660300002)(4326008)(66946007)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 2JtzrnWGC88gs6NSf8Jp02/o0NXBVyc3qnlnp8v4a0cw1cwoDZ0ZRe8y0Dj95DACGwPlmRIQzHRHnQpgRTJNpyHJWRoc9DkyhvKvjQ1kZTsIZMkEQYnvfdAtM8t9TTRVHrSYMns5pN2MS48Ca6ZFeD4CdoM5/K9ey3k9ldEvY9N3wXF3ExVExeiGgUGaosrWyVOi/R3eZhF+Sq3qee9YkzSJ++wC4EMKhxl7Gg8Hl3MRaNOkg6TzOViBt1oMHdfWJYK7pCTsawOj9ItC9ctl9U0pju1I3+uSdyPzQSva6chDToPhMyWlaXhtBGRzWkydfR7+IP6l6ejC3KybfhZAlE3MQGOGFUJ/Y70RWrFaaLNmdGI+vUR00SSJJ0IaD0MWqdmMe37OjvBwE8ajKFV4abayzzq1xdrMi7dAS1W4U9u7bmjirQgSIWSdrnz+B21OHz5F+CJdLmA5Kdq9ys3ZtuWNayxceWJJgMg+YeUZmKomE7Rz4nHMhg2PX9tUOSjz9GXsQUedp57Nec4AGsWKYuHIqdhxkHk8ozihblVefn7bSV56f0pCjVmuJ5nXthEyzMZYEQ9/VFLivaxKY6MxsaK0bQPzKWnBQ6AdBiXOoZcjtVnzwqcmUXEyJrj/MRnnKDRQMkh3WQ2WUxAYfgXl2+S/e0Ys7pUbIp41t2+ZN2shYak4B1qwfVGF5KcupwqUNalz4p4e+cJeLWtY4NelFhQwAPAFqfVHxtE0p7EX5McQjQnE3on+JhRCazXWnLtOoxkpY7NUUDVZ+QufEpTohV0Q/YsUPsLLL1tkpQflqfmzalkZHUYKE29IztLK83IjoGKSLhTSFgP6Mlp0WRwNbRKhE0uWjCsVs6yIWgjdhZpWLnBsEExFvOZ5mqp9ivw0Nvd+z+it14h1z7XTmB+BUG6TeQwpWdNi6y/DL62C+oY0TV/0pmAL4CiXzXP0ZOgx2UJquFWKrncpcl+6mRuZxJNfOP/5ELscDOX1EWsjAQ0tNz1T4ercdEL0sqVbyD7rrg2rv4aww/VJdW/WiIvgXC1Rf9OTrElPqnp0SaoCkkjPQ/QdNPRYG66HyfD9d6jmEhuqlPTP8whj/rQ7iJ3hbI5Qevm6Q1jFPmwuAWIeE6pqqPv0MzXcuQU5v0AjknT7vT/I969y8OUljAojcSPSBPaFNcWUSYcrKMq5e7M92OcNroA6OFJTN8OaOUGcQ4kTnCQl9odVNgnygrv21Zczqp4PedXrecik3/4iH8/04kHKmyS2yzGvHjGiMpJEf2yKsFxlucE0ZCXez/yX0ZhtvUCIQQS39/e/BRfBxrI2APEiEp2DRn9e5+Ml+Cn6+CaX X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: fb9fc3fe-2c9a-47bf-7e0d-08d908ede9e1 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2021 20:00:17.7404 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: W2DKpSexCIg3fr1BOWLf4ei6gOuRUtZOmS951vvoFjM8CFQcJ7+8qTB9vs8jdwcs X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3740 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Now that all mdev drivers directly create their own mdev_device driver and directly register with the vfio core's vfio_device_ops this is all dead code. Delete vfio_mdev.c and the mdev_parent_ops members that are connected to it. Preserve VFIO's design of allowing mdev drivers to be !GPL by allowing the three functions that replace this module for !GPL usage. This goes along with the other 19 symbols that are already marked !GPL in VFIO. Signed-off-by: Jason Gunthorpe --- .../driver-api/vfio-mediated-device.rst | 19 --- drivers/vfio/mdev/Makefile | 2 +- drivers/vfio/mdev/mdev_core.c | 49 +----- drivers/vfio/mdev/mdev_driver.c | 21 +-- drivers/vfio/mdev/mdev_private.h | 2 - drivers/vfio/mdev/vfio_mdev.c | 158 ------------------ drivers/vfio/vfio.c | 6 +- include/linux/mdev.h | 52 ------ include/linux/vfio.h | 4 + 9 files changed, 16 insertions(+), 297 deletions(-) delete mode 100644 drivers/vfio/mdev/vfio_mdev.c diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentation/driver-api/vfio-mediated-device.rst index 1779b85f014e2f..5f866b17c93e69 100644 --- a/Documentation/driver-api/vfio-mediated-device.rst +++ b/Documentation/driver-api/vfio-mediated-device.rst @@ -137,25 +137,6 @@ The structures in the mdev_parent_ops structure are as follows: * mdev_attr_groups: attributes of the mediated device * supported_config: attributes to define supported configurations -The functions in the mdev_parent_ops structure are as follows: - -* create: allocate basic resources in a driver for a mediated device -* remove: free resources in a driver when a mediated device is destroyed - -(Note that mdev-core provides no implicit serialization of create/remove -callbacks per mdev parent device, per mdev type, or any other categorization. -Vendor drivers are expected to be fully asynchronous in this respect or -provide their own internal resource protection.) - -The callbacks in the mdev_parent_ops structure are as follows: - -* open: open callback of mediated device -* close: close callback of mediated device -* ioctl: ioctl callback of mediated device -* read : read emulation callback -* write: write emulation callback -* mmap: mmap emulation callback - A driver should use the mdev_parent_ops structure in the function call to register itself with the mdev core driver:: diff --git a/drivers/vfio/mdev/Makefile b/drivers/vfio/mdev/Makefile index ff9ecd80212503..7c236ba1b90eb1 100644 --- a/drivers/vfio/mdev/Makefile +++ b/drivers/vfio/mdev/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o vfio_mdev.o +mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o obj-$(CONFIG_VFIO_MDEV) += mdev.o diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 51b8a9fcf866ad..d507047e6ecf4a 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -89,17 +89,10 @@ void mdev_release_parent(struct kref *kref) static void mdev_device_remove_common(struct mdev_device *mdev) { struct mdev_parent *parent = mdev->type->parent; - int ret; mdev_remove_sysfs_files(mdev); device_del(&mdev->dev); lockdep_assert_held(&parent->unreg_sem); - if (parent->ops->remove) { - ret = parent->ops->remove(mdev); - if (ret) - dev_err(&mdev->dev, "Remove failed: err=%d\n", ret); - } - /* Balances with device_initialize() */ put_device(&mdev->dev); } @@ -131,17 +124,13 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops) /* check for mandatory ops */ if (!ops || !ops->supported_type_groups) return -EINVAL; - if (!ops->device_driver && (!ops->create || !ops->remove)) + if (!ops->device_driver) return -EINVAL; dev = get_device(dev); if (!dev) return -EINVAL; - /* Not mandatory, but its absence could be a problem */ - if (!ops->request) - dev_info(dev, "Driver cannot be asked to release device\n"); - mutex_lock(&parent_list_lock); /* Check for duplicate */ @@ -263,15 +252,12 @@ static void mdev_device_release(struct device *dev) */ static int mdev_bind_driver(struct mdev_device *mdev) { - struct mdev_driver *drv = mdev->type->parent->ops->device_driver; int ret; - if (!drv) - drv = &vfio_mdev_driver; - while (1) { device_lock(&mdev->dev); - if (mdev->dev.driver == &drv->driver) { + if (mdev->dev.driver == + &mdev->type->parent->ops->device_driver->driver) { ret = 0; goto out_unlock; } @@ -337,15 +323,9 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) goto out_put_device; } - if (parent->ops->create) { - ret = parent->ops->create(mdev); - if (ret) - goto out_unlock; - } - ret = device_add(&mdev->dev); if (ret) - goto out_remove; + goto out_unlock; ret = mdev_bind_driver(mdev); if (ret) @@ -363,9 +343,6 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) out_del: device_del(&mdev->dev); -out_remove: - if (parent->ops->remove) - parent->ops->remove(mdev); out_unlock: up_read(&parent->unreg_sem); out_put_device: @@ -408,28 +385,14 @@ int mdev_device_remove(struct mdev_device *mdev) static int __init mdev_init(void) { - int rc; - - rc = mdev_bus_register(); - if (rc) - return rc; - rc = mdev_register_driver(&vfio_mdev_driver); - if (rc) - goto err_bus; - return 0; -err_bus: - mdev_bus_unregister(); - return rc; + return bus_register(&mdev_bus_type); } static void __exit mdev_exit(void) { - mdev_unregister_driver(&vfio_mdev_driver); - if (mdev_bus_compat_class) class_compat_unregister(mdev_bus_compat_class); - - mdev_bus_unregister(); + bus_unregister(&mdev_bus_type); } module_init(mdev_init) diff --git a/drivers/vfio/mdev/mdev_driver.c b/drivers/vfio/mdev/mdev_driver.c index 6e96c023d7823d..07ada55efd6228 100644 --- a/drivers/vfio/mdev/mdev_driver.c +++ b/drivers/vfio/mdev/mdev_driver.c @@ -74,15 +74,8 @@ static int mdev_remove(struct device *dev) static int mdev_match(struct device *dev, struct device_driver *drv) { struct mdev_device *mdev = to_mdev_device(dev); - struct mdev_driver *target = mdev->type->parent->ops->device_driver; - - /* - * The ops specify the device driver to connect, fall back to the old - * shim driver if the driver hasn't been converted. - */ - if (!target) - target = &vfio_mdev_driver; - return drv == &target->driver; + + return drv == &mdev->type->parent->ops->device_driver->driver; } struct bus_type mdev_bus_type = { @@ -118,13 +111,3 @@ void mdev_unregister_driver(struct mdev_driver *drv) driver_unregister(&drv->driver); } EXPORT_SYMBOL(mdev_unregister_driver); - -int mdev_bus_register(void) -{ - return bus_register(&mdev_bus_type); -} - -void mdev_bus_unregister(void) -{ - bus_unregister(&mdev_bus_type); -} diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h index 5461b67582289f..a656cfe0346c33 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -37,8 +37,6 @@ struct mdev_type { #define to_mdev_type(_kobj) \ container_of(_kobj, struct mdev_type, kobj) -extern struct mdev_driver vfio_mdev_driver; - int parent_create_sysfs_files(struct mdev_parent *parent); void parent_remove_sysfs_files(struct mdev_parent *parent); diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c deleted file mode 100644 index d5b4eede47c1a5..00000000000000 --- a/drivers/vfio/mdev/vfio_mdev.c +++ /dev/null @@ -1,158 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * VFIO based driver for Mediated device - * - * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. - * Author: Neo Jia - * Kirti Wankhede - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "mdev_private.h" - -static int vfio_mdev_open(struct vfio_device *core_vdev) -{ - struct mdev_device *mdev = to_mdev_device(core_vdev->dev); - struct mdev_parent *parent = mdev->type->parent; - - int ret; - - if (unlikely(!parent->ops->open)) - return -EINVAL; - - if (!try_module_get(THIS_MODULE)) - return -ENODEV; - - ret = parent->ops->open(mdev); - if (ret) - module_put(THIS_MODULE); - - return ret; -} - -static void vfio_mdev_release(struct vfio_device *core_vdev) -{ - struct mdev_device *mdev = to_mdev_device(core_vdev->dev); - struct mdev_parent *parent = mdev->type->parent; - - if (likely(parent->ops->release)) - parent->ops->release(mdev); - - module_put(THIS_MODULE); -} - -static long vfio_mdev_unlocked_ioctl(struct vfio_device *core_vdev, - unsigned int cmd, unsigned long arg) -{ - struct mdev_device *mdev = to_mdev_device(core_vdev->dev); - struct mdev_parent *parent = mdev->type->parent; - - if (unlikely(!parent->ops->ioctl)) - return -EINVAL; - - return parent->ops->ioctl(mdev, cmd, arg); -} - -static ssize_t vfio_mdev_read(struct vfio_device *core_vdev, char __user *buf, - size_t count, loff_t *ppos) -{ - struct mdev_device *mdev = to_mdev_device(core_vdev->dev); - struct mdev_parent *parent = mdev->type->parent; - - if (unlikely(!parent->ops->read)) - return -EINVAL; - - return parent->ops->read(mdev, buf, count, ppos); -} - -static ssize_t vfio_mdev_write(struct vfio_device *core_vdev, - const char __user *buf, size_t count, - loff_t *ppos) -{ - struct mdev_device *mdev = to_mdev_device(core_vdev->dev); - struct mdev_parent *parent = mdev->type->parent; - - if (unlikely(!parent->ops->write)) - return -EINVAL; - - return parent->ops->write(mdev, buf, count, ppos); -} - -static int vfio_mdev_mmap(struct vfio_device *core_vdev, - struct vm_area_struct *vma) -{ - struct mdev_device *mdev = to_mdev_device(core_vdev->dev); - struct mdev_parent *parent = mdev->type->parent; - - if (unlikely(!parent->ops->mmap)) - return -EINVAL; - - return parent->ops->mmap(mdev, vma); -} - -static void vfio_mdev_request(struct vfio_device *core_vdev, unsigned int count) -{ - struct mdev_device *mdev = to_mdev_device(core_vdev->dev); - struct mdev_parent *parent = mdev->type->parent; - - if (parent->ops->request) - parent->ops->request(mdev, count); - else if (count == 0) - dev_notice(mdev_dev(mdev), - "No mdev vendor driver request callback support, blocked until released by user\n"); -} - -static const struct vfio_device_ops vfio_mdev_dev_ops = { - .name = "vfio-mdev", - .open = vfio_mdev_open, - .release = vfio_mdev_release, - .ioctl = vfio_mdev_unlocked_ioctl, - .read = vfio_mdev_read, - .write = vfio_mdev_write, - .mmap = vfio_mdev_mmap, - .request = vfio_mdev_request, -}; - -static int vfio_mdev_probe(struct mdev_device *mdev) -{ - struct vfio_device *vdev; - int ret; - - vdev = kzalloc(sizeof(*vdev), GFP_KERNEL); - if (!vdev) - return -ENOMEM; - - vfio_init_group_dev(vdev, &mdev->dev, &vfio_mdev_dev_ops); - ret = vfio_register_group_dev(vdev); - if (ret) { - kfree(vdev); - return ret; - } - dev_set_drvdata(&mdev->dev, vdev); - return 0; -} - -static void vfio_mdev_remove(struct mdev_device *mdev) -{ - struct vfio_device *vdev = dev_get_drvdata(&mdev->dev); - - vfio_unregister_group_dev(vdev); - kfree(vdev); -} - -struct mdev_driver vfio_mdev_driver = { - .driver = { - .name = "vfio_mdev", - .owner = THIS_MODULE, - .mod_name = KBUILD_MODNAME, - }, - .probe = vfio_mdev_probe, - .remove = vfio_mdev_remove, -}; diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 5e631c359ef23c..59bbdf6634f934 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -747,7 +747,7 @@ void vfio_init_group_dev(struct vfio_device *device, struct device *dev, device->dev = dev; device->ops = ops; } -EXPORT_SYMBOL_GPL(vfio_init_group_dev); +EXPORT_SYMBOL(vfio_init_group_dev); int vfio_register_group_dev(struct vfio_device *device) { @@ -796,7 +796,7 @@ int vfio_register_group_dev(struct vfio_device *device) return 0; } -EXPORT_SYMBOL_GPL(vfio_register_group_dev); +EXPORT_SYMBOL(vfio_register_group_dev); /** * Get a reference to the vfio_device for a device. Even if the @@ -927,7 +927,7 @@ void vfio_unregister_group_dev(struct vfio_device *device) /* Matches the get in vfio_register_group_dev() */ vfio_group_put(group); } -EXPORT_SYMBOL_GPL(vfio_unregister_group_dev); +EXPORT_SYMBOL(vfio_unregister_group_dev); /** * VFIO base fd, /dev/vfio/vfio diff --git a/include/linux/mdev.h b/include/linux/mdev.h index 49cc4f65120d57..ea48c401e4fa63 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -61,45 +61,6 @@ struct device *mtype_get_parent_dev(struct mdev_type *mtype); * @mdev_attr_groups: Attributes of the mediated device. * @supported_type_groups: Attributes to define supported types. It is mandatory * to provide supported types. - * @create: Called to allocate basic resources in parent device's - * driver for a particular mediated device. It is - * mandatory to provide create ops. - * @mdev: mdev_device structure on of mediated device - * that is being created - * Returns integer: success (0) or error (< 0) - * @remove: Called to free resources in parent device's driver for - * a mediated device. It is mandatory to provide 'remove' - * ops. - * @mdev: mdev_device device structure which is being - * destroyed - * Returns integer: success (0) or error (< 0) - * @open: Open mediated device. - * @mdev: mediated device. - * Returns integer: success (0) or error (< 0) - * @release: release mediated device - * @mdev: mediated device. - * @read: Read emulation callback - * @mdev: mediated device structure - * @buf: read buffer - * @count: number of bytes to read - * @ppos: address. - * Retuns number on bytes read on success or error. - * @write: Write emulation callback - * @mdev: mediated device structure - * @buf: write buffer - * @count: number of bytes to be written - * @ppos: address. - * Retuns number on bytes written on success or error. - * @ioctl: IOCTL callback - * @mdev: mediated device structure - * @cmd: ioctl command - * @arg: arguments to ioctl - * @mmap: mmap callback - * @mdev: mediated device structure - * @vma: vma structure - * @request: request callback to release device - * @mdev: mediated device structure - * @count: request sequence number * Parent device that support mediated device should be registered with mdev * module with mdev_parent_ops structure. **/ @@ -109,19 +70,6 @@ struct mdev_parent_ops { const struct attribute_group **dev_attr_groups; const struct attribute_group **mdev_attr_groups; struct attribute_group **supported_type_groups; - - int (*create)(struct mdev_device *mdev); - int (*remove)(struct mdev_device *mdev); - int (*open)(struct mdev_device *mdev); - void (*release)(struct mdev_device *mdev); - ssize_t (*read)(struct mdev_device *mdev, char __user *buf, - size_t count, loff_t *ppos); - ssize_t (*write)(struct mdev_device *mdev, const char __user *buf, - size_t count, loff_t *ppos); - long (*ioctl)(struct mdev_device *mdev, unsigned int cmd, - unsigned long arg); - int (*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma); - void (*request)(struct mdev_device *mdev, unsigned int count); }; /* interface for exporting mdev supported type attributes */ diff --git a/include/linux/vfio.h b/include/linux/vfio.h index a2c5b30e1763ba..c5e08be4c56395 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -64,6 +64,10 @@ void vfio_init_group_dev(struct vfio_device *device, struct device *dev, int vfio_register_group_dev(struct vfio_device *device); void vfio_unregister_group_dev(struct vfio_device *device); extern struct vfio_device *vfio_device_get_from_dev(struct device *dev); +static inline void vfio_device_get(struct vfio_device *device) +{ + refcount_inc(&device->refcount); +} extern void vfio_device_put(struct vfio_device *device); /* events for the backend driver notify callback */ From patchwork Mon Apr 26 20:00:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12225007 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=-16.0 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,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS 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 D33C3C433ED for ; Mon, 26 Apr 2021 20:00:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B35D8613AA for ; Mon, 26 Apr 2021 20:00:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241812AbhDZUBN (ORCPT ); Mon, 26 Apr 2021 16:01:13 -0400 Received: from mail-bn8nam08on2069.outbound.protection.outlook.com ([40.107.100.69]:56800 "EHLO NAM04-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S241775AbhDZUBH (ORCPT ); Mon, 26 Apr 2021 16:01:07 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=anznxZ3RJvNdgwyR+ZSzEphkTaHOIX+G7FsYZMKhxMSu4w88PTVFlRDAVH+YalKSPPQ/P4I9HfZlE/Fey+/oqG+pnW4y6fMZpGQbLCa6KiLvsMFNtYrwOpbQOg+7ivSVn02ZPdyetXkE5dCC0r6YhQlFDgRrse4bJ11p/PYSG7zKyZJz736zDAdKn/yu+R3ltAq4tOQ6+J1ZPCSs/C7jDBHCzeCXPJbTRfdbw6Al40z0xLHuEfvJ+UkUART86B8bGZ13r4Svrc06OK6TTMhCGPdNsEsQnSfkNUiPOq6bSODIgPRRULW7mu+V3XETIdWK5lXeZTkcD6YlPqBVIuijLw== 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=2GqfmI8BaiRJtzq2SAixfbkeVfV7VIkOI1t3oWnh6Co=; b=JpNdGbDOnAVq6sn7etlG4+1jsfi9CJtYvNiOzsbF6LwCeXiyC76WJkYIedwm8QFUHIIodx4DqvNtqBA8hjxzJVui9oOu3IEiipKZLqZR9lqWCjt5/HXUMLizpaXt8W5rVJ2d7+Hr/jMwp3INkxwGb91le3QejQMjUnJ3OitCr17iE1hYpw1sTOgtOma9zcSqE4qHOMPFEdnIprPiM4evNGMX71xWONVHSM8rz+0Nz5keMFGphr4oGbCyK3wQBoMWeHDM5lUTN2vpfrtK09fuWK9BfKaARIRXenfN/X1CkG1sv+1laejfOAO4wf2GcB9U9/jQFYB3/KDfXklB9+jqUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2GqfmI8BaiRJtzq2SAixfbkeVfV7VIkOI1t3oWnh6Co=; b=GEJ/mSN9Lc671HsBPpwD5vFFDXwVYQMDdFlML+v/Tm6fWSVs/eyPoGweWEOdc+FprMlbOzKZJm0HhUK86QlZQ2iHgS8H9qhC9yl9pxVb7eAiy5sacJQ5n11W9cKzGZj4cYeP5ZCtEspOLgGxaDUtvo2UudDMPQwZaOUI1nz6BxRvVGkFDacGaZdIUnABVIyHb09DsyTZIbGcst4B5mQz6z7aASODfZJPRhsBy5uefXDRUfsqnDNX93pNj/ZXwktFIX6Sv9WxYJPTFdZ99G+KM6txN+otWWGFBhEyWbDdMEBRwM2m1j2Bx0U1onymkSn61ZtFSRfM7D5/S7Vf13R7kA== Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3740.namprd12.prod.outlook.com (2603:10b6:5:1c3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.24; Mon, 26 Apr 2021 20:00:19 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.4065.026; Mon, 26 Apr 2021 20:00:19 +0000 From: Jason Gunthorpe To: Alex Williamson , Cornelia Huck , kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Dan Williams , Daniel Vetter , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 10/13] vfio/mdev: Remove mdev_parent_ops dev_attr_groups Date: Mon, 26 Apr 2021 17:00:12 -0300 Message-Id: <10-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> In-Reply-To: <0-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: MN2PR01CA0047.prod.exchangelabs.com (2603:10b6:208:23f::16) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by MN2PR01CA0047.prod.exchangelabs.com (2603:10b6:208:23f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21 via Frontend Transport; Mon, 26 Apr 2021 20:00:17 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lb7Oy-00DFZc-47; Mon, 26 Apr 2021 17:00:16 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 69729f29-550f-47a9-fc21-08d908ede9dd X-MS-TrafficTypeDiagnostic: DM6PR12MB3740: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1775; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QZgRpXVsWYpIDaK57fl9Oj+Fr2haNsx01UO9rKQDCml/pp/lv5ivcter3OAzHBPOFNeN7MMMHLTLQ6K54Erdmqvzutf63FF5zakuiiPlGa38s9xnO+Utix0vFFlUYOGHq5fdqdfm3dtksHwRQMMaar6xqaywPiLPfmWm95KSXP5NbDbTvRfE2NElKD71CrH1g/wWE72HDZwKAYJOt+ZEI0MKwNvDEiLTnBsXE++OKsJZxWG1o5f6GW2cNung9zag83zwGiRIfx7OXfWMEDYvXwPchQSwWlGEK+5fzUmjWHRmBDGIpOfsD9lh8RqVeHYbvETbyGZn4T3gQs5awqonMiVQZ17aW8Gsd8m1CEFpe+6RMG18ARdwtTkiWNF1bZ6rMH+CdzaoJALk35aV7rfEMhavQ0GzSNQ3OoQBK5rN0BONq1ziC850exXFeoJ6r9RX5QrdIWvjpompdck5+Bd6vRx+SEB+DY1Xk9+mowb4yVzXlLjjpUakTHWZhmhD1tF7+LYRmPSlidnKfwz6TrNXgns5v52QykYXxbQOajtenTg1Bi2tyWbTcHMRiqjLcrZSJYY9dJDvWNIUGR+/if9w/aEBqMM/w0kCngOwtXaZziU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(39860400002)(346002)(136003)(396003)(376002)(66476007)(66556008)(9746002)(54906003)(426003)(110136005)(107886003)(186003)(26005)(6666004)(36756003)(316002)(2906002)(2616005)(478600001)(6636002)(9786002)(8936002)(83380400001)(38100700002)(86362001)(8676002)(5660300002)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: HhgJMTPN7+CA0yH/OB7ZRAG7KRoLQUNlLyzcBCE+FBLYKerFvATljssJh516UcTcv7Eiip2x4p+gZ2PiG+9lFMUp/B6Ta2pS5pCer4NlW01VAfU7h5jGK5w4rs2W7IT+hdJVVkNhtWTZb84Cos9q095w2rMjVgFBLv8s9OetPmrGSUtBmXVJS4LayvM9Bp7Po0XKQATQE2V5bLDFwSHR/EssKf7ohwg5eral75NSzFhhsdHRgtn9WusSobnOIE6Cj+XS2L8ODFFOjGvq1xwCOfg5ooA1E+U8b6PETHZyPfVnCFUmZo3MQbP0yv9Q7BPRHffoUp1QEC/brlUaYDY09rRNSmXSR2/eBa8HQizyB0IvPuyDplv9WWa4puVw66T3nJeCRCPxVG+shG9Oal0Ga2SvxcUuQwGuLTves8pk21LfCcF09WUfgWzytfmuJBHFhyLvwHk7CKlRTjvcZLpWQw9AT9cby6xlmKVfkIB7v5NdaKmcLRvUmY1A0zpcVQVpOKMlPPyK7ApkOeQSJPSIokX6BQqrE2pN1QmP4In4a22Jl8WWYcIZBu3o34CP3oU8dyWaZ1cNQotKZLp88DR58YyLJa6uUHRnzyIE4ivFQ0e5+hVsZvU1ai/u6PNr3Oyz/ftIhDX54TixTG1JAIfkpO1UT+wHxv2e54HsbUMRrP+ihjB9CiukpCNhdI8JMmrqIrlcbt09YTuj+STSqGJT+nnrM+aJuga6vAoQ4/PtCa04Cmp617fTeGGe6EUMYZ63TYIEzmk76eR5nYxei98HvPwk1C6WcX++93d+phvtlGvte5G1iSr0rsud3DQ9pphW1iz8uCN6yyZgkMTzVCkkb1ZuD2FjKuD0LfxvT49ftvBGl4hN4hF3TZnorw6zDM9BAQhXBuCUFDGHV3OPvq4+8F0Xd5Hgw0pAkuJe84vOhRh2yEVrBv/ZdyQYX4IC2MwQRtULnN0N/hwDPiK6Fvj3pkl812tb1TkSLTgJoty2wnojTOqDcNJShf8g1aNl1mfNRu1+vRHfZ7luVzsas5lMtP6D0mZwTaRxf0WIGwDMrSO+u8KMaIS52L7PwaVAILWmgF/mRNouZIEEW0N3huVgaXAnBx3bqjpiw2tI86kBTj0/E5rJhcsyNFyT1LOk06eCLn7CsqyhCzHeKNB+JbdkccbXr+wnNaxMUOoIY6rSVSvpJ4KEXNY3lGdCll8KUaIs7r3D5MYor9j/5B6FvN0bNl+VwAnFdHBlpm4XzZn2OIzq7xg6zOHI4ksfhLhRG7QlgLBN/jYG/oFTs3cqudWVLzvchTA9DAiB+3RahOVmcHIDDlZs9dMQdj8+zxOVAzmI X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 69729f29-550f-47a9-fc21-08d908ede9dd X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2021 20:00:17.5595 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5PhzIwkNS1v3ikPSK+dr8LwN4LDKrrewZKuoi4qttHOMmnvH2KrTwfBX3SIR/hmf X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3740 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is only used by one sample to print a fixed string that is pointless. In general, having a device driver attach sysfs attributes to the parent is horrific. This should never happen, and always leads to some kind of liftime bug as it become very difficult for the sysfs attribute to go back to any data owned by the device driver. Remove the general mechanism to create this abuse. Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- drivers/vfio/mdev/mdev_sysfs.c | 12 ++---------- include/linux/mdev.h | 2 -- samples/vfio-mdev/mtty.c | 30 +----------------------------- 3 files changed, 3 insertions(+), 41 deletions(-) diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index f5cf1931c54e48..66eef08833a4ef 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -197,7 +197,6 @@ void parent_remove_sysfs_files(struct mdev_parent *parent) remove_mdev_supported_type(type); } - sysfs_remove_groups(&parent->dev->kobj, parent->ops->dev_attr_groups); kset_unregister(parent->mdev_types_kset); } @@ -213,17 +212,10 @@ int parent_create_sysfs_files(struct mdev_parent *parent) INIT_LIST_HEAD(&parent->type_list); - ret = sysfs_create_groups(&parent->dev->kobj, - parent->ops->dev_attr_groups); - if (ret) - goto create_err; - ret = add_mdev_supported_type_groups(parent); if (ret) - sysfs_remove_groups(&parent->dev->kobj, - parent->ops->dev_attr_groups); - else - return ret; + goto create_err; + return 0; create_err: kset_unregister(parent->mdev_types_kset); diff --git a/include/linux/mdev.h b/include/linux/mdev.h index ea48c401e4fa63..fd9fe1dcf0e230 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -57,7 +57,6 @@ struct device *mtype_get_parent_dev(struct mdev_type *mtype); * * @owner: The module owner. * @device_driver: Which device driver to probe() on newly created devices - * @dev_attr_groups: Attributes of the parent device. * @mdev_attr_groups: Attributes of the mediated device. * @supported_type_groups: Attributes to define supported types. It is mandatory * to provide supported types. @@ -67,7 +66,6 @@ struct device *mtype_get_parent_dev(struct mdev_type *mtype); struct mdev_parent_ops { struct module *owner; struct mdev_driver *device_driver; - const struct attribute_group **dev_attr_groups; const struct attribute_group **mdev_attr_groups; struct attribute_group **supported_type_groups; }; diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index d2a168420b775d..31eec76bc553ce 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c @@ -1207,38 +1207,11 @@ static void mtty_close(struct vfio_device *mdev) pr_info("%s\n", __func__); } -static ssize_t -sample_mtty_dev_show(struct device *dev, struct device_attribute *attr, - char *buf) -{ - return sprintf(buf, "This is phy device\n"); -} - -static DEVICE_ATTR_RO(sample_mtty_dev); - -static struct attribute *mtty_dev_attrs[] = { - &dev_attr_sample_mtty_dev.attr, - NULL, -}; - -static const struct attribute_group mtty_dev_group = { - .name = "mtty_dev", - .attrs = mtty_dev_attrs, -}; - -static const struct attribute_group *mtty_dev_groups[] = { - &mtty_dev_group, - NULL, -}; - static ssize_t sample_mdev_dev_show(struct device *dev, struct device_attribute *attr, char *buf) { - if (mdev_from_dev(dev)) - return sprintf(buf, "This is MDEV %s\n", dev_name(dev)); - - return sprintf(buf, "\n"); + return sprintf(buf, "This is MDEV %s\n", dev_name(dev)); } static DEVICE_ATTR_RO(sample_mdev_dev); @@ -1340,7 +1313,6 @@ static struct mdev_driver mtty_driver = { static const struct mdev_parent_ops mdev_fops = { .owner = THIS_MODULE, .device_driver = &mtty_driver, - .dev_attr_groups = mtty_dev_groups, .supported_type_groups = mdev_type_groups, }; From patchwork Mon Apr 26 20:00:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12225009 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=-16.0 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,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 D117CC433B4 for ; Mon, 26 Apr 2021 20:00:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B44836135D for ; Mon, 26 Apr 2021 20:00:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241826AbhDZUBR (ORCPT ); Mon, 26 Apr 2021 16:01:17 -0400 Received: from mail-bn8nam08on2069.outbound.protection.outlook.com ([40.107.100.69]:56800 "EHLO NAM04-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S241772AbhDZUBI (ORCPT ); Mon, 26 Apr 2021 16:01:08 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UMybCx5we8S17H7319DXEq4UIzIUXocXbExGpGKA4uzieqyigejvZygg3ns3MWlNpih19jsOQ3JLHzITBqBSI7bci2ZdkkHbiWF08uGRFh3cr3Tc5WQHuiqX+aIs2ksUfjf2JH9YLGS3/0p7oC2CKBx6KmkemEkJQFsL8QGB1JcullUea2n3WWMED8K/ukn+Nxeb8v1l/Ch5WaH4Kas0Z/c6hPkhdvD/mt2DwGERAKs686WcCkUQIvHPLjeGsbd9gbjFyUEvMdOzcEqG6u0DnJhQQt0HPxJvr1pbMSnEvfQek51tu8KG5RVBryYdB15O/pPFuJM8uAKSWA2h3RPCMg== 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=Ui6Og269Se97lo2DPmiHQraGWQEXfL4ylWpFw8Muxxo=; b=T000Lu37NXRVD9yIhe0ZvJjUVPqF2dduLBCnxUIreiwl7i/PYRVURBu7P5Ncf22c+oTDR3xu/AdcSohHlgFOmQWkW2WWOThOBhkQM4YUByFXa3T8INOPT7Y5lYqFy8sZW21/dkrgA5bAyqJimjsjSGHrUqOXqfkT5Ol1/GNUmI77DXIX4Sy7rUYLfRZFi9IkTDNNGcWb7SIXeUkDTGTc1ES7NujGcbK6X1z7mypTYmD4D8l3JTS9SWgT2Qqt46ULOs9/LUFCJkd+PfAHMhkQS9qtxtnN2a6ip7JOr5pFMMBVP/ju6yXEPJZtSEHrIZFiX1Ek6CVd+b04IoTP22usYg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ui6Og269Se97lo2DPmiHQraGWQEXfL4ylWpFw8Muxxo=; b=P/9I6qOeRADbJm8Vp0d5kwv0/bJC1UQbYhO9d1G3ZKFMc0OJaKM7TkDbsmdG+9UoUuiX7FBZPz2ma/GaEo9YxuuZ8gRBGRj/tSYyrmT/giMl2kKf/LNamNMsHb7HJBcrOTz0F8GmgVID1FNyosYmQAQvIksWzWeXPYX7I7JV2Obp5D1JwhuiJso9MSBrzLtrbtxjV1yChFucfDGDCiG+Uf3a8k6eHUW4aPmRVFO/gsKAYayeihEo1xwwUuLFfQaswRvgFBSzwShmhC3Qo6/CL/3YCEZ0OEfhbJgfSQqTW5W4fiy1VVUZy2IzZXdMTM1FveBas2qldlUyQrf/q/eAWg== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3740.namprd12.prod.outlook.com (2603:10b6:5:1c3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.24; Mon, 26 Apr 2021 20:00:20 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.4065.026; Mon, 26 Apr 2021 20:00:20 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-doc@vger.kernel.org, linux-s390@vger.kernel.org, Peter Oberparleiter , Halil Pasic , Pierre Morel , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: "Raj, Ashok" , Dan Williams , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 11/13] vfio/mdev: Remove mdev_parent_ops Date: Mon, 26 Apr 2021 17:00:13 -0300 Message-Id: <11-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> In-Reply-To: <0-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: MN2PR14CA0006.namprd14.prod.outlook.com (2603:10b6:208:23e::11) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by MN2PR14CA0006.namprd14.prod.outlook.com (2603:10b6:208:23e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20 via Frontend Transport; Mon, 26 Apr 2021 20:00:17 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lb7Oy-00DFZg-57; Mon, 26 Apr 2021 17:00:16 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e3bee208-d0ab-4ed3-6853-08d908ede9e2 X-MS-TrafficTypeDiagnostic: DM6PR12MB3740: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2887; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: It1cvD3pCDsaNIdFWnPBC6ZhgP2ek2Z1J/+6a5TKu0KAO6lYPR8Aesvgk6jgaFaSx1bwJFZACyPgHPFLVzfmeXBRRvLzTLJhNrL4dT/2mgPYyBYchwj64I3XB2zH8lJtp/1a6o2OFhKj84kLfQg6bwj0HAJqFyntBa5Ww/achyyBC1FXqfp9gPVZhf4pAtQ/j4MQAlLF4hQJdlTgvpVHCnXMhB3C54RUAKvtRRa8Edyfcy+Sp3rJGMk27uoV17JiVpYZhW1C4Hj5Ao2Leui634X2vBe+ywaHlOcaHGpRlkmXGywMEwSM+/Hz8mOXxJXziADvvu6r9ap5SquVVi/C6u+j5qO2bnf8l6W1nbZ2WQ7CqHd6ig0ufmTYmCdsCicVIKSsUMN/R/T1o3ai6whJt3vhji9tr21nIbyAGlk5OFfEGokjzCtYIfWhkblKVuWM8tpsaYJXJymAVjNJ9QBBXnLAqIU7yPv9uO8vBQbOv7EOAcB/n3WEUZLfwQ4iXVC+ZBWWPZP/LxDLlta6LZSgISChhtPZgBcTcJmZvTh88DHNc+I8IsJtsLtUbejAw/OUZiBXo9+NyOxC4K2BGQX6MwU2kShK+hDsPprydJMNFQxIieVJI9m//01Zh09fSHuiR1Dl6dgXsQR+qVgdvGIxVQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(39860400002)(346002)(136003)(396003)(376002)(66476007)(66556008)(9746002)(54906003)(426003)(110136005)(107886003)(186003)(26005)(921005)(6666004)(36756003)(316002)(2906002)(30864003)(2616005)(478600001)(9786002)(8936002)(83380400001)(38100700002)(86362001)(8676002)(5660300002)(7416002)(4326008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 2DqjvMu8/qPGzI0qBDgqIjq8Zaq2DGe8iCgppJexVso/o6cuh5717D3L9uUZpGdHO/NurSFS5RBU9FDCcgb08Op8AF744WtI9Inxz2Zue9ggAr2OuieisqkwsWPXFCAhM3D+ZTR3lWyvyHn++IGzo3EnpG4uxKJL6hPDRMFQff3/jjwuYnFnQegATa6fPlYqq4YpmMLo86Jj8ft31MKO94ed2RmFzUZWhQHHysFrNG71tXLCE/T4XEzsl6Q1XFJT3N2kPCgZAmZ+fBNZbU/YntP7sbuXBxJmyA14BN6kgcgpX/zsrTWzUMEW8WLcnHvMAdeo0ary9iLFeGJGaieHhwkW3VVyFrr666iBgr4+LYS9m1zZIxkc7mXQVrTfAUgYRikogguOOpT/eG2B+KNMHSj/vN9I9hinOi8J1STf2ytZkR8jBlExLqkGSQhnNgOQPSPck02vgcKd2JvQ5xqz47HPZrfw+7ZUAzXNn09p2dlhzX/rCGf93HNxKwFTKKFmkqnT1t5tngwjxZULnQffxbCTccn8vFP6HyANXA+Hq7ihCTmXGaOHA2gdWqkDh86cNVHAwWvIH+y/ihTweI7JYUreYPEi1nl524NHs5KwVSdTlTEG9UCkQhmPy0pRJO/X5X9ROODcJkORkT757Wy6BjCRxZNeFKEz7O+G37dlfdjZab6zfYtneaRGfp4YNNd0CVYo/bzpVEAftBNeqDvPuEQ7qVl2sMLiC6Eil3AyjZxoL2F8QfyUwa97B7GdUa3nwn3KmxuCJ/eytXQuxKe/bo+Ip0Fj3S7rf6wxL5ckjr415RDvZBcyPWt6JToHCGQ6dQhB1ZatS/aijUSb0vbCbn7+gIIYVK0sb2ZVqKj6jCR91bRskpjAoZsMYn2XpGD/KFx2zK2oJLVOAM2QV2BrvRcJqXCoZSrOPChsxnxe7EyOergXTR4mPlS+ICrYujTJabU178R8Mc18CWBjiyN8ndE4/WRbjXoYJyRWTscUV2e6W7Taaz0iR/89biLpmKF9ItkotSpM4Ytcj9Fiu/dCr8X1d7VT0051/TAcerU3dOqTZkfqHBRd55rWm+pCiZp7AualSePMdNd2q2aUWHICZtLM2uDBwPmnZBF2/PuG2oNp6N4zqkzXHcWBNmPpOo6vOwKdp8LzvWVpDpM7qhT774brmh2Z4j5gRq6lOnynth3GUVPEOtrZq6v2j4pcVU8Z3+c6upqi0woSUdrjZjvdBh2cS5dlIxTTzPYNu3z2q3inDtdP0hPgcGFGruf2z1oOY21feHzk6hzX9bCzvP40l6Ll9ZXswSXKeHu+np0veWlu8rZJcf6N2FomVA5rBTdq X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e3bee208-d0ab-4ed3-6853-08d908ede9e2 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2021 20:00:17.8043 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PCPotONK0O933CuaZtVgUf2gRXGjnuZrqhFKVO9POkXHZXSLoTqjHYaJPf04EE6c X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3740 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The last useful member in this struct is the supported_type_groups, move it to the mdev_driver and delete mdev_parent_ops. Replace it with mdev_driver as an argument to mdev_register_device() Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- .../driver-api/vfio-mediated-device.rst | 37 +++++++------------ drivers/gpu/drm/i915/gvt/kvmgt.c | 8 +--- drivers/s390/cio/vfio_ccw_ops.c | 7 +--- drivers/s390/crypto/vfio_ap_ops.c | 9 +---- drivers/vfio/mdev/mdev_core.c | 13 +++---- drivers/vfio/mdev/mdev_driver.c | 2 +- drivers/vfio/mdev/mdev_private.h | 2 +- drivers/vfio/mdev/mdev_sysfs.c | 6 +-- include/linux/mdev.h | 24 ++---------- samples/vfio-mdev/mbochs.c | 9 +---- samples/vfio-mdev/mdpy.c | 9 +---- samples/vfio-mdev/mtty.c | 9 +---- 12 files changed, 39 insertions(+), 96 deletions(-) diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentation/driver-api/vfio-mediated-device.rst index 5f866b17c93e69..a073d0bb06e7fd 100644 --- a/Documentation/driver-api/vfio-mediated-device.rst +++ b/Documentation/driver-api/vfio-mediated-device.rst @@ -93,7 +93,7 @@ interfaces: Registration Interface for a Mediated Bus Driver ------------------------------------------------ -The registration interface for a mediated bus driver provides the following +The registration interface for a mediated device driver provides the following structure to represent a mediated device's driver:: /* @@ -105,6 +105,7 @@ structure to represent a mediated device's driver:: struct mdev_driver { int (*probe) (struct mdev_device *dev); void (*remove) (struct mdev_device *dev); + struct attribute_group **supported_type_groups; struct device_driver driver; }; @@ -119,35 +120,25 @@ to register and unregister itself with the core driver: extern void mdev_unregister_driver(struct mdev_driver *drv); -The mediated bus driver is responsible for adding mediated devices to the VFIO -group when devices are bound to the driver and removing mediated devices from -the VFIO when devices are unbound from the driver. +The mediated bus driver's probe function should create a vfio_device on top of +the mdev_device and connect it to an appropriate implementation of +vfio_device_ops. - -Physical Device Driver Interface --------------------------------- - -The physical device driver interface provides the mdev_parent_ops[3] structure -to define the APIs to manage work in the mediated core driver that is related -to the physical device. - -The structures in the mdev_parent_ops structure are as follows: - -* dev_attr_groups: attributes of the parent device -* mdev_attr_groups: attributes of the mediated device -* supported_config: attributes to define supported configurations - -A driver should use the mdev_parent_ops structure in the function call to -register itself with the mdev core driver:: +When a driver wants to add the GUID creation sysfs to an existing device it has +probe'd to then it should call: extern int mdev_register_device(struct device *dev, - const struct mdev_parent_ops *ops); + struct mdev_driver *mdev_driver); + +This will provide the 'mdev_supported_types/XX/create' files which can then be +used to trigger the creation of a mdev_device. The created mdev_device will be +attached to the specified driver. -However, the mdev_parent_ops structure is not required in the function call -that a driver should use to unregister itself with the mdev core driver:: +When the driver needs to remove itself it calls: extern void mdev_unregister_device(struct device *dev); +Which will unbind and destroy all the created mdevs and remove the sysfs files. Mediated Device Management Interface Through sysfs ================================================== diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index 85ef300087e091..02089efd15bb92 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -1669,10 +1669,6 @@ static struct mdev_driver intel_vgpu_mdev_driver = { .remove = intel_vgpu_remove, }; -static struct mdev_parent_ops intel_vgpu_ops = { - .device_driver = &intel_vgpu_mdev_driver, -}; - static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops) { struct attribute_group **kvm_vgpu_type_groups; @@ -1680,9 +1676,9 @@ static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops) intel_gvt_ops = ops; if (!intel_gvt_ops->get_gvt_attrs(&kvm_vgpu_type_groups)) return -EFAULT; - intel_vgpu_ops.supported_type_groups = kvm_vgpu_type_groups; + intel_vgpu_mdev_driver.supported_type_groups = kvm_vgpu_type_groups; - return mdev_register_device(dev, &intel_vgpu_ops); + return mdev_register_device(dev, &intel_vgpu_mdev_driver); } static void kvmgt_host_exit(struct device *dev) diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index 0fcf46031d3821..161697529dcc41 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -655,17 +655,12 @@ struct mdev_driver vfio_ccw_mdev_driver = { }, .probe = vfio_ccw_mdev_probe, .remove = vfio_ccw_mdev_remove, -}; - -static const struct mdev_parent_ops vfio_ccw_mdev_ops = { - .owner = THIS_MODULE, - .device_driver = &vfio_ccw_mdev_driver, .supported_type_groups = mdev_type_groups, }; int vfio_ccw_mdev_reg(struct subchannel *sch) { - return mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops); + return mdev_register_device(&sch->dev, &vfio_ccw_mdev_driver); } void vfio_ccw_mdev_unreg(struct subchannel *sch) diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 79872c857dd522..92789257c87639 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -1339,12 +1339,7 @@ static struct mdev_driver vfio_ap_matrix_driver = { }, .probe = vfio_ap_mdev_probe, .remove = vfio_ap_mdev_remove, -}; - -static const struct mdev_parent_ops vfio_ap_matrix_ops = { - .owner = THIS_MODULE, - .device_driver = &vfio_ap_matrix_driver, - .supported_type_groups = vfio_ap_mdev_type_groups, + .supported_type_groups = vfio_ap_mdev_type_groups, }; int vfio_ap_mdev_register(void) @@ -1357,7 +1352,7 @@ int vfio_ap_mdev_register(void) if (ret) return ret; - ret = mdev_register_device(&matrix_dev->device, &vfio_ap_matrix_ops); + ret = mdev_register_device(&matrix_dev->device, &vfio_ap_matrix_driver); if (ret) goto err_driver; return 0; diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index d507047e6ecf4a..cd1ab9fe299445 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -109,12 +109,12 @@ static int mdev_device_remove_cb(struct device *dev, void *data) /* * mdev_register_device : Register a device * @dev: device structure representing parent device. - * @ops: Parent device operation structure to be registered. + * @mdev_driver: Device driver to bind to the newly created mdev * * Add device to list of registered parent devices. * Returns a negative value on error, otherwise 0. */ -int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops) +int mdev_register_device(struct device *dev, struct mdev_driver *mdev_driver) { int ret; struct mdev_parent *parent; @@ -122,9 +122,7 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops) char *envp[] = { env_string, NULL }; /* check for mandatory ops */ - if (!ops || !ops->supported_type_groups) - return -EINVAL; - if (!ops->device_driver) + if (!mdev_driver->supported_type_groups) return -EINVAL; dev = get_device(dev); @@ -151,7 +149,7 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops) init_rwsem(&parent->unreg_sem); parent->dev = dev; - parent->ops = ops; + parent->mdev_driver = mdev_driver; if (!mdev_bus_compat_class) { mdev_bus_compat_class = class_compat_register("mdev_bus"); @@ -257,7 +255,7 @@ static int mdev_bind_driver(struct mdev_device *mdev) while (1) { device_lock(&mdev->dev); if (mdev->dev.driver == - &mdev->type->parent->ops->device_driver->driver) { + &mdev->type->parent->mdev_driver->driver) { ret = 0; goto out_unlock; } @@ -304,7 +302,6 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) mdev->dev.parent = parent->dev; mdev->dev.bus = &mdev_bus_type; mdev->dev.release = mdev_device_release; - mdev->dev.groups = parent->ops->mdev_attr_groups; mdev->type = type; /* Pairs with the put in mdev_device_release() */ kobject_get(&type->kobj); diff --git a/drivers/vfio/mdev/mdev_driver.c b/drivers/vfio/mdev/mdev_driver.c index 07ada55efd6228..d743a9f51f4c90 100644 --- a/drivers/vfio/mdev/mdev_driver.c +++ b/drivers/vfio/mdev/mdev_driver.c @@ -75,7 +75,7 @@ static int mdev_match(struct device *dev, struct device_driver *drv) { struct mdev_device *mdev = to_mdev_device(dev); - return drv == &mdev->type->parent->ops->device_driver->driver; + return drv == &mdev->type->parent->mdev_driver->driver; } struct bus_type mdev_bus_type = { diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h index a656cfe0346c33..839567d059a07d 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -15,7 +15,7 @@ void mdev_bus_unregister(void); struct mdev_parent { struct device *dev; - const struct mdev_parent_ops *ops; + const struct mdev_driver *mdev_driver; struct kref ref; struct list_head next; struct kset *mdev_types_kset; diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index 66eef08833a4ef..5a3873d1a275ae 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -97,7 +97,7 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, { struct mdev_type *type; struct attribute_group *group = - parent->ops->supported_type_groups[type_group_id]; + parent->mdev_driver->supported_type_groups[type_group_id]; int ret; if (!group->name) { @@ -154,7 +154,7 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, static void remove_mdev_supported_type(struct mdev_type *type) { struct attribute_group *group = - type->parent->ops->supported_type_groups[type->type_group_id]; + type->parent->mdev_driver->supported_type_groups[type->type_group_id]; sysfs_remove_files(&type->kobj, (const struct attribute **)group->attrs); @@ -168,7 +168,7 @@ static int add_mdev_supported_type_groups(struct mdev_parent *parent) { int i; - for (i = 0; parent->ops->supported_type_groups[i]; i++) { + for (i = 0; parent->mdev_driver->supported_type_groups[i]; i++) { struct mdev_type *type; type = add_mdev_supported_type(parent, i); diff --git a/include/linux/mdev.h b/include/linux/mdev.h index fd9fe1dcf0e230..af807c77c1e0f5 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -51,25 +51,6 @@ unsigned int mdev_get_type_group_id(struct mdev_device *mdev); unsigned int mtype_get_type_group_id(struct mdev_type *mtype); struct device *mtype_get_parent_dev(struct mdev_type *mtype); -/** - * struct mdev_parent_ops - Structure to be registered for each parent device to - * register the device to mdev module. - * - * @owner: The module owner. - * @device_driver: Which device driver to probe() on newly created devices - * @mdev_attr_groups: Attributes of the mediated device. - * @supported_type_groups: Attributes to define supported types. It is mandatory - * to provide supported types. - * Parent device that support mediated device should be registered with mdev - * module with mdev_parent_ops structure. - **/ -struct mdev_parent_ops { - struct module *owner; - struct mdev_driver *device_driver; - const struct attribute_group **mdev_attr_groups; - struct attribute_group **supported_type_groups; -}; - /* interface for exporting mdev supported type attributes */ struct mdev_type_attribute { struct attribute attr; @@ -94,12 +75,15 @@ struct mdev_type_attribute mdev_type_attr_##_name = \ * struct mdev_driver - Mediated device driver * @probe: called when new device created * @remove: called when device removed + * @supported_type_groups: Attributes to define supported types. It is mandatory + * to provide supported types. * @driver: device driver structure * **/ struct mdev_driver { int (*probe)(struct mdev_device *dev); void (*remove)(struct mdev_device *dev); + struct attribute_group **supported_type_groups; struct device_driver driver; }; @@ -118,7 +102,7 @@ static inline const guid_t *mdev_uuid(struct mdev_device *mdev) extern struct bus_type mdev_bus_type; -int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops); +int mdev_register_device(struct device *dev, struct mdev_driver *mdev_driver); void mdev_unregister_device(struct device *dev); int mdev_register_driver(struct mdev_driver *drv); diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index e18821a8a6beb8..c76ceec584b41b 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -1418,12 +1418,7 @@ static struct mdev_driver mbochs_driver = { }, .probe = mbochs_probe, .remove = mbochs_remove, -}; - -static const struct mdev_parent_ops mdev_fops = { - .owner = THIS_MODULE, - .device_driver = &mbochs_driver, - .supported_type_groups = mdev_type_groups, + .supported_type_groups = mdev_type_groups, }; static const struct file_operations vd_fops = { @@ -1466,7 +1461,7 @@ static int __init mbochs_dev_init(void) if (ret) goto err_class; - ret = mdev_register_device(&mbochs_dev, &mdev_fops); + ret = mdev_register_device(&mbochs_dev, &mbochs_driver); if (ret) goto err_device; diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c index 82638de333330d..c22b2c808d132d 100644 --- a/samples/vfio-mdev/mdpy.c +++ b/samples/vfio-mdev/mdpy.c @@ -735,12 +735,7 @@ static struct mdev_driver mdpy_driver = { }, .probe = mdpy_probe, .remove = mdpy_remove, -}; - -static const struct mdev_parent_ops mdev_fops = { - .owner = THIS_MODULE, - .device_driver = &mdpy_driver, - .supported_type_groups = mdev_type_groups, + .supported_type_groups = mdev_type_groups, }; static const struct file_operations vd_fops = { @@ -783,7 +778,7 @@ static int __init mdpy_dev_init(void) if (ret) goto err_class; - ret = mdev_register_device(&mdpy_dev, &mdev_fops); + ret = mdev_register_device(&mdpy_dev, &mdpy_driver); if (ret) goto err_device; diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index 31eec76bc553ce..87f5ba12a230e3 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c @@ -1308,12 +1308,7 @@ static struct mdev_driver mtty_driver = { }, .probe = mtty_probe, .remove = mtty_remove, -}; - -static const struct mdev_parent_ops mdev_fops = { - .owner = THIS_MODULE, - .device_driver = &mtty_driver, - .supported_type_groups = mdev_type_groups, + .supported_type_groups = mdev_type_groups, }; static void mtty_device_release(struct device *dev) @@ -1364,7 +1359,7 @@ static int __init mtty_dev_init(void) if (ret) goto err_class; - ret = mdev_register_device(&mtty_dev.dev, &mdev_fops); + ret = mdev_register_device(&mtty_dev.dev, &mtty_driver); if (ret) goto err_device; From patchwork Mon Apr 26 20:00:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12225005 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=-16.0 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,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS 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 AC51AC43460 for ; Mon, 26 Apr 2021 20:00:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67EC5613B1 for ; Mon, 26 Apr 2021 20:00:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241787AbhDZUBJ (ORCPT ); Mon, 26 Apr 2021 16:01:09 -0400 Received: from mail-dm6nam11on2085.outbound.protection.outlook.com ([40.107.223.85]:3982 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S241741AbhDZUBG (ORCPT ); Mon, 26 Apr 2021 16:01:06 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lAdk0N/w60rua6nUqiyYvhACQ/LZVKG6+RDiA6uSL8wNAJLuFv/pWI1BRT8/V9q+e+M05hZ2ESAc3Yrpo0DAMw2zL3Y5ygCqMZDmxE/5ykbwag2HIHLnVbME7yoJSotqgK0eVfmsN/dVafQCNTCBC2YHY3C3pUfDwrLSYwNsUrb0Wq6MGytkj7mqZBqMHhFhsSmc35lKHsSW+fWeNP4XS4QRn58Vv+InZM/IZ/2iIA/wVXsrzL5XHC5yy+NHL4xZaAjG01OXURjneSyZjzFoXZftoKGDEGSG1/c4pbE7P5WXeUC4y8iG+4+jJSQ+PUejhr968y4shpjsCr3Qz6Uvfw== 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=j+Z4dTi3Z/EAr7+nWs6UlI6AlA3va5v5ZjSREaY3vf8=; b=D1ybEdf6d8hO9R2t6yHTb57vQ6pTFj/ESgIx+HJ9TNmZdptcPkpBlkO1Mhh7dpDm5ORMSvtcAg5Jin5nO9ig6agzbZTvlG9arOlCtK+EkhLxThRtKCtGv1yzqJNveeyQJH2pHWckLRmgdtCzm34k+Jg7mr+67ZSV2E/WtIyQimNPhxM3dRigcP9bSLWN4ErwcgGgSlfhmNF/eyYUeGBKtJmAaLJ3TcQW5tHWpclBqWfwDpwcSFuMS2W0fJsjMO6koZjJLDOiHyr2N7snQm6Hvc32qw6aycIDfl2/7YtLVLYqNdoC+FfybUwhIWl7iDXPQBgNm1m7582uNhoSnQoSDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=j+Z4dTi3Z/EAr7+nWs6UlI6AlA3va5v5ZjSREaY3vf8=; b=bHe4WasjaL3BgJfWOakxkIStoVD8VLWUSt+n41uPHwft4TvWGVjU9+Ylo0l7MaBpTNgOpGX5qMR0NLJ5V+FzkD9QQtGloFXNa5YQGhQEym13jwLmkW5yyslFx52yheLfc+3uUGhL6dVOTGnIZyWYimrQXz8AUaGKdCreJZvDuDzIohJeRNs5T3M7LRmE+chZzXABJsDNoWOCboA77EqbCqry0xifT0e5UbUu9GE3SpJ0GlTeG+cH2l64tLPs11yK2G2g3GGLFe2zeQNgCzieZWiVsRnlCKXyvGy6amnN5PLBF+BqW8kTgKv7THf43vATsbcm3teLOPGKZsDXIWW8ug== Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM5PR12MB1659.namprd12.prod.outlook.com (2603:10b6:4:11::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Mon, 26 Apr 2021 20:00:21 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.4065.026; Mon, 26 Apr 2021 20:00:21 +0000 From: Jason Gunthorpe To: Alex Williamson , Cornelia Huck , kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Dan Williams , Daniel Vetter , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 12/13] vfio/mdev: Use the driver core to create the 'remove' file Date: Mon, 26 Apr 2021 17:00:14 -0300 Message-Id: <12-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> In-Reply-To: <0-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: MN2PR14CA0014.namprd14.prod.outlook.com (2603:10b6:208:23e::19) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by MN2PR14CA0014.namprd14.prod.outlook.com (2603:10b6:208:23e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20 via Frontend Transport; Mon, 26 Apr 2021 20:00:18 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lb7Oy-00DFZj-6J; Mon, 26 Apr 2021 17:00:16 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3a50a912-85b2-453e-16d8-08d908edea92 X-MS-TrafficTypeDiagnostic: DM5PR12MB1659: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fTxKyEt3+T0nGwaAiiB4a3dDp7mUTJak6UEigLXK1uxeOe66Hp0VYgbaLVo5ds6+O865Ti8m9atVSPm6eERcebBmLueh9Jq7uG8wXoC73SH0t62vCDOxwdAF1o0nu1rgGqwAuMEb1clJKJj99kYKn5d3GnnJvtFLBxk187W9UUl52BgRMoqa+Jlqtzafa671c32dKtZVKioGm5ruTpbYrn+gu39IuEWc8SkibGT0foaWYHu56WXMG7WSol7zkpMp3HtIBkKgVx5WkqKmEaE7BuaxMAKkWg7d+qV+6AYFWjWxPRxO5nBM6UmfZD1ZIu2ixzY+xm7CccIheJs9XGMa3CzEzh5XMNhEHwYsCIJJryjp7yUlUZu+nBwaEiHOFpguuuw1PMI9e/tHDjEvlybNE1Cv0enbEig7ZYSxesUa/YaAUPQrYrLYCITcNbE+mGb1DMJxdkQ3f5zZLHtpD/prc6LDbS6pjxY/FP4LbemZEIySHj2L1uU5h/6jwdfu4iL6gKWhHtHizBxT46Jdjw3vg+E51zhQym2W5QMLyY3ngZ/pQuBtNfJZQiBw8j7axa4lOhzgDLrcSNihOKXT3aqFjrQvXMEkIsr8OUfoKlFxtHg= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(136003)(396003)(366004)(39860400002)(376002)(66946007)(36756003)(66556008)(66476007)(8676002)(2906002)(86362001)(6636002)(2616005)(8936002)(478600001)(426003)(83380400001)(5660300002)(4326008)(38100700002)(9786002)(107886003)(110136005)(9746002)(186003)(316002)(54906003)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 5RqBgjAd7oVWR0WyWb2BKccfg2g2en7JIiQlA+gAeYHhL/IONkn9Zne0CMdK613U3rPxm3UF3mzg0uxJ9zgsbczgn7r2kea8hP36fhim9Mkm6xiqtcdtKecOJCGHb0mtXhlUgbzEA5Ee+xEuCNqleeZ6plU4K3JkEFrzz4OaOZcyeIe8JzCWkpByLaC/D9xiexOPjBTrAa3IboIUwEFGLOeM4LTmQorAkps2iPEae1zJUlDx4ty3IOZM/l/AggmrNSSDZKpFa30iy++HHTUFzQf+3VyukI0SyX8toCLfjbwh/cTdJs+YqMRjvPzHxJmEEW2jPYJzeYEw3WHyWPCJG54O/l+vX4uJX/pHxS17kJ3OzcM103GqdNy/ATe7dc1xT9CcUSPCmg+t4Z5c4fQkqgyXrztUmjJs3JPGu6/WwX1a4IM4gBhYFZ7N/hPMoTt0NcYq1fE3sXtfMfxaot46hNaxpodI0GAdUHJUH4T6yEChcD1EnTFZK5uVhkfzEtWQljLlFPjhv5oV6mMK1LJMsv3zsFImquSXg7zv76ms9EQAvDaJ/pKjzBb5MqkH5RAxj/MWq8tVJWLFS0ZvfJmnQGXukMhFn0JrPVyypj5XmBVqQYi5+RgtIgIvMcYmGcV4FCHBBqXUudmuonsvEbZW3rnotITPQhQ3PnoP9pgQQlVqQV4hd/LF4J+8RnnMME4gjN0zFSiLQePzrrHX0r4Ju4aQurbxPwqY0Gd4wfVmOeUiul8KM0utESW/KAeFTnGN8uMWPjwqsotm3y9tpsv9LW8qV4+w/lWXvkAwiYt2AI1Kq5krW1vx/VAt0Ka0mh6DmCVL04NTOXRoY6Lc6DQukMzb4K2sjpqFkjrl/lNtkzn/tQfTuD8f6tiKQ7Qk7tccPw3MlDb1PlAKRL3NZoRofXgIYbM8VnTlFW/U91ruQq1jUFkUk8Yhv28YmfsvtxJn5ggO3+0KdDXOiJYmYU6xPczUSM1UATJlERVAqvkxli1guMqix2jGUwM6Orf17aRGvC8m3KISuODBZrUZu/JR5PwqS3y/v42EfdFO14RcUCvDEFhfHmykbPAaW2jDdaZKUcoIFrq94BySyvPX5CZGYrtpKm9Y6J1NloNSVRGbjYlPpNwM3pEQ89Mx0Kkd6zw7CmotN03ibHF6VzSUPKqKOA1ag8QNg2k4zisIRXflKztBsPu605bPuzdXEBJYRZv7xSVV+Ax2AMDs/QAN7CaDsAp9Is879OVEdAkjLPURkrrhGDS6cBBlVIVrGzsMvWU9hYtNMWZ6/W0j/DLvUVpOQhhH8C1CXs1XvvTNXOBNcKQK8F5YP8u6Gk1jnB2VJ1Fp X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3a50a912-85b2-453e-16d8-08d908edea92 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2021 20:00:18.7218 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: w3UfbVt7LROMPytxUSWRbFynmmWhQ9usZ5DspmNFYabvaw5U/Gd2S0i8H5MmRam6 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1659 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The device creator is supposed to use the dev.groups value to add sysfs files before device_add is called, not call sysfs_create_files() after device_add() returns. This creates a race with uevent delivery where the extra attribute will not be visible. This was being done because the groups had been co-opted by the mdev driver, now that prior patches have moved the driver's groups to the struct device_driver the dev.group is properly free for use here. Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- drivers/vfio/mdev/mdev_core.c | 1 + drivers/vfio/mdev/mdev_private.h | 2 ++ drivers/vfio/mdev/mdev_sysfs.c | 19 ++++++++++--------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index cd1ab9fe299445..a61685d8844d44 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -302,6 +302,7 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) mdev->dev.parent = parent->dev; mdev->dev.bus = &mdev_bus_type; mdev->dev.release = mdev_device_release; + mdev->dev.groups = mdev_device_groups; mdev->type = type; /* Pairs with the put in mdev_device_release() */ kobject_get(&type->kobj); diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h index 839567d059a07d..c6944d3eaf78fa 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -32,6 +32,8 @@ struct mdev_type { unsigned int type_group_id; }; +extern const struct attribute_group *mdev_device_groups[]; + #define to_mdev_type_attr(_attr) \ container_of(_attr, struct mdev_type_attribute, attr) #define to_mdev_type(_kobj) \ diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index 5a3873d1a275ae..0ccfeb3dda2455 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -244,11 +244,20 @@ static ssize_t remove_store(struct device *dev, struct device_attribute *attr, static DEVICE_ATTR_WO(remove); -static const struct attribute *mdev_device_attrs[] = { +static struct attribute *mdev_device_attrs[] = { &dev_attr_remove.attr, NULL, }; +static const struct attribute_group mdev_device_group = { + .attrs = mdev_device_attrs, +}; + +const struct attribute_group *mdev_device_groups[] = { + &mdev_device_group, + NULL +}; + int mdev_create_sysfs_files(struct mdev_device *mdev) { struct mdev_type *type = mdev->type; @@ -262,15 +271,8 @@ int mdev_create_sysfs_files(struct mdev_device *mdev) ret = sysfs_create_link(kobj, &type->kobj, "mdev_type"); if (ret) goto type_link_failed; - - ret = sysfs_create_files(kobj, mdev_device_attrs); - if (ret) - goto create_files_failed; - return ret; -create_files_failed: - sysfs_remove_link(kobj, "mdev_type"); type_link_failed: sysfs_remove_link(mdev->type->devices_kobj, dev_name(&mdev->dev)); return ret; @@ -280,7 +282,6 @@ void mdev_remove_sysfs_files(struct mdev_device *mdev) { struct kobject *kobj = &mdev->dev.kobj; - sysfs_remove_files(kobj, mdev_device_attrs); sysfs_remove_link(kobj, "mdev_type"); sysfs_remove_link(mdev->type->devices_kobj, dev_name(&mdev->dev)); } From patchwork Mon Apr 26 20:00:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12224999 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=-16.0 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,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS 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 5589CC43462 for ; Mon, 26 Apr 2021 20:00:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F5D2613AC for ; Mon, 26 Apr 2021 20:00:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241763AbhDZUBF (ORCPT ); Mon, 26 Apr 2021 16:01:05 -0400 Received: from mail-dm6nam11on2085.outbound.protection.outlook.com ([40.107.223.85]:3982 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S241756AbhDZUBD (ORCPT ); Mon, 26 Apr 2021 16:01:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hSeiOf/Taw+QuQLMMjxHIzIDSQaSOkHDIzsfv7x+MUl+FG2hYk/WWAy6MBxwcmwftaeKLyntq7/xkGoUB5QTKcT/NrPLjAowGAt/lQbDhRV3/dphWaY1jVoumxv2VQj4U40Vgd1ZdLlONR+iIYcXtgYakMxf6dh7wc3eXP6HSO9C2uFcb9Iq1lkkS3EOZF0zGjlDW8yhuOsQzPtxQvUo2g+VZZKITlDTsD1UY8F00wQCDa49MGyh11hjMm0I5Q/dUvy3D4xhWTuyOuHiycqZf3O4daDuepaWnLvXFeGgbzGEBHQ6mQbeZ2ALhc+5GJzYmCk5nLuIBsd5C7ychourtA== 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=85d1GGi5lVbNNIETRv7G4mAPZ6QwjFv2EPtHrVvtDg0=; b=caRMrUJlxOp8JOQKbXZRqLVu1AxL6LKUdWTMOLxUHpKNj5ACHlpSBpf+ZDgyROmwOVySTl7UJ8jGSOC64cEAe+iDvcvDqkfHu++Rq1u7LPDBMIRAi0CouHitOyYhhkPQ9l677RkbxzgMpnDtCNRbT8LuLPteAFUq0eOVQF4dTMp8SG9FSjz6YNroelhsaxhldWslua9fb2ylqAShBpdX5D7xgBBlxLCefckz1hRMhedhcsm/fh1KWNOlNW+u8XmbhVf564eC8krqrtgAgGNhVtq9acA1kvLS9t/T53gK88kI/W+igHWZhs//Be6YVPnRypMp3xrXQPYx/EHnbOzI+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=85d1GGi5lVbNNIETRv7G4mAPZ6QwjFv2EPtHrVvtDg0=; b=XmYE2N0Kt2NcoOjKOE88FrotgL60JM9z3o7rvytwxE9e9lcVFfbWr2ZktUh5lrZKrzFoNXTD97iqH9qpuG7ttcMWq2rsMtdQwTOrHfPM6+NOaDGpSmoSPzApGoPzhYTUmr3hc/HgzuL5K0En8AeQ8VpoyEJKNTJWuwkc0iy5JbaRhwFnIJOfXPaqDZnP3TN+I5kXGFC/bFvH9xwPhODeUwRIUrfZsZd36bWoeBpTAKjhfTmTIxLWT1ZscUaWxjyDaWZMjmBLxtP0x3Bjx6bQmforLJzLQOTxA1hLPqCAbSPYkVEq5d+DqnMK7RmSiVrUMEI31gaeeqOCxqnpioEtAA== Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM5PR12MB1659.namprd12.prod.outlook.com (2603:10b6:4:11::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Mon, 26 Apr 2021 20:00:21 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.4065.026; Mon, 26 Apr 2021 20:00:21 +0000 From: Jason Gunthorpe To: kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Dan Williams , Daniel Vetter , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 13/13] vfio/mdev: Remove mdev drvdata Date: Mon, 26 Apr 2021 17:00:15 -0300 Message-Id: <13-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> In-Reply-To: <0-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: BL1PR13CA0412.namprd13.prod.outlook.com (2603:10b6:208:2c2::27) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by BL1PR13CA0412.namprd13.prod.outlook.com (2603:10b6:208:2c2::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.16 via Frontend Transport; Mon, 26 Apr 2021 20:00:18 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lb7Oy-00DFZn-7n; Mon, 26 Apr 2021 17:00:16 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fba8a87b-8eb1-4d40-1612-08d908edea5e X-MS-TrafficTypeDiagnostic: DM5PR12MB1659: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:741; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6fqAB9UdJU1X83Ix06I2SuvpErxdmMRPWfjNZPFSkogjGPiySbVcYNcp/WdyxlXm05Wm+xVqhf9kBFEQxzGCY+8wojwQ3lVMHhBeKbXsbdu5ey7//N749hpWoR+dEhMa37m5RDgfurMcKgT+5xdawBs+NfRcUU9VO0q3z4KhQI2aNgDfIUZHqPaK8GGngnmSZ3HXuKhA2fZWsK5GYFd4iRynKNMlFvAxzCMxyYOsghsMMsjLz/KfhcGMzQjiGKse2IC5nAJ8fCbCHH29AGnKFFbmaA3iihUJcYbT41UUMdL9z9pC59ebuiWqPLNQ1/HjrDoEvhD7ME1eNp0PJNjysgPyEUc+SRQ27+lHC/5TWDKAU4QLn1Si3zR/czovHjui5d72p2PrEDK9cy4emEgZTHEzM+kNSgcoW9Qbea1KNHbsGjUzEGWExDS7G5sYUNmOjEkErXskUozBjGXi7qm9exeA1hzaZqE7xDINDRJd4RwNmhtNErUJxxTDibhehbRZqT+RBQEN918KgbujDzTGY2ztNSxADEOnYN+ohcPTej38RkzibWCDlrvDTcuJJD0tw2z77gkLbZQ0ZoPKm5rC1w1eJzpZOj1FrNIGjCzmmEE= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(136003)(396003)(366004)(39860400002)(376002)(66946007)(36756003)(66556008)(66476007)(8676002)(2906002)(86362001)(6636002)(2616005)(8936002)(478600001)(426003)(83380400001)(5660300002)(4326008)(38100700002)(9786002)(107886003)(37006003)(9746002)(6862004)(186003)(316002)(54906003)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: fK0d5eY2IOujoOohcC1y5xlo/OjZf++BL3nXMSTU/hVhz6XKSqOg/67lJphB9m/BK56e9ZbHI+mCth+0qnmGuGNLQqP77FMBWZ5yN4HFnkYZ/mMlhci0l4UP9QmhsgRHjbSUNy2yaGuWnpNS/hVOtePs+CAIjXEc3Z7wYnnULmo/OkZpKvB94c0ESpLeC3ppzufmsBX0BxogqO4lRw5PIHCorcPRct+2TxPmv+0IxCbuVfUhCfKSslIGREZFhiSlD8lL1JcTwR05qxjqkudH66k+qRfg47r3HTitaFvswRqMaEM0lBZVgFx6blEyUHCnWI1LFCGQFtatMGT8EqbxLd1NOG+pSYCAGil5AECIMRnTlBYOtXUsaDy5Z93aIeKXakVfU8VmtvavVk83h3qkwQxsiVy62StciKHO7GQCWjOHmGrSBzLm0Kfy4dJcvC0M/KaRRNKvY4hkgUPqtS5yL4CPQA/MksEjUREOdxvujN/QZ4l27rpWeBMhd9DHxGa/qxZXWPtWUhuOUo/TzDDCzjpFA51E8lTLm4PaptPqcTSTs5KQzpZ8FdEjddN3R0BfFNDpIQsa+BrPbe/pyTX0ZONB3Rlb4VQNyO6WkXWMArmdgkfs1Cimx+a8edkKkUuUqzCmCiZiJgCsyVVP9hVMhqeNmohh9D2g1dvqDdDNUKEkouSEVSo4z7LQ+Us6y/kYlBfQdb5xhNlKYv9iejlUS5++dXSc+MNk+21yPS7pQeHgMjKErqX5HoJEJ3d7CAvL+yHu0ruRGvhpcU/NCgxgTXszW4Ff/PhcCWkoNBBdnU8SS9hzWX3iy585L686Xk3nqdZTxzbPDkb8pSkhG5I01aHXDT9yjiN9DaHHugNMXpDE0p4L+rBtS26qZxzIN67YXFa5g3S3fIkM7J8sDFoZIcdfqHATv0E1ElqSbI+IC7Z7FkfEC0dRWQ4CMC4jtdXkXem1PIPEmCIYlg25aFvoymrkuJKSiur/LY5X6JqDITAVSxb5rQD3wXssqHFccAJVNnaESRnqmvawJGH+n6gqBd5v6OBY3pQExwGN2cjhE5rs4eJtIB7kNHIqcbFBo8lD8Vca4l7yHr0+q44butY2IkS89amNhJJbqctzmVEr7rvg28IyFEaqn+Rt5nCgqsFBDKyPjY1lYJ3XoOKQghwWBSQmwkLkk4qLYxP0qy5JIfKgDuwcxmE7hjEi3y6Q3/9GSzS1M7/0jgxEVsARpBHZ3h4vJ3f4M18DT1YVQpbNva+1gGmDnqAkOJQ4MVFO3JwjTzwvoX8FaM7jjjgVrD/Q07J4zvBfcWZnzbqPRxWQWAcM7z0tCDj/1eEw3mMnRHN0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: fba8a87b-8eb1-4d40-1612-08d908edea5e X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2021 20:00:18.3600 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: p6P1Wa3IEdmf5D8EyBBKAdSNP6IT0aGVXAXenqOl/R7epzKyM2nyrfTiWMSqT+xd X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1659 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is no longer used, remove it. All usages were moved over to either use container_of() from a vfio_device or to use dev_drvdata() directly on the mdev. Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- include/linux/mdev.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/include/linux/mdev.h b/include/linux/mdev.h index af807c77c1e0f5..2c7267f1356d78 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -15,7 +15,6 @@ struct mdev_type; struct mdev_device { struct device dev; guid_t uuid; - void *driver_data; struct list_head next; struct mdev_type *type; struct device *iommu_device; @@ -87,14 +86,6 @@ struct mdev_driver { struct device_driver driver; }; -static inline void *mdev_get_drvdata(struct mdev_device *mdev) -{ - return mdev->driver_data; -} -static inline void mdev_set_drvdata(struct mdev_device *mdev, void *data) -{ - mdev->driver_data = data; -} static inline const guid_t *mdev_uuid(struct mdev_device *mdev) { return &mdev->uuid;