From patchwork Fri Jul 24 05:57:07 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 37083 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 n6O5vDxE013674 for ; Fri, 24 Jul 2009 05:57:13 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751928AbZGXF5J (ORCPT ); Fri, 24 Jul 2009 01:57:09 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751932AbZGXF5J (ORCPT ); Fri, 24 Jul 2009 01:57:09 -0400 Received: from mx2.redhat.com ([66.187.237.31]:59110 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751551AbZGXF5I (ORCPT ); Fri, 24 Jul 2009 01:57:08 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n6O5v8OP031598 for ; Fri, 24 Jul 2009 01:57:08 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n6O5v7OT024677; Fri, 24 Jul 2009 01:57:08 -0400 Received: from localhost.localdomain (virtlab1.virt.bos.redhat.com [10.16.72.21]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n6O5v7fI021960; Fri, 24 Jul 2009 01:57:07 -0400 From: Glauber Costa To: kvm@vger.kernel.org Cc: avi@redhat.com Subject: [PATCH] simplify creation of kernel irqchip and pit Date: Fri, 24 Jul 2009 01:57:07 -0400 Message-Id: <1248415027-31313-1-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Creation of those devices can be a lot simpler. In particular, if we start by assuming they will be on, and disabling later if anything fails (user request counts as failing here), we can remove two variables that really serves no reason. Signed-off-by: Glauber Costa --- qemu-kvm-x86.c | 33 +++++++++++++++------------- qemu-kvm.c | 65 +++++++++++++++++++++++++------------------------------- qemu-kvm.h | 4 --- 3 files changed, 47 insertions(+), 55 deletions(-) diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index 492dbc5..0a42455 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -116,24 +116,27 @@ static int kvm_init_identity_map_page(kvm_context_t kvm) static int kvm_create_pit(kvm_context_t kvm) { + int r = 0; #ifdef KVM_CAP_PIT - int r; - kvm->pit_in_kernel = 0; - if (!kvm->no_pit_creation) { - r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_PIT); - if (r > 0) { - r = kvm_vm_ioctl(kvm_state, KVM_CREATE_PIT); - if (r >= 0) - kvm->pit_in_kernel = 1; - else { - fprintf(stderr, "Create kernel PIC irqchip failed\n"); - return r; - } - } - } + if (!qemu_kvm_pit_in_kernel()) + return 0; + + r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_PIT); + if (r < 0) { + goto disable_pit; + } + r = kvm_vm_ioctl(kvm_state, KVM_CREATE_PIT); + if (r < 0) { + fprintf(stderr, "Create kernel PIC irqchip failed\n"); + goto disable_pit; + } + + return 0; +disable_pit: + kvm->pit_in_kernel = 0; #endif - return 0; + return r; } int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes, diff --git a/qemu-kvm.c b/qemu-kvm.c index 9d550d3..bca256c 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -382,6 +382,7 @@ int kvm_dirty_pages_log_enable_all(kvm_context_t kvm) if (kvm->dirty_pages_log_all) return 0; kvm->dirty_pages_log_all = 1; + return kvm_dirty_pages_log_change_all(kvm, kvm_dirty_pages_log_enable_slot); } @@ -439,8 +440,6 @@ int kvm_init(int smp_cpus) kvm_state->vmfd = -1; kvm_context->opaque = cpu_single_env; kvm_context->dirty_pages_log_all = 0; - kvm_context->no_irqchip_creation = 0; - kvm_context->no_pit_creation = 0; #ifdef KVM_CAP_SET_GUEST_DEBUG TAILQ_INIT(&kvm_state->kvm_sw_breakpoints); @@ -480,16 +479,6 @@ static void kvm_finalize(KVMState *s) free(s); } -void kvm_disable_irqchip_creation(kvm_context_t kvm) -{ - kvm->no_irqchip_creation = 1; -} - -void kvm_disable_pit_creation(kvm_context_t kvm) -{ - kvm->no_pit_creation = 1; -} - kvm_vcpu_context_t kvm_create_vcpu(CPUState *env, int id) { long mmap_size; @@ -575,28 +564,35 @@ static int kvm_create_default_phys_mem(kvm_context_t kvm, void kvm_create_irqchip(kvm_context_t kvm) { - int r; + int r = 0; - kvm->irqchip_in_kernel = 0; #ifdef KVM_CAP_IRQCHIP - if (!kvm->no_irqchip_creation) { - r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_IRQCHIP); - if (r > 0) { /* kernel irqchip supported */ - r = kvm_vm_ioctl(kvm_state, KVM_CREATE_IRQCHIP); - if (r >= 0) { - kvm->irqchip_inject_ioctl = KVM_IRQ_LINE; + if (!qemu_kvm_irqchip_in_kernel()) { + return; + } + + r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_IRQCHIP); + if (r < 0) { + goto disable_irqchip; + } + + r = kvm_vm_ioctl(kvm_state, KVM_CREATE_IRQCHIP); + if (r < 0) { + fprintf(stderr, "Create kernel PIC irqchip failed\n"); + goto disable_irqchip; + } + + kvm->irqchip_inject_ioctl = KVM_IRQ_LINE; #if defined(KVM_CAP_IRQ_INJECT_STATUS) && defined(KVM_IRQ_LINE_STATUS) - r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, - KVM_CAP_IRQ_INJECT_STATUS); - if (r > 0) - kvm->irqchip_inject_ioctl = KVM_IRQ_LINE_STATUS; + r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_IRQ_INJECT_STATUS); + if (r > 0) { + kvm->irqchip_inject_ioctl = KVM_IRQ_LINE_STATUS; + } #endif - kvm->irqchip_in_kernel = 1; - } - else - fprintf(stderr, "Create kernel PIC irqchip failed\n"); - } - } + return; + +disable_irqchip: + kvm->irqchip_in_kernel = 0; #endif } @@ -2169,12 +2165,9 @@ static int kvm_create_context() { int r; - if (!kvm_irqchip) { - kvm_disable_irqchip_creation(kvm_context); - } - if (!kvm_pit) { - kvm_disable_pit_creation(kvm_context); - } + kvm_context->irqchip_in_kernel = kvm_irqchip; + kvm_context->pit_in_kernel = kvm_pit; + if (kvm_create(kvm_context, 0, NULL) < 0) { kvm_finalize(kvm_state); return -1; diff --git a/qemu-kvm.h b/qemu-kvm.h index b186c9d..5eb1ee5 100644 --- a/qemu-kvm.h +++ b/qemu-kvm.h @@ -55,14 +55,10 @@ struct kvm_context { void *opaque; /// is dirty pages logging enabled for all regions or not int dirty_pages_log_all; - /// do not create in-kernel irqchip if set - int no_irqchip_creation; /// in-kernel irqchip status int irqchip_in_kernel; /// ioctl to use to inject interrupts int irqchip_inject_ioctl; - /// do not create in-kernel pit if set - int no_pit_creation; /// in-kernel pit status int pit_in_kernel; /// in-kernel coalesced mmio