Skip to contentSkip to conversation

drm/amdkfd: fix vm-pasid lookup for multiple partitions

PATCH In review Jonathan Kim 6 participants 11 messages Aug 19, 2024 – Sep 25, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdkfd: fix vm-pasid lookup for multiple partitions

Currently multiple partitions will incorrectly overwrite the VM lookup table since the table is indexed by PASID and multiple partitions can register different VM objects on the same PASID.

This results in loading the wrong VM object on PASID query.

To correct this, setup the lookup table to be per-partition-per-PASID instead.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    | 12 ++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c       |  4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |  7 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 55 +++++++++++--------
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h        | 11 +++-
 drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c        |  5 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c        |  5 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c        |  5 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c         |  3 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c         |  5 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c         | 16 ++----
 drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c        |  2 +-
 drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c      |  4 +-
 drivers/gpu/drm/amd/amdkfd/kfd_events.c       |  3 +-
 .../gpu/drm/amd/amdkfd/kfd_int_process_v10.c  |  8 +--
 .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c   |  8 +--
 drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c   |  3 +-
 18 files changed, 92 insertions(+), 65 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +12 -0
index c272461d70a9..28db789610e1 100644
@@ -887,3 +887,15 @@ int amdgpu_amdkfd_unmap_hiq(struct amdgpu_device *adev, u32 doorbell_off,
 
 	return r;
 }
+
+int amdgpu_amdkfd_node_id_to_xcc_id(struct amdgpu_device *adev, uint32_t node_id)
+{
+	if (adev->gfx.funcs->ih_node_to_logical_xcc) {
+		int xcc_id = adev->gfx.funcs->ih_node_to_logical_xcc(adev, node_id);
+
+		if (xcc_id >= 0)
+			return xcc_id;
+	}
+
+	return 0;
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
index 4ed49265c764..bf8bb45d8ab6 100644
@@ -356,6 +356,7 @@ void amdgpu_amdkfd_unreserve_mem_limit(struct amdgpu_device *adev,
 		uint64_t size, u32 alloc_flag, int8_t xcp_id);
 
 u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int xcp_id);
+int amdgpu_amdkfd_node_id_to_xcc_id(struct amdgpu_device *adev, uint32_t node_id);
 
 #define KFD_XCP_MEM_ID(adev, xcp_id) \
 		((adev)->xcp_mgr && (xcp_id) >= 0 ?\
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2 -2
index c6a1783fc9ef..bf9f8802e18d 100644
@@ -37,7 +37,7 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
 	struct amdgpu_job *job = to_amdgpu_job(s_job);
 	struct amdgpu_task_info *ti;
 	struct amdgpu_device *adev = ring->adev;
-	int idx;
+	int idx, xcp_id = !job->vm ? 0 : job->vm->xcp_id;
 	int r;
 
 	if (!drm_dev_enter(adev_to_drm(adev), &idx)) {
@@ -62,7 +62,7 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
 		job->base.sched->name, atomic_read(&ring->fence_drv.last_seq),
 		ring->fence_drv.sync_seq);
 
-	ti = amdgpu_vm_get_task_info_pasid(ring->adev, job->pasid);
+	ti = amdgpu_vm_get_task_info_pasid(ring->adev, job->pasid, xcp_id);
 	if (ti) {
 		dev_err(adev->dev,
 			"Process information: process %s pid %d thread %s pid %d\n",
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -2
index d9fde38f6ee2..e413bf4a3e84 100644
@@ -1275,17 +1275,20 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 		struct amdgpu_vm *vm = &fpriv->vm;
 		struct drm_amdgpu_info_gpuvm_fault gpuvm_fault;
 		unsigned long flags;
+		int i;
 
 		if (!vm)
 			return -EINVAL;
 
 		memset(&gpuvm_fault, 0, sizeof(gpuvm_fault));
 
-		xa_lock_irqsave(&adev->vm_manager.pasids, flags);
+		for (i = 0; i < adev->xcp_mgr->num_xcps; i++)
+			xa_lock_irqsave(&adev->vm_manager.pasids[i], flags);
 		gpuvm_fault.addr = vm->fault_info.addr;
 		gpuvm_fault.status = vm->fault_info.status;
 		gpuvm_fault.vmhub = vm->fault_info.vmhub;
-		xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
+		for (i = 0; i < adev->xcp_mgr->num_xcps; i++)
+			xa_unlock_irqrestore(&adev->vm_manager.pasids[i], flags);
 
 		return copy_to_user(out, &gpuvm_fault,
 				    min((size_t)size, sizeof(gpuvm_fault))) ? -EFAULT : 0;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +32 -23

143 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +8 -3
index 046949c4b695..1499f5f731e9 100644
@@ -35,6 +35,7 @@
 #include "amdgpu_sync.h"
 #include "amdgpu_ring.h"
 #include "amdgpu_ids.h"
+#include "amdgpu_xcp.h"
 
 struct drm_exec;
 
@@ -418,6 +419,9 @@ struct amdgpu_vm {
 
 	/* cached fault info */
 	struct amdgpu_vm_fault_info fault_info;
+
+	/* XCP ID */
+	int xcp_id;
 };
 
 struct amdgpu_vm_manager {
@@ -456,7 +460,7 @@ struct amdgpu_vm_manager {
 	/* PASID to VM mapping, will be used in interrupt context to
 	 * look up VM of a page fault
 	 */
-	struct xarray				pasids;
+	struct xarray				pasids[MAX_XCP];
 	/* Global registration of recent page fault information */
 	struct amdgpu_vm_fault_info	fault_info;
 };
@@ -550,7 +554,7 @@ bool amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring,
 void amdgpu_vm_check_compute_bug(struct amdgpu_device *adev);
 
 struct amdgpu_task_info *
-amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid);
+amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid, u32 xcp_id);
 
 struct amdgpu_task_info *
 amdgpu_vm_get_task_info_vm(struct amdgpu_vm *vm);
@@ -649,7 +653,8 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev,
 				  unsigned int pasid,
 				  uint64_t addr,
 				  uint32_t status,
-				  unsigned int vmhub);
+				  unsigned int vmhub,
+				  uint32_t xcp_id);
 void amdgpu_vm_tlb_fence_create(struct amdgpu_device *adev,
 				 struct amdgpu_vm *vm,
 				 struct dma_fence **fence);
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +3 -2
index f0ceab3ce5bf..24b042febf5c 100644
@@ -151,7 +151,8 @@ static int gmc_v10_0_process_interrupt(struct amdgpu_device *adev,
 		WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
 
 		amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,
-					     entry->vmid_src ? AMDGPU_MMHUB0(0) : AMDGPU_GFXHUB(0));
+					     entry->vmid_src ? AMDGPU_MMHUB0(0) : AMDGPU_GFXHUB(0),
+					     0);
 	}
 
 	if (!printk_ratelimit())
@@ -161,7 +162,7 @@ static int gmc_v10_0_process_interrupt(struct amdgpu_device *adev,
 		"[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
 		entry->vmid_src ? "mmhub" : "gfxhub",
 		entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
-	task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+	task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
 	if (task_info) {
 		dev_err(adev->dev,
 			" in process %s pid %d thread %s pid %d\n",
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +3 -2
index 2797fd84432b..3507046d33e6 100644
@@ -122,7 +122,8 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev,
 		WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
 
 		amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,
-					     entry->vmid_src ? AMDGPU_MMHUB0(0) : AMDGPU_GFXHUB(0));
+					     entry->vmid_src ? AMDGPU_MMHUB0(0) : AMDGPU_GFXHUB(0),
+					     0);
 	}
 
 	if (printk_ratelimit()) {
@@ -132,7 +133,7 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev,
 			"[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
 			entry->vmid_src ? "mmhub" : "gfxhub",
 			entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
-		task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+		task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
 		if (task_info) {
 			dev_err(adev->dev,
 				" in process %s pid %d thread %s pid %d)\n",
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +3 -2
index 60acf676000b..9844564c6c74 100644
@@ -115,7 +115,8 @@ static int gmc_v12_0_process_interrupt(struct amdgpu_device *adev,
 		WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
 
 		amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,
-					     entry->vmid_src ? AMDGPU_MMHUB0(0) : AMDGPU_GFXHUB(0));
+					     entry->vmid_src ? AMDGPU_MMHUB0(0) : AMDGPU_GFXHUB(0),
+					     0);
 	}
 
 	if (printk_ratelimit()) {
@@ -125,7 +126,7 @@ static int gmc_v12_0_process_interrupt(struct amdgpu_device *adev,
 			"[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
 			entry->vmid_src ? "mmhub" : "gfxhub",
 			entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
-		task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+		task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
 		if (task_info) {
 			dev_err(adev->dev,
 				" in process %s pid %d thread %s pid %d)\n",
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +2 -1
index 994432fb57ea..2cdb0cbb7c4d 100644
@@ -1268,7 +1268,8 @@ static int gmc_v7_0_process_interrupt(struct amdgpu_device *adev,
 		return 0;
 
 	amdgpu_vm_update_fault_cache(adev, entry->pasid,
-				     ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status, AMDGPU_GFXHUB(0));
+				     ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
+				     AMDGPU_GFXHUB(0), 0);
 
 	if (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_FIRST)
 		gmc_v7_0_set_fault_enable_default(adev, false);
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +3 -2
index 86488c052f82..6855caeb7f74 100644
@@ -1437,7 +1437,8 @@ static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev,
 		return 0;
 
 	amdgpu_vm_update_fault_cache(adev, entry->pasid,
-				     ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status, AMDGPU_GFXHUB(0));
+				     ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
+				     AMDGPU_GFXHUB(0), 0);
 
 	if (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_FIRST)
 		gmc_v8_0_set_fault_enable_default(adev, false);
@@ -1448,7 +1449,7 @@ static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev,
 		dev_err(adev->dev, "GPU fault detected: %d 0x%08x\n",
 			entry->src_id, entry->src_data[0]);
 
-		task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+		task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
 		if (task_info) {
 			dev_err(adev->dev, " for process %s pid %d thread %s pid %d\n",
 				task_info->process_name, task_info->tgid,
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +6 -10
index b73136d390cc..e183e08b2c02 100644
@@ -556,10 +556,12 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,
 	unsigned int vmhub;
 	u64 addr;
 	uint32_t cam_index = 0;
-	int ret, xcc_id = 0;
-	uint32_t node_id;
+	int ret;
+	uint32_t node_id, xcc_id, xcp_id;
 
 	node_id = entry->node_id;
+	xcc_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, node_id);
+	xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;
 
 	addr = (u64)entry->src_data[0] << 12;
 	addr |= ((u64)entry->src_data[1] & 0xf) << 44;
@@ -572,12 +574,6 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,
 		vmhub = AMDGPU_MMHUB1(0);
 	} else {
 		hub_name = "gfxhub0";
-		if (adev->gfx.funcs->ih_node_to_logical_xcc) {
-			xcc_id = adev->gfx.funcs->ih_node_to_logical_xcc(adev,
-				node_id);
-			if (xcc_id < 0)
-				xcc_id = 0;
-		}
 		vmhub = xcc_id;
 	}
 	hub = &adev->vmhub[vmhub];
@@ -631,7 +627,7 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,
 		retry_fault ? "retry" : "no-retry",
 		entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
 
-	task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+	task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, xcp_id);
 	if (task_info) {
 		dev_err(adev->dev,
 			" for process %s pid %d thread %s pid %d)\n",
@@ -675,7 +671,7 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,
 	if (!amdgpu_sriov_vf(adev))
 		WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
 
-	amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status, vmhub);
+	amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status, vmhub, xcp_id);
 
 	dev_err(adev->dev,
 		"VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +1 -1
index 23ef4eb36b40..1ac4224bbe5b 100644
@@ -2182,7 +2182,7 @@ static int sdma_v4_0_print_iv_entry(struct amdgpu_device *adev,
 			   instance, addr, entry->src_id, entry->ring_id, entry->vmid,
 			   entry->pasid);
 
-	task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+	task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
 	if (task_info) {
 		dev_dbg_ratelimited(adev->dev,
 				    " for process %s pid %d thread %s pid %d\n",
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +3 -1
index 57f16c09abfc..c8b5c0302ca7 100644
@@ -1683,6 +1683,8 @@ static int sdma_v4_4_2_print_iv_entry(struct amdgpu_device *adev,
 	int instance;
 	struct amdgpu_task_info *task_info;
 	u64 addr;
+	uint32_t xcc_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, entry->node_id);
+	uint32_t xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;
 
 	instance = sdma_v4_4_2_irq_id_to_seq(adev, entry->client_id);
 	if (instance < 0 || instance >= adev->sdma.num_instances) {
@@ -1698,7 +1700,7 @@ static int sdma_v4_4_2_print_iv_entry(struct amdgpu_device *adev,
 			    instance, addr, entry->src_id, entry->ring_id, entry->vmid,
 			    entry->pasid);
 
-	task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+	task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, xcp_id);
 	if (task_info) {
 		dev_dbg_ratelimited(adev->dev, " for process %s pid %d thread %s pid %d\n",
 				    task_info->process_name, task_info->tgid,
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -1
index ea3792249209..c098fbaf0e1c 100644
@@ -1262,8 +1262,9 @@ void kfd_signal_reset_event(struct kfd_node *dev)
 
 		if (dev->dqm->detect_hang_count) {
 			struct amdgpu_task_info *ti;
+			uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;
 
-			ti = amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid);
+			ti = amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid, xcp_id);
 			if (ti) {
 				dev_err(dev->adev->dev,
 					"Queues reset on process %s tid %d thread %s pid %d\n",
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c +2 -6
index 8e0d0356e810..d7cbf9525698 100644
@@ -377,12 +377,8 @@ static void event_interrupt_wq_v10(struct kfd_node *dev,
 		struct kfd_hsa_memory_exception_data exception_data;
 
 		/* gfxhub */
-		if (!vmid_type && dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
-			hub_inst = dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev->adev,
-				node_id);
-			if (hub_inst < 0)
-				hub_inst = 0;
-		}
+		if (!vmid_type)
+			hub_inst = amdgpu_amdkfd_node_id_to_xcc_id(dev->adev, node_id);
 
 		/* mmhub */
 		if (vmid_type && client_id == SOC15_IH_CLIENTID_VMC)
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +2 -6
index a9c3580be8c9..4708b8c811a5 100644
@@ -437,12 +437,8 @@ static void event_interrupt_wq_v9(struct kfd_node *dev,
 		struct kfd_hsa_memory_exception_data exception_data;
 
 		/* gfxhub */
-		if (!vmid_type && dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
-			hub_inst = dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev->adev,
-				node_id);
-			if (hub_inst < 0)
-				hub_inst = 0;
-		}
+		if (!vmid_type)
+			hub_inst = amdgpu_amdkfd_node_id_to_xcc_id(dev->adev, node_id);
 
 		/* mmhub */
 		if (vmid_type && client_id == SOC15_IH_CLIENTID_VMC)
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +2 -1
index ea6a8e43bd5b..b5f2f5b1069c 100644
@@ -251,8 +251,9 @@ void kfd_smi_event_update_thermal_throttling(struct kfd_node *dev,
 void kfd_smi_event_update_vmfault(struct kfd_node *dev, uint16_t pasid)
 {
 	struct amdgpu_task_info *task_info;
+	uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;
 
-	task_info = amdgpu_vm_get_task_info_pasid(dev->adev, pasid);
+	task_info = amdgpu_vm_get_task_info_pasid(dev->adev, pasid, xcp_id);
 	if (task_info) {
 		/* Report VM faults from user applications, not retry from kernel */
 		if (task_info->pid)
Signature · 1 line
2.34.1
#1 lore raw

Am 19.08.24 um 19:59 schrieb Jonathan Kim:

Quoted 3 lines

Currently multiple partitions will incorrectly overwrite the VM lookup table since the table is indexed by PASID and multiple partitions can register different VM objects on the same PASID.

That's a rather bad idea. Why do we have the same PASID for different VM objects in the first place?

Regards,
Christian.

Quoted 576 lines

This results in loading the wrong VM object on PASID query.

To correct this, setup the lookup table to be per-partition-per-PASID instead.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    | 12 ++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c       |  4 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |  7 ++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 55 +++++++++++--------
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h        | 11 +++-
  drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c        |  5 +-
  drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c        |  5 +-
  drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c        |  5 +-
  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c         |  3 +-
  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c         |  5 +-
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c         | 16 ++----
  drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c        |  2 +-
  drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c      |  4 +-
  drivers/gpu/drm/amd/amdkfd/kfd_events.c       |  3 +-
  .../gpu/drm/amd/amdkfd/kfd_int_process_v10.c  |  8 +--
  .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c   |  8 +--
  drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c   |  3 +-
  18 files changed, 92 insertions(+), 65 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +12 -0
index c272461d70a9..28db789610e1 100644
@@ -887,3 +887,15 @@ int amdgpu_amdkfd_unmap_hiq(struct amdgpu_device *adev, u32 doorbell_off,
 
  	return r;
  }
+
+int amdgpu_amdkfd_node_id_to_xcc_id(struct amdgpu_device *adev, uint32_t node_id)
+{
+	if (adev->gfx.funcs->ih_node_to_logical_xcc) {
+		int xcc_id = adev->gfx.funcs->ih_node_to_logical_xcc(adev, node_id);
+
+		if (xcc_id >= 0)
+			return xcc_id;
+	}
+
+	return 0;
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
index 4ed49265c764..bf8bb45d8ab6 100644
@@ -356,6 +356,7 @@ void amdgpu_amdkfd_unreserve_mem_limit(struct amdgpu_device *adev,
  		uint64_t size, u32 alloc_flag, int8_t xcp_id);
 
  u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int xcp_id);
+int amdgpu_amdkfd_node_id_to_xcc_id(struct amdgpu_device *adev, uint32_t node_id);
 
  #define KFD_XCP_MEM_ID(adev, xcp_id) \
  		((adev)->xcp_mgr && (xcp_id) >= 0 ?\
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2 -2
index c6a1783fc9ef..bf9f8802e18d 100644
@@ -37,7 +37,7 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
  	struct amdgpu_job *job = to_amdgpu_job(s_job);
  	struct amdgpu_task_info *ti;
  	struct amdgpu_device *adev = ring->adev;
-	int idx;
+	int idx, xcp_id = !job->vm ? 0 : job->vm->xcp_id;
  	int r;
 
  	if (!drm_dev_enter(adev_to_drm(adev), &idx)) {
@@ -62,7 +62,7 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
  		job->base.sched->name, atomic_read(&ring->fence_drv.last_seq),
  		ring->fence_drv.sync_seq);
 
-	ti = amdgpu_vm_get_task_info_pasid(ring->adev, job->pasid);
+	ti = amdgpu_vm_get_task_info_pasid(ring->adev, job->pasid, xcp_id);
  	if (ti) {
  		dev_err(adev->dev,
  			"Process information: process %s pid %d thread %s pid %d\n",
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -2
index d9fde38f6ee2..e413bf4a3e84 100644
@@ -1275,17 +1275,20 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
  		struct amdgpu_vm *vm = &fpriv->vm;
  		struct drm_amdgpu_info_gpuvm_fault gpuvm_fault;
  		unsigned long flags;
+		int i;
 
  		if (!vm)
  			return -EINVAL;
 
  		memset(&gpuvm_fault, 0, sizeof(gpuvm_fault));
 
-		xa_lock_irqsave(&adev->vm_manager.pasids, flags);
+		for (i = 0; i < adev->xcp_mgr->num_xcps; i++)
+			xa_lock_irqsave(&adev->vm_manager.pasids[i], flags);
  		gpuvm_fault.addr = vm->fault_info.addr;
  		gpuvm_fault.status = vm->fault_info.status;
  		gpuvm_fault.vmhub = vm->fault_info.vmhub;
-		xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
+		for (i = 0; i < adev->xcp_mgr->num_xcps; i++)
+			xa_unlock_irqrestore(&adev->vm_manager.pasids[i], flags);
 
  		return copy_to_user(out, &gpuvm_fault,
  				    min((size_t)size, sizeof(gpuvm_fault))) ? -EFAULT : 0;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +32 -23
index bcb729094521..f43e1c15f423 100644
@@ -146,7 +146,7 @@ int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  		return 0;
 
  	if (vm->pasid) {
-		r = xa_err(xa_erase_irq(&adev->vm_manager.pasids, vm->pasid));
+		r = xa_err(xa_erase_irq(&adev->vm_manager.pasids[vm->xcp_id], vm->pasid));
  		if (r < 0)
  			return r;
 
@@ -154,7 +154,7 @@ int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  	}
 
  	if (pasid) {
-		r = xa_err(xa_store_irq(&adev->vm_manager.pasids, pasid, vm,
+		r = xa_err(xa_store_irq(&adev->vm_manager.pasids[vm->xcp_id], pasid, vm,
  					GFP_KERNEL));
  		if (r < 0)
  			return r;
@@ -2288,14 +2288,14 @@ static void amdgpu_vm_destroy_task_info(struct kref *kref)
  }
 
  static inline struct amdgpu_vm *
-amdgpu_vm_get_vm_from_pasid(struct amdgpu_device *adev, u32 pasid)
+amdgpu_vm_get_vm_from_pasid(struct amdgpu_device *adev, u32 pasid, u32 xcp_id)
  {
  	struct amdgpu_vm *vm;
  	unsigned long flags;
 
-	xa_lock_irqsave(&adev->vm_manager.pasids, flags);
-	vm = xa_load(&adev->vm_manager.pasids, pasid);
-	xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
+	xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], flags);
+	vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
+	xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], flags);
 
  	return vm;
  }
@@ -2343,10 +2343,10 @@ amdgpu_vm_get_task_info_vm(struct amdgpu_vm *vm)
   * referenced down with amdgpu_vm_put_task_info.
   */
  struct amdgpu_task_info *
-amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid)
+amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid, u32 xcp_id)
  {
  	return amdgpu_vm_get_task_info_vm(
-			amdgpu_vm_get_vm_from_pasid(adev, pasid));
+			amdgpu_vm_get_vm_from_pasid(adev, pasid, xcp_id));
  }
 
  static int amdgpu_vm_create_task_info(struct amdgpu_vm *vm)
@@ -2481,6 +2481,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  	amdgpu_bo_unreserve(vm->root.bo);
  	amdgpu_bo_unref(&root_bo);
 
+	vm->xcp_id = xcp_id < 0 ? 0 : xcp_id;
+
  	return 0;
 
  error_free_root:
@@ -2695,8 +2697,8 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev)
  #else
  	adev->vm_manager.vm_update_mode = 0;
  #endif
-
-	xa_init_flags(&adev->vm_manager.pasids, XA_FLAGS_LOCK_IRQ);
+	for (i = 0; i < MAX_XCP; i++)
+		xa_init_flags(&(adev->vm_manager.pasids[i]), XA_FLAGS_LOCK_IRQ);
  }
 
  /**
@@ -2708,10 +2710,15 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev)
   */
  void amdgpu_vm_manager_fini(struct amdgpu_device *adev)
  {
-	WARN_ON(!xa_empty(&adev->vm_manager.pasids));
-	xa_destroy(&adev->vm_manager.pasids);
+	int i;
+
+	for (i = 0; i < MAX_XCP; i++) {
+		WARN_ON(!xa_empty(&adev->vm_manager.pasids[i]));
+		xa_destroy(&adev->vm_manager.pasids[i]);
+	}
 
  	amdgpu_vmid_mgr_fini(adev);
+
  }
 
  /**
@@ -2778,17 +2785,18 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid,
  	unsigned long irqflags;
  	uint64_t value, flags;
  	struct amdgpu_vm *vm;
-	int r;
+	int r, xcp_id;
 
-	xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
-	vm = xa_load(&adev->vm_manager.pasids, pasid);
+	xcp_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, node_id)/adev->gfx.num_xcc_per_xcp;
+	xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], irqflags);
+	vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
  	if (vm) {
  		root = amdgpu_bo_ref(vm->root.bo);
  		is_compute_context = vm->is_compute_context;
  	} else {
  		root = NULL;
  	}
-	xa_unlock_irqrestore(&adev->vm_manager.pasids, irqflags);
+	xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], irqflags);
 
  	if (!root)
  		return false;
@@ -2806,11 +2814,11 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid,
  		goto error_unref;
 
  	/* Double check that the VM still exists */
-	xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
-	vm = xa_load(&adev->vm_manager.pasids, pasid);
+	xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], irqflags);
+	vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
  	if (vm && vm->root.bo != root)
  		vm = NULL;
-	xa_unlock_irqrestore(&adev->vm_manager.pasids, irqflags);
+	xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], irqflags);
  	if (!vm)
  		goto error_unlock;
 
@@ -2968,14 +2976,15 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev,
  				  unsigned int pasid,
  				  uint64_t addr,
  				  uint32_t status,
-				  unsigned int vmhub)
+				  unsigned int vmhub,
+				  uint32_t xcp_id)
  {
  	struct amdgpu_vm *vm;
  	unsigned long flags;
 
-	xa_lock_irqsave(&adev->vm_manager.pasids, flags);
+	xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], flags);
 
-	vm = xa_load(&adev->vm_manager.pasids, pasid);
+	vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
  	/* Don't update the fault cache if status is 0.  In the multiple
  	 * fault case, subsequent faults will return a 0 status which is
  	 * useless for userspace and replaces the useful fault status, so
@@ -3008,7 +3017,7 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev,
  			WARN_ONCE(1, "Invalid vmhub %u\n", vmhub);
  		}
  	}
-	xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
+	xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], flags);
  }
 
  /**
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +8 -3
index 046949c4b695..1499f5f731e9 100644
@@ -35,6 +35,7 @@
  #include "amdgpu_sync.h"
  #include "amdgpu_ring.h"
  #include "amdgpu_ids.h"
+#include "amdgpu_xcp.h"
 
  struct drm_exec;
 
@@ -418,6 +419,9 @@ struct amdgpu_vm {
 
  	/* cached fault info */
  	struct amdgpu_vm_fault_info fault_info;
+
+	/* XCP ID */
+	int xcp_id;
  };
 
  struct amdgpu_vm_manager {
@@ -456,7 +460,7 @@ struct amdgpu_vm_manager {
  	/* PASID to VM mapping, will be used in interrupt context to
  	 * look up VM of a page fault
  	 */
-	struct xarray				pasids;
+	struct xarray				pasids[MAX_XCP];
  	/* Global registration of recent page fault information */
  	struct amdgpu_vm_fault_info	fault_info;
  };
@@ -550,7 +554,7 @@ bool amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring,
  void amdgpu_vm_check_compute_bug(struct amdgpu_device *adev);
 
  struct amdgpu_task_info *
-amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid);
+amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid, u32 xcp_id);
 
  struct amdgpu_task_info *
  amdgpu_vm_get_task_info_vm(struct amdgpu_vm *vm);
@@ -649,7 +653,8 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev,
  				  unsigned int pasid,
  				  uint64_t addr,
  				  uint32_t status,
-				  unsigned int vmhub);
+				  unsigned int vmhub,
+				  uint32_t xcp_id);
  void amdgpu_vm_tlb_fence_create(struct amdgpu_device *adev,
  				 struct amdgpu_vm *vm,
  				 struct dma_fence **fence);
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +3 -2
index f0ceab3ce5bf..24b042febf5c 100644
@@ -151,7 +151,8 @@ static int gmc_v10_0_process_interrupt(struct amdgpu_device *adev,
  		WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
 
  		amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,
-					     entry->vmid_src ? AMDGPU_MMHUB0(0) : AMDGPU_GFXHUB(0));
+					     entry->vmid_src ? AMDGPU_MMHUB0(0) : AMDGPU_GFXHUB(0),
+					     0);
  	}
 
  	if (!printk_ratelimit())
