unikraft / kraftkit

Build and use highly customized and ultra-lightweight unikernel VMs.
https://unikraft.org/docs/cli
BSD 3-Clause "New" or "Revised" License
234 stars 62 forks source link

Kraft run not working on WSL #836

Closed BJhutti closed 8 months ago

BJhutti commented 1 year ago

Describe the bug

On WSL, Ubuntu version 22.04, Windows 10, the following error occurs when kraft run is ran after kraft build in the /helloworld folder:

could not open kvm device: open /dev/kvm: no such device

note2: did not work with -W

note: the application still runs correctly when using the command: /usr/bin/qemu-system-x86_64 -kernel build/helloworld_qemu-x86_64 -nographic

Steps to reproduce

kraft build kraft run

Expected behavior

The console should print:


SeaBIOS (version 1.15.0-1)

iPXE (https://ipxe.org) 00:03.0 CA00 PCI2.10 PnP PMM+07F8B340+07ECB340 CA00

Booting from ROM..Powered by
o.   .o       _ _               __ _
Oo   Oo  ___ (_) | __ __  __ _ ' _) :_
oO   oO ' _ `| | |/ /  _)' _` | |_|  _)
oOo oOO| | | | |   (| | | (_) |  _) :_
 OoOoO ._, ._:_:_,\_._,  .__,_:_, \___)
             Prometheus 0.14.0~018fe1a4
Hello world!
Arguments:  "build/helloworld_qemu-x86_64"

Which architectures were you using or does this bug affect?

x86_64

Which operating system were you using or does this bug affect?

windows

Relevant log output

could not open kvm device: open /dev/kvm: no such device
razvand commented 1 year ago

@Opsine02 , please also use coding style formatting for the Expected behavior section.

BJhutti commented 1 year ago

Updated

razvand commented 1 year ago

@Opsine02 , thanks, 5HP.

craciunoiuc commented 1 year ago

So running with -W causes the same error to occur?

craciunoiuc commented 1 year ago

using -W should basically default to the command you listed

BJhutti commented 1 year ago

Yes, it does not work with -W

craciunoiuc commented 12 months ago

Adding you @antoineco. Maybe you can do some checks. Installing WSL on my PC is usually a hassle :sweat:

antoineco commented 12 months ago

@BJhutti Windows 10 doesn't have nested virtualization enabled in WSL2, only Windows 11 does.

craciunoiuc commented 12 months ago

But any idea why it doesn't work with -W either? I wasn't expecting it to work with kvm anyways

antoineco commented 12 months ago

@craciunoiuc I remember we had another issue open regarding the detection logic trying to be smart, and failing at correctly being able to determine whether userspace or KVM should be used. I'm not sure where that issue is unfortunately.

craciunoiuc commented 12 months ago

Yeah, I also remember something related to that, but it was more in the kvm direction. Right now it goes as deep as communicating with kvm to see if it reports issues.

Here the error reported gives me a hunch that /dev/kvm exists but is not actually a device, but a regular file, or something else:


    file = hostDev("kvm")
    if pathExists(file) {
        if kvmFile, err := os.Stat(file); err == nil &&
            kvmFile.Mode()&os.ModeCharDevice != 0 {
            // Send ioctl for KVM_GET_API_VERSION
            file, err := os.Open(file)
            if err != nil {
                return PlatformUnknown, SystemUnknown, fmt.Errorf("could not open kvm device: %w", err)
            }
            defer file.Close()
                        // [...]

You can see here that the path is first checked if it exists, then it is checked if it is a char device. If both true then it tries to open it to write to the device, and that is when it fails.

craciunoiuc commented 12 months ago

Ah yes, I know why this happens with -W also, here is a snippet:

        if opts.platform == "" {
            opts.platform, _, err = platform.Detect(ctx)
            if err != nil {
                return fmt.Errorf("could not get host platform: %w", err)
            }
        }

Basically if the platform is not specified it will try to autodetect, and that is when it fails. @BJhutti you probably ran kraft run -W with no target and it tried to autodetect what to run.

craciunoiuc commented 12 months ago

We have 3 options:

  1. Assume qemu when -W is specified (only one with no-acceleration options)
  2. Investigate further why the /dev/kvm file exists in WSL Win10, but can't be opened.
  3. Consider this issue actually a feature

@antoineco what do you think

antoineco commented 12 months ago

I'd say we should add a check on the file type of the device, to allow other checks to be performed in case the file is not a device?

craciunoiuc commented 12 months ago

There are checks already, you can see that it checks if the file is a charDevice, which somehow it passes

craciunoiuc commented 8 months ago

@antoineco can you check if this still happens? :pray:

antoineco commented 8 months ago

I unfortunately don't have access to Windows 10, but on Windows 11 both modes work:

% kraft run
 W  specification in Kraftfile (v0.5) version is not latest (v0.6)
 W  specification in Kraftfile (v0.5) version is not latest (v0.6)
o.   .o       _ _               __ _
Oo   Oo  ___ (_) | __ __  __ _ ' _) :_
oO   oO ' _ `| | |/ /  _)' _` | |_|  _)
oOo oOO| | | | |   (| | | (_) |  _) :_
 OoOoO ._, ._:_:_,\_._,  .__,_:_, \___)
                 Telesto 0.16.2~86710f6
Hello world!
Arguments:  "/home/acotten/git/unikraft/app-helloworld/.unikraft/build/helloworld_qemu-x86_64"
% kraft run --disable-acceleration
 W  specification in Kraftfile (v0.5) version is not latest (v0.6)
 W  specification in Kraftfile (v0.5) version is not latest (v0.6)
o.   .o       _ _               __ _
Oo   Oo  ___ (_) | __ __  __ _ ' _) :_
oO   oO ' _ `| | |/ /  _)' _` | |_|  _)
oOo oOO| | | | |   (| | | (_) |  _) :_
 OoOoO ._, ._:_:_,\_._,  .__,_:_, \___)
                 Telesto 0.16.2~86710f6
Hello world!
Arguments:  "/home/acotten/git/unikraft/app-helloworld/.unikraft/build/helloworld_qemu-x86_64"
antoineco commented 8 months ago

With nestedVirtualization=false (notice the warning "using hardware emulation"):

% kraft run
 W  using hardware emulation
 W  specification in Kraftfile (v0.5) version is not latest (v0.6)
 W  specification in Kraftfile (v0.5) version is not latest (v0.6)
o.   .o       _ _               __ _
Oo   Oo  ___ (_) | __ __  __ _ ' _) :_
oO   oO ' _ `| | |/ /  _)' _` | |_|  _)
oOo oOO| | | | |   (| | | (_) |  _) :_
 OoOoO ._, ._:_:_,\_._,  .__,_:_, \___)
                 Telesto 0.16.2~86710f6
Hello world!
Arguments:  "/home/acotten/git/unikraft/app-helloworld/.unikraft/build/helloworld_qemu-x86_64"
% kraft run --disable-acceleration
 W  using hardware emulation
 W  specification in Kraftfile (v0.5) version is not latest (v0.6)
 W  specification in Kraftfile (v0.5) version is not latest (v0.6)
o.   .o       _ _               __ _
Oo   Oo  ___ (_) | __ __  __ _ ' _) :_
oO   oO ' _ `| | |/ /  _)' _` | |_|  _)
oOo oOO| | | | |   (| | | (_) |  _) :_
 OoOoO ._, ._:_:_,\_._,  .__,_:_, \___)
                 Telesto 0.16.2~86710f6
Hello world!
Arguments:  "/home/acotten/git/unikraft/app-helloworld/.unikraft/build/helloworld_qemu-x86_64"

Considering the issue resolved. Feel free to reopen if this is not the case on the latest released version of KraftKit.