All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: "Chen Li" <chenli@uniontech.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v2 2/2] radeon: use memcpy_to/fromio for UVD fw upload
Date: Fri, 4 Jun 2021 09:18:26 +0200	[thread overview]
Message-ID: <0689a006-a0a2-698a-12d8-cb11156e469a@gmail.com> (raw)
In-Reply-To: <87im2ufhyz.wl-chenli@uniontech.com>



Am 04.06.21 um 05:04 schrieb Chen Li:
> I met a gpu addr bug recently and the kernel log
> tells me the pc is memcpy/memset and link register is
> radeon_uvd_resume.
>
> As we know, in some architectures, optimized memcpy/memset
> may not work well on device memory. Trival memcpy_toio/memset_io
> can fix this problem.
>
> BTW, amdgpu has already done it in:
> commit ba0b2275a678 ("drm/amdgpu: use memcpy_to/fromio for UVD fw upload"),
> that's why it has no this issue on the same gpu and platform.
>
> Signed-off-by: Chen Li <chenli@uniontech.com>
> ---
>   drivers/gpu/drm/radeon/radeon_uvd.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_uvd.c b/drivers/gpu/drm/radeon/radeon_uvd.c
> index 85a1f2c31749..0d6a5cfa2abf 100644
> --- a/drivers/gpu/drm/radeon/radeon_uvd.c
> +++ b/drivers/gpu/drm/radeon/radeon_uvd.c
> @@ -288,7 +288,9 @@ int radeon_uvd_resume(struct radeon_device *rdev)
>   	if (rdev->uvd.vcpu_bo == NULL)
>   		return -EINVAL;
>   
> -	memcpy(rdev->uvd.cpu_addr, rdev->uvd_fw->data, rdev->uvd_fw->size);
> +	memcpy_toio((void __iomem *)rdev->uvd.cpu_addr,
> +				rdev->uvd_fw->data,
> +				le32_to_cpu((__force __le32)rdev->uvd_fw->size));

The le32_to_cpu and coding style looks wrong here. The uvd_fw->size is 
always in CPU byte order and is used as such.

And please keep in mind that architectures where memcpy() on MMIO 
doesn't work in the kernel usually doesn't work in userspace as well.

So this is actually now necessary a valid workaround.

Christian.

>   
>   	size = radeon_bo_size(rdev->uvd.vcpu_bo);
>   	size -= rdev->uvd_fw->size;
> @@ -296,7 +298,7 @@ int radeon_uvd_resume(struct radeon_device *rdev)
>   	ptr = rdev->uvd.cpu_addr;
>   	ptr += rdev->uvd_fw->size;
>   
> -	memset(ptr, 0, size);
> +	memset_io((void __iomem *)ptr, 0, size);
>   
>   	return 0;
>   }


WARNING: multiple messages have this Message-ID (diff)
From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: "Chen Li" <chenli@uniontech.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v2 2/2] radeon: use memcpy_to/fromio for UVD fw upload
Date: Fri, 4 Jun 2021 09:18:26 +0200	[thread overview]
Message-ID: <0689a006-a0a2-698a-12d8-cb11156e469a@gmail.com> (raw)
In-Reply-To: <87im2ufhyz.wl-chenli@uniontech.com>



Am 04.06.21 um 05:04 schrieb Chen Li:
> I met a gpu addr bug recently and the kernel log
> tells me the pc is memcpy/memset and link register is
> radeon_uvd_resume.
>
> As we know, in some architectures, optimized memcpy/memset
> may not work well on device memory. Trival memcpy_toio/memset_io
> can fix this problem.
>
> BTW, amdgpu has already done it in:
> commit ba0b2275a678 ("drm/amdgpu: use memcpy_to/fromio for UVD fw upload"),
> that's why it has no this issue on the same gpu and platform.
>
> Signed-off-by: Chen Li <chenli@uniontech.com>
> ---
>   drivers/gpu/drm/radeon/radeon_uvd.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_uvd.c b/drivers/gpu/drm/radeon/radeon_uvd.c
> index 85a1f2c31749..0d6a5cfa2abf 100644
> --- a/drivers/gpu/drm/radeon/radeon_uvd.c
> +++ b/drivers/gpu/drm/radeon/radeon_uvd.c
> @@ -288,7 +288,9 @@ int radeon_uvd_resume(struct radeon_device *rdev)
>   	if (rdev->uvd.vcpu_bo == NULL)
>   		return -EINVAL;
>   
> -	memcpy(rdev->uvd.cpu_addr, rdev->uvd_fw->data, rdev->uvd_fw->size);
> +	memcpy_toio((void __iomem *)rdev->uvd.cpu_addr,
> +				rdev->uvd_fw->data,
> +				le32_to_cpu((__force __le32)rdev->uvd_fw->size));

