Re: [PATCH 11/21] drm/amdkfd: Add GFXv9 MQD manager

2018-05-11 Thread Felix Kuehling
On 2018-05-11 03:06 PM, Oded Gabbay wrote:
> On Fri, May 11, 2018 at 9:15 PM, Felix Kuehling  
> wrote:
>> This patch series was meant to be applied after the userptr changes. I
>> haven't tested this without the userptr changes.
>>
>> I think your main concern about userptr is the use of GFP_NOIO. I
>> remember considering memalloc_noio_save/restore when I worked on this
>> over a year ago. I found an old email thread I had with Christian about
>> this (subject: MMU notifier deadlock on kernel 4.9):
>>
>>> memalloc_noio_save doesn't affect kmalloc directly. It sets
>>> current->flags, which is used deep inside the page allocator, after
>>> lockdep_trace_alloc(gfp) flags a lock as being used with IO enabled. The
>>> slob allocator looks at gfp_allowed_mask, but I'm not sure how safe it
>>> is to change that in a driver and it doesn't seem to be an exported
>>> symbol anyway.
>> Maybe this has changed in the mean time, but a year ago, using
>> memalloc_noio_save/restore may have prevented real deadlocks, but would
>> not shut up the lockdep warnings. Maybe this has changed in the mean
>> time. FWIW, I don't find lockdep_trace_alloc in the current kernel.
>>
>> Regards,
>>   Felix
> I'm not familiar with this API, but from reading about it, it seems a
> more robust solution then to change the GFP flags directly in each
> kmalloc from the reasons I mentioned in the original email I sent.

I agree.

> Having said that, if no one else objects and we say we will look at
> moving to that API in the future, I don't object to taking your
> patch-set as is now.

Yeah. I'll look into this.

Regards,
  Felix

>
> Oded
>
>>
>> On 2018-05-11 05:10 AM, Oded Gabbay wrote:
>>> On Wed, Apr 11, 2018 at 12:33 AM, Felix Kuehling  
>>> wrote:
 Signed-off-by: John Bridgman 
 Signed-off-by: Jay Cornwall 
 Signed-off-by: Felix Kuehling 
 ---
  drivers/gpu/drm/amd/amdkfd/Makefile |   1 +
  drivers/gpu/drm/amd/amdkfd/kfd_device.c |   2 +-
  drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c|   3 +
  drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c | 443 
 
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h   |   3 +
  5 files changed, 451 insertions(+), 1 deletion(-)
  create mode 100644 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c

 diff --git a/drivers/gpu/drm/amd/amdkfd/Makefile 
 b/drivers/gpu/drm/amd/amdkfd/Makefile
 index 52b3c1b..094b591 100644
 --- a/drivers/gpu/drm/amd/amdkfd/Makefile
 +++ b/drivers/gpu/drm/amd/amdkfd/Makefile
 @@ -30,6 +30,7 @@ amdkfd-y  := kfd_module.o kfd_device.o kfd_chardev.o 
 kfd_topology.o \
 kfd_pasid.o kfd_doorbell.o kfd_flat_memory.o \
 kfd_process.o kfd_queue.o kfd_mqd_manager.o \
 kfd_mqd_manager_cik.o kfd_mqd_manager_vi.o \
 +   kfd_mqd_manager_v9.o \
 kfd_kernel_queue.o kfd_kernel_queue_cik.o \
 kfd_kernel_queue_vi.o kfd_kernel_queue_v9.o \
 kfd_packet_manager.o kfd_process_queue_manager.o \
 diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c 
 b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
 index f563acb..c368ce3 100644
 --- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
 +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
 @@ -700,7 +700,7 @@ int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned 
 int size,
 if (size > kfd->gtt_sa_num_of_chunks * kfd->gtt_sa_chunk_size)
 return -ENOMEM;

 -   *mem_obj = kmalloc(sizeof(struct kfd_mem_obj), GFP_NOIO);
 +   *mem_obj = kzalloc(sizeof(struct kfd_mem_obj), GFP_NOIO);
