Received: by 10.223.185.116 with SMTP id b49csp456197wrg; Wed, 14 Feb 2018 01:33:06 -0800 (PST) X-Google-Smtp-Source: AH8x226xSLGG7CByUXSWWfjL3EHuhNssyrrR1taPDtHgDv2eA3Yb39GrZt9rgJizrzCMZhQkO8M9 X-Received: by 10.98.105.199 with SMTP id e190mr4172570pfc.70.1518600786828; Wed, 14 Feb 2018 01:33:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518600786; cv=none; d=google.com; s=arc-20160816; b=ZvcDpJt1ZsyiBtUwcG3YWmld4lkUkl1fj/wZSAZ3Cm+Oe1v0crswEfNbBkINBAB0NP Z9JulujI3fC1aN6vq1oGIdAr4KNePOfbTnACNAw9KwTv/yz4CPs6RvLeqADjwelGK5mg 6q4aXhTTNCVS6s289uMtrVeX+5S99x4l627Uc+CXNn1Pm1LgL/bzdiW8cvbOY3MRI1o1 DlSf5Me50sy2JE8VyxBJ7X4HTKf/oM5GOn3XvZVxdZxqTYYPP6ysxf/kBFTVDjFxiczq 3XrtJGoSOBwyDwCUfFQdYNhIAUTE/SzqGpiAJQ8PRPTdAyhViLY+pC6JkasjK1tn7Xai VXjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=P+dNTnybxRspmNJcZUZH7EyLCEyXjjKAghsJSqFNY64=; b=nAG27X01HyV/ECeuPLXWss9V8mkQakGIYVH/zuTaLcweK3cyNzTT2F4/g4aawVqETp SYKpCb+0F42AsUwXCV9WEaezLbJDCgvi21RLGhh4KmTccplq65c48S39pgvKd5v6CZSf eu2KL+ZzjfoRe5djg+6+jzbtwQL15i835h5T6t/IZbVTgICl72HugyAKfGIAJ6IAj7Zg qWkjcJwv65/qZyXLfxavOSfyxnowOeqa6QeCFnXAUsMSVNtjdO7N1v8/EaB2w+9KquB2 RjzZc5B1/f31IU04mZzM08LoerEiiQNn0mofcnhmsFQdPtRTsH5hfMhXyvXv4oeOzmdP XWOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=F6AMZoz6; 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 n1-v6si1237297pld.589.2018.02.14.01.32.52; Wed, 14 Feb 2018 01:33:06 -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=fail header.i=@gmail.com header.s=20161025 header.b=F6AMZoz6; 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 S966841AbeBNJcG (ORCPT + 99 others); Wed, 14 Feb 2018 04:32:06 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:45563 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966664AbeBNJcE (ORCPT ); Wed, 14 Feb 2018 04:32:04 -0500 Received: by mail-wr0-f196.google.com with SMTP id h9so21437242wre.12; Wed, 14 Feb 2018 01:32:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=P+dNTnybxRspmNJcZUZH7EyLCEyXjjKAghsJSqFNY64=; b=F6AMZoz6v2OTO9IldBZWMgpPrZVPCd5ItrYNiijA34Ew51oVxQ4wBP4ut4RcCGnRX1 eDHaLAVWBJ1f0Z5outGpoLI5nUaTVDB8KTC1CdViBGw0M/MaBKwm4ngYQmGqb1pDXUaj CFzM8KPZfz/jSfIcFqlvCNdU1boYeI/fGGgL2pe6PBP9Dk8ya0wkmtOLfjXOEIsfjMVj YJvlZ5DiTvzO7RYNmQwPVA7SfFn+hTzw9U8moKKJz8PJ5+slG4SvDi/jTDvLL21KOQYH ouXROsLPrLDCnDh7gNtsoLoQEim1xqX/lQKWwQAnhSqh9Gj3ttTRdfcejvaGjVEj9pIl Rg9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=P+dNTnybxRspmNJcZUZH7EyLCEyXjjKAghsJSqFNY64=; b=qAVexDWzBT2PlkVdW6uh4tlHYZLV6McZcP4LEzjfFfYJVv4vVwhDP+RVXSsp/iCxPz eJmIvT6X3wOuAIvF4XNRoVPkBP5UGiT4T9rfzIJkLf51Fc3cny4uwjNA+MS25AkLSrWP 7rTiWYeCcO8tDGqMcU8K0L0qzLELhFVn83ULTk58+eMH8RGtK5WtiS2ILSCZQASTAq1Q /6VqHr3MpFr+GJ3cOCfXpaCIEQAvQAaNfWoaEtSPAqaB4qI0UUX/Feir8WrIwaongdyf n7lLIu64I5G0uPWl80hijrretGyechcYvRpKotOTBO7pRW3gMHA0rtSnnXxe3eAfQquQ KZnA== X-Gm-Message-State: APf1xPA1DgcvhEDUCDgqsG/3Ity/a9ESMS0Pwo5bOMoY4Tp30NVR/N8o DzfECxHM8R0fEyhQktwfPS8= X-Received: by 10.223.136.225 with SMTP id g30mr3773691wrg.103.1518600722573; Wed, 14 Feb 2018 01:32:02 -0800 (PST) Received: from gmail.com (2E8B0CD5.catv.pool.telekom.hu. [46.139.12.213]) by smtp.gmail.com with ESMTPSA id n13sm6027440wra.41.2018.02.14.01.32.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Feb 2018 01:32:02 -0800 (PST) Date: Wed, 14 Feb 2018 10:31:59 +0100 From: Ingo Molnar To: Tim Chen Cc: Peter Zijlstra , Dave Hansen , hpa@zytor.com, tglx@linutronix.de, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, dwmw@amazon.co.uk, linux-tip-commits@vger.kernel.org, Borislav Petkov , Arjan van de Ven Subject: [PATCH] watchdog: hpwdt: Remove spinlock acquire and BIOS calls from NMI context Message-ID: <20180214093159.mdzfupne547bi5qx@gmail.com> References: <1518362359-1005-1-git-send-email-dwmw@amazon.co.uk> <20180212102211.cdrrqqd4hdw7xu5y@gmail.com> <20180212165835.GO25181@hirez.programming.kicks-ass.net> <20180213075540.3lkikkpgjoe6ocjk@gmail.com> <5c3ba123-abbe-f153-7b75-a89d31d25c72@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5c3ba123-abbe-f153-7b75-a89d31d25c72@linux.intel.com> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Tim Chen wrote: > Dave Hansen and I had some discussions on how to handle the nested NMI and > firmware calls. We thought of using a per cpu counter to record the nesting > call depth and toggle IBRS appropriately for the depth 0->1 and 1->0 transition. > Will this change be sufficient? Yeah, so I think the first question should be: does the firmware call from NMI context make sense to begin with? Because in this particular case it does not appear to be so: the reason for the BIOS/firmware call appears to be to determine how we nmi_panic() after receiving an NMI that no other NMI handler handled: with a passive-aggressive "I don't know" panic message or with a slightly more informative panic message. That's not a real value-add to users - so we can avoid all these complications by applying the patch below: drivers/watchdog/hpwdt.c | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) As a bonus the spinlock use can be removed as well. Thanks, Ingo ====================> From b038428a739a3fcf0b9678305c131f60af7422ca Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Wed, 14 Feb 2018 10:24:41 +0100 Subject: [PATCH] watchdog: hpwdt: Remove spinlock acquire and BIOS calls from NMI context Taking a spinlock and calling into the firmware are problematic things to do from NMI callbacks. It also seems completely pointless in this particular case: - cmn_regs is updated by the firmware call in the hpwdt_pretimeout() NMI callback, but there's almost no use for it: we use it only to determine whether to panic with an 'unknown NMI' or a slightly more descriptive message. - cmn_regs and rom_lock is not used anywhere else, other than early detection of the firmware capability. So remove rom_lock, make the cmn_regs call from the detection routine only, and thus make the NMI callback a lot more robust. Signed-off-by: Ingo Molnar --- drivers/watchdog/hpwdt.c | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/drivers/watchdog/hpwdt.c b/drivers/watchdog/hpwdt.c index f1f00dfc0e68..2544fe482fe3 100644 --- a/drivers/watchdog/hpwdt.c +++ b/drivers/watchdog/hpwdt.c @@ -150,9 +150,7 @@ static unsigned int hpwdt_nmi_decoding; static unsigned int allow_kdump = 1; static unsigned int is_icru; static unsigned int is_uefi; -static DEFINE_SPINLOCK(rom_lock); static void *cru_rom_addr; -static struct cmn_registers cmn_regs; extern asmlinkage void asminline_call(struct cmn_registers *pi86Regs, unsigned long *pRomEntry); @@ -225,6 +223,7 @@ static int cru_detect(unsigned long map_entry, unsigned long physical_bios_base = 0; unsigned long physical_bios_offset = 0; int retval = -ENODEV; + struct cmn_registers cmn_regs = { }; bios32_map = ioremap(map_entry, (2 * PAGE_SIZE)); @@ -486,32 +485,18 @@ static int hpwdt_my_nmi(void) */ static int hpwdt_pretimeout(unsigned int ulReason, struct pt_regs *regs) { - unsigned long rom_pl; - static int die_nmi_called; - if (!hpwdt_nmi_decoding) return NMI_DONE; if ((ulReason == NMI_UNKNOWN) && !hpwdt_my_nmi()) return NMI_DONE; - spin_lock_irqsave(&rom_lock, rom_pl); - if (!die_nmi_called && !is_icru && !is_uefi) - asminline_call(&cmn_regs, cru_rom_addr); - die_nmi_called = 1; - spin_unlock_irqrestore(&rom_lock, rom_pl); - if (allow_kdump) hpwdt_stop(); - if (!is_icru && !is_uefi) { - if (cmn_regs.u1.ral == 0) { - nmi_panic(regs, "An NMI occurred, but unable to determine source.\n"); - return NMI_HANDLED; - } - } - nmi_panic(regs, "An NMI occurred. Depending on your system the reason " - "for the NMI is logged in any one of the following " + nmi_panic(regs, + "An NMI occurred. Depending on your system the reason " + "for the NMI might be logged in any one of the following " "resources:\n" "1. Integrated Management Log (IML)\n" "2. OA Syslog\n" @@ -744,13 +729,6 @@ static int hpwdt_init_nmi_decoding(struct pci_dev *dev) HPWDT_ARCH); return retval; } - - /* - * We know this is the only CRU call we need to make so lets keep as - * few instructions as possible once the NMI comes in. - */ - cmn_regs.u1.rah = 0x0D; - cmn_regs.u1.ral = 0x02; } /*