enh: read/write_msr: clearer error messages

This commit is contained in:
Stéphane Lesimple
2026-04-06 18:43:36 +02:00
parent d040c0ffc3
commit be91749d3a
2 changed files with 38 additions and 13 deletions

View File

@@ -5,20 +5,27 @@ readonly WRITE_MSR_RET_ERR=2
readonly WRITE_MSR_RET_LOCKDOWN=3 readonly WRITE_MSR_RET_LOCKDOWN=3
# Write a value to an MSR register across one or all cores # Write a value to an MSR register across one or all cores
# Args: $1=msr_address $2=value(optional) $3=cpu_index(optional, default 0) # Args: $1=msr_address $2=value(optional) $3=cpu_index(optional, default 0)
# Sets: ret_write_msr_msg # Sets: ret_write_msr_msg, ret_write_msr_ADDR_msg (where ADDR is the hex address, e.g. ret_write_msr_0x123_msg)
# Returns: WRITE_MSR_RET_OK | WRITE_MSR_RET_KO | WRITE_MSR_RET_ERR | WRITE_MSR_RET_LOCKDOWN # Returns: WRITE_MSR_RET_OK | WRITE_MSR_RET_KO | WRITE_MSR_RET_ERR | WRITE_MSR_RET_LOCKDOWN
write_msr() { write_msr() {
local ret core first_core_ret local ret core first_core_ret msr_dec msr
msr_dec=$(($1))
msr=$(printf "0x%x" "$msr_dec")
if [ "$opt_cpu" != all ]; then if [ "$opt_cpu" != all ]; then
# we only have one core to write to, do it and return the result # we only have one core to write to, do it and return the result
write_msr_one_core "$opt_cpu" "$@" write_msr_one_core "$opt_cpu" "$@"
return $? ret=$?
# shellcheck disable=SC2163
eval "ret_write_msr_${msr}_msg=\$ret_write_msr_msg"
return $ret
fi fi
# otherwise we must write on all cores # otherwise we must write on all cores
for core in $(seq 0 "$g_max_core_id"); do for core in $(seq 0 "$g_max_core_id"); do
write_msr_one_core "$core" "$@" write_msr_one_core "$core" "$@"
ret=$? ret=$?
# shellcheck disable=SC2163
eval "ret_write_msr_${msr}_msg=\$ret_write_msr_msg"
if [ "$core" = 0 ]; then if [ "$core" = 0 ]; then
# save the result of the first core, for comparison with the others # save the result of the first core, for comparison with the others
first_core_ret=$ret first_core_ret=$ret
@@ -26,6 +33,8 @@ write_msr() {
# compare first core with the other ones # compare first core with the other ones
if [ "$first_core_ret" != "$ret" ]; then if [ "$first_core_ret" != "$ret" ]; then
ret_write_msr_msg="result is not homogeneous between all cores, at least core 0 and $core differ!" ret_write_msr_msg="result is not homogeneous between all cores, at least core 0 and $core differ!"
# shellcheck disable=SC2163
eval "ret_write_msr_${msr}_msg=\$ret_write_msr_msg"
return $WRITE_MSR_RET_ERR return $WRITE_MSR_RET_ERR
fi fi
fi fi
@@ -181,20 +190,28 @@ readonly READ_MSR_RET_ERR=2
readonly READ_MSR_RET_LOCKDOWN=3 readonly READ_MSR_RET_LOCKDOWN=3
# Read an MSR register value across one or all cores # Read an MSR register value across one or all cores
# Args: $1=msr_address $2=cpu_index(optional, default 0) # Args: $1=msr_address $2=cpu_index(optional, default 0)
# Sets: ret_read_msr_value, ret_read_msr_value_hi, ret_read_msr_value_lo, ret_read_msr_msg # Sets: ret_read_msr_value, ret_read_msr_value_hi, ret_read_msr_value_lo, ret_read_msr_msg,
# ret_read_msr_ADDR_msg (where ADDR is the hex address, e.g. ret_read_msr_0x10a_msg)
# Returns: READ_MSR_RET_OK | READ_MSR_RET_KO | READ_MSR_RET_ERR | READ_MSR_RET_LOCKDOWN # Returns: READ_MSR_RET_OK | READ_MSR_RET_KO | READ_MSR_RET_ERR | READ_MSR_RET_LOCKDOWN
read_msr() { read_msr() {
local ret core first_core_ret first_core_value local ret core first_core_ret first_core_value msr_dec msr
msr_dec=$(($1))
msr=$(printf "0x%x" "$msr_dec")
if [ "$opt_cpu" != all ]; then if [ "$opt_cpu" != all ]; then
# we only have one core to read, do it and return the result # we only have one core to read, do it and return the result
read_msr_one_core "$opt_cpu" "$@" read_msr_one_core "$opt_cpu" "$@"
return $? ret=$?
# shellcheck disable=SC2163
eval "ret_read_msr_${msr}_msg=\$ret_read_msr_msg"
return $ret
fi fi
# otherwise we must read all cores # otherwise we must read all cores
for core in $(seq 0 "$g_max_core_id"); do for core in $(seq 0 "$g_max_core_id"); do
read_msr_one_core "$core" "$@" read_msr_one_core "$core" "$@"
ret=$? ret=$?
# shellcheck disable=SC2163
eval "ret_read_msr_${msr}_msg=\$ret_read_msr_msg"
if [ "$core" = 0 ]; then if [ "$core" = 0 ]; then
# save the result of the first core, for comparison with the others # save the result of the first core, for comparison with the others
first_core_ret=$ret first_core_ret=$ret
@@ -203,6 +220,8 @@ read_msr() {
# compare first core with the other ones # compare first core with the other ones
if [ "$first_core_ret" != "$ret" ] || [ "$first_core_value" != "$ret_read_msr_value" ]; then if [ "$first_core_ret" != "$ret" ] || [ "$first_core_value" != "$ret_read_msr_value" ]; then
ret_read_msr_msg="result is not homogeneous between all cores, at least core 0 and $core differ!" ret_read_msr_msg="result is not homogeneous between all cores, at least core 0 and $core differ!"
# shellcheck disable=SC2163
eval "ret_read_msr_${msr}_msg=\$ret_read_msr_msg"
return $READ_MSR_RET_ERR return $READ_MSR_RET_ERR
fi fi
fi fi

View File

@@ -549,7 +549,7 @@ check_cpu() {
elif [ "$spec_ctrl_msr" = 0 ]; then elif [ "$spec_ctrl_msr" = 0 ]; then
pstatus yellow NO pstatus yellow NO
else else
pstatus yellow UNKNOWN "is msr kernel module available?" pstatus yellow UNKNOWN "$ret_read_msr_msg"
fi fi
pr_info_nol " * CPU indicates STIBP capability: " pr_info_nol " * CPU indicates STIBP capability: "
@@ -974,7 +974,8 @@ check_cpu() {
elif [ "$cap_tsx_ctrl_rtm_disable" = 0 ]; then elif [ "$cap_tsx_ctrl_rtm_disable" = 0 ]; then
pstatus blue NO pstatus blue NO
else else
pstatus yellow UNKNOWN "couldn't read MSR" # shellcheck disable=SC2154
pstatus yellow UNKNOWN "$ret_read_msr_0x122_msg"
fi fi
pr_info_nol " * TSX_CTRL MSR indicates TSX CPUID bit is cleared: " pr_info_nol " * TSX_CTRL MSR indicates TSX CPUID bit is cleared: "
@@ -983,7 +984,8 @@ check_cpu() {
elif [ "$cap_tsx_ctrl_cpuid_clear" = 0 ]; then elif [ "$cap_tsx_ctrl_cpuid_clear" = 0 ]; then
pstatus blue NO pstatus blue NO
else else
pstatus yellow UNKNOWN "couldn't read MSR" # shellcheck disable=SC2154
pstatus yellow UNKNOWN "$ret_read_msr_0x122_msg"
fi fi
fi fi
@@ -1008,7 +1010,8 @@ check_cpu() {
pr_info_nol " * GDS microcode mitigation is disabled (GDS_MITG_DIS): " pr_info_nol " * GDS microcode mitigation is disabled (GDS_MITG_DIS): "
if [ "$cap_gds_mitg_dis" = -1 ]; then if [ "$cap_gds_mitg_dis" = -1 ]; then
pstatus yellow UNKNOWN "couldn't read MSR" # shellcheck disable=SC2154
pstatus yellow UNKNOWN "$ret_read_msr_0x123_msg"
elif [ "$cap_gds_mitg_dis" = 1 ]; then elif [ "$cap_gds_mitg_dis" = 1 ]; then
pstatus yellow YES pstatus yellow YES
else else
@@ -1017,7 +1020,8 @@ check_cpu() {
pr_info_nol " * GDS microcode mitigation is locked in enabled state (GDS_MITG_LOCK): " pr_info_nol " * GDS microcode mitigation is locked in enabled state (GDS_MITG_LOCK): "
if [ "$cap_gds_mitg_lock" = -1 ]; then if [ "$cap_gds_mitg_lock" = -1 ]; then
pstatus yellow UNKNOWN "couldn't read MSR" # shellcheck disable=SC2154
pstatus yellow UNKNOWN "$ret_read_msr_0x123_msg"
elif [ "$cap_gds_mitg_lock" = 1 ]; then elif [ "$cap_gds_mitg_lock" = 1 ]; then
pstatus blue YES pstatus blue YES
else else
@@ -1205,7 +1209,8 @@ check_cpu() {
elif [ "$cap_tsx_force_abort_rtm_disable" = 0 ]; then elif [ "$cap_tsx_force_abort_rtm_disable" = 0 ]; then
pstatus blue NO pstatus blue NO
else else
pstatus yellow UNKNOWN "couldn't read MSR" # shellcheck disable=SC2154
pstatus yellow UNKNOWN "$ret_read_msr_0x10f_msg"
fi fi
pr_info_nol " * TSX_FORCE_ABORT MSR indicates TSX CPUID bit is cleared: " pr_info_nol " * TSX_FORCE_ABORT MSR indicates TSX CPUID bit is cleared: "
@@ -1214,7 +1219,8 @@ check_cpu() {
elif [ "$cap_tsx_force_abort_cpuid_clear" = 0 ]; then elif [ "$cap_tsx_force_abort_cpuid_clear" = 0 ]; then
pstatus blue NO pstatus blue NO
else else
pstatus yellow UNKNOWN "couldn't read MSR" # shellcheck disable=SC2154
pstatus yellow UNKNOWN "$ret_read_msr_0x10f_msg"
fi fi
fi fi