From: Andrew Jones <ajones@ventanamicro.com>
To: linux-riscv@lists.infradead.org
Cc: paul.walmsley@sifive.com, palmer@dabbelt.com,
aou@eecs.berkeley.edu, evan@rivosinc.com,
conor.dooley@microchip.com, apatel@ventanamicro.com
Subject: Re: [PATCH v1 3/6] RISC-V: hwprobe: Introduce which-cpus flag
Date: Thu, 19 Oct 2023 19:16:48 +0200 [thread overview]
Message-ID: <20231019-ff7817229eb2cc818ea08fe5@orel> (raw)
In-Reply-To: <20231011135610.122850-11-ajones@ventanamicro.com>
On Wed, Oct 11, 2023 at 03:56:14PM +0200, Andrew Jones wrote:
...
> diff --git a/arch/riscv/kernel/vdso/hwprobe.c b/arch/riscv/kernel/vdso/hwprobe.c
> index 026b7645c5ab..e6c324d64544 100644
> --- a/arch/riscv/kernel/vdso/hwprobe.c
> +++ b/arch/riscv/kernel/vdso/hwprobe.c
> @@ -3,6 +3,7 @@
> * Copyright 2023 Rivos, Inc
> */
>
> +#include <linux/string.h>
> #include <linux/types.h>
> #include <vdso/datapage.h>
> #include <vdso/helpers.h>
> @@ -11,14 +12,9 @@ extern int riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
> size_t cpusetsize, unsigned long *cpus,
> unsigned int flags);
>
> -/* Add a prototype to avoid -Wmissing-prototypes warning. */
> -int __vdso_riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
> - size_t cpusetsize, unsigned long *cpus,
> - unsigned int flags);
> -
> -int __vdso_riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
> - size_t cpusetsize, unsigned long *cpus,
> - unsigned int flags)
> +static int riscv_vdso_get_values(struct riscv_hwprobe *pairs, size_t pair_count,
> + size_t cpusetsize, unsigned long *cpus,
> + unsigned int flags)
> {
> const struct vdso_data *vd = __arch_get_vdso_data();
> const struct arch_vdso_data *avd = &vd->arch_data;
> @@ -50,3 +46,59 @@ int __vdso_riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
>
> return 0;
> }
> +
> +static int riscv_vdso_get_cpus(struct riscv_hwprobe *pairs, size_t pair_count,
> + size_t cpusetsize, unsigned long *cpus,
> + unsigned int flags)
> +{
> + const struct vdso_data *vd = __arch_get_vdso_data();
> + const struct arch_vdso_data *avd = &vd->arch_data;
> + struct riscv_hwprobe *p = pairs;
> + struct riscv_hwprobe *end = pairs + pair_count;
> + bool clear_all = false;
> +
> + if (!cpusetsize || !cpus)
> + return -EINVAL;
> +
> + if (flags != RISCV_HWPROBE_WHICH_CPUS || !avd->homogeneous_cpus)
> + return riscv_hwprobe(pairs, pair_count, cpusetsize, cpus, flags);
> +
> + while (p < end) {
> + if (riscv_hwprobe_key_is_valid(p->key)) {
> + struct riscv_hwprobe t = {
> + .key = p->key,
> + .value = avd->all_cpu_hwprobe_values[p->key],
> + };
> +
> + if (!riscv_hwprobe_pair_cmp(&t, p))
> + clear_all = true;
> + } else {
> + clear_all = true;
> + p->key = -1;
> + p->value = 0;
> + }
> + p++;
> + }
> +
> + if (clear_all)
> + memset(cpus, 0, cpusetsize);
This memset will go away in v2. It wasn't very smart of me to put it there
in the first place as there's no memset available to vdso code, which
means it would segfault when attempting to use it. My initial testing
failed to find this, because I had forgotten that avd->homogeneous_cpus
would be false on a default QEMU machine since it doesn't set mvendorid to
anything. I actually found this problem when trying to add a memcmp which
wasn't skipped with !avd->homogeneous_cpus, and that promptly segfaulted.
(I won't be adding that memcmp either :-)
Thanks,
drew
> +
> + return 0;
> +}
> +
> +/* Add a prototype to avoid -Wmissing-prototypes warning. */
> +int __vdso_riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
> + size_t cpusetsize, unsigned long *cpus,
> + unsigned int flags);
> +
> +int __vdso_riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
> + size_t cpusetsize, unsigned long *cpus,
> + unsigned int flags)
> +{
> + if (flags & RISCV_HWPROBE_WHICH_CPUS)
> + return riscv_vdso_get_cpus(pairs, pair_count, cpusetsize,
> + cpus, flags);
> +
> + return riscv_vdso_get_values(pairs, pair_count, cpusetsize,
> + cpus, flags);
> +}
> --
> 2.41.0
>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2023-10-19 17:17 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-11 13:56 [PATCH v1 0/6] RISC-V: hwprobe: Introduce which-cpus Andrew Jones
2023-10-11 13:56 ` [PATCH v1 1/6] RISC-V: hwprobe: Clarify cpus size parameter Andrew Jones
2023-10-12 13:38 ` Conor Dooley
2023-10-11 13:56 ` [PATCH v1 2/6] RISC-V: Move the hwprobe syscall to its own file Andrew Jones
2023-10-12 13:45 ` Conor Dooley
2023-10-12 16:11 ` Andrew Jones
2023-10-12 16:42 ` Evan Green
2023-10-12 17:02 ` Conor Dooley
2023-10-13 6:45 ` Andrew Jones
2023-10-13 7:39 ` Conor Dooley
2023-10-13 15:26 ` Evan Green
2023-10-11 13:56 ` [PATCH v1 3/6] RISC-V: hwprobe: Introduce which-cpus flag Andrew Jones
2023-10-12 17:40 ` Evan Green
2023-10-13 7:20 ` Andrew Jones
2023-10-19 17:16 ` Andrew Jones [this message]
2023-10-11 13:56 ` [PATCH v1 4/6] RISC-V: selftests: Statically link hwprobe test Andrew Jones
2023-10-11 13:56 ` [PATCH v1 5/6] RISC-V: selftests: Convert hwprobe test to kselftest API Andrew Jones
2023-10-11 13:56 ` [PATCH v1 6/6] RISC-V: selftests: Add which-cpus hwprobe test Andrew Jones
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=20231019-ff7817229eb2cc818ea08fe5@orel \
--to=ajones@ventanamicro.com \
--cc=aou@eecs.berkeley.edu \
--cc=apatel@ventanamicro.com \
--cc=conor.dooley@microchip.com \
--cc=evan@rivosinc.com \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.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