[CI 40/42] drm/xe/svm: Determine a vma is backed by device memory
Oak Zeng
oak.zeng at intel.com
Thu Jun 13 04:24:27 UTC 2024
With system allocator, a userptr can now be back by device
memory also. Introduce a helper function xe_vma_is_devmem
to determine whether a range of vma is backed by device memory.
Cc: Thomas Hellström <thomas.hellstrom at linux.intel.com>
Cc: Matthew Brost <matthew.brost at intel.com>
Cc: Brian Welty <brian.welty at intel.com>
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray at intel.com>
Signed-off-by: Oak Zeng <oak.zeng at intel.com>
---
drivers/gpu/drm/xe/xe_pt.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_pt.c b/drivers/gpu/drm/xe/xe_pt.c
index 91b61fa80acb..691ede2faec5 100644
--- a/drivers/gpu/drm/xe/xe_pt.c
+++ b/drivers/gpu/drm/xe/xe_pt.c
@@ -3,6 +3,7 @@
* Copyright © 2022 Intel Corporation
*/
+#include <linux/hmm.h>
#include "xe_pt.h"
#include "regs/xe_gtt_defs.h"
@@ -578,6 +579,28 @@ static const struct xe_pt_walk_ops xe_pt_stage_bind_ops = {
.pt_entry = xe_pt_stage_bind_entry,
};
+static bool xe_vma_is_devmem(struct xe_vma *vma, u64 start)
+{
+ if (xe_vma_is_userptr(vma)) {
+ struct xe_userptr_vma *uvma = to_userptr_vma(vma);
+ struct drm_hmmptr *hmmptr = &uvma->userptr.hmmptr;
+ u64 offset = start - xe_vma_start(vma);
+ u64 page_idx = offset >> PAGE_SHIFT;
+ u64 hmm_pfn = hmmptr->pfn[page_idx];
+ struct page *page = hmm_pfn_to_page(hmm_pfn);
+
+ /**
+ * FIXME: Assume there is no mixture system memory and device
+ * memory placement in the [start, end) range of vma. We might
+ * need to relook at this in the future.
+ */
+ return is_device_private_page(page);
+ } else {
+ struct xe_bo *bo = xe_vma_bo(vma);
+ return bo && (xe_bo_is_vram(bo) || xe_bo_is_stolen_devmem(bo));
+ }
+}
+
/**
* xe_pt_stage_bind() - Build a disconnected page-table tree for a given address
* range.
@@ -604,8 +627,7 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma, u64 start, u64 end,
{
struct xe_device *xe = tile_to_xe(tile);
struct xe_bo *bo = xe_vma_bo(vma);
- bool is_devmem = !xe_vma_is_userptr(vma) && bo &&
- (xe_bo_is_vram(bo) || xe_bo_is_stolen_devmem(bo));
+ bool is_devmem = xe_vma_is_devmem(vma, start);
struct xe_res_cursor curs;
struct xe_pt_stage_bind_walk xe_walk = {
.base = {
--
2.26.3
More information about the Intel-xe
mailing list