Skip to contentSkip to conversation

Define and use reset domain for GPU recovery in amdgpu

RFC In review Andrey Grodzovsky 7 participants 34 messages Feb 9, 2022 – Mar 4, 2022

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

v4 cover Define and use reset domain for GPU recovery in amdgpu

This patchset is based on earlier work by Boris[1] that allowed to have an ordered workqueue at the driver level that will be used by the different schedulers to queue their timeout work. On top of that I also serialized any GPU reset we trigger from within amdgpu code to also go through the same ordered wq and in this way simplify somewhat our GPU reset code so we don't need to protect from concurrency by multiple GPU reset triggeres such as TDR on one hand and sysfs trigger or RAS trigger on the other hand.

As advised by Christian and Daniel I defined a reset_domain struct such that all the entities that go through reset together will be serialized one against another.

TDR triggered by multiple entities within the same domain due to the same reason will not be triggered as the first such reset will cancel all the pending resets. This is relevant only to TDR timers and not to triggered resets coming from RAS or SYSFS, those will still happen after the in flight resets finishes.

v2:
Add handling on SRIOV configuration, the reset notify coming from host and driver already trigger a work queue to handle the reset so drop this intermediate wq and send directly to timeout wq. (Shaoyun)

v3:
Lijo suggested puting 'adev->in_gpu_reset' in amdgpu_reset_domain struct.
I followed his advise and also moved adev->reset_sem into same place. This
in turn caused to do some follow-up refactor of the original patches
where i decoupled amdgpu_reset_domain life cycle frolm XGMI hive because hive is destroyed and reconstructed for the case of reset the devices in the XGMI hive during probe for SRIOV See [2] while we need the reset sem and gpu_reset flag to always be present. This was attained by adding refcount to amdgpu_reset_domain so each device can safely point to it as long as it needs.

v4:
Just bug fixing of reset_domain refcount on XGMI hive boot and some cosmetic wrappers to reset domain refocunt.

[1] https://patchwork.kernel.org/project/dri-devel/patch/[email protected]/
[2] https://www.spinics.net/lists/amd-gfx/msg58836.html

P.S Going through drm-misc-next and not amd-staging-drm-next as Boris work hasn't landed yet there.

P.P.S Patches 8-12 are the refactor on top of the original V2 patchset.

Andrey Grodzovsky (11):
drm/amdgpu: Introduce reset domain
drm/amdgpu: Move scheduler init to after XGMI is ready drm/amdgpu: Serialize non TDR gpu recovery with TDRs drm/amd/virt: For SRIOV send GPU reset directly to TDR queue. drm/amdgpu: Drop hive->in_reset
drm/amdgpu: Drop concurrent GPU reset protection for device drm/amdgpu: Rework reset domain to be refcounted. drm/amdgpu: Move reset sem into reset_domain drm/amdgpu: Move in_gpu_reset into reset_domain drm/amdgpu: Rework amdgpu_device_lock_adev
Revert 'drm/amdgpu: annotate a false positive recursive locking'

 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  13 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c   |  10 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    | 275 ++++++++++--------
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c     |  34 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c       |   2 +-
 .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c    |  18 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c     |  43 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h     |  37 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h      |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c      |  27 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h      |   3 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c        |   6 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c         |  14 +-
 drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c         |  19 +-
 drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c         |  19 +-
 drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c         |  11 +-
 16 files changed, 335 insertions(+), 198 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

RFC v4 1/11 drm/amdgpu: Introduce reset domain

Defined a reset_domain struct such that
all the entities that go through reset
together will be serialized one against
another. Do it for both single device and
XGMI hive cases.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  5 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 20 +++++++++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c   |  9 +++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h   |  2 ++
 4 files changed, 35 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +5 -0
index d8b854fcbffa..b76c1cfad7f1 100644
@@ -813,6 +813,10 @@ struct amd_powerplay {
 #define AMDGPU_RESET_MAGIC_NUM 64
 #define AMDGPU_MAX_DF_PERFMONS 4
 #define AMDGPU_PRODUCT_NAME_LEN 64
+struct amdgpu_reset_domain {
+	struct workqueue_struct *wq;
+};
+
 struct amdgpu_device {
 	struct device			*dev;
 	struct pci_dev			*pdev;
@@ -1100,6 +1104,7 @@ struct amdgpu_device {
 	uint32_t                        ip_versions[MAX_HWIP][HWIP_MAX_INSTANCE];
 
 	bool				ram_is_direct_mapped;
+	struct amdgpu_reset_domain	reset_domain;
 };
 
 static inline struct amdgpu_device *drm_to_adev(struct drm_device *ddev)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +19 -1
index ed077de426d9..9704b0e1fd82 100644
@@ -2398,9 +2398,27 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
 	if (r)
 		goto init_failed;
 
-	if (adev->gmc.xgmi.num_physical_nodes > 1)
+	if (adev->gmc.xgmi.num_physical_nodes > 1) {
+		struct amdgpu_hive_info *hive;
+
 		amdgpu_xgmi_add_device(adev);
 
+		hive = amdgpu_get_xgmi_hive(adev);
+		if (!hive || !hive->reset_domain.wq) {
+			DRM_ERROR("Failed to obtain reset domain info for XGMI hive:%llx", hive->hive_id);
+			r = -EINVAL;
+			goto init_failed;
+		}
+
+		adev->reset_domain.wq = hive->reset_domain.wq;
+	} else {
+		adev->reset_domain.wq = alloc_ordered_workqueue("amdgpu-reset-dev", 0);
+		if (!adev->reset_domain.wq) {
+			r = -ENOMEM;
+			goto init_failed;
+		}
+	}
+
 	/* Don't init kfd if whole hive need to be reset during init */
 	if (!adev->gmc.xgmi.pending_reset)
 		amdgpu_amdkfd_device_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +9 -0
index e8b8f28c2f72..d406897346d6 100644
@@ -398,6 +398,14 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 		goto pro_end;
 	}
 
+	hive->reset_domain.wq = alloc_ordered_workqueue("amdgpu-reset-hive", 0);
+	if (!hive->reset_domain.wq) {
+		dev_err(adev->dev, "XGMI: failed allocating wq for reset domain!\n");
+		kfree(hive);
+		hive = NULL;
+		goto pro_end;
+	}
+
 	hive->hive_id = adev->gmc.xgmi.hive_id;
 	INIT_LIST_HEAD(&hive->device_list);
 	INIT_LIST_HEAD(&hive->node);
@@ -407,6 +415,7 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 	task_barrier_init(&hive->tb);
 	hive->pstate = AMDGPU_XGMI_PSTATE_UNKNOWN;
 	hive->hi_req_gpu = NULL;
+
 	/*
 	 * hive pstate on boot is high in vega20 so we have to go to low
 	 * pstate on after boot.
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +2 -0
index d2189bf7d428..6121aaa292cb 100644
@@ -42,6 +42,8 @@ struct amdgpu_hive_info {
 		AMDGPU_XGMI_PSTATE_MAX_VEGA20,
 		AMDGPU_XGMI_PSTATE_UNKNOWN
 	} pstate;
+
+	struct amdgpu_reset_domain reset_domain;
 };
 
 struct amdgpu_pcs_ras_field {
Signature · 1 line
2.25.1
#2 lore raw

RFC v4 2/11 drm/amdgpu: Move scheduler init to after XGMI is ready

In reply to Andrey Grodzovsky

Before we initialize schedulers we must know which reset domain are we in - for single device there iis a single domain per device and so single wq per device. For XGMI the reset domain spans the entire XGMI hive and so the reset wq is per hive.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 45 ++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 34 ++--------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h   |  2 +
 3 files changed, 51 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +45 -0
index 9704b0e1fd82..00123b0013d3 100644
@@ -2287,6 +2287,47 @@ static int amdgpu_device_fw_loading(struct amdgpu_device *adev)
 	return r;
 }
 
+static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
+{
+	long timeout;
+	int r, i;
+
+	for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+		struct amdgpu_ring *ring = adev->rings[i];
+
+		/* No need to setup the GPU scheduler for rings that don't need it */
+		if (!ring || ring->no_scheduler)
+			continue;
+
+		switch (ring->funcs->type) {
+		case AMDGPU_RING_TYPE_GFX:
+			timeout = adev->gfx_timeout;
+			break;
+		case AMDGPU_RING_TYPE_COMPUTE:
+			timeout = adev->compute_timeout;
+			break;
+		case AMDGPU_RING_TYPE_SDMA:
+			timeout = adev->sdma_timeout;
+			break;
+		default:
+			timeout = adev->video_timeout;
+			break;
+		}
+
+		r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
+				   ring->num_hw_submission, amdgpu_job_hang_limit,
+				   timeout, adev->reset_domain.wq, ring->sched_score, ring->name);
+		if (r) {
+			DRM_ERROR("Failed to create scheduler on ring %s.\n",
+				  ring->name);
+			return r;
+		}
+	}
+
+	return 0;
+}
+
+
 /**
  * amdgpu_device_ip_init - run init for hardware IPs
  *
@@ -2419,6 +2460,10 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
 		}
 	}
 
+	r = amdgpu_device_init_schedulers(adev);
+	if (r)
+		goto init_failed;
+
 	/* Don't init kfd if whole hive need to be reset during init */
 	if (!adev->gmc.xgmi.pending_reset)
 		amdgpu_amdkfd_device_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +4 -30
index 45977a72b5dd..fa302540c69a 100644
@@ -457,8 +457,6 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
 				  atomic_t *sched_score)
 {
 	struct amdgpu_device *adev = ring->adev;
-	long timeout;
-	int r;
 
 	if (!adev)
 		return -EINVAL;
@@ -478,36 +476,12 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
 	spin_lock_init(&ring->fence_drv.lock);
 	ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
 					 GFP_KERNEL);
-	if (!ring->fence_drv.fences)
-		return -ENOMEM;
 
-	/* No need to setup the GPU scheduler for rings that don't need it */
-	if (ring->no_scheduler)
-		return 0;
+	ring->num_hw_submission = num_hw_submission;
+	ring->sched_score = sched_score;
 
-	switch (ring->funcs->type) {
-	case AMDGPU_RING_TYPE_GFX:
-		timeout = adev->gfx_timeout;
-		break;
-	case AMDGPU_RING_TYPE_COMPUTE:
-		timeout = adev->compute_timeout;
-		break;
-	case AMDGPU_RING_TYPE_SDMA:
-		timeout = adev->sdma_timeout;
-		break;
-	default:
-		timeout = adev->video_timeout;
-		break;
-	}
-
-	r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
-			   num_hw_submission, amdgpu_job_hang_limit,
-			   timeout, NULL, sched_score, ring->name);
-	if (r) {
-		DRM_ERROR("Failed to create scheduler on ring %s.\n",
-			  ring->name);
-		return r;
-	}
+	if (!ring->fence_drv.fences)
+		return -ENOMEM;
 
 	return 0;
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
index fae7d185ad0d..7f20ce73a243 100644
@@ -251,6 +251,8 @@ struct amdgpu_ring {
 	bool			has_compute_vm_bug;
 	bool			no_scheduler;
 	int			hw_prio;
+	unsigned 		num_hw_submission;
+	atomic_t		*sched_score;
 };
 
 #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
Signature · 1 line
2.25.1
#3 lore raw

Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 7 lines

Before we initialize schedulers we must know which reset domain are we in - for single device there iis a single domain per device and so single wq per device. For XGMI the reset domain spans the entire XGMI hive and so the reset wq is per hive.

One more comment below, with that fixed Reviewed-by: Christian König <[email protected]>.

Quoted 84 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 45 ++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 34 ++--------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h   |  2 +
  3 files changed, 51 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +45 -0
index 9704b0e1fd82..00123b0013d3 100644
@@ -2287,6 +2287,47 @@ static int amdgpu_device_fw_loading(struct amdgpu_device *adev)
  	return r;
  }
 
+static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
+{
+	long timeout;
+	int r, i;
+
+	for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+		struct amdgpu_ring *ring = adev->rings[i];
+
+		/* No need to setup the GPU scheduler for rings that don't need it */
+		if (!ring || ring->no_scheduler)
+			continue;
+
+		switch (ring->funcs->type) {
+		case AMDGPU_RING_TYPE_GFX:
+			timeout = adev->gfx_timeout;
+			break;
+		case AMDGPU_RING_TYPE_COMPUTE:
+			timeout = adev->compute_timeout;
+			break;
+		case AMDGPU_RING_TYPE_SDMA:
+			timeout = adev->sdma_timeout;
+			break;
+		default:
+			timeout = adev->video_timeout;
+			break;
+		}
+
+		r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
+				   ring->num_hw_submission, amdgpu_job_hang_limit,
+				   timeout, adev->reset_domain.wq, ring->sched_score, ring->name);
+		if (r) {
+			DRM_ERROR("Failed to create scheduler on ring %s.\n",
+				  ring->name);
+			return r;
+		}
+	}
+
+	return 0;
+}
+
+
  /**
   * amdgpu_device_ip_init - run init for hardware IPs
   *
@@ -2419,6 +2460,10 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
  		}
  	}
 
+	r = amdgpu_device_init_schedulers(adev);
+	if (r)
+		goto init_failed;
+
  	/* Don't init kfd if whole hive need to be reset during init */
  	if (!adev->gmc.xgmi.pending_reset)
  		amdgpu_amdkfd_device_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -2
index 45977a72b5dd..fa302540c69a 100644
@@ -457,8 +457,6 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
  				  atomic_t *sched_score)
  {
  	struct amdgpu_device *adev = ring->adev;
-	long timeout;
-	int r;
 
  	if (!adev)
  		return -EINVAL;
@@ -478,36 +476,12 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
  	spin_lock_init(&ring->fence_drv.lock);

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring, · line 481

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -5
  	ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
  					 GFP_KERNEL);
-	if (!ring->fence_drv.fences)
-		return -ENOMEM;
 
-	/* No need to setup the GPU scheduler for rings that don't need it */
-	if (ring->no_scheduler)
-		return 0;
+	ring->num_hw_submission = num_hw_submission;
+	ring->sched_score = sched_score;

Let's move this into the caller and then use ring->num_hw_submission in the fence code as well.

The maximum number of jobs on the ring is not really fence specific.

Regards,
Christian.

Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -23
-	switch (ring->funcs->type) {
-	case AMDGPU_RING_TYPE_GFX:
-		timeout = adev->gfx_timeout;
-		break;
-	case AMDGPU_RING_TYPE_COMPUTE:
-		timeout = adev->compute_timeout;
-		break;
-	case AMDGPU_RING_TYPE_SDMA:
-		timeout = adev->sdma_timeout;
-		break;
-	default:
-		timeout = adev->video_timeout;
-		break;
-	}
-
-	r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
-			   num_hw_submission, amdgpu_job_hang_limit,
-			   timeout, NULL, sched_score, ring->name);
-	if (r) {
-		DRM_ERROR("Failed to create scheduler on ring %s.\n",
-			  ring->name);
-		return r;
-	}
+	if (!ring->fence_drv.fences)
+		return -ENOMEM;
 
  	return 0;
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
index fae7d185ad0d..7f20ce73a243 100644
@@ -251,6 +251,8 @@ struct amdgpu_ring {
  	bool			has_compute_vm_bug;
  	bool			no_scheduler;
  	int			hw_prio;
+	unsigned 		num_hw_submission;
+	atomic_t		*sched_score;
  };
 
  #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
#4 lore raw

Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready

All comments are fixed and code pushed. Thanks for everyone who helped reviewing.

Andrey

Quoted 155 lines · Christian König

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 7 lines

Before we initialize schedulers we must know which reset domain are we in - for single device there iis a single domain per device and so single wq per device. For XGMI the reset domain spans the entire XGMI hive and so the reset wq is per hive.

One more comment below, with that fixed Reviewed-by: Christian König <[email protected]>.

Quoted 91 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 45 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 34 ++-------------- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h   |  2 +

  3 files changed, 51 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8 -0
index 9704b0e1fd82..00123b0013d3 100644
@@ -2287,6 +2287,47 @@ static int amdgpu_device_fw_loading(struct 
 amdgpu_device *adev)
       return r;
   }
   +static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
+{
+    long timeout;
+    int r, i;
+
+    for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+        struct amdgpu_ring *ring = adev->rings[i];
+
+        /* No need to setup the GPU scheduler for rings that don't 

need it */
+        if (!ring || ring->no_scheduler)
+            continue;

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +19 -0
+
+        switch (ring->funcs->type) {
+        case AMDGPU_RING_TYPE_GFX:
+            timeout = adev->gfx_timeout;
+            break;
+        case AMDGPU_RING_TYPE_COMPUTE:
+            timeout = adev->compute_timeout;
+            break;
+        case AMDGPU_RING_TYPE_SDMA:
+            timeout = adev->sdma_timeout;
+            break;
+        default:
+            timeout = adev->video_timeout;
+            break;
+        }
+
+        r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
+                   ring->num_hw_submission, amdgpu_job_hang_limit,
+                   timeout, adev->reset_domain.wq, 

ring->sched_score, ring->name);
+        if (r) {
+            DRM_ERROR("Failed to create scheduler on ring %s.\n", +                  ring->name);
+            return r;
+        }
+    }

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -0
+
+    return 0;
+}
+
+

  /**
   * amdgpu_device_ip_init - run init for hardware IPs *

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
@@ -2419,6 +2460,10 @@ static int amdgpu_device_ip_init(struct 
 amdgpu_device *adev)
           }
       }
   +    r = amdgpu_device_init_schedulers(adev);
+    if (r)
+        goto init_failed;
+
       /* Don't init kfd if whole hive need to be reset during init */
       if (!adev->gmc.xgmi.pending_reset)

          amdgpu_amdkfd_device_init(adev);

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -4
index 45977a72b5dd..fa302540c69a 100644
@@ -457,8 +457,6 @@ int amdgpu_fence_driver_init_ring(struct 
 amdgpu_ring *ring,
                     atomic_t *sched_score)
   {
       struct amdgpu_device *adev = ring->adev;
-    long timeout;
-    int r;
         if (!adev)
           return -EINVAL;
@@ -478,36 +476,12 @@ int amdgpu_fence_driver_init_ring(struct 
 amdgpu_ring *ring,
       spin_lock_init(&ring->fence_drv.lock);
       ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
                        GFP_KERNEL);
-    if (!ring->fence_drv.fences)
-        return -ENOMEM;
Quoted 5 lines

  -    /* No need to setup the GPU scheduler for rings that don't need it */ -    if (ring->no_scheduler)
-        return 0;
+    ring->num_hw_submission = num_hw_submission;
+    ring->sched_score = sched_score;

Let's move this into the caller and then use ring->num_hw_submission in the fence code as well.

The maximum number of jobs on the ring is not really fence specific.

Regards,
Christian.

Quoted 39 lines

  -    switch (ring->funcs->type) {
-    case AMDGPU_RING_TYPE_GFX:
-        timeout = adev->gfx_timeout;
-        break;
-    case AMDGPU_RING_TYPE_COMPUTE:
-        timeout = adev->compute_timeout;
-        break;
-    case AMDGPU_RING_TYPE_SDMA:
-        timeout = adev->sdma_timeout;
-        break;
-    default:
-        timeout = adev->video_timeout;
-        break;
-    }
-
-    r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, -               num_hw_submission, amdgpu_job_hang_limit, -               timeout, NULL, sched_score, ring->name); -    if (r) {
-        DRM_ERROR("Failed to create scheduler on ring %s.\n", -              ring->name);
-        return r;
-    }
+    if (!ring->fence_drv.fences)
+        return -ENOMEM;
        return 0;
  }

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
index fae7d185ad0d..7f20ce73a243 100644
@@ -251,6 +251,8 @@ struct amdgpu_ring {
       bool            has_compute_vm_bug;
       bool            no_scheduler;
       int            hw_prio;
+    unsigned         num_hw_submission;
+    atomic_t        *sched_score;
   };
     #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
#5 lore raw

Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready

Hi Andrey,

Will you port this patch into amd-staging-drm-next?

Quoted 155 lines · Andrey Grodzovsky

All comments are fixed and code pushed. Thanks for everyone who helped reviewing.

Andrey

Quoted 149 lines · Christian König

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 7 lines

Before we initialize schedulers we must know which reset domain are we in - for single device there iis a single domain per device and so single wq per device. For XGMI the reset domain spans the entire XGMI hive and so the reset wq is per hive.

One more comment below, with that fixed Reviewed-by: Christian König <[email protected]>.

Quoted 85 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 45 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 34 ++-------------- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h   |  2 +

  3 files changed, 51 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +43 -0
index 9704b0e1fd82..00123b0013d3 100644
@@ -2287,6 +2287,47 @@ static int amdgpu_device_fw_loading(struct amdgpu_device *adev)
       return r;
   }
   +static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
+{
+    long timeout;
+    int r, i;
+
+    for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+        struct amdgpu_ring *ring = adev->rings[i];
+
+        /* No need to setup the GPU scheduler for rings that don't need it */
+        if (!ring || ring->no_scheduler)
+            continue;
+
+        switch (ring->funcs->type) {
+        case AMDGPU_RING_TYPE_GFX:
+            timeout = adev->gfx_timeout;
+            break;
+        case AMDGPU_RING_TYPE_COMPUTE:
+            timeout = adev->compute_timeout;
+            break;
+        case AMDGPU_RING_TYPE_SDMA:
+            timeout = adev->sdma_timeout;
+            break;
+        default:
+            timeout = adev->video_timeout;
+            break;
+        }
+
+        r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
+                   ring->num_hw_submission, amdgpu_job_hang_limit,
+                   timeout, adev->reset_domain.wq, ring->sched_score, ring->name);
+        if (r) {
+            DRM_ERROR("Failed to create scheduler on ring %s.\n",
+                  ring->name);
+            return r;
+        }
+    }
+
+    return 0;
+}
+
+
   /**
    * amdgpu_device_ip_init - run init for hardware IPs
    *
@@ -2419,6 +2460,10 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
           }
       }
   +    r = amdgpu_device_init_schedulers(adev);
+    if (r)
+        goto init_failed;
+
       /* Don't init kfd if whole hive need to be reset during init */
       if (!adev->gmc.xgmi.pending_reset)
           amdgpu_amdkfd_device_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -4
index 45977a72b5dd..fa302540c69a 100644
@@ -457,8 +457,6 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
                     atomic_t *sched_score)
   {
       struct amdgpu_device *adev = ring->adev;
-    long timeout;
-    int r;
         if (!adev)
           return -EINVAL;
@@ -478,36 +476,12 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
       spin_lock_init(&ring->fence_drv.lock);
       ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
                        GFP_KERNEL);
-    if (!ring->fence_drv.fences)
-        return -ENOMEM;
Quoted 5 lines

  -    /* No need to setup the GPU scheduler for rings that don't need it */ -    if (ring->no_scheduler)
-        return 0;
+    ring->num_hw_submission = num_hw_submission;
+    ring->sched_score = sched_score;

Let's move this into the caller and then use ring->num_hw_submission in the fence code as well.

The maximum number of jobs on the ring is not really fence specific.

Regards,
Christian.

Quoted 39 lines

  -    switch (ring->funcs->type) {
-    case AMDGPU_RING_TYPE_GFX:
-        timeout = adev->gfx_timeout;
-        break;
-    case AMDGPU_RING_TYPE_COMPUTE:
-        timeout = adev->compute_timeout;
-        break;
-    case AMDGPU_RING_TYPE_SDMA:
-        timeout = adev->sdma_timeout;
-        break;
-    default:
-        timeout = adev->video_timeout;
-        break;
-    }
-
-    r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, -               num_hw_submission, amdgpu_job_hang_limit, -               timeout, NULL, sched_score, ring->name); -    if (r) {
-        DRM_ERROR("Failed to create scheduler on ring %s.\n", -              ring->name);
-        return r;
-    }
+    if (!ring->fence_drv.fences)
+        return -ENOMEM;
        return 0;
  }

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
index fae7d185ad0d..7f20ce73a243 100644
@@ -251,6 +251,8 @@ struct amdgpu_ring {
       bool            has_compute_vm_bug;
       bool            no_scheduler;
       int            hw_prio;
+    unsigned         num_hw_submission;
+    atomic_t        *sched_score;
   };
     #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
#6 lore raw

Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready

No because all the patch-set including this patch was landed into drm-misc-next and will reach amd-staging-drm-next on the next upstream rebase i guess.

Andrey

Quoted 157 lines · JingWen Chen

Hi Andrey,

Will you port this patch into amd-staging-drm-next?

Quoted 152 lines · Andrey Grodzovsky

All comments are fixed and code pushed. Thanks for everyone who helped reviewing.

Andrey

Quoted 146 lines · Christian König

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 7 lines

Before we initialize schedulers we must know which reset domain are we in - for single device there iis a single domain per device and so single wq per device. For XGMI the reset domain spans the entire XGMI hive and so the reset wq is per hive.

One more comment below, with that fixed Reviewed-by: Christian König <[email protected]>.

Quoted 80 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 45 ++++++++++++++++++++++
   drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 34 ++--------------
   drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h   |  2 +
   3 files changed, 51 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +43 -0
index 9704b0e1fd82..00123b0013d3 100644
@@ -2287,6 +2287,47 @@ static int amdgpu_device_fw_loading(struct amdgpu_device *adev)
       return r;
   }
   +static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
+{
+    long timeout;
+    int r, i;
+
+    for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+        struct amdgpu_ring *ring = adev->rings[i];
+
+        /* No need to setup the GPU scheduler for rings that don't need it */
+        if (!ring || ring->no_scheduler)
+            continue;
+
+        switch (ring->funcs->type) {
+        case AMDGPU_RING_TYPE_GFX:
+            timeout = adev->gfx_timeout;
+            break;
+        case AMDGPU_RING_TYPE_COMPUTE:
+            timeout = adev->compute_timeout;
+            break;
+        case AMDGPU_RING_TYPE_SDMA:
+            timeout = adev->sdma_timeout;
+            break;
+        default:
+            timeout = adev->video_timeout;
+            break;
+        }
+
+        r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
+                   ring->num_hw_submission, amdgpu_job_hang_limit,
+                   timeout, adev->reset_domain.wq, ring->sched_score, ring->name);
+        if (r) {
+            DRM_ERROR("Failed to create scheduler on ring %s.\n",
+                  ring->name);
+            return r;
+        }
+    }
+
+    return 0;
+}
+
+
   /**
    * amdgpu_device_ip_init - run init for hardware IPs
    *
@@ -2419,6 +2460,10 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
           }
       }
   +    r = amdgpu_device_init_schedulers(adev);
+    if (r)
+        goto init_failed;
+
       /* Don't init kfd if whole hive need to be reset during init */
       if (!adev->gmc.xgmi.pending_reset)
           amdgpu_amdkfd_device_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -2
index 45977a72b5dd..fa302540c69a 100644
@@ -457,8 +457,6 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
                     atomic_t *sched_score)
   {
       struct amdgpu_device *adev = ring->adev;
-    long timeout;
-    int r;
         if (!adev)
           return -EINVAL;

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring, · line 481

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -4
@@ -478,36 +476,12 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
       spin_lock_init(&ring->fence_drv.lock);
       ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
                        GFP_KERNEL);
-    if (!ring->fence_drv.fences)
-        return -ENOMEM;
   -    /* No need to setup the GPU scheduler for rings that don't need it */
-    if (ring->no_scheduler)
-        return 0;
+    ring->num_hw_submission = num_hw_submission;
+    ring->sched_score = sched_score;

Let's move this into the caller and then use ring->num_hw_submission in the fence code as well.

The maximum number of jobs on the ring is not really fence specific.

Regards,
Christian.

Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -22
   -    switch (ring->funcs->type) {
-    case AMDGPU_RING_TYPE_GFX:
-        timeout = adev->gfx_timeout;
-        break;
-    case AMDGPU_RING_TYPE_COMPUTE:
-        timeout = adev->compute_timeout;
-        break;
-    case AMDGPU_RING_TYPE_SDMA:
-        timeout = adev->sdma_timeout;
-        break;
-    default:
-        timeout = adev->video_timeout;
-        break;
-    }
-
-    r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
-               num_hw_submission, amdgpu_job_hang_limit,
-               timeout, NULL, sched_score, ring->name);
-    if (r) {
-        DRM_ERROR("Failed to create scheduler on ring %s.\n",
-              ring->name);
-        return r;
-    }
+    if (!ring->fence_drv.fences)
+        return -ENOMEM;
         return 0;
   }
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
index fae7d185ad0d..7f20ce73a243 100644
@@ -251,6 +251,8 @@ struct amdgpu_ring {
       bool            has_compute_vm_bug;
       bool            no_scheduler;
       int            hw_prio;
+    unsigned         num_hw_submission;
+    atomic_t        *sched_score;
   };
     #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
#7 lore raw

Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready

[Public]

If it applies cleanly, feel free to drop it in. I'll drop those patches for drm-next since they are already in drm-misc.

Alex

________________________________
From: amd-gfx <[email protected]> on behalf of Andrey Grodzovsky <[email protected]>
Sent: Thursday, February 24, 2022 11:24 AM
To: Chen, JingWen <[email protected]>; Christian König <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Cc: Liu, Monk <[email protected]>; Chen, Horace <[email protected]>; Lazar, Lijo <[email protected]>; Koenig, Christian <[email protected]>; [email protected] <[email protected]>
Subject: Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready

No because all the patch-set including this patch was landed into drm-misc-next and will reach amd-staging-drm-next on the next upstream rebase i guess.

Andrey

Quoted 157 lines · JingWen Chen

Hi Andrey,

Will you port this patch into amd-staging-drm-next?

Quoted 152 lines · Andrey Grodzovsky

All comments are fixed and code pushed. Thanks for everyone who helped reviewing.

Andrey

Quoted 146 lines · Christian König

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 7 lines

Before we initialize schedulers we must know which reset domain are we in - for single device there iis a single domain per device and so single wq per device. For XGMI the reset domain spans the entire XGMI hive and so the reset wq is per hive.

One more comment below, with that fixed Reviewed-by: Christian König <[email protected]>.

Quoted 80 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 45 ++++++++++++++++++++++
   drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 34 ++--------------
   drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h   |  2 +
   3 files changed, 51 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +43 -0
index 9704b0e1fd82..00123b0013d3 100644
@@ -2287,6 +2287,47 @@ static int amdgpu_device_fw_loading(struct amdgpu_device *adev)
       return r;
   }
   +static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
+{
+    long timeout;
+    int r, i;
+
+    for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+        struct amdgpu_ring *ring = adev->rings[i];
+
+        /* No need to setup the GPU scheduler for rings that don't need it */
+        if (!ring || ring->no_scheduler)
+            continue;
+
+        switch (ring->funcs->type) {
+        case AMDGPU_RING_TYPE_GFX:
+            timeout = adev->gfx_timeout;
+            break;
+        case AMDGPU_RING_TYPE_COMPUTE:
+            timeout = adev->compute_timeout;
+            break;
+        case AMDGPU_RING_TYPE_SDMA:
+            timeout = adev->sdma_timeout;
+            break;
+        default:
+            timeout = adev->video_timeout;
+            break;
+        }
+
+        r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
+                   ring->num_hw_submission, amdgpu_job_hang_limit,
+                   timeout, adev->reset_domain.wq, ring->sched_score, ring->name);
+        if (r) {
+            DRM_ERROR("Failed to create scheduler on ring %s.\n",
+                  ring->name);
+            return r;
+        }
+    }
+
+    return 0;
+}
+
+
   /**
    * amdgpu_device_ip_init - run init for hardware IPs
    *
@@ -2419,6 +2460,10 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
           }
       }
   +    r = amdgpu_device_init_schedulers(adev);
+    if (r)
+        goto init_failed;
+
       /* Don't init kfd if whole hive need to be reset during init */
       if (!adev->gmc.xgmi.pending_reset)
           amdgpu_amdkfd_device_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -2
index 45977a72b5dd..fa302540c69a 100644
@@ -457,8 +457,6 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
                     atomic_t *sched_score)
   {
       struct amdgpu_device *adev = ring->adev;
-    long timeout;
-    int r;
         if (!adev)
           return -EINVAL;

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring, · line 481

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -4
@@ -478,36 +476,12 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
       spin_lock_init(&ring->fence_drv.lock);
       ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
                        GFP_KERNEL);
-    if (!ring->fence_drv.fences)
-        return -ENOMEM;
   -    /* No need to setup the GPU scheduler for rings that don't need it */
-    if (ring->no_scheduler)
-        return 0;
+    ring->num_hw_submission = num_hw_submission;
+    ring->sched_score = sched_score;

Let's move this into the caller and then use ring->num_hw_submission in the fence code as well.

The maximum number of jobs on the ring is not really fence specific.

Regards,
Christian.

Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -22
   -    switch (ring->funcs->type) {
-    case AMDGPU_RING_TYPE_GFX:
-        timeout = adev->gfx_timeout;
-        break;
-    case AMDGPU_RING_TYPE_COMPUTE:
-        timeout = adev->compute_timeout;
-        break;
-    case AMDGPU_RING_TYPE_SDMA:
-        timeout = adev->sdma_timeout;
-        break;
-    default:
-        timeout = adev->video_timeout;
-        break;
-    }
-
-    r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
-               num_hw_submission, amdgpu_job_hang_limit,
-               timeout, NULL, sched_score, ring->name);
-    if (r) {
-        DRM_ERROR("Failed to create scheduler on ring %s.\n",
-              ring->name);
-        return r;
-    }
+    if (!ring->fence_drv.fences)
+        return -ENOMEM;
         return 0;
   }
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
index fae7d185ad0d..7f20ce73a243 100644
@@ -251,6 +251,8 @@ struct amdgpu_ring {
       bool            has_compute_vm_bug;
       bool            no_scheduler;
       int            hw_prio;
+    unsigned         num_hw_submission;
+    atomic_t        *sched_score;
   };
     #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
#8 lore raw

Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready

No problem if so but before I do,

JingWen - why you think this patch is needed as a standalone now ? It has no use without the entire feature together with it. Is it some changes you want to do on top of that code ?

Andrey

Quoted 195 lines · Alexander

[Public]

If it applies cleanly, feel free to drop it in.  I'll drop those patches for drm-next since they are already in drm-misc.

Alex

------------------------------------------------------------------------
*From:* amd-gfx <[email protected]> on behalf of Andrey Grodzovsky <[email protected]>
*Sent:* Thursday, February 24, 2022 11:24 AM
*To:* Chen, JingWen <[email protected]>; Christian König <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> *Cc:* Liu, Monk <[email protected]>; Chen, Horace <[email protected]>; Lazar, Lijo <[email protected]>; Koenig, Christian <[email protected]>; [email protected] <[email protected]> *Subject:* Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready
No because all the patch-set including this patch was landed into
drm-misc-next and will reach amd-staging-drm-next on the next upstream
rebase i guess.

Andrey

Quoted 20 lines · JingWen Chen

Hi Andrey,

Will you port this patch into amd-staging-drm-next?

Quoted 15 lines · Andrey Grodzovsky

All comments are fixed and code pushed. Thanks for everyone who helped reviewing.

Andrey

Quoted 9 lines · Christian König

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 7 lines

Before we initialize schedulers we must know which reset domain are we in - for single device there iis a single domain per device and so single wq per device. For XGMI the reset domain spans the entire XGMI hive and so the reset wq is per hive.

One more comment below, with that fixed Reviewed-by: Christian

König <[email protected]>.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 45

++++++++++++++++++++++

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 5 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 34 ++-------------- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h   |  2 +

    3 files changed, 51 insertions(+), 30 deletions(-)
(quoted diff) +0 -0

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

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_fw_loading(struct

Quoted 4 lines

index 9704b0e1fd82..00123b0013d3 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
@@ -2287,6 +2287,47 @@ static int amdgpu_device_fw_loading(struct 

amdgpu_device *adev)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
         return r;
     }

    +static int amdgpu_device_init_schedulers(struct amdgpu_device

*adev)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_fw_loading(struct amdgpu_device *adev)

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8 -0
+{
+    long timeout;
+    int r, i;
+
+    for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+        struct amdgpu_ring *ring = adev->rings[i];
+
+        /* No need to setup the GPU scheduler for rings that 

don't need it */

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

+        if (!ring || ring->no_scheduler)
+            continue;
+
+        switch (ring->funcs->type) {
+        case AMDGPU_RING_TYPE_GFX:
+            timeout = adev->gfx_timeout;
+            break;
+        case AMDGPU_RING_TYPE_COMPUTE:
+            timeout = adev->compute_timeout;
+            break;
+        case AMDGPU_RING_TYPE_SDMA:
+            timeout = adev->sdma_timeout;
+            break;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

+        default:
+            timeout = adev->video_timeout;
+            break;
+        }
+
+        r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
+ ring->num_hw_submission, amdgpu_job_hang_limit, +                   timeout, adev->reset_domain.wq,

ring->sched_score, ring->name);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

+        if (r) {
+            DRM_ERROR("Failed to create scheduler on ring %s.\n", +                  ring->name);
+            return r;
+        }
+    }
+

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_init(struct

Quoted 8 lines

+    return 0;

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
+}
+
+

    /**
     * amdgpu_device_ip_init - run init for hardware IPs *

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
@@ -2419,6 +2460,10 @@ static int amdgpu_device_ip_init(struct 

amdgpu_device *adev)

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_init(struct amdgpu_device *adev)

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
             }
         }
     +    r = amdgpu_device_init_schedulers(adev);
+    if (r)
+        goto init_failed;
+
         /* Don't init kfd if whole hive need to be reset during 

init */

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
         if (!adev->gmc.xgmi.pending_reset)
 amdgpu_amdkfd_device_init(adev);
(quoted diff) +0 -0

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

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_init_ring(struct

Quoted 4 lines

index 45977a72b5dd..fa302540c69a 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
@@ -457,8 +457,6 @@ int amdgpu_fence_driver_init_ring(struct 

amdgpu_ring *ring,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_init_ring(struct

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -2
                       atomic_t *sched_score)
     {
         struct amdgpu_device *adev = ring->adev;
-    long timeout;
-    int r;
           if (!adev)
             return -EINVAL;
@@ -478,36 +476,12 @@ int amdgpu_fence_driver_init_ring(struct 

amdgpu_ring *ring,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_init_ring(struct · line 477

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
 spin_lock_init(&ring->fence_drv.lock);
         ring->fence_drv.fences = kcalloc(num_hw_submission * 2, 

sizeof(void *),

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -2
                          GFP_KERNEL);
-    if (!ring->fence_drv.fences)
-        return -ENOMEM;

    -    /* No need to setup the GPU scheduler for rings that

don't need it */

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

-    if (ring->no_scheduler)
-        return 0;
+    ring->num_hw_submission = num_hw_submission;
+    ring->sched_score = sched_score;

Let's move this into the caller and then use

ring->num_hw_submission in the fence code as well.

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines

The maximum number of jobs on the ring is not really fence specific.

Regards,
Christian.

Quoted 20 lines

    -    switch (ring->funcs->type) {
-    case AMDGPU_RING_TYPE_GFX:
-        timeout = adev->gfx_timeout;
-        break;
-    case AMDGPU_RING_TYPE_COMPUTE:
-        timeout = adev->compute_timeout;
-        break;
-    case AMDGPU_RING_TYPE_SDMA:
-        timeout = adev->sdma_timeout;
-        break;
-    default:
-        timeout = adev->video_timeout;
-        break;
-    }
-
-    r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, -               num_hw_submission, amdgpu_job_hang_limit, -               timeout, NULL, sched_score, ring->name); -    if (r) {
-        DRM_ERROR("Failed to create scheduler on ring %s.\n",

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines

-              ring->name);
-        return r;
-    }
+    if (!ring->fence_drv.fences)
+        return -ENOMEM;
          return 0;
    }

(quoted diff) +0 -0

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

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h struct amdgpu_ring { · line 257

Quoted 11 lines

index fae7d185ad0d..7f20ce73a243 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
@@ -251,6 +251,8 @@ struct amdgpu_ring {
         bool has_compute_vm_bug;
         bool            no_scheduler;
         int            hw_prio;
+    unsigned num_hw_submission;
+    atomic_t        *sched_score;
     };
       #define amdgpu_ring_parse_cs(r, p, ib) 

((r)->funcs->parse_cs((p), (ib)))

#9 lore raw

Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready

Hi Andrey,

Sorry for the misleading, I mean the whole patch series. We are depending on this patch series to fix the concurrency issue within SRIOV TDR sequence.

Quoted 189 lines · Andrey Grodzovsky

No problem if so but before I do,

JingWen - why you think this patch is needed as a standalone now ? It has no use without the entire feature together with it. Is it some changes you want to do on top of that code ?

Andrey

Quoted 178 lines · Alexander

[Public]

If it applies cleanly, feel free to drop it in.  I'll drop those patches for drm-next since they are already in drm-misc.

Alex

------------------------------------------------------------------------
*From:* amd-gfx <[email protected]> on behalf of Andrey Grodzovsky <[email protected]>
*Sent:* Thursday, February 24, 2022 11:24 AM
*To:* Chen, JingWen <[email protected]>; Christian König <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> *Cc:* Liu, Monk <[email protected]>; Chen, Horace <[email protected]>; Lazar, Lijo <[email protected]>; Koenig, Christian <[email protected]>; [email protected] <[email protected]> *Subject:* Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready
No because all the patch-set including this patch was landed into
drm-misc-next and will reach amd-staging-drm-next on the next upstream
rebase i guess.

Andrey

Quoted 157 lines · JingWen Chen

Hi Andrey,

Will you port this patch into amd-staging-drm-next?

Quoted 152 lines · Andrey Grodzovsky

All comments are fixed and code pushed. Thanks for everyone who helped reviewing.

Andrey

Quoted 146 lines · Christian König

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 7 lines

Before we initialize schedulers we must know which reset domain are we in - for single device there iis a single domain per device and so single wq per device. For XGMI the reset domain spans the entire XGMI hive and so the reset wq is per hive.

One more comment below, with that fixed Reviewed-by: Christian König <[email protected]>.

Quoted 85 lines

---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 45 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 34 ++-------------- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h   |  2 +

    3 files changed, 51 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +43 -0
index 9704b0e1fd82..00123b0013d3 100644
@@ -2287,6 +2287,47 @@ static int amdgpu_device_fw_loading(struct amdgpu_device *adev)
         return r;
     }
     +static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
+{
+    long timeout;
+    int r, i;
+
+    for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+        struct amdgpu_ring *ring = adev->rings[i];
+
+        /* No need to setup the GPU scheduler for rings that don't need it */
+        if (!ring || ring->no_scheduler)
+            continue;
+
+        switch (ring->funcs->type) {
+        case AMDGPU_RING_TYPE_GFX:
+            timeout = adev->gfx_timeout;
+            break;
+        case AMDGPU_RING_TYPE_COMPUTE:
+            timeout = adev->compute_timeout;
+            break;
+        case AMDGPU_RING_TYPE_SDMA:
+            timeout = adev->sdma_timeout;
+            break;
+        default:
+            timeout = adev->video_timeout;
+            break;
+        }
+
+        r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
+ ring->num_hw_submission, amdgpu_job_hang_limit,
+                   timeout, adev->reset_domain.wq, ring->sched_score, ring->name);
+        if (r) {
+            DRM_ERROR("Failed to create scheduler on ring %s.\n",
+                  ring->name);
+            return r;
+        }
+    }
+
+    return 0;
+}
+
+
     /**
      * amdgpu_device_ip_init - run init for hardware IPs
      *
@@ -2419,6 +2460,10 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
             }
         }
     +    r = amdgpu_device_init_schedulers(adev);
+    if (r)
+        goto init_failed;
+
         /* Don't init kfd if whole hive need to be reset during init */
         if (!adev->gmc.xgmi.pending_reset)
 amdgpu_amdkfd_device_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -4
index 45977a72b5dd..fa302540c69a 100644
@@ -457,8 +457,6 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
                       atomic_t *sched_score)
     {
         struct amdgpu_device *adev = ring->adev;
-    long timeout;
-    int r;
           if (!adev)
             return -EINVAL;
@@ -478,36 +476,12 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
 spin_lock_init(&ring->fence_drv.lock);
         ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
                          GFP_KERNEL);
-    if (!ring->fence_drv.fences)
-        return -ENOMEM;
Quoted 5 lines

    -    /* No need to setup the GPU scheduler for rings that don't need it */ -    if (ring->no_scheduler)
-        return 0;
+    ring->num_hw_submission = num_hw_submission;
+    ring->sched_score = sched_score;

Let's move this into the caller and then use ring->num_hw_submission in the fence code as well.

The maximum number of jobs on the ring is not really fence specific.

Regards,
Christian.

Quoted 39 lines

    -    switch (ring->funcs->type) {
-    case AMDGPU_RING_TYPE_GFX:
-        timeout = adev->gfx_timeout;
-        break;
-    case AMDGPU_RING_TYPE_COMPUTE:
-        timeout = adev->compute_timeout;
-        break;
-    case AMDGPU_RING_TYPE_SDMA:
-        timeout = adev->sdma_timeout;
-        break;
-    default:
-        timeout = adev->video_timeout;
-        break;
-    }
-
-    r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, -               num_hw_submission, amdgpu_job_hang_limit, -               timeout, NULL, sched_score, ring->name); -    if (r) {
-        DRM_ERROR("Failed to create scheduler on ring %s.\n", -              ring->name);
-        return r;
-    }
+    if (!ring->fence_drv.fences)
+        return -ENOMEM;
          return 0;
    }

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
index fae7d185ad0d..7f20ce73a243 100644
@@ -251,6 +251,8 @@ struct amdgpu_ring {
         bool has_compute_vm_bug;
         bool            no_scheduler;
         int            hw_prio;
+    unsigned num_hw_submission;
+    atomic_t        *sched_score;
     };
       #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
author Reviewed-by Christian König Reviewed-by Christian König Reviewed-by Christian König Reviewed-by Christian König Reviewed-by Christian König Acked-by Christian König Reviewed-by Christian König Reviewed-by Christian König Reviewed-by Liu Shaoyun Reviewed-by Christian König Reviewed-by Christian König Reviewed-by Christian König
#10 lore raw

Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready

Hey, patches attached - i applied the patches and resolved merge conflicts but weren't able to test as my on board's network card doesn't work with 5.16 kernel (it does with 5.17, maybe it's Kconfig issue and i need to check more). The patches are on top of 'cababde192b2 Yifan Zhang         2 days ago     drm/amd/pm: fix mode2 reset fail for smu 13.0.5 ' commit.

Please test and let me know. Maybe by Monday I will be able to resolve the connectivity issue on 5.16.

Andrey

Quoted 187 lines · JingWen Chen

Hi Andrey,

Sorry for the misleading, I mean the whole patch series. We are depending on this patch series to fix the concurrency issue within SRIOV TDR sequence.

Quoted 180 lines · Andrey Grodzovsky

No problem if so but before I do,

JingWen - why you think this patch is needed as a standalone now ? It has no use without the entire feature together with it. Is it some changes you want to do on top of that code ?

Andrey

Quoted 169 lines · Alexander

[Public]

If it applies cleanly, feel free to drop it in.  I'll drop those patches for drm-next since they are already in drm-misc.

Alex

------------------------------------------------------------------------
*From:* amd-gfx <[email protected]> on behalf of Andrey Grodzovsky <[email protected]>
*Sent:* Thursday, February 24, 2022 11:24 AM
*To:* Chen, JingWen <[email protected]>; Christian König <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> *Cc:* Liu, Monk <[email protected]>; Chen, Horace <[email protected]>; Lazar, Lijo <[email protected]>; Koenig, Christian <[email protected]>; [email protected] <[email protected]> *Subject:* Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready
No because all the patch-set including this patch was landed into
drm-misc-next and will reach amd-staging-drm-next on the next upstream
rebase i guess.

Andrey

Quoted 149 lines · JingWen Chen

Hi Andrey,

Will you port this patch into amd-staging-drm-next?

Quoted 144 lines · Andrey Grodzovsky

All comments are fixed and code pushed. Thanks for everyone who helped reviewing.

Andrey

Quoted 138 lines · Christian König

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 7 lines

Before we initialize schedulers we must know which reset domain are we in - for single device there iis a single domain per device and so single wq per device. For XGMI the reset domain spans the entire XGMI hive and so the reset wq is per hive.

One more comment below, with that fixed Reviewed-by: Christian König <[email protected]>.

Quoted 80 lines

---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 45 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 34 ++-------------- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h   |  2 +

     3 files changed, 51 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +43 -0
index 9704b0e1fd82..00123b0013d3 100644
@@ -2287,6 +2287,47 @@ static int amdgpu_device_fw_loading(struct amdgpu_device *adev)
         return r;
     }
     +static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
+{
+    long timeout;
+    int r, i;
+
+    for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+        struct amdgpu_ring *ring = adev->rings[i];
+
+        /* No need to setup the GPU scheduler for rings that don't need it */
+        if (!ring || ring->no_scheduler)
+            continue;
+
+        switch (ring->funcs->type) {
+        case AMDGPU_RING_TYPE_GFX:
+            timeout = adev->gfx_timeout;
+            break;
+        case AMDGPU_RING_TYPE_COMPUTE:
+            timeout = adev->compute_timeout;
+            break;
+        case AMDGPU_RING_TYPE_SDMA:
+            timeout = adev->sdma_timeout;
+            break;
+        default:
+            timeout = adev->video_timeout;
+            break;
+        }
+
+        r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
+ ring->num_hw_submission, amdgpu_job_hang_limit,
+                   timeout, adev->reset_domain.wq, ring->sched_score, ring->name);
+        if (r) {
+            DRM_ERROR("Failed to create scheduler on ring %s.\n",
+                  ring->name);
+            return r;
+        }
+    }
+
+    return 0;
+}
+
+
     /**
      * amdgpu_device_ip_init - run init for hardware IPs
      *
@@ -2419,6 +2460,10 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
             }
         }
     +    r = amdgpu_device_init_schedulers(adev);
+    if (r)
+        goto init_failed;
+
         /* Don't init kfd if whole hive need to be reset during init */
         if (!adev->gmc.xgmi.pending_reset)
 amdgpu_amdkfd_device_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -2
index 45977a72b5dd..fa302540c69a 100644
@@ -457,8 +457,6 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
                       atomic_t *sched_score)
     {
         struct amdgpu_device *adev = ring->adev;
-    long timeout;
-    int r;
           if (!adev)
             return -EINVAL;

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring, · line 481

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -4
@@ -478,36 +476,12 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
 spin_lock_init(&ring->fence_drv.lock);
         ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
                          GFP_KERNEL);
-    if (!ring->fence_drv.fences)
-        return -ENOMEM;
     -    /* No need to setup the GPU scheduler for rings that don't need it */
-    if (ring->no_scheduler)
-        return 0;
+    ring->num_hw_submission = num_hw_submission;
+    ring->sched_score = sched_score;

Let's move this into the caller and then use ring->num_hw_submission in the fence code as well.

The maximum number of jobs on the ring is not really fence specific.

Regards,
Christian.

Quoted 31 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -22
     -    switch (ring->funcs->type) {
-    case AMDGPU_RING_TYPE_GFX:
-        timeout = adev->gfx_timeout;
-        break;
-    case AMDGPU_RING_TYPE_COMPUTE:
-        timeout = adev->compute_timeout;
-        break;
-    case AMDGPU_RING_TYPE_SDMA:
-        timeout = adev->sdma_timeout;
-        break;
-    default:
-        timeout = adev->video_timeout;
-        break;
-    }
-
-    r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
-               num_hw_submission, amdgpu_job_hang_limit,
-               timeout, NULL, sched_score, ring->name);
-    if (r) {
-        DRM_ERROR("Failed to create scheduler on ring %s.\n",
-              ring->name);
-        return r;
-    }
+    if (!ring->fence_drv.fences)
+        return -ENOMEM;
           return 0;
     }
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +0 -0
index fae7d185ad0d..7f20ce73a243 100644
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h struct amdgpu_ring { · line 257

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
@@ -251,6 +251,8 @@ struct amdgpu_ring {
         bool has_compute_vm_bug;
         bool            no_scheduler;
         int            hw_prio;
+    unsigned num_hw_submission;
+    atomic_t        *sched_score;
     };
       #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))

From 9c8783872f42a533440eeed5527f6418fad7aaff Mon Sep 17 00:00:00 2001
From: Andrey Grodzovsky <[email protected]>
Date: Wed, 9 Feb 2022 22:17:24 -0500
Subject: drm/amdgpu: Fix compile error.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Seems I forgot to add this to the relevant commit
when submitting.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +1 -2
index 92de3b7965a1..1949dbe28a86 100644
@@ -118,8 +118,7 @@ static inline bool amdgpu_reset_domain_schedule(struct amdgpu_reset_domain *doma
 	return queue_work(domain->wq, work);
 }
 
-void amdgpu_device_lock_reset_domain(struct amdgpu_reset_domain *reset_domain,
-				     struct amdgpu_hive_info *hive);
+void amdgpu_device_lock_reset_domain(struct amdgpu_reset_domain *reset_domain);
 
 void amdgpu_device_unlock_reset_domain(struct amdgpu_reset_domain *reset_domain);
 
Signature · 1 line
2.25.1

From b6a01953203807a341ca7129cb5fe1ff4773ecc3 Mon Sep 17 00:00:00 2001
From: Andrey Grodzovsky <[email protected]>
Date: Tue, 25 Jan 2022 11:36:18 -0500
Subject: drm/amdgpu: Revert 'drm/amdgpu: annotate a false positive recursive
locking'
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Since we have a single instance of reset semaphore which we lock only once even for XGMI hive we don't need the nested locking hint anymore.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c  | 11 ++---------
 2 files changed, 4 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -2
index 389b4b0fd209..0989f682e0a4 100644
@@ -5127,7 +5127,7 @@ int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
 	/* We need to lock reset domain only once both for XGMI and single device */
 	tmp_adev = list_first_entry(device_list_handle, struct amdgpu_device,
 				    reset_list);
-	amdgpu_device_lock_reset_domain(tmp_adev->reset_domain, hive);
+	amdgpu_device_lock_reset_domain(tmp_adev->reset_domain);
 
 	/* block all schedulers and reset given job's ring */
 	list_for_each_entry(tmp_adev, device_list_handle, reset_list) {
@@ -5554,7 +5554,7 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_sta
 		 * Locking adev->reset_domain->sem will prevent any external access
 		 * to GPU during PCI error recovery
 		 */
-		amdgpu_device_lock_reset_domain(adev->reset_domain, NULL);
+		amdgpu_device_lock_reset_domain(adev->reset_domain);
 		amdgpu_device_set_mp1_state(adev);
 
 		/*
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c +2 -9
index 69061539a20f..248d64158721 100644
@@ -23,7 +23,6 @@
 
 #include "amdgpu_reset.h"
 #include "aldebaran.h"
-#include "amdgpu_xgmi.h"
 
 int amdgpu_reset_add_handler(struct amdgpu_reset_control *reset_ctl,
 			     struct amdgpu_reset_handler *handler)
@@ -138,16 +137,10 @@ struct amdgpu_reset_domain *amdgpu_reset_create_reset_domain(enum amdgpu_reset_d
 	return reset_domain;
 }
 
-void amdgpu_device_lock_reset_domain(struct amdgpu_reset_domain *reset_domain,
-				     struct amdgpu_hive_info *hive)
+void amdgpu_device_lock_reset_domain(struct amdgpu_reset_domain *reset_domain)
 {
 	atomic_set(&reset_domain->in_gpu_reset, 1);
-
-	if (hive) {
-		down_write_nest_lock(&reset_domain->sem, &hive->hive_lock);
-	} else {
-		down_write(&reset_domain->sem);
-	}
+	down_write(&reset_domain->sem);
 }
 
 
Signature · 1 line
2.25.1

From 49b421eb6969b172d97bf782badd9aaed5e8109e Mon Sep 17 00:00:00 2001
From: Andrey Grodzovsky <[email protected]>
Date: Tue, 25 Jan 2022 11:32:47 -0500
Subject: drm/amdgpu: Rework amdgpu_device_lock_adev
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This functions needs to be split into 2 parts where one is called only once for locking single instance of reset_domain's sem and reset flag and the other part which handles MP1 states should still be called for each device in XGMI hive.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 37 ++++++++++++----------
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c  | 20 ++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h  |  4 +++
 3 files changed, 44 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +20 -17
index a9686899b9ca..389b4b0fd209 100644
@@ -4899,16 +4899,8 @@ int amdgpu_do_asic_reset(struct list_head *device_list_handle,
 	return r;
 }
 
-static void amdgpu_device_lock_adev(struct amdgpu_device *adev,
-				struct amdgpu_hive_info *hive)
+static void amdgpu_device_set_mp1_state(struct amdgpu_device *adev)
 {
-	atomic_set(&adev->reset_domain->in_gpu_reset, 1);
-
-	if (hive) {
-		down_write_nest_lock(&adev->reset_domain->sem, &hive->hive_lock);
-	} else {
-		down_write(&adev->reset_domain->sem);
-	}
 
 	switch (amdgpu_asic_reset_method(adev)) {
 	case AMD_RESET_METHOD_MODE1:
@@ -4923,12 +4915,10 @@ static void amdgpu_device_lock_adev(struct amdgpu_device *adev,
 	}
 }
 
-static void amdgpu_device_unlock_adev(struct amdgpu_device *adev)
+static void amdgpu_device_unset_mp1_state(struct amdgpu_device *adev)
 {
 	amdgpu_vf_error_trans_all(adev);
 	adev->mp1_state = PP_MP1_STATE_NONE;
-	atomic_set(&adev->reset_domain->in_gpu_reset, 0);
-	up_write(&adev->reset_domain->sem);
 }
 
 static void amdgpu_device_resume_display_audio(struct amdgpu_device *adev)
@@ -5134,10 +5124,15 @@ int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
 		device_list_handle = &device_list;
 	}
 
+	/* We need to lock reset domain only once both for XGMI and single device */
+	tmp_adev = list_first_entry(device_list_handle, struct amdgpu_device,
+				    reset_list);
+	amdgpu_device_lock_reset_domain(tmp_adev->reset_domain, hive);
+
 	/* block all schedulers and reset given job's ring */
 	list_for_each_entry(tmp_adev, device_list_handle, reset_list) {
 
-		amdgpu_device_lock_adev(tmp_adev, hive);
+		amdgpu_device_set_mp1_state(tmp_adev);
 
 		/*
 		 * Try to put the audio codec into suspend state
@@ -5290,9 +5285,14 @@ int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
 
 		if (audio_suspended)
 			amdgpu_device_resume_display_audio(tmp_adev);
-		amdgpu_device_unlock_adev(tmp_adev);
+
+		amdgpu_device_unset_mp1_state(tmp_adev);
 	}
 
+	tmp_adev = list_first_entry(device_list_handle, struct amdgpu_device,
+					    reset_list);
+	amdgpu_device_unlock_reset_domain(tmp_adev->reset_domain);
+
 	if (hive) {
 		mutex_unlock(&hive->hive_lock);
 		amdgpu_put_xgmi_hive(hive);
@@ -5554,7 +5554,8 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_sta
 		 * Locking adev->reset_domain->sem will prevent any external access
 		 * to GPU during PCI error recovery
 		 */
-		amdgpu_device_lock_adev(adev, NULL);
+		amdgpu_device_lock_reset_domain(adev->reset_domain, NULL);
+		amdgpu_device_set_mp1_state(adev);
 
 		/*
 		 * Block any work scheduling as we do for regular GPU reset
@@ -5661,7 +5662,8 @@ pci_ers_result_t amdgpu_pci_slot_reset(struct pci_dev *pdev)
 		DRM_INFO("PCIe error recovery succeeded\n");
 	} else {
 		DRM_ERROR("PCIe error recovery failed, err:%d", r);
-		amdgpu_device_unlock_adev(adev);
+		amdgpu_device_unset_mp1_state(adev);
+		amdgpu_device_unlock_reset_domain(adev->reset_domain);
 	}
 
 	return r ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED;
@@ -5698,7 +5700,8 @@ void amdgpu_pci_resume(struct pci_dev *pdev)
 		drm_sched_start(&ring->sched, true);
 	}
 
-	amdgpu_device_unlock_adev(adev);
+	amdgpu_device_unset_mp1_state(adev);
+	amdgpu_device_unlock_reset_domain(adev->reset_domain);
 }
 
 bool amdgpu_device_cache_pci_state(struct pci_dev *pdev)
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c +20 -0
index 5ab72c3bfbda..69061539a20f 100644
@@ -23,6 +23,7 @@
 
 #include "amdgpu_reset.h"
 #include "aldebaran.h"
+#include "amdgpu_xgmi.h"
 
 int amdgpu_reset_add_handler(struct amdgpu_reset_control *reset_ctl,
 			     struct amdgpu_reset_handler *handler)
@@ -137,5 +138,24 @@ struct amdgpu_reset_domain *amdgpu_reset_create_reset_domain(enum amdgpu_reset_d
 	return reset_domain;
 }
 
+void amdgpu_device_lock_reset_domain(struct amdgpu_reset_domain *reset_domain,
+				     struct amdgpu_hive_info *hive)
+{
+	atomic_set(&reset_domain->in_gpu_reset, 1);
+
+	if (hive) {
+		down_write_nest_lock(&reset_domain->sem, &hive->hive_lock);
+	} else {
+		down_write(&reset_domain->sem);
+	}
+}
+
+
+void amdgpu_device_unlock_reset_domain(struct amdgpu_reset_domain *reset_domain)
+{
+	atomic_set(&reset_domain->in_gpu_reset, 0);
+	up_write(&reset_domain->sem);
+}
+
 
 
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +4 -0
index ea6fc98ea927..92de3b7965a1 100644
@@ -118,5 +118,9 @@ static inline bool amdgpu_reset_domain_schedule(struct amdgpu_reset_domain *doma
 	return queue_work(domain->wq, work);
 }
 
+void amdgpu_device_lock_reset_domain(struct amdgpu_reset_domain *reset_domain,
+				     struct amdgpu_hive_info *hive);
+
+void amdgpu_device_unlock_reset_domain(struct amdgpu_reset_domain *reset_domain);
 
 #endif
Signature · 1 line
2.25.1

From 243258dcd8c3fbd61797f2fa07c41834c955d94a Mon Sep 17 00:00:00 2001
From: Andrey Grodzovsky <[email protected]>
Date: Wed, 19 Jan 2022 17:20:00 -0500
Subject: drm/amdgpu: Move in_gpu_reset into reset_domain
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

We should have a single instance per entrire reset domain.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  7 ++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 10 +++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c  |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h  |  1 +
 drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c      |  4 ++--
 drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c      |  4 ++--
 6 files changed, 15 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -5
index f879dd3d8256..0b0b449ead7e 100644
@@ -1044,7 +1044,6 @@ struct amdgpu_device {
 	bool				in_s4;
 	bool				in_s0ix;
 
-	atomic_t 			in_gpu_reset;
 	enum pp_mp1_state               mp1_state;
 	struct amdgpu_doorbell_index doorbell_index;
 
@@ -1482,8 +1481,6 @@ static inline bool amdgpu_is_tmz(struct amdgpu_device *adev)
        return adev->gmc.tmz_enabled;
 }
 
-static inline int amdgpu_in_reset(struct amdgpu_device *adev)
-{
-	return atomic_read(&adev->in_gpu_reset);
-}
+int amdgpu_in_reset(struct amdgpu_device *adev);
+
 #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7 -3
index 0279824b855d..a9686899b9ca 100644
@@ -3610,7 +3610,6 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 	mutex_init(&adev->mn_lock);
 	mutex_init(&adev->virt.vf_errors.lock);
 	hash_init(adev->mn_hash);
-	atomic_set(&adev->in_gpu_reset, 0);
 	mutex_init(&adev->psp.mutex);
 	mutex_init(&adev->notifier_lock);
 	mutex_init(&adev->pm.stable_pstate_ctx_lock);
@@ -4903,7 +4902,7 @@ int amdgpu_do_asic_reset(struct list_head *device_list_handle,
 static void amdgpu_device_lock_adev(struct amdgpu_device *adev,
 				struct amdgpu_hive_info *hive)
 {
-	atomic_set(&adev->in_gpu_reset, 1);
+	atomic_set(&adev->reset_domain->in_gpu_reset, 1);
 
 	if (hive) {
 		down_write_nest_lock(&adev->reset_domain->sem, &hive->hive_lock);
@@ -4928,7 +4927,7 @@ static void amdgpu_device_unlock_adev(struct amdgpu_device *adev)
 {
 	amdgpu_vf_error_trans_all(adev);
 	adev->mp1_state = PP_MP1_STATE_NONE;
-	atomic_set(&adev->in_gpu_reset, 0);
+	atomic_set(&adev->reset_domain->in_gpu_reset, 0);
 	up_write(&adev->reset_domain->sem);
 }
 
@@ -5776,6 +5775,11 @@ void amdgpu_device_invalidate_hdp(struct amdgpu_device *adev,
 	amdgpu_asic_invalidate_hdp(adev, ring);
 }
 
+int amdgpu_in_reset(struct amdgpu_device *adev)
+{
+	return atomic_read(&adev->reset_domain->in_gpu_reset);
+	}
+	
 /**
  * amdgpu_device_halt() - bring hardware to some kind of halt state
  *
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c +1 -0
index c0988c804459..5ab72c3bfbda 100644
@@ -131,6 +131,7 @@ struct amdgpu_reset_domain *amdgpu_reset_create_reset_domain(enum amdgpu_reset_d
 
 	}
 
+	atomic_set(&reset_domain->in_gpu_reset, 0);
 	init_rwsem(&reset_domain->sem);
 
 	return reset_domain;
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +1 -0
index 80f918e87d4f..ea6fc98ea927 100644
@@ -81,6 +81,7 @@ struct amdgpu_reset_domain {
 	struct workqueue_struct *wq;
 	enum amdgpu_reset_domain_type type;
 	struct rw_semaphore sem;
+	atomic_t in_gpu_reset;
 };
 
 
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +2 -2
index 4e23c29e665c..b81acf59870c 100644
@@ -259,7 +259,7 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
 	 * otherwise the mailbox msg will be ruined/reseted by
 	 * the VF FLR.
 	 */
-	if (atomic_cmpxchg(&adev->in_gpu_reset, 0, 1) != 0)
+	if (atomic_cmpxchg(&adev->reset_domain->in_gpu_reset, 0, 1) != 0)
 		return;
 
 	down_write(&adev->reset_domain->sem);
@@ -277,7 +277,7 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
 	} while (timeout > 1);
 
 flr_done:
-	atomic_set(&adev->in_gpu_reset, 0);
+	atomic_set(&adev->reset_domain->in_gpu_reset, 0);
 	up_write(&adev->reset_domain->sem);
 
 	/* Trigger recovery for world switch failure if no TDR */
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +2 -2
index f715780f7d20..22c10b97ea81 100644
@@ -283,7 +283,7 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work)
 	 * otherwise the mailbox msg will be ruined/reseted by
 	 * the VF FLR.
 	 */
-	if (atomic_cmpxchg(&adev->in_gpu_reset, 0, 1) != 0)
+	if (atomic_cmpxchg(&adev->reset_domain->in_gpu_reset, 0, 1) != 0)
 		return;
 
 	down_write(&adev->reset_domain->sem);
@@ -301,7 +301,7 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work)
 	} while (timeout > 1);
 
 flr_done:
