Skip to contentSkip to conversation

KVM: s390: Introduce arm64 KVM

PATCH Superseded Steffen Eiden 6 participants 104 messages Aug 12 – Aug 28

Subsystems (14)
x86 KVM arm64 s390 +10 more subsystems

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
author reviewer
#5 lore raw

PATCH v6 3/33 KVM: Allow KVM implementations to switch off MMIO independent of Kconfig

In reply to Steffen Eiden

Only defining KVM_MMIO is not flexible enough for multi-KVM systems where one KVM implements MMIO but others do not. Solve this by additionally testing for the non-existence of KVM_NO_MMIO before including MMIO code to KVM.

---
 virt/kvm/coalesced_mmio.c | 4 ++++
 virt/kvm/coalesced_mmio.h | 2 +-
 virt/kvm/kvm_main.c       | 8 ++++----
 3 files changed, 9 insertions(+), 5 deletions(-)
virt/kvm/coalesced_mmio.c +4 -0
index 6b1d90161099..8ff9d9a6f47a 100644
@@ -15,6 +15,8 @@
 #include <linux/slab.h>
 #include <linux/kvm.h>
 
+#ifndef KVM_NO_MMIO
+
 #include "coalesced_mmio.h"
 
 static inline struct kvm_coalesced_mmio_dev *to_mmio(struct kvm_io_device *dev)
@@ -188,3 +190,5 @@ int kvm_vm_ioctl_unregister_coalesced_mmio(struct kvm *kvm,
 	 */
 	return 0;
 }
+
+#endif /* ifndef KVM_NO_MMIO */
virt/kvm/coalesced_mmio.h +1 -1
index 36f84264ed25..826af421a5be 100644
@@ -11,7 +11,7 @@
  *
  */
 
-#ifdef CONFIG_KVM_MMIO
+#if defined(CONFIG_KVM_MMIO) && !defined(KVM_NO_MMIO)
 
 #include <linux/list.h>
 
virt/kvm/kvm_main.c +4 -4
index 0b34477bf325..a5dcb38e80db 100644
@@ -4063,7 +4063,7 @@ static vm_fault_t kvm_vcpu_fault(struct vm_fault *vmf)
 	else if (vmf->pgoff == KVM_PIO_PAGE_OFFSET)
 		page = virt_to_page(vcpu->arch.pio_data);
 #endif
-#ifdef CONFIG_KVM_MMIO
+#if defined(CONFIG_KVM_MMIO) && !defined(KVM_NO_MMIO)
 	else if (vmf->pgoff == KVM_COALESCED_MMIO_PAGE_OFFSET)
 		page = virt_to_page(vcpu->kvm->coalesced_mmio_ring);
 #endif
@@ -4904,7 +4904,7 @@ static int kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)
 	case KVM_CAP_ENABLE_CAP_VM:
 	case KVM_CAP_HALT_POLL:
 		return 1;
-#ifdef CONFIG_KVM_MMIO
+#if defined(CONFIG_KVM_MMIO) && !defined(KVM_NO_MMIO)
 	case KVM_CAP_COALESCED_MMIO:
 		return KVM_COALESCED_MMIO_PAGE_OFFSET;
 	case KVM_CAP_COALESCED_PIO:
@@ -5245,7 +5245,7 @@ static long kvm_vm_ioctl(struct file *filp,
 		break;
 	}
 #endif
-#ifdef CONFIG_KVM_MMIO
+#if defined(CONFIG_KVM_MMIO) && !defined(KVM_NO_MMIO)
 	case KVM_REGISTER_COALESCED_MMIO: {
 		struct kvm_coalesced_mmio_zone zone;
 
@@ -5580,7 +5580,7 @@ static long kvm_dev_ioctl(struct file *filp,
 #ifdef CONFIG_X86
 		r += PAGE_SIZE;    /* pio data page */
 #endif
-#ifdef CONFIG_KVM_MMIO
+#if defined(CONFIG_KVM_MMIO) && !defined(KVM_NO_MMIO)
 		r += PAGE_SIZE;    /* coalesced mmio ring page */
 #endif
 		break;
Signature · 1 line
2.53.0
author reviewer
#20 lore raw

PATCH v6 8/33 KVM: arm64: Use accessor functions for core regs

In reply to Steffen Eiden

Instead of accessing the value directly use assessor function that abstract the actual location of the register values. Add a helper function to reset fpsimd registers. Enable other KVM implementations to reuse this code.

No functional changes.

---
 arch/arm64/include/asm/kvm_emulate.h | 34 ++++++++++++++++++++++++++--
 arch/arm64/kvm/guest.c               | 16 ++++++-------
 2 files changed, 40 insertions(+), 10 deletions(-)
arch/arm64/include/asm/kvm_emulate.h +32 -2
index 8603766c1b4d..b31d50bdf59e 100644
@@ -141,6 +141,31 @@ static __always_inline unsigned long *vcpu_cpsr(const struct kvm_vcpu *vcpu)
 	return (unsigned long *)&vcpu->arch.ctxt.regs.pstate;
 }
 
+static __always_inline unsigned long *vcpu_sp_el0(struct kvm_vcpu *vcpu)
+{
+	return (unsigned long *)&vcpu->arch.ctxt.regs.sp;
+}
+
+static __always_inline u64 *vcpu_sp_el1(struct kvm_vcpu *vcpu)
+{
+	return __ctxt_sys_reg(&vcpu->arch.ctxt, SP_EL1);
+}
+
+static __always_inline __u128 *vcpu_vreg(struct kvm_vcpu *vcpu, int n)
+{
+	return &vcpu->arch.ctxt.fp_regs.vregs[n];
+}
+
+static __always_inline __u32 *vcpu_fpsr(struct kvm_vcpu *vcpu)
+{
+	return &vcpu->arch.ctxt.fp_regs.fpsr;
+}
+
+static __always_inline __u32 *vcpu_fpcr(struct kvm_vcpu *vcpu)
+{
+	return &vcpu->arch.ctxt.fp_regs.fpcr;
+}
+
 static __always_inline bool vcpu_mode_is_32bit(const struct kvm_vcpu *vcpu)
 {
 	return !!(*vcpu_cpsr(vcpu) & PSR_MODE32_BIT);
@@ -737,6 +762,11 @@ static inline void vcpu_set_hcrx(struct kvm_vcpu *vcpu)
 	}
 }
 
+static inline void kvm_reset_fpsimd(struct kvm_vcpu *vcpu)
+{
+	memset(&vcpu->arch.ctxt.fp_regs, 0, sizeof(vcpu->arch.ctxt.fp_regs));
+}
+
 /* Reset a vcpu's core registers. */
 static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu)
 {
@@ -752,8 +782,8 @@ static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu)
 	/* Reset core registers */
 	memset(vcpu_gp_regs(vcpu), 0, sizeof(vcpu_gp_regs(vcpu)));
 	*vcpu_pc(vcpu) = 0;
-	vcpu->arch.ctxt.regs.sp = 0;
-	memset(&vcpu->arch.ctxt.fp_regs, 0, sizeof(vcpu->arch.ctxt.fp_regs));
+	*vcpu_sp_el0(vcpu) = 0;
+	kvm_reset_fpsimd(vcpu);
 	vcpu->arch.ctxt.spsr_abt = 0;
 	vcpu->arch.ctxt.spsr_und = 0;
 	vcpu->arch.ctxt.spsr_irq = 0;
arch/arm64/kvm/guest.c +8 -8
index b01d6622b872..773f6c8e5026 100644
@@ -134,19 +134,19 @@ static void *core_reg_addr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 	     KVM_REG_ARM_CORE_REG(regs.regs[30]):
 		off -= KVM_REG_ARM_CORE_REG(regs.regs[0]);
 		off /= 2;
-		return &vcpu->arch.ctxt.regs.regs[off];
+		return &vcpu_gp_regs(vcpu)[off];
 
 	case KVM_REG_ARM_CORE_REG(regs.sp):
-		return &vcpu->arch.ctxt.regs.sp;
+		return vcpu_sp_el0(vcpu);
 
 	case KVM_REG_ARM_CORE_REG(regs.pc):
-		return &vcpu->arch.ctxt.regs.pc;
+		return vcpu_pc(vcpu);
 
 	case KVM_REG_ARM_CORE_REG(regs.pstate):
-		return &vcpu->arch.ctxt.regs.pstate;
+		return vcpu_cpsr(vcpu);
 
 	case KVM_REG_ARM_CORE_REG(sp_el1):
-		return __ctxt_sys_reg(&vcpu->arch.ctxt, SP_EL1);
+		return vcpu_sp_el1(vcpu);
 
 	case KVM_REG_ARM_CORE_REG(elr_el1):
 		return __ctxt_sys_reg(&vcpu->arch.ctxt, ELR_EL1);
@@ -170,13 +170,13 @@ static void *core_reg_addr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 	     KVM_REG_ARM_CORE_REG(fp_regs.vregs[31]):
 		off -= KVM_REG_ARM_CORE_REG(fp_regs.vregs[0]);
 		off /= 4;
-		return &vcpu->arch.ctxt.fp_regs.vregs[off];
+		return vcpu_vreg(vcpu, off);
 
 	case KVM_REG_ARM_CORE_REG(fp_regs.fpsr):
-		return &vcpu->arch.ctxt.fp_regs.fpsr;
+		return vcpu_fpsr(vcpu);
 
 	case KVM_REG_ARM_CORE_REG(fp_regs.fpcr):
-		return &vcpu->arch.ctxt.fp_regs.fpcr;
+		return vcpu_fpcr(vcpu);
 
 	default:
 		return NULL;
Signature · 1 line
2.53.0
author reviewer
#17 lore raw

PATCH v6 7/33 KVM: arm64: Access elements of vcpu_gp_regs individually

In reply to Steffen Eiden

While for arm64 the members of vcpu_gp_regs are allocated continuous this is not necessarily true for other architectures implementing ARM.

Let vcpu_gp_regs() no longer return the address of the user_pt_regs in the vcpu context but the address of the gp-register array field in the user_pt_reg struct. Note, this change semantically excludes pc from the GPRs.

No functional change.

---
 arch/arm64/include/asm/kvm_emulate.h       | 14 ++++++++------
 arch/arm64/include/asm/kvm_host.h          |  2 +-
 arch/arm64/kvm/hyp/exception.c             |  4 ++--
 arch/arm64/kvm/hyp/include/hyp/adjust_pc.h |  4 ++--
 arch/arm64/kvm/hyp/include/hyp/switch.h    |  4 ++--
 5 files changed, 15 insertions(+), 13 deletions(-)
arch/arm64/include/asm/kvm_emulate.h +8 -6
index a3c1928bdf74..8603766c1b4d 100644
@@ -133,12 +133,12 @@ static inline void vcpu_set_vsesr(struct kvm_vcpu *vcpu, u64 vsesr)
 
 static __always_inline unsigned long *vcpu_pc(const struct kvm_vcpu *vcpu)
 {
-	return (unsigned long *)&vcpu_gp_regs(vcpu)->pc;
+	return (unsigned long *)&vcpu->arch.ctxt.regs.pc;
 }
 
 static __always_inline unsigned long *vcpu_cpsr(const struct kvm_vcpu *vcpu)
 {
-	return (unsigned long *)&vcpu_gp_regs(vcpu)->pstate;
+	return (unsigned long *)&vcpu->arch.ctxt.regs.pstate;
 }
 
 static __always_inline bool vcpu_mode_is_32bit(const struct kvm_vcpu *vcpu)
@@ -167,14 +167,14 @@ static inline void vcpu_set_thumb(struct kvm_vcpu *vcpu)
 static __always_inline unsigned long vcpu_get_reg(const struct kvm_vcpu *vcpu,
 					 u8 reg_num)
 {
-	return (reg_num == 31) ? 0 : vcpu_gp_regs(vcpu)->regs[reg_num];
+	return (reg_num == 31) ? 0 : vcpu_gp_regs(vcpu)[reg_num];
 }
 
 static __always_inline void vcpu_set_reg(struct kvm_vcpu *vcpu, u8 reg_num,
 				unsigned long val)
 {
 	if (reg_num != 31)
-		vcpu_gp_regs(vcpu)->regs[reg_num] = val;
+		vcpu_gp_regs(vcpu)[reg_num] = val;
 }
 
 static inline bool vcpu_is_el2_ctxt(const struct kvm_cpu_context *ctxt)
@@ -750,13 +750,15 @@ static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu)
 		pstate = VCPU_RESET_PSTATE_EL1;
 
 	/* Reset core registers */
-	memset(vcpu_gp_regs(vcpu), 0, sizeof(*vcpu_gp_regs(vcpu)));
+	memset(vcpu_gp_regs(vcpu), 0, sizeof(vcpu_gp_regs(vcpu)));
+	*vcpu_pc(vcpu) = 0;
+	vcpu->arch.ctxt.regs.sp = 0;
 	memset(&vcpu->arch.ctxt.fp_regs, 0, sizeof(vcpu->arch.ctxt.fp_regs));
 	vcpu->arch.ctxt.spsr_abt = 0;
 	vcpu->arch.ctxt.spsr_und = 0;
 	vcpu->arch.ctxt.spsr_irq = 0;
 	vcpu->arch.ctxt.spsr_fiq = 0;
-	vcpu_gp_regs(vcpu)->pstate = pstate;
+	*vcpu_cpsr(vcpu) = pstate;
 }
 
 /* PSCI reset handling for a vcpu. */
arch/arm64/include/asm/kvm_host.h +1 -1
index 27fe0cd5b2d7..46c8d7928b3f 100644
@@ -1158,7 +1158,7 @@ struct kvm_vcpu_arch {
 #define vcpu_clear_on_unsupported_cpu(vcpu)				\
 	vcpu_clear_flag(vcpu, ON_UNSUPPORTED_CPU)
 
-#define vcpu_gp_regs(v)		(&(v)->arch.ctxt.regs)
+#define vcpu_gp_regs(v)		((v)->arch.ctxt.regs.regs)
 
 /*
  * Only use __vcpu_sys_reg/ctxt_sys_reg if you know you want the
arch/arm64/kvm/hyp/exception.c +2 -2
index 754e2dc1df54..0640c9ccaa3c 100644
@@ -276,12 +276,12 @@ static void enter_exception32(struct kvm_vcpu *vcpu, u32 mode, u32 vect_offset)
 	switch(mode) {
 	case PSR_AA32_MODE_ABT:
 		__vcpu_write_spsr_abt(vcpu, host_spsr_to_spsr32(spsr));
-		vcpu_gp_regs(vcpu)->compat_lr_abt = return_address;
+		vcpu_gp_regs(vcpu)[__compat_lr_abt] = return_address;
 		break;
 
 	case PSR_AA32_MODE_UND:
 		__vcpu_write_spsr_und(vcpu, host_spsr_to_spsr32(spsr));
-		vcpu_gp_regs(vcpu)->compat_lr_und = return_address;
+		vcpu_gp_regs(vcpu)[__compat_lr_und] = return_address;
 		break;
 	}
 
arch/arm64/kvm/hyp/include/hyp/adjust_pc.h +2 -2
index 4fdfeabefeb4..a049983bd5c3 100644
@@ -33,11 +33,11 @@ static inline void kvm_skip_instr(struct kvm_vcpu *vcpu)
 static inline void __kvm_skip_instr(struct kvm_vcpu *vcpu)
 {
 	*vcpu_pc(vcpu) = read_sysreg_el2(SYS_ELR);
-	vcpu_gp_regs(vcpu)->pstate = read_sysreg_el2(SYS_SPSR);
+	*vcpu_cpsr(vcpu) = read_sysreg_el2(SYS_SPSR);
 
 	kvm_skip_instr(vcpu);
 
-	write_sysreg_el2(vcpu_gp_regs(vcpu)->pstate, SYS_SPSR);
+	write_sysreg_el2(*vcpu_cpsr(vcpu), SYS_SPSR);
 	write_sysreg_el2(*vcpu_pc(vcpu), SYS_ELR);
 }
 
arch/arm64/kvm/hyp/include/hyp/switch.h +2 -2
index 1ce7130e2549..a2a054fec2e2 100644
@@ -470,7 +470,7 @@ static inline bool kvm_hyp_handle_mops(struct kvm_vcpu *vcpu, u64 *exit_code)
 	u64 spsr;
 
 	*vcpu_pc(vcpu) = read_sysreg_el2(SYS_ELR);
-	arm64_mops_reset_regs(vcpu_gp_regs(vcpu), vcpu->arch.fault.esr_el2);
+	arm64_mops_reset_regs(&vcpu->arch.ctxt.regs, vcpu->arch.fault.esr_el2);
 	write_sysreg_el2(*vcpu_pc(vcpu), SYS_ELR);
 
 	/*
@@ -902,7 +902,7 @@ static inline void synchronize_vcpu_pstate(struct kvm_vcpu *vcpu)
 	/*
 	 * Check for the conditions of Cortex-A510's #2077057. When these occur
 	 * SPSR_EL2 can't be trusted, but isn't needed either as it is
-	 * unchanged from the value in vcpu_gp_regs(vcpu)->pstate.
+	 * unchanged from the value in vcpu_cpsr(vcpu).
 	 * Are we single-stepping the guest, and took a PAC exception from the
 	 * active-not-pending state?
 	 */
Signature · 1 line
2.53.0
author reviewer
#13 lore raw

PATCH v6 6/33 arm64: sysreg: Convert SPSR_ELx to automatic register generation

In reply to Steffen Eiden

Convert SPSR_EL{1, 2, 12} to automatic register generation as per DDIO616 2026-06. No functional change.

---
 arch/arm64/include/asm/sysreg.h |  3 ---
 arch/arm64/tools/sysreg         | 48 +++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 3 deletions(-)
arch/arm64/include/asm/sysreg.h +0 -3
index 4bfdac9401bd..1aa601c95188 100644
@@ -295,7 +295,6 @@
 #define SYS_APGAKEYLO_EL1		sys_reg(3, 0, 2, 3, 0)
 #define SYS_APGAKEYHI_EL1		sys_reg(3, 0, 2, 3, 1)
 
-#define SYS_SPSR_EL1			sys_reg(3, 0, 4, 0, 0)
 #define SYS_ELR_EL1			sys_reg(3, 0, 4, 0, 1)
 
 #define SYS_ICC_PMR_EL1			sys_reg(3, 0, 4, 6, 0)
@@ -518,7 +517,6 @@
 #define SYS_VTTBR_EL2			sys_reg(3, 4, 2, 1, 0)
 
 #define SYS_HAFGRTR_EL2			sys_reg(3, 4, 3, 1, 6)
-#define SYS_SPSR_EL2			sys_reg(3, 4, 4, 0, 0)
 #define SYS_ELR_EL2			sys_reg(3, 4, 4, 0, 1)
 #define SYS_SP_EL1			sys_reg(3, 4, 4, 1, 0)
 #define SYS_SPSR_irq			sys_reg(3, 4, 4, 3, 0)
@@ -604,7 +602,6 @@
 #define SYS_BRBCR_EL12			sys_reg(2, 5, 9, 0, 0)
 #define SYS_TTBR0_EL12			sys_reg(3, 5, 2, 0, 0)
 #define SYS_TTBR1_EL12			sys_reg(3, 5, 2, 0, 1)
-#define SYS_SPSR_EL12			sys_reg(3, 5, 4, 0, 0)
 #define SYS_ELR_EL12			sys_reg(3, 5, 4, 0, 1)
 #define SYS_AFSR0_EL12			sys_reg(3, 5, 5, 1, 0)
 #define SYS_AFSR1_EL12			sys_reg(3, 5, 5, 1, 1)
arch/arm64/tools/sysreg +48 -0

54 lines not on this page · raw message

Signature · 1 line
2.53.0
author reviewer
#1 lore raw

PATCH v6 1/33 vfio: Use file-based reference counting for KVM

In reply to Steffen Eiden

Replace manual module reference counting with file-based reference counting for KVM integration. Previously, VFIO used symbol_get() to obtain function pointers for kvm_get_kvm_safe() and kvm_put_kvm(), then manually tracked module references through these symbols. This approach required storing the put_kvm function pointer in each device and carefully managing symbol references. Remove the put_kvm field in struct vfio_device as is it no longer used.

Pass struct file pointers instead of struct kvm pointers throughout the VFIO-KVM interface. This leverages the kernel's existing file reference counting mechanism via get_file_active() and fput(), eliminating the need for manual module reference tracking. The file->private_data field provides access to the underlying struct kvm when needed.

This simplifies the code and removes all remaining externally exported symbols for KVM, paving the path for a second concurrent KVM module.

---
 arch/x86/include/asm/kvm_page_track.h |  8 ++---
 arch/x86/kvm/Makefile                 |  3 --
 arch/x86/kvm/mmu/page_track.c         | 16 +++++----
 drivers/s390/crypto/vfio_ap_ops.c     | 30 ++++++++++++----
 drivers/s390/crypto/vfio_ap_private.h |  1 +
 drivers/vfio/device_cdev.c            |  2 +-
 drivers/vfio/group.c                  |  4 +--
 drivers/vfio/pci/vfio_pci_zdev.c      |  7 +++-
 drivers/vfio/vfio.h                   | 10 +++---
 drivers/vfio/vfio_main.c              | 52 +++++++--------------------
 include/linux/kvm_host.h              |  7 ++++
 include/linux/vfio.h                  |  5 ++-
 virt/kvm/kvm_main.c                   | 22 ++++++++++--
 virt/kvm/vfio.c                       |  8 ++---
 14 files changed, 97 insertions(+), 78 deletions(-)
arch/x86/include/asm/kvm_page_track.h +4 -4
index 3d040741044b..046a25c8fe4f 100644
@@ -44,13 +44,13 @@ struct kvm_page_track_notifier_node {
 				    struct kvm_page_track_notifier_node *node);
 };
 
-int kvm_page_track_register_notifier(struct kvm *kvm,
+int kvm_page_track_register_notifier(struct file *file,
 				     struct kvm_page_track_notifier_node *n);
-void kvm_page_track_unregister_notifier(struct kvm *kvm,
+void kvm_page_track_unregister_notifier(struct file *file,
 					struct kvm_page_track_notifier_node *n);
 
-int kvm_write_track_add_gfn(struct kvm *kvm, gfn_t gfn);
-int kvm_write_track_remove_gfn(struct kvm *kvm, gfn_t gfn);
+int kvm_write_track_add_gfn(struct file *file, gfn_t gfn);
+int kvm_write_track_remove_gfn(struct file *file, gfn_t gfn);
 #else
 /*
  * Allow defining a node in a structure even if page tracking is disabled, e.g.
arch/x86/kvm/Makefile +0 -3
index 0474604ab8a1..70645c2cd8ed 100644
@@ -61,9 +61,6 @@ exports_grep_trailer := --include='*.[ch]' -nrw $(srctree)/virt/kvm $(srctree)/a
 				-e kvm_page_track_unregister_notifier \
 				-e kvm_write_track_add_gfn \
 				-e kvm_write_track_remove_gfn \
-				-e kvm_get_kvm \
-				-e kvm_get_kvm_safe \
-				-e kvm_put_kvm
 
 # Force grep to emit a goofy group separator that can in turn be replaced with
 # the above newline macro (newlines in Make are a nightmare).  Note, grep only
arch/x86/kvm/mmu/page_track.c +10 -6
index 7e8195a311bb..860049ed24ea 100644
@@ -237,10 +237,11 @@ static int kvm_enable_external_write_tracking(struct kvm *kvm)
  * register the notifier so that event interception for the tracked guest
  * pages can be received.
  */
-int kvm_page_track_register_notifier(struct kvm *kvm,
+int kvm_page_track_register_notifier(struct file *file,
 				     struct kvm_page_track_notifier_node *n)
 {
 	struct kvm_page_track_notifier_head *head;
+	struct kvm *kvm = file_to_kvm(file);
 	int r;
 
 	if (!kvm || kvm->mm != current->mm)
@@ -252,7 +253,7 @@ int kvm_page_track_register_notifier(struct kvm *kvm,
 			return r;
 	}
 
-	kvm_get_kvm(kvm);
+	get_file(file);
 
 	head = &kvm->arch.track_notifier_head;
 
@@ -267,10 +268,11 @@ EXPORT_SYMBOL_GPL(kvm_page_track_register_notifier);
  * stop receiving the event interception. It is the opposed operation of
  * kvm_page_track_register_notifier().
  */
-void kvm_page_track_unregister_notifier(struct kvm *kvm,
+void kvm_page_track_unregister_notifier(struct file *file,
 					struct kvm_page_track_notifier_node *n)
 {
 	struct kvm_page_track_notifier_head *head;
+	struct kvm *kvm = file_to_kvm(file);
 
 	head = &kvm->arch.track_notifier_head;
 
@@ -279,7 +281,7 @@ void kvm_page_track_unregister_notifier(struct kvm *kvm,
 	write_unlock(&kvm->mmu_lock);
 	synchronize_srcu(&head->track_srcu);
 
-	kvm_put_kvm(kvm);
+	fput(file);
 }
 EXPORT_SYMBOL_GPL(kvm_page_track_unregister_notifier);
 
@@ -339,8 +341,9 @@ void kvm_page_track_delete_slot(struct kvm *kvm, struct kvm_memory_slot *slot)
  * @kvm: the guest instance we are interested in.
  * @gfn: the guest page.
  */
-int kvm_write_track_add_gfn(struct kvm *kvm, gfn_t gfn)
+int kvm_write_track_add_gfn(struct file *file, gfn_t gfn)
 {
+	struct kvm *kvm = file_to_kvm(file);
 	struct kvm_memory_slot *slot;
 	int idx;
 
@@ -369,8 +372,9 @@ EXPORT_SYMBOL_GPL(kvm_write_track_add_gfn);
  * @kvm: the guest instance we are interested in.
  * @gfn: the guest page.
  */
-int kvm_write_track_remove_gfn(struct kvm *kvm, gfn_t gfn)
+int kvm_write_track_remove_gfn(struct file *file, gfn_t gfn)
 {
+	struct kvm *kvm = file_to_kvm(file);
 	struct kvm_memory_slot *slot;
 	int idx;
 
drivers/s390/crypto/vfio_ap_ops.c +23 -7
index 99a0efd999ef..875e67063d8e 100644
@@ -8,6 +8,7 @@
  *	      Halil Pasic <[email protected]>
  *	      Pierre Morel <[email protected]>
  */
+#include "linux/cleanup.h"
 #include <linux/string.h>
 #include <linux/vfio.h>
 #include <linux/device.h>
@@ -1822,12 +1823,25 @@ static const struct attribute_group *vfio_ap_mdev_attr_groups[] = {
  * @matrix_mdev: a mediated matrix device
  * @kvm: reference to KVM instance
  *
- * Return: 0 if no other mediated matrix device has a reference to @kvm;
- * otherwise, returns an -EPERM.
+ * Returns: 0 if the reference to kvm is successfully retrieved from @kvm_file
+ * and set into @matrix_mdev; otherwise, returns:
+ *	-ENOENT if a reference to kvm could not be retrieved from @kvm_file
+ *	-EPERM if another mediated matrix device already has a reference to the same kvm instance
  */
 static int vfio_ap_mdev_set_kvm(struct ap_matrix_mdev *matrix_mdev,
-				struct kvm *kvm)
+				struct file **kvm_file)
 {
+	struct file *kvm_file_ref __free(fput) = NULL;
+	struct kvm *kvm;
+
+	kvm_file_ref = get_file_active(kvm_file);
+	if (!kvm_file_ref)
+		return -ENOENT;
+
+	kvm = kvm_file_ref->private_data;
+	if (!kvm)
+		return -ENOENT;
+
 	if (kvm->arch.crypto.crycbd) {
 		get_update_locks_for_kvm(kvm);
 		if (kvm->arch.crypto.pqap_hook) {
@@ -1836,10 +1850,11 @@ static int vfio_ap_mdev_set_kvm(struct ap_matrix_mdev *matrix_mdev,
 		}
 		kvm->arch.crypto.pqap_hook = &matrix_mdev->pqap_hook;
 
-		kvm_get_kvm(kvm);
 		matrix_mdev->kvm = kvm;
 		vfio_ap_mdev_update_guest_apcb(matrix_mdev);
 		release_update_locks_for_kvm(kvm);
+
+		matrix_mdev->kvm_file = no_free_ptr(kvm_file_ref);
 	}
 
 	return 0;
@@ -1878,9 +1893,10 @@ static void vfio_ap_mdev_dma_unmap(struct vfio_device *vdev, u64 iova,
  */
 static void vfio_ap_mdev_unset_kvm(struct ap_matrix_mdev *matrix_mdev)
 {
+	struct file *kvm_file = matrix_mdev->kvm_file;
 	struct kvm *kvm = matrix_mdev->kvm;
 
-	if (kvm && kvm->arch.crypto.crycbd) {
+	if (kvm_file && kvm && kvm->arch.crypto.crycbd) {
 		get_update_locks_for_kvm(kvm);
 		kvm->arch.crypto.pqap_hook = NULL;
 
@@ -1889,7 +1905,7 @@ static void vfio_ap_mdev_unset_kvm(struct ap_matrix_mdev *matrix_mdev)
 		matrix_mdev->kvm = NULL;
 
 		release_update_locks_for_kvm(kvm);
-		kvm_put_kvm(kvm);
+		fput(kvm_file);
 	}
 }
 
@@ -2053,7 +2069,7 @@ static int vfio_ap_mdev_open_device(struct vfio_device *vdev)
 	if (!vdev->kvm)
 		return -EINVAL;
 
-	return vfio_ap_mdev_set_kvm(matrix_mdev, vdev->kvm);
+	return vfio_ap_mdev_set_kvm(matrix_mdev, &vdev->kvm);
 }
 
 static void vfio_ap_mdev_close_device(struct vfio_device *vdev)
drivers/s390/crypto/vfio_ap_private.h +1 -0
index 9bff666b0b35..4ec91c6827eb 100644
@@ -117,6 +117,7 @@ struct ap_matrix_mdev {
 	struct ap_matrix matrix;
 	struct ap_matrix shadow_apcb;
 	struct kvm *kvm;
+	struct file *kvm_file;
 	crypto_hook pqap_hook;
 	struct mdev_device *mdev;
 	struct ap_queue_table qtable;
drivers/vfio/device_cdev.c +1 -1
index 1d9515c967b0..e32176a55c46 100644
@@ -65,7 +65,7 @@ int vfio_device_fops_cdev_open(struct inode *inode, struct file *filep)
 static void vfio_df_get_kvm_safe(struct vfio_device_file *df)
 {
 	spin_lock(&df->kvm_ref_lock);
-	vfio_device_get_kvm_safe(df->device, df->kvm);
+	vfio_device_get_kvm_safe(df->device, &df->kvm);
 	spin_unlock(&df->kvm_ref_lock);
 }
 
drivers/vfio/group.c +2 -2
index b2299e5bc6df..197298ca0003 100644
@@ -163,7 +163,7 @@ static int vfio_group_ioctl_set_container(struct vfio_group *group,
 static void vfio_device_group_get_kvm_safe(struct vfio_device *device)
 {
 	spin_lock(&device->group->kvm_ref_lock);
-	vfio_device_get_kvm_safe(device, device->group->kvm);
+	vfio_device_get_kvm_safe(device, &device->group->kvm);
 	spin_unlock(&device->group->kvm_ref_lock);
 }
 
@@ -860,7 +860,7 @@ bool vfio_group_enforced_coherent(struct vfio_group *group)
 	return ret;
 }
 
-void vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm)
+void vfio_group_set_kvm(struct vfio_group *group, struct file *kvm)
 {
 	spin_lock(&group->kvm_ref_lock);
 	group->kvm = kvm;
drivers/vfio/pci/vfio_pci_zdev.c +6 -1
index 0990fdb146b7..d3a110101353 100644
@@ -144,6 +144,7 @@ int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,
 int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev)
 {
 	struct zpci_dev *zdev = to_zpci(vdev->pdev);
+	struct kvm *kvm;
 
 	if (!zdev)
 		return -ENODEV;
@@ -151,8 +152,12 @@ int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev)
 	if (!vdev->vdev.kvm)
 		return 0;
 
+	kvm = vdev->vdev.kvm->private_data;
+	if (!kvm)
+		return -ENOENT;
+
 	if (zpci_kvm_hook.kvm_register)
-		return zpci_kvm_hook.kvm_register(zdev, vdev->vdev.kvm);
+		return zpci_kvm_hook.kvm_register(zdev, kvm);
 
 	return -ENOENT;
 }
drivers/vfio/vfio.h +5 -5
index 7728bc99b63d..7935c51ea1ac 100644
@@ -23,7 +23,7 @@ struct vfio_device_file {
 	u8 access_granted;
 	u32 devid; /* only valid when iommufd is valid */
 	spinlock_t kvm_ref_lock; /* protect kvm field */
-	struct kvm *kvm;
+	struct file *kvm;
 	struct iommufd_ctx *iommufd; /* protected by struct vfio_device_set::lock */
 };
 
@@ -88,7 +88,7 @@ struct vfio_group {
 #endif
 	enum vfio_group_type		type;
 	struct mutex			group_lock;
-	struct kvm			*kvm;
+	struct file			*kvm;
 	struct file			*opened_file;
 	struct iommufd_ctx		*iommufd;
 	spinlock_t			kvm_ref_lock;
@@ -107,7 +107,7 @@ void vfio_device_group_unuse_iommu(struct vfio_device *device);
 void vfio_df_group_close(struct vfio_device_file *df);
 struct vfio_group *vfio_group_from_file(struct file *file);
 bool vfio_group_enforced_coherent(struct vfio_group *group);
-void vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm);
+void vfio_group_set_kvm(struct vfio_group *group, struct file *kvm);
 bool vfio_device_has_container(struct vfio_device *device);
 int __init vfio_group_init(void);
 void vfio_group_cleanup(void);
@@ -429,11 +429,11 @@ static inline void vfio_virqfd_exit(void)
 #endif
 
 #if IS_ENABLED(CONFIG_KVM)
-void vfio_device_get_kvm_safe(struct vfio_device *device, struct kvm *kvm);
+void vfio_device_get_kvm_safe(struct vfio_device *device, struct file **kvm);
 void vfio_device_put_kvm(struct vfio_device *device);
 #else
 static inline void vfio_device_get_kvm_safe(struct vfio_device *device,
-					    struct kvm *kvm)
+					    struct file **kvm)
 {
 }
 
drivers/vfio/vfio_main.c +13 -39

92 lines not on this page · raw message

include/linux/kvm_host.h +7 -0
index 03bfc92864b6..1c5bf2801bf1 100644
@@ -784,6 +784,12 @@ struct kvm {
 	 * kvm_swap_active_memslots().
 	 */
 	struct mutex slots_arch_lock;
+	/*
+	 * Back-reference to VM file descriptor without extra refcount held.
+	 * Use get_file_active() to safely access the file without circular references.
+	 * RCU-protected to ensure safe access even during file release.
+	 */
+	struct file __rcu *file;
 	struct mm_struct *mm; /* userspace tied to this vm */
 	unsigned long nr_memslot_pages;
 	/* The two memslot sets - active and inactive (per address space) */
@@ -1082,6 +1088,7 @@ void kvm_get_kvm(struct kvm *kvm);
 bool kvm_get_kvm_safe(struct kvm *kvm);
 void kvm_put_kvm(struct kvm *kvm);
 bool file_is_kvm(struct file *file);
+struct kvm *file_to_kvm(struct file *file);
 void kvm_put_kvm_no_destroy(struct kvm *kvm);
 
 static inline struct kvm_memslots *__kvm_memslots(struct kvm *kvm, int as_id)
include/linux/vfio.h +2 -3
index 45f08986359e..0cc91c6f96d2 100644
@@ -54,7 +54,7 @@ struct vfio_device {
 	struct list_head dev_set_list;
 	unsigned int migration_flags;
 	u8 precopy_info_v2;
-	struct kvm *kvm;
+	struct file *kvm;
 
 	/* Members below here are private, not for driver use */
 	unsigned int index;
@@ -66,7 +66,6 @@ struct vfio_device {
 	unsigned int open_count;
 	struct completion comp;
 	struct iommufd_access *iommufd_access;
-	void (*put_kvm)(struct kvm *kvm);
 	struct inode *inode;
 #if IS_ENABLED(CONFIG_IOMMUFD)
 	struct iommufd_device *iommufd_device;
@@ -378,7 +377,7 @@ static inline bool vfio_file_has_dev(struct file *file, struct vfio_device *devi
 #endif
 bool vfio_file_is_valid(struct file *file);
 bool vfio_file_enforced_coherent(struct file *file);
-void vfio_file_set_kvm(struct file *file, struct kvm *kvm);
+void vfio_file_set_kvm(struct file *vfio_file, struct file *kvm);
 
 #define VFIO_PIN_PAGES_MAX_ENTRIES	(PAGE_SIZE/sizeof(unsigned long))
 
virt/kvm/kvm_main.c +19 -3
index 65eb26a0520d..0d80730e8424 100644
@@ -1314,7 +1314,7 @@ void kvm_get_kvm(struct kvm *kvm)
 {
 	refcount_inc(&kvm->users_count);
 }
-EXPORT_SYMBOL_GPL(kvm_get_kvm);
+EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_get_kvm);
 
 /*
  * Make sure the vm is not during destruction, which is a safe version of
@@ -1324,14 +1324,14 @@ bool kvm_get_kvm_safe(struct kvm *kvm)
 {
 	return refcount_inc_not_zero(&kvm->users_count);
 }
-EXPORT_SYMBOL_GPL(kvm_get_kvm_safe);
+EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_get_kvm_safe);
 
 void kvm_put_kvm(struct kvm *kvm)
 {
 	if (refcount_dec_and_test(&kvm->users_count))
 		kvm_destroy_vm(kvm);
 }
-EXPORT_SYMBOL_GPL(kvm_put_kvm);
+EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_put_kvm);
 
 /*
  * Used to put a reference that was taken on behalf of an object associated
@@ -1352,6 +1352,9 @@ static int kvm_vm_release(struct inode *inode, struct file *filp)
 
 	kvm_irqfd_release(kvm);
 
+	rcu_assign_pointer(kvm->file, NULL);
+	synchronize_rcu();
+
 	kvm_put_kvm(kvm);
 	return 0;
 }
@@ -5496,6 +5499,15 @@ bool file_is_kvm(struct file *file)
 }
 EXPORT_SYMBOL_FOR_KVM_INTERNAL(file_is_kvm);
 
+struct kvm *file_to_kvm(struct file *file)
+{
+	if (!file_is_kvm(file))
+		return NULL;
+
+	return file->private_data;
+}
+EXPORT_SYMBOL_FOR_KVM_INTERNAL(file_to_kvm);
+
 static int kvm_dev_ioctl_create_vm(unsigned long type)
 {
 	char fdname[ITOA_MAX_LEN + 1];
@@ -5527,6 +5539,10 @@ static int kvm_dev_ioctl_create_vm(unsigned long type)
 	 * cases it will be called by the final fput(file) and will take
 	 * care of doing kvm_put_kvm(kvm).
 	 */
+
+	/* Store back-reference for VFIO and other subsystems */
+	rcu_assign_pointer(kvm->file, file);
+
 	kvm_uevent_notify_change(KVM_EVENT_CREATE_VM, kvm);
 
 	fd_install(fd, file);
virt/kvm/vfio.c +4 -4
index 6cdc4e9a333a..0166cc4d39b3 100644
@@ -35,15 +35,15 @@ struct kvm_vfio {
 	bool noncoherent;
 };
 
-static void kvm_vfio_file_set_kvm(struct file *file, struct kvm *kvm)
+static void kvm_vfio_file_set_kvm(struct file *vfio_file, struct file *kvm)
 {
-	void (*fn)(struct file *file, struct kvm *kvm);
+	void (*fn)(struct file *vfio_file, struct file *kvm);
 
 	fn = symbol_get(vfio_file_set_kvm);
 	if (!fn)
 		return;
 
-	fn(file, kvm);
+	fn(vfio_file, kvm);
 
 	symbol_put(vfio_file_set_kvm);
 }
@@ -168,7 +168,7 @@ static int kvm_vfio_file_add(struct kvm_device *dev, unsigned int fd)
 	kvf->file = get_file(filp);
 	list_add_tail(&kvf->node, &kv->file_list);
 
-	kvm_vfio_file_set_kvm(kvf->file, dev->kvm);
+	kvm_vfio_file_set_kvm(kvf->file, dev->kvm->file);
 	kvm_vfio_update_coherency(dev);
 
 	return 0;
Signature · 1 line
2.53.0
author reviewer
#10 lore raw

PATCH v6 5/33 arm64: ptrace: Use constants for compat register numbers

In reply to Steffen Eiden

Define an enum to determine the register number for the mapping from AArch32 and AArch64 registers. This allows for a more flexible use of the register mappings.

---
 arch/arm64/include/asm/ptrace.h | 60 ++++++++++++++++++++++-----------
 1 file changed, 41 insertions(+), 19 deletions(-)
arch/arm64/include/asm/ptrace.h +41 -19
index f7dc5fb9427d..49a83a0636b9 100644
@@ -102,26 +102,48 @@
 #define COMPAT_USER_SZ	296
 
 /* Architecturally defined mapping between AArch32 and AArch64 registers */
+enum {
+	__compat_fp		= 11,
+	__compat_sp		= 13,
+	__compat_lr		= 14,
+	__compat_sp_hyp		= 15,
+	__compat_lr_irq		= 16,
+	__compat_sp_irq		= 17,
+	__compat_lr_svc		= 18,
+	__compat_sp_svc		= 19,
+	__compat_lr_abt		= 20,
+	__compat_sp_abt		= 21,
+	__compat_lr_und		= 22,
+	__compat_sp_und		= 23,
+	__compat_r8_fiq		= 24,
+	__compat_r9_fiq		= 25,
+	__compat_r10_fiq	= 26,
+	__compat_r11_fiq	= 27,
+	__compat_r12_fiq	= 28,
+	__compat_sp_fiq		= 29,
+	__compat_lr_fiq		= 30,
+};
+
 #define compat_usr(x)	regs[(x)]
-#define compat_fp	regs[11]
-#define compat_sp	regs[13]
-#define compat_lr	regs[14]
-#define compat_sp_hyp	regs[15]
-#define compat_lr_irq	regs[16]
-#define compat_sp_irq	regs[17]
-#define compat_lr_svc	regs[18]
-#define compat_sp_svc	regs[19]
-#define compat_lr_abt	regs[20]
-#define compat_sp_abt	regs[21]
-#define compat_lr_und	regs[22]
-#define compat_sp_und	regs[23]
-#define compat_r8_fiq	regs[24]
-#define compat_r9_fiq	regs[25]
-#define compat_r10_fiq	regs[26]
-#define compat_r11_fiq	regs[27]
-#define compat_r12_fiq	regs[28]
-#define compat_sp_fiq	regs[29]
-#define compat_lr_fiq	regs[30]
+#define compat_fp	regs[__compat_fp]
+#define compat_sp	regs[__compat_sp]
+#define compat_lr	regs[__compat_lr]
+#define compat_sp_hyp	regs[__compat_sp_hyp]
+#define compat_lr_irq	regs[__compat_lr_irq]
+#define compat_sp_irq	regs[__compat_sp_irq]
+#define compat_lr_svc	regs[__compat_lr_svc]
+#define compat_sp_svc	regs[__compat_sp_svc]
+#define compat_lr_abt	regs[__compat_lr_abt]
+#define compat_sp_abt	regs[__compat_sp_abt]
+#define compat_lr_und	regs[__compat_lr_und]
+#define compat_sp_und	regs[__compat_sp_und]
+#define compat_r8_fiq	regs[__compat_r8_fiq]
+#define compat_r9_fiq	regs[__compat_r9_fiq]
+#define compat_r10_fiq	regs[__compat_r10_fiq]
+#define compat_r11_fiq	regs[__compat_r11_fiq]
+#define compat_r12_fiq	regs[__compat_r12_fiq]
+#define compat_sp_fiq	regs[__compat_sp_fiq]
+#define compat_lr_fiq	regs[__compat_lr_fiq]
 
 static inline unsigned long compat_psr_to_pstate(const unsigned long psr)
 {
Signature · 1 line
2.53.0
author reviewer
#56 lore raw

PATCH v6 18/33 KVM: s390: Prepare gmap for a second KVM implementation

In reply to Steffen Eiden

Refactor gmap code such that a second s390 (host) KVM implementation can use the gmap code as well. Move mmu code from s390 to gmap so the other KVM implementation can use it as well.

No functional change.

---
 arch/s390/kvm/gmap/Makefile  |   2 +-
 arch/s390/kvm/gmap/kvm_mmu.c | 133 +++++++++++++++++++++++++++++++++++
 arch/s390/kvm/gmap/kvm_mmu.h |  18 +++++
 arch/s390/kvm/s390/s390.c    | 126 ++++-----------------------------
 arch/s390/kvm/s390/s390.h    |   8 +++
 5 files changed, 175 insertions(+), 112 deletions(-)
 create mode 100644 arch/s390/kvm/gmap/kvm_mmu.c
 create mode 100644 arch/s390/kvm/gmap/kvm_mmu.h
arch/s390/kvm/gmap/Makefile +1 -1
index 3a4f8df11622..dd4ef062c536 100644
@@ -2,4 +2,4 @@
 
 GMAP ?= ../gmap
 
-gmap-y += $(GMAP)/dat.o $(GMAP)/gmap.o $(GMAP)/faultin.o
+gmap-y += $(GMAP)/dat.o $(GMAP)/gmap.o $(GMAP)/faultin.o $(GMAP)/kvm_mmu.o
arch/s390/kvm/gmap/kvm_mmu.c new file +133 -0

133 lines not on this page · raw message

arch/s390/kvm/gmap/kvm_mmu.h new file +18 -0
new file mode 100644
index 000000000000..cdbd390bd33c
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef ARCH_KVM_GMAP_KVM_MMU_H
+#define ARCH_KVM_GMAP_KVM_MMU_H
+
+#include <linux/kvm_host.h>
+
+int s390_kvm_mmu_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log);
+int s390_kvm_mmu_prepare_memory_region(struct kvm *kvm,
+				       const struct kvm_memory_slot *old,
+				       struct kvm_memory_slot *new,
+				       enum kvm_mr_change change);
+void s390_kvm_mmu_commit_memory_region(struct kvm *kvm,
+				       struct kvm_memory_slot *old,
+				       const struct kvm_memory_slot *new,
+				       enum kvm_mr_change change);
+
+#endif /* ARCH_KVM_GMAP_KVM_MMU_H */
arch/s390/kvm/s390/s390.c +15 -111

161 lines not on this page · raw message

arch/s390/kvm/s390/s390.h +8 -0
index e144ca2e6d5e..d284a263ba70 100644
@@ -472,6 +472,9 @@ int __kvm_s390_mprotect_many(struct gmap *gmap, gpa_t gpa, u8 npages, unsigned i
 			     unsigned long bits);
 
 bool kvm_arch_setup_async_pf(struct kvm_vcpu *vcpu);
+void kvm_s390_update_cmma_dirty(struct kvm *kvm, struct kvm_memory_slot *old);
+int kvm_s390_vm_stop_migration(struct kvm *kvm);
+
 
 /* implemented in diag.c */
 int kvm_s390_handle_diag(struct kvm_vcpu *vcpu);
@@ -594,6 +597,11 @@ static inline bool kvm_s390_cur_gmap_fault_is_write(void)
 	return test_facility(75) && (current->thread.gmap_teid.fsi == TEID_FSI_STORE);
 }
 
+static __always_inline int kvm_s390_is_migration_mode(struct kvm *kvm)
+{
+	return kvm->arch.migration_mode;
+}
+
 /**
  * kvm_s390_vcpu_crypto_reset_all
  *
Signature · 1 line
2.53.0
author reviewer
#31 lore raw

PATCH v6 10/33 arm64: Share arm64 headers with s390

In reply to Steffen Eiden

Allow sharing of arm64 headers with s390 by marking the shared regions or add a comment that the whole file is shared.

The shared regions are marked with:

#ifdef ARM64_S390_COMMON

/* insert shared definitions here */

#endif /* ARM64_S390_COMMON */

The preprocessor symbol ARM64_S390_COMMON is always defined for arm64. s390 later will generate its own view of arm64 headers based on the content inside the ifdef/endif block.

No functional change.

---
 arch/arm64/Makefile                  |  2 ++
 arch/arm64/include/asm/brk-imm.h     |  1 +
 arch/arm64/include/asm/esr.h         |  1 +
 arch/arm64/include/asm/kvm_arm.h     |  1 +
 arch/arm64/include/asm/kvm_emulate.h | 18 ++++++++++++++++++
 arch/arm64/include/asm/kvm_host.h    | 20 ++++++++++++++++++++
 arch/arm64/include/asm/ptrace.h      |  4 ++++
 arch/arm64/include/asm/sysreg.h      | 15 +++++++++++++++
 8 files changed, 62 insertions(+)
arch/arm64/Makefile +2 -0
index 6b005c8fef70..1cd7cd94a855 100644
@@ -43,7 +43,9 @@ CC_FLAGS_NO_FPU	:= -mgeneral-regs-only
 KBUILD_CFLAGS	+= $(CC_FLAGS_NO_FPU) \
 		   $(compat_vdso) $(cc_has_k_constraint)
 KBUILD_CFLAGS	+= $(call cc-disable-warning, psabi)
+KBUILD_CFLAGS	+= -DARM64_S390_COMMON
 KBUILD_AFLAGS	+= $(compat_vdso)
+KBUILD_AFLAGS	+= -DARM64_S390_COMMON
 
 ifeq ($(call rustc-min-version, 108500),y)
 KBUILD_RUSTFLAGS += --target=aarch64-unknown-none-softfloat
arch/arm64/include/asm/brk-imm.h +1 -0
index beb42c62b6ac..dd2d153dc0d8 100644
@@ -2,6 +2,7 @@
 /*
  * Copyright (C) 2012 ARM Ltd.
  */
+/* Whole file is shared with s390 */
 
 #ifndef __ASM_BRK_IMM_H
 #define __ASM_BRK_IMM_H
arch/arm64/include/asm/esr.h +1 -0
index da085c83b57e..2cb73bde7346 100644
@@ -3,6 +3,7 @@
  * Copyright (C) 2013 - ARM Ltd
  * Author: Marc Zyngier <[email protected]>
  */
+/* Whole file is shared with s390 */
 
 #ifndef __ASM_ESR_H
 #define __ASM_ESR_H
arch/arm64/include/asm/kvm_arm.h +1 -0
index 57edd8437200..678f0daed445 100644
@@ -3,6 +3,7 @@
  * Copyright (C) 2012,2013 - ARM Ltd
  * Author: Marc Zyngier <[email protected]>
  */
+/* Whole file is shared with s390 */
 
 #ifndef __ARM64_KVM_ARM_H__
 #define __ARM64_KVM_ARM_H__
arch/arm64/include/asm/kvm_emulate.h +18 -0
index a34a9417ff4d..09f04a5686a1 100644
@@ -47,6 +47,7 @@ void kvm_skip_instr32(struct kvm_vcpu *vcpu);
 int kvm_inject_dabt_excl_atomic(struct kvm_vcpu *vcpu, u64 addr);
 int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr);
 
+#ifdef ARM64_S390_COMMON
 void kvm_inject_undefined(struct kvm_vcpu *vcpu);
 void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr);
 int kvm_inject_sea(struct kvm_vcpu *vcpu, bool iabt, u64 addr);
@@ -62,6 +63,8 @@ static inline int kvm_inject_sea_iabt(struct kvm_vcpu *vcpu, u64 addr)
 	return kvm_inject_sea(vcpu, true, addr);
 }
 
+#endif /* ARM64_S390_COMMON */
+
 static inline int kvm_inject_serror(struct kvm_vcpu *vcpu)
 {
 	/*
@@ -185,6 +188,7 @@ static inline void vcpu_set_thumb(struct kvm_vcpu *vcpu)
 	*vcpu_cpsr(vcpu) |= PSR_AA32_T_BIT;
 }
 
+#ifdef ARM64_S390_COMMON
 /*
  * vcpu_get_reg and vcpu_set_reg should always be passed a register number
  * coming from a read of ESR_EL2. Otherwise, it may give the wrong result on
@@ -203,6 +207,8 @@ static __always_inline void vcpu_set_reg(struct kvm_vcpu *vcpu, u8 reg_num,
 		vcpu_gp_regs(vcpu)[reg_num] = val;
 }
 
+#endif /* ARM64_S390_COMMON */
+
 static inline bool vcpu_is_el2_ctxt(const struct kvm_cpu_context *ctxt)
 {
 	switch (ctxt->regs.pstate & (PSR_MODE32_BIT | PSR_MODE_MASK)) {
@@ -405,6 +411,7 @@ static inline u64 kvm_vcpu_get_disr(const struct kvm_vcpu *vcpu)
 	return vcpu->arch.fault.disr_el1;
 }
 
+#ifdef ARM64_S390_COMMON
 static inline u32 kvm_vcpu_hvc_get_imm(const struct kvm_vcpu *vcpu)
 {
 	return kvm_vcpu_get_esr(vcpu) & ESR_ELx_xVC_IMM_MASK;
@@ -482,6 +489,8 @@ static __always_inline u8 kvm_vcpu_trap_get_fault(const struct kvm_vcpu *vcpu)
 	return kvm_vcpu_get_esr(vcpu) & ESR_ELx_FSC;
 }
 
+#endif /* ARM64_S390_COMMON */
+
 static inline
 bool kvm_vcpu_trap_is_permission_fault(const struct kvm_vcpu *vcpu)
 {
@@ -522,6 +531,7 @@ static __always_inline int kvm_vcpu_sys_get_rt(struct kvm_vcpu *vcpu)
 	return ESR_ELx_SYS64_ISS_RT(esr);
 }
 
+#ifdef ARM64_S390_COMMON
 static inline bool kvm_is_write_fault(struct kvm_vcpu *vcpu)
 {
 	if (kvm_vcpu_abt_iss1tw(vcpu)) {
@@ -546,6 +556,8 @@ static inline bool kvm_is_write_fault(struct kvm_vcpu *vcpu)
 	return kvm_vcpu_dabt_iswrite(vcpu);
 }
 
+#endif /* ARM64_S390_COMMON */
+
 static inline unsigned long kvm_vcpu_get_mpidr_aff(struct kvm_vcpu *vcpu)
 {
 	return __vcpu_sys_reg(vcpu, MPIDR_EL1) & MPIDR_HWID_BITMASK;
@@ -587,6 +599,7 @@ static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu)
 	return vcpu_read_sys_reg(vcpu, r) & bit;
 }
 
+#ifdef ARM64_S390_COMMON
 static inline unsigned long vcpu_data_guest_to_host(struct kvm_vcpu *vcpu,
 						    unsigned long data,
 						    unsigned int len)
@@ -662,6 +675,8 @@ static __always_inline void kvm_incr_pc(struct kvm_vcpu *vcpu)
 		vcpu_set_flag((v), e);					\
 	} while (0)
 
+#endif /* ARM64_S390_COMMON */
+
 /*
  * Returns a 'sanitised' view of CPTR_EL2, translating from nVHE to the VHE
  * format if E2H isn't set.
@@ -768,6 +783,7 @@ static inline void kvm_reset_fpsimd(struct kvm_vcpu *vcpu)
 	memset(&vcpu->arch.ctxt.fp_regs, 0, sizeof(vcpu->arch.ctxt.fp_regs));
 }
 
+#ifdef ARM64_S390_COMMON
 /* Reset a vcpu's core registers. */
 static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu)
 {
@@ -792,6 +808,8 @@ static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu)
 	*vcpu_cpsr(vcpu) = pstate;
 }
 
+#endif /* ARM64_S390_COMMON */
+
 /* PSCI reset handling for a vcpu. */
 static inline void kvm_reset_vcpu_psci(struct kvm_vcpu *vcpu,
 				       struct vcpu_reset_state *reset_state)
arch/arm64/include/asm/kvm_host.h +20 -0
index 22770c1132cb..e6b3d42abb08 100644
@@ -39,6 +39,7 @@
 
 #define KVM_MAX_VCPUS VGIC_V3_MAX_CPUS
 
+#ifdef ARM64_S390_COMMON
 #define KVM_VCPU_MAX_FEATURES 10
 #define KVM_VCPU_VALID_FEATURES	(BIT(KVM_VCPU_MAX_FEATURES) - 1)
 
@@ -86,6 +87,8 @@
 /* Unhandled SEAs are taken to userspace */
 #define KVM_ARCH_FLAG_EXIT_SEA				11
 
+#endif /* ARM64_S390_COMMON */
+
 #define KVM_DIRTY_LOG_MANUAL_CAPS   (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \
 				     KVM_DIRTY_LOG_INITIALLY_SET)
 
@@ -836,6 +839,8 @@ extern s64 kvm_nvhe_sym(hyp_physvirt_offset);
 extern u64 kvm_nvhe_sym(hyp_cpu_logical_map)[NR_CPUS];
 #define hyp_cpu_logical_map CHOOSE_NVHE_SYM(hyp_cpu_logical_map)
 
+#ifdef ARM64_S390_COMMON
+
 struct vcpu_reset_state {
 	unsigned long	pc;
 	unsigned long	r0;
@@ -843,6 +848,8 @@ struct vcpu_reset_state {
 	bool		reset;
 };
 
+#endif /* ARM64_S390_COMMON */
+
 struct vncr_tlb;
 
 struct kvm_vcpu_arch {
@@ -952,6 +959,7 @@ struct kvm_vcpu_arch {
 	pid_t pid;
 };
 
+#ifdef ARM64_S390_COMMON
 /*
  * Each 'flag' is composed of a comma-separated triplet:
  *
@@ -1105,6 +1113,8 @@ struct kvm_vcpu_arch {
 /* KVM is currently emulating an L2 to L1 exception */
 #define IN_NESTED_EXCEPTION	__vcpu_single_flag(sflags, BIT(9))
 
+#endif /* ARM64_S390_COMMON */
+
 #define vcpu_sve_max_vq(vcpu)	sve_vq_from_vl((vcpu)->arch.sve_max_vl)
 
 #define vcpu_sve_zcr_elx(vcpu)						\
@@ -1240,6 +1250,7 @@ struct kvm_vcpu_stat {
 	u64 exits;
 };
 
+#ifdef ARM64_S390_COMMON
 unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
 int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices);
 int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
@@ -1248,6 +1259,8 @@ int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
 unsigned long kvm_arm_num_sys_reg_descs(struct kvm_vcpu *vcpu);
 int kvm_arm_copy_sys_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices);
 
+#endif /* ARM64_S390_COMMON */
+
 int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
 			      struct kvm_vcpu_events *events);
 
@@ -1326,6 +1339,7 @@ int __init populate_nv_trap_config(void);
 
 void kvm_calculate_traps(struct kvm_vcpu *vcpu);
 
+#ifdef ARM64_S390_COMMON
 /* MMIO helpers */
 void kvm_mmio_write_buf(void *buf, unsigned int len, unsigned long data);
 unsigned long kvm_mmio_read_buf(const void *buf, unsigned int len);
@@ -1333,6 +1347,8 @@ unsigned long kvm_mmio_read_buf(const void *buf, unsigned int len);
 int kvm_handle_mmio_return(struct kvm_vcpu *vcpu);
 int io_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa);
 
+#endif /* ARM64_S390_COMMON */
+
 /*
  * Returns true if a Performance Monitoring Interrupt (PMI), a.k.a. perf event,
  * arrived in guest context.  For arm64, any event that arrives while a vCPU is
@@ -1530,11 +1546,15 @@ static inline bool __vcpu_has_feature(const struct kvm_arch *ka, int feature)
 	return test_bit(feature, ka->vcpu_features);
 }
 
+#ifdef ARM64_S390_COMMON
+
 #define kvm_vcpu_has_feature(k, f)	__vcpu_has_feature(&(k)->arch, (f))
 #define vcpu_has_feature(v, f)	__vcpu_has_feature(&(v)->kvm->arch, (f))
 
 #define kvm_vcpu_initialized(v) vcpu_get_flag(v, VCPU_INITIALIZED)
 
+#endif /* ARM64_S390_COMMON */
+
 int kvm_trng_call(struct kvm_vcpu *vcpu);
 #ifdef CONFIG_KVM
 extern phys_addr_t hyp_mem_base;
arch/arm64/include/asm/ptrace.h +4 -0
index 49a83a0636b9..05c1307fa62f 100644
@@ -26,6 +26,8 @@
 
 #define GIC_PRIO_PSR_I_SET	GICV3_PRIO_PSR_I_SET
 
+#ifdef ARM64_S390_COMMON
+
 /* Additional SPSR bits not exposed in the UABI */
 #define PSR_MODE_THREAD_BIT	(1 << 0)
 #define PSR_IL_BIT		(1 << 20)
@@ -66,6 +68,8 @@
 #define PSR_AA32_IT_MASK	0x0600fc00	/* If-Then execution state mask */
 #define PSR_AA32_GE_MASK	0x000f0000
 
+#endif /* ARM64_S390_COMMON */
+
 #ifdef CONFIG_CPU_BIG_ENDIAN
 #define PSR_AA32_ENDSTATE	PSR_AA32_E_BIT
 #else
arch/arm64/include/asm/sysreg.h +15 -0
index ab205f9db94a..1c5c4df260be 100644
@@ -16,6 +16,8 @@
 
 #include <asm/gpr-num.h>
 
+#ifdef ARM64_S390_COMMON
+
 /*
  * ARMv8 ARM reserves the following encoding for system registers:
  * (Ref: ARMv8 ARM, Section: "System instruction class encoding overview",
@@ -50,6 +52,8 @@
 #define sys_reg_CRm(id)	(((id) >> CRm_shift) & CRm_mask)
 #define sys_reg_Op2(id)	(((id) >> Op2_shift) & Op2_mask)
 
+#endif /* ARM64_S390_COMMON */
+
 #ifndef CONFIG_BROKEN_GAS_INST
 
 #ifdef __ASSEMBLER__
@@ -123,6 +127,8 @@
 #define GSB_SYS_BARRIER_INSN		__SYS_BARRIER_INSN(1, 0, 12, 0, 0, 31)
 #define GSB_ACK_BARRIER_INSN		__SYS_BARRIER_INSN(1, 0, 12, 0, 1, 31)
 
+#ifdef ARM64_S390_COMMON
+
 /* Data cache zero operations */
 #define SYS_DC_ISW			sys_insn(1, 0, 7, 6, 2)
 #define SYS_DC_IGSW			sys_insn(1, 0, 7, 6, 4)
@@ -832,6 +838,8 @@
 #define SCTLR_ELx_A	 (BIT(1))
 #define SCTLR_ELx_M	 (BIT(0))
 
+#endif /* ARM64_S390_COMMON */
+
 #ifdef CONFIG_CPU_BIG_ENDIAN
 #define ENDIAN_SET_EL2		SCTLR_ELx_EE
 #else
@@ -866,6 +874,7 @@
 	 SCTLR_EL1_LSMAOE | SCTLR_EL1_nTLSMD | SCTLR_EL1_EIS   | \
 	 SCTLR_EL1_TSCXT  | SCTLR_EL1_EOS)
 
+#ifdef ARM64_S390_COMMON
 /* MAIR_ELx memory attributes (used by Linux) */
 #define MAIR_ATTR_DEVICE_nGnRnE		UL(0x00)
 #define MAIR_ATTR_DEVICE_nGnRE		UL(0x04)
@@ -1102,6 +1111,8 @@
 #define GICV5_GICR_CDNMIA_TYPE_MASK	GENMASK_ULL(31, 29)
 #define GICV5_GICR_CDNMIA_ID_MASK	GENMASK_ULL(23, 0)
 
+#endif /* ARM64_S390_COMMON */
+
 #define gicr_insn(insn)			read_sysreg_s(GICV5_OP_GICR_##insn)
 #define gic_insn(v, insn)		write_sysreg_s(v, GICV5_OP_GIC_##insn)
 
@@ -1251,6 +1262,8 @@
 	par;								\
 })
 
+#ifdef ARM64_S390_COMMON
+
 #define SYS_FIELD_VALUE(reg, field, val)	reg##_##field##_##val
 
 #define SYS_FIELD_GET(reg, field, val)		\
@@ -1263,6 +1276,8 @@
 		 FIELD_PREP(reg##_##field##_MASK,	\
 			    SYS_FIELD_VALUE(reg, field, val))
 
+#endif /* ARM64_S390_COMMON */
+
 #endif /* __ASSEMBLER__ */
 
 #endif	/* __ASM_SYSREG_H */
Signature · 1 line
2.53.0

Steffen Eiden

author reviewer
#0 lore raw

v6 cover KVM: s390: Introduce arm64 KVM

Introduce arm-on-s390. Enable KVM-accelerated ARM CPU virtualisation on s390.

For the original, now partially outdated, cover letter, have a look at versions one to three [1].

To share arm64 code with arm-on-s390 KVM, s390 extracts relevant parts of arm64 definitions and implementation and uses them locally. This results in minimal changes to existing arm64 code and headers.

To enable s390 to selectively extract relevant definitions while skipping architecture-specific code (e.g., arm64 assembly), a shared marker is introduced. The ARM64_S390_COMMON macro marks regions of arm64 code that are shared with s390:

in arch/arm64/kvm/<code>.c

  <arm64 local code>
  #ifdef ARM64_S390_COMMON
  <shared code>
  #endif /* ARM64_S390_COMMON */
  <arm64 local code>

ARM64_S390_COMMON is defined for all arm64 compilation units.

During the s390 build, an allow-list of arm64 headers is extracted into arch/s390/include/generated/arm64/. If a header contains at least one shared region, only those regions are copied along with the include guard. If no shared region is found, s390 uses the full header, which is copied in its entirety. In such cases, a comment is added at the top of the header to notify arm64 developers that the file is shared with s390 and changes may impact s390.

For C files, the process is similar. Selected KVM/arm64 C files are partially extracted into arch/s390/kvm/arm64/generated/code.inc. The s390 arm64 KVM implementation includes these snippets to reuse arm64 code without changing linkage.

Userspace tools requiring KVM/arm64 uapi on s390 must use a vendored KVM API, as s390 will not ship nor install arm64 KVM uapi headers.

This approach reduces the churn, especially for arm64 while keeping the maintenance burden low.

Series structure

A) KVM symbol cleanup and refactoring (patches 1-3):
Prepare KVM to support two KVM modules in parallel. Clean up KVM module symbol exports, making it possible to load two KVM modules side by side. Make the KVM device name configurable and allow KVM implementations to disable MMIO regardless of CONFIG_KVM_MMIO.

B) Arm64 header and code sharing preparation (patches 4-11): Mark shareable parts with ARM64_S390_COMMON. But first perform minor refactoring to ease integration into s390. All the refactoring/cleanup/fix patches could be picked before the actual share-marker commits (10/11)

C) KVM/s390 reorganization (patches 12-22):
Prepare s390 for a second KVM module. Move existing s390 KVM code into dedicated s390 and gmap subdirectories to make room for a second KVM implementation. Refactor gmap to better integrate with the second KVM implementation. GMAP hides a few features only required when managing s390
guests: Storage keys, CMMA, and prefix handling. Those are guarded behind an #if KVM_S390_MANAGES_S390_GUEST. Only features which implementation would break kvm-arm64 code are guarded. I leave the non-breaking stuff (like shadow-gmaps or ucontrol) for the LTO.

D) Code sharing infrastructure for s390 (patches 23 & 24):
Add Makefile and scripts to extract and build arm64 headers and code for use by s390.

E) KVM on s390 (patches 25-33):
Introduce the SAE (Start Arm Execution) instruction as the s390 mechanism for running arm64 guests. Build up the new kvm-arm64 module incrementally.

A, B, C and D could be picked individually without requiring the others so they could go through different trees if required. E obviously requires A-D.

Based on next-20260811.

Steffen

Changes from v5 [3]:
- fix multiple rcu and use after free issues in vfio
- multiple smaller mostly cosmetic improvements
arm64:
- fixed regression in compat enum & cleaned up
- fixed SPSR_ELx definitions
- removed reset_core_reg extracting which is now is already done (thanks Fuad)
- renamed and moved register access function to vcpu_<foo> to kvm_emulate.h they are now at the same position and naming scheme like the preexisting ones
- fix resetting reserved field in fpsimd

s390:
- gmap: Guard and not move s390-guest only gmap-code
- split refactoring into more patches to ease review
- fixed minor bugs in header/code shared code generation
- Kconfig reorganization:
- removed KVM_S390, the KVM for s390 guests keeps using by CONFIG_KVM
- KVM_ARM64 now depends on KVM
- KVM is selectable (as it was before this series)
- All (s390) KVM configs are in arch/s390/kvm/Kconfig

Changes from v4 [2]:
- do not remove CONFIG_KVM_MMIO but let KVM/s390 opt out of MMIO
- use kstrdup_const for copying the kvm-device name
- use file based vfio tracking instead of inlining struct kvm refcounting arm64:
- reorganized arm64 code share & refactoring - first refactoring then sharing
- add arm64 refactoring to reduce shared regions
- shared a bit more function (definitions) to reduce no of shared regions (which would be shared in later series anyways)
- add patch to generate SPSR sysreg definitions
- add patch which defines an enum for the arm32 compat registers
s390:
- fix arm64 header generation wiring
- awk scripts are more robust and error out if an end marker is missing
- postfix combined headers with -gen instead of -part
- removed pre-fault-memory implementation
- implemented system supported feature sanitisation
- removed some unnecessary functions
- moved prefix, cmma, and storage key code from gmap to kvm/s390
- properly reset vxregs

Changes from v3

- Complete rework of the code sharing approach
- Introduced ARM64_S390_COMMON marker for selective extraction
- Build-time extraction instead of development-time sharing
- Minimal impact on arm64 codebase
- Improved gmap refactoring and integration

[1] Previous versions:
v1 https://lore.kernel.org/all/[email protected]/
v2 https://lore.kernel.org/all/[email protected]/
v3 https://lore.kernel.org/all/[email protected]/

[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/

Hendrik Brueckner (1):
s390/hwcaps: Report SAE support as hwcap

Steffen Eiden (32):
vfio: Use file-based reference counting for KVM
KVM: Make device name configurable
KVM: Allow KVM implementations to switch off MMIO independent of
Kconfig
arm64: Use proper include variant
arm64: ptrace: Use constants for compat register numbers
arm64: sysreg: Convert SPSR_ELx to automatic register generation
KVM: arm64: Access elements of vcpu_gp_regs individually
KVM: arm64: Use accessor functions for core regs
arm64: Prepare sharing arm64 headers with s390
arm64: Share arm64 headers with s390
KVM: arm64: Share arm64 code with s390
KVM: s390: Extract gmap tracing to a separate header
KVM: s390: Prepare include guards for a new location
KVM: s390: Rename kvm-s390.{c,h} to s390.{c,h}
KVM: s390: Move kvm_host definitions to kvm_host_s390
KVM: s390: Move s390 kvm code into a subdirectory
KVM: s390: Move PGM code definitions to asm/kvm_host.h
KVM: s390: Prepare gmap for a second KVM implementation
KVM: s390: gmap: Make storage keys optional
KVM: s390: gmap: Make CMMA optional
KVM: s390: gmap: Make prefix handling optional
KVM: s390: Prepare KVM/s390 for a second KVM module
s390: Use arm64 headers
KVM: s390: Use arm64 code
s390: Introduce Start Arm Execution instruction
KVM: s390: arm64: Introduce host definitions
KVM: s390: Add basic arm64 kvm module
KVM: s390: arm64: Implement required functions
KVM: s390: arm64: Implement vm/vcpu create destroy.
KVM: s390: arm64: Implement vCPU IOCTLs
KVM: s390: arm64: Implement basic page fault handler
KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild

 MAINTAINERS                                   |   2 +-
 arch/arm64/Makefile                           |   2 +
 arch/arm64/include/asm/brk-imm.h              |   1 +
 arch/arm64/include/asm/esr.h                  |   5 +-
 arch/arm64/include/asm/kvm_arm.h              |   6 +-
 arch/arm64/include/asm/kvm_emulate.h          |  69 +-
 arch/arm64/include/asm/kvm_host.h             |  81 +-
 arch/arm64/include/asm/ptrace.h               |  64 +-
 arch/arm64/include/asm/sysreg.h               |  22 +-
 arch/arm64/kvm/arm.c                          |   3 +
 arch/arm64/kvm/guest.c                        |  22 +-
 arch/arm64/kvm/handle_exit.c                  |   6 +
 arch/arm64/kvm/hyp/exception.c                |   4 +-
 arch/arm64/kvm/hyp/include/hyp/adjust_pc.h    |   4 +-
 arch/arm64/kvm/hyp/include/hyp/switch.h       |   4 +-
 arch/arm64/kvm/mmio.c                         |   2 +
 arch/arm64/tools/sysreg                       |  48 ++
 arch/s390/configs/debug_defconfig             |   1 +
 arch/s390/configs/defconfig                   |   1 +
 arch/s390/include/arm64/kvm_emulate.h         | 130 +++
 arch/s390/include/arm64/kvm_nested.h          |  11 +
 arch/s390/include/arm64/ptrace.h              |  11 +
 arch/s390/include/arm64/sysreg.h              |  13 +
 arch/s390/include/asm/Kbuild                  |   3 +
 arch/s390/include/asm/asm-prototypes.h        |   1 +
 arch/s390/include/asm/elf.h                   |   2 +
 arch/s390/include/asm/kvm.h                   |   6 +
 arch/s390/include/asm/kvm_host.h              | 730 +----------------
 arch/s390/include/asm/kvm_host_arm64.h        | 220 ++++++
 arch/s390/include/asm/kvm_host_arm64_types.h  | 118 +++
 .../asm/{kvm_host.h => kvm_host_s390.h}       |  66 +-
 ...kvm_host_types.h => kvm_host_s390_types.h} |   6 +-
 arch/s390/include/asm/kvm_host_types.h        | 353 +--------
 arch/s390/include/asm/sae.h                   |  57 ++
 arch/s390/include/asm/sclp.h                  |   5 +-
 arch/s390/include/asm/stacktrace.h            |   5 +
 arch/s390/kernel/asm-offsets.c                |   1 +
 arch/s390/kernel/entry.S                      |  22 +
 arch/s390/kernel/processor.c                  |   3 +
 arch/s390/kvm/Kconfig                         |  29 +
 arch/s390/kvm/Makefile                        |  12 +-
 arch/s390/kvm/arm64/.gitignore                |   2 +
 arch/s390/kvm/arm64/Makefile                  |  91 +++
 arch/s390/kvm/arm64/Makefile.gen              |  29 +
 arch/s390/kvm/arm64/arm.c                     | 746 ++++++++++++++++++
 arch/s390/kvm/arm64/arm.h                     |  63 ++
 arch/s390/kvm/arm64/copy-arm64c.awk           |  72 ++
 arch/s390/kvm/arm64/guest.c                   | 135 ++++
 arch/s390/kvm/arm64/handle_exit.c             | 131 +++
 arch/s390/kvm/arm64/handle_exit.h             |   9 +
 arch/s390/kvm/arm64/inject_fault.c            |  21 +
 arch/s390/kvm/arm64/mmio.c                    |  15 +
 arch/s390/kvm/arm64/mmu.c                     | 177 +++++
 arch/s390/kvm/arm64/reset.c                   |  73 ++
 arch/s390/kvm/arm64/reset.h                   |  11 +
 arch/s390/kvm/arm64/trace.h                   |  42 +
 arch/s390/kvm/gmap/Makefile                   |   5 +
 arch/s390/kvm/{ => gmap}/dat.c                |   4 +
 arch/s390/kvm/{ => gmap}/dat.h                |  21 +-
 arch/s390/kvm/{ => gmap}/faultin.c            |   8 +-
 arch/s390/kvm/{ => gmap}/faultin.h            |   6 +-
 arch/s390/kvm/{ => gmap}/gmap.c               |  23 +-
 arch/s390/kvm/{ => gmap}/gmap.h               |  25 +-
 arch/s390/kvm/gmap/kvm_mmu.c                  | 137 ++++
 arch/s390/kvm/gmap/kvm_mmu.h                  |  18 +
 arch/s390/kvm/gmap/trace_gmap.h               |  64 ++
 arch/s390/kvm/s390/Makefile                   |  14 +
 arch/s390/kvm/{ => s390}/diag.c               |   2 +-
 arch/s390/kvm/{ => s390}/gaccess.c            |   2 +-
 arch/s390/kvm/{ => s390}/gaccess.h            |   2 +-
 arch/s390/kvm/{ => s390}/guestdbg.c           |   2 +-
 arch/s390/kvm/{ => s390}/intercept.c          |   2 +-
 arch/s390/kvm/{ => s390}/interrupt.c          |   2 +-
 arch/s390/kvm/{ => s390}/pci.c                |   2 +-
 arch/s390/kvm/{ => s390}/pci.h                |   0
 arch/s390/kvm/{ => s390}/priv.c               |   2 +-
 arch/s390/kvm/{ => s390}/pv.c                 |   2 +-
 arch/s390/kvm/{kvm-s390.c => s390/s390.c}     | 136 +---
 arch/s390/kvm/{kvm-s390.h => s390/s390.h}     |  10 +-
 arch/s390/kvm/{ => s390}/sigp.c               |   2 +-
 arch/s390/kvm/{ => s390}/trace-s390.h         |   0
 arch/s390/kvm/{ => s390}/trace.h              |  14 -
 arch/s390/kvm/{ => s390}/vsie.c               |   2 +-
 arch/s390/tools/Makefile                      |   9 +-
 arch/s390/tools/Makefile.arm64h               |  57 ++
 arch/s390/tools/copy-arm64h-full.awk          |  47 ++
 arch/s390/tools/copy-arm64h.awk               |  72 ++
 arch/s390/tools/opcodes.txt                   |   3 +
 arch/x86/include/asm/kvm_page_track.h         |   8 +-
 arch/x86/kvm/Makefile                         |   3 -
 arch/x86/kvm/mmu/page_track.c                 |  16 +-
 drivers/s390/char/sclp_early.c                |   1 +
 drivers/s390/crypto/vfio_ap_ops.c             |  30 +-
 drivers/s390/crypto/vfio_ap_private.h         |   1 +
 drivers/vfio/device_cdev.c                    |   2 +-
 drivers/vfio/group.c                          |   4 +-
 drivers/vfio/pci/vfio_pci_zdev.c              |   7 +-
 drivers/vfio/vfio.h                           |  10 +-
 drivers/vfio/vfio_main.c                      |  52 +-
 include/linux/kvm_host.h                      |  11 +-
 include/linux/vfio.h                          |   5 +-
 virt/kvm/async_pf.c                           |  13 +-
 virt/kvm/async_pf.h                           |   4 +-
 virt/kvm/coalesced_mmio.c                     |   4 +
 virt/kvm/coalesced_mmio.h                     |   2 +-
 virt/kvm/kvm_main.c                           |  73 +-
 virt/kvm/vfio.c                               |   8 +-
 107 files changed, 3241 insertions(+), 1476 deletions(-)
 create mode 100644 arch/s390/include/arm64/kvm_emulate.h
 create mode 100644 arch/s390/include/arm64/kvm_nested.h
 create mode 100644 arch/s390/include/arm64/ptrace.h
 create mode 100644 arch/s390/include/arm64/sysreg.h
 create mode 100644 arch/s390/include/asm/kvm.h
 create mode 100644 arch/s390/include/asm/kvm_host_arm64.h
 create mode 100644 arch/s390/include/asm/kvm_host_arm64_types.h
 copy arch/s390/include/asm/{kvm_host.h => kvm_host_s390.h} (90%)
 copy arch/s390/include/asm/{kvm_host_types.h => kvm_host_s390_types.h} (98%)
 create mode 100644 arch/s390/include/asm/sae.h
 create mode 100644 arch/s390/kvm/arm64/.gitignore
 create mode 100644 arch/s390/kvm/arm64/Makefile
 create mode 100644 arch/s390/kvm/arm64/Makefile.gen
 create mode 100644 arch/s390/kvm/arm64/arm.c
 create mode 100644 arch/s390/kvm/arm64/arm.h
 create mode 100644 arch/s390/kvm/arm64/copy-arm64c.awk
 create mode 100644 arch/s390/kvm/arm64/guest.c
 create mode 100644 arch/s390/kvm/arm64/handle_exit.c
 create mode 100644 arch/s390/kvm/arm64/handle_exit.h
 create mode 100644 arch/s390/kvm/arm64/inject_fault.c
 create mode 100644 arch/s390/kvm/arm64/mmio.c
 create mode 100644 arch/s390/kvm/arm64/mmu.c
 create mode 100644 arch/s390/kvm/arm64/reset.c
 create mode 100644 arch/s390/kvm/arm64/reset.h
 create mode 100644 arch/s390/kvm/arm64/trace.h
 create mode 100644 arch/s390/kvm/gmap/Makefile
 rename arch/s390/kvm/{ => gmap}/dat.c (99%)
 rename arch/s390/kvm/{ => gmap}/dat.h (98%)
 rename arch/s390/kvm/{ => gmap}/faultin.c (96%)
 rename arch/s390/kvm/{ => gmap}/faultin.h (96%)
 rename arch/s390/kvm/{ => gmap}/gmap.c (99%)
 rename arch/s390/kvm/{ => gmap}/gmap.h (96%)
 create mode 100644 arch/s390/kvm/gmap/kvm_mmu.c
 create mode 100644 arch/s390/kvm/gmap/kvm_mmu.h
 create mode 100644 arch/s390/kvm/gmap/trace_gmap.h
 create mode 100644 arch/s390/kvm/s390/Makefile
 rename arch/s390/kvm/{ => s390}/diag.c (99%)
 rename arch/s390/kvm/{ => s390}/gaccess.c (99%)
 rename arch/s390/kvm/{ => s390}/gaccess.h (99%)
 rename arch/s390/kvm/{ => s390}/guestdbg.c (99%)
 rename arch/s390/kvm/{ => s390}/intercept.c (99%)
 rename arch/s390/kvm/{ => s390}/interrupt.c (99%)
 rename arch/s390/kvm/{ => s390}/pci.c (99%)
 rename arch/s390/kvm/{ => s390}/pci.h (100%)
 rename arch/s390/kvm/{ => s390}/priv.c (99%)
 rename arch/s390/kvm/{ => s390}/pv.c (99%)
 rename arch/s390/kvm/{kvm-s390.c => s390/s390.c} (98%)
 rename arch/s390/kvm/{kvm-s390.h => s390/s390.h} (98%)
 rename arch/s390/kvm/{ => s390}/sigp.c (99%)
 rename arch/s390/kvm/{ => s390}/trace-s390.h (100%)
 rename arch/s390/kvm/{ => s390}/trace.h (97%)
 rename arch/s390/kvm/{ => s390}/vsie.c (99%)
 create mode 100644 arch/s390/tools/Makefile.arm64h
 create mode 100644 arch/s390/tools/copy-arm64h-full.awk
 create mode 100644 arch/s390/tools/copy-arm64h.awk

base-commit: 5e6de6a2b522f659defacb1551d0465ba6ce13cf

Signature · 1 line
2.53.0
author reviewer
#3 lore raw

PATCH v6 2/33 KVM: Make device name configurable

Allow KVM implementations to choose alternative device names. This is especially useful for architectures providing multiple KVM implementations simultaneously.

---
 include/linux/kvm_host.h |  4 +++-
 virt/kvm/async_pf.c      | 13 ++++++++++--
 virt/kvm/async_pf.h      |  4 ++--
 virt/kvm/kvm_main.c      | 43 ++++++++++++++++++++++++++++++----------
 4 files changed, 49 insertions(+), 15 deletions(-)
include/linux/kvm_host.h +3 -1
index 1c5bf2801bf1..6ea6322ba8b5 100644
@@ -1081,7 +1081,9 @@ static inline void kvm_irqfd_exit(void)
 {
 }
 #endif
-int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module);
+int kvm_init(unsigned int vcpu_size, unsigned int vcpu_align, struct module *module);
+int kvm_init_with_dev(unsigned int vcpu_size, unsigned int vcpu_align,
+		      struct module *module, const char *dev_name, int minor);
 void kvm_exit(void);
 
 void kvm_get_kvm(struct kvm *kvm);
virt/kvm/async_pf.c +11 -2
index b8aaa96b799b..015761249107 100644
@@ -19,9 +19,18 @@
 
 static struct kmem_cache *async_pf_cache;
 
-int kvm_async_pf_init(void)
+int kvm_async_pf_init(const char *cache_name)
 {
-	async_pf_cache = KMEM_CACHE(kvm_async_pf, 0);
+	char *full_cache_name;
+
+	full_cache_name = kasprintf(GFP_KERNEL, "%s_async_pf", cache_name);
+	if (!full_cache_name)
+		return -ENOMEM;
+
+	async_pf_cache = kmem_cache_create(full_cache_name,
+					   sizeof(struct kvm_async_pf), 0,
+					   SLAB_ACCOUNT, NULL);
+	kfree(full_cache_name);
 
 	if (!async_pf_cache)
 		return -ENOMEM;
virt/kvm/async_pf.h +2 -2
index 90d1a7d8c6de..829003899414 100644
@@ -12,11 +12,11 @@
 #define __KVM_ASYNC_PF_H__
 
 #ifdef CONFIG_KVM_ASYNC_PF
-int kvm_async_pf_init(void);
+int kvm_async_pf_init(const char *cache_name);
 void kvm_async_pf_deinit(void);
 void kvm_async_pf_vcpu_init(struct kvm_vcpu *vcpu);
 #else
-#define kvm_async_pf_init() (0)
+#define kvm_async_pf_init(name) (0)
 #define kvm_async_pf_deinit() do {} while (0)
 #define kvm_async_pf_vcpu_init(C) do {} while (0)
 #endif
virt/kvm/kvm_main.c +33 -10

109 lines not on this page · raw message

Signature · 1 line
2.53.0
author reviewer
#27 lore raw

PATCH v6 9/33 arm64: Prepare sharing arm64 headers with s390

In reply to Steffen Eiden

Prepare the sharing of arm64 headers with s390 by moving a few definitions inside headers to reduce the number of shared markers. Clean up some includes to further streamline the sharing of headers.

No functional change.

---
 arch/arm64/include/asm/esr.h         |  4 +-
 arch/arm64/include/asm/kvm_arm.h     |  5 ++-
 arch/arm64/include/asm/kvm_emulate.h |  5 ++-
 arch/arm64/include/asm/kvm_host.h    | 59 ++++++++++++++--------------
 arch/arm64/include/asm/sysreg.h      |  2 +-
 5 files changed, 39 insertions(+), 36 deletions(-)
arch/arm64/include/asm/esr.h +2 -2
index f816f5d77f1a..da085c83b57e 100644
@@ -7,7 +7,7 @@
 #ifndef __ASM_ESR_H
 #define __ASM_ESR_H
 
-#include <asm/memory.h>
+#include <asm/brk-imm.h>
 #include <asm/sysreg.h>
 
 #define ESR_ELx_EC_UNKNOWN	UL(0x00)
@@ -435,7 +435,7 @@
 #define ESR_ELx_IT_GCSPOPX		7
 
 #ifndef __ASSEMBLER__
-#include <asm/types.h>
+#include <linux/types.h>
 
 static inline unsigned long esr_brk_comment(unsigned long esr)
 {
arch/arm64/include/asm/kvm_arm.h +3 -2
index 4bfbd827c5aa..57edd8437200 100644
@@ -7,10 +7,11 @@
 #ifndef __ARM64_KVM_ARM_H__
 #define __ARM64_KVM_ARM_H__
 
+#include <linux/const.h>
+#include <linux/bits.h>
+#include <linux/types.h>
 #include <asm/esr.h>
-#include <asm/memory.h>
 #include <asm/sysreg.h>
-#include <asm/types.h>
 
 /*
  * Because I'm terribly lazy and that repainting the whole of the KVM
arch/arm64/include/asm/kvm_emulate.h +3 -2
index b31d50bdf59e..a34a9417ff4d 100644
@@ -44,11 +44,12 @@ enum exception_type {
 bool kvm_condition_valid32(const struct kvm_vcpu *vcpu);
 void kvm_skip_instr32(struct kvm_vcpu *vcpu);
 
+int kvm_inject_dabt_excl_atomic(struct kvm_vcpu *vcpu, u64 addr);
+int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr);
+
 void kvm_inject_undefined(struct kvm_vcpu *vcpu);
 void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr);
-int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr);
 int kvm_inject_sea(struct kvm_vcpu *vcpu, bool iabt, u64 addr);
-int kvm_inject_dabt_excl_atomic(struct kvm_vcpu *vcpu, u64 addr);
 void kvm_inject_size_fault(struct kvm_vcpu *vcpu);
 
 static inline int kvm_inject_sea_dabt(struct kvm_vcpu *vcpu, u64 addr)
arch/arm64/include/asm/kvm_host.h +30 -29

71 lines not on this page · raw message

arch/arm64/include/asm/sysreg.h +1 -1
index 1aa601c95188..ab205f9db94a 100644
@@ -1263,6 +1263,6 @@
 		 FIELD_PREP(reg##_##field##_MASK,	\
 			    SYS_FIELD_VALUE(reg, field, val))
 
-#endif
+#endif /* __ASSEMBLER__ */
 
 #endif	/* __ASM_SYSREG_H */
Signature · 1 line
2.53.0
author reviewer
#38 lore raw

PATCH v6 12/33 KVM: s390: Extract gmap tracing to a separate header

In reply to Steffen Eiden

Move the kvm_s390_major_guest_pfault trace event from trace.h to a new trace_gmap.h header. This separates gmap-specific tracing from general KVM/s390 tracing, preparing for code sharing between multiple KVM implementations.

The trace event definition is updated to use local defines for parameters so that they can be replaced later with ease for when another KVM implementation uses these traces.

No functional change.

---
 arch/s390/kvm/faultin.c    |  3 ++-
 arch/s390/kvm/trace.h      | 14 ------------
 arch/s390/kvm/trace_gmap.h | 47 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 15 deletions(-)
 create mode 100644 arch/s390/kvm/trace_gmap.h
arch/s390/kvm/faultin.c +2 -1
index 3cc45f7f5b2d..1dc79807012c 100644
@@ -9,10 +9,11 @@
 #include <linux/kvm_host.h>
 
 #include "gmap.h"
-#include "trace.h"
 #include "faultin.h"
 
 bool kvm_arch_setup_async_pf(struct kvm_vcpu *vcpu);
+#define CREATE_TRACE_POINTS
+#include "trace_gmap.h"
 
 /*
  * kvm_s390_faultin_gfn() - handle a dat fault.
arch/s390/kvm/trace.h +0 -14
index dd2685c7df5b..3d2fffb1555a 100644
@@ -45,20 +45,6 @@ TRACE_EVENT(kvm_s390_skey_related_inst,
 	    VCPU_TP_PRINTK("%s", "storage key related instruction")
 	);
 
-TRACE_EVENT(kvm_s390_major_guest_pfault,
-	    TP_PROTO(VCPU_PROTO_COMMON),
-	    TP_ARGS(VCPU_ARGS_COMMON),
-
-	    TP_STRUCT__entry(
-		    VCPU_FIELD_COMMON
-		    ),
-
-	    TP_fast_assign(
-		    VCPU_ASSIGN_COMMON
-		    ),
-	    VCPU_TP_PRINTK("%s", "major fault, maybe applicable for pfault")
-	);
-
 TRACE_EVENT(kvm_s390_pfault_init,
 	    TP_PROTO(VCPU_PROTO_COMMON, long pfault_token),
 	    TP_ARGS(VCPU_ARGS_COMMON, pfault_token),
arch/s390/kvm/trace_gmap.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.53.0
author reviewer
#41 lore raw

PATCH v6 13/33 KVM: s390: Prepare include guards for a new location

In reply to Steffen Eiden

Update include guard names in dat.h, faultin.h, and gmap.h to ARCH_KVM_GMAP_* to reflect their upcoming relocation to a shared gmap directory.

No functional change.

---
 arch/s390/kvm/dat.h     | 6 +++---
 arch/s390/kvm/faultin.h | 6 +++---
 arch/s390/kvm/gmap.h    | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)
arch/s390/kvm/dat.h +3 -3
index 141ee7b9f019..87108f51228e 100644
@@ -6,8 +6,8 @@
  *    Author(s): Claudio Imbrenda <[email protected]>
  */
 
-#ifndef __KVM_S390_DAT_H
-#define __KVM_S390_DAT_H
+#ifndef ARCH_KVM_GMAP_DAT_H
+#define ARCH_KVM_GMAP_DAT_H
 
 #include <linux/radix-tree.h>
 #include <linux/refcount.h>
@@ -975,4 +975,4 @@ static inline bool crste_is_ucas(union crste crste)
 	return is_pmd(crste) && crste.h.i && crste.h.fc0.tl == 1 && crste.h.fc == 0;
 }
 
-#endif /* __KVM_S390_DAT_H */
+#endif /* ARCH_KVM_GMAP_DAT_H */
arch/s390/kvm/faultin.h +3 -3
index f86176d2769c..f343b6fb6f16 100644
@@ -6,8 +6,8 @@
  *    Author(s): Claudio Imbrenda <[email protected]>
  */
 
-#ifndef __KVM_S390_FAULTIN_H
-#define __KVM_S390_FAULTIN_H
+#ifndef ARCH_KVM_GMAP_FAULTIN_H
+#define ARCH_KVM_GMAP_FAULTIN_H
 
 #include <linux/kvm_host.h>
 
@@ -89,4 +89,4 @@ static inline int kvm_s390_get_guest_pages(struct kvm *kvm, struct guest_fault *
 #define kvm_s390_array_needs_retry_safe(kvm, seq, array) \
 	kvm_s390_multiple_faults_need_retry(kvm, seq, array, ARRAY_SIZE(array), false)
 
-#endif /* __KVM_S390_FAULTIN_H */
+#endif /* ARCH_KVM_GMAP_FAULTIN_H */
arch/s390/kvm/gmap.h +3 -3
index 39938d363ec9..c54c35e47d6d 100644
@@ -7,8 +7,8 @@
  *               Claudio Imbrenda <[email protected]>
  */
 
-#ifndef ARCH_KVM_S390_GMAP_H
-#define ARCH_KVM_S390_GMAP_H
+#ifndef ARCH_KVM_GMAP_GMAP_H
+#define ARCH_KVM_GMAP_GMAP_H
 
 #include "dat.h"
 
@@ -330,4 +330,4 @@ static inline bool gmap_is_shadow_valid(struct gmap *sg, union asce asce, int ed
 	return sg->guest_asce.val == asce.val && sg->edat_level == edat_level;
 }
 
-#endif /* ARCH_KVM_S390_GMAP_H */
+#endif /* ARCH_KVM_GMAP_GMAP_H */
Signature · 1 line
2.53.0
author reviewer
#53 lore raw

PATCH v6 17/33 KVM: s390: Move PGM code definitions to asm/kvm_host.h

In reply to Steffen Eiden

Move PGM code definitions from kvm_host_s390.h (back) to the generic kvm_host.h. These definitions are needed by multiple KVM implementations and should be in a shared location.

No functional change.

---
 arch/s390/include/asm/kvm_host.h      | 57 +++++++++++++++++++++++++++
 arch/s390/include/asm/kvm_host_s390.h | 57 ---------------------------
 2 files changed, 57 insertions(+), 57 deletions(-)
arch/s390/include/asm/kvm_host.h +57 -0
index e76ceee11ef5..147325978225 100644
@@ -5,4 +5,61 @@
 
 #include <asm/kvm_host_s390.h>
 
+#define PGM_OPERATION			0x01
+#define PGM_PRIVILEGED_OP		0x02
+#define PGM_EXECUTE			0x03
+#define PGM_PROTECTION			0x04
+#define PGM_ADDRESSING			0x05
+#define PGM_SPECIFICATION		0x06
+#define PGM_DATA			0x07
+#define PGM_FIXED_POINT_OVERFLOW	0x08
+#define PGM_FIXED_POINT_DIVIDE		0x09
+#define PGM_DECIMAL_OVERFLOW		0x0a
+#define PGM_DECIMAL_DIVIDE		0x0b
+#define PGM_HFP_EXPONENT_OVERFLOW	0x0c
+#define PGM_HFP_EXPONENT_UNDERFLOW	0x0d
+#define PGM_HFP_SIGNIFICANCE		0x0e
+#define PGM_HFP_DIVIDE			0x0f
+#define PGM_SEGMENT_TRANSLATION		0x10
+#define PGM_PAGE_TRANSLATION		0x11
+#define PGM_TRANSLATION_SPEC		0x12
+#define PGM_SPECIAL_OPERATION		0x13
+#define PGM_OPERAND			0x15
+#define PGM_TRACE_TABEL			0x16
+#define PGM_VECTOR_PROCESSING		0x1b
+#define PGM_SPACE_SWITCH		0x1c
+#define PGM_HFP_SQUARE_ROOT		0x1d
+#define PGM_PC_TRANSLATION_SPEC		0x1f
+#define PGM_AFX_TRANSLATION		0x20
+#define PGM_ASX_TRANSLATION		0x21
+#define PGM_LX_TRANSLATION		0x22
+#define PGM_EX_TRANSLATION		0x23
+#define PGM_PRIMARY_AUTHORITY		0x24
+#define PGM_SECONDARY_AUTHORITY		0x25
+#define PGM_LFX_TRANSLATION		0x26
+#define PGM_LSX_TRANSLATION		0x27
+#define PGM_ALET_SPECIFICATION		0x28
+#define PGM_ALEN_TRANSLATION		0x29
+#define PGM_ALE_SEQUENCE		0x2a
+#define PGM_ASTE_VALIDITY		0x2b
+#define PGM_ASTE_SEQUENCE		0x2c
+#define PGM_EXTENDED_AUTHORITY		0x2d
+#define PGM_LSTE_SEQUENCE		0x2e
+#define PGM_ASTE_INSTANCE		0x2f
+#define PGM_STACK_FULL			0x30
+#define PGM_STACK_EMPTY			0x31
+#define PGM_STACK_SPECIFICATION		0x32
+#define PGM_STACK_TYPE			0x33
+#define PGM_STACK_OPERATION		0x34
+#define PGM_ASCE_TYPE			0x38
+#define PGM_REGION_FIRST_TRANS		0x39
+#define PGM_REGION_SECOND_TRANS		0x3a
+#define PGM_REGION_THIRD_TRANS		0x3b
+#define PGM_SECURE_STORAGE_ACCESS	0x3d
+#define PGM_NON_SECURE_STORAGE_ACCESS	0x3e
+#define PGM_SECURE_STORAGE_VIOLATION	0x3f
+#define PGM_MONITOR			0x40
+#define PGM_PER				0x80
+#define PGM_CRYPTO_OPERATION		0x119
+
 #endif /* ASM_KVM_HOST_H */
arch/s390/include/asm/kvm_host_s390.h +0 -57

63 lines not on this page · raw message

Signature · 1 line
2.53.0
author reviewer
#76 lore raw

PATCH v6 26/33 KVM: s390: arm64: Introduce host definitions

In reply to Steffen Eiden

Add all basic definitions the arm on s390 KVM host requires. Including, but not limited to, struct kvm*arch definitions, various functions (to be implemented in the following patches), and various defines required to run arm64 guests.

Enlighten asm/kvm_host.h for the new header variant. The new header is chosen instead of asm/kvm_host_s390.h if KVM_S390_ARM64 is defined.

---
 arch/s390/include/asm/kvm.h            |   6 +
 arch/s390/include/asm/kvm_host.h       |   9 +
 arch/s390/include/asm/kvm_host_arm64.h | 220 +++++++++++++++++++++++++
 3 files changed, 235 insertions(+)
 create mode 100644 arch/s390/include/asm/kvm.h
 create mode 100644 arch/s390/include/asm/kvm_host_arm64.h
arch/s390/include/asm/kvm.h new file +6 -0
new file mode 100644
index 000000000000..aeb11dc631d5
@@ -0,0 +1,6 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifdef KVM_S390_ARM64
+#include <uapi/arm64/kvm.h>
+#else
+#include <uapi/asm/kvm.h>
+#endif
arch/s390/include/asm/kvm_host.h +9 -0
index 147325978225..cd6d572883ab 100644
@@ -3,7 +3,16 @@
 #ifndef ASM_KVM_HOST_H
 #define ASM_KVM_HOST_H
 
+#ifdef KVM_S390_ARM64
+#include <asm/kvm_host_arm64.h>
+#else
 #include <asm/kvm_host_s390.h>
+#endif
+
+static inline  bool kvm_arch_pmi_in_guest(struct kvm_vcpu *vcpu)
+{
+	return false;
+}
 
 #define PGM_OPERATION			0x01
 #define PGM_PRIVILEGED_OP		0x02
arch/s390/include/asm/kvm_host_arm64.h new file +220 -0

220 lines not on this page · raw message

Signature · 1 line
2.53.0
author reviewer
#7 lore raw

PATCH v6 4/33 arm64: Use proper include variant

In reply to Steffen Eiden

Use <> for including the sysreg header as it is not discoverable from the current directory.

Fixes c07d8017bceb ("arm64/sysreg: Enable automatic generation of system register definitions")
---
 arch/arm64/include/asm/sysreg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/sysreg.h +1 -1
index 7aa08d59d494..4bfdac9401bd 100644
@@ -173,7 +173,7 @@
  * come from here. The header relies on the definition of sys_reg()
  * earlier in this file.
  */
-#include "asm/sysreg-defs.h"
+#include <asm/sysreg-defs.h>
 
 /*
  * System registers, organised loosely by encoding but grouped together
Signature · 1 line
2.53.0
author reviewer
#50 lore raw

PATCH v6 16/33 KVM: s390: Move s390 kvm code into a subdirectory

In reply to Steffen Eiden

Move all the code required to run s390 KVM guests on s390 to a s390 subdirectory. Move gmap related code into a gmap directory to later share gmap code between KVM implementations.

Update S390 VFIO-PCI MAINTAINERS filepath.

No functional change.

---
 MAINTAINERS                           |  2 +-
 arch/s390/kvm/Makefile                | 11 +----------
 arch/s390/kvm/gmap/Makefile           |  5 +++++
 arch/s390/kvm/{ => gmap}/dat.c        |  0
 arch/s390/kvm/{ => gmap}/dat.h        |  0
 arch/s390/kvm/{ => gmap}/faultin.c    |  0
 arch/s390/kvm/{ => gmap}/faultin.h    |  0
 arch/s390/kvm/{ => gmap}/gmap.c       |  0
 arch/s390/kvm/{ => gmap}/gmap.h       |  0
 arch/s390/kvm/{ => gmap}/trace_gmap.h |  2 +-
 arch/s390/kvm/{ => s390}/Makefile     |  9 ++++-----
 arch/s390/kvm/{ => s390}/diag.c       |  0
 arch/s390/kvm/{ => s390}/gaccess.c    |  0
 arch/s390/kvm/{ => s390}/gaccess.h    |  0
 arch/s390/kvm/{ => s390}/guestdbg.c   |  0
 arch/s390/kvm/{ => s390}/intercept.c  |  0
 arch/s390/kvm/{ => s390}/interrupt.c  |  0
 arch/s390/kvm/{ => s390}/pci.c        |  0
 arch/s390/kvm/{ => s390}/pci.h        |  0
 arch/s390/kvm/{ => s390}/priv.c       |  0
 arch/s390/kvm/{ => s390}/pv.c         |  0
 arch/s390/kvm/{ => s390}/s390.c       |  0
 arch/s390/kvm/{ => s390}/s390.h       |  0
 arch/s390/kvm/{ => s390}/sigp.c       |  0
 arch/s390/kvm/{ => s390}/trace-s390.h |  0
 arch/s390/kvm/{ => s390}/trace.h      |  0
 arch/s390/kvm/{ => s390}/vsie.c       |  0
 27 files changed, 12 insertions(+), 17 deletions(-)
 create mode 100644 arch/s390/kvm/gmap/Makefile
 rename arch/s390/kvm/{ => gmap}/dat.c (100%)
 rename arch/s390/kvm/{ => gmap}/dat.h (100%)
 rename arch/s390/kvm/{ => gmap}/faultin.c (100%)
 rename arch/s390/kvm/{ => gmap}/faultin.h (100%)
 rename arch/s390/kvm/{ => gmap}/gmap.c (100%)
 rename arch/s390/kvm/{ => gmap}/gmap.h (100%)
 rename arch/s390/kvm/{ => gmap}/trace_gmap.h (96%)
 copy arch/s390/kvm/{ => s390}/Makefile (62%)
 rename arch/s390/kvm/{ => s390}/diag.c (100%)
 rename arch/s390/kvm/{ => s390}/gaccess.c (100%)
 rename arch/s390/kvm/{ => s390}/gaccess.h (100%)
 rename arch/s390/kvm/{ => s390}/guestdbg.c (100%)
 rename arch/s390/kvm/{ => s390}/intercept.c (100%)
 rename arch/s390/kvm/{ => s390}/interrupt.c (100%)
 rename arch/s390/kvm/{ => s390}/pci.c (100%)
 rename arch/s390/kvm/{ => s390}/pci.h (100%)
 rename arch/s390/kvm/{ => s390}/priv.c (100%)
 rename arch/s390/kvm/{ => s390}/pv.c (100%)
 rename arch/s390/kvm/{ => s390}/s390.c (100%)
 rename arch/s390/kvm/{ => s390}/s390.h (100%)
 rename arch/s390/kvm/{ => s390}/sigp.c (100%)
 rename arch/s390/kvm/{ => s390}/trace-s390.h (100%)
 rename arch/s390/kvm/{ => s390}/trace.h (100%)
 rename arch/s390/kvm/{ => s390}/vsie.c (100%)
MAINTAINERS +1 -1
index 15c7dc516f7c..29802f061063 100644
@@ -24150,7 +24150,7 @@ L:	[email protected]
 L:	[email protected]
 S:	Supported
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git
-F:	arch/s390/kvm/pci*
+F:	arch/s390/kvm/s390/pci*
 F:	drivers/vfio/pci/vfio_pci_zdev.c
 F:	include/uapi/linux/vfio_zdev.h
 
arch/s390/kvm/Makefile +1 -10
index 961de97b8e80..a4e3875b5bdd 100644
@@ -3,13 +3,4 @@
 #
 # Copyright IBM Corp. 2008
 
-include $(srctree)/virt/kvm/Makefile.kvm
-
-ccflags-y := -I$(src)
-
-kvm-y += s390.o intercept.o interrupt.o priv.o sigp.o
-kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o
-kvm-y += dat.o gmap.o faultin.o
-
-kvm-$(CONFIG_VFIO_PCI_ZDEV_KVM) += pci.o
-obj-$(CONFIG_KVM) += kvm.o
+obj-$(CONFIG_KVM) += s390/
arch/s390/kvm/gmap/Makefile new file +5 -0
new file mode 100644
index 000000000000..3a4f8df11622
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
+GMAP ?= ../gmap
+
+gmap-y += $(GMAP)/dat.o $(GMAP)/gmap.o $(GMAP)/faultin.o
arch/s390/kvm/gmap/dat.c renamed from arch/s390/kvm/dat.c +0 -0
similarity index 100%
rename from arch/s390/kvm/dat.c
rename to arch/s390/kvm/gmap/dat.c
arch/s390/kvm/gmap/dat.h renamed from arch/s390/kvm/dat.h +0 -0
similarity index 100%
rename from arch/s390/kvm/dat.h
rename to arch/s390/kvm/gmap/dat.h
arch/s390/kvm/gmap/faultin.c renamed from arch/s390/kvm/faultin.c +0 -0
similarity index 100%
rename from arch/s390/kvm/faultin.c
rename to arch/s390/kvm/gmap/faultin.c
arch/s390/kvm/gmap/faultin.h renamed from arch/s390/kvm/faultin.h +0 -0
similarity index 100%
rename from arch/s390/kvm/faultin.h
rename to arch/s390/kvm/gmap/faultin.h
arch/s390/kvm/gmap/gmap.c renamed from arch/s390/kvm/gmap.c +0 -0
similarity index 100%
rename from arch/s390/kvm/gmap.c
rename to arch/s390/kvm/gmap/gmap.c
arch/s390/kvm/gmap/gmap.h renamed from arch/s390/kvm/gmap.h +0 -0
similarity index 100%
rename from arch/s390/kvm/gmap.h
rename to arch/s390/kvm/gmap/gmap.h
arch/s390/kvm/gmap/trace_gmap.h renamed from arch/s390/kvm/trace_gmap.h +1 -1
similarity index 96%
rename from arch/s390/kvm/trace_gmap.h
rename to arch/s390/kvm/gmap/trace_gmap.h
index a3cad705021b..15ec88bdce55 100644
@@ -7,7 +7,7 @@
 #undef TRACE_SYSTEM
 #define TRACE_SYSTEM kvm
 #undef TRACE_INCLUDE_PATH
-#define TRACE_INCLUDE_PATH .
+#define TRACE_INCLUDE_PATH ../gmap
 #undef TRACE_INCLUDE_FILE
 #define TRACE_INCLUDE_FILE trace_gmap
 
arch/s390/kvm/s390/Makefile renamed from arch/s390/kvm/Makefile +4 -5
similarity index 62%
copy from arch/s390/kvm/Makefile
copy to arch/s390/kvm/s390/Makefile
index 961de97b8e80..762a63826423 100644
@@ -1,15 +1,14 @@
 # SPDX-License-Identifier: GPL-2.0
-# Makefile for kernel virtual machines on s390
-#
-# Copyright IBM Corp. 2008
 
+KVM := ../../../../virt/kvm
 include $(srctree)/virt/kvm/Makefile.kvm
+include $(srctree)/arch/s390/kvm/gmap/Makefile
 
-ccflags-y := -I$(src)
+ccflags-y := -I$(src) -I$(srctree)/arch/s390/kvm/gmap
 
 kvm-y += s390.o intercept.o interrupt.o priv.o sigp.o
 kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o
-kvm-y += dat.o gmap.o faultin.o
+kvm-y += $(gmap-y)
 
 kvm-$(CONFIG_VFIO_PCI_ZDEV_KVM) += pci.o
 obj-$(CONFIG_KVM) += kvm.o
arch/s390/kvm/s390/diag.c renamed from arch/s390/kvm/diag.c +0 -0
similarity index 100%
rename from arch/s390/kvm/diag.c
rename to arch/s390/kvm/s390/diag.c
arch/s390/kvm/s390/gaccess.c renamed from arch/s390/kvm/gaccess.c +0 -0
similarity index 100%
rename from arch/s390/kvm/gaccess.c
rename to arch/s390/kvm/s390/gaccess.c
arch/s390/kvm/s390/gaccess.h renamed from arch/s390/kvm/gaccess.h +0 -0
similarity index 100%
rename from arch/s390/kvm/gaccess.h
rename to arch/s390/kvm/s390/gaccess.h
arch/s390/kvm/s390/guestdbg.c renamed from arch/s390/kvm/guestdbg.c +0 -0
similarity index 100%
rename from arch/s390/kvm/guestdbg.c
rename to arch/s390/kvm/s390/guestdbg.c
arch/s390/kvm/s390/intercept.c renamed from arch/s390/kvm/intercept.c +0 -0
similarity index 100%
rename from arch/s390/kvm/intercept.c
rename to arch/s390/kvm/s390/intercept.c
arch/s390/kvm/s390/interrupt.c renamed from arch/s390/kvm/interrupt.c +0 -0
similarity index 100%
rename from arch/s390/kvm/interrupt.c
rename to arch/s390/kvm/s390/interrupt.c
arch/s390/kvm/s390/pci.c renamed from arch/s390/kvm/pci.c +0 -0
similarity index 100%
rename from arch/s390/kvm/pci.c
rename to arch/s390/kvm/s390/pci.c
arch/s390/kvm/s390/pci.h renamed from arch/s390/kvm/pci.h +0 -0
similarity index 100%
rename from arch/s390/kvm/pci.h
rename to arch/s390/kvm/s390/pci.h
arch/s390/kvm/s390/priv.c renamed from arch/s390/kvm/priv.c +0 -0
similarity index 100%
rename from arch/s390/kvm/priv.c
rename to arch/s390/kvm/s390/priv.c
arch/s390/kvm/s390/pv.c renamed from arch/s390/kvm/pv.c +0 -0
similarity index 100%
rename from arch/s390/kvm/pv.c
rename to arch/s390/kvm/s390/pv.c
arch/s390/kvm/s390/s390.c renamed from arch/s390/kvm/s390.c +0 -0
similarity index 100%
rename from arch/s390/kvm/s390.c
rename to arch/s390/kvm/s390/s390.c
arch/s390/kvm/s390/s390.h renamed from arch/s390/kvm/s390.h +0 -0
similarity index 100%
rename from arch/s390/kvm/s390.h
rename to arch/s390/kvm/s390/s390.h
arch/s390/kvm/s390/sigp.c renamed from arch/s390/kvm/sigp.c +0 -0
similarity index 100%
rename from arch/s390/kvm/sigp.c
rename to arch/s390/kvm/s390/sigp.c
arch/s390/kvm/s390/trace-s390.h renamed from arch/s390/kvm/trace-s390.h +0 -0
similarity index 100%
rename from arch/s390/kvm/trace-s390.h
rename to arch/s390/kvm/s390/trace-s390.h
arch/s390/kvm/s390/trace.h renamed from arch/s390/kvm/trace.h +0 -0
similarity index 100%
rename from arch/s390/kvm/trace.h
rename to arch/s390/kvm/s390/trace.h
arch/s390/kvm/s390/vsie.c renamed from arch/s390/kvm/vsie.c +0 -0
similarity index 100%
rename from arch/s390/kvm/vsie.c
rename to arch/s390/kvm/s390/vsie.c
Signature · 1 line
2.53.0
author reviewer
#44 lore raw

PATCH v6 14/33 KVM: s390: Rename kvm-s390.{c,h} to s390.{c,h}

In reply to Steffen Eiden

Rename kvm-s390.c to s390.c and kvm-s390.h to s390.h for consistency with the new directory structure. Update all include statements and simplify Makefile ccflags from explicit paths to -I$(src).

No functional change.

---
 arch/s390/kvm/Makefile               | 4 ++--
 arch/s390/kvm/diag.c                 | 2 +-
 arch/s390/kvm/gaccess.c              | 2 +-
 arch/s390/kvm/gaccess.h              | 2 +-
 arch/s390/kvm/gmap.c                 | 2 +-
 arch/s390/kvm/guestdbg.c             | 2 +-
 arch/s390/kvm/intercept.c            | 2 +-
 arch/s390/kvm/interrupt.c            | 2 +-
 arch/s390/kvm/pci.c                  | 2 +-
 arch/s390/kvm/priv.c                 | 2 +-
 arch/s390/kvm/pv.c                   | 2 +-
 arch/s390/kvm/{kvm-s390.c => s390.c} | 2 +-
 arch/s390/kvm/{kvm-s390.h => s390.h} | 2 +-
 arch/s390/kvm/sigp.c                 | 2 +-
 arch/s390/kvm/vsie.c                 | 2 +-
 15 files changed, 16 insertions(+), 16 deletions(-)
 rename arch/s390/kvm/{kvm-s390.c => s390.c} (99%)
 rename arch/s390/kvm/{kvm-s390.h => s390.h} (99%)
arch/s390/kvm/Makefile +2 -2
index dac9d53b23d8..961de97b8e80 100644
@@ -5,9 +5,9 @@
 
 include $(srctree)/virt/kvm/Makefile.kvm
 
-ccflags-y := -Ivirt/kvm -Iarch/s390/kvm
+ccflags-y := -I$(src)
 
-kvm-y += kvm-s390.o intercept.o interrupt.o priv.o sigp.o
+kvm-y += s390.o intercept.o interrupt.o priv.o sigp.o
 kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o
 kvm-y += dat.o gmap.o faultin.o
 
arch/s390/kvm/diag.c +1 -1
index 031ab6e5d6c4..09033c8ff1bb 100644
@@ -12,7 +12,7 @@
 #include <linux/kvm_host.h>
 #include <asm/gmap_helpers.h>
 #include <asm/virtio-ccw.h>
-#include "kvm-s390.h"
+#include "s390.h"
 #include "trace.h"
 #include "trace-s390.h"
 #include "gaccess.h"
arch/s390/kvm/gaccess.c +1 -1
index 0d389a302a70..e5c064f263df 100644
@@ -17,7 +17,7 @@
 #include <asm/access-regs.h>
 #include <asm/fault.h>
 #include <asm/dat-bits.h>
-#include "kvm-s390.h"
+#include "s390.h"
 #include "dat.h"
 #include "gmap.h"
 #include "gaccess.h"
arch/s390/kvm/gaccess.h +1 -1
index b5385cec60f4..ef922b3b4990 100644
@@ -14,7 +14,7 @@
 #include <linux/kvm_host.h>
 #include <linux/uaccess.h>
 #include <linux/ptrace.h>
-#include "kvm-s390.h"
+#include "s390.h"
 
 /**
  * kvm_s390_real_to_abs - convert guest real address to guest absolute address
arch/s390/kvm/gmap.c +1 -1
index 3758e4009709..b5b920392378 100644
@@ -21,7 +21,7 @@
 
 #include "dat.h"
 #include "gmap.h"
-#include "kvm-s390.h"
+#include "s390.h"
 #include "faultin.h"
 
 static inline bool kvm_s390_is_in_sie(struct kvm_vcpu *vcpu)
arch/s390/kvm/guestdbg.c +1 -1
index 9a6149e310bb..1bf7e91b7e61 100644
@@ -8,7 +8,7 @@
  */
 #include <linux/kvm_host.h>
 #include <linux/errno.h>
-#include "kvm-s390.h"
+#include "s390.h"
 #include "gaccess.h"
 
 /*
arch/s390/kvm/intercept.c +1 -1
index 1980df61ef30..ca1205dfac8b 100644
@@ -17,7 +17,7 @@
 #include <asm/sysinfo.h>
 #include <asm/uv.h>
 
-#include "kvm-s390.h"
+#include "s390.h"
 #include "gaccess.h"
 #include "trace.h"
 #include "trace-s390.h"
arch/s390/kvm/interrupt.c +1 -1
index 0d9fbe75dc66..9aa786952718 100644
@@ -29,7 +29,7 @@
 #include <asm/nmi.h>
 #include <asm/airq.h>
 #include <asm/tpi.h>
-#include "kvm-s390.h"
+#include "s390.h"
 #include "gaccess.h"
 #include "trace-s390.h"
 #include "pci.h"
arch/s390/kvm/pci.c +1 -1
index 50f5ec79600e..82892e1e03d9 100644
@@ -14,7 +14,7 @@
 #include <asm/pci_io.h>
 #include <asm/sclp.h>
 #include "pci.h"
-#include "kvm-s390.h"
+#include "s390.h"
 
 struct zpci_aift *aift;
 
arch/s390/kvm/priv.c +1 -1
index b1ba24c346ef..b3cb2c2c3aa7 100644
@@ -26,7 +26,7 @@
 #include <asm/ap.h>
 #include <asm/gmap_helpers.h>
 #include "gaccess.h"
-#include "kvm-s390.h"
+#include "s390.h"
 #include "trace.h"
 #include "gmap.h"
 
arch/s390/kvm/pv.c +1 -1
index f549b161b972..7adfdc9b62be 100644
@@ -18,7 +18,7 @@
 #include <linux/sched/mm.h>
 #include <linux/mmu_notifier.h>
 #include <asm/gmap_helpers.h>
-#include "kvm-s390.h"
+#include "s390.h"
 #include "dat.h"
 #include "gaccess.h"
 #include "gmap.h"
arch/s390/kvm/s390.c renamed from arch/s390/kvm/kvm-s390.c +1 -1
similarity index 99%
rename from arch/s390/kvm/kvm-s390.c
rename to arch/s390/kvm/s390.c
index 4faff6625da3..ff09ffc10f0d 100644
@@ -50,7 +50,7 @@
 #include <asm/fpu.h>
 #include <asm/ap.h>
 #include <asm/uv.h>
-#include "kvm-s390.h"
+#include "s390.h"
 #include "gaccess.h"
 #include "gmap.h"
 #include "faultin.h"
arch/s390/kvm/s390.h renamed from arch/s390/kvm/kvm-s390.h +1 -1
similarity index 99%
rename from arch/s390/kvm/kvm-s390.h
rename to arch/s390/kvm/s390.h
index 6d2842fb71a3..e144ca2e6d5e 100644
@@ -452,7 +452,7 @@ void kvm_s390_vsie_destroy(struct kvm *kvm);
 int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);
 int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu);
 
-/* implemented in kvm-s390.c */
+/* implemented in s390.c */
 int kvm_s390_try_set_tod_clock(struct kvm *kvm, const struct kvm_s390_vm_tod_clock *gtod);
 int kvm_s390_store_status_unloaded(struct kvm_vcpu *vcpu, unsigned long addr);
 int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu, unsigned long addr);
arch/s390/kvm/sigp.c +1 -1
index 55c34cb35428..131b3371ef4f 100644
@@ -14,7 +14,7 @@
 #include <linux/slab.h>
 #include <asm/sigp.h>
 #include "gaccess.h"
-#include "kvm-s390.h"
+#include "s390.h"
 #include "trace.h"
 
 static int __sigp_sense(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu,
arch/s390/kvm/vsie.c +1 -1
index f546239d8ff8..cc94ede0621f 100644
@@ -23,7 +23,7 @@
 #include <asm/nmi.h>
 #include <asm/dis.h>
 #include <asm/facility.h>
-#include "kvm-s390.h"
+#include "s390.h"
 #include "gaccess.h"
 #include "gmap.h"
 
Signature · 1 line
2.53.0
author reviewer
#47 lore raw

PATCH v6 15/33 KVM: s390: Move kvm_host definitions to kvm_host_s390

In reply to Steffen Eiden

Rename kvm_host.h to kvm_host_s390.h and kvm_host_types.h to kvm_host_s390_types.h to distinguish s390-specific KVM definitions from the generic kvm_host.h that will be used for shared definitions.

No functional change.

---
 arch/s390/include/asm/kvm_host.h              | 780 +-----------------
 .../asm/{kvm_host.h => kvm_host_s390.h}       |   6 +-
 ...kvm_host_types.h => kvm_host_s390_types.h} |   6 +-
 arch/s390/include/asm/kvm_host_types.h        | 349 +-------
 4 files changed, 12 insertions(+), 1129 deletions(-)
 copy arch/s390/include/asm/{kvm_host.h => kvm_host_s390.h} (99%)
 copy arch/s390/include/asm/{kvm_host_types.h => kvm_host_s390_types.h} (98%)
arch/s390/include/asm/kvm_host.h +2 -778
index b4182ca4435f..e76ceee11ef5 100644
@@ -1,784 +1,8 @@
 /* SPDX-License-Identifier: GPL-2.0 */
-/*
- * definition for kernel virtual machines on s390
- *
- * Copyright IBM Corp. 2008, 2018
- *
- *    Author(s): Carsten Otte <[email protected]>
- */
-
 
 #ifndef ASM_KVM_HOST_H
 #define ASM_KVM_HOST_H
 
-#include <linux/types.h>
-#include <linux/hrtimer.h>
-#include <linux/interrupt.h>
-#include <linux/kvm_types.h>
-#include <linux/kvm.h>
-#include <linux/seqlock.h>
-#include <linux/module.h>
-#include <linux/pci.h>
-#include <linux/mmu_notifier.h>
-#include <asm/kvm_host_types.h>
-#include <asm/debug.h>
-#include <asm/cpu.h>
-#include <asm/fpu.h>
-#include <asm/isc.h>
-#include <asm/guarded_storage.h>
-
-#define KVM_HAVE_MMU_RWLOCK
-#define KVM_MAX_VCPUS 255
-
-#define KVM_INTERNAL_MEM_SLOTS 1
-
-/*
- * These seem to be used for allocating ->chip in the routing table, which we
- * don't use. 1 is as small as we can get to reduce the needed memory. If we
- * need to look at ->chip later on, we'll need to revisit this.
- */
-#define KVM_NR_IRQCHIPS 1
-#define KVM_IRQCHIP_NUM_PINS 1
-#define KVM_HALT_POLL_NS_DEFAULT 50000
-
-/* s390-specific vcpu->requests bit members */
-#define KVM_REQ_ENABLE_IBS	KVM_ARCH_REQ(0)
-#define KVM_REQ_DISABLE_IBS	KVM_ARCH_REQ(1)
-#define KVM_REQ_ICPT_OPEREXC	KVM_ARCH_REQ(2)
-#define KVM_REQ_START_MIGRATION KVM_ARCH_REQ(3)
-#define KVM_REQ_STOP_MIGRATION  KVM_ARCH_REQ(4)
-#define KVM_REQ_VSIE_RESTART	KVM_ARCH_REQ(5)
-#define KVM_REQ_REFRESH_GUEST_PREFIX	\
-	KVM_ARCH_REQ_FLAGS(6, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
-
-struct kvm_vcpu_stat {
-	struct kvm_vcpu_stat_generic generic;
-	u64 exit_userspace;
-	u64 exit_null;
-	u64 exit_external_request;
-	u64 exit_io_request;
-	u64 exit_external_interrupt;
-	u64 exit_stop_request;
-	u64 exit_validity;
-	u64 exit_instruction;
-	u64 exit_pei;
-	u64 halt_no_poll_steal;
-	u64 instruction_lctl;
-	u64 instruction_lctlg;
-	u64 instruction_stctl;
-	u64 instruction_stctg;
-	u64 exit_program_interruption;
-	u64 exit_instr_and_program;
-	u64 exit_operation_exception;
-	u64 deliver_ckc;
-	u64 deliver_cputm;
-	u64 deliver_external_call;
-	u64 deliver_emergency_signal;
-	u64 deliver_service_signal;
-	u64 deliver_virtio;
-	u64 deliver_stop_signal;
-	u64 deliver_prefix_signal;
-	u64 deliver_restart_signal;
-	u64 deliver_program;
-	u64 deliver_io;
-	u64 deliver_machine_check;
-	u64 exit_wait_state;
-	u64 inject_ckc;
-	u64 inject_cputm;
-	u64 inject_external_call;
-	u64 inject_emergency_signal;
-	u64 inject_mchk;
-	u64 inject_pfault_init;
-	u64 inject_program;
-	u64 inject_restart;
-	u64 inject_set_prefix;
-	u64 inject_stop_signal;
-	u64 instruction_epsw;
-	u64 instruction_gs;
-	u64 instruction_io_other;
-	u64 instruction_lpsw;
-	u64 instruction_lpswe;
-	u64 instruction_lpswey;
-	u64 instruction_pfmf;
-	u64 instruction_ptff;
-	u64 instruction_sck;
-	u64 instruction_sckpf;
-	u64 instruction_stidp;
-	u64 instruction_spx;
-	u64 instruction_stpx;
-	u64 instruction_stap;
-	u64 instruction_iske;
-	u64 instruction_ri;
-	u64 instruction_rrbe;
-	u64 instruction_sske;
-	u64 instruction_ipte_interlock;
-	u64 instruction_stsi;
-	u64 instruction_stfl;
-	u64 instruction_tb;
-	u64 instruction_tpi;
-	u64 instruction_tprot;
-	u64 instruction_tsch;
-	u64 instruction_sie;
-	u64 instruction_essa;
-	u64 instruction_sthyi;
-	u64 instruction_sigp_sense;
-	u64 instruction_sigp_sense_running;
-	u64 instruction_sigp_external_call;
-	u64 instruction_sigp_emergency;
-	u64 instruction_sigp_cond_emergency;
-	u64 instruction_sigp_start;
-	u64 instruction_sigp_stop;
-	u64 instruction_sigp_stop_store_status;
-	u64 instruction_sigp_store_status;
-	u64 instruction_sigp_store_adtl_status;
-	u64 instruction_sigp_arch;
-	u64 instruction_sigp_prefix;
-	u64 instruction_sigp_restart;
-	u64 instruction_sigp_init_cpu_reset;
-	u64 instruction_sigp_cpu_reset;
-	u64 instruction_sigp_unknown;
-	u64 instruction_diagnose_10;
-	u64 instruction_diagnose_44;
-	u64 instruction_diagnose_9c;
-	u64 diag_9c_ignored;
-	u64 diag_9c_forward;
-	u64 instruction_diagnose_258;
-	u64 instruction_diagnose_308;
-	u64 instruction_diagnose_500;
-	u64 instruction_diagnose_other;
-	u64 pfault_sync;
-	u64 signal_exits;
-};
-
-#define PGM_OPERATION			0x01
-#define PGM_PRIVILEGED_OP		0x02
-#define PGM_EXECUTE			0x03
-#define PGM_PROTECTION			0x04
-#define PGM_ADDRESSING			0x05
-#define PGM_SPECIFICATION		0x06
-#define PGM_DATA			0x07
-#define PGM_FIXED_POINT_OVERFLOW	0x08
-#define PGM_FIXED_POINT_DIVIDE		0x09
-#define PGM_DECIMAL_OVERFLOW		0x0a
-#define PGM_DECIMAL_DIVIDE		0x0b
-#define PGM_HFP_EXPONENT_OVERFLOW	0x0c
-#define PGM_HFP_EXPONENT_UNDERFLOW	0x0d
-#define PGM_HFP_SIGNIFICANCE		0x0e
-#define PGM_HFP_DIVIDE			0x0f
-#define PGM_SEGMENT_TRANSLATION		0x10
-#define PGM_PAGE_TRANSLATION		0x11
-#define PGM_TRANSLATION_SPEC		0x12
-#define PGM_SPECIAL_OPERATION		0x13
-#define PGM_OPERAND			0x15
-#define PGM_TRACE_TABEL			0x16
-#define PGM_VECTOR_PROCESSING		0x1b
-#define PGM_SPACE_SWITCH		0x1c
-#define PGM_HFP_SQUARE_ROOT		0x1d
-#define PGM_PC_TRANSLATION_SPEC		0x1f
-#define PGM_AFX_TRANSLATION		0x20
-#define PGM_ASX_TRANSLATION		0x21
-#define PGM_LX_TRANSLATION		0x22
-#define PGM_EX_TRANSLATION		0x23
-#define PGM_PRIMARY_AUTHORITY		0x24
-#define PGM_SECONDARY_AUTHORITY		0x25
-#define PGM_LFX_TRANSLATION		0x26
-#define PGM_LSX_TRANSLATION		0x27
-#define PGM_ALET_SPECIFICATION		0x28
-#define PGM_ALEN_TRANSLATION		0x29
-#define PGM_ALE_SEQUENCE		0x2a
-#define PGM_ASTE_VALIDITY		0x2b
-#define PGM_ASTE_SEQUENCE		0x2c
-#define PGM_EXTENDED_AUTHORITY		0x2d
-#define PGM_LSTE_SEQUENCE		0x2e
-#define PGM_ASTE_INSTANCE		0x2f
-#define PGM_STACK_FULL			0x30
-#define PGM_STACK_EMPTY			0x31
-#define PGM_STACK_SPECIFICATION		0x32
-#define PGM_STACK_TYPE			0x33
-#define PGM_STACK_OPERATION		0x34
-#define PGM_ASCE_TYPE			0x38
-#define PGM_REGION_FIRST_TRANS		0x39
-#define PGM_REGION_SECOND_TRANS		0x3a
-#define PGM_REGION_THIRD_TRANS		0x3b
-#define PGM_SECURE_STORAGE_ACCESS	0x3d
-#define PGM_NON_SECURE_STORAGE_ACCESS	0x3e
-#define PGM_SECURE_STORAGE_VIOLATION	0x3f
-#define PGM_MONITOR			0x40
-#define PGM_PER				0x80
-#define PGM_CRYPTO_OPERATION		0x119
-
-/* irq types in ascend order of priorities */
-enum irq_types {
-	IRQ_PEND_SET_PREFIX = 0,
-	IRQ_PEND_RESTART,
-	IRQ_PEND_SIGP_STOP,
-	IRQ_PEND_IO_ISC_7,
-	IRQ_PEND_IO_ISC_6,
-	IRQ_PEND_IO_ISC_5,
-	IRQ_PEND_IO_ISC_4,
-	IRQ_PEND_IO_ISC_3,
-	IRQ_PEND_IO_ISC_2,
-	IRQ_PEND_IO_ISC_1,
-	IRQ_PEND_IO_ISC_0,
-	IRQ_PEND_VIRTIO,
-	IRQ_PEND_PFAULT_DONE,
-	IRQ_PEND_PFAULT_INIT,
-	IRQ_PEND_EXT_HOST,
-	IRQ_PEND_EXT_SERVICE,
-	IRQ_PEND_EXT_SERVICE_EV,
-	IRQ_PEND_EXT_TIMING,
-	IRQ_PEND_EXT_CPU_TIMER,
-	IRQ_PEND_EXT_CLOCK_COMP,
-	IRQ_PEND_EXT_EXTERNAL,
-	IRQ_PEND_EXT_EMERGENCY,
-	IRQ_PEND_EXT_MALFUNC,
-	IRQ_PEND_EXT_IRQ_KEY,
-	IRQ_PEND_MCHK_REP,
-	IRQ_PEND_PROG,
-	IRQ_PEND_SVC,
-	IRQ_PEND_MCHK_EX,
-	IRQ_PEND_COUNT
-};
-
-/* We have 2M for virtio device descriptor pages. Smallest amount of
- * memory per page is 24 bytes (1 queue), so (2048*1024) / 24 = 87381
- */
-#define KVM_S390_MAX_VIRTIO_IRQS 87381
-
-/*
- * Repressible (non-floating) machine check interrupts
- * subclass bits in MCIC
- */
-#define MCHK_EXTD_BIT 58
-#define MCHK_DEGR_BIT 56
-#define MCHK_WARN_BIT 55
-#define MCHK_REP_MASK ((1UL << MCHK_DEGR_BIT) | \
-		       (1UL << MCHK_EXTD_BIT) | \
-		       (1UL << MCHK_WARN_BIT))
-
-/* Exigent machine check interrupts subclass bits in MCIC */
-#define MCHK_SD_BIT 63
-#define MCHK_PD_BIT 62
-#define MCHK_EX_MASK ((1UL << MCHK_SD_BIT) | (1UL << MCHK_PD_BIT))
-
-#define IRQ_PEND_EXT_MASK ((1UL << IRQ_PEND_EXT_IRQ_KEY)    | \
-			   (1UL << IRQ_PEND_EXT_CLOCK_COMP) | \
-			   (1UL << IRQ_PEND_EXT_CPU_TIMER)  | \
-			   (1UL << IRQ_PEND_EXT_MALFUNC)    | \
-			   (1UL << IRQ_PEND_EXT_EMERGENCY)  | \
-			   (1UL << IRQ_PEND_EXT_EXTERNAL)   | \
-			   (1UL << IRQ_PEND_EXT_TIMING)     | \
-			   (1UL << IRQ_PEND_EXT_HOST)       | \
-			   (1UL << IRQ_PEND_EXT_SERVICE)    | \
-			   (1UL << IRQ_PEND_EXT_SERVICE_EV) | \
-			   (1UL << IRQ_PEND_VIRTIO)         | \
-			   (1UL << IRQ_PEND_PFAULT_INIT)    | \
-			   (1UL << IRQ_PEND_PFAULT_DONE))
-
-#define IRQ_PEND_IO_MASK ((1UL << IRQ_PEND_IO_ISC_0) | \
-			  (1UL << IRQ_PEND_IO_ISC_1) | \
-			  (1UL << IRQ_PEND_IO_ISC_2) | \
-			  (1UL << IRQ_PEND_IO_ISC_3) | \
-			  (1UL << IRQ_PEND_IO_ISC_4) | \
-			  (1UL << IRQ_PEND_IO_ISC_5) | \
-			  (1UL << IRQ_PEND_IO_ISC_6) | \
-			  (1UL << IRQ_PEND_IO_ISC_7))
-
-#define IRQ_PEND_MCHK_MASK ((1UL << IRQ_PEND_MCHK_REP) | \
-			    (1UL << IRQ_PEND_MCHK_EX))
-
-#define IRQ_PEND_EXT_II_MASK ((1UL << IRQ_PEND_EXT_CPU_TIMER)  | \
-			      (1UL << IRQ_PEND_EXT_CLOCK_COMP) | \
-			      (1UL << IRQ_PEND_EXT_EMERGENCY)  | \
-			      (1UL << IRQ_PEND_EXT_EXTERNAL)   | \
-			      (1UL << IRQ_PEND_EXT_SERVICE)    | \
-			      (1UL << IRQ_PEND_EXT_SERVICE_EV))
-
-struct kvm_s390_interrupt_info {
-	struct list_head list;
-	u64	type;
-	union {
-		struct kvm_s390_io_info io;
-		struct kvm_s390_ext_info ext;
-		struct kvm_s390_pgm_info pgm;
-		struct kvm_s390_emerg_info emerg;
-		struct kvm_s390_extcall_info extcall;
-		struct kvm_s390_prefix_info prefix;
-		struct kvm_s390_stop_info stop;
-		struct kvm_s390_mchk_info mchk;
-	};
-};
-
-struct kvm_s390_irq_payload {
-	struct kvm_s390_io_info io;
-	struct kvm_s390_ext_info ext;
-	struct kvm_s390_pgm_info pgm;
-	struct kvm_s390_emerg_info emerg;
-	struct kvm_s390_extcall_info extcall;
-	struct kvm_s390_prefix_info prefix;
-	struct kvm_s390_stop_info stop;
-	struct kvm_s390_mchk_info mchk;
-};
-
-struct kvm_s390_local_interrupt {
-	spinlock_t lock;
-	DECLARE_BITMAP(sigp_emerg_pending, KVM_MAX_VCPUS);
-	struct kvm_s390_irq_payload irq;
-	unsigned long pending_irqs;
-};
-
-#define FIRQ_LIST_IO_ISC_0 0
-#define FIRQ_LIST_IO_ISC_1 1
-#define FIRQ_LIST_IO_ISC_2 2
-#define FIRQ_LIST_IO_ISC_3 3
-#define FIRQ_LIST_IO_ISC_4 4
-#define FIRQ_LIST_IO_ISC_5 5
-#define FIRQ_LIST_IO_ISC_6 6
-#define FIRQ_LIST_IO_ISC_7 7
-#define FIRQ_LIST_PFAULT   8
-#define FIRQ_LIST_VIRTIO   9
-#define FIRQ_LIST_COUNT   10
-#define FIRQ_CNTR_IO       0
-#define FIRQ_CNTR_SERVICE  1
-#define FIRQ_CNTR_VIRTIO   2
-#define FIRQ_CNTR_PFAULT   3
-#define FIRQ_MAX_COUNT     4
-
-/* mask the AIS mode for a given ISC */
-#define AIS_MODE_MASK(isc) (0x80 >> isc)
-
-#define KVM_S390_AIS_MODE_ALL    0
-#define KVM_S390_AIS_MODE_SINGLE 1
-
-struct kvm_s390_float_interrupt {
-	unsigned long pending_irqs;
-	unsigned long masked_irqs;
-	spinlock_t lock;
-	struct list_head lists[FIRQ_LIST_COUNT];
-	int counters[FIRQ_MAX_COUNT];
-	struct kvm_s390_mchk_info mchk;
-	struct kvm_s390_ext_info srv_signal;
-	int last_sleep_cpu;
-	spinlock_t ais_lock;
-	u8 simm;
-	u8 nimm;
-};
-
-struct kvm_hw_wp_info_arch {
-	unsigned long addr;
-	unsigned long phys_addr;
-	int len;
-	char *old_data;
-};
-
-struct kvm_hw_bp_info_arch {
-	unsigned long addr;
-	int len;
-};
-
-/*
- * Only the upper 16 bits of kvm_guest_debug->control are arch specific.
- * Further KVM_GUESTDBG flags which an be used from userspace can be found in
- * arch/s390/include/uapi/asm/kvm.h
- */
-#define KVM_GUESTDBG_EXIT_PENDING 0x10000000
-
-#define guestdbg_enabled(vcpu) \
-		(vcpu->guest_debug & KVM_GUESTDBG_ENABLE)
-#define guestdbg_sstep_enabled(vcpu) \
-		(vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
-#define guestdbg_hw_bp_enabled(vcpu) \
-		(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)
-#define guestdbg_exit_pending(vcpu) (guestdbg_enabled(vcpu) && \
-		(vcpu->guest_debug & KVM_GUESTDBG_EXIT_PENDING))
-
-#define KVM_GUESTDBG_VALID_MASK \
-		(KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLESTEP |\
-		KVM_GUESTDBG_USE_HW_BP | KVM_GUESTDBG_EXIT_PENDING)
-
-struct kvm_guestdbg_info_arch {
-	unsigned long cr0;
-	unsigned long cr9;
-	unsigned long cr10;
-	unsigned long cr11;
-	struct kvm_hw_bp_info_arch *hw_bp_info;
-	struct kvm_hw_wp_info_arch *hw_wp_info;
-	int nr_hw_bp;
-	int nr_hw_wp;
-	unsigned long last_bp;
-};
-
-struct kvm_s390_pv_vcpu {
-	u64 handle;
-	unsigned long stor_base;
-};
-
-struct kvm_vcpu_arch {
-	struct kvm_s390_sie_block *sie_block;
-	/* if vsie is active, currently executed shadow sie control block */
-	struct kvm_s390_sie_block *vsie_block;
-	unsigned int      host_acrs[NUM_ACRS];
-	struct gs_cb      *host_gscb;
-	struct kvm_s390_local_interrupt local_int;
-	struct hrtimer    ckc_timer;
-	struct kvm_s390_pgm_info pgm;
-	struct gmap *gmap;
-	struct kvm_guestdbg_info_arch guestdbg;
-	unsigned long pfault_token;
-	unsigned long pfault_select;
-	unsigned long pfault_compare;
-	bool cputm_enabled;
-	/*
-	 * The seqcount protects updates to cputm_start and sie_block.cputm,
-	 * this way we can have non-blocking reads with consistent values.
-	 * Only the owning VCPU thread (vcpu->cpu) is allowed to change these
-	 * values and to start/stop/enable/disable cpu timer accounting.
-	 */
-	seqcount_t cputm_seqcount;
-	__u64 cputm_start;
-	bool gs_enabled;
-	bool skey_enabled;
-	/* Indicator if the access registers have been loaded from guest */
-	bool acrs_loaded;
-	bool initialized;
-	struct kvm_s390_pv_vcpu pv;
-	union diag318_info diag318_info;
-	struct kvm_s390_mmu_cache *mc;
-};
-
-struct kvm_vm_stat {
-	struct kvm_vm_stat_generic generic;
-	u64 inject_io;
-	u64 io_390_adapter_map;
-	u64 io_390_adapter_unmap;
-	u64 io_390_inatomic;
-	u64 io_flic_inject_airq;
-	u64 io_set_adapter_int;
-	u64 io_390_inatomic_no_inject;
-	u64 inject_float_mchk;
-	u64 inject_pfault_done;
-	u64 inject_service_signal;
-	u64 inject_virtio;
-	u64 aen_forward;
-	u64 gmap_shadow_create;
-	u64 gmap_shadow_reuse;
-	u64 gmap_shadow_r1_entry;
-	u64 gmap_shadow_r2_entry;
-	u64 gmap_shadow_r3_entry;
-	u64 gmap_shadow_sg_entry;
-	u64 gmap_shadow_pg_entry;
-};
-
-struct kvm_arch_memory_slot {
-};
-
-struct s390_map_info {
-	struct list_head list;
-	__u64 guest_addr;
-	__u64 addr;
-	struct page *page;
-	/*
-	 * True if the page is long-term pinned. False if long-term pinning
-	 * failed and this entry exists only to preserve MAP/UNMAP symmetry.
-	 */
-	bool pinned;
-};
-
-struct s390_io_adapter {
-	unsigned int id;
-	int isc;
-	bool maskable;
-	bool masked;
-	bool swap;
-	bool suppressible;
-	spinlock_t maps_lock;
-	struct list_head maps;
-	unsigned int nr_maps;
-};
-
-#define MAX_S390_IO_ADAPTERS ((MAX_ISC + 1) * 8)
-#define MAX_S390_ADAPTER_MAPS 256
-
-/* maximum size of facilities and facility mask is 2k bytes */
-#define S390_ARCH_FAC_LIST_SIZE_BYTE (1<<11)
-#define S390_ARCH_FAC_LIST_SIZE_U64 \
-	(S390_ARCH_FAC_LIST_SIZE_BYTE / sizeof(u64))
-#define S390_ARCH_FAC_MASK_SIZE_BYTE S390_ARCH_FAC_LIST_SIZE_BYTE
-#define S390_ARCH_FAC_MASK_SIZE_U64 \
-	(S390_ARCH_FAC_MASK_SIZE_BYTE / sizeof(u64))
-
-struct kvm_s390_cpu_model {
-	/* facility mask supported by kvm & hosting machine */
-	__u64 fac_mask[S390_ARCH_FAC_MASK_SIZE_U64];
-	struct kvm_s390_vm_cpu_subfunc subfuncs;
-	/* facility list requested by guest (in dma page) */
-	__u64 *fac_list;
-	u64 cpuid;
-	unsigned short ibc;
-	/* subset of available UV-features for pv-guests enabled by user space */
-	struct kvm_s390_vm_cpu_uv_feat uv_feat_guest;
-};
-
-#define S390_ARCH_FAC_FORMAT_2 2
-struct kvm_s390_flcb2 {
-	union {
-		struct {
-			u8 reserved0[7];
-			u8 length;
-		};
-		u64 header_val;
-	};
-	u64 facilities[S390_ARCH_FAC_LIST_SIZE_U64];
-};
-
-typedef int (*crypto_hook)(struct kvm_vcpu *vcpu);
-
-struct kvm_s390_crypto {
-	struct kvm_s390_crypto_cb *crycb;
-	struct rw_semaphore pqap_hook_rwsem;
-	crypto_hook *pqap_hook;
-	__u32 crycbd;
-	__u8 aes_kw;
-	__u8 dea_kw;
-	__u8 apie;
-};
-
-#define APCB0_MASK_SIZE 1
-struct kvm_s390_apcb0 {
-	__u64 apm[APCB0_MASK_SIZE];		/* 0x0000 */
-	__u64 aqm[APCB0_MASK_SIZE];		/* 0x0008 */
-	__u64 adm[APCB0_MASK_SIZE];		/* 0x0010 */
-	__u64 reserved18;			/* 0x0018 */
-};
-
-#define APCB1_MASK_SIZE 4
-struct kvm_s390_apcb1 {
-	__u64 apm[APCB1_MASK_SIZE];		/* 0x0000 */
-	__u64 aqm[APCB1_MASK_SIZE];		/* 0x0020 */
-	__u64 adm[APCB1_MASK_SIZE];		/* 0x0040 */
-	__u64 reserved60[4];			/* 0x0060 */
-};
-
-struct kvm_s390_crypto_cb {
-	struct kvm_s390_apcb0 apcb0;		/* 0x0000 */
-	__u8   reserved20[0x0048 - 0x0020];	/* 0x0020 */
-	__u8   dea_wrapping_key_mask[24];	/* 0x0048 */
-	__u8   aes_wrapping_key_mask[32];	/* 0x0060 */
-	struct kvm_s390_apcb1 apcb1;		/* 0x0080 */
-};
-
-struct kvm_s390_gisa {
-	union {
-		struct { /* common to all formats */
-			u32 next_alert;
-			u8  ipm;
-			u8  reserved01[2];
-			u8  iam;
-		};
-		struct { /* format 0 */
-			u32 next_alert;
-			u8  ipm;
-			u8  reserved01;
-			u8  : 6;
-			u8  g : 1;
-			u8  c : 1;
-			u8  iam;
-			u8  reserved02[4];
-			u32 airq_count;
-		} g0;
-		struct { /* format 1 */
-			u32 next_alert;
-			u8  ipm;
-			u8  simm;
-			u8  nimm;
-			u8  iam;
-			u8  aism[8];
-			u8  : 6;
-			u8  g : 1;
-			u8  c : 1;
-			u8  reserved03[11];
-			u32 airq_count;
-		} g1;
-		struct {
-			u64 word[4];
-		} u64;
-	};
-};
-
-struct kvm_s390_gib {
-	u32 alert_list_origin;
-	u32 reserved01;
-	u8:5;
-	u8  nisc:3;
-	u8  reserved03[3];
-	u32 reserved04[5];
-};
-
-/*
- * sie_page2 has to be allocated as DMA because fac_list, crycb and
- * gisa need 31bit addresses in the sie control block.
- */
-struct sie_page2 {
-	__u64 fac_list[S390_ARCH_FAC_LIST_SIZE_U64];	/* 0x0000 */
-	struct kvm_s390_crypto_cb crycb;		/* 0x0800 */
-	struct kvm_s390_gisa gisa;			/* 0x0900 */
-	struct kvm *kvm;				/* 0x0920 */
-	u8 reserved928[0x1000 - 0x928];			/* 0x0928 */
-};
-
-struct vsie_page;
-
-struct kvm_s390_vsie {
-	struct mutex mutex;
-	struct radix_tree_root addr_to_page;
-	int page_count;
-	int next;
-	struct vsie_page *pages[KVM_MAX_VCPUS];
-};
-
-struct kvm_s390_gisa_iam {
-	u8 mask;
-	spinlock_t ref_lock;
-	u32 ref_count[MAX_ISC + 1];
-};
-
-struct kvm_s390_gisa_interrupt {
-	struct kvm_s390_gisa *origin;
-	struct kvm_s390_gisa_iam alert;
-	struct hrtimer timer;
-	u64 expires;
-	DECLARE_BITMAP(kicked_mask, KVM_MAX_VCPUS);
-};
-
-struct kvm_s390_pv {
-	u64 handle;
-	u64 guest_len;
-	unsigned long stor_base;
-	void *stor_var;
-	bool dumping;
-	void *set_aside;
-	struct list_head need_cleanup;
-	struct mmu_notifier mmu_notifier;
-	/* Protects against concurrent import-like operations */
-	struct mutex import_lock;
-};
-
-struct kvm_s390_mmu_cache;
-
-struct kvm_arch {
-	struct esca_block *sca;
-	debug_info_t *dbf;
-	struct kvm_s390_float_interrupt float_int;
-	struct kvm_device *flic;
-	struct gmap *gmap;
-	unsigned long mem_limit;
-	int css_support;
-	int use_irqchip;
-	int use_cmma;
-	int use_pfmfi;
-	int use_skf;
-	int use_zpci_interp;
-	int user_cpu_state_ctrl;
-	int user_sigp;
-	int user_stsi;
-	int user_instr0;
-	int user_operexec;
-	int allow_vsie_esamode;
-	struct s390_io_adapter *adapters[MAX_S390_IO_ADAPTERS];
-	wait_queue_head_t ipte_wq;
-	int ipte_lock_count;
-	struct mutex ipte_mutex;
-	spinlock_t start_stop_lock;
-	struct sie_page2 *sie_page2;
-	struct kvm_s390_cpu_model model;
-	struct kvm_s390_crypto crypto;
-	struct kvm_s390_vsie vsie;
-	u8 epdx;
-	u64 epoch;
-	int migration_mode;
-	atomic64_t cmma_dirty_pages;
-	/* subset of available cpu features enabled by user space */
-	DECLARE_BITMAP(cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS);
-	/* indexed by vcpu_idx */
-	DECLARE_BITMAP(idle_mask, KVM_MAX_VCPUS);
-	struct kvm_s390_gisa_interrupt gisa_int;
-	struct kvm_s390_pv pv;
-	struct list_head kzdev_list;
-	spinlock_t kzdev_list_lock;
-	struct kvm_s390_mmu_cache *mc;
-};
-
-#define KVM_HVA_ERR_BAD		(-1UL)
-#define KVM_HVA_ERR_RO_BAD	(-2UL)
-
-static inline bool kvm_is_error_hva(unsigned long addr)
-{
-	return IS_ERR_VALUE(addr);
-}
-
-#define ASYNC_PF_PER_VCPU	64
-struct kvm_arch_async_pf {
-	unsigned long pfault_token;
-};
-
-bool kvm_arch_can_dequeue_async_page_present(struct kvm_vcpu *vcpu);
-
-void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu,
-			       struct kvm_async_pf *work);
-
-bool kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
-				     struct kvm_async_pf *work);
-
-void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
-				 struct kvm_async_pf *work);
-
-static inline void kvm_arch_async_page_present_queued(struct kvm_vcpu *vcpu) {}
-
-void kvm_arch_crypto_clear_masks(struct kvm *kvm);
-void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm,
-			       unsigned long *aqm, unsigned long *adm);
-
-#define SIE64_RETURN_NORMAL	0
-#define SIE64_RETURN_MCCK	1
-
-int __sie64a(phys_addr_t sie_block_phys, struct kvm_s390_sie_block *sie_block, u64 *rsa,
-	     unsigned long gasce);
-
-static inline int sie64a(struct kvm_s390_sie_block *sie_block, u64 *rsa, unsigned long gasce)
-{
-	return __sie64a(virt_to_phys(sie_block), sie_block, rsa, gasce);
-}
-
-extern char sie_exit;
-
-bool kvm_s390_pv_is_protected(struct kvm *kvm);
-bool kvm_s390_pv_cpu_is_protected(struct kvm_vcpu *vcpu);
-
-extern int kvm_s390_enter_exit_sie(struct kvm_s390_sie_block *scb,
-				   u64 *gprs, unsigned long gasce);
-
-extern int kvm_s390_gisc_register(struct kvm *kvm, u32 gisc);
-extern int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc);
-
-bool kvm_s390_is_gpa_in_memslot(struct kvm *kvm, gpa_t gpa);
-
-static inline void kvm_arch_free_memslot(struct kvm *kvm,
-					 struct kvm_memory_slot *slot) {}
-static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {}
-static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {}
-static inline void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
-		struct kvm_memory_slot *slot) {}
-static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {}
-static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}
-
-#define __KVM_HAVE_ARCH_VM_FREE
-void kvm_arch_free_vm(struct kvm *kvm);
-
-struct zpci_kvm_hook {
-	int (*kvm_register)(void *opaque, struct kvm *kvm);
-	void (*kvm_unregister)(void *opaque);
-};
-
-extern struct zpci_kvm_hook zpci_kvm_hook;
+#include <asm/kvm_host_s390.h>
 
-#endif
+#endif /* ASM_KVM_HOST_H */
arch/s390/include/asm/kvm_host_s390.h renamed from arch/s390/include/asm/kvm_host.h +3 -3
similarity index 99%
copy from arch/s390/include/asm/kvm_host.h
copy to arch/s390/include/asm/kvm_host_s390.h
index b4182ca4435f..0c4e061d7437 100644
@@ -8,8 +8,8 @@
  */
 
 
-#ifndef ASM_KVM_HOST_H
-#define ASM_KVM_HOST_H
+#ifndef ASM_KVM_HOST_S390_H
+#define ASM_KVM_HOST_S390_H
 
 #include <linux/types.h>
 #include <linux/hrtimer.h>
@@ -781,4 +781,4 @@ struct zpci_kvm_hook {
 
 extern struct zpci_kvm_hook zpci_kvm_hook;
 
-#endif
+#endif /* ASM_KVM_HOST_S390_H */
arch/s390/include/asm/kvm_host_s390_types.h renamed from arch/s390/include/asm/kvm_host_types.h +3 -3
similarity index 98%
copy from arch/s390/include/asm/kvm_host_types.h
copy to arch/s390/include/asm/kvm_host_s390_types.h
index ac82dd09fce5..9e348a530421 100644
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 
-#ifndef _ASM_KVM_HOST_TYPES_H
-#define _ASM_KVM_HOST_TYPES_H
+#ifndef _ASM_KVM_HOST_S390_TYPES_H
+#define _ASM_KVM_HOST_S390_TYPES_H
 
 #include <linux/atomic.h>
 #include <linux/types.h>
@@ -346,4 +346,4 @@ struct sie_page {
 	__u8 reserved700[2304];		/* 0x0700 */
 };
 
-#endif /* _ASM_KVM_HOST_TYPES_H */
+#endif /* _ASM_KVM_HOST_S390_TYPES_H */
arch/s390/include/asm/kvm_host_types.h +4 -345

353 lines not on this page · raw message

Signature · 1 line
2.53.0
author reviewer
#65 lore raw

PATCH v6 21/33 KVM: s390: gmap: Make prefix handling optional

In reply to Steffen Eiden

Guard guest prefix handling behind KVM_S390_MANAGES_S390_GUEST. This enables other KVM implementations to use gmap without implementing prefix handling. The prefix handling is integrated deeply in the gmap implementation. Therefore, provide safe default implementations for the guarded functions.

No functional changes.

---
 arch/s390/kvm/gmap/dat.c  |  2 +-
 arch/s390/kvm/gmap/dat.h  |  9 +++++++++
 arch/s390/kvm/gmap/gmap.c | 12 +++++++-----
 arch/s390/kvm/gmap/gmap.h |  9 ++++++++-
 4 files changed, 25 insertions(+), 7 deletions(-)
arch/s390/kvm/gmap/dat.c +1 -1
index 43ebafb56ce5..3038eae1cfcc 100644
@@ -1011,6 +1011,7 @@ bool dat_test_age_gfn(union asce asce, gfn_t start, gfn_t end)
 	return _dat_walk_gfn_range(start, end, asce, &test_age_ops, 0, NULL) > 0;
 }
 
+#if KVM_S390_MANAGES_S390_GUEST
 static long dat_set_pn_crste(union crste *crstep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
 {
 	union crste newcrste, oldcrste;
@@ -1059,7 +1060,6 @@ int dat_set_prefix_notif_bit(union asce asce, gfn_t gfn)
 	return 0;
 }
 
-#if KVM_S390_MANAGES_S390_GUEST
 /**
  * dat_perform_essa() - Perform ESSA actions on the PGSTE.
  * @asce: The asce to operate on.
arch/s390/kvm/gmap/dat.h +9 -0
index 4f11f9bbd83a..e452c141b841 100644
@@ -549,7 +549,16 @@ void dat_set_ptval(struct page_table *table, struct ptval_param param, unsigned
 
 int dat_set_slot(struct kvm_s390_mmu_cache *mc, union asce asce, gfn_t start, gfn_t end,
 		 u16 type, u16 param);
+
+#if KVM_S390_MANAGES_S390_GUEST
 int dat_set_prefix_notif_bit(union asce asce, gfn_t gfn);
+#else
+static inline int dat_set_prefix_notif_bit(union asce asce, gfn_t gfn)
+{
+	return 0;
+}
+#endif /* KVM_S390_MANAGES_S390_GUEST */
+
 bool dat_test_age_gfn(union asce asce, gfn_t start, gfn_t end);
 
 #if KVM_S390_MANAGES_S390_GUEST
arch/s390/kvm/gmap/gmap.c +7 -5
index 86513f653850..4968330e9553 100644
@@ -24,11 +24,6 @@
 #include "s390.h"
 #include "faultin.h"
 
-static inline bool kvm_s390_is_in_sie(struct kvm_vcpu *vcpu)
-{
-	return vcpu->arch.sie_block->prog0c & PROG_IN_SIE;
-}
-
 static int gmap_limit_to_type(gfn_t limit)
 {
 	if (!limit)
@@ -256,6 +251,12 @@ int s390_replace_asce(struct gmap *gmap)
 	return 0;
 }
 
+#if KVM_S390_MANAGES_S390_GUEST
+static inline bool kvm_s390_is_in_sie(struct kvm_vcpu *vcpu)
+{
+	return vcpu->arch.sie_block->prog0c & PROG_IN_SIE;
+}
+
 bool _gmap_unmap_prefix(struct gmap *gmap, gfn_t gfn, gfn_t end, bool hint)
 {
 	struct kvm *kvm = gmap->kvm;
@@ -278,6 +279,7 @@ bool _gmap_unmap_prefix(struct gmap *gmap, gfn_t gfn, gfn_t end, bool hint)
 	}
 	return true;
 }
+#endif /* KVM_S390_MANAGES_S390_GUEST */
 
 struct clear_young_pte_priv {
 	struct gmap *gmap;
arch/s390/kvm/gmap/gmap.h +8 -1
index 6f3bf11d2166..8f47f29c89fd 100644
@@ -85,7 +85,6 @@ struct gmap_cache {
 	for (pos = (head); n = pos ? pos->next : NULL, pos; pos = n)
 
 int s390_replace_asce(struct gmap *gmap);
-bool _gmap_unmap_prefix(struct gmap *gmap, gfn_t gfn, gfn_t end, bool hint);
 bool gmap_age_gfn(struct gmap *gmap, gfn_t start, gfn_t end);
 bool gmap_unmap_gfn_range(struct gmap *gmap, struct kvm_memory_slot *slot, gfn_t start, gfn_t end);
 int gmap_try_fixup_minor(struct gmap *gmap, struct guest_fault *fault);
@@ -163,6 +162,14 @@ static inline void gmap_handle_vsie_unshadow_event(struct gmap *parent, gfn_t gf
 		_gmap_handle_vsie_unshadow_event(parent, gfn);
 }
 
+#if KVM_S390_MANAGES_S390_GUEST
+bool _gmap_unmap_prefix(struct gmap *gmap, gfn_t gfn, gfn_t end, bool hint);
+#else
+static inline bool _gmap_unmap_prefix(struct gmap *gmap, gfn_t gfn, gfn_t end, bool hint)
+{
+	return true;
+}
+#endif /* KVM_S390_MANAGES_S390_GUEST */
 static inline bool gmap_mkold_prefix(struct gmap *gmap, gfn_t gfn, gfn_t end)
 {
 	return _gmap_unmap_prefix(gmap, gfn, end, true);
Signature · 1 line
2.53.0
author reviewer
#72 lore raw

PATCH v6 24/33 KVM: s390: Use arm64 code

In reply to Steffen Eiden

Add the infrastructure to extract KVM/arm64 code into s390 at built time similar to the arm64 header sharing. Add copy-arm64c.awk hat detects ARM64_S390_COMMON markers and extracts marked section into an .inc file that can be consumed by arm on s390 host code. If no marker is found make will fail.

To ensure that no code is consumed twice by accident a guard is added during file generation. A s390 C file wanting to consume such an inc file must first define __INCL_GEN_ARM_FILE otherwise the inc file will emit a compile error.

Example:

	#define __INCL_GEN_ARM_FILE
	#include <generated/arm.inc>
	#undef __INCL_GEN_ARM_FILE
---
 arch/s390/kvm/arm64/.gitignore      |  2 +
 arch/s390/kvm/arm64/Makefile.gen    | 29 ++++++++++++
 arch/s390/kvm/arm64/copy-arm64c.awk | 72 +++++++++++++++++++++++++++++
 3 files changed, 103 insertions(+)
 create mode 100644 arch/s390/kvm/arm64/.gitignore
 create mode 100644 arch/s390/kvm/arm64/Makefile.gen
 create mode 100644 arch/s390/kvm/arm64/copy-arm64c.awk
arch/s390/kvm/arm64/.gitignore new file +2 -0
new file mode 100644
index 000000000000..bd9d90694676
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+generated/*
arch/s390/kvm/arm64/Makefile.gen new file +29 -0
new file mode 100644
index 000000000000..cb9482eb947b
@@ -0,0 +1,29 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Extracts ARM64 marked sections to .inc files that are included by main source
+# files
+
+# List of ARM64 C files to extract
+ARM64_CFILES := \
+	arm.c \
+	guest.c \
+	handle_exit.c \
+	mmio.c \
+
+quiet_cmd_extract_inc = GEN     $@
+      cmd_extract_inc = mkdir -p $(dir $@); \
+                        $(AWK) -f $(src)/copy-arm64c.awk $< > $@ || \
+                        { echo "Error: No or unbalanced ARM64_S390_COMMON markers in $<" >&2; rm -f $@; exit 1; }
+
+$(obj)/generated/%.inc: $(srctree)/arch/arm64/kvm/%.c $(src)/copy-arm64c.awk FORCE
+	$(call if_changed,extract_inc)
+
+ARM64_INC_FILES := $(foreach cfile,$(ARM64_CFILES),generated/$(basename $(cfile)).inc)
+
+targets += $(ARM64_INC_FILES)
+clean-files += generated/*.inc
+
+$(addprefix $(obj)/,$(kvm-arm64-obj)): $(addprefix $(obj)/,$(ARM64_INC_FILES))
+
+$(foreach cfile,$(basename $(ARM64_CFILES)),\
+	$(eval $(obj)/$(cfile).o: $(obj)/generated/$(cfile).inc))
arch/s390/kvm/arm64/copy-arm64c.awk new file +72 -0

72 lines not on this page · raw message

Signature · 1 line
2.53.0
author reviewer
#74 lore raw

PATCH v6 25/33 s390: Introduce Start Arm Execution instruction

In reply to Steffen Eiden

The Start Arm Execution (SAE) instruction is the centerpiece for executing arm64 (KVM) guests on s390. Its purpose is, similar to SIE, to enable accelerated execution of arm64 virtual machines. SAE expects the physical address of a control block as the only argument.

The host is responsible to save & restore
- GPRs 0-13
- access register 0-15
- breaking event register (BEAR)
- vector/floating point registers
between SAE executions to guarantee host consistency.

GPRs and BEAR are save and restores in the asm functions. The other register are handled in within C code. Access registers are handled in a later patch and SVEs will be handled when they are introduced in a future series. Most arm64 registers are handled by a satellite block called save_area. Some registers, frequently used by hypervisors, are placed into the SAE control block itself.

Enlighten asm/kvm_host_types.h for the new header variant. The new header is chosen instead of asm/kvm_host_s390_types.h if KVM_S390_ARM64 is defined.

---
 arch/s390/include/asm/asm-prototypes.h       |   1 +
 arch/s390/include/asm/kvm_host_arm64_types.h | 118 +++++++++++++++++++
 arch/s390/include/asm/kvm_host_types.h       |   4 +
 arch/s390/include/asm/sae.h                  |  57 +++++++++
 arch/s390/include/asm/stacktrace.h           |   5 +
 arch/s390/kernel/asm-offsets.c               |   1 +
 arch/s390/kernel/entry.S                     |  22 ++++
 arch/s390/tools/opcodes.txt                  |   3 +
 8 files changed, 211 insertions(+)
 create mode 100644 arch/s390/include/asm/kvm_host_arm64_types.h
 create mode 100644 arch/s390/include/asm/sae.h
arch/s390/include/asm/asm-prototypes.h +1 -0
index d4da4436d02b..faa2afb259a1 100644
@@ -6,6 +6,7 @@
 #include <asm/bug.h>
 #include <asm/fpu.h>
 #include <asm/nospec-branch.h>
+#include <asm/sae.h>
 #include <asm-generic/asm-prototypes.h>
 
 #endif /* _ASM_S390_PROTOTYPES_H */
arch/s390/include/asm/kvm_host_arm64_types.h new file +118 -0

118 lines not on this page · raw message

arch/s390/include/asm/kvm_host_types.h +4 -0
index e5bdba07cab0..d308739ebcf5 100644
@@ -3,6 +3,10 @@
 #ifndef ASM_KVM_HOST_TYPES_H
 #define ASM_KVM_HOST_TYPES_H
 
+#ifdef KVM_S390_ARM64
+#include <asm/kvm_host_arm64_types.h>
+#else
 #include <asm/kvm_host_s390_types.h>
+#endif /* KVM_S390_ARM64 */
 
 #endif /* ASM_KVM_HOST_TYPES_H */
arch/s390/include/asm/sae.h new file +57 -0

57 lines not on this page · raw message

arch/s390/include/asm/stacktrace.h +5 -0
index ac3606c3babe..2d332d7c8145 100644
@@ -59,6 +59,7 @@ static inline bool on_stack(struct stack_info *info,
 struct stack_frame {
 	union {
 		unsigned long empty[9];
+		/* SIE stack frame */
 		struct {
 			unsigned long sie_control_block;
 			unsigned long sie_savearea;
@@ -68,6 +69,10 @@ struct stack_frame {
 			unsigned long sie_guest_asce;
 			unsigned long sie_irq;
 		};
+		/* SAE stack frame */
+		struct {
+			unsigned long sae_bear;
+		};
 	};
 	unsigned long gprs[10];
 	unsigned long back_chain;
arch/s390/kernel/asm-offsets.c +1 -0
index f6dd2b67dcee..f9f9c2246074 100644
@@ -70,6 +70,7 @@ int main(void)
 	OFFSET(__SF_SIE_CONTROL_PHYS, stack_frame, sie_control_block_phys);
 	OFFSET(__SF_SIE_GUEST_ASCE, stack_frame, sie_guest_asce);
 	OFFSET(__SF_SIE_IRQ, stack_frame, sie_irq);
+	OFFSET(__SF_SAE_BEAR, stack_frame, sae_bear);
 	DEFINE(STACK_FRAME_OVERHEAD, sizeof(struct stack_frame));
 	BLANK();
 	OFFSET(__SFUSER_BACKCHAIN, stack_frame_user, back_chain);
arch/s390/kernel/entry.S +22 -0
index 10dd9bbdf985..5d9817acab0b 100644
@@ -245,6 +245,28 @@ EXPORT_SYMBOL(__sie64a)
 EXPORT_SYMBOL(sie_exit)
 #endif
 
+#if IS_ENABLED(CONFIG_KVM_ARM64)
+/*
+ * __sae64a calling convention:
+ * %r2 pointer to sae control block physical address
+ */
+SYM_FUNC_START(__sae64a)
+	stmg	%r6,%r14,__SF_GPRS(%r15)	# store kernel registers
+	STBEAR	__SF_SAE_BEAR(%r15)		# save breaking event address register
+	.insn	rre,0xb9a50000,%r2,0		# Start Arm Execution
+	LBEAR	__SF_SAE_BEAR(%r15)		# restore breaking event address register
+	lmg	%r6,%r14,__SF_GPRS(%r15)	# restore kernel registers
+	xgr	%r0,%r0				# clear guest registers to
+	xgr	%r1,%r1				# prevent speculative use
+	xgr	%r2,%r2
+	xgr	%r3,%r3
+	xgr	%r4,%r4
+	xgr	%r5,%r5
+	BR_EX	%r14
+SYM_FUNC_END(__sae64a)
+EXPORT_SYMBOL(__sae64a)
+#endif
+
 /*
  * SVC interrupt handler routine. System calls are synchronous events and
  * are entered with interrupts disabled.
arch/s390/tools/opcodes.txt +3 -0
index def2659f6602..0e4773c94af0 100644
@@ -594,6 +594,9 @@ b9a0	clp	RRF_U0RR
 b9a1	tpei	RRE_RR
 b9a2	ptf	RRE_R0
 b9a4	uvc	RRF_URR
+b9a5	sae	RRE_R0
+b9a6	lasrm	RRE_R0
+b9a7	stiasrm	RRE_R0
 b9aa	lptea	RRF_RURR2
 b9ab	essa	RRF_U0RR
 b9ac	irbm	RRE_RR
Signature · 1 line
2.53.0
author reviewer
#78 lore raw

PATCH v6 27/33 s390/hwcaps: Report SAE support as hwcap

In reply to Steffen Eiden

From: Hendrik Brueckner <[email protected]>

Report SAE support as hwcap (and /proc/cpuinfo)

---
 arch/s390/include/asm/elf.h    | 2 ++
 arch/s390/include/asm/sclp.h   | 5 ++++-
 arch/s390/kernel/processor.c   | 3 +++
 drivers/s390/char/sclp_early.c | 1 +
 4 files changed, 10 insertions(+), 1 deletion(-)
arch/s390/include/asm/elf.h +2 -0
index bb63fa4d20bb..ad3108ecfb07 100644
@@ -123,6 +123,7 @@ enum {
 	HWCAP_NR_NNPA		= 20,
 	HWCAP_NR_PCI_MIO	= 21,
 	HWCAP_NR_SIE		= 22,
+	HWCAP_NR_SAE		= 23,
 	HWCAP_NR_MAX
 };
 
@@ -150,6 +151,7 @@ enum {
 #define HWCAP_NNPA		BIT(HWCAP_NR_NNPA)
 #define HWCAP_PCI_MIO		BIT(HWCAP_NR_PCI_MIO)
 #define HWCAP_SIE		BIT(HWCAP_NR_SIE)
+#define HWCAP_SAE		BIT(HWCAP_NR_SAE)
 
 /*
  * These are used to set parameters in the core dumps.
arch/s390/include/asm/sclp.h +4 -1
index 44066550b9b1..68f61b71a2d5 100644
@@ -56,7 +56,9 @@ struct sclp_core_entry {
 	u8 siif : 1;
 	u8 sigpif : 1;
 	u8 : 3;
-	u8 reserved2[3];
+	u8 aef: 1;
+	u8 : 7;
+	u8 reserved2[2];
 	u8 : 2;
 	u8 ib : 1;
 	u8 cei : 1;
@@ -109,6 +111,7 @@ struct sclp_info {
 	unsigned char has_aeni : 1;
 	unsigned char has_aisi : 1;
 	unsigned char has_astfleie2 : 1;
+	unsigned char has_aef : 1;
 	unsigned int ibc;
 	unsigned int mtid;
 	unsigned int mtid_cp;
arch/s390/kernel/processor.c +3 -0
index e33a3eccda56..6da55a158027 100644
@@ -150,6 +150,7 @@ static void show_cpu_summary(struct seq_file *m, void *v)
 		[HWCAP_NR_NNPA]		= "nnpa",
 		[HWCAP_NR_PCI_MIO]	= "pcimio",
 		[HWCAP_NR_SIE]		= "sie",
+		[HWCAP_NR_SAE]		= "sae",
 	};
 	int i, cpu;
 
@@ -254,6 +255,8 @@ static int __init setup_hwcaps(void)
 	/* virtualization support */
 	if (sclp.has_sief2)
 		elf_hwcap |= HWCAP_SIE;
+	if (sclp.has_aef)
+		elf_hwcap |= HWCAP_SAE;
 
 	return 0;
 }
drivers/s390/char/sclp_early.c +1 -0
index 22dd797e6229..e58d24b95bd1 100644
@@ -96,6 +96,7 @@ static void __init sclp_early_facilities_detect(void)
 		sclp.has_ib = cpue->ib;
 		sclp.has_cei = cpue->cei;
 		sclp.has_skey = cpue->skey;
+		sclp.has_aef = cpue->aef;
 		break;
 	}
 
Signature · 1 line
2.53.0
author reviewer
#87 lore raw

PATCH v6 30/33 KVM: s390: arm64: Implement vm/vcpu create destroy.

In reply to Steffen Eiden

Implement init and destroy IOCTLS for vcpu and vm. Implement arch vm IOCTL. Use s390 gmap and gmap plumbing. Implement function (stubs) required by gamp.

---
 arch/s390/kvm/arm64/arm.c       | 197 ++++++++++++++++++++++++++++++++
 arch/s390/kvm/arm64/arm.h       |  56 +++++++++
 arch/s390/kvm/gmap/faultin.c    |   5 +
 arch/s390/kvm/gmap/gmap.c       |   4 +
 arch/s390/kvm/gmap/kvm_mmu.c    |   4 +
 arch/s390/kvm/gmap/trace_gmap.h |  17 +++
 6 files changed, 283 insertions(+)
arch/s390/kvm/arm64/arm.c +197 -0
index 8e17b7eef813..69d43066f9e1 100644
@@ -8,6 +8,9 @@
 #include <linux/kvm_types.h>
 #include <linux/kvm_host.h>
 
+#include <gmap.h>
+#include <kvm_mmu.h>
+
 #include "arm.h"
 
 #define CREATE_TRACE_POINTS
@@ -19,6 +22,8 @@ static unsigned long system_supported_vcpu_features(void);
 #include "generated/arm.inc"
 #undef __INCL_GEN_ARM_FILE
 
+#define KVM_PHYS_SHIFT (40)
+
 int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 {
 	int ret;
@@ -53,6 +58,83 @@ static u64 kvm_max_guest_address(void)
 	return ALIGN_DOWN(max_addr + 1, 1 << 30) - 1;
 }
 
+static int kvm_gmap_init(struct kvm *kvm)
+{
+	struct crst_table *table;
+
+	kvm->arch.gmap = gmap_new(kvm, gpa_to_gfn(kvm->arch.guest_phys_size));
+
+	if (!kvm->arch.gmap)
+		return -ENOMEM;
+
+	/* arm64 (on s390) do not have pfault */
+	clear_bit(GMAP_FLAG_PFAULT_ENABLED, &kvm->arch.gmap->flags);
+	set_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &kvm->arch.gmap->flags);
+
+	table = dereference_asce(kvm->arch.gmap->asce);
+	crst_table_init((void *)table, _CRSTE_HOLE(table->crstes[0].h.tt).val);
+
+	return 0;
+}
+
+static int kvm_vm_type_ipa_size_shift(unsigned long type)
+{
+	int phys_shift;
+
+	phys_shift = KVM_VM_TYPE_ARM_IPA_SIZE(type);
+	if (phys_shift) {
+		if (phys_shift > get_kvm_ipa_limit() ||
+		    phys_shift < ARM64_MIN_PARANGE_BITS)
+			return -EINVAL;
+	} else {
+		phys_shift = KVM_PHYS_SHIFT;
+		if (phys_shift > get_kvm_ipa_limit()) {
+			pr_warn_once("%s using unsupported default IPA limit\n",
+				     current->comm);
+			return -EINVAL;
+		}
+	}
+
+	return phys_shift;
+}
+
+int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
+{
+	char debug_name[32];
+	int ret;
+
+	if (type & ~KVM_VM_TYPE_ARM_IPA_SIZE_MASK)
+		return -EINVAL;
+
+	ret = kvm_vm_type_ipa_size_shift(type);
+	if (ret < 0)
+		return ret;
+	kvm->arch.guest_phys_size = 1UL << ret;
+
+	mutex_init(&kvm->arch.config_lock);
+	bitmap_zero(kvm->arch.vcpu_features, KVM_VCPU_MAX_FEATURES);
+
+	snprintf(debug_name, sizeof(debug_name), "kvm-arm64-%u-%u",
+		 current->pid, get_random_u32());
+	kvm->arch.dbf = debug_register(debug_name, 32, 1, 7 * sizeof(long));
+	if (!kvm->arch.dbf)
+		return -ENOMEM;
+	debug_register_view(kvm->arch.dbf, &debug_sprintf_view);
+
+	ret = kvm_gmap_init(kvm);
+	if (ret)
+		goto out_err;
+	kvm->arch.mem_limit = kvm_max_guest_address();
+
+	VM_EVENT(kvm, 3, "vm created with type %lu", type);
+	return 0;
+
+out_err:
+	debug_unregister(kvm->arch.dbf);
+
+	return ret;
+}
+
 vm_fault_t kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)
 {
 	return VM_FAULT_SIGBUS;
@@ -64,6 +146,13 @@ long kvm_arch_dev_ioctl(struct file *filp,
 	return -EINVAL;
 }
 
+void kvm_arch_destroy_vm(struct kvm *kvm)
+{
+	kvm_destroy_vcpus(kvm);
+	debug_unregister(kvm->arch.dbf);
+	kvm->arch.gmap = gmap_put(kvm->arch.gmap);
+}
+
 u32 get_kvm_ipa_limit(void)
 {
 	return fls64(kvm_max_guest_address() + 1) - 1;
@@ -74,10 +163,43 @@ int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id)
 	return 0;
 }
 
+int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
+{
+	struct kvm_sae_block *sae_block = &vcpu->arch.sae_block;
+	struct kvm_sae_save_area *save_area = &vcpu->arch.save_area;
+
+	spin_lock_init(&vcpu->arch.mp_state_lock);
+
+	/* Force users to call KVM_ARM_VCPU_INIT */
+	vcpu_clear_flag(vcpu, VCPU_INITIALIZED);
+
+	vcpu->arch.mc = kvm_s390_new_mmu_cache();
+	if (!vcpu->arch.mc)
+		return -ENOMEM;
+
+	sae_block->hbasce = vcpu->kvm->arch.gmap->asce.val;
+	sae_block->mso = 0L;
+	sae_block->msl = kvm_max_guest_address();
+	sae_block->save_area = virt_to_phys(save_area);
+
+	VM_EVENT(vcpu->kvm, 3,
+		 "create cpu %d at 0x%p, sae block at 0x%p, satellite at 0x%p",
+		 vcpu->vcpu_id, vcpu, &vcpu->arch.sae_block,
+		 &vcpu->arch.save_area);
+	return 0;
+}
+
 void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
 {
 }
 
+void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
+{
+	kvm_s390_free_mmu_cache(vcpu->arch.mc);
+
+	VCPU_EVENT(vcpu, 3, "%s", "free cpu");
+}
+
 int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
 				    struct kvm_mp_state *mp_state)
 {
@@ -103,6 +225,81 @@ static unsigned long system_supported_vcpu_features(void)
 	return features;
 }
 
+int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
+			       struct kvm_dirty_log *log)
+{
+	return s390_kvm_mmu_get_dirty_log(kvm, log);
+}
+
+bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
+{
+	scoped_guard(read_lock, &kvm->mmu_lock)
+		return gmap_age_gfn(kvm->arch.gmap, range->start, range->end);
+}
+
+void kvm_arch_sync_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot)
+{
+	gfn_t last_gfn = memslot->base_gfn + memslot->npages;
+
+	scoped_guard(read_lock, &kvm->mmu_lock)
+		gmap_sync_dirty_log(kvm->arch.gmap, memslot->base_gfn, last_gfn);
+}
+
+int kvm_arch_prepare_memory_region(struct kvm *kvm,
+				   const struct kvm_memory_slot *old,
+				   struct kvm_memory_slot *new,
+				   enum kvm_mr_change change)
+{
+	return s390_kvm_mmu_prepare_memory_region(kvm, old, new, change);
+}
+
+void kvm_arch_commit_memory_region(struct kvm *kvm, struct kvm_memory_slot *old,
+				   const struct kvm_memory_slot *new,
+				   enum kvm_mr_change change)
+{
+	s390_kvm_mmu_commit_memory_region(kvm, old, new, change);
+}
+
+bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range)
+{
+	return gmap_unmap_gfn_range(kvm->arch.gmap, range->slot, range->start, range->end);
+}
+
+bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
+{
+	scoped_guard(read_lock, &kvm->mmu_lock)
+		return dat_test_age_gfn(kvm->arch.gmap->asce, range->start, range->end);
+}
+
+#ifdef CONFIG_KVM_GENERIC_PRE_FAULT_MEMORY
+long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu,
+				    struct kvm_pre_fault_memory *range)
+{
+	return -EOPNOTSUPP;
+}
+#endif /* CONFIG_KVM_GENERIC_PRE_FAULT_MEMORY*/
+
+int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
+{
+	void __user *argp = (void __user *)arg;
+
+	switch (ioctl) {
+	case KVM_ARM_PREFERRED_TARGET: {
+		struct kvm_vcpu_init init = {
+			.target = KVM_ARM_TARGET_GENERIC_V8,
+		};
+
+		if (copy_to_user(argp, &init, sizeof(init)))
+			return -EFAULT;
+
+		return 0;
+	}
+
+	default:
+		return -EINVAL;
+	}
+}
+
 bool kvm_arch_irqchip_in_kernel(struct kvm *kvm)
 {
 	return false;
arch/s390/kvm/arm64/arm.h +56 -0

62 lines not on this page · raw message

arch/s390/kvm/gmap/faultin.c +5 -0
index 1dc79807012c..2e93bd563d5c 100644
@@ -10,6 +10,11 @@
 
 #include "gmap.h"
 #include "faultin.h"
+#ifdef KVM_S390_ARM64
+#include "arm.h"
+#else
+#include "s390.h"
+#endif
 
 bool kvm_arch_setup_async_pf(struct kvm_vcpu *vcpu);
 #define CREATE_TRACE_POINTS
arch/s390/kvm/gmap/gmap.c +4 -0
index 4968330e9553..b7071f50f7ad 100644
@@ -21,7 +21,11 @@
 
 #include "dat.h"
 #include "gmap.h"
+#ifdef KVM_S390_ARM64
+#include "arm.h"
+#else
 #include "s390.h"
+#endif
 #include "faultin.h"
 
 static int gmap_limit_to_type(gfn_t limit)
arch/s390/kvm/gmap/kvm_mmu.c +4 -0
index b08b8229bb6f..a26a16193467 100644
@@ -3,7 +3,11 @@
 #include <linux/kvm_types.h>
 #include <linux/kvm_host.h>
 
+#ifdef KVM_S390_ARM64
+#include "arm.h"
+#else
 #include "s390.h"
+#endif
 #include "gmap.h"
 #include "dat.h"
 #include "kvm_mmu.h"
arch/s390/kvm/gmap/trace_gmap.h +17 -0
index 15ec88bdce55..431c9442b10c 100644
@@ -5,12 +5,28 @@
 #include <linux/tracepoint.h>
 
 #undef TRACE_SYSTEM
+#ifdef KVM_S390_ARM64
+#define TRACE_SYSTEM kvm_arm64
+#else
 #define TRACE_SYSTEM kvm
+#endif
 #undef TRACE_INCLUDE_PATH
 #define TRACE_INCLUDE_PATH ../gmap
 #undef TRACE_INCLUDE_FILE
 #define TRACE_INCLUDE_FILE trace_gmap
 
+#ifdef KVM_S390_ARM64
+#define __KVM_FIELDS \
+	__field(unsigned long, pstate) \
+	__field(unsigned long, pc)
+#define __KVM_ASSIGN ({\
+	__entry->pstate = vcpu->arch.sae_block.pstate; \
+	__entry->pc = vcpu->arch.sae_block.pc; \
+	})
+#define __KVM_PRINT \
+	__entry->pstate, \
+	__entry->pc
+#else
 #define __KVM_FIELDS \
 	__field(unsigned long, pswmask) \
 	__field(unsigned long, pswaddr)
@@ -21,6 +37,7 @@
 #define __KVM_PRINT \
 	__entry->pswmask,\
 	__entry->pswaddr
+#endif
 
 TRACE_EVENT(kvm_s390_major_guest_pfault,
 	    TP_PROTO(struct kvm_vcpu *vcpu),
Signature · 1 line
2.53.0
author reviewer
#59 lore raw

PATCH v6 19/33 KVM: s390: gmap: Make storage keys optional

In reply to Steffen Eiden

Guard guest storage key handling behind KVM_S390_MANAGES_S390_GUEST. This enables other KVM implementations to use gmap without implementing storage key infrastructure. Define KVM_S390_MANAGES_S390_GUEST to 1 for KVM hosts managing s390 guests (in kvm_host_s390.h). A KVM implementation not implementing those features must define KVM_S390_MANAGES_S390_GUEST to 0 in its kvm_host_<guest_arch>.h.

No functional changes besides the new guard.

---
 arch/s390/include/asm/kvm_host_s390.h | 2 ++
 arch/s390/kvm/gmap/dat.c              | 2 ++
 arch/s390/kvm/gmap/dat.h              | 4 ++++
 arch/s390/kvm/gmap/gmap.c             | 3 +++
 arch/s390/kvm/gmap/gmap.h             | 6 ++++++
 5 files changed, 17 insertions(+)
arch/s390/include/asm/kvm_host_s390.h +2 -0
index 22e8d7c4a755..cd692f8fb764 100644
@@ -32,6 +32,8 @@
 
 #define KVM_INTERNAL_MEM_SLOTS 1
 
+#define KVM_S390_MANAGES_S390_GUEST 1
+
 /*
  * These seem to be used for allocating ->chip in the routing table, which we
  * don't use. 1 is as small as we can get to reduce the needed memory. If we
arch/s390/kvm/gmap/dat.c +2 -0
index 3f2d6e8902d7..f4e142995367 100644
@@ -613,6 +613,7 @@ long _dat_walk_gfn_range(gfn_t start, gfn_t end, union asce asce,
 	return dat_crste_walk_range(start, min(end, asce_end(asce)), table, &walk);
 }
 
+#if KVM_S390_MANAGES_S390_GUEST
 int dat_get_storage_key(union asce asce, gfn_t gfn, union skey *skey)
 {
 	union crste *crstep;
@@ -839,6 +840,7 @@ long dat_reset_skeys(union asce asce, gfn_t start)
 
 	return _dat_walk_gfn_range(start, asce_end(asce), asce, &ops, DAT_WALK_IGN_HOLES, NULL);
 }
+#endif /* KVM_S390_MANAGES_S390_GUEST */
 
 struct slot_priv {
 	unsigned long token;
arch/s390/kvm/gmap/dat.h +4 -0
index 87108f51228e..2cc072168810 100644
@@ -9,6 +9,7 @@
 #ifndef ARCH_KVM_GMAP_DAT_H
 #define ARCH_KVM_GMAP_DAT_H
 
+#include <linux/kvm_host.h>
 #include <linux/radix-tree.h>
 #include <linux/refcount.h>
 #include <linux/io.h>
@@ -532,6 +533,8 @@ int dat_entry_walk(struct kvm_s390_mmu_cache *mc, gfn_t gfn, union asce asce, in
 void dat_free_level(struct crst_table *table, bool owns_ptes);
 struct crst_table *dat_alloc_crst_sleepable(unsigned long init);
 int dat_set_asce_limit(struct kvm_s390_mmu_cache *mc, union asce *asce, int newtype);
+
+#if KVM_S390_MANAGES_S390_GUEST
 int dat_get_storage_key(union asce asce, gfn_t gfn, union skey *skey);
 int dat_set_storage_key(struct kvm_s390_mmu_cache *mc, union asce asce, gfn_t gfn,
 			union skey skey, bool nq);
@@ -539,6 +542,7 @@ int dat_cond_set_storage_key(struct kvm_s390_mmu_cache *mmc, union asce asce, gf
 			     union skey skey, union skey *oldkey, bool nq, bool mr, bool mc);
 int dat_reset_reference_bit(union asce asce, gfn_t gfn, union skey *skey);
 long dat_reset_skeys(union asce asce, gfn_t start);
+#endif /* KVM_S390_MANAGES_S390_GUEST */
 
 unsigned long dat_get_ptval(struct page_table *table, struct ptval_param param);
 void dat_set_ptval(struct page_table *table, struct ptval_param param, unsigned long val);
arch/s390/kvm/gmap/gmap.c +3 -0
index b5b920392378..c1b0e2572818 100644
@@ -944,6 +944,8 @@ void gmap_split_huge_pages(struct gmap *gmap)
 	} while (start);
 }
 
+#if KVM_S390_MANAGES_S390_GUEST
+
 static int _gmap_enable_skeys(struct gmap *gmap)
 {
 	gfn_t start = 0;
@@ -975,6 +977,7 @@ int gmap_enable_skeys(struct gmap *gmap)
 	mmap_write_unlock(gmap->kvm->mm);
 	return rc;
 }
+#endif /* KVM_S390_MANAGES_S390_GUEST */
 
 static long _destroy_pages_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
 {
arch/s390/kvm/gmap/gmap.h +6 -0
index c54c35e47d6d..328a81c72c7a 100644
@@ -10,6 +10,8 @@
 #ifndef ARCH_KVM_GMAP_GMAP_H
 #define ARCH_KVM_GMAP_GMAP_H
 
+#include <linux/kvm_host.h>
+
 #include "dat.h"
 
 /**
@@ -98,7 +100,11 @@ int gmap_set_limit(struct gmap *gmap, gfn_t limit);
 int gmap_ucas_translate(struct kvm_s390_mmu_cache *mc, struct gmap *gmap, gpa_t *gaddr);
 int gmap_ucas_map(struct gmap *gmap, gfn_t p_gfn, gfn_t c_gfn, unsigned long count);
 void gmap_ucas_unmap(struct gmap *gmap, gfn_t c_gfn, unsigned long count);
+
+#if KVM_S390_MANAGES_S390_GUEST
 int gmap_enable_skeys(struct gmap *gmap);
+#endif /* KVM_S390_MANAGES_S390_GUEST */
+
 int gmap_pv_destroy_range(struct gmap *gmap, gfn_t start, gfn_t end, bool interruptible);
 int gmap_insert_rmap(struct kvm_s390_mmu_cache *mc, struct gmap *sg, gfn_t p_gfn,
 		     gfn_t r_gfn, int level);
Signature · 1 line
2.53.0
author reviewer
#62 lore raw

PATCH v6 20/33 KVM: s390: gmap: Make CMMA optional

In reply to Steffen Eiden

Guard guest CMMA behind KVM_S390_MANAGES_S390_GUEST. This enables other KVM implementations to use gmap without implementing CMMA.

No functional changes.

---
 arch/s390/kvm/gmap/dat.c  | 2 ++
 arch/s390/kvm/gmap/dat.h  | 2 ++
 arch/s390/kvm/gmap/gmap.c | 2 ++
 arch/s390/kvm/gmap/gmap.h | 4 +++-
 4 files changed, 9 insertions(+), 1 deletion(-)
arch/s390/kvm/gmap/dat.c +2 -0
index f4e142995367..43ebafb56ce5 100644
@@ -1059,6 +1059,7 @@ int dat_set_prefix_notif_bit(union asce asce, gfn_t gfn)
 	return 0;
 }
 
+#if KVM_S390_MANAGES_S390_GUEST
 /**
  * dat_perform_essa() - Perform ESSA actions on the PGSTE.
  * @asce: The asce to operate on.
@@ -1336,3 +1337,4 @@ int dat_set_cmma_bits(struct kvm_s390_mmu_cache *mc, union asce asce, gfn_t gfn,
 	}
 	return _dat_walk_gfn_range(gfn, gfn + count, asce, &ops, DAT_WALK_IGN_HOLES, &state);
 }
+#endif /* KVM_S390_MANAGES_S390_GUEST */
arch/s390/kvm/gmap/dat.h +2 -0
index 2cc072168810..4f11f9bbd83a 100644
@@ -552,12 +552,14 @@ int dat_set_slot(struct kvm_s390_mmu_cache *mc, union asce asce, gfn_t start, gf
 int dat_set_prefix_notif_bit(union asce asce, gfn_t gfn);
 bool dat_test_age_gfn(union asce asce, gfn_t start, gfn_t end);
 
+#if KVM_S390_MANAGES_S390_GUEST
 int dat_perform_essa(union asce asce, gfn_t gfn, int orc, union essa_state *state, bool *dirty);
 long dat_reset_cmma(union asce asce, gfn_t start_gfn);
 int dat_peek_cmma(gfn_t start, union asce asce, unsigned int *count, u8 *values);
 int dat_get_cmma(union asce asce, gfn_t *start, unsigned int *count, u8 *values, atomic64_t *rem);
 int dat_set_cmma_bits(struct kvm_s390_mmu_cache *mc, union asce asce, gfn_t gfn,
 		      unsigned long count, unsigned long mask, const uint8_t *bits);
+#endif /* KVM_S390_MANAGES_S390_GUEST */
 
 int kvm_s390_mmu_cache_topup(struct kvm_s390_mmu_cache *mc);
 
arch/s390/kvm/gmap/gmap.c +2 -0
index c1b0e2572818..86513f653850 100644
@@ -1098,6 +1098,7 @@ int gmap_protect_rmap(struct kvm_s390_mmu_cache *mc, struct gmap *sg, gfn_t p_gf
 	return 0;
 }
 
+#if KVM_S390_MANAGES_S390_GUEST
 static long __set_cmma_clean_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
 {
 	union pgste pgste;
@@ -1140,6 +1141,7 @@ void _gmap_set_cmma_all(struct gmap *gmap, bool dirty)
 						  &gmap->kvm->arch.cmma_dirty_pages);
 	} while (gfn);
 }
+#endif /* KVM_S390_MANAGES_S390_GUEST */
 
 static void gmap_unshadow_level(struct gmap *sg, gfn_t r_gfn, int level)
 {
arch/s390/kvm/gmap/gmap.h +3 -1
index 328a81c72c7a..6f3bf11d2166 100644
@@ -110,7 +110,6 @@ int gmap_insert_rmap(struct kvm_s390_mmu_cache *mc, struct gmap *sg, gfn_t p_gfn
 		     gfn_t r_gfn, int level);
 int gmap_protect_rmap(struct kvm_s390_mmu_cache *mc, struct gmap *sg, gfn_t p_gfn, gfn_t r_gfn,
 		      kvm_pfn_t pfn, int level, bool wr);
-void _gmap_set_cmma_all(struct gmap *gmap, bool dirty);
 void _gmap_handle_vsie_unshadow_event(struct gmap *parent, gfn_t gfn);
 struct gmap *gmap_create_shadow(struct kvm_s390_mmu_cache *mc, struct gmap *gmap,
 				union asce asce, int edat_level);
@@ -204,6 +203,8 @@ static inline bool pte_needs_unshadow(union pte oldpte, union pte newpte, union
 	return !newpte.h.p || !newpte.s.pr;
 }
 
+#if KVM_S390_MANAGES_S390_GUEST
+void _gmap_set_cmma_all(struct gmap *gmap, bool dirty);
 static inline void gmap_set_cmma_all_dirty(struct gmap *gmap)
 {
 	_gmap_set_cmma_all(gmap, true);
@@ -213,6 +214,7 @@ static inline void gmap_set_cmma_all_clean(struct gmap *gmap)
 {
 	_gmap_set_cmma_all(gmap, false);
 }
+#endif /* KVM_S390_MANAGES_S390_GUEST */
 
 static inline union pgste _gmap_ptep_xchg(struct gmap *gmap, union pte *ptep, union pte newpte,
 					  union pgste pgste, gfn_t gfn, bool needs_lock)
Signature · 1 line
2.53.0
author reviewer
#80 lore raw

PATCH v6 28/33 KVM: s390: Add basic arm64 kvm module

In reply to Steffen Eiden

Add basic code for the new arm64 on s390 KVM implementation. Add kernel module boilerplate code and trivial functions. Add tracing scaffolding.

---
 arch/s390/kvm/arm64/arm.c   | 157 ++++++++++++++++++++++++++++++++++++
 arch/s390/kvm/arm64/arm.h   |   7 ++
 arch/s390/kvm/arm64/guest.c |  92 +++++++++++++++++++++
 arch/s390/kvm/arm64/trace.h |  18 +++++
 4 files changed, 274 insertions(+)
 create mode 100644 arch/s390/kvm/arm64/arm.c
 create mode 100644 arch/s390/kvm/arm64/arm.h
 create mode 100644 arch/s390/kvm/arm64/guest.c
 create mode 100644 arch/s390/kvm/arm64/trace.h
arch/s390/kvm/arm64/arm.c new file +157 -0
new file mode 100644
index 000000000000..8e17b7eef813
@@ -0,0 +1,157 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#define KMSG_COMPONENT "kvm-s390-arm64"
+#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
+
+#include <linux/miscdevice.h>
+#include <linux/kvm.h>
+#include <linux/kvm_types.h>
+#include <linux/kvm_host.h>
+
+#include "arm.h"
+
+#define CREATE_TRACE_POINTS
+#include "trace.h"
+
+static unsigned long system_supported_vcpu_features(void);
+
+#define __INCL_GEN_ARM_FILE
+#include "generated/arm.inc"
+#undef __INCL_GEN_ARM_FILE
+
+int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
+{
+	int ret;
+
+	switch (ext) {
+	case KVM_CAP_NR_VCPUS:
+	case KVM_CAP_MAX_VCPUS:
+	case KVM_CAP_MAX_VCPU_ID:
+		ret = KVM_MAX_VCPUS;
+		break;
+	case KVM_CAP_ARM_VM_IPA_SIZE:
+		ret = get_kvm_ipa_limit();
+		break;
+	case KVM_CAP_IOEVENTFD:
+		ret = 1;
+		break;
+	default:
+		ret = 0;
+	}
+
+	return ret;
+}
+
+static u64 kvm_max_guest_address(void)
+{
+	u64 max_addr;
+
+	if (sclp.hamax == U64_MAX)
+		max_addr = TASK_SIZE_MAX;
+	else
+		max_addr = min_t(u64, TASK_SIZE_MAX, sclp.hamax);
+	return ALIGN_DOWN(max_addr + 1, 1 << 30) - 1;
+}
+
+vm_fault_t kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)
+{
+	return VM_FAULT_SIGBUS;
+}
+
+long kvm_arch_dev_ioctl(struct file *filp,
+			unsigned int ioctl, unsigned long arg)
+{
+	return -EINVAL;
+}
+
+u32 get_kvm_ipa_limit(void)
+{
+	return fls64(kvm_max_guest_address() + 1) - 1;
+}
+
+int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id)
+{
+	return 0;
+}
+
+void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
+{
+}
+
+int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
+				    struct kvm_mp_state *mp_state)
+{
+	*mp_state = READ_ONCE(vcpu->arch.mp_state);
+	return 0;
+}
+
+int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
+				    struct kvm_mp_state *mp_state)
+{
+	return -EINVAL;
+}
+
+int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)
+{
+	return 0;
+}
+
+static unsigned long system_supported_vcpu_features(void)
+{
+	unsigned long features = KVM_S390_ARM64_IMPL_FEATURES;
+
+	return features;
+}
+
+bool kvm_arch_irqchip_in_kernel(struct kvm *kvm)
+{
+	return false;
+}
+
+int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm,
+		int irq_source_id, int level, bool line_status)
+{
+	return -EINVAL;
+}
+
+int kvm_set_routing_entry(struct kvm *kvm,
+			  struct kvm_kernel_irq_routing_entry *e,
+			  const struct kvm_irq_routing_entry *ue)
+{
+	return -EINVAL;
+}
+
+int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
+{
+	return 0;
+}
+
+#ifdef CONFIG_HAVE_KVM_NO_POLL
+__weak bool kvm_arch_no_poll(struct kvm_vcpu *vcpu)
+{
+	return false;
+}
+#endif
+
+long kvm_arch_vcpu_unlocked_ioctl(struct file *filp, unsigned int ioctl,
+				  unsigned long arg)
+{
+	return -ENOIOCTLCMD;
+}
+
+static int __init kvm_s390_arm64_init(void)
+{
+	if (!sclp.has_aef)
+		return -ENXIO;
+
+	return kvm_init_with_dev(sizeof(struct kvm_vcpu), 0, THIS_MODULE,
+				 KVM_DEV_NAME, MISC_DYNAMIC_MINOR);
+}
+
+static __exit void kvm_s390_arm64_exit(void)
+{
+	kvm_exit();
+}
+
+module_init(kvm_s390_arm64_init);
+module_exit(kvm_s390_arm64_exit);
arch/s390/kvm/arm64/arm.h new file +7 -0
new file mode 100644
index 000000000000..a3db254462c0
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef ARCH_S390_KVM_ARM64_H
+#define ARCH_S390_KVM_ARM64_H
+
+#define KVM_DEV_NAME "kvm-arm64"
+
+#endif /* ARCH_S390_KVM_ARM64_H */
arch/s390/kvm/arm64/guest.c new file +92 -0

92 lines not on this page · raw message

arch/s390/kvm/arm64/trace.h new file +18 -0
new file mode 100644
index 000000000000..3a5dcd039c13
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#if !defined(KVM_ARM64_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
+#define KVM_ARM64_TRACE_KVM_H
+
+#include <linux/tracepoint.h>
+
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM kvm
+
+#endif /* KVM_ARM64_TRACE_KVM_H */
+
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH .
+#undef TRACE_INCLUDE_FILE
+#define TRACE_INCLUDE_FILE trace
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
Signature · 1 line
2.53.0
author reviewer
#84 lore raw

PATCH v6 29/33 KVM: s390: arm64: Implement required functions

In reply to Steffen Eiden

Implement the mostly trivial functions that the shared arm64 (kvm) code & headers oblige s390 to implement.

Implement a very basic smccc handler that (non-compliantly) is just able to stop a vcpu.

---
 arch/s390/include/arm64/kvm_emulate.h | 130 ++++++++++++++++++++++++++
 arch/s390/include/arm64/kvm_nested.h  |  11 +++
 arch/s390/include/arm64/ptrace.h      |  11 +++
 arch/s390/include/arm64/sysreg.h      |  13 +++
 arch/s390/kvm/arm64/handle_exit.c     |  98 +++++++++++++++++++
 arch/s390/kvm/arm64/inject_fault.c    |  21 +++++
 6 files changed, 284 insertions(+)
 create mode 100644 arch/s390/include/arm64/kvm_emulate.h
 create mode 100644 arch/s390/include/arm64/kvm_nested.h
 create mode 100644 arch/s390/include/arm64/ptrace.h
 create mode 100644 arch/s390/include/arm64/sysreg.h
 create mode 100644 arch/s390/kvm/arm64/handle_exit.c
 create mode 100644 arch/s390/kvm/arm64/inject_fault.c
arch/s390/include/arm64/kvm_emulate.h new file +130 -0
new file mode 100644
index 000000000000..c1551e3da8f4
@@ -0,0 +1,130 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __S390_ARM64_KVM_EMULATE_H__
+#define __S390_ARM64_KVM_EMULATE_H__
+
+#include <asm/fault.h>
+#include <linux/kvm_host.h>
+
+#include <arm64/kvm_nested.h>
+#include <arm64/ptrace.h>
+#include <arm64/kvm_arm.h>
+#include <arm64/sysreg.h>
+
+static __always_inline unsigned long *vcpu_pc(const struct kvm_vcpu *vcpu)
+{
+	return (unsigned long *)&vcpu->arch.sae_block.pc;
+}
+
+static __always_inline unsigned long *vcpu_cpsr(const struct kvm_vcpu *vcpu)
+{
+	return (unsigned long *)&vcpu->arch.sae_block.pstate;
+}
+
+static __always_inline unsigned long *vcpu_sp_el0(const struct kvm_vcpu *vcpu)
+{
+	return (unsigned long *)&vcpu->arch.sae_block.sp_el0;
+}
+
+static __always_inline u64 *vcpu_sp_el1(struct kvm_vcpu *vcpu)
+{
+	return &vcpu->arch.sae_block.sp_el1;
+}
+
+static __always_inline __vector128 *vcpu_vreg(struct kvm_vcpu *vcpu, int off)
+{
+	return &vcpu->arch.ctxt.vregs[off];
+}
+
+static __always_inline u64 *vcpu_fpsr(struct kvm_vcpu *vcpu)
+{
+	return &vcpu->arch.sae_block.fpsr;
+}
+
+static __always_inline u64 *vcpu_fpcr(struct kvm_vcpu *vcpu)
+{
+	return &vcpu->arch.sae_block.fpcr;
+}
+
+static __always_inline bool vcpu_mode_is_32bit(const struct kvm_vcpu *vcpu)
+{
+	return false;
+}
+
+static __always_inline u64 kvm_vcpu_get_esr(const struct kvm_vcpu *vcpu)
+{
+	return vcpu->arch.sae_block.hai.esr_elz;
+}
+
+static inline unsigned long *vcpu_hcr(struct kvm_vcpu *vcpu)
+{
+	return (unsigned long *)&vcpu->arch.hcr_elz;
+}
+
+static __always_inline unsigned long kvm_vcpu_get_hfar(const struct kvm_vcpu *vcpu)
+{
+	return vcpu->arch.sae_block.hai.far_elz;
+}
+
+static __always_inline phys_addr_t kvm_vcpu_get_fault_ipa(const struct kvm_vcpu *vcpu)
+{
+	return vcpu->arch.sae_block.hai.teid.addr * PAGE_SIZE;
+}
+
+static inline u16 kvm_vcpu_fault_pic(const struct kvm_vcpu *vcpu)
+{
+	return vcpu->arch.sae_block.hai.pic & PGM_INT_CODE_MASK;
+}
+
+static __always_inline
+bool kvm_vcpu_trap_is_permission_fault(const struct kvm_vcpu *vcpu)
+{
+	return kvm_vcpu_fault_pic(vcpu) == PGM_PROTECTION;
+}
+
+static __always_inline bool kvm_condition_valid(const struct kvm_vcpu *vcpu)
+{
+	return true;
+}
+
+static __always_inline bool vcpu_el1_is_32bit(struct kvm_vcpu *vcpu)
+{
+	return false;
+}
+
+static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu)
+{
+	return false;
+}
+
+static inline int kvm_vcpu_abt_gltl(struct kvm_vcpu *vcpu)
+{
+	return vcpu->arch.sae_block.hai.gltl;
+}
+
+static inline bool vcpu_mode_priv(const struct kvm_vcpu *vcpu)
+{
+	u32 mode = *vcpu_cpsr(vcpu) & PSR_MODE_MASK;
+
+	return mode != PSR_MODE_EL0t;
+}
+
+static inline void kvm_skip_instr(struct kvm_vcpu *vcpu)
+{
+	*vcpu_pc(vcpu) += 4;
+	*vcpu_cpsr(vcpu) &= ~PSR_BTYPE_MASK;
+
+	/* advance the singlestep state machine */
+	*vcpu_cpsr(vcpu) &= ~SPSR_ELx_SS;
+}
+
+static inline void kvm_reset_fpsimd(struct kvm_vcpu *vcpu)
+{
+	memset(vcpu->arch.ctxt.vregs, 0, sizeof(vcpu->arch.ctxt.vregs));
+	vcpu->arch.sae_block.fpsr = 0;
+	vcpu->arch.sae_block.fpcr = 0;
+}
+
+#include <arm64/kvm_emulate-gen.h>
+
+#endif /* __S390_ARM64_KVM_EMULATE_H__ */
arch/s390/include/arm64/kvm_nested.h new file +11 -0
new file mode 100644
index 000000000000..e950b1a10c41
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef ASM_KVM_NESTED_H
+#define ASM_KVM_NESTED_H
+
+static inline bool vcpu_has_nv(const struct kvm_vcpu *vcpu)
+{
+	return false;
+}
+
+#endif /* ASM_KVM_NESTED_H */
arch/s390/include/arm64/ptrace.h new file +11 -0
new file mode 100644
index 000000000000..449b85582c97
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __S390_ARM64_PTRACE_H__
+#define __S390_ARM64_PTRACE_H__
+
+#include <arm64/sysreg.h>
+#include <uapi/arm64/ptrace.h>
+
+#include <arm64/ptrace-gen.h>
+
+#endif /* __S390_ARM64_PTRACE_H__ */
arch/s390/include/arm64/sysreg.h new file +13 -0
new file mode 100644
index 000000000000..ac6b638fef56
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __S390_ARM64_SYSREG_H__
+#define __S390_ARM64_SYSREG_H__
+
+#include <linux/bits.h>
+#include <linux/stringify.h>
+#include <linux/kasan-tags.h>
+#include <linux/kconfig.h>
+
+#include <arm64/sysreg-gen.h>
+
+#endif /* __S390_ARM64_SYSREG_H__ */
arch/s390/kvm/arm64/handle_exit.c new file +98 -0

98 lines not on this page · raw message

arch/s390/kvm/arm64/inject_fault.c new file +21 -0
new file mode 100644
index 000000000000..425dbeaa421c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <arm64/kvm_emulate.h>
+
+/**
+ * kvm_inject_undefined - inject an undefined instruction into the guest
+ * @vcpu: The vCPU in which to inject the exception
+ *
+ * It is assumed that this code is called from the VCPU thread and that the
+ * VCPU therefore is not currently executing guest code.
+ */
+void kvm_inject_undefined(struct kvm_vcpu *vcpu)
+{
+	/* Stub until s390 supports arm64 sysregs TODO sysregs*/
+}
+
+int kvm_inject_sea(struct kvm_vcpu *vcpu, bool iabt, u64 addr)
+{
+	/* Stub until s390 supports arm64 sysregs TODO sysregs*/
+	return 1;
+}
Signature · 1 line
2.53.0
author reviewer
#95 lore raw

PATCH v6 33/33 KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild

In reply to Steffen Eiden

Add all Kbuild/Makefile configurations to build a second KVM module on s390 implementing the arm64-KVM API. To prevent symbol conflicts with kvm-s390 all internal symbols in kvm-arm64 are mangled if compiled as built-in. The new module ins named kvm-arm64.

As in this case the build does not go through the normal build process the module parameter handling would be messed up. By forcing KBUILD_MODNAME to kvm-arm64 all parameters are at the same location and not at object/basename of the object file the parameter is introduced.

---
 arch/s390/configs/debug_defconfig |  1 +
 arch/s390/configs/defconfig       |  1 +
 arch/s390/include/asm/Kbuild      |  3 +
 arch/s390/kvm/Kconfig             | 29 ++++++++++
 arch/s390/kvm/Makefile            |  1 +
 arch/s390/kvm/arm64/Makefile      | 91 +++++++++++++++++++++++++++++++
 6 files changed, 126 insertions(+)
 create mode 100644 arch/s390/kvm/arm64/Makefile
arch/s390/configs/debug_defconfig +1 -0
index 3dae71474333..a05ea2204cdc 100644
@@ -66,6 +66,7 @@ CONFIG_CMM=m
 CONFIG_APPLDATA_BASE=y
 CONFIG_S390_HYPFS_FS=y
 CONFIG_KVM=m
+CONFIG_KVM_ARM64=m
 CONFIG_KVM_S390_UCONTROL=y
 CONFIG_S390_UNWIND_SELFTEST=m
 CONFIG_S390_KPROBES_SANITY_TEST=m
arch/s390/configs/defconfig +1 -0
index 6f5722634b4d..3497f2959b93 100644
@@ -64,6 +64,7 @@ CONFIG_CMM=m
 CONFIG_APPLDATA_BASE=y
 CONFIG_S390_HYPFS_FS=y
 CONFIG_KVM=m
+CONFIG_KVM_ARM64=m
 CONFIG_S390_UNWIND_SELFTEST=m
 CONFIG_S390_KPROBES_SANITY_TEST=m
 CONFIG_S390_MODULES_SANITY_TEST=m
arch/s390/include/asm/Kbuild +3 -0
index 0c1fc47c3ba0..40a81419e353 100644
@@ -8,3 +8,6 @@ generic-y += asm-offsets.h
 generic-y += mcs_spinlock.h
 generic-y += mmzone.h
 generic-y += ring_buffer.h
+
+generated-y += sysreg-defs.h
+generated-y += kvm_arm64_modname.h
arch/s390/kvm/Kconfig +29 -0
index 8d3ee17a1bcb..ee5c1cdc4580 100644
@@ -53,4 +53,33 @@ config KVM_S390_UCONTROL
 
 	  If unsure, say N.
 
+config KVM_ARM64
+	def_tristate y
+	prompt "KVM support for hardware accelerated arm64 guests"
+	depends on HAS_IOMEM
+	depends on KVM
+	select GUEST_PERF_EVENTS if PERF_EVENTS
+	select HAVE_KVM_CPU_RELAX_INTERCEPT
+	select HAVE_KVM_IRQCHIP
+	select HAVE_KVM_VCPU_RUN_PID_CHANGE
+	select IRQ_BYPASS_MANAGER
+	select KVM_COMMON
+	select KVM_MMIO
+	select KVM_VFIO
+	select SCHED_INFO
+	select XARRAY_MULTI
+	help
+	  Enable support for hosting paravirtualized, hardware-accelerated
+	  arm64 virtual machines on s390 systems using the Start ARM Execution
+	  (SAE) instruction. This requires hardware models that support the Arm
+	  execution facility (AEF).
+
+	  The module provides a character device named /dev/kvm-arm64 to expose
+	  the hardware capabilities.
+
+	  To compile this driver as a module, choose M here. The module will
+	  be called kvm-arm64.
+
+	  If unsure, say N.
+
 endif # VIRTUALIZATION
arch/s390/kvm/Makefile +1 -0
index a4e3875b5bdd..d00efd58f94f 100644
@@ -4,3 +4,4 @@
 # Copyright IBM Corp. 2008
 
 obj-$(CONFIG_KVM) += s390/
+obj-$(CONFIG_KVM_ARM64) += arm64/
arch/s390/kvm/arm64/Makefile new file +91 -0

91 lines not on this page · raw message

Signature · 1 line
2.53.0
author reviewer
#70 lore raw

PATCH v6 23/33 s390: Use arm64 headers

In reply to Steffen Eiden

Introduce a flexible system for sharing ARM64 headers with s390 KVM. Selected arm64 headers or snippet of headers will be reachable by s390 code through asm/header.h.

Add copy-arm64h.awk that detects ARM64_S390_COMMON markers and extracts marked section into a generated header consumable by s390. Falls back to full file copy when no markers are found.

Transform copied includes by replacing '#include <asm/...>' with '#include <arm64/...>' and similar for uapi headers to ensure correct path resolution on s390 and allow for a clear separation of s390 asm headers and arm64 asm headers.

Integrate this extraction into the s390/kapi target, conditional on (the not yet existing) CONFIG_KVM_ARM64.

---
 arch/s390/tools/Makefile             |  9 +++-
 arch/s390/tools/Makefile.arm64h      | 57 ++++++++++++++++++++++
 arch/s390/tools/copy-arm64h-full.awk | 47 ++++++++++++++++++
 arch/s390/tools/copy-arm64h.awk      | 72 ++++++++++++++++++++++++++++
 4 files changed, 184 insertions(+), 1 deletion(-)
 create mode 100644 arch/s390/tools/Makefile.arm64h
 create mode 100644 arch/s390/tools/copy-arm64h-full.awk
 create mode 100644 arch/s390/tools/copy-arm64h.awk
arch/s390/tools/Makefile +8 -1
index f2862364fb42..a624b2639b43 100644
@@ -3,12 +3,19 @@
 # Makefile for s390 specific build tools
 #
 
+include $(srctree)/arch/s390/tools/Makefile.arm64h
+
 kapi := arch/$(ARCH)/include/generated/asm
 kapi-hdrs-y := $(kapi)/facility-defs.h $(kapi)/dis-defs.h
 
+targets += $(addprefix ../../../,$(kapi-hdrs-y))
+targets += $(patsubst $(objtree)/%,../../../%,$(ARM64_TARGETS))
+
+kapi-hdrs-$(CONFIG_KVM_ARM64) += $(ARM64_TARGETS)
+
 PHONY += kapi
 
-kapi:	$(kapi-hdrs-y)
+kapi:	$(kapi-hdrs-y) $(kapi-hdrs-m)
 
 hostprogs		    += gen_facilities
 hostprogs		    += gen_opcode_table
arch/s390/tools/Makefile.arm64h new file +57 -0

57 lines not on this page · raw message

arch/s390/tools/copy-arm64h-full.awk new file +47 -0

47 lines not on this page · raw message

arch/s390/tools/copy-arm64h.awk new file +72 -0

72 lines not on this page · raw message

Signature · 1 line
2.53.0
author reviewer
#89 lore raw

PATCH v6 31/33 KVM: s390: arm64: Implement vCPU IOCTLs

In reply to Steffen Eiden

Implement all required vCPU IOCTLs.

---
 arch/s390/kvm/arm64/arm.c         | 392 ++++++++++++++++++++++++++++++
 arch/s390/kvm/arm64/guest.c       |  47 +++-
 arch/s390/kvm/arm64/handle_exit.c |  31 +++
 arch/s390/kvm/arm64/handle_exit.h |   9 +
 arch/s390/kvm/arm64/reset.c       |  73 ++++++
 arch/s390/kvm/arm64/reset.h       |  11 +
 arch/s390/kvm/arm64/trace.h       |   2 +-
 7 files changed, 562 insertions(+), 3 deletions(-)
 create mode 100644 arch/s390/kvm/arm64/handle_exit.h
 create mode 100644 arch/s390/kvm/arm64/reset.c
 create mode 100644 arch/s390/kvm/arm64/reset.h
arch/s390/kvm/arm64/arm.c +392 -0
index 69d43066f9e1..ef941f408744 100644
@@ -7,11 +7,20 @@
 #include <linux/kvm.h>
 #include <linux/kvm_types.h>
 #include <linux/kvm_host.h>
+#include <linux/cleanup.h>
+#include <linux/fpu.h>
+
+#include <asm/access-regs.h>
+
+#include <arm64/kvm_emulate.h>
+#include <arm64/sysreg.h>
 
 #include <gmap.h>
 #include <kvm_mmu.h>
 
 #include "arm.h"
+#include "handle_exit.h"
+#include "reset.h"
 
 #define CREATE_TRACE_POINTS
 #include "trace.h"
@@ -200,6 +209,22 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
 	VCPU_EVENT(vcpu, 3, "%s", "free cpu");
 }
 
+void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
+{
+	save_access_regs(&vcpu->arch.host_acrs[0]);
+	vcpu->cpu = cpu;
+
+	lasrm(&vcpu->arch.save_area);
+}
+
+void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
+{
+	stiasrm(&vcpu->arch.save_area);
+
+	vcpu->cpu = -1;
+	restore_access_regs(&vcpu->arch.host_acrs[0]);
+}
+
 int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
 				    struct kvm_mp_state *mp_state)
 {
@@ -225,6 +250,373 @@ static unsigned long system_supported_vcpu_features(void)
 	return features;
 }
 
+bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu)
+{
+	return vcpu_mode_priv(vcpu);
+}
+
+int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu)
+{
+	struct kvm *kvm = vcpu->kvm;
+
+	if (!kvm_vcpu_initialized(vcpu))
+		return -ENOEXEC;
+
+	if (!kvm_arm_vcpu_is_finalized(vcpu))
+		return -EPERM;
+
+	if (likely(READ_ONCE(vcpu->pid)))
+		return 0;
+
+	scoped_guard(mutex, &kvm->arch.config_lock)
+		set_bit(KVM_ARCH_FLAG_HAS_RAN_ONCE, &kvm->arch.flags);
+
+	return 0;
+}
+
+/**
+ * check_vcpu_requests - check and handle pending vCPU requests
+ * @vcpu:	the VCPU pointer
+ *
+ * Return: 1 if we should enter the guest
+ *	   0 if we should exit to userspace
+ *	   < 0 if we should exit to userspace, where the return value indicates
+ *	   an error
+ */
+static int check_vcpu_requests(struct kvm_vcpu *vcpu)
+{
+	if (kvm_request_pending(vcpu)) {
+		if (kvm_check_request(KVM_REQ_VCPU_RESET, vcpu))
+			kvm_reset_vcpu(vcpu);
+		/*
+		 * Clear IRQ_PENDING requests that were made to guarantee
+		 * that a VCPU sees new virtual interrupts.
+		 */
+		kvm_check_request(KVM_REQ_IRQ_PENDING, vcpu);
+	}
+
+	return 1;
+}
+
+static int kvm_vcpu_initialize(struct kvm_vcpu *vcpu,
+			       const struct kvm_vcpu_init *init)
+{
+	unsigned long features = init->features[0];
+	struct kvm *kvm = vcpu->kvm;
+
+	scoped_guard(mutex, &kvm->arch.config_lock) {
+		if (test_bit(KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED,
+			     &kvm->arch.flags) &&
+		    kvm_vcpu_init_changed(vcpu, init))
+			return -EINVAL;
+
+		bitmap_copy(kvm->arch.vcpu_features, &features,
+			    KVM_VCPU_MAX_FEATURES);
+
+		kvm_reset_vcpu(vcpu);
+
+		set_bit(KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED,
+			&kvm->arch.flags);
+		vcpu_set_flag(vcpu, VCPU_INITIALIZED);
+	}
+
+	return 0;
+}
+
+static int kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
+			       const struct kvm_vcpu_init *init)
+{
+	int ret;
+
+	if (init->target != KVM_ARM_TARGET_GENERIC_V8)
+		return -EINVAL;
+
+	ret = kvm_vcpu_init_check_features(vcpu, init);
+	if (ret)
+		return ret;
+
+	if (!kvm_vcpu_initialized(vcpu))
+		return kvm_vcpu_initialize(vcpu, init);
+
+	if (kvm_vcpu_init_changed(vcpu, init))
+		return -EINVAL;
+
+	kvm_reset_vcpu(vcpu);
+
+	return 0;
+}
+
+static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,
+					 struct kvm_vcpu_init *init)
+{
+	struct kvm_sae_save_area *save_area = &vcpu->arch.save_area;
+	struct kvm_sae_block *sae_block = &vcpu->arch.sae_block;
+	int ret;
+
+	sae_block->save_area = virt_to_phys(save_area);
+	save_area->sdo = virt_to_phys(sae_block);
+
+	ret = kvm_vcpu_set_target(vcpu, init);
+	if (ret)
+		return ret;
+
+	scoped_guard(spinlock, &vcpu->arch.mp_state_lock) {
+		WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_RUNNABLE);
+	}
+
+	return 0;
+}
+
+int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
+			  bool line_status)
+{
+	/* stub for now*/
+	return -EINVAL;
+}
+
+static void adjust_pc(struct kvm_vcpu *vcpu)
+{
+	if (vcpu_get_flag(vcpu, INCREMENT_PC)) {
+		kvm_skip_instr(vcpu);
+		vcpu_clear_flag(vcpu, INCREMENT_PC);
+	}
+}
+
+static void arm_vcpu_run(struct kvm_vcpu *vcpu)
+{
+	struct kvm_sae_block *sae_block = &vcpu->arch.sae_block;
+
+	adjust_pc(vcpu);
+
+	local_irq_disable();
+	guest_enter_irqoff();
+	local_irq_enable();
+
+	sae_block->icptr = 0;
+
+	sae64a(sae_block);
+
+	local_irq_disable();
+	guest_exit_irqoff();
+	local_irq_enable();
+}
+
+/** kvm_arch_vcpu_ioctl_run() - run arm64 vCPU
+ *
+ * Execute arm64 guest instructions using SAE.
+ *
+ * Returns:
+ * 1 enter the guest (should not be observed by userspace)
+ * 0 exit to userspace
+ * < 0 exit to userspace, where the return value indicates n error
+ *
+ *
+ */
+int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
+{
+	DECLARE_KERNEL_FPU_ONSTACK32(fpu_save);
+	struct kvm_run *kvm_run = vcpu->run;
+	int ret;
+
+	if (kvm_run->exit_reason == KVM_EXIT_MMIO) {
+		ret = kvm_handle_mmio_return(vcpu);
+		if (ret <= 0)
+			return ret;
+	}
+
+	vcpu_load(vcpu);
+
+	kernel_fpu_begin(&fpu_save, KERNEL_FPC | KERNEL_VXR);
+	load_vx_regs((vcpu->arch.ctxt.vregs));
+
+	if (!vcpu->wants_to_run) {
+		ret = -EINTR;
+		goto out;
+	}
+
+	kvm_sigset_activate(vcpu);
+
+	might_fault();
+
+	ret = 1;
+	do {
+		if (signal_pending(current)) {
+			kvm_run->exit_reason = KVM_EXIT_INTR;
+			ret = -EINTR;
+			continue;
+		}
+
+		if (need_resched())
+			schedule();
+
+		if (ret > 0)
+			ret = check_vcpu_requests(vcpu);
+
+		vcpu->arch.sae_block.icptr = 0;
+
+		arm_vcpu_run(vcpu);
+
+		ret = handle_exit(vcpu);
+
+	} while (ret > 0);
+
+	kvm_sigset_deactivate(vcpu);
+out:
+	if (unlikely(vcpu_get_flag(vcpu, INCREMENT_PC)))
+		adjust_pc(vcpu);
+
+	save_vx_regs(vcpu->arch.ctxt.vregs);
+	kernel_fpu_end(&fpu_save, KERNEL_FPC | KERNEL_VXR);
+	vcpu_put(vcpu);
+
+	return ret;
+}
+
+static int kvm_arm_vcpu_set_attr(struct kvm_vcpu *vcpu,
+				 struct kvm_device_attr *attr)
+{
+	int ret;
+
+	switch (attr->group) {
+	default:
+		ret = -ENXIO;
+		break;
+	}
+
+	return ret;
+}
+
+static int kvm_arm_vcpu_get_attr(struct kvm_vcpu *vcpu,
+				 struct kvm_device_attr *attr)
+{
+	int ret;
+
+	switch (attr->group) {
+	default:
+		ret = -ENXIO;
+		break;
+	}
+
+	return ret;
+}
+
+static int kvm_arm_vcpu_has_attr(struct kvm_vcpu *vcpu,
+				 struct kvm_device_attr *attr)
+{
+	int ret;
+
+	switch (attr->group) {
+	default:
+		ret = -ENXIO;
+		break;
+	}
+
+	return ret;
+}
+
+long kvm_arch_vcpu_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
+{
+	struct kvm_vcpu *vcpu = filp->private_data;
+	void __user *argp = (void __user *)arg;
+	struct kvm_device_attr attr;
+	int ret;
+
+	switch (ioctl) {
+	case KVM_ARM_VCPU_INIT: {
+		struct kvm_vcpu_init init;
+
+		ret = -EFAULT;
+		if (copy_from_user(&init, argp, sizeof(init)))
+			break;
+
+		ret = kvm_arch_vcpu_ioctl_vcpu_init(vcpu, &init);
+		break;
+	}
+	case KVM_SET_ONE_REG:
+	case KVM_GET_ONE_REG: {
+		struct kvm_one_reg reg;
+
+		ret = -ENOEXEC;
+		if (unlikely(!kvm_vcpu_initialized(vcpu)))
+			break;
+
+		ret = -EFAULT;
+		if (copy_from_user(&reg, argp, sizeof(reg)))
+			break;
+
+		if (kvm_check_request(KVM_REQ_VCPU_RESET, vcpu))
+			kvm_reset_vcpu(vcpu);
+
+		if (ioctl == KVM_SET_ONE_REG)
+			ret = kvm_arm_set_reg(vcpu, &reg);
+		else
+			ret = kvm_arm_get_reg(vcpu, &reg);
+		break;
+	}
+	case KVM_GET_REG_LIST: {
+		struct kvm_reg_list __user *user_list = argp;
+		struct kvm_reg_list reg_list;
+		unsigned int n;
+
+		ret = -ENOEXEC;
+		if (unlikely(!kvm_vcpu_initialized(vcpu)))
+			break;
+		ret = -EPERM;
+		if (!kvm_arm_vcpu_is_finalized(vcpu))
+			break;
+		ret = -EFAULT;
+		if (copy_from_user(&reg_list, user_list, sizeof(reg_list)))
+			break;
+		n = reg_list.n;
+		reg_list.n = kvm_arm_num_regs(vcpu);
+		if (copy_to_user(user_list, &reg_list, sizeof(reg_list)))
+			break;
+		ret = -E2BIG;
+		if (n < reg_list.n)
+			break;
+		ret = kvm_arm_copy_reg_indices(vcpu, user_list->reg);
+		break;
+	}
+	case KVM_ARM_VCPU_FINALIZE: {
+		int what;
+
+		if (!kvm_vcpu_initialized(vcpu))
+			return -ENOEXEC;
+
+		if (get_user(what, (const int __user *)argp))
+			return -EFAULT;
+
+		ret = kvm_arm_vcpu_finalize(vcpu, what);
+		break;
+	}
+	case KVM_SET_DEVICE_ATTR: {
+		ret = -EFAULT;
+		if (copy_from_user(&attr, argp, sizeof(attr)))
+			break;
+		ret = kvm_arm_vcpu_set_attr(vcpu, &attr);
+		break;
+	}
+	case KVM_GET_DEVICE_ATTR: {
+		ret = -EFAULT;
+		if (copy_from_user(&attr, argp, sizeof(attr)))
+			break;
+		ret = kvm_arm_vcpu_get_attr(vcpu, &attr);
+		break;
+	}
+	case KVM_HAS_DEVICE_ATTR: {
+		ret = -EFAULT;
+		if (copy_from_user(&attr, argp, sizeof(attr)))
+			break;
+		ret = kvm_arm_vcpu_has_attr(vcpu, &attr);
+		break;
+	}
+	default:
+		ret = -EINVAL;
+	}
+
+	return ret;
+}
+
 int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
 			       struct kvm_dirty_log *log)
 {
arch/s390/kvm/arm64/guest.c +45 -2

59 lines not on this page · raw message

arch/s390/kvm/arm64/handle_exit.c +31 -0
index ed872cd804dc..1286a64783e0 100644
@@ -5,6 +5,8 @@
 #include <arm64/esr.h>
 #include <arm64/kvm_emulate.h>
 
+#include "handle_exit.h"
+
 typedef int (*exit_handle_fn)(struct kvm_vcpu *);
 static exit_handle_fn arm_exit_handlers[ESR_ELx_EC_MAX + 1];
 
@@ -55,6 +57,35 @@ static exit_handle_fn arm_exit_handlers[] = {
 	[ESR_ELx_EC_HVC64]	= handle_hvc,
 };
 
+/*
+ * Return > 0 to return to guest, < 0 on error, 0 (and set exit_reason) on
+ * proper exit to userspace.
+ */
+int handle_exit(struct kvm_vcpu *vcpu)
+{
+	u8 icptr = vcpu->arch.sae_block.icptr;
+	int ret = 1;
+
+	switch (icptr) {
+	case SAE_ICPTR_SPURIOUS:
+		break;
+	case SAE_ICPTR_VALIDITY:
+		WARN_ONCE(true, "SAE: validity intercept. vir: 0x%04x",
+			  vcpu->arch.sae_block.vir);
+		ret = -EINVAL;
+		break;
+	case SAE_ICPTR_HOST_ACCESS_EXCEPTION:
+	case SAE_ICPTR_SYNCHRONOUS_EXCEPTION:
+		ret = handle_trap_exceptions(vcpu);
+		break;
+	default:
+		WARN_ONCE(true, "SAE: unknown interception reason 0x%02x",
+			  icptr);
+		ret = -EINVAL;
+	}
+	return ret;
+}
+
 /* manually copied from arch/arm64/kernel/traps.c */
 static const char * const esr_class_str[] = {
 	[0 ... ESR_ELx_EC_MAX]		= "UNRECOGNIZED EC",
arch/s390/kvm/arm64/handle_exit.h new file +9 -0
new file mode 100644
index 000000000000..65ae58721537
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef KVM_ARM64_HANDLE_EXIT_H
+#define KVM_ARM64_HANDLE_EXIT_H
+
+#include <linux/kvm_host.h>
+
+int handle_exit(struct kvm_vcpu *vcpu);
+
+#endif /* KVM_ARM64_HANDLE_EXIT_H */
arch/s390/kvm/arm64/reset.c new file +73 -0

73 lines not on this page · raw message

arch/s390/kvm/arm64/reset.h new file +11 -0
new file mode 100644
index 000000000000..a5c5304e47bc
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef KVM_ARM_RESET_H
+#define KVM_ARM_RESET_H
+
+#include <linux/kvm_host.h>
+
+bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu);
+void kvm_reset_vcpu(struct kvm_vcpu *vcpu);
+int kvm_arm_vcpu_finalize(struct kvm_vcpu *vcpu, int feature);
+
+#endif /* KVM_ARM_RESET_H */
arch/s390/kvm/arm64/trace.h +1 -1
index 3a5dcd039c13..1e3cb6108196 100644
@@ -5,7 +5,7 @@
 #include <linux/tracepoint.h>
 
 #undef TRACE_SYSTEM
-#define TRACE_SYSTEM kvm
+#define TRACE_SYSTEM kvm_arm64
 
 #endif /* KVM_ARM64_TRACE_KVM_H */
 
Signature · 1 line
2.53.0
author reviewer
#93 lore raw

PATCH v6 32/33 KVM: s390: arm64: Implement basic page fault handler

In reply to Steffen Eiden

Add host functionality to page in guest memory. If the guest does something unexpected or illegal exit to userspace abort guest execution. This behaviour will be changed to guest error injects once all sysregs are accessible for the host.

---
 arch/s390/kvm/arm64/handle_exit.c |   2 +
 arch/s390/kvm/arm64/mmio.c        |  15 +++
 arch/s390/kvm/arm64/mmu.c         | 177 ++++++++++++++++++++++++++++++
 arch/s390/kvm/arm64/trace.h       |  24 ++++
 4 files changed, 218 insertions(+)
 create mode 100644 arch/s390/kvm/arm64/mmio.c
 create mode 100644 arch/s390/kvm/arm64/mmu.c
arch/s390/kvm/arm64/handle_exit.c +2 -0
index 1286a64783e0..8b03e8ee5acf 100644
@@ -55,6 +55,8 @@ static int handle_hvc(struct kvm_vcpu *vcpu)
 static exit_handle_fn arm_exit_handlers[] = {
 	[0 ... ESR_ELx_EC_MAX]	= kvm_handle_unknown_ec,
 	[ESR_ELx_EC_HVC64]	= handle_hvc,
+	[ESR_ELx_EC_IABT_LOW]	= kvm_handle_guest_abort,
+	[ESR_ELx_EC_DABT_LOW]	= kvm_handle_guest_abort,
 };
 
 /*
arch/s390/kvm/arm64/mmio.c new file +15 -0
new file mode 100644
index 000000000000..908a6b43ddf7
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/kvm_host.h>
+#include <linux/bitfield.h>
+
+#include <trace/events/kvm.h>
+
+#include <arm64/kvm_emulate.h>
+#include <arm64/sysreg.h>
+
+#include "trace.h"
+
+#define __INCL_GEN_ARM_FILE
+#include "generated/mmio.inc"
+#undef __INCL_GEN_ARM_FILE
arch/s390/kvm/arm64/mmu.c new file +177 -0

177 lines not on this page · raw message

arch/s390/kvm/arm64/trace.h +24 -0
index 1e3cb6108196..2a205ba0165c 100644
@@ -7,6 +7,30 @@
 #undef TRACE_SYSTEM
 #define TRACE_SYSTEM kvm_arm64
 
+TRACE_EVENT(kvm_mmio_nisv,
+	TP_PROTO(unsigned long vcpu_pc, unsigned long esr,
+		 unsigned long far, unsigned long ipa),
+	TP_ARGS(vcpu_pc, esr, far, ipa),
+
+	TP_STRUCT__entry(
+		__field(	unsigned long,	vcpu_pc		)
+		__field(	unsigned long,	esr		)
+		__field(	unsigned long,	far		)
+		__field(	unsigned long,	ipa		)
+	),
+
+	TP_fast_assign(
+		__entry->vcpu_pc		= vcpu_pc;
+		__entry->esr			= esr;
+		__entry->far			= far;
+		__entry->ipa			= ipa;
+	),
+
+	TP_printk("ipa %#016lx, esr %#016lx, far %#016lx, pc %#016lx",
+		  __entry->ipa, __entry->esr,
+		  __entry->far, __entry->vcpu_pc)
+);
+
 #endif /* KVM_ARM64_TRACE_KVM_H */
 
 #undef TRACE_INCLUDE_PATH
Signature · 1 line
2.53.0
author reviewer
#36 lore raw

PATCH v6 11/33 KVM: arm64: Share arm64 code with s390

In reply to Steffen Eiden

Mark functions that s390 can use to implement arm on s390 as shared functions.

No functional change.

---
 arch/arm64/kvm/arm.c         | 3 +++
 arch/arm64/kvm/guest.c       | 6 ++++++
 arch/arm64/kvm/handle_exit.c | 6 ++++++
 arch/arm64/kvm/mmio.c        | 2 ++
 4 files changed, 17 insertions(+)
arch/arm64/kvm/arm.c +3 -0
index 8b080804bc90..6b92a3c1d490 100644
@@ -1603,6 +1603,7 @@ static unsigned long system_supported_vcpu_features(void)
 	return features;
 }
 
+#ifdef ARM64_S390_COMMON
 static int kvm_vcpu_init_check_features(struct kvm_vcpu *vcpu,
 					const struct kvm_vcpu_init *init)
 {
@@ -1656,6 +1657,8 @@ static bool kvm_vcpu_init_changed(struct kvm_vcpu *vcpu,
 			     KVM_VCPU_MAX_FEATURES);
 }
 
+#endif /* ARM64_S390_COMMON */
+
 static int kvm_setup_vcpu(struct kvm_vcpu *vcpu)
 {
 	struct kvm *kvm = vcpu->kvm;
arch/arm64/kvm/guest.c +6 -0
index 773f6c8e5026..6ca5a9f357cd 100644
@@ -62,6 +62,7 @@ const struct kvm_stats_header kvm_vcpu_stats_header = {
 		       sizeof(kvm_vcpu_stats_desc),
 };
 
+#ifdef ARM64_S390_COMMON
 static bool core_reg_offset_is_vreg(u64 off)
 {
 	return off >= KVM_REG_ARM_CORE_REG(fp_regs.vregs) &&
@@ -306,6 +307,8 @@ static int set_core_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 	return err;
 }
 
+#endif /* ARM64_S390_COMMON */
+
 #define vq_word(vq) (((vq) - SVE_VQ_MIN) / 64)
 #define vq_mask(vq) ((u64)1 << ((vq) - SVE_VQ_MIN) % 64)
 #define vq_present(vqs, vq) (!!((vqs)[vq_word(vq)] & vq_mask(vq)))
@@ -543,6 +546,7 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
 	return -EINVAL;
 }
 
+#ifdef ARM64_S390_COMMON
 static int copy_core_reg_indices(const struct kvm_vcpu *vcpu,
 				 u64 __user *uindices)
 {
@@ -591,6 +595,8 @@ static unsigned long num_core_regs(const struct kvm_vcpu *vcpu)
 	return copy_core_reg_indices(vcpu, NULL);
 }
 
+#endif /* ARM64_S390_COMMON */
+
 static unsigned long num_sve_regs(const struct kvm_vcpu *vcpu)
 {
 	const unsigned int slices = vcpu_sve_slices(vcpu);
arch/arm64/kvm/handle_exit.c +6 -0
index 29108e5c0206..6a6ef2c074f4 100644
@@ -213,6 +213,7 @@ static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu)
 	return 0;
 }
 
+#ifdef ARM64_S390_COMMON
 static int kvm_handle_unknown_ec(struct kvm_vcpu *vcpu)
 {
 	u64 esr = kvm_vcpu_get_esr(vcpu);
@@ -224,6 +225,8 @@ static int kvm_handle_unknown_ec(struct kvm_vcpu *vcpu)
 	return 1;
 }
 
+#endif /* ARM64_S390_COMMON */
+
 /*
  * Guest access to SVE registers should be routed to this handler only
  * when the system doesn't support SVE.
@@ -404,6 +407,7 @@ static exit_handle_fn arm_exit_handlers[] = {
 	[ESR_ELx_EC_GCS]	= kvm_handle_gcs,
 };
 
+#ifdef ARM64_S390_COMMON
 static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu)
 {
 	u64 esr = kvm_vcpu_get_esr(vcpu);
@@ -439,6 +443,8 @@ static int handle_trap_exceptions(struct kvm_vcpu *vcpu)
 	return handled;
 }
 
+#endif /* ARM64_S390_COMMON */
+
 /*
  * Return > 0 to return to guest, < 0 on error, 0 (and set exit_reason) on
  * proper exit to userspace.
arch/arm64/kvm/mmio.c +2 -0
index d1c3a352d5a2..5161102da507 100644
@@ -10,6 +10,7 @@
 
 #include "trace.h"
 
+#ifdef ARM64_S390_COMMON
 void kvm_mmio_write_buf(void *buf, unsigned int len, unsigned long data)
 {
 	void *datap = NULL;
@@ -258,3 +259,4 @@ int io_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa)
 	run->exit_reason	= KVM_EXIT_MMIO;
 	return 0;
 }
+#endif /* ARM64_S390_COMMON */
Signature · 1 line
2.53.0
author reviewer
#68 lore raw

PATCH v6 22/33 KVM: s390: Prepare KVM/s390 for a second KVM module

In reply to Steffen Eiden

The second KVM module will have a different Kconfig set. When both modules are compiled the Kconfig sets get merged and the native s390 KVM needs to implement functionality required by the respective config options. Ensure that s390-KVM will still compile by implementing a stub for kvm_arch_vcpu_run_pid_change if CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE is enabled and defining KVM_NO_MMIO to disable KVM_MMIO.

---
 arch/s390/include/asm/kvm_host_s390.h | 1 +
 arch/s390/kvm/s390/s390.c             | 8 ++++++++
 2 files changed, 9 insertions(+)
arch/s390/include/asm/kvm_host_s390.h +1 -0
index cd692f8fb764..207f44cb86d9 100644
@@ -29,6 +29,7 @@
 
 #define KVM_HAVE_MMU_RWLOCK
 #define KVM_MAX_VCPUS 255
+#define KVM_NO_MMIO
 
 #define KVM_INTERNAL_MEM_SLOTS 1
 
arch/s390/kvm/s390/s390.c +8 -0
index 1d0d94f000f7..d1e736e1f06f 100644
@@ -5868,6 +5868,14 @@ bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range)
 	return gmap_unmap_gfn_range(kvm->arch.gmap, range->slot, range->start, range->end);
 }
 
+#ifdef CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE
+/* Make s390 compile if arm64-on-s390 is selected */
+int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu)
+{
+	return 0;
+}
+#endif /* CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE */
+
 static inline unsigned long nonhyp_mask(int i)
 {
 	unsigned int nonhyp_fai = (sclp.hmfai << i * 2) >> 30;
Signature · 1 line
2.53.0
#11 lore raw

Re: [PATCH v6 05/33] arm64: ptrace: Use constants for compat register numbers

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines

Define an enum to determine the register number for the mapping from AArch32 and AArch64 registers. This allows for a more flexible use of the register mappings.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#14 lore raw

Re: [PATCH v6 06/33] arm64: sysreg: Convert SPSR_ELx to automatic register generation

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines

Convert SPSR_EL{1, 2, 12} to automatic register generation as per DDIO616 2026-06. No functional change.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#18 lore raw

Re: [PATCH v6 07/33] KVM: arm64: Access elements of vcpu_gp_regs individually

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

While for arm64 the members of vcpu_gp_regs are allocated continuous this is not necessarily true for other architectures implementing ARM.

Let vcpu_gp_regs() no longer return the address of the user_pt_regs in the vcpu context but the address of the gp-register array field in the user_pt_reg struct. Note, this change semantically excludes pc from the GPRs.

Quoted 5 lines

No functional change.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#6 lore raw

Re: [PATCH v6 03/33] KVM: Allow KVM implementations to switch off MMIO independent of Kconfig

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines

Only defining KVM_MMIO is not flexible enough for multi-KVM systems where one KVM implements MMIO but others do not. Solve this by additionally testing for the non-existence of KVM_NO_MMIO before including MMIO code to KVM.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#21 lore raw

Re: [PATCH v6 08/33] KVM: arm64: Use accessor functions for core regs

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

Instead of accessing the value directly use assessor function that abstract the actual location of the register values. Add a helper function to reset fpsimd registers. Enable other KVM implementations to reuse this code.

No functional changes.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
#8 lore raw

Re: [PATCH v6 04/33] arm64: Use proper include variant

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines

Use <> for including the sysreg header as it is not discoverable from the current directory.

Fixes c07d8017bceb ("arm64/sysreg: Enable automatic generation of system register definitions")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#28 lore raw

Re: [PATCH v6 09/33] arm64: Prepare sharing arm64 headers with s390

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

Prepare the sharing of arm64 headers with s390 by moving a few definitions inside headers to reduce the number of shared markers. Clean up some includes to further streamline the sharing of headers.

No functional change.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
#42 lore raw

Re: [PATCH v6 13/33] KVM: s390: Prepare include guards for a new location

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

Update include guard names in dat.h, faultin.h, and gmap.h to ARCH_KVM_GMAP_* to reflect their upcoming relocation to a shared gmap directory.

No functional change.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
#48 lore raw

Re: [PATCH v6 15/33] KVM: s390: Move kvm_host definitions to kvm_host_s390

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

Rename kvm_host.h to kvm_host_s390.h and kvm_host_types.h to kvm_host_s390_types.h to distinguish s390-specific KVM definitions from the generic kvm_host.h that will be used for shared definitions.

No functional change.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
#39 lore raw

Re: [PATCH v6 12/33] KVM: s390: Extract gmap tracing to a separate header

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines

Move the kvm_s390_major_guest_pfault trace event from trace.h to a new trace_gmap.h header. This separates gmap-specific tracing from general KVM/s390 tracing, preparing for code sharing between multiple KVM implementations.

Quoted 7 lines

The trace event definition is updated to use local defines for parameters so that they can be replaced later with ease for when another KVM implementation uses these traces.

No functional change.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
#45 lore raw

Re: [PATCH v6 14/33] KVM: s390: Rename kvm-s390.{c,h} to s390.{c,h}

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

Rename kvm-s390.c to s390.c and kvm-s390.h to s390.h for consistency with the new directory structure. Update all include statements and simplify Makefile ccflags from explicit paths to -I$(src).

No functional change.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
#37 lore raw

Re: [PATCH v6 11/33] KVM: arm64: Share arm64 code with s390

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines

Mark functions that s390 can use to implement arm on s390 as shared functions.

No functional change.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
#2 lore raw

Re: [PATCH v6 01/33] vfio: Use file-based reference counting for KVM

In reply to Steffen Eiden
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Critical] VFIO retains a dangling weak pointer to the KVM VM `struct file` when the VM fd is closed…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] VFIO retains a dangling weak pointer to the KVM VM struct file when the VM fd is closed, leading to use-after-free and type confusion if the file memory is reallocated.
- [Medium] Direct, unsafe access to the RCU-protected pointer kvm->file without using RCU primitives.
--

--- Patch [1]: [PATCH v6 01/33] vfio: Use file-based reference counting for KVM --- commit fbb73952530ea819e76b37873395b8b6ce2e0444
Author: Steffen Eiden <[email protected]>

vfio: Use file-based reference counting for KVM

This commit replaces manual module reference counting with file-based reference counting for KVM integration. It updates the VFIO-KVM interface to pass struct file pointers instead of struct kvm pointers, relying on get_file_active() and fput() for reference management.

Quoted 4 lines
drivers/s390/crypto/vfio_ap_ops.c +0 -0
index 99a0efd999ef9..875e67063d8e5 100644

[ ... ]

Quoted 15 lines
drivers/s390/crypto/vfio_ap_ops.c +5 -3
@@ -1822,12 +1823,25 @@ static const struct attribute_group *vfio_ap_mdev_attr_groups[] = {
  * @matrix_mdev: a mediated matrix device
  * @kvm: reference to KVM instance
  *
- * Return: 0 if no other mediated matrix device has a reference to @kvm;
- * otherwise, returns an -EPERM.
+ * Returns: 0 if the reference to kvm is successfully retrieved from @kvm_file
+ * and set into @matrix_mdev; otherwise, returns:
+ *	-ENOENT if a reference to kvm could not be retrieved from @kvm_file
+ *	-EPERM if another mediated matrix device already has a reference to the same kvm instance
  */
 static int vfio_ap_mdev_set_kvm(struct ap_matrix_mdev *matrix_mdev,
-				struct kvm *kvm)
+				struct file **kvm_file)
 {

drivers/s390/crypto/vfio_ap_ops.c static const struct attribute_group *vfio_ap_mdev_attr_groups[] = { · line 1843

Quoted 10 lines
drivers/s390/crypto/vfio_ap_ops.c +10 -0
+	struct file *kvm_file_ref __free(fput) = NULL;
+	struct kvm *kvm;
+
+	kvm_file_ref = get_file_active(kvm_file);
+	if (!kvm_file_ref)
+		return -ENOENT;
+
+	kvm = kvm_file_ref->private_data;
+	if (!kvm)
+		return -ENOENT;

[Severity: Critical]
If kvm_file_ref points to a file that was freed and reallocated to a completely different type of file (due to SLAB_TYPESAFE_BY_RCU), could this cause type confusion?

Since struct file memory can be reused, extracting private_data without first verifying the file's operations (f_op) could lead to arbitrary memory corruption. Should this code use file_is_kvm() or file_to_kvm() before dereferencing private_data?

Quoted 4 lines
drivers/vfio/pci/vfio_pci_zdev.c +0 -0
index 0990fdb146b78..d3a1101013531 100644

[ ... ]

Quoted 9 lines
drivers/vfio/pci/vfio_pci_zdev.c +1 -0
@@ -144,6 +144,7 @@ int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,
 int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev)
 {
 	struct zpci_dev *zdev = to_zpci(vdev->pdev);
+	struct kvm *kvm;
 
 	if (!zdev)
 		return -ENODEV;

drivers/vfio/pci/vfio_pci_zdev.c int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev) · line 157

Quoted 6 lines
drivers/vfio/pci/vfio_pci_zdev.c +3 -0
@@ -151,8 +152,12 @@ int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev)
 	if (!vdev->vdev.kvm)
 		return 0;
 
+	kvm = vdev->vdev.kvm->private_data;
+	if (!kvm)
+		return -ENOENT;

[Severity: Critical]
Does this code also need to validate that vdev->vdev.kvm is actually a KVM file before interpreting its private_data as a struct kvm pointer?

Quoted 4 lines
drivers/vfio/vfio_main.c +0 -0
index 423ead48aafe3..b06d1a9116051 100644

[ ... ]

Quoted 8 lines
drivers/vfio/vfio_main.c +1 -2
@@ -472,36 +472,17 @@ void vfio_unregister_group_dev(struct vfio_device *device)
 EXPORT_SYMBOL_GPL(vfio_unregister_group_dev);
 
 #if IS_ENABLED(CONFIG_KVM)
-void vfio_device_get_kvm_safe(struct vfio_device *device, struct kvm *kvm)
+void vfio_device_get_kvm_safe(struct vfio_device *device, struct file **kvm)
 {
-	void (*pfn)(struct kvm *kvm);

drivers/vfio/vfio_main.c void vfio_unregister_group_dev(struct vfio_device *device) · line 483

Quoted 10 lines
drivers/vfio/vfio_main.c +3 -3
-	bool (*fn)(struct kvm *kvm);
-	bool ret;
+	struct file *kvm_file_ref __free(fput) = NULL;
 
 	lockdep_assert_held(&device->dev_set->lock);
 
-	if (!kvm)
+	kvm_file_ref = get_file_active(kvm);
+	if (!kvm_file_ref)
 		return;

[Severity: Critical]
Can this result in getting a reference to a completely unrelated file object?

If userspace opens a KVM VM and creates a KVM VFIO device (taking a reference to the kvm object), VFIO stores a weak pointer to the KVM struct file.

If userspace then closes the KVM VM fd while keeping the KVM VFIO device fd open:

1. The VM fd closes, dropping the f_count to 0 and freeing the struct file via RCU.
2. The kvm->users_count remains > 0 (due to the open KVM VFIO device fd), so kvm_destroy_vm() is never called to clear the VFIO weak pointer.
3. Because struct file uses SLAB_TYPESAFE_BY_RCU, the freed memory can be reallocated to a completely unrelated file.

When get_file_active() is later called here on the dangling pointer, wouldn't it successfully take a reference on the reused struct file?

Quoted 4 lines
virt/kvm/vfio.c +0 -0
index 6cdc4e9a333a3..0166cc4d39b31 100644

[ ... ]

virt/kvm/vfio.c static int kvm_vfio_file_add(struct kvm_device *dev, unsigned int fd) · line 171

Quoted 6 lines
virt/kvm/vfio.c +1 -1
@@ -168,7 +168,7 @@ static int kvm_vfio_file_add(struct kvm_device *dev, unsigned int fd)
 	kvf->file = get_file(filp);
 	list_add_tail(&kvf->node, &kv->file_list);
 
-	kvm_vfio_file_set_kvm(kvf->file, dev->kvm);
+	kvm_vfio_file_set_kvm(kvf->file, dev->kvm->file);

[Severity: Medium]
Is it safe to access dev->kvm->file directly here?

Since kvm->file is explicitly annotated as a __rcu pointer in struct kvm, shouldn't this be accessed within an RCU read-side critical section using rcu_dereference() to avoid data races with kvm_vm_release()?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#51 lore raw

Re: [PATCH v6 16/33] KVM: s390: Move s390 kvm code into a subdirectory

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines

Move all the code required to run s390 KVM guests on s390 to a s390 subdirectory. Move gmap related code into a gmap directory to later share gmap code between KVM implementations.

Update S390 VFIO-PCI MAINTAINERS filepath.

No functional change.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16
#54 lore raw

Re: [PATCH v6 17/33] KVM: s390: Move PGM code definitions to asm/kvm_host.h

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

Move PGM code definitions from kvm_host_s390.h (back) to the generic kvm_host.h. These definitions are needed by multiple KVM implementations and should be in a shared location.

No functional change.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
#60 lore raw

Re: [PATCH v6 19/33] KVM: s390: gmap: Make storage keys optional

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines

Guard guest storage key handling behind KVM_S390_MANAGES_S390_GUEST. This enables other KVM implementations to use gmap without implementing storage key infrastructure. Define KVM_S390_MANAGES_S390_GUEST to 1 for KVM hosts managing s390 guests (in kvm_host_s390.h). A KVM implementation not implementing those features must define KVM_S390_MANAGES_S390_GUEST to 0 in its kvm_host_<guest_arch>.h.

No functional changes besides the new guard.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=19
#66 lore raw

Re: [PATCH v6 21/33] KVM: s390: gmap: Make prefix handling optional

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines

Guard guest prefix handling behind KVM_S390_MANAGES_S390_GUEST. This enables other KVM implementations to use gmap without implementing prefix handling. The prefix handling is integrated deeply in the gmap implementation. Therefore, provide safe default implementations for the guarded functions.

No functional changes.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=21
#4 lore raw

Re: [PATCH v6 02/33] KVM: Make device name configurable

In reply to Steffen Eiden
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] Calling `kvm_init_with_dev()` multiple times within the same module to support multiple…

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Calling kvm_init_with_dev() multiple times within the same module to support multiple simultaneous KVM implementations corrupts KVM's static singleton state and guarantees list corruption.
- [High] kvm_init_with_dev is not exported, making it unusable by independent loadable KVM architecture modules.
- [Medium] The patch fails to parameterize the kvm_gmem_inode_cache name, causing a sysfs kmem_cache name collision when multiple KVM implementations are loaded simultaneously.
- [Medium] The patch silently adds the SLAB_ACCOUNT flag to the async page fault kmem_cache without justification in the commit message.
--

--- Patch [2]: [PATCH v6 02/33] KVM: Make device name configurable --- commit fddf3fec3ead355cf194e06551ca60993f2aec03
Author: Steffen Eiden <[email protected]>

KVM: Make device name configurable

Allow KVM implementations to choose alternative device names. This is especially useful for architectures providing multiple KVM implementations simultaneously.

Quoted 4 lines
virt/kvm/async_pf.c +0 -0
index b8aaa96b799bf..0157612491070 100644

[ ... ]

virt/kvm/async_pf.c line 32

Quoted 13 lines
virt/kvm/async_pf.c +10 -2
-int kvm_async_pf_init(void)
+int kvm_async_pf_init(const char *cache_name)
 {
-	async_pf_cache = KMEM_CACHE(kvm_async_pf, 0);
+	char *full_cache_name;
+
+	full_cache_name = kasprintf(GFP_KERNEL, "%s_async_pf", cache_name);
+	if (!full_cache_name)
+		return -ENOMEM;
+
+	async_pf_cache = kmem_cache_create(full_cache_name,
+					   sizeof(struct kvm_async_pf), 0,
+					   SLAB_ACCOUNT, NULL);

[Severity: Medium]
Does this silently introduce a behavior change? The previous KMEM_CACHE call passed 0 for flags, but this adds SLAB_ACCOUNT. While accounting these to the vCPU's memory cgroup is likely correct, shouldn't this functional change be documented in the commit message?

Quoted 4 lines
virt/kvm/async_pf.c +1 -0
+	kfree(full_cache_name);
 
 	if (!async_pf_cache)
 		return -ENOMEM;

[ ... ]

Quoted 4 lines
virt/kvm/kvm_main.c +0 -0
index 0d80730e84240..0b34477bf325b 100644

[ ... ]

virt/kvm/kvm_main.c void kvm_unregister_perf_callbacks(void) · line 6528

Quoted 9 lines
virt/kvm/kvm_main.c +6 -0
+int kvm_init_with_dev(unsigned int vcpu_size, unsigned int vcpu_align,
+		      struct module *module, const char *dev_name, int minor)
+{
+	char *cache_name;
 	int r;
 	int cpu;
 
+	kvm_dev.minor = minor;
+	kvm_dev.name = kstrdup_const(dev_name, GFP_KERNEL);

[Severity: High]
Can calling kvm_init_with_dev() multiple times corrupt the static miscdevice and list state?

If multiple KVM implementations share the same kvm_main.o core and call this initialization, they will unconditionally overwrite the shared static kvm_dev struct. Calling misc_register(&kvm_dev) a second time with the exact same static struct would overwrite its list_head pointers, which structurally guarantees misc_list corruption and a fatal kernel panic on the next traversal.

Quoted 4 lines
virt/kvm/kvm_main.c +3 -0
+	if (!kvm_dev.name)
+		return -ENOMEM;
+
 	/* A kmem cache lets us meet the alignment requirements of fx_save. */

virt/kvm/kvm_main.c void kvm_unregister_perf_callbacks(void) · line 6541

Quoted 10 lines
virt/kvm/kvm_main.c +6 -1
 	if (!vcpu_align)
 		vcpu_align = __alignof__(struct kvm_vcpu);
+
+	r = -ENOMEM;
+	cache_name = kasprintf(GFP_KERNEL, "%s_vcpu", dev_name);
+	if (!cache_name)
+		goto err_dev_name;
 	kvm_vcpu_cache =
-		kmem_cache_create_usercopy("kvm_vcpu", vcpu_size, vcpu_align,
+		kmem_cache_create_usercopy(cache_name, vcpu_size, vcpu_align,

[Severity: High]
Doesn't this also unconditionally overwrite the global kvm_vcpu_cache pointer and leak the previous cache when multiple implementations initialize?

Quoted 3 lines
virt/kvm/kvm_main.c +0 -0
 					   SLAB_ACCOUNT,
 					   offsetof(struct kvm_vcpu, arch),
 					   offsetofend(struct kvm_vcpu, stats_id)

[ ... ]

virt/kvm/kvm_main.c int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module) · line 6622

Quoted 9 lines
virt/kvm/kvm_main.c +2 -0
@@ -6597,6 +6615,8 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)
 	for_each_possible_cpu(cpu)
 		free_cpumask_var(per_cpu(cpu_kick_mask, cpu));
 	kmem_cache_destroy(kvm_vcpu_cache);
+err_dev_name:
+	kfree_const(kvm_dev.name);
 	return r;
 }
 EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_init);

[Severity: High]
Should kvm_init_with_dev() be exported? The commit states it is meant for architectures providing multiple KVM implementations simultaneously, but without an export macro like EXPORT_SYMBOL_FOR_KVM_INTERNAL, external loadable architecture modules will fail to link against it.

[Severity: Medium]
Also, if multiple implementations are statically linked to avoid the missing export, wouldn't kvm_gmem_init() (called earlier in this function) cause a sysfs naming collision?

It does not take a dev_name parameter and hardcodes the name "kvm_gmem_inode_cache". Because SLAB_ACCOUNT caches are unmergeable, the second creation attempt will fail sysfs registration and emit a SLUB error in dmesg.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#63 lore raw

Re: [PATCH v6 20/33] KVM: s390: gmap: Make CMMA optional

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines

Guard guest CMMA behind KVM_S390_MANAGES_S390_GUEST. This enables other KVM implementations to use gmap without implementing CMMA.

No functional changes.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=20
#57 lore raw

Re: [PATCH v6 18/33] KVM: s390: Prepare gmap for a second KVM implementation

In reply to Steffen Eiden
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [Critical] This problem wasn't introduced by this patch, but an unrecoverable failure in s390_kvm_mmu_commit_memory_region() leaves hardware page tables out of sync with KVM memslots.
- [High] This problem wasn't introduced by this patch, but non-atomic clear of dirty_bitmap in s390_kvm_mmu_get_dirty_log() causes dirty page tracking loss. --

--- Patch [18]: [PATCH v6 18/33] KVM: s390: Prepare gmap for a second KVM implementation --- commit e0cdf68355be56510fa59547630f7974c617a6a1
Author: Steffen Eiden <[email protected]>

KVM: s390: Prepare gmap for a second KVM implementation

Refactor gmap code such that a second s390 (host) KVM implementation can use the gmap code as well. Move mmu code from s390 to gmap so the other KVM implementation can use it as well.

No functional change.

Quoted 6 lines
arch/s390/kvm/gmap/kvm_mmu.c new file +0 -0
new file mode 100644
index 0000000000000..b08b8229bb6ff
@@ -0,0 +1,133 @@

[ ... ]

Quoted 5 lines
arch/s390/kvm/gmap/kvm_mmu.c new file +5 -0
+/*
+ * Get (and clear) the dirty memory log for a memory slot.
+ */
+int s390_kvm_mmu_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
+{

[ ... ]

arch/s390/kvm/gmap/kvm_mmu.c line 37

Quoted 4 lines
arch/s390/kvm/gmap/kvm_mmu.c new file +4 -0
+	/* Clear the dirty log */
+	if (is_dirty) {
+		n = kvm_dirty_bitmap_bytes(memslot);
+		memset(memslot->dirty_bitmap, 0, n);

[Severity: High]
This isn't a bug introduced by this patch, but in s390_kvm_mmu_get_dirty_log() is it safe to use a non-atomic memset() here? If mark_page_dirty() sets bits concurrently (e.g. via DMA or adapter interrupts) using atomic set_bit_le(), this non-atomic memset() might overwrite those newly dirtied bits. Could this lead to lost dirty page tracking and data corruption post-migration?

Quoted 6 lines
arch/s390/kvm/gmap/kvm_mmu.c new file +6 -0
+	}
+	r = 0;
+out:
+	mutex_unlock(&kvm->slots_lock);
+	return r;
+}

[ ... ]

Quoted 7 lines
arch/s390/kvm/gmap/kvm_mmu.c new file +7 -0
+void s390_kvm_mmu_commit_memory_region(struct kvm *kvm,
+				       struct kvm_memory_slot *old,
+				       const struct kvm_memory_slot *new,
+				       enum kvm_mr_change change)
+{
+	struct kvm_s390_mmu_cache *mc __free(kvm_s390_mmu_cache) = NULL;
+	int rc = 0;

arch/s390/kvm/gmap/kvm_mmu.c line 107

Quoted 10 lines
arch/s390/kvm/gmap/kvm_mmu.c new file +10 -0
+
+	guard(mutex)(&kvm->slots_arch_lock);
+
+	if (change == KVM_MR_FLAGS_ONLY)
+		return;
+
+	mc = kvm_s390_new_mmu_cache();
+	if (!mc) {
+		rc = -ENOMEM;
+		goto out;

[Severity: Critical]
This is a pre-existing issue, but in s390_kvm_mmu_commit_memory_region(), could this early return on allocation failure leave hardware page tables out of sync with KVM memslots? If an unprivileged userspace process deletes a memslot and triggers KVM_MR_DELETE, jumping to the out label skips dat_delete_slot(). The generic KVM code removes the memslot, but the guest hardware could retain the physical memory mapping, potentially allowing the guest to access stale or reallocated host memory.

Quoted 8 lines
arch/s390/kvm/gmap/kvm_mmu.c new file +8 -0
+	}
+
+	scoped_guard(write_lock, &kvm->mmu_lock) {
+		kvm_s390_update_cmma_dirty(kvm, old);
+		switch (change) {
+		case KVM_MR_DELETE:
+			rc = dat_delete_slot(mc, kvm->arch.gmap->asce, old->base_gfn, old->npages);
+			break;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=18
#79 lore raw

Re: [PATCH v6 27/33] s390/hwcaps: Report SAE support as hwcap

In reply to Steffen Eiden
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

From: Hendrik Brueckner <[email protected]>

Report SAE support as hwcap (and /proc/cpuinfo)

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=27
#73 lore raw

Re: [PATCH v6 24/33] KVM: s390: Use arm64 code

In reply to Steffen Eiden
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Potential Makefile syntax error due to an incorrectly named variable `kvm-arm64-obj`. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Potential Makefile syntax error due to an incorrectly named variable kvm-arm64-obj. --

--- Patch [24]: [PATCH v6 24/33] KVM: s390: Use arm64 code --- commit e4207bffe34b1de1b2b51c1d13254c153e76c1b6
Author: Steffen Eiden <[email protected]>

KVM: s390: Use arm64 code

This commit adds the infrastructure to extract KVM/arm64 code into s390 at build time. It introduces an awk script to extract marked sections into .inc files and a Makefile.gen to generate these dependencies. A guard macro is also included in the generated files to prevent accidental double consumption.

Quoted 6 lines
arch/s390/kvm/arm64/Makefile.gen new file +0 -0
new file mode 100644
index 0000000000000..cb9482eb947b9
@@ -0,0 +1,29 @@

[ ... ]

arch/s390/kvm/arm64/Makefile.gen line 26

Quoted 6 lines
arch/s390/kvm/arm64/Makefile.gen new file +6 -0
+ARM64_INC_FILES := $(foreach cfile,$(ARM64_CFILES),generated/$(basename $(cfile)).inc)
+
+targets += $(ARM64_INC_FILES)
+clean-files += generated/*.inc
+
+$(addprefix $(obj)/,$(kvm-arm64-obj)): $(addprefix $(obj)/,$(ARM64_INC_FILES))
                        ^^^^^^^^^^^^^

[Severity: Low]
Will this result in a fatal make syntax error if the Makefile is included?

The variable kvm-arm64-obj is used here to declare dependencies, but it does not appear to be defined anywhere in the tree. If this evaluates to an empty string, the addprefix function will return empty on the left side of the colon, breaking make with a missing rule before recipe error.

Should this variable be defined before use, or was a different variable name intended?

Quoted 3 lines
arch/s390/kvm/arm64/Makefile.gen new file +3 -0
+
+$(foreach cfile,$(basename $(ARM64_CFILES)),\
+	$(eval $(obj)/$(cfile).o: $(obj)/generated/$(cfile).inc))
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=24
#32 lore raw

Re: [PATCH v6 10/33] arm64: Share arm64 headers with s390

In reply to Steffen Eiden
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] Gating core arm64 macros behind `#ifdef ARM64_S390_COMMON` breaks userspace tooling (perf, KVM…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Gating core arm64 macros behind #ifdef ARM64_S390_COMMON breaks userspace tooling (perf, KVM selftests, BPF) and creates inconsistent header views for linker scripts.
- [Medium] Using active C preprocessor #ifdef blocks as text-extraction markers for another architecture creates fragile coupling and pollutes the arm64 build system. --

--- Patch [10]: [PATCH v6 10/33] arm64: Share arm64 headers with s390 --- commit 20e1eb14886be076f6d4d8836cb6c7175057685e
Author: Steffen Eiden <[email protected]>

arm64: Share arm64 headers with s390

Allow sharing of arm64 headers with s390 by marking the shared regions or add a comment that the whole file is shared. The preprocessor symbol ARM64_S390_COMMON is always defined for arm64.

arch/arm64/Makefile CC_FLAGS_NO_FPU := -mgeneral-regs-only · line 48

Quoted 11 lines
arch/arm64/Makefile +2 -0
index 6b005c8fef706..1cd7cd94a8554 100644
@@ -43,7 +43,9 @@ CC_FLAGS_NO_FPU	:= -mgeneral-regs-only
 KBUILD_CFLAGS	+= $(CC_FLAGS_NO_FPU) \
 		   $(compat_vdso) $(cc_has_k_constraint)
 KBUILD_CFLAGS	+= $(call cc-disable-warning, psabi)
+KBUILD_CFLAGS	+= -DARM64_S390_COMMON
 KBUILD_AFLAGS	+= $(compat_vdso)
+KBUILD_AFLAGS	+= -DARM64_S390_COMMON

[Severity: Medium]
Since this macro is injected into C and assembly compilation flags, does this omit it from KBUILD_CPPFLAGS used for linker scripts?

Could this create an inconsistency where the C and assembly code sees the shared blocks, but the linker script preprocessing silently strips them?

[ ... ]

arch/arm64/include/asm/kvm_emulate.h void kvm_skip_instr32(struct kvm_vcpu *vcpu); · line 52

Quoted 11 lines
arch/arm64/include/asm/kvm_emulate.h +1 -0
index a34a9417ff4da..09f04a5686a18 100644
@@ -47,6 +47,7 @@ void kvm_skip_instr32(struct kvm_vcpu *vcpu);
 int kvm_inject_dabt_excl_atomic(struct kvm_vcpu *vcpu, u64 addr);
 int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr);
 
+#ifdef ARM64_S390_COMMON
 void kvm_inject_undefined(struct kvm_vcpu *vcpu);
 void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr);

[Severity: Medium]
Is using an active C preprocessor macro as a text-extraction marker for another architecture a robust design?

By using an active ifdef to delineate text for an s390 extraction script, it forces arm64 to modify its global Makefiles just to parse its own native headers. Would it be safer to use specially formatted code comments for script scraping to avoid altering C preprocessor semantics?

[ ... ]

Quoted 14 lines
arch/arm64/include/asm/sysreg.h +2 -0
index ab205f9db94ad..1c5c4df260bea 100644
@@ -16,6 +16,8 @@
 
 #include <asm/gpr-num.h>
 
+#ifdef ARM64_S390_COMMON
+
 /*
  * ARMv8 ARM reserves the following encoding for system registers:
  * (Ref: ARMv8 ARM, Section: "System instruction class encoding overview",

arch/arm64/include/asm/sysreg.h line 55

Quoted 4 lines
arch/arm64/include/asm/sysreg.h +1 -0
@@ -50,6 +52,8 @@
 #define sys_reg_CRm(id)	(((id) >> CRm_shift) & CRm_mask)
 #define sys_reg_Op2(id)	(((id) >> Op2_shift) & Op2_mask)
 
+#endif /* ARM64_S390_COMMON */

[Severity: Medium]
Will gating fundamental arm64 macros like sys_reg() behind this macro break userspace tooling (such as perf, KVM selftests, and BPF)?

When these headers are synced to tools/, their independent Makefiles will not inherit the kernel's KBUILD_CFLAGS. This means the macro is undefined and core arm64 macros are completely hidden from those builds.

[ ... ]

arch/arm64/include/asm/sysreg.h line 1269

Quoted 9 lines
arch/arm64/include/asm/sysreg.h +2 -0
@@ -1251,6 +1262,8 @@
 	par;								\
 })
 
+#ifdef ARM64_S390_COMMON
+
 #define SYS_FIELD_VALUE(reg, field, val)	reg##_##field##_##val
 
 #define SYS_FIELD_GET(reg, field, val)		\

[Severity: Medium]
Similar to the sys_reg() macro above, does hiding widely used field-extraction macros behind this conditional break builds for external tools that lack the new compiler flag when headers are synced?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
#69 lore raw

Re: [PATCH v6 22/33] KVM: s390: Prepare KVM/s390 for a second KVM module

In reply to Steffen Eiden
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The patch fails to provide all necessary stubs to make s390 KVM compile when merged with an arm64…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The patch fails to provide all necessary stubs to make s390 KVM compile when merged with an arm64 KVM Kconfig, leading to undefined references to functions like kvm_get_dirty_log and kvm_arch_allow_write_without_running_vcpu. --

--- Patch [22]: [PATCH v6 22/33] KVM: s390: Prepare KVM/s390 for a second KVM module --- commit fb387e8f82c2198f5fffbab975b0cb04cd2ac49c
Author: Steffen Eiden <[email protected]>

KVM: s390: Prepare KVM/s390 for a second KVM module

The second KVM module will have a different Kconfig set. When both modules are compiled the Kconfig sets get merged and the native s390 KVM needs to implement functionality required by the respective config options. Ensure that s390-KVM will still compile by implementing a stub for kvm_arch_vcpu_run_pid_change if CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE is enabled and defining KVM_NO_MMIO to disable KVM_MMIO.

Quoted 5 lines
arch/s390/kvm/s390/s390.c +0 -0
index 1d0d94f000f72..d1e736e1f06f2 100644

arch/s390/kvm/s390/s390.c bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range) · line 5877

Quoted 10 lines
arch/s390/kvm/s390/s390.c +7 -0
@@ -5868,6 +5868,14 @@ bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range)
 	return gmap_unmap_gfn_range(kvm->arch.gmap, range->slot, range->start, range->end);
 }
 
+#ifdef CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE
+/* Make s390 compile if arm64-on-s390 is selected */
+int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu)
+{
+	return 0;
+}
+#endif /* CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE */

[Severity: Low]
Are there other missing stubs required to make s390 KVM compile when merged with the arm64 KVM Kconfig?

If CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT and CONFIG_NEED_KVM_DIRTY_RING_WITH_BITMAP are enabled by the merged configs, could there be undefined references to functions like kvm_get_dirty_log() and kvm_arch_allow_write_without_running_vcpu()?

For instance, s390_kvm_mmu_get_dirty_log() in arch/s390/kvm/gmap/kvm_mmu.c calls kvm_get_dirty_log(), which is omitted from virt/kvm/kvm_main.c when CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT is selected.

Would adding stubs for these functions be needed to fully resolve the linker errors this patch aims to fix?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=22
#71 lore raw

Re: [PATCH v6 23/33] s390: Use arm64 headers

In reply to Steffen Eiden
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] The header sharing mechanism generates sysreg-gen.h instead of sysreg.h, causing unresolved…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] The header sharing mechanism generates sysreg-gen.h instead of sysreg.h, causing unresolved includes. esr.h is fully copied since it has no ARM64_S390_COMMON markers, meaning its #include <asm/sysreg.h> is retained and transformed to #include <arm64/sysreg.h>. However, because sysreg.h is mapped to sysreg-gen.h in ARM64_SHARED_HEADERS, the target file is generated as arm64/sysreg-gen.h. As a result, the include in esr.h will fail to find arm64/sysreg.h.
- [Low] The Make rule for generating $(ARM64_TARGETS) uses $(call cmd,gen_arm_hdr) without if_changed or FORCE. In Kbuild, files added to targets must be generated using if_changed so that .cmd files are created to track command-line modifications. The omission of if_changed defeats this dependency tracking.
--

--- Patch [23]: [PATCH v6 23/33] s390: Use arm64 headers --- commit 505a7f9c35b46d1872a2e9da2ab63e0bc5a7471f
Author: Steffen Eiden <[email protected]>
s390: Use arm64 headers

This commit introduces a flexible system for sharing ARM64 headers with s390 KVM. It adds awk scripts to extract marked sections or copy full files, and transforms includes to ensure correct path resolution on s390.

Quoted 6 lines
arch/s390/tools/Makefile.arm64h new file +0 -0
new file mode 100644
index 0000000000000..3e033630470a1
@@ -0,0 +1,57 @@

[ ... ]

arch/s390/tools/Makefile.arm64h line 24

Quoted 8 lines
arch/s390/tools/Makefile.arm64h new file +8 -0
+ARM64_SHARED_HEADERS := \
+	brk-imm.h \
+	esr.h \
+	kvm_arm.h \
+	kvm_emulate-gen.h \
+	kvm_host.h \
+	ptrace-gen.h \
+	sysreg-gen.h \

[Severity: Low]
Will this result in an unresolved include when esr.h is compiled?

esr.h has no ARM64_S390_COMMON markers, so it is fully copied using copy-arm64h-full.awk. That script transforms #include <asm/sysreg.h> into #include <arm64/sysreg.h>. However, since ARM64_SHARED_HEADERS maps sysreg.h to sysreg-gen.h, the generated file will be arm64/sysreg-gen.h, and the include in esr.h will fail to find arm64/sysreg.h.

[ ... ]

arch/s390/tools/Makefile.arm64h line 49

Quoted 4 lines
arch/s390/tools/Makefile.arm64h new file +4 -0
+ARM64_TARGETS := $(sort $(foreach hdr,$(ARM64_SHARED_HEADERS),$(call arm64-dst,$(hdr))))
+
+$(ARM64_TARGETS):
+	$(call cmd,gen_arm_hdr)

[Severity: Low]
Should this use if_changed and FORCE instead of directly calling cmd?

In Kbuild, files added to targets must be generated using if_changed so that .cmd files are created to track command-line modifications. Omitting if_changed here prevents automatic rebuilds if the command-line arguments or rules change.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=23
#81 lore raw

Re: [PATCH v6 28/33] KVM: s390: Add basic arm64 kvm module

In reply to Steffen Eiden
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Integer underflow in `kvm_max_guest_address()` bypasses KVM IPA limit validation for systems with…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Integer underflow in kvm_max_guest_address() bypasses KVM IPA limit validation for systems with less than 1GB of max address. --

--- Patch [28]: [PATCH v6 28/33] KVM: s390: Add basic arm64 kvm module --- commit 57ce89696f07b8212cf2fc85a369b60b1ec4f89b
Author: Steffen Eiden <[email protected]>

KVM: s390: Add basic arm64 kvm module

This commit adds the initial architecture-specific KVM infrastructure for supporting arm64 guests on s390 hosts. It includes basic module initialization, tracepoint scaffolding, and API skeleton functions.

Quoted 5 lines
arch/s390/kvm/arm64/arm.c new file +0 -0
new file mode 100644
index 0000000000000..8e17b7eef8131

[ ... ]

arch/s390/kvm/arm64/arm.c line 53

Quoted 9 lines
arch/s390/kvm/arm64/arm.c new file +9 -0
+static u64 kvm_max_guest_address(void)
+{
+	u64 max_addr;
+
+	if (sclp.hamax == U64_MAX)
+		max_addr = TASK_SIZE_MAX;
+	else
+		max_addr = min_t(u64, TASK_SIZE_MAX, sclp.hamax);
+	return ALIGN_DOWN(max_addr + 1, 1 << 30) - 1;

[Severity: High]
Can this underflow if max_addr + 1 is less than 1GB (1 << 30)?

On a system with a small maximum address limit, ALIGN_DOWN() will evaluate to 0. Subtracting 1 from 0 will result in a U64_MAX return value, bypassing the intended limit.

Quoted 1 line

+}

[ ... ]

arch/s390/kvm/arm64/arm.c line 69

Quoted 3 lines
arch/s390/kvm/arm64/arm.c new file +3 -0
+u32 get_kvm_ipa_limit(void)
+{
+	return fls64(kvm_max_guest_address() + 1) - 1;

[Severity: High]
If kvm_max_guest_address() underflows to U64_MAX as mentioned above, does this cause get_kvm_ipa_limit() to return U32_MAX?

Adding 1 to U64_MAX wraps to 0. Calling fls64(0) - 1 would then evaluate to U32_MAX. This effectively disables the IPA size limit validation in kvm_vm_type_ipa_size_shift(), allowing userspace to request unsupported IPA sizes during VM creation.

Quoted 1 line

+}

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=28
#75 lore raw

Re: [PATCH v6 25/33] s390: Introduce Start Arm Execution instruction

In reply to Steffen Eiden
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] __sae64a lacks integration with the host's machine check handler, causing guest-induced machine…

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] __sae64a lacks integration with the host's machine check handler, causing guest-induced machine checks to panic the host kernel.
- [High] Missing branch prediction isolation (Spectre v2 mitigation) around the SAE instruction.
- [High] Missing host interrupt intercept/exit protocol for SAE, which can lead to a CPU lockup.
- [Medium] Potential machine check misattribution due to a missing NOP padding instruction immediately after the SAE instruction. --

--- Patch [25]: [PATCH v6 25/33] s390: Introduce Start Arm Execution instruction --- commit 06d16be51e15035979052bdd29d727897f102ac2
Author: Steffen Eiden <[email protected]>

s390: Introduce Start Arm Execution instruction

This commit introduces the Start Arm Execution (SAE) instruction to enable accelerated execution of arm64 virtual machines on s390. It adds the __sae64a assembly function to handle the execution context switch.

[ ... ]

Quoted 6 lines
arch/s390/kernel/entry.S +0 -0
index 10dd9bbdf9856..5d9817acab0b6 100644
@@ -245,6 +245,28 @@ EXPORT_SYMBOL(__sie64a)
 EXPORT_SYMBOL(sie_exit)

arch/s390/kernel/entry.S EXPORT_SYMBOL(__sie64a) · line 255

Quoted 10 lines
arch/s390/kernel/entry.S +8 -0
 #endif
 
+#if IS_ENABLED(CONFIG_KVM_ARM64)
+/*
+ * __sae64a calling convention:
+ * %r2 pointer to sae control block physical address
+ */
+SYM_FUNC_START(__sae64a)
+	stmg	%r6,%r14,__SF_GPRS(%r15)	# store kernel registers
+	STBEAR	__SF_SAE_BEAR(%r15)		# save breaking event address register

[Severity: High]
Are we missing branch predictor isolation (BPEXIT/BPOFF/BPENTER) around the sae instruction?

Without these macros, the host branch predictor might be left exposed to the guest. Could a malicious guest intentionally mistrain the branch predictor to mount a Spectre v2 branch target injection attack against the host kernel?

[Severity: High]
Should this function set a thread flag before execution, similar to __TI_sie, to allow host interrupts to break the execution loop?

Without a flag like __TI_sae, host interrupt handlers (like ext_int_handler and io_int_handler) will return directly to the sae instruction instead of rewriting the return address. Could this cause the host VCPU thread to enter an infinite execution loop, preventing signal delivery and causing a CPU lockup?

arch/s390/kernel/entry.S EXPORT_SYMBOL(__sie64a) · line 256

Quoted 1 line
arch/s390/kernel/entry.S +1 -0
+	.insn	rre,0xb9a50000,%r2,0		# Start Arm Execution

[Severity: High]
Does this instruction need .Lsae_entry and .Lsae_leave bounds, similar to __sie64a, so the machine check handler can detect guest context?

In mcck_int_handler(), it checks for .Lsie_entry bounds:

mcck_int_handler:

	larl	%r14,.Lsie_entry
	clgrjl	%r9,%r14, 4f
	larl	%r14,.Lsie_leave
	clgrjhe	%r9,%r14, 4f
	lg	%r10,__LC_PCPU(%r13)
	oi	__PCPU_FLAGS+7(%r10), _CIF_MCCK_GUEST

Without equivalent bounds for sae, a guest-induced machine check might be incorrectly handled as a host kernel machine check, leaving _CIF_MCCK_GUEST unset and panicking the host.

arch/s390/kernel/entry.S EXPORT_SYMBOL(__sie64a) · line 257

Quoted 1 line
arch/s390/kernel/entry.S +1 -0
+	LBEAR	__SF_SAE_BEAR(%r15)		# restore breaking event address register

[Severity: Medium]
Is a padding instruction needed immediately following the sae instruction?

In __sie64a, a nopr 7 instruction immediately follows the sie instruction to safely absorb deferred boundary machine checks without attributing them to the host context. Without padding, could a deferred machine check be incorrectly attributed to the host?

Quoted 11 lines
arch/s390/kernel/entry.S +11 -0
+	lmg	%r6,%r14,__SF_GPRS(%r15)	# restore kernel registers
+	xgr	%r0,%r0				# clear guest registers to
+	xgr	%r1,%r1				# prevent speculative use
+	xgr	%r2,%r2
+	xgr	%r3,%r3
+	xgr	%r4,%r4
+	xgr	%r5,%r5
+	BR_EX	%r14
+SYM_FUNC_END(__sae64a)
+EXPORT_SYMBOL(__sae64a)
+#endif
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=25
#77 lore raw

Re: [PATCH v6 26/33] KVM: s390: arm64: Introduce host definitions

In reply to Steffen Eiden
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The vcpu flag wrapper macros (`_vcpu_get_flag`, `_vcpu_set_flag`, etc.) are syntactically broken…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The vcpu flag wrapper macros (_vcpu_get_flag, _vcpu_set_flag, etc.) are syntactically broken and will cause build failures if instantiated. --

--- Patch [26]: [PATCH v6 26/33] KVM: s390: arm64: Introduce host definitions --- commit 9d09eb59e082ce9c0d035d93867a0ac53fc503a3
Author: Steffen Eiden <[email protected]>

KVM: s390: arm64: Introduce host definitions

This commit adds basic definitions required by the ARM on s390 KVM host. It introduces struct kvm*arch definitions and various defines needed to run arm64 guests, selecting the new header variant if KVM_S390_ARM64 is defined.

Quoted 5 lines
arch/s390/include/asm/kvm_host_arm64.h new file +0 -0
new file mode 100644
index 0000000000000..8088409bb0411

[ ... ]

arch/s390/include/asm/kvm_host_arm64.h line 108

Quoted 8 lines
arch/s390/include/asm/kvm_host_arm64.h new file +8 -0
+#define _vcpu_get_flag(v, flagset, ...)	\
+	__vcpu_get_flag(&(v)->arch.flagset, __VA_ARGS__)
+#define _vcpu_set_flag(v, flagset, ...)	\
+	__vcpu_set_flag(&(v)->arch.flagset, __VA_ARGS__)
+#define _vcpu_clear_flag(v, flagset, ...)	\
+	__vcpu_clear_flag(&(v)->arch.flagset, __VA_ARGS__)
+#define _vcpu_test_and_clear_flag(v, flagset, ...)	\
+	__vcpu_test_and_clear_flag(&(v)->arch.flagset, __VA_ARGS__)

[Severity: Low]
Will these wrapper macros cause a build failure when instantiated?

Looking at __vcpu_get_flag() and the related macros from the shared arm64 headers, they expect exactly four arguments: v, flagset, f, and m.

In these wrappers, we pass &(v)->arch.flagset as the first argument and __VA_ARGS__ as the remaining arguments. Since standard flag constants usually expand to two arguments (for example, BIT(0), BIT(0) for f and m), this invocation only provides three arguments in total instead of the required four.

Does this need an additional argument or a different macro structure to resolve the arity mismatch?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=26
#98 lore raw
In reply to Steffen Eiden

Am 12.08.26 um 17:35 schrieb Steffen Eiden:

Quoted 9 lines

C) KVM/s390 reorganization (patches 12-22):
Prepare s390 for a second KVM module. Move existing s390 KVM code into dedicated s390 and gmap subdirectories to make room for a second KVM implementation. Refactor gmap to better integrate with the second KVM implementation. GMAP hides a few features only required when managing s390
guests: Storage keys, CMMA, and prefix handling. Those are guarded behind an #if KVM_S390_MANAGES_S390_GUEST. Only features which implementation would break kvm-arm64 code are guarded. I leave the non-breaking stuff (like shadow-gmaps or ucontrol) for the LTO.

I will likely take 12-21 for the next merge window so that we can minimize this patch set. sashiko and claude are happy. Mostly mechanical moves. I will review those first and might do small fixups myself if necessary.

#94 lore raw

Re: [PATCH v6 32/33] KVM: s390: arm64: Implement basic page fault handler

In reply to Steffen Eiden
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Guest-triggerable KVM_BUG on unexpected program interrupt codes (PICs) causes host denial of…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Guest-triggerable KVM_BUG on unexpected program interrupt codes (PICs) causes host denial of service. --

--- Patch [32]: [PATCH v6 32/33] KVM: s390: arm64: Implement basic page fault handler --- commit 1cc2a3fc0641697d83c316659559bcf0aaa389a1
Author: Steffen Eiden <[email protected]>

KVM: s390: arm64: Implement basic page fault handler

Add host functionality to page in guest memory. If the guest does something unexpected or illegal exit to userspace abort guest execution.

Quoted 5 lines
arch/s390/kvm/arm64/mmu.c new file +0 -0
new file mode 100644
index 0000000000000..71cd582f24ff8

[ ... ]

Quoted 7 lines
arch/s390/kvm/arm64/mmu.c new file +7 -0
+static int kvm_handle_pic(struct kvm_vcpu *vcpu, bool *translation)
+{
+	switch (kvm_vcpu_fault_pic(vcpu)) {
+	/* expected cases: */
+	case PGM_ASCE_TYPE:
+	case PGM_REGION_FIRST_TRANS:
+	case PGM_REGION_SECOND_TRANS:

arch/s390/kvm/arm64/mmu.c line 59

Quoted 10 lines
arch/s390/kvm/arm64/mmu.c new file +10 -0
+	case PGM_REGION_THIRD_TRANS:
+	case PGM_SEGMENT_TRANSLATION:
+	case PGM_PAGE_TRANSLATION:
+		*translation = true;
+		break;
+	case PGM_PROTECTION:
+		break;
+	/* unexpected cases: */
+	case 0:
+		KVM_BUG(1, vcpu->kvm, "On MMU fault path but no fault occurred");

[Severity: High]
Does this KVM_BUG() allow a guest to trigger a host warning?

If a guest performs an action that triggers a hardware exit with an unexpected program interrupt code (like an alignment fault that exits with pic == 0), kvm_handle_pic() falls into these branches.

Since KVM_BUG() expands to a WARN_ONCE in the host kernel, this could cause a host kernel panic on systems configured with panic_on_warn.

Should this cleanly return -EFAULT to userspace to gracefully abort the guest without asserting instead?

Quoted 10 lines
arch/s390/kvm/arm64/mmu.c new file +10 -0
+		return -EFAULT;
+	default:
+		KVM_BUG(1, vcpu->kvm, "Unexpected program interrupt 0x%x, TEID 0x%016lx",
+			vcpu->arch.sae_block.hai.pic, vcpu->arch.sae_block.hai.teid.val);
+		send_sig(SIGSEGV, current, 0);
+		return -EFAULT;
+	}
+
+	return 0;
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=32
#85 lore raw

Re: [PATCH v6 29/33] KVM: s390: arm64: Implement required functions

In reply to Steffen Eiden
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Uninitialized lock acquisition causes lockdep splat or kernel crash. - [High] Empty exception…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Uninitialized lock acquisition causes lockdep splat or kernel crash.
- [High] Empty exception injection stubs cause infinite VCPU exit loops.
--

--- Patch [29]: [PATCH v6 29/33] KVM: s390: arm64: Implement required functions --- commit 7893f22f5b221e3beeba9913544dc8c7efcfbfc0
Author: Steffen Eiden <[email protected]>

KVM: s390: arm64: Implement required functions

Implement the mostly trivial functions that the shared arm64 (kvm) code & headers oblige s390 to implement.

Implement a very basic smccc handler that (non-compliantly) is just able to stop a vcpu.

Quoted 4 lines
arch/s390/kvm/arm64/handle_exit.c new file +0 -0
new file mode 100644

[ ... ]

arch/s390/kvm/arm64/handle_exit.c line 29

Quoted 8 lines
arch/s390/kvm/arm64/handle_exit.c new file +8 -0
+static int kvm_smccc_call_handler(struct kvm_vcpu *vcpu)
+{
+	u32 func_id = vcpu_get_reg(vcpu, 0);
+	u64 val = PSCI_RET_NOT_SUPPORTED;
+	int ret = 1;
+
+	if (func_id == PSCI_0_2_FN_SYSTEM_OFF) {
+		scoped_guard(spinlock, &vcpu->arch.mp_state_lock) {

[Severity: High]
Can this cause a lockdep splat or kernel crash?

This lock is an arm64-specific state that does not appear to be initialized via spin_lock_init() in the s390 VCPU creation path.

If a guest triggers an SMC/HVC trap with func_id == PSCI_0_2_FN_SYSTEM_OFF, the host handles this in kvm_smccc_call_handler() and attempts to acquire vcpu->arch.mp_state_lock. Attempting to acquire the uninitialized lock here will cause a crash or lockdep warning.

Quoted 2 lines
arch/s390/kvm/arm64/handle_exit.c new file +2 -0
+			WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_STOPPED);
+		}

[ ... ]

Quoted 4 lines
arch/s390/kvm/arm64/inject_fault.c new file +0 -0
new file mode 100644

[ ... ]

arch/s390/kvm/arm64/inject_fault.c line 21

Quoted 10 lines
arch/s390/kvm/arm64/inject_fault.c new file +10 -0
+void kvm_inject_undefined(struct kvm_vcpu *vcpu)
+{
+	/* Stub until s390 supports arm64 sysregs TODO sysregs*/
+}
+
+int kvm_inject_sea(struct kvm_vcpu *vcpu, bool iabt, u64 addr)
+{
+	/* Stub until s390 supports arm64 sysregs TODO sysregs*/
+	return 1;
+}

[Severity: High]
Do these empty stubs cause an infinite exit loop?

If a guest executes an undefined instruction or accesses an unmapped memory address, the host KVM code attempts to inject an exception via kvm_inject_undefined() or kvm_inject_sea().

Because these functions are empty stubs, they do not advance the guest PC or alter its exception state. When the exit handler returns 1 to resume execution, the guest will immediately re-execute the exact same faulting instruction and trap again indefinitely. Any unprivileged guest process can trigger this to cause a denial of service against the host and the VM.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=29
#99 lore raw
In reply to Christian Borntraeger
Quoted 12 lines · Christian Borntraeger

Am 12.08.26 um 17:35 schrieb Steffen Eiden:

Quoted 9 lines

C) KVM/s390 reorganization (patches 12-22):
Prepare s390 for a second KVM module. Move existing s390 KVM code into dedicated s390 and gmap subdirectories to make room for a second KVM implementation. Refactor gmap to better integrate with the second KVM implementation. GMAP hides a few features only required when managing s390
guests: Storage keys, CMMA, and prefix handling. Those are guarded behind an #if KVM_S390_MANAGES_S390_GUEST. Only features which implementation would break kvm-arm64 code are guarded. I leave the non-breaking stuff (like shadow-gmaps or ucontrol) for the LTO.

Quoted 3 lines

I will likely take 12-21 for the next merge window so that we can minimize this patch set. sashiko and claude are happy. Mostly mechanical moves. I will review those first and might do small fixups myself if necessary.

Speaking of trimming down the patch set...

Steffen, can you post patch 1, "vfio: Use file-based reference counting for KVM", separately? I'd love to get that merged sooner than later.

#88 lore raw

Re: [PATCH v6 30/33] KVM: s390: arm64: Implement vm/vcpu create destroy.

In reply to Steffen Eiden
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Integer underflow in `kvm_max_guest_address()` bypassing KVM's IPA limits and causing Undefined…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Integer underflow in kvm_max_guest_address() bypassing KVM's IPA limits and causing Undefined Behavior.
- [High] VM IPA size configuration is ignored for memory boundaries, and mem_limit suffers from an off-by-one error. --

--- Patch [30]: [PATCH v6 30/33] KVM: s390: arm64: Implement vm/vcpu create destroy. --- commit ac331802b4f3974b686910d63a6161cfc71cfae4
Author: Steffen Eiden <[email protected]>

KVM: s390: arm64: Implement vm/vcpu create destroy.

Implement init and destroy IOCTLS for vcpu and vm. Implement arch vm IOCTL. Use s390 gmap and gmap plumbing. Implement function (stubs) required by gamp.

arch/s390/kvm/arm64/arm.c static u64 kvm_max_guest_address(void) · line 59

Quoted 7 lines
arch/s390/kvm/arm64/arm.c +0 -0
index 8e17b7eef8131..69d43066f9e1a 100644
@@ -53,6 +58,83 @@ static u64 kvm_max_guest_address(void)
 	return ALIGN_DOWN(max_addr + 1, 1 << 30) - 1;
 }

[Severity: High]
Does this underflow if the host is booted with less than 1GB of memory?

If sclp.hamax is less than 1GB, max_addr + 1 is less than 1 << 30. ALIGN_DOWN would result in 0, and 0 - 1 would underflow to U64_MAX.

[ ... ]

arch/s390/kvm/arm64/arm.c static u64 kvm_max_guest_address(void) · line 88

Quoted 9 lines
arch/s390/kvm/arm64/arm.c +9 -0
+static int kvm_vm_type_ipa_size_shift(unsigned long type)
+{
+	int phys_shift;
+
+	phys_shift = KVM_VM_TYPE_ARM_IPA_SIZE(type);
+	if (phys_shift) {
+		if (phys_shift > get_kvm_ipa_limit() ||
+		    phys_shift < ARM64_MIN_PARANGE_BITS)
+			return -EINVAL;

[Severity: High]
This seems to cascade from the potential underflow in kvm_max_guest_address().

If get_kvm_ipa_limit() computes fls64(0) - 1, it would return -1 as 0xFFFFFFFF via u32. Could a malicious userspace then bypass this IPA size check since phys_shift > get_kvm_ipa_limit() would evaluate to false?

[ ... ]

arch/s390/kvm/arm64/arm.c static u64 kvm_max_guest_address(void) · line 112

Quoted 12 lines
arch/s390/kvm/arm64/arm.c +12 -0
+int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
+{
+	char debug_name[32];
+	int ret;
+
+	if (type & ~KVM_VM_TYPE_ARM_IPA_SIZE_MASK)
+		return -EINVAL;
+
+	ret = kvm_vm_type_ipa_size_shift(type);
+	if (ret < 0)
+		return ret;
+	kvm->arch.guest_phys_size = 1UL << ret;

[Severity: High]
If the check in kvm_vm_type_ipa_size_shift() is bypassed, the phys_shift value (up to 255) would be used in this shift. Would this invoke undefined behavior since the shift amount could exceed the width of the type?

[ ... ]

arch/s390/kvm/arm64/arm.c static u64 kvm_max_guest_address(void) · line 127

Quoted 4 lines
arch/s390/kvm/arm64/arm.c +4 -0
+	ret = kvm_gmap_init(kvm);
+	if (ret)
+		goto out_err;
+	kvm->arch.mem_limit = kvm_max_guest_address();

[Severity: High]
Is it intended that kvm->arch.mem_limit is hardcoded to the global host maximum instead of the VM's configured IPA size limit (kvm->arch.guest_phys_size)?

If it uses the host's maximum, could userspace successfully map memory higher than the configured VM IPA size limit?

Also, kvm_max_guest_address() appears to return an inclusive limit, but when s390_kvm_mmu_prepare_memory_region() checks this limit:

    if ((new->base_gfn + new->npages) * PAGE_SIZE > kvm->arch.mem_limit)

it treats mem_limit as an exclusive boundary. Does this off-by-one prevent userspace from mapping the final page of the allowed memory region?

[ ... ]

Quoted 7 lines
arch/s390/kvm/arm64/arm.c +7 -0
+int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
+{
+	struct kvm_sae_block *sae_block = &vcpu->arch.sae_block;
+	struct kvm_sae_save_area *save_area = &vcpu->arch.save_area;
+
+	spin_lock_init(&vcpu->arch.mp_state_lock);
+

arch/s390/kvm/arm64/arm.c int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id) · line 182

Quoted 10 lines
arch/s390/kvm/arm64/arm.c +10 -0
+	/* Force users to call KVM_ARM_VCPU_INIT */
+	vcpu_clear_flag(vcpu, VCPU_INITIALIZED);
+
+	vcpu->arch.mc = kvm_s390_new_mmu_cache();
+	if (!vcpu->arch.mc)
+		return -ENOMEM;
+
+	sae_block->hbasce = vcpu->kvm->arch.gmap->asce.val;
+	sae_block->mso = 0L;
+	sae_block->msl = kvm_max_guest_address();

[Severity: High]
Does sae_block->msl also need to be scoped to the VM's requested size rather than the host maximum?

Setting this to the host maximum might remove hardware emulation boundaries if the guest physical size was configured to be smaller.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=30
#90 lore raw

Re: [PATCH v6 31/33] KVM: s390: arm64: Implement vCPU IOCTLs

In reply to Steffen Eiden
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider: - [Critical] kvm_arch_vcpu_ioctl_run() fails to acquire the kvm->srcu read lock, leading to a…

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [Critical] kvm_arch_vcpu_ioctl_run() fails to acquire the kvm->srcu read lock, leading to a Use-After-Free when accessing memslots during guest aborts.
- [High] Guest-reachable WARN_ONCE on SAE validity intercept enables a host DoS.
- [High] Calling local_irq_enable() immediately after guest_enter_irqoff() violates strict RCU extended quiescent state (EQS) rules.
- [High] check_vcpu_requests() fails to handle critical KVM requests like KVM_REQ_TLB_FLUSH and KVM_REQ_VM_DEAD.
- [High] Missing IN_GUEST_MODE coordination in the vCPU run loop creates a race condition that can delay or drop signals and KVM requests.
- [High] Missing vcpu_load() and vcpu_put() around KVM IOCTLs that modify architectural state in kvm_arch_vcpu_ioctl.
--

--- Patch [31]: [PATCH v6 31/33] KVM: s390: arm64: Implement vCPU IOCTLs --- commit e43ea7af3ba7491497b01c2a0860a8b946aad58d
Author: Steffen Eiden <[email protected]>

KVM: s390: arm64: Implement vCPU IOCTLs

This commit implements the required vCPU IOCTLs for the s390 arm64 KVM port. It provides the core structures for register access, lifecycle management, and the main vCPU execution loop.

Quoted 3 lines
arch/s390/kvm/arm64/arm.c +0 -0

[ ... ]

arch/s390/kvm/arm64/arm.c line 319

Quoted 12 lines
arch/s390/kvm/arm64/arm.c +11 -0
@@ -284,15 +309,15 @@
+static int check_vcpu_requests(struct kvm_vcpu *vcpu)
+{
+	if (kvm_request_pending(vcpu)) {
+		if (kvm_check_request(KVM_REQ_VCPU_RESET, vcpu))
+			kvm_reset_vcpu(vcpu);
+		/*
+		 * Clear IRQ_PENDING requests that were made to guarantee
+		 * that a VCPU sees new virtual interrupts.
+		 */
+		kvm_check_request(KVM_REQ_IRQ_PENDING, vcpu);
+	}

[Severity: High]
Does this function properly handle all critical KVM requests?

It appears to drop requests like KVM_REQ_TLB_FLUSH and KVM_REQ_VM_DEAD by not explicitly handling or clearing them. Can this bypass necessary TLB invalidations and dead VM checks?

Quoted 3 lines
arch/s390/kvm/arm64/arm.c +3 -0
+
+	return 1;
+}

[ ... ]

arch/s390/kvm/arm64/arm.c line 423

Quoted 10 lines
arch/s390/kvm/arm64/arm.c +9 -0
@@ -390,13 +415,13 @@
+static void arm_vcpu_run(struct kvm_vcpu *vcpu)
+{
+	struct kvm_sae_block *sae_block = &vcpu->arch.sae_block;
+
+	adjust_pc(vcpu);
+
+	local_irq_disable();
+	guest_enter_irqoff();
+	local_irq_enable();

[Severity: High]
Does this sequence violate RCU extended quiescent state rules?

Calling local_irq_enable() immediately after guest_enter_irqoff() allows host interrupts to fire while RCU believes the CPU is idle.

Quoted 4 lines
arch/s390/kvm/arm64/arm.c +4 -0
+
+	sae_block->icptr = 0;
+
+	sae64a(sae_block);

[ ... ]

Quoted 8 lines
arch/s390/kvm/arm64/arm.c +7 -0
@@ -436,15 +461,15 @@
+	ret = 1;
+	do {
+		if (signal_pending(current)) {
+			kvm_run->exit_reason = KVM_EXIT_INTR;
+			ret = -EINTR;
+			continue;
+		}

arch/s390/kvm/arm64/arm.c static unsigned long system_supported_vcpu_features(void) · line 457

Quoted 10 lines
arch/s390/kvm/arm64/arm.c +10 -0
+
+		if (need_resched())
+			schedule();
+
+		if (ret > 0)
+			ret = check_vcpu_requests(vcpu);
+
+		vcpu->arch.sae_block.icptr = 0;
+
+		arm_vcpu_run(vcpu);

[Severity: High]
Could this loop race with concurrent IPI kicks?

It executes arm_vcpu_run() without coordinating via vcpu->mode = IN_GUEST_MODE. A concurrent request kick via kvm_vcpu_kick() might see OUTSIDE_GUEST_MODE and skip sending the IPI.

arch/s390/kvm/arm64/arm.c static unsigned long system_supported_vcpu_features(void) · line 459

Quoted 2 lines
arch/s390/kvm/arm64/arm.c +2 -0
+
+		ret = handle_exit(vcpu);

[Severity: Critical]
Does handle_exit() require SRCU protection here?

The loop calls handle_exit() which routes synchronous exceptions to the guest abort handler. If the abort handler translates guest addresses and accesses active memslots without holding kvm->srcu, could a concurrent userspace operation like KVM_SET_USER_MEMORY_REGION trigger a use-after-free?

Quoted 2 lines
arch/s390/kvm/arm64/arm.c +2 -0
+
+	} while (ret > 0);

[ ... ]

arch/s390/kvm/arm64/arm.c line 549

Quoted 11 lines
arch/s390/kvm/arm64/arm.c +10 -0
@@ -515,15 +540,15 @@
+long kvm_arch_vcpu_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
+{
+	struct kvm_vcpu *vcpu = filp->private_data;
+	void __user *argp = (void __user *)arg;
+	struct kvm_device_attr attr;
+	int ret;
+
+	switch (ioctl) {
+	case KVM_ARM_VCPU_INIT: {
+		struct kvm_vcpu_init init;

[Severity: High]
Are vcpu_load() and vcpu_put() required around these ioctls?

Operations like KVM_SET_ONE_REG modify architectural state but do not acquire the vcpu_load locks, potentially bypassing preempt notifiers and physical-CPU hardware state tracking hooks.

Quoted 4 lines
arch/s390/kvm/arm64/arm.c +4 -0
+
+		ret = -EFAULT;
+		if (copy_from_user(&init, argp, sizeof(init)))
+			break;

[ ... ]

Quoted 3 lines
arch/s390/kvm/arm64/handle_exit.c +0 -0

[ ... ]

arch/s390/kvm/arm64/handle_exit.c line 88

Quoted 12 lines
arch/s390/kvm/arm64/handle_exit.c +11 -0
@@ -66,13 +78,13 @@
+int handle_exit(struct kvm_vcpu *vcpu)
+{
+	u8 icptr = vcpu->arch.sae_block.icptr;
+	int ret = 1;
+
+	switch (icptr) {
+	case SAE_ICPTR_SPURIOUS:
+		break;
+	case SAE_ICPTR_VALIDITY:
+		WARN_ONCE(true, "SAE: validity intercept. vir: 0x%04x",
+			  vcpu->arch.sae_block.vir);

[Severity: High]
Is it safe to use a guest-reachable WARN_ONCE here?

An unprivileged userspace process configuring KVM could set malformed guest state via KVM_SET_ONE_REG, and the hardware would reject this during execution, returning a validity intercept. Should this return an error to userspace instead of triggering a host warning?

Quoted 2 lines
arch/s390/kvm/arm64/handle_exit.c +2 -0
+		ret = -EINVAL;
+		break;

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=31
#96 lore raw

Re: [PATCH v6 33/33] KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild

In reply to Steffen Eiden
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] Trace event name collisions completely break tracing for the kvm-arm64 subsystem. - [Low] The…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Trace event name collisions completely break tracing for the kvm-arm64 subsystem.
- [Low] The $(NM) -jU command is incompatible with GNU nm, causing build failures.
- [Low] The Makefile passes -O default to objcopy, which is an invalid BFD target. --

--- Patch [33]: [PATCH v6 33/33] KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild --- commit 9d8a545589b9d6b384f0fa20e8bcb8b16fc11bd1
Author: Steffen Eiden <[email protected]>

KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild

Adds Kbuild/Makefile configurations to build a second KVM module on s390 implementing the arm64-KVM API. To prevent symbol conflicts with kvm-s390, internal symbols in kvm-arm64 are mangled if compiled as built-in.

Quoted 15 lines
arch/s390/kvm/arm64/Makefile new file +9 -0
new file mode 100644
index 0000000000000..2ae4a5624151d
@@ -0,0 +1,91 @@
+# SPDX-License-Identifier: GPL-2.0
+
+KVM := ../../../../virt/kvm
+include $(srctree)/virt/kvm/Makefile.kvm
+include $(srctree)/arch/s390/kvm/gmap/Makefile
+include $(src)/Makefile.gen
+
+ccflags-y += -I $(src) -I $(objtree)/$(obj) -I$(srctree)/arch/s390/kvm/gmap -DKVM_S390_ARM64
+

arch/s390/kvm/arm64/Makefile line 19

Quoted 10 lines
arch/s390/kvm/arm64/Makefile new file +10 -0
+kvm-arm64-obj := \
+	arm.o \
+	guest.o \
+	handle_exit.o \
+	inject_fault.o \
+	mmu.o \
+	mmio.o \
+	reset.o \
+
+kvm-arm64-obj += $(patsubst %.o,%-arm64.o,$(kvm-y))

[Severity: Medium]
Because kvm_main.c is compiled into both the s390 kvm.ko and kvm-arm64.ko modules, it includes the trace headers with TRACE_SYSTEM kvm. Does this mean both modules will generate trace event structures mapped to the exact same system and event names? If eventfs processes these tracepoints during module load, could the kvm-arm64 trace events be permanently shadowed by the kvm subsystem's events?

[ ... ]

Quoted 5 lines
arch/s390/kvm/arm64/Makefile new file +5 -0
+prereq-o-cmd = $(foreach o, $(filter %.o, $^), $(dir $(o)).$(notdir $(o)).cmd)
+cmd_gen_symversions_o = \
+	grep --no-filename "^\#SYMVER" $(prereq-o-cmd) >> $(dot-target).cmd || true
+
+define rule_ld_o_o

arch/s390/kvm/arm64/Makefile line 70

Quoted 10 lines
arch/s390/kvm/arm64/Makefile new file +10 -0
+	$(call cmd_and_savecmd,ld)
+	$(call cmd,gen_symversions_o)
+endef
+
+LDFLAGS_kvm-unnamespaced.o := -r --whole-archive
+$(obj)/kvm-unnamespaced.o: $(addprefix $(obj)/,$(kvm-arm64-obj)) FORCE
+	$(call if_changed_rule,ld_o_o)
+
+quiet_cmd_nm_filter = NMFLTR  $@
+	cmd_nm_filter = $(NM) -jU $< | sort -u > $@

[Severity: Low]
Are the -j and -U flags compatible with standard GNU nm? GNU nm does not support these flags natively and requires --defined-only instead. Will this cause a build failure on systems using standard GCC/binutils toolchains?

arch/s390/kvm/arm64/Makefile line 81

Quoted 11 lines
arch/s390/kvm/arm64/Makefile new file +11 -0
+
+$(obj)/kvm_symbol_list: $(obj)/kvm-unnamespaced.o FORCE
+	$(call if_changed,nm_filter)
+
+define rule_oc_o_o
+	$(call cmd_and_savecmd,objcopy)
+	$(call cmd,gen_objtooldep)
+	$(call cmd,gen_symversions_o)
+endef
+
+OBJCOPYFLAGS_kvm-namespaced.o := -O default --localize-symbols=$(obj)/kvm_symbol_list

[Severity: Low]
Is default a valid BFD architecture/target name for objcopy? GNU objcopy strictly requires a recognized target like elf64-s390, or for the -O flag to be omitted entirely to preserve the input format. Could this cause a fatal invalid bfd target error?

Quoted 10 lines
arch/s390/kvm/arm64/Makefile new file +10 -0
+$(obj)/kvm-namespaced.o: $(obj)/kvm-unnamespaced.o $(obj)/kvm_symbol_list FORCE
+	$(call if_changed_rule,oc_o_o)
+
+kvm-arm64-y = kvm-namespaced.o
+
+targets += kvm-unnamespaced.o kvm_symbol_list kvm-namespaced.o
+
+endif
+
+obj-$(CONFIG_KVM_ARM64) += kvm-arm64.o
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=33
maintainer Reviewed-by on v6 12/33
#40 lore raw

Re: [PATCH v6 12/33] KVM: s390: Extract gmap tracing to a separate header

In reply to Steffen Eiden

Am 12.08.26 um 17:36 schrieb Steffen Eiden:

Quoted 5 lines

Move the kvm_s390_major_guest_pfault trace event from trace.h to a new trace_gmap.h header. This separates gmap-specific tracing from general KVM/s390 tracing, preparing for code sharing between multiple KVM implementations.

Quoted 7 lines

The trace event definition is updated to use local defines for parameters so that they can be replaced later with ease for when another KVM implementation uses these traces.

No functional change.

Quoted 102 lines
---
  arch/s390/kvm/faultin.c    |  3 ++-
  arch/s390/kvm/trace.h      | 14 ------------
  arch/s390/kvm/trace_gmap.h | 47 ++++++++++++++++++++++++++++++++++++++
  3 files changed, 49 insertions(+), 15 deletions(-)

create mode 100644 arch/s390/kvm/trace_gmap.h

arch/s390/kvm/faultin.c +2 -1
index 3cc45f7f5b2d..1dc79807012c 100644
@@ -9,10 +9,11 @@
  #include <linux/kvm_host.h>
 
  #include "gmap.h"
-#include "trace.h"
  #include "faultin.h"
 
  bool kvm_arch_setup_async_pf(struct kvm_vcpu *vcpu);
+#define CREATE_TRACE_POINTS
+#include "trace_gmap.h"
 
  /*
   * kvm_s390_faultin_gfn() - handle a dat fault.
arch/s390/kvm/trace.h +0 -14
index dd2685c7df5b..3d2fffb1555a 100644
@@ -45,20 +45,6 @@ TRACE_EVENT(kvm_s390_skey_related_inst,
  	    VCPU_TP_PRINTK("%s", "storage key related instruction")
  	);
 
-TRACE_EVENT(kvm_s390_major_guest_pfault,
-	    TP_PROTO(VCPU_PROTO_COMMON),
-	    TP_ARGS(VCPU_ARGS_COMMON),
-
-	    TP_STRUCT__entry(
-		    VCPU_FIELD_COMMON
-		    ),
-
-	    TP_fast_assign(
-		    VCPU_ASSIGN_COMMON
-		    ),
-	    VCPU_TP_PRINTK("%s", "major fault, maybe applicable for pfault")
-	);
-
  TRACE_EVENT(kvm_s390_pfault_init,
  	    TP_PROTO(VCPU_PROTO_COMMON, long pfault_token),
  	    TP_ARGS(VCPU_ARGS_COMMON, pfault_token),
arch/s390/kvm/trace_gmap.h new file +47 -0
new file mode 100644
index 000000000000..a3cad705021b
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#if !defined(GMAP_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
+#define GMAP_TRACE_KVM_H
+
+#include <linux/tracepoint.h>
+
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM kvm
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH .
+#undef TRACE_INCLUDE_FILE
+#define TRACE_INCLUDE_FILE trace_gmap
+
+#define __KVM_FIELDS \
+	__field(unsigned long, pswmask) \
+	__field(unsigned long, pswaddr)
+#define __KVM_ASSIGN ({\
+	__entry->pswmask = vcpu->arch.sie_block->gpsw.mask; \
+	__entry->pswaddr = vcpu->arch.sie_block->gpsw.addr; \
+	})
+#define __KVM_PRINT \
+	__entry->pswmask,\
+	__entry->pswaddr
+
+TRACE_EVENT(kvm_s390_major_guest_pfault,
+	    TP_PROTO(struct kvm_vcpu *vcpu),
+	    TP_ARGS(vcpu),
+
+	    TP_STRUCT__entry(
+		__field(int, id)
+		__KVM_FIELDS
+		),
+
+	    TP_fast_assign(
+		__entry->id = vcpu->vcpu_id;
+		__KVM_ASSIGN
+		),
+	    TP_printk("%02d[%016lx-%016lx]: major fault, maybe applicable for pfault",
+		__entry->id,
+		__KVM_PRINT
+		)
+	    );
+
+#endif /* GMAP_TRACE_KVM_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
maintainer Reviewed-by on v6 13/33
#43 lore raw

Re: [PATCH v6 13/33] KVM: s390: Prepare include guards for a new location

In reply to Steffen Eiden

Am 12.08.26 um 17:36 schrieb Steffen Eiden:

Quoted 7 lines

Update include guard names in dat.h, faultin.h, and gmap.h to ARCH_KVM_GMAP_* to reflect their upcoming relocation to a shared gmap directory.

No functional change.

Quoted 69 lines
---
  arch/s390/kvm/dat.h     | 6 +++---
  arch/s390/kvm/faultin.h | 6 +++---
  arch/s390/kvm/gmap.h    | 6 +++---
  3 files changed, 9 insertions(+), 9 deletions(-)
arch/s390/kvm/dat.h +3 -3
index 141ee7b9f019..87108f51228e 100644
@@ -6,8 +6,8 @@
   *    Author(s): Claudio Imbrenda <[email protected]>
   */
 
-#ifndef __KVM_S390_DAT_H
-#define __KVM_S390_DAT_H
+#ifndef ARCH_KVM_GMAP_DAT_H
+#define ARCH_KVM_GMAP_DAT_H
 
  #include <linux/radix-tree.h>
  #include <linux/refcount.h>
@@ -975,4 +975,4 @@ static inline bool crste_is_ucas(union crste crste)
  	return is_pmd(crste) && crste.h.i && crste.h.fc0.tl == 1 && crste.h.fc == 0;
  }
 
-#endif /* __KVM_S390_DAT_H */
+#endif /* ARCH_KVM_GMAP_DAT_H */
arch/s390/kvm/faultin.h +3 -3
index f86176d2769c..f343b6fb6f16 100644
@@ -6,8 +6,8 @@
   *    Author(s): Claudio Imbrenda <[email protected]>
   */
 
-#ifndef __KVM_S390_FAULTIN_H
-#define __KVM_S390_FAULTIN_H
+#ifndef ARCH_KVM_GMAP_FAULTIN_H
+#define ARCH_KVM_GMAP_FAULTIN_H
 
  #include <linux/kvm_host.h>
 
@@ -89,4 +89,4 @@ static inline int kvm_s390_get_guest_pages(struct kvm *kvm, struct guest_fault *
  #define kvm_s390_array_needs_retry_safe(kvm, seq, array) \
  	kvm_s390_multiple_faults_need_retry(kvm, seq, array, ARRAY_SIZE(array), false)
 
-#endif /* __KVM_S390_FAULTIN_H */
+#endif /* ARCH_KVM_GMAP_FAULTIN_H */
arch/s390/kvm/gmap.h +3 -3
index 39938d363ec9..c54c35e47d6d 100644
@@ -7,8 +7,8 @@
   *               Claudio Imbrenda <[email protected]>
   */
 
-#ifndef ARCH_KVM_S390_GMAP_H
-#define ARCH_KVM_S390_GMAP_H
+#ifndef ARCH_KVM_GMAP_GMAP_H
+#define ARCH_KVM_GMAP_GMAP_H
 
  #include "dat.h"
 
@@ -330,4 +330,4 @@ static inline bool gmap_is_shadow_valid(struct gmap *sg, union asce asce, int ed
  	return sg->guest_asce.val == asce.val && sg->edat_level == edat_level;
  }
 
-#endif /* ARCH_KVM_S390_GMAP_H */
+#endif /* ARCH_KVM_GMAP_GMAP_H */
maintainer Reviewed-by on v6 14/33
#46 lore raw

Re: [PATCH v6 14/33] KVM: s390: Rename kvm-s390.{c,h} to s390.{c,h}

In reply to Steffen Eiden

Am 12.08.26 um 17:36 schrieb Steffen Eiden:

Quoted 7 lines

Rename kvm-s390.c to s390.c and kvm-s390.h to s390.h for consistency with the new directory structure. Update all include statements and simplify Makefile ccflags from explicit paths to -I$(src).

No functional change.

Quoted 224 lines
---
  arch/s390/kvm/Makefile               | 4 ++--
  arch/s390/kvm/diag.c                 | 2 +-
  arch/s390/kvm/gaccess.c              | 2 +-
  arch/s390/kvm/gaccess.h              | 2 +-
  arch/s390/kvm/gmap.c                 | 2 +-
  arch/s390/kvm/guestdbg.c             | 2 +-
  arch/s390/kvm/intercept.c            | 2 +-
  arch/s390/kvm/interrupt.c            | 2 +-
  arch/s390/kvm/pci.c                  | 2 +-
  arch/s390/kvm/priv.c                 | 2 +-
  arch/s390/kvm/pv.c                   | 2 +-
  arch/s390/kvm/{kvm-s390.c => s390.c} | 2 +-
  arch/s390/kvm/{kvm-s390.h => s390.h} | 2 +-
  arch/s390/kvm/sigp.c                 | 2 +-
  arch/s390/kvm/vsie.c                 | 2 +-
  15 files changed, 16 insertions(+), 16 deletions(-)

rename arch/s390/kvm/{kvm-s390.c => s390.c} (99%) rename arch/s390/kvm/{kvm-s390.h => s390.h} (99%)

arch/s390/kvm/Makefile +2 -2
index dac9d53b23d8..961de97b8e80 100644
@@ -5,9 +5,9 @@
 
  include $(srctree)/virt/kvm/Makefile.kvm
 
-ccflags-y := -Ivirt/kvm -Iarch/s390/kvm
+ccflags-y := -I$(src)
 
-kvm-y += kvm-s390.o intercept.o interrupt.o priv.o sigp.o
+kvm-y += s390.o intercept.o interrupt.o priv.o sigp.o
  kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o
  kvm-y += dat.o gmap.o faultin.o
 
arch/s390/kvm/diag.c +1 -1
index 031ab6e5d6c4..09033c8ff1bb 100644
@@ -12,7 +12,7 @@
  #include <linux/kvm_host.h>
  #include <asm/gmap_helpers.h>
  #include <asm/virtio-ccw.h>
-#include "kvm-s390.h"
+#include "s390.h"
  #include "trace.h"
  #include "trace-s390.h"
  #include "gaccess.h"
arch/s390/kvm/gaccess.c +1 -1
index 0d389a302a70..e5c064f263df 100644
@@ -17,7 +17,7 @@
  #include <asm/access-regs.h>
  #include <asm/fault.h>
  #include <asm/dat-bits.h>
-#include "kvm-s390.h"
+#include "s390.h"
  #include "dat.h"
  #include "gmap.h"
  #include "gaccess.h"
arch/s390/kvm/gaccess.h +1 -1
index b5385cec60f4..ef922b3b4990 100644
@@ -14,7 +14,7 @@
  #include <linux/kvm_host.h>
  #include <linux/uaccess.h>
  #include <linux/ptrace.h>
-#include "kvm-s390.h"
+#include "s390.h"
 
  /**
   * kvm_s390_real_to_abs - convert guest real address to guest absolute address
arch/s390/kvm/gmap.c +1 -1
index 3758e4009709..b5b920392378 100644
@@ -21,7 +21,7 @@
 
  #include "dat.h"
  #include "gmap.h"
-#include "kvm-s390.h"
+#include "s390.h"
  #include "faultin.h"
 
  static inline bool kvm_s390_is_in_sie(struct kvm_vcpu *vcpu)
arch/s390/kvm/guestdbg.c +1 -1
index 9a6149e310bb..1bf7e91b7e61 100644
@@ -8,7 +8,7 @@
   */
  #include <linux/kvm_host.h>
  #include <linux/errno.h>
-#include "kvm-s390.h"
+#include "s390.h"
  #include "gaccess.h"
 
  /*
arch/s390/kvm/intercept.c +1 -1
index 1980df61ef30..ca1205dfac8b 100644
@@ -17,7 +17,7 @@
  #include <asm/sysinfo.h>
  #include <asm/uv.h>
 
-#include "kvm-s390.h"
+#include "s390.h"
  #include "gaccess.h"
  #include "trace.h"
  #include "trace-s390.h"
arch/s390/kvm/interrupt.c +1 -1
index 0d9fbe75dc66..9aa786952718 100644
@@ -29,7 +29,7 @@
  #include <asm/nmi.h>
  #include <asm/airq.h>
  #include <asm/tpi.h>
-#include "kvm-s390.h"
+#include "s390.h"
  #include "gaccess.h"
  #include "trace-s390.h"
  #include "pci.h"
arch/s390/kvm/pci.c +1 -1
index 50f5ec79600e..82892e1e03d9 100644
@@ -14,7 +14,7 @@
  #include <asm/pci_io.h>
  #include <asm/sclp.h>
  #include "pci.h"
-#include "kvm-s390.h"
+#include "s390.h"
 
  struct zpci_aift *aift;
 
arch/s390/kvm/priv.c +1 -1
index b1ba24c346ef..b3cb2c2c3aa7 100644
@@ -26,7 +26,7 @@
  #include <asm/ap.h>
  #include <asm/gmap_helpers.h>
  #include "gaccess.h"
-#include "kvm-s390.h"
+#include "s390.h"
  #include "trace.h"
  #include "gmap.h"
 
arch/s390/kvm/pv.c +1 -1
index f549b161b972..7adfdc9b62be 100644
@@ -18,7 +18,7 @@
  #include <linux/sched/mm.h>
  #include <linux/mmu_notifier.h>
  #include <asm/gmap_helpers.h>
-#include "kvm-s390.h"
+#include "s390.h"
  #include "dat.h"
  #include "gaccess.h"
  #include "gmap.h"
arch/s390/kvm/s390.c renamed from arch/s390/kvm/kvm-s390.c +1 -1
similarity index 99%
rename from arch/s390/kvm/kvm-s390.c
rename to arch/s390/kvm/s390.c
index 4faff6625da3..ff09ffc10f0d 100644
@@ -50,7 +50,7 @@
  #include <asm/fpu.h>
  #include <asm/ap.h>
  #include <asm/uv.h>
-#include "kvm-s390.h"
+#include "s390.h"
  #include "gaccess.h"
  #include "gmap.h"
  #include "faultin.h"
arch/s390/kvm/s390.h renamed from arch/s390/kvm/kvm-s390.h +1 -1
similarity index 99%
rename from arch/s390/kvm/kvm-s390.h
rename to arch/s390/kvm/s390.h
index 6d2842fb71a3..e144ca2e6d5e 100644
@@ -452,7 +452,7 @@ void kvm_s390_vsie_destroy(struct kvm *kvm);
  int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);
  int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu);
 
-/* implemented in kvm-s390.c */
+/* implemented in s390.c */
  int kvm_s390_try_set_tod_clock(struct kvm *kvm, const struct kvm_s390_vm_tod_clock *gtod);
  int kvm_s390_store_status_unloaded(struct kvm_vcpu *vcpu, unsigned long addr);
  int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu, unsigned long addr);
arch/s390/kvm/sigp.c +1 -1
index 55c34cb35428..131b3371ef4f 100644
@@ -14,7 +14,7 @@
  #include <linux/slab.h>
  #include <asm/sigp.h>
  #include "gaccess.h"
-#include "kvm-s390.h"
+#include "s390.h"
  #include "trace.h"
 
  static int __sigp_sense(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu,
arch/s390/kvm/vsie.c +1 -1
index f546239d8ff8..cc94ede0621f 100644
@@ -23,7 +23,7 @@
  #include <asm/nmi.h>
  #include <asm/dis.h>
  #include <asm/facility.h>
-#include "kvm-s390.h"
+#include "s390.h"
  #include "gaccess.h"
  #include "gmap.h"
 
maintainer Reviewed-by on v6 15/33
#49 lore raw

Re: [PATCH v6 15/33] KVM: s390: Move kvm_host definitions to kvm_host_s390

In reply to Steffen Eiden

Am 12.08.26 um 17:36 schrieb Steffen Eiden:

Quoted 7 lines

Rename kvm_host.h to kvm_host_s390.h and kvm_host_types.h to kvm_host_s390_types.h to distinguish s390-specific KVM definitions from the generic kvm_host.h that will be used for shared definitions.

No functional change.

maintainer Reviewed-by on v6 16/33
#52 lore raw

Re: [PATCH v6 16/33] KVM: s390: Move s390 kvm code into a subdirectory

In reply to Steffen Eiden

Am 12.08.26 um 17:36 schrieb Steffen Eiden:

Quoted 9 lines

Move all the code required to run s390 KVM guests on s390 to a s390 subdirectory. Move gmap related code into a gmap directory to later share gmap code between KVM implementations.

Update S390 VFIO-PCI MAINTAINERS filepath.

No functional change.

maintainer Reviewed-by on v6 17/33
#55 lore raw

Re: [PATCH v6 17/33] KVM: s390: Move PGM code definitions to asm/kvm_host.h

In reply to Steffen Eiden

Am 12.08.26 um 17:36 schrieb Steffen Eiden:

Quoted 11 lines

Move PGM code definitions from kvm_host_s390.h (back) to the generic kvm_host.h. These definitions are needed by multiple KVM implementations and should be in a shared location.

No functional change.

---
  arch/s390/include/asm/kvm_host.h      | 57 +++++++++++++++++++++++++++
  arch/s390/include/asm/kvm_host_s390.h | 57 ---------------------------
  2 files changed, 57 insertions(+), 57 deletions(-)

Can look weird from a first glance, but this helped to reduce the overall patch size and for rename detection and easier review.

author reviewer
#100 lore raw
In reply to Sean Christopherson
Quoted 13 lines · Sean Christopherson
Quoted 12 lines · Christian Borntraeger

Am 12.08.26 um 17:35 schrieb Steffen Eiden:

Quoted 9 lines

C) KVM/s390 reorganization (patches 12-22):
Prepare s390 for a second KVM module. Move existing s390 KVM code into dedicated s390 and gmap subdirectories to make room for a second KVM implementation. Refactor gmap to better integrate with the second KVM implementation. GMAP hides a few features only required when managing s390
guests: Storage keys, CMMA, and prefix handling. Those are guarded behind an #if KVM_S390_MANAGES_S390_GUEST. Only features which implementation would break kvm-arm64 code are guarded. I leave the non-breaking stuff (like shadow-gmaps or ucontrol) for the LTO.

Quoted 8 lines
Quoted 3 lines

I will likely take 12-21 for the next merge window so that we can minimize this patch set. sashiko and claude are happy. Mostly mechanical moves. I will review those first and might do small fixups myself if necessary.

Speaking of trimming down the patch set...

Steffen, can you post patch 1, "vfio: Use file-based reference counting for KVM", separately? I'd love to get that merged sooner than later.

Sent a Spin-off with some improvements:

https://lore.kernel.org/all/[email protected]/

Steffen

maintainer Reviewed-by on v6 18/33
#58 lore raw

Re: [PATCH v6 18/33] KVM: s390: Prepare gmap for a second KVM implementation

In reply to Steffen Eiden

Am 12.08.26 um 17:36 schrieb Steffen Eiden:

Quoted 7 lines

Refactor gmap code such that a second s390 (host) KVM implementation can use the gmap code as well. Move mmu code from s390 to gmap so the other KVM implementation can use it as well.

No functional change.

maintainer Reviewed-by on v6 19/33
#61 lore raw

Re: [PATCH v6 19/33] KVM: s390: gmap: Make storage keys optional

In reply to Steffen Eiden

Am 12.08.26 um 17:36 schrieb Steffen Eiden:

Quoted 10 lines

Guard guest storage key handling behind KVM_S390_MANAGES_S390_GUEST. This enables other KVM implementations to use gmap without implementing storage key infrastructure. Define KVM_S390_MANAGES_S390_GUEST to 1 for KVM hosts managing s390 guests (in kvm_host_s390.h). A KVM implementation not implementing those features must define KVM_S390_MANAGES_S390_GUEST to 0 in its kvm_host_<guest_arch>.h.

No functional changes besides the new guard.

Maybe we find a better way in the future but this certainly works.

maintainer Reviewed-by on v6 21/33
#67 lore raw

Re: [PATCH v6 21/33] KVM: s390: gmap: Make prefix handling optional

In reply to Steffen Eiden

Am 12.08.26 um 17:36 schrieb Steffen Eiden:

Quoted 9 lines

Guard guest prefix handling behind KVM_S390_MANAGES_S390_GUEST. This enables other KVM implementations to use gmap without implementing prefix handling. The prefix handling is integrated deeply in the gmap implementation. Therefore, provide safe default implementations for the guarded functions.

No functional changes.

#101 lore raw
In reply to Steffen Eiden

Am 12.08.26 um 17:35 schrieb Steffen Eiden:

Quoted 10 lines

C) KVM/s390 reorganization (patches 12-22):
Prepare s390 for a second KVM module. Move existing s390 KVM code into dedicated s390 and gmap subdirectories to make room for a second KVM implementation. Refactor gmap to better integrate with the second KVM implementation. GMAP hides a few features only required when managing s390
guests: Storage keys, CMMA, and prefix handling. Those are guarded behind an #if KVM_S390_MANAGES_S390_GUEST. Only features which implementation would break kvm-arm64 code are guarded. I leave the non-breaking stuff (like shadow-gmaps or ucontrol) for the LTO.

So I picked 12-21 for kvms390/next and left 22 for later.

maintainer Acked-by on v6 4/33
#9 lore raw

Re: [PATCH v6 04/33] arm64: Use proper include variant

In reply to Steffen Eiden
Quoted 15 lines · Steffen Eiden

Use <> for including the sysreg header as it is not discoverable from the current directory.

Fixes c07d8017bceb ("arm64/sysreg: Enable automatic generation of system register definitions")
---
 arch/arm64/include/asm/sysreg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/sysreg.h +0 -0
index 7aa08d59d494..4bfdac9401bd 100644

arch/arm64/include/asm/sysreg.h line 179

Quoted 8 lines
arch/arm64/include/asm/sysreg.h +1 -1
@@ -173,7 +173,7 @@
  * come from here. The header relies on the definition of sys_reg()
  * earlier in this file.
  */
-#include "asm/sysreg-defs.h"
+#include <asm/sysreg-defs.h>
 
 /*
  * System registers, organised loosely by encoding but grouped together
	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
maintainer Reviewed-by on v6 5/33
#12 lore raw

Re: [PATCH v6 05/33] arm64: ptrace: Use constants for compat register numbers

In reply to Steffen Eiden
Quoted 6 lines · Steffen Eiden

Define an enum to determine the register number for the mapping from AArch32 and AArch64 registers. This allows for a more flexible use of the register mappings.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
maintainer
#15 lore raw

Re: [PATCH v6 06/33] arm64: sysreg: Convert SPSR_ELx to automatic register generation

In reply to Steffen Eiden
Quoted 14 lines · Steffen Eiden

Convert SPSR_EL{1, 2, 12} to automatic register generation as per DDIO616 2026-06. No functional change.

---
 arch/arm64/include/asm/sysreg.h |  3 ---
 arch/arm64/tools/sysreg         | 48 +++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 3 deletions(-)
arch/arm64/include/asm/sysreg.h +0 -0
index 4bfdac9401bd..1aa601c95188 100644

[...]

arch/arm64/include/asm/sysreg.h

Quoted 6 lines
arch/arm64/include/asm/sysreg.h +6 -0
+Enum	4:0	M
+	0b0000	EL0
+	0b0100	EL1t
+	0b0101	EL1h
+	0b1000	EL2t
+	0b1001	EL2h

I think you need to be consistent with the way you represent things, as you are mixing two representations:

- either you have a separate M[4] representing PSTATE.nRW, and then the M[3-0] enum is a 4 bit field (and for simplicity you only describe the AArch64 ELs including EL3[th], which are missing here)

- or M is a 5 bit field and, and you represent everything as a 5 bit enum, providing all the AArch32 modes and EL3.

The former matches the JSON, the latter is closer to the representation in older versions of the ARM ARM.

Pick one, stick to it.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
maintainer Reviewed-by on v6 7/33
#19 lore raw

Re: [PATCH v6 07/33] KVM: arm64: Access elements of vcpu_gp_regs individually

In reply to Steffen Eiden
Quoted 9 lines · Steffen Eiden

While for arm64 the members of vcpu_gp_regs are allocated continuous this is not necessarily true for other architectures implementing ARM.

Let vcpu_gp_regs() no longer return the address of the user_pt_regs in the vcpu context but the address of the gp-register array field in the user_pt_reg struct. Note, this change semantically excludes pc from the GPRs.

Quoted 5 lines

No functional change.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
maintainer
#22 lore raw

Re: [PATCH v6 08/33] KVM: arm64: Use accessor functions for core regs

In reply to Steffen Eiden
Quoted 2 lines · Steffen Eiden

Instead of accessing the value directly use assessor function that

s/assessor function/accessors/

Quoted 3 lines

abstract the actual location of the register values. Add a helper function to reset fpsimd registers. Enable other KVM implementations to reuse this code.

to reuse this code by overloading the accessors.

Quoted 73 lines

No functional changes.

---
 arch/arm64/include/asm/kvm_emulate.h | 34 ++++++++++++++++++++++++++--
 arch/arm64/kvm/guest.c               | 16 ++++++-------
 2 files changed, 40 insertions(+), 10 deletions(-)
arch/arm64/include/asm/kvm_emulate.h +32 -2
index 8603766c1b4d..b31d50bdf59e 100644
@@ -141,6 +141,31 @@ static __always_inline unsigned long *vcpu_cpsr(const struct kvm_vcpu *vcpu)
 	return (unsigned long *)&vcpu->arch.ctxt.regs.pstate;
 }
 
+static __always_inline unsigned long *vcpu_sp_el0(struct kvm_vcpu *vcpu)
+{
+	return (unsigned long *)&vcpu->arch.ctxt.regs.sp;
+}
+
+static __always_inline u64 *vcpu_sp_el1(struct kvm_vcpu *vcpu)
+{
+	return __ctxt_sys_reg(&vcpu->arch.ctxt, SP_EL1);
+}
+
+static __always_inline __u128 *vcpu_vreg(struct kvm_vcpu *vcpu, int n)
+{
+	return &vcpu->arch.ctxt.fp_regs.vregs[n];
+}
+
+static __always_inline __u32 *vcpu_fpsr(struct kvm_vcpu *vcpu)
+{
+	return &vcpu->arch.ctxt.fp_regs.fpsr;
+}
+
+static __always_inline __u32 *vcpu_fpcr(struct kvm_vcpu *vcpu)
+{
+	return &vcpu->arch.ctxt.fp_regs.fpcr;
+}
+
 static __always_inline bool vcpu_mode_is_32bit(const struct kvm_vcpu *vcpu)
 {
 	return !!(*vcpu_cpsr(vcpu) & PSR_MODE32_BIT);
@@ -737,6 +762,11 @@ static inline void vcpu_set_hcrx(struct kvm_vcpu *vcpu)
 	}
 }
 
+static inline void kvm_reset_fpsimd(struct kvm_vcpu *vcpu)
+{
+	memset(&vcpu->arch.ctxt.fp_regs, 0, sizeof(vcpu->arch.ctxt.fp_regs));
+}
+
 /* Reset a vcpu's core registers. */
 static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu)
 {
@@ -752,8 +782,8 @@ static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu)
 	/* Reset core registers */
 	memset(vcpu_gp_regs(vcpu), 0, sizeof(vcpu_gp_regs(vcpu)));
 	*vcpu_pc(vcpu) = 0;
-	vcpu->arch.ctxt.regs.sp = 0;
-	memset(&vcpu->arch.ctxt.fp_regs, 0, sizeof(vcpu->arch.ctxt.fp_regs));
+	*vcpu_sp_el0(vcpu) = 0;
+	kvm_reset_fpsimd(vcpu);
 	vcpu->arch.ctxt.spsr_abt = 0;
 	vcpu->arch.ctxt.spsr_und = 0;
 	vcpu->arch.ctxt.spsr_irq = 0;
arch/arm64/kvm/guest.c +0 -0
index b01d6622b872..773f6c8e5026 100644

arch/arm64/kvm/guest.c static void *core_reg_addr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) · line 137

Quoted 5 lines
arch/arm64/kvm/guest.c +1 -1
@@ -134,19 +134,19 @@ static void *core_reg_addr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 	     KVM_REG_ARM_CORE_REG(regs.regs[30]):
 		off -= KVM_REG_ARM_CORE_REG(regs.regs[0]);
 		off /= 2;
-		return &vcpu->arch.ctxt.regs.regs[off];
+		return &vcpu_gp_regs(vcpu)[off];

Doesn't this belong to the previous patch?

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
maintainer
#29 lore raw

Re: [PATCH v6 09/33] arm64: Prepare sharing arm64 headers with s390

In reply to Steffen Eiden

On Wed, 12 Aug 2026 16:36:05 +0100,
Steffen Eiden <[email protected]> wrote:

[...]

Quoted 28 lines
arch/arm64/include/asm/kvm_host.h +20 -0
index 46c8d7928b3f..22770c1132cb 100644
@@ -56,6 +56,36 @@
 #define KVM_REQ_MAP_L1_VNCR_EL2		KVM_ARCH_REQ(10)
 #define KVM_REQ_VGIC_PROCESS_UPDATE	KVM_ARCH_REQ(11)
 
+/*
+ * If we encounter a data abort without valid instruction syndrome
+ * information, report this to user space.  User space can (and
+ * should) opt in to this feature if KVM_CAP_ARM_NISV_TO_USER is
+ * supported.
+ */
+#define KVM_ARCH_FLAG_RETURN_NISV_IO_ABORT_TO_USER	0
+/* Memory Tagging Extension enabled for the guest */
+#define KVM_ARCH_FLAG_MTE_ENABLED			1
+/* At least one vCPU has ran in the VM */
+#define KVM_ARCH_FLAG_HAS_RAN_ONCE			2
+/* The vCPU feature set for the VM is configured */
+#define KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED		3
+/* PSCI SYSTEM_SUSPEND enabled for the guest */
+#define KVM_ARCH_FLAG_SYSTEM_SUSPEND_ENABLED		4
+/* VM counter offset */
+#define KVM_ARCH_FLAG_VM_COUNTER_OFFSET			5
+/* Timer PPIs made immutable */
+#define KVM_ARCH_FLAG_TIMER_PPIS_IMMUTABLE		6
+/* Initial ID reg values loaded */

arch/arm64/include/asm/kvm_host.h line 88

Quoted 10 lines
arch/arm64/include/asm/kvm_host.h +10 -0
+#define KVM_ARCH_FLAG_ID_REGS_INITIALIZED		7
+/* Fine-Grained UNDEF initialised */
+#define KVM_ARCH_FLAG_FGU_INITIALIZED			8
+/* SVE exposed to guest */
+#define KVM_ARCH_FLAG_GUEST_HAS_SVE			9
+/* MIDR_EL1, REVIDR_EL1, and AIDR_EL1 are writable from userspace */
+#define KVM_ARCH_FLAG_WRITABLE_IMP_ID_REGS		10
+/* Unhandled SEAs are taken to userspace */
+#define KVM_ARCH_FLAG_EXIT_SEA				11
+

I don't mind the move, but please add a comment indicating that these are bit indices for for kvm_arch::flags, as we have now lost locality.

And whilst we're at it, there is not reason why this has to be a set of #define, it can perfectly be an enum, as the numbers themselves have no particular meaning. Something like the untested hack below.

	M.
arch/arm64/include/asm/kvm_host.h +34 -29
index 08b2f24dc3c79..402bbb5eb0d91 100644
@@ -306,6 +306,39 @@ enum fgt_group_id {
 	__NR_FGT_GROUP_IDS__
 };
 
+/* Bit indices for kvm_arch::flags */
+enum kvm_arch_flag_bits {
+	/*
+	 * If we encounter a data abort without valid instruction syndrome
+	 * information, report this to user space.  User space can (and
+	 * should) opt in to this feature if KVM_CAP_ARM_NISV_TO_USER is
+	 * supported.
+	 */
+	KVM_ARCH_FLAG_RETURN_NISV_IO_ABORT_TO_USER,
+	/* Memory Tagging Extension enabled for the guest */
+	KVM_ARCH_FLAG_MTE_ENABLED,
+	/* At least one vCPU has ran in the VM */
+	KVM_ARCH_FLAG_HAS_RAN_ONCE,
+	/* The vCPU feature set for the VM is configured */
+	KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED,
+	/* PSCI SYSTEM_SUSPEND enabled for the guest */
+	KVM_ARCH_FLAG_SYSTEM_SUSPEND_ENABLED,
+	/* VM counter offset */
+	KVM_ARCH_FLAG_VM_COUNTER_OFFSET,
+	/* Timer PPIs made immutable */
+	KVM_ARCH_FLAG_TIMER_PPIS_IMMUTABLE,
+	/* Initial ID reg values loaded */
+	KVM_ARCH_FLAG_ID_REGS_INITIALIZED,
+	/* Fine-Grained UNDEF initialised */
+	KVM_ARCH_FLAG_FGU_INITIALIZED,
+	/* SVE exposed to guest */
+	KVM_ARCH_FLAG_GUEST_HAS_SVE,
+	/* MIDR_EL1, REVIDR_EL1, and AIDR_EL1 are writable from userspace */
+	KVM_ARCH_FLAG_WRITABLE_IMP_ID_REGS,
+	/* Unhandled SEAs are taken to userspace */
+	KVM_ARCH_FLAG_EXIT_SEA,
+};
+
 struct kvm_arch {
 	struct kvm_s2_mmu mmu;
 
@@ -338,35 +371,7 @@ struct kvm_arch {
 	/* Protects VM-scoped configuration data */
 	struct mutex config_lock;
 
-	/*
-	 * If we encounter a data abort without valid instruction syndrome
-	 * information, report this to user space.  User space can (and
-	 * should) opt in to this feature if KVM_CAP_ARM_NISV_TO_USER is
-	 * supported.
-	 */
-#define KVM_ARCH_FLAG_RETURN_NISV_IO_ABORT_TO_USER	0
-	/* Memory Tagging Extension enabled for the guest */
-#define KVM_ARCH_FLAG_MTE_ENABLED			1
-	/* At least one vCPU has ran in the VM */
-#define KVM_ARCH_FLAG_HAS_RAN_ONCE			2
-	/* The vCPU feature set for the VM is configured */
-#define KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED		3
-	/* PSCI SYSTEM_SUSPEND enabled for the guest */
-#define KVM_ARCH_FLAG_SYSTEM_SUSPEND_ENABLED		4
-	/* VM counter offset */
-#define KVM_ARCH_FLAG_VM_COUNTER_OFFSET			5
-	/* Timer PPIs made immutable */
-#define KVM_ARCH_FLAG_TIMER_PPIS_IMMUTABLE		6
-	/* Initial ID reg values loaded */
-#define KVM_ARCH_FLAG_ID_REGS_INITIALIZED		7
-	/* Fine-Grained UNDEF initialised */
-#define KVM_ARCH_FLAG_FGU_INITIALIZED			8
-	/* SVE exposed to guest */
-#define KVM_ARCH_FLAG_GUEST_HAS_SVE			9
-	/* MIDR_EL1, REVIDR_EL1, and AIDR_EL1 are writable from userspace */
-#define KVM_ARCH_FLAG_WRITABLE_IMP_ID_REGS		10
-	/* Unhandled SEAs are taken to userspace */
-#define KVM_ARCH_FLAG_EXIT_SEA				11
+	/* VM-wide flags, described in kvm_arch_flag_bits */
 	unsigned long flags;
 
 	/* VM-wide vCPU feature set */
Signature · 1 line
Without deviation from the norm, progress is not possible.
maintainer
#102 lore raw
In reply to Steffen Eiden
Quoted 2 lines · Steffen Eiden

Introduce arm-on-s390. Enable KVM-accelerated ARM CPU virtualisation on s390.

[...]

Quoted 1 line

Based on next-20260811.

Please don't do that. -next isn't a reliable base for *anything*. For all I know, half of what's in -next is broken and will never be merged. This makes the whole thing untestable.

Base your patches on a release tag: ideally an -rc from Linus' tree, or (worse case) a kvmarm tag for patches targeting KVM/arm64.

We can easily deal with conflicts at merge time if necessary, and ask you to check that nothing broke in the process.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#103 lore raw

Am 13.08.26 um 12:53 schrieb Marc Zyngier:

Quoted 5 lines
Quoted 2 lines · Steffen Eiden

Introduce arm-on-s390. Enable KVM-accelerated ARM CPU virtualisation on s390.

Quoted 7 lines

[...]

Quoted 1 line

Based on next-20260811.

Please don't do that. -next isn't a reliable base for *anything*. For all I know, half of what's in -next is broken and will never be merged. This makes the whole thing untestable.

that was my fault since I asked Steffen for that as I wanted to have the s390 move clean on top of kvms390/next + s390/next.
We will switch to -rc release tags in the future.

Sorry for the trouble.

maintainer
#33 lore raw

Re: [PATCH v6 10/33] arm64: Share arm64 headers with s390

In reply to Steffen Eiden
Quoted 136 lines · Steffen Eiden

Allow sharing of arm64 headers with s390 by marking the shared regions or add a comment that the whole file is shared.

The shared regions are marked with:

#ifdef ARM64_S390_COMMON

/* insert shared definitions here */

#endif /* ARM64_S390_COMMON */

The preprocessor symbol ARM64_S390_COMMON is always defined for arm64. s390 later will generate its own view of arm64 headers based on the content inside the ifdef/endif block.

No functional change.

---
 arch/arm64/Makefile                  |  2 ++
 arch/arm64/include/asm/brk-imm.h     |  1 +
 arch/arm64/include/asm/esr.h         |  1 +
 arch/arm64/include/asm/kvm_arm.h     |  1 +
 arch/arm64/include/asm/kvm_emulate.h | 18 ++++++++++++++++++
 arch/arm64/include/asm/kvm_host.h    | 20 ++++++++++++++++++++
 arch/arm64/include/asm/ptrace.h      |  4 ++++
 arch/arm64/include/asm/sysreg.h      | 15 +++++++++++++++
 8 files changed, 62 insertions(+)
arch/arm64/Makefile +2 -0
index 6b005c8fef70..1cd7cd94a855 100644
@@ -43,7 +43,9 @@ CC_FLAGS_NO_FPU	:= -mgeneral-regs-only
 KBUILD_CFLAGS	+= $(CC_FLAGS_NO_FPU) \
 		   $(compat_vdso) $(cc_has_k_constraint)
 KBUILD_CFLAGS	+= $(call cc-disable-warning, psabi)
+KBUILD_CFLAGS	+= -DARM64_S390_COMMON
 KBUILD_AFLAGS	+= $(compat_vdso)
+KBUILD_AFLAGS	+= -DARM64_S390_COMMON
 
 ifeq ($(call rustc-min-version, 108500),y)
 KBUILD_RUSTFLAGS += --target=aarch64-unknown-none-softfloat
arch/arm64/include/asm/brk-imm.h +1 -0
index beb42c62b6ac..dd2d153dc0d8 100644
@@ -2,6 +2,7 @@
 /*
  * Copyright (C) 2012 ARM Ltd.
  */
+/* Whole file is shared with s390 */
 
 #ifndef __ASM_BRK_IMM_H
 #define __ASM_BRK_IMM_H
arch/arm64/include/asm/esr.h +1 -0
index da085c83b57e..2cb73bde7346 100644
@@ -3,6 +3,7 @@
  * Copyright (C) 2013 - ARM Ltd
  * Author: Marc Zyngier <[email protected]>
  */
+/* Whole file is shared with s390 */
 
 #ifndef __ASM_ESR_H
 #define __ASM_ESR_H
arch/arm64/include/asm/kvm_arm.h +1 -0
index 57edd8437200..678f0daed445 100644
@@ -3,6 +3,7 @@
  * Copyright (C) 2012,2013 - ARM Ltd
  * Author: Marc Zyngier <[email protected]>
  */
+/* Whole file is shared with s390 */
 
 #ifndef __ARM64_KVM_ARM_H__
 #define __ARM64_KVM_ARM_H__
arch/arm64/include/asm/kvm_emulate.h +9 -0
index a34a9417ff4d..09f04a5686a1 100644
@@ -47,6 +47,7 @@ void kvm_skip_instr32(struct kvm_vcpu *vcpu);
 int kvm_inject_dabt_excl_atomic(struct kvm_vcpu *vcpu, u64 addr);
 int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr);
 
+#ifdef ARM64_S390_COMMON
 void kvm_inject_undefined(struct kvm_vcpu *vcpu);
 void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr);
 int kvm_inject_sea(struct kvm_vcpu *vcpu, bool iabt, u64 addr);
@@ -62,6 +63,8 @@ static inline int kvm_inject_sea_iabt(struct kvm_vcpu *vcpu, u64 addr)
 	return kvm_inject_sea(vcpu, true, addr);
 }
 
+#endif /* ARM64_S390_COMMON */
+
 static inline int kvm_inject_serror(struct kvm_vcpu *vcpu)
 {
 	/*
@@ -185,6 +188,7 @@ static inline void vcpu_set_thumb(struct kvm_vcpu *vcpu)
 	*vcpu_cpsr(vcpu) |= PSR_AA32_T_BIT;
 }
 
+#ifdef ARM64_S390_COMMON
 /*
  * vcpu_get_reg and vcpu_set_reg should always be passed a register number
  * coming from a read of ESR_EL2. Otherwise, it may give the wrong result on
@@ -203,6 +207,8 @@ static __always_inline void vcpu_set_reg(struct kvm_vcpu *vcpu, u8 reg_num,
 		vcpu_gp_regs(vcpu)[reg_num] = val;
 }
 
+#endif /* ARM64_S390_COMMON */
+
 static inline bool vcpu_is_el2_ctxt(const struct kvm_cpu_context *ctxt)
 {
 	switch (ctxt->regs.pstate & (PSR_MODE32_BIT | PSR_MODE_MASK)) {
@@ -405,6 +411,7 @@ static inline u64 kvm_vcpu_get_disr(const struct kvm_vcpu *vcpu)
 	return vcpu->arch.fault.disr_el1;
 }
 
+#ifdef ARM64_S390_COMMON
 static inline u32 kvm_vcpu_hvc_get_imm(const struct kvm_vcpu *vcpu)
 {
 	return kvm_vcpu_get_esr(vcpu) & ESR_ELx_xVC_IMM_MASK;
@@ -482,6 +489,8 @@ static __always_inline u8 kvm_vcpu_trap_get_fault(const struct kvm_vcpu *vcpu)
 	return kvm_vcpu_get_esr(vcpu) & ESR_ELx_FSC;
 }
 
+#endif /* ARM64_S390_COMMON */
+
 static inline
 bool kvm_vcpu_trap_is_permission_fault(const struct kvm_vcpu *vcpu)
 {

arch/arm64/include/asm/kvm_emulate.h static __always_inline int kvm_vcpu_sys_get_rt(struct kvm_vcpu *vcpu) · line 534

Quoted 4 lines
arch/arm64/include/asm/kvm_emulate.h +1 -0
@@ -522,6 +531,7 @@ static __always_inline int kvm_vcpu_sys_get_rt(struct kvm_vcpu *vcpu)
 	return ESR_ELx_SYS64_ISS_RT(esr);
 }
 
+#ifdef ARM64_S390_COMMON

I'm curious about the reasons for skipping a bunch of architectural helpers:

- kvm_vcpu_trap_is_permission_fault()
- kvm_vcpu_trap_is_translation_fault()
- kvm_vcpu_trap_get_perm_fault_granule()
- kvm_vcpu_abt_issea()
- kvm_vcpu_sys_get_rt()

I really think you should include anything that is exclusively derived from architectural state, specially that these helpers are strictly dependent on stuff you already include.

Any particular reason why this isn't the case?

Quoted 13 lines
arch/arm64/include/asm/kvm_emulate.h +2 -0
 static inline bool kvm_is_write_fault(struct kvm_vcpu *vcpu)
 {
 	if (kvm_vcpu_abt_iss1tw(vcpu)) {
@@ -546,6 +556,8 @@ static inline bool kvm_is_write_fault(struct kvm_vcpu *vcpu)
 	return kvm_vcpu_dabt_iswrite(vcpu);
 }
 
+#endif /* ARM64_S390_COMMON */
+
 static inline unsigned long kvm_vcpu_get_mpidr_aff(struct kvm_vcpu *vcpu)
 {
 	return __vcpu_sys_reg(vcpu, MPIDR_EL1) & MPIDR_HWID_BITMASK;

arch/arm64/include/asm/kvm_emulate.h static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu) · line 602

Quoted 4 lines
arch/arm64/include/asm/kvm_emulate.h +1 -0
@@ -587,6 +599,7 @@ static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu)
 	return vcpu_read_sys_reg(vcpu, r) & bit;
 }
 
+#ifdef ARM64_S390_COMMON

Similarly, you have dropped

- kvm_vcpu_set_be()

- kvm_vcpu_is_be()

I suspect that your implementation is LE only (it'd better be, as we're dropping BE support right now), but it would make a lot more sense if you could rely on the guest architectural state (which must be accurate) rather than short-cutting things in your own implementation.

Quoted 60 lines
arch/arm64/include/asm/kvm_emulate.h +5 -0
 static inline unsigned long vcpu_data_guest_to_host(struct kvm_vcpu *vcpu,
 						    unsigned long data,
 						    unsigned int len)
@@ -662,6 +675,8 @@ static __always_inline void kvm_incr_pc(struct kvm_vcpu *vcpu)
 		vcpu_set_flag((v), e);					\
 	} while (0)
 
+#endif /* ARM64_S390_COMMON */
+
 /*
  * Returns a 'sanitised' view of CPTR_EL2, translating from nVHE to the VHE
  * format if E2H isn't set.
@@ -768,6 +783,7 @@ static inline void kvm_reset_fpsimd(struct kvm_vcpu *vcpu)
 	memset(&vcpu->arch.ctxt.fp_regs, 0, sizeof(vcpu->arch.ctxt.fp_regs));
 }
 
+#ifdef ARM64_S390_COMMON
 /* Reset a vcpu's core registers. */
 static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu)
 {
@@ -792,6 +808,8 @@ static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu)
 	*vcpu_cpsr(vcpu) = pstate;
 }
 
+#endif /* ARM64_S390_COMMON */
+
 /* PSCI reset handling for a vcpu. */
 static inline void kvm_reset_vcpu_psci(struct kvm_vcpu *vcpu,
 				       struct vcpu_reset_state *reset_state)
arch/arm64/include/asm/kvm_host.h +5 -0
index 22770c1132cb..e6b3d42abb08 100644
@@ -39,6 +39,7 @@
 
 #define KVM_MAX_VCPUS VGIC_V3_MAX_CPUS
 
+#ifdef ARM64_S390_COMMON
 #define KVM_VCPU_MAX_FEATURES 10
 #define KVM_VCPU_VALID_FEATURES	(BIT(KVM_VCPU_MAX_FEATURES) - 1)
 
@@ -86,6 +87,8 @@
 /* Unhandled SEAs are taken to userspace */
 #define KVM_ARCH_FLAG_EXIT_SEA				11
 
+#endif /* ARM64_S390_COMMON */
+
 #define KVM_DIRTY_LOG_MANUAL_CAPS   (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \
 				     KVM_DIRTY_LOG_INITIALLY_SET)
 
@@ -836,6 +839,8 @@ extern s64 kvm_nvhe_sym(hyp_physvirt_offset);
 extern u64 kvm_nvhe_sym(hyp_cpu_logical_map)[NR_CPUS];
 #define hyp_cpu_logical_map CHOOSE_NVHE_SYM(hyp_cpu_logical_map)
 
+#ifdef ARM64_S390_COMMON
+
 struct vcpu_reset_state {
 	unsigned long	pc;
 	unsigned long	r0;

arch/arm64/include/asm/kvm_host.h struct vcpu_reset_state { · line 851

Quoted 4 lines
arch/arm64/include/asm/kvm_host.h +1 -0
@@ -843,6 +848,8 @@ struct vcpu_reset_state {
 	bool		reset;
 };
 
+#endif /* ARM64_S390_COMMON */

Given that this is a standalone structure without any dependency, could you simply move it to a "nicer" place as part of the reshuffling patch?

Quoted 47 lines
arch/arm64/include/asm/kvm_host.h +8 -0
+
 struct vncr_tlb;
 
 struct kvm_vcpu_arch {
@@ -952,6 +959,7 @@ struct kvm_vcpu_arch {
 	pid_t pid;
 };
 
+#ifdef ARM64_S390_COMMON
 /*
  * Each 'flag' is composed of a comma-separated triplet:
  *
@@ -1105,6 +1113,8 @@ struct kvm_vcpu_arch {
 /* KVM is currently emulating an L2 to L1 exception */
 #define IN_NESTED_EXCEPTION	__vcpu_single_flag(sflags, BIT(9))
 
+#endif /* ARM64_S390_COMMON */
+
 #define vcpu_sve_max_vq(vcpu)	sve_vq_from_vl((vcpu)->arch.sve_max_vl)
 
 #define vcpu_sve_zcr_elx(vcpu)						\
@@ -1240,6 +1250,7 @@ struct kvm_vcpu_stat {
 	u64 exits;
 };
 
+#ifdef ARM64_S390_COMMON
 unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
 int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices);
 int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
@@ -1248,6 +1259,8 @@ int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
 unsigned long kvm_arm_num_sys_reg_descs(struct kvm_vcpu *vcpu);
 int kvm_arm_copy_sys_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices);
 
+#endif /* ARM64_S390_COMMON */
+
 int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
 			      struct kvm_vcpu_events *events);
 
@@ -1326,6 +1339,7 @@ int __init populate_nv_trap_config(void);
 
 void kvm_calculate_traps(struct kvm_vcpu *vcpu);
 
+#ifdef ARM64_S390_COMMON
 /* MMIO helpers */
 void kvm_mmio_write_buf(void *buf, unsigned int len, unsigned long data);
 unsigned long kvm_mmio_read_buf(const void *buf, unsigned int len);

arch/arm64/include/asm/kvm_host.h unsigned long kvm_mmio_read_buf(const void *buf, unsigned int len); · line 1350

Quoted 4 lines
arch/arm64/include/asm/kvm_host.h +1 -0
@@ -1333,6 +1347,8 @@ unsigned long kvm_mmio_read_buf(const void *buf, unsigned int len);
 int kvm_handle_mmio_return(struct kvm_vcpu *vcpu);
 int io_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa);
 
+#endif /* ARM64_S390_COMMON */

Similarly, it'd be marginally better if you moved some of these prototypes together, as below (untested).

arch/arm64/include/asm/kvm_host.h +11 -11
index e6b3d42abb08d..21d1318babe45 100644
@@ -1250,17 +1250,6 @@ struct kvm_vcpu_stat {
 	u64 exits;
 };
 
-#ifdef ARM64_S390_COMMON
-unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
-int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices);
-int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
-int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
-
-unsigned long kvm_arm_num_sys_reg_descs(struct kvm_vcpu *vcpu);
-int kvm_arm_copy_sys_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices);
-
-#endif /* ARM64_S390_COMMON */
-
 int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
 			      struct kvm_vcpu_events *events);
 
@@ -1340,6 +1329,17 @@ int __init populate_nv_trap_config(void);
 void kvm_calculate_traps(struct kvm_vcpu *vcpu);
 
 #ifdef ARM64_S390_COMMON
+
+/* Userspace access to guest state */
+unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
+int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices);
+
+unsigned long kvm_arm_num_sys_reg_descs(struct kvm_vcpu *vcpu);
+int kvm_arm_copy_sys_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices);
+
+int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
+int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
+
 /* MMIO helpers */
 void kvm_mmio_write_buf(void *buf, unsigned int len, unsigned long data);
 unsigned long kvm_mmio_read_buf(const void *buf, unsigned int len);

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author reviewer
#23 lore raw

Re: [PATCH v6 08/33] KVM: arm64: Use accessor functions for core regs

In reply to Marc Zyngier
Quoted 5 lines · Marc Zyngier
Quoted 2 lines · Steffen Eiden

Instead of accessing the value directly use assessor function that

Quoted 8 lines

s/assessor function/accessors/

Quoted 3 lines

abstract the actual location of the register values. Add a helper function to reset fpsimd registers. Enable other KVM implementations to reuse this code.

to reuse this code by overloading the accessors.

Will change

...

Quoted 4 lines
Quoted 4 lines
arch/arm64/kvm/guest.c +0 -0
index b01d6622b872..773f6c8e5026 100644
Quoted 9 lines

arch/arm64/kvm/guest.c static void *core_reg_addr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) · line 137

Quoted 6 lines
arch/arm64/kvm/guest.c +1 -1
@@ -134,19 +134,19 @@ static void *core_reg_addr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 	     KVM_REG_ARM_CORE_REG(regs.regs[30]):
 		off -= KVM_REG_ARM_CORE_REG(regs.mregs[0]);
 		off /= 2;
-		return &vcpu->arch.ctxt.regs.regs[off];
+		return &vcpu_gp_regs(vcpu)[off];

Doesn't this belong to the previous patch?

My thoughts about positioning this change in this patch:

The previous patch changes the semantics of vcpu_gp_regs and just touched the part where the old semantic of the function was used. This is mainly done by not using vcpu_gp_regs where it was used before as it cannot be used to access e.g. pstate anymore.

This patch then introduces and *uses* new accessor functions for abstractions (and uses the vcpu_gp_regs abstraction where it was not used before).
-> The patch changes direct accesses to using accessor functions.

However, I have no strong feelings for this. If you want this in the previous patch, I can do that.

Steffen

author reviewer
#16 lore raw

Re: [PATCH v6 06/33] arm64: sysreg: Convert SPSR_ELx to automatic register generation

In reply to Marc Zyngier
Quoted 33 lines · Marc Zyngier
Quoted 14 lines · Steffen Eiden

Convert SPSR_EL{1, 2, 12} to automatic register generation as per DDIO616 2026-06. No functional change.

---
 arch/arm64/include/asm/sysreg.h |  3 ---
 arch/arm64/tools/sysreg         | 48 +++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 3 deletions(-)
arch/arm64/include/asm/sysreg.h +0 -0
index 4bfdac9401bd..1aa601c95188 100644

[...]

arch/arm64/include/asm/sysreg.h

Quoted 6 lines
arch/arm64/include/asm/sysreg.h +6 -0
+Enum	4:0	M
+	0b0000	EL0
+	0b0100	EL1t
+	0b0101	EL1h
+	0b1000	EL2t
+	0b1001	EL2h

I think you need to be consistent with the way you represent things, as you are mixing two representations:

- either you have a separate M[4] representing PSTATE.nRW, and then the M[3-0] enum is a 4 bit field (and for simplicity you only describe the AArch64 ELs including EL3[th], which are missing here)

Quoted 7 lines

- or M is a 5 bit field and, and you represent everything as a 5 bit enum, providing all the AArch32 modes and EL3.

The former matches the JSON, the latter is closer to the representation in older versions of the ARM ARM.

Pick one, stick to it.

Ok I'll do the first/JSON approach:

...
Field 4 M4
Enum 3:0 M

	0b0000	EL0
	0b0100	EL1t
	0b0101	EL1h
	0b1000	EL2t
	0b1001	EL2h
	0b1100	EL3t
	0b1101	EL3h

EndEnum

Steffen

author reviewer
#30 lore raw

Re: [PATCH v6 09/33] arm64: Prepare sharing arm64 headers with s390

In reply to Marc Zyngier
Quoted 3 lines · Marc Zyngier

On Wed, 12 Aug 2026 16:36:05 +0100,
Steffen Eiden <[email protected]> wrote:

...

Quoted 7 lines

I don't mind the move, but please add a comment indicating that these are bit indices for for kvm_arch::flags, as we have now lost locality.

And whilst we're at it, there is not reason why this has to be a set of #define, it can perfectly be an enum, as the numbers themselves have no particular meaning. Something like the untested hack below.

Makes sense. Will do that.

Steffen

maintainer
#24 lore raw

Re: [PATCH v6 08/33] KVM: arm64: Use accessor functions for core regs

In reply to Steffen Eiden
Quoted 5 lines · Steffen Eiden
Quoted 3 lines · Marc Zyngier
Quoted 1 line · Steffen Eiden

[...]

Quoted 21 lines
Quoted 4 lines
Quoted 4 lines
arch/arm64/kvm/guest.c +0 -0
index b01d6622b872..773f6c8e5026 100644
Quoted 9 lines

arch/arm64/kvm/guest.c static void *core_reg_addr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) · line 137

Quoted 6 lines
arch/arm64/kvm/guest.c +1 -1
@@ -134,19 +134,19 @@ static void *core_reg_addr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 	     KVM_REG_ARM_CORE_REG(regs.regs[30]):
 		off -= KVM_REG_ARM_CORE_REG(regs.mregs[0]);
 		off /= 2;
-		return &vcpu->arch.ctxt.regs.regs[off];
+		return &vcpu_gp_regs(vcpu)[off];

Doesn't this belong to the previous patch?

My thoughts about positioning this change in this patch:

The previous patch changes the semantics of vcpu_gp_regs and just touched the part where the old semantic of the function was used. This is mainly done by not using vcpu_gp_regs where it was used before as it cannot be used to access e.g. pstate anymore.

Quoted 7 lines

This patch then introduces and *uses* new accessor functions for abstractions (and uses the vcpu_gp_regs abstraction where it was not used before).
-> The patch changes direct accesses to using accessor functions.

However, I have no strong feelings for this. If you want this in the previous patch, I can do that.

I think it'd make more sense. You can capture this in the commit message to make it clear.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author reviewer
#34 lore raw

Re: [PATCH v6 10/33] arm64: Share arm64 headers with s390

In reply to Marc Zyngier
Quoted 32 lines · Marc Zyngier
Quoted 30 lines · Steffen Eiden

Allow sharing of arm64 headers with s390 by marking the shared regions or add a comment that the whole file is shared.

The shared regions are marked with:

#ifdef ARM64_S390_COMMON

/* insert shared definitions here */

#endif /* ARM64_S390_COMMON */

The preprocessor symbol ARM64_S390_COMMON is always defined for arm64. s390 later will generate its own view of arm64 headers based on the content inside the ifdef/endif block.

No functional change.

---
 arch/arm64/Makefile                  |  2 ++
 arch/arm64/include/asm/brk-imm.h     |  1 +
 arch/arm64/include/asm/esr.h         |  1 +
 arch/arm64/include/asm/kvm_arm.h     |  1 +
 arch/arm64/include/asm/kvm_emulate.h | 18 ++++++++++++++++++
 arch/arm64/include/asm/kvm_host.h    | 20 ++++++++++++++++++++
 arch/arm64/include/asm/ptrace.h      |  4 ++++
 arch/arm64/include/asm/sysreg.h      | 15 +++++++++++++++
 8 files changed, 62 insertions(+)

...

Quoted 59 lines
Quoted 59 lines
arch/arm64/include/asm/kvm_emulate.h +9 -0
index a34a9417ff4d..09f04a5686a1 100644
@@ -47,6 +47,7 @@ void kvm_skip_instr32(struct kvm_vcpu *vcpu);
 int kvm_inject_dabt_excl_atomic(struct kvm_vcpu *vcpu, u64 addr);
 int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr);
 
+#ifdef ARM64_S390_COMMON
 void kvm_inject_undefined(struct kvm_vcpu *vcpu);
 void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr);
 int kvm_inject_sea(struct kvm_vcpu *vcpu, bool iabt, u64 addr);
@@ -62,6 +63,8 @@ static inline int kvm_inject_sea_iabt(struct kvm_vcpu *vcpu, u64 addr)
 	return kvm_inject_sea(vcpu, true, addr);
 }
 
+#endif /* ARM64_S390_COMMON */
+
 static inline int kvm_inject_serror(struct kvm_vcpu *vcpu)
 {
 	/*
@@ -185,6 +188,7 @@ static inline void vcpu_set_thumb(struct kvm_vcpu *vcpu)
 	*vcpu_cpsr(vcpu) |= PSR_AA32_T_BIT;
 }
 
+#ifdef ARM64_S390_COMMON
 /*
  * vcpu_get_reg and vcpu_set_reg should always be passed a register number
  * coming from a read of ESR_EL2. Otherwise, it may give the wrong result on
@@ -203,6 +207,8 @@ static __always_inline void vcpu_set_reg(struct kvm_vcpu *vcpu, u8 reg_num,
 		vcpu_gp_regs(vcpu)[reg_num] = val;
 }
 
+#endif /* ARM64_S390_COMMON */
+
 static inline bool vcpu_is_el2_ctxt(const struct kvm_cpu_context *ctxt)
 {
 	switch (ctxt->regs.pstate & (PSR_MODE32_BIT | PSR_MODE_MASK)) {
@@ -405,6 +411,7 @@ static inline u64 kvm_vcpu_get_disr(const struct kvm_vcpu *vcpu)
 	return vcpu->arch.fault.disr_el1;
 }
 
+#ifdef ARM64_S390_COMMON
 static inline u32 kvm_vcpu_hvc_get_imm(const struct kvm_vcpu *vcpu)
 {
 	return kvm_vcpu_get_esr(vcpu) & ESR_ELx_xVC_IMM_MASK;
@@ -482,6 +489,8 @@ static __always_inline u8 kvm_vcpu_trap_get_fault(const struct kvm_vcpu *vcpu)
 	return kvm_vcpu_get_esr(vcpu) & ESR_ELx_FSC;
 }
 
+#endif /* ARM64_S390_COMMON */
+
 static inline
 bool kvm_vcpu_trap_is_permission_fault(const struct kvm_vcpu *vcpu)
 {
@@ -522,6 +531,7 @@ static __always_inline int kvm_vcpu_sys_get_rt(struct kvm_vcpu *vcpu)
 	return ESR_ELx_SYS64_ISS_RT(esr);
 }
 
Quoted 6 lines

arch/arm64/include/asm/kvm_emulate.h static __always_inline int kvm_vcpu_sys_get_rt(struct kvm_vcpu *vcpu) · line 534

Quoted 1 line
arch/arm64/include/asm/kvm_emulate.h +1 -0
+#ifdef ARM64_S390_COMMON

I'm curious about the reasons for skipping a bunch of architectural helpers:

- kvm_vcpu_trap_is_permission_fault()

we need the s390 state for this function -> we overload it the only use is in shared arm64 code for is_write_fault

Quoted 3 lines

- kvm_vcpu_trap_is_translation_fault()
- kvm_vcpu_trap_get_perm_fault_granule()
- kvm_vcpu_abt_issea()

as s390 mm works differntly in comparison to ARMs (suprise :) ) we do not need those

Quoted 1 line

- kvm_vcpu_sys_get_rt()

I'll add using this function in the next series (sysreg enablement) I can do that now - It reduces the churn to the next series.

Quoted 6 lines

I really think you should include anything that is exclusively derived from architectural state, specially that these helpers are strictly dependent on stuff you already include.

Any particular reason why this isn't the case?

These functions operate right at the border where the s390 architectural state (host view) and the arm64 architectural state (guest view) meet.

Especially, for the memory management of the guest we need to use s390 based guest memory management (gmap) as the host only knows s390 (+SAE & friends to actually run an arm64 guest)

The s390 host work here is to convert the s390-state into arm64 state for the guest. e.g. convert a s390 translation fault into a data abort (if applicable)

The code in the second series should make this more clear. As we now are clear on the code-sharing concept I will sent a respin of the second series using the new sharing approach ASAP.

Quoted 23 lines
Quoted 14 lines
arch/arm64/include/asm/kvm_emulate.h +2 -0
 static inline bool kvm_is_write_fault(struct kvm_vcpu *vcpu)
 {
 	if (kvm_vcpu_abt_iss1tw(vcpu)) {
@@ -546,6 +556,8 @@ static inline bool kvm_is_write_fault(struct kvm_vcpu *vcpu)
 	return kvm_vcpu_dabt_iswrite(vcpu);
 }
 
+#endif /* ARM64_S390_COMMON */
+
 static inline unsigned long kvm_vcpu_get_mpidr_aff(struct kvm_vcpu *vcpu)
 {
 	return __vcpu_sys_reg(vcpu, MPIDR_EL1) & MPIDR_HWID_BITMASK;

arch/arm64/include/asm/kvm_emulate.h static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu) · line 602

Quoted 4 lines
arch/arm64/include/asm/kvm_emulate.h +1 -0
@@ -587,6 +599,7 @@ static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu)
 	return vcpu_read_sys_reg(vcpu, r) & bit;
 }
 
+#ifdef ARM64_S390_COMMON

Similarly, you have dropped

- kvm_vcpu_set_be()

Quoted 7 lines

- kvm_vcpu_is_be()

I suspect that your implementation is LE only (it'd better be, as we're dropping BE support right now), but it would make a lot more sense if you could rely on the guest architectural state (which must be accurate) rather than short-cutting things in your own implementation.

Yes, you are right we are LE only. Therefore, I defined the function to false such that the compiler/linker can optimize-out unreachable code. This is true for a couple of function-shortcuts.

I would like to keep it that way if this is no show stopper for you.

...

Quoted 34 lines
Quoted 34 lines
arch/arm64/include/asm/kvm_host.h +5 -0
index 22770c1132cb..e6b3d42abb08 100644
@@ -39,6 +39,7 @@
 
 #define KVM_MAX_VCPUS VGIC_V3_MAX_CPUS
 
+#ifdef ARM64_S390_COMMON
 #define KVM_VCPU_MAX_FEATURES 10
 #define KVM_VCPU_VALID_FEATURES	(BIT(KVM_VCPU_MAX_FEATURES) - 1)
 
@@ -86,6 +87,8 @@
 /* Unhandled SEAs are taken to userspace */
 #define KVM_ARCH_FLAG_EXIT_SEA				11
 
+#endif /* ARM64_S390_COMMON */
+
 #define KVM_DIRTY_LOG_MANUAL_CAPS   (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \
 				     KVM_DIRTY_LOG_INITIALLY_SET)
 
@@ -836,6 +839,8 @@ extern s64 kvm_nvhe_sym(hyp_physvirt_offset);
 extern u64 kvm_nvhe_sym(hyp_cpu_logical_map)[NR_CPUS];
 #define hyp_cpu_logical_map CHOOSE_NVHE_SYM(hyp_cpu_logical_map)
 
+#ifdef ARM64_S390_COMMON
+
 struct vcpu_reset_state {
 	unsigned long	pc;
 	unsigned long	r0;
@@ -843,6 +848,8 @@ struct vcpu_reset_state {
 	bool		reset;
 };
 
Quoted 6 lines

arch/arm64/include/asm/kvm_host.h struct vcpu_reset_state { · line 851

Quoted 1 line
arch/arm64/include/asm/kvm_host.h +1 -0
+#endif /* ARM64_S390_COMMON */

Given that this is a standalone structure without any dependency, could you simply move it to a "nicer" place as part of the reshuffling patch?

Yes, no problem.

I just wanted to limit the number of moves. I'll guess we will meet in the middle somewhere :)

...

Quoted 21 lines
Quoted 21 lines
arch/arm64/include/asm/kvm_host.h +3 -0
@@ -1248,6 +1259,8 @@ int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
 unsigned long kvm_arm_num_sys_reg_descs(struct kvm_vcpu *vcpu);
 int kvm_arm_copy_sys_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices);
 
+#endif /* ARM64_S390_COMMON */
+
 int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
 			      struct kvm_vcpu_events *events);
 
@@ -1326,6 +1339,7 @@ int __init populate_nv_trap_config(void);
 
 void kvm_calculate_traps(struct kvm_vcpu *vcpu);
 
+#ifdef ARM64_S390_COMMON
 /* MMIO helpers */
 void kvm_mmio_write_buf(void *buf, unsigned int len, unsigned long data);
 unsigned long kvm_mmio_read_buf(const void *buf, unsigned int len);
@@ -1333,6 +1347,8 @@ unsigned long kvm_mmio_read_buf(const void *buf, unsigned int len);
 int kvm_handle_mmio_return(struct kvm_vcpu *vcpu);
 int io_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa);
 
Quoted 5 lines

arch/arm64/include/asm/kvm_host.h unsigned long kvm_mmio_read_buf(const void *buf, unsigned int len); · line 1350

Quoted 1 line
arch/arm64/include/asm/kvm_host.h +1 -0
+#endif /* ARM64_S390_COMMON */

Similarly, it'd be marginally better if you moved some of these prototypes together, as below (untested).

Will do.

Steffen

...

author reviewer
#25 lore raw

Re: [PATCH v6 08/33] KVM: arm64: Use accessor functions for core regs

In reply to Marc Zyngier
Quoted 36 lines · Marc Zyngier
Quoted 5 lines · Steffen Eiden
Quoted 3 lines · Marc Zyngier
Quoted 1 line · Steffen Eiden

[...]

Quoted 26 lines
Quoted 4 lines
Quoted 4 lines
arch/arm64/kvm/guest.c +0 -0
index b01d6622b872..773f6c8e5026 100644
Quoted 9 lines

arch/arm64/kvm/guest.c static void *core_reg_addr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) · line 137

Quoted 6 lines
arch/arm64/kvm/guest.c +1 -1
@@ -134,19 +134,19 @@ static void *core_reg_addr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 	     KVM_REG_ARM_CORE_REG(regs.regs[30]):
 		off -= KVM_REG_ARM_CORE_REG(regs.mregs[0]);
 		off /= 2;
-		return &vcpu->arch.ctxt.regs.regs[off];
+		return &vcpu_gp_regs(vcpu)[off];

Doesn't this belong to the previous patch?

My thoughts about positioning this change in this patch:

The previous patch changes the semantics of vcpu_gp_regs and just touched the part where the old semantic of the function was used. This is mainly done by not using vcpu_gp_regs where it was used before as it cannot be used to access e.g. pstate anymore.

This patch then introduces and *uses* new accessor functions for abstractions (and uses the vcpu_gp_regs abstraction where it was not used before).
-> The patch changes direct accesses to using accessor functions.

Quoted 5 lines
Quoted 2 lines

However, I have no strong feelings for this. If you want this in the previous patch, I can do that.

I think it'd make more sense. You can capture this in the commit message to make it clear.

Just that we are on the same page: you want me to move the change to the previous patch?

Steffen

maintainer
#26 lore raw

Re: [PATCH v6 08/33] KVM: arm64: Use accessor functions for core regs

Quoted 38 lines · Steffen Eiden
Quoted 36 lines · Marc Zyngier
Quoted 5 lines · Steffen Eiden
Quoted 3 lines · Marc Zyngier
Quoted 1 line · Steffen Eiden

[...]

Quoted 26 lines
Quoted 4 lines
Quoted 4 lines
arch/arm64/kvm/guest.c +0 -0
index b01d6622b872..773f6c8e5026 100644
Quoted 9 lines

arch/arm64/kvm/guest.c static void *core_reg_addr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) · line 137

Quoted 6 lines
arch/arm64/kvm/guest.c +1 -1
@@ -134,19 +134,19 @@ static void *core_reg_addr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 	     KVM_REG_ARM_CORE_REG(regs.regs[30]):
 		off -= KVM_REG_ARM_CORE_REG(regs.mregs[0]);
 		off /= 2;
-		return &vcpu->arch.ctxt.regs.regs[off];
+		return &vcpu_gp_regs(vcpu)[off];

Doesn't this belong to the previous patch?

My thoughts about positioning this change in this patch:

The previous patch changes the semantics of vcpu_gp_regs and just touched the part where the old semantic of the function was used. This is mainly done by not using vcpu_gp_regs where it was used before as it cannot be used to access e.g. pstate anymore.

This patch then introduces and *uses* new accessor functions for abstractions (and uses the vcpu_gp_regs abstraction where it was not used before).
-> The patch changes direct accesses to using accessor functions.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

However, I have no strong feelings for this. If you want this in the previous patch, I can do that.

I think it'd make more sense. You can capture this in the commit message to make it clear.

Just that we are on the same page: you want me to move the change to the previous patch?

Yes, please.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
maintainer
#35 lore raw

Re: [PATCH v6 10/33] arm64: Share arm64 headers with s390

In reply to Steffen Eiden
Quoted 29 lines · Steffen Eiden
Quoted 4 lines · Marc Zyngier

I'm curious about the reasons for skipping a bunch of architectural helpers:

- kvm_vcpu_trap_is_permission_fault()

we need the s390 state for this function -> we overload it the only use is in shared arm64 code for is_write_fault

Quoted 3 lines

- kvm_vcpu_trap_is_translation_fault()
- kvm_vcpu_trap_get_perm_fault_granule()
- kvm_vcpu_abt_issea()

as s390 mm works differntly in comparison to ARMs (suprise :) ) we do not need those

Quoted 1 line

- kvm_vcpu_sys_get_rt()

I'll add using this function in the next series (sysreg enablement) I can do that now - It reduces the churn to the next series.

Quoted 6 lines

I really think you should include anything that is exclusively derived from architectural state, specially that these helpers are strictly dependent on stuff you already include.

Any particular reason why this isn't the case?

These functions operate right at the border where the s390 architectural state (host view) and the arm64 architectural state (guest view) meet.

Quoted 7 lines

Especially, for the memory management of the guest we need to use s390 based guest memory management (gmap) as the host only knows s390 (+SAE & friends to actually run an arm64 guest)

The s390 host work here is to convert the s390-state into arm64 state for the guest. e.g. convert a s390 translation fault into a data abort (if applicable)

Exactly. Which is why I was expecting that the s390 code would populate the copy of the ESR_EL2 register in the vcpu structure, and let the arm64 code do the talking. But evidently, that's not what is happening (or at least not that way).

Quoted 37 lines

The code in the second series should make this more clear. As we now are clear on the code-sharing concept I will sent a respin of the second series using the new sharing approach ASAP.

Quoted 23 lines
Quoted 14 lines

static inline bool kvm_is_write_fault(struct kvm_vcpu *vcpu) {

(quoted diff) +2 -0
 	if (kvm_vcpu_abt_iss1tw(vcpu)) {
@@ -546,6 +556,8 @@ static inline bool kvm_is_write_fault(struct kvm_vcpu *vcpu)
 	return kvm_vcpu_dabt_iswrite(vcpu);
 }
 
+#endif /* ARM64_S390_COMMON */
+
 static inline unsigned long kvm_vcpu_get_mpidr_aff(struct kvm_vcpu *vcpu)
 {
 	return __vcpu_sys_reg(vcpu, MPIDR_EL1) & MPIDR_HWID_BITMASK;

Review static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu) · line 602

Quoted 4 lines
(quoted diff) +1 -0
@@ -587,6 +599,7 @@ static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu)
 	return vcpu_read_sys_reg(vcpu, r) & bit;
 }
 
+#ifdef ARM64_S390_COMMON

Similarly, you have dropped

- kvm_vcpu_set_be()

Quoted 7 lines

- kvm_vcpu_is_be()

I suspect that your implementation is LE only (it'd better be, as we're dropping BE support right now), but it would make a lot more sense if you could rely on the guest architectural state (which must be accurate) rather than short-cutting things in your own implementation.

Quoted 5 lines

Yes, you are right we are LE only. Therefore, I defined the function to false such that the compiler/linker can optimize-out unreachable code. This is true for a couple of function-shortcuts.

I would like to keep it that way if this is no show stopper for you.

Not a show-stopper, but I think we'll eventually want to work more at the architecture level rather than solely at the "code sharing" level.

I expect it would make things a bit simpler to follow.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
maintainer
#97 lore raw

Re: [PATCH v6 33/33] KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild

In reply to Steffen Eiden

On Wed, 12 Aug 2026 16:36:29 +0100,
Steffen Eiden <[email protected]> wrote:

[...]

Quoted 7 lines
arch/s390/kvm/Kconfig +7 -0
+config KVM_ARM64
+	def_tristate y
+	prompt "KVM support for hardware accelerated arm64 guests"
+	depends on HAS_IOMEM
+	depends on KVM
+	select GUEST_PERF_EVENTS if PERF_EVENTS
+	select HAVE_KVM_CPU_RELAX_INTERCEPT

arch/s390/kvm/Kconfig config KVM_S390_UCONTROL · line 72

Quoted 10 lines
arch/s390/kvm/Kconfig +10 -0
+	select HAVE_KVM_IRQCHIP
+	select HAVE_KVM_VCPU_RUN_PID_CHANGE
+	select IRQ_BYPASS_MANAGER
+	select KVM_COMMON
+	select KVM_MMIO
+	select KVM_VFIO
+	select SCHED_INFO
+	select XARRAY_MULTI
+	help
+	  Enable support for hosting paravirtualized, hardware-accelerated

Err... No.

KVM/arm64 is architectural, and doesn't require anything PV. I suspect this is a direct copy-paste from the s390 text, but this does not represent what KVM/arm64 does, and transitively what KVM/arm64-on-s390 should do.

Please drop the PV nonsense.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
maintainer
#82 lore raw

Re: [PATCH v6 28/33] KVM: s390: Add basic arm64 kvm module

In reply to Steffen Eiden
Quoted 22 lines · Steffen Eiden

Add basic code for the new arm64 on s390 KVM implementation. Add kernel module boilerplate code and trivial functions. Add tracing scaffolding.

---
  arch/s390/kvm/arm64/arm.c   | 157 ++++++++++++++++++++++++++++++++++++
  arch/s390/kvm/arm64/arm.h   |   7 ++
  arch/s390/kvm/arm64/guest.c |  92 +++++++++++++++++++++
  arch/s390/kvm/arm64/trace.h |  18 +++++
  4 files changed, 274 insertions(+)

create mode 100644 arch/s390/kvm/arm64/arm.c
create mode 100644 arch/s390/kvm/arm64/arm.h
create mode 100644 arch/s390/kvm/arm64/guest.c
create mode 100644 arch/s390/kvm/arm64/trace.h

arch/s390/kvm/arm64/arm.c new file +0 -0
new file mode 100644
index 000000000000..8e17b7eef813
@@ -0,0 +1,157 @@

[...]

arch/s390/kvm/arm64/arm.c line 54

Quoted 11 lines
arch/s390/kvm/arm64/arm.c new file +11 -0
+
+static u64 kvm_max_guest_address(void)
+{
+	u64 max_addr;
+
+	if (sclp.hamax == U64_MAX)
+		max_addr = TASK_SIZE_MAX;
+	else
+		max_addr = min_t(u64, TASK_SIZE_MAX, sclp.hamax);
+	return ALIGN_DOWN(max_addr + 1, 1 << 30) - 1;
+}

We're sure that the MSLA + 1 - MSOA > MGPAS check aka VIR code 4 will never bite us? Or will you touch this up with the qmc support?

maintainer
#86 lore raw

Re: [PATCH v6 29/33] KVM: s390: arm64: Implement required functions

In reply to Steffen Eiden
Quoted 22 lines · Steffen Eiden

Implement the mostly trivial functions that the shared arm64 (kvm) code & headers oblige s390 to implement.

Implement a very basic smccc handler that (non-compliantly) is just able to stop a vcpu.

---
  arch/s390/include/arm64/kvm_emulate.h | 130 ++++++++++++++++++++++++++
  arch/s390/include/arm64/kvm_nested.h  |  11 +++
  arch/s390/include/arm64/ptrace.h      |  11 +++
  arch/s390/include/arm64/sysreg.h      |  13 +++
  arch/s390/kvm/arm64/handle_exit.c     |  98 +++++++++++++++++++
  arch/s390/kvm/arm64/inject_fault.c    |  21 +++++
  6 files changed, 284 insertions(+)

create mode 100644 arch/s390/include/arm64/kvm_emulate.h create mode 100644 arch/s390/include/arm64/kvm_nested.h create mode 100644 arch/s390/include/arm64/ptrace.h create mode 100644 arch/s390/include/arm64/sysreg.h create mode 100644 arch/s390/kvm/arm64/handle_exit.c create mode 100644 arch/s390/kvm/arm64/inject_fault.c

[...]

arch/s390/include/arm64/kvm_emulate.h line 71

Quoted 8 lines
arch/s390/include/arm64/kvm_emulate.h new file +8 -0
+static __always_inline unsigned long kvm_vcpu_get_hfar(const struct kvm_vcpu *vcpu)
+{
+	return vcpu->arch.sae_block.hai.far_elz;
+}
+
+static __always_inline phys_addr_t kvm_vcpu_get_fault_ipa(const struct kvm_vcpu *vcpu)
+{
+	return vcpu->arch.sae_block.hai.teid.addr * PAGE_SIZE;

gfn_to_gpa()?

maintainer
#91 lore raw

Re: [PATCH v6 31/33] KVM: s390: arm64: Implement vCPU IOCTLs

In reply to Steffen Eiden
Quoted 20 lines · Steffen Eiden

Implement all required vCPU IOCTLs.

---
  arch/s390/kvm/arm64/arm.c         | 392 ++++++++++++++++++++++++++++++
  arch/s390/kvm/arm64/guest.c       |  47 +++-
  arch/s390/kvm/arm64/handle_exit.c |  31 +++
  arch/s390/kvm/arm64/handle_exit.h |   9 +
  arch/s390/kvm/arm64/reset.c       |  73 ++++++
  arch/s390/kvm/arm64/reset.h       |  11 +
  arch/s390/kvm/arm64/trace.h       |   2 +-
  7 files changed, 562 insertions(+), 3 deletions(-)

create mode 100644 arch/s390/kvm/arm64/handle_exit.h create mode 100644 arch/s390/kvm/arm64/reset.c create mode 100644 arch/s390/kvm/arm64/reset.h

[...]

arch/s390/kvm/arm64/arm.c static unsigned long system_supported_vcpu_features(void) · line 309

Quoted 9 lines
arch/s390/kvm/arm64/arm.c +9 -0
+static int kvm_vcpu_initialize(struct kvm_vcpu *vcpu,
+			       const struct kvm_vcpu_init *init)
+{
+	unsigned long features = init->features[0];
+	struct kvm *kvm = vcpu->kvm;
+
+	scoped_guard(mutex, &kvm->arch.config_lock) {
+		if (test_bit(KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED,
+			     &kvm->arch.flags) &&

In this case I'd rather have a long line than having to look at this mess. One of the cases where a normal mutex acquisition would have made the code more readable.

Quoted 12 lines
arch/s390/kvm/arm64/arm.c +12 -0
+		    kvm_vcpu_init_changed(vcpu, init))
+			return -EINVAL;
+
+		bitmap_copy(kvm->arch.vcpu_features, &features,
+			    KVM_VCPU_MAX_FEATURES);
+
+		kvm_reset_vcpu(vcpu);
+
+		set_bit(KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED,
+			&kvm->arch.flags);
+		vcpu_set_flag(vcpu, VCPU_INITIALIZED);
+	}

[...]

Quoted 33 lines
arch/s390/kvm/arm64/arm.c +33 -0
+/** kvm_arch_vcpu_ioctl_run() - run arm64 vCPU
+ *
+ * Execute arm64 guest instructions using SAE.
+ *
+ * Returns:
+ * 1 enter the guest (should not be observed by userspace)
+ * 0 exit to userspace
+ * < 0 exit to userspace, where the return value indicates n error
+ *
+ *
+ */
+int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
+{
+	DECLARE_KERNEL_FPU_ONSTACK32(fpu_save);
+	struct kvm_run *kvm_run = vcpu->run;
+	int ret;
+
+	if (kvm_run->exit_reason == KVM_EXIT_MMIO) {
+		ret = kvm_handle_mmio_return(vcpu);
+		if (ret <= 0)
+			return ret;
+	}
+
+	vcpu_load(vcpu);
+
+	kernel_fpu_begin(&fpu_save, KERNEL_FPC | KERNEL_VXR);
+	load_vx_regs((vcpu->arch.ctxt.vregs));
+
+	if (!vcpu->wants_to_run) {
+		ret = -EINTR;
+		goto out;
+	}
+

arch/s390/kvm/arm64/arm.c static unsigned long system_supported_vcpu_features(void) · line 446

Quoted 10 lines
arch/s390/kvm/arm64/arm.c +10 -0
+	kvm_sigset_activate(vcpu);
+
+	might_fault();
+
+	ret = 1;
+	do {
+		if (signal_pending(current)) {
+			kvm_run->exit_reason = KVM_EXIT_INTR;
+			ret = -EINTR;
+			continue;

Why not break?
With continue we'll jump to the condition which is immediately false since we just set ret to a negative value.

Quoted 27 lines
arch/s390/kvm/arm64/arm.c +27 -0
+		}
+
+		if (need_resched())
+			schedule();
+
+		if (ret > 0)
+			ret = check_vcpu_requests(vcpu);
+
+		vcpu->arch.sae_block.icptr = 0;
+
+		arm_vcpu_run(vcpu);
+
+		ret = handle_exit(vcpu);
+
+	} while (ret > 0);
+
+	kvm_sigset_deactivate(vcpu);
+out:
+	if (unlikely(vcpu_get_flag(vcpu, INCREMENT_PC)))
+		adjust_pc(vcpu);
+
+	save_vx_regs(vcpu->arch.ctxt.vregs);
+	kernel_fpu_end(&fpu_save, KERNEL_FPC | KERNEL_VXR);
+	vcpu_put(vcpu);
+
+	return ret;
+}
author reviewer
#83 lore raw

Re: [PATCH v6 28/33] KVM: s390: Add basic arm64 kvm module

In reply to Janosch Frank
Quoted 26 lines · Janosch Frank
Quoted 22 lines · Steffen Eiden

Add basic code for the new arm64 on s390 KVM implementation. Add kernel module boilerplate code and trivial functions. Add tracing scaffolding.

---
  arch/s390/kvm/arm64/arm.c   | 157 ++++++++++++++++++++++++++++++++++++
  arch/s390/kvm/arm64/arm.h   |   7 ++
  arch/s390/kvm/arm64/guest.c |  92 +++++++++++++++++++++
  arch/s390/kvm/arm64/trace.h |  18 +++++
  4 files changed, 274 insertions(+)

create mode 100644 arch/s390/kvm/arm64/arm.c
create mode 100644 arch/s390/kvm/arm64/arm.h
create mode 100644 arch/s390/kvm/arm64/guest.c
create mode 100644 arch/s390/kvm/arm64/trace.h

arch/s390/kvm/arm64/arm.c new file +0 -0
new file mode 100644
index 000000000000..8e17b7eef813
@@ -0,0 +1,157 @@

[...]

Quoted 13 lines

arch/s390/kvm/arm64/arm.c line 54

Quoted 11 lines
arch/s390/kvm/arm64/arm.c new file +11 -0
+
+static u64 kvm_max_guest_address(void)
+{
+	u64 max_addr;
+
+	if (sclp.hamax == U64_MAX)
+		max_addr = TASK_SIZE_MAX;
+	else
+		max_addr = min_t(u64, TASK_SIZE_MAX, sclp.hamax);
+	return ALIGN_DOWN(max_addr + 1, 1 << 30) - 1;
+}

We're sure that the MSLA + 1 - MSOA > MGPAS check aka VIR code 4 will never bite us? Or will you touch this up with the qmc support?

Series 2 with qmc support will in addition verify that the maximum guest address is smaller or equal to MGPAS, which is calculated from the PARange. MSO is always zero, so we should not run into this invalidity.

Steffen

author reviewer
#92 lore raw

Re: [PATCH v6 31/33] KVM: s390: arm64: Implement vCPU IOCTLs

In reply to Janosch Frank
Quoted 24 lines · Janosch Frank
Quoted 20 lines · Steffen Eiden

Implement all required vCPU IOCTLs.

---
  arch/s390/kvm/arm64/arm.c         | 392 ++++++++++++++++++++++++++++++
  arch/s390/kvm/arm64/guest.c       |  47 +++-
  arch/s390/kvm/arm64/handle_exit.c |  31 +++
  arch/s390/kvm/arm64/handle_exit.h |   9 +
  arch/s390/kvm/arm64/reset.c       |  73 ++++++
  arch/s390/kvm/arm64/reset.h       |  11 +
  arch/s390/kvm/arm64/trace.h       |   2 +-
  7 files changed, 562 insertions(+), 3 deletions(-)

create mode 100644 arch/s390/kvm/arm64/handle_exit.h create mode 100644 arch/s390/kvm/arm64/reset.c create mode 100644 arch/s390/kvm/arm64/reset.h

[...]

Quoted 14 lines

arch/s390/kvm/arm64/arm.c static unsigned long system_supported_vcpu_features(void) · line 309

Quoted 9 lines
arch/s390/kvm/arm64/arm.c +9 -0
+static int kvm_vcpu_initialize(struct kvm_vcpu *vcpu,
+			       const struct kvm_vcpu_init *init)
+{
+	unsigned long features = init->features[0];
+	struct kvm *kvm = vcpu->kvm;
+
+	scoped_guard(mutex, &kvm->arch.config_lock) {
+		if (test_bit(KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED,
+			     &kvm->arch.flags) &&

In this case I'd rather have a long line than having to look at this mess. One of the cases where a normal mutex acquisition would have made the code more readable.

Technically, it would not fit into the 80chars even if I use traditional locks.

Nontheless, I'll use a guard(mutex) and then go 2 chars over the limit for improved reading.

...

Quoted 12 lines

arch/s390/kvm/arm64/arm.c static unsigned long system_supported_vcpu_features(void) · line 446

Quoted 7 lines
arch/s390/kvm/arm64/arm.c +7 -0
+
+	ret = 1;
+	do {
+		if (signal_pending(current)) {
+			kvm_run->exit_reason = KVM_EXIT_INTR;
+			ret = -EINTR;
+			continue;

Why not break?
With continue we'll jump to the condition which is immediately false since we just set ret to a negative value.

I'll break

Steffen