On 2025/5/9 下午8:36, Jiaxun Yang wrote:


在2025年5月9日周五 上午11:07,Bibo Mao写道:
Add save and store funtction if irqchip-in-kernel property is enabled,
it is to get/set ExtIOI irqchip state from KVM kernel.

Signed-off-by: Bibo Mao <maob...@loongson.cn>
---
  hw/intc/loongarch_extioi.c         |  17 +++++
  hw/intc/loongarch_extioi_kvm.c     | 100 +++++++++++++++++++++++++++++
  include/hw/intc/loongarch_extioi.h |   2 +
  3 files changed, 119 insertions(+)

diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c
index 854f54684b..e81caf430c 100644
--- a/hw/intc/loongarch_extioi.c
+++ b/hw/intc/loongarch_extioi.c
@@ -398,9 +398,21 @@ static void loongarch_extioi_reset_hold(Object
*obj, ResetType type)
      }
  }

+static int vmstate_extioi_pre_save(void *opaque)
+{
+    LoongArchExtIOIState *les = LOONGARCH_EXTIOI(opaque);
+
+    if (kvm_enabled() && les->irqchip_in_kernel) {
+        return kvm_loongarch_extioi_pre_save(opaque);
+    }
+
+    return 0;
+}
+

Hi Bibo,

I believe hijacking loongarch_extioi.c is not the proper way to do it.
The sensible solution is to create a TYPE_LOONGARCH_EXTIOI_KVM, which
inherits TYPE_LOONGARCH_EXTIOI_COMMON, and let machine create
TYPE_LOONGARCH_EXTIOI_KVM vs TYPE_LOONGARCH_EXTIOI as necessary.
what is advantage about creating TYPE_LOONGARCH_EXTIOI_KVM device in KVM node and TYPE_LOONGARCH_EXTIOI device in TCG mode?

That means there will be two virt machine types since device name is different in different accel mode.

In this way you can avoid ugly "irqchip-in-kernel" property.
Also you don't really want all those emulation functions in
loongarch_extioi.c to kick in when irqchip is in kernel. If
IOCSR VMEXIT happens on extioi range, it's a hypervisor error
rather than something needs to be emulated.

Also I think EXTIOI_VIRT_CONFIG range MMIO needs to be handled
differently on KVM vs userspace irqchip. EXTIOI_VIRT_CONFIG needs
to be relayed to kernel, as virt_iocsr_misc_write will perform
IOCSR read/write in userspace, this needs to be translated to
KVM_DEV_LOONGARCH_EXTIOI_SW_STATUS_STATE.
Will handle it, misc iocsr should be emulated in kernel also.

Regards
Bibo Mao

Hope it makes sense.

Thanks



Reply via email to