From nobody Fri Apr 26 00:25:37 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 header.i=@amazon.de; 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=quarantine dis=none) header.from=amazon.de ARC-Seal: i=1; a=rsa-sha256; t=1605277307; cv=none; d=zohomail.com; s=zohoarc; b=inMZXyVzGB2wqWaDudFaJa79dgJe+UoqaQPzfOlld+sWXSrLuXr32ymmwvVz7TujjqsrjMLRnluNCspsq0FfIvAqxGTC/X7XpUjFRE2savJVs17jRLjbeEL3vGAn1CmwmcZQqyaouELXXcpxCDz87Rb8gMh+F6esDPK//aAeEXs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605277307; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=uEC5EXOc4YcDJzP4U01LmoW19H30dbThY1jdb+RYew8=; b=gK/P7AaY/v+s9TP+U+Sx5grhHXs9GJ7LFLSRDg2tTl1siWZLtqpKpgCLPJ92v/+I9C4S17BfzgMzDPNcbC/m7+6szAWw/IEblXs5tX5ofq2zT3co7NjmjVRgZh3eVow9/GaThomdQfJnv1/eqHXrMWjDIh+eSvF7/JiW09BFqpk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@amazon.de; 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=quarantine 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 160527730778055.78450482048845; Fri, 13 Nov 2020 06:21:47 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.26515.54925 (Exim 4.92) (envelope-from ) id 1kdZwl-0000Vm-Lt; Fri, 13 Nov 2020 14:21:03 +0000 Received: by outflank-mailman (output) from mailman id 26515.54925; Fri, 13 Nov 2020 14:21:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kdZwl-0000Vf-IE; Fri, 13 Nov 2020 14:21:03 +0000 Received: by outflank-mailman (input) for mailman id 26515; Fri, 13 Nov 2020 14:19:25 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kdZvA-0008EU-NP for xen-devel@lists.xenproject.org; Fri, 13 Nov 2020 14:19:25 +0000 Received: from smtp-fw-6002.amazon.com (unknown [52.95.49.90]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 21da5738-23df-4304-a15c-d31f7b61fd64; Fri, 13 Nov 2020 14:19:23 +0000 (UTC) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-4e7c8266.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 13 Nov 2020 14:19:01 +0000 Received: from EX13D37EUB004.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-2c-4e7c8266.us-west-2.amazon.com (Postfix) with ESMTPS id F3D6BA0819; Fri, 13 Nov 2020 14:19:00 +0000 (UTC) Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX13D37EUB004.ant.amazon.com (10.43.166.187) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 13 Nov 2020 14:18:59 +0000 Received: from dev-dsk-doebel-2a-b41c32f5.us-west-2.amazon.com (172.19.225.92) by mail-relay.amazon.com (10.43.61.243) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 13 Nov 2020 14:18:58 +0000 Received: by dev-dsk-doebel-2a-b41c32f5.us-west-2.amazon.com (Postfix, from userid 3160037) id 1FE8EA27B6; Fri, 13 Nov 2020 14:18:57 +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 1kdZvA-0008EU-NP for xen-devel@lists.xenproject.org; Fri, 13 Nov 2020 14:19:25 +0000 Received: from smtp-fw-6002.amazon.com (unknown [52.95.49.90]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 21da5738-23df-4304-a15c-d31f7b61fd64; Fri, 13 Nov 2020 14:19:23 +0000 (UTC) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-4e7c8266.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 13 Nov 2020 14:19:01 +0000 Received: from EX13D37EUB004.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-2c-4e7c8266.us-west-2.amazon.com (Postfix) with ESMTPS id F3D6BA0819; Fri, 13 Nov 2020 14:19:00 +0000 (UTC) Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX13D37EUB004.ant.amazon.com (10.43.166.187) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 13 Nov 2020 14:18:59 +0000 Received: from dev-dsk-doebel-2a-b41c32f5.us-west-2.amazon.com (172.19.225.92) by mail-relay.amazon.com (10.43.61.243) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 13 Nov 2020 14:18:58 +0000 Received: by dev-dsk-doebel-2a-b41c32f5.us-west-2.amazon.com (Postfix, from userid 3160037) id 1FE8EA27B6; Fri, 13 Nov 2020 14:18:57 +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 Sender: "Xen-devel" X-Inumbo-ID: 21da5738-23df-4304-a15c-d31f7b61fd64 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1605277163; x=1636813163; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=uEC5EXOc4YcDJzP4U01LmoW19H30dbThY1jdb+RYew8=; b=rG5BmM2/12ebjmGn0qKQtjHPY3qSIbT8sydr905NI8H8upBsgWq+GNqY SdQpZ9iWwx/X2J4N5M082D9c5CPFAFHmKSvSfOUuEzxX9YiJlot7NBK1l 4nvbhDCzTZjoxmapaEsMiu6rT/Ytei4VA+E5z3Vo9PLLcXOMDLfMnda1Z c=; X-IronPort-AV: E=Sophos;i="5.77,475,1596499200"; d="scan'208";a="64882752" From: Bjoern Doebel To: CC: Julien Grall , Eslam Elnikety , Bjoern Doebel , Ian Jackson , Wei Liu Subject: [XEN PATCH] tools/xenstore: Log xenstored build ID on startup Date: Fri, 13 Nov 2020 14:18:23 +0000 Message-ID: <20201113141823.58712-1-doebel@amazon.de> X-Mailer: git-send-email 2.16.6 MIME-Version: 1.0 Precedence: Bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @amazon.de) Right now we do not have a mechanism to determine the version of the currently running xenstored at runtime. As xenstored runs throughout the lifetime of a Xen host, this may lead to problems when newer user space builds are staged. Then, the running xenstored will no longer match the version of the installed xenstored. To allow users to always identify the running version of xenstored, add a linker-generated unique build ID to every xenstored build. Add functionality to log this build ID into a file upon service startup. Signed-off-by: Bjoern Doebel Reviewed-by: Martin Mazein Reviewed-by: Paul Durrant --- tools/hotplug/Linux/launch-xenstore.in | 2 +- tools/xenstore/Makefile | 4 +++ tools/xenstore/buildid_symbols.ld | 10 +++++++ tools/xenstore/xenstored_core.c | 8 ++++++ tools/xenstore/xenstored_core.h | 3 ++ tools/xenstore/xenstored_minios.c | 4 +++ tools/xenstore/xenstored_posix.c | 52 ++++++++++++++++++++++++++++++= ++++ 7 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 tools/xenstore/buildid_symbols.ld diff --git a/tools/hotplug/Linux/launch-xenstore.in b/tools/hotplug/Linux/l= aunch-xenstore.in index 991dec8d25..a6f2254030 100644 --- a/tools/hotplug/Linux/launch-xenstore.in +++ b/tools/hotplug/Linux/launch-xenstore.in @@ -62,7 +62,7 @@ test -f @CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons && . @C= ONFIG_DIR@/@CONFIG_LEAF } =20 echo -n Starting $XENSTORED... - $XENSTORED --pid-file @XEN_RUN_DIR@/xenstored.pid $XENSTORED_ARGS + $XENSTORED --pid-file @XEN_RUN_DIR@/xenstored.pid --buildid-file @XEN_RUN= _DIR@/xenstored.buildid $XENSTORED_ARGS =20 systemd-notify --booted 2>/dev/null || timeout_xenstore $XENSTORED || exi= t 1 =20 diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile index 9a0f0d012d..c63350980b 100644 --- a/tools/xenstore/Makefile +++ b/tools/xenstore/Makefile @@ -66,6 +66,10 @@ $(XENSTORED_OBJS): CFLAGS +=3D $(SYSTEMD_CFLAGS) xenstored: LDFLAGS +=3D $(SYSTEMD_LIBS) endif =20 +# xenstored: enforce creation of a buildID section and use a linker +# script to add additional symbols around that section +xenstored: LDFLAGS +=3D -Wl,--build-id=3Dsha1 -Wl,-T,buildid_symbols.ld + $(XENSTORED_OBJS): CFLAGS +=3D $(CFLAGS_libxengnttab) =20 xenstored: $(XENSTORED_OBJS) diff --git a/tools/xenstore/buildid_symbols.ld b/tools/xenstore/buildid_sym= bols.ld new file mode 100644 index 0000000000..d74024c4e9 --- /dev/null +++ b/tools/xenstore/buildid_symbols.ld @@ -0,0 +1,10 @@ +SECTIONS +{ + __buildid_note_section =3D . ; + .note.gnu.build-id : + { + *(.note.gnu.build-id) + } + __buildid_end =3D . ; +} +INSERT AFTER .data diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index b4be374d3f..c6f107bdd9 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -1844,6 +1844,7 @@ static void usage(void) =20 =20 static struct option options[] =3D { + { "buildid-file", 1, NULL, 'B' }, { "no-domain-init", 0, NULL, 'D' }, { "entry-nb", 1, NULL, 'E' }, { "pid-file", 1, NULL, 'F' }, @@ -1875,12 +1876,16 @@ int main(int argc, char *argv[]) bool outputpid =3D false; bool no_domain_init =3D false; const char *pidfile =3D NULL; + const char *buildid_file =3D NULL; int timeout; =20 =20 while ((opt =3D getopt_long(argc, argv, "DE:F:HNPS:t:T:RVW:", options, NULL)) !=3D -1) { switch (opt) { + case 'B': + buildid_file =3D optarg; + break; case 'D': no_domain_init =3D true; break; @@ -1948,6 +1953,9 @@ int main(int argc, char *argv[]) if (pidfile) write_pidfile(pidfile); =20 + if (buildid_file) + write_buildid_file(buildid_file); + /* Talloc leak reports go to stderr, which is closed if we fork. */ if (!dofork) talloc_enable_leak_report_full(); diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_cor= e.h index 1df6ad94ab..712280626c 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -193,6 +193,9 @@ void xenbus_notify_running(void); /* Write out the pidfile */ void write_pidfile(const char *pidfile); =20 +/* Write the buildid file */ +void write_buildid_file(const char *buildidfile); + /* Fork but do not close terminal FDs */ void daemonize(void); /* Close stdin/stdout/stderr to complete daemonize */ diff --git a/tools/xenstore/xenstored_minios.c b/tools/xenstore/xenstored_m= inios.c index c94493e52a..ef1151aee4 100644 --- a/tools/xenstore/xenstored_minios.c +++ b/tools/xenstore/xenstored_minios.c @@ -24,6 +24,10 @@ void write_pidfile(const char *pidfile) { } =20 +void write_buildid_file(const char *buildid_file) +{ +} + void daemonize(void) { } diff --git a/tools/xenstore/xenstored_posix.c b/tools/xenstore/xenstored_po= six.c index 1f9603fea2..ec017611d6 100644 --- a/tools/xenstore/xenstored_posix.c +++ b/tools/xenstore/xenstored_posix.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include =20 @@ -48,6 +49,57 @@ void write_pidfile(const char *pidfile) close(fd); } =20 +/* + * We don't have a working elf.h available here, so let's define our very = own + * data structs and accessor macros for ELF notes. + * + * https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-18048.html: + * For 64=E2=80=93bit objects and 32=E2=80=93bit objects, each entry is an= array of 4-byte + * words in the format of the target processor. + */ +typedef struct +{ + uint32_t namesz; + uint32_t descsz; + uint32_t type; +} elf_note_hdr; + +/* ELF Note accessors, copied from Xen's elf.h */ +#define ELFNOTE_ALIGN(_n_) (((_n_)+3)&~3) +#define ELFNOTE_NAME(_n_) ((char*)(_n_) + sizeof(*(_n_))) +#define ELFNOTE_DESC(_n_) (ELFNOTE_NAME(_n_) + ELFNOTE_ALIGN((_n_)->namesz= )) +/* GNU LD: type =3D=3D note (NT_GNU_BUILD_ID as in + * https://sourceware.org/ml/binutils/2007-07/msg00012.html)*/ +#define NT_GNU_BUILD_ID 3 + + +void write_buildid_file(const char *buildid_file) +{ + unsigned int i =3D 0; + FILE *fdesc; + extern elf_note_hdr __buildid_note_section; + unsigned int id_length =3D __buildid_note_section.descsz; + char* desc =3D ELFNOTE_DESC(&__buildid_note_section); + + if (__buildid_note_section.type !=3D NT_GNU_BUILD_ID) + barf("Expected GNU_BUILDID note, but found type '%d'", + __buildid_note_section.type); + + fdesc =3D fopen(buildid_file, "w+"); + if (!fdesc) + barf_perror("Error opening buildid file %s", buildid_file); + + /* We exit silently if daemon already running. */ + if (lockf(fileno(fdesc), F_TLOCK, 0) =3D=3D -1) + exit(0); + + for (i =3D 0; i < id_length; ++i) + fprintf(fdesc, "%02x", (unsigned char)desc[i]); + fprintf(fdesc, "\n"); + + fclose(fdesc); +} + /* Stevens. */ void daemonize(void) { --=20 2.16.6 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879