Skip to content

Commit

Permalink
drm/xen-zcopy: Add Xen zero-copy helper DRM driver
Browse files Browse the repository at this point in the history
Introduce Xen zero-copy helper DRM driver, add user-space API
of the driver:
1. DRM_IOCTL_XEN_ZCOPY_DUMB_FROM_REFS
This will create a DRM dumb buffer from grant references provided
by the frontend. The intended usage is:
  - Frontend
    - creates a dumb/display buffer and allocates memory
    - grants foreign access to the buffer pages
    - passes granted references to the backend
  - Backend
    - issues DRM_XEN_ZCOPY_DUMB_FROM_REFS ioctl to map
      granted references and create a dumb buffer
    - requests handle to fd conversion via DRM_IOCTL_PRIME_HANDLE_TO_FD
    - requests real HW driver/consumer to import the PRIME buffer with
      DRM_IOCTL_PRIME_FD_TO_HANDLE
    - uses handle returned by the real HW driver
  - at the end:
    o closes real HW driver's handle with DRM_IOCTL_GEM_CLOSE
    o closes zero-copy driver's handle with DRM_IOCTL_GEM_CLOSE
    o closes file descriptor of the exported buffer

2. DRM_IOCTL_XEN_ZCOPY_DUMB_TO_REFS
This will grant references to a dumb/display buffer's memory provided
 by the backend. The intended usage is:
  - Frontend
    - requests backend to allocate dumb/display buffer and grant
      references to its pages
  - Backend
    - requests real HW driver to create a dumb with
      DRM_IOCTL_MODE_CREATE_DUMB
    - requests handle to fd conversion via
      DRM_IOCTL_PRIME_HANDLE_TO_FD
    - requests zero-copy driver to import the PRIME buffer with
      DRM_IOCTL_PRIME_FD_TO_HANDLE
    - issues DRM_XEN_ZCOPY_DUMB_TO_REFS ioctl to
      grant references to the buffer's memory.
    - passes grant references to the frontend
 - at the end:
    - closes zero-copy driver's handle with DRM_IOCTL_GEM_CLOSE
    - closes real HW driver's handle with DRM_IOCTL_GEM_CLOSE
    - closes file descriptor of the imported buffer

Implement GEM/IOCTL handling depending on driver mode of operation:
- if GEM is created from grant references, then prepare to create
  a dumb from mapped pages
- if GEM grant references are about to be provided for the
  imported PRIME buffer, then prepare for granting references
  and providing those to user-space

Implement handling of display buffers from backend to/from front
interaction point ov view:
- when importing a buffer from the frontend:
  - allocate/free xen ballooned pages via Xen balloon driver
    or by manually allocating a DMA buffer
  - if DMA buffer is used, then increase/decrease its pages
    reservation accordingly
  - map/unmap foreign pages to the ballooned pages
- when exporting a buffer to the frontend:
  - grant references for the pages of the imported PRIME buffer
  - pass the grants back to user-space, so those can be shared
    with the frontend

Add an option to allocate DMA buffers as backing storage while
importing a frontend's buffer into host's memory:
for those use-cases when exported PRIME buffer will be used by
a device expecting CMA buffers only, it is possible to map
frontend's pages onto contiguous buffer, e.g. allocated via
DMA API.

Implement synchronous buffer deletion: for buffers, created from front's
grant references, synchronization between backend and frontend is needed
on buffer deletion as front expects us to unmap these references after
XENDISPL_OP_DBUF_DESTROY response.
For that reason introduce DRM_IOCTL_XEN_ZCOPY_DUMB_WAIT_FREE IOCTL:
this will block until dumb buffer, with the wait handle provided,
be freed.

The rationale behind implementing own wait handle:
  - dumb buffer handle cannot be used as when the PRIME buffer
    gets exported there are at least 2 handles: one is for the
    backend and another one for the importing application,
    so when backend closes its handle and the other application still
    holds the buffer then there is no way for the backend to tell
    which buffer we want to wait for while calling xen_ioctl_wait_free
  - flink cannot be used as well as it is gone when DRM core
    calls .gem_free_object_unlocked

Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
  • Loading branch information
Oleksandr Andrushchenko authored and andr2000 committed Jun 18, 2018
1 parent 3687370 commit 4881b23
Show file tree
Hide file tree
Showing 7 changed files with 1,271 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Documentation/gpu/xen-zcopy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
==============================================
drm/xen-zcopy Xen zero-copy helper DRM driver
==============================================

This helper driver allows implementing zero-copying use-cases
when using Xen para-virtualized frontend display driver:

- a dumb buffer created on backend's side can be shared
with the Xen PV frontend driver, so it directly writes
into backend's domain memory (into the buffer exported from
DRM/KMS driver of a physical display device)
- a dumb buffer allocated by the frontend can be imported
into physical device DRM/KMS driver, thus allowing to
achieve no copying as well

DRM_XEN_ZCOPY_DUMB_FROM_REFS IOCTL
==================================

.. kernel-doc:: include/uapi/drm/xen_zcopy_drm.h
:doc: DRM_XEN_ZCOPY_DUMB_FROM_REFS

DRM_XEN_ZCOPY_DUMB_TO_REFS IOCTL
================================

.. kernel-doc:: include/uapi/drm/xen_zcopy_drm.h
:doc: DRM_XEN_ZCOPY_DUMB_TO_REFS

DRM_XEN_ZCOPY_DUMB_WAIT_FREE IOCTL
==================================

.. kernel-doc:: include/uapi/drm/xen_zcopy_drm.h
:doc: DRM_XEN_ZCOPY_DUMB_WAIT_FREE
25 changes: 25 additions & 0 deletions drivers/gpu/drm/xen/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ config DRM_XEN
Choose this option if you want to enable DRM support
for Xen.

choice
prompt "Xen DRM drivers selection"
depends on DRM_XEN

config DRM_XEN_FRONTEND
tristate "Para-virtualized frontend driver for Xen guest OS"
depends on DRM_XEN
Expand All @@ -15,3 +19,24 @@ config DRM_XEN_FRONTEND
help
Choose this option if you want to enable a para-virtualized
frontend DRM/KMS driver for Xen guest OSes.

config DRM_XEN_ZCOPY
tristate "Zero copy helper DRM driver for Xen"
depends on DRM_XEN
depends on DRM
select DRM_KMS_HELPER
help
Choose this option if you want to enable a zero copy
helper DRM driver for Xen. This is implemented via mapping
of foreign display buffer pages into current domain and
exporting a dumb via PRIME interface. This allows
driver domains to use buffers of unpriveledged guests without
additional memory copying.

config DRM_XEN_ZCOPY_CMA
bool "Use CMA to allocate buffers"
depends on DRM_XEN_ZCOPY
help
Use CMA to allocate display buffers.

endchoice
5 changes: 5 additions & 0 deletions drivers/gpu/drm/xen/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ drm_xen_front-objs := xen_drm_front.o \
xen_drm_front_gem.o

obj-$(CONFIG_DRM_XEN_FRONTEND) += drm_xen_front.o

drm_xen_zcopy-objs := xen_drm_zcopy.o \
xen_drm_zcopy_balloon.o

obj-$(CONFIG_DRM_XEN_ZCOPY) += drm_xen_zcopy.o
Loading

0 comments on commit 4881b23

Please sign in to comment.