From patchwork Thu May 24 19:09:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Langsdorf X-Patchwork-Id: 10425361 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 4232C602D8 for ; Thu, 24 May 2018 19:18:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A5CE295E9 for ; Thu, 24 May 2018 19:18:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F631295ED; Thu, 24 May 2018 19:18:53 +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 81DC9295F1 for ; Thu, 24 May 2018 19:18:52 +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:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yNUnFiVkeToXGZsEwZlya6UIX1Tb8a4ZqfZdXlcLy6E=; b=aWPT0qKId3lhT+ c4TyG2EwhI0bCU936wPaKk4nNQ1o1b5puEkTRJRmqhunPsphLLCwZ8G+BeIsHZCCNW0sRXeMeegjb M43j9O6KT/1Be1tHTS85I5IUdM1boSQGTnUcH2gXgE9XIECuDC1geDJNH10KpKjM3jbVNlc9jARBz ZyeDR6kcCQVuB7g4V0STa/OZk6Cjne1mb88+UP1gsC7aiM5wNheaCwtBJEc7zPSCNYUMpA77c6uCL eM0VcnGPaFFSBxQlDcLBjBw7iQptGzeDHMNHTspPvlxaTJm1R0jssVAnX0DiXqNwXf24/FYdH+7bC 8XEsV1yE222bFyT+M3MQ==; 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 1fLvl3-0001gi-42; Thu, 24 May 2018 19:18:41 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fLvkN-0000Vo-Vv for linux-arm-kernel@bombadil.infradead.org; Thu, 24 May 2018 19:17:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:To:From:Sender:Reply-To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Mq3WoGAtDxWTSIn1/3DV57gl8KTn4NAXfjIn0YPJI9c=; b=gDP3vhqrrbBOwq+FwmF1n15p7 YdTeEGYuuO1y7UZl2iuzrtDus92Y6uDscwY+JQ7kNs2YjmMDd4ULkryXoPp+nlWcotrBkBr0qPQRI gjYFP6obz12KTMIYWZ2z0EQIUlKKN4AOMS3zzZfyHjJZFYqO4hZE6DiwNHPbxcg66ASjWkIiq4xJk xR0u5cq8TUnjgCgqc5i0MI3qKL68c+NXvNQQYmgm6F3zELuvbEXd/eMr+R3OqgL0Va923UpyvNt3+ 1C65ye/T5Q14Y9wqhf9t1hWsxroMgnX/lL4pBM8CeuPMJeTjIsqY5I5QoQ5Kmml3MUaL8I5ylkKVc FjKVtB4bw==; Received: from mx1.redhat.com ([209.132.183.28]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fLvch-0001Hk-Cs for linux-arm-kernel@lists.infradead.org; Thu, 24 May 2018 19:10:05 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 35EDD30C39F1 for ; Thu, 24 May 2018 19:09:37 +0000 (UTC) Received: from redhatnow.redhat.com (ovpn-116-144.phx2.redhat.com [10.3.116.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAC0B67656 for ; Thu, 24 May 2018 19:09:36 +0000 (UTC) From: Mark Langsdorf To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 3/4] arm64: cpufeature: add debugfs interface for KPTI Date: Thu, 24 May 2018 14:09:31 -0500 Message-Id: <20180524190932.32118-4-mlangsdo@redhat.com> In-Reply-To: <20180524190932.32118-1-mlangsdo@redhat.com> References: <20180524190932.32118-1-mlangsdo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 24 May 2018 19:09:37 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180524_201003_569196_924E3858 X-CRM114-Status: GOOD ( 18.24 ) 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: , 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 Add a debugfs interface to check if KPTI is enabled or disabled: cat /sys/kernel/debug/arm64/pti_enabled Slightly rework unmap_kernel_at_el0 logic to simplify calculating if KPTI is enabled. Signed-off-by: Mark Langsdorf --- arch/arm64/kernel/cpufeature.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 7c5d8712..697a6ef 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -860,6 +861,7 @@ static bool has_cache_dic(const struct arm64_cpu_capabilities *entry, #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 static int __kpti_forced; /* 0: not forced, >0: forced on, <0: forced off */ +static bool __pti_enabled; static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, int scope) @@ -884,21 +886,21 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, /* Forced? */ if (__kpti_forced) { + __pti_enabled = __kpti_forced > 0; pr_info_once("kernel page table isolation forced %s by %s\n", - __kpti_forced > 0 ? "ON" : "OFF", str); - return __kpti_forced > 0; + __pti_enabled ? "ON" : "OFF", str); } - /* Useful for KASLR robustness */ - if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) - return true; - + else if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) + __pti_enabled = true; /* Don't force KPTI for CPUs that are not vulnerable */ - if (is_midr_in_range_list(read_cpuid_id(), kpti_safe_list)) - return false; - + else if (is_midr_in_range_list(read_cpuid_id(), kpti_safe_list)) + __pti_enabled = false; /* Defer to CPU feature registers */ - return !has_cpuid_feature(entry, scope); + else + __pti_enabled = !has_cpuid_feature(entry, scope); + + return __pti_enabled; } static void @@ -947,6 +949,14 @@ static int __init force_nokpti(char *arg) return 0; } early_param("nopti", force_nokpti); + +static int __init create_kpti_enabled(void) +{ + debugfs_create_bool("pti_enabled", S_IRUSR, + arch_debugfs_dir, &__pti_enabled); + return 0; +} +late_initcall(create_kpti_enabled); #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ #ifdef CONFIG_ARM64_HW_AFDBM