* [PATCH] drm/amd/amdgpu: Fix amdgpu_debugfs_gpr_read debugfs entry
@ 2018-04-09 12:16 Tom St Denis
[not found] ` <20180409121621.7514-1-tom.stdenis-5C7GfCeVMHo@public.gmane.org>
0 siblings, 1 reply; 6+ messages in thread
From: Tom St Denis @ 2018-04-09 12:16 UTC (permalink / raw)
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW; +Cc: Tom St Denis
We don't need to check the alignment of the offset and there was
potential a buffer overflow as well.
Signed-off-by: Tom St Denis <tom.stdenis@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
index c98e59721444..b1ea300008e5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
@@ -507,6 +507,9 @@ static ssize_t amdgpu_debugfs_wave_read(struct file *f, char __user *buf,
return result;
}
+// read at most 1024 words
+#define AMDGPU_DEBUGFS_MAX_SGPR_READ 1024
+
static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
size_t size, loff_t *pos)
{
@@ -515,7 +518,7 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
ssize_t result = 0;
uint32_t offset, se, sh, cu, wave, simd, thread, bank, *data;
- if (size & 3 || *pos & 3)
+ if (size & 3 || size > (4 * AMDGPU_DEBUGFS_MAX_SGPR_READ))
return -EINVAL;
/* decode offset */
@@ -528,7 +531,8 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
thread = (*pos & GENMASK_ULL(59, 52)) >> 52;
bank = (*pos & GENMASK_ULL(61, 60)) >> 60;
- data = kmalloc_array(1024, sizeof(*data), GFP_KERNEL);
+ data = kmalloc_array(AMDGPU_DEBUGFS_MAX_SGPR_READ, sizeof(*data),
+ GFP_KERNEL);
if (!data)
return -ENOMEM;
--
2.14.3
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/amd/amdgpu: Fix amdgpu_debugfs_gpr_read debugfs entry
[not found] ` <20180409121621.7514-1-tom.stdenis-5C7GfCeVMHo@public.gmane.org>
@ 2018-04-11 11:55 ` Tom St Denis
[not found] ` <aa2b6402-dd7c-d9f1-760a-4d043865eadd-5C7GfCeVMHo@public.gmane.org>
0 siblings, 1 reply; 6+ messages in thread
From: Tom St Denis @ 2018-04-11 11:55 UTC (permalink / raw)
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
Ping?
On 04/09/2018 08:16 AM, Tom St Denis wrote:
> We don't need to check the alignment of the offset and there was
> potential a buffer overflow as well.
>
> Signed-off-by: Tom St Denis <tom.stdenis@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> index c98e59721444..b1ea300008e5 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> @@ -507,6 +507,9 @@ static ssize_t amdgpu_debugfs_wave_read(struct file *f, char __user *buf,
> return result;
> }
>
> +// read at most 1024 words
> +#define AMDGPU_DEBUGFS_MAX_SGPR_READ 1024
> +
> static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
> size_t size, loff_t *pos)
> {
> @@ -515,7 +518,7 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
> ssize_t result = 0;
> uint32_t offset, se, sh, cu, wave, simd, thread, bank, *data;
>
> - if (size & 3 || *pos & 3)
> + if (size & 3 || size > (4 * AMDGPU_DEBUGFS_MAX_SGPR_READ))
> return -EINVAL;
>
> /* decode offset */
> @@ -528,7 +531,8 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
> thread = (*pos & GENMASK_ULL(59, 52)) >> 52;
> bank = (*pos & GENMASK_ULL(61, 60)) >> 60;
>
> - data = kmalloc_array(1024, sizeof(*data), GFP_KERNEL);
> + data = kmalloc_array(AMDGPU_DEBUGFS_MAX_SGPR_READ, sizeof(*data),
> + GFP_KERNEL);
> if (!data)
> return -ENOMEM;
>
>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/amd/amdgpu: Fix amdgpu_debugfs_gpr_read debugfs entry
[not found] ` <aa2b6402-dd7c-d9f1-760a-4d043865eadd-5C7GfCeVMHo@public.gmane.org>
@ 2018-04-11 11:58 ` Christian König
[not found] ` <170cd64d-8d48-b2da-bbd9-d7e934628f6e-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 6+ messages in thread
From: Christian König @ 2018-04-11 11:58 UTC (permalink / raw)
To: Tom St Denis, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
>
> - if (size & 3 || *pos & 3)
> + if (size & 3 || size > (4 * AMDGPU_DEBUGFS_MAX_SGPR_READ))
I think checking the position alignment here is still necessary, cause
we can't read from not dw boundaries don't we?
Christian.
Am 11.04.2018 um 13:55 schrieb Tom St Denis:
> Ping?
>
> On 04/09/2018 08:16 AM, Tom St Denis wrote:
>> We don't need to check the alignment of the offset and there was
>> potential a buffer overflow as well.
>>
>> Signed-off-by: Tom St Denis <tom.stdenis@amd.com>
>> ---
>> drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 8 ++++++--
>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>> index c98e59721444..b1ea300008e5 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>> @@ -507,6 +507,9 @@ static ssize_t amdgpu_debugfs_wave_read(struct
>> file *f, char __user *buf,
>> return result;
>> }
>> +// read at most 1024 words
>> +#define AMDGPU_DEBUGFS_MAX_SGPR_READ 1024
>> +
>> static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user
>> *buf,
>> size_t size, loff_t *pos)
>> {
>> @@ -515,7 +518,7 @@ static ssize_t amdgpu_debugfs_gpr_read(struct
>> file *f, char __user *buf,
>> ssize_t result = 0;
>> uint32_t offset, se, sh, cu, wave, simd, thread, bank, *data;
>> - if (size & 3 || *pos & 3)
>> + if (size & 3 || size > (4 * AMDGPU_DEBUGFS_MAX_SGPR_READ))
>> return -EINVAL;
>> /* decode offset */
>> @@ -528,7 +531,8 @@ static ssize_t amdgpu_debugfs_gpr_read(struct
>> file *f, char __user *buf,
>> thread = (*pos & GENMASK_ULL(59, 52)) >> 52;
>> bank = (*pos & GENMASK_ULL(61, 60)) >> 60;
>> - data = kmalloc_array(1024, sizeof(*data), GFP_KERNEL);
>> + data = kmalloc_array(AMDGPU_DEBUGFS_MAX_SGPR_READ, sizeof(*data),
>> + GFP_KERNEL);
>> if (!data)
>> return -ENOMEM;
>>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/amd/amdgpu: Fix amdgpu_debugfs_gpr_read debugfs entry
[not found] ` <170cd64d-8d48-b2da-bbd9-d7e934628f6e-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2018-04-11 12:03 ` Tom St Denis
[not found] ` <486a6087-e3a0-872d-6f07-b141a2a3e712-5C7GfCeVMHo@public.gmane.org>
0 siblings, 1 reply; 6+ messages in thread
From: Tom St Denis @ 2018-04-11 12:03 UTC (permalink / raw)
To: christian.koenig-5C7GfCeVMHo,
amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
On 04/11/2018 07:58 AM, Christian König wrote:
>>
>> - if (size & 3 || *pos & 3)
>> + if (size & 3 || size > (4 * AMDGPU_DEBUGFS_MAX_SGPR_READ))
>
> I think checking the position alignment here is still necessary, cause
> we can't read from not dw boundaries don't we?
The index is a dword index as fed into SQ_IND_INDEX (offset => start =>
regno as you trace from the debugfs entry to gfx_v8_0_read_wave_sgprs to
wave_read_regs (or analogues...)).
SQ_IND_INDEX doesn't take a byte offset but a dword offset, for instance:
include/asic_reg/gc/gc_9_0_offset.h:#define ixSQ_WAVE_TTMP0
0x026c
include/asic_reg/gc/gc_9_0_offset.h:#define ixSQ_WAVE_TTMP1
0x026d
include/asic_reg/gc/gc_9_0_offset.h:#define ixSQ_WAVE_TTMP2
0x026e
The current way for instance would prohibit reading (directly)
SQ_WAVE_TTMP1.
I agree it's not really how a typical file device works but it's not a
typical file device :-). It's assumed every read would be preceded by a
seek to set the higher order bits anyways.
Cheers,
Tom
>
> Christian.
>
> Am 11.04.2018 um 13:55 schrieb Tom St Denis:
>> Ping?
>>
>> On 04/09/2018 08:16 AM, Tom St Denis wrote:
>>> We don't need to check the alignment of the offset and there was
>>> potential a buffer overflow as well.
>>>
>>> Signed-off-by: Tom St Denis <tom.stdenis@amd.com>
>>> ---
>>> drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 8 ++++++--
>>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>>> index c98e59721444..b1ea300008e5 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>>> @@ -507,6 +507,9 @@ static ssize_t amdgpu_debugfs_wave_read(struct
>>> file *f, char __user *buf,
>>> return result;
>>> }
>>> +// read at most 1024 words
>>> +#define AMDGPU_DEBUGFS_MAX_SGPR_READ 1024
>>> +
>>> static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user
>>> *buf,
>>> size_t size, loff_t *pos)
>>> {
>>> @@ -515,7 +518,7 @@ static ssize_t amdgpu_debugfs_gpr_read(struct
>>> file *f, char __user *buf,
>>> ssize_t result = 0;
>>> uint32_t offset, se, sh, cu, wave, simd, thread, bank, *data;
>>> - if (size & 3 || *pos & 3)
>>> + if (size & 3 || size > (4 * AMDGPU_DEBUGFS_MAX_SGPR_READ))
>>> return -EINVAL;
>>> /* decode offset */
>>> @@ -528,7 +531,8 @@ static ssize_t amdgpu_debugfs_gpr_read(struct
>>> file *f, char __user *buf,
>>> thread = (*pos & GENMASK_ULL(59, 52)) >> 52;
>>> bank = (*pos & GENMASK_ULL(61, 60)) >> 60;
>>> - data = kmalloc_array(1024, sizeof(*data), GFP_KERNEL);
>>> + data = kmalloc_array(AMDGPU_DEBUGFS_MAX_SGPR_READ, sizeof(*data),
>>> + GFP_KERNEL);
>>> if (!data)
>>> return -ENOMEM;
>>>
>> _______________________________________________
>> amd-gfx mailing list
>> amd-gfx@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/amd/amdgpu: Fix amdgpu_debugfs_gpr_read debugfs entry
[not found] ` <486a6087-e3a0-872d-6f07-b141a2a3e712-5C7GfCeVMHo@public.gmane.org>
@ 2018-04-11 12:17 ` Christian König
[not found] ` <ae463873-8fd3-9de5-a1fd-f4d10a5f8675-5C7GfCeVMHo@public.gmane.org>
0 siblings, 1 reply; 6+ messages in thread
From: Christian König @ 2018-04-11 12:17 UTC (permalink / raw)
To: Tom St Denis, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
Am 11.04.2018 um 14:03 schrieb Tom St Denis:
>
>
> On 04/11/2018 07:58 AM, Christian König wrote:
>>>
>>> - if (size & 3 || *pos & 3)
>>> + if (size & 3 || size > (4 * AMDGPU_DEBUGFS_MAX_SGPR_READ))
>>
>> I think checking the position alignment here is still necessary,
>> cause we can't read from not dw boundaries don't we?
>
> The index is a dword index as fed into SQ_IND_INDEX (offset => start
> => regno as you trace from the debugfs entry to
> gfx_v8_0_read_wave_sgprs to wave_read_regs (or analogues...)).
>
> SQ_IND_INDEX doesn't take a byte offset but a dword offset, for instance:
>
> include/asic_reg/gc/gc_9_0_offset.h:#define ixSQ_WAVE_TTMP0 0x026c
> include/asic_reg/gc/gc_9_0_offset.h:#define ixSQ_WAVE_TTMP1 0x026d
> include/asic_reg/gc/gc_9_0_offset.h:#define ixSQ_WAVE_TTMP2 0x026e
>
>
> The current way for instance would prohibit reading (directly)
> SQ_WAVE_TTMP1.
>
> I agree it's not really how a typical file device works but it's not a
> typical file device :-). It's assumed every read would be preceded by
> a seek to set the higher order bits anyways.
So pos=0 is one dw and pos=1 is another one? If that's the case then
that would be a bug since pos is by definition a byte offset.
I suggest to keep the limitation and instead fix how pos is interpreted
instead.
Regards,
Christian.
>
> Cheers,
> Tom
>
>
>>
>> Christian.
>>
>> Am 11.04.2018 um 13:55 schrieb Tom St Denis:
>>> Ping?
>>>
>>> On 04/09/2018 08:16 AM, Tom St Denis wrote:
>>>> We don't need to check the alignment of the offset and there was
>>>> potential a buffer overflow as well.
>>>>
>>>> Signed-off-by: Tom St Denis <tom.stdenis@amd.com>
>>>> ---
>>>> drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 8 ++++++--
>>>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>>>> index c98e59721444..b1ea300008e5 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
>>>> @@ -507,6 +507,9 @@ static ssize_t amdgpu_debugfs_wave_read(struct
>>>> file *f, char __user *buf,
>>>> return result;
>>>> }
>>>> +// read at most 1024 words
>>>> +#define AMDGPU_DEBUGFS_MAX_SGPR_READ 1024
>>>> +
>>>> static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char
>>>> __user *buf,
>>>> size_t size, loff_t *pos)
>>>> {
>>>> @@ -515,7 +518,7 @@ static ssize_t amdgpu_debugfs_gpr_read(struct
>>>> file *f, char __user *buf,
>>>> ssize_t result = 0;
>>>> uint32_t offset, se, sh, cu, wave, simd, thread, bank, *data;
>>>> - if (size & 3 || *pos & 3)
>>>> + if (size & 3 || size > (4 * AMDGPU_DEBUGFS_MAX_SGPR_READ))
>>>> return -EINVAL;
>>>> /* decode offset */
>>>> @@ -528,7 +531,8 @@ static ssize_t amdgpu_debugfs_gpr_read(struct
>>>> file *f, char __user *buf,
>>>> thread = (*pos & GENMASK_ULL(59, 52)) >> 52;
>>>> bank = (*pos & GENMASK_ULL(61, 60)) >> 60;
>>>> - data = kmalloc_array(1024, sizeof(*data), GFP_KERNEL);
>>>> + data = kmalloc_array(AMDGPU_DEBUGFS_MAX_SGPR_READ, sizeof(*data),
>>>> + GFP_KERNEL);
>>>> if (!data)
>>>> return -ENOMEM;
>>>>
>>> _______________________________________________
>>> amd-gfx mailing list
>>> amd-gfx@lists.freedesktop.org
>>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
>>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/amd/amdgpu: Fix amdgpu_debugfs_gpr_read debugfs entry
[not found] ` <ae463873-8fd3-9de5-a1fd-f4d10a5f8675-5C7GfCeVMHo@public.gmane.org>
@ 2018-04-11 15:03 ` Tom St Denis
0 siblings, 0 replies; 6+ messages in thread
From: Tom St Denis @ 2018-04-11 15:03 UTC (permalink / raw)
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
On 04/11/2018 08:17 AM, Christian König wrote:
> Am 11.04.2018 um 14:03 schrieb Tom St Denis:
>>
>>
>> On 04/11/2018 07:58 AM, Christian König wrote:
>>>>
>>>> - if (size & 3 || *pos & 3)
>>>> + if (size & 3 || size > (4 * AMDGPU_DEBUGFS_MAX_SGPR_READ))
>>>
>>> I think checking the position alignment here is still necessary,
>>> cause we can't read from not dw boundaries don't we?
>>
>> The index is a dword index as fed into SQ_IND_INDEX (offset => start
>> => regno as you trace from the debugfs entry to
>> gfx_v8_0_read_wave_sgprs to wave_read_regs (or analogues...)).
>>
>> SQ_IND_INDEX doesn't take a byte offset but a dword offset, for instance:
>>
>> include/asic_reg/gc/gc_9_0_offset.h:#define ixSQ_WAVE_TTMP0 0x026c
>> include/asic_reg/gc/gc_9_0_offset.h:#define ixSQ_WAVE_TTMP1 0x026d
>> include/asic_reg/gc/gc_9_0_offset.h:#define ixSQ_WAVE_TTMP2 0x026e
>>
>>
>> The current way for instance would prohibit reading (directly)
>> SQ_WAVE_TTMP1.
>>
>> I agree it's not really how a typical file device works but it's not a
>> typical file device :-). It's assumed every read would be preceded by
>> a seek to set the higher order bits anyways.
>
> So pos=0 is one dw and pos=1 is another one? If that's the case then
> that would be a bug since pos is by definition a byte offset.
>
> I suggest to keep the limitation and instead fix how pos is interpreted
> instead.
It would break copies of umr out there already (in ways that won't be
obvious and therefore result in lost time/etc). Since umr is probably
the only user of this it's not really a big deal. Ideally, everyone
uses the latest umr each day :-) but that's not realistically the case.
I agree that had I written this today I would keep the file offset
consistent with the byte offset into the register file (shift down by 4
before calling the callback).
Since you need to seek to a very specific address to use this device
it's not the sort of thing that someone would cat and then expect
sensible output anyways.
Tom
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-04-11 15:03 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-09 12:16 [PATCH] drm/amd/amdgpu: Fix amdgpu_debugfs_gpr_read debugfs entry Tom St Denis
[not found] ` <20180409121621.7514-1-tom.stdenis-5C7GfCeVMHo@public.gmane.org>
2018-04-11 11:55 ` Tom St Denis
[not found] ` <aa2b6402-dd7c-d9f1-760a-4d043865eadd-5C7GfCeVMHo@public.gmane.org>
2018-04-11 11:58 ` Christian König
[not found] ` <170cd64d-8d48-b2da-bbd9-d7e934628f6e-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-04-11 12:03 ` Tom St Denis
[not found] ` <486a6087-e3a0-872d-6f07-b141a2a3e712-5C7GfCeVMHo@public.gmane.org>
2018-04-11 12:17 ` Christian König
[not found] ` <ae463873-8fd3-9de5-a1fd-f4d10a5f8675-5C7GfCeVMHo@public.gmane.org>
2018-04-11 15:03 ` Tom St Denis
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.