From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christian Borntraeger Subject: [patch 1/3] kvm: provide synchronous registers in kvm_run Date: Thu, 22 Dec 2011 12:56:47 +0100 Message-ID: <20111222120054.145183940@de.ibm.com> References: <20111222115646.248800653@de.ibm.com> Cc: Carsten Otte , Alexander Graf , Jens Freimann , Cornelia Huck , Heiko Carstens , Martin Schwidefsky , KVM , Christian Borntraeger To: Avi Kivity , Marcelo Tossati Return-path: Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:41291 "EHLO e06smtp12.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752322Ab1LVMA6 (ORCPT ); Thu, 22 Dec 2011 07:00:58 -0500 Received: from /spool/local by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 22 Dec 2011 12:00:57 -0000 Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pBMC0tqC2478242 for ; Thu, 22 Dec 2011 12:00:55 GMT Received: from d06av02.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pBMC0sJ6020274 for ; Thu, 22 Dec 2011 05:00:55 -0700 Content-Disposition: inline; filename=kvm_run_sync_regs.patch Sender: kvm-owner@vger.kernel.org List-ID: From: Christian Borntraeger On some cpus the overhead for virtualization instructions is in the same range as a system call. Having to call multiple ioctls to get set registers will make userspace handled exits more expensive than necessary. Lets provide two sections in kvm_run to have a shared save area for guest registers. 1. the first section is read-only, to handle registers that have side-effects 2. the second section is read/write, e.g. for general purpose registers. Signed-off-by: Christian Borntraeger --- Documentation/virtual/kvm/api.txt | 16 ++++++++++++++++ arch/ia64/include/asm/kvm.h | 7 +++++++ arch/powerpc/include/asm/kvm.h | 7 +++++++ arch/s390/include/asm/kvm.h | 6 ++++++ arch/x86/include/asm/kvm.h | 7 +++++++ include/linux/kvm.h | 13 +++++++++++++ 6 files changed, 56 insertions(+) Index: b/Documentation/virtual/kvm/api.txt =================================================================== --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt @@ -1652,7 +1652,23 @@ developer registration required to acces /* Fix the size of the union. */ char padding[256]; }; + /* Here are two fields that allow to access often used registers + * directly, to avoid the overhead of the ioctl system call */ + union { + /* registers which can be only read */ + struct sync_ro_regs sync_ro_regs; + char padding[1024]; + }; + union { + /* read/write guest registers */ + struct sync_rw_regs sync_rw_regs; + char padding[1024]; + }; }; +These fields allow userspace to access certain guest registers without +having to call SET/GET_*REGS. Thus we can avoid some system call +overhead if userspace has to handle the exit. (only available if +KVM_CAP_SYNC_REGS is set). The ioctls will still work. 6. Capabilities that can be enabled Index: b/arch/ia64/include/asm/kvm.h =================================================================== --- a/arch/ia64/include/asm/kvm.h +++ b/arch/ia64/include/asm/kvm.h @@ -261,4 +261,11 @@ struct kvm_debug_exit_arch { struct kvm_guest_debug_arch { }; +/* definition of registers in kvm_run */ +struct sync_ro_regs { +}; + +struct sync_rw_regs { +}; + #endif Index: b/arch/powerpc/include/asm/kvm.h =================================================================== --- a/arch/powerpc/include/asm/kvm.h +++ b/arch/powerpc/include/asm/kvm.h @@ -265,6 +265,13 @@ struct kvm_debug_exit_arch { struct kvm_guest_debug_arch { }; +/* definition of registers in kvm_run */ +struct sync_ro_regs { +}; + +struct sync_rw_regs { +}; + #define KVM_REG_MASK 0x001f #define KVM_REG_EXT_MASK 0xffe0 #define KVM_REG_GPR 0x0000 Index: b/arch/s390/include/asm/kvm.h =================================================================== --- a/arch/s390/include/asm/kvm.h +++ b/arch/s390/include/asm/kvm.h @@ -41,4 +41,10 @@ struct kvm_debug_exit_arch { struct kvm_guest_debug_arch { }; +/* definition of registers in kvm_run */ +struct sync_ro_regs { +}; + +struct sync_rw_regs { +}; #endif Index: b/arch/x86/include/asm/kvm.h =================================================================== --- a/arch/x86/include/asm/kvm.h +++ b/arch/x86/include/asm/kvm.h @@ -321,4 +321,11 @@ struct kvm_xcrs { __u64 padding[16]; }; +/* definition of registers in kvm_run */ +struct sync_ro_regs { +}; + +struct sync_rw_regs { +}; + #endif /* _ASM_X86_KVM_H */ Index: b/include/linux/kvm.h =================================================================== --- a/include/linux/kvm.h +++ b/include/linux/kvm.h @@ -273,6 +273,18 @@ struct kvm_run { /* Fix the size of the union. */ char padding[256]; }; + /* Here are two fields that allow to access often used registers + * directly, to avoid the overhead of the ioctl system call */ + union { + /* registers which can be only read */ + struct sync_ro_regs sync_ro_regs; + char padding[1024]; + }; + union { + /* read/write guest registers */ + struct sync_rw_regs sync_rw_regs; + char padding[1024]; + }; }; /* for KVM_REGISTER_COALESCED_MMIO / KVM_UNREGISTER_COALESCED_MMIO */ @@ -557,6 +569,7 @@ struct kvm_ppc_pvinfo { #define KVM_CAP_MAX_VCPUS 66 /* returns max vcpus per vm */ #define KVM_CAP_PPC_PAPR 68 #define KVM_CAP_S390_GMAP 71 +#define KVM_CAP_SYNC_REGS 72 #ifdef KVM_CAP_IRQ_ROUTING