Received: by 10.223.185.116 with SMTP id b49csp97926wrg; Thu, 15 Feb 2018 17:25:52 -0800 (PST) X-Google-Smtp-Source: AH8x227HvRhI7qc9y5rwI3D0f+c84s+kMcDccd5hfR1lPeEBSg0QXph3TB6IFB26+AR8wlCCQIsR X-Received: by 2002:a17:902:4a0c:: with SMTP id w12-v6mr4249632pld.17.1518744352834; Thu, 15 Feb 2018 17:25:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518744352; cv=none; d=google.com; s=arc-20160816; b=Rrcwy4f/K+Iqtv/8Lg9Fe2LDL6Y7GtmLwZ62r9NsGRPwmcEjr/KNYNOmek1Q8LBZDZ 54EQz1QnC3unZDW6aMY8DnWLG3HTuJsBD77CFNgOpsr0QFGGKTzVXYMUZczQyqDtGgeN skWhmgaToJSXDTCnh2Af6mps/se+1BNTbHCes3Gxs1VpoEoAHmTzsx8oM8J1fMOzsTLg YWGU9+7swL9uShWrMCPz6x5sEzPAUjj76Wv0AmSmdBxbMZNUr3EX8yZTzchJJIu5DAP9 ayOBsGoeL41vTSGaakED/ncNKsWEyd+X5ipBRoAaQYzST8QKTsXyh+zbK2syuQGndu67 xZXQ== 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=V/wfB22QHuq2mq9SPS5mNW1r2ZfgXiGBsIefq3xJFg8=; b=x5B4vLCxeu3DMHY+PESStCUizMmGn2zoVCK5fAbYibv0AHEH3oAn6vWqOIEXhq8U0f otpV6VPDrJUkBRU8oIyZsmIcpwsMAfUEoO6dIsfo2cCijFyCEy9+T9icu9FW83j3OgLQ R+AKoLzKzeGXlJ7w2a3aR275JYI5GeAxvi8PASQhSBSnPx+G4YZL8QB71DdMptjLNxbL um7YbBx1fACGI8gikGxXbSIC1HhXqgUo2f2a3w7hdOdbxsD3FIYrMhc+al7TBu4wOpmR vTWp7oS+5Dq28SpK6lY4m2qJiWHv/ApMf8VN9iVi3TJ7bM3j0hORnsOYHwOMhqy9Wl+J FUFg== 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 n61-v6si3560535plb.67.2018.02.15.17.25.31; Thu, 15 Feb 2018 17:25:52 -0800 (PST) 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 S1423701AbeBOPkS (ORCPT + 99 others); Thu, 15 Feb 2018 10:40:18 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:60042 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423276AbeBOPkP (ORCPT ); Thu, 15 Feb 2018 10:40:15 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0CE93114A; Thu, 15 Feb 2018 15:40:14 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Rutland , Will Deacon , Marc Zyngier , Suzuki K Poulose , Catalin Marinas Subject: [PATCH 4.15 037/202] [Variant 3/Meltdown] arm64: capabilities: Handle duplicate entries for a capability Date: Thu, 15 Feb 2018 16:15:37 +0100 Message-Id: <20180215151714.969419389@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151712.768794354@linuxfoundation.org> References: <20180215151712.768794354@linuxfoundation.org> User-Agent: quilt/0.65 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.15-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: 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 @@ -1118,6 +1118,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) { @@ -1181,8 +1201,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; @@ -1190,7 +1211,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(); @@ -1272,25 +1293,6 @@ static void __init mark_const_caps_ready static_branch_enable(&arm64_const_caps_ready); } -/* - * 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)