Skip to contentSkip to conversation

riscv: ztso: disallow elf binaries needing TSO

PATCH Superseded Vineet Gupta 3 participants 8 messages Sep 16, 2022 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: ztso: disallow elf binaries needing TSO

As of now the software stack needs work to support ztso. Until that work is finished, disallow binaries needing TSO.

This patch is needed to help ztso ratification and prolifiration of tso bits in tooling.

---
 arch/riscv/include/asm/elf.h      | 11 ++++++++++-
 arch/riscv/include/uapi/asm/elf.h |  2 ++
 2 files changed, 12 insertions(+), 1 deletion(-)
arch/riscv/include/asm/elf.h +10 -1
index f53c40026c7a..37a47352f633 100644
@@ -26,10 +26,19 @@
 
 #define ELF_DATA	ELFDATA2LSB
 
+/*
+ * Make sure the extensions are compatible.
+ *
+ * In the final incarnation this will get the features as provided by DT and
+ * make sure kernel build is compatible.
+ * For now disallow TSO built binaries.
+ */
+#define rv_ext_ok(x)	(!((x)->e_flags & EF_RISCV_TSO))
+
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(x) ((x)->e_machine == EM_RISCV)
+#define elf_check_arch(x) ((x)->e_machine == EM_RISCV && rv_ext_ok())
 
 #define CORE_DUMP_USE_REGSET
 #define ELF_EXEC_PAGESIZE	(PAGE_SIZE)
arch/riscv/include/uapi/asm/elf.h +2 -0
index d696d6610231..fa9e4c52c7ac 100644
@@ -32,6 +32,8 @@ typedef union __riscv_fp_state elf_fpregset_t;
 #define ELF_RISCV_R_TYPE(r_info)	ELF32_R_TYPE(r_info)
 #endif
 
+#define EF_RISCV_TSO		(1 << 3)
+
 /*
  * RISC-V relocation types
  */
Signature · 7 lines
2.34.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw

PATCH v2 1/1 riscv: ztso: disallow elf binaries needing TSO

As of now the software stack needs work to support ztso. Until that work is finished, disallow binaries needing TSO.

This patch is needed to help ztso ratification and prolifiration of tso bits in tooling.

---
Changes since v1
- Build error (and boot tested on qemu)
- Improved the comments a bit

---
 arch/riscv/include/asm/elf.h      | 11 ++++++++++-
 arch/riscv/include/uapi/asm/elf.h |  2 ++
 2 files changed, 12 insertions(+), 1 deletion(-)
arch/riscv/include/asm/elf.h +10 -1
index f53c40026c7a..b6b4542b3039 100644
@@ -26,10 +26,19 @@
 
 #define ELF_DATA	ELFDATA2LSB
 
+/*
+ * Make sure the elf being loaded is compatible with extensions.
+ *
+ * In the final incarnation this will get the extension list from DT and
+ * make sure elf can run on given hardware+kernel.
+ * For now disallow TSO built binaries.
+ */
+#define rv_ext_ok(x)	(!((x)->e_flags & EF_RISCV_TSO))
+
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(x) ((x)->e_machine == EM_RISCV)
+#define elf_check_arch(x) ((x)->e_machine == EM_RISCV && rv_ext_ok(x))
 
 #define CORE_DUMP_USE_REGSET
 #define ELF_EXEC_PAGESIZE	(PAGE_SIZE)
arch/riscv/include/uapi/asm/elf.h +2 -0
index d696d6610231..fa9e4c52c7ac 100644
@@ -32,6 +32,8 @@ typedef union __riscv_fp_state elf_fpregset_t;
 #define ELF_RISCV_R_TYPE(r_info)	ELF32_R_TYPE(r_info)
 #endif
 
+#define EF_RISCV_TSO		(1 << 3)
+
 /*
  * RISC-V relocation types
  */
Signature · 1 line
2.34.1
#2 lore raw
Quoted 9 lines · Vineet Gupta

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

As of now the software stack needs work to support ztso. Until that work is finished, disallow binaries needing TSO.

This patch is needed to help ztso ratification and prolifiration of tso bits in tooling.

I have to admit to being a little confused here, if Ztso is not ratified why do we need to protect ourselves from it?

Quoted 41 lines

---
Changes since v1
- Build error (and boot tested on qemu)
- Improved the comments a bit

---
  arch/riscv/include/asm/elf.h      | 11 ++++++++++-
  arch/riscv/include/uapi/asm/elf.h |  2 ++
  2 files changed, 12 insertions(+), 1 deletion(-)
arch/riscv/include/asm/elf.h +10 -1
index f53c40026c7a..b6b4542b3039 100644
@@ -26,10 +26,19 @@
 
  #define ELF_DATA       ELFDATA2LSB
 
