linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Beau Belgrave <beaub@linux.microsoft.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
	rostedt@goodmis.org, mathieu.desnoyers@efficios.com,
	dcook@linux.microsoft.com, alanau@linux.microsoft.com,
	brauner@kernel.org, akpm@linux-foundation.org,
	ebiederm@xmission.com, keescook@chromium.org, tglx@linutronix.de,
	linux-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCH v8 11/11] tracing/user_events: Limit global user_event count
Date: Fri, 24 Mar 2023 09:43:53 -0700	[thread overview]
Message-ID: <20230324164353.GA1790@kbox> (raw)
In-Reply-To: <d6c83572-17e1-93d4-65a0-d480989e54fb@suse.cz>

On Fri, Mar 24, 2023 at 09:54:48AM +0100, Vlastimil Babka wrote:
> On 3/24/23 01:18, Masami Hiramatsu (Google) wrote:
> > Hi Beau,
> > 
> > On Tue, 21 Feb 2023 13:11:43 -0800
> > Beau Belgrave <beaub@linux.microsoft.com> wrote:
> > 
> >> Operators want to be able to ensure enough tracepoints exist on the
> >> system for kernel components as well as for user components. Since there
> >> are only up to 64K events, by default allow up to half to be used by
> >> user events.
> >> 
> >> Add a boot parameter (user_events_max=%d) and a kernel sysctl parameter
> >> (kernel.user_events_max) to set a global limit that is honored among all
> >> groups on the system. This ensures hard limits can be setup to prevent
> >> user processes from consuming all event IDs on the system.
> > 
> > sysctl is good to me, but would we really need the kernel parameter?
> > The user_events starts using when user-space is up, so I think setting
> > the limit with sysctl is enough.
> > 
> > BTW, Vlastimil tried to add 'sysctl.*' kernel parameter support(*). If we
> > need a kernel cmdline support, I think this is more generic way. But it
> > seems the discussion has been stopped.
> 
> It was actually merged in 5.8. So sysctl should be sufficient with that.
> But maybe it's weird to start adding sysctls, when the rest of tracing
> tunables is AFAIK under /sys/kernel/tracing/ ?
> 

During the TraceFS meetings Steven runs I was asked to add a boot
parameter and sysctl for user_events to limit the max.

To me, it seems when user_events moves toward namespace awareness
sysctl might be easier to use from within a namespace to turn knobs.

Happy to change to whatever, but I want to see Steven and Masami agree
on the approach before doing so.

Steven, do you agree with Masami to move to just sysctl?

Thanks,
-Beau

