Skip to contentSkip to conversation

Access counter squash

PATCH Superseded Himal Prasad Ghimiray 3 participants 4 messages Sep 10

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Access counter squash

---
 drivers/gpu/drm/xe/Makefile                  |   4 +-
 drivers/gpu/drm/xe/regs/xe_gtt_defs.h        |   1 +
 drivers/gpu/drm/xe/regs/xe_lrc_layout.h      |  10 +
 drivers/gpu/drm/xe/xe_access_counter.c       | 366 +++++++++++++++++++
 drivers/gpu/drm/xe/xe_access_counter.h       |  17 +
 drivers/gpu/drm/xe/xe_access_counter_types.h | 143 ++++++++
 drivers/gpu/drm/xe/xe_device.c               |  30 ++
 drivers/gpu/drm/xe/xe_device.h               |   1 +
 drivers/gpu/drm/xe/xe_device_types.h         |  12 +
 drivers/gpu/drm/xe/xe_exec_queue.c           |  35 +-
 drivers/gpu/drm/xe/xe_exec_queue_types.h     |   9 +
 drivers/gpu/drm/xe/xe_execlist.c             |   2 +-
 drivers/gpu/drm/xe/xe_guc_access_counter.c   |  74 ++++
 drivers/gpu/drm/xe/xe_guc_access_counter.h   |  15 +
 drivers/gpu/drm/xe/xe_guc_ct.c               |   4 +
 drivers/gpu/drm/xe/xe_guc_fwif.h             |   1 +
 drivers/gpu/drm/xe/xe_lrc.c                  |  35 +-
 drivers/gpu/drm/xe/xe_lrc.h                  |   5 +-
 drivers/gpu/drm/xe/xe_pagefault.c            |  78 +---
 drivers/gpu/drm/xe/xe_pt.c                   |  23 ++
 drivers/gpu/drm/xe/xe_svm.c                  | 197 ++++++++--
 drivers/gpu/drm/xe/xe_svm.h                  |  33 ++
 drivers/gpu/drm/xe/xe_trace_bo.h             |  32 +-
 drivers/gpu/drm/xe/xe_usm_queue.h            | 127 +++++++
 drivers/gpu/drm/xe/xe_vm.c                   | 130 ++++++-
 drivers/gpu/drm/xe/xe_vm.h                   |   6 +
 drivers/gpu/drm/xe/xe_vm_types.h             |  11 +
 include/uapi/drm/xe_drm.h                    | 205 +++++++++++
 28 files changed, 1491 insertions(+), 115 deletions(-)
 create mode 100644 drivers/gpu/drm/xe/xe_access_counter.c
 create mode 100644 drivers/gpu/drm/xe/xe_access_counter.h
 create mode 100644 drivers/gpu/drm/xe/xe_access_counter_types.h
 create mode 100644 drivers/gpu/drm/xe/xe_guc_access_counter.c
 create mode 100644 drivers/gpu/drm/xe/xe_guc_access_counter.h
 create mode 100644 drivers/gpu/drm/xe/xe_usm_queue.h
drivers/gpu/drm/xe/Makefile +3 -1
index adc2de37e768..ad1acc67ee0b 100644
@@ -32,7 +32,8 @@ $(obj)/generated/%_device_wa_oob.c $(obj)/generated/%_device_wa_oob.h: $(obj)/xe
 
 # core driver code
 
-xe-y += xe_bb.o \
+xe-y += xe_access_counter.o \
+	xe_bb.o \
 	xe_bo.o \
 	xe_bo_evict.o \
 	xe_dep_scheduler.o \
@@ -73,6 +74,7 @@ xe-y += xe_bb.o \
 	xe_guc_id_mgr.o \
 	xe_guc_klv_helpers.o \
 	xe_guc_log.o \
+	xe_guc_access_counter.o \
 	xe_guc_pagefault.o \
 	xe_guc_pc.o \
 	xe_guc_rc.o \
drivers/gpu/drm/xe/regs/xe_gtt_defs.h +1 -0
index d6bc19ef277b..1286ef346504 100644
@@ -30,6 +30,7 @@
 #define XE_PDE_IPS_64K			BIT_ULL(11)
 
 #define XE_GGTT_PTE_DM			BIT_ULL(1)
+#define XE_PPGTT_PTE_NC			BIT_ULL(5)
 #define XE_USM_PPGTT_PTE_AE		BIT_ULL(10)
 #define XE_PPGTT_PTE_DM			BIT_ULL(11)
 #define XE_PDE_64K			BIT_ULL(6)
drivers/gpu/drm/xe/regs/xe_lrc_layout.h +10 -0
index 6f7abc0181b5..c32e47e87f88 100644
@@ -45,4 +45,14 @@
 #define INDIRECT_CTX_RING_START_UDW	(0x08 + 1)
 #define INDIRECT_CTX_RING_CTL		(0x0a + 1)
 
+/* Fields for CTX_ACC_CTR_THOLD */
+#define ACC_TRIGGER_MASK		REG_GENMASK(15, 0)
+#define ACC_TRIGGER_VAL(x)		REG_FIELD_PREP(ACC_TRIGGER_MASK, x)
+#define ACC_NOTIFY_MASK			REG_GENMASK(31, 16)
+#define ACC_NOTIFY_VAL(x)		REG_FIELD_PREP(ACC_NOTIFY_MASK, x)
+
+/* Fields for CTX_ASID */
+#define ACC_GRANULARITY_MASK            REG_GENMASK(22, 20)
+#define ACC_GRANULARITY_VAL(x)          REG_FIELD_PREP(ACC_GRANULARITY_MASK, x)
+
 #endif
drivers/gpu/drm/xe/xe_access_counter.c new file +366 -0

366 lines not on this page · raw message

drivers/gpu/drm/xe/xe_access_counter.h new file +17 -0
new file mode 100644
index 000000000000..b3a331687f13
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2026 Intel Corporation
+ */
+
+#ifndef _XE_ACCESS_COUNTER_H_
+#define _XE_ACCESS_COUNTER_H_
+
+struct xe_device;
+struct xe_gt;
+struct xe_access_counter;
+
+int xe_access_counter_init(struct xe_device *xe);
+
+int xe_access_counter_handler(struct xe_device *xe, struct xe_access_counter *ac);
+
+#endif
drivers/gpu/drm/xe/xe_access_counter_types.h new file +143 -0

143 lines not on this page · raw message

drivers/gpu/drm/xe/xe_device.c +30 -0
index 205cb4e7f9e8..0bab46f0e4e0 100644
@@ -23,6 +23,7 @@
 #include "instructions/xe_gpu_commands.h"
 #include "regs/xe_gt_regs.h"
 #include "regs/xe_regs.h"
+#include "xe_access_counter.h"
 #include "xe_bo.h"
 #include "xe_bo_evict.h"
 #include "xe_configfs.h"
@@ -997,6 +998,10 @@ int xe_device_probe(struct xe_device *xe)
 	if (err)
 		return err;
 