@@ -161,7 +162,7 @@ static int gmc_v10_0_process_interrupt(struct amdgpu_device *adev,
  		"[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
  		entry->vmid_src ? "mmhub" : "gfxhub",
  		entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
-	task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+	task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
  	if (task_info) {
  		dev_err(adev->dev,
  			" in process %s pid %d thread %s pid %d\n",
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +3 -2
index 2797fd84432b..3507046d33e6 100644
@@ -122,7 +122,8 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev,
  		WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
 
  		amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,
-					     entry->vmid_src ? AMDGPU_MMHUB0(0) : AMDGPU_GFXHUB(0));
+					     entry->vmid_src ? AMDGPU_MMHUB0(0) : AMDGPU_GFXHUB(0),
+					     0);
  	}
 
  	if (printk_ratelimit()) {
@@ -132,7 +133,7 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev,
  			"[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
  			entry->vmid_src ? "mmhub" : "gfxhub",
  			entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
-		task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+		task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
  		if (task_info) {
  			dev_err(adev->dev,
  				" in process %s pid %d thread %s pid %d)\n",
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +3 -2
index 60acf676000b..9844564c6c74 100644
@@ -115,7 +115,8 @@ static int gmc_v12_0_process_interrupt(struct amdgpu_device *adev,
  		WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
 
  		amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,
-					     entry->vmid_src ? AMDGPU_MMHUB0(0) : AMDGPU_GFXHUB(0));
+					     entry->vmid_src ? AMDGPU_MMHUB0(0) : AMDGPU_GFXHUB(0),
+					     0);
  	}
 
  	if (printk_ratelimit()) {
@@ -125,7 +126,7 @@ static int gmc_v12_0_process_interrupt(struct amdgpu_device *adev,
  			"[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
  			entry->vmid_src ? "mmhub" : "gfxhub",
  			entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
-		task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+		task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
  		if (task_info) {
  			dev_err(adev->dev,
  				" in process %s pid %d thread %s pid %d)\n",
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +2 -1
index 994432fb57ea..2cdb0cbb7c4d 100644
@@ -1268,7 +1268,8 @@ static int gmc_v7_0_process_interrupt(struct amdgpu_device *adev,
  		return 0;
 
  	amdgpu_vm_update_fault_cache(adev, entry->pasid,
-				     ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status, AMDGPU_GFXHUB(0));
+				     ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
+				     AMDGPU_GFXHUB(0), 0);
 
  	if (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_FIRST)
  		gmc_v7_0_set_fault_enable_default(adev, false);
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +3 -2
index 86488c052f82..6855caeb7f74 100644
@@ -1437,7 +1437,8 @@ static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev,
  		return 0;
 
  	amdgpu_vm_update_fault_cache(adev, entry->pasid,
-				     ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status, AMDGPU_GFXHUB(0));
+				     ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
+				     AMDGPU_GFXHUB(0), 0);
 
  	if (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_FIRST)
  		gmc_v8_0_set_fault_enable_default(adev, false);
@@ -1448,7 +1449,7 @@ static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev,
  		dev_err(adev->dev, "GPU fault detected: %d 0x%08x\n",
  			entry->src_id, entry->src_data[0]);
 
-		task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+		task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
  		if (task_info) {
  			dev_err(adev->dev, " for process %s pid %d thread %s pid %d\n",
  				task_info->process_name, task_info->tgid,
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +6 -10
index b73136d390cc..e183e08b2c02 100644
@@ -556,10 +556,12 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,
  	unsigned int vmhub;
  	u64 addr;
  	uint32_t cam_index = 0;
-	int ret, xcc_id = 0;
-	uint32_t node_id;
+	int ret;
+	uint32_t node_id, xcc_id, xcp_id;
 
  	node_id = entry->node_id;
+	xcc_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, node_id);
+	xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;
 
  	addr = (u64)entry->src_data[0] << 12;
  	addr |= ((u64)entry->src_data[1] & 0xf) << 44;
@@ -572,12 +574,6 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,
  		vmhub = AMDGPU_MMHUB1(0);
  	} else {
  		hub_name = "gfxhub0";
-		if (adev->gfx.funcs->ih_node_to_logical_xcc) {
-			xcc_id = adev->gfx.funcs->ih_node_to_logical_xcc(adev,
-				node_id);
-			if (xcc_id < 0)
-				xcc_id = 0;
-		}
  		vmhub = xcc_id;
  	}
  	hub = &adev->vmhub[vmhub];
@@ -631,7 +627,7 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,
  		retry_fault ? "retry" : "no-retry",
  		entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
 
-	task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+	task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, xcp_id);
  	if (task_info) {
  		dev_err(adev->dev,
  			" for process %s pid %d thread %s pid %d)\n",
@@ -675,7 +671,7 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,
  	if (!amdgpu_sriov_vf(adev))
  		WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
 
-	amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status, vmhub);
+	amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status, vmhub, xcp_id);
 
  	dev_err(adev->dev,
  		"VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +1 -1
index 23ef4eb36b40..1ac4224bbe5b 100644
@@ -2182,7 +2182,7 @@ static int sdma_v4_0_print_iv_entry(struct amdgpu_device *adev,
  			   instance, addr, entry->src_id, entry->ring_id, entry->vmid,
  			   entry->pasid);
 
-	task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+	task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
  	if (task_info) {
  		dev_dbg_ratelimited(adev->dev,
  				    " for process %s pid %d thread %s pid %d\n",
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +3 -1
index 57f16c09abfc..c8b5c0302ca7 100644
@@ -1683,6 +1683,8 @@ static int sdma_v4_4_2_print_iv_entry(struct amdgpu_device *adev,
  	int instance;
  	struct amdgpu_task_info *task_info;
  	u64 addr;
+	uint32_t xcc_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, entry->node_id);
+	uint32_t xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;
 
  	instance = sdma_v4_4_2_irq_id_to_seq(adev, entry->client_id);
  	if (instance < 0 || instance >= adev->sdma.num_instances) {
@@ -1698,7 +1700,7 @@ static int sdma_v4_4_2_print_iv_entry(struct amdgpu_device *adev,
  			    instance, addr, entry->src_id, entry->ring_id, entry->vmid,
  			    entry->pasid);
 
-	task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+	task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, xcp_id);
  	if (task_info) {
  		dev_dbg_ratelimited(adev->dev, " for process %s pid %d thread %s pid %d\n",
  				    task_info->process_name, task_info->tgid,
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -1
index ea3792249209..c098fbaf0e1c 100644
@@ -1262,8 +1262,9 @@ void kfd_signal_reset_event(struct kfd_node *dev)
 
  		if (dev->dqm->detect_hang_count) {
  			struct amdgpu_task_info *ti;
+			uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;
 
-			ti = amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid);
+			ti = amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid, xcp_id);
  			if (ti) {
  				dev_err(dev->adev->dev,
  					"Queues reset on process %s tid %d thread %s pid %d\n",
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c +2 -6
index 8e0d0356e810..d7cbf9525698 100644
@@ -377,12 +377,8 @@ static void event_interrupt_wq_v10(struct kfd_node *dev,
  		struct kfd_hsa_memory_exception_data exception_data;
 
  		/* gfxhub */
-		if (!vmid_type && dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
-			hub_inst = dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev->adev,
-				node_id);
-			if (hub_inst < 0)
-				hub_inst = 0;
-		}
+		if (!vmid_type)
+			hub_inst = amdgpu_amdkfd_node_id_to_xcc_id(dev->adev, node_id);
 
  		/* mmhub */
  		if (vmid_type && client_id == SOC15_IH_CLIENTID_VMC)
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +2 -6
index a9c3580be8c9..4708b8c811a5 100644
@@ -437,12 +437,8 @@ static void event_interrupt_wq_v9(struct kfd_node *dev,
  		struct kfd_hsa_memory_exception_data exception_data;
 
  		/* gfxhub */
-		if (!vmid_type && dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
-			hub_inst = dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev->adev,
-				node_id);
-			if (hub_inst < 0)
-				hub_inst = 0;
-		}
+		if (!vmid_type)
+			hub_inst = amdgpu_amdkfd_node_id_to_xcc_id(dev->adev, node_id);
 
  		/* mmhub */
  		if (vmid_type && client_id == SOC15_IH_CLIENTID_VMC)
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +2 -1
index ea6a8e43bd5b..b5f2f5b1069c 100644
@@ -251,8 +251,9 @@ void kfd_smi_event_update_thermal_throttling(struct kfd_node *dev,
  void kfd_smi_event_update_vmfault(struct kfd_node *dev, uint16_t pasid)
  {
  	struct amdgpu_task_info *task_info;
+	uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;
 
-	task_info = amdgpu_vm_get_task_info_pasid(dev->adev, pasid);
+	task_info = amdgpu_vm_get_task_info_pasid(dev->adev, pasid, xcp_id);
  	if (task_info) {
  		/* Report VM faults from user applications, not retry from kernel */
  		if (task_info->pid)
#2 lore raw

[Public]

Quoted 12 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Thursday, September 5, 2024 10:24 AM
To: Kim, Jonathan <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]>
Subject: Re: [PATCH] drm/amdkfd: fix vm-pasid lookup for multiple partitions

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 7 lines

Am 19.08.24 um 19:59 schrieb Jonathan Kim:

Quoted 3 lines

Currently multiple partitions will incorrectly overwrite the VM lookup table since the table is indexed by PASID and multiple partitions can register different VM objects on the same PASID.

That's a rather bad idea. Why do we have the same PASID for different VM objects in the first place?

Alex can probably elaborate on the KGD side, but from what I can see, the KMS driver open call has always assigned a new VM object per PASID on an open call. The KFD acquires and replaces the KGD PASID-VMID registration on its own compute process open/creation call.
If this is the bad_idea you're referring to, then someone else will have to chime in. I don't have much history on this unfortunately.

That aside, the current problem is, is that all KFD device structures are logical partitions and register their PASID-VM binding using this concept of a device. On the KGD side however, the registration table is maintained in the adev struct, which is a physical socket.
So there's a mismatch in understanding of what a device is between the KFD & KGD with regard to the look up table that results in bad bindings.

Adding a per-partition dimension to the existing lookup table resolves issues where seeing, for example, with memory violation interception and XNACK i.e bad bindings result in wrong vm object found to set no-retry flags on memory violations.

Jon

Quoted 666 lines

Regards,
Christian.

Quoted 6 lines

This results in loading the wrong VM object on PASID query.

To correct this, setup the lookup table to be per-partition-per-PASID instead.

Quoted 7 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    | 12 ++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c       |  4 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |  7 ++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 55 +++++++++++------

--

Quoted 15 lines
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h        | 11 +++-
  drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c        |  5 +-
  drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c        |  5 +-
  drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c        |  5 +-
  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c         |  3 +-
  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c         |  5 +-
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c         | 16 ++----
  drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c        |  2 +-
  drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c      |  4 +-
  drivers/gpu/drm/amd/amdkfd/kfd_events.c       |  3 +-
  .../gpu/drm/amd/amdkfd/kfd_int_process_v10.c  |  8 +--
  .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c   |  8 +--
  drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c   |  3 +-
  18 files changed, 92 insertions(+), 65 deletions(-)

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c int amdgpu_amdkfd_unmap_hiq(struct

Quoted 4 lines

index c272461d70a9..28db789610e1 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0 -0
@@ -887,3 +887,15 @@ int amdgpu_amdkfd_unmap_hiq(struct

amdgpu_device *adev, u32 doorbell_off,

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c int amdgpu_amdkfd_unmap_hiq(struct amdgpu_device *adev, u32 doorbell_off,

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +2 -0
      return r;
  }
+
+int amdgpu_amdkfd_node_id_to_xcc_id(struct amdgpu_device *adev,

uint32_t node_id)

Review

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +10 -0
+{
+     if (adev->gfx.funcs->ih_node_to_logical_xcc) {
+             int xcc_id = adev->gfx.funcs->ih_node_to_logical_xcc(adev, node_id);
+
+             if (xcc_id >= 0)
+                     return xcc_id;
+     }
+
+     return 0;
+}
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h void amdgpu_amdkfd_unreserve_mem_limit(struct

Quoted 4 lines

index 4ed49265c764..bf8bb45d8ab6 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +0 -0
@@ -356,6 +356,7 @@ void amdgpu_amdkfd_unreserve_mem_limit(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h void amdgpu_amdkfd_unreserve_mem_limit(struct amdgpu_device *adev,

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +0 -0
              uint64_t size, u32 alloc_flag, int8_t xcp_id);
 
  u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int

xcp_id);

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h void amdgpu_amdkfd_unreserve_mem_limit(struct · line 359

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
+int amdgpu_amdkfd_node_id_to_xcc_id(struct amdgpu_device *adev,

uint32_t node_id);

Review

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +0 -0
  #define KFD_XCP_MEM_ID(adev, xcp_id) \
              ((adev)->xcp_mgr && (xcp_id) >= 0 ?\
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static enum drm_gpu_sched_stat

Quoted 4 lines

index c6a1783fc9ef..bf9f8802e18d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
@@ -37,7 +37,7 @@ static enum drm_gpu_sched_stat

amdgpu_job_timedout(struct drm_sched_job *s_job)

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static enum drm_gpu_sched_stat

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -1
      struct amdgpu_job *job = to_amdgpu_job(s_job);
      struct amdgpu_task_info *ti;
      struct amdgpu_device *adev = ring->adev;
-     int idx;
+     int idx, xcp_id = !job->vm ? 0 : job->vm->xcp_id;
      int r;
 
      if (!drm_dev_enter(adev_to_drm(adev), &idx)) {
@@ -62,7 +62,7 @@ static enum drm_gpu_sched_stat

amdgpu_job_timedout(struct drm_sched_job *s_job)

Review

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -1
              job->base.sched->name, atomic_read(&ring->fence_drv.last_seq),
              ring->fence_drv.sync_seq);
 
-     ti = amdgpu_vm_get_task_info_pasid(ring->adev, job->pasid);
+     ti = amdgpu_vm_get_task_info_pasid(ring->adev, job->pasid, xcp_id);
      if (ti) {
              dev_err(adev->dev,
                      "Process information: process %s pid %d thread %s pid %d\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_info_ioctl(struct drm_device *dev,

Quoted 4 lines

index d9fde38f6ee2..e413bf4a3e84 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
@@ -1275,17 +1275,20 @@ int amdgpu_info_ioctl(struct drm_device *dev,

void *data, struct drm_file *filp)

Review

Quoted 23 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -2
              struct amdgpu_vm *vm = &fpriv->vm;
              struct drm_amdgpu_info_gpuvm_fault gpuvm_fault;
              unsigned long flags;
+             int i;
 
              if (!vm)
                      return -EINVAL;
 
              memset(&gpuvm_fault, 0, sizeof(gpuvm_fault));
 
-             xa_lock_irqsave(&adev->vm_manager.pasids, flags);
+             for (i = 0; i < adev->xcp_mgr->num_xcps; i++)
+                     xa_lock_irqsave(&adev->vm_manager.pasids[i], flags);
              gpuvm_fault.addr = vm->fault_info.addr;
              gpuvm_fault.status = vm->fault_info.status;
              gpuvm_fault.vmhub = vm->fault_info.vmhub;
-             xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
+             for (i = 0; i < adev->xcp_mgr->num_xcps; i++)
+                     xa_unlock_irqrestore(&adev->vm_manager.pasids[i], flags);
 
              return copy_to_user(out, &gpuvm_fault,
                                  min((size_t)size, sizeof(gpuvm_fault))) ? -EFAULT : 0;
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_set_pasid(struct amdgpu_device

Quoted 4 lines

index bcb729094521..f43e1c15f423 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
@@ -146,7 +146,7 @@ int amdgpu_vm_set_pasid(struct amdgpu_device

*adev, struct amdgpu_vm *vm,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm,

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
              return 0;
 
      if (vm->pasid) {
-             r = xa_err(xa_erase_irq(&adev->vm_manager.pasids, vm->pasid));
+             r = xa_err(xa_erase_irq(&adev->vm_manager.pasids[vm->xcp_id],

vm->pasid));

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_set_pasid(struct amdgpu_device

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
              if (r < 0)
                      return r;
 
@@ -154,7 +154,7 @@ int amdgpu_vm_set_pasid(struct amdgpu_device

*adev, struct amdgpu_vm *vm,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm,

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
      }
 
      if (pasid) {
-             r = xa_err(xa_store_irq(&adev->vm_manager.pasids, pasid, vm,
+             r = xa_err(xa_store_irq(&adev->vm_manager.pasids[vm->xcp_id],

pasid, vm,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static void

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
                                      GFP_KERNEL));
              if (r < 0)
                      return r;
@@ -2288,14 +2288,14 @@ static void

amdgpu_vm_destroy_task_info(struct kref *kref)

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static void amdgpu_vm_destroy_task_info(struct kref *kref)

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
  }
 
  static inline struct amdgpu_vm *
-amdgpu_vm_get_vm_from_pasid(struct amdgpu_device *adev, u32 pasid)
+amdgpu_vm_get_vm_from_pasid(struct amdgpu_device *adev, u32 pasid,

u32 xcp_id)

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c amdgpu_vm_get_task_info_vm(struct

Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -3
  {
      struct amdgpu_vm *vm;
      unsigned long flags;
 
-     xa_lock_irqsave(&adev->vm_manager.pasids, flags);
-     vm = xa_load(&adev->vm_manager.pasids, pasid);
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
+     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], flags);
+     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
+     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], flags);
 
      return vm;
  }
@@ -2343,10 +2343,10 @@ amdgpu_vm_get_task_info_vm(struct

amdgpu_vm *vm)

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c amdgpu_vm_get_task_info_vm(struct amdgpu_vm *vm)

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
   * referenced down with amdgpu_vm_put_task_info.
   */
  struct amdgpu_task_info *
-amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid)
+amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid,

u32 xcp_id)

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_init(struct amdgpu_device

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
  {
      return amdgpu_vm_get_task_info_vm(
-                     amdgpu_vm_get_vm_from_pasid(adev, pasid));
+                     amdgpu_vm_get_vm_from_pasid(adev, pasid, xcp_id));
  }
 
  static int amdgpu_vm_create_task_info(struct amdgpu_vm *vm)
@@ -2481,6 +2481,8 @@ int amdgpu_vm_init(struct amdgpu_device

*adev, struct amdgpu_vm *vm,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_manager_init(struct

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -0
      amdgpu_bo_unreserve(vm->root.bo);
      amdgpu_bo_unref(&root_bo);
 
+     vm->xcp_id = xcp_id < 0 ? 0 : xcp_id;
+
      return 0;
 
  error_free_root:
@@ -2695,8 +2697,8 @@ void amdgpu_vm_manager_init(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_manager_init(struct amdgpu_device *adev)

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -2
  #else
      adev->vm_manager.vm_update_mode = 0;
  #endif
-
-     xa_init_flags(&adev->vm_manager.pasids, XA_FLAGS_LOCK_IRQ);
+     for (i = 0; i < MAX_XCP; i++)
+             xa_init_flags(&(adev->vm_manager.pasids[i]),

XA_FLAGS_LOCK_IRQ);

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_manager_init(struct

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
  }
 
  /**
@@ -2708,10 +2710,15 @@ void amdgpu_vm_manager_init(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c bool amdgpu_vm_handle_fault(struct

Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7 -2
   */
  void amdgpu_vm_manager_fini(struct amdgpu_device *adev)
  {
-     WARN_ON(!xa_empty(&adev->vm_manager.pasids));
-     xa_destroy(&adev->vm_manager.pasids);
+     int i;
+
+     for (i = 0; i < MAX_XCP; i++) {
+             WARN_ON(!xa_empty(&adev->vm_manager.pasids[i]));
+             xa_destroy(&adev->vm_manager.pasids[i]);
+     }
 
      amdgpu_vmid_mgr_fini(adev);
+
  }
 
  /**
@@ -2778,17 +2785,18 @@ bool amdgpu_vm_handle_fault(struct

amdgpu_device *adev, u32 pasid,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c bool amdgpu_vm_handle_fault(struct

Quoted 24 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5 -4
      unsigned long irqflags;
      uint64_t value, flags;
      struct amdgpu_vm *vm;
-     int r;
+     int r, xcp_id;
 
-     xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
-     vm = xa_load(&adev->vm_manager.pasids, pasid);
+     xcp_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, node_id)/adev-
 gfx.num_xcc_per_xcp;
+     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], irqflags);
+     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
      if (vm) {
              root = amdgpu_bo_ref(vm->root.bo);
              is_compute_context = vm->is_compute_context;
      } else {
              root = NULL;
      }
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, irqflags);
+     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], irqflags);
 
      if (!root)
              return false;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
@@ -2806,11 +2814,11 @@ bool amdgpu_vm_handle_fault(struct

amdgpu_device *adev, u32 pasid,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_update_fault_cache(struct

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -3
              goto error_unref;
 
      /* Double check that the VM still exists */
-     xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
-     vm = xa_load(&adev->vm_manager.pasids, pasid);
+     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], irqflags);
+     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
      if (vm && vm->root.bo != root)
              vm = NULL;
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, irqflags);
+     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], irqflags);
      if (!vm)
              goto error_unlock;
 
@@ -2968,14 +2976,15 @@ void amdgpu_vm_update_fault_cache(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_update_fault_cache(struct

Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -3
                                unsigned int pasid,
                                uint64_t addr,
                                uint32_t status,
-                               unsigned int vmhub)
+                               unsigned int vmhub,
+                               uint32_t xcp_id)
  {
      struct amdgpu_vm *vm;
      unsigned long flags;
 
-     xa_lock_irqsave(&adev->vm_manager.pasids, flags);
+     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], flags);
 
-     vm = xa_load(&adev->vm_manager.pasids, pasid);
+     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
      /* Don't update the fault cache if status is 0.  In the multiple
       * fault case, subsequent faults will return a 0 status which is
       * useless for userspace and replaces the useful fault status, so
@@ -3008,7 +3017,7 @@ void amdgpu_vm_update_fault_cache(struct

amdgpu_device *adev,

Review

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
                      WARN_ONCE(1, "Invalid vmhub %u\n", vmhub);
              }
      }
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
+     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], flags);
  }
 
  /**
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h bool amdgpu_vm_need_pipeline_sync(struct

Quoted 31 lines

index 046949c4b695..1499f5f731e9 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +5 -1
@@ -35,6 +35,7 @@
  #include "amdgpu_sync.h"
  #include "amdgpu_ring.h"
  #include "amdgpu_ids.h"
+#include "amdgpu_xcp.h"
 
  struct drm_exec;
 
@@ -418,6 +419,9 @@ struct amdgpu_vm {
 
      /* cached fault info */
      struct amdgpu_vm_fault_info fault_info;
+
+     /* XCP ID */
+     int xcp_id;
  };
 
  struct amdgpu_vm_manager {
@@ -456,7 +460,7 @@ struct amdgpu_vm_manager {
      /* PASID to VM mapping, will be used in interrupt context to
       * look up VM of a page fault
       */
-     struct xarray                           pasids;
+     struct xarray                           pasids[MAX_XCP];
      /* Global registration of recent page fault information */
      struct amdgpu_vm_fault_info     fault_info;
  };
@@ -550,7 +554,7 @@ bool amdgpu_vm_need_pipeline_sync(struct

amdgpu_ring *ring,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h bool amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring,

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -1
  void amdgpu_vm_check_compute_bug(struct amdgpu_device *adev);
 
  struct amdgpu_task_info *
-amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid);
+amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid,

u32 xcp_id);

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h void amdgpu_vm_update_fault_cache(struct

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
  struct amdgpu_task_info *
  amdgpu_vm_get_task_info_vm(struct amdgpu_vm *vm);
@@ -649,7 +653,8 @@ void amdgpu_vm_update_fault_cache(struct

amdgpu_device *adev,

Review

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +2 -1
                                unsigned int pasid,
                                uint64_t addr,
                                uint32_t status,
-                               unsigned int vmhub);
+                               unsigned int vmhub,
+                               uint32_t xcp_id);
  void amdgpu_vm_tlb_fence_create(struct amdgpu_device *adev,
                               struct amdgpu_vm *vm,
                               struct dma_fence **fence);
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c

drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c static int gmc_v10_0_process_interrupt(struct

Quoted 4 lines

index f0ceab3ce5bf..24b042febf5c 100644

drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +0 -0
@@ -151,7 +151,8 @@ static int gmc_v10_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c static int gmc_v10_0_process_interrupt(struct amdgpu_device *adev,

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +0 -1
              WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
 
              amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,
-                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :

AMDGPU_GFXHUB(0));

drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c static int gmc_v10_0_process_interrupt(struct · line 154

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +1 -0
+                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :

AMDGPU_GFXHUB(0),

drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c static int gmc_v10_0_process_interrupt(struct

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +1 -0
+                                          0);
      }
 
      if (!printk_ratelimit())
@@ -161,7 +162,7 @@ static int gmc_v10_0_process_interrupt(struct

amdgpu_device *adev,

Review

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +1 -1
              "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
              entry->vmid_src ? "mmhub" : "gfxhub",
              entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
-     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
      if (task_info) {
              dev_err(adev->dev,
                      " in process %s pid %d thread %s pid %d\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c

drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c static int gmc_v11_0_process_interrupt(struct

Quoted 4 lines

index 2797fd84432b..3507046d33e6 100644

drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +0 -0
@@ -122,7 +122,8 @@ static int gmc_v11_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c static int gmc_v11_0_process_interrupt(struct · line 125

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +0 -1
              WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
 
              amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,
-                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :

AMDGPU_GFXHUB(0));

drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c static int gmc_v11_0_process_interrupt(struct · line 125

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +1 -0
+                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :

AMDGPU_GFXHUB(0),

drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c static int gmc_v11_0_process_interrupt(struct

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +1 -0
+                                          0);
      }
 
      if (printk_ratelimit()) {
@@ -132,7 +133,7 @@ static int gmc_v11_0_process_interrupt(struct

amdgpu_device *adev,

Review

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +1 -1
                      "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
                      entry->vmid_src ? "mmhub" : "gfxhub",
                      entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
-             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
              if (task_info) {
                      dev_err(adev->dev,
                              " in process %s pid %d thread %s pid %d)\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static int gmc_v12_0_process_interrupt(struct

Quoted 4 lines

index 60acf676000b..9844564c6c74 100644

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -0
@@ -115,7 +115,8 @@ static int gmc_v12_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static int gmc_v12_0_process_interrupt(struct · line 118

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -1
              WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
 
              amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,
-                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :

AMDGPU_GFXHUB(0));

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static int gmc_v12_0_process_interrupt(struct · line 118

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +1 -0
+                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :

AMDGPU_GFXHUB(0),

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static int gmc_v12_0_process_interrupt(struct

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +1 -0
+                                          0);
      }
 
      if (printk_ratelimit()) {
@@ -125,7 +126,7 @@ static int gmc_v12_0_process_interrupt(struct

amdgpu_device *adev,

Review

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +1 -1
                      "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
                      entry->vmid_src ? "mmhub" : "gfxhub",
                      entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
-             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
              if (task_info) {
                      dev_err(adev->dev,
                              " in process %s pid %d thread %s pid %d)\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c

drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c static int gmc_v7_0_process_interrupt(struct

Quoted 4 lines

index 994432fb57ea..2cdb0cbb7c4d 100644

drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +0 -0
@@ -1268,7 +1268,8 @@ static int gmc_v7_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c static int gmc_v7_0_process_interrupt(struct amdgpu_device *adev,

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +0 -1
              return 0;
 
      amdgpu_vm_update_fault_cache(adev, entry->pasid,
-                                  ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,

AMDGPU_GFXHUB(0));

Review

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +2 -0
+                                  ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
+                                  AMDGPU_GFXHUB(0), 0);
 
      if (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_FIRST)
              gmc_v7_0_set_fault_enable_default(adev, false);
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct

Quoted 4 lines

index 86488c052f82..6855caeb7f74 100644

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0 -0
@@ -1437,7 +1437,8 @@ static int gmc_v8_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct · line 1440

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0 -1
              return 0;
 
      amdgpu_vm_update_fault_cache(adev, entry->pasid,
-                                  ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,

AMDGPU_GFXHUB(0));

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +2 -0
+                                  ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
+                                  AMDGPU_GFXHUB(0), 0);
 
      if (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_FIRST)
              gmc_v8_0_set_fault_enable_default(adev, false);
@@ -1448,7 +1449,7 @@ static int gmc_v8_0_process_interrupt(struct

amdgpu_device *adev,

Review

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1 -1
              dev_err(adev->dev, "GPU fault detected: %d 0x%08x\n",
                      entry->src_id, entry->src_data[0]);
 
-             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
              if (task_info) {
                      dev_err(adev->dev, " for process %s pid %d thread %s pid %d\n",
                              task_info->process_name, task_info->tgid,
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct

Quoted 4 lines

index b73136d390cc..e183e08b2c02 100644

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
@@ -556,10 +556,12 @@ static int gmc_v9_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +4 -2
      unsigned int vmhub;
      u64 addr;
      uint32_t cam_index = 0;
-     int ret, xcc_id = 0;
-     uint32_t node_id;
+     int ret;
+     uint32_t node_id, xcc_id, xcp_id;
 
      node_id = entry->node_id;
+     xcc_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, node_id);
+     xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;
 
      addr = (u64)entry->src_data[0] << 12;
      addr |= ((u64)entry->src_data[1] & 0xf) << 44;
@@ -572,12 +574,6 @@ static int gmc_v9_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -6
              vmhub = AMDGPU_MMHUB1(0);
      } else {
              hub_name = "gfxhub0";
-             if (adev->gfx.funcs->ih_node_to_logical_xcc) {
-                     xcc_id = adev->gfx.funcs->ih_node_to_logical_xcc(adev,
-                             node_id);
-                     if (xcc_id < 0)
-                             xcc_id = 0;
-             }
              vmhub = xcc_id;
      }
      hub = &adev->vmhub[vmhub];
@@ -631,7 +627,7 @@ static int gmc_v9_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -1
              retry_fault ? "retry" : "no-retry",
              entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
 
-     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid,

xcp_id);

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
      if (task_info) {
              dev_err(adev->dev,
                      " for process %s pid %d thread %s pid %d)\n",
@@ -675,7 +671,7 @@ static int gmc_v9_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -1
      if (!amdgpu_sriov_vf(adev))
              WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
 
-     amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,

vmhub);

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct · line 674

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
+     amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,

vmhub, xcp_id);

Review

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
      dev_err(adev->dev,
              "VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c

drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c static int sdma_v4_0_print_iv_entry(struct

Quoted 4 lines

index 23ef4eb36b40..1ac4224bbe5b 100644

drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +0 -0
@@ -2182,7 +2182,7 @@ static int sdma_v4_0_print_iv_entry(struct

amdgpu_device *adev,

Review

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +1 -1
                         instance, addr, entry->src_id, entry->ring_id, entry->vmid,
                         entry->pasid);
 
-     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
      if (task_info) {
              dev_dbg_ratelimited(adev->dev,
                                  " for process %s pid %d thread %s pid %d\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_print_iv_entry(struct

Quoted 4 lines

index 57f16c09abfc..c8b5c0302ca7 100644

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -0
@@ -1683,6 +1683,8 @@ static int sdma_v4_4_2_print_iv_entry(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_print_iv_entry(struct

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2 -0
      int instance;
      struct amdgpu_task_info *task_info;
      u64 addr;
+     uint32_t xcc_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, entry-
 node_id);
+     uint32_t xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;
 
      instance = sdma_v4_4_2_irq_id_to_seq(adev, entry->client_id);
      if (instance < 0 || instance >= adev->sdma.num_instances) {
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -0
@@ -1698,7 +1700,7 @@ static int sdma_v4_4_2_print_iv_entry(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_print_iv_entry(struct · line 1703

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1 -1
                          instance, addr, entry->src_id, entry->ring_id, entry->vmid,
                          entry->pasid);
 
-     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid,

xcp_id);

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_print_iv_entry(struct · line 1705

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -0
      if (task_info) {
              dev_dbg_ratelimited(adev->dev, " for process %s pid %d thread %s

pid %d\n",

Review

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -0
                                  task_info->process_name, task_info->tgid,
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_events.c

drivers/gpu/drm/amd/amdkfd/kfd_events.c void kfd_signal_reset_event(struct kfd_node

Quoted 4 lines

index ea3792249209..c098fbaf0e1c 100644

drivers/gpu/drm/amd/amdkfd/kfd_events.c +0 -0
@@ -1262,8 +1262,9 @@ void kfd_signal_reset_event(struct kfd_node

*dev)

drivers/gpu/drm/amd/amdkfd/kfd_events.c void kfd_signal_reset_event(struct kfd_node *dev)

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -1
              if (dev->dqm->detect_hang_count) {
                      struct amdgpu_task_info *ti;
+                     uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;
 
-                     ti = amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid);
+                     ti = amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid,

xcp_id);

Review

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +0 -0
                      if (ti) {
                              dev_err(dev->adev->dev,
                                      "Queues reset on process %s tid %d thread %s pid %d\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c static void event_interrupt_wq_v10(struct

Quoted 4 lines

index 8e0d0356e810..d7cbf9525698 100644

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c +0 -0
@@ -377,12 +377,8 @@ static void event_interrupt_wq_v10(struct

kfd_node *dev,

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c static void event_interrupt_wq_v10(struct kfd_node *dev,

Quoted 12 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c +2 -6
              struct kfd_hsa_memory_exception_data exception_data;
 
              /* gfxhub */
-             if (!vmid_type && dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
-                     hub_inst = dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev-
 adev,
-                             node_id);
-                     if (hub_inst < 0)
-                             hub_inst = 0;
-             }
+             if (!vmid_type)
+                     hub_inst = amdgpu_amdkfd_node_id_to_xcc_id(dev->adev,

node_id);

Review

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c +0 -0
              /* mmhub */
              if (vmid_type && client_id == SOC15_IH_CLIENTID_VMC)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_wq_v9(struct

Quoted 4 lines

index a9c3580be8c9..4708b8c811a5 100644

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -0
@@ -437,12 +437,8 @@ static void event_interrupt_wq_v9(struct

kfd_node *dev,

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_wq_v9(struct · line 442

Quoted 12 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +2 -6
              struct kfd_hsa_memory_exception_data exception_data;
 
              /* gfxhub */
-             if (!vmid_type && dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
-                     hub_inst = dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev-
 adev,
-                             node_id);
-                     if (hub_inst < 0)
-                             hub_inst = 0;
-             }
+             if (!vmid_type)
+                     hub_inst = amdgpu_amdkfd_node_id_to_xcc_id(dev->adev,

node_id);

Review

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -0
              /* mmhub */
              if (vmid_type && client_id == SOC15_IH_CLIENTID_VMC)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c

drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c void

Quoted 4 lines

index ea6a8e43bd5b..b5f2f5b1069c 100644

drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +0 -0
@@ -251,8 +251,9 @@ void

kfd_smi_event_update_thermal_throttling(struct kfd_node *dev,

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +2 -1
  void kfd_smi_event_update_vmfault(struct kfd_node *dev, uint16_t pasid)
  {
      struct amdgpu_task_info *task_info;
+     uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;
 
-     task_info = amdgpu_vm_get_task_info_pasid(dev->adev, pasid);
+     task_info = amdgpu_vm_get_task_info_pasid(dev->adev, pasid, xcp_id);
      if (task_info) {
              /* Report VM faults from user applications, not retry from kernel */
              if (task_info->pid)
maintainer
#3 lore raw

Am 09.09.24 um 18:02 schrieb Kim, Jonathan:

Quoted 15 lines

[Public]

Quoted 13 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Thursday, September 5, 2024 10:24 AM
To: Kim, Jonathan <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]>
Subject: Re: [PATCH] drm/amdkfd: fix vm-pasid lookup for multiple partitions

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Am 19.08.24 um 19:59 schrieb Jonathan Kim:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Currently multiple partitions will incorrectly overwrite the VM lookup table since the table is indexed by PASID and multiple partitions can register different VM objects on the same PASID.

That's a rather bad idea. Why do we have the same PASID for different VM objects in the first place?

Alex can probably elaborate on the KGD side, but from what I can see, the KMS driver open call has always assigned a new VM object per PASID on an open call. The KFD acquires and replaces the KGD PASID-VMID registration on its own compute process open/creation call.
If this is the bad_idea you're referring to, then someone else will have to chime in. I don't have much history on this unfortunately.

Yeah, Felix and I designed that.

Quoted 1 line

That aside, the current problem is, is that all KFD device structures are logical partitions and register their PASID-VM binding using this concept of a device.

As far as I can see that is the fundamental problem. This needs to be fixed instead.

Quoted 4 lines

On the KGD side however, the registration table is maintained in the adev struct, which is a physical socket.
So there's a mismatch in understanding of what a device is between the KFD & KGD with regard to the look up table that results in bad bindings.

Adding a per-partition dimension to the existing lookup table resolves issues where seeing, for example, with memory violation interception and XNACK i.e bad bindings result in wrong vm object found to set no-retry flags on memory violations.

Yeah that is pretty much a no-go.

The PASID and how it is used is defined by the PCIe specifications. If we now start to assign multiple VMs to the same PASID then we are violating the PCIe specification.

The problems you see are most likely just the tip of the iceberg here.

Regards,
Christian.

Quoted 660 lines

Jon

Quoted 657 lines

Regards,
Christian.

Quoted 5 lines

This results in loading the wrong VM object on PASID query.

To correct this, setup the lookup table to be per-partition-per-PASID instead.

Quoted 7 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    | 12 ++++
   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |  1 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_job.c       |  4 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |  7 ++-
   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 55 +++++++++++------

--

Quoted 15 lines
   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h        | 11 +++-
   drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c        |  5 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c        |  5 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c        |  5 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c         |  3 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c         |  5 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c         | 16 ++----
   drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c        |  2 +-
   drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c      |  4 +-
   drivers/gpu/drm/amd/amdkfd/kfd_events.c       |  3 +-
   .../gpu/drm/amd/amdkfd/kfd_int_process_v10.c  |  8 +--
   .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c   |  8 +--
   drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c   |  3 +-
   18 files changed, 92 insertions(+), 65 deletions(-)

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c int amdgpu_amdkfd_unmap_hiq(struct

Quoted 4 lines

index c272461d70a9..28db789610e1 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0 -0
@@ -887,3 +887,15 @@ int amdgpu_amdkfd_unmap_hiq(struct

amdgpu_device *adev, u32 doorbell_off,

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c int amdgpu_amdkfd_unmap_hiq(struct amdgpu_device *adev, u32 doorbell_off,

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +2 -0
       return r;
   }
+
+int amdgpu_amdkfd_node_id_to_xcc_id(struct amdgpu_device *adev,

uint32_t node_id)

Review

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +10 -0
+{
+     if (adev->gfx.funcs->ih_node_to_logical_xcc) {
+             int xcc_id = adev->gfx.funcs->ih_node_to_logical_xcc(adev, node_id);
+
+             if (xcc_id >= 0)
+                     return xcc_id;
+     }
+
+     return 0;
+}
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h void amdgpu_amdkfd_unreserve_mem_limit(struct

Quoted 4 lines

index 4ed49265c764..bf8bb45d8ab6 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +0 -0
@@ -356,6 +356,7 @@ void amdgpu_amdkfd_unreserve_mem_limit(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h void amdgpu_amdkfd_unreserve_mem_limit(struct amdgpu_device *adev,

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +0 -0
               uint64_t size, u32 alloc_flag, int8_t xcp_id);
 
   u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int

xcp_id);

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h void amdgpu_amdkfd_unreserve_mem_limit(struct · line 359

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
+int amdgpu_amdkfd_node_id_to_xcc_id(struct amdgpu_device *adev,

uint32_t node_id);

Review

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +0 -0
   #define KFD_XCP_MEM_ID(adev, xcp_id) \
               ((adev)->xcp_mgr && (xcp_id) >= 0 ?\
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static enum drm_gpu_sched_stat

Quoted 4 lines

index c6a1783fc9ef..bf9f8802e18d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
@@ -37,7 +37,7 @@ static enum drm_gpu_sched_stat

amdgpu_job_timedout(struct drm_sched_job *s_job)

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static enum drm_gpu_sched_stat

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -1
       struct amdgpu_job *job = to_amdgpu_job(s_job);
       struct amdgpu_task_info *ti;
       struct amdgpu_device *adev = ring->adev;
-     int idx;
+     int idx, xcp_id = !job->vm ? 0 : job->vm->xcp_id;
       int r;
 
       if (!drm_dev_enter(adev_to_drm(adev), &idx)) {
@@ -62,7 +62,7 @@ static enum drm_gpu_sched_stat

amdgpu_job_timedout(struct drm_sched_job *s_job)

Review

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -1
               job->base.sched->name, atomic_read(&ring->fence_drv.last_seq),
               ring->fence_drv.sync_seq);
 
-     ti = amdgpu_vm_get_task_info_pasid(ring->adev, job->pasid);
+     ti = amdgpu_vm_get_task_info_pasid(ring->adev, job->pasid, xcp_id);
       if (ti) {
               dev_err(adev->dev,
                       "Process information: process %s pid %d thread %s pid %d\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_info_ioctl(struct drm_device *dev,

Quoted 4 lines

index d9fde38f6ee2..e413bf4a3e84 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
@@ -1275,17 +1275,20 @@ int amdgpu_info_ioctl(struct drm_device *dev,

void *data, struct drm_file *filp)

Review

Quoted 23 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -2
               struct amdgpu_vm *vm = &fpriv->vm;
               struct drm_amdgpu_info_gpuvm_fault gpuvm_fault;
               unsigned long flags;
+             int i;
 
               if (!vm)
                       return -EINVAL;
 
               memset(&gpuvm_fault, 0, sizeof(gpuvm_fault));
 
-             xa_lock_irqsave(&adev->vm_manager.pasids, flags);
+             for (i = 0; i < adev->xcp_mgr->num_xcps; i++)
+                     xa_lock_irqsave(&adev->vm_manager.pasids[i], flags);
               gpuvm_fault.addr = vm->fault_info.addr;
               gpuvm_fault.status = vm->fault_info.status;
               gpuvm_fault.vmhub = vm->fault_info.vmhub;
-             xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
+             for (i = 0; i < adev->xcp_mgr->num_xcps; i++)
+                     xa_unlock_irqrestore(&adev->vm_manager.pasids[i], flags);
 
               return copy_to_user(out, &gpuvm_fault,
                                   min((size_t)size, sizeof(gpuvm_fault))) ? -EFAULT : 0;
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_set_pasid(struct amdgpu_device

Quoted 4 lines

index bcb729094521..f43e1c15f423 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
@@ -146,7 +146,7 @@ int amdgpu_vm_set_pasid(struct amdgpu_device

*adev, struct amdgpu_vm *vm,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm,

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
               return 0;
 
       if (vm->pasid) {
-             r = xa_err(xa_erase_irq(&adev->vm_manager.pasids, vm->pasid));
+             r = xa_err(xa_erase_irq(&adev->vm_manager.pasids[vm->xcp_id],

vm->pasid));

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_set_pasid(struct amdgpu_device

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
               if (r < 0)
                       return r;
 
@@ -154,7 +154,7 @@ int amdgpu_vm_set_pasid(struct amdgpu_device

*adev, struct amdgpu_vm *vm,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm,

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
       }
 
       if (pasid) {
-             r = xa_err(xa_store_irq(&adev->vm_manager.pasids, pasid, vm,
+             r = xa_err(xa_store_irq(&adev->vm_manager.pasids[vm->xcp_id],

pasid, vm,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static void

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
                                       GFP_KERNEL));
               if (r < 0)
                       return r;
@@ -2288,14 +2288,14 @@ static void

amdgpu_vm_destroy_task_info(struct kref *kref)

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static void amdgpu_vm_destroy_task_info(struct kref *kref)

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
   }
 
   static inline struct amdgpu_vm *
-amdgpu_vm_get_vm_from_pasid(struct amdgpu_device *adev, u32 pasid)
+amdgpu_vm_get_vm_from_pasid(struct amdgpu_device *adev, u32 pasid,

u32 xcp_id)

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c amdgpu_vm_get_task_info_vm(struct

Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -3
   {
       struct amdgpu_vm *vm;
       unsigned long flags;
 
-     xa_lock_irqsave(&adev->vm_manager.pasids, flags);
-     vm = xa_load(&adev->vm_manager.pasids, pasid);
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
+     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], flags);
+     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
+     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], flags);
 
       return vm;
   }
@@ -2343,10 +2343,10 @@ amdgpu_vm_get_task_info_vm(struct

amdgpu_vm *vm)

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c amdgpu_vm_get_task_info_vm(struct amdgpu_vm *vm)

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
    * referenced down with amdgpu_vm_put_task_info.
    */
   struct amdgpu_task_info *
-amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid)
+amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid,

u32 xcp_id)

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_init(struct amdgpu_device

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
   {
       return amdgpu_vm_get_task_info_vm(
-                     amdgpu_vm_get_vm_from_pasid(adev, pasid));
+                     amdgpu_vm_get_vm_from_pasid(adev, pasid, xcp_id));
   }
 
   static int amdgpu_vm_create_task_info(struct amdgpu_vm *vm)
@@ -2481,6 +2481,8 @@ int amdgpu_vm_init(struct amdgpu_device

*adev, struct amdgpu_vm *vm,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_manager_init(struct

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -0
       amdgpu_bo_unreserve(vm->root.bo);
       amdgpu_bo_unref(&root_bo);
 
+     vm->xcp_id = xcp_id < 0 ? 0 : xcp_id;
+
       return 0;
 
   error_free_root:
@@ -2695,8 +2697,8 @@ void amdgpu_vm_manager_init(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_manager_init(struct amdgpu_device *adev)

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -2
   #else
       adev->vm_manager.vm_update_mode = 0;
   #endif
-
-     xa_init_flags(&adev->vm_manager.pasids, XA_FLAGS_LOCK_IRQ);
+     for (i = 0; i < MAX_XCP; i++)
+             xa_init_flags(&(adev->vm_manager.pasids[i]),

XA_FLAGS_LOCK_IRQ);

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_manager_init(struct

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
   }
 
   /**
@@ -2708,10 +2710,15 @@ void amdgpu_vm_manager_init(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c bool amdgpu_vm_handle_fault(struct

Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7 -2
    */
   void amdgpu_vm_manager_fini(struct amdgpu_device *adev)
   {
-     WARN_ON(!xa_empty(&adev->vm_manager.pasids));
-     xa_destroy(&adev->vm_manager.pasids);
+     int i;
+
+     for (i = 0; i < MAX_XCP; i++) {
+             WARN_ON(!xa_empty(&adev->vm_manager.pasids[i]));
+             xa_destroy(&adev->vm_manager.pasids[i]);
+     }
 
       amdgpu_vmid_mgr_fini(adev);
+
   }
 
   /**
@@ -2778,17 +2785,18 @@ bool amdgpu_vm_handle_fault(struct

amdgpu_device *adev, u32 pasid,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c bool amdgpu_vm_handle_fault(struct

Quoted 24 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5 -4
       unsigned long irqflags;
       uint64_t value, flags;
       struct amdgpu_vm *vm;
-     int r;
+     int r, xcp_id;
 
-     xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
-     vm = xa_load(&adev->vm_manager.pasids, pasid);
+     xcp_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, node_id)/adev-
 gfx.num_xcc_per_xcp;
+     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], irqflags);
+     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
       if (vm) {
               root = amdgpu_bo_ref(vm->root.bo);
               is_compute_context = vm->is_compute_context;
       } else {
               root = NULL;
       }
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, irqflags);
+     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], irqflags);
 
       if (!root)
               return false;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
@@ -2806,11 +2814,11 @@ bool amdgpu_vm_handle_fault(struct

amdgpu_device *adev, u32 pasid,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_update_fault_cache(struct

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -3
               goto error_unref;
 
       /* Double check that the VM still exists */
-     xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
-     vm = xa_load(&adev->vm_manager.pasids, pasid);
+     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], irqflags);
+     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
       if (vm && vm->root.bo != root)
               vm = NULL;
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, irqflags);
+     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], irqflags);
       if (!vm)
               goto error_unlock;
 
@@ -2968,14 +2976,15 @@ void amdgpu_vm_update_fault_cache(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_update_fault_cache(struct

Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -3
                                 unsigned int pasid,
                                 uint64_t addr,
                                 uint32_t status,
-                               unsigned int vmhub)
+                               unsigned int vmhub,
+                               uint32_t xcp_id)
   {
       struct amdgpu_vm *vm;
       unsigned long flags;
 
-     xa_lock_irqsave(&adev->vm_manager.pasids, flags);
+     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], flags);
 
-     vm = xa_load(&adev->vm_manager.pasids, pasid);
+     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
       /* Don't update the fault cache if status is 0.  In the multiple
        * fault case, subsequent faults will return a 0 status which is
        * useless for userspace and replaces the useful fault status, so
@@ -3008,7 +3017,7 @@ void amdgpu_vm_update_fault_cache(struct

amdgpu_device *adev,

Review

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
                       WARN_ONCE(1, "Invalid vmhub %u\n", vmhub);
               }
       }
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
+     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], flags);
   }
 
   /**
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h bool amdgpu_vm_need_pipeline_sync(struct

Quoted 31 lines

index 046949c4b695..1499f5f731e9 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +5 -1
@@ -35,6 +35,7 @@
   #include "amdgpu_sync.h"
   #include "amdgpu_ring.h"
   #include "amdgpu_ids.h"
+#include "amdgpu_xcp.h"
 
   struct drm_exec;
 
@@ -418,6 +419,9 @@ struct amdgpu_vm {
 
       /* cached fault info */
       struct amdgpu_vm_fault_info fault_info;
+
+     /* XCP ID */
+     int xcp_id;
   };
 
   struct amdgpu_vm_manager {
@@ -456,7 +460,7 @@ struct amdgpu_vm_manager {
       /* PASID to VM mapping, will be used in interrupt context to
        * look up VM of a page fault
        */
-     struct xarray                           pasids;
+     struct xarray                           pasids[MAX_XCP];
       /* Global registration of recent page fault information */
       struct amdgpu_vm_fault_info     fault_info;
   };
@@ -550,7 +554,7 @@ bool amdgpu_vm_need_pipeline_sync(struct

amdgpu_ring *ring,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h bool amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring,

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -1
   void amdgpu_vm_check_compute_bug(struct amdgpu_device *adev);
 
   struct amdgpu_task_info *
-amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid);
+amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid,

u32 xcp_id);

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h void amdgpu_vm_update_fault_cache(struct

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
   struct amdgpu_task_info *
   amdgpu_vm_get_task_info_vm(struct amdgpu_vm *vm);
@@ -649,7 +653,8 @@ void amdgpu_vm_update_fault_cache(struct

amdgpu_device *adev,

Review

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +2 -1
                                 unsigned int pasid,
                                 uint64_t addr,
                                 uint32_t status,
-                               unsigned int vmhub);
+                               unsigned int vmhub,
+                               uint32_t xcp_id);
   void amdgpu_vm_tlb_fence_create(struct amdgpu_device *adev,
                                struct amdgpu_vm *vm,
                                struct dma_fence **fence);
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c

drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c static int gmc_v10_0_process_interrupt(struct

Quoted 4 lines

index f0ceab3ce5bf..24b042febf5c 100644

drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +0 -0
@@ -151,7 +151,8 @@ static int gmc_v10_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c static int gmc_v10_0_process_interrupt(struct amdgpu_device *adev,

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +0 -1
               WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
 
               amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,
-                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :

AMDGPU_GFXHUB(0));

drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c static int gmc_v10_0_process_interrupt(struct · line 154

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +1 -0
+                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :

AMDGPU_GFXHUB(0),

drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c static int gmc_v10_0_process_interrupt(struct

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +1 -0
+                                          0);
       }
 
       if (!printk_ratelimit())
@@ -161,7 +162,7 @@ static int gmc_v10_0_process_interrupt(struct

amdgpu_device *adev,

Review

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +1 -1
               "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
               entry->vmid_src ? "mmhub" : "gfxhub",
               entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
-     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
       if (task_info) {
               dev_err(adev->dev,
                       " in process %s pid %d thread %s pid %d\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c

drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c static int gmc_v11_0_process_interrupt(struct

Quoted 4 lines

index 2797fd84432b..3507046d33e6 100644

drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +0 -0
@@ -122,7 +122,8 @@ static int gmc_v11_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c static int gmc_v11_0_process_interrupt(struct · line 125

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +0 -1
               WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
 
               amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,
-                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :

AMDGPU_GFXHUB(0));

drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c static int gmc_v11_0_process_interrupt(struct · line 125

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +1 -0
+                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :

AMDGPU_GFXHUB(0),

drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c static int gmc_v11_0_process_interrupt(struct

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +1 -0
+                                          0);
       }
 
       if (printk_ratelimit()) {
@@ -132,7 +133,7 @@ static int gmc_v11_0_process_interrupt(struct

amdgpu_device *adev,

Review

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +1 -1
                       "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
                       entry->vmid_src ? "mmhub" : "gfxhub",
                       entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
-             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
               if (task_info) {
                       dev_err(adev->dev,
                               " in process %s pid %d thread %s pid %d)\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static int gmc_v12_0_process_interrupt(struct

Quoted 4 lines

index 60acf676000b..9844564c6c74 100644

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -0
@@ -115,7 +115,8 @@ static int gmc_v12_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static int gmc_v12_0_process_interrupt(struct · line 118

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -1
               WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
 
               amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,
-                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :

AMDGPU_GFXHUB(0));

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static int gmc_v12_0_process_interrupt(struct · line 118

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +1 -0
+                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :

AMDGPU_GFXHUB(0),

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static int gmc_v12_0_process_interrupt(struct

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +1 -0
+                                          0);
       }
 
       if (printk_ratelimit()) {
@@ -125,7 +126,7 @@ static int gmc_v12_0_process_interrupt(struct

amdgpu_device *adev,

Review

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +1 -1
                       "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
                       entry->vmid_src ? "mmhub" : "gfxhub",
                       entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
-             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
               if (task_info) {
                       dev_err(adev->dev,
                               " in process %s pid %d thread %s pid %d)\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c

drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c static int gmc_v7_0_process_interrupt(struct

Quoted 4 lines

index 994432fb57ea..2cdb0cbb7c4d 100644

drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +0 -0
@@ -1268,7 +1268,8 @@ static int gmc_v7_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c static int gmc_v7_0_process_interrupt(struct amdgpu_device *adev,

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +0 -1
               return 0;
 
       amdgpu_vm_update_fault_cache(adev, entry->pasid,
-                                  ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,

AMDGPU_GFXHUB(0));

Review

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +2 -0
+                                  ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
+                                  AMDGPU_GFXHUB(0), 0);
 
       if (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_FIRST)
               gmc_v7_0_set_fault_enable_default(adev, false);
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct

Quoted 4 lines

index 86488c052f82..6855caeb7f74 100644

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0 -0
@@ -1437,7 +1437,8 @@ static int gmc_v8_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct · line 1440

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0 -1
               return 0;
 
       amdgpu_vm_update_fault_cache(adev, entry->pasid,
-                                  ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,

AMDGPU_GFXHUB(0));

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +2 -0
+                                  ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
+                                  AMDGPU_GFXHUB(0), 0);
 
       if (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_FIRST)
               gmc_v8_0_set_fault_enable_default(adev, false);
@@ -1448,7 +1449,7 @@ static int gmc_v8_0_process_interrupt(struct

amdgpu_device *adev,

Review

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1 -1
               dev_err(adev->dev, "GPU fault detected: %d 0x%08x\n",
                       entry->src_id, entry->src_data[0]);
 
-             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
               if (task_info) {
                       dev_err(adev->dev, " for process %s pid %d thread %s pid %d\n",
                               task_info->process_name, task_info->tgid,
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct

Quoted 4 lines

index b73136d390cc..e183e08b2c02 100644

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
@@ -556,10 +556,12 @@ static int gmc_v9_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +4 -2
       unsigned int vmhub;
       u64 addr;
       uint32_t cam_index = 0;
-     int ret, xcc_id = 0;
-     uint32_t node_id;
+     int ret;
+     uint32_t node_id, xcc_id, xcp_id;
 
       node_id = entry->node_id;
+     xcc_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, node_id);
+     xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;
 
       addr = (u64)entry->src_data[0] << 12;
       addr |= ((u64)entry->src_data[1] & 0xf) << 44;
@@ -572,12 +574,6 @@ static int gmc_v9_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -6
               vmhub = AMDGPU_MMHUB1(0);
       } else {
               hub_name = "gfxhub0";
-             if (adev->gfx.funcs->ih_node_to_logical_xcc) {
-                     xcc_id = adev->gfx.funcs->ih_node_to_logical_xcc(adev,
-                             node_id);
-                     if (xcc_id < 0)
-                             xcc_id = 0;
-             }
               vmhub = xcc_id;
       }
       hub = &adev->vmhub[vmhub];
@@ -631,7 +627,7 @@ static int gmc_v9_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -1
               retry_fault ? "retry" : "no-retry",
               entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
 
-     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid,

xcp_id);

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
       if (task_info) {
               dev_err(adev->dev,
                       " for process %s pid %d thread %s pid %d)\n",
@@ -675,7 +671,7 @@ static int gmc_v9_0_process_interrupt(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -1
       if (!amdgpu_sriov_vf(adev))
               WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);
 
-     amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,

vmhub);

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct · line 674

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
+     amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,

vmhub, xcp_id);

Review

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
       dev_err(adev->dev,
               "VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c

drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c static int sdma_v4_0_print_iv_entry(struct

Quoted 4 lines

index 23ef4eb36b40..1ac4224bbe5b 100644

drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +0 -0
@@ -2182,7 +2182,7 @@ static int sdma_v4_0_print_iv_entry(struct

amdgpu_device *adev,

Review

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +1 -1
                          instance, addr, entry->src_id, entry->ring_id, entry->vmid,
                          entry->pasid);
 
-     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
       if (task_info) {
               dev_dbg_ratelimited(adev->dev,
                                   " for process %s pid %d thread %s pid %d\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_print_iv_entry(struct

Quoted 4 lines

index 57f16c09abfc..c8b5c0302ca7 100644

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -0
@@ -1683,6 +1683,8 @@ static int sdma_v4_4_2_print_iv_entry(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_print_iv_entry(struct

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2 -0
       int instance;
       struct amdgpu_task_info *task_info;
       u64 addr;
+     uint32_t xcc_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, entry-
 node_id);
+     uint32_t xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;
 
       instance = sdma_v4_4_2_irq_id_to_seq(adev, entry->client_id);
       if (instance < 0 || instance >= adev->sdma.num_instances) {
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -0
@@ -1698,7 +1700,7 @@ static int sdma_v4_4_2_print_iv_entry(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_print_iv_entry(struct · line 1703

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1 -1
                           instance, addr, entry->src_id, entry->ring_id, entry->vmid,
                           entry->pasid);
 
-     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid,

xcp_id);

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_print_iv_entry(struct · line 1705

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -0
       if (task_info) {
               dev_dbg_ratelimited(adev->dev, " for process %s pid %d thread %s

pid %d\n",

Review

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -0
                                   task_info->process_name, task_info->tgid,
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_events.c

drivers/gpu/drm/amd/amdkfd/kfd_events.c void kfd_signal_reset_event(struct kfd_node

Quoted 4 lines

index ea3792249209..c098fbaf0e1c 100644

drivers/gpu/drm/amd/amdkfd/kfd_events.c +0 -0
@@ -1262,8 +1262,9 @@ void kfd_signal_reset_event(struct kfd_node

*dev)

drivers/gpu/drm/amd/amdkfd/kfd_events.c void kfd_signal_reset_event(struct kfd_node *dev)

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -1
               if (dev->dqm->detect_hang_count) {
                       struct amdgpu_task_info *ti;
+                     uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;
 
-                     ti = amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid);
+                     ti = amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid,

xcp_id);

Review

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +0 -0
                       if (ti) {
                               dev_err(dev->adev->dev,
                                       "Queues reset on process %s tid %d thread %s pid %d\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c static void event_interrupt_wq_v10(struct

Quoted 4 lines

index 8e0d0356e810..d7cbf9525698 100644

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c +0 -0
@@ -377,12 +377,8 @@ static void event_interrupt_wq_v10(struct

kfd_node *dev,

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c static void event_interrupt_wq_v10(struct kfd_node *dev,

Quoted 12 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c +2 -6
               struct kfd_hsa_memory_exception_data exception_data;
 
               /* gfxhub */
-             if (!vmid_type && dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
-                     hub_inst = dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev-
 adev,
-                             node_id);
-                     if (hub_inst < 0)
-                             hub_inst = 0;
-             }
+             if (!vmid_type)
+                     hub_inst = amdgpu_amdkfd_node_id_to_xcc_id(dev->adev,

node_id);

Review

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c +0 -0
               /* mmhub */
               if (vmid_type && client_id == SOC15_IH_CLIENTID_VMC)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_wq_v9(struct

Quoted 4 lines

index a9c3580be8c9..4708b8c811a5 100644

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -0
@@ -437,12 +437,8 @@ static void event_interrupt_wq_v9(struct

kfd_node *dev,

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c static void event_interrupt_wq_v9(struct · line 442

Quoted 12 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +2 -6
               struct kfd_hsa_memory_exception_data exception_data;
 
               /* gfxhub */
-             if (!vmid_type && dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
-                     hub_inst = dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev-
 adev,
-                             node_id);
-                     if (hub_inst < 0)
-                             hub_inst = 0;
-             }
+             if (!vmid_type)
+                     hub_inst = amdgpu_amdkfd_node_id_to_xcc_id(dev->adev,

node_id);

Review

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -0
               /* mmhub */
               if (vmid_type && client_id == SOC15_IH_CLIENTID_VMC)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c

drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c void

Quoted 4 lines

index ea6a8e43bd5b..b5f2f5b1069c 100644

drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +0 -0
@@ -251,8 +251,9 @@ void

kfd_smi_event_update_thermal_throttling(struct kfd_node *dev,

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +2 -1
   void kfd_smi_event_update_vmfault(struct kfd_node *dev, uint16_t pasid)
   {
       struct amdgpu_task_info *task_info;
+     uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;
 
-     task_info = amdgpu_vm_get_task_info_pasid(dev->adev, pasid);
+     task_info = amdgpu_vm_get_task_info_pasid(dev->adev, pasid, xcp_id);
       if (task_info) {
               /* Report VM faults from user applications, not retry from kernel */
               if (task_info->pid)
#4 lore raw

On 2024-09-09 14:46, Christian König wrote:
Am 09.09.24 um 18:02 schrieb Kim, Jonathan:
[Public]

-----Original Message-----
From: Christian König <[email protected]>
Sent: Thursday, September 5, 2024 10:24 AM
To: Kim, Jonathan <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]>
Subject: Re: [PATCH] drm/amdkfd: fix vm-pasid lookup for multiple partitions

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Am 19.08.24 um 19:59 schrieb Jonathan Kim:
Currently multiple partitions will incorrectly overwrite the VM lookup
table since the table is indexed by PASID and multiple partitions can
register different VM objects on the same PASID.
That's a rather bad idea. Why do we have the same PASID for different VM
objects in the first place?
Alex can probably elaborate on the KGD side, but from what I can see, the KMS driver open call has always assigned a new VM object per PASID on an open call. The KFD acquires and replaces the KGD PASID-VMID registration on its own compute process open/creation call.
If this is the bad_idea you're referring to, then someone else will have to chime in.  I don't have much history on this unfortunately.

Yeah, Felix and I designed that.
app opens drm node to create vm for each partition, with different vm->pasid for each vm, issue is from kfd_ioctl_acquire_vm -> kfd_process_device_init_vm ->  amdgpu_amdkfd_gpuvm_set_vm_pasid, to replace all vm->pasid with kfd process->pasid, which is from open kfd node. This ends up to store only one vm to adev->vm_manager.pasids with KFD process pasid, so we cannot retrieve correct vm from adev->vm_manager.pasids on mGPUs or multiple partitions.

That aside, the current problem is, is that all KFD device structures are logical partitions and register their PASID-VM binding using this concept of a device.

As far as I can see that is the fundamental problem. This needs to be fixed instead.

On the KGD side however, the registration table is maintained in the adev struct, which is a physical socket.
So there's a mismatch in understanding of what a device is between the KFD & KGD with regard to the look up table that results in bad bindings.

Adding a per-partition dimension to the existing lookup table resolves issues where seeing, for example, with memory violation interception and XNACK i.e bad bindings result in wrong vm object found to set no-retry flags on memory violations. svm_range_restore_pages retry fault recover uses fault pasid to get kfd process, and use the fault node_id to get pdd->vm, maybe you can use this way to fix the debugger issue.

Regards,
Philip

Yeah that is pretty much a no-go.

The PASID and how it is used is defined by the PCIe specifications. If we now start to assign multiple VMs to the same PASID then we are violating the PCIe specification.

The problems you see are most likely just the tip of the iceberg here.

Regards,
Christian.

Jon

Regards,
Christian.

This results in loading the wrong VM object on PASID query.

To correct this, setup the lookup table to be per-partition-per-PASID instead.

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    | 12 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |  1 + drivers/gpu/drm/amd/amdgpu/amdgpu_job.c       |  4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |  7 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 55 +++++++++++------ --

   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h        | 11 +++-
   drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c        |  5 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c        |  5 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c        |  5 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c         |  3 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c         |  5 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c         | 16 ++----

   drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c        |  2 +- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c      |  4 +- drivers/gpu/drm/amd/amdkfd/kfd_events.c       |  3 +- .../gpu/drm/amd/amdkfd/kfd_int_process_v10.c  |  8 +-- .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c   |  8 +-- drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c   |  3 +-

   18 files changed, 92 insertions(+), 65 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index c272461d70a9..28db789610e1 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0 -0
@@ -887,3 +887,15 @@ int amdgpu_amdkfd_unmap_hiq(struct

amdgpu_device *adev, u32 doorbell_off,
       return r;
   }
+
+int amdgpu_amdkfd_node_id_to_xcc_id(struct amdgpu_device *adev, uint32_t node_id)
+{
+     if (adev->gfx.funcs->ih_node_to_logical_xcc) {
+             int xcc_id = adev->gfx.funcs->ih_node_to_logical_xcc(adev, node_id); +
+             if (xcc_id >= 0)
+                     return xcc_id;
+     }
+
+     return 0;
+}

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index 4ed49265c764..bf8bb45d8ab6 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +0 -0
@@ -356,6 +356,7 @@ void amdgpu_amdkfd_unreserve_mem_limit(struct

amdgpu_device *adev,
               uint64_t size, u32 alloc_flag, int8_t xcp_id);

   u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int xcp_id);
+int amdgpu_amdkfd_node_id_to_xcc_id(struct amdgpu_device *adev, uint32_t node_id);
   #define KFD_XCP_MEM_ID(adev, xcp_id) \
               ((adev)->xcp_mgr && (xcp_id) >= 0 ?\

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
index c6a1783fc9ef..bf9f8802e18d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
@@ -37,7 +37,7 @@ static enum drm_gpu_sched_stat

amdgpu_job_timedout(struct drm_sched_job *s_job) struct amdgpu_job *job = to_amdgpu_job(s_job); struct amdgpu_task_info *ti;
       struct amdgpu_device *adev = ring->adev; -     int idx;
+     int idx, xcp_id = !job->vm ? 0 : job->vm->xcp_id; int r;

       if (!drm_dev_enter(adev_to_drm(adev), &idx)) {
@@ -62,7 +62,7 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) job->base.sched->name, atomic_read(&ring->fence_drv.last_seq), ring->fence_drv.sync_seq);

-     ti = amdgpu_vm_get_task_info_pasid(ring->adev, job->pasid);
+     ti = amdgpu_vm_get_task_info_pasid(ring->adev, job->pasid, xcp_id); if (ti) {
               dev_err(adev->dev,
                       "Process information: process %s pid %d thread %s pid %d\n",

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index d9fde38f6ee2..e413bf4a3e84 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
@@ -1275,17 +1275,20 @@ int amdgpu_info_ioctl(struct drm_device *dev,

void *data, struct drm_file *filp)
               struct amdgpu_vm *vm = &fpriv->vm; struct drm_amdgpu_info_gpuvm_fault gpuvm_fault; unsigned long flags;
+             int i;

               if (!vm)
                       return -EINVAL;

               memset(&gpuvm_fault, 0, sizeof(gpuvm_fault));

-             xa_lock_irqsave(&adev->vm_manager.pasids, flags);
+             for (i = 0; i < adev->xcp_mgr->num_xcps; i++)
+                     xa_lock_irqsave(&adev->vm_manager.pasids[i], flags); gpuvm_fault.addr = vm->fault_info.addr; gpuvm_fault.status = vm->fault_info.status; gpuvm_fault.vmhub = vm->fault_info.vmhub;
-             xa_unlock_irqrestore(&adev->vm_manager.pasids, flags); +             for (i = 0; i < adev->xcp_mgr->num_xcps; i++)
+                     xa_unlock_irqrestore(&adev->vm_manager.pasids[i], flags);

               return copy_to_user(out, &gpuvm_fault,
                                   min((size_t)size, sizeof(gpuvm_fault))) ? -EFAULT : 0;

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index bcb729094521..f43e1c15f423 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
@@ -146,7 +146,7 @@ int amdgpu_vm_set_pasid(struct amdgpu_device

*adev, struct amdgpu_vm *vm,
               return 0;

       if (vm->pasid) {
-             r = xa_err(xa_erase_irq(&adev->vm_manager.pasids, vm->pasid)); +             r = xa_err(xa_erase_irq(&adev->vm_manager.pasids[vm->xcp_id], vm->pasid));
               if (r < 0)
                       return r;

@@ -154,7 +154,7 @@ int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm,
       }

       if (pasid) {
-             r = xa_err(xa_store_irq(&adev->vm_manager.pasids, pasid, vm, +             r = xa_err(xa_store_irq(&adev->vm_manager.pasids[vm->xcp_id], pasid, vm,
                                       GFP_KERNEL));
               if (r < 0)
                       return r;
@@ -2288,14 +2288,14 @@ static void amdgpu_vm_destroy_task_info(struct kref *kref)
   }

   static inline struct amdgpu_vm * -amdgpu_vm_get_vm_from_pasid(struct amdgpu_device *adev, u32 pasid) +amdgpu_vm_get_vm_from_pasid(struct amdgpu_device *adev, u32 pasid, u32 xcp_id)
   {
       struct amdgpu_vm *vm;
       unsigned long flags;

-     xa_lock_irqsave(&adev->vm_manager.pasids, flags);
-     vm = xa_load(&adev->vm_manager.pasids, pasid);
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, flags); +     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], flags); +     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid); +     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], flags);

       return vm;
   }
@@ -2343,10 +2343,10 @@ amdgpu_vm_get_task_info_vm(struct amdgpu_vm *vm)
    * referenced down with amdgpu_vm_put_task_info.
    */
   struct amdgpu_task_info * -amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid) +amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid, u32 xcp_id)
   {
       return amdgpu_vm_get_task_info_vm(
-                     amdgpu_vm_get_vm_from_pasid(adev, pasid)); +                     amdgpu_vm_get_vm_from_pasid(adev, pasid, xcp_id)); }

   static int amdgpu_vm_create_task_info(struct amdgpu_vm *vm) @@ -2481,6 +2481,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, amdgpu_bo_unreserve(vm->root.bo); amdgpu_bo_unref(&root_bo);

+     vm->xcp_id = xcp_id < 0 ? 0 : xcp_id;
+
       return 0;

   error_free_root:
@@ -2695,8 +2697,8 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev)
   #else
       adev->vm_manager.vm_update_mode = 0;
   #endif
-
-     xa_init_flags(&adev->vm_manager.pasids, XA_FLAGS_LOCK_IRQ); +     for (i = 0; i < MAX_XCP; i++)
+             xa_init_flags(&(adev->vm_manager.pasids[i]), XA_FLAGS_LOCK_IRQ);
   }

   /**
@@ -2708,10 +2710,15 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev)
    */
   void amdgpu_vm_manager_fini(struct amdgpu_device *adev) {
-     WARN_ON(!xa_empty(&adev->vm_manager.pasids)); -     xa_destroy(&adev->vm_manager.pasids);
+     int i;
+
+     for (i = 0; i < MAX_XCP; i++) {
+             WARN_ON(!xa_empty(&adev->vm_manager.pasids[i])); +             xa_destroy(&adev->vm_manager.pasids[i]); +     }

       amdgpu_vmid_mgr_fini(adev);
+
   }

   /**
@@ -2778,17 +2785,18 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid,
       unsigned long irqflags;
       uint64_t value, flags;
       struct amdgpu_vm *vm;
-     int r;
+     int r, xcp_id;

-     xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
-     vm = xa_load(&adev->vm_manager.pasids, pasid);
+     xcp_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, node_id)/adev- gfx.num_xcc_per_xcp;
+     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], irqflags); +     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid); if (vm) {
               root = amdgpu_bo_ref(vm->root.bo); is_compute_context = vm->is_compute_context; } else {
               root = NULL;
       }
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, irqflags); +     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], irqflags);

       if (!root)
               return false;
@@ -2806,11 +2814,11 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid,
               goto error_unref;

       /* Double check that the VM still exists */
-     xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
-     vm = xa_load(&adev->vm_manager.pasids, pasid);
+     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], irqflags); +     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid); if (vm && vm->root.bo != root)
               vm = NULL;
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, irqflags); +     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], irqflags); if (!vm)
               goto error_unlock;

@@ -2968,14 +2976,15 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev,
                                 unsigned int pasid, uint64_t addr, uint32_t status,
-                               unsigned int vmhub)
+                               unsigned int vmhub,
+                               uint32_t xcp_id)
   {
       struct amdgpu_vm *vm;
       unsigned long flags;

-     xa_lock_irqsave(&adev->vm_manager.pasids, flags); +     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], flags);

-     vm = xa_load(&adev->vm_manager.pasids, pasid);
+     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid); /* Don't update the fault cache if status is 0.  In the multiple
        * fault case, subsequent faults will return a 0 status which is
        * useless for userspace and replaces the useful fault status, so @@ -3008,7 +3017,7 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev,
                       WARN_ONCE(1, "Invalid vmhub %u\n", vmhub); }
       }
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, flags); +     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], flags); }

   /**

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index 046949c4b695..1499f5f731e9 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
@@ -35,6 +35,7 @@

   #include "amdgpu_sync.h"
   #include "amdgpu_ring.h"
   #include "amdgpu_ids.h"
+#include "amdgpu_xcp.h"

   struct drm_exec;

@@ -418,6 +419,9 @@ struct amdgpu_vm {

       /* cached fault info */
       struct amdgpu_vm_fault_info fault_info;
+
+     /* XCP ID */
+     int xcp_id;
   };

   struct amdgpu_vm_manager {
@@ -456,7 +460,7 @@ struct amdgpu_vm_manager {
       /* PASID to VM mapping, will be used in interrupt context to
        * look up VM of a page fault
        */
-     struct xarray                           pasids;
+     struct xarray                           pasids[MAX_XCP]; /* Global registration of recent page fault information */ struct amdgpu_vm_fault_info     fault_info;
   };
@@ -550,7 +554,7 @@ bool amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring,
   void amdgpu_vm_check_compute_bug(struct amdgpu_device *adev);

   struct amdgpu_task_info * -amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid); +amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid, u32 xcp_id);
   struct amdgpu_task_info * amdgpu_vm_get_task_info_vm(struct amdgpu_vm *vm);
@@ -649,7 +653,8 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev,
                                 unsigned int pasid, uint64_t addr,
                                 uint32_t status,
-                               unsigned int vmhub);
+                               unsigned int vmhub,
+                               uint32_t xcp_id);
   void amdgpu_vm_tlb_fence_create(struct amdgpu_device *adev, struct amdgpu_vm *vm, struct dma_fence **fence);

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
index f0ceab3ce5bf..24b042febf5c 100644

drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +0 -0
@@ -151,7 +151,8 @@ static int gmc_v10_0_process_interrupt(struct

amdgpu_device *adev, WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

               amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status, -                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0));
+                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0),
+                                          0);
       }

       if (!printk_ratelimit())
@@ -161,7 +162,7 @@ static int gmc_v10_0_process_interrupt(struct amdgpu_device *adev,
               "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n", entry->vmid_src ? "mmhub" : "gfxhub", entry->src_id, entry->ring_id, entry->vmid, entry->pasid); -     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid); +     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0); if (task_info) {
               dev_err(adev->dev,
                       " in process %s pid %d thread %s pid %d\n",

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c
index 2797fd84432b..3507046d33e6 100644

drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +0 -0
@@ -122,7 +122,8 @@ static int gmc_v11_0_process_interrupt(struct

amdgpu_device *adev, WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

               amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status, -                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0));
+                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0),
+                                          0);
       }

       if (printk_ratelimit()) {
@@ -132,7 +133,7 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev,
                       "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n", entry->vmid_src ? "mmhub" : "gfxhub", entry->src_id, entry->ring_id, entry->vmid, entry->pasid); -             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid); +             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0); if (task_info) {
                       dev_err(adev->dev,
                               " in process %s pid %d thread %s pid %d)\n",

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c
index 60acf676000b..9844564c6c74 100644

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -0
@@ -115,7 +115,8 @@ static int gmc_v12_0_process_interrupt(struct

amdgpu_device *adev, WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

               amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status, -                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0));
+                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0),
+                                          0);
       }

       if (printk_ratelimit()) {
@@ -125,7 +126,7 @@ static int gmc_v12_0_process_interrupt(struct amdgpu_device *adev,
                       "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n", entry->vmid_src ? "mmhub" : "gfxhub", entry->src_id, entry->ring_id, entry->vmid, entry->pasid); -             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid); +             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0); if (task_info) {
                       dev_err(adev->dev,
                               " in process %s pid %d thread %s pid %d)\n",

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
index 994432fb57ea..2cdb0cbb7c4d 100644

drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +0 -0
@@ -1268,7 +1268,8 @@ static int gmc_v7_0_process_interrupt(struct

amdgpu_device *adev,
               return 0;

       amdgpu_vm_update_fault_cache(adev, entry->pasid,
-                                  ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status, AMDGPU_GFXHUB(0));
+                                  ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status, +                                  AMDGPU_GFXHUB(0), 0);

       if (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_FIRST) gmc_v7_0_set_fault_enable_default(adev, false);

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
index 86488c052f82..6855caeb7f74 100644

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0 -0
@@ -1437,7 +1437,8 @@ static int gmc_v8_0_process_interrupt(struct

amdgpu_device *adev,
               return 0;

       amdgpu_vm_update_fault_cache(adev, entry->pasid,
-                                  ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status, AMDGPU_GFXHUB(0));
+                                  ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status, +                                  AMDGPU_GFXHUB(0), 0);

       if (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_FIRST) gmc_v8_0_set_fault_enable_default(adev, false); @@ -1448,7 +1449,7 @@ static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev,
               dev_err(adev->dev, "GPU fault detected: %d 0x%08x\n", entry->src_id, entry->src_data[0]);

-             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid); +             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0); if (task_info) {
                       dev_err(adev->dev, " for process %s pid %d thread %s pid %d\n", task_info->process_name, task_info->tgid,

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
index b73136d390cc..e183e08b2c02 100644

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
@@ -556,10 +556,12 @@ static int gmc_v9_0_process_interrupt(struct

amdgpu_device *adev,
       unsigned int vmhub;
       u64 addr;
       uint32_t cam_index = 0;
-     int ret, xcc_id = 0;
-     uint32_t node_id;
+     int ret;
+     uint32_t node_id, xcc_id, xcp_id;

       node_id = entry->node_id;
+     xcc_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, node_id); +     xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;

       addr = (u64)entry->src_data[0] << 12;
       addr |= ((u64)entry->src_data[1] & 0xf) << 44;
@@ -572,12 +574,6 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,
               vmhub = AMDGPU_MMHUB1(0);
       } else {
               hub_name = "gfxhub0";
-             if (adev->gfx.funcs->ih_node_to_logical_xcc) {
-                     xcc_id = adev->gfx.funcs->ih_node_to_logical_xcc(adev, -                             node_id);
-                     if (xcc_id < 0)
-                             xcc_id = 0;
-             }
               vmhub = xcc_id;
       }
       hub = &adev->vmhub[vmhub];
@@ -631,7 +627,7 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,
               retry_fault ? "retry" : "no-retry", entry->src_id, entry->ring_id, entry->vmid, entry->pasid);

-     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid); +     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, xcp_id);
       if (task_info) {
               dev_err(adev->dev,
                       " for process %s pid %d thread %s pid %d)\n", @@ -675,7 +671,7 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,
       if (!amdgpu_sriov_vf(adev)) WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

-     amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status, vmhub);
+     amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status, vmhub, xcp_id);
       dev_err(adev->dev, "VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
index 23ef4eb36b40..1ac4224bbe5b 100644

drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +0 -0
@@ -2182,7 +2182,7 @@ static int sdma_v4_0_print_iv_entry(struct

amdgpu_device *adev,
                          instance, addr, entry->src_id, entry->ring_id, entry->vmid, entry->pasid);

-     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid); +     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0); if (task_info) {
               dev_dbg_ratelimited(adev->dev,
                                   " for process %s pid %d thread %s pid %d\n",

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
index 57f16c09abfc..c8b5c0302ca7 100644

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -0
@@ -1683,6 +1683,8 @@ static int sdma_v4_4_2_print_iv_entry(struct

amdgpu_device *adev,
       int instance;
       struct amdgpu_task_info *task_info;
       u64 addr;
+     uint32_t xcc_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, entry- node_id);
+     uint32_t xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;

       instance = sdma_v4_4_2_irq_id_to_seq(adev, entry->client_id);
       if (instance < 0 || instance >= adev->sdma.num_instances) {
@@ -1698,7 +1700,7 @@ static int sdma_v4_4_2_print_iv_entry(struct amdgpu_device *adev,
                           instance, addr, entry->src_id, entry->ring_id, entry->vmid, entry->pasid);

-     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid); +     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, xcp_id);
       if (task_info) {
               dev_dbg_ratelimited(adev->dev, " for process %s pid %d thread %s pid %d\n",
                                   task_info->process_name, task_info->tgid,

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
index ea3792249209..c098fbaf0e1c 100644

drivers/gpu/drm/amd/amdkfd/kfd_events.c +0 -0
@@ -1262,8 +1262,9 @@ void kfd_signal_reset_event(struct kfd_node

*dev)
               if (dev->dqm->detect_hang_count) {
                       struct amdgpu_task_info *ti;
+                     uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;

-                     ti = amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid); +                     ti = amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid, xcp_id);
                       if (ti) {
                               dev_err(dev->adev->dev,
                                       "Queues reset on process %s tid %d thread %s pid %d\n",

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c index 8e0d0356e810..d7cbf9525698 100644

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c +0 -0
@@ -377,12 +377,8 @@ static void event_interrupt_wq_v10(struct

kfd_node *dev,
               struct kfd_hsa_memory_exception_data exception_data;

               /* gfxhub */
-             if (!vmid_type && dev->adev->gfx.funcs->ih_node_to_logical_xcc) { -                     hub_inst = dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev- adev,
-                             node_id);
-                     if (hub_inst < 0)
-                             hub_inst = 0;
-             }
+             if (!vmid_type)
+                     hub_inst = amdgpu_amdkfd_node_id_to_xcc_id(dev->adev, node_id);
               /* mmhub */
               if (vmid_type && client_id == SOC15_IH_CLIENTID_VMC)

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c
index a9c3580be8c9..4708b8c811a5 100644

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -0
@@ -437,12 +437,8 @@ static void event_interrupt_wq_v9(struct

kfd_node *dev,
               struct kfd_hsa_memory_exception_data exception_data;

               /* gfxhub */
-             if (!vmid_type && dev->adev->gfx.funcs->ih_node_to_logical_xcc) { -                     hub_inst = dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev- adev,
-                             node_id);
-                     if (hub_inst < 0)
-                             hub_inst = 0;
-             }
+             if (!vmid_type)
+                     hub_inst = amdgpu_amdkfd_node_id_to_xcc_id(dev->adev, node_id);
               /* mmhub */
               if (vmid_type && client_id == SOC15_IH_CLIENTID_VMC)

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
index ea6a8e43bd5b..b5f2f5b1069c 100644

drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +0 -0
@@ -251,8 +251,9 @@ void

kfd_smi_event_update_thermal_throttling(struct kfd_node *dev, void kfd_smi_event_update_vmfault(struct kfd_node *dev, uint16_t pasid) {
       struct amdgpu_task_info *task_info;
+     uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;

-     task_info = amdgpu_vm_get_task_info_pasid(dev->adev, pasid);
+     task_info = amdgpu_vm_get_task_info_pasid(dev->adev, pasid, xcp_id); if (task_info) {
               /* Report VM faults from user applications, not retry from kernel */ if (task_info->pid)

#5 lore raw

[Public]

KMS open still set per pasid-vm bindings per adev (socket) so I don’t see how the per-partition overwrite PASID issue is primarily a KFD concern. Are you saying the KFD process devices holds a shadow copy of the correct VM during page restore during fault?
Doesn’t it acquire the wrong VM object on process init in the first place?
Even if it were the case the KFD had a separate VM reference, the underlying IRQ fault handling is still broken.
We probably don’t want to bandage over something to fix one symptom.

Jon

From: Yang, Philip <[email protected]>
Sent: Tuesday, September 10, 2024 11:24 AM
To: Koenig, Christian <[email protected]>; Kim, Jonathan <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]>
Subject: Re: [PATCH] drm/amdkfd: fix vm-pasid lookup for multiple partitions

On 2024-09-09 14:46, Christian König wrote:
Am 09.09.24 um 18:02 schrieb Kim, Jonathan:

[Public]

-----Original Message-----
From: Christian König <[email protected]><mailto:[email protected]>
Sent: Thursday, September 5, 2024 10:24 AM
To: Kim, Jonathan <[email protected]><mailto:[email protected]>; [email protected]<mailto:[email protected]>
Cc: Kuehling, Felix <[email protected]><mailto:[email protected]>; Deucher, Alexander <[email protected]><mailto:[email protected]>; Joshi, Mukul <[email protected]><mailto:[email protected]>
Subject: Re: [PATCH] drm/amdkfd: fix vm-pasid lookup for multiple partitions

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Am 19.08.24 um 19:59 schrieb Jonathan Kim:

Currently multiple partitions will incorrectly overwrite the VM lookup
table since the table is indexed by PASID and multiple partitions can
register different VM objects on the same PASID.
That's a rather bad idea. Why do we have the same PASID for different VM
objects in the first place?
Alex can probably elaborate on the KGD side, but from what I can see, the KMS driver open call has always assigned a new VM object per PASID on an open call. The KFD acquires and replaces the KGD PASID-VMID registration on its own compute process open/creation call.
If this is the bad_idea you're referring to, then someone else will have to chime in. I don't have much history on this unfortunately.

Yeah, Felix and I designed that.

app opens drm node to create vm for each partition, with different vm->pasid for each vm, issue is from kfd_ioctl_acquire_vm -> kfd_process_device_init_vm -> amdgpu_amdkfd_gpuvm_set_vm_pasid, to replace all vm->pasid with kfd process->pasid, which is from open kfd node. This ends up to store only one vm to adev->vm_manager.pasids with KFD process pasid, so we cannot retrieve correct vm from adev->vm_manager.pasids on mGPUs or multiple partitions.

That aside, the current problem is, is that all KFD device structures are logical partitions and register their PASID-VM binding using this concept of a device.

As far as I can see that is the fundamental problem. This needs to be fixed instead.

On the KGD side however, the registration table is maintained in the adev struct, which is a physical socket.
So there's a mismatch in understanding of what a device is between the KFD & KGD with regard to the look up table that results in bad bindings.

Adding a per-partition dimension to the existing lookup table resolves issues where seeing, for example, with memory violation interception and XNACK i.e bad bindings result in wrong vm object found to set no-retry flags on memory violations.

svm_range_restore_pages retry fault recover uses fault pasid to get kfd process, and use the fault node_id to get pdd->vm, maybe you can use this way to fix the debugger issue.

Regards,

Philip

Yeah that is pretty much a no-go.

The PASID and how it is used is defined by the PCIe specifications. If we now start to assign multiple VMs to the same PASID then we are violating the PCIe specification.

The problems you see are most likely just the tip of the iceberg here.

Regards,
Christian.

Jon

Regards,
Christian.

This results in loading the wrong VM object on PASID query.

To correct this, setup the lookup table to be per-partition-per-PASID instead.

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    | 12 ++++
   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |  1 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_job.c       |  4 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |  7 ++-
   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 55 +++++++++++------

--

   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h        | 11 +++-
   drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c        |  5 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c        |  5 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c        |  5 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c         |  3 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c         |  5 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c         | 16 ++----
   drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c        |  2 +-
   drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c      |  4 +-
   drivers/gpu/drm/amd/amdkfd/kfd_events.c       |  3 +-
   .../gpu/drm/amd/amdkfd/kfd_int_process_v10.c  |  8 +--
   .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c   |  8 +--
   drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c   |  3 +-
   18 files changed, 92 insertions(+), 65 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c

index c272461d70a9..28db789610e1 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0 -0
@@ -887,3 +887,15 @@ int amdgpu_amdkfd_unmap_hiq(struct

amdgpu_device *adev, u32 doorbell_off,

       return r;

}
+
+int amdgpu_amdkfd_node_id_to_xcc_id(struct amdgpu_device *adev, uint32_t node_id)

+{
+ if (adev->gfx.funcs->ih_node_to_logical_xcc) {
+ int xcc_id = adev->gfx.funcs->ih_node_to_logical_xcc(adev, node_id);
+
+ if (xcc_id >= 0)
+ return xcc_id;
+ }
+
+ return 0;
+}

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h

index 4ed49265c764..bf8bb45d8ab6 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +0 -0
@@ -356,6 +356,7 @@ void amdgpu_amdkfd_unreserve_mem_limit(struct

amdgpu_device *adev,

               uint64_t size, u32 alloc_flag, int8_t xcp_id);

u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int
xcp_id);

+int amdgpu_amdkfd_node_id_to_xcc_id(struct amdgpu_device *adev, uint32_t node_id);

   #define KFD_XCP_MEM_ID(adev, xcp_id) \
               ((adev)->xcp_mgr && (xcp_id) >= 0 ?\
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c

index c6a1783fc9ef..bf9f8802e18d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
@@ -37,7 +37,7 @@ static enum drm_gpu_sched_stat

amdgpu_job_timedout(struct drm_sched_job *s_job)

       struct amdgpu_job *job = to_amdgpu_job(s_job);
       struct amdgpu_task_info *ti;
       struct amdgpu_device *adev = ring->adev;
-     int idx;
+     int idx, xcp_id = !job->vm ? 0 : job->vm->xcp_id;
       int r;

       if (!drm_dev_enter(adev_to_drm(adev), &idx)) {

@@ -62,7 +62,7 @@ static enum drm_gpu_sched_stat
amdgpu_job_timedout(struct drm_sched_job *s_job)

               job->base.sched->name, atomic_read(&ring->fence_drv.last_seq),
               ring->fence_drv.sync_seq);

- ti = amdgpu_vm_get_task_info_pasid(ring->adev, job->pasid);

+     ti = amdgpu_vm_get_task_info_pasid(ring->adev, job->pasid, xcp_id);
       if (ti) {
               dev_err(adev->dev,
                       "Process information: process %s pid %d thread %s pid %d\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

index d9fde38f6ee2..e413bf4a3e84 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
@@ -1275,17 +1275,20 @@ int amdgpu_info_ioctl(struct drm_device *dev,

void *data, struct drm_file *filp)

               struct amdgpu_vm *vm = &fpriv->vm;
               struct drm_amdgpu_info_gpuvm_fault gpuvm_fault;
               unsigned long flags;

+ int i;

               if (!vm)
                       return -EINVAL;

               memset(&gpuvm_fault, 0, sizeof(gpuvm_fault));

- xa_lock_irqsave(&adev->vm_manager.pasids, flags);
+ for (i = 0; i < adev->xcp_mgr->num_xcps; i++)

+                     xa_lock_irqsave(&adev->vm_manager.pasids[i], flags);
               gpuvm_fault.addr = vm->fault_info.addr;
               gpuvm_fault.status = vm->fault_info.status;
               gpuvm_fault.vmhub = vm->fault_info.vmhub;

- xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
+ for (i = 0; i < adev->xcp_mgr->num_xcps; i++)
+ xa_unlock_irqrestore(&adev->vm_manager.pasids[i], flags);

return copy_to_user(out, &gpuvm_fault,
min((size_t)size, sizeof(gpuvm_fault))) ? -EFAULT : 0;

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

index bcb729094521..f43e1c15f423 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
@@ -146,7 +146,7 @@ int amdgpu_vm_set_pasid(struct amdgpu_device

*adev, struct amdgpu_vm *vm,

               return 0;

       if (vm->pasid) {

- r = xa_err(xa_erase_irq(&adev->vm_manager.pasids, vm->pasid));
+ r = xa_err(xa_erase_irq(&adev->vm_manager.pasids[vm->xcp_id],
vm->pasid));

               if (r < 0)
                       return r;

@@ -154,7 +154,7 @@ int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm,

       }

       if (pasid) {

- r = xa_err(xa_store_irq(&adev->vm_manager.pasids, pasid, vm,
+ r = xa_err(xa_store_irq(&adev->vm_manager.pasids[vm->xcp_id],
pasid, vm,

                                       GFP_KERNEL));
               if (r < 0)
                       return r;

@@ -2288,14 +2288,14 @@ static void
amdgpu_vm_destroy_task_info(struct kref *kref)

   }

static inline struct amdgpu_vm *
-amdgpu_vm_get_vm_from_pasid(struct amdgpu_device *adev, u32 pasid) +amdgpu_vm_get_vm_from_pasid(struct amdgpu_device *adev, u32 pasid, u32 xcp_id)

   {
       struct amdgpu_vm *vm;
       unsigned long flags;
-     xa_lock_irqsave(&adev->vm_manager.pasids, flags);
-     vm = xa_load(&adev->vm_manager.pasids, pasid);
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
+     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], flags);
+     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
+     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], flags);
       return vm;

}
@@ -2343,10 +2343,10 @@ amdgpu_vm_get_task_info_vm(struct amdgpu_vm *vm)

* referenced down with amdgpu_vm_put_task_info.
*/
struct amdgpu_task_info *
-amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid) +amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid, u32 xcp_id)

   {
       return amdgpu_vm_get_task_info_vm(

- amdgpu_vm_get_vm_from_pasid(adev, pasid));
+ amdgpu_vm_get_vm_from_pasid(adev, pasid, xcp_id));
}

static int amdgpu_vm_create_task_info(struct amdgpu_vm *vm)
@@ -2481,6 +2481,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,

       amdgpu_bo_unreserve(vm->root.bo);
       amdgpu_bo_unref(&root_bo);

+ vm->xcp_id = xcp_id < 0 ? 0 : xcp_id;
+

       return 0;

error_free_root:
@@ -2695,8 +2697,8 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev)

   #else
       adev->vm_manager.vm_update_mode = 0;

#endif
-
- xa_init_flags(&adev->vm_manager.pasids, XA_FLAGS_LOCK_IRQ);
+ for (i = 0; i < MAX_XCP; i++)
+ xa_init_flags(&(adev->vm_manager.pasids[i]),
XA_FLAGS_LOCK_IRQ);

   }

/**
@@ -2708,10 +2710,15 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev)

    */
   void amdgpu_vm_manager_fini(struct amdgpu_device *adev)
   {
-     WARN_ON(!xa_empty(&adev->vm_manager.pasids));
-     xa_destroy(&adev->vm_manager.pasids);
+     int i;

+
+ for (i = 0; i < MAX_XCP; i++) {
+ WARN_ON(!xa_empty(&adev->vm_manager.pasids[i]));
+ xa_destroy(&adev->vm_manager.pasids[i]);
+ }

       amdgpu_vmid_mgr_fini(adev);

+
}

/**
@@ -2778,17 +2785,18 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid,

       unsigned long irqflags;
       uint64_t value, flags;
       struct amdgpu_vm *vm;

- int r;
+ int r, xcp_id;

-     xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
-     vm = xa_load(&adev->vm_manager.pasids, pasid);
+     xcp_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, node_id)/adev-
gfx.num_xcc_per_xcp;
+     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], irqflags);
+     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
       if (vm) {
               root = amdgpu_bo_ref(vm->root.bo);
               is_compute_context = vm->is_compute_context;
       } else {
               root = NULL;
       }

- xa_unlock_irqrestore(&adev->vm_manager.pasids, irqflags);
+ xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], irqflags);

       if (!root)
               return false;

@@ -2806,11 +2814,11 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid,

               goto error_unref;

       /* Double check that the VM still exists */
-     xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
-     vm = xa_load(&adev->vm_manager.pasids, pasid);
+     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], irqflags);
+     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
       if (vm && vm->root.bo != root)
               vm = NULL;
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, irqflags);
+     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], irqflags);
       if (!vm)
               goto error_unlock;

@@ -2968,14 +2976,15 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev,

unsigned int pasid, uint64_t addr, uint32_t status,

-                               unsigned int vmhub)
+                               unsigned int vmhub,
+                               uint32_t xcp_id)
   {
       struct amdgpu_vm *vm;
       unsigned long flags;

- xa_lock_irqsave(&adev->vm_manager.pasids, flags);
+ xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], flags);

- vm = xa_load(&adev->vm_manager.pasids, pasid);
+ vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
/* Don't update the fault cache if status is 0. In the multiple
* fault case, subsequent faults will return a 0 status which is
* useless for userspace and replaces the useful fault status, so
@@ -3008,7 +3017,7 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev,

                       WARN_ONCE(1, "Invalid vmhub %u\n", vmhub);
               }
       }

- xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
+ xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], flags);
}

/**

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h

index 046949c4b695..1499f5f731e9 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +5 -1
@@ -35,6 +35,7 @@
   #include "amdgpu_sync.h"
   #include "amdgpu_ring.h"
   #include "amdgpu_ids.h"
+#include "amdgpu_xcp.h"
 
   struct drm_exec;
 
@@ -418,6 +419,9 @@ struct amdgpu_vm {
 
       /* cached fault info */
       struct amdgpu_vm_fault_info fault_info;
+
+     /* XCP ID */
+     int xcp_id;
   };
 
   struct amdgpu_vm_manager {
@@ -456,7 +460,7 @@ struct amdgpu_vm_manager {
       /* PASID to VM mapping, will be used in interrupt context to
        * look up VM of a page fault
        */
-     struct xarray                           pasids;
+     struct xarray                           pasids[MAX_XCP];
       /* Global registration of recent page fault information */
       struct amdgpu_vm_fault_info     fault_info;
   };
@@ -550,7 +554,7 @@ bool amdgpu_vm_need_pipeline_sync(struct

amdgpu_ring *ring,

   void amdgpu_vm_check_compute_bug(struct amdgpu_device *adev);

struct amdgpu_task_info *
-amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid); +amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid, u32 xcp_id);

struct amdgpu_task_info * amdgpu_vm_get_task_info_vm(struct amdgpu_vm *vm);
@@ -649,7 +653,8 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev,

unsigned int pasid, uint64_t addr, uint32_t status,

-                               unsigned int vmhub);
+                               unsigned int vmhub,
+                               uint32_t xcp_id);

void amdgpu_vm_tlb_fence_create(struct amdgpu_device *adev,
struct amdgpu_vm *vm, struct dma_fence **fence);

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c

index f0ceab3ce5bf..24b042febf5c 100644

drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +0 -0
@@ -151,7 +151,8 @@ static int gmc_v10_0_process_interrupt(struct

amdgpu_device *adev,

               WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

               amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,

- entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0));

+ entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0),

+                                          0);
       }

       if (!printk_ratelimit())

@@ -161,7 +162,7 @@ static int gmc_v10_0_process_interrupt(struct amdgpu_device *adev,

               "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
               entry->vmid_src ? "mmhub" : "gfxhub",
               entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
-     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
       if (task_info) {
               dev_err(adev->dev,
                       " in process %s pid %d thread %s pid %d\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c

index 2797fd84432b..3507046d33e6 100644

drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +0 -0
@@ -122,7 +122,8 @@ static int gmc_v11_0_process_interrupt(struct

amdgpu_device *adev,

               WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

               amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,

- entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0));

+ entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0),

+                                          0);
       }

       if (printk_ratelimit()) {

@@ -132,7 +133,7 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev,

                       "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
                       entry->vmid_src ? "mmhub" : "gfxhub",
                       entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
-             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
               if (task_info) {
                       dev_err(adev->dev,
                               " in process %s pid %d thread %s pid %d)\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c

index 60acf676000b..9844564c6c74 100644

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -0
@@ -115,7 +115,8 @@ static int gmc_v12_0_process_interrupt(struct

amdgpu_device *adev,

               WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

               amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,

- entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0));

+ entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0),

+                                          0);
       }

       if (printk_ratelimit()) {

@@ -125,7 +126,7 @@ static int gmc_v12_0_process_interrupt(struct amdgpu_device *adev,

                       "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
                       entry->vmid_src ? "mmhub" : "gfxhub",
                       entry->src_id, entry->ring_id, entry->vmid, entry->pasid);
-             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
               if (task_info) {
                       dev_err(adev->dev,
                               " in process %s pid %d thread %s pid %d)\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c

index 994432fb57ea..2cdb0cbb7c4d 100644

drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +0 -0
@@ -1268,7 +1268,8 @@ static int gmc_v7_0_process_interrupt(struct

amdgpu_device *adev,

               return 0;

       amdgpu_vm_update_fault_cache(adev, entry->pasid,

- ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
AMDGPU_GFXHUB(0));

+ ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
+ AMDGPU_GFXHUB(0), 0);

       if (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_FIRST)
               gmc_v7_0_set_fault_enable_default(adev, false);
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c

index 86488c052f82..6855caeb7f74 100644

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0 -0
@@ -1437,7 +1437,8 @@ static int gmc_v8_0_process_interrupt(struct

amdgpu_device *adev,

               return 0;

       amdgpu_vm_update_fault_cache(adev, entry->pasid,

- ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
AMDGPU_GFXHUB(0));

+ ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
+ AMDGPU_GFXHUB(0), 0);

       if (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_FIRST)
               gmc_v8_0_set_fault_enable_default(adev, false);

@@ -1448,7 +1449,7 @@ static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev,

               dev_err(adev->dev, "GPU fault detected: %d 0x%08x\n",
                       entry->src_id, entry->src_data[0]);

- task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);

+             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
               if (task_info) {
                       dev_err(adev->dev, " for process %s pid %d thread %s pid %d\n",
                               task_info->process_name, task_info->tgid,
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c

index b73136d390cc..e183e08b2c02 100644

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
@@ -556,10 +556,12 @@ static int gmc_v9_0_process_interrupt(struct

amdgpu_device *adev,

       unsigned int vmhub;
       u64 addr;
       uint32_t cam_index = 0;
-     int ret, xcc_id = 0;
-     uint32_t node_id;
+     int ret;
+     uint32_t node_id, xcc_id, xcp_id;
       node_id = entry->node_id;

+ xcc_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, node_id);
+ xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;

       addr = (u64)entry->src_data[0] << 12;
       addr |= ((u64)entry->src_data[1] & 0xf) << 44;

@@ -572,12 +574,6 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,

               vmhub = AMDGPU_MMHUB1(0);
       } else {
               hub_name = "gfxhub0";

- if (adev->gfx.funcs->ih_node_to_logical_xcc) {
- xcc_id = adev->gfx.funcs->ih_node_to_logical_xcc(adev,
- node_id);
- if (xcc_id < 0)
- xcc_id = 0;
- }

               vmhub = xcc_id;
       }
       hub = &adev->vmhub[vmhub];

@@ -631,7 +627,7 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,

               retry_fault ? "retry" : "no-retry",
               entry->src_id, entry->ring_id, entry->vmid, entry->pasid);

- task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+ task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid,
xcp_id);

       if (task_info) {
               dev_err(adev->dev,
                       " for process %s pid %d thread %s pid %d)\n",

@@ -675,7 +671,7 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,

       if (!amdgpu_sriov_vf(adev))
               WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

- amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,
vmhub);

+ amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status,
vmhub, xcp_id);

       dev_err(adev->dev,
               "VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c

index 23ef4eb36b40..1ac4224bbe5b 100644

drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +0 -0
@@ -2182,7 +2182,7 @@ static int sdma_v4_0_print_iv_entry(struct

amdgpu_device *adev,

                          instance, addr, entry->src_id, entry->ring_id, entry->vmid,
                          entry->pasid);

- task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);

+     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
       if (task_info) {
               dev_dbg_ratelimited(adev->dev,
                                   " for process %s pid %d thread %s pid %d\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

index 57f16c09abfc..c8b5c0302ca7 100644

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -0
@@ -1683,6 +1683,8 @@ static int sdma_v4_4_2_print_iv_entry(struct

amdgpu_device *adev,

       int instance;
       struct amdgpu_task_info *task_info;
       u64 addr;

+ uint32_t xcc_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, entry-
node_id);
+ uint32_t xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;

       instance = sdma_v4_4_2_irq_id_to_seq(adev, entry->client_id);
       if (instance < 0 || instance >= adev->sdma.num_instances) {

@@ -1698,7 +1700,7 @@ static int sdma_v4_4_2_print_iv_entry(struct amdgpu_device *adev,

                           instance, addr, entry->src_id, entry->ring_id, entry->vmid,
                           entry->pasid);

- task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
+ task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid,
xcp_id);

       if (task_info) {
               dev_dbg_ratelimited(adev->dev, " for process %s pid %d thread %s

pid %d\n",

                                   task_info->process_name, task_info->tgid,
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_events.c

index ea3792249209..c098fbaf0e1c 100644

drivers/gpu/drm/amd/amdkfd/kfd_events.c +0 -0
@@ -1262,8 +1262,9 @@ void kfd_signal_reset_event(struct kfd_node

*dev)

               if (dev->dqm->detect_hang_count) {
                       struct amdgpu_task_info *ti;

+ uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;

- ti = amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid);
+ ti = amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid,
xcp_id);

                       if (ti) {
                               dev_err(dev->adev->dev,
                                       "Queues reset on process %s tid %d thread %s pid %d\n",
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c

index 8e0d0356e810..d7cbf9525698 100644

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c +0 -0
@@ -377,12 +377,8 @@ static void event_interrupt_wq_v10(struct

kfd_node *dev,

               struct kfd_hsa_memory_exception_data exception_data;

               /* gfxhub */

- if (!vmid_type && dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
- hub_inst = dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev-
adev,
- node_id);
- if (hub_inst < 0)
- hub_inst = 0;
- }
+ if (!vmid_type)
+ hub_inst = amdgpu_amdkfd_node_id_to_xcc_id(dev->adev,
node_id);

               /* mmhub */
               if (vmid_type && client_id == SOC15_IH_CLIENTID_VMC)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c

index a9c3580be8c9..4708b8c811a5 100644

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -0
@@ -437,12 +437,8 @@ static void event_interrupt_wq_v9(struct

kfd_node *dev,

               struct kfd_hsa_memory_exception_data exception_data;

               /* gfxhub */

- if (!vmid_type && dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
- hub_inst = dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev-
adev,
- node_id);
- if (hub_inst < 0)
- hub_inst = 0;
- }
+ if (!vmid_type)
+ hub_inst = amdgpu_amdkfd_node_id_to_xcc_id(dev->adev,
node_id);

               /* mmhub */
               if (vmid_type && client_id == SOC15_IH_CLIENTID_VMC)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c

index ea6a8e43bd5b..b5f2f5b1069c 100644

drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +0 -0
@@ -251,8 +251,9 @@ void

kfd_smi_event_update_thermal_throttling(struct kfd_node *dev,

void kfd_smi_event_update_vmfault(struct kfd_node *dev, uint16_t pasid)

   {
       struct amdgpu_task_info *task_info;

+ uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;

- task_info = amdgpu_vm_get_task_info_pasid(dev->adev, pasid);

+     task_info = amdgpu_vm_get_task_info_pasid(dev->adev, pasid, xcp_id);
       if (task_info) {
               /* Report VM faults from user applications, not retry from kernel */
               if (task_info->pid)
#6 lore raw

You want have 1:1 mapping between vm and pasid so can query vm from pasid.  I think there is a basic existing issue that we cannot have vm and pasid 1:1 correspondence.

PASIDs are global address space identifiers that can be shared between the GPU, an IOMMU and the driver. One app should have one pasid that iommu uses to decide which page table to use when device access system resource. But one app can open render/kfd node multiple times even for one gpu. That said one app could have multiple GPU vms .

I think we did not have this issue because app usually open a rent node or kfd node only once. With one adev has multiple partitions there are multiple vms on one adev, so have this issue.  But the root cause is not from multiple partitions and solution is not to introduce multiple pasids. I think we should have one pasid for one app and use different way to get vm from pasid.

Regards

Xiaogang

Quoted 1,109 lines · Jonathan

[Public]

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

[Public]

KMS open still set per pasid-vm bindings per adev (socket) so I don’t see how the per-partition overwrite PASID issue is primarily a KFD concern.

Are you saying the KFD process devices holds a shadow copy of the correct VM during page restore during fault?

Doesn’t it acquire the wrong VM object on process init in the first place?

Even if it were the case the KFD had a separate VM reference, the underlying IRQ fault handling is still broken.

We probably don’t want to bandage over something to fix one symptom.

Jon

*From:*Yang, Philip <[email protected]>
*Sent:* Tuesday, September 10, 2024 11:24 AM
*To:* Koenig, Christian <[email protected]>; Kim, Jonathan <[email protected]>; [email protected] *Cc:* Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]> *Subject:* Re: [PATCH] drm/amdkfd: fix vm-pasid lookup for multiple partitions

On 2024-09-09 14:46, Christian König wrote:

Am 09.09.24 um 18:02 schrieb Kim, Jonathan:

[Public]

-----Original Message-----
From: Christian König <[email protected]> <mailto:[email protected]>
Sent: Thursday, September 5, 2024 10:24 AM
To: Kim, Jonathan <[email protected]> <mailto:[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]> <mailto:[email protected]>; Deucher, Alexander <[email protected]> <mailto:[email protected]>; Joshi, Mukul <[email protected]> <mailto:[email protected]>
Subject: Re: [PATCH] drm/amdkfd: fix vm-pasid lookup for multiple partitions

Caution: This message originated from an External Source. Use proper caution
when opening attachments, clicking links, or responding.

Am 19.08.24 um 19:59 schrieb Jonathan Kim:

Currently multiple partitions will incorrectly overwrite the VM lookup
table since the table is indexed by PASID and multiple partitions can
register different VM objects on the same PASID.

That's a rather bad idea. Why do we have the same PASID for different VM
objects in the first place?

Alex can probably elaborate on the KGD side, but from what I can see, the KMS driver open call has always assigned a new VM object per PASID on an open call.
The KFD acquires and replaces the KGD PASID-VMID registration on its own compute process open/creation call.
If this is the bad_idea you're referring to, then someone else will have to chime in.  I don't have much history on this unfortunately.

Yeah, Felix and I designed that.

app opens drm node to create vm for each partition, with different vm->pasid for each vm, issue is from kfd_ioctl_acquire_vm -> kfd_process_device_init_vm ->  amdgpu_amdkfd_gpuvm_set_vm_pasid, to replace all vm->pasid with kfd process->pasid, which is from open kfd node. This ends up to store only one vm to adev->vm_manager.pasids with KFD process pasid, so we cannot retrieve correct vm from adev->vm_manager.pasids on mGPUs or multiple partitions.

That aside, the current problem is, is that all KFD device structures are logical partitions and register their PASID-VM binding using this concept of a device.

As far as I can see that is the fundamental problem. This needs to be fixed instead.

On the KGD side however, the registration table is maintained in the adev struct, which is a physical socket.
So there's a mismatch in understanding of what a device is between the KFD & KGD with regard to the look up table that results in bad bindings.

Adding a per-partition dimension to the existing lookup table resolves issues where seeing, for example, with memory violation interception and XNACK i.e bad bindings result in wrong vm object found to set no-retry flags on memory violations.

svm_range_restore_pages retry fault recover uses fault pasid to get kfd process, and use the fault node_id to get pdd->vm, maybe you can use this way to fix the debugger issue.

Regards,

Philip

    Yeah that is pretty much a no-go.

    The PASID and how it is used is defined by the PCIe
    specifications. If we now start to assign multiple VMs to the same
    PASID then we are violating the PCIe specification.

    The problems you see are most likely just the tip of the iceberg
    here.

    Regards,
    Christian.



        Jon


            Regards,
            Christian.


                This results in loading the wrong VM object on PASID
                query.

                To correct this, setup the lookup table to be
                per-partition-per-PASID
                instead.

                Signed-off-by: Jonathan Kim <[email protected]>
                <mailto:[email protected]>
                ---
                drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 12 ++++
                drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  1 +
                drivers/gpu/drm/amd/amdgpu/amdgpu_job.c |  4 +-
                drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  7 ++-
                drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 55
                +++++++++++------

            -- 

                drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 11 +++-
                drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c |  5 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c |  5 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c |  5 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c |  3 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c |  5 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 16 ++----
                drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c |  2 +-
                drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c |  4 +-
                drivers/gpu/drm/amd/amdkfd/kfd_events.c |  3 +-
                .../gpu/drm/amd/amdkfd/kfd_int_process_v10.c |  8 +--
                .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c |  8 +--
                drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c |  3 +-
                   18 files changed, 92 insertions(+), 65 deletions(-)

                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c

                index c272461d70a9..28db789610e1 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
                @@ -887,3 +887,15 @@ int amdgpu_amdkfd_unmap_hiq(struct

            amdgpu_device *adev, u32 doorbell_off,

                       return r;
                   }
                +
                +int amdgpu_amdkfd_node_id_to_xcc_id(struct
                amdgpu_device *adev,

            uint32_t node_id)

                +{
                +     if (adev->gfx.funcs->ih_node_to_logical_xcc) {
                +             int xcc_id =
                adev->gfx.funcs->ih_node_to_logical_xcc(adev, node_id);
                +
                +             if (xcc_id >= 0)
                +                     return xcc_id;
                +     }
                +
                +     return 0;
                +}
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h

                index 4ed49265c764..bf8bb45d8ab6 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
                @@ -356,6 +356,7 @@ void
                amdgpu_amdkfd_unreserve_mem_limit(struct

            amdgpu_device *adev,

                               uint64_t size, u32 alloc_flag, int8_t
                xcp_id);

                   u64 amdgpu_amdkfd_xcp_memory_size(struct
                amdgpu_device *adev, int

            xcp_id);

                +int amdgpu_amdkfd_node_id_to_xcc_id(struct
                amdgpu_device *adev,

            uint32_t node_id);

                   #define KFD_XCP_MEM_ID(adev, xcp_id) \
                               ((adev)->xcp_mgr && (xcp_id) >= 0 ?\
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c

                index c6a1783fc9ef..bf9f8802e18d 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
                @@ -37,7 +37,7 @@ static enum drm_gpu_sched_stat

            amdgpu_job_timedout(struct drm_sched_job *s_job)

                       struct amdgpu_job *job = to_amdgpu_job(s_job);
                       struct amdgpu_task_info *ti;
                       struct amdgpu_device *adev = ring->adev;
                -     int idx;
                +     int idx, xcp_id = !job->vm ? 0 : job->vm->xcp_id;
                       int r;

                       if (!drm_dev_enter(adev_to_drm(adev), &idx)) {
                @@ -62,7 +62,7 @@ static enum drm_gpu_sched_stat

            amdgpu_job_timedout(struct drm_sched_job *s_job)

                job->base.sched->name,
                atomic_read(&ring->fence_drv.last_seq),
                               ring->fence_drv.sync_seq);

                -     ti = amdgpu_vm_get_task_info_pasid(ring->adev,
                job->pasid);
                +     ti = amdgpu_vm_get_task_info_pasid(ring->adev,
                job->pasid, xcp_id);
                       if (ti) {
                               dev_err(adev->dev,
                                       "Process information: process
                %s pid %d thread %s pid %d\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

                index d9fde38f6ee2..e413bf4a3e84 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
                @@ -1275,17 +1275,20 @@ int amdgpu_info_ioctl(struct
                drm_device *dev,

            void *data, struct drm_file *filp)

                               struct amdgpu_vm *vm = &fpriv->vm;
                               struct drm_amdgpu_info_gpuvm_fault
                gpuvm_fault;
                               unsigned long flags;
                +             int i;

                               if (!vm)
                                       return -EINVAL;

                               memset(&gpuvm_fault, 0,
                sizeof(gpuvm_fault));

                - xa_lock_irqsave(&adev->vm_manager.pasids, flags);
                +             for (i = 0; i < adev->xcp_mgr->num_xcps;
                i++)
                + xa_lock_irqsave(&adev->vm_manager.pasids[i], flags);
                               gpuvm_fault.addr = vm->fault_info.addr;
                               gpuvm_fault.status =
                vm->fault_info.status;
                               gpuvm_fault.vmhub = vm->fault_info.vmhub;
                - xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
                +             for (i = 0; i < adev->xcp_mgr->num_xcps;
                i++)
                + xa_unlock_irqrestore(&adev->vm_manager.pasids[i],
                flags);

                               return copy_to_user(out, &gpuvm_fault,
                min((size_t)size, sizeof(gpuvm_fault))) ? -EFAULT : 0;
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

                index bcb729094521..f43e1c15f423 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
                @@ -146,7 +146,7 @@ int amdgpu_vm_set_pasid(struct
                amdgpu_device

            *adev, struct amdgpu_vm *vm,

                               return 0;

                       if (vm->pasid) {
                -             r =
                xa_err(xa_erase_irq(&adev->vm_manager.pasids,
                vm->pasid));
                +             r =
                xa_err(xa_erase_irq(&adev->vm_manager.pasids[vm->xcp_id],

            vm->pasid));

                               if (r < 0)
                                       return r;

                @@ -154,7 +154,7 @@ int amdgpu_vm_set_pasid(struct
                amdgpu_device

            *adev, struct amdgpu_vm *vm,

                       }

                       if (pasid) {
                -             r =
                xa_err(xa_store_irq(&adev->vm_manager.pasids, pasid, vm,
                +             r =
                xa_err(xa_store_irq(&adev->vm_manager.pasids[vm->xcp_id],

            pasid, vm,

                GFP_KERNEL));
                               if (r < 0)
                                       return r;
                @@ -2288,14 +2288,14 @@ static void

            amdgpu_vm_destroy_task_info(struct kref *kref)

                   }

                   static inline struct amdgpu_vm *
                -amdgpu_vm_get_vm_from_pasid(struct amdgpu_device
                *adev, u32 pasid)
                +amdgpu_vm_get_vm_from_pasid(struct amdgpu_device
                *adev, u32 pasid,

            u32 xcp_id)

                   {
                       struct amdgpu_vm *vm;
                       unsigned long flags;

                - xa_lock_irqsave(&adev->vm_manager.pasids, flags);
                -     vm = xa_load(&adev->vm_manager.pasids, pasid);
                - xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
                + xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id],
                flags);
                +     vm = xa_load(&adev->vm_manager.pasids[xcp_id],
                pasid);
                +
                xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id],
                flags);

                       return vm;
                   }
                @@ -2343,10 +2343,10 @@ amdgpu_vm_get_task_info_vm(struct

            amdgpu_vm *vm)

                    * referenced down with amdgpu_vm_put_task_info.
                    */
                   struct amdgpu_task_info *
                -amdgpu_vm_get_task_info_pasid(struct amdgpu_device
                *adev, u32 pasid)
                +amdgpu_vm_get_task_info_pasid(struct amdgpu_device
                *adev, u32 pasid,

            u32 xcp_id)

                   {
                       return amdgpu_vm_get_task_info_vm(
                - amdgpu_vm_get_vm_from_pasid(adev, pasid));
                + amdgpu_vm_get_vm_from_pasid(adev, pasid, xcp_id));
                   }

                   static int amdgpu_vm_create_task_info(struct
                amdgpu_vm *vm)
                @@ -2481,6 +2481,8 @@ int amdgpu_vm_init(struct
                amdgpu_device

            *adev, struct amdgpu_vm *vm,

                amdgpu_bo_unreserve(vm->root.bo);
                       amdgpu_bo_unref(&root_bo);

                +     vm->xcp_id = xcp_id < 0 ? 0 : xcp_id;
                +
                       return 0;

                   error_free_root:
                @@ -2695,8 +2697,8 @@ void amdgpu_vm_manager_init(struct

            amdgpu_device *adev)

                   #else
                       adev->vm_manager.vm_update_mode = 0;
                   #endif
                -
                - xa_init_flags(&adev->vm_manager.pasids,
                XA_FLAGS_LOCK_IRQ);
                +     for (i = 0; i < MAX_XCP; i++)
                + xa_init_flags(&(adev->vm_manager.pasids[i]),

            XA_FLAGS_LOCK_IRQ);

                   }

                   /**
                @@ -2708,10 +2710,15 @@ void
                amdgpu_vm_manager_init(struct

            amdgpu_device *adev)

                    */
                   void amdgpu_vm_manager_fini(struct amdgpu_device
                *adev)
                   {
                - WARN_ON(!xa_empty(&adev->vm_manager.pasids));
                - xa_destroy(&adev->vm_manager.pasids);
                +     int i;
                +
                +     for (i = 0; i < MAX_XCP; i++) {
                + WARN_ON(!xa_empty(&adev->vm_manager.pasids[i]));
                + xa_destroy(&adev->vm_manager.pasids[i]);
                +     }

                       amdgpu_vmid_mgr_fini(adev);
                +
                   }

                   /**
                @@ -2778,17 +2785,18 @@ bool
                amdgpu_vm_handle_fault(struct

            amdgpu_device *adev, u32 pasid,

                       unsigned long irqflags;
                       uint64_t value, flags;
                       struct amdgpu_vm *vm;
                -     int r;
                +     int r, xcp_id;

                - xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
                -     vm = xa_load(&adev->vm_manager.pasids, pasid);
                +     xcp_id = amdgpu_amdkfd_node_id_to_xcc_id(adev,
                node_id)/adev-
                gfx.num_xcc_per_xcp;
                + xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id],
                irqflags);
                +     vm = xa_load(&adev->vm_manager.pasids[xcp_id],
                pasid);
                       if (vm) {
                               root = amdgpu_bo_ref(vm->root.bo);
                               is_compute_context =
                vm->is_compute_context;
                       } else {
                               root = NULL;
                       }
                - xa_unlock_irqrestore(&adev->vm_manager.pasids,
                irqflags);
                +
                xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id],
                irqflags);

                       if (!root)
                               return false;
                @@ -2806,11 +2814,11 @@ bool
                amdgpu_vm_handle_fault(struct

            amdgpu_device *adev, u32 pasid,

                               goto error_unref;

                       /* Double check that the VM still exists */
                - xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
                -     vm = xa_load(&adev->vm_manager.pasids, pasid);
                + xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id],
                irqflags);
                +     vm = xa_load(&adev->vm_manager.pasids[xcp_id],
                pasid);
                       if (vm && vm->root.bo != root)
                               vm = NULL;
                - xa_unlock_irqrestore(&adev->vm_manager.pasids,
                irqflags);
                +
                xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id],
                irqflags);
                       if (!vm)
                               goto error_unlock;

                @@ -2968,14 +2976,15 @@ void
                amdgpu_vm_update_fault_cache(struct

            amdgpu_device *adev,

                unsigned int pasid,
                                                 uint64_t addr,
                                                 uint32_t status,
                -                               unsigned int vmhub)
                +                               unsigned int vmhub,
                +                               uint32_t xcp_id)
                   {
                       struct amdgpu_vm *vm;
                       unsigned long flags;

                - xa_lock_irqsave(&adev->vm_manager.pasids, flags);
                + xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id],
                flags);

                -     vm = xa_load(&adev->vm_manager.pasids, pasid);
                +     vm = xa_load(&adev->vm_manager.pasids[xcp_id],
                pasid);
                       /* Don't update the fault cache if status is
                0.  In the multiple
                        * fault case, subsequent faults will return a
                0 status which is
                        * useless for userspace and replaces the
                useful fault status, so
                @@ -3008,7 +3017,7 @@ void
                amdgpu_vm_update_fault_cache(struct

            amdgpu_device *adev,

                WARN_ONCE(1, "Invalid vmhub %u\n", vmhub);
                               }
                       }
                - xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
                +
                xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id],
                flags);
                   }

                   /**
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h

                index 046949c4b695..1499f5f731e9 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
                @@ -35,6 +35,7 @@
                   #include "amdgpu_sync.h"
                   #include "amdgpu_ring.h"
                   #include "amdgpu_ids.h"
                +#include "amdgpu_xcp.h"

                   struct drm_exec;

                @@ -418,6 +419,9 @@ struct amdgpu_vm {

                       /* cached fault info */
                       struct amdgpu_vm_fault_info fault_info;
                +
                +     /* XCP ID */
                +     int xcp_id;
                   };

                   struct amdgpu_vm_manager {
                @@ -456,7 +460,7 @@ struct amdgpu_vm_manager {
                       /* PASID to VM mapping, will be used in
                interrupt context to
                        * look up VM of a page fault
                        */
                -     struct xarray pasids;
                +     struct xarray pasids[MAX_XCP];
                       /* Global registration of recent page fault
                information */
                       struct amdgpu_vm_fault_info fault_info;
                   };
                @@ -550,7 +554,7 @@ bool
                amdgpu_vm_need_pipeline_sync(struct

            amdgpu_ring *ring,

                   void amdgpu_vm_check_compute_bug(struct
                amdgpu_device *adev);

                   struct amdgpu_task_info *
                -amdgpu_vm_get_task_info_pasid(struct amdgpu_device
                *adev, u32 pasid);
                +amdgpu_vm_get_task_info_pasid(struct amdgpu_device
                *adev, u32 pasid,

            u32 xcp_id);

                   struct amdgpu_task_info *
                   amdgpu_vm_get_task_info_vm(struct amdgpu_vm *vm);
                @@ -649,7 +653,8 @@ void
                amdgpu_vm_update_fault_cache(struct

            amdgpu_device *adev,

                unsigned int pasid,
                                                 uint64_t addr,
                                                 uint32_t status,
                -                               unsigned int vmhub);
                +                               unsigned int vmhub,
                +                               uint32_t xcp_id);
                   void amdgpu_vm_tlb_fence_create(struct
                amdgpu_device *adev,
                                                struct amdgpu_vm *vm,
                                                struct dma_fence
                **fence);
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c

                index f0ceab3ce5bf..24b042febf5c 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
                @@ -151,7 +151,8 @@ static int
                gmc_v10_0_process_interrupt(struct

            amdgpu_device *adev,

                WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

                amdgpu_vm_update_fault_cache(adev, entry->pasid, addr,
                status,
                - entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0));

                + entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0),

                + 0);
                       }

                       if (!printk_ratelimit())
                @@ -161,7 +162,7 @@ static int
                gmc_v10_0_process_interrupt(struct

            amdgpu_device *adev,

                               "[%s] page fault (src_id:%u ring:%u
                vmid:%u pasid:%u)\n",
                               entry->vmid_src ? "mmhub" : "gfxhub",
                               entry->src_id, entry->ring_id,
                entry->vmid, entry->pasid);
                -     task_info = amdgpu_vm_get_task_info_pasid(adev,
                entry->pasid);
                +     task_info = amdgpu_vm_get_task_info_pasid(adev,
                entry->pasid, 0);
                       if (task_info) {
                               dev_err(adev->dev,
                                       " in process %s pid %d thread
                %s pid %d\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c

                index 2797fd84432b..3507046d33e6 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c
                @@ -122,7 +122,8 @@ static int
                gmc_v11_0_process_interrupt(struct

            amdgpu_device *adev,

                WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

                amdgpu_vm_update_fault_cache(adev, entry->pasid, addr,
                status,
                - entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0));

                + entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0),

                + 0);
                       }

                       if (printk_ratelimit()) {
                @@ -132,7 +133,7 @@ static int
                gmc_v11_0_process_interrupt(struct

            amdgpu_device *adev,

                "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
                                       entry->vmid_src ? "mmhub" :
                "gfxhub",
                                       entry->src_id, entry->ring_id,
                entry->vmid, entry->pasid);
                -             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
                               if (task_info) {
                                       dev_err(adev->dev,
                                               " in process %s pid %d
                thread %s pid %d)\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c

                index 60acf676000b..9844564c6c74 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c
                @@ -115,7 +115,8 @@ static int
                gmc_v12_0_process_interrupt(struct

            amdgpu_device *adev,

                WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

                amdgpu_vm_update_fault_cache(adev, entry->pasid, addr,
                status,
                - entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0));

                + entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0),

                + 0);
                       }

                       if (printk_ratelimit()) {
                @@ -125,7 +126,7 @@ static int
                gmc_v12_0_process_interrupt(struct

            amdgpu_device *adev,

                "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
                                       entry->vmid_src ? "mmhub" :
                "gfxhub",
                                       entry->src_id, entry->ring_id,
                entry->vmid, entry->pasid);
                -             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
                               if (task_info) {
                                       dev_err(adev->dev,
                                               " in process %s pid %d
                thread %s pid %d)\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c

                index 994432fb57ea..2cdb0cbb7c4d 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
                @@ -1268,7 +1268,8 @@ static int
                gmc_v7_0_process_interrupt(struct

            amdgpu_device *adev,

                               return 0;

                       amdgpu_vm_update_fault_cache(adev, entry->pasid,
                -                                  ((u64)addr) <<
                AMDGPU_GPU_PAGE_SHIFT, status,

            AMDGPU_GFXHUB(0));

                + ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
                + AMDGPU_GFXHUB(0), 0);

                       if (amdgpu_vm_fault_stop ==
                AMDGPU_VM_FAULT_STOP_FIRST)
                gmc_v7_0_set_fault_enable_default(adev, false);
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c

                index 86488c052f82..6855caeb7f74 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
                @@ -1437,7 +1437,8 @@ static int
                gmc_v8_0_process_interrupt(struct

            amdgpu_device *adev,

                               return 0;

                       amdgpu_vm_update_fault_cache(adev, entry->pasid,
                -                                  ((u64)addr) <<
                AMDGPU_GPU_PAGE_SHIFT, status,

            AMDGPU_GFXHUB(0));

                + ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
                + AMDGPU_GFXHUB(0), 0);

                       if (amdgpu_vm_fault_stop ==
                AMDGPU_VM_FAULT_STOP_FIRST)
                gmc_v8_0_set_fault_enable_default(adev, false);
                @@ -1448,7 +1449,7 @@ static int
                gmc_v8_0_process_interrupt(struct

            amdgpu_device *adev,

                dev_err(adev->dev, "GPU fault detected: %d 0x%08x\n",
                                       entry->src_id,
                entry->src_data[0]);

                -             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
                               if (task_info) {
                                       dev_err(adev->dev, " for
                process %s pid %d thread %s pid %d\n",
                task_info->process_name, task_info->tgid,
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c

                index b73136d390cc..e183e08b2c02 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
                @@ -556,10 +556,12 @@ static int
                gmc_v9_0_process_interrupt(struct

            amdgpu_device *adev,

                       unsigned int vmhub;
                       u64 addr;
                       uint32_t cam_index = 0;
                -     int ret, xcc_id = 0;
                -     uint32_t node_id;
                +     int ret;
                +     uint32_t node_id, xcc_id, xcp_id;

                       node_id = entry->node_id;
                +     xcc_id = amdgpu_amdkfd_node_id_to_xcc_id(adev,
                node_id);
                +     xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;

                       addr = (u64)entry->src_data[0] << 12;
                       addr |= ((u64)entry->src_data[1] & 0xf) << 44;
                @@ -572,12 +574,6 @@ static int
                gmc_v9_0_process_interrupt(struct

            amdgpu_device *adev,

                               vmhub = AMDGPU_MMHUB1(0);
                       } else {
                               hub_name = "gfxhub0";
                -             if
                (adev->gfx.funcs->ih_node_to_logical_xcc) {
                -                     xcc_id =
                adev->gfx.funcs->ih_node_to_logical_xcc(adev,
                -                             node_id);
                -                     if (xcc_id < 0)
                -                             xcc_id = 0;
                -             }
                               vmhub = xcc_id;
                       }
                       hub = &adev->vmhub[vmhub];
                @@ -631,7 +627,7 @@ static int
                gmc_v9_0_process_interrupt(struct

            amdgpu_device *adev,

                               retry_fault ? "retry" : "no-retry",
                               entry->src_id, entry->ring_id,
                entry->vmid, entry->pasid);

                -     task_info = amdgpu_vm_get_task_info_pasid(adev,
                entry->pasid);
                +     task_info = amdgpu_vm_get_task_info_pasid(adev,
                entry->pasid,

            xcp_id);

                       if (task_info) {
                               dev_err(adev->dev,
                                       " for process %s pid %d thread
                %s pid %d)\n",
                @@ -675,7 +671,7 @@ static int
                gmc_v9_0_process_interrupt(struct

            amdgpu_device *adev,

                       if (!amdgpu_sriov_vf(adev))
                WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

                -     amdgpu_vm_update_fault_cache(adev, entry->pasid,
                addr, status,

            vmhub);

                + amdgpu_vm_update_fault_cache(adev, entry->pasid,
                addr, status,

            vmhub, xcp_id);

                dev_err(adev->dev,
                "VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c

            b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c

                index 23ef4eb36b40..1ac4224bbe5b 100644
                --- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
                @@ -2182,7 +2182,7 @@ static int
                sdma_v4_0_print_iv_entry(struct

            amdgpu_device *adev,

                instance, addr, entry->src_id, entry->ring_id,
                entry->vmid,
                                          entry->pasid);

                -     task_info = amdgpu_vm_get_task_info_pasid(adev,
                entry->pasid);
                +     task_info = amdgpu_vm_get_task_info_pasid(adev,
                entry->pasid, 0);
                       if (task_info) {
                dev_dbg_ratelimited(adev->dev,
                                                   " for process %s
                pid %d thread %s pid %d\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

            b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

                index 57f16c09abfc..c8b5c0302ca7 100644
                --- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
                +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
                @@ -1683,6 +1683,8 @@ static int
                sdma_v4_4_2_print_iv_entry(struct

            amdgpu_device *adev,

                       int instance;
                       struct amdgpu_task_info *task_info;
                       u64 addr;
                +     uint32_t xcc_id =
                amdgpu_amdkfd_node_id_to_xcc_id(adev, entry-
                node_id);
                +     uint32_t xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;

                       instance = sdma_v4_4_2_irq_id_to_seq(adev,
                entry->client_id);
                       if (instance < 0 || instance >=
                adev->sdma.num_instances) {
                @@ -1698,7 +1700,7 @@ static int
                sdma_v4_4_2_print_iv_entry(struct

            amdgpu_device *adev,

                instance, addr, entry->src_id, entry->ring_id,
                entry->vmid,
                                           entry->pasid);

                -     task_info = amdgpu_vm_get_task_info_pasid(adev,
                entry->pasid);
                +     task_info = amdgpu_vm_get_task_info_pasid(adev,
                entry->pasid,

            xcp_id);

                       if (task_info) {
                dev_dbg_ratelimited(adev->dev, " for process %s pid %d
                thread %s

            pid %d\n",

                task_info->process_name, task_info->tgid,
                diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_events.c

            b/drivers/gpu/drm/amd/amdkfd/kfd_events.c

                index ea3792249209..c098fbaf0e1c 100644
                --- a/drivers/gpu/drm/amd/amdkfd/kfd_events.c
                +++ b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
                @@ -1262,8 +1262,9 @@ void
                kfd_signal_reset_event(struct kfd_node

            *dev)

                               if (dev->dqm->detect_hang_count) {
                                       struct amdgpu_task_info *ti;
                +                     uint32_t xcp_id = dev->xcp ?
                dev->xcp->id : 0;

                -                     ti =
                amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid);
                +                     ti =
                amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid,

            xcp_id);

                                       if (ti) {
                dev_err(dev->adev->dev,
                                                       "Queues reset
                on process %s tid %d thread %s pid %d\n",
                diff --git
                a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c

            b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c

                index 8e0d0356e810..d7cbf9525698 100644
                --- a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c
                +++ b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c
                @@ -377,12 +377,8 @@ static void
                event_interrupt_wq_v10(struct

            kfd_node *dev,

                               struct kfd_hsa_memory_exception_data
                exception_data;

                               /* gfxhub */
                -             if (!vmid_type &&
                dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
                -                     hub_inst =
                dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev-
                adev,
                -                             node_id);
                -                     if (hub_inst < 0)
                -                             hub_inst = 0;
                -             }
                +             if (!vmid_type)
                +                     hub_inst =
                amdgpu_amdkfd_node_id_to_xcc_id(dev->adev,

            node_id);

                               /* mmhub */
                               if (vmid_type && client_id ==
                SOC15_IH_CLIENTID_VMC)
                diff --git
                a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c

            b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c

                index a9c3580be8c9..4708b8c811a5 100644
                --- a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c
                +++ b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c
                @@ -437,12 +437,8 @@ static void
                event_interrupt_wq_v9(struct

            kfd_node *dev,

                               struct kfd_hsa_memory_exception_data
                exception_data;

                               /* gfxhub */
                -             if (!vmid_type &&
                dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
                -                     hub_inst =
                dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev-
                adev,
                -                             node_id);
                -                     if (hub_inst < 0)
                -                             hub_inst = 0;
                -             }
                +             if (!vmid_type)
                +                     hub_inst =
                amdgpu_amdkfd_node_id_to_xcc_id(dev->adev,

            node_id);

                               /* mmhub */
                               if (vmid_type && client_id ==
                SOC15_IH_CLIENTID_VMC)
                diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c

            b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c

                index ea6a8e43bd5b..b5f2f5b1069c 100644
                --- a/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
                +++ b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
                @@ -251,8 +251,9 @@ void

            kfd_smi_event_update_thermal_throttling(struct kfd_node *dev,

                   void kfd_smi_event_update_vmfault(struct kfd_node
                *dev, uint16_t pasid)
                   {
                       struct amdgpu_task_info *task_info;
                +     uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;

                -     task_info =
                amdgpu_vm_get_task_info_pasid(dev->adev, pasid);
                +     task_info =
                amdgpu_vm_get_task_info_pasid(dev->adev, pasid, xcp_id);
                       if (task_info) {
                               /* Report VM faults from user
                applications, not retry from kernel */
                               if (task_info->pid)
maintainer
#7 lore raw

Yeah, I completely agree with Xiaogang.

The PASID is an identifier of an address space. And the idea of the KFD was that we can just use the same address space and with it the page tables for multiple execution devices, e.g. CPUs, GPUs etc...

That idea turned out to be a bad one because it clashes with some use cases (e.g. native context virtualization). The better approach is to see the CPU and GPU processes as separate things which just share the same underlying data.

Opening the KFD node multiple times currently results in the same KFD process being used. We should probably consider changing that.

Regards,
Christian.

Am 11.09.24 um 01:59 schrieb Chen, Xiaogang:

Quoted 1,128 lines

You want have 1:1 mapping between vm and pasid so can query vm from pasid.  I think there is a basic existing issue that we cannot have vm and pasid 1:1 correspondence.

PASIDs are global address space identifiers that can be shared between the GPU, an IOMMU and the driver. One app should have one pasid that iommu uses to decide which page table to use when device access system resource. But one app can open render/kfd node multiple times even for one gpu. That said one app could have multiple GPU vms .

I think we did not have this issue because app usually open a rent node or kfd node only once. With one adev has multiple partitions there are multiple vms on one adev, so have this issue.  But the root cause is not from multiple partitions and solution is not to introduce multiple pasids. I think we should have one pasid for one app and use different way to get vm from pasid.

Regards

Xiaogang

Quoted 1,114 lines · Jonathan

[Public]

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

[Public]

KMS open still set per pasid-vm bindings per adev (socket) so I don’t see how the per-partition overwrite PASID issue is primarily a KFD concern.

Are you saying the KFD process devices holds a shadow copy of the correct VM during page restore during fault?

Doesn’t it acquire the wrong VM object on process init in the first place?

Even if it were the case the KFD had a separate VM reference, the underlying IRQ fault handling is still broken.

We probably don’t want to bandage over something to fix one symptom.

Jon

*From:*Yang, Philip <[email protected]>
*Sent:* Tuesday, September 10, 2024 11:24 AM
*To:* Koenig, Christian <[email protected]>; Kim, Jonathan <[email protected]>; [email protected] *Cc:* Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]> *Subject:* Re: [PATCH] drm/amdkfd: fix vm-pasid lookup for multiple partitions

On 2024-09-09 14:46, Christian König wrote:

Am 09.09.24 um 18:02 schrieb Kim, Jonathan:

[Public]

-----Original Message-----
From: Christian König <[email protected]> <mailto:[email protected]>
Sent: Thursday, September 5, 2024 10:24 AM
To: Kim, Jonathan <[email protected]> <mailto:[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]> <mailto:[email protected]>; Deucher, Alexander <[email protected]> <mailto:[email protected]>; Joshi, Mukul <[email protected]> <mailto:[email protected]>
Subject: Re: [PATCH] drm/amdkfd: fix vm-pasid lookup for multiple partitions

Caution: This message originated from an External Source. Use proper caution
when opening attachments, clicking links, or responding.

Am 19.08.24 um 19:59 schrieb Jonathan Kim:

Currently multiple partitions will incorrectly overwrite the VM lookup
table since the table is indexed by PASID and multiple partitions can
register different VM objects on the same PASID.

That's a rather bad idea. Why do we have the same PASID for different VM
objects in the first place?

Alex can probably elaborate on the KGD side, but from what I can see, the KMS driver open call has always assigned a new VM object per PASID on an open call.
The KFD acquires and replaces the KGD PASID-VMID registration on its own compute process open/creation call.
If this is the bad_idea you're referring to, then someone else will have to chime in.  I don't have much history on this unfortunately.

Yeah, Felix and I designed that.

app opens drm node to create vm for each partition, with different vm->pasid for each vm, issue is from kfd_ioctl_acquire_vm -> kfd_process_device_init_vm -> amdgpu_amdkfd_gpuvm_set_vm_pasid, to replace all vm->pasid with kfd process->pasid, which is from open kfd node. This ends up to store only one vm to adev->vm_manager.pasids with KFD process pasid, so we cannot retrieve correct vm from adev->vm_manager.pasids on mGPUs or multiple partitions.

That aside, the current problem is, is that all KFD device structures are logical partitions and register their PASID-VM binding using this concept of a device.

As far as I can see that is the fundamental problem. This needs to be fixed instead.

On the KGD side however, the registration table is maintained in the adev struct, which is a physical socket.
So there's a mismatch in understanding of what a device is between the KFD & KGD with regard to the look up table that results in bad bindings.

Adding a per-partition dimension to the existing lookup table resolves issues where seeing, for example, with memory violation interception and XNACK i.e bad bindings result in wrong vm object found to set no-retry flags on memory violations.

svm_range_restore_pages retry fault recover uses fault pasid to get kfd process, and use the fault node_id to get pdd->vm, maybe you can use this way to fix the debugger issue.

Regards,

Philip

    Yeah that is pretty much a no-go.

    The PASID and how it is used is defined by the PCIe
    specifications. If we now start to assign multiple VMs to the
    same PASID then we are violating the PCIe specification.

    The problems you see are most likely just the tip of the iceberg
    here.

    Regards,
    Christian.



        Jon


            Regards,
            Christian.


                This results in loading the wrong VM object on PASID
                query.

                To correct this, setup the lookup table to be
                per-partition-per-PASID
                instead.

                Signed-off-by: Jonathan Kim <[email protected]>
                <mailto:[email protected]>
                ---
                drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 12 ++++
                drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  1 +
                drivers/gpu/drm/amd/amdgpu/amdgpu_job.c |  4 +-
                drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  7 ++-
                drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 55
                +++++++++++------

            -- 

                drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 11 +++-
                drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c |  5 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c |  5 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c |  5 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c |  3 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c |  5 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 16 ++----
                drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c |  2 +-
                drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c |  4 +-
                drivers/gpu/drm/amd/amdkfd/kfd_events.c |  3 +-
                .../gpu/drm/amd/amdkfd/kfd_int_process_v10.c |  8 +--
                .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c |  8 +--
                drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c |  3 +-
                   18 files changed, 92 insertions(+), 65 deletions(-)

                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c

                index c272461d70a9..28db789610e1 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
                @@ -887,3 +887,15 @@ int amdgpu_amdkfd_unmap_hiq(struct

            amdgpu_device *adev, u32 doorbell_off,

                       return r;
                   }
                +
                +int amdgpu_amdkfd_node_id_to_xcc_id(struct
                amdgpu_device *adev,

            uint32_t node_id)

                +{
                +     if (adev->gfx.funcs->ih_node_to_logical_xcc) {
                +             int xcc_id =
                adev->gfx.funcs->ih_node_to_logical_xcc(adev, node_id);
                +
                +             if (xcc_id >= 0)
                +                     return xcc_id;
                +     }
                +
                +     return 0;
                +}
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h

                index 4ed49265c764..bf8bb45d8ab6 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
                @@ -356,6 +356,7 @@ void
                amdgpu_amdkfd_unreserve_mem_limit(struct

            amdgpu_device *adev,

                               uint64_t size, u32 alloc_flag, int8_t
                xcp_id);

                   u64 amdgpu_amdkfd_xcp_memory_size(struct
                amdgpu_device *adev, int

            xcp_id);

                +int amdgpu_amdkfd_node_id_to_xcc_id(struct
                amdgpu_device *adev,

            uint32_t node_id);

                   #define KFD_XCP_MEM_ID(adev, xcp_id) \
                               ((adev)->xcp_mgr && (xcp_id) >= 0 ?\
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c

                index c6a1783fc9ef..bf9f8802e18d 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
                @@ -37,7 +37,7 @@ static enum drm_gpu_sched_stat

            amdgpu_job_timedout(struct drm_sched_job *s_job)

                       struct amdgpu_job *job = to_amdgpu_job(s_job);
                       struct amdgpu_task_info *ti;
                       struct amdgpu_device *adev = ring->adev;
                -     int idx;
                +     int idx, xcp_id = !job->vm ? 0 : job->vm->xcp_id;
                       int r;

                       if (!drm_dev_enter(adev_to_drm(adev), &idx)) {
                @@ -62,7 +62,7 @@ static enum drm_gpu_sched_stat

            amdgpu_job_timedout(struct drm_sched_job *s_job)

                job->base.sched->name,
                atomic_read(&ring->fence_drv.last_seq),
                               ring->fence_drv.sync_seq);

                -     ti = amdgpu_vm_get_task_info_pasid(ring->adev,
                job->pasid);
                +     ti = amdgpu_vm_get_task_info_pasid(ring->adev,
                job->pasid, xcp_id);
                       if (ti) {
                               dev_err(adev->dev,
                                       "Process information: process
                %s pid %d thread %s pid %d\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

                index d9fde38f6ee2..e413bf4a3e84 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
                @@ -1275,17 +1275,20 @@ int amdgpu_info_ioctl(struct
                drm_device *dev,

            void *data, struct drm_file *filp)

                               struct amdgpu_vm *vm = &fpriv->vm;
                               struct drm_amdgpu_info_gpuvm_fault
                gpuvm_fault;
                               unsigned long flags;
                +             int i;

                               if (!vm)
                                       return -EINVAL;

                               memset(&gpuvm_fault, 0,
                sizeof(gpuvm_fault));

                - xa_lock_irqsave(&adev->vm_manager.pasids, flags);
                +             for (i = 0; i <
                adev->xcp_mgr->num_xcps; i++)
                + xa_lock_irqsave(&adev->vm_manager.pasids[i], flags);
                               gpuvm_fault.addr = vm->fault_info.addr;
                               gpuvm_fault.status =
                vm->fault_info.status;
                               gpuvm_fault.vmhub = vm->fault_info.vmhub;
                - xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
                +             for (i = 0; i <
                adev->xcp_mgr->num_xcps; i++)
                + xa_unlock_irqrestore(&adev->vm_manager.pasids[i],
                flags);

                               return copy_to_user(out, &gpuvm_fault,
                min((size_t)size, sizeof(gpuvm_fault))) ? -EFAULT : 0;
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

                index bcb729094521..f43e1c15f423 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
                @@ -146,7 +146,7 @@ int amdgpu_vm_set_pasid(struct
                amdgpu_device

            *adev, struct amdgpu_vm *vm,

                               return 0;

                       if (vm->pasid) {
                -             r =
                xa_err(xa_erase_irq(&adev->vm_manager.pasids,
                vm->pasid));
                +             r =
                xa_err(xa_erase_irq(&adev->vm_manager.pasids[vm->xcp_id],


            vm->pasid));

                               if (r < 0)
                                       return r;

                @@ -154,7 +154,7 @@ int amdgpu_vm_set_pasid(struct
                amdgpu_device

            *adev, struct amdgpu_vm *vm,

                       }

                       if (pasid) {
                -             r =
                xa_err(xa_store_irq(&adev->vm_manager.pasids, pasid, vm,
                +             r =
                xa_err(xa_store_irq(&adev->vm_manager.pasids[vm->xcp_id],


            pasid, vm,

                GFP_KERNEL));
                               if (r < 0)
                                       return r;
                @@ -2288,14 +2288,14 @@ static void

            amdgpu_vm_destroy_task_info(struct kref *kref)

                   }

                   static inline struct amdgpu_vm *
                -amdgpu_vm_get_vm_from_pasid(struct amdgpu_device
                *adev, u32 pasid)
                +amdgpu_vm_get_vm_from_pasid(struct amdgpu_device
                *adev, u32 pasid,

            u32 xcp_id)

                   {
                       struct amdgpu_vm *vm;
                       unsigned long flags;

                - xa_lock_irqsave(&adev->vm_manager.pasids, flags);
                -     vm = xa_load(&adev->vm_manager.pasids, pasid);
                - xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
                + xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id],
                flags);
                +     vm = xa_load(&adev->vm_manager.pasids[xcp_id],
                pasid);
                +
                xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id],
                flags);

                       return vm;
                   }
                @@ -2343,10 +2343,10 @@
                amdgpu_vm_get_task_info_vm(struct

            amdgpu_vm *vm)

                    * referenced down with amdgpu_vm_put_task_info.
                    */
                   struct amdgpu_task_info *
                -amdgpu_vm_get_task_info_pasid(struct amdgpu_device
                *adev, u32 pasid)
                +amdgpu_vm_get_task_info_pasid(struct amdgpu_device
                *adev, u32 pasid,

            u32 xcp_id)

                   {
                       return amdgpu_vm_get_task_info_vm(
                - amdgpu_vm_get_vm_from_pasid(adev, pasid));
                + amdgpu_vm_get_vm_from_pasid(adev, pasid, xcp_id));
                   }

                   static int amdgpu_vm_create_task_info(struct
                amdgpu_vm *vm)
                @@ -2481,6 +2481,8 @@ int amdgpu_vm_init(struct
                amdgpu_device

            *adev, struct amdgpu_vm *vm,

                amdgpu_bo_unreserve(vm->root.bo);
                       amdgpu_bo_unref(&root_bo);

                +     vm->xcp_id = xcp_id < 0 ? 0 : xcp_id;
                +
                       return 0;

                   error_free_root:
                @@ -2695,8 +2697,8 @@ void amdgpu_vm_manager_init(struct

            amdgpu_device *adev)

                   #else
                       adev->vm_manager.vm_update_mode = 0;
                   #endif
                -
                - xa_init_flags(&adev->vm_manager.pasids,
                XA_FLAGS_LOCK_IRQ);
                +     for (i = 0; i < MAX_XCP; i++)
                + xa_init_flags(&(adev->vm_manager.pasids[i]),

            XA_FLAGS_LOCK_IRQ);

                   }

                   /**
                @@ -2708,10 +2710,15 @@ void
                amdgpu_vm_manager_init(struct

            amdgpu_device *adev)

                    */
                   void amdgpu_vm_manager_fini(struct amdgpu_device
                *adev)
                   {
                - WARN_ON(!xa_empty(&adev->vm_manager.pasids));
                - xa_destroy(&adev->vm_manager.pasids);
                +     int i;
                +
                +     for (i = 0; i < MAX_XCP; i++) {
                + WARN_ON(!xa_empty(&adev->vm_manager.pasids[i]));
                + xa_destroy(&adev->vm_manager.pasids[i]);
                +     }

                       amdgpu_vmid_mgr_fini(adev);
                +
                   }

                   /**
                @@ -2778,17 +2785,18 @@ bool
                amdgpu_vm_handle_fault(struct

            amdgpu_device *adev, u32 pasid,

                       unsigned long irqflags;
                       uint64_t value, flags;
                       struct amdgpu_vm *vm;
                -     int r;
                +     int r, xcp_id;

                - xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
                -     vm = xa_load(&adev->vm_manager.pasids, pasid);
                +     xcp_id = amdgpu_amdkfd_node_id_to_xcc_id(adev,
                node_id)/adev-
                gfx.num_xcc_per_xcp;
                + xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id],
                irqflags);
                +     vm = xa_load(&adev->vm_manager.pasids[xcp_id],
                pasid);
                       if (vm) {
                               root = amdgpu_bo_ref(vm->root.bo);
                               is_compute_context =
                vm->is_compute_context;
                       } else {
                               root = NULL;
                       }
                - xa_unlock_irqrestore(&adev->vm_manager.pasids,
                irqflags);
                +
                xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id],
                irqflags);

                       if (!root)
                               return false;
                @@ -2806,11 +2814,11 @@ bool
                amdgpu_vm_handle_fault(struct

            amdgpu_device *adev, u32 pasid,

                               goto error_unref;

                       /* Double check that the VM still exists */
                - xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
                -     vm = xa_load(&adev->vm_manager.pasids, pasid);
                + xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id],
                irqflags);
                +     vm = xa_load(&adev->vm_manager.pasids[xcp_id],
                pasid);
                       if (vm && vm->root.bo != root)
                               vm = NULL;
                - xa_unlock_irqrestore(&adev->vm_manager.pasids,
                irqflags);
                +
                xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id],
                irqflags);
                       if (!vm)
                               goto error_unlock;

                @@ -2968,14 +2976,15 @@ void
                amdgpu_vm_update_fault_cache(struct

            amdgpu_device *adev,

                unsigned int pasid,
                                                 uint64_t addr,
                                                 uint32_t status,
                -                               unsigned int vmhub)
                +                               unsigned int vmhub,
                +                               uint32_t xcp_id)
                   {
                       struct amdgpu_vm *vm;
                       unsigned long flags;

                - xa_lock_irqsave(&adev->vm_manager.pasids, flags);
                + xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id],
                flags);

                -     vm = xa_load(&adev->vm_manager.pasids, pasid);
                +     vm = xa_load(&adev->vm_manager.pasids[xcp_id],
                pasid);
                       /* Don't update the fault cache if status is
                0.  In the multiple
                        * fault case, subsequent faults will return a
                0 status which is
                        * useless for userspace and replaces the
                useful fault status, so
                @@ -3008,7 +3017,7 @@ void
                amdgpu_vm_update_fault_cache(struct

            amdgpu_device *adev,

                WARN_ONCE(1, "Invalid vmhub %u\n", vmhub);
                               }
                       }
                - xa_unlock_irqrestore(&adev->vm_manager.pasids, flags);
                +
                xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id],
                flags);
                   }

                   /**
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h

                index 046949c4b695..1499f5f731e9 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
                @@ -35,6 +35,7 @@
                   #include "amdgpu_sync.h"
                   #include "amdgpu_ring.h"
                   #include "amdgpu_ids.h"
                +#include "amdgpu_xcp.h"

                   struct drm_exec;

                @@ -418,6 +419,9 @@ struct amdgpu_vm {

                       /* cached fault info */
                       struct amdgpu_vm_fault_info fault_info;
                +
                +     /* XCP ID */
                +     int xcp_id;
                   };

                   struct amdgpu_vm_manager {
                @@ -456,7 +460,7 @@ struct amdgpu_vm_manager {
                       /* PASID to VM mapping, will be used in
                interrupt context to
                        * look up VM of a page fault
                        */
                -     struct xarray                           pasids;
                +     struct xarray pasids[MAX_XCP];
                       /* Global registration of recent page fault
                information */
                       struct amdgpu_vm_fault_info fault_info;
                   };
                @@ -550,7 +554,7 @@ bool
                amdgpu_vm_need_pipeline_sync(struct

            amdgpu_ring *ring,

                   void amdgpu_vm_check_compute_bug(struct
                amdgpu_device *adev);

                   struct amdgpu_task_info *
                -amdgpu_vm_get_task_info_pasid(struct amdgpu_device
                *adev, u32 pasid);
                +amdgpu_vm_get_task_info_pasid(struct amdgpu_device
                *adev, u32 pasid,

            u32 xcp_id);

                   struct amdgpu_task_info *
                   amdgpu_vm_get_task_info_vm(struct amdgpu_vm *vm);
                @@ -649,7 +653,8 @@ void
                amdgpu_vm_update_fault_cache(struct

            amdgpu_device *adev,

                unsigned int pasid,
                                                 uint64_t addr,
                                                 uint32_t status,
                -                               unsigned int vmhub);
                +                               unsigned int vmhub,
                +                               uint32_t xcp_id);
                   void amdgpu_vm_tlb_fence_create(struct
                amdgpu_device *adev,
                                                struct amdgpu_vm *vm,
                                                struct dma_fence
                **fence);
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c

                index f0ceab3ce5bf..24b042febf5c 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
                @@ -151,7 +151,8 @@ static int
                gmc_v10_0_process_interrupt(struct

            amdgpu_device *adev,

                WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

                amdgpu_vm_update_fault_cache(adev, entry->pasid,
                addr, status,
                - entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0));

                + entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0),

                + 0);
                       }

                       if (!printk_ratelimit())
                @@ -161,7 +162,7 @@ static int
                gmc_v10_0_process_interrupt(struct

            amdgpu_device *adev,

                               "[%s] page fault (src_id:%u ring:%u
                vmid:%u pasid:%u)\n",
                               entry->vmid_src ? "mmhub" : "gfxhub",
                               entry->src_id, entry->ring_id,
                entry->vmid, entry->pasid);
                -     task_info = amdgpu_vm_get_task_info_pasid(adev,
                entry->pasid);
                +     task_info = amdgpu_vm_get_task_info_pasid(adev,
                entry->pasid, 0);
                       if (task_info) {
                               dev_err(adev->dev,
                                       " in process %s pid %d thread
                %s pid %d\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c

                index 2797fd84432b..3507046d33e6 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c
                @@ -122,7 +122,8 @@ static int
                gmc_v11_0_process_interrupt(struct

            amdgpu_device *adev,

                WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

                amdgpu_vm_update_fault_cache(adev, entry->pasid,
                addr, status,
                - entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0));

                + entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0),

                + 0);
                       }

                       if (printk_ratelimit()) {
                @@ -132,7 +133,7 @@ static int
                gmc_v11_0_process_interrupt(struct

            amdgpu_device *adev,

                "[%s] page fault (src_id:%u ring:%u vmid:%u
                pasid:%u)\n",
                                       entry->vmid_src ? "mmhub" :
                "gfxhub",
                                       entry->src_id, entry->ring_id,
                entry->vmid, entry->pasid);
                -             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
                               if (task_info) {
                                       dev_err(adev->dev,
                                               " in process %s pid %d
                thread %s pid %d)\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c

                index 60acf676000b..9844564c6c74 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c
                @@ -115,7 +115,8 @@ static int
                gmc_v12_0_process_interrupt(struct

            amdgpu_device *adev,

                WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

                amdgpu_vm_update_fault_cache(adev, entry->pasid,
                addr, status,
                - entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0));

                + entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0),

                + 0);
                       }

                       if (printk_ratelimit()) {
                @@ -125,7 +126,7 @@ static int
                gmc_v12_0_process_interrupt(struct

            amdgpu_device *adev,

                "[%s] page fault (src_id:%u ring:%u vmid:%u
                pasid:%u)\n",
                                       entry->vmid_src ? "mmhub" :
                "gfxhub",
                                       entry->src_id, entry->ring_id,
                entry->vmid, entry->pasid);
                -             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
                               if (task_info) {
                                       dev_err(adev->dev,
                                               " in process %s pid %d
                thread %s pid %d)\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c

                index 994432fb57ea..2cdb0cbb7c4d 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
                @@ -1268,7 +1268,8 @@ static int
                gmc_v7_0_process_interrupt(struct

            amdgpu_device *adev,

                               return 0;

                       amdgpu_vm_update_fault_cache(adev, entry->pasid,
                - ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,

            AMDGPU_GFXHUB(0));

                + ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
                + AMDGPU_GFXHUB(0), 0);

                       if (amdgpu_vm_fault_stop ==
                AMDGPU_VM_FAULT_STOP_FIRST)
                gmc_v7_0_set_fault_enable_default(adev, false);
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c

                index 86488c052f82..6855caeb7f74 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
                @@ -1437,7 +1437,8 @@ static int
                gmc_v8_0_process_interrupt(struct

            amdgpu_device *adev,

                               return 0;

                       amdgpu_vm_update_fault_cache(adev, entry->pasid,
                - ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,

            AMDGPU_GFXHUB(0));

                + ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
                + AMDGPU_GFXHUB(0), 0);

                       if (amdgpu_vm_fault_stop ==
                AMDGPU_VM_FAULT_STOP_FIRST)
                gmc_v8_0_set_fault_enable_default(adev, false);
                @@ -1448,7 +1449,7 @@ static int
                gmc_v8_0_process_interrupt(struct

            amdgpu_device *adev,

                dev_err(adev->dev, "GPU fault detected: %d 0x%08x\n",
                                       entry->src_id,
                entry->src_data[0]);

                -             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
                               if (task_info) {
                                       dev_err(adev->dev, " for
                process %s pid %d thread %s pid %d\n",
                task_info->process_name, task_info->tgid,
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c

                index b73136d390cc..e183e08b2c02 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
                @@ -556,10 +556,12 @@ static int
                gmc_v9_0_process_interrupt(struct

            amdgpu_device *adev,

                       unsigned int vmhub;
                       u64 addr;
                       uint32_t cam_index = 0;
                -     int ret, xcc_id = 0;
                -     uint32_t node_id;
                +     int ret;
                +     uint32_t node_id, xcc_id, xcp_id;

                       node_id = entry->node_id;
                +     xcc_id = amdgpu_amdkfd_node_id_to_xcc_id(adev,
                node_id);
                +     xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;

                       addr = (u64)entry->src_data[0] << 12;
                       addr |= ((u64)entry->src_data[1] & 0xf) << 44;
                @@ -572,12 +574,6 @@ static int
                gmc_v9_0_process_interrupt(struct

            amdgpu_device *adev,

                               vmhub = AMDGPU_MMHUB1(0);
                       } else {
                               hub_name = "gfxhub0";
                -             if
                (adev->gfx.funcs->ih_node_to_logical_xcc) {
                -                     xcc_id =
                adev->gfx.funcs->ih_node_to_logical_xcc(adev,
                -                             node_id);
                -                     if (xcc_id < 0)
                -                             xcc_id = 0;
                -             }
                               vmhub = xcc_id;
                       }
                       hub = &adev->vmhub[vmhub];
                @@ -631,7 +627,7 @@ static int
                gmc_v9_0_process_interrupt(struct

            amdgpu_device *adev,

                retry_fault ? "retry" : "no-retry",
                               entry->src_id, entry->ring_id,
                entry->vmid, entry->pasid);

                -     task_info = amdgpu_vm_get_task_info_pasid(adev,
                entry->pasid);
                +     task_info = amdgpu_vm_get_task_info_pasid(adev,
                entry->pasid,

            xcp_id);

                       if (task_info) {
                               dev_err(adev->dev,
                                       " for process %s pid %d thread
                %s pid %d)\n",
                @@ -675,7 +671,7 @@ static int
                gmc_v9_0_process_interrupt(struct

            amdgpu_device *adev,

                       if (!amdgpu_sriov_vf(adev))
                WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

                -     amdgpu_vm_update_fault_cache(adev,
                entry->pasid, addr, status,

            vmhub);

                + amdgpu_vm_update_fault_cache(adev, entry->pasid,
                addr, status,

            vmhub, xcp_id);

                dev_err(adev->dev,
                "VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c

            b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c

                index 23ef4eb36b40..1ac4224bbe5b 100644
                --- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
                @@ -2182,7 +2182,7 @@ static int
                sdma_v4_0_print_iv_entry(struct

            amdgpu_device *adev,

                instance, addr, entry->src_id, entry->ring_id,
                entry->vmid,
                                          entry->pasid);

                -     task_info = amdgpu_vm_get_task_info_pasid(adev,
                entry->pasid);
                +     task_info = amdgpu_vm_get_task_info_pasid(adev,
                entry->pasid, 0);
                       if (task_info) {
                dev_dbg_ratelimited(adev->dev,
                                                   " for process %s
                pid %d thread %s pid %d\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

            b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

                index 57f16c09abfc..c8b5c0302ca7 100644
                --- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
                +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
                @@ -1683,6 +1683,8 @@ static int
                sdma_v4_4_2_print_iv_entry(struct

            amdgpu_device *adev,

                       int instance;
                       struct amdgpu_task_info *task_info;
                       u64 addr;
                +     uint32_t xcc_id =
                amdgpu_amdkfd_node_id_to_xcc_id(adev, entry-
                node_id);
                +     uint32_t xcp_id =
                xcc_id/adev->gfx.num_xcc_per_xcp;

                       instance = sdma_v4_4_2_irq_id_to_seq(adev,
                entry->client_id);
                       if (instance < 0 || instance >=
                adev->sdma.num_instances) {
                @@ -1698,7 +1700,7 @@ static int
                sdma_v4_4_2_print_iv_entry(struct

            amdgpu_device *adev,

                instance, addr, entry->src_id, entry->ring_id,
                entry->vmid,
                                           entry->pasid);

                -     task_info = amdgpu_vm_get_task_info_pasid(adev,
                entry->pasid);
                +     task_info = amdgpu_vm_get_task_info_pasid(adev,
                entry->pasid,

            xcp_id);

                       if (task_info) {
                dev_dbg_ratelimited(adev->dev, " for process %s pid
                %d thread %s

            pid %d\n",

                task_info->process_name, task_info->tgid,
                diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_events.c

            b/drivers/gpu/drm/amd/amdkfd/kfd_events.c

                index ea3792249209..c098fbaf0e1c 100644
                --- a/drivers/gpu/drm/amd/amdkfd/kfd_events.c
                +++ b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
                @@ -1262,8 +1262,9 @@ void
                kfd_signal_reset_event(struct kfd_node

            *dev)

                               if (dev->dqm->detect_hang_count) {
                                       struct amdgpu_task_info *ti;
                +                     uint32_t xcp_id = dev->xcp ?
                dev->xcp->id : 0;

                -                     ti =
                amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid);
                +                     ti =
                amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid,

            xcp_id);

                                       if (ti) {
                dev_err(dev->adev->dev,
                "Queues reset on process %s tid %d thread %s pid %d\n",
                diff --git
                a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c

            b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c

                index 8e0d0356e810..d7cbf9525698 100644
                --- a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c
                +++ b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c
                @@ -377,12 +377,8 @@ static void
                event_interrupt_wq_v10(struct

            kfd_node *dev,

                               struct kfd_hsa_memory_exception_data
                exception_data;

                               /* gfxhub */
                -             if (!vmid_type &&
                dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
                -                     hub_inst =
                dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev-
                adev,
                -                             node_id);
                -                     if (hub_inst < 0)
                -                             hub_inst = 0;
                -             }
                +             if (!vmid_type)
                +                     hub_inst =
                amdgpu_amdkfd_node_id_to_xcc_id(dev->adev,

            node_id);

                               /* mmhub */
                               if (vmid_type && client_id ==
                SOC15_IH_CLIENTID_VMC)
                diff --git
                a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c

            b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c

                index a9c3580be8c9..4708b8c811a5 100644
                --- a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c
                +++ b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c
                @@ -437,12 +437,8 @@ static void
                event_interrupt_wq_v9(struct

            kfd_node *dev,

                               struct kfd_hsa_memory_exception_data
                exception_data;

                               /* gfxhub */
                -             if (!vmid_type &&
                dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
                -                     hub_inst =
                dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev-
                adev,
                -                             node_id);
                -                     if (hub_inst < 0)
                -                             hub_inst = 0;
                -             }
                +             if (!vmid_type)
                +                     hub_inst =
                amdgpu_amdkfd_node_id_to_xcc_id(dev->adev,

            node_id);

                               /* mmhub */
                               if (vmid_type && client_id ==
                SOC15_IH_CLIENTID_VMC)
                diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c

            b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c

                index ea6a8e43bd5b..b5f2f5b1069c 100644
                --- a/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
                +++ b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
                @@ -251,8 +251,9 @@ void

            kfd_smi_event_update_thermal_throttling(struct kfd_node
            *dev,

                   void kfd_smi_event_update_vmfault(struct kfd_node
                *dev, uint16_t pasid)
                   {
                       struct amdgpu_task_info *task_info;
                +     uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;

                -     task_info =
                amdgpu_vm_get_task_info_pasid(dev->adev, pasid);
                +     task_info =
                amdgpu_vm_get_task_info_pasid(dev->adev, pasid, xcp_id);
                       if (task_info) {
                               /* Report VM faults from user
                applications, not retry from kernel */
                               if (task_info->pid)
#8 lore raw

On 2024-09-11 02:54, Christian König wrote:
Yeah, I completely agree with Xiaogang.

The PASID is an identifier of an address space. And the idea of the KFD was that we can just use the same address space and with it the page tables for multiple execution devices, e.g. CPUs, GPUs etc...

That idea turned out to be a bad one because it clashes with some use cases (e.g. native context virtualization). The better approach is to see the CPU and GPU processes as separate things which just share the same underlying data.

Opening the KFD node multiple times currently results in the same KFD process being used. We should probably consider changing that. It is one KFD process binding to one app process, with count to support multiple open/close of for the same process.

The IOMMU most likely uses Linux process pid, not from kfd process->pasid. The KFD process->pasid is passed to F/W to map queues, flush TLB.
The reason to replace vm->pasid with KFD process->pasid is to find vm from fault pasid, then for compute vm, find the kfd process from pasid.
I can see a bug in amdgpu_vm_handle_fault, only for compute vm, to force update PTE no-retry-fault to the incorrect VM for multiple partitions. This patch will fix this bug but we can have a simple fix.

Regards,
Philip

Regards,
Christian.

Am 11.09.24 um 01:59 schrieb Chen, Xiaogang:

You want have 1:1 mapping between vm and pasid so can query vm from pasid.  I think there is a basic existing issue that we cannot have vm and pasid 1:1 correspondence.
PASIDs are global address space identifiers that can be shared between the GPU, an IOMMU and the driver. One app should have one pasid that iommu uses to decide which page table to use when device access system resource. But one app can open render/kfd node multiple times even for one gpu. That said one app could have multiple GPU vms . I think we did not have this issue because app usually open a rent node or kfd node only once. With one adev has multiple partitions there are multiple vms on one adev, so have this issue.  But the root cause is not from multiple partitions and solution is not to introduce multiple pasids. I think we should have one pasid for one app and use different way to get vm from pasid.

Regards
Xiaogang

On 9/10/2024 3:47 PM, Kim, Jonathan wrote:
[Public]

Caution:This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding. [Public]

KMS open still set per pasid-vm bindings per adev (socket) so I don’t see how the per-partition overwrite PASID issue is primarily a KFD concern. Are you saying the KFD process devices holds a shadow copy of the correct VM during page restore during fault?
Doesn’t it acquire the wrong VM object on process init in the first place?
Even if it were the case the KFD had a separate VM reference, the underlying IRQ fault handling is still broken.
We probably don’t want to bandage over something to fix one symptom.

Jon


From:Yang, Philip <[email protected]>
Sent:Tuesday, September 10, 2024 11:24 AM
To:Koenig, Christian <[email protected]>; Kim, Jonathan <[email protected]>; [email protected] Cc:Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]> Subject:Re: [PATCH] drm/amdkfd: fix vm-pasid lookup for multiple partitions


On 2024-09-09 14:46, Christian König wrote:
Am 09.09.24 um 18:02 schrieb Kim, Jonathan:

[Public]

-----Original Message-----
From: Christian König <[email protected]>
Sent: Thursday, September 5, 2024 10:24 AM
To: Kim, Jonathan <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]>
Subject: Re: [PATCH] drm/amdkfd: fix vm-pasid lookup for multiple partitions

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Am 19.08.24 um 19:59 schrieb Jonathan Kim:

Currently multiple partitions will incorrectly overwrite the VM lookup
table since the table is indexed by PASID and multiple partitions can
register different VM objects on the same PASID.
That's a rather bad idea. Why do we have the same PASID for different VM
objects in the first place?
Alex can probably elaborate on the KGD side, but from what I can see, the KMS driver open call has always assigned a new VM object per PASID on an open call. The KFD acquires and replaces the KGD PASID-VMID registration on its own compute process open/creation call.
If this is the bad_idea you're referring to, then someone else will have to chime in.  I don't have much history on this unfortunately.

Yeah, Felix and I designed that.
app opens drm node to create vm for each partition, with different vm->pasid for each vm, issue is from kfd_ioctl_acquire_vm -> kfd_process_device_init_vm ->  amdgpu_amdkfd_gpuvm_set_vm_pasid, to replace all vm->pasid with kfd process->pasid, which is from open kfd node. This ends up to store only one vm to adev->vm_manager.pasids with KFD process pasid, so we cannot retrieve correct vm from adev->vm_manager.pasids on mGPUs or multiple partitions.

That aside, the current problem is, is that all KFD device structures are logical partitions and register their PASID-VM binding using this concept of a device.

As far as I can see that is the fundamental problem. This needs to be fixed instead.

On the KGD side however, the registration table is maintained in the adev struct, which is a physical socket.
So there's a mismatch in understanding of what a device is between the KFD & KGD with regard to the look up table that results in bad bindings.

Adding a per-partition dimension to the existing lookup table resolves issues where seeing, for example, with memory violation interception and XNACK i.e bad bindings result in wrong vm object found to set no-retry flags on memory violations. svm_range_restore_pages retry fault recover uses fault pasid to get kfd process, and use the fault node_id to get pdd->vm, maybe you can use this way to fix the debugger issue.
Regards,
Philip

Yeah that is pretty much a no-go.

The PASID and how it is used is defined by the PCIe specifications. If we now start to assign multiple VMs to the same PASID then we are violating the PCIe specification.

The problems you see are most likely just the tip of the iceberg here.

Regards,
Christian.

Jon

Regards,
Christian.

This results in loading the wrong VM object on PASID query.

To correct this, setup the lookup table to be per-partition-per-PASID instead.

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    | 12 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |  1 + drivers/gpu/drm/amd/amdgpu/amdgpu_job.c       |  4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |  7 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 55 +++++++++++------ --

   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h        | 11 +++-
   drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c        |  5 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c        |  5 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c        |  5 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c         |  3 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c         |  5 +-
   drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c         | 16 ++----

   drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c        |  2 +- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c      |  4 +- drivers/gpu/drm/amd/amdkfd/kfd_events.c       |  3 +- .../gpu/drm/amd/amdkfd/kfd_int_process_v10.c  |  8 +-- .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c   |  8 +-- drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c   |  3 +-

   18 files changed, 92 insertions(+), 65 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c

index c272461d70a9..28db789610e1 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0 -0
@@ -887,3 +887,15 @@ int amdgpu_amdkfd_unmap_hiq(struct

amdgpu_device *adev, u32 doorbell_off,

       return r;
   }
+
+int amdgpu_amdkfd_node_id_to_xcc_id(struct amdgpu_device *adev, uint32_t node_id)

+{
+     if (adev->gfx.funcs->ih_node_to_logical_xcc) {
+             int xcc_id = adev->gfx.funcs->ih_node_to_logical_xcc(adev, node_id); +
+             if (xcc_id >= 0)
+                     return xcc_id;
+     }
+
+     return 0;
+}

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h

index 4ed49265c764..bf8bb45d8ab6 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +0 -0
@@ -356,6 +356,7 @@ void amdgpu_amdkfd_unreserve_mem_limit(struct

amdgpu_device *adev,

               uint64_t size, u32 alloc_flag, int8_t xcp_id);

   u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int xcp_id);

+int amdgpu_amdkfd_node_id_to_xcc_id(struct amdgpu_device *adev, uint32_t node_id);

   #define KFD_XCP_MEM_ID(adev, xcp_id) \
               ((adev)->xcp_mgr && (xcp_id) >= 0 ?\

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c

index c6a1783fc9ef..bf9f8802e18d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
@@ -37,7 +37,7 @@ static enum drm_gpu_sched_stat

amdgpu_job_timedout(struct drm_sched_job *s_job)

       struct amdgpu_job *job = to_amdgpu_job(s_job); struct amdgpu_task_info *ti;
       struct amdgpu_device *adev = ring->adev; -     int idx;
+     int idx, xcp_id = !job->vm ? 0 : job->vm->xcp_id; int r;

       if (!drm_dev_enter(adev_to_drm(adev), &idx)) { @@ -62,7 +62,7 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)

               job->base.sched->name, atomic_read(&ring->fence_drv.last_seq), ring->fence_drv.sync_seq);

-     ti = amdgpu_vm_get_task_info_pasid(ring->adev, job->pasid);
+     ti = amdgpu_vm_get_task_info_pasid(ring->adev, job->pasid, xcp_id); if (ti) {
               dev_err(adev->dev,
                       "Process information: process %s pid %d thread %s pid %d\n",

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

index d9fde38f6ee2..e413bf4a3e84 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
@@ -1275,17 +1275,20 @@ int amdgpu_info_ioctl(struct drm_device *dev,

void *data, struct drm_file *filp)

               struct amdgpu_vm *vm = &fpriv->vm; struct drm_amdgpu_info_gpuvm_fault gpuvm_fault; unsigned long flags;
+             int i;

               if (!vm)
                       return -EINVAL;

               memset(&gpuvm_fault, 0, sizeof(gpuvm_fault));

-             xa_lock_irqsave(&adev->vm_manager.pasids, flags);
+             for (i = 0; i < adev->xcp_mgr->num_xcps; i++)
+                     xa_lock_irqsave(&adev->vm_manager.pasids[i], flags); gpuvm_fault.addr = vm->fault_info.addr; gpuvm_fault.status = vm->fault_info.status; gpuvm_fault.vmhub = vm->fault_info.vmhub;
-             xa_unlock_irqrestore(&adev->vm_manager.pasids, flags); +             for (i = 0; i < adev->xcp_mgr->num_xcps; i++)
+                     xa_unlock_irqrestore(&adev->vm_manager.pasids[i], flags);

               return copy_to_user(out, &gpuvm_fault,
                                   min((size_t)size, sizeof(gpuvm_fault))) ? -EFAULT : 0;

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

index bcb729094521..f43e1c15f423 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
@@ -146,7 +146,7 @@ int amdgpu_vm_set_pasid(struct amdgpu_device

*adev, struct amdgpu_vm *vm,

               return 0;

       if (vm->pasid) {
-             r = xa_err(xa_erase_irq(&adev->vm_manager.pasids, vm->pasid)); +             r = xa_err(xa_erase_irq(&adev->vm_manager.pasids[vm->xcp_id], vm->pasid));

               if (r < 0)
                       return r;

@@ -154,7 +154,7 @@ int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm,

       }

       if (pasid) {
-             r = xa_err(xa_store_irq(&adev->vm_manager.pasids, pasid, vm, +             r = xa_err(xa_store_irq(&adev->vm_manager.pasids[vm->xcp_id], pasid, vm,

                                       GFP_KERNEL)); if (r < 0)
                       return r;
@@ -2288,14 +2288,14 @@ static void amdgpu_vm_destroy_task_info(struct kref *kref)

   }

   static inline struct amdgpu_vm * -amdgpu_vm_get_vm_from_pasid(struct amdgpu_device *adev, u32 pasid) +amdgpu_vm_get_vm_from_pasid(struct amdgpu_device *adev, u32 pasid, u32 xcp_id)

   {
       struct amdgpu_vm *vm;
       unsigned long flags;

-     xa_lock_irqsave(&adev->vm_manager.pasids, flags);
-     vm = xa_load(&adev->vm_manager.pasids, pasid);
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, flags); +     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], flags); +     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid); +     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], flags);

       return vm;
   }
@@ -2343,10 +2343,10 @@ amdgpu_vm_get_task_info_vm(struct amdgpu_vm *vm)

    * referenced down with amdgpu_vm_put_task_info.
    */
   struct amdgpu_task_info * -amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid) +amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid, u32 xcp_id)

   {
       return amdgpu_vm_get_task_info_vm(
-                     amdgpu_vm_get_vm_from_pasid(adev, pasid)); +                     amdgpu_vm_get_vm_from_pasid(adev, pasid, xcp_id)); }

   static int amdgpu_vm_create_task_info(struct amdgpu_vm *vm) @@ -2481,6 +2481,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,

       amdgpu_bo_unreserve(vm->root.bo);
       amdgpu_bo_unref(&root_bo);

+     vm->xcp_id = xcp_id < 0 ? 0 : xcp_id;
+
       return 0;

   error_free_root:
@@ -2695,8 +2697,8 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev)

   #else
       adev->vm_manager.vm_update_mode = 0;
   #endif
-
-     xa_init_flags(&adev->vm_manager.pasids, XA_FLAGS_LOCK_IRQ); +     for (i = 0; i < MAX_XCP; i++)
+             xa_init_flags(&(adev->vm_manager.pasids[i]), XA_FLAGS_LOCK_IRQ);

   }

   /**
@@ -2708,10 +2710,15 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev)

    */
   void amdgpu_vm_manager_fini(struct amdgpu_device *adev) {
-     WARN_ON(!xa_empty(&adev->vm_manager.pasids)); -     xa_destroy(&adev->vm_manager.pasids);
+     int i;
+
+     for (i = 0; i < MAX_XCP; i++) {
+             WARN_ON(!xa_empty(&adev->vm_manager.pasids[i])); +             xa_destroy(&adev->vm_manager.pasids[i]); +     }

       amdgpu_vmid_mgr_fini(adev);
+
   }

   /**
@@ -2778,17 +2785,18 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid,

       unsigned long irqflags;
       uint64_t value, flags;
       struct amdgpu_vm *vm;
-     int r;
+     int r, xcp_id;

-     xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
-     vm = xa_load(&adev->vm_manager.pasids, pasid);
+     xcp_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, node_id)/adev- gfx.num_xcc_per_xcp;
+     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], irqflags); +     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid); if (vm) {
               root = amdgpu_bo_ref(vm->root.bo); is_compute_context = vm->is_compute_context; } else {
               root = NULL;
       }
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, irqflags); +     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], irqflags);

       if (!root)
               return false;
@@ -2806,11 +2814,11 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid,

               goto error_unref;

       /* Double check that the VM still exists */
-     xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
-     vm = xa_load(&adev->vm_manager.pasids, pasid);
+     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], irqflags); +     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid); if (vm && vm->root.bo != root)
               vm = NULL;
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, irqflags); +     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], irqflags); if (!vm)
               goto error_unlock;

@@ -2968,14 +2976,15 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev,

                                 unsigned int pasid, uint64_t addr, uint32_t status, -                               unsigned int vmhub) +                               unsigned int vmhub, +                               uint32_t xcp_id) {
       struct amdgpu_vm *vm;
       unsigned long flags;

-     xa_lock_irqsave(&adev->vm_manager.pasids, flags); +     xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id], flags);

-     vm = xa_load(&adev->vm_manager.pasids, pasid);
+     vm = xa_load(&adev->vm_manager.pasids[xcp_id], pasid); /* Don't update the fault cache if status is 0.  In the multiple
        * fault case, subsequent faults will return a 0 status which is
        * useless for userspace and replaces the useful fault status, so @@ -3008,7 +3017,7 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev,

                       WARN_ONCE(1, "Invalid vmhub %u\n", vmhub); }
       }
-     xa_unlock_irqrestore(&adev->vm_manager.pasids, flags); +     xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id], flags); }

   /**

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h

index 046949c4b695..1499f5f731e9 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
@@ -35,6 +35,7 @@

   #include "amdgpu_sync.h"
   #include "amdgpu_ring.h"
   #include "amdgpu_ids.h"
+#include "amdgpu_xcp.h"

   struct drm_exec;

@@ -418,6 +419,9 @@ struct amdgpu_vm {

       /* cached fault info */
       struct amdgpu_vm_fault_info fault_info;
+
+     /* XCP ID */
+     int xcp_id;
   };

   struct amdgpu_vm_manager {
@@ -456,7 +460,7 @@ struct amdgpu_vm_manager {
       /* PASID to VM mapping, will be used in interrupt context to
        * look up VM of a page fault
        */
-     struct xarray                           pasids;
+     struct xarray                           pasids[MAX_XCP]; /* Global registration of recent page fault information */ struct amdgpu_vm_fault_info     fault_info;
   };
@@ -550,7 +554,7 @@ bool amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring,

   void amdgpu_vm_check_compute_bug(struct amdgpu_device *adev);

   struct amdgpu_task_info * -amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid); +amdgpu_vm_get_task_info_pasid(struct amdgpu_device *adev, u32 pasid, u32 xcp_id);

   struct amdgpu_task_info * amdgpu_vm_get_task_info_vm(struct amdgpu_vm *vm); @@ -649,7 +653,8 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev,

                                 unsigned int pasid, uint64_t addr, uint32_t status,
-                               unsigned int vmhub); +                               unsigned int vmhub, +                               uint32_t xcp_id); void amdgpu_vm_tlb_fence_create(struct amdgpu_device *adev, struct amdgpu_vm *vm, struct dma_fence **fence);

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c

index f0ceab3ce5bf..24b042febf5c 100644

drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +0 -0
@@ -151,7 +151,8 @@ static int gmc_v10_0_process_interrupt(struct

amdgpu_device *adev,

               WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

               amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status, -                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0));

+                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0),

+                                          0);
       }

       if (!printk_ratelimit())
@@ -161,7 +162,7 @@ static int gmc_v10_0_process_interrupt(struct amdgpu_device *adev,

               "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n", entry->vmid_src ? "mmhub" : "gfxhub", entry->src_id, entry->ring_id, entry->vmid, entry->pasid); -     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid); +     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0); if (task_info) {
               dev_err(adev->dev,
                       " in process %s pid %d thread %s pid %d\n",

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c

index 2797fd84432b..3507046d33e6 100644

drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +0 -0
@@ -122,7 +122,8 @@ static int gmc_v11_0_process_interrupt(struct

amdgpu_device *adev,

               WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

               amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status, -                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0));

+                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0),

+                                          0);
       }

       if (printk_ratelimit()) {
@@ -132,7 +133,7 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev,

                       "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n", entry->vmid_src ? "mmhub" : "gfxhub", entry->src_id, entry->ring_id, entry->vmid, entry->pasid); -             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid); +             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0); if (task_info) {
                       dev_err(adev->dev,
                               " in process %s pid %d thread %s pid %d)\n",

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c

index 60acf676000b..9844564c6c74 100644

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -0
@@ -115,7 +115,8 @@ static int gmc_v12_0_process_interrupt(struct

amdgpu_device *adev,

               WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

               amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status, -                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0));

+                                          entry->vmid_src ? AMDGPU_MMHUB0(0) :
AMDGPU_GFXHUB(0),

+                                          0);
       }

       if (printk_ratelimit()) {
@@ -125,7 +126,7 @@ static int gmc_v12_0_process_interrupt(struct amdgpu_device *adev,

                       "[%s] page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n", entry->vmid_src ? "mmhub" : "gfxhub", entry->src_id, entry->ring_id, entry->vmid, entry->pasid); -             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid); +             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0); if (task_info) {
                       dev_err(adev->dev,
                               " in process %s pid %d thread %s pid %d)\n",

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c

index 994432fb57ea..2cdb0cbb7c4d 100644

drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +0 -0
@@ -1268,7 +1268,8 @@ static int gmc_v7_0_process_interrupt(struct

amdgpu_device *adev,

               return 0;

       amdgpu_vm_update_fault_cache(adev, entry->pasid,
-                                  ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status, AMDGPU_GFXHUB(0));

+                                  ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status, +                                  AMDGPU_GFXHUB(0), 0);

       if (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_FIRST) gmc_v7_0_set_fault_enable_default(adev, false);

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c

index 86488c052f82..6855caeb7f74 100644

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0 -0
@@ -1437,7 +1437,8 @@ static int gmc_v8_0_process_interrupt(struct

amdgpu_device *adev,

               return 0;

       amdgpu_vm_update_fault_cache(adev, entry->pasid,
-                                  ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status, AMDGPU_GFXHUB(0));

+                                  ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status, +                                  AMDGPU_GFXHUB(0), 0);

       if (amdgpu_vm_fault_stop == AMDGPU_VM_FAULT_STOP_FIRST) gmc_v8_0_set_fault_enable_default(adev, false); @@ -1448,7 +1449,7 @@ static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev,

               dev_err(adev->dev, "GPU fault detected: %d 0x%08x\n", entry->src_id, entry->src_data[0]);

-             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid); +             task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0); if (task_info) {
                       dev_err(adev->dev, " for process %s pid %d thread %s pid %d\n", task_info->process_name, task_info->tgid,

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c

index b73136d390cc..e183e08b2c02 100644

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
@@ -556,10 +556,12 @@ static int gmc_v9_0_process_interrupt(struct

amdgpu_device *adev,

       unsigned int vmhub;
       u64 addr;
       uint32_t cam_index = 0;
-     int ret, xcc_id = 0;
-     uint32_t node_id;
+     int ret;
+     uint32_t node_id, xcc_id, xcp_id;

       node_id = entry->node_id;
+     xcc_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, node_id); +     xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;

       addr = (u64)entry->src_data[0] << 12;
       addr |= ((u64)entry->src_data[1] & 0xf) << 44; @@ -572,12 +574,6 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,

               vmhub = AMDGPU_MMHUB1(0);
       } else {
               hub_name = "gfxhub0";
-             if (adev->gfx.funcs->ih_node_to_logical_xcc) {
-                     xcc_id = adev->gfx.funcs->ih_node_to_logical_xcc(adev, -                             node_id);
-                     if (xcc_id < 0)
-                             xcc_id = 0;
-             }
               vmhub = xcc_id;
       }
       hub = &adev->vmhub[vmhub];
@@ -631,7 +627,7 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,

               retry_fault ? "retry" : "no-retry", entry->src_id, entry->ring_id, entry->vmid, entry->pasid);

-     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid); +     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, xcp_id);

       if (task_info) {
               dev_err(adev->dev,
                       " for process %s pid %d thread %s pid %d)\n", @@ -675,7 +671,7 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,

       if (!amdgpu_sriov_vf(adev)) WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

-     amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status, vmhub);

+     amdgpu_vm_update_fault_cache(adev, entry->pasid, addr, status, vmhub, xcp_id);

       dev_err(adev->dev, "VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c

index 23ef4eb36b40..1ac4224bbe5b 100644

drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +0 -0
@@ -2182,7 +2182,7 @@ static int sdma_v4_0_print_iv_entry(struct

amdgpu_device *adev,

                          instance, addr, entry->src_id, entry->ring_id, entry->vmid, entry->pasid);

-     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid); +     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0); if (task_info) {
               dev_dbg_ratelimited(adev->dev,
                                   " for process %s pid %d thread %s pid %d\n",

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

index 57f16c09abfc..c8b5c0302ca7 100644

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -0
@@ -1683,6 +1683,8 @@ static int sdma_v4_4_2_print_iv_entry(struct

amdgpu_device *adev,

       int instance;
       struct amdgpu_task_info *task_info;
       u64 addr;
+     uint32_t xcc_id = amdgpu_amdkfd_node_id_to_xcc_id(adev, entry- node_id);
+     uint32_t xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;

       instance = sdma_v4_4_2_irq_id_to_seq(adev, entry->client_id); if (instance < 0 || instance >= adev->sdma.num_instances) { @@ -1698,7 +1700,7 @@ static int sdma_v4_4_2_print_iv_entry(struct amdgpu_device *adev,

                           instance, addr, entry->src_id, entry->ring_id, entry->vmid, entry->pasid);

-     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid); +     task_info = amdgpu_vm_get_task_info_pasid(adev, entry->pasid, xcp_id);

       if (task_info) {
               dev_dbg_ratelimited(adev->dev, " for process %s pid %d thread %s pid %d\n",

                                   task_info->process_name, task_info->tgid,

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_events.c

index ea3792249209..c098fbaf0e1c 100644

drivers/gpu/drm/amd/amdkfd/kfd_events.c +0 -0
@@ -1262,8 +1262,9 @@ void kfd_signal_reset_event(struct kfd_node

*dev)

               if (dev->dqm->detect_hang_count) {
                       struct amdgpu_task_info *ti;
+                     uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;

-                     ti = amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid); +                     ti = amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid, xcp_id);

                       if (ti) {
                               dev_err(dev->adev->dev,
                                       "Queues reset on process %s tid %d thread %s pid %d\n",

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c

index 8e0d0356e810..d7cbf9525698 100644

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c +0 -0
@@ -377,12 +377,8 @@ static void event_interrupt_wq_v10(struct

kfd_node *dev,

               struct kfd_hsa_memory_exception_data exception_data;

               /* gfxhub */
-             if (!vmid_type && dev->adev->gfx.funcs->ih_node_to_logical_xcc) { -                     hub_inst = dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev- adev,
-                             node_id);
-                     if (hub_inst < 0)
-                             hub_inst = 0;
-             }
+             if (!vmid_type)
+                     hub_inst = amdgpu_amdkfd_node_id_to_xcc_id(dev->adev, node_id);

               /* mmhub */
               if (vmid_type && client_id == SOC15_IH_CLIENTID_VMC)

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c

index a9c3580be8c9..4708b8c811a5 100644

drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c +0 -0
@@ -437,12 +437,8 @@ static void event_interrupt_wq_v9(struct

kfd_node *dev,

               struct kfd_hsa_memory_exception_data exception_data;

               /* gfxhub */
-             if (!vmid_type && dev->adev->gfx.funcs->ih_node_to_logical_xcc) { -                     hub_inst = dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev- adev,
-                             node_id);
-                     if (hub_inst < 0)
-                             hub_inst = 0;
-             }
+             if (!vmid_type)
+                     hub_inst = amdgpu_amdkfd_node_id_to_xcc_id(dev->adev, node_id);

               /* mmhub */
               if (vmid_type && client_id == SOC15_IH_CLIENTID_VMC)

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c

index ea6a8e43bd5b..b5f2f5b1069c 100644

drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +0 -0
@@ -251,8 +251,9 @@ void

kfd_smi_event_update_thermal_throttling(struct kfd_node *dev,

   void kfd_smi_event_update_vmfault(struct kfd_node *dev, uint16_t pasid) {
       struct amdgpu_task_info *task_info;
+     uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;

-     task_info = amdgpu_vm_get_task_info_pasid(dev->adev, pasid);
+     task_info = amdgpu_vm_get_task_info_pasid(dev->adev, pasid, xcp_id); if (task_info) {
               /* Report VM faults from user applications, not retry from kernel */ if (task_info->pid)

maintainer
#9 lore raw

Am 11.09.24 um 15:40 schrieb Philip Yang:

Quoted 13 lines · Christian König
Quoted 8 lines

Yeah, I completely agree with Xiaogang.

The PASID is an identifier of an address space. And the idea of the KFD was that we can just use the same address space and with it the page tables for multiple execution devices, e.g. CPUs, GPUs etc...

That idea turned out to be a bad one because it clashes with some use cases (e.g. native context virtualization). The better approach is to see the CPU and GPU processes as separate things which just share the same underlying data.

Opening the KFD node multiple times currently results in the same KFD process being used. We should probably consider changing that.

It is one KFD process binding to one app process, with count to support multiple open/close of for the same process.

Yeah and to repeat myself: That seems to be a bad idea.

Quoted 2 lines

The IOMMU most likely uses Linux process pid, not from kfd process->pasid. The KFD process->pasid is passed to F/W to map queues, flush TLB.

Actually no, the IOMMU uses driver assigned PASIDs.

Quoted 2 lines

The reason to replace vm->pasid with KFD process->pasid is to find vm from fault pasid, then for compute vm, find the kfd process from pasid.

Why aren't we doing it the other way around? In other words start using the VM assigned PASID?

IIRC that the KFD overwrites the PASID inside the VM was only done for the ATC/IOMMU handling, which is now completely gone.

Regards,
Christian.

Quoted 1,157 lines

I can see a bug in amdgpu_vm_handle_fault, only for compute vm, to force update PTE no-retry-fault to the incorrect VM for multiple partitions. This patch will fix this bug but we can have a simple fix.

Regards,

Philip

Quoted 1,151 lines

Regards,
Christian.

Am 11.09.24 um 01:59 schrieb Chen, Xiaogang:

Quoted 1,145 lines

You want have 1:1 mapping between vm and pasid so can query vm from pasid.  I think there is a basic existing issue that we cannot have vm and pasid 1:1 correspondence.

PASIDs are global address space identifiers that can be shared between the GPU, an IOMMU and the driver. One app should have one pasid that iommu uses to decide which page table to use when device access system resource. But one app can open render/kfd node multiple times even for one gpu. That said one app could have multiple GPU vms .

I think we did not have this issue because app usually open a rent node or kfd node only once. With one adev has multiple partitions there are multiple vms on one adev, so have this issue.  But the root cause is not from multiple partitions and solution is not to introduce multiple pasids. I think we should have one pasid for one app and use different way to get vm from pasid.

Regards

Xiaogang

Quoted 1,131 lines · Jonathan

[Public]

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

[Public]

KMS open still set per pasid-vm bindings per adev (socket) so I don’t see how the per-partition overwrite PASID issue is primarily a KFD concern.

Are you saying the KFD process devices holds a shadow copy of the correct VM during page restore during fault?

Doesn’t it acquire the wrong VM object on process init in the first place?

Even if it were the case the KFD had a separate VM reference, the underlying IRQ fault handling is still broken.

We probably don’t want to bandage over something to fix one symptom.

Jon

*From:*Yang, Philip <[email protected]>
*Sent:* Tuesday, September 10, 2024 11:24 AM
*To:* Koenig, Christian <[email protected]>; Kim, Jonathan <[email protected]>; [email protected] *Cc:* Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]> *Subject:* Re: [PATCH] drm/amdkfd: fix vm-pasid lookup for multiple partitions

On 2024-09-09 14:46, Christian König wrote:

Am 09.09.24 um 18:02 schrieb Kim, Jonathan:

[Public]

-----Original Message-----
From: Christian König <[email protected]> <mailto:[email protected]>
Sent: Thursday, September 5, 2024 10:24 AM
To: Kim, Jonathan <[email protected]> <mailto:[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]> <mailto:[email protected]>; Deucher, Alexander <[email protected]> <mailto:[email protected]>; Joshi, Mukul <[email protected]> <mailto:[email protected]>
Subject: Re: [PATCH] drm/amdkfd: fix vm-pasid lookup for multiple partitions

Caution: This message originated from an External Source. Use proper caution
when opening attachments, clicking links, or responding.

Am 19.08.24 um 19:59 schrieb Jonathan Kim:

Currently multiple partitions will incorrectly overwrite the VM lookup
table since the table is indexed by PASID and multiple partitions can
register different VM objects on the same PASID.

That's a rather bad idea. Why do we have the same PASID for different VM
objects in the first place?

Alex can probably elaborate on the KGD side, but from what I can see, the KMS driver open call has always assigned a new VM object per PASID on an open call.
The KFD acquires and replaces the KGD PASID-VMID registration on its own compute process open/creation call. If this is the bad_idea you're referring to, then someone else will have to chime in.  I don't have much history on this unfortunately.

Yeah, Felix and I designed that.

app opens drm node to create vm for each partition, with different vm->pasid for each vm, issue is from kfd_ioctl_acquire_vm -> kfd_process_device_init_vm -> amdgpu_amdkfd_gpuvm_set_vm_pasid, to replace all vm->pasid with kfd process->pasid, which is from open kfd node. This ends up to store only one vm to adev->vm_manager.pasids with KFD process pasid, so we cannot retrieve correct vm from adev->vm_manager.pasids on mGPUs or multiple partitions.

That aside, the current problem is, is that all KFD device structures are logical partitions and register their PASID-VM binding using this concept of a device.

As far as I can see that is the fundamental problem. This needs to be fixed instead.

On the KGD side however, the registration table is maintained in the adev struct, which is a physical socket. So there's a mismatch in understanding of what a device is between the KFD & KGD with regard to the look up table that results in bad bindings.

Adding a per-partition dimension to the existing lookup table resolves issues where seeing, for example, with memory violation interception and XNACK i.e bad bindings result in wrong vm object found to set no-retry flags on memory violations.

svm_range_restore_pages retry fault recover uses fault pasid to get kfd process, and use the fault node_id to get pdd->vm, maybe you can use this way to fix the debugger issue.

Regards,

Philip

    Yeah that is pretty much a no-go.

    The PASID and how it is used is defined by the PCIe
    specifications. If we now start to assign multiple VMs to the
    same PASID then we are violating the PCIe specification.

    The problems you see are most likely just the tip of the
    iceberg here.

    Regards,
    Christian.



        Jon


            Regards,
            Christian.


                This results in loading the wrong VM object on
                PASID query.

                To correct this, setup the lookup table to be
                per-partition-per-PASID
                instead.

                Signed-off-by: Jonathan Kim <[email protected]>
                <mailto:[email protected]>
                ---
                drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 12 ++++
                drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  1 +
                drivers/gpu/drm/amd/amdgpu/amdgpu_job.c |  4 +-
                drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  7 ++-
                drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 55
                +++++++++++------

            -- 

                drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 11 +++-
                drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c |  5 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c |  5 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c |  5 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c |  3 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c |  5 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 16 ++----
                drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c |  2 +-
                drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c |  4 +-
                drivers/gpu/drm/amd/amdkfd/kfd_events.c |  3 +-
                .../gpu/drm/amd/amdkfd/kfd_int_process_v10.c |  8 +--
                .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c |  8 +--
                drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c |  3 +-
                   18 files changed, 92 insertions(+), 65 deletions(-)

                diff --git
                a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c

                index c272461d70a9..28db789610e1 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
                @@ -887,3 +887,15 @@ int
                amdgpu_amdkfd_unmap_hiq(struct

            amdgpu_device *adev, u32 doorbell_off,

                       return r;
                   }
                +
                +int amdgpu_amdkfd_node_id_to_xcc_id(struct
                amdgpu_device *adev,

            uint32_t node_id)

                +{
                +     if (adev->gfx.funcs->ih_node_to_logical_xcc) {
                +             int xcc_id =
                adev->gfx.funcs->ih_node_to_logical_xcc(adev,
                node_id);
                +
                +             if (xcc_id >= 0)
                +                     return xcc_id;
                +     }
                +
                +     return 0;
                +}
                diff --git
                a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h

                index 4ed49265c764..bf8bb45d8ab6 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
                @@ -356,6 +356,7 @@ void
                amdgpu_amdkfd_unreserve_mem_limit(struct

            amdgpu_device *adev,

                uint64_t size, u32 alloc_flag, int8_t xcp_id);

                   u64 amdgpu_amdkfd_xcp_memory_size(struct
                amdgpu_device *adev, int

            xcp_id);

                +int amdgpu_amdkfd_node_id_to_xcc_id(struct
                amdgpu_device *adev,

            uint32_t node_id);

                   #define KFD_XCP_MEM_ID(adev, xcp_id) \
                               ((adev)->xcp_mgr && (xcp_id) >= 0 ?\
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c

                index c6a1783fc9ef..bf9f8802e18d 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
                @@ -37,7 +37,7 @@ static enum drm_gpu_sched_stat

            amdgpu_job_timedout(struct drm_sched_job *s_job)

                       struct amdgpu_job *job = to_amdgpu_job(s_job);
                       struct amdgpu_task_info *ti;
                       struct amdgpu_device *adev = ring->adev;
                -     int idx;
                +     int idx, xcp_id = !job->vm ? 0 :
                job->vm->xcp_id;
                       int r;

                       if (!drm_dev_enter(adev_to_drm(adev), &idx)) {
                @@ -62,7 +62,7 @@ static enum drm_gpu_sched_stat

            amdgpu_job_timedout(struct drm_sched_job *s_job)

                job->base.sched->name,
                atomic_read(&ring->fence_drv.last_seq),
                ring->fence_drv.sync_seq);

                -     ti =
                amdgpu_vm_get_task_info_pasid(ring->adev, job->pasid);
                +     ti =
                amdgpu_vm_get_task_info_pasid(ring->adev,
                job->pasid, xcp_id);
                       if (ti) {
                               dev_err(adev->dev,
                                       "Process information:
                process %s pid %d thread %s pid %d\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

                index d9fde38f6ee2..e413bf4a3e84 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
                @@ -1275,17 +1275,20 @@ int
                amdgpu_info_ioctl(struct drm_device *dev,

            void *data, struct drm_file *filp)

                               struct amdgpu_vm *vm = &fpriv->vm;
                               struct drm_amdgpu_info_gpuvm_fault
                gpuvm_fault;
                               unsigned long flags;
                +             int i;

                               if (!vm)
                                       return -EINVAL;

                               memset(&gpuvm_fault, 0,
                sizeof(gpuvm_fault));

                - xa_lock_irqsave(&adev->vm_manager.pasids, flags);
                +             for (i = 0; i <
                adev->xcp_mgr->num_xcps; i++)
                + xa_lock_irqsave(&adev->vm_manager.pasids[i], flags);
                               gpuvm_fault.addr = vm->fault_info.addr;
                               gpuvm_fault.status =
                vm->fault_info.status;
                               gpuvm_fault.vmhub =
                vm->fault_info.vmhub;
                - xa_unlock_irqrestore(&adev->vm_manager.pasids,
                flags);
                +             for (i = 0; i <
                adev->xcp_mgr->num_xcps; i++)
                + xa_unlock_irqrestore(&adev->vm_manager.pasids[i],
                flags);

                               return copy_to_user(out, &gpuvm_fault,
                min((size_t)size, sizeof(gpuvm_fault))) ? -EFAULT : 0;
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

                index bcb729094521..f43e1c15f423 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
                @@ -146,7 +146,7 @@ int amdgpu_vm_set_pasid(struct
                amdgpu_device

            *adev, struct amdgpu_vm *vm,

                               return 0;

                       if (vm->pasid) {
                -             r =
                xa_err(xa_erase_irq(&adev->vm_manager.pasids,
                vm->pasid));
                +             r =
                xa_err(xa_erase_irq(&adev->vm_manager.pasids[vm->xcp_id],


            vm->pasid));

                               if (r < 0)
                                       return r;

                @@ -154,7 +154,7 @@ int amdgpu_vm_set_pasid(struct
                amdgpu_device

            *adev, struct amdgpu_vm *vm,

                       }

                       if (pasid) {
                -             r =
                xa_err(xa_store_irq(&adev->vm_manager.pasids,
                pasid, vm,
                +             r =
                xa_err(xa_store_irq(&adev->vm_manager.pasids[vm->xcp_id],


            pasid, vm,

                GFP_KERNEL));
                               if (r < 0)
                                       return r;
                @@ -2288,14 +2288,14 @@ static void

            amdgpu_vm_destroy_task_info(struct kref *kref)

                   }

                   static inline struct amdgpu_vm *
                -amdgpu_vm_get_vm_from_pasid(struct amdgpu_device
                *adev, u32 pasid)
                +amdgpu_vm_get_vm_from_pasid(struct amdgpu_device
                *adev, u32 pasid,

            u32 xcp_id)

                   {
                       struct amdgpu_vm *vm;
                       unsigned long flags;

                - xa_lock_irqsave(&adev->vm_manager.pasids, flags);
                -     vm = xa_load(&adev->vm_manager.pasids, pasid);
                - xa_unlock_irqrestore(&adev->vm_manager.pasids,
                flags);
                + xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id],
                flags);
                +     vm =
                xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
                +
                xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id],
                flags);

                       return vm;
                   }
                @@ -2343,10 +2343,10 @@
                amdgpu_vm_get_task_info_vm(struct

            amdgpu_vm *vm)

                    * referenced down with amdgpu_vm_put_task_info.
                    */
                   struct amdgpu_task_info *
                -amdgpu_vm_get_task_info_pasid(struct amdgpu_device
                *adev, u32 pasid)
                +amdgpu_vm_get_task_info_pasid(struct amdgpu_device
                *adev, u32 pasid,

            u32 xcp_id)

                   {
                       return amdgpu_vm_get_task_info_vm(
                - amdgpu_vm_get_vm_from_pasid(adev, pasid));
                + amdgpu_vm_get_vm_from_pasid(adev, pasid, xcp_id));
                   }

                   static int amdgpu_vm_create_task_info(struct
                amdgpu_vm *vm)
                @@ -2481,6 +2481,8 @@ int amdgpu_vm_init(struct
                amdgpu_device

            *adev, struct amdgpu_vm *vm,

                amdgpu_bo_unreserve(vm->root.bo);
                       amdgpu_bo_unref(&root_bo);

                +     vm->xcp_id = xcp_id < 0 ? 0 : xcp_id;
                +
                       return 0;

                   error_free_root:
                @@ -2695,8 +2697,8 @@ void
                amdgpu_vm_manager_init(struct

            amdgpu_device *adev)

                   #else
                adev->vm_manager.vm_update_mode = 0;
                   #endif
                -
                - xa_init_flags(&adev->vm_manager.pasids,
                XA_FLAGS_LOCK_IRQ);
                +     for (i = 0; i < MAX_XCP; i++)
                + xa_init_flags(&(adev->vm_manager.pasids[i]),

            XA_FLAGS_LOCK_IRQ);

                   }

                   /**
                @@ -2708,10 +2710,15 @@ void
                amdgpu_vm_manager_init(struct

            amdgpu_device *adev)

                    */
                   void amdgpu_vm_manager_fini(struct amdgpu_device
                *adev)
                   {
                - WARN_ON(!xa_empty(&adev->vm_manager.pasids));
                - xa_destroy(&adev->vm_manager.pasids);
                +     int i;
                +
                +     for (i = 0; i < MAX_XCP; i++) {
                + WARN_ON(!xa_empty(&adev->vm_manager.pasids[i]));
                + xa_destroy(&adev->vm_manager.pasids[i]);
                +     }

                       amdgpu_vmid_mgr_fini(adev);
                +
                   }

                   /**
                @@ -2778,17 +2785,18 @@ bool
                amdgpu_vm_handle_fault(struct

            amdgpu_device *adev, u32 pasid,

                       unsigned long irqflags;
                       uint64_t value, flags;
                       struct amdgpu_vm *vm;
                -     int r;
                +     int r, xcp_id;

                - xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
                -     vm = xa_load(&adev->vm_manager.pasids, pasid);
                +     xcp_id =
                amdgpu_amdkfd_node_id_to_xcc_id(adev, node_id)/adev-
                gfx.num_xcc_per_xcp;
                + xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id],
                irqflags);
                +     vm =
                xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
                       if (vm) {
                               root = amdgpu_bo_ref(vm->root.bo);
                               is_compute_context =
                vm->is_compute_context;
                       } else {
                               root = NULL;
                       }
                - xa_unlock_irqrestore(&adev->vm_manager.pasids,
                irqflags);
                +
                xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id],
                irqflags);

                       if (!root)
                               return false;
                @@ -2806,11 +2814,11 @@ bool
                amdgpu_vm_handle_fault(struct

            amdgpu_device *adev, u32 pasid,

                               goto error_unref;

                       /* Double check that the VM still exists */
                - xa_lock_irqsave(&adev->vm_manager.pasids, irqflags);
                -     vm = xa_load(&adev->vm_manager.pasids, pasid);
                + xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id],
                irqflags);
                +     vm =
                xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
                       if (vm && vm->root.bo != root)
                               vm = NULL;
                - xa_unlock_irqrestore(&adev->vm_manager.pasids,
                irqflags);
                +
                xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id],
                irqflags);
                       if (!vm)
                               goto error_unlock;

                @@ -2968,14 +2976,15 @@ void
                amdgpu_vm_update_fault_cache(struct

            amdgpu_device *adev,

                unsigned int pasid,
                uint64_t addr,
                uint32_t status,
                -                               unsigned int vmhub)
                +                               unsigned int vmhub,
                +                               uint32_t xcp_id)
                   {
                       struct amdgpu_vm *vm;
                       unsigned long flags;

                - xa_lock_irqsave(&adev->vm_manager.pasids, flags);
                + xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id],
                flags);

                -     vm = xa_load(&adev->vm_manager.pasids, pasid);
                +     vm =
                xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
                       /* Don't update the fault cache if status is
                0.  In the multiple
                        * fault case, subsequent faults will return
                a 0 status which is
                        * useless for userspace and replaces the
                useful fault status, so
                @@ -3008,7 +3017,7 @@ void
                amdgpu_vm_update_fault_cache(struct

            amdgpu_device *adev,

                WARN_ONCE(1, "Invalid vmhub %u\n", vmhub);
                               }
                       }
                - xa_unlock_irqrestore(&adev->vm_manager.pasids,
                flags);
                +
                xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id],
                flags);
                   }

                   /**
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h

                index 046949c4b695..1499f5f731e9 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
                @@ -35,6 +35,7 @@
                   #include "amdgpu_sync.h"
                   #include "amdgpu_ring.h"
                   #include "amdgpu_ids.h"
                +#include "amdgpu_xcp.h"

                   struct drm_exec;

                @@ -418,6 +419,9 @@ struct amdgpu_vm {

                       /* cached fault info */
                       struct amdgpu_vm_fault_info fault_info;
                +
                +     /* XCP ID */
                +     int xcp_id;
                   };

                   struct amdgpu_vm_manager {
                @@ -456,7 +460,7 @@ struct amdgpu_vm_manager {
                       /* PASID to VM mapping, will be used in
                interrupt context to
                        * look up VM of a page fault
                        */
                -     struct xarray                           pasids;
                +     struct xarray pasids[MAX_XCP];
                       /* Global registration of recent page fault
                information */
                       struct amdgpu_vm_fault_info fault_info;
                   };
                @@ -550,7 +554,7 @@ bool
                amdgpu_vm_need_pipeline_sync(struct

            amdgpu_ring *ring,

                   void amdgpu_vm_check_compute_bug(struct
                amdgpu_device *adev);

                   struct amdgpu_task_info *
                -amdgpu_vm_get_task_info_pasid(struct amdgpu_device
                *adev, u32 pasid);
                +amdgpu_vm_get_task_info_pasid(struct amdgpu_device
                *adev, u32 pasid,

            u32 xcp_id);

                   struct amdgpu_task_info *
                   amdgpu_vm_get_task_info_vm(struct amdgpu_vm *vm);
                @@ -649,7 +653,8 @@ void
                amdgpu_vm_update_fault_cache(struct

            amdgpu_device *adev,

                unsigned int pasid,
                uint64_t addr,
                uint32_t status,
                -                               unsigned int vmhub);
                +                               unsigned int vmhub,
                +                               uint32_t xcp_id);
                   void amdgpu_vm_tlb_fence_create(struct
                amdgpu_device *adev,
                                                struct amdgpu_vm *vm,
                                                struct dma_fence
                **fence);
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c

                index f0ceab3ce5bf..24b042febf5c 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
                @@ -151,7 +151,8 @@ static int
                gmc_v10_0_process_interrupt(struct

            amdgpu_device *adev,

                WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

                amdgpu_vm_update_fault_cache(adev, entry->pasid,
                addr, status,
                -                                         
                entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0));

                + entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0),

                + 0);
                       }

                       if (!printk_ratelimit())
                @@ -161,7 +162,7 @@ static int
                gmc_v10_0_process_interrupt(struct

            amdgpu_device *adev,

                               "[%s] page fault (src_id:%u ring:%u
                vmid:%u pasid:%u)\n",
                               entry->vmid_src ? "mmhub" : "gfxhub",
                               entry->src_id, entry->ring_id,
                entry->vmid, entry->pasid);
                -     task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +     task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
                       if (task_info) {
                               dev_err(adev->dev,
                                       " in process %s pid %d
                thread %s pid %d\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c

                index 2797fd84432b..3507046d33e6 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c
                @@ -122,7 +122,8 @@ static int
                gmc_v11_0_process_interrupt(struct

            amdgpu_device *adev,

                WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

                amdgpu_vm_update_fault_cache(adev, entry->pasid,
                addr, status,
                -                                         
                entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0));

                + entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0),

                + 0);
                       }

                       if (printk_ratelimit()) {
                @@ -132,7 +133,7 @@ static int
                gmc_v11_0_process_interrupt(struct

            amdgpu_device *adev,

                "[%s] page fault (src_id:%u ring:%u vmid:%u
                pasid:%u)\n",
                entry->vmid_src ? "mmhub" : "gfxhub",
                                       entry->src_id,
                entry->ring_id, entry->vmid, entry->pasid);
                -             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
                               if (task_info) {
                dev_err(adev->dev,
                                               " in process %s pid
                %d thread %s pid %d)\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c

                index 60acf676000b..9844564c6c74 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c
                @@ -115,7 +115,8 @@ static int
                gmc_v12_0_process_interrupt(struct

            amdgpu_device *adev,

                WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

                amdgpu_vm_update_fault_cache(adev, entry->pasid,
                addr, status,
                -                                         
                entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0));

                + entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0),

                + 0);
                       }

                       if (printk_ratelimit()) {
                @@ -125,7 +126,7 @@ static int
                gmc_v12_0_process_interrupt(struct

            amdgpu_device *adev,

                "[%s] page fault (src_id:%u ring:%u vmid:%u
                pasid:%u)\n",
                entry->vmid_src ? "mmhub" : "gfxhub",
                                       entry->src_id,
                entry->ring_id, entry->vmid, entry->pasid);
                -             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
                               if (task_info) {
                dev_err(adev->dev,
                                               " in process %s pid
                %d thread %s pid %d)\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c

                index 994432fb57ea..2cdb0cbb7c4d 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
                @@ -1268,7 +1268,8 @@ static int
                gmc_v7_0_process_interrupt(struct

            amdgpu_device *adev,

                               return 0;

                amdgpu_vm_update_fault_cache(adev, entry->pasid,
                - ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,

            AMDGPU_GFXHUB(0));

                + ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
                + AMDGPU_GFXHUB(0), 0);

                       if (amdgpu_vm_fault_stop ==
                AMDGPU_VM_FAULT_STOP_FIRST)
                gmc_v7_0_set_fault_enable_default(adev, false);
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c

                index 86488c052f82..6855caeb7f74 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
                @@ -1437,7 +1437,8 @@ static int
                gmc_v8_0_process_interrupt(struct

            amdgpu_device *adev,

                               return 0;

                amdgpu_vm_update_fault_cache(adev, entry->pasid,
                - ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,

            AMDGPU_GFXHUB(0));

                + ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
                + AMDGPU_GFXHUB(0), 0);

                       if (amdgpu_vm_fault_stop ==
                AMDGPU_VM_FAULT_STOP_FIRST)
                gmc_v8_0_set_fault_enable_default(adev, false);
                @@ -1448,7 +1449,7 @@ static int
                gmc_v8_0_process_interrupt(struct

            amdgpu_device *adev,

                dev_err(adev->dev, "GPU fault detected: %d 0x%08x\n",
                                       entry->src_id,
                entry->src_data[0]);

                -             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
                               if (task_info) {
                dev_err(adev->dev, " for process %s pid %d thread
                %s pid %d\n",
                task_info->process_name, task_info->tgid,
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c

                index b73136d390cc..e183e08b2c02 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
                @@ -556,10 +556,12 @@ static int
                gmc_v9_0_process_interrupt(struct

            amdgpu_device *adev,

                       unsigned int vmhub;
                       u64 addr;
                       uint32_t cam_index = 0;
                -     int ret, xcc_id = 0;
                -     uint32_t node_id;
                +     int ret;
                +     uint32_t node_id, xcc_id, xcp_id;

                       node_id = entry->node_id;
                +     xcc_id =
                amdgpu_amdkfd_node_id_to_xcc_id(adev, node_id);
                +     xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;

                       addr = (u64)entry->src_data[0] << 12;
                       addr |= ((u64)entry->src_data[1] & 0xf) << 44;
                @@ -572,12 +574,6 @@ static int
                gmc_v9_0_process_interrupt(struct

            amdgpu_device *adev,

                               vmhub = AMDGPU_MMHUB1(0);
                       } else {
                               hub_name = "gfxhub0";
                -             if
                (adev->gfx.funcs->ih_node_to_logical_xcc) {
                -                     xcc_id =
                adev->gfx.funcs->ih_node_to_logical_xcc(adev,
                -                             node_id);
                -                     if (xcc_id < 0)
                -                             xcc_id = 0;
                -             }
                               vmhub = xcc_id;
                       }
                       hub = &adev->vmhub[vmhub];
                @@ -631,7 +627,7 @@ static int
                gmc_v9_0_process_interrupt(struct

            amdgpu_device *adev,

                retry_fault ? "retry" : "no-retry",
                               entry->src_id, entry->ring_id,
                entry->vmid, entry->pasid);

                -     task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +     task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid,

            xcp_id);

                       if (task_info) {
                               dev_err(adev->dev,
                                       " for process %s pid %d
                thread %s pid %d)\n",
                @@ -675,7 +671,7 @@ static int
                gmc_v9_0_process_interrupt(struct

            amdgpu_device *adev,

                       if (!amdgpu_sriov_vf(adev))
                WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

                -     amdgpu_vm_update_fault_cache(adev,
                entry->pasid, addr, status,

            vmhub);

                + amdgpu_vm_update_fault_cache(adev, entry->pasid,
                addr, status,

            vmhub, xcp_id);

                dev_err(adev->dev,
                "VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c

            b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c

                index 23ef4eb36b40..1ac4224bbe5b 100644
                --- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
                @@ -2182,7 +2182,7 @@ static int
                sdma_v4_0_print_iv_entry(struct

            amdgpu_device *adev,

                instance, addr, entry->src_id, entry->ring_id,
                entry->vmid,
                entry->pasid);

                -     task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +     task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
                       if (task_info) {
                dev_dbg_ratelimited(adev->dev,
                                                   " for process %s
                pid %d thread %s pid %d\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

            b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

                index 57f16c09abfc..c8b5c0302ca7 100644
                --- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
                +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
                @@ -1683,6 +1683,8 @@ static int
                sdma_v4_4_2_print_iv_entry(struct

            amdgpu_device *adev,

                       int instance;
                       struct amdgpu_task_info *task_info;
                       u64 addr;
                +     uint32_t xcc_id =
                amdgpu_amdkfd_node_id_to_xcc_id(adev, entry-
                node_id);
                +     uint32_t xcp_id =
                xcc_id/adev->gfx.num_xcc_per_xcp;

                       instance = sdma_v4_4_2_irq_id_to_seq(adev,
                entry->client_id);
                       if (instance < 0 || instance >=
                adev->sdma.num_instances) {
                @@ -1698,7 +1700,7 @@ static int
                sdma_v4_4_2_print_iv_entry(struct

            amdgpu_device *adev,

                instance, addr, entry->src_id, entry->ring_id,
                entry->vmid,
                entry->pasid);

                -     task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +     task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid,

            xcp_id);

                       if (task_info) {
                dev_dbg_ratelimited(adev->dev, " for process %s pid
                %d thread %s

            pid %d\n",

                task_info->process_name, task_info->tgid,
                diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_events.c

            b/drivers/gpu/drm/amd/amdkfd/kfd_events.c

                index ea3792249209..c098fbaf0e1c 100644
                --- a/drivers/gpu/drm/amd/amdkfd/kfd_events.c
                +++ b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
                @@ -1262,8 +1262,9 @@ void
                kfd_signal_reset_event(struct kfd_node

            *dev)

                               if (dev->dqm->detect_hang_count) {
                                       struct amdgpu_task_info *ti;
                +                     uint32_t xcp_id = dev->xcp ?
                dev->xcp->id : 0;

                -                     ti =
                amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid);
                +                     ti =
                amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid,

            xcp_id);

                if (ti) {
                dev_err(dev->adev->dev,
                "Queues reset on process %s tid %d thread %s pid
                %d\n",
                diff --git
                a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c

            b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c

                index 8e0d0356e810..d7cbf9525698 100644
                --- a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c
                +++ b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c
                @@ -377,12 +377,8 @@ static void
                event_interrupt_wq_v10(struct

            kfd_node *dev,

                               struct kfd_hsa_memory_exception_data
                exception_data;

                               /* gfxhub */
                -             if (!vmid_type &&
                dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
                -                     hub_inst =
                dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev-
                adev,
                -                             node_id);
                -                     if (hub_inst < 0)
                -                             hub_inst = 0;
                -             }
                +             if (!vmid_type)
                +                     hub_inst =
                amdgpu_amdkfd_node_id_to_xcc_id(dev->adev,

            node_id);

                               /* mmhub */
                               if (vmid_type && client_id ==
                SOC15_IH_CLIENTID_VMC)
                diff --git
                a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c

            b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c

                index a9c3580be8c9..4708b8c811a5 100644
                --- a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c
                +++ b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c
                @@ -437,12 +437,8 @@ static void
                event_interrupt_wq_v9(struct

            kfd_node *dev,

                               struct kfd_hsa_memory_exception_data
                exception_data;

                               /* gfxhub */
                -             if (!vmid_type &&
                dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
                -                     hub_inst =
                dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev-
                adev,
                -                             node_id);
                -                     if (hub_inst < 0)
                -                             hub_inst = 0;
                -             }
                +             if (!vmid_type)
                +                     hub_inst =
                amdgpu_amdkfd_node_id_to_xcc_id(dev->adev,

            node_id);

                               /* mmhub */
                               if (vmid_type && client_id ==
                SOC15_IH_CLIENTID_VMC)
                diff --git
                a/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c

            b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c

                index ea6a8e43bd5b..b5f2f5b1069c 100644
                --- a/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
                +++ b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
                @@ -251,8 +251,9 @@ void

            kfd_smi_event_update_thermal_throttling(struct kfd_node
            *dev,

                   void kfd_smi_event_update_vmfault(struct
                kfd_node *dev, uint16_t pasid)
                   {
                       struct amdgpu_task_info *task_info;
                +     uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;

                -     task_info =
                amdgpu_vm_get_task_info_pasid(dev->adev, pasid);
                +     task_info =
                amdgpu_vm_get_task_info_pasid(dev->adev, pasid,
                xcp_id);
                       if (task_info) {
                               /* Report VM faults from user
                applications, not retry from kernel */
                               if (task_info->pid)
maintainer
#10 lore raw

I sort of agree that KFD allocated one PASID per process for historical reasons. KFD used one address space per process that was shared by all GPUs and the CPU, so it seemed wasteful to allocate multiple PASIDs for the same process.

On the other hand, I also don't see why you can't use the same PASID on multiple devices, even if they do refer to different address spaces. If the PASID is a per-device address space ID, that should be perfectly fine. It doesn't need to be globally unique. If it was globally unique, the adev->vm_manager.pasids table should actually be global, not in the adev.

That said, it should be doable to change KFD to use per-VM PASIDs. PASIDs are not exposed in user mode, so user mode APIs wouldn't be affected. Some debugfs stuff and dmesg logs would change. And we'd need to move kfd_process->pasid to pdd->pasids. This is probably a bigger change than what Jon proposed in his patch, though.

Regards,
  Felix

Quoted 1,200 lines · Christian König

Am 11.09.24 um 15:40 schrieb Philip Yang:

Quoted 13 lines · Christian König
Quoted 8 lines

Yeah, I completely agree with Xiaogang.

The PASID is an identifier of an address space. And the idea of the KFD was that we can just use the same address space and with it the page tables for multiple execution devices, e.g. CPUs, GPUs etc...

That idea turned out to be a bad one because it clashes with some use cases (e.g. native context virtualization). The better approach is to see the CPU and GPU processes as separate things which just share the same underlying data.

Opening the KFD node multiple times currently results in the same KFD process being used. We should probably consider changing that.

It is one KFD process binding to one app process, with count to support multiple open/close of for the same process.

Yeah and to repeat myself: That seems to be a bad idea.

Quoted 2 lines

The IOMMU most likely uses Linux process pid, not from kfd process->pasid. The KFD process->pasid is passed to F/W to map queues, flush TLB.

Actually no, the IOMMU uses driver assigned PASIDs.

Quoted 2 lines

The reason to replace vm->pasid with KFD process->pasid is to find vm from fault pasid, then for compute vm, find the kfd process from pasid.

Why aren't we doing it the other way around? In other words start using the VM assigned PASID?

IIRC that the KFD overwrites the PASID inside the VM was only done for the ATC/IOMMU handling, which is now completely gone.

Regards,
Christian.

Quoted 1,167 lines

I can see a bug in amdgpu_vm_handle_fault, only for compute vm, to force update PTE no-retry-fault to the incorrect VM for multiple partitions. This patch will fix this bug but we can have a simple fix.

Regards,

Philip

Quoted 1,161 lines

Regards,
Christian.

Am 11.09.24 um 01:59 schrieb Chen, Xiaogang:

Quoted 1,155 lines

You want have 1:1 mapping between vm and pasid so can query vm from pasid.  I think there is a basic existing issue that we cannot have vm and pasid 1:1 correspondence.

PASIDs are global address space identifiers that can be shared between the GPU, an IOMMU and the driver. One app should have one pasid that iommu uses to decide which page table to use when device access system resource. But one app can open render/kfd node multiple times even for one gpu. That said one app could have multiple GPU vms .

I think we did not have this issue because app usually open a rent node or kfd node only once. With one adev has multiple partitions there are multiple vms on one adev, so have this issue.  But the root cause is not from multiple partitions and solution is not to introduce multiple pasids. I think we should have one pasid for one app and use different way to get vm from pasid.

Regards

Xiaogang

Quoted 1,141 lines · Jonathan

[Public]

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

[Public]

KMS open still set per pasid-vm bindings per adev (socket) so I don’t see how the per-partition overwrite PASID issue is primarily a KFD concern.

Are you saying the KFD process devices holds a shadow copy of the correct VM during page restore during fault?

Doesn’t it acquire the wrong VM object on process init in the first place?

Even if it were the case the KFD had a separate VM reference, the underlying IRQ fault handling is still broken.

We probably don’t want to bandage over something to fix one symptom.

Jon

*From:*Yang, Philip <[email protected]>
*Sent:* Tuesday, September 10, 2024 11:24 AM
*To:* Koenig, Christian <[email protected]>; Kim, Jonathan <[email protected]>; [email protected] *Cc:* Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]> *Subject:* Re: [PATCH] drm/amdkfd: fix vm-pasid lookup for multiple partitions

On 2024-09-09 14:46, Christian König wrote:

Am 09.09.24 um 18:02 schrieb Kim, Jonathan:

[Public]

-----Original Message-----
From: Christian König <[email protected]> <mailto:[email protected]>
Sent: Thursday, September 5, 2024 10:24 AM
To: Kim, Jonathan <[email protected]> <mailto:[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]> <mailto:[email protected]>; Deucher, Alexander <[email protected]> <mailto:[email protected]>; Joshi, Mukul <[email protected]> <mailto:[email protected]>
Subject: Re: [PATCH] drm/amdkfd: fix vm-pasid lookup for multiple partitions

Caution: This message originated from an External Source. Use proper caution
when opening attachments, clicking links, or responding.

Am 19.08.24 um 19:59 schrieb Jonathan Kim:

Currently multiple partitions will incorrectly overwrite the VM lookup
table since the table is indexed by PASID and multiple partitions can
register different VM objects on the same PASID.

That's a rather bad idea. Why do we have the same PASID for different VM
objects in the first place?

Alex can probably elaborate on the KGD side, but from what I can see, the KMS driver open call has always assigned a new VM object per PASID on an open call.
The KFD acquires and replaces the KGD PASID-VMID registration on its own compute process open/creation call. If this is the bad_idea you're referring to, then someone else will have to chime in.  I don't have much history on this unfortunately.

Yeah, Felix and I designed that.

app opens drm node to create vm for each partition, with different vm->pasid for each vm, issue is from kfd_ioctl_acquire_vm -> kfd_process_device_init_vm -> amdgpu_amdkfd_gpuvm_set_vm_pasid, to replace all vm->pasid with kfd process->pasid, which is from open kfd node. This ends up to store only one vm to adev->vm_manager.pasids with KFD process pasid, so we cannot retrieve correct vm from adev->vm_manager.pasids on mGPUs or multiple partitions.

That aside, the current problem is, is that all KFD device structures are logical partitions and register their PASID-VM binding using this concept of a device.

As far as I can see that is the fundamental problem. This needs to be fixed instead.

On the KGD side however, the registration table is maintained in the adev struct, which is a physical socket. So there's a mismatch in understanding of what a device is between the KFD & KGD with regard to the look up table that results in bad bindings.

Adding a per-partition dimension to the existing lookup table resolves issues where seeing, for example, with memory violation interception and XNACK i.e bad bindings result in wrong vm object found to set no-retry flags on memory violations.

svm_range_restore_pages retry fault recover uses fault pasid to get kfd process, and use the fault node_id to get pdd->vm, maybe you can use this way to fix the debugger issue.

Regards,

Philip

    Yeah that is pretty much a no-go.

    The PASID and how it is used is defined by the PCIe
    specifications. If we now start to assign multiple VMs to the
    same PASID then we are violating the PCIe specification.

    The problems you see are most likely just the tip of the
    iceberg here.

    Regards,
    Christian.



        Jon


            Regards,
            Christian.


                This results in loading the wrong VM object on
                PASID query.

                To correct this, setup the lookup table to be
                per-partition-per-PASID
                instead.

                Signed-off-by: Jonathan Kim <[email protected]>
                <mailto:[email protected]>
                ---
                drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 12 ++++
                drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  1 +
                drivers/gpu/drm/amd/amdgpu/amdgpu_job.c |  4 +-
                drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  7 ++-
                drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 55
                +++++++++++------

            -- 

                drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 11 +++-
                drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c |  5 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c |  5 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c |  5 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c |  3 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c |  5 +-
                drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 16 ++----
                drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c |  2 +-
                drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c |  4 +-
                drivers/gpu/drm/amd/amdkfd/kfd_events.c |  3 +-
                .../gpu/drm/amd/amdkfd/kfd_int_process_v10.c |  8 +--
                .../gpu/drm/amd/amdkfd/kfd_int_process_v9.c |  8 +--
                drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c |  3 +-
                   18 files changed, 92 insertions(+), 65
                deletions(-)

                diff --git
                a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c

                index c272461d70a9..28db789610e1 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
                @@ -887,3 +887,15 @@ int
                amdgpu_amdkfd_unmap_hiq(struct

            amdgpu_device *adev, u32 doorbell_off,

                       return r;
                   }
                +
                +int amdgpu_amdkfd_node_id_to_xcc_id(struct
                amdgpu_device *adev,

            uint32_t node_id)

                +{
                +     if (adev->gfx.funcs->ih_node_to_logical_xcc) {
                +             int xcc_id =
                adev->gfx.funcs->ih_node_to_logical_xcc(adev,
                node_id);
                +
                +             if (xcc_id >= 0)
                +                     return xcc_id;
                +     }
                +
                +     return 0;
                +}
                diff --git
                a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h

                index 4ed49265c764..bf8bb45d8ab6 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
                @@ -356,6 +356,7 @@ void
                amdgpu_amdkfd_unreserve_mem_limit(struct

            amdgpu_device *adev,

                uint64_t size, u32 alloc_flag, int8_t xcp_id);

                   u64 amdgpu_amdkfd_xcp_memory_size(struct
                amdgpu_device *adev, int

            xcp_id);

                +int amdgpu_amdkfd_node_id_to_xcc_id(struct
                amdgpu_device *adev,

            uint32_t node_id);

                   #define KFD_XCP_MEM_ID(adev, xcp_id) \
                               ((adev)->xcp_mgr && (xcp_id) >= 0 ?\
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c

                index c6a1783fc9ef..bf9f8802e18d 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
                @@ -37,7 +37,7 @@ static enum drm_gpu_sched_stat

            amdgpu_job_timedout(struct drm_sched_job *s_job)

                       struct amdgpu_job *job = to_amdgpu_job(s_job);
                       struct amdgpu_task_info *ti;
                       struct amdgpu_device *adev = ring->adev;
                -     int idx;
                +     int idx, xcp_id = !job->vm ? 0 :
                job->vm->xcp_id;
                       int r;

                       if (!drm_dev_enter(adev_to_drm(adev), &idx)) {
                @@ -62,7 +62,7 @@ static enum drm_gpu_sched_stat

            amdgpu_job_timedout(struct drm_sched_job *s_job)

                job->base.sched->name,
                atomic_read(&ring->fence_drv.last_seq),
                ring->fence_drv.sync_seq);

                -     ti =
                amdgpu_vm_get_task_info_pasid(ring->adev,
                job->pasid);
                +     ti =
                amdgpu_vm_get_task_info_pasid(ring->adev,
                job->pasid, xcp_id);
                       if (ti) {
                               dev_err(adev->dev,
                                       "Process information:
                process %s pid %d thread %s pid %d\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

                index d9fde38f6ee2..e413bf4a3e84 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
                @@ -1275,17 +1275,20 @@ int
                amdgpu_info_ioctl(struct drm_device *dev,

            void *data, struct drm_file *filp)

                struct amdgpu_vm *vm = &fpriv->vm;
                               struct drm_amdgpu_info_gpuvm_fault
                gpuvm_fault;
                               unsigned long flags;
                +             int i;

                               if (!vm)
                                       return -EINVAL;

                memset(&gpuvm_fault, 0, sizeof(gpuvm_fault));

                - xa_lock_irqsave(&adev->vm_manager.pasids, flags);
                +             for (i = 0; i <
                adev->xcp_mgr->num_xcps; i++)
                + xa_lock_irqsave(&adev->vm_manager.pasids[i],
                flags);
                               gpuvm_fault.addr =
                vm->fault_info.addr;
                               gpuvm_fault.status =
                vm->fault_info.status;
                               gpuvm_fault.vmhub =
                vm->fault_info.vmhub;
                - xa_unlock_irqrestore(&adev->vm_manager.pasids,
                flags);
                +             for (i = 0; i <
                adev->xcp_mgr->num_xcps; i++)
                +
                xa_unlock_irqrestore(&adev->vm_manager.pasids[i],
                flags);

                               return copy_to_user(out, &gpuvm_fault,
                min((size_t)size, sizeof(gpuvm_fault))) ? -EFAULT
                : 0;
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

                index bcb729094521..f43e1c15f423 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
                @@ -146,7 +146,7 @@ int amdgpu_vm_set_pasid(struct
                amdgpu_device

            *adev, struct amdgpu_vm *vm,

                return 0;

                       if (vm->pasid) {
                -             r =
                xa_err(xa_erase_irq(&adev->vm_manager.pasids,
                vm->pasid));
                +             r =
                xa_err(xa_erase_irq(&adev->vm_manager.pasids[vm->xcp_id],


            vm->pasid));

                               if (r < 0)
                                       return r;

                @@ -154,7 +154,7 @@ int amdgpu_vm_set_pasid(struct
                amdgpu_device

            *adev, struct amdgpu_vm *vm,

                       }

                       if (pasid) {
                -             r =
                xa_err(xa_store_irq(&adev->vm_manager.pasids,
                pasid, vm,
                +             r =
                xa_err(xa_store_irq(&adev->vm_manager.pasids[vm->xcp_id],


            pasid, vm,

                GFP_KERNEL));
                               if (r < 0)
                                       return r;
                @@ -2288,14 +2288,14 @@ static void

            amdgpu_vm_destroy_task_info(struct kref *kref)

                   }

                   static inline struct amdgpu_vm *
                -amdgpu_vm_get_vm_from_pasid(struct amdgpu_device
                *adev, u32 pasid)
                +amdgpu_vm_get_vm_from_pasid(struct amdgpu_device
                *adev, u32 pasid,

            u32 xcp_id)

                   {
                       struct amdgpu_vm *vm;
                       unsigned long flags;

                - xa_lock_irqsave(&adev->vm_manager.pasids, flags);
                -     vm = xa_load(&adev->vm_manager.pasids, pasid);
                - xa_unlock_irqrestore(&adev->vm_manager.pasids,
                flags);
                +
                xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id],
                flags);
                +     vm =
                xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
                +
                xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id],
                flags);

                       return vm;
                   }
                @@ -2343,10 +2343,10 @@
                amdgpu_vm_get_task_info_vm(struct

            amdgpu_vm *vm)

                    * referenced down with amdgpu_vm_put_task_info.
                    */
                   struct amdgpu_task_info *
                -amdgpu_vm_get_task_info_pasid(struct
                amdgpu_device *adev, u32 pasid)
                +amdgpu_vm_get_task_info_pasid(struct
                amdgpu_device *adev, u32 pasid,

            u32 xcp_id)

                   {
                       return amdgpu_vm_get_task_info_vm(
                - amdgpu_vm_get_vm_from_pasid(adev, pasid));
                + amdgpu_vm_get_vm_from_pasid(adev, pasid, xcp_id));
                   }

                   static int amdgpu_vm_create_task_info(struct
                amdgpu_vm *vm)
                @@ -2481,6 +2481,8 @@ int amdgpu_vm_init(struct
                amdgpu_device

            *adev, struct amdgpu_vm *vm,

                amdgpu_bo_unreserve(vm->root.bo);
                       amdgpu_bo_unref(&root_bo);

                +     vm->xcp_id = xcp_id < 0 ? 0 : xcp_id;
                +
                       return 0;

                   error_free_root:
                @@ -2695,8 +2697,8 @@ void
                amdgpu_vm_manager_init(struct

            amdgpu_device *adev)

                   #else
                adev->vm_manager.vm_update_mode = 0;
                   #endif
                -
                - xa_init_flags(&adev->vm_manager.pasids,
                XA_FLAGS_LOCK_IRQ);
                +     for (i = 0; i < MAX_XCP; i++)
                + xa_init_flags(&(adev->vm_manager.pasids[i]),

            XA_FLAGS_LOCK_IRQ);

                   }

                   /**
                @@ -2708,10 +2710,15 @@ void
                amdgpu_vm_manager_init(struct

            amdgpu_device *adev)

                    */
                   void amdgpu_vm_manager_fini(struct
                amdgpu_device *adev)
                   {
                - WARN_ON(!xa_empty(&adev->vm_manager.pasids));
                - xa_destroy(&adev->vm_manager.pasids);
                +     int i;
                +
                +     for (i = 0; i < MAX_XCP; i++) {
                + WARN_ON(!xa_empty(&adev->vm_manager.pasids[i]));
                + xa_destroy(&adev->vm_manager.pasids[i]);
                +     }

                       amdgpu_vmid_mgr_fini(adev);
                +
                   }

                   /**
                @@ -2778,17 +2785,18 @@ bool
                amdgpu_vm_handle_fault(struct

            amdgpu_device *adev, u32 pasid,

                       unsigned long irqflags;
                       uint64_t value, flags;
                       struct amdgpu_vm *vm;
                -     int r;
                +     int r, xcp_id;

                - xa_lock_irqsave(&adev->vm_manager.pasids,
                irqflags);
                -     vm = xa_load(&adev->vm_manager.pasids, pasid);
                +     xcp_id =
                amdgpu_amdkfd_node_id_to_xcc_id(adev, node_id)/adev-
                gfx.num_xcc_per_xcp;
                +
                xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id],
                irqflags);
                +     vm =
                xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
                       if (vm) {
                               root = amdgpu_bo_ref(vm->root.bo);
                               is_compute_context =
                vm->is_compute_context;
                       } else {
                               root = NULL;
                       }
                - xa_unlock_irqrestore(&adev->vm_manager.pasids,
                irqflags);
                +
                xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id],
                irqflags);

                       if (!root)
                               return false;
                @@ -2806,11 +2814,11 @@ bool
                amdgpu_vm_handle_fault(struct

            amdgpu_device *adev, u32 pasid,

                               goto error_unref;

                       /* Double check that the VM still exists */
                - xa_lock_irqsave(&adev->vm_manager.pasids,
                irqflags);
                -     vm = xa_load(&adev->vm_manager.pasids, pasid);
                +
                xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id],
                irqflags);
                +     vm =
                xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
                       if (vm && vm->root.bo != root)
                               vm = NULL;
                - xa_unlock_irqrestore(&adev->vm_manager.pasids,
                irqflags);
                +
                xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id],
                irqflags);
                       if (!vm)
                               goto error_unlock;

                @@ -2968,14 +2976,15 @@ void
                amdgpu_vm_update_fault_cache(struct

            amdgpu_device *adev,

                unsigned int pasid,
                uint64_t addr,
                uint32_t status,
                - unsigned int vmhub)
                + unsigned int vmhub,
                + uint32_t xcp_id)
                   {
                       struct amdgpu_vm *vm;
                       unsigned long flags;

                - xa_lock_irqsave(&adev->vm_manager.pasids, flags);
                +
                xa_lock_irqsave(&adev->vm_manager.pasids[xcp_id],
                flags);

                -     vm = xa_load(&adev->vm_manager.pasids, pasid);
                +     vm =
                xa_load(&adev->vm_manager.pasids[xcp_id], pasid);
                       /* Don't update the fault cache if status
                is 0.  In the multiple
                        * fault case, subsequent faults will
                return a 0 status which is
                        * useless for userspace and replaces the
                useful fault status, so
                @@ -3008,7 +3017,7 @@ void
                amdgpu_vm_update_fault_cache(struct

            amdgpu_device *adev,

                WARN_ONCE(1, "Invalid vmhub %u\n", vmhub);
                               }
                       }
                - xa_unlock_irqrestore(&adev->vm_manager.pasids,
                flags);
                +
                xa_unlock_irqrestore(&adev->vm_manager.pasids[xcp_id],
                flags);
                   }

                   /**
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h

            b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h

                index 046949c4b695..1499f5f731e9 100644
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
                @@ -35,6 +35,7 @@
                   #include "amdgpu_sync.h"
                   #include "amdgpu_ring.h"
                   #include "amdgpu_ids.h"
                +#include "amdgpu_xcp.h"

                   struct drm_exec;

                @@ -418,6 +419,9 @@ struct amdgpu_vm {

                       /* cached fault info */
                       struct amdgpu_vm_fault_info fault_info;
                +
                +     /* XCP ID */
                +     int xcp_id;
                   };

                   struct amdgpu_vm_manager {
                @@ -456,7 +460,7 @@ struct amdgpu_vm_manager {
                       /* PASID to VM mapping, will be used in
                interrupt context to
                        * look up VM of a page fault
                        */
                -     struct xarray pasids;
                +     struct xarray pasids[MAX_XCP];
                       /* Global registration of recent page fault
                information */
                       struct amdgpu_vm_fault_info fault_info;
                   };
                @@ -550,7 +554,7 @@ bool
                amdgpu_vm_need_pipeline_sync(struct

            amdgpu_ring *ring,

                   void amdgpu_vm_check_compute_bug(struct
                amdgpu_device *adev);

                   struct amdgpu_task_info *
                -amdgpu_vm_get_task_info_pasid(struct
                amdgpu_device *adev, u32 pasid);
                +amdgpu_vm_get_task_info_pasid(struct
                amdgpu_device *adev, u32 pasid,

            u32 xcp_id);

                   struct amdgpu_task_info *
                   amdgpu_vm_get_task_info_vm(struct amdgpu_vm *vm);
                @@ -649,7 +653,8 @@ void
                amdgpu_vm_update_fault_cache(struct

            amdgpu_device *adev,

                unsigned int pasid,
                uint64_t addr,
                uint32_t status,
                - unsigned int vmhub);
                + unsigned int vmhub,
                + uint32_t xcp_id);
                   void amdgpu_vm_tlb_fence_create(struct
                amdgpu_device *adev,
                                                struct amdgpu_vm *vm,
                                                struct dma_fence
                **fence);
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c

                index f0ceab3ce5bf..24b042febf5c 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
                @@ -151,7 +151,8 @@ static int
                gmc_v10_0_process_interrupt(struct

            amdgpu_device *adev,

                WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

                amdgpu_vm_update_fault_cache(adev, entry->pasid,
                addr, status,
                -                                         
                entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0));

                + entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0),

                + 0);
                       }

                       if (!printk_ratelimit())
                @@ -161,7 +162,7 @@ static int
                gmc_v10_0_process_interrupt(struct

            amdgpu_device *adev,

                "[%s] page fault (src_id:%u ring:%u vmid:%u
                pasid:%u)\n",
                               entry->vmid_src ? "mmhub" : "gfxhub",
                               entry->src_id, entry->ring_id,
                entry->vmid, entry->pasid);
                -     task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +     task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
                       if (task_info) {
                               dev_err(adev->dev,
                                       " in process %s pid %d
                thread %s pid %d\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c

                index 2797fd84432b..3507046d33e6 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c
                @@ -122,7 +122,8 @@ static int
                gmc_v11_0_process_interrupt(struct

            amdgpu_device *adev,

                WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

                amdgpu_vm_update_fault_cache(adev, entry->pasid,
                addr, status,
                -                                         
                entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0));

                + entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0),

                + 0);
                       }

                       if (printk_ratelimit()) {
                @@ -132,7 +133,7 @@ static int
                gmc_v11_0_process_interrupt(struct

            amdgpu_device *adev,

                "[%s] page fault (src_id:%u ring:%u vmid:%u
                pasid:%u)\n",
                entry->vmid_src ? "mmhub" : "gfxhub",
                entry->src_id, entry->ring_id, entry->vmid,
                entry->pasid);
                -             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
                               if (task_info) {
                dev_err(adev->dev,
                                               " in process %s pid
                %d thread %s pid %d)\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c

                index 60acf676000b..9844564c6c74 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c
                @@ -115,7 +115,8 @@ static int
                gmc_v12_0_process_interrupt(struct

            amdgpu_device *adev,

                WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

                amdgpu_vm_update_fault_cache(adev, entry->pasid,
                addr, status,
                -                                         
                entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0));

                + entry->vmid_src ? AMDGPU_MMHUB0(0) :

            AMDGPU_GFXHUB(0),

                + 0);
                       }

                       if (printk_ratelimit()) {
                @@ -125,7 +126,7 @@ static int
                gmc_v12_0_process_interrupt(struct

            amdgpu_device *adev,

                "[%s] page fault (src_id:%u ring:%u vmid:%u
                pasid:%u)\n",
                entry->vmid_src ? "mmhub" : "gfxhub",
                entry->src_id, entry->ring_id, entry->vmid,
                entry->pasid);
                -             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
                               if (task_info) {
                dev_err(adev->dev,
                                               " in process %s pid
                %d thread %s pid %d)\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c

                index 994432fb57ea..2cdb0cbb7c4d 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
                @@ -1268,7 +1268,8 @@ static int
                gmc_v7_0_process_interrupt(struct

            amdgpu_device *adev,

                return 0;

                amdgpu_vm_update_fault_cache(adev, entry->pasid,
                - ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,

            AMDGPU_GFXHUB(0));

                + ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
                + AMDGPU_GFXHUB(0), 0);

                       if (amdgpu_vm_fault_stop ==
                AMDGPU_VM_FAULT_STOP_FIRST)
                gmc_v7_0_set_fault_enable_default(adev, false);
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c

                index 86488c052f82..6855caeb7f74 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
                @@ -1437,7 +1437,8 @@ static int
                gmc_v8_0_process_interrupt(struct

            amdgpu_device *adev,

                return 0;

                amdgpu_vm_update_fault_cache(adev, entry->pasid,
                - ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,

            AMDGPU_GFXHUB(0));

                + ((u64)addr) << AMDGPU_GPU_PAGE_SHIFT, status,
                + AMDGPU_GFXHUB(0), 0);

                       if (amdgpu_vm_fault_stop ==
                AMDGPU_VM_FAULT_STOP_FIRST)
                gmc_v8_0_set_fault_enable_default(adev, false);
                @@ -1448,7 +1449,7 @@ static int
                gmc_v8_0_process_interrupt(struct

            amdgpu_device *adev,

                dev_err(adev->dev, "GPU fault detected: %d 0x%08x\n",
                entry->src_id, entry->src_data[0]);

                -             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +             task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
                               if (task_info) {
                dev_err(adev->dev, " for process %s pid %d thread
                %s pid %d\n",
                task_info->process_name, task_info->tgid,
                diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c

            b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c

                index b73136d390cc..e183e08b2c02 100644
                --- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
                @@ -556,10 +556,12 @@ static int
                gmc_v9_0_process_interrupt(struct

            amdgpu_device *adev,

                       unsigned int vmhub;
                       u64 addr;
                       uint32_t cam_index = 0;
                -     int ret, xcc_id = 0;
                -     uint32_t node_id;
                +     int ret;
                +     uint32_t node_id, xcc_id, xcp_id;

                       node_id = entry->node_id;
                +     xcc_id =
                amdgpu_amdkfd_node_id_to_xcc_id(adev, node_id);
                +     xcp_id = xcc_id/adev->gfx.num_xcc_per_xcp;

                       addr = (u64)entry->src_data[0] << 12;
                       addr |= ((u64)entry->src_data[1] & 0xf) << 44;
                @@ -572,12 +574,6 @@ static int
                gmc_v9_0_process_interrupt(struct

            amdgpu_device *adev,

                vmhub = AMDGPU_MMHUB1(0);
                       } else {
                               hub_name = "gfxhub0";
                -             if
                (adev->gfx.funcs->ih_node_to_logical_xcc) {
                -                     xcc_id =
                adev->gfx.funcs->ih_node_to_logical_xcc(adev,
                - node_id);
                -                     if (xcc_id < 0)
                -                             xcc_id = 0;
                -             }
                               vmhub = xcc_id;
                       }
                       hub = &adev->vmhub[vmhub];
                @@ -631,7 +627,7 @@ static int
                gmc_v9_0_process_interrupt(struct

            amdgpu_device *adev,

                retry_fault ? "retry" : "no-retry",
                               entry->src_id, entry->ring_id,
                entry->vmid, entry->pasid);

                -     task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +     task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid,

            xcp_id);

                       if (task_info) {
                               dev_err(adev->dev,
                                       " for process %s pid %d
                thread %s pid %d)\n",
                @@ -675,7 +671,7 @@ static int
                gmc_v9_0_process_interrupt(struct

            amdgpu_device *adev,

                       if (!amdgpu_sriov_vf(adev))
                WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);

                - amdgpu_vm_update_fault_cache(adev, entry->pasid,
                addr, status,

            vmhub);

                + amdgpu_vm_update_fault_cache(adev, entry->pasid,
                addr, status,

            vmhub, xcp_id);

                dev_err(adev->dev,
                "VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c

            b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c

                index 23ef4eb36b40..1ac4224bbe5b 100644
                --- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
                +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
                @@ -2182,7 +2182,7 @@ static int
                sdma_v4_0_print_iv_entry(struct

            amdgpu_device *adev,

                instance, addr, entry->src_id, entry->ring_id,
                entry->vmid,
                entry->pasid);

                -     task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +     task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid, 0);
                       if (task_info) {
                dev_dbg_ratelimited(adev->dev,
                                                   " for process
                %s pid %d thread %s pid %d\n",
                diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

            b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

                index 57f16c09abfc..c8b5c0302ca7 100644
                --- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
                +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
                @@ -1683,6 +1683,8 @@ static int
                sdma_v4_4_2_print_iv_entry(struct

            amdgpu_device *adev,

                       int instance;
                       struct amdgpu_task_info *task_info;
                       u64 addr;
                +     uint32_t xcc_id =
                amdgpu_amdkfd_node_id_to_xcc_id(adev, entry-
                node_id);
                +     uint32_t xcp_id =
                xcc_id/adev->gfx.num_xcc_per_xcp;

                       instance = sdma_v4_4_2_irq_id_to_seq(adev,
                entry->client_id);
                       if (instance < 0 || instance >=
                adev->sdma.num_instances) {
                @@ -1698,7 +1700,7 @@ static int
                sdma_v4_4_2_print_iv_entry(struct

            amdgpu_device *adev,

                instance, addr, entry->src_id, entry->ring_id,
                entry->vmid,
                entry->pasid);

                -     task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid);
                +     task_info =
                amdgpu_vm_get_task_info_pasid(adev, entry->pasid,

            xcp_id);

                       if (task_info) {
                dev_dbg_ratelimited(adev->dev, " for process %s
                pid %d thread %s

            pid %d\n",

                task_info->process_name, task_info->tgid,
                diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_events.c

            b/drivers/gpu/drm/amd/amdkfd/kfd_events.c

                index ea3792249209..c098fbaf0e1c 100644
                --- a/drivers/gpu/drm/amd/amdkfd/kfd_events.c
                +++ b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
                @@ -1262,8 +1262,9 @@ void
                kfd_signal_reset_event(struct kfd_node

            *dev)

                               if (dev->dqm->detect_hang_count) {
                                       struct amdgpu_task_info *ti;
                +                     uint32_t xcp_id = dev->xcp ?
                dev->xcp->id : 0;

                -                     ti =
                amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid);
                +                     ti =
                amdgpu_vm_get_task_info_pasid(dev->adev, p->pasid,

            xcp_id);

                if (ti) {
                dev_err(dev->adev->dev,
                "Queues reset on process %s tid %d thread %s pid
                %d\n",
                diff --git
                a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c

            b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c

                index 8e0d0356e810..d7cbf9525698 100644
                ---
                a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c
                +++
                b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v10.c
                @@ -377,12 +377,8 @@ static void
                event_interrupt_wq_v10(struct

            kfd_node *dev,

                struct kfd_hsa_memory_exception_data exception_data;

                               /* gfxhub */
                -             if (!vmid_type &&
                dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
                -                     hub_inst =
                dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev-
                adev,
                - node_id);
                -                     if (hub_inst < 0)
                -                             hub_inst = 0;
                -             }
                +             if (!vmid_type)
                +                     hub_inst =
                amdgpu_amdkfd_node_id_to_xcc_id(dev->adev,

            node_id);

                               /* mmhub */
                               if (vmid_type && client_id ==
                SOC15_IH_CLIENTID_VMC)
                diff --git
                a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c

            b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c

                index a9c3580be8c9..4708b8c811a5 100644
                --- a/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c
                +++ b/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c
                @@ -437,12 +437,8 @@ static void
                event_interrupt_wq_v9(struct

            kfd_node *dev,

                struct kfd_hsa_memory_exception_data exception_data;

                               /* gfxhub */
                -             if (!vmid_type &&
                dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
                -                     hub_inst =
                dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev-
                adev,
                - node_id);
                -                     if (hub_inst < 0)
                -                             hub_inst = 0;
                -             }
                +             if (!vmid_type)
                +                     hub_inst =
                amdgpu_amdkfd_node_id_to_xcc_id(dev->adev,

            node_id);

                               /* mmhub */
                               if (vmid_type && client_id ==
                SOC15_IH_CLIENTID_VMC)
                diff --git
                a/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c

            b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c

                index ea6a8e43bd5b..b5f2f5b1069c 100644
                --- a/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
                +++ b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
                @@ -251,8 +251,9 @@ void

            kfd_smi_event_update_thermal_throttling(struct
            kfd_node *dev,

                   void kfd_smi_event_update_vmfault(struct
                kfd_node *dev, uint16_t pasid)
                   {
                       struct amdgpu_task_info *task_info;
                +     uint32_t xcp_id = dev->xcp ? dev->xcp->id : 0;

                -     task_info =
                amdgpu_vm_get_task_info_pasid(dev->adev, pasid);
                +     task_info =
                amdgpu_vm_get_task_info_pasid(dev->adev, pasid,
                xcp_id);
                       if (task_info) {
                               /* Report VM faults from user
                applications, not retry from kernel */
                               if (task_info->pid)