From patchwork Thu Nov 23 11:23:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13466130 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 56DB9C624B4 for ; Thu, 23 Nov 2023 11:24:09 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.639617.997159 (Exim 4.92) (envelope-from ) id 1r67oG-0001EJ-ME; Thu, 23 Nov 2023 11:23:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 639617.997159; Thu, 23 Nov 2023 11:23:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r67oG-0001EC-JS; Thu, 23 Nov 2023 11:23:52 +0000 Received: by outflank-mailman (input) for mailman id 639617; Thu, 23 Nov 2023 11:23:51 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r67oF-0000zG-Bx for xen-devel@lists.xenproject.org; Thu, 23 Nov 2023 11:23:51 +0000 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [2a00:1450:4864:20::331]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c6375b7e-89f2-11ee-9b0e-b553b5be7939; Thu, 23 Nov 2023 12:23:49 +0100 (CET) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4083f61322fso5546985e9.1 for ; Thu, 23 Nov 2023 03:23:49 -0800 (PST) Received: from localhost ([213.195.113.99]) by smtp.gmail.com with ESMTPSA id o7-20020a05600c510700b0040b36ad5413sm1517387wms.46.2023.11.23.03.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 03:23:48 -0800 (PST) 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: c6375b7e-89f2-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1700738629; x=1701343429; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wo3ZoyDOsm6vfE7b7gB3JvtmVqfZ9c23rBT3rNX08wQ=; b=mDwidpTF5Bu4Qqn5Su56rxY/jjV5aKgqZb6Y0Pxf2rwEH8lww4IJqPQWFNxwnxIEcZ tZm+BiR7TUllRurQjB4RxswtcJXVo85TucsfudWxOhWsGtFxFt+45V0mqtMNag3Yry/q qwNS4xNqiG8vySrlUgoOgLOg/HyKvnOdhnpFM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700738629; x=1701343429; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wo3ZoyDOsm6vfE7b7gB3JvtmVqfZ9c23rBT3rNX08wQ=; b=swQeVllLt4Yoe4rkXu5lgoF0OhIzqVQ3tym9zby2W6H0ZyZbfe58oy/Lze7gID5AbC KLf87HkVKihQuqow9q+4Fgjh5Q0oSFyPNJUBfHQXBgVNaRlo15iYNon/jVGaTrR5fC2g tZqZrJvZ//xh72duGZluPXtaCTGeOuDC6cuRxh4CG2QhIxLY6onmrB/NlgZ4xyDPoRoh q+eP2quv8H4giUmMJcqkZg9QaXTTLe8L39yEx2A9Fy4gWruTj4SL3iOEJygMKh/AkUOd njChRXVQBC8QbKx+TEB6d0RyTCY64KPl0+6n8lTDCW0f0/Qnbn0JXN4HSt4KJkleUskf NwPw== X-Gm-Message-State: AOJu0Yy2/XzAALZ+yUPy503SrtnGmX6Bp1C31ANVfch6KpIQwdRXM0rT ZI6uA0bXKrEtm1ctawNAXyH4dglmW8CRLkMfsgg= X-Google-Smtp-Source: AGHT+IGf5xv8yJqt4BMhVCmerRVLtFKzG4hXzB4fOythjOMK4qB54YinEYQ8zZkHczq1xlv4H0okLA== X-Received: by 2002:a05:600c:1d03:b0:408:3696:3d51 with SMTP id l3-20020a05600c1d0300b0040836963d51mr4147460wms.4.1700738628892; Thu, 23 Nov 2023 03:23:48 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Doug Goldstein , Stefano Stabellini Subject: [PATCH 1/3] automation/alpine: add elfutils-dev and coreutils for livepatch-build-tools Date: Thu, 23 Nov 2023 12:23:36 +0100 Message-ID: <20231123112338.14477-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231123112338.14477-1-roger.pau@citrix.com> References: <20231123112338.14477-1-roger.pau@citrix.com> MIME-Version: 1.0 In preparation for adding some livepatch-build-tools test update the Alpine container to also install elfutils-dev, coreutils and GNU awk. Signed-off-by: Roger Pau Monné --- I don't very much like to add coreutils and gawk, as it's also good to test that we can build Xen with Busybox, but I also got tired of adjusting livepatch-build-tools. --- automation/build/alpine/3.18.dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/automation/build/alpine/3.18.dockerfile b/automation/build/alpine/3.18.dockerfile index 4ae9cb5e9e30..fa6789347d87 100644 --- a/automation/build/alpine/3.18.dockerfile +++ b/automation/build/alpine/3.18.dockerfile @@ -47,3 +47,7 @@ RUN apk --no-cache add \ libcap-ng-dev \ ninja \ pixman-dev \ + # livepatch-tools deps + elfutils-dev \ + coreutils \ + gawk \ From patchwork Thu Nov 23 11:23:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13466128 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 63BFCC5AD4C for ; Thu, 23 Nov 2023 11:24:05 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.639618.997169 (Exim 4.92) (envelope-from ) id 1r67oH-0001TL-Uz; Thu, 23 Nov 2023 11:23:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 639618.997169; Thu, 23 Nov 2023 11:23:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r67oH-0001TC-SI; Thu, 23 Nov 2023 11:23:53 +0000 Received: by outflank-mailman (input) for mailman id 639618; Thu, 23 Nov 2023 11:23:52 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r67oG-000197-9l for xen-devel@lists.xenproject.org; Thu, 23 Nov 2023 11:23:52 +0000 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [2a00:1450:4864:20::32e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c70a7c2c-89f2-11ee-98e2-6d05b1d4d9a1; Thu, 23 Nov 2023 12:23:51 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40907b82ab9so10358825e9.1 for ; Thu, 23 Nov 2023 03:23:51 -0800 (PST) Received: from localhost ([213.195.113.99]) by smtp.gmail.com with ESMTPSA id o7-20020a05600c510700b0040b36ad5413sm1517433wms.46.2023.11.23.03.23.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 03:23:49 -0800 (PST) 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: c70a7c2c-89f2-11ee-98e2-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1700738630; x=1701343430; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xiZONnswDwKe9ci9BXT6f1Pl5k4kKA0IcogCCNF7rGo=; b=soL4yu/rlcOvZTdj0068957+rwV79PvhfYL4lje7cm6yjpq8WZmsx1M3WcRBJjO0qp 4vArxTkw7EIZ8d0+K+GJsi547Y7EtrumvH5zZSoVOa/oRlKaE3banPzEbnmewWkDAcGW lqDWZzvtuOoeNp2saQSX0Bx57ddsNPvfrpgeo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700738630; x=1701343430; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xiZONnswDwKe9ci9BXT6f1Pl5k4kKA0IcogCCNF7rGo=; b=oqPbLshXr4JUWeR0Z4Y6lNmyBM8EhjDyKKhGF+nXvIP7Y/wdaQKB3tIEO+nbr+hWCE 1smW4lu6ZC8EtAs6VfcMGh9EitjPfFI0Q4UarRE0Hb/dV818/lgrKrJsVFGwbPJi5abg 0YVTSGJwLQrS65ODaQvWtJQgTkJG0jcn0qPOQIh3xy18aunmcF0aUwqU6dPeAZUb58OX kQfrcfms8Ca0hUm7yRoJKBnpRxQThMd5w+yAhpTvVmOlmV/tSJrGGaCnT8Hi/3Q3orvM fWy6fqS2aNnKiRvP4XoDDfD5QybmLweNI5XmEyelyvTZY8cFbxeddYUyvU10y/5Mr2gf Z3+g== X-Gm-Message-State: AOJu0YzhljbV5QRkHUx2HVNGXSvKjfIrpwINvoGXgNuQhLUhTPHahk4H HISc4H6RUfRtk6wEPNLzFrZW40JKTHvzNhSBg5c= X-Google-Smtp-Source: AGHT+IFg873uNCV2N+OzyDtfqrX8jTH0uhH3pweuWtn+iHtjCvPG+B22v0Vg2pBvxYLDPTBOIH4c0Q== X-Received: by 2002:a05:600c:5124:b0:40b:2ad8:579f with SMTP id o36-20020a05600c512400b0040b2ad8579fmr2060739wms.3.1700738629858; Thu, 23 Nov 2023 03:23:49 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Wei Liu , Anthony PERARD , Juergen Gross , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Konrad Rzeszutek Wilk , Ross Lagerwall Subject: [PATCH 2/3] livepatch: add a dummy hypercall for testing purposes Date: Thu, 23 Nov 2023 12:23:37 +0100 Message-ID: <20231123112338.14477-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231123112338.14477-1-roger.pau@citrix.com> References: <20231123112338.14477-1-roger.pau@citrix.com> MIME-Version: 1.0 Introduce a dummy XEN_SYSCTL_LIVEPATCH_TEST hypercall to be used in order to test livepatch functionality. The hypercall fills a value in the passed structure, which is returned to the caller. The xen-livepatch utility is expanded to allow calling that hypercall, and printing the returned value on stdout. Finally, add dummy patch that changes the returned value of the hypercall from 1 to 2. Such patch can be used with livepatch-build-tools in order to generate a livepatch payload, that when applied to the hypervisor change the printed value of `xen-livepatch test`. Signed-off-by: Roger Pau Monné --- The whole logic is very simple now. I think it's enough to have a skeleton we can later expand. Unsure whether we should do some kind of test (with `patch -F0`) that the patch still applies cleanly as part of Xen build. --- tools/include/xenctrl.h | 3 +++ tools/libs/ctrl/xc_misc.c | 14 ++++++++++++++ tools/misc/xen-livepatch.c | 25 +++++++++++++++++++++++++ xen/common/Makefile | 2 +- xen/common/livepatch-test.c | 20 ++++++++++++++++++++ xen/common/livepatch.c | 4 ++++ xen/include/public/sysctl.h | 7 +++++++ xen/include/xen/livepatch.h | 4 ++++ xen/test/livepatch/patches/test1.patch | 13 +++++++++++++ 9 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 xen/common/livepatch-test.c create mode 100644 xen/test/livepatch/patches/test1.patch diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 2ef8b4e05422..83a00d4974dd 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2645,6 +2645,9 @@ int xc_livepatch_revert(xc_interface *xch, char *name, uint32_t timeout, uint32_ int xc_livepatch_unload(xc_interface *xch, char *name, uint32_t timeout, uint32_t flags); int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout, uint32_t flags); +/* Dummy hypercall to test livepatch functionality. */ +int xc_livepatch_test(xc_interface *xch, uint32_t *result); + /* * Ensure cache coherency after memory modifications. A call to this function * is only required on ARM as the x86 architecture provides cache coherency diff --git a/tools/libs/ctrl/xc_misc.c b/tools/libs/ctrl/xc_misc.c index 5ecdfa2c7934..0ca86a53d097 100644 --- a/tools/libs/ctrl/xc_misc.c +++ b/tools/libs/ctrl/xc_misc.c @@ -1021,6 +1021,20 @@ int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout, uint32 return _xc_livepatch_action(xch, name, LIVEPATCH_ACTION_REPLACE, timeout, flags); } +int xc_livepatch_test(xc_interface *xch, uint32_t *result) +{ + struct xen_sysctl sysctl = { + .cmd = XEN_SYSCTL_livepatch_op, + .u.livepatch.cmd = XEN_SYSCTL_LIVEPATCH_TEST, + }; + int rc = do_sysctl(xch, &sysctl); + + if ( !rc ) + *result = sysctl.u.livepatch.u.test.result; + + return rc; +} + /* * Local variables: * mode: C diff --git a/tools/misc/xen-livepatch.c b/tools/misc/xen-livepatch.c index 5bf9d9a32b65..5f6fd20d8814 100644 --- a/tools/misc/xen-livepatch.c +++ b/tools/misc/xen-livepatch.c @@ -37,6 +37,7 @@ void show_help(void) " replace apply patch and revert all others.\n" " unload unload name patch.\n" " load [flags] upload and apply with name as the name\n" + " test print the result of the test hypercall (for testing purposes only)\n" " Supported flags:\n" " --nodeps Disable inter-module buildid dependency check.\n" " Check only against hypervisor buildid.\n", @@ -542,6 +543,29 @@ error: return rc; } +static int test_func(int argc, char *argv[]) +{ + int rc; + uint32_t result = 0; + + if ( argc != 0 ) + { + show_help(); + return -1; + } + + rc = xc_livepatch_test(xch, &result); + if ( rc ) + { + fprintf(stderr, "test operation failed: %s\n", strerror(errno)); + return -1; + } + + printf("%u\n", result); + + return 0; +} + /* * These are also functions in action_options that are called in case * none of the ones in main_options match. @@ -554,6 +578,7 @@ struct { { "list", list_func }, { "upload", upload_func }, { "load", load_func }, + { "test", test_func }, }; int main(int argc, char *argv[]) diff --git a/xen/common/Makefile b/xen/common/Makefile index 69d6aa626c7f..ab073d41f1d2 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -23,7 +23,7 @@ obj-y += kernel.o obj-y += keyhandler.o obj-$(CONFIG_KEXEC) += kexec.o obj-$(CONFIG_KEXEC) += kimage.o -obj-$(CONFIG_LIVEPATCH) += livepatch.o livepatch_elf.o +obj-$(CONFIG_LIVEPATCH) += livepatch.o livepatch_elf.o livepatch-test.o obj-$(CONFIG_MEM_ACCESS) += mem_access.o obj-y += memory.o obj-y += multicall.o diff --git a/xen/common/livepatch-test.c b/xen/common/livepatch-test.c new file mode 100644 index 000000000000..05b638b2ac67 --- /dev/null +++ b/xen/common/livepatch-test.c @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* Dummy file for testing livepatch functionality. */ +#include + +int livepatch_test(struct xen_sysctl_livepatch_test *test) +{ + test->result = 1; + return 0; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 1209fea2566c..e8894db1cc93 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -2116,6 +2116,10 @@ int livepatch_op(struct xen_sysctl_livepatch_op *livepatch) rc = livepatch_action(&livepatch->u.action); break; + case XEN_SYSCTL_LIVEPATCH_TEST: + rc = livepatch_test(&livepatch->u.test); + break; + default: rc = -EOPNOTSUPP; break; diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 9b19679caeb1..9c13a7fdb22c 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -1137,6 +1137,12 @@ struct xen_sysctl_livepatch_action { uint32_t pad; /* IN: Always zero. */ }; +/* Dummy hypercall for testing live patches. */ +#define XEN_SYSCTL_LIVEPATCH_TEST 4 +struct xen_sysctl_livepatch_test { + uint32_t result; /* OUT: dummy result for testing. */ +}; + struct xen_sysctl_livepatch_op { uint32_t cmd; /* IN: XEN_SYSCTL_LIVEPATCH_*. */ uint32_t pad; /* IN: Always zero. */ @@ -1145,6 +1151,7 @@ struct xen_sysctl_livepatch_op { struct xen_sysctl_livepatch_list list; struct xen_sysctl_livepatch_get get; struct xen_sysctl_livepatch_action action; + struct xen_sysctl_livepatch_test test; } u; }; diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h index df339a134e40..60d11d037dfb 100644 --- a/xen/include/xen/livepatch.h +++ b/xen/include/xen/livepatch.h @@ -11,6 +11,8 @@ struct livepatch_elf_sec; struct livepatch_elf_sym; struct xen_sysctl_livepatch_op; +#include /* For elfstructs.h */ + #include #include /* For -ENOSYS or -EOVERFLOW */ @@ -165,6 +167,8 @@ static inline void common_livepatch_revert(const struct livepatch_func *func, arch_livepatch_revert(func, state); state->applied = LIVEPATCH_FUNC_NOT_APPLIED; } + +int livepatch_test(struct xen_sysctl_livepatch_test *test); #else /* diff --git a/xen/test/livepatch/patches/test1.patch b/xen/test/livepatch/patches/test1.patch new file mode 100644 index 000000000000..c07d697cc8de --- /dev/null +++ b/xen/test/livepatch/patches/test1.patch @@ -0,0 +1,13 @@ +diff --git a/xen/common/livepatch-test.c b/xen/common/livepatch-test.c +index 05b638b2ac..876173ab6f 100644 +--- a/xen/common/livepatch-test.c ++++ b/xen/common/livepatch-test.c +@@ -5,7 +5,7 @@ + + int livepatch_test(struct xen_sysctl_livepatch_test *test) + { +- test->result = 1; ++ test->result = 2; + return 0; + } + From patchwork Thu Nov 23 11:23:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13466131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4464DC61D85 for ; Thu, 23 Nov 2023 11:24:09 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.639619.997175 (Exim 4.92) (envelope-from ) id 1r67oI-0001Vl-7i; Thu, 23 Nov 2023 11:23:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 639619.997175; Thu, 23 Nov 2023 11:23:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r67oI-0001V4-3B; Thu, 23 Nov 2023 11:23:54 +0000 Received: by outflank-mailman (input) for mailman id 639619; Thu, 23 Nov 2023 11:23:53 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r67oG-000197-Uw for xen-devel@lists.xenproject.org; Thu, 23 Nov 2023 11:23:52 +0000 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [2a00:1450:4864:20::433]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c77d390d-89f2-11ee-98e2-6d05b1d4d9a1; Thu, 23 Nov 2023 12:23:51 +0100 (CET) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-32f737deedfso415805f8f.3 for ; Thu, 23 Nov 2023 03:23:51 -0800 (PST) Received: from localhost ([213.195.113.99]) by smtp.gmail.com with ESMTPSA id f6-20020adfc986000000b0032d829e10c0sm1381164wrh.28.2023.11.23.03.23.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 03:23:50 -0800 (PST) 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: c77d390d-89f2-11ee-98e2-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1700738631; x=1701343431; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wLtx0ZHwxub7aYGGcUOFcd7W8DhSc9jxNrdpqnW0014=; b=YYtCi7hz0mHzHR0iLMcYiCwWvhe/mjIjNYY5cYdS7rowKTED8btPPpH8CGEPoj3f+o adbCDjgNbc5PIlEJIDRD+n4V1l6I6oTt5qJ0cCO59vtiCDLButFzJVqvImhe1dCKzFEW cQc3LXcBkUX8yDRcJQ+gKabjWTgn8Qvhuzzz8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700738631; x=1701343431; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wLtx0ZHwxub7aYGGcUOFcd7W8DhSc9jxNrdpqnW0014=; b=SEgVhYx5/F3g+GE8b+B0xq8FscY8NpAxWuvTUpmcMT36QRgTVnf1eQIm0CJ5MsMsB8 wzLKU6b9j3FrNrPTUmwmrb28GnOa8yYtPA0Z4zEOY3UJyA+ZMVOF6tZQzF8I/GoZuDl9 3DfnDAic+bn6R4+lOB1J4bm364ucelDof+IdWewttRmsrneuuQLDrHOjbX5qbQfre9oO H57fmNohdRzjCHkbrUt8eAB/0abN0ews9EKWNxb5C6buDzAbsPG7/3mAPeUw+mTA/foW R+u4RL7FalciKn/0FOItKgHOtQFFb/Pp44xQn7MMGyzFtMLdaNoDgQUYsP+tN3cYUwoS wRQg== X-Gm-Message-State: AOJu0YyTdCb9AjIgsVXTBkLUwsUznM6q3Np6OATA2EwHgNMViS9mPxSB exdgw6Wq+Bh3+u+ZESue2tUgasw7qMkh/bqgQ54= X-Google-Smtp-Source: AGHT+IFTR9Y8VTBtZ4QDarawvzfpL5UEA4L3ZvECk1rwwNNM7ZbT9gStWQkkRtg7I7inMcGK8Z8I+w== X-Received: by 2002:a5d:5609:0:b0:32f:b407:5b77 with SMTP id l9-20020a5d5609000000b0032fb4075b77mr2235018wrv.64.1700738631053; Thu, 23 Nov 2023 03:23:51 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Doug Goldstein , Stefano Stabellini Subject: [PATCH 3/3] automation: add x86-64 livepatching test Date: Thu, 23 Nov 2023 12:23:38 +0100 Message-ID: <20231123112338.14477-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231123112338.14477-1-roger.pau@citrix.com> References: <20231123112338.14477-1-roger.pau@citrix.com> MIME-Version: 1.0 Introduce a new gitlab tests for livepatching, using livepatch-build-tools, which better reflects how downstreams build live patches rather than the in-tree tests. The tests applies the dummy in-tree patch example, checks that the patch is applied correctly and then reverts and unloads it. Signed-off-by: Roger Pau Monné --- automation/gitlab-ci/build.yaml | 8 ++ automation/gitlab-ci/test.yaml | 8 ++ automation/scripts/build | 13 +++ .../scripts/qemu-alpine-x86_64-livepatch.sh | 79 +++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100755 automation/scripts/qemu-alpine-x86_64-livepatch.sh diff --git a/automation/gitlab-ci/build.yaml b/automation/gitlab-ci/build.yaml index 32af30ccedc9..22026df51b87 100644 --- a/automation/gitlab-ci/build.yaml +++ b/automation/gitlab-ci/build.yaml @@ -358,6 +358,14 @@ alpine-3.18-gcc-debug: variables: CONTAINER: alpine:3.18 +alpine-3.18-gcc-livepatch: + extends: .gcc-x86-64-build + variables: + CONTAINER: alpine:3.18 + LIVEPATCH: y + EXTRA_XEN_CONFIG: | + CONFIG_LIVEPATCH=y + debian-stretch-gcc-debug: extends: .gcc-x86-64-build-debug variables: diff --git a/automation/gitlab-ci/test.yaml b/automation/gitlab-ci/test.yaml index 6aabdb9d156f..58a90be5ed0e 100644 --- a/automation/gitlab-ci/test.yaml +++ b/automation/gitlab-ci/test.yaml @@ -459,3 +459,11 @@ qemu-smoke-ppc64le-powernv9-gcc: needs: - qemu-system-ppc64-8.1.0-ppc64-export - debian-bullseye-gcc-ppc64le-debug + +qemu-alpine-x86_64-gcc-livepatch: + extends: .qemu-x86-64 + script: + - ./automation/scripts/qemu-alpine-x86_64-livepatch.sh 2>&1 | tee ${LOGFILE} + needs: + - *x86-64-test-needs + - alpine-3.18-gcc-livepatch diff --git a/automation/scripts/build b/automation/scripts/build index b3c71fb6fb60..7ae735fc193e 100755 --- a/automation/scripts/build +++ b/automation/scripts/build @@ -103,3 +103,16 @@ else cp -r dist binaries/ if [[ -f xen/xen ]] ; then cp xen/xen binaries/xen; fi fi + +if [[ "$LIVEPATCH" == "y" ]]; then + # Build a test livepatch using livepatch-build-tools. + + BUILDID=$(readelf -Wn xen/xen-syms | sed -n -e 's/^.*Build ID: //p') + + git clone https://xenbits.xen.org/git-http/livepatch-build-tools.git + cd livepatch-build-tools + make + ./livepatch-build -s ../ -p ../xen/test/livepatch/patches/test1.patch \ + -o out -c ../xen/.config --depends $BUILDID --xen-depends $BUILDID + cp out/test1.livepatch ../binaries/test1.livepatch +fi diff --git a/automation/scripts/qemu-alpine-x86_64-livepatch.sh b/automation/scripts/qemu-alpine-x86_64-livepatch.sh new file mode 100755 index 000000000000..9b27a01b07f0 --- /dev/null +++ b/automation/scripts/qemu-alpine-x86_64-livepatch.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +set -ex + +cd binaries +# initrd.tar.gz is Dom0 rootfs +mkdir -p rootfs +cd rootfs +tar xvzf ../initrd.tar.gz +mkdir proc +mkdir run +mkdir srv +mkdir sys +rm var/run +cp -ar ../dist/install/* . +cp ../test1.livepatch ./root/ +cat << "EOF" >> etc/local.d/xen.start +#!/bin/bash + +set -ex + +trap poweroff EXIT + +export LD_LIBRARY_PATH=/usr/local/lib + +result=`xen-livepatch test` +if [ "$result" != "1" ]; then + echo "FAIL" + exit 1 +fi + +xen-livepatch load /root/test1.livepatch + +result=`xen-livepatch test` +if [ "$result" != "2" ]; then + echo "FAIL" + exit 1 +fi + +xen-livepatch revert test1 +xen-livepatch unload test1 + +result=`xen-livepatch test` +if [ "$result" != "1" ]; then + echo "FAIL" + exit 1 +fi + +echo "SUCCESS" +EOF +chmod +x etc/local.d/xen.start +echo "rc_verbose=yes" >> etc/rc.conf +# rebuild Dom0 rootfs +find . |cpio -H newc -o|gzip > ../xen-rootfs.cpio.gz +cd ../.. + +cat >> binaries/pxelinux.0 << EOF +#!ipxe + +kernel xen console=com1 console_timestamps=boot +module bzImage console=hvc0 +module xen-rootfs.cpio.gz +boot +EOF + +# Run the test +rm -f smoke.serial +timeout -k 1 360 \ +qemu-system-x86_64 \ + -cpu qemu64,+svm \ + -m 2G -smp 2 \ + -monitor none -serial stdio \ + -nographic \ + -device virtio-net-pci,netdev=n0 \ + -netdev user,id=n0,tftp=binaries,bootfile=/pxelinux.0 |& \ + tee smoke.serial | sed 's/\r//' + +grep -q "SUCCESS" smoke.serial +exit 0