+	err = xe_access_counter_init(xe);
+	if (err)
+		return err;
+
 	if (xe->tiles->media_gt &&
 	    XE_GT_WA(xe->tiles->media_gt, 15015404425_disable))
 		XE_DEVICE_WA_DISABLE(xe, 15015404425);
@@ -1501,3 +1506,28 @@ struct xe_vm *xe_device_asid_to_vm(struct xe_device *xe, u32 asid)
 
 	return vm;
 }
+
+/**
+ * xe_device_asid_to_fault_vm() - Find FAULT VM from ASID
+ * @xe: the &xe_device
+ * @asid: Address space ID
+ *
+ * Find a FAULTING VM from ASID and take a reference to VM which
+ * caller must drop. Reclaim safe.
+ *
+ * Return: VM on success, ERR_PTR on failure
+ */
+struct xe_vm *xe_device_asid_to_fault_vm(struct xe_device *xe, u32 asid)
+{
+	struct xe_vm *vm;
+
+	down_read(&xe->usm.lock);
+	vm = xa_load(&xe->usm.asid_to_vm, asid);
+	if (vm && xe_vm_in_fault_mode(vm))
+		xe_vm_get(vm);
+	else
+		vm = ERR_PTR(-EINVAL);
+	up_read(&xe->usm.lock);
+
+	return vm;
+}
drivers/gpu/drm/xe/xe_device.h +1 -0
index 6d3d6d5eba29..42ddd4a21b48 100644
@@ -273,6 +273,7 @@ int xe_is_injection_active(void);
 bool xe_is_xe_file(const struct file *file);
 
 struct xe_vm *xe_device_asid_to_vm(struct xe_device *xe, u32 asid);
+struct xe_vm *xe_device_asid_to_fault_vm(struct xe_device *xe, u32 asid);
 
 #ifdef CONFIG_PCI_IOV
 bool xe_device_is_admin_only(const struct xe_device *xe);
drivers/gpu/drm/xe/xe_device_types.h +12 -0
index f88bacf63c83..3d0e3cc54878 100644
@@ -12,6 +12,7 @@
 #include <drm/drm_file.h>
 #include <drm/ttm/ttm_device.h>
 
+#include "xe_access_counter_types.h"
 #include "xe_devcoredump_types.h"
 #include "xe_drm_ras_types.h"
 #include "xe_heci_gsc.h"
@@ -29,6 +30,7 @@
 #include "xe_survivability_mode_types.h"
 #include "xe_sysctrl_types.h"
 #include "xe_tile_types.h"
+#include "xe_usm_queue.h"
 #include "xe_validation.h"
 
 #if IS_ENABLED(CONFIG_DRM_XE_DEBUG)
