All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kuehling, Felix" <Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
To: "Zeng, Oak" <Oak.Zeng-5C7GfCeVMHo@public.gmane.org>,
	"amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org"
	<amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>
Cc: "Keely, Sean" <Sean.Keely-5C7GfCeVMHo@public.gmane.org>,
	"Koenig,
	Christian" <Christian.Koenig-5C7GfCeVMHo@public.gmane.org>
Subject: Re: [PATCH 8/8] drm/amdkfd: Use kfd fd to mmap mmio
Date: Fri, 24 May 2019 18:59:13 +0000	[thread overview]
Message-ID: <10b1e33c-221d-251f-d939-1df49a4ea192@amd.com> (raw)
In-Reply-To: <1558651263-3478-8-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>

Hi Oak,

I'm not sure why this is part of the GWS patch series. It's unrelated to 
GWS. Anyway, see one comment inline.

On 2019-05-23 6:41 p.m., Zeng, Oak wrote:
> TTM doesn't support CPU mapping of sg type bo (under which
> mmio bo is created). Switch mmaping of mmio page to kfd
> device file.
>
> Change-Id: I1a1a24f2ac0662be3783d460c137731ade007b83
> Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
> ---
>   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 46 ++++++++++++++++++++++++++++++++
>   drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  1 +
>   2 files changed, 47 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> index 455a3db..67d269b 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> @@ -1309,6 +1309,15 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep,
>   	args->handle = MAKE_HANDLE(args->gpu_id, idr_handle);
>   	args->mmap_offset = offset;
>   
> +	/* MMIO is mapped through kfd device
> +	 * Generate a kfd mmap offset
> +	 */
> +	if (flags & KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP) {
> +		args->mmap_offset = KFD_MMAP_TYPE_MMIO | KFD_MMAP_GPU_ID(args->gpu_id);
> +		args->mmap_offset <<= PAGE_SHIFT;
> +		args->mmap_offset |= amdgpu_amdkfd_get_mmio_remap_phys_addr(dev->kgd);

It seems the mmio_remap_phys_addr doesn't need to be part of the 
mmap_offset. It's not used for anything in kfd_mmap. And it 
unnecessarily exposes a physical address to user mode, which we usually 
tend to avoid.

With that fixes, the patch is Reviewed-by: Felix Kuehling 
<Felix.Kuehling@amd.com>

Regards,
   Felix


> +	}
> +
>   	return 0;
>   
>   err_free:
> @@ -1880,6 +1889,39 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
>   	return retcode;
>   }
>   
> +static int kfd_mmio_mmap(struct kfd_dev *dev, struct kfd_process *process,
> +		      struct vm_area_struct *vma)
> +{
> +	phys_addr_t address;
> +	int ret;
> +
> +	if (vma->vm_end - vma->vm_start != PAGE_SIZE)
> +		return -EINVAL;
> +
> +	address = amdgpu_amdkfd_get_mmio_remap_phys_addr(dev->kgd);
> +
> +	vma->vm_flags |= VM_IO | VM_DONTCOPY | VM_DONTEXPAND | VM_NORESERVE |
> +				VM_DONTDUMP | VM_PFNMAP;
> +
> +	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
> +
> +	pr_debug("Process %d mapping mmio page\n"
> +		 "     target user address == 0x%08llX\n"
> +		 "     physical address    == 0x%08llX\n"
> +		 "     vm_flags            == 0x%04lX\n"
> +		 "     size                == 0x%04lX\n",
> +		 process->pasid, (unsigned long long) vma->vm_start,
> +		 address, vma->vm_flags, PAGE_SIZE);
> +
> +	ret = io_remap_pfn_range(vma,
> +				vma->vm_start,
> +				address >> PAGE_SHIFT,
> +				PAGE_SIZE,
> +				vma->vm_page_prot);
> +	return ret;
> +}
> +
> +
>   static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)
>   {
>   	struct kfd_process *process;
> @@ -1910,6 +1952,10 @@ static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)
>   		if (!dev)
>   			return -ENODEV;
>   		return kfd_reserved_mem_mmap(dev, process, vma);
> +	case KFD_MMAP_TYPE_MMIO:
> +		if (!dev)
> +			return -ENODEV;
> +		return kfd_mmio_mmap(dev, process, vma);
>   	}
>   
>   	return -EFAULT;
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> index 40a5c67..b61dc53 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> @@ -59,6 +59,7 @@
>   #define KFD_MMAP_TYPE_DOORBELL	(0x3ULL << KFD_MMAP_TYPE_SHIFT)
>   #define KFD_MMAP_TYPE_EVENTS	(0x2ULL << KFD_MMAP_TYPE_SHIFT)
>   #define KFD_MMAP_TYPE_RESERVED_MEM	(0x1ULL << KFD_MMAP_TYPE_SHIFT)
> +#define KFD_MMAP_TYPE_MMIO	(0x0ULL << KFD_MMAP_TYPE_SHIFT)
>   
>   #define KFD_MMAP_GPU_ID_SHIFT (46 - PAGE_SHIFT)
>   #define KFD_MMAP_GPU_ID_MASK (((1ULL << KFD_GPU_ID_HASH_WIDTH) - 1) \
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

      parent reply	other threads:[~2019-05-24 18:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-23 22:41 [PATCH 1/8] drm/amdkfd: Add gws number to kfd topology node properties Zeng, Oak
     [not found] ` <1558651263-3478-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
2019-05-23 22:41   ` [PATCH 2/8] drm/amdgpu: Add interface to alloc gws from amdgpu Zeng, Oak
2019-05-23 22:41   ` [PATCH 3/8] drm/amdkfd: Allocate gws on device initialization Zeng, Oak
2019-05-23 22:41   ` [PATCH 4/8] drm/amdgpu: Add function to add/remove gws to kfd process Zeng, Oak
2019-05-23 22:41   ` [PATCH 5/8] drm/amdkfd: Add function to set queue gws Zeng, Oak
     [not found]     ` <1558651263-3478-5-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
2019-05-24 19:47       ` Kuehling, Felix
2019-05-23 22:41   ` [PATCH 6/8] drm/amdkfd: New IOCTL to allocate queue GWS Zeng, Oak
     [not found]     ` <1558651263-3478-6-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
2019-05-24 19:48       ` Kuehling, Felix
     [not found]         ` <4f49af4d-0953-030c-bb1b-47b7a5fa7c7c-5C7GfCeVMHo@public.gmane.org>
2019-05-31  3:13           ` Dave Airlie
     [not found]             ` <CAPM=9tzs9adV7_ef4hpgswB-S==iQizAF_=FTarVm3EYwPCg0w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-05-31 20:04               ` Kuehling, Felix
     [not found]                 ` <e857f0f4-341d-1e64-0ffe-5b6812ca5b7f-5C7GfCeVMHo@public.gmane.org>
2019-05-31 20:53                   ` Dave Airlie
     [not found]                     ` <CAPM=9tzQB_SbCHcAcs3PRq-maed9XdMroROWNQuf9DdgOH5zcQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-05-31 21:18                       ` Kuehling, Felix
2019-05-23 22:41   ` [PATCH 7/8] drm/amdkfd: PM4 packets change to support GWS Zeng, Oak
2019-05-23 22:41   ` [PATCH 8/8] drm/amdkfd: Use kfd fd to mmap mmio Zeng, Oak
     [not found]     ` <1558651263-3478-8-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
2019-05-24  8:47       ` Christian König
2019-05-24 18:59       ` Kuehling, Felix [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=10b1e33c-221d-251f-d939-1df49a4ea192@amd.com \
    --to=felix.kuehling-5c7gfcevmho@public.gmane.org \
    --cc=Christian.Koenig-5C7GfCeVMHo@public.gmane.org \
    --cc=Oak.Zeng-5C7GfCeVMHo@public.gmane.org \
    --cc=Sean.Keely-5C7GfCeVMHo@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --subject='Re: [PATCH 8/8] drm/amdkfd: Use kfd fd to mmap mmio' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.