From patchwork Thu Oct 24 12:48:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 177448 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp2142639ill; Thu, 24 Oct 2019 05:49:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqz45a6c7oQRgtAdYfNtryy+vBqNJdBC6oqtiwmS6iQgX9uZdRavk56ADJSJo7NeXSG4ncGH X-Received: by 2002:a05:6402:557:: with SMTP id i23mr42717942edx.71.1571921375899; Thu, 24 Oct 2019 05:49:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571921375; cv=none; d=google.com; s=arc-20160816; b=WoPlKyQmgY0jziZB2bJ/1evEPHq8HTU6LgMVceuLd7Z/fglS2xx7XH0Vh/ksE/yt2e IKYGU8Xdxrz/2s2MZ0XSH1mOn7IVcYfQrK2aJ2A5x9qYk8mXgOrDEU0kxPeA1y3uOf4D qFP4y62pr+WhoQzzrhzF7+0NQVK+QPTrjEMhTUs5SLQMWPioDfrQLDzVwOkp8+QcTdWO TSMHTuOMVRDCT98I5QgmWoZFlKxkBHAVDw9/K/HnWznExP3LpfHwFWs5GCdHBK+8Of8w AiZGxpA+Ugd2HgDZycRdGgzG0ECN5FFGbgV6KE6MVxau4RWSKceIu6mr9Z6tD1Oh0Ame 8s6g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gzFM3RyzENfVewP1wnm0lxMkCup4hV7qkdK3Ri3PuLQ=; b=A4CrTKYDFGrlfgqTmj76NgkGZpvKwmGqQ4pHsw0tFvS4HqtKTJBZkBH1ak8thrQwCc 1VUQ36ZdEEbeOPGOC9aRFnVm8/CJ33HCPj6rPwsQTjuGHfFGQBFv/5AdQAN4XD2BDThM HOm+ThUxL0gxLezs7DDSJQJbJfzfsxnm05/En8HkNoscMMCSK7hDZwikZXz7l7T7YEZ7 L/1jCspocq8xbKsFL4rXm9CS76aWuADp/97H8Ge+ZjArNQr9tqDgqv5s1D+L4zOY/Sfa jH1tdNOXOqlMxtVppx5PRMqhE7GC6Sg+H205f6GHjkyQyZ3aXqfxDlTZF16j6M/2uM2R XyuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SAOryz4q; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3si12973378eda.251.2019.10.24.05.49.35; Thu, 24 Oct 2019 05:49:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org header.s=google header.b=SAOryz4q; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502112AbfJXMtf (ORCPT + 14 others); Thu, 24 Oct 2019 08:49:35 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:40571 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2502106AbfJXMtf (ORCPT ); Thu, 24 Oct 2019 08:49:35 -0400 Received: by mail-wm1-f67.google.com with SMTP id w9so1306206wmm.5 for ; Thu, 24 Oct 2019 05:49:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gzFM3RyzENfVewP1wnm0lxMkCup4hV7qkdK3Ri3PuLQ=; b=SAOryz4qpF7vLLg8STwu/HsXJnEmiJKZ6wctIgxpjR42vqnnEn9dUORMvRtal8iNeG hi0m0QtCMdEhFInZZw3rkEEUj+/ewHeIhYGzxO1DYgl8UkS90BJbOFX7ES84MVB537zn MYCJyLiN7mb127hwZoaIWuSQDrW5jKb1ue1z9EUIJwHTxQ5AB192EmhdkfMM8GvaPZSk IDx2KwCH95cY/ceZ8Bq8Leu69oNtSkYdNPX67FaFIdyE67RNmNURmN6GlojwSJ2+ceKh E8q6LeGZjRyDU3rsuVOhkj0t65PgFowrIDKYs/m7mYWviR/1L+LPLbQ4Czf/Jok210YH qpVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gzFM3RyzENfVewP1wnm0lxMkCup4hV7qkdK3Ri3PuLQ=; b=kcodhzDRbrhKXX7xEmlbIcnJW2H+QOi3Kn/JKSs4bdFdUeWH5TvurqiFYsZ1lxB53G gNLhijQjBtE7EkFyfvCqQAYmule9InfYdCBRN3QSKpoLrFzQeDradJ6YbCHOAzVKz2Ip jemOlqr85PFsXDTdBFv3gk4DHStPIaKrm7x7eIAcVCmgbbfbEb6iwEO645ysCz3kpJyd iiJDTKVJSGk5cUtS3oegRygE76HkscOB8VFPZollJ7zB2Pzm6eAXOPaRnuPEOo25eK3L y1Iexww4yV6mueoRzWAFQJpylYPJPD/q/w7ZLkH2hFkOxMPDwEWCpQz8GVcrVLc9Wk4w Pktw== X-Gm-Message-State: APjAAAX1elAwt2Mg73AZdRlzN1NlVqYNSNsm2821I/10Na9fobI1uPQY NrVrkLuUwr/6c4A8A3FaqYvuBsp4ohEFaLpv X-Received: by 2002:a1c:f018:: with SMTP id a24mr4666375wmb.77.1571921371016; Thu, 24 Oct 2019 05:49:31 -0700 (PDT) Received: from localhost.localdomain (aaubervilliers-681-1-126-126.w90-88.abo.wanadoo.fr. [90.88.7.126]) by smtp.gmail.com with ESMTPSA id j22sm29111038wrd.41.2019.10.24.05.49.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 05:49:30 -0700 (PDT) From: Ard Biesheuvel To: stable@vger.kernel.org Cc: Ard Biesheuvel , Will Deacon , Catalin Marinas , Marc Zyngier , Mark Rutland , Suzuki K Poulose , Jeremy Linton , Andre Przywara , Alexandru Elisei , Will Deacon , Dave Martin Subject: [PATCH for-stable-4.14 26/48] arm64: Add helpers for checking CPU MIDR against a range Date: Thu, 24 Oct 2019 14:48:11 +0200 Message-Id: <20191024124833.4158-27-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191024124833.4158-1-ard.biesheuvel@linaro.org> References: <20191024124833.4158-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Suzuki K Poulose [ Upstream commit 1df310505d6d544802016f6bae49aab836ae8510 ] Add helpers for checking if the given CPU midr falls in a range of variants/revisions for a given model. Cc: Will Deacon Cc: Mark Rutland Cc: Ard Biesheuvel Reviewed-by: Dave Martin Signed-off-by: Suzuki K Poulose Signed-off-by: Will Deacon Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/cpufeature.h | 4 +-- arch/arm64/include/asm/cputype.h | 30 ++++++++++++++++++++ arch/arm64/kernel/cpu_errata.c | 18 +++++------- 3 files changed, 39 insertions(+), 13 deletions(-) -- 2.20.1 diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 839aaa1505a3..ade058ada2b0 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -10,6 +10,7 @@ #define __ASM_CPUFEATURE_H #include +#include #include #include @@ -302,8 +303,7 @@ struct arm64_cpu_capabilities { void (*cpu_enable)(const struct arm64_cpu_capabilities *cap); union { struct { /* To be used for erratum handling only */ - u32 midr_model; - u32 midr_range_min, midr_range_max; + struct midr_range midr_range; }; struct { /* Feature register checking */ diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h index 04569aa267fd..c60eb29ea261 100644 --- a/arch/arm64/include/asm/cputype.h +++ b/arch/arm64/include/asm/cputype.h @@ -125,6 +125,36 @@ #define read_cpuid(reg) read_sysreg_s(SYS_ ## reg) +/* + * Represent a range of MIDR values for a given CPU model and a + * range of variant/revision values. + * + * @model - CPU model as defined by MIDR_CPU_MODEL + * @rv_min - Minimum value for the revision/variant as defined by + * MIDR_CPU_VAR_REV + * @rv_max - Maximum value for the variant/revision for the range. + */ +struct midr_range { + u32 model; + u32 rv_min; + u32 rv_max; +}; + +#define MIDR_RANGE(m, v_min, r_min, v_max, r_max) \ + { \ + .model = m, \ + .rv_min = MIDR_CPU_VAR_REV(v_min, r_min), \ + .rv_max = MIDR_CPU_VAR_REV(v_max, r_max), \ + } + +#define MIDR_ALL_VERSIONS(m) MIDR_RANGE(m, 0, 0, 0xf, 0xf) + +static inline bool is_midr_in_range(u32 midr, struct midr_range const *range) +{ + return MIDR_IS_CPU_MODEL_RANGE(midr, range->model, + range->rv_min, range->rv_max); +} + /* * The CPU ID never changes at run time, so we might as well tell the * compiler that it's constant. Use this function to read the CPU ID diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 1e87e1427cc3..a3675d279b90 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -26,10 +26,10 @@ static bool __maybe_unused is_affected_midr_range(const struct arm64_cpu_capabilities *entry, int scope) { + u32 midr = read_cpuid_id(); + WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); - return MIDR_IS_CPU_MODEL_RANGE(read_cpuid_id(), entry->midr_model, - entry->midr_range_min, - entry->midr_range_max); + return is_midr_in_range(midr, &entry->midr_range); } static bool __maybe_unused @@ -43,7 +43,7 @@ is_kryo_midr(const struct arm64_cpu_capabilities *entry, int scope) model &= MIDR_IMPLEMENTOR_MASK | (0xf00 << MIDR_PARTNUM_SHIFT) | MIDR_ARCHITECTURE_MASK; - return model == entry->midr_model; + return model == entry->midr_range.model; } static bool @@ -407,15 +407,11 @@ static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry, #define CAP_MIDR_RANGE(model, v_min, r_min, v_max, r_max) \ .matches = is_affected_midr_range, \ - .midr_model = model, \ - .midr_range_min = MIDR_CPU_VAR_REV(v_min, r_min), \ - .midr_range_max = MIDR_CPU_VAR_REV(v_max, r_max) + .midr_range = MIDR_RANGE(model, v_min, r_min, v_max, r_max) #define CAP_MIDR_ALL_VERSIONS(model) \ .matches = is_affected_midr_range, \ - .midr_model = model, \ - .midr_range_min = MIDR_CPU_VAR_REV(0, 0), \ - .midr_range_max = (MIDR_VARIANT_MASK | MIDR_REVISION_MASK) + .midr_range = MIDR_ALL_VERSIONS(model) #define MIDR_FIXED(rev, revidr_mask) \ .fixed_revs = (struct arm64_midr_revidr[]){{ (rev), (revidr_mask) }, {}} @@ -556,7 +552,7 @@ const struct arm64_cpu_capabilities arm64_errata[] = { .desc = "Qualcomm Technologies Kryo erratum 1003", .capability = ARM64_WORKAROUND_QCOM_FALKOR_E1003, .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, - .midr_model = MIDR_QCOM_KRYO, + .midr_range.model = MIDR_QCOM_KRYO, .matches = is_kryo_midr, }, #endif