Giacomo Travaglini has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/55964 )

 (

5 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one. )Change subject: arch-arm, kvm: Handle vcpu2 if more than 256 vCPUs are in use
......................................................................

arch-arm, kvm: Handle vcpu2 if more than 256 vCPUs are in use

According to KVM Docs [1]:

"When KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 is supported, the target vcpu is
identified as (256 * vcpu2_index + vcpu_index). Otherwise, vcpu2_index
must be zero."

The vcpu parameter from the setIntState method is populated with
the gem5 context identifier (ContextID) of a specific PE.
It is not contrained by the 256 vcpu limit, so it can already specify
more than 256 vcpus. We therefore just need to translate/unpack the
value in two indices (vcpu and vcpu2) which will be forwarded to KVM
when raising an IRQ from userspace.

We guard the vcpu2 retrieval with a hash define as this is a late
addition and some older kernels do not define this capability (4.15 as
an example).

[1]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html

Signed-off-by: Giacomo Travaglini <giacomo.travagl...@arm.com>
Change-Id: If0c475dc4a573337edd053020920e9b109d13991
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/55964
Reviewed-by: Andreas Sandberg <andreas.sandb...@arm.com>
Maintainer: Andreas Sandberg <andreas.sandb...@arm.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/arch/arm/kvm/gic.cc
1 file changed, 50 insertions(+), 2 deletions(-)

Approvals:
  Andreas Sandberg: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass




diff --git a/src/arch/arm/kvm/gic.cc b/src/arch/arm/kvm/gic.cc
index 8d60255..f5e5b4e 100644
--- a/src/arch/arm/kvm/gic.cc
+++ b/src/arch/arm/kvm/gic.cc
@@ -91,12 +91,27 @@
 KvmKernelGic::setIntState(unsigned type, unsigned vcpu, unsigned irq,
                           bool high)
 {
+    const unsigned vcpu_index = vcpu & 0xff;
+    const unsigned vcpu2_index = (vcpu >> 8) & 0xff;
+
+#if defined(KVM_CAP_ARM_IRQ_LINE_LAYOUT_2) && defined(KVM_ARM_IRQ_VCPU2_SHIFT)
+    static const bool vcpu2_enabled = vm.checkExtension(
+        KVM_CAP_ARM_IRQ_LINE_LAYOUT_2);
+    uint32_t kvm_vcpu = (vcpu2_index << KVM_ARM_IRQ_VCPU2_SHIFT) |
+                        (vcpu_index << KVM_ARM_IRQ_VCPU_SHIFT);
+#else
+    static const bool vcpu2_enabled = false;
+    uint32_t kvm_vcpu = (vcpu_index << KVM_ARM_IRQ_VCPU_SHIFT);
+#endif
+
+    panic_if((!vcpu2_enabled && vcpu2_index) || kvm_vcpu > 0xffff,
+              "VCPU out of range");
+
     assert(type <= KVM_ARM_IRQ_TYPE_MASK);
-    assert(vcpu <= KVM_ARM_IRQ_VCPU_MASK);
     assert(irq <= KVM_ARM_IRQ_NUM_MASK);
     const uint32_t line(
+        kvm_vcpu |
         (type << KVM_ARM_IRQ_TYPE_SHIFT) |
-        (vcpu << KVM_ARM_IRQ_VCPU_SHIFT) |
         (irq << KVM_ARM_IRQ_NUM_SHIFT));

     vm.setIRQLine(line, high);

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/55964
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: If0c475dc4a573337edd053020920e9b109d13991
Gerrit-Change-Number: 55964
Gerrit-PatchSet: 9
Gerrit-Owner: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to