From patchwork Sat Sep 23 12:20:04 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: 143887 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp151811vqu; Sat, 23 Sep 2023 05:38:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGdODKH4fS3S4MTRJpx098ERM3OKsE4egNkcg0a/kGnjeYgGtN/5PsCteYzQvENcPO+FaTQ X-Received: by 2002:a17:90a:de0e:b0:26d:2158:10ac with SMTP id m14-20020a17090ade0e00b0026d215810acmr1516736pjv.14.1695472690008; Sat, 23 Sep 2023 05:38:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695472689; cv=none; d=google.com; s=arc-20160816; b=j5key/KpwMFdxlnyD90gGM2rvc5WQgpTLC6Y44fz/KHDYYamdPlIMKYfQ/hkgFnGEE Ejw9SWYKCpS1uHDiRvYx4D3YVDOtKk7Kd/SKSHbkMXnOLWkPfheuU+H625m61EKL+lYi 7i270YZXe38pw92KJlEXnczyh3GLJ7PEZSKVVOn5n4eOf63fWYS6E+aBYGqYkrzA2E3P MOaI0l6eyffmxKD8G+3Ox0fdmF4GZMZJw2Yr2X5VPdvnR8CP7xs7LWy6p8Dfe7mvsf5t 1PVzEFcKs2H25raoRY0Cih8wCnjTq0yNQ5Nk5Mg3gXCHYJmHYDfdCVC6yMqRLn4pDJGQ gc9w== 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=YaH82Qg0REdS/rhhkNFax1UzkciLIXMxnC2+Hqyy6PY=; fh=XQzvgGFN0vdKiMIeZ4ZfxAoeXyv3DYgAQ8NDVRT2sT8=; b=JJ/fUawSuomNrmK9P009zY9Q8/KoQurXpARd4/W9vQ6pzT7KTqie2mvjEAbGqxLZqO x/M8IpPXLpaBAkB7Mt+SEIbR0KO/12PXHidpKMyHE5f1vzEnWVFXr3pElAWAJkQasLoA YqGwIFAdJLquegh+kfHCqaOgNRtyrcvAChd3iaX4HY3RGuYBBO7fZV8cPfezHi/1w919 nwqTxq55x8sTtLNvM8ZG2j6bvz49V0DYt2ADxzb9+8ARh1HAqbIut5xWLQ+AlgGKE/gH iujV89f3n/mVIpQYq8XvDbf820KPzilmxxaL7n20BelCMKCosHPObEEcA9dlS86h4vbY 2IwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=VMKaaScB; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id t1-20020a17090aba8100b00268278c51e3si7859911pjr.49.2023.09.23.05.38.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 05:38:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=VMKaaScB; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 0A52883EC18A; Sat, 23 Sep 2023 05:20:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231666AbjIWMUY (ORCPT + 29 others); Sat, 23 Sep 2023 08:20:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231607AbjIWMUQ (ORCPT ); Sat, 23 Sep 2023 08:20:16 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6DA719F; Sat, 23 Sep 2023 05:20:08 -0700 (PDT) Date: Sat, 23 Sep 2023 12:20:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695471605; 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=YaH82Qg0REdS/rhhkNFax1UzkciLIXMxnC2+Hqyy6PY=; b=VMKaaScBFtXP0vV1h3Jz/Z7vdCJkXHbpeA501n8oxrDfYKYW/bHo0c/RwqTbrAhB7Jn6kU qjenwCfzYThssBm2Kc5zFRTgUtUY/M7icHWK6ns17oc7u4k7oU5e9RRVTlWWesCDaWdT0A Eoivh308YgWGVYnUgNv9SJqpxXcxa6WtyzWJ2b3Gdgmq1aOTxM6paVSb6PvFKQ1dJukx8B pIFEWYuLsAm3Z5XLAMtdlJd2qt1fagzfxcQWJFwBaj2/Ok5N9R5ZT+srZ2nMc8LWSCl5Kq sg+fI2r4e/RmhehyQnHyqDiBylG94e4wNhGDZMa9GatmrHW+g3qhMpYIy8cgVg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695471605; 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=YaH82Qg0REdS/rhhkNFax1UzkciLIXMxnC2+Hqyy6PY=; b=krEAHnwTw07aarUVT9jWjGLXO/PUCufUgEz4AJrmZAoXk7A3Wmkxaq1XXLsGpfKZ7Ocigm xx+XPN70tq3ggfAg== 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: <169547160485.27769.7181650143283871949.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Sat, 23 Sep 2023 05:20:36 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777114039682512637 X-GMAIL-MSGID: 1777831971434952437 The following commit has been merged into the x86/bugs branch of tip: Commit-ID: e2efc8e7d36a38e0a1f7724e74ff7c885963e7ca Gitweb: https://git.kernel.org/tip/e2efc8e7d36a38e0a1f7724e74ff7c885963e7ca Author: Jo Van Bulck AuthorDate: Sat, 19 Aug 2023 10:09:21 +02:00 Committer: Ingo Molnar CommitterDate: Sat, 23 Sep 2023 14:13:03 +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) { /*