From: Markus Elfring <Markus.Elfring@web.de>
To: Luis Chamberlain <mcgrof@kernel.org>, kdevops@lists.linux.dev
Cc: cocci@inria.fr, gost.dev@samsung.com,
Davidlohr Bueso <dave@stgolabs.net>, Jan Kara <jack@suse.cz>,
Julia Lawall <julia.lawall@inria.fr>
Subject: Re: [cocci] [PATCH kdevops] scripts/coccinelle/generation: add example generation script
Date: Sun, 6 Apr 2025 16:00:46 +0200 [thread overview]
Message-ID: <dc6b7ff7-8da7-4d02-8fb4-52593137bf11@web.de> (raw)
In-Reply-To: <20250403020123.1806887-1-mcgrof@kernel.org>
…
> +++ b/scripts/coccinelle/generation/check_for_atomic_calls.py
> @@ -0,0 +1,443 @@
…
> +header = f"""// SPDX-License-Identifier: GPL-2.0
…
> +/// Detect atomic context in ANY transitive caller (up to {max_depth} levels)
…
> +virtual after_start
> +virtual report
Can any code refinements trigger desirable effects?
+virtual after_start, report
…
> +@irq_handler_def@
> +identifier fn;
> +@@
> +(
> +DEFINE_IRQ_HANDLER(fn, ...)
> +|
> +DECLARE_TASKLET(fn, ...)
> +)
+(DEFINE_IRQ_HANDLER
+|DECLARE_TASKLET
+)(fn, ...)
…
> +@irq_func_names@
> +identifier fn =~ "(_irq|_intr|_isr|_napi|_poll|_tasklet|_softirq|_bh)$";
> +@@
+identifier fn =~ "_(?:i(?:rq|(?:nt|s)r)|napi|poll|tasklet|softirq|bh)$";
…
> +@interrupt_prefixed@
> +identifier fn =~ "^(irq_|intr_|isr_|napi_|poll_|do_softirq|tasklet_)";
> +@@
+identifier fn =~ "^(?:i(?:rq|(?:nt|s)r)|napi|poll|tasklet)_|do_softirq)";
…
> +@atomic_name{level} depends on after_start exists@
> +identifier virtual.transitive_caller;
> +identifier atomic_fn =~ "(_irq|_intr|_isr|_napi|_poll|_bh|_softirq|_tasklet|_atomic)$";
+identifier virtual.transitive_caller,
+ atomic_fn =~ "_(?:i(?:rq|(?:nt|s)r)|napi|poll|bh|softirq|tasklet|atomic)$";
…
> +++ b/scripts/coccinelle/generation/check_for_sleepy_calls.py
> @@ -0,0 +1,678 @@
…
> + f.write(f"""// SPDX-License-Identifier: GPL-2.0
…
> +def register_sleep_point(caller_func, sleep_func, file, line, reason=""):
…
> + if reason:
> + message = f"{{symbol}} {'VERIFIED' if expected_to_sleep else 'WARNING'}: {{caller_func}}() might sleep at {{file}}:{{line}} - {{reason}} (via {{sleep_func}})"
> + path_message = f" Call path: {{path_str}} → {{sleep_func}}"
> + print(message)
> + print(path_message)
> + else:
> + message = f"{{symbol}} {'VERIFIED' if expected_to_sleep else 'WARNING'}: {{caller_func}}() might sleep at {{file}}:{{line}} (via {{sleep_func}})"
> + path_message = f" Call path: {{path_str}} → {{sleep_func}}"
> + print(message)
> + print(path_message)
+ if reason:
+ message = f"{{symbol}} {'VERIFIED' if expected_to_sleep else 'WARNING'}: {{caller_func}}() might sleep at {{file}}:{{line}} - {{reason}} (via {{sleep_func}})"
+ else:
+ message = f"{{symbol}} {'VERIFIED' if expected_to_sleep else 'WARNING'}: {{caller_func}}() might sleep at {{file}}:{{line}} (via {{sleep_func}})"
+
+ print(message)
+ print(f" Call path: {{path_str}} → {{sleep_func}}")
> + # Store this for our final stats
> + if path:
> + path_value = path_str + " → " + sleep_func
> + else:
> + path_value = caller_func + " → " + sleep_func
+ path_value = " → ".join(((path_str if path else caller_func), sleep_func))
…
> +@check_sleep_names@
> +position p;
> +identifier fn;
> +identifier sleep_fn =~ "(_sleep|_timeout|_wait|_block|_sync|_lock|create_|alloc_|_kmalloc|_mutex)";
+identifier fn,
+ sleep_fn =~ "(?:_(sleep|timeout|wait|block|sync|lock|kmalloc|mutex)|(?:create|alloc)_)";
> +@@
> +fn(...) {{
> + <...
> + sleep_fn@p(...)
> + ...>
May the search pattern be really optional here?
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/fe67e5985c72582553ecde33cd7d6e6c2643ef00/docs/manual/cocci_syntax.tex#L802-806
https://github.com/coccinelle/coccinelle/blob/4093aad2da23ea5c86916de0a71f43032fc2bb2f/docs/manual/cocci_syntax.tex#L802-L806
…
> + if sleepy_func:
> + message = f"\n\n{{symbol}}: {{caller_func}}() can sleep at {{file}}:{{line}} - {{reason}} (via {{sleep_func}})"
> + print(message)
> + else:
> + message = f"\n\n{{symbol}}: {{caller_func}}() found to may sleep."
> + print(message)
+ if sleepy_func:
+ message = f"\n\n{{symbol}}: {{caller_func}}() can sleep at {{file}}:{{line}} - {{reason}} (via {{sleep_func}})"
+ else:
+ message = f"\n\n{{symbol}}: {{caller_func}}() found to may sleep."
+
+ print(message)
…
> +msg = f"✅ Generated {outfile} to check if '{target_func}' might sleep"
> +if sleepy_func:
> + msg = f"✅ Generated {outfile} to check if '{target_func}' calls '{sleepy_func}'"
> +print(msg)
+if sleepy_func:
+ msg = f"✅ Generated {outfile} to check if '{target_func}' calls '{sleepy_func}'"
+else:
+ msg = f"✅ Generated {outfile} to check if '{target_func}' might sleep"
+
+print(msg)
…
Regards,
Markus
next prev parent reply other threads:[~2025-04-06 14:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-03 2:01 [PATCH kdevops] scripts/coccinelle/generation: add example generation script Luis Chamberlain
2025-04-03 6:50 ` [cocci] " Markus Elfring
2025-04-06 14:00 ` Markus Elfring [this message]
2025-04-06 14:07 ` Julia Lawall
2025-04-06 15:00 ` Markus Elfring
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=dc6b7ff7-8da7-4d02-8fb4-52593137bf11@web.de \
--to=markus.elfring@web.de \
--cc=cocci@inria.fr \
--cc=dave@stgolabs.net \
--cc=gost.dev@samsung.com \
--cc=jack@suse.cz \
--cc=julia.lawall@inria.fr \
--cc=kdevops@lists.linux.dev \
--cc=mcgrof@kernel.org \
/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