Skip to contentSkip to conversation

drm/amdgpu: Disable XNACK retry on GFX12.1

PATCH In review Kent Russell 4 participants 4 messages Nov 16 – Nov 17

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

PATCH 1/1 drm/amdgpu: Disable XNACK retry on GFX12.1

This feature cannot be properly supported, so disable it both on the amdgpu side and the amdkfd side.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c        |  7 +++++++
 drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c         |  5 ++---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c       | 12 ++++++++++++
 .../amdkfd/kfd_device_queue_manager_v12_1.c    | 18 ++++--------------
 drivers/gpu/drm/amd/amdkfd/kfd_process.c       |  7 +++++++
 5 files changed, 32 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +7 -0
index 08d3ff61edcc..d0ede277aa85 100644
@@ -1151,6 +1151,13 @@ void amdgpu_gmc_noretry_set(struct amdgpu_device *adev)
 		gmc->noretry = 1;
 	else
 		gmc->noretry = (amdgpu_noretry == -1) ? noretry_default : amdgpu_noretry;
+
+	/* XNACK cannot be enabled on GFX12.1, so keep noretry=1 */
+	if (gc_ver == IP_VERSION(12, 1, 0)) {
+		if (amdgpu_noretry == 0)
+			dev_warn(adev->dev, "Unable to set noretry = 0 on GFX12.1. Keeping noretry = 1");
+		gmc->noretry = 1;
+	}
 }
 
 void amdgpu_gmc_set_vm_fault_masks(struct amdgpu_device *adev, int hub_type,
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +2 -3
index 1f57d0fa2c04..034cc3fd07f3 100644
@@ -1518,9 +1518,8 @@ static u32 gfx_v12_1_get_sh_mem_config(struct amdgpu_device *adev)
 {
 	u32 sh_mem_config = DEFAULT_SH_MEM_CONFIG;
 
-	/* GC 12.1.0 A0 requires RETRY_DISABLE in SH_MEM_CONFIG. */
-	if (SOC_V1_0_DIE_REV_XCD(adev->rev_id) == 0)
-		sh_mem_config |= 1 << SH_MEM_CONFIG__RETRY_DISABLE__SHIFT;
+	/* XNACK cannot be enabled for GFX12.1 */
+	sh_mem_config |= 1 << SH_MEM_CONFIG__RETRY_DISABLE__SHIFT;
 
 	return sh_mem_config;
 }
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +12 -0
index 3d2136adb62b..3b62b9e5ecda 100644
@@ -1766,6 +1766,8 @@ static int kfd_ioctl_set_xnack_mode(struct file *filep,
 
 	mutex_lock(&p->mutex);
 	if (args->xnack_enabled >= 0) {
+		int i;
+
 		if (!list_empty(&p->pqm.queues)) {
 			pr_debug("Process has user queues running\n");
 			r = -EBUSY;
@@ -1780,6 +1782,16 @@ static int kfd_ioctl_set_xnack_mode(struct file *filep,
 			goto out_unlock;
 		}
 
+		/* XNACK cannot be enabled for gfx12.1 */
+		for (i = 0; i < p->n_pdds; i++) {
+			struct kfd_node *dev = p->pdds[i]->dev;
+
+			if (KFD_GC_VERSION(dev) == IP_VERSION(12, 1, 0)) {
+				r = -EPERM;
+				goto out_unlock;
+			}
+		}
+
 		r = svm_range_switch_xnack_reserve_mem(p, args->xnack_enabled);
 	} else {
 		args->xnack_enabled = p->xnack_enabled;
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager_v12_1.c +4 -14
index 525989371378..63ba13a60b98 100644
@@ -54,7 +54,6 @@ static int update_qpd_v12_1(struct device_queue_manager *dqm,
 	struct kfd_process_device *pdd;
 	struct amdgpu_device *adev = dqm->dev->adev;
 	struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB(0)];
-	bool xnack_enabled;
 
 	pdd = qpd_to_pdd(qpd);
 	qpd->vm_cntx_cntl = hub->vm_cntx_cntl;
@@ -72,19 +71,10 @@ static int update_qpd_v12_1(struct device_queue_manager *dqm,
 		qpd->sh_mem_ape1_base = 0;
 	}
 
-	xnack_enabled = KFD_SUPPORT_XNACK_PER_PROCESS(dqm->dev) ?
-			pdd->process->xnack_enabled :
-			!pdd->dev->kfd->noretry;
-
-	if (!xnack_enabled) {
-		qpd->sh_mem_config |= 1 << SH_MEM_CONFIG__RETRY_DISABLE__SHIFT;
-		qpd->vm_cntx_cntl &=
-			~(1 << GCVM_CONTEXT0_CNTL__RETRY_PERMISSION_OR_INVALID_PAGE_FAULT__SHIFT);
-	} else {
-		qpd->sh_mem_config &= ~(1 << SH_MEM_CONFIG__RETRY_DISABLE__SHIFT);
-		qpd->vm_cntx_cntl |=
-			(1 << GCVM_CONTEXT0_CNTL__RETRY_PERMISSION_OR_INVALID_PAGE_FAULT__SHIFT);
-	}
+	/* XNACK cannot be enabled for gfx12.1 */
+	qpd->sh_mem_config |= 1 << SH_MEM_CONFIG__RETRY_DISABLE__SHIFT;
+	qpd->vm_cntx_cntl &=
+		~(1 << GCVM_CONTEXT0_CNTL__RETRY_PERMISSION_OR_INVALID_PAGE_FAULT__SHIFT);
 
 	qpd->sh_mem_bases = compute_sh_mem_bases_64bit(pdd);
 
drivers/gpu/drm/amd/amdkfd/kfd_process.c +7 -0
index 546721b4d59a..059e22cd7f1a 100644
@@ -1670,6 +1670,13 @@ bool kfd_process_xnack_mode(struct kfd_process *p, bool supported)
 		    KFD_GC_VERSION(dev) < IP_VERSION(12, 1, 0))
 			return false;
 
+		/* XNACK cannot be enabled on GFX12.1 . While dev->kfd->noretry
+		 * should propagate this requirement, adding it explicitly here
+		 * will help cover any possible future reworks
+		 */
+		if (KFD_GC_VERSION(dev) == IP_VERSION(12, 1, 0))
+			return false;
+
 		if (dev->kfd->noretry)
 			return false;
 	}
Signature · 1 line
2.43.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] drm/amdkfd: unreachable duplicate GFX12.1 check in kfd_ioctl_set_xnack_mode() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] drm/amdkfd: unreachable duplicate GFX12.1 check in kfd_ioctl_set_xnack_mode()
--

