[PATCH 03/12] KVM: arm64: Share timer and smccc code with s390

Steffen Eiden seiden at linux.ibm.com
Wed Dec 2 06:11:41 PST 2026


Share the whole smccc related files. s390 will use the whole unmodified
infrastructure. Share useful timer related functions. As timers work
differntly on s390 only a subset can be reused. Share functions for
managing SMP guests.

Signed-off-by: Steffen Eiden <seiden at linux.ibm.com>
---
 arch/arm64/kvm/arch_timer.c |  8 ++++++++
 arch/arm64/kvm/arm.c        | 15 +++++++++++++++
 arch/arm64/kvm/hypercalls.c |  4 ++++
 arch/arm64/kvm/psci.c       |  3 +++
 arch/arm64/kvm/pvtime.c     |  2 ++
 arch/arm64/kvm/trng.c       |  2 ++
 6 files changed, 34 insertions(+)

diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
index 2de8ce48a7a0..626cfa71133a 100644
--- a/arch/arm64/kvm/arch_timer.c
+++ b/arch/arm64/kvm/arch_timer.c
@@ -248,6 +248,8 @@ static bool vcpu_has_wfit_active(struct kvm_vcpu *vcpu)
 		vcpu_get_flag(vcpu, IN_WFIT));
 }
 
+#if ARM64_S390_COMMON == 1
+
 static int nr_timers(struct kvm_vcpu *vcpu)
 {
 	if (!vcpu_has_nv(vcpu))
@@ -314,6 +316,8 @@ static u64 kvm_timer_earliest_exp(struct kvm_vcpu *vcpu)
 	return min_delta;
 }
 
+#endif /* ARM64_S390_COMMON == 1 */
+
 static enum hrtimer_restart kvm_bg_timer_expire(struct hrtimer *hrt)
 {
 	struct arch_timer_cpu *timer;
@@ -406,6 +410,8 @@ static bool kvm_timer_pending(struct arch_timer_context *timer_ctx)
 	return cval <= now;
 }
 
+#if ARM64_S390_COMMON == 1
+
 int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
 {
 	return vcpu_has_wfit_active(vcpu) && wfit_delay_ns(vcpu) == 0;
@@ -451,6 +457,8 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu)
 	soft_timer_cancel(&timer->bg_timer);
 }
 
+#endif /* ARM64_S390_COMMON == 1 */
+
 static void kvm_timer_update_status(struct arch_timer_context *ctx, bool level)
 {
 	/*
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 0d4d4849564c..4b52dfdcec48 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -318,6 +318,7 @@ void kvm_arch_create_vm_debugfs(struct kvm *kvm)
 	kvm_s2_ptdump_create_debugfs(kvm);
 }
 
+#if ARM64_S390_COMMON == 1
 static void kvm_destroy_mpidr_data(struct kvm *kvm)
 {
 	struct kvm_mpidr_data *data;
@@ -334,6 +335,7 @@ static void kvm_destroy_mpidr_data(struct kvm *kvm)
 
 	mutex_unlock(&kvm->arch.config_lock);
 }
+#endif /* ARM64_S390_COMMON == 1 */
 
 /**
  * kvm_arch_destroy_vm - destroy the VM data structure
@@ -865,6 +867,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
 	vcpu->cpu = -1;
 }
 
+#if ARM64_S390_COMMON == 1
 static void __kvm_arm_vcpu_power_off(struct kvm_vcpu *vcpu, u32 mp_state)
 {
 	WRITE_ONCE(vcpu->arch.mp_state.mp_state, mp_state);
@@ -912,6 +915,8 @@ bool kvm_pkvm_vcpu_is_powered_off(struct kvm_vcpu *vcpu)
 	return READ_ONCE(vcpu->arch.mp_state.mp_state) == KVM_MP_STATE_UNINITIALIZED;
 }
 
+#endif /* ARM64_S390_COMMON == 1 */
+
 int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
 				    struct kvm_mp_state *mp_state)
 {
@@ -981,6 +986,7 @@ bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu)
 	return vcpu_mode_priv(vcpu);
 }
 
+#if ARM64_S390_COMMON == 1
 #ifdef CONFIG_GUEST_PERF_EVENTS
 unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu)
 {
@@ -1040,6 +1046,8 @@ static void kvm_init_mpidr_data(struct kvm *kvm)
 	mutex_unlock(&kvm->arch.config_lock);
 }
 
