From: Hridya Valsaraju <hridya@google.com>
To: "Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@linux.ie>,
"Daniel Vetter" <daniel@ffwll.ch>,
"Jonathan Corbet" <corbet@lwn.net>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Arve Hjønnevåg" <arve@android.com>,
"Todd Kjos" <tkjos@android.com>,
"Martijn Coenen" <maco@android.com>,
"Joel Fernandes" <joel@joelfernandes.org>,
"Christian Brauner" <christian@brauner.io>,
"Hridya Valsaraju" <hridya@google.com>,
"Suren Baghdasaryan" <surenb@google.com>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Benjamin Gaignard" <benjamin.gaignard@linaro.org>,
"Liam Mark" <lmark@codeaurora.org>,
"Laura Abbott" <labbott@redhat.com>,
"Brian Starkey" <Brian.Starkey@arm.com>,
"John Stultz" <john.stultz@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Tejun Heo" <tj@kernel.org>, "Zefan Li" <lizefan.x@bytedance.com>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Dave Airlie" <airlied@redhat.com>,
"Kenneth Graunke" <kenneth@whitecape.org>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Matthew Brost" <matthew.brost@intel.com>,
"Matthew Auld" <matthew.auld@intel.com>,
"Li Li" <dualli@google.com>, "Marco Ballesio" <balejs@google.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Hang Lu" <hangl@codeaurora.org>,
"Wedson Almeida Filho" <wedsonaf@google.com>,
"Masahiro Yamada" <masahiroy@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Nathan Chancellor" <nathan@kernel.org>,
"Kees Cook" <keescook@chromium.org>,
"Nick Desaulniers" <ndesaulniers@google.com>,
"Chris Down" <chris@chrisdown.name>,
"Vipin Sharma" <vipinsh@google.com>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Vlastimil Babka" <vbabka@suse.cz>,
"Arnd Bergmann" <arnd@arndb.de>,
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
Cc: Kenny.Ho@amd.com, daniels@collabora.com, kaleshsingh@google.com,
tjmercier@google.com
Subject: [RFC 5/6] dmabuf: system_heap: implement dma-buf op for GPU cgroup charge transfer
Date: Fri, 14 Jan 2022 17:06:03 -0800 [thread overview]
Message-ID: <20220115010622.3185921-6-hridya@google.com> (raw)
In-Reply-To: <20220115010622.3185921-1-hridya@google.com>
The DMA-BUF op can be invoked when a process that allocated a buffer
relinquishes its ownership and passes it over to another process.
Signed-off-by: Hridya Valsaraju <hridya@google.com>
---
drivers/dma-buf/heaps/system_heap.c | 43 +++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
index adfdc8c576f2..70f5b98f1157 100644
--- a/drivers/dma-buf/heaps/system_heap.c
+++ b/drivers/dma-buf/heaps/system_heap.c
@@ -307,6 +307,48 @@ static void system_heap_dma_buf_release(struct dma_buf *dmabuf)
kfree(buffer);
}
+#ifdef CONFIG_CGROUP_GPU
+static int system_heap_dma_buf_charge(struct dma_buf *dmabuf, struct gpucg *gpucg)
+{
+ struct gpucg *current_gpucg;
+ struct gpucg_device *gpucg_dev;
+ struct system_heap_buffer *buffer = dmabuf->priv;
+ size_t len = buffer->len;
+ int ret = 0;
+
+ /*
+ * Check that the process requesting the transfer is the same as the one
+ * to whom the buffer is currently charged to.
+ */
+ current_gpucg = gpucg_get(current);
+ if (current_gpucg != buffer->gpucg)
+ ret = -EPERM;
+
+ gpucg_put(current_gpucg);
+ if (ret)
+ return ret;
+
+ gpucg_dev = dma_heap_get_gpucg_dev(buffer->heap);
+
+ ret = gpucg_try_charge(gpucg, gpucg_dev, len);
+ if (ret)
+ return ret;
+
+ /* uncharge the buffer from the cgroup its currently charged to. */
+ gpucg_uncharge(buffer->gpucg, gpucg_dev, buffer->len);
+ gpucg_put(buffer->gpucg);
+
+ buffer->gpucg = gpucg;
+
+ return 0;
+}
+#else
+static int system_heap_dma_buf_charge(struct dma_buf *dmabuf, struct gpucg *gpucg)
+{
+ return 0;
+}
+#endif
+
static const struct dma_buf_ops system_heap_buf_ops = {
.attach = system_heap_attach,
.detach = system_heap_detach,
@@ -318,6 +360,7 @@ static const struct dma_buf_ops system_heap_buf_ops = {
.vmap = system_heap_vmap,
.vunmap = system_heap_vunmap,
.release = system_heap_dma_buf_release,
+ .charge_to_cgroup = system_heap_dma_buf_charge,
};
static struct page *alloc_largest_available(unsigned long size,
--
2.34.1.703.g22d0c6ccf7-goog
next prev parent reply other threads:[~2022-01-15 1:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-15 1:05 [RFC 0/6] Proposal for a GPU cgroup controller Hridya Valsaraju
2022-01-15 1:05 ` [RFC 1/6] gpu: rfc: " Hridya Valsaraju
2022-01-15 1:06 ` [RFC 2/6] cgroup: gpu: Add a cgroup controller for allocator attribution of GPU memory Hridya Valsaraju
2022-01-19 15:40 ` Randy Dunlap
2022-01-19 18:24 ` Hridya Valsaraju
2022-01-15 1:06 ` [RFC 3/6] dmabuf: heaps: Use the GPU cgroup charge/uncharge APIs Hridya Valsaraju
2022-01-15 1:06 ` [RFC 4/6] dma-buf: Add DMA-BUF exporter op to charge a DMA-BUF to a cgroup Hridya Valsaraju
2022-01-17 7:46 ` Christian König
2022-01-18 18:54 ` Hridya Valsaraju
2022-01-19 15:54 ` Daniel Vetter
2022-01-19 15:58 ` Christian König
2022-01-19 18:21 ` Hridya Valsaraju
2022-01-15 1:06 ` Hridya Valsaraju [this message]
2022-01-15 1:06 ` [RFC 6/6] android: binder: Add a buffer flag to relinquish ownership of fds Hridya Valsaraju
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220115010622.3185921-6-hridya@google.com \
--to=hridya@google.com \
--cc=Brian.Starkey@arm.com \
--cc=Kenny.Ho@amd.com \
--cc=airlied@linux.ie \
--cc=airlied@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=arve@android.com \
--cc=balejs@google.com \
--cc=benjamin.gaignard@linaro.org \
--cc=cgroups@vger.kernel.org \
--cc=chris@chrisdown.name \
--cc=christian.koenig@amd.com \
--cc=christian@brauner.io \
--cc=corbet@lwn.net \
--cc=daniel@ffwll.ch \
--cc=daniel@iogearbox.net \
--cc=daniels@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=dualli@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=hangl@codeaurora.org \
--cc=hannes@cmpxchg.org \
--cc=joel@joelfernandes.org \
--cc=john.stultz@linaro.org \
--cc=kaleshsingh@google.com \
--cc=keescook@chromium.org \
--cc=kenneth@whitecape.org \
--cc=labbott@redhat.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=lmark@codeaurora.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=maco@android.com \
--cc=masahiroy@kernel.org \
--cc=matthew.auld@intel.com \
--cc=matthew.brost@intel.com \
--cc=mripard@kernel.org \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=ojeda@kernel.org \
--cc=rodrigo.vivi@intel.com \
--cc=sumit.semwal@linaro.org \
--cc=surenb@google.com \
--cc=tj@kernel.org \
--cc=tjmercier@google.com \
--cc=tkjos@android.com \
--cc=tzimmermann@suse.de \
--cc=vbabka@suse.cz \
--cc=vipinsh@google.com \
--cc=wedsonaf@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®