]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/ttm: Convert -EAGAIN from dmem_cgroup_try_charge to -ENOSPC
authorThomas Hellström <thomas.hellstrom@linux.intel.com>
Fri, 8 May 2026 16:09:20 +0000 (18:09 +0200)
committerThomas Hellström <thomas.hellstrom@linux.intel.com>
Thu, 14 May 2026 11:12:57 +0000 (13:12 +0200)
dmem_cgroup_try_charge() returns -EAGAIN when the cgroup limit is
hit and the charge fails. TTM has no concept of -EAGAIN from resource
allocation; -ENOSPC is the canonical error meaning "no space, try
eviction". Convert at the source in ttm_resource_alloc() so no caller
needs to handle an unexpected error code, and clean up the now-redundant
-EAGAIN check in ttm_bo_alloc_resource().

Without this, -EAGAIN escaping ttm_resource_alloc() during an eviction
walk causes the walk to terminate early instead of continuing to the
next candidate.

Cc: Friedrich Vock <friedrich.vock@gmx.de>
Cc: Maarten Lankhorst <dev@lankhorst.se>
Cc: Tejun Heo <tj@kernel.org>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Christian Koenig <christian.koenig@amd.com>
Cc: dri-devel@lists.freedesktop.org
Cc: <stable@vger.kernel.org> # v6.14+
Fixes: 2b624a2c1865 ("drm/ttm: Handle cgroup based eviction in TTM")
Assisted-by: GitHub_Copilot:claude-sonnet-4.6
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Maarten Lankhorst <dev@lankhrost.se>
Link: https://patch.msgid.link/20260508160920.230339-1-thomas.hellstrom@linux.intel.com
drivers/gpu/drm/ttm/ttm_bo.c
drivers/gpu/drm/ttm/ttm_resource.c

index 2934017055429ca15b22207d2806dd29cc95a44d..bcd76f6bb7f02d64dc816c3cfbe7e02b13bd6d5e 100644 (file)
@@ -739,7 +739,7 @@ static int ttm_bo_alloc_resource(struct ttm_buffer_object *bo,
                may_evict = (force_space && place->mem_type != TTM_PL_SYSTEM);
                ret = ttm_resource_alloc(bo, place, res, force_space ? &limit_pool : NULL);
                if (ret) {
-                       if (ret != -ENOSPC && ret != -EAGAIN) {
+                       if (ret != -ENOSPC) {
                                dmem_cgroup_pool_state_put(limit_pool);
                                return ret;
                        }
index 0e5f1582f13d8466e17b9cbfb3827e9667f045c0..154d6739256f86925d6a2b5d9ad1cd6632f460c6 100644 (file)
@@ -398,8 +398,11 @@ int ttm_resource_alloc(struct ttm_buffer_object *bo,
 
        if (man->cg) {
                ret = dmem_cgroup_try_charge(man->cg, bo->base.size, &pool, ret_limit_pool);
-               if (ret)
+               if (ret) {
+                       if (ret == -EAGAIN)
+                               ret = -ENOSPC;
                        return ret;
+               }
        }
 
        ret = man->func->alloc(man, bo, place, res_ptr);