[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v4 31/42] xen/riscv: introduce imsic_migrate_vcpu()



Moving a vCPU's guest interrupt file to the pCPU the vCPU has been
moved to follows "Migrating a virtual hart to a different guest
interrupt file" in the AIA spec: take a new file, retarget the
interrupt producers to it, synchronize with them, move the state of the
old file into the new one and point hstatus.VGEIN at it. That is a
sizeable sequence, so it is implemented step by step, and
imsic_migrate_vcpu(), introduced here as its entry point, is
deliberately a stub for now: the move itself is left as
BUG_ON("unimplemented").

The function has to be called by the vCPU itself, right before it
enters the guest: as long as a vCPU runs on a pCPU, it can neither run
on nor be moved to any other one, so its file can't be in use elsewhere
while it is moved. An ASSERT() checks that the vCPU is the current one.

What these requirements already allow is to tell whether there is
anything to move at all: the file has to be moved only once the
scheduler has moved the vCPU, not on every entry to the guest. Return
early unless the vCPU's h/w interrupt file belongs to a pCPU other than
the one the vCPU runs on, as told by the new imsic_vsfile_needs_move().
A vCPU without a h/w file has nothing to move, as s/w guest interrupt
files aren't supported yet: such a vCPU is one which couldn't be given
a h/w file, e.g. as imsic_vsfile_attach() failed and crashed its
domain. vsfile_cpu is read without the lock: once a vCPU runs, nothing
but the vCPU itself changes it.

Nothing calls imsic_migrate_vcpu() yet.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
---
Changes in v4:
 - New patch, replacing "xen/riscv: handle the case when no vCPU
   migration is needed": the vCPU's interrupt file is now moved by the
   vCPU itself on its way back to the guest rather than from
   arch_move_irqs(), so what has to be told first is whether the file
   belongs to another pCPU, rather than whether the vCPU has run yet.
   Why the file isn't moved from arch_move_irqs() is explained in more
   detail in "xen/riscv: introduce arch_move_irqs()".
---
---
 xen/arch/riscv/imsic.c             | 37 ++++++++++++++++++++++++++++++
 xen/arch/riscv/include/asm/imsic.h |  2 ++
 2 files changed, 39 insertions(+)

diff --git a/xen/arch/riscv/imsic.c b/xen/arch/riscv/imsic.c
index 3d947226f371..48214ab0d363 100644
--- a/xen/arch/riscv/imsic.c
+++ b/xen/arch/riscv/imsic.c
@@ -1070,3 +1070,40 @@ void imsic_vsfile_attach(struct vcpu *v)
      */
     imsic_vsfile_set_vgein(v, hgei);
 }
+
+/*
+ * Whether the h/w guest interrupt file of @v, the vCPU running on this pCPU,
+ * belongs to another pCPU, i.e. has to be moved here by imsic_migrate_vcpu().
+ * A vCPU without a h/w file has none to move.
+ *
+ * No lock is needed: vsfile_cpu of a running vCPU is changed only by the vCPU
+ * itself, when it acquires a file in imsic_vsfile_attach().
+ *
+ * TODO: a s/w file, once supported, has to be moved too.
+ */
+static bool imsic_vsfile_needs_move(const struct vcpu *v)
+{
+    unsigned int cpu = ACCESS_ONCE(v->arch.vimsic_state->vsfile_cpu);
+
+    ASSERT(v == current);
+
+    return cpu != CPU_NONE && cpu != smp_processor_id();
+}
+
+/*
+ * Make the h/w guest interrupt file of @v belong to the pCPU @v runs on.
+ *
+ * Has to be called by @v itself (see the ASSERT() below), right before it
+ * enters the guest: as long as @v runs on this pCPU, it can neither run on
+ * nor be moved to another one, so its file can't be in use elsewhere while
+ * it is moved.
+ */
+void imsic_migrate_vcpu(struct vcpu *v)
+{
+    ASSERT(v == current);
+
+    if ( !imsic_vsfile_needs_move(v) )
+        return;
+
+    BUG_ON("unimplemented");
+}
diff --git a/xen/arch/riscv/include/asm/imsic.h 
b/xen/arch/riscv/include/asm/imsic.h
index 1f3ccfbccd1e..f7e537be29b4 100644
--- a/xen/arch/riscv/include/asm/imsic.h
+++ b/xen/arch/riscv/include/asm/imsic.h
@@ -133,4 +133,6 @@ int imsic_map_guest_file(struct vcpu *v, unsigned int 
vsfile_id);
 
 void imsic_vsfile_attach(struct vcpu *v);
 
+void imsic_migrate_vcpu(struct vcpu *v);
+
 #endif /* RISCV_IMSIC_H */
-- 
2.56.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.