mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steffen Eiden <seiden@linux.ibm.com>
To: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>,
	Fuad Tabba <fuad.tabba@linux.dev>,
	Joey Gouly <joey.gouly@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Andreas Grapentin <gra@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Janosch Frank <frankja@linux.ibm.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>,
	David Hildenbrand <david@kernel.org>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	Friedrich Welter <fritz@linux.ibm.com>,
	Gautam Gala <ggala@linux.ibm.com>,
	Hariharan Mari <hari55@linux.ibm.com>,
	Hendrik Brueckner <brueckner@linux.ibm.com>,
	Nico Boehr <nrb@linux.ibm.com>,
	Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	linux-s390@vger.kernel.org, Steffen Eiden <seiden@linux.ibm.com>
Subject: [PATCH 03/12] KVM: arm64: Share timer and smccc code with s390
Date: Wed, 02 Dec 2026 15:11:41 +0100	[thread overview]
Message-ID: <20261202-smccc-v1-3-48340e2737b6@linux.ibm.com> (raw)
In-Reply-To: <20261202-smccc-v1-0-48340e2737b6@linux.ibm.com>

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@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


  parent reply	other threads:[~2026-12-02 14:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 14:11 [PATCH 00/12] KVM: s390: arm64: SMCCC, timers and IRQ line Steffen Eiden
2026-12-02 14:11 ` [PATCH 01/12] arm64: Prepare for sharing with s390 Steffen Eiden
2026-12-02 14:11 ` [PATCH 02/12] arm64: Share timer and smccc functionality " Steffen Eiden
2026-12-02 14:11 ` Steffen Eiden [this message]
2026-12-02 14:11 ` [PATCH 04/12] KVM: s390: arm64: Use register shadow helper Steffen Eiden
2026-12-02 14:11 ` [PATCH 05/12] KVM: s390: arm64: Shadow the guest timer CVAL registers Steffen Eiden
2026-12-02 14:11 ` [PATCH 06/12] KVM: s390: arm64: Use mpstate for guests Steffen Eiden
2026-12-02 14:11 ` [PATCH 07/12] KVM: s390: arm64: Enable full smccc support Steffen Eiden
2026-12-02 14:11 ` [PATCH 08/12] KVM: s390: arm64: Report fwregs to userspace Steffen Eiden
2026-12-02 14:11 ` [PATCH 09/12] KVM: s390: arm64: Provide timer infrastructure Steffen Eiden
2026-12-02 14:11 ` [PATCH 10/12] KVM: s390: arm64: Integrate guest timer Steffen Eiden
2026-12-02 14:11 ` [PATCH 11/12] KVM: s390: arm64: Trap WFx Steffen Eiden
2026-12-02 14:11 ` [PATCH 12/12] KVM: s390: arm64: Add IRQ line Steffen Eiden

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202-smccc-v1-3-48340e2737b6@linux.ibm.com \
    --to=seiden@linux.ibm.com \
    --cc=Ulrich.Weigand@de.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=arnd@arndb.de \
    --cc=borntraeger@linux.ibm.com \
    --cc=brueckner@linux.ibm.com \
    --cc=catalin.marinas@arm.com \
    --cc=david@kernel.org \
    --cc=frankja@linux.ibm.com \
    --cc=fritz@linux.ibm.com \
    --cc=fuad.tabba@linux.dev \
    --cc=ggala@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=gra@linux.ibm.com \
    --cc=hari55@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=joey.gouly@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=nrb@linux.ibm.com \
    --cc=oupton@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=suzuki.poulose@arm.com \
    --cc=svens@linux.ibm.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®