Skip to contentSkip to conversation

drm/amdgpu/sriov: For sriov runtime, use kiq to do invalidate tlb

PATCH In review Emily Deng 5 participants 12 messages Aug 15, 2018 – Aug 16, 2018 9 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Emily Deng

author
#0 lore raw

PATCH 1/2 drm/amdgpu/sriov: For sriov runtime, use kiq to do invalidate tlb

To avoid the tlb flush not interrupted by world switch, use kiq and one command to do tlb invalidate.

v2:
Add firmware version checking.

v3:
Refine the code, and move the firmware checking into gfx_v9_0_ring_emit_reg_write_reg_wait.

SWDEV-161497

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h      |  4 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c |  3 --
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 15 +++++++-
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    | 61 ++++++++++++++++++++++++++++++++
 4 files changed, 79 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
index 07924d4..67b584b 100644
@@ -210,6 +210,10 @@ enum amdgpu_kiq_irq {
 	AMDGPU_CP_KIQ_IRQ_LAST
 };
 
+#define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
+#define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
+#define MAX_KIQ_REG_TRY 20
+
 int amdgpu_device_ip_set_clockgating_state(void *dev,
 					   enum amd_ip_block_type block_type,
 					   enum amd_clockgating_state state);
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -3
index 21adb1b6..3885636 100644
@@ -22,9 +22,6 @@
  */
 
 #include "amdgpu.h"
-#define MAX_KIQ_REG_WAIT	5000 /* in usecs, 5ms */
-#define MAX_KIQ_REG_BAILOUT_INTERVAL	5 /* in msecs, 5ms */
-#define MAX_KIQ_REG_TRY 20
 
 uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev)
 {
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +14 -1
index 76d979e..c9b3db4 100644
@@ -4348,8 +4348,21 @@ static void gfx_v9_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,
 						  uint32_t ref, uint32_t mask)
 {
 	int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
+	struct amdgpu_device *adev = ring->adev;
+	bool fw_version_ok = false;
 
-	if (amdgpu_sriov_vf(ring->adev))
+	if (ring->funcs->type == AMDGPU_RING_TYPE_GFX) {
+		if ((adev->gfx.me_fw_version >= 0x0000009c) && (adev->gfx.me_feature_version >= 42))
+			if ((adev->gfx.pfp_fw_version >=  0x000000b1) && (adev->gfx.pfp_feature_version >= 42))
+				fw_version_ok = true;
+	} else {
+		if ((adev->gfx.mec_fw_version >=  0x00000193) && (adev->gfx.mec_feature_version >= 42))
+			fw_version_ok = true;
+	}
+
+	fw_version_ok = (adev->asic_type == CHIP_VEGA10) ? fw_version_ok : false;
+
+	if (amdgpu_sriov_vf(adev) && fw_version_ok)
 		gfx_v9_0_wait_reg_mem(ring, usepfp, 0, 1, reg0, reg1,
 				      ref, mask, 0x20);
 	else
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +61 -0

79 lines not on this page · raw message

Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1534326508-17477-1-git-send-email-Emily.Deng-5C7GfCeVMHo@public.gmane.org

author
#2 lore raw

PATCH 1/1 drm/amdgpu: MC_VM_FB_OFFSET is pf only register.

---
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +4 -1
index b60ed28..52b13e6 100644
@@ -693,7 +693,10 @@ static void gmc_v9_0_vram_gtt_location(struct amdgpu_device *adev,
 	amdgpu_device_vram_location(adev, &adev->gmc, base);
 	amdgpu_device_gart_location(adev, mc);
 	/* base offset of vram pages */
-	adev->vm_manager.vram_base_offset = gfxhub_v1_0_get_mc_fb_offset(adev);
+	if (!amdgpu_sriov_vf(adev))
+		adev->vm_manager.vram_base_offset = gfxhub_v1_0_get_mc_fb_offset(adev);
+	else
+		adev->vm_manager.vram_base_offset = 0;
 }
 
 /**
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1534326508-17477-2-git-send-email-Emily.Deng-5C7GfCeVMHo@public.gmane.org

#4 lore raw

RE: [PATCH] drm/amdgpu: MC_VM_FB_OFFSET is pf only register.

Sorry, sent the wrong patch, please ignore this email.

Quoted 31 lines

-----Original Message-----
From: Emily Deng <[email protected]>
Sent: Wednesday, August 15, 2018 5:48 PM
To: [email protected]
Cc: Deng, Emily <[email protected]>
Subject: [PATCH] drm/amdgpu: MC_VM_FB_OFFSET is pf only register.

---
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 5 ++++-

1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +4 -1
index b60ed28..52b13e6 100644
@@ -693,7 +693,10 @@ static void gmc_v9_0_vram_gtt_location(struct
 amdgpu_device *adev,
 	amdgpu_device_vram_location(adev, &adev->gmc, base);
 	amdgpu_device_gart_location(adev, mc);
 	/* base offset of vram pages */
-	adev->vm_manager.vram_base_offset =
 gfxhub_v1_0_get_mc_fb_offset(adev);
+	if (!amdgpu_sriov_vf(adev))
+		adev->vm_manager.vram_base_offset =
 gfxhub_v1_0_get_mc_fb_offset(adev);
+	else
+		adev->vm_manager.vram_base_offset = 0;

}

Quoted 3 lines

/**
--
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#5 lore raw
In reply to a message not in the archive

Am 15.08.2018 um 11:48 schrieb Emily Deng:

Quoted 54 lines

To avoid the tlb flush not interrupted by world switch, use kiq and one command to do tlb invalidate.

v2:
Add firmware version checking.

v3:
Refine the code, and move the firmware checking into gfx_v9_0_ring_emit_reg_write_reg_wait.

SWDEV-161497

---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h      |  4 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c |  3 --
  drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 15 +++++++-
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    | 61 ++++++++++++++++++++++++++++++++
  4 files changed, 79 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
index 07924d4..67b584b 100644
@@ -210,6 +210,10 @@ enum amdgpu_kiq_irq {
  	AMDGPU_CP_KIQ_IRQ_LAST
  };
 
+#define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
+#define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
+#define MAX_KIQ_REG_TRY 20
+
  int amdgpu_device_ip_set_clockgating_state(void *dev,
  					   enum amd_ip_block_type block_type,
  					   enum amd_clockgating_state state);
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -3
index 21adb1b6..3885636 100644
@@ -22,9 +22,6 @@
   */
 
  #include "amdgpu.h"
-#define MAX_KIQ_REG_WAIT	5000 /* in usecs, 5ms */
-#define MAX_KIQ_REG_BAILOUT_INTERVAL	5 /* in msecs, 5ms */
-#define MAX_KIQ_REG_TRY 20
 
  uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev)
  {
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -0
index 76d979e..c9b3db4 100644

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static void gfx_v9_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring, · line 4356

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +5 -1
@@ -4348,8 +4348,21 @@ static void gfx_v9_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,
  						  uint32_t ref, uint32_t mask)
  {
  	int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
+	struct amdgpu_device *adev = ring->adev;
+	bool fw_version_ok = false;
 
-	if (amdgpu_sriov_vf(ring->adev))
+	if (ring->funcs->type == AMDGPU_RING_TYPE_GFX) {
+		if ((adev->gfx.me_fw_version >= 0x0000009c) && (adev->gfx.me_feature_version >= 42))
+			if ((adev->gfx.pfp_fw_version >=  0x000000b1) && (adev->gfx.pfp_feature_version >= 42))

Why "if (...) if (...)" ? Just if (... && ...) should do as well.

Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +9 -0
+				fw_version_ok = true;
+	} else {
+		if ((adev->gfx.mec_fw_version >=  0x00000193) && (adev->gfx.mec_feature_version >= 42))
+			fw_version_ok = true;
+	}
+
+	fw_version_ok = (adev->asic_type == CHIP_VEGA10) ? fw_version_ok : false;
+
+	if (amdgpu_sriov_vf(adev) && fw_version_ok)
  		gfx_v9_0_wait_reg_mem(ring, usepfp, 0, 1, reg0, reg1,
  				      ref, mask, 0x20);
  	else
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
index ed467de..3419178 100644

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid) · line 315

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +2 -0
@@ -311,6 +311,60 @@ static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid)
  	return req;
  }
 
+signed long  amdgpu_kiq_invalidate_tlb(struct amdgpu_device *adev, struct amdgpu_vmhub *hub,
+		unsigned eng, u32 req, uint32_t vmid)

