Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2079275rdb; Tue, 3 Oct 2023 09:32:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFE8jWappIyq9xKyPhd4VjqVtYBVF79w71k4MYMCEWqnDUa6RxebcxVUXXfR9f1LLRzL0l1 X-Received: by 2002:a05:6a20:3d95:b0:159:b7dc:2295 with SMTP id s21-20020a056a203d9500b00159b7dc2295mr10691pzi.9.1696350754213; Tue, 03 Oct 2023 09:32:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696350754; cv=none; d=google.com; s=arc-20160816; b=bAi9icXQ9IXSC6i6W2BQqguMLLZFOiA3NxpFMbbOLm7iuPpVF3R76qyyDuVZlFPOvW k18PE3Sj36P0OXEWWlL6jL2U/dFwSNEaxwThETsnouBQHeNID3QqJS92bTnPfg4hVXb1 V9k3i17f/wqUAL+J5KqSjBBVCWXKqps1ljWElNcG0HbiS958yMZxnL4OCs+bdQ5EVNN0 f1hDHRI/G5lhdcaALkCAn3VShK+KkDuJklnpYZFQatPq/bM21mQlVgiwaDbIE5ttnbB9 s8NQih7+b97AgUW2GIXr8RgNvT1kq42UUXQKTKtKn2Q6xmQ58w0S47/LulTUj1Jc9KVG d/6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=jnAappGLcI7SttRhXM5h4PO6a2E358kygnqSmyrYV5g=; fh=YKYmj84m4EMVQJOuyG2d2Dfkmmv3x2LBVjLW/wRC8Mw=; b=N6RZxzzbuwVJehrVY75L3NTxiHZ4o+fgp4VowNwW8BbDaoe1oUdvfsBIxe3E8b9HNv 2GboTJM2gnMGlGE/rLZusI6hv2A1wlAQ1oZpmnv9QXYSXlD+ICbLOwp3/QvBlAreE2ue +xs+mD5gfWflVm543JTMwbKQFZe8hPiHbrkCu52pEqyCu2pRj3GxmSXqLDq+up93v/Rk qrhU1cu83Yn4bQomfcpmS1ezE9VkaBoh6suNDIlfoufV2friv2pbwUCk8SlYZ/Fyuc+D 49mfD4ivo40HE9AtpJZMSWpZ71wA5GKtHfctSlgNouTsPPv9DQpymhMqDvm7MrLU7HF6 V7Rw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id u11-20020a6540cb000000b0057795cb4f16si1685701pgp.684.2023.10.03.09.32.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 09:32:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 309F6817C1E3; Tue, 3 Oct 2023 09:32:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231592AbjJCQcT (ORCPT + 99 others); Tue, 3 Oct 2023 12:32:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240373AbjJCQcS (ORCPT ); Tue, 3 Oct 2023 12:32:18 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CF85391 for ; Tue, 3 Oct 2023 09:32:14 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 18165C15; Tue, 3 Oct 2023 09:32:53 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.93.206]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CA9753F762; Tue, 3 Oct 2023 09:32:11 -0700 (PDT) Date: Tue, 3 Oct 2023 17:32:09 +0100 From: Mark Rutland To: Doug Anderson Cc: Catalin Marinas , Will Deacon , Marc Zyngier , Stephen Boyd , Valentin Schneider , Chen-Yu Tsai , AngeloGioacchino Del Regno , D Scott Phillips , Josh Poimboeuf , Matthias Brugger , Misono Tomohiro , Peter Zijlstra , Sumit Garg , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org Subject: Re: [PATCH 1/2] arm64: smp: Fix pseudo NMI issues w/ broken Mediatek FW Message-ID: References: <20231002094526.1.Ie8f760213053e3d11592f892b30912dbac6b8b48@changeid> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 03 Oct 2023 09:32:27 -0700 (PDT) On Tue, Oct 03, 2023 at 06:43:07AM -0700, Doug Anderson wrote: > Hi, > > On Tue, Oct 3, 2023 at 5:29 AM Mark Rutland wrote: > > > > On Mon, Oct 02, 2023 at 12:16:17PM -0700, Doug Anderson wrote: > > > Hi, > > > > > > On Mon, Oct 2, 2023 at 10:24 AM Mark Rutland wrote: > > > > > > > > On Mon, Oct 02, 2023 at 09:45:29AM -0700, Douglas Anderson wrote: > > > > > Some mediatek devices have the property > > > > > "mediatek,broken-save-restore-fw" in their GIC. This means that, > > > > > although the hardware supports pseudo-NMI, the firmware has a bug > > > > > that blocks enabling it. When we're in this state, > > > > > system_uses_irq_prio_masking() will return true but we'll fail to > > > > > actually enable the IRQ in the GIC. > > > > > > > > > > Let's make the code handle this. We'll detect that we failed to > > > > > request an IPI as NMI and fallback to requesting it normally. Though > > > > > we expect that either all of our requests will fail or all will > > > > > succeed, it's just as cheap to keep a per-IPI bitmap and that keeps us > > > > > robust. > > > > > > > > > > Fixes: 331a1b3a836c ("arm64: smp: Add arch support for backtrace using pseudo-NMI") > > > > > Reported-by: Chen-Yu Tsai > > > > > Closes: https://issuetracker.google.com/issues/197061987#comment68 > > > > > Signed-off-by: Douglas Anderson > > > > > --- > > > > > > > > > > arch/arm64/kernel/smp.c | 19 ++++++++++++------- > > > > > 1 file changed, 12 insertions(+), 7 deletions(-) > > > > > > > > I'm not too keen on falling back here when we have no idea why the request failed. > > > > > > > > I'd prefer if we could check the `supports_pseudo_nmis` static key directly to > > > > account for the case of broken FW, e.g. as below. > > > > > > > > Mark. > > > > > > > > ---->8---- > > > > From 72fdec05c64a74f21871b44c7c760bbe07cac044 Mon Sep 17 00:00:00 2001 > > > > From: Mark Rutland > > > > Date: Mon, 2 Oct 2023 18:00:36 +0100 > > > > Subject: [PATCH] arm64: smp: avoid NMI IPIs with broken MediaTek FW > > > > > > > > Some MediaTek devices have broken firmware which corrupts some GICR > > > > registers behind the back of the OS, and pseudo-NMIs cannot be used on > > > > these devices. For more details see commit: > > > > > > > > 44bd78dd2b8897f5 ("irqchip/gic-v3: Disable pseudo NMIs on Mediatek devices w/ firmware issues") > > > > > > > > We did not take this problem into account in commit: > > > > > > > > 331a1b3a836c0f38 ("arm64: smp: Add arch support for backtrace using pseudo-NMI") > > > > > > > > Since that commit arm64's SMP code will try to setup some IPIs as > > > > pseudo-NMIs, even on systems with broken FW. The GICv3 code will > > > > (rightly) reject attempts to request interrupts as pseudo-NMIs, > > > > resulting in boot-time failures. > > > > > > > > Avoid the problem by taking the broken FW into account when deciding to > > > > request IPIs as pseudo-NMIs. The GICv3 driver maintains a static_key > > > > named "supports_pseudo_nmis" which is false on systems with broken FW, > > > > and we can consult this within ipi_should_be_nmi(). > > > > > > > > Fixes: 331a1b3a836c0f38 ("arm64: smp: Add arch support for backtrace using pseudo-NMI") > > > > Reported-by: Chen-Yu Tsai > > > > Closes: https://issuetracker.google.com/issues/197061987#comment68 > > > > Signed-off-by: Mark Rutland > > > > Cc: Douglas Anderson > > > > Cc: Marc Zyngier > > > > --- > > > > arch/arm64/kernel/smp.c | 5 ++++- > > > > drivers/irqchip/irq-gic-v3.c | 2 +- > > > > 2 files changed, 5 insertions(+), 2 deletions(-) > > > > > > Sure, this is OK w/ me as long as folks don't mind accessing the > > > global here, it's OK w/ me: > > > > > > Reviewed-by: Douglas Anderson > > > > > > It seems to work for me, thus: > > > > > > Tested-by: Douglas Anderson > > > > > > > > > > diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c > > > > index 814d9aa93b21b..061c69160f90f 100644 > > > > --- a/arch/arm64/kernel/smp.c > > > > +++ b/arch/arm64/kernel/smp.c > > > > @@ -964,7 +964,10 @@ static void smp_cross_call(const struct cpumask *target, unsigned int ipinr) > > > > > > > > static bool ipi_should_be_nmi(enum ipi_msg_type ipi) > > > > { > > > > - if (!system_uses_irq_prio_masking()) > > > > + DECLARE_STATIC_KEY_FALSE(supports_pseudo_nmis); > > > > + > > > > + if (!system_uses_irq_prio_masking() || > > > > + !static_branch_likely(&supports_pseudo_nmis)) > > > > > > One thought, actually, is whether we should actually change > > > system_uses_irq_prio_masking() to return the correct value. What do > > > you think? > > > > I don't think we should add this to system_uses_irq_prio_masking(); that's used > > by the low-level flags manipulation code that gets inlined all over the place, > > and that code will work regarldess of whether we actually use NMI priorities. > > > > If we want to avoid using PMR masking *at all* on these platforms, we'd need to > > detect that within can_use_gic_priorities() or early_enable_pseudo_nmi(). > > I suspect that anyone trying to use PMR masking on these systems for > any purpose will be unhappy. The issue is talked about in: > > https://issuetracker.google.com/281831288 > > ...where you can see that the firmware on these systems isn't properly > saving/restoring some registers, including GICR_IPRIORITYR. Ok, then that's a latent bug even before the IPI changes, going back to the original workaround in commit: 44bd78dd2b8897f5 ("irqchip/gic-v3: Disable pseudo NMIs on Mediatek devices w/ firmware issues") For the sake of those reading the archive, can we have a better description of what exactly happens on these boards? IIUC on these boards the firmware fails to save+restore (some?) GICR registers across (some?) PSCI CPU_SUSPEND idle states. Which registers does it save+restore? Does it reset other registers into a specific state? Thanks, Mark.