From: Jike Song <jike.song@intel.com>
To: Neo Jia <cjia@nvidia.com>
Cc: Kirti Wankhede <kwankhede@nvidia.com>,
alex.williamson@redhat.com, pbonzini@redhat.com,
kraxel@redhat.com, qemu-devel@nongnu.org, kvm@vger.kernel.org,
kevin.tian@intel.com, bjsdjshi@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [PATCH v7 1/4] vfio: Mediated device Core driver
Date: Fri, 09 Sep 2016 14:26:24 +0800 [thread overview]
Message-ID: <57D25610.8000801@intel.com> (raw)
In-Reply-To: <20160908093824.GA23397@nvidia.com>
On 09/08/2016 05:38 PM, Neo Jia wrote:
> On Thu, Sep 08, 2016 at 04:09:39PM +0800, Jike Song wrote:
>> On 08/25/2016 11:53 AM, Kirti Wankhede wrote:
>>> +
>>> +/**
>>> + * struct parent_ops - Structure to be registered for each parent device to
>>> + * register the device to mdev module.
>>> + *
>>> + * @owner: The module owner.
>>> + * @dev_attr_groups: Default attributes of the parent device.
>>> + * @mdev_attr_groups: Default attributes of the mediated device.
>>> + * @supported_config: Called to get information about supported types.
>>> + * @dev : device structure of parent device.
>>> + * @config: should return string listing supported config
>>> + * Returns integer: success (0) or error (< 0)
>>> + * @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
>>> + * @mdev_params: extra parameters required by parent
>>> + * device's driver.
>>> + * Returns integer: success (0) or error (< 0)
>>> + * @destroy: Called to free resources in parent device's driver for a
>>> + * a mediated device. It is mandatory to provide destroy
>>> + * ops.
>>> + * @mdev: mdev_device device structure which is being
>>> + * destroyed
>>> + * Returns integer: success (0) or error (< 0)
>>> + * If VMM is running and destroy() is called that means the
>>> + * mdev is being hotunpluged. Return error if VMM is
>>> + * running and driver doesn't support mediated device
>>> + * hotplug.
>>> + * @reset: Called to reset mediated device.
>>> + * @mdev: mdev_device device structure.
>>> + * Returns integer: success (0) or error (< 0)
>>> + * @set_online_status: Called to change to status of mediated device.
>>> + * @mdev: mediated device.
>>> + * @online: set true or false to make mdev device online or
>>> + * offline.
>>> + * Returns integer: success (0) or error (< 0)
>>> + * @get_online_status: Called to get online/offline status of mediated device
>>> + * @mdev: mediated device.
>>> + * @online: Returns status of mediated device.
>>> + * Returns integer: success (0) or error (< 0)
>>> + * @read: Read emulation callback
>>> + * @mdev: mediated device structure
>>> + * @buf: read buffer
>>> + * @count: number of bytes to read
>>> + * @pos: 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
>>> + * @pos: address.
>>> + * Retuns number on bytes written on success or error.
>>> + * @get_irq_info: Called to retrieve information about mediated device IRQ
>>> + * @mdev: mediated device structure
>>> + * @irq_info: VFIO IRQ flags and count.
>>> + * Returns integer: success (0) or error (< 0)
>>> + * @set_irqs: Called to send about interrupts configuration
>>> + * information that VMM sets.
>>> + * @mdev: mediated device structure
>>> + * @flags, index, start, count and *data : same as that of
>>> + * struct vfio_irq_set of VFIO_DEVICE_SET_IRQS API.
>>> + * @get_device_info: Called to get VFIO device information for a mediated
>>> + * device.
>>> + * @vfio_device_info: VFIO device info.
>>> + * Returns integer: success (0) or error (< 0)
>>> + * @get_region_info: Called to get VFIO region size and flags of mediated
>>> + * device.
>>> + * @mdev: mediated device structure
>>> + * @region_info: output, returns size and flags of
>>> + * requested region.
>>> + * @cap_type_id: returns id of capability.
>>> + * @cap_type: returns pointer to capability structure
>>> + * corresponding to capability id.
>>> + * Returns integer: success (0) or error (< 0)
>>> + *
>>> + * Parent device that support mediated device should be registered with mdev
>>> + * module with parent_ops structure.
>>> + */
>>> +
>>> +struct parent_ops {
>>> + struct module *owner;
>>> + const struct attribute_group **dev_attr_groups;
>>> + const struct attribute_group **mdev_attr_groups;
>>> +
>>> + int (*supported_config)(struct device *dev, char *config);
>>> + int (*create)(struct mdev_device *mdev, char *mdev_params);
>>> + int (*destroy)(struct mdev_device *mdev);
>>> + int (*reset)(struct mdev_device *mdev);
>>> + int (*set_online_status)(struct mdev_device *mdev, bool online);
>>> + int (*get_online_status)(struct mdev_device *mdev, bool *online);
>>> + ssize_t (*read)(struct mdev_device *mdev, char *buf, size_t count,
>>> + loff_t pos);
>>> + ssize_t (*write)(struct mdev_device *mdev, char *buf, size_t count,
>>> + loff_t pos);
>>> + int (*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma);
>>> + int (*get_irq_info)(struct mdev_device *mdev,
>>> + struct vfio_irq_info *irq_info);
>>> + int (*set_irqs)(struct mdev_device *mdev, uint32_t flags,
>>> + unsigned int index, unsigned int start,
>>> + unsigned int count, void *data);
>>> + int (*get_device_info)(struct mdev_device *mdev,
>>> + struct vfio_device_info *dev_info);
>>> + int (*get_region_info)(struct mdev_device *mdev,
>>> + struct vfio_region_info *region_info,
>>> + u16 *cap_type_id, void **cap_type);
>>> +};
>>
>> I have a strong objection here to such low-level interfaces, the interfaces
>> between vfio-mdev and vendor drivers should be as thin as possible, not imposing
>> any limitation to vendor drivers.
>
> Hi Jike,
>
> Welcome! :-)
Aha, thanks! :)
>
> Unfortunately, this is something I definitely can't agree with you.
>
Glad to see your opinion!
> We would like to capture the common code as much as possible without losing
> flexibilities, so each vendor driver writers won't have to duplicate them and we
> have something can be maintained publicly.
>
Yeah it is good to reduce the duplications among different vendor drivers,
but what do you think about the duplication between here and other bus drivers
like vfio-pci?
> If you are running into specific limitation with above callback interfaces,
> please show us the scenarios and we are very happy to look into that.
>
Though we don't actually test it upon this series (using high-level implementations
instead), I personally don't think there is a problem. However, this doesn't
necessarily mean it's sufficient.
>>
>> I saw that validate_map_request was removed from the ops and mmap was added.
>> That is pretty nice. Furthermore, if you add an ioctl here, you can also remove
>> get_device_info, get_irq_info, set_irqs, and get_region_info (and even "reset").
>> There are several benefits by doing this:
>
> The decision of moving validate_map_request is mainly because we are adding a lot of
> advanced logic which most vendor drivers don't require, since we are the only consumer
> of such logic, no need to put it in the public/shared module.
>
>>
>> - Balanced interfaces.
>> Like I replied in another mail, you won't have unbalanced interfaces.
>> You already have read, write and mmap in the ops, why not ioctl?
>
> Sorry, don't think "balanced" interface is a design criteria especially when
> simply pursuing the sake of "balanced or full-set" interface ends up lots
> duplicated code for vendor driver writers.
>
Please kindly have a look at my comment on patch 2/4, about how to check the
validity of "count".
>>
>> - Scalability.
>> You are intercepting vfio optional capabilities in the framework, but
>> how if vfio.ko, or vfio-pci.ko add a few new capabilities in the future?
>
> Exactly my point about the code sharing.
>
> If new cap is added inside vfio.ko or vfio-pci.ko, we can just add it into
> vfio_mdev.ko.
>
> Adding the code in one place is better to duplicate in multiple vendor drivers.
So after adding that, how many places will you have?
>>
>> - Abstraction.
>> Even placing common codes here can avoid code duplication, you still
>> have code duplicate with vfio-pci. Better to move common logic out of
>> vfio-pci and call them from mdev vendor drivers.
>
> Are you saying to avoid the code duplications between vfio-pci and vfio-mdev?
>
Exactly. I haven't check other bus-driver like vfio-platform, but even if only
having vfio-pci considered, there will be duplications.
>>
>> - Maintainability.
>> This is pretty obvious :)
>
> Definitely not, the burden is moving to the vendor driver side.
>
Moving to vendor side is not the target, as said above, this will probably cause
more abstraction and refactoring of existing vfio code.
> Again, Jike, I really want to enable you with the mediated framework we have been
> doing here. So it is probably easier for us to accommodate your need if you could
> follow the interfaces we have introduced and let us know if you have any specific
> issues.
I won't read this as that one is not welcome to comment as long as he met no
actual issue :)
--
Thanks,
Jike
>>> +
>>> +/*
>>> + * Parent Device
>>> + */
>>> +
>>> +struct parent_device {
>>> + struct device *dev;
>>> + const struct parent_ops *ops;
>>> +
>>> + /* internal */
>>> + struct kref ref;
>>> + struct list_head next;
>>> + struct list_head mdev_list;
>>> + struct mutex mdev_list_lock;
>>> + wait_queue_head_t release_done;
>>> +};
>>> +
>>> +/**
>>> + * struct mdev_driver - Mediated device driver
>>> + * @name: driver name
>>> + * @probe: called when new device created
>>> + * @remove: called when device removed
>>> + * @driver: device driver structure
>>> + *
>>> + **/
>>> +struct mdev_driver {
>>> + const char *name;
>>> + int (*probe)(struct device *dev);
>>> + void (*remove)(struct device *dev);
>>> + struct device_driver driver;
>>> +};
>>> +
>>> +static inline struct mdev_driver *to_mdev_driver(struct device_driver *drv)
>>> +{
>>> + return drv ? container_of(drv, struct mdev_driver, driver) : NULL;
>>> +}
>>> +
>>> +static inline struct mdev_device *to_mdev_device(struct device *dev)
>>> +{
>>> + return dev ? container_of(dev, struct mdev_device, dev) : NULL;
>>> +}
>>
>> These can be macros, like pci ones.
>>
>>> +
>>> +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;
>>> +}
>>> +
>>> +extern struct bus_type mdev_bus_type;
>>> +
>>> +#define dev_is_mdev(d) ((d)->bus == &mdev_bus_type)
>>> +
>>> +extern int mdev_register_device(struct device *dev,
>>> + const struct parent_ops *ops);
>>> +extern void mdev_unregister_device(struct device *dev);
>>> +
>>> +extern int mdev_register_driver(struct mdev_driver *drv, struct module *owner);
>>> +extern void mdev_unregister_driver(struct mdev_driver *drv);
>>> +
>>> +extern struct mdev_device *mdev_get_device(struct mdev_device *mdev);
>>> +extern void mdev_put_device(struct mdev_device *mdev);
>>> +
>>> +extern struct mdev_device *mdev_get_device_by_group(struct iommu_group *group);
>>> +
>>> +#endif /* MDEV_H */
>>>
>>
>> --
>> Thanks,
>> Jike
next prev parent reply other threads:[~2016-09-09 6:28 UTC|newest]
Thread overview: 95+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-25 3:53 [Qemu-devel] [PATCH v7 0/4] Add Mediated device support Kirti Wankhede
2016-08-25 3:53 ` [Qemu-devel] [PATCH v7 1/4] vfio: Mediated device Core driver Kirti Wankhede
2016-09-08 8:09 ` Jike Song
2016-09-08 9:38 ` Neo Jia
2016-09-09 6:26 ` Jike Song [this message]
2016-09-09 17:48 ` Kirti Wankhede
2016-09-09 18:42 ` Alex Williamson
2016-09-09 19:55 ` Kirti Wankhede
2016-09-12 5:10 ` Jike Song
2016-09-12 7:49 ` Kirti Wankhede
2016-09-12 15:53 ` Alex Williamson
2016-09-19 7:08 ` Jike Song
2016-09-19 17:29 ` Kirti Wankhede
2016-09-19 18:11 ` Alex Williamson
2016-09-19 20:09 ` Kirti Wankhede
2016-09-19 20:59 ` Alex Williamson
2016-09-20 12:48 ` Jike Song
2016-08-25 3:53 ` [Qemu-devel] [PATCH v7 2/4] vfio: VFIO driver for mediated devices Kirti Wankhede
2016-08-25 9:22 ` Dong Jia
2016-08-26 14:13 ` Kirti Wankhede
2016-09-08 2:38 ` Jike Song
2016-09-19 18:22 ` Kirti Wankhede
2016-09-19 18:36 ` Alex Williamson
2016-09-19 19:13 ` Kirti Wankhede
2016-09-19 20:03 ` Alex Williamson
2016-09-20 2:50 ` Jike Song
2016-09-20 16:24 ` Alex Williamson
2016-09-21 3:19 ` Jike Song
2016-09-21 4:51 ` Alex Williamson
2016-09-21 5:02 ` Jike Song
2016-09-08 2:45 ` Jike Song
2016-09-13 2:35 ` Jike Song
2016-09-20 5:48 ` Dong Jia Shi
2016-09-20 6:37 ` Jike Song
2016-09-20 12:53 ` Jike Song
2016-08-25 3:53 ` [Qemu-devel] [PATCH v7 3/4] vfio iommu: Add support " Kirti Wankhede
2016-08-25 7:29 ` Dong Jia
2016-08-26 13:50 ` Kirti Wankhede
2016-09-29 2:17 ` Jike Song
2016-09-29 15:06 ` Kirti Wankhede
2016-09-30 2:58 ` Jike Song
2016-09-30 3:10 ` Jike Song
2016-09-30 11:44 ` Kirti Wankhede
2016-10-08 7:09 ` Jike Song
2016-08-25 3:53 ` [Qemu-devel] [PATCH v7 4/4] docs: Add Documentation for Mediated devices Kirti Wankhede
2016-09-03 16:40 ` Kirti Wankhede
2016-08-30 16:16 ` [Qemu-devel] [PATCH v7 0/4] Add Mediated device support Alex Williamson
2016-08-31 6:12 ` Tian, Kevin
2016-08-31 7:04 ` Jike Song
2016-08-31 15:48 ` Alex Williamson
2016-09-01 4:09 ` Tian, Kevin
2016-09-01 4:10 ` Tian, Kevin
2016-09-01 18:22 ` Kirti Wankhede
2016-09-01 20:01 ` Alex Williamson
2016-09-02 6:17 ` Kirti Wankhede
2016-09-01 16:47 ` Michal Privoznik
2016-09-01 16:59 ` Alex Williamson
2016-09-02 4:48 ` Michal Privoznik
2016-09-02 5:21 ` Kirti Wankhede
2016-09-02 10:05 ` Paolo Bonzini
2016-09-02 17:15 ` Kirti Wankhede
2016-09-02 17:25 ` Paolo Bonzini
2016-09-02 18:33 ` Kirti Wankhede
2016-09-02 20:29 ` [Qemu-devel] [libvirt] " John Ferlan
2016-09-03 16:31 ` Kirti Wankhede
2016-09-06 17:54 ` Alex Williamson
2016-09-02 21:48 ` [Qemu-devel] " Paolo Bonzini
2016-09-03 11:56 ` [Qemu-devel] [libvirt] " John Ferlan
2016-09-03 13:07 ` Paolo Bonzini
2016-09-03 17:47 ` Kirti Wankhede
2016-09-03 16:34 ` [Qemu-devel] " Kirti Wankhede
2016-09-06 17:40 ` Alex Williamson
2016-09-06 19:35 ` Kirti Wankhede
2016-09-06 21:28 ` Alex Williamson
2016-09-07 8:22 ` Tian, Kevin
2016-09-07 16:00 ` Alex Williamson
2016-09-07 16:15 ` Kirti Wankhede
2016-09-07 16:44 ` Alex Williamson
2016-09-07 18:06 ` Kirti Wankhede
2016-09-07 22:13 ` Alex Williamson
2016-09-08 18:48 ` Kirti Wankhede
2016-09-08 20:51 ` Alex Williamson
2016-09-07 18:17 ` Neo Jia
2016-09-07 18:27 ` Daniel P. Berrange
2016-09-07 18:32 ` Neo Jia
2016-09-07 6:48 ` Tian, Kevin
2016-09-02 20:19 ` [Qemu-devel] [libvirt] " John Ferlan
2016-09-02 21:44 ` Paolo Bonzini
2016-09-02 23:57 ` Laine Stump
2016-09-03 16:49 ` Kirti Wankhede
2016-09-05 7:52 ` Paolo Bonzini
2016-09-03 11:57 ` John Ferlan
2016-09-05 7:54 ` Paolo Bonzini
2016-09-02 17:55 ` Laine Stump
2016-09-02 19:15 ` Alex Williamson
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=57D25610.8000801@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=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).