Skip to contentSkip to conversation

Some style cleanups for recent extension additions

PATCH Applied Heiko Stuebner 4 participants 13 messages Sep 5, 2022 – Oct 13, 2022 1 message not in the archive RISC-V

lore
Share & tools
lore
#0 lore raw

v2 cover Some style cleanups for recent extension additions

As noted by some people, some parts of the recently added extensions (svpbmt, zicbom) + t-head errata could use some styling upgrades.

So this series provides these.

changes in v2:
- add patch also converting cpufeature probe to BIT()
- update commit message in patch1 (Conor)

Heiko Stuebner (5):
riscv: cleanup svpbmt cpufeature probing
riscv: drop some idefs from CMO initialization
riscv: use BIT() macros in t-head errata init
riscv: use BIT() marco for cpufeature probing
riscv: check for kernel config option in t-head memory types errata

 arch/riscv/errata/thead/errata.c    | 14 ++++++-----
 arch/riscv/include/asm/cacheflush.h |  2 ++
 arch/riscv/kernel/cpufeature.c      | 39 ++++++++++++-----------------
 3 files changed, 26 insertions(+), 29 deletions(-)
Signature · 1 line
2.35.1
#1 lore raw

PATCH v2 1/5 riscv: cleanup svpbmt cpufeature probing

For better readability (and compile time coverage) use IS_ENABLED instead of ifdef and drop the new unneeded switch statement.

---
 arch/riscv/kernel/cpufeature.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
arch/riscv/kernel/cpufeature.c +5 -8
index 553d755483ed..764ea220161f 100644
@@ -253,16 +253,13 @@ void __init riscv_fill_hwcap(void)
 #ifdef CONFIG_RISCV_ALTERNATIVE
 static bool __init_or_module cpufeature_probe_svpbmt(unsigned int stage)
 {
-#ifdef CONFIG_RISCV_ISA_SVPBMT
-	switch (stage) {
-	case RISCV_ALTERNATIVES_EARLY_BOOT:
+	if (!IS_ENABLED(CONFIG_RISCV_ISA_SVPBMT))
 		return false;
-	default:
-		return riscv_isa_extension_available(NULL, SVPBMT);
-	}
-#endif
 
-	return false;
+	if (stage == RISCV_ALTERNATIVES_EARLY_BOOT)
+		return false;
+
+	return riscv_isa_extension_available(NULL, SVPBMT);
 }
 
 static bool __init_or_module cpufeature_probe_zicbom(unsigned int stage)
Signature · 1 line
2.35.1
#2 lore raw

PATCH v2 2/5 riscv: drop some idefs from CMO initialization

In reply to Heiko Stuebner

Wrapping things in #ifdefs makes the code harder to read while we also have IS_ENABLED() macros to do this in regular code and the extension detection is not _that_ runtime critical.

So define a stub for riscv_noncoherent_supported() in the non-CONFIG_RISCV_DMA_NONCOHERENT case and move the code to us IS_ENABLED.

---
 arch/riscv/errata/thead/errata.c    |  7 +++----
 arch/riscv/include/asm/cacheflush.h |  2 ++
 arch/riscv/kernel/cpufeature.c      | 22 +++++++++-------------
 3 files changed, 14 insertions(+), 17 deletions(-)
