Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve compatibility with older CPU's #467

Merged
merged 14 commits into from
Apr 18, 2024
11 changes: 3 additions & 8 deletions src/boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ case "${BOOT_MODE,,}" in
ROM="OVMF_CODE_4M.secboot.fd"
VARS="OVMF_VARS_4M.secboot.fd"
;;
windows)
windows | windows_plain | windows_secure)
ROM="OVMF_CODE_4M.ms.fd"
VARS="OVMF_VARS_4M.ms.fd"
;;
windows_plain)
TPM="N"
ROM="OVMF_CODE_4M.fd"
VARS="OVMF_VARS_4M.fd"
;;
windows_legacy)
USB="usb-ehci,id=ehci"
;;
Expand Down Expand Up @@ -53,15 +48,15 @@ if [[ "${BOOT_MODE,,}" != "legacy" ]] && [[ "${BOOT_MODE,,}" != "windows_legacy"
cp "$OVMF/$VARS" "$DEST.vars"
fi

if [[ "${BOOT_MODE,,}" == "secure" ]] || [[ "${BOOT_MODE,,}" == "windows" ]]; then
if [[ "${BOOT_MODE,,}" == "secure" ]] || [[ "${BOOT_MODE,,}" == "windows_secure" ]]; then
SECURE=",smm=on"
BOOT_OPTS="$BOOT_OPTS -global driver=cfi.pflash01,property=secure,value=on"
fi

BOOT_OPTS="$BOOT_OPTS -drive file=$DEST.rom,if=pflash,unit=0,format=raw,readonly=on"
BOOT_OPTS="$BOOT_OPTS -drive file=$DEST.vars,if=pflash,unit=1,format=raw"

if [[ "${BOOT_MODE,,}" == "windows" ]]; then
if [[ "${BOOT_MODE,,}" == "windows_secure" ]]; then

BOOT_OPTS="$BOOT_OPTS -global ICH9-LPC.disable_s3=1"

Expand Down
61 changes: 49 additions & 12 deletions src/proc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ if [[ "$KVM" != [Nn]* ]]; then
if ! sh -c 'echo -n > /dev/kvm' &> /dev/null; then
KVM_ERR="(no write access)"
else
if ! grep -q -e vmx -e svm /proc/cpuinfo; then
flags=$(sed -ne '/^flags/s/^.*: //p' /proc/cpuinfo)
if ! grep -qw "vmx\|svm" <<< "$flags"; then
KVM_ERR="(vmx/svm disabled)"
fi
fi
Expand All @@ -39,22 +40,61 @@ fi
if [[ "$KVM" != [Nn]* ]]; then

CPU_FEATURES="kvm=on,l3-cache=on"
HV_FEATURES="+hypervisor,+invtsc,hv_passthrough"
KVM_OPTS=",accel=kvm -enable-kvm -global kvm-pit.lost_tick_policy=discard"

if [ -z "$CPU_MODEL" ]; then
CPU_MODEL="host"
CPU_FEATURES="$CPU_FEATURES,migratable=no"
fi

if [[ "$HV" != [Nn]* ]] && [[ "${BOOT_MODE,,}" == "windows"* ]]; then

HV_FEATURES="+hypervisor,hv_passthrough"

if grep -qw "svm" <<< "$flags"; then

# AMD processor

if grep -qw "tsc_scale" <<< "$flags"; then
HV_FEATURES="$HV_FEATURES,+invtsc"
fi

if ! grep -qw "avic" <<< "$flags"; then
HV_FEATURES="$HV_FEATURES,-hv-avic"
fi

else

# Intel processor

vmx=$(sed -ne '/^vmx flags/s/^.*: //p' /proc/cpuinfo)

if grep -qw "tsc_scaling" <<< "$vmx"; then
HV_FEATURES="$HV_FEATURES,+invtsc"
fi

if ! grep -qw "apicv" <<< "$vmx"; then
HV_FEATURES="$HV_FEATURES,-hv-apicv,-hv-evmcs"
else
if ! grep -qw "shadow_vmcs" <<< "$vmx"; then
# Prevent eVMCS version range error on Atom CPU's
HV_FEATURES="$HV_FEATURES,-hv-evmcs"
fi
fi

fi

[ -n "$CPU_FEATURES" ] && CPU_FEATURES="$CPU_FEATURES,"
CPU_FEATURES="$CPU_FEATURES${HV_FEATURES}"

fi

else

KVM_OPTS=""
CPU_FEATURES="l3-cache=on"
HV_FEATURES="+hypervisor,hv_passthrough"

if [[ "$ARCH" != "amd64" ]]; then
KVM_OPTS=""
else
if [[ "$ARCH" == "amd64" ]]; then
KVM_OPTS=" -accel tcg,thread=multi"
fi

Expand All @@ -69,12 +109,9 @@ else

CPU_FEATURES="$CPU_FEATURES,+ssse3,+sse4.1,+sse4.2"

fi

if [[ "$HV" != [Nn]* ]] && [[ "${BOOT_MODE,,}" == "windows"* ]]; then

[ -n "$CPU_FEATURES" ] && CPU_FEATURES="$CPU_FEATURES,"
CPU_FEATURES="$CPU_FEATURES${HV_FEATURES}"
if [[ "$HV" != [Nn]* ]] && [[ "${BOOT_MODE,,}" == "windows"* ]]; then
CPU_FEATURES="$CPU_FEATURES,+hypervisor"
fi

fi

Expand Down
Loading