From: Xiang W <wxjstz@126.com>
To: opensbi@lists.infradead.org
Subject: [PATCH 2/2] lib: sbi_ipi: Return error for invalid hartids
Date: Mon, 17 Mar 2025 18:27:10 +0800 [thread overview]
Message-ID: <72a1316613d4dcc4840f31da1e356861ba582f34.camel@126.com> (raw)
In-Reply-To: <20250317-a6c4a9822fab93ae96c9337a@orel>
? 2025-03-17?? 09:45 +0100?Andrew Jones???
> On Mon, Mar 17, 2025 at 12:56:59PM +0800, Xiang W wrote:
> > ? 2025-03-14?? 17:30 +0100?Andrew Jones???
> > > sbi_send_ipi() should return SBI_ERR_INVALID_PARAM if even one hartid
> > > constructed from hart_mask_base and hart_mask, is not valid.
> > >
> > > Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
> > > ---
> > > ?lib/sbi/sbi_ipi.c | 9 +++++++++
> > > ?1 file changed, 9 insertions(+)
> > >
> > > diff --git a/lib/sbi/sbi_ipi.c b/lib/sbi/sbi_ipi.c
> > > index 52898d302376..2de459b089ff 100644
> > > --- a/lib/sbi/sbi_ipi.c
> > > +++ b/lib/sbi/sbi_ipi.c
> > > @@ -116,6 +116,11 @@ int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data)
> > > ? struct sbi_domain *dom = sbi_domain_thishart_ptr();
> > > ? struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
> > > ?
> > > + if (hmask == 0 && hbase != -1UL) {
> > > + /* Nothing to do, but it's not an error either. */
> > > + return 0;
> > > + }
> > > +
> > > ? /* Find the target harts */
> > > ? rc = sbi_hsm_hart_interruptible_mask(dom, &target_mask);
> > > ? if (rc)
> > > @@ -123,6 +128,7 @@ int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data)
> > > ?
> > > ? if (hbase != -1UL) {
> > > ? struct sbi_hartmask tmp_mask = { 0 };
> > > + int count = sbi_popcount(hmask);
> > > ?
> > > ? for (i = hbase; hmask; i++, hmask >>= 1) {
> > > ? if (hmask & 1UL)
> > > @@ -130,6 +136,9 @@ int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data)
> > > ? }
> > > ?
> > > ? sbi_hartmask_and(&target_mask, &target_mask, &tmp_mask);
> > > +
> > > + if (sbi_hartmask_weight(&target_mask) != count)
> > > + return SBI_EINVAL;
> > If hmask is equal to 0 and hbase is equal to -1, count will be 0.
> > This will always return SBI_EINVAL. Need to add some code to skip
> > this case
>
> Wrong, again, and this time for two reasons. This code is in an
> 'hbase != -1' block (as can be seen a few lines above). Also, if count
> were to equal 0 (which it can't, due to the early out added above), then
> the weight of target_mask would also be 0, which means we would never
> return SBI_EINVAL, as that would require 0 != 0 to be true.
pardon me!
Xiang
> drew
next prev parent reply other threads:[~2025-03-17 10:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-14 16:30 [PATCH 0/2] lib: sbi_ipi: Return error for invalid hartids Andrew Jones
2025-03-14 16:30 ` [PATCH 1/2] sbi: Introduce sbi_hartmask_weight Andrew Jones
2025-03-16 6:26 ` Anup Patel
2025-03-16 6:46 ` Xiang W
2025-03-14 16:30 ` [PATCH 2/2] lib: sbi_ipi: Return error for invalid hartids Andrew Jones
2025-03-15 4:19 ` Xiang W
2025-03-15 10:50 ` Andrew Jones
2025-03-15 11:19 ` Anup Patel
2025-03-16 6:29 ` Anup Patel
2025-03-16 6:45 ` Xiang W
2025-03-17 4:56 ` Xiang W
2025-03-17 8:45 ` Andrew Jones
2025-03-17 10:27 ` Xiang W [this message]
2025-04-14 10:01 ` [PATCH 0/2] " Anup Patel
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=72a1316613d4dcc4840f31da1e356861ba582f34.camel@126.com \
--to=wxjstz@126.com \
--cc=opensbi@lists.infradead.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.