From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony Liguori Subject: [PATCH][SVM] Lazy fast syscall MSR save/restore Date: Fri, 27 Apr 2007 00:53:52 -0500 Message-ID: <46318FF0.7000207@us.ibm.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------000103090504010402070309" To: kvm-devel , Avi Kivity Return-path: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org This is a multi-part message in MIME format. --------------000103090504010402070309 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Howdy, The attached patch only reloads the host fast syscall MSRs when we leave KVM (when we put_cpu()). Since we'll never execute a sys{enter,call,ret,exit} until we put_cpu() in the host, this should be safe. This has a huge impact on in-kernel vmexit performance. I see a savings of about a 1,000 cycles going from 4,700 to about 3,700 or ~21%. I've only tested on a 64bit host with a 32bit FC6 guest but I wanted to get it out before calling it a night. I had fumbled my previous attempt at this by switching the rdmsr/wrmsrs around so ignore my previous rambles about improperly blocking :-) Regards, Anthony Liguori --------------000103090504010402070309 Content-Type: text/x-patch; name="svm-lazy-msrs.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="svm-lazy-msrs.diff" From: Anthony Liguori Subject: [PATCH][SVM] Only save fast syscall MSRS when leaving VCPU We only need to restore the host fast syscall related MSRS when leaving the VCPU. This should only occur when we {get,put}_cpu(). Signed-off-by: Anthony Liguori Index: kernel/drivers/kvm/svm.c =================================================================== --- kernel.orig/drivers/kvm/svm.c 2007-04-26 18:07:09.909905480 -0500 +++ kernel/drivers/kvm/svm.c 2007-04-27 00:38:57.671182560 -0500 @@ -611,7 +611,7 @@ static void svm_vcpu_load(struct kvm_vcpu *vcpu) { - int cpu; + int cpu, i; cpu = get_cpu(); if (unlikely(cpu != vcpu->cpu)) { @@ -626,10 +626,18 @@ vcpu->svm->vmcb->control.tsc_offset += delta; vcpu->cpu = cpu; } + + for (i = 0; i < NR_HOST_SAVE_USER_MSRS; i++) + rdmsrl(host_save_user_msrs[i], vcpu->svm->host_user_msrs[i]); } static void svm_vcpu_put(struct kvm_vcpu *vcpu) { + int i; + + for (i = 0; i < NR_HOST_SAVE_USER_MSRS; i++) + wrmsrl(host_save_user_msrs[i], vcpu->svm->host_user_msrs[i]); + rdtscll(vcpu->host_tsc); put_cpu(); } Index: kernel/drivers/kvm/kvm_svm.h =================================================================== --- kernel.orig/drivers/kvm/kvm_svm.h 2007-04-26 18:07:09.949899400 -0500 +++ kernel/drivers/kvm/kvm_svm.h 2007-04-27 00:38:30.310342040 -0500 @@ -11,15 +11,19 @@ static const u32 host_save_msrs[] = { #ifdef CONFIG_X86_64 - MSR_STAR, MSR_LSTAR, MSR_CSTAR, MSR_SYSCALL_MASK, MSR_KERNEL_GS_BASE, - MSR_FS_BASE, MSR_GS_BASE, + MSR_KERNEL_GS_BASE, MSR_FS_BASE, MSR_GS_BASE, #endif - MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP, MSR_IA32_DEBUGCTLMSR, /*MSR_IA32_LASTBRANCHFROMIP, MSR_IA32_LASTBRANCHTOIP, MSR_IA32_LASTINTFROMIP,MSR_IA32_LASTINTTOIP,*/ }; +static const u32 host_save_user_msrs[] = { + MSR_STAR, MSR_LSTAR, MSR_CSTAR, MSR_SYSCALL_MASK, + MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP, +}; + #define NR_HOST_SAVE_MSRS ARRAY_SIZE(host_save_msrs) +#define NR_HOST_SAVE_USER_MSRS ARRAY_SIZE(host_save_user_msrs) #define NUM_DB_REGS 4 struct vcpu_svm { @@ -33,6 +37,7 @@ u64 next_rip; u64 host_msrs[NR_HOST_SAVE_MSRS]; + u64 host_user_msrs[NR_HOST_SAVE_USER_MSRS]; unsigned long host_cr2; unsigned long host_db_regs[NUM_DB_REGS]; unsigned long host_dr6; --------------000103090504010402070309 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ --------------000103090504010402070309 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kvm-devel mailing list kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/kvm-devel --------------000103090504010402070309--