Enable ''-enable-kvm" flag by default - qemu

My laptop support hardware virtualization & enabled in bios & i am trying to compile qemu from source. So Is it possible to compile qemu in a way that i do not enter "-enable-kvm" flage from command line every time?

You could try passing configure --disable-tcg, which will disable the CPU emulation entirely (this only works for some target architectures like x86 at the moment). Then I think QEMU will default to KVM as the only available accelerator.
Alternatively if you rename your executable to something whose name ends with "kvm" then QEMU will default to the KVM accelerator rather than TCG. (I think a hardlink or maybe even a symlink to the binary will also work as well as simply renaming it, but haven't tested this.)

Related

Qemu Virt Machine from flash device image

I have been developing the OS for a prototype device using hardware. Unfortunately, it's a very manual and buggy process to flash the OS each time and then debug the issues.
I'd like to switch to developing the OS in QEMU, so that I can be sure that the OS is loading correctly before going through the faff of programming the device for real. This will come in handy later for Continuous Integration work.
I have a full copy of the NVM device that is generated from my build process. This is a known working image I'd like to run in QEMU as a start point. This is ready to then be JTAG'd onto the device. The partition layout is:
P0 - loader - Flash of IDBLoader from rockchip loader binaries
P1 - Uboot - Flash of Uboot
P2 - trust - Flash of Trust image for rockchip specific loader
P3 - / - Root partition with Debian based image and packages required for application
P4 - data partition - Application Data
I have not changed anything with the Rockchip partitions (P0 - P2) apart from the serial console settings. When trying to boot the image though, nothing happens. There is no output at all, but the VM shows as still running. I use the following command to run it:
qemu-system-aarch64 -machine virt -cpu cortex-a53 \
-kernel u-boot-nodtb.bin \
-drive format=raw,file=image.img \
-boot c -serial stdio
I have no error information to go on to understand what is going on with it, where can I get more information or debug?
QEMU cannot not emulate arbitrary hardware. You will have to compile U-Boot to match the hardware that QEMU emulates, e.g. using make qemu_arm64_defconfig. The OS must also provide drivers for QEMU's emulated hardware.
If you want to emulate the complete hardware to debug drivers, Renode (https://renode.io/) is a good choice.
For anyone else trying to figure this out, I found good resources here:
https://translatedcode.wordpress.com/2017/07/24/installing-debian-on-qemus-64-bit-arm-virt-board/
and
https://azeria-labs.com/emulate-raspberry-pi-with-qemu/
Looking at the information though, you need to extract the kernel from your image and provide that to the qemu command line as an argument. You'll also need to append an argument telling the system which partition to use as a root drive.
My final command line for starting the machine looks like this:
qemu-system-aarch64 -machine virt -cpu cortex-a53 \
-drive format=raw,file=image.img,id=hd \
-boot c -serial stdio
-kernel <kernelextracted> -append "root=fe04"
Different Arm boards can be significantly different from one another in where they put their hardware, including where they put basic hardware required for bootup (UART, RAM, interrupt controller, etc). It is therefore pretty much expected that if you take a piece of low-level software like u-boot or a Linux kernel that was compiled to run on one board and try to run it on a different one that it will fail to boot. Generally it won't be able to output anything because it won't even have been able to find the UART. (Linux kernels can be compiled to be generic and include drivers for a wider variety of hardware, so if you have that sort of kernel it can be booted on a different board type: it will use a device tree blob, provided either by you or autogenerated by QEMU for the 'virt' board, to figure out what hardware it's running on and adapt to it. But kernels compiled for a specific embedded target are often built with only the device drivers they need, and that kind of kernel can't boot on a different system.)
There are broadly speaking two paths you can take:
(1) build the guest for the board you're emulating (here the 'virt' one). u-boot and Linux both have support for QEMU's 'virt' board. This may or may not be useful for what you're trying to do -- you would be able to test any userspace level code that doesn't care what hardware it runs on, but obviously not anything that's specific to the real hardware you're targeting.
(2) In theory you could add emulation support to QEMU for the hardware you're trying to run on. However this is generally a fair amount of work and isn't trivial if you're not already familiar with QEMU internals. I usually ballpark estimate it as "about as much work as it would take to port the kernel to the hardware"; though it depends a bit on how much functionality you/your guest need to have working, and whether QEMU already has a model of the SoC your hardware is using.
To answer the general "what's the best way to debug a guest image that doesn't boot", the best thing is usually to connect an arm-aware gdb to QEMU's gdbstub. This gives you debug access broadly similar to a JTAG debug connection to real hardware and is probably sufficient to let you find out where the guest is crashing. QEMU also has some debug logging options under the '-d' option, although the logging is partially intended to assist in debugging problems within QEMU itself and can be a bit tricky to interpret.

QEMU Monitor on Windows 10

I'm Ronaldo, Newbie of Stackoverflow.
I'm having a problem, On my PC it's running Windows 10 Build 1803, Then I installed QEMU, but not only that, I installed the graphical version which is QtEmu.
Then I wanted to virtualize CentOS 3.1, with Disk 1, Disk 2 and Disk 3. But I don't know how to eject the disk in QtEmu, I tried it in PowerShell and I couldn't, not even in CMD, just the serial0, and the keyboard is not works, only on the PC that works. the Mouse is ok. But QEMU Monitor is out of QtEmu! Is there any way to install QEMU Monitor on Windows, with QtEmu?
Please help me!
QEMU can be started with option "-monitor" so you can send commands to it there. I never used QtEmu so not sure how it starts QEMU. If you figure out how, check out https://qemu.weilnetz.de/w64/2012/2012-08-24/qemu-doc.html#pcsys_005fmonitor.
So basically, you can use "change" command to mount and unmount a CD drive or other storage devices. For example, "change ide1-cd0 /tmp/file.iso" to mount an image file. The device names are not fixed across different VM configurations. "info block" can tell you what name you need to use.
sorry i just discovered QEMU, it's far now, but it can help people in the future.
I dislike QTEmu and others IHM, too much bugs currently (2022)..
With QEMU
default mode: you can directly have an access with the window, go to view and you can switch by clicking on "compat monitor 0" . You can also detach the monitor.
sdl: ctrl+alt 2.
Here:
Identify your devices by "info block"
As you can see here, i ran without anything (it's just to show).
To change/add content of your cd-rom, "Change "
here my device is "ide1-cd0"
Path can be your physical or virtual drive, a disk image, you can always swap according your needs.
As you can see now, i use "R:", a virtual device from a software like daemon tools (an alt).
I think it's better, before to swap, to eject from the guest... But perhaps
it depends of your OS. For the while i used it, the most of time, with win98x.

qemu-system-aarch64 exit from within the guest system

I was wondering if there is a way to exit from qemu from within the guest system in the aarch64 version. For instance the x86 has the isa-debug-exit device which is used for this purpose.
Any ideas?
Cheers
The general answer to this question is "do whatever you would do on the real hardware to cause a power-off". The details of this depend on which machine QEMU is emulating. For the aarch64 "virt" board, you can use the emulated PSCI firmware interface to request a powerdown using the SYSTEM_OFF function.
The PSCI API documentation is here: http://infocenter.arm.com/help/topic/com.arm.doc.den0022d/Power_State_Coordination_Interface_PDD_v1_1_DEN0022D.pdf
For debug/test purposes you might also be interested in the semihosting API (https://developer.arm.com/docs/dui0003/b) which has a SYS_EXIT function, but some caveats: for QEMU you can only use semihosting if you enable it via the -semihosting commandline argument, and only from kernel mode in the guest, and you must only use it if you absolutely trust the guest code, because it provides access to functions that allow the guest to read and write any host file. But for explicitly trusted small test programs it can be a nice way to do easy debug printing and exit with a given exit status.

What's the difference between "arm-linux-user" and "armeb-linux-user"?

When compile QEMU from source code, I find in file configure, option --target-list supports arm-linux-user and **armeb-linux-user". I know xx-linux-user is for User Emulation. What is the difference between "arm-linux-user" and "armeb-linux-user"?
armeb-linux-user is for big-endian Linux ARM binaries, and arm-linux-user is for little-endian ARM binaries. If you don't know you want big-endian then you don't want it. (The usual setup for user-mode QEMU uses the host-kernel's binfmt-misc support so it can automatically pick the right -linux-user QEMU binary to run for the guest executable anyway.)

setting cudaDeviceProperty: cudaKernelExecTimeoutEnabled

Is it possible to set the device property cudaKernelExecTimeoutEnabled to 0 at runtime? Currently it is 1 because I'm also running an X-server on it. The problem is, that my threads time out.
On Linux, you can disable the timeout (about 6 to 7 seconds for me) by adding an option to your X11 configuration. On modern Linux systems, there is no X11 configuration any more, everything is autodetected, but you can create it manually:
mkdir -p /etc/X11/xorg.conf.d
touch /etc/X11/xorg.conf.d/20-nvidia.conf
Then add the following into this file:
Section "Device"
Identifier "My GPU"
Driver "nvidia"
Option "Interactive" "0"
EndSection
The key here is the "Interactive" option. This works for me even without X11 restart. It was obvious that this configuration is read and applied as soon as my OpenCL application is started.
"Identifier" can be an arbitrary value. "Driver" is "nvidia" in my case, since I'm using the proprietary Nvidia driver for Linux (part of the official Debian package repositories).
I am assuming you are on windows:
You need to disable the windows driver timeout:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Watchdog\Display\DisableBugCheck
create a REG_DWORD and set it to 1.
On Linux, you need to use the nvidia-smi command to change properties of the device. But I think if you're running a display on the GPU, you might not be able to set that property.