The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Rik van Riel <riel@surriel.com>
To: Daniel Borkmann <daniel@iogearbox.net>
Cc: kernel-team@meta.com, Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman	 <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song	 <yonghong.song@linux.dev>,
	linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
	 "Paul E. McKenney"	 <paulmck@kernel.org>,
	Frederic Weisbecker <frederic@kernel.org>,
	Neeraj Upadhyay <neeraj.upadhyay@kernel.org>,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra	 <peterz@infradead.org>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH + QUESTION] bpf: use cond_resched_tasks_rcu_qs in  bpf_fd_array_map_clear() loop
Date: Thu, 16 Jul 2026 22:04:47 -0400	[thread overview]
Message-ID: <be9c5707e2d83090de28e4b0ce3bc43c67f423af.camel@surriel.com> (raw)
In-Reply-To: <20260715215314.44423f47@fangorn>

On Wed, 2026-07-15 at 21:53 -0400, Rik van Riel wrote:
> syzkaller creates a PROG_ARRAY with huge max_entries and triggers
> perf
> tracepoint open close in parallel. The hung task detector reports
> "INFO: task hung in perf_tp_event_init" with event_mutex held waiting
> for synchronize_rcu_tasks().
> 
OK, this is more interesting than it looked at first,
and this patch does not look like the right approach,
but I'm also not sure what other approach would work :(

The actual error being thrown is a hung task:



The syzkaller kernel failure is a tragedy in 3 parts.

First, we have perf_event_open() waiting on the event_mutex:

   syz.7.35551 (pid 31354, state D): perf_event_open 
  -> perf_tp_event_init
   -> perf_trace_init
    -> __mutex_lock
     -> blocked on event_mutex.


Second, we have perf_trace_destroy() indirectly
waiting in synchronize_rcu_tasks(), with the
event_mutex held.

    syz.5.35491 (state:I)  do_exit 
  -> task_work_run 
   -> __fput 
    -> perf_release
     -> perf_event_release_kernel
      -> __free_event
       -> perf_trace_destroy
        -> perf_trace_event_close
         -> reg(TRACE_REG_PERF_CLOSE)
          -> perf_ftrace_event_register
           -> perf_ftrace_function_unregister
            -> unregister_ftrace_function 
             -> ftrace_shutdown
              -> synchronize_rcu_tasks()   <-- BLOCKS HERE, forever,
holding event_mutex

Tasks RCU waits for every task to have gone through
a voluntary reschedule, before the grace period can
be advanced. A preemption does not count.


Third, we have a kworker looping for a very long time:
 
  kworker/0:0 (pid 9, TASK_RUNNING, on CPU0): process_one_work
  -> prog_array_map_clear_deferred
   -> bpf_fd_array_map_clear
    -> __fd_array_map_delete_elem. Looping over a huge PROG_ARRAY
max_entries.

With CONFIG_PREEMPT_LAZY=y this gets preempted,
but since involuntary preemptions do not count
for tasks RCU, that does nothnig to help
ftrace_shutdown() get unstuck.


How do we solve this?

Do we actually need to have cond_resched() points
quiesce the task RCU state when running with lazy
preempt, since those are points where we could
preempt voluntarily?

Do we need to prohibit calling synchronize_rcu_tasks()
while holding a mutex?

Do we need to do something else?

What is the best way forward here?

-- 
All Rights Reversed.

  parent reply	other threads:[~2026-07-17  2:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16  1:53 [PATCH + QUESTION] bpf: use cond_resched_tasks_rcu_qs in bpf_fd_array_map_clear() loop Rik van Riel
2026-07-16  3:17 ` Paul E. McKenney
2026-07-17  2:04 ` Rik van Riel [this message]
2026-07-17  4:21   ` Paul E. McKenney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=be9c5707e2d83090de28e4b0ce3bc43c67f423af.camel@surriel.com \
    --to=riel@surriel.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=frederic@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox