Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3273667imm; Fri, 25 May 2018 02:52:23 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrAIvTNLhDG1bZyX4AUFcIctY6U43JG5+d255rK9yMuAkkHVAW8aLky4PniZZGLUwbQV1CX X-Received: by 2002:a17:902:622:: with SMTP id 31-v6mr1876010plg.135.1527241943600; Fri, 25 May 2018 02:52:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527241943; cv=none; d=google.com; s=arc-20160816; b=xkU79OQNwZWksq8rWN72p3lZLX5nAzgzmA7laUoj+xloSu3bCRoIg7dpAEOerZGyJz 9vY68HeQxYW8X1I68P5PEnzYIGdjna6vDDaM+DwvL5UDoLeyWXpmuk+WkBCybHG5S984 ci+HDlZsls0IIsuAaGr7YK++7wTCTXWAwJPC1u7LtPNjpXS/80wlJjX+z2vy4d4gpyoz C5EEp0hNBDnO9KTmsaMWO6v116wfvo271AtGErC5Qk74O/FRtzFj1zcb0gHRgNC0MjXX hw2UQcUohUppTGWusn61J2SEnDQ62J5KEj71+/CQr8MarxJq0wMb6Ksm7Fmm4R7KpeIZ ns2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Xe365MH/p+FKCJpHk0sLgmhhSDJIf4hHu1ZSHPHE6/M=; b=IPI05EVdEDYMiFgGNl9TRskA/s6U6PBBa4ItXfQXXU8alHWeiXdXVvAkJ+DDODAQu9 rZc7L0n6aZBSjnfAkvCrCw170BRtTyjyp8MJtOm9qf5DgSt0356xImdQ25IddYv16uRe MoCOJW3dJTrp41AQWCbLO4Z829zRydGPOCHo/vxeLgS/Eq51f1/aoqUkz4Cy9HknfI22 KqFRqFpam3/QICRxjqMzZLc/XwNfTsWui8a4ugW5WMxSRpM2kjAkH4NbNwjutcsAz1ch oI+5Vh22p1NrdjDdWEMbq4jQB8QUE/Y4HJPXHNgt6bcBuDbautlV3ti1XejdlwfJtcsY zydQ== 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 p13-v6si17722602pgv.182.2018.05.25.02.52.09; Fri, 25 May 2018 02:52:23 -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 S966244AbeEYJuw (ORCPT + 99 others); Fri, 25 May 2018 05:50:52 -0400 Received: from foss.arm.com ([217.140.101.70]:57642 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966147AbeEYJut (ORCPT ); Fri, 25 May 2018 05:50:49 -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 AF09A80D; Fri, 25 May 2018 02:50:49 -0700 (PDT) Received: from e112298-lin.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 643ED3F25D; Fri, 25 May 2018 02:50:47 -0700 (PDT) From: Julien Thierry To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, daniel.thompson@linaro.org, joel@joelfernandes.org, marc.zyngier@arm.com, mark.rutland@arm.com, christoffer.dall@arm.com, james.morse@arm.com, catalin.marinas@arm.com, will.deacon@arm.com, Julien Thierry , Jonathan Corbet , Thomas Gleixner , Jason Cooper Subject: [PATCH v4 22/26] arm64: Detect current view of GIC priorities Date: Fri, 25 May 2018 10:49:28 +0100 Message-Id: <1527241772-48007-23-git-send-email-julien.thierry@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1527241772-48007-1-git-send-email-julien.thierry@arm.com> References: <1527241772-48007-1-git-send-email-julien.thierry@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The values non secure EL1 needs to use for PMR and RPR registers depends on the value of SCR_EL3.FIQ. The values non secure EL1 sees from the distributor and redistributor depend on whether security is enabled for the GIC or not. Figure out what values we are dealing with to know if the values we use for PMR and RPR match the priority values that have been configured in the distributor and redistributors. Also, add firmware requirements related to SCR_EL3. Signed-off-by: Julien Thierry Cc: Catalin Marinas Cc: Will Deacon Cc: Jonathan Corbet Cc: Thomas Gleixner Cc: Jason Cooper Cc: Marc Zyngier --- Documentation/arm64/booting.txt | 5 +++++ drivers/irqchip/irq-gic-v3.c | 42 +++++++++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/Documentation/arm64/booting.txt b/Documentation/arm64/booting.txt index 8d0df62..e387938 100644 --- a/Documentation/arm64/booting.txt +++ b/Documentation/arm64/booting.txt @@ -188,6 +188,11 @@ Before jumping into the kernel, the following conditions must be met: the kernel image will be entered must be initialised by software at a higher exception level to prevent execution in an UNKNOWN state. + - SCR_EL3.FIQ must have the same value across all CPUs the kernel is + executing on. + - The value of SCR_EL3.FIQ must be the same as the one present at boot + time whenever the kernel is executing. + For systems with a GICv3 interrupt controller to be used in v3 mode: - If EL3 is present: ICC_SRE_EL3.Enable (bit 3) must be initialiased to 0b1. diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c index 2fd0440..b144f73 100644 --- a/drivers/irqchip/irq-gic-v3.c +++ b/drivers/irqchip/irq-gic-v3.c @@ -63,6 +63,28 @@ struct gic_chip_data { static struct gic_chip_data gic_data __read_mostly; static DEFINE_STATIC_KEY_TRUE(supports_deactivate_key); +/* + * The behaviours of RPR and PMR registers differ depending on the value of + * SCR_EL3.FIQ, and the behaviour of non-secure priority registers of the + * distributor and redistributors depends on whether security is enabled in the + * GIC. + * + * When security is enabled, non-secure priority values from the (re)distributor + * are presented to the GIC CPUIF as follow: + * (GIC_(R)DIST_PRI[irq] >> 1) | 0x80; + * + * If SCR_EL3.FIQ == 1, the values writen to/read from PMR and RPR at non-secure + * EL1 are subject to a similar operation thus matching the priorities presented + * from the (re)distributor when security is enabled. + * + * see GICv3/GICv4 Architecture Specification (IHI0069D): + * - section 4.8.1 Non-secure accesses to register fields for Secure interrupt + * priorities. + * - Figure 4-7 Secure read of the priority field for a Non-secure Group 1 + * interrupt. + */ +DEFINE_STATIC_KEY_FALSE(have_non_secure_prio_view); + static struct gic_kvm_info gic_v3_kvm_info; static DEFINE_PER_CPU(bool, has_rss); @@ -573,6 +595,12 @@ static void gic_update_vlpi_properties(void) !gic_data.rdists.has_direct_lpi ? "no " : ""); } +/* Check whether it's single security state view */ +static inline bool gic_dist_security_disabled(void) +{ + return readl_relaxed(gic_data.dist_base + GICD_CTLR) & GICD_CTLR_DS; +} + static void gic_cpu_sys_reg_init(void) { int i, cpu = smp_processor_id(); @@ -598,6 +626,9 @@ static void gic_cpu_sys_reg_init(void) /* Set priority mask register */ if (!arch_uses_gic_prios()) write_gicreg(DEFAULT_PMR_VALUE, ICC_PMR_EL1); + else if (static_branch_likely(&have_non_secure_prio_view) && group0) + /* Mismatch configuration with boot CPU */ + WARN_ON(group0 && !gic_dist_security_disabled()); /* * Some firmwares hand over to the kernel with the BPR changed from @@ -850,12 +881,6 @@ static int gic_set_affinity(struct irq_data *d, const struct cpumask *mask_val, #endif #ifdef CONFIG_CPU_PM -/* Check whether it's single security state view */ -static bool gic_dist_security_disabled(void) -{ - return readl_relaxed(gic_data.dist_base + GICD_CTLR) & GICD_CTLR_DS; -} - static int gic_cpu_pm_notifier(struct notifier_block *self, unsigned long cmd, void *v) { @@ -1155,6 +1180,11 @@ static int __init gic_init_bases(void __iomem *dist_base, gic_cpu_init(); gic_cpu_pm_init(); + if (arch_uses_gic_prios()) { + if (!gic_has_group0() || gic_dist_security_disabled()) + static_branch_enable(&have_non_secure_prio_view); + } + return 0; out_free: -- 1.9.1