Fixes include: - Error handling - Cleanup - Standard init/uninit Signed-off-by: Sasha Levin <levinsasha...@gmail.com> --- tools/kvm/builtin-run.c | 8 ++++++++ tools/kvm/include/kvm/kvm.h | 3 ++- tools/kvm/powerpc/kvm.c | 9 ++++++++- tools/kvm/x86/include/kvm/mptable.h | 3 ++- tools/kvm/x86/kvm.c | 18 ++++++++++++++++-- tools/kvm/x86/mptable.c | 20 +++++++++++++++----- 6 files changed, 51 insertions(+), 10 deletions(-)
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index eef3f80..2be3949 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -1158,6 +1158,10 @@ static int kvm_cmd_run_init(int argc, const char **argv) kvm__start_timer(kvm); kvm__arch_setup_firmware(kvm); + if (r < 0) { + pr_error("kvm__arch_setup_firmware() failed with error %d\n", r); + goto fail; + } for (i = 0; i < nrcpus; i++) { kvm_cpus[i] = kvm_cpu__init(kvm, i); @@ -1223,6 +1227,10 @@ static void kvm_cmd_run_uninit(int guest_ret) if (r < 0) pr_warning("serial8250__uninit() failed with error %d\n", r); + r = kvm__arch_free_firmware(kvm); + if (r < 0) + pr_warning("kvm__arch_free_firmware() failed with error %d\n", r); + r = ioport__uninit(kvm); if (r < 0) pr_warning("ioport__uninit() failed with error %d\n", r); diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h index 8a0c01d..74f46c1 100644 --- a/tools/kvm/include/kvm/kvm.h +++ b/tools/kvm/include/kvm/kvm.h @@ -55,7 +55,8 @@ void kvm__remove_socket(const char *name); void kvm__arch_set_cmdline(char *cmdline, bool video); void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, const char *hugetlbfs_path, u64 ram_size, const char *name); -void kvm__arch_setup_firmware(struct kvm *kvm); +int kvm__arch_setup_firmware(struct kvm *kvm); +int kvm__arch_free_firmware(struct kvm *kvm); bool kvm__arch_cpu_supports_vm(void); void kvm__arch_periodic_poll(struct kvm *kvm); diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c index f838a8f..67d042c 100644 --- a/tools/kvm/powerpc/kvm.c +++ b/tools/kvm/powerpc/kvm.c @@ -176,7 +176,7 @@ static void setup_fdt(struct kvm *kvm) /** * kvm__arch_setup_firmware */ -void kvm__arch_setup_firmware(struct kvm *kvm) +int kvm__arch_setup_firmware(struct kvm *kvm) { /* Load RTAS */ @@ -184,4 +184,11 @@ void kvm__arch_setup_firmware(struct kvm *kvm) /* Init FDT */ setup_fdt(kvm); + + return 0; +} + +int kvm__arch_free_firmware(struct kvm *kvm) +{ + return 0; } diff --git a/tools/kvm/x86/include/kvm/mptable.h b/tools/kvm/x86/include/kvm/mptable.h index 8557ae8..cfc1c72 100644 --- a/tools/kvm/x86/include/kvm/mptable.h +++ b/tools/kvm/x86/include/kvm/mptable.h @@ -3,6 +3,7 @@ struct kvm; -void mptable_setup(struct kvm *kvm, unsigned int ncpus); +int mptable__init(struct kvm *kvm); +int mptable__uninit(struct kvm *kvm); #endif /* KVM_MPTABLE_H_ */ diff --git a/tools/kvm/x86/kvm.c b/tools/kvm/x86/kvm.c index d2fbbe2..1ecadad 100644 --- a/tools/kvm/x86/kvm.c +++ b/tools/kvm/x86/kvm.c @@ -349,15 +349,29 @@ bool load_bzimage(struct kvm *kvm, int fd_kernel, * This function is a main routine where we poke guest memory * and install BIOS there. */ -void kvm__arch_setup_firmware(struct kvm *kvm) +int kvm__arch_setup_firmware(struct kvm *kvm) { + int r; + /* standart minimal configuration */ setup_bios(kvm); /* FIXME: SMP, ACPI and friends here */ /* MP table */ - mptable_setup(kvm, kvm->nrcpus); + r = mptable__init(kvm); + + return r; +} + +int kvm__arch_free_firmware(struct kvm *kvm) +{ + int r; + + /* MP table */ + r = mptable__uninit(kvm); + + return r; } void kvm__arch_periodic_poll(struct kvm *kvm) diff --git a/tools/kvm/x86/mptable.c b/tools/kvm/x86/mptable.c index 701605a..d499c51 100644 --- a/tools/kvm/x86/mptable.c +++ b/tools/kvm/x86/mptable.c @@ -71,7 +71,7 @@ static void mptable_add_irq_src(struct mpc_intsrc *mpc_intsrc, /** * mptable_setup - create mptable and fill guest memory with it */ -void mptable_setup(struct kvm *kvm, unsigned int ncpus) +int mptable__init(struct kvm *kvm) { unsigned long real_mpc_table, real_mpf_intel, size; struct mpf_intel *mpf_intel; @@ -85,7 +85,7 @@ void mptable_setup(struct kvm *kvm, unsigned int ncpus) const int pcibusid = 0; const int isabusid = 1; - unsigned int i, nentries = 0; + unsigned int i, nentries = 0, ncpus = kvm->nrcpus; unsigned int ioapicid; void *last_addr; @@ -100,7 +100,7 @@ void mptable_setup(struct kvm *kvm, unsigned int ncpus) mpc_table = calloc(1, MPTABLE_MAX_SIZE); if (!mpc_table) - die("Out of memory"); + return -ENOMEM; MPTABLE_STRNCPY(mpc_table->signature, MPC_SIGNATURE); MPTABLE_STRNCPY(mpc_table->oem, MPTABLE_OEM); @@ -264,8 +264,11 @@ void mptable_setup(struct kvm *kvm, unsigned int ncpus) */ if (size > (unsigned long)(MB_BIOS_END - bios_rom_size) || - size > MPTABLE_MAX_SIZE) - die("MP table is too big"); + size > MPTABLE_MAX_SIZE) { + free(mpc_table); + + return -E2BIG; + } /* * OK, it is time to move it to guest memory. @@ -273,4 +276,11 @@ void mptable_setup(struct kvm *kvm, unsigned int ncpus) memcpy(guest_flat_to_host(kvm, real_mpc_table), mpc_table, size); free(mpc_table); + + return 0; } + +int mptable__uninit(struct kvm *kvm) +{ + return 0; +} \ No newline at end of file -- 1.7.8 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html