<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 02.01.23 18:36, Koenig, Christian wrote:<br>
</div>
<blockquote type="cite" cite="mid:BN8PR12MB3587673F8EF2642D267E943D83F79@BN8PR12MB3587.namprd12.prod.outlook.com">
<style type="text/css" style="display:none;">P {margin-top:0;margin-bottom:0;}</style>
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only - General]<br>
</p>
<br>
<div>
<div class="elementToProof" style="font-family: Calibri, Arial,
Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);
background-color: rgb(255, 255, 255);">
<span style="font-family: Calibri, Arial, Helvetica, sans-serif;
font-size: 12pt; color: rgb(0, 0, 0); background-color:
rgb(255, 255, 255);">Sorry for the messed up mail. We currently have mail problems here at AMD.</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;
font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>Von:</b> Oleksii Moisieiev
<a class="moz-txt-link-rfc2396E" href="mailto:Oleksii_Moisieiev@epam.com"><Oleksii_Moisieiev@epam.com></a><br>
<b>Gesendet:</b> Montag, 2. Januar 2023 14:41<br>
<b>An:</b> <a class="moz-txt-link-abbreviated
moz-txt-link-freetext" href="mailto:jgross@suse.com">
jgross@suse.com</a> <a class="moz-txt-link-rfc2396E" href="mailto:jgross@suse.com">
<jgross@suse.com></a><br>
<b>Cc:</b> Oleksii Moisieiev <a class="moz-txt-link-rfc2396E" href="mailto:Oleksii_Moisieiev@epam.com">
<Oleksii_Moisieiev@epam.com></a>; Stefano Stabellini <a class="moz-txt-link-rfc2396E" href="mailto:sstabellini@kernel.org">
<sstabellini@kernel.org></a>; Oleksandr Tyshchenko <a class="moz-txt-link-rfc2396E" href="mailto:Oleksandr_Tyshchenko@epam.com">
<Oleksandr_Tyshchenko@epam.com></a>; <a class="moz-txt-link-abbreviated moz-txt-link-freetext" href="mailto:xen-devel@lists.xenproject.org">
xen-devel@lists.xenproject.org</a> <a class="moz-txt-link-rfc2396E" href="mailto:xen-devel@lists.xenproject.org">
<xen-devel@lists.xenproject.org></a>; <a class="moz-txt-link-abbreviated moz-txt-link-freetext" href="mailto:linux-kernel@vger.kernel.org">
linux-kernel@vger.kernel.org</a> <a class="moz-txt-link-rfc2396E" href="mailto:linux-kernel@vger.kernel.org">
<linux-kernel@vger.kernel.org></a>; Sumit Semwal <a class="moz-txt-link-rfc2396E" href="mailto:sumit.semwal@linaro.org">
<sumit.semwal@linaro.org></a>; Koenig, Christian <a class="moz-txt-link-rfc2396E" href="mailto:Christian.Koenig@amd.com">
<Christian.Koenig@amd.com></a>; <a class="moz-txt-link-abbreviated moz-txt-link-freetext" href="mailto:linux-media@vger.kernel.org">
linux-media@vger.kernel.org</a> <a class="moz-txt-link-rfc2396E" href="mailto:linux-media@vger.kernel.org">
<linux-media@vger.kernel.org></a>; <a class="moz-txt-link-abbreviated moz-txt-link-freetext" href="mailto:dri-devel@lists.freedesktop.org">
dri-devel@lists.freedesktop.org</a> <a class="moz-txt-link-rfc2396E" href="mailto:dri-devel@lists.freedesktop.org">
<dri-devel@lists.freedesktop.org></a>; <a class="moz-txt-link-abbreviated moz-txt-link-freetext" href="mailto:linaro-mm-sig@lists.linaro.org">
linaro-mm-sig@lists.linaro.org</a> <a class="moz-txt-link-rfc2396E" href="mailto:linaro-mm-sig@lists.linaro.org">
<linaro-mm-sig@lists.linaro.org></a><br>
<b>Betreff:</b> [PATCH v1 0/3] Add ioctls to map grant refs on the external backing storage</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText elementToProof">Hello,<br>
<br>
Let me introduce the new ioctls, which are intended to allow gntdev to<br>
map scatter-gather table on top of the existing dmabuf, referenced by<br>
file descriptor.<br>
<br>
When using dma-buf exporter to create dma-buf with backing storage and<br>
map it to the grant refs, provided from the domain, we've met a problem,<br>
that several HW (i.MX8 gpu in our case) do not support external buffer<br>
and requires backing storage to be created using it's native tools.<br>
That's why new ioctls were added to be able to pass existing dma-buffer<br>
fd as input parameter and use it as backing storage to export to refs.</div>
<div class="PlainText elementToProof"><br>
</div>
<div class="PlainText elementToProof">This is a pretty big NAK from my side to this approach.</div>
<div class="PlainText elementToProof"><br>
</div>
<div class="PlainText elementToProof">If you need to replace a file descriptor number local to your process then you can simply use dup2() from userspace.</div>
<div class="PlainText elementToProof"><br>
</div>
<div class="PlainText elementToProof">If your intention here is to replace the backing store of the fd on all processes which currently have it open then please just completely forget that. This will *NEVER* ever work correctly.</div>
<div class="PlainText elementToProof"><br>
</div>
<div class="PlainText elementToProof">Regards,</div>
<div class="PlainText elementToProof">Christian.</div>
<div class="PlainText elementToProof"><br>
</div>
</span></font></div>
</div>
</blockquote>
<p>Hello Cristian,</p>
<p><br>
</p>
<p>Thank you for the quick response.</p>
<p><br>
</p>
<p>My goal is to provide correct buffer for the interfaces, such as <font size="2">
<span style="font-size:11pt">zwp_linux_dmabuf_v1_interface, so zero-copy</span></font></p>
<p><font size="2"><span style="font-size:11pt">feature will work. My suggestion is to give a possibility to use some specific buffer as backing storage where caller</span></font></p>
<p><font size="2"><span style="font-size:11pt">takes responsibility for the provided buffer to have the correct format.</span></font></p>
<p><font size="2"><span style="font-size:11pt"><br>
</span></font></p>
<p><font size="2"><span style="font-size:11pt">In our case we are using these calls the following way:</span></font></p>
<p><font size="2"><span style="font-size:11pt">1) Get grefs from another Domain (We're working on the virtualized system with different Domains</span></font></p>
<p><font size="2"><span style="font-size:11pt">working as standalone VMs that are sharing resources);</span></font></p>
<p><font size="2"><span style="font-size:11pt">2) Create buffer using gbm_bo_create and receive fd (i.MX8 requires egl api to be called for the buffer</span></font></p>
<p><font size="2"><span style="font-size:11pt">allocation, or </span></font><font size="2"><span style="font-size:11pt"><font size="2"><span style="font-size:11pt">eglCreateImageKHR will return EGL_NO_IMAGE_KHR
</span></font>during param setting for zwp_linux_dmabuf);</span></font></p>
<p><font size="2"><span style="font-size:11pt">3) Call for </span></font><font size="2"><span style="font-size:11pt">IOCTL_GNTDEV_DMABUF_MAP_REFS_TO_BUF to map grefs using fd as the backing storage;</span></font></p>
<p><font size="2"><span style="font-size:11pt">4) Call for </span></font><font size="2"><span style="font-size:11pt">zwp_linux_dmabuf_v1_interface and use zero-copy feature with Wayland;</span></font></p>
<p><font size="2"><span style="font-size:11pt">5) After work finished - call for </span>
</font><font size="2"><span style="font-size:11pt">IOCTL_GNTDEV_DMABUF_MAP_RELEASE to unmap grant refs;</span></font></p>
<p><font size="2"><span style="font-size:11pt">6) Call gbm_bo_destroy to release allocated BO object;</span></font></p>
<p><font size="2"><span style="font-size:11pt">7) Call for </span></font><font size="2"><span style="font-size:11pt">IOCTL_GNTDEV_DMABUF_MAP_WAIT_RELEASED to wait until map released completely</span></font></p>
<p><font size="2"><span style="font-size:11pt">(This includes releasing grant refs on the Domain side).</span></font></p>
<p><font size="2"><span style="font-size:11pt"><br>
</span></font></p>
<p><font size="2"><span style="font-size:11pt">I've tested my changes on IMX8QM board using gbm_bo_create to allocate buffer and</span></font></p>
<p><font size="2"><span style="font-size:11pt">on QEMU setup using </span></font><font size="2"><span style="font-size:11pt">DRM_IOCTL_MODE_CREATE_DUMB for buffer allocation.</span></font></p>
<p><font size="2"><span style="font-size:11pt">I can provide test applications I've used for testing purposes.<br>
</span></font></p>
<p><font size="2"><span style="font-size:11pt"><br>
</span></font></p>
<p><font size="2"><span style="font-size:11pt">Best regards,</span></font></p>
<p><font size="2"><span style="font-size:11pt">Oleksii.</span></font></p>
<p><font size="2"><span style="font-size:11pt"><br>
</span></font><font size="2"><span style="font-size:11pt"></span></font><font size="2"><span style="font-size:11pt"></span></font></p>
<blockquote type="cite" cite="mid:BN8PR12MB3587673F8EF2642D267E943D83F79@BN8PR12MB3587.namprd12.prod.outlook.com">
<div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText elementToProof">Following calls were added:<br>
IOCTL_GNTDEV_DMABUF_MAP_REFS_TO_BUF - map existing buffer as the backing<br>
storage and export it to the provided grant refs;<br>
IOCTL_GNTDEV_DMABUF_MAP_RELEASE - detach buffer from the grant table and<br>
set notification to unmap grant refs before releasing the external<br>
buffer. After this call the external buffer should be detroyed.<br>
IOCTL_GNTDEV_DMABUF_MAP_WAIT_RELEASED - wait for timeout until buffer is<br>
completely destroyed and gnt refs unmapped so domain could free grant<br>
pages. Should be called after buffer was destoyed.<br>
<br>
Our setup is based on IMX8QM board. We're trying to implement zero-copy<br>
support for DomU graphics using Wayland zwp_linux_dmabuf_v1_interface<br>
implementation.<br>
<br>
For dma-buf exporter we used i.MX8 gpu native tools to create backing<br>
storage grant-refs, received from DomU. Buffer for the backing storage was<br>
allocated using gbm_bo_create call because gpu do not support external<br>
buffer and requires backing storage to be created using it's native tools<br>
(eglCreateImageKHR returns EGL_NO_IMAGE_KHR for buffers, which were not<br>
created using gbm_bo_create).<br>
<br>
This behaviour was also tested on Qemu setup using<br>
DRM_IOCTL_MODE_CREATE_DUMB call to create backing storage buffer.<br>
<br>
---<br>
Oleksii Moisieiev (3):<br>
xen/grant-table: save page_count on map and use if during async<br>
unmapping<br>
dma-buf: add dma buffer release notifier callback<br>
xen/grant-table: add new ioctls to map dmabuf to existing fd<br>
<br>
drivers/dma-buf/dma-buf.c | 44 ++++<br>
drivers/xen/gntdev-common.h | 8 +-<br>
drivers/xen/gntdev-dmabuf.c | 416 +++++++++++++++++++++++++++++++++++-<br>
drivers/xen/gntdev-dmabuf.h | 7 +<br>
drivers/xen/gntdev.c | 101 ++++++++-<br>
drivers/xen/grant-table.c | 73 +++++--<br>
include/linux/dma-buf.h | 15 ++<br>
include/uapi/xen/gntdev.h | 62 ++++++<br>
include/xen/grant_table.h | 8 +<br>
9 files changed, 703 insertions(+), 31 deletions(-)<br>
<br>
-- <br>
2.25.1<br>
</div>
</span></font></div>
</div>
</blockquote>
</body>
</html>