fix: xen: consider Xen dom0 as non-guest (#343 continued)

(cherry picked from commit bc00a81526)
This commit is contained in:
Stéphane Lesimple
2026-07-30 15:51:23 +02:00
parent cc29aaba6b
commit d5cbaaa7c3
5 changed files with 62 additions and 17 deletions
+12 -2
View File
@@ -46,8 +46,18 @@ is_arm_cpu() {
# Check whether SMT (HyperThreading) is enabled on the system
# Returns: 0 if SMT enabled, 1 otherwise
is_cpu_smt_enabled() {
local siblings cpucores
# SMT / HyperThreading is enabled if siblings != cpucores
local siblings cpucores smt_active
# Most reliable: /sys/devices/system/cpu/smt/active mirrors the kernel's
# sched_smt_active() (1=SMT active, 0=not), which is exactly what the kernel
# itself uses to derive the "SMT (disabled|vulnerable)" vulnerability strings.
if [ -r /sys/devices/system/cpu/smt/active ]; then
smt_active=$(cat /sys/devices/system/cpu/smt/active 2>/dev/null)
case "$smt_active" in
1) return 0 ;;
0) return 1 ;;
esac
fi
# Fallback: SMT / HyperThreading is enabled if siblings != cpucores
if [ -e "$g_procfs/cpuinfo" ]; then
siblings=$(awk '/^siblings/ {print $3;exit}' "$g_procfs/cpuinfo")
cpucores=$(awk '/^cpu cores/ {print $4;exit}' "$g_procfs/cpuinfo")
+8 -1
View File
@@ -127,7 +127,14 @@ is_running_as_guest() {
if [ "${g_is_guest_vm_cached:-0}" != 1 ]; then
g_is_guest_vm=0
g_is_guest_vm_reason=''
if [ -e "$g_procfs/cpuinfo" ] && grep -qw 'hypervisor' "$g_procfs/cpuinfo" 2>/dev/null; then
# A Xen dom0 runs on top of the hypervisor and therefore also has the
# 'hypervisor' CPUID flag set, but it's the privileged control domain:
# it has direct hardware access and a truthful view of the host CPU
# topology, so it must not be classified as a guest (#343). Check it
# before the cpuinfo probe below, which would otherwise match.
if is_xen_dom0; then
g_is_guest_vm=0
elif [ -e "$g_procfs/cpuinfo" ] && grep -qw 'hypervisor' "$g_procfs/cpuinfo" 2>/dev/null; then
g_is_guest_vm=1
g_is_guest_vm_reason="'hypervisor' flag in $g_procfs/cpuinfo"
fi