From patchwork Tue Jun 17 17:04:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 32080 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0595C206A0 for ; Tue, 17 Jun 2014 17:06:52 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id n16sf43143119oag.10 for ; Tue, 17 Jun 2014 10:06:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=0pZ6Q67fKVnAynK49uUQwim1IJHVJQuEzOpy6lVF38I=; b=jif/RywT/sf+HyOccOyUq1atBu6/RogPTtzDvOCQcKUslfwff1Q74glolx3ok9dUJU BLrOWeIWpYU7wMAgAJGt3m/s2FQ0yW9DLO4qKsFdvM5ZHSVT24eVC8n+epNJhleF0fzG wuEPgSvmtsyHdHmgTBUwCVpmNUAG1Epr1lvF4Ifjc+zlnRN2yMuw4zeZHTpowPco+w2/ C6i3xvizDcDvmwGGMAVD1mzKiUTsv60HeEKOqkvwbwj3ow7xUhWBuC/sIWDxuZv2liUp gDuANAQoUWa7GORhhxLAy/tuqwS8BRYMl1md063uk+Gk5zbfeWj6Cw5aZdQIEbwWLI0A 3EoQ== X-Gm-Message-State: ALoCoQn6okdvaEyjy9NUQ40DyEi/lP+nyshFqVOCqgJVOEJzBCoY0KF4XSA1yJWXFICLU1ZIX/vc X-Received: by 10.182.252.166 with SMTP id zt6mr1245537obc.17.1403024812567; Tue, 17 Jun 2014 10:06:52 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.27.138 with SMTP id 10ls4952858qgx.9.gmail; Tue, 17 Jun 2014 10:06:52 -0700 (PDT) X-Received: by 10.52.243.225 with SMTP id xb1mr7187729vdc.36.1403024812480; Tue, 17 Jun 2014 10:06:52 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id iq6si5715313vcb.100.2014.06.17.10.06.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 17 Jun 2014 10:06:52 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id hy10so6680363vcb.17 for ; Tue, 17 Jun 2014 10:06:52 -0700 (PDT) X-Received: by 10.221.26.10 with SMTP id rk10mr23165948vcb.0.1403024812384; Tue, 17 Jun 2014 10:06:52 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.54.6 with SMTP id vs6csp224757vcb; Tue, 17 Jun 2014 10:06:52 -0700 (PDT) X-Received: by 10.224.87.130 with SMTP id w2mr37727491qal.5.1403024811998; Tue, 17 Jun 2014 10:06:51 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id y9si9086216qad.113.2014.06.17.10.06.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jun 2014 10:06:51 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WwwpD-0007ZX-An; Tue, 17 Jun 2014 17:05:35 +0000 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wwwos-0006LX-2S for linux-arm-kernel@lists.infradead.org; Tue, 17 Jun 2014 17:05:15 +0000 Received: from leverpostej.cambridge.arm.com (leverpostej.cambridge.arm.com [10.1.205.151]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id s5HH4ewr015319; Tue, 17 Jun 2014 18:04:55 +0100 (BST) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Subject: [PATCHv2 3/4] arm64: cachetype: report weakest cache policy Date: Tue, 17 Jun 2014 18:04:33 +0100 Message-Id: <1403024674-25108-4-git-send-email-mark.rutland@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1403024674-25108-1-git-send-email-mark.rutland@arm.com> References: <1403024674-25108-1-git-send-email-mark.rutland@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140617_100514_525317_FE66F89B X-CRM114-Status: GOOD ( 14.86 ) X-Spam-Score: -6.0 (------) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-6.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [217.140.96.50 listed in list.dnswl.org] -1.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record Cc: Mark Rutland , lorenzo.pieralisi@arm.com, will.deacon@arm.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: mark.rutland@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 In big.LITTLE systems, the I-cache policy may differ across CPUs, and thus we must always meet the most stringent maintenance requirements of any I-cache in the system when performing maintenance to ensure correctness. Unfortunately this requirement is not met as we always look at the current CPU's cache type register to determine the maintenance requirements. This patch causes the I-cache policy of all CPUs to be taken into account for icache_is_aliasing and icache_is_aivivt. If any I-cache in the system is aliasing or AIVIVT, the respective function will return true. At boot each CPU may set flags to identify that at least one I-cache in the system is aliasing and/or AIVIVT. The now unused and potentially misleading icache_policy function is removed. Signed-off-by: Mark Rutland --- arch/arm64/include/asm/cachetype.h | 16 ++++++++++------ arch/arm64/include/asm/cpu.h | 1 + arch/arm64/kernel/cpuinfo.c | 28 +++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/cachetype.h b/arch/arm64/include/asm/cachetype.h index 4b23e75..7a2e076 100644 --- a/arch/arm64/include/asm/cachetype.h +++ b/arch/arm64/include/asm/cachetype.h @@ -30,10 +30,14 @@ #ifndef __ASSEMBLY__ -static inline u32 icache_policy(void) -{ - return (read_cpuid_cachetype() >> CTR_L1IP_SHIFT) & CTR_L1IP_MASK; -} +#include + +#define CTR_L1IP(ctr) (((ctr) >> CTR_L1IP_SHIFT) & CTR_L1IP_MASK) + +#define ICACHEF_ALIASING BIT(0) +#define ICACHEF_AIVIVT BIT(1) + +extern unsigned long __icache_flags; /* * Whilst the D-side always behaves as PIPT on AArch64, aliasing is @@ -41,12 +45,12 @@ static inline u32 icache_policy(void) */ static inline int icache_is_aliasing(void) { - return icache_policy() != ICACHE_POLICY_PIPT; + return test_bit(ICACHEF_ALIASING, &__icache_flags); } static inline int icache_is_aivivt(void) { - return icache_policy() == ICACHE_POLICY_AIVIVT; + return test_bit(ICACHEF_AIVIVT, &__icache_flags); } static inline u32 cache_type_cwg(void) diff --git a/arch/arm64/include/asm/cpu.h b/arch/arm64/include/asm/cpu.h index 74bf9bb..daca48d 100644 --- a/arch/arm64/include/asm/cpu.h +++ b/arch/arm64/include/asm/cpu.h @@ -20,6 +20,7 @@ */ struct cpuinfo_arm64 { struct cpu cpu; + u32 reg_ctr; u32 reg_midr; }; diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c index 340621d..b146148 100644 --- a/arch/arm64/kernel/cpuinfo.c +++ b/arch/arm64/kernel/cpuinfo.c @@ -14,18 +14,44 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include #include +#include +#include #include DEFINE_PER_CPU(struct cpuinfo_arm64, cpu_data); +static char *icache_policy_str[] = { + [ICACHE_POLICY_RESERVED] = "RESERVED/UNKNOWN", + [ICACHE_POLICY_AIVIVT] = "AIVIVT", + [ICACHE_POLICY_VIPT] = "VIPT", + [ICACHE_POLICY_PIPT] = "PIPT", +}; + +unsigned long __icache_flags; + +static void cpuinfo_detect_icache_policy(struct cpuinfo_arm64 *info, int cpu) +{ + u32 l1ip = CTR_L1IP(info->reg_ctr); + + if (l1ip != ICACHE_POLICY_PIPT) + set_bit(ICACHEF_ALIASING, &__icache_flags); + if (l1ip == ICACHE_POLICY_AIVIVT); + set_bit(ICACHEF_AIVIVT, &__icache_flags); + + pr_info("Detected %s I-cache on CPU%d", icache_policy_str[l1ip], cpu); +} + void cpuinfo_store_cpu(void) { int cpu = smp_processor_id(); struct cpuinfo_arm64 *cpuinfo = &per_cpu(cpu_data, cpu); + cpuinfo->reg_ctr = read_cpuid_cachetype(); cpuinfo->reg_midr = read_cpuid_id(); -} + cpuinfo_detect_icache_policy(cpuinfo, cpu); +}