vhost-user: add migration support
v6 cover vhost-user: add migration support
From: Marc-André Lureau <[email protected]>
Hi,
The following series implement shareable log for vhost-user to support memory tracking during live migration. On qemu-side, the solution is fairly straightfoward since vhost already supports the dirty log, only vhost-user couldn't access the log memory until then.
The series includes "vhost user: Add live migration" patches from Thibaut Collet.
v5->v6:
- rebased
- fix protocol feature mask update
- add a patch from Thibault Collet using enum for features, and compute mask
- add unistd.h linux headers to help building memfd if missing on build host. Hopefully will be useful for other syscalls some day
- reorder/merge patches to share-allocate the log only if needed
- split the memfd helper to allow to drop the fallback code
- allow to call qemu_memfd_free() even if alloc failed
- add some missing spaces
v4->v5:
- rebase on top of last Michael S. Tsirkin PULL request
- block live migration if !PROTOCOL_F_LOG_SHMFD
- wait for a reply after SET_LOG_BASE
- split vhost_set_log_base from the rest of vhost_call refactoring
- use a seperate global vhost_log_shm
v3->v4:
- add the proto negotiation & the migration series
- replace the varargs vhost_call() approach for callbacks
- only share-allocate when the backend needs it
v2->v3:
- changed some patch summary
- added migration tests
- added a patch to replace error message with a trace
The development branch I used is:
https://github.com/elmarco/qemu branch "vhost-user"
Marc-André Lureau (20):
configure: probe for memfd
linux-headers: add unistd.h
util: add linux-only memfd fallback
util: add memfd helpers
memfd: add fallback for memfd
vhost: document log resizing
vhost: add vhost_set_log_base op
vhost-user: add vhost_user_requires_shm_log()
vhost: alloc shareable log
vhost-user: send log shm fd along with log_base
vhost-user: add a migration blocker
vhost: use a function for each call
vhost-user: document migration log
net: add trace_vhost_user_event
vhost-user-test: move wait_for_fds() out
vhost-user-test: remove useless static check
vhost-user-test: wrap server in TestServer struct
vhost-user-test: learn to tweak various qemu arguments
vhost-user-test: add live-migration test
vhost-user-test: check ownership during migration
Michael S. Tsirkin (1):
vhost-user: unit test for new messages
Thibaut Collet (3):
vhost user: add support of live migration
vhost user: add rarp sending after live migration for legacy guest
vhost-user: use an enum helper for features mask
configure | 19 + docs/specs/vhost-user.txt | 63 ++- hw/net/vhost_net.c | 35 +- hw/scsi/vhost-scsi.c | 7 +- hw/virtio/vhost-backend.c | 121 +++- hw/virtio/vhost-user.c | 576 ++++++++++++------- hw/virtio/vhost.c | 102 ++-- include/hw/virtio/vhost-backend.h | 77 ++- include/hw/virtio/vhost.h | 15 +- include/net/vhost_net.h | 1 + include/qemu/memfd.h | 24 + linux-headers/asm-arm/unistd.h | 448 +++++++++++++++ linux-headers/asm-arm64/kvm.h | 37 +- linux-headers/asm-arm64/unistd.h | 16 + linux-headers/asm-mips/unistd.h | 1063 ++++++++++++++++++++++++++++++++++++ linux-headers/asm-powerpc/unistd.h | 392 +++++++++++++ linux-headers/asm-s390/unistd.h | 404 ++++++++++++++ linux-headers/asm-x86/unistd.h | 15 + linux-headers/asm-x86/unistd_32.h | 377 +++++++++++++ linux-headers/asm-x86/unistd_64.h | 330 +++++++++++ linux-headers/asm-x86/unistd_x32.h | 319 +++++++++++ net/vhost-user.c | 34 +- scripts/update-linux-headers.sh | 7 +- tests/vhost-user-test.c | 390 +++++++++++-- trace-events | 3 + util/Makefile.objs | 2 +- util/memfd.c | 129 +++++ 27 files changed, 4673 insertions(+), 333 deletions(-) create mode 100644 include/qemu/memfd.h create mode 100644 linux-headers/asm-arm/unistd.h create mode 100644 linux-headers/asm-arm64/unistd.h create mode 100644 linux-headers/asm-mips/unistd.h create mode 100644 linux-headers/asm-powerpc/unistd.h create mode 100644 linux-headers/asm-s390/unistd.h create mode 100644 linux-headers/asm-x86/unistd.h create mode 100644 linux-headers/asm-x86/unistd_32.h create mode 100644 linux-headers/asm-x86/unistd_64.h create mode 100644 linux-headers/asm-x86/unistd_x32.h create mode 100644 util/memfd.c
Signature · 1 line
2.4.3
PATCH v6 1/24 vhost-user: unit test for new messages
From: "Michael S. Tsirkin" <[email protected]>
Data is empty for now, but do make sure master
sets the new feature bit flag.
--- tests/vhost-user-test.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
tests/vhost-user-test.c +19 -0
@@ -53,6 +53,8 @@#define VHOST_MEMORY_MAX_NREGIONS 8 +#define VHOST_USER_F_PROTOCOL_FEATURES 30 + typedef enum VhostUserRequest { VHOST_USER_NONE = 0, VHOST_USER_GET_FEATURES = 1,
@@ -69,6 +71,8 @@ typedef enum VhostUserRequest {VHOST_USER_SET_VRING_KICK =12 ,VHOST_USER_SET_VRING_CALL =13 ,VHOST_USER_SET_VRING_ERR =14 , +VHOST_USER_GET_PROTOCOL_FEATURES =15 , +VHOST_USER_SET_PROTOCOL_FEATURES =16 , VHOST_USER_MAX } VhostUserRequest;
@@ -293,11 +297,26 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)/* send back features to qemu */ msg.flags |=VHOST_USER_REPLY_MASK ; msg.size =sizeof (m.u64); + msg.u64 =0x1ULL <<VHOST_USER_F_PROTOCOL_FEATURES ; + p = (uint8_t *) &msg; +qemu_chr_fe_write_all (chr, p,VHOST_USER_HDR_SIZE + msg.size); +break ; + +case VHOST_USER_SET_FEATURES : +g_assert_cmpint (msg.u64 & (0x1ULL <<VHOST_USER_F_PROTOCOL_FEATURES ), + !=, 0ULL); +break ; + +case VHOST_USER_GET_PROTOCOL_FEATURES : +/* send back features to qemu */ + msg.flags |=VHOST_USER_REPLY_MASK ; + msg.size =sizeof (m.u64); msg.u64 =0 ; p = (uint8_t *) &msg;qemu_chr_fe_write_all (chr, p,VHOST_USER_HDR_SIZE + msg.size);break ; +case VHOST_USER_GET_VRING_BASE :/* send back vring base to qemu */ msg.flags |=VHOST_USER_REPLY_MASK ;
Signature · 1 line
2.4.3
PATCH v6 2/24 configure: probe for memfd
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Check if memfd_create() is part of system libc.
--- configure | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
configure +19 -0
@@ -3486,6 +3486,22 @@ if compile_prog "" "" ; then eventfd=yes fi +# check if memfd is supported +memfd=no +cat > $TMPC << EOF +#include <sys/memfd.h> + +int main(void) +{ + return memfd_create("foo", MFD_ALLOW_SEALING); +} +EOF +if compile_prog "" "" ; then + memfd=yes +fi + + + # check for fallocate fallocate=no cat > $TMPC << EOF
@@ -4857,6 +4873,9 @@ fi if test "$eventfd" = "yes" ; then echo "CONFIG_EVENTFD=y" >> $config_host_mak fi +if test "$memfd" = "yes" ; then + echo "CONFIG_MEMFD=y" >> $config_host_mak +fi if test "$fallocate" = "yes" ; then echo "CONFIG_FALLOCATE=y" >> $config_host_mak fi
Signature · 1 line
2.4.3
PATCH v6 3/24 linux-headers: add unistd.h
In reply to [email protected]From: Marc-André Lureau <[email protected]>
New syscalls are not yet widely distributed. Add them to qemu linux-headers include directory. Update based on v4.3-rc3 kernel headers.
Exclude mips for now, which is more problematic due to extra header inclusion and probably unnecessary here.
--- linux-headers/asm-arm/unistd.h | 448 +++++++++++++++ linux-headers/asm-arm64/kvm.h | 37 +- linux-headers/asm-arm64/unistd.h | 16 + linux-headers/asm-mips/unistd.h | 1063 ++++++++++++++++++++++++++++++++++++ linux-headers/asm-powerpc/unistd.h | 392 +++++++++++++ linux-headers/asm-s390/unistd.h | 404 ++++++++++++++ linux-headers/asm-x86/unistd.h | 15 + linux-headers/asm-x86/unistd_32.h | 377 +++++++++++++ linux-headers/asm-x86/unistd_64.h | 330 +++++++++++ linux-headers/asm-x86/unistd_x32.h | 319 +++++++++++ scripts/update-linux-headers.sh | 7 +- 11 files changed, 3404 insertions(+), 4 deletions(-) create mode 100644 linux-headers/asm-arm/unistd.h create mode 100644 linux-headers/asm-arm64/unistd.h create mode 100644 linux-headers/asm-mips/unistd.h create mode 100644 linux-headers/asm-powerpc/unistd.h create mode 100644 linux-headers/asm-s390/unistd.h create mode 100644 linux-headers/asm-x86/unistd.h create mode 100644 linux-headers/asm-x86/unistd_32.h create mode 100644 linux-headers/asm-x86/unistd_64.h create mode 100644 linux-headers/asm-x86/unistd_x32.h
linux-headers/asm-arm/unistd.h new file +448 -0
@@ -0,0 +1,448 @@ +/* +* arch/arm/include/asm/unistd.h +* +* Copyright (C) 2001-2005 Russell King +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* Please forward _all_ changes to this file to [email protected], +* no matter what the change is. Thanks! +*/ +#ifndef __ASM_ARM_UNISTD_H +#define __ASM_ARM_UNISTD_H + +#define __NR_OABI_SYSCALL_BASE 0x900000 + +#if defined(__thumb__) || defined(__ARM_EABI__) +#define __NR_SYSCALL_BASE 0 +#else +#define __NR_SYSCALL_BASE __NR_OABI_SYSCALL_BASE +#endif + +/* +* This file contains the system call numbers. +*/ + +#define __NR_restart_syscall (__NR_SYSCALL_BASE+ 0) +#define __NR_exit (__NR_SYSCALL_BASE+ 1) +#define __NR_fork (__NR_SYSCALL_BASE+ 2) +#define __NR_read (__NR_SYSCALL_BASE+ 3) +#define __NR_write (__NR_SYSCALL_BASE+ 4) +#define __NR_open (__NR_SYSCALL_BASE+ 5) +#define __NR_close (__NR_SYSCALL_BASE+ 6) +/* 7 was sys_waitpid */ +#define __NR_creat (__NR_SYSCALL_BASE+ 8) +#define __NR_link (__NR_SYSCALL_BASE+ 9) +#define __NR_unlink (__NR_SYSCALL_BASE+ 10) +#define __NR_execve (__NR_SYSCALL_BASE+ 11) +#define __NR_chdir (__NR_SYSCALL_BASE+ 12) +#define __NR_time (__NR_SYSCALL_BASE+ 13) +#define __NR_mknod (__NR_SYSCALL_BASE+ 14) +#define __NR_chmod (__NR_SYSCALL_BASE+ 15) +#define __NR_lchown (__NR_SYSCALL_BASE+ 16) +/* 17 was sys_break */ +/* 18 was sys_stat */ +#define __NR_lseek (__NR_SYSCALL_BASE+ 19) +#define __NR_getpid (__NR_SYSCALL_BASE+ 20) +#define __NR_mount (__NR_SYSCALL_BASE+ 21) +#define __NR_umount (__NR_SYSCALL_BASE+ 22) +#define __NR_setuid (__NR_SYSCALL_BASE+ 23) +#define __NR_getuid (__NR_SYSCALL_BASE+ 24) +#define __NR_stime (__NR_SYSCALL_BASE+ 25) +#define __NR_ptrace (__NR_SYSCALL_BASE+ 26) +#define __NR_alarm (__NR_SYSCALL_BASE+ 27) +/* 28 was sys_fstat */ +#define __NR_pause (__NR_SYSCALL_BASE+ 29) +#define __NR_utime (__NR_SYSCALL_BASE+ 30) +/* 31 was sys_stty */ +/* 32 was sys_gtty */ +#define __NR_access (__NR_SYSCALL_BASE+ 33) +#define __NR_nice (__NR_SYSCALL_BASE+ 34) +/* 35 was sys_ftime */ +#define __NR_sync (__NR_SYSCALL_BASE+ 36) +#define __NR_kill (__NR_SYSCALL_BASE+ 37) +#define __NR_rename (__NR_SYSCALL_BASE+ 38) +#define __NR_mkdir (__NR_SYSCALL_BASE+ 39) +#define __NR_rmdir (__NR_SYSCALL_BASE+ 40) +#define __NR_dup (__NR_SYSCALL_BASE+ 41) +#define __NR_pipe (__NR_SYSCALL_BASE+ 42) +#define __NR_times (__NR_SYSCALL_BASE+ 43) +/* 44 was sys_prof */ +#define __NR_brk (__NR_SYSCALL_BASE+ 45) +#define __NR_setgid (__NR_SYSCALL_BASE+ 46) +#define __NR_getgid (__NR_SYSCALL_BASE+ 47) +/* 48 was sys_signal */ +#define __NR_geteuid (__NR_SYSCALL_BASE+ 49) +#define __NR_getegid (__NR_SYSCALL_BASE+ 50) +#define __NR_acct (__NR_SYSCALL_BASE+ 51) +#define __NR_umount2 (__NR_SYSCALL_BASE+ 52) +/* 53 was sys_lock */ +#define __NR_ioctl (__NR_SYSCALL_BASE+ 54) +#define __NR_fcntl (__NR_SYSCALL_BASE+ 55) +/* 56 was sys_mpx */ +#define __NR_setpgid (__NR_SYSCALL_BASE+ 57) +/* 58 was sys_ulimit */ +/* 59 was sys_olduname */ +#define __NR_umask (__NR_SYSCALL_BASE+ 60) +#define __NR_chroot (__NR_SYSCALL_BASE+ 61) +#define __NR_ustat (__NR_SYSCALL_BASE+ 62) +#define __NR_dup2 (__NR_SYSCALL_BASE+ 63) +#define __NR_getppid (__NR_SYSCALL_BASE+ 64) +#define __NR_getpgrp (__NR_SYSCALL_BASE+ 65) +#define __NR_setsid (__NR_SYSCALL_BASE+ 66) +#define __NR_sigaction (__NR_SYSCALL_BASE+ 67) +/* 68 was sys_sgetmask */ +/* 69 was sys_ssetmask */ +#define __NR_setreuid (__NR_SYSCALL_BASE+ 70) +#define __NR_setregid (__NR_SYSCALL_BASE+ 71) +#define __NR_sigsuspend (__NR_SYSCALL_BASE+ 72) +#define __NR_sigpending (__NR_SYSCALL_BASE+ 73) +#define __NR_sethostname (__NR_SYSCALL_BASE+ 74) +#define __NR_setrlimit (__NR_SYSCALL_BASE+ 75) +#define __NR_getrlimit (__NR_SYSCALL_BASE+ 76)/* Back compat 2GB limited rlimit */ +#define __NR_getrusage (__NR_SYSCALL_BASE+ 77) +#define __NR_gettimeofday (__NR_SYSCALL_BASE+ 78) +#define __NR_settimeofday (__NR_SYSCALL_BASE+ 79) +#define __NR_getgroups (__NR_SYSCALL_BASE+ 80) +#define __NR_setgroups (__NR_SYSCALL_BASE+ 81) +#define __NR_select (__NR_SYSCALL_BASE+ 82) +#define __NR_symlink (__NR_SYSCALL_BASE+ 83) +/* 84 was sys_lstat */ +#define __NR_readlink (__NR_SYSCALL_BASE+ 85) +#define __NR_uselib (__NR_SYSCALL_BASE+ 86) +#define __NR_swapon (__NR_SYSCALL_BASE+ 87) +#define __NR_reboot (__NR_SYSCALL_BASE+ 88) +#define __NR_readdir (__NR_SYSCALL_BASE+ 89) +#define __NR_mmap (__NR_SYSCALL_BASE+ 90) +#define __NR_munmap (__NR_SYSCALL_BASE+ 91) +#define __NR_truncate (__NR_SYSCALL_BASE+ 92) +#define __NR_ftruncate (__NR_SYSCALL_BASE+ 93) +#define __NR_fchmod (__NR_SYSCALL_BASE+ 94) +#define __NR_fchown (__NR_SYSCALL_BASE+ 95) +#define __NR_getpriority (__NR_SYSCALL_BASE+ 96) +#define __NR_setpriority (__NR_SYSCALL_BASE+ 97) +/* 98 was sys_profil */ +#define __NR_statfs (__NR_SYSCALL_BASE+ 99) +#define __NR_fstatfs (__NR_SYSCALL_BASE+100) +/* 101 was sys_ioperm */ +#define __NR_socketcall (__NR_SYSCALL_BASE+102) +#define __NR_syslog (__NR_SYSCALL_BASE+103) +#define __NR_setitimer (__NR_SYSCALL_BASE+104) +#define __NR_getitimer (__NR_SYSCALL_BASE+105) +#define __NR_stat (__NR_SYSCALL_BASE+106) +#define __NR_lstat (__NR_SYSCALL_BASE+107) +#define __NR_fstat (__NR_SYSCALL_BASE+108) +/* 109 was sys_uname */ +/* 110 was sys_iopl */ +#define __NR_vhangup (__NR_SYSCALL_BASE+111) +/* 112 was sys_idle */ +#define __NR_syscall (__NR_SYSCALL_BASE+113)/* syscall to call a syscall! */ +#define __NR_wait4 (__NR_SYSCALL_BASE+114) +#define __NR_swapoff (__NR_SYSCALL_BASE+115) +#define __NR_sysinfo (__NR_SYSCALL_BASE+116) +#define __NR_ipc (__NR_SYSCALL_BASE+117) +#define __NR_fsync (__NR_SYSCALL_BASE+118) +#define __NR_sigreturn (__NR_SYSCALL_BASE+119) +#define __NR_clone (__NR_SYSCALL_BASE+120) +#define __NR_setdomainname (__NR_SYSCALL_BASE+121) +#define __NR_uname (__NR_SYSCALL_BASE+122) +/* 123 was sys_modify_ldt */ +#define __NR_adjtimex (__NR_SYSCALL_BASE+124) +#define __NR_mprotect (__NR_SYSCALL_BASE+125) +#define __NR_sigprocmask (__NR_SYSCALL_BASE+126) +/* 127 was sys_create_module */ +#define __NR_init_module (__NR_SYSCALL_BASE+128) +#define __NR_delete_module (__NR_SYSCALL_BASE+129) +/* 130 was sys_get_kernel_syms */ +#define __NR_quotactl (__NR_SYSCALL_BASE+131) +#define __NR_getpgid (__NR_SYSCALL_BASE+132) +#define __NR_fchdir (__NR_SYSCALL_BASE+133) +#define __NR_bdflush (__NR_SYSCALL_BASE+134) +#define __NR_sysfs (__NR_SYSCALL_BASE+135) +#define __NR_personality (__NR_SYSCALL_BASE+136) +/* 137 was sys_afs_syscall */ +#define __NR_setfsuid (__NR_SYSCALL_BASE+138) +#define __NR_setfsgid (__NR_SYSCALL_BASE+139) +#define __NR__llseek (__NR_SYSCALL_BASE+140) +#define __NR_getdents (__NR_SYSCALL_BASE+141) +#define __NR__newselect (__NR_SYSCALL_BASE+142) +#define __NR_flock (__NR_SYSCALL_BASE+143) +#define __NR_msync (__NR_SYSCALL_BASE+144) +#define __NR_readv (__NR_SYSCALL_BASE+145) +#define __NR_writev (__NR_SYSCALL_BASE+146) +#define __NR_getsid (__NR_SYSCALL_BASE+147) +#define __NR_fdatasync (__NR_SYSCALL_BASE+148) +#define __NR__sysctl (__NR_SYSCALL_BASE+149) +#define __NR_mlock (__NR_SYSCALL_BASE+150) +#define __NR_munlock (__NR_SYSCALL_BASE+151) +#define __NR_mlockall (__NR_SYSCALL_BASE+152) +#define __NR_munlockall (__NR_SYSCALL_BASE+153) +#define __NR_sched_setparam (__NR_SYSCALL_BASE+154) +#define __NR_sched_getparam (__NR_SYSCALL_BASE+155) +#define __NR_sched_setscheduler (__NR_SYSCALL_BASE+156) +#define __NR_sched_getscheduler (__NR_SYSCALL_BASE+157) +#define __NR_sched_yield (__NR_SYSCALL_BASE+158) +#define __NR_sched_get_priority_max (__NR_SYSCALL_BASE+159) +#define __NR_sched_get_priority_min (__NR_SYSCALL_BASE+160) +#define __NR_sched_rr_get_interval (__NR_SYSCALL_BASE+161) +#define __NR_nanosleep (__NR_SYSCALL_BASE+162) +#define __NR_mremap (__NR_SYSCALL_BASE+163) +#define __NR_setresuid (__NR_SYSCALL_BASE+164) +#define __NR_getresuid (__NR_SYSCALL_BASE+165) +/* 166 was sys_vm86 */ +/* 167 was sys_query_module */ +#define __NR_poll (__NR_SYSCALL_BASE+168) +#define __NR_nfsservctl (__NR_SYSCALL_BASE+169) +#define __NR_setresgid (__NR_SYSCALL_BASE+170) +#define __NR_getresgid (__NR_SYSCALL_BASE+171) +#define __NR_prctl (__NR_SYSCALL_BASE+172) +#define __NR_rt_sigreturn (__NR_SYSCALL_BASE+173) +#define __NR_rt_sigaction (__NR_SYSCALL_BASE+174) +#define __NR_rt_sigprocmask (__NR_SYSCALL_BASE+175) +#define __NR_rt_sigpending (__NR_SYSCALL_BASE+176) +#define __NR_rt_sigtimedwait (__NR_SYSCALL_BASE+177) +#define __NR_rt_sigqueueinfo (__NR_SYSCALL_BASE+178) +#define __NR_rt_sigsuspend (__NR_SYSCALL_BASE+179) +#define __NR_pread64 (__NR_SYSCALL_BASE+180) +#define __NR_pwrite64 (__NR_SYSCALL_BASE+181) +#define __NR_chown (__NR_SYSCALL_BASE+182) +#define __NR_getcwd (__NR_SYSCALL_BASE+183) +#define __NR_capget (__NR_SYSCALL_BASE+184) +#define __NR_capset (__NR_SYSCALL_BASE+185) +#define __NR_sigaltstack (__NR_SYSCALL_BASE+186) +#define __NR_sendfile (__NR_SYSCALL_BASE+187) +/* 188 reserved */ +/* 189 reserved */ +#define __NR_vfork (__NR_SYSCALL_BASE+190) +#define __NR_ugetrlimit (__NR_SYSCALL_BASE+191)/* SuS compliant getrlimit */ +#define __NR_mmap2 (__NR_SYSCALL_BASE+192) +#define __NR_truncate64 (__NR_SYSCALL_BASE+193) +#define __NR_ftruncate64 (__NR_SYSCALL_BASE+194) +#define __NR_stat64 (__NR_SYSCALL_BASE+195) +#define __NR_lstat64 (__NR_SYSCALL_BASE+196) +#define __NR_fstat64 (__NR_SYSCALL_BASE+197) +#define __NR_lchown32 (__NR_SYSCALL_BASE+198) +#define __NR_getuid32 (__NR_SYSCALL_BASE+199) +#define __NR_getgid32 (__NR_SYSCALL_BASE+200) +#define __NR_geteuid32 (__NR_SYSCALL_BASE+201) +#define __NR_getegid32 (__NR_SYSCALL_BASE+202) +#define __NR_setreuid32 (__NR_SYSCALL_BASE+203) +#define __NR_setregid32 (__NR_SYSCALL_BASE+204) +#define __NR_getgroups32 (__NR_SYSCALL_BASE+205) +#define __NR_setgroups32 (__NR_SYSCALL_BASE+206) +#define __NR_fchown32 (__NR_SYSCALL_BASE+207) +#define __NR_setresuid32 (__NR_SYSCALL_BASE+208) +#define __NR_getresuid32 (__NR_SYSCALL_BASE+209) +#define __NR_setresgid32 (__NR_SYSCALL_BASE+210) +#define __NR_getresgid32 (__NR_SYSCALL_BASE+211) +#define __NR_chown32 (__NR_SYSCALL_BASE+212) +#define __NR_setuid32 (__NR_SYSCALL_BASE+213) +#define __NR_setgid32 (__NR_SYSCALL_BASE+214) +#define __NR_setfsuid32 (__NR_SYSCALL_BASE+215) +#define __NR_setfsgid32 (__NR_SYSCALL_BASE+216) +#define __NR_getdents64 (__NR_SYSCALL_BASE+217) +#define __NR_pivot_root (__NR_SYSCALL_BASE+218) +#define __NR_mincore (__NR_SYSCALL_BASE+219) +#define __NR_madvise (__NR_SYSCALL_BASE+220) +#define __NR_fcntl64 (__NR_SYSCALL_BASE+221) +/* 222 for tux */ +/* 223 is unused */ +#define __NR_gettid (__NR_SYSCALL_BASE+224) +#define __NR_readahead (__NR_SYSCALL_BASE+225) +#define __NR_setxattr (__NR_SYSCALL_BASE+226) +#define __NR_lsetxattr (__NR_SYSCALL_BASE+227) +#define __NR_fsetxattr (__NR_SYSCALL_BASE+228) +#define __NR_getxattr (__NR_SYSCALL_BASE+229) +#define __NR_lgetxattr (__NR_SYSCALL_BASE+230) +#define __NR_fgetxattr (__NR_SYSCALL_BASE+231) +#define __NR_listxattr (__NR_SYSCALL_BASE+232) +#define __NR_llistxattr (__NR_SYSCALL_BASE+233) +#define __NR_flistxattr (__NR_SYSCALL_BASE+234) +#define __NR_removexattr (__NR_SYSCALL_BASE+235) +#define __NR_lremovexattr (__NR_SYSCALL_BASE+236) +#define __NR_fremovexattr (__NR_SYSCALL_BASE+237) +#define __NR_tkill (__NR_SYSCALL_BASE+238) +#define __NR_sendfile64 (__NR_SYSCALL_BASE+239) +#define __NR_futex (__NR_SYSCALL_BASE+240) +#define __NR_sched_setaffinity (__NR_SYSCALL_BASE+241) +#define __NR_sched_getaffinity (__NR_SYSCALL_BASE+242) +#define __NR_io_setup (__NR_SYSCALL_BASE+243) +#define __NR_io_destroy (__NR_SYSCALL_BASE+244) +#define __NR_io_getevents (__NR_SYSCALL_BASE+245) +#define __NR_io_submit (__NR_SYSCALL_BASE+246) +#define __NR_io_cancel (__NR_SYSCALL_BASE+247) +#define __NR_exit_group (__NR_SYSCALL_BASE+248) +#define __NR_lookup_dcookie (__NR_SYSCALL_BASE+249) +#define __NR_epoll_create (__NR_SYSCALL_BASE+250) +#define __NR_epoll_ctl (__NR_SYSCALL_BASE+251) +#define __NR_epoll_wait (__NR_SYSCALL_BASE+252) +#define __NR_remap_file_pages (__NR_SYSCALL_BASE+253) +/* 254 for set_thread_area */ +/* 255 for get_thread_area */ +#define __NR_set_tid_address (__NR_SYSCALL_BASE+256) +#define __NR_timer_create (__NR_SYSCALL_BASE+257) +#define __NR_timer_settime (__NR_SYSCALL_BASE+258) +#define __NR_timer_gettime (__NR_SYSCALL_BASE+259) +#define __NR_timer_getoverrun (__NR_SYSCALL_BASE+260) +#define __NR_timer_delete (__NR_SYSCALL_BASE+261) +#define __NR_clock_settime (__NR_SYSCALL_BASE+262) +#define __NR_clock_gettime (__NR_SYSCALL_BASE+263) +#define __NR_clock_getres (__NR_SYSCALL_BASE+264) +#define __NR_clock_nanosleep (__NR_SYSCALL_BASE+265) +#define __NR_statfs64 (__NR_SYSCALL_BASE+266) +#define __NR_fstatfs64 (__NR_SYSCALL_BASE+267) +#define __NR_tgkill (__NR_SYSCALL_BASE+268) +#define __NR_utimes (__NR_SYSCALL_BASE+269) +#define __NR_arm_fadvise64_64 (__NR_SYSCALL_BASE+270) +#define __NR_pciconfig_iobase (__NR_SYSCALL_BASE+271) +#define __NR_pciconfig_read (__NR_SYSCALL_BASE+272) +#define __NR_pciconfig_write (__NR_SYSCALL_BASE+273) +#define __NR_mq_open (__NR_SYSCALL_BASE+274) +#define __NR_mq_unlink (__NR_SYSCALL_BASE+275) +#define __NR_mq_timedsend (__NR_SYSCALL_BASE+276) +#define __NR_mq_timedreceive (__NR_SYSCALL_BASE+277) +#define __NR_mq_notify (__NR_SYSCALL_BASE+278) +#define __NR_mq_getsetattr (__NR_SYSCALL_BASE+279) +#define __NR_waitid (__NR_SYSCALL_BASE+280) +#define __NR_socket (__NR_SYSCALL_BASE+281) +#define __NR_bind (__NR_SYSCALL_BASE+282) +#define __NR_connect (__NR_SYSCALL_BASE+283) +#define __NR_listen (__NR_SYSCALL_BASE+284) +#define __NR_accept (__NR_SYSCALL_BASE+285) +#define __NR_getsockname (__NR_SYSCALL_BASE+286) +#define __NR_getpeername (__NR_SYSCALL_BASE+287) +#define __NR_socketpair (__NR_SYSCALL_BASE+288) +#define __NR_send (__NR_SYSCALL_BASE+289) +#define __NR_sendto (__NR_SYSCALL_BASE+290) +#define __NR_recv (__NR_SYSCALL_BASE+291) +#define __NR_recvfrom (__NR_SYSCALL_BASE+292) +#define __NR_shutdown (__NR_SYSCALL_BASE+293) +#define __NR_setsockopt (__NR_SYSCALL_BASE+294) +#define __NR_getsockopt (__NR_SYSCALL_BASE+295) +#define __NR_sendmsg (__NR_SYSCALL_BASE+296) +#define __NR_recvmsg (__NR_SYSCALL_BASE+297) +#define __NR_semop (__NR_SYSCALL_BASE+298) +#define __NR_semget (__NR_SYSCALL_BASE+299) +#define __NR_semctl (__NR_SYSCALL_BASE+300) +#define __NR_msgsnd (__NR_SYSCALL_BASE+301) +#define __NR_msgrcv (__NR_SYSCALL_BASE+302) +#define __NR_msgget (__NR_SYSCALL_BASE+303) +#define __NR_msgctl (__NR_SYSCALL_BASE+304) +#define __NR_shmat (__NR_SYSCALL_BASE+305) +#define __NR_shmdt (__NR_SYSCALL_BASE+306) +#define __NR_shmget (__NR_SYSCALL_BASE+307) +#define __NR_shmctl (__NR_SYSCALL_BASE+308) +#define __NR_add_key (__NR_SYSCALL_BASE+309) +#define __NR_request_key (__NR_SYSCALL_BASE+310) +#define __NR_keyctl (__NR_SYSCALL_BASE+311) +#define __NR_semtimedop (__NR_SYSCALL_BASE+312) +#define __NR_vserver (__NR_SYSCALL_BASE+313) +#define __NR_ioprio_set (__NR_SYSCALL_BASE+314) +#define __NR_ioprio_get (__NR_SYSCALL_BASE+315) +#define __NR_inotify_init (__NR_SYSCALL_BASE+316) +#define __NR_inotify_add_watch (__NR_SYSCALL_BASE+317) +#define __NR_inotify_rm_watch (__NR_SYSCALL_BASE+318) +#define __NR_mbind (__NR_SYSCALL_BASE+319) +#define __NR_get_mempolicy (__NR_SYSCALL_BASE+320) +#define __NR_set_mempolicy (__NR_SYSCALL_BASE+321) +#define __NR_openat (__NR_SYSCALL_BASE+322) +#define __NR_mkdirat (__NR_SYSCALL_BASE+323) +#define __NR_mknodat (__NR_SYSCALL_BASE+324) +#define __NR_fchownat (__NR_SYSCALL_BASE+325) +#define __NR_futimesat (__NR_SYSCALL_BASE+326) +#define __NR_fstatat64 (__NR_SYSCALL_BASE+327) +#define __NR_unlinkat (__NR_SYSCALL_BASE+328) +#define __NR_renameat (__NR_SYSCALL_BASE+329) +#define __NR_linkat (__NR_SYSCALL_BASE+330) +#define __NR_symlinkat (__NR_SYSCALL_BASE+331) +#define __NR_readlinkat (__NR_SYSCALL_BASE+332) +#define __NR_fchmodat (__NR_SYSCALL_BASE+333) +#define __NR_faccessat (__NR_SYSCALL_BASE+334) +#define __NR_pselect6 (__NR_SYSCALL_BASE+335) +#define __NR_ppoll (__NR_SYSCALL_BASE+336) +#define __NR_unshare (__NR_SYSCALL_BASE+337) +#define __NR_set_robust_list (__NR_SYSCALL_BASE+338) +#define __NR_get_robust_list (__NR_SYSCALL_BASE+339) +#define __NR_splice (__NR_SYSCALL_BASE+340) +#define __NR_arm_sync_file_range (__NR_SYSCALL_BASE+341) +#define __NR_sync_file_range2 __NR_arm_sync_file_range +#define __NR_tee (__NR_SYSCALL_BASE+342) +#define __NR_vmsplice (__NR_SYSCALL_BASE+343) +#define __NR_move_pages (__NR_SYSCALL_BASE+344) +#define __NR_getcpu (__NR_SYSCALL_BASE+345) +#define __NR_epoll_pwait (__NR_SYSCALL_BASE+346) +#define __NR_kexec_load (__NR_SYSCALL_BASE+347) +#define __NR_utimensat (__NR_SYSCALL_BASE+348) +#define __NR_signalfd (__NR_SYSCALL_BASE+349) +#define __NR_timerfd_create (__NR_SYSCALL_BASE+350) +#define __NR_eventfd (__NR_SYSCALL_BASE+351) +#define __NR_fallocate (__NR_SYSCALL_BASE+352) +#define __NR_timerfd_settime (__NR_SYSCALL_BASE+353) +#define __NR_timerfd_gettime (__NR_SYSCALL_BASE+354) +#define __NR_signalfd4 (__NR_SYSCALL_BASE+355) +#define __NR_eventfd2 (__NR_SYSCALL_BASE+356) +#define __NR_epoll_create1 (__NR_SYSCALL_BASE+357) +#define __NR_dup3 (__NR_SYSCALL_BASE+358) +#define __NR_pipe2 (__NR_SYSCALL_BASE+359) +#define __NR_inotify_init1 (__NR_SYSCALL_BASE+360) +#define __NR_preadv (__NR_SYSCALL_BASE+361) +#define __NR_pwritev (__NR_SYSCALL_BASE+362) +#define __NR_rt_tgsigqueueinfo (__NR_SYSCALL_BASE+363) +#define __NR_perf_event_open (__NR_SYSCALL_BASE+364) +#define __NR_recvmmsg (__NR_SYSCALL_BASE+365) +#define __NR_accept4 (__NR_SYSCALL_BASE+366) +#define __NR_fanotify_init (__NR_SYSCALL_BASE+367) +#define __NR_fanotify_mark (__NR_SYSCALL_BASE+368) +#define __NR_prlimit64 (__NR_SYSCALL_BASE+369) +#define __NR_name_to_handle_at (__NR_SYSCALL_BASE+370) +#define __NR_open_by_handle_at (__NR_SYSCALL_BASE+371) +#define __NR_clock_adjtime (__NR_SYSCALL_BASE+372) +#define __NR_syncfs (__NR_SYSCALL_BASE+373) +#define __NR_sendmmsg (__NR_SYSCALL_BASE+374) +#define __NR_setns (__NR_SYSCALL_BASE+375) +#define __NR_process_vm_readv (__NR_SYSCALL_BASE+376) +#define __NR_process_vm_writev (__NR_SYSCALL_BASE+377) +#define __NR_kcmp (__NR_SYSCALL_BASE+378) +#define __NR_finit_module (__NR_SYSCALL_BASE+379) +#define __NR_sched_setattr (__NR_SYSCALL_BASE+380) +#define __NR_sched_getattr (__NR_SYSCALL_BASE+381) +#define __NR_renameat2 (__NR_SYSCALL_BASE+382) +#define __NR_seccomp (__NR_SYSCALL_BASE+383) +#define __NR_getrandom (__NR_SYSCALL_BASE+384) +#define __NR_memfd_create (__NR_SYSCALL_BASE+385) +#define __NR_bpf (__NR_SYSCALL_BASE+386) +#define __NR_execveat (__NR_SYSCALL_BASE+387) +#define __NR_userfaultfd (__NR_SYSCALL_BASE+388) +#define __NR_membarrier (__NR_SYSCALL_BASE+389) + +/* +* The following SWIs are ARM private. +*/ +#define __ARM_NR_BASE (__NR_SYSCALL_BASE+0x0f0000) +#define __ARM_NR_breakpoint (__ARM_NR_BASE+1) +#define __ARM_NR_cacheflush (__ARM_NR_BASE+2) +#define __ARM_NR_usr26 (__ARM_NR_BASE+3) +#define __ARM_NR_usr32 (__ARM_NR_BASE+4) +#define __ARM_NR_set_tls (__ARM_NR_BASE+5) + +/* +* The following syscalls are obsolete and no longer available for EABI. +*/ +#if defined(__ARM_EABI__) +#undef __NR_time +#undef __NR_umount +#undef __NR_stime +#undef __NR_alarm +#undef __NR_utime +#undef __NR_getrlimit +#undef __NR_select +#undef __NR_readdir +#undef __NR_mmap +#undef __NR_socketcall +#undef __NR_syscall +#undef __NR_ipc +#endif + +#endif /* __ASM_ARM_UNISTD_H */
linux-headers/asm-arm64/kvm.h +35 -2
@@ -53,14 +53,20 @@ struct kvm_regs {struct user_fpsimd_state fp_regs; }; -/* Supported Processor Types */ +/* +* Supported CPU Targets - Adding a new target type is not recommended, +* unless there are some special registers not supported by the +* genericv8 syreg table. +*/ #define KVM_ARM_TARGET_AEM_V8 0#define KVM_ARM_TARGET_FOUNDATION_V8 1#define KVM_ARM_TARGET_CORTEX_A57 2#define KVM_ARM_TARGET_XGENE_POTENZA 3#define KVM_ARM_TARGET_CORTEX_A53 4 +/* Generic ARM v8 target */ +#define KVM_ARM_TARGET_GENERIC_V8 5 -#define KVM_ARM_NUM_TARGETS 5 +#define KVM_ARM_NUM_TARGETS 6/* KVM_ARM_SET_DEVICE_ADDR ioctl id encoding */ #define KVM_ARM_DEVICE_TYPE_SHIFT 0
@@ -100,12 +106,39 @@ struct kvm_sregs {struct kvm_fpu { }; +/* +* See v8 ARM ARM D7.3: Debug Registers +* +* The architectural limit is 16 debug registers of each type although +* in practice there are usually less (see ID_AA64DFR0_EL1). +* +* Although the control registers are architecturally defined as 32 +* bits wide we use a 64 bit structure here to keep parity with +* KVM_GET/SET_ONE_REG behaviour which treats all system registers as +* 64 bit values. It also allows for the possibility of the +* architecture expanding the control registers without having to +* change the userspace ABI. +*/ +#define KVM_ARM_MAX_DBG_REGS 16struct kvm_guest_debug_arch { +__u64 dbg_bcr[KVM_ARM_MAX_DBG_REGS ]; +__u64 dbg_bvr[KVM_ARM_MAX_DBG_REGS ]; +__u64 dbg_wcr[KVM_ARM_MAX_DBG_REGS ]; +__u64 dbg_wvr[KVM_ARM_MAX_DBG_REGS ]; };struct kvm_debug_exit_arch { +__u32 hsr; +__u64 far;/* used for watchpoints */ }; +/* +* Architecture specific defines for kvm_guest_debug->control +*/ + +#define KVM_GUESTDBG_USE_SW_BP (1 << 16) +#define KVM_GUESTDBG_USE_HW (1 << 17) +struct kvm_sync_regs { };
linux-headers/asm-arm64/unistd.h new file +16 -0
@@ -0,0 +1,16 @@ +/* +* Copyright (C) 2012 ARM Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#include <asm-generic/unistd.h>
linux-headers/asm-mips/unistd.h new file +1063 -0
1,063 lines not on this page · raw message
linux-headers/asm-powerpc/unistd.h new file +392 -0
392 lines not on this page · raw message
linux-headers/asm-s390/unistd.h new file +404 -0
404 lines not on this page · raw message
linux-headers/asm-x86/unistd.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef _ASM_X86_UNISTD_H +#define _ASM_X86_UNISTD_H + +/* x32 syscall flag bit */ +#define __X32_SYSCALL_BIT 0x40000000 + +# ifdef __i386__ +# include <asm/unistd_32.h> +# elif defined(__ILP32__) +# include <asm/unistd_x32.h> +# else +# include <asm/unistd_64.h> +# endif + +#endif /* _ASM_X86_UNISTD_H */
linux-headers/asm-x86/unistd_32.h new file +377 -0
377 lines not on this page · raw message
linux-headers/asm-x86/unistd_64.h new file +330 -0
224 lines not on this page · raw message
linux-headers/asm-x86/unistd_x32.h new file +319 -0
319 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.4.3
Part of the diff is not shown here. View the raw message.
PATCH v6 4/24 util: add linux-only memfd fallback
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Implement memfd_create() fallback if not available in system libc. memfd_create() is still not included in glibc today, atlhough it's been available since Linux 3.17 in Oct 2014.
memfd has numerous advantages over traditional shm/mmap for ipc memory sharing with fd handler, which we are going to make use of for vhost-user logging memory in following patches.
--- include/qemu/memfd.h | 20 +++++++++++++++++++ util/Makefile.objs | 2 +- util/memfd.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 include/qemu/memfd.h create mode 100644 util/memfd.c
include/qemu/memfd.h new file +20 -0
@@ -0,0 +1,20 @@ +#ifndef QEMU_MEMFD_H +#define QEMU_MEMFD_H + +#include "config-host.h" + +#ifndef F_LINUX_SPECIFIC_BASE +#define F_LINUX_SPECIFIC_BASE 1024 +#endif + +#ifndef F_ADD_SEALS +#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9) +#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10) + +#define F_SEAL_SEAL 0x0001/* prevent further seals from being set */ +#define F_SEAL_SHRINK 0x0002/* prevent file from shrinking */ +#define F_SEAL_GROW 0x0004/* prevent file from growing */ +#define F_SEAL_WRITE 0x0008/* prevent writes */ +#endif + +#endif /* QEMU_MEMFD_H */
util/Makefile.objs +1 -1
@@ -1,6 +1,6 @@ util-obj-y = osdep.o cutils.o unicode.o qemu-timer-common.o util-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o event_notifier-win32.o -util-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o event_notifier-posix.o qemu-openpty.o +util-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o event_notifier-posix.o qemu-openpty.o memfd.o util-obj-y += envlist.o path.o module.o util-obj-$(call lnot,$(CONFIG_INT128)) += host-utils.o util-obj-y += bitmap.o bitops.o hbitmap.o
util/memfd.c new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v6 04/24] util: add linux-only memfd fallback
Quoted 86 lines · On Tue, Sep 29, 2015 at 06:34:34PM +0200, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Implement
memfd_create()fallback if not available in system libc.memfd_create()is still not included in glibc today, atlhough it's been available since Linux 3.17 in Oct 2014.memfd has numerous advantages over traditional shm/mmap for ipc memory sharing with fd handler, which we are going to make use of for vhost-user logging memory in following patches.
Signed-off-by Marc-André Lureau <[email protected]>--- include/qemu/memfd.h | 20 +++++++++++++++++++ util/Makefile.objs | 2 +- util/memfd.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 include/qemu/memfd.h create mode 100644 util/memfd.cinclude/qemu/memfd.h new file +20
-0@@ -0,0 +1,20 @@ +#ifndef QEMU_MEMFD_H +#define QEMU_MEMFD_H + +#include "config-host.h" + +#ifndef F_LINUX_SPECIFIC_BASE +#define F_LINUX_SPECIFIC_BASE 1024 +#endif + +#ifndef F_ADD_SEALS +#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9) +#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10) + +#define F_SEAL_SEAL 0x0001/* prevent further seals from being set */ +#define F_SEAL_SHRINK 0x0002/* prevent file from shrinking */ +#define F_SEAL_GROW 0x0004/* prevent file from growing */ +#define F_SEAL_WRITE 0x0008/* prevent writes */ +#endif + +#endif /* QEMU_MEMFD_H */ util/Makefile.objs +1
-1@@ -1,6 +1,6 @@ util-obj-y = osdep.o cutils.o unicode.o qemu-timer-common.o util-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o event_notifier-win32.o -util-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o event_notifier-posix.o qemu-openpty.o +util-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o event_notifier-posix.o qemu-openpty.o memfd.o util-obj-y += envlist.o path.o module.o util-obj-$(call lnot,$(CONFIG_INT128)) += host-utils.o util-obj-y += bitmap.o bitops.o hbitmap.outil/memfd.c new file +23
-0@@ -0,0 +1,56 @@ +/* +* memfd.c +* +* Copyright (c) 2015 Red Hat, Inc. +* +* QEMU library functions on POSIX which are shared between QEMU and +* the QEMU tools. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
util/memfd.c line 33
Quoted 10 lines
util/memfd.c new file +10
-0+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include "config-host.h" + +#include "qemu/memfd.h" + +#ifdef CONFIG_MEMFD +#include <sys/memfd.h>
So the file is empty if CONFIG_MEMFD is set?
It would be more elegant to avoid linking it in.
Can be a patch on top.
Quoted 25 lines
util/memfd.c new file +23
-0+#elif definedCONFIG_LINUX +#include <unistd.h> +#include <sys/syscall.h> +#include <asm/unistd.h> + +#ifndef MFD_CLOEXEC +#define MFD_CLOEXEC 0x0001U +#endif + +#ifndef MFD_ALLOW_SEALING +#define MFD_ALLOW_SEALING 0x0002U +#endif + +static inline int memfd_create (const char *name,unsigned int flags) +{ +return syscall (__NR_memfd_create, name, flags); +} +#else /* !LINUX */ +static inline int memfd_create (const char *name,unsigned int flags) +{ +return -1 ; +} +#endif Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v6 04/24] util: add linux-only memfd fallback
Hi
Quoted 3 lines · Michael S. Tsirkin
So the file is empty if
CONFIG_MEMFDis set?
It would be more elegant to avoid linking it in.
Can be a patch on top.
It's not empty in the following commits, with the helpers introduced
Signature · 1 line
Marc-André Lureau
PATCH v6 5/24 util: add memfd helpers
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Add qemu_memfd_alloc/free() helpers.
The function helps to allocate and seal a memfd.
--- include/qemu/memfd.h | 4 ++++ util/memfd.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-)
include/qemu/memfd.h +4 -0
@@ -17,4 +17,8 @@#define F_SEAL_WRITE 0x0008/* prevent writes */ #endif +void *qemu_memfd_alloc (const char *name,size_t size,unsigned int seals, +int *fd); +void qemu_memfd_free (void *ptr,size_t size,int fd); +#endif /* QEMU_MEMFD_H */
util/memfd.c +57 -2
76 lines not on this page · raw message
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v6 05/24] util: add memfd helpers
Quoted 71 lines · On Tue, Sep 29, 2015 at 06:34:35PM +0200, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Add qemu_memfd_alloc/free() helpers.
The function helps to allocate and seal a memfd.
Signed-off-by Marc-André Lureau <[email protected]>--- include/qemu/memfd.h | 4 ++++ util/memfd.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-)include/qemu/memfd.h +4
-0@@ -17,4 +17,8 @@#define F_SEAL_WRITE 0x0008/* prevent writes */ #endif +void *qemu_memfd_alloc (const char *name,size_t size,unsigned int seals, +int *fd); +void qemu_memfd_free (void *ptr,size_t size,int fd); +#endif /* QEMU_MEMFD_H */ util/memfd.c +21
-2@@ -27,6 +27,14 @@#include "config-host.h" +#include <glib.h> +#include <glib/gprintf.h> + +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <sys/mman.h> +#include "qemu/memfd.h" #ifdef CONFIG_MEMFD @@ -44,13 +52,60 @@#define MFD_ALLOW_SEALING 0x0002U#endif -static inline int memfd_create (const char *name,unsigned int flags) +static int memfd_create (const char *name,unsigned int flags) {return syscall (__NR_memfd_create, name, flags); }#else /* !LINUX */ -static inline int memfd_create (const char *name,unsigned int flags) +static int memfd_create (const char *name,unsigned int flags) {return -1 ; }#endif + +void *qemu_memfd_alloc (const char *name,size_t size,unsigned int seals, +int *fd) +{ +void *ptr; +int mfd; + + *fd =-1 ; + mfd =memfd_create (name,MFD_ALLOW_SEALING |MFD_CLOEXEC ); +if (mfd !=-1 ) { +if (ftruncate (mfd, size) ==-1 ) {
util/memfd.c line 85
Quoted 10 lines
util/memfd.c +10
-0+perror ("ftruncate" ); +close (mfd); +return NULL ; + } + +if (fcntl (mfd,F_ADD_SEALS , seals) ==-1 ) { +perror ("fcntl" ); +close (mfd); +return NULL ; + }
Why do it here? I note that you don't try to do this with the tmpfs fallback.
Quoted 28 lines
util/memfd.c +26
-0+ }else { +perror ("memfd" ); +return NULL ; + } + + ptr =mmap (0 , size,PROT_READ |PROT_WRITE ,MAP_SHARED , mfd,0 ); +if (ptr ==MAP_FAILED ) { +perror ("mmap" ); +close (mfd); +return NULL ; + } + + *fd = mfd; +return ptr; +} + +void qemu_memfd_free (void *ptr,size_t size,int fd) +{ +if (ptr) { +munmap (ptr, size); + } + +if (fd !=-1 ) { +close (fd); + } +}Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v6 05/24] util: add memfd helpers
----- Original Message -----
Quoted 78 lines · On Tue, Sep 29, 2015 at 06:34:35PM +0200, [email protected] wrote:
Quoted 77 lines
From: Marc-André Lureau <[email protected]>
Add qemu_memfd_alloc/free() helpers.
The function helps to allocate and seal a memfd.
Signed-off-by Marc-André Lureau <[email protected]>--- include/qemu/memfd.h | 4 ++++ util/memfd.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-)include/qemu/memfd.h +4
-0@@ -17,4 +17,8 @@#define F_SEAL_WRITE 0x0008/* prevent writes */ #endif +void *qemu_memfd_alloc (const char *name,size_t size,unsigned int seals, +int *fd); +void qemu_memfd_free (void *ptr,size_t size,int fd); +#endif /* QEMU_MEMFD_H */ util/memfd.c +26
-2@@ -27,6 +27,14 @@#include "config-host.h" +#include <glib.h> +#include <glib/gprintf.h> + +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <sys/mman.h> +#include "qemu/memfd.h" #ifdef CONFIG_MEMFD @@ -44,13 +52,60 @@#define MFD_ALLOW_SEALING 0x0002U#endif -static inline int memfd_create (const char *name,unsigned int flags) +static int memfd_create (const char *name,unsigned int flags) {return syscall (__NR_memfd_create, name, flags); }#else /* !LINUX */ -static inline int memfd_create (const char *name,unsigned int flags) +static int memfd_create (const char *name,unsigned int flags) {return -1 ; }#endif + +void *qemu_memfd_alloc (const char *name,size_t size,unsigned int seals, +int *fd) +{ +void *ptr; +int mfd; + + *fd =-1 ; + mfd =memfd_create (name,MFD_ALLOW_SEALING |MFD_CLOEXEC ); +if (mfd !=-1 ) { +if (ftruncate (mfd, size) ==-1 ) { +perror ("ftruncate" ); +close (mfd); +return NULL ; + } +
Quoted 8 lines
util/memfd.c line 85
Quoted 5 lines
util/memfd.c +5
-0+if (fcntl (mfd,F_ADD_SEALS , seals) ==-1 ) { +perror ("fcntl" ); +close (mfd); +return NULL ; + }Why do it here? I note that you don't try to do this with the tmpfs fallback.
The idea of the helper is to use the best practices of using memfd: sealing, and provide graceful feedback if not available. Without sealing, there isn't much benefit over traditional open/mmap. If you want to use memfd differently, for ex to enforce sealing, then the helper isn't of much use. F_ADD_SEALS doesn't work on regular open/mmap shared memory, it was added with memfd afaik.
Since some kernel support memfd without sealing, I'll add a fallback for that case.
Quoted 30 lines
Quoted 29 lines
util/memfd.c +26
-1+ }else { +perror ("memfd" ); +return NULL ; + } + + ptr =mmap (0 , size,PROT_READ |PROT_WRITE ,MAP_SHARED , mfd,0 ); +if (ptr ==MAP_FAILED ) { +perror ("mmap" ); +close (mfd); +return NULL ; + } + + *fd = mfd; +return ptr; +} + +void qemu_memfd_free (void *ptr,size_t size,int fd) +{ +if (ptr) { +munmap (ptr, size); + } + +if (fd !=-1 ) { +close (fd); + } +} --2.4.3
PATCH v6 6/24 memfd: add fallback for memfd
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Add an open/unlink/mmap fallback for system that do not support memfd. This patch may require additional SELinux policies to work for enforced systems, but should gracefully fail nonetheless.
--- util/memfd.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
util/memfd.c +20 -2
@@ -84,8 +84,26 @@ void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals,return NULL ; } }else { -perror ("memfd" ); -return NULL ; +const char *tmpdir =getenv ("TMPDIR" ); +gchar *fname; + + tmpdir = tmpdir ? tmpdir :"/tmp" ; + + fname =g_strdup_printf ("%s/memfd-XXXXXX" , tmpdir); + mfd =mkstemp (fname); +unlink (fname); +g_free (fname); + +if (mfd ==-1 ) { +perror ("mkstemp" ); +return NULL ; + } + +if (ftruncate (mfd, size) ==-1 ) { +perror ("ftruncate" ); +close (mfd); +return NULL ; + } } ptr =mmap (0 , size,PROT_READ |PROT_WRITE ,MAP_SHARED , mfd,0 );
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v6 06/24] memfd: add fallback for memfd
Quoted 7 lines · On Tue, Sep 29, 2015 at 06:34:36PM +0200, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
Add an open/unlink/mmap fallback for system that do not support memfd. This patch may require additional SELinux policies to work for enforced systems, but should gracefully fail nonetheless.
Signed-off-by Marc-André Lureau <[email protected]>
I'd rather just fail migration.
Quoted 39 lines
--- util/memfd.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)util/memfd.c +20
-2@@ -84,8 +84,26 @@ void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals,return NULL ; } }else { -perror ("memfd" ); -return NULL ; +const char *tmpdir =getenv ("TMPDIR" ); +gchar *fname; + + tmpdir = tmpdir ? tmpdir :"/tmp" ; + + fname =g_strdup_printf ("%s/memfd-XXXXXX" , tmpdir); + mfd =mkstemp (fname); +unlink (fname); +g_free (fname); + +if (mfd ==-1 ) { +perror ("mkstemp" ); +return NULL ; + } + +if (ftruncate (mfd, size) ==-1 ) { +perror ("ftruncate" ); +close (mfd); +return NULL ; + } } ptr =mmap (0 , size,PROT_READ |PROT_WRITE ,MAP_SHARED , mfd,0 );Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v6 06/24] memfd: add fallback for memfd
Hi
----- Original Message -----
Quoted 10 lines · On Tue, Sep 29, 2015 at 06:34:36PM +0200, [email protected] wrote:
Quoted 7 lines
From: Marc-André Lureau <[email protected]>
Add an open/unlink/mmap fallback for system that do not support memfd. This patch may require additional SELinux policies to work for enforced systems, but should gracefully fail nonetheless.
Signed-off-by Marc-André Lureau <[email protected]>I'd rather just fail migration.
So we don't provide this compatibility code and migration should fail.
Would it be enough to check if memfd works at early runtime and add a migration blocker for vhost-user? Or is it possible to recover if migration fails when memfd fails to allocate? I would thing the former is better.
Quoted 42 lines
Quoted 41 lines
--- util/memfd.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)util/memfd.c +20
-2@@ -84,8 +84,26 @@ void *qemu_memfd_alloc(const char *name, size_t size,unsigned int seals, return NULL; } }else { -perror ("memfd" ); -return NULL ; +const char *tmpdir =getenv ("TMPDIR" ); +gchar *fname; + + tmpdir = tmpdir ? tmpdir :"/tmp" ; + + fname =g_strdup_printf ("%s/memfd-XXXXXX" , tmpdir); + mfd =mkstemp (fname); +unlink (fname); +g_free (fname); + +if (mfd ==-1 ) { +perror ("mkstemp" ); +return NULL ; + } + +if (ftruncate (mfd, size) ==-1 ) { +perror ("ftruncate" ); +close (mfd); +return NULL ; + } }ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, 0);--
2.4.3
Re: [Qemu-devel] [PATCH v6 06/24] memfd: add fallback for memfd
Quoted 10 lines · Marc-André Lureau
Hi
----- Original Message -----
Quoted 7 lines · On Tue, Sep 29, 2015 at 06:34:36PM +0200, [email protected] wrote:
Quoted 6 lines
From: Marc-André Lureau <[email protected]>
Add an open/unlink/mmap fallback for system that do not support memfd. This patch may require additional SELinux policies to work for enforced systems, but should gracefully fail nonetheless.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Marc-André Lureau <[email protected]>I'd rather just fail migration.
So we don't provide this compatibility code and migration should fail.
Would it be enough to check if memfd works at early runtime and add a migration blocker for vhost-user? Or is it possible to recover if migration fails when memfd fails to allocate? I would thing the former is better.
Fine with me.
Quoted 42 lines
Quoted 42 lines
Quoted 41 lines
--- util/memfd.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)util/memfd.c +20
-2@@ -84,8 +84,26 @@ void *qemu_memfd_alloc(const char *name, size_t size,unsigned int seals, return NULL; } }else { -perror ("memfd" ); -return NULL ; +const char *tmpdir =getenv ("TMPDIR" ); +gchar *fname; + + tmpdir = tmpdir ? tmpdir :"/tmp" ; + + fname =g_strdup_printf ("%s/memfd-XXXXXX" , tmpdir); + mfd =mkstemp (fname); +unlink (fname); +g_free (fname); + +if (mfd ==-1 ) { +perror ("mkstemp" ); +return NULL ; + } + +if (ftruncate (mfd, size) ==-1 ) { +perror ("ftruncate" ); +close (mfd); +return NULL ; + } }ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, 0);--
2.4.3
PATCH v6 7/24 vhost: document log resizing
In reply to [email protected]From: Marc-André Lureau <[email protected]>
--- hw/virtio/vhost.c | 2 ++ 1 file changed, 2 insertions(+)
hw/virtio/vhost.c +2 -0
@@ -334,6 +334,8 @@ static inline void vhost_dev_log_resize(struct vhost_dev* dev, uint64_t size)uint64_t log_base = (uintptr_t )log->log;int r; +/* inform backend of log switching, this must be done before +releasing the current log, to ensure no logging is lost */ r = dev->vhost_ops->vhost_call (dev,VHOST_SET_LOG_BASE , &log_base);assert (r >=0 );vhost_log_put (dev, true);
Signature · 1 line
2.4.3
PATCH v6 8/24 vhost: add vhost_set_log_base op
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Split VHOST_SET_LOG_BASE call in a seperate function callback, so that type safety works and more arguments can be added in the next patches.
--- hw/virtio/vhost-backend.c | 8 ++++++++ hw/virtio/vhost-user.c | 17 ++++++++++++++++- hw/virtio/vhost.c | 6 +++--- include/hw/virtio/vhost-backend.h | 5 +++++ 4 files changed, 32 insertions(+), 4 deletions(-)
hw/virtio/vhost-backend.c +8 -0
@@ -11,6 +11,7 @@#include "hw/virtio/vhost.h" #include "hw/virtio/vhost-backend.h" #include "qemu/error-report.h" +#include "linux/vhost.h" #include <sys/ioctl.h>
@@ -49,12 +50,19 @@ static int vhost_kernel_get_vq_index(struct vhost_dev *dev, int idx)return idx - dev->vq_index; } +static int vhost_set_log_base (struct vhost_dev *dev,uint64_t base) +{ +return vhost_kernel_call (dev,VHOST_SET_LOG_BASE , &base); +} +static const VhostOps kernel_ops = { .backend_type =VHOST_BACKEND_TYPE_KERNEL , .vhost_call = vhost_kernel_call, .vhost_backend_init = vhost_kernel_init, .vhost_backend_cleanup = vhost_kernel_cleanup, .vhost_backend_get_vq_index = vhost_kernel_get_vq_index, + + .vhost_set_log_base = vhost_set_log_base, };int vhost_set_backend_type (struct vhost_dev *dev,VhostBackendType backend_type)
hw/virtio/vhost-user.c +16 -1
@@ -242,7 +242,6 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,break ;case VHOST_USER_SET_FEATURES : -case VHOST_USER_SET_LOG_BASE :case VHOST_USER_SET_PROTOCOL_FEATURES : msg.u64 = *((__u64 *) arg); msg.size =sizeof (m.u64);
@@ -367,6 +366,20 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,return 0 ; } +static int vhost_set_log_base (struct vhost_dev *dev,uint64_t base) +{ +VhostUserMsg msg = { + .request =VHOST_USER_SET_LOG_BASE , + .flags =VHOST_USER_VERSION , + .u64 = base, + .size =sizeof (m.u64), + }; + +vhost_user_write (dev, &msg,NULL ,0 ); + +return 0 ; +} +static int vhost_user_init (struct vhost_dev *dev,void *opaque) {unsigned long long features;
@@ -447,4 +460,6 @@ const VhostOps user_ops = { .vhost_backend_cleanup = vhost_user_cleanup, .vhost_backend_get_vq_index = vhost_user_get_vq_index, .vhost_backend_set_vring_enable = vhost_user_set_vring_enable, + + .vhost_set_log_base = vhost_set_log_base, };
hw/virtio/vhost.c +3 -3
@@ -336,7 +336,7 @@ static inline void vhost_dev_log_resize(struct vhost_dev* dev, uint64_t size)/* inform backend of log switching, this must be done before releasing the current log, to ensure no logging is lost */ - r = dev->vhost_ops->vhost_call (dev,VHOST_SET_LOG_BASE , &log_base); + r = dev->vhost_ops->vhost_set_log_base (dev, log_base);assert (r >=0 );vhost_log_put (dev, true); dev->log = log;
@@ -1140,8 +1140,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) hdev->log_size =vhost_get_log_size (hdev); hdev->log =vhost_log_get (hdev->log_size); log_base = (uintptr_t )hdev->log->log; - r = hdev->vhost_ops->vhost_call (hdev,VHOST_SET_LOG_BASE , - hdev->log_size ? &log_base :NULL ); + r = hdev->vhost_ops->vhost_set_log_base (hdev, + hdev->log_size ? log_base :0 );if (r <0 ) { r = -errno; goto fail_log;
include/hw/virtio/vhost-backend.h +5 -0
@@ -27,13 +27,18 @@ typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev);typedef int (*vhost_backend_get_vq_index )(struct vhost_dev *dev,int idx);typedef int (*vhost_backend_set_vring_enable )(struct vhost_dev *dev,int enable); +typedef int (*vhost_set_log_base_op )(struct vhost_dev *dev,uint64_t base); +typedef struct VhostOps {VhostBackendType backend_type;vhost_call vhost_call; +vhost_backend_init vhost_backend_init;vhost_backend_cleanup vhost_backend_cleanup;vhost_backend_get_vq_index vhost_backend_get_vq_index;vhost_backend_set_vring_enable vhost_backend_set_vring_enable; + +vhost_set_log_base_op vhost_set_log_base; }VhostOps ;extern const VhostOps user_ops;
Signature · 1 line
2.4.3
PATCH v6 9/24 vhost-user: add vhost_user_requires_shm_log()
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Check if the backend has VHOST_USER_PROTOCOL_F_LOG_SHMFD feature and require a shared log.
--- hw/virtio/vhost-user.c | 14 ++++++++++++-- include/hw/virtio/vhost-backend.h | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-)
hw/virtio/vhost-user.c +12 -2
@@ -25,9 +25,10 @@#define VHOST_MEMORY_MAX_NREGIONS 8#define VHOST_USER_F_PROTOCOL_FEATURES 30 -#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x1ULL -#define VHOST_USER_PROTOCOL_F_MQ 0 +#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x3ULL +#define VHOST_USER_PROTOCOL_F_MQ 0 +#define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 typedef enum VhostUserRequest { VHOST_USER_NONE = 0,
@@ -453,6 +454,14 @@ static int vhost_user_get_vq_index(struct vhost_dev *dev, int idx)return idx; } +static bool vhost_user_requires_shm_log (struct vhost_dev *dev) +{ +assert (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_USER ); + +return virtio_has_feature (dev->protocol_features, +VHOST_USER_PROTOCOL_F_LOG_SHMFD ); +} +const VhostOps user_ops = { .backend_type =VHOST_BACKEND_TYPE_USER , .vhost_call = vhost_user_call,
@@ -462,4 +471,5 @@ const VhostOps user_ops = { .vhost_backend_set_vring_enable = vhost_user_set_vring_enable, .vhost_set_log_base = vhost_set_log_base, + .vhost_requires_shm_log = vhost_user_requires_shm_log, };
include/hw/virtio/vhost-backend.h +4 -0
@@ -11,6 +11,8 @@ #ifndef VHOST_BACKEND_H_ #define VHOST_BACKEND_H_ +#include <stdbool.h> + typedef enum VhostBackendType { VHOST_BACKEND_TYPE_NONE = 0, VHOST_BACKEND_TYPE_KERNEL = 1,
@@ -28,6 +30,7 @@ typedef int (*vhost_backend_get_vq_index)(struct vhost_dev *dev, int idx);typedef int (*vhost_backend_set_vring_enable )(struct vhost_dev *dev,int enable);typedef int (*vhost_set_log_base_op )(struct vhost_dev *dev,uint64_t base); +typedef bool (*vhost_requires_shm_log_op )(struct vhost_dev *dev); typedef struct VhostOps { VhostBackendType backend_type;
@@ -39,6 +42,7 @@ typedef struct VhostOps {vhost_backend_set_vring_enable vhost_backend_set_vring_enable;vhost_set_log_base_op vhost_set_log_base; +vhost_requires_shm_log_op vhost_requires_shm_log; } VhostOps;extern const VhostOps user_ops;
Signature · 1 line
2.4.3
PATCH v6 10/24 vhost: alloc shareable log
In reply to [email protected]From: Marc-André Lureau <[email protected]>
If the backend is requires it, allocate shareable memory.
vhost_log_get() now uses 2 globals "vhost_log" and "vhost_log_shm", that way there is a common non-shareable log and a common shareable one.
--- hw/virtio/vhost.c | 57 ++++++++++++++++++++++++++++++++++++++--------- include/hw/virtio/vhost.h | 3 ++- 2 files changed, 49 insertions(+), 11 deletions(-)
hw/virtio/vhost.c +47 -10
@@ -18,6 +18,7 @@#include "qemu/atomic.h" #include "qemu/range.h" #include "qemu/error-report.h" +#include "qemu/memfd.h" #include <linux/vhost.h> #include "exec/address-spaces.h" #include "hw/virtio/virtio-bus.h"
@@ -25,6 +26,7 @@#include "migration/migration.h" static struct vhost_log *vhost_log; +static struct vhost_log *vhost_log_shm; static void vhost_dev_sync_region(struct vhost_dev *dev, MemoryRegionSection *section,
@@ -286,25 +288,46 @@ static uint64_t vhost_get_log_size(struct vhost_dev *dev) }return log_size; } -static struct vhost_log *vhost_log_alloc (uint64_t size) + +static struct vhost_log *vhost_log_alloc (uint64_t size,bool share) { -struct vhost_log *log =g_malloc0 (sizeof *log + size *sizeof (*(log->log))); +struct vhost_log *log; +uint64_t logsize = size *sizeof (*(log->log)); +int fd =-1 ; + + log = g_new0(struct vhost_log, 1); +if (share) { + log->log =qemu_memfd_alloc ("vhost-log" , logsize, +F_SEAL_GROW |F_SEAL_SHRINK |F_SEAL_SEAL , + &fd); +memset (log->log,0 , logsize); + }else { + log->log =g_malloc0 (logsize); + } log->size = size; log->refcnt =1 ; + log->fd = fd;return log; } -static struct vhost_log *vhost_log_get (uint64_t size) +static struct vhost_log *vhost_log_get (uint64_t size,bool share) { -if (!vhost_log || vhost_log->size != size) { - vhost_log =vhost_log_alloc (size); +struct vhost_log *log = share ? vhost_log_shm : vhost_log; + +if (!log || log->size != size) { + log =vhost_log_alloc (size, share); +if (share) { + vhost_log_shm = log; + }else { + vhost_log = log; + } }else { - ++vhost_log->refcnt; + ++log->refcnt; } -return vhost_log; +return log; }static void vhost_log_put (struct vhost_dev *dev,bool sync)
@@ -321,16 +344,29 @@ static void vhost_log_put(struct vhost_dev *dev, bool sync)if (dev->log_size && sync) {vhost_log_sync_range (dev,0 , dev->log_size *VHOST_LOG_CHUNK -1 ); } +if (vhost_log == log) { +g_free (log->log); vhost_log =NULL ; + }else if (vhost_log_shm == log) { +qemu_memfd_free (log->log, log->size *sizeof (*(log->log)), + log->fd); + vhost_log_shm =NULL ; } +g_free (log); } } -static inline void vhost_dev_log_resize (struct vhost_dev * dev,uint64_t size) +static bool vhost_dev_log_is_shared (struct vhost_dev *dev) +{ +return dev->vhost_ops->vhost_requires_shm_log && + dev->vhost_ops->vhost_requires_shm_log (dev); +} + +static inline void vhost_dev_log_resize (struct vhost_dev *dev,uint64_t size) { -struct vhost_log *log =vhost_log_get (size); +struct vhost_log *log =vhost_log_get (size,vhost_dev_log_is_shared (dev));uint64_t log_base = (uintptr_t )log->log;int r;
@@ -1138,7 +1174,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev)uint64_t log_base; hdev->log_size =vhost_get_log_size (hdev); - hdev->log =vhost_log_get (hdev->log_size); + hdev->log =vhost_log_get (hdev->log_size, +vhost_dev_log_is_shared (hdev)); log_base = (uintptr_t )hdev->log->log; r = hdev->vhost_ops->vhost_set_log_base (hdev, hdev->log_size ? log_base :0 );
include/hw/virtio/vhost.h +2 -1
@@ -31,7 +31,8 @@ typedef unsigned long vhost_log_chunk_t;struct vhost_log {unsigned long long size;int refcnt; -vhost_log_chunk_t log[0 ]; +int fd; +vhost_log_chunk_t *log; };struct vhost_memory ;
Signature · 1 line
2.4.3
PATCH v6 11/24 vhost-user: send log shm fd along with log_base
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Send the shm for the dirty pages logging if the backend supports VHOST_USER_PROTOCOL_F_LOG_SHMFD. Wait for a reply to make sure the old log is no longer used.
--- hw/virtio/vhost-backend.c | 3 ++- hw/virtio/vhost-user.c | 27 +++++++++++++++++++++++++-- hw/virtio/vhost.c | 5 +++-- include/hw/virtio/vhost-backend.h | 4 +++- 4 files changed, 33 insertions(+), 6 deletions(-)
hw/virtio/vhost-backend.c +2 -1
@@ -50,7 +50,8 @@ static int vhost_kernel_get_vq_index(struct vhost_dev *dev, int idx)return idx - dev->vq_index; } -static int vhost_set_log_base (struct vhost_dev *dev,uint64_t base) +static int vhost_set_log_base (struct vhost_dev *dev,uint64_t base, +struct vhost_log *log) {return vhost_kernel_call (dev,VHOST_SET_LOG_BASE , &base); }
hw/virtio/vhost-user.c +25 -2
@@ -367,8 +367,13 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,return 0 ; } -static int vhost_set_log_base (struct vhost_dev *dev,uint64_t base) +static int vhost_set_log_base (struct vhost_dev *dev,uint64_t base, +struct vhost_log *log) { +int fds[VHOST_MEMORY_MAX_NREGIONS ]; +size_t fd_num =0 ; +bool shmfd =virtio_has_feature (dev->protocol_features, +VHOST_USER_PROTOCOL_F_LOG_SHMFD );VhostUserMsg msg = { .request =VHOST_USER_SET_LOG_BASE , .flags =VHOST_USER_VERSION ,
@@ -376,7 +381,25 @@ static int vhost_set_log_base(struct vhost_dev *dev, uint64_t base) .size = sizeof(m.u64), }; -vhost_user_write (dev, &msg,NULL ,0 ); +if (shmfd && log->fd !=-1 ) { + fds[fd_num++] = log->fd; + } + +vhost_user_write (dev, &msg, fds, fd_num); + +if (shmfd) { + msg.size =0 ; +if (vhost_user_read (dev, &msg) <0 ) { +return 0 ; + } + +if (msg.request !=VHOST_USER_SET_LOG_BASE ) { +error_report ("Received unexpected msg type. " +"Expected %d received %d" , +VHOST_USER_SET_LOG_BASE , msg.request); +return -1 ; + } + }return 0 ; }
hw/virtio/vhost.c +3 -2
@@ -372,7 +372,7 @@ static inline void vhost_dev_log_resize(struct vhost_dev *dev, uint64_t size)/* inform backend of log switching, this must be done before releasing the current log, to ensure no logging is lost */ - r = dev->vhost_ops->vhost_set_log_base (dev, log_base); + r = dev->vhost_ops->vhost_set_log_base (dev, log_base, log);assert (r >=0 );vhost_log_put (dev, true); dev->log = log;
@@ -1178,7 +1178,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) vhost_dev_log_is_shared(hdev)); log_base = (uintptr_t )hdev->log->log; r = hdev->vhost_ops->vhost_set_log_base (hdev, - hdev->log_size ? log_base :0 ); + hdev->log_size ? log_base :0 , + hdev->log);if (r <0 ) { r = -errno; goto fail_log;
include/hw/virtio/vhost-backend.h +3 -1
@@ -21,6 +21,7 @@ typedef enum VhostBackendType { } VhostBackendType;struct vhost_dev ; +struct vhost_log ;typedef int (*vhost_call )(struct vhost_dev *dev,unsigned long int request,void *arg);
@@ -29,7 +30,8 @@ typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev);typedef int (*vhost_backend_get_vq_index )(struct vhost_dev *dev,int idx);typedef int (*vhost_backend_set_vring_enable )(struct vhost_dev *dev,int enable); -typedef int (*vhost_set_log_base_op )(struct vhost_dev *dev,uint64_t base); +typedef int (*vhost_set_log_base_op )(struct vhost_dev *dev,uint64_t base, +struct vhost_log *log);typedef bool (*vhost_requires_shm_log_op )(struct vhost_dev *dev); typedef struct VhostOps {
Signature · 1 line
2.4.3
PATCH v6 12/24 vhost-user: add a migration blocker
In reply to [email protected]From: Marc-André Lureau <[email protected]>
If VHOST_USER_PROTOCOL_F_LOG_SHMFD is not announced, block vhost-user migration.
--- hw/virtio/vhost-user.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
hw/virtio/vhost-user.c +13 -0
@@ -15,6 +15,7 @@#include "qemu/error-report.h" #include "qemu/sockets.h" #include "exec/ram_addr.h" +#include "migration/migration.h" #include <fcntl.h> #include <unistd.h>
@@ -442,6 +443,14 @@ static int vhost_user_init(struct vhost_dev *dev, void *opaque) } } +if (!virtio_has_feature (dev->protocol_features, +VHOST_USER_PROTOCOL_F_LOG_SHMFD )) { +migrate_add_blocker (dev->migration_blocker); +error_setg (&dev->migration_blocker, +"Migration disabled: vhost-user backend lacks " +"VHOST_USER_PROTOCOL_F_LOG_SHMFD feature." ); + } +return 0 ; }
@@ -466,6 +475,10 @@ static int vhost_user_cleanup(struct vhost_dev *dev)assert (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_USER ); dev->opaque =0 ; +if (dev->migration_blocker) { +migrate_del_blocker (dev->migration_blocker); +error_free (dev->migration_blocker); + }return 0 ; }
Signature · 1 line
2.4.3
PATCH v6 13/24 vhost: use a function for each call
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Replace the generic vhost_call() by specific functions for each function call to help with type safety and changing arguments.
While doing this, I found that "unsigned long long" and "uint64_t" were used interchangeably and causing compilation warnings, using uint64_t instead, as the vhost & protocol specifies.
--- hw/net/vhost_net.c | 16 +- hw/scsi/vhost-scsi.c | 7 +- hw/virtio/vhost-backend.c | 124 ++++++++- hw/virtio/vhost-user.c | 518 ++++++++++++++++++++++---------------- hw/virtio/vhost.c | 36 +-- include/hw/virtio/vhost-backend.h | 63 ++++- include/hw/virtio/vhost.h | 12 +- 7 files changed, 501 insertions(+), 275 deletions(-)
hw/net/vhost_net.c +6 -10
@@ -252,8 +252,7 @@ static int vhost_net_start_one(struct vhost_net *net, file.fd = net->backend;for (file.index =0 ; file.index < net->dev.nvqs; ++file.index) {const VhostOps *vhost_ops = net->dev.vhost_ops; - r = vhost_ops->vhost_call (&net->dev,VHOST_NET_SET_BACKEND , - &file); + r = vhost_ops->vhost_net_set_backend (&net->dev, &file);if (r <0 ) { r = -errno; goto fail;
@@ -266,8 +265,7 @@ fail:if (net->nc->info->type ==NET_CLIENT_OPTIONS_KIND_TAP ) {while (file.index-- >0 ) {const VhostOps *vhost_ops = net->dev.vhost_ops; -int r = vhost_ops->vhost_call (&net->dev,VHOST_NET_SET_BACKEND , - &file); +int r = vhost_ops->vhost_net_set_backend (&net->dev, &file);assert (r >=0 ); } }
@@ -289,15 +287,13 @@ static void vhost_net_stop_one(struct vhost_net *net,if (net->nc->info->type ==NET_CLIENT_OPTIONS_KIND_TAP ) {for (file.index =0 ; file.index < net->dev.nvqs; ++file.index) {const VhostOps *vhost_ops = net->dev.vhost_ops; -int r = vhost_ops->vhost_call (&net->dev,VHOST_NET_SET_BACKEND , - &file); +int r = vhost_ops->vhost_net_set_backend (&net->dev, &file);assert (r >=0 ); } }else if (net->nc->info->type ==NET_CLIENT_OPTIONS_KIND_VHOST_USER ) {for (file.index =0 ; file.index < net->dev.nvqs; ++file.index) {const VhostOps *vhost_ops = net->dev.vhost_ops; -int r = vhost_ops->vhost_call (&net->dev,VHOST_RESET_DEVICE , -NULL ); +int r = vhost_ops->vhost_reset_device (&net->dev);assert (r >=0 ); } }
@@ -428,8 +424,8 @@ int vhost_set_vring_enable(NetClientState *nc, int enable)VHostNetState *net =get_vhost_net (nc);const VhostOps *vhost_ops = net->dev.vhost_ops; -if (vhost_ops->vhost_backend_set_vring_enable) { -return vhost_ops->vhost_backend_set_vring_enable (&net->dev, enable); +if (vhost_ops->vhost_set_vring_enable) { +return vhost_ops->vhost_set_vring_enable (&net->dev, enable); }return 0 ;
hw/scsi/vhost-scsi.c +3 -4
@@ -46,7 +46,7 @@ static int vhost_scsi_set_endpoint(VHostSCSI *s)memset (&backend,0 ,sizeof (backend));pstrcpy (backend.vhost_wwpn,sizeof (backend.vhost_wwpn), vs->conf.wwpn); - ret = vhost_ops->vhost_call (&s->dev,VHOST_SCSI_SET_ENDPOINT , &backend); + ret = vhost_ops->vhost_scsi_set_endpoint (&s->dev, &backend);if (ret <0 ) {return -errno; }
@@ -61,7 +61,7 @@ static void vhost_scsi_clear_endpoint(VHostSCSI *s)memset (&backend,0 ,sizeof (backend));pstrcpy (backend.vhost_wwpn,sizeof (backend.vhost_wwpn), vs->conf.wwpn); - vhost_ops->vhost_call (&s->dev,VHOST_SCSI_CLEAR_ENDPOINT , &backend); + vhost_ops->vhost_scsi_clear_endpoint (&s->dev, &backend); }static int vhost_scsi_start (VHostSCSI *s)
@@ -77,8 +77,7 @@ static int vhost_scsi_start(VHostSCSI *s)return -ENOSYS ; } - ret = vhost_ops->vhost_call (&s->dev, -VHOST_SCSI_GET_ABI_VERSION , &abi_version); + ret = vhost_ops->vhost_scsi_get_abi_version (&s->dev, &abi_version);if (ret <0 ) {return -errno; }
hw/virtio/vhost-backend.c +116 -8
143 lines not on this page · raw message
hw/virtio/vhost-user.c +296 -222
631 lines not on this page · raw message
hw/virtio/vhost.c +18 -18
@@ -538,7 +538,7 @@ static void vhost_commit(MemoryListener *listener) }if (!dev->log_enabled) { - r = dev->vhost_ops->vhost_call (dev,VHOST_SET_MEM_TABLE , dev->mem); + r = dev->vhost_ops->vhost_set_mem_table (dev, dev->mem);assert (r >=0 ); dev->memory_changed = false;return ;
@@ -551,7 +551,7 @@ static void vhost_commit(MemoryListener *listener)if (dev->log_size < log_size) {vhost_dev_log_resize (dev, log_size +VHOST_LOG_BUFFER ); } - r = dev->vhost_ops->vhost_call (dev,VHOST_SET_MEM_TABLE , dev->mem); + r = dev->vhost_ops->vhost_set_mem_table (dev, dev->mem);assert (r >=0 );/* To log less, can only decrease log size after table update. */ if (dev->log_size > log_size +VHOST_LOG_BUFFER ) {
@@ -619,7 +619,7 @@ static int vhost_virtqueue_set_addr(struct vhost_dev *dev, .log_guest_addr = vq->used_phys, .flags = enable_log ? (1 << VHOST_VRING_F_LOG) : 0, }; -int r = dev->vhost_ops->vhost_call (dev,VHOST_SET_VRING_ADDR , &addr); +int r = dev->vhost_ops->vhost_set_vring_addr (dev, &addr);if (r <0 ) {return -errno; }
@@ -633,7 +633,7 @@ static int vhost_dev_set_features(struct vhost_dev *dev, bool enable_log)if (enable_log) { features |=0x1ULL <<VHOST_F_LOG_ALL ; } - r = dev->vhost_ops->vhost_call (dev,VHOST_SET_FEATURES , &features); + r = dev->vhost_ops->vhost_set_features (dev, features);return r <0 ? -errno :0 ; }
@@ -738,7 +738,7 @@ static int vhost_virtqueue_set_vring_endian_legacy(struct vhost_dev *dev, .num = is_big_endian }; -if (!dev->vhost_ops->vhost_call (dev,VHOST_SET_VRING_ENDIAN , &s)) { +if (!dev->vhost_ops->vhost_set_vring_endian (dev, &s)) {return 0 ; }
@@ -757,7 +757,7 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, {hwaddr s, l, a;int r; -int vhost_vq_index = dev->vhost_ops->vhost_backend_get_vq_index (dev, idx); +int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index (dev, idx);struct vhost_vring_file file = { .index = vhost_vq_index };
@@ -768,13 +768,13 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, vq->num = state.num =virtio_queue_get_num (vdev, idx); - r = dev->vhost_ops->vhost_call (dev,VHOST_SET_VRING_NUM , &state); + r = dev->vhost_ops->vhost_set_vring_num (dev, &state);if (r) {return -errno; } state.num =virtio_queue_get_last_avail_idx (vdev, idx); - r = dev->vhost_ops->vhost_call (dev,VHOST_SET_VRING_BASE , &state); + r = dev->vhost_ops->vhost_set_vring_base (dev, &state);if (r) {return -errno; }
@@ -826,7 +826,7 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, } file.fd =event_notifier_get_fd (virtio_queue_get_host_notifier (vvq)); - r = dev->vhost_ops->vhost_call (dev,VHOST_SET_VRING_KICK , &file); + r = dev->vhost_ops->vhost_set_vring_kick (dev, &file);if (r) { r = -errno; goto fail_kick;
@@ -859,13 +859,13 @@ static void vhost_virtqueue_stop(struct vhost_dev *dev,struct vhost_virtqueue *vq, unsigned idx) { - int vhost_vq_index = dev->vhost_ops->vhost_backend_get_vq_index(dev, idx); + int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index(dev, idx);struct vhost_vring_state state = { .index = vhost_vq_index, };int r; - r = dev->vhost_ops->vhost_call (dev,VHOST_GET_VRING_BASE , &state); + r = dev->vhost_ops->vhost_get_vring_base (dev, &state);if (r <0 ) {fprintf (stderr,"vhost VQ %d ring restore failed: %d\n" , idx, r);fflush (stderr);
@@ -912,7 +912,7 @@ static void vhost_eventfd_del(MemoryListener *listener,static int vhost_virtqueue_init (struct vhost_dev *dev,struct vhost_virtqueue *vq,int n) { -int vhost_vq_index = dev->vhost_ops->vhost_backend_get_vq_index (dev, n); +int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index (dev, n);struct vhost_vring_file file = { .index = vhost_vq_index, };
@@ -922,7 +922,7 @@ static int vhost_virtqueue_init(struct vhost_dev *dev, } file.fd =event_notifier_get_fd (&vq->masked_notifier); - r = dev->vhost_ops->vhost_call (dev,VHOST_SET_VRING_CALL , &file); + r = dev->vhost_ops->vhost_set_vring_call (dev, &file);if (r) { r = -errno; goto fail_call;
@@ -954,12 +954,12 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,return -errno; } - r = hdev->vhost_ops->vhost_call (hdev,VHOST_SET_OWNER ,NULL ); + r = hdev->vhost_ops->vhost_set_owner (hdev);if (r <0 ) { goto fail; } - r = hdev->vhost_ops->vhost_call (hdev,VHOST_GET_FEATURES , &features); + r = hdev->vhost_ops->vhost_get_features (hdev, &features);if (r <0 ) { goto fail; }
@@ -1112,8 +1112,8 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n, file.fd =event_notifier_get_fd (virtio_queue_get_guest_notifier (vvq)); } - file.index = hdev->vhost_ops->vhost_backend_get_vq_index (hdev, n); - r = hdev->vhost_ops->vhost_call (hdev,VHOST_SET_VRING_CALL , &file); + file.index = hdev->vhost_ops->vhost_get_vq_index (hdev, n); + r = hdev->vhost_ops->vhost_set_vring_call (hdev, &file);assert (r >=0 ); }
@@ -1155,7 +1155,7 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev)if (r <0 ) { goto fail_features; } - r = hdev->vhost_ops->vhost_call (hdev,VHOST_SET_MEM_TABLE , hdev->mem); + r = hdev->vhost_ops->vhost_set_mem_table (hdev, hdev->mem);if (r <0 ) { r = -errno; goto fail_mem;
include/hw/virtio/vhost-backend.h +56 -7
84 lines not on this page · raw message
include/hw/virtio/vhost.h +6 -6
@@ -45,14 +45,14 @@ struct vhost_dev {int nvqs;/* the first virtqueue which would be used by this vhost dev */ int vq_index; -unsigned long long features; -unsigned long long acked_features; -unsigned long long backend_features; -unsigned long long protocol_features; -unsigned long long max_queues; +uint64_t features; +uint64_t acked_features; +uint64_t backend_features; +uint64_t protocol_features; +uint64_t max_queues;bool started;bool log_enabled; -unsigned long long log_size; +uint64_t log_size;Error *migration_blocker;bool memory_changed;hwaddr mem_changed_start_addr;
Signature · 1 line
2.4.3
PATCH v6 14/24 vhost-user: document migration log
In reply to [email protected]From: Marc-André Lureau <[email protected]>
--- docs/specs/vhost-user.txt | 48 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-)
docs/specs/vhost-user.txt +46 -2
@@ -115,11 +115,13 @@ the ones that do: * VHOST_GET_FEATURES * VHOST_GET_PROTOCOL_FEATURES * VHOST_GET_VRING_BASE + * VHOST_SET_LOG_BASE (if VHOST_USER_PROTOCOL_F_LOG_SHMFD) There are several messages that the master sends with file descriptors passed in the ancillary data: * VHOST_SET_MEM_TABLE + * VHOST_SET_LOG_BASE (if VHOST_USER_PROTOCOL_F_LOG_SHMFD) * VHOST_SET_LOG_FD * VHOST_SET_VRING_KICK * VHOST_SET_VRING_CALL
@@ -140,8 +142,7 @@ Multiple queue support Multiple queue is treated as a protocol extension, hence the slave has to implement protocol features first. The multiple queues feature is supported -only when the protocol feature VHOST_USER_PROTOCOL_F_MQ (bit 0) is set: -#define VHOST_USER_PROTOCOL_F_MQ 0 +only when the protocol feature VHOST_USER_PROTOCOL_F_MQ (bit 0) is set. The max number of queues the slave supports can be queried with message VHOST_USER_GET_PROTOCOL_FEATURES. Master should stop when the number of
@@ -152,6 +153,48 @@ queue in the sent message to identify a specified queue. One queue pair is enabled initially. More queues are enabled dynamically, by sending message VHOST_USER_SET_VRING_ENABLE. +Migration +--------- + +During live migration, the master may need to track the modifications +the slave makes to the memory mapped regions. The client should mark +the dirty pages in a log. Once it complies to this logging, it may +declare the VHOST_F_LOG_ALL vhost feature. + +All the modifications to memory pointed by vring "descriptor" should +be marked. Modifications to "used" vring should be marked if +VHOST_VRING_F_LOG is part of ring's features. + +Dirty pages are of size: +#define VHOST_LOG_PAGE 0x1000 + +The log memory fd is provided in the ancillary data of +VHOST_USER_SET_LOG_BASE message when the slave has +VHOST_USER_PROTOCOL_F_LOG_SHMFD protocol feature. + +The size of the log may be computed by using all the known guest +addresses. The log covers from address 0 to the maximum of guest +regions. In pseudo-code, to mark page at "addr" as dirty: + +page = addr / VHOST_LOG_PAGE +log[page / 8] |= 1 << page % 8 + +Use atomic operations, as the log may be concurrently manipulated. + +VHOST_USER_SET_LOG_FD is an optional message with an eventfd in +ancillary data, it may be used to inform the master that the log has +been modified. + +Once the source has finished migration, VHOST_USER_RESET_OWNER message +will be sent by the source. No further update must be done before the +destination takes over with new regions & rings. + +Protocol features +----------------- + +#define VHOST_USER_PROTOCOL_F_MQ 0 +#define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 + Message types -------------
@@ -236,6 +279,7 @@ Message types Id: 6 Equivalent ioctl: VHOST_SET_LOG_BASE Master payload: u64 + Slave payload: N/A Sets the logging base address.
Signature · 1 line
2.4.3
PATCH v6 15/24 net: add trace_vhost_user_event
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Replace error_report() and use tracing instead. It's not an error to get a connection or a disconnection, so silence this and trace it instead.
--- net/vhost-user.c | 4 ++-- trace-events | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)
net/vhost-user.c +2 -2
@@ -15,6 +15,7 @@#include "qemu/config-file.h" #include "qemu/error-report.h" #include "qmp-commands.h" +#include "trace.h" typedef struct VhostUserState { NetClientState nc;
@@ -148,18 +149,17 @@ static void net_vhost_user_event(void *opaque, int event)NET_CLIENT_OPTIONS_KIND_NIC , MAX_QUEUE_NUM); s =DO_UPCAST (VhostUserState, nc, ncs[0 ]); +trace_vhost_user_event (s->chr->label, event);switch (event) {case CHR_EVENT_OPENED :if (vhost_user_start (queues, ncs) <0 ) {exit (1 ); }qmp_set_link (name, true, &err); -error_report ("chardev \"%s\" went up" , s->chr->label);break ;case CHR_EVENT_CLOSED :qmp_set_link (name, true, &err);vhost_user_stop (queues, ncs); -error_report ("chardev \"%s\" went down" , s->chr->label);break ; }
trace-events +3 -0
@@ -1697,3 +1697,6 @@ qcrypto_tls_creds_x509_load_cert_list(void *creds, const char *file) "TLS creds # crypto/tlssession.c qcrypto_tls_session_new(void *session, void *creds, const char *hostname, const char *aclname, int endpoint) "TLS session new session=%p creds=%p hostname=%s aclname=%s endpoint=%d" + +# net/vhost-user.c +vhost_user_event(const char *chr, int event) "chr: %s got event: %d"
Signature · 1 line
2.4.3
PATCH v6 16/24 vhost user: add support of live migration
In reply to [email protected]From: Thibaut Collet <[email protected]>
Some vhost user backends are able to support live migration.
To provide this service the following features must be added:
1. Add the VIRTIO_NET_F_GUEST_ANNOUNCE capability to vhost-net when netdev backend is vhost-user.
2. Provide a nop receive callback to vhost-user.
This callback is called by:
* qemu_announce_self after a migration to send fake RARP to avoid network outage for peers talking to the migrated guest.
- For guest with GUEST_ANNOUNCE capabilities, guest already sends GARP when the bit VIRTIO_NET_S_ANNOUNCE is set.
=> These packets must be discarded.
- For guest without GUEST_ANNOUNCE capabilities, migration termination is notified when the guest sends packets.
=> These packets can be discarded.
* virtio_net_tx_bh with a dummy boot to send fake bootp/dhcp request. BIOS guest manages virtio driver to send 4 bootp/dhcp request in case of dummy boot.
=> These packets must be discarded.
--- hw/net/vhost_net.c | 2 ++ net/vhost-user.c | 10 ++++++++++ 2 files changed, 12 insertions(+)
hw/net/vhost_net.c +2 -0
@@ -85,6 +85,8 @@ static const int user_feature_bits[] = {VIRTIO_NET_F_CTRL_MAC_ADDR ,VIRTIO_NET_F_CTRL_GUEST_OFFLOADS , +VIRTIO_NET_F_GUEST_ANNOUNCE , +VIRTIO_NET_F_MQ ,VHOST_INVALID_FEATURE_BIT
net/vhost-user.c +10 -0
@@ -103,6 +103,15 @@ err:return -1 ; } +static ssize_t vhost_user_receive (NetClientState *nc,const uint8_t *buf, +size_t size) +{ +/* Discard the request that is received and managed by backend +* by an other way. +*/ +return size; +} +static void vhost_user_cleanup (NetClientState *nc) {VhostUserState *s =DO_UPCAST (VhostUserState, nc, nc);
@@ -132,6 +141,7 @@ static bool vhost_user_has_ufo(NetClientState *nc)static NetClientInfo net_vhost_user_info = { .type =NET_CLIENT_OPTIONS_KIND_VHOST_USER , .size =sizeof (VhostUserState), + .receive = vhost_user_receive, .cleanup = vhost_user_cleanup, .has_vnet_hdr = vhost_user_has_vnet_hdr, .has_ufo = vhost_user_has_ufo,
Signature · 1 line
2.4.3
PATCH v6 17/24 vhost user: add rarp sending after live migration for legacy guest
In reply to [email protected]From: Thibaut Collet <[email protected]>
A new vhost user message is added to allow QEMU to ask to vhost user backend to broadcast a fake RARP after live migration for guest without GUEST_ANNOUNCE capability.
This new message is sent only if the backend supports the new VHOST_USER_PROTOCOL_F_RARP protocol feature.
The payload of this new message is the MAC address of the guest (not known by the backend). The MAC address is copied in the first 6 bytes of a u64 to avoid to create a new payload message type.
This new message has no equivalent ioctl so a new callback is added in the userOps structure to send the request.
Upon reception of this new message the vhost user backend must generate and broadcast a fake RARP request to notify the migration is terminated.
--- docs/specs/vhost-user.txt | 15 +++++++++++++++ hw/net/vhost_net.c | 17 +++++++++++++++++ hw/virtio/vhost-user.c | 32 +++++++++++++++++++++++++++++++- include/hw/virtio/vhost-backend.h | 3 +++ include/net/vhost_net.h | 1 + net/vhost-user.c | 24 ++++++++++++++++++++++-- 6 files changed, 89 insertions(+), 3 deletions(-)
docs/specs/vhost-user.txt +15 -0
@@ -194,6 +194,7 @@ Protocol features #define VHOST_USER_PROTOCOL_F_MQ 0 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 +#define VHOST_USER_PROTOCOL_F_RARP 2 Message types -------------
@@ -381,3 +382,17 @@ Message types Master payload: vring state description Signal slave to enable or disable corresponding vring. + + * VHOST_USER_SEND_RARP + + Id: 19 + Equivalent ioctl: N/A + Master payload: u64 + + Ask vhost user backend to broadcast a fake RARP to notify the migration + is terminated for guest that does not support GUEST_ANNOUNCE. + Only legal if feature bit VHOST_USER_F_PROTOCOL_FEATURES is present in + VHOST_USER_GET_FEATURES and protocol feature bit VHOST_USER_PROTOCOL_F_RARP + is present in VHOST_USER_GET_PROTOCOL_FEATURES. + The first 6 bytes of the payload contain the mac address of the guest to + allow the vhost user backend to construct and broadcast the fake RARP.
hw/net/vhost_net.c +17 -0
@@ -388,6 +388,18 @@ void vhost_net_cleanup(struct vhost_net *net)g_free (net); } +int vhost_net_notify_migration_done (struct vhost_net *net,char * mac_addr) +{ +const VhostOps *vhost_ops = net->dev.vhost_ops; +int r =-1 ; + +if (vhost_ops->vhost_migration_done) { + r = vhost_ops->vhost_migration_done (&net->dev, mac_addr); + } + +return r; +} +bool vhost_net_virtqueue_pending (VHostNetState *net,int idx) {return vhost_virtqueue_pending (&net->dev, idx);
@@ -479,6 +491,11 @@ void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev, { } +int vhost_net_notify_migration_done (struct vhost_net *net) +{ +return -1 ; +} +VHostNetState *get_vhost_net (NetClientState *nc) {return 0 ;
hw/virtio/vhost-user.c +31 -1
@@ -10,6 +10,7 @@#include "hw/virtio/vhost.h" #include "hw/virtio/vhost-backend.h" +#include "hw/virtio/virtio-net.h" #include "sysemu/char.h" #include "sysemu/kvm.h" #include "qemu/error-report.h"
@@ -27,9 +28,10 @@#define VHOST_MEMORY_MAX_NREGIONS 8#define VHOST_USER_F_PROTOCOL_FEATURES 30 -#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x3ULL +#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x7ULL#define VHOST_USER_PROTOCOL_F_MQ 0#define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 +#define VHOST_USER_PROTOCOL_F_RARP 2 typedef enum VhostUserRequest { VHOST_USER_NONE = 0,
@@ -51,6 +53,7 @@ typedef enum VhostUserRequest {VHOST_USER_SET_PROTOCOL_FEATURES =16 ,VHOST_USER_GET_QUEUE_NUM =17 ,VHOST_USER_SET_VRING_ENABLE =18 , +VHOST_USER_SEND_RARP =19 , VHOST_USER_MAX } VhostUserRequest;
@@ -561,6 +564,32 @@ static bool vhost_user_requires_shm_log(struct vhost_dev *dev) VHOST_USER_PROTOCOL_F_LOG_SHMFD); } +static int vhost_user_migration_done (struct vhost_dev *dev,char * mac_addr) +{ +VhostUserMsg msg = {0 }; +int err; + +assert (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_USER ); + +/* If guest supports GUEST_ANNOUNCE do nothing */ +if (virtio_has_feature (dev->acked_features,VIRTIO_NET_F_GUEST_ANNOUNCE )) { +return 0 ; + } + +/* if backend supports VHOST_USER_PROTOCOL_F_RARP ask it to send the RARP */ +if (virtio_has_feature (dev->protocol_features, +VHOST_USER_PROTOCOL_F_RARP )) { + msg.request =VHOST_USER_SEND_RARP ; + msg.flags =VHOST_USER_VERSION ; +memcpy ((char *)&msg.u64, mac_addr,6 ); + msg.size =sizeof (m.u64); + + err =vhost_user_write (dev, &msg,NULL ,0 ); +return err; + } +return -1 ; +} +const VhostOps user_ops = { .backend_type =VHOST_BACKEND_TYPE_USER , .vhost_backend_init = vhost_user_init,
@@ -582,4 +611,5 @@ const VhostOps user_ops = { .vhost_get_vq_index = vhost_user_get_vq_index, .vhost_set_vring_enable = vhost_user_set_vring_enable, .vhost_requires_shm_log = vhost_user_requires_shm_log, + .vhost_migration_done = vhost_user_migration_done, };
include/hw/virtio/vhost-backend.h +3 -0
@@ -67,6 +67,8 @@ typedef int (*vhost_get_vq_index_op)(struct vhost_dev *dev, int idx);typedef int (*vhost_set_vring_enable_op )(struct vhost_dev *dev,int enable);typedef bool (*vhost_requires_shm_log_op )(struct vhost_dev *dev); +typedef int (*vhost_migration_done_op )(struct vhost_dev *dev, +char *mac_addr); typedef struct VhostOps { VhostBackendType backend_type;
@@ -94,6 +96,7 @@ typedef struct VhostOps {vhost_get_vq_index_op vhost_get_vq_index;vhost_set_vring_enable_op vhost_set_vring_enable;vhost_requires_shm_log_op vhost_requires_shm_log; +vhost_migration_done_op vhost_migration_done; } VhostOps;extern const VhostOps user_ops;
include/net/vhost_net.h +1 -0
@@ -27,6 +27,7 @@ void vhost_net_ack_features(VHostNetState *net, uint64_t features);bool vhost_net_virtqueue_pending (VHostNetState *net,int n);void vhost_net_virtqueue_mask (VHostNetState *net,VirtIODevice *dev,int idx,bool mask); +int vhost_net_notify_migration_done (VHostNetState *net,char * mac_addr);VHostNetState *get_vhost_net (NetClientState *nc);int vhost_set_vring_enable (NetClientState * nc,int enable);
net/vhost-user.c +22 -2
@@ -106,9 +106,29 @@ err:static ssize_t vhost_user_receive (NetClientState *nc,const uint8_t *buf,size_t size) { -/* Discard the request that is received and managed by backend -* by an other way. +/* In case of RARP (message size is 60) notify backup to send a fake RARP. +This fake RARP will be sent by backend only for guest +without GUEST_ANNOUNCE capability. */ +if (size ==60 ) { +VhostUserState *s =DO_UPCAST (VhostUserState, nc, nc); +int r; +static int display_rarp_failure =1 ; +char mac_addr[6 ]; + +/* extract guest mac address from the RARP message */ +memcpy (mac_addr, &buf[6 ],6 ); + + r =vhost_net_notify_migration_done (s->vhost_net, mac_addr); + +if ((r !=0 ) && (display_rarp_failure)) { +fprintf (stderr, +"Vhost user backend fails to broadcast fake RARP\n" ); +fflush (stderr); + display_rarp_failure =0 ; + } + } +return size; }
Signature · 1 line
2.4.3
PATCH v6 18/24 vhost-user-test: move wait_for_fds() out
In reply to [email protected]From: Marc-André Lureau <[email protected]>
This function is a precondition for most vhost-user tests.
--- tests/vhost-user-test.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
tests/vhost-user-test.c +12 -5
@@ -205,15 +205,11 @@ static GThread *_thread_new(const gchar *name, GThreadFunc func, gpointer data)return thread; } -static void read_guest_mem (void ) +static void wait_for_fds (void ) { -uint32_t *guest_mem;gint64 end_time; -int i, j; -size_t size;g_mutex_lock (data_mutex); - end_time =_get_time () +5 *G_TIME_SPAN_SECOND ;while (!fds_num) {if (!_cond_wait_until (data_cond, data_mutex, end_time)) {
@@ -227,6 +223,17 @@ static void read_guest_mem(void) g_assert_cmpint(fds_num, >, 0); g_assert_cmpint(fds_num, ==, memory.nregions); +g_mutex_unlock (data_mutex); +} + +static void read_guest_mem (void ) +{ +uint32_t *guest_mem; +int i, j; +size_t size; + +wait_for_fds (); +/* iterate all regions */ for (i =0 ; i < fds_num; i++) {
Signature · 1 line
2.4.3
PATCH v6 19/24 vhost-user-test: remove useless static check
In reply to [email protected]From: Marc-André Lureau <[email protected]>
--- tests/vhost-user-test.c | 1 - 1 file changed, 1 deletion(-)
tests/vhost-user-test.c +0 -1
@@ -262,7 +262,6 @@ static void read_guest_mem(void)munmap (guest_mem, memory.regions[i].memory_size); } - g_assert_cmpint(1, ==, 1);g_mutex_unlock (data_mutex); }
Signature · 1 line
2.4.3
PATCH v6 20/24 vhost-user-test: wrap server in TestServer struct
In reply to [email protected]From: Marc-André Lureau <[email protected]>
In the coming patches, a test will use several servers simultaneously. Wrap the server in a struct, out of the global scope.
--- tests/vhost-user-test.c | 146 ++++++++++++++++++++++++++++++------------------ 1 file changed, 92 insertions(+), 54 deletions(-)
tests/vhost-user-test.c +92 -54
@@ -115,10 +115,18 @@ static VhostUserMsg m __attribute__ ((unused));#define VHOST_USER_VERSION (0x1)/*****************************************************************************/ -int fds_num =0 , fds[VHOST_MEMORY_MAX_NREGIONS ]; -static VhostUserMemory memory; -static GMutex *data_mutex; -static GCond *data_cond; +typedef struct TestServer { +gchar *socket_path; +gchar *chr_name; +CharDriverState *chr; +int fds_num; +int fds[VHOST_MEMORY_MAX_NREGIONS ]; +VhostUserMemory memory; +GMutex *data_mutex; +GCond *data_cond; +}TestServer ; + +static const char *hugefs;static gint64 _get_time (void ) {
@@ -205,64 +213,63 @@ static GThread *_thread_new(const gchar *name, GThreadFunc func, gpointer data)return thread; } -static void wait_for_fds (void ) +static void wait_for_fds (TestServer *s) {gint64 end_time; -g_mutex_lock (data_mutex); +g_mutex_lock (s->data_mutex); end_time =_get_time () +5 *G_TIME_SPAN_SECOND ; -while (!fds_num) { -if (!_cond_wait_until (data_cond, data_mutex, end_time)) { +while (!s->fds_num) { +if (!_cond_wait_until (s->data_cond, s->data_mutex, end_time)) {/* timeout has passed */ -g_assert (fds_num); +g_assert (s->fds_num);break ; } }/* check for sanity */ - g_assert_cmpint(fds_num, >, 0); - g_assert_cmpint(fds_num, ==, memory.nregions); + g_assert_cmpint(s->fds_num, >, 0); + g_assert_cmpint(s->fds_num, ==, s->memory.nregions); -g_mutex_unlock (data_mutex); +g_mutex_unlock (s->data_mutex); } -static void read_guest_mem (void ) +static void read_guest_mem (TestServer *s) {uint32_t *guest_mem;int i, j;size_t size; -wait_for_fds (); +wait_for_fds (s);/* iterate all regions */ -for (i =0 ; i < fds_num; i++) { +for (i =0 ; i < s->fds_num; i++) {/* We'll check only the region statring at 0x0*/ -if (memory.regions[i].guest_phys_addr !=0x0 ) { +if (s->memory.regions[i].guest_phys_addr !=0x0 ) {continue ; } - g_assert_cmpint(memory.regions[i].memory_size, >, 1024); + g_assert_cmpint(s->memory.regions[i].memory_size, >, 1024); - size = memory.regions[i].memory_size + memory.regions[i].mmap_offset; + size = s->memory.regions[i].memory_size + + s->memory.regions[i].mmap_offset; guest_mem =mmap (0 , size,PROT_READ |PROT_WRITE , -MAP_SHARED , fds[i],0 ); +MAP_SHARED , s->fds[i],0 );g_assert (guest_mem !=MAP_FAILED ); - guest_mem += (memory.regions[i].mmap_offset /sizeof (*guest_mem)); + guest_mem += (s->memory.regions[i].mmap_offset /sizeof (*guest_mem));for (j =0 ; j <256 ; j++) { -uint32_t a =readl (memory.regions[i].guest_phys_addr + j*4 ); +uint32_t a =readl (s->memory.regions[i].guest_phys_addr + j*4 );uint32_t b = guest_mem[j]; g_assert_cmpint(a, ==, b); } -munmap (guest_mem, memory.regions[i].memory_size); +munmap (guest_mem, s->memory.regions[i].memory_size); } - -g_mutex_unlock (data_mutex); }static void *thread_function (void *data)
@@ -280,7 +287,8 @@ static int chr_can_read(void *opaque)static void chr_read (void *opaque,const uint8_t *buf,int size) { -CharDriverState *chr = opaque; +TestServer *s = opaque; +CharDriverState *chr = s->chr;VhostUserMsg msg;uint8_t *p = (uint8_t *) &msg;int fd;
@@ -290,12 +298,12 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)return ; } -g_mutex_lock (data_mutex); +g_mutex_lock (s->data_mutex);memcpy (p, buf,VHOST_USER_HDR_SIZE );if (msg.size) { p +=VHOST_USER_HDR_SIZE ; -qemu_chr_fe_read_all (chr, p, msg.size); + g_assert_cmpint(qemu_chr_fe_read_all(chr, p, msg.size), ==, msg.size); }switch (msg.request) {
@@ -334,11 +342,11 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)case VHOST_USER_SET_MEM_TABLE :/* received the mem table */ -memcpy (&memory, &msg.memory,sizeof (msg.memory)); - fds_num =qemu_chr_fe_get_msgfds (chr, fds,sizeof (fds) /sizeof (int )); +memcpy (&s->memory, &msg.memory,sizeof (msg.memory)); + s->fds_num =qemu_chr_fe_get_msgfds (chr, s->fds,G_N_ELEMENTS (s->fds));/* signal the test that it can continue */ -g_cond_signal (data_cond); +g_cond_signal (s->data_cond);break ;case VHOST_USER_SET_VRING_KICK :
@@ -355,7 +363,53 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)default :break ; } -g_mutex_unlock (data_mutex); + +g_mutex_unlock (s->data_mutex); +} + +static TestServer *test_server_new (const gchar *name) +{ +TestServer *server =g_new0 (TestServer,1 ); +gchar *chr_path; + + server->socket_path =g_strdup_printf ("/tmp/vhost-%s-%d.sock" , + name,getpid ()); + + chr_path =g_strdup_printf ("unix:%s,server,nowait" , server->socket_path); + server->chr_name =g_strdup_printf ("chr-%s" , name); + server->chr =qemu_chr_new (server->chr_name, chr_path,NULL ); +g_free (chr_path); + +qemu_chr_add_handlers (server->chr, chr_can_read, chr_read,NULL , server); + +/* run the main loop thread so the chardev may operate */ + server->data_mutex =_mutex_new (); + server->data_cond =_cond_new (); + +return server; +} + +#define GET_QEMU_CMD (s) \ + g_strdup_printf(QEMU_CMD, (hugefs), (s)->socket_path) + + +static void test_server_free (TestServer *server) +{ +int i; + +qemu_chr_delete (server->chr); + +for (i =0 ; i < server->fds_num; i++) { +close (server->fds[i]); + } + +unlink (server->socket_path); +g_free (server->socket_path); + +_cond_free (server->data_cond); +_mutex_free (server->data_mutex); + +g_free (server); }static const char *init_hugepagefs (void )
@@ -394,41 +448,28 @@ static const char *init_hugepagefs(void)int main (int argc,char **argv) {QTestState *s =NULL ; -CharDriverState *chr =NULL ; -const char *hugefs =0 ; -char *socket_path =0 ; -char *qemu_cmd =0 ; -char *chr_path =0 ; +TestServer *server =NULL ; +char *qemu_cmd;int ret;g_test_init (&argc, &argv,NULL );module_call_init (MODULE_INIT_QOM ); +qemu_add_opts (&qemu_chardev_opts); hugefs =init_hugepagefs ();if (!hugefs) {return 0 ; } - socket_path =g_strdup_printf ("/tmp/vhost-%d.sock" ,getpid ()); - -/* create char dev and add read handlers */ -qemu_add_opts (&qemu_chardev_opts); - chr_path =g_strdup_printf ("unix:%s,server,nowait" , socket_path); - chr =qemu_chr_new ("chr0" , chr_path,NULL ); -g_free (chr_path); -qemu_chr_add_handlers (chr, chr_can_read, chr_read,NULL , chr); - -/* run the main loop thread so the chardev may operate */ - data_mutex =_mutex_new (); - data_cond =_cond_new ();_thread_new (NULL , thread_function,NULL ); - qemu_cmd =g_strdup_printf (QEMU_CMD , hugefs, socket_path); + server =test_server_new ("test" ); + qemu_cmd =GET_QEMU_CMD (server); s =qtest_start (qemu_cmd);g_free (qemu_cmd); -qtest_add_func ("/vhost-user/read-guest-mem" , read_guest_mem); +qtest_add_data_func ("/vhost-user/read-guest-mem" , server, read_guest_mem); ret =g_test_run ();
@@ -437,10 +478,7 @@ int main(int argc, char **argv) }/* cleanup */ -unlink (socket_path); -g_free (socket_path); -_cond_free (data_cond); -_mutex_free (data_mutex); +test_server_free (server);return ret; }
Signature · 1 line
2.4.3
PATCH v6 21/24 vhost-user-test: learn to tweak various qemu arguments
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Add a new macro to make the qemu command line with other values of memory size, and specific chardev id.
--- tests/vhost-user-test.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
tests/vhost-user-test.c +9 -5
@@ -37,10 +37,10 @@#endif #define QEMU_CMD_ACCEL " -machine accel=tcg" -#define QEMU_CMD_MEM " -m 512 -object memory-backend-file,id=mem,size=512M,"\ +#define QEMU_CMD_MEM " -m %d -object memory-backend-file,id=mem,size=%dM,"\ "mem-path=%s,share=on -numa node,memdev=mem" -#define QEMU_CMD_CHR " -chardev socket,id=chr0,path=%s" -#define QEMU_CMD_NETDEV " -netdev vhost-user,id=net0,chardev=chr0,vhostforce" +#define QEMU_CMD_CHR " -chardev socket,id=%s,path=%s" +#define QEMU_CMD_NETDEV " -netdev vhost-user,id=net0,chardev=%s,vhostforce"#define QEMU_CMD_NET " -device virtio-net-pci,netdev=net0 "#define QEMU_CMD_ROM " -option-rom ../pc-bios/pxe-virtio.rom"
@@ -389,9 +389,13 @@ static TestServer *test_server_new(const gchar *name)return server; } -#define GET_QEMU_CMD (s) \ - g_strdup_printf(QEMU_CMD, (hugefs), (s)->socket_path) +#define GET_QEMU_CMD (s) \ + g_strdup_printf(QEMU_CMD, 512, 512, (hugefs), \ + (s)->chr_name, (s)->socket_path, (s)->chr_name) +#define GET_QEMU_CMDE (s, mem, extra, ...) \ + g_strdup_printf(QEMU_CMD extra, (mem), (mem), (hugefs), \ + (s)->chr_name, (s)->socket_path, (s)->chr_name, ##__VA_ARGS__)static void test_server_free (TestServer *server) {
Signature · 1 line
2.4.3
PATCH v6 22/24 vhost-user-test: add live-migration test
In reply to [email protected]From: Marc-André Lureau <[email protected]>
This test checks that the log fd is given to the migration source, and mark dirty pages during migration.
--- tests/vhost-user-test.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 168 insertions(+), 3 deletions(-)
tests/vhost-user-test.c +168 -3
@@ -13,6 +13,7 @@#include "libqtest.h" #include "qemu/option.h" +#include "qemu/range.h" #include "sysemu/char.h" #include "sysemu/sysemu.h"
@@ -54,6 +55,9 @@#define VHOST_MEMORY_MAX_NREGIONS 8#define VHOST_USER_F_PROTOCOL_FEATURES 30 +#define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 + +#define VHOST_LOG_PAGE 0x1000 typedef enum VhostUserRequest { VHOST_USER_NONE = 0,
@@ -124,6 +128,7 @@ typedef struct TestServer {VhostUserMemory memory;GMutex *data_mutex;GCond *data_cond; +int log_fd; } TestServer;static const char *hugefs;
@@ -311,7 +316,8 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)/* send back features to qemu */ msg.flags |=VHOST_USER_REPLY_MASK ; msg.size =sizeof (m.u64); - msg.u64 =0x1ULL <<VHOST_USER_F_PROTOCOL_FEATURES ; + msg.u64 =0x1ULL <<VHOST_F_LOG_ALL | +0x1ULL <<VHOST_USER_F_PROTOCOL_FEATURES ; p = (uint8_t *) &msg;qemu_chr_fe_write_all (chr, p,VHOST_USER_HDR_SIZE + msg.size);break ;
@@ -325,12 +331,11 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)/* send back features to qemu */ msg.flags |=VHOST_USER_REPLY_MASK ; msg.size =sizeof (m.u64); - msg.u64 =0 ; + msg.u64 =1 <<VHOST_USER_PROTOCOL_F_LOG_SHMFD ; p = (uint8_t *) &msg;qemu_chr_fe_write_all (chr, p,VHOST_USER_HDR_SIZE + msg.size);break ; -case VHOST_USER_GET_VRING_BASE :/* send back vring base to qemu */ msg.flags |=VHOST_USER_REPLY_MASK ;
@@ -360,6 +365,21 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)*/ qemu_set_nonblock (fd);break ; + +case VHOST_USER_SET_LOG_BASE : +if (s->log_fd !=-1 ) { +close (s->log_fd); + s->log_fd =-1 ; + } +qemu_chr_fe_get_msgfds (chr, &s->log_fd,1 ); + msg.flags |=VHOST_USER_REPLY_MASK ; + msg.size =0 ; + p = (uint8_t *) &msg; +qemu_chr_fe_write_all (chr, p,VHOST_USER_HDR_SIZE ); + +g_cond_signal (s->data_cond); +break ; +default :break ; }
@@ -386,6 +406,8 @@ static TestServer *test_server_new(const gchar *name) server->data_mutex =_mutex_new (); server->data_cond =_cond_new (); + server->log_fd =-1 ; +return server; }
@@ -407,15 +429,157 @@ static void test_server_free(TestServer *server)close (server->fds[i]); } +if (server->log_fd !=-1 ) { +close (server->log_fd); + } +unlink (server->socket_path);g_free (server->socket_path);_cond_free (server->data_cond);_mutex_free (server->data_mutex); +g_free (server->chr_name);g_free (server); } +static void wait_for_log_fd (TestServer *s) +{ +gint64 end_time; + +g_mutex_lock (s->data_mutex); + end_time =_get_time () +5 *G_TIME_SPAN_SECOND ; +while (s->log_fd ==-1 ) { +if (!_cond_wait_until (s->data_cond, s->data_mutex, end_time)) { +/* timeout has passed */ +g_assert (s->log_fd !=-1 ); +break ; + } + } + +g_mutex_unlock (s->data_mutex); +} + +static void write_guest_mem (TestServer *s,uint32 seed) +{ +uint32_t *guest_mem; +int i, j; +size_t size; + +wait_for_fds (s); + +/* iterate all regions */ +for (i =0 ; i < s->fds_num; i++) { + +/* We'll write only the region statring at 0x0 */ +if (s->memory.regions[i].guest_phys_addr !=0x0 ) { +continue ; + } + + g_assert_cmpint(s->memory.regions[i].memory_size, >, 1024); + + size = s->memory.regions[i].memory_size + + s->memory.regions[i].mmap_offset; + + guest_mem =mmap (0 , size,PROT_READ |PROT_WRITE , +MAP_SHARED , s->fds[i],0 ); + +g_assert (guest_mem !=MAP_FAILED ); + guest_mem += (s->memory.regions[i].mmap_offset /sizeof (*guest_mem)); + +for (j =0 ; j <256 ; j++) { + guest_mem[j] = seed + j; + } + +munmap (guest_mem, s->memory.regions[i].memory_size); +break ; + } +} + +static guint64 get_log_size (TestServer *s) +{ +guint64 log_size =0 ; +int i; + +for (i =0 ; i < s->memory.nregions; ++i) { +VhostUserMemoryRegion *reg = &s->memory.regions[i]; +guint64 last =range_get_last (reg->guest_phys_addr, + reg->memory_size); + log_size =MAX (log_size, last / (8 *VHOST_LOG_PAGE ) +1 ); + } + +return log_size; +} + +static void test_migrate (void ) +{ +TestServer *s =test_server_new ("src" ); +TestServer *dest =test_server_new ("dest" ); +const char *uri ="tcp:127.0.0.1:1234" ; +QTestState *global = global_qtest, *from, *to; +gchar *cmd; +QDict *rsp; +guint8 *log; +guint64 size; + + cmd =GET_QEMU_CMDE (s,2 ,"" ); + from =qtest_start (cmd); +g_free (cmd); + +wait_for_fds (s); + size =get_log_size (s); + g_assert_cmpint(size, ==, (2 * 1024 * 1024) / (VHOST_LOG_PAGE * 8)); + + cmd =GET_QEMU_CMDE (dest,2 ," -incoming %s" , uri); + to =qtest_init (cmd); +g_free (cmd); + +/* slow down migration to have time to fiddle with log */ +/* TODO: qtest could learn to break on some places */ + rsp =qmp ("{ 'execute': 'migrate_set_speed'," +"'arguments': { 'value': 10 } }" ); +g_assert (qdict_haskey (rsp,"return" )); +QDECREF (rsp); + + cmd =g_strdup_printf ("{ 'execute': 'migrate'," +"'arguments': { 'uri': '%s' } }" , + uri); + rsp =qmp (cmd); +g_free (cmd); +g_assert (qdict_haskey (rsp,"return" )); +QDECREF (rsp); + +wait_for_log_fd (s); + + log =mmap (0 , size,PROT_READ |PROT_WRITE ,MAP_SHARED , s->log_fd,0 ); +g_assert (log !=MAP_FAILED ); + +/* modify first page */ +write_guest_mem (s,0x42 ); + log[0 ] =1 ; +munmap (log, size); + +/* speed things up */ + rsp =qmp ("{ 'execute': 'migrate_set_speed'," +"'arguments': { 'value': 0 } }" ); +g_assert (qdict_haskey (rsp,"return" )); +QDECREF (rsp); + +qmp_eventwait ("STOP" ); + + global_qtest = to; +qmp_eventwait ("RESUME" ); + +read_guest_mem (dest); + +qtest_quit (to); +test_server_free (dest); +qtest_quit (from); +test_server_free (s); + + global_qtest = global; +} +static const char *init_hugepagefs (void ) {const char *path;
@@ -474,6 +638,7 @@ int main(int argc, char **argv)g_free (qemu_cmd);qtest_add_data_func ("/vhost-user/read-guest-mem" , server, read_guest_mem); +qtest_add_func ("/vhost-user/migrate" , test_migrate); ret =g_test_run ();
Signature · 1 line
2.4.3
PATCH v6 23/24 vhost-user-test: check ownership during migration
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Check that backend source and destination do not have simultaneous ownership during migration.
--- tests/vhost-user-test.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
tests/vhost-user-test.c +38 -0
@@ -380,6 +380,10 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)g_cond_signal (s->data_cond);break ; +case VHOST_USER_RESET_DEVICE : + s->fds_num =0 ; +break ; +default :break ; }
@@ -511,12 +515,37 @@ static guint64 get_log_size(TestServer *s)return log_size; } +typedef struct TestMigrateSource { +GSource source; +TestServer *src; +TestServer *dest; +}TestMigrateSource ; + +static gboolean +test_migrate_source_check (GSource *source) +{ +TestMigrateSource *t = (TestMigrateSource *)source; +gboolean overlap = t->src->fds_num >0 && t->dest->fds_num >0 ; + +g_assert (!overlap); + +return FALSE; +} + +GSourceFuncs test_migrate_source_funcs = { +NULL , + test_migrate_source_check, +NULL , +NULL +}; +static void test_migrate (void ) {TestServer *s =test_server_new ("src" );TestServer *dest =test_server_new ("dest" );const char *uri ="tcp:127.0.0.1:1234" ;QTestState *global = global_qtest, *from, *to; +GSource *source;gchar *cmd;QDict *rsp;guint8 *log;
@@ -534,6 +563,12 @@ static void test_migrate(void) to =qtest_init (cmd);g_free (cmd); + source =g_source_new (&test_migrate_source_funcs, +sizeof (TestMigrateSource)); + ((TestMigrateSource *)source)->src = s; + ((TestMigrateSource *)source)->dest = dest; +g_source_attach (source,NULL ); +/* slow down migration to have time to fiddle with log */ /* TODO: qtest could learn to break on some places */ rsp = qmp("{ 'execute': 'migrate_set_speed',"
@@ -572,6 +607,9 @@ static void test_migrate(void)read_guest_mem (dest); +g_source_destroy (source); +g_source_unref (source); +qtest_quit (to);test_server_free (dest);qtest_quit (from);
Signature · 1 line
2.4.3
PATCH v6 24/24 vhost-user: use an enum helper for features mask
In reply to [email protected]From: Thibaut Collet <[email protected]>
The VHOST_USER_PROTOCOL_FEATURE_MASK will be automatically updated when adding new features to the enum.
--- hw/virtio/vhost-user.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
hw/virtio/vhost-user.c +9 -4
@@ -28,10 +28,15 @@#define VHOST_MEMORY_MAX_NREGIONS 8#define VHOST_USER_F_PROTOCOL_FEATURES 30 -#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x7ULL -#define VHOST_USER_PROTOCOL_F_MQ 0 -#define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 -#define VHOST_USER_PROTOCOL_F_RARP 2 +enum VhostUserProtocolFeature { +VHOST_USER_PROTOCOL_F_MQ =0 , +VHOST_USER_PROTOCOL_F_LOG_SHMFD =1 , +VHOST_USER_PROTOCOL_F_RARP =2 , + +VHOST_USER_PROTOCOL_F_MAX +}; + +#define VHOST_USER_PROTOCOL_FEATURE_MASK ((1 << VHOST_USER_PROTOCOL_F_MAX) - 1) typedef enum VhostUserRequest { VHOST_USER_NONE = 0,
Signature · 1 line
2.4.3