Better make that function just a generic reg_write_reg_wait function, instead of specialized for tlb flushing.

Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +26 -0
+{
+	signed long r, cnt = 0;
+	unsigned long flags;
+	uint32_t seq;
+	struct amdgpu_kiq *kiq = &adev->gfx.kiq;
+	struct amdgpu_ring *ring = &kiq->ring;
+
+	if (!ring->ready) {
+		return -EINVAL;
+	}
+
+	spin_lock_irqsave(&kiq->ring_lock, flags);
+
+	amdgpu_ring_alloc(ring, 32);
+	amdgpu_ring_emit_reg_write_reg_wait(ring, hub->vm_inv_eng0_req + eng,
+					    hub->vm_inv_eng0_ack + eng,
+					    req, 1 << vmid);
+	amdgpu_fence_emit_polling(ring, &seq);
+	amdgpu_ring_commit(ring);
+	spin_unlock_irqrestore(&kiq->ring_lock, flags);
+
+	r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
+
+	/* don't wait anymore for gpu reset case because this way may
+	 * block gpu_recover() routine forever, e.g. this virt_kiq_rreg
+	 * is triggered in TTM and ttm_bo_lock_delayed_workqueue() will

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid) · line 351

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +10 -0
+	 * never return if we keep waiting in virt_kiq_rreg, which cause
+	 * gpu_recover() hang there.
+	 *
+	 * also don't wait anymore for IRQ context
+	 * */
+	if (r < 1 && (adev->in_gpu_reset || in_interrupt()))
+		goto failed_kiq;
+
+	if (in_interrupt())
+		might_sleep();

What should that be good for?

Quoted 28 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +17 -0
+
+	while (r < 1 && cnt++ < MAX_KIQ_REG_TRY) {
+		msleep(MAX_KIQ_REG_BAILOUT_INTERVAL);
+		r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
+	}
+
+	if (cnt > MAX_KIQ_REG_TRY)
+		goto failed_kiq;
+
+	return 0;
+
+failed_kiq:
+	pr_err("failed to invalidate tlb with kiq\n");
+	return r;
+}
+
  /*
   * GART
   * VMID 0 is the physical GPU addresses as used by the kernel.
@@ -332,6 +386,7 @@ static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev,
  	/* Use register 17 for GART */
  	const unsigned eng = 17;
  	unsigned i, j;
+	int r;
 
  	spin_lock(&adev->gmc.invalidate_lock);
 

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, · line 397

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
@@ -339,6 +394,12 @@ static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev,
  		struct amdgpu_vmhub *hub = &adev->vmhub[i];
  		u32 tmp = gmc_v9_0_get_invalidate_req(vmid);
 
+		if (amdgpu_sriov_vf(adev) ) {

As discussed drop the sriov check here and use the KIQ path all the time.

Christian.

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, · line 405

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +5 -0
+			r = amdgpu_kiq_invalidate_tlb(adev, hub, eng, tmp, vmid);
+			if (!r)
+				continue;
+		}
+
  		WREG32_NO_KIQ(hub->vm_inv_eng0_req + eng, tmp);
 
  		/* Busy wait for ACK.*/

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 5f51ffa1-1e84-dacf-840c-76bd9cbb282b-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#7 lore raw
Quoted 75 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Wednesday, August 15, 2018 6:50 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH 1/2] drm/amdgpu/sriov: For sriov runtime, use kiq to do invalidate tlb

Am 15.08.2018 um 11:48 schrieb Emily Deng:

Quoted 10 lines

To avoid the tlb flush not interrupted by world switch, use kiq and one command to do tlb invalidate.

v2:
Add firmware version checking.

v3:
Refine the code, and move the firmware checking into gfx_v9_0_ring_emit_reg_write_reg_wait.

Quoted 8 lines

SWDEV-161497

---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h      |  4 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c |  3 --
  drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 15 +++++++-
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    | 61

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

Quoted 8 lines
  4 files changed, 79 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index 07924d4..67b584b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu.h enum amdgpu_kiq_irq { · line 219

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
@@ -210,6 +210,10 @@ enum amdgpu_kiq_irq {
  	AMDGPU_CP_KIQ_IRQ_LAST
  };
 
+#define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
+#define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
+#define MAX_KIQ_REG_TRY 20
+
  int amdgpu_device_ip_set_clockgating_state(void *dev,
  					   enum amd_ip_block_type block_type,
  					   enum amd_clockgating_state state);

diff --git

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

Quoted 21 lines

a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index 21adb1b6..3885636 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -3
@@ -22,9 +22,6 @@
   */
 
  #include "amdgpu.h"
-#define MAX_KIQ_REG_WAIT	5000 /* in usecs, 5ms */
-#define MAX_KIQ_REG_BAILOUT_INTERVAL	5 /* in msecs, 5ms */
-#define MAX_KIQ_REG_TRY 20
 
  uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev)
  {
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -0
index 76d979e..c9b3db4 100644
@@ -4348,8 +4348,21 @@ static void

gfx_v9_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -0
  						  uint32_t ref, uint32_t mask)
  {
  	int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
+	struct amdgpu_device *adev = ring->adev;
+	bool fw_version_ok = false;
 
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static void · line 4358

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +4 -1
-	if (amdgpu_sriov_vf(ring->adev))
+	if (ring->funcs->type == AMDGPU_RING_TYPE_GFX) {
+		if ((adev->gfx.me_fw_version >= 0x0000009c) && (adev-
 gfx.me_feature_version >= 42))
+			if ((adev->gfx.pfp_fw_version >=  0x000000b1) &&
+(adev->gfx.pfp_feature_version >= 42))

Why "if (...) if (...)" ? Just if (... && ...) should do as well.

Ok, will modify.

Quoted 25 lines

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t

Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +10 -0
+				fw_version_ok = true;
+	} else {
+		if ((adev->gfx.mec_fw_version >=  0x00000193) && (adev-
 gfx.mec_feature_version >= 42))
+			fw_version_ok = true;
+	}
+
+	fw_version_ok = (adev->asic_type == CHIP_VEGA10) ? fw_version_ok :
+false;
+
+	if (amdgpu_sriov_vf(adev) && fw_version_ok)
  		gfx_v9_0_wait_reg_mem(ring, usepfp, 0, 1, reg0, reg1,
  				      ref, mask, 0x20);
  	else
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
index ed467de..3419178 100644
@@ -311,6 +311,60 @@ static uint32_t

gmc_v9_0_get_invalidate_req(unsigned int vmid)

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
  	return req;
  }
 
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t · line 314

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
+signed long  amdgpu_kiq_invalidate_tlb(struct amdgpu_device *adev, struct

amdgpu_vmhub *hub,

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid) · line 315

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
+		unsigned eng, u32 req, uint32_t vmid)

Better make that function just a generic reg_write_reg_wait function, instead of specialized for tlb flushing.

Do you mean rename the function to amdgpu_reg_write_reg_wait?

Quoted 32 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +5 -0
+{
+	signed long r, cnt = 0;
+	unsigned long flags;
+	uint32_t seq;
+	struct amdgpu_kiq *kiq = &adev->gfx.kiq;

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +10 -0
+	struct amdgpu_ring *ring = &kiq->ring;
+
+	if (!ring->ready) {
+		return -EINVAL;
+	}
+
+	spin_lock_irqsave(&kiq->ring_lock, flags);
+
+	amdgpu_ring_alloc(ring, 32);
+	amdgpu_ring_emit_reg_write_reg_wait(ring, hub->vm_inv_eng0_req +

eng,

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +15 -0
+					    hub->vm_inv_eng0_ack + eng,
+					    req, 1 << vmid);
+	amdgpu_fence_emit_polling(ring, &seq);
+	amdgpu_ring_commit(ring);
+	spin_unlock_irqrestore(&kiq->ring_lock, flags);
+
+	r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
+
+	/* don't wait anymore for gpu reset case because this way may
+	 * block gpu_recover() routine forever, e.g. this virt_kiq_rreg
+	 * is triggered in TTM and ttm_bo_lock_delayed_workqueue() will
+	 * never return if we keep waiting in virt_kiq_rreg, which cause
+	 * gpu_recover() hang there.
+	 *
+	 * also don't wait anymore for IRQ context
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid) · line 351

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +6 -0
+	 * */
+	if (r < 1 && (adev->in_gpu_reset || in_interrupt()))
+		goto failed_kiq;
+
+	if (in_interrupt())
+		might_sleep();

What should that be good for?

It is only used for the interrupt case.

Quoted 29 lines

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid)

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +4 -0
+
+	while (r < 1 && cnt++ < MAX_KIQ_REG_TRY) {
+		msleep(MAX_KIQ_REG_BAILOUT_INTERVAL);
+		r = amdgpu_fence_wait_polling(ring, seq,

MAX_KIQ_REG_WAIT);

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_flush_gpu_tlb(struct

Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +12 -0
+	}
+
+	if (cnt > MAX_KIQ_REG_TRY)
+		goto failed_kiq;
+
+	return 0;
+
+failed_kiq:
+	pr_err("failed to invalidate tlb with kiq\n");
+	return r;
+}
+
  /*
   * GART
   * VMID 0 is the physical GPU addresses as used by the kernel.
@@ -332,6 +386,7 @@ static void gmc_v9_0_flush_gpu_tlb(struct

amdgpu_device *adev,

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
  	/* Use register 17 for GART */
  	const unsigned eng = 17;
  	unsigned i, j;