>>> This assumes the patch in the userptr patch-set is applied. I changed
>>> it to GFP_KERNEL for now.
>>>
 if ((*mem_obj) == NULL)
 return -ENOMEM;

 diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c 
 b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
 index ee7061e..4b8eb50 100644
 --- a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
 +++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
 @@ -38,6 +38,9 @@ struct mqd_manager *mqd_manager_init(enum KFD_MQD_TYPE 
 type,
 case CHIP_POLARIS10:
 case CHIP_POLARIS11:
 return mqd_manager_init_vi_tonga(type, dev);
 +   case CHIP_VEGA10:
 +   case CHIP_RAVEN:
 +   return mqd_manager_init_v9(type, dev);
 default:
 WARN(1, "Unexpected ASIC family %u",
  dev->device_info->asic_family);
 diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c 
 b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
 new file mode 100644
 index 000..684054f
 --- /dev/null
 +++ 

Re: [PATCH 11/21] drm/amdkfd: Add GFXv9 MQD manager

2018-05-11 Thread Oded Gabbay
On Fri, May 11, 2018 at 9:15 PM, Felix Kuehling  wrote:
> This patch series was meant to be applied after the userptr changes. I
> haven't tested this without the userptr changes.
>
> I think your main concern about userptr is the use of GFP_NOIO. I
> remember considering memalloc_noio_save/restore when I worked on this
> over a year ago. I found an old email thread I had with Christian about
> this (subject: MMU notifier deadlock on kernel 4.9):
>
>> memalloc_noio_save doesn't affect kmalloc directly. It sets
>> current->flags, which is used deep inside the page allocator, after
>> lockdep_trace_alloc(gfp) flags a lock as being used with IO enabled. The
>> slob allocator looks at gfp_allowed_mask, but I'm not sure how safe it
>> is to change that in a driver and it doesn't seem to be an exported
>> symbol anyway.
> Maybe this has changed in the mean time, but a year ago, using
> memalloc_noio_save/restore may have prevented real deadlocks, but would
> not shut up the lockdep warnings. Maybe this has changed in the mean
> time. FWIW, I don't find lockdep_trace_alloc in the current kernel.
>
> Regards,
>   Felix

I'm not familiar with this API, but from reading about it, it seems a
more robust solution then to change the GFP flags directly in each
kmalloc from the reasons I mentioned in the original email I sent.
Having said that, if no one else objects and we say we will look at
moving to that API in the future, I don't object to taking your
patch-set as is now.

Oded

>
>
> On 2018-05-11 05:10 AM, Oded Gabbay wrote:
>> On Wed, Apr 11, 2018 at 12:33 AM, Felix Kuehling  
>> wrote:
>>> Signed-off-by: John Bridgman 
>>> Signed-off-by: Jay Cornwall 
>>> Signed-off-by: Felix Kuehling 
>>> ---
>>>  drivers/gpu/drm/amd/amdkfd/Makefile |   1 +
>>>  drivers/gpu/drm/amd/amdkfd/kfd_device.c |   2 +-
>>>  drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c|   3 +
>>>  drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c | 443 
>>> 
>>>  drivers/gpu/drm/amd/amdkfd/kfd_priv.h   |   3 +
>>>  5 files changed, 451 insertions(+), 1 deletion(-)
>>>  create mode 100644 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdkfd/Makefile 
>>> b/drivers/gpu/drm/amd/amdkfd/Makefile
>>> index 52b3c1b..094b591 100644
>>> --- a/drivers/gpu/drm/amd/amdkfd/Makefile
>>> +++ b/drivers/gpu/drm/amd/amdkfd/Makefile
>>> @@ -30,6 +30,7 @@ amdkfd-y  := kfd_module.o kfd_device.o kfd_chardev.o 
>>> kfd_topology.o \
>>> kfd_pasid.o kfd_doorbell.o kfd_flat_memory.o \
>>> kfd_process.o kfd_queue.o kfd_mqd_manager.o \
>>> kfd_mqd_manager_cik.o kfd_mqd_manager_vi.o \
>>> +   kfd_mqd_manager_v9.o \
>>> kfd_kernel_queue.o kfd_kernel_queue_cik.o \
>>> kfd_kernel_queue_vi.o kfd_kernel_queue_v9.o \
>>> kfd_packet_manager.o kfd_process_queue_manager.o \
>>> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c 
>>> b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
>>> index f563acb..c368ce3 100644
>>> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
>>> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
>>> @@ -700,7 +700,7 @@ int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned 
>>> int size,
>>> if (size > kfd->gtt_sa_num_of_chunks * kfd->gtt_sa_chunk_size)
>>> return -ENOMEM;
>>>
>>> -   *mem_obj = kmalloc(sizeof(struct kfd_mem_obj), GFP_NOIO);
>>> +   *mem_obj = kzalloc(sizeof(struct kfd_mem_obj), GFP_NOIO);
>> This assumes the patch in the userptr patch-set is applied. I changed
>> it to GFP_KERNEL for now.
>>
>>> if ((*mem_obj) == NULL)
>>> return -ENOMEM;
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c 
>>> b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
>>> index ee7061e..4b8eb50 100644
>>> --- a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
>>> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
>>> @@ -38,6 +38,9 @@ struct mqd_manager *mqd_manager_init(enum KFD_MQD_TYPE 
>>> type,
>>> case CHIP_POLARIS10:
>>> case CHIP_POLARIS11:
>>> return mqd_manager_init_vi_tonga(type, dev);
>>> +   case CHIP_VEGA10:
>>> +   case CHIP_RAVEN:
>>> +   return mqd_manager_init_v9(type, dev);
>>> default:
>>> WARN(1, "Unexpected ASIC family %u",
>>>  dev->device_info->asic_family);
>>> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c 
>>> b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
>>> new file mode 100644
>>> index 000..684054f
>>> --- /dev/null
>>> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
>>> @@ -0,0 +1,443 @@
>>> +/*
>>> + * Copyright 2016-2018 Advanced Micro Devices, Inc.
>>> + *
>>> + * Permission is hereby granted, free of charge, to any person obtaining a
>>> + * copy 

Re: [PATCH 11/21] drm/amdkfd: Add GFXv9 MQD manager

2018-05-11 Thread Felix Kuehling
This patch series was meant to be applied after the userptr changes. I
haven't tested this without the userptr changes.

I think your main concern about userptr is the use of GFP_NOIO. I
remember considering memalloc_noio_save/restore when I worked on this
over a year ago. I found an old email thread I had with Christian about
this (subject: MMU notifier deadlock on kernel 4.9):

> memalloc_noio_save doesn't affect kmalloc directly. It sets
> current->flags, which is used deep inside the page allocator, after
> lockdep_trace_alloc(gfp) flags a lock as being used with IO enabled. The
> slob allocator looks at gfp_allowed_mask, but I'm not sure how safe it
> is to change that in a driver and it doesn't seem to be an exported
> symbol anyway.
Maybe this has changed in the mean time, but a year ago, using
memalloc_noio_save/restore may have prevented real deadlocks, but would
not shut up the lockdep warnings. Maybe this has changed in the mean
time. FWIW, I don't find lockdep_trace_alloc in the current kernel.

Regards,
  Felix


On 2018-05-11 05:10 AM, Oded Gabbay wrote:
> On Wed, Apr 11, 2018 at 12:33 AM, Felix Kuehling  
> wrote:
>> Signed-off-by: John Bridgman 
>> Signed-off-by: Jay Cornwall 
>> Signed-off-by: Felix Kuehling 
>> ---
>>  drivers/gpu/drm/amd/amdkfd/Makefile |   1 +
>>  drivers/gpu/drm/amd/amdkfd/kfd_device.c |   2 +-
>>  drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c|   3 +
>>  drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c | 443 
>> 
>>  drivers/gpu/drm/amd/amdkfd/kfd_priv.h   |   3 +
>>  5 files changed, 451 insertions(+), 1 deletion(-)
>>  create mode 100644 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
>>
>> diff --git a/drivers/gpu/drm/amd/amdkfd/Makefile 
>> b/drivers/gpu/drm/amd/amdkfd/Makefile
>> index 52b3c1b..094b591 100644
>> --- a/drivers/gpu/drm/amd/amdkfd/Makefile
>> +++ b/drivers/gpu/drm/amd/amdkfd/Makefile
>> @@ -30,6 +30,7 @@ amdkfd-y  := kfd_module.o kfd_device.o kfd_chardev.o 
>> kfd_topology.o \
>> kfd_pasid.o kfd_doorbell.o kfd_flat_memory.o \
>> kfd_process.o kfd_queue.o kfd_mqd_manager.o \
>> kfd_mqd_manager_cik.o kfd_mqd_manager_vi.o \
>> +   kfd_mqd_manager_v9.o \
>> kfd_kernel_queue.o kfd_kernel_queue_cik.o \
>> kfd_kernel_queue_vi.o kfd_kernel_queue_v9.o \
>> kfd_packet_manager.o kfd_process_queue_manager.o \
>> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c 
>> b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
>> index f563acb..c368ce3 100644
>> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
>> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
>> @@ -700,7 +700,7 @@ int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned 
>> int size,
>> if (size > kfd->gtt_sa_num_of_chunks * kfd->gtt_sa_chunk_size)
>> return -ENOMEM;
>>
>> -   *mem_obj = kmalloc(sizeof(struct kfd_mem_obj), GFP_NOIO);
>> +   *mem_obj = kzalloc(sizeof(struct kfd_mem_obj), GFP_NOIO);
> This assumes the patch in the userptr patch-set is applied. I changed
> it to GFP_KERNEL for now.
>
>> if ((*mem_obj) == NULL)
>> return -ENOMEM;
>>
>> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c 
>> b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
>> index ee7061e..4b8eb50 100644
>> --- a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
>> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
>> @@ -38,6 +38,9 @@ struct mqd_manager *mqd_manager_init(enum KFD_MQD_TYPE 
>> type,
>> case CHIP_POLARIS10:
>> case CHIP_POLARIS11:
>> return mqd_manager_init_vi_tonga(type, dev);
>> +   case CHIP_VEGA10:
>> +   case CHIP_RAVEN:
>> +   return mqd_manager_init_v9(type, dev);
>> default:
>> WARN(1, "Unexpected ASIC family %u",
>>  dev->device_info->asic_family);
>> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c 
>> b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
>> new file mode 100644
>> index 000..684054f
>> --- /dev/null
>> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
>> @@ -0,0 +1,443 @@
>> +/*
>> + * Copyright 2016-2018 Advanced Micro Devices, Inc.
>> + *
>> + * Permission is hereby granted, free of charge, to any person obtaining a
>> + * copy of this software and associated documentation files (the 
>> "Software"),
>> + * to deal in the Software without restriction, including without limitation
>> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
>> + * and/or sell copies of the Software, and to permit persons to whom the
>> + * Software is furnished to do so, subject to the following conditions:
>> + *
>> + * The above copyright notice and this permission notice shall be included 
>> in
>> + * all copies or substantial portions of the Software.
>> + *
>> + * THE 

Re: [PATCH 11/21] drm/amdkfd: Add GFXv9 MQD manager

2018-05-11 Thread Oded Gabbay
On Wed, Apr 11, 2018 at 12:33 AM, Felix Kuehling  wrote:
> Signed-off-by: John Bridgman 
> Signed-off-by: Jay Cornwall 
> Signed-off-by: Felix Kuehling 
> ---
>  drivers/gpu/drm/amd/amdkfd/Makefile |   1 +
>  drivers/gpu/drm/amd/amdkfd/kfd_device.c |   2 +-
>  drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c|   3 +
>  drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c | 443 
> 
>  drivers/gpu/drm/amd/amdkfd/kfd_priv.h   |   3 +
>  5 files changed, 451 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/Makefile 
> b/drivers/gpu/drm/amd/amdkfd/Makefile
> index 52b3c1b..094b591 100644
> --- a/drivers/gpu/drm/amd/amdkfd/Makefile
> +++ b/drivers/gpu/drm/amd/amdkfd/Makefile
> @@ -30,6 +30,7 @@ amdkfd-y  := kfd_module.o kfd_device.o kfd_chardev.o 
> kfd_topology.o \
> kfd_pasid.o kfd_doorbell.o kfd_flat_memory.o \
> kfd_process.o kfd_queue.o kfd_mqd_manager.o \
> kfd_mqd_manager_cik.o kfd_mqd_manager_vi.o \
> +   kfd_mqd_manager_v9.o \
> kfd_kernel_queue.o kfd_kernel_queue_cik.o \
> kfd_kernel_queue_vi.o kfd_kernel_queue_v9.o \
> kfd_packet_manager.o kfd_process_queue_manager.o \
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c 
> b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> index f563acb..c368ce3 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> @@ -700,7 +700,7 @@ int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned int 
> size,
> if (size > kfd->gtt_sa_num_of_chunks * kfd->gtt_sa_chunk_size)
> return -ENOMEM;
>
> -   *mem_obj = kmalloc(sizeof(struct kfd_mem_obj), GFP_NOIO);
> +   *mem_obj = kzalloc(sizeof(struct kfd_mem_obj), GFP_NOIO);
This assumes the patch in the userptr patch-set is applied. I changed
it to GFP_KERNEL for now.

> if ((*mem_obj) == NULL)
> return -ENOMEM;
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c 
> b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
> index ee7061e..4b8eb50 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
> @@ -38,6 +38,9 @@ struct mqd_manager *mqd_manager_init(enum KFD_MQD_TYPE type,
> case CHIP_POLARIS10:
> case CHIP_POLARIS11:
> return mqd_manager_init_vi_tonga(type, dev);
> +   case CHIP_VEGA10:
> +   case CHIP_RAVEN:
> +   return mqd_manager_init_v9(type, dev);
> default:
> WARN(1, "Unexpected ASIC family %u",
>  dev->device_info->asic_family);
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c 
> b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
> new file mode 100644
> index 000..684054f
> --- /dev/null
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
> @@ -0,0 +1,443 @@
> +/*
> + * Copyright 2016-2018 Advanced Micro Devices, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + *
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include "kfd_priv.h"
> +#include "kfd_mqd_manager.h"
> +#include "v9_structs.h"
> +#include "gc/gc_9_0_offset.h"
> +#include "gc/gc_9_0_sh_mask.h"
> +#include "sdma0/sdma0_4_0_sh_mask.h"
> +
> +static inline struct v9_mqd *get_mqd(void *mqd)
> +{
> +   return (struct v9_mqd *)mqd;
> +}
> +
> +static inline struct v9_sdma_mqd *get_sdma_mqd(void *mqd)
> +{
> +   return (struct v9_sdma_mqd *)mqd;
> +}
> +
> +static int init_mqd(struct mqd_manager *mm, void **mqd,
> +   struct kfd_mem_obj **mqd_mem_obj, uint64_t *gart_addr,
> +   struct queue_properties *q)
> +{
> +   int 

[PATCH 11/21] drm/amdkfd: Add GFXv9 MQD manager

2018-04-10 Thread Felix Kuehling
Signed-off-by: John Bridgman 
Signed-off-by: Jay Cornwall 
Signed-off-by: Felix Kuehling 
---
 drivers/gpu/drm/amd/amdkfd/Makefile |   1 +
 drivers/gpu/drm/amd/amdkfd/kfd_device.c |   2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c|   3 +
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c | 443 
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h   |   3 +
 5 files changed, 451 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c

diff --git a/drivers/gpu/drm/amd/amdkfd/Makefile 
b/drivers/gpu/drm/amd/amdkfd/Makefile
index 52b3c1b..094b591 100644
--- a/drivers/gpu/drm/amd/amdkfd/Makefile
+++ b/drivers/gpu/drm/amd/amdkfd/Makefile
@@ -30,6 +30,7 @@ amdkfd-y  := kfd_module.o kfd_device.o kfd_chardev.o 
kfd_topology.o \
kfd_pasid.o kfd_doorbell.o kfd_flat_memory.o \
kfd_process.o kfd_queue.o kfd_mqd_manager.o \
kfd_mqd_manager_cik.o kfd_mqd_manager_vi.o \
+   kfd_mqd_manager_v9.o \
kfd_kernel_queue.o kfd_kernel_queue_cik.o \
kfd_kernel_queue_vi.o kfd_kernel_queue_v9.o \
kfd_packet_manager.o kfd_process_queue_manager.o \
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
index f563acb..c368ce3 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -700,7 +700,7 @@ int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned int 
size,
if (size > kfd->gtt_sa_num_of_chunks * kfd->gtt_sa_chunk_size)
return -ENOMEM;
 
-   *mem_obj = kmalloc(sizeof(struct kfd_mem_obj), GFP_NOIO);
+   *mem_obj = kzalloc(sizeof(struct kfd_mem_obj), GFP_NOIO);
if ((*mem_obj) == NULL)
return -ENOMEM;
 
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
index ee7061e..4b8eb50 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
@@ -38,6 +38,9 @@ struct mqd_manager *mqd_manager_init(enum KFD_MQD_TYPE type,
case CHIP_POLARIS10:
case CHIP_POLARIS11:
return mqd_manager_init_vi_tonga(type, dev);
+   case CHIP_VEGA10:
+   case CHIP_RAVEN:
+   return mqd_manager_init_v9(type, dev);
default:
WARN(1, "Unexpected ASIC family %u",
 dev->device_info->asic_family);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
new file mode 100644
index 000..684054f
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
@@ -0,0 +1,443 @@
+/*
+ * Copyright 2016-2018 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include "kfd_priv.h"
+#include "kfd_mqd_manager.h"
+#include "v9_structs.h"
+#include "gc/gc_9_0_offset.h"
+#include "gc/gc_9_0_sh_mask.h"
+#include "sdma0/sdma0_4_0_sh_mask.h"
+
+static inline struct v9_mqd *get_mqd(void *mqd)
+{
+   return (struct v9_mqd *)mqd;
+}
+
+static inline struct v9_sdma_mqd *get_sdma_mqd(void *mqd)
+{
+   return (struct v9_sdma_mqd *)mqd;
+}
+
+static int init_mqd(struct mqd_manager *mm, void **mqd,
+   struct kfd_mem_obj **mqd_mem_obj, uint64_t *gart_addr,
+   struct queue_properties *q)
+{
+   int retval;
+   uint64_t addr;
+   struct v9_mqd *m;
+   struct kfd_dev *kfd = mm->dev;
+
+   /* From V9,  for CWSR, the control stack is located on the next page
+* boundary after the mqd, we will use the gtt allocation function
+* instead of sub-allocation function.
+*/
+   if (kfd->cwsr_enabled && (q->type == KFD_QUEUE_TYPE_COMPUTE)) {
+