+#endif /* ARM64_S390_COMMON == 1 */
+
 /*
  * Handle both the initialisation that is being done when the vcpu is
  * run for the first time, as well as the updates that must be
@@ -1164,6 +1172,7 @@ void kvm_arm_resume_guest(struct kvm *kvm)
 		kvm_resume_vcpu(vcpu);
 }
 
+#if ARM64_S390_COMMON == 1
 static void kvm_vcpu_sleep(struct kvm_vcpu *vcpu)
 {
 	struct rcuwait *wait = kvm_arch_vcpu_get_wait(vcpu);
@@ -1249,6 +1258,7 @@ static int kvm_vcpu_suspend(struct kvm_vcpu *vcpu)
 	 */
 	return 1;
 }
+#endif /* ARM64_S390_COMMON == 1 */
 
 /**
  * check_vcpu_requests - check and handle pending vCPU requests
@@ -1607,6 +1617,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 	return ret;
 }
 
+#if ARM64_S390_COMMON == 1
 static int vcpu_interrupt_line(struct kvm_vcpu *vcpu, int number, bool level)
 {
 	int bit_index;
@@ -1641,6 +1652,8 @@ static int vcpu_interrupt_line(struct kvm_vcpu *vcpu, int number, bool level)
 	return 0;
 }
 
+#endif /* ARM64_S390_COMMON == 1 */
+
 int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
 			  bool line_status)
 {
@@ -3157,6 +3170,7 @@ static int __init init_hyp_mode(void)
 	return err;
 }
 
+#if ARM64_S390_COMMON == 1
 struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr)
 {
 	struct kvm_vcpu *vcpu = NULL;
@@ -3187,6 +3201,7 @@ struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr)
 	}
 	return NULL;
 }
+#endif /* ARM64_S390_COMMON == 1 */
 
 bool kvm_arch_irqchip_in_kernel(struct kvm *kvm)
 {
diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c
index c00b0044ef11..1314e2e11ac1 100644
--- a/arch/arm64/kvm/hypercalls.c
+++ b/arch/arm64/kvm/hypercalls.c
@@ -67,6 +67,8 @@ static void kvm_ptp_get_time(struct kvm_vcpu *vcpu, u64 *val)
 	val[3] = lower_32_bits(cycles);
 }
 
+#if ARM64_S390_COMMON == 1
+
 static bool kvm_smccc_default_allowed(u32 func_id)
 {
 	switch (func_id) {
@@ -691,3 +693,5 @@ int kvm_vm_smccc_set_attr(struct kvm *kvm, struct kvm_device_attr *attr)
 		return -ENXIO;
 	}
 }
+
+#endif /* ARM64_S390_COMMON == 1 */
diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c
index b01f8d44033f..582dbf4d6c00 100644
--- a/arch/arm64/kvm/psci.c
+++ b/arch/arm64/kvm/psci.c
@@ -16,6 +16,7 @@
 #include <kvm/arm_psci.h>
 #include <kvm/arm_hypercalls.h>
 
+#if ARM64_S390_COMMON == 1
 /*
  * This is an implementation of the Power State Coordination Interface
  * as described in ARM document number ARM DEN 0022A.
@@ -484,3 +485,5 @@ int kvm_psci_call(struct kvm_vcpu *vcpu)
 		return 1;
 	}
 }
+
+#endif /* ARM64_S390_COMMON == 1 */
diff --git a/arch/arm64/kvm/pvtime.c b/arch/arm64/kvm/pvtime.c
index 053fe831fa54..84e9b1937725 100644
--- a/arch/arm64/kvm/pvtime.c
+++ b/arch/arm64/kvm/pvtime.c
@@ -10,6 +10,7 @@
 
 #include <kvm/arm_hypercalls.h>
 
+#if ARM64_S390_COMMON == 1
 void kvm_update_stolen_time(struct kvm_vcpu *vcpu)
 {
 	struct kvm *kvm = vcpu->kvm;
@@ -131,3 +132,4 @@ int kvm_arm_pvtime_has_attr(struct kvm_vcpu *vcpu,
 	}
 	return -ENXIO;
 }
+#endif /* ARM64_S390_COMMON == 1 */
diff --git a/arch/arm64/kvm/trng.c b/arch/arm64/kvm/trng.c
index 99bdd7103c9c..fbec1329d953 100644
--- a/arch/arm64/kvm/trng.c
+++ b/arch/arm64/kvm/trng.c
@@ -8,6 +8,7 @@
 
 #include <kvm/arm_hypercalls.h>
 
+#if ARM64_S390_COMMON == 1
 #define ARM_SMCCC_TRNG_VERSION_1_0	0x10000UL
 
 /* Those values are deliberately separate from the generic SMCCC definitions. */
@@ -83,3 +84,4 @@ int kvm_trng_call(struct kvm_vcpu *vcpu)
 	smccc_set_retval(vcpu, val, 0, 0, 0);
 	return 1;
 }
+#endif /* ARM64_S390_COMMON == 1 */

-- 
2.56.1




More information about the linux-arm-kernel mailing list