kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jike Song <jike.song@intel.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: Kirti Wankhede <kwankhede@nvidia.com>,
	pbonzini@redhat.com, kraxel@redhat.com, cjia@nvidia.com,
	qemu-devel@nongnu.org, kvm@vger.kernel.org, kevin.tian@intel.com,
	bjsdjshi@linux.vnet.ibm.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v9 01/12] vfio: Mediated device Core driver
Date: Fri, 21 Oct 2016 10:41:22 +0800	[thread overview]
Message-ID: <58098052.2080802@intel.com> (raw)
In-Reply-To: <20161020111231.6fbbd421@t450s.home>

On 10/21/2016 01:12 AM, Alex Williamson wrote:
> On Thu, 20 Oct 2016 15:23:53 +0800
> Jike Song <jike.song@intel.com> wrote:
> 
>> On 10/18/2016 05:22 AM, Kirti Wankhede wrote:
>>> diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
>>> new file mode 100644
>>> index 000000000000..7db5ec164aeb
>>> --- /dev/null
>>> +++ b/drivers/vfio/mdev/mdev_core.c
>>> @@ -0,0 +1,372 @@
>>> +/*
>>> + * Mediated device Core Driver
>>> + *
>>> + * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
>>> + *     Author: Neo Jia <cjia@nvidia.com>
>>> + *	       Kirti Wankhede <kwankhede@nvidia.com>
>>> + *
>>> + * This program is free software; you can redistribute it and/or modify
>>> + * it under the terms of the GNU General Public License version 2 as
>>> + * published by the Free Software Foundation.
>>> + */
>>> +
>>> +#include <linux/module.h>
>>> +#include <linux/device.h>
>>> +#include <linux/slab.h>
>>> +#include <linux/uuid.h>
>>> +#include <linux/sysfs.h>
>>> +#include <linux/mdev.h>
>>> +
>>> +#include "mdev_private.h"
>>> +
>>> +#define DRIVER_VERSION		"0.1"
>>> +#define DRIVER_AUTHOR		"NVIDIA Corporation"
>>> +#define DRIVER_DESC		"Mediated device Core Driver"
>>> +
>>> +static LIST_HEAD(parent_list);
>>> +static DEFINE_MUTEX(parent_list_lock);
>>> +static struct class_compat *mdev_bus_compat_class;
>>> +  
>>
>>> +
>>> +/*
>>> + * mdev_register_device : Register a device
>>> + * @dev: device structure representing parent device.
>>> + * @ops: Parent device operation structure to be registered.
>>> + *
>>> + * 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 parent_ops *ops)
>>> +{
>>> +	int ret = 0;
>>> +	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);
>>> +
>>> +	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");
>>> +
>>> +	list_add(&parent->next, &parent_list);
>>> +	mutex_unlock(&parent_list_lock);
>>> +
>>> +	dev_info(dev, "MDEV: Registered\n");
>>> +	return 0;
>>> +
>>> +add_dev_err:
>>> +	mutex_unlock(&parent_list_lock);
>>> +	put_device(dev);
>>> +	return ret;
>>> +}
>>> +EXPORT_SYMBOL(mdev_register_device);  
>>
>>> +static int __init mdev_init(void)
>>> +{
>>> +	int ret;
>>> +
>>> +	ret = mdev_bus_register();
>>> +	if (ret) {
>>> +		pr_err("Failed to register mdev bus\n");
>>> +		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.
>>> +	 */
>>> +	request_module_nowait("vfio_mdev");
>>> +
>>> +	return ret;
>>> +}
>>> +
>>> +static void __exit mdev_exit(void)
>>> +{
>>> +	class_compat_unregister(mdev_bus_compat_class);
>>> +	mdev_bus_unregister();
>>> +}
>>> +
>>> +module_init(mdev_init)
>>> +module_exit(mdev_exit)  
>>
>> Hi Kirti,
>>
>> There is a possible issue: mdev_bus_register is called from mdev_init,
>> a module_init, equal to device_initcall if builtin to vmlinux; however,
>> the vendor driver, say i915.ko for intel case, have to call
>> mdev_register_device from its module_init: at that time, mdev_init
>> is still not called.
>>
>> Not sure if this issue exists with nvidia.ko. Though in most cases we
>> are expecting users select mdev as a standalone module, we still won't
>> break builtin case.
>>
>>
>> Hi Alex, do you have any suggestion here?
> 
> To fully solve the problem of built-in drivers making use of the mdev
> infrastructure we'd need to make mdev itself builtin and possibly a
> subsystem that is initialized prior to device drivers.  Is that really
> necessary?  Even though i915.ko is often loaded as part of an
> initramfs, most systems still build it as a module.  I would expect
> that standard module dependencies will pull in the necessary mdev and
> vfio modules to make this work correctly.  I can't say that I'm
> prepared to make mdev be a subsystem as would be necessary for builtin
> drivers to make use of.  Perhaps if such a driver exists it could
> somehow do late binding with mdev.  i915 should certainly be tested as
> a builtin driver to make sure it doesn't fail with mdev support added.
> The kvm-vfio device (virt/kvm/vfio.c) makes use of symbol tricks to
> avoid hard dependencies between kvm and vfio, perhaps when builtin to
> the kernel, i915 could use something like that.  Thanks,

Fair enough, I'll use symbol_get to avoid the problem. Thanks!

