qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org, "Gleb Natapov" <gleb@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [RFC 7/7] target-i386: Disable direct passthrough of PMU CPUID leaf by default
Date: Fri, 26 Apr 2013 17:10:29 +0200	[thread overview]
Message-ID: <20130426171029.3e159116@thinkpad> (raw)
In-Reply-To: <1366915386-14728-8-git-send-email-ehabkost@redhat.com>

On Thu, 25 Apr 2013 15:43:06 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:

> The current code handling the CPUID 0xA leaf simply forwards all data
> from GET_SUPPORTED_CPUID directly to the guest, breaking migration
> between hosts with different number of PMU counters.
> 
> This patch disables this behavior, except on older machine-types (for
> compatibility) and on the "host" CPU model.
Please, make it static property and use compat properties.
Result will be simpler and  much less will have to be redone/discarded after
converting to the rest to properties and sub-classes.

> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> Cc: Gleb Natapov <gleb@redhat.com>
> ---
>  hw/i386/pc_piix.c |  1 +
>  hw/i386/pc_q35.c  |  1 +
>  target-i386/cpu.c | 25 ++++++++++++++++++++++++-
>  target-i386/cpu.h |  7 +++++++
>  4 files changed, 33 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> index 9372f77..bbc7064 100644
> --- a/hw/i386/pc_piix.c
> +++ b/hw/i386/pc_piix.c
> @@ -239,6 +239,7 @@ static void pc_init_pci_1_4(QEMUMachineInitArgs *args)
>  {
>      x86_cpu_compat_set_features("n270", FEAT_1_ECX, 0, CPUID_EXT_MOVBE);
>      x86_cpu_compat_set_model("486", 0);
> +    x86_cpu_enable_pmu_passthrough();
>      pc_init_pci(args);
>  }
>  
> diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
> index fc566fd..9718e94 100644
> --- a/hw/i386/pc_q35.c
> +++ b/hw/i386/pc_q35.c
> @@ -213,6 +213,7 @@ static void pc_q35_init_1_4(QEMUMachineInitArgs *args)
>  {
>      x86_cpu_compat_set_features("n270", FEAT_1_ECX, 0, CPUID_EXT_MOVBE);
>      x86_cpu_compat_set_model("486", 0);
> +    x86_cpu_enable_pmu_passthrough();
>      pc_q35_init(args);
>  }
>  
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 4fc7527..602d00f 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -245,6 +245,16 @@ static uint32_t kvm_default_features = (1 << KVM_FEATURE_CLOCKSOURCE) |
>          (1 << KVM_FEATURE_PV_EOI) |
>          (1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT);
>  
> +/* Enables passthrough of CPUID leaf 0xA by default, for compatibility with old
> + * machine-types.
> + */
> +static bool default_pmu_passthrough;
> +
> +void x86_cpu_enable_pmu_passthrough(void)
> +{
> +    default_pmu_passthrough = true;
> +}
> +
>  void disable_kvm_pv_eoi(void)
>  {
>      kvm_default_features &= ~(1UL << KVM_FEATURE_PV_EOI);
> @@ -375,6 +385,12 @@ typedef struct x86_def_t {
>      int stepping;
>      FeatureWordArray features;
>      char model_id[48];
> +
> +    /* Enable direct passthrough of PMU leaf from the GET_SUPPORTED_CPUID
> +     * data returned by the kernel. This is not migration-safe and should
> +     * never be enabled by default.
> +     */
> +    bool cpuid_pmu_passthrough;
>  } x86_def_t;
>  
>  #define I486_FEATURES (CPUID_FP87 | CPUID_VME | CPUID_PSE)
> @@ -1120,6 +1136,8 @@ static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
>      x86_cpu_def->features[FEAT_KVM] =
>          kvm_arch_get_supported_cpuid(s, KVM_CPUID_FEATURES, 0, R_EAX);
>  
> +    x86_cpu_def->cpuid_pmu_passthrough = true;
> +
>  #endif /* CONFIG_KVM */
>  }
>  
> @@ -1735,9 +1753,13 @@ static void cpu_x86_register(X86CPU *cpu, const char *name, Error **errp)
>          return;
>      }
>  
> +    /* Defaults & compat bits that are not in the builtin_x86_defs table: */
>      if (kvm_enabled()) {
>          def->features[FEAT_KVM] |= kvm_default_features;
>      }
> +    if (default_pmu_passthrough) {
> +        def->cpuid_pmu_passthrough = true;
> +    }
>      def->features[FEAT_1_ECX] |= CPUID_EXT_HYPERVISOR;
>  
>      object_property_set_str(OBJECT(cpu), def->vendor, "vendor", errp);
> @@ -1755,6 +1777,7 @@ static void cpu_x86_register(X86CPU *cpu, const char *name, Error **errp)
>      env->features[FEAT_C000_0001_EDX] = def->features[FEAT_C000_0001_EDX];
>      env->features[FEAT_7_0_EBX] = def->features[FEAT_7_0_EBX];
>      env->cpuid_xlevel2 = def->xlevel2;
> +    env->cpuid_pmu_passthrough = def->cpuid_pmu_passthrough;
>  
>      object_property_set_str(OBJECT(cpu), def->model_id, "model-id", errp);
>  }
> @@ -1986,7 +2009,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
>          break;
>      case 0xA:
>          /* Architectural Performance Monitoring Leaf */
> -        if (kvm_enabled()) {
> +        if (kvm_enabled() && env->cpuid_pmu_passthrough) {
>              KVMState *s = cs->kvm_state;
>  
>              *eax = kvm_arch_get_supported_cpuid(s, 0xA, count, R_EAX);
> diff --git a/target-i386/cpu.h b/target-i386/cpu.h
> index 1cd5d19..12c8bf1 100644
> --- a/target-i386/cpu.h
> +++ b/target-i386/cpu.h
> @@ -843,6 +843,12 @@ typedef struct CPUX86State {
>      uint32_t cpuid_vendor3;
>      uint32_t cpuid_version;
>      FeatureWordArray features;
> +
> +    /* Enable direct passthrough of PMU leaf from the GET_SUPPORTED_CPUID
> +     * data returned by the kernel. This is not migration-safe and should
> +     * never be enabled by default.
> +     */
> +    bool cpuid_pmu_passthrough;
>      uint32_t cpuid_model[12];
>      uint32_t cpuid_apic_id;
>  
> @@ -1258,6 +1264,7 @@ void x86_cpu_compat_set_features(const char *cpu_model, FeatureWord w,
>                                   uint32_t feat_add, uint32_t feat_remove);
>  void x86_cpu_compat_set_level(const char *cpu_model, uint32_t level);
>  void x86_cpu_compat_set_model(const char *cpu_model, uint32_t model);
> +void x86_cpu_enable_pmu_passthrough(void);
>  
>  
>  /* Return name of 32-bit register, from a R_* constant */
> -- 
> 1.8.1.4
> 


-- 
Regards,
  Igor

  reply	other threads:[~2013-04-26 15:10 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-25 18:42 [Qemu-devel] [RFC 0/7] CPUID fixes for 1.5 Eduardo Habkost
2013-04-25 18:43 ` [Qemu-devel] [RFC 1/7] target-i386: Introduce generic CPUID feature compat function Eduardo Habkost
2013-05-06 20:34   ` Andreas Färber
2013-04-25 18:43 ` [Qemu-devel] [RFC 2/7] target-i386: Introduce compat function to set CPUID 'level' Eduardo Habkost
2013-04-26 15:16   ` Igor Mammedov
2013-04-26 15:28     ` Eduardo Habkost
2013-04-25 18:43 ` [Qemu-devel] [RFC 3/7] target-i386: Introduce compat function to set CPUID 'model' Eduardo Habkost
2013-04-25 18:43 ` [Qemu-devel] [RFC 4/7] pc: Use separate init functions for pc-*-1.4 Eduardo Habkost
2013-04-25 18:43 ` [Qemu-devel] [RFC 5/7] target-i386: n270 can MOVBE Eduardo Habkost
2013-05-06 20:35   ` Andreas Färber
2013-04-25 18:43 ` [Qemu-devel] [RFC 6/7] target-i386: change CPUID model of 486 to 8 Eduardo Habkost
2013-04-25 19:11   ` Eduardo Habkost
2013-04-25 18:43 ` [Qemu-devel] [RFC 7/7] target-i386: Disable direct passthrough of PMU CPUID leaf by default Eduardo Habkost
2013-04-26 15:10   ` Igor Mammedov [this message]
2013-04-26 15:31     ` Eduardo Habkost
2013-04-26 15:33       ` Andreas Färber
2013-04-26 15:39         ` Igor Mammedov
2013-04-26 17:30           ` Eduardo Habkost
2013-04-26 17:41             ` Igor Mammedov
2013-04-26 19:01               ` Eduardo Habkost
2013-04-30 17:04                 ` Igor Mammedov
2013-04-30 19:57                   ` Eduardo Habkost
2013-05-01 11:14                     ` Andreas Färber
2013-05-02 14:43                       ` Eduardo Habkost
2013-05-02 14:50                         ` Andreas Färber

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=20130426171029.3e159116@thinkpad \
    --to=imammedo@redhat.com \
    --cc=afaerber@suse.de \
    --cc=ehabkost@redhat.com \
    --cc=gleb@redhat.com \
    --cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).