Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'for-7.1/module-function-test' into for-linus

+194
+100
tools/testing/selftests/livepatch/test-livepatch.sh
··· 8 8 MOD_LIVEPATCH2=test_klp_syscall 9 9 MOD_LIVEPATCH3=test_klp_callbacks_demo 10 10 MOD_REPLACE=test_klp_atomic_replace 11 + MOD_TARGET=test_klp_mod_target 12 + MOD_TARGET_PATCH=test_klp_mod_patch 11 13 12 14 setup_config 13 15 ··· 196 194 livepatch: '$MOD_REPLACE': completing unpatching transition 197 195 livepatch: '$MOD_REPLACE': unpatching complete 198 196 % rmmod $MOD_REPLACE" 197 + 198 + 199 + # - load a target module that provides /proc/test_klp_mod_target with 200 + # original output 201 + # - load a livepatch that patches the target module's show function 202 + # - verify the proc entry returns livepatched output 203 + # - disable and unload the livepatch 204 + # - verify the proc entry returns original output again 205 + # - unload the target module 206 + 207 + start_test "module function patching" 208 + 209 + load_mod $MOD_TARGET 210 + 211 + if [[ "$(cat /proc/$MOD_TARGET)" != "$MOD_TARGET: original output" ]] ; then 212 + echo -e "FAIL\n\n" 213 + die "livepatch kselftest(s) failed" 214 + fi 215 + 216 + load_lp $MOD_TARGET_PATCH 217 + 218 + if [[ "$(cat /proc/$MOD_TARGET)" != "$MOD_TARGET_PATCH: this has been live patched" ]] ; then 219 + echo -e "FAIL\n\n" 220 + die "livepatch kselftest(s) failed" 221 + fi 222 + 223 + disable_lp $MOD_TARGET_PATCH 224 + unload_lp $MOD_TARGET_PATCH 225 + 226 + if [[ "$(cat /proc/$MOD_TARGET)" != "$MOD_TARGET: original output" ]] ; then 227 + echo -e "FAIL\n\n" 228 + die "livepatch kselftest(s) failed" 229 + fi 230 + 231 + unload_mod $MOD_TARGET 232 + 233 + check_result "% insmod test_modules/$MOD_TARGET.ko 234 + $MOD_TARGET: test_klp_mod_target_init 235 + % insmod test_modules/$MOD_TARGET_PATCH.ko 236 + livepatch: enabling patch '$MOD_TARGET_PATCH' 237 + livepatch: '$MOD_TARGET_PATCH': initializing patching transition 238 + livepatch: '$MOD_TARGET_PATCH': starting patching transition 239 + livepatch: '$MOD_TARGET_PATCH': completing patching transition 240 + livepatch: '$MOD_TARGET_PATCH': patching complete 241 + % echo 0 > $SYSFS_KLP_DIR/$MOD_TARGET_PATCH/enabled 242 + livepatch: '$MOD_TARGET_PATCH': initializing unpatching transition 243 + livepatch: '$MOD_TARGET_PATCH': starting unpatching transition 244 + livepatch: '$MOD_TARGET_PATCH': completing unpatching transition 245 + livepatch: '$MOD_TARGET_PATCH': unpatching complete 246 + % rmmod $MOD_TARGET_PATCH 247 + % rmmod $MOD_TARGET 248 + $MOD_TARGET: test_klp_mod_target_exit" 249 + 250 + 251 + # - load a livepatch that targets a not-yet-loaded module 252 + # - load the target module: klp_module_coming patches it immediately 253 + # - verify the proc entry returns livepatched output 254 + # - disable and unload the livepatch 255 + # - verify the proc entry returns original output again 256 + # - unload the target module 257 + 258 + start_test "module function patching (livepatch first)" 259 + 260 + load_lp $MOD_TARGET_PATCH 261 + load_mod $MOD_TARGET 262 + 263 + if [[ "$(cat /proc/$MOD_TARGET)" != "$MOD_TARGET_PATCH: this has been live patched" ]] ; then 264 + echo -e "FAIL\n\n" 265 + die "livepatch kselftest(s) failed" 266 + fi 267 + 268 + disable_lp $MOD_TARGET_PATCH 269 + unload_lp $MOD_TARGET_PATCH 270 + 271 + if [[ "$(cat /proc/$MOD_TARGET)" != "$MOD_TARGET: original output" ]] ; then 272 + echo -e "FAIL\n\n" 273 + die "livepatch kselftest(s) failed" 274 + fi 275 + 276 + unload_mod $MOD_TARGET 277 + 278 + check_result "% insmod test_modules/$MOD_TARGET_PATCH.ko 279 + livepatch: enabling patch '$MOD_TARGET_PATCH' 280 + livepatch: '$MOD_TARGET_PATCH': initializing patching transition 281 + livepatch: '$MOD_TARGET_PATCH': starting patching transition 282 + livepatch: '$MOD_TARGET_PATCH': completing patching transition 283 + livepatch: '$MOD_TARGET_PATCH': patching complete 284 + % insmod test_modules/$MOD_TARGET.ko 285 + livepatch: applying patch '$MOD_TARGET_PATCH' to loading module '$MOD_TARGET' 286 + $MOD_TARGET: test_klp_mod_target_init 287 + % echo 0 > $SYSFS_KLP_DIR/$MOD_TARGET_PATCH/enabled 288 + livepatch: '$MOD_TARGET_PATCH': initializing unpatching transition 289 + livepatch: '$MOD_TARGET_PATCH': starting unpatching transition 290 + livepatch: '$MOD_TARGET_PATCH': completing unpatching transition 291 + livepatch: '$MOD_TARGET_PATCH': unpatching complete 292 + % rmmod $MOD_TARGET_PATCH 293 + % rmmod $MOD_TARGET 294 + $MOD_TARGET: test_klp_mod_target_exit" 199 295 200 296 201 297 exit 0
+2
tools/testing/selftests/livepatch/test_modules/Makefile
··· 8 8 test_klp_callbacks_mod.o \ 9 9 test_klp_kprobe.o \ 10 10 test_klp_livepatch.o \ 11 + test_klp_mod_patch.o \ 12 + test_klp_mod_target.o \ 11 13 test_klp_shadow_vars.o \ 12 14 test_klp_state.o \ 13 15 test_klp_state2.o \
+53
tools/testing/selftests/livepatch/test_modules/test_klp_mod_patch.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // Copyright (C) 2026 Pablo Hugen <phugen@redhat.com> 3 + 4 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 5 + 6 + #include <linux/module.h> 7 + #include <linux/kernel.h> 8 + #include <linux/livepatch.h> 9 + #include <linux/seq_file.h> 10 + 11 + static int livepatch_mod_target_show(struct seq_file *m, void *v) 12 + { 13 + seq_printf(m, "%s: %s\n", THIS_MODULE->name, 14 + "this has been live patched"); 15 + return 0; 16 + } 17 + 18 + static struct klp_func funcs[] = { 19 + { 20 + .old_name = "test_klp_mod_target_show", 21 + .new_func = livepatch_mod_target_show, 22 + }, 23 + {}, 24 + }; 25 + 26 + static struct klp_object objs[] = { 27 + { 28 + .name = "test_klp_mod_target", 29 + .funcs = funcs, 30 + }, 31 + {}, 32 + }; 33 + 34 + static struct klp_patch patch = { 35 + .mod = THIS_MODULE, 36 + .objs = objs, 37 + }; 38 + 39 + static int test_klp_mod_patch_init(void) 40 + { 41 + return klp_enable_patch(&patch); 42 + } 43 + 44 + static void test_klp_mod_patch_exit(void) 45 + { 46 + } 47 + 48 + module_init(test_klp_mod_patch_init); 49 + module_exit(test_klp_mod_patch_exit); 50 + MODULE_LICENSE("GPL"); 51 + MODULE_INFO(livepatch, "Y"); 52 + MODULE_AUTHOR("Pablo Hugen <phugen@redhat.com>"); 53 + MODULE_DESCRIPTION("Livepatch test: patch for module-provided function");
+39
tools/testing/selftests/livepatch/test_modules/test_klp_mod_target.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // Copyright (C) 2026 Pablo Hugen <phugen@redhat.com> 3 + 4 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 5 + 6 + #include <linux/module.h> 7 + #include <linux/kernel.h> 8 + #include <linux/proc_fs.h> 9 + #include <linux/seq_file.h> 10 + 11 + static struct proc_dir_entry *pde; 12 + 13 + static noinline int test_klp_mod_target_show(struct seq_file *m, void *v) 14 + { 15 + seq_printf(m, "%s: %s\n", THIS_MODULE->name, "original output"); 16 + return 0; 17 + } 18 + 19 + static int test_klp_mod_target_init(void) 20 + { 21 + pr_info("%s\n", __func__); 22 + pde = proc_create_single("test_klp_mod_target", 0, NULL, 23 + test_klp_mod_target_show); 24 + if (!pde) 25 + return -ENOMEM; 26 + return 0; 27 + } 28 + 29 + static void test_klp_mod_target_exit(void) 30 + { 31 + pr_info("%s\n", __func__); 32 + proc_remove(pde); 33 + } 34 + 35 + module_init(test_klp_mod_target_init); 36 + module_exit(test_klp_mod_target_exit); 37 + MODULE_LICENSE("GPL"); 38 + MODULE_AUTHOR("Pablo Hugen <phugen@redhat.com>"); 39 + MODULE_DESCRIPTION("Livepatch test: target module with proc entry");