From: Christian Borntraeger <borntraeger@xxxxxxxxxx> 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 <borntraeger@xxxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html