From: Andi Kleen <andi@firstfloor.org>
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 <ak@linux.intel.com>
Subject: [PATCH v1 1/2] x86/cpufeature: Add facility to match microcode revisions
Date: Fri, 5 Oct 2018 17:19:27 -0700 [thread overview]
Message-ID: <20181006001928.28097-1-andi@firstfloor.org> (raw)
From: Andi Kleen <ak@linux.intel.com>
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 <ak@linux.intel.com>
---
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;
+}
--
2.17.1
next reply other threads:[~2018-10-06 0:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-06 0:19 Andi Kleen [this message]
2018-10-06 14:14 ` [PATCH v1 1/2] x86/cpufeature: Add facility to match microcode revisions Thomas Gleixner
2018-10-06 16:10 ` Thomas Gleixner
2018-10-06 18:15 ` Andi Kleen
2018-10-06 18:39 ` Borislav Petkov
2018-10-07 5:32 ` Thomas Gleixner
[not found] ` <20181006001928.28097-2-andi@firstfloor.org>
2018-10-06 14:40 ` [PATCH v1 2/2] perf/x86/kvm: Avoid unnecessary work in guest filtering Thomas Gleixner
2018-10-06 16:13 ` Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181006001928.28097-1-andi@firstfloor.org \
--to=andi@firstfloor.org \
--cc=ak@linux.intel.com \
--cc=eranian@google.com \
--cc=isaku.yamahata@intel.com \
--cc=kan.liang@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).