Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3648001pxf; Mon, 15 Mar 2021 14:57:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaEE2xOCeKhJxpIGXh9cOhhm90kmSCU0QFxJhv+gsQGD+rES3AVgV7Vj59iDxWpk0ayIuk X-Received: by 2002:a17:907:4cf:: with SMTP id vz15mr25643120ejb.113.1615845465908; Mon, 15 Mar 2021 14:57:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615845465; cv=none; d=google.com; s=arc-20160816; b=DTgsjY2YCnFW1T0UuYYmV034RV5GZgORViMAR15n0uJj7y+4aU/FA/GZz4uobtyMvb z+7OYHtUcLPFDdvLTp9M9P37FMRHIN+hd1INU5LWIxeYD5XAsew1h3/3tyzfRmeTMpen ghCanBMj/ocGXCjVYkFplK9Jq+EdoEX3cbp4nc6N4JNgifv9C0wrMS9n82bJROdWxee+ 4ABw7fiP6Vr9UiFdyDhkEZi5Wf5PM2Fr3d65AViN+pCzYqWUC6og2Rn/n7wby8O8hJju jHKScJNj2OFhSIfF+obWAKC0NQuu2FDaxqfufAUmI4gFGNPd4/QxQTviv7HQKE/Ba2gj eZ+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=7XeKhr7CPuLWpezZdLdwR9imo7EjFN3I1W1hRStNFLA=; b=jrS8CXkW99kY9ngKC/pI+QCpojT6XyO46N+mfxf4OUj/WrSYYmIM5A6Ouu97qvWt36 tnojO5W2+czWC1yxjlGvCmZqDTEaNYNM4FhwQOsCBnR1ozP+qAqQUbA90Lshw8Z0xB2S mzFc/mlSR9PTFci4fu6EwWwDoU08Dy97F5rLKpI2ccfca5f5iXpei1GU1BAzmejTZ+SD Me0broCAPV85AWb1aKgOkd876E5SaCZPOJ4EzTl61UL5P5DMz6LHAO3sZwgokuAqNud1 tiOqGa7V79F/BGC3G1XCaZJpaqy2iBy5TfHwl0rjjcte396ws1YkGI6MKHLoAI4695iW DDxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@jlekstrand-net.20150623.gappssmtp.com header.s=20150623 header.b=rOyTvbm0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dg2si11317123edb.136.2021.03.15.14.57.23; Mon, 15 Mar 2021 14:57:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@jlekstrand-net.20150623.gappssmtp.com header.s=20150623 header.b=rOyTvbm0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232410AbhCOVMA (ORCPT + 99 others); Mon, 15 Mar 2021 17:12:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232848AbhCOVLp (ORCPT ); Mon, 15 Mar 2021 17:11:45 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8EC0C06175F for ; Mon, 15 Mar 2021 14:11:44 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id jt13so68736237ejb.0 for ; Mon, 15 Mar 2021 14:11:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jlekstrand-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=7XeKhr7CPuLWpezZdLdwR9imo7EjFN3I1W1hRStNFLA=; b=rOyTvbm0rpYHUYLb6C2cR5Mn1A5XpScpBFUv6Kl5IM8xCvvTNA8uxv/nnkuCW3pByP 2lOD0x39Lei9K/01UDokzH2XVK5fzt3v5yHjAyQ1kJCd/Ms9wz04ZKMommZx3myn2u7o UI6qU194/xGxo6NXHcek5AcF5/YhlJLsziczLaHhoskd/afTJFIPwu+P/5D9X76Kz8we NtK60DIllezF4lzOt7+gqJC06bk2fOielWRwh2ZOYj2/2eONW0e4MMiyhwmRsydVF4rj bGaH6LP7f53BmuAVRkZGpR4LYSiDvmd2URmLzjo3O99uwRJGN1eS/SKvGDWoIqswdmdw qFSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=7XeKhr7CPuLWpezZdLdwR9imo7EjFN3I1W1hRStNFLA=; b=b8Crk4j99VDq+MJE4+nObLVPo33Q+zz/7CXOh2iWu59A6Bhw0unXb/4R8thsP7Sv8s 0VH4YGNMZxm2hf4gr6GJESU7kIoMTLNlQqidGr9IC0ZtxZtRmG9ON/KA7Gao8zU/3l1C IDnhExHCIgMwnjH90qj0thi0KsHcN8SJzjoinWny+wd7/R5J6eDaH/g96HNXl0ndsRNb 7e/5iEXuMkCM5QzC3eQxeHmyUOOF8/8X0FkfF5PGQ7xfmVCFlKdTppwP6Rf8I/SjNlL0 iSsMN+tP6Yw9k50mODV3pawXOJ5DGp/HlU+K2Vnl8zFqQl/TiAM6L7n0j84cnKVOZP/+ Pj0A== X-Gm-Message-State: AOAM533laxcP9IfQFLYB138GFdbriCTTF2ktkxTAe0hJQHCuksdCAfLz FP6hu/fJpuYkprgClMGcHrjN25gTLkdoVofo3rN4tQ== X-Received: by 2002:a17:906:b288:: with SMTP id q8mr25774469ejz.210.1615842703458; Mon, 15 Mar 2021 14:11:43 -0700 (PDT) MIME-Version: 1.0 References: <20200311034351.1275197-3-jason@jlekstrand.net> <20200317212115.419358-1-jason@jlekstrand.net> <64eed158-22a8-10a7-7686-c972f8542649@daenzer.net> <20200930095542.GY438822@phenom.ffwll.local> In-Reply-To: <20200930095542.GY438822@phenom.ffwll.local> From: Jason Ekstrand Date: Mon, 15 Mar 2021 16:11:32 -0500 Message-ID: Subject: Re: [PATCH 3/3] RFC: dma-buf: Add an API for importing and exporting sync files (v5) To: =?UTF-8?Q?Michel_D=C3=A4nzer?= , Jason Ekstrand , Chenbo Feng , Daniel Stone , James Jones , LKML , Greg Hackmann , linaro-mm-sig@lists.linaro.org, =?UTF-8?Q?Kristian_H=C3=B8gsberg?= , Maling list - DRI developers , Jesse Hall , Dave Airlie , =?UTF-8?Q?Christian_K=C3=B6nig?= , "open list:DMA BUFFER SHARING FRAMEWORK" Cc: Daniel Vetter Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 30, 2020 at 4:55 AM Daniel Vetter wrote: > > On Wed, Sep 30, 2020 at 11:39:06AM +0200, Michel D=C3=A4nzer wrote: > > On 2020-03-17 10:21 p.m., Jason Ekstrand wrote: > > > Explicit synchronization is the future. At least, that seems to be w= hat > > > most userspace APIs are agreeing on at this point. However, most of = our > > > Linux APIs (both userspace and kernel UAPI) are currently built aroun= d > > > implicit synchronization with dma-buf. While work is ongoing to chan= ge > > > many of the userspace APIs and protocols to an explicit synchronizati= on > > > model, switching over piecemeal is difficult due to the number of > > > potential components involved. On the kernel side, many drivers use > > > dma-buf including GPU (3D/compute), display, v4l, and others. In > > > userspace, we have X11, several Wayland compositors, 3D drivers, comp= ute > > > drivers (OpenCL etc.), media encode/decode, and the list goes on. > > > > > > This patch provides a path forward by allowing userspace to manually > > > manage the fences attached to a dma-buf. Alternatively, one can thin= k > > > of this as making dma-buf's implicit synchronization simply a carrier > > > for an explicit fence. This is accomplished by adding two IOCTLs to > > > dma-buf for importing and exporting a sync file to/from the dma-buf. > > > This way a userspace component which is uses explicit synchronization= , > > > such as a Vulkan driver, can manually set the write fence on a buffer > > > before handing it off to an implicitly synchronized component such as= a > > > Wayland compositor or video encoder. In this way, each of the differ= ent > > > components can be upgraded to an explicit synchronization model one a= t a > > > time as long as the userspace pieces connecting them are aware of it = and > > > import/export fences at the right times. > > > > > > There is a potential race condition with this API if userspace is not > > > careful. A typical use case for implicit synchronization is to wait = for > > > the dma-buf to be ready, use it, and then signal it for some other > > > component. Because a sync_file cannot be created until it is guarant= eed > > > to complete in finite time, userspace can only signal the dma-buf aft= er > > > it has already submitted the work which uses it to the kernel and has > > > received a sync_file back. There is no way to atomically submit a > > > wait-use-signal operation. This is not, however, really a problem wi= th > > > this API so much as it is a problem with explicit synchronization > > > itself. The way this is typically handled is to have very explicit > > > ownership transfer points in the API or protocol which ensure that on= ly > > > one component is using it at any given time. Both X11 (via the PRESE= NT > > > extension) and Wayland provide such ownership transfer points via > > > explicit present and idle messages. > > > > > > The decision was intentionally made in this patch to make the import = and > > > export operations IOCTLs on the dma-buf itself rather than as a DRM > > > IOCTL. This makes it the import/export operation universal across al= l > > > components which use dma-buf including GPU, display, v4l, and others. > > > It also means that a userspace component can do the import/export > > > without access to the DRM fd which may be tricky to get in cases wher= e > > > the client communicates with DRM via a userspace API such as OpenGL o= r > > > Vulkan. At a future date we may choose to add direct import/export A= PIs > > > to components such as drm_syncobj to avoid allocating a file descript= or > > > and going through two ioctls. However, that seems to be something of= a > > > micro-optimization as import/export operations are likely to happen a= t a > > > rate of a few per frame of rendered or decoded video. > > > > > > v2 (Jason Ekstrand): > > > - Use a wrapper dma_fence_array of all fences including the new one > > > when importing an exclusive fence. > > > > > > v3 (Jason Ekstrand): > > > - Lock around setting shared fences as well as exclusive > > > - Mark SIGNAL_SYNC_FILE as a read-write ioctl. > > > - Initialize ret to 0 in dma_buf_wait_sync_file > > > > > > v4 (Jason Ekstrand): > > > - Use the new dma_resv_get_singleton helper > > > > > > v5 (Jason Ekstrand): > > > - Rename the IOCTLs to import/export rather than wait/signal > > > - Drop the WRITE flag and always get/set the exclusive fence > > > > > > Signed-off-by: Jason Ekstrand > > > > What's the status of this? DMA_BUF_IOCTL_EXPORT_SYNC_FILE would be usef= ul > > for Wayland compositors to wait for client buffers to become ready with= out > > being prone to getting delayed by later HW access to them, so it would = be > > nice to merge that at least (if DMA_BUF_IOCTL_IMPORT_SYNC_FILE is still > > controversial). > > I think the missing bits are just the usual stuff > - igt testcases > - userspace using the new ioctls > - review of the entire pile > > I don't think there's any fundamental objections aside from "no one ever > pushed this over the finish line". I just re-upped the patch series and you should have been on the CC for the cover letter. The Mesa MR is here: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4037 I'm going to try and knock out an IGT test quick but I don't know how much is really practical to test in that environment besides a basic fuzz for "does the IOCTL return a sync file". I've dropped all the sync_file import stuff in the latest version. It would have been useful for testing but it's also where all the scary stuff lives and I'm no longer convinced it solves any real problems for userspace. --Jason