RISC-V: Add support for Ztso
Subsystems (2)
PATCH 1/1 RISC-V: Add support for Ztso
The Ztso extension was recently frozen, this adds support for running binaries that depend on TSO on systems that support Ztso.
---
This is very minimaly tested: I can run no-Ztso binaries on both yes-Ztso and no-Ztso QEMU instances, but I don't have a yes-Ztso userspace together in order to make sure that works.
--- arch/riscv/include/asm/elf.h | 18 ++++++++++++++++-- arch/riscv/include/asm/hwcap.h | 3 +++ arch/riscv/kernel/cpu.c | 1 + arch/riscv/kernel/cpufeature.c | 3 +++ 4 files changed, 23 insertions(+), 2 deletions(-)
arch/riscv/include/asm/elf.h +16 -2
@@ -14,6 +14,7 @@#include <asm/auxvec.h> #include <asm/byteorder.h> #include <asm/cacheinfo.h> +#include <asm/hwcap.h> /* * These are used to set parameters in the core dumps.
@@ -31,10 +32,23 @@#define ELF_DATA ELFDATA2LSB/* -* This is used to ensure we don't load something for the wrong architecture. +* Binaries that assume TSO cannot be correctly run on non-TSO systems, so +* prevent them from even being loaded. +*/ +#define EF_RISCV_TSO 0x0010 + +static inline int riscv_elf_tso_ok (long eflags) +{ +return likely (!(eflags &EF_RISCV_TSO )) || riscv_tso_hw; +} + +/* +* This is used to ensure we don't load something for the wrong architecture or +* variant. */ #define elf_check_arch (x) (((x)->e_machine == EM_RISCV) && \ - ((x)->e_ident[EI_CLASS] == ELF_CLASS)) + ((x)->e_ident[EI_CLASS] == ELF_CLASS) && \ + riscv_elf_tso_ok((x)->e_flags))extern bool compat_elf_check_arch (Elf32_Ehdr *hdr);#define compat_elf_check_arch compat_elf_check_arch
arch/riscv/include/asm/hwcap.h +3 -0
@@ -36,6 +36,8 @@ extern unsigned long elf_hwcap;#define RISCV_ISA_EXT_s ('s' - 'a')#define RISCV_ISA_EXT_u ('u' - 'a') +extern bool riscv_tso_hw; +/* * Increse this to higher value as kernel support more ISA extensions. */
@@ -58,6 +60,7 @@ enum riscv_isa_ext_id {RISCV_ISA_EXT_ZICBOM ,RISCV_ISA_EXT_ZIHINTPAUSE ,RISCV_ISA_EXT_SSTC , +RISCV_ISA_EXT_ZTSO , RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX, };
arch/riscv/kernel/cpu.c +1 -0
@@ -95,6 +95,7 @@ static struct riscv_isa_ext_data isa_ext_arr[] = {__RISCV_ISA_EXT_DATA (svpbmt,RISCV_ISA_EXT_SVPBMT ),__RISCV_ISA_EXT_DATA (zicbom,RISCV_ISA_EXT_ZICBOM ),__RISCV_ISA_EXT_DATA (zihintpause,RISCV_ISA_EXT_ZIHINTPAUSE ), +__RISCV_ISA_EXT_DATA (ztso,RISCV_ISA_EXT_ZTSO ),__RISCV_ISA_EXT_DATA (sstc,RISCV_ISA_EXT_SSTC ), __RISCV_ISA_EXT_DATA("", RISCV_ISA_EXT_MAX), };
arch/riscv/kernel/cpufeature.c +3 -0
@@ -25,6 +25,8 @@unsigned long elf_hwcap__read_mostly ; +bool riscv_tso_hw__read_mostly ; +/* Host ISA bitmap */ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;
@@ -204,6 +206,7 @@ void __init riscv_fill_hwcap(void)SET_ISA_EXT_MAP ("zicbom" ,RISCV_ISA_EXT_ZICBOM );SET_ISA_EXT_MAP ("zihintpause" ,RISCV_ISA_EXT_ZIHINTPAUSE );SET_ISA_EXT_MAP ("sstc" ,RISCV_ISA_EXT_SSTC ); +SET_ISA_EXT_MAP ("ztso" ,RISCV_ISA_EXT_ZTSO ); }#undef SET_ISA_EXT_MAP }
Signature · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
arch/riscv/include/asm/elf.h line 38
Quoted 9 lines · Palmer Dabbelt
arch/riscv/include/asm/elf.h +4
-1@@ -31,10 +32,23 @@#define ELF_DATA ELFDATA2LSB/* -* This is used to ensure we don't load something for the wrong architecture. +* Binaries that assume TSO cannot be correctly run on non-TSO systems, so +* prevent them from even being loaded. +*/ +#define EF_RISCV_TSO 0x0010
That should probably be defined in <asm/elf.h>.
Signature · 8 lines
Andreas Schwab, [email protected] GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different." _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 5 lines · On Thu, 01 Sep 2022 23:39:15 PDT (-0700), [email protected] wrote:
Quoted 3 lines · Palmer Dabbelt
arch/riscv/include/asm/elf.h +0
-0@@ -31,10 +32,23 @@#define ELF_DATA ELFDATA2LSB
Quoted 8 lines
arch/riscv/include/asm/elf.h line 38
Quoted 6 lines
arch/riscv/include/asm/elf.h +4
-1/* -* This is used to ensure we don't load something for the wrong architecture. +* Binaries that assume TSO cannot be correctly run on non-TSO systems, so +* prevent them from even being loaded. +*/ +#define EF_RISCV_TSO 0x0010That should probably be defined in <
asm/elf.h>.
Sorry, not sure if I'm missing something here? This is <arch/riscv/include/asm/elf.h>, we just don't have any ELF flags defined for RISC-V yet in the kernel because we don't use them.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 94 lines · Palmer Dabbelt
The Ztso extension was recently frozen, this adds support for running binaries that depend on TSO on systems that support Ztso.
Signed-off-by Palmer Dabbelt <[email protected]>---
This is very minimaly tested: I can run no-Ztso binaries on both yes-Ztso and no-Ztso QEMU instances, but I don't have a yes-Ztso userspace together in order to make sure that works.
--- arch/riscv/include/asm/elf.h | 18 ++++++++++++++++-- arch/riscv/include/asm/hwcap.h | 3 +++ arch/riscv/kernel/cpu.c | 1 + arch/riscv/kernel/cpufeature.c | 3 +++ 4 files changed, 23 insertions(+), 2 deletions(-)arch/riscv/include/asm/elf.h +16
-2@@ -14,6 +14,7 @@#include <asm/auxvec.h> #include <asm/byteorder.h> #include <asm/cacheinfo.h> +#include <asm/hwcap.h> /* * These are used to set parameters in the core dumps. @@ -31,10 +32,23 @@#define ELF_DATA ELFDATA2LSB/* -* This is used to ensure we don't load something for the wrong architecture. +* Binaries that assume TSO cannot be correctly run on non-TSO systems, so +* prevent them from even being loaded. +*/ +#define EF_RISCV_TSO 0x0010 + +static inline int riscv_elf_tso_ok (long eflags) +{ +return likely (!(eflags &EF_RISCV_TSO )) || riscv_tso_hw; +} + +/* +* This is used to ensure we don't load something for the wrong architecture or +* variant. */ #define elf_check_arch (x) (((x)->e_machine == EM_RISCV) && \ - ((x)->e_ident[EI_CLASS] == ELF_CLASS)) + ((x)->e_ident[EI_CLASS] == ELF_CLASS) && \ + riscv_elf_tso_ok((x)->e_flags))extern bool compat_elf_check_arch (Elf32_Ehdr *hdr);#define compat_elf_check_arch compat_elf_check_archarch/riscv/include/asm/hwcap.h +3
-0@@ -36,6 +36,8 @@ extern unsigned long elf_hwcap;#define RISCV_ISA_EXT_s ('s' - 'a')#define RISCV_ISA_EXT_u ('u' - 'a') +extern bool riscv_tso_hw; +/* * Increse this to higher value as kernel support more ISA extensions. */ @@ -58,6 +60,7 @@ enum riscv_isa_ext_id {RISCV_ISA_EXT_ZICBOM ,RISCV_ISA_EXT_ZIHINTPAUSE ,RISCV_ISA_EXT_SSTC , +RISCV_ISA_EXT_ZTSO , RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX, };arch/riscv/kernel/cpu.c +1
-0@@ -95,6 +95,7 @@ static struct riscv_isa_ext_data isa_ext_arr[] = {__RISCV_ISA_EXT_DATA (svpbmt,RISCV_ISA_EXT_SVPBMT ),__RISCV_ISA_EXT_DATA (zicbom,RISCV_ISA_EXT_ZICBOM ),__RISCV_ISA_EXT_DATA (zihintpause,RISCV_ISA_EXT_ZIHINTPAUSE ), +__RISCV_ISA_EXT_DATA (ztso,RISCV_ISA_EXT_ZTSO ),__RISCV_ISA_EXT_DATA (sstc,RISCV_ISA_EXT_SSTC ), __RISCV_ISA_EXT_DATA("", RISCV_ISA_EXT_MAX), };arch/riscv/kernel/cpufeature.c +0
-0
arch/riscv/kernel/cpufeature.c line 28
Quoted 4 lines
arch/riscv/kernel/cpufeature.c +1
-0@@ -25,6 +25,8 @@unsigned long elf_hwcap__read_mostly ; +bool riscv_tso_hw__read_mostly ;
This is not set anywhere. Maybe riscv_fill_hwcap() should set it ?
Quoted 16 lines
arch/riscv/kernel/cpufeature.c +2
-1+/* Host ISA bitmap */ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;@@ -204,6 +206,7 @@ void __init riscv_fill_hwcap(void)SET_ISA_EXT_MAP ("zicbom" ,RISCV_ISA_EXT_ZICBOM );SET_ISA_EXT_MAP ("zihintpause" ,RISCV_ISA_EXT_ZIHINTPAUSE );SET_ISA_EXT_MAP ("sstc" ,RISCV_ISA_EXT_SSTC ); +SET_ISA_EXT_MAP ("ztso" ,RISCV_ISA_EXT_ZTSO ); }#undef SET_ISA_EXT_MAP } --2.34.1
Quoted 4 lines
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Regards,
Anup
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 96 lines · On Thu, 01 Sep 2022 23:50:50 PDT (-0700), [email protected] wrote:
Quoted 95 lines · Palmer Dabbelt
The Ztso extension was recently frozen, this adds support for running binaries that depend on TSO on systems that support Ztso.
Signed-off-by Palmer Dabbelt <[email protected]>---
This is very minimaly tested: I can run no-Ztso binaries on both yes-Ztso and no-Ztso QEMU instances, but I don't have a yes-Ztso userspace together in order to make sure that works.
--- arch/riscv/include/asm/elf.h | 18 ++++++++++++++++-- arch/riscv/include/asm/hwcap.h | 3 +++ arch/riscv/kernel/cpu.c | 1 + arch/riscv/kernel/cpufeature.c | 3 +++ 4 files changed, 23 insertions(+), 2 deletions(-)arch/riscv/include/asm/elf.h +16
-2@@ -14,6 +14,7 @@#include <asm/auxvec.h> #include <asm/byteorder.h> #include <asm/cacheinfo.h> +#include <asm/hwcap.h> /* * These are used to set parameters in the core dumps. @@ -31,10 +32,23 @@#define ELF_DATA ELFDATA2LSB/* -* This is used to ensure we don't load something for the wrong architecture. +* Binaries that assume TSO cannot be correctly run on non-TSO systems, so +* prevent them from even being loaded. +*/ +#define EF_RISCV_TSO 0x0010 + +static inline int riscv_elf_tso_ok (long eflags) +{ +return likely (!(eflags &EF_RISCV_TSO )) || riscv_tso_hw; +} + +/* +* This is used to ensure we don't load something for the wrong architecture or +* variant. */ #define elf_check_arch (x) (((x)->e_machine == EM_RISCV) && \ - ((x)->e_ident[EI_CLASS] == ELF_CLASS)) + ((x)->e_ident[EI_CLASS] == ELF_CLASS) && \ + riscv_elf_tso_ok((x)->e_flags))extern bool compat_elf_check_arch (Elf32_Ehdr *hdr);#define compat_elf_check_arch compat_elf_check_archarch/riscv/include/asm/hwcap.h +3
-0@@ -36,6 +36,8 @@ extern unsigned long elf_hwcap;#define RISCV_ISA_EXT_s ('s' - 'a')#define RISCV_ISA_EXT_u ('u' - 'a') +extern bool riscv_tso_hw; +/* * Increse this to higher value as kernel support more ISA extensions. */ @@ -58,6 +60,7 @@ enum riscv_isa_ext_id {RISCV_ISA_EXT_ZICBOM ,RISCV_ISA_EXT_ZIHINTPAUSE ,RISCV_ISA_EXT_SSTC , +RISCV_ISA_EXT_ZTSO , RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX, };arch/riscv/kernel/cpu.c +1
-0@@ -95,6 +95,7 @@ static struct riscv_isa_ext_data isa_ext_arr[] = {__RISCV_ISA_EXT_DATA (svpbmt,RISCV_ISA_EXT_SVPBMT ),__RISCV_ISA_EXT_DATA (zicbom,RISCV_ISA_EXT_ZICBOM ),__RISCV_ISA_EXT_DATA (zihintpause,RISCV_ISA_EXT_ZIHINTPAUSE ), +__RISCV_ISA_EXT_DATA (ztso,RISCV_ISA_EXT_ZTSO ),__RISCV_ISA_EXT_DATA (sstc,RISCV_ISA_EXT_SSTC ), __RISCV_ISA_EXT_DATA("", RISCV_ISA_EXT_MAX), };arch/riscv/kernel/cpufeature.c +0
-0@@ -25,6 +25,8 @@
Quoted 5 lines
arch/riscv/kernel/cpufeature.c line 28
Quoted 3 lines
arch/riscv/kernel/cpufeature.c +1
-0unsigned long elf_hwcap__read_mostly ; +bool riscv_tso_hw__read_mostly ;This is not set anywhere. Maybe
riscv_fill_hwcap()should set it ?
Even worse: I got half way through writing the code, realized I should have just used a static branch, got distracted, wrote the QEMU code, and then forgot about it. I'll fix it for the v2.
Quoted 17 lines
Quoted 17 lines
arch/riscv/kernel/cpufeature.c +2
-1+/* Host ISA bitmap */ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly;@@ -204,6 +206,7 @@ void __init riscv_fill_hwcap(void)SET_ISA_EXT_MAP ("zicbom" ,RISCV_ISA_EXT_ZICBOM );SET_ISA_EXT_MAP ("zihintpause" ,RISCV_ISA_EXT_ZIHINTPAUSE );SET_ISA_EXT_MAP ("sstc" ,RISCV_ISA_EXT_SSTC ); +SET_ISA_EXT_MAP ("ztso" ,RISCV_ISA_EXT_ZTSO ); }#undef SET_ISA_EXT_MAP } --2.34.1
Quoted 7 lines
Quoted 4 lines
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscvRegards,
Anup
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 5 lines · Palmer Dabbelt
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
The Ztso extension was recently frozen, this adds support for running binaries that depend on TSO on systems that support Ztso.
Quoted 8 lines
Signed-off-by Palmer Dabbelt <[email protected]>/*
- * This is used to ensure we don't load something for the wrong architecture.
+ * Binaries that assume TSO cannot be correctly run on non-TSO systems, so
+ * prevent them from even being loaded.
+ */
+#defineEF_RISCV_TSO0x0010
My only comment, and I asked this on the other patch too, is why is this not s/EF/ELF like the other defines in the file?
Thanks,
Conor.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 15 lines · On Fri, 16 Sep 2022 03:00:35 PDT (-0700), [email protected] wrote:
Quoted 5 lines · Palmer Dabbelt
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
The Ztso extension was recently frozen, this adds support for running binaries that depend on TSO on systems that support Ztso.
Quoted 8 lines
Signed-off-by Palmer Dabbelt <[email protected]>/*
- * This is used to ensure we don't load something for the wrong architecture.
+ * Binaries that assume TSO cannot be correctly run on non-TSO systems, so
+ * prevent them from even being loaded.
+ */
+#defineEF_RISCV_TSO0x0010
Quoted 2 lines
My only comment, and I asked this on the other patch too, is why is this not s/EF/ELF like the other defines in the file?
It's EF_RISCV_TSO in the ELF spec, and that's what other ports do (see EF_ARM, for example).
Quoted 4 lines
Thanks,
Conor.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 18 lines · Palmer Dabbelt
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 15 lines · On Fri, 16 Sep 2022 03:00:35 PDT (-0700), [email protected] wrote:
Quoted 13 lines · Palmer Dabbelt
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
The Ztso extension was recently frozen, this adds support for running binaries that depend on TSO on systems that support Ztso.
Signed-off-by Palmer Dabbelt <[email protected]>/*
- * This is used to ensure we don't load something for the wrong architecture.
+ * Binaries that assume TSO cannot be correctly run on non-TSO systems, so
+ * prevent them from even being loaded.
+ */
+#define EF_RISCV_TSO0x0010
Quoted 5 lines
Quoted 2 lines
My only comment, and I asked this on the other patch too, is why is this not s/EF/ELF like the other defines in the file?
It's
EF_RISCV_TSOin the ELF spec, and that's what other ports do (seeEF_ARM, for example).
Right. I did try looking in arm, but I must've missed it. These spec people really have it out for my OCD...
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv