* [PATCH v2] coccinelle: mini_lock: improve performance when searching loops
@ 2026-07-27 13:52 Sang-Heon Jeon
2026-08-06 21:14 ` Julia Lawall
0 siblings, 1 reply; 2+ messages in thread
From: Sang-Heon Jeon @ 2026-07-27 13:52 UTC (permalink / raw)
To: Julia Lawall, Nicolas Palix; +Cc: cocci, linux-kernel
The 'looped' rule collects the returns inside a for loop to
prevent 'err' from reporting them. It searches every for loop in
the file, and on files with large loop bodies the search explodes.
For example, kernel/bpf/verifier.c runs for over 200 seconds,
almost entirely in 'looped' according to --profile. Since the
kernel .cocciconfig sets a 200 second timeout, coccicheck silently
skips the file.
To avoid this, collect the candidate returns first, so that
'looped' checks only those positions. 'err' then excludes what
'looped' found.
Every return that 'err' can report is also a candidate, so the
same returns are excluded as before and the output does not change.
A report-mode run over every .c file in the tree produces identical
output.
So verifier.c now finishes well within the timeout, in a few
seconds.
Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
---
Changes from v1 [1]
- remove unnecessary depends keyword as Julia suggested
- add exists keyword to 'looped' rule
[1] https://lore.kernel.org/all/20260725113303.691676-2-ekffu200098@gmail.com/
---
scripts/coccinelle/locks/mini_lock.cocci | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/scripts/coccinelle/locks/mini_lock.cocci b/scripts/coccinelle/locks/mini_lock.cocci
index 71065d8a5d54..c65241c895ff 100644
--- a/scripts/coccinelle/locks/mini_lock.cocci
+++ b/scripts/coccinelle/locks/mini_lock.cocci
@@ -53,11 +53,31 @@ spin_lock_irq@p1
spin_lock_irqsave@p1
) (E1@p,...);
-@looped@
+@err_candidate exists@
+expression E1;
+position prelocked.p;
+position up != prelocked.p1;
+position rc;
+identifier lock,unlock;
+@@
+
+lock(E1@p,...);
+... when != E1
+ when any
+if (...) {
+ ... when != E1
+ return@rc ...;
+}
+... when != E1
+ when any
+unlock@up(E1,...);
+
+@looped exists@
+position err_candidate.rc;
position r;
@@
-for(...;...;...) { <+... return@r ...; ...+> }
+for(...;...;...) { <+... return@rc@r ...; ...+> }
@err exists@
expression E1;
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v2] coccinelle: mini_lock: improve performance when searching loops
2026-07-27 13:52 [PATCH v2] coccinelle: mini_lock: improve performance when searching loops Sang-Heon Jeon
@ 2026-08-06 21:14 ` Julia Lawall
0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2026-08-06 21:14 UTC (permalink / raw)
To: Sang-Heon Jeon; +Cc: Nicolas Palix, cocci, linux-kernel
On Mon, 27 Jul 2026, Sang-Heon Jeon wrote:
> The 'looped' rule collects the returns inside a for loop to
> prevent 'err' from reporting them. It searches every for loop in
> the file, and on files with large loop bodies the search explodes.
>
> For example, kernel/bpf/verifier.c runs for over 200 seconds,
> almost entirely in 'looped' according to --profile. Since the
> kernel .cocciconfig sets a 200 second timeout, coccicheck silently
> skips the file.
>
> To avoid this, collect the candidate returns first, so that
> 'looped' checks only those positions. 'err' then excludes what
> 'looped' found.
>
> Every return that 'err' can report is also a candidate, so the
> same returns are excluded as before and the output does not change.
> A report-mode run over every .c file in the tree produces identical
> output.
>
> So verifier.c now finishes well within the timeout, in a few
> seconds.
Thanks for the fixes. Applied.
julia
>
> Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
> ---
> Changes from v1 [1]
> - remove unnecessary depends keyword as Julia suggested
> - add exists keyword to 'looped' rule
>
> [1] https://lore.kernel.org/all/20260725113303.691676-2-ekffu200098@gmail.com/
> ---
> scripts/coccinelle/locks/mini_lock.cocci | 24 ++++++++++++++++++++++--
> 1 file changed, 22 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/coccinelle/locks/mini_lock.cocci b/scripts/coccinelle/locks/mini_lock.cocci
> index 71065d8a5d54..c65241c895ff 100644
> --- a/scripts/coccinelle/locks/mini_lock.cocci
> +++ b/scripts/coccinelle/locks/mini_lock.cocci
> @@ -53,11 +53,31 @@ spin_lock_irq@p1
> spin_lock_irqsave@p1
> ) (E1@p,...);
>
> -@looped@
> +@err_candidate exists@
> +expression E1;
> +position prelocked.p;
> +position up != prelocked.p1;
> +position rc;
> +identifier lock,unlock;
> +@@
> +
> +lock(E1@p,...);
> +... when != E1
> + when any
> +if (...) {
> + ... when != E1
> + return@rc ...;
> +}
> +... when != E1
> + when any
> +unlock@up(E1,...);
> +
> +@looped exists@
> +position err_candidate.rc;
> position r;
> @@
>
> -for(...;...;...) { <+... return@r ...; ...+> }
> +for(...;...;...) { <+... return@rc@r ...; ...+> }
>
> @err exists@
> expression E1;
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-06 21:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-27 13:52 [PATCH v2] coccinelle: mini_lock: improve performance when searching loops Sang-Heon Jeon
2026-08-06 21:14 ` Julia Lawall
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®