All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jike Song <jike.song@intel.com>
To: alex.williamson@redhat.com, kwankhede@nvidia.com, cjia@nvidia.com
Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org,
	bjsdjshi@linux.vnet.ibm.com, kevin.tian@intel.com,
	guangrong.xiao@linux.intel.com, zhenyuw@linux.intel.com,
	zhiyuan.lv@intel.com, jike.song@intel.com, pbonzini@redhat.com,
	kraxel@redhat.com
Subject: [RFC v2 4/4] docs: Add Documentation for Mediated devices
Date: Fri,  2 Sep 2016 16:16:12 +0800	[thread overview]
Message-ID: <1472804172-25542-5-git-send-email-jike.song@intel.com> (raw)
In-Reply-To: <1472804172-25542-1-git-send-email-jike.song@intel.com>

From: Kirti Wankhede <kwankhede@nvidia.com>

Add file Documentation/vfio-mediated-device.txt that include details of
mediated device framework.

Signed-off-by: Kirti Wankhede <kwankhede@nvidia.com>
Signed-off-by: Neo Jia <cjia@nvidia.com>
Signed-off-by: Jike Song <jike.song@intel.com>
---
 Documentation/vfio-mediated-device.txt | 203 +++++++++++++++++++++++++++++++++
 1 file changed, 203 insertions(+)
 create mode 100644 Documentation/vfio-mediated-device.txt

