From: "Jan Beulich" Subject: Re: [PATCH v8 05/19] vmx: Merge MSR management routines Date: Mon, 28 Jul 2014 15:08:39 +0100 Message-ID: <53D675870200007800026AB1@mail.emea.novell.com> References: <1404225480-2664-1-git-send-email-boris.ostrovsky@oracle.com> <1404225480-2664-6-git-send-email-boris.ostrovsky@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1404225480-2664-6-git-send-email-boris.ostrovsky@oracle.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Boris Ostrovsky Cc: kevin.tian@intel.com, keir@xen.org, suravee.suthikulpanit@amd.com, andrew.cooper3@citrix.com, tim@xen.org, dietmar.hahn@ts.fujitsu.com, xen-devel@lists.xen.org, jun.nakajima@intel.com List-Id: xen-devel@lists.xenproject.org >>> On 01.07.14 at 16:37, wrote: > --- a/xen/arch/x86/hvm/vmx/vmcs.c > +++ b/xen/arch/x86/hvm/vmx/vmcs.c > @@ -1176,117 +1176,107 @@ int vmx_write_guest_msr(u32 msr, u64 val) > return -ESRCH; > } > > -int vmx_add_guest_msr(u32 msr) > +int vmx_add_msr(u32 msr, u8 type) > { > struct vcpu *curr = current; > - unsigned int i, msr_count = curr->arch.hvm_vmx.msr_count; > - struct vmx_msr_entry *msr_area = curr->arch.hvm_vmx.msr_area; > + unsigned int idx, *msr_count; > + struct vmx_msr_entry **msr_area; > + > + ASSERT((type == VMX_GUEST_MSR) || (type == VMX_HOST_MSR)); > + > + if ( type == VMX_GUEST_MSR ) Better (smaller code) to move the ASSERT() into the else branch in cases like this. > - msr_area[msr_count].index = msr; > - msr_area[msr_count].mbz = 0; > - msr_area[msr_count].data = 0; > - curr->arch.hvm_vmx.msr_count = ++msr_count; > - __vmwrite(VM_EXIT_MSR_STORE_COUNT, msr_count); > - __vmwrite(VM_ENTRY_MSR_LOAD_COUNT, msr_count); > + (*msr_area)[*msr_count].index = msr; > + (*msr_area)[*msr_count].mbz = 0; > + (*msr_count)++; > + if ( type == VMX_GUEST_MSR ) > + { > + (*msr_area)[*msr_count - 1].data = 0; > + __vmwrite(VM_EXIT_MSR_STORE_COUNT, *msr_count); > + __vmwrite(VM_ENTRY_MSR_LOAD_COUNT, *msr_count); > + } > + else > + { > + rdmsrl(msr, (*msr_area)[*msr_count - 1].data); > + __vmwrite(VM_EXIT_MSR_LOAD_COUNT, *msr_count); > + } For better readability perhaps worth having a local variable set to *msr_area + *msr_count, at once allowing to avoid the slightly ugly *msr_count - 1 in both the if and else branches. > + --(*msr_count); > + memmove(&(*msr_area)[idx], &(*msr_area)[idx + 1], > + sizeof(struct vmx_msr_entry) * (*msr_count - idx)); > + msr_area[(*msr_count)]->index = 0; Pointless pairs of parentheses in the first and last quoted lines above. Jan