All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Ostrovsky <boris.ostrovsky@oracle.com>
To: Jan Beulich <JBeulich@suse.com>
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
Subject: Re: [PATCH v18 07/16] x86/VPMU: Initialize PMU for PV(H) guests
Date: Fri, 20 Feb 2015 11:55:15 -0500	[thread overview]
Message-ID: <54E766F3.2070104@oracle.com> (raw)
In-Reply-To: <54E76E7A0200007800062296@mail.emea.novell.com>


On 02/20/2015 11:27 AM, Jan Beulich wrote:
>>>> On 20.02.15 at 17:15, <boris.ostrovsky@oracle.com> wrote:
>> On 02/20/2015 09:35 AM, Jan Beulich wrote:
>>>>>> On 16.02.15 at 23:26, <boris.ostrovsky@oracle.com> wrote:
>>>> --- a/xen/arch/x86/domain.c
>>>> +++ b/xen/arch/x86/domain.c
>>>> @@ -437,6 +437,8 @@ int vcpu_initialise(struct vcpu *v)
>>>>            vmce_init_vcpu(v);
>>>>        }
>>>>    
>>>> +    spin_lock_init(&v->arch.vpmu.vpmu_lock);
>>> This would rather seem to belong into vpmu_initialize().
>> vpmu_initialize() is called under this lock so we can't do this.
> Yes, I saw that later on, but it still doesn't look well structured. Can't
> you bail early from vpmu_initialize() the first time through for PV(H)
> guests, rather than guarding the HVM invocations with is_hvm_...()?

I could but I am not sure how it would allow me to move spin_lock_init() 
to vpmu_initialize().

We are protecting xenpmu_data and it is supposed to be set before we get 
into vpmu_initialize().


>
>>>> +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;
>>>> +
>>>> +    if ( v->arch.vpmu.xenpmu_data )
>>>> +        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);
>>>> +
>>>> +    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);
>>>> +        return -EINVAL;
>>>> +    }
>>>> +
>>>> +    vpmu_initialise(v);
>>>> +
>>>> +    spin_unlock(&vpmu->vpmu_lock);
>>> So what is this lock guarding against here? Certainly not overwriting
>>> of a non-NULL v->arch.vpmu.xenpmu_data (and hence leaking a
>>> page reference)...
>> This is trying to protect a race with pvmu_finish() that could clear
>> xenpmu_data.
>>
>> (I actually think you were the one who suggested it).
> But it should also protect against a second pvpmu_init() on another
> pCPU.

Right, I will move 'if (v->arch.vpmu.xenpmu_data )' under the lock (and 
clean up if it is non-NULL)

-boris

  reply	other threads:[~2015-02-20 16:55 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-16 22:26 [PATCH v18 00/16] x86/PMU: Xen PMU PV(H) support Boris Ostrovsky
2015-02-16 22:26 ` [PATCH v18 01/16] common/symbols: Export hypervisor symbols to privileged guest Boris Ostrovsky
2015-02-16 22:26 ` [PATCH v18 02/16] x86/VPMU: Add public xenpmu.h Boris Ostrovsky
2015-02-16 22:26 ` [PATCH v18 03/16] x86/VPMU: Make vpmu not HVM-specific Boris Ostrovsky
2015-02-16 22:26 ` [PATCH v18 04/16] x86/VPMU: Replace vcpu with vpmu as argument to some routines Boris Ostrovsky
2015-02-16 22:26 ` [PATCH v18 05/16] x86/VPMU: Interface for setting PMU mode and flags Boris Ostrovsky
2015-02-18 11:06   ` Dietmar Hahn
2015-02-20 13:59   ` Jan Beulich
2015-02-20 16:04     ` Boris Ostrovsky
2015-02-20 16:23       ` Jan Beulich
2015-02-20 16:43         ` Boris Ostrovsky
2015-02-20 14:31   ` Jan Beulich
2015-02-20 16:07     ` Boris Ostrovsky
2015-02-16 22:26 ` [PATCH v18 06/16] x86/VPMU: Initialize VPMUs with __initcall Boris Ostrovsky
2015-02-20 14:15   ` Jan Beulich
2015-02-16 22:26 ` [PATCH v18 07/16] x86/VPMU: Initialize PMU for PV(H) guests Boris Ostrovsky
2015-02-20 14:35   ` Jan Beulich
2015-02-20 16:15     ` Boris Ostrovsky
2015-02-20 16:27       ` Jan Beulich
2015-02-20 16:55         ` Boris Ostrovsky [this message]
2015-02-16 22:26 ` [PATCH v18 08/16] x86/VPMU: Save VPMU state for PV guests during context switch Boris Ostrovsky
2015-02-16 22:26 ` [PATCH v18 09/16] x86/VPMU: When handling MSR accesses, leave fault injection to callers Boris Ostrovsky
2015-02-16 22:26 ` [PATCH v18 10/16] x86/VPMU: Add support for PMU register handling on PV guests Boris Ostrovsky
2015-02-16 22:26 ` [PATCH v18 11/16] x86/VPMU: Handle PMU interrupts for " Boris Ostrovsky
2015-02-17 15:44   ` Andrew Cooper
2015-02-17 17:41     ` Boris Ostrovsky
2015-02-17 17:49       ` Andrew Cooper
2015-02-16 22:26 ` [PATCH v18 12/16] x86/VPMU: Merge vpmu_rdmsr and vpmu_wrmsr Boris Ostrovsky
2015-02-20 14:49   ` Jan Beulich
2015-02-16 22:26 ` [PATCH v18 13/16] x86/VPMU: Add privileged PMU mode Boris Ostrovsky
2015-02-16 22:26 ` [PATCH v18 14/16] x86/VPMU: NMI-based VPMU support Boris Ostrovsky
2015-02-20 15:03   ` Jan Beulich
2015-02-20 16:24     ` Boris Ostrovsky
2015-02-16 22:26 ` [PATCH v18 15/16] x86/VPMU: VPMU should not exist when vpmu_initialise() is called Boris Ostrovsky
2015-02-20 15:06   ` Jan Beulich
2015-02-16 22:26 ` [PATCH v18 16/16] x86/VPMU: Move VPMU files up from hvm/ directory Boris Ostrovsky
2015-02-17 15:13 ` [PATCH v18 00/16] x86/PMU: Xen PMU PV(H) support Andrew Cooper
2015-02-17 17:38   ` Boris Ostrovsky
2015-02-17 17:46     ` Andrew Cooper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54E766F3.2070104@oracle.com \
    --to=boris.ostrovsky@oracle.com \
    --cc=Aravind.Gopalakrishnan@amd.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=dgdegra@tycho.nsa.gov \
    --cc=dietmar.hahn@ts.fujitsu.com \
    --cc=jun.nakajima@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.