From patchwork Thu Jan 21 17:01:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 8083371 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 880CBBEEE5 for ; Thu, 21 Jan 2016 17:04:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 57E5E200FE for ; Thu, 21 Jan 2016 17:04:51 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2FA9F200F2 for ; Thu, 21 Jan 2016 17:04:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aMIcl-0005kX-HC; Thu, 21 Jan 2016 17:02:19 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aMIcj-0005ij-Uv for xen-devel@lists.xensource.com; Thu, 21 Jan 2016 17:02:18 +0000 Received: from [85.158.143.35] by server-2.bemta-4.messagelabs.com id 53/AE-08977-91F01A65; Thu, 21 Jan 2016 17:02:17 +0000 X-Env-Sender: prvs=821047e81=Stefano.Stabellini@citrix.com X-Msg-Ref: server-16.tower-21.messagelabs.com!1453395731!7014214!4 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 63085 invoked from network); 21 Jan 2016 17:02:16 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-16.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 21 Jan 2016 17:02:16 -0000 X-IronPort-AV: E=Sophos;i="5.22,326,1449532800"; d="scan'208";a="326849554" From: Stefano Stabellini To: Date: Thu, 21 Jan 2016 17:01:22 +0000 Message-ID: <1453395690-32660-3-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-DLP: MIA2 Cc: Markus Armbruster , xen-devel@lists.xensource.com, qemu-devel@nongnu.org, Stefano Stabellini Subject: [Xen-devel] [PULL 03/11] xen-hvm: Clean up xen_hvm_init() error handling X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Armbruster xen_hvm_init() returns -1 without cleaning up on some errors (harmless long as the caller exit()s on error), dies with hw_error() on others. hw_error() isn't approprate here. Clean up to exit() on all errors. Signed-off-by: Markus Armbruster Reviewed-by: Stefano Stabellini Signed-off-by: Stefano Stabellini --- hw/i386/pc_piix.c | 5 ++--- hw/i386/pc_q35.c | 5 ++--- include/hw/xen/xen.h | 2 +- xen-hvm-stub.c | 3 +-- xen-hvm.c | 61 ++++++++++++++++++++++++++------------------------ 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index df2b824..db0ae9c 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -121,9 +121,8 @@ static void pc_init1(MachineState *machine, pcms->below_4g_mem_size = machine->ram_size; } - if (xen_enabled() && xen_hvm_init(pcms, &ram_memory) != 0) { - fprintf(stderr, "xen hardware virtual machine initialisation failed\n"); - exit(1); + if (xen_enabled()) { + xen_hvm_init(pcms, &ram_memory); } pc_cpus_init(pcms); diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 412b3cd..abbcbf9 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -111,9 +111,8 @@ static void pc_q35_init(MachineState *machine) pcms->below_4g_mem_size = machine->ram_size; } - if (xen_enabled() && xen_hvm_init(pcms, &ram_memory) != 0) { - fprintf(stderr, "xen hardware virtual machine initialisation failed\n"); - exit(1); + if (xen_enabled()) { + xen_hvm_init(pcms, &ram_memory); } pc_cpus_init(pcms); diff --git a/include/hw/xen/xen.h b/include/hw/xen/xen.h index e90931a..d07bc99 100644 --- a/include/hw/xen/xen.h +++ b/include/hw/xen/xen.h @@ -39,7 +39,7 @@ qemu_irq *xen_interrupt_controller_init(void); void xenstore_store_pv_console_info(int i, struct CharDriverState *chr); #if defined(NEED_CPU_H) && !defined(CONFIG_USER_ONLY) -int xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory); +void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory); void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, struct MemoryRegion *mr); void xen_modified_memory(ram_addr_t start, ram_addr_t length); diff --git a/xen-hvm-stub.c b/xen-hvm-stub.c index 6a39425..7ff0602 100644 --- a/xen-hvm-stub.c +++ b/xen-hvm-stub.c @@ -47,9 +47,8 @@ void xen_modified_memory(ram_addr_t start, ram_addr_t length) { } -int xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) +void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) { - return 0; } void qmp_xen_set_global_dirty_log(bool enable, Error **errp) diff --git a/xen-hvm.c b/xen-hvm.c index 2a93390..cb7128c 100644 --- a/xen-hvm.c +++ b/xen-hvm.c @@ -17,6 +17,7 @@ #include "qmp-commands.h" #include "sysemu/char.h" +#include "qemu/error-report.h" #include "qemu/range.h" #include "sysemu/xen-mapcache.h" #include "trace.h" @@ -1189,16 +1190,8 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data) xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 0); } -/* return 0 means OK, or -1 means critical issue -- will exit(1) */ -int xen_hvm_init(PCMachineState *pcms, - MemoryRegion **ram_memory) +void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) { - /* - * FIXME Returns -1 without cleaning up on some errors (harmless - * as long as the caller exit()s on error), dies with hw_error() - * on others. hw_error() isn't approprate here. Should probably - * simply exit() on all errors. - */ int i, rc; xen_pfn_t ioreq_pfn; xen_pfn_t bufioreq_pfn; @@ -1210,19 +1203,19 @@ int xen_hvm_init(PCMachineState *pcms, state->xce_handle = xen_xc_evtchn_open(NULL, 0); if (state->xce_handle == XC_HANDLER_INITIAL_VALUE) { perror("xen: event channel open"); - return -1; + goto err; } state->xenstore = xs_daemon_open(); if (state->xenstore == NULL) { perror("xen: xenstore open"); - return -1; + goto err; } rc = xen_create_ioreq_server(xen_xc, xen_domid, &state->ioservid); if (rc < 0) { perror("xen: ioreq server create"); - return -1; + goto err; } state->exit.notify = xen_exit_notifier; @@ -1238,8 +1231,9 @@ int xen_hvm_init(PCMachineState *pcms, &ioreq_pfn, &bufioreq_pfn, &bufioreq_evtchn); if (rc < 0) { - hw_error("failed to get ioreq server info: error %d handle=" XC_INTERFACE_FMT, - errno, xen_xc); + error_report("failed to get ioreq server info: error %d handle=" XC_INTERFACE_FMT, + errno, xen_xc); + goto err; } DPRINTF("shared page at pfn %lx\n", ioreq_pfn); @@ -1249,8 +1243,9 @@ int xen_hvm_init(PCMachineState *pcms, state->shared_page = xc_map_foreign_range(xen_xc, xen_domid, XC_PAGE_SIZE, PROT_READ|PROT_WRITE, ioreq_pfn); if (state->shared_page == NULL) { - hw_error("map shared IO page returned error %d handle=" XC_INTERFACE_FMT, - errno, xen_xc); + error_report("map shared IO page returned error %d handle=" XC_INTERFACE_FMT, + errno, xen_xc); + goto err; } rc = xen_get_vmport_regs_pfn(xen_xc, xen_domid, &ioreq_pfn); @@ -1260,11 +1255,14 @@ int xen_hvm_init(PCMachineState *pcms, xc_map_foreign_range(xen_xc, xen_domid, XC_PAGE_SIZE, PROT_READ|PROT_WRITE, ioreq_pfn); if (state->shared_vmport_page == NULL) { - hw_error("map shared vmport IO page returned error %d handle=" - XC_INTERFACE_FMT, errno, xen_xc); + error_report("map shared vmport IO page returned error %d handle=" + XC_INTERFACE_FMT, errno, xen_xc); + goto err; } } else if (rc != -ENOSYS) { - hw_error("get vmport regs pfn returned error %d, rc=%d", errno, rc); + error_report("get vmport regs pfn returned error %d, rc=%d", + errno, rc); + goto err; } state->buffered_io_page = xc_map_foreign_range(xen_xc, xen_domid, @@ -1272,7 +1270,8 @@ int xen_hvm_init(PCMachineState *pcms, PROT_READ|PROT_WRITE, bufioreq_pfn); if (state->buffered_io_page == NULL) { - hw_error("map buffered IO page returned error %d", errno); + error_report("map buffered IO page returned error %d", errno); + goto err; } /* Note: cpus is empty at this point in init */ @@ -1280,8 +1279,9 @@ int xen_hvm_init(PCMachineState *pcms, rc = xen_set_ioreq_server_state(xen_xc, xen_domid, state->ioservid, true); if (rc < 0) { - hw_error("failed to enable ioreq server info: error %d handle=" XC_INTERFACE_FMT, - errno, xen_xc); + error_report("failed to enable ioreq server info: error %d handle=" XC_INTERFACE_FMT, + errno, xen_xc); + goto err; } state->ioreq_local_port = g_malloc0(max_cpus * sizeof (evtchn_port_t)); @@ -1291,8 +1291,8 @@ int xen_hvm_init(PCMachineState *pcms, rc = xc_evtchn_bind_interdomain(state->xce_handle, xen_domid, xen_vcpu_eport(state->shared_page, i)); if (rc == -1) { - fprintf(stderr, "shared evtchn %d bind error %d\n", i, errno); - return -1; + error_report("shared evtchn %d bind error %d", i, errno); + goto err; } state->ioreq_local_port[i] = rc; } @@ -1300,8 +1300,8 @@ int xen_hvm_init(PCMachineState *pcms, rc = xc_evtchn_bind_interdomain(state->xce_handle, xen_domid, bufioreq_evtchn); if (rc == -1) { - fprintf(stderr, "buffered evtchn bind error %d\n", errno); - return -1; + error_report("buffered evtchn bind error %d", errno); + goto err; } state->bufioreq_local_port = rc; @@ -1324,15 +1324,18 @@ int xen_hvm_init(PCMachineState *pcms, /* Initialize backend core & drivers */ if (xen_be_init() != 0) { - fprintf(stderr, "%s: xen backend core setup failed\n", __FUNCTION__); - return -1; + error_report("xen backend core setup failed"); + goto err; } xen_be_register("console", &xen_console_ops); xen_be_register("vkbd", &xen_kbdmouse_ops); xen_be_register("qdisk", &xen_blkdev_ops); xen_read_physmap(state); + return; - return 0; +err: + error_report("xen hardware virtual machine initialisation failed"); + exit(1); } void destroy_hvm_domain(bool reboot)