From patchwork Sat Oct 6 00:19:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 10629045 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 C4A7B15A6 for ; Sat, 6 Oct 2018 00:19:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A56C62989E for ; Sat, 6 Oct 2018 00:19:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8256B298A1; Sat, 6 Oct 2018 00:19:55 +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 8E4D02989E for ; Sat, 6 Oct 2018 00:19:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728088AbeJFHUj (ORCPT ); Sat, 6 Oct 2018 03:20:39 -0400 Received: from mga06.intel.com ([134.134.136.31]:24702 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726505AbeJFHUi (ORCPT ); Sat, 6 Oct 2018 03:20:38 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Oct 2018 17:19:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,346,1534834800"; d="scan'208";a="75803273" Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.7.201.126]) by fmsmga007.fm.intel.com with ESMTP; 05 Oct 2018 17:19:31 -0700 Received: by tassilo.localdomain (Postfix, from userid 1000) id C0C7C301B97; Fri, 5 Oct 2018 17:19:31 -0700 (PDT) From: Andi Kleen To: peterz@infradead.org Cc: x86@kernel.org, linux-kernel@vger.kernel.org, eranian@google.com, kan.liang@intel.com, isaku.yamahata@intel.com, kvm@vger.kernel.org, Andi Kleen Subject: [PATCH v1 1/2] x86/cpufeature: Add facility to match microcode revisions Date: Fri, 5 Oct 2018 17:19:27 -0700 Message-Id: <20181006001928.28097-1-andi@firstfloor.org> X-Mailer: git-send-email 2.17.1 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Andi Kleen For bug workarounds or checks it is useful to check for specific microcode versions. Add a new table format to check for steppings with min/max microcode revisions. This does not change the existing x86_cpu_id because it's an ABI shared with modutils, and also has quite difference requirements, as in no wildcards, but everything has to be matched exactly. Signed-off-by: Andi Kleen --- arch/x86/include/asm/cpu_device_id.h | 22 ++++++++++++++ arch/x86/kernel/cpu/match.c | 43 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/arch/x86/include/asm/cpu_device_id.h b/arch/x86/include/asm/cpu_device_id.h index baeba0567126..bf2222d5438c 100644 --- a/arch/x86/include/asm/cpu_device_id.h +++ b/arch/x86/include/asm/cpu_device_id.h @@ -11,4 +11,26 @@ extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match); +/* + * Match specific microcodes or steppings. + * + * vendor/family/model/stepping must be all set. + * min_ucode/max_ucode/driver_data are optional and can be 0. + */ + +struct x86_ucode_id { + __u16 vendor; + __u16 family; + __u16 model; + __u16 stepping; + __u32 min_ucode; + __u32 max_ucode; + kernel_ulong_t driver_data; +}; + +extern const struct x86_ucode_id * +x86_match_ucode_cpu(int cpu, const struct x86_ucode_id *match); +extern const struct x86_ucode_id * +x86_match_ucode_all(const struct x86_ucode_id *match); + #endif diff --git a/arch/x86/kernel/cpu/match.c b/arch/x86/kernel/cpu/match.c index 3fed38812eea..f29a21b2809c 100644 --- a/arch/x86/kernel/cpu/match.c +++ b/arch/x86/kernel/cpu/match.c @@ -48,3 +48,46 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match) return NULL; } EXPORT_SYMBOL(x86_match_cpu); + +const struct x86_ucode_id *x86_match_ucode_cpu(int cpu, + const struct x86_ucode_id *match) +{ + const struct x86_ucode_id *m; + struct cpuinfo_x86 *c = &cpu_data(cpu); + + for (m = match; m->vendor | m->family | m->model; m++) { + if (c->x86_vendor != m->vendor) + continue; + if (c->x86 != m->family) + continue; + if (c->x86_model != m->model) + continue; + if (c->x86_stepping != m->stepping) + continue; + if (m->min_ucode && c->microcode < m->min_ucode) + continue; + if (m->max_ucode && c->microcode > m->max_ucode) + continue; + return m; + } + return NULL; +} + +/* Check all CPUs */ +const struct x86_ucode_id *x86_match_ucode_all(const struct x86_ucode_id *match) +{ + int cpu; + const struct x86_ucode_id *all_m = NULL; + bool first = true; + + for_each_online_cpu(cpu) { + const struct x86_ucode_id *m = x86_match_ucode_cpu(cpu, match); + + if (first) + all_m = m; + else if (m != all_m) + return NULL; + first = false; + } + return all_m; +}