Skip to content

Commit c9b8cd1

Browse files
clementlegerpalmer-dabbelt
authored andcommitted
riscv: hwprobe: export highest virtual userspace address
Some userspace applications (OpenJDK for instance) uses the free MSBs in pointers to insert additional information for their own logic and need to get this information from somewhere. Currently they rely on parsing /proc/cpuinfo "mmu=svxx" string to obtain the current value of virtual address usable bits [1]. Since this reflect the raw supported MMU mode, it might differ from the logical one used internally which is why arch_get_mmap_end() is used. Exporting the highest mmapable address through hwprobe will allow a more stable interface to be used. For that purpose, add a new hwprobe key named RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS which will export the highest userspace virtual address. Link: https://github.com/openjdk/jdk/blob/master/src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp#L171 [1] Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Charlie Jenkins <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 16badac commit c9b8cd1

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

Documentation/arch/riscv/hwprobe.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,6 @@ The following keys are defined:
257257

258258
* :c:macro:`RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE`: An unsigned int which
259259
represents the size of the Zicboz block in bytes.
260+
261+
* :c:macro:`RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS`: An unsigned long which
262+
represent the highest userspace virtual address usable.

arch/riscv/include/asm/hwprobe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <uapi/asm/hwprobe.h>
1010

11-
#define RISCV_HWPROBE_MAX_KEY 6
11+
#define RISCV_HWPROBE_MAX_KEY 7
1212

1313
static inline bool riscv_hwprobe_key_is_valid(__s64 key)
1414
{

arch/riscv/include/asm/processor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757

5858
#define STACK_TOP DEFAULT_MAP_WINDOW
5959

60+
#ifdef CONFIG_MMU
61+
#define user_max_virt_addr() arch_get_mmap_end(ULONG_MAX, 0, 0)
62+
#else
63+
#define user_max_virt_addr() 0
64+
#endif /* CONFIG_MMU */
65+
6066
/*
6167
* This decides where the kernel will search for a free chunk of vm
6268
* space during mmap's.

arch/riscv/include/uapi/asm/hwprobe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct riscv_hwprobe {
7979
#define RISCV_HWPROBE_MISALIGNED_UNSUPPORTED (4 << 0)
8080
#define RISCV_HWPROBE_MISALIGNED_MASK (7 << 0)
8181
#define RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE 6
82+
#define RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS 7
8283
/* Increase RISCV_HWPROBE_MAX_KEY when adding items. */
8384

8485
/* Flags */

arch/riscv/kernel/sys_hwprobe.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <asm/cacheflush.h>
99
#include <asm/cpufeature.h>
1010
#include <asm/hwprobe.h>
11+
#include <asm/processor.h>
1112
#include <asm/sbi.h>
1213
#include <asm/switch_to.h>
1314
#include <asm/uaccess.h>
@@ -231,6 +232,9 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair,
231232
if (hwprobe_ext0_has(cpus, RISCV_HWPROBE_EXT_ZICBOZ))
232233
pair->value = riscv_cboz_block_size;
233234
break;
235+
case RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS:
236+
pair->value = user_max_virt_addr();
237+
break;
234238

235239
/*
236240
* For forward compatibility, unknown keys don't fail the whole

0 commit comments

Comments
 (0)