From patchwork Tue Aug 7 18:14:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mian Yousaf Kaukab X-Patchwork-Id: 10559067 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4B68B14E5 for ; Tue, 7 Aug 2018 18:15:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F00B2A762 for ; Tue, 7 Aug 2018 18:15:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 331232A7D0; Tue, 7 Aug 2018 18:15: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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham 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 D22EB2A762 for ; Tue, 7 Aug 2018 18:15:29 +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=IkGeBOZXdZv8Ocd1w2a4Zzz1/u6jHS+zOWJTuBRk+lk=; b=afqiXw7flmhXdvbKen3vUJ151b rmhx8lSNyrNU8koJsFEXBxF4hJ4oVs8I0HxpUI1QTooOBIPr4zIrS01LB8+EL/ggM6TsXMqw408Kn YF0pEtTMzjCgeace9yTKO72zZKGS24FWKZfeWm8y/zdHEajqvAr4eLnBcO+EWuKmHKV8NjcvF498Y uxjQLi4M4sYn6vIbg29gJNsLlaoSZ7HZYRTRrrmrZ8Qzll+DFUEIM7wCTWBiFUeYI3ebEBOggtu5m JmY6lc5ZMIf7VxQx+F7qv7FxOt72pjBAtgJVhGxmlyTYJsWU7gJ2mZXjdLW3l2Ay7ZurUVFdsEg5i a7cutxlg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fn6Vw-0006aB-Nv; Tue, 07 Aug 2018 18:15:24 +0000 Received: from mx2.suse.de ([195.135.220.15] helo=mx1.suse.de) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fn6Vm-00057c-Fw for linux-arm-kernel@lists.infradead.org; Tue, 07 Aug 2018 18:15:16 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A32F6ACD3; Tue, 7 Aug 2018 18:15:00 +0000 (UTC) From: Mian Yousaf Kaukab To: will.deacon@arm.com, marc.zyngier@arm.com Subject: [PATCH 1/6] arm64: kpti: move check for non-vulnerable CPUs to a function Date: Tue, 7 Aug 2018 20:14:14 +0200 Message-Id: <20180807181419.15690-2-ykaukab@suse.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180807181419.15690-1-ykaukab@suse.de> References: <20180807181419.15690-1-ykaukab@suse.de> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180807_111514_695524_D9C2A570 X-CRM114-Status: GOOD ( 12.97 ) 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: robert.richter@cavium.com, Mian Yousaf Kaukab , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, cwu@amperecomputing.com 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 Prepare to call it in generic cpu vulnerabilities support. Signed-off-by: Mian Yousaf Kaukab --- arch/arm64/include/asm/cpufeature.h | 16 ++++++++++++++++ arch/arm64/kernel/cpufeature.c | 9 +-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 1717ba1db35d..0b0b5b3e36ba 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -530,6 +530,22 @@ void arm64_set_ssbd_mitigation(bool state); static inline void arm64_set_ssbd_mitigation(bool state) {} #endif +static inline bool is_cpu_meltdown_safe(void) +{ + /* List of CPUs that are not vulnerable and don't need KPTI */ + static const struct midr_range kpti_safe_list[] = { + MIDR_ALL_VERSIONS(MIDR_CAVIUM_THUNDERX2), + MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN), + { /* sentinel */ } + }; + + /* Don't force KPTI for CPUs that are not vulnerable */ + if (is_midr_in_range_list(read_cpuid_id(), kpti_safe_list)) + return true; + + return false; +} + #endif /* __ASSEMBLY__ */ #endif diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index e238b7932096..6a94f8bce35a 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -865,12 +865,6 @@ static int __kpti_forced; /* 0: not forced, >0: forced on, <0: forced off */ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, int scope) { - /* List of CPUs that are not vulnerable and don't need KPTI */ - static const struct midr_range kpti_safe_list[] = { - MIDR_ALL_VERSIONS(MIDR_CAVIUM_THUNDERX2), - MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN), - { /* sentinel */ } - }; char const *str = "command line option"; /* @@ -894,8 +888,7 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) return true; - /* Don't force KPTI for CPUs that are not vulnerable */ - if (is_midr_in_range_list(read_cpuid_id(), kpti_safe_list)) + if (is_cpu_meltdown_safe()) return false; /* Defer to CPU feature registers */