[PATCH 01/12] arm64: Prepare for sharing with s390

From: Steffen Eiden

Date: Wed Dec 02 2026 - 09:12:48 EST


Add s390 guards for arm headers which reside in include/kvm. This allows
s390 to use headers placed in its arch include/arm64/ .

Move vcpu_can_run to a more convenient location such that it can be
shared without adding another shared section. Move functions in
arch_timer.c to more convenient locations such that the required
functionality can be shared with just two shared regions instead of
seven.

Signed-off-by: Steffen Eiden <seiden@xxxxxxxxxxxxx>
---
arch/arm64/include/asm/kvm_host.h | 4 +-
arch/arm64/kvm/arch_timer.c | 87 ++++++++++++++++++++-------------------
arch/arm64/kvm/arm.c | 10 ++---
include/kvm/arm_hypercalls.h | 3 ++
include/kvm/arm_psci.h | 3 ++
5 files changed, 57 insertions(+), 50 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 3242bdf1acf8..5072de2ac8ce 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -396,6 +396,8 @@ static inline u16 kvm_mpidr_index(struct kvm_mpidr_data *data, u64 mpidr)
return index;
}

+struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr);
+
struct kvm_sysreg_masks;

enum fgt_group_id {
@@ -1444,8 +1446,6 @@ static inline bool kvm_arm_is_pvtime_enabled(struct kvm_vcpu_arch *vcpu_arch)
return (vcpu_arch->steal.base != INVALID_GPA);
}

-struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr);
-
DECLARE_KVM_HYP_PER_CPU(struct kvm_host_data, kvm_host_data);

/*
diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
index b2c5ba499aa5..2de8ce48a7a0 100644
--- a/arch/arm64/kvm/arch_timer.c
+++ b/arch/arm64/kvm/arch_timer.c
@@ -50,6 +50,7 @@ static u64 kvm_arm_timer_read(struct kvm_vcpu *vcpu,
struct arch_timer_context *timer,
enum kvm_arch_timer_regs treg);
static bool kvm_arch_timer_get_input_level(int vintid);
+static inline bool userspace_irqchip(struct kvm *kvm);

static unsigned long kvm_arch_timer_get_irq_flags(void)
{
@@ -67,14 +68,6 @@ static const struct irq_ops arch_timer_irq_ops_vgic_v5 = {
.set_direct_injection = vgic_v5_set_ppi_dvi,
};

-static int nr_timers(struct kvm_vcpu *vcpu)
-{
- if (!vcpu_has_nv(vcpu))
- return NR_KVM_EL0_TIMERS;
-
- return NR_KVM_TIMERS;
-}
-
u32 timer_get_ctl(struct arch_timer_context *ctxt)
{
struct kvm_vcpu *vcpu = timer_context_to_vcpu(ctxt);
@@ -191,22 +184,6 @@ void get_timer_map(struct kvm_vcpu *vcpu, struct timer_map *map)
trace_kvm_get_timer_map(vcpu->vcpu_id, map);
}

-static inline bool userspace_irqchip(struct kvm *kvm)
-{
- return unlikely(!irqchip_in_kernel(kvm));
-}
-
-static void soft_timer_start(struct hrtimer *hrt, u64 ns)
-{
- hrtimer_start(hrt, ktime_add_ns(ktime_get(), ns),
- HRTIMER_MODE_ABS_HARD);
-}
-
-static void soft_timer_cancel(struct hrtimer *hrt)
-{
- hrtimer_cancel(hrt);
-}
-
static irqreturn_t kvm_arch_timer_handler(int irq, void *dev_id)
{
struct kvm_vcpu *vcpu = *(struct kvm_vcpu **)dev_id;
@@ -257,11 +234,6 @@ static u64 kvm_counter_compute_delta(struct arch_timer_context *timer_ctx,
return 0;
}

-static u64 kvm_timer_compute_delta(struct arch_timer_context *timer_ctx)
-{
- return kvm_counter_compute_delta(timer_ctx, timer_get_cval(timer_ctx));
-}
-
static bool kvm_timer_enabled(struct arch_timer_context *timer_ctx)
{
WARN_ON(timer_ctx && timer_ctx->loaded);
@@ -276,6 +248,35 @@ static bool vcpu_has_wfit_active(struct kvm_vcpu *vcpu)
vcpu_get_flag(vcpu, IN_WFIT));
}

+static int nr_timers(struct kvm_vcpu *vcpu)
+{
+ if (!vcpu_has_nv(vcpu))
+ return NR_KVM_EL0_TIMERS;
+
+ return NR_KVM_TIMERS;
+}
+
+static inline bool userspace_irqchip(struct kvm *kvm)
+{
+ return unlikely(!irqchip_in_kernel(kvm));
+}
+
+static void soft_timer_start(struct hrtimer *hrt, u64 ns)
+{
+ hrtimer_start(hrt, ktime_add_ns(ktime_get(), ns),
+ HRTIMER_MODE_ABS_HARD);
+}
+
+static void soft_timer_cancel(struct hrtimer *hrt)
+{
+ hrtimer_cancel(hrt);
+}
+
+static u64 kvm_timer_compute_delta(struct arch_timer_context *timer_ctx)
+{
+ return kvm_counter_compute_delta(timer_ctx, timer_get_cval(timer_ctx));
+}
+
static u64 wfit_delay_ns(struct kvm_vcpu *vcpu)
{
u64 val = vcpu_get_reg(vcpu, kvm_vcpu_sys_get_rt(vcpu));
@@ -436,6 +437,20 @@ bool kvm_timer_update_run(struct kvm_vcpu *vcpu)
return !!mask;
}

+static void kvm_timer_unblocking(struct kvm_vcpu *vcpu)
+{
+ struct arch_timer_cpu *timer = vcpu_timer(vcpu);
+
+ soft_timer_cancel(&timer->bg_timer);
+}
+
+void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu)
+{
+ struct arch_timer_cpu *timer = vcpu_timer(vcpu);
+
+ soft_timer_cancel(&timer->bg_timer);
+}
+
static void kvm_timer_update_status(struct arch_timer_context *ctx, bool level)
{
/*
@@ -612,13 +627,6 @@ static void kvm_timer_blocking(struct kvm_vcpu *vcpu)
soft_timer_start(&timer->bg_timer, kvm_timer_earliest_exp(vcpu));
}

-static void kvm_timer_unblocking(struct kvm_vcpu *vcpu)
-{
- struct arch_timer_cpu *timer = vcpu_timer(vcpu);
-
- soft_timer_cancel(&timer->bg_timer);
-}
-
static void timer_restore_state(struct arch_timer_context *ctx)
{
struct arch_timer_cpu *timer = vcpu_timer(timer_context_to_vcpu(ctx));
@@ -1520,13 +1528,6 @@ int __init kvm_timer_hyp_init(bool has_gic)
return err;
}

-void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu)
-{
- struct arch_timer_cpu *timer = vcpu_timer(vcpu);
-
- soft_timer_cancel(&timer->bg_timer);
-}
-
static bool timer_irqs_are_valid(struct kvm_vcpu *vcpu)
{
u32 ppis = 0;
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 4d44b638b7d3..0d4d4849564c 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -901,6 +901,11 @@ static bool kvm_arm_vcpu_suspended(struct kvm_vcpu *vcpu)
return READ_ONCE(vcpu->arch.mp_state.mp_state) == KVM_MP_STATE_SUSPENDED;
}

+static bool vcpu_can_run(struct kvm_vcpu *vcpu)
+{
+ return !kvm_arm_vcpu_stopped(vcpu) && !atomic_read(&vcpu->arch.pause);
+}
+
/* Only the guest's CPU_ON may start a vCPU EL2 holds powered off. */
bool kvm_pkvm_vcpu_is_powered_off(struct kvm_vcpu *vcpu)
{
@@ -953,11 +958,6 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
return ret;
}

