Skip to content

Commit 36d842d

Browse files
Andrew Jonespalmer-dabbelt
authored andcommitted
RISC-V: hwprobe: Clarify cpus size parameter
The "count" parameter associated with the 'cpus' parameter of the hwprobe syscall is the size in bytes of 'cpus'. Naming it 'cpu_count' may mislead users (it did me) to think it's the number of CPUs that are or can be represented by 'cpus' instead. This is particularly easy (IMO) to get wrong since 'cpus' is documented to be defined by CPU_SET(3) and CPU_SET(3) also documents a CPU_COUNT() (the number of CPUs in set) macro. CPU_SET(3) refers to the size of cpu sets with 'setsize'. Adopt 'cpusetsize' for the hwprobe parameter and specifically state it is in bytes in Documentation/riscv/hwprobe.rst to clarify. Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> Reviewed-by: Conor Dooley <conor.dooley@microchip.com> Signed-off-by: Andrew Jones <ajones@ventanamicro.com> Link: https://lore.kernel.org/r/20231122164700.127954-7-ajones@ventanamicro.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent b85ea95 commit 36d842d

6 files changed

Lines changed: 23 additions & 30 deletions

File tree

Documentation/arch/riscv/hwprobe.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@ is defined in <asm/hwprobe.h>::
1212
};
1313

1414
long sys_riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
15-
size_t cpu_count, cpu_set_t *cpus,
15+
size_t cpusetsize, cpu_set_t *cpus,
1616
unsigned int flags);
1717

1818
The arguments are split into three groups: an array of key-value pairs, a CPU
1919
set, and some flags. The key-value pairs are supplied with a count. Userspace
2020
must prepopulate the key field for each element, and the kernel will fill in the
2121
value if the key is recognized. If a key is unknown to the kernel, its key field
2222
will be cleared to -1, and its value set to 0. The CPU set is defined by
23-
CPU_SET(3). For value-like keys (eg. vendor/arch/impl), the returned value will
24-
be only be valid if all CPUs in the given set have the same value. Otherwise -1
25-
will be returned. For boolean-like keys, the value returned will be a logical
26-
AND of the values for the specified CPUs. Usermode can supply NULL for cpus and
27-
0 for cpu_count as a shortcut for all online CPUs. There are currently no flags,
28-
this value must be zero for future compatibility.
23+
CPU_SET(3) with size ``cpusetsize`` bytes. For value-like keys (eg. vendor,
24+
arch, impl), the returned value will only be valid if all CPUs in the given set
25+
have the same value. Otherwise -1 will be returned. For boolean-like keys, the
26+
value returned will be a logical AND of the values for the specified CPUs.
27+
Usermode can supply NULL for ``cpus`` and 0 for ``cpusetsize`` as a shortcut for
28+
all online CPUs. There are currently no flags, this value must be zero for
29+
future compatibility.
2930

3031
On success 0 is returned, on failure a negative error code is returned.
3132

arch/riscv/kernel/sys_riscv.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair,
246246
}
247247

