[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 1/3] x86/vpmu: Calculate vpmu_enabled() based on vpmu_mode value

vpmu_enabled() is currently reported based on VPMU_CONTEXT_ALLOCATED
bit of VPMU's flags. This presents a problem on Intel processors where
VPMU context is allocated lazily, during the first access to VPMU MSRs.
With such delayed allocation we, for example, cannot properly report
CPUID's leaf 0xa since it is likely that the leaf is queried by a
guest before the guest attempts ro read or write the MSR.

Instead of keying vpmu_enabled() off the flags we should compute it
based on vpmu_mode.

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>

vpmu_enabled() cannot be made an inline in vpmu.h since is_hardware_domain()
is defined in sched.h which includes asm-x86/domain.h which, in turn, needs

Making it a macro would work but then we'd depend on whoever includes vpmu.h
to also include sched.h and I didn't like that.

 xen/arch/x86/cpu/vpmu.c    | 6 ++++++
 xen/include/asm-x86/vpmu.h | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/cpu/vpmu.c b/xen/arch/x86/cpu/vpmu.c
index 35a9403..0252171 100644
--- a/xen/arch/x86/cpu/vpmu.c
+++ b/xen/arch/x86/cpu/vpmu.c
@@ -110,6 +110,12 @@ static void __init parse_vpmu_params(char *s)
     printk("VPMU: unknown flags: %s - vpmu disabled!\n", s);
+bool_t vpmu_enabled (const struct vcpu *v)
+    return ((vpmu_mode & (XENPMU_MODE_SELF | XENPMU_MODE_HV)) ||
+            ((vpmu_mode & XENPMU_MODE_ALL) && is_hardware_domain(v->domain)));
 void vpmu_lvtpc_update(uint32_t val)
     struct vpmu_struct *vpmu;
diff --git a/xen/include/asm-x86/vpmu.h b/xen/include/asm-x86/vpmu.h
index e50618f..30a0476 100644
--- a/xen/include/asm-x86/vpmu.h
+++ b/xen/include/asm-x86/vpmu.h
@@ -25,7 +25,6 @@
 #define vcpu_vpmu(vcpu)   (&(vcpu)->arch.vpmu)
 #define vpmu_vcpu(vpmu)   container_of((vpmu), struct vcpu, arch.vpmu)
-#define vpmu_enabled(vcpu) vpmu_is_set(vcpu_vpmu(vcpu), VPMU_CONTEXT_ALLOCATED)
 #define MSR_TYPE_COUNTER            0
 #define MSR_TYPE_CTRL               1
@@ -101,6 +100,7 @@ static inline bool_t vpmu_are_all_set(const struct 
vpmu_struct *vpmu,
     return !!((vpmu->flags & mask) == mask);
+bool_t vpmu_enabled(const struct vcpu *v);
 void vpmu_lvtpc_update(uint32_t val);
 int vpmu_do_msr(unsigned int msr, uint64_t *msr_content,
                 uint64_t supported, bool_t is_write);

Xen-devel mailing list



Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.