]> git.baikalelectronics.ru Git - kernel.git/commitdiff
powerpc/mobility: wait for memory transfer to complete
authorLaurent Dufour <ldufour@linux.ibm.com>
Wed, 13 Jul 2022 15:47:26 +0000 (17:47 +0200)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 25 Jul 2022 03:28:45 +0000 (13:28 +1000)
In pseries_migration_partition(), loop until the memory transfer is
complete. This way the calling drmgr process will not exit earlier,
allowing callbacks to be run only once the migration is fully completed.

If reading the VASI state is done after the hypervisor has completed the
migration, the HCALL is returning H_PARAMETER. We can safely assume that
the memory transfer is achieved if this happens.

This will also allow to manage the NMI watchdog state in the next commits.

Signed-off-by: Laurent Dufour <ldufour@linux.ibm.com>
Reviewed-by: Nathan Lynch <nathanl@linux.ibm.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220713154729.80789-2-ldufour@linux.ibm.com
arch/powerpc/platforms/pseries/mobility.c

index 78f3f74c7056bb92bf617442868a228143551fce..6297467072e6c455d5f459cd849970f44a3ac46b 100644 (file)
@@ -427,6 +427,43 @@ static int wait_for_vasi_session_suspending(u64 handle)
        return ret;
 }
 
+static void wait_for_vasi_session_completed(u64 handle)
+{
+       unsigned long state = 0;
+       int ret;
+
+       pr_info("waiting for memory transfer to complete...\n");
+
+       /*
+        * Wait for transition from H_VASI_RESUMED to H_VASI_COMPLETED.
+        */
+       while (true) {
+               ret = poll_vasi_state(handle, &state);
+
+               /*
+                * If the memory transfer is already complete and the migration
+                * has been cleaned up by the hypervisor, H_PARAMETER is return,
+                * which is translate in EINVAL by poll_vasi_state().
+                */
+               if (ret == -EINVAL || (!ret && state == H_VASI_COMPLETED)) {
+                       pr_info("memory transfer completed.\n");
+                       break;
+               }
+
+               if (ret) {
+                       pr_err("H_VASI_STATE return error (%d)\n", ret);
+                       break;
+               }
+
+               if (state != H_VASI_RESUMED) {
+                       pr_err("unexpected H_VASI_STATE result %lu\n", state);
+                       break;
+               }
+
+               msleep(500);
+       }
+}
+
 static void prod_single(unsigned int target_cpu)
 {
        long hvrc;
@@ -673,9 +710,16 @@ static int pseries_migrate_partition(u64 handle)
        vas_migration_handler(VAS_SUSPEND);
 
        ret = pseries_suspend(handle);
-       if (ret == 0)
+       if (ret == 0) {
                post_mobility_fixup();
-       else
+               /*
+                * Wait until the memory transfer is complete, so that the user
+                * space process returns from the syscall after the transfer is
+                * complete. This allows the user hooks to be executed at the
+                * right time.
+                */
+               wait_for_vasi_session_completed(handle);
+       } else
                pseries_cancel_migration(handle, ret);
 
        vas_migration_handler(VAS_RESUME);