diff mbox series

[v13,4/7] s390x/cpu_topology: CPU topology migration

Message ID 20221208094432.9732-5-pmorel@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series s390x: CPU Topology | expand

Commit Message

Pierre Morel Dec. 8, 2022, 9:44 a.m. UTC
The migration can only take place if both source and destination
of the migration both use or both do not use the CPU topology
facility.

We indicate a change in topology during migration postload for the
case the topology changed between source and destination.

Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>
---
 target/s390x/cpu.h        |  1 +
 hw/s390x/cpu-topology.c   | 49 +++++++++++++++++++++++++++++++++++++++
 target/s390x/cpu-sysemu.c |  8 +++++++
 3 files changed, 58 insertions(+)

Comments

Cédric Le Goater Dec. 9, 2022, 2:56 p.m. UTC | #1
On 12/8/22 10:44, Pierre Morel wrote:
> The migration can only take place if both source and destination
> of the migration both use or both do not use the CPU topology
> facility.
> 
> We indicate a change in topology during migration postload for the
> case the topology changed between source and destination.
> 
> Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>
> ---
>   target/s390x/cpu.h        |  1 +
>   hw/s390x/cpu-topology.c   | 49 +++++++++++++++++++++++++++++++++++++++
>   target/s390x/cpu-sysemu.c |  8 +++++++
>   3 files changed, 58 insertions(+)
> 
> diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h
> index bc1a7de932..284c708a6c 100644
> --- a/target/s390x/cpu.h
> +++ b/target/s390x/cpu.h
> @@ -854,6 +854,7 @@ void s390_do_cpu_set_diag318(CPUState *cs, run_on_cpu_data arg);
>   int s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch_id,
>                                   int vq, bool assign);
>   void s390_cpu_topology_reset(void);
> +int s390_cpu_topology_mtcr_set(void);
>   #ifndef CONFIG_USER_ONLY
>   unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu);
>   #else
> diff --git a/hw/s390x/cpu-topology.c b/hw/s390x/cpu-topology.c
> index f54afcf550..8a2fe041d4 100644
> --- a/hw/s390x/cpu-topology.c
> +++ b/hw/s390x/cpu-topology.c
> @@ -18,6 +18,7 @@
>   #include "target/s390x/cpu.h"
>   #include "hw/s390x/s390-virtio-ccw.h"
>   #include "hw/s390x/cpu-topology.h"
> +#include "migration/vmstate.h"
>   
>   /**
>    * s390_has_topology
> @@ -129,6 +130,53 @@ static void s390_topology_reset(DeviceState *dev)
>       s390_cpu_topology_reset();
>   }
>   
> +/**
> + * cpu_topology_postload
> + * @opaque: a pointer to the S390Topology
> + * @version_id: version identifier
> + *
> + * We check that the topology is used or is not used
> + * on both side identically.
> + *
> + * If the topology is in use we set the Modified Topology Change Report
> + * on the destination host.
> + */
> +static int cpu_topology_postload(void *opaque, int version_id)
> +{
> +    int ret;
> +
> +    /* We do not support CPU Topology, all is good */
> +    if (!s390_has_topology()) {
> +        return 0;
> +    }
> +
> +    /* We support CPU Topology, set the MTCR unconditionally */
> +    ret = s390_cpu_topology_mtcr_set();
> +    if (ret) {
> +        error_report("Failed to set MTCR: %s", strerror(-ret));
> +    }
> +    return ret;
> +}
> +
> +/**
> + * cpu_topology_needed:
> + * @opaque: The pointer to the S390Topology
> + *
> + * We always need to know if source and destination use the topology.
> + */
> +static bool cpu_topology_needed(void *opaque)
> +{
> +    return s390_has_topology();
> +}
> +
> +const VMStateDescription vmstate_cpu_topology = {
> +    .name = "cpu_topology",
> +    .version_id = 1,
> +    .post_load = cpu_topology_postload,

Please use 'cpu_topology_post_load', it is easier to catch with a grep.

Thanks,

C.

> +    .minimum_version_id = 1,
> +    .needed = cpu_topology_needed,
> +};
> +
>   /**
>    * topology_class_init:
>    * @oc: Object class
> @@ -145,6 +193,7 @@ static void topology_class_init(ObjectClass *oc, void *data)
>       device_class_set_props(dc, s390_topology_properties);
>       set_bit(DEVICE_CATEGORY_MISC, dc->categories);
>       dc->reset = s390_topology_reset;
> +    dc->vmsd = &vmstate_cpu_topology;
>   }
>   
>   static const TypeInfo cpu_topology_info = {
> diff --git a/target/s390x/cpu-sysemu.c b/target/s390x/cpu-sysemu.c
> index e27864c5f5..a8e3e6219d 100644
> --- a/target/s390x/cpu-sysemu.c
> +++ b/target/s390x/cpu-sysemu.c
> @@ -319,3 +319,11 @@ void s390_cpu_topology_reset(void)
>           }
>       }
>   }
> +
> +int s390_cpu_topology_mtcr_set(void)
> +{
> +    if (kvm_enabled()) {
> +        return kvm_s390_topology_set_mtcr(1);
> +    }
> +    return -ENOENT;
> +}
Pierre Morel Dec. 11, 2022, 2:55 p.m. UTC | #2
Sorry, I made an error in this patch that break the migration.

On 12/8/22 10:44, Pierre Morel wrote:

> +
> +const VMStateDescription vmstate_cpu_topology = {
> +    .name = "cpu_topology",
> +    .version_id = 1,
> +    .post_load = cpu_topology_postload,
> +    .minimum_version_id = 1,
> +    .needed = cpu_topology_needed,
> +};

Here having no VMStateField break the migration.
Since there will be a new spin I will change this in the next with 
something like this where I also add the saving of the mtcr before the 
migration to set it back after the migration.


+/**
+ * cpu_topology_post_load
+ * @opaque: a pointer to the S390Topology
+ * @version_id: version identifier
+ *
+ * We check that the topology is used or is not used
+ * on both side identically.
+ *
+ * If the topology is in use we set the Modified Topology Change Report
+ * on the destination host.
+ */
+static int cpu_topology_post_load(void *opaque, int version_id)
+{
+    S390Topology *topo = opaque;
+    int ret;
+
+    /* Set the MTCR to the saved value */
+    ret = s390_cpu_topology_mtcr_set(topo->mtcr);
+    if (ret) {
+        error_report("Failed to set MTCR: %s", strerror(-ret));
+    }
+    return ret;
+}
+
+/**
+ * cpu_topology_pre_save:
+ * @opaque: The pointer to the S390Topology
+ *
+ * Save the usage of the CPU Topology in the VM State.
+ */
+static int cpu_topology_pre_save(void *opaque)
+{
+    S390Topology *topo = opaque;
+
+    return  s390_cpu_topology_mtcr_get(&topo->mtcr);
+}
+
+/**
+ * cpu_topology_needed:
+ * @opaque: The pointer to the S390Topology
+ *
+ * We always need to know if source and destination use the topology.
+ */
+static bool cpu_topology_needed(void *opaque)
+{
+    return true;
+}
+
+const VMStateDescription vmstate_cpu_topology = {
+    .name = "cpu_topology",
+    .version_id = 1,
+    .post_load = cpu_topology_post_load,
+    .pre_save = cpu_topology_pre_save,
+    .minimum_version_id = 1,
+    .needed = cpu_topology_needed,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT8(mtcr, S390Topology),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
Pierre Morel Dec. 12, 2022, 9:14 a.m. UTC | #3
On 12/9/22 15:56, Cédric Le Goater wrote:
> On 12/8/22 10:44, Pierre Morel wrote:
>> The migration can only take place if both source and destination
>> of the migration both use or both do not use the CPU topology
>> facility.
>>
>> We indicate a change in topology during migration postload for the
>> case the topology changed between source and destination.
>>
>> Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>


>> +
>> +const VMStateDescription vmstate_cpu_topology = {
>> +    .name = "cpu_topology",
>> +    .version_id = 1,
>> +    .post_load = cpu_topology_postload,
> 
> Please use 'cpu_topology_post_load', it is easier to catch with a grep.
> 

OK

Regards,
Pierre
Christian Borntraeger Dec. 13, 2022, 1:26 p.m. UTC | #4
Am 08.12.22 um 10:44 schrieb Pierre Morel:
> The migration can only take place if both source and destination
> of the migration both use or both do not use the CPU topology
> facility.
> 
> We indicate a change in topology during migration postload for the
> case the topology changed between source and destination.

I dont get why we need this? If the target QEMU has topology it should
already create this according to the configuration. WHy do we need a
trigger?

> 
> Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>
> ---
>   target/s390x/cpu.h        |  1 +
>   hw/s390x/cpu-topology.c   | 49 +++++++++++++++++++++++++++++++++++++++
>   target/s390x/cpu-sysemu.c |  8 +++++++
>   3 files changed, 58 insertions(+)
> 
> diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h
> index bc1a7de932..284c708a6c 100644
> --- a/target/s390x/cpu.h
> +++ b/target/s390x/cpu.h
> @@ -854,6 +854,7 @@ void s390_do_cpu_set_diag318(CPUState *cs, run_on_cpu_data arg);
>   int s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch_id,
>                                   int vq, bool assign);
>   void s390_cpu_topology_reset(void);
> +int s390_cpu_topology_mtcr_set(void);
>   #ifndef CONFIG_USER_ONLY
>   unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu);
>   #else
> diff --git a/hw/s390x/cpu-topology.c b/hw/s390x/cpu-topology.c
> index f54afcf550..8a2fe041d4 100644
> --- a/hw/s390x/cpu-topology.c
> +++ b/hw/s390x/cpu-topology.c
> @@ -18,6 +18,7 @@
>   #include "target/s390x/cpu.h"
>   #include "hw/s390x/s390-virtio-ccw.h"
>   #include "hw/s390x/cpu-topology.h"
> +#include "migration/vmstate.h"
>   
>   /**
>    * s390_has_topology
> @@ -129,6 +130,53 @@ static void s390_topology_reset(DeviceState *dev)
>       s390_cpu_topology_reset();
>   }
>   
> +/**
> + * cpu_topology_postload
> + * @opaque: a pointer to the S390Topology
> + * @version_id: version identifier
> + *
> + * We check that the topology is used or is not used
> + * on both side identically.
> + *
> + * If the topology is in use we set the Modified Topology Change Report
> + * on the destination host.
> + */
> +static int cpu_topology_postload(void *opaque, int version_id)
> +{
> +    int ret;
> +
> +    /* We do not support CPU Topology, all is good */
> +    if (!s390_has_topology()) {
> +        return 0;
> +    }
> +
> +    /* We support CPU Topology, set the MTCR unconditionally */
> +    ret = s390_cpu_topology_mtcr_set();
> +    if (ret) {
> +        error_report("Failed to set MTCR: %s", strerror(-ret));
> +    }
> +    return ret;
> +}
> +
> +/**
> + * cpu_topology_needed:
> + * @opaque: The pointer to the S390Topology
> + *
> + * We always need to know if source and destination use the topology.
> + */
> +static bool cpu_topology_needed(void *opaque)
> +{
> +    return s390_has_topology();
> +}
> +
> +const VMStateDescription vmstate_cpu_topology = {
> +    .name = "cpu_topology",
> +    .version_id = 1,
> +    .post_load = cpu_topology_postload,
> +    .minimum_version_id = 1,
> +    .needed = cpu_topology_needed,
> +};
> +
>   /**
>    * topology_class_init:
>    * @oc: Object class
> @@ -145,6 +193,7 @@ static void topology_class_init(ObjectClass *oc, void *data)
>       device_class_set_props(dc, s390_topology_properties);
>       set_bit(DEVICE_CATEGORY_MISC, dc->categories);
>       dc->reset = s390_topology_reset;
> +    dc->vmsd = &vmstate_cpu_topology;
>   }
>   
>   static const TypeInfo cpu_topology_info = {
> diff --git a/target/s390x/cpu-sysemu.c b/target/s390x/cpu-sysemu.c
> index e27864c5f5..a8e3e6219d 100644
> --- a/target/s390x/cpu-sysemu.c
> +++ b/target/s390x/cpu-sysemu.c
> @@ -319,3 +319,11 @@ void s390_cpu_topology_reset(void)
>           }
>       }
>   }
> +
> +int s390_cpu_topology_mtcr_set(void)
> +{
> +    if (kvm_enabled()) {
> +        return kvm_s390_topology_set_mtcr(1);
> +    }
> +    return -ENOENT;
> +}
Pierre Morel Dec. 13, 2022, 5:40 p.m. UTC | #5
On 12/13/22 14:26, Christian Borntraeger wrote:
> Am 08.12.22 um 10:44 schrieb Pierre Morel:
>> The migration can only take place if both source and destination
>> of the migration both use or both do not use the CPU topology
>> facility.
>>
>> We indicate a change in topology during migration postload for the
>> case the topology changed between source and destination.
> 
> I dont get why we need this? If the target QEMU has topology it should
> already create this according to the configuration. WHy do we need a
> trigger?

We do not.
The first idea was to migrate the topology with a dedicated object but 
after today discussion, it will be recreated by the admin on the target 
and the MTCR will not be migrated but simply set to 1 on target start.

So next spin will not get migration included.

Regards,
Pierre
diff mbox series

Patch

diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h
index bc1a7de932..284c708a6c 100644
--- a/target/s390x/cpu.h
+++ b/target/s390x/cpu.h
@@ -854,6 +854,7 @@  void s390_do_cpu_set_diag318(CPUState *cs, run_on_cpu_data arg);
 int s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch_id,
                                 int vq, bool assign);
 void s390_cpu_topology_reset(void);
+int s390_cpu_topology_mtcr_set(void);
 #ifndef CONFIG_USER_ONLY
 unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu);
 #else
diff --git a/hw/s390x/cpu-topology.c b/hw/s390x/cpu-topology.c
index f54afcf550..8a2fe041d4 100644
--- a/hw/s390x/cpu-topology.c
+++ b/hw/s390x/cpu-topology.c
@@ -18,6 +18,7 @@ 
 #include "target/s390x/cpu.h"
 #include "hw/s390x/s390-virtio-ccw.h"
 #include "hw/s390x/cpu-topology.h"
+#include "migration/vmstate.h"
 
 /**
  * s390_has_topology
@@ -129,6 +130,53 @@  static void s390_topology_reset(DeviceState *dev)
     s390_cpu_topology_reset();
 }
 
+/**
+ * cpu_topology_postload
+ * @opaque: a pointer to the S390Topology
+ * @version_id: version identifier
+ *
+ * We check that the topology is used or is not used
+ * on both side identically.
+ *
+ * If the topology is in use we set the Modified Topology Change Report
+ * on the destination host.
+ */
+static int cpu_topology_postload(void *opaque, int version_id)
+{
+    int ret;
+
+    /* We do not support CPU Topology, all is good */
+    if (!s390_has_topology()) {
+        return 0;
+    }
+
+    /* We support CPU Topology, set the MTCR unconditionally */
+    ret = s390_cpu_topology_mtcr_set();
+    if (ret) {
+        error_report("Failed to set MTCR: %s", strerror(-ret));
+    }
+    return ret;
+}
+
+/**
+ * cpu_topology_needed:
+ * @opaque: The pointer to the S390Topology
+ *
+ * We always need to know if source and destination use the topology.
+ */
+static bool cpu_topology_needed(void *opaque)
+{
+    return s390_has_topology();
+}
+
+const VMStateDescription vmstate_cpu_topology = {
+    .name = "cpu_topology",
+    .version_id = 1,
+    .post_load = cpu_topology_postload,
+    .minimum_version_id = 1,
+    .needed = cpu_topology_needed,
+};
+
 /**
  * topology_class_init:
  * @oc: Object class
@@ -145,6 +193,7 @@  static void topology_class_init(ObjectClass *oc, void *data)
     device_class_set_props(dc, s390_topology_properties);
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
     dc->reset = s390_topology_reset;
+    dc->vmsd = &vmstate_cpu_topology;
 }
 
 static const TypeInfo cpu_topology_info = {
diff --git a/target/s390x/cpu-sysemu.c b/target/s390x/cpu-sysemu.c
index e27864c5f5..a8e3e6219d 100644
--- a/target/s390x/cpu-sysemu.c
+++ b/target/s390x/cpu-sysemu.c
@@ -319,3 +319,11 @@  void s390_cpu_topology_reset(void)
         }
     }
 }
+
+int s390_cpu_topology_mtcr_set(void)
+{
+    if (kvm_enabled()) {
+        return kvm_s390_topology_set_mtcr(1);
+    }
+    return -ENOENT;
+}