Received: by 10.213.65.68 with SMTP id h4csp286588imn; Wed, 21 Mar 2018 19:00:06 -0700 (PDT) X-Google-Smtp-Source: AG47ELto2Tu9TkOzBijdBkbPncxPmtNsGcxN2qPjQwGdRr5R52X2IS/He5p0+T71VSgFw7kry59e X-Received: by 10.98.210.7 with SMTP id c7mr15233311pfg.92.1521684006900; Wed, 21 Mar 2018 19:00:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521684006; cv=none; d=google.com; s=arc-20160816; b=idaj/6SWGPOYnXxJz5VQkZcOBJzsnZy11XKtpGC/jRiL2NWu5Z24iKtLAUTjb/xprO Y+q5XsJ29umOqAoww7dTp3YJeBgFz+189W1Kj2emL7fdvmTGRTMAi2vTWy7BSQT1U1z3 R1Ui9xAAWUhrXJ8sr1DXnBUeHaA6s3PhdfNt9Catx7VZEKUsHhU/Nx9cjbNQhmMPBeiW jR5lWAAYlyV90yPz9lUxAcPRAYVuEtXi4QxPrmcJbs8UG7bV18EPWbX1WNBo1FSgD7Zd MQuyEEe7tcKNhGUf4ni4OgMJc5CiEPUnN3kPkkY9HzFk3hcXOBkO0jvjiNJGLDNHfHpB jH2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=HNIgZ9WbSzlU4LotbI+tgwLFBHPfvO62WLfm6z1Jleo=; b=bgr1hfzX/vgxpvu5XnQq6IJVAl+InM0lcsqKMXASp7jdx5l4rLRW2e5TY9xFds808B cS8wn79TKXk7rUYWv1Z6VYPbqxbQtEEjtwbAfcGAo5btJ88wcepQ+h0tt96p7JDmmUeE 2h8iXfPnTxP7bJ1GRmM02tCgJrJHJXwHzyJ+PVF2TjCyCkOQ+2ToozJ8wcL3WOoDtFgY nxYu0VRANwf7nuftRy7/47h3vONaKZjiAWEKmBnxX+jDkkwYnj+Ssz9kFKRUF/ydbWeS 6UhxsKholDL+2lApx1jHJpVL65WQoaDXbYIc4GhGyN3xyPArMYfi9YgnprKf/nICtuX9 dxSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=QBY3dptv; dkim=pass header.i=@codeaurora.org header.s=default header.b=QBY3dptv; 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 f6-v6si5321692plf.70.2018.03.21.18.59.50; Wed, 21 Mar 2018 19:00: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; dkim=pass header.i=@codeaurora.org header.s=default header.b=QBY3dptv; dkim=pass header.i=@codeaurora.org header.s=default header.b=QBY3dptv; 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 S1754350AbeCVB64 (ORCPT + 99 others); Wed, 21 Mar 2018 21:58:56 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:38774 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752725AbeCVB6y (ORCPT ); Wed, 21 Mar 2018 21:58:54 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id CB18760C65; Thu, 22 Mar 2018 01:58:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1521683933; bh=8PojuYaehDgA3yLAVbox5jSpwRO1+2gwyLH50FeCjXg=; h=From:To:Cc:Subject:Date:From; b=QBY3dptvja3DFikzoKAewuxVjs3OKOSQgK6/DeFJRqfPwJtr5hKJsH3SHeIA9EutB orL7uH1stMn3wGnfPmGPsWeTcXWo+OMCqpOilIVrSjGtOiH/s0a9JBfB4kb8x0FzrP dAJau9YQtEzZT1QAOsZe9Rmw8PTCbUD0YbEOahgc= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from shankerd-ubuntu.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: shankerd@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 43A94607A2; Thu, 22 Mar 2018 01:58:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1521683933; bh=8PojuYaehDgA3yLAVbox5jSpwRO1+2gwyLH50FeCjXg=; h=From:To:Cc:Subject:Date:From; b=QBY3dptvja3DFikzoKAewuxVjs3OKOSQgK6/DeFJRqfPwJtr5hKJsH3SHeIA9EutB orL7uH1stMn3wGnfPmGPsWeTcXWo+OMCqpOilIVrSjGtOiH/s0a9JBfB4kb8x0FzrP dAJau9YQtEzZT1QAOsZe9Rmw8PTCbUD0YbEOahgc= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 43A94607A2 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=shankerd@codeaurora.org From: Shanker Donthineni To: Marc Zyngier , linux-kernel , linux-arm-kernel Cc: Mark Rutland , Thomas Gleixner , Jason Cooper , Vikram Sethi , Shanker Donthineni Subject: [PATCH v3] irqchip/gic-v3: Ensure GICR_CTLR.EnableLPI=0 is observed before enabling Date: Wed, 21 Mar 2018 20:58:49 -0500 Message-Id: <1521683929-15644-1-git-send-email-shankerd@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 @@ -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", + 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; + 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) -- Qualcomm Datacenter Technologies, Inc. on behalf of the Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.