Received: by 10.213.65.68 with SMTP id h4csp458202imn; Sat, 17 Mar 2018 10:15:47 -0700 (PDT) X-Google-Smtp-Source: AG47ELtuCxrhVe3tWhEl6Am/ZccbawI7cFsyrL1+PYWRACjolPSAyV+DRShoGToyHZ8Mmu4TqZyn X-Received: by 10.99.110.11 with SMTP id j11mr4801063pgc.294.1521306947530; Sat, 17 Mar 2018 10:15:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521306947; cv=none; d=google.com; s=arc-20160816; b=EEteby2VtMp0vnPRrXnUw0ljFjtfITDJoc0mZjMjQtzz5JAUCs7upTsUFzOTb+9vQs iO7uiXAnozYC2OjlxWqGWz37NJWhpeR2bhFU9tRIwLoJrtL99K6UHaYga1RJDqoZaHJg HNYtCWulOQsoUag/RcQc4pxU5moO9mplbx4kzKm4BqbQ22v/siIpVUj0ofWiPUa+jCbz 9UA4NXYeNv/qMCvcrdlLN54vUx5AMtRvuOUozPDao5VruUX1BR5JuUV9yNnSLcB5+RGQ pC8bUy2Dq8mdKY4QT/ayX6jSDwiDeXAVECGcEIs5Se0zg1hQEm4IEFvIFSlRiK2K2JIs nCgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:organization:user-agent :references:in-reply-to:subject:cc:to:from:message-id:date :arc-authentication-results; bh=9F6VHll+qFX16MWPbjAoJ8llVp9gHulK4FyeCBcR8/Q=; b=QnPLwrC0yJTJNplImSz9BeS5vs6kleZESNaElMPNk7G91lztKK78q0ASFaxeI+3doh c54f/eP9JpS1c9bLVxZ+Se+jqBRdqX0MoU3v76ygS7YK/C43MRfFgsgPujq9Drhw4G/M z0hU+ZOtEqo3x6KP1GmyEQvR4ssqdtH+ktF30M3zD+1AA+jMiTXJYmG6VPGNMNZF6RSa 02AGNpGDyMePj/uZZKLoU1JrDAczc4DluZpIVN5NdhnsR6l24ljGiALEzNqaQB+iDLGh V2BVKm7P78IqTGJi7f7xhD0KsuhjjsXf66LoJRDdGxSi85/xWax4cd9ppf/5AA3oIBEe fQWA== ARC-Authentication-Results: i=1; mx.google.com; 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 c18si7577703pfe.335.2018.03.17.10.15.33; Sat, 17 Mar 2018 10:15:47 -0700 (PDT) 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; 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 S1753264AbeCQRNl (ORCPT + 99 others); Sat, 17 Mar 2018 13:13:41 -0400 Received: from foss.arm.com ([217.140.101.70]:41202 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752676AbeCQRNj (ORCPT ); Sat, 17 Mar 2018 13:13:39 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BB5041529; Sat, 17 Mar 2018 10:13:38 -0700 (PDT) Received: from big-swifty.misterjones.org (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D71783F24A; Sat, 17 Mar 2018 10:13:36 -0700 (PDT) Date: Sat, 17 Mar 2018 17:13:33 +0000 Message-ID: <864llebp6q.wl-marc.zyngier@arm.com> From: Marc Zyngier To: shankerd@codeaurora.org Cc: Mark Rutland , Jason Cooper , Vikram Sethi , linux-kernel , Thomas Gleixner , linux-arm-kernel Subject: Re: [PATCH v2] irqchip/gic-v3: Ensure GICR_CTLR.EnableLPI=0 is observed before enabling In-Reply-To: References: <1521124287-25009-1-git-send-email-shankerd@codeaurora.org> <20180317133445.772733ac@why.wild-wind.fr.eu.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL/10.8 EasyPG/1.0.0 Emacs/25.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Organization: ARM Ltd MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 17 Mar 2018 16:11:06 +0000, Shanker Donthineni wrote: > > Hi Marc, > > On 03/17/2018 08:34 AM, Marc Zyngier wrote: > > On Thu, 15 Mar 2018 09:31:27 -0500 > > Shanker Donthineni wrote: > > > >> The definition of the GICR_CTLR.RWP control bit was expanded to indicate > >> status of changing GICR_CTLR.EnableLPI from 1 to 0 is being in progress > >> or completed. Software must observe GICR_CTLR.RWP==0 after clearing > >> GICR_CTLR.EnableLPI from 1 to 0 and before writing GICR_PENDBASER and/or > >> GICR_PROPBASER, otherwise behavior is UNPREDICTABLE. > >> > >> Signed-off-by: Shanker Donthineni > >> --- > >> Changes since v1: > >> -Moved LPI disable code to a seperate function as Marc suggested. > >> -Mark's suggestion to use readl_relaxed_poll_timeout() helper functions. > >> > >> drivers/irqchip/irq-gic-v3-its.c | 66 ++++++++++++++++++++++++++++++-------- > >> include/linux/irqchip/arm-gic-v3.h | 1 + > >> 2 files changed, 53 insertions(+), 14 deletions(-) > >> > >> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c > >> index 1d3056f..cba71a7 100644 > >> --- a/drivers/irqchip/irq-gic-v3-its.c > >> +++ b/drivers/irqchip/irq-gic-v3-its.c > >> @@ -33,6 +33,8 @@ > >> #include > >> #include > >> #include > >> +#include > >> +#include > >> > >> #include > >> #include > >> @@ -1875,16 +1877,6 @@ static void its_cpu_init_lpis(void) > >> gic_data_rdist()->pend_page = pend_page; > >> } > >> > >> - /* Disable LPIs */ > >> - val = readl_relaxed(rbase + GICR_CTLR); > >> - val &= ~GICR_CTLR_ENABLE_LPIS; > >> - writel_relaxed(val, rbase + GICR_CTLR); > >> - > >> - /* > >> - * Make sure any change to the table is observable by the GIC. > >> - */ > >> - dsb(sy); > >> - > >> /* set PROPBASE */ > >> val = (page_to_phys(gic_rdists->prop_page) | > >> GICR_PROPBASER_InnerShareable | > >> @@ -3288,13 +3280,59 @@ static bool gic_rdists_supports_plpis(void) > >> return !!(gic_read_typer(gic_data_rdist_rd_base() + GICR_TYPER) & GICR_TYPER_PLPIS); > >> } > >> > >> +static int redist_disable_lpis(void) > >> +{ > >> + void __iomem *rbase = gic_data_rdist_rd_base(); > >> + u64 val; > >> + int ret; > >> + > >> + if (!gic_rdists_supports_plpis()) { > >> + pr_info("CPU%d: LPIs not supported\n", smp_processor_id()); > >> + return -ENXIO; > >> + } > >> + > >> + val = readl_relaxed(rbase + GICR_CTLR); > >> + if (!(val & GICR_CTLR_ENABLE_LPIS)) > >> + return 0; > >> + > >> + /* Disable LPIs */ > >> + val &= ~GICR_CTLR_ENABLE_LPIS; > >> + writel_relaxed(val, rbase + GICR_CTLR); > >> + > >> + /* Make sure any change to GICR_CTLR is observable by the GIC */ > >> + dsb(sy); > >> + > >> + /* Wait for GICR_CTLR.GICR_CTLR_ENABLE_LPIS==0 or timeout */ > >> + ret = readl_relaxed_poll_timeout_atomic(rbase + GICR_CTLR, val, > >> + !(val & GICR_CTLR_ENABLE_LPIS), 1, > >> + USEC_PER_SEC); > > > > Why do you need to poll on EnableLPIs? It is supposed to be immediately > > written. It seems to me that the sequence should be: > > > > Agree we don't need to poll EnableLPIs here. I'll remove. > > > - Check EnableLPis > > - If set to 1, scream about bootloader being braindead > > - Write EnableLPIs to 0 > > - Read back EnableLpis: > > - If still set 1, bail out, we're doomed. Scream about the HW being > > braindead > > - Poll RWP > > - If timeout, bail out, the HW has locked up. Scream again. > > > > I think this should cover the whole thing. An alternative would be to > > place the poll between the write and read-back, but that doesn't change > > anything. > > > > I'll prefer your second approach. Please comment on the below change before > I post v3. > > static int redist_disable_lpis(void) > { > void __iomem *rbase = gic_data_rdist_rd_base(); > u64 val; > int ret; > > if (!gic_rdists_supports_plpis()) { > pr_info("CPU%d: LPIs not supported\n", smp_processor_id()); > return -ENXIO; > } > > if (!(readl(rbase + GICR_CTLR) & GICR_CTLR_ENABLE_LPIS)) > return 0; > > pr_warn("CPU%d: Trying to disable LPIs\n", smp_processor_id()); I'd be much more clear: pr_warn("CPU%d: Booted with LPIs enabled, memory probably corrupted\n", smp_processor_id()); add_taint(TAINT_CRAP, LOCKDEP_STILL_OK); > val &= ~GICR_CTLR_ENABLE_LPIS; > writel_relaxed(val, rbase + GICR_CTLR); > > /* Make sure any change to GICR_CTLR is observable by the GIC */ > dsb(sy); > > /** > * Software must observe RWP==0 after clearing GICR_CTLR.EnableLPIs > * from 1 to 0 before programming GICR_PEND{PROP}BASER registers. > * Bail out the driver probe() in case of timeout. > */ > ret = readl_relaxed_poll_timeout_atomic(rbase + GICR_CTLR, val, > !(val & GICR_CTLR_RWP), 1, > USEC_PER_SEC); > if (ret) { > pr_err("CPU%d: EnableLPIs not observed\n", smp_processor_id()); Let's call a spade a spade: the redistributor hasn't reacted after a whole second, it has probably locked-up. Just say so, because your message doesn't mean much to me. > return ret; > } > > /** > * After it has been written to 1, it is IMPLEMENTATION DEFINED whether > * the bit GICR_CTLR.EnableLPI becomes RES1 or can be cleared to 0. > * Bail out the driver probe() on systems where it's RES1. > */ > if (readl_relaxed(rbase + GICR_CTLR) & GICR_CTLR_ENABLE_LPIS) { > pr_err("CPU%d: Failed to disable LPIs\n", smp_processor_id()); > return -EPERM; EPERM? EBUSY was a better approximation... Thanks, M. -- Jazz is not dead, it just smell funny.