@@ -336,6 +338,16 @@ struct xe_device {
 		struct xe_pagefault_work pf_workers[XE_PAGEFAULT_WORK_MAX];
 		/** @usm.pf_queue: Page fault queue */
 		struct xe_pagefault_queue pf_queue;
+		/**
+		 * @usm.ac_workers_indx: Round-robin index selecting the
+		 * next access-counter worker to wake.
+		 */
+		u32 ac_workers_indx;
+#define XE_ACCESS_COUNTER_WORKER_COUNT	4
+		/** @usm.ac_workers: Access counter workers */
+		struct xe_ac_worker ac_workers[XE_ACCESS_COUNTER_WORKER_COUNT];
+		/** @usm.ac_queue: Access counter queue */
+		struct xe_usm_queue ac_queue;
 #if IS_ENABLED(CONFIG_DRM_XE_PAGEMAP)
 		/** @usm.dpagemap_shrinker: Shrinker for unused pagemaps */
 		struct drm_pagemap_shrinker *dpagemap_shrinker;
drivers/gpu/drm/xe/xe_exec_queue.c +34 -1
index e63559a2f582..390288e09b40 100644
@@ -436,7 +436,7 @@ static int __xe_exec_queue_init(struct xe_exec_queue *q, u32 exec_queue_flags)
 
 			marker = xe_gt_sriov_vf_wait_valid_ggtt(q->gt);
 
-			lrc = xe_lrc_create(q->hwe, q->vm, q->replay_state,
+			lrc = xe_lrc_create(q, q->hwe, q->vm, q->replay_state,
 					    xe_lrc_ring_size(), q->msix_vec, flags);
 			if (IS_ERR(lrc)) {
 				err = PTR_ERR(lrc);
@@ -1153,6 +1153,38 @@ static int exec_queue_user_ext_check_final(struct xe_exec_queue *q, u64 properti
 	return 0;
 }
 
+static int exec_queue_user_ext_set_acc_param(struct xe_device *xe,
+					     struct xe_exec_queue *q,
+					     u64 extension, u64 *properties)
+{
+	u64 __user *address = u64_to_user_ptr(extension);
+	struct drm_xe_exec_queue_set_acc_param ext;
+	int err;
+
+	if (!xe->info.has_access_counter)
+		return -EINVAL;
+
+	err = copy_from_user(&ext, address, sizeof(ext));
+	if (XE_IOCTL_DBG(xe, err))
+		return -EFAULT;
+
+	if (XE_IOCTL_DBG(xe, ext.pad1 || ext.pad2))
+		return -EINVAL;
+
+	if (XE_IOCTL_DBG(xe, ext.granularity > DRM_XE_ACCESS_COUNTER_GRANULARITY_64M))
+		return -EINVAL;
+
+	if (XE_IOCTL_DBG(xe, ext.notify > ext.trigger))
+		return -EINVAL;
+
+	/* Store access counter parameters in exec queue */
+	q->acc.trigger = ext.trigger;
+	q->acc.notify = ext.notify;
+	q->acc.granularity = ext.granularity;
+
+	return 0;
+}
+
 static int exec_queue_user_ext_set_property(struct xe_device *xe,
 					    struct xe_exec_queue *q,
 					    u64 extension, u64 *properties)
@@ -1199,6 +1231,7 @@ typedef int (*xe_exec_queue_user_extension_fn)(struct xe_device *xe,
 
 static const xe_exec_queue_user_extension_fn exec_queue_user_extension_funcs[] = {
 	[DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY] = exec_queue_user_ext_set_property,
+	[DRM_XE_EXEC_QUEUE_EXTENSION_SET_ACC_PARAM] = exec_queue_user_ext_set_acc_param,
 };
 
 #define MAX_USER_EXTENSIONS	16
drivers/gpu/drm/xe/xe_exec_queue_types.h +9 -0
index 836f88fc0faa..c5777689eead 100644
@@ -265,6 +265,15 @@ struct xe_exec_queue {
 
 	/** @replay_state: GPU hang replay state */
 	void *replay_state;
+	/** @acc: Access counter parameters */
+	struct {
+		/** @acc.trigger: Access counter trigger threshold */
+		u16 trigger;
+		/** @acc.notify: Access counter notify threshold */
+		u16 notify;
+		/** @acc.granularity: Access counter granularity */
+		u8 granularity;
+	} acc;
 
 	/** @ops: submission backend exec queue operations */
 	const struct xe_exec_queue_ops *ops;
drivers/gpu/drm/xe/xe_execlist.c +1 -1
index a36db39dcda8..14d5f90e234d 100644
@@ -259,7 +259,7 @@ struct xe_execlist_port *xe_execlist_port_create(struct xe_device *xe,
 
 	port->hwe = hwe;
 
-	port->lrc = xe_lrc_create(hwe, NULL, NULL, SZ_16K, XE_IRQ_DEFAULT_MSIX, 0);
+	port->lrc = xe_lrc_create(NULL, hwe, NULL, NULL, SZ_16K, XE_IRQ_DEFAULT_MSIX, 0);
 	if (IS_ERR(port->lrc)) {
 		err = PTR_ERR(port->lrc);
 		goto err;
drivers/gpu/drm/xe/xe_guc_access_counter.c new file +74 -0

74 lines not on this page · raw message

drivers/gpu/drm/xe/xe_guc_access_counter.h new file +15 -0
new file mode 100644
index 000000000000..1ac8e76398d2
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2025 Intel Corporation
+ */
+
+#ifndef _XE_GUC_ACCESS_COUNTER_H_
+#define _XE_GUC_ACCESS_COUNTER_H_
+
+#include <linux/types.h>
+
+struct xe_guc;
+
+int xe_guc_access_counter_handler(struct xe_guc *guc, u32 *msg, u32 len);
+
+#endif
drivers/gpu/drm/xe/xe_guc_ct.c +4 -0
index 5c4733da385c..3068cbbff8c7 100644
@@ -26,6 +26,7 @@
 #include "xe_gt_sriov_pf_monitor.h"
 #include "xe_guc.h"
 #include "xe_guc_log.h"
+#include "xe_guc_access_counter.h"
 #include "xe_guc_pagefault.h"
 #include "xe_guc_relay.h"
 #include "xe_guc_submit.h"
@@ -1753,6 +1754,9 @@ static int process_g2h_msg(struct xe_guc_ct *ct, u32 *msg, u32 len)
 	case XE_GUC_ACTION_REPORT_PAGE_FAULT_REQ_DESC:
 		ret = xe_guc_pagefault_handler(guc, payload, adj_len);
 		break;
+	case XE_GUC_ACTION_ACCESS_COUNTER_NOTIFY:
+		ret = xe_guc_access_counter_handler(guc, payload, adj_len);
+		break;
 	case XE_GUC_ACTION_TLB_INVALIDATION_DONE:
 		ret = xe_guc_tlb_inval_done_handler(guc, payload, adj_len);
 		break;
drivers/gpu/drm/xe/xe_guc_fwif.h +1 -0
index 971b850f2136..a2a77b252d3e 100644
@@ -299,6 +299,7 @@ struct xe_guc_acc_desc {
 #define ACC_TRIGGER	0
 #define ACC_NOTIFY	1
 #define ACC_SUBG_LO	GENMASK(31, 1)
+#define ACC_SUBG_LO_WIDTH 31
 
 	u32 dw1;
 #define ACC_SUBG_HI	BIT(0)
drivers/gpu/drm/xe/xe_lrc.c +26 -9
index f1cf1463f1b2..991a17f283de 100644
@@ -1516,8 +1516,10 @@ static void xe_lrc_set_gpgpu_preemption_level(struct xe_lrc *lrc, struct xe_gt *
 	xe_lrc_write_ctx_reg(lrc, CTX_CS_CHICKEN1, val);
 }
 
-static int xe_lrc_ctx_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe, struct xe_vm *vm,
-			   void *replay_state, u16 msix_vec, u32 init_flags)
+static int xe_lrc_ctx_init(struct xe_lrc *lrc, struct xe_exec_queue *q,
+			   struct xe_hw_engine *hwe, struct xe_vm *vm,
+			   void *replay_state,
+			   u16 msix_vec, u32 init_flags)
 {
 	struct xe_gt *gt = hwe->gt;
 	struct xe_tile *tile = gt_to_tile(gt);
@@ -1616,8 +1618,20 @@ static int xe_lrc_ctx_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe, struct
 		xe_lrc_write_ctx_reg(lrc, CTX_QUEUE_TIMESTAMP_UDW, 0);
 	}
 
-	if (xe->info.has_asid && vm)
-		xe_lrc_write_ctx_reg(lrc, CTX_ASID, vm->usm.asid);
+	if (xe->info.has_asid && vm) {
+		u32 asid;
+
+		if (q)
+			asid = vm->usm.asid | ACC_GRANULARITY_VAL(q->acc.granularity);
+		else
+			asid = vm->usm.asid;
+		xe_lrc_write_ctx_reg(lrc, CTX_ASID, asid);
+	}
+
+	if (q && xe->info.has_access_counter && vm)
+		xe_lrc_write_ctx_reg(lrc, CTX_ACC_CTR_THOLD,
+				     ACC_NOTIFY_VAL(q->acc.notify) |
+				     ACC_TRIGGER_VAL(q->acc.trigger));
 
 	if (GRAPHICS_VER(xe) >= 20 && hwe->class == XE_ENGINE_CLASS_RENDER)
 		xe_lrc_set_gpgpu_preemption_level(lrc, gt);
@@ -1662,7 +1676,8 @@ static int xe_lrc_ctx_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe, struct
 	return err;
 }
 
-static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe, struct xe_vm *vm,
+static int xe_lrc_init(struct xe_lrc *lrc, struct xe_exec_queue *q,
+		       struct xe_hw_engine *hwe, struct xe_vm *vm,
 		       void *replay_state, u32 ring_size, u16 msix_vec, u32 init_flags)
 {
 	struct xe_gt *gt = hwe->gt;
@@ -1718,7 +1733,7 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe, struct xe_v
 	xe_hw_fence_ctx_init(&lrc->fence_ctx, hwe->gt,
 			     hwe->fence_irq, hwe->name);
 
-	err = xe_lrc_ctx_init(lrc, hwe, vm, replay_state, msix_vec, init_flags);
+	err = xe_lrc_ctx_init(lrc, q, hwe, vm, replay_state, msix_vec, init_flags);
 	if (err)
 		goto err_lrc_finish;
 
@@ -1734,6 +1749,7 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe, struct xe_v
 
 /**
  * xe_lrc_create - Create a LRC
+ * @q: Exec queue (can be NULL for kernel queues)
  * @hwe: Hardware Engine
  * @vm: The VM (address space)
  * @replay_state: GPU hang replay state
@@ -1746,8 +1762,9 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe, struct xe_v
  * Return pointer to created LRC upon success and an error pointer
  * upon failure.
  */
-struct xe_lrc *xe_lrc_create(struct xe_hw_engine *hwe, struct xe_vm *vm,
-			     void *replay_state, u32 ring_size, u16 msix_vec, u32 flags)
+struct xe_lrc *xe_lrc_create(struct xe_exec_queue *q, struct xe_hw_engine *hwe,
+			     struct xe_vm *vm, void *replay_state, u32 ring_size,
+			     u16 msix_vec, u32 flags)
 {
 	struct xe_lrc *lrc;
 	int err;
@@ -1756,7 +1773,7 @@ struct xe_lrc *xe_lrc_create(struct xe_hw_engine *hwe, struct xe_vm *vm,
 	if (!lrc)
 		return ERR_PTR(-ENOMEM);
 
-	err = xe_lrc_init(lrc, hwe, vm, replay_state, ring_size, msix_vec, flags);
+	err = xe_lrc_init(lrc, q, hwe, vm, replay_state, ring_size, msix_vec, flags);
 	if (err) {
 		kfree(lrc);
 		return ERR_PTR(err);
drivers/gpu/drm/xe/xe_lrc.h +3 -2
index a8ff4e59a1f4..006b3628f360 100644
@@ -61,8 +61,9 @@ struct xe_lrc_snapshot {
 #define XE_LRC_CREATE_USER_CTX		BIT(2)
 #define XE_LRC_DISABLE_STATE_CACHE_PERF_FIX	BIT(3)
 
-struct xe_lrc *xe_lrc_create(struct xe_hw_engine *hwe, struct xe_vm *vm,
-			     void *replay_state, u32 ring_size, u16 msix_vec, u32 flags);
+struct xe_lrc *xe_lrc_create(struct xe_exec_queue *q, struct xe_hw_engine *hwe,
+			     struct xe_vm *vm, void *replay_state,
+			     u32 ring_size, u16 msix_vec, u32 flags);
 void xe_lrc_destroy(struct kref *ref);
 
 /**
drivers/gpu/drm/xe/xe_pagefault.c +14 -64

119 lines not on this page · raw message

drivers/gpu/drm/xe/xe_pt.c +23 -0
index 7fb2fe1f826c..70450e59241f 100644
@@ -800,6 +800,7 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma,
 		.clear_pt = clear_pt,
 	};
 	struct xe_pt *pt = vm->pt_root[tile->id];
+	struct drm_gpusvm_range_flags range_flags;
 	int ret;
 	bool is_purged = false;
 
@@ -862,6 +863,28 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma,
 			XE_USM_PPGTT_PTE_AE : 0;
 	}
 
+	if (!xe_vma_supports_access_ctr(xe, vma, tile)) {
+		xe_walk.default_vram_pte |= XE_PPGTT_PTE_NC;
+		xe_walk.default_system_pte |= XE_PPGTT_PTE_NC;
+	}
+
+	if (range) {
+		/*
+		 * Always set NC (no-count) on VRAM PTEs for SVM ranges so
+		 * this GPU does not generate access counter events for memory
+		 * it is already responsible for.  Today default_vram_pte
+		 * covers only local VRAM; once UAL lands, remote-device VRAM
+		 * pages will also flow through default_vram_pte — NC remains
+		 * the right setting there too, as the owning device handles
+		 * AC for its own local memory.  Update this comment when UAL
+		 * support is added and adjust if the semantics change.
+		 */
+		xe_walk.default_vram_pte |= XE_PPGTT_PTE_NC;
+		range_flags.__flags = READ_ONCE(range->base.flags.__flags);
+		if (!range_flags.migrate_devmem)
+			xe_walk.default_system_pte |= XE_PPGTT_PTE_NC;
+	}
+
 	xe_walk.default_vram_pte |= XE_PPGTT_PTE_DM;
 	xe_walk.dma_offset = (bo && !is_purged) ? vram_region_gpu_offset(bo->ttm.resource) : 0;
 	if (!range)
drivers/gpu/drm/xe/xe_svm.c +165 -32

312 lines not on this page · raw message

drivers/gpu/drm/xe/xe_svm.h +33 -0
index 2ef4ef026ccd..cfc6eb840ca0 100644
@@ -28,6 +28,14 @@ struct xe_vm;
 struct xe_vma;
 struct xe_vram_region;
 
+/** struct xe_svm_range_setup_flags -flags for range setup */
+struct xe_svm_range_setup_flags {
+	/** @atomic: is atomic access */
+	u32 atomic : 1;
+	/** @acc_ctr_trigger: is called by access ctr trigger */
+	u32 acc_ctr_trigger : 1;
+};
+
 /** struct xe_svm_range - SVM range */
 struct xe_svm_range {
 	/** @base: base drm_gpusvm_range */
@@ -109,6 +117,12 @@ void xe_svm_fini(struct xe_vm *vm);
 
 void xe_svm_close(struct xe_vm *vm);
 
+int xe_svm_range_setup(struct xe_vm *vm, struct xe_vma *vma,
+		       struct xe_pagefault *pf, struct xe_gt *gt,
+		       u64 addr, struct xe_svm_range_setup_flags flags);
+
+struct xe_svm_range *xe_svm_range_find_first(struct xe_vm *vm, u64 start, u64 end);
+
 int xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
 			    struct xe_pagefault *pf, struct xe_gt *gt,
 			    u64 fault_addr, bool atomic);
@@ -270,6 +284,11 @@ struct xe_svm_range {
 	u32 tile_invalidated;
 };
 
+struct xe_svm_range_setup_flags {
+	u32 atomic : 1;
+	u32 acc_ctr_trigger : 1;
+};
+
 static inline void xe_svm_range_put(struct xe_svm_range *range)
 {
 }
@@ -318,6 +337,20 @@ int xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
 	return 0;
 }
 
+static inline
+int xe_svm_range_setup(struct xe_vm *vm, struct xe_vma *vma,
+		       struct xe_pagefault *pf, struct xe_gt *gt,
+		       u64 addr, struct xe_svm_range_setup_flags flags)
+{
+	return 0;
+}
+
+static inline
+struct xe_svm_range *xe_svm_range_find_first(struct xe_vm *vm, u64 start, u64 end)
+{
+	return NULL;
+}
+
 static inline
 bool xe_svm_has_mapping(struct xe_vm *vm, u64 start, u64 end)
 {
drivers/gpu/drm/xe/xe_trace_bo.h +29 -3
index 86323cf3be2c..eae5a5d0dbdc 100644
@@ -12,6 +12,7 @@
 #include <linux/tracepoint.h>
 #include <linux/types.h>
 
+#include "xe_access_counter_types.h"
 #include "xe_bo.h"
 #include "xe_bo_types.h"
 #include "xe_vm.h"
@@ -125,9 +126,34 @@ DEFINE_EVENT(xe_vma, xe_vma_pagefault,
 	     TP_ARGS(vma)
 );
 
-DEFINE_EVENT(xe_vma, xe_vma_acc,
-	     TP_PROTO(struct xe_vma *vma),
-	     TP_ARGS(vma)
+TRACE_EVENT(xe_vma_acc,
+	    TP_PROTO(struct xe_vma *vma, u8 counter_type),
+	    TP_ARGS(vma, counter_type),
+
+	    TP_STRUCT__entry(
+		     __string(dev, __dev_name_vma(vma))
+		     __field(struct xe_vma *, vma)
+		     __field(struct xe_vm *, vm)
+		     __field(u32, asid)
+		     __field(u64, start)
+		     __field(u64, end)
+		     __field(u8, counter_type)
+		     ),
+
+	    TP_fast_assign(
+		   __assign_str(dev);
+		   __entry->vma = vma;
+		   __entry->vm = xe_vma_vm(vma);
+		   __entry->asid = xe_vma_vm(vma)->usm.asid;
+		   __entry->start = xe_vma_start(vma);
+		   __entry->end = xe_vma_end(vma) - 1;
+		   __entry->counter_type = counter_type;
+		   ),
+
+	    TP_printk("dev=%s, vma=%p, vm=%p, asid=0x%05x, start=0x%012llx, end=0x%012llx, type=%s",
+		      __get_str(dev), __entry->vma, __entry->vm,
+		      __entry->asid, __entry->start, __entry->end,
+		      __entry->counter_type == XE_ACCESS_COUNTER_TYPE_NOTIFY ? "NOTIFY" : "TRIGGER")
 );
 
 DEFINE_EVENT(xe_vma, xe_vma_bind,
drivers/gpu/drm/xe/xe_usm_queue.h new file +127 -0

127 lines not on this page · raw message

drivers/gpu/drm/xe/xe_vm.c +128 -2

178 lines not on this page · raw message

drivers/gpu/drm/xe/xe_vm.h +6 -0
index c5b900f38ded..2a5ae0aacc97 100644
@@ -185,6 +185,9 @@ struct xe_vma *xe_vm_find_vma_by_addr(struct xe_vm *vm, u64 page_addr);
 
 int xe_vma_need_vram_for_atomic(struct xe_device *xe, struct xe_vma *vma, bool is_atomic);
 
+bool xe_vma_supports_access_ctr(struct xe_device *xe, struct xe_vma *vma,
+				struct xe_tile *tile);
+
 int xe_vm_alloc_madvise_vma(struct xe_vm *vm, uint64_t addr, uint64_t size);
 
 int xe_vm_alloc_cpu_addr_mirror_vma(struct xe_vm *vm, uint64_t addr, uint64_t size);
@@ -281,6 +284,9 @@ static inline void xe_vm_reactivate_rebind(struct xe_vm *vm)
 
 int xe_vm_lock_vma(struct drm_exec *exec, struct xe_vma *vma);
 
+int xe_vma_lock_and_validate(struct drm_exec *exec, struct xe_vma *vma,
+			     struct xe_vram_region *vram, bool need_vram_move);
+
 int xe_vm_validate_rebind(struct xe_vm *vm, struct drm_exec *exec,
 			  unsigned int num_fences);
 
drivers/gpu/drm/xe/xe_vm_types.h +11 -0
index 648031e64145..a88e20329e9f 100644
@@ -52,6 +52,7 @@ struct xe_vm_pgtable_update_op;
 #define XE_VMA_DUMPABLE		(DRM_GPUVA_USERBITS << 8)
 #define XE_VMA_SYSTEM_ALLOCATOR	(DRM_GPUVA_USERBITS << 9)
 #define XE_VMA_MADV_AUTORESET	(DRM_GPUVA_USERBITS << 10)
+#define XE_VMA_MIGRATE_ON_ACC	(DRM_GPUVA_USERBITS << 11)
 
 /**
  * struct xe_vma_mem_attr - memory attributes associated with vma
@@ -175,6 +176,16 @@ struct xe_vma {
 	 */
 	struct xe_user_fence *ufence;
 
+	/**
+	 * @ac_move_fence: Fence for an in-progress access-counter triggered
+	 * migration/rebind. Written by the AC service and read+cleared by the
+	 * page-fault handler, both under down_read(&vm->lock) + @fault_lock;
+	 * any access under the read lock MUST also hold @fault_lock. The final
+	 * put on VMA destroy (xe_vma_destroy_late()) is unlocked - safe as no
+	 * other reference to the VMA remains.
+	 */
+	struct dma_fence *ac_move_fence;
+
 	/**
 	 * @attr: The attributes of vma which determines the migration policy
 	 * and encoding of the PTEs for this vma.
include/uapi/drm/xe_drm.h +205 -0

229 lines not on this page · raw message

Signature · 1 line
2.43.0
#1 lore raw

✗ CI.checkpatch: warning for Access counter squash (rev2)

== Series Details ==

== Series Details ==

Series: Access counter squash (rev2)
URL : https://patchwork.freedesktop.org/series/173728/
State : warning

== Summary ==

+ KERNEL=/kernel
+ git clone https://gitlab.freedesktop.org/drm/maintainer-tools mt Cloning into 'mt'...
warning: redirecting to https://gitlab.freedesktop.org/drm/maintainer-tools.git/
+ git -C mt rev-list -n1 origin/master d875049d2b299159a272bd5151994970cdcd1e31
+ cd /kernel
+ git config --global --add safe.directory /kernel
+ git log -n1
commit 16386dad08dfecbf71a362bcb31ac8e4e939c65b

Author: Himal Prasad Ghimiray <[email protected]>
Date:   Thu Sep 10 15:53:59 2026 +0530

Access counter squash
+ /mt/dim checkpatch 03ba909762f8b1e4c1a82fb67232987fc40e6163 drm-intel 16386dad08df Access counter squash
-:8: WARNING:COMMIT_MESSAGE: Missing commit description - Add an appropriate one

-:61: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #61:
new file mode 100644

-:1626: CHECK:OPEN_ENDED_LINE: Lines should not end with a '(' #1626: FILE: drivers/gpu/drm/xe/xe_trace_bo.h:133:
+ TP_STRUCT__entry(

-:1636: CHECK:OPEN_ENDED_LINE: Lines should not end with a '(' #1636: FILE: drivers/gpu/drm/xe/xe_trace_bo.h:143:
+ TP_fast_assign(

-:2265: ERROR:MISSING_SIGN_OFF: Missing Signed-off-by: line(s)

total: 1 errors, 2 warnings, 2 checks, 2063 lines checked

#2 lore raw

✗ CI.KUnit: failure for Access counter squash (rev2)

In reply to Himal Prasad Ghimiray
== Series Details ==

== Series Details ==

Series: Access counter squash (rev2)
URL : https://patchwork.freedesktop.org/series/173728/
State : failure

== Summary ==

+ trap cleanup EXIT
+ kunitconfigs=('/kernel/drivers/gpu/tests/.kunitconfig' '/kernel/drivers/gpu/drm/xe/.kunitconfig' '/kernel/drivers/gpu/drm/tests/.kunitconfig' '/kernel/drivers/gpu/drm/ttm/tests/.kunitconfig' '/kernel/drivers/dma-buf/.kunitconfig')
+ for kcfg in "${kunitconfigs[@]}"
+ [[ ! -f /kernel/drivers/gpu/tests/.kunitconfig ]]
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/tests/.kunitconfig
[10:26:59] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:

$ make ARCH=um O=.kunit olddefconfig
[10:27:03] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=48
[10:27:23] Starting KUnit Kernel (1/1)...
[10:27:23] ============================================================
Running tests with:
$ .kunit/linux kunit.enable=1 mem=1G console=tty kunit_shutdown=halt
[10:27:24] ============= refcount_interrupt (4 subtests) ==============
[10:27:24] [PASSED] test_single_irq_change
[10:27:24] [PASSED] test_nested_irq_change
[10:27:24] [PASSED] test_multiple_irq_change
[10:27:24] [PASSED] test_irq_save
[10:27:24] =============== [PASSED] refcount_interrupt ================
[10:27:24] ================= gpu_buddy (14 subtests) ==================
[10:27:24] [PASSED] gpu_test_buddy_alloc_limit
[10:27:24] [PASSED] gpu_test_buddy_alloc_optimistic
[10:27:24] [PASSED] gpu_test_buddy_alloc_pessimistic
[10:27:24] [PASSED] gpu_test_buddy_alloc_pathological
[10:27:24] [PASSED] gpu_test_buddy_alloc_contiguous
[10:27:24] [PASSED] gpu_test_buddy_alloc_clear
[10:27:24] [PASSED] gpu_test_buddy_alloc_range
[10:27:24] [PASSED] gpu_test_buddy_alloc_range_bias
[10:27:25] [PASSED] gpu_test_buddy_fragmentation_performance
[10:27:25] [PASSED] gpu_test_buddy_dirty_tracker_performance
[10:27:25] [PASSED] gpu_test_buddy_alloc_exceeds_max_order
[10:27:25] [PASSED] gpu_test_buddy_offset_aligned_allocation
[10:27:25] [PASSED] gpu_test_buddy_subtree_offset_alignment_stress
[10:27:25] [PASSED] gpu_test_buddy_addr_to_block
[10:27:25] ==================== [PASSED] gpu_buddy ====================
[10:27:25] ============================================================
[10:27:25] Testing complete. Ran 18 tests: passed: 18
[10:27:25] Elapsed time: 26.710s total, 4.424s configuring, 20.368s building, 1.871s running

+ for kcfg in "${kunitconfigs[@]}"
+ [[ ! -f /kernel/drivers/gpu/drm/xe/.kunitconfig ]]
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig ERROR:root:In file included from <command-line>:
../drivers/gpu/drm/xe/xe_pt.c: In function ‘xe_pt_stage_bind’:
../drivers/gpu/drm/xe/xe_pt.c:883:60: error: ‘struct <anonymous>’ has no member named ‘flags’
883 | range_flags.__flags = READ_ONCE(range->base.flags.__flags);
| ^
./../include/linux/compiler_types.h:682:23: note: in definition of macro ‘__compiletime_assert’

  682 |                 if (!(condition))                                       \
      |                       ^~~~~~~~~
./../include/linux/compiler_types.h:702:9: note: in expansion of macro ‘_compiletime_assert’
  702 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
      |         ^~~~~~~~~~~~~~~~~~~
../include/asm-generic/rwonce.h:36:9: note: in expansion of macro ‘compiletime_assert’
   36 |         compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long),  \
      |         ^~~~~~~~~~~~~~~~~~
../include/asm-generic/rwonce.h:36:28: note: in expansion of macro ‘__native_word’
   36 |         compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long),  \
      |                            ^~~~~~~~~~~~~
../include/asm-generic/rwonce.h:49:9: note: in expansion of macro ‘compiletime_assert_rwonce_type’
   49 |         compiletime_assert_rwonce_type(x);                              \
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../drivers/gpu/drm/xe/xe_pt.c:883:39: note: in expansion of macro ‘READ_ONCE’
883 | range_flags.__flags = READ_ONCE(range->base.flags.__flags);
| ^~~~~~~~~
../drivers/gpu/drm/xe/xe_pt.c:883:60: error: ‘struct <anonymous>’ has no member named ‘flags’
883 | range_flags.__flags = READ_ONCE(range->base.flags.__flags);
| ^
./../include/linux/compiler_types.h:682:23: note: in definition of macro ‘__compiletime_assert’

  682 |                 if (!(condition))                                       \
      |                       ^~~~~~~~~
./../include/linux/compiler_types.h:702:9: note: in expansion of macro ‘_compiletime_assert’
  702 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
      |         ^~~~~~~~~~~~~~~~~~~
../include/asm-generic/rwonce.h:36:9: note: in expansion of macro ‘compiletime_assert’
   36 |         compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long),  \
      |         ^~~~~~~~~~~~~~~~~~
../include/asm-generic/rwonce.h:36:28: note: in expansion of macro ‘__native_word’
   36 |         compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long),  \
      |                            ^~~~~~~~~~~~~
../include/asm-generic/rwonce.h:49:9: note: in expansion of macro ‘compiletime_assert_rwonce_type’
   49 |         compiletime_assert_rwonce_type(x);                              \
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../drivers/gpu/drm/xe/xe_pt.c:883:39: note: in expansion of macro ‘READ_ONCE’
883 | range_flags.__flags = READ_ONCE(range->base.flags.__flags);
| ^~~~~~~~~
../drivers/gpu/drm/xe/xe_pt.c:883:60: error: ‘struct <anonymous>’ has no member named ‘flags’
883 | range_flags.__flags = READ_ONCE(range->base.flags.__flags);
| ^
./../include/linux/compiler_types.h:682:23: note: in definition of macro ‘__compiletime_assert’

  682 |                 if (!(condition))                                       \
      |                       ^~~~~~~~~
./../include/linux/compiler_types.h:702:9: note: in expansion of macro ‘_compiletime_assert’
  702 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
      |         ^~~~~~~~~~~~~~~~~~~
../include/asm-generic/rwonce.h:36:9: note: in expansion of macro ‘compiletime_assert’
   36 |         compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long),  \
      |         ^~~~~~~~~~~~~~~~~~
../include/asm-generic/rwonce.h:36:28: note: in expansion of macro ‘__native_word’
   36 |         compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long),  \
      |                            ^~~~~~~~~~~~~
../include/asm-generic/rwonce.h:49:9: note: in expansion of macro ‘compiletime_assert_rwonce_type’
   49 |         compiletime_assert_rwonce_type(x);                              \
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../drivers/gpu/drm/xe/xe_pt.c:883:39: note: in expansion of macro ‘READ_ONCE’
883 | range_flags.__flags = READ_ONCE(range->base.flags.__flags);
| ^~~~~~~~~
../drivers/gpu/drm/xe/xe_pt.c:883:60: error: ‘struct <anonymous>’ has no member named ‘flags’
883 | range_flags.__flags = READ_ONCE(range->base.flags.__flags);
| ^
./../include/linux/compiler_types.h:682:23: note: in definition of macro ‘__compiletime_assert’

  682 |                 if (!(condition))                                       \
      |                       ^~~~~~~~~
./../include/linux/compiler_types.h:702:9: note: in expansion of macro ‘_compiletime_assert’
  702 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
      |         ^~~~~~~~~~~~~~~~~~~
../include/asm-generic/rwonce.h:36:9: note: in expansion of macro ‘compiletime_assert’
   36 |         compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long),  \
      |         ^~~~~~~~~~~~~~~~~~
../include/asm-generic/rwonce.h:36:28: note: in expansion of macro ‘__native_word’
   36 |         compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long),  \
      |                            ^~~~~~~~~~~~~
../include/asm-generic/rwonce.h:49:9: note: in expansion of macro ‘compiletime_assert_rwonce_type’
   49 |         compiletime_assert_rwonce_type(x);                              \
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../drivers/gpu/drm/xe/xe_pt.c:883:39: note: in expansion of macro ‘READ_ONCE’
883 | range_flags.__flags = READ_ONCE(range->base.flags.__flags);
| ^~~~~~~~~
../drivers/gpu/drm/xe/xe_pt.c:883:60: error: ‘struct <anonymous>’ has no member named ‘flags’
883 | range_flags.__flags = READ_ONCE(range->base.flags.__flags);
| ^
./../include/linux/compiler_types.h:682:23: note: in definition of macro ‘__compiletime_assert’

  682 |                 if (!(condition))                                       \
      |                       ^~~~~~~~~
./../include/linux/compiler_types.h:702:9: note: in expansion of macro ‘_compiletime_assert’
  702 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
      |         ^~~~~~~~~~~~~~~~~~~
../include/asm-generic/rwonce.h:36:9: note: in expansion of macro ‘compiletime_assert’
   36 |         compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long),  \
      |         ^~~~~~~~~~~~~~~~~~
../include/asm-generic/rwonce.h:49:9: note: in expansion of macro ‘compiletime_assert_rwonce_type’
   49 |         compiletime_assert_rwonce_type(x);                              \
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../drivers/gpu/drm/xe/xe_pt.c:883:39: note: in expansion of macro ‘READ_ONCE’
883 | range_flags.__flags = READ_ONCE(range->base.flags.__flags);
| ^~~~~~~~~
../drivers/gpu/drm/xe/xe_pt.c:883:60: error: ‘struct <anonymous>’ has no member named ‘flags’
883 | range_flags.__flags = READ_ONCE(range->base.flags.__flags);
| ^
./../include/linux/compiler_types.h:626:27: note: in definition of macro ‘__unqual_scalar_typeof’
626 | _Generic((x), \
| ^
../include/asm-generic/rwonce.h:50:9: note: in expansion of macro ‘__READ_ONCE’

   50 |         __READ_ONCE(x);                                                 \
      |         ^~~~~~~~~~~

../drivers/gpu/drm/xe/xe_pt.c:883:39: note: in expansion of macro ‘READ_ONCE’
883 | range_flags.__flags = READ_ONCE(range->base.flags.__flags);
| ^~~~~~~~~
In file included from ./arch/x86/include/generated/asm/rwonce.h:1,

                 from ../include/linux/compiler.h:369,
                 from ../include/linux/export.h:5,
                 from ../include/linux/linkage.h:7,
                 from ../include/linux/preempt.h:10,
                 from ../include/linux/spinlock.h:56,
                 from ../include/linux/kref.h:16,
                 from ../drivers/gpu/drm/xe/xe_page_reclaim.h:9,
                 from ../drivers/gpu/drm/xe/xe_pt_types.h:11,
                 from ../drivers/gpu/drm/xe/xe_pt.h:10,
                 from ../drivers/gpu/drm/xe/xe_pt.c:6:

../drivers/gpu/drm/xe/xe_pt.c:883:60: error: ‘struct <anonymous>’ has no member named ‘flags’
883 | range_flags.__flags = READ_ONCE(range->base.flags.__flags);
| ^
../include/asm-generic/rwonce.h:44:73: note: in definition of macro ‘__READ_ONCE’
44 | #define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)&(x))
| ^
../drivers/gpu/drm/xe/xe_pt.c:883:39: note: in expansion of macro ‘READ_ONCE’
883 | range_flags.__flags = READ_ONCE(range->base.flags.__flags);
| ^~~~~~~~~
make[7]: *** [../scripts/Makefile.build:290: drivers/gpu/drm/xe/xe_pt.o] Error 1 make[7]: *** Waiting for unfinished jobs....
make[6]: *** [../scripts/Makefile.build:551: drivers/gpu/drm/xe] Error 2 make[5]: *** [../scripts/Makefile.build:551: drivers/gpu/drm] Error 2
make[4]: *** [../scripts/Makefile.build:551: drivers/gpu] Error 2
make[3]: *** [../scripts/Makefile.build:551: drivers] Error 2
make[2]: *** [/kernel/Makefile:2229: .] Error 2
make[1]: *** [/kernel/Makefile:248: __sub-make] Error 2
make: *** [Makefile:248: __sub-make] Error 2

[10:27:25] Configuring KUnit Kernel ...
Regenerating .config ...
Populating config with:

$ make ARCH=um O=.kunit olddefconfig
[10:27:27] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=48
+ cleanup
++ stat -c %u:%g /kernel
+ chown -R 1003:1003 /kernel
#3 lore raw
In reply to Himal Prasad Ghimiray
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [High] Leaked `drm_gpusvm_range` reference due to empty `xe_svm_range_put()` stub. - [High]…

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Leaked drm_gpusvm_range reference due to empty xe_svm_range_put() stub.
- [High] MIGRATE_ON_ACCESS_COUNTER unconditionally blocks required VRAM migrations, breaking device atomics.
- [High] Advisory access counter queue overflow crashes the GuC CT (GPU reset).
- [Medium] Incorrect page_va calculation masks out the subchunk index, corrupting the access counter window boundaries.
- [Medium] Dead code and premature -EACCES abort in SVM range setup for access counters.
--

commit 8ecf8e94242179d64ad6f6e867a90856cd275a2f
Author: Himal Prasad Ghimiray <[email protected]>

Access counter squash

This patch introduces access counter infrastructure for Xe, including USM queue processing, GuC CT handlers, and SVM integration for page migration.

Quoted 5 lines
drivers/gpu/drm/xe/xe_access_counter.c new file +0 -0
new file mode 100644
index 0000000000000..ed1ed6091ac5b

[ ... ]

Quoted 11 lines
drivers/gpu/drm/xe/xe_access_counter.c new file +11 -0
+int xe_access_counter_handler(struct xe_device *xe, struct xe_access_counter *ac)
+{
+	struct xe_usm_queue *ac_queue = &xe->usm.ac_queue;
+	int idx;
+	unsigned long flags;
+	bool full;
+
+	spin_lock_irqsave(&ac_queue->lock, flags);
+	idx = xe_access_counter_work_index(xe);
+	full = xe_usm_queue_full(ac_queue);
+	if (!full) {

drivers/gpu/drm/xe/xe_access_counter.c line 366

Quoted 10 lines
drivers/gpu/drm/xe/xe_access_counter.c new file +10 -0
+		xe_usm_queue_push(ac_queue, ac);
+		queue_work(xe->usm.pagefault_wq, &xe->usm.ac_workers[idx].work);
+	} else {
+		drm_warn(&xe->drm,
+			 "AccessCounter Queue full, shouldn't be possible\n");
+	}
+	spin_unlock_irqrestore(&ac_queue->lock, flags);
+
+	return full ? -ENOSPC : 0;
+}

[Severity: High]
Does this cause an unnecessary GPU reset on advisory queue overflow?

If xe_access_counter_handler() returns -ENOSPC because the 128-entry advisory queue is full, that error propagates up to process_g2h_msg() via xe_guc_access_counter_handler().

In process_g2h_msg() in xe_guc_ct.c, a non-zero return value triggers CT_DEAD(), which forces a GPU reset:

process_g2h_msg() {
    ...
    if (ret) {
        xe_gt_err(gt, "G2H action %#04x failed...");
        CT_DEAD(ct, NULL, PROCESS_FAILED);
    }
}

Since access counter events are purely advisory, could we safely ignore the -ENOSPC error rather than crashing the GuC CT?

Quoted 5 lines
drivers/gpu/drm/xe/xe_guc_access_counter.c new file +0 -0
new file mode 100644
index 0000000000000..7e9b835e1ed67

[ ... ]

drivers/gpu/drm/xe/xe_guc_access_counter.c line 23

Quoted 7 lines
drivers/gpu/drm/xe/xe_guc_access_counter.c new file +7 -0
+static u64 xe_guc_access_counter_page_va(struct xe_device *xe, u64 addr, u8 gran)
+{
+	u64 gran_size = xe_access_counter_granularity_to_size(gran);
+	u64 sub_gran_size = gran_size / 32;
+	u64 region_base = ALIGN_DOWN(addr, gran_size);
+	u64 offset_in_subchunk = addr & (sub_gran_size - 1);
+	u64 page_va = region_base + offset_in_subchunk;

[Severity: Medium]
Does this calculation drop the subchunk index from the starting virtual address?

By doing addr & (sub_gran_size - 1), offset_in_subchunk only retains the offset within the subchunk itself. The bits representing the subchunk index (between sub_gran_size and gran_size) are masked out.

This causes page_va to point to the wrong virtual address, and subsequently shifts the entire access counter window when xe_guc_access_counter_handler() computes gran_end = page_va + gran_size. Should this preserve the full offset within the granularity window?

Quoted 4 lines
drivers/gpu/drm/xe/xe_svm.c +0 -0
index 6c3033fc4db73..2aafeedf05147 100644

[ ... ]

Quoted 14 lines
drivers/gpu/drm/xe/xe_svm.c +5 -2
@@ -1331,13 +1369,32 @@ static int __xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
 
 	if (xe_svm_range_is_valid(range, tile, ctx.devmem_only, dpagemap)) {
 		xe_svm_range_valid_fault_count_stats_incr(gt, range);
-		range_debug(range, "PAGE FAULT - VALID");
+		range_debug(range, acc_ctr_trigger ?
+			    "ACCESS COUNTER TRIGGERED - VALID" :
+			    "PAGE FAULT - VALID");
 		goto out;
 	}
 
-	range_debug(range, "PAGE FAULT");
+	range_debug(range, acc_ctr_trigger ?
+		    "ACCESS COUNTER TRIGGERED" : "PAGE FAULT");

drivers/gpu/drm/xe/xe_svm.c static int __xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma, · line 1389

Quoted 10 lines
drivers/gpu/drm/xe/xe_svm.c +10 -0
+
+	/*
+	 * AC-triggered setup: if the range is already in device memory a
+	 * rebind is all that's needed.  Otherwise proceed to the
+	 * migration path — with no explicit madvise preferred location, the
+	 * default first-touch-then-migrate-on-hot policy applies and we
+	 * should attempt VRAM placement for this hot range.
+	 */
+	if (acc_ctr_trigger && !range_flags.migrate_devmem)
+		goto out;

[Severity: Medium]
Is this goto out unreachable due to an earlier check in this function?

Earlier in __xe_svm_range_setup, there is this block:

	range_flags.__flags = READ_ONCE(range->base.flags.__flags);
	if (ctx.devmem_only && !range_flags.migrate_devmem) {
		err = -EACCES;
		goto err_out;
	}

For access counter triggers, ctx.devmem_only is set to true. If the range does not have migrate_devmem set, the earlier block will catch it and return -EACCES.

Returning -EACCES propagates to xe_access_counter_service(), which will abort and discard any remaining VMAs in the advisory window instead of gracefully skipping the non-migratable range. Could this be adjusted so access counter hints gracefully skip non-migratable memory?

drivers/gpu/drm/xe/xe_svm.c static int __xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma, · line 1398

Quoted 9 lines
drivers/gpu/drm/xe/xe_svm.c +7 -0
+
+	/*
+	 * With MIGRATE_ON_ACCESS_COUNTER, defer first placement to access
+	 * counters: skip the eager migrate on a normal page fault, but still
+	 * migrate when this setup was itself triggered by an AC event.
+	 */
 	if (--migrate_try_count >= 0 &&
+	    (acc_ctr_trigger || !(vma->gpuva.flags & XE_VMA_MIGRATE_ON_ACC)) &&
 	    xe_svm_range_needs_migrate_to_vram(range, vma, dpagemap)) {

[Severity: High]
Does this condition block required VRAM migrations for device atomics?

If userspace combines device atomics with the DRM_XE_VM_BIND_FLAG_MIGRATE_ON_ACCESS_COUNTER flag, a normal page fault (acc_ctr_trigger == false) with an atomic requirement (need_vram == true) will evaluate this condition to false.

Because the required xe_svm_alloc_vram() is skipped, the fault handler falls back to xe_svm_range_get_pages() with ctx.devmem_only = true for system memory pages. This fails with -EOPNOTSUPP, causing the fault to retry until the attempt count is exhausted and fail entirely.

Should migrations required for correctness bypass the MIGRATE_ON_ACC flag?

Quoted 4 lines
drivers/gpu/drm/xe/xe_svm.h +0 -0
index 2ef4ef026ccdc..cfc6eb840ca08 100644

[ ... ]

drivers/gpu/drm/xe/xe_svm.h struct xe_svm_range { · line 294

Quoted 12 lines
drivers/gpu/drm/xe/xe_svm.h +5 -0
@@ -270,6 +284,11 @@ struct xe_svm_range {
 	u32 tile_invalidated;
 };
 
+struct xe_svm_range_setup_flags {
+	u32 atomic : 1;
+	u32 acc_ctr_trigger : 1;
+};
+
 static inline void xe_svm_range_put(struct xe_svm_range *range)
 {
 }

[Severity: High]
Does this empty stub lead to a memory leak of drm_gpusvm_range objects?

When an access counter notification is serviced in xe_access_counter_service(), it calls xe_svm_range_find_first(), which acquires a reference via drm_gpusvm_range_get().

After servicing, it attempts to release the reference by calling xe_svm_range_put(range). Since this stub is empty and fails to call drm_gpusvm_range_put(), does it continuously leak memory for heavily accessed ranges in the hardware-generated event worker?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1