Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp45845lqo; Tue, 7 May 2024 11:38:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUMrkgWRAuTyxN9RVvCDZ+IuwNSn5AGr090EnWN6NCWRw6BhPdG9Zd2wjAw39OJOGn5bXh1qox1TGh5tT11oElCOKOc0f2o6sp1CfHzPw== X-Google-Smtp-Source: AGHT+IG9W1MU7GfYd5TKA5XAh2BocGYTmMDb3SHvRP+G0apzLeQJjvxcdFa6w/K6obcyV/x1xcwB X-Received: by 2002:a17:907:2da7:b0:a59:c319:f1e0 with SMTP id a640c23a62f3a-a59fb9e72e7mr21374466b.75.1715107096295; Tue, 07 May 2024 11:38:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715107096; cv=pass; d=google.com; s=arc-20160816; b=ciYV9HyqpSvW/x4yVfp0Xch3P09ciUADFAQUX0TshSe6A1bYBKtFDvIHfq+O+qNZ6v L0PRREOz+yDOjY4vLMjR1xN2fGaGkAATKGPs+77pjIUltgDqn0MNXFhy8OuRucMY3txq Jl4uu7PNzhlx/OAFFSD4gcaOB//yviM1WqFp58X/xOSO0FcZ+cdNDFTyZT2KdXaSmPWk ejI/LS4uwZOiOsS8CWDr7G1OSv2GEm/FIdn5dDVGzOJSXIYNM7UsNwnxoKvvOrtHUO0B +ajQ/2pxZoBaXyTyzsjp46GwUu+X2qE6Mul/0q2kIjI0TzWR2AUQr1GdQRMPrQneI4Z+ rmXQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=40s1dvQ8n0n8Z7jefb/zyZXdyjrgkZlr4Np09KHHwL0=; fh=cqpi+aiZqkxGJmpEVnm3lUrJFxrcxFmuuqOnCQLx4wc=; b=n6g/O4ASOOrNMoziiMXxnc4dVo/JhIc+0tOJpd2UeUPC8Sjv9ajP1x7za9vvyV15XB kFzHKVgGxIh6z9PIseu/iz71DfSNM7MJSojPvvV2xzSOuSwielKHt74T50nVoYdF2IKV 09YyAzft2fu2a0WAJ5jhxtyKXZfYrGPmHmEW7IkH6KQyn16XrglDaIrXtI8MbRbI8hve HTADCd6QxddfIH3Vr/KHyggdRTnHhXJzr5VsuQ0q1PcPX8ce0EAT41g0AIagEs5D1/+E n28dIdMh3/NGYeCiDwTOvQl8Olzukil7bRFaViM2zIqgSe80NsW1W3FxybWfRQ+8hjPc 7G+Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b="X/mgoeSO"; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-171992-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171992-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id go42-20020a1709070daa00b00a59d1052d02si2381832ejc.532.2024.05.07.11.38.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 11:38:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171992-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b="X/mgoeSO"; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-171992-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171992-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0A6531F22624 for ; Tue, 7 May 2024 18:38:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C1C516F29B; Tue, 7 May 2024 18:36:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="X/mgoeSO" Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 872AB16F274; Tue, 7 May 2024 18:36:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715106991; cv=none; b=kOx+IkpdwmP9CtwpDJanLWC+0f5mJNddpZjuvytPOqvV9qoeMr4X/Y5XWsmOfQKkoUawmi+9uI7CAQHYDZpspV4po8GVnRio2/oupA05Pl3vv2WH6CcOct01qqWG0dtYGuLyTgTAMO2ucm4SH3Aog0q6KRY0XcqtoRj4QbQQius= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715106991; c=relaxed/simple; bh=teQKchOEq9uRazgHEW2r0xLVQ+sR4ZkcVno60PW+UY8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mi7o5ztFrzo8ZhojP8RuRWkOnW5ZMfJ83/9kekBnNs2tJ9LnTZbI75BmYzpBqvICap2iEe1sJ0h0dFFG2nS1wFguk49E92sBPJYhCEr0XBYfIoysNx1N0biUDdL+mbySegx/qSyFtmOSgbqjfs638wk6tBkAgzfIHXzc61+JzUo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=X/mgoeSO; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 728A3904; Tue, 7 May 2024 20:36:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1715106979; bh=teQKchOEq9uRazgHEW2r0xLVQ+sR4ZkcVno60PW+UY8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=X/mgoeSODr0I6iobUNwoM8X5WMzal5pkTvtETqp7JW0yE1ELUfsgZlkItx6WSn1HJ kzHWjIBCuvr2wAwoOLsnlLqOzbCsETelWIbA77BDOdTVMxL86OdaD3yTc4QfaE4LPe +7YclK0P+9Me7DLG/h1upYg/q3F1J9HBn0qofRIs= Date: Tue, 7 May 2024 21:36:13 +0300 From: Laurent Pinchart To: Daniel Vetter Cc: Bryan O'Donoghue , Dmitry Baryshkov , Hans de Goede , Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , Christian =?utf-8?B?S8O2bmln?= , Lennart Poettering , Robert Mader , Sebastien Bacher , Linux Media Mailing List , "dri-devel@lists.freedesktop.org" , linaro-mm-sig@lists.linaro.org, Linux Kernel Mailing List , Milan Zamazal , Maxime Ripard , Andrey Konovalov Subject: Re: Safety of opening up /dev/dma_heap/* to physically present users (udev uaccess tag) ? Message-ID: <20240507183613.GB20390@pendragon.ideasonboard.com> References: <3c0c7e7e-1530-411b-b7a4-9f13e0ff1f9e@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: On Tue, May 07, 2024 at 07:36:59PM +0200, Daniel Vetter wrote: > On Tue, May 07, 2024 at 04:15:05PM +0100, Bryan O'Donoghue wrote: > > On 07/05/2024 16:09, Dmitry Baryshkov wrote: > > > Ah, I see. Then why do you require the DMA-ble buffer at all? If you are > > > providing data to VPU or DRM, then you should be able to get the buffer > > > from the data-consuming device. > > > > Because we don't necessarily know what the consuming device is, if any. > > Well ... that's an entirely different issue. And it's unsolved. > > Currently the approach is to allocate where the constraints are usually > most severe (like display, if you need that, or the camera module for > input) and then just pray the stack works out without too much copying. > All userspace (whether the generic glue or the userspace driver depends a > bit upon the exact api) does need to have a copy fallback for these > sharing cases, ideally with the copying accelerated by hw. > > If you try to solve this by just preemptive allocating everything as cma > buffers, then you'll make the situation substantially worse (because now > you're wasting tons of cma memory where you might not even need it). > And without really solving the problem, since for some gpus that memory > might be unusable (because you cannot scan that out on any discrete gpu, > and sometimes not even on an integrated one). I think we have a general agreement that the proposed solution is a stop-gap measure for an unsolved issue. Note that libcamera is already designed that way. The API is designed to import buffers, using dma-buf file handles. If an application has a way to allocate dma-buf instances through another means (from the display or from a video encoder for instance), it should do so, and use those buffers with libcamera. For applications that don't have an easy way to get hold of dma-buf instances, we have a buffer allocator helper as a side component. That allocator uses the underlying camera capture device, and allocates buffers from the V4L2 video device. It's only on platforms where we have no hardware camera processing (or, rather, platforms where the hardware vendors doesn't give us access to the camera hardware, such as recent Intel SoCs, or Qualcomm SoCs used in ARM laptops) that we need to allocate memory elsewhere. In the long run, I want a centralized memory allocator accessible by userspace applications (something similar in purpose to gralloc on Android), and I want to get rid of buffer allocation in libcamera (and even in V4L2, in the even longer term). That's the long run. Shorter term, we have a problem to solve, and the best option we have found so far is to rely on dma-buf heaps as a backend for the frame buffer allocatro helper in libcamera for the use case described above. This won't work in 100% of the cases, clearly. It's a stop-gap measure until we can do better. > > Could be VPU, could be Zoom/Hangouts via pipewire, could for argument sake > > be GPU or DSP. > > > > Also if we introduce a dependency on another device to allocate the output > > buffers - say always taking the output buffer from the GPU, then we've added > > another dependency which is more difficult to guarantee across different > > arches. -- Regards, Laurent Pinchart