diff --git a/Kconfig b/Kconfig index 48a80beab685..6c961991514a 100644 --- a/Kconfig +++ b/Kconfig @@ -30,3 +30,5 @@ source "crypto/Kconfig" source "lib/Kconfig" source "lib/Kconfig.debug" + +source "gaoyang3513/Kconfig" diff --git a/Makefile b/Makefile index 2b71b24eb9db..58e528557b44 100644 --- a/Makefile +++ b/Makefile @@ -624,6 +624,7 @@ net-y := net/ libs-y := lib/ core-y := usr/ virt-y := virt/ +drivers-y += gaoyang3513/ endif # KBUILD_EXTMOD ifeq ($(dot-config),1) @@ -1130,6 +1131,7 @@ export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds export LDFLAGS_vmlinux # used by scripts/package/Makefile export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux-alldirs)) arch Documentation include samples scripts tools) +export KBUILD_ALLDIRS += $(sort $(KBUILD_ALLDIRS) gaoyang3513) vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN) $(KBUILD_VMLINUX_LIBS) diff --git a/arch/arm64/configs/lubancat2_defconfig b/arch/arm64/configs/lubancat2_defconfig index d8a9296c3f6d..e99604956835 100644 --- a/arch/arm64/configs/lubancat2_defconfig +++ b/arch/arm64/configs/lubancat2_defconfig @@ -798,3 +798,5 @@ CONFIG_RCU_CPU_STALL_TIMEOUT=60 CONFIG_FUNCTION_TRACER=y CONFIG_BLK_DEV_IO_TRACE=y CONFIG_LKDTM=y + +CONFIG_TESTING_PSTORE=m diff --git a/gaoyang3513/Kconfig b/gaoyang3513/Kconfig new file mode 100644 index 000000000000..764d47775881 --- /dev/null +++ b/gaoyang3513/Kconfig @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 + +menu "Gaoyang3513 Custom" + +source "gaoyang3513/testings/Kconfig" + +endmenu diff --git a/gaoyang3513/Makefile b/gaoyang3513/Makefile new file mode 100644 index 000000000000..bcde418d3159 --- /dev/null +++ b/gaoyang3513/Makefile @@ -0,0 +1,2 @@ + +obj-y += testings/ \ No newline at end of file diff --git a/gaoyang3513/testings/Kconfig b/gaoyang3513/testings/Kconfig new file mode 100644 index 000000000000..c15b457c12bc --- /dev/null +++ b/gaoyang3513/testings/Kconfig @@ -0,0 +1,8 @@ +# +# Testings configuration +# + +config TESTING_PSTORE + tristate "Testing Pstore" + ---help--- + Testing Pstore diff --git a/gaoyang3513/testings/Makefile b/gaoyang3513/testings/Makefile new file mode 100644 index 000000000000..a2c07943d1ac --- /dev/null +++ b/gaoyang3513/testings/Makefile @@ -0,0 +1,2 @@ + +obj-$(CONFIG_TESTING_PSTORE) += pstore/ \ No newline at end of file diff --git a/gaoyang3513/testings/pstore/Makefile b/gaoyang3513/testings/pstore/Makefile new file mode 100644 index 000000000000..5db476756f64 --- /dev/null +++ b/gaoyang3513/testings/pstore/Makefile @@ -0,0 +1,71 @@ +#******************************************************************************* +# Gaoyang3513 All Right Reserved. +# Author : +# Version : V1.0.0 202x.xx.xx +# Description : +# Note : gaoyang3513@163.com Createe 202x.xx.xx +#******************************************************************************* + +#******************************************************************************* +# Path information +#******************************************************************************* +LOCAL_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) +KERNEL_DIR ?= $(realpath $(LOCAL_DIR)/../../../kernel) + +# Subdirectory +OUTPUT_DIR := $(LOCAL_DIR)/output +INSTALL_DIR ?= $(LOCAL_DIR)/__install +#$(info Output directoty : $(OUTPUT_DIR)) +#$(info Install directoty: $(INSTALL_DIR)) + +#******************************************************************************* +# Variables +#******************************************************************************* +MULTI_CORES ?= $(shell grep -c ^processor /proc/cpuinfo) + +#******************************************************************************* +# Compile configure +#******************************************************************************* +CC := $(CROSS_COMPILE)gcc +LD := $(CROSS_COMPILE)ld +AR := $(CROSS_COMPILE)ar +STRIP := $(CROSS_COMPILE)strip + +export ARCH CROSS_COMPILE +#******************************************************************************* +# Targets +#******************************************************************************* +.PHONY: init all clean install + +ifeq ($(KERNELRELEASE),) +all: init + @$(MAKE) modules -C $(KERNEL_DIR) M=$(LOCAL_DIR) -j$(MULTI_CORES) + @$(MAKE) modules_install -C $(KERNEL_DIR) M=$(LOCAL_DIR) INSTALL_MOD_PATH=$(KERNEL_DIR)/_install_modules INSTALL_MOD_DIR=private + +clean: + @for sub in $(SUB_DIRS); do \ + $(MAKE) clean -C $$sub || exit "$$?"; \ + done; +# Directory + @if [ -d $(LOCAL_DIR)/output ]; then rm -rf $(LOCAL_DIR)/output; fi; + @if [ -d $(LOCAL_DIR)/__install ]; then rm -rf $(LOCAL_DIR)/__install; fi; + @if [ -d $(LOCAL_DIR)/.tmp_versions ]; then rm -rf $(LOCAL_DIR)/.tmp_versions; fi; +# File + @for f in {Module.symvers,modules.order}; do \ + if [ -e $$f ]; then rm -rf $$f; fi; \ + done + +install: + @mkdir -p $(INSTALL_DIR) + @cp -arf $(OUTPUT_DIR)/. $(INSTALL_DIR) + +init: + @mkdir -p $(OUTPUT_DIR); + +else +# called from kernel build system: just declare what our modules are +obj-$(CONFIG_TESTING_PSTORE) += test_ps.o + + + +endif # ifeq ($(KERNELRELEASE),) diff --git a/gaoyang3513/testings/pstore/test_ps.c b/gaoyang3513/testings/pstore/test_ps.c new file mode 100644 index 000000000000..7be00dd9dcb1 --- /dev/null +++ b/gaoyang3513/testings/pstore/test_ps.c @@ -0,0 +1,82 @@ +#include +#include +#include +#include +#include +#include + +static unsigned int test_type; +module_param(test_type, uint, 0400); +MODULE_PARM_DESC(test_type, "set to 1 to try to OOM (default 0)"); + +static int trigger_oops(void) +{ + int *ptr = (int *)0; // 强制类型转换0地址为指针并尝试读取 + + printk(KERN_ALERT "Dereferenced NULL pointer value: %d\n", *ptr); + + return 0; +} + +static int trigger_oom(void) +{ + void *memory = NULL; + size_t memory_size = 0; + + printk(KERN_INFO "oom_trigger: Initializing the oom_trigger LKM\n"); + + memory_size = 100*1024*1024; + while (1) { // 尝试分配大块内存 + memory = vmalloc(memory_size); + if (!memory) { + printk(KERN_ALERT "oom_trigger: Memory allocation failed\n"); + break; + } + + // 仅为防止编译器优化,实际不访问分配的内存 + memset(memory, 0, memory_size); + } + + return 0; +} + +static int test_data = 0; +static struct rcu_head test_rcu_head; + +static void bad_rcu_callback(struct rcu_head *head) +{ + // 违规操作:在RCU回调函数中睡眠,这可能导致RCU grace period过长 + msleep(1000); + + // 违规操作:修改被RCU保护的数据结构 + test_data++; // 不应在RCU回调中修改全局变量 + + pr_info("Bad RCU callback executed\n"); +} + +static void trigger_rcu(void) +{ + pr_info("RCU error module loaded\n"); + + call_rcu(&test_rcu_head, bad_rcu_callback); +} + +static int trigger_init(void) { + if (test_type == 0) + trigger_oom(); + else if (test_type == 1) + trigger_oops(); + else if (test_type == 2) + trigger_rcu(); + + return 0; // 加载模块不应该有返回值,但这里返回0避免编译警告。 +} + +static void __exit trigger_exit(void) { + printk(KERN_INFO "oom_trigger: Exiting the oom_trigger LKM\n"); +} + +module_init(trigger_init); +module_exit(trigger_exit); + +MODULE_LICENSE("GPL");