Userspace changes for configuring irq0->inti2 override (v6)
PATCH 1/5 Userspace changes for configuring irq0->inti2 override (v6)
These patches resolve the irq0->inti2 override issue, and get the hpet working on kvm.
Override and HPET changes are sent as a series because HPET depends on the override. Win2k8 expects the HPET interrupt on inti2, regardless of whether an override exists in the BIOS. And the HPET spec states that in legacy mode, timer interrupt is on inti2.
The irq0->inti2 override will always be used unless the kernel cannot do irq routing (i.e., compatibility with old kernels). So if the kernel is capable, userspace sets up irq0->inti2 via the irq routing interface, and adds the irq0->inti2 override to the MADT interrupt source override table, and the mp table (for the no-acpi case).
Changes from v3:
- changes based on comments from Avi and Gleb.
- corrected legacy enable/disable for in-kernel PIT. The code now best approximates a multiplexer that disables PIT interrupts when HPET is in legacy mode (as described by HPET spec). Any changes to the PIT that may occur while HPET is operating in legacy mode are saved, so if HPET leaves legacy mode, the PIT is just reenabled, with mode set to whatever the last setting from guest was. Legacy mode is disabled at least during crash and shutdown (in Linux), so this needs to be handled properly.
Changes from v4:
- Modify mp_table entry count depending on whether irq_override is enabled.
--- kvm/bios/rombios32.c | 67 ++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 51 insertions(+), 16 deletions(-)
kvm/bios/rombios32.c +51 -16
@@ -446,6 +446,9 @@ uint32_t cpuid_features;uint32_t cpuid_ext_features;unsigned long ram_size;uint64_t ram_end; +#ifdef BX_QEMU +uint8_t irq0_override; +#endif #ifdef BX_USE_EBDA_TABLES unsigned long ebda_cur_addr;#endif
@@ -487,6 +490,7 @@ void wrmsr_smp(uint32_t index, uint64_t val)#define QEMU_CFG_ARCH_LOCAL 0x8000#define QEMU_CFG_ACPI_TABLES (QEMU_CFG_ARCH_LOCAL + 0)#define QEMU_CFG_SMBIOS_ENTRIES (QEMU_CFG_ARCH_LOCAL + 1) +#define QEMU_CFG_IRQ0_OVERRIDE (QEMU_CFG_ARCH_LOCAL + 2)int qemu_cfg_port;
@@ -555,6 +559,17 @@ uint64_t qemu_cfg_get64 (void) }#endif +#ifdef BX_QEMU +void irq0_override_probe (void ) +{ +if (qemu_cfg_port) { +qemu_cfg_select (QEMU_CFG_IRQ0_OVERRIDE ); +qemu_cfg_read (&irq0_override,1 ); +return ; + } +} +#endif +void cpu_probe (void ) {uint32_t eax, ebx, ecx, edx;
@@ -1153,7 +1168,14 @@ static void mptable_init(void)putstr (&q,"0.1 " );/* vendor id */ putle32 (&q,0 );/* OEM table ptr */ putle16 (&q,0 );/* OEM table size */ +#ifdef BX_QEMU +if (irq0_override) +putle16 (&q,MAX_CPUS +17 );/* entry count */ +else +putle16 (&q,MAX_CPUS +18 );/* entry count */ +#else putle16 (&q,MAX_CPUS +18 );/* entry count */ +#endif putle32 (&q,0xfee00000 );/* local APIC addr */ putle16 (&q,0 );/* ext table length */ putb (&q,0 );/* ext table checksum */
@@ -1197,6 +1219,13 @@ static void mptable_init(void)/* irqs */ for (i =0 ; i <16 ; i++) { +#ifdef BX_QEMU +/* One entry per ioapic interrupt destination. Destination 2 is covered +* by irq0->inti2 override (i == 0). Source IRQ 2 is unused +*/ +if (irq0_override && i ==2 ) +continue ; +#endif putb (&q,3 );/* entry type = I/O interrupt */ putb (&q,0 );/* interrupt type = vectored interrupt */ putb (&q,0 );/* flags: po=0, el=0 */
@@ -1204,7 +1233,12 @@ static void mptable_init(void)putb (&q,0 );/* source bus ID = ISA */ putb (&q, i);/* source bus IRQ */ putb (&q, ioapic_id);/* dest I/O APIC ID */ -putb (&q, i);/* dest I/O APIC interrupt in */ +#ifdef BX_QEMU +if (irq0_override && i ==0 ) +putb (&q,2 );/* dest I/O APIC interrupt in */ + else +#endif +putb (&q, i);/* dest I/O APIC interrupt in */ }/* patch length */ len = q - mp_config_table;
@@ -1760,23 +1794,21 @@ void acpi_bios_init(void) io_apic->io_apic_id = smp_cpus; io_apic->address =cpu_to_le32 (0xfec00000 ); io_apic->interrupt =cpu_to_le32 (0 ); -#ifdef BX_QEMU -#ifdef HPET_WORKS_IN_KVM io_apic++; - - int_override = (void *)io_apic; - int_override->type =APIC_XRUPT_OVERRIDE ; - int_override->length =sizeof (*int_override); - int_override->bus =cpu_to_le32 (0 ); - int_override->source =cpu_to_le32 (0 ); - int_override->gsi =cpu_to_le32 (2 ); - int_override->flags =cpu_to_le32 (0 ); -#endif + int_override = (struct madt_int_override *)(io_apic); +#ifdef BX_QEMU +if (irq0_override) { +memset (int_override,0 ,sizeof (*int_override)); + int_override->type =APIC_XRUPT_OVERRIDE ; + int_override->length =sizeof (*int_override); + int_override->source =0 ; + int_override->gsi =2 ; + int_override->flags =0 ;/* conforms to bus specifications */ + int_override++; + }#endif - - int_override = (struct madt_int_override *)(io_apic +1 ); -for ( i =0 ; i <16 ; i++ ) { -if (PCI_ISA_IRQ_MASK & (1U << i) ) { +for (i =0 ; i <16 ; i++) { +if (PCI_ISA_IRQ_MASK & (1U << i)) {memset (int_override,0 ,sizeof (*int_override)); int_override->type =APIC_XRUPT_OVERRIDE ; int_override->length =sizeof (*int_override);
@@ -2700,6 +2732,9 @@ void rombios32_init(uint32_t *s3_resume_vector, uint8_t *shutdown_flag)if (bios_table_cur_addr !=0 ) { +#ifdef BX_QEMU +irq0_override_probe (); +#endif mptable_init ();smbios_init ();
PATCH 2/5 Userspace changes for configuring irq0->inti2 override (v6)
--- hw/ioapic.c | 6 +++--- hw/pc.c | 2 ++ qemu-kvm-x86.c | 6 +++++- qemu-kvm.h | 2 ++ sysemu.h | 1 + vl.c | 11 +++++++++-- 6 files changed, 22 insertions(+), 6 deletions(-)
hw/ioapic.c +3 -3
@@ -23,6 +23,7 @@#include "hw.h" #include "pc.h" +#include "sysemu.h" #include "qemu-timer.h" #include "host-utils.h"
@@ -95,14 +96,13 @@ void ioapic_set_irq(void *opaque, int vector, int level) {IOAPICState *s = opaque; -#if 0 /* ISA IRQs map to GSI 1-1 except for IRQ0 which maps * to GSI 2. GSI maps to ioapic 1-1. This is not * the cleanest way of doing it but it should work. */ -if (vector ==0 ) +if (vector ==0 && irq0override) { vector =2 ; -#endif + }if (vector >=0 && vector <IOAPIC_NUM_PINS ) {uint32_t mask =1 << vector;
hw/pc.c +2 -0
@@ -55,6 +55,7 @@#define BIOS_CFG_IOPORT 0x510#define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0)#define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1) +#define FW_CFG_IRQ0_OVERRIDE (FW_CFG_ARCH_LOCAL + 2)#define MAX_IDE_BUS 2
@@ -476,6 +477,7 @@ static void bochs_bios_init(void)fw_cfg_add_i64 (fw_cfg,FW_CFG_RAM_SIZE , (uint64_t )ram_size);fw_cfg_add_bytes (fw_cfg,FW_CFG_ACPI_TABLES , (uint8_t *)acpi_tables, acpi_tables_len); +fw_cfg_add_bytes (fw_cfg,FW_CFG_IRQ0_OVERRIDE , &irq0override,1 ); smbios_table =smbios_get_table (&smbios_len);if (smbios_table)
qemu-kvm-x86.c +5 -1
@@ -909,7 +909,11 @@ int kvm_arch_init_irq_routing(void)return r; }for (i =0 ; i <24 ; ++i) { - r =kvm_add_irq_route (kvm_context, i,KVM_IRQCHIP_IOAPIC , i); +if (i ==0 ) { + r =kvm_add_irq_route (kvm_context, i,KVM_IRQCHIP_IOAPIC ,2 ); + }else if (i !=2 ) { + r =kvm_add_irq_route (kvm_context, i,KVM_IRQCHIP_IOAPIC , i); + }if (r <0 )return r; }
qemu-kvm.h +2 -0
@@ -169,6 +169,7 @@ int handle_tpr_access(void *opaque, kvm_vcpu_context_t vcpu,#define kvm_enabled () (kvm_allowed)#define qemu_kvm_irqchip_in_kernel () kvm_irqchip_in_kernel(kvm_context)#define qemu_kvm_pit_in_kernel () kvm_pit_in_kernel(kvm_context) +#define qemu_kvm_has_gsi_routing () kvm_has_gsi_routing(kvm_context)#define kvm_has_sync_mmu () qemu_kvm_has_sync_mmu()void kvm_init_vcpu (CPUState *env);void kvm_load_tsc (CPUState *env);
@@ -177,6 +178,7 @@ void kvm_load_tsc(CPUState *env);#define kvm_nested 0#define qemu_kvm_irqchip_in_kernel () (0)#define qemu_kvm_pit_in_kernel () (0) +#define qemu_kvm_has_gsi_routing () (0)#define kvm_has_sync_mmu () (0)#define kvm_load_registers (env) do {} while(0)#define kvm_save_registers (env) do {} while(0)
sysemu.h +1 -0
@@ -108,6 +108,7 @@ extern int xenfb_enabled;extern int graphic_width;extern int graphic_height;extern int graphic_depth; +extern uint8_t irq0override;extern DisplayType display_type;extern const char *keyboard_layout;extern int win2k_install_hack;
vl.c +9 -2
@@ -253,6 +253,7 @@ int no_reboot = 0;int no_shutdown =0 ;int cursor_hide =1 ;int graphic_rotate =0 ; +uint8_t irq0override =1 ;#ifndef _WIN32int daemonize =0 ;#endif
@@ -6054,8 +6055,14 @@ int main(int argc, char **argv, char **envp)module_call_init (MODULE_INIT_DEVICE ); -if (kvm_enabled ()) -kvm_init_ap (); +if (kvm_enabled ()) { +kvm_init_ap (); +#ifdef USE_KVM +if (kvm_irqchip && !qemu_kvm_has_gsi_routing ()) { + irq0override =0 ; + } +#endif + } machine->init (ram_size, boot_devices, kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
PATCH 3/5 BIOS changes for KVM HPET (v6)
In reply to Beth Kon--- kvm/bios/acpi-dsdt.dsl | 2 -- kvm/bios/rombios32.c | 11 +++-------- 2 files changed, 3 insertions(+), 10 deletions(-)
kvm/bios/acpi-dsdt.dsl +0 -2
@@ -296,7 +296,6 @@ DefinitionBlock ( }) } #ifdef BX_QEMU -#ifdef HPET_WORKS_IN_KVM Device(HPET) { Name(_HID, EISAID("PNP0103")) Name(_UID, 0)
@@ -316,7 +315,6 @@ DefinitionBlock ( }) } #endif -#endif } Scope(\_SB.PCI0) {
kvm/bios/rombios32.c +3 -8
@@ -1518,8 +1518,8 @@ struct acpi_20_generic_address { } __attribute__((__packed__));/* -* * HPET Description Table -* */ +* HPET Description Table +*/ struct acpi_20_hpet {ACPI_TABLE_HEADER_DEF /* ACPI common table header */ uint32_t timer_block_id;
@@ -1703,13 +1703,11 @@ void acpi_bios_init(void) addr += madt_size;#ifdef BX_QEMU -#ifdef HPET_WORKS_IN_KVM addr = (addr +7 ) & ~7 ; hpet_addr = addr; hpet = (void *)(addr); addr +=sizeof (*hpet);#endif -#endif /* RSDP */ memset (rsdp,0 ,sizeof (*rsdp));
@@ -1883,7 +1881,6 @@ void acpi_bios_init(void) }/* HPET */ -#ifdef HPET_WORKS_IN_KVM memset (hpet,0 ,sizeof (*hpet));/* Note timer_block_id value must be kept in sync with value advertised by * emulated hpet
@@ -1892,7 +1889,6 @@ void acpi_bios_init(void) hpet->addr.address =cpu_to_le32 (ACPI_HPET_ADDRESS );acpi_build_table_header ((struct acpi_table_header *)hpet,"HPET" ,sizeof (*hpet),1 ); -#endif acpi_additional_tables ();/* resets cfg to required entry */ for (i =0 ; i < external_tables; i++) {
@@ -1912,8 +1908,7 @@ void acpi_bios_init(void)/* kvm has no ssdt (processors are in dsdt) */ // rsdt->table_offset_entry[nb_rsdt_entries++] = cpu_to_le32(ssdt_addr); #ifdef BX_QEMU -/* No HPET (yet) */ -// rsdt->table_offset_entry[nb_rsdt_entries++] = cpu_to_le32(hpet_addr); + rsdt->table_offset_entry[nb_rsdt_entries++] =cpu_to_le32 (hpet_addr);if (nb_numa_nodes >0 ) rsdt->table_offset_entry[nb_rsdt_entries++] =cpu_to_le32 (srat_addr);#endif
PATCH 4/5 Userspace changes for KVM HPET (v6)
In reply to Beth KonThe big change here is handling of enabling/disabling of hpet legacy mode. When hpet enters legacy mode, the spec says that the pit stops generating interrupts. In practice, we want to stop the pit periodic timer from running because it is wasteful in a virtual environment.
We also have to worry about the hpet leaving legacy mode (which, at least in linux, happens only during a shutdown or crash). At this point, according to the hpet spec, PIT interrupts need to be reenabled. For us, it means the PIT timer needs to be restarted.
This patch handles this situation better than the previous version by coming closer to just disabling PIT interrupts. It allows the PIT state to change if the OS modifies it, even while PIT is disabled, but does not allow a pit timer to start. Then if HPET legacy mode is disabled, whatever the PIT state is at that point, the PIT timer is restarted accordingly.
---
hw/hpet.c +11 -4
@@ -206,6 +206,9 @@ static int hpet_load(QEMUFile *f, void *opaque, int version_id)qemu_get_timer (f, s->timer[i].qemu_timer); } } +if (hpet_in_legacy_mode ()) { +hpet_disable_pit (); + }return 0 ; }
@@ -475,9 +478,11 @@ static void hpet_ram_writel(void *opaque, target_phys_addr_t addr, }/* i8254 and RTC are disabled when HPET is in legacy mode */ if (activating_bit (old_val, new_val,HPET_CFG_LEGACY )) { -hpet_pit_disable (); +hpet_disable_pit (); +dprintf ("qemu: hpet disabled pit\n" ); }else if (deactivating_bit (old_val, new_val,HPET_CFG_LEGACY )) { -hpet_pit_enable (); +hpet_enable_pit (); +dprintf ("qemu: hpet enabled pit\n" ); }break ;case HPET_CFG +4 :
@@ -554,13 +559,15 @@ static void hpet_reset(void *opaque) {/* 64-bit main counter; 3 timers supported; LegacyReplacementRoute. */ s->capability =0x8086a201ULL ; s->capability |= ((HPET_CLK_PERIOD ) <<32 ); -if (count >0 ) +if (count >0 ) {/* we don't enable pit when hpet_reset is first called (by hpet_init) * because hpet is taking over for pit here. On subsequent invocations, * hpet_reset is called due to system reset. At this point control must * be returned to pit until SW reenables hpet. */ -hpet_pit_enable (); +hpet_enable_pit (); +dprintf ("qemu: hpet enabled pit\n" ); + } count =1 ; }
hw/i8254.c +30 -13
90 lines not on this page · raw message
hw/i8254.h +2 -0
@@ -35,6 +35,7 @@ typedef struct PITChannelState { int count; /* can be 65536 */ + uint8_t channel; uint16_t latched_count; uint8_t count_latched; uint8_t status_latched;
@@ -55,6 +56,7 @@ typedef struct PITChannelState {struct PITState {PITChannelState channels[3 ]; +uint8_t hpet_legacy_mode; };void pit_save (QEMUFile *f,void *opaque);
hw/pc.h +2 -2
@@ -74,8 +74,8 @@ int pit_get_out(PITState *pit, int channel, int64_t current_time);PITState *kvm_pit_init (int base,qemu_irq irq); -void hpet_pit_disable (void ); -void hpet_pit_enable (void ); +void hpet_disable_pit (void ); +void hpet_enable_pit (void );/* vmport.c */ void vmport_init (void );
kvm/include/x86/asm/kvm.h +1 -0
@@ -274,6 +274,7 @@ struct kvm_guest_debug_arch {struct kvm_pit_state {struct kvm_pit_channel_state channels[3 ]; +__u8 hpet_legacy_mode; };struct kvm_reinject_control {
qemu-kvm.c +20 -0
@@ -467,6 +467,26 @@ int kvm_vcpu_inited(CPUState *env)return env->kvm_cpu_state.created; } +void kvm_hpet_disable_kpit (void ) +{ +struct kvm_pit_state ps; +if (qemu_kvm_pit_in_kernel ()) { +kvm_get_pit (kvm_context, &ps); + ps.hpet_legacy_mode =1 ; +kvm_set_pit (kvm_context, &ps); + } +} + +void kvm_hpet_enable_kpit (void ) +{ +struct kvm_pit_state ps; +if (qemu_kvm_pit_in_kernel ()) { +kvm_get_pit (kvm_context, &ps); + ps.hpet_legacy_mode =0 ; +kvm_set_pit (kvm_context, &ps); + } +} +int kvm_init_ap (void ) {#ifdef TARGET_I386
qemu-kvm.h +2 -1
@@ -34,7 +34,8 @@ int kvm_qemu_check_extension(int ext);void kvm_apic_init (CPUState *env);/* called from vcpu initialization */ void qemu_kvm_load_lapic (CPUState *env); - +void kvm_hpet_enable_kpit (void ); +void kvm_hpet_disable_kpit (void );int kvm_set_irq (int irq,int level,int *status);int kvm_physical_memory_set_dirty_tracking (int enable);
vl.c +6 -1
@@ -6056,10 +6056,15 @@ int main(int argc, char **argv, char **envp)module_call_init (MODULE_INIT_DEVICE );if (kvm_enabled ()) { -kvm_init_ap (); +kvm_init_ap ();#ifdef USE_KVM if (kvm_irqchip && !qemu_kvm_has_gsi_routing ()) { irq0override =0 ; +/* if kernel can't do irq routing, interrupt source +* override 0->2 can not be set up as required by hpet, +* so disable hpet. +*/ + no_hpet=1 ; }#endif }
Re: [PATCH 4/5] Userspace changes for KVM HPET (v6)
Quoted 12 lines · Beth Kon
The big change here is handling of enabling/disabling of hpet legacy mode. When hpet enters
legacy mode, the spec says that the pit stops generating interrupts. In practice, we want to stop the pit periodic timer from running because it is wasteful in a virtual environment.We also have to worry about the hpet leaving legacy mode (which, at least in linux, happens only during a shutdown or crash). At this point, according to the hpet spec, PIT interrupts need to be reenabled. For us, it means the PIT timer needs to be restarted.
This patch handles this situation better than the previous version by coming closer to just disabling PIT interrupts. It allows the PIT state to change if the OS modifies it, even while PIT is disabled, but does not allow a pit timer to start. Then if HPET
legacy mode is disabled, whatever the PIT state is at that point, the PIT timer is restarted accordingly.
Given that this depends on the ABI-breaking patch 5, I've dropped it too.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH 4/5] Userspace changes for KVM HPET (v6)
Quoted 11 lines · Avi Kivity
Quoted 9 lines · Beth Kon
The big change here is handling of enabling/disabling of hpet legacy mode. When hpet enters
legacy mode, the spec says that the pit stops generating interrupts. In practice, we want to stop the pit periodic timer from running because it is wasteful in a virtual environment.
We also have to worry about the hpet leaving legacy mode (which, at least in linux, happens
only during a shutdown or crash). At this point, according to the hpet spec, PIT interrupts
need to be reenabled. For us, it means the PIT timer needs to be restarted. This patch handles this situation better than the previous version by coming closer to just disabling PIT interrupts. It allows the PIT state to change if the OS modifies it, even while PIT is disabled, but does not allow a pit timer to start. Then if HPET
legacy mode is disabled, whatever the PIT state is at that point, the PIT timer is restarted accordingly.
Quoted 2 lines
Given that this depends on the ABI-breaking patch 5, I've dropped it too.
Actually, I got nervous about applying a partial patchset (which is likely to be untested), so I dropped everything else. I pushed the three patches to an 'hpet' branch of qemu-kvm.git, so you don't have to redo the rebasing I did.
Signature · 1 line
error compiling committee.c: too many arguments to function
PATCH 5/5 HPET interaction with in-kernel PIT (v6)
In reply to Beth Kon--- arch/x86/include/asm/kvm.h | 1 + arch/x86/kvm/i8254.c | 24 +++++++++++++++++++----- arch/x86/kvm/i8254.h | 3 ++- arch/x86/kvm/x86.c | 5 ++++- 4 files changed, 26 insertions(+), 7 deletions(-)
arch/x86/include/asm/kvm.h +1 -0
@@ -235,6 +235,7 @@ struct kvm_guest_debug_arch {struct kvm_pit_state {struct kvm_pit_channel_state channels[3 ]; +u8 hpet_legacy_mode; };struct kvm_reinject_control {
arch/x86/kvm/i8254.c +19 -5
@@ -340,10 +340,20 @@ static void pit_load_count(struct kvm *kvm, int channel, u32 val) } } -void kvm_pit_load_count (struct kvm *kvm,int channel,u32 val) +void kvm_pit_load_count (struct kvm *kvm,int channel,u32 val,int hpet_legacy_start) { +u8 saved_mode;mutex_lock (&kvm->arch.vpit->pit_state.lock); -pit_load_count (kvm, channel, val); +if (hpet_legacy_start) { +/* save existing mode for later reenablement */ + saved_mode = kvm->arch.vpit->pit_state.channels[0 ].mode; + kvm->arch.vpit->pit_state.channels[0 ].mode =0xff ;/* disable timer */ +pit_load_count (kvm, channel, val); + kvm->arch.vpit->pit_state.channels[0 ].mode = saved_mode; + }else { +if (!(channel ==0 && kvm->arch.vpit->pit_state.hpet_legacy_mode)) +pit_load_count (kvm, channel, val); + }mutex_unlock (&kvm->arch.vpit->pit_state.lock); }
@@ -411,17 +421,20 @@ static void pit_ioport_write(struct kvm_io_device *this,switch (s->write_state) {default :case RW_STATE_LSB : -pit_load_count (kvm, addr, val); +if (!(addr ==0 && pit_state->hpet_legacy_mode)) +pit_load_count (kvm, addr, val);break ;case RW_STATE_MSB : -pit_load_count (kvm, addr, val <<8 ); +if (!(addr ==0 && pit_state->hpet_legacy_mode)) +pit_load_count (kvm, addr, val <<8 );break ;case RW_STATE_WORD0 : s->write_latch = val; s->write_state =RW_STATE_WORD1 ;break ;case RW_STATE_WORD1 : -pit_load_count (kvm, addr, s->write_latch | (val <<8 )); +if (!(addr ==0 && pit_state->hpet_legacy_mode)) +pit_load_count (kvm, addr, s->write_latch | (val <<8 )); s->write_state =RW_STATE_WORD0 ;break ; }
@@ -548,6 +561,7 @@ void kvm_pit_reset(struct kvm_pit *pit)struct kvm_kpit_channel_state *c;mutex_lock (&pit->pit_state.lock); + pit->pit_state.hpet_legacy_mode =0 ;for (i =0 ; i <3 ; i++) { c = &pit->pit_state.channels[i]; c->mode =0xff ;
arch/x86/kvm/i8254.h +2 -1
@@ -21,6 +21,7 @@ struct kvm_kpit_channel_state {struct kvm_kpit_state {struct kvm_kpit_channel_state channels[3 ]; +u8 hpet_legacy_mode;struct kvm_timer pit_timer;bool is_periodic;u32 speaker_data_on;
@@ -49,7 +50,7 @@ struct kvm_pit {#define KVM_PIT_CHANNEL_MASK 0x3void kvm_inject_pit_timer_irqs (struct kvm_vcpu *vcpu); -void kvm_pit_load_count (struct kvm *kvm,int channel,u32 val); +void kvm_pit_load_count (struct kvm *kvm,int channel,u32 val,int hpet_legacy_start);struct kvm_pit *kvm_create_pit (struct kvm *kvm,u32 flags);void kvm_free_pit (struct kvm *kvm);void kvm_pit_reset (struct kvm_pit *pit);
arch/x86/kvm/x86.c +4 -1
@@ -1948,9 +1948,12 @@ static int kvm_vm_ioctl_get_pit(struct kvm *kvm, struct kvm_pit_state *ps)static int kvm_vm_ioctl_set_pit (struct kvm *kvm,struct kvm_pit_state *ps) {int r =0 ; +int hpet_legacy_start =0 ; +if (ps->hpet_legacy_mode && !kvm->arch.vpit->pit_state.hpet_legacy_mode) + hpet_legacy_start =1 ;memcpy (&kvm->arch.vpit->pit_state, ps,sizeof (struct kvm_pit_state )); -kvm_pit_load_count (kvm,0 , ps->channels[0 ].count); +kvm_pit_load_count (kvm,0 , ps->channels[0 ].count, hpet_legacy_start);return r; }
Re: [PATCH 5/5] HPET interaction with in-kernel PIT (v6)
Quoted 3 lines · Beth Kon
Signed-off-by Beth Kon <[email protected]>
Please write a few words on what this patch does and why.
Quoted 12 lines
--- arch/x86/include/asm/kvm.h | 1 + arch/x86/kvm/i8254.c | 24 +++++++++++++++++++----- arch/x86/kvm/i8254.h | 3 ++- arch/x86/kvm/x86.c | 5 ++++- 4 files changed, 26 insertions(+), 7 deletions(-)arch/x86/include/asm/kvm.h +0
-0
arch/x86/include/asm/kvm.h struct kvm_guest_debug_arch { · line 240
Quoted 6 lines
arch/x86/include/asm/kvm.h +1
-0@@ -235,6 +235,7 @@ struct kvm_guest_debug_arch {struct kvm_pit_state {struct kvm_pit_channel_state channels[3 ]; +u8 hpet_legacy_mode; };
This changes the ABI, breaking older binaries running on newer kernels, or newer binaries running on older kernels.
Quoted 10 lines
arch/x86/include/asm/kvm.h +2
-2@@ -340,10 +340,20 @@ static void pit_load_count(struct kvm *kvm, int channel, u32 val) } } -void kvm_pit_load_count (struct kvm *kvm,int channel,u32 val) +void kvm_pit_load_count (struct kvm *kvm,int channel,u32 val,int hpet_legacy_start) { +u8 saved_mode;mutex_lock (&kvm->arch.vpit->pit_state.lock); -pit_load_count (kvm, channel, val);
arch/x86/include/asm/kvm.h static void pit_load_count(struct kvm *kvm, int channel, u32 val) · line 356
Quoted 10 lines
arch/x86/include/asm/kvm.h +9
-0+if (hpet_legacy_start) { +/* save existing mode for later reenablement */ + saved_mode = kvm->arch.vpit->pit_state.channels[0 ].mode; + kvm->arch.vpit->pit_state.channels[0 ].mode =0xff ;/* disable timer */ +pit_load_count (kvm, channel, val); + kvm->arch.vpit->pit_state.channels[0 ].mode = saved_mode; + }else { +if (!(channel ==0 && kvm->arch.vpit->pit_state.hpet_legacy_mode)) +pit_load_count (kvm, channel, val);
Overindented.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH 5/5] HPET interaction with in-kernel PIT (v6)
Quoted 20 lines · Avi Kivity
Quoted 3 lines · Beth Kon
Signed-off-by Beth Kon <[email protected]>Please write a few words on what this patch does and why.
Quoted 13 lines
--- arch/x86/include/asm/kvm.h | 1 + arch/x86/kvm/i8254.c | 24 +++++++++++++++++++----- arch/x86/kvm/i8254.h | 3 ++- arch/x86/kvm/x86.c | 5 ++++- 4 files changed, 26 insertions(+), 7 deletions(-)arch/x86/include/asm/kvm.h +0
-0@@ -235,6 +235,7 @@ struct kvm_guest_debug_arch {
Quoted 8 lines
arch/x86/include/asm/kvm.h struct kvm_guest_debug_arch { · line 240
Quoted 5 lines
arch/x86/include/asm/kvm.h +1
-0struct kvm_pit_state {struct kvm_pit_channel_state channels[3 ]; +u8 hpet_legacy_mode; };This changes the ABI, breaking older binaries running on newer kernels, or newer binaries running on older kernels.
As we have KVM_CREATE_PIT2 now, which includes struct kvm_pit_config with a lot of unused flags, it should be straightforward to negotiate the kvm_pit_state format between kernel and user space: kernel advertises support for the new one via capability, user space requests it via a bit in kvm_pit_state.flags.
Jan
Re: [PATCH 5/5] HPET interaction with in-kernel PIT (v6)
Quoted 11 lines · Jan Kiszka
Quoted 10 lines
Quoted 7 lines
struct kvm_pit_state { struct kvm_pit_channel_state channels[3];+ u8
hpet_legacy_mode;
};This changes the ABI, breaking older binaries running on newer kernels, or newer binaries running on older kernels.
Quoted 6 lines
As we have
KVM_CREATE_PIT2now, which includes structkvm_pit_configwith a lot of unused flags, it should be straightforward to negotiate thekvm_pit_stateformat between kernel and user space: kernel advertises support for the new one via capability, user space requests it via a bit in kvm_pit_state.flags.
We still need a new ioctl. The structure size is embedded in the ioctl number, so any additions automatically cause version mismatches.
I sent patches some time ago to have the kernel automatically adjust for this, but they weren't well received.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH 5/5] HPET interaction with in-kernel PIT (v6)
Quoted 18 lines · Avi Kivity
Quoted 10 lines · Jan Kiszka
Quoted 9 lines
Quoted 6 lines
struct kvm_pit_state { struct kvm_pit_channel_state channels[3];+ u8
hpet_legacy_mode;
};This changes the ABI, breaking older binaries running on newer kernels, or newer binaries running on older kernels.
Quoted 6 lines
As we have
KVM_CREATE_PIT2now, which includes structkvm_pit_configwith a lot of unused flags, it should be straightforward to negotiate thekvm_pit_stateformat between kernel and user space: kernel advertises support for the new one via capability, user space requests it via a bit in kvm_pit_state.flags.
Quoted 5 lines
We still need a new ioctl. The structure size is embedded in the ioctl number, so any additions automatically cause version mismatches.
I sent patches some time ago to have the kernel automatically adjust for this, but they weren't well received.
Unfortunate. But on the one hand, nothing technically prevents defining the IOCTL base on existing kvm_pit_state, but passing down extended kvm_pit_state2 if that negotiation took place. On the other hand, we are not yet running out of IOCTL numbers...
However, I guess kvm_pit_state2 will also need some flags field and a bit tail room for potential future extensions.
Jan
Re: [PATCH 5/5] HPET interaction with in-kernel PIT (v6)
Quoted 5 lines · Jan Kiszka
Unfortunate. But on the one hand, nothing technically prevents defining the IOCTL base on existing
kvm_pit_state, but passing down extendedkvm_pit_state2if that negotiation took place. On the other hand, we are not yet running out of IOCTL numbers...
Right, and we are not in any competition for most obfuscated interface yet (though we'd probably get an honourable mention if we were to apply).
Quoted 3 lines
However, I guess
kvm_pit_state2will also need some flags field and a bit tail room for potential future extensions.
Yes, it's a common pattern in kvm.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 8 lines · Beth Kon
These patches resolve the
irq0->inti2override issue, and get the hpet working on kvm.Override and HPET changes are sent as a series because HPET depends on the override. Win2k8 expects the HPET interrupt on inti2, regardless of whether an override exists in the BIOS. And the HPET spec states that in legacy mode, timer interrupt is on inti2.
Quoted 7 lines
The
irq0->inti2override will always be used unless the kernel cannot do irq routing (i.e., compatibility with old kernels). So if the kernel is capable, userspace sets upirq0->inti2via the irq routing interface, and adds theirq0->inti2override to the MADT interrupt source override table, and the mp table (for the no-acpi case).
Applied the first four patches; thanks. See separate reply about patch 5.
Signature · 1 line
error compiling committee.c: too many arguments to function