From patchwork Fri Oct 20 11:37:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 156021 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp990356vqb; Fri, 20 Oct 2023 04:37:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGxJwPDnwbzVJ5/GN2PAVaVcM+xkVRiUD1FwyimiR2nJejXt6k+QDSoE1Qo8HaTufgW6FKG X-Received: by 2002:a05:6a21:7882:b0:137:74f8:62ee with SMTP id bf2-20020a056a21788200b0013774f862eemr1832648pzc.18.1697801868367; Fri, 20 Oct 2023 04:37:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697801868; cv=none; d=google.com; s=arc-20160816; b=q5LW5Hpz3nYPk//3+NICv5U8Hcoo+nqh7vGSADEEBgH+wqwTo4UJLtENvr2HVURuKi RgpnbuFb4ewz53z0dJB/rchlr6zvzxQ4f2lz8zb5Dd8ybUYhZHM6tSeIfwOT9z5Fs2Z9 2Yr6K0DFs84se1hFnefS9JHkm5dIyIZw9XrhNK/VmUHiEWnueBaztXlermIf0wcVTLgq 7ZyURNO0rX+ftvdF7JgmVSMpj9abolTzI+s64X5l1w2lc9wapJqLLeTch8x+kx+xPyt7 DKVhnofDapaxfHrT4GkZ3Fkseg2LOKwRalrkLrx5a3JWzRw10reWWzTf83eon93F+gPH W3KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=UQGEIy1LdKfqt2kfVkFuk9/fT9Gj/V/gTHu5P6ProZw=; fh=+GNh9+sKZpV6fGVPaQ3XU6BzeZBenFYX+WxNlJABy1U=; b=IinrwTGlZ7Ayo4qYgyVhWlX06L5GW5J6IMSEc7lUbt1msL+sezOWLfSdEu0dyMfdzW PiAO84Mx+M2M1ByRNu4OzAg9IqjOJYAIyN2EdF4/gh5ZtMMSQ68IjSQ64PEGx/Ut3nLX JgK1jK0MCZYyCZYChmvP8X9KZbRPVbLlZPPAsicPWhkxP+76SfuGM3qzkDHf+t+TT2Zr OeBR2gct/kXHEiXVmJJhyp7tAMhAhCCkpkYtwyO+bVnEKA2mnaiwDj8VhiitgH0WsI+0 lQRweIKSwwQd5tgZE1udTh9VpG0fRVgPfWkwMrTcfcNH4OsFg2Fllbj2BdsNbSHP0+pJ ZEHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Yio8fp8t; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id bj11-20020a170902850b00b001c7264c458dsi1548223plb.181.2023.10.20.04.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 04:37:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Yio8fp8t; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 0AB0483F69AC; Fri, 20 Oct 2023 04:37:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377195AbjJTLh0 (ORCPT + 25 others); Fri, 20 Oct 2023 07:37:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377148AbjJTLhT (ORCPT ); Fri, 20 Oct 2023 07:37:19 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F03EBD49; Fri, 20 Oct 2023 04:37:17 -0700 (PDT) Date: Fri, 20 Oct 2023 11:37:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697801836; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UQGEIy1LdKfqt2kfVkFuk9/fT9Gj/V/gTHu5P6ProZw=; b=Yio8fp8trObEnrzlrfSAxf0FkSFTT4Qw5F8yq3UOr2Hs1tIr42ydenD0x0OsjQO9WVwryA OuSY35kgEBfPGUaqhjWOMvPVX6njrw0HWA65NNM4MDbxbnJCLlQ1eE5QqgCB+6+zpa0z0T RGQhXKzxGTmljWKCYodmOaCWpDZEseUwolO2TEbwotfumE5xlSvLRlimNly6dBayHbTISi GrdRTjZJn1BUDICurqJhVfNnRJDMKkk8eGfLzlCXK4vKzSdLjuRiSXtGv74P+5cj1WLZAM BwbBDX/Xg78oxrpyJafumpqJSBL6SDMGp3yXFaC9I3LcPdp2QiUmBmL77eOLOA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697801836; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UQGEIy1LdKfqt2kfVkFuk9/fT9Gj/V/gTHu5P6ProZw=; b=SIhM691drJFG6ssreCf387yGLG+5j6JtodnMaXQotsF6z/7B1nGmVYMEVCbvo0Rvbmq964 a7zU590SWrjm3MAw== From: "tip-bot2 for Jo Van Bulck" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/bugs] x86/pti: Fix kernel warnings for pti= and nopti cmdline options Cc: Jo Van Bulck , Ingo Molnar , "Borislav Petkov (AMD)" , Sohil Mehta , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230819080921.5324-2-jo.vanbulck@cs.kuleuven.be> References: <20230819080921.5324-2-jo.vanbulck@cs.kuleuven.be> MIME-Version: 1.0 Message-ID: <169780183596.3135.4427078331601256934.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 20 Oct 2023 04:37:43 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777114039682512637 X-GMAIL-MSGID: 1780274292330490749 The following commit has been merged into the x86/bugs branch of tip: Commit-ID: 0bd7feb2df7ef092c6b8914acca706fb21826f80 Gitweb: https://git.kernel.org/tip/0bd7feb2df7ef092c6b8914acca706fb21826f80 Author: Jo Van Bulck AuthorDate: Sat, 19 Aug 2023 10:09:21 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Fri, 20 Oct 2023 12:50:14 +02:00 x86/pti: Fix kernel warnings for pti= and nopti cmdline options Parse the pti= and nopti cmdline options using early_param to fix 'Unknown kernel command line parameters "nopti", will be passed to user space' warnings in the kernel log when nopti or pti= are passed to the kernel cmdline on x86 platforms. Additionally allow the kernel to warn for malformed pti= options. Signed-off-by: Jo Van Bulck Signed-off-by: Ingo Molnar Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Sohil Mehta Link: https://lore.kernel.org/r/20230819080921.5324-2-jo.vanbulck@cs.kuleuven.be --- arch/x86/mm/pti.c | 58 +++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c index 78414c6..5dd7339 100644 --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -69,6 +69,7 @@ static void __init pti_print_if_secure(const char *reason) pr_info("%s\n", reason); } +/* Assume mode is auto unless overridden via cmdline below. */ static enum pti_mode { PTI_AUTO = 0, PTI_FORCE_OFF, @@ -77,50 +78,49 @@ static enum pti_mode { void __init pti_check_boottime_disable(void) { - char arg[5]; - int ret; - - /* Assume mode is auto unless overridden. */ - pti_mode = PTI_AUTO; - if (hypervisor_is_type(X86_HYPER_XEN_PV)) { pti_mode = PTI_FORCE_OFF; pti_print_if_insecure("disabled on XEN PV."); return; } - ret = cmdline_find_option(boot_command_line, "pti", arg, sizeof(arg)); - if (ret > 0) { - if (ret == 3 && !strncmp(arg, "off", 3)) { - pti_mode = PTI_FORCE_OFF; - pti_print_if_insecure("disabled on command line."); - return; - } - if (ret == 2 && !strncmp(arg, "on", 2)) { - pti_mode = PTI_FORCE_ON; - pti_print_if_secure("force enabled on command line."); - goto enable; - } - if (ret == 4 && !strncmp(arg, "auto", 4)) { - pti_mode = PTI_AUTO; - goto autosel; - } - } - - if (cmdline_find_option_bool(boot_command_line, "nopti") || - cpu_mitigations_off()) { + if (cpu_mitigations_off()) pti_mode = PTI_FORCE_OFF; + if (pti_mode == PTI_FORCE_OFF) { pti_print_if_insecure("disabled on command line."); return; } -autosel: - if (!boot_cpu_has_bug(X86_BUG_CPU_MELTDOWN)) + if (pti_mode == PTI_FORCE_ON) + pti_print_if_secure("force enabled on command line."); + + if (pti_mode == PTI_AUTO && !boot_cpu_has_bug(X86_BUG_CPU_MELTDOWN)) return; -enable: + setup_force_cpu_cap(X86_FEATURE_PTI); } +static int __init pti_parse_cmdline(char *arg) +{ + if (!strcmp(arg, "off")) + pti_mode = PTI_FORCE_OFF; + else if (!strcmp(arg, "on")) + pti_mode = PTI_FORCE_ON; + else if (!strcmp(arg, "auto")) + pti_mode = PTI_AUTO; + else + return -EINVAL; + return 0; +} +early_param("pti", pti_parse_cmdline); + +static int __init pti_parse_cmdline_nopti(char *arg) +{ + pti_mode = PTI_FORCE_OFF; + return 0; +} +early_param("nopti", pti_parse_cmdline_nopti); + pgd_t __pti_set_user_pgtbl(pgd_t *pgdp, pgd_t pgd) { /*