From patchwork Sat Oct 29 10:06:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirti Wankhede X-Patchwork-Id: 9403533 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6FB49601C0 for ; Sat, 29 Oct 2016 10:07:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50C112A1EB for ; Sat, 29 Oct 2016 10:07:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 342462A2EB; Sat, 29 Oct 2016 10:07:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_TVD_MIME_EPI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 126692A1EB for ; Sat, 29 Oct 2016 10:07:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932615AbcJ2KG4 (ORCPT ); Sat, 29 Oct 2016 06:06:56 -0400 Received: from hqemgate15.nvidia.com ([216.228.121.64]:6759 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752409AbcJ2KGy (ORCPT ); Sat, 29 Oct 2016 06:06:54 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com id ; Sat, 29 Oct 2016 03:16:24 -0700 Received: from HQMAIL107.nvidia.com ([172.20.13.39]) by hqpgpgate101.nvidia.com (PGP Universal service); Sat, 29 Oct 2016 03:06:52 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Sat, 29 Oct 2016 03:06:52 -0700 Received: from BGMAIL102.nvidia.com (10.25.59.11) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Sat, 29 Oct 2016 10:06:51 +0000 Received: from [10.25.75.127] (10.25.75.127) by bgmail102.nvidia.com (10.25.59.11) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Sat, 29 Oct 2016 10:06:45 +0000 Subject: Re: [PATCH v10 01/19] vfio: Mediated device Core driver To: Jike Song References: <1477517366-27871-1-git-send-email-kwankhede@nvidia.com> <1477517366-27871-2-git-send-email-kwankhede@nvidia.com> <581425F9.5070902@intel.com> CC: , , , , , , , , X-Nvconfidentiality: public From: Kirti Wankhede Message-ID: Date: Sat, 29 Oct 2016 15:36:36 +0530 MIME-Version: 1.0 In-Reply-To: <581425F9.5070902@intel.com> X-Originating-IP: [10.25.75.127] X-ClientProxiedBy: DRBGMAIL103.nvidia.com (10.18.16.22) To bgmail102.nvidia.com (10.25.59.11) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 10/29/2016 10:00 AM, Jike Song wrote: > On 10/27/2016 05:29 AM, Kirti Wankhede wrote: >> +int mdev_register_device(struct device *dev, const struct parent_ops *ops) >> +{ >> + int ret; >> + struct parent_device *parent; >> + >> + /* check for mandatory ops */ >> + if (!ops || !ops->create || !ops->remove || !ops->supported_type_groups) >> + return -EINVAL; >> + >> + dev = get_device(dev); >> + if (!dev) >> + return -EINVAL; >> + >> + mutex_lock(&parent_list_lock); >> + >> + /* Check for duplicate */ >> + parent = __find_parent_device(dev); >> + if (parent) { >> + ret = -EEXIST; >> + goto add_dev_err; >> + } >> + >> + parent = kzalloc(sizeof(*parent), GFP_KERNEL); >> + if (!parent) { >> + ret = -ENOMEM; >> + goto add_dev_err; >> + } >> + >> + kref_init(&parent->ref); >> + mutex_init(&parent->lock); >> + >> + parent->dev = dev; >> + parent->ops = ops; >> + >> + ret = parent_create_sysfs_files(parent); >> + if (ret) { >> + mutex_unlock(&parent_list_lock); >> + mdev_put_parent(parent); >> + return ret; >> + } >> + >> + ret = class_compat_create_link(mdev_bus_compat_class, dev, NULL); >> + if (ret) >> + dev_warn(dev, "Failed to create compatibility class link\n"); >> + > > Hi Kirti, > > Like I replied to previous version: > > http://www.spinics.net/lists/kvm/msg139331.html > Hi Jike, I saw your reply but by that time v10 version of patch series was out for review. > You can always check if mdev_bus_compat_class already registered > here, and register it if not yet. Same logic should be adopted to > mdev_init. > > Current implementation will simply panic if configured as builtin, > which is rare but far from impossible. > Can you verify attached patch with v10 patch-set whether this works for you? I'll incorporate this change in my next version. Thanks, Kirti From: Kirti Wankhede Date: Sat, 29 Oct 2016 15:12:01 +0530 Subject: [PATCH 1/1] Register mdev_bus class on first mdev_device_register Signed-off-by: Kirti Wankhede Signed-off-by: Neo Jia Reviewed-by: Jike Song --- drivers/vfio/mdev/mdev_core.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 9d8fa5c91c2e..54c59f325336 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -187,13 +187,18 @@ int mdev_register_device(struct device *dev, const struct parent_ops *ops) parent->dev = dev; parent->ops = ops; - ret = parent_create_sysfs_files(parent); - if (ret) { - mutex_unlock(&parent_list_lock); - mdev_put_parent(parent); - return ret; + if (!mdev_bus_compat_class) { + mdev_bus_compat_class = class_compat_register("mdev_bus"); + if (!mdev_bus_compat_class) { + ret = -ENOMEM; + goto add_dev_err; + } } + ret = parent_create_sysfs_files(parent); + if (ret) + goto add_dev_err; + ret = class_compat_create_link(mdev_bus_compat_class, dev, NULL); if (ret) dev_warn(dev, "Failed to create compatibility class link\n"); @@ -206,7 +211,10 @@ int mdev_register_device(struct device *dev, const struct parent_ops *ops) add_dev_err: mutex_unlock(&parent_list_lock); - put_device(dev); + if (parent) + mdev_put_parent(parent); + else + put_device(dev); return ret; } EXPORT_SYMBOL(mdev_register_device); @@ -354,12 +362,6 @@ static int __init mdev_init(void) return ret; } - mdev_bus_compat_class = class_compat_register("mdev_bus"); - if (!mdev_bus_compat_class) { - mdev_bus_unregister(); - return -ENOMEM; - } - /* * Attempt to load known vfio_mdev. This gives us a working environment * without the user needing to explicitly load vfio_mdev driver. @@ -371,7 +373,9 @@ static int __init mdev_init(void) static void __exit mdev_exit(void) { - class_compat_unregister(mdev_bus_compat_class); + if (mdev_bus_compat_class) + class_compat_unregister(mdev_bus_compat_class); + mdev_bus_unregister(); }