-static bool vcpu_can_run(struct kvm_vcpu *vcpu)
-{
- return !kvm_arm_vcpu_stopped(vcpu) && !atomic_read(&vcpu->arch.pause);
-}
-
/**
* kvm_arch_vcpu_runnable - determine if the vcpu can be scheduled
* @v: The VCPU pointer
diff --git a/include/kvm/arm_hypercalls.h b/include/kvm/arm_hypercalls.h
index 2df152207ccd..5ce4c2d43f9a 100644
--- a/include/kvm/arm_hypercalls.h
+++ b/include/kvm/arm_hypercalls.h
@@ -4,7 +4,10 @@
#ifndef __KVM_ARM_HYPERCALLS_H
#define __KVM_ARM_HYPERCALLS_H

+/* s390 provides its own header view */
+#ifndef __s390__
#include <asm/kvm_emulate.h>
+#endif // !__s390__

int kvm_smccc_call_handler(struct kvm_vcpu *vcpu);

diff --git a/include/kvm/arm_psci.h b/include/kvm/arm_psci.h
index 06c20612e9e7..f358ae19267b 100644
--- a/include/kvm/arm_psci.h
+++ b/include/kvm/arm_psci.h
@@ -10,7 +10,10 @@
#include <linux/kvm_host.h>
#include <uapi/linux/psci.h>

+/* s390 provides its own header view */
+#ifndef __s390__
#include <asm/kvm_emulate.h>
+#endif // !__s390__

#define KVM_ARM_PSCI_0_1 PSCI_VERSION(0, 1)
#define KVM_ARM_PSCI_0_2 PSCI_VERSION(0, 2)

--
2.56.1