From: Honglei Huang <honglei1.huang@amd.com>
To: <Felix.Kuehling@amd.com>, <alexander.deucher@amd.com>,
<christian.koenig@amd.com>, <Philip.Yang@amd.com>,
<Ray.Huang@amd.com>
Cc: <dmitry.osipenko@collabora.com>, <airlied@gmail.com>,
<daniel@ffwll.ch>, <amd-gfx@lists.freedesktop.org>,
<dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org>,
<linux-mm@kvack.org>, <akpm@linux-foundation.org>,
<honghuan@amd.com>
Subject: [PATCH v4 3/8] drm/amdkfd: Implement interval tree for userptr ranges
Date: Mon, 9 Feb 2026 14:10:42 +0800 [thread overview]
Message-ID: <20260209061047.3881808-4-honglei1.huang@amd.com> (raw)
In-Reply-To: <20260209061047.3881808-1-honglei1.huang@amd.com>
From: Honglei Huang <honghuan@amd.com>
Add interval tree support for efficient lookup of affected userptr
ranges during MMU notifier callbacks.
add:
- Include linux/interval_tree.h
- discard_invalid_ranges() function that uses interval tree to
identify and mark ranges affected by a given invalidation event
Signed-off-by: Honglei Huang <honghuan@amd.com>
---
.../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 21 +++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index a32b46355..6fe4ed22c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -25,6 +25,7 @@
#include <linux/pagemap.h>
#include <linux/sched/mm.h>
#include <linux/sched/task.h>
+#include <linux/interval_tree.h>
#include <drm/ttm/ttm_tt.h>
#include <drm/drm_exec.h>
@@ -1122,6 +1123,26 @@ static int init_user_pages(struct kgd_mem *mem, uint64_t user_addr,
return ret;
}
+static bool discard_invalid_ranges(struct kgd_mem *mem,
+ unsigned long inv_start, unsigned long inv_end)
+{
+ struct interval_tree_node *node;
+ struct user_range_info *range_info;
+ bool any_invalid = false;
+
+ for (node = interval_tree_iter_first(&mem->user_ranges_itree, inv_start, inv_end - 1);
+ node;
+ node = interval_tree_iter_next(node, inv_start, inv_end - 1)) {
+ range_info = container_of(node, struct user_range_info, it_node);
+
+ range_info->valid = false;
+ any_invalid = true;
+ pr_debug("Range [0x%llx-0x%llx) marked invalid\n",
+ range_info->start, range_info->start + range_info->size);
+ }
+ return any_invalid;
+}
+
/* Reserving a BO and its page table BOs must happen atomically to
* avoid deadlocks. Some operations update multiple VMs at once. Track
* all the reservation info in a context structure. Optionally a sync
--
2.34.1
next prev parent reply other threads:[~2026-02-09 6:11 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-09 6:10 [PATCH v4 0/8] drm/amdkfd: Add batch userptr allocation support Honglei Huang
2026-02-09 6:10 ` [PATCH v4 1/8] drm/amdkfd: Add userptr batch allocation UAPI structures Honglei Huang
2026-02-11 7:15 ` Claude review: " Claude Code Review Bot
2026-02-09 6:10 ` [PATCH v4 2/8] drm/amdkfd: Add user_range_info infrastructure to kgd_mem Honglei Huang
2026-02-11 7:15 ` Claude review: " Claude Code Review Bot
2026-02-09 6:10 ` Honglei Huang [this message]
2026-02-11 7:15 ` Claude review: drm/amdkfd: Implement interval tree for userptr ranges Claude Code Review Bot
2026-02-09 6:10 ` [PATCH v4 4/8] drm/amdkfd: Add batch MMU notifier support Honglei Huang
2026-02-11 7:15 ` Claude review: " Claude Code Review Bot
2026-02-09 6:10 ` [PATCH v4 5/8] drm/amdkfd: Implement batch userptr page management Honglei Huang
2026-02-11 7:15 ` Claude review: " Claude Code Review Bot
2026-02-09 6:10 ` [PATCH v4 6/8] drm/amdkfd: Add batch allocation function and export API Honglei Huang
2026-02-11 7:15 ` Claude review: " Claude Code Review Bot
2026-02-09 6:10 ` [PATCH v4 7/8] drm/amdkfd: Unify userptr cleanup and update paths Honglei Huang
2026-02-11 7:15 ` Claude review: " Claude Code Review Bot
2026-02-09 6:10 ` [PATCH v4 8/8] drm/amdkfd: Wire up batch allocation in ioctl handler Honglei Huang
2026-02-11 7:15 ` Claude review: " Claude Code Review Bot
2026-02-11 7:15 ` Claude review: drm/amdkfd: Add batch userptr allocation support Claude Code Review Bot
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=20260209061047.3881808-4-honglei1.huang@amd.com \
--to=honglei1.huang@amd.com \
--cc=Felix.Kuehling@amd.com \
--cc=Philip.Yang@amd.com \
--cc=Ray.Huang@amd.com \
--cc=airlied@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=daniel@ffwll.ch \
--cc=dmitry.osipenko@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=honghuan@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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