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 05/16] x86/VPMU: Interface for setting PMU mode and flags
Date: Fri, 20 Feb 2015 11:43:22 -0500	[thread overview]
Message-ID: <54E7642A.8030506@oracle.com> (raw)
In-Reply-To: <54E76D910200007800062280@mail.emea.novell.com>


On 02/20/2015 11:23 AM, Jan Beulich wrote:
>>>> On 20.02.15 at 17:04, <boris.ostrovsky@oracle.com> wrote:
>> On 02/20/2015 08:59 AM, Jan Beulich wrote:
>>>>>> On 16.02.15 at 23:26, <boris.ostrovsky@oracle.com> wrote:
>>>> --- a/xen/arch/x86/hvm/svm/vpmu.c
>>>> +++ b/xen/arch/x86/hvm/svm/vpmu.c
>>>> @@ -253,6 +253,26 @@ static int amd_vpmu_save(struct vpmu_struct *vpmu)
>>>>        return 1;
>>>>    }
>>>>    
>>>> +static void amd_vpmu_unload(struct vpmu_struct *vpmu)
>>>> +{
>>>> +    struct vcpu *v;
>>>> +
>>>> +    if ( vpmu_is_set(vpmu, VPMU_CONTEXT_LOADED | VPMU_FROZEN) )
>>>> +    {
>>>> +        unsigned int i;
>>>> +
>>>> +        for ( i = 0; i < num_counters; i++ )
>>>> +            wrmsrl(ctrls[i], 0);
>>>> +        context_save(vpmu);
>>> This assumes vpmu_vcpu(vpmu) == current, yet it looks like you're
>>> also calling it under different circumstances now.
>> This doesn't make this assumption. PMU MSRs may be loaded with values
>> that belong to a VCPU that is not currently running if, for example,
>> current VCPU is not using PMU. And flags test guarantees that we won't
>> stomp on someone else's registers.
>>
>> I could make a test here and write zeroes to the MSRs only if vpmu is
>> current but I don't like leaving these MSRs with what is essentially
>> garbage values. This routine is executed very rarely so overhead is
>> negligible.
> The question wasn't on the wrmsr() - writing zero here
> unconditionally is fine - but on the actions context_save() takes.

Same reasoning for context_save() (which is a bunch of RDMSRs) --- if 
flags indicate that the context is LOADED|FROZEN then contents of those 
MSRs belong to this vpmu, regardless of whether it is current.

>
>>>> --- a/xen/arch/x86/hvm/vmx/vmcs.c
>>>> +++ b/xen/arch/x86/hvm/vmx/vmcs.c
>>>> @@ -1183,11 +1183,10 @@ int vmx_read_guest_msr(u32 msr, u64 *val)
>>>>        return -ESRCH;
>>>>    }
>>>>    
>>>> -int vmx_write_guest_msr(u32 msr, u64 val)
>>>> +int vmx_write_guest_msr_vcpu(struct vcpu *v, u32 msr, u64 val)
>>>>    {
>>>> -    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 i, msr_count = v->arch.hvm_vmx.msr_count;
>>>> +    struct vmx_msr_entry *msr_area = v->arch.hvm_vmx.msr_area;
>>>>    
>>>>        for ( i = 0; i < msr_count; i++ )
>>>>        {
>>> Same here - while the code itself is only accessing memory, it
>>> remains unclear whether correct behavior results when the subject
>>> vCPU is actually executing.
>> Not sure what you mean here. The changes are specifically for updating
>> MSR values (cached in VMCS) of possibly non-current VCPU.
> But non-current doesn't mean not-running. I.e. what if the vCPU
> you deal with here is active on another pCPU?

I see. With VPMU (which is the only place that calls this routine) this 
will never happen but the interface itself allows it. I'll add an ASSERT 
or some other test to make sure.


-boris

  reply	other threads:[~2015-02-20 16:43 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 [this message]
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
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=54E7642A.8030506@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.