Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1999768ybl; Sat, 11 Jan 2020 07:02:53 -0800 (PST) X-Google-Smtp-Source: APXvYqzvryUT+sUqEAT15QYCUGpJ9IwPll+CUjDnH7eONHVZFDuhhcghQX/KYYWvscWRHprspBOQ X-Received: by 2002:a9d:6f0a:: with SMTP id n10mr7267469otq.54.1578754973404; Sat, 11 Jan 2020 07:02:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578754973; cv=none; d=google.com; s=arc-20160816; b=GUsxM+KKBDVQ32/dXyaG06Xh03aHopNbSxhC/IaQwmIUazDkHSRRgtRUSZpWiAmex9 KQxdaJ389ITRgBdj2tJB7XSGAf0Mt+ls8INzBPokLBeAXV/uUBAFVqFyBJ9yyTt0K/kw xtR6tiJ4Gr47dAdvpdj43b3JhUrvuRlaOhClXBZcr8ZcyQDKQmYJYSxjwsTj77S+jjcf 2tyayuu9x1SbW9Gwaf68qsTcvplI5lgP5W/pV6tq3wF3UsU0YmfUTlsAI+pf3Obxsszc 15GPmz9mcrm9nHEvblrGBPzOtDOB7C58wRCt1qv29yz0x6pM5mYKqr/NOKgSweyGPN0+ RaMQ== 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 :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=m1s8G2YtdMfibGs9Sy8KaMxOEggtyHM8Dn63DuHMUcE=; b=Ct1wFaQLxRrfuq1xtXklvSdncvMk3pa/D/+SvPIXQLDsUC81B+Ozah2SRe+HjxInHl B/p3lcggLTDAENqL4Y/WC+kbpR9Guvbfxw4lliUTfZubXF4iMx7WVtYamsibL8i4SHuk rBvQ1tgCw3JmRaygvRH2rrf232isjqdJjuQjxb2lih21Ljiu+MzQ9renoTX+orHnkRQI BmQxDY8anLSCKXFx6tkpSNKi72//gTaE+T3wFnYUR90az4rXnNouF7knl4KoTZbkNlKv 4dHpm/Mn0GCpPxSVLq9MFtiCid41qPVuCUh0MP3wY4rynjnytElfsJL+qoJNgCpmdshT ornA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t130si3121977oib.202.2020.01.11.07.02.41; Sat, 11 Jan 2020 07:02:53 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729957AbgAKPBi (ORCPT + 99 others); Sat, 11 Jan 2020 10:01:38 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:33352 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729696AbgAKPBh (ORCPT ); Sat, 11 Jan 2020 10:01:37 -0500 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iqIGb-0004an-4o; Sat, 11 Jan 2020 16:01:33 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id AAC4A1C1944; Sat, 11 Jan 2020 16:01:32 +0100 (CET) Date: Sat, 11 Jan 2020 15:01:32 -0000 From: "tip-bot2 for Changbin Du" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/core] x86/nmi: Remove irq_work from the long duration NMI handler Cc: Changbin Du , Borislav Petkov , Thomas Gleixner , x86 , LKML In-Reply-To: <20200111125427.15662-1-changbin.du@gmail.com> References: <20200111125427.15662-1-changbin.du@gmail.com> MIME-Version: 1.0 Message-ID: <157875489248.30329.781797148985800902.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/core branch of tip: Commit-ID: 248ed51048c40d36728e70914e38bffd7821da57 Gitweb: https://git.kernel.org/tip/248ed51048c40d36728e70914e38bffd7821da57 Author: Changbin Du AuthorDate: Sat, 11 Jan 2020 20:54:27 +08:00 Committer: Borislav Petkov CommitterDate: Sat, 11 Jan 2020 15:55:39 +01:00 x86/nmi: Remove irq_work from the long duration NMI handler First, printk() is NMI-context safe now since the safe printk() has been implemented and it already has an irq_work to make NMI-context safe. Second, this NMI irq_work actually does not work if a NMI handler causes panic by watchdog timeout. It has no chance to run in such case, while the safe printk() will flush its per-cpu buffers before panicking. While at it, repurpose the irq_work callback into a function which concentrates the NMI duration checking and makes the code easier to follow. [ bp: Massage. ] Signed-off-by: Changbin Du Signed-off-by: Borislav Petkov Acked-by: Thomas Gleixner Link: https://lkml.kernel.org/r/20200111125427.15662-1-changbin.du@gmail.com --- 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 75ded1d..9d5d949 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 e676a99..54c21d6 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); + u64 whole_msecs = READ_ONCE(action->max_duration); int remainder_ns, decimal_msecs; - u64 whole_msecs = READ_ONCE(a->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); /*