diff mbox series

[v2] riscv: Report error when repeatedly recording CPU hardware ID

Message ID 20240828020718.46977-1-qiaozhe@iscas.ac.cn (mailing list archive)
State New
Headers show
Series [v2] riscv: Report error when repeatedly recording CPU hardware ID | expand

Checks

Context Check Description
conchuod/vmtest-for-next-PR success PR summary
conchuod/patch-1-test-1 success .github/scripts/patches/tests/build_rv32_defconfig.sh
conchuod/patch-1-test-2 success .github/scripts/patches/tests/build_rv64_clang_allmodconfig.sh
conchuod/patch-1-test-3 success .github/scripts/patches/tests/build_rv64_gcc_allmodconfig.sh
conchuod/patch-1-test-4 success .github/scripts/patches/tests/build_rv64_nommu_k210_defconfig.sh
conchuod/patch-1-test-5 success .github/scripts/patches/tests/build_rv64_nommu_virt_defconfig.sh
conchuod/patch-1-test-6 warning .github/scripts/patches/tests/checkpatch.sh
conchuod/patch-1-test-7 success .github/scripts/patches/tests/dtb_warn_rv64.sh
conchuod/patch-1-test-8 success .github/scripts/patches/tests/header_inline.sh
conchuod/patch-1-test-9 success .github/scripts/patches/tests/kdoc.sh
conchuod/patch-1-test-10 success .github/scripts/patches/tests/module_param.sh
conchuod/patch-1-test-11 success .github/scripts/patches/tests/verify_fixes.sh
conchuod/patch-1-test-12 success .github/scripts/patches/tests/verify_signedoff.sh

Commit Message

Zhe Qiao Aug. 28, 2024, 2:07 a.m. UTC
If the same CPU hardware attributes exist, the boot is aborted.
Ensure the uniqueness of the CPU hardware ID recorded in the
__cpuid_to_hartid_map[] array.

Signed-off-by: Zhe Qiao <qiaozhe@iscas.ac.cn>
---
V1 -> V2:
  1. Change the error report to BUG().
  2. Change the function name to is_cartid_duplicate().
  3. Modify commit description.
---
 arch/riscv/kernel/smpboot.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff mbox series

Patch

diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
index 0f8f1c95ac38..f29a6fd55aa8 100644
--- a/arch/riscv/kernel/smpboot.c
+++ b/arch/riscv/kernel/smpboot.c
@@ -118,6 +118,16 @@  static void __init acpi_parse_and_init_cpus(void)
 #define acpi_parse_and_init_cpus(...)	do { } while (0)
 #endif
 
+static bool __init is_hartid_duplicate(unsigned int cpuid, u64 hart)
+{
+	unsigned int i;
+
+	for (i = 1; (i < cpuid) && (i < NR_CPUS); i++)
+		if (cpuid_to_hartid_map(i) == hart)
+			return true;
+	return false;
+}
+
 static void __init of_parse_and_init_cpus(void)
 {
 	struct device_node *dn;
@@ -131,6 +141,9 @@  static void __init of_parse_and_init_cpus(void)
 		if (rc < 0)
 			continue;
 
+		if (is_hartid_duplicate(cpuid, hart))
+			BUG_ON(1);
+
 		if (hart == cpuid_to_hartid_map(0)) {
 			BUG_ON(found_boot_cpu);
 			found_boot_cpu = 1;