qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] linux-user: fix handling of cpu mask in riscv_hwprobe syscall
@ 2025-03-04 16:52 Andreas Schwab
  2025-03-10 23:10 ` Alistair Francis
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Schwab @ 2025-03-04 16:52 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: Palmer Dabbelt, Robbin Ehn, Alistair Francis, qemu-devel

The third argument of the riscv_hwprobe syscall contains the size of the
cpu mask in bytes, not bits.

Signed-off-by: Andreas Schwab <schwab@suse.de>
---
 linux-user/syscall.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index a22a5df8cc..4cc1a31d0d 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -9120,16 +9120,16 @@ static void risc_hwprobe_fill_pairs(CPURISCVState *env,
 
 static int cpu_set_valid(abi_long arg3, abi_long arg4)
 {
-    int ret, i, tmp;
+    int ret, i;
     size_t host_mask_size, target_mask_size;
     unsigned long *host_mask;
 
     /*
      * cpu_set_t represent CPU masks as bit masks of type unsigned long *.
-     * arg3 contains the cpu count.
+     * arg3 contains the size of the cpu mask.
      */
-    tmp = (8 * sizeof(abi_ulong));
-    target_mask_size = ((arg3 + tmp - 1) / tmp) * sizeof(abi_ulong);
+    target_mask_size = (arg3 + (sizeof(abi_ulong) - 1)) &
+                       ~(sizeof(abi_ulong) - 1);
     host_mask_size = (target_mask_size + (sizeof(*host_mask) - 1)) &
                      ~(sizeof(*host_mask) - 1);
 
-- 
2.48.1


-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] linux-user: fix handling of cpu mask in riscv_hwprobe syscall
  2025-03-04 16:52 [PATCH] linux-user: fix handling of cpu mask in riscv_hwprobe syscall Andreas Schwab
@ 2025-03-10 23:10 ` Alistair Francis
  2025-03-11  7:28   ` Robbin Ehn
  0 siblings, 1 reply; 3+ messages in thread
From: Alistair Francis @ 2025-03-10 23:10 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: Laurent Vivier, Palmer Dabbelt, Robbin Ehn, Alistair Francis,
	qemu-devel

On Wed, Mar 5, 2025 at 2:54 AM Andreas Schwab <schwab@suse.de> wrote:
>
> The third argument of the riscv_hwprobe syscall contains the size of the
> cpu mask in bytes, not bits.
>
> Signed-off-by: Andreas Schwab <schwab@suse.de>

Richard sent a v2 that I have applied:

https://patchew.org/QEMU/20250308225902.1208237-3-richard.henderson@linaro.org/

Alistair

> ---
>  linux-user/syscall.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index a22a5df8cc..4cc1a31d0d 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -9120,16 +9120,16 @@ static void risc_hwprobe_fill_pairs(CPURISCVState *env,
>
>  static int cpu_set_valid(abi_long arg3, abi_long arg4)
>  {
> -    int ret, i, tmp;
> +    int ret, i;
>      size_t host_mask_size, target_mask_size;
>      unsigned long *host_mask;
>
>      /*
>       * cpu_set_t represent CPU masks as bit masks of type unsigned long *.
> -     * arg3 contains the cpu count.
> +     * arg3 contains the size of the cpu mask.
>       */
> -    tmp = (8 * sizeof(abi_ulong));
> -    target_mask_size = ((arg3 + tmp - 1) / tmp) * sizeof(abi_ulong);
> +    target_mask_size = (arg3 + (sizeof(abi_ulong) - 1)) &
> +                       ~(sizeof(abi_ulong) - 1);
>      host_mask_size = (target_mask_size + (sizeof(*host_mask) - 1)) &
>                       ~(sizeof(*host_mask) - 1);
>
> --
> 2.48.1
>
>
> --
> Andreas Schwab, SUSE Labs, schwab@suse.de
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] linux-user: fix handling of cpu mask in riscv_hwprobe syscall
  2025-03-10 23:10 ` Alistair Francis
@ 2025-03-11  7:28   ` Robbin Ehn
  0 siblings, 0 replies; 3+ messages in thread
From: Robbin Ehn @ 2025-03-11  7:28 UTC (permalink / raw)
  To: Alistair Francis
  Cc: Andreas Schwab, Laurent Vivier, Palmer Dabbelt, Alistair Francis,
	qemu-devel

On Tue, Mar 11, 2025 at 12:10 AM Alistair Francis <alistair23@gmail.com> wrote:
>
> On Wed, Mar 5, 2025 at 2:54 AM Andreas Schwab <schwab@suse.de> wrote:
> >
> > The third argument of the riscv_hwprobe syscall contains the size of the
> > cpu mask in bytes, not bits.
> >
> > Signed-off-by: Andreas Schwab <schwab@suse.de>
>
> Richard sent a v2 that I have applied:
>
> https://patchew.org/QEMU/20250308225902.1208237-3-richard.henderson@linaro.org/

Hey, thanks for fixing!

Acked-by: Robbin Ehn <rehn@rivosinc.com>

>
> Alistair
>
> > ---
> >  linux-user/syscall.c | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> > index a22a5df8cc..4cc1a31d0d 100644
> > --- a/linux-user/syscall.c
> > +++ b/linux-user/syscall.c
> > @@ -9120,16 +9120,16 @@ static void risc_hwprobe_fill_pairs(CPURISCVState *env,
> >
> >  static int cpu_set_valid(abi_long arg3, abi_long arg4)
> >  {
> > -    int ret, i, tmp;
> > +    int ret, i;
> >      size_t host_mask_size, target_mask_size;
> >      unsigned long *host_mask;
> >
> >      /*
> >       * cpu_set_t represent CPU masks as bit masks of type unsigned long *.
> > -     * arg3 contains the cpu count.
> > +     * arg3 contains the size of the cpu mask.
> >       */
> > -    tmp = (8 * sizeof(abi_ulong));
> > -    target_mask_size = ((arg3 + tmp - 1) / tmp) * sizeof(abi_ulong);
> > +    target_mask_size = (arg3 + (sizeof(abi_ulong) - 1)) &
> > +                       ~(sizeof(abi_ulong) - 1);
> >      host_mask_size = (target_mask_size + (sizeof(*host_mask) - 1)) &
> >                       ~(sizeof(*host_mask) - 1);
> >
> > --
> > 2.48.1
> >
> >
> > --
> > Andreas Schwab, SUSE Labs, schwab@suse.de
> > GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> > "And now for something completely different."
> >


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-11  7:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-04 16:52 [PATCH] linux-user: fix handling of cpu mask in riscv_hwprobe syscall Andreas Schwab
2025-03-10 23:10 ` Alistair Francis
2025-03-11  7:28   ` Robbin Ehn

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).