Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1895311ybl; Sat, 11 Jan 2020 05:02:55 -0800 (PST) X-Google-Smtp-Source: APXvYqxGnYQPgcqBVdC/c2TQDBP/X//9qoIIt+Wp8kPjMpvWIHe9NeJTRgX+xdeYw7e90MXjHRxC X-Received: by 2002:aca:4306:: with SMTP id q6mr6451553oia.54.1578747775445; Sat, 11 Jan 2020 05:02:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578747775; cv=none; d=google.com; s=arc-20160816; b=PW8rsbMUIPkrENRY9FM3SVs3ajf3olpG0bN+JeFudcYyiTW3T8DR9NwWzs88xw8EYi tLnXARcrcIDpf7GcSgrlOjI5ZDj+TlJZat6VbKYZ4fggaPd/4KDEfKDf4jQdzst4f2oi pnPzgROnTql/z+ICeBVl3f4OfXiOn1fxq9QF95y34h6Y1AcVNx3swlN1lc71Wx3qGA/f R/oDId8X8BBc7IsuWPcu7WbJY+c+WdrkxML272TnFotVhS+rvuVybu/VeFpKjwS5JDHR ambtASoDS7ts8qwJwyAT1RALut6trQYp9wSp1BQlnhODRpM40ZT9M6XdGwf+ukAMhtM9 Gb7g== 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=8aRGKGD24XARcqooB6yRW5X2AEG/hCOzoKCAjLuvYNQ=; b=XW5Fwjv0umsi7fbq6emeTQNK4L3jYMOsTcWDBE+16W/QN3IrVfW4LSs2fdVictFA8+ 5SFwPHktFrnWyC6a4IPJV+jNTWTW6Jqjn0zyaz1o95CvH96XSGTGN/fQTh2cwdcg4fTT 70V5bNFJdrSKeoQpWAbIjU/qeahvP6wuQG2/jqQXE3eohnWUn4Otd9/PlVQC5YcswqeW 1KA1NKDxb2NfoNZsTeDpDuNYercuhkTad189mzLzgdvTGeefQKmixgXXa8cyJRDWX558 jewqg9DTx2cm6mZKhUBh6SfT15YRH93X6O9REDhkWORmh5AmGgrVir34u3NjAnXPqkCG lo/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uAgQwmVh; 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 z24si3875313otm.101.2020.01.11.05.02.09; Sat, 11 Jan 2020 05:02:55 -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=uAgQwmVh; 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 S1729313AbgAKMyn (ORCPT + 99 others); Sat, 11 Jan 2020 07:54:43 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:43742 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729202AbgAKMyn (ORCPT ); Sat, 11 Jan 2020 07:54:43 -0500 Received: by mail-pg1-f193.google.com with SMTP id k197so2348943pga.10 for ; Sat, 11 Jan 2020 04:54:43 -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=8aRGKGD24XARcqooB6yRW5X2AEG/hCOzoKCAjLuvYNQ=; b=uAgQwmVhODKaaZcjw+d37vVpfPujD+R9Lw/PPZ/xe2TlMviSHZD5O/6MW7ASXOMnSI 19qqmz4efo4FRoJhEpiAabxnN/LjT2VfZLtndJMaYACY2TITXKNwS79dcqvf8l7mz65Q 58uylkMAxbDWUhicFjLnHyqEb4SD73km2l2lfPyXcKUqu3AlBTLaK0FbJjTpVq2WYG9A 0CxXcb4FA1VhnFdM5BmaRK7KIJhItLUEJ1kABY6dDv4sTrW7agPrr7GG1ZPwrOg3sfGy 2T5TNamZSjuqvcwDx6wYibE7WQ5LFGhsmD+/LIss9MUXDEhuhWT3J+VIhkJc38YUGicp 3GPQ== 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=8aRGKGD24XARcqooB6yRW5X2AEG/hCOzoKCAjLuvYNQ=; b=isrxl54mN0qtBgadAUGWu5EmKD5cAjRn8VGkt1e3Cmz+uAyGnL80rRLLyjg+ztKys9 kfiit/azjLs6+z+PW5NEdtuC9bcD6flNHVYHAywCeVXfp2JvxDVsf0OWj3U+59ax56hJ ToRg4/P0IwlcDyZazDRyaH4kkXuI1M3u9SdJpyjKjZQZh3sT5+gghz12movKyr5gl9gL dS7yExZHeA/Mg9ixO68Z9U+jR6M7ljwbLCjQ4zmxkYMo53M4YY6CkvlNODJIr2lgQgqD XHffmaA+RjSdX1W6OR0AG8r3PcaVC/j6PSE/Al6lkL9oI5DE7HEuSlBgtstSogxyYg6g zrcw== X-Gm-Message-State: APjAAAVLwNHfsdo22/a7bfvVnGmZTpmKFErnXsEGcodd1YTHM/wo/P6Z b2X4BQQum6CUhOfVuKu7x8c= X-Received: by 2002:a63:2142:: with SMTP id s2mr10871756pgm.54.1578747282689; Sat, 11 Jan 2020 04:54:42 -0800 (PST) Received: from localhost.localdomain ([139.180.133.10]) by smtp.gmail.com with ESMTPSA id a2sm6375440pgv.64.2020.01.11.04.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jan 2020 04:54:42 -0800 (PST) From: Changbin Du To: Thomas Gleixner Cc: Ingo Molnar , Borislav Petkov , hpa@zytor.com, x86@kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Changbin Du Subject: [PATCH v2] x86/nmi: remove the irqwork from long duration nmi handler Date: Sat, 11 Jan 2020 20:54:27 +0800 Message-Id: <20200111125427.15662-1-changbin.du@gmail.com> X-Mailer: git-send-email 2.24.0 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 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. While at it, repurpose the IRQ work callback into a function which concentrates the NMI duration checking. Signed-off-by: Changbin Du --- v2: polish commit message. (Borislav Petkov) --- 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