public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: kvm@vger.kernel.org
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Subject: [patch 6/7] kvm-tpr-opt: replace kvm_get_{s,r}egs usage with cpu_synchronize_state
Date: Mon, 08 Mar 2010 21:47:10 -0300	[thread overview]
Message-ID: <20100309004834.847943165@redhat.com> (raw)
In-Reply-To: 20100309004704.049355766@redhat.com

[-- Attachment #1: tpr-remove-kvmregs --]
[-- Type: text/plain, Size: 3773 bytes --]

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

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 <stdio.h>
 
-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, &regs);
-    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, &regs);
-    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, &regs);
-    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;
 	}



  parent reply	other threads:[~2010-03-09  0:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-09  0:47 [patch 0/7] kvm-tpr-opt cleanups Marcelo Tosatti
2010-03-09  0:47 ` [patch 1/7] qemu-kvm: move vapic enablement to kvm_arch_load_regs Marcelo Tosatti
2010-03-09  0:47 ` [patch 2/7] kvm-tpr-opt: use device_init Marcelo Tosatti
2010-03-09  0:47 ` [patch 3/7] kvm-tpr-opt: qemu-kvm.h -> kvm.h Marcelo Tosatti
2010-03-09  0:47 ` [patch 4/7] kvm-tpr-opt: clean up usage of bios_enabled Marcelo Tosatti
2010-03-09  0:47 ` [patch 5/7] kvm-tpr-opt: remove dead code Marcelo Tosatti
2010-03-09  0:47 ` Marcelo Tosatti [this message]
2010-03-09  0:47 ` [patch 7/7] kvm-tpr-opt: rename env->update_vapic Marcelo Tosatti
2010-03-09 13:18 ` [patch 0/7] kvm-tpr-opt cleanups Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100309004834.847943165@redhat.com \
    --to=mtosatti@redhat.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox