Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp909852imb; Fri, 1 Mar 2019 18:54:33 -0800 (PST) X-Google-Smtp-Source: APXvYqySIo4P+bqeXXXoHchtP+fNY/3yTGPYuzm9ROrUGkmERBY9vIx9WzfMdUaSV0dIXOUX/t3B X-Received: by 2002:a17:902:9a98:: with SMTP id w24mr8685772plp.247.1551495273805; Fri, 01 Mar 2019 18:54:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551495273; cv=none; d=google.com; s=arc-20160816; b=mDH0yk7NVhRdb01S1nwFGIoIbKhrNWR+5mKH7orZ5Et1P6Bx7t7HxIvaLACQiGVy1w nxApAobnkuIvZ8t1zZSBL9MNIJodOkHR2YnpRFFvRR41pxqwCSOoMt0fnSRwRoVUBJkj b6CubsAxeQdbuDm/Jl1gaeBVYw/qzw+/QcLUX1d+nd409HxHo7rBtwTB/9CSj7J4+nh8 lUvdA7DwRNLKFtr6gfVCwoi6r+JgnpVfwK2R19ODIckyha9BjiOxW9ysayLG2m4q5Xzn /bvvrml5wUmxL4gAs3AVl4PmQv7iV/ueiGAX/+utO2pFa5xHxVHQbjL1VcpQVdqwyPoV Z0Tg== 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=XYmcXIBnaWN/72kqpLy1GPdRF+X9Mfwd7PxAJA7uI/o=; b=ycXuLrFSe47daPm6sIsZQvCx2kVgfCLRfJWn4lTMYHcNtARLeSKYtzy6JsYvZGTMS0 zC54LRHUQna10DxKaO3mxIgyS1unSlCYTd955gyJyuzH2uebkpB7f1blJfRtBxWhZM92 1X2g0zQUACl+RSdgQus8c9pnzvRk9oDA2p9+JoKu5awurj/WPZJeTS6D/viTy+Lhr6KU 8vXwUjueJmSafKcb23QN/gjf6kzUQ5xnnyUmH3OMOBCYVscG7d3HLtPXgOpGFINbX9hE N0ZlFN4yKQDwenLq9q8fATdxQWaVFl62XVubMUrSROxMoD7igfcmAEZE9Ra00guXhglV rsKg== 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 x35si22313297pgk.107.2019.03.01.18.54.18; Fri, 01 Mar 2019 18:54:33 -0800 (PST) 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 S1728155AbfCBCxP (ORCPT + 99 others); Fri, 1 Mar 2019 21:53:15 -0500 Received: from mga04.intel.com ([192.55.52.120]:49764 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727828AbfCBCwb (ORCPT ); Fri, 1 Mar 2019 21:52:31 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Mar 2019 18:52:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,430,1544515200"; d="scan'208";a="148572613" Received: from romley-ivt3.sc.intel.com ([172.25.110.60]) by fmsmga004.fm.intel.com with ESMTP; 01 Mar 2019 18:52:28 -0800 From: Fenghua Yu To: "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "H Peter Anvin" , "Paolo Bonzini" , "Dave Hansen" , "Ashok Raj" , "Peter Zijlstra" , "Ravi V Shankar" , "Xiaoyao Li " Cc: "linux-kernel" , "x86" , kvm@vger.kernel.org, Fenghua Yu Subject: [PATCH v4 09/17] x86/clearcpuid: Support feature flag string in kernel option clearcpuid Date: Fri, 1 Mar 2019 18:45:03 -0800 Message-Id: <1551494711-213533-10-git-send-email-fenghua.yu@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1551494711-213533-1-git-send-email-fenghua.yu@intel.com> References: <1551494711-213533-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 ce95b8cbd229..6792088525e3 100644 --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -132,6 +132,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 5ba11ce99f92..b84b133d0ebd 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.7.4