Skip to contentSkip to conversation

drm/amdgpu:implement invalid tlbs with kiq

PATCH In review Monk Liu 3 participants 5 messages Dec 13, 2017 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Monk Liu

author
#0 lore raw

PATCH 1/2 drm/amdgpu:implement invalid tlbs with kiq

Implement gart flush gpu tlbs with INVALIDATE_TLBS package on gfx9/gmc9

Change-Id I851fb93db17e04d19959768c01ba6c677cbb777c
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h      | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 1 +
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 7 +++++++
 drivers/gpu/drm/amd/amdgpu/soc15d.h      | 6 +++++-
 4 files changed, 14 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 0cb2235..b3292cb 100644
@@ -1885,6 +1885,7 @@ amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
 #define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
 #define amdgpu_ring_emit_rreg(r, d) (r)->funcs->emit_rreg((r), (d))
 #define amdgpu_ring_emit_wreg(r, d, v) (r)->funcs->emit_wreg((r), (d), (v))
+#define amdgpu_ring_emit_invalidate_tlbs(r) (r)->funcs->emit_invalidate_tlbs((r))
 #define amdgpu_ring_emit_tmz(r, b) (r)->funcs->emit_tmz((r), (b))
 #define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
 #define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -0
index 010f690..6ad314e 100644
@@ -152,6 +152,7 @@ struct amdgpu_ring_funcs {
 	void (*emit_rreg)(struct amdgpu_ring *ring, uint32_t reg);
 	void (*emit_wreg)(struct amdgpu_ring *ring, uint32_t reg, uint32_t val);
 	void (*emit_tmz)(struct amdgpu_ring *ring, bool start);
+	void (*emit_invalidate_tlbs)(struct amdgpu_ring *ring);
 	/* priority functions */
 	void (*set_priority) (struct amdgpu_ring *ring,
 			      enum drm_sched_priority priority);
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +7 -0
index e9a668b..1a48a92 100644
@@ -3905,6 +3905,12 @@ static void gfx_v9_0_ring_emit_wreg(struct amdgpu_ring *ring, uint32_t reg,
 	amdgpu_ring_write(ring, val);
 }
 
+static void gfx_v9_ring_emit_invalidate_tlbs(struct amdgpu_ring *ring) {
+	amdgpu_ring_write(ring, PACKET3(PACKET3_INVALIDATE_TLBS, 0));
+	amdgpu_ring_write(ring, PACKET3_INVALIDATE_TLBS_DST_SEL(0) |
+							PACKET3_INVALIDATE_TLBS_ALL_HUB(1));
+}
+
 static void gfx_v9_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev,
 						 enum amdgpu_interrupt_state state)
 {
@@ -4280,6 +4286,7 @@ static const struct amdgpu_ring_funcs gfx_v9_0_ring_funcs_kiq = {
 	.pad_ib = amdgpu_ring_generic_pad_ib,
 	.emit_rreg = gfx_v9_0_ring_emit_rreg,
 	.emit_wreg = gfx_v9_0_ring_emit_wreg,
+	.emit_invalidate_tlbs = gfx_v9_ring_emit_invalidate_tlbs,
 };
 
 static void gfx_v9_0_set_ring_funcs(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/soc15d.h +5 -1
index 7f408f8..f0d0b91 100644
@@ -267,7 +267,11 @@
 			 * x=0: tmz_begin
 			 * x=1: tmz_end
 			 */
-
+#define	PACKET3_INVALIDATE_TLBS				0x98
+#              define PACKET3_INVALIDATE_TLBS_DST_SEL(x)     ((x) << 0)
+#              define PACKET3_INVALIDATE_TLBS_ALL_HUB(x)     ((x) << 4)
+#              define PACKET3_INVALIDATE_TLBS_PASID(x)       ((x) << 5)
+#              define PACKET3_INVALIDATE_TLBS_FLUSH_TYPE(x)  ((x) << 29)
 #define PACKET3_SET_RESOURCES				0xA0
 /* 1. header
  * 2. CONTROL
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): 1513136577-5343-1-git-send-email-Monk.Liu-5C7GfCeVMHo@public.gmane.org

author
#2 lore raw

PATCH 2/2 drm/amdgpu:impl virt_gart_flush_tlbs

a new gart flush tlb function implemented for SRIOV, and invoke it during RUNTIME for gart flush TLBs

this could avoid the issue that gart flush (via CPU MMIO) being interrupted by word switch which lead to DMAR error on Host/IOMMU side, with this function the gart flush tlbs always run on KIQ with single PM4 package so it won't get interrupted before the flushing finished.

Change-Id I0849658d7945c3874b3cc0d9369a50e1aedb8312
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 27 +++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h |  1 +
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    |  3 +++
 3 files changed, 31 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +27 -0
index e7dfb7b..7a6ef64 100644
@@ -172,6 +172,33 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)
 		DRM_ERROR("wait for kiq fence error: %ld\n", r);
 }
 
+int amdgpu_virt_gart_flush_tlbs(struct amdgpu_device *adev)
+{
+	struct amdgpu_kiq *kiq = &adev->gfx.kiq;
+	struct amdgpu_ring *ring = &kiq->ring;
+	unsigned long flags;
+	signed long r;
+	uint32_t seq;
+
+	if(!ring->funcs->emit_invalidate_tlbs)
+		return -ENOENT;
+
+	spin_lock_irqsave(&kiq->ring_lock, flags);
+	amdgpu_ring_alloc(ring, 16);
+	amdgpu_ring_emit_invalidate_tlbs(ring);
+	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);
+	if (r < 1) {
+		DRM_ERROR("wait for kiq invalidate tlbs error: %ld\n", r);
+		return -ETIME;
+	}
+
+	return 0;
+}
+
 /**
  * amdgpu_virt_request_full_gpu() - request full gpu access
  * @amdgpu:	amdgpu device.
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +1 -0
index 6a83425..935fed3 100644
@@ -297,5 +297,6 @@ int amdgpu_virt_fw_reserve_get_checksum(void *obj, unsigned long obj_size,
 					unsigned int key,
 					unsigned int chksum);
 void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev);
+int amdgpu_virt_gart_flush_tlbs(struct amdgpu_device *adev);
 
 #endif
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +3 -0
index 1b5dfcc..a195039 100644
@@ -332,6 +332,9 @@ static void gmc_v9_0_gart_flush_gpu_tlb(struct amdgpu_device *adev,
 	/* flush hdp cache */
 	adev->nbio_funcs->hdp_flush(adev);
 
+	if (amdgpu_sriov_runtime(adev) && !amdgpu_virt_gart_flush_tlbs(adev))
+		return;
+
 	spin_lock(&adev->mc.invalidate_lock);
 
 	for (i = 0; i < AMDGPU_MAX_VMHUBS; ++i) {
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): 1513136577-5343-2-git-send-email-Monk.Liu-5C7GfCeVMHo@public.gmane.org

#4 lore raw

Re: [PATCH 2/2] drm/amdgpu:impl virt_gart_flush_tlbs

Am 13.12.2017 um 04:42 schrieb Monk Liu:

Quoted 71 lines

a new gart flush tlb function implemented for SRIOV, and invoke it during RUNTIME for gart flush TLBs

this could avoid the issue that gart flush (via CPU MMIO) being interrupted by word switch which lead to DMAR error on Host/IOMMU side, with this function the gart flush tlbs always run on KIQ with single PM4 package so it won't get interrupted before the flushing finished.

Change-Id I0849658d7945c3874b3cc0d9369a50e1aedb8312
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 27 +++++++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h |  1 +
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    |  3 +++
  3 files changed, 31 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +27 -0
index e7dfb7b..7a6ef64 100644
@@ -172,6 +172,33 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)
  		DRM_ERROR("wait for kiq fence error: %ld\n", r);
  }
 
