Git Product home page Git Product logo

kvmtool's Introduction

Native Linux KVM tool
=====================

kvmtool is a lightweight tool for hosting KVM guests. As a pure virtualization
tool it only supports guests using the same architecture, though it supports
running 32-bit guests on those 64-bit architectures that allow this.

From the original announcement email:
-------------------------------------------------------
The goal of this tool is to provide a clean, from-scratch, lightweight
KVM host tool implementation that can boot Linux guest images (just a
hobby, won't be big and professional like QEMU) with no BIOS
dependencies and with only the minimal amount of legacy device
emulation.

It's great as a learning tool if you want to get your feet wet in
virtualization land: it's only 5 KLOC of clean C code that can already
boot a guest Linux image.

Right now it can boot a Linux image and provide you output via a serial
console, over the host terminal, i.e. you can use it to boot a guest
Linux image in a terminal or over ssh and log into the guest without
much guest or host side setup work needed.
--------------------------

This is the stand-alone version which does not live inside a Linux
kernel tree.
1. To check it out, clone the main git repository:

  git clone git://git.kernel.org/pub/scm/linux/kernel/git/will/kvmtool.git

2. Compile the tool (for more elaborate instructions see INSTALL):

  cd kvmtool && make

3. Download a raw userspace image:

  wget http://wiki.qemu.org/download/linux-0.2.img.bz2 && bunzip2
linux-0.2.img.bz2

4. The guest kernel has to be built with the following configuration:

 - For the default console output:
	CONFIG_SERIAL_8250=y
	CONFIG_SERIAL_8250_CONSOLE=y

 - For running 32bit images on 64bit hosts:
	CONFIG_IA32_EMULATION=y

 - Proper FS options according to image FS (e.g. CONFIG_EXT2_FS, CONFIG_EXT4_FS).

 - For all virtio devices listed below:
	CONFIG_VIRTIO=y
	CONFIG_VIRTIO_RING=y
	CONFIG_VIRTIO_PCI=y

 - For virtio-blk devices (--disk, -d):
	CONFIG_VIRTIO_BLK=y

 - For virtio-net devices ([--network, -n] virtio):
	CONFIG_VIRTIO_NET=y

 - For virtio-9p devices (--virtio-9p):
	CONFIG_NET_9P=y
	CONFIG_NET_9P_VIRTIO=y
	CONFIG_9P_FS=y

 - For virtio-balloon device (--balloon):
	CONFIG_VIRTIO_BALLOON=y

 - For virtio-console device (--console virtio):
	CONFIG_VIRTIO_CONSOLE=y

 - For virtio-rng device (--rng):
	CONFIG_HW_RANDOM_VIRTIO=y

 - For vesa device (--sdl or --vnc):
	CONFIG_FB_VESA=y


5. And finally, launch the hypervisor:

  ./lkvm run --disk linux-0.2.img \
	    --kernel ../../arch/x86/boot/bzImage \
or

  sudo ./lkvm run --disk linux-0.2.img \
		 --kernel ../../arch/x86/boot/bzImage \
		 --network virtio

The tool has been written by Pekka Enberg, Cyrill Gorcunov, Asias He,
Sasha Levin and Prasad Joshi. Special thanks to Avi Kivity for his help
on KVM internals and Ingo Molnar for all-around support and encouragement!

See the following thread for original discussion for motivation of this
project:

http://thread.gmane.org/gmane.linux.kernel/962051/focus=962620

Another detailed example can be found in the lwn.net article:

http://lwn.net/Articles/658511/

Contributing
------------

Please send patches for kvmtool to [email protected], in the usual git
patch format, including "kvmtool" in the mail subject. "kvmtool" can be
added automatically by issuing the command

 git config format.subjectprefix "PATCH kvmtool"

in the git repository.

Maintainers
-----------

kvmtool is maintained by Will Deacon <[email protected]> and Julien Thierry
<[email protected]>.

kvmtool's People

Contributors

amoskong avatar andre-arm avatar asias avatar avpatel avatar bsingharora avatar cappsule avatar cyrillos avatar daviddaney avatar evansm7 avatar floren avatar gaowanlong avatar hamo avatar jaustin avatar joshtriplett avatar jpbrucker avatar kaga-koko avatar koct9i avatar koukaipan avatar kvaneesh avatar martinradev avatar mpe avatar oleg-nesterov avatar penberg avatar rmurphy-arm avatar sashalevin avatar walimis avatar walken-google avatar wdauchy avatar wildea01 avatar willdeacon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kvmtool's Issues

KVM_CREATE_PIT2

Hello,

kvm.c<x86> reads:

 133 │ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)                                         
 134 │ {                                                                                                                      
 135 │     struct kvm_pit_config pit_config = { .flags = 0, };                                                                
 136 │     int ret;                                                                                                           
 137 │                                                                                                                        
 138 │     ret = ioctl(kvm->vm_fd, KVM_SET_TSS_ADDR, 0xfffbd000);                                                             
 139 │     if (ret < 0)                                                                                                       
 140 │         die_perror("KVM_SET_TSS_ADDR ioctl");                                                                          
 141 │                                                                                                                        
 142 │     ret = ioctl(kvm->vm_fd, KVM_CREATE_PIT2, &pit_config);                                                             
 143 │     if (ret < 0)                                                                                                       
 144 │         die_perror("KVM_CREATE_PIT2 ioctl");                                                                           
 145 │                                                                                                                        
 146 │     if (ram_size < KVM_32BIT_GAP_START) {                                                                              
 147 │         kvm->ram_size = ram_size;                                                                                      
 148 │         kvm->ram_start = mmap_anon_or_hugetlbfs(kvm, hugetlbfs_path, ram_size);                                        
 149 │     } else {                                                                                                           
 150 │         kvm->ram_start = mmap_anon_or_hugetlbfs(kvm, hugetlbfs_path, ram_size + KVM_32BIT_GAP_SIZE);                   
 151 │         kvm->ram_size = ram_size + KVM_32BIT_GAP_SIZE;                                                                 
 152 │         if (kvm->ram_start != MAP_FAILED)                                                                              
 153 │             /*                                                                                                         
 154 │              * We mprotect the gap (see kvm__init_ram() for details) PROT_NONE so that                                 
 155 │              * if we accidently write to it, we will know.                                                             
 156 │              */                                                                                                        
 157 │             mprotect(kvm->ram_start + KVM_32BIT_GAP_START, KVM_32BIT_GAP_SIZE, PROT_NONE);                             
 158 │     }                                                                                                                  
 159 │     if (kvm->ram_start == MAP_FAILED)                                                                                  
 160 │         die("out of memory");                                                                                          
 161 │                                                                                                                        
 162 │     madvise(kvm->ram_start, kvm->ram_size, MADV_MERGEABLE);                                                            
 163 │                                                                                                                        
 164 │     ret = ioctl(kvm->vm_fd, KVM_CREATE_IRQCHIP);                                                                       
 165 │     if (ret < 0)                                                                                                       
 166 │         die_perror("KVM_CREATE_IRQCHIP ioctl");                                                                        
 167 │ }

