[PATCH] spapr: Fix VSMT mode when it is not supported by the kernel

Laurent Vivier posted 1 patch 1 week ago
Test docker-clang@ubuntu passed
Test docker-quick@centos7 passed
Test asan passed
Test checkpatch passed
Test FreeBSD passed
Test docker-mingw@fedora passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20191108154035.12913-1-lvivier@redhat.com
Maintainers: David Gibson <david@gibson.dropbear.id.au>
hw/ppc/spapr.c       | 2 +-
target/ppc/kvm.c     | 5 +++++
target/ppc/kvm_ppc.h | 6 ++++++
3 files changed, 12 insertions(+), 1 deletion(-)

[PATCH] spapr: Fix VSMT mode when it is not supported by the kernel

Posted by Laurent Vivier 1 week ago
Commit 29cb4187497d sets by default the VSMT to smp_threads,
but older kernels (< 4.13) don't support that.

We can reasonably restore previous behavior with this kernel
to allow to run QEMU as before.

If VSMT is not supported, VSMT will be set to MAX(8, smp_threads)
as it is done for previous machine types (< pseries-4.2)

Fixes: 29cb4187497d ("spapr: Set VSMT to smp_threads by default")
Cc: groug@kaod.org
Reported-by: Lukáš Doktor <ldoktor@redhat.com>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 hw/ppc/spapr.c       | 2 +-
 target/ppc/kvm.c     | 5 +++++
 target/ppc/kvm_ppc.h | 6 ++++++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 94f9d27096af..f6c8ad1eda32 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -2522,7 +2522,7 @@ static void spapr_set_vsmt_mode(SpaprMachineState *spapr, Error **errp)
             goto out;
         }
         /* In this case, spapr->vsmt has been set by the command line */
