From patchwork Tue Mar 9 00:47:10 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 84199 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 o290o4av020711 for ; Tue, 9 Mar 2010 00:50:05 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756283Ab0CIAtt (ORCPT ); Mon, 8 Mar 2010 19:49:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50030 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755725Ab0CIAt3 (ORCPT ); Mon, 8 Mar 2010 19:49:29 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o290nTYr024711 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 8 Mar 2010 19:49:29 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o290nTYL019933; Mon, 8 Mar 2010 19:49:29 -0500 Received: from amt.cnet (vpn-9-132.rdu.redhat.com [10.11.9.132]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o290nRqT000983; Mon, 8 Mar 2010 19:49:28 -0500 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 56EE668A867; Mon, 8 Mar 2010 21:48:49 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id o290mmET019710; Mon, 8 Mar 2010 21:48:48 -0300 Message-Id: <20100309004834.847943165@redhat.com> User-Agent: quilt/0.47-1 Date: Mon, 08 Mar 2010 21:47:10 -0300 From: Marcelo Tosatti To: kvm@vger.kernel.org Cc: Marcelo Tosatti Subject: [patch 6/7] kvm-tpr-opt: replace kvm_get_{s, r}egs usage with cpu_synchronize_state References: <20100309004704.049355766@redhat.com> Content-Disposition: inline; filename=tpr-remove-kvmregs X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 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]); Tue, 09 Mar 2010 00:50:05 +0000 (UTC) Index: qemu-kvm-tpr/kvm-tpr-opt.c =================================================================== --- qemu-kvm-tpr.orig/kvm-tpr-opt.c +++ qemu-kvm-tpr/kvm-tpr-opt.c @@ -19,13 +19,13 @@ #include -static uint64_t map_addr(struct kvm_sregs *sregs, target_ulong virt, unsigned *perms) +static uint64_t map_addr(CPUState *env, target_ulong virt, unsigned *perms) { uint64_t mask = ((1ull << 48) - 1) & ~4095ull; uint64_t p, pp = 7; - p = sregs->cr3; - if (sregs->cr4 & 0x20) { + p = env->cr[3]; + if (env->cr[4] & 0x20) { p &= ~31ull; p = ldq_phys(p + 8 * (virt >> 30)); if (!(p & 1)) @@ -68,26 +68,12 @@ static uint64_t map_addr(struct kvm_sreg static uint8_t read_byte_virt(CPUState *env, target_ulong virt) { - struct kvm_sregs sregs; - - kvm_get_sregs(env, &sregs); - return ldub_phys(map_addr(&sregs, virt, NULL)); + return ldub_phys(map_addr(env, virt, NULL)); } static void write_byte_virt(CPUState *env, target_ulong virt, uint8_t b) { - struct kvm_sregs sregs; - - kvm_get_sregs(env, &sregs); - stb_phys(map_addr(&sregs, virt, NULL), b); -} - -static __u64 kvm_rsp_read(CPUState *env) -{ - struct kvm_regs regs; - - kvm_get_regs(env, ®s); - return regs.rsp; + stb_phys(map_addr(env, virt, NULL), b); } struct vapic_bios { @@ -143,7 +129,7 @@ static int instruction_is_ok(CPUState *e if ((rip & 0xf0000000) != 0x80000000 && (rip & 0xf0000000) != 0xe0000000) return 0; - if (kvm_rsp_read(env) == 0) + if (env->regs[R_ESP] == 0) return 0; b1 = read_byte_virt(env, rip); b2 = read_byte_virt(env, rip + 1); @@ -185,7 +171,6 @@ static int bios_is_mapped(CPUState *env, { uint32_t probe; uint64_t phys; - struct kvm_sregs sregs; unsigned perms; uint32_t i; uint32_t offset, fixup, start = vapic_bios_addr ? : 0xe0000; @@ -193,10 +178,8 @@ static int bios_is_mapped(CPUState *env, if (bios_enabled) return 1; - kvm_get_sregs(env, &sregs); - probe = (rip & 0xf0000000) + start; - phys = map_addr(&sregs, probe, &perms); + phys = map_addr(env, probe, &perms); if (phys != start) return 0; bios_addr = probe; @@ -309,6 +292,7 @@ static void patch_instruction(CPUState * void kvm_tpr_access_report(CPUState *env, uint64_t rip, int is_write) { + cpu_synchronize_state(env); if (!instruction_is_ok(env, rip, is_write)) return; if (!bios_is_mapped(env, rip)) @@ -358,33 +342,30 @@ static int tpr_load(QEMUFile *f, void *s static void vtpr_ioport_write16(void *opaque, uint32_t addr, uint32_t val) { - struct kvm_regs regs; CPUState *env = cpu_single_env; - struct kvm_sregs sregs; - kvm_get_regs(env, ®s); - kvm_get_sregs(env, &sregs); - vapic_bios_addr = ((sregs.cs.base + regs.rip) & ~(512 - 1)) + val; + + cpu_synchronize_state(env); + + vapic_bios_addr = ((env->segs[R_CS].base + env->eip) & ~(512 - 1)) + val; bios_enabled = 0; } static void vtpr_ioport_write(void *opaque, uint32_t addr, uint32_t val) { CPUState *env = cpu_single_env; - struct kvm_regs regs; - struct kvm_sregs sregs; uint32_t rip; - kvm_get_regs(env, ®s); - rip = regs.rip - 2; + cpu_synchronize_state(env); + + rip = env->eip - 2; write_byte_virt(env, rip, 0x66); write_byte_virt(env, rip + 1, 0x90); if (bios_enabled) return; if (!bios_is_mapped(env, rip)) printf("bios not mapped?\n"); - kvm_get_sregs(env, &sregs); for (addr = 0xfffff000u; addr >= 0x80000000u; addr -= 4096) - if (map_addr(&sregs, addr, NULL) == 0xfee00000u) { + if (map_addr(env, addr, NULL) == 0xfee00000u) { real_tpr = addr + 0x80; break; }