From: Linus Torvalds <torvalds@linux-foundation.org>
To: Vernon Yang <vernon2gm@gmail.com>
Cc: tytso@mit.edu, Jason@zx2c4.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
jejb@linux.ibm.com, martin.petersen@oracle.com,
yury.norov@gmail.com, andriy.shevchenko@linux.intel.com,
linux@rasmusvillemoes.dk, james.smart@broadcom.com,
dick.kennedy@broadcom.com, linux-kernel@vger.kernel.org,
wireguard@lists.zx2c4.com, netdev@vger.kernel.org,
linux-scsi@vger.kernel.org
Subject: Re: [PATCH 5/5] cpumask: fix comment of cpumask_xxx
Date: Mon, 6 Mar 2023 10:02:27 -0800 [thread overview]
Message-ID: <CAHk-=wj5hFp39ZM7fEtmctwkWdHHnx0X7c2j5Z8L+b18jUgcMQ@mail.gmail.com> (raw)
In-Reply-To: <CAHk-=witXXeQuP9fgs4dDL2Ex0meXQiHJs+3JEfNdaPwngMVEg@mail.gmail.com>
On Mon, Mar 6, 2023 at 9:47 AM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> The drivers/char/random.c code is very wrong, and does
>
> if (cpu == nr_cpumask_bits)
> cpu = cpumask_first(&timer_cpus);
>
> which fails miserably exactly because it doesn't use ">=".
Turns out this "cpu == nr_cpumask_bits" pattern exists in a couple of
other places too.
It was always wrong, but it always just happened to work. The lpfc
SCSI driver in particular seems to *love* this pattern:
start_cpu = cpumask_next(new_cpu, cpu_present_mask);
if (start_cpu == nr_cpumask_bits)
start_cpu = first_cpu;
and has repeated it multiple times, all incorrect.
We do have "cpumask_next_wrap()", and that *seems* to be what the lpcf
driver actually wants to do.
.. and then we have kernel/sched/fair.c, which is actually not buggy,
just odd. It uses nr_cpumask_bits too, but it uses it purely for its
own internal nefarious reasons - it's not actually related to the
cpumask functions at all, its just used as a "not valid CPU number".
I think that scheduler use is still very *wrong*, but it doesn't look
actively buggy.
The other cases all look very buggy indeed, but yes, they happened to
work, and now they don't. So commit 596ff4a09b89 ("cpumask:
re-introduce constant-sized cpumask optimizations") did break them.
I'd rather fix these bad users than revert, but there does seem to be
an alarming number of these things, which worries me:
git grep '== nr_cpumask_bits'
and that's just checking for this *exact* thing.
Linus
next prev parent reply other threads:[~2023-03-06 18:09 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-06 16:06 [PATCH 0/5] fix call cpumask_next() if no further cpus set Vernon Yang
2023-03-06 16:06 ` [PATCH 1/5] random: fix try_to_generate_entropy() " Vernon Yang
2023-03-06 16:26 ` Yury Norov
2023-03-06 16:06 ` [PATCH 2/5] wireguard: fix wg_cpumask_choose_online() " Vernon Yang
2023-03-06 16:06 ` [PATCH 3/5] scsi: lpfc: fix lpfc_cpu_affinity_check() " Vernon Yang
2023-03-06 18:48 ` Linus Torvalds
2023-03-06 20:09 ` Vernon Yang
2023-03-06 16:06 ` [PATCH 4/5] scsi: lpfc: fix lpfc_nvmet_setup_io_context() " Vernon Yang
2023-03-06 16:06 ` [PATCH 5/5] cpumask: fix comment of cpumask_xxx Vernon Yang
2023-03-06 16:39 ` Yury Norov
2023-03-06 16:44 ` Jason A. Donenfeld
2023-03-06 16:54 ` Yury Norov
2023-03-06 17:04 ` Jason A. Donenfeld
2023-03-06 17:45 ` Vernon Yang
2023-03-06 17:29 ` Linus Torvalds
2023-03-06 17:47 ` Linus Torvalds
2023-03-06 18:02 ` Linus Torvalds [this message]
2023-03-06 18:13 ` Vernon Yang
2023-03-06 18:34 ` Linus Torvalds
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='CAHk-=wj5hFp39ZM7fEtmctwkWdHHnx0X7c2j5Z8L+b18jUgcMQ@mail.gmail.com' \
--to=torvalds@linux-foundation.org \
--cc=Jason@zx2c4.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=davem@davemloft.net \
--cc=dick.kennedy@broadcom.com \
--cc=edumazet@google.com \
--cc=james.smart@broadcom.com \
--cc=jejb@linux.ibm.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=martin.petersen@oracle.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tytso@mit.edu \
--cc=vernon2gm@gmail.com \
--cc=wireguard@lists.zx2c4.com \
--cc=yury.norov@gmail.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;
as well as URLs for NNTP newsgroup(s).