Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp669112pxj; Thu, 10 Jun 2021 09:49:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwc8Dv53EptLjDyeEgJbHQH7HBhYGzHkYi4AslBSlONynbC/XchuCC10cu3ixB3B+u0i9aq X-Received: by 2002:a17:906:c1d0:: with SMTP id bw16mr540630ejb.146.1623343745450; Thu, 10 Jun 2021 09:49:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623343745; cv=none; d=google.com; s=arc-20160816; b=g5iyiqZ31a14TDdShmxpzR3A4poBTNbm3nTGequ5v/7qdgQEZz3Xny83WZOiilvYpf 42VpSTOL8JKpOdW2NmwCmJv+C9qr8F8GoIzN7MzAmJp49UVFPr87IE2nXUJTnsOPK7Fw mr4YSUx2U3DETVhXPOPtCiOw6Y7TGidKQHHChEgmRW/e8ekZac8Qtuoa0sV+moUAqAfY iyueGx5/erME3nv5gyG/tbDsQHfhK2hEU9z2y+mGTKbp3mv5wv+SHvXMBsV9mrJti7wE KOAVWmISRuNUu3zm+pzL3Bxd+4wpVkzBHrM+Eip9jXc2BzzhwTYGOAo2Ag7SNDwfmU0U Vp8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=j3jPHJqvLksOZdunqh4hKD5WdKx7wVlca5HYMWPW3MI=; b=LxBPClqsfC09Mx1QiAHLNOTIf/XqdioWmPwUZYAjMyAlLDRIjorjrDwPeIe3t26fOx 2CsQ+Kbn1ASyqC4bfUJuzrleGm0BECs3H4zPXw4RJuKfqUYBK1nbRpE730jAoyiW3RC3 apf8/GU8miOeKDU7nBC6LfZqSNJRQeuAa9yW7/+7/JQiSQagE/RGdrw4MSrBQ4cA+HEP P3uJI2TNMIke0wbOWOgLrJM8kfGobXttlELohqUbMSuJkpOhQmixKZ1LqOQg6N68wJRv hk+9bJ8LX2i5ew4VdWMsUWGM2bgWe8MY2VG1wxZ0SfOdcBw6+OIgXz3JyXWkEwu+p8Xi i6bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ULo2cnYy; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=9xDiIYos; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j20si2925030edp.274.2021.06.10.09.48.41; Thu, 10 Jun 2021 09:49:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ULo2cnYy; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=9xDiIYos; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231356AbhFJQrg (ORCPT + 99 others); Thu, 10 Jun 2021 12:47:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230396AbhFJQrg (ORCPT ); Thu, 10 Jun 2021 12:47:36 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D440FC061574 for ; Thu, 10 Jun 2021 09:45:39 -0700 (PDT) Date: Thu, 10 Jun 2021 16:45:36 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1623343537; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j3jPHJqvLksOZdunqh4hKD5WdKx7wVlca5HYMWPW3MI=; b=ULo2cnYyL0MCi5nCKQ0MY/6TLF1+ZVteyyV6Q30sB7FjdACxY0GJytEctIYYVyDfc9b/xT jv9CIt5WL2qy72J3s//f5567StMPbpPJrzeOTou3kB9xLYp4Bc9TS6OAdZAha8KK4mgHBu UVuVvYWpA7Ico7I020sMD+Q5JLjm6DIlHf3Z0/iib4bjoy6bsiVvicX2PKiuZGBjQVshSu PC8vp0Mou8Iw+uaDS595f+Fek/ClkpTAyJnlq1ObK6LsdQ5yPHsbuUm59ZWaSnvMIYXqyu mH7PZl+9XJcOOIhnafdGn9efqo1Q85ADdkukTIURkJYwyUVm+/HNp7Xz/4cvMg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1623343537; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j3jPHJqvLksOZdunqh4hKD5WdKx7wVlca5HYMWPW3MI=; b=9xDiIYosu+8rThsc9R8/+zUfBMGwNHKzxfkYiTKrsYwxsia3fkWyL10Tlexm7PAzhU4Di7 A0oH0oPgkl7V08CQ== From: "irqchip-bot for Marc Zyngier" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-kernel@vger.kernel.org Subject: [irqchip: irq/irqchip-fixes] irqchip/gic-v3: Workaround inconsistent PMR setting on NMI entry Cc: Mark Rutland , Marc Zyngier , tglx@linutronix.de In-Reply-To: <20210610145731.1350460-1-maz@kernel.org> References: <20210610145731.1350460-1-maz@kernel.org> MIME-Version: 1.0 Message-ID: <162334353698.29796.16060603253543221581.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the irq/irqchip-fixes branch of irqchip: Commit-ID: f6f3e6e9b362363d6eb303982d6302a1d43312c9 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/f6f3e6e9b362363d6eb303982d6302a1d43312c9 Author: Marc Zyngier AuthorDate: Thu, 10 Jun 2021 15:13:46 +01:00 Committer: Marc Zyngier CommitterDate: Thu, 10 Jun 2021 17:42:21 +01:00 irqchip/gic-v3: Workaround inconsistent PMR setting on NMI entry The arm64 entry code suffers from an annoying issue on taking a NMI, as it sets PMR to a value that actually allows IRQs to be acknowledged. This is done for consistency with other parts of the code, and is in the process of being fixed. This shouldn't be a problem, as we are not enabling interrupts whilst in NMI context. However, in the infortunate scenario that we took a spurious NMI (retired before the read of IAR) *and* that there is an IRQ pending at the same time, we'll ack the IRQ in NMI context. Too bad. In order to avoid deadlocks while running something like perf, teach the GICv3 driver about this situation: if we were in a context where no interrupt should have fired, transiently set PMR to a value that only allows NMIs before acking the pending interrupt, and restore the original value after that. This papers over the core issue for the time being, and makes NMIs great again. Sort of. Fixes: 4d6a38da8e79e94c ("arm64: entry: always set GIC_PRIO_PSR_I_SET during entry") Co-developed-by: Mark Rutland Signed-off-by: Mark Rutland Signed-off-by: Marc Zyngier Link: https://lore.kernel.org/lkml/20210610145731.1350460-1-maz@kernel.org --- drivers/irqchip/irq-gic-v3.c | 36 ++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c index 37a23aa..66d623f 100644 --- a/drivers/irqchip/irq-gic-v3.c +++ b/drivers/irqchip/irq-gic-v3.c @@ -642,11 +642,45 @@ static inline void gic_handle_nmi(u32 irqnr, struct pt_regs *regs) nmi_exit(); } +static u32 do_read_iar(struct pt_regs *regs) +{ + u32 iar; + + if (gic_supports_nmi() && unlikely(!interrupts_enabled(regs))) { + u64 pmr; + + /* + * We were in a context with IRQs disabled. However, the + * entry code has set PMR to a value that allows any + * interrupt to be acknowledged, and not just NMIs. This can + * lead to surprising effects if the NMI has been retired in + * the meantime, and that there is an IRQ pending. The IRQ + * would then be taken in NMI context, something that nobody + * wants to debug twice. + * + * Until we sort this, drop PMR again to a level that will + * actually only allow NMIs before reading IAR, and then + * restore it to what it was. + */ + pmr = gic_read_pmr(); + gic_pmr_mask_irqs(); + isb(); + + iar = gic_read_iar(); + + gic_write_pmr(pmr); + } else { + iar = gic_read_iar(); + } + + return iar; +} + static asmlinkage void __exception_irq_entry gic_handle_irq(struct pt_regs *regs) { u32 irqnr; - irqnr = gic_read_iar(); + irqnr = do_read_iar(regs); /* Check for special IDs first */ if ((irqnr >= 1020 && irqnr <= 1023))