From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.13 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796294873; b=xDnKgzuSgE3gHsdiedLtkijpfyFU5WAX37qpDep0vTH9OioObsaLBZirajx+eq4s3EAY zN6lG9T/bXrnRWh0P5pfWJy/u24u9RE2/2qyCrW3ixL+UrtbB09t9JE3zPBddUYTs/ZxL sGu4s2PwQvRwsno3RAdNess1CgliabmLg0c+gS0jQitNE4r52julqUqGDfjHbDigDO7FQ 78YqKp5lOq3rdeWHCOiYPC4bJaBS7CYVwb28Q7D5mXH2L9BmZ0xD1zepPb8hMQ8l6SBTX 1mNOam5xf539s7fv8I9z8BkV0ws0i9PVWq9WX51pd+fbb8kHsFOr+rYIgJCElvQcABw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796294873; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=K3Qq0ndcuAfT3Q5dGnNT8GTjJBwiARxfHX0DBTwyE3w=; b=F9lrNCDj5U0OGc/GyLikYcdDdVw6MpjR7zj6uB+ylINNEylL/g4vqB/aa6iW0gmvUMOJ Bv9MjRgVlESyqDKJ0GzHcr4xPG5ymMPK87+u/Nvd+9hNttegn4VNtiftxEhR05qWzUfPh vh8azL+9xdNRdPc0iueRadXTZVuebWHUoEo8pcS0KGQVhZ6LyCEe/XK7O6JhXkRIQzlZP YUVpj+Xn6gsbkhwVn9jex/GpljFQKsEYTUCDeQJsgosthpjIY9aAL1Fcrh9h4VFBDEAWo Qmq9ZNv99ijgOdPhretr+dO/Rqhm+wosR0UlN/Ik/BtU1fVaTwdT6fRs4k4guJmoJbA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=i8AuAh9s; arc=none smtp.remote-ip=198.175.65.13 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4C14606A332 for ; Thu, 3 Dec 2026 10:47:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D4C14606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=i8AuAh9s DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796294873; x=1827830873; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=K3Qq0ndcuAfT3Q5dGnNT8GTjJBwiARxfHX0DBTwyE3w=; b=i8AuAh9sl2ii2WFUnTRGOcc+YriOd1DeiK5F6pLqute1ozgRoy1NDi06 sPHRIHFVaiuJESw6Qo2mM4czNAWRj4XFmgA3Gb9F4jS22afYthvrdb04d sW8b+ZfQHkCnm1I2YJRScO4q4biq5BkciRLFqNwOovjjJRF78oY9UJOw1 VvqksgX8w7rfheOGZmnUHVgucPX42nKo0UF2HLrQubqc/gvkrhQpXiw8J kp1+Vbbs4Qjzh0ivzy2Zf/H+T3N1UACgs6pFQlUqI2B48k4nDVky5Ahzk iazKtt/7i06WBDGzFdcpfUWZXNXqLZ1mbpsDuVLRwgJepJP9+sq144KxB Q==; X-CSE-ConnectionGUID: pGk3PWcxRnmECACT0D1ywQ== X-CSE-MsgGUID: PSj5GTw6TZq9f75UaDwTCQ== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5161237" X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="5161237" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 02:47:53 -0800 X-CSE-ConnectionGUID: NSih+M01RNW+YdGgXacXZA== X-CSE-MsgGUID: cXaBvn2vTgCxtrSF75q+tQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="13761714" Received: from ettammin-mobl3.ger.corp.intel.com (HELO fedora) ([10.245.244.105]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 02:47:51 -0800 From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= To: intel-xe@lists.freedesktop.org Cc: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Matthew Auld , Matthew Brost , Rodrigo Vivi , Natalie Vock , Arun Pravin , dri-devel@lists.freedesktop.org, stable@vger.kernel.org, Arunpravin Paneer Selvam Subject: [PATCH v3 3/3] drm/ttm, drm/xe: Don't invoke the OOM killer when evicting VRAM at suspend Date: Thu, 3 Dec 2026 11:47:15 +0100 Message-ID: <20261203104715.270111-4-thomas.hellstrom@linux.intel.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261203104715.270111-1-thomas.hellstrom@linux.intel.com> References: <20261203104715.270111-1-thomas.hellstrom@linux.intel.com> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When evicting user BOs from VRAM at suspend time, allocating system memory for the eviction may currently invoke the OOM killer. Under memory pressure it is preferable to abort the suspend and return -ENOMEM rather than killing processes. TTM's ttm_resource_manager_evict_all() uses a default operation context, which doesn't allow the caller to request __GFP_RETRY_MAYFAIL allocations. Introduce ttm_resource_manager_evict_all_ctx() taking a caller-supplied struct ttm_operation_ctx, keeping ttm_resource_manager_evict_all() as an exported wrapper using a default context so that existing users are unaffected. Also honor the ctx interruptible setting when waiting for the eviction fences. Use the new function from xe_bo_evict_all_user() with gfp_retry_mayfail set. Note that the PM notifier eviction is best-effort and ignores errors. Any remaining BOs are evicted again from the .suspend() callback, where an -ENOMEM might then cause the suspend to be aborted. v2: - Rebase v3: - Rebase onto latest drm-tip Fixes: c6a4d46ec1d7 ("drm/xe: evict user memory in PM notifier") Cc: Matthew Auld Cc: Matthew Brost Cc: Rodrigo Vivi Cc: Natalie Vock Cc: Arun Pravin Cc: intel-xe@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org Cc: # v6.16+ Link: https://gitlab.freedesktop.org/drm/xe/kernel/-/work_items/9615 Reviewed-by: Matthew Brost Reviewed-by: Arunpravin Paneer Selvam Signed-off-by: Thomas Hellström --- drivers/gpu/drm/ttm/ttm_resource.c | 37 +++++++++++++++++++++++------- drivers/gpu/drm/xe/xe_bo_evict.c | 5 +++- include/drm/ttm/ttm_resource.h | 5 ++++ 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c index 2db5d9bbfbe7..d1eccaeb1047 100644 --- a/drivers/gpu/drm/ttm/ttm_resource.c +++ b/drivers/gpu/drm/ttm/ttm_resource.c @@ -568,24 +568,26 @@ void ttm_resource_manager_init(struct ttm_resource_manager *man, } EXPORT_SYMBOL(ttm_resource_manager_init); -/* - * ttm_resource_manager_evict_all - * +/** + * ttm_resource_manager_evict_all_ctx() - Evict all objects from a manager * @bdev: device to use * @man: manager to use + * @ctx: operation context for the eviction * * Evict all the objects out of a memory manager until it is empty. * Part of memory manager cleanup sequence. + * + * Return: 0 on success, negative error code on failure. */ -int ttm_resource_manager_evict_all(struct ttm_device *bdev, - struct ttm_resource_manager *man) +int ttm_resource_manager_evict_all_ctx(struct ttm_device *bdev, + struct ttm_resource_manager *man, + struct ttm_operation_ctx *ctx) { - struct ttm_operation_ctx ctx = { }; struct dma_fence *fence; int ret, i; do { - ret = ttm_bo_evict_first(bdev, man, &ctx); + ret = ttm_bo_evict_first(bdev, man, ctx); cond_resched(); } while (!ret); @@ -600,7 +602,7 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev, if (fence && !dma_fence_is_signaled(fence)) { dma_fence_get(fence); spin_unlock(&man->eviction_lock); - ret = dma_fence_wait(fence, false); + ret = dma_fence_wait(fence, ctx->interruptible); dma_fence_put(fence); if (ret) return ret; @@ -611,6 +613,25 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev, return ret; } +EXPORT_SYMBOL(ttm_resource_manager_evict_all_ctx); + +/** + * ttm_resource_manager_evict_all() - Evict all objects from a manager + * @bdev: device to use + * @man: manager to use + * + * Same as ttm_resource_manager_evict_all_ctx() using a default, + * non-interruptible operation context. + * + * Return: 0 on success, negative error code on failure. + */ +int ttm_resource_manager_evict_all(struct ttm_device *bdev, + struct ttm_resource_manager *man) +{ + struct ttm_operation_ctx ctx = { }; + + return ttm_resource_manager_evict_all_ctx(bdev, man, &ctx); +} EXPORT_SYMBOL(ttm_resource_manager_evict_all); /** diff --git a/drivers/gpu/drm/xe/xe_bo_evict.c b/drivers/gpu/drm/xe/xe_bo_evict.c index 61986422772c..7fdbe32473ab 100644 --- a/drivers/gpu/drm/xe/xe_bo_evict.c +++ b/drivers/gpu/drm/xe/xe_bo_evict.c @@ -156,6 +156,9 @@ static int xe_bo_evict_all_ccs(struct ttm_resource_manager *man) */ int xe_bo_evict_all_user(struct xe_device *xe) { + struct ttm_operation_ctx ctx = { + .gfp_retry_mayfail = true, + }; struct ttm_device *bdev = &xe->ttm; u32 mem_type; int ret; @@ -182,7 +185,7 @@ int xe_bo_evict_all_user(struct xe_device *xe) continue; } - ret = ttm_resource_manager_evict_all(bdev, man); + ret = ttm_resource_manager_evict_all_ctx(bdev, man, &ctx); if (ret) return ret; } diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h index d90e1cffa862..103a241525e6 100644 --- a/include/drm/ttm/ttm_resource.h +++ b/include/drm/ttm/ttm_resource.h @@ -42,6 +42,7 @@ struct dmem_cgroup_device; struct dmem_cgroup_region; struct drm_printer; struct ttm_device; +struct ttm_operation_ctx; struct ttm_resource_manager; struct ttm_resource; struct ttm_place; @@ -488,6 +489,10 @@ void ttm_resource_manager_set_dmem_region(struct ttm_resource_manager *man, int ttm_resource_manager_dmem_reclaim(struct dmem_cgroup_pool_state *pool, u64 target_bytes, void *priv); +int ttm_resource_manager_evict_all_ctx(struct ttm_device *bdev, + struct ttm_resource_manager *man, + struct ttm_operation_ctx *ctx); + int ttm_resource_manager_evict_all(struct ttm_device *bdev, struct ttm_resource_manager *man); -- 2.56.1