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

Conversation

shenki
Copy link
Contributor

@shenki shenki commented May 1, 2025

https://lore.kernel.org/qemu-devel/20250404152750.332791-1-dbarboza@ventanamicro.com/

[As more] distros use the 'virt' machine, and they'll start building
on top of RVA23, and rv64 does not have RVA23 support. In short,
distros will start to break in the default 'virt' CPU.

Changing the default CPU to 'max' will not cause (intentional) user
regressions: if the software runs in rv64 it will run in 'max' too given
that we're adding more extensions as default instead of removing them.

To ensure lima works once Ubuntu 25.10 comes out, which is expected to require RV23, set the cpu type to max.

https://lore.kernel.org/qemu-devel/20250404152750.332791-1-dbarboza@ventanamicro.com/

> [As more] distros use the 'virt' machine, and they'll start building
> on top of RVA23, and rv64 does not have RVA23 support. In short,
> distros will start to break in the default 'virt' CPU.
>
> Changing the default CPU to 'max' will not cause (intentional) user
> regressions: if the software runs in rv64 it will run in 'max' too given
> that we're adding more extensions as default instead of removing them.

To ensure lima works once Ubuntu 25.10 comes out, which is expected to
require RV23, set the cpu type to max.

Signed-off-by: Joel Stanley <jms@tenstorrent.com>
@shenki
Copy link
Contributor Author

shenki commented May 1, 2025

cc @danielhb

@@ -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.

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda added this to the v1.1.0 milestone May 1, 2025
@AkihiroSuda AkihiroSuda merged commit 94ed78c into lima-vm:master May 2, 2025
54 of 55 checks passed
@danielhb
Copy link

danielhb commented May 2, 2025

https://lore.kernel.org/qemu-devel/20250404152750.332791-1-dbarboza@ventanamicro.com/

[As more] distros use the 'virt' machine, and they'll start building
on top of RVA23, and rv64 does not have RVA23 support. In short,
distros will start to break in the default 'virt' CPU.
Changing the default CPU to 'max' will not cause (intentional) user
regressions: if the software runs in rv64 it will run in 'max' too given
that we're adding more extensions as default instead of removing them.

To ensure lima works once Ubuntu 25.10 comes out, which is expected to require RV23, set the cpu type to max.

+1 for this change. I recommend that all tooling that uses QEMU specifies their desired CPU in the command line (-cpu option) instead of relying on QEMU defaults.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants