Skip to content

Commit 90ab713

Browse files
committed
test/integration/amzn-2023: Add integration tests for AL2023
This commit adds tests for Amazon Linux 2023. All patches apply and integration tests pass. Signed-off-by: Puranjay Mohan <[email protected]>
1 parent 17b795b commit 90ab713

16 files changed

+530
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
grep "kpatch: 5" /proc/meminfo
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
diff -Nupr src.orig/fs/proc/meminfo.c src/fs/proc/meminfo.c
2+
--- src.orig/fs/proc/meminfo.c 2023-01-12 11:20:07.184710563 -0500
3+
+++ src/fs/proc/meminfo.c 2023-01-12 11:20:08.166716386 -0500
4+
@@ -29,6 +29,8 @@ static void show_val_kb(struct seq_file
5+
seq_write(m, " kB\n", 4);
6+
}
7+
8+
+static int foo = 5;
9+
+
10+
static int meminfo_proc_show(struct seq_file *m, void *v)
11+
{
12+
struct sysinfo i;
13+
@@ -154,6 +156,7 @@ static int meminfo_proc_show(struct seq_
14+
show_val_kb(m, "CmaFree: ",
15+
global_zone_page_state(NR_FREE_CMA_PAGES));
16+
#endif
17+
+ seq_printf(m, "kpatch: %d\n", foo);
18+
19+
hugetlb_report_meminfo(m);
20+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff -Nupr src.orig/net/ipv6/netfilter.c src/net/ipv6/netfilter.c
2+
--- src.orig/net/ipv6/netfilter.c 2023-01-12 11:20:07.630713207 -0500
3+
+++ src/net/ipv6/netfilter.c 2023-01-12 11:20:29.874845095 -0500
4+
@@ -96,6 +96,8 @@ static int nf_ip6_reroute(struct sk_buff
5+
return 0;
6+
}
7+
8+
+#include "kpatch-macros.h"
9+
+
10+
int __nf_ip6_route(struct net *net, struct dst_entry **dst,
11+
struct flowi *fl, bool strict)
12+
{
13+
@@ -109,6 +111,9 @@ int __nf_ip6_route(struct net *net, stru
14+
struct dst_entry *result;
15+
int err;
16+
17+
+ if (!jiffies)
18+
+ printk("kpatch nf_ip6_route foo\n");
19+
+
20+
result = ip6_route_output(net, sk, &fl->u.ip6);
21+
err = result->error;
22+
if (err)
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
diff -Nupr src.orig/drivers/input/joydev.c src/drivers/input/joydev.c
2+
--- src.orig/drivers/input/joydev.c 2023-01-12 11:20:06.597707083 -0500
3+
+++ src/drivers/input/joydev.c 2023-01-12 11:20:38.032893465 -0500
4+
@@ -1096,3 +1096,47 @@ static void __exit joydev_exit(void)
5+
6+
module_init(joydev_init);
7+
module_exit(joydev_exit);
8+
+
9+
+#include <linux/module.h>
10+
+#include "kpatch-macros.h"
11+
+
12+
+static const char *const module_state[] = {
13+
+ [MODULE_STATE_LIVE] = "[MODULE_STATE_LIVE] Normal state",
14+
+ [MODULE_STATE_COMING] = "[MODULE_STATE_COMING] Full formed, running module_init",
15+
+ [MODULE_STATE_GOING] = "[MODULE_STATE_GOING] Going away",
16+
+ [MODULE_STATE_UNFORMED] = "[MODULE_STATE_UNFORMED] Still setting it up",
17+
+};
18+
+
19+
+static void callback_info(const char *callback, patch_object *obj)
20+
+{
21+
+ if (obj->mod)
22+
+ pr_info("%s: %s -> %s\n", callback, obj->mod->name,
23+
+ module_state[obj->mod->state]);
24+
+ else
25+
+ pr_info("%s: vmlinux\n", callback);
26+
+}
27+
+
28+
+static int pre_patch_callback(patch_object *obj)
29+
+{
30+
+ callback_info(__func__, obj);
31+
+ return 0; /* return -ENODEV; */
32+
+}
33+
+KPATCH_PRE_PATCH_CALLBACK(pre_patch_callback);
34+
+
35+
+static void post_patch_callback(patch_object *obj)
36+
+{
37+
+ callback_info(__func__, obj);
38+
+}
39+
+KPATCH_POST_PATCH_CALLBACK(post_patch_callback);
40+
+
41+
+static void pre_unpatch_callback(patch_object *obj)
42+
+{
43+
+ callback_info(__func__, obj);
44+
+}
45+
+KPATCH_PRE_UNPATCH_CALLBACK(pre_unpatch_callback);
46+
+
47+
+static void post_unpatch_callback(patch_object *obj)
48+
+{
49+
+ callback_info(__func__, obj);
50+
+}
51+
+KPATCH_POST_UNPATCH_CALLBACK(post_unpatch_callback);
52+
diff -Nupr src.orig/drivers/input/misc/pcspkr.c src/drivers/input/misc/pcspkr.c
53+
--- src.orig/drivers/input/misc/pcspkr.c 2023-01-12 11:20:06.578706970 -0500
54+
+++ src/drivers/input/misc/pcspkr.c 2023-01-12 11:20:38.032893465 -0500
55+
@@ -134,3 +134,46 @@ static struct platform_driver pcspkr_pla
56+
};
57+
module_platform_driver(pcspkr_platform_driver);
58+
59+
+#include <linux/module.h>
60+
+#include "kpatch-macros.h"
61+
+
62+
+static const char *const module_state[] = {
63+
+ [MODULE_STATE_LIVE] = "[MODULE_STATE_LIVE] Normal state",
64+
+ [MODULE_STATE_COMING] = "[MODULE_STATE_COMING] Full formed, running module_init",
65+
+ [MODULE_STATE_GOING] = "[MODULE_STATE_GOING] Going away",
66+
+ [MODULE_STATE_UNFORMED] = "[MODULE_STATE_UNFORMED] Still setting it up",
67+
+};
68+
+
69+
+static void callback_info(const char *callback, patch_object *obj)
70+
+{
71+
+ if (obj->mod)
72+
+ pr_info("%s: %s -> %s\n", callback, obj->mod->name,
73+
+ module_state[obj->mod->state]);
74+
+ else
75+
+ pr_info("%s: vmlinux\n", callback);
76+
+}
77+
+
78+
+static int pre_patch_callback(patch_object *obj)
79+
+{
80+
+ callback_info(__func__, obj);
81+
+ return 0;
82+
+}
83+
+KPATCH_PRE_PATCH_CALLBACK(pre_patch_callback);
84+
+
85+
+static void post_patch_callback(patch_object *obj)
86+
+{
87+
+ callback_info(__func__, obj);
88+
+}
89+
+KPATCH_POST_PATCH_CALLBACK(post_patch_callback);
90+
+
91+
+static void pre_unpatch_callback(patch_object *obj)
92+
+{
93+
+ callback_info(__func__, obj);
94+
+}
95+
+KPATCH_PRE_UNPATCH_CALLBACK(pre_unpatch_callback);
96+
+
97+
+static void post_unpatch_callback(patch_object *obj)
98+
+{
99+
+ callback_info(__func__, obj);
100+
+}
101+
+KPATCH_POST_UNPATCH_CALLBACK(post_unpatch_callback);
102+
diff -Nupr src.orig/fs/aio.c src/fs/aio.c
103+
--- src.orig/fs/aio.c 2023-01-12 11:20:07.273711091 -0500
104+
+++ src/fs/aio.c 2023-01-12 11:20:38.033893471 -0500
105+
@@ -50,6 +50,50 @@
106+
107+
#define KIOCB_KEY 0
108+
109+
+#include <linux/module.h>
110+
+#include "kpatch-macros.h"
111+
+
112+
+static const char *const module_state[] = {
113+
+ [MODULE_STATE_LIVE] = "[MODULE_STATE_LIVE] Normal state",
114+
+ [MODULE_STATE_COMING] = "[MODULE_STATE_COMING] Full formed, running module_init",
115+
+ [MODULE_STATE_GOING] = "[MODULE_STATE_GOING] Going away",
116+
+ [MODULE_STATE_UNFORMED] = "[MODULE_STATE_UNFORMED] Still setting it up",
117+
+};
118+
+
119+
+static void callback_info(const char *callback, patch_object *obj)
120+
+{
121+
+ if (obj->mod)
122+
+ pr_info("%s: %s -> %s\n", callback, obj->mod->name,
123+
+ module_state[obj->mod->state]);
124+
+ else
125+
+ pr_info("%s: vmlinux\n", callback);
126+
+}
127+
+
128+
+static int pre_patch_callback(patch_object *obj)
129+
+{
130+
+ callback_info(__func__, obj);
131+
+ return 0;
132+
+}
133+
+KPATCH_PRE_PATCH_CALLBACK(pre_patch_callback);
134+
+
135+
+static void post_patch_callback(patch_object *obj)
136+
+{
137+
+ callback_info(__func__, obj);
138+
+}
139+
+KPATCH_POST_PATCH_CALLBACK(post_patch_callback);
140+
+
141+
+static void pre_unpatch_callback(patch_object *obj)
142+
+{
143+
+ callback_info(__func__, obj);
144+
+}
145+
+KPATCH_PRE_UNPATCH_CALLBACK(pre_unpatch_callback);
146+
+
147+
+static void post_unpatch_callback(patch_object *obj)
148+
+{
149+
+ callback_info(__func__, obj);
150+
+}
151+
+KPATCH_POST_UNPATCH_CALLBACK(post_unpatch_callback);
152+
+
153+
#define AIO_RING_MAGIC 0xa10a10a1
154+
#define AIO_RING_COMPAT_FEATURES 1
155+
#define AIO_RING_INCOMPAT_FEATURES 0
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
5+
sudo modprobe xfs
6+
sleep 5
7+
echo "file fs/xfs/xfs_stats.c +p" > /sys/kernel/debug/dynamic_debug/control
8+
grep -q kpatch /sys/fs/xfs/stats/stats
9+
dmesg | grep -q "kpatch: pr_debug"
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
kpatch module integration test
2+
3+
This tests several things related to the patching of modules:
4+
5+
- 'kpatch_string' tests the referencing of a symbol which is outside the
6+
.o, but inside the patch module.
7+
8+
- alternatives patching (.altinstructions)
9+
10+
- paravirt patching (.parainstructions)
11+
12+
- jump labels (5.8+ kernels only) -- including dynamic printk
13+
14+
Signed-off-by: Josh Poimboeuf <[email protected]>
15+
16+
diff --git a/fs/xfs/xfs_stats.c b/fs/xfs/xfs_stats.c
17+
index 90a77cd3ebad..f65df90ae8e1 100644
18+
--- a/fs/xfs/xfs_stats.c
19+
+++ b/fs/xfs/xfs_stats.c
20+
@@ -16,6 +16,8 @@ static int counter_val(struct xfsstats __percpu *stats, int idx)
21+
return val;
22+
}
23+
24+
+extern char *kpatch_string(void);
25+
+
26+
int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
27+
{
28+
int i, j;
29+
@@ -85,6 +87,34 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
30+
0);
31+
#endif
32+
33+
+ /* Reference a symbol outside the .o yet inside the patch module: */
34+
+ len += scnprintf(buf + len, PATH_MAX-len, "%s\n", kpatch_string());
35+
+
36+
+#ifdef CONFIG_X86_64
37+
+ /* Test alternatives patching: */
38+
+ alternative("ud2", "nop", X86_FEATURE_ALWAYS);
39+
+ alternative("nop", "ud2", X86_FEATURE_IA64);
40+
+
41+
+ /* Test paravirt patching: */
42+
+ slow_down_io(); /* paravirt call */
43+
+#endif
44+
+
45+
+ /* Test pr_debug: */
46+
+ pr_debug("kpatch: pr_debug() test\n");
47+
+
48+
+{
49+
+ /* Test static branches: */
50+
+ static DEFINE_STATIC_KEY_TRUE(kpatch_key);
51+
+
52+
+ if (static_branch_unlikely(&memcg_kmem_enabled_key))
53+
+ printk("kpatch: memcg_kmem_enabled_key\n");
54+
+
55+
+ BUG_ON(!static_branch_likely(&kpatch_key));
56+
+ static_branch_disable(&kpatch_key);
57+
+ BUG_ON(static_branch_likely(&kpatch_key));
58+
+ static_branch_enable(&kpatch_key);
59+
+}
60+
+
61+
return len;
62+
}
63+
64+
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
65+
index c64277659753..05b753c2ec84 100644
66+
--- a/net/netlink/af_netlink.c
67+
+++ b/net/netlink/af_netlink.c
68+
@@ -2980,4 +2980,9 @@ static int __init netlink_proto_init(void)
69+
panic("netlink_init: Cannot allocate nl_table\n");
70+
}
71+
72+
+char *kpatch_string(void)
73+
+{
74+
+ return "kpatch";
75+
+}
76+
+
77+
core_initcall(netlink_proto_init);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
SCRIPTDIR="$(readlink -f $(dirname $(type -p $0)))"
4+
5+
declare -a blacklist=(meminfo-string-LOADED.test)
6+
7+
source ${SCRIPTDIR}/../common/multiple.template
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
diff -Nupr src.orig/drivers/tty/n_tty.c src/drivers/tty/n_tty.c
2+
--- src.orig/drivers/tty/n_tty.c 2023-01-12 11:20:06.978709342 -0500
3+
+++ src/drivers/tty/n_tty.c 2023-01-12 11:20:54.149989024 -0500
4+
@@ -2315,7 +2315,7 @@ more_to_be_read:
5+
* (note that the process_output*() functions take this lock themselves)
6+
*/
7+
8+
-static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
9+
+static ssize_t noinline kpatch_n_tty_write(struct tty_struct *tty, struct file *file,
10+
const unsigned char *buf, size_t nr)
11+
{
12+
const unsigned char *b = buf;
13+
@@ -2402,6 +2402,12 @@ break_out:
14+
return (b - buf) ? b - buf : retval;
15+
}
16+
17+
+static ssize_t __attribute__((optimize("-fno-optimize-sibling-calls"))) n_tty_write(struct tty_struct *tty, struct file *file,
18+
+ const unsigned char *buf, size_t nr)
19+
+{
20+
+ return kpatch_n_tty_write(tty, file, buf, nr);
21+
+}
22+
+
23+
/**
24+
* n_tty_poll - poll method for N_TTY
25+
* @tty: terminal device
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
diff -Nupr src.orig/fs/proc/cmdline.c src/fs/proc/cmdline.c
2+
--- src.orig/fs/proc/cmdline.c 2023-01-12 11:20:07.184710563 -0500
3+
+++ src/fs/proc/cmdline.c 2023-01-12 11:21:02.411038005 -0500
4+
@@ -21,3 +21,10 @@ static int __init proc_cmdline_init(void
5+
return 0;
6+
}
7+
fs_initcall(proc_cmdline_init);
8+
+
9+
+#include <linux/printk.h>
10+
+void kpatch_print_message(void)
11+
+{
12+
+ if (!jiffies)
13+
+ printk("hello there!\n");
14+
+}
15+
diff -Nupr src.orig/fs/proc/meminfo.c src/fs/proc/meminfo.c
16+
--- src.orig/fs/proc/meminfo.c 2023-01-12 11:20:07.184710563 -0500
17+
+++ src/fs/proc/meminfo.c 2023-01-12 11:21:02.411038005 -0500
18+
@@ -19,6 +19,8 @@
19+
#include <asm/page.h>
20+
#include "internal.h"
21+
22+
+void kpatch_print_message(void);
23+
+
24+
void __attribute__((weak)) arch_report_meminfo(struct seq_file *m)
25+
{
26+
}
27+
@@ -55,6 +57,7 @@ static int meminfo_proc_show(struct seq_
28+
sreclaimable = global_node_page_state_pages(NR_SLAB_RECLAIMABLE_B);
29+
sunreclaim = global_node_page_state_pages(NR_SLAB_UNRECLAIMABLE_B);
30+
31+
+ kpatch_print_message();
32+
show_val_kb(m, "MemTotal: ", i.totalram);
33+
show_val_kb(m, "MemFree: ", i.freeram);
34+
show_val_kb(m, "MemAvailable: ", available);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
grep -q newpid: /proc/$$/status

0 commit comments

Comments
 (0)