From patchwork Fri Oct 9 18:03:09 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 52773 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n99I6uNr012234 for ; Fri, 9 Oct 2009 18:06:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761160AbZJISDv (ORCPT ); Fri, 9 Oct 2009 14:03:51 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1761193AbZJISDu (ORCPT ); Fri, 9 Oct 2009 14:03:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51495 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759130AbZJISDt (ORCPT ); Fri, 9 Oct 2009 14:03:49 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n99I3Nka025511 for ; Fri, 9 Oct 2009 14:03:23 -0400 Received: from localhost.localdomain (vpn-12-36.rdu.redhat.com [10.11.12.36]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n99I3JJ9017374; Fri, 9 Oct 2009 14:03:22 -0400 From: Glauber Costa To: kvm@vger.kernel.org Cc: avi@redhat.com Subject: [PATCH 01/10] use a more upstream friendly version of irqchip-in-kernel test Date: Fri, 9 Oct 2009 15:03:09 -0300 Message-Id: <1255111398-15251-2-git-send-email-glommer@redhat.com> In-Reply-To: <1255111398-15251-1-git-send-email-glommer@redhat.com> References: <1255111398-15251-1-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/exec.c b/exec.c index 24956cf..fcffb0f 100644 --- a/exec.c +++ b/exec.c @@ -1570,7 +1570,7 @@ void cpu_interrupt(CPUState *env, int mask) old_mask = env->interrupt_request; env->interrupt_request |= mask; - if (kvm_enabled() && !qemu_kvm_irqchip_in_kernel()) + if (kvm_enabled() && !kvm_irqchip_in_kernel()) kvm_update_interrupt_request(env); #ifndef CONFIG_USER_ONLY diff --git a/hw/apic.c b/hw/apic.c index 2952675..b8fe529 100644 --- a/hw/apic.c +++ b/hw/apic.c @@ -301,7 +301,7 @@ void cpu_set_apic_base(CPUState *env, uint64_t val) #endif if (!s) return; - if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) + if (kvm_enabled() && kvm_irqchip_in_kernel()) s->apicbase = val; else s->apicbase = (val & 0xfffff000) | @@ -509,7 +509,7 @@ void apic_init_reset(CPUState *env) env->halted = !(s->apicbase & MSR_IA32_APICBASE_BSP); #ifdef KVM_CAP_MP_STATE - if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) { + if (kvm_enabled() && kvm_irqchip_in_kernel()) { env->mp_state = env->halted ? KVM_MP_STATE_UNINITIALIZED : KVM_MP_STATE_RUNNABLE; } @@ -961,7 +961,7 @@ static void kvm_kernel_lapic_load_from_user(APICState *s) void qemu_kvm_load_lapic(CPUState *env) { #ifdef KVM_CAP_IRQCHIP - if (kvm_enabled() && kvm_vcpu_inited(env) && qemu_kvm_irqchip_in_kernel()) { + if (kvm_enabled() && kvm_vcpu_inited(env) && kvm_irqchip_in_kernel()) { kvm_kernel_lapic_load_from_user(env->apic_state); } #endif @@ -972,7 +972,7 @@ static void apic_pre_save(void *opaque) #ifdef KVM_CAP_IRQCHIP APICState *s = (void *)opaque; - if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) { + if (kvm_enabled() && kvm_irqchip_in_kernel()) { kvm_kernel_lapic_save_to_user(s); } #endif @@ -983,7 +983,7 @@ static int apic_post_load(void *opaque, int version_id) #ifdef KVM_CAP_IRQCHIP APICState *s = opaque; - if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) { + if (kvm_enabled() && kvm_irqchip_in_kernel()) { kvm_kernel_lapic_load_from_user(s); } #endif diff --git a/hw/ioapic.c b/hw/ioapic.c index cd62395..a66325d 100644 --- a/hw/ioapic.c +++ b/hw/ioapic.c @@ -244,7 +244,7 @@ static void ioapic_pre_save(void *opaque) { IOAPICState *s = (void *)opaque; - if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) { + if (kvm_enabled() && kvm_irqchip_in_kernel()) { kvm_kernel_ioapic_save_to_user(s); } } @@ -263,7 +263,7 @@ static int ioapic_post_load(void *opaque, int version_id) { IOAPICState *s = opaque; - if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) { + if (kvm_enabled() && kvm_irqchip_in_kernel()) { kvm_kernel_ioapic_load_from_user(s); } return 0; @@ -297,7 +297,7 @@ static void ioapic_reset(void *opaque) for(i = 0; i < IOAPIC_NUM_PINS; i++) s->ioredtbl[i] = 1 << 16; /* mask LVT */ #ifdef KVM_CAP_IRQCHIP - if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) { + if (kvm_enabled() && kvm_irqchip_in_kernel()) { kvm_kernel_ioapic_load_from_user(s); } #endif diff --git a/hw/msix.c b/hw/msix.c index b68fb5f..c1e5eb8 100644 --- a/hw/msix.c +++ b/hw/msix.c @@ -221,7 +221,7 @@ static int msix_add_config(struct PCIDevice *pdev, unsigned short nentries, static void msix_free_irq_entries(PCIDevice *dev) { int vector; - if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) { + if (kvm_enabled() && kvm_irqchip_in_kernel()) { kvm_msix_free(dev); } @@ -298,7 +298,7 @@ static void msix_mmio_writel(void *opaque, target_phys_addr_t addr, int vector = offset / MSIX_ENTRY_SIZE; int was_masked = msix_is_masked(dev, vector); memcpy(dev->msix_table_page + offset, &val, 4); - if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) { + if (kvm_enabled() && kvm_irqchip_in_kernel()) { kvm_msix_update(dev, vector, was_masked, msix_is_masked(dev, vector)); } if (!msix_is_masked(dev, vector) && msix_is_pending(dev, vector)) { @@ -354,7 +354,7 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries, return -EINVAL; #ifdef KVM_CAP_IRQCHIP - if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) { + if (kvm_enabled() && kvm_irqchip_in_kernel()) { dev->msix_irq_entries = qemu_malloc(nentries * sizeof *dev->msix_irq_entries); } @@ -478,7 +478,7 @@ void msix_notify(PCIDevice *dev, unsigned vector) } #ifdef KVM_CAP_IRQCHIP - if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) { + if (kvm_enabled() && kvm_irqchip_in_kernel()) { kvm_set_irq(dev->msix_irq_entries[vector].gsi, 1, NULL); return; } @@ -516,7 +516,7 @@ int msix_vector_use(PCIDevice *dev, unsigned vector) if (dev->msix_entry_used[vector]) { return 0; } - if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) { + if (kvm_enabled() && kvm_irqchip_in_kernel()) { ret = kvm_msix_add(dev, vector); if (ret) { return ret; @@ -531,7 +531,7 @@ void msix_vector_unuse(PCIDevice *dev, unsigned vector) { if (vector < dev->msix_entries_nr && dev->msix_entry_used[vector]) { --dev->msix_entry_used[vector]; - if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) { + if (kvm_enabled() && kvm_irqchip_in_kernel()) { kvm_msix_del(dev, vector); } } diff --git a/hw/pc.c b/hw/pc.c index f504f0b..9f53c97 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -1288,7 +1288,7 @@ static void pc_init1(ram_addr_t ram_size, cpu_irq = qemu_allocate_irqs(pic_irq_request, NULL, 1); #ifdef KVM_CAP_IRQCHIP - if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) { + if (kvm_enabled() && kvm_irqchip_in_kernel()) { isa_irq_state = qemu_mallocz(sizeof(*isa_irq_state)); isa_irq = i8259 = kvm_i8259_init(cpu_irq[0]); } else diff --git a/hw/pci.c b/hw/pci.c index 4472910..5f6bae0 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -679,7 +679,7 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l) } #ifdef CONFIG_KVM_DEVICE_ASSIGNMENT - if (kvm_enabled() && qemu_kvm_irqchip_in_kernel() && + if (kvm_enabled() && kvm_irqchip_in_kernel() && addr >= PIIX_CONFIG_IRQ_ROUTE && addr < PIIX_CONFIG_IRQ_ROUTE + 4) assigned_dev_update_irqs(); diff --git a/kvm-all.c b/kvm-all.c index b2651df..1356aa8 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -155,12 +155,14 @@ static void kvm_reset_vcpu(void *opaque) abort(); } } +#endif int kvm_irqchip_in_kernel(void) { return kvm_state->irqchip_in_kernel; } +#ifdef KVM_UPSTREAM int kvm_pit_in_kernel(void) { return kvm_state->pit_in_kernel; diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index acb1b91..a44ae67 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -284,7 +284,7 @@ int kvm_destroy_memory_alias(kvm_context_t kvm, uint64_t phys_start) int kvm_get_lapic(kvm_vcpu_context_t vcpu, struct kvm_lapic_state *s) { int r; - if (!kvm_irqchip_in_kernel(vcpu->kvm)) + if (!kvm_irqchip_in_kernel()) return 0; r = ioctl(vcpu->fd, KVM_GET_LAPIC, s); if (r == -1) { @@ -297,7 +297,7 @@ int kvm_get_lapic(kvm_vcpu_context_t vcpu, struct kvm_lapic_state *s) int kvm_set_lapic(kvm_vcpu_context_t vcpu, struct kvm_lapic_state *s) { int r; - if (!kvm_irqchip_in_kernel(vcpu->kvm)) + if (!kvm_irqchip_in_kernel()) return 0; r = ioctl(vcpu->fd, KVM_SET_LAPIC, s); if (r == -1) { @@ -1376,7 +1376,7 @@ int kvm_arch_halt(void *opaque, kvm_vcpu_context_t vcpu) void kvm_arch_pre_kvm_run(void *opaque, CPUState *env) { - if (!kvm_irqchip_in_kernel(kvm_context)) + if (!kvm_irqchip_in_kernel()) kvm_set_cr8(env->kvm_cpu_state.vcpu_ctx, cpu_get_apic_tpr(env)); } @@ -1440,7 +1440,7 @@ void kvm_arch_cpu_reset(CPUState *env) { kvm_arch_load_regs(env); if (!cpu_is_bsp(env)) { - if (kvm_irqchip_in_kernel(kvm_context)) { + if (kvm_irqchip_in_kernel()) { #ifdef KVM_CAP_MP_STATE kvm_reset_mpstate(env->kvm_cpu_state.vcpu_ctx); #endif diff --git a/qemu-kvm.c b/qemu-kvm.c index a4a90ed..6bda694 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -558,6 +558,7 @@ void kvm_create_irqchip(kvm_context_t kvm) } } #endif + kvm_state->irqchip_in_kernel = kvm->irqchip_in_kernel; } int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **vm_mem) @@ -1109,11 +1110,6 @@ int kvm_set_signal_mask(kvm_vcpu_context_t vcpu, const sigset_t *sigset) return r; } -int kvm_irqchip_in_kernel(kvm_context_t kvm) -{ - return kvm->irqchip_in_kernel; -} - int kvm_pit_in_kernel(kvm_context_t kvm) { return kvm->pit_in_kernel; @@ -1610,7 +1606,7 @@ void kvm_arch_get_registers(CPUState *env) kvm_arch_save_regs(env); kvm_arch_save_mpstate(env); #ifdef KVM_CAP_MP_STATE - if (kvm_irqchip_in_kernel(kvm_context)) + if (kvm_irqchip_in_kernel()) env->halted = (env->mp_state == KVM_MP_STATE_HALTED); #endif } @@ -1967,7 +1963,7 @@ static int kvm_main_loop_cpu(CPUState *env) while (1) { int run_cpu = !is_cpu_stopped(env); - if (run_cpu && !kvm_irqchip_in_kernel(kvm_context)) { + if (run_cpu && !kvm_irqchip_in_kernel()) { process_irqchip_events(env); run_cpu = !env->halted; } diff --git a/qemu-kvm.h b/qemu-kvm.h index 05b025f..e957e96 100644 --- a/qemu-kvm.h +++ b/qemu-kvm.h @@ -553,13 +553,6 @@ int kvm_dirty_pages_log_enable_all(kvm_context_t kvm); */ int kvm_dirty_pages_log_reset(kvm_context_t kvm); -/*! - * \brief Query whether in kernel irqchip is used - * - * \param kvm Pointer to the current kvm_context - */ -int kvm_irqchip_in_kernel(kvm_context_t kvm); - #ifdef KVM_CAP_IRQCHIP /*! * \brief Dump in kernel IRQCHIP contents @@ -1122,7 +1115,6 @@ int handle_tpr_access(void *opaque, kvm_vcpu_context_t vcpu, uint64_t rip, int kvm_has_sync_mmu(void); #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) #ifdef TARGET_I386 @@ -1134,7 +1126,6 @@ void kvm_load_tsc(CPUState *env); #define kvm_has_sync_mmu() (0) #define kvm_enabled() (0) #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) #ifndef QEMU_KVM_NO_CPU @@ -1210,6 +1201,8 @@ static inline int kvm_set_migration_log(int enable) return kvm_physical_memory_set_dirty_tracking(enable); } + +int kvm_irqchip_in_kernel(void); #ifdef CONFIG_KVM typedef struct KVMSlot { @@ -1232,6 +1225,8 @@ typedef struct KVMState { #ifdef KVM_CAP_SET_GUEST_DEBUG struct kvm_sw_breakpoint_head kvm_sw_breakpoints; #endif + int irqchip_in_kernel; + struct kvm_context kvm_context; } KVMState;