Proposal for a GPU cgroup controller
Subsystems (9)
T.J. Mercier
reviewerv5 cover Proposal for a GPU cgroup controller
This patch series revisits the proposal for a GPU cgroup controller to track and limit memory allocations by various device/allocator subsystems. The patch series also contains a simple prototype to illustrate how Android intends to implement DMA-BUF allocator attribution using the GPU cgroup controller. The prototype does not include resource limit enforcements.
Changelog:
v5:
Rebase on top of v5.18-rc3
Drop the global GPU cgroup "total" (sum of all device totals) portion of the design since there is no currently known use for this per Tejun Heo.
Fix commit message which still contained the old name for dma_buf_transfer_charge per Michal Koutný.
Remove all GPU cgroup code except what's necessary to support charge transfer from dma_buf. Previously charging was done in export, but for non-Android graphics use-cases this is not ideal since there may be a delay between allocation and export, during which time there is no accounting.
Merge dmabuf: Use the GPU cgroup charge/uncharge APIs patch into
dmabuf: heaps: export system_heap buffers with GPU cgroup charging as a result of above.
Put the charge and uncharge code in the same file (system_heap_allocate, system_heap_dma_buf_release) instead of splitting them between the heap and the dma_buf_release. This avoids asymmetric management of the gpucg charges.
Modify the dma_buf_transfer_charge API to accept a task_struct instead of a gpucg. This avoids requiring the caller to manage the refcount of the gpucg upon failure and confusing ownership transfer logic.
Support all strings for gpucg_register_bucket instead of just string literals.
Enforce globally unique gpucg_bucket names.
Constrain gpucg_bucket name lengths to 64 bytes.
Append "-heap" to gpucg_bucket names from dmabuf-heaps.
Drop patch 7 from the series, which changed the types of binder_transaction_data's sender_pid and sender_euid fields. This was done in another commit here:
https://lore.kernel.org/all/20220210021129.3386083-4-masahiroy-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org/
Rename:
gpucg_try_charge -> gpucg_charge
find_cg_rpool_locked -> cg_rpool_find_locked
init_cg_rpool -> cg_rpool_init
get_cg_rpool_locked -> cg_rpool_get_locked
"gpu cgroup controller" -> "GPU controller"
gpucg_device -> gpucg_bucket
usage -> size
Tests:
Support both binder_fd_array_object and binder_fd_object. This is necessary because new versions of Android will use binder_fd_object instead of binder_fd_array_object, and we need to support both.
Tests for both binder_fd_array_object and binder_fd_object.
For binder_utils return error codes instead of
struct binder{fs}_ctx.
Use ifdef __ANDROID__ to choose platform-dependent temp path instead of a runtime fallback.
Ensure binderfs_mntpt ends with a trailing '/' character instead of prepending it where used.
v4:
Skip test if not run as root per Shuah Khan
Add better test logging for abnormal child termination per Shuah Khan
Adjust ordering of charge/uncharge during transfer to avoid potentially hitting cgroup limit per Michal Koutný
Adjust gpucg_try_charge critical section for charge transfer functionality
Fix uninitialized return code error for dmabuf_try_charge error case
v3:
Remove Upstreaming Plan from gpu-cgroup.rst per John Stultz
Use more common dual author commit message format per John Stultz
Remove android from binder changes title per Todd Kjos
Add a kselftest for this new behavior per Greg Kroah-Hartman
Include details on behavior for all combinations of kernel/userspace versions in changelog (thanks Suren Baghdasaryan) per Greg Kroah-Hartman.
Fix pid and uid types in binder UAPI header
v2:
See the previous revision of this change submitted by Hridya Valsaraju
at: https://lore.kernel.org/all/20220115010622.3185921-1-hridya-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org/
Move dma-buf cgroup charge transfer from a dma_buf_op defined by every heap to a single dma-buf function for all heaps per Daniel Vetter and Christian König. Pointers to struct gpucg and struct gpucg_device tracking the current associations were added to the dma_buf struct to achieve this.
Fix incorrect Kconfig help section indentation per Randy Dunlap.
History of the GPU cgroup controller
====================================
The GPU/DRM cgroup controller came into being when a consensus[1] was reached that the resources it tracked were unsuitable to be integrated into memcg. Originally, the proposed controller was specific to the DRM subsystem and was intended to track GEM buffers and GPU-specific resources[2]. In order to help establish a unified memory accounting model for all GPU and all related subsystems, Daniel Vetter put forth a suggestion to move it out of the DRM subsystem so that it can be used by other DMA-BUF exporters as well[3]. This RFC proposes an interface that does the same.
[1]: https://patchwork.kernel.org/project/dri-devel/cover/20190501140438.9506-1-brian.welty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org/#22624705
[2]: https://lore.kernel.org/amd-gfx/[email protected]/
[3]: https://lore.kernel.org/amd-gfx/YCVOl8%[email protected]/
Hridya Valsaraju (3):
gpu: rfc: Proposal for a GPU cgroup controller
cgroup: gpu: Add a cgroup controller for allocator attribution of GPU
memory
binder: Add flags to relinquish ownership of fds
T.J. Mercier (3):
dmabuf: heaps: export system_heap buffers with GPU cgroup charging
dmabuf: Add gpu cgroup charge transfer function
selftests: Add binder cgroup gpu memory transfer tests
Documentation/gpu/rfc/gpu-cgroup.rst | 190 +++++++ Documentation/gpu/rfc/index.rst | 4 + drivers/android/binder.c | 27 +- drivers/dma-buf/dma-buf.c | 80 ++- drivers/dma-buf/dma-heap.c | 39 ++ drivers/dma-buf/heaps/system_heap.c | 28 +- include/linux/cgroup_gpu.h | 137 +++++ include/linux/cgroup_subsys.h | 4 + include/linux/dma-buf.h | 49 +- include/linux/dma-heap.h | 15 + include/uapi/linux/android/binder.h | 23 +- init/Kconfig | 7 + kernel/cgroup/Makefile | 1 + kernel/cgroup/gpu.c | 386 +++++++++++++ .../selftests/drivers/android/binder/Makefile | 8 + .../drivers/android/binder/binder_util.c | 250 +++++++++ .../drivers/android/binder/binder_util.h | 32 ++ .../selftests/drivers/android/binder/config | 4 + .../binder/test_dmabuf_cgroup_transfer.c | 526 ++++++++++++++++++ 19 files changed, 1787 insertions(+), 23 deletions(-) create mode 100644 Documentation/gpu/rfc/gpu-cgroup.rst create mode 100644 include/linux/cgroup_gpu.h create mode 100644 kernel/cgroup/gpu.c create mode 100644 tools/testing/selftests/drivers/android/binder/Makefile create mode 100644 tools/testing/selftests/drivers/android/binder/binder_util.c create mode 100644 tools/testing/selftests/drivers/android/binder/binder_util.h create mode 100644 tools/testing/selftests/drivers/android/binder/config create mode 100644 tools/testing/selftests/drivers/android/binder/test_dmabuf_cgroup_transfer.c
Signature · 1 line
2.36.0.rc0.470.gd361397f0d-goog
T.J. Mercier
reviewerRFC v5 1/6 gpu: rfc: Proposal for a GPU cgroup controller
From: Hridya Valsaraju <[email protected]>
This patch adds a proposal for a new GPU cgroup controller for accounting/limiting GPU and GPU-related memory allocations. The proposed controller is based on the DRM cgroup controller[1] and follows the design of the RDMA cgroup controller.
The new cgroup controller would:
* Allow setting per-device limits on the total size of buffers allocated by device within a cgroup.
* Expose a per-device/allocator breakdown of the buffers charged to a cgroup.
The prototype in the following patches is only for memory accounting using the GPU cgroup controller and does not implement limit setting.
[1]: https://lore.kernel.org/amd-gfx/[email protected]/
---
v5 changes
Drop the global GPU cgroup "total" (sum of all device totals) portion of the design since there is no currently known use for this per Tejun Heo.
Update for renamed functions/variables.
v3 changes
Remove Upstreaming Plan from gpu-cgroup.rst per John Stultz.
Use more common dual author commit message format per John Stultz.
--- Documentation/gpu/rfc/gpu-cgroup.rst | 190 +++++++++++++++++++++++++++ Documentation/gpu/rfc/index.rst | 4 + 2 files changed, 194 insertions(+) create mode 100644 Documentation/gpu/rfc/gpu-cgroup.rst
Documentation/gpu/rfc/gpu-cgroup.rst new file +190 -0
@@ -0,0 +1,190 @@ +=================================== +GPU cgroup controller +=================================== + +Goals +===== +This document intends to outline a plan to create a cgroup v2 controller subsystem +for the per-cgroup accounting of device and system memory allocated by the GPU +and related subsystems. + +The new cgroup controller would: + +* Allow setting per-device limits on the total size of buffers allocated by a + device/allocator within a cgroup. + +* Expose a per-device/allocator breakdown of the buffers charged to a cgroup. + +Alternatives Considered +======================= + +The following alternatives were considered: + +The memory cgroup controller +____________________________ + +1. As was noted in [1], memory accounting provided by the GPU cgroup +controller is not a good fit for integration into memcg due to the +differences in how accounting is performed. It implements a mechanism +for the allocator attribution of GPU and GPU-related memory by +charging each buffer to the cgroup of the process on behalf of which +the memory was allocated. The buffer stays charged to the cgroup until +it is freed regardless of whether the process retains any references +to it. On the other hand, the memory cgroup controller offers a more +fine-grained charging and uncharging behavior depending on the kind of +page being accounted. + +2. Memcg performs accounting in units of pages. In the DMA-BUF buffer sharing model, +a process takes a reference to the entire buffer(hence keeping it alive) even if +it is only accessing parts of it. Therefore, per-page memory tracking for DMA-BUF +memory accounting would only introduce additional overhead without any benefits. + +[1]: https://patchwork.kernel.org/project/dri-devel/cover/[email protected]/#22624705 + +Userspace service to keep track of buffer allocations and releases +__________________________________________________________________ + +1. There is no way for a userspace service to intercept all allocations and releases. +2. In case the process gets killed or restarted, we lose all accounting so far. + +UAPI +==== +When enabled, the new cgroup controller would create the following files in every cgroup. + +:: + + gpu.memory.current (R) + gpu.memory.max (R/W) + +gpu.memory.current is a read-only file and would contain per-device memory allocations +in a key-value format where key is a string representing the device name and the value +is the size of memory charged to the device in the cgroup in bytes. The device name +should be globally unique. + +For example: + +:: + + cat /sys/kernel/fs/cgroup1/gpu.memory.current + dev1 4194304 + dev2 4194304 + +The string key for each device is set by the device driver when the device registers +with the GPU cgroup controller to participate in resource accounting (see section +'Design and Implementation' for more details). + +gpu.memory.max is a read/write file. It would show the current size limits on +memory usage for each allocator/device. + +Setting a limit for a particular device/allocator can be done as follows: + +:: + + echo “dev1 4194304” > /sys/kernel/fs/cgroup1/gpu.memory.max + +In this example, 'dev1' is the string key set by the device driver during +registration. + +Design and Implementation +========================= + +The cgroup controller would closely follow the design of the RDMA cgroup controller +subsystem where each cgroup maintains a list of resource pools. +Each resource pool is associated with a device name via a pointer to a struct gpucg_bucket +and contains a counter to track current, total, and the maximum limit set for the device. + +The below code block is a preliminary estimation on how the core kernel data structures +and APIs would look like. + +.. code-block:: c + + /* The GPU cgroup controller data structure */ + struct gpucg { + struct cgroup_subsys_state css; + + /* list of all resource pools that belong to this cgroup */ + struct list_head rpools; + }; + + /* A named entity representing bucket of tracked memory. */ + struct gpucg_bucket { + /* list of various resource pools in various cgroups that the bucket is part of */ + struct list_head rpools; + + /* list of all buckets registered for GPU cgroup accounting */ + struct list_head bucket_node; + + /* string to be used as identifier for accounting and limit setting */ + const char *name; + }; + + struct gpucg_resource_pool { + /* The bucket whose resource usage is tracked by this resource pool */ + struct gpucg_bucket *bucket; + + /* list of all resource pools for the cgroup */ + struct list_head cg_node; + + /* list maintained by the gpucg_bucket to keep track of its resource pools */ + struct list_head bucket_node; + + /* tracks memory usage of the resource pool */ + struct page_counter total; + }; + + /** + * gpucg_register_bucket - Registers a bucket for memory accounting using the + * GPU cgroup controller. + * + * @bucket: The bucket to register for memory accounting. + * @name: Pointer to a null-terminated string to denote the name of the bucket. This name + * should be globally unique, and should not exceed @GPUCG_BUCKET_NAME_MAX_LEN bytes. + * + * @bucket must remain valid. @name will be copied. + */ + void gpucg_register_bucket(struct gpucg_bucket *bucket, const char *name) + + /** + * gpucg_charge - charge memory to the specified gpucg and gpucg_bucket. + * + * @gpucg: The gpu cgroup to charge the memory to. + * @bucket: The pool to charge the memory to. + * @size: The size of memory to charge in bytes. + * This size will be rounded up to the nearest page size. + * + * Return: returns 0 if the charging is successful and otherwise returns an + * error code. + */ + int gpucg_charge(struct gpucg *gpucg, struct gpucg_bucket *bucket, u64 size); + + /** + * gpucg_uncharge - uncharge memory from the specified gpucg and gpucg_bucket. + * The caller must hold a reference to @gpucg obtained through gpucg_get(). + * + * @gpucg: The gpu cgroup to uncharge the memory from. + * @bucket: The bucket to uncharge the memory from. + * @size: The size of memory to uncharge in bytes. + * This size will be rounded up to the nearest page size. + */ + void gpucg_uncharge(struct gpucg *gpucg, struct gpucg_bucket *bucket, u64 size); + + /** + * gpucg_transfer_charge - Transfer a GPU charge from one cgroup to another. + * + * @source: [in] The GPU cgroup the charge will be transferred from. + * @dest: [in] The GPU cgroup the charge will be transferred to. + * @bucket: [in] The GPU cgroup bucket corresponding to the charge. + * @size: [in] The size of the memory in bytes. + * This size will be rounded up to the nearest page size. + * + * Returns 0 on success, or a negative errno code otherwise. + */ + int gpucg_transfer_charge(struct gpucg *source, + struct gpucg *dest, + struct gpucg_bucket *bucket, + u64 size) + + +Future Work +=========== +Additional GPU resources can be supported by adding new controller files.
Documentation/gpu/rfc/index.rst +4 -0
@@ -23,3 +23,7 @@ host such documentation: .. toctree:: i915_scheduler.rst + +.. toctree:: + + gpu-cgroup.rst
Signature · 1 line
2.36.0.rc0.470.gd361397f0d-goog
Tejun Heo
maintainerRe: [RFC v5 1/6] gpu: rfc: Proposal for a GPU cgroup controller
Hello,
Quoted 13 lines · T.J. Mercier
From: Hridya Valsaraju <[email protected]>
This patch adds a proposal for a new GPU cgroup controller for accounting/limiting GPU and GPU-related memory allocations. The proposed controller is based on the DRM cgroup controller[1] and follows the design of the RDMA cgroup controller.
The new cgroup controller would:
* Allow setting per-device limits on the total size of buffers allocated by device within a cgroup.
* Expose a per-device/allocator breakdown of the buffers charged to a cgroup.
Quoted 7 lines
The prototype in the following patches is only for memory accounting using the GPU cgroup controller and does not implement limit setting.
[1]: https://lore.kernel.org/amd-gfx/[email protected]/
Signed-off-by Hridya Valsaraju <[email protected]>Signed-off-by T.J. Mercier <[email protected]>
Looks straight-forward enough from cgroup side. Are gpu folks generally happy? David, Daniel, Kenny, what are your thoughts?
Quoted 1 line
Documentation/gpu/rfc/gpu-cgroup.rst | 190 +++++++++++++++++++++++++++
Can you fold the important part into cgroup-v2.rst and maybe make the rest code comments if necessary?
Thanks.
Signature · 1 line
tejun
T.J. Mercier
reviewerRe: [RFC v5 1/6] gpu: rfc: Proposal for a GPU cgroup controller
Quoted 25 lines · Tejun Heo
Hello,
Quoted 13 lines · T.J. Mercier
From: Hridya Valsaraju <[email protected]>
This patch adds a proposal for a new GPU cgroup controller for accounting/limiting GPU and GPU-related memory allocations. The proposed controller is based on the DRM cgroup controller[1] and follows the design of the RDMA cgroup controller.
The new cgroup controller would:
* Allow setting per-device limits on the total size of buffers allocated by device within a cgroup.
* Expose a per-device/allocator breakdown of the buffers charged to a cgroup.Quoted 7 lines
The prototype in the following patches is only for memory accounting using the GPU cgroup controller and does not implement limit setting.
[1]: https://lore.kernel.org/amd-gfx/[email protected]/
Signed-off-by Hridya Valsaraju <[email protected]>Signed-off-by T.J. Mercier <[email protected]>
Quoted 8 lines
Looks straight-forward enough from cgroup side. Are gpu folks generally happy? David, Daniel, Kenny, what are your thoughts?
Quoted 1 line
Documentation/gpu/rfc/gpu-cgroup.rst | 190 +++++++++++++++++++++++++++Can you fold the important part into
cgroup-v2.rstand maybe make the rest code comments if necessary?
Sure thing, thanks.
Quoted 4 lines
Thanks.
--
tejun
T.J. Mercier
reviewerRFC v5 2/6 cgroup: gpu: Add a cgroup controller for allocator attribution of GPU memory
In reply to T.J. MercierFrom: Hridya Valsaraju <[email protected]>
The cgroup controller provides accounting for GPU and GPU-related memory allocations. The memory being accounted can be device memory or memory allocated from pools dedicated to serve GPU-related tasks.
This patch adds APIs to:
-allow a device to register for memory accounting using the GPU cgroup controller.
-charge and uncharge allocated memory to a cgroup.
When the cgroup controller is enabled, it would expose information about the memory allocated by each device(registered for GPU cgroup memory accounting) for each cgroup.
The API/UAPI can be extended to set per-device/total allocation limits in the future.
The cgroup controller has been named following the discussion in [1].
[1]: https://lore.kernel.org/amd-gfx/YCJp%2F%[email protected]/
---
v5 changes
Support all strings for gpucg_register_device instead of just string literals.
Enforce globally unique gpucg_bucket names.
Constrain gpucg_bucket name lengths to 64 bytes.
Obtain just a single css refcount instead of nr_pages for each charge.
Rename:gpucg_try_charge -> gpucg_chargefind_cg_rpool_locked -> cg_rpool_find_lockedinit_cg_rpool -> cg_rpool_initget_cg_rpool_locked -> cg_rpool_get_locked
"gpu cgroup controller" -> "GPU controller"gpucg_device -> gpucg_bucket
usage -> size
v4 changes
Adjust gpucg_try_charge critical section for future charge transfer functionality.
v3 changes
Use more common dual author commit message format per John Stultz.
v2 changes
Fix incorrect Kconfig help section indentation per Randy Dunlap.
--- include/linux/cgroup_gpu.h | 123 +++++++++++++ include/linux/cgroup_subsys.h | 4 + init/Kconfig | 7 + kernel/cgroup/Makefile | 1 + kernel/cgroup/gpu.c | 324 ++++++++++++++++++++++++++++++++++ 5 files changed, 459 insertions(+) create mode 100644 include/linux/cgroup_gpu.h create mode 100644 kernel/cgroup/gpu.c
include/linux/cgroup_gpu.h new file +123 -0
@@ -0,0 +1,123 @@ +/* SPDX-License-Identifier: MIT +* Copyright 2019 Advanced Micro Devices, Inc. +* Copyright (C) 2022 Google LLC. +*/ +#ifndef _CGROUP_GPU_H +#define _CGROUP_GPU_H + +#include <linux/cgroup.h> +#include <linux/list.h> + +#define GPUCG_BUCKET_NAME_MAX_LEN 64 + +#ifdef CONFIG_CGROUP_GPU +/* The GPU cgroup controller data structure */ +struct gpucg { +struct cgroup_subsys_state css; + +/* list of all resource pools that belong to this cgroup */ +struct list_head rpools; +}; + +/* A named entity representing bucket of tracked memory. */ +struct gpucg_bucket { +/* list of various resource pools in various cgroups that the bucket is part of */ +struct list_head rpools; + +/* list of all buckets registered for GPU cgroup accounting */ +struct list_head bucket_node; + +/* string to be used as identifier for accounting and limit setting */ +const char *name; +}; + +/** +* css_to_gpucg - get the corresponding gpucg ref from a cgroup_subsys_state +* @css: the target cgroup_subsys_state +* +* Returns: gpu cgroup that contains the @css +*/ +static inline struct gpucg *css_to_gpucg (struct cgroup_subsys_state *css) +{ + return css ? container_of(css, struct gpucg, css) : NULL; +} + +/** +* gpucg_get - get the gpucg reference that a task belongs to +* @task: the target task +* +* This increases the reference count of the css that the @task belongs to. +* +* Returns: reference to the gpu cgroup the task belongs to. +*/ +static inline struct gpucg *gpucg_get (struct task_struct *task) +{ +if (!cgroup_subsys_enabled (gpu_cgrp_subsys)) +return NULL ; +return css_to_gpucg (task_get_css (task, gpu_cgrp_id)); +} + +/** +* gpucg_put - put a gpucg reference +* @gpucg: the target gpucg +* +* Put a reference obtained via gpucg_get +*/ +static inline void gpucg_put (struct gpucg *gpucg) +{ +if (gpucg) +css_put (&gpucg->css); +} + +/** +* gpucg_parent - find the parent of a gpu cgroup +* @cg: the target gpucg +* +* This does not increase the reference count of the parent cgroup +* +* Returns: parent gpu cgroup of @cg +*/ +static inline struct gpucg *gpucg_parent (struct gpucg *cg) +{ +return css_to_gpucg (cg->css.parent); +} + +int gpucg_charge (struct gpucg *gpucg,struct gpucg_bucket *bucket,u64 size); +void gpucg_uncharge (struct gpucg *gpucg,struct gpucg_bucket *bucket,u64 size); +int gpucg_register_bucket (struct gpucg_bucket *bucket,const char *name); +#else /* CONFIG_CGROUP_GPU */ + +struct gpucg ; +struct gpucg_bucket ; + +static inline struct gpucg *css_to_gpucg (struct cgroup_subsys_state *css) +{ +return NULL ; +} + +static inline struct gpucg *gpucg_get (struct task_struct *task) +{ +return NULL ; +} + +static inline void gpucg_put (struct gpucg *gpucg) {} + +static inline struct gpucg *gpucg_parent (struct gpucg *cg) +{ +return NULL ; +} + +static inline int gpucg_charge (struct gpucg *gpucg, +struct gpucg_bucket *bucket, +u64 size) +{ +return 0 ; +} + +static inline void gpucg_uncharge (struct gpucg *gpucg, +struct gpucg_bucket *bucket, +u64 size) {} + +static inline int gpucg_register_bucket (struct gpucg_bucket *bucket,const char *name) {} +#endif /* CONFIG_CGROUP_GPU */ +#endif /* _CGROUP_GPU_H */
include/linux/cgroup_subsys.h +4 -0
@@ -65,6 +65,10 @@ SUBSYS(rdma) SUBSYS(misc)#endif +#if IS_ENABLED (CONFIG_CGROUP_GPU ) +SUBSYS(gpu) +#endif +/* * The following subsystems are not supported on the default hierarchy. */
init/Kconfig +7 -0
@@ -984,6 +984,13 @@ config BLK_CGROUP See Documentation/admin-guide/cgroup-v1/blkio-controller.rst for more information. +config CGROUP_GPU + bool "GPU controller (EXPERIMENTAL)" + select PAGE_COUNTER + help + Provides accounting and limit setting for memory allocations by the GPU and + GPU-related subsystems. + config CGROUP_WRITEBACK bool depends on MEMCG && BLK_CGROUP
kernel/cgroup/Makefile +1 -0
@@ -7,3 +7,4 @@ obj-$(CONFIG_CGROUP_RDMA) += rdma.o obj-$(CONFIG_CPUSETS) += cpuset.o obj-$(CONFIG_CGROUP_MISC) += misc.o obj-$(CONFIG_CGROUP_DEBUG) += debug.o +obj-$(CONFIG_CGROUP_GPU) += gpu.o
kernel/cgroup/gpu.c new file +324 -0
324 lines not on this page · raw message
Signature · 1 line
2.36.0.rc0.470.gd361397f0d-goog
T.J. Mercier
reviewerRFC v5 3/6 dmabuf: heaps: export system_heap buffers with GPU cgroup charging
In reply to T.J. MercierAll DMA heaps now register a new GPU cgroup bucket upon creation, and the system_heap now exports buffers associated with its GPU cgroup bucket for tracking purposes.
In order to support GPU cgroup charge transfer on a dma-buf, the current GPU cgroup information must be stored inside the dma-buf struct. For tracked buffers, exporters include the struct gpucg and struct gpucg_bucket pointers in the export info which can later be modified if the charge is migrated to another cgroup.
---
v5 changes
Merge dmabuf: Use the GPU cgroup charge/uncharge APIs into this patch.
Remove all GPU cgroup code from dma-buf except what's necessary to support charge transfer. Previously charging was done in export, but for non-Android graphics use-cases this is not ideal since there may be a dealy between allocation and export, during which time there is no accounting.
Append "-heap" to gpucg_bucket names.
Charge on allocation instead of export. This should more closely mirror non-Android use-cases where there is potentially a delay between allocation and export.
Put the charge and uncharge code in the same file (system_heap_allocate, system_heap_dma_buf_release) instead of splitting them between the heap and the dma_buf_release.
Move no-op code to header file to match other files in the series.
v3 changes
Use more common dual author commit message format per John Stultz.
v2 changes
Move dma-buf cgroup charge transfer from a dma_buf_op defined by every heap to a single dma-buf function for all heaps per Daniel Vetter and Christian König.
--- drivers/dma-buf/dma-buf.c | 19 +++++++++++++ drivers/dma-buf/dma-heap.c | 39 +++++++++++++++++++++++++++ drivers/dma-buf/heaps/system_heap.c | 28 +++++++++++++++++--- include/linux/dma-buf.h | 41 +++++++++++++++++++++++------ include/linux/dma-heap.h | 15 +++++++++++ 5 files changed, 130 insertions(+), 12 deletions(-)
drivers/dma-buf/dma-buf.c +19 -0
@@ -462,6 +462,24 @@ static struct file *dma_buf_getfile(struct dma_buf *dmabuf, int flags)* &dma_buf_ops. */ +#ifdef CONFIG_CGROUP_GPU +static void dma_buf_set_gpucg (struct dma_buf *dmabuf,const struct dma_buf_export_info *exp) +{ + dmabuf->gpucg = exp->gpucg; + dmabuf->gpucg_bucket = exp->gpucg_bucket; +} + +void dma_buf_exp_info_set_gpucg (struct dma_buf_export_info *exp_info, +struct gpucg *gpucg, +struct gpucg_bucket *gpucg_bucket) +{ + exp_info->gpucg = gpucg; + exp_info->gpucg_bucket = gpucg_bucket; +} +#else +static void dma_buf_set_gpucg (struct dma_buf *dmabuf,struct dma_buf_export_info *exp) {} +#endif +/** * dma_buf_export - Creates a new dma_buf, and associates an anon file * with this buffer, so it can be exported.
@@ -527,6 +545,7 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)init_waitqueue_head (&dmabuf->poll); dmabuf->cb_in.poll = dmabuf->cb_out.poll = &dmabuf->poll; dmabuf->cb_in.active = dmabuf->cb_out.active =0 ; +dma_buf_set_gpucg (dmabuf, exp_info);if (!resv) { resv = (struct dma_resv *)&dmabuf[1 ];
drivers/dma-buf/dma-heap.c +39 -0
@@ -7,10 +7,12 @@*/ #include <linux/cdev.h> +#include <linux/cgroup_gpu.h> #include <linux/debugfs.h> #include <linux/device.h> #include <linux/dma-buf.h> #include <linux/err.h> +#include <linux/kconfig.h> #include <linux/xarray.h> #include <linux/list.h> #include <linux/slab.h>
@@ -21,6 +23,7 @@#include <uapi/linux/dma-heap.h> #define DEVNAME "dma_heap" +#define HEAP_NAME_SUFFIX "-heap"#define NUM_HEAP_MINORS 128
@@ -31,6 +34,7 @@* @heap_devt heap device node * @list list head connecting to list of heaps * @heap_cdev heap char device +* @gpucg_bucket gpu cgroup bucket for memory accounting * * Represents a heap of memory from which buffers can be made. */
@@ -41,6 +45,9 @@ struct dma_heap {dev_t heap_devt;struct list_head list;struct cdev heap_cdev; +#ifdef CONFIG_CGROUP_GPU +struct gpucg_bucket gpucg_bucket; +#endif };static LIST_HEAD (heap_list);
@@ -216,6 +223,19 @@ const char *dma_heap_get_name(struct dma_heap *heap)return heap->name; } +/** +* dma_heap_get_gpucg_bucket() - get struct gpucg_bucket for the heap. +* @heap: DMA-Heap to get the gpucg_bucket struct for. +* +* Returns: +* The gpucg_bucket struct for the heap. NULL if the GPU cgroup controller is +* not enabled. +*/ +struct gpucg_bucket *dma_heap_get_gpucg_bucket (struct dma_heap *heap) +{ +return &heap->gpucg_bucket; +} +struct dma_heap *dma_heap_add (const struct dma_heap_export_info *exp_info) {struct dma_heap *heap, *h, *err_ret;
@@ -228,6 +248,12 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info)return ERR_PTR (-EINVAL ); } +if (IS_ENABLED (CONFIG_CGROUP_GPU ) &&strlen (exp_info->name) +strlen (HEAP_NAME_SUFFIX ) >= +GPUCG_BUCKET_NAME_MAX_LEN ) { +pr_err ("dma_heap: Name is too long for GPU cgroup\n" ); +return ERR_PTR (-ENAMETOOLONG ); + } +if (!exp_info->ops || !exp_info->ops->allocate) {pr_err ("dma_heap: Cannot add heap with invalid ops struct\n" );return ERR_PTR (-EINVAL );
@@ -253,6 +279,19 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) heap->ops = exp_info->ops; heap->priv = exp_info->priv; +if (IS_ENABLED (CONFIG_CGROUP_GPU )) { +char gpucg_bucket_name[GPUCG_BUCKET_NAME_MAX_LEN ]; + +snprintf (gpucg_bucket_name,sizeof (gpucg_bucket_name),"%s%s" , + exp_info->name,HEAP_NAME_SUFFIX ); + + ret =gpucg_register_bucket (dma_heap_get_gpucg_bucket (heap), gpucg_bucket_name); +if (ret <0 ) { + err_ret =ERR_PTR (ret); + goto err0; + } + } +/* Find unused minor number */ ret =xa_alloc (&dma_heap_minors, &minor, heap,XA_LIMIT (0 ,NUM_HEAP_MINORS -1 ),GFP_KERNEL );
drivers/dma-buf/heaps/system_heap.c +24 -4
@@ -297,6 +297,11 @@ static void system_heap_dma_buf_release(struct dma_buf *dmabuf) }sg_free_table (table);kfree (buffer); + +if (dmabuf->gpucg && dmabuf->gpucg_bucket) { +gpucg_uncharge (dmabuf->gpucg, dmabuf->gpucg_bucket, dmabuf->size); +gpucg_put (dmabuf->gpucg); + } }static const struct dma_buf_ops system_heap_buf_ops = {
@@ -346,11 +351,21 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,struct scatterlist *sg;struct list_head pages;struct page *page, *tmp_page; -int i, ret = -ENOMEM ; +struct gpucg *gpucg; +struct gpucg_bucket *gpucg_bucket; +int i, ret; + + gpucg =gpucg_get (current); + gpucg_bucket =dma_heap_get_gpucg_bucket (heap); + ret =gpucg_charge (gpucg, gpucg_bucket, len); +if (ret) + goto put_gpucg; buffer =kzalloc (sizeof (*buffer),GFP_KERNEL ); -if (!buffer) -return ERR_PTR (-ENOMEM ); +if (!buffer) { + ret = -ENOMEM ; + goto uncharge_gpucg; + }INIT_LIST_HEAD (&buffer->attachments);mutex_init (&buffer->lock);
@@ -396,6 +411,8 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap, exp_info.size = buffer->len; exp_info.flags = fd_flags; exp_info.priv = buffer; +dma_buf_exp_info_set_gpucg (&exp_info, gpucg, gpucg_bucket); + dmabuf =dma_buf_export (&exp_info);if (IS_ERR (dmabuf)) { ret =PTR_ERR (dmabuf);
@@ -414,7 +431,10 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,list_for_each_entry_safe (page, tmp_page, &pages, lru)__free_pages (page,compound_order (page));kfree (buffer); - +uncharge_gpucg: +gpucg_uncharge (gpucg, gpucg_bucket, len); +put_gpucg: +gpucg_put (gpucg);return ERR_PTR (ret); }
include/linux/dma-buf.h +33 -8
75 lines not on this page · raw message
include/linux/dma-heap.h +15 -0
@@ -10,6 +10,7 @@#define _DMA_HEAPS_H#include <linux/cdev.h> +#include <linux/cgroup_gpu.h> #include <linux/types.h> struct dma_heap ;
@@ -59,6 +60,20 @@ void *dma_heap_get_drvdata(struct dma_heap *heap);*/ const char *dma_heap_get_name (struct dma_heap *heap); +#ifdef CONFIG_CGROUP_GPU +/** +* dma_heap_get_gpucg_bucket() - get a pointer to the struct gpucg_bucket for the heap. +* @heap: DMA-Heap to retrieve gpucg_bucket for +* +* Returns: +* The gpucg_bucket struct for the heap. +*/ +struct gpucg_bucket *dma_heap_get_gpucg_bucket (struct dma_heap *heap); +#else /* CONFIG_CGROUP_GPU */ +static inline struct gpucg_bucket *dma_heap_get_gpucg_bucket (struct dma_heap *heap) +{return NULL ; } +#endif /* CONFIG_CGROUP_GPU */ +/** * dma_heap_add - adds a heap to dmabuf heaps * @exp_info: information needed to register this heap
Signature · 1 line
2.36.0.rc0.470.gd361397f0d-goog
T.J. Mercier
reviewerRFC v5 4/6 dmabuf: Add gpu cgroup charge transfer function
In reply to T.J. MercierThe dma_buf_transfer_charge function 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.
---
v5 changes
Fix commit message which still contained the old name for dma_buf_transfer_charge per Michal Koutný.
Modify the dma_buf_transfer_charge API to accept a task_struct instead of a gpucg. This avoids requiring the caller to manage the refcount of the gpucg upon failure and confusing ownership transfer logic.
v4 changes
Adjust ordering of charge/uncharge during transfer to avoid potentially hitting cgroup limit per Michal Koutný.
v3 changes
Use more common dual author commit message format per John Stultz.
v2 changes
Move dma-buf cgroup charge transfer from a dma_buf_op defined by every heap to a single dma-buf function for all heaps per Daniel Vetter and Christian König.
--- drivers/dma-buf/dma-buf.c | 57 +++++++++++++++++++++++++++++++++++ include/linux/cgroup_gpu.h | 14 +++++++++ include/linux/dma-buf.h | 6 ++++ kernel/cgroup/gpu.c | 62 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+)
drivers/dma-buf/dma-buf.c +57 -0
@@ -1341,6 +1341,63 @@ void dma_buf_vunmap(struct dma_buf *dmabuf, struct iosys_map *map) }EXPORT_SYMBOL_NS_GPL (dma_buf_vunmap,DMA_BUF ); +/** +* dma_buf_transfer_charge - Change the GPU cgroup to which the provided dma_buf is charged. +* @dmabuf: [in] buffer whose charge will be migrated to a different GPU cgroup +* @target: [in] the task_struct of the destination process for the GPU cgroup charge +* +* Only tasks that belong to the same cgroup the buffer is currently charged to +* may call this function, otherwise it will return -EPERM. +* +* Returns 0 on success, or a negative errno code otherwise. +*/ +int dma_buf_transfer_charge (struct dma_buf *dmabuf,struct task_struct *target) +{ +struct gpucg *current_gpucg, *target_gpucg, *to_release; +int ret; + +if (!dmabuf->gpucg || !dmabuf->gpucg_bucket) { +/* This dmabuf is not tracked under GPU cgroup accounting */ +return 0 ; + } + + current_gpucg =gpucg_get (current); + target_gpucg =gpucg_get (target); + to_release = target_gpucg; + +/* If the source and destination cgroups are the same, don't do anything. */ +if (current_gpucg == target_gpucg) { + ret =0 ; + goto skip_transfer; + } + +/* +* Verify that the cgroup of the process requesting the transfer +* is the same as the one the buffer is currently charged to. +*/ +mutex_lock (&dmabuf->lock); +if (current_gpucg != dmabuf->gpucg) { + ret = -EPERM ; + goto err; + } + + ret =gpucg_transfer_charge ( + dmabuf->gpucg, target_gpucg, dmabuf->gpucg_bucket, dmabuf->size); +if (ret) + goto err; + + to_release = dmabuf->gpucg; + dmabuf->gpucg = target_gpucg; + +err: +mutex_unlock (&dmabuf->lock); +skip_transfer: +gpucg_put (current_gpucg); +gpucg_put (to_release); +return ret; +} +EXPORT_SYMBOL_NS_GPL (dma_buf_transfer_charge,DMA_BUF ); +#ifdef CONFIG_DEBUG_FS static int dma_buf_debug_show (struct seq_file *s,void *unused) {
include/linux/cgroup_gpu.h +14 -0
@@ -83,7 +83,13 @@ static inline struct gpucg *gpucg_parent(struct gpucg *cg) }int gpucg_charge (struct gpucg *gpucg,struct gpucg_bucket *bucket,u64 size); +void gpucg_uncharge (struct gpucg *gpucg,struct gpucg_bucket *bucket,u64 size); + +int gpucg_transfer_charge (struct gpucg *source, +struct gpucg *dest, +struct gpucg_bucket *bucket, +u64 size);int gpucg_register_bucket (struct gpucg_bucket *bucket,const char *name);#else /* CONFIG_CGROUP_GPU */
@@ -118,6 +124,14 @@ static inline void gpucg_uncharge(struct gpucg *gpucg, struct gpucg_bucket *bucket, u64 size) {} +static inline int gpucg_transfer_charge (struct gpucg *source, +struct gpucg *dest, +struct gpucg_bucket *bucket, +u64 size) +{ +return 0 ; +} +static inline int gpucg_register_bucket (struct gpucg_bucket *bucket,const char *name) {}#endif /* CONFIG_CGROUP_GPU */ #endif /* _CGROUP_GPU_H */
include/linux/dma-buf.h +6 -0
@@ -18,6 +18,7 @@#include <linux/file.h> #include <linux/err.h> #include <linux/scatterlist.h> +#include <linux/sched.h> #include <linux/list.h> #include <linux/dma-mapping.h> #include <linux/fs.h>
@@ -650,9 +651,14 @@ void dma_buf_vunmap(struct dma_buf *dmabuf, struct iosys_map *map);void dma_buf_exp_info_set_gpucg (struct dma_buf_export_info *exp_info,struct gpucg *gpucg,struct gpucg_bucket *gpucg_bucket); + +int dma_buf_transfer_charge (struct dma_buf *dmabuf,struct task_struct *target);#else /* CONFIG_CGROUP_GPU */ static inline void dma_buf_exp_info_set_gpucg (struct dma_buf_export_info *exp_info,struct gpucg *gpucg,struct gpucg_bucket *gpucg_bucket) {} + +static inline int dma_buf_transfer_charge (struct dma_buf *dmabuf,struct task_struct *target) +{return 0 ; }#endif /* CONFIG_CGROUP_GPU */ #endif /* __DMA_BUF_H__ */
kernel/cgroup/gpu.c +62 -0
68 lines not on this page · raw message
Signature · 1 line
2.36.0.rc0.470.gd361397f0d-goog
T.J. Mercier
reviewerRFC v5 5/6 binder: Add flags to relinquish ownership of fds
In reply to T.J. MercierFrom: Hridya Valsaraju <[email protected]>
This patch introduces flags BINDER_FD_FLAG_SENDER_NO_NEED, and BINDER_FDA_FLAG_SENDER_NO_NEED that a process sending an individual fd or fd array to another process over binder IPC can set to relinquish ownership of the fds being sent for memory accounting purposes. If the flag is found to be set during the fd or fd array translation and the fd is for a DMA-BUF, the buffer is uncharged from the sender's cgroup and charged to the receiving process's cgroup instead.
It is up to the sending process to ensure that it closes the fds regardless of whether the transfer failed or succeeded.
Most graphics shared memory allocations in Android are done by the graphics allocator HAL process. On requests from clients, the HAL process allocates memory and sends the fds to the clients over binder IPC. The graphics allocator HAL will not retain any references to the buffers. When the HAL sets *_FLAG_SENDER_NO_NEED for fd arrays holding DMA-BUF fds, or individual fd objects, the gpu cgroup controller will be able to correctly charge the buffers to the client processes instead of the graphics allocator HAL.
Since this is a new feature exposed to userspace, the kernel and userspace must be compatible for the accounting to work for transfers. In all cases the allocation and transport of DMA buffers via binder will succeed, but only when both the kernel supports, and userspace depends on this feature will the transfer accounting work. The possible scenarios are detailed below:
1. new kernel + old userspace
The kernel supports the feature but userspace does not use it. The old userspace won't mount the new cgroup controller, accounting is not performed, charge is not transferred.
2. old kernel + new userspace
The new cgroup controller is not supported by the kernel, accounting is not performed, charge is not transferred.
3. old kernel + old userspace
Same as #2
4. new kernel + new userspace
Cgroup is mounted, feature is supported and used.
---
v5 changes
Support both binder_fd_array_object and binder_fd_object. This is necessary because new versions of Android will use binder_fd_object instead of binder_fd_array_object, and we need to support both.
Use the new, simpler dma_buf_transfer_charge API.
v3 changes
Remove android from title per Todd Kjos.
Use more common dual author commit message format per John Stultz.
Include details on behavior for all combinations of kernel/userspace versions in changelog (thanks Suren Baghdasaryan) per Greg Kroah-Hartman.
v2 changes
Move dma-buf cgroup charge transfer from a dma_buf_op defined by every heap to a single dma-buf function for all heaps per Daniel Vetter and Christian König.
--- drivers/android/binder.c | 27 +++++++++++++++++++++++---- drivers/dma-buf/dma-buf.c | 4 ++-- include/linux/dma-buf.h | 2 +- include/uapi/linux/android/binder.h | 23 +++++++++++++++++++---- 4 files changed, 45 insertions(+), 11 deletions(-)
drivers/android/binder.c +23 -4
@@ -42,6 +42,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/dma-buf.h> #include <linux/fdtable.h> #include <linux/file.h> #include <linux/freezer.h>
@@ -2170,7 +2171,7 @@ static int binder_translate_handle(struct flat_binder_object *fp,return ret; } -static int binder_translate_fd (u32 fd,binder_size_t fd_offset, +static int binder_translate_fd (u32 fd,binder_size_t fd_offset,__u32 flags,struct binder_transaction *t,struct binder_thread *thread,struct binder_transaction *in_reply_to)
@@ -2208,6 +2209,23 @@ static int binder_translate_fd(u32 fd, binder_size_t fd_offset, goto err_security; } +if (IS_ENABLED (CONFIG_CGROUP_GPU ) && (flags &BINDER_FD_FLAG_SENDER_NO_NEED )) { +if (is_dma_buf_file (file)) { +struct dma_buf *dmabuf = file->private_data; + + ret =dma_buf_transfer_charge (dmabuf, target_proc->tsk); +if (ret) +pr_warn ("%d:%d Unable to transfer DMA-BUF fd charge to %d\n" , + proc->pid, thread->pid, target_proc->pid); + }else { +binder_user_error ( +"%d:%d got transaction with SENDER_NO_NEED for non-dmabuf fd, %d\n" , + proc->pid, thread->pid, fd); + ret = -EINVAL ; + goto err_noneed; + } + } +/* * Add fixup record for this transaction. The allocation * of the fd in the target needs to be done from a
@@ -2226,6 +2244,7 @@ static int binder_translate_fd(u32 fd, binder_size_t fd_offset,return ret; err_alloc: +err_noneed: err_security:fput (file); err_fget:
@@ -2528,7 +2547,7 @@ static int binder_translate_fd_array(struct list_head *pf_head, ret =copy_from_user (&fd, sender_ufda_base + sender_uoffset,sizeof (fd));if (!ret) - ret =binder_translate_fd (fd, offset, t, thread, + ret =binder_translate_fd (fd, offset, fda->flags, t, thread, in_reply_to);if (ret)return ret >0 ? -EINVAL : ret;
@@ -3179,8 +3198,8 @@ static void binder_transaction(struct binder_proc *proc,struct binder_fd_object *fp =to_binder_fd_object (hdr);binder_size_t fd_offset = object_offset + (uintptr_t )&fp->fd - (uintptr_t )fp; -int ret =binder_translate_fd (fp->fd, fd_offset, t, - thread, in_reply_to); +int ret =binder_translate_fd (fp->fd, fd_offset, fp->flags, + t, thread, in_reply_to); fp->pad_binder =0 ; if (ret < 0 ||
drivers/dma-buf/dma-buf.c +2 -2
@@ -31,7 +31,6 @@#include "dma-buf-sysfs-stats.h" -static inline int is_dma_buf_file (struct file *);struct dma_buf_list {struct list_head head;
@@ -400,10 +399,11 @@ static const struct file_operations dma_buf_fops = {/* * is_dma_buf_file - Check if struct file* is associated with dma_buf */ -static inline int is_dma_buf_file (struct file *file) +int is_dma_buf_file (struct file *file) {return file->f_op == &dma_buf_fops; } +EXPORT_SYMBOL_NS_GPL (is_dma_buf_file,DMA_BUF );static struct file *dma_buf_getfile (struct dma_buf *dmabuf,int flags) {
include/linux/dma-buf.h +1 -1
@@ -614,7 +614,7 @@ dma_buf_attachment_is_dynamic(struct dma_buf_attachment *attach) {return !!attach->importer_ops; } - +int is_dma_buf_file (struct file *file);struct dma_buf_attachment *dma_buf_attach (struct dma_buf *dmabuf,struct device *dev); struct dma_buf_attachment *
include/uapi/linux/android/binder.h +19 -4
@@ -91,14 +91,14 @@ struct flat_binder_object {/** * struct binder_fd_object - describes a filedescriptor to be fixed up. * @hdr: common header structure -* @pad_flags: padding to remain compatible with old userspace code +* @flags: One or more BINDER_FD_FLAG_* flags * @pad_binder: padding to remain compatible with old userspace code * @fd: file descriptor * @cookie: opaque data, used by user-space */ struct binder_fd_object {struct binder_object_header hdr; -__u32 pad_flags; +__u32 flags;union {binder_uintptr_t pad_binder;__u32 fd;
@@ -107,6 +107,17 @@ struct binder_fd_object {binder_uintptr_t cookie; }; +enum { +/** +* @BINDER_FD_FLAG_SENDER_NO_NEED +* +* When set, the sender of a binder_fd_object wishes to relinquish ownership of the fd for +* memory accounting purposes. If the fd is for a DMA-BUF, the buffer is uncharged from the +* sender's cgroup and charged to the receiving process's cgroup instead. +*/ +BINDER_FD_FLAG_SENDER_NO_NEED =0x2000 , +}; +/* struct binder_buffer_object - object describing a userspace buffer * @hdr: common header structure * @flags: one or more BINDER_BUFFER_* flags
@@ -141,7 +152,7 @@ enum {/* struct binder_fd_array_object - object describing an array of fds in a buffer * @hdr: common header structure -* @pad: padding to ensure correct alignment +* flags: One or more BINDER_FDA_FLAG_* flags * @num_fds: number of file descriptors in the buffer * @parent: index in offset array to buffer holding the fd array * @parent_offset: start offset of fd array in the buffer
@@ -162,12 +173,16 @@ enum {*/ struct binder_fd_array_object {struct binder_object_header hdr; -__u32 pad; +__u32 flags;binder_size_t num_fds;binder_size_t parent;binder_size_t parent_offset; }; +enum { +BINDER_FDA_FLAG_SENDER_NO_NEED =BINDER_FD_FLAG_SENDER_NO_NEED , +}; +/* * On 64-bit platforms where user code may run in 32-bits the driver must * translate the buffer (and local binder) addresses appropriately.
Signature · 1 line
2.36.0.rc0.470.gd361397f0d-goog
Re: [RFC v5 5/6] binder: Add flags to relinquish ownership of fds
Quoted 22 lines · T.J. Mercier
From: Hridya Valsaraju <[email protected]>
This patch introduces flags
BINDER_FD_FLAG_SENDER_NO_NEED, andBINDER_FDA_FLAG_SENDER_NO_NEEDthat a process sending an individual fd or fd array to another process over binder IPC can set to relinquish ownership of the fds being sent for memory accounting purposes. If the flag is found to be set during the fd or fd array translation and the fd is for a DMA-BUF, the buffer is uncharged from the sender's cgroup and charged to the receiving process's cgroup instead.It is up to the sending process to ensure that it closes the fds regardless of whether the transfer failed or succeeded.
Most graphics shared memory allocations in Android are done by the graphics allocator HAL process. On requests from clients, the HAL process allocates memory and sends the fds to the clients over binder IPC. The graphics allocator HAL will not retain any references to the buffers. When the HAL sets
*_FLAG_SENDER_NO_NEEDfor fd arrays holding DMA-BUF fds, or individual fd objects, the gpu cgroup controller will be able to correctly charge the buffers to the client processes instead of the graphics allocator HAL.
Quoted 6 lines
Since this is a new feature exposed to userspace, the kernel and userspace must be compatible for the accounting to work for transfers. In all cases the allocation and transport of DMA buffers via binder will succeed, but only when both the kernel supports, and userspace depends on this feature will the transfer accounting work. The possible scenarios are detailed below:
New binder driver features which require userspace coordination can be "advertised" by the kernel via binderfs. You can see an example of how oneway_spam_detection is exposed in commit fc470abf54b2 ("binderfs: add support for feature files"). This is just an option to consider if it makes things easier in userspace. Although it seems that for the second scenario (old kernel + new userpsace) the flags would just be ignored.
Quoted 69 lines
1. new kernel + old userspace
The kernel supports the feature but userspace does not use it. The old userspace won't mount the new cgroup controller, accounting is not performed, charge is not transferred.2. old kernel + new userspace
The new cgroup controller is not supported by the kernel, accounting is not performed, charge is not transferred.3. old kernel + old userspace
Same as #24. new kernel + new userspace
Cgroup is mounted, feature is supported and used.Signed-off-by Hridya Valsaraju <[email protected]>Signed-off-by T.J. Mercier <[email protected]>---
v5 changes
Support bothbinder_fd_array_objectandbinder_fd_object. This is necessary because new versions of Android will usebinder_fd_objectinstead ofbinder_fd_array_object, and we need to support both.Use the new, simpler
dma_buf_transfer_chargeAPI.v3 changes
Remove android from title per Todd Kjos.Use more common dual author commit message format per John Stultz.
Include details on behavior for all combinations of kernel/userspace versions in changelog (thanks Suren Baghdasaryan) per Greg Kroah-Hartman.
v2 changes
Move dma-buf cgroup charge transfer from adma_buf_opdefined by every heap to a single dma-buf function for all heaps per Daniel Vetter and Christian König.--- drivers/android/binder.c | 27 +++++++++++++++++++++++---- drivers/dma-buf/dma-buf.c | 4 ++-- include/linux/dma-buf.h | 2 +- include/uapi/linux/android/binder.h | 23 +++++++++++++++++++---- 4 files changed, 45 insertions(+), 11 deletions(-)drivers/android/binder.c +2
-1@@ -42,6 +42,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/dma-buf.h> #include <linux/fdtable.h> #include <linux/file.h> #include <linux/freezer.h> @@ -2170,7 +2171,7 @@ static int binder_translate_handle(struct flat_binder_object *fp,return ret; } -static int binder_translate_fd (u32 fd,binder_size_t fd_offset, +static int binder_translate_fd (u32 fd,binder_size_t fd_offset,__u32 flags,struct binder_transaction *t,struct binder_thread *thread,struct binder_transaction *in_reply_to)@@ -2208,6 +2209,23 @@ static int binder_translate_fd(u32 fd, binder_size_t fd_offset, goto err_security;
drivers/android/binder.c static int binder_translate_fd(u32 fd, binder_size_t fd_offset, · line 2219
Quoted 10 lines
drivers/android/binder.c +8
-0} +if (IS_ENABLED (CONFIG_CGROUP_GPU ) && (flags &BINDER_FD_FLAG_SENDER_NO_NEED )) { +if (is_dma_buf_file (file)) { +struct dma_buf *dmabuf = file->private_data; + + ret =dma_buf_transfer_charge (dmabuf, target_proc->tsk); +if (ret) +pr_warn ("%d:%d Unable to transfer DMA-BUF fd charge to %d\n" , + proc->pid, thread->pid, target_proc->pid);
If we fail to transfer the charge, it seems we continue with the fixup allocation and then propagate the error. Shouldn't the translation be aborted at this point instead? Or is this supposed to be handled?
drivers/android/binder.c static int binder_translate_fd(u32 fd, binder_size_t fd_offset, · line 2220
Quoted 1 line
drivers/android/binder.c +1
-0+ }else {
nit: negating is_dma_buf_file() check eliminates the "else" here.
Quoted 82 lines
drivers/android/binder.c +12
-3+binder_user_error ( +"%d:%d got transaction with SENDER_NO_NEED for non-dmabuf fd, %d\n" , + proc->pid, thread->pid, fd); + ret = -EINVAL ; + goto err_noneed; + } + } +/* * Add fixup record for this transaction. The allocation * of the fd in the target needs to be done from a @@ -2226,6 +2244,7 @@ static int binder_translate_fd(u32 fd, binder_size_t fd_offset,return ret; err_alloc: +err_noneed: err_security:fput (file); err_fget:@@ -2528,7 +2547,7 @@ static int binder_translate_fd_array(struct list_head *pf_head, ret =copy_from_user (&fd, sender_ufda_base + sender_uoffset,sizeof (fd));if (!ret) - ret =binder_translate_fd (fd, offset, t, thread, + ret =binder_translate_fd (fd, offset, fda->flags, t, thread, in_reply_to);if (ret)return ret >0 ? -EINVAL : ret;@@ -3179,8 +3198,8 @@ static void binder_transaction(struct binder_proc *proc,struct binder_fd_object *fp =to_binder_fd_object (hdr);binder_size_t fd_offset = object_offset + (uintptr_t )&fp->fd - (uintptr_t )fp; -int ret =binder_translate_fd (fp->fd, fd_offset, t, - thread, in_reply_to); +int ret =binder_translate_fd (fp->fd, fd_offset, fp->flags, + t, thread, in_reply_to); fp->pad_binder =0 ; if (ret < 0 ||drivers/dma-buf/dma-buf.c +2
-2@@ -31,7 +31,6 @@#include "dma-buf-sysfs-stats.h" -static inline int is_dma_buf_file (struct file *);struct dma_buf_list {struct list_head head;@@ -400,10 +399,11 @@ static const struct file_operations dma_buf_fops = {/* * is_dma_buf_file - Check if struct file* is associated with dma_buf */ -static inline int is_dma_buf_file (struct file *file) +int is_dma_buf_file (struct file *file) {return file->f_op == &dma_buf_fops; } +EXPORT_SYMBOL_NS_GPL (is_dma_buf_file,DMA_BUF );static struct file *dma_buf_getfile (struct dma_buf *dmabuf,int flags) {include/linux/dma-buf.h +1
-1@@ -614,7 +614,7 @@ dma_buf_attachment_is_dynamic(struct dma_buf_attachment *attach) {return !!attach->importer_ops; } - +int is_dma_buf_file (struct file *file);struct dma_buf_attachment *dma_buf_attach (struct dma_buf *dmabuf,struct device *dev); struct dma_buf_attachment *include/uapi/linux/android/binder.h +0
-0
include/uapi/linux/android/binder.h struct flat_binder_object { · line 94
Quoted 4 lines
include/uapi/linux/android/binder.h +0
-1@@ -91,14 +91,14 @@ struct flat_binder_object {/** * struct binder_fd_object - describes a filedescriptor to be fixed up. * @hdr: common header structure -* @pad_flags: padding to remain compatible with old userspace code
Does this mean we no longer need to keep the compatibility with the "old userspace code"? Maybe these old flags are all less than 0x2000?
Quoted 15 lines
include/uapi/linux/android/binder.h +2
-1+* @flags: One or more BINDER_FD_FLAG_* flags * @pad_binder: padding to remain compatible with old userspace code * @fd: file descriptor * @cookie: opaque data, used by user-space */ struct binder_fd_object {struct binder_object_header hdr; -__u32 pad_flags; +__u32 flags;union {binder_uintptr_t pad_binder;__u32 fd;@@ -107,6 +107,17 @@ struct binder_fd_object {binder_uintptr_t cookie; };
include/uapi/linux/android/binder.h struct binder_fd_object { · line 118
Quoted 10 lines
include/uapi/linux/android/binder.h +9
-0+enum { +/** +* @BINDER_FD_FLAG_SENDER_NO_NEED +* +* When set, the sender of a binder_fd_object wishes to relinquish ownership of the fd for +* memory accounting purposes. If the fd is for a DMA-BUF, the buffer is uncharged from the +* sender's cgroup and charged to the receiving process's cgroup instead. +*/ +BINDER_FD_FLAG_SENDER_NO_NEED =0x2000 ,
SENDER_NO_NEED wasn't straight-forward for me. Perhaps RELINQUISH or XFER_{OWNER|CHARGE|CGROUP} could be some other options to consider.
Quoted 35 lines
include/uapi/linux/android/binder.h +8
-2+}; +/* struct binder_buffer_object - object describing a userspace buffer * @hdr: common header structure * @flags: one or more BINDER_BUFFER_* flags @@ -141,7 +152,7 @@ enum {/* struct binder_fd_array_object - object describing an array of fds in a buffer * @hdr: common header structure -* @pad: padding to ensure correct alignment +* flags: One or more BINDER_FDA_FLAG_* flags * @num_fds: number of file descriptors in the buffer * @parent: index in offset array to buffer holding the fd array * @parent_offset: start offset of fd array in the buffer @@ -162,12 +173,16 @@ enum {*/ struct binder_fd_array_object {struct binder_object_header hdr; -__u32 pad; +__u32 flags;binder_size_t num_fds;binder_size_t parent;binder_size_t parent_offset; }; +enum { +BINDER_FDA_FLAG_SENDER_NO_NEED =BINDER_FD_FLAG_SENDER_NO_NEED , +}; +/* * On 64-bit platforms where user code may run in 32-bits the driver must * translate the buffer (and local binder) addresses appropriately. Signature · 1 line
2.36.0.rc0.470.gd361397f0d-goog
Other than included minor comments:
--
Carlos Llamas
T.J. Mercier
reviewerRe: [RFC v5 5/6] binder: Add flags to relinquish ownership of fds
Quoted 31 lines · Carlos Llamas
Quoted 22 lines · T.J. Mercier
From: Hridya Valsaraju <[email protected]>
This patch introduces flags
BINDER_FD_FLAG_SENDER_NO_NEED, andBINDER_FDA_FLAG_SENDER_NO_NEEDthat a process sending an individual fd or fd array to another process over binder IPC can set to relinquish ownership of the fds being sent for memory accounting purposes. If the flag is found to be set during the fd or fd array translation and the fd is for a DMA-BUF, the buffer is uncharged from the sender's cgroup and charged to the receiving process's cgroup instead.It is up to the sending process to ensure that it closes the fds regardless of whether the transfer failed or succeeded.
Most graphics shared memory allocations in Android are done by the graphics allocator HAL process. On requests from clients, the HAL process allocates memory and sends the fds to the clients over binder IPC. The graphics allocator HAL will not retain any references to the buffers. When the HAL sets
*_FLAG_SENDER_NO_NEEDfor fd arrays holding DMA-BUF fds, or individual fd objects, the gpu cgroup controller will be able to correctly charge the buffers to the client processes instead of the graphics allocator HAL.Quoted 6 lines
Since this is a new feature exposed to userspace, the kernel and userspace must be compatible for the accounting to work for transfers. In all cases the allocation and transport of DMA buffers via binder will succeed, but only when both the kernel supports, and userspace depends on this feature will the transfer accounting work. The possible scenarios are detailed below:
Quoted 7 lines
New binder driver features which require userspace coordination can be "advertised" by the kernel via binderfs. You can see an example of how
oneway_spam_detectionis exposed in commitfc470abf54b2("binderfs: add support for feature files"). This is just an option to consider if it makes things easier in userspace. Although it seems that for the second scenario (old kernel + new userpsace) the flags would just be ignored.
This is a cool idea. You're right that the flags would be ignored. Since this isn't a binder feature that can be toggled like BINDER_ENABLE_ONEWAY_SPAM_DETECTION, I think the presence of the GPU cgroup controller in the cgroup.controllers file would also tell us the same thing from userspace.
Quoted 71 lines
Quoted 71 lines
1. new kernel + old userspace
The kernel supports the feature but userspace does not use it. The old userspace won't mount the new cgroup controller, accounting is not performed, charge is not transferred.2. old kernel + new userspace
The new cgroup controller is not supported by the kernel, accounting is not performed, charge is not transferred.3. old kernel + old userspace
Same as #24. new kernel + new userspace
Cgroup is mounted, feature is supported and used.Signed-off-by Hridya Valsaraju <[email protected]>Signed-off-by T.J. Mercier <[email protected]>---
v5 changes
Support bothbinder_fd_array_objectandbinder_fd_object. This is necessary because new versions of Android will usebinder_fd_objectinstead ofbinder_fd_array_object, and we need to support both.Use the new, simpler
dma_buf_transfer_chargeAPI.v3 changes
Remove android from title per Todd Kjos.Use more common dual author commit message format per John Stultz.
Include details on behavior for all combinations of kernel/userspace versions in changelog (thanks Suren Baghdasaryan) per Greg Kroah-Hartman.
v2 changes
Move dma-buf cgroup charge transfer from adma_buf_opdefined by every heap to a single dma-buf function for all heaps per Daniel Vetter and Christian König.--- drivers/android/binder.c | 27 +++++++++++++++++++++++---- drivers/dma-buf/dma-buf.c | 4 ++-- include/linux/dma-buf.h | 2 +- include/uapi/linux/android/binder.h | 23 +++++++++++++++++++---- 4 files changed, 45 insertions(+), 11 deletions(-)drivers/android/binder.c +2
-1@@ -42,6 +42,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/dma-buf.h> #include <linux/fdtable.h> #include <linux/file.h> #include <linux/freezer.h> @@ -2170,7 +2171,7 @@ static int binder_translate_handle(struct flat_binder_object *fp,return ret; } -static int binder_translate_fd (u32 fd,binder_size_t fd_offset, +static int binder_translate_fd (u32 fd,binder_size_t fd_offset,__u32 flags,struct binder_transaction *t,struct binder_thread *thread,struct binder_transaction *in_reply_to)@@ -2208,6 +2209,23 @@ static int binder_translate_fd(u32 fd, binder_size_t fd_offset, goto err_security; }
Quoted 13 lines
drivers/android/binder.c static int binder_translate_fd(u32 fd, binder_size_t fd_offset, · line 2219
Quoted 8 lines
drivers/android/binder.c +8
-0+if (IS_ENABLED (CONFIG_CGROUP_GPU ) && (flags &BINDER_FD_FLAG_SENDER_NO_NEED )) { +if (is_dma_buf_file (file)) { +struct dma_buf *dmabuf = file->private_data; + + ret =dma_buf_transfer_charge (dmabuf, target_proc->tsk); +if (ret) +pr_warn ("%d:%d Unable to transfer DMA-BUF fd charge to %d\n" , + proc->pid, thread->pid, target_proc->pid);If we fail to transfer the charge, it seems we continue with the fixup allocation and then propagate the error. Shouldn't the translation be aborted at this point instead? Or is this supposed to be handled?
I took the position that it was better to have incorrect accounting along with this log statement than potentially causing lots of crashes due to failed transactions. However if limiting gets added for the GPU cgroup, then we really should kill the transaction here. I'll go ahead and add that goto now.
Quoted 4 lines
drivers/android/binder.c static int binder_translate_fd(u32 fd, binder_size_t fd_offset, · line 2220
Quoted 1 line
drivers/android/binder.c +1
-0+ }else {nit: negating
is_dma_buf_file()check eliminates the "else" here.
Thanks.
Quoted 81 lines
Quoted 81 lines
drivers/android/binder.c +12
-3+binder_user_error ( +"%d:%d got transaction with SENDER_NO_NEED for non-dmabuf fd, %d\n" , + proc->pid, thread->pid, fd); + ret = -EINVAL ; + goto err_noneed; + } + } +/* * Add fixup record for this transaction. The allocation * of the fd in the target needs to be done from a @@ -2226,6 +2244,7 @@ static int binder_translate_fd(u32 fd, binder_size_t fd_offset,return ret; err_alloc: +err_noneed: err_security:fput (file); err_fget:@@ -2528,7 +2547,7 @@ static int binder_translate_fd_array(struct list_head *pf_head, ret =copy_from_user (&fd, sender_ufda_base + sender_uoffset,sizeof (fd));if (!ret) - ret =binder_translate_fd (fd, offset, t, thread, + ret =binder_translate_fd (fd, offset, fda->flags, t, thread, in_reply_to);if (ret)return ret >0 ? -EINVAL : ret;@@ -3179,8 +3198,8 @@ static void binder_transaction(struct binder_proc *proc,struct binder_fd_object *fp =to_binder_fd_object (hdr);binder_size_t fd_offset = object_offset + (uintptr_t )&fp->fd - (uintptr_t )fp; -int ret =binder_translate_fd (fp->fd, fd_offset, t, - thread, in_reply_to); +int ret =binder_translate_fd (fp->fd, fd_offset, fp->flags, + t, thread, in_reply_to); fp->pad_binder =0 ; if (ret < 0 ||drivers/dma-buf/dma-buf.c +2
-2@@ -31,7 +31,6 @@#include "dma-buf-sysfs-stats.h" -static inline int is_dma_buf_file (struct file *);struct dma_buf_list {struct list_head head;@@ -400,10 +399,11 @@ static const struct file_operations dma_buf_fops = {/* * is_dma_buf_file - Check if struct file* is associated with dma_buf */ -static inline int is_dma_buf_file (struct file *file) +int is_dma_buf_file (struct file *file) {return file->f_op == &dma_buf_fops; } +EXPORT_SYMBOL_NS_GPL (is_dma_buf_file,DMA_BUF );static struct file *dma_buf_getfile (struct dma_buf *dmabuf,int flags) {include/linux/dma-buf.h +1
-1@@ -614,7 +614,7 @@ dma_buf_attachment_is_dynamic(struct dma_buf_attachment *attach) {return !!attach->importer_ops; } - +int is_dma_buf_file (struct file *file);struct dma_buf_attachment *dma_buf_attach (struct dma_buf *dmabuf,struct device *dev); struct dma_buf_attachment *include/uapi/linux/android/binder.h +0
-0
Quoted 9 lines
include/uapi/linux/android/binder.h struct flat_binder_object { · line 94
Quoted 5 lines
include/uapi/linux/android/binder.h +0
-1@@ -91,14 +91,14 @@ struct flat_binder_object {/** * struct binder_fd_object - describes a filedescriptor to be fixed up. * @hdr: common header structure -* @pad_flags: padding to remain compatible with old userspace code Does this mean we no longer need to keep the compatibility with the "old userspace code"? Maybe these old flags are all less than
0x2000?
This comes from before binder_fd{_array}_object existed as a distinct type from flat_binder_object. With this layout, it's possible to cast between flat_binder_object and the binder_fd{_array}_object types. I don't think there were ever any binder_fd{_array}_object specific flags before now, but yes the value of 0x2000 was chosen to be sure that the FLAT_BINDER_* flags do not conflict. I did try smaller values (0x02) but found that occasionally this bit was set when I was not expecting it to be.
https://lore.kernel.org/lkml/[email protected]/
Quoted 16 lines
Quoted 16 lines
include/uapi/linux/android/binder.h +2
-1+* @flags: One or more BINDER_FD_FLAG_* flags * @pad_binder: padding to remain compatible with old userspace code * @fd: file descriptor * @cookie: opaque data, used by user-space */ struct binder_fd_object {struct binder_object_header hdr; -__u32 pad_flags; +__u32 flags;union {binder_uintptr_t pad_binder;__u32 fd;@@ -107,6 +107,17 @@ struct binder_fd_object {binder_uintptr_t cookie; };
Quoted 13 lines
include/uapi/linux/android/binder.h struct binder_fd_object { · line 118
Quoted 9 lines
include/uapi/linux/android/binder.h +9
-0+enum { +/** +* @BINDER_FD_FLAG_SENDER_NO_NEED +* +* When set, the sender of a binder_fd_object wishes to relinquish ownership of the fd for +* memory accounting purposes. If the fd is for a DMA-BUF, the buffer is uncharged from the +* sender's cgroup and charged to the receiving process's cgroup instead. +*/ +BINDER_FD_FLAG_SENDER_NO_NEED =0x2000 ,
SENDER_NO_NEEDwasn't straight-forward for me. Perhaps RELINQUISH or XFER_{OWNER|CHARGE|CGROUP} could be some other options to consider.
I'm happy to change this up. I like _XFER_CHARGE the best out of these.
Quoted 42 lines
Quoted 33 lines
include/uapi/linux/android/binder.h +8
-3+}; +/* struct binder_buffer_object - object describing a userspace buffer * @hdr: common header structure * @flags: one or more BINDER_BUFFER_* flags @@ -141,7 +152,7 @@ enum {/* struct binder_fd_array_object - object describing an array of fds in a buffer * @hdr: common header structure -* @pad: padding to ensure correct alignment +* flags: One or more BINDER_FDA_FLAG_* flags * @num_fds: number of file descriptors in the buffer * @parent: index in offset array to buffer holding the fd array * @parent_offset: start offset of fd array in the buffer @@ -162,12 +173,16 @@ enum {*/ struct binder_fd_array_object {struct binder_object_header hdr; -__u32 pad; +__u32 flags;binder_size_t num_fds;binder_size_t parent;binder_size_t parent_offset; }; +enum { +BINDER_FDA_FLAG_SENDER_NO_NEED =BINDER_FD_FLAG_SENDER_NO_NEED , +}; +/* * On 64-bit platforms where user code may run in 32-bits the driver must * translate the buffer (and local binder) addresses appropriately. -- Quoted 2 lines
2.36.0.rc0.470.gd361397f0d-goog
Other than included minor comments:
Reviewed-by Carlos Llamas <[email protected]>--
Carlos Llamas
T.J. Mercier
reviewerRFC v5 6/6 selftests: Add binder cgroup gpu memory transfer tests
In reply to T.J. MercierThese tests verify that the cgroup GPU memory charge is transferred correctly when a dmabuf is passed between processes in two different cgroups and the sender specifies BINDER_FD_FLAG_SENDER_NO_NEED or BINDER_FDA_FLAG_SENDER_NO_NEED in the binder transaction data containing the dmabuf file descriptor.
---
v5 changes
Tests for both binder_fd_array_object and binder_fd_object.
Return error code instead of struct binder{fs}_ctx.
Use ifdef __ANDROID__ to choose platform-dependent temp path instead of a runtime fallback.
Ensure binderfs_mntpt ends with a trailing '/' character instead of prepending it where used.
v4 changes
Skip test if not run as root per Shuah Khan.
Add better logging for abnormal child termination per Shuah Khan.
--- .../selftests/drivers/android/binder/Makefile | 8 + .../drivers/android/binder/binder_util.c | 250 +++++++++ .../drivers/android/binder/binder_util.h | 32 ++ .../selftests/drivers/android/binder/config | 4 + .../binder/test_dmabuf_cgroup_transfer.c | 526 ++++++++++++++++++ 5 files changed, 820 insertions(+) create mode 100644 tools/testing/selftests/drivers/android/binder/Makefile create mode 100644 tools/testing/selftests/drivers/android/binder/binder_util.c create mode 100644 tools/testing/selftests/drivers/android/binder/binder_util.h create mode 100644 tools/testing/selftests/drivers/android/binder/config create mode 100644 tools/testing/selftests/drivers/android/binder/test_dmabuf_cgroup_transfer.c
tools/testing/selftests/drivers/android/binder/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +CFLAGS += -Wall + +TEST_GEN_PROGS = test_dmabuf_cgroup_transfer + +include ../../../lib.mk + +$(OUTPUT)/test_dmabuf_cgroup_transfer: ../../../cgroup/cgroup_util.c binder_util.c
tools/testing/selftests/drivers/android/binder/binder_util.c new file +250 -0
250 lines not on this page · raw message
tools/testing/selftests/drivers/android/binder/binder_util.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef SELFTEST_BINDER_UTIL_H +#define SELFTEST_BINDER_UTIL_H + +#include <stdint.h> + +#include <linux/android/binder.h> + +struct binderfs_ctx { +char *name; +char *mountpoint; +}; + +struct binder_ctx { +int fd; +void *memory; +}; + +int create_binderfs (struct binderfs_ctx *ctx,const char *name); +void destroy_binderfs (struct binderfs_ctx *ctx); + +int open_binder (const struct binderfs_ctx *bfs_ctx,struct binder_ctx *ctx); +void close_binder (struct binder_ctx *ctx); + +int become_binder_context_manager (int binder_fd); + +int do_binder_write_read (int binder_fd,void *writebuf,binder_size_t writesize, +void *readbuf,binder_size_t readsize); + +int expect_binder_reply (int32_t actual,int32_t expected); +#endif
tools/testing/selftests/drivers/android/binder/config new file +4 -0
@@ -0,0 +1,4 @@ +CONFIG_CGROUP_GPU=y +CONFIG_ANDROID=y +CONFIG_ANDROID_BINDERFS=y +CONFIG_ANDROID_BINDER_IPC=y
tools/testing/selftests/drivers/android/binder/test_dmabuf_cgroup_transfer.c new file +526 -0
526 lines not on this page · raw message
Signature · 1 line
2.36.0.rc0.470.gd361397f0d-goog
Greg Kroah-Hartman
maintainerQuoted 10 lines · T.J. Mercier
This patch series revisits the proposal for a GPU cgroup controller to track and limit memory allocations by various device/allocator subsystems. The patch series also contains a simple prototype to illustrate how Android intends to implement DMA-BUF allocator attribution using the GPU cgroup controller. The prototype does not include resource limit enforcements.
Changelog:
v5:
Rebase on top of v5.18-rc3
Why is a "RFC" series on v5? I treat "RFC" as "not ready to be merged, if people are interested, please look at it". But v5 seems like you think this is real.
confused,
greg k-h
T.J. Mercier
reviewerQuoted 13 lines · Greg Kroah-Hartman
Quoted 10 lines · T.J. Mercier
This patch series revisits the proposal for a GPU cgroup controller to track and limit memory allocations by various device/allocator subsystems. The patch series also contains a simple prototype to illustrate how Android intends to implement DMA-BUF allocator attribution using the GPU cgroup controller. The prototype does not include resource limit enforcements.
Changelog:
v5:
Rebase on top of v5.18-rc3
Quoted 7 lines
Why is a "RFC" series on v5? I treat "RFC" as "not ready to be merged, if people are interested, please look at it". But v5 seems like you think this is real.
confused,
greg k-h
I'm sorry for the confusion. I'll change this to PATCH in future revisions.