Skip to contentSkip to conversation

mshv: Fix soft reboot by using scrub partition ioctl on init

RFC PATCH New Doru Blânzeanu 1 participant 4 messages Oct 30

lore
Share & tools
lore
#0 lore raw

cover mshv: Fix soft reboot by using scrub partition ioctl on init

This series is an RFC because, the kernel mshv driver changes that introduce this ioctl, are not upstream yet.
Below is a link to the posted kernel patch.
https://lore.kernel.org/linux-hyperv/[email protected]/

This patch series uses the SCRUB_PARTITION ioctl during reset to ensure a sane state for the mshv driver.

The series consists of:
1. accel/mshv: mask mshv cpus as resetable
2. include/hw/hyperv: Add SCRUB_PARTITION ioctl
3. accel/mshv: use scrub_partition ioctl on init

The second commit that adds the SCRUB_PARTITION ioctl definition can be dropped once the kernel patch is merged and the Qemu linux-headers are updated.

In short, the changes mark the vCPUs as resettable and run the SCRUB_PARTITION ioctl on the synchronize_post_reset hook for the first vCPU.

Doru Blânzeanu (2):
include/hw/hyperv: Add SCRUB_PARTITION ioctl
accel/mshv: use scrub_partition ioctl on init

Magnus Kulke (1):
accel/mshv: mark mshv cpus as resetable

 accel/mshv/mshv-all.c          | 27 +++++++++++++++++++++++++--
 include/hw/hyperv/hvgdk_mini.h |  2 ++
 2 files changed, 27 insertions(+), 2 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

RFC PATCH 1/3 accel/mshv: mark mshv cpus as resetable

From: Magnus Kulke <[email protected]>

Guest using the MSHV accelerator aren't resetable otherwise.

---
 accel/mshv/mshv-all.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
accel/mshv/mshv-all.c +1 -1
index d820a67b95..a7b7017fb1 100644
@@ -952,7 +952,7 @@ static void mshv_cpu_synchronize(CPUState *cpu)
 
 static bool mshv_cpus_are_resettable(void)
 {
-    return false;
+    return true;
 }
 
 static void mshv_accel_class_init(ObjectClass *oc, const void *data)
Signature · 1 line
2.54.0
#2 lore raw

RFC PATCH 2/3 include/hw/hyperv: Add SCRUB_PARTITION ioctl

In reply to Doru Blânzeanu
---
 include/hw/hyperv/hvgdk_mini.h | 2 ++
 1 file changed, 2 insertions(+)
include/hw/hyperv/hvgdk_mini.h +2 -0
index 0983e3a58d..5178ed07a1 100644
@@ -545,6 +545,8 @@ struct hv_input_assert_virtual_interrupt {
 #define MSHV_IOEVENTFD              _IOW(MSHV_IOCTL, 0x04, struct mshv_user_ioeventfd)
 #define MSHV_SET_MSI_ROUTING        _IOW(MSHV_IOCTL, 0x05, struct mshv_user_irq_table)
 
+#define MSHV_SCRUB_PARTITION        _IO(MSHV_IOCTL, 0x0B)
+
 /*
  ********************************
  * VP APIs for child partitions *
Signature · 1 line
2.54.0
#3 lore raw

RFC PATCH 3/3 accel/mshv: use scrub_partition ioctl on init

In reply to Doru Blânzeanu

This is relevant on soft resets, when the MSHV partition will have a preinitialized state for guest enlightenments and LAPIC state. Without invoking the ioctl, a rebooted guest will fail during boot when attempting to init Hyper-V enlightenments or the APIC.

---
 accel/mshv/mshv-all.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
accel/mshv/mshv-all.c +24 -1
index a7b7017fb1..5e51d0f1fa 100644
@@ -84,6 +84,17 @@ static int mshv_load_cleanup(void *opaque)
     return 0;
 }
 
+static int scrub_partition(int vm_fd)
+{
+    int ret = ioctl(vm_fd, MSHV_SCRUB_PARTITION);
+
+    if (ret < 0) {
+        error_report("Failed to scrub partition");
+        return -errno;
+    }
+
+    return 0;
+}
 
 static int get_host_partition_property(int mshv_fd, uint32_t property_code,
                                        uint64_t *value)
@@ -906,7 +917,19 @@ static void mshv_cpu_synchronize_post_init(CPUState *cpu)
 
 static void mshv_cpu_synchronize_post_reset(CPUState *cpu)
 {
-    int ret = mshv_arch_store_vcpu_state(cpu);
+    int ret;
+    bool is_bsp = (cpu == first_cpu);
+
+    if (is_bsp) {
+        ret = scrub_partition(mshv_state->vm);
+        if (ret < 0) {
+            error_report("Failed to scrub partition during reset: %s",
+                         strerror(-ret));
+            vm_stop(RUN_STATE_INTERNAL_ERROR);
+        }
+    }
+
+    ret = mshv_arch_store_vcpu_state(cpu);
     if (ret) {
         error_report("Failed to put registers after reset: %s",
                      strerror(-ret));
Signature · 1 line
2.54.0