Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E3DF3093A6 for ; Sat, 1 Aug 2026 14:04:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785593048; cv=none; b=aPRA1dJqKcWdAcgCD3BSwvfVwBVrSroOiFMYOOdjzivWFIb2BTp1CtPkXfoD1QsJPgonsJArZFKwM3X6rK7sGU3Hhl8WGGO6hLHBphwkbfo9Jx9SOlFewgq3wV7FOXY7BlFP1lAzR68a8nsSbeNdPgmIniK9ZLxIouVTGEKqgCg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785593048; c=relaxed/simple; bh=j611efynchdDns6Y1QRTvI+QkCmicmlX2tupXkNqUJI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hVaMxJbPtgX5zxYvZENIED/mgXl5SXd1cDlEGTLQg36Hpog5Rpct9RBKl4Jctqn3Ful9g8pBUk/6fHHHas7GXd79BHV4xQc/BFDQ5g30J9bGzOaGqe+wUfazwqcHfgPlmw4fzahCqTT6Wh6eFJEyv51l/aeWsSS56QH9gtmbg/s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DE+aiHk5; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DE+aiHk5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E8101F00ACA; Sat, 1 Aug 2026 14:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785593047; bh=pAT/cCdCN6TTD1+oC73XgclDX3b4ja4jX4XonkVQybI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DE+aiHk5YcEYvf8QAkFk7jk0UPw9Qxk9Rr1EqtakBG0J4cabR4Jk5wyJnMHDO9U0T ewSz904wbk1dRYA3sLaKlDZXropYyDqnUG06RtHk+f53YgdiASo20Xxj2J+pWZPCaM w5FvRoTqrb+fRIOlieAaYkb+w5dRKdkA8OL3WPOg1tV1ZegP6gGwF8aFg0HikYmesq JclsOAgPRu8KAxZ2bSJv9v5JYTZTK9v6X59RlZtKG3eyyjGr4aCEfXJe8Iq5lKmt2n Nr7fwnBXEXD4Exy+o8wVdZxpWUD0uGn8HiNYf/Q58CeAf7ESj6byQUb3DUiLoTtSog cVOPRqwrcLTTQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Arvind Yadav , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Himal Prasad Ghimiray , Matthew Brost , Sasha Levin Subject: [PATCH 6.18.y 3/5] drm/xe/bo: Add purgeable bo state tracking and field madv to xe_bo Date: Sat, 1 Aug 2026 10:03:57 -0400 Message-ID: <20260801140402.3645391-3-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260801140402.3645391-1-sashal@kernel.org> References: <2026072936-hummus-emblem-55be@gregkh> <20260801140402.3645391-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Arvind Yadav [ Upstream commit b67427f939ccf038a658badb02dd948c7b516248 ] Add infrastructure for tracking purgeable state of buffer objects. This includes: Introduce enum xe_madv_purgeable_state with three states: - XE_MADV_PURGEABLE_WILLNEED (0): BO is needed and should not be purged. This is the default state for all BOs. - XE_MADV_PURGEABLE_DONTNEED (1): BO is not currently needed and can be purged by the kernel under memory pressure to reclaim resources. Only non-shared BOs can be marked as DONTNEED. - XE_MADV_PURGEABLE_PURGED (2): BO has been purged by the kernel. Accessing a purged BO results in error. Follows i915 semantics where once purged, the BO remains permanently invalid ("once purged, always purged"). Add madv_purgeable field to struct xe_bo for state tracking of purgeable state across concurrent access paths Cc: Thomas Hellström Cc: Himal Prasad Ghimiray Reviewed-by: Matthew Brost Signed-off-by: Arvind Yadav Signed-off-by: Matthew Brost Link: https://patch.msgid.link/20260326130843.3545241-3-arvind.yadav@intel.com Stable-dep-of: 7bc597ce74ba ("drm/xe/vm: Fix BO prefetch with CONSULT_MEM_ADVISE_PREF_LOC") Signed-off-by: Sasha Levin --- drivers/gpu/drm/xe/xe_bo.h | 56 ++++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_bo_types.h | 6 ++++ 2 files changed, 62 insertions(+) diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h index a77af42b5f9e..02506c337f00 100644 --- a/drivers/gpu/drm/xe/xe_bo.h +++ b/drivers/gpu/drm/xe/xe_bo.h @@ -84,6 +84,28 @@ #define XE_PCI_BARRIER_MMAP_OFFSET (0x50 << XE_PTE_SHIFT) +/** + * enum xe_madv_purgeable_state - Buffer object purgeable state enumeration + * + * This enum defines the possible purgeable states for a buffer object, + * allowing userspace to provide memory usage hints to the kernel for + * better memory management under pressure. + * + * @XE_MADV_PURGEABLE_WILLNEED: The buffer object is needed and should not be purged. + * This is the default state. + * @XE_MADV_PURGEABLE_DONTNEED: The buffer object is not currently needed and can be + * purged by the kernel under memory pressure. + * @XE_MADV_PURGEABLE_PURGED: The buffer object has been purged by the kernel. + * + * Accessing a purged buffer will result in an error. Per i915 semantics, + * once purged, a BO remains permanently invalid and must be destroyed and recreated. + */ +enum xe_madv_purgeable_state { + XE_MADV_PURGEABLE_WILLNEED, + XE_MADV_PURGEABLE_DONTNEED, + XE_MADV_PURGEABLE_PURGED, +}; + struct sg_table; struct xe_bo *xe_bo_alloc(void); @@ -212,6 +234,40 @@ static inline bool xe_bo_is_protected(const struct xe_bo *bo) return bo->pxp_key_instance; } +/** + * xe_bo_is_purged() - Check if buffer object has been purged + * @bo: The buffer object to check + * + * Checks if the buffer object's backing store has been discarded by the + * kernel due to memory pressure after being marked as purgeable (DONTNEED). + * Once purged, the BO cannot be restored and any attempt to use it will fail. + * + * Context: Caller must hold the BO's dma-resv lock + * Return: true if the BO has been purged, false otherwise + */ +static inline bool xe_bo_is_purged(struct xe_bo *bo) +{ + xe_bo_assert_held(bo); + return bo->madv_purgeable == XE_MADV_PURGEABLE_PURGED; +} + +/** + * xe_bo_madv_is_dontneed() - Check if BO is marked as DONTNEED + * @bo: The buffer object to check + * + * Checks if userspace has marked this BO as DONTNEED (i.e., its contents + * are not currently needed and can be discarded under memory pressure). + * This is used internally to decide whether a BO is eligible for purging. + * + * Context: Caller must hold the BO's dma-resv lock + * Return: true if the BO is marked DONTNEED, false otherwise + */ +static inline bool xe_bo_madv_is_dontneed(struct xe_bo *bo) +{ + xe_bo_assert_held(bo); + return bo->madv_purgeable == XE_MADV_PURGEABLE_DONTNEED; +} + static inline void xe_bo_unpin_map_no_vm(struct xe_bo *bo) { if (likely(bo)) { diff --git a/drivers/gpu/drm/xe/xe_bo_types.h b/drivers/gpu/drm/xe/xe_bo_types.h index d4fe3c8dca5b..ff8317bfc1ae 100644 --- a/drivers/gpu/drm/xe/xe_bo_types.h +++ b/drivers/gpu/drm/xe/xe_bo_types.h @@ -108,6 +108,12 @@ struct xe_bo { * from default */ u64 min_align; + + /** + * @madv_purgeable: user space advise on BO purgeability, protected + * by BO's dma-resv lock. + */ + u32 madv_purgeable; }; #endif -- 2.53.0