+int amdgpu_virt_gart_flush_tlbs(struct amdgpu_device *adev)
+{
+	struct amdgpu_kiq *kiq = &adev->gfx.kiq;
+	struct amdgpu_ring *ring = &kiq->ring;
+	unsigned long flags;
+	signed long r;
+	uint32_t seq;
+
+	if(!ring->funcs->emit_invalidate_tlbs)
+		return -ENOENT;
+
+	spin_lock_irqsave(&kiq->ring_lock, flags);
+	amdgpu_ring_alloc(ring, 16);
+	amdgpu_ring_emit_invalidate_tlbs(ring);
+	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);
+	if (r < 1) {
+		DRM_ERROR("wait for kiq invalidate tlbs error: %ld\n", r);
+		return -ETIME;
+	}
+
+	return 0;
+}
+
  /**
   * amdgpu_virt_request_full_gpu() - request full gpu access
   * @amdgpu:	amdgpu device.
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +1 -0
index 6a83425..935fed3 100644
@@ -297,5 +297,6 @@ int amdgpu_virt_fw_reserve_get_checksum(void *obj, unsigned long obj_size,
  					unsigned int key,
  					unsigned int chksum);
  void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev);
+int amdgpu_virt_gart_flush_tlbs(struct amdgpu_device *adev);
 
  #endif
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
index 1b5dfcc..a195039 100644

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

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +3 -0
@@ -332,6 +332,9 @@ static void gmc_v9_0_gart_flush_gpu_tlb(struct amdgpu_device *adev,
  	/* flush hdp cache */
  	adev->nbio_funcs->hdp_flush(adev);
 