-	atomic_set(&adev->in_gpu_reset, 0);
+	atomic_set(&adev->reset_domain->in_gpu_reset, 0);
 	up_write(&adev->reset_domain->sem);
 
 	/* Trigger recovery for world switch failure if no TDR */
Signature · 1 line
2.25.1

From 2d5679ed6bb74676ad75bb0cf66e2793500d7378 Mon Sep 17 00:00:00 2001
From: Andrey Grodzovsky <[email protected]>
Date: Wed, 19 Jan 2022 17:09:58 -0500
Subject: drm/amdgpu: Move reset sem into reset_domain
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

We want single instance of reset sem across all reset clients because in case of XGMI we should stop access cross device MMIO because any of them could be in a reset in the moment.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c   | 22 ++++++++--------
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    | 25 +++++++++----------
 .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c    | 18 +++++++------
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c     |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h     |  1 +
 drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c        |  6 +++--
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c         | 14 ++++++-----
 drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c         |  4 +--
 drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c         |  4 +--
 10 files changed, 53 insertions(+), 44 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -1
index 64a3ff31ee7d..f879dd3d8256 100644
@@ -1046,7 +1046,6 @@ struct amdgpu_device {
 
 	atomic_t 			in_gpu_reset;
 	enum pp_mp1_state               mp1_state;
-	struct rw_semaphore reset_sem;
 	struct amdgpu_doorbell_index doorbell_index;
 
 	struct mutex			notifier_lock;
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +12 -10
index 9eb9b440bd43..426b63e4f1f6 100644
@@ -37,6 +37,8 @@
 #include "amdgpu_fw_attestation.h"
 #include "amdgpu_umr.h"
 
+#include "amdgpu_reset.h"
+
 #if defined(CONFIG_DEBUG_FS)
 
 /**
@@ -1284,7 +1286,7 @@ static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)
 	}
 
 	/* Avoid accidently unparking the sched thread during GPU reset */
-	r = down_write_killable(&adev->reset_sem);
+	r = down_write_killable(&adev->reset_domain->sem);
 	if (r)
 		return r;
 
@@ -1313,7 +1315,7 @@ static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)
 		kthread_unpark(ring->sched.thread);
 	}
 
-	up_write(&adev->reset_sem);
+	up_write(&adev->reset_domain->sem);
 
 	pm_runtime_mark_last_busy(dev->dev);
 	pm_runtime_put_autosuspend(dev->dev);
@@ -1543,7 +1545,7 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val)
 		return -ENOMEM;
 
 	/* Avoid accidently unparking the sched thread during GPU reset */
-	r = down_read_killable(&adev->reset_sem);
+	r = down_read_killable(&adev->reset_domain->sem);
 	if (r)
 		goto pro_end;
 
@@ -1586,7 +1588,7 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val)
 	/* restart the scheduler */
 	kthread_unpark(ring->sched.thread);
 
-	up_read(&adev->reset_sem);
+	up_read(&adev->reset_domain->sem);
 
 	ttm_bo_unlock_delayed_workqueue(&adev->mman.bdev, resched);
 
