qemu-kvm: Cleanup and switch to upstream - Part II
cover qemu-kvm: Cleanup and switch to upstream - Part II
The second round of merging qemu-kvm with upstream. This part stops after switching to upstreams kvm_init implementation.
To achieve this, various small cleanups and refactorings are applied, the irq0 override management is simplified and the kvm_context fields are migrated into KVMState.
Please review/merge.
Jan Kiszka (16):
qemu-kvm: Drop kvm_cpu_register_phys_memory_client wrapper
qemu-kvm: Drop kvm_inject_interrupt
Revert "qemu-kvm-x86: consider the irq0override flag in
kvm_arch_init_irq_routing"
qemu-kvm: Drop IRQ0 override test from ioapic_set_irq
qemu-kvm: Clean up IRQ0 override configuration
qemu-kvm: Refactor irqchip and routing initialization
qemu-kvm: Fold kvm_get_gsi_count into kvm_create_irqchip
qemu-kvm: Make some private functions static
qemu-kvm: Implement kvm_has_pit_state2 in upstream style
qemu-kvm: Fold kvm_set_irq_level into kvm_set_irq
qemu-kvm: Remove kvm_context from public interfaces
qemu-kvm: Fold kvm_set_boot_vcpu_id into kvm_set_boot_cpu_id
qemu-kvm: Remove handle_io_window
qemu-kvm: Merge kvm_context into KVMState
qemu-kvm: Use KVM-optimized interrupt handler
qemu-kvm: Use upstream kvm_init
exec.c | 2 - hw/device-assignment.c | 21 ++- hw/i8254-kvm.c | 12 +- hw/i8254.c | 4 +- hw/i8259.c | 4 +- hw/ioapic.c | 7 +- hw/pc.c | 2 +- hw/pcspk.c | 4 +- kvm-all.c | 48 ++++-- kvm-stub.c | 10 + kvm.h | 17 +- monitor.c | 5 +- qemu-kvm-x86.c | 51 +++--- qemu-kvm.c | 461 ++++++++++++++---------------------------------- qemu-kvm.h | 166 ++---------------- sysemu.h | 1 - target-i386/kvm.c | 8 +- vl.c | 1 - 18 files changed, 257 insertions(+), 567 deletions(-)
PATCH 1/16 qemu-kvm: Drop kvm_cpu_register_phys_memory_client wrapper
--- kvm-all.c | 5 ----- kvm.h | 2 -- qemu-kvm.c | 2 +- 3 files changed, 1 insertions(+), 8 deletions(-)
kvm-all.c +0 -5
@@ -675,11 +675,6 @@ static CPUPhysMemoryClient kvm_cpu_phys_memory_client = { .log_stop = kvm_log_stop, }; -void kvm_cpu_register_phys_memory_client (void ) -{ -cpu_register_phys_memory_client (&kvm_cpu_phys_memory_client); -} -#ifdef OBSOLETE_KVM_IMPL static void kvm_handle_interrupt (CPUState *env,int mask) {
kvm.h +0 -2
@@ -63,8 +63,6 @@ int kvm_init_vcpu(CPUState *env);int kvm_cpu_exec (CPUState *env);#if !defined(CONFIG_USER_ONLY ) -void kvm_cpu_register_phys_memory_client (void ); -void kvm_setup_guest_memory (void *start,size_t size);int kvm_coalesce_mmio_region (target_phys_addr_t start,ram_addr_t size);
qemu-kvm.c +1 -1
@@ -192,7 +192,7 @@ int kvm_init(void) } } -kvm_cpu_register_phys_memory_client (); +cpu_register_phys_memory_client (&kvm_cpu_phys_memory_client);pthread_mutex_lock (&qemu_mutex);return kvm_create_context ();
Signature · 1 line
1.7.1
PATCH 2/16 qemu-kvm: Drop kvm_inject_interrupt
In reply to Jan KiszkaNot required, do_inject_nmi runs under the global mutex and can therefore safely invoke cpu_interrupt (like in upstream).
--- monitor.c | 5 +---- qemu-kvm.c | 10 ---------- qemu-kvm.h | 1 - 3 files changed, 1 insertions(+), 15 deletions(-)
monitor.c +1 -4
@@ -2572,10 +2572,7 @@ static void do_inject_nmi(Monitor *mon, const QDict *qdict)for (env = first_cpu; env !=NULL ; env = env->next_cpu)if (env->cpu_index == cpu_index) { -if (kvm_enabled ()) -kvm_inject_interrupt (env,CPU_INTERRUPT_NMI ); -else -cpu_interrupt (env,CPU_INTERRUPT_NMI ); +cpu_interrupt (env,CPU_INTERRUPT_NMI );break ; } }
qemu-kvm.c +0 -10
@@ -931,16 +931,6 @@ void on_vcpu(CPUState *env, void (*func)(void *data), void *data) } } -static void inject_interrupt (void *data) -{ -cpu_interrupt (current_env, (long ) data); -} - -void kvm_inject_interrupt (CPUState *env,int mask) -{ -on_vcpu (env, inject_interrupt, (void *) (long ) mask); -} -void kvm_update_interrupt_request (CPUState *env) {int signal =0 ;
qemu-kvm.h +0 -1
@@ -407,7 +407,6 @@ void kvm_hpet_enable_kpit(void);void kvm_hpet_disable_kpit (void );void on_vcpu (CPUState *env,void (*func)(void *data),void *data); -void kvm_inject_interrupt (CPUState *env,int mask);void kvm_update_interrupt_request (CPUState *env);int kvm_arch_has_work (CPUState *env);
Signature · 1 line
1.7.1
PATCH 3/16 Revert "qemu-kvm-x86: consider the irq0override flag in kvm_arch_init_irq_routing"
In reply to Jan KiszkaThis reverts commit fd6bfef3d49a62b36092f131690de3e34f84662d.
It is a nop, and it always was a nop:
irq0override = !kvm_irqchip || kvm_has_gsi_routing
But this code is only executed when gsi routing is available.
Conflicts:
qemu-kvm-x86.c
--- qemu-kvm-x86.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
qemu-kvm-x86.c +2 -2
@@ -317,9 +317,9 @@ int kvm_arch_init_irq_routing(void) } }for (i =0 ; i <24 ; ++i) { -if (i ==0 && irq0override) { +if (i ==0 ) { r =kvm_add_irq_route (i,KVM_IRQCHIP_IOAPIC ,2 ); - }else if (i !=2 || !irq0override) { + }else if (i !=2 ) { r =kvm_add_irq_route (i,KVM_IRQCHIP_IOAPIC , i); }if (r <0 ) {
Signature · 1 line
1.7.1
Re: [PATCH 03/16] Revert "qemu-kvm-x86: consider the irq0override flag in kvm_arch_init_irq_routing"
Quoted 7 lines · Jan Kiszka
This reverts commit
fd6bfef3d49a62b36092f131690de3e34f84662d.It is a nop, and it always was a nop:
irq0override = !kvm_irqchip || kvm_has_gsi_routingBut this code is only executed when gsi routing is available.
That means that if kvm_has_gsi_routing, then irq0override = true, and this code is executed?
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH 03/16] Revert "qemu-kvm-x86: consider the irq0override flag in kvm_arch_init_irq_routing"
Quoted 11 lines · Avi Kivity
Quoted 7 lines · Jan Kiszka
This reverts commit
fd6bfef3d49a62b36092f131690de3e34f84662d.It is a nop, and it always was a nop:
irq0override = !kvm_irqchip || kvm_has_gsi_routingBut this code is only executed when gsi routing is available.
That means that if
kvm_has_gsi_routing, then irq0override = true, and this code is executed?
Ah, sorry, you did constant propagation here. Patch is fine.
Signature · 1 line
error compiling committee.c: too many arguments to function
PATCH 4/16 qemu-kvm: Drop IRQ0 override test from ioapic_set_irq
In reply to Jan KiszkaThe IRQ0 override is not configurable while using the user space IOAPIC. When the in-kernel irqchip is active, ioapic_set_irq is never called. So drop this useless test.
--- hw/ioapic.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
hw/ioapic.c +1 -2
@@ -22,7 +22,6 @@#include "hw.h" #include "pc.h" -#include "sysemu.h" #include "apic.h" #include "ioapic.h" #include "qemu-timer.h"
@@ -146,7 +145,7 @@ static void ioapic_set_irq(void *opaque, int vector, int level)* the cleanest way of doing it but it should work. */ DPRINTF ("%s: %s vec %x\n" , __func__, level ?"raise" :"lower" , vector); -if (vector ==0 && irq0override) { +if (vector ==0 ) { vector =2 ; }if (vector >=0 && vector <IOAPIC_NUM_PINS ) {
Signature · 1 line
1.7.1
Re: [PATCH 04/16] qemu-kvm: Drop IRQ0 override test from ioapic_set_irq
Quoted 6 lines · Jan Kiszka
The IRQ0 override is not configurable while using the user space IOAPIC. When the in-kernel irqchip is active,
ioapic_set_irqis never called. So drop this useless test.
hw/ioapic.c static void ioapic_set_irq(void *opaque, int vector, int level) · line 151
Quoted 8 lines
hw/ioapic.c +1
-1@@ -146,7 +145,7 @@ static void ioapic_set_irq(void *opaque, int vector, int level)* the cleanest way of doing it but it should work. */ DPRINTF ("%s: %s vec %x\n" , __func__, level ?"raise" :"lower" , vector); -if (vector ==0 && irq0override) { +if (vector ==0 ) { vector =2 ; }if (vector>=0 && vector<IOAPIC_NUM_PINS ) {
Incidentally, the variable should be called pin, not vector, and gsi->ioapic/pic wiring should be done outside the ioapic code.
Signature · 1 line
error compiling committee.c: too many arguments to function
PATCH 5/16 qemu-kvm: Clean up IRQ0 override configuration
In reply to Jan KiszkaIntroduce kvm_allows_irq0_override to overcome the global irq0override variable and convert the BIOS initialization.
--- hw/pc.c | 2 +- kvm-all.c | 5 +++++ kvm-stub.c | 5 +++++ kvm.h | 1 + qemu-kvm.c | 1 - sysemu.h | 1 - vl.c | 1 - 7 files changed, 12 insertions(+), 4 deletions(-)
hw/pc.c +1 -1
@@ -605,7 +605,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 ); +fw_cfg_add_i32 (fw_cfg,FW_CFG_IRQ0_OVERRIDE ,kvm_allows_irq0_override ()); smbios_table =smbios_get_table (&smbios_len);if (smbios_table)
kvm-all.c +5 -0
@@ -1121,6 +1121,11 @@ int kvm_has_many_ioeventfds(void)return kvm_state->many_ioeventfds; } +int kvm_allows_irq0_override (void ) +{ +return !kvm_enabled () || !kvm_irqchip_in_kernel () ||kvm_has_gsi_routing (); +} +void kvm_setup_guest_memory (void *start,size_t size) {if (!kvm_has_sync_mmu ()) {
kvm-stub.c +5 -0
@@ -93,6 +93,11 @@ int kvm_has_many_ioeventfds(void)return 0 ; } +int kvm_allows_irq0_override (void ) +{ +return 1 ; +} +void kvm_setup_guest_memory (void *start,size_t size) { }
kvm.h +1 -0
@@ -220,6 +220,7 @@ typedef struct KVMMsiMessage { } KVMMsiMessage;int kvm_has_gsi_routing (void ); +int kvm_allows_irq0_override (void );int kvm_get_irq_route_gsi (void );int kvm_msi_message_add (KVMMsiMessage *msg);
qemu-kvm.c +0 -1
@@ -1426,7 +1426,6 @@ static int kvm_create_context(void)kvm_init_ap ();if (kvm_irqchip) {if (!qemu_kvm_has_gsi_routing ()) { - irq0override =0 ;#ifdef TARGET_I386 /* if kernel can't do irq routing, interrupt source * override 0->2 can not be set up as required by hpet,
sysemu.h +0 -1
@@ -102,7 +102,6 @@ extern int vga_interface_type;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 +0 -1
@@ -217,7 +217,6 @@ int no_reboot = 0;int no_shutdown =0 ;int cursor_hide =1 ;int graphic_rotate =0 ; -uint8_t irq0override =1 ;const char *watchdog;QEMUOptionRom option_rom[MAX_OPTION_ROMS ];int nb_option_roms;
Signature · 1 line
1.7.1
PATCH 6/16 qemu-kvm: Refactor irqchip and routing initialization
In reply to Jan KiszkaPush all irq routing setup into kvm_init_irq_routing and move arch dependent bits into kvm_arch_init_irq_routing. This will also help to merge qemu-kvm's init into upstream kvm_init.
--- qemu-kvm-x86.c | 13 ++++++- qemu-kvm.c | 115 ++++++++++++++++++++++++++++---------------------------- qemu-kvm.h | 4 +- 3 files changed, 70 insertions(+), 62 deletions(-)
qemu-kvm-x86.c +12 -1
@@ -299,7 +299,7 @@ int kvm_arch_init_irq_routing(void) {int i, r; -if (kvm_irqchip &&kvm_has_gsi_routing ()) { +if (kvm_has_gsi_routing ()) {kvm_clear_gsi_routes ();for (i =0 ; i <8 ; ++i) {if (i ==2 ) {
@@ -327,7 +327,18 @@ int kvm_arch_init_irq_routing(void) } }kvm_commit_irq_routes (); + +if (!qemu_kvm_has_pit_state2 ()) { + no_hpet =1 ; + } + }else { +/* If kernel can't do irq routing, interrupt source +* override 0->2 can not be set up as required by HPET. +* so we have to disable it. +*/ + no_hpet =1 ; } +return 0 ; }
qemu-kvm.c +57 -58
170 lines not on this page · raw message
qemu-kvm.h +1 -3
@@ -74,7 +74,7 @@ int pre_kvm_run(kvm_context_t kvm, CPUState *env);int handle_io_window (kvm_context_t kvm);int try_push_interrupts (kvm_context_t kvm); -void kvm_create_irqchip (kvm_context_t kvm); +int kvm_create_irqchip (kvm_context_t kvm);/*! * \brief Start the VCPU
@@ -449,13 +449,11 @@ int kvm_arch_halt(CPUState *env);int handle_tpr_access (void *opaque,CPUState *env,uint64_t rip,int is_write); -#define qemu_kvm_has_gsi_routing () kvm_has_gsi_routing()#ifdef TARGET_I386 #define qemu_kvm_has_pit_state2 () kvm_has_pit_state2(kvm_context)#endif #else #define kvm_nested 0 -#define qemu_kvm_has_gsi_routing () (0)#ifdef TARGET_I386 #define qemu_kvm_has_pit_state2 () (0)#endif
Signature · 1 line
1.7.1
PATCH 7/16 qemu-kvm: Fold kvm_get_gsi_count into kvm_create_irqchip
In reply to Jan Kiszka--- qemu-kvm.c | 11 +---------- qemu-kvm.h | 11 ----------- 2 files changed, 1 insertions(+), 21 deletions(-)
qemu-kvm.c +1 -10
@@ -217,7 +217,7 @@ static int kvm_init_irq_routing(kvm_context_t kvm)#ifdef KVM_CAP_IRQ_ROUTING int r, gsi_count; - gsi_count =kvm_get_gsi_count (kvm); + gsi_count =kvm_check_extension (kvm_state,KVM_CAP_IRQ_ROUTING );if (gsi_count >0 ) {int gsi_bits, i;
@@ -590,15 +590,6 @@ int kvm_has_gsi_routing(void)return r; } -int kvm_get_gsi_count (kvm_context_t kvm) -{ -#ifdef KVM_CAP_IRQ_ROUTING -return kvm_check_extension (kvm_state,KVM_CAP_IRQ_ROUTING ); -#else -return -EINVAL ; -#endif -} -int kvm_clear_gsi_routes (void ) {#ifdef KVM_CAP_IRQ_ROUTING
qemu-kvm.h +0 -11
@@ -306,17 +306,6 @@ int kvm_deassign_pci_device(kvm_context_t kvm,#endif /*! -* \brief Determines the number of gsis that can be routed -* -* Returns the number of distinct gsis that can be routed by kvm. This is -* also the number of distinct routes (if a gsi has two routes, than another -* gsi cannot be used...) -* -* \param kvm Pointer to the current kvm_context -*/ -int kvm_get_gsi_count (kvm_context_t kvm); - -/*! * \brief Clears the temporary irq routing table * * Clears the temporary irq routing table. Nothing is committed to the
Signature · 1 line
1.7.1
PATCH 8/16 qemu-kvm: Make some private functions static
In reply to Jan Kiszka--- qemu-kvm.c | 12 ++++++------ qemu-kvm.h | 32 -------------------------------- 2 files changed, 6 insertions(+), 38 deletions(-)
qemu-kvm.c +6 -6
@@ -350,12 +350,12 @@ static int handle_mmio(CPUState *env)return 0 ; } -int handle_io_window (kvm_context_t kvm) +static int handle_io_window (kvm_context_t kvm) {return 1 ; } -int handle_shutdown (kvm_context_t kvm,CPUState *env) +static int handle_shutdown (kvm_context_t kvm,CPUState *env) {/* stop the current vcpu from going back to guest mode */ env->stopped =1 ;
@@ -371,14 +371,14 @@ static inline void push_nmi(kvm_context_t kvm)#endif /* KVM_CAP_USER_NMI */ } -void post_kvm_run (kvm_context_t kvm,CPUState *env) +static void post_kvm_run (kvm_context_t kvm,CPUState *env) {pthread_mutex_lock (&qemu_mutex);kvm_arch_post_run (env, env->kvm_run); cpu_single_env = env; } -int pre_kvm_run (kvm_context_t kvm,CPUState *env) +static int pre_kvm_run (kvm_context_t kvm,CPUState *env) {kvm_arch_pre_run (env, env->kvm_run);
@@ -391,7 +391,7 @@ int kvm_is_ready_for_interrupt_injection(CPUState *env)return env->kvm_run->ready_for_interrupt_injection; } -int kvm_run (CPUState *env) +static int kvm_run (CPUState *env) {int r;kvm_context_t kvm = &env->kvm_state->kvm_context;
@@ -984,7 +984,7 @@ int kvm_cpu_exec(CPUState *env)return 0 ; } -int kvm_cpu_is_stopped (CPUState *env) +static int kvm_cpu_is_stopped (CPUState *env) {return !vm_running || env->stopped; }
qemu-kvm.h +0 -32
@@ -66,40 +66,9 @@ typedef struct kvm_context *kvm_context_t;int kvm_arch_run (CPUState *env); -int handle_halt (CPUState *env); - -int handle_shutdown (kvm_context_t kvm,CPUState *env); -void post_kvm_run (kvm_context_t kvm,CPUState *env); -int pre_kvm_run (kvm_context_t kvm,CPUState *env); -int handle_io_window (kvm_context_t kvm); -int try_push_interrupts (kvm_context_t kvm); -int kvm_create_irqchip (kvm_context_t kvm);/*! -* \brief Start the VCPU -* -* This starts the VCPU and virtualization is started.\n -* \n -* This function will not return until any of these conditions are met: -* - An IO/MMIO handler does not return "0" -* - An exception that neither the guest OS, nor KVM can handle occurs -* -* \note This function will call the callbacks registered in kvm_init() -* to emulate those functions -* \note If you at any point want to interrupt the VCPU, kvm_run() will -* listen to the EINTR signal. This allows you to simulate external interrupts -* and asyncronous IO. -* -* \param kvm Pointer to the current kvm_context -* \param vcpu Which virtual CPU should be started -* \return 0 on success, but you really shouldn't expect this function to -* return except for when an error has occured, or when you have sent it -* an EINTR signal. -*/ -int kvm_run (CPUState *env); - -/*! * \brief Check if a vcpu is ready for interrupt injection * * This checks if vcpu interrupts are not masked by mov ss or sti.
@@ -487,7 +456,6 @@ struct KVMState {int kvm_tpr_enable_vapic (CPUState *env);unsigned long kvm_get_thread_id (void ); -int kvm_cpu_is_stopped (CPUState *env);#endif
Signature · 1 line
1.7.1
PATCH 9/16 qemu-kvm: Implement kvm_has_pit_state2 in upstream style
In reply to Jan Kiszka--- hw/i8254-kvm.c | 4 ++-- hw/i8254.c | 4 ++-- kvm-all.c | 11 +++++++++++ kvm-stub.c | 5 +++++ kvm.h | 1 + qemu-kvm-x86.c | 12 +----------- qemu-kvm.c | 5 +++++ qemu-kvm.h | 15 +-------------- 8 files changed, 28 insertions(+), 29 deletions(-)
hw/i8254-kvm.c +2 -2
@@ -38,7 +38,7 @@ static void kvm_pit_pre_save(void *opaque)struct PITChannelState *sc;int i; -if (qemu_kvm_has_pit_state2 ()) { +if (kvm_has_pit_state2 ()) {kvm_get_pit2 (kvm_context, &pit2); s->flags = pit2.flags; }else {
@@ -91,7 +91,7 @@ static int kvm_pit_post_load(void *opaque, int version_id) c->count_load_time = sc->count_load_time; } -if (qemu_kvm_has_pit_state2 ()) { +if (kvm_has_pit_state2 ()) {kvm_set_pit2 (kvm_context, &pit2); }else {kvm_set_pit (kvm_context, (struct kvm_pit_state *)&pit2);
hw/i8254.c +2 -2
@@ -497,7 +497,7 @@ void hpet_pit_disable(void)PITChannelState *s = &pit_state.channels[0 ];if (kvm_enabled () &&kvm_pit_in_kernel ()) { -if (qemu_kvm_has_pit_state2 ()) { +if (kvm_has_pit_state2 ()) {kvm_hpet_disable_kpit (); }else {fprintf (stderr,"%s: kvm does not support pit_state2!\n" , __FUNCTION__);
@@ -521,7 +521,7 @@ void hpet_pit_enable(void)PITChannelState *s = &pit->channels[0 ];if (kvm_enabled () &&kvm_pit_in_kernel ()) { -if (qemu_kvm_has_pit_state2 ()) { +if (kvm_has_pit_state2 ()) {kvm_hpet_enable_kpit (); }else {fprintf (stderr,"%s: kvm does not support pit_state2!\n" , __FUNCTION__);
kvm-all.c +11 -0
@@ -82,6 +82,7 @@ struct KVMStateint pit_in_kernel;int xsave, xcrs;int many_ioeventfds; +int pit_state2; };KVMState *kvm_state;
@@ -783,6 +784,11 @@ int kvm_init(void) s->xcrs =kvm_check_extension (s,KVM_CAP_XCRS );#endif + s->pit_state2 =0 ; +#ifdef KVM_CAP_PIT_STATE2 + s->pit_state2 =kvm_check_extension (s,KVM_CAP_PIT_STATE2 ); +#endif + ret =kvm_arch_init (s);if (ret <0 ) { goto err;
@@ -1113,6 +1119,11 @@ int kvm_has_xcrs(void)return kvm_state->xcrs; } +int kvm_has_pit_state2 (void ) +{ +return kvm_state->pit_state2; +} +int kvm_has_many_ioeventfds (void ) {if (!kvm_enabled ()) {
kvm-stub.c +5 -0
@@ -98,6 +98,11 @@ int kvm_allows_irq0_override(void)return 1 ; } +int kvm_has_pit_state2 (void ) +{ +return 0 ; +} +void kvm_setup_guest_memory (void *start,size_t size) { }
kvm.h +1 -0
@@ -56,6 +56,7 @@ int kvm_has_debugregs(void);int kvm_has_xsave (void );int kvm_has_xcrs (void );int kvm_has_many_ioeventfds (void ); +int kvm_has_pit_state2 (void );#ifdef NEED_CPU_H int kvm_init_vcpu (CPUState *env);
qemu-kvm-x86.c +1 -11
@@ -178,16 +178,6 @@ int kvm_set_pit2(kvm_context_t kvm, struct kvm_pit_state2 *ps2)#endif #endif -int kvm_has_pit_state2 (kvm_context_t kvm) -{ -int r =0 ; - -#ifdef KVM_CAP_PIT_STATE2 - r =kvm_check_extension (kvm_state,KVM_CAP_PIT_STATE2 ); -#endif -return r; -} -static void kvm_set_cr8 (CPUState *env,uint64_t cr8) { env->kvm_run->cr8 = cr8;
@@ -328,7 +318,7 @@ int kvm_arch_init_irq_routing(void) }kvm_commit_irq_routes (); -if (!qemu_kvm_has_pit_state2 ()) { +if (!kvm_has_pit_state2 ()) { no_hpet =1 ; } }else {
qemu-kvm.c +5 -0
@@ -1428,6 +1428,11 @@ static int kvm_create_context(void) kvm_state->many_ioeventfds =kvm_check_many_ioeventfds (); + kvm_state->pit_state2 =0 ; +#ifdef KVM_CAP_PIT_STATE2 + kvm_state->pit_state2 =kvm_check_extension (kvm_state,KVM_CAP_PIT_STATE2 ); +#endif +kvm_init_ap ();return 0 ;
qemu-kvm.h +1 -14
@@ -185,14 +185,6 @@ int kvm_reinject_control(kvm_context_t kvm, int pit_reinject);#ifdef KVM_CAP_PIT_STATE2 /*! -* \brief Check for kvm support of kvm_pit_state2 -* -* \param kvm Pointer to the current kvm_context -* \return 0 on success -*/ -int kvm_has_pit_state2 (kvm_context_t kvm); - -/*! * \brief Set in kernel PIT state2 of the virtual domain * *
@@ -407,14 +399,8 @@ int kvm_arch_halt(CPUState *env);int handle_tpr_access (void *opaque,CPUState *env,uint64_t rip,int is_write); -#ifdef TARGET_I386 -#define qemu_kvm_has_pit_state2 () kvm_has_pit_state2(kvm_context) -#endif #else #define kvm_nested 0 -#ifdef TARGET_I386 -#define qemu_kvm_has_pit_state2 () (0) -#endif #endif #ifdef CONFIG_KVM
@@ -449,6 +435,7 @@ struct KVMState {int pit_in_kernel;int xsave, xcrs;int many_ioeventfds; +int pit_state2;struct kvm_context kvm_context; };
Signature · 1 line
1.7.1
PATCH 10/16 qemu-kvm: Fold kvm_set_irq_level into kvm_set_irq
In reply to Jan Kiszka--- qemu-kvm.c | 19 ++++++------------- qemu-kvm.h | 2 -- 2 files changed, 6 insertions(+), 15 deletions(-)
qemu-kvm.c +6 -13
@@ -278,7 +278,7 @@ int kvm_create_irqchip(kvm_context_t kvm)#ifdef KVM_CAP_IRQCHIP -int kvm_set_irq_level (kvm_context_t kvm,int irq,int level,int *status) +int kvm_set_irq (int irq,int level,int *status) {struct kvm_irq_level event;int r;
@@ -288,15 +288,17 @@ int kvm_set_irq_level(kvm_context_t kvm, int irq, int level, int *status) } event.level = level; event.irq = irq; - r =kvm_vm_ioctl (kvm_state, kvm->irqchip_inject_ioctl, &event); + r =kvm_vm_ioctl (kvm_state, kvm_state->kvm_context.irqchip_inject_ioctl, + &event);if (r <0 ) { -perror ("kvm_set_irq_level" ); +perror ("kvm_set_irq" ); }if (status) {#ifdef KVM_CAP_IRQ_INJECT_STATUS *status = - (kvm->irqchip_inject_ioctl ==KVM_IRQ_LINE ) ?1 : event.status; + (kvm_state->kvm_context.irqchip_inject_ioctl ==KVM_IRQ_LINE ) ? +1 : event.status;#else *status =1 ;#endif
@@ -1438,15 +1440,6 @@ static int kvm_create_context(void)return 0 ; } -#ifdef KVM_CAP_IRQCHIP - -int kvm_set_irq (int irq,int level,int *status) -{ -return kvm_set_irq_level (kvm_context, irq, level, status); -} - -#endif -static void kvm_mutex_unlock (void ) {assert (!cpu_single_env);
qemu-kvm.h +0 -2
@@ -93,8 +93,6 @@ int kvm_is_ready_for_interrupt_injection(CPUState *env);int kvm_inject_irq (CPUState *env,unsigned irq);#endif -int kvm_set_irq_level (kvm_context_t kvm,int irq,int level,int *status); -#ifdef KVM_CAP_IRQCHIP /*! * \brief Dump in kernel IRQCHIP contents
Signature · 1 line
1.7.1
PATCH 11/16 qemu-kvm: Remove kvm_context from public interfaces
In reply to Jan KiszkaThe goal is to remove kvm_context (and also kvm_state one day). For the few cases we currently still need kvm_context, we can perfectly derive it from kvm_state.
--- hw/device-assignment.c | 21 +++++----- hw/i8254-kvm.c | 8 ++-- hw/i8259.c | 4 +- hw/ioapic.c | 4 +- hw/pcspk.c | 4 +- kvm.h | 9 +++- qemu-kvm-x86.c | 22 +++++----- qemu-kvm.c | 101 ++++++++++++++++++++++++------------------------ qemu-kvm.h | 32 +++++++-------- target-i386/kvm.c | 4 +- 10 files changed, 104 insertions(+), 105 deletions(-)
hw/device-assignment.c +11 -10
@@ -967,7 +967,7 @@ static int assign_device(AssignedDevice *dev) "requests!\n"); } - r =kvm_assign_pci_device (kvm_context, &assigned_dev_data); + r =kvm_assign_pci_device (kvm_state, &assigned_dev_data);if (r <0 ) {fprintf (stderr,"Failed to assign device \"%s\" : %s\n" , dev->dev.qdev.id,strerror (-r));
@@ -1010,7 +1010,7 @@ static int assign_irq(AssignedDevice *dev)#ifdef KVM_CAP_ASSIGN_DEV_IRQ if (dev->irq_requested_type) { assigned_irq_data.flags = dev->irq_requested_type; - r =kvm_deassign_irq (kvm_context, &assigned_irq_data); + r =kvm_deassign_irq (kvm_state, &assigned_irq_data);/* -ENXIO means no assigned irq */ if (r && r != -ENXIO )perror ("assign_irq: deassign" );
@@ -1024,7 +1024,7 @@ static int assign_irq(AssignedDevice *dev) assigned_irq_data.flags |=KVM_DEV_IRQ_HOST_INTX ;#endif - r =kvm_assign_irq (kvm_context, &assigned_irq_data); + r =kvm_assign_irq (kvm_state, &assigned_irq_data);if (r <0 ) {fprintf (stderr,"Failed to assign irq for \"%s\": %s\n" , dev->dev.qdev.id,strerror (-r));
@@ -1048,7 +1048,7 @@ static void deassign_device(AssignedDevice *dev) assigned_dev_data.assigned_dev_id =calc_assigned_dev_id (dev->h_segnr, dev->h_busnr, dev->h_devfn); - r =kvm_deassign_pci_device (kvm_context, &assigned_dev_data); + r =kvm_deassign_pci_device (kvm_state, &assigned_dev_data);if (r <0 )fprintf (stderr,"Failed to deassign device \"%s\" : %s\n" , dev->dev.qdev.id,strerror (-r));
@@ -1113,7 +1113,7 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev, unsigned int ctrl_pos) assigned_irq_data.flags = assigned_dev->irq_requested_type;free_dev_irq_entries (assigned_dev); - r =kvm_deassign_irq (kvm_context, &assigned_irq_data); + r =kvm_deassign_irq (kvm_state, &assigned_irq_data);/* -ENXIO means no assigned irq */ if (r && r != -ENXIO )perror ("assigned_dev_update_msi: deassign irq" );
@@ -1147,8 +1147,9 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev, unsigned int ctrl_pos) assigned_irq_data.guest_irq = assigned_dev->entry->gsi; assigned_irq_data.flags =KVM_DEV_IRQ_HOST_MSI |KVM_DEV_IRQ_GUEST_MSI ; -if (kvm_assign_irq (kvm_context, &assigned_irq_data) <0 ) +if (kvm_assign_irq (kvm_state, &assigned_irq_data) <0 ) {perror ("assigned_dev_enable_msi: assign irq" ); + } assigned_dev->girq =-1 ; assigned_dev->irq_requested_type = assigned_irq_data.flags;
@@ -1192,7 +1193,7 @@ static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev) msix_nr.assigned_dev_id =calc_assigned_dev_id (adev->h_segnr, adev->h_busnr, (uint8_t )adev->h_devfn); msix_nr.entry_nr = entries_nr; - r =kvm_assign_set_msix_nr (kvm_context, &msix_nr); + r =kvm_assign_set_msix_nr (kvm_state, &msix_nr);if (r !=0 ) {fprintf (stderr,"fail to set MSI-X entry number for MSIX! %s\n" ,strerror (-r));
@@ -1231,7 +1232,7 @@ static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev) msix_entry.gsi = adev->entry[entries_nr].gsi; msix_entry.entry = i; - r =kvm_assign_set_msix_entry (kvm_context, &msix_entry); + r =kvm_assign_set_msix_entry (kvm_state, &msix_entry);if (r) {fprintf (stderr,"fail to set MSI-X entry! %s\n" ,strerror (-r));break ;
@@ -1269,7 +1270,7 @@ static void assigned_dev_update_msix(PCIDevice *pci_dev, unsigned int ctrl_pos) assigned_irq_data.flags = assigned_dev->irq_requested_type;free_dev_irq_entries (assigned_dev); - r =kvm_deassign_irq (kvm_context, &assigned_irq_data); + r =kvm_deassign_irq (kvm_state, &assigned_irq_data);/* -ENXIO means no assigned irq */ if (r && r != -ENXIO )perror ("assigned_dev_update_msix: deassign irq" );
@@ -1285,7 +1286,7 @@ static void assigned_dev_update_msix(PCIDevice *pci_dev, unsigned int ctrl_pos)perror ("assigned_dev_update_msix_mmio" );return ; } -if (kvm_assign_irq (kvm_context, &assigned_irq_data) <0 ) { +if (kvm_assign_irq (kvm_state, &assigned_irq_data) <0 ) {perror ("assigned_dev_enable_msix: assign irq" );return ; }
hw/i8254-kvm.c +4 -4
@@ -39,11 +39,11 @@ static void kvm_pit_pre_save(void *opaque)int i;if (kvm_has_pit_state2 ()) { -kvm_get_pit2 (kvm_context, &pit2); +kvm_get_pit2 (kvm_state, &pit2); s->flags = pit2.flags; }else {/* pit2 is superset of pit struct so just cast it and use it */ -kvm_get_pit (kvm_context, (struct kvm_pit_state *)&pit2); +kvm_get_pit (kvm_state, (struct kvm_pit_state *)&pit2); }for (i =0 ; i <3 ; i++) { c = &pit2.channels[i];
@@ -92,9 +92,9 @@ static int kvm_pit_post_load(void *opaque, int version_id) }if (kvm_has_pit_state2 ()) { -kvm_set_pit2 (kvm_context, &pit2); +kvm_set_pit2 (kvm_state, &pit2); }else { -kvm_set_pit (kvm_context, (struct kvm_pit_state *)&pit2); +kvm_set_pit (kvm_state, (struct kvm_pit_state *)&pit2); }return 0 ; }
hw/i8259.c +2 -2
@@ -590,7 +590,7 @@ static void kvm_kernel_pic_save_to_user(PicState *s) chip.chip_id = (&s->pics_state->pics[0 ] == s) ?KVM_IRQCHIP_PIC_MASTER :KVM_IRQCHIP_PIC_SLAVE ; -kvm_get_irqchip (kvm_context, &chip); +kvm_get_irqchip (kvm_state, &chip); kpic = &chip.chip.pic; s->last_irr = kpic->last_irr;
@@ -640,7 +640,7 @@ static int kvm_kernel_pic_load_from_user(PicState *s) kpic->elcr = s->elcr; kpic->elcr_mask = s->elcr_mask; -kvm_set_irqchip (kvm_context, &chip); +kvm_set_irqchip (kvm_state, &chip);#endif return 0 ; }
hw/ioapic.c +2 -2
@@ -278,7 +278,7 @@ static void kvm_kernel_ioapic_save_to_user(IOAPICState *s)int i; chip.chip_id =KVM_IRQCHIP_IOAPIC ; -kvm_get_irqchip (kvm_context, &chip); +kvm_get_irqchip (kvm_state, &chip); kioapic = &chip.chip.ioapic; s->id = kioapic->id;
@@ -308,7 +308,7 @@ static void kvm_kernel_ioapic_load_from_user(IOAPICState *s) kioapic->redirtbl[i].bits = s->ioredtbl[i]; } -kvm_set_irqchip (kvm_context, &chip); +kvm_set_irqchip (kvm_state, &chip);#endif }
hw/pcspk.c +2 -2
@@ -58,7 +58,7 @@ static void kvm_get_pit_ch2(ISADevice *dev,struct kvm_pit_state pit_state;if (kvm_enabled () &&kvm_pit_in_kernel ()) { -kvm_get_pit (kvm_context, &pit_state); +kvm_get_pit (kvm_state, &pit_state); pit->channels[2 ].mode = pit_state.channels[2 ].mode; pit->channels[2 ].count = pit_state.channels[2 ].count; pit->channels[2 ].count_load_time = pit_state.channels[2 ].count_load_time;
@@ -80,7 +80,7 @@ static void kvm_set_pit_ch2(ISADevice *dev, inkernel_state->channels[2 ].count_load_time = pit->channels[2 ].count_load_time; inkernel_state->channels[2 ].gate = pit->channels[2 ].gate; - kvm_set_pit(kvm_context, inkernel_state); + kvm_set_pit(kvm_state, inkernel_state); } }#else
kvm.h +6 -3
@@ -17,9 +17,6 @@#include <errno.h> #include "config-host.h" #include "qemu-queue.h" -#ifdef NEED_CPU_H -#include "qemu-kvm.h" -#endif #ifdef CONFIG_KVM #include <linux/kvm.h>
@@ -85,6 +82,7 @@ int kvm_pit_in_kernel(void);int kvm_on_sigbus_vcpu (CPUState *env,int code,void *addr);int kvm_on_sigbus (int code,void *addr); +#endif /* NEED_CPU_H */ /* internal API */
@@ -96,6 +94,7 @@ int kvm_ioctl(KVMState *s, int type, ...);int kvm_vm_ioctl (KVMState *s,int type, ...); +#ifdef NEED_CPU_H int kvm_vcpu_ioctl (CPUState *env,int type, ...);/* Arch specific hooks */
@@ -234,4 +233,8 @@ int kvm_irqchip_in_kernel(void);int kvm_set_irq (int irq,int level,int *status); +#ifdef NEED_CPU_H +#include "qemu-kvm.h" +#endif +#endif
qemu-kvm-x86.c +11 -11
@@ -23,19 +23,19 @@#include "kvm.h" #include "hw/apic.h" -static int kvm_create_pit (kvm_context_t kvm) +static int kvm_create_pit (KVMState *s) {#ifdef KVM_CAP_PIT int r;if (kvm_pit_in_kernel ()) { - r =kvm_vm_ioctl (kvm_state,KVM_CREATE_PIT ); + r =kvm_vm_ioctl (s,KVM_CREATE_PIT );if (r <0 ) {fprintf (stderr,"Create kernel PIC irqchip failed\n" );return r; }if (!kvm_pit_reinject) { - r =kvm_reinject_control (kvm_context,0 ); + r =kvm_reinject_control (s,0 );if (r <0 ) {fprintf (stderr,"failure to disable in-kernel PIT reinjection\n" );
@@ -142,37 +142,37 @@ int kvm_set_lapic(CPUState *env, struct kvm_lapic_state *s)#ifdef KVM_CAP_PIT -int kvm_get_pit (kvm_context_t kvm,struct kvm_pit_state *s) +int kvm_get_pit (KVMState *s,struct kvm_pit_state *pit_state) {if (!kvm_pit_in_kernel ()) {return 0 ; } -return kvm_vm_ioctl (kvm_state,KVM_GET_PIT , s); +return kvm_vm_ioctl (s,KVM_GET_PIT , pit_state); } -int kvm_set_pit (kvm_context_t kvm,struct kvm_pit_state *s) +int kvm_set_pit (KVMState *s,struct kvm_pit_state *pit_state) {if (!kvm_pit_in_kernel ()) {return 0 ; } -return kvm_vm_ioctl (kvm_state,KVM_SET_PIT , s); +return kvm_vm_ioctl (s,KVM_SET_PIT , pit_state); }#ifdef KVM_CAP_PIT_STATE2 -int kvm_get_pit2 (kvm_context_t kvm,struct kvm_pit_state2 *ps2) +int kvm_get_pit2 (KVMState *s,struct kvm_pit_state2 *ps2) {if (!kvm_pit_in_kernel ()) {return 0 ; } -return kvm_vm_ioctl (kvm_state,KVM_GET_PIT2 , ps2); +return kvm_vm_ioctl (s,KVM_GET_PIT2 , ps2); } -int kvm_set_pit2 (kvm_context_t kvm,struct kvm_pit_state2 *ps2) +int kvm_set_pit2 (KVMState *s,struct kvm_pit_state2 *ps2) {if (!kvm_pit_in_kernel ()) {return 0 ; } -return kvm_vm_ioctl (kvm_state,KVM_SET_PIT2 , ps2); +return kvm_vm_ioctl (s,KVM_SET_PIT2 , ps2); }#endif
qemu-kvm.c +50 -51
290 lines not on this page · raw message
qemu-kvm.h +14 -18
@@ -66,7 +66,7 @@ typedef struct kvm_context *kvm_context_t;int kvm_arch_run (CPUState *env); -int kvm_create_irqchip (kvm_context_t kvm); +int kvm_create_irqchip (KVMState *s);/*! * \brief Check if a vcpu is ready for interrupt injection
@@ -103,7 +103,7 @@ int kvm_inject_irq(CPUState *env, unsigned irq);* \param kvm Pointer to the current kvm_context * \param chip The irq chip device to be dumped */ -int kvm_get_irqchip (kvm_context_t kvm,struct kvm_irqchip *chip); +int kvm_get_irqchip (KVMState *s,struct kvm_irqchip *chip);/*! * \brief Set in kernel IRQCHIP contents
@@ -115,7 +115,7 @@ int kvm_get_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip);* \param kvm Pointer to the current kvm_context * \param chip THe irq chip device to be written */ -int kvm_set_irqchip (kvm_context_t kvm,struct kvm_irqchip *chip); +int kvm_set_irqchip (KVMState *s,struct kvm_irqchip *chip);#if defined(__i386__) || defined(__x86_64__)/*!
@@ -166,7 +166,7 @@ int kvm_inject_nmi(CPUState *env);* \param kvm Pointer to the current kvm_context * \param s PIT state of the virtual domain */ -int kvm_get_pit (kvm_context_t kvm,struct kvm_pit_state *s); +int kvm_get_pit (KVMState *s,struct kvm_pit_state *pit_state);/*! * \brief Set in kernel PIT of the virtual domain
@@ -177,9 +177,9 @@ int kvm_get_pit(kvm_context_t kvm, struct kvm_pit_state *s);* \param kvm Pointer to the current kvm_context * \param s PIT state of the virtual domain */ -int kvm_set_pit (kvm_context_t kvm,struct kvm_pit_state *s); +int kvm_set_pit (KVMState *s,struct kvm_pit_state *pit_state); -int kvm_reinject_control (kvm_context_t kvm,int pit_reinject); +int kvm_reinject_control (KVMState *s,int pit_reinject);#ifdef KVM_CAP_PIT_STATE2 /*!
@@ -190,7 +190,7 @@ int kvm_reinject_control(kvm_context_t kvm, int pit_reinject);* \param ps2 PIT state2 of the virtual domain * \return 0 on success */ -int kvm_set_pit2 (kvm_context_t kvm,struct kvm_pit_state2 *ps2); +int kvm_set_pit2 (KVMState *s,struct kvm_pit_state2 *ps2);/*! * \brief Get in kernel PIT state2 of the virtual domain
@@ -200,7 +200,7 @@ int kvm_set_pit2(kvm_context_t kvm, struct kvm_pit_state2 *ps2);* \param ps2 PIT state2 of the virtual domain * \return 0 on success */ -int kvm_get_pit2 (kvm_context_t kvm,struct kvm_pit_state2 *ps2); +int kvm_get_pit2 (KVMState *s,struct kvm_pit_state2 *ps2);#endif #endif
@@ -222,7 +222,7 @@ int kvm_enable_vapic(CPUState *env, uint64_t vapic);* \param kvm Pointer to the current kvm_context * \param assigned_dev Parameters, like bus, devfn number, etc */ -int kvm_assign_pci_device (kvm_context_t kvm, +int kvm_assign_pci_device (KVMState *s,struct kvm_assigned_pci_dev *assigned_dev);/*!
@@ -234,7 +234,7 @@ int kvm_assign_pci_device(kvm_context_t kvm,* \param kvm Pointer to the current kvm_context * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc */ -int kvm_assign_irq (kvm_context_t kvm,struct kvm_assigned_irq *assigned_irq); +int kvm_assign_irq (KVMState *s,struct kvm_assigned_irq *assigned_irq);#ifdef KVM_CAP_ASSIGN_DEV_IRQ /*!
@@ -246,7 +246,7 @@ int kvm_assign_irq(kvm_context_t kvm, struct kvm_assigned_irq *assigned_irq);* \param kvm Pointer to the current kvm_context * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc */ -int kvm_deassign_irq (kvm_context_t kvm,struct kvm_assigned_irq *assigned_irq); +int kvm_deassign_irq (KVMState *s,struct kvm_assigned_irq *assigned_irq);#endif #endif
@@ -260,7 +260,7 @@ int kvm_deassign_irq(kvm_context_t kvm, struct kvm_assigned_irq *assigned_irq);* \param kvm Pointer to the current kvm_context * \param assigned_dev Parameters, like bus, devfn number, etc */ -int kvm_deassign_pci_device (kvm_context_t kvm, +int kvm_deassign_pci_device (KVMState *s,struct kvm_assigned_pci_dev *assigned_dev);#endif
@@ -318,16 +318,13 @@ int kvm_update_routing_entry(struct kvm_irq_routing_entry *entry,#ifdef KVM_CAP_DEVICE_MSIX -int kvm_assign_set_msix_nr (kvm_context_t kvm, -struct kvm_assigned_msix_nr *msix_nr); -int kvm_assign_set_msix_entry (kvm_context_t kvm, +int kvm_assign_set_msix_nr (KVMState *s,struct kvm_assigned_msix_nr *msix_nr); +int kvm_assign_set_msix_entry (KVMState *s,struct kvm_assigned_msix_entry *entry);#endif #else /* !CONFIG_KVM */ -typedef struct kvm_context *kvm_context_t ; -struct kvm_pit_state { };
@@ -383,7 +380,6 @@ extern int kvm_irqchip;extern int kvm_pit;extern int kvm_pit_reinject;extern int kvm_nested; -extern kvm_context_t kvm_context;extern unsigned int kvm_shadow_memory;struct ioperm_data {
target-i386/kvm.c +2 -2
@@ -601,7 +601,7 @@ static int kvm_get_supported_msrs(KVMState *s)return ret; } -static int kvm_create_pit (kvm_context_t kvm); +static int kvm_create_pit (KVMState *s);int kvm_arch_init (KVMState *s) {
@@ -653,7 +653,7 @@ int kvm_arch_init(KVMState *s) }qemu_register_reset (kvm_unpoison_all,NULL ); - ret =kvm_create_pit (&s->kvm_context); + ret =kvm_create_pit (s);if (ret <0 ) {return ret; }
Signature · 1 line
1.7.1
PATCH 12/16 qemu-kvm: Fold kvm_set_boot_vcpu_id into kvm_set_boot_cpu_id
In reply to Jan Kiszka--- qemu-kvm.c | 23 ++++++++--------------- qemu-kvm.h | 2 +- target-i386/kvm.c | 2 +- 3 files changed, 10 insertions(+), 17 deletions(-)
qemu-kvm.c +8 -15
@@ -197,19 +197,6 @@ static void kvm_finalize(KVMState *s)free (s); } -static int kvm_set_boot_vcpu_id (kvm_context_t kvm,uint32_t id) -{ -#ifdef KVM_CAP_SET_BOOT_CPU_ID -int r =kvm_ioctl (kvm_state,KVM_CHECK_EXTENSION ,KVM_CAP_SET_BOOT_CPU_ID ); -if (r >0 ) { -return kvm_vm_ioctl (kvm_state,KVM_SET_BOOT_CPU_ID , id); - } -return -ENOSYS ; -#else -return -ENOSYS ; -#endif -} -static int kvm_init_irq_routing (KVMState *s) {#ifdef KVM_CAP_IRQ_ROUTING
@@ -1497,8 +1484,14 @@ void kvm_ioperm(CPUState *env, void *data)#endif -int kvm_set_boot_cpu_id (uint32_t id) +int kvm_set_boot_cpu_id (KVMState *s,uint32_t id) { -return kvm_set_boot_vcpu_id (&kvm_state->kvm_context, id); +#ifdef KVM_CAP_SET_BOOT_CPU_ID +int r =kvm_ioctl (s,KVM_CHECK_EXTENSION ,KVM_CAP_SET_BOOT_CPU_ID ); +if (r >0 ) { +return kvm_vm_ioctl (s,KVM_SET_BOOT_CPU_ID , id); + } +#endif +return -ENOSYS ; }
qemu-kvm.h +1 -1
@@ -358,7 +358,7 @@ int kvm_arch_has_work(CPUState *env);void kvm_arch_process_irqchip_events (CPUState *env);int kvm_arch_try_push_interrupts (void *opaque);void kvm_arch_push_nmi (void ); -int kvm_set_boot_cpu_id (uint32_t id); +int kvm_set_boot_cpu_id (KVMState *s,uint32_t id);void kvm_tpr_access_report (CPUState *env,uint64_t rip,int is_write);
target-i386/kvm.c +1 -1
@@ -665,7 +665,7 @@ int kvm_arch_init(KVMState *s) } } - ret =kvm_set_boot_cpu_id (0 ); + ret =kvm_set_boot_cpu_id (s,0 );if (ret <0 && ret != -ENOSYS ) {return ret; }
Signature · 1 line
1.7.1
PATCH 13/16 qemu-kvm: Remove handle_io_window
In reply to Jan KiszkaDisentangle the logic around handle_io_window in kvm_run.
--- qemu-kvm.c | 9 +-------- 1 files changed, 1 insertions(+), 8 deletions(-)
qemu-kvm.c +1 -8
@@ -339,11 +339,6 @@ static int handle_mmio(CPUState *env)return 0 ; } -static int handle_io_window (kvm_context_t kvm) -{ -return 1 ; -} -static int handle_shutdown (kvm_context_t kvm,CPUState *env) {/* stop the current vcpu from going back to guest mode */
@@ -422,8 +417,7 @@ static int kvm_run(CPUState *env)#if !defined(__s390__)if (r ==-1 ) { - r =handle_io_window (kvm); - goto more; +return 1 ; }#endif if (1 ) {
@@ -483,7 +477,6 @@ static int kvm_run(CPUState *env)break ; } } -more:if (!r) { goto again; }
Signature · 1 line
1.7.1
PATCH 14/16 qemu-kvm: Merge kvm_context into KVMState
In reply to Jan KiszkaAppend the few additional fields needed for qemu-kvm to upstream's KVMState and drop all related duplications.
--- kvm-all.c | 11 ++++- qemu-kvm.c | 121 ++++++++++++++++++++++++++++------------------------------- qemu-kvm.h | 58 ----------------------------- 3 files changed, 66 insertions(+), 124 deletions(-)
kvm-all.c +9 -2
@@ -50,8 +50,6 @@ do { } while (0)#endif -#ifdef OBSOLETE_KVM_IMPL - typedef struct KVMSlot { target_phys_addr_t start_addr;
@@ -83,10 +81,19 @@ struct KVMStateint xsave, xcrs;int many_ioeventfds;int pit_state2; + +int irqchip_inject_ioctl; +#ifdef KVM_CAP_IRQ_ROUTING +struct kvm_irq_routing *irq_routes; +int nr_allocated_irq_routes; +#endif +void *used_gsi_bitmap; +int max_gsi; };KVMState *kvm_state; +#ifdef OBSOLETE_KVM_IMPL static const KVMCapabilityInfo kvm_required_capabilites[] = { KVM_CAP_INFO(USER_MEMORY),
qemu-kvm.c +57 -64
336 lines not on this page · raw message
qemu-kvm.h +0 -58
72 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 15/16 qemu-kvm: Use KVM-optimized interrupt handler
In reply to Jan KiszkaInstead of hooking into tcg_handler_interrupt, set cpu_interrupt_handler just like upstream and move kvm_update_interrupt_request to kvm_handle_interrupt. It's not worth keeping the check for !irqchip, we will only rarely get here in the in-kernel irqchip case.
--- exec.c | 2 -- kvm-all.c | 3 ++- qemu-kvm.c | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-)
exec.c +0 -2
@@ -1646,8 +1646,6 @@ static void tcg_handle_interrupt(CPUState *env, int mask) old_mask = env->interrupt_request; env->interrupt_request |= mask; -if (kvm_enabled () && !kvm_irqchip_in_kernel ()) -kvm_update_interrupt_request (env);/* * If called from iothread context, wake the target cpu in
kvm-all.c +2 -1
@@ -683,7 +683,6 @@ static CPUPhysMemoryClient kvm_cpu_phys_memory_client = { .log_stop = kvm_log_stop, }; -#ifdef OBSOLETE_KVM_IMPL static void kvm_handle_interrupt (CPUState *env,int mask) { env->interrupt_request |= mask;
@@ -691,8 +690,10 @@ static void kvm_handle_interrupt(CPUState *env, int mask)if (!qemu_cpu_is_self (env)) {qemu_cpu_kick (env); } +kvm_update_interrupt_request (env); } +#ifdef OBSOLETE_KVM_IMPL int kvm_init (void ) { static const char upgrade_note[] =
qemu-kvm.c +2 -0
@@ -1409,6 +1409,8 @@ static int kvm_create_context(void)kvm_init_ap (); + cpu_interrupt_handler = kvm_handle_interrupt; +return 0 ; }
Signature · 1 line
1.7.1
PATCH 16/16 qemu-kvm: Use upstream kvm_init
In reply to Jan KiszkaFold remaining qemu-kvm specific initialization bits into upsteam kvm_init and use that service.
--- kvm-all.c | 17 +++--- kvm.h | 4 -- qemu-kvm-x86.c | 2 +- qemu-kvm.c | 156 +---------------------------------------------------- qemu-kvm.h | 13 ----- target-i386/kvm.c | 2 - 6 files changed, 12 insertions(+), 182 deletions(-)
kvm-all.c +9 -8
@@ -93,16 +93,12 @@ struct KVMStateKVMState *kvm_state; -#ifdef OBSOLETE_KVM_IMPL -static const KVMCapabilityInfo kvm_required_capabilites[] = {KVM_CAP_INFO (USER_MEMORY ),KVM_CAP_INFO (DESTROY_MEMORY_REGION_WORKS ),KVM_CAP_LAST_INFO }; -#endif -static KVMSlot *kvm_alloc_slot (KVMState *s) {int i;
@@ -512,7 +508,6 @@ static int kvm_check_many_ioeventfds(void)#endif } -#ifdef OBSOLETE_KVM_IMPL static const KVMCapabilityInfo *kvm_check_extension_list (KVMState *s,const KVMCapabilityInfo *list) {
@@ -524,7 +519,6 @@ kvm_check_extension_list(KVMState *s, const KVMCapabilityInfo *list) }return NULL ; } -#endif static void kvm_set_phys_mem (target_phys_addr_t start_addr,ram_addr_t size,ram_addr_t phys_offset)
@@ -693,7 +687,6 @@ static void kvm_handle_interrupt(CPUState *env, int mask)kvm_update_interrupt_request (env); } -#ifdef OBSOLETE_KVM_IMPL int kvm_init (void ) { static const char upgrade_note[] =
@@ -797,6 +790,8 @@ int kvm_init(void) s->pit_state2 =kvm_check_extension (s,KVM_CAP_PIT_STATE2 );#endif + s->pit_in_kernel = kvm_pit; + ret =kvm_arch_init (s);if (ret <0 ) { goto err;
@@ -807,6 +802,13 @@ int kvm_init(void) s->many_ioeventfds =kvm_check_many_ioeventfds (); + ret =kvm_create_irqchip (s); +if (ret <0 ) { +return ret; + } + +kvm_init_ap (); + cpu_interrupt_handler = kvm_handle_interrupt;return 0 ;
@@ -824,7 +826,6 @@ err:return ret; } -#endif static void kvm_handle_io (uint16_t port,void *data,int direction,int size,uint32_t count)
kvm.h +0 -4
@@ -30,7 +30,6 @@ extern int kvm_allowed;#define kvm_enabled () (0)#endif -#ifdef OBSOLETE_KVM_IMPLstruct kvm_run ; typedef struct KVMCapabilityInfo {
@@ -44,7 +43,6 @@ typedef struct KVMCapabilityInfo {/* external API */ int kvm_init (void ); -#endif /* OBSOLETE_KVM_IMPL */ int kvm_has_sync_mmu (void );int kvm_has_vcpu_events (void );
@@ -99,9 +97,7 @@ int kvm_vcpu_ioctl(CPUState *env, int type, ...);/* Arch specific hooks */ -#ifdef OBSOLETE_KVM_IMPL extern const KVMCapabilityInfo kvm_arch_required_capabilities[]; -#endif void kvm_arch_pre_run (CPUState *env,struct kvm_run *run);void kvm_arch_post_run (CPUState *env,struct kvm_run *run);
qemu-kvm-x86.c +1 -1
@@ -28,7 +28,7 @@ static int kvm_create_pit(KVMState *s)#ifdef KVM_CAP_PIT int r; -if (kvm_pit_in_kernel ()) { +if (kvm_pit) { r =kvm_vm_ioctl (s,KVM_CREATE_PIT );if (r <0 ) {fprintf (stderr,"Create kernel PIC irqchip failed\n" );
qemu-kvm.c +2 -154
174 lines not on this page · raw message
qemu-kvm.h +0 -13
@@ -311,19 +311,6 @@ struct kvm_pit_state {#endif /* !CONFIG_KVM */ - -/*! -* \brief Create new KVM context -* -* This creates a new kvm_context. A KVM context is a small area of data that -* holds information about the KVM instance that gets created by this call.\n -* This should always be your first call to KVM. -* -* \param opaque Not used -* \return NULL on failure -*/ -int kvm_init (void ); -int kvm_main_loop (void );int kvm_init_ap (void );void kvm_save_lapic (CPUState *env);
target-i386/kvm.c +0 -2
@@ -53,14 +53,12 @@#define BUS_MCEERR_AO 5#endif -#ifdef OBSOLETE_KVM_IMPL const KVMCapabilityInfo kvm_arch_required_capabilities[] = {KVM_CAP_INFO (SET_TSS_ADDR ),KVM_CAP_INFO (EXT_CPUID ),KVM_CAP_INFO (MP_STATE ),KVM_CAP_LAST_INFO }; -#endif static bool has_msr_star;static bool has_msr_hsave_pa;
Signature · 1 line
1.7.1
Quoted 7 lines · Jan Kiszka
The second round of merging qemu-kvm with upstream. This part stops after switching to upstreams
kvm_initimplementation.To achieve this, various small cleanups and refactorings are applied, the irq0 override management is simplified and the
kvm_contextfields are migrated into KVMState.
Looks good.
Signature · 1 line
error compiling committee.c: too many arguments to function
Marcelo Tosatti
AppliedQuoted 8 lines · Jan Kiszka
The second round of merging qemu-kvm with upstream. This part stops after switching to upstreams
kvm_initimplementation.To achieve this, various small cleanups and refactorings are applied, the irq0 override management is simplified and the
kvm_contextfields are migrated into KVMState.Please review/merge.
Applied, thanks.