From patchwork Fri Nov 6 18:26:27 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 37879 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E0C44B70B3 for ; Sat, 7 Nov 2009 05:36:16 +1100 (EST) Received: from localhost ([127.0.0.1]:34496 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N6TfR-0002sH-VV for incoming@patchwork.ozlabs.org; Fri, 06 Nov 2009 13:36:14 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N6TWI-0000Dy-IX for qemu-devel@nongnu.org; Fri, 06 Nov 2009 13:26:46 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N6TWC-0008Vp-HG for qemu-devel@nongnu.org; Fri, 06 Nov 2009 13:26:44 -0500 Received: from [199.232.76.173] (port=44865 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N6TWC-0008Ve-BT for qemu-devel@nongnu.org; Fri, 06 Nov 2009 13:26:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:11686) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N6TWB-0001ik-W5 for qemu-devel@nongnu.org; Fri, 06 Nov 2009 13:26:40 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nA6IQdUQ031399; Fri, 6 Nov 2009 13:26:39 -0500 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nA6IQUhZ029342; Fri, 6 Nov 2009 13:26:38 -0500 From: Glauber Costa To: qemu-devel@nongnu.org Date: Fri, 6 Nov 2009 16:26:27 -0200 Message-Id: <1257531990-19437-6-git-send-email-glommer@redhat.com> In-Reply-To: <1257531990-19437-5-git-send-email-glommer@redhat.com> References: <1257531990-19437-1-git-send-email-glommer@redhat.com> <1257531990-19437-2-git-send-email-glommer@redhat.com> <1257531990-19437-3-git-send-email-glommer@redhat.com> <1257531990-19437-4-git-send-email-glommer@redhat.com> <1257531990-19437-5-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 5/8] Don't call apic functions directly from kvm code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It is actually not necessary to call a tpr function to save and load cr8, as cr8 is part of the processor state, and thus, it is much easier to just add it to CPUState. As for apic base, wrap kvm usages, so we can call either the qemu device, or the in kernel version. Signed-off-by: Glauber Costa --- target-i386/cpu.h | 1 + target-i386/kvm.c | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/target-i386/cpu.h b/target-i386/cpu.h index 5929d28..e5470f7 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -606,6 +606,7 @@ typedef struct CPUX86State { SegmentCache idt; /* only base and limit are used */ target_ulong cr[5]; /* NOTE: cr1 is unused */ + target_ulong cr8; int32_t a20_mask; /* FPU state */ diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 7010999..7c761f6 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -338,6 +338,19 @@ static void get_seg(SegmentCache *lhs, const struct kvm_segment *rhs) | (rhs->avl * DESC_AVL_MASK); } +static void kvm_set_apic_base(CPUState *env, uint64_t val) +{ + if (!kvm_irqchip_in_kernel()) + cpu_set_apic_base(env, val); +} + +static uint64_t kvm_get_apic_base(CPUState *env) +{ + if (!kvm_irqchip_in_kernel()) + return cpu_get_apic_base(env); + return 0; +} + static void kvm_getput_reg(__u64 *kvm_reg, target_ulong *qemu_reg, int set) { if (set) @@ -447,8 +460,8 @@ static int kvm_put_sregs(CPUState *env) sregs.cr3 = env->cr[3]; sregs.cr4 = env->cr[4]; - sregs.cr8 = cpu_get_apic_tpr(env); - sregs.apic_base = cpu_get_apic_base(env); + sregs.cr8 = env->cr8; + sregs.apic_base = kvm_get_apic_base(env); sregs.efer = env->efer; @@ -546,7 +559,7 @@ static int kvm_get_sregs(CPUState *env) env->cr[3] = sregs.cr3; env->cr[4] = sregs.cr4; - cpu_set_apic_base(env, sregs.apic_base); + kvm_set_apic_base(env, sregs.apic_base); env->efer = sregs.efer; //cpu_set_apic_tpr(env, sregs.cr8); @@ -742,7 +755,7 @@ int kvm_arch_pre_run(CPUState *env, struct kvm_run *run) run->request_interrupt_window = 0; dprintf("setting tpr\n"); - run->cr8 = cpu_get_apic_tpr(env); + run->cr8 = env->cr8; return 0; } @@ -754,8 +767,8 @@ int kvm_arch_post_run(CPUState *env, struct kvm_run *run) else env->eflags &= ~IF_MASK; - cpu_set_apic_tpr(env, run->cr8); - cpu_set_apic_base(env, run->apic_base); + env->cr8 = run->cr8; + kvm_set_apic_base(env, run->apic_base); return 0; }