The le32_to_cpu and coding style looks wrong here. The uvd_fw->size is 
always in CPU byte order and is used as such.

And please keep in mind that architectures where memcpy() on MMIO 
doesn't work in the kernel usually doesn't work in userspace as well.

So this is actually now necessary a valid workaround.

Christian.

>   
>   	size = radeon_bo_size(rdev->uvd.vcpu_bo);
>   	size -= rdev->uvd_fw->size;
> @@ -296,7 +298,7 @@ int radeon_uvd_resume(struct radeon_device *rdev)
>   	ptr = rdev->uvd.cpu_addr;
>   	ptr += rdev->uvd_fw->size;
>   
> -	memset(ptr, 0, size);
> +	memset_io((void __iomem *)ptr, 0, size);
>   
>   	return 0;
>   }

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

  reply	other threads:[~2021-06-04  7:18 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-03  5:35 [PATCH] radeon: use memcpy_to/fromio for UVD fw upload Chen Li
2021-06-03  5:35 ` Chen Li
2021-06-03 19:21 ` Alex Deucher
2021-06-03 19:21   ` Alex Deucher
2021-06-04  3:00   ` [PATCH v2 0/2] " Chen Li
2021-06-04  3:00     ` Chen Li
2021-06-04  3:02 ` [PATCH v2 1/2] radeon: fix coding issues reported from sparse Chen Li
2021-06-04  3:02   ` Chen Li
2021-06-04  7:14   ` Christian König
2021-06-04  7:14     ` Christian König
2021-06-04  3:04 ` [PATCH v2 2/2] radeon: use memcpy_to/fromio for UVD fw upload Chen Li
2021-06-04  3:04   ` Chen Li
2021-06-04  7:18   ` Christian König [this message]
2021-06-04  7:18     ` Christian König
2021-06-04  7:50     ` [PATCH v3 0/2] " Chen Li
2021-06-04  7:50       ` Chen Li
2021-06-04  7:52     ` [PATCH v3 1/2] radeon: fix coding issues reported from sparse Chen Li
2021-06-04  7:52       ` Chen Li
2021-06-04  7:53     ` [PATCH v3 2/2] radeon: use memcpy_to/fromio for UVD fw upload Chen Li
2021-06-04  7:53       ` Chen Li
2021-06-04  8:08       ` Christian König
2021-06-04  8:08         ` Christian König
2021-06-04  8:28         ` Chen Li
2021-06-04  8:28           ` Chen Li
2021-06-04  8:31           ` Christian König
2021-06-04  8:31             ` Christian König
2021-06-04  8:37             ` Chen Li
2021-06-04  8:37               ` Chen Li
2021-06-04  8:38         ` [PATCH v4 0/2] " Chen Li
2021-06-04  8:38           ` Chen Li
2021-06-04  8:40         ` [PATCH v4 1/2] radeon: fix coding issues reported from sparse Chen Li
2021-06-04  8:40           ` Chen Li
2021-06-04 17:19           ` Alex Deucher
2021-06-04 17:19             ` Alex Deucher
2021-06-04  8:43         ` [PATCH v4 2/2] radeon: use memcpy_to/fromio for UVD fw upload Chen Li
2021-06-04  8:43           ` Chen Li
2021-06-04  8:47           ` Christian König
2021-06-04  8:47             ` Christian König
2021-06-04 17:21           ` Alex Deucher
2021-06-04 17:21             ` Alex Deucher

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=0689a006-a0a2-698a-12d8-cb11156e469a@gmail.com \
    --to=ckoenig.leichtzumerken@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=chenli@uniontech.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.