Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1593182ybv; Thu, 20 Feb 2020 23:56:05 -0800 (PST) X-Google-Smtp-Source: APXvYqy/XywzhPIFGT/hfADsp2eq8YzVRcxPx+N8Id9OQGZ2tL/XM7pGkZNolFL09aDVWX9hP2Bf X-Received: by 2002:a54:4595:: with SMTP id z21mr958552oib.136.1582271765020; Thu, 20 Feb 2020 23:56:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582271765; cv=none; d=google.com; s=arc-20160816; b=R2PlFY5fGHivqBYkMeLHIKY4deUbVYFPC2rDZhJqWH7UQH+F2a0wf6n4yX91Rexq2w m5gKEc8u050qp7b46heGutJnBK+pTo3555ZjNuW15/yPMnmzDoisuDI2ffDWn/coU7i4 3Xa5nEaXveEljTZa/y75MNh7rBSHTuAFYE8hcicY3Dl8pmQsOMooTY0h9gYcZqhHIEzm udSHjU5KnbZ7g9h73snPGWBE1nZ1L6kuPmwkfDzgJuk4akbf76bibYQ37ELWgK4lEpmi WmO+ABdHX67agE472ajzfpceU/xXdt5NEXLAdKJfiE68RGzUrJy+9VeyNYr4Pxnvl96X wQ+A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AO1vfq/QaukgwxdxZtnq4K4mqE6ctlIRpPLK2q+8/NI=; b=wa/0vlHbYtbalze3VCYDZ8NNXa7jfSHE7ZBwmp3HPBBEC8p499tEvDgGyQJI+a9qcp L5yn8VjoUM4HYWOPi1gmuApJH47v2+dsfBiUKbKBpZ6/TRUSZZBnx18Ka4z8MtxIGH4G Xcrq6z0EBGO9OJyS8c/GpGfIfAR/VGQv+4tfW/5ljcropf0vRoElt/eNBjdjvie5Uw/Z 0zcoaBMySwfcQ1iTlkKvKfdnQIucTVui3Zpz5tQWWvn5tXZ0wfx0xaYHyOs4IHyUkt+Z 0ZujsF0fw4UCk8kVnEafVwd87VtR7I2Z7qbeaRgKMMvd2R8LtN+o5JC4mNqHBpqEOySw 8xFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hWpzILTS; 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 u13si1135452otg.56.2020.02.20.23.55.52; Thu, 20 Feb 2020 23:56:05 -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=@kernel.org header.s=default header.b=hWpzILTS; 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 S1730370AbgBUHzn (ORCPT + 99 others); Fri, 21 Feb 2020 02:55:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:54726 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730369AbgBUHzk (ORCPT ); Fri, 21 Feb 2020 02:55:40 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4C65924676; Fri, 21 Feb 2020 07:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582271739; bh=P1plHYGMYC1qyi04bgC3z1Yfbf1bTSu9ZEsG1MsEc/s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hWpzILTSL1RDGrKu1ep/wPMWrZr3ixd/f+XNYBqu4DuEi9owm2N2Toriyy0z7cVyp lrvhVZVsY73A/E+Z4yEJJMr34QCZzwLoL/37y1+Lc5YfvGxqyFcUWn2jkhQWKoN2BE wUs8J5exGbgXAhdP/ztg1Ik8VEtYdkWYPaAG5UW4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Changbin Du , Borislav Petkov , Thomas Gleixner , Sasha Levin Subject: [PATCH 5.5 233/399] x86/nmi: Remove irq_work from the long duration NMI handler Date: Fri, 21 Feb 2020 08:39:18 +0100 Message-Id: <20200221072425.386819154@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072402.315346745@linuxfoundation.org> References: <20200221072402.315346745@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Changbin Du [ Upstream commit 248ed51048c40d36728e70914e38bffd7821da57 ] 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 Signed-off-by: Sasha Levin --- 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 75ded1d13d98d..9d5d949e662e1 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 e676a9916c498..54c21d6abd5ac 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); /* -- 2.20.1