-    } else if (!smc->smp_threads_vsmt) {
+    } else if (!smc->smp_threads_vsmt || !kvmppc_check_smt_possible()) {
         /*
          * Default VSMT value is tricky, because we need it to be as
          * consistent as possible (for migration), but this requires
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index 7d2e8969ac5f..40ed59881167 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -2060,6 +2060,11 @@ void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy)
     }
 }
 
+bool kvmppc_check_smt_possible(void)
+{
+    return kvm_enabled() && cap_ppc_smt_possible;
+}
+
 int kvmppc_smt_threads(void)
 {
     return cap_ppc_smt ? cap_ppc_smt : 1;
diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h
index 98bd7d5da6d6..c9629a416b0b 100644
--- a/target/ppc/kvm_ppc.h
+++ b/target/ppc/kvm_ppc.h
@@ -27,6 +27,7 @@ void kvmppc_enable_h_page_init(void);
 void kvmppc_set_papr(PowerPCCPU *cpu);
 int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr);
 void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy);
+bool kvmppc_check_smt_possible(void);
 int kvmppc_smt_threads(void);
 void kvmppc_hint_smt_possible(Error **errp);
 int kvmppc_set_smt_threads(int smt);
@@ -159,6 +160,11 @@ static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy)
 {
 }
 
+static inline bool kvmppc_check_smt_possible(void)
+{
+    return false;
+}
+
 static inline int kvmppc_smt_threads(void)
 {
     return 1;
-- 
2.21.0


Re: [PATCH] spapr: Fix VSMT mode when it is not supported by the kernel

Posted by Greg Kurz 6 days ago
On Fri,  8 Nov 2019 16:40:35 +0100
Laurent Vivier <lvivier@redhat.com> wrote:

> Commit 29cb4187497d sets by default the VSMT to smp_threads,
> but older kernels (< 4.13) don't support that.
> 
> We can reasonably restore previous behavior with this kernel
> to allow to run QEMU as before.
> 
> If VSMT is not supported, VSMT will be set to MAX(8, smp_threads)
> as it is done for previous machine types (< pseries-4.2)
> 

It is usually _bad_ to base the machine behavior on host capabilities.
What happens if we migrate between an older kernel and a recent one ?

I understand this is to fix tests/migration-test on older kernels.
Couldn't this be achieved with migration-test doing some introspection
and maybe pass vsmt=8 on the QEMU command line ?

> Fixes: 29cb4187497d ("spapr: Set VSMT to smp_threads by default")
> Cc: groug@kaod.org
> Reported-by: Lukáš Doktor <ldoktor@redhat.com>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
>  hw/ppc/spapr.c       | 2 +-
>  target/ppc/kvm.c     | 5 +++++
>  target/ppc/kvm_ppc.h | 6 ++++++
>  3 files changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 94f9d27096af..f6c8ad1eda32 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -2522,7 +2522,7 @@ static void spapr_set_vsmt_mode(SpaprMachineState *spapr, Error **errp)
>              goto out;
>          }
>          /* In this case, spapr->vsmt has been set by the command line */
> -    } else if (!smc->smp_threads_vsmt) {
> +    } else if (!smc->smp_threads_vsmt || !kvmppc_check_smt_possible()) {
>          /*
>           * Default VSMT value is tricky, because we need it to be as
>           * consistent as possible (for migration), but this requires
> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
> index 7d2e8969ac5f..40ed59881167 100644
> --- a/target/ppc/kvm.c
> +++ b/target/ppc/kvm.c
> @@ -2060,6 +2060,11 @@ void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy)
>      }
>  }
>  
> +bool kvmppc_check_smt_possible(void)
> +{
> +    return kvm_enabled() && cap_ppc_smt_possible;
> +}
> +
>  int kvmppc_smt_threads(void)
>  {
>      return cap_ppc_smt ? cap_ppc_smt : 1;
> diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h
> index 98bd7d5da6d6..c9629a416b0b 100644
> --- a/target/ppc/kvm_ppc.h
> +++ b/target/ppc/kvm_ppc.h
> @@ -27,6 +27,7 @@ void kvmppc_enable_h_page_init(void);
>  void kvmppc_set_papr(PowerPCCPU *cpu);
>  int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr);
>  void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy);
> +bool kvmppc_check_smt_possible(void);
>  int kvmppc_smt_threads(void);
>  void kvmppc_hint_smt_possible(Error **errp);
>  int kvmppc_set_smt_threads(int smt);
> @@ -159,6 +160,11 @@ static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy)
>  {
>  }
>  
> +static inline bool kvmppc_check_smt_possible(void)
> +{
> +    return false;
> +}
> +
>  static inline int kvmppc_smt_threads(void)
>  {
>      return 1;


Re: [PATCH] spapr: Fix VSMT mode when it is not supported by the kernel

Posted by Laurent Vivier 6 days ago
On 08/11/2019 17:47, Greg Kurz wrote:
> On Fri,  8 Nov 2019 16:40:35 +0100
> Laurent Vivier <lvivier@redhat.com> wrote:
> 
>> Commit 29cb4187497d sets by default the VSMT to smp_threads,
>> but older kernels (< 4.13) don't support that.
>>
>> We can reasonably restore previous behavior with this kernel
>> to allow to run QEMU as before.
>>
>> If VSMT is not supported, VSMT will be set to MAX(8, smp_threads)
>> as it is done for previous machine types (< pseries-4.2)
>>
> 
> It is usually _bad_ to base the machine behavior on host capabilities.

This is already the case, statically: your patch guesses the kernel
always support VSMT. So you can't start the machine (and thus can't
migrate it to/from).

> What happens if we migrate between an older kernel and a recent one ?

I think migration is supported correctly only if parameters are
explicitly set. So this is not our case.

> I understand this is to fix tests/migration-test on older kernels.
> Couldn't this be achieved with migration-test doing some introspection
> and maybe pass vsmt=8 on the QEMU command line ?

It could be a little bit complicated to instrospect this.
We could also set by default vsmt=8 at the test level.

Thanks,
Laurent


Re: [PATCH] spapr: Fix VSMT mode when it is not supported by the kernel

Posted by Greg Kurz 6 days ago
On Fri, 8 Nov 2019 18:03:08 +0100
Laurent Vivier <lvivier@redhat.com> wrote:

> On 08/11/2019 17:47, Greg Kurz wrote:
> > On Fri,  8 Nov 2019 16:40:35 +0100
> > Laurent Vivier <lvivier@redhat.com> wrote:
> > 
> >> Commit 29cb4187497d sets by default the VSMT to smp_threads,
> >> but older kernels (< 4.13) don't support that.
> >>
> >> We can reasonably restore previous behavior with this kernel
> >> to allow to run QEMU as before.
> >>
> >> If VSMT is not supported, VSMT will be set to MAX(8, smp_threads)
> >> as it is done for previous machine types (< pseries-4.2)
> >>
> > 
> > It is usually _bad_ to base the machine behavior on host capabilities.
> 
> This is already the case, statically: your patch guesses the kernel
> always support VSMT. So you can't start the machine (and thus can't
> migrate it to/from).
> 

Failing to start the machine is okay. The thing we want to avoid is
to successfully start the guest and discover later on we cannot
migrate it.

> > What happens if we migrate between an older kernel and a recent one ?
> 
> I think migration is supported correctly only if parameters are
> explicitly set. So this is not our case.
> 

Hence my suggestion to introspect...

> > I understand this is to fix tests/migration-test on older kernels.
> > Couldn't this be achieved with migration-test doing some introspection
> > and maybe pass vsmt=8 on the QEMU command line ?
> 
> It could be a little bit complicated to instrospect this.

... ah, you likely know migration-test better than I do :)

> We could also set by default vsmt=8 at the test level.
> 

This would mean that we don't test an exact default setup, but this
would still test most of the migration paths. I guess this could be
an acceptable trade-off only if 'make check' must *really* support
older kernels.

> Thanks,
> Laurent
>