drm/i915/gvt: Dma-buf support for GVT-g
Subsystems (5)
v19 cover drm/i915/gvt: Dma-buf support for GVT-g
v18->v19:
1) include "Handle-orphan-dmabuf_objs.patch".
2) rebase to the latest staging branch.
v17->v18:
1) unmap vgpu's opregion when destroying vgpu.
2) update comments for VFIO_DEVICE_GET_GFX_DMABUF. (Alex)
v16->v17:
1) modify VFIO_DEVICE_GET_GFX_DMABUF interface. (Alex)
2) add comments for x_hot/y_hot. (Gerd)
v15->v16:
1) add cursor hotspot fields in struct vfio_device_gfx_plane_info. (Gerd)
2) clean up some typos and add comments for VFIO_DEVICE_QUERY_GFX_PLANE. (Alex)
3) seperate the GEM Proxy part to another patch-set. (Joonas and Chris)
https://lists.freedesktop.org/archives/intel-gvt-dev/2017-November/002377.html
4) please note that this patch-set needs 3) to be applied first.
5) rebase to 4.14.0-rc6.
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
A topic branch with the latest patch set is:
https://github.com/intel/gvt-linux.git branch: topic/dmabuf
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
vfio: ABI for mdev display dma-buf operation drm/i915/gvt: Dmabuf support for GVT-g drm/i915/gvt: Handle orphan dmabuf_objs
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 | 537 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/gvt/dmabuf.h | 67 ++++ 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 | 2 + drivers/gpu/drm/i915/gvt/kvmgt.c | 53 ++++ 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 + include/uapi/drm/drm_fourcc.h | 4 + include/uapi/linux/vfio.h | 62 ++++ 16 files changed, 1470 insertions(+), 3 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 · 6 lines
2.7.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v19 1/6 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.
v16:
- rebase to 4.14.0-rc6.
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
@@ -2,7 +2,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 debugfs.o + execlist.o scheduler.o sched_policy.o render.o cmd_parser.o debugfs.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 · 6 lines
2.7.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v19 2/6 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 · 1 line
2.7.4
PATCH v19 3/6 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 v19 4/6 vfio: ABI for mdev display dma-buf operation
In reply to Tina ZhangAdd VFIO_DEVICE_QUERY_GFX_PLANE ioctl command to let user query and get a plane and its information. So far, two types of buffers are supported:
buffers based on dma-buf and buffers based on region.
This ioctl can be invoked with:
1) Either DMABUF or REGION flag. Vendor driver returns a plane_info successfully only when the specific kind of buffer is supported.
2) Flag PROBE. And at the same time either DMABUF or REGION must be set, so that vendor driver returns success only when the specific kind of buffer is supported.
Add VFIO_DEVICE_GET_GFX_DMABUF ioctl command to let user get a specific dma-buf fd of an exposed MDEV buffer provided by dmabuf_id which was returned in VFIO_DEVICE_QUERY_GFX_PLANE ioctl command.
The life cycle of an exposed MDEV buffer is handled by userspace and tracked by kernel space. The returned dmabuf_id in struct vfio_device_ query_gfx_plane can be a new id of a new exposed buffer or an old id of a re-exported buffer. Host user can check the value of dmabuf_id to see if it needs to create new resources according to the new exposed buffer or just re-use the existing resource related to the old buffer.
v18:
- update comments for VFIO_DEVICE_GET_GFX_DMABUF. (Alex)
v17:
- modify VFIO_DEVICE_GET_GFX_DMABUF interface. (Alex)
v16:
- add x_hot and y_hot fields. (Gerd)
- add comments for VFIO_DEVICE_GET_GFX_DMABUF. (Alex)
- rebase to 4.14.0-rc6.
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
@@ -503,6 +503,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. +* +* Note: +* 1. Plane could be disabled by guest. In that case, success will be +* returned with zero-initialized drm_format, size, width and height +* fields. +* 2. x_hot/y_hot is set to 0xFFFFFFFF if no hotspot information available +* +* Return: 0 on success, -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*/ +__u32 x_hot;/* horizontal position of cursor hotspot */ +__u32 y_hot;/* vertical position of cursor hotspot */ +union { +__u32 region_index;/* region index */ +__u32 dmabuf_id;/* dma-buf id */ + }; +}; + +#define VFIO_DEVICE_QUERY_GFX_PLANE _IO(VFIO_TYPE, VFIO_BASE + 14) + +/** +* VFIO_DEVICE_GET_GFX_DMABUF - _IOW(VFIO_TYPE, VFIO_BASE + 15, __u32) +* +* Return a new dma-buf file descriptor for an exposed guest framebuffer +* described by the provided dmabuf_id. The dmabuf_id is returned from VFIO_ +* DEVICE_QUERY_GFX_PLANE as a token of the exposed guest framebuffer. +*/ + +#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
PATCH v19 5/6 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.
v17:
- modify VFIO_DEVICE_GET_GFX_DMABUF interface. (Alex)
v16:
- add x_hot and y_hot. (Gerd)
- add flag validation for VFIO_DEVICE_GET_GFX_DMABUF. (Alex)
- rebase 4.14.0-rc6.
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 | 523 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/gvt/dmabuf.h | 67 +++++ 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 | 53 ++++ 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, 695 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
@@ -3,7 +3,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 debugfs.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 +523 -0
523 lines not on this page · raw message
drivers/gpu/drm/i915/gvt/dmabuf.h new file +67 -0
67 lines not on this page · raw message
drivers/gpu/drm/i915/gvt/gvt.c +2 -0
@@ -181,6 +181,8 @@ static const struct intel_gvt_ops intel_gvt_ops = { .vgpu_deactivate = intel_gvt_deactivate_vgpu, .gvt_find_vgpu_type = intel_gvt_find_vgpu_type, .get_gvt_attrs = intel_get_gvt_attrs, + .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
@@ -209,8 +210,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; + };/* validating GM healthy status*/
@@ -536,6 +545,8 @@ struct intel_gvt_ops { const char *name);bool (*get_gvt_attrs)(struct attribute ***type_attrs,struct attribute_group ***intel_vgpu_type_groups); +int (*vgpu_query_plane)(struct intel_vgpu *vgpu,void *); +int (*vgpu_get_dmabuf)(struct intel_vgpu *vgpu,unsigned int ); };
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 +53 -0
87 lines not on this page · raw message
drivers/gpu/drm/i915/gvt/mpt.h +30 -0
@@ -309,4 +309,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
@@ -236,6 +236,7 @@ void intel_gvt_deactivate_vgpu(struct intel_vgpu *vgpu) }intel_vgpu_stop_schedule (vgpu); +intel_vgpu_dmabuf_cleanup (vgpu);mutex_unlock (&gvt->lock); }
@@ -265,6 +266,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);
@@ -349,7 +351,8 @@ static struct intel_vgpu *__intel_gvt_create_vgpu(struct intel_gvt *gvt, vgpu->handle = param->handle; vgpu->gvt = gvt; vgpu->sched_ctl.weight = param->weight; - +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
@@ -261,6 +261,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
PATCH v19 6/6 drm/i915/gvt: Handle orphan dmabuf_objs
In reply to Tina Zhangdmabuf_obj's destruction relys on GEM release operation, which is managed in i915 driver. And there is a time window between vgpu's destruction and its dmabuf_objs' destruction. This patch is to free the orphan dmabuf_objs correctly after the vgpu passes away.
--- drivers/gpu/drm/i915/gvt/dmabuf.c | 56 ++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 21 deletions(-)
drivers/gpu/drm/i915/gvt/dmabuf.c +35 -21
@@ -88,19 +88,26 @@ static void dmabuf_gem_object_free(struct kref *kref) container_of(kref, struct intel_vgpu_dmabuf_obj, kref);struct intel_vgpu *vgpu = obj->vgpu;struct list_head *pos; -struct intel_vgpu_dmabuf_obj *dmabuf_obj; -list_for_each (pos, &vgpu->dmabuf_obj_list_head) { - dmabuf_obj = container_of(pos, struct intel_vgpu_dmabuf_obj, - list); -if (dmabuf_obj == obj) { -idr_remove (&vgpu->object_idr, dmabuf_obj->dmabuf_id); -kfree (dmabuf_obj->info); -kfree (dmabuf_obj); -list_del (pos); -break ; +if (vgpu) { +list_for_each (pos, &vgpu->dmabuf_obj_list_head) { + dmabuf_obj =container_of (pos, + struct intel_vgpu_dmabuf_obj, list); +if (dmabuf_obj == obj) { +intel_gvt_hypervisor_put_vfio_device (vgpu); +idr_remove (&vgpu->object_idr, + dmabuf_obj->dmabuf_id); +kfree (dmabuf_obj->info); +kfree (dmabuf_obj); +list_del (pos); +break ; + } } + }else { +/* Free the orphan dmabuf_objs here */ +kfree (obj->info); +kfree (obj); } }
@@ -122,11 +129,16 @@ static void vgpu_gem_release(struct drm_i915_gem_object *gem_obj)struct intel_vgpu_dmabuf_obj *obj = fb_info->obj;struct intel_vgpu *vgpu = obj->vgpu; -mutex_lock (&vgpu->dmabuf_lock); - gem_obj->base.dma_buf =NULL ; -dmabuf_obj_put (obj); -intel_gvt_hypervisor_put_vfio_device (vgpu); -mutex_unlock (&vgpu->dmabuf_lock); +if (vgpu) { +mutex_lock (&vgpu->dmabuf_lock); + gem_obj->base.dma_buf =NULL ; +dmabuf_obj_put (obj); +mutex_unlock (&vgpu->dmabuf_lock); + }else { +/* vgpu is NULL, as it has been removed already */ + gem_obj->base.dma_buf =NULL ; +dmabuf_obj_put (obj); + } }static const struct drm_i915_gem_object_ops intel_vgpu_gem_ops = {
@@ -471,12 +483,6 @@ int intel_vgpu_get_dmabuf(struct intel_vgpu *vgpu, unsigned int dmabuf_id) } dmabuf_fd = ret; -if (intel_gvt_hypervisor_get_vfio_device (vgpu)) { -gvt_vgpu_err ("get vfio device failed\n" ); -put_unused_fd (ret); - goto out_free_dmabuf; - } -dmabuf_obj_get (dmabuf_obj);if (dmabuf_obj->initref) {
@@ -518,6 +524,14 @@ void intel_vgpu_dmabuf_cleanup(struct intel_vgpu *vgpu) dmabuf_obj->initref = false;dmabuf_obj_put (dmabuf_obj); } + +idr_remove (&vgpu->object_idr, dmabuf_obj->dmabuf_id); + +if (dmabuf_obj->vgpu) +intel_gvt_hypervisor_put_vfio_device (vgpu); + + dmabuf_obj->vgpu =NULL ; + }mutex_unlock (&vgpu->dmabuf_lock); }
Signature · 1 line
2.7.4
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/34272/
State : failure
== Summary ==
commit ffa17d69cf53bd5af4d7e41900c3ba40f6656e31
Author: Chris Wilson <[email protected]> Date: Thu Nov 23 07:47:39 2017 +0000
drm-tip: 2017y-11m-23d-07h-46m-50s UTC integration manifest
_______________________________________________
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/34272/
State : failure
== Summary ==
commit 606231c4d58188daa3a9a02ac6b95f42c4fcf267
Author: Joonas Lahtinen <[email protected]> Date: Thu Nov 23 12:37:47 2017 +0200
drm-tip: 2017y-11m-23d-10h-35m-48s UTC integration manifest
_______________________________________________
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/34272/
State : failure
== Summary ==
Applying: drm/i915/gvt: Add framebuffer decoder support
Applying: drm: Introduce RGB 64-bit 16:16:16:16 float format
Applying: drm/i915/gvt: Add RGB 64-bit 16:16:16:16 float format
Applying: vfio: ABI for mdev display dma-buf operation
Applying: drm/i915/gvt: Dmabuf support for GVT-g Patch failed at 0005 drm/i915/gvt: Dmabuf support for GVT-g
Current HEAD:
commit 9d399f81694538228a539de9a908cdf9ef00f814
Author: Tvrtko Ursulin <[email protected]> Date: Thu Nov 23 12:29:07 2017 +0000
drm-tip: 2017y-11m-23d-12h-28m-12s UTC integration manifest
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx