Skip to content

Commit 3df9604

Browse files
Oleksandr Andrushchenkoiartemenko
authored andcommitted
drm/xen-zcopy: Add Xen zero-copy helper DRM driver
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 <[email protected]>
1 parent 477b748 commit 3df9604

File tree

8 files changed

+1272
-0
lines changed

8 files changed

+1272
-0
lines changed

Documentation/gpu/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Linux GPU Driver Developer's Guide
2020
vgaarbiter
2121
bridge/dw-hdmi
2222
xen-front
23+
xen-zcopy
2324
todo
2425

2526
.. only:: subproject and html

Documentation/gpu/xen-zcopy.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
==============================================
2+
drm/xen-zcopy Xen zero-copy helper DRM driver
3+
==============================================
4+
5+
This helper driver allows implementing zero-copying use-cases
6+
when using Xen para-virtualized frontend display driver:
7+
8+
- a dumb buffer created on backend's side can be shared
9+
with the Xen PV frontend driver, so it directly writes
10+
into backend's domain memory (into the buffer exported from
11+
DRM/KMS driver of a physical display device)
12+
- a dumb buffer allocated by the frontend can be imported
13+
into physical device DRM/KMS driver, thus allowing to
14+
achieve no copying as well
15+
16+
DRM_XEN_ZCOPY_DUMB_FROM_REFS IOCTL
17+
==================================
18+
19+
.. kernel-doc:: include/uapi/drm/xen_zcopy_drm.h
20+
:doc: DRM_XEN_ZCOPY_DUMB_FROM_REFS
21+
22+
DRM_XEN_ZCOPY_DUMB_TO_REFS IOCTL
23+
================================
24+
25+
.. kernel-doc:: include/uapi/drm/xen_zcopy_drm.h
26+
:doc: DRM_XEN_ZCOPY_DUMB_TO_REFS
27+
28+
DRM_XEN_ZCOPY_DUMB_WAIT_FREE IOCTL
29+
==================================
30+
31+
.. kernel-doc:: include/uapi/drm/xen_zcopy_drm.h
32+
:doc: DRM_XEN_ZCOPY_DUMB_WAIT_FREE

drivers/gpu/drm/xen/Kconfig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ config DRM_XEN
55
Choose this option if you want to enable DRM support
66
for Xen.
77

8+
choice
9+
prompt "Xen DRM drivers selection"
10+
depends on DRM_XEN
11+
812
config DRM_XEN_FRONTEND
913
tristate "Para-virtualized frontend driver for Xen guest OS"
1014
depends on DRM_XEN
@@ -15,3 +19,24 @@ config DRM_XEN_FRONTEND
1519
help
1620
Choose this option if you want to enable a para-virtualized
1721
frontend DRM/KMS driver for Xen guest OSes.
22+
23+
config DRM_XEN_ZCOPY
24+
tristate "Zero copy helper DRM driver for Xen"
25+
depends on DRM_XEN
26+
depends on DRM
27+
select DRM_KMS_HELPER
28+
help
29+
Choose this option if you want to enable a zero copy
30+
helper DRM driver for Xen. This is implemented via mapping
31+
of foreign display buffer pages into current domain and
32+
exporting a dumb via PRIME interface. This allows
33+
driver domains to use buffers of unpriveledged guests without
34+
additional memory copying.
35+
36+
config DRM_XEN_ZCOPY_CMA
37+
bool "Use CMA to allocate buffers"
38+
depends on DRM_XEN_ZCOPY
39+
help
40+
Use CMA to allocate display buffers.
41+
42+
endchoice

drivers/gpu/drm/xen/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ drm_xen_front-objs := xen_drm_front.o \
99
xen_drm_front_gem.o
1010

1111
obj-$(CONFIG_DRM_XEN_FRONTEND) += drm_xen_front.o
12+
13+
drm_xen_zcopy-objs := xen_drm_zcopy.o \
14+
xen_drm_zcopy_balloon.o
15+
16+
obj-$(CONFIG_DRM_XEN_ZCOPY) += drm_xen_zcopy.o

0 commit comments

Comments
 (0)