+/*
+ * Make sure the elf being loaded is compatible with extensions.
+ *
+ * In the final incarnation this will get the extension list from DT and
+ * make sure elf can run on given hardware+kernel.
+ * For now disallow TSO built binaries.
+ */
+#define rv_ext_ok(x)   (!((x)->e_flags & EF_RISCV_TSO))
+
  /*
   * This is used to ensure we don't load something for the wrong architecture.
   */
-#define elf_check_arch(x) ((x)->e_machine == EM_RISCV)
+#define elf_check_arch(x) ((x)->e_machine == EM_RISCV && rv_ext_ok(x))
 
  #define CORE_DUMP_USE_REGSET
  #define ELF_EXEC_PAGESIZE      (PAGE_SIZE)
arch/riscv/include/uapi/asm/elf.h +0 -0
index d696d6610231..fa9e4c52c7ac 100644

arch/riscv/include/uapi/asm/elf.h typedef union __riscv_fp_state elf_fpregset_t; · line 35

Quoted 4 lines
arch/riscv/include/uapi/asm/elf.h +1 -0
@@ -32,6 +32,8 @@ typedef union __riscv_fp_state elf_fpregset_t;
  #define ELF_RISCV_R_TYPE(r_info)       ELF32_R_TYPE(r_info)
  #endif
 
+#define EF_RISCV_TSO           (1 << 3)

s/EF/ELF ?

Thanks,
Conor.

Quoted 12 lines
arch/riscv/include/uapi/asm/elf.h +1 -1
+
  /*
   * RISC-V relocation types
   */
--

2.34.1

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

A message that is not in the archive (sent off-list or not yet received): CAHYeh+okQuVQjRX_6CwEK5-zWFDcRfUF132WXt2BNbMSAP8_mA@mail.gmail.com

#5 lore raw
In reply to [email protected]
Quoted 5 lines · Conor Dooley
Quoted 4 lines · Vineet Gupta

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 8 lines
Quoted 5 lines

As of now the software stack needs work to support ztso. Until that work is finished, disallow binaries needing TSO.

This patch is needed to help ztso ratification and prolifiration of tso bits in tooling.

I have to admit to being a little confused here, if Ztso is not ratified why do we need to protect ourselves from it?

Also, since this is not marked as a fix, why would we not just apply the patchset from Palmer that looks like a more complete version of this patch:
https://lore.kernel.org/linux-riscv/[email protected]/

Maybe you could offer an R-b or some comments on that patch instead?

Thanks,
Conor.

Quoted 65 lines
Quoted 42 lines

---
Changes since v1
   - Build error (and boot tested on qemu)
   - Improved the comments a bit
---
  arch/riscv/include/asm/elf.h      | 11 ++++++++++- arch/riscv/include/uapi/asm/elf.h |  2 ++

  2 files changed, 12 insertions(+), 1 deletion(-)
arch/riscv/include/asm/elf.h +10 -1
index f53c40026c7a..b6b4542b3039 100644
@@ -26,10 +26,19 @@
 
   #define ELF_DATA       ELFDATA2LSB
 
+/*
+ * Make sure the elf being loaded is compatible with extensions.
+ *
+ * In the final incarnation this will get the extension list from DT and
+ * make sure elf can run on given hardware+kernel.
+ * For now disallow TSO built binaries.
+ */
+#define rv_ext_ok(x)   (!((x)->e_flags & EF_RISCV_TSO))
+
   /*
    * This is used to ensure we don't load something for the wrong architecture.
    */
-#define elf_check_arch(x) ((x)->e_machine == EM_RISCV)
+#define elf_check_arch(x) ((x)->e_machine == EM_RISCV && rv_ext_ok(x))
 
   #define CORE_DUMP_USE_REGSET
   #define ELF_EXEC_PAGESIZE      (PAGE_SIZE)
arch/riscv/include/uapi/asm/elf.h +0 -0
index d696d6610231..fa9e4c52c7ac 100644

arch/riscv/include/uapi/asm/elf.h typedef union __riscv_fp_state elf_fpregset_t; · line 35

Quoted 4 lines
arch/riscv/include/uapi/asm/elf.h +1 -0
@@ -32,6 +32,8 @@ typedef union __riscv_fp_state elf_fpregset_t;
   #define ELF_RISCV_R_TYPE(r_info)       ELF32_R_TYPE(r_info)
   #endif
 
+#define EF_RISCV_TSO           (1 << 3)

s/EF/ELF ?

Thanks,
Conor.

Quoted 12 lines
arch/riscv/include/uapi/asm/elf.h +1 -0
+
   /*
    * RISC-V relocation types
    */
