From: "Jan Beulich" Subject: Re: [PATCH v19 07/14] x86/VPMU: Initialize PMU for PV(H) guests Date: Tue, 24 Mar 2015 14:08:41 +0000 Message-ID: <55117DF9020000780006CFE1@mail.emea.novell.com> References: <1426604051-2980-1-git-send-email-boris.ostrovsky@oracle.com> <1426604051-2980-8-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: <1426604051-2980-8-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, suravee.suthikulpanit@amd.com, andrew.cooper3@citrix.com, tim@xen.org, dietmar.hahn@ts.fujitsu.com, xen-devel@lists.xen.org, Aravind.Gopalakrishnan@amd.com, jun.nakajima@intel.com, dgdegra@tycho.nsa.gov List-Id: xen-devel@lists.xenproject.org >>> On 17.03.15 at 15:54, wrote: > @@ -263,14 +264,14 @@ void vpmu_initialise(struct vcpu *v) > BUILD_BUG_ON(sizeof(struct xen_pmu_intel_ctxt) > XENPMU_CTXT_PAD_SZ); > BUILD_BUG_ON(sizeof(struct xen_pmu_amd_ctxt) > XENPMU_CTXT_PAD_SZ); > > - if ( is_pvh_vcpu(v) ) > - return; > - > ASSERT(!vpmu->flags && !vpmu->context); > > - spin_lock(&vpmu_lock); > - vpmu_count++; /* Prevent vpmu_mode from changing until we are done */ > - spin_unlock(&vpmu_lock); > + if ( v->domain != hardware_domain ) > + { > + spin_lock(&vpmu_lock); > + vpmu_count++; /* Prevent vpmu_mode from changing until we are done */ > + spin_unlock(&vpmu_lock); > + } So why is this being made conditional here? A patch this size would certainly benefit from a slightly more verbose description... And then if the conditional is indeed needed - why don't you use is_hardware_domain()? > +static int pvpmu_init(struct domain *d, xen_pmu_params_t *params) > +{ > + struct vcpu *v; > + struct vpmu_struct *vpmu; > + struct page_info *page; > + uint64_t gfn = params->val; > + > + if ( vpmu_mode == XENPMU_MODE_OFF ) > + return -EINVAL; > + > + if ( (params->vcpu >= d->max_vcpus) || (d->vcpu == NULL) || > + (d->vcpu[params->vcpu] == NULL) ) > + return -EINVAL; > + > + page = get_page_from_gfn(d, gfn, NULL, P2M_ALLOC); > + if ( !page ) > + return -EINVAL; > + > + if ( !get_page_type(page, PGT_writable_page) ) > + { > + put_page(page); > + return -EINVAL; > + } > + > + v = d->vcpu[params->vcpu]; > + vpmu = vcpu_vpmu(v); > + > + spin_lock(&vpmu->vpmu_lock); > + > + if ( v->arch.vpmu.xenpmu_data ) > + { > + put_page_and_type(page); > + spin_unlock(&vpmu->vpmu_lock); These two lines should be switched. > + return -EEXIST; > + } > + > + v->arch.vpmu.xenpmu_data = __map_domain_page_global(page); > + if ( !v->arch.vpmu.xenpmu_data ) > + { > + put_page_and_type(page); > + spin_unlock(&vpmu->vpmu_lock); Same here. > +static void pvpmu_finish(struct domain *d, xen_pmu_params_t *params) > +{ > + struct vcpu *v; > + struct vpmu_struct *vpmu; > + uint64_t mfn; > + > + if ( (params->vcpu >= d->max_vcpus) || (d->vcpu == NULL) || > + (d->vcpu[params->vcpu] == NULL) ) > + return; > + > + v = d->vcpu[params->vcpu]; > + if ( v != current ) > + vcpu_pause(v); > + > + vpmu = vcpu_vpmu(v); > + spin_lock(&vpmu->vpmu_lock); > + > + vpmu_destroy(v); > + > + if ( v->arch.vpmu.xenpmu_data ) > + { > + mfn = domain_page_map_to_mfn(v->arch.vpmu.xenpmu_data); > + ASSERT(mfn != 0); > + unmap_domain_page_global(v->arch.vpmu.xenpmu_data); > + put_page_and_type(mfn_to_page(mfn)); > + v->arch.vpmu.xenpmu_data = NULL; > + } > + > + spin_unlock(&vpmu->vpmu_lock); Similarly here the put should be moved out of the locked region. Jan