From: sashiko-bot@kernel.org
To: "Dave Airlie" <airlied@gmail.com>
Cc: tj@kernel.org, mkoutny@suse.com, dri-devel@lists.freedesktop.org,
hannes@cmpxchg.org
Subject: Re: [PATCH 10/10] xe: create a flag to enable memcg accounting for XE as well.
Date: Mon, 06 Jul 2026 03:18:31 +0000 [thread overview]
Message-ID: <20260706031832.2CF491F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260706024122.853329-11-airlied@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Missing memcg accounting for userspace dumb buffers created via xe_bo_dumb_create.
- [High] Page tables created asynchronously via workqueues are charged to the kworker's root memcg instead of the user's memcg.
- [High] BOs created with deferred backing bypass memcg accounting upon CPU page fault.
--
commit ebf9090c8281d875d2f980bb34d324c88a8b277f
Author: Maarten Lankhorst <dev@lankhorst.se>
xe: create a flag to enable memcg accounting for XE as well.
This adds support for memcg accounting to ttm object used by xe driver.
> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
> @@ -56,6 +56,7 @@ static const struct ttm_place sys_placement_flags = {
> .flags = 0,
> };
>
> +/* TTM_PL_FLAG_MEMCG is not set, those placements are used for eviction */
> static struct ttm_placement sys_placement = {
[Severity: High]
If userspace creates a buffer object with the deferred backing flag, mmaps
it, and accesses it via the CPU before the GPU validates it,
xe_bo_init_locked() assigns sys_placement as the initial placement.
Since sys_placement lacks TTM_PL_FLAG_MEMCG, will a CPU page fault
(which calls xe_bo_fault_migrate() and ttm_bo_populate()) allocate memory
without charging the memcg? Does this allow userspace to bypass memcg
limits for deferred backing buffers?
> .num_placement = 1,
> .placement = &sys_placement_flags,
> };
[ ... ]
> @@ -2384,6 +2385,9 @@ struct xe_bo *xe_bo_init_locked(struct xe_device *xe, struct xe_bo *bo,
> placement = (type == ttm_bo_type_sg ||
> bo->flags & XE_BO_FLAG_DEFER_BACKING) ? &sys_placement :
> &bo->placement;
> +
> + if (bo->flags & XE_BO_FLAG_ACCOUNTED)
> + ttm_bo_set_cgroup(&bo->ttm, get_obj_cgroup_from_current());
[Severity: High]
When page tables are created asynchronously, such as from GPU page fault
handlers or rebinding operations executing in workqueues via
xe_pt_create(), get_obj_cgroup_from_current() will resolve to the
kworker's context. Does this cause these allocations to be incorrectly
charged to the root memcg instead of the user's memcg?
> err = ttm_bo_init_reserved(&xe->ttm, &bo->ttm, type,
> placement, alignment,
[ ... ]
> @@ -3361,7 +3365,7 @@ int xe_gem_create_ioctl(struct drm_device *dev, void *data,
> if (XE_IOCTL_DBG(xe, args->size & ~PAGE_MASK))
> return -EINVAL;
>
> - bo_flags = 0;
> + bo_flags = XE_BO_FLAG_ACCOUNTED;
> if (args->flags & DRM_XE_GEM_CREATE_FLAG_DEFER_BACKING)
> bo_flags |= XE_BO_FLAG_DEFER_BACKING;
[Severity: High]
This correctly adds the accounting flag for standard GEM object creation, but
are dumb buffers created via xe_bo_dumb_create() missing this flag?
Dumb buffers are also allocated on behalf of userspace via
DRM_IOCTL_MODE_CREATE_DUMB:
xe_bo_dumb_create() {
...
bo = xe_bo_create_user(xe, NULL, args->size,
DRM_XE_GEM_CPU_CACHING_WC,
XE_BO_FLAG_VRAM_IF_DGFX(xe_device_get_root_tile(xe)) |
XE_BO_FLAG_FORCE_WC |
XE_BO_FLAG_NEEDS_CPU_ACCESS, NULL);
}
Do these also need XE_BO_FLAG_ACCOUNTED to prevent a malicious or buggy
userspace application from bypassing memcg limits to exhaust host memory?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260706024122.853329-1-airlied@gmail.com?part=10
next prev parent reply other threads:[~2026-07-06 3:18 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 2:36 drm/ttm/memcg/lru: enable memcg tracking for ttm, xe and amdgpu driver (part 2) Dave Airlie
2026-07-06 2:36 ` [PATCH 01/10] memcg: add support for GPU page counters. (v4) Dave Airlie
2026-07-06 3:01 ` sashiko-bot
2026-07-06 2:36 ` [PATCH 02/10] ttm: add a memcg accounting flag to the alloc/populate APIs Dave Airlie
2026-07-06 2:58 ` sashiko-bot
2026-07-06 2:36 ` [PATCH 03/10] ttm/pool: initialise the shrinker earlier Dave Airlie
2026-07-06 2:56 ` sashiko-bot
2026-07-06 2:36 ` [PATCH 04/10] ttm: add objcg pointer to bo and tt (v2) Dave Airlie
2026-07-06 2:53 ` sashiko-bot
2026-07-06 2:36 ` [PATCH 05/10] ttm/pool: enable memcg tracking and shrinker. (v3) Dave Airlie
2026-07-06 2:59 ` sashiko-bot
2026-07-06 2:36 ` [PATCH 06/10] ttm: hook up memcg placement flags Dave Airlie
2026-07-06 3:01 ` sashiko-bot
2026-07-06 2:36 ` [PATCH 07/10] memcontrol: allow objcg api when memcg is config off Dave Airlie
2026-07-06 2:55 ` sashiko-bot
2026-07-06 2:36 ` [PATCH 08/10] amdgpu: add support for memory cgroups Dave Airlie
2026-07-06 3:14 ` sashiko-bot
2026-07-06 2:36 ` [PATCH 09/10] ttm: add support for a module option to disable memcg integration Dave Airlie
2026-07-06 3:10 ` sashiko-bot
2026-07-06 2:36 ` [PATCH 10/10] xe: create a flag to enable memcg accounting for XE as well Dave Airlie
2026-07-06 3:18 ` sashiko-bot [this message]
2026-07-06 7:59 ` drm/ttm/memcg/lru: enable memcg tracking for ttm, xe and amdgpu driver (part 2) Christian König
-- strict thread matches above, loose matches on Subject: below --
2026-07-06 5:22 drm/ttm/memcg/lru: enable memcg tracking for ttm, xe and amdgpu driver (part 2) (v2) Dave Airlie
2026-07-06 5:22 ` [PATCH 10/10] xe: create a flag to enable memcg accounting for XE as well Dave Airlie
2026-07-06 5:50 ` 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=20260706031832.2CF491F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=hannes@cmpxchg.org \
--cc=mkoutny@suse.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox