riscv: hwprobe: export largest userspace address
Subsystems (2)
PATCH v2 1/1 riscv: hwprobe: export largest 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 used bits [1]. Since this reflect the raw MMU mode supported, it might differ from the logical one used internally. Exporting the maximum mmappable address through hwprobe will allow a more stable interface to be used. For that purpose, add a new hwprobe key named RISCV_HWPROBE_MAX_KEY which will export the maximum mmappable userspace address.
---
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/uapi/asm/hwprobe.h | 1 + arch/riscv/kernel/sys_hwprobe.c | 4 ++++ 4 files changed, 9 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_MAX_USER_ADDRESS`: An unsigned long which + represent the maximum userspace mmappable address.
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/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_MAX_USER_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>
@@ -202,6 +203,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_MAX_USER_ADDRESS : + pair->value =arch_get_mmap_end (ULONG_MAX ,0 ,0 ); +break ;/* * For forward compatibility, unknown keys don't fail the whole
Signature · 1 line
2.43.0
Quoted 11 lines · Clément Léger
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 used bits [1]. Since this reflect the raw MMU mode supported, it might differ from the logical one used internally. Exporting the maximum mmappable address through hwprobe will allow a more stable interface to be used. For that purpose, add a new hwprobe key namedRISCV_HWPROBE_MAX_KEYwhich will export the maximum mmappable userspace address.
Quoted 4 lines
[1]Signed-off-by Clément Léger <[email protected]>
Ideally, we'd have something arch-independent, but this is a good interface and simple enough to support in perpetuity.
-s
Quoted 85 lines
---
v2:
- Note: tried sysconf to export it but this is not backed by syscall and thus does not allow exporting such information easily.
- Usearch_get_mmap_end()instead ofVA_BITSsince it reflects the maximum logical address used by the riscv port
- Change hwprobe key name fromRISCV_HWPROBE_KEY_VA_BITStoRISCV_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/uapi/asm/hwprobe.h | 1 + arch/riscv/kernel/sys_hwprobe.c | 4 ++++ 4 files changed, 9 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_MAX_USER_ADDRESS`: An unsigned long which + represent the maximum userspace mmappable address.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/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_MAX_USER_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> @@ -202,6 +203,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_MAX_USER_ADDRESS : + pair->value =arch_get_mmap_end (ULONG_MAX ,0 ,0 ); +break ;/* * For forward compatibility, unknown keys don't fail the whole Signature · 7 lines
2.43.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 17 lines · Stefan O'Rear
Quoted 11 lines · Clément Léger
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 used bits [1]. Since this reflect the raw MMU mode supported, it might differ from the logical one used internally. Exporting the maximum mmappable address through hwprobe will allow a more stable interface to be used. For that purpose, add a new hwprobe key namedRISCV_HWPROBE_MAX_KEYwhich will export the maximum mmappable userspace address.Quoted 4 lines
[1]Signed-off-by Clément Léger <[email protected]>
Quoted 4 lines
Reviewed-by Stefan O'Rear <[email protected]>Ideally, we'd have something arch-independent, but this is a good interface and simple enough to support in perpetuity.
Hi Stefan,
Indeed while not architecture specific, I did not found anything relevant in which this information could easily fit. sysconf is actually mainly compile time constants returned by the libc. And the few non POSIX sysconf defines (_SC_xx) are actually using either /proc parsing or the sysinfo syscall which did not changed since kernel 2.3. But maybe someone out there knows something better suited to export this information.
Thanks,
Clément
Quoted 88 lines
-s
Quoted 85 lines
---
v2:
- Note: tried sysconf to export it but this is not backed by syscall and thus does not allow exporting such information easily.
- Usearch_get_mmap_end()instead ofVA_BITSsince it reflects the maximum logical address used by the riscv port
- Change hwprobe key name fromRISCV_HWPROBE_KEY_VA_BITStoRISCV_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/uapi/asm/hwprobe.h | 1 + arch/riscv/kernel/sys_hwprobe.c | 4 ++++ 4 files changed, 9 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_MAX_USER_ADDRESS`: An unsigned long which + represent the maximum userspace mmappable address.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/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_MAX_USER_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> @@ -202,6 +203,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_MAX_USER_ADDRESS : + pair->value =arch_get_mmap_end (ULONG_MAX ,0 ,0 ); +break ;/* * For forward compatibility, unknown keys don't fail the whole Signature · 7 lines
2.43.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 11 lines · Clément Léger
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 used bits [1]. Since this reflect the raw MMU mode supported, it might differ from the logical one used internally. Exporting the maximum mmappable address through hwprobe will allow a more stable interface to be used. For that purpose, add a new hwprobe key namedRISCV_HWPROBE_MAX_KEYwhich will export the maximum mmappable userspace address.
Quoted 2 lines
Doesn't build for nommu:
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/
Cheers,
Conor.