Skip to content

Set riscv64 cpu to max #3484

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

Merged
merged 1 commit into from
May 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/limayaml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func defaultCPUType() CPUType {
ARMV7L: "cortex-a7",
// Since https://github.com/lima-vm/lima/pull/494, we use qemu64 cpu for better emulation of x86_64.
X8664: "qemu64",
RISCV64: "rv64", // FIXME: what is the right choice for riscv64?
RISCV64: "max",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if we can use max for other architectures too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that qemu-system-x86_64 -cpu max didn't work with TCG mode in the past, but I could be just wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChatGPT says -cpu max is safe on modern QEMU

You’re not imagining it—there really were times when -cpu max under the TCG accelerator simply didn’t work correctly. Here’s a quick rundown:


1. What “-cpu max” really means

By design,

-cpu max enables all CPU features that your accelerator supports (i.e. KVM, HVF, TCG, etc.) ([kvm virtualization - KVM - difference between -cpu host and -cpu max? - Server Fault](https://serverfault.com/questions/977643/kvm-difference-between-cpu-host-and-cpu-max)).
So in pure-software (TCG) mode it will try to expose every feature TCG has implemented.


2. Historical bugs in TCG + -cpu max

  1. Linux would hang
    In QEMU 6.1.0 (and the Fedora builds around that time), launching a Linux guest with TCG and -cpu max caused SeaBIOS to hang just before the kernel took over.

  2. Invalid-opcode on BMI instructions
    Even when it didn’t outright hang, -cpu max could turn on modern bit-manipulation extensions (BMI, BMI2, ABM) that TCG didn’t fully decode, leading to “invalid opcode” traps under TCG (while they worked flawlessly under KVM) ([Bug #1748296 “TCG throws Invalid Opcode when executing x86 BMI s...” : Bugs : QEMU](https://bugs.launchpad.net/bugs/1748296)).


3. What to do today

  • On older QEMU (≈6.1.0):
    Avoid -cpu max with TCG. Instead use -cpu host (which matches your host CPU) or pick a specific named model (e.g. Skylake-Server).

  • On recent QEMU (≥6.1.0-5):
    The hanging bug was fixed in the 6.1.0-5 update, and the BMI issue has also been addressed in later patches. You can now safely use -cpu max under TCG, though unsupported features will still emit harmless warnings like:

    warning: TCG doesn't support requested feature: CPUID.01H:ECX.vmx [bit 5]
    

    and any truly unimplemented instructions will fault, so keep an eye on your guest’s dmesg or console output.


In short: your memory is correct—-cpu max did misbehave in TCG mode in the past. If you’ve upgraded to a modern QEMU, those specific issues are fixed, but if you’re on an older 6.1.0-era build, you’ll still hit those TCG-only bugs with -cpu max.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not as familiar with the other arches.

S390X: "qemu", // FIXME: what is the right choice for s390x?
}
for arch := range cpuType {
Expand Down
Loading