@@ -1649,23 +1651,23 @@ static ssize_t amdgpu_reset_dump_register_list_read(struct file *f,
 		return 0;
 
 	memset(reg_offset, 0, 12);
-	ret = down_read_killable(&adev->reset_sem);
+	ret = down_read_killable(&adev->reset_domain->sem);
 	if (ret)
 		return ret;
 
 	for (i = 0; i < adev->num_regs; i++) {
 		sprintf(reg_offset, "0x%x\n", adev->reset_dump_reg_list[i]);
-		up_read(&adev->reset_sem);
+		up_read(&adev->reset_domain->sem);
 		if (copy_to_user(buf + len, reg_offset, strlen(reg_offset)))
 			return -EFAULT;
 
 		len += strlen(reg_offset);
-		ret = down_read_killable(&adev->reset_sem);
+		ret = down_read_killable(&adev->reset_domain->sem);
 		if (ret)
 			return ret;
 	}
 
-	up_read(&adev->reset_sem);
+	up_read(&adev->reset_domain->sem);
 	*pos += len;
 
 	return len;
@@ -1697,13 +1699,13 @@ static ssize_t amdgpu_reset_dump_register_list_write(struct file *f,
 		i++;
 	} while (len < size);
 
-	ret = down_write_killable(&adev->reset_sem);
+	ret = down_write_killable(&adev->reset_domain->sem);
 	if (ret)
 		goto error_free;
 
 	swap(adev->reset_dump_reg_list, tmp);
 	adev->num_regs = i;
-	up_write(&adev->reset_sem);
+	up_write(&adev->reset_domain->sem);
 	ret = size;
 
 error_free:
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +12 -13
index 6180d4ae5f8a..0279824b855d 100644
@@ -426,10 +426,10 @@ bool amdgpu_device_skip_hw_access(struct amdgpu_device *adev)
 	 * the lock.
 	 */
 	if (in_task()) {
-		if (down_read_trylock(&adev->reset_sem))
-			up_read(&adev->reset_sem);
+		if (down_read_trylock(&adev->reset_domain->sem))
+			up_read(&adev->reset_domain->sem);
 		else
-			lockdep_assert_held(&adev->reset_sem);
+			lockdep_assert_held(&adev->reset_domain->sem);
 	}
 #endif
 	return false;
@@ -455,9 +455,9 @@ uint32_t amdgpu_device_rreg(struct amdgpu_device *adev,
 	if ((reg * 4) < adev->rmmio_size) {
 		if (!(acc_flags & AMDGPU_REGS_NO_KIQ) &&
 		    amdgpu_sriov_runtime(adev) &&
-		    down_read_trylock(&adev->reset_sem)) {
+		    down_read_trylock(&adev->reset_domain->sem)) {
 			ret = amdgpu_kiq_rreg(adev, reg);
-			up_read(&adev->reset_sem);
+			up_read(&adev->reset_domain->sem);
 		} else {
 			ret = readl(((void __iomem *)adev->rmmio) + (reg * 4));
 		}
@@ -540,9 +540,9 @@ void amdgpu_device_wreg(struct amdgpu_device *adev,
 	if ((reg * 4) < adev->rmmio_size) {
 		if (!(acc_flags & AMDGPU_REGS_NO_KIQ) &&
 		    amdgpu_sriov_runtime(adev) &&
-		    down_read_trylock(&adev->reset_sem)) {
+		    down_read_trylock(&adev->reset_domain->sem)) {
 			amdgpu_kiq_wreg(adev, reg, v);
-			up_read(&adev->reset_sem);
+			up_read(&adev->reset_domain->sem);
 		} else {
 			writel(v, ((void __iomem *)adev->rmmio) + (reg * 4));
 		}
@@ -3611,7 +3611,6 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 	mutex_init(&adev->virt.vf_errors.lock);
 	hash_init(adev->mn_hash);
 	atomic_set(&adev->in_gpu_reset, 0);
-	init_rwsem(&adev->reset_sem);
 	mutex_init(&adev->psp.mutex);
 	mutex_init(&adev->notifier_lock);
 	mutex_init(&adev->pm.stable_pstate_ctx_lock);
@@ -4722,7 +4721,7 @@ static int amdgpu_reset_reg_dumps(struct amdgpu_device *adev)
 	uint32_t reg_value;
 	int i;
 
-	lockdep_assert_held(&adev->reset_sem);
+	lockdep_assert_held(&adev->reset_domain->sem);
 	dump_stack();
 
 	for (i = 0; i < adev->num_regs; i++) {
@@ -4907,9 +4906,9 @@ static void amdgpu_device_lock_adev(struct amdgpu_device *adev,
 	atomic_set(&adev->in_gpu_reset, 1);
 
 	if (hive) {
-		down_write_nest_lock(&adev->reset_sem, &hive->hive_lock);
+		down_write_nest_lock(&adev->reset_domain->sem, &hive->hive_lock);
 	} else {
-		down_write(&adev->reset_sem);
+		down_write(&adev->reset_domain->sem);
 	}
 
 	switch (amdgpu_asic_reset_method(adev)) {
@@ -4930,7 +4929,7 @@ static void amdgpu_device_unlock_adev(struct amdgpu_device *adev)
 	amdgpu_vf_error_trans_all(adev);
 	adev->mp1_state = PP_MP1_STATE_NONE;
 	atomic_set(&adev->in_gpu_reset, 0);
-	up_write(&adev->reset_sem);
+	up_write(&adev->reset_domain->sem);
 }
 
 static void amdgpu_device_resume_display_audio(struct amdgpu_device *adev)
@@ -5553,7 +5552,7 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_sta
 	/* Fatal error, prepare for slot reset */
 	case pci_channel_io_frozen:
 		/*
-		 * Locking adev->reset_sem will prevent any external access
+		 * Locking adev->reset_domain->sem will prevent any external access
 		 * to GPU during PCI error recovery
 		 */
 		amdgpu_device_lock_adev(adev, NULL);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +10 -8
index 2b844a5aafdb..a44f2eeed6ef 100644
@@ -31,6 +31,8 @@
 #include <linux/debugfs.h>
 #include <linux/uaccess.h>
 
+#include "amdgpu_reset.h"
+
 #define EEPROM_I2C_MADDR_VEGA20         0x0
 #define EEPROM_I2C_MADDR_ARCTURUS       0x40000
 #define EEPROM_I2C_MADDR_ARCTURUS_D342  0x0
@@ -193,12 +195,12 @@ static int __write_table_header(struct amdgpu_ras_eeprom_control *control)
 	__encode_table_header_to_buf(&control->tbl_hdr, buf);
 
 	/* i2c may be unstable in gpu reset */
-	down_read(&adev->reset_sem);
+	down_read(&adev->reset_domain->sem);
 	res = amdgpu_eeprom_write(adev->pm.ras_eeprom_i2c_bus,
 				  control->i2c_address +
 				  control->ras_header_offset,
 				  buf, RAS_TABLE_HEADER_SIZE);
-	up_read(&adev->reset_sem);
+	up_read(&adev->reset_domain->sem);
 
 	if (res < 0) {
 		DRM_ERROR("Failed to write EEPROM table header:%d", res);
@@ -390,13 +392,13 @@ static int __amdgpu_ras_eeprom_write(struct amdgpu_ras_eeprom_control *control,
 	int res;
 
 	/* i2c may be unstable in gpu reset */
-	down_read(&adev->reset_sem);
+	down_read(&adev->reset_domain->sem);
 	buf_size = num * RAS_TABLE_RECORD_SIZE;
 	res = amdgpu_eeprom_write(adev->pm.ras_eeprom_i2c_bus,
 				  control->i2c_address +
 				  RAS_INDEX_TO_OFFSET(control, fri),
 				  buf, buf_size);
-	up_read(&adev->reset_sem);
+	up_read(&adev->reset_domain->sem);
 	if (res < 0) {
 		DRM_ERROR("Writing %d EEPROM table records error:%d",
 			  num, res);
@@ -550,12 +552,12 @@ amdgpu_ras_eeprom_update_header(struct amdgpu_ras_eeprom_control *control)
 		goto Out;
 	}
 
-	down_read(&adev->reset_sem);
+	down_read(&adev->reset_domain->sem);
 	res = amdgpu_eeprom_read(adev->pm.ras_eeprom_i2c_bus,
 				 control->i2c_address +
 				 control->ras_record_offset,
 				 buf, buf_size);
-	up_read(&adev->reset_sem);
+	up_read(&adev->reset_domain->sem);
 	if (res < 0) {
 		DRM_ERROR("EEPROM failed reading records:%d\n",
 			  res);
@@ -645,13 +647,13 @@ static int __amdgpu_ras_eeprom_read(struct amdgpu_ras_eeprom_control *control,
 	int res;
 
 	/* i2c may be unstable in gpu reset */
-	down_read(&adev->reset_sem);
+	down_read(&adev->reset_domain->sem);
 	buf_size = num * RAS_TABLE_RECORD_SIZE;
 	res = amdgpu_eeprom_read(adev->pm.ras_eeprom_i2c_bus,
 				 control->i2c_address +
 				 RAS_INDEX_TO_OFFSET(control, fri),
 				 buf, buf_size);
-	up_read(&adev->reset_sem);
+	up_read(&adev->reset_domain->sem);
 	if (res < 0) {
 		DRM_ERROR("Reading %d EEPROM table records error:%d",
 			  num, res);
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c +2 -0
index 91864947063f..c0988c804459 100644
@@ -131,6 +131,8 @@ struct amdgpu_reset_domain *amdgpu_reset_create_reset_domain(enum amdgpu_reset_d
 
 	}
 
+	init_rwsem(&reset_domain->sem);
+
 	return reset_domain;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +1 -0
index cc625e441fa0..80f918e87d4f 100644
@@ -80,6 +80,7 @@ struct amdgpu_reset_domain {
 	struct kref refcount;
 	struct workqueue_struct *wq;
 	enum amdgpu_reset_domain_type type;
+	struct rw_semaphore sem;
 };
 
 
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +4 -2
index e7add2020d48..3dcd82b49481 100644
@@ -48,6 +48,8 @@
 #include "athub_v2_0.h"
 #include "athub_v2_1.h"
 
+#include "amdgpu_reset.h"
+
 #if 0
 static const struct soc15_reg_golden golden_settings_navi10_hdp[] =
 {
@@ -328,7 +330,7 @@ static void gmc_v10_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
 	 */
 	if (adev->gfx.kiq.ring.sched.ready &&
 	    (amdgpu_sriov_runtime(adev) || !amdgpu_sriov_vf(adev)) &&
-	    down_read_trylock(&adev->reset_sem)) {
+	    down_read_trylock(&adev->reset_domain->sem)) {
 		struct amdgpu_vmhub *hub = &adev->vmhub[vmhub];
 		const unsigned eng = 17;
 		u32 inv_req = hub->vmhub_funcs->get_invalidate_req(vmid, flush_type);
@@ -338,7 +340,7 @@ static void gmc_v10_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
 		amdgpu_virt_kiq_reg_write_reg_wait(adev, req, ack, inv_req,
 				1 << vmid);
 
-		up_read(&adev->reset_sem);
+		up_read(&adev->reset_domain->sem);
 		return;
 	}
 
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +8 -6
index 412e44af1608..df35f0252eea 100644
@@ -62,6 +62,8 @@
 #include "amdgpu_ras.h"
 #include "amdgpu_xgmi.h"
 
+#include "amdgpu_reset.h"
+
 /* add these here since we already include dce12 headers and these are for DCN */
 #define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION                                                          0x055d
 #define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION_BASE_IDX                                                 2
@@ -787,13 +789,13 @@ static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
 	 */
 	if (adev->gfx.kiq.ring.sched.ready &&
 	    (amdgpu_sriov_runtime(adev) || !amdgpu_sriov_vf(adev)) &&
-	    down_read_trylock(&adev->reset_sem)) {
+	    down_read_trylock(&adev->reset_domain->sem)) {
 		uint32_t req = hub->vm_inv_eng0_req + hub->eng_distance * eng;
 		uint32_t ack = hub->vm_inv_eng0_ack + hub->eng_distance * eng;
 
 		amdgpu_virt_kiq_reg_write_reg_wait(adev, req, ack, inv_req,
 						   1 << vmid);
-		up_read(&adev->reset_sem);
+		up_read(&adev->reset_domain->sem);
 		return;
 	}
 
@@ -900,7 +902,7 @@ static int gmc_v9_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev,
 	if (amdgpu_in_reset(adev))
 		return -EIO;
 
-	if (ring->sched.ready && down_read_trylock(&adev->reset_sem)) {
+	if (ring->sched.ready && down_read_trylock(&adev->reset_domain->sem)) {
 		/* Vega20+XGMI caches PTEs in TC and TLB. Add a
 		 * heavy-weight TLB flush (type 2), which flushes
 		 * both. Due to a race condition with concurrent
@@ -927,7 +929,7 @@ static int gmc_v9_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev,
 		if (r) {
 			amdgpu_ring_undo(ring);
 			spin_unlock(&adev->gfx.kiq.ring_lock);
-			up_read(&adev->reset_sem);
+			up_read(&adev->reset_domain->sem);
 			return -ETIME;
 		}
 
@@ -936,10 +938,10 @@ static int gmc_v9_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev,
 		r = amdgpu_fence_wait_polling(ring, seq, adev->usec_timeout);
 		if (r < 1) {
 			dev_err(adev->dev, "wait for kiq fence error: %ld.\n", r);
-			up_read(&adev->reset_sem);
+			up_read(&adev->reset_domain->sem);
 			return -ETIME;
 		}
-		up_read(&adev->reset_sem);
+		up_read(&adev->reset_domain->sem);
 		return 0;
 	}
 
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +2 -2
index 6740eef84ee1..4e23c29e665c 100644
@@ -262,7 +262,7 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
 	if (atomic_cmpxchg(&adev->in_gpu_reset, 0, 1) != 0)
 		return;
 
-	down_write(&adev->reset_sem);
+	down_write(&adev->reset_domain->sem);
 
 	amdgpu_virt_fini_data_exchange(adev);
 
@@ -278,7 +278,7 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
 
 flr_done:
 	atomic_set(&adev->in_gpu_reset, 0);
-	up_write(&adev->reset_sem);
+	up_write(&adev->reset_domain->sem);
 
 	/* Trigger recovery for world switch failure if no TDR */
 	if (amdgpu_device_should_recover_gpu(adev)
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +2 -2
index e967d61c7134..f715780f7d20 100644
@@ -286,7 +286,7 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work)
 	if (atomic_cmpxchg(&adev->in_gpu_reset, 0, 1) != 0)
 		return;
 
-	down_write(&adev->reset_sem);
+	down_write(&adev->reset_domain->sem);
 
 	amdgpu_virt_fini_data_exchange(adev);
 
@@ -302,7 +302,7 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work)
 
 flr_done:
 	atomic_set(&adev->in_gpu_reset, 0);
-	up_write(&adev->reset_sem);
+	up_write(&adev->reset_domain->sem);
 
 	/* Trigger recovery for world switch failure if no TDR */
 	if (amdgpu_device_should_recover_gpu(adev)
Signature · 1 line
2.25.1

From fb95cf9a519b7703cb1cc54dbce6e0adc4f4e6e0 Mon Sep 17 00:00:00 2001
From: Andrey Grodzovsky <[email protected]>
Date: Fri, 21 Jan 2022 17:23:32 -0500
Subject: drm/amdgpu: Rework reset domain to be refcounted.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The reset domain contains register access semaphor now and so needs to be present as long as each device in a hive needs it and so it cannot be binded to XGMI hive life cycle.
Adress this by making reset domain refcounted and pointed by each member of the hive and the hive itself.

v4:

Fix crash on boot witrh XGMI hive by adding type to reset_domain. XGMI will only create a new reset_domain if prevoius was of single device type meaning it's first boot. Otherwsie it will take a refocunt to exsiting reset_domain from the amdgou device.

Add a wrapper around reset_domain->refcount get/put and a wrapper around send to reset wq (Lijo)

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  6 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 44 +++++++++++++---------
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c  | 40 ++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h  | 35 +++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c   | 29 +++++++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h   |  2 +-
 drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c      |  6 ++-
 drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c      |  6 ++-
 drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c      |  6 ++-
 9 files changed, 140 insertions(+), 34 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -4
index 10f6aaa62e92..64a3ff31ee7d 100644
@@ -807,9 +807,7 @@ struct ip_discovery_top;
 #define AMDGPU_RESET_MAGIC_NUM 64
 #define AMDGPU_MAX_DF_PERFMONS 4
 #define AMDGPU_PRODUCT_NAME_LEN 64
-struct amdgpu_reset_domain {
-	struct workqueue_struct *wq;
-};
+struct amdgpu_reset_domain;
 
 struct amdgpu_device {
 	struct device			*dev;
@@ -1103,7 +1101,7 @@ struct amdgpu_device {
 	uint32_t                        *reset_dump_reg_list;
 	int                             num_regs;
 
-	struct amdgpu_reset_domain	reset_domain;
+	struct amdgpu_reset_domain	*reset_domain;
 };
 
 static inline struct amdgpu_device *drm_to_adev(struct drm_device *ddev)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +27 -17

77 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c +40 -0
index 02afd4115675..91864947063f 100644
@@ -96,3 +96,43 @@ int amdgpu_reset_perform_reset(struct amdgpu_device *adev,
 	return reset_handler->restore_hwcontext(adev->reset_cntl,
 						reset_context);
 }
+
+
+void amdgpu_reset_destroy_reset_domain(struct kref *ref)
+{
+	struct amdgpu_reset_domain *reset_domain = container_of(ref,
+								struct amdgpu_reset_domain,
+								refcount);
+	if (reset_domain->wq)
+		destroy_workqueue(reset_domain->wq);
+
+	kvfree(reset_domain);
+}
+
+struct amdgpu_reset_domain *amdgpu_reset_create_reset_domain(enum amdgpu_reset_domain_type type,
+							     char *wq_name)
+{
+	struct amdgpu_reset_domain *reset_domain;
+
+	reset_domain = kvzalloc(sizeof(struct amdgpu_reset_domain), GFP_KERNEL);
+	if (!reset_domain) {
+		DRM_ERROR("Failed to allocate amdgpu_reset_domain!");
+		return NULL;
+	}
+
+	reset_domain->type = type;
+	kref_init(&reset_domain->refcount);
+
+	reset_domain->wq = create_singlethread_workqueue(wq_name);
+	if (!reset_domain->wq) {
+		DRM_ERROR("Failed to allocate wq for amdgpu_reset_domain!");
+		amdgpu_reset_put_reset_domain(reset_domain);
+		return NULL;
+
+	}
+
+	return reset_domain;
+}
+
+
+
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +35 -0
index e00d38d9160a..cc625e441fa0 100644
@@ -70,6 +70,19 @@ struct amdgpu_reset_control {
 	void (*async_reset)(struct work_struct *work);
 };
 
+
+enum amdgpu_reset_domain_type {
+	SINGLE_DEVICE,
+	XGMI_HIVE
+};
+
+struct amdgpu_reset_domain {
+	struct kref refcount;
+	struct workqueue_struct *wq;
+	enum amdgpu_reset_domain_type type;
+};
+
+
 int amdgpu_reset_init(struct amdgpu_device *adev);
 int amdgpu_reset_fini(struct amdgpu_device *adev);
 
@@ -82,4 +95,26 @@ int amdgpu_reset_perform_reset(struct amdgpu_device *adev,
 int amdgpu_reset_add_handler(struct amdgpu_reset_control *reset_ctl,
 			     struct amdgpu_reset_handler *handler);
 
+struct amdgpu_reset_domain *amdgpu_reset_create_reset_domain(enum amdgpu_reset_domain_type type,
+							     char *wq_name);
+
+void amdgpu_reset_destroy_reset_domain(struct kref *ref);
+
+static inline bool amdgpu_reset_get_reset_domain(struct amdgpu_reset_domain *domain)
+{
+	return kref_get_unless_zero(&domain->refcount) != 0;
+}
+
+static inline void amdgpu_reset_put_reset_domain(struct amdgpu_reset_domain *domain)
+{
+	kref_put(&domain->refcount, amdgpu_reset_destroy_reset_domain);
+}
+
+static inline bool amdgpu_reset_domain_schedule(struct amdgpu_reset_domain *domain,
+						struct work_struct *work)
+{
+	return queue_work(domain->wq, work);
+}
+
+
 #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +23 -6
index 68e645fadb35..91817a31f3e1 100644
@@ -32,6 +32,8 @@
 #include "wafl/wafl2_4_0_0_smn.h"
 #include "wafl/wafl2_4_0_0_sh_mask.h"
 
+#include "amdgpu_reset.h"
+
 #define smnPCS_XGMI23_PCS_ERROR_STATUS   0x11a01210
 #define smnPCS_XGMI3X16_PCS_ERROR_STATUS 0x11a0020c
 #define smnPCS_GOPX1_PCS_ERROR_STATUS    0x12200210
@@ -227,6 +229,9 @@ static void amdgpu_xgmi_hive_release(struct kobject *kobj)
 	struct amdgpu_hive_info *hive = container_of(
 		kobj, struct amdgpu_hive_info, kobj);
 
+	amdgpu_reset_put_reset_domain(hive->reset_domain);
+	hive->reset_domain = NULL;
+
 	mutex_destroy(&hive->hive_lock);
 	kfree(hive);
 }
@@ -398,12 +403,24 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 		goto pro_end;
 	}
 
-	hive->reset_domain.wq = alloc_ordered_workqueue("amdgpu-reset-hive", 0);
-	if (!hive->reset_domain.wq) {
-		dev_err(adev->dev, "XGMI: failed allocating wq for reset domain!\n");
-		kfree(hive);
-		hive = NULL;
-		goto pro_end;
+	/**
+	 * Avoid recreating reset domain when hive is reconstructed for the case
+	 * of reset the devices in the XGMI hive during probe for SRIOV
+	 * See https://www.spinics.net/lists/amd-gfx/msg58836.html
+	 */
+	if (adev->reset_domain->type != XGMI_HIVE) {
+		hive->reset_domain = amdgpu_reset_create_reset_domain(XGMI_HIVE, "amdgpu-reset-hive");
+			if (!hive->reset_domain) {
+				dev_err(adev->dev, "XGMI: failed initializing reset domain for xgmi hive\n");
+				ret = -ENOMEM;
+				kobject_put(&hive->kobj);
+				kfree(hive);
+				hive = NULL;
+				goto pro_end;
+			}
+	} else {
+		amdgpu_reset_get_reset_domain(adev->reset_domain);
+		hive->reset_domain = adev->reset_domain;
 	}
 
 	hive->hive_id = adev->gmc.xgmi.hive_id;
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +1 -1
index 1649ae4c7e09..b4a705545657 100644
@@ -42,7 +42,7 @@ struct amdgpu_hive_info {
 		AMDGPU_XGMI_PSTATE_UNKNOWN
 	} pstate;
 
-	struct amdgpu_reset_domain reset_domain;
+	struct amdgpu_reset_domain *reset_domain;
 };
 
 struct amdgpu_pcs_ras_field {
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +4 -2
index 5869d51d8bee..6740eef84ee1 100644
@@ -32,6 +32,8 @@
 #include "soc15_common.h"
 #include "mxgpu_ai.h"
 
+#include "amdgpu_reset.h"
+
 static void xgpu_ai_mailbox_send_ack(struct amdgpu_device *adev)
 {
 	WREG8(AI_MAIBOX_CONTROL_RCV_OFFSET_BYTE, 2);
@@ -308,8 +310,8 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev,
 	switch (event) {
 		case IDH_FLR_NOTIFICATION:
 		if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
-			WARN_ONCE(!queue_work(adev->reset_domain.wq,
-					      &adev->virt.flr_work),
+			WARN_ONCE(!amdgpu_reset_domain_schedule(adev->reset_domain,
+								&adev->virt.flr_work),
 				  "Failed to queue work! at %s",
 				  __func__);
 		break;
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +4 -2
index 5728a6401d73..e967d61c7134 100644
@@ -31,6 +31,8 @@
 #include "soc15_common.h"
 #include "mxgpu_nv.h"
 
+#include "amdgpu_reset.h"
+
 static void xgpu_nv_mailbox_send_ack(struct amdgpu_device *adev)
 {
 	WREG8(NV_MAIBOX_CONTROL_RCV_OFFSET_BYTE, 2);
@@ -338,8 +340,8 @@ static int xgpu_nv_mailbox_rcv_irq(struct amdgpu_device *adev,
 	switch (event) {
 	case IDH_FLR_NOTIFICATION:
 		if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
-			WARN_ONCE(!queue_work(adev->reset_domain.wq,
-					      &adev->virt.flr_work),
+			WARN_ONCE(!amdgpu_reset_domain_schedule(adev->reset_domain,
+				   &adev->virt.flr_work),
 				  "Failed to queue work! at %s",
 				  __func__);
 		break;
drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c +4 -2
index 1f4cda0447f1..7b63d30b9b79 100644
@@ -42,6 +42,8 @@
 #include "smu/smu_7_1_3_d.h"
 #include "mxgpu_vi.h"
 
+#include "amdgpu_reset.h"
+
 /* VI golden setting */
 static const u32 xgpu_fiji_mgcg_cgcg_init[] = {
 	mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
@@ -551,8 +553,8 @@ static int xgpu_vi_mailbox_rcv_irq(struct amdgpu_device *adev,
 
 		/* only handle FLR_NOTIFY now */
 		if (!r && !amdgpu_in_reset(adev))
-			WARN_ONCE(!queue_work(adev->reset_domain.wq,
-					      &adev->virt.flr_work),
+			WARN_ONCE(!amdgpu_reset_domain_schedule(adev->reset_domain,
+								&adev->virt.flr_work),
 				  "Failed to queue work! at %s",
 				  __func__);
 	}
Signature · 1 line
2.25.1

From db8b614a34efa8c5df47eb402fe2141f45e49415 Mon Sep 17 00:00:00 2001
From: Andrey Grodzovsky <[email protected]>
Date: Thu, 16 Dec 2021 14:24:43 -0500
Subject: drm/amdgpu: Drop concurrent GPU reset protection for device
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Since now all GPU resets are serialzied there is no need for this.

This patch also reverts 'drm/amdgpu: race issue when jobs on 2 ring timeout'

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 89 ++--------------------
 1 file changed, 7 insertions(+), 82 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7 -82

147 lines not on this page · raw message

Signature · 1 line
2.25.1

From 22f905dc76ee225542b7d261bcf6ff7b724d40e9 Mon Sep 17 00:00:00 2001
From: Andrey Grodzovsky <[email protected]>
Date: Wed, 15 Dec 2021 16:55:25 -0500
Subject: drm/amdgpu: Drop hive->in_reset
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Since we serialize all resets no need to protect from concurrent resets.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19 +------------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c   |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h   |  1 -
 3 files changed, 1 insertion(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -18
index b32d40a8718e..21d646e10d89 100644
@@ -5141,26 +5141,10 @@ int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
 	dev_info(adev->dev, "GPU %s begin!\n",
 		need_emergency_restart ? "jobs stop":"reset");
 
-	/*
-	 * Here we trylock to avoid chain of resets executing from
-	 * either trigger by jobs on different adevs in XGMI hive or jobs on
-	 * different schedulers for same device while this TO handler is running.
-	 * We always reset all schedulers for device and all devices for XGMI
-	 * hive so that should take care of them too.
-	 */
 	if (!amdgpu_sriov_vf(adev))
 		hive = amdgpu_get_xgmi_hive(adev);
-	if (hive) {
-		if (atomic_cmpxchg(&hive->in_reset, 0, 1) != 0) {
-			DRM_INFO("Bailing on TDR for s_job:%llx, hive: %llx as another already in progress",
-				job ? job->base.id : -1, hive->hive_id);
-			amdgpu_put_xgmi_hive(hive);
-			if (job && job->vm)
-				drm_sched_increase_karma(&job->base);
-			return 0;
-		}
+	if (hive)
 		mutex_lock(&hive->hive_lock);
-	}
 
 	reset_context.method = AMD_RESET_METHOD_NONE;
 	reset_context.reset_req_dev = adev;
@@ -5359,7 +5343,6 @@ int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
 
 skip_recovery:
 	if (hive) {
-		atomic_set(&hive->in_reset, 0);
 		mutex_unlock(&hive->hive_lock);
 		amdgpu_put_xgmi_hive(hive);
 	}
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +0 -1
index 5367ce572b2d..68e645fadb35 100644
@@ -410,7 +410,6 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 	INIT_LIST_HEAD(&hive->device_list);
 	INIT_LIST_HEAD(&hive->node);
 	mutex_init(&hive->hive_lock);
-	atomic_set(&hive->in_reset, 0);
 	atomic_set(&hive->number_devices, 0);
 	task_barrier_init(&hive->tb);
 	hive->pstate = AMDGPU_XGMI_PSTATE_UNKNOWN;
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +0 -1
index 2a89d820acea..1649ae4c7e09 100644
@@ -33,7 +33,6 @@ struct amdgpu_hive_info {
 	struct list_head node;
 	atomic_t number_devices;
 	struct mutex hive_lock;
-	atomic_t in_reset;
 	int hi_req_count;
 	struct amdgpu_device *hi_req_gpu;
 	struct task_barrier tb;
Signature · 1 line
2.25.1

From 2bc793d7de623944eff4f22bf68d7fa5cb39d7cc Mon Sep 17 00:00:00 2001
From: Andrey Grodzovsky <[email protected]>
Date: Mon, 20 Dec 2021 17:27:37 -0500
Subject: drm/amd/virt: For SRIOV send GPU reset directly to TDR queue.

No need to to trigger another work queue inside the work queue.

v3:

Problem:
Extra reset caused by host side FLR notification following guest side triggered reset.
Fix: Preven qeuing flr_work from mailbox irq if guest already executing a reset.

---
 drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c | 9 ++++++---
 drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c | 9 ++++++---
 drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c | 9 ++++++---
 3 files changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +6 -3
index 56da5ab82987..5869d51d8bee 100644
@@ -282,7 +282,7 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
 	if (amdgpu_device_should_recover_gpu(adev)
 		&& (!amdgpu_device_has_job_running(adev) ||
 		adev->sdma_timeout == MAX_SCHEDULE_TIMEOUT))
-		amdgpu_device_gpu_recover(adev, NULL);
+		amdgpu_device_gpu_recover_imp(adev, NULL);
 }
 
 static int xgpu_ai_set_mailbox_rcv_irq(struct amdgpu_device *adev,
@@ -307,8 +307,11 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev,
 
 	switch (event) {
 		case IDH_FLR_NOTIFICATION:
-		if (amdgpu_sriov_runtime(adev))
-			schedule_work(&adev->virt.flr_work);
+		if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
+			WARN_ONCE(!queue_work(adev->reset_domain.wq,
+					      &adev->virt.flr_work),
+				  "Failed to queue work! at %s",
+				  __func__);
 		break;
 		case IDH_QUERY_ALIVE:
 			xgpu_ai_mailbox_send_ack(adev);
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +6 -3
index 477d0dde19c5..5728a6401d73 100644
@@ -309,7 +309,7 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work)
 		adev->gfx_timeout == MAX_SCHEDULE_TIMEOUT ||
 		adev->compute_timeout == MAX_SCHEDULE_TIMEOUT ||
 		adev->video_timeout == MAX_SCHEDULE_TIMEOUT))
-		amdgpu_device_gpu_recover(adev, NULL);
+		amdgpu_device_gpu_recover_imp(adev, NULL);
 }
 
 static int xgpu_nv_set_mailbox_rcv_irq(struct amdgpu_device *adev,
@@ -337,8 +337,11 @@ static int xgpu_nv_mailbox_rcv_irq(struct amdgpu_device *adev,
 
 	switch (event) {
 	case IDH_FLR_NOTIFICATION:
-		if (amdgpu_sriov_runtime(adev))
-			schedule_work(&adev->virt.flr_work);
+		if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
+			WARN_ONCE(!queue_work(adev->reset_domain.wq,
+					      &adev->virt.flr_work),
+				  "Failed to queue work! at %s",
+				  __func__);
 		break;
 		/* READY_TO_ACCESS_GPU is fetched by kernel polling, IRQ can ignore
 		 * it byfar since that polling thread will handle it,
drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c +6 -3
index a642c04cf17d..1f4cda0447f1 100644
@@ -521,7 +521,7 @@ static void xgpu_vi_mailbox_flr_work(struct work_struct *work)
 
 	/* Trigger recovery due to world switch failure */
 	if (amdgpu_device_should_recover_gpu(adev))
-		amdgpu_device_gpu_recover(adev, NULL);
+		amdgpu_device_gpu_recover_imp(adev, NULL);
 }
 
 static int xgpu_vi_set_mailbox_rcv_irq(struct amdgpu_device *adev,
@@ -550,8 +550,11 @@ static int xgpu_vi_mailbox_rcv_irq(struct amdgpu_device *adev,
 		r = xgpu_vi_mailbox_rcv_msg(adev, IDH_FLR_NOTIFICATION);
 
 		/* only handle FLR_NOTIFY now */
-		if (!r)
-			schedule_work(&adev->virt.flr_work);
+		if (!r && !amdgpu_in_reset(adev))
+			WARN_ONCE(!queue_work(adev->reset_domain.wq,
+					      &adev->virt.flr_work),
+				  "Failed to queue work! at %s",
+				  __func__);
 	}
 
 	return 0;
Signature · 1 line
2.25.1

From 22896398cac958965896470447a99cb717ae218d Mon Sep 17 00:00:00 2001
From: Andrey Grodzovsky <[email protected]>
Date: Fri, 17 Dec 2021 13:05:15 -0500
Subject: drm/amdgpu: Serialize non TDR gpu recovery with TDRs
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Use reset domain wq also for non TDR gpu recovery trigers such as sysfs and RAS. We must serialize all possible GPU recoveries to gurantee no concurrency there. For TDR call the original recovery function directly since it's already executed from within the wq. For others just use a wrapper to qeueue work and wait on it to finish.

v2: Rename to amdgpu_recover_work_struct

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 33 +++++++++++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c    |  2 +-
 3 files changed, 35 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index 9f8aeb30e930..10f6aaa62e92 100644
@@ -1297,6 +1297,8 @@ bool amdgpu_device_has_job_running(struct amdgpu_device *adev);
 bool amdgpu_device_should_recover_gpu(struct amdgpu_device *adev);
 int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
 			      struct amdgpu_job* job);
+int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
+			      struct amdgpu_job *job);
 void amdgpu_device_pci_config_reset(struct amdgpu_device *adev);
 int amdgpu_device_pci_reset(struct amdgpu_device *adev);
 bool amdgpu_device_need_post(struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +32 -1
index e6ebf5276ce6..b32d40a8718e 100644
@@ -5107,7 +5107,7 @@ static void amdgpu_device_recheck_guilty_jobs(
  * Returns 0 for success or an error on failure.
  */
 
-int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
+int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
 			      struct amdgpu_job *job)
 {
 	struct list_head device_list, *device_list_handle =  NULL;
@@ -5369,6 +5369,37 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
 	return r;
 }
 
+struct amdgpu_recover_work_struct {
+	struct work_struct base;
+	struct amdgpu_device *adev;
+	struct amdgpu_job *job;
+	int ret;
+};
+
+static void amdgpu_device_queue_gpu_recover_work(struct work_struct *work)
+{
+	struct amdgpu_recover_work_struct *recover_work = container_of(work, struct amdgpu_recover_work_struct, base);
+
+	recover_work->ret = amdgpu_device_gpu_recover_imp(recover_work->adev, recover_work->job);
+}
+/*
+ * Serialize gpu recover into reset domain single threaded wq
+ */
+int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
+				    struct amdgpu_job *job)
+{
+	struct amdgpu_recover_work_struct work = {.adev = adev, .job = job};
+
+	INIT_WORK(&work.base, amdgpu_device_queue_gpu_recover_work);
+
+	if (!queue_work(adev->reset_domain.wq, &work.base))
+		return -EAGAIN;
+
+	flush_work(&work.base);
+
+	return work.ret;
+}
+
 /**
  * amdgpu_device_get_pcie_info - fence pcie info about the PCIE slot
  *
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -1
index 4870e093213d..a66ac2e6d189 100644
@@ -64,7 +64,7 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
 		  ti.process_name, ti.tgid, ti.task_name, ti.pid);
 
 	if (amdgpu_device_should_recover_gpu(ring->adev)) {
-		r = amdgpu_device_gpu_recover(ring->adev, job);
+		r = amdgpu_device_gpu_recover_imp(ring->adev, job);
 		if (r)
 			DRM_ERROR("GPU Recovery Failed: %d\n", r);
 
Signature · 1 line
2.25.1

From 8d5ddc7037fc6c699692cdc8de799b1583d5765a Mon Sep 17 00:00:00 2001
From: Andrey Grodzovsky <[email protected]>
Date: Mon, 6 Dec 2021 14:59:35 -0500
Subject: drm/amdgpu: Move scheduler init to after XGMI is ready
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Before we initialize schedulers we must know which reset domain are we in - for single device there iis a single domain per device and so single wq per device. For XGMI the reset domain spans the entire XGMI hive and so the reset wq is per hive.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 46 ++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 43 +++-----------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c   |  5 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h   |  6 +--
 4 files changed, 57 insertions(+), 43 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +46 -0

58 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +5 -38

70 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +3 -2
index ab2351ba9574..35bcb6dc1816 100644
@@ -191,8 +191,9 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 		ring->adev = adev;
 		ring->idx = adev->num_rings++;
 		adev->rings[ring->idx] = ring;
-		r = amdgpu_fence_driver_init_ring(ring, sched_hw_submission,
-						  sched_score);
+		ring->num_hw_submission = sched_hw_submission;
+		ring->sched_score = sched_score;
+		r = amdgpu_fence_driver_init_ring(ring);
 		if (r)
 			return r;
 	}
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +3 -3
index fae7d185ad0d..48365da213dc 100644
@@ -114,9 +114,7 @@ struct amdgpu_fence_driver {
 void amdgpu_fence_driver_clear_job_fences(struct amdgpu_ring *ring);
 void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring);
 
-int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
-				  unsigned num_hw_submission,
-				  atomic_t *sched_score);
+int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring);
 int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
 				   struct amdgpu_irq_src *irq_src,
 				   unsigned irq_type);
@@ -251,6 +249,8 @@ struct amdgpu_ring {
 	bool			has_compute_vm_bug;
 	bool			no_scheduler;
 	int			hw_prio;
+	unsigned 		num_hw_submission;
+	atomic_t		*sched_score;
 };
 
 #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
Signature · 1 line
2.25.1

From 5961b221ce9e61880991fd6c040cf525cadd4a35 Mon Sep 17 00:00:00 2001
From: Andrey Grodzovsky <[email protected]>
Date: Tue, 30 Nov 2021 16:19:03 -0500
Subject: drm/amdgpu: Introduce reset domain
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Defined a reset_domain struct such that
all the entities that go through reset
together will be serialized one against
another. Do it for both single device and
XGMI hive cases.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  6 ++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 20 +++++++++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c   |  9 +++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h   |  2 ++
 4 files changed, 36 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +6 -0
index bbe9950bf4db..9f8aeb30e930 100644
@@ -807,6 +807,10 @@ struct ip_discovery_top;
 #define AMDGPU_RESET_MAGIC_NUM 64
 #define AMDGPU_MAX_DF_PERFMONS 4
 #define AMDGPU_PRODUCT_NAME_LEN 64
+struct amdgpu_reset_domain {
+	struct workqueue_struct *wq;
+};
+
 struct amdgpu_device {
 	struct device			*dev;
 	struct pci_dev			*pdev;
@@ -1098,6 +1102,8 @@ struct amdgpu_device {
 	/* reset dump register */
 	uint32_t                        *reset_dump_reg_list;
 	int                             num_regs;
+
+	struct amdgpu_reset_domain	reset_domain;
 };
 
 static inline struct amdgpu_device *drm_to_adev(struct drm_device *ddev)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +19 -1
index 6113ddc765a7..214ac2d42930 100644
@@ -2447,9 +2447,27 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
 	if (r)
 		goto init_failed;
 
-	if (adev->gmc.xgmi.num_physical_nodes > 1)
+	if (adev->gmc.xgmi.num_physical_nodes > 1) {
+		struct amdgpu_hive_info *hive;
+
 		amdgpu_xgmi_add_device(adev);
 
+		hive = amdgpu_get_xgmi_hive(adev);
+		if (!hive || !hive->reset_domain.wq) {
+			DRM_ERROR("Failed to obtain reset domain info for XGMI hive:%llx", hive->hive_id);
+			r = -EINVAL;
+			goto init_failed;
+		}
+
+		adev->reset_domain.wq = hive->reset_domain.wq;
+	} else {
+		adev->reset_domain.wq = alloc_ordered_workqueue("amdgpu-reset-dev", 0);
+		if (!adev->reset_domain.wq) {
+			r = -ENOMEM;
+			goto init_failed;
+		}
+	}
+
 	/* Don't init kfd if whole hive need to be reset during init */
 	if (!adev->gmc.xgmi.pending_reset)
 		amdgpu_amdkfd_device_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +9 -0
index 77b65434ccc2..5367ce572b2d 100644
@@ -398,6 +398,14 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 		goto pro_end;
 	}
 
+	hive->reset_domain.wq = alloc_ordered_workqueue("amdgpu-reset-hive", 0);
+	if (!hive->reset_domain.wq) {
+		dev_err(adev->dev, "XGMI: failed allocating wq for reset domain!\n");
+		kfree(hive);
+		hive = NULL;
+		goto pro_end;
+	}
+
 	hive->hive_id = adev->gmc.xgmi.hive_id;
 	INIT_LIST_HEAD(&hive->device_list);
 	INIT_LIST_HEAD(&hive->node);
@@ -407,6 +415,7 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 	task_barrier_init(&hive->tb);
 	hive->pstate = AMDGPU_XGMI_PSTATE_UNKNOWN;
 	hive->hi_req_gpu = NULL;
+
 	/*
 	 * hive pstate on boot is high in vega20 so we have to go to low
 	 * pstate on after boot.
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +2 -0
index 0afca51c3c0c..2a89d820acea 100644
@@ -42,6 +42,8 @@ struct amdgpu_hive_info {
 		AMDGPU_XGMI_PSTATE_MAX_VEGA20,
 		AMDGPU_XGMI_PSTATE_UNKNOWN
 	} pstate;
+
+	struct amdgpu_reset_domain reset_domain;
 };
 
 struct amdgpu_pcs_ras_field {
Signature · 1 line
2.25.1
#11 lore raw

Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready

Hi Andrey,

Most part of the patches are OK, but the code will introduce a ib test fail on the disabled vcn of sienna_cichlid.

In SRIOV use case we will disable one vcn on sienna_cichlid, I have attached a patch to fix this issue, please check the attachment.

Best Regards,

Jingwen Chen

Quoted 195 lines · Andrey Grodzovsky

Hey, patches attached - i applied the patches and resolved merge conflicts but weren't able to test as my on board's network card doesn't work with 5.16 kernel (it does with 5.17, maybe it's Kconfig issue and i need to check more). The patches are on top of 'cababde192b2 Yifan Zhang         2 days ago     drm/amd/pm: fix mode2 reset fail for smu 13.0.5 ' commit.

Please test and let me know. Maybe by Monday I will be able to resolve the connectivity issue on 5.16.

Andrey

Quoted 187 lines · JingWen Chen

Hi Andrey,

Sorry for the misleading, I mean the whole patch series. We are depending on this patch series to fix the concurrency issue within SRIOV TDR sequence.

Quoted 180 lines · Andrey Grodzovsky

No problem if so but before I do,

JingWen - why you think this patch is needed as a standalone now ? It has no use without the entire feature together with it. Is it some changes you want to do on top of that code ?

Andrey

Quoted 169 lines · Alexander

[Public]

If it applies cleanly, feel free to drop it in.  I'll drop those patches for drm-next since they are already in drm-misc.

Alex

------------------------------------------------------------------------
*From:* amd-gfx <[email protected]> on behalf of Andrey Grodzovsky <[email protected]>
*Sent:* Thursday, February 24, 2022 11:24 AM
*To:* Chen, JingWen <[email protected]>; Christian König <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> *Cc:* Liu, Monk <[email protected]>; Chen, Horace <[email protected]>; Lazar, Lijo <[email protected]>; Koenig, Christian <[email protected]>; [email protected] <[email protected]> *Subject:* Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready
No because all the patch-set including this patch was landed into
drm-misc-next and will reach amd-staging-drm-next on the next upstream
rebase i guess.

Andrey

Quoted 149 lines · JingWen Chen

Hi Andrey,

Will you port this patch into amd-staging-drm-next?

Quoted 144 lines · Andrey Grodzovsky

All comments are fixed and code pushed. Thanks for everyone who helped reviewing.

Andrey

Quoted 138 lines · Christian König

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 7 lines

Before we initialize schedulers we must know which reset domain are we in - for single device there iis a single domain per device and so single wq per device. For XGMI the reset domain spans the entire XGMI hive and so the reset wq is per hive.

One more comment below, with that fixed Reviewed-by: Christian König <[email protected]>.

Quoted 85 lines

---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 45 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 34 ++-------------- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h   |  2 +

     3 files changed, 51 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +43 -0
index 9704b0e1fd82..00123b0013d3 100644
@@ -2287,6 +2287,47 @@ static int amdgpu_device_fw_loading(struct amdgpu_device *adev)
          return r;
      }
      +static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
+{
+    long timeout;
+    int r, i;
+
+    for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+        struct amdgpu_ring *ring = adev->rings[i];
+
+        /* No need to setup the GPU scheduler for rings that don't need it */
+        if (!ring || ring->no_scheduler)
+            continue;
+
+        switch (ring->funcs->type) {
+        case AMDGPU_RING_TYPE_GFX:
+            timeout = adev->gfx_timeout;
+            break;
+        case AMDGPU_RING_TYPE_COMPUTE:
+            timeout = adev->compute_timeout;
+            break;
+        case AMDGPU_RING_TYPE_SDMA:
+            timeout = adev->sdma_timeout;
+            break;
+        default:
+            timeout = adev->video_timeout;
+            break;
+        }
+
+        r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
+ ring->num_hw_submission, amdgpu_job_hang_limit,
+                   timeout, adev->reset_domain.wq, ring->sched_score, ring->name);
+        if (r) {
+            DRM_ERROR("Failed to create scheduler on ring %s.\n",
+                  ring->name);
+            return r;
+        }
+    }
+
+    return 0;
+}
+
+
      /**
       * amdgpu_device_ip_init - run init for hardware IPs
       *
@@ -2419,6 +2460,10 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
              }
          }
      +    r = amdgpu_device_init_schedulers(adev);
+    if (r)
+        goto init_failed;
+
          /* Don't init kfd if whole hive need to be reset during init */
          if (!adev->gmc.xgmi.pending_reset)
 amdgpu_amdkfd_device_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -4
index 45977a72b5dd..fa302540c69a 100644
@@ -457,8 +457,6 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
                        atomic_t *sched_score)
      {
          struct amdgpu_device *adev = ring->adev;
-    long timeout;
-    int r;
            if (!adev)
              return -EINVAL;
@@ -478,36 +476,12 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
 spin_lock_init(&ring->fence_drv.lock);
          ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
                           GFP_KERNEL);
-    if (!ring->fence_drv.fences)
-        return -ENOMEM;
Quoted 5 lines

     -    /* No need to setup the GPU scheduler for rings that don't need it */ -    if (ring->no_scheduler)
-        return 0;
+    ring->num_hw_submission = num_hw_submission;
+    ring->sched_score = sched_score;

Let's move this into the caller and then use ring->num_hw_submission in the fence code as well.

The maximum number of jobs on the ring is not really fence specific.

Regards,
Christian.

Quoted 31 lines

     -    switch (ring->funcs->type) {
-    case AMDGPU_RING_TYPE_GFX:
-        timeout = adev->gfx_timeout;
-        break;
-    case AMDGPU_RING_TYPE_COMPUTE:
-        timeout = adev->compute_timeout;
-        break;
-    case AMDGPU_RING_TYPE_SDMA:
-        timeout = adev->sdma_timeout;
-        break;
-    default:
-        timeout = adev->video_timeout;
-        break;
-    }
-
-    r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, -               num_hw_submission, amdgpu_job_hang_limit, -               timeout, NULL, sched_score, ring->name); -    if (r) {
-        DRM_ERROR("Failed to create scheduler on ring %s.\n", -              ring->name);
-        return r;
-    }
+    if (!ring->fence_drv.fences)
+        return -ENOMEM;
           return 0;
     }

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +0 -0
index fae7d185ad0d..7f20ce73a243 100644
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h struct amdgpu_ring { · line 257

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
@@ -251,6 +251,8 @@ struct amdgpu_ring {
          bool has_compute_vm_bug;
          bool            no_scheduler;
          int            hw_prio;
+    unsigned num_hw_submission;
+    atomic_t        *sched_score;
      };
        #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))

From f8e53c74ce7d094ac14648e9da6bf43b3098323f Mon Sep 17 00:00:00 2001
From: Jingwen Chen <[email protected]>
Date: Wed, 2 Mar 2022 17:44:38 +0800
Subject: [PATCH] drm/amd/amdgpu: set disabled vcn to no_schduler

[Why]
after the reset domain introduced, the sched.ready will be init after hw_init, which will overwrite the setup in vcn hw_init, and lead to vcn ib test fail.

[How]
set disabled vcn to no_scheduler

Change-Id I69cfd7b5fe0b9f86c263b293dc663a9368f055b0
---
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +2 -0
index da11ceba0698..5b515ca36748 100644
@@ -295,6 +295,7 @@ static int vcn_v3_0_hw_init(void *handle)
 			ring = &adev->vcn.inst[i].ring_dec;
 			if (amdgpu_vcn_is_disabled_vcn(adev, VCN_DECODE_RING, i)) {
 				ring->sched.ready = false;
+				ring->no_scheduler = true;
 				dev_info(adev->dev, "ring %s is disabled by hypervisor\n", ring->name);
 			} else {
 				ring->wptr = 0;
@@ -307,6 +308,7 @@ static int vcn_v3_0_hw_init(void *handle)
 				ring = &adev->vcn.inst[i].ring_enc[j];
 				if (amdgpu_vcn_is_disabled_vcn(adev, VCN_ENCODE_RING, i)) {
 					ring->sched.ready = false;
+					ring->no_scheduler = true;
 					dev_info(adev->dev, "ring %s is disabled by hypervisor\n", ring->name);
 				} else {
 					ring->wptr = 0;
Signature · 1 line
2.32.0 (Apple Git-132)
#12 lore raw

Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready

The patch is acked-by: Andrey Grodzovsky <[email protected]>

If you also smoked tested bare metal feel free to apply all the patches, if no let me know.

Andrey

Quoted 215 lines · JingWen Chen

Hi Andrey,

Most part of the patches are OK, but the code will introduce a ib test fail on the disabled vcn of sienna_cichlid.

In SRIOV use case we will disable one vcn on sienna_cichlid, I have attached a patch to fix this issue, please check the attachment.

Best Regards,

Jingwen Chen

Quoted 203 lines · Andrey Grodzovsky

Hey, patches attached - i applied the patches and resolved merge conflicts but weren't able to test as my on board's network card doesn't work with 5.16 kernel (it does with 5.17, maybe it's Kconfig issue and i need to check more). The patches are on top of 'cababde192b2 Yifan Zhang         2 days ago     drm/amd/pm: fix mode2 reset fail for smu 13.0.5 ' commit.

Please test and let me know. Maybe by Monday I will be able to resolve the connectivity issue on 5.16.

Andrey

Quoted 195 lines · JingWen Chen

Hi Andrey,

Sorry for the misleading, I mean the whole patch series. We are depending on this patch series to fix the concurrency issue within SRIOV TDR sequence.

Quoted 188 lines · Andrey Grodzovsky

No problem if so but before I do,

JingWen - why you think this patch is needed as a standalone now ? It has no use without the entire feature together with it. Is it some changes you want to do on top of that code ?

Andrey

Quoted 177 lines · Alexander

[Public]

If it applies cleanly, feel free to drop it in.  I'll drop those patches for drm-next since they are already in drm-misc.

Alex

------------------------------------------------------------------------
*From:* amd-gfx <[email protected]> on behalf of Andrey Grodzovsky <[email protected]>
*Sent:* Thursday, February 24, 2022 11:24 AM
*To:* Chen, JingWen <[email protected]>; Christian König <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> *Cc:* Liu, Monk <[email protected]>; Chen, Horace <[email protected]>; Lazar, Lijo <[email protected]>; Koenig, Christian <[email protected]>; [email protected] <[email protected]> *Subject:* Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready
No because all the patch-set including this patch was landed into
drm-misc-next and will reach amd-staging-drm-next on the next upstream
rebase i guess.

Andrey

Quoted 157 lines · JingWen Chen

Hi Andrey,

Will you port this patch into amd-staging-drm-next?

Quoted 152 lines · Andrey Grodzovsky

All comments are fixed and code pushed. Thanks for everyone who helped reviewing.

Andrey

Quoted 146 lines · Christian König

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 7 lines

Before we initialize schedulers we must know which reset domain are we in - for single device there iis a single domain per device and so single wq per device. For XGMI the reset domain spans the entire XGMI hive and so the reset wq is per hive.

One more comment below, with that fixed Reviewed-by: Christian König <[email protected]>.

Quoted 80 lines

---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 45 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 34 ++-------------- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h   |  2 +

      3 files changed, 51 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +43 -0
index 9704b0e1fd82..00123b0013d3 100644
@@ -2287,6 +2287,47 @@ static int amdgpu_device_fw_loading(struct amdgpu_device *adev)
          return r;
      }
      +static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
+{
+    long timeout;
+    int r, i;
+
+    for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+        struct amdgpu_ring *ring = adev->rings[i];
+
+        /* No need to setup the GPU scheduler for rings that don't need it */
+        if (!ring || ring->no_scheduler)
+            continue;
+
+        switch (ring->funcs->type) {
+        case AMDGPU_RING_TYPE_GFX:
+            timeout = adev->gfx_timeout;
+            break;
+        case AMDGPU_RING_TYPE_COMPUTE:
+            timeout = adev->compute_timeout;
+            break;
+        case AMDGPU_RING_TYPE_SDMA:
+            timeout = adev->sdma_timeout;
+            break;
+        default:
+            timeout = adev->video_timeout;
+            break;
+        }
+
+        r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
+ ring->num_hw_submission, amdgpu_job_hang_limit,
+                   timeout, adev->reset_domain.wq, ring->sched_score, ring->name);
+        if (r) {
+            DRM_ERROR("Failed to create scheduler on ring %s.\n",
+                  ring->name);
+            return r;
+        }
+    }
+
+    return 0;
+}
+
+
      /**
       * amdgpu_device_ip_init - run init for hardware IPs
       *
@@ -2419,6 +2460,10 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
              }
          }
      +    r = amdgpu_device_init_schedulers(adev);
+    if (r)
+        goto init_failed;
+
          /* Don't init kfd if whole hive need to be reset during init */
          if (!adev->gmc.xgmi.pending_reset)
 amdgpu_amdkfd_device_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -2
index 45977a72b5dd..fa302540c69a 100644
@@ -457,8 +457,6 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
                        atomic_t *sched_score)
      {
          struct amdgpu_device *adev = ring->adev;
-    long timeout;
-    int r;
            if (!adev)
              return -EINVAL;

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring, · line 481

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -4
@@ -478,36 +476,12 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
 spin_lock_init(&ring->fence_drv.lock);
          ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
                           GFP_KERNEL);
-    if (!ring->fence_drv.fences)
-        return -ENOMEM;
      -    /* No need to setup the GPU scheduler for rings that don't need it */
-    if (ring->no_scheduler)
-        return 0;
+    ring->num_hw_submission = num_hw_submission;
+    ring->sched_score = sched_score;

Let's move this into the caller and then use ring->num_hw_submission in the fence code as well.

The maximum number of jobs on the ring is not really fence specific.

Regards,
Christian.

Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -22
      -    switch (ring->funcs->type) {
-    case AMDGPU_RING_TYPE_GFX:
-        timeout = adev->gfx_timeout;
-        break;
-    case AMDGPU_RING_TYPE_COMPUTE:
-        timeout = adev->compute_timeout;
-        break;
-    case AMDGPU_RING_TYPE_SDMA:
-        timeout = adev->sdma_timeout;
-        break;
-    default:
-        timeout = adev->video_timeout;
-        break;
-    }
-
-    r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
-               num_hw_submission, amdgpu_job_hang_limit,
-               timeout, NULL, sched_score, ring->name);
-    if (r) {
-        DRM_ERROR("Failed to create scheduler on ring %s.\n",
-              ring->name);
-        return r;
-    }
+    if (!ring->fence_drv.fences)
+        return -ENOMEM;
            return 0;
      }
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
index fae7d185ad0d..7f20ce73a243 100644
@@ -251,6 +251,8 @@ struct amdgpu_ring {
          bool has_compute_vm_bug;
          bool            no_scheduler;
          int            hw_prio;
+    unsigned num_hw_submission;
+    atomic_t        *sched_score;
      };
        #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
#13 lore raw

Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready

Hi Andrey,

I don't have the bare mental environment, I can only test the SRIOV cases.

Best Regards,
JingWen Chen

Quoted 224 lines · Andrey

The patch is acked-by: Andrey Grodzovsky <[email protected]>

If you also smoked tested bare metal feel free to apply all the patches, if no let me know.

Andrey

Quoted 215 lines · JingWen Chen

Hi Andrey,

Most part of the patches are OK, but the code will introduce a ib test fail on the disabled vcn of sienna_cichlid.

In SRIOV use case we will disable one vcn on sienna_cichlid, I have attached a patch to fix this issue, please check the attachment.

Best Regards,

Jingwen Chen

Quoted 203 lines · Andrey Grodzovsky

Hey, patches attached - i applied the patches and resolved merge conflicts but weren't able to test as my on board's network card doesn't work with 5.16 kernel (it does with 5.17, maybe it's Kconfig issue and i need to check more).
The patches are on top of 'cababde192b2 Yifan Zhang 2 days ago drm/amd/pm: fix mode2 reset fail for smu 13.0.5 ' commit.

Please test and let me know. Maybe by Monday I will be able to resolve the connectivity issue on 5.16.

Andrey

Quoted 195 lines · JingWen Chen

Hi Andrey,

Sorry for the misleading, I mean the whole patch series. We are depending on this patch series to fix the concurrency issue within SRIOV TDR sequence.

Quoted 188 lines · Andrey Grodzovsky

No problem if so but before I do,

JingWen - why you think this patch is needed as a standalone now ? It has no use without the entire feature together with it. Is it some changes you want to do on top of that code ?

Andrey

Quoted 177 lines · Alexander

[Public]

If it applies cleanly, feel free to drop it in. I'll drop those patches for drm-next since they are already in drm-misc.

Alex

------------------------------------------------------------------------
*From:* amd-gfx <[email protected]> on behalf of Andrey Grodzovsky <[email protected]>
*Sent:* Thursday, February 24, 2022 11:24 AM
*To:* Chen, JingWen <[email protected]>; Christian König <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> *Cc:* Liu, Monk <[email protected]>; Chen, Horace <[email protected]>; Lazar, Lijo <[email protected]>; Koenig, Christian <[email protected]>; [email protected] <[email protected]> *Subject:* Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready
No because all the patch-set including this patch was landed into
drm-misc-next and will reach amd-staging-drm-next on the next upstream
rebase i guess.

Andrey

Quoted 157 lines · JingWen Chen

Hi Andrey,

Will you port this patch into amd-staging-drm-next?

Quoted 152 lines · Andrey Grodzovsky

All comments are fixed and code pushed. Thanks for everyone who helped reviewing.

Andrey

Quoted 146 lines · Christian König

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 7 lines

Before we initialize schedulers we must know which reset domain are we in - for single device there iis a single domain per device and so single wq per device. For XGMI the reset domain spans the entire XGMI hive and so the reset wq is per hive.

One more comment below, with that fixed Reviewed-by: Christian König <[email protected]>.

Quoted 80 lines

---

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 45 ++++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 34 ++--------------
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h   |  2 +
     3 files changed, 51 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +43 -0
index 9704b0e1fd82..00123b0013d3 100644
@@ -2287,6 +2287,47 @@ static int amdgpu_device_fw_loading(struct amdgpu_device *adev)
         return r;
     }
     +static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
+{
+    long timeout;
+    int r, i;
+
+    for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+        struct amdgpu_ring *ring = adev->rings[i];
+
+        /* No need to setup the GPU scheduler for rings that don't need it */
+        if (!ring || ring->no_scheduler)
+            continue;
+
+        switch (ring->funcs->type) {
+        case AMDGPU_RING_TYPE_GFX:
+            timeout = adev->gfx_timeout;
+            break;
+        case AMDGPU_RING_TYPE_COMPUTE:
+            timeout = adev->compute_timeout;
+            break;
+        case AMDGPU_RING_TYPE_SDMA:
+            timeout = adev->sdma_timeout;
+            break;
+        default:
+            timeout = adev->video_timeout;
+            break;
+        }
+
+        r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
+ ring->num_hw_submission, amdgpu_job_hang_limit,
+                   timeout, adev->reset_domain.wq, ring->sched_score, ring->name);
+        if (r) {
+            DRM_ERROR("Failed to create scheduler on ring %s.\n",
+                  ring->name);
+            return r;
+        }
+    }
+
+    return 0;
+}
+
+
     /**
      * amdgpu_device_ip_init - run init for hardware IPs
      *
@@ -2419,6 +2460,10 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
             }
         }
     +    r = amdgpu_device_init_schedulers(adev);
+    if (r)
+        goto init_failed;
+
         /* Don't init kfd if whole hive need to be reset during init */
         if (!adev->gmc.xgmi.pending_reset)
 amdgpu_amdkfd_device_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -2
index 45977a72b5dd..fa302540c69a 100644
@@ -457,8 +457,6 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
                       atomic_t *sched_score)
     {
         struct amdgpu_device *adev = ring->adev;
-    long timeout;
-    int r;
           if (!adev)
             return -EINVAL;

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring, · line 481

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -4
@@ -478,36 +476,12 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
 spin_lock_init(&ring->fence_drv.lock);
         ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
                          GFP_KERNEL);
-    if (!ring->fence_drv.fences)
-        return -ENOMEM;
     -    /* No need to setup the GPU scheduler for rings that don't need it */
-    if (ring->no_scheduler)
-        return 0;
+    ring->num_hw_submission = num_hw_submission;
+    ring->sched_score = sched_score;

Let's move this into the caller and then use ring->num_hw_submission in the fence code as well.

The maximum number of jobs on the ring is not really fence specific.

Regards,
Christian.

Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -22
     -    switch (ring->funcs->type) {
-    case AMDGPU_RING_TYPE_GFX:
-        timeout = adev->gfx_timeout;
-        break;
-    case AMDGPU_RING_TYPE_COMPUTE:
-        timeout = adev->compute_timeout;
-        break;
-    case AMDGPU_RING_TYPE_SDMA:
-        timeout = adev->sdma_timeout;
-        break;
-    default:
-        timeout = adev->video_timeout;
-        break;
-    }
-
-    r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
-               num_hw_submission, amdgpu_job_hang_limit,
-               timeout, NULL, sched_score, ring->name);
-    if (r) {
-        DRM_ERROR("Failed to create scheduler on ring %s.\n",
-              ring->name);
-        return r;
-    }
+    if (!ring->fence_drv.fences)
+        return -ENOMEM;
           return 0;
     }
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
index fae7d185ad0d..7f20ce73a243 100644
@@ -251,6 +251,8 @@ struct amdgpu_ring {
         bool has_compute_vm_bug;
         bool            no_scheduler;
         int            hw_prio;
+    unsigned num_hw_submission;
+    atomic_t        *sched_score;
     };
       #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
#14 lore raw

Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready

OK, i will do quick smoke test tomorrow and push all of it it then.

Andrey

Quoted 233 lines · JingWen

Hi Andrey,

I don't have the bare mental environment, I can only test the SRIOV cases.

Best Regards,
JingWen Chen

Quoted 224 lines · Andrey

The patch is acked-by: Andrey Grodzovsky <[email protected]>

If you also smoked tested bare metal feel free to apply all the patches, if no let me know.

Andrey

Quoted 215 lines · JingWen Chen

Hi Andrey,

Most part of the patches are OK, but the code will introduce a ib test fail on the disabled vcn of sienna_cichlid.

In SRIOV use case we will disable one vcn on sienna_cichlid, I have attached a patch to fix this issue, please check the attachment.

Best Regards,

Jingwen Chen

Quoted 203 lines · Andrey Grodzovsky

Hey, patches attached - i applied the patches and resolved merge conflicts but weren't able to test as my on board's network card doesn't work with 5.16 kernel (it does with 5.17, maybe it's Kconfig issue and i need to check more).
The patches are on top of 'cababde192b2 Yifan Zhang 2 days ago drm/amd/pm: fix mode2 reset fail for smu 13.0.5 ' commit.

Please test and let me know. Maybe by Monday I will be able to resolve the connectivity issue on 5.16.

Andrey

Quoted 195 lines · JingWen Chen

Hi Andrey,

Sorry for the misleading, I mean the whole patch series. We are depending on this patch series to fix the concurrency issue within SRIOV TDR sequence.

Quoted 188 lines · Andrey Grodzovsky

No problem if so but before I do,

JingWen - why you think this patch is needed as a standalone now ? It has no use without the entire feature together with it. Is it some changes you want to do on top of that code ?

Andrey

Quoted 177 lines · Alexander

[Public]

If it applies cleanly, feel free to drop it in. I'll drop those patches for drm-next since they are already in drm-misc.

Alex

------------------------------------------------------------------------
*From:* amd-gfx <[email protected]> on behalf of Andrey Grodzovsky <[email protected]>
*Sent:* Thursday, February 24, 2022 11:24 AM
*To:* Chen, JingWen <[email protected]>; Christian König <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> *Cc:* Liu, Monk <[email protected]>; Chen, Horace <[email protected]>; Lazar, Lijo <[email protected]>; Koenig, Christian <[email protected]>; [email protected] <[email protected]> *Subject:* Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready
No because all the patch-set including this patch was landed into
drm-misc-next and will reach amd-staging-drm-next on the next upstream
rebase i guess.

Andrey

Quoted 157 lines · JingWen Chen

Hi Andrey,

Will you port this patch into amd-staging-drm-next?

Quoted 152 lines · Andrey Grodzovsky

All comments are fixed and code pushed. Thanks for everyone who helped reviewing.

Andrey

Quoted 146 lines · Christian König

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 7 lines

Before we initialize schedulers we must know which reset domain are we in - for single device there iis a single domain per device and so single wq per device. For XGMI the reset domain spans the entire XGMI hive and so the reset wq is per hive.

One more comment below, with that fixed Reviewed-by: Christian König <[email protected]>.

Quoted 80 lines

---

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 45 ++++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 34 ++--------------
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h   |  2 +
      3 files changed, 51 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +43 -0
index 9704b0e1fd82..00123b0013d3 100644
@@ -2287,6 +2287,47 @@ static int amdgpu_device_fw_loading(struct amdgpu_device *adev)
          return r;
      }
      +static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
+{
+    long timeout;
+    int r, i;
+
+    for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+        struct amdgpu_ring *ring = adev->rings[i];
+
+        /* No need to setup the GPU scheduler for rings that don't need it */
+        if (!ring || ring->no_scheduler)
+            continue;
+
+        switch (ring->funcs->type) {
+        case AMDGPU_RING_TYPE_GFX:
+            timeout = adev->gfx_timeout;
+            break;
+        case AMDGPU_RING_TYPE_COMPUTE:
+            timeout = adev->compute_timeout;
+            break;
+        case AMDGPU_RING_TYPE_SDMA:
+            timeout = adev->sdma_timeout;
+            break;
+        default:
+            timeout = adev->video_timeout;
+            break;
+        }
+
+        r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
+ ring->num_hw_submission, amdgpu_job_hang_limit,
+                   timeout, adev->reset_domain.wq, ring->sched_score, ring->name);
+        if (r) {
+            DRM_ERROR("Failed to create scheduler on ring %s.\n",
+                  ring->name);
+            return r;
+        }
+    }
+
+    return 0;
+}
+
+
      /**
       * amdgpu_device_ip_init - run init for hardware IPs
       *
@@ -2419,6 +2460,10 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
              }
          }
      +    r = amdgpu_device_init_schedulers(adev);
+    if (r)
+        goto init_failed;
+
          /* Don't init kfd if whole hive need to be reset during init */
          if (!adev->gmc.xgmi.pending_reset)
 amdgpu_amdkfd_device_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -2
index 45977a72b5dd..fa302540c69a 100644
@@ -457,8 +457,6 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
                        atomic_t *sched_score)
      {
          struct amdgpu_device *adev = ring->adev;
-    long timeout;
-    int r;
            if (!adev)
              return -EINVAL;

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring, · line 481

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -4
@@ -478,36 +476,12 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
 spin_lock_init(&ring->fence_drv.lock);
          ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
                           GFP_KERNEL);
-    if (!ring->fence_drv.fences)
-        return -ENOMEM;
      -    /* No need to setup the GPU scheduler for rings that don't need it */
-    if (ring->no_scheduler)
-        return 0;
+    ring->num_hw_submission = num_hw_submission;
+    ring->sched_score = sched_score;

Let's move this into the caller and then use ring->num_hw_submission in the fence code as well.

The maximum number of jobs on the ring is not really fence specific.

Regards,
Christian.

Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -22
      -    switch (ring->funcs->type) {
-    case AMDGPU_RING_TYPE_GFX:
-        timeout = adev->gfx_timeout;
-        break;
-    case AMDGPU_RING_TYPE_COMPUTE:
-        timeout = adev->compute_timeout;
-        break;
-    case AMDGPU_RING_TYPE_SDMA:
-        timeout = adev->sdma_timeout;
-        break;
-    default:
-        timeout = adev->video_timeout;
-        break;
-    }
-
-    r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
-               num_hw_submission, amdgpu_job_hang_limit,
-               timeout, NULL, sched_score, ring->name);
-    if (r) {
-        DRM_ERROR("Failed to create scheduler on ring %s.\n",
-              ring->name);
-        return r;
-    }
+    if (!ring->fence_drv.fences)
+        return -ENOMEM;
            return 0;
      }
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
index fae7d185ad0d..7f20ce73a243 100644
@@ -251,6 +251,8 @@ struct amdgpu_ring {
          bool has_compute_vm_bug;
          bool            no_scheduler;
          int            hw_prio;
+    unsigned num_hw_submission;
+    atomic_t        *sched_score;
      };
        #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