> 
> > (*) https://patchwork.kernel.org/project/linux-mm/patch/20200427180433.7029-2-vbabka@suse.cz/
> > 
> > Thank you,
> > 
> >> 
> >> Signed-off-by: Beau Belgrave <beaub@linux.microsoft.com>
> >> ---
> >>  kernel/trace/trace_events_user.c | 59 ++++++++++++++++++++++++++++++++
> >>  1 file changed, 59 insertions(+)
> >> 
> >> diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
> >> index 222f2eb59c7c..6a5ebe243999 100644
> >> --- a/kernel/trace/trace_events_user.c
> >> +++ b/kernel/trace/trace_events_user.c
> >> @@ -20,6 +20,7 @@
> >>  #include <linux/types.h>
> >>  #include <linux/uaccess.h>
> >>  #include <linux/highmem.h>
> >> +#include <linux/init.h>
> >>  #include <linux/user_events.h>
> >>  #include "trace.h"
> >>  #include "trace_dynevent.h"
> >> @@ -61,6 +62,12 @@ struct user_event_group {
> >>  /* Group for init_user_ns mapping, top-most group */
> >>  static struct user_event_group *init_group;
> >>  
> >> +/* Max allowed events for the whole system */
> >> +static unsigned int max_user_events = 32768;
> >> +
> >> +/* Current number of events on the whole system */
> >> +static unsigned int current_user_events;
> >> +
> >>  /*
> >>   * Stores per-event properties, as users register events
> >>   * within a file a user_event might be created if it does not
> >> @@ -1241,6 +1248,8 @@ static int destroy_user_event(struct user_event *user)
> >>  {
> >>  	int ret = 0;
> >>  
> >> +	lockdep_assert_held(&event_mutex);
> >> +
> >>  	/* Must destroy fields before call removal */
> >>  	user_event_destroy_fields(user);
> >>  
> >> @@ -1257,6 +1266,11 @@ static int destroy_user_event(struct user_event *user)
> >>  	kfree(EVENT_NAME(user));
> >>  	kfree(user);
> >>  
> >> +	if (current_user_events > 0)
> >> +		current_user_events--;
> >> +	else
> >> +		pr_alert("BUG: Bad current_user_events\n");
> >> +
> >>  	return ret;
> >>  }
> >>  
> >> @@ -1744,6 +1758,11 @@ static int user_event_parse(struct user_event_group *group, char *name,
> >>  
> >>  	mutex_lock(&event_mutex);
> >>  
> >> +	if (current_user_events >= max_user_events) {
> >> +		ret = -EMFILE;
> >> +		goto put_user_lock;
> >> +	}
> >> +
> >>  	ret = user_event_trace_register(user);
> >>  
> >>  	if (ret)
> >> @@ -1755,6 +1774,7 @@ static int user_event_parse(struct user_event_group *group, char *name,
> >>  	dyn_event_init(&user->devent, &user_event_dops);
> >>  	dyn_event_add(&user->devent, &user->call);
> >>  	hash_add(group->register_table, &user->node, key);
> >> +	current_user_events++;
> >>  
> >>  	mutex_unlock(&event_mutex);
> >>  
> >> @@ -2386,6 +2406,43 @@ static int create_user_tracefs(void)
> >>  	return -ENODEV;
> >>  }
> >>  
> >> +static int __init set_max_user_events(char *str)
> >> +{
> >> +	if (!str)
> >> +		return 0;
> >> +
> >> +	if (kstrtouint(str, 0, &max_user_events))
> >> +		return 0;
> >> +
> >> +	return 1;
> >> +}
> >> +__setup("user_events_max=", set_max_user_events);
> >> +
> >> +static int set_max_user_events_sysctl(struct ctl_table *table, int write,
> >> +				      void *buffer, size_t *lenp, loff_t *ppos)
> >> +{
> >> +	int ret;
> >> +
> >> +	mutex_lock(&event_mutex);
> >> +
> >> +	ret = proc_douintvec(table, write, buffer, lenp, ppos);
> >> +
> >> +	mutex_unlock(&event_mutex);
> >> +
> >> +	return ret;
> >> +}
> >> +
> >> +static struct ctl_table user_event_sysctls[] = {
> >> +	{
> >> +		.procname	= "user_events_max",
> >> +		.data		= &max_user_events,
> >> +		.maxlen		= sizeof(unsigned int),
> >> +		.mode		= 0644,
> >> +		.proc_handler	= set_max_user_events_sysctl,
> >> +	},
> >> +	{}
> >> +};
> >> +
> >>  static int __init trace_events_user_init(void)
> >>  {
> >>  	int ret;
> >> @@ -2415,6 +2472,8 @@ static int __init trace_events_user_init(void)
> >>  	if (dyn_event_register(&user_event_dops))
> >>  		pr_warn("user_events could not register with dyn_events\n");
> >>  
> >> +	register_sysctl_init("kernel", user_event_sysctls);
> >> +
> >>  	return 0;
> >>  }
> >>  
> >> -- 
> >> 2.25.1
> >> 
> > 
> > 


  reply	other threads:[~2023-03-24 16:44 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-21 21:11 [PATCH v8 00/11] tracing/user_events: Remote write ABI Beau Belgrave
2023-02-21 21:11 ` [PATCH v8 01/11] tracing/user_events: Split header into uapi and kernel Beau Belgrave
2023-02-21 21:11 ` [PATCH v8 02/11] tracing/user_events: Track fork/exec/exit for mm lifetime Beau Belgrave
2023-02-21 21:11 ` [PATCH v8 03/11] tracing/user_events: Use remote writes for event enablement Beau Belgrave
2023-03-28 20:59   ` Steven Rostedt
2023-02-21 21:11 ` [PATCH v8 04/11] tracing/user_events: Fixup enable faults asyncly Beau Belgrave
2023-03-28 21:20   ` Steven Rostedt
2023-03-28 21:42     ` Beau Belgrave
2023-02-21 21:11 ` [PATCH v8 05/11] tracing/user_events: Add ioctl for disabling addresses Beau Belgrave
2023-02-21 21:11 ` [PATCH v8 06/11] tracing/user_events: Update self-tests to write ABI Beau Belgrave
2023-02-21 21:11 ` [PATCH v8 07/11] tracing/user_events: Add ABI self-test Beau Belgrave
2023-02-21 21:11 ` [PATCH v8 08/11] tracing/user_events: Use write ABI in example Beau Belgrave
2023-02-21 21:11 ` [PATCH v8 09/11] tracing/user_events: Update documentation for ABI Beau Belgrave
2023-03-24  0:06   ` Masami Hiramatsu
2023-03-24 16:47     ` Beau Belgrave
2023-02-21 21:11 ` [PATCH v8 10/11] tracing/user_events: Charge event allocs to cgroups Beau Belgrave
2023-02-21 21:11 ` [PATCH v8 11/11] tracing/user_events: Limit global user_event count Beau Belgrave
2023-03-24  0:18   ` Masami Hiramatsu
2023-03-24  8:54     ` Vlastimil Babka
2023-03-24 16:43       ` Beau Belgrave [this message]
2023-03-24 17:06         ` Steven Rostedt
2023-03-26 15:22           ` Masami Hiramatsu
2023-03-24  0:05 ` [PATCH v8 00/11] tracing/user_events: Remote write ABI Masami Hiramatsu

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=20230324164353.GA1790@kbox \
    --to=beaub@linux.microsoft.com \
    --cc=akpm@linux-foundation.org \
    --cc=alanau@linux.microsoft.com \
    --cc=brauner@kernel.org \
    --cc=dcook@linux.microsoft.com \
    --cc=ebiederm@xmission.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=vbabka@suse.cz \
    /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