File: module.patch

package info (click to toggle)
kpatch 0.9.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,716 kB
  • sloc: ansic: 9,716; sh: 2,592; makefile: 260; asm: 35
file content (77 lines) | stat: -rw-r--r-- 2,077 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
kpatch module integration test

This tests several things related to the patching of modules:

- 'kpatch_string' tests the referencing of a symbol which is outside the
  .o, but inside the patch module.

- alternatives patching (.altinstructions)

- paravirt patching (.parainstructions)

- jump labels (5.8+ kernels only) -- including dynamic printk

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>

diff --git a/fs/xfs/xfs_stats.c b/fs/xfs/xfs_stats.c
index 90a77cd3ebad..f65df90ae8e1 100644
--- a/fs/xfs/xfs_stats.c
+++ b/fs/xfs/xfs_stats.c
@@ -16,6 +16,8 @@ static int counter_val(struct xfsstats __percpu *stats, int idx)
 	return val;
 }
 
+extern char *kpatch_string(void);
+
 int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
 {
 	int		i, j;
@@ -85,6 +87,34 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
 		0);
 #endif
 
+	/* Reference a symbol outside the .o yet inside the patch module: */
+	len += scnprintf(buf + len, PATH_MAX-len, "%s\n", kpatch_string());
+
+#ifdef CONFIG_X86_64
+	/* Test alternatives patching: */
+	alternative("ud2", "nop", X86_FEATURE_ALWAYS);
+	alternative("nop", "ud2", X86_FEATURE_IA64);
+
+	/* Test paravirt patching: */
+	slow_down_io();   /* paravirt call */
+#endif
+
+	/* Test pr_debug: */
+	pr_debug("kpatch: pr_debug() test\n");
+
+{
+	/* Test static branches: */
+	static DEFINE_STATIC_KEY_TRUE(kpatch_key);
+
+       if (static_branch_unlikely(&memcg_kmem_enabled_key))
+		printk("kpatch: memcg_kmem_enabled_key\n");
+
+	BUG_ON(!static_branch_likely(&kpatch_key));
+	static_branch_disable(&kpatch_key);
+	BUG_ON(static_branch_likely(&kpatch_key));
+	static_branch_enable(&kpatch_key);
+}
+
 	return len;
 }
 
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index c64277659753..05b753c2ec84 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -2980,4 +2980,9 @@ static int __init netlink_proto_init(void)
 	panic("netlink_init: Cannot allocate nl_table\n");
 }
 
+char *kpatch_string(void)
+{
+	return "kpatch";
+}
+
 core_initcall(netlink_proto_init);