diff --git a/patches.suse/fprobe-add-recursion-detection-in-fprobe_exit_handler.patch b/patches.suse/fprobe-add-recursion-detection-in-fprobe_exit_handler.patch new file mode 100644 index 0000000..a6c9425 --- /dev/null +++ b/patches.suse/fprobe-add-recursion-detection-in-fprobe_exit_handler.patch @@ -0,0 +1,77 @@ +From: Ze Gao +Date: Wed, 17 May 2023 11:45:08 +0800 +Subject: fprobe: add recursion detection in fprobe_exit_handler +Git-commit: 2752741080f84f9b2fc93fa92735315d10a415bf +Patch-mainline: v6.4-rc3 +References: git-fixes + +fprobe_hander and fprobe_kprobe_handler has guarded ftrace recursion +detection but fprobe_exit_handler has not, which possibly introduce +recursive calls if the fprobe exit callback calls any traceable +functions. Checking in fprobe_hander or fprobe_kprobe_handler +is not enough and misses this case. + +So add recursion free guard the same way as fprobe_hander. Since +ftrace recursion check does not employ ip(s), so here use entry_ip and +entry_parent_ip the same as fprobe_handler. + +Link: https://lore.kernel.org/all/20230517034510.15639-4-zegao@tencent.com/ + +Fixes: 5b0ab78998e3 ("fprobe: Add exit_handler support") +Signed-off-by: Ze Gao +Cc: stable@vger.kernel.org +Acked-by: Masami Hiramatsu (Google) +Signed-off-by: Masami Hiramatsu (Google) +Acked-by: Petr Pavlu +--- + kernel/trace/fprobe.c | 14 ++++++++++++++ + 1 file changed, 14 insertions(+) + +diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c +index 7a692c02f787..18d36842faf5 100644 +--- a/kernel/trace/fprobe.c ++++ b/kernel/trace/fprobe.c +@@ -17,6 +17,7 @@ + struct fprobe_rethook_node { + struct rethook_node node; + unsigned long entry_ip; ++ unsigned long entry_parent_ip; + }; + + static inline void __fprobe_handler(unsigned long ip, unsigned long parent_ip, +@@ -39,6 +40,7 @@ static inline void __fprobe_handler(unsigned long ip, unsigned long parent_ip, + } + fpr = container_of(rh, struct fprobe_rethook_node, node); + fpr->entry_ip = ip; ++ fpr->entry_parent_ip = parent_ip; + rethook_hook(rh, ftrace_get_regs(fregs), true); + } + } +@@ -114,14 +116,26 @@ static void fprobe_exit_handler(struct rethook_node *rh, void *data, + { + struct fprobe *fp = (struct fprobe *)data; + struct fprobe_rethook_node *fpr; ++ int bit; + + if (!fp || fprobe_disabled(fp)) + return; + + fpr = container_of(rh, struct fprobe_rethook_node, node); + ++ /* ++ * we need to assure no calls to traceable functions in-between the ++ * end of fprobe_handler and the beginning of fprobe_exit_handler. ++ */ ++ bit = ftrace_test_recursion_trylock(fpr->entry_ip, fpr->entry_parent_ip); ++ if (bit < 0) { ++ fp->nmissed++; ++ return; ++ } ++ + fp->exit_handler(fp, fpr->entry_ip, regs); ++ ftrace_test_recursion_unlock(bit); + } + NOKPROBE_SYMBOL(fprobe_exit_handler); + + static int symbols_cmp(const void *a, const void *b) + diff --git a/patches.suse/fprobe-make-fprobe_kprobe_handler-recursion-free.patch b/patches.suse/fprobe-make-fprobe_kprobe_handler-recursion-free.patch new file mode 100644 index 0000000..95674ed --- /dev/null +++ b/patches.suse/fprobe-make-fprobe_kprobe_handler-recursion-free.patch @@ -0,0 +1,145 @@ +From: Ze Gao +Date: Wed, 17 May 2023 11:45:07 +0800 +Subject: fprobe: make fprobe_kprobe_handler recursion free +Git-commit: 3cc4e2c5fbae84e5033723fb7e350bc6c164e3a2 +Patch-mainline: v6.4-rc3 +References: git-fixes + +Current implementation calls kprobe related functions before doing +ftrace recursion check in fprobe_kprobe_handler, which opens door +to kernel crash due to stack recursion if preempt_count_{add, sub} +is traceable in kprobe_busy_{begin, end}. + +Things goes like this without this patch quoted from Steven: +" +fprobe_kprobe_handler() { + kprobe_busy_begin() { + preempt_disable() { + preempt_count_add() { <-- trace + fprobe_kprobe_handler() { + [ wash, rinse, repeat, CRASH!!! ] +" + +By refactoring the common part out of fprobe_kprobe_handler and +fprobe_handler and call ftrace recursion detection at the very beginning, +the whole fprobe_kprobe_handler is free from recursion. + +[ Fix the indentation of __fprobe_handler() parameters. ] + +Link: https://lore.kernel.org/all/20230517034510.15639-3-zegao@tencent.com/ + +Fixes: ab51e15d535e ("fprobe: Introduce FPROBE_FL_KPROBE_SHARED flag for fprobe") +Signed-off-by: Ze Gao +Acked-by: Masami Hiramatsu (Google) +Cc: stable@vger.kernel.org +Signed-off-by: Masami Hiramatsu (Google) +Acked-by: Petr Pavlu +--- + kernel/trace/fprobe.c | 59 ++++++++++++++++++++++++++++++++++++++------------- + 1 file changed, 44 insertions(+), 15 deletions(-) + +diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c +index 293184227394..7a692c02f787 100644 +--- a/kernel/trace/fprobe.c ++++ b/kernel/trace/fprobe.c +@@ -20,32 +20,23 @@ struct fprobe_rethook_node { + unsigned long entry_ip; + }; + +-static void fprobe_handler(unsigned long ip, unsigned long parent_ip, +- struct ftrace_ops *ops, struct ftrace_regs *fregs) ++static inline void __fprobe_handler(unsigned long ip, unsigned long parent_ip, ++ struct ftrace_ops *ops, struct ftrace_regs *fregs) + { + struct fprobe_rethook_node *fpr; + struct rethook_node *rh; + struct fprobe *fp; +- int bit; + + fp = container_of(ops, struct fprobe, ops); +- if (fprobe_disabled(fp)) +- return; +- +- bit = ftrace_test_recursion_trylock(ip, parent_ip); +- if (bit < 0) { +- fp->nmissed++; +- return; +- } + + if (fp->entry_handler) + fp->entry_handler(fp, ip, ftrace_get_regs(fregs)); + + if (fp->exit_handler) { + rh = rethook_try_get(fp->rethook); + if (!rh) { + fp->nmissed++; +- goto out; ++ return; + } + fpr = container_of(rh, struct fprobe_rethook_node, node); + fpr->entry_ip = ip; +@@ -61,23 +53,59 @@ static void fprobe_handler(unsigned long ip, unsigned long parent_ip, + rethook_hook(rh, ftrace_get_regs(fregs), true); + } +- +-out: ++} ++ ++static void fprobe_handler(unsigned long ip, unsigned long parent_ip, ++ struct ftrace_ops *ops, struct ftrace_regs *fregs) ++{ ++ struct fprobe *fp; ++ int bit; ++ ++ fp = container_of(ops, struct fprobe, ops); ++ if (fprobe_disabled(fp)) ++ return; ++ ++ /* recursion detection has to go before any traceable function and ++ * all functions before this point should be marked as notrace ++ */ ++ bit = ftrace_test_recursion_trylock(ip, parent_ip); ++ if (bit < 0) { ++ fp->nmissed++; ++ return; ++ } ++ __fprobe_handler(ip, parent_ip, ops, fregs); + ftrace_test_recursion_unlock(bit); ++ + } + NOKPROBE_SYMBOL(fprobe_handler); + + static void fprobe_kprobe_handler(unsigned long ip, unsigned long parent_ip, + struct ftrace_ops *ops, struct ftrace_regs *fregs) + { +- struct fprobe *fp = container_of(ops, struct fprobe, ops); ++ struct fprobe *fp; ++ int bit; ++ ++ fp = container_of(ops, struct fprobe, ops); ++ if (fprobe_disabled(fp)) ++ return; ++ ++ /* recursion detection has to go before any traceable function and ++ * all functions called before this point should be marked as notrace ++ */ ++ bit = ftrace_test_recursion_trylock(ip, parent_ip); ++ if (bit < 0) { ++ fp->nmissed++; ++ return; ++ } + + if (unlikely(kprobe_running())) { + fp->nmissed++; + return; + } ++ + kprobe_busy_begin(); +- fprobe_handler(ip, parent_ip, ops, fregs); ++ __fprobe_handler(ip, parent_ip, ops, fregs); + kprobe_busy_end(); ++ ftrace_test_recursion_unlock(bit); + } + + static void fprobe_exit_handler(struct rethook_node *rh, void *data, + diff --git a/patches.suse/rethook-use-preempt_-disable-enable-_notrace-in-rethook_trampoline_handler.patch b/patches.suse/rethook-use-preempt_-disable-enable-_notrace-in-rethook_trampoline_handler.patch new file mode 100644 index 0000000..1547d24 --- /dev/null +++ b/patches.suse/rethook-use-preempt_-disable-enable-_notrace-in-rethook_trampoline_handler.patch @@ -0,0 +1,48 @@ +From: Ze Gao +Date: Wed, 17 May 2023 11:45:06 +0800 +Subject: rethook: use preempt_{disable, enable}_notrace in + rethook_trampoline_handler +Git-commit: be243bacfb25f5219f2396d787408e8cf1301dd1 +Patch-mainline: v6.4-rc3 +References: git-fixes + +This patch replaces preempt_{disable, enable} with its corresponding +notrace version in rethook_trampoline_handler so no worries about stack +recursion or overflow introduced by preempt_count_{add, sub} under +fprobe + rethook context. + +Link: https://lore.kernel.org/all/20230517034510.15639-2-zegao@tencent.com/ + +Fixes: 54ecbe6f1ed5 ("rethook: Add a generic return hook") +Signed-off-by: Ze Gao +Acked-by: Masami Hiramatsu (Google) +Cc: +Signed-off-by: Masami Hiramatsu (Google) +Acked-by: Petr Pavlu +--- + kernel/trace/rethook.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c +index 32c3dfdb4d6a..60f6cb2b486b 100644 +--- a/kernel/trace/rethook.c ++++ b/kernel/trace/rethook.c +@@ -288,7 +288,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs, + * These loops must be protected from rethook_free_rcu() because those + * are accessing 'rhn->rethook'. + */ +- preempt_disable(); ++ preempt_disable_notrace(); + + /* + * Run the handler on the shadow stack. Do not unlink the list here because +@@ -321,7 +321,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs, + first = first->next; + rethook_recycle(rhn); + } +- preempt_enable(); ++ preempt_enable_notrace(); + + return correct_ret_addr; + } + diff --git a/patches.suse/trace-hwlat-Do-not-start-per-cpu-thread-if-it-is-already-running.patch b/patches.suse/trace-hwlat-Do-not-start-per-cpu-thread-if-it-is-already-running.patch index 2364180..c83b503 100644 --- a/patches.suse/trace-hwlat-Do-not-start-per-cpu-thread-if-it-is-already-running.patch +++ b/patches.suse/trace-hwlat-Do-not-start-per-cpu-thread-if-it-is-already-running.patch @@ -39,14 +39,14 @@ index edc26dc22c3f..c4945f8adc11 100644 --- a/kernel/trace/trace_hwlat.c +++ b/kernel/trace/trace_hwlat.c @@ -492,6 +492,10 @@ static int start_cpu_kthread(unsigned int cpu) + { struct task_struct *kthread; - char comm[24]; + /* Do not start a new hwlatd thread if it is already running */ + if (per_cpu(hwlat_per_cpu_data, cpu).kthread) + return 0; + - snprintf(comm, 24, "hwlatd/%d", cpu); - - kthread = kthread_create_on_cpu(kthread_fn, NULL, cpu, comm); + kthread = kthread_run_on_cpu(kthread_fn, NULL, cpu, "hwlatd/%u"); + if (IS_ERR(kthread)) { + pr_err(BANNER "could not start sampling thread\n"); diff --git a/patches.suse/trace-hwlat-make-use-of-the-helper-function-kthread_run_on_cpu.patch b/patches.suse/trace-hwlat-make-use-of-the-helper-function-kthread_run_on_cpu.patch new file mode 100644 index 0000000..eff16e8 --- /dev/null +++ b/patches.suse/trace-hwlat-make-use-of-the-helper-function-kthread_run_on_cpu.patch @@ -0,0 +1,56 @@ +From: Cai Huoqing +Date: Fri, 14 Jan 2022 14:03:10 -0800 +Subject: trace/hwlat: make use of the helper function kthread_run_on_cpu() +Git-commit: ff78f6679d2e223e073fcbdc8f70b6bc0abadf99 +Patch-mainline: v5.17-rc1 +References: git-fixes + +Replace kthread_create_on_cpu/wake_up_process() with kthread_run_on_cpu() +to simplify the code. + +Link: https://lkml.kernel.org/r/20211022025711.3673-7-caihuoqing@baidu.com +Signed-off-by: Cai Huoqing +Cc: Bernard Metzler +Cc: Daniel Bristot de Oliveira +Cc: Davidlohr Bueso +Cc: Doug Ledford +Cc: Ingo Molnar +Cc: Jason Gunthorpe +Cc: Joel Fernandes (Google) +Cc: Josh Triplett +Cc: Lai Jiangshan +Cc: Mathieu Desnoyers +Cc: "Paul E . McKenney" +Cc: Steven Rostedt +Signed-off-by: Andrew Morton +Signed-off-by: Linus Torvalds +Acked-by: Petr Pavlu +--- + kernel/trace/trace_hwlat.c | 6 +----- + 1 file changed, 1 insertion(+), 5 deletions(-) + +diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c +index 56bb7b890578..d440ddd5fd8b 100644 +--- a/kernel/trace/trace_hwlat.c ++++ b/kernel/trace/trace_hwlat.c +@@ -491,18 +491,14 @@ static void stop_per_cpu_kthreads(void) + static int start_cpu_kthread(unsigned int cpu) + { + struct task_struct *kthread; +- char comm[24]; + +- snprintf(comm, 24, "hwlatd/%d", cpu); +- +- kthread = kthread_create_on_cpu(kthread_fn, NULL, cpu, comm); ++ kthread = kthread_run_on_cpu(kthread_fn, NULL, cpu, "hwlatd/%u"); + if (IS_ERR(kthread)) { + pr_err(BANNER "could not start sampling thread\n"); + return -ENOMEM; + } + + per_cpu(hwlat_per_cpu_data, cpu).kthread = kthread; +- wake_up_process(kthread); + + return 0; + } + diff --git a/series.conf b/series.conf index bc0d207..5d5044b 100644 --- a/series.conf +++ b/series.conf @@ -16935,6 +16935,7 @@ patches.suse/i2c-bcm2835-Use-platform_get_irq-to-get-the-interrup.patch patches.suse/kthread-add-the-helper-function-kthread_run_on_cpu.patch patches.suse/RDMA-siw-make-use-of-the-helper-function-kthread_run.patch + patches.suse/trace-hwlat-make-use-of-the-helper-function-kthread_run_on_cpu.patch patches.suse/mm-page_alloc-split-prep_compound_page-into-head-and-tail-subparts.patch patches.suse/mm-page_alloc-refactor-memmap_init_zone_device-page-init.patch patches.suse/mm-memremap-add-ZONE_DEVICE-support-for-compound-pages.patch @@ -40094,6 +40095,9 @@ patches.suse/drm-amd-pm-parse-pp_handle-under-appropriate-conditi.patch patches.suse/drm-amdgpu-Fix-vram-recover-doesn-t-work-after-whole.patch patches.suse/drm-amdgpu-change-gfx-11.0.4-external_id-range.patch + patches.suse/rethook-use-preempt_-disable-enable-_notrace-in-rethook_trampoline_handler.patch + patches.suse/fprobe-make-fprobe_kprobe_handler-recursion-free.patch + patches.suse/fprobe-add-recursion-detection-in-fprobe_exit_handler.patch patches.suse/thunderbolt-Clear-registers-properly-when-auto-clear.patch ########################################################