Received: by 10.213.65.68 with SMTP id h4csp359491imn; Sat, 17 Mar 2018 06:36:07 -0700 (PDT) X-Google-Smtp-Source: AG47ELs8F2pQtDbFrQeUAv4Dqlcus7R0zbwXWsCaZ8YdPcyEn2G7o649nwQRuWHEk5Kwj4SRex6u X-Received: by 10.99.45.194 with SMTP id t185mr4360626pgt.267.1521293767024; Sat, 17 Mar 2018 06:36:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521293766; cv=none; d=google.com; s=arc-20160816; b=evCpb9BxVQttVGAAzyflnzmcP6UFnm/QXpaoijEweCmCil4ZMwqVbp8uyA3/9uIqJe 0HtUaK5bTPwRArnvamd48EyXgTP2grItfcn/FAK2Re5JWEuwECcPE6bolG1lkqMmjxNy B9EtB1OOUyIEplxdMBF8HXrtqTW1LGWb2mLuGNZQ+9RkzqltZet1o8Dx26CpqcWaRIQ6 +g/+wRfNJFs8SQMgdEcHwc3/c0fIS/b+jMP/qlPQQZgBNF86QaezbZce8TYZHu6gOup2 4sqBOp7D/OCw/RrPgfPfYgGXD8avWNTqMv2aXjGsFPDhWNFx3Lh2izsqf850B/Ax0rsE Khcw== 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:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:arc-authentication-results; bh=a+KJbAbKpxIxFyflGrfWt+EltgqwlljynHte0B/3UKI=; b=kMAt38RMFjLFDZek4LGF6/nNNjZF3vxeLqK4hTtT943A9cTj9FRt2GLrx9Sv+ADd1R Nb5fhCiQEfToyKz2flbY+tMPG1zLpQLxrGXGGo/VfuFzTtBFXSo+bxbNqZ5l5wg/wmy6 54GALRCFtYwkoQya6G5FgTY4T/Jmm8/+me21zGBMobugau6Ul3p0J25BsWFkwagI1Ohv zsIJzV9S0ylEPGKsNGd2tezOwcLT2SYqIomNFTOHsLwXfbfX6AnP5UQMDeO0Xy7SaU7G 1h4sfP00A8yjST8t0hl76TUc2pwGu2XqsMlpSxURy8/W2Cs3CwDzJATs9Tu+6LqOgJ7K St9w== 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 h19si7255151pfn.411.2018.03.17.06.35.51; Sat, 17 Mar 2018 06:36:06 -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 S1752313AbeCQNez (ORCPT + 99 others); Sat, 17 Mar 2018 09:34:55 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:40450 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751618AbeCQNey (ORCPT ); Sat, 17 Mar 2018 09:34:54 -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 E977C1529; Sat, 17 Mar 2018 06:34:53 -0700 (PDT) Received: from why.wild-wind.fr.eu.org (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 53DC93F487; Sat, 17 Mar 2018 06:34:52 -0700 (PDT) Date: Sat, 17 Mar 2018 13:34:45 +0000 From: Marc Zyngier To: Shanker Donthineni Cc: linux-kernel , linux-arm-kernel , Mark Rutland , Thomas Gleixner , Jason Cooper , Vikram Sethi Subject: Re: [PATCH v2] irqchip/gic-v3: Ensure GICR_CTLR.EnableLPI=0 is observed before enabling Message-ID: <20180317133445.772733ac@why.wild-wind.fr.eu.org> In-Reply-To: <1521124287-25009-1-git-send-email-shankerd@codeaurora.org> References: <1521124287-25009-1-git-send-email-shankerd@codeaurora.org> Organization: ARM Ltd X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: - 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. > + if (ret) { > + pr_err("CPU%d: Failed to disable LPIs\n", smp_processor_id()); > + return -EBUSY; > + } > + > + /* Wait for GICR_CTLR.RWP==0 or 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: Failed to observe RWP==0 after enabling LPIs\n", > + smp_processor_id()); > + return -EBUSY; > + } > + > + return 0; > +} > + > int its_cpu_init(void) > { > + int ret; > + > if (!list_empty(&its_nodes)) { nit: move 'ret' here. > - if (!gic_rdists_supports_plpis()) { > - pr_info("CPU%d: LPIs not supported\n", smp_processor_id()); > - return -ENXIO; > - } > + ret = redist_disable_lpis(); > + if (ret) > + return ret; > + > 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 c00c4c33..4d5fb60 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. -- Without deviation from the norm, progress is not possible.