All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: Boris Ostrovsky <boris.ostrovsky@oracle.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 16:23:29 +0000	[thread overview]
Message-ID: <54E76D910200007800062280@mail.emea.novell.com> (raw)
In-Reply-To: <54E75B1D.4030402@oracle.com>

>>> 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.

>>> --- 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?

>>> +long do_xenpmu_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg)
>>> +{
>>> +    int ret;
>>> +    struct xen_pmu_params pmu_params;
>>> +
>>> +    if ( vpmu_disabled )
>>> +        return -EINVAL;
>> EOPNOTSUPP perhaps?
>>
>> And I agree with Dietmar that keeping opt_vpmu_enabled instead
>> of introducing vpmu_disabled would seem more natural, the more
>> that the default is disabled.
> 
> I can switch polarity back to enabled since both of you think it makes 
> more sense but I don't think I should keep "opt_" prefix since this flag 
> can be modified independently of what boot option says (e.g. when 
> watchdog is on).

Grep through the sources, and if you don't find other examples
doing so (I think you will), I'm fine with you dropping the opt_prefix
(in a separate patch).

Jan

  reply	other threads:[~2015-02-20 16:23 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 [this message]
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
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=54E76D910200007800062280@mail.emea.novell.com \
    --to=jbeulich@suse.com \
    --cc=Aravind.Gopalakrishnan@amd.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=boris.ostrovsky@oracle.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.