commit 34665c5afc18630d5c2e3d3dd0b64b6b650cafc2
Author: Kent Russell <[email protected]>

drm/amdgpu: Disable XNACK retry on GFX12.1

This commit disables XNACK retry on GFX12.1 in both amdgpu and amdkfd by forcing noretry=1, setting RETRY_DISABLE in SH_MEM_CONFIG, and rejecting XNACK mode enablement for GFX12.1 devices.

[ ... ]

Quoted 16 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -0
index 5a7f4f0cd0ce7..0728271f8c087 100644
@@ -1766,6 +1766,8 @@ static int kfd_ioctl_set_xnack_mode(struct file *filep,
 
 	mutex_lock(&p->mutex);
 	if (args->xnack_enabled >= 0) {
+		int i;
+
 		if (!list_empty(&p->pqm.queues)) {
 			pr_debug("Process has user queues running\n");
 			r = -EBUSY;
@@ -1780,6 +1782,16 @@ static int kfd_ioctl_set_xnack_mode(struct file *filep,
 			goto out_unlock;
 		}

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_ioctl_set_xnack_mode(struct file *filep, · line 1793

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +9 -0
 
+		/* XNACK cannot be enabled for gfx12.1 */
+		for (i = 0; i < p->n_pdds; i++) {
+			struct kfd_node *dev = p->pdds[i]->dev;
+
+			if (KFD_GC_VERSION(dev) == IP_VERSION(12, 1, 0)) {
+				r = -EPERM;
+				goto out_unlock;
+			}
+		}

[Severity: Low]
Is this loop in kfd_ioctl_set_xnack_mode() reachable?

Immediately above it, enabling XNACK checks kfd_process_xnack_mode(p, true), which already iterates over p->pdds[] and returns false when KFD_GC_VERSION(dev) == IP_VERSION(12, 1, 0) (or dev->kfd->noretry is set):

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c:kfd_ioctl_set_xnack_mode() {
	...
		if (p->xnack_enabled == args->xnack_enabled)
			goto out_unlock;

		if (args->xnack_enabled && !kfd_process_xnack_mode(p, true)) {
			r = -EPERM;
			goto out_unlock;
		}
	...
}

When args->xnack_enabled is 0, p->xnack_enabled is already initialized to false on GFX12.1, so the p->xnack_enabled == args->xnack_enabled check exits early (and if p->xnack_enabled were ever true, this unguarded loop would reject disabling XNACK with -EPERM).

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Kent Russell
Quoted 35 lines · Kent Russell

This feature cannot be properly supported, so disable it both on the amdgpu side and the amdkfd side.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c        |  7 +++++++
 drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c         |  5 ++---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c       | 12 ++++++++++++
 .../amdkfd/kfd_device_queue_manager_v12_1.c    | 18 ++++--------------
 drivers/gpu/drm/amd/amdkfd/kfd_process.c       |  7 +++++++
 5 files changed, 32 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +7 -0
index 08d3ff61edcc..d0ede277aa85 100644
@@ -1151,6 +1151,13 @@ void amdgpu_gmc_noretry_set(struct amdgpu_device *adev)
 		gmc->noretry = 1;
 	else
 		gmc->noretry = (amdgpu_noretry == -1) ? noretry_default : amdgpu_noretry;
+
+	/* XNACK cannot be enabled on GFX12.1, so keep noretry=1 */
+	if (gc_ver == IP_VERSION(12, 1, 0)) {
+		if (amdgpu_noretry == 0)
+			dev_warn(adev->dev, "Unable to set noretry = 0 on GFX12.1. Keeping noretry = 1");
+		gmc->noretry = 1;
+	}
 }
 
 void amdgpu_gmc_set_vm_fault_masks(struct amdgpu_device *adev, int hub_type,
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +0 -0
index 1f57d0fa2c04..034cc3fd07f3 100644

drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c static u32 gfx_v12_1_get_sh_mem_config(struct amdgpu_device *adev) · line 1522

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +2 -3
@@ -1518,9 +1518,8 @@ static u32 gfx_v12_1_get_sh_mem_config(struct amdgpu_device *adev)
 {
 	u32 sh_mem_config = DEFAULT_SH_MEM_CONFIG;
 
-	/* GC 12.1.0 A0 requires RETRY_DISABLE in SH_MEM_CONFIG. */
-	if (SOC_V1_0_DIE_REV_XCD(adev->rev_id) == 0)
-		sh_mem_config |= 1 << SH_MEM_CONFIG__RETRY_DISABLE__SHIFT;
+	/* XNACK cannot be enabled for GFX12.1 */
+	sh_mem_config |= 1 << SH_MEM_CONFIG__RETRY_DISABLE__SHIFT;

I think we only the above 2 changes. I don't think we need the changes below.

noretry=1 should handle the conditions below correctly anyways.

Regards,

Mukul

Quoted 86 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +0 -0
 	return sh_mem_config;
 }
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +12 -0
index 3d2136adb62b..3b62b9e5ecda 100644
@@ -1766,6 +1766,8 @@ static int kfd_ioctl_set_xnack_mode(struct file *filep,
 
 	mutex_lock(&p->mutex);
 	if (args->xnack_enabled >= 0) {
+		int i;
+
 		if (!list_empty(&p->pqm.queues)) {
 			pr_debug("Process has user queues running\n");
 			r = -EBUSY;
@@ -1780,6 +1782,16 @@ static int kfd_ioctl_set_xnack_mode(struct file *filep,
 			goto out_unlock;
 		}
 
+		/* XNACK cannot be enabled for gfx12.1 */
+		for (i = 0; i < p->n_pdds; i++) {
+			struct kfd_node *dev = p->pdds[i]->dev;
+
+			if (KFD_GC_VERSION(dev) == IP_VERSION(12, 1, 0)) {
+				r = -EPERM;
+				goto out_unlock;
+			}
+		}
+
 		r = svm_range_switch_xnack_reserve_mem(p, args->xnack_enabled);
 	} else {
 		args->xnack_enabled = p->xnack_enabled;
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager_v12_1.c +4 -14
index 525989371378..63ba13a60b98 100644
@@ -54,7 +54,6 @@ static int update_qpd_v12_1(struct device_queue_manager *dqm,
 	struct kfd_process_device *pdd;
 	struct amdgpu_device *adev = dqm->dev->adev;
 	struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB(0)];
-	bool xnack_enabled;
 
 	pdd = qpd_to_pdd(qpd);
 	qpd->vm_cntx_cntl = hub->vm_cntx_cntl;
@@ -72,19 +71,10 @@ static int update_qpd_v12_1(struct device_queue_manager *dqm,
 		qpd->sh_mem_ape1_base = 0;
 	}
 
-	xnack_enabled = KFD_SUPPORT_XNACK_PER_PROCESS(dqm->dev) ?
-			pdd->process->xnack_enabled :
-			!pdd->dev->kfd->noretry;
-
-	if (!xnack_enabled) {
-		qpd->sh_mem_config |= 1 << SH_MEM_CONFIG__RETRY_DISABLE__SHIFT;
-		qpd->vm_cntx_cntl &=
-			~(1 << GCVM_CONTEXT0_CNTL__RETRY_PERMISSION_OR_INVALID_PAGE_FAULT__SHIFT);
-	} else {
-		qpd->sh_mem_config &= ~(1 << SH_MEM_CONFIG__RETRY_DISABLE__SHIFT);
-		qpd->vm_cntx_cntl |=
-			(1 << GCVM_CONTEXT0_CNTL__RETRY_PERMISSION_OR_INVALID_PAGE_FAULT__SHIFT);
-	}
+	/* XNACK cannot be enabled for gfx12.1 */
+	qpd->sh_mem_config |= 1 << SH_MEM_CONFIG__RETRY_DISABLE__SHIFT;
+	qpd->vm_cntx_cntl &=
+		~(1 << GCVM_CONTEXT0_CNTL__RETRY_PERMISSION_OR_INVALID_PAGE_FAULT__SHIFT);
 
 	qpd->sh_mem_bases = compute_sh_mem_bases_64bit(pdd);
 
drivers/gpu/drm/amd/amdkfd/kfd_process.c +7 -0
index 546721b4d59a..059e22cd7f1a 100644
@@ -1670,6 +1670,13 @@ bool kfd_process_xnack_mode(struct kfd_process *p, bool supported)
 		    KFD_GC_VERSION(dev) < IP_VERSION(12, 1, 0))
 			return false;
 
+		/* XNACK cannot be enabled on GFX12.1 . While dev->kfd->noretry
+		 * should propagate this requirement, adding it explicitly here
+		 * will help cover any possible future reworks
+		 */
+		if (KFD_GC_VERSION(dev) == IP_VERSION(12, 1, 0))
+			return false;
+
 		if (dev->kfd->noretry)
 			return false;
 	}
#3 lore raw
Quoted 47 lines · Mukul Joshi
Quoted 35 lines · Kent Russell

This feature cannot be properly supported, so disable it both on the amdgpu side and the amdkfd side.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c        |  7 +++++++
  drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c         |  5 ++---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c       | 12 ++++++++++++
  .../amdkfd/kfd_device_queue_manager_v12_1.c    | 18 ++++--------------
  drivers/gpu/drm/amd/amdkfd/kfd_process.c       |  7 +++++++
  5 files changed, 32 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +7 -0
index 08d3ff61edcc..d0ede277aa85 100644
@@ -1151,6 +1151,13 @@ void amdgpu_gmc_noretry_set(struct amdgpu_device *adev)
  		gmc->noretry = 1;
  	else
  		gmc->noretry = (amdgpu_noretry == -1) ? noretry_default : amdgpu_noretry;
+
+	/* XNACK cannot be enabled on GFX12.1, so keep noretry=1 */
+	if (gc_ver == IP_VERSION(12, 1, 0)) {
+		if (amdgpu_noretry == 0)
+			dev_warn(adev->dev, "Unable to set noretry = 0 on GFX12.1. Keeping noretry = 1");
+		gmc->noretry = 1;
+	}
  }
 
  void amdgpu_gmc_set_vm_fault_masks(struct amdgpu_device *adev, int hub_type,
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +0 -0
index 1f57d0fa2c04..034cc3fd07f3 100644

drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c static u32 gfx_v12_1_get_sh_mem_config(struct amdgpu_device *adev) · line 1522

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +2 -3
@@ -1518,9 +1518,8 @@ static u32 gfx_v12_1_get_sh_mem_config(struct amdgpu_device *adev)
  {
  	u32 sh_mem_config = DEFAULT_SH_MEM_CONFIG;
 
-	/* GC 12.1.0 A0 requires RETRY_DISABLE in SH_MEM_CONFIG. */
-	if (SOC_V1_0_DIE_REV_XCD(adev->rev_id) == 0)
-		sh_mem_config |= 1 << SH_MEM_CONFIG__RETRY_DISABLE__SHIFT;
+	/* XNACK cannot be enabled for GFX12.1 */
+	sh_mem_config |= 1 << SH_MEM_CONFIG__RETRY_DISABLE__SHIFT;

I think we only the above 2 changes. I don't think we need the changes below.

Quoted 1 line

noretry=1 should handle the conditions below correctly anyways.

yes, I think change are limited in function kfd_process_xnack_mode() and function update_qpd_v12_1(), then set XNACK+ will return failure and qpd->sh_mem_config is always set to xnack- regardless of boottime noretry parameter. Regards, Philip

Quoted 91 lines

Regards,

Mukul

Quoted 86 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +0 -0
  	return sh_mem_config;
  }
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +12 -0
index 3d2136adb62b..3b62b9e5ecda 100644
@@ -1766,6 +1766,8 @@ static int kfd_ioctl_set_xnack_mode(struct file *filep,
 
  	mutex_lock(&p->mutex);
  	if (args->xnack_enabled >= 0) {
+		int i;
+
  		if (!list_empty(&p->pqm.queues)) {
  			pr_debug("Process has user queues running\n");
  			r = -EBUSY;
@@ -1780,6 +1782,16 @@ static int kfd_ioctl_set_xnack_mode(struct file *filep,
  			goto out_unlock;
  		}
 
+		/* XNACK cannot be enabled for gfx12.1 */
+		for (i = 0; i < p->n_pdds; i++) {
+			struct kfd_node *dev = p->pdds[i]->dev;
+
+			if (KFD_GC_VERSION(dev) == IP_VERSION(12, 1, 0)) {
+				r = -EPERM;
+				goto out_unlock;
+			}
+		}
+
  		r = svm_range_switch_xnack_reserve_mem(p, args->xnack_enabled);
  	} else {
  		args->xnack_enabled = p->xnack_enabled;
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager_v12_1.c +4 -14
index 525989371378..63ba13a60b98 100644
@@ -54,7 +54,6 @@ static int update_qpd_v12_1(struct device_queue_manager *dqm,
  	struct kfd_process_device *pdd;
  	struct amdgpu_device *adev = dqm->dev->adev;
  	struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB(0)];
-	bool xnack_enabled;
 
  	pdd = qpd_to_pdd(qpd);
  	qpd->vm_cntx_cntl = hub->vm_cntx_cntl;
@@ -72,19 +71,10 @@ static int update_qpd_v12_1(struct device_queue_manager *dqm,
  		qpd->sh_mem_ape1_base = 0;
  	}
 
-	xnack_enabled = KFD_SUPPORT_XNACK_PER_PROCESS(dqm->dev) ?
-			pdd->process->xnack_enabled :
-			!pdd->dev->kfd->noretry;
-
-	if (!xnack_enabled) {
-		qpd->sh_mem_config |= 1 << SH_MEM_CONFIG__RETRY_DISABLE__SHIFT;
-		qpd->vm_cntx_cntl &=
-			~(1 << GCVM_CONTEXT0_CNTL__RETRY_PERMISSION_OR_INVALID_PAGE_FAULT__SHIFT);
-	} else {
-		qpd->sh_mem_config &= ~(1 << SH_MEM_CONFIG__RETRY_DISABLE__SHIFT);
-		qpd->vm_cntx_cntl |=
-			(1 << GCVM_CONTEXT0_CNTL__RETRY_PERMISSION_OR_INVALID_PAGE_FAULT__SHIFT);
-	}
+	/* XNACK cannot be enabled for gfx12.1 */
+	qpd->sh_mem_config |= 1 << SH_MEM_CONFIG__RETRY_DISABLE__SHIFT;
+	qpd->vm_cntx_cntl &=
+		~(1 << GCVM_CONTEXT0_CNTL__RETRY_PERMISSION_OR_INVALID_PAGE_FAULT__SHIFT);
 
  	qpd->sh_mem_bases = compute_sh_mem_bases_64bit(pdd);
 
drivers/gpu/drm/amd/amdkfd/kfd_process.c +7 -0
index 546721b4d59a..059e22cd7f1a 100644
@@ -1670,6 +1670,13 @@ bool kfd_process_xnack_mode(struct kfd_process *p, bool supported)
  		    KFD_GC_VERSION(dev) < IP_VERSION(12, 1, 0))
  			return false;
 
+		/* XNACK cannot be enabled on GFX12.1 . While dev->kfd->noretry
+		 * should propagate this requirement, adding it explicitly here
+		 * will help cover any possible future reworks
+		 */
+		if (KFD_GC_VERSION(dev) == IP_VERSION(12, 1, 0))
+			return false;
+
  		if (dev->kfd->noretry)
  			return false;
  	}