Interestingly, kernel Documentation/virtual/kvm/api.txt reads:

Capability: KVM_CAP_PIT2
Architectures: x86
Type: vm ioctl
Parameters: struct kvm_pit_config (in)
Returns: 0 on success, -1 on error

Creates an in-kernel device model for the i8254 PIT. This call is only valid
after enabling in-kernel irqchip support via KVM_CREATE_IRQCHIP. The following
parameters have to be passed:

Question: should CREATE_PIT2 be executed after CREATE_IRQCHIP in line 164?

best,
evrim.

linux image vs guest memory size

kvmtool/riscv/kvm.c

Lines 101 to 105 in e17d182

/*
* Linux requires the initrd and dtb to be mapped inside lowmem,
* so we can't just place them at the top of memory.
*/
limit = kvm->ram_start + min(kvm->ram_size, (u64)SZ_256M) - 1;

Might be a noob question, but isn't this line counter-intuitive? If the linux image is large enough (> 256M), then we will fail on the later file read even if we keep increasing guest memory size with -m. At least for me, this was confusing because I kept hitting the same kernel image too big to fit in guest memory. message even when I knew I had allocated enough.

A question about the code in "kvmtool/x86/mptable.c"

Hi, I'm a green hand about kvmtool but I've recently participated in a project related to it.
But when I viewed the underlined file, I found codes as followed.
mpc_intsrc->irqtype = mp_ExtINT;
mpc_intsrc->irqtype = mp_INT;
I have no idea if it's my own misunderstanding or an error. I tried to searched it on Internet, but nothing of much help.
So I'm looking forward to seeking help from developers.

KVM_32BIT_GAP

Hello,

