From: Waiman Long <longman@redhat.com>
To: Kamlesh Gurudasani <kamlesh@ti.com>,
Steffen Klassert <steffen.klassert@secunet.com>,
Daniel Jordan <daniel.m.jordan@oracle.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] padata: Fix possible divide-by-0 panic in padata_mt_helper()
Date: Tue, 13 Aug 2024 14:28:17 -0400 [thread overview]
Message-ID: <986ef2c0-4ed7-4b13-82f2-5f14e30d08e1@redhat.com> (raw)
In-Reply-To: <87h6brobq1.fsf@kamlesh.i-did-not-set--mail-host-address--so-tickle-me>
On 8/11/24 01:44, Kamlesh Gurudasani wrote:
> Waiman Long <longman@redhat.com> writes:
>
>> On 8/10/24 13:44, Kamlesh Gurudasani wrote:
>>> Waiman Long <longman@redhat.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);
That will certainly work. My current patch has been merged into the
Linus tree. You are welcome to post another patch to clean it up if you
want.
Cheers,
Longman
>
> Cheers,
> Kamlesh
>
>> Cheers,
>> Longman
prev parent reply other threads:[~2024-08-13 18:28 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-06 17:46 [PATCH] padata: Fix possible divide-by-0 panic in padata_mt_helper() Waiman Long
2024-08-10 4:05 ` Herbert Xu
2024-08-11 1:30 ` Waiman Long
2024-08-11 1:45 ` Herbert Xu
2024-08-11 3:11 ` Waiman Long
2024-08-11 3:13 ` Herbert Xu
2024-08-11 3:27 ` Waiman Long
2024-08-11 3:41 ` Herbert Xu
[not found] ` <c5cc5ea9-1135-4ac6-a38f-652ed07dae17@redhat.com>
2024-08-17 7:12 ` Herbert Xu
2024-08-19 22:29 ` Daniel Jordan
2024-08-20 0:07 ` Waiman Long
2024-08-20 4:06 ` Herbert Xu
2024-08-20 21:24 ` Daniel Jordan
2024-08-21 8:10 ` [EXTERNAL] " Kamlesh Gurudasani
2024-08-21 21:10 ` Kamlesh Gurudasani
2024-08-23 0:45 ` Daniel Jordan
2024-08-10 17:44 ` Kamlesh Gurudasani
2024-08-11 3:33 ` Waiman Long
2024-08-11 5:44 ` Kamlesh Gurudasani
2024-08-13 18:28 ` Waiman Long [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=986ef2c0-4ed7-4b13-82f2-5f14e30d08e1@redhat.com \
--to=longman@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=daniel.m.jordan@oracle.com \
--cc=kamlesh@ti.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=steffen.klassert@secunet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox