From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: Re: [PATCH 28/28] kvm tools: Create arch-specific kvm_cpu__emulate_io() Date: Tue, 06 Dec 2011 10:54:47 +0200 Message-ID: <1323161687.3882.16.camel@lappy> References: <4EDD8F51.2020007@ozlabs.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org To: Matt Evans Return-path: Received: from mail-ee0-f46.google.com ([74.125.83.46]:56930 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932971Ab1LFIzH (ORCPT ); Tue, 6 Dec 2011 03:55:07 -0500 In-Reply-To: <4EDD8F51.2020007@ozlabs.org> Sender: kvm-owner@vger.kernel.org List-ID: Can we possibly do it by getting the generic code to call both 'kvm_cpu__arch_emulate_io' and 'kvm_cpu__arch_emulate_mmio', and have the ppc code have an empty static for 'kvm_cpu__arch_emulate_io'? On Tue, 2011-12-06 at 14:43 +1100, Matt Evans wrote: > Different architectures will deal with MMIO exits differently. For example, > KVM_EXIT_IO is x86-specific, and I/O cycles are often synthesisted by steering > into windows in PCI bridges on other architectures. > > This patch moves the IO/MMIO exit code from the main runloop into x86/kvm-cpu.c > > Signed-off-by: Matt Evans > --- > tools/kvm/include/kvm/kvm-cpu.h | 1 + > tools/kvm/kvm-cpu.c | 37 +++++-------------------------------- > tools/kvm/x86/kvm-cpu.c | 37 +++++++++++++++++++++++++++++++++++++ > 3 files changed, 43 insertions(+), 32 deletions(-) > > diff --git a/tools/kvm/include/kvm/kvm-cpu.h b/tools/kvm/include/kvm/kvm-cpu.h > index 15618f1..6f38c0c 100644 > --- a/tools/kvm/include/kvm/kvm-cpu.h > +++ b/tools/kvm/include/kvm/kvm-cpu.h > @@ -13,6 +13,7 @@ void kvm_cpu__run(struct kvm_cpu *vcpu); > void kvm_cpu__reboot(void); > int kvm_cpu__start(struct kvm_cpu *cpu); > bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu); > +bool kvm_cpu__emulate_io(struct kvm_cpu *cpu, struct kvm_run *kvm_run); > > int kvm_cpu__get_debug_fd(void); > void kvm_cpu__set_debug_fd(int fd); > diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c > index 884a89f..c9fbc81 100644 > --- a/tools/kvm/kvm-cpu.c > +++ b/tools/kvm/kvm-cpu.c > @@ -103,49 +103,22 @@ int kvm_cpu__start(struct kvm_cpu *cpu) > kvm_cpu__show_registers(cpu); > kvm_cpu__show_code(cpu); > break; > - 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); > - > - if (!ret) > + case KVM_EXIT_IO: > + case KVM_EXIT_MMIO: > + if (!kvm_cpu__emulate_io(cpu, cpu->kvm_run)) > goto panic_kvm; > break; > - } > - 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); > - > - if (!ret) > - goto panic_kvm; > - break; > - } > case KVM_EXIT_INTR: > if (cpu->is_running) > break; > goto exit_kvm; > case KVM_EXIT_SHUTDOWN: > goto exit_kvm; > - default: { > - bool ret; > - > - ret = kvm_cpu__handle_exit(cpu); > - if (!ret) > + default: > + if (!kvm_cpu__handle_exit(cpu)) > goto panic_kvm; > break; > } > - } > kvm_cpu__handle_coalesced_mmio(cpu); > } > > diff --git a/tools/kvm/x86/kvm-cpu.c b/tools/kvm/x86/kvm-cpu.c > index a0d10cc..665d742 100644 > --- a/tools/kvm/x86/kvm-cpu.c > +++ b/tools/kvm/x86/kvm-cpu.c > @@ -217,6 +217,43 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu) > return false; > } > > +bool kvm_cpu__emulate_io(struct kvm_cpu *cpu, struct kvm_run *kvm_run) > +{ > + bool ret; > + switch (kvm_run->exit_reason) { > + case KVM_EXIT_IO: { > + 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); > + > + if (!ret) > + goto panic_kvm; > + break; > + } > + case KVM_EXIT_MMIO: { > + 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); > + > + if (!ret) > + goto panic_kvm; > + break; > + } > + default: > + pr_warning("Unknown exit reason %d in %s\n", kvm_run->exit_reason, __FUNCTION__); > + return false; > + } > + return true; > +panic_kvm: > + return false; > +} > + > static void print_dtable(const char *name, struct kvm_dtable *dtable) > { > dprintf(debug_fd, " %s %016llx %08hx\n", > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- Sasha. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Date: Tue, 06 Dec 2011 08:54:47 +0000 Subject: Re: [PATCH 28/28] kvm tools: Create arch-specific Message-Id: <1323161687.3882.16.camel@lappy> List-Id: References: <4EDD8F51.2020007@ozlabs.org> In-Reply-To: <4EDD8F51.2020007@ozlabs.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Matt Evans Cc: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Can we possibly do it by getting the generic code to call both 'kvm_cpu__arch_emulate_io' and 'kvm_cpu__arch_emulate_mmio', and have the ppc code have an empty static for 'kvm_cpu__arch_emulate_io'? On Tue, 2011-12-06 at 14:43 +1100, Matt Evans wrote: > Different architectures will deal with MMIO exits differently. For example, > KVM_EXIT_IO is x86-specific, and I/O cycles are often synthesisted by steering > into windows in PCI bridges on other architectures. > > This patch moves the IO/MMIO exit code from the main runloop into x86/kvm-cpu.c > > Signed-off-by: Matt Evans > --- > tools/kvm/include/kvm/kvm-cpu.h | 1 + > tools/kvm/kvm-cpu.c | 37 +++++-------------------------------- > tools/kvm/x86/kvm-cpu.c | 37 +++++++++++++++++++++++++++++++++++++ > 3 files changed, 43 insertions(+), 32 deletions(-) > > diff --git a/tools/kvm/include/kvm/kvm-cpu.h b/tools/kvm/include/kvm/kvm-cpu.h > index 15618f1..6f38c0c 100644 > --- a/tools/kvm/include/kvm/kvm-cpu.h > +++ b/tools/kvm/include/kvm/kvm-cpu.h > @@ -13,6 +13,7 @@ void kvm_cpu__run(struct kvm_cpu *vcpu); > void kvm_cpu__reboot(void); > int kvm_cpu__start(struct kvm_cpu *cpu); > bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu); > +bool kvm_cpu__emulate_io(struct kvm_cpu *cpu, struct kvm_run *kvm_run); > > int kvm_cpu__get_debug_fd(void); > void kvm_cpu__set_debug_fd(int fd); > diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c > index 884a89f..c9fbc81 100644 > --- a/tools/kvm/kvm-cpu.c > +++ b/tools/kvm/kvm-cpu.c > @@ -103,49 +103,22 @@ int kvm_cpu__start(struct kvm_cpu *cpu) > kvm_cpu__show_registers(cpu); > kvm_cpu__show_code(cpu); > break; > - 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); > - > - if (!ret) > + case KVM_EXIT_IO: > + case KVM_EXIT_MMIO: > + if (!kvm_cpu__emulate_io(cpu, cpu->kvm_run)) > goto panic_kvm; > break; > - } > - 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); > - > - if (!ret) > - goto panic_kvm; > - break; > - } > case KVM_EXIT_INTR: > if (cpu->is_running) > break; > goto exit_kvm; > case KVM_EXIT_SHUTDOWN: > goto exit_kvm; > - default: { > - bool ret; > - > - ret = kvm_cpu__handle_exit(cpu); > - if (!ret) > + default: > + if (!kvm_cpu__handle_exit(cpu)) > goto panic_kvm; > break; > } > - } > kvm_cpu__handle_coalesced_mmio(cpu); > } > > diff --git a/tools/kvm/x86/kvm-cpu.c b/tools/kvm/x86/kvm-cpu.c > index a0d10cc..665d742 100644 > --- a/tools/kvm/x86/kvm-cpu.c > +++ b/tools/kvm/x86/kvm-cpu.c > @@ -217,6 +217,43 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu) > return false; > } > > +bool kvm_cpu__emulate_io(struct kvm_cpu *cpu, struct kvm_run *kvm_run) > +{ > + bool ret; > + switch (kvm_run->exit_reason) { > + case KVM_EXIT_IO: { > + 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); > + > + if (!ret) > + goto panic_kvm; > + break; > + } > + case KVM_EXIT_MMIO: { > + 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); > + > + if (!ret) > + goto panic_kvm; > + break; > + } > + default: > + pr_warning("Unknown exit reason %d in %s\n", kvm_run->exit_reason, __FUNCTION__); > + return false; > + } > + return true; > +panic_kvm: > + return false; > +} > + > static void print_dtable(const char *name, struct kvm_dtable *dtable) > { > dprintf(debug_fd, " %s %016llx %08hx\n", > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- Sasha.