Received: by 10.213.65.68 with SMTP id h4csp802840imn; Thu, 22 Mar 2018 08:54:18 -0700 (PDT) X-Google-Smtp-Source: AG47ELuEOud3Z7cNvw1oCl/T2htH2bvIzWbaxcpmJhHv5IKQuTVXdPlLaIjKVniCRHnhD0p23jkL X-Received: by 10.99.170.70 with SMTP id x6mr16186445pgo.114.1521734058643; Thu, 22 Mar 2018 08:54:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521734058; cv=none; d=google.com; s=arc-20160816; b=DEIarq0qRfQQVvu30h9VhQiC0hxvTl88apfa9gm5ZYDLkK6cCemODLmydV60xN2uxN dA9B5oSu9MyCVayS881j/YE3Vb/9DfGTY+EV32WBvsdR3cBPaCgI1hz0hOMoLOMY07Eg hh3cQDDgBGPDDTnQ43bU/nIO7CgaP1f9308tW7lti9FSn52pj6IIvoqIpV3M5G7g/Lne vHPb36kwNQhzYADUX2bXNcbExoUJWuZhrdtD6fKRzZ+bw9wav5Tvgix2pOcLaAuT5q0/ 6YhDa21SWAP1AKgCwPs8XIK/TI+lozzc/R4CiGp+MuwFOb/bXStDjYoTKdNr8lkxQL6q WcYQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject :arc-authentication-results; bh=hMnClXGKlafah/qJzbRopYrk7yd0OmFi9vj+zmTbGWo=; b=loA2+jNwvuCt4RVucKP42IM4psIi7bAY7+veMXQgYQQMWcklj5EQrEF2Gb9y9/wa7r Kw0dtpevuRwZfM5ndUDPVks5FN1rG0xNdbrK1ZyxvdXj4J/FrgIt1UGVfEuAPoYAJ56+ SIWRi3voNO8g9emldYRSObtSDZsuhcGXDy2Go402xTAlYnmG6MRBEakAYLHdveMRa1za g2kOzn0EU5+hJBbDmwsTuLSkPEdpp5CA1TUU5BH0sT8Vj5kq8gLhb7Jv1KIfknrfbXSq EIARsmjbst7FnZ8a/rpFAY3t/a0QzBS4dTjz/Bk1/xI0SeH2ZXDpVWXDdfMMkg8J4P4C PkhA== 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 y16-v6si4975658pll.435.2018.03.22.08.54.04; Thu, 22 Mar 2018 08:54:18 -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 S1751798AbeCVPvV (ORCPT + 99 others); Thu, 22 Mar 2018 11:51:21 -0400 Received: from foss.arm.com ([217.140.101.70]:39426 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751752AbeCVPvS (ORCPT ); Thu, 22 Mar 2018 11:51:18 -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 4F6571529; Thu, 22 Mar 2018 08:51:18 -0700 (PDT) Received: from [10.1.206.75] (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BFC613F24A; Thu, 22 Mar 2018 08:51:15 -0700 (PDT) Subject: Re: [PATCH v3] irqchip/gic-v3: Ensure GICR_CTLR.EnableLPI=0 is observed before enabling To: Shanker Donthineni , linux-kernel , linux-arm-kernel Cc: Mark Rutland , Thomas Gleixner , Jason Cooper , Vikram Sethi References: <1521683929-15644-1-git-send-email-shankerd@codeaurora.org> From: Marc Zyngier Organization: ARM Ltd Message-ID: Date: Thu, 22 Mar 2018 15:51:14 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1521683929-15644-1-git-send-email-shankerd@codeaurora.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 22/03/18 01:58, 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 v2: > -Revert readl_relaxed_poll() usage since it's not usable in GICv3 probe(). > -Changes to pr_xxx messages. > > 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 | 75 +++++++++++++++++++++++++++++++------- > include/linux/irqchip/arm-gic-v3.h | 1 + > 2 files changed, 62 insertions(+), 14 deletions(-) > > diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c > index 2cbb19c..c1e8a8e 100644 > --- a/drivers/irqchip/irq-gic-v3-its.c > +++ b/drivers/irqchip/irq-gic-v3-its.c > @@ -33,6 +33,7 @@ > #include > #include > #include > +#include > > #include > #include This hunk doesn't apply to my -next branch, but I don't think it is actually required either... > @@ -1875,16 +1876,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 | > @@ -3287,13 +3278,69 @@ 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 timeout = USEC_PER_SEC; > + u64 val; > + > + 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; > + > + pr_warn("CPU%d: Booted with LPIs enabled, memory probably corrupted\n", > + smp_processor_id()); > + add_taint(TAINT_CRAP, LOCKDEP_STILL_OK); > + > + /* 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); > + > + /** > + * 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. > + */ > + while (readl_relaxed(rbase + GICR_CTLR) & GICR_CTLR_RWP) { > + if (!timeout) { > + pr_err("CPU%d: Failed to observe RWP==0 after disabling LPIs\n", I think you can simplify the message with something like: "Time-out disabling LPIs\n" Nobody apart from you and I really want to know about RWP... > + smp_processor_id()); > + return -ETIMEDOUT; > + } > + udelay(1); > + timeout--; > + } > + > + /** > + * 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 -EBUSY; > + } > + > + return 0; > +} > + > int its_cpu_init(void) > { > if (!list_empty(&its_nodes)) { > - if (!gic_rdists_supports_plpis()) { > - pr_info("CPU%d: LPIs not supported\n", smp_processor_id()); > - return -ENXIO; > - } > + int ret; > + > + ret = redist_disable_lpis(); > + if (ret) > + return ret; Just realised that this is totally broken. Why do we have this in the loop? Checking the LPI support for each ITS was admittedly braindead (we only need to check it once per CPU), but now trying to disable the LPIs each time we encounter an ITS is going to make it go crazy and taint the kernel for no reason. > + > its_cpu_init_lpis(); > its_cpu_init_collection(); > } > diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h > index b26eccc..c6f4c48 100644 > --- a/include/linux/irqchip/arm-gic-v3.h > +++ b/include/linux/irqchip/arm-gic-v3.h > @@ -106,6 +106,7 @@ > #define GICR_PIDR2 GICD_PIDR2 > > #define GICR_CTLR_ENABLE_LPIS (1UL << 0) > +#define GICR_CTLR_RWP (1UL << 3) > > #define GICR_TYPER_CPU_NUMBER(r) (((r) >> 8) & 0xffff) > > Thanks, M. -- Jazz is not dead. It just smells funny...