Skip to contentSkip to conversation

decouple x2apic from irq remapping

PATCH Applied Gleb Natapov 2 participants 2 messages Feb 18, 2009 – Feb 19, 2009 x86

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 decouple x2apic from irq remapping

Hi,

Currently x2apic is used only if interrupt remapping can be enabled, but if all apic ids are smaller then 255 there is no reason to enable interrupt remapping at all. Although there is not real HW that has x2apic but does not have IR the decoupling is useful since we want to emulate x2apic interface in KVM (it is more vitalization friendly), but we don't want to emulate IR just for that.

According to Intel docs BIOS should pass control to OS in x2apic mode if there are apics with id > 255 and in xapic otherwise, so the proposed patch requires IR configuration only if BIOS switched apic to x2apic mode.

The patch is against tip:x86/apic.

arch/x86/kernel/apic.c +38 -54
index af494ba..2f048f8 100644
@@ -1293,10 +1293,33 @@ void enable_x2apic(void)
 	}
 }
 
-void __init enable_IR_x2apic(void)
+static int __init enable_IR(void)
 {
-#ifdef CONFIG_INTR_REMAP
 	int ret;
+
+	ret = dmar_table_init();
+	if (ret) {
+		pr_info("dmar_table_init() failed with %d:\n", ret);
+		return ret;
+	}
+
+	ret = save_mask_IO_APIC_setup();
+	if (ret) {
+		pr_info("Saving IO-APIC state failed: %d\n", ret);
+		return ret;
+	}
+
+	ret = enable_intr_remapping(1);
+	if (ret)
+		return ret;
+
+	reinit_intr_remapped_IO_APIC(x2apic_preenabled);
+
+	return 0;
+}
+
+void __init enable_IR_x2apic(void)
+{
 	unsigned long flags;
 
 	if (!cpu_has_x2apic)
@@ -1317,72 +1340,33 @@ void __init enable_IR_x2apic(void)
 		return;
 	}
 
-	ret = dmar_table_init();
-	if (ret) {
-		pr_info("dmar_table_init() failed with %d:\n", ret);
-
-		if (x2apic_preenabled)
-			panic("x2apic enabled by bios. But IR enabling failed");
-		else
-			pr_info("Not enabling x2apic,Intr-remapping\n");
-		return;
-	}
-
 	local_irq_save(flags);
 	mask_8259A();
 
-	ret = save_mask_IO_APIC_setup();
-	if (ret) {
-		pr_info("Saving IO-APIC state failed: %d\n", ret);
-		goto end;
-	}
-
-	ret = enable_intr_remapping(1);
-
-	if (ret && x2apic_preenabled) {
+	if (x2apic_preenabled) {
+#ifdef CONFIG_INTR_REMAP
+		if (enable_IR()) {
+			local_irq_restore(flags);
+			panic("x2apic enabled by bios. But IR enabling failed");
+		}
+#else
 		local_irq_restore(flags);
-		panic("x2apic enabled by bios. But IR enabling failed");
+		panic("x2apic enabled prior OS handover,"
+				" enable CONFIG_INTR_REMAP");
+#endif
+		pr_info("Enabled interrupt remapping for x2apic\n");
 	}
 
-	if (ret)
-		goto end_restore;
-
 	if (!x2apic) {
 		x2apic = 1;
 		enable_x2apic();
 	}
 
-end_restore:
-	if (ret)
-		/*
-		 * IR enabling failed
-		 */
-		restore_IO_APIC_setup();
-	else
-		reinit_intr_remapped_IO_APIC(x2apic_preenabled);
-
-end:
 	unmask_8259A();
 	local_irq_restore(flags);
 
-	if (!ret) {
-		if (!x2apic_preenabled)
-			pr_info("Enabled x2apic and interrupt-remapping\n");
-		else
-			pr_info("Enabled Interrupt-remapping\n");
-	} else
-		pr_err("Failed to enable Interrupt-remapping and x2apic\n");
-#else
-	if (!cpu_has_x2apic)
-		return;
-
-	if (x2apic_preenabled)
-		panic("x2apic enabled prior OS handover,"
-		      " enable CONFIG_INTR_REMAP");
-
-	pr_info("Enable CONFIG_INTR_REMAP for enabling intr-remapping "
-		" and x2apic\n");
-#endif
+	if (!x2apic_preenabled)
+		pr_info("Enabled x2apic\n");
 
 	return;
 }
arch/x86/kernel/genapic_64.c +0 -7
index ef78863..0fd3bed 100644
@@ -49,13 +49,6 @@ static struct genapic *apic_probe[] __initdata = {
  */
 void __init default_setup_apic_routing(void)
 {
-#ifdef CONFIG_X86_X2APIC
-	if (apic == &apic_x2apic_phys || apic == &apic_x2apic_cluster) {
-		if (!intr_remapping_enabled)
-			apic = &apic_flat;
-	}
-#endif
-
 	if (apic == &apic_flat) {
 		if (max_physical_apicid >= 8)
 			apic = &apic_physflat;
arch/x86/kernel/genx2apic_cluster.c +35 -23

79 lines not on this page · raw message

--
Gleb.

Applied
#1 lore raw
Quoted 9 lines · Gleb Natapov

Hi,

Currently x2apic is used only if interrupt remapping can be enabled, but if all apic ids are smaller then 255 there is no reason to enable interrupt remapping at all. Although there is not real HW that has x2apic but does not have IR the decoupling is useful since we want to emulate x2apic interface in KVM (it is more vitalization friendly), but we don't want to emulate IR just for that.

Quoted 6 lines

According to Intel docs BIOS should pass control to OS in x2apic mode if there are apics with id > 255 and in xapic otherwise, so the proposed patch requires IR configuration only if BIOS switched apic to x2apic mode.

The patch is against tip:x86/apic.

Applied to tip:x86/apic, thanks Gleb!

Ingo