#15 lore raw

Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready

I pushed all the changes including your patch.

Andrey

Quoted 248 lines · Andrey Grodzovsky

OK, i will do quick smoke test tomorrow and push all of it it then.

Andrey

Quoted 243 lines · JingWen

Hi Andrey,

I don't have the bare mental environment, I can only test the SRIOV cases.

Best Regards,
JingWen Chen

Quoted 234 lines · Andrey

The patch is acked-by: Andrey Grodzovsky <[email protected]>

If you also smoked tested bare metal feel free to apply all the patches, if no let me know.

Andrey

Quoted 225 lines · JingWen Chen

Hi Andrey,

Most part of the patches are OK, but the code will introduce a ib test fail on the disabled vcn of sienna_cichlid.

In SRIOV use case we will disable one vcn on sienna_cichlid, I have attached a patch to fix this issue, please check the attachment.

Best Regards,

Jingwen Chen

Quoted 213 lines · Andrey Grodzovsky

Hey, patches attached - i applied the patches and resolved merge conflicts but weren't able to test as my on board's network card doesn't work with 5.16 kernel (it does with 5.17, maybe it's Kconfig issue and i need to check more). The patches are on top of 'cababde192b2 Yifan Zhang         2 days ago     drm/amd/pm: fix mode2 reset fail for smu 13.0.5 ' commit.

Please test and let me know. Maybe by Monday I will be able to resolve the connectivity issue on 5.16.

Andrey

Quoted 205 lines · JingWen Chen

Hi Andrey,

Sorry for the misleading, I mean the whole patch series. We are depending on this patch series to fix the concurrency issue within SRIOV TDR sequence.

Quoted 198 lines · Andrey Grodzovsky

No problem if so but before I do,

JingWen - why you think this patch is needed as a standalone now ? It has no use without the entire feature together with it. Is it some changes you want to do on top of that code ?

Andrey

Quoted 187 lines · Alexander

[Public]

If it applies cleanly, feel free to drop it in. I'll drop those patches for drm-next since they are already in drm-misc.

Alex

------------------------------------------------------------------------

*From:* amd-gfx <[email protected]> on behalf of Andrey Grodzovsky <[email protected]>
*Sent:* Thursday, February 24, 2022 11:24 AM
*To:* Chen, JingWen <[email protected]>; Christian König <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> *Cc:* Liu, Monk <[email protected]>; Chen, Horace <[email protected]>; Lazar, Lijo <[email protected]>; Koenig, Christian <[email protected]>; [email protected] <[email protected]> *Subject:* Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready
No because all the patch-set including this patch was landed into
drm-misc-next and will reach amd-staging-drm-next on the next upstream
rebase i guess.

Andrey

Quoted 166 lines · JingWen Chen

Hi Andrey,

Will you port this patch into amd-staging-drm-next?

Quoted 161 lines · Andrey Grodzovsky

All comments are fixed and code pushed. Thanks for everyone who helped reviewing.

Andrey

Quoted 155 lines · Christian König

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 7 lines

Before we initialize schedulers we must know which reset domain are we in - for single device there iis a single domain per device and so single wq per device. For XGMI the reset domain spans the entire XGMI hive and so the reset wq is per hive.

One more comment below, with that fixed Reviewed-by: Christian König <[email protected]>.

Quoted 94 lines

---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 45
++++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 34
++--------------
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  2 +

      3 files changed, 51 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8 -0
index 9704b0e1fd82..00123b0013d3 100644
@@ -2287,6 +2287,47 @@ static int 
 amdgpu_device_fw_loading(struct amdgpu_device *adev)
           return r;
       }
       +static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
+{
+    long timeout;
+    int r, i;
+
+    for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+        struct amdgpu_ring *ring = adev->rings[i];
+
+        /* No need to setup the GPU scheduler for rings 

that don't need it */
+        if (!ring || ring->no_scheduler)
+            continue;

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +19 -0
+
+        switch (ring->funcs->type) {
+        case AMDGPU_RING_TYPE_GFX:
+            timeout = adev->gfx_timeout;
+            break;
+        case AMDGPU_RING_TYPE_COMPUTE:
+            timeout = adev->compute_timeout;
+            break;
+        case AMDGPU_RING_TYPE_SDMA:
+            timeout = adev->sdma_timeout;
+            break;
+        default:
+            timeout = adev->video_timeout;
+            break;
+        }
+
+        r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
+ ring->num_hw_submission, amdgpu_job_hang_limit,
+                   timeout, adev->reset_domain.wq, 

ring->sched_score, ring->name);
+        if (r) {
+            DRM_ERROR("Failed to create scheduler on ring %s.\n",
+                  ring->name);
+            return r;
+        }
+    }

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -0
+
+    return 0;
+}
+
+

      /**
       * amdgpu_device_ip_init - run init for hardware IPs *

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
@@ -2419,6 +2460,10 @@ static int 
 amdgpu_device_ip_init(struct amdgpu_device *adev)
               }
           }
       +    r = amdgpu_device_init_schedulers(adev);
+    if (r)
+        goto init_failed;
+
           /* Don't init kfd if whole hive need to be reset during init */
           if (!adev->gmc.xgmi.pending_reset)

amdgpu_amdkfd_device_init(adev);

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -4
index 45977a72b5dd..fa302540c69a 100644
@@ -457,8 +457,6 @@ int 
 amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
                         atomic_t *sched_score)
       {
           struct amdgpu_device *adev = ring->adev;
-    long timeout;
-    int r;
             if (!adev)
               return -EINVAL;
@@ -478,36 +476,12 @@ int 
 amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
 spin_lock_init(&ring->fence_drv.lock);
           ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
                            GFP_KERNEL);
-    if (!ring->fence_drv.fences)
-        return -ENOMEM;
Quoted 5 lines

      -    /* No need to setup the GPU scheduler for rings that don't need it */ -    if (ring->no_scheduler)
-        return 0;
+    ring->num_hw_submission = num_hw_submission;
+    ring->sched_score = sched_score;

Let's move this into the caller and then use ring->num_hw_submission in the fence code as well.

The maximum number of jobs on the ring is not really fence specific.

Regards,
Christian.

Quoted 39 lines

      -    switch (ring->funcs->type) {
-    case AMDGPU_RING_TYPE_GFX:
-        timeout = adev->gfx_timeout;
-        break;
-    case AMDGPU_RING_TYPE_COMPUTE:
-        timeout = adev->compute_timeout;
-        break;
-    case AMDGPU_RING_TYPE_SDMA:
-        timeout = adev->sdma_timeout;
-        break;
-    default:
-        timeout = adev->video_timeout;
-        break;
-    }
-
-    r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, -               num_hw_submission, amdgpu_job_hang_limit, -               timeout, NULL, sched_score, ring->name); -    if (r) {
-        DRM_ERROR("Failed to create scheduler on ring %s.\n", -              ring->name);
-        return r;
-    }
+    if (!ring->fence_drv.fences)
+        return -ENOMEM;
            return 0;
      }

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
index fae7d185ad0d..7f20ce73a243 100644
@@ -251,6 +251,8 @@ struct amdgpu_ring {
           bool has_compute_vm_bug;
           bool            no_scheduler;
           int            hw_prio;
+    unsigned num_hw_submission;
+    atomic_t        *sched_score;
       };
         #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
#16 lore raw

Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready

Thanks a lot

Best Regards,
JingWen Chen

Quoted 245 lines · Andrey

I pushed all the changes including your patch.

Andrey

Quoted 238 lines · Andrey Grodzovsky

OK, i will do quick smoke test tomorrow and push all of it it then.

Andrey

Quoted 233 lines · JingWen

Hi Andrey,

I don't have the bare mental environment, I can only test the SRIOV cases.

Best Regards,
JingWen Chen

Quoted 224 lines · Andrey

The patch is acked-by: Andrey Grodzovsky <[email protected]>

If you also smoked tested bare metal feel free to apply all the patches, if no let me know.

Andrey

Quoted 215 lines · JingWen Chen

Hi Andrey,

Most part of the patches are OK, but the code will introduce a ib test fail on the disabled vcn of sienna_cichlid.

In SRIOV use case we will disable one vcn on sienna_cichlid, I have attached a patch to fix this issue, please check the attachment.

Best Regards,

Jingwen Chen

Quoted 203 lines · Andrey Grodzovsky

Hey, patches attached - i applied the patches and resolved merge conflicts but weren't able to test as my on board's network card doesn't work with 5.16 kernel (it does with 5.17, maybe it's Kconfig issue and i need to check more).
The patches are on top of 'cababde192b2 Yifan Zhang 2 days ago drm/amd/pm: fix mode2 reset fail for smu 13.0.5 ' commit.

Please test and let me know. Maybe by Monday I will be able to resolve the connectivity issue on 5.16.

Andrey

Quoted 195 lines · JingWen Chen

Hi Andrey,

Sorry for the misleading, I mean the whole patch series. We are depending on this patch series to fix the concurrency issue within SRIOV TDR sequence.

Quoted 188 lines · Andrey Grodzovsky

No problem if so but before I do,

JingWen - why you think this patch is needed as a standalone now ? It has no use without the entire feature together with it. Is it some changes you want to do on top of that code ?

Andrey

Quoted 177 lines · Alexander

[Public]

If it applies cleanly, feel free to drop it in. I'll drop those patches for drm-next since they are already in drm-misc.

Alex

------------------------------------------------------------------------
*From:* amd-gfx <[email protected]> on behalf of Andrey Grodzovsky <[email protected]>
*Sent:* Thursday, February 24, 2022 11:24 AM
*To:* Chen, JingWen <[email protected]>; Christian König <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> *Cc:* Liu, Monk <[email protected]>; Chen, Horace <[email protected]>; Lazar, Lijo <[email protected]>; Koenig, Christian <[email protected]>; [email protected] <[email protected]> *Subject:* Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready
No because all the patch-set including this patch was landed into
drm-misc-next and will reach amd-staging-drm-next on the next upstream
rebase i guess.

Andrey

Quoted 157 lines · JingWen Chen

Hi Andrey,

Will you port this patch into amd-staging-drm-next?

Quoted 152 lines · Andrey Grodzovsky

All comments are fixed and code pushed. Thanks for everyone who helped reviewing.

Andrey

Quoted 146 lines · Christian König

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 7 lines

Before we initialize schedulers we must know which reset
domain are we in - for single device there iis a single
domain per device and so single wq per device. For XGMI
the reset domain spans the entire XGMI hive and so the
reset wq is per hive.

Signed-off-by: Andrey Grodzovsky <[email protected]>

One more comment below, with that fixed Reviewed-by: Christian König <[email protected]>.

Quoted 90 lines

---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 45 ++++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 34 ++--------------
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 2 +
3 files changed, 51 insertions(+), 30 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 9704b0e1fd82..00123b0013d3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -2287,6 +2287,47 @@ static int amdgpu_device_fw_loading(struct amdgpu_device *adev)
return r;
}
+static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
+{
+ long timeout;
+ int r, i;
+
+ for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+ struct amdgpu_ring *ring = adev->rings[i];
+
+ /* No need to setup the GPU scheduler for rings that don't need it */
+ if (!ring || ring->no_scheduler)
+ continue;
+
+ switch (ring->funcs->type) {
+ case AMDGPU_RING_TYPE_GFX:
+ timeout = adev->gfx_timeout;
+ break;
+ case AMDGPU_RING_TYPE_COMPUTE:
+ timeout = adev->compute_timeout;
+ break;
+ case AMDGPU_RING_TYPE_SDMA:
+ timeout = adev->sdma_timeout;
+ break;
+ default:
+ timeout = adev->video_timeout;
+ break;
+ }
+
+ r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
+ ring->num_hw_submission, amdgpu_job_hang_limit,
+ timeout, adev->reset_domain.wq, ring->sched_score, ring->name);
+ if (r) {
+ DRM_ERROR("Failed to create scheduler on ring %s.\n",
+ ring->name);
+ return r;
+ }
+ }
+
+ return 0;
+}
+
+
/**
* amdgpu_device_ip_init - run init for hardware IPs
*
@@ -2419,6 +2460,10 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
}
}
+ r = amdgpu_device_init_schedulers(adev);
+ if (r)
+ goto init_failed;
+
/* Don't init kfd if whole hive need to be reset during init */
if (!adev->gmc.xgmi.pending_reset)
amdgpu_amdkfd_device_init(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
index 45977a72b5dd..fa302540c69a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
@@ -457,8 +457,6 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
atomic_t *sched_score)
{
struct amdgpu_device *adev = ring->adev;
- long timeout;
- int r;
if (!adev)
return -EINVAL;
@@ -478,36 +476,12 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
spin_lock_init(&ring->fence_drv.lock);
ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
GFP_KERNEL);
- if (!ring->fence_drv.fences)
- return -ENOMEM;
- /* No need to setup the GPU scheduler for rings that don't need it */
- if (ring->no_scheduler)
- return 0;
+ ring->num_hw_submission = num_hw_submission;
+ ring->sched_score = sched_score;

Let's move this into the caller and then use ring->num_hw_submission in the fence code as well.

The maximum number of jobs on the ring is not really fence specific.

Regards,
Christian.

Quoted 39 lines

- switch (ring->funcs->type) {
- case AMDGPU_RING_TYPE_GFX:
- timeout = adev->gfx_timeout;
- break;
- case AMDGPU_RING_TYPE_COMPUTE:
- timeout = adev->compute_timeout;
- break;
- case AMDGPU_RING_TYPE_SDMA:
- timeout = adev->sdma_timeout;
- break;
- default:
- timeout = adev->video_timeout;
- break;
- }
-
- r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
- num_hw_submission, amdgpu_job_hang_limit,
- timeout, NULL, sched_score, ring->name);
- if (r) {
- DRM_ERROR("Failed to create scheduler on ring %s.\n",
- ring->name);
- return r;
- }
+ if (!ring->fence_drv.fences)
+ return -ENOMEM;
return 0;
}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
index fae7d185ad0d..7f20ce73a243 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
@@ -251,6 +251,8 @@ struct amdgpu_ring {
bool has_compute_vm_bug;
bool no_scheduler;
int hw_prio;
+ unsigned num_hw_submission;
+ atomic_t *sched_score;
};
#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))

maintainer
#17 lore raw

Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready

In reply to JingWen Chen

Hi Jingwen,

can you please always send patches using "git send-email" and not as attachment? This one for example went under my radar because of this.

Regarding the patch itself can you please also remove the code which touches "ring->sched.ready"?

That variable is internal to the scheduler and should never ever be touched by any hardware specific code.

Thanks,
Christian.

Am 02.03.22 um 10:51 schrieb JingWen Chen:

Quoted 215 lines

Hi Andrey,

Most part of the patches are OK, but the code will introduce a ib test fail on the disabled vcn of sienna_cichlid.

In SRIOV use case we will disable one vcn on sienna_cichlid, I have attached a patch to fix this issue, please check the attachment.

Best Regards,

Jingwen Chen

Quoted 203 lines · Andrey Grodzovsky

Hey, patches attached - i applied the patches and resolved merge conflicts but weren't able to test as my on board's network card doesn't work with 5.16 kernel (it does with 5.17, maybe it's Kconfig issue and i need to check more). The patches are on top of 'cababde192b2 Yifan Zhang         2 days ago     drm/amd/pm: fix mode2 reset fail for smu 13.0.5 ' commit.

Please test and let me know. Maybe by Monday I will be able to resolve the connectivity issue on 5.16.

Andrey

Quoted 195 lines · JingWen Chen

Hi Andrey,

Sorry for the misleading, I mean the whole patch series. We are depending on this patch series to fix the concurrency issue within SRIOV TDR sequence.

Quoted 188 lines · Andrey Grodzovsky

No problem if so but before I do,

JingWen - why you think this patch is needed as a standalone now ? It has no use without the entire feature together with it. Is it some changes you want to do on top of that code ?

Andrey

Quoted 177 lines · Alexander

[Public]

If it applies cleanly, feel free to drop it in.  I'll drop those patches for drm-next since they are already in drm-misc.

Alex

------------------------------------------------------------------------
*From:* amd-gfx <[email protected]> on behalf of Andrey Grodzovsky <[email protected]>
*Sent:* Thursday, February 24, 2022 11:24 AM
*To:* Chen, JingWen <[email protected]>; Christian König <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> *Cc:* Liu, Monk <[email protected]>; Chen, Horace <[email protected]>; Lazar, Lijo <[email protected]>; Koenig, Christian <[email protected]>; [email protected] <[email protected]> *Subject:* Re: [RFC v4 02/11] drm/amdgpu: Move scheduler init to after XGMI is ready
No because all the patch-set including this patch was landed into
drm-misc-next and will reach amd-staging-drm-next on the next upstream
rebase i guess.

Andrey

Quoted 157 lines · JingWen Chen

Hi Andrey,

Will you port this patch into amd-staging-drm-next?

Quoted 152 lines · Andrey Grodzovsky

All comments are fixed and code pushed. Thanks for everyone who helped reviewing.

Andrey

Quoted 146 lines · Christian König

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 7 lines

Before we initialize schedulers we must know which reset domain are we in - for single device there iis a single domain per device and so single wq per device. For XGMI the reset domain spans the entire XGMI hive and so the reset wq is per hive.

One more comment below, with that fixed Reviewed-by: Christian König <[email protected]>.

Quoted 80 lines

---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 45 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 34 ++-------------- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h   |  2 +

      3 files changed, 51 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +43 -0
index 9704b0e1fd82..00123b0013d3 100644
@@ -2287,6 +2287,47 @@ static int amdgpu_device_fw_loading(struct amdgpu_device *adev)
          return r;
      }
      +static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
+{
+    long timeout;
+    int r, i;
+
+    for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
+        struct amdgpu_ring *ring = adev->rings[i];
+
+        /* No need to setup the GPU scheduler for rings that don't need it */
+        if (!ring || ring->no_scheduler)
+            continue;
+
+        switch (ring->funcs->type) {
+        case AMDGPU_RING_TYPE_GFX:
+            timeout = adev->gfx_timeout;
+            break;
+        case AMDGPU_RING_TYPE_COMPUTE:
+            timeout = adev->compute_timeout;
+            break;
+        case AMDGPU_RING_TYPE_SDMA:
+            timeout = adev->sdma_timeout;
+            break;
+        default:
+            timeout = adev->video_timeout;
+            break;
+        }
+
+        r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
+ ring->num_hw_submission, amdgpu_job_hang_limit,
+                   timeout, adev->reset_domain.wq, ring->sched_score, ring->name);
+        if (r) {
+            DRM_ERROR("Failed to create scheduler on ring %s.\n",
+                  ring->name);
+            return r;
+        }
+    }
+
+    return 0;
+}
+
+
      /**
       * amdgpu_device_ip_init - run init for hardware IPs
       *
@@ -2419,6 +2460,10 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
              }
          }
      +    r = amdgpu_device_init_schedulers(adev);
+    if (r)
+        goto init_failed;
+
          /* Don't init kfd if whole hive need to be reset during init */
          if (!adev->gmc.xgmi.pending_reset)
 amdgpu_amdkfd_device_init(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -2
index 45977a72b5dd..fa302540c69a 100644
@@ -457,8 +457,6 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
                        atomic_t *sched_score)
      {
          struct amdgpu_device *adev = ring->adev;
-    long timeout;
-    int r;
            if (!adev)
              return -EINVAL;

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring, · line 481

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -4
@@ -478,36 +476,12 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
 spin_lock_init(&ring->fence_drv.lock);
          ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *),
                           GFP_KERNEL);
-    if (!ring->fence_drv.fences)
-        return -ENOMEM;
      -    /* No need to setup the GPU scheduler for rings that don't need it */
-    if (ring->no_scheduler)
-        return 0;
+    ring->num_hw_submission = num_hw_submission;
+    ring->sched_score = sched_score;

Let's move this into the caller and then use ring->num_hw_submission in the fence code as well.

The maximum number of jobs on the ring is not really fence specific.

Regards,
Christian.

Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2 -22
      -    switch (ring->funcs->type) {
-    case AMDGPU_RING_TYPE_GFX:
-        timeout = adev->gfx_timeout;
-        break;
-    case AMDGPU_RING_TYPE_COMPUTE:
-        timeout = adev->compute_timeout;
-        break;
-    case AMDGPU_RING_TYPE_SDMA:
-        timeout = adev->sdma_timeout;
-        break;
-    default:
-        timeout = adev->video_timeout;
-        break;
-    }
-
-    r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
-               num_hw_submission, amdgpu_job_hang_limit,
-               timeout, NULL, sched_score, ring->name);
-    if (r) {
-        DRM_ERROR("Failed to create scheduler on ring %s.\n",
-              ring->name);
-        return r;
-    }
+    if (!ring->fence_drv.fences)
+        return -ENOMEM;
            return 0;
      }
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -0
index fae7d185ad0d..7f20ce73a243 100644
@@ -251,6 +251,8 @@ struct amdgpu_ring {
          bool has_compute_vm_bug;
          bool            no_scheduler;
          int            hw_prio;
+    unsigned num_hw_submission;
+    atomic_t        *sched_score;
      };
        #define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
#18 lore raw

RFC v4 3/11 drm/amdgpu: Serialize non TDR gpu recovery with TDRs

In reply to Andrey Grodzovsky

Use reset domain wq also for non TDR gpu recovery trigers such as sysfs and RAS. We must serialize all possible GPU recoveries to gurantee no concurrency there. For TDR call the original recovery function directly since it's already executed from within the wq. For others just use a wrapper to qeueue work and wait on it to finish.

v2: Rename to amdgpu_recover_work_struct

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 33 +++++++++++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c    |  2 +-
 3 files changed, 35 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index b76c1cfad7f1..540a38fe5cd6 100644
@@ -1298,6 +1298,8 @@ bool amdgpu_device_has_job_running(struct amdgpu_device *adev);
 bool amdgpu_device_should_recover_gpu(struct amdgpu_device *adev);
 int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
 			      struct amdgpu_job* job);
+int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
+			      struct amdgpu_job *job);
 void amdgpu_device_pci_config_reset(struct amdgpu_device *adev);
 int amdgpu_device_pci_reset(struct amdgpu_device *adev);
 bool amdgpu_device_need_post(struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +32 -1
index 00123b0013d3..15e8fde3ac2d 100644
@@ -5033,7 +5033,7 @@ static void amdgpu_device_recheck_guilty_jobs(
  * Returns 0 for success or an error on failure.
  */
 
-int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
+int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
 			      struct amdgpu_job *job)
 {
 	struct list_head device_list, *device_list_handle =  NULL;
@@ -5292,6 +5292,37 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
 	return r;
 }
 
+struct amdgpu_recover_work_struct {
+	struct work_struct base;
+	struct amdgpu_device *adev;
+	struct amdgpu_job *job;
+	int ret;
+};
+
+static void amdgpu_device_queue_gpu_recover_work(struct work_struct *work)
+{
+	struct amdgpu_recover_work_struct *recover_work = container_of(work, struct amdgpu_recover_work_struct, base);
+
+	recover_work->ret = amdgpu_device_gpu_recover_imp(recover_work->adev, recover_work->job);
+}
+/*
+ * Serialize gpu recover into reset domain single threaded wq
+ */
+int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
+				    struct amdgpu_job *job)
+{
+	struct amdgpu_recover_work_struct work = {.adev = adev, .job = job};
+
+	INIT_WORK(&work.base, amdgpu_device_queue_gpu_recover_work);
+
+	if (!queue_work(adev->reset_domain.wq, &work.base))
+		return -EAGAIN;
+
+	flush_work(&work.base);
+
+	return work.ret;
+}
+
 /**
  * amdgpu_device_get_pcie_info - fence pcie info about the PCIE slot
  *
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -1
index bfc47bea23db..38c9fd7b7ad4 100644
@@ -63,7 +63,7 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
 		  ti.process_name, ti.tgid, ti.task_name, ti.pid);
 
 	if (amdgpu_device_should_recover_gpu(ring->adev)) {
-		amdgpu_device_gpu_recover(ring->adev, job);
+		amdgpu_device_gpu_recover_imp(ring->adev, job);
 	} else {
 		drm_sched_suspend_timeout(&ring->sched);
 		if (amdgpu_sriov_vf(adev))
Signature · 1 line
2.25.1
#19 lore raw

RFC v4 4/11 drm/amd/virt: For SRIOV send GPU reset directly to TDR queue.

In reply to Andrey Grodzovsky

No need to to trigger another work queue inside the work queue.

v3:

Problem:
Extra reset caused by host side FLR notification following guest side triggered reset.
Fix: Preven qeuing flr_work from mailbox irq if guest already executing a reset.

---
 drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c | 9 ++++++---
 drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c | 9 ++++++---
 drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c | 9 ++++++---
 3 files changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +6 -3
index 56da5ab82987..5869d51d8bee 100644
@@ -282,7 +282,7 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
 	if (amdgpu_device_should_recover_gpu(adev)
 		&& (!amdgpu_device_has_job_running(adev) ||
 		adev->sdma_timeout == MAX_SCHEDULE_TIMEOUT))
-		amdgpu_device_gpu_recover(adev, NULL);
+		amdgpu_device_gpu_recover_imp(adev, NULL);
 }
 
 static int xgpu_ai_set_mailbox_rcv_irq(struct amdgpu_device *adev,
@@ -307,8 +307,11 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev,
 
 	switch (event) {
 		case IDH_FLR_NOTIFICATION:
-		if (amdgpu_sriov_runtime(adev))
-			schedule_work(&adev->virt.flr_work);
+		if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
+			WARN_ONCE(!queue_work(adev->reset_domain.wq,
+					      &adev->virt.flr_work),
+				  "Failed to queue work! at %s",
+				  __func__);
 		break;
 		case IDH_QUERY_ALIVE:
 			xgpu_ai_mailbox_send_ack(adev);
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +6 -3
index 477d0dde19c5..5728a6401d73 100644
@@ -309,7 +309,7 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work)
 		adev->gfx_timeout == MAX_SCHEDULE_TIMEOUT ||
 		adev->compute_timeout == MAX_SCHEDULE_TIMEOUT ||
 		adev->video_timeout == MAX_SCHEDULE_TIMEOUT))
-		amdgpu_device_gpu_recover(adev, NULL);
+		amdgpu_device_gpu_recover_imp(adev, NULL);
 }
 
 static int xgpu_nv_set_mailbox_rcv_irq(struct amdgpu_device *adev,
@@ -337,8 +337,11 @@ static int xgpu_nv_mailbox_rcv_irq(struct amdgpu_device *adev,
 
 	switch (event) {
 	case IDH_FLR_NOTIFICATION:
-		if (amdgpu_sriov_runtime(adev))
-			schedule_work(&adev->virt.flr_work);
+		if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
+			WARN_ONCE(!queue_work(adev->reset_domain.wq,
+					      &adev->virt.flr_work),
+				  "Failed to queue work! at %s",
+				  __func__);
 		break;
 		/* READY_TO_ACCESS_GPU is fetched by kernel polling, IRQ can ignore
 		 * it byfar since that polling thread will handle it,
drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c +6 -3
index aef9d059ae52..02290febfcf4 100644
@@ -521,7 +521,7 @@ static void xgpu_vi_mailbox_flr_work(struct work_struct *work)
 
 	/* Trigger recovery due to world switch failure */
 	if (amdgpu_device_should_recover_gpu(adev))