kvm.c<x86> reads:

  80 │ /*                                                                                                                     
  81 │  * Allocating RAM size bigger than 4GB requires us to leave a gap                                                      
  82 │  * in the RAM which is used for PCI MMIO, hotplug, and unconfigured                                                    
  83 │  * devices (see documentation of e820_setup_gap() for details).                                                        
  84 │  *                                                                                                                     
  85 │  * If we're required to initialize RAM bigger than 4GB, we will create                                                 
  86 │  * a gap between 0xe0000000 and 0x100000000 in the guest virtual mem space.                                            
  87 │  */
  88 │ 
  89 │ void kvm__init_ram(struct kvm *kvm)                                                                                    
  90 │ {                                                                                                                      
  91 │     u64 phys_start, phys_size;                                                                                         
  92 │     void    *host_mem;                                   

kvm-arch.h<x86> reads:

   9 │ 
  10 │ /*                                                                                                                     
  11 │  * The hole includes VESA framebuffer and PCI memory.                                                                  
  12 │  */
  13 │ #define KVM_32BIT_MAX_MEM_SIZE  (1ULL << 32)                                      
  14 │ #define KVM_32BIT_GAP_SIZE  (768 << 20)                                       
  15 │ #define KVM_32BIT_GAP_START (KVM_32BIT_MAX_MEM_SIZE - KVM_32BIT_GAP_SIZE) 
  17 │ #define KVM_MMIO_START      KVM_32BIT_GAP_START

Gdb tells:

(gdb) p/x (1ULL << 32) - (768 << 20)
$1 = 0xd0000000

confused ⭕️

best,
evrim.

‘value’may be used uninitialized in this function `kbd_io`

When build with gcc (GCC) 8.4.1, i got a error

hw/i8042.c: In function ‘kbd_io’:
hw/i8042.c:153:19: error: ‘value’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
   state.write_cmd = val;
   ~~~~~~~~~~~~~~~~^~~~~
hw/i8042.c:298:5: note: ‘value’ was declared here
  u8 value;
     ^~~~~
cc1: all warnings being treated as errors

when assigning devices using VFIO allows the guest to have direct access to the device of nvme, nvme0: I/O tag 4 (0004) QID 0 timeout

When SR-IOV capable NVMe PCIe device is passed through to the guest vm using lkvm VFIO functionality (--vfio-pci), "nvme0: I/O tag 4 (0004) QID 0 timeout" is observed.

the following is lkvm cmds and logs.

  • lkvm cmd
lkvm run -m 512 -c1 --console serial -p "console=ttyS0 earlycon" -k Image -d rootfs.ext2 --vfio-pci 0000:00:01.1
  • log
# lspci -v
00:00.0 Non-Volatile memory controller: Red Hat, Inc. QEMU NVM Express Controller (rev 02) (prog-if 02 [NVM Express])
        Subsystem: Red Hat, Inc. Device 1100
        Flags: fast devsel
        Memory at 40000000 (32-bit, non-prefetchable) [size=16K]
        Capabilities: [40] MSI-X: Enable- Count=1 Masked-
        Capabilities: [80] Express Root Complex Integrated Endpoint, MSI 00
  • kernel log
[    1.527082] pci 0000:00:00.0: BAR 0 [mem 0x40000000-0x40003fff]: assigned
[    1.533870] pci 0000:00:01.0: BAR 2 [mem 0x40004000-0x400043ff]: assigned
[    1.541026] pci 0000:00:02.0: BAR 2 [mem 0x40004400-0x400047ff]: assigned
[    1.547329] pci 0000:00:01.0: BAR 0 [io  0x0100-0x01ff]: assigned
[    1.553120] pci 0000:00:01.0: BAR 1 [mem 0x40004800-0x400048ff]: assigned
[    1.559346] pci 0000:00:02.0: BAR 0 [io  0x0200-0x02ff]: assigned
[    1.566536] pci 0000:00:02.0: BAR 1 [mem 0x40004900-0x400049ff]: assigned
[    1.586236] nvme nvme0: pci function 0000:00:00.0
[    1.771708] nvme nvme0: failed to register the CMB
[   62.601763] nvme nvme0: I/O tag 4 (0004) QID 0 timeout, disable controller
[   62.614979] nvme nvme0: Identify Controller failed (-4)
[   62.633939] nvme 0000:00:00.0: probe with driver nvme failed with error -5

But save device behavaves correctly using qemu utils.

The following is logs.

00:01.0 Non-Volatile memory controller: Red Hat, Inc. QEMU NVM Express Controller (rev 02) (prog-if 02 [NVM Express])
        Subsystem: Red Hat, Inc. Device 1100
        Flags: bus master, fast devsel, latency 0
        Memory at 400000000 (64-bit, non-prefetchable) [size=16K]
        Capabilities: [40] MSI-X: Enable+ Count=1 Masked-
        Capabilities: [80] Express Root Complex Integrated Endpoint, MSI 00
        Capabilities: [60] Power Management version 3
        Kernel driver in use: nvme

How can I solve this problem with kvmtool?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.