2019-06-12 18:07:24

by Divya Indi

[permalink] [raw]
Subject: [PATCH 1/3] tracing: Relevant changes for kernel access to Ftrace instances.

For commit f45d1225adb0 ("tracing: Kernel access to Ftrace instances")
Adding the following changes to ensure other kernel components can
use these functions -
1) Remove static keyword for newly exported fn - ftrace_set_clr_event.
2) Add the req functions to header file include/linux/trace_events.h.

Signed-off-by: Divya Indi <[email protected]>
---
include/linux/trace_events.h | 6 ++++++
kernel/trace/trace_events.c | 2 +-
2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index 8a62731..d7b7d85 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -539,6 +539,12 @@ extern int trace_define_field(struct trace_event_call *call, const char *type,

#define is_signed_type(type) (((type)(-1)) < (type)1)

+void trace_printk_init_buffers(void);
+int trace_array_printk(struct trace_array *tr, unsigned long ip,
+ const char *fmt, ...);
+struct trace_array *trace_array_create(const char *name);
+int trace_array_destroy(struct trace_array *tr);
+int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set);
int trace_set_clr_event(const char *system, const char *event, int set);

/*
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 0ce3db6..b6b4618 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -795,7 +795,7 @@ static int __ftrace_set_clr_event(struct trace_array *tr, const char *match,
return ret;
}

-static int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
+int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
{
char *event = NULL, *sub = NULL, *match;
int ret;
--
1.8.3.1


2019-06-12 18:08:37

by Divya Indi

[permalink] [raw]
Subject: [PATCH 2/3] tracing: Adding additional NULL checks.

commit f45d1225adb0 ("tracing: Kernel access to Ftrace instances")
exported certain functions providing access to Ftrace instances from
other kernel components.
Adding some additional NULL checks to ensure safe usage by the users.

Signed-off-by: Divya Indi <[email protected]>
---
kernel/trace/trace.c | 3 +++
kernel/trace/trace_events.c | 2 ++
2 files changed, 5 insertions(+)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 1c80521..a60dc13 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3205,6 +3205,9 @@ int trace_array_printk(struct trace_array *tr,
if (!(global_trace.trace_flags & TRACE_ITER_PRINTK))
return 0;

+ if (!tr)
+ return -EINVAL;
+
va_start(ap, fmt);
ret = trace_array_vprintk(tr, ip, fmt, ap);
va_end(ap);
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index b6b4618..445b059 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -800,6 +800,8 @@ int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
char *event = NULL, *sub = NULL, *match;
int ret;

+ if (!tr)
+ return -ENODEV;
/*
* The buf format can be <subsystem>:<event-name>
* *:<event-name> means any event by that name.
--
1.8.3.1

2019-06-17 23:34:55

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH 1/3] tracing: Relevant changes for kernel access to Ftrace instances.

On Wed, 12 Jun 2019 09:34:17 -0700
Divya Indi <[email protected]> wrote:

Hi Divya,

First, make sure the patches are all replied to the cover patch [0/3].
That is, patch 1, 2 and 3 should all be in reply to [0/3] to see a all
the patches at the same level, and that makes replies easy to stand out.

Having patch 2 a reply to patch 1 and patch 3 a reply to patch 2, makes
it hard to see what comments are for what patches.

> For commit f45d1225adb0 ("tracing: Kernel access to Ftrace instances")
> Adding the following changes to ensure other kernel components can
> use these functions -
> 1) Remove static keyword for newly exported fn - ftrace_set_clr_event.
> 2) Add the req functions to header file include/linux/trace_events.h.

The above change log is hard to parse. The "Adding" looks to be a start
of a new sentence, and what changes and what components can use these
functions?

Also avoid shorten words ("fn", "req") that just makes trying to figure
out what is being said that more confusing.

>
> Signed-off-by: Divya Indi <[email protected]>
> ---
> include/linux/trace_events.h | 6 ++++++
> kernel/trace/trace_events.c | 2 +-
> 2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
> index 8a62731..d7b7d85 100644
> --- a/include/linux/trace_events.h
> +++ b/include/linux/trace_events.h
> @@ -539,6 +539,12 @@ extern int trace_define_field(struct trace_event_call *call, const char *type,
>
> #define is_signed_type(type) (((type)(-1)) < (type)1)
>
> +void trace_printk_init_buffers(void);
> +int trace_array_printk(struct trace_array *tr, unsigned long ip,
> + const char *fmt, ...);
> +struct trace_array *trace_array_create(const char *name);
> +int trace_array_destroy(struct trace_array *tr);
> +int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set);

These function are declared elsewhere. If we are adding them here, then
they should be removed from the other places.

But trace_events.h is not the proper place to put these. The
trace_events.h file is only for code used in the TRACE_EVENT() macros.

The proper file is include/linux/trace.h

-- Steve

> int trace_set_clr_event(const char *system, const char *event, int set);
>
> /*
> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index 0ce3db6..b6b4618 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
> @@ -795,7 +795,7 @@ static int __ftrace_set_clr_event(struct trace_array *tr, const char *match,
> return ret;
> }
>
> -static int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
> +int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
> {
> char *event = NULL, *sub = NULL, *match;
> int ret;

2019-06-17 23:37:29

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH 2/3] tracing: Adding additional NULL checks.

On Wed, 12 Jun 2019 09:34:18 -0700
Divya Indi <[email protected]> wrote:

> commit f45d1225adb0 ("tracing: Kernel access to Ftrace instances")
> exported certain functions providing access to Ftrace instances from
> other kernel components.

I'm fine with the patch, the above statement is hard to understand.

-- Steve

> Adding some additional NULL checks to ensure safe usage by the users.
>
> Signed-off-by: Divya Indi <[email protected]>
> ---
> kernel/trace/trace.c | 3 +++
> kernel/trace/trace_events.c | 2 ++
> 2 files changed, 5 insertions(+)
>
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 1c80521..a60dc13 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -3205,6 +3205,9 @@ int trace_array_printk(struct trace_array *tr,
> if (!(global_trace.trace_flags & TRACE_ITER_PRINTK))
> return 0;
>
> + if (!tr)
> + return -EINVAL;
> +
> va_start(ap, fmt);
> ret = trace_array_vprintk(tr, ip, fmt, ap);
> va_end(ap);
> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index b6b4618..445b059 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
> @@ -800,6 +800,8 @@ int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
> char *event = NULL, *sub = NULL, *match;
> int ret;
>
> + if (!tr)
> + return -ENODEV;
> /*
> * The buf format can be <subsystem>:<event-name>
> * *:<event-name> means any event by that name.