From patchwork Wed Mar 20 15:43:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 10862131 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3829714DE for ; Wed, 20 Mar 2019 15:45:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C60E29D2B for ; Wed, 20 Mar 2019 15:45:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1018D283AF; Wed, 20 Mar 2019 15:45:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ABDC128AC3 for ; Wed, 20 Mar 2019 15:45:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h6dNY-0002Gy-To; Wed, 20 Mar 2019 15:43:44 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h6dNX-0002Gr-21 for xen-devel@lists.xenproject.org; Wed, 20 Mar 2019 15:43:43 +0000 X-Inumbo-ID: ef4e51d9-4b26-11e9-bc90-bc764e045a96 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id ef4e51d9-4b26-11e9-bc90-bc764e045a96; Wed, 20 Mar 2019 15:43:41 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.60,249,1549929600"; d="scan'208";a="81143064" From: Wei Liu To: Date: Wed, 20 Mar 2019 15:43:38 +0000 Message-ID: <20190320154338.24124-1-wei.liu2@citrix.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2] libxc: fix HVM core dump X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Igor Druzhinin , Wei Liu , Andrew Cooper , Ian Jackson , Jan Beulich Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP f969bc9fc96 forbid get_address_size call on HVM guests, because that didn't make sense. It broke core dump functionality on HVM because libxc unconditionally asked for guest width. Force guest_width to a sensible value. Reported-by: Igor Druzhinin Signed-off-by: Wei Liu Acked-by: Ian Jackson --- Cc: Ian Jackson Cc: Jan Beulich Cc: Andrew Cooper Cc: Igor Druzhinin Cc: Juergen Gross Juergen, this is probably too late for 4.12, but you can at least add a release note somewhere. Ian, please backport this to 4.12. --- tools/libxc/xc_core.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/tools/libxc/xc_core.c b/tools/libxc/xc_core.c index e581905ba9..2ee1d205b4 100644 --- a/tools/libxc/xc_core.c +++ b/tools/libxc/xc_core.c @@ -459,12 +459,6 @@ xc_domain_dumpcore_via_callback(xc_interface *xch, struct xc_core_section_headers *sheaders = NULL; Elf64_Shdr *shdr; - if ( xc_domain_get_guest_width(xch, domid, &dinfo->guest_width) != 0 ) - { - PERROR("Could not get address size for domain"); - return sts; - } - xc_core_arch_context_init(&arch_ctxt); if ( (dump_mem_start = malloc(DUMP_INCREMENT*PAGE_SIZE)) == NULL ) { @@ -487,6 +481,40 @@ xc_domain_dumpcore_via_callback(xc_interface *xch, } auto_translated_physmap = xc_core_arch_auto_translated_physmap(&info); + if ( !auto_translated_physmap ) + + { + if ( xc_domain_get_guest_width(xch, domid, &dinfo->guest_width) != 0 ) + { + PERROR("Could not get address size for domain"); + goto out; + } + } + else + { + /* + * Autotranslated guest never sets guest width in the first + * place. Force guest_width to be sizeof(unsigned long) so + * code below functions properly. + * + * Here is why this is correct. + * + * 1. Before f969bc9fc, xc_domain_get_guest_width for HVM (x86 + * and ARM) always returned hypervisor's idea of + * sizeof(unsigned long). + * + * 2. There has never been a situation in which hypervisor's + * word width is smaller than toolstack domain's (i.e. no + * 32bit hypervisor + 64bit toolstack). + * + * Predicates in code test guest_width against toolstack + * domain's sizeof(unsigned long), so setting guest_width to + * toolstack domain's idea of sizeof(unsigned long) matches + * the original behaviour for HVM guests. + */ + dinfo->guest_width = sizeof(unsigned long); + } + if ( domid != info.domid ) { PERROR("Domain %d does not exist", domid);