x86: Fixes issue with only one CPU available in kernel 6.9
v2 cover x86: Fixes issue with only one CPU available in kernel 6.9
On x86 architecture, starting with Linux 6.9, using the "noapic" kernel command line parameter will result in only one CPU being available, which is currently the case with kvmtool, and this series fixes this issue.
v1 version is here:
https://lore.kernel.org/all/[email protected]/
Changes since v1:
- Improved the subject and description of some patches
Dongli Si (4):
x86: Set the correct srcbusirq of pci irq mptable
x86: Add the ISA IRQ entries of mptable
x86: Remove the "noapic" kernel cmdline parameter (for enable the IO
APIC)
x86: Disable Topology Extensions on AMD processors in cpuid
x86/cpuid.c | 3 +++ x86/kvm.c | 2 +- x86/mptable.c | 23 +++++++++++++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-)
Signature · 1 line
2.44.0
PATCH v2 1/4 x86: Set the correct srcbusirq of pci irq mptable
The srcbusirq should be pci device number where the
interrupt originates. Fix it.
--- x86/mptable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
x86/mptable.c +1 -1
@@ -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
PATCH v2 2/4 x86: Add the ISA IRQ entries of mptable
In reply to Dongli SiMissing ISA IRQ entries will cause the guest kernel to report some warnings or errors, for examples:
1, If none of the pci devices are registered, the guest kernel will report:
[ 0.022503] BIOS bug, no explicit IRQ entries, using default mptable. (tell your hw vendor)
2, If the guest kernel cmdline does not have the "noapic" parameter and one or more pci devices are registered, the guest kernel will report:
[ 0.033913] BUG: kernel NULL pointer dereference, address: 0000000000000004 [ 0.034313] #PF: supervisor read access in kernel mode [ 0.034614] #PF: error_code(0x0000) - not-present page [ 0.034911] PGD 0 P4D 0 [ 0.035062] Oops: Oops: 0000 [#1] SMP [ 0.035277] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 6.10.0 #95 [ 0.035628] RIP: 0010:setup_IO_APIC+0x23e/0x7e0 [ 0.035892] Code: ff e8 16 f6 ff ff 89 45 88 e8 5e f6 ff ff 83 3d e3 93 e1 ff 00 8b 1d d9 23 f1 ff 89 85 78 ff ff ff 44 8b 25 d0 23 f1 ff 78 1b <41> 8b 76 04 8b 4d 88 41 89 d9 45 89 e0 89 c2 48 c7 c7 70 fe 8e 81 [ 0.036965] RSP: 0000:ffffffff81a03e20 EFLAGS: 00010002 [ 0.037267] RAX: 00000000ffffffff RBX: 00000000ffffffff RCX: 0000000000000001 [ 0.037681] RDX: 0000000000000001 RSI: 0000000000000001 RDI: 0000000000000000 [ 0.038092] RBP: ffffffff81a03eb0 R08: 0000000000052da5 R09: 0000000000000000 [ 0.038503] R10: ffffffff81a920c0 R11: 0000000000000000 R12: 00000000ffffffff [ 0.038918] R13: ffff88800205f628 R14: 0000000000000000 R15: 0000000000000005 [ 0.039329] FS: 0000000000000000(0000) GS:ffff88807dc00000(0000) knlGS:0000000000000000 [ 0.039798] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 0.040130] CR2: 0000000000000004 CR3: 0000000001a13000 CR4: 00000000000000b0 [ 0.040542] Call Trace: [ 0.040692] <TASK> [ 0.040818] ? show_regs.part.0+0x1d/0x20 [ 0.041053] ? __die+0x52/0x91 [ 0.041234] ? page_fault_oops+0x56/0x1b0 [ 0.041469] ? exc_page_fault+0x3d9/0x5f0 [ 0.041707] ? asm_exc_page_fault+0x27/0x30 [ 0.041952] ? setup_IO_APIC+0x23e/0x7e0 [ 0.042181] ? clear_IO_APIC_pin+0x127/0x1f0 [ 0.042430] ? clear_IO_APIC+0x34/0x60 [ 0.042656] apic_intr_mode_init+0xb5/0xc0 [ 0.042896] x86_late_time_init+0x16/0x30 [ 0.043131] start_kernel+0x546/0x5b0 [ 0.043345] x86_64_start_reservations+0x29/0x30 [ 0.043619] x86_64_start_kernel+0x78/0x80 [ 0.043858] common_startup_64+0x13b/0x148 [ 0.044097] </TASK>
This is because there is no ISA IRQ 0 entry in the mptable which is required by the PIT. In addition, interrupts for the 8250 serial device will also be unavailable because there is also no ISA IRQ 4 entry in mptable.
Solve the above problem by adding all standard ISA IRQ entries.
--- x86/mptable.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
x86/mptable.c +18 -3
@@ -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
PATCH v2 3/4 x86: Remove the "noapic" kernel cmdline parameter (for enable the IO APIC)
In reply to Dongli SiWhen 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
@@ -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
PATCH v2 4/4 x86: Disable Topology Extensions on AMD processors in cpuid
In reply to Dongli SiWhen 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
@@ -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