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]
Message-ID: <YFr7KSwgX/WexbXy@alley>
Date:   Wed, 24 Mar 2021 09:41:13 +0100
From:   Petr Mladek <pmladek@...e.com>
To:     John Ogness <john.ogness@...utronix.de>
Cc:     Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>,
        Sergey Senozhatsky <sergey.senozhatsky@...il.com>,
        Steven Rostedt <rostedt@...dmis.org>,
        Thomas Gleixner <tglx@...utronix.de>,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH next v1 1/3] printk: track/limit recursion

On Tue 2021-03-23 22:32:00, John Ogness wrote:
> On 2021-03-22, Petr Mladek <pmladek@...e.com> wrote:
> > On Wed 2021-03-17 00:33:24, John Ogness wrote:
> >> Track printk() recursion and limit it to 3 levels per-CPU and per-context.
> >
> >> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> >> index 2f829fbf0a13..c666e3e43f0c 100644
> >> --- a/kernel/printk/printk.c
> >> +++ b/kernel/printk/printk.c
> >> +/* Return a pointer to the dedicated counter for the CPU+context of the caller. */
> >> +static char *printk_recursion_counter(void)
> >> +{
> >> +	int ctx = 0;
> >> +
> >> +#ifdef CONFIG_PRINTK_NMI
> >> +	if (in_nmi())
> >> +		ctx = 1;
> >> +#endif
> >> +	if (!printk_percpu_data_ready())
> >> +		return &printk_count_early[ctx];
> >> +	return &((*this_cpu_ptr(&printk_count))[ctx]);
> >> +}
> >
> > It is not a big deal. But using an array for two contexts looks strange
> > especially when only one is used on some architectures.
> > Also &((*this_cpu_ptr(&printk_count))[ctx]) is quite tricky ;-)
> >
> > What do you think about the following, please?
> >
> > static DEFINE_PER_CPU(u8 printk_count);
> > static u8 printk_count_early;
> >
> > #ifdef CONFIG_HAVE_NMI
> > static DEFINE_PER_CPU(u8 printk_count_nmi);
> > static u8 printk_count_nmi_early;
> > #endif
> >
> > static u8 *printk_recursion_counter(void)
> > {
> > 	if (IS_ENABLED(CONFIG_HAVE_NMI) && in_nmi()) {
> > 		if (printk_cpu_data_ready())
> > 			return this_cpu_ptr(&printk_count_nmi);
> > 		return printk_count_nmi_early;
> > 	}
> >
> > 	if (printk_cpu_data_ready())
> > 		return this_cpu_ptr(&printk_count);
> > 	return printk_count_early;
> > }
> 
> I can split it into explicit variables. But is the use of the IS_ENABLED
> macro preferred over ifdef? I would prefer:
> 
> static u8 *printk_recursion_counter(void)
> {
> #ifdef CONFIG_HAVE_NMI
> 	if (in_nmi()) {
> 		if (printk_cpu_data_ready())
> 			return this_cpu_ptr(&printk_count_nmi);
> 		return printk_count_nmi_early;
> 	}
> #endif
> 	if (printk_cpu_data_ready())
> 		return this_cpu_ptr(&printk_count);
> 	return printk_count_early;
> }
> 
> Since @printk_count_nmi and @printk_count_nmi_early would not exist, I
> would prefer the pre-processor removes that code block rather than
> relying on compiler optimization.

Feel free to use #ifdef.

Best Regards,
Petr

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