From mboxrd@z Thu Jan 1 00:00:00 1970 From: Boris Ostrovsky Subject: Re: [PATCH v12 for-xen-4.5 12/20] x86/VPMU: Initialize PMU for PV(H) guests Date: Mon, 29 Sep 2014 11:41:23 -0400 Message-ID: <54297DA3.30200@oracle.com> References: <1411673336-32736-1-git-send-email-boris.ostrovsky@oracle.com> <1411673336-32736-13-git-send-email-boris.ostrovsky@oracle.com> <54299627020000780003AA60@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <54299627020000780003AA60@mail.emea.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jan Beulich 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, Aravind.Gopalakrishnan@amd.com, jun.nakajima@intel.com, dgdegra@tycho.nsa.gov List-Id: xen-devel@lists.xenproject.org On 09/29/2014 11:25 AM, Jan Beulich wrote: >>>> On 25.09.14 at 21:28, wrote: >> @@ -389,14 +390,26 @@ static int amd_vpmu_initialise(struct vcpu *v) >> } >> } >> >> - ctxt = xzalloc_bytes(sizeof(struct xen_pmu_amd_ctxt) + >> - 2 * sizeof(uint64_t) * AMD_MAX_COUNTERS); >> - if ( !ctxt ) >> + regs_size = 2 * sizeof(uint64_t) * AMD_MAX_COUNTERS; >> + if ( is_hvm_domain(v->domain) ) >> { >> - gdprintk(XENLOG_WARNING, "Insufficient memory for PMU, " >> - " PMU feature is unavailable on domain %d vcpu %d.\n", >> - v->vcpu_id, v->domain->domain_id); >> - return -ENOMEM; >> + ctxt = xzalloc_bytes(sizeof(struct xen_pmu_amd_ctxt) + regs_size); >> + if ( !ctxt ) >> + { >> + gdprintk(XENLOG_WARNING, "Insufficient memory for PMU, " >> + "PMU feature is unavailable\n"); >> + return -ENOMEM; >> + } >> + } >> + else >> + { >> + if ( sizeof(struct xen_pmu_data) + regs_size > PAGE_SIZE ) > This is a compile time constant condition - no reason to issue a > message and return failure at runtime, just BUILD_BUG_ON() instead. It will not be if I replace AMD_MAX_COUNTERS with runtime register count, as you asked in an earlier comment. -boris