--- y/include/linux/sched.h
+++ x/include/linux/sched.h
@@ -944,6 +944,9 @@ struct task_struct {
 #ifdef	CONFIG_CPU_SUP_INTEL
 	unsigned			reported_split_lock:1;
 #endif
+#ifdef CONFIG_BPF_EVENTS
+	unsigned			in_bpf_trace_printk:1;
+#endif
 
 	unsigned long			atomic_flags; /* Flags requiring atomic access. */
 
--- y/kernel/trace/bpf_trace.c
+++ x/kernel/trace/bpf_trace.c
@@ -2041,10 +2041,14 @@ void bpf_put_raw_tracepoint(struct bpf_r
 static __always_inline
 void __bpf_trace_run(struct bpf_prog *prog, u64 *args)
 {
+	if (current->in_bpf_trace_printk)
+		return;
 	cant_sleep();
+	current->in_bpf_trace_printk = 1;
 	rcu_read_lock();
 	(void) bpf_prog_run(prog, args);
 	rcu_read_unlock();
+	current->in_bpf_trace_printk = 0;
 }
 
 #define UNPACK(...)			__VA_ARGS__