[PATCH 12/12] KVM: s390: arm64: Add IRQ line
Steffen Eiden
seiden at linux.ibm.com
Wed Dec 2 06:11:50 PST 2026
From: Andreas Grapentin <gra at linux.ibm.com>
As all relevant helper and CPU management functions are in place and
behave correctly it is time to add support for non-kernel IRQ handling.
Implement the IRQ line for the !irqchip_in_kernel case.
With that arm on s390 is able to run full Linux arm64 guests using the
user irq chip.
Co-developed-by: Steffen Eiden <seiden at linux.ibm.com>
Signed-off-by: Andreas Grapentin <gra at linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden at linux.ibm.com>
---
arch/s390/include/arm64/kvm_emulate.h | 1 +
arch/s390/include/asm/kvm_host_arm64.h | 1 +
arch/s390/kvm/arm64/arm.c | 49 +++++++++++++++++++++++++++++++---
arch/s390/kvm/arm64/reset.c | 6 +++--
arch/s390/kvm/arm64/trace.h | 25 +++++++++++++++++
5 files changed, 77 insertions(+), 5 deletions(-)
diff --git a/arch/s390/include/arm64/kvm_emulate.h b/arch/s390/include/arm64/kvm_emulate.h
index bb2ddfe22b95..4b6aae2d6e67 100644
--- a/arch/s390/include/arm64/kvm_emulate.h
+++ b/arch/s390/include/arm64/kvm_emulate.h
@@ -125,6 +125,7 @@ static inline void kvm_reset_fpsimd(struct kvm_vcpu *vcpu)
vcpu->arch.sae_block.fpcr = 0;
}
+void vcpu_reset_hcr(struct kvm_vcpu *vcpu);
void vcpu_reset_hcrx(struct kvm_vcpu *vcpu);
static inline bool is_hyp_ctxt(const struct kvm_vcpu *vcpu)
diff --git a/arch/s390/include/asm/kvm_host_arm64.h b/arch/s390/include/asm/kvm_host_arm64.h
index 8367d34990a9..08dd08e58f33 100644
--- a/arch/s390/include/asm/kvm_host_arm64.h
+++ b/arch/s390/include/asm/kvm_host_arm64.h
@@ -39,6 +39,7 @@ bool cpus_have_final_cap(unsigned int num);
/* GICv2 maximum TODO change with in-kernel gic support*/
#define KVM_MAX_VCPUS 8
#define __KVM_HAVE_VCPU_RUN_PID_CHANGE
+#define __KVM_HAVE_IRQ_LINE
#define KVM_S390_ARM64_IMPL_FEATURES ( \
BIT(KVM_ARM_VCPU_PTRAUTH_ADDRESS) | \
diff --git a/arch/s390/kvm/arm64/arm.c b/arch/s390/kvm/arm64/arm.c
index 7964848f37dd..0a736ff85a77 100644
--- a/arch/s390/kvm/arm64/arm.c
+++ b/arch/s390/kvm/arm64/arm.c
@@ -59,6 +59,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
case KVM_CAP_MP_STATE:
case KVM_CAP_ARM_PSCI:
case KVM_CAP_ARM_PSCI_0_2:
+ case KVM_CAP_ARM_USER_IRQ:
ret = 1;
break;
case KVM_CAP_ARM_SVE:
@@ -319,7 +320,12 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)
{
- return 0;
+ int irq_lines = vcpu->arch.hcr_el2 & (HCR_EL2_VI | HCR_EL2_VF | HCR_EL2_VSE);
+
+ irq_lines |= (!irqchip_in_kernel(vcpu->kvm) &&
+ kvm_timer_should_notify_user(vcpu));
+
+ return irq_lines && vcpu_can_run(vcpu);
}
static unsigned long system_supported_vcpu_features(struct kvm_vcpu *vcpu)
@@ -475,6 +481,13 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,
if (ret)
return ret;
+ /*
+ * Only KVM_ARM_VCPU_INIT ioctl rebuilds hcr_el2. The PSCI CPU_ON
+ * reset must preserve it so that the interrupt lines asserted via
+ * KVM_IRQ_LINE (VI/VF/VSE) survive.
+ */
+ vcpu_reset_hcr(vcpu);
+
scoped_guard(spinlock, &vcpu->arch.mp_state_lock) {
if (power_off)
__kvm_arm_vcpu_power_off(vcpu, KVM_MP_STATE_STOPPED);
@@ -488,8 +501,38 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,
int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
bool line_status)
{
- /* stub for now*/
- return -EINVAL;
+ u32 irq = irq_level->irq;
+ unsigned int irq_type, vcpu_id, irq_num;
+ struct kvm_vcpu *vcpu = NULL;
+ bool level = irq_level->level;
+
+ irq_type = (irq >> KVM_ARM_IRQ_TYPE_SHIFT) & KVM_ARM_IRQ_TYPE_MASK;
+ vcpu_id = (irq >> KVM_ARM_IRQ_VCPU_SHIFT) & KVM_ARM_IRQ_VCPU_MASK;
+ vcpu_id += ((irq >> KVM_ARM_IRQ_VCPU2_SHIFT) & KVM_ARM_IRQ_VCPU2_MASK) * (KVM_ARM_IRQ_VCPU_MASK + 1);
+ irq_num = (irq >> KVM_ARM_IRQ_NUM_SHIFT) & KVM_ARM_IRQ_NUM_MASK;
+
+ trace_kvm_irq_line(irq_type, vcpu_id, irq_num, irq_level->level);
+
+ switch (irq_type) {
+ case KVM_ARM_IRQ_TYPE_CPU:
+ if (irqchip_in_kernel(kvm))
+ return -ENXIO;
+
+ vcpu = kvm_get_vcpu_by_id(kvm, vcpu_id);
+ if (!vcpu)
+ return -EINVAL;
+
+ if (irq_num > KVM_ARM_IRQ_CPU_FIQ)
+ return -EINVAL;
+
+ return vcpu_interrupt_line(vcpu, irq_num, level);
+ /* no in kernel gic */
+ case KVM_ARM_IRQ_TYPE_PPI:
+ case KVM_ARM_IRQ_TYPE_SPI:
+ return -ENXIO;
+ default:
+ return -EINVAL;
+ }
}
static noinstr void arm_vcpu_enter_exit(phys_addr_t sae_block)
diff --git a/arch/s390/kvm/arm64/reset.c b/arch/s390/kvm/arm64/reset.c
index feec5009d2cb..891fe4b4fc16 100644
--- a/arch/s390/kvm/arm64/reset.c
+++ b/arch/s390/kvm/arm64/reset.c
@@ -23,7 +23,7 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu)
return true;
}
-static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu)
+void vcpu_reset_hcr(struct kvm_vcpu *vcpu)
{
vcpu->arch.hcr_el2 = HCR_EL2_E2H | HCR_EL2_RW | HCR_EL2_AMO |
HCR_EL2_IMO | HCR_EL2_FMO | HCR_EL2_PTW;
@@ -105,12 +105,14 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
kvm_timer_vcpu_reset(vcpu);
/* Reset special registers */
- vcpu_reset_hcr(vcpu);
vcpu_reset_hcrx(vcpu);
vcpu_reset_cptr(vcpu);
vcpu_reset_cnthctl(vcpu);
vcpu_reset_icc(vcpu);
+ /* Discard a pending SError */
+ vcpu->arch.hcr_el2 &= ~HCR_EL2_VSE;
+
if (reset_state.reset) {
/* The guest found the shoot yourself in the foot button */
if (reset_state.be)
diff --git a/arch/s390/kvm/arm64/trace.h b/arch/s390/kvm/arm64/trace.h
index 694752842cc4..ab69e66aaa7b 100644
--- a/arch/s390/kvm/arm64/trace.h
+++ b/arch/s390/kvm/arm64/trace.h
@@ -43,6 +43,31 @@ TRACE_EVENT(kvm_exit,
__entry->vcpu_pc)
);
+TRACE_EVENT(kvm_irq_line,
+ TP_PROTO(unsigned int type, int vcpu_idx, int irq_num, int level),
+ TP_ARGS(type, vcpu_idx, irq_num, level),
+
+ TP_STRUCT__entry(
+ __field( unsigned int, type )
+ __field( int, vcpu_idx )
+ __field( int, irq_num )
+ __field( int, level )
+ ),
+
+ TP_fast_assign(
+ __entry->type = type;
+ __entry->vcpu_idx = vcpu_idx;
+ __entry->irq_num = irq_num;
+ __entry->level = level;
+ ),
+
+ TP_printk("Inject %s interrupt (%d), vcpu->idx: %d, num: %d, level: %d",
+ (__entry->type == KVM_ARM_IRQ_TYPE_CPU) ? "CPU" :
+ (__entry->type == KVM_ARM_IRQ_TYPE_PPI) ? "VGIC PPI" :
+ (__entry->type == KVM_ARM_IRQ_TYPE_SPI) ? "VGIC SPI" : "UNKNOWN",
+ __entry->type, __entry->vcpu_idx, __entry->irq_num, __entry->level)
+);
+
TRACE_EVENT(kvm_mmio_nisv,
TP_PROTO(unsigned long vcpu_pc, unsigned long esr,
unsigned long far, unsigned long ipa),
--
2.56.1
More information about the linux-arm-kernel
mailing list