* [PATCH][next] amd/amdgpu_ctx: Use struct_size() helper and kmalloc()
@ 2020-10-08 14:34 Gustavo A. R. Silva
2020-10-08 17:22 ` Alex Deucher
2020-10-09 7:08 ` Christian König
0 siblings, 2 replies; 6+ messages in thread
From: Gustavo A. R. Silva @ 2020-10-08 14:34 UTC (permalink / raw)
To: Alex Deucher, Christian König, David Airlie, Daniel Vetter
Cc: amd-gfx, dri-devel, linux-kernel, Gustavo A. R. Silva, linux-hardening
Make use of the new struct_size() helper instead of the offsetof() idiom.
Also, use kmalloc() instead of kcalloc().
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index c80d8339f58c..5be125f3b92a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -100,7 +100,7 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, u32 hw_ip,
enum drm_sched_priority priority;
int r;
- entity = kcalloc(1, offsetof(typeof(*entity), fences[amdgpu_sched_jobs]),
+ entity = kmalloc(struct_size(entity, fences, amdgpu_sched_jobs),
GFP_KERNEL);
if (!entity)
return -ENOMEM;
--
2.27.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH][next] amd/amdgpu_ctx: Use struct_size() helper and kmalloc()
2020-10-08 14:34 [PATCH][next] amd/amdgpu_ctx: Use struct_size() helper and kmalloc() Gustavo A. R. Silva
@ 2020-10-08 17:22 ` Alex Deucher
2020-10-09 7:08 ` Christian König
1 sibling, 0 replies; 6+ messages in thread
From: Alex Deucher @ 2020-10-08 17:22 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Alex Deucher, Christian König, David Airlie, Daniel Vetter,
linux-hardening, Maling list - DRI developers, amd-gfx list,
LKML
Applied. Thanks!
Alex
On Thu, Oct 8, 2020 at 10:29 AM Gustavo A. R. Silva
<gustavoars@kernel.org> wrote:
>
> Make use of the new struct_size() helper instead of the offsetof() idiom.
> Also, use kmalloc() instead of kcalloc().
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> index c80d8339f58c..5be125f3b92a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> @@ -100,7 +100,7 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, u32 hw_ip,
> enum drm_sched_priority priority;
> int r;
>
> - entity = kcalloc(1, offsetof(typeof(*entity), fences[amdgpu_sched_jobs]),
> + entity = kmalloc(struct_size(entity, fences, amdgpu_sched_jobs),
> GFP_KERNEL);
> if (!entity)
> return -ENOMEM;
> --
> 2.27.0
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH][next] amd/amdgpu_ctx: Use struct_size() helper and kmalloc()
2020-10-08 14:34 [PATCH][next] amd/amdgpu_ctx: Use struct_size() helper and kmalloc() Gustavo A. R. Silva
2020-10-08 17:22 ` Alex Deucher
@ 2020-10-09 7:08 ` Christian König
2020-10-09 13:54 ` Gustavo A. R. Silva
1 sibling, 1 reply; 6+ messages in thread
From: Christian König @ 2020-10-09 7:08 UTC (permalink / raw)
To: Gustavo A. R. Silva, Alex Deucher, David Airlie, Daniel Vetter
Cc: amd-gfx, dri-devel, linux-kernel, linux-hardening
Am 08.10.20 um 16:34 schrieb Gustavo A. R. Silva:
> Make use of the new struct_size() helper instead of the offsetof() idiom.
> Also, use kmalloc() instead of kcalloc().
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> index c80d8339f58c..5be125f3b92a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> @@ -100,7 +100,7 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, u32 hw_ip,
> enum drm_sched_priority priority;
> int r;
>
> - entity = kcalloc(1, offsetof(typeof(*entity), fences[amdgpu_sched_jobs]),
> + entity = kmalloc(struct_size(entity, fences, amdgpu_sched_jobs),
NAK. You could use kzalloc() here, but kmalloc won't zero initialize the
memory which could result in unforeseen consequences.
Christian.
> GFP_KERNEL);
> if (!entity)
> return -ENOMEM;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH][next] amd/amdgpu_ctx: Use struct_size() helper and kmalloc()
2020-10-09 7:08 ` Christian König
@ 2020-10-09 13:54 ` Gustavo A. R. Silva
2020-10-09 14:29 ` Christian König
0 siblings, 1 reply; 6+ messages in thread
From: Gustavo A. R. Silva @ 2020-10-09 13:54 UTC (permalink / raw)
To: Christian König
Cc: Alex Deucher, David Airlie, Daniel Vetter, amd-gfx, dri-devel,
linux-kernel, linux-hardening
On Fri, Oct 09, 2020 at 09:08:51AM +0200, Christian König wrote:
> Am 08.10.20 um 16:34 schrieb Gustavo A. R. Silva:
> > Make use of the new struct_size() helper instead of the offsetof() idiom.
> > Also, use kmalloc() instead of kcalloc().
> >
> > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> > ---
> > drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> > index c80d8339f58c..5be125f3b92a 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
> > @@ -100,7 +100,7 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, u32 hw_ip,
> > enum drm_sched_priority priority;
> > int r;
> > - entity = kcalloc(1, offsetof(typeof(*entity), fences[amdgpu_sched_jobs]),
> > + entity = kmalloc(struct_size(entity, fences, amdgpu_sched_jobs),
>
> NAK. You could use kzalloc() here, but kmalloc won't zero initialize the
> memory which could result in unforeseen consequences.
Oh I see.. I certainly didn't take that into account.
I'll fix that up and respin.
Thanks
--
Gustavo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH][next] amd/amdgpu_ctx: Use struct_size() helper and kmalloc()
2020-10-09 13:54 ` Gustavo A. R. Silva
@ 2020-10-09 14:29 ` Christian König
2020-10-09 14:39 ` Gustavo A. R. Silva
0 siblings, 1 reply; 6+ messages in thread
From: Christian König @ 2020-10-09 14:29 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Alex Deucher, David Airlie, Daniel Vetter, amd-gfx, dri-devel,
linux-kernel, linux-hardening
Am 09.10.20 um 15:54 schrieb Gustavo A. R. Silva:
> On Fri, Oct 09, 2020 at 09:08:51AM +0200, Christian König wrote:
>> Am 08.10.20 um 16:34 schrieb Gustavo A. R. Silva:
>>> Make use of the new struct_size() helper instead of the offsetof() idiom.
>>> Also, use kmalloc() instead of kcalloc().
>>>
>>> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
>>> ---
>>> drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
>>> index c80d8339f58c..5be125f3b92a 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
>>> @@ -100,7 +100,7 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, u32 hw_ip,
>>> enum drm_sched_priority priority;
>>> int r;
>>> - entity = kcalloc(1, offsetof(typeof(*entity), fences[amdgpu_sched_jobs]),
>>> + entity = kmalloc(struct_size(entity, fences, amdgpu_sched_jobs),
>> NAK. You could use kzalloc() here, but kmalloc won't zero initialize the
>> memory which could result in unforeseen consequences.
> Oh I see.. I certainly didn't take that into account.
>
> I'll fix that up and respin.
Shit happens, we already have a fix for this. Alex merged it and it
immediately broke our testing systems.
So one of our engineers came up with a fix which should already have
been applied.
Christian.
>
> Thanks
> --
> Gustavo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH][next] amd/amdgpu_ctx: Use struct_size() helper and kmalloc()
2020-10-09 14:29 ` Christian König
@ 2020-10-09 14:39 ` Gustavo A. R. Silva
0 siblings, 0 replies; 6+ messages in thread
From: Gustavo A. R. Silva @ 2020-10-09 14:39 UTC (permalink / raw)
To: Christian König
Cc: Alex Deucher, David Airlie, Daniel Vetter, amd-gfx, dri-devel,
linux-kernel, linux-hardening
On Fri, Oct 09, 2020 at 04:29:55PM +0200, Christian König wrote:
> > > > - entity = kcalloc(1, offsetof(typeof(*entity), fences[amdgpu_sched_jobs]),
> > > > + entity = kmalloc(struct_size(entity, fences, amdgpu_sched_jobs),
> > > NAK. You could use kzalloc() here, but kmalloc won't zero initialize the
> > > memory which could result in unforeseen consequences.
> > Oh I see.. I certainly didn't take that into account.
> >
> > I'll fix that up and respin.
>
> Shit happens, we already have a fix for this. Alex merged it and it
> immediately broke our testing systems.
:/
> So one of our engineers came up with a fix which should already have been
> applied.
Great. Good to know it's already fixed! :)
Thanks
--
Gustavo
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-10-09 14:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-08 14:34 [PATCH][next] amd/amdgpu_ctx: Use struct_size() helper and kmalloc() Gustavo A. R. Silva
2020-10-08 17:22 ` Alex Deucher
2020-10-09 7:08 ` Christian König
2020-10-09 13:54 ` Gustavo A. R. Silva
2020-10-09 14:29 ` Christian König
2020-10-09 14:39 ` Gustavo A. R. Silva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).