Message ID | 4EDD8F51.2020007@ozlabs.org |
---|---|
State | New, archived |
Headers | show |
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 <matt@ozlabs.org> > --- > 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
On 06/12/11 19:54, Sasha Levin wrote: > 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'? Yeah that's nicer, I'll make that change... less invasive. Cheers, Matt > > 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 <matt@ozlabs.org> >> --- >> 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 > -- To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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",
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 <matt@ozlabs.org> --- 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(-) -- To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html