Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp374945ybc; Sat, 16 Nov 2019 00:51:57 -0800 (PST) X-Google-Smtp-Source: APXvYqx5/9eRUF70FuAONx46paZRRIlSELyQBoZ650Ng7DIWi89L5GboTapqfyni5NAr3Zg8/RTc X-Received: by 2002:a17:906:a457:: with SMTP id cb23mr7953262ejb.191.1573894317445; Sat, 16 Nov 2019 00:51:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573894317; cv=none; d=google.com; s=arc-20160816; b=u1MElWtO7JlsIyelgjPREZmyLeXLHINRhsFcxYORW+zguhTVQDmRMRRBmdd61nAUmp mYGAdfjPXzaxhmJIaGgLcEm5c7LxRiGTBlHoU6ufH2xKvhKJas8K6FXZM/86gAksGOsG jGlN2O7so+qck/1xqQmW811QE7sH0Gi4QMLluQDuA2h7PlbhElhNvypj6jHgmy0WigYB DGgeTNOi2JLGph2WI2mkmlC5dvVyYND4a979FZB2jTT8tGYrTrv8CH3VHhrCTIdIKoZV tT1Y8QA7E+tlaO/YNBIuodsaD99Eh2U5s3SFgmVDHw0yUnuSZlwFaP6XywDtDjgnchPv pzAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=wXK8i3dcP0wrlupZd2syn0RAvq63einR0Js8n3kXDKU=; b=0n5nIP+JbEwPILJ8Ayb59pIbgfrWd88+4tYgh2EtDzpuaN6U1tq8ycNEKU8Bom554X 2yYD7o32Am8ioEuBxgfC0xEcQWIwapWcIwj2Tflx5Uznl+LKBxJ1osKfrpv/o5AkfpMz xySAAsMUKF1/1qxXCp5OFcctpMNS+xhI9eV3lZTLFduX0H8rRB2p9HK3Pz5+l5xJsHEU 3RderIwUynTAGe42SghQcHUov6c3LlMa57FkRVW2exQ0XcoDlNMD6Q82v+nqcWFQ++Do 9rXkpzb9TuR4jHHStaEvvYoMD/qi7vGrnkk2oXKFNj6A+FPgFpsd+QX+ZKtKnDqGP3LO B45A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bYBP+Mc0; 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 d27si5069309ejt.116.2019.11.16.00.51.33; Sat, 16 Nov 2019 00:51:57 -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=bYBP+Mc0; 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 S1727139AbfKPIst (ORCPT + 99 others); Sat, 16 Nov 2019 03:48:49 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:35048 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726166AbfKPIst (ORCPT ); Sat, 16 Nov 2019 03:48:49 -0500 Received: by mail-wm1-f68.google.com with SMTP id 8so12934567wmo.0 for ; Sat, 16 Nov 2019 00:48:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wXK8i3dcP0wrlupZd2syn0RAvq63einR0Js8n3kXDKU=; b=bYBP+Mc0aBAuqpK0IA27BZ/v66eES1UImafLgG20OvK0dZt/CYrruegMIC55VjXffY sZdUbk8h04brIJHW8PLu+oX4QbxttezEZxdVB4lLQETTOclFjroIPfZJP3qTcAskBS6G uZdc1EQuWmjFeTWkOvEd6IDZpPPD/w/E6l9f1ohTLg5feDW/ckxMQrVyH/VqAizzTvhp 30zylcW+gVWSGxsw/bBjJsvJG/l9JXEOpsWFbWbbB7uUZOnNutsQg+79Qmsal7FfLwBy nCCEDoCC3v24x7Fl1zu5R9/PJ3GqBNMZf1p9MpdqkMiO4LTtcQCbpr1+zNwkBCj3/9yN DJJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wXK8i3dcP0wrlupZd2syn0RAvq63einR0Js8n3kXDKU=; b=LL8x1Fbb8A648EatUHiv0lSxghVi8BB8TQUXBKcudJDNePC7Azmsi3duYGdltSn9OC EfN0o7hmlcxoS+ENODrD/9vrtY1/I7d+NnJnrOhQuZKjTyW77SfuRajsineoX6bolFq3 Pi5XWa8C9KdrExtGwSQTezhFAdQ3zS0Tl3VX1UBWE1pjlZXSPaIZnIYTKna+knOIg63u 20hxtBPwF8Pcf01RbLCPb9Vzj6lLO8Lve65WvHHnBxlxao0uVm5vJ+v7WrymFJvzkwPn WEhFDskedwHL3TTXGOA7c1jyglfhRmJSIBcqg7hU2JPOARwiWNAFaodwAmAstUqUCXMv BXzw== X-Gm-Message-State: APjAAAWs2g5ob31DeyjfMGYPMEoWU6qCHFnPqymSzQXym/yXsBAF8S+Y +VhhoPuQR2LYZRDYuxTUSXU= X-Received: by 2002:a1c:9804:: with SMTP id a4mr18594011wme.57.1573894125367; Sat, 16 Nov 2019 00:48:45 -0800 (PST) Received: from localhost.localdomain ([104.238.174.53]) by smtp.gmail.com with ESMTPSA id g184sm13460814wma.8.2019.11.16.00.48.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Nov 2019 00:48:43 -0800 (PST) From: Changbin Du To: Thomas Gleixner , Ingo Molnar Cc: Borislav Petkov , hpa@zytor.com, x86@kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Changbin Du Subject: [RESEND PATCH] x86/nmi: remove the irqwork for long nmi handler duration warning Date: Sat, 16 Nov 2019 16:48:35 +0800 Message-Id: <20191116084835.3524-1-changbin.du@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org First, printk is NMI context safe now since the safe printk has been implemented. The safe printk will help us to do such work in its irqwork. Second, the NMI irqwork actually does not work if a NMI handler causes watchdog timeout panic. The 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 4df7705022b9..0fa51f80ad73 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.20.1