From nobody Mon Feb 9 22:39:03 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=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 ARC-Seal: i=1; a=rsa-sha256; t=1597746662; cv=none; d=zohomail.com; s=zohoarc; b=DTpgqvYpFKX6YKmaU2y/4M770B7s8I/Ro5udRk1e7D/6C4OZvh76IaaFYbrpU3Ufpr8XLe3EbLQG/kaHyOp98fRIni+3gju0VtoFBc0/fysZcuPyBIlX5LptxODGTskA1RF9KDkPlf6tNUnIMeQf7lEn71jRvzxH4tZZDCoJN3w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597746662; 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=m3L0Qwt75VQeY/gR+JcBF0R6pPuj2jl9noLoJU874z0=; b=dO2dliU2wNHu4uGdojmNYm7wQy+p+FXCcR77YGE8cITf3lavTc3dTN/SKcKSCkAKMoa/qrAd93pV36U8HdZHlYDXdO8mwvoHiFs1uqCpc/soTwUNZvUuw31jomIzKOXCzc+YRrECjPZIMaTFCcJLGi/3MdW1cDKuPTf9ISuToPs= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1597746662578437.78189745379586; Tue, 18 Aug 2020 03:31:02 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k7yt8-00061N-S8; Tue, 18 Aug 2020 10:30:42 +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.92) (envelope-from ) id 1k7yt7-0005zo-A8 for xen-devel@lists.xenproject.org; Tue, 18 Aug 2020 10:30:41 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 32d6f7b2-af59-451d-b2b4-cf93ea382235; Tue, 18 Aug 2020 10:30:40 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k7yt5-00013Z-8H; Tue, 18 Aug 2020 10:30:39 +0000 Received: from host31-48-92-96.range31-48.btcentralplus.com ([31.48.92.96] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k7yt5-0003Rw-0g; Tue, 18 Aug 2020 10:30:39 +0000 X-Inumbo-ID: 32d6f7b2-af59-451d-b2b4-cf93ea382235 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; bh=m3L0Qwt75VQeY/gR+JcBF0R6pPuj2jl9noLoJU874z0=; b=5vTI/zq4NveV7yvK7ihnFTm+bx vvSiBcRL4GRFuruDloOi9F13/jjrV4ZKpNslyrTVyK2PD7CwnSy71MnOB/8v8buYMJD4ndiBGVKAk kXV/pXkd4A6qSsCsK3MykkiWaE1SJi2u+1Xj10fqblRi18XwCLXooYky8fMFvSMBWIr0=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Andrew Cooper , Wei Liu Subject: [PATCH v7 3/9] tools/misc: add xen-domctx to present domain context Date: Tue, 18 Aug 2020 11:30:26 +0100 Message-Id: <20200818103032.3050-4-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200818103032.3050-1-paul@xen.org> References: <20200818103032.3050-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @xen.org) Content-Type: text/plain; charset="utf-8" This tool 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 Acked-by: Ian Jackson --- Cc: Andrew Cooper Cc: Wei Liu NOTE: Ian requested ack from Andrew v3: - Re-worked to avoid copying onto stack - Added optional typecode and instance arguments v2: - Change name from 'xen-ctx' to 'xen-domctx' --- .gitignore | 1 + tools/misc/Makefile | 4 + tools/misc/xen-domctx.c | 200 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 tools/misc/xen-domctx.c diff --git a/.gitignore b/.gitignore index 36ce2ea104..7e5dccacce 100644 --- a/.gitignore +++ b/.gitignore @@ -211,6 +211,7 @@ tools/misc/xen_cpuperf tools/misc/xen-cpuid tools/misc/xen-detect tools/misc/xen-diag +tools/misc/xen-domctx tools/misc/xen-tmem-list-parse tools/misc/xen-livepatch tools/misc/xenperf diff --git a/tools/misc/Makefile b/tools/misc/Makefile index 9fdb13597f..13e37402e2 100644 --- a/tools/misc/Makefile +++ b/tools/misc/Makefile @@ -31,6 +31,7 @@ INSTALL_SBIN +=3D xenpm INSTALL_SBIN +=3D xenwatchdogd INSTALL_SBIN +=3D xen-livepatch INSTALL_SBIN +=3D xen-diag +INSTALL_SBIN +=3D xen-domctx INSTALL_SBIN +=3D $(INSTALL_SBIN-y) =20 # Everything to be installed in a private bin/ @@ -114,6 +115,9 @@ xen-livepatch: xen-livepatch.o xen-diag: xen-diag.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) =20 +xen-domctx: xen-domctx.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-domctx.c b/tools/misc/xen-domctx.c new file mode 100644 index 0000000000..243325dfce --- /dev/null +++ b/tools/misc/xen-domctx.c @@ -0,0 +1,200 @@ +/* + * xen-domctx.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 GET_PTR(_x) = \ + do { = \ + if ( len - off < sizeof(*(_x)) ) = \ + { = \ + fprintf(stderr, = \ + "error: need another %lu bytes, only %lu available\n",= \ + sizeof(*(_x)), len - off); = \ + exit(1); = \ + } = \ + (_x) =3D buf + off; = \ + } while (false); + +static void dump_header(void) +{ + DOMAIN_SAVE_TYPE(HEADER) *h; + + GET_PTR(h); + + printf(" HEADER: magic %#x, version %u\n", + h->magic, h->version); + +} + +static void dump_end(void) +{ + DOMAIN_SAVE_TYPE(END) *e; + + GET_PTR(e); + + printf(" END\n"); +} + +static void usage(const char *prog) +{ + fprintf(stderr, "usage: %s [ [ ]]\n", + prog); + exit(1); +} + +int main(int argc, char **argv) +{ + char *s, *e; + long domid; + long typecode =3D -1; + long instance =3D -1; + unsigned int entry; + xc_interface *xch; + int rc; + + if ( argc < 2 || argc > 4 ) + usage(argv[0]); + + s =3D e =3D argv[1]; + domid =3D strtol(s, &e, 0); + + if ( *s =3D=3D '\0' || *e !=3D '\0' || + domid < 0 || domid >=3D DOMID_FIRST_RESERVED ) + { + fprintf(stderr, "invalid domid '%s'\n", s); + exit(1); + } + + if ( argc >=3D 3 ) + { + s =3D e =3D argv[2]; + typecode =3D strtol(s, &e, 0); + + if ( *s =3D=3D '\0' || *e !=3D '\0' ) + { + fprintf(stderr, "invalid typecode '%s'\n", s); + exit(1); + } + } + + if ( argc =3D=3D 4 ) + { + s =3D e =3D argv[3]; + instance =3D strtol(s, &e, 0); + + if ( *s =3D=3D '\0' || *e !=3D '\0' ) + { + fprintf(stderr, "invalid instance '%s'\n", s); + exit(1); + } + } + + 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, NULL, &len); + if ( rc < 0 ) + { + fprintf(stderr, "error: can't get record length for dom %lu: %s\n", + domid, strerror(errno)); + exit(1); + } + + 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, buf, &len); + if ( rc < 0 ) + { + fprintf(stderr, "error: can't get domain record for dom %lu: %s\n", + domid, strerror(errno)); + exit(1); + } + off =3D 0; + + entry =3D 0; + for ( ; ; ) + { + struct domain_save_descriptor *desc; + + GET_PTR(desc); + + off +=3D sizeof(*desc); + + if ( (typecode < 0 || typecode =3D=3D desc->typecode) && + (instance < 0 || instance =3D=3D desc->instance) ) + { + 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(); break; + default: + printf("Unknown type %u: skipping\n", desc->typecode); + break; + } + } + + if ( desc->typecode =3D=3D DOMAIN_SAVE_CODE(END) ) + break; + + off +=3D desc->length; + } + + return 0; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.20.1