kpatch/test/integration/linux-6.2.0/module.patch
Josh Poimboeuf f499fc25e0 test/integration: Updated module.patch for Linux 6.2
Yulia reported a bug with module.patch which can be seen with
CONFIG_PROVE_RCU:

  BUG: sleeping function called from invalid context at include/linux/percpu-rwsem.h:49
  in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 1053, name: grep
  preempt_count: 0, expected: 0
  RCU nest depth: 1, expected: 0
  2 locks held by grep/1053:
   #0: ffff8881079bf1a0 (&p->lock){+.+.}-{3:3}, at: seq_read_iter+0x55/0x460
   #1: ffffffff8275d620 (rcu_read_lock){....}-{1:2}, at: cache_seq_start_rcu+0x5/0x140 [sunrpc]
  CPU: 3 PID: 1053 Comm: grep Tainted: G           OE K    6.2.0 #57
  Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.1-2.fc37 04/01/2014
  Call Trace:
   <TASK>
   dump_stack_lvl+0x5b/0x77
   __might_resched.cold+0xff/0x13a
   cpus_read_lock+0x16/0xd0
   static_key_disable+0xe/0x20
   e_show+0x5b/0xd70 [livepatch_module]
   seq_read_iter+0x127/0x460
   seq_read+0xa3/0xd0
   proc_reg_read+0x52/0xa0
   vfs_read+0xc9/0x2f0
   ? __do_sys_newfstat+0x57/0x60
   ? lock_is_held_type+0xe8/0x140
   ksys_read+0x6c/0xf0
   do_syscall_64+0x37/0x90
   entry_SYSCALL_64_after_hwframe+0x72/0xdc
  RIP: 0033:0x7fbd314f7af0
  Code: b6 fe ff ff 48 8d 3d 2f 78 09 00 48 83 ec 08 e8 96 25 02 00 66 0f 1f 44 00 00 83 3d d9 db 2c 00 00 75 10 b8 00 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 31 c3 48 83 ec 08 e8 7e e3 01 00 48 89 04 24
  RSP: 002b:00007ffcd6f1c708 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
  RAX: ffffffffffffffda RBX: 0000000000008000 RCX: 00007fbd314f7af0
  RDX: 0000000000008000 RSI: 0000563c751ea000 RDI: 0000000000000003
  RBP: 0000000000008000 R08: 0000000000009008 R09: 0000000000000000
  R10: 0000000000000000 R11: 0000000000000246 R12: 0000563c751ea000
  R13: 0000000000000003 R14: 0000000000000003 R15: 0000563c751ea000

The problem is that the patched module's seq_operations take an RCU read
lock before calling e_show(), which is patched to call
static_key_disable(), which can sleep.

Fix the issue by moving all the module test code to a different module
(xfs) which doesn't take an RCU lock.

Also enable the pr_debug() test and make the static branch test
unconditional since they're supported by newer kernels and this test is
for 6.2.

Reported-by: Yulia Kopkova <ykopkova@redhat.com>
Debugged-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2023-03-22 17:45:07 -07:00

78 lines
2.0 KiB
Diff

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);