File: //usr/libexec/microcode_ctl/reload_microcode
#! /bin/bash -efu
# Trigger microcode reload with additional check for BDW-EP that can have
# microcode reloaded only in case kernel has specific patches.
#
# SPDX-License-Identifier: CC0-1.0
export LC_ALL=C
CHECK_CAVEATS=/usr/libexec/microcode_ctl/check_caveats
IGNORE_HYPERVISOR="/etc/microcode_ctl/ignore-hypervisor-flag"
[ -e "$IGNORE_HYPERVISOR" ] || {
if grep -q '^flags[[:space:]]*:.* hypervisor\( .*\)\?$' /proc/cpuinfo
then
exit 0
fi
}
"$CHECK_CAVEATS" -m > /dev/null || exit 0
# For Intel, if the running microcode >= on-disk microcode, skip load.
if [ "$(/bin/sed -rn '1,/^$/s/^vendor_id[[:space:]]*: (.*)$/\1/p' /proc/cpuinfo)" = "GenuineIntel" ]; then
ucode_filename=$(/usr/bin/printf "%02x-%02x-%02x" \
$(/bin/sed -rn '1,/^$/{
s/^cpu family[[:space:]]*: (.*)$/\1/p;
s/^model[[:space:]]*: (.*)$/\1/p;
s/^stepping[[:space:]]*: (.*)$/\1/p;
}' /proc/cpuinfo))
ucode_file="/lib/firmware/$(uname -r)/intel-ucode/$ucode_filename"
if [ ! -f "$ucode_file" ]; then
ucode_file=/lib/firmware/intel-ucode/$ucode_filename
fi
running_ucode=$(/bin/sed -rn '1,/^$/s/^microcode[[:space:]]*: (.*)$/\1/p' /proc/cpuinfo)
if [ -f $ucode_file -a -n "$running_ucode" ]; then
new_ucode=$(od -An -j4 -N4 -tdI $ucode_file)
if [ $(($running_ucode)) -ge $new_ucode ]; then
echo "on-disk microcode is <= running microcode; not reloading"
exit 0
fi
fi
fi
echo 2>/dev/null 1 > /sys/devices/system/cpu/microcode/reload || :
exit 0