Signature · 7 lines
2.34.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#6 lore raw
Quoted 15 lines · On Thu, 15 Sep 2022 23:58:05 PDT (-0700), [email protected] wrote:
Quoted 5 lines · Conor Dooley
Quoted 4 lines · Vineet Gupta

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 8 lines
Quoted 5 lines

As of now the software stack needs work to support ztso. Until that work is finished, disallow binaries needing TSO.

This patch is needed to help ztso ratification and prolifiration of tso bits in tooling.

I have to admit to being a little confused here, if Ztso is not ratified why do we need to protect ourselves from it?

Quoted 6 lines

Also, since this is not marked as a fix, why would we not just apply the patchset from Palmer that looks like a more complete version of this patch:
https://lore.kernel.org/linux-riscv/[email protected]/

Maybe you could offer an R-b or some comments on that patch instead?

IMO that's the better way to go, Ztso is frozen so we can expect software to start using it. Might as well let it run if the machine is going to be TSO anyway (and IIRC some of the T-Head stuff either is or can be TSO, so we'll need to detection soon anyway).

I was also planning on re-spinning the QEMU stuff so we can test it, but given how simple the Linux patch is I think it's fine to just go ahead and take it.

Happy to hear any comments, though.

Quoted 70 lines

Thanks,
Conor.

Quoted 65 lines
Quoted 42 lines

---
Changes since v1
   - Build error (and boot tested on qemu)
   - Improved the comments a bit
---
  arch/riscv/include/asm/elf.h      | 11 ++++++++++- arch/riscv/include/uapi/asm/elf.h |  2 ++

  2 files changed, 12 insertions(+), 1 deletion(-)
arch/riscv/include/asm/elf.h +10 -1
index f53c40026c7a..b6b4542b3039 100644
@@ -26,10 +26,19 @@
 
   #define ELF_DATA       ELFDATA2LSB
 
+/*
+ * Make sure the elf being loaded is compatible with extensions.
+ *
+ * In the final incarnation this will get the extension list from DT and
+ * make sure elf can run on given hardware+kernel.
+ * For now disallow TSO built binaries.
+ */
+#define rv_ext_ok(x)   (!((x)->e_flags & EF_RISCV_TSO))
+
   /*
    * This is used to ensure we don't load something for the wrong architecture.
    */
-#define elf_check_arch(x) ((x)->e_machine == EM_RISCV)
+#define elf_check_arch(x) ((x)->e_machine == EM_RISCV && rv_ext_ok(x))
 
   #define CORE_DUMP_USE_REGSET
   #define ELF_EXEC_PAGESIZE      (PAGE_SIZE)
arch/riscv/include/uapi/asm/elf.h +0 -0
index d696d6610231..fa9e4c52c7ac 100644

arch/riscv/include/uapi/asm/elf.h typedef union __riscv_fp_state elf_fpregset_t; · line 35

Quoted 4 lines
arch/riscv/include/uapi/asm/elf.h +1 -0
@@ -32,6 +32,8 @@ typedef union __riscv_fp_state elf_fpregset_t;
   #define ELF_RISCV_R_TYPE(r_info)       ELF32_R_TYPE(r_info)
   #endif
 
+#define EF_RISCV_TSO           (1 << 3)

s/EF/ELF ?

Thanks,
Conor.

Quoted 12 lines
arch/riscv/include/uapi/asm/elf.h +1 -0
+
   /*
    * RISC-V relocation types
    */
Signature · 7 lines
2.34.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#7 lore raw
In reply to [email protected]
Quoted 6 lines · On 9/15/22 23:58, [email protected] wrote:

Also, since this is not marked as a fix, why would we not just apply the patchset from Palmer that looks like a more complete version of this patch:
https://lore.kernel.org/linux-riscv/[email protected]/

Maybe you could offer an R-b or some comments on that patch instead?

Sure I didn't know about that patch and my idea was just to get the ball rolling so tooling at least can start having tso bits as last time around that was the blocker to getting stuff in binutils and gcc etc.

-Vineet

#8 lore raw
Quoted 8 lines · Vineet Gupta

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 5 lines · On 9/15/22 23:58, [email protected] wrote:

Also, since this is not marked as a fix, why would we not just apply the patchset from Palmer that looks like a more complete version of this patch:
https://lore.kernel.org/linux-riscv/[email protected]/

Quoted 5 lines
Quoted 1 line

Maybe you could offer an R-b or some comments on that patch instead?

Sure I didn't know about that patch and my idea was just to get the ball rolling so tooling at least can start having tso bits as last time around that was the blocker to getting stuff in binutils and gcc etc.

Ye nw, sure I completely forgot what the order was between frozen, public review & ratification was ;)