From patchwork Wed Feb 28 03:56:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 129905 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp569017lja; Tue, 27 Feb 2018 20:00:14 -0800 (PST) X-Google-Smtp-Source: AH8x226dzu5LYbbySciJuncty6P+q4SHM/MwUKUDMKaKSd2jGboch7beK8gwBH775yMW7Jd68yZ3 X-Received: by 10.99.122.74 with SMTP id j10mr12682059pgn.84.1519790414380; Tue, 27 Feb 2018 20:00:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519790414; cv=none; d=google.com; s=arc-20160816; b=FSw1V6Kjm6SiYX0qsUGbpbTHuTLGqvyHd3rCpiXco3j2PR4CBpDiJqLn6+CkOeosLC P9DmkqrDf+f5hH0aqlIv9/+IxI1Nnzx2HzOh5xbHIMhIDaet7nRrQ373TsYnIxIG0Hhh ucIBOQtPRR+0Nm+i4PAh2JyBFhQY/ajxoNhGZ03tgjCWqxzAr76g5E5jGaNbMOFJcEcd qyQ8oU5G7apVwjPXLLLaKJ4qhFVAABMPqu/xcYTHNtlJSw37h/TK9cuyLz79GCw9N6ao WiFkG+UppUWK16DpEBJbPS6ADp6LxJZo7UMjIEOu6dIIRkwNTvG0/4fkKCSaW55k+JPl KetA== 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:dkim-signature:arc-authentication-results; bh=dHNDx9kw7MHipWQb550NFtLt7C6FAMAdmYc8+9G2iPE=; b=vStegD/B8UEcea6n1Ns0GrYV/7y4KAox+McdzgAP9edqUB800TC3X9PfMUUZ17UXsk LkCMABpejCiRZCbmGG74NhQgD6cD9Cy46EUsUzADE1Qcnk+ndTqoZlUEtBmrhGlVE1pJ MCB19HBX5xJHTfKqZLQ1JRdnnPe5I0Nf/oa435GBEdVBWIMilodOJak+rsQDqbQT4ikP +p2zACYyFU6q9vmiFrCdrULZ8BxeQeQwucXW2aet1rYI2IGZKccNu+CnE2SiD1jETOaV poCaDp7ZDFlLpxK0aei4Gj4UxRSfG+ZRRmX35cpx9HlF8POeQ2hrsShZdeBEbfo4Huc2 joBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h1S8wsae; 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; 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 g17-v6si571790plo.357.2018.02.27.20.00.13; Tue, 27 Feb 2018 20:00:14 -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; dkim=pass header.i=@linaro.org header.s=google header.b=h1S8wsae; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752279AbeB1EAJ (ORCPT + 28 others); Tue, 27 Feb 2018 23:00:09 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:45776 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751863AbeB1EAG (ORCPT ); Tue, 27 Feb 2018 23:00:06 -0500 Received: by mail-pf0-f193.google.com with SMTP id j24so502509pff.12 for ; Tue, 27 Feb 2018 20:00:06 -0800 (PST) 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; bh=dHNDx9kw7MHipWQb550NFtLt7C6FAMAdmYc8+9G2iPE=; b=h1S8wsaeFW8IVTBk8hc4XBeJLTJLvX4Ytnhji056gbM5KuO2UNLGhSn3UIv6PgA9n5 XBiZVGac/aiTRO6P5b5r2zJnN7cQaAlGNs+a76axCx7c1c7jvv+09fHEAYhaWAkSRTBO 92pwR4bJ5C4ZoITsGUaRLvhnt6D9WjaTCdhvg= 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; bh=dHNDx9kw7MHipWQb550NFtLt7C6FAMAdmYc8+9G2iPE=; b=eqxFcJpPRSxxIiZ2k2UQUYnqxqpHv5k3iWX/68sChyoALcB8Gq7F+cjQlqzusP5zax kQJhTTMkxYE/quj57Z1RXGqqX0a78XoQQQxD0Nd3PuIdxflaCvgYtvHtmFVURD1KJI/j E7zzXtOyVE1ASD7/gmlWGYYjLkQO5u7EpgTHjbhvhMzLmcevvs4bWEaIXBQlwTgrbHyG U2fkHXvQNijDLD7e0bMLqu2O+N9DJ8Z3SfBeuUJ2eptsDTMbhCyEaelIKQlG19qVX1U/ gc9txf9Ocr0SRfiY4rQVnMvOP4Gw0zTyj8hjmnWuz/G9pMlw6QjN/2YXOmMeM3gtJncp t89g== X-Gm-Message-State: APf1xPCmMzWHBXJADu8r31HOoKaOWO+TXm1Khfgr+O9L2VM5Sg9YRM7L /ZxLolpHnpSZpaej2/AlfG0t3g== X-Received: by 10.98.23.136 with SMTP id 130mr16186438pfx.43.1519790405671; Tue, 27 Feb 2018 20:00:05 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id q17sm739911pgt.7.2018.02.27.19.59.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Feb 2018 20:00:05 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Suzuki K Poulose , Mark Rutland , Alex Shi Subject: [PATCH 21/29] arm64: capabilities: Handle duplicate entries for a capability Date: Wed, 28 Feb 2018 11:56:43 +0800 Message-Id: <1519790211-16582-22-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519790211-16582-1-git-send-email-alex.shi@linaro.org> References: <1519790211-16582-1-git-send-email-alex.shi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 Conflicts: arch/arm64/kernel/cpufeature.c --- arch/arm64/kernel/cpufeature.c | 44 ++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 21 deletions(-) -- 2.7.4 diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 4e5dff1..6200b81 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)