From: sashiko-bot@kernel.org
To: "Natalie Vock" <natalie.vock@gmx.de>
Cc: mkoutny@suse.com, hannes@cmpxchg.org, tj@kernel.org,
dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v7 5/6] drm/ttm: Be more aggressive when allocating below protection limit
Date: Tue, 21 Jul 2026 20:02:13 +0000 [thread overview]
Message-ID: <20260721200214.29B9B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260721-dmemcg-aggressive-protect-v7-5-97c4b1014315@gmx.de>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing IS_ERR check on get_cg_pool_unlocked() return value in dmem_cgroup_get_common_ancestor() causes a css reference leak and returns an ERR_PTR.
- [High] alloc_state->may_try_low remains uninitialized (false) when ttm_resource_try_charge fails with -EAGAIN, preventing necessary eviction of low-protected buffers.
--
--- Patch [5]: [PATCH v7 5/6] drm/ttm: Be more aggressive when allocating below protection limit ---
commit e2b13b1ad2c262766026403c3b8254d739bd29e9
Author: Natalie Vock <natalie.vock@gmx.de>
Subject: drm/ttm: Be more aggressive when allocating below protection limit
This patch modifies the TTM allocation process to consider cgroup protection
limits. When a cgroup's memory usage is below its low or min limit, TTM will
now attempt to evict unprotected buffers to make space rather than forcing
allocations into the GTT domain.
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 95ce3fc0f8764..ec0821e306da1 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
[ ... ]
> @@ -544,6 +548,42 @@ static int ttm_bo_alloc_at_place(struct ttm_buffer_object *bo,
> }
> }
>
> + /*
> + * cgroup protection plays a special role in eviction.
[ ... ]
> + * eviction path that only evicts buffers covered by neither 'low' or
> + * 'min' protections.
> + */
> + if (!alloc_state->in_evict) {
> + may_evict |= dmem_cgroup_below_min(NULL, alloc_state->charge_pool);
> + alloc_state->may_try_low = may_evict;
[Severity: High]
If ttm_resource_try_charge() fails with -EAGAIN earlier in this function, it
returns early and bypasses setting alloc_state->may_try_low here.
Since alloc_state is zero-initialized, may_try_low would remain false.
Would this unintentionally prevent the fallback eviction pass in
ttm_bo_evict_alloc() from executing, thereby preventing a cgroup at its max
limit from evicting low-protected BOs from its own subtree?
> +
> + may_evict |= dmem_cgroup_below_low(NULL, alloc_state->charge_pool);
> + }
> +
> ret = ttm_resource_alloc(bo, place, res, alloc_state->charge_pool);
> if (ret) {
[ ... ]
While reviewing the interactions with the dmem cgroup API, I noticed an
issue in kernel/cgroup/dmem.c:
kernel/cgroup/dmem.c:dmem_cgroup_get_common_ancestor() {
...
pool = get_cg_pool_unlocked(css_to_dmemcs(ancestor_css),
a->region);
if (!pool)
css_put(ancestor_css);
...
}
[Severity: High]
Could get_cg_pool_unlocked() return an error pointer like ERR_PTR(-ENOMEM)?
If it returns an error pointer, the !pool check evaluates to false, causing
the ancestor_css reference to be leaked.
Additionally, since this function is expected to return NULL on failure,
returning an ERR_PTR could cause callers checking for NULL to dereference
the error pointer. Should this check use IS_ERR(pool) instead?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260721-dmemcg-aggressive-protect-v7-0-97c4b1014315@gmx.de?part=5
next prev parent reply other threads:[~2026-07-21 20:02 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 19:43 [PATCH v7 0/6] cgroup/dmem,drm/ttm: Improve protection in contended cases Natalie Vock
2026-07-21 19:43 ` [PATCH v7 1/6] cgroup/dmem: Add queries for protection values Natalie Vock
2026-07-21 19:43 ` [PATCH v7 2/6] cgroup,cgroup/dmem: Add (dmem_)cgroup_common_ancestor helper Natalie Vock
2026-07-21 19:55 ` sashiko-bot
2026-07-21 19:58 ` Maarten Lankhorst
2026-07-21 19:43 ` [PATCH v7 3/6] drm/ttm: Extract code for attempting allocation in a place Natalie Vock
2026-07-21 19:58 ` sashiko-bot
2026-07-21 20:03 ` Maarten Lankhorst
2026-07-21 19:43 ` [PATCH v7 4/6] drm/ttm: Split cgroup charge and resource allocation Natalie Vock
2026-07-21 19:43 ` [PATCH v7 5/6] drm/ttm: Be more aggressive when allocating below protection limit Natalie Vock
2026-07-21 20:02 ` sashiko-bot [this message]
2026-07-21 19:43 ` [PATCH v7 6/6] drm/ttm: Use common ancestor of evictor and evictee as limit pool Natalie Vock
2026-07-21 20:01 ` 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=20260721200214.29B9B1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=hannes@cmpxchg.org \
--cc=mkoutny@suse.com \
--cc=natalie.vock@gmx.de \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tj@kernel.org \
/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.