From 7d85112d12e26a50c28b93ce60ed4867a3de5f8f Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 15 Sep 2025 22:09:51 +0200 Subject: [PATCH] feat: Restrict AMD CPU's to a single core (#297) --- src/boot.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/boot.sh b/src/boot.sh index c709f7d..7c5209c 100644 --- a/src/boot.sh +++ b/src/boot.sh @@ -2,8 +2,9 @@ set -Eeuo pipefail # Docker environment variables -: "${BOOT_MODE:="macos"}" # Boot mode +: "${FORCE:="N"}" # Force cores : "${SECURE:="off"}" # Secure boot +: "${BOOT_MODE:="macos"}" # Boot mode BOOT_DESC="" BOOT_OPTS="" @@ -156,7 +157,7 @@ DISK_OPTS+=" -drive file=$IMG,id=$BOOT_DRIVE_ID,format=raw,cache=unsafe,readonly CPU_VENDOR=$(lscpu | awk '/Vendor ID/{print $3}') DEFAULT_FLAGS="vendor=GenuineIntel,vmware-cpuid-freq=on,-pdpe1gb" -if [[ "$CPU_VENDOR" != "GenuineIntel" ]] || [[ "${KVM:-}" == [Nn]* ]]; then +if [[ "$CPU_VENDOR" == "AuthenticAMD" ]] || [[ "${KVM:-}" == [Nn]* ]]; then [ -z "${CPU_MODEL:-}" ] && CPU_MODEL="Haswell-noTSX" DEFAULT_FLAGS+=",+pcid,+ssse3,+sse4.2,+popcnt,+avx,+avx2,+aes,+fma,+bmi1,+bmi2,+smep,+xsave,+xsavec,+xsaveopt,+xgetbv1,+movbe,+rdrand,check" fi @@ -167,6 +168,11 @@ else CPU_FLAGS="$DEFAULT_FLAGS,$CPU_FLAGS" fi +if [[ "$CPU_VENDOR" == "AuthenticAMD" ]] && [[ "${CPU_CORES,,}" != "1" ]] && [[ "${FORCE:-}" == [Nn]* ]] && [[ "${KVM:-}" != [Nn]* ]]; then + warn "Restricted processor to a single core (instead of $CPU_CORES cores) because an AMD CPU was detected! (Set FORCE=Y to disable this measure)" + CPU_CORES="1" +fi + SM_BIOS="" CLOCKSOURCE="tsc" [[ "${ARCH,,}" == "arm64" ]] && CLOCKSOURCE="arch_sys_counter" @@ -180,8 +186,8 @@ else case "${result,,}" in "${CLOCKSOURCE,,}" ) ;; "kvm-clock" ) - if [[ "$CPU_VENDOR" != "GenuineIntel" ]] && [[ "${CPU_CORES,,}" == "2" ]]; then - warn "Restricted processor to a single core because nested KVM virtualization was detected!" + if [[ "$CPU_VENDOR" == "AuthenticAMD" ]] && [[ "${CPU_CORES,,}" != "1" ]] && [[ "${FORCE:-}" == [Nn]* ]] && [[ "${KVM:-}" != [Nn]* ]]; then + warn "Restricted processor to a single core (instead of $CPU_CORES cores) because nested KVM virtualization on an AMD CPU was detected! (Set FORCE=Y to disable this measure)" CPU_CORES="1" else warn "Nested KVM virtualization detected, this might cause issues running macOS!"