On Wed, Feb 16, 2022 at 11:39:39AM -0500, Joe Lawrence wrote:
quoted hunk ↗ jump to hunk
[ ... snip ... ]
diff --git a/lib/livepatch/test_klp_convert_data.c b/lib/livepatch/test_klp_convert_data.c
new file mode 100644
index 000000000000..142422664159
--- /dev/null
+++ b/lib/livepatch/test_klp_convert_data.c
@@ -0,0 +1,190 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2021 Joe Lawrence <joe.lawrence@redhat.com>
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/cache.h>
+#include <linux/livepatch.h>
+#include "test_klp_convert.h"
+
+/* Small global */
+int *p_global_small = &global_small;
+
+/* Small global (const) */
+// .rela.data.rel.ro, .rela.rodata supported ???:
+int * const p_const_global_small = &const_global_small;
+
+/* Small file-static */
+static int *p_static_small = &static_small;
+
+/* Small file-static (constant) */
+static int * const p_static_const_small = &static_const_small;
+
+/* Large global */
+int *p_global_large[4] = {
+ &global_large[0], &global_large[1],
+ &global_large[2], &global_large[3],
+};
+
+/* Large global (const) */
+// .rela.data.rel.ro, .rela.rodata supported ???:
+int * const p_const_global_large[4] = {
+ &const_global_large[0], &const_global_large[1],
+ &const_global_large[2], &const_global_large[3],
+};
+
+/* Large file-static global */
+static int *p_static_large[4] = {
+ &static_large[0], &static_large[1],
+ &static_large[2], &static_large[3],
+};
+
+/* Large file-static (const) */
+static int * const p_static_const_large[4] = {
+ &static_const_large[0], &static_const_large[1],
+ &static_const_large[2], &static_const_large[3],
+};
+
+// .rela.data.rel.ro, .rela.rodata supported ???:
+static int * __ro_after_init p_static_ro_after_init = &static_ro_after_init;
+static int * __read_mostly p_static_read_mostly = &static_read_mostly;
This started getting a bit repetitive, and maybe belongs to its own set
of klp-convert unit tests (as the selftests seem closer to integration
type tests).
Anyway, I left in the .rela.<read-only> type relocations as mentioned in
the [RFC PATCH v6 03/12] livepatch: Add klp-convert tool [1]. We can
talk about whether such sections should be supported over there.
As for this test, it currently crashes ppc64le as it generates a late
klp-relocation type R_PPC64_ADDR64 in a section that was marked RO.
(IIRC such ppc64le data relocations to other .rela.<text> sections are
safe as they aren't marked RO.)
[1] https://lore.kernel.org/lkml/Yg0qgtSFNQx5Mo1i@redhat.com/ (local)
-- Joe