From: Matt Evans <matt@ozlabs.org>
To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org
Cc: penberg@kernel.org, asias.hejun@gmail.com,
levinsasha928@gmail.com, gorcunov@gmail.com
Subject: [PATCH V3 2/2] kvm tools: Create arch-specific kvm_cpu__emulate_{mm}io()
Date: Tue, 13 Dec 2011 17:21:47 +1100 [thread overview]
Message-ID: <1323757307-10411-3-git-send-email-matt@ozlabs.org> (raw)
In-Reply-To: <1323757307-10411-1-git-send-email-matt@ozlabs.org>
Different architectures will deal with MMIO exits differently. For example,
KVM_EXIT_IO is x86-specific, and I/O cycles are often synthesised by steering
into windows in PCI bridges on other architectures.
This patch calls arch-specific kvm_cpu__emulate_io() and kvm_cpu__emulate_mmio()
from the main runloop's IO and MMIO exit handlers. For x86, these directly
call kvm__emulate_io() and kvm__emulate_mmio() but other architectures will
perform some address munging before passing on the call.
Signed-off-by: Matt Evans <matt@ozlabs.org>
---
tools/kvm/kvm-cpu.c | 34 +++++++++++++++---------------
tools/kvm/x86/include/kvm/kvm-cpu-arch.h | 17 ++++++++++++++-
2 files changed, 33 insertions(+), 18 deletions(-)
diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c
index 8ec4efa..b7ae3d3 100644
--- a/tools/kvm/kvm-cpu.c
+++ b/tools/kvm/kvm-cpu.c
@@ -52,11 +52,11 @@ static void kvm_cpu__handle_coalesced_mmio(struct kvm_cpu *cpu)
while (cpu->ring->first != cpu->ring->last) {
struct kvm_coalesced_mmio *m;
m = &cpu->ring->coalesced_mmio[cpu->ring->first];
- kvm__emulate_mmio(cpu->kvm,
- m->phys_addr,
- m->data,
- m->len,
- 1);
+ kvm_cpu__emulate_mmio(cpu->kvm,
+ m->phys_addr,
+ m->data,
+ m->len,
+ 1);
cpu->ring->first = (cpu->ring->first + 1) % KVM_COALESCED_MMIO_MAX;
}
}
@@ -111,13 +111,13 @@ int kvm_cpu__start(struct kvm_cpu *cpu)
case KVM_EXIT_IO: {
bool ret;
- ret = kvm__emulate_io(cpu->kvm,
- cpu->kvm_run->io.port,
- (u8 *)cpu->kvm_run +
- cpu->kvm_run->io.data_offset,
- cpu->kvm_run->io.direction,
- cpu->kvm_run->io.size,
- cpu->kvm_run->io.count);
+ ret = kvm_cpu__emulate_io(cpu->kvm,
+ cpu->kvm_run->io.port,
+ (u8 *)cpu->kvm_run +
+ cpu->kvm_run->io.data_offset,
+ cpu->kvm_run->io.direction,
+ cpu->kvm_run->io.size,
+ cpu->kvm_run->io.count);
if (!ret)
goto panic_kvm;
@@ -126,11 +126,11 @@ int kvm_cpu__start(struct kvm_cpu *cpu)
case KVM_EXIT_MMIO: {
bool ret;
- ret = kvm__emulate_mmio(cpu->kvm,
- cpu->kvm_run->mmio.phys_addr,
- cpu->kvm_run->mmio.data,
- cpu->kvm_run->mmio.len,
- cpu->kvm_run->mmio.is_write);
+ ret = kvm_cpu__emulate_mmio(cpu->kvm,
+ cpu->kvm_run->mmio.phys_addr,
+ cpu->kvm_run->mmio.data,
+ cpu->kvm_run->mmio.len,
+ cpu->kvm_run->mmio.is_write);
if (!ret)
goto panic_kvm;
diff --git a/tools/kvm/x86/include/kvm/kvm-cpu-arch.h b/tools/kvm/x86/include/kvm/kvm-cpu-arch.h
index 822d966..198efe6 100644
--- a/tools/kvm/x86/include/kvm/kvm-cpu-arch.h
+++ b/tools/kvm/x86/include/kvm/kvm-cpu-arch.h
@@ -4,7 +4,8 @@
/* Architecture-specific kvm_cpu definitions. */
#include <linux/kvm.h> /* for struct kvm_regs */
-
+#include "kvm/kvm.h" /* for kvm__emulate_{mm}io() */
+#include <stdbool.h>
#include <pthread.h>
struct kvm;
@@ -31,4 +32,18 @@ struct kvm_cpu {
struct kvm_coalesced_mmio_ring *ring;
};
+/*
+ * As these are such simple wrappers, let's have them in the header so they'll
+ * be cheaper to call:
+ */
+static inline bool kvm_cpu__emulate_io(struct kvm *kvm, u16 port, void *data, int direction, int size, u32 count)
+{
+ return kvm__emulate_io(kvm, port, data, direction, size, count);
+}
+
+static inline bool kvm_cpu__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, u8 is_write)
+{
+ return kvm__emulate_mmio(kvm, phys_addr, data, len, is_write);
+}
+
#endif /* KVM__KVM_CPU_ARCH_H */
--
1.7.0.4
next prev parent reply other threads:[~2011-12-13 6:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-13 6:21 [PATCH V3 0/2] kvm tools: Prepare kvmtool for another architecture Matt Evans
2011-12-13 6:21 ` [PATCH V3 1/2] kvm tools: Add ability to map guest RAM from hugetlbfs Matt Evans
2011-12-14 0:03 ` David Evensky
2011-12-14 1:45 ` Matt Evans
2011-12-13 6:21 ` Matt Evans [this message]
2011-12-23 12:58 ` [PATCH V3 2/2] kvm tools: Create arch-specific kvm_cpu__emulate_{mm}io() Alexander Graf
2011-12-23 13:26 ` Matt Evans
2011-12-23 13:39 ` Alexander Graf
2012-01-06 5:32 ` Matt Evans
2012-01-09 13:41 ` Alexander Graf
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=1323757307-10411-3-git-send-email-matt@ozlabs.org \
--to=matt@ozlabs.org \
--cc=asias.hejun@gmail.com \
--cc=gorcunov@gmail.com \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=levinsasha928@gmail.com \
--cc=penberg@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;
as well as URLs for NNTP newsgroup(s).