Skip to contentSkip to conversation

x86: Two minor fixes to apic code

PATCH New Zhenzhong Duan 1 participant 1 message Nov 3, 2021 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: Two minor fixes to apic code

Apicid isn't guaranteed to be consecutive or starting from BSP's. But there are many codes depending on BSP's apicid are smallest among others. This patch makes it works in any case.

Bumping active_cpus in smp_reset_apic() isn't correct as it is already bumped in smp_init(). This can cause on_cpus() in dead loop. Fix it by removing that bumping in smp_reset_apic().

---
 lib/x86/apic.c | 6 ++++++
 lib/x86/smp.c  | 2 --
 2 files changed, 6 insertions(+), 2 deletions(-)
lib/x86/apic.c +6 -0
index da8f301..562b3ec 100644
@@ -237,8 +237,14 @@ extern unsigned char online_cpus[(MAX_TEST_CPUS + 7) / 8];
 void init_apic_map(void)
 {
 	unsigned int i, j = 0;
+	u32 bsp_apicid = apic_id();
+
+	/* BSP's logical id is 0 */
+	id_map[j++] = bsp_apicid;
 
 	for (i = 0; i < MAX_TEST_CPUS; i++) {
+		if (i == bsp_apicid)
+			continue;
 		if ((1ul << (i % 8)) & (online_cpus[i / 8]))
 			id_map[j++] = i;
 	}
lib/x86/smp.c +0 -2
index 2ac0ef7..46d2630 100644
@@ -143,6 +143,4 @@ void smp_reset_apic(void)
     reset_apic();
     for (i = 1; i < cpu_count(); ++i)
         on_cpu(i, do_reset_apic, 0);
-
-    atomic_inc(&active_cpus);
 }
Signature · 1 line
2.25.1