Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp537036pxx; Wed, 28 Oct 2020 10:33:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypb4K9/+y7VwIokcBOsUoBu344Mit/E5ylPNXVb1aH4tbW5HfybdooCpQggPXVhf0cwvpM X-Received: by 2002:a17:906:7157:: with SMTP id z23mr163382ejj.474.1603906393925; Wed, 28 Oct 2020 10:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603906393; cv=none; d=google.com; s=arc-20160816; b=wVv4PpdsqYXNDa7ilBTKsnp2ruNvXSu9t89RfTUCxMVIILvAQ7wf8VRPMXw1Lv7pQc 5IbgxRnVqq87IYJSfv1AYi+pgwiCGb771eO0l43F32ifbNRrvuCzQI3yuKeE0ITnyOeK BSqGhiZEsv9UkS4PWsIXQZvRSLn7WpEKd6F69pPF7DJp8ODk3hPqUQsCUqYY/OVU0cZA j+FjiJUdwyX5WX2Bo38UfRSUPQWn9tRTRKdd72+g/jdGrBFw50XgcxrW9GiPmVFFOykq wmusYJxkMmcjIhb1QdDWmHWLdTdvx/Yl4w2TJiZbjAvGeh6gBYhhDyay3rYjvC8/Gc5Y EmOg== 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=hrdPUQBpDouecbNKMOhxA9X5yAUtLdAAXtCR24YqG9s=; b=z5d20Svwvm/mM9aZ7Gp+h5CnZpDgwShsicZ2Lq7lhnl4xIAQVuDMMjFijQjX9iqVnT nXlBT+7OUeNVUrGfrqJC3ffH8w4bYt3GdclVay4RwyZ1QgDCv6hlCCEjrKacva5YOuNO Xy4rsJlJEHHZ08BGZYeQ1Y/czZgyGOS8pOQwny3OB+hnd5jWqjrXBagtMyqG46VyGyxo OYoY3EWfTgNBxgswFwR5BhYrlCuBEb4zJtbPeqa+dMu032jI6pTcPysnxa/1ftE6fzaB 8ThQRRgGEMh8L65kGfciajpW6cnfaASfjASSQCHcTraFMINoxlZ2TC4DxkazmFV1nKPw cQcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="TLZVt/3u"; 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 bs17si4061011ejb.543.2020.10.28.10.32.51; Wed, 28 Oct 2020 10:33:13 -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="TLZVt/3u"; 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 S1822063AbgJ0Rql (ORCPT + 99 others); Tue, 27 Oct 2020 13:46:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:57522 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760021AbgJ0Oay (ORCPT ); Tue, 27 Oct 2020 10:30:54 -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 A9A302222C; Tue, 27 Oct 2020 14:30:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809053; bh=I/zpd2i9fGwREVNiiOAouNMgkF6wahOZPbtJExvZbeA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TLZVt/3uYRWW9bvYZuLmV4qDCxuXqe2IQPcFhNtOsbu12rk+LxMW7oamW6G9ENyxQ c5s7A+BFlxX2C7n0z+Bq/cQ8Wsvr96MiYtm6/rz2oM4sjxox5SVsin8ZDkbmYV6tSD aN5+8Z79uaJ+zPow++CdVtbnYoabia+Aij86mEHU= 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.4 059/408] x86/fpu: Allow multiple bits in clearcpuid= parameter Date: Tue, 27 Oct 2020 14:49:57 +0100 Message-Id: <20201027135457.800435993@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@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 13984b6cc3225..988a0d2535b25 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -567,7 +567,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 6ce7e0a23268f..b271da0fa2193 100644 --- a/arch/x86/kernel/fpu/init.c +++ b/arch/x86/kernel/fpu/init.c @@ -242,9 +242,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")) @@ -267,12 +267,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