[PATCH 0/8] xen: dma-buf support for grant device
andr2000 at gmail.com
Fri May 25 15:33:23 UTC 2018
From: Oleksandr Andrushchenko <oleksandr_andrushchenko at epam.com>
This work is in response to my previous attempt to introduce Xen/DRM
zero-copy driver  to enable Linux dma-buf API  for Xen based
frontends/backends. There is also an existing hyper_dmabuf approach
available  which, if reworked to utilize the proposed solution,
can greatly benefit as well.
RFC for this series was published and discussed , comments addressed.
The original rationale behind this work was to enable zero-copying
use-cases while working with Xen para-virtual display driver :
when using Xen PV DRM frontend driver then on backend side one will
need to do copying of display buffers' contents (filled by the
frontend's user-space) into buffers allocated at the backend side.
Taking into account the size of display buffers and frames per
second it may result in unneeded huge data bus occupation and
The helper driver  allows implementing zero-copying use-cases
when using Xen para-virtualized frontend display driver by implementing
a DRM/KMS helper driver running on backend's side.
It utilizes PRIME buffers API (implemented on top of Linux dma-buf)
to share frontend's buffers with physical device drivers on
- 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
Finally, it was discussed and decided (, ) that it is worth
implementing such use-cases via extension of the existing Xen gntdev
driver instead of introducing new DRM specific driver.
Please note, that the support of dma-buf is Linux only,
as dma-buf is a Linux only thing.
Now to the proposed solution. The changes to the existing Xen drivers
in the Linux kernel fall into 2 categories:
1. DMA-able memory buffer allocation and increasing/decreasing memory
reservation of the pages of such a buffer.
This is required if we are about to share dma-buf with the hardware
that does require those to be allocated with dma_alloc_xxx API.
(It is still possible to allocate a dma-buf from any system memory,
e.g. system pages).
2. Extension of the gntdev driver to enable it to import/export dma-buf’s.
The first four patches are in preparation for Xen dma-buf support,
but I consider those usable regardless of the dma-buf use-case,
e.g. other frontend/backend kernel modules may also benefit from these
for better code reuse:
The next three patches are Xen implementation of dma-buf as part of
the grant device:
The last patch makes it possible for in-kernel use of Xen dma-buf API:
The corresponding libxengnttab changes are available at .
All the above was tested with display backend  and its accompanying
helper library  on Renesas ARM64 based board.
*To all the communities*: I would like to ask you to review the proposed
solution and give feedback on it, so I can improve and send final
patches for review (this is still work in progress, but enough to start
discussing the implementation).
Thank you in advance,
Oleksandr Andrushchenko (8):
xen/grant-table: Make set/clear page private code shared
xen/balloon: Move common memory reservation routines to a module
xen/grant-table: Allow allocating buffers suitable for DMA
xen/gntdev: Allow mappings for DMA buffers
xen/gntdev: Add initial support for dma-buf UAPI
xen/gntdev: Implement dma-buf export functionality
xen/gntdev: Implement dma-buf import functionality
xen/gntdev: Expose gntdev's dma-buf API for in-kernel use
drivers/xen/Kconfig | 23 +
drivers/xen/Makefile | 1 +
drivers/xen/balloon.c | 71 +--
drivers/xen/gntdev.c | 1025 ++++++++++++++++++++++++++++++++-
drivers/xen/grant-table.c | 176 +++++-
drivers/xen/mem-reservation.c | 134 +++++
include/uapi/xen/gntdev.h | 106 ++++
include/xen/grant_dev.h | 37 ++
include/xen/grant_table.h | 28 +
include/xen/mem_reservation.h | 29 +
10 files changed, 1527 insertions(+), 103 deletions(-)
create mode 100644 drivers/xen/mem-reservation.c
create mode 100644 include/xen/grant_dev.h
create mode 100644 include/xen/mem_reservation.h
More information about the dri-devel