From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F41B9C3DA6F for ; Fri, 25 Aug 2023 11:41:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82C9C280055; Fri, 25 Aug 2023 07:41:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7DB7E280038; Fri, 25 Aug 2023 07:41:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CAF1280055; Fri, 25 Aug 2023 07:41:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 5E603280038 for ; Fri, 25 Aug 2023 07:41:28 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2B5C2C04AD for ; Fri, 25 Aug 2023 11:41:28 +0000 (UTC) X-FDA: 81162436656.13.B48D5FE Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by imf19.hostedemail.com (Postfix) with ESMTP id 45F2F1A0018 for ; Fri, 25 Aug 2023 11:41:26 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=l3dZTosl; spf=pass (imf19.hostedemail.com: domain of ppaalanen@gmail.com designates 209.85.167.54 as permitted sender) smtp.mailfrom=ppaalanen@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692963686; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7XB8gnfeXwz3PBP03jcAxDaUlg2aSuMcd4cXYoa7Jfk=; b=F7vG2mEBlXuf192w+XSWznjQDSNGvLhs3/6T42/IiyFbuNXreJKhwQpNSbbsfFa7HCkq7+ fBxKf+/gkpvqqPOjeFOHHvlqvgC2CqIaTs5GoxaWFeO/4KgzcazX4OhlEvccK12+xEmz+R wmDwL9m5e515NKcRxMdY4b0q2dthDFI= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=l3dZTosl; spf=pass (imf19.hostedemail.com: domain of ppaalanen@gmail.com designates 209.85.167.54 as permitted sender) smtp.mailfrom=ppaalanen@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692963686; a=rsa-sha256; cv=none; b=UeFiznLxGCX+gzNxQNrm+YnTu+jTbkk+CX1AR/fuflgJ/YArHkfqpDV3KTlrlcGPSsfsc+ 3YA/epHdywJZiwDirNsQHGMM1DiXgdOkxVi3wiYmLwzK/7j9Ro0QoVtTjKFPmbDafXCnbC chv+P93fGTh68262nISA0bkfc1Ig99I= Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-4ff933f9ca8so1247158e87.1 for ; Fri, 25 Aug 2023 04:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692963684; x=1693568484; h=mime-version:references:in-reply-to:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=7XB8gnfeXwz3PBP03jcAxDaUlg2aSuMcd4cXYoa7Jfk=; b=l3dZTosl7Hz9yo3uNyJ027jBuQwNpn0tO07C3kMRvb3/ali/t2h/STlmvOWPZo1AcK Man4yRSr/uFPCpRgEeU0oiaZC3h07S6tgb0mWNSTwh64YH8vgpOT7r56TfrTxjDO8LTL chQAjdC0bsG5BFxHD4lTiKupBryWo8HJd6ayTu7fHX4feT/qjQcPtxVKxnkTCUGPODe/ VQq/BVKZVSjHMHV7ePch7Je1mrieoy0jjWqQNz+F9t6aL7sbvhak4VP+D9IoMMOZoFvA NeQP+QwUCImDD+Xl2iSaR97g8TdOS+UUE+2HITfg2lrBbScs4rYLaLNQTCewIHe7HVvl F5Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692963684; x=1693568484; h=mime-version:references:in-reply-to:message-id:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7XB8gnfeXwz3PBP03jcAxDaUlg2aSuMcd4cXYoa7Jfk=; b=ZHZvcoiZjd39dVJRb2Xe+Pv6LEPPUM2EljcoVXG0ut5q07PMi9IgNc5uduOPEmhMwf d+FWTb1B4v6tLoH7St2JCqOQ1mRYxCNsg+O8nVSHBqwaIfOU3EA7I0Gg6y+FwpgpXAJc 0qDDN7FjVrfflHbIHndOCQK+OGRVMs2vRms9VFH0yFn3sCdFyOA9VAJ1IWQP+kO+JWVl fTU6kzxtVLUcesKVgXLD0fNMN2DMianICrVChr6UZ97RD45p1NVYQ8AADnkvODT+CUz3 SxGSxXF8H6XG2Gmlp4A1IRHawuoCCficjWPVXZQreTUfWPmHLfNOZ3GSyyfJcNIYUFUW iO6Q== X-Gm-Message-State: AOJu0YzCvbUk1NxHQFLlk1tziNIxSUIEciX0IaxEzKx5RAGH9gsTQVCI mKDVA/fCy5H/t3OoM2CQyUM= X-Google-Smtp-Source: AGHT+IHDgb5Yhbcq9kfuhmnzC36PS1dJtyuRMhZs4ZKUIbWW5GhJVTYMYUihVW8mlau0avuqzWNPNw== X-Received: by 2002:a05:6512:ba0:b0:500:882b:e55a with SMTP id b32-20020a0565120ba000b00500882be55amr11342373lfv.45.1692963683929; Fri, 25 Aug 2023 04:41:23 -0700 (PDT) Received: from eldfell ([194.136.85.206]) by smtp.gmail.com with ESMTPSA id v9-20020a197409000000b004ff91dde4b4sm257584lfe.93.2023.08.25.04.41.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Aug 2023 04:41:23 -0700 (PDT) Date: Fri, 25 Aug 2023 14:41:10 +0300 From: Pekka Paalanen To: Hsia-Jun Li Cc: Tomasz Figa , linux-mm@kvack.org, dri-devel@lists.freedesktop.org, Linux Media Mailing List , hughd@google.com, akpm@linux-foundation.org, Simon Ser , Hans Verkuil , daniels@collabora.com, ayaka , linux-kernel@vger.kernel.org, Nicolas Dufresne Subject: Re: [RFC]: shmem fd for non-DMA buffer sharing cross drivers Message-ID: <20230825144110.1c58928f@eldfell> In-Reply-To: <65432c20-a6fd-141c-2ced-a7e6599a1e7c@synaptics.com> References: <029b982f-da62-4fa8-66c4-ab11a515574a@synaptics.com> <20230825104052.4573ab7b@eldfell> <65432c20-a6fd-141c-2ced-a7e6599a1e7c@synaptics.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.37; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="Sig_/=7wEatCdcP1mozuK9z20Vy1"; protocol="application/pgp-signature"; micalg=pgp-sha256 X-Rspamd-Queue-Id: 45F2F1A0018 X-Rspam-User: X-Stat-Signature: tbkgfhq66ojyyoba8x1r7qhnpkjzx8j1 X-Rspamd-Server: rspam01 X-HE-Tag: 1692963685-872594 X-HE-Meta: U2FsdGVkX194Zt+0I/cT73Xi0Oe37ol5jD3Cr1dk8BPbX6Fq51+Au6YUvocd4E097pIQja4rqdxAbaBqp1q+0T31AlCLpVPy9gCVJdT1VFL4jCYfXpqnHeeaUaiubqZIM9olh/61jI46yOBiCPBFwh/3vWuPKkvmBohHzZN6UFBWzJrvlsgOXfnr9DEcQVQEWYLCwzBsKBhkYrz7SG8LeVp74s9IVR1zFueN9zC/qypT3+DX+rpgkGNXiAui4ztM7JlhdKxLDzTZU6RxqsT4jlSXLK9SK1+yZkfPl9Xz00cfz98zXoEQX7O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TrG9faAnMu1g++ECc5GRV2QLhHWpZGiMHKFL8/UmzRP/WpyanIKuBEJKSgn+OEySXyOsbMD9erYfs/VKlxwBcf/x101E6GuERC4mUArssBpxKix9HMi2oM1mkvr/tFntPscbjNbzH8MuuzUfrD6yFSWlcrESidPClqk/UjDOdKDrJvmqhXLbogB4w08oBpd07HDsw3EAAjwHxioon+/JVBRRyrvgCVbiPucGNVs+ictciRX4sHK22VFhJHTdxjLnv76yp+AzfbiACQLmHZU5NnGU+kbZbOhiAnFQmz5aRkZ5KPkI1oDo1FASSkyeCG0D8QCUDmj4syKYaUhFkLrDm3qhL5//GfR8AsIZwXO2P6J3Nr48FbwIOjeLZz7yyRh9sDp2T9ZfEvDF6qFEIIV/7CMJt7UQH/j9TqJDf4Cxrx9MOu1gIJvLzcYJfImKDfSHvJvIfw/cPvAFAY410iFVTZiGuIxKfR2PO/sebaziXSfEngeHsjuFVzqP0/9cum1BR7JZo6yAf1ATuKFYm9RqHXglfv6OM3zbQcJSdqhDnV2Ox4IppnvVAWpDp0N2y8VBIY5ET AA3ZJjVo HDz/VROS1Krs2hF3Rn+HdetnpHh47XY3xmhCvPcvlyswbRZt3sRhs2X/bVY8/2y1Ll9JowbwZpIduV1c3yHhAYcmJENPUk0RGIcfYku2KcOOEaquVGeXDgbYrNTzrQTUVQe3tXwN0NUEVGf5XGNSa0AR1QjeOSN0kXFyEuGGxb1VM2hv1JDYqz5Ibh7dBtU3tUfrr1+AeSYevKSRy6HFlau0hLvslRdoFLA+eSzkEpg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: --Sig_/=7wEatCdcP1mozuK9z20Vy1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, 25 Aug 2023 15:56:18 +0800 Hsia-Jun Li wrote: > On 8/25/23 15:40, Pekka Paalanen wrote: > > Subject: > > Re: [RFC]: shmem fd for non-DMA buffer sharing cross drivers > > From: > > Pekka Paalanen > > Date: > > 8/25/23, 15:40 > >=20 > > To: > > Hsia-Jun Li > > CC: > > Tomasz Figa , linux-mm@kvack.org,=20 > > dri-devel@lists.freedesktop.org, Linux Media Mailing List=20 > > , hughd@google.com,=20 > > akpm@linux-foundation.org, Simon Ser , Hans Verkui= l=20 > > , daniels@collabora.com, ayaka=20 > > , linux-kernel@vger.kernel.org, Nicolas Dufresne=20 > > > >=20 > >=20 > > On Wed, 23 Aug 2023 15:11:23 +0800 > > Hsia-Jun Li wrote: > > =20 > >> On 8/23/23 12:46, Tomasz Figa wrote: =20 > >>> CAUTION: Email originated externally, do not click links or open atta= chments unless you recognize the sender and know the content is safe. > >>> > >>> > >>> Hi Hsia-Jun, > >>> > >>> On Tue, Aug 22, 2023 at 8:14=E2=80=AFPM Hsia-Jun Li wrote: =20 > >>>> Hello > >>>> > >>>> I would like to introduce a usage of SHMEM slimier to DMA-buf, the m= ajor > >>>> purpose of that is sharing metadata or just a pure container for cro= ss > >>>> drivers. > >>>> > >>>> We need to exchange some sort of metadata between drivers, likes dyn= amic > >>>> HDR data between video4linux2 and DRM. =20 > >>> If the metadata isn't too big, would it be enough to just have the > >>> kernel copy_from_user() to a kernel buffer in the ioctl code? > >>> =20 > >>>> Or the graphics frame buffer is > >>>> too complex to be described with plain plane's DMA-buf fd. > >>>> An issue between DRM and V4L2 is that DRM could only support 4 planes > >>>> while it is 8 for V4L2. It would be pretty hard for DRM to expend its > >>>> interface to support that 4 more planes which would lead to revision= of > >>>> many standard likes Vulkan, EGL. =20 > >>> Could you explain how a shmem buffer could be used to support frame > >>> buffers with more than 4 planes? > >>> If you are asking why we need this: =20 > >> 1. metadata likes dynamic HDR tone data > >> 2. DRM also challenges with this problem, let me quote what sima said: > >> "another trick that we iirc used for afbc is that sometimes the planes > >> have a fixed layout > >> like nv12 > >> and so logically it's multiple planes, but you only need one plane slot > >> to describe the buffer > >> since I think afbc had the "we need more than 4 planes" issue too" > >> > >> Unfortunately, there are vendor pixel formats are not fixed layout. > >> > >> 3. Secure(REE, trusted video piepline) info. > >> > >> For how to assign such metadata data. > >> In case with a drm fb_id, it is simple, we just add a drm plane proper= ty > >> for it. The V4L2 interface is not flexible, we could only leave into > >> CAPTURE request_fd as a control. =20 > >>>> Also, there is no reason to consume a device's memory for the content > >>>> that device can't read it, or wasting an entry of IOMMU for such dat= a. =20 > >>> That's right, but DMA-buf doesn't really imply any of those. DMA-buf > >>> is just a kernel object with some backing memory. It's up to the > >>> allocator to decide how the backing memory is allocated and up to the > >>> importer on whether it would be mapped into an IOMMU. > >>> =20 > >> I just want to say it can't be allocated at the same place which was f= or > >> those DMA bufs(graphics or compressed bitstream). > >> This also could be answer for your first question, if we place this ki= nd > >> of buffer in a plane for DMABUF(importing) in V4L2, V4L2 core would try > >> to prepare it, which could map it into IOMMU. > >> =20 > >>>> Usually, such a metadata would be the value should be written to a > >>>> hardware's registers, a 4KiB page would be 1024 items of 32 bits reg= isters. > >>>> > >>>> Still, I have some problems with SHMEM: > >>>> 1. I don't want the userspace modify the context of the SHMEM alloca= ted > >>>> by the kernel, is there a way to do so? =20 > >>> This is generally impossible without doing any of the two: > >>> 1) copying the contents to an internal buffer not accessible to the > >>> userspace, OR > >>> 2) modifying any of the buffer mappings to read-only > >>> > >>> 2) can actually be more costly than 1) (depending on the architecture, > >>> data size, etc.), so we shouldn't just discard the option of a simple > >>> copy_from_user() in the ioctl. > >>> =20 > >> I don't want the userspace access it at all. So that won't be a proble= m. =20 > > Hi, > >=20 > > if userspace cannot access things like an image's HDR metadata, then it > > will be impossible for userspace to program KMS to have the correct > > color pipeline, or to send intended HDR metadata to a video sink. > >=20 > > You cannot leave userspace out of HDR metadata handling, because quite > > probably the V4L2 buffer is not the only thing on screen. That means > > there must composition of multiple sources with different image > > properties and metadata, which means it is no longer obvious what HDR > > metadata should be sent to the video sink. > >=20 > > Even if it is a TV-like application rather than a windowed desktop, you > > will still have other contents to composite: OSD (volume indicators, > > channels indicators, program guide, ...), sub-titles, channel logos, > > notifications... These components ideally should not change their > > appearance arbitrarily with the main program content and metadata > > changes. Either the metadata sent to the video sink is kept static and > > the main program adapted on the fly, or main program metadata is sent > > to the video sink and the additional content is adapted on the fly. > >=20 > > There is only one set of HDR metadata and one composited image that can > > be sent to a video sink, so both must be chosen and produced correctly > > at the source side. This cannot be done automatically inside KMS kernel > > drivers. > > =20 > There may be some misunderstanding. > Let suppose this HDR data is in a vendor specific format. > Both upstream(decoder) and downstream(DRM) hardware devices are coming=20 > from the same vendor. > Then we just need to delivery the reference to this metadata buffer from= =20 > the upstream to downstream, both of drivers know how to handle it. >=20 > Despite the userspace, we just need to extend a wayland protocol that=20 > making wayland compositor know how to receive the reference to the=20 > metadata and set it to the DRM plane. Hi, FWIW, I don't think Wayland upstream (wayland-protocols) would be any more welcoming to opaque vendor-specific proprietary data blobs than the upstream Linux. (To everyone not following #dri-devel: There was a fairly long IRC discussion about how HDR metadata is an exceptionally poor use case example for "hidden" ancillary data blobs, and then continuing to how a mechanism to pass proprietary data blobs around would not be accepted upstream: https://oftc.irclog.whitequark.org/dri-devel/2023-08-25#1692950883-16929604= 35; ) > If you want a common HDR formats for all HDR variants(HDR10+, DV), I am=20 > not against it. But it won't make the userspace be able to fill the HDR=20 > metadata even the HDR data comes from the bitstream(likes SEI). We must=20 > consider the case of Secure Video Path(Digital Right), the bitstream is=20 > not accessible from (REE) userspace nor linux kernel, the downstream=20 > must take what the upstream feed. In that case, Secure Video Path is simply not possible to have (in upstream). Keeping actual pixels restricted is one thing, and understandable given they are the essence of the copyrighted material that the providers want to keep inaccessible. Not being able to deliver the metadata to userspace OTOH does not seem to have any justification in comparison. Thanks, pq > >>>> 2. Should I create a helper function for installing the SHMEM file a= s a fd? =20 > >>> We already have the udmabuf device [1] to turn a memfd into a DMA-buf, > >>> so maybe that would be enough? > >>> > >>> [1]https://elixir.bootlin.com/linux/v6.5-rc7/source/drivers/dma-buf/u= dmabuf.c > >>> =20 > >> It is the kernel driver that allocate this buffer. For example, v4l2 > >> CAPTURE allocate a buffer for metadata when VIDIOC_REQBUFS. > >> Or GBM give you a fd which is assigned with a surface. > >> > >> So we need a kernel interface. =20 > >>> Best, > >>> Tomasz > >>> =20 > >>>> -- > >>>> Hsia-Jun(Randy) Li =20 > > =20 >=20 --Sig_/=7wEatCdcP1mozuK9z20Vy1 Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEJQjwWQChkWOYOIONI1/ltBGqqqcFAmTok1YACgkQI1/ltBGq qqeJTQ//YMiq0BxH7MunqPu+HKNs+EQYCnO4e82D4TNR96frJ7j9Nyd1ru8ZFSav vdgXX0LN/mt682PDcZHIPLle/83LjpNwfD33ed/P3czpu9NMjhQHQ5wLu1kvvSv2 SINZnCmH8KitLvJsu51jWhI0mxEt74u/YjACIpgnxXLvsvZoyx+FOCF5XDm94qEi TAAbMdaFA5LBDFlHiarSbF17aM8aFm/XSJWPQZU9KHTv5ZCIiiU83CyDXIpV78OY FfxBhCCefD8NS11UUjqkEWb8VGQ97O5ZTtyl8Dio6A5lMcohWHnCFZr6bqGSG8kA OEPnm8WPEITW2nVUT3TMmJrPZFp3YPWZ3K/I0U7+KOzbI8FRl4nelg4jv5875eXi isQZ3iivpYLf2/0l7WKvu9ca50SFKxK6qsGy9qsi6jxph7PDQ0KaPz7E7iF15oQB z4rJY8cBfHSV0AVT7FQPiE0w8z7fWfvqzgtaVwk6fIkorxdHE32IdSsHOGjBnwWC EOmF96euDy/IG7eYatqN3Dld5sZyj4IZagRg2iQuMFnDpd++GdjZFUyvkkLjBVMP AdgaIM7sfLxPQNJDv5dqfhRGeFQrLWSGkXg7S40gY/9G1oqc3RtCu4XWbjR9ZrMm sGdU/4fFgELc4T+9oYTU5d7Cl6IwHKn1u2Kvdoa4hrFg8ynP5zI= =ltBp -----END PGP SIGNATURE----- --Sig_/=7wEatCdcP1mozuK9z20Vy1--