arch/riscv/errata/thead/errata.c +3 -4
index 202c83f677b2..bffa711aaf64 100644
@@ -30,7 +30,9 @@ static bool errata_probe_pbmt(unsigned int stage,
 static bool errata_probe_cmo(unsigned int stage,
 			     unsigned long arch_id, unsigned long impid)
 {
-#ifdef CONFIG_ERRATA_THEAD_CMO
+	if (!IS_ENABLED(CONFIG_ERRATA_THEAD_CMO))
+		return false;
+
 	if (arch_id != 0 || impid != 0)
 		return false;
 
@@ -39,9 +41,6 @@ static bool errata_probe_cmo(unsigned int stage,
 
 	riscv_noncoherent_supported();
 	return true;
-#else
-	return false;
-#endif
 }
 
 static u32 thead_errata_probe(unsigned int stage,
arch/riscv/include/asm/cacheflush.h +2 -0
index a60acaecfeda..4363d0beb38a 100644
@@ -50,6 +50,8 @@ static inline void riscv_init_cbom_blocksize(void) { }
 
 #ifdef CONFIG_RISCV_DMA_NONCOHERENT
 void riscv_noncoherent_supported(void);
+#else
+static inline void riscv_noncoherent_supported(void) {}
 #endif
 
 /*
arch/riscv/kernel/cpufeature.c +9 -13
index 764ea220161f..729f7a218093 100644
@@ -264,21 +264,17 @@ static bool __init_or_module cpufeature_probe_svpbmt(unsigned int stage)
 
 static bool __init_or_module cpufeature_probe_zicbom(unsigned int stage)
 {
-#ifdef CONFIG_RISCV_ISA_ZICBOM
-	switch (stage) {
-	case RISCV_ALTERNATIVES_EARLY_BOOT:
+	if (!IS_ENABLED(CONFIG_RISCV_ISA_ZICBOM))
+		return false;
+
+	if (stage == RISCV_ALTERNATIVES_EARLY_BOOT)
+		return false;
+
+	if (!riscv_isa_extension_available(NULL, ZICBOM))
 		return false;
-	default:
-		if (riscv_isa_extension_available(NULL, ZICBOM)) {
-			riscv_noncoherent_supported();
-			return true;
-		} else {
-			return false;
-		}
-	}
-#endif
 
-	return false;
+	riscv_noncoherent_supported();
+	return true;
 }
 
 /*
Signature · 1 line
2.35.1
#3 lore raw

PATCH v2 3/5 riscv: use BIT() macros in t-head errata init

In reply to Heiko Stuebner

Using the appropriate BIT macro makes the code better readable.

---
 arch/riscv/errata/thead/errata.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/errata/thead/errata.c +2 -2
index bffa711aaf64..a6f4bd8ccf3f 100644
@@ -49,10 +49,10 @@ static u32 thead_errata_probe(unsigned int stage,
 	u32 cpu_req_errata = 0;
 
 	if (errata_probe_pbmt(stage, archid, impid))
-		cpu_req_errata |= (1U << ERRATA_THEAD_PBMT);
+		cpu_req_errata |= BIT(ERRATA_THEAD_PBMT);
 
 	if (errata_probe_cmo(stage, archid, impid))
-		cpu_req_errata |= (1U << ERRATA_THEAD_CMO);
+		cpu_req_errata |= BIT(ERRATA_THEAD_CMO);
 
 	return cpu_req_errata;
 }
Signature · 1 line
2.35.1
#4 lore raw

PATCH v2 4/5 riscv: use BIT() marco for cpufeature probing

In reply to Heiko Stuebner

Using the appropriate BIT macro makes the code better readable.

---
 arch/riscv/kernel/cpufeature.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/kernel/cpufeature.c +2 -2
index 729f7a218093..08f7445985dc 100644
@@ -289,10 +289,10 @@ static u32 __init_or_module cpufeature_probe(unsigned int stage)
 	u32 cpu_req_feature = 0;
 
 	if (cpufeature_probe_svpbmt(stage))
-		cpu_req_feature |= (1U << CPUFEATURE_SVPBMT);
+		cpu_req_feature |= BIT(CPUFEATURE_SVPBMT);
 
 	if (cpufeature_probe_zicbom(stage))
-		cpu_req_feature |= (1U << CPUFEATURE_ZICBOM);
+		cpu_req_feature |= BIT(CPUFEATURE_ZICBOM);
 
 	return cpu_req_feature;
 }
Signature · 1 line
2.35.1
Reviewed-by on v2 4/5
#5 lore raw

Re: [PATCH v2 4/5] riscv: use BIT() marco for cpufeature probing

Quoted 6 lines · Heiko Stuebner

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

Using the appropriate BIT macro makes the code better readable.

Missing the cover-letter with the changelog? At least, I didn't get it in my inbox. Either way,

Quoted 24 lines
---
  arch/riscv/kernel/cpufeature.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/kernel/cpufeature.c +2 -3
index 729f7a218093..08f7445985dc 100644
@@ -289,10 +289,10 @@ static u32 __init_or_module cpufeature_probe(unsigned int stage)
         u32 cpu_req_feature = 0;
 
         if (cpufeature_probe_svpbmt(stage))
-               cpu_req_feature |= (1U << CPUFEATURE_SVPBMT);
+               cpu_req_feature |= BIT(CPUFEATURE_SVPBMT);
 
         if (cpufeature_probe_zicbom(stage))
-               cpu_req_feature |= (1U << CPUFEATURE_ZICBOM);
+               cpu_req_feature |= BIT(CPUFEATURE_ZICBOM);
 
         return cpu_req_feature;
  }
--

2.35.1

#6 lore raw

Re: [PATCH v2 4/5] riscv: use BIT() marco for cpufeature probing

Am Montag, 5. September 2022, 13:19:41 CEST schrieb [email protected]:

Quoted 10 lines · Heiko Stuebner
Quoted 6 lines

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

Using the appropriate BIT macro makes the code better readable.

Missing the cover-letter with the changelog?
At least, I didn't get it in my inbox.

darn git send-email and its automatic selection ;-)

I.e. I _should_ have added you to the hard recipient list for my series in the first place, but instead git send-email selected you based on the Suggested-by ... but it looks like these selectoions don't get applied to the cover-letter ... sorry about that

Heiko

Quoted 30 lines

Either way,

Quoted 24 lines
---
  arch/riscv/kernel/cpufeature.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/kernel/cpufeature.c +2 -3
index 729f7a218093..08f7445985dc 100644
@@ -289,10 +289,10 @@ static u32 __init_or_module cpufeature_probe(unsigned int stage)
         u32 cpu_req_feature = 0;
 
         if (cpufeature_probe_svpbmt(stage))
-               cpu_req_feature |= (1U << CPUFEATURE_SVPBMT);
+               cpu_req_feature |= BIT(CPUFEATURE_SVPBMT);
 
         if (cpufeature_probe_zicbom(stage))
-               cpu_req_feature |= (1U << CPUFEATURE_ZICBOM);
+               cpu_req_feature |= BIT(CPUFEATURE_ZICBOM);
 
         return cpu_req_feature;
  }
--

2.35.1

#7 lore raw

Re: [PATCH v2 4/5] riscv: use BIT() marco for cpufeature probing

Am Montag, 5. September 2022, 13:23:01 CEST schrieb Heiko Stübner:

Quoted 12 lines

Am Montag, 5. September 2022, 13:19:41 CEST schrieb [email protected]:

Quoted 10 lines · Heiko Stuebner
Quoted 6 lines

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

Using the appropriate BIT macro makes the code better readable.

Missing the cover-letter with the changelog?
At least, I didn't get it in my inbox.

Quoted 6 lines

darn git send-email and its automatic selection ;-)

I.e. I _should_ have added you to the hard recipient list for my series in the first place, but instead git send-email selected you based on the Suggested-by ... but it looks like these selectoions don't get applied to the cover-letter ... sorry about that

For the record, the series is here:
https://lore.kernel.org/all/[email protected]/

Though right now, I don't see it in the linux-riscv list-archive or my own inbox of that list. Maybe infradead has some issue today.

Quoted 37 lines

Heiko

Quoted 30 lines

Either way,

Quoted 24 lines
---
  arch/riscv/kernel/cpufeature.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/kernel/cpufeature.c +2 -3
index 729f7a218093..08f7445985dc 100644
@@ -289,10 +289,10 @@ static u32 __init_or_module cpufeature_probe(unsigned int stage)
         u32 cpu_req_feature = 0;
 
         if (cpufeature_probe_svpbmt(stage))
-               cpu_req_feature |= (1U << CPUFEATURE_SVPBMT);
+               cpu_req_feature |= BIT(CPUFEATURE_SVPBMT);
 
         if (cpufeature_probe_zicbom(stage))
-               cpu_req_feature |= (1U << CPUFEATURE_ZICBOM);
+               cpu_req_feature |= BIT(CPUFEATURE_ZICBOM);
 
         return cpu_req_feature;
  }
--

2.35.1

#8 lore raw

Re: [PATCH v2 4/5] riscv: use BIT() marco for cpufeature probing

Quoted 22 lines · Heiko Stübner

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

Am Montag, 5. September 2022, 13:23:01 CEST schrieb Heiko Stübner:

Quoted 12 lines

Am Montag, 5. September 2022, 13:19:41 CEST schrieb [email protected]:

Quoted 10 lines · Heiko Stuebner
Quoted 6 lines

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

Using the appropriate BIT macro makes the code better readable.

Missing the cover-letter with the changelog?
At least, I didn't get it in my inbox.

Quoted 6 lines

darn git send-email and its automatic selection ;-)

I.e. I _should_ have added you to the hard recipient list for my series in the first place, but instead git send-email selected you based on the Suggested-by ... but it looks like these selectoions don't get applied to the cover-letter ... sorry about that

Quoted 5 lines

For the record, the series is here:
https://lore.kernel.org/all/[email protected]/

Though right now, I don't see it in the linux-riscv list-archive or my own inbox of that list. Maybe infradead has some issue today.

I ended up seeing it in one of my random folders but not my linux-riscv which is where I checked after it didnt come directly.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Either way,

btw, just noticed - s/marco/macro in the subject...

Conor.

A message that is not in the archive (sent off-list or not yet received): CAOnJCUJ9hC2xhoxuBPCNHEEZACeWckEL-Tc7xS6ECWrfx5KXhg@mail.gmail.com

Reviewed-by
#10 lore raw

Re: [PATCH v2 4/5] riscv: use BIT() marco for cpufeature probing

Quoted 47 lines · Atish Patra
Quoted 30 lines · Heiko Stuebner

Using the appropriate BIT macro makes the code better readable.

---
 arch/riscv/kernel/cpufeature.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/kernel/cpufeature.c +2 -3
index 729f7a218093..08f7445985dc 100644
@@ -289,10 +289,10 @@ static u32 __init_or_module cpufeature_probe(unsigned int stage)
        u32 cpu_req_feature = 0;
 
        if (cpufeature_probe_svpbmt(stage))
-               cpu_req_feature |= (1U << CPUFEATURE_SVPBMT);
+               cpu_req_feature |= BIT(CPUFEATURE_SVPBMT);
 
        if (cpufeature_probe_zicbom(stage))
-               cpu_req_feature |= (1U << CPUFEATURE_ZICBOM);
+               cpu_req_feature |= BIT(CPUFEATURE_ZICBOM);
 
        return cpu_req_feature;
 }
--

2.35.1

Quoted 4 lines

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

--
Regards,
Atish

Signature · 2 lines
Best Regards
 Guo Ren
#11 lore raw

PATCH v2 5/5 riscv: check for kernel config option in t-head memory types errata

In reply to Heiko Stuebner

The t-head variant of page-based memory types should also check first for the enabled kernel config option.

Fixes a35707c3d850 ("riscv: add memory-type errata for T-Head")
---
 arch/riscv/errata/thead/errata.c | 3 +++
 1 file changed, 3 insertions(+)
arch/riscv/errata/thead/errata.c +3 -0
index a6f4bd8ccf3f..902e12452821 100644
@@ -17,6 +17,9 @@
 static bool errata_probe_pbmt(unsigned int stage,
 			      unsigned long arch_id, unsigned long impid)
 {
+	if (!IS_ENABLED(CONFIG_ERRATA_THEAD_PBMT))
+		return false;
+
 	if (arch_id != 0 || impid != 0)
 		return false;
 
Signature · 1 line
2.35.1
Reviewed-by on v2 5/5
#12 lore raw

Re: [PATCH v2 5/5] riscv: check for kernel config option in t-head memory types errata

Quoted 29 lines · Heiko Stuebner

The t-head variant of page-based memory types should also check first for the enabled kernel config option.

Fixes a35707c3d850 ("riscv: add memory-type errata for T-Head")
---
 arch/riscv/errata/thead/errata.c | 3 +++
 1 file changed, 3 insertions(+)
arch/riscv/errata/thead/errata.c +3 -1
index a6f4bd8ccf3f..902e12452821 100644
@@ -17,6 +17,9 @@
 static bool errata_probe_pbmt(unsigned int stage,
                              unsigned long arch_id, unsigned long impid)
 {
+       if (!IS_ENABLED(CONFIG_ERRATA_THEAD_PBMT))
+               return false;
+
        if (arch_id != 0 || impid != 0)
                return false;
 
--

2.35.1

Signature · 2 lines
Best Regards
 Guo Ren
#13 lore raw
In reply to Heiko Stuebner
Quoted 10 lines · Heiko Stuebner

As noted by some people, some parts of the recently added extensions (svpbmt, zicbom) + t-head errata could use some styling upgrades.

So this series provides these.

changes in v2:
- add patch also converting cpufeature probe to BIT()
- update commit message in patch1 (Conor)

[...]

Applied, thanks!

[1/5] riscv: cleanup svpbmt cpufeature probing

      https://git.kernel.org/palmer/c/e47bddcb2ec5
[2/5] riscv: drop some idefs from CMO initialization
      https://git.kernel.org/palmer/c/f055268e3946
[3/5] riscv: use BIT() macros in t-head errata init
      https://git.kernel.org/palmer/c/499590c084f1
[4/5] riscv: use BIT() marco for cpufeature probing
      https://git.kernel.org/palmer/c/e283187c034c
[5/5] riscv: check for kernel config option in t-head memory types errata
      https://git.kernel.org/palmer/c/14057733109d

Best regards,

Signature · 1 line
Palmer Dabbelt <[email protected]>