From patchwork Wed Apr 17 21:34:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fenghua Yu X-Patchwork-Id: 10906151 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3D2C51390 for ; Wed, 17 Apr 2019 21:42:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26CDA28BA8 for ; Wed, 17 Apr 2019 21:42:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17B5A28BAA; Wed, 17 Apr 2019 21:42:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B443828BA8 for ; Wed, 17 Apr 2019 21:42:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387666AbfDQVmd (ORCPT ); Wed, 17 Apr 2019 17:42:33 -0400 Received: from mga12.intel.com ([192.55.52.136]:20176 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387647AbfDQVmb (ORCPT ); Wed, 17 Apr 2019 17:42:31 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Apr 2019 14:42:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,363,1549958400"; d="scan'208";a="224441220" Received: from romley-ivt3.sc.intel.com ([172.25.110.60]) by orsmga001.jf.intel.com with ESMTP; 17 Apr 2019 14:42:30 -0700 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 " , "Christopherson Sean J" , "Kalle Valo" , "Michael Chan" Cc: "linux-kernel" , "x86" , kvm@vger.kernel.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, Fenghua Yu Subject: [PATCH v7 19/21] x86/clearcpuid: Apply cleared feature bits that are forced set before Date: Wed, 17 Apr 2019 14:34:09 -0700 Message-Id: <1555536851-17462-20-git-send-email-fenghua.yu@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1555536851-17462-1-git-send-email-fenghua.yu@intel.com> References: <1555536851-17462-1-git-send-email-fenghua.yu@intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some CPU feature bits are forced set and stored in cpuinfo_x86 before handling clearcpuid options. To clear those bits from cpuinfo_x86, apply_forced_cap() is called after handling the options. Please note, apply_forced_cap() is called twice on boot CPU. But this code is simple and there is no functionality issue. Signed-off-by: Fenghua Yu --- arch/x86/include/asm/cpu.h | 2 ++ arch/x86/kernel/cpu/common.c | 5 +++-- arch/x86/kernel/fpu/init.c | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h index cd7493f20234..261e8ff3e2fb 100644 --- a/arch/x86/include/asm/cpu.h +++ b/arch/x86/include/asm/cpu.h @@ -26,6 +26,8 @@ struct x86_cpu { struct cpu cpu; }; +void apply_forced_caps(struct cpuinfo_x86 *c); + #ifdef CONFIG_HOTPLUG_CPU extern int arch_register_cpu(int num); extern void arch_unregister_cpu(int); diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index bbdd69dd4f5f..e1d41405c27b 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -758,13 +758,14 @@ void cpu_detect(struct cpuinfo_x86 *c) } } -static void apply_forced_caps(struct cpuinfo_x86 *c) +void apply_forced_caps(struct cpuinfo_x86 *c) { int i; for (i = 0; i < NCAPINTS + NBUGINTS; i++) { - c->x86_capability[i] &= ~cpu_caps_cleared[i]; + /* Bits may be cleared after they are set. */ c->x86_capability[i] |= cpu_caps_set[i]; + c->x86_capability[i] &= ~cpu_caps_cleared[i]; } } diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c index 99b895eea166..9c2801b605e3 100644 --- a/arch/x86/kernel/fpu/init.c +++ b/arch/x86/kernel/fpu/init.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -261,6 +262,7 @@ static void __init clear_cpuid(void) bit >= 0 && bit < NCAPINTS * 32) setup_clear_cpu_cap(bit); } + apply_forced_caps(&boot_cpu_data); } /*