From: Tejas Upadhyay <tejas.upadhyay@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: himal.prasad.ghimiray@intel.com,
Tejas Upadhyay <tejas.upadhyay@intel.com>,
Arunpravin Paneer Selvam <arunpravin.paneerselvam@amd.com>,
dri-devel@lists.freedesktop.org,
Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Subject: [PATCH V14 2/9] [DO NOT MERGE]drm/gpu: Add gpu_buddy_allocated_addr_to_block helper
Date: Thu, 30 Jul 2026 15:41:24 +0530 [thread overview]
Message-ID: <20260730101132.2770752-13-tejas.upadhyay@intel.com> (raw)
In-Reply-To: <20260730101132.2770752-11-tejas.upadhyay@intel.com>
Add helper with primary purpose is to efficiently trace a specific
physical memory address back to its corresponding TTM buffer object.
v3:
- use mm->chunk_size minimum allocation granularity (Arun)
v2:
- %s/gpu_buddy_addr_to_block/gpu_buddy_allocated_addr_to_block(MattA)
- remove clear->avail and split nodes check(MattA)
- Adapt lockdep(MattB)
Signed-off-by: Tejas Upadhyay <tejas.upadhyay@intel.com>
Cc: Arunpravin Paneer Selvam <arunpravin.paneerselvam@amd.com>
Cc: dri-devel@lists.freedesktop.org
Reviewed-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
---
drivers/gpu/buddy.c | 53 +++++++++++++++++++++++++++++++++++++++
include/linux/gpu_buddy.h | 2 ++
2 files changed, 55 insertions(+)
diff --git a/drivers/gpu/buddy.c b/drivers/gpu/buddy.c
index dc81fe0301ce..4d5ac375a538 100644
--- a/drivers/gpu/buddy.c
+++ b/drivers/gpu/buddy.c
@@ -630,6 +630,59 @@ void gpu_buddy_free_block(struct gpu_buddy *mm,
}
EXPORT_SYMBOL(gpu_buddy_free_block);
+/**
+ * gpu_buddy_allocated_addr_to_block - given relative address find the allocated block
+ *
+ * @mm: GPU buddy manager
+ * @addr: Relative address
+ *
+ * Returns:
+ * gpu_buddy_block on success, NULL or error code on failure
+ */
+struct gpu_buddy_block *gpu_buddy_allocated_addr_to_block(struct gpu_buddy *mm, u64 addr)
+{
+ struct gpu_buddy_block *block;
+ LIST_HEAD(dfs);
+ u64 end;
+ int i;
+
+ gpu_buddy_driver_lock_held(mm);
+
+ end = addr + mm->chunk_size - 1;
+ for (i = 0; i < mm->n_roots; ++i)
+ list_add_tail(&mm->roots[i]->tmp_link, &dfs);
+
+ do {
+ u64 block_start;
+ u64 block_end;
+
+ block = list_first_entry_or_null(&dfs,
+ struct gpu_buddy_block,
+ tmp_link);
+ if (!block)
+ break;
+
+ list_del(&block->tmp_link);
+
+ block_start = gpu_buddy_block_offset(block);
+ block_end = block_start + gpu_buddy_block_size(mm, block) - 1;
+
+ if (!overlaps(addr, end, block_start, block_end))
+ continue;
+
+ if (gpu_buddy_block_is_allocated(block))
+ return block;
+ else if (gpu_buddy_block_is_free(block))
+ return NULL;
+
+ list_add(&block->right->tmp_link, &dfs);
+ list_add(&block->left->tmp_link, &dfs);
+ } while (1);
+
+ return ERR_PTR(-ENXIO);
+}
+EXPORT_SYMBOL(gpu_buddy_allocated_addr_to_block);
+
static void __gpu_buddy_free_list(struct gpu_buddy *mm,
struct list_head *objects,
bool mark_clear,
diff --git a/include/linux/gpu_buddy.h b/include/linux/gpu_buddy.h
index e037714563d8..2c36124bb696 100644
--- a/include/linux/gpu_buddy.h
+++ b/include/linux/gpu_buddy.h
@@ -287,6 +287,8 @@ void gpu_buddy_reset_clear(struct gpu_buddy *mm, bool is_clear);
void gpu_buddy_free_block(struct gpu_buddy *mm, struct gpu_buddy_block *block);
+struct gpu_buddy_block *gpu_buddy_allocated_addr_to_block(struct gpu_buddy *mm, u64 addr);
+
void gpu_buddy_free_list(struct gpu_buddy *mm,
struct list_head *objects,
unsigned int flags);
--
2.52.0
next prev parent reply other threads:[~2026-07-30 10:12 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 10:11 [PATCH V14 0/9] Add memory page offlining support Tejas Upadhyay
2026-07-30 10:11 ` [PATCH V14 1/9] drm/xe: Link VRAM object with gpu buddy Tejas Upadhyay
2026-08-11 11:04 ` Ghimiray, Himal Prasad
2026-07-30 10:11 ` Tejas Upadhyay [this message]
2026-07-30 10:11 ` [PATCH V14 3/9] drm/xe: Link LRC BO and its execution Queue Tejas Upadhyay
2026-08-11 11:05 ` Ghimiray, Himal Prasad
2026-07-30 10:11 ` [PATCH V14 4/9] drm/xe: Extend BO purge to handle vram pages as well Tejas Upadhyay
2026-08-11 11:06 ` Ghimiray, Himal Prasad
2026-07-30 10:11 ` [PATCH V14 5/9] drm/xe: Handle physical memory address error Tejas Upadhyay
2026-07-30 10:11 ` [PATCH V14 6/9] drm/xe/configfs: Add vram bad page reservation policy Tejas Upadhyay
2026-07-30 10:11 ` [PATCH V14 7/9] drm/xe/cri: Add sysfs interface for bad gpu vram pages Tejas Upadhyay
2026-07-30 10:11 ` [PATCH V14 8/9] drm/xe/uapi: Expose ban reason in EXEC_QUEUE_GET_PROPERTY_BAN Tejas Upadhyay
2026-07-30 10:11 ` [PATCH V14 9/9] drm/xe: Add fault-inject based VRAM page offline injection Tejas Upadhyay
2026-07-30 10:18 ` ✗ CI.checkpatch: warning for Add memory page offlining support (rev16) Patchwork
2026-07-30 10:19 ` ✓ CI.KUnit: success " Patchwork
2026-07-30 11:04 ` ✓ Xe.CI.BAT: " Patchwork
2026-07-30 12:10 ` ✓ 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=20260730101132.2770752-13-tejas.upadhyay@intel.com \
--to=tejas.upadhyay@intel.com \
--cc=arunpravin.paneerselvam@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=himal.prasad.ghimiray@intel.com \
--cc=intel-xe@lists.freedesktop.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