From nobody Fri Apr 26 11:21:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1605088932; cv=none; d=zohomail.com; s=zohoarc; b=V5OxtDonipBS/WnSeJ7EQexd22cXpn2g3K9nZVuohuOx+PSXPmmGaAB8zSKLcvVygmafpKxdE0zkIq8MoMp99pcYkhWZeMz2HRY/nQ8OfB5DUNOow6meLVgMyypMtfmSnK/nG+poB5SJNGe2wmxZKrIatKMLjzq8x8f7c2Ys8CQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605088932; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=KZhvr+aHJsAIl4S2AH81gc6u7VXj74Lri8KHt68rkDg=; b=m57B5eWYgKg6oxxsV9cgoFX+4GziscMQ3vCHWy0NFzcMPdPuv+gj4xwseWPjogf/jh9oVz4xGv0JNFydrxPUIHm7ObRGMcDPT7eG55BFsfeFZ07+rsg6C5uQzIcn3ubbIvNi12AUderXqRC5LTbbF/duKVkhxSHtpgkhiyy5Wd4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1605088932408112.11758963150066; Wed, 11 Nov 2020 02:02:12 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.24586.51897 (Exim 4.92) (envelope-from ) id 1kcmwn-0006nP-15; Wed, 11 Nov 2020 10:01:49 +0000 Received: by outflank-mailman (output) from mailman id 24586.51897; Wed, 11 Nov 2020 10:01:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kcmwm-0006nI-UO; Wed, 11 Nov 2020 10:01:48 +0000 Received: by outflank-mailman (input) for mailman id 24586; Wed, 11 Nov 2020 10:01:47 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kcmwl-0006nD-EF for xen-devel@lists.xenproject.org; Wed, 11 Nov 2020 10:01:47 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0c8eb5f3-ef88-44dc-b668-8c19ca45da39; Wed, 11 Nov 2020 10:01:46 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B3A5FAC23; Wed, 11 Nov 2020 10:01:45 +0000 (UTC) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kcmwl-0006nD-EF for xen-devel@lists.xenproject.org; Wed, 11 Nov 2020 10:01:47 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0c8eb5f3-ef88-44dc-b668-8c19ca45da39; Wed, 11 Nov 2020 10:01:46 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B3A5FAC23; Wed, 11 Nov 2020 10:01:45 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0c8eb5f3-ef88-44dc-b668-8c19ca45da39 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1605088905; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=KZhvr+aHJsAIl4S2AH81gc6u7VXj74Lri8KHt68rkDg=; b=XJBwr9YOkcmTzxprZy6Ug8GISMnzb+t/rr35/nudQCWCPCqa7sTa1Kpcus/IjmGXrlz+7E 0PC77OTnsOo0R4R4s8DJvo0V+EBVHrgteESMiN7t2VHbbDIq+lFZnOsVA6piHrVL+U+FCA BYMbEVMYx8RdUJH2extVX8lLm3zccKU= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Ian Jackson , Wei Liu Subject: [PATCH v2] tools/libs/ctrl: fix dumping of ballooned guest Date: Wed, 11 Nov 2020 11:01:43 +0100 Message-Id: <20201111100143.13820-1-jgross@suse.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" A guest with memory < maxmem often can't be dumped via xl dump-core without an error message today: xc: info: exceeded nr_pages (262144) losing pages In case the last page of the guest isn't allocated the loop in xc_domain_dumpcore_via_callback() will always spit out this message, as the number of already dumped pages is tested before the next page is checked to be valid. The guest's p2m_size might be lower than expected, so this should be tested in order to avoid reading past the end of it. The guest might use high bits in p2m entries to flag special cases like foreign mappings. Entries with an MFN larger than the highest MFN of the host should be skipped. Signed-off-by: Juergen Gross --- tools/libs/ctrl/xc_core.c | 42 +++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/tools/libs/ctrl/xc_core.c b/tools/libs/ctrl/xc_core.c index e8c6fb96f9..b47ab2f6d8 100644 --- a/tools/libs/ctrl/xc_core.c +++ b/tools/libs/ctrl/xc_core.c @@ -439,6 +439,7 @@ xc_domain_dumpcore_via_callback(xc_interface *xch, unsigned long i; unsigned long j; unsigned long nr_pages; + unsigned long max_mfn; =20 xc_core_memory_map_t *memory_map =3D NULL; unsigned int nr_memory_map; @@ -577,6 +578,10 @@ xc_domain_dumpcore_via_callback(xc_interface *xch, &p2m, &dinfo->p2m_size); if ( sts !=3D 0 ) goto out; + + sts =3D xc_maximum_ram_page(xch, &max_mfn); + if ( sts !=3D 0 ) + goto out; } else { @@ -818,19 +823,12 @@ xc_domain_dumpcore_via_callback(xc_interface *xch, { uint64_t gmfn; void *vaddr; - =20 - if ( j >=3D nr_pages ) - { - /* - * When live dump-mode (-L option) is specified, - * guest domain may increase memory. - */ - IPRINTF("exceeded nr_pages (%ld) losing pages", nr_pages); - goto copy_done; - } =20 if ( !auto_translated_physmap ) { + if ( i >=3D dinfo->p2m_size ) + break; + if ( dinfo->guest_width >=3D sizeof(unsigned long) ) { if ( dinfo->guest_width =3D=3D sizeof(unsigned long) ) @@ -846,6 +844,14 @@ xc_domain_dumpcore_via_callback(xc_interface *xch, if ( gmfn =3D=3D (uint32_t)INVALID_PFN ) continue; } + if ( gmfn > max_mfn ) + continue; + + if ( j >=3D nr_pages ) + { + j++; + continue; + } =20 p2m_array[j].pfn =3D i; p2m_array[j].gmfn =3D gmfn; @@ -855,6 +861,12 @@ xc_domain_dumpcore_via_callback(xc_interface *xch, if ( !xc_core_arch_gpfn_may_present(&arch_ctxt, i) ) continue; =20 + if ( j >=3D nr_pages ) + { + j++; + continue; + } + gmfn =3D i; pfn_array[j] =3D i; } @@ -879,7 +891,15 @@ xc_domain_dumpcore_via_callback(xc_interface *xch, } } =20 -copy_done: + if ( j > nr_pages ) + { + /* + * When live dump-mode (-L option) is specified, + * guest domain may increase memory. + */ + IPRINTF("exceeded nr_pages (%ld) losing %ld pages", nr_pages, j - = nr_pages); + } + sts =3D dump_rtn(xch, args, dump_mem_start, dump_mem - dump_mem_start); if ( sts !=3D 0 ) goto out; --=20 2.26.2