Skip to contentSkip to conversation

riscv: cpu_ops: Change return value type of cpu_is_stopped() to bool

PATCH In review Hui Wang 2 participants 4 messages Apr 13 – May 28 RISC-V

lore
Share & tools
lore

Hui Wang

author
#0 lore raw

PATCH 1/2 riscv: cpu_ops: Change return value type of cpu_is_stopped() to bool

In the original sbi_cpu_is_stopped(), if rc doesn't equal to the SBI_HSM_STATE_STOPPED, it will return rc to the caller directly. But there is a hidden problem, the rc could be SBI_HSM_STATE_STARTED, if so, this function will report cpu stopped while the cpu isn't really stopped.

Furthermore, from the name of cpu_is_stopped(), it gives a sense the return value is a bool type, true means the cpu is stopped, conversely false means the cpu is not stopped.

Here change the return value type to bool and change the callers accordingly. This could fix the above two issues.

Fixes f1e58583b9c7c ("RISC-V: Support cpu hotplug")

---
In the v1:
move the cpu status number printing from arch_cpuhp_cleanup_dead_cpu() to sbi_cpu_is_stopped().

 arch/riscv/include/asm/cpu_ops.h |  2 +-
 arch/riscv/kernel/cpu-hotplug.c  |  4 ++--
 arch/riscv/kernel/cpu_ops_sbi.c  | 11 +++++++----
 3 files changed, 10 insertions(+), 7 deletions(-)
arch/riscv/include/asm/cpu_ops.h +1 -1
index 176b570ef982..065811fca594 100644
@@ -24,7 +24,7 @@ struct cpu_operations {
 				     struct task_struct *tidle);
 #ifdef CONFIG_HOTPLUG_CPU
 	void		(*cpu_stop)(void);
-	int		(*cpu_is_stopped)(unsigned int cpu);
+	bool		(*cpu_is_stopped)(unsigned int cpu);
 #endif
 };
 
arch/riscv/kernel/cpu-hotplug.c +2 -2
index a0ee426f6d93..3b9fa03f02a9 100644
@@ -57,8 +57,8 @@ void arch_cpuhp_cleanup_dead_cpu(unsigned int cpu)
 	/* Verify from the firmware if the cpu is really stopped*/
 	if (cpu_ops->cpu_is_stopped)
 		ret = cpu_ops->cpu_is_stopped(cpu);
-	if (ret)
-		pr_warn("CPU%u may not have stopped: %d\n", cpu, ret);
+	if (!ret)
+		pr_warn("CPU%u may not have stopped.\n", cpu);
 }
 
 /*
arch/riscv/kernel/cpu_ops_sbi.c +7 -4
index 00aff669f5f2..b6de2b2f8deb 100644
@@ -88,16 +88,19 @@ static void sbi_cpu_stop(void)
 	pr_crit("Unable to stop the cpu %d (%d)\n", smp_processor_id(), ret);
 }
 
-static int sbi_cpu_is_stopped(unsigned int cpuid)
+static bool sbi_cpu_is_stopped(unsigned int cpuid)
 {
 	int rc;
 	unsigned long hartid = cpuid_to_hartid_map(cpuid);
 
 	rc = sbi_hsm_hart_get_status(hartid);
 
-	if (rc == SBI_HSM_STATE_STOPPED)
-		return 0;
-	return rc;
+	if (rc != SBI_HSM_STATE_STOPPED) {
+		pr_warn("HART%lu isn't stopped and the status number is: %d\n", hartid, rc);
+		return false;
+	}
+
+	return true;
 }
 #endif
 
Signature · 7 lines
2.43.0


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

PATCH 2/2 riscv: cpu_ops_sbi: No need to be bothered to check ret.error

If the ret.error equals to 0, the sbi_err_map_linux_errno() can also handle it, i.e. if ret.error is SBI_SUCCESS, it will return 0 immediately, so no need to be bothered to check ret.error here.

---
 arch/riscv/kernel/cpu_ops_sbi.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
arch/riscv/kernel/cpu_ops_sbi.c +3 -8
index b6de2b2f8deb..037ecf403a0a 100644
@@ -30,10 +30,8 @@ static int sbi_hsm_hart_start(unsigned long hartid, unsigned long saddr,
 
 	ret = sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_START,
 			hartid, saddr, priv, 0, 0, 0);
-	if (ret.error)
-		return sbi_err_map_linux_errno(ret.error);
-	else
-		return 0;
+
+	return sbi_err_map_linux_errno(ret.error);
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
@@ -43,10 +41,7 @@ static int sbi_hsm_hart_stop(void)
 
 	ret = sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_STOP, 0, 0, 0, 0, 0, 0);
 
-	if (ret.error)
-		return sbi_err_map_linux_errno(ret.error);
-	else
-		return 0;
+	return sbi_err_map_linux_errno(ret.error);
 }
 
 static int sbi_hsm_hart_get_status(unsigned long hartid)
Signature · 7 lines
2.43.0


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

Re: [PATCH v1 2/2] riscv: cpu_ops_sbi: No need to be bothered to check ret.error

Quoted 5 lines · Hui Wang

If the ret.error equals to 0, the sbi_err_map_linux_errno() can also handle it, i.e. if ret.error is SBI_SUCCESS, it will return 0 immediately, so no need to be bothered to check ret.error here.

Thanks, queued for v7.2.

- Paul

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

maintainer
#3 lore raw
In reply to Hui Wang
Quoted 10 lines · Hui Wang

In the original sbi_cpu_is_stopped(), if rc doesn't equal to the SBI_HSM_STATE_STOPPED, it will return rc to the caller directly. But there is a hidden problem, the rc could be SBI_HSM_STATE_STARTED, if so, this function will report cpu stopped while the cpu isn't really stopped.

Furthermore, from the name of cpu_is_stopped(), it gives a sense the return value is a bool type, true means the cpu is stopped, conversely false means the cpu is not stopped.

Quoted 5 lines

Here change the return value type to bool and change the callers accordingly. This could fix the above two issues.

Fixes f1e58583b9c7c ("RISC-V: Support cpu hotplug")

Thanks, queued for v7.2.

- Paul

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