Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp323478ybl; Tue, 7 Jan 2020 06:46:31 -0800 (PST) X-Google-Smtp-Source: APXvYqy+aHPXQk3t7nHOYlA1N/39mrw6s8K+tJxQFOz+s69Zt0eyfrpliQKcfoVD/CqGiT2mmhff X-Received: by 2002:a05:6830:c2:: with SMTP id x2mr131459oto.8.1578408391806; Tue, 07 Jan 2020 06:46:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578408391; cv=none; d=google.com; s=arc-20160816; b=QjhFOeOd+/KscLEQ6YiOsyU9pjnuKmU7xlPqP94FUb3riM20ci6I6rJwcdxzhkIiXj N3Boh1IeaVlPMJxz9/IN8cM5M1X+lNNGHh6VDttqC8F7OKw2uyEwbDvUE3YOmp9DE5hQ xAk9KGbK+pN6RFi2JKnUzew6CvHiIr+xy7Hy1I/s5r7QRYHxCxMw0715SfUa1aZ0EUDk v9zj9lkJvrN15/a6iAzyNl187K/nnwvQllxLieLGZZPmJXg5//azNrQWwdrFyqCOiDWH 6G2+AGeGYI5ccrSj2vG/coI0VYgN58rbGnRiAN7PZM3jHNc0v1BIDEAElDme7aYJmX1C 6zcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=eEYkUNGS8mhB7emwtN313Sbfg/RUdQ3TrJ4h5H7dG24=; b=nuSxf6UJxqnb4MzExczLJcxuv7Sy50r4oDWcKfLcbBsV/PWnbummyuP90bXi29UDWJ QCJt0D47b+D+qnJO9oIu2K8W+1OpSU2MfN6WJNzlUm0c1DX3qS9K1T7mr4/EBTRCAXaw QfGITeY6/EZrGLTS4cBw/IGHT3O5M58Zqc9eVuR2Y9llurha/te+rDMdUnztplNPlVzd Y99tmvf8WfZk0L9iQ+6L0epQ3jKq+mX9jKdhiQm/Yi5VfPbdYdlKMsl3NZsXG2xKXnty Z8Yiusbosu9iFE0nhugDi4QQ3F7mGMq5xu5qzVtECsREx2ln9xbpvvCYQaTVAnTLTlWh sftA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VdtjwDkH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e63si37925230ote.166.2020.01.07.06.46.17; Tue, 07 Jan 2020 06:46:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VdtjwDkH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728189AbgAGOmC (ORCPT + 99 others); Tue, 7 Jan 2020 09:42:02 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:46543 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727894AbgAGOmC (ORCPT ); Tue, 7 Jan 2020 09:42:02 -0500 Received: by mail-pf1-f194.google.com with SMTP id n9so20832222pff.13 for ; Tue, 07 Jan 2020 06:42:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=eEYkUNGS8mhB7emwtN313Sbfg/RUdQ3TrJ4h5H7dG24=; b=VdtjwDkHRXSyjDMgIZkql7APZlgBoF0R6+7S/GGMVwpAxwVpQL1uLOsVAov0qkInwN ryd0HE3YksFSa2rtBal0M2WlOthiJVMUYi/26xiCZDXr1MYho4o1NFOsxgaKazraqGrO wITMrAvINmeLVUs2YskXaSRxXxKyjxxrsfjMW9Tm6XW+9gu7WMIbuK9UlTi61Y3zoX3j /wTUHoMhAMgsuUiG+GqXWktLyoGOQQngv2Klhp8sHT7nW2s+VkI8cai9HTx8Em3DIiUJ F3Y472m8UHZ/6P0RpxH+bCFVg/oq76WCRmJND42l9d6cRk8VtGSalkVksFvwSJoEVgzt HpcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=eEYkUNGS8mhB7emwtN313Sbfg/RUdQ3TrJ4h5H7dG24=; b=BEsb5QPXWDek95LTQapJ234N45iNo/tiq5FATp2KmI8xAKIE9XF1AnIWYL8nCUAd4W x+Ub+w9y+6NqHAKnVkhpQFvXJffamoBPY0r/UY9WKwOtPdJZk4elCioQprAwnSDKrW6G tUzmehavfedoVIFp+YyMzRNtDDGA1Ob7br9mmuI6Eu6tH4CHE0hzh+lvQJZNvrHTFP7D Q3DbSfRatJ8xK3fVPJNhpHPiG40q6Ql4VhNLByL5jdS1RrDd1oCvY2wTFlUVYNdCrmBv cYidhIUcPAm+rO3ZppXq+7l+rd5RC6ue+eF3uYbQ2BP+1oO1COkF9uZjzwLFfOTWnszw 0yPg== X-Gm-Message-State: APjAAAVfXhaeJRnWxskdFV7WxgzFibLrKGMUfdM3lJ8FVX3fq6Kkc/dz b1SRP3AYF6AiGVOxHCOCeCQ= X-Received: by 2002:a62:7c58:: with SMTP id x85mr114809042pfc.76.1578408121405; Tue, 07 Jan 2020 06:42:01 -0800 (PST) Received: from mail.google.com ([139.180.133.10]) by smtp.gmail.com with ESMTPSA id w11sm75744646pgs.60.2020.01.07.06.41.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2020 06:42:00 -0800 (PST) Date: Tue, 7 Jan 2020 22:41:53 +0800 From: Changbin Du To: Changbin Du Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , hpa@zytor.com, x86@kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86/nmi: remove the irqwork from long duration nmi handler Message-ID: <20200107144153.ysspbqtuwbywpjnm@mail.google.com> References: <20200101072017.82990-1-changbin.du@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200101072017.82990-1-changbin.du@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Thomas, Have you checked this one? I think this even can consider as a fix. On Wed, Jan 01, 2020 at 03:20:17PM +0800, Changbin Du wrote: > First, printk is NMI context safe now since the safe printk has been > implemented. The safe printk already has an irqwork to make NMI context > safe. > > Second, the NMI irqwork actually does not work if a NMI handler causes > panic by watchdog timeout. This NMI irqwork have no chance to run in such > case, while the safe printk will flush its per-cpu buffer before panic. > > Signed-off-by: Changbin Du > --- > arch/x86/include/asm/nmi.h | 1 - > arch/x86/kernel/nmi.c | 20 +++++++++----------- > 2 files changed, 9 insertions(+), 12 deletions(-) > > diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h > index 75ded1d13d98..9d5d949e662e 100644 > --- a/arch/x86/include/asm/nmi.h > +++ b/arch/x86/include/asm/nmi.h > @@ -41,7 +41,6 @@ struct nmiaction { > struct list_head list; > nmi_handler_t handler; > u64 max_duration; > - struct irq_work irq_work; > unsigned long flags; > const char *name; > }; > diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c > index e676a9916c49..aa15d4f2340f 100644 > --- a/arch/x86/kernel/nmi.c > +++ b/arch/x86/kernel/nmi.c > @@ -104,18 +104,22 @@ static int __init nmi_warning_debugfs(void) > } > fs_initcall(nmi_warning_debugfs); > > -static void nmi_max_handler(struct irq_work *w) > +static void nmi_check_duration(struct nmiaction *action, u64 duration) > { > - struct nmiaction *a = container_of(w, struct nmiaction, irq_work); > int remainder_ns, decimal_msecs; > - u64 whole_msecs = READ_ONCE(a->max_duration); > + u64 whole_msecs = READ_ONCE(action->max_duration); > + > + if (duration < nmi_longest_ns || duration < action->max_duration) > + return; > + > + action->max_duration = duration; > > remainder_ns = do_div(whole_msecs, (1000 * 1000)); > decimal_msecs = remainder_ns / 1000; > > printk_ratelimited(KERN_INFO > "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n", > - a->handler, whole_msecs, decimal_msecs); > + action->handler, whole_msecs, decimal_msecs); > } > > static int nmi_handle(unsigned int type, struct pt_regs *regs) > @@ -142,11 +146,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs) > delta = sched_clock() - delta; > trace_nmi_handler(a->handler, (int)delta, thishandled); > > - if (delta < nmi_longest_ns || delta < a->max_duration) > - continue; > - > - a->max_duration = delta; > - irq_work_queue(&a->irq_work); > + nmi_check_duration(a, delta); > } > > rcu_read_unlock(); > @@ -164,8 +164,6 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action) > if (!action->handler) > return -EINVAL; > > - init_irq_work(&action->irq_work, nmi_max_handler); > - > raw_spin_lock_irqsave(&desc->lock, flags); > > /* > -- > 2.24.0 > -- Cheers, Changbin Du