riscv: hwprobe: export highest virtual userspace address
Subsystems (2)
PATCH v5 1/1 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.
---
Testing:
This new hwprobe key can be tested using qemu and a simple hwprobe dump tool:
https://github.com/clementleger/hwprobe_dump/tree/dev/cleger/highest_virt
v5:
- Rebased on master to fix merge conflicts
- Link to v4: https://lore.kernel.org/lkml/[email protected]/
v4:
- Added Charlie Reviewed-by
- Replace a tab instead of a space
- Resend with actual V4 tag in front of message which was missing
- Link to v3: https://lore.kernel.org/lkml/[email protected]/
v3:
- Note: I did not added Stefan Reviewed-by since I did more
modifications than just a simple respin.
- Handle CONFIG_MMU=n as well and rename the key to RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS
- Add a user_max_virt_addr() macro to handle !MMU config
- Link to v2: https://lore.kernel.org/lkml/[email protected]/
v2:
- Note: tried sysconf to export it but this is not backed by syscall
and thus does not allow exporting such information easily.
- Use arch_get_mmap_end() instead of VA_BITS since it reflects the maximum logical address used by the riscv port
- Change hwprobe key name from RISCV_HWPROBE_KEY_VA_BITS to RISCV_HWPROBE_KEY_MAX_ADDRESS
- Link to v1: https://lore.kernel.org/lkml/[email protected]/
--- Documentation/arch/riscv/hwprobe.rst | 3 +++ arch/riscv/include/asm/hwprobe.h | 2 +- arch/riscv/include/asm/processor.h | 6 ++++++ arch/riscv/include/uapi/asm/hwprobe.h | 1 + arch/riscv/kernel/sys_hwprobe.c | 4 ++++ 5 files changed, 15 insertions(+), 1 deletion(-)
Documentation/arch/riscv/hwprobe.rst +3 -0
@@ -210,3 +210,6 @@ The following keys are defined: * :c:macro:`RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE`: An unsigned int which represents the size of the Zicboz block in bytes. + +* :c:macro:`RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS`: An unsigned long which + represent the highest userspace virtual address usable.
arch/riscv/include/asm/hwprobe.h +1 -1
@@ -8,7 +8,7 @@#include <uapi/asm/hwprobe.h> -#define RISCV_HWPROBE_MAX_KEY 6 +#define RISCV_HWPROBE_MAX_KEY 7static inline bool riscv_hwprobe_key_is_valid (__s64 key) {
arch/riscv/include/asm/processor.h +6 -0
@@ -57,6 +57,12 @@#define STACK_TOP DEFAULT_MAP_WINDOW +#ifdef CONFIG_MMU +#define user_max_virt_addr () arch_get_mmap_end(ULONG_MAX, 0, 0) +#else +#define user_max_virt_addr () 0 +#endif /* CONFIG_MMU */ +/* * This decides where the kernel will search for a free chunk of vm * space during mmap's.
arch/riscv/include/uapi/asm/hwprobe.h +1 -0
@@ -67,6 +67,7 @@ struct riscv_hwprobe {#define RISCV_HWPROBE_MISALIGNED_UNSUPPORTED (4 << 0)#define RISCV_HWPROBE_MISALIGNED_MASK (7 << 0)#define RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE 6 +#define RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS 7/* Increase RISCV_HWPROBE_MAX_KEY when adding items. */ /* Flags */
arch/riscv/kernel/sys_hwprobe.c +4 -0
@@ -8,6 +8,7 @@#include <asm/cacheflush.h> #include <asm/cpufeature.h> #include <asm/hwprobe.h> +#include <asm/processor.h> #include <asm/sbi.h> #include <asm/switch_to.h> #include <asm/uaccess.h>
@@ -215,6 +216,9 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair,if (hwprobe_ext0_has (cpus,RISCV_HWPROBE_EXT_ZICBOZ )) pair->value = riscv_cboz_block_size;break ; +case RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS : + pair->value =user_max_virt_addr (); +break ;/* * For forward compatibility, unknown keys don't fail the whole
Signature · 1 line
2.43.0
This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:
Hello:
This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:
Quoted 12 lines · On Wed, 10 Apr 2024 16:45:57 +0200 you wrote:
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 whyarch_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 namedRISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESSwhich will export the highest userspace virtual address.
Quoted 1 line
[...]
Here is the summary with links:
- [v5] riscv: hwprobe: export highest virtual userspace address
https://git.kernel.org/riscv/c/c9b8cd139c1d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html