KVM userspace interface updates
cover KVM userspace interface updates
This patchset updates the kvm userspace interface to what I hope will be the long-term stable interface. Provisions are included for extending the interface later. The patches address performance and cleanliness concerns.
One patch is missing -- I'd like the string pio transfers not to include guest virtual addresses. To date all my attempts to write the patch ended with me losing consiousness. Hopefully I'll manage it soon.
I'd like to submit the patchset post 2.6.21. Comments are welcome.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 1/15 KVM: Use a shared page for kernel/user communication when runing a vcpu
Instead of passing a 'struct kvm_run' back and forth between the kernel and userspace, allocate a page and allow the user to mmap() it. This reduces needless copying and makes the interface expandable by providing lots of free space.
--- drivers/kvm/kvm.h | 1 + drivers/kvm/kvm_main.c | 54 +++++++++++++++++++++++++++++++++++------------ include/linux/kvm.h | 6 ++-- 3 files changed, 44 insertions(+), 17 deletions(-) mode change 100755 => 100644 drivers/kvm/kvm_main.c
drivers/kvm/kvm.h +1 -0
@@ -228,6 +228,7 @@ struct kvm_vcpu {struct mutex mutex;int cpu;int launched; +struct kvm_run *run;int interrupt_window_open;unsigned long irq_summary;/* bit vector: 1 per word in irq_pending */ #define NR_IRQ_WORDS KVM_IRQ_BITMAP_SIZE(unsigned long)
drivers/kvm/kvm_main.c +40 -14
97 lines not on this page · raw message
include/linux/kvm.h +3 -3
@@ -11,7 +11,7 @@#include <asm/types.h> #include <linux/ioctl.h> -#define KVM_API_VERSION 4 +#define KVM_API_VERSION 5/* * Architectural interrupt line count, and the size of the bitmap needed
@@ -49,7 +49,7 @@ enum kvm_exit_reason { KVM_EXIT_SHUTDOWN = 8, }; -/* for KVM_RUN */ +/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */ struct kvm_run {/* in */ __u32 emulated;/* skip current instruction */
@@ -233,7 +233,7 @@ struct kvm_dirty_log {/* * ioctls for vcpu fds */ -#define KVM_RUN _IOWR(KVMIO, 2, struct kvm_run) +#define KVM_RUN _IO(KVMIO, 16)#define KVM_GET_REGS _IOR(KVMIO, 3, struct kvm_regs)#define KVM_SET_REGS _IOW(KVMIO, 4, struct kvm_regs)#define KVM_GET_SREGS _IOR(KVMIO, 5, struct kvm_sregs)
Signature · 8 lines
1.5.0.2 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [kvm-devel] [PATCH 01/15] KVM: Use a shared page for kernel/user communication when runing a vcpu
Quoted 4 lines · Avi Kivity
Instead of passing a 'struct
kvm_run' back and forth between the kernel and userspace, allocate a page and allow the user tommap()it. This reduces needless copying and makes the interface expandable by providing lots of free space.
Do you provide for another means of accessing guest memory from host userspace? For example, how do you attach a host debugger to the guest?
Xen uses an ioctl followed by mmap for this purpose, which is why I wonder about using mmap(/dev/kvm) for another purpose.
-Hollis
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [kvm-devel] [PATCH 01/15] KVM: Use a shared page for kernel/user communication when runing a vcpu
Quoted 11 lines · Hollis Blanchard
Quoted 4 lines · Avi Kivity
Instead of passing a 'struct
kvm_run' back and forth between the kernel and userspace, allocate a page and allow the user tommap()it. This reduces needless copying and makes the interface expandable by providing lots of free space.Do you provide for another means of accessing guest memory from host userspace? For example, how do you attach a host debugger to the guest?
Xen uses an ioctl followed by mmap for this purpose, which is why I wonder about using mmap(/dev/kvm) for another purpose.
Never mind: I see now that you have separate device nodes for the VM vs each vcpu.
-Hollis
PATCH 2/15 KVM: Do not communicate to userspace through cpu registers during PIO
In reply to Avi KivityCurrently when passing the a PIO emulation request to userspace, we rely on userspace updating %rax (on 'in' instructions) and %rsi/%rdi/%rcx (on string instructions). This (a) requires two extra ioctls for getting and setting the registers and (b) is unfriendly to non-x86 archs, when they get kvm ports.
So fix by doing the register fixups in the kernel and passing to userspace only an abstract description of the PIO to be done.
--- drivers/kvm/kvm.h | 1 + drivers/kvm/kvm_main.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- drivers/kvm/svm.c | 1 + drivers/kvm/vmx.c | 1 + include/linux/kvm.h | 6 +++--- 5 files changed, 51 insertions(+), 6 deletions(-)
drivers/kvm/kvm.h +1 -0
@@ -274,6 +274,7 @@ struct kvm_vcpu {int mmio_size;unsigned char mmio_data[8 ];gpa_t mmio_phys_addr; +int pio_pending;struct {int active;
drivers/kvm/kvm_main.c +45 -3
60 lines not on this page · raw message
drivers/kvm/svm.c +1 -0
@@ -1056,6 +1056,7 @@ static int io_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) } }else kvm_run->io.value = vcpu->svm->vmcb->save.rax; + vcpu->pio_pending =1 ;return 0 ; }
drivers/kvm/vmx.c +1 -0
@@ -1465,6 +1465,7 @@ static int handle_io(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) kvm_run->io.address =vmcs_readl (GUEST_LINEAR_ADDRESS ); }else kvm_run->io.value = vcpu->regs[VCPU_REGS_RAX ];/* rax */ + vcpu->pio_pending =1 ;return 0 ; }
include/linux/kvm.h +3 -3
@@ -11,7 +11,7 @@#include <asm/types.h> #include <linux/ioctl.h> -#define KVM_API_VERSION 5 +#define KVM_API_VERSION 6/* * Architectural interrupt line count, and the size of the bitmap needed
@@ -53,7 +53,7 @@ enum kvm_exit_reason {struct kvm_run {/* in */ __u32 emulated;/* skip current instruction */ -__u32 mmio_completed;/* mmio request completed */ +__u32 io_completed;/* mmio/pio request completed */ __u8 request_interrupt_window;__u8 padding1[7 ];
@@ -80,7 +80,7 @@ struct kvm_run {__u32 error_code; } ex;/* KVM_EXIT_IO */ -struct { +struct kvm_io {#define KVM_EXIT_IO_IN 0#define KVM_EXIT_IO_OUT 1__u8 direction;
Signature · 8 lines
1.5.0.2 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 3/15 KVM: Initialize PIO I/O count
In reply to Avi KivityThis allows userspace to ignore the io.rep field. No a big deal, but friendly.
--- drivers/kvm/svm.c | 1 + drivers/kvm/vmx.c | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)
drivers/kvm/svm.c +1 -0
@@ -1037,6 +1037,7 @@ static int io_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) kvm_run->io.size = ((io_info &SVM_IOIO_SIZE_MASK ) >>SVM_IOIO_SIZE_SHIFT ); kvm_run->io.string = (io_info &SVM_IOIO_STR_MASK ) !=0 ; kvm_run->io.rep = (io_info &SVM_IOIO_REP_MASK ) !=0 ; + kvm_run->io.count =1 ;if (kvm_run->io.string) {unsigned addr_mask;
drivers/kvm/vmx.c +1 -0
@@ -1459,6 +1459,7 @@ static int handle_io(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) = (vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_DF) != 0; kvm_run->io.rep = (exit_qualification &32 ) !=0 ; kvm_run->io.port = exit_qualification >>16 ; + kvm_run->io.count =1 ;if (kvm_run->io.string) {if (!get_io_count (vcpu, &kvm_run->io.count))return 1 ;
Signature · 8 lines
1.5.0.2 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 4/15 KVM: Handle cpuid in the kernel instead of punting to userspace
In reply to Avi KivityKVM used to handle cpuid by letting userspace decide what values to return to the guest. We now handle cpuid completely in the kernel. We still let userspace decide which values the guest will see by having userspace set up the value table beforehand (this is necessary to allow management software to set the cpu features to the least common denominator, so that live migration can work).
The motivation for the change is that kvm kernel code can be impacted by cpuid features, for example the x86 emulator.
--- drivers/kvm/kvm.h | 5 +++ drivers/kvm/kvm_main.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ drivers/kvm/svm.c | 4 +- drivers/kvm/vmx.c | 4 +- include/linux/kvm.h | 18 ++++++++++++- 5 files changed, 95 insertions(+), 5 deletions(-)
drivers/kvm/kvm.h +5 -0
@@ -55,6 +55,7 @@#define KVM_NUM_MMU_PAGES 256#define KVM_MIN_FREE_MMU_PAGES 5#define KVM_REFILL_PAGES 25 +#define KVM_MAX_CPUID_ENTRIES 40#define FX_IMAGE_SIZE 512#define FX_IMAGE_ALIGN 16
@@ -286,6 +287,9 @@ struct kvm_vcpu {u32 ar; } tr, es, ds, fs, gs; } rmode; + +int cpuid_nent; +struct kvm_cpuid_entry cpuid_entries[KVM_MAX_CPUID_ENTRIES ]; };struct kvm_memory_slot {
@@ -446,6 +450,7 @@ void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long value,struct x86_emulate_ctxt ; +void kvm_emulate_cpuid (struct kvm_vcpu *vcpu);int emulate_invlpg (struct kvm_vcpu *vcpu,gva_t address);int emulate_clts (struct kvm_vcpu *vcpu); int emulator_get_dr(struct x86_emulate_ctxt* ctxt, int dr,
drivers/kvm/kvm_main.c +69 -0
87 lines not on this page · raw message
drivers/kvm/svm.c +2 -2
@@ -1101,8 +1101,8 @@ static int task_switch_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_rstatic int cpuid_interception (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run) { vcpu->svm->next_rip = vcpu->svm->vmcb->save.rip +2 ; - kvm_run->exit_reason =KVM_EXIT_CPUID ; -return 0 ; +kvm_emulate_cpuid (vcpu); +return 1 ; }static int emulate_on_interception (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run)
drivers/kvm/vmx.c +2 -2
@@ -1585,8 +1585,8 @@ static int handle_dr(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)static int handle_cpuid (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run) { - kvm_run->exit_reason =KVM_EXIT_CPUID ; -return 0 ; +kvm_emulate_cpuid (vcpu); +return 1 ; }static int handle_rdmsr (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run)
include/linux/kvm.h +17 -1
@@ -41,7 +41,6 @@ enum kvm_exit_reason {KVM_EXIT_UNKNOWN =0 ,KVM_EXIT_EXCEPTION =1 ,KVM_EXIT_IO =2 , -KVM_EXIT_CPUID =3 ,KVM_EXIT_DEBUG =4 ,KVM_EXIT_HLT =5 , KVM_EXIT_MMIO = 6,
@@ -210,6 +209,22 @@ struct kvm_dirty_log { }; }; +struct kvm_cpuid_entry { +__u32 function; +__u32 eax; +__u32 ebx; +__u32 ecx; +__u32 edx; +__u32 padding; +}; + +/* for KVM_SET_CPUID */ +struct kvm_cpuid { +__u32 nent; +__u32 padding; +struct kvm_cpuid_entry entries[0 ]; +}; +#define KVMIO 0xAE/*
@@ -243,5 +258,6 @@ struct kvm_dirty_log {#define KVM_DEBUG_GUEST _IOW(KVMIO, 9, struct kvm_debug_guest)#define KVM_GET_MSRS _IOWR(KVMIO, 13, struct kvm_msrs)#define KVM_SET_MSRS _IOW(KVMIO, 14, struct kvm_msrs) +#define KVM_SET_CPUID _IOW(KVMIO, 17, struct kvm_cpuid)#endif
Signature · 8 lines
1.5.0.2 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 5/15 KVM: Remove the 'emulated' field from the userspace interface
In reply to Avi KivityWe no longer emulate single instructions in userspace. Instead, we service mmio or pio requests.
--- drivers/kvm/kvm_main.c | 5 ----- include/linux/kvm.h | 3 +-- 2 files changed, 1 insertions(+), 7 deletions(-)
drivers/kvm/kvm_main.c +0 -5
@@ -1588,11 +1588,6 @@ static int kvm_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)/* re-sync apic's tpr */ vcpu->cr8 = kvm_run->cr8; -if (kvm_run->emulated) { - kvm_arch_ops->skip_emulated_instruction (vcpu); - kvm_run->emulated =0 ; - } -if (kvm_run->io_completed) {if (vcpu->pio_pending)complete_pio (vcpu);
include/linux/kvm.h +1 -2
@@ -51,10 +51,9 @@ enum kvm_exit_reason {/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */ struct kvm_run {/* in */ -__u32 emulated;/* skip current instruction */ __u32 io_completed;/* mmio/pio request completed */ __u8 request_interrupt_window; -__u8 padding1[7 ]; +__u8 padding1[3 ];/* out */ __u32 exit_type;
Signature · 8 lines
1.5.0.2 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 6/15 KVM: Remove minor wart from KVM_CREATE_VCPU ioctl
In reply to Avi KivityThat ioctl does not transfer any data, so it should be an _IO rather than an _IOW.
--- include/linux/kvm.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/kvm.h +1 -1
@@ -241,7 +241,7 @@ struct kvm_cpuid {* KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns * a vcpu fd. */ -#define KVM_CREATE_VCPU _IOW(KVMIO, 11, int) +#define KVM_CREATE_VCPU _IO(KVMIO, 11)#define KVM_GET_DIRTY_LOG _IOW(KVMIO, 12, struct kvm_dirty_log)/*
Signature · 8 lines
1.5.0.2 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 7/15 KVM: Renumber ioctls
In reply to Avi KivityThe recent changes have left the ioctl numbers in complete disarray.
--- include/linux/kvm.h | 34 +++++++++++++++++----------------- 1 files changed, 17 insertions(+), 17 deletions(-)
include/linux/kvm.h +17 -17
@@ -229,34 +229,34 @@ struct kvm_cpuid {/* * ioctls for /dev/kvm fds: */ -#define KVM_GET_API_VERSION _IO(KVMIO, 1) -#define KVM_CREATE_VM _IO(KVMIO, 2)/* returns a VM fd */ -#define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 15, struct kvm_msr_list) +#define KVM_GET_API_VERSION _IO(KVMIO, 0x00) +#define KVM_CREATE_VM _IO(KVMIO, 0x01)/* returns a VM fd */ +#define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0x02, struct kvm_msr_list)/* * ioctls for VM fds */ -#define KVM_SET_MEMORY_REGION _IOW(KVMIO, 10, struct kvm_memory_region) +#define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region)/* * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns * a vcpu fd. */ -#define KVM_CREATE_VCPU _IO(KVMIO, 11) -#define KVM_GET_DIRTY_LOG _IOW(KVMIO, 12, struct kvm_dirty_log) +#define KVM_CREATE_VCPU _IO(KVMIO, 0x41) +#define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log)/* * ioctls for vcpu fds */ -#define KVM_RUN _IO(KVMIO, 16) -#define KVM_GET_REGS _IOR(KVMIO, 3, struct kvm_regs) -#define KVM_SET_REGS _IOW(KVMIO, 4, struct kvm_regs) -#define KVM_GET_SREGS _IOR(KVMIO, 5, struct kvm_sregs) -#define KVM_SET_SREGS _IOW(KVMIO, 6, struct kvm_sregs) -#define KVM_TRANSLATE _IOWR(KVMIO, 7, struct kvm_translation) -#define KVM_INTERRUPT _IOW(KVMIO, 8, struct kvm_interrupt) -#define KVM_DEBUG_GUEST _IOW(KVMIO, 9, struct kvm_debug_guest) -#define KVM_GET_MSRS _IOWR(KVMIO, 13, struct kvm_msrs) -#define KVM_SET_MSRS _IOW(KVMIO, 14, struct kvm_msrs) -#define KVM_SET_CPUID _IOW(KVMIO, 17, struct kvm_cpuid) +#define KVM_RUN _IO(KVMIO, 0x80) +#define KVM_GET_REGS _IOR(KVMIO, 0x81, struct kvm_regs) +#define KVM_SET_REGS _IOW(KVMIO, 0x82, struct kvm_regs) +#define KVM_GET_SREGS _IOR(KVMIO, 0x83, struct kvm_sregs) +#define KVM_SET_SREGS _IOW(KVMIO, 0x84, struct kvm_sregs) +#define KVM_TRANSLATE _IOWR(KVMIO, 0x85, struct kvm_translation) +#define KVM_INTERRUPT _IOW(KVMIO, 0x86, struct kvm_interrupt) +#define KVM_DEBUG_GUEST _IOW(KVMIO, 0x87, struct kvm_debug_guest) +#define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs) +#define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs) +#define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid)#endif
Signature · 8 lines
1.5.0.2 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 8/15 KVM: Add method to check for backwards-compatible API extensions
In reply to Avi Kivity--- drivers/kvm/kvm_main.c | 6 ++++++ include/linux/kvm.h | 5 +++++ 2 files changed, 11 insertions(+), 0 deletions(-)
drivers/kvm/kvm_main.c +6 -0
@@ -2416,6 +2416,12 @@ static long kvm_dev_ioctl(struct file *filp, r =0 ;break ; } +case KVM_CHECK_EXTENSION : +/* +* No extensions defined at present. +*/ + r =0 ; +break ;default : ; }
include/linux/kvm.h +5 -0
@@ -232,6 +232,11 @@ struct kvm_cpuid {#define KVM_GET_API_VERSION _IO(KVMIO, 0x00)#define KVM_CREATE_VM _IO(KVMIO, 0x01)/* returns a VM fd */ #define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 0x02, struct kvm_msr_list) +/* +* Check if a kvm extension is available. Argument is extension number, +* return is 1 (yes) or 0 (no, sorry). +*/ +#define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03)/* * ioctls for VM fds
Signature · 8 lines
1.5.0.2 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Re: [kvm-devel] [PATCH 08/15] KVM: Add method to check for backwards-compatible API extensions
Quoted 5 lines
drivers/kvm/kvm_main.c +0
-0
drivers/kvm/kvm_main.c static long kvm_dev_ioctl(struct file *filp, · line 2425
Quoted 10 lines
drivers/kvm/kvm_main.c +6
-0@@ -2416,6 +2416,12 @@ static long kvm_dev_ioctl(struct file *filp, r =0 ;break ; } +case KVM_CHECK_EXTENSION : +/* +* No extensions defined at present. +*/ + r =0 ; +break ;default :
What exactly is this good for?
Re: [kvm-devel] [PATCH 08/15] KVM: Add method to check for backwards-compatible API extensions
Quoted 10 lines · Heiko Carstens
Quoted 10 lines
drivers/kvm/kvm_main.c +2
-0@@ -2416,6 +2416,12 @@ static long kvm_dev_ioctl(struct file *filp, r =0 ;break ; } +case KVM_CHECK_EXTENSION : +/*
Quoted 9 lines
drivers/kvm/kvm_main.c static long kvm_dev_ioctl(struct file *filp,
Quoted 6 lines
drivers/kvm/kvm_main.c +4
-0+* No extensions defined at present. +*/ + r =0 ; +break ;default :What exactly is this good for?
Extending the interface in a backwards compatible manner. When new interfaces are added, it will return 1 (depending on arg) for implemented extensions.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 9/15 KVM: Allow userspace to process hypercalls which have no kernel handler
In reply to Avi KivityThis is useful for paravirtualized graphics devices, for example.
--- drivers/kvm/kvm_main.c | 18 +++++++++++++++++- include/linux/kvm.h | 10 +++++++++- 2 files changed, 26 insertions(+), 2 deletions(-)
drivers/kvm/kvm_main.c +17 -1
@@ -1203,7 +1203,16 @@ int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run) }switch (nr) {default : - ; + run->hypercall.args[0 ] = a0; + run->hypercall.args[1 ] = a1; + run->hypercall.args[2 ] = a2; + run->hypercall.args[3 ] = a3; + run->hypercall.args[4 ] = a4; + run->hypercall.args[5 ] = a5; + run->hypercall.ret = ret; + run->hypercall.longmode =is_long_mode (vcpu); + kvm_arch_ops->decache_regs (vcpu); +return 0 ; } vcpu->regs[VCPU_REGS_RAX ] = ret; kvm_arch_ops->decache_regs (vcpu);
@@ -1599,6 +1608,13 @@ static int kvm_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) vcpu->mmio_needed =0 ; +if (kvm_run->exit_type ==KVM_EXIT_TYPE_VM_EXIT + && kvm_run->exit_type ==KVM_EXIT_HYPERCALL ) { + kvm_arch_ops->cache_regs (vcpu); + vcpu->regs[VCPU_REGS_RAX ] = kvm_run->hypercall.ret; + kvm_arch_ops->decache_regs (vcpu); + } + r = kvm_arch_ops->run (vcpu, kvm_run);vcpu_put (vcpu);
include/linux/kvm.h +9 -1
@@ -11,7 +11,7 @@#include <asm/types.h> #include <linux/ioctl.h> -#define KVM_API_VERSION 6 +#define KVM_API_VERSION 7/* * Architectural interrupt line count, and the size of the bitmap needed
@@ -41,6 +41,7 @@ enum kvm_exit_reason {KVM_EXIT_UNKNOWN =0 ,KVM_EXIT_EXCEPTION =1 ,KVM_EXIT_IO =2 , +KVM_EXIT_HYPERCALL =3 ,KVM_EXIT_DEBUG =4 ,KVM_EXIT_HLT =5 , KVM_EXIT_MMIO = 6,
@@ -103,6 +104,13 @@ struct kvm_run {__u32 len;__u8 is_write; } mmio; +/* KVM_EXIT_HYPERCALL */ +struct { +__u64 args[6 ]; +__u64 ret; +__u32 longmode; +__u32 pad; + } hypercall; }; };
Signature · 8 lines
1.5.0.2 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 10/15 KVM: Fold kvm_run::exit_type into kvm_run::exit_reason
In reply to Avi KivityCurrently, userspace is told about the nature of the last exit from the guest using two fields, exit_type and exit_reason, where exit_type has just two enumerations (and no need for more). So fold exit_type into exit_reason, reducing the complexity of determining what really happened.
--- drivers/kvm/kvm_main.c | 3 +-- drivers/kvm/svm.c | 7 +++---- drivers/kvm/vmx.c | 7 +++---- include/linux/kvm.h | 15 ++++++++------- 4 files changed, 15 insertions(+), 17 deletions(-)
drivers/kvm/kvm_main.c +1 -2
@@ -1608,8 +1608,7 @@ static int kvm_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) vcpu->mmio_needed =0 ; -if (kvm_run->exit_type ==KVM_EXIT_TYPE_VM_EXIT - && kvm_run->exit_type ==KVM_EXIT_HYPERCALL ) { +if (kvm_run->exit_reason ==KVM_EXIT_HYPERCALL ) { kvm_arch_ops->cache_regs (vcpu); vcpu->regs[VCPU_REGS_RAX ] = kvm_run->hypercall.ret; kvm_arch_ops->decache_regs (vcpu);
drivers/kvm/svm.c +3 -4
@@ -1298,8 +1298,6 @@ static int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) {u32 exit_code = vcpu->svm->vmcb->control.exit_code; - kvm_run->exit_type =KVM_EXIT_TYPE_VM_EXIT ; -if (is_external_interrupt (vcpu->svm->vmcb->control.exit_int_info) && exit_code !=SVM_EXIT_EXCP_BASE +PF_VECTOR ) printk(KERN_ERR "%s: unexpected exit_ini_info 0x%x "
@@ -1609,8 +1607,9 @@ again: vcpu->svm->next_rip =0 ;if (vcpu->svm->vmcb->control.exit_code ==SVM_EXIT_ERR ) { - kvm_run->exit_type =KVM_EXIT_TYPE_FAIL_ENTRY ; - kvm_run->exit_reason = vcpu->svm->vmcb->control.exit_code; + kvm_run->exit_reason =KVM_EXIT_FAIL_ENTRY ; + kvm_run->fail_entry.hardware_entry_failure_reason + = vcpu->svm->vmcb->control.exit_code;post_kvm_run_save (vcpu, kvm_run);return 0 ; }
drivers/kvm/vmx.c +3 -4
@@ -1901,10 +1901,10 @@ again: asm ("mov %0, %%ds; mov %0, %%es" : :"r" (__USER_DS)); - kvm_run->exit_type =0 ;if (fail) { - kvm_run->exit_type =KVM_EXIT_TYPE_FAIL_ENTRY ; - kvm_run->exit_reason =vmcs_read32 (VM_INSTRUCTION_ERROR ); + kvm_run->exit_reason =KVM_EXIT_FAIL_ENTRY ; + kvm_run->fail_entry.hardware_entry_failure_reason + =vmcs_read32 (VM_INSTRUCTION_ERROR ); r =0 ; }else {if (fs_gs_ldt_reload_needed) {
@@ -1930,7 +1930,6 @@ again:profile_hit (KVM_PROFILING , (void *)vmcs_readl (GUEST_RIP )); vcpu->launched =1 ; - kvm_run->exit_type =KVM_EXIT_TYPE_VM_EXIT ; r =kvm_handle_exit (kvm_run, vcpu);if (r >0 ) {/* Give scheduler a change to reschedule. */
include/linux/kvm.h +8 -7
@@ -11,7 +11,7 @@#include <asm/types.h> #include <linux/ioctl.h> -#define KVM_API_VERSION 7 +#define KVM_API_VERSION 8/* * Architectural interrupt line count, and the size of the bitmap needed
@@ -34,9 +34,6 @@ struct kvm_memory_region {#define KVM_MEM_LOG_DIRTY_PAGES 1UL -#define KVM_EXIT_TYPE_FAIL_ENTRY 1 -#define KVM_EXIT_TYPE_VM_EXIT 2 -enum kvm_exit_reason {KVM_EXIT_UNKNOWN =0 ,KVM_EXIT_EXCEPTION =1 ,
@@ -47,6 +44,7 @@ enum kvm_exit_reason {KVM_EXIT_MMIO =6 ,KVM_EXIT_IRQ_WINDOW_OPEN =7 ,KVM_EXIT_SHUTDOWN =8 , + KVM_EXIT_FAIL_ENTRY = 9, };/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
@@ -57,12 +55,11 @@ struct kvm_run {__u8 padding1[3 ];/* out */ -__u32 exit_type;__u32 exit_reason;__u32 instruction_length;__u8 ready_for_interrupt_injection;__u8 if_flag; -__u16 padding2; +__u8 padding2[6 ];/* in (pre_kvm_run), out (post_kvm_run) */ __u64 cr8;
@@ -71,8 +68,12 @@ struct kvm_run {union {/* KVM_EXIT_UNKNOWN */ struct { -__u32 hardware_exit_reason; +__u64 hardware_exit_reason; } hw; +/* KVM_EXIT_FAIL_ENTRY */ +struct { +__u64 hardware_entry_failure_reason; + } fail_entry;/* KVM_EXIT_EXCEPTION */ struct {__u32 exception;
Signature · 8 lines
1.5.0.2 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 11/15 KVM: Add a special exit reason when exiting due to an interrupt
In reply to Avi KivityThis is redundant, as we also return -EINTR from the ioctl, but it allows us to examine the exit_reason field on resume without seeing old data.
--- drivers/kvm/svm.c | 2 ++ drivers/kvm/vmx.c | 2 ++ include/linux/kvm.h | 3 ++- 3 files changed, 6 insertions(+), 1 deletions(-)
drivers/kvm/svm.c +2 -0
@@ -1619,12 +1619,14 @@ again:if (signal_pending (current)) { ++kvm_stat.signal_exits;post_kvm_run_save (vcpu, kvm_run); + kvm_run->exit_reason =KVM_EXIT_INTR ;return -EINTR ; }if (dm_request_for_irq_injection (vcpu, kvm_run)) { ++kvm_stat.request_irq_exits;post_kvm_run_save (vcpu, kvm_run); + kvm_run->exit_reason =KVM_EXIT_INTR ;return -EINTR ; }kvm_resched (vcpu);
drivers/kvm/vmx.c +2 -0
@@ -1936,12 +1936,14 @@ again:if (signal_pending (current)) { ++kvm_stat.signal_exits;post_kvm_run_save (vcpu, kvm_run); + kvm_run->exit_reason =KVM_EXIT_INTR ;return -EINTR ; }if (dm_request_for_irq_injection (vcpu, kvm_run)) { ++kvm_stat.request_irq_exits;post_kvm_run_save (vcpu, kvm_run); + kvm_run->exit_reason =KVM_EXIT_INTR ;return -EINTR ; }
include/linux/kvm.h +2 -1
@@ -11,7 +11,7 @@#include <asm/types.h> #include <linux/ioctl.h> -#define KVM_API_VERSION 8 +#define KVM_API_VERSION 9/* * Architectural interrupt line count, and the size of the bitmap needed
@@ -45,6 +45,7 @@ enum kvm_exit_reason {KVM_EXIT_IRQ_WINDOW_OPEN =7 ,KVM_EXIT_SHUTDOWN =8 ,KVM_EXIT_FAIL_ENTRY =9 , + KVM_EXIT_INTR = 10, };/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
Signature · 8 lines
1.5.0.2 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 12/15 KVM: Initialize the apic_base msr on svm too
In reply to Avi KivityOlder userspace didn't care, but newer userspace (with the cpuid changes) does.
--- drivers/kvm/svm.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/kvm/svm.c +3 -0
@@ -582,6 +582,9 @@ static int svm_create_vcpu(struct kvm_vcpu *vcpu)init_vmcb (vcpu->svm->vmcb);fx_init (vcpu); + vcpu->apic_base =0xfee00000 | +/*for vcpu 0*/ MSR_IA32_APICBASE_BSP | +MSR_IA32_APICBASE_ENABLE ;return 0 ;
Signature · 8 lines
1.5.0.2 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 13/15 KVM: Add guest mode signal mask
In reply to Avi KivityAllow a special signal mask to be used while executing in guest mode. This allows signals to be used to interrupt a vcpu without requiring signal delivery to a userspace handler, which is quite expensive. Userspace still receives -EINTR and can get the signal via sigwait().
--- drivers/kvm/kvm.h | 3 +++ drivers/kvm/kvm_main.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/linux/kvm.h | 7 +++++++ 3 files changed, 51 insertions(+), 0 deletions(-)
drivers/kvm/kvm.h +3 -0
@@ -277,6 +277,9 @@ struct kvm_vcpu {gpa_t mmio_phys_addr;int pio_pending; +int sigset_active; +sigset_t sigset; +struct {int active;u8 save_iopl;
drivers/kvm/kvm_main.c +41 -0
68 lines not on this page · raw message
include/linux/kvm.h +7 -0
@@ -234,6 +234,12 @@ struct kvm_cpuid {struct kvm_cpuid_entry entries[0 ]; }; +/* for KVM_SET_SIGNAL_MASK */ +struct kvm_signal_mask { +__u32 len; +__u8 sigset[0 ]; +}; +#define KVMIO 0xAE/*
@@ -273,5 +279,6 @@ struct kvm_cpuid {#define KVM_GET_MSRS _IOWR(KVMIO, 0x88, struct kvm_msrs)#define KVM_SET_MSRS _IOW(KVMIO, 0x89, struct kvm_msrs)#define KVM_SET_CPUID _IOW(KVMIO, 0x8a, struct kvm_cpuid) +#define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask)#endif
Signature · 8 lines
1.5.0.2 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 14/15 KVM: Allow kernel to select size of mmap() buffer
In reply to Avi KivityThis allows us to store offsets in the kernel/user kvm_run area, and be sure that userspace has them mapped. As offsets can be outside the kvm_run struct, userspace has no way of knowing how much to mmap.
--- drivers/kvm/kvm_main.c | 8 +++++++- include/linux/kvm.h | 4 ++++ 2 files changed, 11 insertions(+), 1 deletions(-)
drivers/kvm/kvm_main.c +7 -1
@@ -2436,7 +2436,7 @@ static long kvm_dev_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) { void __user *argp = (void __user *)arg; -int r = -EINVAL ; +long r = -EINVAL ;switch (ioctl) {case KVM_GET_API_VERSION :
@@ -2478,6 +2478,12 @@ static long kvm_dev_ioctl(struct file *filp,*/ r =0 ;break ; +case KVM_GET_VCPU_MMAP_SIZE : + r = -EINVAL ; +if (arg) + goto out; + r =PAGE_SIZE ; +break ;default : ; }
include/linux/kvm.h +4 -0
@@ -253,6 +253,10 @@ struct kvm_signal_mask {* return is 1 (yes) or 0 (no, sorry). */ #define KVM_CHECK_EXTENSION _IO(KVMIO, 0x03) +/* +* Get size for mmap(vcpu_fd) +*/ +#define KVM_GET_VCPU_MMAP_SIZE _IO(KVMIO, 0x04)/* in bytes */ /* * ioctls for VM fds
Signature · 8 lines
1.5.0.2 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 15/15 KVM: Future-proof argument-less ioctls
In reply to Avi KivitySome ioctls ignore their arguments. By requiring them to be zero now, we allow a nonzero value to have some special meaning in the future.
--- drivers/kvm/kvm_main.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
drivers/kvm/kvm_main.c +9 -0
@@ -2169,6 +2169,9 @@ static long kvm_vcpu_ioctl(struct file *filp,switch (ioctl) {case KVM_RUN : + r = -EINVAL ; +if (arg) + goto out; r =kvm_vcpu_ioctl_run (vcpu, vcpu->run);break ;case KVM_GET_REGS : {
@@ -2440,9 +2443,15 @@ static long kvm_dev_ioctl(struct file *filp,switch (ioctl) {case KVM_GET_API_VERSION : + r = -EINVAL ; +if (arg) + goto out; r =KVM_API_VERSION ;break ;case KVM_CREATE_VM : + r = -EINVAL ; +if (arg) + goto out; r =kvm_dev_ioctl_create_vm ();break ;case KVM_GET_MSR_INDEX_LIST : {
Signature · 8 lines
1.5.0.2 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Quoted 4 lines · Avi Kivity
This patchset updates the kvm userspace interface to what I hope will be the long-term stable interface. Provisions are included for extending the interface later. The patches address performance and cleanliness concerns.
Searching the mailing list I figured that as soons as the interface seems to be stable, kvm should/would switch to a system call based interface. I assume the userspace interface might still change a lot, especially if kvm is ported to new architectures.
But the general question is: do you still plan to switch to a syscall interface?
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Quoted 8 lines · Heiko Carstens
Quoted 5 lines · Avi Kivity
This patchset updates the kvm userspace interface to what I hope will be the long-term stable interface. Provisions are included for extending the interface later. The patches address performance and cleanliness concerns.
Quoted 7 lines
Searching the mailing list I figured that as soons as the interface seems to be stable, kvm should/would switch to a system call based interface. I assume the userspace interface might still change a lot, especially if kvm is ported to new architectures.
But the general question is: do you still plan to switch to a syscall interface?
What benefit would a syscall interface have?
Regards,
Anthony Liguori
Quoted 11 lines
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
kvm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel
Quoted 17 lines · Anthony Liguori
Quoted 8 lines · Heiko Carstens
Quoted 5 lines · Avi Kivity
This patchset updates the kvm userspace interface to what I hope will be the long-term stable interface. Provisions are included for extending the interface later. The patches address performance and cleanliness concerns.
Quoted 7 lines
Searching the mailing list I figured that as soons as the interface seems to be stable, kvm should/would switch to a system call based interface. I assume the userspace interface might still change a lot, especially if kvm is ported to new architectures.
But the general question is: do you still plan to switch to a syscall interface?
Quoted 1 line
What benefit would a syscall interface have?
First of all: it's faster and doesn't burn a bunch of additional cpu cycles like sys_ioctl and the large switch statements do.
Another thing is that this patch set already introduces a way to pass a sigset. Passing a sigset to a device node is sort of strange.
In addition, if we would port kvm to s390, then we would need to make sure that each virtual cpu only gets executed from the thread that created it. That is simply because the upper half of our page tables contain information about the guest page states. This is yet another thing that would be strange to do via an ioctl based interface.
Of course everthing can be done via an iotcl interface too, but IMHO that's just the wrong interface.
Quoted 8 lines · Heiko Carstens
Quoted 4 lines
Quoted 2 lines
What benefit would a syscall interface have?
Another thing is that this patch set already introduces a way to pass a sigset. Passing a sigset to a device node is sort of strange.
The sigset is passed to the device node just for safekeeping, as it doesn't normally change. It's only used when switching to guest mode.
Quoted 6 lines
In addition, if we would port kvm to s390, then we would need to make sure that each virtual cpu only gets executed from the thread that created it. That is simply because the upper half of our page tables contain information about the guest page states. This is yet another thing that would be strange to do via an ioctl based interface.
Right. I agree it's more natural to associate a vcpu with a task instead of a vcpu being an independent entry. We'd still need a handle for it, and in Linux that's an fd (pid doesn't cut it as it's racy, and probably slower too as it has to go through a global structure).
Quoted 3 lines
Of course everthing can be done via an iotcl interface too, but IMHO that's just the wrong interface.
I guess once we have smp, and preferably an additional arch port, we can do another round of API consolidation around a syscall based API. We'll need to support the ioctl based API in parallel until the distros flush out older userspace.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 11 lines · Avi Kivity
Quoted 5 lines · Heiko Carstens
In addition, if we would port kvm to s390, then we would need to make sure that each virtual cpu only gets executed from the thread that created it. That is simply because the upper half of our page tables contain information about the guest page states. This is yet another thing that would be strange to do via an ioctl based interface.
Right. I agree it's more natural to associate a vcpu with a task instead of a vcpu being an independent entry. We'd still need a handle for it, and in Linux that's an fd (pid doesn't cut it as it's racy, and probably slower too as it has to go through a global structure).
If you go for: only one VM per thread group and only one vcpu per thread you don't need any identifier.
All relevant information or a pointer to it would be saved in the thread_info structure.
That would give you two system calls to add/remove cpus which implicitely create a VM if none is present. This add_vcpu syscall would also map a memory range to user space which would be used to communicate between user/kernel space to avoid frequent copy_to/from_user just like your latest patches for KVM_RUN do.
We implemented a prototype on s390 based on a system call interface and which does have full smp support.
This is a simplified version of how a add_cpu system call would look like. Please note that I left out all error checkings etc. E.g. checking if the vcpu already exists in the VM.
asmlinkage long sys_kvm_add_cpu(int vcpu, unsigned long addr)
{
struct kvm *kvm;
if (current_thread_info()->vcpu != -1)
return -EINVAL;
mutex_lock(&kvm_mutex);
write_lock_bh(&tasklist_lock);
/*
* Check all thread_infos in thread group if a VM context
* was already created.
*/
kvm = search_threads_for_kvm();
write_unlock_bh(&tasklist_lock);
if (!kvm) {
kvm = create_kvm_context();
current_thread_info()->kvm = kvm;
}
arch_add_cpu(vcpu);
current_thread_info()->vcpu = vcpu;
/*
* Map vcpu data to userspace at addr.
*/
arch_create_kvm_area(addr);
mutex_unlock(&kvm_mutex);
return 0;
}asmlinkage long sys_kvm_remove_cpu(void)
{
int vcpu;
vcpu = current_thread_info()->vcpu;
if (cpu == -1)
return -EINVAL;
mutex_lock(&kvm_mutex);
arch_remove_cpu(vcpu);
current_thread_info()->vcpu = -1;
mutex_unlock(&kvm_mutex);
return 0;
}The interesting part with this is that you don't need any locking for a kvm_run system call, simply because only the thread itself can create/remove the vcpu:
asmlinkage long sys_kvm_run(void)
{
int vcpu;
vcpu = current_thread_info()->vcpu;
if (vcpu == -1)
return -EINVAL;
return arch_kvm_run();
}Of course all this is rather simplified, but should give a good idea why I think that a syscall based interface should be the way to go.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Quoted 9 lines · Heiko Carstens
Quoted 5 lines
Right. I agree it's more natural to associate a vcpu with a task instead of a vcpu being an independent entry. We'd still need a handle for it, and in Linux that's an fd (pid doesn't cut it as it's racy, and probably slower too as it has to go through a global structure).
If you go for: only one VM per thread group and only one vcpu per thread you don't need any identifier.
That's the idea, but if I want to send an inter-processor-interrupt to another cpu, I need to be able to identify it. The pid [tid] is natural, but racy if the thread can die.
Quoted 10 lines
All relevant information or a pointer to it would be saved in the
thread_infostructure.
That would give you two system calls to add/remove cpus which implicitely create a VM if none is present. Thisadd_vcpusyscall would also map a memory range to user space which would be used to communicate between user/kernel space to avoid frequent copy_to/from_user just like your latest patches forKVM_RUNdo.We implemented a prototype on s390 based on a system call interface and which does have full smp support.
[...]
Quoted 4 lines
The interesting part with this is that you don't need any locking for a
kvm_runsystem call, simply because only the thread itself can create/remove the vcpu:
Yes! The vcpu is an implied parameter (current->vcpu).
Quoted 3 lines
Of course all this is rather simplified, but should give a good idea why I think that a syscall based interface should be the way to go.
I agree with all of the above, and in addition, integration to the scheduler will allow us to reduce vcpu migration rate, and maybe do things like gang scheduling.
But that doesn't mean it can be done now: we really need to see how it works out with smp and with an additional arch, and then we can stabilize it. Meanwhile I'd like a stable ABI so distros can start shipping kvm without worrying about upgrade headaches.
So the plan is:
- get the /dev/kvm ABI into 2.6.22
- implement smp
- add another arch
- move to a syscall based interface in parallel; userspace should work with both
- deprecate the old ABI and external modules.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Quoted 10 lines · Avi Kivity
Heiko Carstens wrote:
I agree with all of the above, and in addition, integration to the scheduler will allow us to reduce vcpu migration rate, and maybe do things like gang scheduling.But that doesn't mean it can be done now: we really need to see how it works out with smp and with an additional arch, and then we can stabilize it. Meanwhile I'd like a stable ABI so distros can start shipping kvm without worrying about upgrade headaches.
Quoted 6 lines
So the plan is:
- get the/dev/kvmABI into 2.6.22
- implement smp
- add another arch
- move to a syscall based interface in parallel; userspace should work with both
- deprecate the old ABI and external modules.
I wasn't asking to change the ABI right now, just wanted to make sure that it is not the 'final' interface. So I agree with your plan.
Quoted 8 lines · Avi Kivity
So the plan is:
- get the/dev/kvmABI into 2.6.22
- implement smp
- add another arch
- move to a syscall based interface in parallel; userspace should work with both
- deprecate the old ABI and external modules.
I would also like to add using arbitrary vmas as guest memory (and paging guest memory) to that list.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Quoted 8 lines · Heiko Carstens
Quoted 5 lines · Avi Kivity
This patchset updates the kvm userspace interface to what I hope will be the long-term stable interface. Provisions are included for extending the interface later. The patches address performance and cleanliness concerns.
Quoted 7 lines
Searching the mailing list I figured that as soons as the interface seems to be stable, kvm should/would switch to a system call based interface. I assume the userspace interface might still change a lot, especially if kvm is ported to new architectures.
But the general question is: do you still plan to switch to a syscall interface?
I don't have any present plans for that. Maybe when the interface starts to evolve at a slower pace, or if it is shown to be significantly faster.
Not that interface stabilization here doesn't mean a freeze; it means that backwards compatibility starts when this gets merged.
Signature · 8 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Quoted 11 lines · Avi Kivity
Quoted 9 lines · Heiko Carstens
Quoted 4 lines · Avi Kivity
This patchset updates the kvm userspace interface to what I hope will be the long-term stable interface. Provisions are included for extending the interface later. The patches address performance and cleanliness concerns.
[...]
But the general question is: do you still plan to switch to a syscall interface?
Quoted 5 lines
I don't have any present plans for that. Maybe when the interface starts to evolve at a slower pace, or if it is shown to be significantly faster.
Not that interface stabilization here doesn't mean a freeze; it means that backwards compatibility starts when this gets merged.
If the interface is considered to be stable you can get rid of the KVM_GET_API_VERSION ioctl, since the version can't change anymore, right?
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Quoted 19 lines · Heiko Carstens
Quoted 17 lines · Avi Kivity
Quoted 12 lines · Heiko Carstens
Quoted 5 lines · Avi Kivity
This patchset updates the kvm userspace interface to what I hope will be the long-term stable interface. Provisions are included for extending the interface later. The patches address performance and cleanliness concerns.
[...]
But the general question is: do you still plan to switch to a syscall interface?I don't have any present plans for that. Maybe when the interface starts to evolve at a slower pace, or if it is shown to be significantly faster.
Quoted 7 lines
Quoted 3 lines
Not that interface stabilization here doesn't mean a freeze; it means that backwards compatibility starts when this gets merged.
If the interface is considered to be stable you can get rid of the
KVM_GET_API_VERSIONioctl, since the version can't change anymore, right?
It's needed in case pre-stabilization userspace tries to use the stabilized interface. It's true the version won't change.
But maybe we can get rid of it, and the old userspace will just fail on the ioctl (we need to keep it reserved for that).
Signature · 1 line
error compiling committee.c: too many arguments to function