+	if (amdgpu_sriov_runtime(adev) && !amdgpu_virt_gart_flush_tlbs(adev))
+		return;
+

Better open code that like this:

if (amdgpu_sriov_runtime(adev)) {
    /* Try using the KIQ */
    r = amdgpu_virt_gart_flush_tlbs(adev));
    if (!r)
        return;
}

Apart from that it looks good to me.

Christian.

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

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
  	spin_lock(&adev->mc.invalidate_lock);
 
  	for (i = 0; i < AMDGPU_MAX_VMHUBS; ++i) {

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

#5 lore raw

Re: [PATCH 2/2] drm/amdgpu:impl virt_gart_flush_tlbs

In reply to a message not in the archive
Quoted 71 lines · Monk Liu

a new gart flush tlb function implemented for SRIOV, and invoke it during RUNTIME for gart flush TLBs

this could avoid the issue that gart flush (via CPU MMIO) being interrupted by word switch which lead to DMAR error on Host/IOMMU side, with this function the gart flush tlbs always run on KIQ with single PM4 package so it won't get interrupted before the flushing finished.

Change-Id I0849658d7945c3874b3cc0d9369a50e1aedb8312
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 27 +++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h |  1 +
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    |  3 +++
 3 files changed, 31 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +27 -0
index e7dfb7b..7a6ef64 100644
@@ -172,6 +172,33 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)
                DRM_ERROR("wait for kiq fence error: %ld\n", r);
 }
 
+int amdgpu_virt_gart_flush_tlbs(struct amdgpu_device *adev)
+{
+       struct amdgpu_kiq *kiq = &adev->gfx.kiq;
+       struct amdgpu_ring *ring = &kiq->ring;
+       unsigned long flags;
+       signed long r;
+       uint32_t seq;
+
+       if(!ring->funcs->emit_invalidate_tlbs)
+               return -ENOENT;
+
+       spin_lock_irqsave(&kiq->ring_lock, flags);
+       amdgpu_ring_alloc(ring, 16);
+       amdgpu_ring_emit_invalidate_tlbs(ring);
+       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);
+       if (r < 1) {
+               DRM_ERROR("wait for kiq invalidate tlbs error: %ld\n", r);
+               return -ETIME;
+       }
+
+       return 0;
+}
+
 /**
  * amdgpu_virt_request_full_gpu() - request full gpu access
  * @amdgpu:    amdgpu device.
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +1 -0
index 6a83425..935fed3 100644
@@ -297,5 +297,6 @@ int amdgpu_virt_fw_reserve_get_checksum(void *obj, unsigned long obj_size,
                                        unsigned int key,
                                        unsigned int chksum);
 void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev);
+int amdgpu_virt_gart_flush_tlbs(struct amdgpu_device *adev);
 
 #endif
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
index 1b5dfcc..a195039 100644

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

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +2 -0
@@ -332,6 +332,9 @@ static void gmc_v9_0_gart_flush_gpu_tlb(struct amdgpu_device *adev,
        /* flush hdp cache */
        adev->nbio_funcs->hdp_flush(adev);
 
+       if (amdgpu_sriov_runtime(adev) && !amdgpu_virt_gart_flush_tlbs(adev))
+               return;

Do we need a fw version check for the flush_tlb packet?

