Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3785581pxk; Tue, 22 Sep 2020 02:27:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhY18TDyiEwcke3f4Ve/KO+I4Oewbi/ds9d8JagHjGjHlfDuGL1cP7vI3pqfuFSvJD/e8t X-Received: by 2002:a17:906:aac7:: with SMTP id kt7mr3843208ejb.548.1600766851615; Tue, 22 Sep 2020 02:27:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600766851; cv=none; d=google.com; s=arc-20160816; b=lqQxY41DytqowNG2orVf3ROXBlHlhtA64a1xtBsy+AYOge8F+EN4X1o+xlJrrEv81b zSqibLRihkBtfACWVGdNHLSR/YZpZplw6m4dLJCfFEK9eSKI3dRqC89IIxFYSSK8Q2Xe SuLuIGkM20rF741x49+WEAomhMSAW/CiTSWGsz/Ya1pq0GHt/HQdtXY+X29IuyGEDiRi UzDZJAFleBuGKj3gziJWiw4OOARY3gDJlL/GKXeVwpugp40057zjHrbxpArfO5UMzarh EqqTx6BnxWO8i7zbbe6O/tkkGTziw1DdPetwNiZG2FHN7nfL36n6m11ZgaN4of5kPu/B UCDw== 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=ixjuw1XFDPLcizWawh34SFjvcPywEDOscfH4W7tXDl8=; b=vVO8WlTYJ5BgiDA/j4Monx9YuI/QFsAU8bdwZcWsoyt6qeX9UtJMCXnTkkgkklbdGm 8q/MLtZJNR4RKdlZfp452XsflYVTLCHnjADy9LwU2u8V9vRO/ZNLXtD5BsMTv7X3fEP+ jyB5tPSogpJTa00vnmtUgLRv48L+KmZdaDQZ9nEEs1q2Azt96PztBWHNl62p6msBcBEj seZgwr5go4KtyOobh0BXCZm0k/DiqsJex8bJoL+qjjgpgpVvGm2iV7mjvTUs+OnK0wxV ry8TK4pRprZIM6ufwCLUWMyh1rEYPhtgRvQvJ9yBp6RRd7Kg96zpBJ/ZDQciufyznw7p GQvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=BeZg3vpc; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z23si10083962edx.215.2020.09.22.02.27.06; Tue, 22 Sep 2020 02:27:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=BeZg3vpc; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726545AbgIVJZ6 (ORCPT + 99 others); Tue, 22 Sep 2020 05:25:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726424AbgIVJZ5 (ORCPT ); Tue, 22 Sep 2020 05:25:57 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AA8FC061755; Tue, 22 Sep 2020 02:25:57 -0700 (PDT) Date: Tue, 22 Sep 2020 09:25:54 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1600766755; 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=ixjuw1XFDPLcizWawh34SFjvcPywEDOscfH4W7tXDl8=; b=BeZg3vpch3xrhWaIeoQ425qBfQSaOQLJpqARWSh9DEHK3f6tSYgMrS4ccQUOxx3Rr2nBTN oG8G1lrx9xcUB8FP9Hdy1YB4Lfalr9lgOpLkxq1vgMEfHREtjTbojDDX3gGMXzewukB89a zdRTj8YrzOlmIPAkDw2M0z/eNk8P3K2acqxoBGVMZhUppY1xEFVbbW8kn94YXpssKPcrir +iCOGZv2WSscCICyt3EP+oDidW8O9S+htuIS0URng07q1KaOJlP9XF5/rJh705eg4KFDZV 9iFc2MHNnMRPKZ72a2XG6As8YSkemCGH/mMrvIIklXtOYHYuxhpY/kYN1A1DtQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1600766755; 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=ixjuw1XFDPLcizWawh34SFjvcPywEDOscfH4W7tXDl8=; b=c/IXmH15Gs5DFJ1tLHnFyAD0keVSzXKdcgvV2smvuL3jgw+dqCJO02kAmy6GKCb4fknQWJ 4aFj0lZ8FyfJpVDw== From: "tip-bot2 for Mike Hommey" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/fpu] x86/fpu: Handle FPU-related and clearcpuid command line arguments earlier Cc: Mike Hommey , Borislav Petkov , x86 , LKML In-Reply-To: <20200921215638.37980-1-mh@glandium.org> References: <20200921215638.37980-1-mh@glandium.org> MIME-Version: 1.0 Message-ID: <160076675453.15536.12823133077636708676.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/fpu branch of tip: Commit-ID: 1ef5423a55c2ac6f1361811efe75b6e46d1023ed Gitweb: https://git.kernel.org/tip/1ef5423a55c2ac6f1361811efe75b6e46d1023ed Author: Mike Hommey AuthorDate: Tue, 22 Sep 2020 06:56:38 +09:00 Committer: Borislav Petkov CommitterDate: Tue, 22 Sep 2020 00:24:27 +02:00 x86/fpu: Handle FPU-related and clearcpuid command line arguments earlier FPU initialization handles them currently. However, in the case of clearcpuid=, some other early initialization code may check for features before the FPU initialization code is called. Handling the argument earlier allows the command line to influence those early initializations. Signed-off-by: Mike Hommey Signed-off-by: Borislav Petkov Link: https://lkml.kernel.org/r/20200921215638.37980-1-mh@glandium.org --- arch/x86/kernel/cpu/common.c | 55 +++++++++++++++++++++++++++++++++++- arch/x86/kernel/fpu/init.c | 55 +----------------------------------- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index c5d6f17..3c75193 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -1221,6 +1222,59 @@ static void detect_nopl(void) } /* + * We parse cpu parameters early because fpu__init_system() is executed + * before parse_early_param(). + */ +static void __init cpu_parse_early_param(void) +{ + char arg[128]; + char *argptr = arg; + int arglen, res, bit; + +#ifdef CONFIG_X86_32 + if (cmdline_find_option_bool(boot_command_line, "no387")) +#ifdef CONFIG_MATH_EMULATION + setup_clear_cpu_cap(X86_FEATURE_FPU); +#else + pr_err("Option 'no387' required CONFIG_MATH_EMULATION enabled.\n"); +#endif + + if (cmdline_find_option_bool(boot_command_line, "nofxsr")) + setup_clear_cpu_cap(X86_FEATURE_FXSR); +#endif + + if (cmdline_find_option_bool(boot_command_line, "noxsave")) + setup_clear_cpu_cap(X86_FEATURE_XSAVE); + + if (cmdline_find_option_bool(boot_command_line, "noxsaveopt")) + setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT); + + if (cmdline_find_option_bool(boot_command_line, "noxsaves")) + setup_clear_cpu_cap(X86_FEATURE_XSAVES); + + arglen = cmdline_find_option(boot_command_line, "clearcpuid", arg, sizeof(arg)); + if (arglen <= 0) + return; + + pr_info("Clearing CPUID bits:"); + do { + res = get_option(&argptr, &bit); + if (res == 0 || res == 3) + break; + + /* If the argument was too long, the last bit may be cut off */ + if (res == 1 && arglen >= sizeof(arg)) + break; + + if (bit >= 0 && bit < NCAPINTS * 32) { + pr_cont(" " X86_CAP_FMT, x86_cap_flag(bit)); + setup_clear_cpu_cap(bit); + } + } while (res == 2); + pr_cont("\n"); +} + +/* * Do minimum CPU detection early. * Fields really needed: vendor, cpuid_level, family, model, mask, * cache alignment. @@ -1255,6 +1309,7 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c) get_cpu_cap(c); get_cpu_address_sizes(c); setup_force_cpu_cap(X86_FEATURE_CPUID); + cpu_parse_early_param(); if (this_cpu->c_early_init) this_cpu->c_early_init(c); diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c index f8ff895..701f196 100644 --- a/arch/x86/kernel/fpu/init.c +++ b/arch/x86/kernel/fpu/init.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include @@ -238,65 +237,11 @@ static void __init fpu__init_system_ctx_switch(void) } /* - * We parse fpu parameters early because fpu__init_system() is executed - * before parse_early_param(). - */ -static void __init fpu__init_parse_early_param(void) -{ - char arg[128]; - char *argptr = arg; - int arglen, res, bit; - -#ifdef CONFIG_X86_32 - if (cmdline_find_option_bool(boot_command_line, "no387")) -#ifdef CONFIG_MATH_EMULATION - setup_clear_cpu_cap(X86_FEATURE_FPU); -#else - pr_err("Option 'no387' required CONFIG_MATH_EMULATION enabled.\n"); -#endif - - if (cmdline_find_option_bool(boot_command_line, "nofxsr")) - setup_clear_cpu_cap(X86_FEATURE_FXSR); -#endif - - if (cmdline_find_option_bool(boot_command_line, "noxsave")) - setup_clear_cpu_cap(X86_FEATURE_XSAVE); - - if (cmdline_find_option_bool(boot_command_line, "noxsaveopt")) - setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT); - - if (cmdline_find_option_bool(boot_command_line, "noxsaves")) - setup_clear_cpu_cap(X86_FEATURE_XSAVES); - - arglen = cmdline_find_option(boot_command_line, "clearcpuid", arg, sizeof(arg)); - if (arglen <= 0) - return; - - pr_info("Clearing CPUID bits:"); - do { - res = get_option(&argptr, &bit); - if (res == 0 || res == 3) - break; - - /* If the argument was too long, the last bit may be cut off */ - if (res == 1 && arglen >= sizeof(arg)) - break; - - if (bit >= 0 && bit < NCAPINTS * 32) { - pr_cont(" " X86_CAP_FMT, x86_cap_flag(bit)); - setup_clear_cpu_cap(bit); - } - } while (res == 2); - pr_cont("\n"); -} - -/* * Called on the boot CPU once per system bootup, to set up the initial * FPU state that is later cloned into all processes: */ void __init fpu__init_system(struct cpuinfo_x86 *c) { - fpu__init_parse_early_param(); fpu__init_system_early_generic(c); /*