From patchwork Thu Jan 28 19:03:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 75603 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o0SJ6rcO018445 for ; Thu, 28 Jan 2010 19:06:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755465Ab0A1TGu (ORCPT ); Thu, 28 Jan 2010 14:06:50 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755441Ab0A1TGu (ORCPT ); Thu, 28 Jan 2010 14:06:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42006 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753587Ab0A1TGt (ORCPT ); Thu, 28 Jan 2010 14:06:49 -0500 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 o0SJ6nCT025348 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 28 Jan 2010 14:06:49 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0SJ6m9L009299; Thu, 28 Jan 2010 14:06:48 -0500 Received: from amt.cnet (vpn-8-142.rdu.redhat.com [10.11.8.142]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o0SJ6lBA024786; Thu, 28 Jan 2010 14:06:47 -0500 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 868BA6520F1; Thu, 28 Jan 2010 17:06:42 -0200 (BRST) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id o0SJ6fHb018465; Thu, 28 Jan 2010 17:06:41 -0200 Message-Id: <20100128190411.624005970@redhat.com> User-Agent: quilt/0.47-1 Date: Thu, 28 Jan 2010 17:03:03 -0200 From: Marcelo Tosatti To: kvm@vger.kernel.org Cc: quintela@redhat.com, Marcelo Tosatti Subject: [patch 3/3] uqmaster: save/restore PIO page References: <20100128190300.414710338@redhat.com> Content-Disposition: inline; filename=kvm-save-pio-page 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 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 28 Jan 2010 19:06:53 +0000 (UTC) Index: qemu-kvm/target-i386/cpu.h =================================================================== --- qemu-kvm.orig/target-i386/cpu.h +++ qemu-kvm/target-i386/cpu.h @@ -716,6 +716,7 @@ typedef struct CPUX86State { uint32_t cpuid_kvm_features; KVMPIOState kvm_pio; + uint8_t kvm_pio_page[4096]; /* in order to simplify APIC support, we leave this pointer to the user */ Index: qemu-kvm/target-i386/machine.c =================================================================== --- qemu-kvm.orig/target-i386/machine.c +++ qemu-kvm/target-i386/machine.c @@ -350,6 +350,8 @@ static void cpu_pre_save(void *opaque) int i; cpu_synchronize_state(env); + if (kvm_enabled()) + kvm_get_pio_page(env); /* FPU */ env->fpus_vmstate = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11; @@ -378,6 +380,9 @@ static int cpu_post_load(void *opaque, i CPUState *env = opaque; int i; + if (kvm_enabled()) + kvm_put_pio_page(env); + /* XXX: restore FPU round state */ env->fpstt = (env->fpus_vmstate >> 11) & 7; env->fpus = env->fpus_vmstate & ~0x3800; @@ -494,6 +499,7 @@ static const VMStateDescription vmstate_ VMSTATE_UINT64_V(wall_clock_msr, CPUState, 11), VMSTATE_KVM_PIO(kvm_pio, CPUState, 11), + VMSTATE_UINT8_ARRAY_V(kvm_pio_page, CPUState, TARGET_PAGE_SIZE, 11), VMSTATE_END_OF_LIST() /* The above list is not sorted /wrt version numbers, watch out! */ Index: qemu-kvm/kvm.h =================================================================== --- qemu-kvm.orig/kvm.h +++ qemu-kvm/kvm.h @@ -132,6 +132,9 @@ uint32_t kvm_arch_get_supported_cpuid(CP int reg); void kvm_cpu_synchronize_state(CPUState *env); +void kvm_put_pio_page(CPUState *env); +void kvm_get_pio_page(CPUState *env); + /* generic hooks - to be moved/refactored once there are more users */ static inline void cpu_synchronize_state(CPUState *env) Index: qemu-kvm/target-i386/kvm.c =================================================================== --- qemu-kvm.orig/target-i386/kvm.c +++ qemu-kvm/target-i386/kvm.c @@ -889,6 +889,39 @@ static int kvm_get_pio(CPUState *env) return 0; } +static int kvm_pio_page_offset(CPUState *env) +{ + int ret = 0; + +#ifdef KVM_CAP_PIO + ret = kvm_check_extension(env->kvm_state, KVM_CAP_PIO); +#endif + + return ret; +} + +void kvm_put_pio_page(CPUState *env) +{ + uint8_t *pio_page; + int pio_page_off = kvm_pio_page_offset(env); + + if (pio_page_off) { + pio_page = (uint8_t *)env->kvm_run + (pio_page_off * TARGET_PAGE_SIZE); + memcpy(pio_page, env->kvm_pio_page, TARGET_PAGE_SIZE); + } +} + +void kvm_get_pio_page(CPUState *env) +{ + uint8_t *pio_page; + int pio_page_off = kvm_pio_page_offset(env); + + if (pio_page_off) { + pio_page = (uint8_t *)env->kvm_run + (pio_page_off * TARGET_PAGE_SIZE); + memcpy(env->kvm_pio_page, pio_page, TARGET_PAGE_SIZE); + } +} + int kvm_arch_put_registers(CPUState *env) { int ret;