Re: [PATCH v3 56/57] perf: Simplify perf_pmu_output_stop()

From: Peter Zijlstra
Date: Mon Jun 12 2023 - 14:55:37 EST


On Mon, Jun 12, 2023 at 09:19:19AM -0700, Linus Torvalds wrote:
> This patch looks completely broken to me.
>
> You now do
>
> if (err == -EAGAIN)
> goto restart;
>
> *within* the RCU-guarded section, and the "goto restart" will guard it again.

restart:
guard(rcu)();
list_for_each_entry_rcu(iter, &head, rb_entry) {
...
if (err == -EAGAIN)
goto restart;
}

So the restart is *before* the variable exists, eg. it's out-of-scope.

per the last email's guard.c, if changed like so:

void main(void)
{
int done = 0;
restart:
lock_guard(spin, moo, &lock);
for (;!done;) {
done = 1;
goto restart;
}
}

$ gcc -O2 -o guard guard.c && ./guard
spin_lock
spin_unlock
spin_lock
spin_unlock

Which is exactly the expected result.