Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1632738 > unrolled thread
| Started by | Xiaoguang Chen <xiaoguang.chen@intel.com> |
|---|---|
| First post | 2017-04-28 11:50 +0200 |
| Last post | 2017-05-12 19:10 +0200 |
| Articles | 20 on this page of 30 — 4 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Xiaoguang Chen <xiaoguang.chen@intel.com> - 2017-04-28 11:50 +0200
Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Gerd Hoffmann <kraxel@redhat.com> - 2017-05-02 12:00 +0200
RE: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf "Chen, Xiaoguang" <xiaoguang.chen@intel.com> - 2017-05-03 03:50 +0200
RE: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf "Chen, Xiaoguang" <xiaoguang.chen@intel.com> - 2017-05-04 05:20 +0200
Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Alex Williamson <alex.williamson@redhat.com> - 2017-05-04 18:10 +0200
Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Gerd Hoffmann <kraxel@redhat.com> - 2017-05-05 09:00 +0200
Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Alex Williamson <alex.williamson@redhat.com> - 2017-05-05 17:20 +0200
RE: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf "Chen, Xiaoguang" <xiaoguang.chen@intel.com> - 2017-05-11 10:50 +0200
Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Gerd Hoffmann <kraxel@redhat.com> - 2017-05-11 15:30 +0200
Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Alex Williamson <alex.williamson@redhat.com> - 2017-05-11 17:50 +0200
RE: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf "Chen, Xiaoguang" <xiaoguang.chen@intel.com> - 2017-05-12 04:20 +0200
Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Alex Williamson <alex.williamson@redhat.com> - 2017-05-12 05:00 +0200
RE: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf "Chen, Xiaoguang" <xiaoguang.chen@intel.com> - 2017-05-12 06:00 +0200
Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Gerd Hoffmann <kraxel@redhat.com> - 2017-05-12 11:20 +0200
Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Alex Williamson <alex.williamson@redhat.com> - 2017-05-12 18:50 +0200
RE: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf "Chen, Xiaoguang" <xiaoguang.chen@intel.com> - 2017-05-15 05:40 +0200
Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Alex Williamson <alex.williamson@redhat.com> - 2017-05-15 19:50 +0200
RE: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf "Chen, Xiaoguang" <xiaoguang.chen@intel.com> - 2017-05-16 12:20 +0200
Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Alex Williamson <alex.williamson@redhat.com> - 2017-05-17 23:50 +0200
RE: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf "Chen, Xiaoguang" <xiaoguang.chen@intel.com> - 2017-05-18 04:00 +0200
Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Alex Williamson <alex.williamson@redhat.com> - 2017-05-18 17:00 +0200
RE: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf "Chen, Xiaoguang" <xiaoguang.chen@intel.com> - 2017-05-19 08:30 +0200
Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Gerd Hoffmann <kraxel@redhat.com> - 2017-05-19 10:10 +0200
RE: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf "Chen, Xiaoguang" <xiaoguang.chen@intel.com> - 2017-05-19 10:20 +0200
Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Gerd Hoffmann <kraxel@redhat.com> - 2017-05-19 11:00 +0200
RE: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf "Chen, Xiaoguang" <xiaoguang.chen@intel.com> - 2017-05-19 11:20 +0200
Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Gerd Hoffmann <kraxel@redhat.com> - 2017-05-19 13:00 +0200
Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Gerd Hoffmann <kraxel@redhat.com> - 2017-05-18 08:30 +0200
RE: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf "Chen, Xiaoguang" <xiaoguang.chen@intel.com> - 2017-05-12 09:00 +0200
Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf Alex Williamson <alex.williamson@redhat.com> - 2017-05-12 19:10 +0200
Page 1 of 2 [1] 2 Next page →
| From | Xiaoguang Chen <xiaoguang.chen@intel.com> |
|---|---|
| Date | 2017-04-28 11:50 +0200 |
| Subject | [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf |
| Message-ID | <tBaHf-5yJ-5@gated-at.bofh.it> |
GVT-g will create an anonymous fd and a vfio device region to deliver
the fd to QEMU.
QEMU can do ioctl using this fd to query/generate dmabuf on an intel vgpu.
Signed-off-by: Xiaoguang Chen <xiaoguang.chen@intel.com>
---
drivers/gpu/drm/i915/gvt/gvt.c | 2 +
drivers/gpu/drm/i915/gvt/gvt.h | 2 +
drivers/gpu/drm/i915/gvt/kvmgt.c | 109 +++++++++++++++++++++++++++++++++++++++
include/uapi/linux/vfio.h | 1 +
4 files changed, 114 insertions(+)
diff --git a/drivers/gpu/drm/i915/gvt/gvt.c b/drivers/gpu/drm/i915/gvt/gvt.c
index 7dea5e5..c266d31 100644
--- a/drivers/gpu/drm/i915/gvt/gvt.c
+++ b/drivers/gpu/drm/i915/gvt/gvt.c
@@ -54,6 +54,8 @@
.vgpu_reset = intel_gvt_reset_vgpu,
.vgpu_activate = intel_gvt_activate_vgpu,
.vgpu_deactivate = intel_gvt_deactivate_vgpu,
+ .vgpu_query_dmabuf = intel_vgpu_query_dmabuf,
+ .vgpu_generate_dmabuf = intel_vgpu_generate_dmabuf,
};
/**
diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h
index 763a8c5..2733a69 100644
--- a/drivers/gpu/drm/i915/gvt/gvt.h
+++ b/drivers/gpu/drm/i915/gvt/gvt.h
@@ -467,6 +467,8 @@ struct intel_gvt_ops {
void (*vgpu_reset)(struct intel_vgpu *);
void (*vgpu_activate)(struct intel_vgpu *);
void (*vgpu_deactivate)(struct intel_vgpu *);
+ int (*vgpu_query_dmabuf)(struct intel_vgpu *, void *);
+ int (*vgpu_generate_dmabuf)(struct intel_vgpu *, void *);
};
diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
index 389f072..beb5356 100644
--- a/drivers/gpu/drm/i915/gvt/kvmgt.c
+++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
@@ -41,6 +41,7 @@
#include <linux/kvm_host.h>
#include <linux/vfio.h>
#include <linux/mdev.h>
+#include <linux/anon_inodes.h>
#include "i915_drv.h"
#include "gvt.h"
@@ -524,6 +525,106 @@ static int intel_vgpu_reg_init_opregion(struct intel_vgpu *vgpu)
return ret;
}
+static int intel_vgpu_gvtg_mmap(struct file *file, struct vm_area_struct *vma)
+{
+ WARN_ON(1);
+
+ return 0;
+}
+
+static int intel_vgpu_gvtg_release(struct inode *inode, struct file *filp)
+{
+ return 0;
+}
+
+static long intel_vgpu_gvtg_ioctl(struct file *filp,
+ unsigned int ioctl, unsigned long arg)
+{
+ struct intel_vgpu *vgpu = filp->private_data;
+ int minsz;
+ struct intel_vgpu_dmabuf dmabuf;
+ int ret;
+
+ minsz = offsetofend(struct intel_vgpu_dmabuf, y_pos);
+ if (copy_from_user(&dmabuf, (void __user *)arg, minsz))
+ return -EFAULT;
+ if (ioctl == INTEL_VGPU_QUERY_DMABUF)
+ ret = intel_gvt_ops->vgpu_query_dmabuf(vgpu, &dmabuf);
+ else if (ioctl == INTEL_VGPU_GENERATE_DMABUF)
+ ret = intel_gvt_ops->vgpu_generate_dmabuf(vgpu, &dmabuf);
+ else {
+ gvt_vgpu_err("unsupported dmabuf operation\n");
+ return -EINVAL;
+ }
+
+ if (ret != 0) {
+ gvt_vgpu_err("gvt-g get dmabuf failed:%d\n", ret);
+ return -EINVAL;
+ }
+
+ return copy_to_user((void __user *)arg, &dmabuf, minsz) ? -EFAULT : 0;
+}
+
+static const struct file_operations intel_vgpu_gvtg_ops = {
+ .release = intel_vgpu_gvtg_release,
+ .unlocked_ioctl = intel_vgpu_gvtg_ioctl,
+ .mmap = intel_vgpu_gvtg_mmap,
+ .llseek = noop_llseek,
+};
+
+static size_t intel_vgpu_reg_rw_gvtg(struct intel_vgpu *vgpu, char *buf,
+ size_t count, loff_t *ppos, bool iswrite)
+{
+ unsigned int i = VFIO_PCI_OFFSET_TO_INDEX(*ppos) -
+ VFIO_PCI_NUM_REGIONS;
+ loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
+ int fd;
+
+ if (pos >= vgpu->vdev.region[i].size || iswrite) {
+ gvt_vgpu_err("invalid op or offset for Intel vgpu fd region\n");
+ return -EINVAL;
+ }
+
+ fd = anon_inode_getfd("gvtg", &intel_vgpu_gvtg_ops, vgpu,
+ O_RDWR | O_CLOEXEC);
+ if (fd < 0) {
+ gvt_vgpu_err("create intel vgpu fd failed:%d\n", fd);
+ return -EINVAL;
+ }
+
+ count = min(count, (size_t)(vgpu->vdev.region[i].size - pos));
+ memcpy(buf, &fd, count);
+
+ return count;
+}
+
+static void intel_vgpu_reg_release_gvtg(struct intel_vgpu *vgpu,
+ struct vfio_region *region)
+{
+}
+
+static const struct intel_vgpu_regops intel_vgpu_regops_gvtg = {
+ .rw = intel_vgpu_reg_rw_gvtg,
+ .release = intel_vgpu_reg_release_gvtg,
+};
+
+static int intel_vgpu_reg_init_gvtg(struct intel_vgpu *vgpu)
+{
+ int ret;
+
+ ret = intel_vgpu_register_reg(vgpu,
+ PCI_VENDOR_ID_INTEL | VFIO_REGION_TYPE_PCI_VENDOR_TYPE,
+ VFIO_REGION_SUBTYPE_INTEL_IGD_GVTG,
+ &intel_vgpu_regops_gvtg, sizeof(int),
+ VFIO_REGION_INFO_FLAG_READ, NULL);
+ if (ret) {
+ gvt_vgpu_err("failed to register gvtg region:%d\n", ret);
+ return ret;
+ }
+
+ return ret;
+}
+
static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
{
struct intel_vgpu *vgpu = NULL;
@@ -564,6 +665,14 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
gvt_dbg_core("create OpRegion succeeded for mdev:%s\n",
dev_name(mdev_dev(mdev)));
+ ret = intel_vgpu_reg_init_gvtg(vgpu);
+ if (ret) {
+ gvt_vgpu_err("create gvtg region failed\n");
+ goto out;
+ }
+ gvt_dbg_core("create gvtg region succeeded for mdev:%s\n",
+ dev_name(mdev_dev(mdev)));
+
gvt_dbg_core("intel_vgpu_create succeeded for mdev: %s\n",
dev_name(mdev_dev(mdev)));
ret = 0;
diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
index 519eff3..96d2c58 100644
--- a/include/uapi/linux/vfio.h
+++ b/include/uapi/linux/vfio.h
@@ -297,6 +297,7 @@ struct vfio_region_info_cap_type {
#define VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION (1)
#define VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG (2)
#define VFIO_REGION_SUBTYPE_INTEL_IGD_LPC_CFG (3)
+#define VFIO_REGION_SUBTYPE_INTEL_IGD_GVTG (4)
/**
* VFIO_DEVICE_GET_IRQ_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 9,
--
1.9.1
[toc] | [next] | [standalone]
| From | Gerd Hoffmann <kraxel@redhat.com> |
|---|---|
| Date | 2017-05-02 12:00 +0200 |
| Message-ID | <tCCL7-4Uk-3@gated-at.bofh.it> |
| In reply to | #1632738 |
On Fr, 2017-04-28 at 17:35 +0800, Xiaoguang Chen wrote:
> +static size_t intel_vgpu_reg_rw_gvtg(struct intel_vgpu *vgpu, char
> *buf,
> + size_t count, loff_t *ppos, bool iswrite)
> +{
> + unsigned int i = VFIO_PCI_OFFSET_TO_INDEX(*ppos) -
> + VFIO_PCI_NUM_REGIONS;
> + loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
> + int fd;
> +
> + if (pos >= vgpu->vdev.region[i].size || iswrite) {
> + gvt_vgpu_err("invalid op or offset for Intel vgpu fd
> region\n");
> + return -EINVAL;
> + }
> +
> + fd = anon_inode_getfd("gvtg", &intel_vgpu_gvtg_ops, vgpu,
> + O_RDWR | O_CLOEXEC);
> + if (fd < 0) {
> + gvt_vgpu_err("create intel vgpu fd failed:%d\n", fd);
> + return -EINVAL;
> + }
> +
> + count = min(count, (size_t)(vgpu->vdev.region[i].size - pos));
> + memcpy(buf, &fd, count);
> +
> + return count;
> +}
Hmm, that looks like a rather strange way to return a file descriptor.
What is the reason to not use ioctls on the vfio file handle, like older
version of these patches did?
cheers,
Gerd
[toc] | [prev] | [next] | [standalone]
| From | "Chen, Xiaoguang" <xiaoguang.chen@intel.com> |
|---|---|
| Date | 2017-05-03 03:50 +0200 |
| Message-ID | <tCRAt-68i-3@gated-at.bofh.it> |
| In reply to | #1634306 |
>-----Original Message-----
>From: Gerd Hoffmann [mailto:kraxel@redhat.com]
>Sent: Tuesday, May 02, 2017 5:51 PM
>To: Chen, Xiaoguang <xiaoguang.chen@intel.com>
>Cc: alex.williamson@redhat.com; intel-gfx@lists.freedesktop.org; intel-gvt-
>dev@lists.freedesktop.org; Wang, Zhi A <zhi.a.wang@intel.com>;
>zhenyuw@linux.intel.com; linux-kernel@vger.kernel.org; Lv, Zhiyuan
><zhiyuan.lv@intel.com>; Tian, Kevin <kevin.tian@intel.com>
>Subject: Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf
>
>On Fr, 2017-04-28 at 17:35 +0800, Xiaoguang Chen wrote:
>> +static size_t intel_vgpu_reg_rw_gvtg(struct intel_vgpu *vgpu, char
>> *buf,
>> + size_t count, loff_t *ppos, bool iswrite) {
>> + unsigned int i = VFIO_PCI_OFFSET_TO_INDEX(*ppos) -
>> + VFIO_PCI_NUM_REGIONS;
>> + loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
>> + int fd;
>> +
>> + if (pos >= vgpu->vdev.region[i].size || iswrite) {
>> + gvt_vgpu_err("invalid op or offset for Intel vgpu fd
>> region\n");
>> + return -EINVAL;
>> + }
>> +
>> + fd = anon_inode_getfd("gvtg", &intel_vgpu_gvtg_ops, vgpu,
>> + O_RDWR | O_CLOEXEC);
>> + if (fd < 0) {
>> + gvt_vgpu_err("create intel vgpu fd failed:%d\n", fd);
>> + return -EINVAL;
>> + }
>> +
>> + count = min(count, (size_t)(vgpu->vdev.region[i].size - pos));
>> + memcpy(buf, &fd, count);
>> +
>> + return count;
>> +}
>
>Hmm, that looks like a rather strange way to return a file descriptor.
>
>What is the reason to not use ioctls on the vfio file handle, like older version of
>these patches did?
If I understood correctly that Alex prefer not to change the ioctls on the vfio file handle like the old version.
So I used this way the smallest change to general vfio framework only adding a subregion definition.
>
>cheers,
> Gerd
[toc] | [prev] | [next] | [standalone]
| From | "Chen, Xiaoguang" <xiaoguang.chen@intel.com> |
|---|---|
| Date | 2017-05-04 05:20 +0200 |
| Message-ID | <tDft7-6bj-7@gated-at.bofh.it> |
| In reply to | #1634692 |
Hi Alex, do you have any comments for this interface?
>-----Original Message-----
>From: intel-gvt-dev [mailto:intel-gvt-dev-bounces@lists.freedesktop.org] On
>Behalf Of Chen, Xiaoguang
>Sent: Wednesday, May 03, 2017 9:39 AM
>To: Gerd Hoffmann <kraxel@redhat.com>
>Cc: Tian, Kevin <kevin.tian@intel.com>; intel-gfx@lists.freedesktop.org; linux-
>kernel@vger.kernel.org; zhenyuw@linux.intel.com; alex.williamson@redhat.com;
>Lv, Zhiyuan <zhiyuan.lv@intel.com>; intel-gvt-dev@lists.freedesktop.org; Wang,
>Zhi A <zhi.a.wang@intel.com>
>Subject: RE: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf
>
>
>
>>-----Original Message-----
>>From: Gerd Hoffmann [mailto:kraxel@redhat.com]
>>Sent: Tuesday, May 02, 2017 5:51 PM
>>To: Chen, Xiaoguang <xiaoguang.chen@intel.com>
>>Cc: alex.williamson@redhat.com; intel-gfx@lists.freedesktop.org;
>>intel-gvt- dev@lists.freedesktop.org; Wang, Zhi A
>><zhi.a.wang@intel.com>; zhenyuw@linux.intel.com;
>>linux-kernel@vger.kernel.org; Lv, Zhiyuan <zhiyuan.lv@intel.com>; Tian,
>>Kevin <kevin.tian@intel.com>
>>Subject: Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the
>>dmabuf
>>
>>On Fr, 2017-04-28 at 17:35 +0800, Xiaoguang Chen wrote:
>>> +static size_t intel_vgpu_reg_rw_gvtg(struct intel_vgpu *vgpu, char
>>> *buf,
>>> + size_t count, loff_t *ppos, bool iswrite) {
>>> + unsigned int i = VFIO_PCI_OFFSET_TO_INDEX(*ppos) -
>>> + VFIO_PCI_NUM_REGIONS;
>>> + loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
>>> + int fd;
>>> +
>>> + if (pos >= vgpu->vdev.region[i].size || iswrite) {
>>> + gvt_vgpu_err("invalid op or offset for Intel vgpu fd
>>> region\n");
>>> + return -EINVAL;
>>> + }
>>> +
>>> + fd = anon_inode_getfd("gvtg", &intel_vgpu_gvtg_ops, vgpu,
>>> + O_RDWR | O_CLOEXEC);
>>> + if (fd < 0) {
>>> + gvt_vgpu_err("create intel vgpu fd failed:%d\n", fd);
>>> + return -EINVAL;
>>> + }
>>> +
>>> + count = min(count, (size_t)(vgpu->vdev.region[i].size - pos));
>>> + memcpy(buf, &fd, count);
>>> +
>>> + return count;
>>> +}
>>
>>Hmm, that looks like a rather strange way to return a file descriptor.
>>
>>What is the reason to not use ioctls on the vfio file handle, like
>>older version of these patches did?
>If I understood correctly that Alex prefer not to change the ioctls on the vfio file
>handle like the old version.
>So I used this way the smallest change to general vfio framework only adding a
>subregion definition.
>
>>
>>cheers,
>> Gerd
>
>_______________________________________________
>intel-gvt-dev mailing list
>intel-gvt-dev@lists.freedesktop.org
>https://lists.freedesktop.org/mailman/listinfo/intel-gvt-dev
[toc] | [prev] | [next] | [standalone]
| From | Alex Williamson <alex.williamson@redhat.com> |
|---|---|
| Date | 2017-05-04 18:10 +0200 |
| Message-ID | <tDruh-5So-1@gated-at.bofh.it> |
| In reply to | #1635389 |
On Thu, 4 May 2017 03:09:40 +0000
"Chen, Xiaoguang" <xiaoguang.chen@intel.com> wrote:
> Hi Alex, do you have any comments for this interface?
>
> >-----Original Message-----
> >From: intel-gvt-dev [mailto:intel-gvt-dev-bounces@lists.freedesktop.org] On
> >Behalf Of Chen, Xiaoguang
> >Sent: Wednesday, May 03, 2017 9:39 AM
> >To: Gerd Hoffmann <kraxel@redhat.com>
> >Cc: Tian, Kevin <kevin.tian@intel.com>; intel-gfx@lists.freedesktop.org; linux-
> >kernel@vger.kernel.org; zhenyuw@linux.intel.com; alex.williamson@redhat.com;
> >Lv, Zhiyuan <zhiyuan.lv@intel.com>; intel-gvt-dev@lists.freedesktop.org; Wang,
> >Zhi A <zhi.a.wang@intel.com>
> >Subject: RE: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf
> >
> >
> >
> >>-----Original Message-----
> >>From: Gerd Hoffmann [mailto:kraxel@redhat.com]
> >>Sent: Tuesday, May 02, 2017 5:51 PM
> >>To: Chen, Xiaoguang <xiaoguang.chen@intel.com>
> >>Cc: alex.williamson@redhat.com; intel-gfx@lists.freedesktop.org;
> >>intel-gvt- dev@lists.freedesktop.org; Wang, Zhi A
> >><zhi.a.wang@intel.com>; zhenyuw@linux.intel.com;
> >>linux-kernel@vger.kernel.org; Lv, Zhiyuan <zhiyuan.lv@intel.com>; Tian,
> >>Kevin <kevin.tian@intel.com>
> >>Subject: Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the
> >>dmabuf
> >>
> >>On Fr, 2017-04-28 at 17:35 +0800, Xiaoguang Chen wrote:
> >>> +static size_t intel_vgpu_reg_rw_gvtg(struct intel_vgpu *vgpu, char
> >>> *buf,
> >>> + size_t count, loff_t *ppos, bool iswrite) {
> >>> + unsigned int i = VFIO_PCI_OFFSET_TO_INDEX(*ppos) -
> >>> + VFIO_PCI_NUM_REGIONS;
> >>> + loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
> >>> + int fd;
> >>> +
> >>> + if (pos >= vgpu->vdev.region[i].size || iswrite) {
> >>> + gvt_vgpu_err("invalid op or offset for Intel vgpu fd
> >>> region\n");
> >>> + return -EINVAL;
> >>> + }
> >>> +
> >>> + fd = anon_inode_getfd("gvtg", &intel_vgpu_gvtg_ops, vgpu,
> >>> + O_RDWR | O_CLOEXEC);
> >>> + if (fd < 0) {
> >>> + gvt_vgpu_err("create intel vgpu fd failed:%d\n", fd);
> >>> + return -EINVAL;
> >>> + }
> >>> +
> >>> + count = min(count, (size_t)(vgpu->vdev.region[i].size - pos));
> >>> + memcpy(buf, &fd, count);
> >>> +
> >>> + return count;
> >>> +}
> >>
> >>Hmm, that looks like a rather strange way to return a file descriptor.
> >>
> >>What is the reason to not use ioctls on the vfio file handle, like
> >>older version of these patches did?
> >If I understood correctly that Alex prefer not to change the ioctls on the vfio file
> >handle like the old version.
> >So I used this way the smallest change to general vfio framework only adding a
> >subregion definition.
I think I was hoping we could avoid a separate file descriptor
altogether and use a vfio region instead. However, it was explained
previously why this really needs to be a separate fd and I agree that
using a region to expose an fd is really awkward. If we're going to
have a separate fd, let's use a device specific ioctl to get it.
Thanks,
Alex
[toc] | [prev] | [next] | [standalone]
| From | Gerd Hoffmann <kraxel@redhat.com> |
|---|---|
| Date | 2017-05-05 09:00 +0200 |
| Message-ID | <tDFnz-6yA-11@gated-at.bofh.it> |
| In reply to | #1635865 |
Hi, > > >>Hmm, that looks like a rather strange way to return a file descriptor. > > >> > > >>What is the reason to not use ioctls on the vfio file handle, like > > >>older version of these patches did? > > >If I understood correctly that Alex prefer not to change the ioctls on the vfio file > > >handle like the old version. > > >So I used this way the smallest change to general vfio framework only adding a > > >subregion definition. > > I think I was hoping we could avoid a separate file descriptor > altogether and use a vfio region instead. What exactly did you have in mind? Put the framebuffer information (struct intel_vgpu_dmabuf) into the vfio region, then access it using read/write/mmap? > However, it was explained > previously why this really needs to be a separate fd and I agree that > using a region to expose an fd is really awkward. Now with this patchset we have *two* kinds of separate file handles. First the anon-fd created by reading from the region. This is then used to run the intel ioctls on, which in turn create the other kind of file handle (dma-buf-fd). The dma-buf-fd really needs to be a separate fd, because it gets passed around as handle and because this is the way dma-bufs work (guess this is the discussion you are referring to). I can't see a compelling reason for the anon-fd though. I suspect this was done due to a misunderstanding ... cheers, Gerd
[toc] | [prev] | [next] | [standalone]
| From | Alex Williamson <alex.williamson@redhat.com> |
|---|---|
| Date | 2017-05-05 17:20 +0200 |
| Message-ID | <tDNbs-3rG-7@gated-at.bofh.it> |
| In reply to | #1636203 |
On Fri, 05 May 2017 08:55:31 +0200 Gerd Hoffmann <kraxel@redhat.com> wrote: > Hi, > > > > >>Hmm, that looks like a rather strange way to return a file descriptor. > > > >> > > > >>What is the reason to not use ioctls on the vfio file handle, like > > > >>older version of these patches did? > > > >If I understood correctly that Alex prefer not to change the ioctls on the vfio file > > > >handle like the old version. > > > >So I used this way the smallest change to general vfio framework only adding a > > > >subregion definition. > > > > I think I was hoping we could avoid a separate file descriptor > > altogether and use a vfio region instead. > > What exactly did you have in mind? Put the framebuffer information > (struct intel_vgpu_dmabuf) into the vfio region, then access it using > read/write/mmap? Yeah, that was my hope. Adding a new file descriptor means we have one more reference floating around complicating the life cycle of the device, group, and container. Furthermore this one is really only visible to the mdev vendor driver, so we can't rely on vfio-core, the vendor driver will need to consider the reference when releasing the device. > > However, it was explained > > previously why this really needs to be a separate fd and I agree that > > using a region to expose an fd is really awkward. > > Now with this patchset we have *two* kinds of separate file handles. > First the anon-fd created by reading from the region. This is then used > to run the intel ioctls on, which in turn create the other kind of file > handle (dma-buf-fd). > > The dma-buf-fd really needs to be a separate fd, because it gets passed > around as handle and because this is the way dma-bufs work (guess this > is the discussion you are referring to). Yep, we're going to need to trust the vendor driver to manage it, we have lots of places where we need to trust the vendor driver for an mdev device, unfortunately. > I can't see a compelling reason for the anon-fd though. I suspect this > was done due to a misunderstanding ... Yeah, vfio-core passes device ioctls to the vendor driver, so the vendor driver should be able to implement a VFIO_DEVICE_GVT_GET_DMABUF_FD ioctl direclty. Ideally maybe this isn't even GVT specific, and we'd s/GVT_//. Thanks, Alex
[toc] | [prev] | [next] | [standalone]
| From | "Chen, Xiaoguang" <xiaoguang.chen@intel.com> |
|---|---|
| Date | 2017-05-11 10:50 +0200 |
| Message-ID | <tFRXj-44b-7@gated-at.bofh.it> |
| In reply to | #1636437 |
Hi Alex, >-----Original Message----- >From: intel-gvt-dev [mailto:intel-gvt-dev-bounces@lists.freedesktop.org] On >Behalf Of Alex Williamson >Sent: Friday, May 05, 2017 11:11 PM >To: Gerd Hoffmann <kraxel@redhat.com> >Cc: Tian, Kevin <kevin.tian@intel.com>; intel-gfx@lists.freedesktop.org; linux- >kernel@vger.kernel.org; zhenyuw@linux.intel.com; Lv, Zhiyuan ><zhiyuan.lv@intel.com>; Chen, Xiaoguang <xiaoguang.chen@intel.com>; intel- >gvt-dev@lists.freedesktop.org; Wang, Zhi A <zhi.a.wang@intel.com> >Subject: Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf > >On Fri, 05 May 2017 08:55:31 +0200 >Gerd Hoffmann <kraxel@redhat.com> wrote: > >> Hi, >> >> > > >>Hmm, that looks like a rather strange way to return a file descriptor. >> > > >> >> > > >>What is the reason to not use ioctls on the vfio file handle, like >> > > >>older version of these patches did? >> > > >If I understood correctly that Alex prefer not to change the >> > > >ioctls on the vfio file handle like the old version. >> > > >So I used this way the smallest change to general vfio framework >> > > >only adding a subregion definition. >> > >> > I think I was hoping we could avoid a separate file descriptor >> > altogether and use a vfio region instead. >> >> What exactly did you have in mind? Put the framebuffer information >> (struct intel_vgpu_dmabuf) into the vfio region, then access it using >> read/write/mmap? > >Yeah, that was my hope. Adding a new file descriptor means we have one more >reference floating around complicating the life cycle of the device, group, and >container. Furthermore this one is really only visible to the mdev vendor driver, >so we can't rely on vfio-core, the vendor driver will need to consider the >reference when releasing the device. While read the framebuffer region we have to tell the vendor driver which framebuffer we want to read? There are two framebuffers now in KVMGT that is primary and cursor. There are two methods to implement this: 1) write the plane id first and then read the framebuffer. 2) create 2 vfio regions one for primary and one for cursor. Which method do you prefer? Or do you have other idea to handle this problem? chenxg
[toc] | [prev] | [next] | [standalone]
| From | Gerd Hoffmann <kraxel@redhat.com> |
|---|---|
| Date | 2017-05-11 15:30 +0200 |
| Message-ID | <tFWki-6O0-3@gated-at.bofh.it> |
| In reply to | #1639250 |
Hi,
> While read the framebuffer region we have to tell the vendor driver which framebuffer we want to read? There are two framebuffers now in KVMGT that is primary and cursor.
> There are two methods to implement this:
> 1) write the plane id first and then read the framebuffer.
> 2) create 2 vfio regions one for primary and one for cursor.
(3) Place information for both planes into one vfio region.
Which allows to fetch both with a single read() syscall.
The question is how you'll get the file descriptor then. If the ioctl
returns the dma-buf fd only you have a racy interface: Things can
change between read(vfio-region) and ioctl(need-dmabuf-fd).
ioctl(need-dma-buf) could return both dmabuf fd and plane info to fix
the race, but then it is easier to go with ioctl only interface (simliar
to the orginal one from dec last year) I think.
cheers,
Gerd
[toc] | [prev] | [next] | [standalone]
| From | Alex Williamson <alex.williamson@redhat.com> |
|---|---|
| Date | 2017-05-11 17:50 +0200 |
| Message-ID | <tFYvO-8cz-73@gated-at.bofh.it> |
| In reply to | #1639428 |
On Thu, 11 May 2017 15:27:53 +0200 Gerd Hoffmann <kraxel@redhat.com> wrote: > Hi, > > > While read the framebuffer region we have to tell the vendor driver which framebuffer we want to read? There are two framebuffers now in KVMGT that is primary and cursor. > > There are two methods to implement this: > > 1) write the plane id first and then read the framebuffer. > > 2) create 2 vfio regions one for primary and one for cursor. > > (3) Place information for both planes into one vfio region. > Which allows to fetch both with a single read() syscall. > > The question is how you'll get the file descriptor then. If the ioctl > returns the dma-buf fd only you have a racy interface: Things can > change between read(vfio-region) and ioctl(need-dmabuf-fd). > > ioctl(need-dma-buf) could return both dmabuf fd and plane info to fix > the race, but then it is easier to go with ioctl only interface (simliar > to the orginal one from dec last year) I think. If the dmabuf fd is provided by a separate mdev vendor driver specific ioctl, I don't see how vfio regions should be involved. Selecting which framebuffer should be an ioctl parameter. What sort of information needs to be conveyed about each plane? Is it static information or something that needs to be read repeatedly? Do we need it before we get the dmabuf fd or can it be an ioctl on the dmabuf fd? Thanks, Alex
[toc] | [prev] | [next] | [standalone]
| From | "Chen, Xiaoguang" <xiaoguang.chen@intel.com> |
|---|---|
| Date | 2017-05-12 04:20 +0200 |
| Message-ID | <tG8ls-6ft-5@gated-at.bofh.it> |
| In reply to | #1639782 |
Hi Alex and Gerd, >-----Original Message----- >From: intel-gvt-dev [mailto:intel-gvt-dev-bounces@lists.freedesktop.org] On >Behalf Of Alex Williamson >Sent: Thursday, May 11, 2017 11:45 PM >To: Gerd Hoffmann <kraxel@redhat.com> >Cc: Tian, Kevin <kevin.tian@intel.com>; intel-gfx@lists.freedesktop.org; linux- >kernel@vger.kernel.org; zhenyuw@linux.intel.com; Lv, Zhiyuan ><zhiyuan.lv@intel.com>; Chen, Xiaoguang <xiaoguang.chen@intel.com>; intel- >gvt-dev@lists.freedesktop.org; Wang, Zhi A <zhi.a.wang@intel.com> >Subject: Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf > >On Thu, 11 May 2017 15:27:53 +0200 >Gerd Hoffmann <kraxel@redhat.com> wrote: > >> Hi, >> >> > While read the framebuffer region we have to tell the vendor driver which >framebuffer we want to read? There are two framebuffers now in KVMGT that is >primary and cursor. >> > There are two methods to implement this: >> > 1) write the plane id first and then read the framebuffer. >> > 2) create 2 vfio regions one for primary and one for cursor. >> >> (3) Place information for both planes into one vfio region. >> Which allows to fetch both with a single read() syscall. >> >> The question is how you'll get the file descriptor then. If the ioctl >> returns the dma-buf fd only you have a racy interface: Things can >> change between read(vfio-region) and ioctl(need-dmabuf-fd). >> >> ioctl(need-dma-buf) could return both dmabuf fd and plane info to fix >> the race, but then it is easier to go with ioctl only interface >> (simliar to the orginal one from dec last year) I think. > >If the dmabuf fd is provided by a separate mdev vendor driver specific ioctl, I >don't see how vfio regions should be involved. Selecting which framebuffer >should be an ioctl parameter. Based on your last mail. I think the implementation looks like this: 1) user query the framebuffer information by reading the vfio region. 2) if the framebuffer changed(such as framebuffer's graphics address changed, size changed etc) we will need to create a new dmabuf fd. 3) create a new dmabuf fd using vfio device specific ioctl. >What sort of information needs to be conveyed >about each plane? Only plane id is needed. >Is it static information or something that needs to be read >repeatedly? It is static information. For our case plane id 1 represent primary plane and 3 for cursor plane. 2 means sprite plane which will not be used in our case. >Do we need it before we get the dmabuf fd or can it be an ioctl on >the dmabuf fd? We need it while query the framebuffer. In kernel we need the plane id to decide which plane we should decode. Below is my current implementation: 1) user first query the framebuffer(primary or cursor) and kernel decode the framebuffer and return the framebuffer information to user and also save a copy in kernel. 2) user compared the framebuffer and if the framebuffer changed creating a new dmabuf fd. 3) kernel create a new dmabuf fd based on saved framebuffer information. So we need plane id in step 1. In step 3 we create a dmabuf fd only using saved framebuffer information(no other information is needed). Chenxg. >Thanks, > >Alex >_______________________________________________ >intel-gvt-dev mailing list >intel-gvt-dev@lists.freedesktop.org >https://lists.freedesktop.org/mailman/listinfo/intel-gvt-dev
[toc] | [prev] | [next] | [standalone]
| From | Alex Williamson <alex.williamson@redhat.com> |
|---|---|
| Date | 2017-05-12 05:00 +0200 |
| Message-ID | <tG8Y9-6vq-7@gated-at.bofh.it> |
| In reply to | #1640129 |
On Fri, 12 May 2017 02:12:10 +0000 "Chen, Xiaoguang" <xiaoguang.chen@intel.com> wrote: > Hi Alex and Gerd, > > >-----Original Message----- > >From: intel-gvt-dev [mailto:intel-gvt-dev-bounces@lists.freedesktop.org] On > >Behalf Of Alex Williamson > >Sent: Thursday, May 11, 2017 11:45 PM > >To: Gerd Hoffmann <kraxel@redhat.com> > >Cc: Tian, Kevin <kevin.tian@intel.com>; intel-gfx@lists.freedesktop.org; linux- > >kernel@vger.kernel.org; zhenyuw@linux.intel.com; Lv, Zhiyuan > ><zhiyuan.lv@intel.com>; Chen, Xiaoguang <xiaoguang.chen@intel.com>; intel- > >gvt-dev@lists.freedesktop.org; Wang, Zhi A <zhi.a.wang@intel.com> > >Subject: Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf > > > >On Thu, 11 May 2017 15:27:53 +0200 > >Gerd Hoffmann <kraxel@redhat.com> wrote: > > > >> Hi, > >> > >> > While read the framebuffer region we have to tell the vendor driver which > >framebuffer we want to read? There are two framebuffers now in KVMGT that is > >primary and cursor. > >> > There are two methods to implement this: > >> > 1) write the plane id first and then read the framebuffer. > >> > 2) create 2 vfio regions one for primary and one for cursor. > >> > >> (3) Place information for both planes into one vfio region. > >> Which allows to fetch both with a single read() syscall. > >> > >> The question is how you'll get the file descriptor then. If the ioctl > >> returns the dma-buf fd only you have a racy interface: Things can > >> change between read(vfio-region) and ioctl(need-dmabuf-fd). > >> > >> ioctl(need-dma-buf) could return both dmabuf fd and plane info to fix > >> the race, but then it is easier to go with ioctl only interface > >> (simliar to the orginal one from dec last year) I think. > > > >If the dmabuf fd is provided by a separate mdev vendor driver specific ioctl, I > >don't see how vfio regions should be involved. Selecting which framebuffer > >should be an ioctl parameter. > Based on your last mail. I think the implementation looks like this: > 1) user query the framebuffer information by reading the vfio region. > 2) if the framebuffer changed(such as framebuffer's graphics address changed, size changed etc) we will need to create a new dmabuf fd. > 3) create a new dmabuf fd using vfio device specific ioctl. > > >What sort of information needs to be conveyed > >about each plane? > Only plane id is needed. > > >Is it static information or something that needs to be read > >repeatedly? > It is static information. For our case plane id 1 represent primary plane and 3 for cursor plane. 2 means sprite plane which will not be used in our case. > > >Do we need it before we get the dmabuf fd or can it be an ioctl on > >the dmabuf fd? > We need it while query the framebuffer. In kernel we need the plane id to decide which plane we should decode. > Below is my current implementation: > 1) user first query the framebuffer(primary or cursor) and kernel decode the framebuffer and return the framebuffer information to user and also save a copy in kernel. > 2) user compared the framebuffer and if the framebuffer changed creating a new dmabuf fd. If the contents of the framebuffer change or if the parameters of the framebuffer change? I can't image that creating a new dmabuf fd for every visual change within the framebuffer would be efficient, but I don't have any concept of what a dmabuf actually does. > 3) kernel create a new dmabuf fd based on saved framebuffer information. > > So we need plane id in step 1. > In step 3 we create a dmabuf fd only using saved framebuffer information(no other information is needed). What changes to the framebuffer require a new dmabuf fd? Shouldn't the user query the parameters of the framebuffer through a dmabuf fd and shouldn't the dmabuf fd have some signaling mechanism to the user (eventfd perhaps) to notify the user to re-evaluate the parameters? Otherwise are you imagining that the user polls the vfio region? Why can a dmabuf fd not persist across changes to the framebuffer? Can someone explain what a dmabuf is and how it works in terms that a non-graphics person can understand? Thanks, Alex
[toc] | [prev] | [next] | [standalone]
| From | "Chen, Xiaoguang" <xiaoguang.chen@intel.com> |
|---|---|
| Date | 2017-05-12 06:00 +0200 |
| Message-ID | <tG9Ue-75O-7@gated-at.bofh.it> |
| In reply to | #1640145 |
>-----Original Message----- >From: Alex Williamson [mailto:alex.williamson@redhat.com] >Sent: Friday, May 12, 2017 10:58 AM >To: Chen, Xiaoguang <xiaoguang.chen@intel.com> >Cc: Gerd Hoffmann <kraxel@redhat.com>; Tian, Kevin <kevin.tian@intel.com>; >intel-gfx@lists.freedesktop.org; linux-kernel@vger.kernel.org; >zhenyuw@linux.intel.com; Lv, Zhiyuan <zhiyuan.lv@intel.com>; intel-gvt- >dev@lists.freedesktop.org; Wang, Zhi A <zhi.a.wang@intel.com> >Subject: Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf > >On Fri, 12 May 2017 02:12:10 +0000 >"Chen, Xiaoguang" <xiaoguang.chen@intel.com> wrote: > >> Hi Alex and Gerd, >> >> >-----Original Message----- >> >From: intel-gvt-dev >> >[mailto:intel-gvt-dev-bounces@lists.freedesktop.org] On Behalf Of >> >Alex Williamson >> >Sent: Thursday, May 11, 2017 11:45 PM >> >To: Gerd Hoffmann <kraxel@redhat.com> >> >Cc: Tian, Kevin <kevin.tian@intel.com>; >> >intel-gfx@lists.freedesktop.org; linux- kernel@vger.kernel.org; >> >zhenyuw@linux.intel.com; Lv, Zhiyuan <zhiyuan.lv@intel.com>; Chen, >> >Xiaoguang <xiaoguang.chen@intel.com>; intel- >> >gvt-dev@lists.freedesktop.org; Wang, Zhi A <zhi.a.wang@intel.com> >> >Subject: Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the >> >dmabuf >> > >> >On Thu, 11 May 2017 15:27:53 +0200 >> >Gerd Hoffmann <kraxel@redhat.com> wrote: >> > >> >> Hi, >> >> >> >> > While read the framebuffer region we have to tell the vendor >> >> > driver which >> >framebuffer we want to read? There are two framebuffers now in KVMGT >> >that is primary and cursor. >> >> > There are two methods to implement this: >> >> > 1) write the plane id first and then read the framebuffer. >> >> > 2) create 2 vfio regions one for primary and one for cursor. >> >> >> >> (3) Place information for both planes into one vfio region. >> >> Which allows to fetch both with a single read() syscall. >> >> >> >> The question is how you'll get the file descriptor then. If the >> >> ioctl returns the dma-buf fd only you have a racy interface: >> >> Things can change between read(vfio-region) and ioctl(need-dmabuf-fd). >> >> >> >> ioctl(need-dma-buf) could return both dmabuf fd and plane info to >> >> fix the race, but then it is easier to go with ioctl only interface >> >> (simliar to the orginal one from dec last year) I think. >> > >> >If the dmabuf fd is provided by a separate mdev vendor driver >> >specific ioctl, I don't see how vfio regions should be involved. Selecting which >framebuffer >> >should be an ioctl parameter. >> Based on your last mail. I think the implementation looks like this: >> 1) user query the framebuffer information by reading the vfio region. >> 2) if the framebuffer changed(such as framebuffer's graphics address changed, >size changed etc) we will need to create a new dmabuf fd. >> 3) create a new dmabuf fd using vfio device specific ioctl. >> >> >What sort of information needs to be conveyed >> >about each plane? >> Only plane id is needed. >> >> >Is it static information or something that needs to be read >> >repeatedly? >> It is static information. For our case plane id 1 represent primary plane and 3 for >cursor plane. 2 means sprite plane which will not be used in our case. >> >> >Do we need it before we get the dmabuf fd or can it be an ioctl on >> >the dmabuf fd? >> We need it while query the framebuffer. In kernel we need the plane id to >decide which plane we should decode. >> Below is my current implementation: >> 1) user first query the framebuffer(primary or cursor) and kernel decode the >framebuffer and return the framebuffer information to user and also save a copy >in kernel. >> 2) user compared the framebuffer and if the framebuffer changed creating a >new dmabuf fd. > >If the contents of the framebuffer change or if the parameters of the framebuffer >change? If the parameters of the framebuffer change we need to create new dmabuf. >I can't image that creating a new dmabuf fd for every visual change >within the framebuffer would be efficient, but I don't have any concept of what a >dmabuf actually does. > >> 3) kernel create a new dmabuf fd based on saved framebuffer information. >> >> So we need plane id in step 1. >> In step 3 we create a dmabuf fd only using saved framebuffer information(no >other information is needed). > >What changes to the framebuffer require a new dmabuf fd? Shouldn't the user >query the parameters of the framebuffer through a dmabuf fd and shouldn't the >dmabuf fd have some signaling mechanism to the user (eventfd perhaps) to notify >the user to re-evaluate the parameters? >Otherwise are you imagining that the user polls the vfio region? Why can a >dmabuf fd not persist across changes to the framebuffer? Can someone explain >what a dmabuf is and how it works in terms that a non-graphics person can >understand? Thanks, A dmabuf will be associated a gem object. In our case the backing storage of the gem object is from the framebuffer. We use the GMA(graphics memory address) to traverse the GTT(graphics translation table) to get all the pages belong to the framebuffer and assign these pages to the gem object. So once the GMA of a framebuffer changed we have to create new dmabuf for it. The other parameters of the framebuffer such as the size of the framebuffer, the tiling mode changed we also have to create a new dmabuf. We did consider the signal mechanism to notify the user but doing so the kernel need to save a lot of information of the framebuffers so we decide to let the user check whether to create a new dmabuf or not. So the usage flow is: 1) query the framebuffer information 2) compare with saved dmabuf whether need to create a new dmabuf 3) create a new dmabuf(save the dmabuf and related framebuffer information such as gma, size....) > >Alex
[toc] | [prev] | [next] | [standalone]
| From | Gerd Hoffmann <kraxel@redhat.com> |
|---|---|
| Date | 2017-05-12 11:20 +0200 |
| Message-ID | <tGeTT-2j8-3@gated-at.bofh.it> |
| In reply to | #1640145 |
Hi,
> If the contents of the framebuffer change or if the parameters of the
> framebuffer change? I can't image that creating a new dmabuf fd for
> every visual change within the framebuffer would be efficient, but I
> don't have any concept of what a dmabuf actually does.
Ok, some background:
The drm subsystem has the concept of planes. The most important plane
is the primary framebuffer (i.e. what gets scanned out to the physical
display). The cursor is a plane too, and there can be additional
overlay planes for stuff like video playback.
Typically there are multiple planes in a system and only one of them
gets scanned out to the crtc, i.e. the fbdev emulation creates one plane
for the framebuffer console. The X-Server creates a plane too, and when
you switch between X-Server and framebuffer console via ctrl-alt-fn the
intel driver just reprograms the encoder to scan out the one or the
other plane to the crtc.
The dma-buf handed out by gvt is a reference to a plane. I think on the
host side gvt can see only the active plane (from encoder/crtc register
programming) not the inactive ones.
The dma-buf can be imported as opengl texture and then be used to render
the guest display to a host window. I think it is even possible to use
the dma-buf as plane in the host drm driver and scan it out directly to
a physical display. The actual framebuffer content stays in gpu memory
all the time, the cpu never has to touch it.
It is possible to cache the dma-buf handles, i.e. when the guest boots
you'll get the first for the fbcon plane, when the x-server starts the
second for the x-server framebuffer, and when the user switches to the
text console via ctrl-alt-fn you can re-use the fbcon dma-buf you
already have.
The caching becomes more important for good performance when the guest
uses pageflipping (wayland does): define two planes, render into one
while displaying the other, then flip the two for a atomic display
update.
The caching also makes it a bit difficult to create a good interface.
So, the current patch set creates:
(a) A way to query the active planes (ioctl
INTEL_VGPU_QUERY_DMABUF added by patch 5/6 of this series).
(b) A way to create a dma-buf for the active plane (ioctl
INTEL_VGPU_GENERATE_DMABUF).
Typical userspace workflow is to first query the plane, then check if it
already has a dma-buf for it, and if not create one.
> What changes to the framebuffer require a new dmabuf fd? Shouldn't the
> user query the parameters of the framebuffer through a dmabuf fd and
> shouldn't the dmabuf fd have some signaling mechanism to the user
> (eventfd perhaps) to notify the user to re-evaluate the parameters?
dma-bufs don't support that, they are really just a handle to a piece of
memory, all metadata (format, size) most be communicated by other means.
> Otherwise are you imagining that the user polls the vfio region?
Hmm, notification support would probably a good reason to have a
separate file handle to manage the dma-bufs (instead of using
driver-specific ioctls on the vfio fd), because the driver could also
use the management fd for notifications then.
I'm not sure how useful notification support actually is though.
Notifications when another plane gets mapped to the crtc should be easy.
But I'm not sure it is possible to get notifications when the plane
content changes, especially in case the guest does software rendering so
the display is updated without gvt seeing guest activity on the
rendering pipeline. Without the later qemu needs a timer for display
updates _anyway_ ...
cheers,
Gerd
[toc] | [prev] | [next] | [standalone]
| From | Alex Williamson <alex.williamson@redhat.com> |
|---|---|
| Date | 2017-05-12 18:50 +0200 |
| Message-ID | <tGlVn-7jv-5@gated-at.bofh.it> |
| In reply to | #1640336 |
On Fri, 12 May 2017 11:12:05 +0200 Gerd Hoffmann <kraxel@redhat.com> wrote: > Hi, > > > If the contents of the framebuffer change or if the parameters of the > > framebuffer change? I can't image that creating a new dmabuf fd for > > every visual change within the framebuffer would be efficient, but I > > don't have any concept of what a dmabuf actually does. > > Ok, some background: > > The drm subsystem has the concept of planes. The most important plane > is the primary framebuffer (i.e. what gets scanned out to the physical > display). The cursor is a plane too, and there can be additional > overlay planes for stuff like video playback. > > Typically there are multiple planes in a system and only one of them > gets scanned out to the crtc, i.e. the fbdev emulation creates one plane > for the framebuffer console. The X-Server creates a plane too, and when > you switch between X-Server and framebuffer console via ctrl-alt-fn the > intel driver just reprograms the encoder to scan out the one or the > other plane to the crtc. > > The dma-buf handed out by gvt is a reference to a plane. I think on the > host side gvt can see only the active plane (from encoder/crtc register > programming) not the inactive ones. > > The dma-buf can be imported as opengl texture and then be used to render > the guest display to a host window. I think it is even possible to use > the dma-buf as plane in the host drm driver and scan it out directly to > a physical display. The actual framebuffer content stays in gpu memory > all the time, the cpu never has to touch it. > > It is possible to cache the dma-buf handles, i.e. when the guest boots > you'll get the first for the fbcon plane, when the x-server starts the > second for the x-server framebuffer, and when the user switches to the > text console via ctrl-alt-fn you can re-use the fbcon dma-buf you > already have. > > The caching becomes more important for good performance when the guest > uses pageflipping (wayland does): define two planes, render into one > while displaying the other, then flip the two for a atomic display > update. > > The caching also makes it a bit difficult to create a good interface. > So, the current patch set creates: > > (a) A way to query the active planes (ioctl > INTEL_VGPU_QUERY_DMABUF added by patch 5/6 of this series). > (b) A way to create a dma-buf for the active plane (ioctl > INTEL_VGPU_GENERATE_DMABUF). > > Typical userspace workflow is to first query the plane, then check if it > already has a dma-buf for it, and if not create one. Thank you! This is immensely helpful! > > What changes to the framebuffer require a new dmabuf fd? Shouldn't the > > user query the parameters of the framebuffer through a dmabuf fd and > > shouldn't the dmabuf fd have some signaling mechanism to the user > > (eventfd perhaps) to notify the user to re-evaluate the parameters? > > dma-bufs don't support that, they are really just a handle to a piece of > memory, all metadata (format, size) most be communicated by other means. > > > Otherwise are you imagining that the user polls the vfio region? > > Hmm, notification support would probably a good reason to have a > separate file handle to manage the dma-bufs (instead of using > driver-specific ioctls on the vfio fd), because the driver could also > use the management fd for notifications then. I like this idea of a separate control fd for dmabufs, it provides not only a central management point, but also a nice abstraction for the vfio device specific interface. We potentially only need a single VFIO_DEVICE_GET_DMABUF_MGR_FD() ioctl to get a dmabuf management fd (perhaps with a type parameter, ex. GFX) where maybe we could have vfio-core incorporate this reference into the group lifecycle, so the vendor driver only needs to fdget/put this manager fd for the various plane dmabuf fds spawned in order to get core-level reference counting. The dmabuf manager fd can be separately versioned from vfio or make use of some vendor magic if there are portions that are vendor specific (the above examples for query/get ioctls really don't seem vendor specific). > I'm not sure how useful notification support actually is though. > Notifications when another plane gets mapped to the crtc should be easy. > But I'm not sure it is possible to get notifications when the plane > content changes, especially in case the guest does software rendering so > the display is updated without gvt seeing guest activity on the > rendering pipeline. Without the later qemu needs a timer for display > updates _anyway_ ... Seems like it has benefits even if we don't have an initial use for notification mechanisms. Thanks, Alex
[toc] | [prev] | [next] | [standalone]
| From | "Chen, Xiaoguang" <xiaoguang.chen@intel.com> |
|---|---|
| Date | 2017-05-15 05:40 +0200 |
| Message-ID | <tHf1v-2vF-3@gated-at.bofh.it> |
| In reply to | #1640577 |
Hi Alex and Gerd, >-----Original Message----- >From: Alex Williamson [mailto:alex.williamson@redhat.com] >Sent: Saturday, May 13, 2017 12:38 AM >To: Gerd Hoffmann <kraxel@redhat.com> >Cc: Chen, Xiaoguang <xiaoguang.chen@intel.com>; Tian, Kevin ><kevin.tian@intel.com>; intel-gfx@lists.freedesktop.org; linux- >kernel@vger.kernel.org; zhenyuw@linux.intel.com; Lv, Zhiyuan ><zhiyuan.lv@intel.com>; intel-gvt-dev@lists.freedesktop.org; Wang, Zhi A ><zhi.a.wang@intel.com> >Subject: Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf > >On Fri, 12 May 2017 11:12:05 +0200 >Gerd Hoffmann <kraxel@redhat.com> wrote: > >> Hi, >> >> > If the contents of the framebuffer change or if the parameters of >> > the framebuffer change? I can't image that creating a new dmabuf fd >> > for every visual change within the framebuffer would be efficient, >> > but I don't have any concept of what a dmabuf actually does. >> >> Ok, some background: >> >> The drm subsystem has the concept of planes. The most important plane >> is the primary framebuffer (i.e. what gets scanned out to the physical >> display). The cursor is a plane too, and there can be additional >> overlay planes for stuff like video playback. >> >> Typically there are multiple planes in a system and only one of them >> gets scanned out to the crtc, i.e. the fbdev emulation creates one >> plane for the framebuffer console. The X-Server creates a plane too, >> and when you switch between X-Server and framebuffer console via >> ctrl-alt-fn the intel driver just reprograms the encoder to scan out >> the one or the other plane to the crtc. >> >> The dma-buf handed out by gvt is a reference to a plane. I think on >> the host side gvt can see only the active plane (from encoder/crtc >> register >> programming) not the inactive ones. >> >> The dma-buf can be imported as opengl texture and then be used to >> render the guest display to a host window. I think it is even >> possible to use the dma-buf as plane in the host drm driver and scan >> it out directly to a physical display. The actual framebuffer content >> stays in gpu memory all the time, the cpu never has to touch it. >> >> It is possible to cache the dma-buf handles, i.e. when the guest boots >> you'll get the first for the fbcon plane, when the x-server starts the >> second for the x-server framebuffer, and when the user switches to the >> text console via ctrl-alt-fn you can re-use the fbcon dma-buf you >> already have. >> >> The caching becomes more important for good performance when the guest >> uses pageflipping (wayland does): define two planes, render into one >> while displaying the other, then flip the two for a atomic display >> update. >> >> The caching also makes it a bit difficult to create a good interface. >> So, the current patch set creates: >> >> (a) A way to query the active planes (ioctl >> INTEL_VGPU_QUERY_DMABUF added by patch 5/6 of this series). >> (b) A way to create a dma-buf for the active plane (ioctl >> INTEL_VGPU_GENERATE_DMABUF). >> >> Typical userspace workflow is to first query the plane, then check if >> it already has a dma-buf for it, and if not create one. > >Thank you! This is immensely helpful! > >> > What changes to the framebuffer require a new dmabuf fd? Shouldn't >> > the user query the parameters of the framebuffer through a dmabuf fd >> > and shouldn't the dmabuf fd have some signaling mechanism to the >> > user (eventfd perhaps) to notify the user to re-evaluate the parameters? >> >> dma-bufs don't support that, they are really just a handle to a piece >> of memory, all metadata (format, size) most be communicated by other means. >> >> > Otherwise are you imagining that the user polls the vfio region? >> >> Hmm, notification support would probably a good reason to have a >> separate file handle to manage the dma-bufs (instead of using >> driver-specific ioctls on the vfio fd), because the driver could also >> use the management fd for notifications then. > >I like this idea of a separate control fd for dmabufs, it provides not only a central >management point, but also a nice abstraction for the vfio device specific >interface. We potentially only need a single >VFIO_DEVICE_GET_DMABUF_MGR_FD() ioctl to get a dmabuf management fd >(perhaps with a type parameter, ex. GFX) where maybe we could have vfio-core >incorporate this reference into the group lifecycle, so the vendor driver only >needs to fdget/put this manager fd for the various plane dmabuf fds spawned in >order to get core-level reference counting. Following is my understanding of the management fd idea: 1) QEMU will call VFIO_DEVICE_GET_DMABUF_MGR_FD() ioctl to create a fd and saved the fd in vfio group while initializing the vfio. 2) vendor driver use fdget to add reference count of the fd. 3) vendor driver use ioctl to the fd to query plane information or create dma-buf fd. 4) vendor driver use fdput when finished using this fd. Is my understanding right? Both QEMU and kernel vfio-core will have changes based on this proposal except the vendor part changes. Who will make these changes? Thanks Chenxg > >The dmabuf manager fd can be separately versioned from vfio or make use of >some vendor magic if there are portions that are vendor specific (the above >examples for query/get ioctls really don't seem vendor specific). > >> I'm not sure how useful notification support actually is though. >> Notifications when another plane gets mapped to the crtc should be easy. >> But I'm not sure it is possible to get notifications when the plane >> content changes, especially in case the guest does software rendering >> so the display is updated without gvt seeing guest activity on the >> rendering pipeline. Without the later qemu needs a timer for display >> updates _anyway_ ... > >Seems like it has benefits even if we don't have an initial use for notification >mechanisms. Thanks, > >Alex
[toc] | [prev] | [next] | [standalone]
| From | Alex Williamson <alex.williamson@redhat.com> |
|---|---|
| Date | 2017-05-15 19:50 +0200 |
| Message-ID | <tHsi7-2M0-23@gated-at.bofh.it> |
| In reply to | #1641261 |
On Mon, 15 May 2017 03:36:50 +0000 "Chen, Xiaoguang" <xiaoguang.chen@intel.com> wrote: > Hi Alex and Gerd, > > >-----Original Message----- > >From: Alex Williamson [mailto:alex.williamson@redhat.com] > >Sent: Saturday, May 13, 2017 12:38 AM > >To: Gerd Hoffmann <kraxel@redhat.com> > >Cc: Chen, Xiaoguang <xiaoguang.chen@intel.com>; Tian, Kevin > ><kevin.tian@intel.com>; intel-gfx@lists.freedesktop.org; linux- > >kernel@vger.kernel.org; zhenyuw@linux.intel.com; Lv, Zhiyuan > ><zhiyuan.lv@intel.com>; intel-gvt-dev@lists.freedesktop.org; Wang, Zhi A > ><zhi.a.wang@intel.com> > >Subject: Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf > > > >On Fri, 12 May 2017 11:12:05 +0200 > >Gerd Hoffmann <kraxel@redhat.com> wrote: > > > >> Hi, > >> > >> > If the contents of the framebuffer change or if the parameters of > >> > the framebuffer change? I can't image that creating a new dmabuf fd > >> > for every visual change within the framebuffer would be efficient, > >> > but I don't have any concept of what a dmabuf actually does. > >> > >> Ok, some background: > >> > >> The drm subsystem has the concept of planes. The most important plane > >> is the primary framebuffer (i.e. what gets scanned out to the physical > >> display). The cursor is a plane too, and there can be additional > >> overlay planes for stuff like video playback. > >> > >> Typically there are multiple planes in a system and only one of them > >> gets scanned out to the crtc, i.e. the fbdev emulation creates one > >> plane for the framebuffer console. The X-Server creates a plane too, > >> and when you switch between X-Server and framebuffer console via > >> ctrl-alt-fn the intel driver just reprograms the encoder to scan out > >> the one or the other plane to the crtc. > >> > >> The dma-buf handed out by gvt is a reference to a plane. I think on > >> the host side gvt can see only the active plane (from encoder/crtc > >> register > >> programming) not the inactive ones. > >> > >> The dma-buf can be imported as opengl texture and then be used to > >> render the guest display to a host window. I think it is even > >> possible to use the dma-buf as plane in the host drm driver and scan > >> it out directly to a physical display. The actual framebuffer content > >> stays in gpu memory all the time, the cpu never has to touch it. > >> > >> It is possible to cache the dma-buf handles, i.e. when the guest boots > >> you'll get the first for the fbcon plane, when the x-server starts the > >> second for the x-server framebuffer, and when the user switches to the > >> text console via ctrl-alt-fn you can re-use the fbcon dma-buf you > >> already have. > >> > >> The caching becomes more important for good performance when the guest > >> uses pageflipping (wayland does): define two planes, render into one > >> while displaying the other, then flip the two for a atomic display > >> update. > >> > >> The caching also makes it a bit difficult to create a good interface. > >> So, the current patch set creates: > >> > >> (a) A way to query the active planes (ioctl > >> INTEL_VGPU_QUERY_DMABUF added by patch 5/6 of this series). > >> (b) A way to create a dma-buf for the active plane (ioctl > >> INTEL_VGPU_GENERATE_DMABUF). > >> > >> Typical userspace workflow is to first query the plane, then check if > >> it already has a dma-buf for it, and if not create one. > > > >Thank you! This is immensely helpful! > > > >> > What changes to the framebuffer require a new dmabuf fd? Shouldn't > >> > the user query the parameters of the framebuffer through a dmabuf fd > >> > and shouldn't the dmabuf fd have some signaling mechanism to the > >> > user (eventfd perhaps) to notify the user to re-evaluate the parameters? > >> > >> dma-bufs don't support that, they are really just a handle to a piece > >> of memory, all metadata (format, size) most be communicated by other means. > >> > >> > Otherwise are you imagining that the user polls the vfio region? > >> > >> Hmm, notification support would probably a good reason to have a > >> separate file handle to manage the dma-bufs (instead of using > >> driver-specific ioctls on the vfio fd), because the driver could also > >> use the management fd for notifications then. > > > >I like this idea of a separate control fd for dmabufs, it provides not only a central > >management point, but also a nice abstraction for the vfio device specific > >interface. We potentially only need a single > >VFIO_DEVICE_GET_DMABUF_MGR_FD() ioctl to get a dmabuf management fd > >(perhaps with a type parameter, ex. GFX) where maybe we could have vfio-core > >incorporate this reference into the group lifecycle, so the vendor driver only > >needs to fdget/put this manager fd for the various plane dmabuf fds spawned in > >order to get core-level reference counting. > Following is my understanding of the management fd idea: > 1) QEMU will call VFIO_DEVICE_GET_DMABUF_MGR_FD() ioctl to create a fd and saved the fd in vfio group while initializing the vfio. Ideally there'd be kernel work here too if we want vfio-core to incorporate lifecycle of this fd into the device/group/container lifecycle. Maybe we even want to generalize it further to something like VFIO_DEVICE_GET_FD which takes a parameter of what type of FD to get, GFX_DMABUF_MGR_FD in this case. vfio-core would probably allocate the fd, tap into the release hook for reference counting and pass it to the vfio_device_ops (mdev vendor driver in this case) to attach further. > 2) vendor driver use fdget to add reference count of the fd. > 3) vendor driver use ioctl to the fd to query plane information or create dma-buf fd. > 4) vendor driver use fdput when finished using this fd. > > Is my understanding right? With the above addition, which maybe you were already considering, seems right. > Both QEMU and kernel vfio-core will have changes based on this proposal except the vendor part changes. > Who will make these changes? /me points to the folks trying to enable this functionality... Thanks, Alex
[toc] | [prev] | [next] | [standalone]
| From | "Chen, Xiaoguang" <xiaoguang.chen@intel.com> |
|---|---|
| Date | 2017-05-16 12:20 +0200 |
| Message-ID | <tHHKa-4hW-15@gated-at.bofh.it> |
| In reply to | #1641935 |
Hi Alex,
>-----Original Message-----
>From: Alex Williamson [mailto:alex.williamson@redhat.com]
>Sent: Tuesday, May 16, 2017 1:44 AM
>To: Chen, Xiaoguang <xiaoguang.chen@intel.com>
>Cc: Gerd Hoffmann <kraxel@redhat.com>; Tian, Kevin <kevin.tian@intel.com>;
>intel-gfx@lists.freedesktop.org; linux-kernel@vger.kernel.org;
>zhenyuw@linux.intel.com; Lv, Zhiyuan <zhiyuan.lv@intel.com>; intel-gvt-
>dev@lists.freedesktop.org; Wang, Zhi A <zhi.a.wang@intel.com>
>Subject: Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf
>
>On Mon, 15 May 2017 03:36:50 +0000
>"Chen, Xiaoguang" <xiaoguang.chen@intel.com> wrote:
>
>> Hi Alex and Gerd,
>>
>> >-----Original Message-----
>> >From: Alex Williamson [mailto:alex.williamson@redhat.com]
>> >Sent: Saturday, May 13, 2017 12:38 AM
>> >To: Gerd Hoffmann <kraxel@redhat.com>
>> >Cc: Chen, Xiaoguang <xiaoguang.chen@intel.com>; Tian, Kevin
>> ><kevin.tian@intel.com>; intel-gfx@lists.freedesktop.org; linux-
>> >kernel@vger.kernel.org; zhenyuw@linux.intel.com; Lv, Zhiyuan
>> ><zhiyuan.lv@intel.com>; intel-gvt-dev@lists.freedesktop.org; Wang,
>> >Zhi A <zhi.a.wang@intel.com>
>> >Subject: Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the
>> >dmabuf
>> >
>> >On Fri, 12 May 2017 11:12:05 +0200
>> >Gerd Hoffmann <kraxel@redhat.com> wrote:
>> >
>> >> Hi,
>> >>
>> >> > If the contents of the framebuffer change or if the parameters of
>> >> > the framebuffer change? I can't image that creating a new dmabuf
>> >> > fd for every visual change within the framebuffer would be
>> >> > efficient, but I don't have any concept of what a dmabuf actually does.
>> >>
>> >> Ok, some background:
>> >>
>> >> The drm subsystem has the concept of planes. The most important
>> >> plane is the primary framebuffer (i.e. what gets scanned out to the
>> >> physical display). The cursor is a plane too, and there can be
>> >> additional overlay planes for stuff like video playback.
>> >>
>> >> Typically there are multiple planes in a system and only one of
>> >> them gets scanned out to the crtc, i.e. the fbdev emulation creates
>> >> one plane for the framebuffer console. The X-Server creates a
>> >> plane too, and when you switch between X-Server and framebuffer
>> >> console via ctrl-alt-fn the intel driver just reprograms the
>> >> encoder to scan out the one or the other plane to the crtc.
>> >>
>> >> The dma-buf handed out by gvt is a reference to a plane. I think
>> >> on the host side gvt can see only the active plane (from
>> >> encoder/crtc register
>> >> programming) not the inactive ones.
>> >>
>> >> The dma-buf can be imported as opengl texture and then be used to
>> >> render the guest display to a host window. I think it is even
>> >> possible to use the dma-buf as plane in the host drm driver and
>> >> scan it out directly to a physical display. The actual framebuffer
>> >> content stays in gpu memory all the time, the cpu never has to touch it.
>> >>
>> >> It is possible to cache the dma-buf handles, i.e. when the guest
>> >> boots you'll get the first for the fbcon plane, when the x-server
>> >> starts the second for the x-server framebuffer, and when the user
>> >> switches to the text console via ctrl-alt-fn you can re-use the
>> >> fbcon dma-buf you already have.
>> >>
>> >> The caching becomes more important for good performance when the
>> >> guest uses pageflipping (wayland does): define two planes, render
>> >> into one while displaying the other, then flip the two for a atomic
>> >> display update.
>> >>
>> >> The caching also makes it a bit difficult to create a good interface.
>> >> So, the current patch set creates:
>> >>
>> >> (a) A way to query the active planes (ioctl
>> >> INTEL_VGPU_QUERY_DMABUF added by patch 5/6 of this series).
>> >> (b) A way to create a dma-buf for the active plane (ioctl
>> >> INTEL_VGPU_GENERATE_DMABUF).
>> >>
>> >> Typical userspace workflow is to first query the plane, then check
>> >> if it already has a dma-buf for it, and if not create one.
>> >
>> >Thank you! This is immensely helpful!
>> >
>> >> > What changes to the framebuffer require a new dmabuf fd?
>> >> > Shouldn't the user query the parameters of the framebuffer
>> >> > through a dmabuf fd and shouldn't the dmabuf fd have some
>> >> > signaling mechanism to the user (eventfd perhaps) to notify the user to re-
>evaluate the parameters?
>> >>
>> >> dma-bufs don't support that, they are really just a handle to a
>> >> piece of memory, all metadata (format, size) most be communicated by
>other means.
>> >>
>> >> > Otherwise are you imagining that the user polls the vfio region?
>> >>
>> >> Hmm, notification support would probably a good reason to have a
>> >> separate file handle to manage the dma-bufs (instead of using
>> >> driver-specific ioctls on the vfio fd), because the driver could
>> >> also use the management fd for notifications then.
>> >
>> >I like this idea of a separate control fd for dmabufs, it provides
>> >not only a central management point, but also a nice abstraction for
>> >the vfio device specific interface. We potentially only need a
>> >single
>> >VFIO_DEVICE_GET_DMABUF_MGR_FD() ioctl to get a dmabuf management fd
>> >(perhaps with a type parameter, ex. GFX) where maybe we could have
>> >vfio-core incorporate this reference into the group lifecycle, so the
>> >vendor driver only needs to fdget/put this manager fd for the various
>> >plane dmabuf fds spawned in order to get core-level reference counting.
>> Following is my understanding of the management fd idea:
>> 1) QEMU will call VFIO_DEVICE_GET_DMABUF_MGR_FD() ioctl to create a fd
>and saved the fd in vfio group while initializing the vfio.
>
>Ideally there'd be kernel work here too if we want vfio-core to incorporate
>lifecycle of this fd into the device/group/container lifecycle. Maybe we even
>want to generalize it further to something like VFIO_DEVICE_GET_FD which takes
>a parameter of what type of FD to get, GFX_DMABUF_MGR_FD in this case. vfio-
>core would probably allocate the fd, tap into the release hook for reference
>counting and pass it to the vfio_device_ops (mdev vendor driver in this case) to
>attach further.
I tried to implement this today and now it functionally worked.
I am still a little confuse of how to tap the fd into the release hook of device/group/container.
I tried to create the fd in vfio core but found it is difficult to get the file operations for the fd, the file operations should be supplied by vendor drivers.
So the fd is created in kvmgt.c for now.
Below is part of the codes:
diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
index 389f072..d0649ba 100644
--- a/drivers/gpu/drm/i915/gvt/kvmgt.c
+++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
@@ -41,6 +41,7 @@
#include <linux/kvm_host.h>
#include <linux/vfio.h>
#include <linux/mdev.h>
+#include <linux/anon_inodes.h>
#include "i915_drv.h"
#include "gvt.h"
@@ -524,6 +525,63 @@ static int intel_vgpu_reg_init_opregion(struct intel_vgpu *vgpu)
return ret;
}
+static int intel_vgpu_dmabuf_mgr_fd_mmap(struct file *file, struct vm_area_struct *vma)
+{
+ WARN_ON(1);
+
+ return 0;
+}
+
+static int intel_vgpu_dmabuf_mgr_fd_release(struct inode *inode, struct file *filp)
+{
+ struct intel_vgpu *vgpu = filp->private_data;
+
+ if (vgpu->vdev.vfio_device != NULL)
+ vfio_device_put(vgpu->vdev.vfio_device);
+
+ return 0;
+}
+
+static long intel_vgpu_dmabuf_mgr_fd_ioctl(struct file *filp,
+ unsigned int ioctl, unsigned long arg)
+{
+ struct intel_vgpu *vgpu = filp->private_data;
+ int minsz;
+ struct intel_vgpu_dmabuf dmabuf;
+ int ret;
+ struct fd f;
+ f = fdget(dmabuf.fd);
+ minsz = offsetofend(struct intel_vgpu_dmabuf, tiled);
+ if (copy_from_user(&dmabuf, (void __user *)arg, minsz))
+ return -EFAULT;
+ if (ioctl == INTEL_VGPU_QUERY_DMABUF)
+ ret = intel_gvt_ops->vgpu_query_dmabuf(vgpu, &dmabuf);
+ else if (ioctl == INTEL_VGPU_GENERATE_DMABUF)
+ ret = intel_gvt_ops->vgpu_generate_dmabuf(vgpu, &dmabuf);
+ else {
+ fdput(f);
+ gvt_vgpu_err("unsupported dmabuf operation\n");
+ return -EINVAL;
+ }
+
+ if (ret != 0) {
+ fdput(f);
+ gvt_vgpu_err("gvt-g get dmabuf failed:%d\n", ret);
+ return -EINVAL;
+ }
+ fdput(f);
+
+ return copy_to_user((void __user *)arg, &dmabuf, minsz) ? -EFAULT : 0;
+}
+
+static const struct file_operations intel_vgpu_dmabuf_mgr_fd_ops = {
+ .release = intel_vgpu_dmabuf_mgr_fd_release,
+ .unlocked_ioctl = intel_vgpu_dmabuf_mgr_fd_ioctl,
+ .mmap = intel_vgpu_dmabuf_mgr_fd_mmap,
+ .llseek = noop_llseek,
+};
+
static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
{
struct intel_vgpu *vgpu = NULL;
@@ -1259,6 +1317,31 @@ static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd,
} else if (cmd == VFIO_DEVICE_RESET) {
intel_gvt_ops->vgpu_reset(vgpu);
return 0;
+ } else if (cmd == VFIO_DEVICE_GET_FD) {
+ struct vfio_fd vfio_fd;
+ int fd;
+ struct vfio_device *device;
+
+ minsz = offsetofend(struct vfio_fd, fd);
+ if (copy_from_user(&vfio_fd, (void __user *)arg, minsz))
+ return -EINVAL;
+
+ if (vfio_fd.argsz < minsz)
+ return -EINVAL;
+
+ fd = anon_inode_getfd("vfio_dmabuf_mgr_fd", &intel_vgpu_dmabuf_mgr_fd_ops,
+ vgpu, O_RDWR | O_CLOEXEC);
+ if (fd < 0)
+ return -EINVAL;
+
+ vfio_fd.fd = fd;
+ device = vfio_device_get_from_dev(mdev_dev(mdev));
+ if (device == NULL)
+ gvt_vgpu_err("kvmgt: vfio device is null\n");
+ else
+ vgpu->vdev.vfio_device = device;
+
+ return copy_to_user((void __user *)arg, &vfio_fd, minsz) ? -EFAULT : 0;
}
return 0;
diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
index 519eff3..98be2e0 100644
--- a/include/uapi/linux/vfio.h
+++ b/include/uapi/linux/vfio.h
@@ -484,6 +485,20 @@ struct vfio_pci_hot_reset {
#define VFIO_DEVICE_PCI_HOT_RESET _IO(VFIO_TYPE, VFIO_BASE + 13)
+/**
+ * VFIO_DEVICE_GET_FD - _IOW(VFIO_TYPE, VFIO_BASE + 21, struct vfio_fd)
+ *
+ * Create a fd for a vfio device.
+ * This fd can be used for various purpose.
+ */
+struct vfio_fd {
+ __u32 argsz;
+ __u32 flags;
+ /* out */
+ __u32 fd;
+};
+#define VFIO_DEVICE_GET_FD _IO(VFIO_TYPE, VFIO_BASE + 14)
+
/* -------- API for Type1 VFIO IOMMU -------- */
/**
--
2.7.4
Thanks
chenxg
>
>> 2) vendor driver use fdget to add reference count of the fd.
>> 3) vendor driver use ioctl to the fd to query plane information or create dma-
>buf fd.
>> 4) vendor driver use fdput when finished using this fd.
>>
>> Is my understanding right?
>
>With the above addition, which maybe you were already considering, seems right.
>
>> Both QEMU and kernel vfio-core will have changes based on this proposal
>except the vendor part changes.
>> Who will make these changes?
>
>/me points to the folks trying to enable this functionality...
>
>Thanks,
>Alex
[toc] | [prev] | [next] | [standalone]
| From | Alex Williamson <alex.williamson@redhat.com> |
|---|---|
| Date | 2017-05-17 23:50 +0200 |
| Message-ID | <tIeZs-8x-27@gated-at.bofh.it> |
| In reply to | #1642388 |
On Tue, 16 May 2017 10:16:28 +0000
"Chen, Xiaoguang" <xiaoguang.chen@intel.com> wrote:
> Hi Alex,
>
> >-----Original Message-----
> >From: Alex Williamson [mailto:alex.williamson@redhat.com]
> >Sent: Tuesday, May 16, 2017 1:44 AM
> >To: Chen, Xiaoguang <xiaoguang.chen@intel.com>
> >Cc: Gerd Hoffmann <kraxel@redhat.com>; Tian, Kevin <kevin.tian@intel.com>;
> >intel-gfx@lists.freedesktop.org; linux-kernel@vger.kernel.org;
> >zhenyuw@linux.intel.com; Lv, Zhiyuan <zhiyuan.lv@intel.com>; intel-gvt-
> >dev@lists.freedesktop.org; Wang, Zhi A <zhi.a.wang@intel.com>
> >Subject: Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf
> >
> >On Mon, 15 May 2017 03:36:50 +0000
> >"Chen, Xiaoguang" <xiaoguang.chen@intel.com> wrote:
> >
> >> Hi Alex and Gerd,
> >>
> >> >-----Original Message-----
> >> >From: Alex Williamson [mailto:alex.williamson@redhat.com]
> >> >Sent: Saturday, May 13, 2017 12:38 AM
> >> >To: Gerd Hoffmann <kraxel@redhat.com>
> >> >Cc: Chen, Xiaoguang <xiaoguang.chen@intel.com>; Tian, Kevin
> >> ><kevin.tian@intel.com>; intel-gfx@lists.freedesktop.org; linux-
> >> >kernel@vger.kernel.org; zhenyuw@linux.intel.com; Lv, Zhiyuan
> >> ><zhiyuan.lv@intel.com>; intel-gvt-dev@lists.freedesktop.org; Wang,
> >> >Zhi A <zhi.a.wang@intel.com>
> >> >Subject: Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the
> >> >dmabuf
> >> >
> >> >On Fri, 12 May 2017 11:12:05 +0200
> >> >Gerd Hoffmann <kraxel@redhat.com> wrote:
> >> >
> >> >> Hi,
> >> >>
> >> >> > If the contents of the framebuffer change or if the parameters of
> >> >> > the framebuffer change? I can't image that creating a new dmabuf
> >> >> > fd for every visual change within the framebuffer would be
> >> >> > efficient, but I don't have any concept of what a dmabuf actually does.
> >> >>
> >> >> Ok, some background:
> >> >>
> >> >> The drm subsystem has the concept of planes. The most important
> >> >> plane is the primary framebuffer (i.e. what gets scanned out to the
> >> >> physical display). The cursor is a plane too, and there can be
> >> >> additional overlay planes for stuff like video playback.
> >> >>
> >> >> Typically there are multiple planes in a system and only one of
> >> >> them gets scanned out to the crtc, i.e. the fbdev emulation creates
> >> >> one plane for the framebuffer console. The X-Server creates a
> >> >> plane too, and when you switch between X-Server and framebuffer
> >> >> console via ctrl-alt-fn the intel driver just reprograms the
> >> >> encoder to scan out the one or the other plane to the crtc.
> >> >>
> >> >> The dma-buf handed out by gvt is a reference to a plane. I think
> >> >> on the host side gvt can see only the active plane (from
> >> >> encoder/crtc register
> >> >> programming) not the inactive ones.
> >> >>
> >> >> The dma-buf can be imported as opengl texture and then be used to
> >> >> render the guest display to a host window. I think it is even
> >> >> possible to use the dma-buf as plane in the host drm driver and
> >> >> scan it out directly to a physical display. The actual framebuffer
> >> >> content stays in gpu memory all the time, the cpu never has to touch it.
> >> >>
> >> >> It is possible to cache the dma-buf handles, i.e. when the guest
> >> >> boots you'll get the first for the fbcon plane, when the x-server
> >> >> starts the second for the x-server framebuffer, and when the user
> >> >> switches to the text console via ctrl-alt-fn you can re-use the
> >> >> fbcon dma-buf you already have.
> >> >>
> >> >> The caching becomes more important for good performance when the
> >> >> guest uses pageflipping (wayland does): define two planes, render
> >> >> into one while displaying the other, then flip the two for a atomic
> >> >> display update.
> >> >>
> >> >> The caching also makes it a bit difficult to create a good interface.
> >> >> So, the current patch set creates:
> >> >>
> >> >> (a) A way to query the active planes (ioctl
> >> >> INTEL_VGPU_QUERY_DMABUF added by patch 5/6 of this series).
> >> >> (b) A way to create a dma-buf for the active plane (ioctl
> >> >> INTEL_VGPU_GENERATE_DMABUF).
> >> >>
> >> >> Typical userspace workflow is to first query the plane, then check
> >> >> if it already has a dma-buf for it, and if not create one.
> >> >
> >> >Thank you! This is immensely helpful!
> >> >
> >> >> > What changes to the framebuffer require a new dmabuf fd?
> >> >> > Shouldn't the user query the parameters of the framebuffer
> >> >> > through a dmabuf fd and shouldn't the dmabuf fd have some
> >> >> > signaling mechanism to the user (eventfd perhaps) to notify the user to re-
> >evaluate the parameters?
> >> >>
> >> >> dma-bufs don't support that, they are really just a handle to a
> >> >> piece of memory, all metadata (format, size) most be communicated by
> >other means.
> >> >>
> >> >> > Otherwise are you imagining that the user polls the vfio region?
> >> >>
> >> >> Hmm, notification support would probably a good reason to have a
> >> >> separate file handle to manage the dma-bufs (instead of using
> >> >> driver-specific ioctls on the vfio fd), because the driver could
> >> >> also use the management fd for notifications then.
> >> >
> >> >I like this idea of a separate control fd for dmabufs, it provides
> >> >not only a central management point, but also a nice abstraction for
> >> >the vfio device specific interface. We potentially only need a
> >> >single
> >> >VFIO_DEVICE_GET_DMABUF_MGR_FD() ioctl to get a dmabuf management fd
> >> >(perhaps with a type parameter, ex. GFX) where maybe we could have
> >> >vfio-core incorporate this reference into the group lifecycle, so the
> >> >vendor driver only needs to fdget/put this manager fd for the various
> >> >plane dmabuf fds spawned in order to get core-level reference counting.
> >> Following is my understanding of the management fd idea:
> >> 1) QEMU will call VFIO_DEVICE_GET_DMABUF_MGR_FD() ioctl to create a fd
> >and saved the fd in vfio group while initializing the vfio.
> >
> >Ideally there'd be kernel work here too if we want vfio-core to incorporate
> >lifecycle of this fd into the device/group/container lifecycle. Maybe we even
> >want to generalize it further to something like VFIO_DEVICE_GET_FD which takes
> >a parameter of what type of FD to get, GFX_DMABUF_MGR_FD in this case. vfio-
> >core would probably allocate the fd, tap into the release hook for reference
> >counting and pass it to the vfio_device_ops (mdev vendor driver in this case) to
> >attach further.
> I tried to implement this today and now it functionally worked.
> I am still a little confuse of how to tap the fd into the release hook of device/group/container.
> I tried to create the fd in vfio core but found it is difficult to get the file operations for the fd, the file operations should be supplied by vendor drivers.
I'm not fully convinced there's benefit to having vfio-core attempt to
do this, I was just hoping to avoid each vendor driver needing to
implement their own reference counting. I don't think vfio-core wants
to get into tracking each ioctl for each vendor specific fd type to
know which create new references and which don't. Perhaps we'll come
up with easier ways to do this as we go.
> So the fd is created in kvmgt.c for now.
> Below is part of the codes:
>
> diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
> index 389f072..d0649ba 100644
> --- a/drivers/gpu/drm/i915/gvt/kvmgt.c
> +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
> @@ -41,6 +41,7 @@
> #include <linux/kvm_host.h>
> #include <linux/vfio.h>
> #include <linux/mdev.h>
> +#include <linux/anon_inodes.h>
>
> #include "i915_drv.h"
> #include "gvt.h"
> @@ -524,6 +525,63 @@ static int intel_vgpu_reg_init_opregion(struct intel_vgpu *vgpu)
> return ret;
> }
>
> +static int intel_vgpu_dmabuf_mgr_fd_mmap(struct file *file, struct vm_area_struct *vma)
> +{
> + WARN_ON(1);
A user can abuse this, simply return error.
> +
> + return 0;
> +}
> +
> +static int intel_vgpu_dmabuf_mgr_fd_release(struct inode *inode, struct file *filp)
> +{
> + struct intel_vgpu *vgpu = filp->private_data;
> +
> + if (vgpu->vdev.vfio_device != NULL)
> + vfio_device_put(vgpu->vdev.vfio_device);
When does the case occur where we don't have a vfio_device? This looks
a bit like a warning flag that reference counting isn't handled
properly.
> +
> + return 0;
> +}
> +
> +static long intel_vgpu_dmabuf_mgr_fd_ioctl(struct file *filp,
> + unsigned int ioctl, unsigned long arg)
> +{
> + struct intel_vgpu *vgpu = filp->private_data;
> + int minsz;
> + struct intel_vgpu_dmabuf dmabuf;
> + int ret;
> + struct fd f;
> + f = fdget(dmabuf.fd);
> + minsz = offsetofend(struct intel_vgpu_dmabuf, tiled);
> + if (copy_from_user(&dmabuf, (void __user *)arg, minsz))
> + return -EFAULT;
> + if (ioctl == INTEL_VGPU_QUERY_DMABUF)
> + ret = intel_gvt_ops->vgpu_query_dmabuf(vgpu, &dmabuf);
> + else if (ioctl == INTEL_VGPU_GENERATE_DMABUF)
> + ret = intel_gvt_ops->vgpu_generate_dmabuf(vgpu, &dmabuf);
Why do we need vendor specific ioctls here? Aren't querying the
current plane and getting an fd for that plane very generic concepts?
Is the resulting dmabuf Intel specific?
> + else {
> + fdput(f);
> + gvt_vgpu_err("unsupported dmabuf operation\n");
> + return -EINVAL;
> + }
> +
> + if (ret != 0) {
> + fdput(f);
> + gvt_vgpu_err("gvt-g get dmabuf failed:%d\n", ret);
> + return -EINVAL;
> + }
> + fdput(f);
> +
> + return copy_to_user((void __user *)arg, &dmabuf, minsz) ? -EFAULT : 0;
> +}
> +
> +static const struct file_operations intel_vgpu_dmabuf_mgr_fd_ops = {
> + .release = intel_vgpu_dmabuf_mgr_fd_release,
> + .unlocked_ioctl = intel_vgpu_dmabuf_mgr_fd_ioctl,
> + .mmap = intel_vgpu_dmabuf_mgr_fd_mmap,
> + .llseek = noop_llseek,
> +};
> +
> static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
> {
> struct intel_vgpu *vgpu = NULL;
> @@ -1259,6 +1317,31 @@ static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd,
> } else if (cmd == VFIO_DEVICE_RESET) {
> intel_gvt_ops->vgpu_reset(vgpu);
> return 0;
> + } else if (cmd == VFIO_DEVICE_GET_FD) {
> + struct vfio_fd vfio_fd;
> + int fd;
> + struct vfio_device *device;
> +
> + minsz = offsetofend(struct vfio_fd, fd);
> + if (copy_from_user(&vfio_fd, (void __user *)arg, minsz))
> + return -EINVAL;
> +
> + if (vfio_fd.argsz < minsz)
> + return -EINVAL;
> +
> + fd = anon_inode_getfd("vfio_dmabuf_mgr_fd", &intel_vgpu_dmabuf_mgr_fd_ops,
> + vgpu, O_RDWR | O_CLOEXEC);
> + if (fd < 0)
> + return -EINVAL;
> +
> + vfio_fd.fd = fd;
> + device = vfio_device_get_from_dev(mdev_dev(mdev));
> + if (device == NULL)
> + gvt_vgpu_err("kvmgt: vfio device is null\n");
> + else
> + vgpu->vdev.vfio_device = device;
> +
> + return copy_to_user((void __user *)arg, &vfio_fd, minsz) ? -EFAULT : 0;
> }
>
> return 0;
> diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
> index 519eff3..98be2e0 100644
> --- a/include/uapi/linux/vfio.h
> +++ b/include/uapi/linux/vfio.h
> @@ -484,6 +485,20 @@ struct vfio_pci_hot_reset {
>
> #define VFIO_DEVICE_PCI_HOT_RESET _IO(VFIO_TYPE, VFIO_BASE + 13)
>
> +/**
> + * VFIO_DEVICE_GET_FD - _IOW(VFIO_TYPE, VFIO_BASE + 21, struct vfio_fd)
> + *
> + * Create a fd for a vfio device.
> + * This fd can be used for various purpose.
> + */
> +struct vfio_fd {
> + __u32 argsz;
> + __u32 flags;
> + /* out */
> + __u32 fd;
> +};
> +#define VFIO_DEVICE_GET_FD _IO(VFIO_TYPE, VFIO_BASE + 14)
The idea was that we pass some sort of type to VFIO_DEVICE_GET_FD, for
instance we might ask for a DEVICE_FD_GRAPHICS_DMABUF and the vfio bus
driver (mdev vendor driver) would test whether it supports that type of
thing and either return an fd or error. We can return the fd the same
way we do for VFIO_DEVICE_GET_FD. For instance the user should do
something like:
dmabuf_fd = ioctl(device_fd,
VFIO_DEVICE_GET_FD, DEVICE_FD_GRAPHICS_DMABUF);
if (dmabuf_fd < 0)
/* not supported... */
else
/* do stuff */
Thanks,
Alex
[toc] | [prev] | [next] | [standalone]
| From | "Chen, Xiaoguang" <xiaoguang.chen@intel.com> |
|---|---|
| Date | 2017-05-18 04:00 +0200 |
| Message-ID | <tIiTn-2In-7@gated-at.bofh.it> |
| In reply to | #1643656 |
Hi Alex,
>-----Original Message-----
>From: Alex Williamson [mailto:alex.williamson@redhat.com]
>Sent: Thursday, May 18, 2017 5:44 AM
>To: Chen, Xiaoguang <xiaoguang.chen@intel.com>
>Cc: Gerd Hoffmann <kraxel@redhat.com>; Tian, Kevin <kevin.tian@intel.com>;
>linux-kernel@vger.kernel.org; zhenyuw@linux.intel.com; Lv, Zhiyuan
><zhiyuan.lv@intel.com>; intel-gvt-dev@lists.freedesktop.org; Wang, Zhi A
><zhi.a.wang@intel.com>
>Subject: Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the dmabuf
>
>On Tue, 16 May 2017 10:16:28 +0000
>"Chen, Xiaoguang" <xiaoguang.chen@intel.com> wrote:
>
>> Hi Alex,
>>
>> >-----Original Message-----
>> >From: Alex Williamson [mailto:alex.williamson@redhat.com]
>> >Sent: Tuesday, May 16, 2017 1:44 AM
>> >To: Chen, Xiaoguang <xiaoguang.chen@intel.com>
>> >Cc: Gerd Hoffmann <kraxel@redhat.com>; Tian, Kevin
>> ><kevin.tian@intel.com>; intel-gfx@lists.freedesktop.org;
>> >linux-kernel@vger.kernel.org; zhenyuw@linux.intel.com; Lv, Zhiyuan
>> ><zhiyuan.lv@intel.com>; intel-gvt- dev@lists.freedesktop.org; Wang,
>> >Zhi A <zhi.a.wang@intel.com>
>> >Subject: Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting the
>> >dmabuf
>> >
>> >On Mon, 15 May 2017 03:36:50 +0000
>> >"Chen, Xiaoguang" <xiaoguang.chen@intel.com> wrote:
>> >
>> >> Hi Alex and Gerd,
>> >>
>> >> >-----Original Message-----
>> >> >From: Alex Williamson [mailto:alex.williamson@redhat.com]
>> >> >Sent: Saturday, May 13, 2017 12:38 AM
>> >> >To: Gerd Hoffmann <kraxel@redhat.com>
>> >> >Cc: Chen, Xiaoguang <xiaoguang.chen@intel.com>; Tian, Kevin
>> >> ><kevin.tian@intel.com>; intel-gfx@lists.freedesktop.org; linux-
>> >> >kernel@vger.kernel.org; zhenyuw@linux.intel.com; Lv, Zhiyuan
>> >> ><zhiyuan.lv@intel.com>; intel-gvt-dev@lists.freedesktop.org; Wang,
>> >> >Zhi A <zhi.a.wang@intel.com>
>> >> >Subject: Re: [RFC PATCH 6/6] drm/i915/gvt: support QEMU getting
>> >> >the dmabuf
>> >> >
>> >> >On Fri, 12 May 2017 11:12:05 +0200 Gerd Hoffmann
>> >> ><kraxel@redhat.com> wrote:
>> >> >
>> >> >> Hi,
>> >> >>
>> >> >> > If the contents of the framebuffer change or if the parameters
>> >> >> > of the framebuffer change? I can't image that creating a new
>> >> >> > dmabuf fd for every visual change within the framebuffer would
>> >> >> > be efficient, but I don't have any concept of what a dmabuf actually
>does.
>> >> >>
>> >> >> Ok, some background:
>> >> >>
>> >> >> The drm subsystem has the concept of planes. The most important
>> >> >> plane is the primary framebuffer (i.e. what gets scanned out to
>> >> >> the physical display). The cursor is a plane too, and there can
>> >> >> be additional overlay planes for stuff like video playback.
>> >> >>
>> >> >> Typically there are multiple planes in a system and only one of
>> >> >> them gets scanned out to the crtc, i.e. the fbdev emulation
>> >> >> creates one plane for the framebuffer console. The X-Server
>> >> >> creates a plane too, and when you switch between X-Server and
>> >> >> framebuffer console via ctrl-alt-fn the intel driver just
>> >> >> reprograms the encoder to scan out the one or the other plane to the crtc.
>> >> >>
>> >> >> The dma-buf handed out by gvt is a reference to a plane. I
>> >> >> think on the host side gvt can see only the active plane (from
>> >> >> encoder/crtc register
>> >> >> programming) not the inactive ones.
>> >> >>
>> >> >> The dma-buf can be imported as opengl texture and then be used
>> >> >> to render the guest display to a host window. I think it is
>> >> >> even possible to use the dma-buf as plane in the host drm driver
>> >> >> and scan it out directly to a physical display. The actual
>> >> >> framebuffer content stays in gpu memory all the time, the cpu never has
>to touch it.
>> >> >>
>> >> >> It is possible to cache the dma-buf handles, i.e. when the guest
>> >> >> boots you'll get the first for the fbcon plane, when the
>> >> >> x-server starts the second for the x-server framebuffer, and
>> >> >> when the user switches to the text console via ctrl-alt-fn you
>> >> >> can re-use the fbcon dma-buf you already have.
>> >> >>
>> >> >> The caching becomes more important for good performance when the
>> >> >> guest uses pageflipping (wayland does): define two planes,
>> >> >> render into one while displaying the other, then flip the two
>> >> >> for a atomic display update.
>> >> >>
>> >> >> The caching also makes it a bit difficult to create a good interface.
>> >> >> So, the current patch set creates:
>> >> >>
>> >> >> (a) A way to query the active planes (ioctl
>> >> >> INTEL_VGPU_QUERY_DMABUF added by patch 5/6 of this series).
>> >> >> (b) A way to create a dma-buf for the active plane (ioctl
>> >> >> INTEL_VGPU_GENERATE_DMABUF).
>> >> >>
>> >> >> Typical userspace workflow is to first query the plane, then
>> >> >> check if it already has a dma-buf for it, and if not create one.
>> >> >
>> >> >Thank you! This is immensely helpful!
>> >> >
>> >> >> > What changes to the framebuffer require a new dmabuf fd?
>> >> >> > Shouldn't the user query the parameters of the framebuffer
>> >> >> > through a dmabuf fd and shouldn't the dmabuf fd have some
>> >> >> > signaling mechanism to the user (eventfd perhaps) to notify
>> >> >> > the user to re-
>> >evaluate the parameters?
>> >> >>
>> >> >> dma-bufs don't support that, they are really just a handle to a
>> >> >> piece of memory, all metadata (format, size) most be
>> >> >> communicated by
>> >other means.
>> >> >>
>> >> >> > Otherwise are you imagining that the user polls the vfio region?
>> >> >>
>> >> >> Hmm, notification support would probably a good reason to have a
>> >> >> separate file handle to manage the dma-bufs (instead of using
>> >> >> driver-specific ioctls on the vfio fd), because the driver could
>> >> >> also use the management fd for notifications then.
>> >> >
>> >> >I like this idea of a separate control fd for dmabufs, it provides
>> >> >not only a central management point, but also a nice abstraction
>> >> >for the vfio device specific interface. We potentially only need
>> >> >a single
>> >> >VFIO_DEVICE_GET_DMABUF_MGR_FD() ioctl to get a dmabuf management
>> >> >fd (perhaps with a type parameter, ex. GFX) where maybe we could
>> >> >have vfio-core incorporate this reference into the group
>> >> >lifecycle, so the vendor driver only needs to fdget/put this
>> >> >manager fd for the various plane dmabuf fds spawned in order to get core-
>level reference counting.
>> >> Following is my understanding of the management fd idea:
>> >> 1) QEMU will call VFIO_DEVICE_GET_DMABUF_MGR_FD() ioctl to create a
>> >> fd
>> >and saved the fd in vfio group while initializing the vfio.
>> >
>> >Ideally there'd be kernel work here too if we want vfio-core to
>> >incorporate lifecycle of this fd into the device/group/container
>> >lifecycle. Maybe we even want to generalize it further to something
>> >like VFIO_DEVICE_GET_FD which takes a parameter of what type of FD to
>> >get, GFX_DMABUF_MGR_FD in this case. vfio- core would probably
>> >allocate the fd, tap into the release hook for reference counting and
>> >pass it to the vfio_device_ops (mdev vendor driver in this case) to attach
>further.
>> I tried to implement this today and now it functionally worked.
>> I am still a little confuse of how to tap the fd into the release hook of
>device/group/container.
>> I tried to create the fd in vfio core but found it is difficult to get the file
>operations for the fd, the file operations should be supplied by vendor drivers.
>
>I'm not fully convinced there's benefit to having vfio-core attempt to do this, I
>was just hoping to avoid each vendor driver needing to implement their own
>reference counting. I don't think vfio-core wants to get into tracking each ioctl
>for each vendor specific fd type to know which create new references and which
>don't. Perhaps we'll come up with easier ways to do this as we go.
Got it.
>
>> So the fd is created in kvmgt.c for now.
>> Below is part of the codes:
>>
>> diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c
>> b/drivers/gpu/drm/i915/gvt/kvmgt.c
>> index 389f072..d0649ba 100644
>> --- a/drivers/gpu/drm/i915/gvt/kvmgt.c
>> +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
>> @@ -41,6 +41,7 @@
>> #include <linux/kvm_host.h>
>> #include <linux/vfio.h>
>> #include <linux/mdev.h>
>> +#include <linux/anon_inodes.h>
>>
>> #include "i915_drv.h"
>> #include "gvt.h"
>> @@ -524,6 +525,63 @@ static int intel_vgpu_reg_init_opregion(struct
>intel_vgpu *vgpu)
>> return ret;
>> }
>>
>> +static int intel_vgpu_dmabuf_mgr_fd_mmap(struct file *file, struct
>> +vm_area_struct *vma) {
>> + WARN_ON(1);
>
>A user can abuse this, simply return error.
OK.
>
>> +
>> + return 0;
>> +}
>> +
>> +static int intel_vgpu_dmabuf_mgr_fd_release(struct inode *inode,
>> +struct file *filp) {
>> + struct intel_vgpu *vgpu = filp->private_data;
>> +
>> + if (vgpu->vdev.vfio_device != NULL)
>> + vfio_device_put(vgpu->vdev.vfio_device);
>
>When does the case occur where we don't have a vfio_device? This looks a bit
>like a warning flag that reference counting isn't handled properly.
This situation happen only when anonymous fd created successfully but error occur while trying to get the vfio_device.
We should return error while user space trying to create the management fd and print an error message while kernel release this fd.
>
>> +
>> + return 0;
>> +}
>> +
>> +static long intel_vgpu_dmabuf_mgr_fd_ioctl(struct file *filp,
>> + unsigned int ioctl, unsigned long arg) {
>> + struct intel_vgpu *vgpu = filp->private_data;
>> + int minsz;
>> + struct intel_vgpu_dmabuf dmabuf;
>> + int ret;
>> + struct fd f;
>> + f = fdget(dmabuf.fd);
>> + minsz = offsetofend(struct intel_vgpu_dmabuf, tiled);
>> + if (copy_from_user(&dmabuf, (void __user *)arg, minsz))
>> + return -EFAULT;
>> + if (ioctl == INTEL_VGPU_QUERY_DMABUF)
>> + ret = intel_gvt_ops->vgpu_query_dmabuf(vgpu, &dmabuf);
>> + else if (ioctl == INTEL_VGPU_GENERATE_DMABUF)
>> + ret = intel_gvt_ops->vgpu_generate_dmabuf(vgpu,
>> +&dmabuf);
>
>Why do we need vendor specific ioctls here? Aren't querying the current plane
>and getting an fd for that plane very generic concepts?
>Is the resulting dmabuf Intel specific?
No. not Intel specific. Like Gerd said "Typical userspace workflow is to first query the plane, then
check if it already has a dma-buf for it, and if not create one".
We first query the plane info(WITHOUT creating a fd).
User space need to check whether there's a dmabuf for the plane(user space usually cached two or three dmabuf to handle double buffer or triple buffer situation) only there's no dmabuf for the plane we will create a dmabuf for it(another ioctl).
>
>> + else {
>> + fdput(f);
>> + gvt_vgpu_err("unsupported dmabuf operation\n");
>> + return -EINVAL;
>> + }
>> +
>> + if (ret != 0) {
>> + fdput(f);
>> + gvt_vgpu_err("gvt-g get dmabuf failed:%d\n", ret);
>> + return -EINVAL;
>> + }
>> + fdput(f);
>> +
>> + return copy_to_user((void __user *)arg, &dmabuf, minsz) ?
>> +-EFAULT : 0; }
>> +
>> +static const struct file_operations intel_vgpu_dmabuf_mgr_fd_ops = {
>> + .release = intel_vgpu_dmabuf_mgr_fd_release,
>> + .unlocked_ioctl = intel_vgpu_dmabuf_mgr_fd_ioctl,
>> + .mmap = intel_vgpu_dmabuf_mgr_fd_mmap,
>> + .llseek = noop_llseek,
>> +};
>> +
>> static int intel_vgpu_create(struct kobject *kobj, struct mdev_device
>> *mdev) {
>> struct intel_vgpu *vgpu = NULL; @@ -1259,6 +1317,31 @@ static
>> long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd,
>> } else if (cmd == VFIO_DEVICE_RESET) {
>> intel_gvt_ops->vgpu_reset(vgpu);
>> return 0;
>> + } else if (cmd == VFIO_DEVICE_GET_FD) {
>> + struct vfio_fd vfio_fd;
>> + int fd;
>> + struct vfio_device *device;
>> +
>> + minsz = offsetofend(struct vfio_fd, fd);
>> + if (copy_from_user(&vfio_fd, (void __user *)arg, minsz))
>> + return -EINVAL;
>> +
>> + if (vfio_fd.argsz < minsz)
>> + return -EINVAL;
>> +
>> + fd = anon_inode_getfd("vfio_dmabuf_mgr_fd",
>&intel_vgpu_dmabuf_mgr_fd_ops,
>> + vgpu, O_RDWR | O_CLOEXEC);
>> + if (fd < 0)
>> + return -EINVAL;
>> +
>> + vfio_fd.fd = fd;
>> + device = vfio_device_get_from_dev(mdev_dev(mdev));
>> + if (device == NULL)
>> + gvt_vgpu_err("kvmgt: vfio device is null\n");
>> + else
>> + vgpu->vdev.vfio_device = device;
>> +
>> + return copy_to_user((void __user *)arg, &vfio_fd,
>> + minsz) ? -EFAULT : 0;
>> }
>>
>> return 0;
>> diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
>> index 519eff3..98be2e0 100644
>> --- a/include/uapi/linux/vfio.h
>> +++ b/include/uapi/linux/vfio.h
>> @@ -484,6 +485,20 @@ struct vfio_pci_hot_reset {
>>
>> #define VFIO_DEVICE_PCI_HOT_RESET _IO(VFIO_TYPE, VFIO_BASE + 13)
>>
>> +/**
>> + * VFIO_DEVICE_GET_FD - _IOW(VFIO_TYPE, VFIO_BASE + 21, struct
>> +vfio_fd)
>> + *
>> + * Create a fd for a vfio device.
>> + * This fd can be used for various purpose.
>> + */
>> +struct vfio_fd {
>> + __u32 argsz;
>> + __u32 flags;
>> + /* out */
>> + __u32 fd;
>> +};
>> +#define VFIO_DEVICE_GET_FD _IO(VFIO_TYPE, VFIO_BASE + 14)
>
>
>The idea was that we pass some sort of type to VFIO_DEVICE_GET_FD, for
>instance we might ask for a DEVICE_FD_GRAPHICS_DMABUF and the vfio bus
>driver (mdev vendor driver) would test whether it supports that type of thing and
>either return an fd or error. We can return the fd the same way we do for
>VFIO_DEVICE_GET_FD. For instance the user should do something like:
>
>dmabuf_fd = ioctl(device_fd,
> VFIO_DEVICE_GET_FD, DEVICE_FD_GRAPHICS_DMABUF); if
>(dmabuf_fd < 0)
> /* not supported... */
>else
> /* do stuff */
OK. Got it.
>
>Thanks,
>Alex
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | linux.kernel
csiph-web