Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp248584pxx; Wed, 28 Oct 2020 04:04:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7SgxyWlccOFJWzXY6XrvFjS2C9U1pu90LGRN8L6bhT+4053HkMvHEvj0yX2ChEBF9prf+ X-Received: by 2002:a05:6402:1bc9:: with SMTP id ch9mr7272503edb.386.1603883050020; Wed, 28 Oct 2020 04:04:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603883050; cv=none; d=google.com; s=arc-20160816; b=qix5fQmRn8wxtzftJ3gAB+hAIOeqqt8PeJSdi17tLyLnOke8aJdDMAMgJMOvlAGoU2 kmcBOvEhrq7sMvFPS87gTe/2fLK4vpAyNcGiA7MezyozMA2iIEoW0Oy2LXVjxozYqFei 5EYcWLDT2+Eu2YneGKihG5T9Eu5NZI6S+m1a357z7uzXdAe5zUOV8W02OY+0t9X8SMgu XOHENagBKFlT5WvUF3IpWKqlTNVBKgLfdrPYFviM3QH/xAuUytpVqKBJcxCMljPgbSZO QsbiJpe0uSkhTOamEQalo6AnBv8Cu4L3084bpUfkKLeIb+QdCkztdva6a8vlpygv43XJ ZaGQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UPTlcn9fpgILykk0GAykrLGHCerQx5ru9BjW1iTpAuY=; b=jyDR8eKooLgSJtBZVArDNR04+3McLiOv6l53XJ32oYdsKpYMwJfBrL0C089fPXF99k Ur1r23tj6a/8BK8irb3lSdoZTd8EkxZ8Aw6fe9rOk2yR3Fk0qqRD4YW0zDhPVcmjfFPk Mrwl578e9LjQAED6Jgx3cV5UaV+2Q7C9VkNXMSovTk9G3KhLv23IWa1gopYFHcZDhPZD TZr6Q6UlkHHSVtpkg9W7GO173qpaFm/C/gmh+IHaH1waTVppdXpC0xu5t5ZiKTOPEgcX HP7bXvh0OuT2rljFLuB0OwMQiOsEufTz8Vi8lpXW4f6oBIgueG2HdE0EVtgelm7wW0KL 6fRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qj3bDsD1; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bt10si1135660edb.503.2020.10.28.04.03.47; Wed, 28 Oct 2020 04:04:10 -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=@kernel.org header.s=default header.b=qj3bDsD1; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1784009AbgJ0O6s (ORCPT + 99 others); Tue, 27 Oct 2020 10:58:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:50780 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1773119AbgJ0Ov2 (ORCPT ); Tue, 27 Oct 2020 10:51:28 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 43A33206E5; Tue, 27 Oct 2020 14:51:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810285; bh=umgnazMM2+hsWUIgo63fu0bPJ5MrrCfaTwB0dvoL8jc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qj3bDsD1nposbD4rSfs05Y7VSC692A5DuqtSCNTcWZ00FT/3droRnEEr2yYRxuAth p1Ea8jIQku0khsc3JZJkc73kFlsleX4drQeLGRd+CNVwhTRVgtv0cI70a1nKZ7vUA9 7TppgEJLUQAD4FE7gXUl8PA7wG2KmiJx0Jx/yezc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arvind Sankar , Borislav Petkov , Sasha Levin Subject: [PATCH 5.8 086/633] x86/fpu: Allow multiple bits in clearcpuid= parameter Date: Tue, 27 Oct 2020 14:47:09 +0100 Message-Id: <20201027135526.724563114@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arvind Sankar [ Upstream commit 0a4bb5e5507a585532cc413125b921c8546fc39f ] Commit 0c2a3913d6f5 ("x86/fpu: Parse clearcpuid= as early XSAVE argument") changed clearcpuid parsing from __setup() to cmdline_find_option(). While the __setup() function would have been called for each clearcpuid= parameter on the command line, cmdline_find_option() will only return the last one, so the change effectively made it impossible to disable more than one bit. Allow a comma-separated list of bit numbers as the argument for clearcpuid to allow multiple bits to be disabled again. Log the bits being disabled for informational purposes. Also fix the check on the return value of cmdline_find_option(). It returns -1 when the option is not found, so testing as a boolean is incorrect. Fixes: 0c2a3913d6f5 ("x86/fpu: Parse clearcpuid= as early XSAVE argument") Signed-off-by: Arvind Sankar Signed-off-by: Borislav Petkov Link: https://lkml.kernel.org/r/20200907213919.2423441-1-nivedita@alum.mit.edu Signed-off-by: Sasha Levin --- .../admin-guide/kernel-parameters.txt | 2 +- arch/x86/kernel/fpu/init.c | 30 ++++++++++++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index fb95fad81c79a..6746f91ebc490 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -577,7 +577,7 @@ loops can be debugged more effectively on production systems. - clearcpuid=BITNUM [X86] + clearcpuid=BITNUM[,BITNUM...] [X86] Disable CPUID feature X for the kernel. See arch/x86/include/asm/cpufeatures.h for the valid bit numbers. Note the Linux specific bits are not necessarily diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c index 61ddc3a5e5c2b..f8ff895aaf7e1 100644 --- a/arch/x86/kernel/fpu/init.c +++ b/arch/x86/kernel/fpu/init.c @@ -243,9 +243,9 @@ static void __init fpu__init_system_ctx_switch(void) */ static void __init fpu__init_parse_early_param(void) { - char arg[32]; + char arg[128]; char *argptr = arg; - int bit; + int arglen, res, bit; #ifdef CONFIG_X86_32 if (cmdline_find_option_bool(boot_command_line, "no387")) @@ -268,12 +268,26 @@ static void __init fpu__init_parse_early_param(void) 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); + 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"); } /* -- 2.25.1