hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/arch/x86/kernel/cpu/microcode/amd.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * AMD CPU Microcode Update Driver for Linux
34 *
....@@ -5,7 +6,7 @@
56 * CPUs and later.
67 *
78 * Copyright (C) 2008-2011 Advanced Micro Devices Inc.
8
- * 2013-2016 Borislav Petkov <bp@alien8.de>
9
+ * 2013-2018 Borislav Petkov <bp@alien8.de>
910 *
1011 * Author: Peter Oruba <peter.oruba@amd.com>
1112 *
....@@ -17,9 +18,6 @@
1718 *
1819 * Author: Jacob Shin <jacob.shin@amd.com>
1920 * Fixes: Borislav Petkov <bp@suse.de>
20
- *
21
- * Licensed under the terms of the GNU General Public
22
- * License version 2. See file COPYING for details.
2321 */
2422 #define pr_fmt(fmt) "microcode: " fmt
2523
....@@ -38,7 +36,10 @@
3836 #include <asm/cpu.h>
3937 #include <asm/msr.h>
4038
41
-static struct equiv_cpu_entry *equiv_cpu_table;
39
+static struct equiv_cpu_table {
40
+ unsigned int num_entries;
41
+ struct equiv_cpu_entry *entry;
42
+} equiv_table;
4243
4344 /*
4445 * This points to the current valid container of microcode patches which we will
....@@ -58,17 +59,229 @@
5859
5960 /*
6061 * Microcode patch container file is prepended to the initrd in cpio
61
- * format. See Documentation/x86/microcode.txt
62
+ * format. See Documentation/x86/microcode.rst
6263 */
6364 static const char
6465 ucode_path[] __maybe_unused = "kernel/x86/microcode/AuthenticAMD.bin";
6566
66
-static u16 find_equiv_id(struct equiv_cpu_entry *equiv_table, u32 sig)
67
+static u16 find_equiv_id(struct equiv_cpu_table *et, u32 sig)
6768 {
68
- for (; equiv_table && equiv_table->installed_cpu; equiv_table++) {
69
- if (sig == equiv_table->installed_cpu)
70
- return equiv_table->equiv_cpu;
69
+ unsigned int i;
70
+
71
+ if (!et || !et->num_entries)
72
+ return 0;
73
+
74
+ for (i = 0; i < et->num_entries; i++) {
75
+ struct equiv_cpu_entry *e = &et->entry[i];
76
+
77
+ if (sig == e->installed_cpu)
78
+ return e->equiv_cpu;
79
+
80
+ e++;
7181 }
82
+ return 0;
83
+}
84
+
85
+/*
86
+ * Check whether there is a valid microcode container file at the beginning
87
+ * of @buf of size @buf_size. Set @early to use this function in the early path.
88
+ */
89
+static bool verify_container(const u8 *buf, size_t buf_size, bool early)
90
+{
91
+ u32 cont_magic;
92
+
93
+ if (buf_size <= CONTAINER_HDR_SZ) {
94
+ if (!early)
95
+ pr_debug("Truncated microcode container header.\n");
96
+
97
+ return false;
98
+ }
99
+
100
+ cont_magic = *(const u32 *)buf;
101
+ if (cont_magic != UCODE_MAGIC) {
102
+ if (!early)
103
+ pr_debug("Invalid magic value (0x%08x).\n", cont_magic);
104
+
105
+ return false;
106
+ }
107
+
108
+ return true;
109
+}
110
+
111
+/*
112
+ * Check whether there is a valid, non-truncated CPU equivalence table at the
113
+ * beginning of @buf of size @buf_size. Set @early to use this function in the
114
+ * early path.
115
+ */
116
+static bool verify_equivalence_table(const u8 *buf, size_t buf_size, bool early)
117
+{
118
+ const u32 *hdr = (const u32 *)buf;
119
+ u32 cont_type, equiv_tbl_len;
120
+
121
+ if (!verify_container(buf, buf_size, early))
122
+ return false;
123
+
124
+ cont_type = hdr[1];
125
+ if (cont_type != UCODE_EQUIV_CPU_TABLE_TYPE) {
126
+ if (!early)
127
+ pr_debug("Wrong microcode container equivalence table type: %u.\n",
128
+ cont_type);
129
+
130
+ return false;
131
+ }
132
+
133
+ buf_size -= CONTAINER_HDR_SZ;
134
+
135
+ equiv_tbl_len = hdr[2];
136
+ if (equiv_tbl_len < sizeof(struct equiv_cpu_entry) ||
137
+ buf_size < equiv_tbl_len) {
138
+ if (!early)
139
+ pr_debug("Truncated equivalence table.\n");
140
+
141
+ return false;
142
+ }
143
+
144
+ return true;
145
+}
146
+
147
+/*
148
+ * Check whether there is a valid, non-truncated microcode patch section at the
149
+ * beginning of @buf of size @buf_size. Set @early to use this function in the
150
+ * early path.
151
+ *
152
+ * On success, @sh_psize returns the patch size according to the section header,
153
+ * to the caller.
154
+ */
155
+static bool
156
+__verify_patch_section(const u8 *buf, size_t buf_size, u32 *sh_psize, bool early)
157
+{
158
+ u32 p_type, p_size;
159
+ const u32 *hdr;
160
+
161
+ if (buf_size < SECTION_HDR_SIZE) {
162
+ if (!early)
163
+ pr_debug("Truncated patch section.\n");
164
+
165
+ return false;
166
+ }
167
+
168
+ hdr = (const u32 *)buf;
169
+ p_type = hdr[0];
170
+ p_size = hdr[1];
171
+
172
+ if (p_type != UCODE_UCODE_TYPE) {
173
+ if (!early)
174
+ pr_debug("Invalid type field (0x%x) in container file section header.\n",
175
+ p_type);
176
+
177
+ return false;
178
+ }
179
+
180
+ if (p_size < sizeof(struct microcode_header_amd)) {
181
+ if (!early)
182
+ pr_debug("Patch of size %u too short.\n", p_size);
183
+
184
+ return false;
185
+ }
186
+
187
+ *sh_psize = p_size;
188
+
189
+ return true;
190
+}
191
+
192
+/*
193
+ * Check whether the passed remaining file @buf_size is large enough to contain
194
+ * a patch of the indicated @sh_psize (and also whether this size does not
195
+ * exceed the per-family maximum). @sh_psize is the size read from the section
196
+ * header.
197
+ */
198
+static unsigned int __verify_patch_size(u8 family, u32 sh_psize, size_t buf_size)
199
+{
200
+ u32 max_size;
201
+
202
+ if (family >= 0x15)
203
+ return min_t(u32, sh_psize, buf_size);
204
+
205
+#define F1XH_MPB_MAX_SIZE 2048
206
+#define F14H_MPB_MAX_SIZE 1824
207
+
208
+ switch (family) {
209
+ case 0x10 ... 0x12:
210
+ max_size = F1XH_MPB_MAX_SIZE;
211
+ break;
212
+ case 0x14:
213
+ max_size = F14H_MPB_MAX_SIZE;
214
+ break;
215
+ default:
216
+ WARN(1, "%s: WTF family: 0x%x\n", __func__, family);
217
+ return 0;
218
+ break;
219
+ }
220
+
221
+ if (sh_psize > min_t(u32, buf_size, max_size))
222
+ return 0;
223
+
224
+ return sh_psize;
225
+}
226
+
227
+/*
228
+ * Verify the patch in @buf.
229
+ *
230
+ * Returns:
231
+ * negative: on error
232
+ * positive: patch is not for this family, skip it
233
+ * 0: success
234
+ */
235
+static int
236
+verify_patch(u8 family, const u8 *buf, size_t buf_size, u32 *patch_size, bool early)
237
+{
238
+ struct microcode_header_amd *mc_hdr;
239
+ unsigned int ret;
240
+ u32 sh_psize;
241
+ u16 proc_id;
242
+ u8 patch_fam;
243
+
244
+ if (!__verify_patch_section(buf, buf_size, &sh_psize, early))
245
+ return -1;
246
+
247
+ /*
248
+ * The section header length is not included in this indicated size
249
+ * but is present in the leftover file length so we need to subtract
250
+ * it before passing this value to the function below.
251
+ */
252
+ buf_size -= SECTION_HDR_SIZE;
253
+
254
+ /*
255
+ * Check if the remaining buffer is big enough to contain a patch of
256
+ * size sh_psize, as the section claims.
257
+ */
258
+ if (buf_size < sh_psize) {
259
+ if (!early)
260
+ pr_debug("Patch of size %u truncated.\n", sh_psize);
261
+
262
+ return -1;
263
+ }
264
+
265
+ ret = __verify_patch_size(family, sh_psize, buf_size);
266
+ if (!ret) {
267
+ if (!early)
268
+ pr_debug("Per-family patch size mismatch.\n");
269
+ return -1;
270
+ }
271
+
272
+ *patch_size = sh_psize;
273
+
274
+ mc_hdr = (struct microcode_header_amd *)(buf + SECTION_HDR_SIZE);
275
+ if (mc_hdr->nb_dev_id || mc_hdr->sb_dev_id) {
276
+ if (!early)
277
+ pr_err("Patch-ID 0x%08x: chipset-specific code unsupported.\n", mc_hdr->patch_id);
278
+ return -1;
279
+ }
280
+
281
+ proc_id = mc_hdr->processor_rev_id;
282
+ patch_fam = 0xf + (proc_id >> 12);
283
+ if (patch_fam != family)
284
+ return 1;
72285
73286 return 0;
74287 }
....@@ -80,26 +293,28 @@
80293 * Returns the amount of bytes consumed while scanning. @desc contains all the
81294 * data we're going to use in later stages of the application.
82295 */
83
-static ssize_t parse_container(u8 *ucode, ssize_t size, struct cont_desc *desc)
296
+static size_t parse_container(u8 *ucode, size_t size, struct cont_desc *desc)
84297 {
85
- struct equiv_cpu_entry *eq;
86
- ssize_t orig_size = size;
298
+ struct equiv_cpu_table table;
299
+ size_t orig_size = size;
87300 u32 *hdr = (u32 *)ucode;
88301 u16 eq_id;
89302 u8 *buf;
90303
91
- /* Am I looking at an equivalence table header? */
92
- if (hdr[0] != UCODE_MAGIC ||
93
- hdr[1] != UCODE_EQUIV_CPU_TABLE_TYPE ||
94
- hdr[2] == 0)
95
- return CONTAINER_HDR_SZ;
304
+ if (!verify_equivalence_table(ucode, size, true))
305
+ return 0;
96306
97307 buf = ucode;
98308
99
- eq = (struct equiv_cpu_entry *)(buf + CONTAINER_HDR_SZ);
309
+ table.entry = (struct equiv_cpu_entry *)(buf + CONTAINER_HDR_SZ);
310
+ table.num_entries = hdr[2] / sizeof(struct equiv_cpu_entry);
100311
101
- /* Find the equivalence ID of our CPU in this table: */
102
- eq_id = find_equiv_id(eq, desc->cpuid_1_eax);
312
+ /*
313
+ * Find the equivalence ID of our CPU in this table. Even if this table
314
+ * doesn't contain a patch for the CPU, scan through the whole container
315
+ * so that it can be skipped in case there are other containers appended.
316
+ */
317
+ eq_id = find_equiv_id(&table, desc->cpuid_1_eax);
103318
104319 buf += hdr[2] + CONTAINER_HDR_SZ;
105320 size -= hdr[2] + CONTAINER_HDR_SZ;
....@@ -111,29 +326,29 @@
111326 while (size > 0) {
112327 struct microcode_amd *mc;
113328 u32 patch_size;
329
+ int ret;
114330
115
- hdr = (u32 *)buf;
331
+ ret = verify_patch(x86_family(desc->cpuid_1_eax), buf, size, &patch_size, true);
332
+ if (ret < 0) {
333
+ /*
334
+ * Patch verification failed, skip to the next
335
+ * container, if there's one:
336
+ */
337
+ goto out;
338
+ } else if (ret > 0) {
339
+ goto skip;
340
+ }
116341
117
- if (hdr[0] != UCODE_UCODE_TYPE)
118
- break;
119
-
120
- /* Sanity-check patch size. */
121
- patch_size = hdr[1];
122
- if (patch_size > PATCH_MAX_SIZE)
123
- break;
124
-
125
- /* Skip patch section header: */
126
- buf += SECTION_HDR_SIZE;
127
- size -= SECTION_HDR_SIZE;
128
-
129
- mc = (struct microcode_amd *)buf;
342
+ mc = (struct microcode_amd *)(buf + SECTION_HDR_SIZE);
130343 if (eq_id == mc->hdr.processor_rev_id) {
131344 desc->psize = patch_size;
132345 desc->mc = mc;
133346 }
134347
135
- buf += patch_size;
136
- size -= patch_size;
348
+skip:
349
+ /* Skip patch section header too: */
350
+ buf += patch_size + SECTION_HDR_SIZE;
351
+ size -= patch_size + SECTION_HDR_SIZE;
137352 }
138353
139354 /*
....@@ -150,6 +365,7 @@
150365 return 0;
151366 }
152367
368
+out:
153369 return orig_size - size;
154370 }
155371
....@@ -159,15 +375,18 @@
159375 */
160376 static void scan_containers(u8 *ucode, size_t size, struct cont_desc *desc)
161377 {
162
- ssize_t rem = size;
163
-
164
- while (rem >= 0) {
165
- ssize_t s = parse_container(ucode, rem, desc);
378
+ while (size) {
379
+ size_t s = parse_container(ucode, size, desc);
166380 if (!s)
167381 return;
168382
169
- ucode += s;
170
- rem -= s;
383
+ /* catch wraparound */
384
+ if (size >= s) {
385
+ ucode += s;
386
+ size -= s;
387
+ } else {
388
+ return;
389
+ }
171390 }
172391 }
173392
....@@ -222,7 +441,13 @@
222441 return ret;
223442
224443 native_rdmsr(MSR_AMD64_PATCH_LEVEL, rev, dummy);
225
- if (rev >= mc->hdr.patch_id)
444
+
445
+ /*
446
+ * Allow application of the same revision to pick up SMT-specific
447
+ * changes even if the revision of the other SMT thread is already
448
+ * up-to-date.
449
+ */
450
+ if (rev > mc->hdr.patch_id)
226451 return ret;
227452
228453 if (!__apply_microcode_amd(mc)) {
....@@ -304,8 +529,12 @@
304529
305530 native_rdmsr(MSR_AMD64_PATCH_LEVEL, rev, dummy);
306531
307
- /* Check whether we have saved a new patch already: */
308
- if (*new_rev && rev < mc->hdr.patch_id) {
532
+ /*
533
+ * Check whether a new patch has been saved already. Also, allow application of
534
+ * the same revision in order to pick up SMT-thread-specific configuration even
535
+ * if the sibling SMT thread already has an up-to-date revision.
536
+ */
537
+ if (*new_rev && rev <= mc->hdr.patch_id) {
309538 if (!__apply_microcode_amd(mc)) {
310539 *new_rev = mc->hdr.patch_id;
311540 return;
....@@ -348,7 +577,7 @@
348577 void reload_ucode_amd(void)
349578 {
350579 struct microcode_amd *mc;
351
- u32 rev, dummy;
580
+ u32 rev, dummy __always_unused;
352581
353582 mc = (struct microcode_amd *)amd_ucode_patch;
354583
....@@ -364,21 +593,7 @@
364593 static u16 __find_equiv_id(unsigned int cpu)
365594 {
366595 struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
367
- return find_equiv_id(equiv_cpu_table, uci->cpu_sig.sig);
368
-}
369
-
370
-static u32 find_cpu_family_by_equiv_cpu(u16 equiv_cpu)
371
-{
372
- int i = 0;
373
-
374
- BUG_ON(!equiv_cpu_table);
375
-
376
- while (equiv_cpu_table[i].equiv_cpu != 0) {
377
- if (equiv_cpu == equiv_cpu_table[i].equiv_cpu)
378
- return equiv_cpu_table[i].installed_cpu;
379
- i++;
380
- }
381
- return 0;
596
+ return find_equiv_id(&equiv_table, uci->cpu_sig.sig);
382597 }
383598
384599 /*
....@@ -461,43 +676,6 @@
461676 return 0;
462677 }
463678
464
-static unsigned int verify_patch_size(u8 family, u32 patch_size,
465
- unsigned int size)
466
-{
467
- u32 max_size;
468
-
469
-#define F1XH_MPB_MAX_SIZE 2048
470
-#define F14H_MPB_MAX_SIZE 1824
471
-#define F15H_MPB_MAX_SIZE 4096
472
-#define F16H_MPB_MAX_SIZE 3458
473
-#define F17H_MPB_MAX_SIZE 3200
474
-
475
- switch (family) {
476
- case 0x14:
477
- max_size = F14H_MPB_MAX_SIZE;
478
- break;
479
- case 0x15:
480
- max_size = F15H_MPB_MAX_SIZE;
481
- break;
482
- case 0x16:
483
- max_size = F16H_MPB_MAX_SIZE;
484
- break;
485
- case 0x17:
486
- max_size = F17H_MPB_MAX_SIZE;
487
- break;
488
- default:
489
- max_size = F1XH_MPB_MAX_SIZE;
490
- break;
491
- }
492
-
493
- if (patch_size > min_t(u32, size, max_size)) {
494
- pr_err("patch size mismatch\n");
495
- return 0;
496
- }
497
-
498
- return patch_size;
499
-}
500
-
501679 static enum ucode_state apply_microcode_amd(int cpu)
502680 {
503681 struct cpuinfo_x86 *c = &cpu_data(cpu);
....@@ -505,7 +683,7 @@
505683 struct ucode_cpu_info *uci;
506684 struct ucode_patch *p;
507685 enum ucode_state ret;
508
- u32 rev, dummy;
686
+ u32 rev, dummy __always_unused;
509687
510688 BUG_ON(raw_smp_processor_id() != cpu);
511689
....@@ -548,34 +726,34 @@
548726 return ret;
549727 }
550728
551
-static int install_equiv_cpu_table(const u8 *buf)
729
+static size_t install_equiv_cpu_table(const u8 *buf, size_t buf_size)
552730 {
553
- unsigned int *ibuf = (unsigned int *)buf;
554
- unsigned int type = ibuf[1];
555
- unsigned int size = ibuf[2];
731
+ u32 equiv_tbl_len;
732
+ const u32 *hdr;
556733
557
- if (type != UCODE_EQUIV_CPU_TABLE_TYPE || !size) {
558
- pr_err("empty section/"
559
- "invalid type field in container file section header\n");
560
- return -EINVAL;
561
- }
734
+ if (!verify_equivalence_table(buf, buf_size, false))
735
+ return 0;
562736
563
- equiv_cpu_table = vmalloc(size);
564
- if (!equiv_cpu_table) {
737
+ hdr = (const u32 *)buf;
738
+ equiv_tbl_len = hdr[2];
739
+
740
+ equiv_table.entry = vmalloc(equiv_tbl_len);
741
+ if (!equiv_table.entry) {
565742 pr_err("failed to allocate equivalent CPU table\n");
566
- return -ENOMEM;
743
+ return 0;
567744 }
568745
569
- memcpy(equiv_cpu_table, buf + CONTAINER_HDR_SZ, size);
746
+ memcpy(equiv_table.entry, buf + CONTAINER_HDR_SZ, equiv_tbl_len);
747
+ equiv_table.num_entries = equiv_tbl_len / sizeof(struct equiv_cpu_entry);
570748
571749 /* add header length */
572
- return size + CONTAINER_HDR_SZ;
750
+ return equiv_tbl_len + CONTAINER_HDR_SZ;
573751 }
574752
575753 static void free_equiv_cpu_table(void)
576754 {
577
- vfree(equiv_cpu_table);
578
- equiv_cpu_table = NULL;
755
+ vfree(equiv_table.entry);
756
+ memset(&equiv_table, 0, sizeof(equiv_table));
579757 }
580758
581759 static void cleanup(void)
....@@ -585,47 +763,23 @@
585763 }
586764
587765 /*
588
- * We return the current size even if some of the checks failed so that
766
+ * Return a non-negative value even if some of the checks failed so that
589767 * we can skip over the next patch. If we return a negative value, we
590768 * signal a grave error like a memory allocation has failed and the
591769 * driver cannot continue functioning normally. In such cases, we tear
592770 * down everything we've used up so far and exit.
593771 */
594
-static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover)
772
+static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover,
773
+ unsigned int *patch_size)
595774 {
596775 struct microcode_header_amd *mc_hdr;
597776 struct ucode_patch *patch;
598
- unsigned int patch_size, crnt_size, ret;
599
- u32 proc_fam;
600777 u16 proc_id;
778
+ int ret;
601779
602
- patch_size = *(u32 *)(fw + 4);
603
- crnt_size = patch_size + SECTION_HDR_SIZE;
604
- mc_hdr = (struct microcode_header_amd *)(fw + SECTION_HDR_SIZE);
605
- proc_id = mc_hdr->processor_rev_id;
606
-
607
- proc_fam = find_cpu_family_by_equiv_cpu(proc_id);
608
- if (!proc_fam) {
609
- pr_err("No patch family for equiv ID: 0x%04x\n", proc_id);
610
- return crnt_size;
611
- }
612
-
613
- /* check if patch is for the current family */
614
- proc_fam = ((proc_fam >> 8) & 0xf) + ((proc_fam >> 20) & 0xff);
615
- if (proc_fam != family)
616
- return crnt_size;
617
-
618
- if (mc_hdr->nb_dev_id || mc_hdr->sb_dev_id) {
619
- pr_err("Patch-ID 0x%08x: chipset-specific code unsupported.\n",
620
- mc_hdr->patch_id);
621
- return crnt_size;
622
- }
623
-
624
- ret = verify_patch_size(family, patch_size, leftover);
625
- if (!ret) {
626
- pr_err("Patch-ID 0x%08x: size mismatch.\n", mc_hdr->patch_id);
627
- return crnt_size;
628
- }
780
+ ret = verify_patch(family, fw, leftover, patch_size, false);
781
+ if (ret)
782
+ return ret;
629783
630784 patch = kzalloc(sizeof(*patch), GFP_KERNEL);
631785 if (!patch) {
....@@ -633,12 +787,16 @@
633787 return -EINVAL;
634788 }
635789
636
- patch->data = kmemdup(fw + SECTION_HDR_SIZE, patch_size, GFP_KERNEL);
790
+ patch->data = kmemdup(fw + SECTION_HDR_SIZE, *patch_size, GFP_KERNEL);
637791 if (!patch->data) {
638792 pr_err("Patch data allocation failure.\n");
639793 kfree(patch);
640794 return -EINVAL;
641795 }
796
+ patch->size = *patch_size;
797
+
798
+ mc_hdr = (struct microcode_header_amd *)(fw + SECTION_HDR_SIZE);
799
+ proc_id = mc_hdr->processor_rev_id;
642800
643801 INIT_LIST_HEAD(&patch->plist);
644802 patch->patch_id = mc_hdr->patch_id;
....@@ -650,39 +808,38 @@
650808 /* ... and add to cache. */
651809 update_cache(patch);
652810
653
- return crnt_size;
811
+ return 0;
654812 }
655813
656814 static enum ucode_state __load_microcode_amd(u8 family, const u8 *data,
657815 size_t size)
658816 {
659
- enum ucode_state ret = UCODE_ERROR;
660
- unsigned int leftover;
661817 u8 *fw = (u8 *)data;
662
- int crnt_size = 0;
663
- int offset;
818
+ size_t offset;
664819
665
- offset = install_equiv_cpu_table(data);
666
- if (offset < 0) {
667
- pr_err("failed to create equivalent cpu table\n");
668
- return ret;
669
- }
670
- fw += offset;
671
- leftover = size - offset;
820
+ offset = install_equiv_cpu_table(data, size);
821
+ if (!offset)
822
+ return UCODE_ERROR;
823
+
824
+ fw += offset;
825
+ size -= offset;
672826
673827 if (*(u32 *)fw != UCODE_UCODE_TYPE) {
674828 pr_err("invalid type field in container file section header\n");
675829 free_equiv_cpu_table();
676
- return ret;
830
+ return UCODE_ERROR;
677831 }
678832
679
- while (leftover) {
680
- crnt_size = verify_and_add_patch(family, fw, leftover);
681
- if (crnt_size < 0)
682
- return ret;
833
+ while (size > 0) {
834
+ unsigned int crnt_size = 0;
835
+ int ret;
683836
684
- fw += crnt_size;
685
- leftover -= crnt_size;
837
+ ret = verify_and_add_patch(family, fw, size, &crnt_size);
838
+ if (ret < 0)
839
+ return UCODE_ERROR;
840
+
841
+ fw += crnt_size + SECTION_HDR_SIZE;
842
+ size -= (crnt_size + SECTION_HDR_SIZE);
686843 }
687844
688845 return UCODE_OK;
....@@ -718,7 +875,7 @@
718875 return ret;
719876
720877 memset(amd_ucode_patch, 0, PATCH_MAX_SIZE);
721
- memcpy(amd_ucode_patch, p->data, min_t(u32, ksize(p->data), PATCH_MAX_SIZE));
878
+ memcpy(amd_ucode_patch, p->data, min_t(u32, p->size, PATCH_MAX_SIZE));
722879
723880 return ret;
724881 }
....@@ -761,10 +918,8 @@
761918 }
762919
763920 ret = UCODE_ERROR;
764
- if (*(u32 *)fw->data != UCODE_MAGIC) {
765
- pr_err("invalid magic value (0x%08x)\n", *(u32 *)fw->data);
921
+ if (!verify_container(fw->data, fw->size, false))
766922 goto fw_release;
767
- }
768923
769924 ret = load_microcode_amd(bsp, c->x86, fw->data, fw->size);
770925