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: 10246751 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BBD8660362 for ; Wed, 28 Feb 2018 04:07:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8D6A28976 for ; Wed, 28 Feb 2018 04:07:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 992DD289CE; Wed, 28 Feb 2018 04:07:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 17BCA28976 for ; Wed, 28 Feb 2018 04:07:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=5r9Fm0n6Dt0uhNbHRuGiV6BCEx87fRFsH47f7/sw4fc=; b=Mr4vJveSGuNTM1dhjztmdjL3b5 pd07GfL6MjN8xFBVDy0mXmxrKU5s49+MFgu2L4E88AdZ8j3kb1BF5aw1ktdljnfT9lAZRAC5A5V7b 6tHE3q1+s+hmptyTKSsh5uF6g1qVSKNXnlu4KIuRpE4jZTOU55nW2xJIKJnkPkbpjurWQiedvU06G 0ATYcbAmZXwb1t8/mLbNEavwl6XWv4/eALy9V25hKfFiiTFw8tGr66VEJtU4OmemlyFyVtqel+9i7 3+8MbDLoUks3DRSALw7yt4IZJQ9jjE4VAGEdDu3hqitIsiuVfd5dX7zHeNEljvvCe4Njcy8o1wi34 PyKPEc4w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eqt1R-00061p-6l; Wed, 28 Feb 2018 04:07:17 +0000 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqsuf-00086x-7m for linux-arm-kernel@lists.infradead.org; Wed, 28 Feb 2018 04:01:32 +0000 Received: by mail-pf0-x242.google.com with SMTP id f80so505657pfa.8 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=S8EJvzA3uJVu5fQqCPiROXERGWPZ0XeUdeG4ggldt5QthsjRAC1q0Jyj4Xz6JCumCP /438XPUdaFWqvflM4rI8eE0YlQix0RsqdlMprpeJNtNCaTtWF/6fxo9PpDWSN721AINA MeKFVI6EWNDqL3eO9ocsikYBZcJyEhhENVeFhCrSoXdbv4X7lpedL43FcHZ0EpEUzSLF U2x2ApC58r4RdgilRY+6LV5w9raWJK6fYN5D6AcJjb/mCZEn256HrdJUIuui68MKtVKP gb+HHvh6K5di7b1UtifGKoZRwM/RMKyjXgaxlG60sreoZCaF6wg9hrZxeV3m4X8ObMTd 8dvg== X-Gm-Message-State: APf1xPDezySau/O3zOvTVYN78owNVIvxkYD7cQHcNBdUIAP70F4MnHOt Ot8M/gsoK2nQFZLIQNhIZsNaoRVXMMc= X-Google-Smtp-Source: AH8x226R0HDxtLi6JPqOw4eV1yPJLsUE4g6zFxXsD/R3h/pydHsMcCt/VdIIVLsfOfGvZa+73NoV9g== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180227_200018_220867_56997F3E X-CRM114-Status: GOOD ( 17.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Alex Shi , Suzuki K Poulose MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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)