Skip to contentSkip to conversation

drm/i915/gvt: Dma-buf support for GVT-g

PATCH Superseded Tina Zhang 3 participants 10 messages Jul 19, 2017 – Jul 21, 2017

Subsystems (5)

v12 of 19 Superseded Latest is v19 →

lore
Share & tools
lore

Tina Zhang

author
#0 lore raw

v12 cover drm/i915/gvt: Dma-buf support for GVT-g

v11->v12:
1) add drm_format_mod back. (Gerd and Zhenyu)
2) add region_index. (Gerd)
3) refine the lifecycle of dmabuf.
4) send to [email protected]. (Ville)

v10->v11:
1) rename plane_type to drm_plane_type. (Gerd)
2) move fields of vfio_device_query_gfx_plane to
vfio_device_gfx_plane_info. (Gerd)
3) remove drm_format_mod, start fields. (Daniel)
4) remove plane_id.

v9->v10:
1) remove dma-buf management
2) refine the ABI API VFIO_DEVICE_QUERY_GFX_PLANE
3) track the dma-buf create and release in kernel mode

v8->v9:
1) refine the dma-buf ioctl definition
2) add a lock to protect the dmabuf list
3) move drm format change to a separate patch
4) codes cleanup

v7->v8:
1) refine framebuffer decoder code
2) fix a bug in decoding primary plane

v6->v7:
1) release dma-buf related allocations in dma-buf's associated release function.
2) refine ioctl interface for querying plane info or create dma-buf
3) refine framebuffer decoder code
4) the patch series is based on 4.12.0-rc1

v5->v6:
1) align the dma-buf life cycle with the vfio device.
2) add the dma-buf releated operations in a separate patch.
3) i915 releated changes.

v4->v5:
1) fix bug while checking whether the gem obj is gvt's dma-buf when user change caching mode or domains. Add a helper function to do it.
2) add definition for the query plane and create dma-buf.

v3->v4:
1) fix bug while checking whether the gem obj is gvt's dma-buf when set caching mode or doamins.

v2->v3:
1) add a field gvt_plane_info in the drm_i915_gem_obj structure to save the decoded plane information to avoid look up while need the plane info.
2) declare a new flag I915_GEM_OBJECT_IS_GVT_DMABUF in drm_i915_gem_object to represent the gem obj for gvt's dma-buf. The tiling mode, caching mode and domains can not be changed for this kind of gem object.
3) change dma-buf related information to be more generic. So other vendor can use the same interface.

v1->v2:
1) create a management fd for dma-buf operations.
2) alloc gem object's backing storage in gem obj's get_pages() callback.

This patch set adds the dma-buf support for intel GVT-g. dma-buf is a uniform mechanism to share DMA buffers across different devices and sub-systems.
dma-buf for intel GVT-g is mainly used to share the vgpu's framebuffer to other users or sub-systems so they can use the dma-buf to show the desktop of a vm which uses intel vgpu.

The main idea is we create a gem object and set vgpu's framebuffer as the backing storage of this gem object. And associate this gem obj to a dma-buf object then export this dma-buf at the meantime generate a file descriptor for this dma-buf. Finally deliver this file descriptor to user space. And user can use this dma-buf fd to do render or other operations.

Tina Zhang (6):
drm/i915/gvt: Add framebuffer decoder support
drm: Introduce RGB 64-bit 16:16:16:16 float format drm/i915/gvt: Add RGB 64-bit 16:16:16:16 float format support drm/i915/gvt: add opregion support
vfio: ABI for mdev display dma-buf operation drm/i915: Introduce GEM proxy

 drivers/gpu/drm/i915/gvt/Makefile      |   3 +-
 drivers/gpu/drm/i915/gvt/display.c     |   2 +-
 drivers/gpu/drm/i915/gvt/display.h     |   2 +
 drivers/gpu/drm/i915/gvt/fb_decoder.c  | 440 +++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/gvt/fb_decoder.h  | 175 +++++++++++++
 drivers/gpu/drm/i915/gvt/gvt.h         |   1 +
 drivers/gpu/drm/i915/gvt/hypercall.h   |   1 +
 drivers/gpu/drm/i915/gvt/kvmgt.c       | 109 +++++++-
 drivers/gpu/drm/i915/gvt/mpt.h         |  15 ++
 drivers/gpu/drm/i915/gvt/opregion.c    |  26 +-
 drivers/gpu/drm/i915/gvt/vgpu.c        |   4 +
 drivers/gpu/drm/i915/i915_gem.c        |  26 +-
 drivers/gpu/drm/i915/i915_gem_object.h |   9 +
 drivers/gpu/drm/i915/i915_gem_tiling.c |   5 +
 include/uapi/drm/drm_fourcc.h          |   4 +
 include/uapi/linux/vfio.h              |  28 +++
 16 files changed, 838 insertions(+), 12 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/gvt/fb_decoder.c
 create mode 100644 drivers/gpu/drm/i915/gvt/fb_decoder.h
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#1 lore raw

PATCH v12 1/6 drm/i915/gvt: Add framebuffer decoder support

Framebuffer decoder returns guest framebuffer information. Guest framebuffer includes primary, cursor and sprite plane.

---
 drivers/gpu/drm/i915/gvt/Makefile     |   3 +-
 drivers/gpu/drm/i915/gvt/display.c    |   2 +-
 drivers/gpu/drm/i915/gvt/display.h    |   2 +
 drivers/gpu/drm/i915/gvt/fb_decoder.c | 429 ++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/gvt/fb_decoder.h | 175 ++++++++++++++
 drivers/gpu/drm/i915/gvt/gvt.h        |   1 +
 6 files changed, 610 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/gvt/fb_decoder.c
 create mode 100644 drivers/gpu/drm/i915/gvt/fb_decoder.h
