From: "Christian König" <christian.koenig-5C7GfCeVMHo@public.gmane.org>
To: Nikola Pajkovsky <npajkovsky-AlSwsSmVLrQ@public.gmane.org>,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: "Alex Deucher" <alexander.deucher-5C7GfCeVMHo@public.gmane.org>,
"David Airlie" <airlied-cv59FeDIM0c@public.gmane.org>,
amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
"Christian König" <christian.koenig-5C7GfCeVMHo@public.gmane.org>,
dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: Re: [RFC] drm/amd/amdgpu: get rid of else branch
Date: Fri, 28 Apr 2017 10:30:49 +0200 [thread overview]
Message-ID: <6ce3044b-9473-94eb-e54c-e8e856f1c88f@amd.com> (raw)
In-Reply-To: <c9e022e344770c861714615c6386d1821e2fa0a5.1493307341.git.npajkovsky-AlSwsSmVLrQ@public.gmane.org>
Am 27.04.2017 um 18:17 schrieb Nikola Pajkovsky:
> This is super simple elimination of else branch and I should
> probably even use unlikely in
>
> if (ring->count_dw < count_dw) {
>
> However, amdgpu_ring_write() has similar if condition, but does not
> return after DRM_ERROR and it looks suspicious. On error, we still
> adding v to ring and keeping count_dw-- below zero.
>
> if (ring->count_dw <= 0)
> DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
> ring->ring[ring->wptr++] = v;
> ring->wptr &= ring->ptr_mask;
> ring->count_dw--;
>
> I can obviously be totaly wrong. Hmm?
That's just choosing the lesser evil.
When we write more DW to the ring than expected it is possible (but not
likely) that we override stuff on the ring buffer which is still
executed by the command processor leading to a possible CP crash.
But when we completely drop the write the commands in the ring buffer
will certainly be invalid and so the CP will certainly crash sooner or
later.
Please add the unlikely() as well and then send out the patch with a
signed-of-by line and I will be happy to push it into our upstream branch.
Regards,
Christian.
>
> --------8<--------8<--------8<--------8<--------8<--------8<--------8<--------8<--------8<
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index c1b913541739..c6f4f874ea68 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1596,28 +1596,29 @@ static inline void amdgpu_ring_write_multiple(struct amdgpu_ring *ring, void *sr
>
> if (ring->count_dw < count_dw) {
> DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
> - } else {
> - occupied = ring->wptr & ring->ptr_mask;
> - dst = (void *)&ring->ring[occupied];
> - chunk1 = ring->ptr_mask + 1 - occupied;
> - chunk1 = (chunk1 >= count_dw) ? count_dw: chunk1;
> - chunk2 = count_dw - chunk1;
> - chunk1 <<= 2;
> - chunk2 <<= 2;
> -
> - if (chunk1)
> - memcpy(dst, src, chunk1);
> -
> - if (chunk2) {
> - src += chunk1;
> - dst = (void *)ring->ring;
> - memcpy(dst, src, chunk2);
> - }
> -
> - ring->wptr += count_dw;
> - ring->wptr &= ring->ptr_mask;
> - ring->count_dw -= count_dw;
> + return;
> }
> +
> + occupied = ring->wptr & ring->ptr_mask;
> + dst = (void *)&ring->ring[occupied];
> + chunk1 = ring->ptr_mask + 1 - occupied;
> + chunk1 = (chunk1 >= count_dw) ? count_dw: chunk1;
> + chunk2 = count_dw - chunk1;
> + chunk1 <<= 2;
> + chunk2 <<= 2;
> +
> + if (chunk1)
> + memcpy(dst, src, chunk1);
> +
> + if (chunk2) {
> + src += chunk1;
> + dst = (void *)ring->ring;
> + memcpy(dst, src, chunk2);
> + }
> +
> + ring->wptr += count_dw;
> + ring->wptr &= ring->ptr_mask;
> + ring->count_dw -= count_dw;
> }
>
> static inline struct amdgpu_sdma_instance *
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
WARNING: multiple messages have this Message-ID (diff)
From: "Christian König" <christian.koenig@amd.com>
To: Nikola Pajkovsky <npajkovsky@suse.cz>, <linux-kernel@vger.kernel.org>
Cc: "Alex Deucher" <alexander.deucher@amd.com>,
"David Airlie" <airlied@linux.ie>,
dri-devel@lists.freedesktop.org,
"Christian König" <christian.koenig@amd.com>,
amd-gfx@lists.freedesktop.org
Subject: Re: [RFC] drm/amd/amdgpu: get rid of else branch
Date: Fri, 28 Apr 2017 10:30:49 +0200 [thread overview]
Message-ID: <6ce3044b-9473-94eb-e54c-e8e856f1c88f@amd.com> (raw)
In-Reply-To: <c9e022e344770c861714615c6386d1821e2fa0a5.1493307341.git.npajkovsky@suse.cz>
Am 27.04.2017 um 18:17 schrieb Nikola Pajkovsky:
> This is super simple elimination of else branch and I should
> probably even use unlikely in
>
> if (ring->count_dw < count_dw) {
>
> However, amdgpu_ring_write() has similar if condition, but does not
> return after DRM_ERROR and it looks suspicious. On error, we still
> adding v to ring and keeping count_dw-- below zero.
>
> if (ring->count_dw <= 0)
> DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
> ring->ring[ring->wptr++] = v;
> ring->wptr &= ring->ptr_mask;
> ring->count_dw--;
>
> I can obviously be totaly wrong. Hmm?
That's just choosing the lesser evil.
When we write more DW to the ring than expected it is possible (but not
likely) that we override stuff on the ring buffer which is still
executed by the command processor leading to a possible CP crash.
But when we completely drop the write the commands in the ring buffer
will certainly be invalid and so the CP will certainly crash sooner or
later.
Please add the unlikely() as well and then send out the patch with a
signed-of-by line and I will be happy to push it into our upstream branch.
Regards,
Christian.
>
> --------8<--------8<--------8<--------8<--------8<--------8<--------8<--------8<--------8<
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index c1b913541739..c6f4f874ea68 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1596,28 +1596,29 @@ static inline void amdgpu_ring_write_multiple(struct amdgpu_ring *ring, void *sr
>
> if (ring->count_dw < count_dw) {
> DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
> - } else {
> - occupied = ring->wptr & ring->ptr_mask;
> - dst = (void *)&ring->ring[occupied];
> - chunk1 = ring->ptr_mask + 1 - occupied;
> - chunk1 = (chunk1 >= count_dw) ? count_dw: chunk1;
> - chunk2 = count_dw - chunk1;
> - chunk1 <<= 2;
> - chunk2 <<= 2;
> -
> - if (chunk1)
> - memcpy(dst, src, chunk1);
> -
> - if (chunk2) {
> - src += chunk1;
> - dst = (void *)ring->ring;
> - memcpy(dst, src, chunk2);
> - }
> -
> - ring->wptr += count_dw;
> - ring->wptr &= ring->ptr_mask;
> - ring->count_dw -= count_dw;
> + return;
> }
> +
> + occupied = ring->wptr & ring->ptr_mask;
> + dst = (void *)&ring->ring[occupied];
> + chunk1 = ring->ptr_mask + 1 - occupied;
> + chunk1 = (chunk1 >= count_dw) ? count_dw: chunk1;
> + chunk2 = count_dw - chunk1;
> + chunk1 <<= 2;
> + chunk2 <<= 2;
> +
> + if (chunk1)
> + memcpy(dst, src, chunk1);
> +
> + if (chunk2) {
> + src += chunk1;
> + dst = (void *)ring->ring;
> + memcpy(dst, src, chunk2);
> + }
> +
> + ring->wptr += count_dw;
> + ring->wptr &= ring->ptr_mask;
> + ring->count_dw -= count_dw;
> }
>
> static inline struct amdgpu_sdma_instance *
next prev parent reply other threads:[~2017-04-28 8:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-27 16:17 [RFC] drm/amd/amdgpu: get rid of else branch Nikola Pajkovsky
[not found] ` <c9e022e344770c861714615c6386d1821e2fa0a5.1493307341.git.npajkovsky-AlSwsSmVLrQ@public.gmane.org>
2017-04-28 8:30 ` Christian König [this message]
2017-04-28 8:30 ` Christian König
2017-05-04 12:57 ` Nikola Pajkovsky
2017-05-04 12:57 ` Nikola Pajkovsky
2017-05-04 13:19 ` Christian König
2017-05-04 13:19 ` Christian König
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=6ce3044b-9473-94eb-e54c-e8e856f1c88f@amd.com \
--to=christian.koenig-5c7gfcevmho@public.gmane.org \
--cc=airlied-cv59FeDIM0c@public.gmane.org \
--cc=alexander.deucher-5C7GfCeVMHo@public.gmane.org \
--cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=npajkovsky-AlSwsSmVLrQ@public.gmane.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.