Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp563346yba; Wed, 3 Apr 2019 14:31:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqz3hMiZepbbw5S4hu+qqwinEj15S/SMBBvH3jwiJgBOKllPrEU10+eF6uN+jlktHNVEE5Ua X-Received: by 2002:a63:28c:: with SMTP id 134mr2028144pgc.278.1554327071092; Wed, 03 Apr 2019 14:31:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554327071; cv=none; d=google.com; s=arc-20160816; b=gyVFuD7lUh8r3FUbuUKkne7nB880AkFAxOs37Bfl1HZQC3EzgxZSReTkwoZWuovcCC /NtTZO9deok5uIgNNDmsai7pRw++6+26v72CeyVANwjhwFv3cE423VBd5XQXe52/KhIH n5lOLfnANWy+qXL/vDaPtkqIoFlhrYp4aiYXSs37K3HjziAGeHDgg0m+Y6lhCrzN/jHs q8mWHt8SFJaBXe7E/rOIa0sdX3klcNAiPz5qkBUYntdm9L0MLXTijEAWjs91zFjQTJgJ lkM1bPj6NnXvJdgS/bw+P+FGNWnhCj2S0MmxcFCy8DNJwqWXYA2am2DoRIU7Idxkbm7+ b34w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=9cugXPfLPG69ZTlO4wt38d5qo1uXaEG47gg1MKtuclE=; b=cJFkd6kOW8xcRsFt1sucSzX+1bE78v6nLcLV2Upw5gtgCAKfQeDkO6d3n9Or3/uXkr +TIDAkCIm1y5AgbPsq2igZNnX8cVBjeDfbHKHDf0/54Bx4hx8fGetnsqS9cgA8XlG1oS X+Ax1+16hGiQ3sGXovpZHVfOkLV8oTsCUmkKeY7klybsV/Mna0Te354vzVBZqKRSJan4 O8Nr1wj38t4laBGS+vb9CHt729bLPMCHag3qMMvOZUU2yyu03KMFUPunqkMQSrZsMo3U 3dgORMVKb3nuUmga7lDIQV8wzmTxESiqqYGY9GGnCYqMNwinEMTjMJNgj8OwgbKNmscb oxrw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y184si14589440pgd.423.2019.04.03.14.30.56; Wed, 03 Apr 2019 14:31:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726640AbfDCVaT (ORCPT + 99 others); Wed, 3 Apr 2019 17:30:19 -0400 Received: from mga05.intel.com ([192.55.52.43]:37312 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726562AbfDCVaS (ORCPT ); Wed, 3 Apr 2019 17:30:18 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Apr 2019 14:30:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,306,1549958400"; d="scan'208";a="334754277" Received: from romley-ivt3.sc.intel.com ([172.25.110.60]) by fmsmga005.fm.intel.com with ESMTP; 03 Apr 2019 14:30:12 -0700 From: Fenghua Yu To: "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "H Peter Anvin" , "Dave Hansen" , "Paolo Bonzini" , "Ashok Raj" , "Peter Zijlstra" , "Kalle Valo" , "Xiaoyao Li " , "Michael Chan" , "Ravi V Shankar" Cc: "linux-kernel" , "x86" , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, kvm@vger.kernel.org, Fenghua Yu Subject: [PATCH v6 17/20] x86/clearcpuid: Support feature flag string in kernel option clearcpuid Date: Wed, 3 Apr 2019 14:22:03 -0700 Message-Id: <1554326526-172295-18-git-send-email-fenghua.yu@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1554326526-172295-1-git-send-email-fenghua.yu@intel.com> References: <1554326526-172295-1-git-send-email-fenghua.yu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The kernel option clearcpuid currently only takes feature bit which can be changed from kernel to kernel. Extend clearcpuid to use cap flag string, which is defined in x86_cap_flags[] and won't be changed from kernel to kernel. And user can easily get the cap flag string from /proc/cpuinfo. Signed-off-by: Fenghua Yu --- arch/x86/include/asm/cpufeature.h | 1 + arch/x86/kernel/cpu/cpuid-deps.c | 26 ++++++++++++++++++++++++++ arch/x86/kernel/fpu/init.c | 3 ++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h index 0e56ff7e4848..823c4ab82e12 100644 --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -133,6 +133,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; extern void setup_clear_cpu_cap(unsigned int bit); extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit); +bool find_cpu_cap(char *cap_flag, unsigned int *pfeature); #define setup_force_cpu_cap(bit) do { \ set_cpu_cap(&boot_cpu_data, bit); \ diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c index 3d633f67fbd7..1a71434f7b46 100644 --- a/arch/x86/kernel/cpu/cpuid-deps.c +++ b/arch/x86/kernel/cpu/cpuid-deps.c @@ -120,3 +120,29 @@ void setup_clear_cpu_cap(unsigned int feature) { do_clear_cpu_cap(NULL, feature); } + +/** + * find_cpu_cap - Given a cap flag string, find its corresponding feature bit. + * @cap_flag: cap flag string as defined in x86_cap_flags[] + * @pfeature: feature bit + * + * Return: true if the feature is found. false if not found + */ +bool find_cpu_cap(char *cap_flag, unsigned int *pfeature) +{ +#ifdef CONFIG_X86_FEATURE_NAMES + unsigned int feature; + + for (feature = 0; feature < NCAPINTS * 32; feature++) { + if (!x86_cap_flags[feature]) + continue; + + if (strcmp(cap_flag, x86_cap_flags[feature]) == 0) { + *pfeature = feature; + + return true; + } + } +#endif + return false; +} diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c index 88bbba7ee96a..99b895eea166 100644 --- a/arch/x86/kernel/fpu/init.c +++ b/arch/x86/kernel/fpu/init.c @@ -256,7 +256,8 @@ static void __init clear_cpuid(void) /* Chang command line range for next search. */ cmdline_size = option_pos - boot_command_line + 1; argptr = arg; - if (get_option(&argptr, &bit) && + /* cpu cap can be specified by either feature bit or string */ + if ((get_option(&argptr, &bit) || find_cpu_cap(arg, &bit)) && bit >= 0 && bit < NCAPINTS * 32) setup_clear_cpu_cap(bit); } -- 2.19.1