Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp16175810ybl; Tue, 31 Dec 2019 23:24:46 -0800 (PST) X-Google-Smtp-Source: APXvYqx8dzUtJq88UxQZpDASYfduVfG1GMUQNfNtsj+QZ7jBFIBXblmWJgK/EujR0XilVbkJJ312 X-Received: by 2002:a17:906:80b:: with SMTP id e11mr80538657ejd.278.1577863486436; Tue, 31 Dec 2019 23:24:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577863486; cv=none; d=google.com; s=arc-20160816; b=bSaQRj49bPrvFifnbP3OjUKlrD2XgFtI4lpXPyQb5fNBcICfYAFt7NbBQ/Bf3rMupA UktqtnodOuFCHN+FNzsu0hWEoL6eRNpGsRfyxQo8xv70LGiCHqQoPUM8mQFbENXEVqih 5xtGEBPqux9ikqr3zcqBkhrECm9thsJLSWKrEnZN2x7603hsshm1eJhfah6B+dBxxPI2 c87VjZ8Jv+ySAeEsv8tkBmXM8arTJnBvkBCnPqVAccha/DKaDUez2YgMv4l7xVvEALlk TZ32W3JeiPXv6t7kcS2W3pR7YCGH87ZzaqLjQ3j0g9pywHt0Vr4JpdTPwZAnzE+ujBSI Rj2w== 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=vy4x1uZ6KviudWnvu6W2UMmvm4EQwTGZG2bElmjYCN8=; b=W17cHdTGClIHB03iJR4zG+IdUVK3+2ObYwA7/bzlUxDhzmnTvLU8yzZCpFQfhbgdV8 1SCoV62Dxzm+qPeeLs0pGIxS/qUhnS7/SQlX79eGFFvWPUeDZp1wjqgDJPUT5p/Kyxn6 VYqYW/bGiD9DWhbAFfdHC4HjfqsFAYts7gBVXbmpGZQffh81YEYwnyebbokZABUaMhve 4BNBFDbFnWQuUq9kcAwiYJwmCdSTwCQiN3yt1YoBvd3ZtihU+7/TDE56W8XhiCVjBnAd LYxiNHNcfV5nDV7Kgtsja/XN0C58FkZ0vXNK4xQMts7mhmbyHY/tH58EtvGPpM48HkYq ev/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=trMtSEBm; 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 i12si32312430edn.233.2019.12.31.23.24.22; Tue, 31 Dec 2019 23:24:46 -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=trMtSEBm; 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 S1725871AbgAAHUa (ORCPT + 99 others); Wed, 1 Jan 2020 02:20:30 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:40730 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725783AbgAAHU3 (ORCPT ); Wed, 1 Jan 2020 02:20:29 -0500 Received: by mail-pf1-f196.google.com with SMTP id q8so20537092pfh.7 for ; Tue, 31 Dec 2019 23:20:29 -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=vy4x1uZ6KviudWnvu6W2UMmvm4EQwTGZG2bElmjYCN8=; b=trMtSEBmMAZrGlO66FIry9BOrqXyvdjGQq6m9t53Dz8bt3tj8h7gBxEaZUQkYmxg9l QMwvTW5T6y8ZKbF2EXpd8eQxtTUVyi3EhfGk9QA4XEo5aADu3NDyFR3vaddU3GZJD2jq IcHM4g5RQASd4XzqbIGSpt5ka6i1XTytRE3Ao3qmWK0uWi3L87wX9OoJMyXhjOmtCmyk Ufc/clPY4khUoiSfOWJeaZuTSPnVo9JtISHmnqxW+t2s34sYjtwD5U4VxfA93FkXCaTY A4pqVAVcAEQ9J+QOgvSIqO3bknNvAbk3ml9EgbshkYPD21moXPjDDVCYZ2cJYzuQd9Gm +CVg== 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=vy4x1uZ6KviudWnvu6W2UMmvm4EQwTGZG2bElmjYCN8=; b=Ow961hQ1bNVruppbGOZWK8JBjrzVGMH1uYG2OQ8nCJhs+U7xagTo/tJiddteAF4w2K IXsKiiLinw+4TIza+TxslzuUKLxNVpLS8ep9bnPm5AMvGTk00J05neR/l8OTxD356Jex n0DY2CBvEngEpI/m21ll8+ER6Pd2eb8B/NEzcYpIJrKnFx5jNZnqOVInGNE23TTDVedy SkPS25Bl0fUyKbDBf95klTDU745pBfDkuKkC6ZFKnPsag/HrwEEwitGQKogp3gZuAm9A /t1xakjkSorLw6GhywJ6AJb2H3W04RS87heJePMGMbihqaLMPCweOoOjtQTS+QmohRFu oCVA== X-Gm-Message-State: APjAAAXVL7Z69Zw5DSB9xICs6H3gYZ4pM1yFgpCGvQ5lI3ARKaHTsanM ziGkxYoaPuBn6vxMvqO+zs0= X-Received: by 2002:a63:62c2:: with SMTP id w185mr79715130pgb.271.1577863229319; Tue, 31 Dec 2019 23:20:29 -0800 (PST) Received: from localhost.localdomain ([139.180.133.10]) by smtp.gmail.com with ESMTPSA id c68sm59993423pfc.156.2019.12.31.23.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Dec 2019 23:20:28 -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] x86/nmi: remove the irqwork from long duration nmi handler Date: Wed, 1 Jan 2020 15:20:17 +0800 Message-Id: <20200101072017.82990-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. 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