riscv: Userspace pointer masking and tagged address ABI
Subsystems (5)
cover riscv: Userspace pointer masking and tagged address ABI
RISC-V defines three extensions for pointer masking[1]:
- Smmpm: configured in M-mode, affects M-mode
- Smnpm: configured in M-mode, affects the next lower mode (S or U-mode)
- Ssnpm: configured in S-mode, affects the next lower mode (U-mode)
This series adds support for configuring Smnpm or Ssnpm (depending on which mode the kernel is running in) to allow pointer masking in userspace by extending the existing PR_SET_TAGGED_ADDR_CTRL API from arm64. Unlike arm64 TBI, userspace pointer masking is not enabled by default on RISC-V. Additionally, the tag width (referred to as PMLEN) is variable, so userspace needs to ask the kernel for a specific tag width (which is interpreted as a minimum number of tag bits).
This series also adds support for a tagged address ABI similar to arm64. Since accesses from the kernel to user memory use the kernel's pointer masking configuration, not the user's, the kernel must untag user pointers in software before dereferencing them.
This series can be tested in QEMU by applying a patch set[2].
KASAN support is not included here because there is not yet any standard way for the kernel to ask firmware to enable pointer masking in S-mode.
[1]: https://github.com/riscv/riscv-j-extension/raw/a1e68469c60/zjpm-spec.pdf
[2]: https://patchwork.kernel.org/project/qemu-devel/list/?series=822467&archive=both
Samuel Holland (9):
dt-bindings: riscv: Add pointer masking ISA extensions
riscv: Add ISA extension parsing for pointer masking
riscv: Add CSR definitions for pointer masking
riscv: Define is_compat_thread()
riscv: Split per-CPU and per-thread envcfg bits
riscv: Add support for userspace pointer masking
riscv: Add support for the tagged address ABI
riscv: Allow ptrace control of the tagged address ABI
selftests: riscv: Add a pointer masking test
.../devicetree/bindings/riscv/extensions.yaml | 18 + arch/riscv/Kconfig | 8 + arch/riscv/include/asm/compat.h | 16 + arch/riscv/include/asm/cpufeature.h | 2 + arch/riscv/include/asm/csr.h | 16 + arch/riscv/include/asm/hwcap.h | 5 + arch/riscv/include/asm/processor.h | 10 + arch/riscv/include/asm/switch_to.h | 12 + arch/riscv/include/asm/uaccess.h | 40 ++- arch/riscv/kernel/cpufeature.c | 7 +- arch/riscv/kernel/process.c | 154 +++++++++ arch/riscv/kernel/ptrace.c | 42 +++ include/uapi/linux/elf.h | 1 + include/uapi/linux/prctl.h | 3 + tools/testing/selftests/riscv/Makefile | 2 +- tools/testing/selftests/riscv/tags/Makefile | 10 + .../selftests/riscv/tags/pointer_masking.c | 307 ++++++++++++++++++ 17 files changed, 646 insertions(+), 7 deletions(-) create mode 100644 tools/testing/selftests/riscv/tags/Makefile create mode 100644 tools/testing/selftests/riscv/tags/pointer_masking.c
Signature · 1 line
2.43.1
RFC PATCH 1/9 dt-bindings: riscv: Add pointer masking ISA extensions
The RISC-V Pointer Masking specification defines three extensions:
Smmpm, Smnpm, and Ssnpm. Document the behavior as of the current draft of the specification, which is version 0.8.4.
---
.../devicetree/bindings/riscv/extensions.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
Documentation/devicetree/bindings/riscv/extensions.yaml +18 -0
@@ -128,6 +128,18 @@ properties: changes to interrupts as frozen at commit ccbddab ("Merge pull request #42 from riscv/jhauser-2023-RC4") of riscv-aia. + - const: smmpm + description: | + The standard Smmpm extension for M-mode pointer masking as defined + at commit a1e68469c60 ("Minor correction to pointer masking spec.") + of riscv-j-extension. + + - const: smnpm + description: | + The standard Smnpm extension for next-mode pointer masking as defined + at commit a1e68469c60 ("Minor correction to pointer masking spec.") + of riscv-j-extension. + - const: smstateen description: | The standard Smstateen extension for controlling access to CSRs
@@ -147,6 +159,12 @@ properties: and mode-based filtering as ratified at commit 01d1df0 ("Add ability to manually trigger workflow. (#2)") of riscv-count-overflow. + - const: ssnpm + description: | + The standard Ssnpm extension for next-mode pointer masking as defined + at commit a1e68469c60 ("Minor correction to pointer masking spec.") + of riscv-j-extension. + - const: sstc description: | The standard Sstc supervisor-level extension for time compare as
Signature · 1 line
2.43.1
RFC PATCH 2/9 riscv: Add ISA extension parsing for pointer masking
In reply to Samuel HollandThe RISC-V Pointer Masking specification defines three extensions:
Smmpm, Smnpm, and Ssnpm. Add support for parsing each of them.
Smmpm implies the existence of the mseccfg CSR. As it is the only user of this CSR so far, there is no need for an Xlinuxmseccfg extension.
---
arch/riscv/include/asm/hwcap.h | 5 +++++ arch/riscv/kernel/cpufeature.c | 3 +++ 2 files changed, 8 insertions(+)
arch/riscv/include/asm/hwcap.h +5 -0
@@ -80,6 +80,9 @@#define RISCV_ISA_EXT_ZFA 71#define RISCV_ISA_EXT_ZTSO 72#define RISCV_ISA_EXT_ZACAS 73 +#define RISCV_ISA_EXT_SMMPM 74 +#define RISCV_ISA_EXT_SMNPM 75 +#define RISCV_ISA_EXT_SSNPM 76#define RISCV_ISA_EXT_XLINUXENVCFG 127
@@ -88,8 +91,10 @@#ifdef CONFIG_RISCV_M_MODE #define RISCV_ISA_EXT_SxAIA RISCV_ISA_EXT_SMAIA +#define RISCV_ISA_EXT_SxNPM RISCV_ISA_EXT_SMNPM#else #define RISCV_ISA_EXT_SxAIA RISCV_ISA_EXT_SSAIA +#define RISCV_ISA_EXT_SxNPM RISCV_ISA_EXT_SSNPM#endif #endif /* _ASM_RISCV_HWCAP_H */
arch/riscv/kernel/cpufeature.c +3 -0
@@ -311,9 +311,12 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {__RISCV_ISA_EXT_BUNDLE (zvksg, riscv_zvksg_bundled_exts),__RISCV_ISA_EXT_DATA (zvkt,RISCV_ISA_EXT_ZVKT ),__RISCV_ISA_EXT_DATA (smaia,RISCV_ISA_EXT_SMAIA ), +__RISCV_ISA_EXT_DATA (smmpm,RISCV_ISA_EXT_SMMPM ), +__RISCV_ISA_EXT_SUPERSET (smnpm,RISCV_ISA_EXT_SMNPM , riscv_xlinuxenvcfg_exts),__RISCV_ISA_EXT_DATA (smstateen,RISCV_ISA_EXT_SMSTATEEN ),__RISCV_ISA_EXT_DATA (ssaia,RISCV_ISA_EXT_SSAIA ),__RISCV_ISA_EXT_DATA (sscofpmf,RISCV_ISA_EXT_SSCOFPMF ), +__RISCV_ISA_EXT_SUPERSET (ssnpm,RISCV_ISA_EXT_SSNPM , riscv_xlinuxenvcfg_exts),__RISCV_ISA_EXT_DATA (sstc,RISCV_ISA_EXT_SSTC ),__RISCV_ISA_EXT_DATA (svinval,RISCV_ISA_EXT_SVINVAL ), __RISCV_ISA_EXT_DATA(svnapot, RISCV_ISA_EXT_SVNAPOT),
Signature · 1 line
2.43.1
RFC PATCH 3/9 riscv: Add CSR definitions for pointer masking
In reply to Samuel HollandPointer masking is controlled via a two-bit PMM field, which appears in various CSRs depending on which extensions are implemented. Smmpm defines the field in mseccfg; Smnpm defines the field in menvcfg; Ssnpm defines the field in senvcfg and (if present) henvcfg and hstatus.
---
arch/riscv/include/asm/csr.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
arch/riscv/include/asm/csr.h +16 -0
@@ -119,6 +119,10 @@/* HSTATUS flags */ #ifdef CONFIG_64BIT +#define HSTATUS_PMM _AC(0x3000000000000, UL) +#define HSTATUS_PMM_PMLEN_0 _AC(0x0000000000000, UL) +#define HSTATUS_PMM_PMLEN_7 _AC(0x2000000000000, UL) +#define HSTATUS_PMM_PMLEN_16 _AC(0x3000000000000, UL)#define HSTATUS_VSXL _AC(0x300000000, UL)#define HSTATUS_VSXL_SHIFT 32#endif
@@ -194,6 +198,10 @@/* xENVCFG flags */ #define ENVCFG_STCE (_AC(1, ULL) << 63)#define ENVCFG_PBMTE (_AC(1, ULL) << 62) +#define ENVCFG_PMM _AC(0x300000000, ULL) +#define ENVCFG_PMM_PMLEN_0 _AC(0x000000000, ULL) +#define ENVCFG_PMM_PMLEN_7 _AC(0x200000000, ULL) +#define ENVCFG_PMM_PMLEN_16 _AC(0x300000000, ULL)#define ENVCFG_CBZE (_AC(1, UL) << 7)#define ENVCFG_CBCFE (_AC(1, UL) << 6)#define ENVCFG_CBIE_SHIFT 4
@@ -215,6 +223,12 @@#define SMSTATEEN0_SSTATEEN0_SHIFT 63#define SMSTATEEN0_SSTATEEN0 (_ULL(1) << SMSTATEEN0_SSTATEEN0_SHIFT) +/* mseccfg bits */ +#define MSECCFG_PMM ENVCFG_PMM +#define MSECCFG_PMM_PMLEN_0 ENVCFG_PMM_PMLEN_0 +#define MSECCFG_PMM_PMLEN_7 ENVCFG_PMM_PMLEN_7 +#define MSECCFG_PMM_PMLEN_16 ENVCFG_PMM_PMLEN_16 +/* symbolic CSR names: */ #define CSR_CYCLE 0xc00#define CSR_TIME 0xc01
@@ -381,6 +395,8 @@#define CSR_MIP 0x344#define CSR_PMPCFG0 0x3a0#define CSR_PMPADDR0 0x3b0 +#define CSR_MSECCFG 0x747 +#define CSR_MSECCFGH 0x757#define CSR_MVENDORID 0xf11#define CSR_MARCHID 0xf12#define CSR_MIMPID 0xf13
Signature · 1 line
2.43.1
RFC PATCH 4/9 riscv: Define is_compat_thread()
In reply to Samuel HollandThis allows checking if some thread other than current is 32-bit.
---
arch/riscv/include/asm/compat.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
arch/riscv/include/asm/compat.h +16 -0
@@ -12,11 +12,18 @@#include <linux/sched/task_stack.h> #include <asm-generic/compat.h> +#ifdef CONFIG_COMPAT + static inline int is_compat_task(void) { return test_thread_flag(TIF_32BIT); } +static inline int is_compat_thread(struct thread_info *thread) +{ + return test_ti_thread_flag(thread, TIF_32BIT); +} + struct compat_user_regs_struct { compat_ulong_t pc; compat_ulong_t ra;
@@ -126,4 +133,13 @@ static inline void cregs_to_regs(struct compat_user_regs_struct *cregs, regs->t6 = (unsigned long ) cregs->t6; }; +#else + +static inline int is_compat_thread (struct thread_info *thread) +{ +return 0 ; +} + +#endif +#endif /* __ASM_COMPAT_H */
Signature · 1 line
2.43.1
RFC PATCH 5/9 riscv: Split per-CPU and per-thread envcfg bits
In reply to Samuel HollandSome envcfg bits need to be controlled on a per-thread basis, such as the pointer masking mode. However, the envcfg CSR value cannot simply be stored in struct thread_struct, because some hardware may implement a different subset of envcfg CSR bits is across CPUs. As a result, we need to combine the per-CPU and per-thread bits whenever we switch threads.
---
arch/riscv/include/asm/cpufeature.h | 2 ++ arch/riscv/include/asm/processor.h | 1 + arch/riscv/include/asm/switch_to.h | 12 ++++++++++++ arch/riscv/kernel/cpufeature.c | 4 +++- 4 files changed, 18 insertions(+), 1 deletion(-)
arch/riscv/include/asm/cpufeature.h +2 -0
@@ -33,6 +33,8 @@ DECLARE_PER_CPU(long, misaligned_access_speed);/* Per-cpu ISA extensions. */ extern struct riscv_isainfo hart_isa[NR_CPUS ]; +DECLARE_PER_CPU(unsigned long, riscv_cpu_envcfg); +void riscv_user_isa_enable (void );#ifdef CONFIG_RISCV_MISALIGNED
arch/riscv/include/asm/processor.h +1 -0
@@ -118,6 +118,7 @@ struct thread_struct {unsigned long s[12 ];/* s[0]: frame pointer */ struct __riscv_d_ext_state fstate;unsigned long bad_cause; +unsigned long envcfg;u32 riscv_v_flags;u32 vstate_ctrl;struct __riscv_v_ext_state vstate;
arch/riscv/include/asm/switch_to.h +12 -0
@@ -69,6 +69,17 @@ static __always_inline bool has_fpu(void) { return false; }#define __switch_to_fpu (__prev, __next) do { } while (0)#endif +static inline void sync_envcfg (struct task_struct *task) +{ +csr_write (CSR_ENVCFG ,this_cpu_read (riscv_cpu_envcfg) | task->thread.envcfg); +} + +static inline void __switch_to_envcfg (struct task_struct *next) +{ +if (riscv_cpu_has_extension_unlikely (smp_processor_id (),RISCV_ISA_EXT_XLINUXENVCFG )) +sync_envcfg (next); +} +extern struct task_struct *__switch_to (struct task_struct *,struct task_struct *);
@@ -80,6 +91,7 @@ do { \__switch_to_fpu (__prev, __next); \if (has_vector ()) \__switch_to_vector (__prev, __next); \ +__switch_to_envcfg (__next); \ ((last) =__switch_to (__prev, __next)); \ }while (0 )
arch/riscv/kernel/cpufeature.c +3 -1
@@ -44,6 +44,8 @@ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;/* Per-cpu ISA extensions. */ struct riscv_isainfo hart_isa[NR_CPUS ]; +DEFINE_PER_CPU(unsigned long, riscv_cpu_envcfg); +/* Performance information */ DEFINE_PER_CPU (long, misaligned_access_speed);
@@ -978,7 +980,7 @@ arch_initcall(check_unaligned_access_all_cpus);void riscv_user_isa_enable (void ) {if (riscv_cpu_has_extension_unlikely (smp_processor_id (),RISCV_ISA_EXT_ZICBOZ )) -csr_set (CSR_ENVCFG ,ENVCFG_CBZE ); +this_cpu_or (riscv_cpu_envcfg,ENVCFG_CBZE ); }#ifdef CONFIG_RISCV_ALTERNATIVE
Signature · 1 line
2.43.1
Re: [RISC-V] [tech-j-ext] [RFC PATCH 5/9] riscv: Split per-CPU and per-thread envcfg bits
Quoted 7 lines · Samuel Holland via lists.riscv.org
Some envcfg bits need to be controlled on a per-thread basis, such as the pointer masking mode. However, the envcfg CSR value cannot simply be stored in struct
thread_struct, because some hardware may implement a different subset of envcfg CSR bits is across CPUs. As a result, we need to combine the per-CPU and per-thread bits whenever we switch threads.
Why not do something like this
arch/riscv/include/asm/csr.h +2 -0
@@ -202,6 +202,8 @@#define ENVCFG_CBIE_FLUSH _AC(0x1, UL)#define ENVCFG_CBIE_INV _AC(0x3, UL)#define ENVCFG_FIOM _AC(0x1, UL) +/* by default all threads should be able to zero cache */ +#define ENVCFG_BASE ENVCFG_CBZE/* Smstateen bits */ #define SMSTATEEN0_AIA_IMSIC_SHIFT 58
arch/riscv/kernel/process.c +1 -0
@@ -152,6 +152,7 @@ void start_thread(struct pt_regs *regs, unsigned long pc, else regs->status |= SR_UXL_64;#endif + current->thread_info.envcfg =ENVCFG_BASE ; }
And instead of context switching in _switch_to,
In entry.S pick up envcfg from thread_info and write it into CSR.
This construction avoids
- declaring per cpu riscv_cpu_envcfg
- syncing up
- collection of *envcfg bits.
Quoted 40 lines
Signed-off-by Samuel Holland <[email protected]>---
arch/riscv/include/asm/cpufeature.h | 2 ++ arch/riscv/include/asm/processor.h | 1 + arch/riscv/include/asm/switch_to.h | 12 ++++++++++++ arch/riscv/kernel/cpufeature.c | 4 +++- 4 files changed, 18 insertions(+), 1 deletion(-)arch/riscv/include/asm/cpufeature.h +2
-0@@ -33,6 +33,8 @@ DECLARE_PER_CPU(long, misaligned_access_speed);/* Per-cpu ISA extensions. */ extern struct riscv_isainfo hart_isa[NR_CPUS ]; +DECLARE_PER_CPU(unsigned long, riscv_cpu_envcfg); +void riscv_user_isa_enable (void );#ifdef CONFIG_RISCV_MISALIGNED arch/riscv/include/asm/processor.h +1
-0@@ -118,6 +118,7 @@ struct thread_struct {unsigned long s[12 ];/* s[0]: frame pointer */ struct __riscv_d_ext_state fstate;unsigned long bad_cause; +unsigned long envcfg;u32 riscv_v_flags;u32 vstate_ctrl;struct __riscv_v_ext_state vstate;arch/riscv/include/asm/switch_to.h +0
-0@@ -69,6 +69,17 @@ static __always_inline bool has_fpu(void) { return false; }#define __switch_to_fpu (__prev, __next) do { } while (0)
arch/riscv/include/asm/switch_to.h static __always_inline bool has_fpu(void) { return false; } · line 79
Quoted 10 lines
arch/riscv/include/asm/switch_to.h +8
-0#endif +static inline void sync_envcfg (struct task_struct *task) +{ +csr_write (CSR_ENVCFG ,this_cpu_read (riscv_cpu_envcfg) | task->thread.envcfg); +} + +static inline void __switch_to_envcfg (struct task_struct *next) +{ +if (riscv_cpu_has_extension_unlikely (smp_processor_id (),RISCV_ISA_EXT_XLINUXENVCFG ))
I've seen riscv_cpu_has_extension_unlikely generating branchy code even if ALTERNATIVES was turned on.
Can you check disasm on your end as well. IMHO, entry.S is a better place to pick up *envcfg.
Quoted 50 lines
arch/riscv/include/asm/switch_to.h +4
-0+sync_envcfg (next); +} +extern struct task_struct *__switch_to (struct task_struct *,struct task_struct *);@@ -80,6 +91,7 @@ do { \__switch_to_fpu (__prev, __next); \if (has_vector ()) \__switch_to_vector (__prev, __next); \ +__switch_to_envcfg (__next); \ ((last) =__switch_to (__prev, __next)); \ }while (0 )arch/riscv/kernel/cpufeature.c +3
-2@@ -44,6 +44,8 @@ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;/* Per-cpu ISA extensions. */ struct riscv_isainfo hart_isa[NR_CPUS ]; +DEFINE_PER_CPU(unsigned long, riscv_cpu_envcfg); +/* Performance information */ DEFINE_PER_CPU (long, misaligned_access_speed);@@ -978,7 +980,7 @@ arch_initcall(check_unaligned_access_all_cpus);void riscv_user_isa_enable (void ) {if (riscv_cpu_has_extension_unlikely (smp_processor_id (),RISCV_ISA_EXT_ZICBOZ )) -csr_set (CSR_ENVCFG ,ENVCFG_CBZE ); +this_cpu_or (riscv_cpu_envcfg,ENVCFG_CBZE ); }#ifdef CONFIG_RISCV_ALTERNATIVE --2.43.1
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#659): https://lists.riscv.org/g/tech-j-ext/message/659
Mute This Topic: https://lists.riscv.org/mt/105033914/7300952
Group Owner: [email protected]
Unsubscribe: https://lists.riscv.org/g/tech-j-ext/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [RISC-V] [tech-j-ext] [RFC PATCH 5/9] riscv: Split per-CPU and per-thread envcfg bits
Hi Deepak,
Quoted 17 lines · Deepak Gupta
Quoted 7 lines · Samuel Holland via lists.riscv.org
Some envcfg bits need to be controlled on a per-thread basis, such as the pointer masking mode. However, the envcfg CSR value cannot simply be stored in struct
thread_struct, because some hardware may implement a different subset of envcfg CSR bits is across CPUs. As a result, we need to combine the per-CPU and per-thread bits whenever we switch threads.Why not do something like this
arch/riscv/include/asm/csr.h +0
-0
arch/riscv/include/asm/csr.h line 206
Quoted 5 lines
arch/riscv/include/asm/csr.h +2
-0@@ -202,6 +202,8 @@#define ENVCFG_CBIE_FLUSH _AC(0x1, UL)#define ENVCFG_CBIE_INV _AC(0x3, UL)#define ENVCFG_FIOM _AC(0x1, UL) +/* by default all threads should be able to zero cache */ +#define ENVCFG_BASE ENVCFG_CBZE
Linux does not assume Sstrict, so without Zicboz being present in DT/ACPI, we have no idea what the CBZE bit does--there's no guarantee it has the standard meaning--so it's not safe to set the bit unconditionally. If that policy changes, we could definitely simplify the code.
Quoted 14 lines
arch/riscv/include/asm/csr.h +0
-0/* Smstateen bits */ #define SMSTATEEN0_AIA_IMSIC_SHIFT 58arch/riscv/kernel/process.c +1
-0@@ -152,6 +152,7 @@ void start_thread(struct pt_regs *regs, unsigned long pc, else regs->status |= SR_UXL_64;#endif + current->thread_info.envcfg =ENVCFG_BASE ; } And instead of context switching in `_switch_to`,
Quoted 1 line
In
entry.Spick upenvcfgfromthread_infoand write it into CSR.
The immediate reason is that writing envcfg in ret_from_exception() adds cycles to every IRQ and system call exit, even though most of them will not change the envcfg value. This is especially the case when returning from an IRQ/exception back to S-mode, since envcfg has zero effect there.
The CSRs that are read/written in entry.S are generally those where the value can be updated by hardware, as part of taking an exception. But envcfg never changes on its own. The kernel knows exactly when its value will change, and those places are:
1) Task switch, i.e. switch_to()
2) execve(), i.e. start_thread() or flush_thread()
3) A system call that specifically affects a feature controlled by envcfg
So that's where this series writes it. There are a couple of minor tradeoffs about when exactly to do the write:
- We could drop the sync_envcfg() calls outside of switch_to() by reading the current CSR value when scheduling out a thread, but again that adds overhead to the fast path to remove a tiny bit of code in the prctl() handlers.
- We don't need to write envcfg when switching to a kernel thread, only when switching to a user thread, because kernel threads never leave S-mode, so envcfg doesn't affect them. But checking the thread type takes many more instructions than just writing the CSR.
Overall, the optimal implementation will approximate the rule of only writing envcfg when its value changes.
Quoted 2 lines
This construction avoids
- declaring per cpuriscv_cpu_envcfg
This is really a separate concern than when we write envcfg. The per-CPU variable is only necessary to support hardware where a subset of harts support Zicboz. Since the riscv_cpu_has_extension_[un]likely() helpers were added specifically for Zicboz, I assume this is an important use case, and dropping support for this hardware would be a regression. After all, hwprobe() allows userspace to see that Zicboz is implemented at a per-CPU level. Maybe Andrew can weigh in on that.
If we decide to enable Zicboz only when all harts support it, or we decide it's safe to attempt to set the envcfg.CBZE bit on harts that do not declare support for Zicboz, then we could drop the percpu variable.
Quoted 46 lines
- syncing up
- collection of *envcfg bits.Quoted 42 lines
Signed-off-by Samuel Holland <[email protected]>---
arch/riscv/include/asm/cpufeature.h | 2 ++ arch/riscv/include/asm/processor.h | 1 + arch/riscv/include/asm/switch_to.h | 12 ++++++++++++ arch/riscv/kernel/cpufeature.c | 4 +++- 4 files changed, 18 insertions(+), 1 deletion(-)arch/riscv/include/asm/cpufeature.h +2
-0@@ -33,6 +33,8 @@ DECLARE_PER_CPU(long, misaligned_access_speed);/* Per-cpu ISA extensions. */ extern struct riscv_isainfo hart_isa[NR_CPUS ]; +DECLARE_PER_CPU(unsigned long, riscv_cpu_envcfg); +void riscv_user_isa_enable (void );#ifdef CONFIG_RISCV_MISALIGNED arch/riscv/include/asm/processor.h +1
-0@@ -118,6 +118,7 @@ struct thread_struct {unsigned long s[12 ];/* s[0]: frame pointer */ struct __riscv_d_ext_state fstate;unsigned long bad_cause; +unsigned long envcfg;u32 riscv_v_flags;u32 vstate_ctrl;struct __riscv_v_ext_state vstate;arch/riscv/include/asm/switch_to.h +0
-0@@ -69,6 +69,17 @@ static __always_inline bool has_fpu(void) { return false; }#define __switch_to_fpu (__prev, __next) do { } while (0)#endif
Quoted 13 lines
arch/riscv/include/asm/switch_to.h static __always_inline bool has_fpu(void) { return false; } · line 79
Quoted 8 lines
arch/riscv/include/asm/switch_to.h +8
-0+static inline void sync_envcfg (struct task_struct *task) +{ +csr_write (CSR_ENVCFG ,this_cpu_read (riscv_cpu_envcfg) | task->thread.envcfg); +} + +static inline void __switch_to_envcfg (struct task_struct *next) +{ +if (riscv_cpu_has_extension_unlikely (smp_processor_id (),RISCV_ISA_EXT_XLINUXENVCFG ))I've seen
riscv_cpu_has_extension_unlikelygenerating branchy code even if ALTERNATIVES was turned on.
Can you check disasm on your end as well. IMHO,entry.Sis a better place to pick up *envcfg.
The branchiness is sort of expected, since that function is implemented by switching on/off a branch instruction, so the alternate code is necessarily a separate basic block. It's a tradeoff so we don't have to write assembly code for every bit of code that depends on an extension. However, the cost should be somewhat lowered since the branch is unconditional and so entirely predictable.
If the branch turns out to be problematic for performance, then we could use ALTERNATIVE directly in sync_envcfg() to NOP out the CSR write.
Quoted 27 lines
Quoted 27 lines
arch/riscv/include/asm/switch_to.h +4
-0+sync_envcfg (next); +} +extern struct task_struct *__switch_to (struct task_struct *,struct task_struct *);@@ -80,6 +91,7 @@ do { \__switch_to_fpu (__prev, __next); \if (has_vector ()) \__switch_to_vector (__prev, __next); \ +__switch_to_envcfg (__next); \ ((last) =__switch_to (__prev, __next)); \ }while (0 )arch/riscv/kernel/cpufeature.c +2
-0@@ -44,6 +44,8 @@ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;/* Per-cpu ISA extensions. */ struct riscv_isainfo hart_isa[NR_CPUS ]; +DEFINE_PER_CPU(unsigned long, riscv_cpu_envcfg); +/* Performance information */ DEFINE_PER_CPU (long, misaligned_access_speed);
Quoted 6 lines
arch/riscv/kernel/cpufeature.c arch_initcall(check_unaligned_access_all_cpus); · line 983
Quoted 6 lines
arch/riscv/kernel/cpufeature.c +1
-1@@ -978,7 +980,7 @@ arch_initcall(check_unaligned_access_all_cpus);void riscv_user_isa_enable (void ) {if (riscv_cpu_has_extension_unlikely (smp_processor_id (),RISCV_ISA_EXT_ZICBOZ )) -csr_set (CSR_ENVCFG ,ENVCFG_CBZE ); +this_cpu_or (riscv_cpu_envcfg,ENVCFG_CBZE );
If we drop the percpu variable, this becomes
if (riscv_has_extension_unlikely(RISCV_ISA_EXT_ZICBOZ)) current->thread.envcfg |= ENVCFG_CBZE;
since the init thread's envcfg gets copied to all other threads via fork(), and we can drop the call to riscv_user_isa_enable() from smp_callin(). Or if we decide CBZE is always safe to set, then the function is even simpler:
current->thread.envcfg = ENVCFG_CBZE;
Regards,
Samuel
Quoted 5 lines
Quoted 5 lines
arch/riscv/kernel/cpufeature.c +0
-1}#ifdef CONFIG_RISCV_ALTERNATIVE --2.43.1
Re: [RISC-V] [tech-j-ext] [RFC PATCH 5/9] riscv: Split per-CPU and per-thread envcfg bits
Hi Samuel,
Thanks for your response.
Quoted 16 lines · Samuel Holland
Hi Deepak,
Quoted 12 lines · Deepak Gupta
Quoted 7 lines · Samuel Holland via lists.riscv.org
Some envcfg bits need to be controlled on a per-thread basis, such as the pointer masking mode. However, the envcfg CSR value cannot simply be stored in struct
thread_struct, because some hardware may implement a different subset of envcfg CSR bits is across CPUs. As a result, we need to combine the per-CPU and per-thread bits whenever we switch threads.Why not do something like this
Quoted 16 lines
arch/riscv/include/asm/csr.h line 206
Quoted 10 lines
arch/riscv/include/asm/csr.h +2
-0@@ -202,6 +202,8 @@#define ENVCFG_CBIE_FLUSH _AC(0x1, UL)#define ENVCFG_CBIE_INV _AC(0x3, UL)#define ENVCFG_FIOM _AC(0x1, UL) +/* by default all threads should be able to zero cache */ +#define ENVCFG_BASE ENVCFG_CBZELinux does not assume Sstrict, so without Zicboz being present in DT/ACPI, we have no idea what the CBZE bit does--there's no guarantee it has the standard meaning--so it's not safe to set the bit unconditionally. If that policy changes, we could definitely simplify the code.
Yeah, it makes sense.
Quoted 21 lines
Quoted 14 lines
arch/riscv/include/asm/csr.h +0
-0/* Smstateen bits */ #define SMSTATEEN0_AIA_IMSIC_SHIFT 58arch/riscv/kernel/process.c +1
-0@@ -152,6 +152,7 @@ void start_thread(struct pt_regs *regs, unsigned long pc, else regs->status |= SR_UXL_64;#endif + current->thread_info.envcfg =ENVCFG_BASE ; } And instead of context switching in `_switch_to`,Quoted 1 line
In
entry.Spick upenvcfgfromthread_infoand write it into CSR.The immediate reason is that writing envcfg in
ret_from_exception()adds cycles to every IRQ and system call exit, even though most of them will not change the envcfg value. This is especially the case when returning from an IRQ/exception back to S-mode, since envcfg has zero effect there.
Quoted 8 lines
The CSRs that are read/written in
entry.Sare generally those where the value can be updated by hardware, as part of taking an exception. But envcfg never changes on its own. The kernel knows exactly when its value will change, and those places are:1) Task switch, i.e.
switch_to()
2)execve(), i.e.start_thread()orflush_thread()
3) A system call that specifically affects a feature controlled by envcfg
Yeah I was optimizing for a single place to write instead of sprinkling at multiple places.
But I see your argument. That's fine.
Quoted 18 lines
So that's where this series writes it. There are a couple of minor tradeoffs about when exactly to do the write:
- We could drop the
sync_envcfg()calls outside ofswitch_to()by reading the current CSR value when scheduling out a thread, but again that adds overhead to the fast path to remove a tiny bit of code in theprctl()handlers.
- We don't need to write envcfg when switching to a kernel thread, only when switching to a user thread, because kernel threads never leave S-mode, so envcfg doesn't affect them. But checking the thread type takes many more instructions than just writing the CSR.Overall, the optimal implementation will approximate the rule of only writing envcfg when its value changes.
Quoted 2 lines
This construction avoids
- declaring per cpuriscv_cpu_envcfg
Quoted 7 lines
This is really a separate concern than when we write envcfg. The per-CPU variable is only necessary to support hardware where a subset of harts support Zicboz. Since the riscv_cpu_has_extension_[un]likely() helpers were added specifically for Zicboz, I assume this is an important use case, and dropping support for this hardware would be a regression. After all,
hwprobe()allows userspace to see that Zicboz is implemented at a per-CPU level. Maybe Andrew can weigh in on that.
I am not sure of the practicality of this heterogeneity for Zicboz and for that matter any of the upcoming
features that'll be enabled via senvcfg (control flow integrity, pointer masking, etc).
As an example if cache zeroing instructions are used by app binary, I expect it to be used in following
manner
- Explicitly inserting cbo.zero by application developer
- Some compiler flag which ensures that structures larger than cache
line gets zeroed by cbo.zero
In either of the cases, the developer is not expecting to target it to a specific hart on SoC and instead expect it to work.
There might be libraries (installed via sudo apt get) with cache zero support in them which may run in different address spaces. Should the library be aware of the CPU on which it's running. Now whoever is running these binaries should be aware which CPUs they get assigned to in order to avoid faults?
That seems excessive, doesn't it?
Quoted 65 lines
If we decide to enable Zicboz only when all harts support it, or we decide it's safe to attempt to set the envcfg.CBZE bit on harts that do not declare support for Zicboz, then we could drop the percpu variable.
Quoted 46 lines
- syncing up
- collection of *envcfg bits.Quoted 42 lines
Signed-off-by Samuel Holland <[email protected]>---
arch/riscv/include/asm/cpufeature.h | 2 ++ arch/riscv/include/asm/processor.h | 1 + arch/riscv/include/asm/switch_to.h | 12 ++++++++++++ arch/riscv/kernel/cpufeature.c | 4 +++- 4 files changed, 18 insertions(+), 1 deletion(-)arch/riscv/include/asm/cpufeature.h +2
-0@@ -33,6 +33,8 @@ DECLARE_PER_CPU(long, misaligned_access_speed);/* Per-cpu ISA extensions. */ extern struct riscv_isainfo hart_isa[NR_CPUS ]; +DECLARE_PER_CPU(unsigned long, riscv_cpu_envcfg); +void riscv_user_isa_enable (void );#ifdef CONFIG_RISCV_MISALIGNED arch/riscv/include/asm/processor.h +1
-0@@ -118,6 +118,7 @@ struct thread_struct {unsigned long s[12 ];/* s[0]: frame pointer */ struct __riscv_d_ext_state fstate;unsigned long bad_cause; +unsigned long envcfg;u32 riscv_v_flags;u32 vstate_ctrl;struct __riscv_v_ext_state vstate;arch/riscv/include/asm/switch_to.h +0
-0@@ -69,6 +69,17 @@ static __always_inline bool has_fpu(void) { return false; }#define __switch_to_fpu (__prev, __next) do { } while (0)#endif Quoted 13 lines
arch/riscv/include/asm/switch_to.h static __always_inline bool has_fpu(void) { return false; } · line 79
Quoted 8 lines
arch/riscv/include/asm/switch_to.h +8
-0+static inline void sync_envcfg (struct task_struct *task) +{ +csr_write (CSR_ENVCFG ,this_cpu_read (riscv_cpu_envcfg) | task->thread.envcfg); +} + +static inline void __switch_to_envcfg (struct task_struct *next) +{ +if (riscv_cpu_has_extension_unlikely (smp_processor_id (),RISCV_ISA_EXT_XLINUXENVCFG ))I've seen
riscv_cpu_has_extension_unlikelygenerating branchy code even if ALTERNATIVES was turned on.
Can you check disasm on your end as well. IMHO,entry.Sis a better place to pick up *envcfg.
Quoted 8 lines
The branchiness is sort of expected, since that function is implemented by switching on/off a branch instruction, so the alternate code is necessarily a separate basic block. It's a tradeoff so we don't have to write assembly code for every bit of code that depends on an extension. However, the cost should be somewhat lowered since the branch is unconditional and so entirely predictable.
If the branch turns out to be problematic for performance, then we could use ALTERNATIVE directly in
sync_envcfg()to NOP out the CSR write.
Yeah I lean towards using alternatives directly.
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
arch/riscv/include/asm/switch_to.h +2
-0+sync_envcfg (next); +}
Re: [RISC-V] [tech-j-ext] [RFC PATCH 5/9] riscv: Split per-CPU and per-thread envcfg bits
Quoted 26 lines · Deepak Gupta
Quoted 26 lines
Quoted 6 lines
Quoted 6 lines
arch/riscv/include/asm/switch_to.h +0
-0@@ -69,6 +69,17 @@ static __always_inline bool has_fpu(void) { return false; }#define __switch_to_fpu (__prev, __next) do { } while (0)#endif Quoted 13 lines
arch/riscv/include/asm/switch_to.h static __always_inline bool has_fpu(void) { return false; } · line 79
Quoted 8 lines
arch/riscv/include/asm/switch_to.h +8
-0+static inline void sync_envcfg (struct task_struct *task) +{ +csr_write (CSR_ENVCFG ,this_cpu_read (riscv_cpu_envcfg) | task->thread.envcfg); +} + +static inline void __switch_to_envcfg (struct task_struct *next) +{ +if (riscv_cpu_has_extension_unlikely (smp_processor_id (),RISCV_ISA_EXT_XLINUXENVCFG ))I've seen
riscv_cpu_has_extension_unlikelygenerating branchy code even if ALTERNATIVES was turned on.
Can you check disasm on your end as well. IMHO,entry.Sis a better place to pick up *envcfg.The branchiness is sort of expected, since that function is implemented by switching on/off a branch instruction, so the alternate code is necessarily a separate basic block. It's a tradeoff so we don't have to write assembly code for every bit of code that depends on an extension. However, the cost should be somewhat lowered since the branch is unconditional and so entirely predictable.
Quoted 4 lines
Quoted 2 lines
If the branch turns out to be problematic for performance, then we could use ALTERNATIVE directly in
sync_envcfg()to NOP out the CSR write.Yeah I lean towards using alternatives directly.
One thing to note here: we can't use alternatives directly if the behavior needs to be different on different harts (i.e. a subset of harts implement the envcfg CSR). I think we need some policy about which ISA extensions are allowed to be asymmetric across harts, or else we add too much complexity.
Regards,
Samuel
Re: [RISC-V] [tech-j-ext] [RFC PATCH 5/9] riscv: Split per-CPU and per-thread envcfg bits
Quoted 31 lines · Samuel Holland
Quoted 29 lines · Deepak Gupta
Quoted 28 lines
Quoted 6 lines
Quoted 6 lines
arch/riscv/include/asm/switch_to.h +0
-0@@ -69,6 +69,17 @@ static __always_inline bool has_fpu(void) { return false; }#define __switch_to_fpu (__prev, __next) do { } while (0)#endif Quoted 13 lines
arch/riscv/include/asm/switch_to.h static __always_inline bool has_fpu(void) { return false; } · line 79
Quoted 8 lines
arch/riscv/include/asm/switch_to.h +8
-0+static inline void sync_envcfg (struct task_struct *task) +{ +csr_write (CSR_ENVCFG ,this_cpu_read (riscv_cpu_envcfg) | task->thread.envcfg); +} + +static inline void __switch_to_envcfg (struct task_struct *next) +{ +if (riscv_cpu_has_extension_unlikely (smp_processor_id (),RISCV_ISA_EXT_XLINUXENVCFG ))I've seen
riscv_cpu_has_extension_unlikelygenerating branchy code even if ALTERNATIVES was turned on.
Can you check disasm on your end as well. IMHO,entry.Sis a better place to pick up *envcfg.The branchiness is sort of expected, since that function is implemented by switching on/off a branch instruction, so the alternate code is necessarily a separate basic block. It's a tradeoff so we don't have to write assembly code for every bit of code that depends on an extension. However, the cost should be somewhat lowered since the branch is unconditional and so entirely predictable.
If the branch turns out to be problematic for performance, then we could use ALTERNATIVE directly in
sync_envcfg()to NOP out the CSR write.
Quoted 6 lines
Quoted 1 line
Yeah I lean towards using alternatives directly.
One thing to note here: we can't use alternatives directly if the behavior needs to be different on different harts (i.e. a subset of harts implement the envcfg CSR). I think we need some policy about which ISA extensions are allowed to be asymmetric across harts, or else we add too much complexity.
As I've responded on the same thread . We are adding too much complexity by assuming
that heterogeneous ISA exists (which it doesn't today). And even if it exists, it wouldn't work.
Nobody wants to spend a lot of time figuring out which harts have which ISA and which
packages are compiled with which ISA. Most of the end users do sudo apt get install blah blah
And then expect it to just work. It doesn't work for other architectures and even when someone
tried, they had to disable certain ISA features to make sure that all cores have the same ISA feature
(search AVX12 Intel Alder Lake Disable).
Quoted 4 lines
Regards,
Samuel
Re: [RISC-V] [tech-j-ext] [RFC PATCH 5/9] riscv: Split per-CPU and per-thread envcfg bits
Quoted 40 lines · Deepak Gupta
Quoted 31 lines · Samuel Holland
Quoted 29 lines · Deepak Gupta
Quoted 28 lines
Quoted 6 lines
Quoted 6 lines
arch/riscv/include/asm/switch_to.h +0
-0@@ -69,6 +69,17 @@ static __always_inline bool has_fpu(void) { return false; }#define __switch_to_fpu (__prev, __next) do { } while (0)#endif Quoted 13 lines
arch/riscv/include/asm/switch_to.h static __always_inline bool has_fpu(void) { return false; } · line 79
Quoted 8 lines
arch/riscv/include/asm/switch_to.h +8
-0+static inline void sync_envcfg (struct task_struct *task) +{ +csr_write (CSR_ENVCFG ,this_cpu_read (riscv_cpu_envcfg) | task->thread.envcfg); +} + +static inline void __switch_to_envcfg (struct task_struct *next) +{ +if (riscv_cpu_has_extension_unlikely (smp_processor_id (),RISCV_ISA_EXT_XLINUXENVCFG ))I've seen
riscv_cpu_has_extension_unlikelygenerating branchy code even if ALTERNATIVES was turned on.
Can you check disasm on your end as well. IMHO,entry.Sis a better place to pick up *envcfg.The branchiness is sort of expected, since that function is implemented by switching on/off a branch instruction, so the alternate code is necessarily a separate basic block. It's a tradeoff so we don't have to write assembly code for every bit of code that depends on an extension. However, the cost should be somewhat lowered since the branch is unconditional and so entirely predictable.
If the branch turns out to be problematic for performance, then we could use ALTERNATIVE directly in
sync_envcfg()to NOP out the CSR write.Quoted 6 lines
Quoted 1 line
Yeah I lean towards using alternatives directly.
One thing to note here: we can't use alternatives directly if the behavior needs to be different on different harts (i.e. a subset of harts implement the envcfg CSR). I think we need some policy about which ISA extensions are allowed to be asymmetric across harts, or else we add too much complexity.
Quoted 9 lines
As I've responded on the same thread . We are adding too much complexity by assuming
that heterogeneous ISA exists (which it doesn't today). And even if it exists, it wouldn't work.
Nobody wants to spend a lot of time figuring out which harts have which ISA and which
packages are compiled with which ISA. Most of the end users dosudo apt get install blah blah
And then expect it to just work.
That will still work if the applications and libraries installed are heterogeneous-platform aware, i.e. they do the figuring out which harts have which extensions themselves. Applications/libraries should already be probing for ISA extensions before using them. It's not a huge leap to also check which harts support those extensions and then ensure affinity is set appropriately.
Quoted 5 lines
It doesn't work for other
architectures and even when someone
tried, they had to disable certain ISA features to make sure that all cores have the same ISA feature
(search AVX12 Intel Alder Lake Disable).
The RISC-V software ecosystem is still being developed. We have an opportunity to drop assumptions made by other architectures.
As I said in a different reply, it's reasonable for Linux to not add the complexity until a use case comes along that Linux would like to support, but I think it would be premature for Linux to put a stake in the sand.
So, how about we add code that confirms Zicboz is on all harts. If any hart does not have it, then we complain loudly and disable it on all the other harts. If it was just a hardware description bug, then it'll get fixed. If there's actually a platform which doesn't have Zicboz on all harts, then, when the issue is reported, we can decide to not support it, support it with defconfig, or support it under a Kconfig guard which must be enabled by the user.
Thanks,
drew
Re: [RISC-V] [tech-j-ext] [RFC PATCH 5/9] riscv: Split per-CPU and per-thread envcfg bits
Quoted 20 lines · Andrew Jones
Quoted 7 lines · Deepak Gupta
Quoted 6 lines
Quoted 1 line
Yeah I lean towards using alternatives directly.
One thing to note here: we can't use alternatives directly if the behavior needs to be different on different harts (i.e. a subset of harts implement the envcfg CSR). I think we need some policy about which ISA extensions are allowed to be asymmetric across harts, or else we add too much complexity.
Quoted 9 lines
As I've responded on the same thread . We are adding too much complexity by assuming
that heterogeneous ISA exists (which it doesn't today). And even if it exists, it wouldn't work.
Nobody wants to spend a lot of time figuring out which harts have which ISA and which
packages are compiled with which ISA. Most of the end users dosudo apt get install blah blah
And then expect it to just work.
Quoted 6 lines
That will still work if the applications and libraries installed are heterogeneous-platform aware, i.e. they do the figuring out which harts have which extensions themselves. Applications/libraries should already be probing for ISA extensions before using them. It's not a huge leap to also check which harts support those extensions and then ensure affinity is set appropriately.
How ?
It's a single image of a library that will be loaded in multiple address spaces. You expect all code pages to do COW for multiple address spaces or expect to have
per task variables to choose different code paths in the library based on address space its
running in ?
On top of that, the library/application developer doesn't know how the end user is going to use them.
End users (sysadmin, etc) just might use taskset to put affinity on tasks without being aware.
I just don't see the motivation in an application developer/library developer to do something
like this. No application/library developer has time for this. Putting a lot of burden on application
developers is mostly a nuisance considering they don't have to think about these nuisance
when they expect the same code to be deployed on non-riscv architectures.
One good example of putting unnecessary burden on app/library developer is Intel SGX
This is exactly the reason Intel SGX failed. Application developers don't have time to develop
confidential compute version of the application for a specific CPU while on other CPUs carry
a different version of application. But at the same time virtual machine confidential compute is
better approach where all complicated decision making is delegated to operating system
developer and application/library developers are empowered to only think about their stuff.
Quoted 9 lines
Quoted 6 lines
It doesn't work for other
architectures and even when someone
tried, they had to disable certain ISA features to make sure that all cores have the same ISA feature
(search AVX12 Intel Alder Lake Disable).The RISC-V software ecosystem is still being developed. We have an opportunity to drop assumptions made by other architectures.
It doesn't mean that it should try to make the same mistakes which others have done.
If there is a motivation and use case from end user perspective, please provide. Otherwise no point doing something which is just a science thought exercise and no concrete use case.
Please note that these arguments are against Heterogeneous ISA on cores. From power and efficiency perspective cores can still be heterogeneous.
Quoted 16 lines
As I said in a different reply, it's reasonable for Linux to not add the complexity until a use case comes along that Linux would like to support, but I think it would be premature for Linux to put a stake in the sand.
So, how about we add code that confirms Zicboz is on all harts. If any hart does not have it, then we complain loudly and disable it on all the other harts. If it was just a hardware description bug, then it'll get fixed. If there's actually a platform which doesn't have Zicboz on all harts, then, when the issue is reported, we can decide to not support it, support it with defconfig, or support it under a
Kconfigguard which must be enabled by the user.Thanks,
drew
Re: [RISC-V] [tech-j-ext] [RFC PATCH 5/9] riscv: Split per-CPU and per-thread envcfg bits
In reply to Deepak GuptaOn Tue, Mar 19, 2024 at 09:39:52PM -0700, Deepak Gupta wrote:
...
Quoted 21 lines
I am not sure of the practicality of this heterogeneity for Zicboz and for that matter any of the upcoming
features that'll be enabled via senvcfg (control flow integrity, pointer masking, etc).As an example if cache zeroing instructions are used by app binary, I expect it to be used in following
manner- Explicitly inserting cbo.zero by application developer
- Some compiler flag which ensures that structures larger than cache
line gets zeroed by cbo.zeroIn either of the cases, the developer is not expecting to target it to a specific hart on SoC and instead expect it to work.
There might be libraries (installed via sudo apt get) with cache zero support in them which may run in different address spaces. Should the library be aware of the CPU on which it's running. Now whoever is running these binaries should be aware which CPUs they get assigned to in order to avoid faults?
Quoted 2 lines
That seems excessive, doesn't it?
It might be safe to assume extensions like Zicboz will be on all harts if any, but I wouldn't expect all extensions in the future to be present on all available harts. For example, some Arm big.LITTLE boards only have virt extensions on big CPUs. When a VMM wants to launch a guest it must be aware of which CPUs it will use for the VCPU threads. For riscv, we have the which-cpus variant of the hwprobe syscall to try and make this type of thing easier to manage, but I agree it will still be a pain for software since it will need to make that query and then set its affinity, which is something it hasn't needed to do before.
Thanks,
drew
Re: [RISC-V] [tech-j-ext] [RFC PATCH 5/9] riscv: Split per-CPU and per-thread envcfg bits
Quoted 27 lines · Andrew Jones
On Tue, Mar 19, 2024 at 09:39:52PM -0700, Deepak Gupta wrote:
...Quoted 21 lines
I am not sure of the practicality of this heterogeneity for Zicboz and for that matter any of the upcoming
features that'll be enabled via senvcfg (control flow integrity, pointer masking, etc).As an example if cache zeroing instructions are used by app binary, I expect it to be used in following
manner- Explicitly inserting cbo.zero by application developer
- Some compiler flag which ensures that structures larger than cache
line gets zeroed by cbo.zeroIn either of the cases, the developer is not expecting to target it to a specific hart on SoC and instead expect it to work.
There might be libraries (installed via sudo apt get) with cache zero support in them which may run in different address spaces. Should the library be aware of the CPU on which it's running. Now whoever is running these binaries should be aware which CPUs they get assigned to in order to avoid faults?Quoted 2 lines
That seems excessive, doesn't it?
Quoted 10 lines
It might be safe to assume extensions like Zicboz will be on all harts if any, but I wouldn't expect all extensions in the future to be present on all available harts. For example, some Arm big.LITTLE boards only have virt extensions on big CPUs. When a VMM wants to launch a guest it must be aware of which CPUs it will use for the VCPU threads. For riscv, we have the which-cpus variant of the hwprobe syscall to try and make this type of thing easier to manage, but I agree it will still be a pain for software since it will need to make that query and then set its affinity, which is something it hasn't needed to do before.
Sure, the future may be a world where heterogeneous ISA is a thing. But that's not the present. Let's not try to build for something which doesn't exist.
It has been (heterogeneous ISA) tried earlier many times and mostly have fallen flat (remember on Intel alder lake, Intel had to ship a ucode patch to disable AVX512 exactly for same reason)
https://www.anandtech.com/show/17047/the-intel-12th-gen-core-i912900k-review-hybrid-performance-brings-hybrid-complexity/2
As and when ISA features get enabled, they get compiled into libraries/binaries and end user many times use things like taskset to set affinity without even realizing
there is some weirdness going on under the hood. For majority of use cases -- heterogeneous
ISA doesn't make sense. Sure if someone is willing to build a custom SoC with heterogeneous
ISA for their strict usecase, they control their software and hardware and thus they can do that.
But littering linux kernel to support wierd usecases and putting a burden of that on majority of
usecases and software is not wise.
If something like this has to be done, I expect first that it doesn't force end users to learn
about ISA differences between harts on their system and then figure out which installed
packages have which ISA features compiled in. This is like walking on eggshells from the end
user perspective. Sure, end user can be extremely intelligent / smart and figure it all out but
that population is rare and that rare population can develop their custom kernel and libc
patches to do something like this.
This is a good science project to support heterogeneous ISA but practically not viable unless
there is a high level end user use case.
Quoted 2 lines
Thanks,
drew
Re: [RISC-V] [tech-j-ext] [RFC PATCH 5/9] riscv: Split per-CPU and per-thread envcfg bits
In reply to Samuel HollandQuoted 13 lines · Samuel Holland
Quoted 12 lines · Deepak Gupta
Quoted 7 lines · Samuel Holland via lists.riscv.org
Some envcfg bits need to be controlled on a per-thread basis, such as the pointer masking mode. However, the envcfg CSR value cannot simply be stored in struct
thread_struct, because some hardware may implement a different subset of envcfg CSR bits is across CPUs. As a result, we need to combine the per-CPU and per-thread bits whenever we switch threads.Why not do something like this
Quoted 15 lines
arch/riscv/include/asm/csr.h line 206
Quoted 10 lines
arch/riscv/include/asm/csr.h +2
-0@@ -202,6 +202,8 @@#define ENVCFG_CBIE_FLUSH _AC(0x1, UL)#define ENVCFG_CBIE_INV _AC(0x3, UL)#define ENVCFG_FIOM _AC(0x1, UL) +/* by default all threads should be able to zero cache */ +#define ENVCFG_BASE ENVCFG_CBZELinux does not assume Sstrict, so without Zicboz being present in DT/ACPI, we have no idea what the CBZE bit does--there's no guarantee it has the standard meaning--so it's not safe to set the bit unconditionally. If that policy changes, we could definitely simplify the code.
The wording for that "extension", if two lines in the profiles doc makes something an extension is:
"No non-conforming extensions are present. Attempts to execute unimplemented opcodes or access unimplemented CSRs in the standard or reserved encoding spaces raises an illegal instruction exception that results in a contained trap to the supervisor-mode trap handler."
I know we have had new extensions come along and mark previously fair game interrupts for vendors as out of bounds. I wonder if there's a risk of that happening with CSRs or opcodes too (or maybe it has happened and I cannot recall).
Going back to the interrupts - is the Andes PMU non-conforming because it uses an interrupt that was declared as vendor usable but is now part of the standard space because of AIA? If it is, then the meaning of Sstrict could vary wildly based on the set of extensions (and their versions for specs). That sounds like a lot of fun.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [RISC-V] [tech-j-ext] [RFC PATCH 5/9] riscv: Split per-CPU and per-thread envcfg bits
Quoted 14 lines
Quoted 14 lines
Quoted 3 lines
And instead of context switching in
_switch_to,
Inentry.Spick upenvcfgfromthread_infoand write it into CSR.The immediate reason is that writing envcfg in
ret_from_exception()adds cycles to every IRQ and system call exit, even though most of them will not change the envcfg value. This is especially the case when returning from an IRQ/exception back to S-mode, since envcfg has zero effect there.The CSRs that are read/written in
entry.Sare generally those where the value can be updated by hardware, as part of taking an exception. But envcfg never changes on its own. The kernel knows exactly when its value will change, and those places are:
Quoted 8 lines
Quoted 3 lines
1) Task switch, i.e.
switch_to()
2)execve(), i.e.start_thread()orflush_thread()
3) A system call that specifically affects a feature controlled by envcfgYeah I was optimizing for a single place to write instead of sprinkling at multiple places.
But I see your argument. That's fine.
Because this is RFC and we are discussing it. I thought a little bit more about this.
If we were to go with the above approach that essentially requires whenever a envcfg bit changes, sync_envcfg
has to be called to reflect the correct value.
What if some of these features enable/disable are exposed to ptrace (gdb, etc use cases) for enable/disable.
How will syncing work then ?
I can see the reasoning behind saving some cycles during trap return. But senvcfg is not actually a user state, it
controls the execution environment configuration for user mode. I think the best place for this CSR to be written is
trap return and writing at a single place from a single image on stack reduces chances of bugs and errors. And allowssenvcfg features to be exposed to other kernel flows (like ptrace)
We can figure out ways on how to optimize in trap return path to avoid writing it if we entered and exiting on the same
task.
Re: [RISC-V] [tech-j-ext] [RFC PATCH 5/9] riscv: Split per-CPU and per-thread envcfg bits
Hi Deepak,
Quoted 17 lines · Deepak Gupta
Quoted 17 lines
Quoted 16 lines
Quoted 2 lines
And instead of context switching in
_switch_to,
Inentry.Spick upenvcfgfromthread_infoand write it into CSR.The immediate reason is that writing envcfg in
ret_from_exception()adds cycles to every IRQ and system call exit, even though most of them will not change the envcfg value. This is especially the case when returning from an IRQ/exception back to S-mode, since envcfg has zero effect there.The CSRs that are read/written in
entry.Sare generally those where the value can be updated by hardware, as part of taking an exception. But envcfg never changes on its own. The kernel knows exactly when its value will change, and those places are:1) Task switch, i.e.
switch_to()
2)execve(), i.e.start_thread()orflush_thread()
3) A system call that specifically affects a feature controlled by envcfg
Quoted 7 lines
Quoted 4 lines
Yeah I was optimizing for a single place to write instead of sprinkling at multiple places.
But I see your argument. That's fine.Because this is RFC and we are discussing it. I thought a little bit more about this.
Thanks for your comments and the discussion! I know several in-progress features depend on envcfg, so hopefully we can agree on a design acceptable to everyone.
Quoted 3 lines
If we were to go with the above approach that essentially requires whenever a envcfg bit changes,
sync_envcfg
has to be called to reflect the correct value.
sync_envcfg() is only needed if the task being updated is current. Would it be more acceptable if this happened inside a helper function? Something like:
static inline void envcfg_update_bits(struct task_struct *task,
unsigned long mask, unsigned long val)
{
unsigned long envcfg;
envcfg = (task->thread.envcfg & ~mask) | val;
task->thread.envcfg = envcfg;
if (task == current)
csr_write(CSR_ENVCFG, this_cpu_read(riscv_cpu_envcfg) | envcfg);
}Quoted 3 lines
What if some of these features enable/disable are exposed to
ptrace(gdb, etc use cases) for enable/disable.
How will syncing work then ?
ptrace_check_attach() ensures the tracee is scheduled out while a ptrace operation is running, so there is no need to sync anything. Any changes to task->thread.envcfg are written to the CSR when the tracee is scheduled back in.
Quoted 7 lines
I can see the reasoning behind saving some cycles during trap return. But
senvcfgis not actually a user state, it
controls the execution environment configuration for user mode. I think the best place for this CSR to be written is
trap return and writing at a single place from a single image on stack reduces chances of bugs and errors. And allowssenvcfgfeatures to be exposed to other kernel flows (likeptrace)
If ptrace is accessing a process, then task->thread.envcfg is always up to date. The only complication is that the per-CPU bits need to be ORed back in to get the real CSR value for another process, but this again is unrelated to whether the CSR is written in switch_to() or ret_from_exception().
Quoted 3 lines
We can figure out ways on how to optimize in trap return path to avoid writing it if we entered and exiting on the same
task.
Optimizing out the CSR write when the task did not switch requires knowing if the current task's envcfg was changed during this trip to S-mode... and this starts looking similar to sync_envcfg().
Regards,
Samuel
Re: [RISC-V] [tech-j-ext] [RFC PATCH 5/9] riscv: Split per-CPU and per-thread envcfg bits
In reply to Samuel HollandOn Tue, Mar 19, 2024 at 09:20:59PM -0500, Samuel Holland wrote:
...
Quoted 8 lines
This is really a separate concern than when we write envcfg. The per-CPU variable is only necessary to support hardware where a subset of harts support Zicboz. Since the riscv_cpu_has_extension_[un]likely() helpers were added specifically for Zicboz, I assume this is an important use case, and dropping support for this hardware would be a regression. After all,
hwprobe()allows userspace to see that Zicboz is implemented at a per-CPU level. Maybe Andrew can weigh in on that.
Hi Samuel,
I've approached Zicboz the same way I would approach all extensions, which is to be per-hart. I'm not currently aware of a platform that is / will be composed of harts where some have Zicboz and others don't, but there's nothing stopping a platform like that from being built. I realize this adds complexity that we may not want to manage in Linux without an actual use case requiring it. I wouldn't be opposed to keeping things simple for now, only bringing in complexity when needed (for this extension or for a future extension with envcfg bits), but we should ensure we make it clear that we're making those simplifications now based on assumptions, and we may need to change things later.
Thanks,
drew
Re: [RISC-V] [tech-j-ext] [RFC PATCH 5/9] riscv: Split per-CPU and per-thread envcfg bits
In reply to Samuel HollandQuoted 7 lines · Samuel Holland
Quoted 7 lines
else regs->status |= SR_UXL_64;#endif
+current->thread_info.envcfg=ENVCFG_BASE;
}
Quoted 8 lines
Quoted 2 lines
And instead of context switching in
_switch_to,
Inentry.Spick upenvcfgfromthread_infoand write it into CSR.The immediate reason is that writing envcfg in
ret_from_exception()adds cycles to every IRQ and system call exit, even though most of them will not change the envcfg value. This is especially the case when returning from an IRQ/exception back to S-mode, since envcfg has zero effect there.
A quick observation:
So I tried this on my setup. When I put senvcfg writes in __switch_to path, qemu suddenly
just tanks and takes a lot of time to boot up as opposed to when senvcfg was in trap return path.
In my case entire userspace (all processes) have cfi enabled for them via senvcfg and it gets
context switched. Not sure it's specific to my setup. I don't think it should be an issue on actual
hardware.
Still debugging why it slows down my qemu drastically when same writes to same CSR
are moved from ret_from_exception to switch_to
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [RISC-V] [tech-j-ext] [RFC PATCH 5/9] riscv: Split per-CPU and per-thread envcfg bits
Quoted 29 lines · Deepak Gupta via lists.riscv.org
Quoted 7 lines · Samuel Holland
Quoted 7 lines
else regs->status |= SR_UXL_64;#endif
+current->thread_info.envcfg=ENVCFG_BASE;
}Quoted 8 lines
Quoted 2 lines
And instead of context switching in
_switch_to,
Inentry.Spick upenvcfgfromthread_infoand write it into CSR.The immediate reason is that writing envcfg in
ret_from_exception()adds cycles to every IRQ and system call exit, even though most of them will not change the envcfg value. This is especially the case when returning from an IRQ/exception back to S-mode, since envcfg has zero effect there.A quick observation:
So I tried this on my setup. When I putsenvcfgwrites in__switch_topath, qemu suddenly
just tanks and takes a lot of time to boot up as opposed to whensenvcfgwas in trap return path.
In my case entire userspace (all processes) have cfi enabled for them viasenvcfgand it gets
context switched. Not sure it's specific to my setup. I don't think it should be an issue on actual
hardware.
Quoted 3 lines
Still debugging why it slows down my qemu drastically when same writes to same CSR
are moved fromret_from_exceptiontoswitch_to
Nevermind and sorry for the bother. An issue on my setup.
Quoted 11 lines
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#680): https://lists.riscv.org/g/tech-j-ext/message/680
Mute This Topic: https://lists.riscv.org/mt/105033914/7300952
Group Owner: [email protected]
Unsubscribe: https://lists.riscv.org/g/tech-j-ext/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
RFC PATCH 6/9 riscv: Add support for userspace pointer masking
In reply to Samuel HollandRISC-V supports pointer masking with a variable number of tag bits ("PMLEN") and which is configured at the next higher privilege level.
Wire up the PR_SET_TAGGED_ADDR_CTRL and PR_GET_TAGGED_ADDR_CTRL prctls so userspace can request a minimum number of tag bits and determine the actual number of tag bits. As with PR_TAGGED_ADDR_ENABLE, the pointer masking configuration is thread-scoped, inherited on clone() and fork() and cleared on exec().
---
arch/riscv/Kconfig | 8 +++ arch/riscv/include/asm/processor.h | 8 +++ arch/riscv/kernel/process.c | 107 +++++++++++++++++++++++++++++ include/uapi/linux/prctl.h | 3 + 4 files changed, 126 insertions(+)
arch/riscv/Kconfig +8 -0
@@ -479,6 +479,14 @@ config RISCV_ISA_C If you don't know what to do here, say Y. +config RISCV_ISA_POINTER_MASKING + bool "Smmpm, Smnpm, and Ssnpm extensions for pointer masking" + depends on 64BIT + default y + help + Add support to dynamically detect the presence of the Smmpm, Smnpm, + and Ssnpm extensions (pointer masking) and enable their usage. + config RISCV_ISA_SVNAPOT bool "Svnapot extension support for supervisor mode NAPOT pages" depends on 64BIT && MMU
arch/riscv/include/asm/processor.h +8 -0
@@ -185,6 +185,14 @@ extern int set_unalign_ctl(struct task_struct *tsk, unsigned int val);#define GET_UNALIGN_CTL (tsk, addr) get_unalign_ctl((tsk), (addr))#define SET_UNALIGN_CTL (tsk, val) set_unalign_ctl((tsk), (val)) +#ifdef CONFIG_RISCV_ISA_POINTER_MASKING +/* PR_{SET,GET}_TAGGED_ADDR_CTRL prctl */ +long set_tagged_addr_ctrl (struct task_struct *task,unsigned long arg); +long get_tagged_addr_ctrl (struct task_struct *task); +#define SET_TAGGED_ADDR_CTRL (arg) set_tagged_addr_ctrl(current, arg) +#define GET_TAGGED_ADDR_CTRL () get_tagged_addr_ctrl(current) +#endif +#endif /* __ASSEMBLY__ */ #endif /* _ASM_RISCV_PROCESSOR_H */
arch/riscv/kernel/process.c +107 -0
128 lines not on this page · raw message
include/uapi/linux/prctl.h +3 -0
@@ -244,6 +244,9 @@ struct prctl_mm_map {# define PR_MTE_TAG_MASK (0xffffUL << PR_MTE_TAG_SHIFT)/* Unused; kept only for source compatibility */ # define PR_MTE_TCF_SHIFT 1 +/* RISC-V pointer masking tag length */ +# define PR_PMLEN_SHIFT 24 +# define PR_PMLEN_MASK (0x7fUL << PR_PMLEN_SHIFT)/* Control reclaim behavior when allocating memory */ #define PR_SET_IO_FLUSHER 57
Signature · 1 line
2.43.1
RFC PATCH 7/9 riscv: Add support for the tagged address ABI
In reply to Samuel HollandWhen pointer masking is enabled for userspace, the kernel can accept tagged pointers as arguments to some system calls. Allow this by untagging the pointers in access_ok() and the uaccess routines. The software untagging in the uaccess routines is required because U-mode and S-mode have entirely separate pointer masking configurations.
---
arch/riscv/include/asm/processor.h | 1 + arch/riscv/include/asm/uaccess.h | 40 +++++++++++++++++++++--- arch/riscv/kernel/process.c | 49 +++++++++++++++++++++++++++++- 3 files changed, 84 insertions(+), 6 deletions(-)
arch/riscv/include/asm/processor.h +1 -0
@@ -124,6 +124,7 @@ struct thread_struct {struct __riscv_v_ext_state vstate;unsigned long align_ctl;struct __riscv_v_ext_state kernel_vstate; +u8 pmlen; };/* Whitelist the fstate from the task_struct for hardened usercopy */
arch/riscv/include/asm/uaccess.h +35 -5
@@ -9,8 +9,38 @@#define _ASM_RISCV_UACCESS_H#include <asm/asm-extable.h> +#include <asm/cpufeature.h> #include <asm/pgtable.h> /* for TASK_SIZE */ +#ifdef CONFIG_RISCV_ISA_POINTER_MASKING +static inline unsigned long __untagged_addr (unsigned long addr) +{ +if (riscv_has_extension_unlikely (RISCV_ISA_EXT_SxNPM)) { +u8 shift = current->thread.pmlen; + +/* +* Virtual addresses are sign-extended, while +* physical addresses are zero-extended. +*/ +if (IS_ENABLED (CONFIG_MMU )) +return (long )(addr << shift) >> shift; +else +return (addr << shift) >> shift; + } + +return addr; +} + +#define untagged_addr (addr) ({ \ + unsigned long __addr = (__force unsigned long)(addr); \ + (__force __typeof__(addr))__untagged_addr(__addr); \ +}) + +#define access_ok (addr, size) likely(__access_ok(untagged_addr(addr), size)) +#else +#define untagged_addr (addr) addr +#endif +/* * User space memory access functions */
@@ -130,7 +160,7 @@ do { \*/ #define __get_user (x, ptr) \ ({ \ - const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \ + const __typeof__(*(ptr)) __user *__gu_ptr = untagged_addr(ptr); \ long __gu_err = 0; \ \ __chk_user_ptr(__gu_ptr); \
@@ -246,7 +276,7 @@ do { \*/ #define __put_user (x, ptr) \ ({ \ - __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \ + __typeof__(*(ptr)) __user *__gu_ptr = untagged_addr(ptr); \ __typeof__(*__gu_ptr) __val = (x); \ long __pu_err = 0; \ \
@@ -293,13 +323,13 @@ unsigned long __must_check __asm_copy_from_user(void *to,static inline unsigned long raw_copy_from_user (void *to,const void __user *from,unsigned long n) { -return __asm_copy_from_user (to, from, n); +return __asm_copy_from_user (to,untagged_addr (from), n); }static inline unsigned long raw_copy_to_user (void __user *to,const void *from,unsigned long n) { -return __asm_copy_to_user (to, from, n); +return __asm_copy_to_user (untagged_addr (to), from, n); }extern long strncpy_from_user (char *dest,const char __user *src,long count);
@@ -314,7 +344,7 @@ unsigned long __must_check clear_user(void __user *to, unsigned long n) {might_fault ();return access_ok (to, n) ? -__clear_user (to, n) : n; +__clear_user (untagged_addr (to), n) : n; }#define __get_kernel_nofault (dst, src, type, err_label) \
arch/riscv/kernel/process.c +48 -1
93 lines not on this page · raw message
Signature · 1 line
2.43.1
RFC PATCH 8/9 riscv: Allow ptrace control of the tagged address ABI
In reply to Samuel HollandThis allows a tracer to control the ABI of the tracee, as on arm64.
---
arch/riscv/kernel/ptrace.c | 42 ++++++++++++++++++++++++++++++++++++++ include/uapi/linux/elf.h | 1 + 2 files changed, 43 insertions(+)
arch/riscv/kernel/ptrace.c +42 -0
@@ -28,6 +28,9 @@ enum riscv_regset {#ifdef CONFIG_RISCV_ISA_V REGSET_V,#endif +#ifdef CONFIG_RISCV_ISA_POINTER_MASKING + REGSET_TAGGED_ADDR_CTRL, +#endif }; static int riscv_gpr_get(struct task_struct *target,
@@ -152,6 +155,35 @@ static int riscv_vr_set(struct task_struct *target, }#endif +#ifdef CONFIG_RISCV_ISA_POINTER_MASKING +static int tagged_addr_ctrl_get (struct task_struct *target, +const struct user_regset *regset, +struct membuf to) +{ +long ctrl =get_tagged_addr_ctrl (target); + +if (IS_ERR_VALUE (ctrl)) +return ctrl; + +return membuf_write (&to, &ctrl,sizeof (ctrl)); +} + +static int tagged_addr_ctrl_set (struct task_struct *target, +const struct user_regset *regset, +unsigned int pos,unsigned int count, +const void *kbuf,const void __user *ubuf) +{ +int ret; +long ctrl; + + ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, &ctrl,0 ,-1 ); +if (ret) +return ret; + +return set_tagged_addr_ctrl (target, ctrl); +} +#endif +static const struct user_regset riscv_user_regset[] = { [REGSET_X ] = { .core_note_type =NT_PRSTATUS ,
@@ -182,6 +214,16 @@ static const struct user_regset riscv_user_regset[] = { .set = riscv_vr_set, },#endif +#ifdef CONFIG_RISCV_ISA_POINTER_MASKING + [REGSET_TAGGED_ADDR_CTRL] = { + .core_note_type = NT_RISCV_TAGGED_ADDR_CTRL, + .n = 1, + .size = sizeof(long), + .align = sizeof(long), + .regset_get = tagged_addr_ctrl_get, + .set = tagged_addr_ctrl_set, + }, +#endif }; static const struct user_regset_view riscv_user_native_view = {
include/uapi/linux/elf.h +1 -0
@@ -447,6 +447,7 @@ typedef struct elf64_shdr {#define NT_MIPS_MSA 0x802/* MIPS SIMD registers */ #define NT_RISCV_CSR 0x900/* RISC-V Control and Status Registers */ #define NT_RISCV_VECTOR 0x901/* RISC-V vector registers */ +#define NT_RISCV_TAGGED_ADDR_CTRL 0x902/* RISC-V tagged address control (prctl()) */ #define NT_LOONGARCH_CPUCFG 0xa00/* LoongArch CPU config registers */ #define NT_LOONGARCH_CSR 0xa01/* LoongArch control and status registers */ #define NT_LOONGARCH_LSX 0xa02/* LoongArch Loongson SIMD Extension registers */
Signature · 1 line
2.43.1
RFC PATCH 9/9 selftests: riscv: Add a pointer masking test
In reply to Samuel HollandThis test covers the behavior of the PR_SET_TAGGED_ADDR_CTRL and PR_GET_TAGGED_ADDR_CTRL prctl() operations, their effects on the userspace ABI, and their effects on the system call ABI.
---
tools/testing/selftests/riscv/Makefile | 2 +- tools/testing/selftests/riscv/tags/Makefile | 10 + .../selftests/riscv/tags/pointer_masking.c | 307 ++++++++++++++++++ 3 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/riscv/tags/Makefile create mode 100644 tools/testing/selftests/riscv/tags/pointer_masking.c
tools/testing/selftests/riscv/Makefile +1 -1
@@ -5,7 +5,7 @@ ARCH ?= $(shell uname -m 2>/dev/null || echo not) ifneq (,$(filter $(ARCH),riscv)) -RISCV_SUBTARGETS ?= hwprobe vector mm +RISCV_SUBTARGETS ?= hwprobe mm tags vector else RISCV_SUBTARGETS := endif
tools/testing/selftests/riscv/tags/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 + +CFLAGS += -I$(top_srcdir)/tools/include + +TEST_GEN_PROGS := pointer_masking + +include ../../lib.mk + +$(OUTPUT)/pointer_masking: pointer_masking.c + $(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^
tools/testing/selftests/riscv/tags/pointer_masking.c new file +307 -0
307 lines not on this page · raw message
Signature · 1 line
2.43.1
Re: [RFC PATCH 9/9] selftests: riscv: Add a pointer masking test
Quoted 10 lines · Samuel Holland
This test covers the behavior of the
PR_SET_TAGGED_ADDR_CTRLandPR_GET_TAGGED_ADDR_CTRLprctl()operations, their effects on the userspace ABI, and their effects on the system call ABI.Signed-off-by Samuel Holland <[email protected]>---
tools/testing/selftests/riscv/Makefile | 2 +- tools/testing/selftests/riscv/tags/Makefile | 10 + .../selftests/riscv/tags/pointer_masking.c | 307 ++++++++++++++++++
I dunno much about selftests, but this patch seems to produce some
warnings about gitignores with allmodconfig:tools/testing/selftests/riscv/tags/Makefile: warning: ignored by one of the .gitignore files tools/testing/selftests/riscv/tags/pointer_masking.c: warning: ignored by one of the .gitignore files
Re: [RFC PATCH 9/9] selftests: riscv: Add a pointer masking test
Hi Conor,
Quoted 8 lines · Conor Dooley
Quoted 7 lines · Samuel Holland
This test covers the behavior of the
PR_SET_TAGGED_ADDR_CTRLandPR_GET_TAGGED_ADDR_CTRLprctl()operations, their effects on the userspace ABI, and their effects on the system call ABI.Signed-off-by Samuel Holland <[email protected]>---
Quoted 8 lines
Quoted 3 lines
tools/testing/selftests/riscv/Makefile | 2 +- tools/testing/selftests/riscv/tags/Makefile | 10 + .../selftests/riscv/tags/pointer_masking.c | 307 ++++++++++++++++++I dunno much about selftests, but this patch seems to produce some
warnings about gitignores with allmodconfig:tools/testing/selftests/riscv/tags/Makefile: warning: ignored by one of the .gitignore filestools/testing/selftests/riscv/tags/pointer_masking.c: warning: ignored by one of the .gitignore files
This is because the "tags" directory name is ignored by the top-level .gitignore. I chose the name to match tools/testing/selftests/arm64/tags, but I am fine with renaming it to avoid the warning.
Regards,
Samuel