From patchwork Tue Sep 19 09:53:07 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: 141989 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3511878vqi; Tue, 19 Sep 2023 09:19:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5CmSRLn9RY9o8Ddu3em+yR9TE2sahulOq1G2OtuCkooI1s7b08XjVc+YCKtlhhmAR2D8u X-Received: by 2002:a05:6a20:8e01:b0:13a:fa9e:787b with SMTP id y1-20020a056a208e0100b0013afa9e787bmr29077pzj.12.1695140356773; Tue, 19 Sep 2023 09:19:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695140356; cv=none; d=google.com; s=arc-20160816; b=pNIHAPiRtL8djDlSgboSJW3RJx4QbHHvZMBbtd28hCddpBPvulqnzQW0MJqbPbYdlM BpJtNsltN8woM3mAb9Ls/4ppa9QnrLnm5KVcIzEEmrAbET1LuRMF+BFXE8a8ffKLLuwU HxZmN6DKZguIvrrMZSLvXQhnxHvkdZ5F/oovvzvE9RtOCmmgHY3sxMBRdUj/Quadul/o rnbf8SnoXinj+2fmgs2mEcpmPbdnKFZFZbEZjeu6Mt+XqSIsUh3yLzjf0lM4nOis00+N glCXAMn6p8EeUdY0mxevJ6yz+x1gliTqi25YQdjD7TlXmvWrWGk2Octpg+0hEACg0PoC Ha/Q== 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=ZzgA9F8IwwfNo7xjrqDlG248CoeZfGOO7kNYjMLnXRo=; fh=XQzvgGFN0vdKiMIeZ4ZfxAoeXyv3DYgAQ8NDVRT2sT8=; b=nFyQ4HU7hhGmBNdCmF7kqgMnuC/UQK/HzAcHXTRY+XNicSJCoH5SEYrB9CVCLLeiZo 8TvjmboGeCYXTZ952Nii7oF8FdvUK0BAvLRF8bwHRBiB2b6hoM5zYCE/zX31kG1Cuq01 BAeCcaS+NCK2MI3WYtnskeEum2eTn3S/PN5Qe2ry0sVTS3L48kqPEJuJbp3pbzQpLz1s u88uBrLLHJ2ItmkI814StmjcK9zGMmVJYkwBR5yEr7Tsdv1J9POyT48yzOg9KYgLTgHo HR0ebz86W1vIPOOTzf4CXnMEWRoWh5CPkAXV9M7JRQzCp9a0EmCjMxSqck56vMWd5CPH ldKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=gBe2BZmr; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id w67-20020a636246000000b00565f617a486si9629743pgb.212.2023.09.19.09.19.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 09:19:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=gBe2BZmr; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 8D51480E8F9D; Tue, 19 Sep 2023 02:54:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231852AbjISJx3 (ORCPT + 26 others); Tue, 19 Sep 2023 05:53:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231792AbjISJxR (ORCPT ); Tue, 19 Sep 2023 05:53:17 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B8CD198; Tue, 19 Sep 2023 02:53:10 -0700 (PDT) Date: Tue, 19 Sep 2023 09:53:07 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695117188; 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=ZzgA9F8IwwfNo7xjrqDlG248CoeZfGOO7kNYjMLnXRo=; b=gBe2BZmrnTAitWIhmuAglpi7IW7t9ffhaA0E5GYV+C48R4VVB/idFanyMjI2qLGo5Oeg/7 V0EWH7d5ngj2d1oEo7ZXyk6s0CwQgMLYNUUlF4+XgN4XxhPL9ZVkpLs26qhtfRTMUvwRNM YHYWJz4Q3OTmrd/wwnl5PCGm5O2Kdp14mzX1fefGL2IOUUgMqeFwa+53CAJTUXCu8bFfCZ yS+3jKRoxQNOADJI6VITMHcVDUpdym9izlV905WcEVpQX4UcSulShl0voUqS7jGUOtc4/z EpTdvpsB77kB8BPIw8za0gVa+ciAU7qGDHQg5kdwPKEjFzso0LnxAubz9WKkzw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695117188; 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=ZzgA9F8IwwfNo7xjrqDlG248CoeZfGOO7kNYjMLnXRo=; b=XVRxcuYJX3i92obM/6IHAnWHTUrGLxoTppR9JbZwdMbITrKy4sZMeQEbA9qaszs6D+lxfy k6K0uUADD/8fbEDA== 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 , 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: <169511718771.27769.15019317036773813903.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.9 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 groat.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 (groat.vger.email [0.0.0.0]); Tue, 19 Sep 2023 02:54:46 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777114039682512637 X-GMAIL-MSGID: 1777483494964769024 The following commit has been merged into the x86/bugs branch of tip: Commit-ID: f75a0e70ed379019b209cdb591ffbfe2fbf4342f Gitweb: https://git.kernel.org/tip/f75a0e70ed379019b209cdb591ffbfe2fbf4342f Author: Jo Van Bulck AuthorDate: Sat, 19 Aug 2023 10:09:21 +02:00 Committer: Ingo Molnar CommitterDate: Tue, 19 Sep 2023 11:42:48 +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 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) { /*