Skip to content

The basic example doesn't work for UEFI #562

Closed as not planned
Closed as not planned

Description

@chrisdsloan

I cloned the repo, cd'ed into examples/basic and tried cargo run bios. That run and exited in about 3 seconds.
Next, I tried cargo run uefi and it sat there spinning on the CPU for 6 minutes before I killed it.

So, QEMU works on my box, but examples/basic doesn't seem to work with uefi out of the box for me.

I got no output on the console (ie. the serial port) during the run. Judging on the bios run, it seems like the bootloader should probably be printing stuff, so I don't know if that helps narrow down what could be blocked spinning.

I'm not sure what other information to include. Let me know what would help.

$ time cargo r uefi
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/basic uefi`
QEMU: Terminated

real	6m24.164s
user	6m22.835s
sys	0m0.384s
$ 

Activity

  1. Freax13 commented on May 10, 2026

    @Freax13
    Member

    I can't reproduce this. Can you try with the latest nightly compiler? Using the latest nightly version is currently broken, so you might need the fixes from #563.

  2. chrisdsloan commented on May 10, 2026

    @chrisdsloan
    Author

    Actually, I continued debugging and investigating and I guess I've figured it out. The issue is that without KVM, ovmf in QEMU is so slow that even 6 minutes is not enough to get to the kernel code. When I add cmd.arg("-enable-kvm"); just before the spawn call in examples/basic/src/main.rs it works.

    In case it matters, here's the version of qemu I have:

    $ qemu-system-x86_64 --version
    QEMU emulator version 6.2.0 (Debian 1:6.2+dfsg-2ubuntu6.30)
    Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers
    

    I don't know if adding -enable-kvm is reasonable to do in general since not everyone may be in the kvm group (I was not before this). If not, maybe the docs can mention kvm and the fact that it can look hung if it's not enabled?

  3. Freax13 commented on May 10, 2026

    @Freax13
    Member

    Hmm, that's odd it shouldn't be that slow. The basic example completes in under 2 seconds on my machine. I'm using QEMU 10.2.2.

  4. chrisdsloan commented on May 10, 2026

    @chrisdsloan
    Author

    Is there a chance that qemu 10 is enabling kvm by default or something? Because with kvm, it completes in 1.7 seconds for me.

  5. Freax13 commented on May 10, 2026

    @Freax13
    Member

    I don't think so.

    Output without any modifications:
    real 0m1.664s
    user 0m1.574s
    sys 0m0.082s

    Output with -machine accel=tcg:
    real 0m1.685s
    user 0m1.616s
    sys 0m0.063s

    Output with -machine accel=kvm:
    real 0m1.434s
    user 0m0.958s
    sys 0m0.564s

  6. chrisdsloan commented on May 10, 2026

    @chrisdsloan
    Author

    I get an error if I try -machine accel=tag so I'm assuming you meant -machine accel=tcg.

    For me, with no modification or with -machine accel=tcg it doesn't print anything and spins. Presumably if I wait long enough it might print something.

    With -machine accel=kvm I get the same speed as I got with -enable-kvm. Under 2 seconds.

    So, I guess maybe it's a version difference? I don't know a lot about the internals of qemu. My kernel is 6.17.9-76061709-generic if that matters. (This is a Pop!OS 22.04 machine, but largely that's the same as Ubuntu 22.04.)

  7. Freax13 commented on May 10, 2026

    @Freax13
    Member

    Yup, I meant -machine accel=tcg 🙈.

    I can reproduce the issue with QEMU 6.2.0. I'm looking into it.

  8. Freax13 commented on May 10, 2026

    @Freax13
    Member

    The hang seem to be intentional by OVMF because QEMU has a bug: https://edk2.groups.io/g/devel/topic/patch_v3_2_2/96374974. If possible, try updating QEMU, otherwise try -fw_cfg name=opt/org.tianocore/X-Cpuhp-Bugcheck-Override,string=yes.

  9. chrisdsloan commented on May 24, 2026

    @chrisdsloan
    Author

    Sorry for disappearing. I upgraded to:

    QEMU emulator version 9.0.2 (Debian 1:9.0.2+ds-4ubuntu5.4~backport22.04.202506131633~ubuntu22.04.1)
    Copyright (c) 2003-2024 Fabrice Bellard and the QEMU Project developers
    

    Now it works with and without the -enable-kvm argument.

    (In case anyone is curious, I installed qemu from here: https://launchpad.net/~canonical-server/+archive/ubuntu/server-backports .)

    Thanks for the help!

    (Should I close this issue? Or do you want to have it open for any reason?)

  10. Freax13 commented on May 24, 2026

    @Freax13
    Member

    No worries. Considering this isn't something we can fix in the bootloader (OVMF hangs way before the bootloader starts executing), let's close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions