From nobody Mon Feb 9 20:10:45 2026 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=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1585335061; cv=none; d=zohomail.com; s=zohoarc; b=bVrfWV8eSgHJce36R8b5xmMz212D6qq7/2nLG4Ienz2snIjIDB/jjr95Vu4en886t/sqzrDTspcIIqmYpEkEzU92emWAK3i5pNsP8EYVvg13jciHR/SD7EEnarx6UM7GpBALkeFd1EF3JTilFEFhOcjXZYtq7BlUFYo+ecifBfc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585335061; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gaej7huESA3uufYv2UCPxiLF2FbJiwCLGYTRpcZ6bD0=; b=Mp5lT2fs6IPC1T3AktipTm4miM7wlS2Ry3h4+OOLLnPVZAqMJpIeCww2MppF8+l5GULJG0pGJBC0r0bygSov5STe7kbVnVPugCGn9YkdejVdvX6GhCDM9uRTzhCPjIJzgSRiqY8iHU/9Zh/fKJlCCi+Jvk022TGSQA+EVbGzTHM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 158533506185617.45042033234074; Fri, 27 Mar 2020 11:51:01 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jHu3l-0007zz-Py; Fri, 27 Mar 2020 18:50:25 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jHu3k-0007yx-9l for xen-devel@lists.xenproject.org; Fri, 27 Mar 2020 18:50:24 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id cebcf95e-705b-11ea-8a16-12813bfff9fa; Fri, 27 Mar 2020 18:50:20 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jHu3f-0008KU-V6; Fri, 27 Mar 2020 18:50:19 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=u2f063a87eabd5f.cbg10.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jHu3f-0007P4-MV; Fri, 27 Mar 2020 18:50:19 +0000 X-Inumbo-ID: cebcf95e-705b-11ea-8a16-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=gaej7huESA3uufYv2UCPxiLF2FbJiwCLGYTRpcZ6bD0=; b=bHjHZbkqZkzKiN2Lc5fRXj8hQL eF0RamGUkN0GEuYsgz9hsPwDUK8Fyq6aQO5iuL5IkCtCgHqDkehvBCoIlC0/n5/N09rvvkuMqyqDU 7+nztf19nwTZRmbLOHJS4jYIKKQMq+K16ZhKkzTCIOVQ0/CfgHCJ4qnL9kw42VxNLb6U=; From: Paul Durrant To: xen-devel@lists.xenproject.org Date: Fri, 27 Mar 2020 18:50:10 +0000 Message-Id: <20200327185012.1795-4-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200327185012.1795-1-paul@xen.org> References: <20200327185012.1795-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: [Xen-devel] [PATCH 3/5] tools/misc: add xen-ctx to present domain context 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: Ian Jackson , Wei Liu , Paul Durrant Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This tools is analogous to 'xen-hvmctx' which presents HVM context. Subsequent patches will add 'dump' functions when new records are introduced. Signed-off-by: Paul Durrant --- Cc: Ian Jackson Cc: Wei Liu --- .gitignore | 1 + tools/misc/Makefile | 4 ++ tools/misc/xen-ctx.c | 144 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 tools/misc/xen-ctx.c diff --git a/.gitignore b/.gitignore index 4ca679ddbc..72b807141f 100644 --- a/.gitignore +++ b/.gitignore @@ -206,6 +206,7 @@ tools/misc/cpuperf/cpuperf-xen tools/misc/xc_shadow tools/misc/xen_cpuperf tools/misc/xen-cpuid +tools/misc/xen-ctx tools/misc/xen-detect tools/misc/xen-diag tools/misc/xen-tmem-list-parse diff --git a/tools/misc/Makefile b/tools/misc/Makefile index 63947bfadc..6347bb24e9 100644 --- a/tools/misc/Makefile +++ b/tools/misc/Makefile @@ -30,6 +30,7 @@ INSTALL_SBIN +=3D xenpm INSTALL_SBIN +=3D xenwatchdogd INSTALL_SBIN +=3D xen-livepatch INSTALL_SBIN +=3D xen-diag +INSTALL_SBIN +=3D xen-ctx INSTALL_SBIN +=3D $(INSTALL_SBIN-y) =20 # Everything to be installed in a private bin/ @@ -108,6 +109,9 @@ xen-livepatch: xen-livepatch.o xen-diag: xen-diag.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) =20 +xen-ctx: xen-ctx.o + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) + xen-lowmemd: xen-lowmemd.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(L= DLIBS_libxenstore) $(APPEND_LDFLAGS) =20 diff --git a/tools/misc/xen-ctx.c b/tools/misc/xen-ctx.c new file mode 100644 index 0000000000..c31dd5d8e9 --- /dev/null +++ b/tools/misc/xen-ctx.c @@ -0,0 +1,144 @@ +/* + * xen-ctx.c + * + * Print out domain save records in a human-readable way. + * + * Copyright Amazon.com Inc. or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software= "), + * to deal in the Software without restriction, including without limitati= on + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +static void *buf =3D NULL; +static size_t len, off; + +#define READ(_x) do { = \ + if ( len - off < sizeof (_x) ) = \ + { = \ + fprintf(stderr, "Error: need another %lu bytes, only %lu available= ",\ + sizeof(_x), len - off); = \ + exit(1); = \ + } = \ + memcpy(&(_x), buf + off, sizeof (_x)); = \ + off +=3D sizeof (_x); = \ +} while (0) + +static void dump_header(void) +{ + DOMAIN_SAVE_TYPE(HEADER) h; + READ(h); + printf(" HEADER: magic %#x, version %u\n", + h.magic, h.version); +} + +static void dump_end(void) +{ + DOMAIN_SAVE_TYPE(END) e; + READ(e); + printf(" END\n"); +} + +int main(int argc, char **argv) +{ + uint32_t domid; + unsigned int entry; + xc_interface *xch; + int rc; + + if ( argc !=3D 2 || !argv[1] || (rc =3D atoi(argv[1])) < 0 ) + { + fprintf(stderr, "usage: %s \n", argv[0]); + exit(1); + } + domid =3D rc; + + xch =3D xc_interface_open(0,0,0); + if ( !xch ) + { + fprintf(stderr, "Error: can't open libxc handle\n"); + exit(1); + } + + rc =3D xc_domain_getcontext(xch, domid, 0, 0, 0); + if ( rc < 0 ) + { + fprintf(stderr, "Error: can't get record length for dom %u: %s\n", + domid, strerror(errno)); + exit(1); + } + len =3D rc; + + buf =3D malloc(len); + if ( !buf ) + { + fprintf(stderr, "Error: can't allocate %lu bytes\n", len); + exit(1); + } + + rc =3D xc_domain_getcontext(xch, domid, 0, buf, len); + if ( rc < 0 ) + { + fprintf(stderr, "Error: can't get domain record for dom %u: %s\n", + domid, strerror(errno)); + exit(1); + } + len =3D rc; + off =3D 0; + + printf("Domain save records for d%u\n", domid); + + entry =3D 0; + for (;;) { + struct domain_save_descriptor desc; + + READ(desc); + printf("[%u] type %u instance %u, length %u\n", entry++, + desc.typecode, desc.instance, desc.length); + + switch (desc.typecode) + { + case DOMAIN_SAVE_CODE(HEADER): dump_header(); break; + case DOMAIN_SAVE_CODE(END): dump_end(); return 0; + default: + printf("Unknown type %u: skipping\n", desc.typecode); + off +=3D desc.length; + break; + } + } +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.20.1