* [PATCH 2/3] gpu: drm: dead code elimination
@ 2019-12-18 3:50 Pan Zhang
2019-12-18 9:52 ` Christian König
2019-12-18 9:52 ` Michel Dänzer
0 siblings, 2 replies; 4+ messages in thread
From: Pan Zhang @ 2019-12-18 3:50 UTC (permalink / raw)
To: zhangpan26, hushiyuan, alexander.deucher, christian.koenig,
David1.Zhou, airlied, daniel, ray.huang, irmoy.das, sam
Cc: amd-gfx, dri-devel, linux-kernel
this set adds support for removal of gpu drm dead code.
patch2:
`num_entries` is a data of unsigned type(compilers always treat as unsigned int) and SIZE_MAX == ~0,
so there is a impossible condition:
'(num_entries > ((~0) - 56) / 72) => (max(0-u32) > 256204778801521549)'.
Signed-off-by: Pan Zhang <zhangpan26@huawei.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
index 85b0515..10a7f30 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
@@ -71,10 +71,6 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
unsigned i;
int r;
- if (num_entries > (SIZE_MAX - sizeof(struct amdgpu_bo_list))
- / sizeof(struct amdgpu_bo_list_entry))
- return -EINVAL;
-
size = sizeof(struct amdgpu_bo_list);
size += num_entries * sizeof(struct amdgpu_bo_list_entry);
list = kvmalloc(size, GFP_KERNEL);
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/3] gpu: drm: dead code elimination
2019-12-18 3:50 [PATCH 2/3] gpu: drm: dead code elimination Pan Zhang
@ 2019-12-18 9:52 ` Christian König
2019-12-18 9:52 ` Michel Dänzer
1 sibling, 0 replies; 4+ messages in thread
From: Christian König @ 2019-12-18 9:52 UTC (permalink / raw)
To: Pan Zhang, hushiyuan, alexander.deucher, David1.Zhou, airlied,
daniel, ray.huang, irmoy.das, sam
Cc: amd-gfx, dri-devel, linux-kernel
Am 18.12.19 um 04:50 schrieb Pan Zhang:
> this set adds support for removal of gpu drm dead code.
>
> patch2:
> `num_entries` is a data of unsigned type(compilers always treat as unsigned int) and SIZE_MAX == ~0,
>
> so there is a impossible condition:
> '(num_entries > ((~0) - 56) / 72) => (max(0-u32) > 256204778801521549)'.
NAK, that calculation is not correct on 32-bit systems.
Christian.
>
> Signed-off-by: Pan Zhang <zhangpan26@huawei.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 4 ----
> 1 file changed, 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> index 85b0515..10a7f30 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> @@ -71,10 +71,6 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
> unsigned i;
> int r;
>
> - if (num_entries > (SIZE_MAX - sizeof(struct amdgpu_bo_list))
> - / sizeof(struct amdgpu_bo_list_entry))
> - return -EINVAL;
> -
> size = sizeof(struct amdgpu_bo_list);
> size += num_entries * sizeof(struct amdgpu_bo_list_entry);
> list = kvmalloc(size, GFP_KERNEL);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/3] gpu: drm: dead code elimination
2019-12-18 3:50 [PATCH 2/3] gpu: drm: dead code elimination Pan Zhang
2019-12-18 9:52 ` Christian König
@ 2019-12-18 9:52 ` Michel Dänzer
2019-12-19 3:38 ` Pan Zhang
1 sibling, 1 reply; 4+ messages in thread
From: Michel Dänzer @ 2019-12-18 9:52 UTC (permalink / raw)
To: Pan Zhang, hushiyuan, alexander.deucher, christian.koenig,
David1.Zhou, airlied, daniel, ray.huang, irmoy.das, sam
Cc: dri-devel, amd-gfx, linux-kernel
On 2019-12-18 4:50 a.m., Pan Zhang wrote:
> this set adds support for removal of gpu drm dead code.
>
> patch2:
> `num_entries` is a data of unsigned type(compilers always treat as unsigned int) and SIZE_MAX == ~0,
>
> so there is a impossible condition:
> '(num_entries > ((~0) - 56) / 72) => (max(0-u32) > 256204778801521549)'.
While this looks correct for 64-bit, where size_t is unsigned long, on
32-bit it's unsigned int, in which case this isn't dead code.
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> index 85b0515..10a7f30 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
> @@ -71,10 +71,6 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
> unsigned i;
> int r;
>
> - if (num_entries > (SIZE_MAX - sizeof(struct amdgpu_bo_list))
> - / sizeof(struct amdgpu_bo_list_entry))
> - return -EINVAL;
> -
> size = sizeof(struct amdgpu_bo_list);
> size += num_entries * sizeof(struct amdgpu_bo_list_entry);
> list = kvmalloc(size, GFP_KERNEL);
>
--
Earthling Michel Dänzer | https://redhat.com
Libre software enthusiast | Mesa and X developer
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Re: [PATCH 2/3] gpu: drm: dead code elimination
2019-12-18 9:52 ` Michel Dänzer
@ 2019-12-19 3:38 ` Pan Zhang
0 siblings, 0 replies; 4+ messages in thread
From: Pan Zhang @ 2019-12-19 3:38 UTC (permalink / raw)
To: christian.koenig, michel, alexander.deucher, David1.Zhou,
airlied, daniel, ray.huang, irmoy.das, sam, zhangpan26,
hushiyuan
Cc: amd-gfx, dri-devel, linux-kernel
On 2019-12-18 5:52 p.m., Michel Dänzer <michel@daenzer.net> wrote:
>> this set adds support for removal of gpu drm dead code.
>>
>> patch2:
>> `num_entries` is a data of unsigned type(compilers always treat as
>> unsigned int) and SIZE_MAX == ~0,
>>
>> so there is a impossible condition:
>> '(num_entries > ((~0) - 56) / 72) => (max(0-u32) > 256204778801521549)'.
>While this looks correct for 64-bit, where size_t is unsigned long, on 32-bit it's unsigned int, in which case this isn't dead code.
and
On 2019-12-18 5:52 p.m., Christian König <christian.koenig@xxxxxxx> wrote:
>NAK, that calculation is not correct on 32-bit systems.
>Christian.
Yes, you are right. I just figured this out (because our Server usually uses 64 bits).
thanks.
>>Signed-off-by: Pan Zhang <zhangpan26@xxxxxxxxxx>
>>---
>> drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 4 ----
>> 1 file changed, 4 deletions(-)
>>diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
>>index 85b0515..10a7f30 100644
>>--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
>>+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
>>@@ -71,10 +71,6 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
>> unsigned i;
>> int r;
>>
>>- if (num_entries > (SIZE_MAX - sizeof(struct amdgpu_bo_list))
>>- / sizeof(struct amdgpu_bo_list_entry))
>>- return -EINVAL;
>>-
>> size = sizeof(struct amdgpu_bo_list);
>> size += num_entries * sizeof(struct amdgpu_bo_list_entry);
>> list = kvmalloc(size, GFP_KERNEL);
>>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-12-19 3:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-18 3:50 [PATCH 2/3] gpu: drm: dead code elimination Pan Zhang
2019-12-18 9:52 ` Christian König
2019-12-18 9:52 ` Michel Dänzer
2019-12-19 3:38 ` Pan Zhang
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).