RE: [PATCH V2] drm/amdgpu: Fix module unload hang by KIQ IRQ set

2017-02-19 Thread Yu, Xiangliang
Reviewed-by: Xiangliang Yu < xiangliang...@amd.com>

Thanks!
Xiangliang Yu

> -Original Message-
> From: Trigger Huang [mailto:trigger.hu...@amd.com]
> Sent: Monday, February 20, 2017 11:03 AM
> To: amd-gfx@lists.freedesktop.org
> Cc: Liu, Monk ; Yu, Xiangliang
> ; Huang, Trigger 
> Subject: [PATCH V2] drm/amdgpu: Fix module unload hang by KIQ IRQ set
> 
> In some cases, manually insmod/rmmod amdgpu is necessary. When
> unloading amdgpu, the KIQ IRQ enable/disable function will case system
> hang. The root cause is, in the sequence of function amdgpu_fini, the sw_fini
> of IP block AMD_IP_BLOCK_TYPE_GFX will be invoked earlier than that of
> AMD_IP_BLOCK_TYPE_IH. So continue to use the variable freed by
> AMD_IP_BLOCK_TYPE_GFX will cause system hang.
> 
> Changes in v2:
> -- Refine according to Xiangliang Yu's suggestions
> 
> Signed-off-by: Trigger Huang 
> ---
>  drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 10 --
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
> b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
> index 5a484ef..c417324 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
> @@ -1395,7 +1395,6 @@ static int gfx_v8_0_kiq_init_ring(struct
> amdgpu_device *adev,
>   ring->pipe = 1;
>   }
> 
> - irq->data = ring;
>   ring->queue = 0;
>   sprintf(ring->name, "kiq %d.%d.%d", ring->me, ring->pipe, ring-
> >queue);
>   r = amdgpu_ring_init(adev, ring, 1024, @@ -1410,7 +1409,6 @@ static
> void gfx_v8_0_kiq_free_ring(struct amdgpu_ring *ring,  {
>   amdgpu_wb_free(ring->adev, ring->adev->virt.reg_val_offs);
>   amdgpu_ring_fini(ring);
> - irq->data = NULL;
>  }
> 
>  #define MEC_HPD_SIZE 2048
> @@ -6931,9 +6929,9 @@ static int gfx_v8_0_kiq_set_interrupt_state(struct
> amdgpu_device *adev,
>   enum amdgpu_interrupt_state
> state)  {
>   uint32_t tmp, target;
> - struct amdgpu_ring *ring = (struct amdgpu_ring *)src->data;
> + struct amdgpu_ring *ring = &(adev->gfx.kiq.ring);
> 
> - BUG_ON(!ring || (ring->funcs->type != AMDGPU_RING_TYPE_KIQ));
> + BUG_ON(ring->funcs->type != AMDGPU_RING_TYPE_KIQ);
> 
>   if (ring->me == 1)
>   target = mmCP_ME1_PIPE0_INT_CNTL;
> @@ -6977,9 +6975,9 @@ static int gfx_v8_0_kiq_irq(struct amdgpu_device
> *adev,
>   struct amdgpu_iv_entry *entry)
>  {
>   u8 me_id, pipe_id, queue_id;
> - struct amdgpu_ring *ring = (struct amdgpu_ring *)source->data;
> + struct amdgpu_ring *ring = &(adev->gfx.kiq.ring);
> 
> - BUG_ON(!ring || (ring->funcs->type != AMDGPU_RING_TYPE_KIQ));
> + BUG_ON(ring->funcs->type != AMDGPU_RING_TYPE_KIQ);
> 
>   me_id = (entry->ring_id & 0x0c) >> 2;
>   pipe_id = (entry->ring_id & 0x03) >> 0;
> --
> 2.7.4

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 0/2] [libdrm] export gfx double offchip LDS buffers

2017-02-19 Thread Junwei Zhang

Junwei Zhang (2):
  amdgpu: export gfx double offchip LDS buffers by gpu info
  amdgpu/tests: show gfx config double offchip LDS buffers in gpu info

 amdgpu/amdgpu.h| 2 ++
 amdgpu/amdgpu_gpu_info.c   | 2 ++
 include/drm/amdgpu_drm.h   | 2 ++
 tests/amdgpu/basic_tests.c | 2 ++
 4 files changed, 8 insertions(+)

-- 
1.9.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH V2] drm/amdgpu: Fix module unload hang by KIQ IRQ set

2017-02-19 Thread Trigger Huang
In some cases, manually insmod/rmmod amdgpu is necessary. When
unloading amdgpu, the KIQ IRQ enable/disable function will case
system hang. The root cause is, in the sequence of function
amdgpu_fini, the sw_fini of IP block AMD_IP_BLOCK_TYPE_GFX will be
invoked earlier than that of AMD_IP_BLOCK_TYPE_IH. So continue to use
the variable freed by AMD_IP_BLOCK_TYPE_GFX will cause system hang.

Changes in v2:
-- Refine according to Xiangliang Yu's suggestions

Signed-off-by: Trigger Huang 
---
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index 5a484ef..c417324 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
@@ -1395,7 +1395,6 @@ static int gfx_v8_0_kiq_init_ring(struct amdgpu_device 
*adev,
ring->pipe = 1;
}
 
-   irq->data = ring;
ring->queue = 0;
sprintf(ring->name, "kiq %d.%d.%d", ring->me, ring->pipe, ring->queue);
r = amdgpu_ring_init(adev, ring, 1024,
@@ -1410,7 +1409,6 @@ static void gfx_v8_0_kiq_free_ring(struct amdgpu_ring 
*ring,
 {
amdgpu_wb_free(ring->adev, ring->adev->virt.reg_val_offs);
amdgpu_ring_fini(ring);
-   irq->data = NULL;
 }
 
 #define MEC_HPD_SIZE 2048
@@ -6931,9 +6929,9 @@ static int gfx_v8_0_kiq_set_interrupt_state(struct 
amdgpu_device *adev,
enum amdgpu_interrupt_state state)
 {
uint32_t tmp, target;
-   struct amdgpu_ring *ring = (struct amdgpu_ring *)src->data;
+   struct amdgpu_ring *ring = &(adev->gfx.kiq.ring);
 
-   BUG_ON(!ring || (ring->funcs->type != AMDGPU_RING_TYPE_KIQ));
+   BUG_ON(ring->funcs->type != AMDGPU_RING_TYPE_KIQ);
 
if (ring->me == 1)
target = mmCP_ME1_PIPE0_INT_CNTL;
@@ -6977,9 +6975,9 @@ static int gfx_v8_0_kiq_irq(struct amdgpu_device *adev,
struct amdgpu_iv_entry *entry)
 {
u8 me_id, pipe_id, queue_id;
-   struct amdgpu_ring *ring = (struct amdgpu_ring *)source->data;
+   struct amdgpu_ring *ring = &(adev->gfx.kiq.ring);
 
-   BUG_ON(!ring || (ring->funcs->type != AMDGPU_RING_TYPE_KIQ));
+   BUG_ON(ring->funcs->type != AMDGPU_RING_TYPE_KIQ);
 
me_id = (entry->ring_id & 0x0c) >> 2;
pipe_id = (entry->ring_id & 0x03) >> 0;
-- 
2.7.4

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 2/2] amdgpu/tests: show gfx config double offchip LDS buffers in gpu info

2017-02-19 Thread Junwei Zhang
Signed-off-by: Junwei Zhang 
---
 tests/amdgpu/basic_tests.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/amdgpu/basic_tests.c b/tests/amdgpu/basic_tests.c
index b5fd700..d930ad8 100644
--- a/tests/amdgpu/basic_tests.c
+++ b/tests/amdgpu/basic_tests.c
@@ -361,6 +361,8 @@ static void amdgpu_query_gpu_info_test()
amdgpu_vprintf("0x%x\n", gpu_info.vce_harvest_config);
amdgpu_vprintf("PCI revision ID:");
amdgpu_vprintf("0x%x\n", gpu_info.pci_rev_id);
+   amdgpu_vprintf("gfx config double offchip LDS buffers:");
+   amdgpu_vprintf("0x%x\n", gpu_info.gc_double_offchip_lds_buf);
 }
 
 static void amdgpu_query_firmware_info_test(void)
-- 
1.9.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 1/2] amdgpu: export gfx double offchip LDS buffers by gpu info

2017-02-19 Thread Junwei Zhang
Signed-off-by: Junwei Zhang 
---
 amdgpu/amdgpu.h  | 2 ++
 amdgpu/amdgpu_gpu_info.c | 2 ++
 include/drm/amdgpu_drm.h | 2 ++
 3 files changed, 6 insertions(+)

diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h
index 84ab688..7a26298 100644
--- a/amdgpu/amdgpu.h
+++ b/amdgpu/amdgpu.h
@@ -487,6 +487,8 @@ struct amdgpu_gpu_info {
uint32_t vce_harvest_config;
/* PCI revision ID */
uint32_t pci_rev_id;
+   /* gfx double offchip LDS buffers */
+   uint32_t gc_double_offchip_lds_buf;
 };
 
 
diff --git a/amdgpu/amdgpu_gpu_info.c b/amdgpu/amdgpu_gpu_info.c
index d801b86..984674e 100644
--- a/amdgpu/amdgpu_gpu_info.c
+++ b/amdgpu/amdgpu_gpu_info.c
@@ -175,6 +175,8 @@ drm_private int 
amdgpu_query_gpu_info_init(amdgpu_device_handle dev)
dev->info.ce_ram_size = dev->dev_info.ce_ram_size;
dev->info.vce_harvest_config = dev->dev_info.vce_harvest_config;
dev->info.pci_rev_id = dev->dev_info.pci_rev;
+   dev->info.gc_double_offchip_lds_buf =
+   dev->dev_info.gc_double_offchip_lds_buf;
 
for (i = 0; i < (int)dev->info.num_shader_engines; i++) {
unsigned instance = (i << AMDGPU_INFO_MMR_SE_INDEX_SHIFT) |
diff --git a/include/drm/amdgpu_drm.h b/include/drm/amdgpu_drm.h
index 9c3bd18..85bb701 100644
--- a/include/drm/amdgpu_drm.h
+++ b/include/drm/amdgpu_drm.h
@@ -767,6 +767,8 @@ struct drm_amdgpu_info_device {
uint32_t vram_bit_width;
/* vce harvesting instance */
uint32_t vce_harvest_config;
+   /* gfx double offchip LDS buffers */
+   uint32_t gc_double_offchip_lds_buf;
 };
 
 struct drm_amdgpu_info_hw_ip {
-- 
1.9.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH v3 1/1] drm/amdgpu: export gfx config double offchip LDS buffers (v3)

2017-02-19 Thread Junwei Zhang
v2: move the config struct to drm_amdgpu_info_device
v3: move the config feature to amdgpu_gca_config

Signed-off-by: Junwei Zhang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h |  3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  2 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c   |  6 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c   |  6 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c   | 16 +++-
 include/uapi/drm/amdgpu_drm.h   |  2 ++
 6 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 7f1421f..9c552a9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -856,6 +856,9 @@ struct amdgpu_gca_config {
uint32_t macrotile_mode_array[16];
 
struct amdgpu_rb_config 
rb_config[AMDGPU_GFX_MAX_SE][AMDGPU_GFX_MAX_SH_PER_SE];
+
+   /* gfx configure feature */
+   uint32_t double_offchip_lds_buf;
 };
 
 struct amdgpu_cu_info {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 6b9bf0e..bcc13907d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -545,6 +545,8 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void 
*data, struct drm_file
dev_info.vram_type = adev->mc.vram_type;
dev_info.vram_bit_width = adev->mc.vram_width;
dev_info.vce_harvest_config = adev->vce.harvest_config;
+   dev_info.gc_double_offchip_lds_buf =
+   adev->gfx.config.double_offchip_lds_buf;
 
return copy_to_user(out, _info,
min((size_t)size, sizeof(dev_info))) ? 
-EFAULT : 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
index 782190d..138e15a 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
@@ -1579,6 +1579,11 @@ static void gfx_v6_0_setup_spi(struct amdgpu_device 
*adev)
mutex_unlock(>grbm_idx_mutex);
 }
 
+static void gfx_v6_0_config_init(struct amdgpu_device *adev)
+{
+   adev->gfx.config.double_offchip_lds_buf = 1;
+}
+
 static void gfx_v6_0_gpu_init(struct amdgpu_device *adev)
 {
u32 gb_addr_config = 0;
@@ -1736,6 +1741,7 @@ static void gfx_v6_0_gpu_init(struct amdgpu_device *adev)
gfx_v6_0_setup_spi(adev);
 
gfx_v6_0_get_cu_info(adev);
+   gfx_v6_0_config_init(adev);
 
WREG32(mmCP_QUEUE_THRESHOLDS, ((0x16 << 
CP_QUEUE_THRESHOLDS__ROQ_IB1_START__SHIFT) |
   (0x2b << 
CP_QUEUE_THRESHOLDS__ROQ_IB2_START__SHIFT)));
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
index 8e07a50..6e7b273 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
@@ -1876,6 +1876,11 @@ static void gmc_v7_0_init_compute_vmid(struct 
amdgpu_device *adev)
mutex_unlock(>srbm_mutex);
 }
 
+static void gfx_v7_0_config_init(struct amdgpu_device *adev)
+{
+   adev->gfx.config.double_offchip_lds_buf = 1;
+}
+
 /**
  * gfx_v7_0_gpu_init - setup the 3D engine
  *
@@ -1900,6 +1905,7 @@ static void gfx_v7_0_gpu_init(struct amdgpu_device *adev)
 
gfx_v7_0_setup_rb(adev);
gfx_v7_0_get_cu_info(adev);
+   gfx_v7_0_config_init(adev);
 
/* set HW defaults for 3D engine */
WREG32(mmCP_MEQ_THRESHOLDS,
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index fdce3de..1533693 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
@@ -3846,6 +3846,19 @@ static void gfx_v8_0_init_compute_vmid(struct 
amdgpu_device *adev)
mutex_unlock(>srbm_mutex);
 }
 
+static void gfx_v8_0_config_init(struct amdgpu_device *adev)
+{
+   switch (adev->asic_type) {
+   default:
+   adev->gfx.config.double_offchip_lds_buf = 1;
+   break;
+   case CHIP_CARRIZO:
+   case CHIP_STONEY:
+   adev->gfx.config.double_offchip_lds_buf = 0;
+   break;
+   }
+}
+
 static void gfx_v8_0_gpu_init(struct amdgpu_device *adev)
 {
u32 tmp, sh_static_mem_cfg;
@@ -3859,6 +3872,7 @@ static void gfx_v8_0_gpu_init(struct amdgpu_device *adev)
gfx_v8_0_tiling_mode_table_init(adev);
gfx_v8_0_setup_rb(adev);
gfx_v8_0_get_cu_info(adev);
+   gfx_v8_0_config_init(adev);
 
/* XXX SH_MEM regs */
/* where to put LDS, scratch, GPUVM in FSA64 space */
@@ -7389,4 +7403,4 @@ static void gfx_v8_0_compute_mqd_soft_fini(struct 
amdgpu_device *adev)
 
ring = >gfx.kiq.ring;
amdgpu_bo_free_kernel(>mqd_obj, >mqd_gpu_addr, (void 
**)>mqd_ptr);
-}
\ No newline at end of file
+}
diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index 64abc9b..0849592 100644
--- 

RE: [PATCH v2 1/1] drm/amdgpu: export gfx config by gpu info (v2)

2017-02-19 Thread Zhang, Jerry
Hi Christian,

Good point.
I will update the patch.

Regards,
Jerry (Junwei Zhang)

Linux Base Graphics
SRDC Software Development
_


> -Original Message-
> From: Christian König [mailto:deathsim...@vodafone.de]
> Sent: Friday, February 17, 2017 18:13
> To: Zhang, Jerry; amd-gfx@lists.freedesktop.org
> Subject: Re: [PATCH v2 1/1] drm/amdgpu: export gfx config by gpu info (v2)
> 
> Am 17.02.2017 um 06:05 schrieb Junwei Zhang:
> > v2: move the config struct to drm_amdgpu_info_device
> >
> > Signed-off-by: Junwei Zhang 
> > ---
> >   drivers/gpu/drm/amd/amdgpu/amdgpu.h |  7 +++
> >   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  1 +
> >   drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c   |  6 ++
> >   drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c   |  6 ++
> >   drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c   | 16 +++-
> >   include/uapi/drm/amdgpu_drm.h   |  2 ++
> >   6 files changed, 37 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > index 7f1421f..9204545 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> > @@ -873,6 +873,10 @@ struct amdgpu_gfx_funcs {
> > void (*read_wave_sgprs)(struct amdgpu_device *adev, uint32_t simd,
> uint32_t wave, uint32_t start, uint32_t size, uint32_t *dst);
> >   };
> >
> > +struct amdgpu_gfx_config {
> > +   uint32_t double_offchip_lds_buf;
> > +};
> > +
> 
> Any specific reason why we can't add that to the existing amdgpu_gca_config
> structure?
> 
> Apart from that the patch looks good to me.
> 
> Regards,
> Christian.
> 
> >   struct amdgpu_gfx {
> > struct mutexgpu_clock_mutex;
> > struct amdgpu_gca_configconfig;
> > @@ -916,6 +920,9 @@ struct amdgpu_gfx {
> > uint32_tgrbm_soft_reset;
> > uint32_tsrbm_soft_reset;
> > boolin_reset;
> > +
> > +   /* gfx config */
> > +   struct amdgpu_gfx_configgc;
> >   };
> >
> >   int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> > index 6b9bf0e..922ae3e 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> > @@ -545,6 +545,7 @@ static int amdgpu_info_ioctl(struct drm_device *dev,
> void *data, struct drm_file
> > dev_info.vram_type = adev->mc.vram_type;
> > dev_info.vram_bit_width = adev->mc.vram_width;
> > dev_info.vce_harvest_config = adev->vce.harvest_config;
> > +   dev_info.gc_double_offchip_lds_buf =
> > +adev->gfx.gc.double_offchip_lds_buf;
> >
> > return copy_to_user(out, _info,
> > min((size_t)size, sizeof(dev_info))) ? 
> > -EFAULT :
> 0; diff
> > --git a/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
> > b/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
> > index 782190d..b758283 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
> > @@ -1579,6 +1579,11 @@ static void gfx_v6_0_setup_spi(struct
> amdgpu_device *adev)
> > mutex_unlock(>grbm_idx_mutex);
> >   }
> >
> > +static void gfx_v6_0_config_init(struct amdgpu_device *adev) {
> > +   adev->gfx.gc.double_offchip_lds_buf = 1; }
> > +
> >   static void gfx_v6_0_gpu_init(struct amdgpu_device *adev)
> >   {
> > u32 gb_addr_config = 0;
> > @@ -1736,6 +1741,7 @@ static void gfx_v6_0_gpu_init(struct amdgpu_device
> *adev)
> > gfx_v6_0_setup_spi(adev);
> >
> > gfx_v6_0_get_cu_info(adev);
> > +   gfx_v6_0_config_init(adev);
> >
> > WREG32(mmCP_QUEUE_THRESHOLDS, ((0x16 <<
> CP_QUEUE_THRESHOLDS__ROQ_IB1_START__SHIFT) |
> >(0x2b <<
> CP_QUEUE_THRESHOLDS__ROQ_IB2_START__SHIFT)));
> > diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
> > b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
> > index 8e07a50..f0f0512 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
> > @@ -1876,6 +1876,11 @@ static void gmc_v7_0_init_compute_vmid(struct
> amdgpu_device *adev)
> > mutex_unlock(>srbm_mutex);
> >   }
> >
> > +static void gfx_v7_0_config_init(struct amdgpu_device *adev) {
> > +   adev->gfx.gc.double_offchip_lds_buf = 1; }
> > +
> >   /**
> >* gfx_v7_0_gpu_init - setup the 3D engine
> >*
> > @@ -1900,6 +1905,7 @@ static void gfx_v7_0_gpu_init(struct
> > amdgpu_device *adev)
> >
> > gfx_v7_0_setup_rb(adev);
> > gfx_v7_0_get_cu_info(adev);
> > +   gfx_v7_0_config_init(adev);
> >
> > /* set HW defaults for 3D engine */
> > WREG32(mmCP_MEQ_THRESHOLDS,
> > diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
> > b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
> > index fdce3de..0b700b1 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
> > +++ 

Re: [PATCH] drm/ttm: fix use-after-free races in vm fault handling

2017-02-19 Thread Christian König

Am 18.02.2017 um 23:50 schrieb Nicolai Hähnle:

From: Nicolai Hähnle 

The vm fault handler relies on the fact that the VMA owns a reference
to the BO. However, once mmap_sem is released, other tasks are free to
destroy the VMA, which can lead to the BO being freed. Fix two code
paths where that can happen, both related to vm fault retries.

Found via a lock debugging warning which flagged >wu_mutex as
locked while being destroyed.

Fixes: cbe12e74ee4e ("drm/ttm: Allow vm fault retries")
Signed-off-by: Nicolai Hähnle 


Good catch! Patch is Reviewed-by: Christian König 


--
This does not fix the random memory corruption I've been seeing.
---
  drivers/gpu/drm/ttm/ttm_bo_vm.c | 12 
  1 file changed, 12 insertions(+)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index a6ed9d5..750733a 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -66,8 +66,11 @@ static int ttm_bo_vm_fault_idle(struct ttm_buffer_object *bo,
if (vmf->flags & FAULT_FLAG_RETRY_NOWAIT)
goto out_unlock;
  
+		ttm_bo_reference(bo);

up_read(>vm_mm->mmap_sem);
(void) fence_wait(bo->moving, true);
+   ttm_bo_unreserve(bo);
+   ttm_bo_unref();
goto out_unlock;
}
  
@@ -120,8 +123,10 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
  
  		if (vmf->flags & FAULT_FLAG_ALLOW_RETRY) {

if (!(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
+   ttm_bo_reference(bo);
up_read(>vm_mm->mmap_sem);
(void) ttm_bo_wait_unreserved(bo);
+   ttm_bo_unref();
}
  
  			return VM_FAULT_RETRY;

@@ -166,6 +171,13 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, 
struct vm_fault *vmf)
ret = ttm_bo_vm_fault_idle(bo, vma, vmf);
if (unlikely(ret != 0)) {
retval = ret;
+
+   if (retval == VM_FAULT_RETRY &&
+   !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
+   /* The BO has already been unreserved. */
+   return retval;
+   }
+
goto out_unlock;
}
  



___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx