From: "Jan Beulich" Subject: Re: [PATCH v8 14/19] x86/VPMU: Handle PMU interrupts for PV guests Date: Tue, 29 Jul 2014 08:39:02 +0100 Message-ID: <53D76BB60200007800027227@mail.emea.novell.com> References: <1404225480-2664-1-git-send-email-boris.ostrovsky@oracle.com> <1404225480-2664-15-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-15-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/vpmu.c > +++ b/xen/arch/x86/hvm/vpmu.c > @@ -80,40 +80,169 @@ static void __init parse_vpmu_param(char *s) > > void vpmu_lvtpc_update(uint32_t val) > { > - struct vpmu_struct *vpmu = vcpu_vpmu(current); > + struct vcpu *v = current; "curr" please (here and wherever else). > int vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) > { > - struct vpmu_struct *vpmu = vcpu_vpmu(current); > + struct vcpu *v = current; > + struct vpmu_struct *vpmu = vcpu_vpmu(v); > > if ( !(vpmu_mode & XENPMU_MODE_ON) ) > return 0; > > if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->do_wrmsr ) > - return vpmu->arch_vpmu_ops->do_wrmsr(msr, msr_content); > + { > + int ret = vpmu->arch_vpmu_ops->do_wrmsr(msr, msr_content); > + > + /* > + * We may have received a PMU interrupt during WRMSR handling > + * and since do_wrmsr may load VPMU context we should save > + * (and unload) it again. > + */ > + if ( !is_hvm_domain(v->domain) && > + (vpmu->xenpmu_data && > + (vpmu->xenpmu_data->pmu_flags & PMU_CACHED)) ) Chains of && don't need parentheses to separate one from the other. > int vpmu_do_interrupt(struct cpu_user_regs *regs) > { > - struct vcpu *v = current; > - struct vpmu_struct *vpmu = vcpu_vpmu(v); > + struct vcpu *curr_vcpu, *v = current; Here the naming is particularly relevant: "curr_vcpu" really doesn't appear to mean anything "current", it's just the subject vCPU. I.e. that one would be "v", and what currently is "v" ought to be "curr". > + else if ( !is_hardware_domain(curr_vcpu->domain) && > + !is_idle_vcpu(curr_vcpu) ) > + { > + /* PV(H) guest */ > + gregs = guest_cpu_user_regs(); > + memcpy(&vpmu->xenpmu_data->pmu.r.regs, > + gregs, sizeof(struct cpu_user_regs)); > + } > + else > + memcpy(&vpmu->xenpmu_data->pmu.r.regs, > + regs, sizeof(struct cpu_user_regs)); Can neither of these two memcpy()s be (type safe) assignments instead? > @@ -523,6 +654,12 @@ long do_xenpmu_op(int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg) > vpmu_lvtpc_update(current->arch.vpmu.xenpmu_data->pmu.l.lapic_lvtpc); > ret = 0; > break; > + case XENPMU_flush: > + current->arch.vpmu.xenpmu_data->pmu_flags &= ~PMU_CACHED; > + vpmu_lvtpc_update(current->arch.vpmu.xenpmu_data->pmu.l.lapic_lvtpc); > + vpmu_load(current); Worth having a "curr" local variable in this function? Jan