248248
static int do_riscv_hwprobe(struct riscv_hwprobe __user *pairs,
249-
size_t pair_count, size_t cpu_count,
249+
size_t pair_count, size_t cpusetsize,
250250
unsigned long __user *cpus_user,
251251
unsigned int flags)
252252
{
@@ -264,13 +264,13 @@ static int do_riscv_hwprobe(struct riscv_hwprobe __user *pairs,
264264
* 0 as a shortcut to all online CPUs.
265265
*/
266266
cpumask_clear(&cpus);
267-
if (!cpu_count && !cpus_user) {
267+
if (!cpusetsize && !cpus_user) {
268268
cpumask_copy(&cpus, cpu_online_mask);
269269
} else {
270-
if (cpu_count > cpumask_size())
271-
cpu_count = cpumask_size();
270+
if (cpusetsize > cpumask_size())
271+
cpusetsize = cpumask_size();
272272

273-
ret = copy_from_user(&cpus, cpus_user, cpu_count);
273+
ret = copy_from_user(&cpus, cpus_user, cpusetsize);
274274
if (ret)
275275
return -EFAULT;
276276

@@ -347,10 +347,10 @@ arch_initcall_sync(init_hwprobe_vdso_data);
347347
#endif /* CONFIG_MMU */
348348

349349
SYSCALL_DEFINE5(riscv_hwprobe, struct riscv_hwprobe __user *, pairs,
350-
size_t, pair_count, size_t, cpu_count, unsigned long __user *,
350+
size_t, pair_count, size_t, cpusetsize, unsigned long __user *,
351351
cpus, unsigned int, flags)
352352
{
353-
return do_riscv_hwprobe(pairs, pair_count, cpu_count,
353+
return do_riscv_hwprobe(pairs, pair_count, cpusetsize,
354354
cpus, flags);
355355
}
356356

arch/riscv/kernel/vdso/hwprobe.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
#include <vdso/helpers.h>
99

1010
extern int riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
11-
size_t cpu_count, unsigned long *cpus,
11+
size_t cpusetsize, unsigned long *cpus,
1212
unsigned int flags);
1313

1414
/* Add a prototype to avoid -Wmissing-prototypes warning. */
1515
int __vdso_riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
16-
size_t cpu_count, unsigned long *cpus,
16+
size_t cpusetsize, unsigned long *cpus,
1717
unsigned int flags);
1818

1919
int __vdso_riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
20-
size_t cpu_count, unsigned long *cpus,
20+
size_t cpusetsize, unsigned long *cpus,
2121
unsigned int flags)
2222
{
2323
const struct vdso_data *vd = __arch_get_vdso_data();
2424
const struct arch_vdso_data *avd = &vd->arch_data;
25-
bool all_cpus = !cpu_count && !cpus;
25+
bool all_cpus = !cpusetsize && !cpus;
2626
struct riscv_hwprobe *p = pairs;
2727
struct riscv_hwprobe *end = pairs + pair_count;
2828

@@ -33,7 +33,7 @@ int __vdso_riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
3333
* masks.
3434
*/
3535
if ((flags != 0) || (!all_cpus && !avd->homogeneous_cpus))
36-
return riscv_hwprobe(pairs, pair_count, cpu_count, cpus, flags);
36+
return riscv_hwprobe(pairs, pair_count, cpusetsize, cpus, flags);
3737

3838
/* This is something we can handle, fill out the pairs. */
3939
while (p < end) {

tools/testing/selftests/riscv/hwprobe/hwprobe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int main(int argc, char **argv)
4747
ksft_test_result(out != 0, "Bad CPU set\n");
4848

4949
out = riscv_hwprobe(pairs, 8, 1, 0, 0);
50-
ksft_test_result(out != 0, "NULL CPU set with non-zero count\n");
50+
ksft_test_result(out != 0, "NULL CPU set with non-zero size\n");
5151

5252
pairs[0].key = RISCV_HWPROBE_KEY_BASE_BEHAVIOR;
5353
out = riscv_hwprobe(pairs, 1, 1, &cpus, 0);

tools/testing/selftests/riscv/hwprobe/hwprobe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
* contain the call.
1111
*/
1212
long riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
13-
size_t cpu_count, unsigned long *cpus, unsigned int flags);
13+
size_t cpusetsize, unsigned long *cpus, unsigned int flags);
1414

1515
#endif

tools/testing/selftests/riscv/vector/vstate_prctl.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
#include <sys/prctl.h>
33
#include <unistd.h>
4-
#include <asm/hwprobe.h>
54
#include <errno.h>
65
#include <sys/wait.h>
76

7+
#include "../hwprobe/hwprobe.h"
88
#include "../../kselftest.h"
99

10-
/*
11-
* Rather than relying on having a new enough libc to define this, just do it
12-
* ourselves. This way we don't need to be coupled to a new-enough libc to
13-
* contain the call.
14-
*/
15-
long riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
16-
size_t cpu_count, unsigned long *cpus, unsigned int flags);
17-
1810
#define NEXT_PROGRAM "./vstate_exec_nolibc"
1911
static int launch_test(int test_inherit)
2012
{

0 commit comments

Comments
 (0)