Skip to content

Commit

Permalink
integration: update module.patch
Browse files Browse the repository at this point in the history
- Avoid kernel warnings:

  =============================
  WARNING: suspicious RCU usage
  6.2.0-rc3 dynup#1 Tainted: G           OE K
  -----------------------------
  include/linux/rcupdate.h:390 Illegal context switch in RCU read-side critical section!

  other info that might help us debug this:

  rcu_scheduler_active = 2, debug_locks = 1
  2 locks held by grep/192875:
   #0: 000000008f19e678 (&p->lock){+.+.}-{3:3}, at: seq_read_iter+0x66/0x4e0
   dynup#1: 0000000128f0fe10 (rcu_read_lock){....}-{1:2}, at: cache_seq_start_rcu+0x6/0x1a0 [sunrpc]

  stack backtrace:
  CPU: 0 PID: 192875 Comm: grep Tainted: G           OE K    6.2.0- rc3 dynup#1
  Hardware name: IBM 8561 LT1 400 (z/VM 7.2.0)
  Call Trace:
   [<0000000128423aa8>] dump_stack_lvl+0x80/0xa8
   [<0000000127687920>] __might_resched+0x1a0/0x2a0
   [<0000000127647764>] cpus_read_lock+0x34/0x110
   [<000000012789fcb6>] static_key_disable+0x26/0x40
   [<000003ff802e7fcc>] e_show+0x7c/0x230 [test_COMBINED]
   [<00000001279fb9b2>] seq_read_iter+0x152/0x4e0
   [<00000001279fbdd2>] seq_read+0x92/0xb0
   [<0000000127a8052a>] proc_reg_read+0x9a/0xf0
   [<00000001279bcb64>] vfs_read+0x94/0x270
   [<00000001279bd724>] ksys_read+0x74/0x100
   [<0000000128423f86>] __do_syscall+0x1d6/0x200
   [<000000012843a9d2>] system_call+0x82/0xb0

- Remove TODO comment from the test

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
  • Loading branch information
joe-lawrence committed Feb 10, 2023
1 parent 9f84a76 commit df09fa6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
4 changes: 1 addition & 3 deletions test/integration/linux-6.2.0/module-LOADED.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ sudo modprobe nfsd
sleep 5
grep -q kpatch /proc/fs/nfs/exports

# TODO: This will trigger a printk on newer kernels which have the .klp.arch
# removal. Don't actually do the grep until running on a newer kernel.
echo "file fs/nfsd/export.c +p" > /sys/kernel/debug/dynamic_debug/control
cat /proc/fs/nfs/exports > /dev/null
# dmesg | grep -q "kpatch: pr_debug"
dmesg | grep -q "kpatch: pr_debug"
66 changes: 41 additions & 25 deletions test/integration/linux-6.2.0/module.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
kpatch module integration test
From 4ad0397efd708a961ecf733bc649783565a6f2db Mon Sep 17 00:00:00 2001
From: Joe Lawrence <joe.lawrence@redhat.com>
Date: Thu, 19 Jan 2023 16:43:46 -0500
Subject: [PATCH] kpatch module integration test
Content-type: text/plain

This tests several things related to the patching of modules:

Expand All @@ -12,22 +16,44 @@ This tests several things related to the patching of modules:
- jump labels (5.8+ kernels only) -- including dynamic printk

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
fs/nfsd/export.c | 31 +++++++++++++++++++++++++++++++
net/netlink/af_netlink.c | 5 +++++
2 files changed, 36 insertions(+)

diff -Nupr src.orig/fs/nfsd/export.c src/fs/nfsd/export.c
--- src.orig/fs/nfsd/export.c 2023-01-12 11:20:07.174710504 -0500
+++ src/fs/nfsd/export.c 2023-01-12 11:20:46.075941153 -0500
@@ -1294,6 +1294,10 @@ static void exp_flags(struct seq_file *m
diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
index 668c7527b17e..a3122ee61466 100644
--- a/fs/nfsd/export.c
+++ b/fs/nfsd/export.c
@@ -1294,6 +1294,27 @@ static void exp_flags(struct seq_file *m, int flag, int fsid,
}
}

+#include <linux/version.h>
+#include "kpatch-macros.h"
+static int pre_patch_callback(patch_object *obj)
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0)
+ 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);
+#endif
+ return 0;
+}
+KPATCH_PRE_PATCH_CALLBACK(pre_patch_callback);
+
+extern char *kpatch_string(void);
+
+__attribute__((optimize("-fno-optimize-sibling-calls")))
static int e_show(struct seq_file *m, void *p)
{
struct cache_head *cp = p;
@@ -1301,12 +1305,36 @@ static int e_show(struct seq_file *m, vo
@@ -1301,12 +1322,22 @@ static int e_show(struct seq_file *m, void *p)
struct cache_detail *cd = m->private;
bool export_stats = is_export_stats_file(m);

Expand All @@ -39,20 +65,6 @@ diff -Nupr src.orig/fs/nfsd/export.c src/fs/nfsd/export.c
+#endif
+
+ pr_debug("kpatch: pr_debug() test\n");
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0)
+{
+ 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);
+}
+#endif
+
if (p == SEQ_START_TOKEN) {
seq_puts(m, "# Version 1.1\n");
Expand All @@ -64,10 +76,11 @@ diff -Nupr src.orig/fs/nfsd/export.c src/fs/nfsd/export.c
return 0;
}

diff -Nupr src.orig/net/netlink/af_netlink.c src/net/netlink/af_netlink.c
--- src.orig/net/netlink/af_netlink.c 2023-01-12 11:20:07.603713047 -0500
+++ src/net/netlink/af_netlink.c 2023-01-12 11:20:46.076941159 -0500
@@ -2970,4 +2970,9 @@ panic:
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index bca2a470ccad..53ede086f39e 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -2970,4 +2970,9 @@ static int __init netlink_proto_init(void)
panic("netlink_init: Cannot allocate nl_table\n");
}

Expand All @@ -77,3 +90,6 @@ diff -Nupr src.orig/net/netlink/af_netlink.c src/net/netlink/af_netlink.c
+}
+
core_initcall(netlink_proto_init);
--
2.39.0

0 comments on commit df09fa6

Please sign in to comment.