Skip to content

Commit 38febce

Browse files
committed
x86/ucode: Rework Intel's microcode_update_match()
This function is overloaded, creating complexity; 3 of 4 callers already only want it for it's "applicable to this CPU or not" answer, and handle revision calculations separately. Change it to be microcode_fits_cpu(), returning a simple boolean. Notably, this removes a path where cpu_request_microcode() inspects currently-loaded microcode revision, just to discard the answer. No functional change. Signed-off-by: Andrew Cooper <[email protected]> Reviewed-by: Jan Beulich <[email protected]>
1 parent 39360c3 commit 38febce

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

xen/arch/x86/cpu/microcode/intel.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,8 @@ static enum microcode_match_result compare_revisions(
248248
return OLD_UCODE;
249249
}
250250

251-
/* Check an update against the CPU signature and current update revision */
252-
static enum microcode_match_result microcode_update_match(
253-
const struct microcode_patch *mc)
251+
/* Check whether this microcode patch is applicable for the current CPU. */
252+
static bool microcode_fits_cpu(const struct microcode_patch *mc)
254253
{
255254
const struct extended_sigtable *ext;
256255
unsigned int i;
@@ -260,18 +259,15 @@ static enum microcode_match_result microcode_update_match(
260259

261260
/* Check the main microcode signature. */
262261
if ( signature_matches(cpu_sig, mc->sig, mc->pf) )
263-
goto found;
262+
return true;
264263

265264
/* If there is an extended signature table, check each of them. */
266265
if ( (ext = get_ext_sigtable(mc)) != NULL )
267266
for ( i = 0; i < ext->count; ++i )
268267
if ( signature_matches(cpu_sig, ext->sigs[i].sig, ext->sigs[i].pf) )
269-
goto found;
270-
271-
return MIS_UCODE;
268+
return true;
272269

273-
found:
274-
return compare_revisions(cpu_sig->rev, mc->rev);
270+
return false;
275271
}
276272

277273
static enum microcode_match_result cf_check compare_patch(
@@ -281,8 +277,8 @@ static enum microcode_match_result cf_check compare_patch(
281277
* Both patches to compare are supposed to be applicable to local CPU.
282278
* Just compare the revision number.
283279
*/
284-
ASSERT(microcode_update_match(old) != MIS_UCODE);
285-
ASSERT(microcode_update_match(new) != MIS_UCODE);
280+
ASSERT(microcode_fits_cpu(old));
281+
ASSERT(microcode_fits_cpu(new));
286282

287283
return compare_revisions(old->rev, new->rev);
288284
}
@@ -297,11 +293,11 @@ static int cf_check apply_microcode(const struct microcode_patch *patch,
297293
enum microcode_match_result result;
298294
bool ucode_force = flags & XENPF_UCODE_FORCE;
299295

300-
result = microcode_update_match(patch);
301-
302-
if ( result == MIS_UCODE )
296+
if ( !microcode_fits_cpu(patch) )
303297
return -EINVAL;
304298

299+
result = compare_revisions(old_rev, patch->rev);
300+
305301
if ( !ucode_force && (result == SAME_UCODE || result == OLD_UCODE) )
306302
return -EEXIST;
307303

@@ -365,7 +361,7 @@ static struct microcode_patch *cf_check cpu_request_microcode(
365361
* If the new update covers current CPU, compare updates and store the
366362
* one with higher revision.
367363
*/
368-
if ( (microcode_update_match(mc) != MIS_UCODE) &&
364+
if ( microcode_fits_cpu(mc) &&
369365
(!saved || compare_revisions(saved->rev, mc->rev) == NEW_UCODE) )
370366
saved = mc;
371367

0 commit comments

Comments
 (0)