Received: by 10.213.65.68 with SMTP id h4csp642419imn; Fri, 6 Apr 2018 06:38:45 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/ixNqkB2IwNC78Dzl7pKYdcnXpKd+2VFO+0u87hwp5RaXMYfn83zKuse+BFRDSIHDAZVr7 X-Received: by 10.98.144.205 with SMTP id q74mr20517317pfk.55.1523021925615; Fri, 06 Apr 2018 06:38:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523021925; cv=none; d=google.com; s=arc-20160816; b=r5yUD0VkAO/vj8kGYXPuM5nhHPVo/oKVrc7gOTfKn6zI6eP2ld/rP67mzywkn40O4I AgtNbp/1qGCBwDf/CvjGxOxB5TlZyRchOC3fLozLdsk5v6Dzwrvb0VSseivg1Zjxzcc4 C0iNEBTi8DES6JIFSEk4sKh5XQDbQupA7rVVYjEbq/UL5jNik3ZE/z/U+TV3q6M60NtV z3z4fL2Fmg1G046uTRYFzHCHIp0JbnMHtzLIVEL+XdNKVS7d2+QSz8YI6BmeVbxv9EM2 UG+U0A9TgQAt+ZjI45bC5viJrdt/8TiOP+zc2hQNv2CZQww2m0hO82dYe9Mh4/xBDucq fPCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=mDzLJi7GjLM7nUkyH2I3Lp9zn7ahVKjEG68ld7dwTMI=; b=R0hKaUcCuMdrXO5OoR7sLbXi+YnJou9m3D5+GHm3alzuESU4FE9ML/9llhVMvPjx5q kSUCV1DFRnEpHQXDn/CF497g7dVOp70nbRaotzvWdAcvN08NB6eFFkbJVsv8swFbyybd soAHADzEo7EdPPEdwt4aw3VL1SutyY24JwbkOhwsPIDsIVCtxTQFPTgjJO3ylo13x3Tj z5HW9MYhoZIycnR/7iQrX5xScbBp8Qt9BgtOMhK+UCG1BFY+szgVAMWqTWES6Rs8OejM 7rvbSXh1LGvEaTiTRl5v+Io3v1RttC/XMpYChzl9iUEWjzMHFjI5LDhcaqeBsPUm12Wg ANkA== 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 h190si7218152pge.13.2018.04.06.06.38.31; Fri, 06 Apr 2018 06:38:45 -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 S932225AbeDFNhQ (ORCPT + 99 others); Fri, 6 Apr 2018 09:37:16 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60582 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932194AbeDFNhM (ORCPT ); Fri, 6 Apr 2018 09:37:12 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 89F77BB6; Fri, 6 Apr 2018 13:36:58 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Mark Rutland , Will Deacon , Marc Zyngier , Suzuki K Poulose , Catalin Marinas , Greg Hackmann , Alex Shi Subject: [PATCH 4.9 069/102] arm64: capabilities: Handle duplicate entries for a capability Date: Fri, 6 Apr 2018 15:23:50 +0200 Message-Id: <20180406084341.167811426@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084331.507038179@linuxfoundation.org> References: <20180406084331.507038179@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ 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] Tested-by: Will Deacon Tested-by: Greg Hackmann Signed-off-by: Greg Kroah-Hartman --- arch/arm64/kernel/cpufeature.c | 44 +++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 21 deletions(-) --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -969,6 +969,26 @@ static void __init setup_elf_hwcaps(cons 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 arm } 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 a * 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_capabil 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)