From: Tao Zhou <tao.zhou@linux.dev>
To: Daniel Bristot de Oliveira <bristot@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Wim Van Sebroeck <wim@linux-watchdog.org>,
Guenter Roeck <linux@roeck-us.net>,
Jonathan Corbet <corbet@lwn.net>, Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Will Deacon <will@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Marco Elver <elver@google.com>,
Dmitry Vyukov <dvyukov@google.com>,
"Paul E. McKenney" <paulmck@kernel.org>,
Shuah Khan <skhan@linuxfoundation.org>,
Gabriele Paoloni <gpaoloni@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
Clark Williams <williams@redhat.com>,
Randy Dunlap <rdunlap@infradead.org>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-trace-devel@vger.kernel.org, Tao Zhou <tao.zhou@linux.dev>
Subject: Re: [PATCH V9 01/16] rv: Add Runtime Verification (RV) interface
Date: Sat, 30 Jul 2022 22:08:12 +0800 [thread overview]
Message-ID: <YuU7TGxm5pzmBFTx@geo.homenetwork> (raw)
In-Reply-To: <a4bfe038f50cb047bfb343ad0e12b0e646ab308b.1659052063.git.bristot@kernel.org>
On Fri, Jul 29, 2022 at 11:38:40AM +0200, Daniel Bristot de Oliveira wrote:
> +static int __rv_disable_monitor(struct rv_monitor_def *mdef, bool sync)
> +{
> + lockdep_assert_held(&rv_interface_lock);
> +
> + if (mdef->monitor->enabled) {
> + mdef->monitor->enabled = 0;
> + mdef->monitor->disable();
If call disable(), the @enabled is set 0 there.
> +
> + /*
> + * Wait for the execution of all events to finish.
> + * Otherwise, the data used by the monitor could
> + * be inconsistent. i.e., if the monitor is re-enabled.
> + */
> + if (sync)
> + tracepoint_synchronize_unregister();
> + return 1;
Return 0 indicate the actually disabling and successed.
> + }
> + return 0;
If disable a diabled monitor, return error(negative).
> +}
> +
> +/**
> + * rv_disable_monitor - disable a given runtime monitor
> + *
> + * Returns 0 on success.
> + */
> +int rv_disable_monitor(struct rv_monitor_def *mdef)
> +{
> + __rv_disable_monitor(mdef, true);
> + return 0;
Always return 0 here, whatever the return value of __rv_disable_monitor().
And this enforce me to look more here, see below.
> +}
> +static ssize_t enabled_monitors_write(struct file *filp, const char __user *user_buf,
> + size_t count, loff_t *ppos)
> +{
> + char buff[MAX_RV_MONITOR_NAME_SIZE + 2];
> + struct rv_monitor_def *mdef;
> + int retval = -EINVAL;
> + bool enable = true;
> + char *ptr = buff;
> + int len;
> +
> + if (count < 1 || count > MAX_RV_MONITOR_NAME_SIZE + 1)
> + return -EINVAL;
> +
> + memset(buff, 0, sizeof(buff));
> +
> + retval = simple_write_to_buffer(buff, sizeof(buff) - 1, ppos, user_buf, count);
> + if (retval < 0)
> + return -EFAULT;
> +
> + ptr = strim(buff);
> +
> + if (ptr[0] == '!') {
> + enable = false;
> + ptr++;
> + }
> +
> + len = strlen(ptr);
> + if (!len)
> + return count;
> +
> + mutex_lock(&rv_interface_lock);
> +
> + retval = -EINVAL;
> +
> + list_for_each_entry(mdef, &rv_monitors_list, list) {
> + if (strcmp(ptr, mdef->monitor->name) != 0)
> + continue;
> +
> + /*
> + * Monitor found!
> + */
> + if (enable)
> + retval = rv_enable_monitor(mdef);
> + else
> + retval = rv_disable_monitor(mdef);
About the retval here. If count == 1 and retval == 0, then
`retval = count` --> retval == 1. This retval will be returned to
user space and dedicate that how many character read and success
If retval is 1(it is not possiable, the return value of
da_monitor_init_*() called in enable callback in rv_enable_monitor()
will be 0, so that return value check is not needed, or any other functions
called in enable callback need to check the return value then, so I checked
the WARN_ONCE() called in macro rv_attach_trace_probe() which is called in
enable callback, if the WARN_ONCE is called, it means that something go wrong.
We need to check the return value of WARN_ONCE() in enable callback), the
return value will be returned to user space but actually the error(warn) happened.
User space do not know. They treat the two kind of return value 1 the same
but one is the write count value successed and another is the write error
value returned.
In enable callback, check rv_attach_trace_probe():
static int enable_wip(void)
{
int retval = 1;
/*
* Delete the check of return value of da_monitor_init_wip()
* because it is always 0
*/
da_monitor_init_wip();
retval &= rv_attach_trace_probe("wip", preempt_enable, handle_preempt_enable);
retval &= rv_attach_trace_probe("wip", sched_waking, handle_sched_waking);
retval &= rv_attach_trace_probe("wip", preempt_disable, handle_preempt_disable);
/*
* If the retval is not 0, it mean at least one rv_attach_trace_probe()
* is WARN_ONCE(). I am not sure that if the first WARN_ONCE() happened,
* then return directly or at here after all rv_attach_trace_probe() is
* called and check the retval is 0 or 1.
*/
if (retval)
return -1;
return retval;
}
> +
> + if (!retval)
> + retval = count;
> +
> + break;
> + }
> +/**
> + * rv_register_monitor - register a rv monitor.
> + * @monitor: The rv_monitor to be registered.
> + *
> + * Returns 0 if successful, error otherwise.
> + */
> +int rv_register_monitor(struct rv_monitor *monitor)
> +{
> + struct rv_monitor_def *r;
> + int retval = 0;
> +
> + if (strlen(monitor->name) >= MAX_RV_MONITOR_NAME_SIZE) {
s/>=/>/ no? The same check happened in patch 2. Thanks,
> + pr_info("Monitor %s has a name longer than %d\n", monitor->name,
> + MAX_RV_MONITOR_NAME_SIZE);
next prev parent reply other threads:[~2022-07-30 14:08 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-29 9:38 [PATCH V9 00/16] The Runtime Verification (RV) interface Daniel Bristot de Oliveira
2022-07-29 9:38 ` [PATCH V9 01/16] rv: Add " Daniel Bristot de Oliveira
2022-07-30 14:08 ` Tao Zhou [this message]
2022-07-30 17:01 ` Steven Rostedt
2022-07-30 22:05 ` Tao Zhou
2022-07-30 18:07 ` Daniel Bristot de Oliveira
2022-07-31 15:06 ` Tao Zhou
2022-07-31 15:56 ` Daniel Bristot de Oliveira
2022-07-31 16:48 ` Steven Rostedt
2022-07-31 16:47 ` Steven Rostedt
2022-07-31 17:01 ` Steven Rostedt
2022-07-31 17:49 ` Daniel Bristot de Oliveira
2022-07-31 17:53 ` Steven Rostedt
2022-07-29 9:38 ` [PATCH V9 02/16] rv: Add runtime reactors interface Daniel Bristot de Oliveira
2022-07-29 9:38 ` [PATCH V9 03/16] rv/include: Add helper functions for deterministic automata Daniel Bristot de Oliveira
2022-07-31 15:13 ` Tao Zhou
2022-07-31 16:02 ` Daniel Bristot de Oliveira
2022-07-31 18:17 ` Tao Zhou
2022-07-29 9:38 ` [PATCH V9 04/16] rv/include: Add deterministic automata monitor definition via C macros Daniel Bristot de Oliveira
2022-07-29 9:38 ` [PATCH V9 05/16] rv/include: Add instrumentation helper functions Daniel Bristot de Oliveira
2022-07-29 9:38 ` [PATCH V9 06/16] Documentation/rv: Add a basic documentation Daniel Bristot de Oliveira
2022-07-29 9:38 ` [PATCH V9 07/16] tools/rv: Add dot2c Daniel Bristot de Oliveira
2022-07-29 9:38 ` [PATCH V9 08/16] Documentation/rv: Add deterministic automaton documentation Daniel Bristot de Oliveira
2022-07-29 9:38 ` [PATCH V9 09/16] tools/rv: Add dot2k Daniel Bristot de Oliveira
2022-07-29 9:38 ` [PATCH V9 10/16] Documentation/rv: Add deterministic automata monitor synthesis documentation Daniel Bristot de Oliveira
2022-07-29 9:38 ` [PATCH V9 11/16] Documentation/rv: Add deterministic automata instrumentation documentation Daniel Bristot de Oliveira
2022-07-29 9:38 ` [PATCH V9 12/16] rv/monitor: Add the wip monitor skeleton created by dot2k Daniel Bristot de Oliveira
2022-07-29 9:38 ` [PATCH V9 13/16] rv/monitor: Add the wip monitor Daniel Bristot de Oliveira
2022-07-29 9:38 ` [PATCH V9 14/16] rv/monitor: Add the wwnr monitor Daniel Bristot de Oliveira
2022-07-29 9:38 ` [PATCH V9 15/16] rv/reactor: Add the printk reactor Daniel Bristot de Oliveira
2022-07-29 9:38 ` [PATCH V9 16/16] rv/reactor: Add the panic reactor Daniel Bristot de Oliveira
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=YuU7TGxm5pzmBFTx@geo.homenetwork \
--to=tao.zhou@linux.dev \
--cc=bristot@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=corbet@lwn.net \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=gpaoloni@redhat.com \
--cc=juri.lelli@redhat.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-devel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mingo@redhat.com \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=skhan@linuxfoundation.org \
--cc=tglx@linutronix.de \
--cc=will@kernel.org \
--cc=williams@redhat.com \
--cc=wim@linux-watchdog.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