Skip to contentSkip to conversation

riscv: Add macro for multiple nop instructions

PATCH In review Heiko Stuebner 4 participants 6 messages Jun 7, 2022 – Jul 24, 2022 RISC-V

lore
Share & tools
lore
#0 lore raw

cover riscv: Add macro for multiple nop instructions

Some cases need multiple nop instructions and arm64 already has a nice helper for not needing to write all of them out but instead use a helper to add n nops.

So add a similar thing to riscv and convert the T-Head PMA alternative to use it.

Heiko Stuebner (2):
riscv: introduce nops and __nops macros for NOP sequences
riscv: convert the t-head pbmt errata to use the __nops macro

 arch/riscv/include/asm/asm.h         | 15 +++++++++++++++
 arch/riscv/include/asm/barrier.h     |  2 ++
 arch/riscv/include/asm/errata_list.h |  8 +-------
 3 files changed, 18 insertions(+), 7 deletions(-)
Signature · 1 line
2.35.1
#1 lore raw

PATCH 1/2 riscv: introduce nops and __nops macros for NOP sequences

NOP sequences tend to get used for padding out alternative sections

This change adds macros for generating these sequences as both inline asm blocks, but also as strings suitable for embedding in other asm blocks directly.

It essentially mimics similar functionality from arm64 introduced by Wil Deacon in commit f99a250cb6a3 ("arm64: barriers: introduce nops and __nops macros for NOP sequences").

---
 arch/riscv/include/asm/asm.h     | 15 +++++++++++++++
 arch/riscv/include/asm/barrier.h |  2 ++
 2 files changed, 17 insertions(+)
arch/riscv/include/asm/asm.h +15 -0
index 618d7c5af1a2..1b471ff73178 100644
@@ -67,4 +67,19 @@
 #error "Unexpected __SIZEOF_SHORT__"
 #endif
 
+#ifdef __ASSEMBLY__
+
+/* Common assembly source macros */
+
+/*
+ * NOP sequence
+ */
+.macro	nops, num
+	.rept	\num
+	nop
+	.endr
+.endm
+
+#endif /* __ASSEMBLY__ */
+
 #endif /* _ASM_RISCV_ASM_H */
arch/riscv/include/asm/barrier.h +2 -0
index d0e24aaa2aa0..110752594228 100644
@@ -13,6 +13,8 @@
 #ifndef __ASSEMBLY__
 
 #define nop()		__asm__ __volatile__ ("nop")
+#define __nops(n)	".rept	" #n "\nnop\n.endr\n"
+#define nops(n)		__asm__ __volatile__ (__nops(n))
 
 #define RISCV_FENCE(p, s) \
 	__asm__ __volatile__ ("fence " #p "," #s : : : "memory")
Signature · 1 line
2.35.1
#2 lore raw

PATCH 2/2 riscv: convert the t-head pbmt errata to use the __nops macro

In reply to Heiko Stuebner

Instead of manually inserting the list of nops, use the recently introduced __nops(n) macro to make everything more readable.

---
 arch/riscv/include/asm/errata_list.h | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
arch/riscv/include/asm/errata_list.h +1 -7
index 416ead0f9a65..398e351e7002 100644
@@ -68,13 +68,7 @@ asm(ALTERNATIVE_2("li %0, 0\t\nnop",					\
  */
 #define ALT_THEAD_PMA(_val)						\
 asm volatile(ALTERNATIVE(						\
-	"nop\n\t"							\
-	"nop\n\t"							\
-	"nop\n\t"							\
-	"nop\n\t"							\
-	"nop\n\t"							\
-	"nop\n\t"							\
-	"nop",								\
+	__nops(7),							\
 	"li      t3, %1\n\t"						\
 	"slli    t3, t3, %3\n\t"					\
 	"and     t3, %0, t3\n\t"					\
Signature · 1 line
2.35.1
Reviewed-by on the v1 series
#3 lore raw
In reply to Heiko Stuebner

Just a safe good coding convention point.

Quoted 21 lines · Heiko Stuebner

Some cases need multiple nop instructions and arm64 already has a nice helper for not needing to write all of them out but instead use a helper to add n nops.

So add a similar thing to riscv and convert the T-Head PMA alternative to use it.

Heiko Stuebner (2):
riscv: introduce nops and __nops macros for NOP sequences
riscv: convert the t-head pbmt errata to use the __nops macro

 arch/riscv/include/asm/asm.h         | 15 +++++++++++++++
 arch/riscv/include/asm/barrier.h     |  2 ++
 arch/riscv/include/asm/errata_list.h |  8 +-------
 3 files changed, 18 insertions(+), 7 deletions(-)

--
2.35.1

Signature · 9 lines
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
maintainer
#4 lore raw
In reply to Heiko Stuebner
Quoted 8 lines · On Tue, 07 Jun 2022 07:30:57 PDT (-0700), [email protected] wrote:

Some cases need multiple nop instructions and arm64 already has a nice helper for not needing to write all of them out but instead use a helper to add n nops.

So add a similar thing to riscv and convert the T-Head PMA alternative to use it.

Quoted 8 lines

Heiko Stuebner (2):
riscv: introduce nops and __nops macros for NOP sequences
riscv: convert the t-head pbmt errata to use the __nops macro

 arch/riscv/include/asm/asm.h         | 15 +++++++++++++++
 arch/riscv/include/asm/barrier.h     |  2 ++
 arch/riscv/include/asm/errata_list.h |  8 +-------
 3 files changed, 18 insertions(+), 7 deletions(-)

Thanks, these are on for-next. I had to fix up some minor conflicts, but hopefuly nothing went wrong.

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

#5 lore raw

Hi Palmer,

Quoted 13 lines · Palmer Dabbelt
Quoted 12 lines · On Tue, 07 Jun 2022 07:30:57 PDT (-0700), [email protected] wrote:

Some cases need multiple nop instructions and arm64 already has a nice helper for not needing to write all of them out but instead use a helper to add n nops.

So add a similar thing to riscv and convert the T-Head PMA alternative to use it.

Heiko Stuebner (2):
  riscv: introduce nops and __nops macros for NOP sequences
  riscv: convert the t-head pbmt errata to use the __nops macro

Quoted 7 lines
Quoted 4 lines

 arch/riscv/include/asm/asm.h         | 15 +++++++++++++++ arch/riscv/include/asm/barrier.h     |  2 ++ arch/riscv/include/asm/errata_list.h |  8 +-------

 3 files changed, 18 insertions(+), 7 deletions(-)

Thanks, these are on for-next.  I had to fix up some minor conflicts, but hopefuly nothing went wrong.

The conflicts are because the patch was sent on top of fixes, specifically e83031564137 ("riscv: Fix ALT_THEAD_PMA's asm parameters"). Since you applied this patch without pulling fixes in to for-next, now for-next conflicts with master.

Regards,
Samuel