From: Tejas Upadhyay <tejas.upadhyay@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: himal.prasad.ghimiray@intel.com, rodrigo.vivi@intel.com,
michal.wajdeczko@intel.com,
Tejas Upadhyay <tejas.upadhyay@intel.com>
Subject: [PATCH V18 06/14] drm/xe/vram: Extract buddy alloc and free helpers
Date: Wed, 26 Aug 2026 19:21:41 +0530 [thread overview]
Message-ID: <20260826135136.204044-22-tejas.upadhyay@intel.com> (raw)
In-Reply-To: <20260826135136.204044-16-tejas.upadhyay@intel.com>
Factor out xe_ttm_vram_buddy_alloc() and xe_ttm_vram_buddy_free()
from xe_ttm_vram_mgr_new() and xe_ttm_vram_mgr_del(). These helpers
consolidate block allocation with visible-size tracking and
block->private tagging, making them reusable by the upcoming VRAM
page offline reservation path.
No functional change.
Reviewed-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Signed-off-by: Tejas Upadhyay <tejas.upadhyay@intel.com>
---
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 82 +++++++++++++++++-----------
1 file changed, 51 insertions(+), 31 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
index 51e983ee3bad..16ecea497780 100644
--- a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
+++ b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
@@ -49,6 +49,40 @@ static inline bool xe_is_vram_mgr_blocks_contiguous(struct gpu_buddy *mm,
return true;
}
+static int xe_ttm_vram_buddy_alloc(struct xe_ttm_vram_mgr *mgr, u64 start,
+ u64 end, u64 size, u64 min_page_size,
+ struct list_head *blocks, unsigned long flags,
+ void *priv, u64 *used_visible)
+{
+ struct gpu_buddy *mm = &mgr->mm;
+ struct gpu_buddy_block *block;
+ int err;
+
+ err = gpu_buddy_alloc_blocks(mm, start, end, size, min_page_size, blocks, flags);
+ if (err)
+ return err;
+
+ list_for_each_entry(block, blocks, link)
+ block->private = priv;
+
+ if (end <= mgr->visible_size) {
+ *used_visible = size;
+ } else {
+ list_for_each_entry(block, blocks, link) {
+ u64 blk_start = gpu_buddy_block_offset(block);
+
+ if (blk_start < mgr->visible_size) {
+ u64 blk_end = blk_start + gpu_buddy_block_size(mm, block);
+
+ *used_visible += min(blk_end, mgr->visible_size) - blk_start;
+ }
+ }
+ }
+
+ mgr->visible_avail -= *used_visible;
+ return 0;
+}
+
static int xe_ttm_vram_mgr_new(struct ttm_resource_manager *man,
struct ttm_buffer_object *tbo,
const struct ttm_place *place,
@@ -57,7 +91,6 @@ static int xe_ttm_vram_mgr_new(struct ttm_resource_manager *man,
struct xe_ttm_vram_mgr *mgr = to_xe_ttm_vram_mgr(man);
struct xe_ttm_vram_mgr_resource *vres;
struct gpu_buddy *mm = &mgr->mm;
- struct gpu_buddy_block *block;
u64 size, min_page_size;
unsigned long lpfn;
int err;
@@ -118,32 +151,12 @@ static int xe_ttm_vram_mgr_new(struct ttm_resource_manager *man,
goto error_unlock;
}
- err = gpu_buddy_alloc_blocks(mm, (u64)place->fpfn << PAGE_SHIFT,
- (u64)lpfn << PAGE_SHIFT, size,
- min_page_size, &vres->blocks, vres->flags);
+ err = xe_ttm_vram_buddy_alloc(mgr, (u64)place->fpfn << PAGE_SHIFT,
+ (u64)lpfn << PAGE_SHIFT, size,
+ min_page_size, &vres->blocks, vres->flags,
+ tbo, &vres->used_visible_size);
if (err)
goto error_unlock;
-
- if (lpfn <= mgr->visible_size >> PAGE_SHIFT) {
- vres->used_visible_size = size;
- } else {
- struct gpu_buddy_block *block;
-
- list_for_each_entry(block, &vres->blocks, link) {
- u64 start = gpu_buddy_block_offset(block);
-
- if (start < mgr->visible_size) {
- u64 end = start + gpu_buddy_block_size(mm, block);
-
- vres->used_visible_size +=
- min(end, mgr->visible_size) - start;
- }
- }
- }
-
- mgr->visible_avail -= vres->used_visible_size;
- list_for_each_entry(block, &vres->blocks, link)
- block->private = tbo;
mutex_unlock(&mgr->lock);
if (!(vres->base.placement & TTM_PL_FLAG_CONTIGUOUS) &&
@@ -175,20 +188,27 @@ static int xe_ttm_vram_mgr_new(struct ttm_resource_manager *man,
return err;
}
+static void xe_ttm_vram_buddy_free(struct xe_ttm_vram_mgr *mgr,
+ struct list_head *blocks,
+ u64 used_visible)
+{
+ struct gpu_buddy_block *block;
+
+ list_for_each_entry(block, blocks, link)
+ block->private = NULL;
+ gpu_buddy_free_list(&mgr->mm, blocks, 0);
+ mgr->visible_avail += used_visible;
+}
+
static void xe_ttm_vram_mgr_del(struct ttm_resource_manager *man,
struct ttm_resource *res)
{
struct xe_ttm_vram_mgr_resource *vres =
to_xe_ttm_vram_mgr_resource(res);
struct xe_ttm_vram_mgr *mgr = to_xe_ttm_vram_mgr(man);
- struct gpu_buddy *mm = &mgr->mm;
- struct gpu_buddy_block *block;
mutex_lock(&mgr->lock);
- list_for_each_entry(block, &vres->blocks, link)
- block->private = NULL;
- gpu_buddy_free_list(mm, &vres->blocks, 0);
- mgr->visible_avail += vres->used_visible_size;
+ xe_ttm_vram_buddy_free(mgr, &vres->blocks, vres->used_visible_size);
mutex_unlock(&mgr->lock);
ttm_resource_fini(man, res);
--
2.52.0
next prev parent reply other threads:[~2026-08-26 13:52 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 13:51 [PATCH V18 00/14] Add memory page offlining support Tejas Upadhyay
2026-08-26 13:51 ` [PATCH V18 01/14] drm/xe: Link VRAM object with gpu buddy Tejas Upadhyay
2026-08-26 22:31 ` Andi Shyti
2026-08-26 13:51 ` [PATCH V18 02/14] drm/xe: Link LRC BO and its execution Queue Tejas Upadhyay
2026-08-26 22:34 ` Andi Shyti
2026-08-26 13:51 ` [PATCH V18 03/14] drm/xe: Extend BO purge to handle vram pages as well Tejas Upadhyay
2026-08-26 14:07 ` sashiko-bot
2026-08-26 22:42 ` Andi Shyti
2026-08-27 6:17 ` Upadhyay, Tejas
2026-08-27 14:40 ` Andi Shyti
2026-08-27 14:48 ` Upadhyay, Tejas
2026-08-28 5:25 ` Upadhyay, Tejas
2026-08-28 7:39 ` Andi Shyti
2026-08-28 17:29 ` Upadhyay, Tejas
2026-08-26 13:51 ` [PATCH V18 04/14] drm/xe/bo: Make xe_bo_is_user() public Tejas Upadhyay
2026-08-26 22:44 ` Andi Shyti
2026-08-26 13:51 ` [PATCH V18 05/14] drm/xe: Guard teardown paths against purged BOs Tejas Upadhyay
2026-08-26 14:12 ` sashiko-bot
2026-08-27 6:08 ` Ghimiray, Himal Prasad
2026-08-27 8:27 ` Upadhyay, Tejas
2026-08-26 13:51 ` Tejas Upadhyay [this message]
2026-08-26 22:50 ` [PATCH V18 06/14] drm/xe/vram: Extract buddy alloc and free helpers Andi Shyti
2026-08-26 13:51 ` [PATCH V18 07/14] drm/xe/vram: Add page offline data structures and lifecycle Tejas Upadhyay
2026-08-26 23:09 ` Andi Shyti
2026-08-27 6:19 ` Ghimiray, Himal Prasad
2026-08-26 13:51 ` [PATCH V18 08/14] drm/xe/vram: Add VRAM page offline fault handler Tejas Upadhyay
2026-08-26 14:05 ` sashiko-bot
2026-08-26 13:51 ` [PATCH V18 09/14] drm/xe/configfs: Add bad_page_reservation attribute Tejas Upadhyay
2026-08-27 6:42 ` Ghimiray, Himal Prasad
2026-08-27 15:00 ` Michal Wajdeczko
2026-08-28 17:48 ` Upadhyay, Tejas
2026-08-26 13:51 ` [PATCH V18 10/14] drm/xe/ras: Cache bad_page_reservation policy at init Tejas Upadhyay
2026-08-26 14:11 ` sashiko-bot
2026-08-27 6:45 ` Ghimiray, Himal Prasad
2026-08-26 13:51 ` [PATCH V18 11/14] drm/xe/vram: Check bad_page_reservation policy in fault handler Tejas Upadhyay
2026-08-26 14:08 ` sashiko-bot
2026-08-27 6:46 ` Ghimiray, Himal Prasad
2026-08-27 15:04 ` Michal Wajdeczko
2026-09-02 7:14 ` Mallesh, Koujalagi
2026-08-26 13:51 ` [PATCH V18 12/14] drm/xe: Expose bad VRAM pages via debugfs Tejas Upadhyay
2026-08-26 14:13 ` sashiko-bot
2026-08-27 15:16 ` Michal Wajdeczko
2026-08-28 19:06 ` Upadhyay, Tejas
2026-08-31 3:28 ` Iddamsetty, Aravind
2026-08-28 15:04 ` Rodrigo Vivi
2026-08-26 13:51 ` [PATCH V18 13/14] drm/xe/uapi: Expose ban reason in EXEC_QUEUE_GET_PROPERTY_BAN Tejas Upadhyay
2026-08-26 14:20 ` sashiko-bot
2026-08-27 18:26 ` Andi Shyti
2026-08-28 5:31 ` Upadhyay, Tejas
2026-08-26 13:51 ` [PATCH V18 14/14] drm/xe: Add fault-inject based VRAM page offline injection Tejas Upadhyay
2026-08-27 7:10 ` Ghimiray, Himal Prasad
2026-08-27 8:23 ` Upadhyay, Tejas
2026-08-26 14:37 ` ✗ CI.checkpatch: warning for Add memory page offlining support (rev21) Patchwork
2026-08-26 14:39 ` ✓ CI.KUnit: success " Patchwork
2026-08-26 15:21 ` ✓ Xe.CI.BAT: " Patchwork
2026-08-26 19:01 ` ✓ Xe.CI.FULL: " Patchwork
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=20260826135136.204044-22-tejas.upadhyay@intel.com \
--to=tejas.upadhyay@intel.com \
--cc=himal.prasad.ghimiray@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=michal.wajdeczko@intel.com \
--cc=rodrigo.vivi@intel.com \
/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.