From 3be4042cedc91205ad62008e3a8b20e9a547e181 Mon Sep 17 00:00:00 2001
Message-Id: <3be4042cedc91205ad62008e3a8b20e9a547e181.1349175436.git.minovotn@redhat.com>
In-Reply-To: <94968b7fa9b14e71f004474d7ce77e189e6a2bf3.1349175436.git.minovotn@redhat.com>
References: <94968b7fa9b14e71f004474d7ce77e189e6a2bf3.1349175436.git.minovotn@redhat.com>
From: Eduardo Habkost <ehabkost@redhat.com>
Date: Fri, 28 Sep 2012 21:40:10 +0200
Subject: [PATCH 13/34] replace disable_cpuid_leaf10() with
 set_pmu_passthrough(bool) (v2)

RH-Author: Eduardo Habkost <ehabkost@redhat.com>
Message-id: <1348868411-18680-1-git-send-email-ehabkost@redhat.com>
Patchwork-id: 42544
O-Subject: [RHEL6 qemu-kvm PATCHv2 12/18] replace disable_cpuid_leaf10() with set_pmu_passthrough(bool) (v2)
Bugzilla: 833152
RH-Acked-by: Alex Williamson <alex.williamson@redhat.com>
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>

Bugzilla: 852083
Upstream status: not applicable
  Fixing this upstream will require the CPU qdevification to be finished
  first (something that is not going to be backported to RHEL-6), so
  there's no point in waiting for upstream.

This keeps the current behavior, but change the code to allow PMU
passthrough to be enabled or disabled by machine-type code.

Changes v1 -> v2:
 - Set default to pmu_passthrough_enabled = true, to actually keep the
   current behavior

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/pc.c             |  2 +-
 hw/pc.h             |  5 +++--
 target-i386/cpuid.c | 10 +++++-----
 3 files changed, 9 insertions(+), 8 deletions(-)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 hw/pc.c             |  2 +-
 hw/pc.h             |  5 +++--
 target-i386/cpuid.c | 10 +++++-----
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/hw/pc.c b/hw/pc.c
index 9fca9f7..3e519e9 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -1637,7 +1637,7 @@ static void pc_rhel630_compat(void)
 static void pc_rhel620_compat(void)
 {
     pc_rhel630_compat();
-    disable_cpuid_leaf10();
+    set_pmu_passthrough(false);
 }
 
 static void pc_init_rhel640(ram_addr_t ram_size,
diff --git a/hw/pc.h b/hw/pc.h
index f351cbb..051dab8 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -178,7 +178,8 @@ void extboot_init(BlockDriverState *bs, int cmd);
 
 int cpu_is_bsp(CPUState *env);
 
-void disable_cpuid_leaf10(void);
-
+/* machine-type CPU compatibility functions: */
+void set_pmu_passthrough(bool enable);
 void disable_kvm_pv_eoi(void);
+
 #endif
diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index d77f765..3fcbeaa 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -89,7 +89,7 @@ int enforce_cpuid = 0;
 
 /* machine-type compatibility settings: */
 static bool kvm_pv_eoi_disabled;
-static bool cpuid_leaf10_disabled;
+static bool pmu_passthrough_enabled = true;
 
 static void host_cpuid(uint32_t function, uint32_t count, uint32_t *eax,
                        uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
@@ -1232,7 +1232,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
         break;
     case 0xA:
         /* Architectural Performance Monitoring Leaf */
-        if (kvm_enabled() && !cpuid_leaf10_disabled) {
+        if (kvm_enabled() && pmu_passthrough_enabled) {
             KVMState *s = env->kvm_state;
             *eax = kvm_arch_get_supported_cpuid(s, 0xA, count, R_EAX);
             *ebx = kvm_arch_get_supported_cpuid(s, 0xA, count, R_EBX);
@@ -1393,12 +1393,12 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
  * both files include to put this into.
  * Put it here to silence compiler warning.
  */
-void disable_cpuid_leaf10(void);
+void set_pmu_passthrough(bool enable);
 void disable_kvm_pv_eoi(void);
 
-void disable_cpuid_leaf10(void)
+void set_pmu_passthrough(bool enable)
 {
-	cpuid_leaf10_disabled = true;
+	pmu_passthrough_enabled = enable;
 }
 
 void disable_kvm_pv_eoi(void)
-- 
1.7.11.4