drivers/gpu/drm/i915/gvt/Makefile +2 -1
index f5486cb9..019d596 100644
@@ -1,7 +1,8 @@
 GVT_DIR := gvt
 GVT_SOURCE := gvt.o aperture_gm.o handlers.o vgpu.o trace_points.o firmware.o \
 	interrupt.o gtt.o cfg_space.o opregion.o mmio.o display.o edid.o \
-	execlist.o scheduler.o sched_policy.o render.o cmd_parser.o
+	execlist.o scheduler.o sched_policy.o render.o cmd_parser.o \
+	fb_decoder.o
 
 ccflags-y				+= -I$(src) -I$(src)/$(GVT_DIR)
 i915-y					+= $(addprefix $(GVT_DIR)/, $(GVT_SOURCE))
drivers/gpu/drm/i915/gvt/display.c +1 -1
index 2deb05f..58d90cf 100644
@@ -67,7 +67,7 @@ static int edp_pipe_is_enabled(struct intel_vgpu *vgpu)
 	return 1;
 }
 
-static int pipe_is_enabled(struct intel_vgpu *vgpu, int pipe)
+int pipe_is_enabled(struct intel_vgpu *vgpu, int pipe)
 {
 	struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv;
 
drivers/gpu/drm/i915/gvt/display.h +2 -0
index d73de22..b46b868 100644
@@ -179,4 +179,6 @@ int intel_vgpu_init_display(struct intel_vgpu *vgpu, u64 resolution);
 void intel_vgpu_reset_display(struct intel_vgpu *vgpu);
 void intel_vgpu_clean_display(struct intel_vgpu *vgpu);
 
+int pipe_is_enabled(struct intel_vgpu *vgpu, int pipe);
+
 #endif
drivers/gpu/drm/i915/gvt/fb_decoder.c new file +429 -0

429 lines not on this page · raw message

drivers/gpu/drm/i915/gvt/fb_decoder.h new file +175 -0

175 lines not on this page · raw message

drivers/gpu/drm/i915/gvt/gvt.h +1 -0
index ba53ad1..d0fe4d0 100644
@@ -46,6 +46,7 @@
 #include "sched_policy.h"
 #include "render.h"
 #include "cmd_parser.h"
+#include "fb_decoder.h"
 
 #define GVT_MAX_VGPU 8
 
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#2 lore raw

PATCH v12 2/6 drm: Introduce RGB 64-bit 16:16:16:16 float format

In reply to Tina Zhang

The RGB 64-bit 16:16:16:16 float pixel format is needed by windows guest VM. This patch is to introduce the format to drm.

v1:
Suggested by Ville to submit this patch to dri-devel.

---
 include/uapi/drm/drm_fourcc.h | 4 ++++
 1 file changed, 4 insertions(+)
include/uapi/drm/drm_fourcc.h +4 -0
index 7586c46..3e002e3 100644
@@ -113,6 +113,10 @@ extern "C" {
 
 #define DRM_FORMAT_AYUV		fourcc_code('A', 'Y', 'U', 'V') /* [31:0] A:Y:Cb:Cr 8:8:8:8 little endian */
 
+/* 64 bpp RGB */
+#define DRM_FORMAT_XRGB161616  fourcc_code('X', 'R', '4', '8') /* [63:0] x:R:G:B 16:16:16:16 little endian */
+#define DRM_FORMAT_XBGR161616  fourcc_code('X', 'B', '4', '8') /* [63:0] x:B:G:R 16:16:16:16 little endian */
+
 /*
  * 2 plane RGB + A
  * index 0 = RGB plane, same format as the corresponding non _A8 format has
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#3 lore raw

PATCH v12 3/6 drm/i915/gvt: Add RGB 64-bit 16:16:16:16 float format support

In reply to Tina Zhang

The RGB 64-bit 16:16:16:16 float pixel format is needed by windows 10 guest VM. This patch is to add this pixel format support to gvt device model. Without this patch, some Apps, e.g. "DXGIGammaVM.exe", will crash and make guest screen black.

---
 drivers/gpu/drm/i915/gvt/fb_decoder.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/gpu/drm/i915/gvt/fb_decoder.c +11 -0
index 2bd5b3c..739ca81 100644
@@ -54,6 +54,8 @@ static struct pixel_format bdw_pixel_formats[PRIMARY_FORMAT_NUM] = {
 		"32-bit RGBX (2:10:10:10 MSB-X:B:G:R)"},
 	[0xa] = {DRM_FORMAT_XRGB2101010, 32,
 		"32-bit BGRX (2:10:10:10 MSB-X:R:G:B)"},
+	[0xc] = {DRM_FORMAT_XRGB161616, 64,
+		"64-bit RGBX Floating Point(16:16:16:16 MSB-X:B:G:R)"},
 	[0xe] = {DRM_FORMAT_XBGR8888, 32,
 		"32-bit RGBX (8:8:8:8 MSB-X:B:G:R)"},
 };
@@ -75,6 +77,10 @@ static struct pixel_format skl_pixel_formats[] = {
 	{DRM_FORMAT_XBGR2101010, 32, "32-bit RGBX (2:10:10:10 MSB-X:B:G:R)"},
 	{DRM_FORMAT_XRGB2101010, 32, "32-bit BGRX (2:10:10:10 MSB-X:R:G:B)"},
 
+	{DRM_FORMAT_XRGB161616, 64,
+		"64-bit XRGB (16:16:16:16 MSB-X:R:G:B)"},
+	{DRM_FORMAT_XBGR161616, 64,
+		"64-bit XBGR (16:16:16:16 MSB-X:B:G:R)"},
 
 	/* non-supported format has bpp default to 0 */
 	{0, 0, NULL},
@@ -101,6 +107,9 @@ static int skl_format_to_drm(int format, bool rgb_order, bool alpha,
 	case PLANE_CTL_FORMAT_XRGB_2101010:
 		skl_pixel_formats_index = rgb_order ? 10 : 11;
 		break;
+	case PLANE_CTL_FORMAT_XRGB_16161616F:
+		skl_pixel_formats_index = rgb_order ? 12 : 13;
+		break;
 	case PLANE_CTL_FORMAT_YUV422:
 		skl_pixel_formats_index = yuv_order >> 16;
 		if (skl_pixel_formats_index > 3)
@@ -321,6 +330,8 @@ static struct pixel_format sprite_pixel_formats[SPRITE_FORMAT_NUM] = {
 	[0x0]  = {DRM_FORMAT_YUV422, 16, "YUV 16-bit 4:2:2 packed"},
 	[0x1]  = {DRM_FORMAT_XRGB2101010, 32, "RGB 32-bit 2:10:10:10"},
 	[0x2]  = {DRM_FORMAT_XRGB8888, 32, "RGB 32-bit 8:8:8:8"},
+	[0x3]  = {DRM_FORMAT_XRGB161616, 64,
+		    "RGB 64-bit 16:16:16:16 Floating Point"},
 	[0x4] = {DRM_FORMAT_AYUV, 32,
 		"YUV 32-bit 4:4:4 packed (8:8:8:8 MSB-X:Y:U:V)"},
 };
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#4 lore raw

PATCH v12 4/6 drm/i915/gvt: add opregion support

In reply to Tina Zhang

Windows guest UPT driver can use operegion to configure the setting for display. Without the opregion support, the display registers won't be set and this blocks display model to get the correct information of the guest display plane.

---
 drivers/gpu/drm/i915/gvt/hypercall.h |   1 +
 drivers/gpu/drm/i915/gvt/kvmgt.c     | 109 ++++++++++++++++++++++++++++++++++-
 drivers/gpu/drm/i915/gvt/mpt.h       |  15 +++++
 drivers/gpu/drm/i915/gvt/opregion.c  |  26 +++++++--
 drivers/gpu/drm/i915/gvt/vgpu.c      |   4 ++
 5 files changed, 146 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/gvt/hypercall.h +1 -0
index df7f33a..32c345c 100644
@@ -55,6 +55,7 @@ struct intel_gvt_mpt {
 			      unsigned long mfn, unsigned int nr, bool map);
 	int (*set_trap_area)(unsigned long handle, u64 start, u64 end,
 			     bool map);
+	int (*set_opregion)(void *vgpu);
 };
 
 extern struct intel_gvt_mpt xengt_mpt;
drivers/gpu/drm/i915/gvt/kvmgt.c +106 -3

157 lines not on this page · raw message

drivers/gpu/drm/i915/gvt/mpt.h +15 -0
index f0e5487..9e73f2e 100644
@@ -292,4 +292,19 @@ static inline int intel_gvt_hypervisor_set_trap_area(
 	return intel_gvt_host.mpt->set_trap_area(vgpu->handle, start, end, map);
 }
 
+/**
+ * intel_gvt_hypervisor_set_opregion - Set opregion for guest
+ * @vgpu: a vGPU
+ *
+ * Returns:
+ * Zero on success, negative error code if failed.
+ */
+static inline int intel_gvt_hypervisor_set_opregion(struct intel_vgpu *vgpu)
+{
+	if (!intel_gvt_host.mpt->set_opregion)
+		return 0;
+
+	return intel_gvt_host.mpt->set_opregion(vgpu);
+}
+
 #endif /* _GVT_MPT_H_ */
drivers/gpu/drm/i915/gvt/opregion.c +20 -6
index 3117991..04c0452 100644
@@ -113,23 +113,37 @@ void intel_vgpu_clean_opregion(struct intel_vgpu *vgpu)
  */
 int intel_vgpu_init_opregion(struct intel_vgpu *vgpu, u32 gpa)
 {
-	int ret;
+	int ret = 0;
+	unsigned long pfn;
 
 	gvt_dbg_core("vgpu%d: init vgpu opregion\n", vgpu->id);
 
-	if (intel_gvt_host.hypervisor_type == INTEL_GVT_HYPERVISOR_XEN) {
+	switch (intel_gvt_host.hypervisor_type) {
+	case INTEL_GVT_HYPERVISOR_KVM:
+		pfn = intel_gvt_hypervisor_gfn_to_mfn(vgpu, gpa >> PAGE_SHIFT);
+		vgpu_opregion(vgpu)->va = memremap(pfn << PAGE_SHIFT,
+						INTEL_GVT_OPREGION_SIZE,
+						MEMREMAP_WB);
+		if (!vgpu_opregion(vgpu)->va) {
+			gvt_vgpu_err("failed to map guest opregion\n");
+			ret = -EFAULT;
+		}
+		break;
+	case INTEL_GVT_HYPERVISOR_XEN:
 		gvt_dbg_core("emulate opregion from kernel\n");
 
 		ret = init_vgpu_opregion(vgpu, gpa);
 		if (ret)
-			return ret;
+			break;
 
 		ret = map_vgpu_opregion(vgpu, true);
-		if (ret)
-			return ret;
+		break;
+	default:
+		ret = -EINVAL;
+		gvt_vgpu_err("not supported hypervisor\n");
 	}
 
-	return 0;
+	return ret;
 }
 
 /**
drivers/gpu/drm/i915/gvt/vgpu.c +4 -0
index 90c14e6..03f9539 100644
@@ -383,6 +383,10 @@ static struct intel_vgpu *__intel_gvt_create_vgpu(struct intel_gvt *gvt,
 	if (ret)
 		goto out_clean_shadow_ctx;
 
+	ret = intel_gvt_hypervisor_set_opregion(vgpu);
+	if (ret)
+		goto out_clean_shadow_ctx;
+
 	mutex_unlock(&gvt->lock);
 
 	return vgpu;
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#5 lore raw

PATCH v12 5/6 vfio: ABI for mdev display dma-buf operation

In reply to Tina Zhang

Add VFIO_DEVICE_QUERY_GFX_PLANE ioctl command to let user mode query and get the plan and its related information.

The dma-buf's life cycle is handled by user mode and tracked by kernel. The returned fd in struct vfio_device_query_gfx_plane can be a new fd or an old fd of a re-exported dma-buf. Host User mode can check the value of fd and to see if it needs to create new resource according to the new fd or just use the existed resource related to the old fd.

---
 include/uapi/linux/vfio.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
include/uapi/linux/vfio.h +28 -0
index ae46105..827a230 100644
@@ -502,6 +502,34 @@ struct vfio_pci_hot_reset {
 
 #define VFIO_DEVICE_PCI_HOT_RESET	_IO(VFIO_TYPE, VFIO_BASE + 13)
 
+/**
+ * VFIO_DEVICE_QUERY_GFX_PLANE - _IOW(VFIO_TYPE, VFIO_BASE + 14, struct vfio_device_query_gfx_plane)
+ *
+ * Set the drm_plane_type and retrieve information about the gfx plane.
+ *
+ * Return: 0 on success, -errno on failure.
+ */
+struct vfio_device_gfx_plane_info {
+	__u32 argsz;
+	__u32 flags;
+	/* in */
+	__u32 drm_plane_type;	/* type of plane: DRM_PLANE_TYPE_* */
+	/* out */
+	__u32 drm_format;	/* drm format of plane */
+	__u64 drm_format_mod;   /* tiled mode */
+	__u32 width;	/* width of plane */
+	__u32 height;	/* height of plane */
+	__u32 stride;	/* stride of plane */
+	__u32 size;	/* size of plane in bytes, align on page*/
+	__u32 x_pos;	/* horizontal position of cursor plane, upper left corner in pixels */
+	__u32 y_pos;	/* vertical position of cursor plane, upper left corner in lines*/
+	__u32 region_index;
+	__s32 fd;	/* dma-buf fd */
+};
+
+#define VFIO_DEVICE_QUERY_GFX_PLANE _IO(VFIO_TYPE, VFIO_BASE + 14)
+
+
 /* -------- API for Type1 VFIO IOMMU -------- */
 
 /**
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#6 lore raw

PATCH v12 6/6 drm/i915: Introduce GEM proxy

In reply to Tina Zhang
---
 drivers/gpu/drm/i915/i915_gem.c        | 26 +++++++++++++++++++++++++-
 drivers/gpu/drm/i915/i915_gem_object.h |  9 +++++++++
 drivers/gpu/drm/i915/i915_gem_tiling.c |  5 +++++
 3 files changed, 39 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem.c +25 -1
index 1b2dfa8..ebacc04 100644
@@ -1612,6 +1612,12 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
 	if (!obj)
 		return -ENOENT;
 
+	/* proxy gem object does not support setting domain */
+	if (i915_gem_object_is_proxy(obj)) {
+		err = -EPERM;
+		goto out;
+	}
+
 	/* Try to flush the object off the GPU without holding the lock.
 	 * We will repeat the flush holding the lock in the normal manner
 	 * to catch cases where we are gazumped.
@@ -1680,6 +1686,12 @@ i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
 	if (!obj)
 		return -ENOENT;
 
+	/* proxy gem obj does not support this operation */
+	if (i915_gem_object_is_proxy(obj)) {
+		i915_gem_object_put(obj);
+		return -EPERM;
+	}
+
 	/* Pinned buffers may be scanout, so flush the cache */
 	i915_gem_object_flush_if_display(obj);
 	i915_gem_object_put(obj);
@@ -1730,7 +1742,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
 	 */
 	if (!obj->base.filp) {
 		i915_gem_object_put(obj);
-		return -EINVAL;
+		return -EPERM;
 	}
 
 	addr = vm_mmap(obj->base.filp, 0, args->size,
@@ -3764,6 +3776,12 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
 	if (!obj)
 		return -ENOENT;
 
+	/* proxy gem obj does not support setting caching mode */
+	if (i915_gem_object_is_proxy(obj)) {
+		ret = -EPERM;
+		goto out;
+	}
+
 	if (obj->cache_level == level)
 		goto out;
 
@@ -4210,6 +4228,12 @@ i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
 	if (!obj)
 		return -ENOENT;
 
+	/* proxy gem obj does not support changing backding storage */
+	if (i915_gem_object_is_proxy(obj)) {
+		err = -EPERM;
+		goto out;
+	}
+
 	err = mutex_lock_interruptible(&obj->mm.lock);
 	if (err)
 		goto out;
drivers/gpu/drm/i915/i915_gem_object.h +9 -0
index 5b19a49..c91e336 100644
@@ -39,6 +39,7 @@ struct drm_i915_gem_object_ops {
 	unsigned int flags;
 #define I915_GEM_OBJECT_HAS_STRUCT_PAGE BIT(0)
 #define I915_GEM_OBJECT_IS_SHRINKABLE   BIT(1)
+#define I915_GEM_OBJECT_IS_PROXY	BIT(2)
 
 	/* Interface between the GEM object and its backing storage.
 	 * get_pages() is called once prior to the use of the associated set
@@ -198,6 +199,8 @@ struct drm_i915_gem_object {
 		} userptr;
 
 		unsigned long scratch;
+
+		void *gvt_info;
 	};
 
 	/** for phys allocated objects */
@@ -300,6 +303,12 @@ i915_gem_object_is_shrinkable(const struct drm_i915_gem_object *obj)
 }
 
 static inline bool
+i915_gem_object_is_proxy(const struct drm_i915_gem_object *obj)
+{
+	return obj->ops->flags & I915_GEM_OBJECT_IS_PROXY;
+}
+
+static inline bool
 i915_gem_object_is_active(const struct drm_i915_gem_object *obj)
 {
 	return obj->active_count;
drivers/gpu/drm/i915/i915_gem_tiling.c +5 -0
index fb5231f..21ec066 100644
@@ -345,6 +345,11 @@ i915_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
 	if (!obj)
 		return -ENOENT;
 
+	if (i915_gem_object_is_proxy(obj)) {
+		err = -EPERM;
+		goto err;
+	}
+
 	if (!i915_tiling_ok(obj, args->tiling_mode, args->stride)) {
 		err = -EINVAL;
 		goto err;
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#7 lore raw

Re: [PATCH v12 6/6] drm/i915: Introduce GEM proxy

s/GEM proxy/a GEM proxy object/

Quoting Tina Zhang (2017-07-19 11:59:05)

Rationale goes here.

Quoted 12 lines
---
 drivers/gpu/drm/i915/i915_gem.c        | 26 +++++++++++++++++++++++++-
 drivers/gpu/drm/i915/i915_gem_object.h |  9 +++++++++
 drivers/gpu/drm/i915/i915_gem_tiling.c |  5 +++++
 3 files changed, 39 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem.c +0 -0
index 1b2dfa8..ebacc04 100644

drivers/gpu/drm/i915/i915_gem.c i915_gem_set_domain_ioctl(struct drm_device *dev, void *data, · line 1615

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem.c +1 -0
@@ -1612,6 +1612,12 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
        if (!obj)
                return -ENOENT;
 
+       /* proxy gem object does not support setting domain */

Yes, this is what the code is doing. The comment tells us why.

/*
* Proxy objects do not control access to the backing storage, ergo
* they cannot be used as a means to manipulate the cache domain
* tracking for that backing storage. The proxy object is always
* considered to be outside of any cache domain.
*/

However, set-domain does have some other side-effects that includes waiting which should still be performed, i.e. this check should be after the lockless wait.

drivers/gpu/drm/i915/i915_gem.c i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data, · line 1688

Quoted 12 lines
drivers/gpu/drm/i915/i915_gem.c +5 -0
+       if (i915_gem_object_is_proxy(obj)) {
+               err = -EPERM;
+               goto out;
+       }
+
        /* Try to flush the object off the GPU without holding the lock.
         * We will repeat the flush holding the lock in the normal manner
         * to catch cases where we are gazumped.
@@ -1680,6 +1686,12 @@ i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
        if (!obj)
                return -ENOENT;
 

A comment could explain that since proxy objects are barred from CPU access, we do not need to ban sw_finish as it is a nop.

Quoted 19 lines
drivers/gpu/drm/i915/i915_gem.c +7 -1
+       /* proxy gem obj does not support this operation */
+       if (i915_gem_object_is_proxy(obj)) {
+               i915_gem_object_put(obj);
+               return -EPERM;
+       }
+
        /* Pinned buffers may be scanout, so flush the cache */
        i915_gem_object_flush_if_display(obj);
        i915_gem_object_put(obj);
@@ -1730,7 +1742,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
         */
        if (!obj->base.filp) {
                i915_gem_object_put(obj);
-               return -EINVAL;
+               return -EPERM;
        }
 
        addr = vm_mmap(obj->base.filp, 0, args->size,

drivers/gpu/drm/i915/i915_gem.c int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data, · line 3779

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem.c +1 -0
@@ -3764,6 +3776,12 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
        if (!obj)
                return -ENOENT;
 
+       /* proxy gem obj does not support setting caching mode */

More rationale. Also is the proxied object (its target) also banned from changing the PTE bits or do we inherit all such changes automatically?

drivers/gpu/drm/i915/i915_gem.c i915_gem_madvise_ioctl(struct drm_device *dev, void *data, · line 4231

Quoted 13 lines
drivers/gpu/drm/i915/i915_gem.c +6 -0
+       if (i915_gem_object_is_proxy(obj)) {
+               ret = -EPERM;
+               goto out;
+       }
+
        if (obj->cache_level == level)
                goto out;
 
@@ -4210,6 +4228,12 @@ i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
        if (!obj)
                return -ENOENT;
 
+       /* proxy gem obj does not support changing backding storage */

This one could be generalised to I915_GEM_OBJECT_IS_SHRINKABLE?

Quoted 21 lines
drivers/gpu/drm/i915/i915_gem.c +5 -0
+       if (i915_gem_object_is_proxy(obj)) {
+               err = -EPERM;
+               goto out;
+       }
+
        err = mutex_lock_interruptible(&obj->mm.lock);
        if (err)
                goto out;
drivers/gpu/drm/i915/i915_gem_object.h +1 -0
index 5b19a49..c91e336 100644
@@ -39,6 +39,7 @@ struct drm_i915_gem_object_ops {
        unsigned int flags;
 #define I915_GEM_OBJECT_HAS_STRUCT_PAGE BIT(0)
 #define I915_GEM_OBJECT_IS_SHRINKABLE   BIT(1)
+#define I915_GEM_OBJECT_IS_PROXY       BIT(2)
 
        /* Interface between the GEM object and its backing storage.
         * get_pages() is called once prior to the use of the associated set

drivers/gpu/drm/i915/i915_gem_object.h struct drm_i915_gem_object { · line 203

Quoted 5 lines
drivers/gpu/drm/i915/i915_gem_object.h +2 -0
@@ -198,6 +199,8 @@ struct drm_i915_gem_object {
                } userptr;
 
                unsigned long scratch;
+
+               void *gvt_info;

Unrelated chunk, this should go into the gvt patch to use the object.

Quoted 21 lines
drivers/gpu/drm/i915/i915_gem_object.h +6 -0
        };
 
        /** for phys allocated objects */
@@ -300,6 +303,12 @@ i915_gem_object_is_shrinkable(const struct drm_i915_gem_object *obj)
 }
 
 static inline bool
+i915_gem_object_is_proxy(const struct drm_i915_gem_object *obj)
+{
+       return obj->ops->flags & I915_GEM_OBJECT_IS_PROXY;
+}
+
+static inline bool
 i915_gem_object_is_active(const struct drm_i915_gem_object *obj)
 {
        return obj->active_count;
drivers/gpu/drm/i915/i915_gem_tiling.c +0 -0
index fb5231f..21ec066 100644

drivers/gpu/drm/i915/i915_gem_tiling.c i915_gem_set_tiling_ioctl(struct drm_device *dev, void *data, · line 351

Quoted 7 lines
drivers/gpu/drm/i915/i915_gem_tiling.c +4 -0
@@ -345,6 +345,11 @@ i915_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
        if (!obj)
                return -ENOENT;
 
+       if (i915_gem_object_is_proxy(obj)) {
+               err = -EPERM;
+               goto err;
+       }

Changing the tiling mode may well be justifiable, even for a proxy since the tiling is local to the view. The ban on GVT behalf should be done via obj->framebuffer_references, and a good rationale given here on why the proxy should be banned.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#8 lore raw

RE: [PATCH v12 6/6] drm/i915: Introduce GEM proxy

Quoted 14 lines

-----Original Message-----
From: Chris Wilson [mailto:[email protected]]
Sent: Wednesday, July 19, 2017 7:20 PM
To: Zhang, Tina <[email protected]>; [email protected]; intel- [email protected]; [email protected]; [email protected]; [email protected]; Lv, Zhiyuan <[email protected]>; Wang, Zhi A <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Tian, Kevin <[email protected]>
Cc: Zhang, Tina <[email protected]>
Subject: Re: [PATCH v12 6/6] drm/i915: Introduce GEM proxy

Quoted 5 lines

s/GEM proxy/a GEM proxy object/

Quoting Tina Zhang (2017-07-19 11:59:05)

Rationale goes here.

Thanks for the comments. The idea behind the GEM proxy is that we want to propose a kind of GEM which content is produced by the guest VM and used by host. So, to host, this kind of GEM should be read only (both for CPU and GPU), and host cannot use ioctls to change or modify the GEM. I will add more comments in the next version. Thanks.

Quoted 28 lines

drivers/gpu/drm/i915/i915_gem.c i915_gem_set_domain_ioctl(struct drm_device

Quoted 13 lines
---
 drivers/gpu/drm/i915/i915_gem.c        | 26 +++++++++++++++++++++++++-
 drivers/gpu/drm/i915/i915_gem_object.h |  9 +++++++++
drivers/gpu/drm/i915/i915_gem_tiling.c |  5 +++++
 3 files changed, 39 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_gem.c index 1b2dfa8..ebacc04 100644

drivers/gpu/drm/i915/i915_gem.c +0 -0
@@ -1612,6 +1612,12 @@ i915_gem_set_domain_ioctl(struct drm_device

*dev, void *data,

drivers/gpu/drm/i915/i915_gem.c i915_gem_set_domain_ioctl(struct drm_device *dev, void *data, · line 1615

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem.c +1 -0
        if (!obj)
                return -ENOENT;
 
+       /* proxy gem object does not support setting domain */

Yes, this is what the code is doing. The comment tells us why.

/*
* Proxy objects do not control access to the backing storage, ergo
* they cannot be used as a means to manipulate the cache domain
* tracking for that backing storage. The proxy object is always
* considered to be outside of any cache domain.
*/

Quoted 2 lines

However, set-domain does have some other side-effects that includes waiting which should still be performed, i.e. this check should be after the lockless wait.

Is it the requirement of this ioctl? Other ioctls here in this patch, won't need it?

Quoted 11 lines

drivers/gpu/drm/i915/i915_gem.c i915_gem_sw_finish_ioctl(struct drm_device

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +5 -0
+       if (i915_gem_object_is_proxy(obj)) {
+               err = -EPERM;
+               goto out;
+       }
+
        /* Try to flush the object off the GPU without holding the lock.
         * We will repeat the flush holding the lock in the normal manner
         * to catch cases where we are gazumped.
@@ -1680,6 +1686,12 @@ i915_gem_sw_finish_ioctl(struct drm_device

*dev, void *data,

Quoted 6 lines

drivers/gpu/drm/i915/i915_gem.c i915_gem_set_domain_ioctl(struct drm_device *dev, void *data, · line 1614

Quoted 3 lines
drivers/gpu/drm/i915/i915_gem.c +0 -0
        if (!obj)
                return -ENOENT;
 

A comment could explain that since proxy objects are barred from CPU access, we do not need to ban sw_finish as it is a nop.

Agree.

Quoted 21 lines

drivers/gpu/drm/i915/i915_gem.c i915_gem_mmap_ioctl(struct drm_device *dev,

Quoted 11 lines
drivers/gpu/drm/i915/i915_gem.c +6 -0
+       /* proxy gem obj does not support this operation */
+       if (i915_gem_object_is_proxy(obj)) {
+               i915_gem_object_put(obj);
+               return -EPERM;
+       }
+
        /* Pinned buffers may be scanout, so flush the cache */
        i915_gem_object_flush_if_display(obj);
        i915_gem_object_put(obj);
@@ -1730,7 +1742,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev,

void *data,

drivers/gpu/drm/i915/i915_gem.c i915_gem_mmap_ioctl(struct drm_device *dev, void *data,

Quoted 9 lines
drivers/gpu/drm/i915/i915_gem.c +2 -1
         */
        if (!obj->base.filp) {
                i915_gem_object_put(obj);
-               return -EINVAL;
+               return -EPERM;
        }
 
        addr = vm_mmap(obj->base.filp, 0, args->size, @@ -3764,6
+3776,12 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void
Quoted 8 lines

*data,

Quoted 4 lines
        if (!obj)
                return -ENOENT;

+ /* proxy gem obj does not support setting caching mode */

More rationale. Also is the proxied object (its target) also banned from changing the PTE bits or do we inherit all such changes automatically?

From v2, cache_level isn't be set during the GEM generation, i.e. cache_level=0. And the PTE bits which is set by guest, won't be modified by host.

Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/i915_gem.c +5 -0
+       if (i915_gem_object_is_proxy(obj)) {
+               ret = -EPERM;
+               goto out;
+       }
+
        if (obj->cache_level == level)
                goto out;
Quoted 8 lines

drivers/gpu/drm/i915/i915_gem.c i915_gem_madvise_ioctl(struct drm_device

Quoted 1 line
drivers/gpu/drm/i915/i915_gem.c +0 -0
@@ -4210,6 +4228,12 @@ i915_gem_madvise_ioctl(struct drm_device

*dev, void *data,

drivers/gpu/drm/i915/i915_gem.c i915_gem_madvise_ioctl(struct drm_device *dev, void *data, · line 4231

Quoted 4 lines
drivers/gpu/drm/i915/i915_gem.c +1 -0
        if (!obj)
                return -ENOENT;
 
+       /* proxy gem obj does not support changing backding storage */

This one could be generalised to I915_GEM_OBJECT_IS_SHRINKABLE?

I suppose no. The backend pages should always be the guest framebuffer. And when to release it is up to user mode. If the kernel part senses the guest framebuffer is changed, it will generate a new GEM/dma-buf with the new framebuffer backend, to user mode.

Quoted 59 lines
Quoted 26 lines
drivers/gpu/drm/i915/i915_gem.c +5 -0
+       if (i915_gem_object_is_proxy(obj)) {
+               err = -EPERM;
+               goto out;
+       }
+
        err = mutex_lock_interruptible(&obj->mm.lock);
        if (err)
                goto out;
drivers/gpu/drm/i915/i915_gem_object.h +1 -0
index 5b19a49..c91e336 100644
@@ -39,6 +39,7 @@ struct drm_i915_gem_object_ops {
        unsigned int flags;
 #define I915_GEM_OBJECT_HAS_STRUCT_PAGE BIT(0)
 #define I915_GEM_OBJECT_IS_SHRINKABLE   BIT(1)
+#define I915_GEM_OBJECT_IS_PROXY       BIT(2)
 
        /* Interface between the GEM object and its backing storage.
         * get_pages() is called once prior to the use of the
associated set @@ -198,6 +199,8 @@ struct drm_i915_gem_object {
                } userptr;

                unsigned long scratch;

drivers/gpu/drm/i915/i915_gem_object.h struct drm_i915_gem_object { · line 203

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_object.h +2 -0
+
+               void *gvt_info;

Unrelated chunk, this should go into the gvt patch to use the object.

drivers/gpu/drm/i915/i915_gem_tiling.c i915_gem_set_tiling_ioctl(struct drm_device *dev,

Quoted 19 lines
        };

        /** for phys allocated objects */ @@ -300,6 +303,12 @@

i915_gem_object_is_shrinkable(const struct drm_i915_gem_object *obj) }

static inline bool

drivers/gpu/drm/i915/i915_gem_object.h +4 -0
+i915_gem_object_is_proxy(const struct drm_i915_gem_object *obj) {
+       return obj->ops->flags & I915_GEM_OBJECT_IS_PROXY; }
+
+static inline bool
 i915_gem_object_is_active(const struct drm_i915_gem_object *obj)  {
        return obj->active_count;
drivers/gpu/drm/i915/i915_gem_tiling.c +0 -0
index fb5231f..21ec066 100644
@@ -345,6 +345,11 @@ i915_gem_set_tiling_ioctl(struct drm_device *dev,

void *data,

drivers/gpu/drm/i915/i915_gem_tiling.c i915_gem_set_tiling_ioctl(struct drm_device *dev, void *data, · line 351

Quoted 7 lines
drivers/gpu/drm/i915/i915_gem_tiling.c +4 -0
        if (!obj)
                return -ENOENT;
 
+       if (i915_gem_object_is_proxy(obj)) {
+               err = -EPERM;
+               goto err;
+       }
Quoted 4 lines

Changing the tiling mode may well be justifiable, even for a proxy since the tiling is local to the view. The ban on GVT behalf should be done via obj->framebuffer_references, and a good rationale given here on why the proxy should be banned.

The GEM's content and tiling mode is produced by guest, in host, how could we guarantee the correction of the view if we allow the tiling modification through this ioctl? And I guess we tried the obj->framebuffer_references before, based on the discussion in v6 (https://lists.freedesktop.org/archives/intel-gvt-dev/2017-June/001146.html)
Thanks.

Tina

Quoted 1 line

-Chris

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#9 lore raw

✓ Fi.CI.BAT: success for drm/i915/gvt: Dma-buf support for GVT-g

In reply to Tina Zhang
== Series Details ==

== Series Details ==

Series: drm/i915/gvt: Dma-buf support for GVT-g
URL : https://patchwork.freedesktop.org/series/27572/
State : success

== Summary ==

Series 27572v1 drm/i915/gvt: Dma-buf support for GVT-g
https://patchwork.freedesktop.org/api/1.0/series/27572/revisions/1/mbox/

Test gem_exec_flush:

        Subgroup basic-batch-kernel-default-uc:
                pass       -> FAIL       (fi-snb-2600) fdo#100007
Test kms_pipe_crc_basic:
        Subgroup suspend-read-crc-pipe-b:
                pass       -> DMESG-WARN (fi-byt-j1900) fdo#101705

fdo#100007 https://bugs.freedesktop.org/show_bug.cgi?id=100007
fdo#101705 https://bugs.freedesktop.org/show_bug.cgi?id=101705

fi-bdw-5557u     total:279  pass:268  dwarn:0   dfail:0   fail:0   skip:11  time:453s
fi-bdw-gvtdvm    total:279  pass:265  dwarn:0   dfail:0   fail:0   skip:14  time:438s
fi-blb-e6850     total:279  pass:224  dwarn:1   dfail:0   fail:0   skip:54  time:356s
fi-bsw-n3050     total:279  pass:243  dwarn:0   dfail:0   fail:0   skip:36  time:545s
fi-bxt-j4205     total:279  pass:260  dwarn:0   dfail:0   fail:0   skip:19  time:512s
fi-byt-j1900     total:279  pass:254  dwarn:1   dfail:0   fail:0   skip:24  time:496s
fi-byt-n2820     total:279  pass:250  dwarn:1   dfail:0   fail:0   skip:28  time:485s
fi-glk-2a        total:279  pass:260  dwarn:0   dfail:0   fail:0   skip:19  time:606s
fi-hsw-4770      total:279  pass:263  dwarn:0   dfail:0   fail:0   skip:16  time:439s
fi-hsw-4770r     total:279  pass:263  dwarn:0   dfail:0   fail:0   skip:16  time:417s
fi-ilk-650       total:279  pass:229  dwarn:0   dfail:0   fail:0   skip:50  time:417s
fi-ivb-3520m     total:279  pass:261  dwarn:0   dfail:0   fail:0   skip:18  time:496s
fi-ivb-3770      total:279  pass:261  dwarn:0   dfail:0   fail:0   skip:18  time:472s
fi-kbl-7500u     total:279  pass:261  dwarn:0   dfail:0   fail:0   skip:18  time:469s
fi-kbl-7560u     total:279  pass:269  dwarn:0   dfail:0   fail:0   skip:10  time:576s
fi-kbl-r         total:279  pass:261  dwarn:0   dfail:0   fail:0   skip:18  time:590s
fi-pnv-d510      total:279  pass:222  dwarn:2   dfail:0   fail:0   skip:55  time:560s
fi-skl-6260u     total:279  pass:269  dwarn:0   dfail:0   fail:0   skip:10  time:463s
fi-skl-6700hq    total:279  pass:262  dwarn:0   dfail:0   fail:0   skip:17  time:582s
fi-skl-6700k     total:279  pass:257  dwarn:4   dfail:0   fail:0   skip:18  time:472s
fi-skl-6770hq    total:279  pass:269  dwarn:0   dfail:0   fail:0   skip:10  time:474s
fi-skl-gvtdvm    total:279  pass:266  dwarn:0   dfail:0   fail:0   skip:13  time:433s
fi-skl-x1585l    total:279  pass:268  dwarn:0   dfail:0   fail:0   skip:11  time:474s
fi-snb-2520m     total:279  pass:251  dwarn:0   dfail:0   fail:0   skip:28  time:546s
fi-snb-2600      total:279  pass:249  dwarn:0   dfail:0   fail:1   skip:29  time:404s

541e75cb2ac9f85388e9e6f228d98f266506eebd drm-tip: 2017y-07m-19d-10h-10m-36s UTC integration manifest 2cd6b00 drm/i915: Introduce GEM proxy
6ca8e14 vfio: ABI for mdev display dma-buf operation
fd3a206 drm/i915/gvt: add opregion support
11cb619 drm/i915/gvt: Add RGB 64-bit 16:16:16:16 float format support
38501de drm: Introduce RGB 64-bit 16:16:16:16 float format
879bb65 drm/i915/gvt: Add framebuffer decoder support

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_5233/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx