fimage icon indicating copy to clipboard operation
fimage copied to clipboard

Confusing permission errors really implicate udev issues with /dev/kvm

Open nealmcb opened this issue 3 years ago • 8 comments

Thanks for making it easier to run fushcia!

I was puzzled by a variety of confusing kvm permission errors trying to get configured on Ubuntu 18.04. E.g.

$ ./fimage-headless 2048
...
cannot add library /home/usr/fuchsia/fimage-210528/linux-x64/qemu/linux-x86_64/lib64/vulkan/libvulkan.so: failed
added library /home/usr/fuchsia/fimage-210528/linux-x64/lib64/vulkan/libvulkan.so
cannot add library /home/usr/fuchsia/fimage-210528/linux-x64/lib64/vulkan/libvulkan.so.1: full
Could not access KVM kernel module: Permission denied
qemu-system-x86_64-headless: failed to initialize KVM: Permission denied
./fimage-headless: line 2: 27139 User defined signal 1   linux-x64/emulator -feature VirtioInput,GLDirectMem,VirtioMouse,KVM,Vulkan -window-size 1280x800 -gpu swiftshader_indirect -no-location-ui -no-window -no-hidpi-scaling -fuchsia -kernel default/multiboot.bin -initrd init/fuchsia-ssh.zbi -m $1 -serial stdio -vga none -device virtio-keyboard-pci -smp 4 -device virtio-mouse-pci -machine q35 -device isa-debug-exit,iobase=0xf4,iosize=0x04 -enable-kvm -cpu host,migratable=no,+invtsc -netdev type=tap,ifname=qemu,id=net0,script=scripts/start-unsecure-internet.sh,downscript=no -device virtio-net-pci,vectors=8,netdev=net0,mac=52:54:00:63:5e:7a -drive file=init/fvm_raw.blk,format=raw,if=none,id=vdisk -device virtio-blk-pci,drive=vdisk -append 'TERM=xterm-256color zircon.nodename=fuchsia_fimage kernel.serial=legacy kernel.entropy-mixin=ec98e395c5dd4771931a91dfe7e044a651c3b8b0be2828c8bf6544d151f62e2f kernel.halt-on-panic=false '

I had my account properly set up for kvm, since it tells me that the KVM line in /etc/group should end with ":" followed by your username. and that's true...

That file /home/usr/fuchsia/fimage-210528/linux-x64/lib64/vulkan/libvulkan.so.1 exists, but I don't know what full means in that context and don't see good tips on the web.

That problem turned out to be incorrect permissions on /dev/kvm itself. But note you can't just change the permissions with chmod. You need to configure udev, as described concisely in Gerd's answer at Android Studio: /dev/kvm device permission denied.

Since the error is misleading, it would help to have the shell scripts check for that explicitly and give better hints.

nealmcb avatar Jun 09 '21 20:06 nealmcb

Hey ma dude, did you install qemu-kvm and add your user to the kvm group?

carbonatedcaffeine avatar Jun 09 '21 22:06 carbonatedcaffeine

Cause thats what you need to do to get KVM working correctly.

carbonatedcaffeine avatar Jun 09 '21 22:06 carbonatedcaffeine

If you read the link I pointed to, you'll see that qemu-kvm is not actually required, but the udev rule it includes is required.

nealmcb avatar Jun 09 '21 23:06 nealmcb

The Fuchsia emulator needs KVM. It won't work unless you enable it.

carbonatedcaffeine avatar Jun 10 '21 00:06 carbonatedcaffeine

@EnderNightLord-ChromeBook I think thats understood, the issue here is that Ubunut 18.04 doesnt configure the permissions correctly, although i'm not able to reproduce this, seems to run out of the box on every other system I have.

nmcain avatar Jun 10 '21 00:06 nmcain

I see

carbonatedcaffeine avatar Jun 10 '21 00:06 carbonatedcaffeine

Ahh - linking to this from the README or some other documentation might help people diagnose kvm issues. I found it in Set up and start the Fuchsia emulator (FEMU).

To verify that KVM is configured correctly, run the following command:

if [[ -r /dev/kvm ]] && grep '^flags' /proc/cpuinfo | grep -qE 'vmx|svm'; then echo 'KVM is working'; else echo 'KVM not working'; fi

nealmcb avatar Jun 10 '21 02:06 nealmcb

I'll be sure to implement that command into the documentation.

nmcain avatar Jun 10 '21 02:06 nmcain