Skip to contentSkip to conversation

x86: Set the correct srcbusirq of pci irq mptable

PATCH Superseded Dongli Si 1 participant 4 messages Aug 19, 2024 KVM

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Dongli Si

author
#0 lore raw

PATCH 1/4 x86: Set the correct srcbusirq of pci irq mptable

The srcbusirq should be pci device number where the
interrupt originates. Fix it.

Fixes f83cd16 ("kvm tools: irq: replace the x86 irq rbtree with the PCI device tree")
---
 x86/mptable.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
x86/mptable.c +1 -1
index f13cf0f..f4753bd 100644
@@ -180,7 +180,7 @@ int mptable__init(struct kvm *kvm)
 		unsigned char srcbusirq;
 		struct pci_device_header *pci_hdr = dev_hdr->data;
 
-		srcbusirq = (pci_hdr->subsys_id << 2) | (pci_hdr->irq_pin - 1);
+		srcbusirq = (dev_hdr->dev_num << 2) | (pci_hdr->irq_pin - 1);
 		mpc_intsrc = last_addr;
 		mptable_add_irq_src(mpc_intsrc, pcibusid, srcbusirq, ioapicid, pci_hdr->irq_line);
 
Signature · 1 line
2.44.0
author
#1 lore raw

PATCH 2/4 x86: Add the ISA I/O interrupt assignment entries of mptable

According to Intel MultiProcessor Specification:
"There is one entry for each I/O APIC interrupt input that is connected."

Missing this will cause the guest kernel to report some warnings or errors when enabling the io apic.

Fixes 0c7c14a7 ("kvm tools: Add MP tables support")
---
 x86/mptable.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
x86/mptable.c +18 -3
index f4753bd..82b692e 100644
@@ -171,10 +171,8 @@ int mptable__init(struct kvm *kvm)
 	nentries++;
 
 	/*
-	 * IRQ sources.
-	 * Also note we use PCI irqs here, no for ISA bus yet.
+	 * PCI IRQ sources.
 	 */
-
 	dev_hdr = device__first_dev(DEVICE_BUS_PCI);
 	while (dev_hdr) {
 		unsigned char srcbusirq;
@@ -189,6 +187,23 @@ int mptable__init(struct kvm *kvm)
 		dev_hdr = device__next_dev(dev_hdr);
 	}
 
+	/*
+	 * ISA IRQ sources.
+	 */
+	for (i = 0; i < 16; i++) {
+		if (i == 2)
+			continue;
+
+		mpc_intsrc = last_addr;
+		if (i == 0)
+			mptable_add_irq_src(mpc_intsrc, isabusid, i, ioapicid, 2);
+		else
+			mptable_add_irq_src(mpc_intsrc, isabusid, i, ioapicid, i);
+
+		last_addr = (void *)&mpc_intsrc[1];
+		nentries++;
+	}
+
 	/*
 	 * Local IRQs assignment (LINT0, LINT1)
 	 */
Signature · 1 line
2.44.0
author
#2 lore raw

PATCH 3/4 x86: Remove the noapic option from the kernel command line

In reply to Dongli Si

When running guest kernel 6.9 and later and above and the number of vCPUs is greater than 1, dmesg reports:

[    0.009932] CPU topo: CPU limit of 1 reached. Ignoring further CPUs

Only one CPU is available at this point, solve this problem by enabling io apic.

---
 x86/kvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
x86/kvm.c +1 -1
index 71ebb1e..e07d964 100644
@@ -130,7 +130,7 @@ void kvm__init_ram(struct kvm *kvm)
 /* Arch-specific commandline setup */
 void kvm__arch_set_cmdline(char *cmdline, bool video)
 {
-	strcpy(cmdline, "noapic noacpi pci=conf1 reboot=k panic=1 i8042.direct=1 "
+	strcpy(cmdline, "noacpi pci=conf1 reboot=k panic=1 i8042.direct=1 "
 				"i8042.dumbkbd=1 i8042.nopnp=1");
 	if (video)
 		strcat(cmdline, " video=vesafb");
Signature · 1 line
2.44.0
author
#3 lore raw

PATCH 4/4 x86: Disable Topology Extensions on AMD processors in cpuid

In reply to Dongli Si

When running guest kernel 6.9 and later on AMD processors, dmesg reports:

[    0.001987] [Firmware Bug]: CPU   1: APIC ID mismatch. CPUID: 0x0000 APIC: 0x0001

This is because kvmtool does not support topoext but does not tell the guest, causing the guest kernel to read the wrong Extended APIC ID.

---
 x86/cpuid.c | 3 +++
 1 file changed, 3 insertions(+)
x86/cpuid.c +3 -0
index f4347a8..fd23429 100644
@@ -56,6 +56,9 @@ static void filter_cpuid(struct kvm_cpuid2 *kvm_cpuid, int cpu_id)
 			}
 			break;
 		}
+		case 0x80000001:
+			entry->ecx &= ~(1 << 22);
+			break;
 		default:
 			/* Keep the CPUID function as -is */
 			break;
Signature · 1 line
2.44.0