[PATCH v12 24/24] virt: geniezone: Emulate IPI for guest VM

From: Liju-clr Chen
Date: Tue Jul 30 2024 - 04:31:26 EST


From: Kevenny Hsieh <kevenny.hsieh@xxxxxxxxxxxx>

Emulate Inter-Processor Interrupts (IPI) handling for guest VMs.
Ensure that when a vCPU thread enters an idle state and relinquishes
CPU control to the host, it can be woken up by IPIs issued by other
vCPUs through the gzvm driver.

Add a new wake-up mechanism, `GZVM_EXIT_IPI`, to handle IPIs. Ensure
that idle vCPUs can be woken up not only by virtual timer (vtimer) and
virtio interrupts but also by IPIs issued by other vCPUs.

Ensure proper handling of IPIs, allowing idle vCPUs to be woken up and
respond to interrupts, thereby maintaining correct and efficient
inter-processor communication within the guest VM.

Signed-off-by: Kevenny Hsieh <kevenny.hsieh@xxxxxxxxxxxx>
Signed-off-by: Liju Chen <liju-clr.chen@xxxxxxxxxxxx>
---
drivers/virt/geniezone/gzvm_exception.c | 5 +++++
drivers/virt/geniezone/gzvm_vcpu.c | 3 +++
include/linux/soc/mediatek/gzvm_drv.h | 1 +
include/uapi/linux/gzvm.h | 1 +
4 files changed, 10 insertions(+)

diff --git a/drivers/virt/geniezone/gzvm_exception.c b/drivers/virt/geniezone/gzvm_exception.c
index 391168a3f737..7a4e3d76aa7a 100644
--- a/drivers/virt/geniezone/gzvm_exception.c
+++ b/drivers/virt/geniezone/gzvm_exception.c
@@ -105,3 +105,8 @@ int gzvm_handle_guest_idle(struct gzvm_vcpu *vcpu)

return ret;
}
+
+void gzvm_handle_guest_ipi(struct gzvm_vcpu *vcpu)
+{
+ gzvm_vcpu_wakeup_all(vcpu->gzvm);
+}
diff --git a/drivers/virt/geniezone/gzvm_vcpu.c b/drivers/virt/geniezone/gzvm_vcpu.c
index 247848ee126c..5cdd6ccbe76d 100644
--- a/drivers/virt/geniezone/gzvm_vcpu.c
+++ b/drivers/virt/geniezone/gzvm_vcpu.c
@@ -184,6 +184,9 @@ static long gzvm_vcpu_run(struct gzvm_vcpu *vcpu, void __user *argp)
case GZVM_EXIT_IDLE:
gzvm_handle_guest_idle(vcpu);
break;
+ case GZVM_EXIT_IPI:
+ gzvm_handle_guest_ipi(vcpu);
+ break;
case GZVM_EXIT_UNKNOWN:
fallthrough;
default:
diff --git a/include/linux/soc/mediatek/gzvm_drv.h b/include/linux/soc/mediatek/gzvm_drv.h
index 61f3ae4ee793..0302890ed69e 100644
--- a/include/linux/soc/mediatek/gzvm_drv.h
+++ b/include/linux/soc/mediatek/gzvm_drv.h
@@ -241,6 +241,7 @@ int gzvm_handle_relinquish(struct gzvm_vcpu *vcpu, phys_addr_t ipa);
bool gzvm_handle_guest_hvc(struct gzvm_vcpu *vcpu);
bool gzvm_arch_handle_guest_hvc(struct gzvm_vcpu *vcpu);
int gzvm_handle_guest_idle(struct gzvm_vcpu *vcpu);
+void gzvm_handle_guest_ipi(struct gzvm_vcpu *vcpu);
void gzvm_vcpu_wakeup_all(struct gzvm *gzvm);

int gzvm_arch_create_device(u16 vm_id, struct gzvm_create_device *gzvm_dev);
diff --git a/include/uapi/linux/gzvm.h b/include/uapi/linux/gzvm.h
index 1fe483ef2ed5..bcbc4d62a70f 100644
--- a/include/uapi/linux/gzvm.h
+++ b/include/uapi/linux/gzvm.h
@@ -189,6 +189,7 @@ enum {
GZVM_EXIT_SHUTDOWN = 0x92920009,
GZVM_EXIT_GZ = 0x9292000a,
GZVM_EXIT_IDLE = 0x9292000b,
+ GZVM_EXIT_IPI = 0x9292000d,
};

/* exception definitions of GZVM_EXIT_EXCEPTION */
--
2.18.0