-		amdgpu_device_gpu_recover(adev, NULL);
+		amdgpu_device_gpu_recover_imp(adev, NULL);
 }
 
 static int xgpu_vi_set_mailbox_rcv_irq(struct amdgpu_device *adev,
@@ -550,8 +550,11 @@ static int xgpu_vi_mailbox_rcv_irq(struct amdgpu_device *adev,
 		r = xgpu_vi_mailbox_rcv_msg(adev, IDH_FLR_NOTIFICATION);
 
 		/* only handle FLR_NOTIFY now */
-		if (!r)
-			schedule_work(&adev->virt.flr_work);
+		if (!r && !amdgpu_in_reset(adev))
+			WARN_ONCE(!queue_work(adev->reset_domain.wq,
+					      &adev->virt.flr_work),
+				  "Failed to queue work! at %s",
+				  __func__);
 	}
 
 	return 0;
Signature · 1 line
2.25.1
#20 lore raw

RE: [RFC v4 04/11] drm/amd/virt: For SRIOV send GPU reset directly to TDR queue.

[AMD Official Use Only]

This patch is reviewed by Shaoyun.liu <[email protected]>

Since other patches are suggested by other engineer and they may already od some review on them , so I will leave them to continue review the rest patches.

Regards
Shaoyun.liu

-----Original Message-----
From: Grodzovsky, Andrey <[email protected]>
Sent: Tuesday, February 8, 2022 7:23 PM
To: [email protected]; [email protected]
Cc: Koenig, Christian <[email protected]>; [email protected]; Liu, Monk <[email protected]>; Chen, Horace <[email protected]>; Lazar, Lijo <[email protected]>; Chen, JingWen <[email protected]>; Grodzovsky, Andrey <[email protected]>; Liu, Shaoyun <[email protected]>
Subject: [RFC v4 04/11] drm/amd/virt: For SRIOV send GPU reset directly to TDR queue.

No need to to trigger another work queue inside the work queue.

v3:

Problem:
Extra reset caused by host side FLR notification following guest side triggered reset.
Fix: Preven qeuing flr_work from mailbox irq if guest already executing a reset.

---
 drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c | 9 ++++++---  drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c | 9 ++++++---  drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c | 9 ++++++---
 3 files changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +1 -1
index 56da5ab82987..5869d51d8bee 100644
@@ -282,7 +282,7 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
 	if (amdgpu_device_should_recover_gpu(adev)
 		&& (!amdgpu_device_has_job_running(adev) ||
 		adev->sdma_timeout == MAX_SCHEDULE_TIMEOUT))
-		amdgpu_device_gpu_recover(adev, NULL);
+		amdgpu_device_gpu_recover_imp(adev, NULL);
 }
 
 static int xgpu_ai_set_mailbox_rcv_irq(struct amdgpu_device *adev, @@ -307,8 +307,11 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev,

switch (event) {
case IDH_FLR_NOTIFICATION:
- if (amdgpu_sriov_runtime(adev))
- schedule_work(&adev->virt.flr_work);
+ if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
+ WARN_ONCE(!queue_work(adev->reset_domain.wq,
+ &adev->virt.flr_work),
+ "Failed to queue work! at %s",
+ __func__);
break;
case IDH_QUERY_ALIVE:
xgpu_ai_mailbox_send_ack(adev);

drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +1 -1
index 477d0dde19c5..5728a6401d73 100644
@@ -309,7 +309,7 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work)
 		adev->gfx_timeout == MAX_SCHEDULE_TIMEOUT ||
 		adev->compute_timeout == MAX_SCHEDULE_TIMEOUT ||
 		adev->video_timeout == MAX_SCHEDULE_TIMEOUT))