diff --git a/Documentation/vfio-mediated-device.txt b/Documentation/vfio-mediated-device.txt
new file mode 100644
index 0000000..39bdcd9
--- /dev/null
+++ b/Documentation/vfio-mediated-device.txt
@@ -0,0 +1,203 @@
+VFIO Mediated devices [1]
+-------------------------------------------------------------------------------
+
+There are more and more use cases/demands to virtualize the DMA devices which
+doesn't have SR_IOV capability built-in. To do this, drivers of different
+devices had to develop their own management interface and set of APIs and then
+integrate it to user space software. We've identified common requirements and
+unified management interface for such devices to make user space software
+integration easier.
+
+The VFIO driver framework provides unified APIs for direct device access. It is
+an IOMMU/device agnostic framework for exposing direct device access to
+user space, in a secure, IOMMU protected environment. This framework is
+used for multiple devices like GPUs, network adapters and compute accelerators.
+With direct device access, virtual machines or user space applications have
+direct access of physical device. This framework is reused for mediated devices.
+
+Mediated core driver provides a common interface for mediated device management
+that can be used by drivers of different devices. This module provides a generic
+interface to create/destroy mediated device, add/remove it to mediated bus
+driver, add/remove device to IOMMU group. It also provides an interface to
+register different types of bus drivers, for example, Mediated VFIO PCI driver
+is designed for mediated PCI devices and supports VFIO APIs. Similarly, driver
+can be designed to support any type of mediated device and added to this
+framework. Mediated bus driver add/delete mediated device to VFIO Group.
+
+Below is the high level block diagram, with NVIDIA, Intel and IBM devices
+as examples, since these are the devices which are going to actively use
+this module as of now.
+
+
+     +---------------+
+     |               |
+     | +-----------+ |
+     | |           | |
+     | |           | |
+     | |  mdev     | |    mdev_register_driver()     +---------------+
+     | |  bus      | |<------------------------------+               |
+     | |  driver   | |                               |               |
+     | |           | +------------------------------>| vfio_mdev.ko  |<-> VFIO user
+     | |           | |     probe()/remove()          |               |    APIs
+     | |           | |                               +---------------+
+     | |           | |
+     | +-----------+ |
+     |               |
+     |  MDEV CORE    |
+     |   MODULE      |
+     |   mdev.ko     |
+     |               |
+     | +-----------+ |  mdev_register_host_device()  +---------------+
+     | |           | +<------------------------------+               |
+     | |           | |                               |  nvidia.ko    |<-> physical
+     | |           | +------------------------------>+               |    device
+     | |           | |        callbacks              +---------------+
+     | |           | |
+     | | Physical  | |  mdev_register_host_device()  +---------------+
+     | | Device    | |<------------------------------+               |
+     | | Interface | |                               |  i915.ko      |<-> physical
+     | |           | +------------------------------>+               |    device
+     | |           | |        callbacks              +---------------+
+     | |           | |
+     | |           | |  mdev_register_host_device()  +---------------+
+     | |           | +<------------------------------+               |
+     | |           | |                               | ccw_device.ko |<-> physical
+     | |           | +------------------------------>+               |    device
+     | |           | |        callbacks              +---------------+
+     | +-----------+ |
+     +---------------+
+
+
+Registration Interfaces
+-------------------------------------------------------------------------------
+
+Mediated core driver provides two types of registration interfaces:
+
+1. Registration interface for mediated bus driver:
+-------------------------------------------------
+
+	/**
+	 * struct mdev_driver [2] - 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);
+		int (*online)(struct device *dev);
+		int (*offline)(struct device *dev);
+		struct device_driver driver;
+	};
+
+
+
+Mediated bus driver for mdev should use this interface to register and
+unregister with core driver respectively:
+
+extern int  mdev_register_driver(struct mdev_driver *drv, struct module *owner);
+extern void mdev_unregister_driver(struct mdev_driver *drv);
+
+Mediated bus driver is responsible to add/delete mediated devices to/from VFIO
+group when devices are bound and unbound to the driver.
+
+2. Physical device driver interface:
+-----------------------------------
+This interface [3] provides a set of APIs to manage physical device related work
+in its driver. APIs are:
+
+* hdev_attr_groups: attribute groups of the mdev host device.
+* mdev_attr_groups: attribute groups of the mediated device.
+* supported_config: to provide supported configuration list by the driver.
+* create: to allocate basic resources in driver for a mediated device.
+* destroy: to free resources in driver when mediated device is destroyed.
+* start: to start the mediated device
+* stop: to stop the mediated device
+* read : read emulation callback.
+* write: write emulation callback.
+* mmap: the mmap callback
+* ioctl: the ioctl callback
+
+Drivers should use this interface to register and unregister device to mdev core
+driver respectively:
+
+	struct mdev_host *mdev_register_host_device(struct device *pdev,
+					 const struct mdev_host_ops *ops);
+	void mdev_unregister_device(struct mdev_host *host);
+
+
+Mediated device management interface via sysfs
+-------------------------------------------------------------------------------
+This is the interface that allows user space software, like libvirt, to query
+and configure mediated device in a HW agnostic fashion. This management
+interface provide flexibility to underlying physical device's driver to support
+mediated device hotplug, multiple mediated devices per virtual machine, multiple
+mediated devices from different physical devices, etc.
+
+For echo physical device, there is a mdev host device created, it shows in sysfs:
+/sys/bus/pci/devices/0000:05:00.0/mdev-host/
+---------------------------------
+
+* mdev_supported_types: (read only)
+    List the current supported mediated device types and its details.
+
+* mdev_create: (write only)
+	Create a mediated device on target physical device.
+	Input syntax: <UUID:params>
+	where,
+		UUID: mediated device's UUID
+		params: extra parameters required by driver
+	Example:
+	# echo "12345678-1234-1234-1234-123456789abc" >
+				 /sys/bus/pci/devices/0000\:05\:00.0/mdev-host/mdev_create
+
+* mdev_destroy: (write only)
+	Destroy a mediated device on a target physical device.
+	Input syntax: <UUID>
+	where,
+		UUID: mediated device's UUID
+	Example:
+	# echo "12345678-1234-1234-1234-123456789abc" >
+			       /sys/bus/pci/devices/0000\:05\:00.0/mdev-host/mdev_destroy
+
+Under mdev sysfs directory:
+/sys/bus/pci/devices/0000:05:00.0/mdev-host/12345678-1234-1234-1234-123456789abc/
+----------------------------------
+
+* online: (read/write)
+	This shows and sets the online status of mdev.
+	Input syntax: <0|1>
+	To set mdev online, simply echo "1" to the online file; "0" to
+	offline the mdev.
+	Example:
+	# echo 1 > /sys/bus/pci/devices/0000\:05\:00.0/mdev-host/12345678-1234-1234-1234-123456789abc/online
+	# echo 0 > /sys/bus/pci/devices/0000\:05\:00.0/mdev-host/12345678-1234-1234-1234-123456789abc/online
+
+
+Translation APIs for Mediated device
+------------------------------------------------------------------------------
+
+Below APIs are provided for user pfn to host pfn translation in VFIO driver:
+
+extern long vfio_pin_pages(struct mdev_device *mdev, unsigned long *user_pfn,
+                           long npage, int prot, unsigned long *phys_pfn);
+
+extern long vfio_unpin_pages(struct mdev_device *mdev, unsigned long *pfn,
+                             long npage);
+
+These functions call back into the backend IOMMU module using two callbacks of
+struct vfio_iommu_driver_ops, pin_pages and unpin_pages [4]. Currently these are
+supported in TYPE1 IOMMU module. To enable the same for other IOMMU backend
+modules, such as PPC64 sPAPR module, they need to provide these two callback
+functions.
+
+References
+-------------------------------------------------------------------------------
+
+[1] See Documentation/vfio.txt for more information on VFIO.
+[2] struct mdev_driver in include/linux/mdev.h
+[3] struct mdev_host_ops in include/linux/mdev.h
+[4] struct vfio_iommu_driver_ops in include/linux/vfio.h
+
-- 
1.9.1


WARNING: multiple messages have this Message-ID (diff)
From: Jike Song <jike.song@intel.com>
To: alex.williamson@redhat.com, kwankhede@nvidia.com, cjia@nvidia.com
Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org,
	bjsdjshi@linux.vnet.ibm.com, kevin.tian@intel.com,
	guangrong.xiao@linux.intel.com, zhenyuw@linux.intel.com,
	zhiyuan.lv@intel.com, jike.song@intel.com, pbonzini@redhat.com,
	kraxel@redhat.com
Subject: [Qemu-devel] [RFC v2 4/4] docs: Add Documentation for Mediated devices
Date: Fri,  2 Sep 2016 16:16:12 +0800	[thread overview]
Message-ID: <1472804172-25542-5-git-send-email-jike.song@intel.com> (raw)
In-Reply-To: <1472804172-25542-1-git-send-email-jike.song@intel.com>

From: Kirti Wankhede <kwankhede@nvidia.com>

Add file Documentation/vfio-mediated-device.txt that include details of
mediated device framework.

Signed-off-by: Kirti Wankhede <kwankhede@nvidia.com>
Signed-off-by: Neo Jia <cjia@nvidia.com>
Signed-off-by: Jike Song <jike.song@intel.com>
---
 Documentation/vfio-mediated-device.txt | 203 +++++++++++++++++++++++++++++++++
 1 file changed, 203 insertions(+)
 create mode 100644 Documentation/vfio-mediated-device.txt

diff --git a/Documentation/vfio-mediated-device.txt b/Documentation/vfio-mediated-device.txt
new file mode 100644
index 0000000..39bdcd9
--- /dev/null
+++ b/Documentation/vfio-mediated-device.txt
@@ -0,0 +1,203 @@
+VFIO Mediated devices [1]
+-------------------------------------------------------------------------------
+
+There are more and more use cases/demands to virtualize the DMA devices which
+doesn't have SR_IOV capability built-in. To do this, drivers of different
+devices had to develop their own management interface and set of APIs and then
+integrate it to user space software. We've identified common requirements and
+unified management interface for such devices to make user space software
+integration easier.
+
+The VFIO driver framework provides unified APIs for direct device access. It is
+an IOMMU/device agnostic framework for exposing direct device access to
+user space, in a secure, IOMMU protected environment. This framework is
+used for multiple devices like GPUs, network adapters and compute accelerators.
+With direct device access, virtual machines or user space applications have
+direct access of physical device. This framework is reused for mediated devices.
+
+Mediated core driver provides a common interface for mediated device management
+that can be used by drivers of different devices. This module provides a generic
+interface to create/destroy mediated device, add/remove it to mediated bus
+driver, add/remove device to IOMMU group. It also provides an interface to
+register different types of bus drivers, for example, Mediated VFIO PCI driver
+is designed for mediated PCI devices and supports VFIO APIs. Similarly, driver
+can be designed to support any type of mediated device and added to this
+framework. Mediated bus driver add/delete mediated device to VFIO Group.
+
+Below is the high level block diagram, with NVIDIA, Intel and IBM devices
+as examples, since these are the devices which are going to actively use
+this module as of now.
+
+
+     +---------------+
+     |               |
+     | +-----------+ |
+     | |           | |
+     | |           | |
+     | |  mdev     | |    mdev_register_driver()     +---------------+
+     | |  bus      | |<------------------------------+               |
+     | |  driver   | |                               |               |
+     | |           | +------------------------------>| vfio_mdev.ko  |<-> VFIO user
+     | |           | |     probe()/remove()          |               |    APIs
+     | |           | |                               +---------------+
+     | |           | |
+     | +-----------+ |
+     |               |
+     |  MDEV CORE    |
+     |   MODULE      |
+     |   mdev.ko     |
+     |               |
+     | +-----------+ |  mdev_register_host_device()  +---------------+
+     | |           | +<------------------------------+               |
+     | |           | |                               |  nvidia.ko    |<-> physical
+     | |           | +------------------------------>+               |    device
+     | |           | |        callbacks              +---------------+
+     | |           | |
+     | | Physical  | |  mdev_register_host_device()  +---------------+
+     | | Device    | |<------------------------------+               |
+     | | Interface | |                               |  i915.ko      |<-> physical
+     | |           | +------------------------------>+               |    device
+     | |           | |        callbacks              +---------------+
+     | |           | |
+     | |           | |  mdev_register_host_device()  +---------------+
+     | |           | +<------------------------------+               |
+     | |           | |                               | ccw_device.ko |<-> physical
+     | |           | +------------------------------>+               |    device
+     | |           | |        callbacks              +---------------+
+     | +-----------+ |
+     +---------------+
+
+
+Registration Interfaces
+-------------------------------------------------------------------------------
+
+Mediated core driver provides two types of registration interfaces:
+
+1. Registration interface for mediated bus driver:
+-------------------------------------------------
+
+	/**
+	 * struct mdev_driver [2] - 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);
+		int (*online)(struct device *dev);
+		int (*offline)(struct device *dev);
+		struct device_driver driver;
+	};
+
+
+
+Mediated bus driver for mdev should use this interface to register and
+unregister with core driver respectively:
+
+extern int  mdev_register_driver(struct mdev_driver *drv, struct module *owner);
+extern void mdev_unregister_driver(struct mdev_driver *drv);
+
+Mediated bus driver is responsible to add/delete mediated devices to/from VFIO
+group when devices are bound and unbound to the driver.
+
+2. Physical device driver interface:
+-----------------------------------
+This interface [3] provides a set of APIs to manage physical device related work
+in its driver. APIs are:
+
+* hdev_attr_groups: attribute groups of the mdev host device.
+* mdev_attr_groups: attribute groups of the mediated device.
+* supported_config: to provide supported configuration list by the driver.
+* create: to allocate basic resources in driver for a mediated device.
+* destroy: to free resources in driver when mediated device is destroyed.
+* start: to start the mediated device
+* stop: to stop the mediated device
+* read : read emulation callback.
+* write: write emulation callback.
+* mmap: the mmap callback
+* ioctl: the ioctl callback
+
+Drivers should use this interface to register and unregister device to mdev core
+driver respectively:
+
+	struct mdev_host *mdev_register_host_device(struct device *pdev,
+					 const struct mdev_host_ops *ops);
+	void mdev_unregister_device(struct mdev_host *host);
+
+
+Mediated device management interface via sysfs
+-------------------------------------------------------------------------------
+This is the interface that allows user space software, like libvirt, to query
+and configure mediated device in a HW agnostic fashion. This management
+interface provide flexibility to underlying physical device's driver to support
+mediated device hotplug, multiple mediated devices per virtual machine, multiple
+mediated devices from different physical devices, etc.
+
+For echo physical device, there is a mdev host device created, it shows in sysfs:
+/sys/bus/pci/devices/0000:05:00.0/mdev-host/
+---------------------------------
+
+* mdev_supported_types: (read only)
+    List the current supported mediated device types and its details.
+
+* mdev_create: (write only)
+	Create a mediated device on target physical device.
+	Input syntax: <UUID:params>
+	where,
+		UUID: mediated device's UUID
+		params: extra parameters required by driver
+	Example:
+	# echo "12345678-1234-1234-1234-123456789abc" >
+				 /sys/bus/pci/devices/0000\:05\:00.0/mdev-host/mdev_create
+
+* mdev_destroy: (write only)
+	Destroy a mediated device on a target physical device.
+	Input syntax: <UUID>
+	where,
+		UUID: mediated device's UUID
+	Example:
+	# echo "12345678-1234-1234-1234-123456789abc" >
+			       /sys/bus/pci/devices/0000\:05\:00.0/mdev-host/mdev_destroy
+
+Under mdev sysfs directory:
+/sys/bus/pci/devices/0000:05:00.0/mdev-host/12345678-1234-1234-1234-123456789abc/
+----------------------------------
+
+* online: (read/write)
+	This shows and sets the online status of mdev.
+	Input syntax: <0|1>
+	To set mdev online, simply echo "1" to the online file; "0" to
+	offline the mdev.
+	Example:
+	# echo 1 > /sys/bus/pci/devices/0000\:05\:00.0/mdev-host/12345678-1234-1234-1234-123456789abc/online
+	# echo 0 > /sys/bus/pci/devices/0000\:05\:00.0/mdev-host/12345678-1234-1234-1234-123456789abc/online
+
+
+Translation APIs for Mediated device
+------------------------------------------------------------------------------
+
+Below APIs are provided for user pfn to host pfn translation in VFIO driver:
+
+extern long vfio_pin_pages(struct mdev_device *mdev, unsigned long *user_pfn,
+                           long npage, int prot, unsigned long *phys_pfn);
+
+extern long vfio_unpin_pages(struct mdev_device *mdev, unsigned long *pfn,
+                             long npage);
+
+These functions call back into the backend IOMMU module using two callbacks of
+struct vfio_iommu_driver_ops, pin_pages and unpin_pages [4]. Currently these are
+supported in TYPE1 IOMMU module. To enable the same for other IOMMU backend
+modules, such as PPC64 sPAPR module, they need to provide these two callback
+functions.
+
+References
+-------------------------------------------------------------------------------
+
+[1] See Documentation/vfio.txt for more information on VFIO.
+[2] struct mdev_driver in include/linux/mdev.h
+[3] struct mdev_host_ops in include/linux/mdev.h
+[4] struct vfio_iommu_driver_ops in include/linux/vfio.h
+
-- 
1.9.1

  parent reply	other threads:[~2016-09-02  8:25 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-02  8:16 [RFC v2 0/4] adding mdev bus and vfio support Jike Song
2016-09-02  8:16 ` [Qemu-devel] " Jike Song
2016-09-02  8:16 ` [RFC v2 1/4] Mediated device Core driver Jike Song
2016-09-02  8:16   ` [Qemu-devel] " Jike Song
2016-09-02  8:16 ` [RFC v2 2/4] vfio: VFIO bus driver for MDEV devices Jike Song
2016-09-02  8:16   ` [Qemu-devel] " Jike Song
2016-09-02  8:16 ` [RFC v2 3/4] vfio iommu: Add support for mediated devices Jike Song
2016-09-02  8:16   ` [Qemu-devel] " Jike Song
2016-09-02  8:16 ` Jike Song [this message]
2016-09-02  8:16   ` [Qemu-devel] [RFC v2 4/4] docs: Add Documentation for Mediated devices Jike Song
2016-09-02 22:09   ` Eric Blake
2016-09-02 22:09     ` Eric Blake
2016-09-02 23:30     ` Neo Jia
2016-09-02 23:30       ` Neo Jia
2016-09-02 15:03 ` [RFC v2 0/4] adding mdev bus and vfio support Alex Williamson
2016-09-02 15:03   ` [Qemu-devel] " Alex Williamson
2016-09-02 20:05   ` Neo Jia
2016-09-02 20:05     ` [Qemu-devel] " Neo Jia
2016-09-07  2:22   ` Jike Song
2016-09-07  2:22     ` [Qemu-devel] " Jike Song
2016-09-07  3:38     ` Neo Jia
2016-09-07  3:38       ` [Qemu-devel] " Neo Jia
2016-09-07  6:42       ` Jike Song
2016-09-07  6:42         ` [Qemu-devel] " Jike Song
2016-09-07 16:56         ` Alex Williamson
2016-09-07 16:56           ` [Qemu-devel] " Alex Williamson
2016-09-08  8:00           ` Jike Song
2016-09-08  8:00             ` [Qemu-devel] " Jike Song

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=1472804172-25542-5-git-send-email-jike.song@intel.com \
    --to=jike.song@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=bjsdjshi@linux.vnet.ibm.com \
    --cc=cjia@nvidia.com \
    --cc=guangrong.xiao@linux.intel.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 \
    --cc=zhenyuw@linux.intel.com \
    --cc=zhiyuan.lv@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.