linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] riscv: Add macro for multiple nop instructions
@ 2022-06-07 14:30 Heiko Stuebner
  2022-06-07 14:30 ` [PATCH 1/2] riscv: introduce nops and __nops macros for NOP sequences Heiko Stuebner
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Heiko Stuebner @ 2022-06-07 14:30 UTC (permalink / raw)
  To: palmer, paul.walmsley
  Cc: linux-riscv, linux-kernel, wefu, guoren, mick, samuel, cmuellner,
	philipp.tomsich, hch, 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


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] riscv: introduce nops and __nops macros for NOP sequences
  2022-06-07 14:30 [PATCH 0/2] riscv: Add macro for multiple nop instructions Heiko Stuebner
@ 2022-06-07 14:30 ` Heiko Stuebner
  2022-06-07 14:30 ` [PATCH 2/2] riscv: convert the t-head pbmt errata to use the __nops macro Heiko Stuebner
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Heiko Stuebner @ 2022-06-07 14:30 UTC (permalink / raw)
  To: palmer, paul.walmsley
  Cc: linux-riscv, linux-kernel, wefu, guoren, mick, samuel, cmuellner,
	philipp.tomsich, hch, Heiko Stuebner

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").

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
 arch/riscv/include/asm/asm.h     | 15 +++++++++++++++
 arch/riscv/include/asm/barrier.h |  2 ++
 2 files changed, 17 insertions(+)

diff --git a/arch/riscv/include/asm/asm.h b/arch/riscv/include/asm/asm.h
index 618d7c5af1a2..1b471ff73178 100644
--- a/arch/riscv/include/asm/asm.h
+++ b/arch/riscv/include/asm/asm.h
@@ -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 */
diff --git a/arch/riscv/include/asm/barrier.h b/arch/riscv/include/asm/barrier.h
index d0e24aaa2aa0..110752594228 100644
--- a/arch/riscv/include/asm/barrier.h
+++ b/arch/riscv/include/asm/barrier.h
@@ -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")
-- 
2.35.1


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] riscv: convert the t-head pbmt errata to use the __nops macro
  2022-06-07 14:30 [PATCH 0/2] riscv: Add macro for multiple nop instructions Heiko Stuebner
  2022-06-07 14:30 ` [PATCH 1/2] riscv: introduce nops and __nops macros for NOP sequences Heiko Stuebner
@ 2022-06-07 14:30 ` Heiko Stuebner
  2022-06-08  2:28 ` [PATCH 0/2] riscv: Add macro for multiple nop instructions Guo Ren
  2022-07-22  2:16 ` Palmer Dabbelt
  3 siblings, 0 replies; 6+ messages in thread
From: Heiko Stuebner @ 2022-06-07 14:30 UTC (permalink / raw)
  To: palmer, paul.walmsley
  Cc: linux-riscv, linux-kernel, wefu, guoren, mick, samuel, cmuellner,
	philipp.tomsich, hch, Heiko Stuebner

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

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
 arch/riscv/include/asm/errata_list.h | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/arch/riscv/include/asm/errata_list.h b/arch/riscv/include/asm/errata_list.h
index 416ead0f9a65..398e351e7002 100644
--- a/arch/riscv/include/asm/errata_list.h
+++ b/arch/riscv/include/asm/errata_list.h
@@ -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"					\
-- 
2.35.1


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] riscv: Add macro for multiple nop instructions
  2022-06-07 14:30 [PATCH 0/2] riscv: Add macro for multiple nop instructions Heiko Stuebner
  2022-06-07 14:30 ` [PATCH 1/2] riscv: introduce nops and __nops macros for NOP sequences Heiko Stuebner
  2022-06-07 14:30 ` [PATCH 2/2] riscv: convert the t-head pbmt errata to use the __nops macro Heiko Stuebner
@ 2022-06-08  2:28 ` Guo Ren
  2022-07-22  2:16 ` Palmer Dabbelt
  3 siblings, 0 replies; 6+ messages in thread
From: Guo Ren @ 2022-06-08  2:28 UTC (permalink / raw)
  To: Heiko Stuebner
  Cc: Palmer Dabbelt, Paul Walmsley, linux-riscv,
	Linux Kernel Mailing List, Wei Fu, Nick Kossifidis,
	Samuel Holland, Christoph Muellner, Philipp Tomsich,
	Christoph Hellwig

Just a safe good coding convention point.

Reviewed-by: Guo Ren <guoren@kernel.org>

On Tue, Jun 7, 2022 at 10:31 PM Heiko Stuebner <heiko@sntech.de> 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
>
>  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
>


-- 
Best Regards
 Guo Ren

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

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] riscv: Add macro for multiple nop instructions
  2022-06-07 14:30 [PATCH 0/2] riscv: Add macro for multiple nop instructions Heiko Stuebner
                   ` (2 preceding siblings ...)
  2022-06-08  2:28 ` [PATCH 0/2] riscv: Add macro for multiple nop instructions Guo Ren
@ 2022-07-22  2:16 ` Palmer Dabbelt
  2022-07-24 17:24   ` Samuel Holland
  3 siblings, 1 reply; 6+ messages in thread
From: Palmer Dabbelt @ 2022-07-22  2:16 UTC (permalink / raw)
  To: heiko
  Cc: Paul Walmsley, linux-riscv, linux-kernel, wefu, guoren, mick,
	samuel, cmuellner, philipp.tomsich, Christoph Hellwig, heiko

On Tue, 07 Jun 2022 07:30:57 PDT (-0700), heiko@sntech.de 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
>
>  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
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] riscv: Add macro for multiple nop instructions
  2022-07-22  2:16 ` Palmer Dabbelt
@ 2022-07-24 17:24   ` Samuel Holland
  0 siblings, 0 replies; 6+ messages in thread
From: Samuel Holland @ 2022-07-24 17:24 UTC (permalink / raw)
  To: Palmer Dabbelt; +Cc: heiko, Paul Walmsley, linux-riscv, linux-kernel

Hi Palmer,

On 7/21/22 9:16 PM, Palmer Dabbelt wrote:
> On Tue, 07 Jun 2022 07:30:57 PDT (-0700), heiko@sntech.de 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
>>
>>  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

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-07-24 17:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-07 14:30 [PATCH 0/2] riscv: Add macro for multiple nop instructions Heiko Stuebner
2022-06-07 14:30 ` [PATCH 1/2] riscv: introduce nops and __nops macros for NOP sequences Heiko Stuebner
2022-06-07 14:30 ` [PATCH 2/2] riscv: convert the t-head pbmt errata to use the __nops macro Heiko Stuebner
2022-06-08  2:28 ` [PATCH 0/2] riscv: Add macro for multiple nop instructions Guo Ren
2022-07-22  2:16 ` Palmer Dabbelt
2022-07-24 17:24   ` Samuel Holland

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).