Alex

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -1
+
        spin_lock(&adev->mc.invalidate_lock);
 
        for (i = 0; i < AMDGPU_MAX_VMHUBS; ++i) {
--

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

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

Am 13.12.2017 um 04:42 schrieb Monk Liu:

Quoted 29 lines

Implement gart flush gpu tlbs with INVALIDATE_TLBS package on gfx9/gmc9

Change-Id I851fb93db17e04d19959768c01ba6c677cbb777c
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h      | 1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 1 +
  drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 7 +++++++
  drivers/gpu/drm/amd/amdgpu/soc15d.h      | 6 +++++-
  4 files changed, 14 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 0cb2235..b3292cb 100644
@@ -1885,6 +1885,7 @@ amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
  #define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
  #define amdgpu_ring_emit_rreg(r, d) (r)->funcs->emit_rreg((r), (d))
  #define amdgpu_ring_emit_wreg(r, d, v) (r)->funcs->emit_wreg((r), (d), (v))
+#define amdgpu_ring_emit_invalidate_tlbs(r) (r)->funcs->emit_invalidate_tlbs((r))
  #define amdgpu_ring_emit_tmz(r, b) (r)->funcs->emit_tmz((r), (b))
  #define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
  #define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +0 -0
index 010f690..6ad314e 100644

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

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -0
@@ -152,6 +152,7 @@ struct amdgpu_ring_funcs {
  	void (*emit_rreg)(struct amdgpu_ring *ring, uint32_t reg);
  	void (*emit_wreg)(struct amdgpu_ring *ring, uint32_t reg, uint32_t val);
  	void (*emit_tmz)(struct amdgpu_ring *ring, bool start);
+	void (*emit_invalidate_tlbs)(struct amdgpu_ring *ring);

At some point we should probably superset amdgpu_ring_funcs with and amdgpu_kiq_funcs structure.

But that can come in a later patch as well.

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +0 -0
  	/* priority functions */
  	void (*set_priority) (struct amdgpu_ring *ring,
  			      enum drm_sched_priority priority);
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -0
index e9a668b..1a48a92 100644

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static void gfx_v9_0_ring_emit_wreg(struct amdgpu_ring *ring, uint32_t reg, · line 3911

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +4 -0
@@ -3905,6 +3905,12 @@ static void gfx_v9_0_ring_emit_wreg(struct amdgpu_ring *ring, uint32_t reg,
  	amdgpu_ring_write(ring, val);
  }
 
+static void gfx_v9_ring_emit_invalidate_tlbs(struct amdgpu_ring *ring) {
+	amdgpu_ring_write(ring, PACKET3(PACKET3_INVALIDATE_TLBS, 0));
+	amdgpu_ring_write(ring, PACKET3_INVALIDATE_TLBS_DST_SEL(0) |
+							PACKET3_INVALIDATE_TLBS_ALL_HUB(1));

That is once more way to far indented to the right.

With that fixed the patch is Reviewed-by: Christian König <[email protected]>

Christian.

Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +3 -0
+}
+
  static void gfx_v9_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev,
  						 enum amdgpu_interrupt_state state)
  {
@@ -4280,6 +4286,7 @@ static const struct amdgpu_ring_funcs gfx_v9_0_ring_funcs_kiq = {
  	.pad_ib = amdgpu_ring_generic_pad_ib,
  	.emit_rreg = gfx_v9_0_ring_emit_rreg,
  	.emit_wreg = gfx_v9_0_ring_emit_wreg,
+	.emit_invalidate_tlbs = gfx_v9_ring_emit_invalidate_tlbs,
  };
 
  static void gfx_v9_0_set_ring_funcs(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/soc15d.h +0 -0
index 7f408f8..f0d0b91 100644
@@ -267,7 +267,11 @@
  			 * x=0: tmz_begin
  			 * x=1: tmz_end

drivers/gpu/drm/amd/amdgpu/soc15d.h line 277

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/soc15d.h +5 -1
  			 */
-
+#define	PACKET3_INVALIDATE_TLBS				0x98
+#              define PACKET3_INVALIDATE_TLBS_DST_SEL(x)     ((x) << 0)
+#              define PACKET3_INVALIDATE_TLBS_ALL_HUB(x)     ((x) << 4)
+#              define PACKET3_INVALIDATE_TLBS_PASID(x)       ((x) << 5)
+#              define PACKET3_INVALIDATE_TLBS_FLUSH_TYPE(x)  ((x) << 29)
  #define PACKET3_SET_RESOURCES				0xA0
  /* 1. header
   * 2. CONTROL

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