From patchwork Wed Dec 16 04:42:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11976407 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3140C4361B for ; Wed, 16 Dec 2020 04:42:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8C50B23124 for ; Wed, 16 Dec 2020 04:42:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8C50B23124 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 212138D0002; Tue, 15 Dec 2020 23:42:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C2106B0070; Tue, 15 Dec 2020 23:42:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D8768D0002; Tue, 15 Dec 2020 23:42:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0169.hostedemail.com [216.40.44.169]) by kanga.kvack.org (Postfix) with ESMTP id EC4B56B006E for ; Tue, 15 Dec 2020 23:42:38 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A419A8249980 for ; Wed, 16 Dec 2020 04:42:38 +0000 (UTC) X-FDA: 77597899596.20.pull36_511102a27429 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 8418B180C07A3 for ; Wed, 16 Dec 2020 04:42:38 +0000 (UTC) X-HE-Tag: pull36_511102a27429 X-Filterd-Recvd-Size: 5367 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Dec 2020 04:42:37 +0000 (UTC) Date: Tue, 15 Dec 2020 20:42:36 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1608093757; bh=Iu7nGoAASVa0OLMEKHKmOarIpIf3q2k3cjkxq0RVYpU=; h=From:To:Subject:In-Reply-To:From; b=LIaBs/ViYi+gq/l5lQcmkjpbucQID/Rzyp4hU/awpXnfGbdCsov69iU2S6T6sAV2J xJ5/+2LPui3wLyKO8n3+OZRZCB29B2D2Qm05QHPkAjcM5vLsIQ0QJOuvkLLNZ7P6cO f9KrUD+DOc4lQFQBBzOyZmgWS/nsdg5xGR2Jx+Xc= From: Andrew Morton To: adobriyan@gmail.com, akpm@linux-foundation.org, amistry@google.com, asteinhauser@google.com, corbet@lwn.net, gladkov.alexey@gmail.com, keescook@chromium.org, linux-mm@kvack.org, mchehab+huawei@kernel.org, mhocko@suse.com, mm-commits@vger.kernel.org, neilb@suse.de, peterz@infradead.org, rppt@kernel.org, tglx@linutronix.de, torvalds@linux-foundation.org Subject: [patch 05/95] proc: provide details on indirect branch speculation Message-ID: <20201216044236.C5qdRtOt_%akpm@linux-foundation.org> In-Reply-To: <20201215204156.f05ec694b907845bcfab5c44@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Anand K Mistry Subject: proc: provide details on indirect branch speculation Similar to speculation store bypass, show information about the indirect branch speculation mode of a task in /proc/$pid/status. For testing/benchmarking, I needed to see whether IB (Indirect Branch) speculation (see Spectre-v2) is enabled on a task, to see whether an IBPB instruction should be executed on an address space switch. Unfortunately, this information isn't available anywhere else and currently the only way to get it is to hack the kernel to expose it (like this change). It also helped expose a bug with conditional IB speculation on certain CPUs. Another place this could be useful is to audit the system when using sanboxing. With this change, I can confirm that seccomp-enabled process have IB speculation force disabled as expected when the kernel command line parameter `spectre_v2_user=seccomp`. Since there's already a 'Speculation_Store_Bypass' field, I used that as precedent for adding this one. [amistry@google.com: remove underscores from field name to workaround documentation issue] Link: https://lkml.kernel.org/r/20201106131015.v2.1.I7782b0cedb705384a634cfd8898eb7523562da99@changeid Link: https://lkml.kernel.org/r/20201030172731.1.I7782b0cedb705384a634cfd8898eb7523562da99@changeid Signed-off-by: Anand K Mistry Cc: Anthony Steinhauser Cc: Thomas Gleixner Cc: Anand K Mistry Cc: Alexey Dobriyan Cc: Alexey Gladkov Cc: Jonathan Corbet Cc: Kees Cook Cc: Mauro Carvalho Chehab Cc: Michal Hocko Cc: Mike Rapoport Cc: NeilBrown Cc: Peter Zijlstra Signed-off-by: Andrew Morton --- Documentation/filesystems/proc.rst | 2 + fs/proc/array.c | 28 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) --- a/Documentation/filesystems/proc.rst~proc-provide-details-on-indirect-branch-speculation +++ a/Documentation/filesystems/proc.rst @@ -210,6 +210,7 @@ read the file /proc/PID/status:: NoNewPrivs: 0 Seccomp: 0 Speculation_Store_Bypass: thread vulnerable + SpeculationIndirectBranch: conditional enabled voluntary_ctxt_switches: 0 nonvoluntary_ctxt_switches: 1 @@ -292,6 +293,7 @@ It's slow but very precise. NoNewPrivs no_new_privs, like prctl(PR_GET_NO_NEW_PRIV, ...) Seccomp seccomp mode, like prctl(PR_GET_SECCOMP, ...) Speculation_Store_Bypass speculative store bypass mitigation status + SpeculationIndirectBranch indirect branch speculation mode Cpus_allowed mask of CPUs on which this process may run Cpus_allowed_list Same as previous, but in "list format" Mems_allowed mask of memory nodes allowed to this process --- a/fs/proc/array.c~proc-provide-details-on-indirect-branch-speculation +++ a/fs/proc/array.c @@ -369,6 +369,34 @@ static inline void task_seccomp(struct s seq_puts(m, "vulnerable"); break; } + + seq_puts(m, "\nSpeculationIndirectBranch:\t"); + switch (arch_prctl_spec_ctrl_get(p, PR_SPEC_INDIRECT_BRANCH)) { + case -EINVAL: + seq_puts(m, "unsupported"); + break; + case PR_SPEC_NOT_AFFECTED: + seq_puts(m, "not affected"); + break; + case PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE: + seq_puts(m, "conditional force disabled"); + break; + case PR_SPEC_PRCTL | PR_SPEC_DISABLE: + seq_puts(m, "conditional disabled"); + break; + case PR_SPEC_PRCTL | PR_SPEC_ENABLE: + seq_puts(m, "conditional enabled"); + break; + case PR_SPEC_ENABLE: + seq_puts(m, "always enabled"); + break; + case PR_SPEC_DISABLE: + seq_puts(m, "always disabled"); + break; + default: + seq_puts(m, "unknown"); + break; + } seq_putc(m, '\n'); }