From patchwork Fri Mar 22 20:37:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 2322451 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 8C7F940AFD for ; Fri, 22 Mar 2013 20:37:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422968Ab3CVUhb (ORCPT ); Fri, 22 Mar 2013 16:37:31 -0400 Received: from mail-wi0-f174.google.com ([209.85.212.174]:64442 "EHLO mail-wi0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422911Ab3CVUh2 (ORCPT ); Fri, 22 Mar 2013 16:37:28 -0400 Received: by mail-wi0-f174.google.com with SMTP id hj8so195862wib.13 for ; Fri, 22 Mar 2013 13:37:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=k5izYjjEMzyRZRx/TPgznNljw9zK8XfwRa1uxSCCiwA=; b=Fv+bA0ie7a+eb4Y+pHmw5Gu9yZql5+B3NgwCqA1S5ouFUHLMbYhZz4w+RGZlNKFwPC 3xI8bZZqhdLQ0b9PVShZbBo7v4d5cillDSAo3NGg+VWn6axjvBtR1ORoMc9utH/iahwR inAQ4Jae5ifKnImvjK9j+HjHHDrI0bERtR/5BGFjtsLkCS+vqvpVBtv+3Uh0uUl8lBK3 PqIBwyJiBdDVaQ7LPHGeN+ZO8sWJHDNJx62bYRZL92gD3vqbOJnew6hSwwB1vzdKursh PAiZnrFqNf4zOII5O6cOTWelC5yaAYnOdOQFTnoSbiU6I21YtZ/7amynmahtE/NsQBzN 6dhQ== X-Received: by 10.180.78.168 with SMTP id c8mr5335671wix.27.1363984646807; Fri, 22 Mar 2013 13:37:26 -0700 (PDT) Received: from playground.lan (93-34-176-20.ip50.fastwebnet.it. [93.34.176.20]) by mx.google.com with ESMTPS id j4sm13077190wiz.10.2013.03.22.13.37.24 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 22 Mar 2013 13:37:25 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Gleb Natapov , Marcelo Tosatti Subject: [PATCH uq/master v2 2/2] kvm: forward INIT signals coming from the chipset Date: Fri, 22 Mar 2013 21:37:17 +0100 Message-Id: <1363984637-18132-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1363984637-18132-1-git-send-email-pbonzini@redhat.com> References: <1363984637-18132-1-git-send-email-pbonzini@redhat.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When an INIT comes in, we can do the entire reset process in userspace. However, we have to be careful and move APs into KVM_MP_STATE_INIT_RECEIVED, so that the in-kernel APIC will listen to startup IPIs. Signed-off-by: Paolo Bonzini --- target-i386/helper.c | 4 ++++ target-i386/kvm.c | 37 ++++++++++++++++++++++++++----------- target-i386/kvm_i386.h | 1 + 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/target-i386/helper.c b/target-i386/helper.c index 9449a0c..bbc5adf 100644 --- a/target-i386/helper.c +++ b/target-i386/helper.c @@ -19,6 +19,7 @@ #include "cpu.h" #include "sysemu/kvm.h" +#include "kvm_i386.h" #ifndef CONFIG_USER_ONLY #include "sysemu/sysemu.h" #include "monitor/monitor.h" @@ -1290,6 +1291,9 @@ void do_cpu_init(X86CPU *cpu) cpu_reset(cs); cs->interrupt_request = sipi; env->pat = pat; + if (kvm_enabled()) { + kvm_arch_do_init_vcpu(cs); + } apic_init_reset(env->apic_state); } diff --git a/target-i386/kvm.c b/target-i386/kvm.c index df30fa6..42a4571 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -30,6 +30,8 @@ #include "qemu/config-file.h" #include "hw/pc.h" #include "hw/apic.h" +#include "hw/apic_internal.h" +#include "hw/apic-msidef.h" #include "exec/ioport.h" #include "hyperv.h" #include "hw/pci/pci.h" @@ -676,6 +678,17 @@ void kvm_arch_reset_vcpu(CPUState *cs) } } +void kvm_arch_do_init_vcpu(CPUState *cs) +{ + X86CPU *cpu = X86_CPU(cs); + CPUX86State *env = &cpu->env; + + /* APs go straight into wait-for-SIPI state after INIT# is asserted. */ + if (env->mp_state == KVM_MP_STATE_UNINITIALIZED) { + env->mp_state = KVM_MP_STATE_INIT_RECEIVED; + } +} + static int kvm_get_supported_msrs(KVMState *s) { static int kvm_supported_msrs; @@ -1773,14 +1786,15 @@ void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run) } } - if (!kvm_irqchip_in_kernel()) { - /* Force the VCPU out of its inner loop to process any INIT requests - * or pending TPR access reports. */ - if (cpu->interrupt_request & - (CPU_INTERRUPT_INIT | CPU_INTERRUPT_TPR)) { - cpu->exit_request = 1; - } + /* Force the VCPU out of its inner loop to process any INIT requests + * or (for userspace APIC, but it is cheap to combine the checks here) + * pending TPR access reports. + */ + if (cpu->interrupt_request & (CPU_INTERRUPT_INIT | CPU_INTERRUPT_TPR)) { + cpu->exit_request = 1; + } + if (!kvm_irqchip_in_kernel()) { /* Try to inject an interrupt if the guest can accept it */ if (run->ready_for_interrupt_injection && (cpu->interrupt_request & CPU_INTERRUPT_HARD) && @@ -1860,6 +1874,11 @@ int kvm_arch_process_async_events(CPUState *cs) } } + if (cs->interrupt_request & CPU_INTERRUPT_INIT) { + kvm_cpu_synchronize_state(env); + do_cpu_init(cpu); + } + if (kvm_irqchip_in_kernel()) { return 0; } @@ -1873,10 +1892,6 @@ int kvm_arch_process_async_events(CPUState *cs) (cs->interrupt_request & CPU_INTERRUPT_NMI)) { cs->halted = 0; } - if (cs->interrupt_request & CPU_INTERRUPT_INIT) { - kvm_cpu_synchronize_state(env); - do_cpu_init(cpu); - } if (cs->interrupt_request & CPU_INTERRUPT_SIPI) { kvm_cpu_synchronize_state(env); do_cpu_sipi(cpu); diff --git a/target-i386/kvm_i386.h b/target-i386/kvm_i386.h index 3accc2d..ce38ee6 100644 --- a/target-i386/kvm_i386.h +++ b/target-i386/kvm_i386.h @@ -15,6 +15,7 @@ bool kvm_allows_irq0_override(void); void kvm_arch_reset_vcpu(CPUState *cs); +void kvm_arch_do_init_vcpu(CPUState *cs); int kvm_device_pci_assign(KVMState *s, PCIHostDeviceAddress *dev_addr, uint32_t flags, uint32_t *dev_id);