lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Sun, 21 Dec 2014 19:47:53 +0100
From:	Bruno Prémont <bonbons@...ux-vserver.org>
To:	dwalker@...o99.com
Cc:	Andrew Morton <akpm@...ux-foundation.org>,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] printk: add per console loglevel

On Sat, 20 December 2014 dwalker@...o99.com wrote:
> This adds to to the console= command line options allowing the
> addition of a per console log level setting.
> 
> examples,
> 
> 	console=ttyS0,ll4
> 	console=tty0,ll6
> 
> This can be used on systems which have multiple serial consoles, but
> it's desired for logging to be light on one and heavy on another.

Looks useful to me.
What would be the best way to make these per-console loglevels
configurable at runtime? `dmesg -n $LEVEL` only affects the global
limit.

One drawback to letting global loglevel have precedence is that
all consoles that should not get detailed log messages need to have
their loglevel explicitly lowered and it's not possible to have
one console forced to show more than the global loglevel.


An approach I would prefer is to have all consoles follow global
loglevel except when something different had been explicitly requested
for them.
This way a single console can be added later on (e.g. netconsole)
and set to pass through debug messages without affecting anyone else.

Bruno

> Signed-off-by: Daniel Walker <dwalker@...o99.com>
> ---
>  Documentation/kernel-parameters.txt | 24 ++++++++++++++++++------
>  include/linux/console.h             |  1 +
>  kernel/printk/console_cmdline.h     |  9 +++++----
>  kernel/printk/printk.c              | 37 ++++++++++++++++++++++++++++++++++++-
>  4 files changed, 60 insertions(+), 11 deletions(-)
> 
> diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
> index 4df73da..7e65d5b 100644
> --- a/Documentation/kernel-parameters.txt
> +++ b/Documentation/kernel-parameters.txt
> @@ -696,30 +696,42 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
>  
>  	console=	[KNL] Output console device and options.
>  
> -		tty<n>	Use the virtual console device <n>.
> +		tty<n>[,llX]	Use the virtual console device <n>.
>  
> -		ttyS<n>[,options]
> -		ttyUSB0[,options]
> +		ttyS<n>[,options][,llX]
> +		ttyUSB0[,options][,llX]
>  			Use the specified serial port.  The options are of
>  			the form "bbbbpnf", where "bbbb" is the baud rate,
>  			"p" is parity ("n", "o", or "e"), "n" is number of
>  			bits, and "f" is flow control ("r" for RTS or
>  			omit it).  Default is "9600n8".
>  
> +			"llX" explained below,
> +
>  			See Documentation/serial-console.txt for more
>  			information.  See
>  			Documentation/networking/netconsole.txt for an
>  			alternative.
>  
> -		uart[8250],io,<addr>[,options]
> -		uart[8250],mmio,<addr>[,options]
> +		uart[8250],io,<addr>[,options][,llX]
> +		uart[8250],mmio,<addr>[,options][,llX]
>  			Start an early, polled-mode console on the 8250/16550
>  			UART at the specified I/O port or MMIO address,
>  			switching to the matching ttyS device later.  The
>  			options are the same as for ttyS, above.
> -		hvc<n>	Use the hypervisor console device <n>. This is for
> +
> +			"llX" explained below,
> +
> +		hvc<n>[,llX]
> +			Use the hypervisor console device <n>. This is for
>  			both Xen and PowerPC hypervisors.
>  
> +			"llX" is used to define the loglevel per console. The "X"
> +			defines the loglevel number for this console. The usage
> +			is similar to the "loglevel=" option, and the effect is
> +			the same only per console. The "loglevel=" option takes
> +			precedence of this option.
> +
>                  If the device connected to the port is not a TTY but a braille
>                  device, prepend "brl," before the device type, for instance
>  			console=brl,ttyS0
> diff --git a/include/linux/console.h b/include/linux/console.h
> index 7571a16..99020d5 100644
> --- a/include/linux/console.h
> +++ b/include/linux/console.h
> @@ -118,6 +118,7 @@ static inline int con_debug_leave(void)
>  
>  struct console {
>  	char	name[16];
> +	int	loglevel;
>  	void	(*write)(struct console *, const char *, unsigned);
>  	int	(*read)(struct console *, char *, unsigned);
>  	struct tty_driver *(*device)(struct console *, int *);
> diff --git a/kernel/printk/console_cmdline.h b/kernel/printk/console_cmdline.h
> index cbd69d8..6f6f98f 100644
> --- a/kernel/printk/console_cmdline.h
> +++ b/kernel/printk/console_cmdline.h
> @@ -3,11 +3,12 @@
>  
>  struct console_cmdline
>  {
> -	char	name[8];			/* Name of the driver	    */
> -	int	index;				/* Minor dev. to use	    */
> -	char	*options;			/* Options for the driver   */
> +	char	name[8];		/* Name of the driver		*/
> +	int	index;			/* Minor dev. to use		*/
> +	int	loglevel;		/* Log level for this console	*/
> +	char	*options;		/* Options for the driver	*/
>  #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
> -	char	*brl_options;			/* Options for braille driver */
> +	char	*brl_options;		/* Options for braille driver	*/
>  #endif
>  };
>  
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 02d6b6d..218d94d 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -1414,6 +1414,9 @@ static void call_console_drivers(int level, const char *text, size_t len)
>  		if (!cpu_online(smp_processor_id()) &&
>  		    !(con->flags & CON_ANYTIME))
>  			continue;
> +		if (con->loglevel && !ignore_loglevel &&
> +		    level >= con->loglevel)
> +			continue;
>  		con->write(con, text, len);
>  	}
>  }
> @@ -1925,6 +1928,33 @@ asmlinkage __visible void early_printk(const char *fmt, ...)
>  }
>  #endif
>  
> +
> +char *setup_per_console_loglevel(struct console_cmdline *con, char *options)
> +{
> +	int size = options ? strlen(options) : 0;
> +
> +	if (size >= 3 &&
> +	    options[size - 3] == 'l' &&
> +	    options[size - 2] == 'l' &&
> +	    options[size - 1] >=  '1' && options[size - 1] <= '9') {
> +		con->loglevel = options[size - 1] - '0';
> +
> +		/* Catch if the user added a comma after some serial console
> +		 * options,
> +		 * i.e. console=ttyS0,9600n8,ll3
> +		 * the first comma is gone at this point, but we need to delete
> +		 * the second one.
> +		 */
> +		if (size > 3 && options[size - 4] == ',')
> +			options[size - 4] = 0;
> +		else
> +			options[size - 3] = 0;
> +	} else
> +		con->loglevel = 0;
> +
> +	return options;
> +}
> +
>  static int __add_preferred_console(char *name, int idx, char *options,
>  				   char *brl_options)
>  {
> @@ -1949,12 +1979,15 @@ static int __add_preferred_console(char *name, int idx, char *options,
>  	if (!brl_options)
>  		selected_console = i;
>  	strlcpy(c->name, name, sizeof(c->name));
> -	c->options = options;
> +
> +	c->options = setup_per_console_loglevel(c, options);
> +
>  	braille_set_options(c, brl_options);
>  
>  	c->index = idx;
>  	return 0;
>  }
> +
>  /*
>   * Set up a console.  Called via do_early_param() in init/main.c
>   * for each "console=" parameter in the boot command line.
> @@ -2478,6 +2511,8 @@ void register_console(struct console *newcon)
>  		if (newcon->setup &&
>  		    newcon->setup(newcon, console_cmdline[i].options) != 0)
>  			break;
> +
> +		newcon->loglevel = c->loglevel;
>  		newcon->flags |= CON_ENABLED;
>  		newcon->index = c->index;
>  		if (i == selected_console) {

Content of type "application/pgp-signature" skipped

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