-		amdgpu_device_gpu_recover(adev, NULL);
+		amdgpu_device_gpu_recover_imp(adev, NULL);
 }
 
 static int xgpu_nv_set_mailbox_rcv_irq(struct amdgpu_device *adev, @@ -337,8 +337,11 @@ static int xgpu_nv_mailbox_rcv_irq(struct amdgpu_device *adev,

switch (event) {
case IDH_FLR_NOTIFICATION:
- if (amdgpu_sriov_runtime(adev))
- schedule_work(&adev->virt.flr_work);
+ if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
+ WARN_ONCE(!queue_work(adev->reset_domain.wq,
+ &adev->virt.flr_work),
+ "Failed to queue work! at %s",
+ __func__);
break;
/* READY_TO_ACCESS_GPU is fetched by kernel polling, IRQ can ignore
* it byfar since that polling thread will handle it, diff --git a/drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c b/drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c
index aef9d059ae52..02290febfcf4 100644

drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c +1 -1
@@ -521,7 +521,7 @@ static void xgpu_vi_mailbox_flr_work(struct work_struct *work)
 
 	/* Trigger recovery due to world switch failure */
 	if (amdgpu_device_should_recover_gpu(adev))
-		amdgpu_device_gpu_recover(adev, NULL);
+		amdgpu_device_gpu_recover_imp(adev, NULL);
 }
 
 static int xgpu_vi_set_mailbox_rcv_irq(struct amdgpu_device *adev, @@ -550,8 +550,11 @@ static int xgpu_vi_mailbox_rcv_irq(struct amdgpu_device *adev,

r = xgpu_vi_mailbox_rcv_msg(adev, IDH_FLR_NOTIFICATION);

/* only handle FLR_NOTIFY now */
- if (!r)
- schedule_work(&adev->virt.flr_work);
+ if (!r && !amdgpu_in_reset(adev))
+ WARN_ONCE(!queue_work(adev->reset_domain.wq,
+ &adev->virt.flr_work),
+ "Failed to queue work! at %s",
+ __func__);
}

return 0;
--
2.25.1

#21 lore raw

Re: [RFC v4 04/11] drm/amd/virt: For SRIOV send GPU reset directly to TDR queue.

In reply to Andrey Grodzovsky

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 4 lines

No need to to trigger another work queue inside the work queue.

v3:

Quoted 8 lines

Problem:
Extra reset caused by host side FLR notification following guest side triggered reset.
Fix: Preven qeuing flr_work from mailbox irq if guest already executing a reset.

Feel free to add an Acked-by: Christian König <[email protected]>, but an rb from somebody more familiar with the code would be better.

Regards,
Christian.

Quoted 87 lines
---
  drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c | 9 ++++++---
  drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c | 9 ++++++---
  drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c | 9 ++++++---
  3 files changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +6 -3
index 56da5ab82987..5869d51d8bee 100644
@@ -282,7 +282,7 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
  	if (amdgpu_device_should_recover_gpu(adev)
  		&& (!amdgpu_device_has_job_running(adev) ||
  		adev->sdma_timeout == MAX_SCHEDULE_TIMEOUT))
-		amdgpu_device_gpu_recover(adev, NULL);
+		amdgpu_device_gpu_recover_imp(adev, NULL);
  }
 
  static int xgpu_ai_set_mailbox_rcv_irq(struct amdgpu_device *adev,
@@ -307,8 +307,11 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev,
 
  	switch (event) {
  		case IDH_FLR_NOTIFICATION:
-		if (amdgpu_sriov_runtime(adev))
-			schedule_work(&adev->virt.flr_work);
+		if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
+			WARN_ONCE(!queue_work(adev->reset_domain.wq,
+					      &adev->virt.flr_work),
+				  "Failed to queue work! at %s",
+				  __func__);
  		break;
  		case IDH_QUERY_ALIVE:
  			xgpu_ai_mailbox_send_ack(adev);
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +6 -3
index 477d0dde19c5..5728a6401d73 100644
@@ -309,7 +309,7 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work)
  		adev->gfx_timeout == MAX_SCHEDULE_TIMEOUT ||
  		adev->compute_timeout == MAX_SCHEDULE_TIMEOUT ||
  		adev->video_timeout == MAX_SCHEDULE_TIMEOUT))
-		amdgpu_device_gpu_recover(adev, NULL);
+		amdgpu_device_gpu_recover_imp(adev, NULL);
  }
 
  static int xgpu_nv_set_mailbox_rcv_irq(struct amdgpu_device *adev,
@@ -337,8 +337,11 @@ static int xgpu_nv_mailbox_rcv_irq(struct amdgpu_device *adev,
 
  	switch (event) {
  	case IDH_FLR_NOTIFICATION:
-		if (amdgpu_sriov_runtime(adev))
-			schedule_work(&adev->virt.flr_work);
+		if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
+			WARN_ONCE(!queue_work(adev->reset_domain.wq,
+					      &adev->virt.flr_work),
+				  "Failed to queue work! at %s",
+				  __func__);
  		break;
  		/* READY_TO_ACCESS_GPU is fetched by kernel polling, IRQ can ignore
  		 * it byfar since that polling thread will handle it,
drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c +6 -3
index aef9d059ae52..02290febfcf4 100644
@@ -521,7 +521,7 @@ static void xgpu_vi_mailbox_flr_work(struct work_struct *work)
 
  	/* Trigger recovery due to world switch failure */
  	if (amdgpu_device_should_recover_gpu(adev))
-		amdgpu_device_gpu_recover(adev, NULL);
+		amdgpu_device_gpu_recover_imp(adev, NULL);
  }
 
  static int xgpu_vi_set_mailbox_rcv_irq(struct amdgpu_device *adev,
@@ -550,8 +550,11 @@ static int xgpu_vi_mailbox_rcv_irq(struct amdgpu_device *adev,
  		r = xgpu_vi_mailbox_rcv_msg(adev, IDH_FLR_NOTIFICATION);
 
  		/* only handle FLR_NOTIFY now */
-		if (!r)
-			schedule_work(&adev->virt.flr_work);
+		if (!r && !amdgpu_in_reset(adev))
+			WARN_ONCE(!queue_work(adev->reset_domain.wq,
+					      &adev->virt.flr_work),
+				  "Failed to queue work! at %s",
+				  __func__);
  	}
 
  	return 0;
#22 lore raw

RFC v4 5/11 drm/amdgpu: Drop hive->in_reset

In reply to Andrey Grodzovsky

Since we serialize all resets no need to protect from concurrent resets.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19 +------------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c   |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h   |  1 -
 3 files changed, 1 insertion(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -18
index 15e8fde3ac2d..7e92f2432087 100644
@@ -5067,26 +5067,10 @@ int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
 	dev_info(adev->dev, "GPU %s begin!\n",
 		need_emergency_restart ? "jobs stop":"reset");
 
-	/*
-	 * Here we trylock to avoid chain of resets executing from
-	 * either trigger by jobs on different adevs in XGMI hive or jobs on
-	 * different schedulers for same device while this TO handler is running.
-	 * We always reset all schedulers for device and all devices for XGMI
-	 * hive so that should take care of them too.
-	 */
 	if (!amdgpu_sriov_vf(adev))
 		hive = amdgpu_get_xgmi_hive(adev);
-	if (hive) {
-		if (atomic_cmpxchg(&hive->in_reset, 0, 1) != 0) {
-			DRM_INFO("Bailing on TDR for s_job:%llx, hive: %llx as another already in progress",
-				job ? job->base.id : -1, hive->hive_id);
-			amdgpu_put_xgmi_hive(hive);
-			if (job && job->vm)
-				drm_sched_increase_karma(&job->base);
-			return 0;
-		}
+	if (hive)
 		mutex_lock(&hive->hive_lock);
-	}
 
 	reset_context.method = AMD_RESET_METHOD_NONE;
 	reset_context.reset_req_dev = adev;
@@ -5282,7 +5266,6 @@ int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
 
 skip_recovery:
 	if (hive) {
-		atomic_set(&hive->in_reset, 0);
 		mutex_unlock(&hive->hive_lock);
 		amdgpu_put_xgmi_hive(hive);
 	}
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +0 -1
index d406897346d6..89b682afe821 100644
@@ -410,7 +410,6 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 	INIT_LIST_HEAD(&hive->device_list);
 	INIT_LIST_HEAD(&hive->node);
 	mutex_init(&hive->hive_lock);
-	atomic_set(&hive->in_reset, 0);
 	atomic_set(&hive->number_devices, 0);
 	task_barrier_init(&hive->tb);
 	hive->pstate = AMDGPU_XGMI_PSTATE_UNKNOWN;
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +0 -1
index 6121aaa292cb..2f2ce53645a5 100644
@@ -33,7 +33,6 @@ struct amdgpu_hive_info {
 	struct list_head node;
 	atomic_t number_devices;
 	struct mutex hive_lock;
-	atomic_t in_reset;
 	int hi_req_count;
 	struct amdgpu_device *hi_req_gpu;
 	struct task_barrier tb;
Signature · 1 line
2.25.1
#23 lore raw

RFC v4 6/11 drm/amdgpu: Drop concurrent GPU reset protection for device

In reply to Andrey Grodzovsky

Since now all GPU resets are serialzied there is no need for this.

This patch also reverts 'drm/amdgpu: race issue when jobs on 2 ring timeout'

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 89 ++--------------------
 1 file changed, 7 insertions(+), 82 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7 -82
index 7e92f2432087..e3c0ec684a85 100644
@@ -4817,11 +4817,10 @@ int amdgpu_do_asic_reset(struct list_head *device_list_handle,
 	return r;
 }
 
-static bool amdgpu_device_lock_adev(struct amdgpu_device *adev,
+static void amdgpu_device_lock_adev(struct amdgpu_device *adev,
 				struct amdgpu_hive_info *hive)
 {
-	if (atomic_cmpxchg(&adev->in_gpu_reset, 0, 1) != 0)
-		return false;
+	atomic_set(&adev->in_gpu_reset, 1);
 
 	if (hive) {
 		down_write_nest_lock(&adev->reset_sem, &hive->hive_lock);
@@ -4840,8 +4839,6 @@ static bool amdgpu_device_lock_adev(struct amdgpu_device *adev,
 		adev->mp1_state = PP_MP1_STATE_NONE;
 		break;
 	}
-
-	return true;
 }
 
 static void amdgpu_device_unlock_adev(struct amdgpu_device *adev)
@@ -4852,46 +4849,6 @@ static void amdgpu_device_unlock_adev(struct amdgpu_device *adev)
 	up_write(&adev->reset_sem);
 }
 
-/*
- * to lockup a list of amdgpu devices in a hive safely, if not a hive
- * with multiple nodes, it will be similar as amdgpu_device_lock_adev.
- *
- * unlock won't require roll back.
- */
-static int amdgpu_device_lock_hive_adev(struct amdgpu_device *adev, struct amdgpu_hive_info *hive)
-{
-	struct amdgpu_device *tmp_adev = NULL;
-
-	if (!amdgpu_sriov_vf(adev) && (adev->gmc.xgmi.num_physical_nodes > 1)) {
-		if (!hive) {
-			dev_err(adev->dev, "Hive is NULL while device has multiple xgmi nodes");
-			return -ENODEV;
-		}
-		list_for_each_entry(tmp_adev, &hive->device_list, gmc.xgmi.head) {
-			if (!amdgpu_device_lock_adev(tmp_adev, hive))
-				goto roll_back;
-		}
-	} else if (!amdgpu_device_lock_adev(adev, hive))
-		return -EAGAIN;
-
-	return 0;
-roll_back:
-	if (!list_is_first(&tmp_adev->gmc.xgmi.head, &hive->device_list)) {
-		/*
-		 * if the lockup iteration break in the middle of a hive,
-		 * it may means there may has a race issue,
-		 * or a hive device locked up independently.
-		 * we may be in trouble and may not, so will try to roll back
-		 * the lock and give out a warnning.
-		 */
-		dev_warn(tmp_adev->dev, "Hive lock iteration broke in the middle. Rolling back to unlock");
-		list_for_each_entry_continue_reverse(tmp_adev, &hive->device_list, gmc.xgmi.head) {
-			amdgpu_device_unlock_adev(tmp_adev);
-		}
-	}
-	return -EAGAIN;
-}
-
 static void amdgpu_device_resume_display_audio(struct amdgpu_device *adev)
 {
 	struct pci_dev *p = NULL;
@@ -5078,22 +5035,6 @@ int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
 	reset_context.hive = hive;
 	clear_bit(AMDGPU_NEED_FULL_RESET, &reset_context.flags);
 
-	/*
-	 * lock the device before we try to operate the linked list
-	 * if didn't get the device lock, don't touch the linked list since
-	 * others may iterating it.
-	 */
-	r = amdgpu_device_lock_hive_adev(adev, hive);
-	if (r) {
-		dev_info(adev->dev, "Bailing on TDR for s_job:%llx, as another already in progress",
-					job ? job->base.id : -1);
-
-		/* even we skipped this reset, still need to set the job to guilty */
-		if (job && job->vm)
-			drm_sched_increase_karma(&job->base);
-		goto skip_recovery;
-	}
-
 	/*
 	 * Build list of devices to reset.
 	 * In case we are in XGMI hive mode, resort the device list
@@ -5113,6 +5054,9 @@ int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
 
 	/* block all schedulers and reset given job's ring */
 	list_for_each_entry(tmp_adev, device_list_handle, reset_list) {
+
+		amdgpu_device_lock_adev(tmp_adev, hive);
+
 		/*
 		 * Try to put the audio codec into suspend state
 		 * before gpu reset started.
@@ -5264,13 +5208,12 @@ int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
 		amdgpu_device_unlock_adev(tmp_adev);
 	}
 
-skip_recovery:
 	if (hive) {
 		mutex_unlock(&hive->hive_lock);
 		amdgpu_put_xgmi_hive(hive);
 	}
 
-	if (r && r != -EAGAIN)
+	if (r)
 		dev_info(adev->dev, "GPU reset end with ret = %d\n", r);
 	return r;
 }
@@ -5493,20 +5436,6 @@ int amdgpu_device_baco_exit(struct drm_device *dev)
 	return 0;
 }
 
-static void amdgpu_cancel_all_tdr(struct amdgpu_device *adev)
-{
-	int i;
-
-	for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
-		struct amdgpu_ring *ring = adev->rings[i];
-
-		if (!ring || !ring->sched.thread)
-			continue;
-
-		cancel_delayed_work_sync(&ring->sched.work_tdr);
-	}
-}
-
 /**
  * amdgpu_pci_error_detected - Called when a PCI error is detected.
  * @pdev: PCI device struct
@@ -5537,14 +5466,10 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_sta
 	/* Fatal error, prepare for slot reset */
 	case pci_channel_io_frozen:
 		/*
-		 * Cancel and wait for all TDRs in progress if failing to
-		 * set  adev->in_gpu_reset in amdgpu_device_lock_adev
-		 *
 		 * Locking adev->reset_sem will prevent any external access
 		 * to GPU during PCI error recovery
 		 */
-		while (!amdgpu_device_lock_adev(adev, NULL))
-			amdgpu_cancel_all_tdr(adev);
+		amdgpu_device_lock_adev(adev, NULL);
 
 		/*
 		 * Block any work scheduling as we do for regular GPU reset
Signature · 1 line
2.25.1
#24 lore raw

RFC v4 7/11 drm/amdgpu: Rework reset domain to be refcounted.

In reply to Andrey Grodzovsky

The reset domain contains register access semaphor now and so needs to be present as long as each device in a hive needs it and so it cannot be binded to XGMI hive life cycle.
Adress this by making reset domain refcounted and pointed by each member of the hive and the hive itself.

v4:

Fix crash on boot witrh XGMI hive by adding type to reset_domain. XGMI will only create a new reset_domain if prevoius was of single device type meaning it's first boot. Otherwsie it will take a refocunt to exsiting reset_domain from the amdgou device.

Add a wrapper around reset_domain->refcount get/put and a wrapper around send to reset wq (Lijo)

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  6 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 44 +++++++++++++---------
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c  | 40 ++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h  | 35 +++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c   | 29 +++++++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h   |  2 +-
 drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c      |  6 ++-
 drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c      |  6 ++-
 drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c      |  6 ++-
 9 files changed, 140 insertions(+), 34 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -4
index 540a38fe5cd6..cb9764513df8 100644
@@ -813,9 +813,7 @@ struct amd_powerplay {
 #define AMDGPU_RESET_MAGIC_NUM 64
 #define AMDGPU_MAX_DF_PERFMONS 4
 #define AMDGPU_PRODUCT_NAME_LEN 64
-struct amdgpu_reset_domain {
-	struct workqueue_struct *wq;
-};
+struct amdgpu_reset_domain;
 
 struct amdgpu_device {
 	struct device			*dev;
@@ -1104,7 +1102,7 @@ struct amdgpu_device {
 	uint32_t                        ip_versions[MAX_HWIP][HWIP_MAX_INSTANCE];
 
 	bool				ram_is_direct_mapped;
-	struct amdgpu_reset_domain	reset_domain;
+	struct amdgpu_reset_domain	*reset_domain;
 };
 
 static inline struct amdgpu_device *drm_to_adev(struct drm_device *ddev)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +27 -17

77 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c +40 -0
index 02afd4115675..91864947063f 100644
@@ -96,3 +96,43 @@ int amdgpu_reset_perform_reset(struct amdgpu_device *adev,
 	return reset_handler->restore_hwcontext(adev->reset_cntl,
 						reset_context);
 }
+
+
+void amdgpu_reset_destroy_reset_domain(struct kref *ref)
+{
+	struct amdgpu_reset_domain *reset_domain = container_of(ref,
+								struct amdgpu_reset_domain,
+								refcount);
+	if (reset_domain->wq)
+		destroy_workqueue(reset_domain->wq);
+
+	kvfree(reset_domain);
+}
+
+struct amdgpu_reset_domain *amdgpu_reset_create_reset_domain(enum amdgpu_reset_domain_type type,
+							     char *wq_name)
+{
+	struct amdgpu_reset_domain *reset_domain;
+
+	reset_domain = kvzalloc(sizeof(struct amdgpu_reset_domain), GFP_KERNEL);
+	if (!reset_domain) {
+		DRM_ERROR("Failed to allocate amdgpu_reset_domain!");
+		return NULL;
+	}
+
+	reset_domain->type = type;
+	kref_init(&reset_domain->refcount);
+
+	reset_domain->wq = create_singlethread_workqueue(wq_name);
+	if (!reset_domain->wq) {
+		DRM_ERROR("Failed to allocate wq for amdgpu_reset_domain!");
+		amdgpu_reset_put_reset_domain(reset_domain);
+		return NULL;
+
+	}
+
+	return reset_domain;
+}
+
+
+
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +35 -0
index e00d38d9160a..cc625e441fa0 100644
@@ -70,6 +70,19 @@ struct amdgpu_reset_control {
 	void (*async_reset)(struct work_struct *work);
 };
 
+
+enum amdgpu_reset_domain_type {
+	SINGLE_DEVICE,
+	XGMI_HIVE
+};
+
+struct amdgpu_reset_domain {
+	struct kref refcount;
+	struct workqueue_struct *wq;
+	enum amdgpu_reset_domain_type type;
+};
+
+
 int amdgpu_reset_init(struct amdgpu_device *adev);
 int amdgpu_reset_fini(struct amdgpu_device *adev);
 
@@ -82,4 +95,26 @@ int amdgpu_reset_perform_reset(struct amdgpu_device *adev,
 int amdgpu_reset_add_handler(struct amdgpu_reset_control *reset_ctl,
 			     struct amdgpu_reset_handler *handler);
 
+struct amdgpu_reset_domain *amdgpu_reset_create_reset_domain(enum amdgpu_reset_domain_type type,
+							     char *wq_name);
+
+void amdgpu_reset_destroy_reset_domain(struct kref *ref);
+
+static inline bool amdgpu_reset_get_reset_domain(struct amdgpu_reset_domain *domain)
+{
+	return kref_get_unless_zero(&domain->refcount) != 0;
+}
+
+static inline void amdgpu_reset_put_reset_domain(struct amdgpu_reset_domain *domain)
+{
+	kref_put(&domain->refcount, amdgpu_reset_destroy_reset_domain);
+}
+
+static inline bool amdgpu_reset_domain_schedule(struct amdgpu_reset_domain *domain,
+						struct work_struct *work)
+{
+	return queue_work(domain->wq, work);
+}
+
+
 #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +23 -6
index 89b682afe821..eb06322d2972 100644
@@ -32,6 +32,8 @@
 #include "wafl/wafl2_4_0_0_smn.h"
 #include "wafl/wafl2_4_0_0_sh_mask.h"
 
+#include "amdgpu_reset.h"
+
 #define smnPCS_XGMI23_PCS_ERROR_STATUS   0x11a01210
 #define smnPCS_XGMI3X16_PCS_ERROR_STATUS 0x11a0020c
 #define smnPCS_GOPX1_PCS_ERROR_STATUS    0x12200210
@@ -227,6 +229,9 @@ static void amdgpu_xgmi_hive_release(struct kobject *kobj)
 	struct amdgpu_hive_info *hive = container_of(
 		kobj, struct amdgpu_hive_info, kobj);
 
+	amdgpu_reset_put_reset_domain(hive->reset_domain);
+	hive->reset_domain = NULL;
+
 	mutex_destroy(&hive->hive_lock);
 	kfree(hive);
 }
@@ -398,12 +403,24 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 		goto pro_end;
 	}
 
-	hive->reset_domain.wq = alloc_ordered_workqueue("amdgpu-reset-hive", 0);
-	if (!hive->reset_domain.wq) {
-		dev_err(adev->dev, "XGMI: failed allocating wq for reset domain!\n");
-		kfree(hive);
-		hive = NULL;
-		goto pro_end;
+	/**
+	 * Avoid recreating reset domain when hive is reconstructed for the case
+	 * of reset the devices in the XGMI hive during probe for SRIOV
+	 * See https://www.spinics.net/lists/amd-gfx/msg58836.html
+	 */
+	if (adev->reset_domain->type != XGMI_HIVE) {
+		hive->reset_domain = amdgpu_reset_create_reset_domain(XGMI_HIVE, "amdgpu-reset-hive");
+			if (!hive->reset_domain) {
+				dev_err(adev->dev, "XGMI: failed initializing reset domain for xgmi hive\n");
+				ret = -ENOMEM;
+				kobject_put(&hive->kobj);
+				kfree(hive);
+				hive = NULL;
+				goto pro_end;
+			}
+	} else {
+		amdgpu_reset_get_reset_domain(adev->reset_domain);
+		hive->reset_domain = adev->reset_domain;
 	}
 
 	hive->hive_id = adev->gmc.xgmi.hive_id;
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +1 -1
index 2f2ce53645a5..dcaad22be492 100644
@@ -42,7 +42,7 @@ struct amdgpu_hive_info {
 		AMDGPU_XGMI_PSTATE_UNKNOWN
 	} pstate;
 
-	struct amdgpu_reset_domain reset_domain;
+	struct amdgpu_reset_domain *reset_domain;
 };
 
 struct amdgpu_pcs_ras_field {
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +4 -2
index 5869d51d8bee..6740eef84ee1 100644
@@ -32,6 +32,8 @@
 #include "soc15_common.h"
 #include "mxgpu_ai.h"
 
+#include "amdgpu_reset.h"
+
 static void xgpu_ai_mailbox_send_ack(struct amdgpu_device *adev)
 {
 	WREG8(AI_MAIBOX_CONTROL_RCV_OFFSET_BYTE, 2);
@@ -308,8 +310,8 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev,
 	switch (event) {
 		case IDH_FLR_NOTIFICATION:
 		if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
-			WARN_ONCE(!queue_work(adev->reset_domain.wq,
-					      &adev->virt.flr_work),
+			WARN_ONCE(!amdgpu_reset_domain_schedule(adev->reset_domain,
+								&adev->virt.flr_work),
 				  "Failed to queue work! at %s",
 				  __func__);
 		break;
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +4 -2
index 5728a6401d73..e967d61c7134 100644
@@ -31,6 +31,8 @@
 #include "soc15_common.h"
 #include "mxgpu_nv.h"
 
+#include "amdgpu_reset.h"
+
 static void xgpu_nv_mailbox_send_ack(struct amdgpu_device *adev)
 {
 	WREG8(NV_MAIBOX_CONTROL_RCV_OFFSET_BYTE, 2);
@@ -338,8 +340,8 @@ static int xgpu_nv_mailbox_rcv_irq(struct amdgpu_device *adev,
 	switch (event) {
 	case IDH_FLR_NOTIFICATION:
 		if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
-			WARN_ONCE(!queue_work(adev->reset_domain.wq,
-					      &adev->virt.flr_work),
+			WARN_ONCE(!amdgpu_reset_domain_schedule(adev->reset_domain,
+				   &adev->virt.flr_work),
 				  "Failed to queue work! at %s",
 				  __func__);
 		break;
drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c +4 -2
index 02290febfcf4..531cfba759dd 100644
@@ -42,6 +42,8 @@
 #include "smu/smu_7_1_3_d.h"
 #include "mxgpu_vi.h"
 
+#include "amdgpu_reset.h"
+
 /* VI golden setting */
 static const u32 xgpu_fiji_mgcg_cgcg_init[] = {
 	mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
@@ -551,8 +553,8 @@ static int xgpu_vi_mailbox_rcv_irq(struct amdgpu_device *adev,
 
 		/* only handle FLR_NOTIFY now */
 		if (!r && !amdgpu_in_reset(adev))
-			WARN_ONCE(!queue_work(adev->reset_domain.wq,
-					      &adev->virt.flr_work),
+			WARN_ONCE(!amdgpu_reset_domain_schedule(adev->reset_domain,
+								&adev->virt.flr_work),
 				  "Failed to queue work! at %s",
 				  __func__);
 	}
Signature · 1 line
2.25.1
Acked-by on v4 7/11
#25 lore raw

Re: [RFC v4 07/11] drm/amdgpu: Rework reset domain to be refcounted.

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 14 lines

The reset domain contains register access semaphor now and so needs to be present as long as each device in a hive needs it and so it cannot be binded to XGMI hive life cycle.
Adress this by making reset domain refcounted and pointed by each member of the hive and the hive itself.

v4:

Fix crash on boot witrh XGMI hive by adding type to reset_domain. XGMI will only create a new reset_domain if prevoius was of single device type meaning it's first boot. Otherwsie it will take a refocunt to exsiting reset_domain from the amdgou device.

Quoted 4 lines

Add a wrapper around reset_domain->refcount get/put and a wrapper around send to reset wq (Lijo)

Quoted 360 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  6 +--
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 44 +++++++++++++---------
  drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c  | 40 ++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h  | 35 +++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c   | 29 +++++++++++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h   |  2 +-
  drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c      |  6 ++-
  drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c      |  6 ++-
  drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c      |  6 ++-
  9 files changed, 140 insertions(+), 34 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -4
index 540a38fe5cd6..cb9764513df8 100644
@@ -813,9 +813,7 @@ struct amd_powerplay {
  #define AMDGPU_RESET_MAGIC_NUM 64
  #define AMDGPU_MAX_DF_PERFMONS 4
  #define AMDGPU_PRODUCT_NAME_LEN 64
-struct amdgpu_reset_domain {
-	struct workqueue_struct *wq;
-};
+struct amdgpu_reset_domain;
 
  struct amdgpu_device {
  	struct device			*dev;
@@ -1104,7 +1102,7 @@ struct amdgpu_device {
  	uint32_t                        ip_versions[MAX_HWIP][HWIP_MAX_INSTANCE];
 
  	bool				ram_is_direct_mapped;
-	struct amdgpu_reset_domain	reset_domain;
+	struct amdgpu_reset_domain	*reset_domain;
  };
 
  static inline struct amdgpu_device *drm_to_adev(struct drm_device *ddev)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +27 -17
index e3c0ec684a85..d61bc0a0457c 100644
@@ -2316,7 +2316,7 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
 
  		r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
  				   ring->num_hw_submission, amdgpu_job_hang_limit,
-				   timeout, adev->reset_domain.wq, ring->sched_score, ring->name);
+				   timeout, adev->reset_domain->wq, ring->sched_score, ring->name);
  		if (r) {
  			DRM_ERROR("Failed to create scheduler on ring %s.\n",
  				  ring->name);
@@ -2439,24 +2439,22 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
  	if (r)
  		goto init_failed;
 
+	/**
+	 * In case of XGMI grab extra reference for reset domain for this device
+	 */
  	if (adev->gmc.xgmi.num_physical_nodes > 1) {
-		struct amdgpu_hive_info *hive;
+		if (amdgpu_xgmi_add_device(adev) == 0) {
+			struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev);
 
-		amdgpu_xgmi_add_device(adev);
+			if (!hive->reset_domain ||
+			    !amdgpu_reset_get_reset_domain(hive->reset_domain)) {
+				r = -ENOENT;
+				goto init_failed;
+			}
 
-		hive = amdgpu_get_xgmi_hive(adev);
-		if (!hive || !hive->reset_domain.wq) {
-			DRM_ERROR("Failed to obtain reset domain info for XGMI hive:%llx", hive->hive_id);
-			r = -EINVAL;
-			goto init_failed;
-		}
-
-		adev->reset_domain.wq = hive->reset_domain.wq;
-	} else {
-		adev->reset_domain.wq = alloc_ordered_workqueue("amdgpu-reset-dev", 0);
-		if (!adev->reset_domain.wq) {
-			r = -ENOMEM;
-			goto init_failed;
+			/* Drop the early temporary reset domain we created for device */
+			amdgpu_reset_put_reset_domain(adev->reset_domain);
+			adev->reset_domain = hive->reset_domain;
  		}
  	}
 
@@ -3640,6 +3638,15 @@ int amdgpu_device_init(struct amdgpu_device *adev,
  		return r;
  	}
 
+	/*
+	 * Reset domain needs to be present early, before XGMI hive discovered
+	 * (if any) and intitialized to use reset sem and in_gpu reset flag
+	 * early on during init.
+	 */
+	adev->reset_domain = amdgpu_reset_create_reset_domain(SINGLE_DEVICE ,"amdgpu-reset-dev");
+	if (!adev->reset_domain)
+		return -ENOMEM;
+
  	/* early init functions */
  	r = amdgpu_device_ip_early_init(adev);
  	if (r)
@@ -4016,6 +4023,9 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)
  	if (adev->mman.discovery_bin)
  		amdgpu_discovery_fini(adev);
 
+	amdgpu_reset_put_reset_domain(adev->reset_domain);
+	adev->reset_domain = NULL;
+
  	kfree(adev->pci_state);
 
  }
@@ -5241,7 +5251,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
 
  	INIT_WORK(&work.base, amdgpu_device_queue_gpu_recover_work);
 
-	if (!queue_work(adev->reset_domain.wq, &work.base))
+	if (!amdgpu_reset_domain_schedule(adev->reset_domain, &work.base))
  		return -EAGAIN;
 
  	flush_work(&work.base);
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c +40 -0
index 02afd4115675..91864947063f 100644
@@ -96,3 +96,43 @@ int amdgpu_reset_perform_reset(struct amdgpu_device *adev,
  	return reset_handler->restore_hwcontext(adev->reset_cntl,
  						reset_context);
  }
+
+
+void amdgpu_reset_destroy_reset_domain(struct kref *ref)
+{
+	struct amdgpu_reset_domain *reset_domain = container_of(ref,
+								struct amdgpu_reset_domain,
+								refcount);
+	if (reset_domain->wq)
+		destroy_workqueue(reset_domain->wq);
+
+	kvfree(reset_domain);
+}
+
+struct amdgpu_reset_domain *amdgpu_reset_create_reset_domain(enum amdgpu_reset_domain_type type,
+							     char *wq_name)
+{
+	struct amdgpu_reset_domain *reset_domain;
+
+	reset_domain = kvzalloc(sizeof(struct amdgpu_reset_domain), GFP_KERNEL);
+	if (!reset_domain) {
+		DRM_ERROR("Failed to allocate amdgpu_reset_domain!");
+		return NULL;
+	}
+
+	reset_domain->type = type;
+	kref_init(&reset_domain->refcount);
+
+	reset_domain->wq = create_singlethread_workqueue(wq_name);
+	if (!reset_domain->wq) {
+		DRM_ERROR("Failed to allocate wq for amdgpu_reset_domain!");
+		amdgpu_reset_put_reset_domain(reset_domain);
+		return NULL;
+
+	}
+
+	return reset_domain;
+}
+
+
+
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +35 -0
index e00d38d9160a..cc625e441fa0 100644
@@ -70,6 +70,19 @@ struct amdgpu_reset_control {
  	void (*async_reset)(struct work_struct *work);
  };
 
+
+enum amdgpu_reset_domain_type {
+	SINGLE_DEVICE,
+	XGMI_HIVE
+};
+
+struct amdgpu_reset_domain {
+	struct kref refcount;
+	struct workqueue_struct *wq;
+	enum amdgpu_reset_domain_type type;
+};
+
+
  int amdgpu_reset_init(struct amdgpu_device *adev);
  int amdgpu_reset_fini(struct amdgpu_device *adev);
 
@@ -82,4 +95,26 @@ int amdgpu_reset_perform_reset(struct amdgpu_device *adev,
  int amdgpu_reset_add_handler(struct amdgpu_reset_control *reset_ctl,
  			     struct amdgpu_reset_handler *handler);
 
+struct amdgpu_reset_domain *amdgpu_reset_create_reset_domain(enum amdgpu_reset_domain_type type,
+							     char *wq_name);
+
+void amdgpu_reset_destroy_reset_domain(struct kref *ref);
+
+static inline bool amdgpu_reset_get_reset_domain(struct amdgpu_reset_domain *domain)
+{
+	return kref_get_unless_zero(&domain->refcount) != 0;
+}
+
+static inline void amdgpu_reset_put_reset_domain(struct amdgpu_reset_domain *domain)
+{
+	kref_put(&domain->refcount, amdgpu_reset_destroy_reset_domain);
+}
+
+static inline bool amdgpu_reset_domain_schedule(struct amdgpu_reset_domain *domain,
+						struct work_struct *work)
+{
+	return queue_work(domain->wq, work);
+}
+
+
  #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +23 -6
index 89b682afe821..eb06322d2972 100644
@@ -32,6 +32,8 @@
  #include "wafl/wafl2_4_0_0_smn.h"
  #include "wafl/wafl2_4_0_0_sh_mask.h"
 
+#include "amdgpu_reset.h"
+
  #define smnPCS_XGMI23_PCS_ERROR_STATUS   0x11a01210
  #define smnPCS_XGMI3X16_PCS_ERROR_STATUS 0x11a0020c
  #define smnPCS_GOPX1_PCS_ERROR_STATUS    0x12200210
@@ -227,6 +229,9 @@ static void amdgpu_xgmi_hive_release(struct kobject *kobj)
  	struct amdgpu_hive_info *hive = container_of(
  		kobj, struct amdgpu_hive_info, kobj);
 
+	amdgpu_reset_put_reset_domain(hive->reset_domain);
+	hive->reset_domain = NULL;
+
  	mutex_destroy(&hive->hive_lock);
  	kfree(hive);
  }
@@ -398,12 +403,24 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
  		goto pro_end;
  	}
 
-	hive->reset_domain.wq = alloc_ordered_workqueue("amdgpu-reset-hive", 0);
-	if (!hive->reset_domain.wq) {
-		dev_err(adev->dev, "XGMI: failed allocating wq for reset domain!\n");
-		kfree(hive);
-		hive = NULL;
-		goto pro_end;
+	/**
+	 * Avoid recreating reset domain when hive is reconstructed for the case
+	 * of reset the devices in the XGMI hive during probe for SRIOV
+	 * See https://www.spinics.net/lists/amd-gfx/msg58836.html
+	 */
+	if (adev->reset_domain->type != XGMI_HIVE) {
+		hive->reset_domain = amdgpu_reset_create_reset_domain(XGMI_HIVE, "amdgpu-reset-hive");
+			if (!hive->reset_domain) {
+				dev_err(adev->dev, "XGMI: failed initializing reset domain for xgmi hive\n");
+				ret = -ENOMEM;
+				kobject_put(&hive->kobj);
+				kfree(hive);
+				hive = NULL;
+				goto pro_end;
+			}
+	} else {
+		amdgpu_reset_get_reset_domain(adev->reset_domain);
+		hive->reset_domain = adev->reset_domain;
  	}
 
  	hive->hive_id = adev->gmc.xgmi.hive_id;
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +1 -1
index 2f2ce53645a5..dcaad22be492 100644
@@ -42,7 +42,7 @@ struct amdgpu_hive_info {
  		AMDGPU_XGMI_PSTATE_UNKNOWN
  	} pstate;
 
-	struct amdgpu_reset_domain reset_domain;
+	struct amdgpu_reset_domain *reset_domain;
  };
 
  struct amdgpu_pcs_ras_field {
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +4 -2
index 5869d51d8bee..6740eef84ee1 100644
@@ -32,6 +32,8 @@
  #include "soc15_common.h"
  #include "mxgpu_ai.h"
 
+#include "amdgpu_reset.h"
+
  static void xgpu_ai_mailbox_send_ack(struct amdgpu_device *adev)
  {
  	WREG8(AI_MAIBOX_CONTROL_RCV_OFFSET_BYTE, 2);
@@ -308,8 +310,8 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev,
  	switch (event) {
  		case IDH_FLR_NOTIFICATION:
  		if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
-			WARN_ONCE(!queue_work(adev->reset_domain.wq,
-					      &adev->virt.flr_work),
+			WARN_ONCE(!amdgpu_reset_domain_schedule(adev->reset_domain,
+								&adev->virt.flr_work),
  				  "Failed to queue work! at %s",
  				  __func__);
  		break;
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +4 -2
index 5728a6401d73..e967d61c7134 100644
@@ -31,6 +31,8 @@
  #include "soc15_common.h"
  #include "mxgpu_nv.h"
 
+#include "amdgpu_reset.h"
+
  static void xgpu_nv_mailbox_send_ack(struct amdgpu_device *adev)
  {
  	WREG8(NV_MAIBOX_CONTROL_RCV_OFFSET_BYTE, 2);
@@ -338,8 +340,8 @@ static int xgpu_nv_mailbox_rcv_irq(struct amdgpu_device *adev,
  	switch (event) {
  	case IDH_FLR_NOTIFICATION:
  		if (amdgpu_sriov_runtime(adev) && !amdgpu_in_reset(adev))
-			WARN_ONCE(!queue_work(adev->reset_domain.wq,
-					      &adev->virt.flr_work),
+			WARN_ONCE(!amdgpu_reset_domain_schedule(adev->reset_domain,
+				   &adev->virt.flr_work),
  				  "Failed to queue work! at %s",
  				  __func__);
  		break;
drivers/gpu/drm/amd/amdgpu/mxgpu_vi.c +4 -2
index 02290febfcf4..531cfba759dd 100644
@@ -42,6 +42,8 @@
  #include "smu/smu_7_1_3_d.h"
  #include "mxgpu_vi.h"
 
+#include "amdgpu_reset.h"
+
  /* VI golden setting */
  static const u32 xgpu_fiji_mgcg_cgcg_init[] = {
  	mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
@@ -551,8 +553,8 @@ static int xgpu_vi_mailbox_rcv_irq(struct amdgpu_device *adev,
 
  		/* only handle FLR_NOTIFY now */
  		if (!r && !amdgpu_in_reset(adev))
-			WARN_ONCE(!queue_work(adev->reset_domain.wq,
-					      &adev->virt.flr_work),
+			WARN_ONCE(!amdgpu_reset_domain_schedule(adev->reset_domain,
+								&adev->virt.flr_work),
  				  "Failed to queue work! at %s",
  				  __func__);
  	}
#26 lore raw

RFC v4 8/11 drm/amdgpu: Move reset sem into reset_domain

In reply to Andrey Grodzovsky

We want single instance of reset sem across all reset clients because in case of XGMI we should stop access cross device MMIO because any of them could be in a reset in the moment.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c   | 10 ++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    | 23 +++++++++----------
 .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c    | 18 ++++++++-------
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c     |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h     |  1 +
 drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c        |  6 +++--
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c         | 14 ++++++-----
 drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c         |  4 ++--
 drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c         |  4 ++--
 10 files changed, 46 insertions(+), 37 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -1
index cb9764513df8..ddfbcc8fd3d3 100644
@@ -1058,7 +1058,6 @@ struct amdgpu_device {
 
 	atomic_t 			in_gpu_reset;
 	enum pp_mp1_state               mp1_state;
-	struct rw_semaphore reset_sem;
 	struct amdgpu_doorbell_index doorbell_index;
 
 	struct mutex			notifier_lock;
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +6 -4
index 25e2e5bf90eb..c3728061d65a 100644
@@ -37,6 +37,8 @@
 #include "amdgpu_fw_attestation.h"
 #include "amdgpu_umr.h"
 
+#include "amdgpu_reset.h"
+
 #if defined(CONFIG_DEBUG_FS)
 
 /**
@@ -1279,7 +1281,7 @@ static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)
 	}
 
 	/* Avoid accidently unparking the sched thread during GPU reset */
-	r = down_write_killable(&adev->reset_sem);
+	r = down_write_killable(&adev->reset_domain->sem);
 	if (r)
 		return r;
 
@@ -1308,7 +1310,7 @@ static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)
 		kthread_unpark(ring->sched.thread);
 	}
 
-	up_write(&adev->reset_sem);
+	up_write(&adev->reset_domain->sem);
 
 	pm_runtime_mark_last_busy(dev->dev);
 	pm_runtime_put_autosuspend(dev->dev);
@@ -1517,7 +1519,7 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val)
 		return -ENOMEM;
 
 	/* Avoid accidently unparking the sched thread during GPU reset */
-	r = down_read_killable(&adev->reset_sem);
+	r = down_read_killable(&adev->reset_domain->sem);
 	if (r)
 		goto pro_end;
 
@@ -1560,7 +1562,7 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val)
 	/* restart the scheduler */
 	kthread_unpark(ring->sched.thread);
 
-	up_read(&adev->reset_sem);
+	up_read(&adev->reset_domain->sem);
 
 	ttm_bo_unlock_delayed_workqueue(&adev->mman.bdev, resched);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +11 -12
index d61bc0a0457c..dcbb175d336f 100644
@@ -424,10 +424,10 @@ bool amdgpu_device_skip_hw_access(struct amdgpu_device *adev)
 	 * the lock.
 	 */
 	if (in_task()) {
-		if (down_read_trylock(&adev->reset_sem))
-			up_read(&adev->reset_sem);
+		if (down_read_trylock(&adev->reset_domain->sem))
+			up_read(&adev->reset_domain->sem);
 		else
-			lockdep_assert_held(&adev->reset_sem);
+			lockdep_assert_held(&adev->reset_domain->sem);
 	}
 #endif
 	return false;
@@ -453,9 +453,9 @@ uint32_t amdgpu_device_rreg(struct amdgpu_device *adev,
 	if ((reg * 4) < adev->rmmio_size) {
 		if (!(acc_flags & AMDGPU_REGS_NO_KIQ) &&
 		    amdgpu_sriov_runtime(adev) &&
-		    down_read_trylock(&adev->reset_sem)) {
+		    down_read_trylock(&adev->reset_domain->sem)) {
 			ret = amdgpu_kiq_rreg(adev, reg);
-			up_read(&adev->reset_sem);
+			up_read(&adev->reset_domain->sem);
 		} else {
 			ret = readl(((void __iomem *)adev->rmmio) + (reg * 4));
 		}
@@ -538,9 +538,9 @@ void amdgpu_device_wreg(struct amdgpu_device *adev,
 	if ((reg * 4) < adev->rmmio_size) {
 		if (!(acc_flags & AMDGPU_REGS_NO_KIQ) &&
 		    amdgpu_sriov_runtime(adev) &&
-		    down_read_trylock(&adev->reset_sem)) {
+		    down_read_trylock(&adev->reset_domain->sem)) {
 			amdgpu_kiq_wreg(adev, reg, v);
-			up_read(&adev->reset_sem);
+			up_read(&adev->reset_domain->sem);
 		} else {
 			writel(v, ((void __iomem *)adev->rmmio) + (reg * 4));
 		}
@@ -3555,7 +3555,6 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 	mutex_init(&adev->virt.vf_errors.lock);
 	hash_init(adev->mn_hash);
 	atomic_set(&adev->in_gpu_reset, 0);
-	init_rwsem(&adev->reset_sem);
 	mutex_init(&adev->psp.mutex);
 	mutex_init(&adev->notifier_lock);
 
@@ -4833,9 +4832,9 @@ static void amdgpu_device_lock_adev(struct amdgpu_device *adev,
 	atomic_set(&adev->in_gpu_reset, 1);
 
 	if (hive) {
-		down_write_nest_lock(&adev->reset_sem, &hive->hive_lock);
+		down_write_nest_lock(&adev->reset_domain->sem, &hive->hive_lock);
 	} else {
-		down_write(&adev->reset_sem);
+		down_write(&adev->reset_domain->sem);
 	}
 
 	switch (amdgpu_asic_reset_method(adev)) {
@@ -4856,7 +4855,7 @@ static void amdgpu_device_unlock_adev(struct amdgpu_device *adev)
 	amdgpu_vf_error_trans_all(adev);
 	adev->mp1_state = PP_MP1_STATE_NONE;
 	atomic_set(&adev->in_gpu_reset, 0);
-	up_write(&adev->reset_sem);
+	up_write(&adev->reset_domain->sem);
 }
 
 static void amdgpu_device_resume_display_audio(struct amdgpu_device *adev)
@@ -5476,7 +5475,7 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_sta
 	/* Fatal error, prepare for slot reset */
 	case pci_channel_io_frozen:
 		/*
-		 * Locking adev->reset_sem will prevent any external access
+		 * Locking adev->reset_domain->sem will prevent any external access
 		 * to GPU during PCI error recovery
 		 */
 		amdgpu_device_lock_adev(adev, NULL);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +10 -8
index 05117eda105b..d3e055314804 100644
@@ -31,6 +31,8 @@
 #include <linux/debugfs.h>
 #include <linux/uaccess.h>
 
+#include "amdgpu_reset.h"
+
 #define EEPROM_I2C_MADDR_VEGA20         0x0
 #define EEPROM_I2C_MADDR_ARCTURUS       0x40000
 #define EEPROM_I2C_MADDR_ARCTURUS_D342  0x0
@@ -193,12 +195,12 @@ static int __write_table_header(struct amdgpu_ras_eeprom_control *control)
 	__encode_table_header_to_buf(&control->tbl_hdr, buf);
 
 	/* i2c may be unstable in gpu reset */
-	down_read(&adev->reset_sem);
+	down_read(&adev->reset_domain->sem);
 	res = amdgpu_eeprom_write(&adev->pm.smu_i2c,
 				  control->i2c_address +
 				  control->ras_header_offset,
 				  buf, RAS_TABLE_HEADER_SIZE);
-	up_read(&adev->reset_sem);
+	up_read(&adev->reset_domain->sem);
 
 	if (res < 0) {
 		DRM_ERROR("Failed to write EEPROM table header:%d", res);
@@ -387,13 +389,13 @@ static int __amdgpu_ras_eeprom_write(struct amdgpu_ras_eeprom_control *control,
 	int res;
 
 	/* i2c may be unstable in gpu reset */
-	down_read(&adev->reset_sem);
+	down_read(&adev->reset_domain->sem);
 	buf_size = num * RAS_TABLE_RECORD_SIZE;
 	res = amdgpu_eeprom_write(&adev->pm.smu_i2c,
 				  control->i2c_address +
 				  RAS_INDEX_TO_OFFSET(control, fri),
 				  buf, buf_size);
-	up_read(&adev->reset_sem);
+	up_read(&adev->reset_domain->sem);
 	if (res < 0) {
 		DRM_ERROR("Writing %d EEPROM table records error:%d",
 			  num, res);
@@ -547,12 +549,12 @@ amdgpu_ras_eeprom_update_header(struct amdgpu_ras_eeprom_control *control)
 		goto Out;
 	}
 
-	down_read(&adev->reset_sem);
+	down_read(&adev->reset_domain->sem);
 	res = amdgpu_eeprom_read(&adev->pm.smu_i2c,
 				 control->i2c_address +
 				 control->ras_record_offset,
 				 buf, buf_size);
-	up_read(&adev->reset_sem);
+	up_read(&adev->reset_domain->sem);
 	if (res < 0) {
 		DRM_ERROR("EEPROM failed reading records:%d\n",
 			  res);
@@ -642,13 +644,13 @@ static int __amdgpu_ras_eeprom_read(struct amdgpu_ras_eeprom_control *control,
 	int res;
 
 	/* i2c may be unstable in gpu reset */
-	down_read(&adev->reset_sem);
+	down_read(&adev->reset_domain->sem);
 	buf_size = num * RAS_TABLE_RECORD_SIZE;
 	res = amdgpu_eeprom_read(&adev->pm.smu_i2c,
 				 control->i2c_address +
 				 RAS_INDEX_TO_OFFSET(control, fri),
 				 buf, buf_size);
-	up_read(&adev->reset_sem);
+	up_read(&adev->reset_domain->sem);
 	if (res < 0) {
 		DRM_ERROR("Reading %d EEPROM table records error:%d",
 			  num, res);
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c +2 -0
index 91864947063f..c0988c804459 100644
@@ -131,6 +131,8 @@ struct amdgpu_reset_domain *amdgpu_reset_create_reset_domain(enum amdgpu_reset_d
 
 	}
 
+	init_rwsem(&reset_domain->sem);
+
 	return reset_domain;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +1 -0
index cc625e441fa0..80f918e87d4f 100644
@@ -80,6 +80,7 @@ struct amdgpu_reset_domain {
 	struct kref refcount;
 	struct workqueue_struct *wq;
 	enum amdgpu_reset_domain_type type;
+	struct rw_semaphore sem;
 };
 
 
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +4 -2
index 38bb42727715..222b1da9d601 100644
@@ -48,6 +48,8 @@
 #include "athub_v2_0.h"
 #include "athub_v2_1.h"
 
+#include "amdgpu_reset.h"
+
 #if 0
 static const struct soc15_reg_golden golden_settings_navi10_hdp[] =
 {
@@ -328,7 +330,7 @@ static void gmc_v10_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
 	 */
 	if (adev->gfx.kiq.ring.sched.ready &&
 	    (amdgpu_sriov_runtime(adev) || !amdgpu_sriov_vf(adev)) &&
-	    down_read_trylock(&adev->reset_sem)) {
+	    down_read_trylock(&adev->reset_domain->sem)) {
 		struct amdgpu_vmhub *hub = &adev->vmhub[vmhub];
 		const unsigned eng = 17;
 		u32 inv_req = hub->vmhub_funcs->get_invalidate_req(vmid, flush_type);
@@ -338,7 +340,7 @@ static void gmc_v10_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
 		amdgpu_virt_kiq_reg_write_reg_wait(adev, req, ack, inv_req,
 				1 << vmid);
 
-		up_read(&adev->reset_sem);
+		up_read(&adev->reset_domain->sem);
 		return;
 	}
 
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +8 -6
index 88c1eb9ad068..3a5efe969735 100644
@@ -62,6 +62,8 @@
 #include "amdgpu_ras.h"
 #include "amdgpu_xgmi.h"
 
+#include "amdgpu_reset.h"
+
 /* add these here since we already include dce12 headers and these are for DCN */
 #define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION                                                          0x055d
 #define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION_BASE_IDX                                                 2
@@ -787,13 +789,13 @@ static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
 	 */
 	if (adev->gfx.kiq.ring.sched.ready &&
 	    (amdgpu_sriov_runtime(adev) || !amdgpu_sriov_vf(adev)) &&
-	    down_read_trylock(&adev->reset_sem)) {
+	    down_read_trylock(&adev->reset_domain->sem)) {
 		uint32_t req = hub->vm_inv_eng0_req + hub->eng_distance * eng;
 		uint32_t ack = hub->vm_inv_eng0_ack + hub->eng_distance * eng;
 
 		amdgpu_virt_kiq_reg_write_reg_wait(adev, req, ack, inv_req,
 						   1 << vmid);
-		up_read(&adev->reset_sem);
+		up_read(&adev->reset_domain->sem);
 		return;
 	}
 
@@ -900,7 +902,7 @@ static int gmc_v9_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev,
 	if (amdgpu_in_reset(adev))
 		return -EIO;
 
-	if (ring->sched.ready && down_read_trylock(&adev->reset_sem)) {
+	if (ring->sched.ready && down_read_trylock(&adev->reset_domain->sem)) {
 		/* Vega20+XGMI caches PTEs in TC and TLB. Add a
 		 * heavy-weight TLB flush (type 2), which flushes
 		 * both. Due to a race condition with concurrent
@@ -927,7 +929,7 @@ static int gmc_v9_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev,
 		if (r) {
 			amdgpu_ring_undo(ring);
 			spin_unlock(&adev->gfx.kiq.ring_lock);
-			up_read(&adev->reset_sem);
+			up_read(&adev->reset_domain->sem);
 			return -ETIME;
 		}
 
@@ -936,10 +938,10 @@ static int gmc_v9_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev,
 		r = amdgpu_fence_wait_polling(ring, seq, adev->usec_timeout);
 		if (r < 1) {
 			dev_err(adev->dev, "wait for kiq fence error: %ld.\n", r);
-			up_read(&adev->reset_sem);
+			up_read(&adev->reset_domain->sem);
 			return -ETIME;
 		}
-		up_read(&adev->reset_sem);
+		up_read(&adev->reset_domain->sem);
 		return 0;
 	}
 
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +2 -2
index 6740eef84ee1..4e23c29e665c 100644
@@ -262,7 +262,7 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
 	if (atomic_cmpxchg(&adev->in_gpu_reset, 0, 1) != 0)
 		return;
 
-	down_write(&adev->reset_sem);
+	down_write(&adev->reset_domain->sem);
 
 	amdgpu_virt_fini_data_exchange(adev);
 
@@ -278,7 +278,7 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
 
 flr_done:
 	atomic_set(&adev->in_gpu_reset, 0);
-	up_write(&adev->reset_sem);
+	up_write(&adev->reset_domain->sem);
 
 	/* Trigger recovery for world switch failure if no TDR */
 	if (amdgpu_device_should_recover_gpu(adev)
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +2 -2
index e967d61c7134..f715780f7d20 100644
@@ -286,7 +286,7 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work)
 	if (atomic_cmpxchg(&adev->in_gpu_reset, 0, 1) != 0)
 		return;
 
-	down_write(&adev->reset_sem);
+	down_write(&adev->reset_domain->sem);
 
 	amdgpu_virt_fini_data_exchange(adev);
 
@@ -302,7 +302,7 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work)
 
 flr_done:
 	atomic_set(&adev->in_gpu_reset, 0);
-	up_write(&adev->reset_sem);
+	up_write(&adev->reset_domain->sem);
 
 	/* Trigger recovery for world switch failure if no TDR */
 	if (amdgpu_device_should_recover_gpu(adev)
Signature · 1 line
2.25.1
Reviewed-by on v4 8/11
#27 lore raw

Re: [RFC v4 08/11] drm/amdgpu: Move reset sem into reset_domain

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 6 lines

We want single instance of reset sem across all reset clients because in case of XGMI we should stop access cross device MMIO because any of them could be in a reset in the moment.

Quoted 389 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  1 -
  drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c   | 10 ++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    | 23 +++++++++----------
  .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c    | 18 ++++++++-------
  drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c     |  2 ++
  drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h     |  1 +
  drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c        |  6 +++--
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c         | 14 ++++++-----
  drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c         |  4 ++--
  drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c         |  4 ++--
  10 files changed, 46 insertions(+), 37 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -1
index cb9764513df8..ddfbcc8fd3d3 100644
@@ -1058,7 +1058,6 @@ struct amdgpu_device {
 
  	atomic_t 			in_gpu_reset;
  	enum pp_mp1_state               mp1_state;
-	struct rw_semaphore reset_sem;
  	struct amdgpu_doorbell_index doorbell_index;
 
  	struct mutex			notifier_lock;
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +6 -4
index 25e2e5bf90eb..c3728061d65a 100644
@@ -37,6 +37,8 @@
  #include "amdgpu_fw_attestation.h"
  #include "amdgpu_umr.h"
 
+#include "amdgpu_reset.h"
+
  #if defined(CONFIG_DEBUG_FS)
 
  /**
@@ -1279,7 +1281,7 @@ static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)
  	}
 
  	/* Avoid accidently unparking the sched thread during GPU reset */
-	r = down_write_killable(&adev->reset_sem);
+	r = down_write_killable(&adev->reset_domain->sem);
  	if (r)
  		return r;
 
@@ -1308,7 +1310,7 @@ static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)
  		kthread_unpark(ring->sched.thread);
  	}
 
-	up_write(&adev->reset_sem);
+	up_write(&adev->reset_domain->sem);
 
  	pm_runtime_mark_last_busy(dev->dev);
  	pm_runtime_put_autosuspend(dev->dev);
@@ -1517,7 +1519,7 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val)
  		return -ENOMEM;
 
  	/* Avoid accidently unparking the sched thread during GPU reset */
-	r = down_read_killable(&adev->reset_sem);
+	r = down_read_killable(&adev->reset_domain->sem);
  	if (r)
  		goto pro_end;
 
@@ -1560,7 +1562,7 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val)
  	/* restart the scheduler */
  	kthread_unpark(ring->sched.thread);
 
-	up_read(&adev->reset_sem);
+	up_read(&adev->reset_domain->sem);
 
  	ttm_bo_unlock_delayed_workqueue(&adev->mman.bdev, resched);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +11 -12
index d61bc0a0457c..dcbb175d336f 100644
@@ -424,10 +424,10 @@ bool amdgpu_device_skip_hw_access(struct amdgpu_device *adev)
  	 * the lock.
  	 */
  	if (in_task()) {
-		if (down_read_trylock(&adev->reset_sem))
-			up_read(&adev->reset_sem);
+		if (down_read_trylock(&adev->reset_domain->sem))
+			up_read(&adev->reset_domain->sem);
  		else
-			lockdep_assert_held(&adev->reset_sem);
+			lockdep_assert_held(&adev->reset_domain->sem);
  	}
  #endif
  	return false;
@@ -453,9 +453,9 @@ uint32_t amdgpu_device_rreg(struct amdgpu_device *adev,
  	if ((reg * 4) < adev->rmmio_size) {
  		if (!(acc_flags & AMDGPU_REGS_NO_KIQ) &&
  		    amdgpu_sriov_runtime(adev) &&
-		    down_read_trylock(&adev->reset_sem)) {
+		    down_read_trylock(&adev->reset_domain->sem)) {
  			ret = amdgpu_kiq_rreg(adev, reg);
-			up_read(&adev->reset_sem);
+			up_read(&adev->reset_domain->sem);
  		} else {
  			ret = readl(((void __iomem *)adev->rmmio) + (reg * 4));
  		}
@@ -538,9 +538,9 @@ void amdgpu_device_wreg(struct amdgpu_device *adev,
  	if ((reg * 4) < adev->rmmio_size) {
  		if (!(acc_flags & AMDGPU_REGS_NO_KIQ) &&
  		    amdgpu_sriov_runtime(adev) &&
-		    down_read_trylock(&adev->reset_sem)) {
+		    down_read_trylock(&adev->reset_domain->sem)) {
  			amdgpu_kiq_wreg(adev, reg, v);
-			up_read(&adev->reset_sem);
+			up_read(&adev->reset_domain->sem);
  		} else {
  			writel(v, ((void __iomem *)adev->rmmio) + (reg * 4));
  		}
@@ -3555,7 +3555,6 @@ int amdgpu_device_init(struct amdgpu_device *adev,
  	mutex_init(&adev->virt.vf_errors.lock);
  	hash_init(adev->mn_hash);
  	atomic_set(&adev->in_gpu_reset, 0);
-	init_rwsem(&adev->reset_sem);
  	mutex_init(&adev->psp.mutex);
  	mutex_init(&adev->notifier_lock);
 
@@ -4833,9 +4832,9 @@ static void amdgpu_device_lock_adev(struct amdgpu_device *adev,
  	atomic_set(&adev->in_gpu_reset, 1);
 
  	if (hive) {
-		down_write_nest_lock(&adev->reset_sem, &hive->hive_lock);
+		down_write_nest_lock(&adev->reset_domain->sem, &hive->hive_lock);
  	} else {
-		down_write(&adev->reset_sem);
+		down_write(&adev->reset_domain->sem);
  	}
 
  	switch (amdgpu_asic_reset_method(adev)) {
@@ -4856,7 +4855,7 @@ static void amdgpu_device_unlock_adev(struct amdgpu_device *adev)
  	amdgpu_vf_error_trans_all(adev);
  	adev->mp1_state = PP_MP1_STATE_NONE;
  	atomic_set(&adev->in_gpu_reset, 0);
-	up_write(&adev->reset_sem);
+	up_write(&adev->reset_domain->sem);
  }
 
  static void amdgpu_device_resume_display_audio(struct amdgpu_device *adev)
@@ -5476,7 +5475,7 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_sta
  	/* Fatal error, prepare for slot reset */
  	case pci_channel_io_frozen:
  		/*
-		 * Locking adev->reset_sem will prevent any external access
+		 * Locking adev->reset_domain->sem will prevent any external access
  		 * to GPU during PCI error recovery
  		 */
  		amdgpu_device_lock_adev(adev, NULL);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +10 -8
index 05117eda105b..d3e055314804 100644
@@ -31,6 +31,8 @@
  #include <linux/debugfs.h>
  #include <linux/uaccess.h>
 
+#include "amdgpu_reset.h"
+
  #define EEPROM_I2C_MADDR_VEGA20         0x0
  #define EEPROM_I2C_MADDR_ARCTURUS       0x40000
  #define EEPROM_I2C_MADDR_ARCTURUS_D342  0x0
@@ -193,12 +195,12 @@ static int __write_table_header(struct amdgpu_ras_eeprom_control *control)
  	__encode_table_header_to_buf(&control->tbl_hdr, buf);
 
  	/* i2c may be unstable in gpu reset */
-	down_read(&adev->reset_sem);
+	down_read(&adev->reset_domain->sem);
  	res = amdgpu_eeprom_write(&adev->pm.smu_i2c,
  				  control->i2c_address +
  				  control->ras_header_offset,
  				  buf, RAS_TABLE_HEADER_SIZE);
-	up_read(&adev->reset_sem);
+	up_read(&adev->reset_domain->sem);
 
  	if (res < 0) {
  		DRM_ERROR("Failed to write EEPROM table header:%d", res);
@@ -387,13 +389,13 @@ static int __amdgpu_ras_eeprom_write(struct amdgpu_ras_eeprom_control *control,
  	int res;
 
  	/* i2c may be unstable in gpu reset */
-	down_read(&adev->reset_sem);
+	down_read(&adev->reset_domain->sem);
  	buf_size = num * RAS_TABLE_RECORD_SIZE;
  	res = amdgpu_eeprom_write(&adev->pm.smu_i2c,
  				  control->i2c_address +
  				  RAS_INDEX_TO_OFFSET(control, fri),
  				  buf, buf_size);
-	up_read(&adev->reset_sem);
+	up_read(&adev->reset_domain->sem);
  	if (res < 0) {
  		DRM_ERROR("Writing %d EEPROM table records error:%d",
  			  num, res);
@@ -547,12 +549,12 @@ amdgpu_ras_eeprom_update_header(struct amdgpu_ras_eeprom_control *control)
  		goto Out;
  	}
 
-	down_read(&adev->reset_sem);
+	down_read(&adev->reset_domain->sem);
  	res = amdgpu_eeprom_read(&adev->pm.smu_i2c,
  				 control->i2c_address +
  				 control->ras_record_offset,
  				 buf, buf_size);
-	up_read(&adev->reset_sem);
+	up_read(&adev->reset_domain->sem);
  	if (res < 0) {
  		DRM_ERROR("EEPROM failed reading records:%d\n",
  			  res);
@@ -642,13 +644,13 @@ static int __amdgpu_ras_eeprom_read(struct amdgpu_ras_eeprom_control *control,
  	int res;
 
  	/* i2c may be unstable in gpu reset */
-	down_read(&adev->reset_sem);
+	down_read(&adev->reset_domain->sem);
  	buf_size = num * RAS_TABLE_RECORD_SIZE;
  	res = amdgpu_eeprom_read(&adev->pm.smu_i2c,
  				 control->i2c_address +
  				 RAS_INDEX_TO_OFFSET(control, fri),
  				 buf, buf_size);
-	up_read(&adev->reset_sem);
+	up_read(&adev->reset_domain->sem);
  	if (res < 0) {
  		DRM_ERROR("Reading %d EEPROM table records error:%d",
  			  num, res);
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c +2 -0
index 91864947063f..c0988c804459 100644
@@ -131,6 +131,8 @@ struct amdgpu_reset_domain *amdgpu_reset_create_reset_domain(enum amdgpu_reset_d
 
  	}
 
+	init_rwsem(&reset_domain->sem);
+
  	return reset_domain;
  }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +1 -0
index cc625e441fa0..80f918e87d4f 100644
@@ -80,6 +80,7 @@ struct amdgpu_reset_domain {
  	struct kref refcount;
  	struct workqueue_struct *wq;
  	enum amdgpu_reset_domain_type type;
+	struct rw_semaphore sem;
  };
 
 
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +4 -2
index 38bb42727715..222b1da9d601 100644
@@ -48,6 +48,8 @@
  #include "athub_v2_0.h"
  #include "athub_v2_1.h"
 
+#include "amdgpu_reset.h"
+
  #if 0
  static const struct soc15_reg_golden golden_settings_navi10_hdp[] =
  {
@@ -328,7 +330,7 @@ static void gmc_v10_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
  	 */
  	if (adev->gfx.kiq.ring.sched.ready &&
  	    (amdgpu_sriov_runtime(adev) || !amdgpu_sriov_vf(adev)) &&
-	    down_read_trylock(&adev->reset_sem)) {
+	    down_read_trylock(&adev->reset_domain->sem)) {
  		struct amdgpu_vmhub *hub = &adev->vmhub[vmhub];
  		const unsigned eng = 17;
  		u32 inv_req = hub->vmhub_funcs->get_invalidate_req(vmid, flush_type);
@@ -338,7 +340,7 @@ static void gmc_v10_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
  		amdgpu_virt_kiq_reg_write_reg_wait(adev, req, ack, inv_req,
  				1 << vmid);
 
-		up_read(&adev->reset_sem);
+		up_read(&adev->reset_domain->sem);
  		return;
  	}
 
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +8 -6
index 88c1eb9ad068..3a5efe969735 100644
@@ -62,6 +62,8 @@
  #include "amdgpu_ras.h"
  #include "amdgpu_xgmi.h"
 
+#include "amdgpu_reset.h"
+
  /* add these here since we already include dce12 headers and these are for DCN */
  #define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION                                                          0x055d
  #define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION_BASE_IDX                                                 2
@@ -787,13 +789,13 @@ static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
  	 */
  	if (adev->gfx.kiq.ring.sched.ready &&
  	    (amdgpu_sriov_runtime(adev) || !amdgpu_sriov_vf(adev)) &&
-	    down_read_trylock(&adev->reset_sem)) {
+	    down_read_trylock(&adev->reset_domain->sem)) {
  		uint32_t req = hub->vm_inv_eng0_req + hub->eng_distance * eng;
  		uint32_t ack = hub->vm_inv_eng0_ack + hub->eng_distance * eng;
 
  		amdgpu_virt_kiq_reg_write_reg_wait(adev, req, ack, inv_req,
  						   1 << vmid);
-		up_read(&adev->reset_sem);
+		up_read(&adev->reset_domain->sem);
  		return;
  	}
 
@@ -900,7 +902,7 @@ static int gmc_v9_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev,
  	if (amdgpu_in_reset(adev))
  		return -EIO;
 
-	if (ring->sched.ready && down_read_trylock(&adev->reset_sem)) {
+	if (ring->sched.ready && down_read_trylock(&adev->reset_domain->sem)) {
  		/* Vega20+XGMI caches PTEs in TC and TLB. Add a
  		 * heavy-weight TLB flush (type 2), which flushes
  		 * both. Due to a race condition with concurrent
@@ -927,7 +929,7 @@ static int gmc_v9_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev,
  		if (r) {
  			amdgpu_ring_undo(ring);
  			spin_unlock(&adev->gfx.kiq.ring_lock);
-			up_read(&adev->reset_sem);
+			up_read(&adev->reset_domain->sem);
  			return -ETIME;
  		}
 
@@ -936,10 +938,10 @@ static int gmc_v9_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev,
  		r = amdgpu_fence_wait_polling(ring, seq, adev->usec_timeout);
  		if (r < 1) {
  			dev_err(adev->dev, "wait for kiq fence error: %ld.\n", r);
-			up_read(&adev->reset_sem);
+			up_read(&adev->reset_domain->sem);
  			return -ETIME;
  		}
-		up_read(&adev->reset_sem);
+		up_read(&adev->reset_domain->sem);
  		return 0;
  	}
 
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +2 -2
index 6740eef84ee1..4e23c29e665c 100644
@@ -262,7 +262,7 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
  	if (atomic_cmpxchg(&adev->in_gpu_reset, 0, 1) != 0)
  		return;
 
-	down_write(&adev->reset_sem);
+	down_write(&adev->reset_domain->sem);
 
  	amdgpu_virt_fini_data_exchange(adev);
 
@@ -278,7 +278,7 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
 
  flr_done:
  	atomic_set(&adev->in_gpu_reset, 0);
-	up_write(&adev->reset_sem);
+	up_write(&adev->reset_domain->sem);
 
  	/* Trigger recovery for world switch failure if no TDR */
  	if (amdgpu_device_should_recover_gpu(adev)
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +2 -2
index e967d61c7134..f715780f7d20 100644
@@ -286,7 +286,7 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work)
  	if (atomic_cmpxchg(&adev->in_gpu_reset, 0, 1) != 0)
  		return;
 
-	down_write(&adev->reset_sem);
+	down_write(&adev->reset_domain->sem);
 
  	amdgpu_virt_fini_data_exchange(adev);
 
@@ -302,7 +302,7 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work)
 
  flr_done:
  	atomic_set(&adev->in_gpu_reset, 0);
-	up_write(&adev->reset_sem);
+	up_write(&adev->reset_domain->sem);
 
  	/* Trigger recovery for world switch failure if no TDR */
  	if (amdgpu_device_should_recover_gpu(adev)
#28 lore raw

RFC v4 9/11 drm/amdgpu: Move in_gpu_reset into reset_domain

In reply to Andrey Grodzovsky

We should have a single instance per entrire reset domain.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  7 ++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 10 +++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c  |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h  |  1 +
 drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c      |  4 ++--
 drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c      |  4 ++--
 6 files changed, 15 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -5
index ddfbcc8fd3d3..b89406b01694 100644
@@ -1056,7 +1056,6 @@ struct amdgpu_device {
 	bool				in_s4;
 	bool				in_s0ix;
 
-	atomic_t 			in_gpu_reset;
 	enum pp_mp1_state               mp1_state;
 	struct amdgpu_doorbell_index doorbell_index;
 
@@ -1463,8 +1462,6 @@ static inline bool amdgpu_is_tmz(struct amdgpu_device *adev)
        return adev->gmc.tmz_enabled;
 }
 
-static inline int amdgpu_in_reset(struct amdgpu_device *adev)
-{
-	return atomic_read(&adev->in_gpu_reset);
-}
+int amdgpu_in_reset(struct amdgpu_device *adev);
+
 #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7 -3
index dcbb175d336f..e05d7cbefd2c 100644
@@ -3554,7 +3554,6 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 	mutex_init(&adev->mn_lock);
 	mutex_init(&adev->virt.vf_errors.lock);
 	hash_init(adev->mn_hash);
-	atomic_set(&adev->in_gpu_reset, 0);
 	mutex_init(&adev->psp.mutex);
 	mutex_init(&adev->notifier_lock);
 
@@ -4829,7 +4828,7 @@ int amdgpu_do_asic_reset(struct list_head *device_list_handle,
 static void amdgpu_device_lock_adev(struct amdgpu_device *adev,
 				struct amdgpu_hive_info *hive)
 {
-	atomic_set(&adev->in_gpu_reset, 1);
+	atomic_set(&adev->reset_domain->in_gpu_reset, 1);
 
 	if (hive) {
 		down_write_nest_lock(&adev->reset_domain->sem, &hive->hive_lock);
@@ -4854,7 +4853,7 @@ static void amdgpu_device_unlock_adev(struct amdgpu_device *adev)
 {
 	amdgpu_vf_error_trans_all(adev);
 	adev->mp1_state = PP_MP1_STATE_NONE;
-	atomic_set(&adev->in_gpu_reset, 0);
+	atomic_set(&adev->reset_domain->in_gpu_reset, 0);
 	up_write(&adev->reset_domain->sem);
 }
 
@@ -5699,6 +5698,11 @@ void amdgpu_device_invalidate_hdp(struct amdgpu_device *adev,
 	amdgpu_asic_invalidate_hdp(adev, ring);
 }
 
+int amdgpu_in_reset(struct amdgpu_device *adev)
+{
+	return atomic_read(&adev->reset_domain->in_gpu_reset);
+	}
+	
 /**
  * amdgpu_device_halt() - bring hardware to some kind of halt state
  *
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c +1 -0
index c0988c804459..5ab72c3bfbda 100644
@@ -131,6 +131,7 @@ struct amdgpu_reset_domain *amdgpu_reset_create_reset_domain(enum amdgpu_reset_d
 
 	}
 
+	atomic_set(&reset_domain->in_gpu_reset, 0);
 	init_rwsem(&reset_domain->sem);
 
 	return reset_domain;
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +1 -0
index 80f918e87d4f..ea6fc98ea927 100644
@@ -81,6 +81,7 @@ struct amdgpu_reset_domain {
 	struct workqueue_struct *wq;
 	enum amdgpu_reset_domain_type type;
 	struct rw_semaphore sem;
+	atomic_t in_gpu_reset;
 };
 
 
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +2 -2
index 4e23c29e665c..b81acf59870c 100644
@@ -259,7 +259,7 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
 	 * otherwise the mailbox msg will be ruined/reseted by
 	 * the VF FLR.
 	 */
-	if (atomic_cmpxchg(&adev->in_gpu_reset, 0, 1) != 0)
+	if (atomic_cmpxchg(&adev->reset_domain->in_gpu_reset, 0, 1) != 0)
 		return;
 
 	down_write(&adev->reset_domain->sem);
@@ -277,7 +277,7 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
 	} while (timeout > 1);
 
 flr_done:
-	atomic_set(&adev->in_gpu_reset, 0);
+	atomic_set(&adev->reset_domain->in_gpu_reset, 0);
 	up_write(&adev->reset_domain->sem);
 
 	/* Trigger recovery for world switch failure if no TDR */
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +2 -2
index f715780f7d20..22c10b97ea81 100644
@@ -283,7 +283,7 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work)
 	 * otherwise the mailbox msg will be ruined/reseted by
 	 * the VF FLR.
 	 */
-	if (atomic_cmpxchg(&adev->in_gpu_reset, 0, 1) != 0)
+	if (atomic_cmpxchg(&adev->reset_domain->in_gpu_reset, 0, 1) != 0)
 		return;
 
 	down_write(&adev->reset_domain->sem);
@@ -301,7 +301,7 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work)
 	} while (timeout > 1);
 
 flr_done:
-	atomic_set(&adev->in_gpu_reset, 0);
+	atomic_set(&adev->reset_domain->in_gpu_reset, 0);
 	up_write(&adev->reset_domain->sem);
 
 	/* Trigger recovery for world switch failure if no TDR */
Signature · 1 line
2.25.1
Reviewed-by on v4 9/11
#29 lore raw

Re: [RFC v4 09/11] drm/amdgpu: Move in_gpu_reset into reset_domain

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 4 lines

We should have a single instance per entrire reset domain.

Quoted 142 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  7 ++-----
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 10 +++++++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c  |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h  |  1 +
  drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c      |  4 ++--
  drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c      |  4 ++--
  6 files changed, 15 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -5
index ddfbcc8fd3d3..b89406b01694 100644
@@ -1056,7 +1056,6 @@ struct amdgpu_device {
  	bool				in_s4;
  	bool				in_s0ix;
 
-	atomic_t 			in_gpu_reset;
  	enum pp_mp1_state               mp1_state;
  	struct amdgpu_doorbell_index doorbell_index;
 
@@ -1463,8 +1462,6 @@ static inline bool amdgpu_is_tmz(struct amdgpu_device *adev)
         return adev->gmc.tmz_enabled;
  }
 
-static inline int amdgpu_in_reset(struct amdgpu_device *adev)
-{
-	return atomic_read(&adev->in_gpu_reset);
-}
+int amdgpu_in_reset(struct amdgpu_device *adev);
+
  #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7 -3
index dcbb175d336f..e05d7cbefd2c 100644
@@ -3554,7 +3554,6 @@ int amdgpu_device_init(struct amdgpu_device *adev,
  	mutex_init(&adev->mn_lock);
  	mutex_init(&adev->virt.vf_errors.lock);
  	hash_init(adev->mn_hash);
-	atomic_set(&adev->in_gpu_reset, 0);
  	mutex_init(&adev->psp.mutex);
  	mutex_init(&adev->notifier_lock);
 
@@ -4829,7 +4828,7 @@ int amdgpu_do_asic_reset(struct list_head *device_list_handle,
  static void amdgpu_device_lock_adev(struct amdgpu_device *adev,
  				struct amdgpu_hive_info *hive)
  {
-	atomic_set(&adev->in_gpu_reset, 1);
+	atomic_set(&adev->reset_domain->in_gpu_reset, 1);
 
  	if (hive) {
  		down_write_nest_lock(&adev->reset_domain->sem, &hive->hive_lock);
@@ -4854,7 +4853,7 @@ static void amdgpu_device_unlock_adev(struct amdgpu_device *adev)
  {
  	amdgpu_vf_error_trans_all(adev);
  	adev->mp1_state = PP_MP1_STATE_NONE;
-	atomic_set(&adev->in_gpu_reset, 0);
+	atomic_set(&adev->reset_domain->in_gpu_reset, 0);
  	up_write(&adev->reset_domain->sem);
  }
 
@@ -5699,6 +5698,11 @@ void amdgpu_device_invalidate_hdp(struct amdgpu_device *adev,
  	amdgpu_asic_invalidate_hdp(adev, ring);
  }
 
+int amdgpu_in_reset(struct amdgpu_device *adev)
+{
+	return atomic_read(&adev->reset_domain->in_gpu_reset);
+	}
+	
  /**
   * amdgpu_device_halt() - bring hardware to some kind of halt state
   *
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c +1 -0
index c0988c804459..5ab72c3bfbda 100644
@@ -131,6 +131,7 @@ struct amdgpu_reset_domain *amdgpu_reset_create_reset_domain(enum amdgpu_reset_d
 
  	}
 
+	atomic_set(&reset_domain->in_gpu_reset, 0);
  	init_rwsem(&reset_domain->sem);
 
  	return reset_domain;
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +1 -0
index 80f918e87d4f..ea6fc98ea927 100644
@@ -81,6 +81,7 @@ struct amdgpu_reset_domain {
  	struct workqueue_struct *wq;
  	enum amdgpu_reset_domain_type type;
  	struct rw_semaphore sem;
+	atomic_t in_gpu_reset;
  };
 
 
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +2 -2
index 4e23c29e665c..b81acf59870c 100644
@@ -259,7 +259,7 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
  	 * otherwise the mailbox msg will be ruined/reseted by
  	 * the VF FLR.
  	 */
-	if (atomic_cmpxchg(&adev->in_gpu_reset, 0, 1) != 0)
+	if (atomic_cmpxchg(&adev->reset_domain->in_gpu_reset, 0, 1) != 0)
  		return;
 
  	down_write(&adev->reset_domain->sem);
@@ -277,7 +277,7 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
  	} while (timeout > 1);
 
  flr_done:
-	atomic_set(&adev->in_gpu_reset, 0);
+	atomic_set(&adev->reset_domain->in_gpu_reset, 0);
  	up_write(&adev->reset_domain->sem);
 
  	/* Trigger recovery for world switch failure if no TDR */
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +2 -2
index f715780f7d20..22c10b97ea81 100644
@@ -283,7 +283,7 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work)
  	 * otherwise the mailbox msg will be ruined/reseted by
  	 * the VF FLR.
  	 */
-	if (atomic_cmpxchg(&adev->in_gpu_reset, 0, 1) != 0)
+	if (atomic_cmpxchg(&adev->reset_domain->in_gpu_reset, 0, 1) != 0)
  		return;
 
  	down_write(&adev->reset_domain->sem);
@@ -301,7 +301,7 @@ static void xgpu_nv_mailbox_flr_work(struct work_struct *work)
  	} while (timeout > 1);
 
  flr_done:
-	atomic_set(&adev->in_gpu_reset, 0);
+	atomic_set(&adev->reset_domain->in_gpu_reset, 0);
  	up_write(&adev->reset_domain->sem);
 
  	/* Trigger recovery for world switch failure if no TDR */
#30 lore raw

RFC v4 10/11 drm/amdgpu: Rework amdgpu_device_lock_adev

In reply to Andrey Grodzovsky

This functions needs to be split into 2 parts where one is called only once for locking single instance of reset_domain's sem and reset flag and the other part which handles MP1 states should still be called for each device in XGMI hive.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 48 ++++++++++++++++------
 1 file changed, 35 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +35 -13
index e05d7cbefd2c..aaecf0797484 100644
@@ -4825,16 +4825,20 @@ int amdgpu_do_asic_reset(struct list_head *device_list_handle,
 	return r;
 }
 
-static void amdgpu_device_lock_adev(struct amdgpu_device *adev,
-				struct amdgpu_hive_info *hive)
+static void amdgpu_device_lock_reset_domain(struct amdgpu_reset_domain *reset_domain,
+					    struct amdgpu_hive_info *hive)
 {
-	atomic_set(&adev->reset_domain->in_gpu_reset, 1);
+	atomic_set(&reset_domain->in_gpu_reset, 1);
 
 	if (hive) {
-		down_write_nest_lock(&adev->reset_domain->sem, &hive->hive_lock);
+		down_write_nest_lock(&reset_domain->sem, &hive->hive_lock);
 	} else {
-		down_write(&adev->reset_domain->sem);
+		down_write(&reset_domain->sem);
 	}
+}
+
+static void amdgpu_device_set_mp1_state(struct amdgpu_device *adev)
+{
 
 	switch (amdgpu_asic_reset_method(adev)) {
 	case AMD_RESET_METHOD_MODE1:
@@ -4849,14 +4853,19 @@ static void amdgpu_device_lock_adev(struct amdgpu_device *adev,
 	}
 }
 
-static void amdgpu_device_unlock_adev(struct amdgpu_device *adev)
+static void amdgpu_device_unset_mp1_state(struct amdgpu_device *adev)
 {
 	amdgpu_vf_error_trans_all(adev);
 	adev->mp1_state = PP_MP1_STATE_NONE;
-	atomic_set(&adev->reset_domain->in_gpu_reset, 0);
-	up_write(&adev->reset_domain->sem);
 }
 
+static void amdgpu_device_unlock_reset_domain(struct amdgpu_reset_domain *reset_domain)
+{
+	atomic_set(&reset_domain->in_gpu_reset, 0);
+	up_write(&reset_domain->sem);
+}
+
+
 static void amdgpu_device_resume_display_audio(struct amdgpu_device *adev)
 {
 	struct pci_dev *p = NULL;
@@ -5060,10 +5069,15 @@ int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
 		device_list_handle = &device_list;
 	}
 
+	/* We need to lock reset domain only once both for XGMI and single device */
+	tmp_adev = list_first_entry(device_list_handle, struct amdgpu_device,
+				    reset_list);
+	amdgpu_device_lock_reset_domain(tmp_adev->reset_domain, hive);
+
 	/* block all schedulers and reset given job's ring */
 	list_for_each_entry(tmp_adev, device_list_handle, reset_list) {
 
-		amdgpu_device_lock_adev(tmp_adev, hive);
+		amdgpu_device_set_mp1_state(tmp_adev);
 
 		/*
 		 * Try to put the audio codec into suspend state
@@ -5213,9 +5227,14 @@ int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
 
 		if (audio_suspended)
 			amdgpu_device_resume_display_audio(tmp_adev);
-		amdgpu_device_unlock_adev(tmp_adev);
+
+		amdgpu_device_unset_mp1_state(tmp_adev);
 	}
 
+	tmp_adev = list_first_entry(device_list_handle, struct amdgpu_device,
+					    reset_list);
+	amdgpu_device_unlock_reset_domain(tmp_adev->reset_domain);
+
 	if (hive) {
 		mutex_unlock(&hive->hive_lock);
 		amdgpu_put_xgmi_hive(hive);
@@ -5477,7 +5496,8 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_sta
 		 * Locking adev->reset_domain->sem will prevent any external access
 		 * to GPU during PCI error recovery
 		 */
-		amdgpu_device_lock_adev(adev, NULL);
+		amdgpu_device_lock_reset_domain(adev->reset_domain, NULL);
+		amdgpu_device_set_mp1_state(adev);
 
 		/*
 		 * Block any work scheduling as we do for regular GPU reset
@@ -5584,7 +5604,8 @@ pci_ers_result_t amdgpu_pci_slot_reset(struct pci_dev *pdev)
 		DRM_INFO("PCIe error recovery succeeded\n");
 	} else {
 		DRM_ERROR("PCIe error recovery failed, err:%d", r);
-		amdgpu_device_unlock_adev(adev);
+		amdgpu_device_unset_mp1_state(adev);
+		amdgpu_device_unlock_reset_domain(adev->reset_domain);
 	}
 
 	return r ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED;
@@ -5621,7 +5642,8 @@ void amdgpu_pci_resume(struct pci_dev *pdev)
 		drm_sched_start(&ring->sched, true);
 	}
 
-	amdgpu_device_unlock_adev(adev);
+	amdgpu_device_unset_mp1_state(adev);
+	amdgpu_device_unlock_reset_domain(adev->reset_domain);
 }
 
 bool amdgpu_device_cache_pci_state(struct pci_dev *pdev)
Signature · 1 line
2.25.1
#31 lore raw

Re: [RFC v4 10/11] drm/amdgpu: Rework amdgpu_device_lock_adev

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 49 lines

This functions needs to be split into 2 parts where one is called only once for locking single instance of reset_domain's sem and reset flag and the other part which handles MP1 states should still be called for each device in XGMI hive.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 48 ++++++++++++++++------
  1 file changed, 35 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -6
index e05d7cbefd2c..aaecf0797484 100644
@@ -4825,16 +4825,20 @@ int amdgpu_do_asic_reset(struct list_head *device_list_handle,
  	return r;
  }
 
-static void amdgpu_device_lock_adev(struct amdgpu_device *adev,
-				struct amdgpu_hive_info *hive)
+static void amdgpu_device_lock_reset_domain(struct amdgpu_reset_domain *reset_domain,
+					    struct amdgpu_hive_info *hive)
  {
-	atomic_set(&adev->reset_domain->in_gpu_reset, 1);
+	atomic_set(&reset_domain->in_gpu_reset, 1);
 
  	if (hive) {
-		down_write_nest_lock(&adev->reset_domain->sem, &hive->hive_lock);
+		down_write_nest_lock(&reset_domain->sem, &hive->hive_lock);
  	} else {
-		down_write(&adev->reset_domain->sem);
+		down_write(&reset_domain->sem);
  	}
+}
+
+static void amdgpu_device_set_mp1_state(struct amdgpu_device *adev)
+{
 
  	switch (amdgpu_asic_reset_method(adev)) {
  	case AMD_RESET_METHOD_MODE1:
@@ -4849,14 +4853,19 @@ static void amdgpu_device_lock_adev(struct amdgpu_device *adev,
  	}
  }
 
-static void amdgpu_device_unlock_adev(struct amdgpu_device *adev)
+static void amdgpu_device_unset_mp1_state(struct amdgpu_device *adev)
  {
  	amdgpu_vf_error_trans_all(adev);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void amdgpu_device_lock_adev(struct amdgpu_device *adev, · line 4866

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -2
  	adev->mp1_state = PP_MP1_STATE_NONE;
-	atomic_set(&adev->reset_domain->in_gpu_reset, 0);
-	up_write(&adev->reset_domain->sem);
  }
 
+static void amdgpu_device_unlock_reset_domain(struct amdgpu_reset_domain *reset_domain)
+{
+	atomic_set(&reset_domain->in_gpu_reset, 0);
+	up_write(&reset_domain->sem);
+}

I would move this into amdgpu_reset.c and call it amdgpu_reset_domain_unlock().

Same of course for amdgpu_reset_domain_lock()...

Apart from that looks good to me,
Christian.

Quoted 68 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +20 -5
+
+
  static void amdgpu_device_resume_display_audio(struct amdgpu_device *adev)
  {
  	struct pci_dev *p = NULL;
@@ -5060,10 +5069,15 @@ int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
  		device_list_handle = &device_list;
  	}
 
+	/* We need to lock reset domain only once both for XGMI and single device */
+	tmp_adev = list_first_entry(device_list_handle, struct amdgpu_device,
+				    reset_list);
+	amdgpu_device_lock_reset_domain(tmp_adev->reset_domain, hive);
+
  	/* block all schedulers and reset given job's ring */
  	list_for_each_entry(tmp_adev, device_list_handle, reset_list) {
 
-		amdgpu_device_lock_adev(tmp_adev, hive);
+		amdgpu_device_set_mp1_state(tmp_adev);
 
  		/*
  		 * Try to put the audio codec into suspend state
@@ -5213,9 +5227,14 @@ int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
 
  		if (audio_suspended)
  			amdgpu_device_resume_display_audio(tmp_adev);
-		amdgpu_device_unlock_adev(tmp_adev);
+
+		amdgpu_device_unset_mp1_state(tmp_adev);
  	}
 
+	tmp_adev = list_first_entry(device_list_handle, struct amdgpu_device,
+					    reset_list);
+	amdgpu_device_unlock_reset_domain(tmp_adev->reset_domain);
+
  	if (hive) {
  		mutex_unlock(&hive->hive_lock);
  		amdgpu_put_xgmi_hive(hive);
@@ -5477,7 +5496,8 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_sta
  		 * Locking adev->reset_domain->sem will prevent any external access
  		 * to GPU during PCI error recovery
  		 */
-		amdgpu_device_lock_adev(adev, NULL);
+		amdgpu_device_lock_reset_domain(adev->reset_domain, NULL);
+		amdgpu_device_set_mp1_state(adev);
 
  		/*
  		 * Block any work scheduling as we do for regular GPU reset
@@ -5584,7 +5604,8 @@ pci_ers_result_t amdgpu_pci_slot_reset(struct pci_dev *pdev)
  		DRM_INFO("PCIe error recovery succeeded\n");
  	} else {
  		DRM_ERROR("PCIe error recovery failed, err:%d", r);
-		amdgpu_device_unlock_adev(adev);
+		amdgpu_device_unset_mp1_state(adev);
+		amdgpu_device_unlock_reset_domain(adev->reset_domain);
  	}
 
  	return r ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED;
@@ -5621,7 +5642,8 @@ void amdgpu_pci_resume(struct pci_dev *pdev)
  		drm_sched_start(&ring->sched, true);
  	}
 
-	amdgpu_device_unlock_adev(adev);
+	amdgpu_device_unset_mp1_state(adev);
+	amdgpu_device_unlock_reset_domain(adev->reset_domain);
  }
 
  bool amdgpu_device_cache_pci_state(struct pci_dev *pdev)
#32 lore raw

RFC v4 11/11 Revert 'drm/amdgpu: annotate a false positive recursive locking'

In reply to Andrey Grodzovsky

Since we have a single instance of reset semaphore which we lock only once even for XGMI hive we don't need the nested locking hint anymore.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -10
index aaecf0797484..75d0dd289023 100644
@@ -4825,16 +4825,10 @@ int amdgpu_do_asic_reset(struct list_head *device_list_handle,
 	return r;
 }
 
-static void amdgpu_device_lock_reset_domain(struct amdgpu_reset_domain *reset_domain,
-					    struct amdgpu_hive_info *hive)
+static void amdgpu_device_lock_reset_domain(struct amdgpu_reset_domain *reset_domain)
 {
 	atomic_set(&reset_domain->in_gpu_reset, 1);
-
-	if (hive) {
-		down_write_nest_lock(&reset_domain->sem, &hive->hive_lock);
-	} else {
-		down_write(&reset_domain->sem);
-	}
+	down_write(&reset_domain->sem);
 }
 
 static void amdgpu_device_set_mp1_state(struct amdgpu_device *adev)
@@ -5072,7 +5066,7 @@ int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
 	/* We need to lock reset domain only once both for XGMI and single device */
 	tmp_adev = list_first_entry(device_list_handle, struct amdgpu_device,
 				    reset_list);
-	amdgpu_device_lock_reset_domain(tmp_adev->reset_domain, hive);
+	amdgpu_device_lock_reset_domain(tmp_adev->reset_domain);
 
 	/* block all schedulers and reset given job's ring */
 	list_for_each_entry(tmp_adev, device_list_handle, reset_list) {
@@ -5496,7 +5490,7 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_sta
 		 * Locking adev->reset_domain->sem will prevent any external access
 		 * to GPU during PCI error recovery
 		 */
-		amdgpu_device_lock_reset_domain(adev->reset_domain, NULL);
+		amdgpu_device_lock_reset_domain(adev->reset_domain);
 		amdgpu_device_set_mp1_state(adev);
 
 		/*
Signature · 1 line
2.25.1
Reviewed-by on v4 11/11
#33 lore raw

Re: [RFC v4 11/11] Revert 'drm/amdgpu: annotate a false positive recursive locking'

Am 09.02.22 um 01:23 schrieb Andrey Grodzovsky:

Quoted 5 lines

Since we have a single instance of reset semaphore which we lock only once even for XGMI hive we don't need the nested locking hint anymore.

Oh, yes please :)

Quoted 45 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 14 ++++----------
  1 file changed, 4 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -10
index aaecf0797484..75d0dd289023 100644
@@ -4825,16 +4825,10 @@ int amdgpu_do_asic_reset(struct list_head *device_list_handle,
  	return r;
  }
 
-static void amdgpu_device_lock_reset_domain(struct amdgpu_reset_domain *reset_domain,
-					    struct amdgpu_hive_info *hive)
+static void amdgpu_device_lock_reset_domain(struct amdgpu_reset_domain *reset_domain)
  {
  	atomic_set(&reset_domain->in_gpu_reset, 1);
-
-	if (hive) {
-		down_write_nest_lock(&reset_domain->sem, &hive->hive_lock);
-	} else {
-		down_write(&reset_domain->sem);
-	}
+	down_write(&reset_domain->sem);
  }
 
  static void amdgpu_device_set_mp1_state(struct amdgpu_device *adev)
@@ -5072,7 +5066,7 @@ int amdgpu_device_gpu_recover_imp(struct amdgpu_device *adev,
  	/* We need to lock reset domain only once both for XGMI and single device */
  	tmp_adev = list_first_entry(device_list_handle, struct amdgpu_device,
  				    reset_list);
-	amdgpu_device_lock_reset_domain(tmp_adev->reset_domain, hive);
+	amdgpu_device_lock_reset_domain(tmp_adev->reset_domain);
 
  	/* block all schedulers and reset given job's ring */
  	list_for_each_entry(tmp_adev, device_list_handle, reset_list) {
@@ -5496,7 +5490,7 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_sta
  		 * Locking adev->reset_domain->sem will prevent any external access
  		 * to GPU during PCI error recovery
  		 */
-		amdgpu_device_lock_reset_domain(adev->reset_domain, NULL);
+		amdgpu_device_lock_reset_domain(adev->reset_domain);
  		amdgpu_device_set_mp1_state(adev);
 
  		/*