--
Thanks,
Jike


  reply	other threads:[~2016-10-21  2:44 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-17 21:22 [PATCH v9 00/12] Add Mediated device support Kirti Wankhede
2016-10-17 21:22 ` [PATCH v9 01/12] vfio: Mediated device Core driver Kirti Wankhede
2016-10-18 23:16   ` Alex Williamson
2016-10-19 19:16     ` Kirti Wankhede
2016-10-19 22:20       ` Alex Williamson
2016-10-20  7:23   ` Jike Song
2016-10-20 17:12     ` Alex Williamson
2016-10-21  2:41       ` Jike Song [this message]
2016-10-27  5:56       ` Jike Song
2016-10-26  6:52   ` Tian, Kevin
2016-10-26 14:58     ` Kirti Wankhede
2016-10-17 21:22 ` [PATCH v9 02/12] vfio: VFIO based driver for Mediated devices Kirti Wankhede
2016-10-26  6:57   ` Tian, Kevin
2016-10-26 15:01     ` Kirti Wankhede
2016-10-17 21:22 ` [PATCH v9 03/12] vfio: Rearrange functions to get vfio_group from dev Kirti Wankhede
2016-10-19 17:26   ` Alex Williamson
2016-10-17 21:22 ` [PATCH v9 04/12] vfio iommu: Add support for mediated devices Kirti Wankhede
2016-10-19 21:02   ` Alex Williamson
2016-10-20 20:17     ` Kirti Wankhede
2016-10-24  2:32       ` Alex Williamson
2016-10-26  7:19         ` Tian, Kevin
2016-10-26 15:06           ` Kirti Wankhede
2016-10-26  7:53     ` Tian, Kevin
2016-10-26 15:16       ` Alex Williamson
2016-10-26  7:54     ` Tian, Kevin
2016-10-26 15:19       ` Alex Williamson
2016-10-21  7:49   ` Jike Song
2016-10-21 14:36     ` Alex Williamson
2016-10-24 10:35       ` Kirti Wankhede
2016-10-27  7:20   ` [Qemu-devel] " Alexey Kardashevskiy
2016-10-27 12:31     ` Kirti Wankhede
2016-10-27 14:30       ` Alex Williamson
2016-10-27 15:59         ` [Qemu-devel] " Kirti Wankhede
2016-10-28  2:18       ` Alexey Kardashevskiy
2016-11-01 14:01         ` Kirti Wankhede
2016-11-02  1:24           ` Alexey Kardashevskiy
2016-11-02  3:29             ` Kirti Wankhede
2016-11-02  4:09               ` Alexey Kardashevskiy
2016-11-02 12:21                 ` Jike Song
2016-11-02 12:41                   ` [Qemu-devel] " Kirti Wankhede
2016-11-02 13:00                     ` Jike Song
2016-11-02 13:18                       ` Kirti Wankhede
2016-11-02 13:35                         ` Jike Song
2016-11-03  4:29                         ` [Qemu-devel] " Alexey Kardashevskiy
2016-10-17 21:22 ` [PATCH v9 05/12] vfio: Introduce common function to add capabilities Kirti Wankhede
2016-10-20 19:24   ` Alex Williamson
2016-10-24 21:27     ` Kirti Wankhede
2016-10-24 21:39       ` Alex Williamson
2016-10-17 21:22 ` [PATCH v9 06/12] vfio_pci: Update vfio_pci to use vfio_info_add_capability() Kirti Wankhede
2016-10-20 19:24   ` Alex Williamson
2016-10-24 21:22     ` Kirti Wankhede
2016-10-24 21:37       ` Alex Williamson
2016-10-17 21:22 ` [PATCH v9 07/12] vfio: Introduce vfio_set_irqs_validate_and_prepare() Kirti Wankhede
2016-10-17 21:22 ` [PATCH v9 08/12] vfio_pci: Updated to use vfio_set_irqs_validate_and_prepare() Kirti Wankhede
2016-10-17 21:22 ` [PATCH v9 09/12] vfio_platform: " Kirti Wankhede
2016-10-17 21:22 ` [PATCH v9 10/12] vfio: Add function to get device_api string from vfio_device_info.flags Kirti Wankhede
2016-10-20 19:34   ` Alex Williamson
2016-10-20 20:29     ` Kirti Wankhede
2016-10-20 21:05       ` Alex Williamson
2016-10-20 21:14         ` Kirti Wankhede
2016-10-20 21:22           ` Alex Williamson
2016-10-21  3:00             ` Kirti Wankhede
2016-10-21  3:20               ` Alex Williamson
2016-10-17 21:22 ` [PATCH v9 11/12] docs: Add Documentation for Mediated devices Kirti Wankhede
2016-10-25 16:17   ` Alex Williamson
2016-10-17 21:22 ` [PATCH v9 12/12] docs: Sample driver to demonstrate how to use Mediated device framework Kirti Wankhede
2016-10-18  2:54   ` Dong Jia Shi
     [not found]   ` <20161018025411.GA22572@bjsdjshi@linux.vnet.ibm.com>
2016-10-18 17:17     ` Alex Williamson
2016-10-19 19:19       ` Kirti Wankhede
2016-10-17 21:41 ` [PATCH v9 00/12] Add Mediated device support Alex Williamson
2016-10-24  7:07 ` Jike Song
2016-12-05 17:44   ` Gerd Hoffmann
2016-12-06  2:24     ` Jike Song
2016-12-07 14:40       ` Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=58098052.2080802@intel.com \
    --to=jike.song@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=bjsdjshi@linux.vnet.ibm.com \
    --cc=cjia@nvidia.com \
    --cc=kevin.tian@intel.com \
    --cc=kraxel@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).