drm/i915/gvt: Dma-buf support for GVT-g
Subsystems (5)
v15 cover drm/i915/gvt: Dma-buf support for GVT-g
v14->15:
1) Add VFIO_DEVICE_GET_GFX_DMABUF ABI. (Gerd)
2) Add intel_vgpu_dmabuf_cleanup() to clean up the vGPU's dmabuf. (Gerd)
v13->v14:
1) add PROBE, DMABUF and REGION flags. (Alex)
2) return -ENXIO when gem proxy object is banned by ioctl. (Chris) (Daniel)
3) add some details about the float pixel format. (Daniel)
4) add F suffix to the defined name. (Daniel)
5) refine pixel format table. (Zhenyu)
v12->v13:
1) add comments to GEM proxy. (Chris)
2) don't ban GEM proxy in i915_gem_sw_finish_ioctl. (Chris)
3) check GEM proxy bar after finishing i915_gem_object_wait. (Chris)
4) remove GEM proxy bar in i915_gem_madvise_ioctl.
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 dri-devel at lists.freedesktop.org. (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 related 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 an uniform mechanism to share DMA buffers across different devices and subsystems. dma-buf for intel GVT-g is mainly used to share the vgpu's framebuffer to userspace to leverage userspace graphics stacks to render the framebuffer to the display monitor.
The main idea is that we create a gem object and set vgpu's framebuffer as its backing storage. Then, export a dma-buf associated with this gem object. With the fd of this dma-buf, userspace can directly handle this buffer.
This patch set can be tried with the following example:
git://git.kraxel.org/qemu branch: work/intel-vgpu
Tina Zhang (7):
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 drm/i915/gvt: Add opregion support
vfio: ABI for mdev display dma-buf operation drm/i915: Introduce GEM proxy
drm/i915/gvt: Dmabuf support for GVT-g
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/dmabuf.c | 513 ++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/gvt/dmabuf.h | 65 ++++ drivers/gpu/drm/i915/gvt/fb_decoder.c | 521 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/gvt/fb_decoder.h | 169 +++++++++++ drivers/gpu/drm/i915/gvt/gvt.c | 2 + drivers/gpu/drm/i915/gvt/gvt.h | 12 + drivers/gpu/drm/i915/gvt/hypercall.h | 3 + drivers/gpu/drm/i915/gvt/kvmgt.c | 169 ++++++++++- drivers/gpu/drm/i915/gvt/mpt.h | 45 +++ drivers/gpu/drm/i915/gvt/opregion.c | 26 +- drivers/gpu/drm/i915/gvt/vgpu.c | 9 +- drivers/gpu/drm/i915/i915_gem.c | 24 +- drivers/gpu/drm/i915/i915_gem_object.h | 9 + drivers/gpu/drm/i915/i915_gem_tiling.c | 8 + include/uapi/drm/drm_fourcc.h | 4 + include/uapi/linux/vfio.h | 62 ++++ 19 files changed, 1635 insertions(+), 13 deletions(-) create mode 100644 drivers/gpu/drm/i915/gvt/dmabuf.c create mode 100644 drivers/gpu/drm/i915/gvt/dmabuf.h create mode 100644 drivers/gpu/drm/i915/gvt/fb_decoder.c create mode 100644 drivers/gpu/drm/i915/gvt/fb_decoder.h
Signature · 1 line
2.7.4
PATCH v15 1/7 drm/i915/gvt: Add framebuffer decoder support
This patch is to introduce the framebuffer decoder which can decode guest OS's framebuffer information, including primary, cursor and sprite plane.
v14:
- refine pixel format table. (Zhenyu)
v9:
- move drm format change to a separate patch. (Xiaoguang)
v8:
- fix a bug in decoding primary plane. (Tina)
v7:
- refine framebuffer decoder code. (Zhenyu)
--- 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 | 507 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/gvt/fb_decoder.h | 169 ++++++++++++ drivers/gpu/drm/i915/gvt/gvt.h | 1 + 6 files changed, 682 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
@@ -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
@@ -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
@@ -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 +507 -0
507 lines not on this page · raw message
drivers/gpu/drm/i915/gvt/fb_decoder.h new file +169 -0
169 lines not on this page · raw message
drivers/gpu/drm/i915/gvt/gvt.h +1 -0
@@ -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 · 1 line
2.7.4
PATCH v15 2/7 drm: Introduce RGB 64-bit 16:16:16:16 float format
In reply to Tina ZhangThe RGB 64-bit 16:16:16:16 float pixel format is needed by some Apps in windows. The float format in each component is 1:5:10 MSb-sign:exponent:
fraction.
This patch is to introduce the format to drm, so that the windows guest's framebuffer in this kind of format can be recognized and used by linux host.
v14:
- add some details about the float pixel format. (Daniel)
- add F suffix to the defined name. (Daniel)
v12:
- send to dri-devel at lists.freedesktop.org. (Ville)
v9:
- separated from framebuffer decoder patch. (Zhenyu) (Xiaoguang)
--- include/uapi/drm/drm_fourcc.h | 4 ++++ 1 file changed, 4 insertions(+)
include/uapi/drm/drm_fourcc.h +4 -0
@@ -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 16:16:16:16 Floating Point */ +#define DRM_FORMAT_XRGB161616F fourcc_code('X', 'R', '3', 'F')/* [63:0] x:R:G:B 16:16:16:16 little endian */ +#define DRM_FORMAT_XBGR161616F fourcc_code('X', 'B', '3', 'F')/* [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
PATCH v15 3/7 drm/i915/gvt: Add RGB 64-bit 16:16:16:16 float format
In reply to Tina ZhangThe 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 | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/gvt/fb_decoder.c +21 -7
@@ -52,6 +52,8 @@ static struct pixel_format bdw_pixel_formats[] = { {DRM_FORMAT_XRGB2101010, 32, "32-bit BGRX (2:10:10:10 MSB-X:R:G:B)"}, {DRM_FORMAT_XBGR8888, 32, "32-bit RGBX (8:8:8:8 MSB-X:B:G:R)"}, + {DRM_FORMAT_XRGB161616F, 64, + "64-bit XRGB Floating Point (16:16:16:16 MSB-X:R:G:B)"},/* non-supported format has bpp default to 0 */ {0, 0, NULL},
@@ -73,13 +75,18 @@ 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_XRGB161616F, 64, + "64-bit XRGB Floating Point (16:16:16:16 MSB-X:R:G:B)"}, + {DRM_FORMAT_XBGR161616F, 64, + "64-bit XBGR Floating Point (16:16:16:16 MSB-X:B:G:R)"}, +/* non-supported format has bpp default to 0 */ {0, 0, NULL}, };static int bdw_format_to_drm (int format) { -int bdw_pixel_formats_index =6 ; +int bdw_pixel_formats_index =7 ;switch (format) {case DISPPLANE_8BPP :
@@ -100,7 +107,9 @@ static int bdw_format_to_drm(int format)case DISPPLANE_RGBX888 : bdw_pixel_formats_index =5 ;break ; - +case DISPPLANE_RGBX161616 : + bdw_pixel_formats_index =6 ; +break ;default :break ; }
@@ -111,7 +120,7 @@ static int bdw_format_to_drm(int format)static int skl_format_to_drm (int format,bool rgb_order,bool alpha,int yuv_order) { -int skl_pixel_formats_index =12 ; +int skl_pixel_formats_index =14 ;switch (format) {case PLANE_CTL_FORMAT_INDEXED :
@@ -129,6 +138,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 )
@@ -389,11 +401,13 @@ int intel_vgpu_decode_cursor_plane(struct intel_vgpu *vgpu,#define SPRITE_FORMAT_NUM (1 << 3)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" }, + [0x0 ] = {DRM_FORMAT_YUV422 ,16 ,"16-bit YUV 4:2:2 packed" }, + [0x1 ] = {DRM_FORMAT_XRGB2101010 ,32 ,"32-bit BGRX (2:10:10:10 MSB-X:R:G:B)" }, + [0x2 ] = {DRM_FORMAT_XRGB8888 ,32 ,"32-bit RGBX (8:8:8:8 MSB-X:B:G:R)" }, + [0x3 ] = {DRM_FORMAT_XRGB161616F ,64 , +"64-bit XRGB Floating Point (16:16:16:16 MSB-X:R:G:B)" }, [0x4 ] = {DRM_FORMAT_AYUV ,32 , -"YUV 32-bit 4:4:4 packed (8:8:8:8 MSB-X:Y:U:V)" }, +"32-bit YUV 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
PATCH v15 4/7 drm/i915/gvt: Add opregion support
In reply to Tina ZhangWindows guest driver needs vbt in opregion, to configure the setting for display. Without opregion support, the display registers won't be set and this blocks display model to get the correct information of the guest display plane.
This patch is to provide a virtual opregion for guest. Current implementation is to fill the virtual opregion with the content in host's opregion. The original author of this patch is Xiaoguang Chen.
--- 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
@@ -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
@@ -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
@@ -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
@@ -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
Re: [PATCH v15 4/7] drm/i915/gvt: Add opregion support
Quoted 24 lines · Tina Zhang
Windows guest driver needs vbt in opregion, to configure the setting for display. Without opregion support, the display registers won't be set and this blocks display model to get the correct information of the guest display plane.
This patch is to provide a virtual opregion for guest. Current implementation is to fill the virtual opregion with the content in host's opregion. The original author of this patch is Xiaoguang Chen.
Signed-off-by Bing Niu <[email protected]>Signed-off-by Tina Zhang <[email protected]>--- 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 +0
-0
drivers/gpu/drm/i915/gvt/hypercall.h struct intel_gvt_mpt { · line 58
Quoted 4 lines
drivers/gpu/drm/i915/gvt/hypercall.h +1
-0@@ -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);
Seems we try to hide struct intel_vgpu for kvmgt, but acctually kvmgt already use it. So set type as struct intel_vgpu directly? I am not sure about xengt, but the code shows that 'handle' is correct thing?
Quoted 32 lines
drivers/gpu/drm/i915/gvt/hypercall.h +0
-0};extern struct intel_gvt_mpt xengt_mpt;drivers/gpu/drm/i915/gvt/kvmgt.c +12
-0@@ -53,11 +53,23 @@ static const struct intel_gvt_ops *intel_gvt_ops;#define VFIO_PCI_INDEX_TO_OFFSET (index) ((u64)(index) << VFIO_PCI_OFFSET_SHIFT)#define VFIO_PCI_OFFSET_MASK (((u64)(1) << VFIO_PCI_OFFSET_SHIFT) - 1) +#define OPREGION_SIGNATURE "IntelGraphicsMem" + +struct vfio_region ; +struct intel_vgpu_regops { +size_t (*rw)(struct intel_vgpu *vgpu,char *buf, +size_t count,loff_t *ppos,bool iswrite); +void (*release)(struct intel_vgpu *vgpu, +struct vfio_region *region); +}; +struct vfio_region {u32 type;u32 subtype;size_t size;u32 flags; +const struct intel_vgpu_regops *ops; +void *data; };struct kvmgt_pgfn {
drivers/gpu/drm/i915/gvt/kvmgt.c static void kvmgt_protect_table_del(struct kvmgt_guest_info *info, · line 446
Quoted 5 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +2
-0@@ -430,6 +442,91 @@ static void kvmgt_protect_table_del(struct kvmgt_guest_info *info, } } +static size_t intel_vgpu_reg_rw_opregion (struct intel_vgpu *vgpu,char *buf, +size_t count,loff_t *ppos,bool iswrite)
Personally I think intel_vgpu_rw_opregion() is better. :)
Quoted 18 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +18
-0+{ +unsigned int i =VFIO_PCI_OFFSET_TO_INDEX (*ppos) - +VFIO_PCI_NUM_REGIONS ; +void *base = vgpu->vdev.region[i].data; +loff_t pos = *ppos &VFIO_PCI_OFFSET_MASK ; + +if (pos >= vgpu->vdev.region[i].size || iswrite) { +gvt_vgpu_err ("invalid op or offset for Intel vgpu OpRegion\n" ); +return -EINVAL ; + } + count =min (count, (size_t )(vgpu->vdev.region[i].size - pos)); +memcpy (buf, base + pos, count); + +return count; +} + +static void intel_vgpu_reg_release_opregion (struct intel_vgpu *vgpu, +struct vfio_region *region)
drivers/gpu/drm/i915/gvt/kvmgt.c static void kvmgt_protect_table_del(struct kvmgt_guest_info *info, · line 474
Quoted 10 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +10
-0+{ +memunmap (region->data); +} + +static const struct intel_vgpu_regops intel_vgpu_regops_opregion = { + .rw = intel_vgpu_reg_rw_opregion, + .release = intel_vgpu_reg_release_opregion, +}; + +static int intel_vgpu_register_reg(struct intel_vgpu *vgpu,
Maybe full name xx_register_region? coufusing between a register and region.
Quoted 28 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +28
-0+ unsigned int type, unsigned int subtype, + const struct intel_vgpu_regops *ops, + size_t size, u32 flags, void *data) +{ + struct vfio_region *region; + + region =krealloc (vgpu->vdev.region, + (vgpu->vdev.num_regions +1 ) *sizeof (*region), +GFP_KERNEL ); +if (!region) +return -ENOMEM ; + + vgpu->vdev.region = region; + vgpu->vdev.region[vgpu->vdev.num_regions].type = type; + vgpu->vdev.region[vgpu->vdev.num_regions].subtype = subtype; + vgpu->vdev.region[vgpu->vdev.num_regions].ops = ops; + vgpu->vdev.region[vgpu->vdev.num_regions].size = size; + vgpu->vdev.region[vgpu->vdev.num_regions].flags = flags; + vgpu->vdev.region[vgpu->vdev.num_regions].data = data; + vgpu->vdev.num_regions++; + +return 0 ; +} + +static int kvmgt_set_opregion (void *p_vgpu) +{ +struct intel_vgpu *vgpu = (struct intel_vgpu *)p_vgpu; +unsigned int addr;
drivers/gpu/drm/i915/gvt/kvmgt.c static void kvmgt_protect_table_del(struct kvmgt_guest_info *info, · line 512
Quoted 10 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +10
-0+void *base; +int ret; + + addr = vgpu->gvt->opregion.opregion_pa; +if (!addr || !(~addr)) +return -ENODEV ; + + base =memremap (addr,OPREGION_SIZE ,MEMREMAP_WB ); +if (!base) +return -ENOMEM ;
No need map again, i915 has mapped it (dev_priv->opregion->header).
drivers/gpu/drm/i915/gvt/kvmgt.c static void kvmgt_protect_table_del(struct kvmgt_guest_info *info, · line 518
Quoted 6 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +6
-0+ +if (memcmp (base,OPREGION_SIGNATURE ,16 )) { +memunmap (base); +return -EINVAL ; + } +
Just check "opregion->header != NULL", since i915 already validates it.
Quoted 24 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +12
-1+ ret =intel_vgpu_register_reg (vgpu, +PCI_VENDOR_ID_INTEL |VFIO_REGION_TYPE_PCI_VENDOR_TYPE , +VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION , + &intel_vgpu_regops_opregion,OPREGION_SIZE , +VFIO_REGION_INFO_FLAG_READ , base); +if (ret) +memunmap (base); + +return ret; +} +static int intel_vgpu_create (struct kobject *kobj,struct mdev_device *mdev) {struct intel_vgpu *vgpu =NULL ;@@ -646,7 +743,7 @@ static ssize_t intel_vgpu_rw(struct mdev_device *mdev, char *buf,int ret = -EINVAL ; -if (index >=VFIO_PCI_NUM_REGIONS ) { +if (index >=VFIO_PCI_NUM_REGIONS + vgpu->vdev.num_regions) {gvt_vgpu_err ("invalid index: %u\n" , index);return -EINVAL ; }
drivers/gpu/drm/i915/gvt/kvmgt.c static ssize_t intel_vgpu_rw(struct mdev_device *mdev, char *buf, · line 784
Quoted 9 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +4
-1@@ -680,8 +777,11 @@ static ssize_t intel_vgpu_rw(struct mdev_device *mdev, char *buf,case VFIO_PCI_BAR5_REGION_INDEX :case VFIO_PCI_VGA_REGION_INDEX :case VFIO_PCI_ROM_REGION_INDEX : +break ;default : -gvt_vgpu_err ("unsupported region: %u\n" , index); + index -=VFIO_PCI_NUM_REGIONS ; +return vgpu->vdev.region[index].ops->rw (vgpu, buf, count, + ppos, is_write);
Make region ops gerneric is great. You can factor out MMIO and CFG region ops as well. It is better not to mix generic and special handling.
Quoted 68 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +4
-1}return ret ==0 ? count : ret;@@ -944,7 +1044,8 @@ static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd, info.flags =VFIO_DEVICE_FLAGS_PCI ; info.flags |=VFIO_DEVICE_FLAGS_RESET ; - info.num_regions =VFIO_PCI_NUM_REGIONS ; + info.num_regions =VFIO_PCI_NUM_REGIONS + + vgpu->vdev.num_regions; info.num_irqs =VFIO_PCI_NUM_IRQS ; return copy_to_user((void __user *)arg, &info, minsz) ?@@ -1065,6 +1166,7 @@ static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd, }if (caps.size) { + info.flags |=VFIO_REGION_INFO_FLAG_CAPS ;if (info.argsz <sizeof (info) + caps.size) { info.argsz =sizeof (info) + caps.size; info.cap_offset =0 ;@@ -1513,6 +1615,7 @@ struct intel_gvt_mpt kvmgt_mpt = { .read_gpa = kvmgt_read_gpa, .write_gpa = kvmgt_write_gpa, .gfn_to_mfn = kvmgt_gfn_to_pfn, + .set_opregion = kvmgt_set_opregion, };EXPORT_SYMBOL_GPL (kvmgt_mpt);drivers/gpu/drm/i915/gvt/mpt.h +15
-0@@ -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 +2
-2@@ -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 ) {
drivers/gpu/drm/i915/gvt/opregion.c void intel_vgpu_clean_opregion(struct intel_vgpu *vgpu) · line 130
Quoted 10 lines
drivers/gpu/drm/i915/gvt/opregion.c +10
-0+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 ; + }
ditto.
Quoted 45 lines
drivers/gpu/drm/i915/gvt/opregion.c +8
-4+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@@ -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-gvt-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gvt-dev
Signature · 2 lines
Thanks, Changbin Du
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v15 5/7 vfio: ABI for mdev display dma-buf operation
In reply to Tina ZhangAdd VFIO_DEVICE_QUERY_GFX_PLANE ioctl command to let user mode query and get the plan and its related information. This ioctl can be invoked with:
1) either flag DMABUF or REGION is set. Vendor driver returns success and the plane_info only when the specific kind of buffer is supported.
2) flag PROBE is set with either DMABUF or REGION. Vendor driver returns success only when the specific kind of buffer is supported.
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.
v15:
- add a ioctl to get a dmabuf for a given dmabuf id. (Gerd)
v14:
- add PROBE, DMABUF and REGION flags. (Alex)
v12:
- add drm_format_mod back. (Gerd and Zhenyu)
- add region_index. (Gerd)
v11:
- rename plane_type to drm_plane_type. (Gerd)
- move fields of vfio_device_query_gfx_plane to vfio_device_gfx_plane_info. (Gerd)
- remove drm_format_mod, start fields. (Daniel)
- remove plane_id.
v10:
- refine the ABI API VFIO_DEVICE_QUERY_GFX_PLANE. (Alex) (Gerd)
v3:
- 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. (Gerd)
--- include/uapi/linux/vfio.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)
include/uapi/linux/vfio.h +62 -0
@@ -502,6 +502,68 @@ 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 flags, then retrieve the gfx plane info. +* +* flags supported: +* - VFIO_GFX_PLANE_TYPE_PROBE and VFIO_GFX_PLANE_TYPE_DMABUF are set +* to ask if the mdev supports dma-buf. 0 on support, -EINVAL on no +* support for dma-buf. +* - VFIO_GFX_PLANE_TYPE_PROBE and VFIO_GFX_PLANE_TYPE_REGION are set +* to ask if the mdev supports region. 0 on support, -EINVAL on no +* support for region. +* - VFIO_GFX_PLANE_TYPE_DMABUF or VFIO_GFX_PLANE_TYPE_REGION is set +* with each call to query the plane info. +* - Others are invalid and return -EINVAL. +* +* Return: 0 on success, -ENODEV with all out fields zero on mdev +* device initialization, -errno on other failure. +*/ +struct vfio_device_gfx_plane_info { +__u32 argsz; +__u32 flags; +#define VFIO_GFX_PLANE_TYPE_PROBE (1 << 0) +#define VFIO_GFX_PLANE_TYPE_DMABUF (1 << 1) +#define VFIO_GFX_PLANE_TYPE_REGION (1 << 2) +/* 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 */ +__u32 y_pos;/* vertical position of cursor plane*/ +union { +__u32 region_index;/* region index */ +__s32 dmabuf_id;/* dma-buf fd */ + }; +}; + +#define VFIO_DEVICE_QUERY_GFX_PLANE _IO(VFIO_TYPE, VFIO_BASE + 14) + +/** +* VFIO_DEVICE_GET_GFX_DMABUF - _IOW(VFIO_TYPE, VFIO_BASE + 15, +* struct vfio_device_gfx_dmabuf_fd) +* +* Return: 0 on success, -errno on failure. +*/ +struct vfio_device_gfx_dmabuf_fd { +__u32 argsz; +__u32 flags; +/* in */ +__u32 dmabuf_id; +/* out */ +__s32 dmabuf_fd; +}; + +#define VFIO_DEVICE_GET_GFX_DMABUF _IO(VFIO_TYPE, VFIO_BASE + 15) +/* -------- 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
Re: [PATCH v15 5/7] vfio: ABI for mdev display dma-buf operation
Quoted 11 lines · Tina Zhang
Add
VFIO_DEVICE_QUERY_GFX_PLANEioctl command to let user mode query and
get the plan and its related information. This ioctl can be invoked with:
1) either flag DMABUF or REGION is set. Vendor driver returns success and
theplane_infoonly when the specific kind of buffer is supported.
2) flag PROBE is set with either DMABUF or REGION. Vendor driver returns
success only when the specific kind of buffer is supported.
Quoted 8 lines
The dma-buf's life cycle is handled by user mode and tracked by kernel.
The returned fd in structvfio_device_query_gfx_planecan 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.
cheers,
Gerd
Re: [PATCH v15 5/7] vfio: ABI for mdev display dma-buf operation
In reply to Tina ZhangQuoted 2 lines · On Tue, 10 Oct 2017 17:50:05 +0800 Tina Zhang <[email protected]> wrote:
Add
VFIO_DEVICE_QUERY_GFX_PLANEioctl command to let user mode query and get the plan and its related information. This ioctl can be invoked with:
s/plan/plane/
Quoted 57 lines
1) either flag DMABUF or REGION is set. Vendor driver returns success and the
plane_infoonly when the specific kind of buffer is supported.
2) flag PROBE is set with either DMABUF or REGION. Vendor driver returns success only when the specific kind of buffer is supported.The dma-buf's life cycle is handled by user mode and tracked by kernel. The returned fd in struct
vfio_device_query_gfx_planecan 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.v15:
- add a ioctl to get a dmabuf for a given dmabuf id. (Gerd)v14:
- add PROBE, DMABUF and REGION flags. (Alex)v12:
- adddrm_format_modback. (Gerd and Zhenyu)
- addregion_index. (Gerd)v11:
- renameplane_typetodrm_plane_type. (Gerd)
- move fields ofvfio_device_query_gfx_planetovfio_device_gfx_plane_info. (Gerd)
- removedrm_format_mod, start fields. (Daniel)
- removeplane_id.v10:
- refine the ABI APIVFIO_DEVICE_QUERY_GFX_PLANE. (Alex) (Gerd)v3:
- add a fieldgvt_plane_infoin thedrm_i915_gem_objstructure to save the decoded plane information to avoid look up while need the plane info. (Gerd)Signed-off-by Tina Zhang <[email protected]>Cc Gerd Hoffmann <[email protected]>Cc Alex Williamson <[email protected]>Cc Daniel Vetter <[email protected]>--- include/uapi/linux/vfio.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)include/uapi/linux/vfio.h +5
-0@@ -502,6 +502,68 @@ 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 flags, then retrieve the gfx plane info.
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 519
Quoted 10 lines
include/uapi/linux/vfio.h +10
-0+* +* flags supported: +* - VFIO_GFX_PLANE_TYPE_PROBE and VFIO_GFX_PLANE_TYPE_DMABUF are set +* to ask if the mdev supports dma-buf. 0 on support, -EINVAL on no +* support for dma-buf. +* - VFIO_GFX_PLANE_TYPE_PROBE and VFIO_GFX_PLANE_TYPE_REGION are set +* to ask if the mdev supports region. 0 on support, -EINVAL on no +* support for region. +* - VFIO_GFX_PLANE_TYPE_DMABUF or VFIO_GFX_PLANE_TYPE_REGION is set +* with each call to query the plane info.
So dmabuf_id is effectively just a token that can be fed into GET_GFX_DMABUF to get the fd. The implementation of the token is vendor specific, but can be thought of as some sort of sequence ID or generation ID (but not necessarily monotonically increasing), so GET_GFX_DMABUF may fail if the previously provided dmabuf_id is no longer valid. Do I have this correct?
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 520
Quoted 1 line
include/uapi/linux/vfio.h +1
-0+* - Others are invalid and return -EINVAL.
And I see that in patch 7/7 that i915 is checking explicitly for only these flag combinations, great!
Quoted 14 lines
include/uapi/linux/vfio.h +14
-0+* +* Return: 0 on success, -ENODEV with all out fields zero on mdev +* device initialization, -errno on other failure. +*/ +struct vfio_device_gfx_plane_info { +__u32 argsz; +__u32 flags; +#define VFIO_GFX_PLANE_TYPE_PROBE (1 << 0) +#define VFIO_GFX_PLANE_TYPE_DMABUF (1 << 1) +#define VFIO_GFX_PLANE_TYPE_REGION (1 << 2) +/* in */ +__u32 drm_plane_type;/* type of plane: DRM_PLANE_TYPE_* */ +/* out */ +__u32 drm_format;/* drm format of plane */
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 544
Quoted 10 lines
include/uapi/linux/vfio.h +10
-0+__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 */ +__u32 y_pos;/* vertical position of cursor plane*/ +union { +__u32 region_index;/* region index */ +__s32 dmabuf_id;/* dma-buf fd */
"dma-buf fd", but it's not an fd. Why is this signed since it's no longer an fd?
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 555
Quoted 11 lines
include/uapi/linux/vfio.h +11
-0+ }; +}; + +#define VFIO_DEVICE_QUERY_GFX_PLANE _IO(VFIO_TYPE, VFIO_BASE + 14) + +/** +* VFIO_DEVICE_GET_GFX_DMABUF - _IOW(VFIO_TYPE, VFIO_BASE + 15, +* struct vfio_device_gfx_dmabuf_fd) +* +* Return: 0 on success, -errno on failure. +*/
So given a dmabuf_id, return a dmabuf_fd, which may be the same as a fd previously returned to the user. In the latter case, can we assume that there's no new reference added to the existing fd? Is the user permitted to cache the dmabuf_id to dmabuf_fd mapping? Similarly, if a user already has a dmabuf_fd, can calling GET_GFX_DMABUF ever fail or return a different result for the same dmabuf_id which provided that fd? Maybe we could define some of these behaviors in the header file to keep vendor implementations consistent.
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 558
Quoted 3 lines
include/uapi/linux/vfio.h +3
-0+struct vfio_device_gfx_dmabuf_fd { +__u32 argsz; +__u32 flags;
Patch 7/7 however fails to validate this flags field. It needs to return -EINVAL if any unsupported flags are set, which at this point is all of them.
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 560
Quoted 2 lines
include/uapi/linux/vfio.h +2
-0+/* in */ +__u32 dmabuf_id;
This unsigned dmabuf_id is probably correct, but it doesn't match the signed one provided above.
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 563
Quoted 3 lines
include/uapi/linux/vfio.h +3
-0+/* out */ +__s32 dmabuf_fd; +};
VFIO_GROUP_GET_DEVICE_FD returns the fd through the return code, is there a reason to do it differently here? GET_DEVICE_FD also only takes a char parameter without the extra future proofing, I wonder if this ioctl is simple enough to do the same.
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 569
Quoted 6 lines
include/uapi/linux/vfio.h +3
-0+ +#define VFIO_DEVICE_GET_GFX_DMABUF _IO(VFIO_TYPE, VFIO_BASE + 15) +/* -------- API for Type1 VFIO IOMMU -------- */ /**
Thanks,
Alex
RE: [PATCH v15 5/7] vfio: ABI for mdev display dma-buf operation
Quoted 13 lines
-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Wednesday, October 11, 2017 3:17 AM
To: Zhang, Tina <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Lv, Zhiyuan <[email protected]>; Wang, Zhi A <[email protected]>; Tian, Kevin <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; Daniel Vetter <[email protected]>
Subject: Re: [PATCH v15 5/7] vfio: ABI for mdev display dma-buf operation
Quoted 7 lines
Quoted 2 lines · On Tue, 10 Oct 2017 17:50:05 +0800 Tina Zhang <[email protected]> wrote:
Add
VFIO_DEVICE_QUERY_GFX_PLANEioctl command to let user mode query and get the plan and its related information. This ioctl can be invoked with:s/plan/plane/
Sorry about this typo :).
Quoted 71 lines
Quoted 51 lines
1) either flag DMABUF or REGION is set. Vendor driver returns success and the
plane_infoonly when the specific kind of buffer is supported.
2) flag PROBE is set with either DMABUF or REGION. Vendor driver returns success only when the specific kind of buffer is supported.The dma-buf's life cycle is handled by user mode and tracked by kernel. The returned fd in struct
vfio_device_query_gfx_planecan 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.v15:
- add a ioctl to get a dmabuf for a given dmabuf id. (Gerd)v14:
- add PROBE, DMABUF and REGION flags. (Alex)v12:
- adddrm_format_modback. (Gerd and Zhenyu)
- addregion_index. (Gerd)v11:
- renameplane_typetodrm_plane_type. (Gerd)
- move fields ofvfio_device_query_gfx_planetovfio_device_gfx_plane_info. (Gerd)
- removedrm_format_mod, start fields. (Daniel)
- removeplane_id.v10:
- refine the ABI APIVFIO_DEVICE_QUERY_GFX_PLANE. (Alex) (Gerd)v3:
- add a fieldgvt_plane_infoin thedrm_i915_gem_objstructure to save the decoded plane information to avoid look up while need the plane info. (Gerd)Signed-off-by Tina Zhang <[email protected]>Cc Gerd Hoffmann <[email protected]>Cc Alex Williamson <[email protected]>Cc Daniel Vetter <[email protected]>--- include/uapi/linux/vfio.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)include/uapi/linux/vfio.h +0
-0include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 503
Quoted 2 lines
include/uapi/linux/vfio.h +0
-0@@ -502,6 +502,68 @@ struct vfio_pci_hot_reset {#define VFIO_DEVICE_PCI_HOT_RESET _IO(VFIO_TYPE, VFIO_BASE +13)
include/uapi/linux/vfio.h struct vfio_pci_hot_reset {
Quoted 9 lines
include/uapi/linux/vfio.h +8
-0+/** +* VFIO_DEVICE_QUERY_GFX_PLANE - _IOW(VFIO_TYPE, VFIO_BASE + 14, +* struct vfio_device_query_gfx_plane) +* +* Set the drm_plane_type and flags, then retrieve the gfx plane info. +* +* flags supported: +* - VFIO_GFX_PLANE_TYPE_PROBE and VFIO_GFX_PLANE_TYPE_DMABUF are set
include/uapi/linux/vfio.h struct vfio_pci_hot_reset {
Quoted 3 lines
include/uapi/linux/vfio.h +3
-0+* to ask if the mdev supports dma-buf. 0 on support, -EINVAL on no +* support for dma-buf. +* - VFIO_GFX_PLANE_TYPE_PROBE and VFIO_GFX_PLANE_TYPE_REGION are set
include/uapi/linux/vfio.h struct vfio_pci_hot_reset {
Quoted 3 lines
include/uapi/linux/vfio.h +3
-0+* to ask if the mdev supports region. 0 on support, -EINVAL on no +* support for region. +* - VFIO_GFX_PLANE_TYPE_DMABUF or VFIO_GFX_PLANE_TYPE_REGION
Quoted 8 lines
is set
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 519
Quoted 1 line
include/uapi/linux/vfio.h +1
-0+* with each call to query the plane info. So
dmabuf_idis effectively just a token that can be fed intoGET_GFX_DMABUFto get the fd. The implementation of the token is vendor specific, but can be thought of as some sort of sequence ID or generation ID (but not necessarily monotonically increasing), soGET_GFX_DMABUFmay fail if the previously provideddmabuf_idis no longer valid. Do I have this correct?
Exactly. GET_GFX_DMABUF may fail if the dmabuf_id is no longer valid. -EINVAL will be returned in that case.
And dmabuf_id is invalid when:
1) user space has closed all dma-buf fds which are exposed with the dmabuf_id,
2) or the dmabuf_id isn't returned from QUERY_GFX_PLANE.
I will add the comments. Thanks.
Quoted 24 lines
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 520
Quoted 2 lines
include/uapi/linux/vfio.h +1
-0+* - Others are invalid and return -EINVAL. And I see that in patch 7/7 that i915 is checking explicitly for only these flag combinations, great!
Quoted 18 lines
include/uapi/linux/vfio.h +18
-0+* +* Return: 0 on success, -ENODEV with all out fields zero on mdev +* device initialization, -errno on other failure. +*/ +struct vfio_device_gfx_plane_info { +__u32 argsz; +__u32 flags; +#define VFIO_GFX_PLANE_TYPE_PROBE (1 << 0) #define +VFIO_GFX_PLANE_TYPE_DMABUF (1 << 1) #define +VFIO_GFX_PLANE_TYPE_REGION (1 << 2) +/* 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 */
Quoted 8 lines
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 544
Quoted 6 lines
include/uapi/linux/vfio.h +6
-0+__u32 size;/* size of plane in bytes, align on page*/ +__u32 x_pos;/* horizontal position of cursor plane */ +__u32 y_pos;/* vertical position of cursor plane*/ +union { +__u32 region_index;/* region index */ +__s32 dmabuf_id;/* dma-buf fd */ "dma-buf fd", but it's not an fd. Why is this signed since it's no longer an fd?
Again, sorry about the typo :)
Quoted 13 lines
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 555
Quoted 12 lines
include/uapi/linux/vfio.h +11
-0+ }; +}; + +#define VFIO_DEVICE_QUERY_GFX_PLANE _IO(VFIO_TYPE, VFIO_BASE + 14) + +/** +* VFIO_DEVICE_GET_GFX_DMABUF - _IOW(VFIO_TYPE, VFIO_BASE + 15, +* struct vfio_device_gfx_dmabuf_fd) +* +* Return: 0 on success, -errno on failure. +*/
Quoted 7 lines
So given a
dmabuf_id, return admabuf_fd, which may be the same as a fd previously returned to the user. In the latter case, can we assume that there's no new reference added to the existing fd? Is the user permitted to cache thedmabuf_idtodmabuf_fdmapping? Similarly, if a user already has admabuf_fd, can callingGET_GFX_DMABUFever fail or return a different result for the samedmabuf_idwhich provided that fd? Maybe we could define some of these behaviors in the header file to keep vendor implementations consistent.
Actually, a new fd is returned with each time GET_GFX_DMABUF invoked, even with the same dmabuf_id. The benefit is to leave the dma-buf's life cycle management to userspace. The dma-buf will be released when all its fds in userspace are closed.
Then, I think I need to add some comments like this:
"dmabuf_fd will return a new fd with each time GET_GFX_DMABUF being invoked"
Quoted 7 lines
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 558
Quoted 4 lines
include/uapi/linux/vfio.h +3
-0+struct vfio_device_gfx_dmabuf_fd { +__u32 argsz; +__u32 flags;Patch 7/7 however fails to validate this flags field. It needs to return
-EINVALif any unsupported flags are set, which at this point is all of them.
Indeed.
Quoted 6 lines
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 559
Quoted 3 lines
include/uapi/linux/vfio.h +2
-0+/* in */ +__u32 dmabuf_id;This unsigned
dmabuf_idis probably correct, but it doesn't match the signed one provided above.
Will make them both unsigned :)
Quoted 9 lines
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 563
Quoted 4 lines
include/uapi/linux/vfio.h +3
-0+/* out */ +__s32 dmabuf_fd; +};
VFIO_GROUP_GET_DEVICE_FDreturns the fd through the return code, is there a reason to do it differently here?GET_DEVICE_FDalso only takes a char parameter without the extra future proofing, I wonder if this ioctl is simple enough to do the same.
So that means we don't need the "flages" field and change dmabuf_id to a character string. Maybe it's fine for the current usage. But, I'm not sure if it's suitable for future. Gerd, Zhenyu and Zhi, how do you think about it?
Thanks.
Tina
Quoted 10 lines
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 569
Quoted 7 lines
include/uapi/linux/vfio.h +3
-0+ +#define VFIO_DEVICE_GET_GFX_DMABUF _IO(VFIO_TYPE, VFIO_BASE + 15) +/* -------- API for Type1 VFIO IOMMU -------- */ /** Thanks,
Alex
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v15 5/7] vfio: ABI for mdev display dma-buf operation
Quoted 161 lines · Tina
Quoted 11 lines
-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Wednesday, October 11, 2017 3:17 AM
To: Zhang, Tina <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Lv, Zhiyuan <[email protected]>; Wang, Zhi A <[email protected]>; Tian, Kevin <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; Daniel Vetter <[email protected]>
Subject: Re: [PATCH v15 5/7] vfio: ABI for mdev display dma-buf operationQuoted 7 lines
Quoted 2 lines · On Tue, 10 Oct 2017 17:50:05 +0800 Tina Zhang <[email protected]> wrote:
Add
VFIO_DEVICE_QUERY_GFX_PLANEioctl command to let user mode query and get the plan and its related information. This ioctl can be invoked with:s/plan/plane/
Sorry about this typo :).
Quoted 71 lines
Quoted 51 lines
1) either flag DMABUF or REGION is set. Vendor driver returns success and the
plane_infoonly when the specific kind of buffer is supported.
2) flag PROBE is set with either DMABUF or REGION. Vendor driver returns success only when the specific kind of buffer is supported.The dma-buf's life cycle is handled by user mode and tracked by kernel. The returned fd in struct
vfio_device_query_gfx_planecan 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.v15:
- add a ioctl to get a dmabuf for a given dmabuf id. (Gerd)v14:
- add PROBE, DMABUF and REGION flags. (Alex)v12:
- adddrm_format_modback. (Gerd and Zhenyu)
- addregion_index. (Gerd)v11:
- renameplane_typetodrm_plane_type. (Gerd)
- move fields ofvfio_device_query_gfx_planetovfio_device_gfx_plane_info. (Gerd)
- removedrm_format_mod, start fields. (Daniel)
- removeplane_id.v10:
- refine the ABI APIVFIO_DEVICE_QUERY_GFX_PLANE. (Alex) (Gerd)v3:
- add a fieldgvt_plane_infoin thedrm_i915_gem_objstructure to save the decoded plane information to avoid look up while need the plane info. (Gerd)Signed-off-by Tina Zhang <[email protected]>Cc Gerd Hoffmann <[email protected]>Cc Alex Williamson <[email protected]>Cc Daniel Vetter <[email protected]>--- include/uapi/linux/vfio.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)include/uapi/linux/vfio.h +0
-0include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 503
Quoted 2 lines
include/uapi/linux/vfio.h +0
-0@@ -502,6 +502,68 @@ struct vfio_pci_hot_reset {#define VFIO_DEVICE_PCI_HOT_RESET _IO(VFIO_TYPE, VFIO_BASE +13)
include/uapi/linux/vfio.h struct vfio_pci_hot_reset {
Quoted 9 lines
include/uapi/linux/vfio.h +8
-0+/** +* VFIO_DEVICE_QUERY_GFX_PLANE - _IOW(VFIO_TYPE, VFIO_BASE + 14, +* struct vfio_device_query_gfx_plane) +* +* Set the drm_plane_type and flags, then retrieve the gfx plane info. +* +* flags supported: +* - VFIO_GFX_PLANE_TYPE_PROBE and VFIO_GFX_PLANE_TYPE_DMABUF are set
include/uapi/linux/vfio.h struct vfio_pci_hot_reset {
Quoted 3 lines
include/uapi/linux/vfio.h +3
-0+* to ask if the mdev supports dma-buf. 0 on support, -EINVAL on no +* support for dma-buf. +* - VFIO_GFX_PLANE_TYPE_PROBE and VFIO_GFX_PLANE_TYPE_REGION are set
include/uapi/linux/vfio.h struct vfio_pci_hot_reset {
Quoted 3 lines
include/uapi/linux/vfio.h +3
-0+* to ask if the mdev supports region. 0 on support, -EINVAL on no +* support for region. +* - VFIO_GFX_PLANE_TYPE_DMABUF or VFIO_GFX_PLANE_TYPE_REGION Quoted 8 lines
is set
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 519
Quoted 1 line
include/uapi/linux/vfio.h +1
-0+* with each call to query the plane info. So
dmabuf_idis effectively just a token that can be fed intoGET_GFX_DMABUFto get the fd. The implementation of the token is vendor specific, but can be thought of as some sort of sequence ID or generation ID (but not necessarily monotonically increasing), soGET_GFX_DMABUFmay fail if the previously provideddmabuf_idis no longer valid. Do I have this correct?Exactly.
GET_GFX_DMABUFmay fail if thedmabuf_idis no longer valid.-EINVALwill be returned in that case.
Anddmabuf_idis invalid when:
1) user space has closed all dma-buf fds which are exposed with thedmabuf_id,
2) or thedmabuf_idisn't returned fromQUERY_GFX_PLANE.
I will add the comments. Thanks.Quoted 24 lines
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 520
Quoted 2 lines
include/uapi/linux/vfio.h +1
-0+* - Others are invalid and return -EINVAL. And I see that in patch 7/7 that i915 is checking explicitly for only these flag combinations, great!
Quoted 18 lines
include/uapi/linux/vfio.h +18
-0+* +* Return: 0 on success, -ENODEV with all out fields zero on mdev +* device initialization, -errno on other failure. +*/ +struct vfio_device_gfx_plane_info { +__u32 argsz; +__u32 flags; +#define VFIO_GFX_PLANE_TYPE_PROBE (1 << 0) #define +VFIO_GFX_PLANE_TYPE_DMABUF (1 << 1) #define +VFIO_GFX_PLANE_TYPE_REGION (1 << 2) +/* 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 */ Quoted 8 lines
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 544
Quoted 6 lines
include/uapi/linux/vfio.h +6
-0+__u32 size;/* size of plane in bytes, align on page*/ +__u32 x_pos;/* horizontal position of cursor plane */ +__u32 y_pos;/* vertical position of cursor plane*/ +union { +__u32 region_index;/* region index */ +__s32 dmabuf_id;/* dma-buf fd */ "dma-buf fd", but it's not an fd. Why is this signed since it's no longer an fd?
Again, sorry about the typo :)
Quoted 13 lines
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 555
Quoted 12 lines
include/uapi/linux/vfio.h +11
-0+ }; +}; + +#define VFIO_DEVICE_QUERY_GFX_PLANE _IO(VFIO_TYPE, VFIO_BASE + 14) + +/** +* VFIO_DEVICE_GET_GFX_DMABUF - _IOW(VFIO_TYPE, VFIO_BASE + 15, +* struct vfio_device_gfx_dmabuf_fd) +* +* Return: 0 on success, -errno on failure. +*/ Quoted 7 lines
So given a
dmabuf_id, return admabuf_fd, which may be the same as a fd previously returned to the user. In the latter case, can we assume that there's no new reference added to the existing fd? Is the user permitted to cache thedmabuf_idtodmabuf_fdmapping? Similarly, if a user already has admabuf_fd, can callingGET_GFX_DMABUFever fail or return a different result for the samedmabuf_idwhich provided that fd? Maybe we could define some of these behaviors in the header file to keep vendor implementations consistent.
Quoted 3 lines
Actually, a new fd is returned with each time
GET_GFX_DMABUFinvoked, even with the samedmabuf_id. The benefit is to leave the dma-buf's life cycle management to userspace. The dma-buf will be released when all its fds in userspace are closed.
Ok, so userspace could actually have multiple dmabuf_fds open at the same time for the same dmabuf_id if they were sloppy with management of those fds.
Quoted 2 lines
Then, I think I need to add some comments like this:
"dmabuf_fdwill return a new fd with each timeGET_GFX_DMABUFbeing invoked"
Yes, that would be great.
Quoted 26 lines
Quoted 7 lines
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 558
Quoted 4 lines
include/uapi/linux/vfio.h +3
-0+struct vfio_device_gfx_dmabuf_fd { +__u32 argsz; +__u32 flags;Patch 7/7 however fails to validate this flags field. It needs to return
-EINVALif any unsupported flags are set, which at this point is all of them.Indeed.
Quoted 6 lines
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 559
Quoted 3 lines
include/uapi/linux/vfio.h +2
-0+/* in */ +__u32 dmabuf_id;This unsigned
dmabuf_idis probably correct, but it doesn't match the signed one provided above.Will make them both unsigned :)
Quoted 9 lines
include/uapi/linux/vfio.h struct vfio_pci_hot_reset { · line 563
Quoted 4 lines
include/uapi/linux/vfio.h +3
-0+/* out */ +__s32 dmabuf_fd; +};
VFIO_GROUP_GET_DEVICE_FDreturns the fd through the return code, is there a reason to do it differently here?GET_DEVICE_FDalso only takes a char parameter without the extra future proofing, I wonder if this ioctl is simple enough to do the same.
Quoted 3 lines
So that means we don't need the "flages" field and change
dmabuf_idto a character string. Maybe it's fine for the current usage. But, I'm not sure if it's suitable for future. Gerd, Zhenyu and Zhi, how do you think about it?
No, the parameter wouldn't be a char, you'd use an __u32 for the dmabuf_id. I'm just referencing the structure of the GET_DEVICE_FD as an ioctl which returns an fd through the return value and takes a single parameter. I don't mean to imply matching the type of that parameter. Gerd, what are your thoughts on that, it'd make it slightly easier to call GET_GFX_DMABUF, but it limits us to file descriptor for the dmabuf whereas with a flag and expandable structure we could use some future mechanism to return the dmabuf to userspace. Thanks,
Alex
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v15 5/7] vfio: ABI for mdev display dma-buf operation
Hi,
Quoted 7 lines
No, the parameter wouldn't be a char, you'd use an
__u32for the dmabuf_id. I'm just referencing the structure of theGET_DEVICE_FDas
an ioctl which returns an fd through the return value and takes a single parameter. I don't mean to imply matching the type of that parameter.
Quoted 5 lines
Gerd, what are your thoughts on that, it'd make it slightly easier to call
GET_GFX_DMABUF, but it limits us to file descriptor for
the dmabuf whereas with a flag and expandable structure we could use some future mechanism to return the dmabuf to userspace.
It's fine with me.
The point of using fd's to refer to dmabufs is that they can be passed around easily, so I doubt this is going to change.
cheers,
Gerd
PATCH v15 6/7 drm/i915: Introduce GEM proxy
In reply to Tina ZhangGEM proxy is a kind of GEM, whose backing physical memory is pinned and produced by guest VM and is used by host as read only. With GEM proxy, host is able to access guest physical memory through GEM object interface. As GEM proxy is such a special kind of GEM, a new flag I915_GEM_OBJECT_IS_PROXY is introduced to ban host from changing the backing storage of GEM proxy.
v14:
- return -ENXIO when gem proxy object is banned by ioctl. (Chris) (Daniel)
v13:
- add comments to GEM proxy. (Chris)
- don't ban GEM proxy in i915_gem_sw_finish_ioctl. (Chris)
- check GEM proxy bar after finishing i915_gem_object_wait. (Chris)
- remove GEM proxy bar in i915_gem_madvise_ioctl.
v6:
- add gem proxy barrier in the following ioctls. (Chris) i915_gem_set_caching_ioctl i915_gem_set_domain_ioctl i915_gem_sw_finish_ioctl i915_gem_set_tiling_ioctl i915_gem_madvise_ioctl
--- drivers/gpu/drm/i915/i915_gem.c | 24 +++++++++++++++++++++++- drivers/gpu/drm/i915/i915_gem_object.h | 7 +++++++ drivers/gpu/drm/i915/i915_gem_tiling.c | 8 ++++++++ 3 files changed, 38 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem.c +23 -1
@@ -1584,6 +1584,16 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,if (err) goto out; +/* 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. +*/ +if (i915_gem_object_is_proxy (obj)) { + err = -ENXIO ; + goto out; + } +/* Flush and acquire obj->pages so that we are coherent through * direct access in memory with previous cached writes through * shmemfs and that our cache domain tracking remains valid.
@@ -1640,6 +1650,10 @@ i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,if (!obj)return -ENOENT ; +/* Proxy objects are barred from CPU access, so there is no +* need to ban sw_finish as it is a nop. +*/ +/* Pinned buffers may be scanout, so flush the cache */ i915_gem_object_flush_if_display (obj);i915_gem_object_put (obj);
@@ -1690,7 +1704,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,*/ if (!obj->base.filp) {i915_gem_object_put (obj); -return -EINVAL ; +return -ENXIO ; } addr = vm_mmap(obj->base.filp, 0, args->size,
@@ -3749,6 +3763,14 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,if (!obj)return -ENOENT ; +/* The caching mode of proxy object is handled by its generator, and not +* expected to be changed by user mode. +*/ +if (i915_gem_object_is_proxy (obj)) { + ret = -ENXIO ; + goto out; + } +if (obj->cache_level == level) goto out;
drivers/gpu/drm/i915/i915_gem_object.h +7 -0
@@ -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
@@ -300,6 +301,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 +8 -0
@@ -345,6 +345,14 @@ i915_gem_set_tiling_ioctl(struct drm_device *dev, void *data,if (!obj)return -ENOENT ; +/* The tiling mode of proxy objects is handled by its generator, and not +* expected to be changed by user mode. +*/ +if (i915_gem_object_is_proxy (obj)) { + err = -ENXIO ; + goto err; + } +if (!i915_tiling_ok (obj, args->tiling_mode, args->stride)) { err = -EINVAL ; goto err;
Signature · 6 lines
2.7.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v15 6/7] drm/i915: Introduce GEM proxy
Quoted 29 lines · Tina Zhang
GEM proxy is a kind of GEM, whose backing physical memory is pinned and produced by guest VM and is used by host as read only. With GEM proxy, host is able to access guest physical memory through GEM object interface. As GEM proxy is such a special kind of GEM, a new flag
I915_GEM_OBJECT_IS_PROXYis introduced to ban host from changing the backing storage of GEM proxy.v14:
- return-ENXIOwhen gem proxy object is banned by ioctl. (Chris) (Daniel)v13:
- add comments to GEM proxy. (Chris)
- don't ban GEM proxy ini915_gem_sw_finish_ioctl. (Chris)
- check GEM proxy bar after finishingi915_gem_object_wait. (Chris)
- remove GEM proxy bar ini915_gem_madvise_ioctl.v6:
- add gem proxy barrier in the following ioctls. (Chris)i915_gem_set_caching_ioctli915_gem_set_domain_ioctli915_gem_sw_finish_ioctli915_gem_set_tiling_ioctli915_gem_madvise_ioctlSigned-off-by Tina Zhang <[email protected]>Cc Daniel Vetter <[email protected]>Cc Chris Wilson <[email protected]>Cc Joonas Lahtinen <[email protected]>
<SNIP>
drivers/gpu/drm/i915/i915_gem_object.h struct drm_i915_gem_object_ops { · line 42
Quoted 6 lines
+++
b/drivers/gpu/drm/i915/i915_gem_object.hdrivers/gpu/drm/i915/i915_gem_object.h +1
-0@@ -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)
Please fix the indent to match. Do convert the above two lines to use TAB character too.
<SNIP>
drivers/gpu/drm/i915/i915_gem.c i915_gem_mmap_ioctl(struct drm_device *dev, void *data, · line 1708
Quoted 7 lines
drivers/gpu/drm/i915/i915_gem.c +1
-1@@ -1690,7 +1704,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,*/ if (!obj->base.filp) {i915_gem_object_put (obj); -return -EINVAL ; +return -ENXIO ; }
This still needs to be a separate patch.
With those fixes, this is;
Regards, Joonas
Signature · 3 lines
Joonas Lahtinen Open Source Technology Center Intel Corporation
Joonas Lahtinen
maintainerRe: [Intel-gfx] [PATCH v15 6/7] drm/i915: Introduce GEM proxy
Quoted 55 lines · Joonas Lahtinen
Quoted 29 lines · Tina Zhang
GEM proxy is a kind of GEM, whose backing physical memory is pinned and produced by guest VM and is used by host as read only. With GEM proxy, host is able to access guest physical memory through GEM object interface. As GEM proxy is such a special kind of GEM, a new flag
I915_GEM_OBJECT_IS_PROXYis introduced to ban host from changing the backing storage of GEM proxy.v14:
- return-ENXIOwhen gem proxy object is banned by ioctl. (Chris) (Daniel)v13:
- add comments to GEM proxy. (Chris)
- don't ban GEM proxy ini915_gem_sw_finish_ioctl. (Chris)
- check GEM proxy bar after finishingi915_gem_object_wait. (Chris)
- remove GEM proxy bar ini915_gem_madvise_ioctl.v6:
- add gem proxy barrier in the following ioctls. (Chris)i915_gem_set_caching_ioctli915_gem_set_domain_ioctli915_gem_sw_finish_ioctli915_gem_set_tiling_ioctli915_gem_madvise_ioctlSigned-off-by Tina Zhang <[email protected]>Cc Daniel Vetter <[email protected]>Cc Chris Wilson <[email protected]>Cc Joonas Lahtinen <[email protected]><SNIP>
drivers/gpu/drm/i915/i915_gem_object.h struct drm_i915_gem_object_ops { · line 42
Quoted 6 lines
+++
b/drivers/gpu/drm/i915/i915_gem_object.hdrivers/gpu/drm/i915/i915_gem_object.h +1
-0@@ -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)Please fix the indent to match. Do convert the above two lines to use TAB character too.
<SNIP>
drivers/gpu/drm/i915/i915_gem.c i915_gem_mmap_ioctl(struct drm_device *dev, void *data, · line 1708
Quoted 7 lines
drivers/gpu/drm/i915/i915_gem.c +1
-1@@ -1690,7 +1704,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,*/ if (!obj->base.filp) {i915_gem_object_put (obj); -return -EINVAL ; +return -ENXIO ; }This still needs to be a separate patch.
Quoted 3 lines
With those fixes, this is;
Reviewed-by Joonas Lahtinen <[email protected]>
Also, send the produced two patches (this and the split patch) as a standalone series for easier testing and merging.
CI seems to have hard time applying the whole series.
Regards, Joonas
Signature · 3 lines
Joonas Lahtinen Open Source Technology Center Intel Corporation
RE: [Intel-gfx] [PATCH v15 6/7] drm/i915: Introduce GEM proxy
Quoted 70 lines
-----Original Message-----
From: Joonas Lahtinen [mailto:[email protected]]
Sent: Tuesday, October 10, 2017 9:02 PM
To: Zhang, Tina <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Lv, Zhiyuan <[email protected]>; Wang, Zhi A <[email protected]>; Tian, Kevin <[email protected]>; [email protected]; [email protected]
Cc: Daniel Vetter <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [Intel-gfx] [PATCH v15 6/7] drm/i915: Introduce GEM proxyQuoted 43 lines · Joonas Lahtinen
Quoted 29 lines · Tina Zhang
GEM proxy is a kind of GEM, whose backing physical memory is pinned and produced by guest VM and is used by host as read only. With GEM proxy, host is able to access guest physical memory through GEM object interface. As GEM proxy is such a special kind of GEM, a new flag
I915_GEM_OBJECT_IS_PROXYis introduced to ban host from changing the backing storage of GEM proxy.v14:
- return-ENXIOwhen gem proxy object is banned by ioctl. (Chris) (Daniel)v13:
- add comments to GEM proxy. (Chris)
- don't ban GEM proxy ini915_gem_sw_finish_ioctl. (Chris)
- check GEM proxy bar after finishingi915_gem_object_wait. (Chris)
- remove GEM proxy bar ini915_gem_madvise_ioctl.v6:
- add gem proxy barrier in the following ioctls. (Chris)i915_gem_set_caching_ioctli915_gem_set_domain_ioctli915_gem_sw_finish_ioctli915_gem_set_tiling_ioctli915_gem_madvise_ioctlSigned-off-by Tina Zhang <[email protected]>Cc Daniel Vetter <[email protected]>Cc Chris Wilson <[email protected]>Cc Joonas Lahtinen <[email protected]><SNIP>
drivers/gpu/drm/i915/i915_gem_object.h struct drm_i915_gem_object_ops { · line 42
Quoted 6 lines
+++
b/drivers/gpu/drm/i915/i915_gem_object.hdrivers/gpu/drm/i915/i915_gem_object.h +1
-0@@ -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)Please fix the indent to match. Do convert the above two lines to use TAB character too.
Quoted 3 lines
<SNIP>
Review i915_gem_mmap_ioctl(struct drm_device *dev,
Quoted 1 line
(quoted diff) +0
-0@@ -1690,7 +1704,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev,void *data,
Quoted 9 lines
drivers/gpu/drm/i915/i915_gem.c i915_gem_mmap_ioctl(struct drm_device *dev, void *data, · line 1708
Quoted 6 lines
drivers/gpu/drm/i915/i915_gem.c +1
-1*/ if (!obj->base.filp) {i915_gem_object_put (obj); -return -EINVAL ; +return -ENXIO ; }This still needs to be a separate patch.
Quoted 6 lines
Quoted 3 lines
With those fixes, this is;
Reviewed-by Joonas Lahtinen <[email protected]>Also, send the produced two patches (this and the split patch) as a standalone series for easier testing and merging.
Got it. Thanks.
BR,
Tina
Quoted 8 lines
CI seems to have hard time applying the whole series.
Regards, Joonas
--
Joonas Lahtinen
Open Source Technology Center
Intel Corporation
PATCH v15 7/7 drm/i915/gvt: Dmabuf support for GVT-g
In reply to Tina ZhangThis patch introduces a guest's framebuffer sharing mechanism based on dma-buf subsystem. With this sharing mechanism, guest's framebuffer can be shared between guest VM and host.
v15:
- Add VFIO_DEVICE_GET_GFX_DMABUF ABI. (Gerd)
- Add intel_vgpu_dmabuf_cleanup() to clean up the vGPU's dmabuf. (Gerd)
v14:
- add PROBE, DMABUF and REGION flags. (Alex)
v12:
- refine the lifecycle of dmabuf.
v9:
- remove dma-buf management. (Alex)
- track the dma-buf create and release in kernel mode. (Gerd) (Daniel)
v8:
- refine the dma-buf ioctl definition.(Alex)
- add a lock to protect the dmabuf list. (Alex)
v7:
- release dma-buf related allocations in dma-buf's associated release function. (Alex)
- refine ioctl interface for querying plane info or create dma-buf. (Alex)
v6:
- align the dma-buf life cycle with the vfio device. (Alex)
- add the dma-buf related operations in a separate patch. (Gerd)
- i915 related changes. (Chris)
v5:
- 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. (Xiaoguang)
- add definition for the query plane and create dma-buf. (Xiaoguang)
v4:
- fix bug while checking whether the gem obj is gvt's dma-buf when set caching mode or doamins. (Xiaoguang)
v3:
- 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. (Alex)
- change dma-buf related information to be more generic. So other vendor can use the same interface. (Alex)
v2:
- create a management fd for dma-buf operations. (Alex)
- alloc gem object's backing storage in gem obj's get_pages() callback. (Chris)
--- drivers/gpu/drm/i915/gvt/Makefile | 2 +- drivers/gpu/drm/i915/gvt/dmabuf.c | 513 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/gvt/dmabuf.h | 65 +++++ drivers/gpu/drm/i915/gvt/gvt.c | 2 + drivers/gpu/drm/i915/gvt/gvt.h | 11 + drivers/gpu/drm/i915/gvt/hypercall.h | 2 + drivers/gpu/drm/i915/gvt/kvmgt.c | 60 ++++ drivers/gpu/drm/i915/gvt/mpt.h | 30 ++ drivers/gpu/drm/i915/gvt/vgpu.c | 5 +- drivers/gpu/drm/i915/i915_gem_object.h | 2 + 10 files changed, 690 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/i915/gvt/dmabuf.c create mode 100644 drivers/gpu/drm/i915/gvt/dmabuf.h
drivers/gpu/drm/i915/gvt/Makefile +1 -1
@@ -2,7 +2,7 @@ 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 \ - fb_decoder.o + fb_decoder.o dmabuf.o ccflags-y += -I$(src) -I$(src)/$(GVT_DIR) i915-y += $(addprefix $(GVT_DIR)/, $(GVT_SOURCE))
drivers/gpu/drm/i915/gvt/dmabuf.c new file +513 -0
513 lines not on this page · raw message
drivers/gpu/drm/i915/gvt/dmabuf.h new file +65 -0
65 lines not on this page · raw message
drivers/gpu/drm/i915/gvt/gvt.c +2 -0
@@ -54,6 +54,8 @@ static const struct intel_gvt_ops intel_gvt_ops = { .vgpu_reset = intel_gvt_reset_vgpu, .vgpu_activate = intel_gvt_activate_vgpu, .vgpu_deactivate = intel_gvt_deactivate_vgpu, + .vgpu_query_plane = intel_vgpu_query_plane, + .vgpu_get_dmabuf = intel_vgpu_get_dmabuf, };/**
drivers/gpu/drm/i915/gvt/gvt.h +11 -0
@@ -47,6 +47,7 @@#include "render.h" #include "cmd_parser.h" #include "fb_decoder.h" +#include "dmabuf.h" #define GVT_MAX_VGPU 8
@@ -183,8 +184,16 @@ struct intel_vgpu {struct kvm *kvm;struct work_struct release_work;atomic_t released; +struct vfio_device *vfio_device; } vdev;#endif + +struct list_head dmabuf_obj_list_head; +struct mutex dmabuf_lock; +struct idr object_idr; + +struct completion vblank_done; + }; struct intel_gvt_gm {
@@ -500,6 +509,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_plane)(struct intel_vgpu *vgpu,void *); +int (*vgpu_get_dmabuf)(struct intel_vgpu *vgpu,void *); };
drivers/gpu/drm/i915/gvt/hypercall.h +2 -0
@@ -56,6 +56,8 @@ struct intel_gvt_mpt {int (*set_trap_area)(unsigned long handle,u64 start,u64 end,bool map);int (*set_opregion)(void *vgpu); +int (*get_vfio_device)(void *vgpu); +void (*put_vfio_device)(void *vgpu); };extern struct intel_gvt_mpt xengt_mpt;
drivers/gpu/drm/i915/gvt/kvmgt.c +60 -0
94 lines not on this page · raw message
drivers/gpu/drm/i915/gvt/mpt.h +30 -0
@@ -307,4 +307,34 @@ static inline int intel_gvt_hypervisor_set_opregion(struct intel_vgpu *vgpu) return intel_gvt_host.mpt->set_opregion(vgpu); } +/** +* intel_gvt_hypervisor_get_vfio_device - increase vfio device ref count +* @vgpu: a vGPU +* +* Returns: +* Zero on success, negative error code if failed. +*/ +static inline int intel_gvt_hypervisor_get_vfio_device (struct intel_vgpu *vgpu) +{ +if (!intel_gvt_host.mpt->get_vfio_device) +return 0 ; + +return intel_gvt_host.mpt->get_vfio_device (vgpu); +} + +/** +* intel_gvt_hypervisor_put_vfio_device - decrease vfio device ref count +* @vgpu: a vGPU +* +* Returns: +* Zero on success, negative error code if failed. +*/ +static inline void intel_gvt_hypervisor_put_vfio_device (struct intel_vgpu *vgpu) +{ +if (!intel_gvt_host.mpt->put_vfio_device) +return ; + + intel_gvt_host.mpt->put_vfio_device (vgpu); +} +#endif /* _GVT_MPT_H_ */
drivers/gpu/drm/i915/gvt/vgpu.c +4 -1
@@ -232,6 +232,7 @@ void intel_gvt_deactivate_vgpu(struct intel_vgpu *vgpu) }intel_vgpu_stop_schedule (vgpu); +intel_vgpu_dmabuf_cleanup (vgpu);mutex_unlock (&gvt->lock); }
@@ -261,6 +262,7 @@ void intel_gvt_destroy_vgpu(struct intel_vgpu *vgpu)intel_gvt_hypervisor_detach_vgpu (vgpu);intel_vgpu_free_resource (vgpu);intel_vgpu_clean_mmio (vgpu); +intel_vgpu_dmabuf_cleanup (vgpu);vfree (vgpu);intel_gvt_update_vgpu_types (gvt);
@@ -346,7 +348,8 @@ static struct intel_vgpu *__intel_gvt_create_vgpu(struct intel_gvt *gvt, vgpu->gvt = gvt; vgpu->sched_ctl.weight = param->weight;bitmap_zero (vgpu->tlb_handle_pending,I915_NUM_ENGINES ); - +INIT_LIST_HEAD (&vgpu->dmabuf_obj_list_head); +idr_init (&vgpu->object_idr);intel_vgpu_init_cfg_space (vgpu, param->primary); ret =intel_vgpu_init_mmio (vgpu);
drivers/gpu/drm/i915/i915_gem_object.h +2 -0
@@ -199,6 +199,8 @@ struct drm_i915_gem_object { } userptr;unsigned long scratch; + +void *gvt_info; };/** for phys allocated objects */
Signature · 6 lines
2.7.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✗ Fi.CI.BAT: failure 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/31638/
State : failure
== Summary ==
CHK include/config/kernel.release
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
CHK include/generated/bounds.h
CHK include/generated/timeconst.h
CHK include/generated/asm-offsets.h
CALL scripts/checksyscalls.sh
CHK scripts/mod/devicetable-offsets.h
CHK include/generated/compile.h
CHK kernel/config_data.h
CC [M] drivers/gpu/drm/i915/gvt/dmabuf.o
drivers/gpu/drm/i915/gvt/dmabuf.c:132:15: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
.get_pages = vgpu_gem_get_pages,
^~~~~~~~~~~~~~~~~~drivers/gpu/drm/i915/gvt/dmabuf.c:132:15: note: (near initialization for ‘intel_vgpu_gem_ops.get_pages’)
cc1: all warnings being treated as errorsscripts/Makefile.build:313: recipe for target 'drivers/gpu/drm/i915/gvt/dmabuf.o' failed make[4]: *** [drivers/gpu/drm/i915/gvt/dmabuf.o] Error 1scripts/Makefile.build:572: recipe for target 'drivers/gpu/drm/i915' failed
make[3]: *** [drivers/gpu/drm/i915] Error 2scripts/Makefile.build:572: recipe for target 'drivers/gpu/drm' failed
make[2]: *** [drivers/gpu/drm] Error 2scripts/Makefile.build:572: recipe for target 'drivers/gpu' failed
make[1]: *** [drivers/gpu] Error 2
Makefile:1019: recipe for target 'drivers' failed
make: *** [drivers] Error 2
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 9 lines · Tina Zhang
This patch set adds the dma-buf support for intel GVT-g.
dma-buf is an uniform mechanism to share DMA buffers across different devices and subsystems. dma-buf for intel GVT-g is mainly used to share
the vgpu's framebuffer to userspace to leverage userspace graphics stacks
to render the framebuffer to the display monitor.
Quoted 6 lines
The main idea is that we create a gem object and set vgpu's framebuffer as
its backing storage. Then, export a dma-buf associated with this gem object.
With the fd of this dma-buf, userspace can directly handle this buffer.
cheers,
Gerd
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx