From: Boris Ostrovsky <boris.ostrovsky@oracle.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: kevin.tian@intel.com, suravee.suthikulpanit@amd.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 v17 13/23] x86/VPMU: Interface for setting PMU mode and flags
Date: Fri, 30 Jan 2015 10:17:35 -0500 [thread overview]
Message-ID: <54CBA08F.6010901@oracle.com> (raw)
In-Reply-To: <54CB95DD020000780005B533@mail.emea.novell.com>
On 01/30/2015 08:31 AM, Jan Beulich wrote:
>>>> On 05.01.15 at 22:44, <boris.ostrovsky@oracle.com> wrote:
>> +static long vpmu_unload_next(void *arg)
>> +{
>> + struct vcpu *last;
>> + int ret;
>> + unsigned int thiscpu = smp_processor_id();
>> +
>> + if ( thiscpu != vpmu_next_unload_cpu )
>> + {
>> + /* Continuation thread may have been moved due to CPU hot-unplug */
>> + vpmu_mode = (unsigned long)arg;
>> + vpmu_first_unload_cpu = VPMU_INVALID_CPU;
>> + return -EAGAIN;
>> + }
>> +
>> + local_irq_disable(); /* so that last_vcpu doesn't change under us. */
>> +
>> + last = this_cpu(last_vcpu);
>> + if ( last )
>> + {
>> + vpmu_unload(vcpu_vpmu(last));
>> + this_cpu(last_vcpu) = NULL;
>> + }
> So you do this for last_vcpu here, but ...
>
>
>> +static int vpmu_unload_all(unsigned long old_mode)
>> +{
>> + int ret = 0;
>> +
>> + vpmu_unload(vcpu_vpmu(current));
> ... for current here, also without clearing this_cpu(last_vcpu). Is
> that really correct?
No, I should clear it here as well.
>
>> +long do_xenpmu_op(int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg)
>> +{
>> + int ret;
>> + struct xen_pmu_params pmu_params;
>> +
>> + ret = xsm_pmu_op(XSM_OTHER, current->domain, op);
>> + if ( ret )
>> + return ret;
>> +
>> + switch ( op )
>> + {
>> + case XENPMU_mode_set:
>> + {
>> + unsigned int old_mode;
>> + static DEFINE_SPINLOCK(xenpmu_mode_lock);
>> +
>> + if ( copy_from_guest(&pmu_params, arg, 1) )
>> + return -EFAULT;
>> +
>> + if ( pmu_params.val & ~(XENPMU_MODE_SELF | XENPMU_MODE_HV) )
>> + return -EINVAL;
>> +
>> + /* 32-bit dom0 can only sample itself. */
>> + if ( is_pv_32bit_vcpu(current) && (pmu_params.val & XENPMU_MODE_HV) )
>> + return -EINVAL;
>> +
>> + /*
>> + * Return error if someone else is in the middle of changing mode ---
>> + * this is most likely indication of two system administrators
>> + * working against each other.
>> + */
>> + if ( !spin_trylock(&xenpmu_mode_lock) )
>> + return -EAGAIN;
>> + if ( vpmu_first_unload_cpu != VPMU_INVALID_CPU )
>> + {
>> + spin_unlock(&xenpmu_mode_lock);
>> + return -EAGAIN;
>> + }
>> +
>> + old_mode = vpmu_mode;
>> + vpmu_mode = pmu_params.val;
>> +
>> + if ( vpmu_mode == XENPMU_MODE_OFF )
>> + {
>> + /* Make sure all (non-dom0) VCPUs have unloaded their VPMUs. */
>> + ret = vpmu_unload_all(old_mode);
>> + if ( ret )
>> + vpmu_mode = old_mode;
>> + }
>> +
>> + spin_unlock(&xenpmu_mode_lock);
>> +
>> + break;
>> + }
>> +
>> + case XENPMU_mode_get:
>> + memset(&pmu_params, 0, sizeof(pmu_params));
>> + pmu_params.val = vpmu_mode;
>> +
>> + pmu_params.version.maj = XENPMU_VER_MAJ;
>> + pmu_params.version.min = XENPMU_VER_MIN;
>> +
>> + if ( copy_to_guest(arg, &pmu_params, 1) )
>> + return -EFAULT;
>> + break;
>> +
>> + case XENPMU_feature_set:
>> + if ( copy_from_guest(&pmu_params, arg, 1) )
>> + return -EFAULT;
>> +
>> + if ( pmu_params.val & ~XENPMU_FEATURE_INTEL_BTS )
>> + return -EINVAL;
>> +
>> + vpmu_features = pmu_params.val;
>> + break;
>> +
>> + case XENPMU_feature_get:
>> + pmu_params.val = vpmu_features;
>> + if ( copy_field_to_guest(arg, &pmu_params, val) )
>> + return -EFAULT;
>> + break;
>> +
>> + default:
>> + ret = -EINVAL;
>> + }
>> +
>> + return ret;
>> +}
> Throughout this function, the "pad" field isn't being checked to be
> zero (and XENPMU_feature_get also doesn't clear it, but that seems
> secondary, at least as long as it's being declared "IN" only). As I'm
> sure I said before - we ought to do this in order to be able to assign
> meaning to the field later on. Perhaps it would even better be
> renamed to e.g. "mbz".
If we decide to start using this filed then presumably we will have to
bump interface version. If pad field becomes something else it will only
be considered when minor version is > 1. (And I should probably add
major version check.)
-boris
next prev parent reply other threads:[~2015-01-30 15:17 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-05 21:43 [PATCH v17 00/23] x86/PMU: Xen PMU PV(H) support Boris Ostrovsky
2015-01-05 21:43 ` [PATCH v17 01/23] common/symbols: Export hypervisor symbols to privileged guest Boris Ostrovsky
2015-01-05 21:43 ` [PATCH v17 02/23] x86/VPMU: Don't globally disable VPMU if initialization fails Boris Ostrovsky
2015-01-05 21:43 ` [PATCH v17 03/23] x86/VPMU: Manage VPMU_CONTEXT_SAVE flag in vpmu_save_force() Boris Ostrovsky
2015-01-05 21:43 ` [PATCH v17 04/23] x86/VPMU: Set MSR bitmaps only for HVM/PVH guests Boris Ostrovsky
2015-01-05 21:43 ` [PATCH v17 05/23] x86/VPMU: Make vpmu macros a bit more efficient Boris Ostrovsky
2015-01-05 21:44 ` [PATCH v17 06/23] intel/VPMU: Clean up Intel VPMU code Boris Ostrovsky
2015-01-05 21:44 ` [PATCH v17 07/23] vmx: Merge MSR management routines Boris Ostrovsky
2015-01-05 21:44 ` [PATCH v17 08/23] x86/VPMU: Handle APIC_LVTPC accesses Boris Ostrovsky
2015-01-05 21:44 ` [PATCH v17 09/23] intel/VPMU: MSR_CORE_PERF_GLOBAL_CTRL should be initialized to zero Boris Ostrovsky
2015-01-05 21:44 ` [PATCH v17 10/23] x86/VPMU: Add public xenpmu.h Boris Ostrovsky
2015-01-05 21:44 ` [PATCH v17 11/23] x86/VPMU: Make vpmu not HVM-specific Boris Ostrovsky
2015-01-05 21:44 ` [PATCH v17 12/23] x86/VPMU: Replace vcpu with vpmu as argument to some routines Boris Ostrovsky
2015-01-05 21:44 ` [PATCH v17 13/23] x86/VPMU: Interface for setting PMU mode and flags Boris Ostrovsky
2015-01-30 13:31 ` Jan Beulich
2015-01-30 15:17 ` Boris Ostrovsky [this message]
2015-01-05 21:44 ` [PATCH v17 14/23] x86/VPMU: Initialize VPMUs with __initcall Boris Ostrovsky
2015-01-30 14:54 ` Jan Beulich
2015-02-03 16:02 ` Boris Ostrovsky
2015-02-03 16:18 ` Jan Beulich
2015-01-05 21:44 ` [PATCH v17 15/23] x86/VPMU: Initialize PMU for PV(H) guests Boris Ostrovsky
2015-01-05 21:44 ` [PATCH v17 16/23] x86/VPMU: Save VPMU state for PV guests during context switch Boris Ostrovsky
2015-01-05 21:44 ` [PATCH v17 17/23] x86/VPMU: When handling MSR accesses, leave fault injection to callers Boris Ostrovsky
2015-01-05 21:44 ` [PATCH v17 18/23] x86/VPMU: Add support for PMU register handling on PV guests Boris Ostrovsky
2015-01-05 21:44 ` [PATCH v17 19/23] x86/VPMU: Handle PMU interrupts for " Boris Ostrovsky
2015-01-05 21:44 ` [PATCH v17 20/23] x86/VPMU: Merge vpmu_rdmsr and vpmu_wrmsr Boris Ostrovsky
2015-01-05 21:44 ` [PATCH v17 21/23] x86/VPMU: Add privileged PMU mode Boris Ostrovsky
2015-01-05 21:44 ` [PATCH v17 22/23] x86/VPMU: NMI-based VPMU support Boris Ostrovsky
2015-01-05 21:44 ` [PATCH v17 23/23] x86/VPMU: Move VPMU files up from hvm/ directory Boris Ostrovsky
2015-01-20 10:37 ` [PATCH v17 00/23] x86/PMU: Xen PMU PV(H) support Jan Beulich
2015-01-20 16:38 ` Boris Ostrovsky
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=54CBA08F.6010901@oracle.com \
--to=boris.ostrovsky@oracle.com \
--cc=Aravind.Gopalakrishnan@amd.com \
--cc=JBeulich@suse.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.