+	int r;
 
  	spin_lock(&adev->gmc.invalidate_lock);
 
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_flush_gpu_tlb(struct

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
@@ -339,6 +394,12 @@ static void gmc_v9_0_flush_gpu_tlb(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, · line 397

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
  		struct amdgpu_vmhub *hub = &adev->vmhub[i];
  		u32 tmp = gmc_v9_0_get_invalidate_req(vmid);
 
+		if (amdgpu_sriov_vf(adev) ) {

As discussed drop the sriov check here and use the KIQ path all the time.

Already drop it in the patch 2.

Best wishes
Emily Deng

Quoted 10 lines

Christian.

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_flush_gpu_tlb(struct · line 398

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
+			r = amdgpu_kiq_invalidate_tlb(adev, hub, eng, tmp,

vmid);

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +4 -0
+			if (!r)
+				continue;
+		}
+
  		WREG32_NO_KIQ(hub->vm_inv_eng0_req + eng, tmp);
 
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, · line 405

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
  		/* Busy wait for ACK.*/

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CY4PR12MB112541E31A354E9E94BE2FCF8F3F0-rpdhrqHFk07v2MZdTKcfDgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#9 lore raw

Am 15.08.2018 um 13:08 schrieb Deng, Emily:

Quoted 107 lines
Quoted 75 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Wednesday, August 15, 2018 6:50 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH 1/2] drm/amdgpu/sriov: For sriov runtime, use kiq to do invalidate tlb

Am 15.08.2018 um 11:48 schrieb Emily Deng:

Quoted 10 lines

To avoid the tlb flush not interrupted by world switch, use kiq and one command to do tlb invalidate.

v2:
Add firmware version checking.

v3:
Refine the code, and move the firmware checking into gfx_v9_0_ring_emit_reg_write_reg_wait.

Quoted 8 lines

SWDEV-161497

---
   drivers/gpu/drm/amd/amdgpu/amdgpu.h      |  4 +++
   drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c |  3 --
   drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 15 +++++++-
   drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    | 61

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

Quoted 8 lines
   4 files changed, 79 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index 07924d4..67b584b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu.h enum amdgpu_kiq_irq { · line 219

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
@@ -210,6 +210,10 @@ enum amdgpu_kiq_irq {
   	AMDGPU_CP_KIQ_IRQ_LAST
   };
 
+#define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
+#define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
+#define MAX_KIQ_REG_TRY 20
+
   int amdgpu_device_ip_set_clockgating_state(void *dev,
   					   enum amd_ip_block_type block_type,
   					   enum amd_clockgating_state state);

diff --git

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

Quoted 21 lines

a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index 21adb1b6..3885636 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -3
@@ -22,9 +22,6 @@
    */
 
   #include "amdgpu.h"
-#define MAX_KIQ_REG_WAIT	5000 /* in usecs, 5ms */
-#define MAX_KIQ_REG_BAILOUT_INTERVAL	5 /* in msecs, 5ms */
-#define MAX_KIQ_REG_TRY 20
 
   uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev)
   {
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -0
index 76d979e..c9b3db4 100644
@@ -4348,8 +4348,21 @@ static void

gfx_v9_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -0
   						  uint32_t ref, uint32_t mask)
   {
   	int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
+	struct amdgpu_device *adev = ring->adev;
+	bool fw_version_ok = false;
 
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static void · line 4358

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +4 -1
-	if (amdgpu_sriov_vf(ring->adev))
+	if (ring->funcs->type == AMDGPU_RING_TYPE_GFX) {
+		if ((adev->gfx.me_fw_version >= 0x0000009c) && (adev-
 gfx.me_feature_version >= 42))
+			if ((adev->gfx.pfp_fw_version >=  0x000000b1) &&
+(adev->gfx.pfp_feature_version >= 42))

Why "if (...) if (...)" ? Just if (... && ...) should do as well.

Ok, will modify.

Quoted 24 lines

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t

Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +10 -0
+				fw_version_ok = true;
+	} else {
+		if ((adev->gfx.mec_fw_version >=  0x00000193) && (adev-
 gfx.mec_feature_version >= 42))
+			fw_version_ok = true;
+	}
+
+	fw_version_ok = (adev->asic_type == CHIP_VEGA10) ? fw_version_ok :
+false;
+
+	if (amdgpu_sriov_vf(adev) && fw_version_ok)
   		gfx_v9_0_wait_reg_mem(ring, usepfp, 0, 1, reg0, reg1,
   				      ref, mask, 0x20);
   	else
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
index ed467de..3419178 100644
@@ -311,6 +311,60 @@ static uint32_t

gmc_v9_0_get_invalidate_req(unsigned int vmid)

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
   	return req;
   }
 
Quoted 6 lines
Quoted 5 lines

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t · line 314

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
+signed long  amdgpu_kiq_invalidate_tlb(struct amdgpu_device *adev, struct

amdgpu_vmhub *hub,

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid) · line 315

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
+		unsigned eng, u32 req, uint32_t vmid)

Better make that function just a generic reg_write_reg_wait function, instead of specialized for tlb flushing.

Do you mean rename the function to amdgpu_reg_write_reg_wait?

Yeah, something like that. I suggest amdgpu_kiq_reg_write_reg_wait() or otherwise you might run into a name clash.

Quoted 38 lines
Quoted 30 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +5 -0
+{
+	signed long r, cnt = 0;
+	unsigned long flags;
+	uint32_t seq;
+	struct amdgpu_kiq *kiq = &adev->gfx.kiq;

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +10 -0
+	struct amdgpu_ring *ring = &kiq->ring;
+
+	if (!ring->ready) {
+		return -EINVAL;
+	}
+
+	spin_lock_irqsave(&kiq->ring_lock, flags);
+
+	amdgpu_ring_alloc(ring, 32);
+	amdgpu_ring_emit_reg_write_reg_wait(ring, hub->vm_inv_eng0_req +

eng,

Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +14 -0
+					    hub->vm_inv_eng0_ack + eng,
+					    req, 1 << vmid);
+	amdgpu_fence_emit_polling(ring, &seq);
+	amdgpu_ring_commit(ring);
+	spin_unlock_irqrestore(&kiq->ring_lock, flags);
+
+	r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
+
+	/* don't wait anymore for gpu reset case because this way may
+	 * block gpu_recover() routine forever, e.g. this virt_kiq_rreg
+	 * is triggered in TTM and ttm_bo_lock_delayed_workqueue() will
+	 * never return if we keep waiting in virt_kiq_rreg, which cause
+	 * gpu_recover() hang there.
+	 *
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid) · line 351

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +7 -0
+	 * also don't wait anymore for IRQ context
+	 * */
+	if (r < 1 && (adev->in_gpu_reset || in_interrupt()))
+		goto failed_kiq;
+
+	if (in_interrupt())
+		might_sleep();

What should that be good for?

Quoted 1 line

It is only used for the interrupt case.

Well, might_sleep() is a debugging helper which bails out if called in a situation where you can't sleep.

Protecting that with "if (in_interrupt())" doesn't make any sense at all. So what exactly is your intention here?

Thanks,
Christian.

Quoted 34 lines
Quoted 34 lines

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid)

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +4 -0
+
+	while (r < 1 && cnt++ < MAX_KIQ_REG_TRY) {
+		msleep(MAX_KIQ_REG_BAILOUT_INTERVAL);
+		r = amdgpu_fence_wait_polling(ring, seq,

MAX_KIQ_REG_WAIT);

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_flush_gpu_tlb(struct

Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +12 -0
+	}
+
+	if (cnt > MAX_KIQ_REG_TRY)
+		goto failed_kiq;
+
+	return 0;
+
+failed_kiq:
+	pr_err("failed to invalidate tlb with kiq\n");
+	return r;
+}
+
   /*
    * GART
    * VMID 0 is the physical GPU addresses as used by the kernel.
@@ -332,6 +386,7 @@ static void gmc_v9_0_flush_gpu_tlb(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_flush_gpu_tlb(struct

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
   	/* Use register 17 for GART */
   	const unsigned eng = 17;
   	unsigned i, j;
+	int r;
 
   	spin_lock(&adev->gmc.invalidate_lock);
 
@@ -339,6 +394,12 @@ static void gmc_v9_0_flush_gpu_tlb(struct

amdgpu_device *adev,

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
   		struct amdgpu_vmhub *hub = &adev->vmhub[i];
   		u32 tmp = gmc_v9_0_get_invalidate_req(vmid);
 
Quoted 21 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, · line 397

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
+		if (amdgpu_sriov_vf(adev) ) {

As discussed drop the sriov check here and use the KIQ path all the time.

Already drop it in the patch 2.

Best wishes
Emily Deng

Quoted 15 lines

Christian.

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_flush_gpu_tlb(struct · line 398

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
+			r = amdgpu_kiq_invalidate_tlb(adev, hub, eng, tmp,

vmid);

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, · line 405

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +4 -0
+			if (!r)
+				continue;
+		}
+
   		WREG32_NO_KIQ(hub->vm_inv_eng0_req + eng, tmp);
 
   		/* Busy wait for ACK.*/

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 8a5bff61-c03f-856a-3f0e-3497b2bd0ba8-5C7GfCeVMHo@public.gmane.org

#11 lore raw
Quoted 165 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Wednesday, August 15, 2018 7:14 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH 1/2] drm/amdgpu/sriov: For sriov runtime, use kiq to do invalidate tlb

Am 15.08.2018 um 13:08 schrieb Deng, Emily:

Quoted 107 lines
Quoted 75 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Wednesday, August 15, 2018 6:50 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH 1/2] drm/amdgpu/sriov: For sriov runtime, use kiq to do invalidate tlb

Am 15.08.2018 um 11:48 schrieb Emily Deng:

Quoted 10 lines

To avoid the tlb flush not interrupted by world switch, use kiq and one command to do tlb invalidate.

v2:
Add firmware version checking.

v3:
Refine the code, and move the firmware checking into gfx_v9_0_ring_emit_reg_write_reg_wait.

Quoted 8 lines

SWDEV-161497

---
   drivers/gpu/drm/amd/amdgpu/amdgpu.h      |  4 +++
   drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c |  3 --
   drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 15 +++++++-
   drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    | 61

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

Quoted 8 lines
   4 files changed, 79 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index 07924d4..67b584b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu.h enum amdgpu_kiq_irq { · line 219

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
@@ -210,6 +210,10 @@ enum amdgpu_kiq_irq {
   	AMDGPU_CP_KIQ_IRQ_LAST
   };
 
+#define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
+#define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
+#define MAX_KIQ_REG_TRY 20
+
   int amdgpu_device_ip_set_clockgating_state(void *dev,
   					   enum amd_ip_block_type block_type,
   					   enum amd_clockgating_state state);

diff --git

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

Quoted 21 lines

a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index 21adb1b6..3885636 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -3
@@ -22,9 +22,6 @@
    */
 
   #include "amdgpu.h"
-#define MAX_KIQ_REG_WAIT	5000 /* in usecs, 5ms */
-#define MAX_KIQ_REG_BAILOUT_INTERVAL	5 /* in msecs, 5ms */
-#define MAX_KIQ_REG_TRY 20
 
   uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev)
   {
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -0
index 76d979e..c9b3db4 100644
@@ -4348,8 +4348,21 @@ static void

gfx_v9_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -0
   						  uint32_t ref, uint32_t mask)
   {
   	int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
+	struct amdgpu_device *adev = ring->adev;
+	bool fw_version_ok = false;
 
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static void · line 4358

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +4 -1
-	if (amdgpu_sriov_vf(ring->adev))
+	if (ring->funcs->type == AMDGPU_RING_TYPE_GFX) {
+		if ((adev->gfx.me_fw_version >= 0x0000009c) && (adev-
 gfx.me_feature_version >= 42))
+			if ((adev->gfx.pfp_fw_version >=  0x000000b1) &&
+(adev->gfx.pfp_feature_version >= 42))

Why "if (...) if (...)" ? Just if (... && ...) should do as well.

Ok, will modify.

Quoted 24 lines

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t

Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +10 -0
+				fw_version_ok = true;
+	} else {
+		if ((adev->gfx.mec_fw_version >=  0x00000193) && (adev-
 gfx.mec_feature_version >= 42))
+			fw_version_ok = true;
+	}
+
+	fw_version_ok = (adev->asic_type == CHIP_VEGA10) ? fw_version_ok :
+false;
+
+	if (amdgpu_sriov_vf(adev) && fw_version_ok)
   		gfx_v9_0_wait_reg_mem(ring, usepfp, 0, 1, reg0, reg1,
   				      ref, mask, 0x20);
   	else
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
index ed467de..3419178 100644
@@ -311,6 +311,60 @@ static uint32_t

gmc_v9_0_get_invalidate_req(unsigned int vmid)

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
   	return req;
   }
 
Quoted 7 lines
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t · line 315

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +2 -0
+signed long  amdgpu_kiq_invalidate_tlb(struct amdgpu_device *adev,
+struct

amdgpu_vmhub *hub,

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t · line 316

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
+		unsigned eng, u32 req, uint32_t vmid)

Better make that function just a generic reg_write_reg_wait function, instead of specialized for tlb flushing.

Do you mean rename the function to amdgpu_reg_write_reg_wait?

Yeah, something like that. I suggest amdgpu_kiq_reg_write_reg_wait() or otherwise you might run into a name clash.

Quoted 38 lines
Quoted 38 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +5 -0
+{
+	signed long r, cnt = 0;
+	unsigned long flags;
+	uint32_t seq;
+	struct amdgpu_kiq *kiq = &adev->gfx.kiq;

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t · line 331

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +10 -0
+	struct amdgpu_ring *ring = &kiq->ring;
+
+	if (!ring->ready) {
+		return -EINVAL;
+	}
+
+	spin_lock_irqsave(&kiq->ring_lock, flags);
+
+	amdgpu_ring_alloc(ring, 32);
+	amdgpu_ring_emit_reg_write_reg_wait(ring, hub->vm_inv_eng0_req +

eng,

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +11 -0
+					    hub->vm_inv_eng0_ack + eng,
+					    req, 1 << vmid);
+	amdgpu_fence_emit_polling(ring, &seq);
+	amdgpu_ring_commit(ring);
+	spin_unlock_irqrestore(&kiq->ring_lock, flags);
+
+	r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
+
+	/* don't wait anymore for gpu reset case because this way may
+	 * block gpu_recover() routine forever, e.g. this virt_kiq_rreg
+	 * is triggered in TTM and ttm_bo_lock_delayed_workqueue() will

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t · line 352

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +10 -0
+	 * never return if we keep waiting in virt_kiq_rreg, which cause
+	 * gpu_recover() hang there.
+	 *
+	 * also don't wait anymore for IRQ context
+	 * */
+	if (r < 1 && (adev->in_gpu_reset || in_interrupt()))
+		goto failed_kiq;
+
+	if (in_interrupt())
+		might_sleep();

What should that be good for?

Quoted 7 lines
Quoted 1 line

It is only used for the interrupt case.

Well, might_sleep() is a debugging helper which bails out if called in a situation where you can't sleep.

Protecting that with "if (in_interrupt())" doesn't make any sense at all. So what exactly is your intention here?

Understand, will remove in_interrupt().

Quoted 60 lines

Thanks,
Christian.

Quoted 34 lines
Quoted 34 lines

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint32_t · line 356

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +4 -0
+
+	while (r < 1 && cnt++ < MAX_KIQ_REG_TRY) {
+		msleep(MAX_KIQ_REG_BAILOUT_INTERVAL);
+		r = amdgpu_fence_wait_polling(ring, seq,

MAX_KIQ_REG_WAIT);

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_flush_gpu_tlb(struct

Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +12 -0
+	}
+
+	if (cnt > MAX_KIQ_REG_TRY)
+		goto failed_kiq;
+
+	return 0;
+
+failed_kiq:
+	pr_err("failed to invalidate tlb with kiq\n");
+	return r;
+}
+
   /*
    * GART
    * VMID 0 is the physical GPU addresses as used by the kernel.
@@ -332,6 +386,7 @@ static void gmc_v9_0_flush_gpu_tlb(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_flush_gpu_tlb(struct

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
   	/* Use register 17 for GART */
   	const unsigned eng = 17;
   	unsigned i, j;
+	int r;
 
   	spin_lock(&adev->gmc.invalidate_lock);
 
@@ -339,6 +394,12 @@ static void gmc_v9_0_flush_gpu_tlb(struct

amdgpu_device *adev,

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
   		struct amdgpu_vmhub *hub = &adev->vmhub[i];
   		u32 tmp = gmc_v9_0_get_invalidate_req(vmid);
 
Quoted 21 lines
Quoted 2 lines

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_flush_gpu_tlb(struct · line 397

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
+		if (amdgpu_sriov_vf(adev) ) {

As discussed drop the sriov check here and use the KIQ path all the time.

Already drop it in the patch 2.

Best wishes
Emily Deng

Quoted 15 lines

Christian.

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_flush_gpu_tlb(struct · line 398

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
+			r = amdgpu_kiq_invalidate_tlb(adev, hub, eng, tmp,

vmid);

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_flush_gpu_tlb(struct · line 405

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +4 -0
+			if (!r)
+				continue;
+		}
+
   		WREG32_NO_KIQ(hub->vm_inv_eng0_req + eng, tmp);
 
   		/* Busy wait for ACK.*/

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#12 lore raw
In reply to a message not in the archive
Quoted 14 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Emily Deng
Sent: Wednesday, August 15, 2018 5:48 PM
To: [email protected]
Cc: Deng, Emily <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu/sriov: For sriov runtime, use kiq to do invalidate tlb

To avoid the tlb flush not interrupted by world switch, use kiq and one command to do tlb invalidate.

Quoted 8 lines

v2:
Add firmware version checking.

v3:
Refine the code, and move the firmware checking into gfx_v9_0_ring_emit_reg_write_reg_wait.

SWDEV-161497

The "SWDEV-161497" is meanless.
you can describe the issue or just remove the bug number.

Quoted 64 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h      |  4 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c |  3 --
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 15 +++++++-
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    | 61
++++++++++++++++++++++++++++++++
 4 files changed, 79 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
index 07924d4..67b584b 100644
@@ -210,6 +210,10 @@ enum amdgpu_kiq_irq {
 	AMDGPU_CP_KIQ_IRQ_LAST
 };
 
+#define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
+#define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
+#define MAX_KIQ_REG_TRY 20
+
 int amdgpu_device_ip_set_clockgating_state(void *dev,
 					   enum amd_ip_block_type
 block_type,
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
 					   enum amd_clockgating_state state);
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -3
index 21adb1b6..3885636 100644
@@ -22,9 +22,6 @@
  */
 
 #include "amdgpu.h"
-#define MAX_KIQ_REG_WAIT	5000 /* in usecs, 5ms */
-#define MAX_KIQ_REG_BAILOUT_INTERVAL	5 /* in msecs, 5ms */
-#define MAX_KIQ_REG_TRY 20
 
 uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev)  { diff --git

a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
index 76d979e..c9b3db4 100644

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +8 -1
@@ -4348,8 +4348,21 @@ static void
 gfx_v9_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,
 						  uint32_t ref, uint32_t mask)
 {
 	int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
+	struct amdgpu_device *adev = ring->adev;
+	bool fw_version_ok = false;
 
-	if (amdgpu_sriov_vf(ring->adev))
+	if (ring->funcs->type == AMDGPU_RING_TYPE_GFX) {
+		if ((adev->gfx.me_fw_version >= 0x0000009c) && (adev-
 >gfx.me_feature_version >= 42))
+			if ((adev->gfx.pfp_fw_version >=  0x000000b1) &&
 (adev->gfx.pfp_feature_version >= 42))
+				fw_version_ok = true;
+	} else {
+		if ((adev->gfx.mec_fw_version >=  0x00000193) && (adev-
Quoted 1 line

gfx.mec_feature_version >= 42))

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -0
+			fw_version_ok = true;
+	}

Maybe we can add a flag and set the flag when request_firmware.

Quoted 101 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -0
+
+	fw_version_ok = (adev->asic_type == CHIP_VEGA10) ? fw_version_ok

:

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +3 -0
+false;
+
+	if (amdgpu_sriov_vf(adev) && fw_version_ok)
 		gfx_v9_0_wait_reg_mem(ring, usepfp, 0, 1, reg0, reg1,
 				      ref, mask, 0x20);
 	else
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +54 -0
index ed467de..3419178 100644
@@ -311,6 +311,60 @@ static uint32_t
 gmc_v9_0_get_invalidate_req(unsigned int vmid)
 	return req;
 }
 
+signed long  amdgpu_kiq_invalidate_tlb(struct amdgpu_device *adev, struct
 amdgpu_vmhub *hub,
+		unsigned eng, u32 req, uint32_t vmid) {
+	signed long r, cnt = 0;
+	unsigned long flags;
+	uint32_t seq;
+	struct amdgpu_kiq *kiq = &adev->gfx.kiq;
+	struct amdgpu_ring *ring = &kiq->ring;
+
+	if (!ring->ready) {
+		return -EINVAL;
+	}
+
+	spin_lock_irqsave(&kiq->ring_lock, flags);
+
+	amdgpu_ring_alloc(ring, 32);
+	amdgpu_ring_emit_reg_write_reg_wait(ring, hub->vm_inv_eng0_req
+ eng,
+					    hub->vm_inv_eng0_ack + eng,
+					    req, 1 << vmid);
+	amdgpu_fence_emit_polling(ring, &seq);
+	amdgpu_ring_commit(ring);
+	spin_unlock_irqrestore(&kiq->ring_lock, flags);
+
+	r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
+
+	/* don't wait anymore for gpu reset case because this way may
+	 * block gpu_recover() routine forever, e.g. this virt_kiq_rreg
+	 * is triggered in TTM and ttm_bo_lock_delayed_workqueue() will
+	 * never return if we keep waiting in virt_kiq_rreg, which cause
+	 * gpu_recover() hang there.
+	 *
+	 * also don't wait anymore for IRQ context
+	 * */
+	if (r < 1 && (adev->in_gpu_reset || in_interrupt()))
+		goto failed_kiq;
+
+	if (in_interrupt())
+		might_sleep();
+
+	while (r < 1 && cnt++ < MAX_KIQ_REG_TRY) {
+		msleep(MAX_KIQ_REG_BAILOUT_INTERVAL);
+		r = amdgpu_fence_wait_polling(ring, seq,
 MAX_KIQ_REG_WAIT);
+	}
+
+	if (cnt > MAX_KIQ_REG_TRY)
+		goto failed_kiq;
+
+	return 0;
+
+failed_kiq:
+	pr_err("failed to invalidate tlb with kiq\n");
+	return r;
+}
+

/*
* GART
* VMID 0 is the physical GPU addresses as used by the kernel.

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +7 -0
@@ -332,6 +386,7 @@ static void gmc_v9_0_flush_gpu_tlb(struct
 amdgpu_device *adev,
 	/* Use register 17 for GART */
 	const unsigned eng = 17;
 	unsigned i, j;
+	int r;
 
 	spin_lock(&adev->gmc.invalidate_lock);
@@ -339,6 +394,12 @@ static void gmc_v9_0_flush_gpu_tlb(struct
 amdgpu_device *adev,
 		struct amdgpu_vmhub *hub = &adev->vmhub[i];
 		u32 tmp = gmc_v9_0_get_invalidate_req(vmid);
 
+		if (amdgpu_sriov_vf(adev) ) {
+			r = amdgpu_kiq_invalidate_tlb(adev, hub, eng, tmp,
 vmid);
+			if (!r)
+				continue;
+		}
+
 		WREG32_NO_KIQ(hub->vm_inv_eng0_req + eng, tmp);
Quoted 8 lines

/* Busy wait for ACK.*/
--
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): BYAPR12MB27755A475CE994215D964F04FB3F0-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#14 lore raw
Quoted 90 lines · Rex
Quoted 15 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Emily Deng
Sent: Wednesday, August 15, 2018 5:48 PM
To: [email protected]
Cc: Deng, Emily <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu/sriov: For sriov runtime, use kiq to do invalidate tlb

To avoid the tlb flush not interrupted by world switch, use kiq and one command to do tlb invalidate.

Quoted 8 lines

v2:
Add firmware version checking.

v3:
Refine the code, and move the firmware checking into gfx_v9_0_ring_emit_reg_write_reg_wait.

SWDEV-161497

The "SWDEV-161497" is meanless.
you can describe the issue or just remove the bug number.

Quoted 63 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h      |  4 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c |  3 --
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 15 +++++++-
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    | 61
++++++++++++++++++++++++++++++++
 4 files changed, 79 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
index 07924d4..67b584b 100644
@@ -210,6 +210,10 @@ enum amdgpu_kiq_irq {
      AMDGPU_CP_KIQ_IRQ_LAST
 };
 
+#define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
+#define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
+#define MAX_KIQ_REG_TRY 20
+
 int amdgpu_device_ip_set_clockgating_state(void *dev,
                                         enum amd_ip_block_type
 block_type,
                                         enum amd_clockgating_state state);
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -3
index 21adb1b6..3885636 100644
@@ -22,9 +22,6 @@
  */
 
 #include "amdgpu.h"
-#define MAX_KIQ_REG_WAIT     5000 /* in usecs, 5ms */
-#define MAX_KIQ_REG_BAILOUT_INTERVAL 5 /* in msecs, 5ms */
-#define MAX_KIQ_REG_TRY 20
 
 uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev)  { diff --git

a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
index 76d979e..c9b3db4 100644

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +8 -1
@@ -4348,8 +4348,21 @@ static void
 gfx_v9_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,
                                                uint32_t ref, uint32_t mask)
 {
      int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
+     struct amdgpu_device *adev = ring->adev;
+     bool fw_version_ok = false;
 
-     if (amdgpu_sriov_vf(ring->adev))
+     if (ring->funcs->type == AMDGPU_RING_TYPE_GFX) {
+             if ((adev->gfx.me_fw_version >= 0x0000009c) && (adev-
 >gfx.me_feature_version >= 42))
+                     if ((adev->gfx.pfp_fw_version >=  0x000000b1) &&
 (adev->gfx.pfp_feature_version >= 42))
+                             fw_version_ok = true;
+     } else {
+             if ((adev->gfx.mec_fw_version >=  0x00000193) && (adev-
Quoted 5 lines

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c

Quoted 3 lines
Quoted 1 line

gfx.mec_feature_version >= 42))

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -0
+                     fw_version_ok = true;
+     }

Maybe we can add a flag and set the flag when request_firmware.

I was going to suggest the same thing.

Quoted 3 lines

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -0
+
+     fw_version_ok = (adev->asic_type == CHIP_VEGA10) ? fw_version_ok

Also is this specific to vega10 or do all gfx9 parts have this fix? Please verify.

Alex

Quoted 103 lines
Quoted 103 lines

:

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +3 -0
+false;
+
+     if (amdgpu_sriov_vf(adev) && fw_version_ok)
              gfx_v9_0_wait_reg_mem(ring, usepfp, 0, 1, reg0, reg1,
                                    ref, mask, 0x20);
      else
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +54 -0
index ed467de..3419178 100644
@@ -311,6 +311,60 @@ static uint32_t
 gmc_v9_0_get_invalidate_req(unsigned int vmid)
      return req;
 }
 
+signed long  amdgpu_kiq_invalidate_tlb(struct amdgpu_device *adev, struct
 amdgpu_vmhub *hub,
+             unsigned eng, u32 req, uint32_t vmid) {
+     signed long r, cnt = 0;
+     unsigned long flags;
+     uint32_t seq;
+     struct amdgpu_kiq *kiq = &adev->gfx.kiq;
+     struct amdgpu_ring *ring = &kiq->ring;
+
+     if (!ring->ready) {
+             return -EINVAL;
+     }
+
+     spin_lock_irqsave(&kiq->ring_lock, flags);
+
+     amdgpu_ring_alloc(ring, 32);
+     amdgpu_ring_emit_reg_write_reg_wait(ring, hub->vm_inv_eng0_req
+ eng,
+                                         hub->vm_inv_eng0_ack + eng,
+                                         req, 1 << vmid);
+     amdgpu_fence_emit_polling(ring, &seq);
+     amdgpu_ring_commit(ring);
+     spin_unlock_irqrestore(&kiq->ring_lock, flags);
+
+     r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
+
+     /* don't wait anymore for gpu reset case because this way may
+      * block gpu_recover() routine forever, e.g. this virt_kiq_rreg
+      * is triggered in TTM and ttm_bo_lock_delayed_workqueue() will
+      * never return if we keep waiting in virt_kiq_rreg, which cause
+      * gpu_recover() hang there.
+      *
+      * also don't wait anymore for IRQ context
+      * */
+     if (r < 1 && (adev->in_gpu_reset || in_interrupt()))
+             goto failed_kiq;
+
+     if (in_interrupt())
+             might_sleep();
+
+     while (r < 1 && cnt++ < MAX_KIQ_REG_TRY) {
+             msleep(MAX_KIQ_REG_BAILOUT_INTERVAL);
+             r = amdgpu_fence_wait_polling(ring, seq,
 MAX_KIQ_REG_WAIT);
+     }
+
+     if (cnt > MAX_KIQ_REG_TRY)
+             goto failed_kiq;
+
+     return 0;
+
+failed_kiq:
+     pr_err("failed to invalidate tlb with kiq\n");
+     return r;
+}
+

/*
* GART
* VMID 0 is the physical GPU addresses as used by the kernel.

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +7 -0
@@ -332,6 +386,7 @@ static void gmc_v9_0_flush_gpu_tlb(struct
 amdgpu_device *adev,
      /* Use register 17 for GART */
      const unsigned eng = 17;
      unsigned i, j;
+     int r;
 
      spin_lock(&adev->gmc.invalidate_lock);
@@ -339,6 +394,12 @@ static void gmc_v9_0_flush_gpu_tlb(struct
 amdgpu_device *adev,
              struct amdgpu_vmhub *hub = &adev->vmhub[i];
              u32 tmp = gmc_v9_0_get_invalidate_req(vmid);
 
+             if (amdgpu_sriov_vf(adev) ) {
+                     r = amdgpu_kiq_invalidate_tlb(adev, hub, eng, tmp,
 vmid);
+                     if (!r)
+                             continue;
+             }
+
              WREG32_NO_KIQ(hub->vm_inv_eng0_req + eng, tmp);
              /* Busy wait for ACK.*/

--
2.7.4

Quoted 8 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CADnq5_Pu4kxrjUK8e--EjLR55hE-eeb89KosZXajN-u3ZU2ZMA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#16 lore raw
Quoted 115 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, August 15, 2018 10:14 PM
To: Zhu, Rex <[email protected]>
Cc: Deng, Emily <[email protected]>; amd-gfx list <amd- [email protected]>
Subject: Re: [PATCH 1/2] drm/amdgpu/sriov: For sriov runtime, use kiq to do invalidate tlb

Quoted 62 lines · Rex
Quoted 15 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Emily Deng
Sent: Wednesday, August 15, 2018 5:48 PM
To: [email protected]
Cc: Deng, Emily <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu/sriov: For sriov runtime, use kiq to do invalidate tlb

To avoid the tlb flush not interrupted by world switch, use kiq and one command to do tlb invalidate.

Quoted 8 lines

v2:
Add firmware version checking.

v3:
Refine the code, and move the firmware checking into gfx_v9_0_ring_emit_reg_write_reg_wait.

SWDEV-161497

The "SWDEV-161497" is meanless.
you can describe the issue or just remove the bug number.

Quoted 35 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h      |  4 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c |  3 --
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 15 +++++++-
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    | 61
++++++++++++++++++++++++++++++++
 4 files changed, 79 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
index 07924d4..67b584b 100644
@@ -210,6 +210,10 @@ enum amdgpu_kiq_irq {
      AMDGPU_CP_KIQ_IRQ_LAST
 };
 
+#define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
+#define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
+#define MAX_KIQ_REG_TRY 20
+
 int amdgpu_device_ip_set_clockgating_state(void *dev,
                                         enum amd_ip_block_type
 block_type,

enum amd_clockgating_state
state); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index 21adb1b6..3885636 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -0
@@ -22,9 +22,6 @@
  */
 
Quoted 3 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -2
 #include "amdgpu.h"
-#define MAX_KIQ_REG_WAIT     5000 /* in usecs, 5ms */
-#define MAX_KIQ_REG_BAILOUT_INTERVAL 5 /* in msecs, 5ms */ -

#define

Quoted 27 lines
Quoted 27 lines

MAX_KIQ_REG_TRY 20

uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { diff --git
a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
index 76d979e..c9b3db4 100644

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +10 -1
@@ -4348,8 +4348,21 @@ static void
 gfx_v9_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,
                                                uint32_t ref,
 uint32_t mask)  {
      int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
+     struct amdgpu_device *adev = ring->adev;
+     bool fw_version_ok = false;
 
-     if (amdgpu_sriov_vf(ring->adev))
+     if (ring->funcs->type == AMDGPU_RING_TYPE_GFX) {
+             if ((adev->gfx.me_fw_version >= 0x0000009c) && (adev-
 >gfx.me_feature_version >= 42))
+                     if ((adev->gfx.pfp_fw_version >=  0x000000b1)
+ &&
 (adev->gfx.pfp_feature_version >= 42))
+                             fw_version_ok = true;
+     } else {
+             if ((adev->gfx.mec_fw_version >=  0x00000193) &&
+ (adev-
Quoted 5 lines

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c

Quoted 3 lines
Quoted 1 line

gfx.mec_feature_version >= 42))

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -0
+                     fw_version_ok = true;
+     }

Maybe we can add a flag and set the flag when request_firmware.

I was going to suggest the same thing.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +3 -0
+
+     fw_version_ok = (adev->asic_type == CHIP_VEGA10) ?
+ fw_version_ok

Also is this specific to vega10 or do all gfx9 parts have this fix? Please verify.

Alex

The patch can work on Raven.
Raven firmware version as :
MC feature version: 0, firmware version: 0x00000000 ME feature version: 42, firmware version: 0x0000009c PFP feature version: 42, firmware version: 0x000000b1 CE feature version: 42, firmware version: 0x0000004d MEC feature version: 42, firmware version: 0x00000192 MEC2 feature version: 42, firmware version: 0x00000192 VBIOS version: 113-RAVEN-110

Best Regards
Rex

Quoted 105 lines
Quoted 105 lines
Quoted 105 lines

:

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +3 -0
+false;
+
+     if (amdgpu_sriov_vf(adev) && fw_version_ok)
              gfx_v9_0_wait_reg_mem(ring, usepfp, 0, 1, reg0, reg1,
                                    ref, mask, 0x20);
      else
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +63 -1
index ed467de..3419178 100644
@@ -311,6 +311,60 @@ static uint32_t
 gmc_v9_0_get_invalidate_req(unsigned int vmid)
      return req;
 }
 
+signed long  amdgpu_kiq_invalidate_tlb(struct amdgpu_device *adev,
+struct
 amdgpu_vmhub *hub,
+             unsigned eng, u32 req, uint32_t vmid) {
+     signed long r, cnt = 0;
+     unsigned long flags;
+     uint32_t seq;
+     struct amdgpu_kiq *kiq = &adev->gfx.kiq;
+     struct amdgpu_ring *ring = &kiq->ring;
+
+     if (!ring->ready) {
+             return -EINVAL;
+     }
+
+     spin_lock_irqsave(&kiq->ring_lock, flags);
+
+     amdgpu_ring_alloc(ring, 32);
+     amdgpu_ring_emit_reg_write_reg_wait(ring, hub->vm_inv_eng0_req
+ eng,
+                                         hub->vm_inv_eng0_ack + eng,
+                                         req, 1 << vmid);
+     amdgpu_fence_emit_polling(ring, &seq);
+     amdgpu_ring_commit(ring);
+     spin_unlock_irqrestore(&kiq->ring_lock, flags);
+
+     r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
+
+     /* don't wait anymore for gpu reset case because this way may
+      * block gpu_recover() routine forever, e.g. this virt_kiq_rreg
+      * is triggered in TTM and ttm_bo_lock_delayed_workqueue() will
+      * never return if we keep waiting in virt_kiq_rreg, which cause
+      * gpu_recover() hang there.
+      *
+      * also don't wait anymore for IRQ context
+      * */
+     if (r < 1 && (adev->in_gpu_reset || in_interrupt()))
+             goto failed_kiq;
+
+     if (in_interrupt())
+             might_sleep();
+
+     while (r < 1 && cnt++ < MAX_KIQ_REG_TRY) {
+             msleep(MAX_KIQ_REG_BAILOUT_INTERVAL);
+             r = amdgpu_fence_wait_polling(ring, seq,
 MAX_KIQ_REG_WAIT);
+     }
+
+     if (cnt > MAX_KIQ_REG_TRY)
+             goto failed_kiq;
+
+     return 0;
+
+failed_kiq:
+     pr_err("failed to invalidate tlb with kiq\n");
+     return r;
+}
+
 /*
  * GART
  * VMID 0 is the physical GPU addresses as used by the kernel.
@@ -332,6 +386,7 @@ static void gmc_v9_0_flush_gpu_tlb(struct
 amdgpu_device *adev,
      /* Use register 17 for GART */
      const unsigned eng = 17;
      unsigned i, j;
+     int r;
 
      spin_lock(&adev->gmc.invalidate_lock);
@@ -339,6 +394,12 @@ static void gmc_v9_0_flush_gpu_tlb(struct
 amdgpu_device *adev,
              struct amdgpu_vmhub *hub = &adev->vmhub[i];
              u32 tmp = gmc_v9_0_get_invalidate_req(vmid);
 
+             if (amdgpu_sriov_vf(adev) ) {
+                     r = amdgpu_kiq_invalidate_tlb(adev, hub, eng,
+ tmp,
 vmid);
+                     if (!r)
+                             continue;
+             }
+
              WREG32_NO_KIQ(hub->vm_inv_eng0_req + eng, tmp);
 
              /* Busy wait for ACK.*/
--

2.7.4

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): BYAPR12MB27754BF4F6A7F1560D93DE01FB3E0-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#18 lore raw
Quoted 137 lines

-----Original Message-----
From: Zhu, Rex
Sent: Thursday, August 16, 2018 1:41 PM
To: 'Alex Deucher' <[email protected]>
Cc: Deng, Emily <[email protected]>; amd-gfx list <amd- [email protected]>
Subject: RE: [PATCH 1/2] drm/amdgpu/sriov: For sriov runtime, use kiq to do invalidate tlb

Quoted 115 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, August 15, 2018 10:14 PM
To: Zhu, Rex <[email protected]>
Cc: Deng, Emily <[email protected]>; amd-gfx list <amd- [email protected]>
Subject: Re: [PATCH 1/2] drm/amdgpu/sriov: For sriov runtime, use kiq to do invalidate tlb

Quoted 63 lines · Rex
Quoted 15 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Emily Deng
Sent: Wednesday, August 15, 2018 5:48 PM
To: [email protected]
Cc: Deng, Emily <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu/sriov: For sriov runtime, use kiq to do invalidate tlb

To avoid the tlb flush not interrupted by world switch, use kiq and one command to do tlb invalidate.

Quoted 8 lines

v2:
Add firmware version checking.

v3:
Refine the code, and move the firmware checking into gfx_v9_0_ring_emit_reg_write_reg_wait.

SWDEV-161497

The "SWDEV-161497" is meanless.
you can describe the issue or just remove the bug number.

Quoted 36 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h      |  4 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c |  3 --
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 15 +++++++-
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    | 61
++++++++++++++++++++++++++++++++
 4 files changed, 79 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
index 07924d4..67b584b 100644
@@ -210,6 +210,10 @@ enum amdgpu_kiq_irq {
      AMDGPU_CP_KIQ_IRQ_LAST
 };
 
+#define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
+#define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
+#define MAX_KIQ_REG_TRY 20
+
 int amdgpu_device_ip_set_clockgating_state(void *dev,
                                         enum amd_ip_block_type
 block_type,

enum
amd_clockgating_state state); diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index 21adb1b6..3885636 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -0
@@ -22,9 +22,6 @@
  */
 
Quoted 3 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c line 26

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -2
 #include "amdgpu.h"
-#define MAX_KIQ_REG_WAIT     5000 /* in usecs, 5ms */
-#define MAX_KIQ_REG_BAILOUT_INTERVAL 5 /* in msecs, 5ms */ -

#define

Quoted 28 lines
Quoted 28 lines

MAX_KIQ_REG_TRY 20

uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { diff
--git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
index 76d979e..c9b3db4 100644

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +11 -1
@@ -4348,8 +4348,21 @@ static void
 gfx_v9_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,
                                                uint32_t ref,
 uint32_t mask)  {
      int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
+     struct amdgpu_device *adev = ring->adev;
+     bool fw_version_ok = false;
 
-     if (amdgpu_sriov_vf(ring->adev))
+     if (ring->funcs->type == AMDGPU_RING_TYPE_GFX) {
+             if ((adev->gfx.me_fw_version >= 0x0000009c) &&
+ (adev-
 >gfx.me_feature_version >= 42))
+                     if ((adev->gfx.pfp_fw_version >=
+ 0x000000b1) &&
 (adev->gfx.pfp_feature_version >= 42))
+                             fw_version_ok = true;
+     } else {
+             if ((adev->gfx.mec_fw_version >=  0x00000193) &&
+ (adev-
Quoted 5 lines

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c

Quoted 3 lines
Quoted 1 line

gfx.mec_feature_version >= 42))

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -0
+                     fw_version_ok = true;
+     }

Maybe we can add a flag and set the flag when request_firmware.

I was going to suggest the same thing.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +3 -0
+
+     fw_version_ok = (adev->asic_type == CHIP_VEGA10) ?
+ fw_version_ok

Also is this specific to vega10 or do all gfx9 parts have this fix? Please verify.

Alex

Quoted 8 lines

The patch can work on Raven.
Raven firmware version as :
MC feature version: 0, firmware version: 0x00000000 ME feature version: 42, firmware version: 0x0000009c PFP feature version: 42, firmware version:
0x000000b1 CE feature version: 42, firmware version: 0x0000004d MEC feature version: 42, firmware version: 0x00000192
MEC2 feature version: 42, firmware version: 0x00000192 VBIOS version: 113- RAVEN-110

The patch can work on Vega12.
Firmware version on Vega12:
MC feature version: 0, firmware version: 0x00000000 ME feature version: 44, firmware version: 0x0000009c PFP feature version: 44, firmware version: 0x000000b2 CE feature version: 44, firmware version: 0x0000004d MEC feature version: 44, firmware version: 0x00000196 MEC2 feature version: 44, firmware version: 0x00000196 VBIOS version: 113-D2060300-016

Best Regards
Rex

Quoted 107 lines
Quoted 107 lines
Quoted 107 lines
Quoted 107 lines

:

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +3 -0
+false;
+
+     if (amdgpu_sriov_vf(adev) && fw_version_ok)
              gfx_v9_0_wait_reg_mem(ring, usepfp, 0, 1, reg0, reg1,
                                    ref, mask, 0x20);
      else
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +63 -1
index ed467de..3419178 100644
@@ -311,6 +311,60 @@ static uint32_t
 gmc_v9_0_get_invalidate_req(unsigned int vmid)
      return req;
 }
 
+signed long  amdgpu_kiq_invalidate_tlb(struct amdgpu_device
+*adev, struct
 amdgpu_vmhub *hub,
+             unsigned eng, u32 req, uint32_t vmid) {
+     signed long r, cnt = 0;
+     unsigned long flags;
+     uint32_t seq;
+     struct amdgpu_kiq *kiq = &adev->gfx.kiq;
+     struct amdgpu_ring *ring = &kiq->ring;
+
+     if (!ring->ready) {
+             return -EINVAL;
+     }
+
+     spin_lock_irqsave(&kiq->ring_lock, flags);
+
+     amdgpu_ring_alloc(ring, 32);
+     amdgpu_ring_emit_reg_write_reg_wait(ring,
+ hub->vm_inv_eng0_req eng,
+                                         hub->vm_inv_eng0_ack + eng,
+                                         req, 1 << vmid);
+     amdgpu_fence_emit_polling(ring, &seq);
+     amdgpu_ring_commit(ring);
+     spin_unlock_irqrestore(&kiq->ring_lock, flags);
+
+     r = amdgpu_fence_wait_polling(ring, seq, MAX_KIQ_REG_WAIT);
+
+     /* don't wait anymore for gpu reset case because this way may
+      * block gpu_recover() routine forever, e.g. this virt_kiq_rreg
+      * is triggered in TTM and ttm_bo_lock_delayed_workqueue() will
+      * never return if we keep waiting in virt_kiq_rreg, which cause
+      * gpu_recover() hang there.
+      *
+      * also don't wait anymore for IRQ context
+      * */
+     if (r < 1 && (adev->in_gpu_reset || in_interrupt()))
+             goto failed_kiq;
+
+     if (in_interrupt())
+             might_sleep();
+
+     while (r < 1 && cnt++ < MAX_KIQ_REG_TRY) {
+             msleep(MAX_KIQ_REG_BAILOUT_INTERVAL);
+             r = amdgpu_fence_wait_polling(ring, seq,
 MAX_KIQ_REG_WAIT);
+     }
+
+     if (cnt > MAX_KIQ_REG_TRY)
+             goto failed_kiq;
+
+     return 0;
+
+failed_kiq:
+     pr_err("failed to invalidate tlb with kiq\n");
+     return r;
+}
+
 /*
  * GART
  * VMID 0 is the physical GPU addresses as used by the kernel.
@@ -332,6 +386,7 @@ static void gmc_v9_0_flush_gpu_tlb(struct
 amdgpu_device *adev,
      /* Use register 17 for GART */
      const unsigned eng = 17;
      unsigned i, j;
+     int r;
 
      spin_lock(&adev->gmc.invalidate_lock);
@@ -339,6 +394,12 @@ static void gmc_v9_0_flush_gpu_tlb(struct
 amdgpu_device *adev,
              struct amdgpu_vmhub *hub = &adev->vmhub[i];
              u32 tmp = gmc_v9_0_get_invalidate_req(vmid);
 
+             if (amdgpu_sriov_vf(adev) ) {
+                     r = amdgpu_kiq_invalidate_tlb(adev, hub,
+ eng, tmp,
 vmid);
+                     if (!r)
+                             continue;
+             }
+
              WREG32_NO_KIQ(hub->vm_inv_eng0_req + eng, tmp);
 
              /* Busy wait for ACK.*/
--

2.7.4

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): BYAPR12MB2775F83981EF5557A7613128FB3E0-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#20 lore raw

Thanks all, I am modifying the patch, and testing.

Best wishes
Emily Deng

Quoted 167 lines

-----Original Message-----
From: Zhu, Rex
Sent: Thursday, August 16, 2018 2:25 PM
To: 'Alex Deucher' <[email protected]>
Cc: Deng, Emily <[email protected]>; 'amd-gfx list' <amd- [email protected]>
Subject: RE: [PATCH 1/2] drm/amdgpu/sriov: For sriov runtime, use kiq to do invalidate tlb

Quoted 133 lines

-----Original Message-----
From: Zhu, Rex
Sent: Thursday, August 16, 2018 1:41 PM
To: 'Alex Deucher' <[email protected]>
Cc: Deng, Emily <[email protected]>; amd-gfx list <amd- [email protected]>
Subject: RE: [PATCH 1/2] drm/amdgpu/sriov: For sriov runtime, use kiq to do invalidate tlb

Quoted 122 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, August 15, 2018 10:14 PM
To: Zhu, Rex <[email protected]>
Cc: Deng, Emily <[email protected]>; amd-gfx list <amd- [email protected]>
Subject: Re: [PATCH 1/2] drm/amdgpu/sriov: For sriov runtime, use kiq to do invalidate tlb

Quoted 63 lines · Rex
Quoted 15 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Emily Deng
Sent: Wednesday, August 15, 2018 5:48 PM
To: [email protected]
Cc: Deng, Emily <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu/sriov: For sriov runtime, use kiq to do invalidate tlb

To avoid the tlb flush not interrupted by world switch, use kiq and one command to do tlb invalidate.

Quoted 8 lines

v2:
Add firmware version checking.

v3:
Refine the code, and move the firmware checking into gfx_v9_0_ring_emit_reg_write_reg_wait.

SWDEV-161497

The "SWDEV-161497" is meanless.
you can describe the issue or just remove the bug number.

Quoted 36 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h      |  4 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c |  3 --
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 15 +++++++-
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    | 61
++++++++++++++++++++++++++++++++
 4 files changed, 79 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
index 07924d4..67b584b 100644
@@ -210,6 +210,10 @@ enum amdgpu_kiq_irq {
      AMDGPU_CP_KIQ_IRQ_LAST
 };
 
+#define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
+#define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
+#define MAX_KIQ_REG_TRY 20
+
 int amdgpu_device_ip_set_clockgating_state(void *dev,
                                         enum amd_ip_block_type
 block_type,

enum
amd_clockgating_state state); diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index 21adb1b6..3885636 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -0
@@ -22,9 +22,6 @@
  */
 
Quoted 3 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c line 26

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -2
 #include "amdgpu.h"
-#define MAX_KIQ_REG_WAIT     5000 /* in usecs, 5ms */
-#define MAX_KIQ_REG_BAILOUT_INTERVAL 5 /* in msecs, 5ms */ -

#define

Quoted 28 lines
Quoted 28 lines

MAX_KIQ_REG_TRY 20

uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev) { diff
--git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
index 76d979e..c9b3db4 100644

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +11 -1
@@ -4348,8 +4348,21 @@ static void
 gfx_v9_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,
                                                uint32_t ref,
 uint32_t mask)  {
      int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
+     struct amdgpu_device *adev = ring->adev;
+     bool fw_version_ok = false;
 
-     if (amdgpu_sriov_vf(ring->adev))
+     if (ring->funcs->type == AMDGPU_RING_TYPE_GFX) {
+             if ((adev->gfx.me_fw_version >= 0x0000009c) &&
+ (adev-
 >gfx.me_feature_version >= 42))
+                     if ((adev->gfx.pfp_fw_version >=
+ 0x000000b1) &&
 (adev->gfx.pfp_feature_version >= 42))
+                             fw_version_ok = true;
+     } else {
+             if ((adev->gfx.mec_fw_version >=  0x00000193) &&
+ (adev-
Quoted 5 lines

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c

Quoted 3 lines
Quoted 1 line

gfx.mec_feature_version >= 42))

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -0
+                     fw_version_ok = true;
+     }

Maybe we can add a flag and set the flag when request_firmware.

I was going to suggest the same thing.

Quoted 4 lines

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +3 -0
+
+     fw_version_ok = (adev->asic_type == CHIP_VEGA10) ?
+ fw_version_ok

Also is this specific to vega10 or do all gfx9 parts have this fix? Please verify.

Quoted 6 lines
Quoted 1 line

Alex

The patch can work on Raven.
Raven firmware version as :
MC feature version: 0, firmware version: 0x00000000 ME feature
version: 42, firmware version: 0x0000009c PFP feature version: 42, firmware

version:

Quoted 5 lines

0x000000b1 CE feature version: 42, firmware version: 0x0000004d MEC feature version: 42, firmware version: 0x00000192
MEC2 feature version: 42, firmware version: 0x00000192 VBIOS version:
113-
RAVEN-110

The patch can work on Vega12.
Firmware version on Vega12:
MC feature version: 0, firmware version: 0x00000000 ME feature version: 44, firmware version: 0x0000009c PFP feature version: 44, firmware version:
0x000000b2 CE feature version: 44, firmware version: 0x0000004d MEC feature
version: 44, firmware version: 0x00000196
MEC2 feature version: 44, firmware version: 0x00000196 VBIOS version: 113- D2060300-016

Quoted 118 lines

Best Regards
Rex

Quoted 116 lines
Quoted 116 lines
Quoted 116 lines
Quoted 108 lines

:

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +3 -0
+false;
+
+     if (amdgpu_sriov_vf(adev) && fw_version_ok)
              gfx_v9_0_wait_reg_mem(ring, usepfp, 0, 1, reg0, reg1,
                                    ref, mask, 0x20);
      else
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +64 -1
index ed467de..3419178 100644
@@ -311,6 +311,60 @@ static uint32_t
 gmc_v9_0_get_invalidate_req(unsigned int vmid)
      return req;
 }
 
+signed long  amdgpu_kiq_invalidate_tlb(struct amdgpu_device
+*adev, struct
 amdgpu_vmhub *hub,
+             unsigned eng, u32 req, uint32_t vmid) {
+     signed long r, cnt = 0;
+     unsigned long flags;
+     uint32_t seq;
+     struct amdgpu_kiq *kiq = &adev->gfx.kiq;
+     struct amdgpu_ring *ring = &kiq->ring;
+
+     if (!ring->ready) {
+             return -EINVAL;
+     }
+
+     spin_lock_irqsave(&kiq->ring_lock, flags);
+
+     amdgpu_ring_alloc(ring, 32);
+     amdgpu_ring_emit_reg_write_reg_wait(ring,
+ hub->vm_inv_eng0_req eng,
+                                         hub->vm_inv_eng0_ack + eng,
+                                         req, 1 << vmid);
+     amdgpu_fence_emit_polling(ring, &seq);
+     amdgpu_ring_commit(ring);
+     spin_unlock_irqrestore(&kiq->ring_lock, flags);
+
+     r = amdgpu_fence_wait_polling(ring, seq,
+ MAX_KIQ_REG_WAIT);
+
+     /* don't wait anymore for gpu reset case because this way may
+      * block gpu_recover() routine forever, e.g. this virt_kiq_rreg
+      * is triggered in TTM and ttm_bo_lock_delayed_workqueue() will
+      * never return if we keep waiting in virt_kiq_rreg, which cause
+      * gpu_recover() hang there.
+      *
+      * also don't wait anymore for IRQ context
+      * */
+     if (r < 1 && (adev->in_gpu_reset || in_interrupt()))
+             goto failed_kiq;
+
+     if (in_interrupt())
+             might_sleep();
+
+     while (r < 1 && cnt++ < MAX_KIQ_REG_TRY) {
+             msleep(MAX_KIQ_REG_BAILOUT_INTERVAL);
+             r = amdgpu_fence_wait_polling(ring, seq,
 MAX_KIQ_REG_WAIT);
+     }
+
+     if (cnt > MAX_KIQ_REG_TRY)
+             goto failed_kiq;
+
+     return 0;
+
+failed_kiq:
+     pr_err("failed to invalidate tlb with kiq\n");
+     return r;
+}
+
 /*
  * GART
  * VMID 0 is the physical GPU addresses as used by the kernel.
@@ -332,6 +386,7 @@ static void gmc_v9_0_flush_gpu_tlb(struct
 amdgpu_device *adev,
      /* Use register 17 for GART */
      const unsigned eng = 17;
      unsigned i, j;
+     int r;
 
      spin_lock(&adev->gmc.invalidate_lock);
@@ -339,6 +394,12 @@ static void gmc_v9_0_flush_gpu_tlb(struct
 amdgpu_device *adev,
              struct amdgpu_vmhub *hub = &adev->vmhub[i];
              u32 tmp = gmc_v9_0_get_invalidate_req(vmid);
 
+             if (amdgpu_sriov_vf(adev) ) {
+                     r = amdgpu_kiq_invalidate_tlb(adev, hub,
+ eng, tmp,
 vmid);
+                     if (!r)
+                             continue;
+             }
+
              WREG32_NO_KIQ(hub->vm_inv_eng0_req + eng, tmp);
 
              /* Busy wait for ACK.*/
--

2.7.4

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx