arch/riscv: add proc status (proc/<pid>/status)
RFC PATCH 1/1 arch/riscv: add proc status (proc/<pid>/status)
x86 has proc/<pid>/status to see various runtime characteristics of running task. Implement same for riscv. This patch implements status for shadow stack and landing pad state.
---
This is just a one patch but sending it as RFC with cover letter to seek feedback. x86 has arch_proc_pid_thread_features to enumerate status of arch thread specific features on runtime. This can be done using prctl as well but from quick/script perspective cat /proc/<pid>/status is more desirable. In this patch, simply arch_proc_pid_thread_features is implemented for riscv which queries shadow stack and landing pad state and reports back. Thus it is dependent on riscv user cfi enabling series.
If this patch itself is self-standing and good enough, I can roll this patch as part of riscv user cfi enabling series.
OR
If there is ask for other riscv thread specific features that could be enumerated in similar fashion, we will need it to be done as separate series (with thread_features added to thread_info)
Example output below.
Name: cat Umask: 0022 State: R (running) Tgid: 133 Ngid: 0 Pid: 133 PPid: 129 TracerPid: 0 Uid: 0 0 0 0 Gid: 0 0 0 0 FDSize: 256 Groups: 0 10 NStgid: 133 NSpid: 133 NSpgid: 133 NSsid: 129 Kthread: 0 VmPeak: 10788 kB VmSize: 10788 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 1400 kB VmRSS: 1400 kB RssAnon: 116 kB RssFile: 1284 kB RssShmem: 0 kB VmData: 92 kB VmStk: 8324 kB VmExe: 4 kB VmLib: 2312 kB VmPTE: 40 kB VmSwap: 0 kB HugetlbPages: 0 kB CoreDumping: 0 THP_enabled: 0 untag_mask: 0xffffffffffffffff Threads: 1 SigQ: 0/31771 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000000000 SigIgn: 0000000000000000 SigCgt: 0000000000000000 CapInh: 0000000000000000 CapPrm: 000001ffffffffff CapEff: 000001ffffffffff CapBnd: 000001ffffffffff CapAmb: 0000000000000000 NoNewPrivs: 0 Seccomp: 0 Seccomp_filters: 0 Speculation_Store_Bypass: unknown SpeculationIndirectBranch: unsupported Cpus_allowed: 3 Cpus_allowed_list: 0-1 Mems_allowed: 1 Mems_allowed_list: 0 voluntary_ctxt_switches: 0 nonvoluntary_ctxt_switches: 3 riscv_thread_features: shstk_enabled lpad_enabled riscv_thread_features_locked: shstk_unlocked lpad_unlocked --- arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/cpu/Makefile | 1 + arch/riscv/kernel/cpu/proc.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+)
arch/riscv/kernel/Makefile +1 -0
@@ -71,6 +71,7 @@ obj-y += vendor_extensions.o obj-y += vendor_extensions/ obj-y += probes/ obj-y += tests/ +obj-y += cpu/ obj-$(CONFIG_MMU) += vdso.o vdso/ obj-$(CONFIG_RISCV_MISALIGNED) += traps_misaligned.o
arch/riscv/kernel/cpu/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_PROC_FS) += proc.o
arch/riscv/kernel/cpu/proc.c new file +28 -0
@@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/smp.h> +#include <linux/timex.h> +#include <linux/string.h> +#include <linux/seq_file.h> +#include <linux/cpufreq.h> +#include <linux/proc_fs.h> +#include <asm/usercfi.h> + +#ifdef CONFIG_RISCV_USER_CFI + +void arch_proc_pid_thread_features (struct seq_file *m,struct task_struct *task) +{ +seq_puts (m,"riscv_thread_features:\t" ); +if (is_shstk_enabled (task)) +seq_puts (m,"shstk_enabled " ); + +if (is_indir_lp_enabled (task)) +seq_puts (m,"lpad_enabled " ); + +seq_putc (m,'\n' ); + +seq_puts (m,"riscv_thread_features_locked:\t" ); +is_shstk_locked (task) ?seq_puts (m,"shstk_locked " ) :seq_puts (m,"shstk_unlocked " ); +is_indir_lp_locked (task) ?seq_puts (m,"lpad_locked " ) :seq_puts (m,"lpad_unlocked " ); +seq_putc (m,'\n' ); +} +#endif /* CONFIG_RISCV_USER_CFI */
---
base-commit: 3a8660878839faadb4f1a6dd72c3179c1df56787
change-id: 20251017-proc_status-df1aedc85c7c --
- debug
Quoted 5 lines · Deepak Gupta
x86 has proc/<pid>/status to see various runtime characteristics of running task. Implement same for riscv. This patch implements status for shadow stack and landing pad state.
Signed-off-by Deepak Gupta <[email protected]>
Quoted 8 lines
---
This is just a one patch but sending it as RFC with cover letter to seek feedback. x86 hasarch_proc_pid_thread_featuresto enumerate status of arch thread specific features on runtime. This can be done using prctl as well but from quick/script perspectivecat /proc/<pid>/statusis more desirable. In this patch, simplyarch_proc_pid_thread_featuresis implemented for riscv which queries shadow stack and landing pad state and reports back. Thus it is dependent on riscv user cfi enabling series.
Hello Deepak,
This looks like a valuable addition.
Shouldn't architecture specific fields be in /proc/<pid>/arch_status and not in /proc/<pid>/status?
Please, add a documentation patch adding the RISC-V specific fields to "3.12 /proc/<pid>/arch_status - Task architecture specific information" in Documentation/filesystems/proc.rst.
Should you stick to /proc/*/status, please, add the documentation to Documentation/arch/riscv/.
Quoted 110 lines
If this patch itself is self-standing and good enough, I can roll this patch as part of riscv user cfi enabling series.
OR
If there is ask for other riscv thread specific features that could be enumerated in similar fashion, we will need it to be done as separate series (with
thread_featuresadded tothread_info)Example output below.
Name: cat Umask: 0022 State: R (running) Tgid: 133 Ngid: 0 Pid: 133 PPid: 129 TracerPid: 0 Uid: 0 0 0 0 Gid: 0 0 0 0 FDSize: 256 Groups: 0 10 NStgid: 133 NSpid: 133 NSpgid: 133 NSsid: 129 Kthread: 0 VmPeak: 10788 kB VmSize: 10788 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 1400 kB VmRSS: 1400 kB RssAnon: 116 kB RssFile: 1284 kB RssShmem: 0 kB VmData: 92 kB VmStk: 8324 kB VmExe: 4 kB VmLib: 2312 kB VmPTE: 40 kB VmSwap: 0 kB HugetlbPages: 0 kB CoreDumping: 0 THP_enabled: 0 untag_mask: 0xffffffffffffffff Threads: 1 SigQ: 0/31771 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000000000 SigIgn: 0000000000000000 SigCgt: 0000000000000000 CapInh: 0000000000000000 CapPrm: 000001ffffffffff CapEff: 000001ffffffffff CapBnd: 000001ffffffffff CapAmb: 0000000000000000 NoNewPrivs: 0 Seccomp: 0 Seccomp_filters: 0 Speculation_Store_Bypass: unknown SpeculationIndirectBranch: unsupported Cpus_allowed: 3 Cpus_allowed_list: 0-1 Mems_allowed: 1 Mems_allowed_list: 0 voluntary_ctxt_switches: 0 nonvoluntary_ctxt_switches: 3 riscv_thread_features: shstk_enabled lpad_enabled riscv_thread_features_locked: shstk_unlocked lpad_unlocked --- arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/cpu/Makefile | 1 + arch/riscv/kernel/cpu/proc.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+)arch/riscv/kernel/Makefile +1
-0@@ -71,6 +71,7 @@ obj-y += vendor_extensions.o obj-y += vendor_extensions/ obj-y += probes/ obj-y += tests/ +obj-y += cpu/ obj-$(CONFIG_MMU) += vdso.o vdso/ obj-$(CONFIG_RISCV_MISALIGNED) += traps_misaligned.oarch/riscv/kernel/cpu/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-$(CONFIG_PROC_FS) += proc.oarch/riscv/kernel/cpu/proc.c new file +6
-0@@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/smp.h> +#include <linux/timex.h> +#include <linux/string.h> +#include <linux/seq_file.h> +#include <linux/cpufreq.h>
arch/riscv/kernel/cpu/proc.c line 16
Quoted 10 lines
arch/riscv/kernel/cpu/proc.c new file +10
-0+#include <linux/proc_fs.h> +#include <asm/usercfi.h> + +#ifdef CONFIG_RISCV_USER_CFI + +void arch_proc_pid_thread_features (struct seq_file *m,struct task_struct *task) +{ +seq_puts (m,"riscv_thread_features:\t" ); +if (is_shstk_enabled (task)) +seq_puts (m,"shstk_enabled " );
According to Documentation/arch/x86/shstk.rst, x86 is avoiding the '_enabled' postfix here:
x86_Thread_features: shstk wrss
arch/riscv/kernel/cpu/proc.c line 25
Quoted 9 lines
arch/riscv/kernel/cpu/proc.c new file +9
-0+ +if (is_indir_lp_enabled (task)) +seq_puts (m,"lpad_enabled " ); + +seq_putc (m,'\n' ); + +seq_puts (m,"riscv_thread_features_locked:\t" ); +is_shstk_locked (task) ?seq_puts (m,"shstk_locked " ) :seq_puts (m,"shstk_unlocked " ); +is_indir_lp_locked (task) ?seq_puts (m,"lpad_locked " ) :seq_puts (m,"lpad_unlocked " );
Why do we need any entry for an unlocked feature in riscv_thread_features_locked?
Best regards
Heinrich
Quoted 10 lines
arch/riscv/kernel/cpu/proc.c new file +3
-1+ seq_putc(m, '\n'); +} +#endif /* CONFIG_RISCV_USER_CFI */ ---base-commit:
3a8660878839faadb4f1a6dd72c3179c1df56787
change-id: 20251017-proc_status-df1aedc85c7c --
- debug
Hi Hienrich,
Quoted 15 lines · Heinrich Schuchardt
Quoted 5 lines · Deepak Gupta
x86 has proc/<pid>/status to see various runtime characteristics of running task. Implement same for riscv. This patch implements status for shadow stack and landing pad state.
Signed-off-by Deepak Gupta <[email protected]>Quoted 8 lines
---
This is just a one patch but sending it as RFC with cover letter to seek feedback. x86 hasarch_proc_pid_thread_featuresto enumerate status of arch thread specific features on runtime. This can be done using prctl as well but from quick/script perspectivecat /proc/<pid>/statusis more desirable. In this patch, simplyarch_proc_pid_thread_featuresis implemented for riscv which queries shadow stack and landing pad state and reports back. Thus it is dependent on riscv user cfi enabling series.
Quoted 6 lines
Hello Deepak,
This looks like a valuable addition.
Shouldn't architecture specific fields be in /proc/<pid>/arch_status and not in /proc/<pid>/status?
Just following what x86 did. I believe shadow stack and landing pad are there in arm64, x86 and riscv. So probably /proc/<pid>/status is best place.
Quoted 6 lines
Please, add a documentation patch adding the RISC-V specific fields to "3.12 /proc/<pid>/arch_status - Task architecture specific information" in
Documentation/filesystems/proc.rst.Should you stick to
/proc/*/status, please, add the documentation toDocumentation/arch/riscv/.
Will do.
Quoted 123 lines
Quoted 110 lines
If this patch itself is self-standing and good enough, I can roll this patch as part of riscv user cfi enabling series.
OR
If there is ask for other riscv thread specific features that could be enumerated in similar fashion, we will need it to be done as separate series (with
thread_featuresadded tothread_info)Example output below.
Name: cat Umask: 0022 State: R (running) Tgid: 133 Ngid: 0 Pid: 133 PPid: 129 TracerPid: 0 Uid: 0 0 0 0 Gid: 0 0 0 0 FDSize: 256 Groups: 0 10 NStgid: 133 NSpid: 133 NSpgid: 133 NSsid: 129 Kthread: 0 VmPeak: 10788 kB VmSize: 10788 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 1400 kB VmRSS: 1400 kB RssAnon: 116 kB RssFile: 1284 kB RssShmem: 0 kB VmData: 92 kB VmStk: 8324 kB VmExe: 4 kB VmLib: 2312 kB VmPTE: 40 kB VmSwap: 0 kB HugetlbPages: 0 kB CoreDumping: 0 THP_enabled: 0 untag_mask: 0xffffffffffffffff Threads: 1 SigQ: 0/31771 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000000000 SigIgn: 0000000000000000 SigCgt: 0000000000000000 CapInh: 0000000000000000 CapPrm: 000001ffffffffff CapEff: 000001ffffffffff CapBnd: 000001ffffffffff CapAmb: 0000000000000000 NoNewPrivs: 0 Seccomp: 0 Seccomp_filters: 0 Speculation_Store_Bypass: unknown SpeculationIndirectBranch: unsupported Cpus_allowed: 3 Cpus_allowed_list: 0-1 Mems_allowed: 1 Mems_allowed_list: 0 voluntary_ctxt_switches: 0 nonvoluntary_ctxt_switches: 3 riscv_thread_features: shstk_enabled lpad_enabled riscv_thread_features_locked: shstk_unlocked lpad_unlocked --- arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/cpu/Makefile | 1 + arch/riscv/kernel/cpu/proc.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+)arch/riscv/kernel/Makefile +1
-0@@ -71,6 +71,7 @@ obj-y += vendor_extensions.o obj-y += vendor_extensions/ obj-y += probes/ obj-y += tests/ +obj-y += cpu/ obj-$(CONFIG_MMU) += vdso.o vdso/ obj-$(CONFIG_RISCV_MISALIGNED) += traps_misaligned.oarch/riscv/kernel/cpu/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-$(CONFIG_PROC_FS) += proc.oarch/riscv/kernel/cpu/proc.c new file +6
-0@@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/smp.h> +#include <linux/timex.h> +#include <linux/string.h> +#include <linux/seq_file.h> +#include <linux/cpufreq.h> arch/riscv/kernel/cpu/proc.c line 16
Quoted 10 lines
arch/riscv/kernel/cpu/proc.c new file +10
-0+#include <linux/proc_fs.h> +#include <asm/usercfi.h> + +#ifdef CONFIG_RISCV_USER_CFI + +void arch_proc_pid_thread_features (struct seq_file *m,struct task_struct *task) +{ +seq_puts (m,"riscv_thread_features:\t" ); +if (is_shstk_enabled (task)) +seq_puts (m,"shstk_enabled " );According to
Documentation/arch/x86/shstk.rst, x86 is avoiding the '_enabled' postfix here:
Quoted 1 line
x86_Thread_features: shstk wrss
I can follow same and use shstk. We don't have wrss because shadow stack is writeable by right instruction (sspush and ssamoswap) in riscv.
Quoted 4 lines
arch/riscv/kernel/cpu/proc.c line 19
Quoted 4 lines
arch/riscv/kernel/cpu/proc.c new file +3
-0+ +if (is_indir_lp_enabled (task)) +seq_puts (m,"lpad_enabled " );
Would you prefer similar here. Just "lpad"?
Quoted 8 lines
arch/riscv/kernel/cpu/proc.c line 25
Quoted 6 lines
arch/riscv/kernel/cpu/proc.c new file +6
-0+ +seq_putc (m,'\n' ); + +seq_puts (m,"riscv_thread_features_locked:\t" ); +is_shstk_locked (task) ?seq_puts (m,"shstk_locked " ) :seq_puts (m,"shstk_unlocked " ); +is_indir_lp_locked (task) ?seq_puts (m,"lpad_locked " ) :seq_puts (m,"lpad_unlocked " );Why do we need any entry for an unlocked feature in
riscv_thread_features_locked?
absence of "feature_locked" is considered unlocked, then I can drop it.
Quoted 16 lines
Best regards
Heinrich
Quoted 10 lines
arch/riscv/kernel/cpu/proc.c new file +3
-1+ seq_putc(m, '\n'); +} +#endif /* CONFIG_RISCV_USER_CFI */ ---base-commit:
3a8660878839faadb4f1a6dd72c3179c1df56787
change-id: 20251017-proc_status-df1aedc85c7c --
- debug
Quoted 168 lines · Deepak Gupta
Hi Hienrich,
Quoted 15 lines · Heinrich Schuchardt
Quoted 5 lines · Deepak Gupta
x86 has proc/<pid>/status to see various runtime characteristics of running task. Implement same for riscv. This patch implements status for shadow stack and landing pad state.
Signed-off-by Deepak Gupta <[email protected]>Quoted 8 lines
---
This is just a one patch but sending it as RFC with cover letter to seek feedback. x86 hasarch_proc_pid_thread_featuresto enumerate status of arch thread specific features on runtime. This can be done using prctl as well but from quick/script perspectivecat /proc/<pid>/statusis more desirable. In this patch, simplyarch_proc_pid_thread_featuresis implemented for riscv which queries shadow stack and landing pad state and reports back. Thus it is dependent on riscv user cfi enabling series.Quoted 6 lines
Hello Deepak,
This looks like a valuable addition.
Shouldn't architecture specific fields be in /proc/<pid>/arch_status and not in /proc/<pid>/status?
Just following what x86 did. I believe shadow stack and landing pad are there in arm64, x86 and riscv. So probably /proc/<pid>/status is best place.
Quoted 6 lines
Please, add a documentation patch adding the RISC-V specific fields to "3.12 /proc/<pid>/arch_status - Task architecture specific information" in
Documentation/filesystems/proc.rst.Should you stick to
/proc/*/status, please, add the documentation toDocumentation/arch/riscv/.Will do.
Quoted 124 lines
Quoted 116 lines
If this patch itself is self-standing and good enough, I can roll this patch as part of riscv user cfi enabling series.
OR
If there is ask for other riscv thread specific features that could be enumerated in similar fashion, we will need it to be done as separate series (with
thread_featuresadded tothread_info)Example output below.
Name: cat
Umask: 0022
State: R (running)
Tgid: 133
Ngid: 0
Pid: 133
PPid: 129
TracerPid: 0
Uid: 0 0 0 0
Gid: 0 0 0 0
FDSize: 256
Groups: 0 10
NStgid: 133
NSpid: 133
NSpgid: 133
NSsid: 129
Kthread: 0
VmPeak: 10788 kB
VmSize: 10788 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: 1400 kB
VmRSS: 1400 kB
RssAnon: 116 kB
RssFile: 1284 kB
RssShmem: 0 kB
VmData: 92 kB
VmStk: 8324 kB
VmExe: 4 kB
VmLib: 2312 kB
VmPTE: 40 kB
VmSwap: 0 kB
HugetlbPages: 0 kB
CoreDumping: 0
THP_enabled: 0
untag_mask:0xffffffffffffffff
Threads: 1
SigQ: 0/31771
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000000000
SigCgt: 0000000000000000
CapInh: 0000000000000000
CapPrm:000001ffffffffff
CapEff:000001ffffffffff
CapBnd:000001ffffffffff
CapAmb: 0000000000000000
NoNewPrivs: 0
Seccomp: 0
Seccomp_filters: 0
Speculation_Store_Bypass: unknown SpeculationIndirectBranch: unsupported Cpus_allowed: 3
Cpus_allowed_list: 0-1
Mems_allowed: 1
Mems_allowed_list: 0
voluntary_ctxt_switches: 0 nonvoluntary_ctxt_switches: 3 riscv_thread_features:shstk_enabledlpad_enabledriscv_thread_features_locked:shstk_unlockedlpad_unlocked
---
arch/riscv/kernel/Makefile | 1 +arch/riscv/kernel/cpu/Makefile| 1 + arch/riscv/kernel/cpu/proc.c | 28 ++++++++++++++++++++++++++++3 files changed, 30 insertions(+)arch/riscv/kernel/Makefile +0
-0@@ -71,6 +71,7 @@ obj-y += vendor_extensions.oobj-y += vendor_extensions/
obj-y += probes/
obj-y += tests/
+obj-y += cpu/
obj-$(CONFIG_MMU) += vdso.o vdso/ obj-$(CONFIG_RISCV_MISALIGNED) += traps_misaligned.oarch/riscv/kernel/cpu/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-$(CONFIG_PROC_FS) += proc.oarch/riscv/kernel/cpu/proc.c new file +12
-0@@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/smp.h> +#include <linux/timex.h> +#include <linux/string.h> +#include <linux/seq_file.h> +#include <linux/cpufreq.h> +#include <linux/proc_fs.h> +#include <asm/usercfi.h> + +#ifdef CONFIG_RISCV_USER_CFI + +void arch_proc_pid_thread_features(struct seq_file *m, structQuoted 5 lines
task_struct*task)
+{
+seq_puts(m, "riscv_thread_features:\t");
+ if (is_shstk_enabled(task))
+seq_puts(m, "shstk_enabled ");According to
Documentation/arch/x86/shstk.rst, x86 is avoiding the '_enabled' postfix here:Quoted 1 line
x86_Thread_features: shstk wrssI can follow same and use
shstk. We don't havewrssbecause shadow stack is writeable by right instruction (sspush and ssamoswap) in riscv.Quoted 1 line
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
+
+ if (is_indir_lp_enabled(task))
+seq_puts(m, "lpad_enabled ");Would you prefer similar here. Just "lpad"?
That would be consistent with what is done for x86.
Best regards
Heinrich
Quoted 30 lines
Quoted 11 lines
Quoted 9 lines
arch/riscv/kernel/cpu/proc.c new file +5
-0+ + seq_putc(m, '\n'); + + seq_puts(m, "riscv_thread_features_locked:\t"); + is_shstk_locked(task) ? seq_puts(m, "shstk_locked ") :
seq_puts(m, "shstk_unlocked ");
+is_indir_lp_locked(task)?seq_puts(m, "lpad_locked "):seq_puts(m, "lpad_unlocked ");Why do we need any entry for an unlocked feature in
riscv_thread_features_locked?absence of "
feature_locked" is considered unlocked, then I can drop it.Quoted 16 lines
Best regards
Heinrich
Quoted 10 lines
+
seq_putc(m, '\n');arch/riscv/kernel/cpu/proc.c new file +2
-1+} +#endif /* CONFIG_RISCV_USER_CFI */ ---base-commit:
3a8660878839faadb4f1a6dd72c3179c1df56787
change-id: 20251017-proc_status-df1aedc85c7cSignature · 1 line
- debug
Valentin Haudiquet
Tested-byQuoted 223 lines · Heinrich Schuchardt
Quoted 177 lines · Deepak Gupta
Hi Hienrich,
Quoted 18 lines · Heinrich Schuchardt
Quoted 5 lines · Deepak Gupta
x86 has proc/<pid>/status to see various runtime characteristics of running task. Implement same for riscv. This patch implements status for shadow stack and landing pad state.
Signed-off-by Deepak Gupta <[email protected]>Quoted 11 lines
---
This is just a one patch but sending it as RFC with cover letter to seek feedback. x86 hasarch_proc_pid_thread_featuresto enumerate status of arch thread specific features on runtime. This can be done using prctl as well but from quick/script perspectivecat /proc/<pid>/statusis more
desirable. In this patch, simplyarch_proc_pid_thread_featuresis implemented
for riscv which queries shadow stack and landing pad state and reports back.
Thus it is dependent on riscv user cfi enabling series.Quoted 6 lines
Hello Deepak,
This looks like a valuable addition.
Shouldn't architecture specific fields be in /proc/<pid>/arch_status and not in /proc/<pid>/status?
Just following what x86 did. I believe shadow stack and landing pad are there
in arm64, x86 and riscv. So probably /proc/<pid>/status is best place.Quoted 7 lines
Please, add a documentation patch adding the RISC-V specific fields to "3.12 /proc/<pid>/arch_status - Task architecture specific information" in
Documentation/filesystems/proc.rst.Should you stick to
/proc/*/status, please, add the documentation toDocumentation/arch/riscv/.Will do.
Quoted 128 lines
Quoted 120 lines
If this patch itself is self-standing and good enough, I can roll this patch
as part of riscv user cfi enabling series.OR
If there is ask for other riscv thread specific features that could be enumerated in similar fashion, we will need it to be done as separate series
(withthread_featuresadded tothread_info)Example output below.
Name: cat Umask: 0022 State: R (running) Tgid: 133 Ngid: 0 Pid: 133 PPid: 129 TracerPid: 0 Uid: 0 0 0 0 Gid: 0 0 0 0 FDSize: 256 Groups: 0 10 NStgid: 133 NSpid: 133 NSpgid: 133 NSsid: 129 Kthread: 0 VmPeak: 10788 kB VmSize: 10788 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 1400 kB VmRSS: 1400 kB RssAnon: 116 kB RssFile: 1284 kB RssShmem: 0 kB VmData: 92 kB VmStk: 8324 kB VmExe: 4 kB VmLib: 2312 kB VmPTE: 40 kB VmSwap: 0 kB HugetlbPages: 0 kB CoreDumping: 0 THP_enabled: 0 untag_mask: 0xffffffffffffffff Threads: 1 SigQ: 0/31771 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000000000 SigIgn: 0000000000000000 SigCgt: 0000000000000000 CapInh: 0000000000000000 CapPrm: 000001ffffffffff CapEff: 000001ffffffffff CapBnd: 000001ffffffffff CapAmb: 0000000000000000 NoNewPrivs: 0 Seccomp: 0 Seccomp_filters: 0 Speculation_Store_Bypass: unknown SpeculationIndirectBranch: unsupported Cpus_allowed: 3 Cpus_allowed_list: 0-1 Mems_allowed: 1 Mems_allowed_list: 0 voluntary_ctxt_switches: 0 nonvoluntary_ctxt_switches: 3 riscv_thread_features: shstk_enabled lpad_enabled riscv_thread_features_locked: shstk_unlocked lpad_unlocked --- arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/cpu/Makefile | 1 + arch/riscv/kernel/cpu/proc.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+)arch/riscv/kernel/Makefile +1
-0@@ -71,6 +71,7 @@ obj-y += vendor_extensions.o obj-y += vendor_extensions/ obj-y += probes/ obj-y += tests/ +obj-y += cpu/ obj-$(CONFIG_MMU) += vdso.o vdso/ obj-$(CONFIG_RISCV_MISALIGNED) += traps_misaligned.oarch/riscv/kernel/cpu/ renamed from arch/riscv/kernel/cpu/Makefile +0
-0
Makefile
new file mode 100644
index 000000000000..2b474fb49afearch/riscv/kernel/cpu/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-$(CONFIG_PROC_FS) += proc.oarch/riscv/kernel/cpu/proc.c new file +12
-0@@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/smp.h> +#include <linux/timex.h> +#include <linux/string.h> +#include <linux/seq_file.h> +#include <linux/cpufreq.h> +#include <linux/proc_fs.h> +#include <asm/usercfi.h> + +#ifdef CONFIG_RISCV_USER_CFI + +void arch_proc_pid_thread_features(struct seq_file *m, struct
task_struct*task)arch/riscv/kernel/cpu/proc.c line 16
Quoted 4 lines
arch/riscv/kernel/cpu/proc.c new file +4
-0+{ +seq_puts (m,"riscv_thread_features:\t" ); +if (is_shstk_enabled (task)) +seq_puts (m,"shstk_enabled " );According to
Documentation/arch/x86/shstk.rst, x86 is avoiding the '_enabled' postfix here:Quoted 1 line
x86_Thread_features: shstk wrssI can follow same and use
shstk. We don't havewrssbecause shadow stack is writeable by right instruction (sspush and ssamoswap) in riscv.Quoted 1 line
Quoted 5 lines
Quoted 3 lines
arch/riscv/kernel/cpu/proc.c line 19
Quoted 3 lines
arch/riscv/kernel/cpu/proc.c new file +3
-0+ +if (is_indir_lp_enabled (task)) +seq_puts (m,"lpad_enabled " );Would you prefer similar here. Just "lpad"?
That would be consistent with what is done for x86.
Best regards
Heinrich
Quoted 31 lines
Quoted 12 lines
Quoted 9 lines
arch/riscv/kernel/cpu/proc.c new file +5
-0+ +seq_putc (m,'\n' ); + +seq_puts (m,"riscv_thread_features_locked:\t" ); + is_shstk_locked(task) ? seq_puts(m, "shstk_locked ") :
seq_puts(m, "shstk_unlocked ");
+is_indir_lp_locked(task)?seq_puts(m, "lpad_locked "):seq_puts(m, "lpad_unlocked ");Why do we need any entry for an unlocked feature in
riscv_thread_features_locked?absence of "
feature_locked" is considered unlocked, then I can drop it.Quoted 16 lines
Best regards
Heinrich
Quoted 10 lines
arch/riscv/kernel/cpu/proc.c new file +3
-1+ seq_putc(m, '\n'); +} +#endif /* CONFIG_RISCV_USER_CFI */ ---base-commit:
3a8660878839faadb4f1a6dd72c3179c1df56787
change-id: 20251017-proc_status-df1aedc85c7c --
- debug
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Deepak,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on 3a8660878839faadb4f1a6dd72c3179c1df56787]
url: https://github.com/intel-lab-lkp/linux/commits/Deepak-Gupta/arch-riscv-add-proc-status-proc-pid-status/20251021-022001 base: 3a8660878839faadb4f1a6dd72c3179c1df56787 patch link: https://lore.kernel.org/r/20251020-proc_status-v1-1-59d2c8ccd4f0%40rivosinc.com patch subject: [PATCH RFC] arch/riscv: add proc status (proc/<pid>/status) config: riscv-randconfig-001-20251021 (https://download.01.org/0day-ci/archive/20251021/[email protected]/config) compiler: riscv64-linux-gcc (GCC) 8.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251021/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> arch/riscv/kernel/cpu/proc.c:8:10: fatal error: asm/usercfi.h: No such file or directory
#include <asm/usercfi.h>
^~~~~~~~~~~~~~~compilation terminated.
vim +8 arch/riscv/kernel/cpu/proc.c
> 8 #include <asm/usercfi.h>
9 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Deepak,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on 3a8660878839faadb4f1a6dd72c3179c1df56787]
url: https://github.com/intel-lab-lkp/linux/commits/Deepak-Gupta/arch-riscv-add-proc-status-proc-pid-status/20251021-022001 base: 3a8660878839faadb4f1a6dd72c3179c1df56787 patch link: https://lore.kernel.org/r/20251020-proc_status-v1-1-59d2c8ccd4f0%40rivosinc.com patch subject: [PATCH RFC] arch/riscv: add proc status (proc/<pid>/status) config: riscv-randconfig-002-20251021 (https://download.01.org/0day-ci/archive/20251021/[email protected]/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 754ebc6ebb9fb9fbee7aef33478c74ea74949853) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251021/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> arch/riscv/kernel/cpu/proc.c:8:10: fatal error: 'asm/usercfi.h' file not found
8 | #include <asm/usercfi.h>
| ^~~~~~~~~~~~~~~
1 error generated.
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for DRM_GEM_SHMEM_HELPER Depends on [n]: HAS_IOMEM [=y] && DRM [=y] && MMU [=n] Selected by [y]:
- DRM_PIXPAPER [=y] && HAS_IOMEM [=y] && DRM [=y] && SPI [=y]
WARNING: unmet direct dependencies detected for ARCH_HAS_ELF_CORE_EFLAGS Depends on [n]: BINFMT_ELF [=n] && ELF_CORE [=y]
Selected by [y]:
- RISCV [=y]
vim +8 arch/riscv/kernel/cpu/proc.c
> 8 #include <asm/usercfi.h>
9 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki