Skip to content

Commit 39cd7c1

Browse files
maciejsszmigierosuryasaimadhu
authored andcommitted
x86/microcode/AMD: Convert CPU equivalence table variable into a struct
Convert the CPU equivalence table into a proper struct in preparation for tracking also the size of this table. [ bp: Have functions deal with struct equiv_cpu_table pointers only. Rediff. ] Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name> Signed-off-by: Borislav Petkov <bp@suse.de> Cc: x86@kernel.org Link: https://lkml.kernel.org/r/20181107170218.7596-15-bp@alien8.de
1 parent 38673f6 commit 39cd7c1

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

  • arch/x86/kernel/cpu/microcode

‎arch/x86/kernel/cpu/microcode/amd.c‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
#include <asm/cpu.h>
3939
#include <asm/msr.h>
4040

41-
static struct equiv_cpu_entry *equiv_cpu_table;
41+
static struct equiv_cpu_table {
42+
struct equiv_cpu_entry *entry;
43+
} equiv_table;
4244

4345
/*
4446
* This points to the current valid container of microcode patches which we will
@@ -63,11 +65,13 @@ static u8 amd_ucode_patch[PATCH_MAX_SIZE];
6365
static const char
6466
ucode_path[] __maybe_unused = "kernel/x86/microcode/AuthenticAMD.bin";
6567

66-
static u16 find_equiv_id(struct equiv_cpu_entry *equiv_table, u32 sig)
68+
static u16 find_equiv_id(struct equiv_cpu_table *et, u32 sig)
6769
{
68-
for (; equiv_table && equiv_table->installed_cpu; equiv_table++) {
69-
if (sig == equiv_table->installed_cpu)
70-
return equiv_table->equiv_cpu;
70+
struct equiv_cpu_entry *entry = et->entry;
71+
72+
for (; entry && entry->installed_cpu; entry++) {
73+
if (sig == entry->installed_cpu)
74+
return entry->equiv_cpu;
7175
}
7276

7377
return 0;
@@ -286,7 +290,7 @@ verify_patch(u8 family, const u8 *buf, size_t buf_size, u32 *patch_size, bool ea
286290
*/
287291
static size_t parse_container(u8 *ucode, size_t size, struct cont_desc *desc)
288292
{
289-
struct equiv_cpu_entry *eq;
293+
struct equiv_cpu_table table;
290294
size_t orig_size = size;
291295
u32 *hdr = (u32 *)ucode;
292296
u16 eq_id;
@@ -297,14 +301,14 @@ static size_t parse_container(u8 *ucode, size_t size, struct cont_desc *desc)
297301

298302
buf = ucode;
299303

300-
eq = (struct equiv_cpu_entry *)(buf + CONTAINER_HDR_SZ);
304+
table.entry = (struct equiv_cpu_entry *)(buf + CONTAINER_HDR_SZ);
301305

302306
/*
303307
* Find the equivalence ID of our CPU in this table. Even if this table
304308
* doesn't contain a patch for the CPU, scan through the whole container
305309
* so that it can be skipped in case there are other containers appended.
306310
*/
307-
eq_id = find_equiv_id(eq, desc->cpuid_1_eax);
311+
eq_id = find_equiv_id(&table, desc->cpuid_1_eax);
308312

309313
buf += hdr[2] + CONTAINER_HDR_SZ;
310314
size -= hdr[2] + CONTAINER_HDR_SZ;
@@ -573,7 +577,7 @@ void reload_ucode_amd(void)
573577
static u16 __find_equiv_id(unsigned int cpu)
574578
{
575579
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
576-
return find_equiv_id(equiv_cpu_table, uci->cpu_sig.sig);
580+
return find_equiv_id(&equiv_table, uci->cpu_sig.sig);
577581
}
578582

579583
/*
@@ -717,22 +721,22 @@ static size_t install_equiv_cpu_table(const u8 *buf, size_t buf_size)
717721
hdr = (const u32 *)buf;
718722
equiv_tbl_len = hdr[2];
719723

720-
equiv_cpu_table = vmalloc(equiv_tbl_len);
721-
if (!equiv_cpu_table) {
724+
equiv_table.entry = vmalloc(equiv_tbl_len);
725+
if (!equiv_table.entry) {
722726
pr_err("failed to allocate equivalent CPU table\n");
723727
return 0;
724728
}
725729

726-
memcpy(equiv_cpu_table, buf + CONTAINER_HDR_SZ, equiv_tbl_len);
730+
memcpy(equiv_table.entry, buf + CONTAINER_HDR_SZ, equiv_tbl_len);
727731

728732
/* add header length */
729733
return equiv_tbl_len + CONTAINER_HDR_SZ;
730734
}
731735

732736
static void free_equiv_cpu_table(void)
733737
{
734-
vfree(equiv_cpu_table);
735-
equiv_cpu_table = NULL;
738+
vfree(equiv_table.entry);
739+
equiv_table.entry = NULL;
736740
}
737741

738742
static void cleanup(void)

0 commit comments

Comments
 (0)