Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1182943pxb; Fri, 21 Jan 2022 11:40:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJzyuKf4glFV+l/BP+5Z6JrlDVbX9fxQKTncjWwTiDDE9RoAlGJYfIYhnOtry6+5/viS3/Xy X-Received: by 2002:a17:903:22d2:b0:14b:298c:433f with SMTP id y18-20020a17090322d200b0014b298c433fmr1846260plg.79.1642794055961; Fri, 21 Jan 2022 11:40:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642794055; cv=none; d=google.com; s=arc-20160816; b=p2BFbyPxjvYLaerz/XDt2gKPx1TkcZdgvYgas+HgCXVeGuAR84rqZTcQZo2Cd6QLwp JSQfRLrZyQbp98kikwOxuXNoN7q7iulCqkKbWiNGUHwXdDSkBl77zFKqbCBbL4KtSbLw /d+xdD/ClDqg34ri3l8oqBaNwzmqcYnmDIIMFcy+gTB5DpJ0t1sEeRCnuQ5yFzbfQOZr QSW5CtqC6p079Ti04PkrIO1NSMPdOdG+TCMKbqGw7vVdYCA2zWMTRa94k3iEOB1hDDtq IKWJv5svmAlDgpK+Mg8ahLEABH4Ko2E98grPm3a0G7oKlA4V5WZXy4xQr2Wv3TPR16VJ G9Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature; bh=0wqlG/hTKmwc1qlTFRNgFAeCCLQtJYdgJJ7JVZ30KiM=; b=WCeErWbHSjZBimEe9XF9aBW6KlYQfRWC8Nn46oplqW8BiWQpwRJs4XNMrYyOtS3QY1 aNKnbpocCjOuiT3ru2DGbVL1Ua7yBzDn3juMitxR1kvyknDkgDXyqdh/1GENWUKPWzm6 AfKVDMIISlvhnraI/3h+lxy9xqz2lVwgG6v2thOHcK+68RJ2ItPqcwtYXp8PIyiYEdfh 6dsbIYNBudlJEvzzk5f/Kz6p+eFwjnTLnFv1yaXliXFr5ow8pRODVX4jPVXFcsElMfFu 77PDSksiGEkhyvt5tmns7rhpAn4hOdid3ZaLifzoB/d8DwCvu1MPgT2IhJMmR4zfo8eR I3Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b="e3Pr/dvF"; 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 p1si7391436pfo.150.2022.01.21.11.40.43; Fri, 21 Jan 2022 11:40:55 -0800 (PST) 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=@ffwll.ch header.s=google header.b="e3Pr/dvF"; 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 S1355963AbiASPyH (ORCPT + 99 others); Wed, 19 Jan 2022 10:54:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355575AbiASPyF (ORCPT ); Wed, 19 Jan 2022 10:54:05 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 675A4C06173E for ; Wed, 19 Jan 2022 07:54:05 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id p18so5862113wmg.4 for ; Wed, 19 Jan 2022 07:54:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=0wqlG/hTKmwc1qlTFRNgFAeCCLQtJYdgJJ7JVZ30KiM=; b=e3Pr/dvFruT2iN6cAa0XHKtiGXwO9ueK+tpw6WUP4dtdEWHBBmgavmSQF8CU9J+UcN Hz8qBhrHQ1Vt/k5htfjwnT1NUI2SOss2Xgrkvlggt0Lb//TD0mBdhSnopsXNee83qc/w W1zJllJJxCEqEHZ8Wdd6DgeaZC8r9Yvd0MdkE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :content-transfer-encoding:in-reply-to; bh=0wqlG/hTKmwc1qlTFRNgFAeCCLQtJYdgJJ7JVZ30KiM=; b=KvQtnRvf0WCcvGM9xqVTCA19MNVtZxSX54gdsD3WjjHEn1Tib33RPOfnUWFxWCCEXZ zqNuNsRissyB0dabqi+63i2xcSlISIv0PzJ3K81fRDSZ6vufLdMBXLDD4h3FnrMs/i4f oETAZJLEN8+zSqd4ggUNeAqbYVSujYfkD3dk9zq1qwPb3Iadx+3Q4hwALdlbUEzuaMwc 4jZzXa4e5UwbK5twZZ+XxBn5lk2D0GTHr2+oBTBmM6zTeBNnnBsqgDsCphXoFsOnxDrj /hRLqRzD0JeD8y5wfBF7/w5omDewHT4vTZLvLX+mSKf/J31IQkXoaw7C9fKsVGt5bzgM MFxA== X-Gm-Message-State: AOAM532veK0FtxZ/ChmwKZetA0Ygz/L6IeuiD4JG/yu9zh2EBPm/nVtt 7VF/7Nhby5zJ/9G+E9s5ze/WqQ== X-Received: by 2002:a05:6000:381:: with SMTP id u1mr18768876wrf.431.1642607643845; Wed, 19 Jan 2022 07:54:03 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id w9sm6382224wmc.36.2022.01.19.07.54.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jan 2022 07:54:02 -0800 (PST) Date: Wed, 19 Jan 2022 16:54:00 +0100 From: Daniel Vetter To: Hridya Valsaraju Cc: Christian =?iso-8859-1?Q?K=F6nig?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Jonathan Corbet , Greg Kroah-Hartman , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Suren Baghdasaryan , Sumit Semwal , Benjamin Gaignard , Liam Mark , Laura Abbott , Brian Starkey , John Stultz , Tejun Heo , Zefan Li , Johannes Weiner , Dave Airlie , Jason Ekstrand , Matthew Auld , Matthew Brost , Li Li , Marco Ballesio , Miguel Ojeda , Hang Lu , Wedson Almeida Filho , Masahiro Yamada , Andrew Morton , Nathan Chancellor , Kees Cook , Nick Desaulniers , Chris Down , Vipin Sharma , Daniel Borkmann , Vlastimil Babka , Arnd Bergmann , dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, cgroups@vger.kernel.org, Kenny.Ho@amd.com, daniels@collabora.com, kaleshsingh@google.com, tjmercier@google.com Subject: Re: [RFC 4/6] dma-buf: Add DMA-BUF exporter op to charge a DMA-BUF to a cgroup. Message-ID: Mail-Followup-To: Hridya Valsaraju , Christian =?iso-8859-1?Q?K=F6nig?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Greg Kroah-Hartman , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Suren Baghdasaryan , Sumit Semwal , Benjamin Gaignard , Liam Mark , Laura Abbott , Brian Starkey , John Stultz , Tejun Heo , Zefan Li , Johannes Weiner , Dave Airlie , Jason Ekstrand , Matthew Auld , Matthew Brost , Li Li , Marco Ballesio , Miguel Ojeda , Hang Lu , Wedson Almeida Filho , Masahiro Yamada , Andrew Morton , Nathan Chancellor , Kees Cook , Nick Desaulniers , Chris Down , Vipin Sharma , Daniel Borkmann , Vlastimil Babka , Arnd Bergmann , dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, cgroups@vger.kernel.org, Kenny.Ho@amd.com, daniels@collabora.com, kaleshsingh@google.com, tjmercier@google.com References: <20220115010622.3185921-1-hridya@google.com> <20220115010622.3185921-5-hridya@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Operating-System: Linux phenom 5.10.0-8-amd64 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 18, 2022 at 10:54:16AM -0800, Hridya Valsaraju wrote: > On Sun, Jan 16, 2022 at 11:46 PM Christian K?nig > wrote: > > > > Am 15.01.22 um 02:06 schrieb Hridya Valsaraju: > > > The optional exporter op provides a way for processes to transfer > > > charge of a buffer to a different process. This is essential for the > > > cases where a central allocator process does allocations for various > > > subsystems, hands over the fd to the client who > > > requested the memory and drops all references to the allocated memory. > > > > > > Signed-off-by: Hridya Valsaraju > > > --- > > > include/linux/dma-buf.h | 18 ++++++++++++++++++ > > > 1 file changed, 18 insertions(+) > > > > > > diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h > > > index 7ab50076e7a6..d5e52f81cc6f 100644 > > > --- a/include/linux/dma-buf.h > > > +++ b/include/linux/dma-buf.h > > > @@ -13,6 +13,7 @@ > > > #ifndef __DMA_BUF_H__ > > > #define __DMA_BUF_H__ > > > > > > +#include > > > #include > > > #include > > > #include > > > @@ -285,6 +286,23 @@ struct dma_buf_ops { > > > > > > int (*vmap)(struct dma_buf *dmabuf, struct dma_buf_map *map); > > > void (*vunmap)(struct dma_buf *dmabuf, struct dma_buf_map *map); > > > + > > > + /** > > > + * @charge_to_cgroup: > > > + * > > > + * This is called by an exporter to charge a buffer to the specified > > > + * cgroup. > > > > Well that sentence makes absolutely no sense at all. > > > > The dma_buf_ops are supposed to be called by the DMA-buf subsystem on > > behalves of the importer and never by the exporter itself. > > > > I hope that this is just a documentation mixup. > > Thank you for taking a look Christian! > > Yes, that was poor wording, sorry about that. It should instead say > that the op would be called by the process the buffer is currently > charged to in order to transfer the buffer's charge to a different > cgroup. This is helpful in the case where a process acts as an > allocator for multiple client processes and we would like the > allocated buffers to be charged to the clients who requested their > allocation(instead of the allocating process as is the default > behavior). In Android, the graphics allocator HAL process[1] does > most of the graphics allocations on behalf of various clients. After > allocation, the HAL process passes the fd to the client over binder > IPC and the binder driver invokes the charge_to_cgroup() DMA-BUF op to > uncharge the buffer from the HAL process and charge it to the client > process instead. > > [1]: https://source.android.com/devices/graphics/arch-bq-gralloc For that use-case, do we really need to have the vfunc abstraction and force all exporters to do something reasonable with it? I think just storing the cgrpus gpu memory bucket this is charged against and doing this in a generic way would be a lot better. That way we can also easily add other neat features in the future, like e.g. ttm could take care of charge-assignement automatically maybe, or we could print the current cgroups charge relationship in the sysfs info file. Or anything else really. I do feel that in general for gpu memory cgroups to be useful, we should really have memory pools as a fairly strong concept. Otherwise every driver/allocator/thing is going to come up with their own, and very likely incompatible interpretation. And we end up with a supposed generic cgroups interface which cannot actually be used in a driver/vendor agnostic way at all. -Daniel > > Regards, > Hridya > > > > > > Regards, > > Christian. > > > > > The caller must hold a reference to @gpucg obtained via > > > + * gpucg_get(). The DMA-BUF will be uncharged from the cgroup it is > > > + * currently charged to before being charged to @gpucg. The caller must > > > + * belong to the cgroup the buffer is currently charged to. > > > + * > > > + * This callback is optional. > > > + * > > > + * Returns: > > > + * > > > + * 0 on success or negative error code on failure. > > > + */ > > > + int (*charge_to_cgroup)(struct dma_buf *dmabuf, struct gpucg *gpucg); > > > }; > > > > > > /** > > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch