From: sashiko-bot@kernel.org
To: "Albert Esteve" <aesteve@redhat.com>, "Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Michal Hocko" <mhocko@kernel.org>,
"Roman Gushchin" <roman.gushchin@linux.dev>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Muchun Song" <muchun.song@linux.dev>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Benjamin Gaignard" <benjamin.gaignard@collabora.com>,
"Brian Starkey" <Brian.Starkey@arm.com>,
"John Stultz" <jstultz@google.com>,
"T.J. Mercier" <tjmercier@google.com>,
"Christian Brauner" <brauner@kernel.org>,
"Paul Moore" <paul@paul-moore.com>,
"James Morris" <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
"Stephen Smalley" <stephen.smalley.work@gmail.com>,
"Shuah Khan" <shuah@kernel.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Ondrej Mosnáček" <omosnacek@gmail.com>,
"Jens Wiklander" <jenswi@kernel.org>,
"Sumit Garg" <sumit.garg@kernel.org>,
"Philipp Stanner" <phasta@kernel.org>
Cc: airlied@gmail.com, dri-devel@lists.freedesktop.org,
linux-mm@kvack.org, linux-security-module@vger.kernel.org,
selinux@vger.kernel.org, op-tee@lists.trustedfirmware.org,
echanude@redhat.com, mripard@kernel.org, media-ci@linuxtv.org
Subject: Re: [PATCH v6 7/7] selftests/dmabuf-heaps: Add dma-buf memcg accounting tests
Date: Wed, 25 Nov 2026 13:05:26 +0000 [thread overview]
Message-ID: <sashiko-outbox-233449@kernel.org> (raw)
In-Reply-To: <20261124-v2_20230123_tjmercier_google_com-v6-7-dce12fa03ad6@redhat.com>
Thank you for your contribution! Sashiko AI review found 9 potential
issues to consider:
- [Medium] selftests/cgroup: test_memcg_dmabuf_xfer_at_limit() misses
skip checks
- [Medium] selftests/cgroup: dmabuf tests read memory.stat below rstat
flush threshold
- [Medium] selftests/dmabuf-heaps: pidfd_alloc_supported() mishandles
disabled memcg
- [Medium] selftests/dmabuf-heaps: open_self_cgroupfd() misses memory
controller check
- [Medium] selftests/dmabuf-heaps: check_deps() runs before
handle_build() in vmtest.sh
- [Low] selftests/cgroup: child_cg leak on cg_create() error in
test_memcg_dmabuf()
- [Low] selftests/cgroup: unused MEMCG_SOCKSTAT_WAIT_RETRIES macro in
test_memcontrol
- [Low] selftests/dmabuf-heaps: make_runner() omits
test_memcg_dmabuf_dead_cgroup
- [Low] selftests/dmabuf-heaps: vmtest.sh creates TMP_DIR before setting
EXIT trap
--
commit 65b17f139f560196804a32a9dffe9eb0a344be15
Author: Albert Esteve <aesteve@redhat.com>
selftests/dmabuf-heaps: Add dma-buf memcg accounting tests
This commit adds selftests for dma-buf memcg accounting via charge_fd and
DMA_BUF_IOCTL_XFER_CHARGE in dmabuf-heaps and cgroup/test_memcontrol, along
with a virtme-ng test runner script and config fragment.
> diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c
> index bb673012dcf08..f612726bd9af7 100644
> --- a/tools/testing/selftests/cgroup/test_memcontrol.c
> +++ b/tools/testing/selftests/cgroup/test_memcontrol.c
> @@ -27,6 +34,13 @@
> #define MEMCG_FLUSH_BYTES \
> (2 * sysconf(_SC_PAGESIZE) * MEMCG_CHARGE_BATCH * get_nprocs())
>
> +#define DMA_HEAP_SYSTEM "/dev/dma_heap/system"
> +#define ONE_MEG (1024 * 1024)
> +
> +#define MEMCG_SOCKSTAT_WAIT_RETRIES 30
[Severity: Low]
MEMCG_SOCKSTAT_WAIT_RETRIES was removed by eb69e955de7b ("selftests:
cgroup: make test_memcg_sock check flushed sock stats") and has no users.
Was it re-added here by mistake during a rebase?
> +#define MEMCG_DMABUF_WAIT_RETRIES 30
> +#define MEMCG_DMABUF_DEAD_WAIT_RETRIES 80
> +
> static bool has_localevents;
> static bool has_recursiveprot;
> static int page_size;
> @@ -1797,6 +1811,417 @@ static int test_memcg_inotify_delete_dir(const char *root)
> return ret;
> }
>
[ ... ]
> +static int test_memcg_dmabuf(const char *root)
> +{
> + char *parent = NULL, *child_cg = NULL;
> + int ret = KSFT_FAIL;
[ ... ]
> + child_cg = cg_name(parent, "child");
> + if (!child_cg)
> + goto cleanup_parent;
> +
> + if (cg_create(child_cg))
> + goto cleanup_parent;
[Severity: Low]
Does this leak child_cg when cg_create(child_cg) fails? Jumping to
cleanup_parent skips free(child_cg) in cleanup_child.
[ ... ]
> + dmabuf_stat = cg_read_key_long(child_cg, "memory.stat", "dmabuf ");
> + if (dmabuf_stat == -1) {
> + ret = KSFT_SKIP;
> + goto cleanup_dmabuf;
> + }
> + if (dmabuf_stat != ONE_MEG)
> + dmabuf_stat = cg_read_key_long_poll(child_cg, "memory.stat",
> + "dmabuf ", ONE_MEG,
> + MEMCG_DMABUF_WAIT_RETRIES,
> + DEFAULT_WAIT_INTERVAL_US);
[Severity: Medium]
Can polling memory.stat for ONE_MEG miss the rstat flush threshold in
test_memcg_dmabuf(), test_memcg_dmabuf_xfer_at_limit(), and
test_memcg_dmabuf_dead_cgroup()?
Reading memory.stat only flushes rstat synchronously when pending updates
exceed MEMCG_CHARGE_BATCH * num_online_cpus() pages. On systems with 4 or
more CPUs (or 64 KB pages), a 1 MB charge or uncharge is below that
threshold, so cg_read_key_long_poll() relies on the periodic 2s deferrable
stats_flush_dwork running within the 3s poll window (the same issue fixed
for test_memcg_sock by eb69e955de7b ("selftests: cgroup: make
test_memcg_sock check flushed sock stats") using MEMCG_FLUSH_BYTES).
In addition, when test_memcg_dmabuf_xfer_at_limit() polls cg_a for ONE_MEG
after DMA_BUF_IOCTL_XFER_CHARGE fails with ENOMEM, cg_read_key_long_poll()
immediately matches the pre-existing cached ONE_MEG value on its first read
without flushing rstat after the ioctl.
[ ... ]
> +static int test_memcg_dmabuf_xfer_at_limit(const char *root)
> +{
[ ... ]
> + if (ioctl(heap_fd, DMA_HEAP_IOCTL_ALLOC, &alloc) < 0) {
> + close(alloc.charge_fd);
> + goto cleanup_heap;
> + }
> + close(alloc.charge_fd);
> + dmabuf_fd = (int)alloc.fd;
[ ... ]
> + xfer.charge_fd = (__u32)cg_b_fd;
> + if (ioctl(dmabuf_fd, DMA_BUF_IOCTL_XFER_CHARGE, &xfer) == 0) {
> + fprintf(stderr, "xfer_charge should have failed at limit\n");
> + goto cleanup_cgfd;
> + }
> + if (errno != ENOMEM) {
> + fprintf(stderr, "Expected ENOMEM, got %s\n", strerror(errno));
> + goto cleanup_cgfd;
> + }
[Severity: Medium]
Should test_memcg_dmabuf_xfer_at_limit() set ret = KSFT_SKIP when
DMA_HEAP_IOCTL_ALLOC or DMA_BUF_IOCTL_XFER_CHARGE fails with EINVAL,
ENOTTY, or EOPNOTSUPP?
Unlike test_memcg_dmabuf() and test_memcg_dmabuf_dead_cgroup(), neither
ioctl failure path sets ret = KSFT_SKIP, so this test fails instead of
skipping on unpatched kernels or when dma_heap.mem_accounting=0.
> diff --git a/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c
> index 1d49df6719198..44e3f33acf877 100644
> --- a/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c
> +++ b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c
[ ... ]
> +static bool pidfd_alloc_supported(int heap_fd)
> +{
> + int devnull_fd, dmabuf_fd = -1, ret;
> +
> + devnull_fd = open("/dev/null", O_RDONLY);
> + if (devnull_fd < 0)
> + return false;
> +
> + ret = dmabuf_heap_alloc_pidfd(heap_fd, ONE_MEG, 0, devnull_fd, &dmabuf_fd);
> + if (dmabuf_fd >= 0) {
> + close(dmabuf_fd);
> + dmabuf_fd = -1;
> + }
> + close(devnull_fd);
> + return ret < 0;
> +}
[Severity: Medium]
Does pidfd_alloc_supported() return true when memory cgroups are disabled?
When CONFIG_MEMCG=n or cgroup_disable=memory is passed at boot,
get_obj_cgroup_from_fd() returns ERR_PTR(-EOPNOTSUPP) before inspecting the
fd. Because ret < 0 is true, pidfd_alloc_supported() reports charge_fd as
supported (whereas active memcg rejects /dev/null with EBADF), and
test_alloc_pidfd_self(), test_alloc_pidfd_child(), and
test_alloc_cgroupfd_self() then fail with EOPNOTSUPP instead of skipping.
[ ... ]
> +static int open_self_cgroupfd(void)
> +{
> + char cgroup_path[PATH_MAX];
> + char line[PATH_MAX];
> + int ret = -1;
> + FILE *f;
> +
> + f = fopen("/proc/self/cgroup", "r");
> + if (!f)
> + return -1;
> + while (fgets(line, sizeof(line), f)) {
> + if (strncmp(line, "0::", 3))
> + continue;
> + line[strcspn(line, "\n")] = '\0';
> + if (snprintf(cgroup_path, sizeof(cgroup_path),
> + "/sys/fs/cgroup%s", line + 3) < PATH_MAX)
> + ret = 0;
> + break;
> + }
> + fclose(f);
> +
> + if (ret)
> + return -1;
> +
> + return open(cgroup_path, O_RDONLY | O_DIRECTORY);
> +}
[Severity: Medium]
What happens in test_alloc_cgroupfd_self() and
test_xfer_charge_cgroupfd_self() if the calling process runs in a cgroup
where the memory controller is not enabled?
Unlike the pidfd path in get_obj_cgroup_from_fd(), which resolves the
effective ancestor CSS via task_css(), the cgroup directory fd path calls
css_tryget_online_from_dir() directly on that directory and fails with
ENOENT when +memory is not enabled in its parent's cgroup.subtree_control,
causing both tests to fail instead of skipping.
> diff --git a/tools/testing/selftests/dmabuf-heaps/vmtest.sh b/tools/testing/selftests/dmabuf-heaps/vmtest.sh
> new file mode 100755
> index 0000000000000..3574b71ca83e8
> --- /dev/null
> +++ b/tools/testing/selftests/dmabuf-heaps/vmtest.sh
> @@ -0,0 +1,226 @@
[ ... ]
> +readonly DMABUF_HEAP_TEST="${SCRIPT_DIR}"/dmabuf-heap
> +readonly MEMCONTROL_TEST="${CGROUP_DIR}"/test_memcontrol
> +readonly TMP_DIR=$(mktemp -d /tmp/dmabuf-vmtest.XXXXXXXX)
[Severity: Low]
Does creating TMP_DIR before getopts leak /tmp/dmabuf-vmtest.XXXXXXXX when
usage() exits on -h or an invalid option before trap cleanup EXIT is
installed?
[ ... ]
> +check_deps() {
> + for dep in vng make; do
> + if [[ ! -x $(command -v "${dep}") ]]; then
> + echo -e "skip: dependency ${dep} not found!\n"
> + exit "${KSFT_SKIP}"
> + fi
> + done
> +
> + if ${SHELL_MODE}; then
> + return
> + fi
> +
> + if [[ ! -x "${DMABUF_HEAP_TEST}" ]]; then
> + printf "skip: %s not found!" "${DMABUF_HEAP_TEST}"
> + printf " Please build the kselftest dmabuf-heaps target (or use -b).\n"
> + exit "${KSFT_SKIP}"
> + fi
> +
> + if [[ ! -x "${MEMCONTROL_TEST}" ]]; then
> + printf "skip: %s not found!" "${MEMCONTROL_TEST}"
> + printf " Please build the kselftest cgroup target (or use -b).\n"
> + exit "${KSFT_SKIP}"
> + fi
> +}
[Severity: Medium]
Does check_deps() exit with KSFT_SKIP when vmtest.sh -b is run on an
unbuilt tree?
check_deps() runs before handle_build() compiles DMABUF_HEAP_TEST and
MEMCONTROL_TEST, and it only returns early for SHELL_MODE, not BUILD.
[ ... ]
> + run "dmabuf-heap charge_fd ioctl" ${DMABUF_HEAP_TEST}
> + run "memcontrol dma-buf memcg" ${MEMCONTROL_TEST} test_memcg_dmabuf
> + run "memcontrol dma-buf xfer limit" \
> + ${MEMCONTROL_TEST} test_memcg_dmabuf_xfer_at_limit
[Severity: Low]
Should make_runner() also run test_memcg_dmabuf_dead_cgroup here?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-v2_20230123_tjmercier_google_com-v6-0-dce12fa03ad6@redhat.com?part=7
WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot--- via OP-TEE <op-tee@lists.trustedfirmware.org>
To: "Albert Esteve" <aesteve@redhat.com>, "Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Michal Hocko" <mhocko@kernel.org>,
"Roman Gushchin" <roman.gushchin@linux.dev>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Muchun Song" <muchun.song@linux.dev>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Benjamin Gaignard" <benjamin.gaignard@collabora.com>,
"Brian Starkey" <Brian.Starkey@arm.com>,
"John Stultz" <jstultz@google.com>,
"T.J. Mercier" <tjmercier@google.com>,
"Christian Brauner" <brauner@kernel.org>,
"Paul Moore" <paul@paul-moore.com>,
"James Morris" <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
"Stephen Smalley" <stephen.smalley.work@gmail.com>,
"Shuah Khan" <shuah@kernel.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Ondrej Mosnáček" <omosnacek@gmail.com>,
"Jens Wiklander" <jenswi@kernel.org>,
"Sumit Garg" <sumit.garg@kernel.org>,
"Philipp Stanner" <phasta@kernel.org>
Cc: airlied@gmail.com, dri-devel@lists.freedesktop.org,
linux-mm@kvack.org, linux-security-module@vger.kernel.org,
selinux@vger.kernel.org, op-tee@lists.trustedfirmware.org,
echanude@redhat.com, mripard@kernel.org, media-ci@linuxtv.org
Subject: Re: [PATCH v6 7/7] selftests/dmabuf-heaps: Add dma-buf memcg accounting tests
Date: Wed, 25 Nov 2026 13:05:26 +0000 [thread overview]
Message-ID: <sashiko-outbox-233449@kernel.org> (raw)
In-Reply-To: <20261124-v2_20230123_tjmercier_google_com-v6-7-dce12fa03ad6@redhat.com>
Thank you for your contribution! Sashiko AI review found 9 potential
issues to consider:
- [Medium] selftests/cgroup: test_memcg_dmabuf_xfer_at_limit() misses
skip checks
- [Medium] selftests/cgroup: dmabuf tests read memory.stat below rstat
flush threshold
- [Medium] selftests/dmabuf-heaps: pidfd_alloc_supported() mishandles
disabled memcg
- [Medium] selftests/dmabuf-heaps: open_self_cgroupfd() misses memory
controller check
- [Medium] selftests/dmabuf-heaps: check_deps() runs before
handle_build() in vmtest.sh
- [Low] selftests/cgroup: child_cg leak on cg_create() error in
test_memcg_dmabuf()
- [Low] selftests/cgroup: unused MEMCG_SOCKSTAT_WAIT_RETRIES macro in
test_memcontrol
- [Low] selftests/dmabuf-heaps: make_runner() omits
test_memcg_dmabuf_dead_cgroup
- [Low] selftests/dmabuf-heaps: vmtest.sh creates TMP_DIR before setting
EXIT trap
--
commit 65b17f139f560196804a32a9dffe9eb0a344be15
Author: Albert Esteve <aesteve@redhat.com>
selftests/dmabuf-heaps: Add dma-buf memcg accounting tests
This commit adds selftests for dma-buf memcg accounting via charge_fd and
DMA_BUF_IOCTL_XFER_CHARGE in dmabuf-heaps and cgroup/test_memcontrol, along
with a virtme-ng test runner script and config fragment.
> diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c
> index bb673012dcf08..f612726bd9af7 100644
> --- a/tools/testing/selftests/cgroup/test_memcontrol.c
> +++ b/tools/testing/selftests/cgroup/test_memcontrol.c
> @@ -27,6 +34,13 @@
> #define MEMCG_FLUSH_BYTES \
> (2 * sysconf(_SC_PAGESIZE) * MEMCG_CHARGE_BATCH * get_nprocs())
>
> +#define DMA_HEAP_SYSTEM "/dev/dma_heap/system"
> +#define ONE_MEG (1024 * 1024)
> +
> +#define MEMCG_SOCKSTAT_WAIT_RETRIES 30
[Severity: Low]
MEMCG_SOCKSTAT_WAIT_RETRIES was removed by eb69e955de7b ("selftests:
cgroup: make test_memcg_sock check flushed sock stats") and has no users.
Was it re-added here by mistake during a rebase?
> +#define MEMCG_DMABUF_WAIT_RETRIES 30
> +#define MEMCG_DMABUF_DEAD_WAIT_RETRIES 80
> +
> static bool has_localevents;
> static bool has_recursiveprot;
> static int page_size;
> @@ -1797,6 +1811,417 @@ static int test_memcg_inotify_delete_dir(const char *root)
> return ret;
> }
>
[ ... ]
> +static int test_memcg_dmabuf(const char *root)
> +{
> + char *parent = NULL, *child_cg = NULL;
> + int ret = KSFT_FAIL;
[ ... ]
> + child_cg = cg_name(parent, "child");
> + if (!child_cg)
> + goto cleanup_parent;
> +
> + if (cg_create(child_cg))
> + goto cleanup_parent;
[Severity: Low]
Does this leak child_cg when cg_create(child_cg) fails? Jumping to
cleanup_parent skips free(child_cg) in cleanup_child.
[ ... ]
> + dmabuf_stat = cg_read_key_long(child_cg, "memory.stat", "dmabuf ");
> + if (dmabuf_stat == -1) {
> + ret = KSFT_SKIP;
> + goto cleanup_dmabuf;
> + }
> + if (dmabuf_stat != ONE_MEG)
> + dmabuf_stat = cg_read_key_long_poll(child_cg, "memory.stat",
> + "dmabuf ", ONE_MEG,
> + MEMCG_DMABUF_WAIT_RETRIES,
> + DEFAULT_WAIT_INTERVAL_US);
[Severity: Medium]
Can polling memory.stat for ONE_MEG miss the rstat flush threshold in
test_memcg_dmabuf(), test_memcg_dmabuf_xfer_at_limit(), and
test_memcg_dmabuf_dead_cgroup()?
Reading memory.stat only flushes rstat synchronously when pending updates
exceed MEMCG_CHARGE_BATCH * num_online_cpus() pages. On systems with 4 or
more CPUs (or 64 KB pages), a 1 MB charge or uncharge is below that
threshold, so cg_read_key_long_poll() relies on the periodic 2s deferrable
stats_flush_dwork running within the 3s poll window (the same issue fixed
for test_memcg_sock by eb69e955de7b ("selftests: cgroup: make
test_memcg_sock check flushed sock stats") using MEMCG_FLUSH_BYTES).
In addition, when test_memcg_dmabuf_xfer_at_limit() polls cg_a for ONE_MEG
after DMA_BUF_IOCTL_XFER_CHARGE fails with ENOMEM, cg_read_key_long_poll()
immediately matches the pre-existing cached ONE_MEG value on its first read
without flushing rstat after the ioctl.
[ ... ]
> +static int test_memcg_dmabuf_xfer_at_limit(const char *root)
> +{
[ ... ]
> + if (ioctl(heap_fd, DMA_HEAP_IOCTL_ALLOC, &alloc) < 0) {
> + close(alloc.charge_fd);
> + goto cleanup_heap;
> + }
> + close(alloc.charge_fd);
> + dmabuf_fd = (int)alloc.fd;
[ ... ]
> + xfer.charge_fd = (__u32)cg_b_fd;
> + if (ioctl(dmabuf_fd, DMA_BUF_IOCTL_XFER_CHARGE, &xfer) == 0) {
> + fprintf(stderr, "xfer_charge should have failed at limit\n");
> + goto cleanup_cgfd;
> + }
> + if (errno != ENOMEM) {
> + fprintf(stderr, "Expected ENOMEM, got %s\n", strerror(errno));
> + goto cleanup_cgfd;
> + }
[Severity: Medium]
Should test_memcg_dmabuf_xfer_at_limit() set ret = KSFT_SKIP when
DMA_HEAP_IOCTL_ALLOC or DMA_BUF_IOCTL_XFER_CHARGE fails with EINVAL,
ENOTTY, or EOPNOTSUPP?
Unlike test_memcg_dmabuf() and test_memcg_dmabuf_dead_cgroup(), neither
ioctl failure path sets ret = KSFT_SKIP, so this test fails instead of
skipping on unpatched kernels or when dma_heap.mem_accounting=0.
> diff --git a/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c
> index 1d49df6719198..44e3f33acf877 100644
> --- a/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c
> +++ b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c
[ ... ]
> +static bool pidfd_alloc_supported(int heap_fd)
> +{
> + int devnull_fd, dmabuf_fd = -1, ret;
> +
> + devnull_fd = open("/dev/null", O_RDONLY);
> + if (devnull_fd < 0)
> + return false;
> +
> + ret = dmabuf_heap_alloc_pidfd(heap_fd, ONE_MEG, 0, devnull_fd, &dmabuf_fd);
> + if (dmabuf_fd >= 0) {
> + close(dmabuf_fd);
> + dmabuf_fd = -1;
> + }
> + close(devnull_fd);
> + return ret < 0;
> +}
[Severity: Medium]
Does pidfd_alloc_supported() return true when memory cgroups are disabled?
When CONFIG_MEMCG=n or cgroup_disable=memory is passed at boot,
get_obj_cgroup_from_fd() returns ERR_PTR(-EOPNOTSUPP) before inspecting the
fd. Because ret < 0 is true, pidfd_alloc_supported() reports charge_fd as
supported (whereas active memcg rejects /dev/null with EBADF), and
test_alloc_pidfd_self(), test_alloc_pidfd_child(), and
test_alloc_cgroupfd_self() then fail with EOPNOTSUPP instead of skipping.
[ ... ]
> +static int open_self_cgroupfd(void)
> +{
> + char cgroup_path[PATH_MAX];
> + char line[PATH_MAX];
> + int ret = -1;
> + FILE *f;
> +
> + f = fopen("/proc/self/cgroup", "r");
> + if (!f)
> + return -1;
> + while (fgets(line, sizeof(line), f)) {
> + if (strncmp(line, "0::", 3))
> + continue;
> + line[strcspn(line, "\n")] = '\0';
> + if (snprintf(cgroup_path, sizeof(cgroup_path),
> + "/sys/fs/cgroup%s", line + 3) < PATH_MAX)
> + ret = 0;
> + break;
> + }
> + fclose(f);
> +
> + if (ret)
> + return -1;
> +
> + return open(cgroup_path, O_RDONLY | O_DIRECTORY);
> +}
[Severity: Medium]
What happens in test_alloc_cgroupfd_self() and
test_xfer_charge_cgroupfd_self() if the calling process runs in a cgroup
where the memory controller is not enabled?
Unlike the pidfd path in get_obj_cgroup_from_fd(), which resolves the
effective ancestor CSS via task_css(), the cgroup directory fd path calls
css_tryget_online_from_dir() directly on that directory and fails with
ENOENT when +memory is not enabled in its parent's cgroup.subtree_control,
causing both tests to fail instead of skipping.
> diff --git a/tools/testing/selftests/dmabuf-heaps/vmtest.sh b/tools/testing/selftests/dmabuf-heaps/vmtest.sh
> new file mode 100755
> index 0000000000000..3574b71ca83e8
> --- /dev/null
> +++ b/tools/testing/selftests/dmabuf-heaps/vmtest.sh
> @@ -0,0 +1,226 @@
[ ... ]
> +readonly DMABUF_HEAP_TEST="${SCRIPT_DIR}"/dmabuf-heap
> +readonly MEMCONTROL_TEST="${CGROUP_DIR}"/test_memcontrol
> +readonly TMP_DIR=$(mktemp -d /tmp/dmabuf-vmtest.XXXXXXXX)
[Severity: Low]
Does creating TMP_DIR before getopts leak /tmp/dmabuf-vmtest.XXXXXXXX when
usage() exits on -h or an invalid option before trap cleanup EXIT is
installed?
[ ... ]
> +check_deps() {
> + for dep in vng make; do
> + if [[ ! -x $(command -v "${dep}") ]]; then
> + echo -e "skip: dependency ${dep} not found!\n"
> + exit "${KSFT_SKIP}"
> + fi
> + done
> +
> + if ${SHELL_MODE}; then
> + return
> + fi
> +
> + if [[ ! -x "${DMABUF_HEAP_TEST}" ]]; then
> + printf "skip: %s not found!" "${DMABUF_HEAP_TEST}"
> + printf " Please build the kselftest dmabuf-heaps target (or use -b).\n"
> + exit "${KSFT_SKIP}"
> + fi
> +
> + if [[ ! -x "${MEMCONTROL_TEST}" ]]; then
> + printf "skip: %s not found!" "${MEMCONTROL_TEST}"
> + printf " Please build the kselftest cgroup target (or use -b).\n"
> + exit "${KSFT_SKIP}"
> + fi
> +}
[Severity: Medium]
Does check_deps() exit with KSFT_SKIP when vmtest.sh -b is run on an
unbuilt tree?
check_deps() runs before handle_build() compiles DMABUF_HEAP_TEST and
MEMCONTROL_TEST, and it only returns early for SHELL_MODE, not BUILD.
[ ... ]
> + run "dmabuf-heap charge_fd ioctl" ${DMABUF_HEAP_TEST}
> + run "memcontrol dma-buf memcg" ${MEMCONTROL_TEST} test_memcg_dmabuf
> + run "memcontrol dma-buf xfer limit" \
> + ${MEMCONTROL_TEST} test_memcg_dmabuf_xfer_at_limit
[Severity: Low]
Should make_runner() also run test_memcg_dmabuf_dead_cgroup here?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-v2_20230123_tjmercier_google_com-v6-0-dce12fa03ad6@redhat.com?part=7
next prev parent reply other threads:[~2026-11-25 13:05 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 13:03 [PATCH v6 0/7] memcg: dma-buf cgroup accounting and charge transfer Albert Esteve
2026-11-24 13:03 ` Albert Esteve via OP-TEE
2026-11-24 13:03 ` [PATCH v6 1/7] memcg: Add MEMCG_DMABUF accounting infrastructure Albert Esteve
2026-11-24 13:03 ` Albert Esteve via OP-TEE
2026-11-24 13:03 ` [PATCH v6 2/7] dma-heap: charge dma-buf memory via explicit memcg Albert Esteve
2026-11-24 13:03 ` Albert Esteve via OP-TEE
2026-11-25 13:05 ` sashiko-bot
2026-11-25 13:05 ` sashiko-bot--- via OP-TEE
2026-11-25 16:13 ` Albert Esteve
2026-11-25 16:13 ` Albert Esteve via OP-TEE
2026-11-24 13:03 ` [PATCH v6 3/7] dma-buf: transfer objcg charges via DMA_BUF_IOCTL_XFER_CHARGE Albert Esteve
2026-11-24 13:03 ` Albert Esteve via OP-TEE
2026-11-24 13:03 ` [PATCH v6 4/7] lsm: Add memcg_charge_task LSM hook Albert Esteve
2026-11-24 13:03 ` Albert Esteve via OP-TEE
2026-11-24 13:03 ` [PATCH v6 5/7] lsm: Add memcg_charge_cgroup " Albert Esteve
2026-11-24 13:03 ` Albert Esteve via OP-TEE
2026-11-24 13:03 ` [PATCH v6 6/7] selinux: Restrict cross-cgroup memcg charging Albert Esteve
2026-11-24 13:03 ` Albert Esteve via OP-TEE
2026-11-24 13:49 ` Christian Göttsche
2026-11-24 13:49 ` Christian Göttsche via OP-TEE
2026-11-25 16:14 ` Albert Esteve
2026-11-25 16:14 ` Albert Esteve via OP-TEE
2026-11-24 13:03 ` [PATCH v6 7/7] selftests/dmabuf-heaps: Add dma-buf memcg accounting tests Albert Esteve
2026-11-24 13:03 ` Albert Esteve via OP-TEE
2026-11-25 13:05 ` sashiko-bot [this message]
2026-11-25 13:05 ` sashiko-bot--- via OP-TEE
2026-11-25 13:05 ` [PATCH v6 0/7] memcg: dma-buf cgroup accounting and charge transfer sashiko-bot
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=sashiko-outbox-233449@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Brian.Starkey@arm.com \
--cc=aesteve@redhat.com \
--cc=airlied@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=benjamin.gaignard@collabora.com \
--cc=brauner@kernel.org \
--cc=christian.koenig@amd.com \
--cc=corbet@lwn.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=echanude@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=jenswi@kernel.org \
--cc=jmorris@namei.org \
--cc=jstultz@google.com \
--cc=linux-mm@kvack.org \
--cc=linux-security-module@vger.kernel.org \
--cc=media-ci@linuxtv.org \
--cc=mhocko@kernel.org \
--cc=mkoutny@suse.com \
--cc=mripard@kernel.org \
--cc=muchun.song@linux.dev \
--cc=omosnacek@gmail.com \
--cc=op-tee@lists.trustedfirmware.org \
--cc=paul@paul-moore.com \
--cc=phasta@kernel.org \
--cc=rdunlap@infradead.org \
--cc=roman.gushchin@linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=selinux@vger.kernel.org \
--cc=serge@hallyn.com \
--cc=shakeel.butt@linux.dev \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=stephen.smalley.work@gmail.com \
--cc=sumit.garg@kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=tj@kernel.org \
--cc=tjmercier@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.