From 8897f1aaaf98febbd4d15d3ab8410d3a6847158c Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Fri, 13 Jan 2012 10:18:46 +0200 Subject: [PATCH] kvm tools: Fixes for mptable module Fixes include: - Error handling - Cleanup - Standard init/uninit Signed-off-by: Sasha Levin --- tools/kvm/builtin-run.c | 8 ++++++++ tools/kvm/include/kvm/kvm.h | 1 + tools/kvm/powerpc/kvm.c | 5 +++++ tools/kvm/x86/include/kvm/mptable.h | 3 ++- tools/kvm/x86/kvm.c | 16 +++++++++++++++- tools/kvm/x86/mptable.c | 15 +++++++++++---- 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index 4f4843d4acce..b76184d05ebe 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -1201,6 +1201,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_err("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); @@ -1270,6 +1274,10 @@ static void kvm_cmd_run_exit(int guest_ret) if (r < 0) pr_warning("serial8250__exit() 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__exit(kvm); if (r < 0) pr_warning("ioport__exit() failed with error %d\n", r); diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h index d48f2e2a724f..1b8b0323f970 100644 --- a/tools/kvm/include/kvm/kvm.h +++ b/tools/kvm/include/kvm/kvm.h @@ -63,6 +63,7 @@ void kvm__arch_set_cmdline(char *cmdline, bool video); void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size); void kvm__arch_delete_ram(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 627a66a5661b..58982ff7b0af 100644 --- a/tools/kvm/powerpc/kvm.c +++ b/tools/kvm/powerpc/kvm.c @@ -191,3 +191,8 @@ int kvm__arch_setup_firmware(struct kvm *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 8f04332f217d..9e3cfa6be1ce 100644 --- a/tools/kvm/x86/include/kvm/mptable.h +++ b/tools/kvm/x86/include/kvm/mptable.h @@ -3,6 +3,7 @@ struct kvm; -int mptable_setup(struct kvm *kvm, unsigned int ncpus); +int mptable__init(struct kvm *kvm); +int mptable__exit(struct kvm *kvm); #endif /* KVM_MPTABLE_H_ */ diff --git a/tools/kvm/x86/kvm.c b/tools/kvm/x86/kvm.c index a21888123e99..d6afa02101dd 100644 --- a/tools/kvm/x86/kvm.c +++ b/tools/kvm/x86/kvm.c @@ -358,13 +358,27 @@ bool load_bzimage(struct kvm *kvm, int fd_kernel, */ int kvm__arch_setup_firmware(struct kvm *kvm) { + int r; + /* standart minimal configuration */ setup_bios(kvm); /* FIXME: SMP, ACPI and friends here */ /* MP table */ - return 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__exit(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 c775829f090b..12bdcf8f32b8 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 */ -int 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 @@ int 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 @@ int 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); @@ -267,7 +267,8 @@ int mptable_setup(struct kvm *kvm, unsigned int ncpus) size > MPTABLE_MAX_SIZE) { free(mpc_table); pr_err("MP table is too big"); - return -1; + + return -E2BIG; } /* @@ -276,5 +277,11 @@ int 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__exit(struct kvm *kvm) +{ return 0; } -- 2.39.5