From patchwork Tue Apr 3 11:09:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 132727 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp3666299ljb; Tue, 3 Apr 2018 04:10:29 -0700 (PDT) X-Google-Smtp-Source: AIpwx490mQicAKbj/4j7mQrsxtPgB9toA+2y5ow6VN+II9VKb1UV+Ksc1gzDPUefMw9ayew+64Wk X-Received: by 10.98.31.216 with SMTP id l85mr10270781pfj.80.1522753829652; Tue, 03 Apr 2018 04:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522753829; cv=none; d=google.com; s=arc-20160816; b=lNrmtOIj43+gR77QhUi2NNZUt5M+Yg1bcLG+uQsF58N2fzlh42PcFzwNLDwlsY1YXJ cPj3+wiRwKgEPqmEmhnjcx1jXWXqZIut8GyYlJ7rh+X9xJUYJL7v+cnlY3nKq5OCkkDj EYgx7IiiYouo3ftiE4GfD0zhuflycdtLOzMInFSFNHl1eOTl0SFjZDSyoMhikNZEttBf OokinCpwZqq9LP78jmYKPloMqCdiv9935OZw4q3C+f28g/KkIlTUTOYSRioCsNqnFn+J G5gvTAjKPfG2vdI6hUx0/1wp1B7lpLbgVtysSNIA0utWxbfhieAShwqI155BCso0rsxr XlQg== 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=XhA+PUYoAplAPvt5LqtysvruiGYelA0zrSokHSwRZYU=; b=t/A8iZ7jBO1vVD3lb/44BWD5uhTPjWACqm5TNbsSkzPOvpy0pFxZwEO2hmj/HS0Yb+ hgpbdDl/VvKA9r/4yYh3aXkFahaXLUyIeUhy9cQuVAl15hEpYwgNxnkmocctomabP0UZ WafWKxN0Sg7GZ2pCjtps9M7s5ItxvSCv9d2dwtJgr/SrT4ouL2L5dt8F4wVyQTnFMfEQ CDHFJxYWkxyU6FjE1dB2LDsfB1WmQuOGhWs2fwkFvafptiyuUzpCDfLDJnwmNfPXLFwy WT3dvwZd5jkRQ2dMLB+cyMSRcpwYwP7fAobZ72talp8L6oQKPXfSknPDuaGAWAYmwlZZ JpJQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l91-v6si306341plb.301.2018.04.03.04.10.29; Tue, 03 Apr 2018 04:10:29 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755312AbeDCLK1 (ORCPT + 11 others); Tue, 3 Apr 2018 07:10:27 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:59394 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755427AbeDCLKZ (ORCPT ); Tue, 3 Apr 2018 07:10:25 -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 B3FE41435; Tue, 3 Apr 2018 04:10:25 -0700 (PDT) Received: from lakrids.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 835503F587; Tue, 3 Apr 2018 04:10:24 -0700 (PDT) From: Mark Rutland To: stable@vger.kernel.org Cc: mark.brown@linaro.org, ard.biesheuvel@linaro.org, marc.zyngier@arm.com, will.deacon@arm.com Subject: [PATCH v4.9.y 20/27] arm64: capabilities: Handle duplicate entries for a capability Date: Tue, 3 Apr 2018 12:09:16 +0100 Message-Id: <20180403110923.43575-21-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180403110923.43575-1-mark.rutland@arm.com> References: <20180403110923.43575-1-mark.rutland@arm.com> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Suzuki K Poulose commit 67948af41f2e upstream. Sometimes a single capability could be listed multiple times with differing matches(), e.g, CPU errata for different MIDR versions. This breaks verify_local_cpu_feature() and this_cpu_has_cap() as we stop checking for a capability on a CPU with the first entry in the given table, which is not sufficient. Make sure we run the checks for all entries of the same capability. We do this by fixing __this_cpu_has_cap() to run through all the entries in the given table for a match and reuse it for verify_local_cpu_feature(). Cc: Mark Rutland Cc: Will Deacon Acked-by: Marc Zyngier Signed-off-by: Suzuki K Poulose Signed-off-by: Catalin Marinas Signed-off-by: Will Deacon Signed-off-by: Alex Shi [v4.9 backport] Signed-off-by: Mark Rutland [v4.9 backport] --- arch/arm64/kernel/cpufeature.c | 44 ++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 21 deletions(-) -- 2.11.0 diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 810f8bf7c57f..2d7c7796cce1 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -969,6 +969,26 @@ static void __init setup_elf_hwcaps(const struct arm64_cpu_capabilities *hwcaps) cap_set_elf_hwcap(hwcaps); } +/* + * Check if the current CPU has a given feature capability. + * Should be called from non-preemptible context. + */ +static bool __this_cpu_has_cap(const struct arm64_cpu_capabilities *cap_array, + unsigned int cap) +{ + const struct arm64_cpu_capabilities *caps; + + if (WARN_ON(preemptible())) + return false; + + for (caps = cap_array; caps->desc; caps++) + if (caps->capability == cap && + caps->matches && + caps->matches(caps, SCOPE_LOCAL_CPU)) + return true; + return false; +} + void update_cpu_capabilities(const struct arm64_cpu_capabilities *caps, const char *info) { @@ -1037,8 +1057,9 @@ verify_local_elf_hwcaps(const struct arm64_cpu_capabilities *caps) } static void -verify_local_cpu_features(const struct arm64_cpu_capabilities *caps) +verify_local_cpu_features(const struct arm64_cpu_capabilities *caps_list) { + const struct arm64_cpu_capabilities *caps = caps_list; for (; caps->matches; caps++) { if (!cpus_have_cap(caps->capability)) continue; @@ -1046,7 +1067,7 @@ verify_local_cpu_features(const struct arm64_cpu_capabilities *caps) * If the new CPU misses an advertised feature, we cannot proceed * further, park the cpu. */ - if (!caps->matches(caps, SCOPE_LOCAL_CPU)) { + if (!__this_cpu_has_cap(caps_list, caps->capability)) { pr_crit("CPU%d: missing feature: %s\n", smp_processor_id(), caps->desc); cpu_die_early(); @@ -1099,25 +1120,6 @@ static void __init setup_feature_capabilities(void) enable_cpu_capabilities(arm64_features); } -/* - * Check if the current CPU has a given feature capability. - * Should be called from non-preemptible context. - */ -static bool __this_cpu_has_cap(const struct arm64_cpu_capabilities *cap_array, - unsigned int cap) -{ - const struct arm64_cpu_capabilities *caps; - - if (WARN_ON(preemptible())) - return false; - - for (caps = cap_array; caps->desc; caps++) - if (caps->capability == cap && caps->matches) - return caps->matches(caps, SCOPE_LOCAL_CPU); - - return false; -} - extern const struct arm64_cpu_capabilities arm64_errata[]; bool this_cpu_has_cap(unsigned int cap)