Skip to content

Commit 2fe51d5

Browse files
committed
fix(quickemu): skip x86 CPU feature checks on Apple Silicon
When using TCG emulation for cross-architecture VMs (e.g., x86_64 guest on arm64 host), skip the SSE/AVX CPU feature detection since QEMU emulates these features in software. This fixes macOS guest startup on Apple Silicon Macs. Fixes #1457
1 parent 81143af commit 2fe51d5

File tree

1 file changed

+50
-46
lines changed

1 file changed

+50
-46
lines changed

quickemu

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -429,52 +429,56 @@ function configure_cpu() {
429429
fi
430430
# A CPU with fma is required for Metal support
431431
# A CPU with invtsc is required for macOS to boot
432-
case ${macos_release} in
433-
ventura|sonoma|sequoia|tahoe)
434-
# A CPU with AVX2 support is required for >= macOS Ventura
435-
if check_cpu_flag sse4_2 && check_cpu_flag avx2; then
436-
if [ "${HOST_CPU_VENDOR}" != "GenuineIntel" ] && [ -z "${HYPERVISOR}" ]; then
437-
CPU+=",+avx2,+sse4.2"
438-
fi
439-
else
440-
echo "ERROR! macOS ${macos_release} requires a CPU with SSE 4.2 and AVX2 support."
441-
echo " Try macOS Monterey or Big Sur."
442-
exit 1
443-
fi;;
444-
catalina|big-sur|monterey)
445-
# A CPU with SSE4.2 support is required for >= macOS Catalina
446-
if check_cpu_flag sse4_2; then
447-
if [ "${HOST_CPU_VENDOR}" != "GenuineIntel" ] && [ -z "${HYPERVISOR}" ]; then
448-
CPU+=",+sse4.2"
449-
fi
450-
else
451-
echo "ERROR! macOS ${macos_release} requires a CPU with SSE 4.2 support."
452-
exit 1
453-
fi;;
454-
*)
455-
# A CPU with SSE4.1 support is required for >= macOS Sierra
456-
if check_cpu_flag sse4_1; then
457-
if [ "${HOST_CPU_VENDOR}" != "GenuineIntel" ] && [ -z "${HYPERVISOR}" ]; then
458-
CPU+=",+sse4.1"
459-
fi
460-
else
461-
echo "ERROR! macOS ${macos_release} requires a CPU with SSE 4.1 support."
462-
exit 1
463-
fi;;
464-
esac
465-
466-
if [ "${HOST_CPU_VENDOR}" != "GenuineIntel" ] && [ -z "${HYPERVISOR}" ]; then
467-
for FLAG in abm adx aes amd-ssbd apic arat bmi1 bmi2 clflush cmov cx8 cx16 de \
468-
eist erms f16c fma fp87 fsgsbase fxsr invpcid invtsc lahf_lm lm \
469-
mca mce mmx movbe mpx msr mtrr nx pae pat pcid pge pse popcnt pse36 \
470-
rdrand rdtscp sep smep syscall tsc tsc_adjust vaes vbmi2 vmx vpclmulqdq \
471-
x2apic xgetbv1 xsave xsaveopt; do
472-
CPU+=$(configure_cpu_flag "${FLAG}")
473-
done
474-
# AMD CPUs with constant_tsc need explicit TSC flags for macOS stability
475-
# constant_tsc is AMD's equivalent of Intel's invtsc
476-
if [ "${HOST_CPU_VENDOR}" == "AuthenticAMD" ] && check_cpu_flag invtsc; then
477-
CPU+=",+tsc,+tsc-deadline"
432+
# Skip CPU feature checks when using TCG emulation (cross-architecture)
433+
# as QEMU will emulate the required x86 features in software
434+
if [ "${QEMU_ACCEL}" != "tcg" ]; then
435+
case ${macos_release} in
436+
ventura|sonoma|sequoia|tahoe)
437+
# A CPU with AVX2 support is required for >= macOS Ventura
438+
if check_cpu_flag sse4_2 && check_cpu_flag avx2; then
439+
if [ "${HOST_CPU_VENDOR}" != "GenuineIntel" ] && [ -z "${HYPERVISOR}" ]; then
440+
CPU+=",+avx2,+sse4.2"
441+
fi
442+
else
443+
echo "ERROR! macOS ${macos_release} requires a CPU with SSE 4.2 and AVX2 support."
444+
echo " Try macOS Monterey or Big Sur."
445+
exit 1
446+
fi;;
447+
catalina|big-sur|monterey)
448+
# A CPU with SSE4.2 support is required for >= macOS Catalina
449+
if check_cpu_flag sse4_2; then
450+
if [ "${HOST_CPU_VENDOR}" != "GenuineIntel" ] && [ -z "${HYPERVISOR}" ]; then
451+
CPU+=",+sse4.2"
452+
fi
453+
else
454+
echo "ERROR! macOS ${macos_release} requires a CPU with SSE 4.2 support."
455+
exit 1
456+
fi;;
457+
*)
458+
# A CPU with SSE4.1 support is required for >= macOS Sierra
459+
if check_cpu_flag sse4_1; then
460+
if [ "${HOST_CPU_VENDOR}" != "GenuineIntel" ] && [ -z "${HYPERVISOR}" ]; then
461+
CPU+=",+sse4.1"
462+
fi
463+
else
464+
echo "ERROR! macOS ${macos_release} requires a CPU with SSE 4.1 support."
465+
exit 1
466+
fi;;
467+
esac
468+
469+
if [ "${HOST_CPU_VENDOR}" != "GenuineIntel" ] && [ -z "${HYPERVISOR}" ]; then
470+
for FLAG in abm adx aes amd-ssbd apic arat bmi1 bmi2 clflush cmov cx8 cx16 de \
471+
eist erms f16c fma fp87 fsgsbase fxsr invpcid invtsc lahf_lm lm \
472+
mca mce mmx movbe mpx msr mtrr nx pae pat pcid pge pse popcnt pse36 \
473+
rdrand rdtscp sep smep syscall tsc tsc_adjust vaes vbmi2 vmx vpclmulqdq \
474+
x2apic xgetbv1 xsave xsaveopt; do
475+
CPU+=$(configure_cpu_flag "${FLAG}")
476+
done
477+
# AMD CPUs with constant_tsc need explicit TSC flags for macOS stability
478+
# constant_tsc is AMD's equivalent of Intel's invtsc
479+
if [ "${HOST_CPU_VENDOR}" == "AuthenticAMD" ] && check_cpu_flag invtsc; then
480+
CPU+=",+tsc,+tsc-deadline"
481+
fi
478482
fi
479483
fi
480484

0 commit comments

Comments
 (0)