Rename kvm-[command] into builtin-[command] to prevent
clashes with non-command files such as kvm-cpu.h
Suggested-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Add a 'kvm version' command which prints the version of the kernel
used to build kvm tools.
Part of the code is based on and was loaned from perf.
Suggested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
"K. Watts" writes:
When the singlestep is enabled the ioctl to sent out when the kvm_cpu
is initialized (kvm-cpu.c in the for loop that gets each vcpu built).
When the ioct goes out the CPU is sitting at the initialization vector
of 0xf000:0xfff0 on CPU #0 and 0x000000 on the other SMP CPUs. The
new host kernel code that handles setting the TF was changed in 2.6.32
and again at 2.6.38. 2.6.32 seems just flat broken, but 2.6.38 checks
that the linear address of the RIP matches what it was when the
KVM_GUESTDBG_SINGLESTEP flag was set. Because the kvm-tool doesn't
start the CPU at the initialization vector (0xfff0) (0x7c00 for the
MBR and where ever you guys map the linux kernel to) they don't match
and the host kernel won't set the trap flag.
Basically the debug and singlestep ioclts need to happen after the CPU
has been initialized. I moved kvm_cpu__enable_singlestep to happen in
kvm_cpu__reset_vcpu after the registers are set (EIP points to boot
address) and the TRAP flags get set and all is good with the world.
Singlestepping is disabled when the guest issues a CLI because the
Linux host doesn't support features in new Intel and AMD CPUs. We can
sort of "shadow" the interrupt mask and still get the CPU to trap out
at ever instruction even when the guest has disabled interrupts on the
CPU. I have to get the bios disk handler working completely first,
but that may be my next task so that we can trace all the CPU
instructions. My current hack is to just re-enable the trap flag
every time a VMEXIT occurs. I get enough instructions to get me by.
This patch fixes the problem by moving the kvm_cpu__enable_singlestep() into
kvm_cpu__start().
Suggested-by: K. Watts <traetox@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This will allow cleaning up ghost pid files outside of the module.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Add a command to allow easily inflate/deflate the balloon driver in running
instances.
Usage:
kvm balloon [command] [instance name] [size]
command is either inflate or deflate, and size is represented in MB.
Target instance must be named (started with '--name').
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
From the virtio spec:
The virtio memory balloon device is a primitive device for managing guest
memory: the device asks for a certain amount of memory, and the guest supplies
it (or withdraws it, if the device has more than it asks for). This allows the
guest to adapt to changes in allowance of underlying physical memory.
To activate the virtio-balloon device run kvm tools with the '--balloon'
command line parameter.
Current implementation listens for two signals:
- SIGKVMADDMEM: Adds 1M to the balloon driver (inflate). This will decrease
available memory within the guest.
- SIGKVMDELMEM: Remove 1M from the balloon driver (deflate). This will
increase available memory within the guest.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This will allow tracking instance names and sending commands
to specific instances if multiple instances are running.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
To allow efficient use of shorter-term threadpool jobs, don't
allocate them dynamically upon creation. Instead, store them
within 'job' structures.
This will prevent some overhead creating/destroying jobs which live
for a short time.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch implement rx interface for uip. uip_rx() can be called in
virtio_net_rx_thread().
It is a consumer of the ethernet used buffer. It sleeps until there is
used buffer avaiable and copy ethernet data into virtio iov buffers
which provided by virtio_net_rx_thread().
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch implement tx interface for uip. uip_tx() can be called in
virtio_net_tx_thread().
It dispatches ethernet frame to ARP or IP handling code.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
- Implement uip_tx_do_ipv4_tcp() to send TCP package to remote host.
- Implement uip_tcp_socket_thread() to receive TCP package from
remote host.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Guest's initial sequence number can be found in the SYN package that
guest send to us to intialize a TCP session.
Remote server's initial sequence number is faked. RFC 793 specifies
that the ISN should be viewed as a 32-bit counter that increments
by one every 4 microseconds. For simplicity's sake, current
implementation in uip just returns a constant.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch adds too helpers uip_tcp_is_syn(), uip_tcp_is_fin() to check if SYN and
FIN bit is set.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
uip_tcp_payload() returns start address of TCP payload in a TCP package.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch adds three helpers uip_tcp_hdrlen(), uip_tcp_len(),
uip_tcp_payloadlen() to return TCP header length, TCP totoal
length, and tcp payload length.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
struct uip_tcp_socket is used to present every session
between guest and remote host.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
- Implement uip_tx_do_ipv4_udp() to send UDP package to remote host.
- Implement uip_udp_socket_thread() to receive UDP package from
remote host.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
struct uip_udp_socket is used to present every "connection" between
guest and remote host.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
- Introduce struct uip_icmp to present ICMP package
- Implement uip_csum_icmp() to calculate ICMP checksum
- Current ICMP implementation in uip does not really send ICMP package
to remote host in question, instead it just fake a ICMP reply to fool guest.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Other protocal, e.g. TCP, UDP, ICMP, can use uip_csum() to make
checsksum as well.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
- Introduce struct uip_ip to present IP package
- Add a helper uip_ip_len() to return totoal length of a IP package
- Add a helper uip_ip_hdrlen() to return the IP header length
- Currently, uip does not support IP options
Drop IP package if IP header length is not 20 bytes which means it
contains IP options.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
- Introduce struct uip_arp to present ARP package
- uip_tx_do_arp()
Clone incoming ARP ethernet frame, if ARP is requesting
host IP address, tell guest host MAC address.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
- uip_buf_get_free()
Get a free buffer from buffer pool, sleep if there is no free buffer.
- uip_buf_get_used()
Get a used buffer from buffer pool, sleep if there is no used buffer.
- uip_buf_set_free()
Set a buffer as free, so it can be reused by the buffer producer.
- uip_buf_set_used()
Set a buffer as used, uip rx code will inject the ethernet frame in
this buffer into guest.
- uip_buf_clone()
Get a free buffer, and clone data into it.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Implement the keyboard reset method which allows guest kernel
to reboot the guest using the keyboard controller.
This will allow guest kernel to reboot the guest when it needs to,
for example - kernel panic (when passing "panic=1" as kernel parameter).
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Framebuffer memory which was mmap() is being free() at the shutdown
of the guest, leading to glibc errors.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch fixes the following nasty 'kvm run' startup problem that's caused by
'long' and 'u64' mixup in the code:
$ ./kvm run
Fatal: out of memory
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Add a command line debug option to add a fix amount of delay in read and
write operation.
From Ingo "the delays are *constant* [make sure you use a high-res timers
kernel], so they do not result in nearly as much measurement noise as real
block IO does.
[...]
This way you are basically 'emulating' a real disk drive but you will
emulate uniform latencies, which makes measurements a lot more
reliable - while still relevant to the end result."
Suggested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch adds a 'kvm debug' command that's currently an alias for
kill -USR2 `pidof kvm`
Which pauses a guest (freezes all VCPU threads) or resumes a paused
guest.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch kills fb_write() and related functions because they're no longer
called as of commit 6768f73 ("kvm tools, vesa: Use guest-mapped memory for
framebuffer").
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: John Floren <john@jfloren.net>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
QCOW uses two tables level1 (L1) table and level2 (L2) table. The L1 table
points to offset of L2 table. When a QCOW image is probed, the L1 table is
cached in the memory to avoid reading it from disk on every access. This
caching improves the performance.
The similar performance improvement can be observed when L2 tables are cached.
It is impossible to cache all of the L2 tables because of the memory
constraint. The patch adds L2 table caching capability for up to 32 L2 tables,
it uses combination of RB tree and List to manage the L2 cached tables. The
link list implementation helps in building simple LRU structure and RB tree
helps to search cached table efficiently.
To calculate the performance numbers, the VM was started with following
command line arguments
$ ./kvm run -d /dev/shm/kvm_ubuntu_server.qcow2 --params "root=/dev/vda1" \
> -m 2048
Without Cache
=============
$ fio fio-mixed.job
[...]
fio-sync: (groupid=3, jobs=1): err= 0: pid=563
read : io=102400KB, bw=31239KB/s, iops=429 , runt= 3278msec
clat (usec): min=4 , max=31668 , avg=1663.94, stdev=1810.37
lat (usec): min=281 , max=658022 , avg=162456.88, stdev=242272.58
bw (KB/s) : min=21536, max=29322, per=20.77%, avg=25956.50, stdev=2755.33
write: io=34688KB, bw=13235KB/s, iops=183 , runt= 2621msec
clat (usec): min=77 , max=1619 , avg=431.80, stdev=343.81
lat (usec): min=78 , max=1620 , avg=433.11, stdev=343.83
bw (KB/s) : min=11168, max=14447, per=26.34%, avg=13246.00, stdev=1293.73
[...]
Run status group 0 (all jobs):
READ: io=409600KB, aggrb=74594KB/s, minb=19096KB/s, maxb=20917KB/s,
mint=5013msec, maxt=5491msec
WRITE: io=139552KB, aggrb=42624KB/s, minb=10263KB/s, maxb=14463KB/s,
mint=2414msec, maxt=3274msec
Run status group 1 (all jobs):
READ: io=409600KB, aggrb=146442KB/s, minb=37489KB/s, maxb=48680KB/s,
mint=2154msec, maxt=2797msec
WRITE: io=133296KB, aggrb=59613KB/s, minb=15328KB/s, maxb=16774KB/s,
mint=2041msec, maxt=2236msec
Run status group 2 (all jobs):
READ: io=409600KB, aggrb=7178KB/s, minb=1837KB/s, maxb=1840KB/s,
mint=56961msec, maxt=57057msec
WRITE: io=139136KB, aggrb=2446KB/s, minb=600KB/s, maxb=661KB/s,
mint=56238msec, maxt=56880msec
Run status group 3 (all jobs):
READ: io=409600KB, aggrb=124954KB/s, minb=31988KB/s, maxb=37704KB/s,
mint=2781msec, maxt=3278msec
WRITE: io=137936KB, aggrb=50286KB/s, minb=12447KB/s, maxb=13885KB/s,
mint=2621msec, maxt=2743msec
Disk stats (read/write):
vda: ios=118760/16273, merge=0/107354, ticks=159260/658290, in_queue=817410,
util=94.37%
[...]
With Cache
==========
$ fio fio-mixed.job
[...]
fio-sync: (groupid=3, jobs=1): err= 0: pid=573
read : io=102400KB, bw=76704KB/s, iops=1018 , runt= 1335msec
clat (usec): min=0 , max=66131 , avg=591.46, stdev=2582.59
lat (usec): min=66 , max=123396 , avg=25609.49, stdev=38397.57
bw (KB/s) : min=58208, max=59584, per=34.55%, avg=58896.00, stdev=972.98
write: io=35600KB, bw=29373KB/s, iops=381 , runt= 1212msec
clat (usec): min=11 , max=2661 , avg=169.58, stdev=191.60
lat (usec): min=11 , max=2663 , avg=170.91, stdev=191.78
bw (KB/s) : min=27104, max=37664, per=29.98%, avg=32384.00, stdev=7467.05
[...]
Run status group 0 (all jobs):
READ: io=409600KB, aggrb=140562KB/s, minb=35984KB/s, maxb=44450KB/s,
mint=2359msec, maxt=2914msec
WRITE: io=138816KB, aggrb=124722KB/s, minb=31502KB/s, maxb=40180KB/s,
mint=893msec, maxt=1113msec
Run status group 1 (all jobs):
READ: io=409600KB, aggrb=231151KB/s, minb=59174KB/s, maxb=96111KB/s,
mint=1091msec, maxt=1772msec
WRITE: io=141936KB, aggrb=137268KB/s, minb=32340KB/s, maxb=44496KB/s,
mint=813msec, maxt=1034msec
Run status group 2 (all jobs):
READ: io=409600KB, aggrb=9211KB/s, minb=2358KB/s, maxb=2363KB/s,
mint=44367msec, maxt=44468msec
WRITE: io=129808KB, aggrb=2931KB/s, minb=707KB/s, maxb=797KB/s,
mint=43331msec, maxt=44285msec
Run status group 3 (all jobs):
READ: io=409600KB, aggrb=170453KB/s, minb=43636KB/s, maxb=78545KB/s,
mint=1335msec, maxt=2403msec
WRITE: io=138256KB, aggrb=108012KB/s, minb=27648KB/s, maxb=37931KB/s,
mint=879msec, maxt=1280msec
Disk stats (read/write):
vda: ios=120698/16690, merge=0/114742, ticks=113170/304480, in_queue=417560,
util=93.26%
[...]
Summary
=======
Read bandwidth increased by 1.2 to 1.8 times
Write bandwidth increased by 1.1 to 2.9 times
Read latency decreased by small margin of 0.2
Write latency decreased by 0.4
Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch converts hw/vesa.c to use guest-mapped memory for framebuffer and
drops the slow MMIO emulation. This speeds up framebuffer accesses
considerably. Please note that this can be optimized even more with the
KVM_GET_DIRTY_LOG ioctl() as explained by Alexander Graf.
Cc: Alexander Graf <agraf@suse.de>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: John Floren <john@jfloren.net>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Coalescing MMIO allows us to avoid an exit every time we have a
MMIO write, instead - MMIO writes are coalesced in a ring which
can be flushed once an exit for a different reason is needed.
A MMIO exit is also trigged once the ring is full.
Coalesce all MMIO regions registered in the MMIO mapper.
Add a coalescing handler under kvm_cpu.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>