Re: [PATCH v4 02/27] hardirq/nmi: Allow nested nmi_enter()
From: Frederic Weisbecker
Date: Fri Feb 21 2020 - 17:22:01 EST
On Fri, Feb 21, 2020 at 02:34:18PM +0100, Peter Zijlstra wrote:
> Since there are already a number of sites (ARM64, PowerPC) that
> effectively nest nmi_enter(), lets make the primitive support this
> before adding even more.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
> Reviewed-by: Petr Mladek <pmladek@xxxxxxxx>
> Acked-by: Will Deacon <will@xxxxxxxxxx>
> Acked-by: Marc Zyngier <maz@xxxxxxxxxx>
> ---
> arch/arm64/include/asm/hardirq.h | 4 ++--
> arch/arm64/kernel/sdei.c | 14 ++------------
> arch/arm64/kernel/traps.c | 8 ++------
> arch/powerpc/kernel/traps.c | 22 ++++++----------------
> include/linux/hardirq.h | 5 ++++-
> include/linux/preempt.h | 4 ++--
> kernel/printk/printk_safe.c | 6 ++++--
> 7 files changed, 22 insertions(+), 41 deletions(-)
>
> --- a/kernel/printk/printk_safe.c
> +++ b/kernel/printk/printk_safe.c
> @@ -296,12 +296,14 @@ static __printf(1, 0) int vprintk_nmi(co
>
> void notrace printk_nmi_enter(void)
> {
> - this_cpu_or(printk_context, PRINTK_NMI_CONTEXT_MASK);
> + if (!in_nmi())
> + this_cpu_or(printk_context, PRINTK_NMI_CONTEXT_MASK);
> }
>
> void notrace printk_nmi_exit(void)
> {
> - this_cpu_and(printk_context, ~PRINTK_NMI_CONTEXT_MASK);
> + if (!in_nmi())
> + this_cpu_and(printk_context, ~PRINTK_NMI_CONTEXT_MASK);
> }
If the outermost NMI is interrupted while between printk_nmi_enter()
and preempt_count_add(), there is still a risk that we race and clear?