]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
(no commit message)
authorRoger Pau Monne <roger.pau@citrix.com>
Wed, 5 Apr 2023 10:15:58 +0000 (12:15 +0200)
committerRoger Pau Monne <roger.pau@citrix.com>
Wed, 5 Apr 2023 13:33:04 +0000 (15:33 +0200)
tools/include/xenctrl.h
tools/libs/ctrl/xc_misc.c
tools/misc/xen-livepatch.c
xen/common/Makefile
xen/common/livepatch-test.c [new file with mode: 0644]
xen/common/livepatch.c
xen/include/public/sysctl.h
xen/include/xen/livepatch.h
xen/test/livepatch/test.patch [new file with mode: 0644]

index 05967ecc92e28cf67a884b2f9c9d4311b5e9be77..d8aea225aaf75a0458ace6a1df1612801ca63488 100644 (file)
@@ -2629,6 +2629,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
index 265f15ec2da344e948cbbe532d6d456a09accfc0..b4c986584e3e4a58350aa7a8bf6a7dc325bef814 100644 (file)
@@ -986,6 +986,21 @@ 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)
+{
+    int rc;
+    DECLARE_SYSCTL = {
+        .cmd = XEN_SYSCTL_livepatch_op,
+        .u.livepatch.cmd = XEN_SYSCTL_LIVEPATCH_TEST,
+    };
+
+    rc = do_sysctl(xch, &sysctl);
+    if ( !rc )
+        *result = sysctl.u.livepatch.u.test.result;
+
+    return rc;
+}
+
 /*
  * Local variables:
  * mode: C
index 5bf9d9a32b65bf1f6bdcd53ef2f44257a22621bb..7c37965748dcde334d5ebf3f96ebdca10ad0cd21 100644 (file)
@@ -37,6 +37,7 @@ void show_help(void)
             "  replace <name>         apply <name> patch and revert all others.\n"
             "  unload <name>          unload name <name> patch.\n"
             "  load <file> [flags]    upload and apply <file> with name as the <file> 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;
+
+    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[])
index 46049eac35a28c21302a55e093e16b47cd81d233..ec04a8782c7fd3ea4d3fbf2633d84c2294146fb4 100644 (file)
@@ -22,7 +22,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 (file)
index 0000000..876173a
--- /dev/null
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/* Dummy file for testing livepatch functionality. */
+#include <xen/livepatch.h>
+
+int livepatch_test(struct xen_sysctl_livepatch_test *test)
+{
+    test->result = 2;
+    return 0;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
index d385f882c65c1df8fc07a62299b5d7b5f19d4777..25fa1deedd106e820faf732e7bf18f022353a60f 100644 (file)
@@ -2050,6 +2050,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;
index 2b24d6bfd00ed3cec523ea970e3328612e176272..48c97a33623bf3a1ddbead1450a43080ee34b2bc 100644 (file)
@@ -1010,6 +1010,12 @@ struct xen_sysctl_livepatch_action {
     uint32_t pad;                           /* IN: Always zero. */
 };
 
+/* Dummy hypercall used for testing the generation of 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. */
@@ -1018,6 +1024,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;
 };
 
index 9fdb29c382b6ee5dc4643edf12b6dd3e929c848f..c88341374843943c83a33e567f2e1a2a9c05674f 100644 (file)
@@ -11,6 +11,8 @@ struct livepatch_elf_sec;
 struct livepatch_elf_sym;
 struct xen_sysctl_livepatch_op;
 
+#include <xen/types.h>
+
 #include <xen/elfstructs.h>
 #include <xen/errno.h> /* For -ENOSYS or -EOVERFLOW */
 #ifdef CONFIG_LIVEPATCH
@@ -151,6 +153,8 @@ static inline void common_livepatch_revert(struct livepatch_func *func)
     arch_livepatch_revert(func);
     func->applied = LIVEPATCH_FUNC_NOT_APPLIED;
 }
+
+int livepatch_test(struct xen_sysctl_livepatch_test *test);
 #else
 
 /*
diff --git a/xen/test/livepatch/test.patch b/xen/test/livepatch/test.patch
new file mode 100644 (file)
index 0000000..c07d697
--- /dev/null
@@ -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;
+ }