[PATCH] riscv: Use kvmalloc_array on relocation_hashtable

William Pierce wgpierce17 at gmail.com
Wed Apr 2 01:12:44 PDT 2025


Hi Alexandre,

On 4/1/25 11:56 PM, Alexandre Ghiti wrote:
> Hi Will,
> 
> On 02/04/2025 07:34, wgpierce17 at gmail.com wrote:
>> From: Will Pierce <wgpierce17 at gmail.com>
>>
>> The number of relocations may be a huge value that is unallocatable
>> by kmalloc. Use kvmalloc instead so that it does not fail.
>>
>> Signed-off-by: Will Pierce <wgpierce17 at gmail.com>
>> ---
>>   arch/riscv/kernel/module.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c
>> index 47d0ebeec93c..bae3db50647c 100644
>> --- a/arch/riscv/kernel/module.c
>> +++ b/arch/riscv/kernel/module.c
>> @@ -648,7 +648,7 @@ process_accumulated_relocations(struct module *me,
>>           kfree(bucket_iter);
>>       }
>>   -    kfree(*relocation_hashtable);
>> +    kvfree(*relocation_hashtable);
>>   }
>>     static int add_relocation_to_accumulate(struct module *me, int type,
>> @@ -752,7 +752,8 @@ initialize_relocation_hashtable(unsigned int num_relocations,
>>         hashtable_size <<= should_double_size;
>>   -    *relocation_hashtable = kmalloc_array(hashtable_size,
>> +    /* Number of relocations may be large, so kvmalloc it */
>> +    *relocation_hashtable = kvmalloc_array(hashtable_size,
>>                             sizeof(**relocation_hashtable),
>>                             GFP_KERNEL);
>>       if (!*relocation_hashtable)
> 
> 
> Let's add a fixes tag:
> 
> Fixes: 8fd6c5142395 ("riscv: Add remaining module relocations")
> 
> Since Clément suggested this solution:
> 
> Suggested-by: Clément Léger <cleger at rivosinc.com>
> 
> And finally, this looks good to me so:
> 
> Reviewed-by: Alexandre Ghiti <alexghiti at rivosinc.com>
> 
> It's a bit late for rc1 so I'll take this one for a next rc.
> 
> Thanks for the patch!
> 
> Alex
> 
> 

Thank you for checking. I will send a v2 with these additions and
a minor whitespace fix right now.

- Will



More information about the linux-riscv mailing list