[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87h6brobq1.fsf@kamlesh.i-did-not-set--mail-host-address--so-tickle-me>
Date: Sun, 11 Aug 2024 11:14:06 +0530
From: Kamlesh Gurudasani <kamlesh@...com>
To: Waiman Long <longman@...hat.com>,
Steffen Klassert
<steffen.klassert@...unet.com>,
Daniel Jordan <daniel.m.jordan@...cle.com>,
Andrew Morton <akpm@...ux-foundation.org>
CC: <linux-crypto@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] padata: Fix possible divide-by-0 panic in
padata_mt_helper()
Waiman Long <longman@...hat.com> writes:
> On 8/10/24 13:44, Kamlesh Gurudasani wrote:
>> Waiman Long <longman@...hat.com> writes:
>>
...
>>> diff --git a/kernel/padata.c b/kernel/padata.c
>>> index 53f4bc912712..0fa6c2895460 100644
>>> --- a/kernel/padata.c
>>> +++ b/kernel/padata.c
>>> @@ -517,6 +517,13 @@ void __init padata_do_multithreaded(struct padata_mt_job *job)
>>> ps.chunk_size = max(ps.chunk_size, job->min_chunk);
>>> ps.chunk_size = roundup(ps.chunk_size, job->align);
>>>
>>> + /*
>>> + * chunk_size can be 0 if the caller sets min_chunk to 0. So force it
>>> + * to at least 1 to prevent divide-by-0 panic in padata_mt_helper().`
>>> + */
>> Thanks for the patch and detailed comment.
>>> + if (!ps.chunk_size)
>>> + ps.chunk_size = 1U;
>>> +
>> could it be
>> ps.chunk_size = max(ps.chunk_size, 1U);
>>
>> or can be merged with earlier max()
>> ps.chunk_size = max(ps.chunk_size, max(job->min_chunk, 1U));
>> ps.chunk_size = roundup(ps.chunk_size, job->align);
>>
>> sits well with how entire file is written and compiler is optimizing
>> them to same level.
>
> I had actually thought about doing that as an alternative. I used the
> current patch to avoid putting too many max() calls there. I can go this
> route if you guys prefer this.
Just curious, what is your reason for avoiding too many max() calls? Both
if (!ps.chunk_size)
ps.chunk_size = 1U;
and
ps.chunk_size = max(ps.chunk_size, 1U);
are having same number of instructions [1].
[1] https://godbolt.org/z/ajrK59c67
We can avoid nested max(), though following would make it easier to understand.
ps.chunk_size = max(ps.chunk_size, 1U);
Cheers,
Kamlesh
>
> Cheers,
> Longman
Powered by blists - more mailing lists