2014-12-03 14:26:50

by Sasha Levin

[permalink] [raw]
Subject: [PATCH] amdkfd: use sizeof(long) granularity for the pasid bitmask

All the bit operations (such as find_first_zero_bit()) read sizeof(long) bytes
at a time. If we allocated less than sizeof(long) bytes for the bitmask we
would be accessing invalid memory when working with the bitmask.

Change the allocator to allocate sizeof(long) multiples for the bitmask.

Signed-off-by: Sasha Levin <[email protected]>
---
drivers/gpu/drm/amd/amdkfd/kfd_pasid.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_pasid.c b/drivers/gpu/drm/amd/amdkfd/kfd_pasid.c
index 2458ab7..71699ad 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_pasid.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_pasid.c
@@ -32,8 +32,7 @@ int kfd_pasid_init(void)
{
pasid_limit = max_num_of_processes;

- pasid_bitmap = kzalloc(DIV_ROUND_UP(pasid_limit, BITS_PER_BYTE),
- GFP_KERNEL);
+ pasid_bitmap = kzalloc(BITS_TO_LONGS(pasid_limit), GFP_KERNEL);
if (!pasid_bitmap)
return -ENOMEM;

--
2.1.0


2014-12-04 12:21:44

by Oded Gabbay

[permalink] [raw]
Subject: Re: [PATCH] amdkfd: use sizeof(long) granularity for the pasid bitmask



On 12/03/2014 04:26 PM, Sasha Levin wrote:
> All the bit operations (such as find_first_zero_bit()) read sizeof(long) bytes
> at a time. If we allocated less than sizeof(long) bytes for the bitmask we
> would be accessing invalid memory when working with the bitmask.
>
> Change the allocator to allocate sizeof(long) multiples for the bitmask.
>
> Signed-off-by: Sasha Levin <[email protected]>
> ---
> drivers/gpu/drm/amd/amdkfd/kfd_pasid.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_pasid.c b/drivers/gpu/drm/amd/amdkfd/kfd_pasid.c
> index 2458ab7..71699ad 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_pasid.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_pasid.c
> @@ -32,8 +32,7 @@ int kfd_pasid_init(void)
> {
> pasid_limit = max_num_of_processes;
>
> - pasid_bitmap = kzalloc(DIV_ROUND_UP(pasid_limit, BITS_PER_BYTE),
> - GFP_KERNEL);
> + pasid_bitmap = kzalloc(BITS_TO_LONGS(pasid_limit), GFP_KERNEL);
> if (!pasid_bitmap)
> return -ENOMEM;
>
>

Thanks!
Applied to my -next tree.

Oded