Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2724036pxk; Sun, 20 Sep 2020 15:03:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzusi0zKEsKvIvgYNNNpShXy7Z1Ip3Oxq2oudIOa+APyUncWZMqJCpxpppmqBVpeYSJhZ6f X-Received: by 2002:a17:906:3088:: with SMTP id 8mr36608093ejv.487.1600639404176; Sun, 20 Sep 2020 15:03:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600639404; cv=none; d=google.com; s=arc-20160816; b=N0elISVcO5OEixJu8Jm8e/Wp3192Q/M7HUOvETJM7d0bKqWLi18pC+2JckarvGnfoI BglszUrxf4SUXzzwlGuZjP0V1Cb+Fyy+0j37z1HyVD+LkMZOid3A1l2UY6j70sA44MHV Iz2sixE29VRGDGa6zWqlypIT1OSxh6jUjHK2FICJlhM70uMAZ+MvK7PwK6jgWI4B8OUS V26UFwyP2Ow4C7Uu5qhO3ICGm0TEbJva72pUsc3jgLcvpfICb93gse7ykxUWsnRYuK9d yZv8p817ssWDM+YGzPy2oBvBnkcF60TJqo04yKQhPHqvDbmeRf5DJQdbrSehlKRdVMAG UcHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ByCgbjHBTs2y+vxW0oJawfxAdyumUhYVyPnCWrxz9bI=; b=hfoCL1l4dxgiEo2AgtDo3EuL0Yf5uVnYVhl95+udmsAhsJF06JuajsVTHjKDfCDC5l jdb3CYSIM220rFBWpfv8rHtWj20bBdmNodr1DYeKMjBxB2nRZcurBtqmS01a+gMAcRRP jr09N4QAuyE2FW+W0dE+637pDHcodjZlxM90NogSrqNrSzVcMjPxGygYqGrFnuc51JVc fbQk44zuMLXFRwc7BZP79YwR0KTrby4AprfPbc1QoEHX1TjA5hoKHR50zu7gs3wOuRng eb/YevGwGtw6RzEsNy0oZqpxF/7Ynab+AvFWwjYEEEIV1B1kYavwBZgTxJlV2WfAWTAP 5wVw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v21si7251548edl.133.2020.09.20.15.02.59; Sun, 20 Sep 2020 15:03:24 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726253AbgITWAz (ORCPT + 99 others); Sun, 20 Sep 2020 18:00:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726156AbgITWAz (ORCPT ); Sun, 20 Sep 2020 18:00:55 -0400 Received: from vuizook.err.no (vuizook.err.no [IPv6:2a02:20c8:2640::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA54AC061755 for ; Sun, 20 Sep 2020 15:00:54 -0700 (PDT) Received: from [2400:4160:1877:2b00:3dc4:3545:b496:6a29] (helo=glandium.org) by vuizook.err.no with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kK7O1-0005Fd-Kz; Sun, 20 Sep 2020 22:00:46 +0000 Received: from glandium by goemon.lan with local (Exim 4.92) (envelope-from ) id 1kK7Nv-0001xE-Ia; Mon, 21 Sep 2020 07:00:39 +0900 From: Mike Hommey To: Borislav Petkov Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Mike Hommey Subject: [PATCH v2] x86/boot: Handle fpu-related and clearcpuid command line arguments earlier Date: Mon, 21 Sep 2020 07:00:36 +0900 Message-Id: <20200920220036.7469-1-mh@glandium.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200920083626.GA7473@zn.tnic> References: <20200920083626.GA7473@zn.tnic> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: (score 2.2): No, score=2.2 required=5.0 tests=RDNS_NONE,SPF_FAIL,SPF_HELO_FAIL autolearn=disabled version=3.4.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/x86/kernel/cpu/common.c | 41 ++++++++++++++++++++++++++++++++++++ arch/x86/kernel/fpu/init.c | 41 ------------------------------------ 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index c5d6f17d9b9d..5e2e4d3621bd 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 @@ -1220,6 +1221,45 @@ static void detect_nopl(void) #endif } +/* + * We parse cpu parameters early because early_identify_cpu() is executed + * before parse_early_param(). + */ +static void __init cpu__init_parse_early_param(void) +{ + char arg[32]; + char *argptr = arg; + int 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); + + if (cmdline_find_option(boot_command_line, "clearcpuid", arg, + sizeof(arg)) && + get_option(&argptr, &bit) && + bit >= 0 && + bit < NCAPINTS * 32) + setup_clear_cpu_cap(bit); +} + /* * Do minimum CPU detection early. * Fields really needed: vendor, cpuid_level, family, model, mask, @@ -1255,6 +1295,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__init_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 61ddc3a5e5c2..701f196d7c68 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 @@ -237,52 +236,12 @@ static void __init fpu__init_system_ctx_switch(void) on_boot_cpu = 0; } -/* - * 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[32]; - char *argptr = arg; - int 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); - - if (cmdline_find_option(boot_command_line, "clearcpuid", arg, - sizeof(arg)) && - get_option(&argptr, &bit) && - bit >= 0 && - bit < NCAPINTS * 32) - setup_clear_cpu_cap(bit); -} - /* * 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); /* -- 2.28.0