All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avnish Chouhan <avnish@linux.ibm.com>
To: hector.cao@canonical.com
Cc: grub-devel@gnu.org
Subject: Re: [RFC PATCH 2/2] target/i386: add compatibility property for pdcm feature
Date: Thu, 11 Sep 2025 16:09:03 +0530	[thread overview]
Message-ID: <97564f46c7850ec554c418d91b894a87@linux.ibm.com> (raw)
In-Reply-To: <mailman.870.1757509050.1197.grub-devel@gnu.org>

On 2025-09-10 18:27, grub-devel-request@gnu.org wrote:
> Message: 3
> Date: Wed, 10 Sep 2025 10:24:32 +0200
> From: Hector Cao <hector.cao@canonical.com>
> To: grub-devel@gnu.org
> Subject: [RFC PATCH 2/2] target/i386: add compatibility property for
> 	pdcm feature
> Message-ID: <20250910082432.14764-3-hector.cao@canonical.com>
> 
> The pdcm feature is supposed to be disabled when PMU is not
> available. Up until v10.1, pdcm feature is enabled even when PMU
> is off. This behavior has been fixed but this change breaks the
> migration of VMs that are run with QEMU < 10.0 and expect the pdcm
> feature to be enabled on the destination host.
> 
> This commit restores the legacy behavior for machines with version
> prior to 10.1 to allow the migration from older QEMU to QEMU 10.1.
> 
> Signed-off-by: Hector Cao <hector.cao@canonical.com>
> ---
>  hw/core/machine.c     |  1 +
>  migration/migration.h | 11 +++++++++++
>  migration/options.c   |  3 +++
>  target/i386/cpu.c     | 17 ++++++++++++++---
>  4 files changed, 29 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index 8ad5d79cb3..535184c221 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -46,6 +46,7 @@ GlobalProperty hw_compat_10_0[] = {
>      { "ramfb", "use-legacy-x86-rom", "true"},
>      { "vfio-pci-nohotplug", "use-legacy-x86-rom", "true" },
>      { "migration", "arch-cap-always-on", "true" },
> +    { "migration", "pdcm-on-even-without-pmu", "true" },
>  };
>  const size_t hw_compat_10_0_len = G_N_ELEMENTS(hw_compat_10_0);
> 
> diff --git a/migration/migration.h b/migration/migration.h
> index 5124ff3636..7d5b2aa042 100644
> --- a/migration/migration.h
> +++ b/migration/migration.h
> @@ -522,6 +522,17 @@ struct MigrationState {
>       * to a host with QEMU 10.1 with error : missing feature 
> arch-capabilities
>       */
>      bool arch_cap_always_on;
> +
> +    /*
> +     * This variable allows to keep the backward compatibility with
> QEMU (<10.1)
> +     * on the pdcm feature detection. The pdcm feature should be 
> disabled when
> +     * PMU is not available. Prio to 10.1, there is a bug and pdcm can 
> still be
> +     * enabled even if PMU is off. This behavior has been fixed by the 
> commit
> +     * e68ec29 (since 10.1).
> +     * This new behavior breaks migration of VMs that expect, with the 
> QEMU
> +     * (since 10.1), pdcm to be disabled.
> +     */
> +    bool pdcm_on_even_without_pmu;
>  };
> 
>  void migrate_set_state(MigrationStatus *state, MigrationStatus 
> old_state,
> diff --git a/migration/options.c b/migration/options.c
> index 3a80dba9c5..a2a95dfcc4 100644
> --- a/migration/options.c
> +++ b/migration/options.c
> @@ -206,6 +206,9 @@ const Property migration_properties[] = {
> 
>      DEFINE_PROP_BOOL("arch-cap-always-on", MigrationState,
>                       arch_cap_always_on, false),
> +
> +    DEFINE_PROP_BOOL("pdcm-on-even-without-pmu", MigrationState,

Hi Hector,

Missing space before '('

> +                     pdcm_on_even_without_pmu, false),
>  };
>  const size_t migration_properties_count = 
> ARRAY_SIZE(migration_properties);
> 
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index 6d85149e6e..1f0f2c8dbf 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -51,6 +51,8 @@
>  #include "disas/capstone.h"
>  #include "cpu-internal.h"
> 
> +#include "migration/migration.h"
> +
>  static void x86_cpu_realizefn(DeviceState *dev, Error **errp);
>  static void x86_cpu_get_supported_cpuid(uint32_t func, uint32_t index,
>                                          uint32_t *eax, uint32_t *ebx,
> @@ -7839,6 +7841,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t
> index, uint32_t count,
>      uint32_t signature[3];
>      X86CPUTopoInfo *topo_info = &env->topo_info;
>      uint32_t threads_per_pkg;
> +    MigrationState *ms = migrate_get_current();
> 
>      threads_per_pkg = x86_threads_per_pkg(topo_info);
> 
> @@ -7894,6 +7897,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t
> index, uint32_t count,
>              /* Fixup overflow: max value for bits 23-16 is 255. */
>              *ebx |= MIN(num, 255) << 16;
>          }
> +        if (ms->pdcm_on_even_without_pmu) {

Please move '{' to next line.

> +            if (!cpu->enable_pmu) {

Same as above!

> +                *ecx &= ~CPUID_EXT_PDCM;
> +            }
> +        }
>          break;
>      case 2: { /* cache info: needed for Pentium Pro compatibility */
>          const CPUCaches *caches;
> @@ -8892,6 +8900,7 @@ void x86_cpu_expand_features(X86CPU *cpu, Error 
> **errp)
>      FeatureWord w;
>      int i;
>      GList *l;
> +    MigrationState *ms = migrate_get_current();
> 
>      for (l = plus_features; l; l = l->next) {
>          const char *prop = l->data;
> @@ -8944,9 +8953,11 @@ void x86_cpu_expand_features(X86CPU *cpu, Error 
> **errp)
>          }
>      }
> 
> -    /* PDCM is fixed1 bit for TDX */
> -    if (!cpu->enable_pmu && !is_tdx_vm()) {
> -        env->features[FEAT_1_ECX] &= ~CPUID_EXT_PDCM;
> +    if (!ms->pdcm_on_even_without_pmu) {

Same as above!

> +        /* PDCM is fixed1 bit for TDX */
> +        if (!cpu->enable_pmu && !is_tdx_vm()) {

same as above!
Thank you!

Regards,
Avnish Chouhan

> +            env->features[FEAT_1_ECX] &= ~CPUID_EXT_PDCM;
> +        }
>      }
> 
>      for (i = 0; i < ARRAY_SIZE(feature_dependencies); i++) {
> --
> 2.45.2
> 
> 

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

  parent reply	other threads:[~2025-09-11 10:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.870.1757509050.1197.grub-devel@gnu.org>
2025-09-11  6:59 ` [PATCH v2] kern: perform NULL check in unregister paths (command/extcmd) Avnish Chouhan
2025-09-11  8:09   ` Srish Srinivasan
2025-09-11  8:27 ` [RFC PATCH 1/2] target/i386: add compatibility property for arch_capabilities Avnish Chouhan
2025-09-11 10:39 ` Avnish Chouhan [this message]
2025-09-04 14:35 Issues with pdcm in qemu 10.1-rc on migration and save/restore Hector Cao
2025-09-10  8:24 ` [RFC PATCH 0/2] Fix cross migration issue with missing features: pdcm, arch-capabilities Hector Cao
2025-09-10  8:24   ` [RFC PATCH 2/2] target/i386: add compatibility property for pdcm feature Hector Cao

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=97564f46c7850ec554c418d91b894a87@linux.ibm.com \
    --to=avnish@linux.ibm.com \
    --cc=grub-devel@gnu.org \
    --cc=hector.cao@canonical.com \
    /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.