* [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM
@ 2026-07-06 8:52 Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 01/27] VFIO: take reference to the KVM module Steffen Eiden
` (26 more replies)
0 siblings, 27 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
This series is a complete rework of previous versions [1], fundamentally
changing the approach to code and header sharing between s390 and arm64.
For the original, now partially outdated, cover letter, have a look at one of
the previous versions [1].
The new approach does not move arm64 code to a shared location. Instead,
during build time, 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 the 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
KVM symbol cleanup and refactoring (patches 1-5):
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 remove KVM_MMIO as a config
option.
Arm64 header and code sharing preparation (patches 6-9):
Mark shareable parts with ARM64_S390_COMMON. Perform minor refactoring
to ease integration into s390.
Code sharing infrastructure for s390 (patches 10&11):
Add Makefile and scripts to extract and build arm64 headers and code for
use by s390.
KVM/s390 reorganization (patches 12-17):
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.
KVM on s390 (patches 18-26):
Introduce the SAE (Start Arm Execution) instruction as the s390
mechanism for running arm64 guests. Build up the new kvm-arm64 module
incrementally.
I hope that this new approach suits arm64 better. I definitely think this way
of doing things is more elegant, has less churn, and less work for us all.
Some comments:
I want to create a verification tool for you arm guys that mimics the s390 use
of the arm64 code and headers but compiles/works on arm64 as a quick sanity
check for any arm64 developer. I have some general Ideas (A C file including
all the arm code & headers and see if it compiles) about how to do this but no
concrete ideas yet. Pointers/Ideas are highly appreciated
To further harden the extraction of code/headers one could do the following:
1. Expand all the macros on the header/code
a) with -DARM64_S390_COMMON
b) without -DARM64_S390_COMMON
2. The diff of a & b should be the stuff s390 needs
3. Postprocess it a bit (guards and copyight)
But the AWK approach looked more straight forward and simpler.
There is no way around it - In the future Arm64 maintainers should at least
build s390 before sending merge request.
Steffen
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/20260402042125.3948963-1-seiden@linux.ibm.com/
v2 https://lore.kernel.org/all/20260428155622.1361364-1-seiden@linux.ibm.com/
v3 https://lore.kernel.org/all/20260529155050.2902245-1-seiden@linux.ibm.com/
Hendrik Brueckner (1):
s390/hwcaps: Report SAE support as hwcap
Paolo Bonzini (3):
VFIO: take reference to the KVM module
KVM, vfio: remove symbol_get(kvm_get_kvm_safe) from vfio
KVM, vfio: remove symbol_get(kvm_put_kvm) from vfio
Steffen Eiden (23):
KVM: Make device name configurable
KVM: Remove KVM_MMIO as config option
arm64: Use proper include variant
arm64: Prepare sharing arm64 headers with s390
KVM: arm64: Prepare sharing arm64 code with s390
KVM: arm64: Access elements of vcpu_gp_regs individually
KVM: arm64: Refactor core-reset into a separate function
s390: Use arm64 headers
KVM: s390: Use arm64 code
KVM: s390: Prepare KVM/s390 for a second KVM module
KVM: s390: Move s390 kvm code into a subdirectory
KVM: S390: Prepare gmap for a second KVM implementation
KVM: s390: gmap: Refactor storage key and CMMA code into separate
files
KVM: s390: Refactor prefix handling into a separate file
KVM: s390: Prepare kvm-s390 for a second kvm module
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
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 | 32 +-
arch/arm64/include/asm/kvm_host.h | 38 +-
arch/arm64/include/asm/kvm_mmu.h | 6 +
arch/arm64/include/asm/ptrace.h | 9 +
arch/arm64/include/asm/sysreg.h | 31 +-
arch/arm64/kvm/Kconfig | 1 -
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 | 7 +-
arch/arm64/kvm/hyp/include/hyp/adjust_pc.h | 4 +-
arch/arm64/kvm/hyp/include/hyp/switch.h | 6 +-
arch/arm64/kvm/mmio.c | 14 +
arch/arm64/kvm/reset.c | 46 +-
arch/loongarch/include/asm/kvm_host.h | 2 +
arch/loongarch/kvm/Kconfig | 1 -
arch/mips/include/asm/kvm_host.h | 2 +
arch/mips/kvm/Kconfig | 1 -
arch/powerpc/include/asm/kvm_host.h | 7 +
arch/powerpc/kvm/Kconfig | 4 -
arch/riscv/include/asm/kvm_host.h | 2 +
arch/riscv/kvm/Kconfig | 1 -
arch/s390/Kconfig | 2 +-
arch/s390/boot/ipl_parm.c | 2 +-
arch/s390/boot/uv.c | 2 +-
arch/s390/configs/debug_defconfig | 2 +-
arch/s390/configs/defconfig | 3 +-
arch/s390/include/arm64/kvm_emulate.h | 135 +++
arch/s390/include/arm64/kvm_nested.h | 11 +
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 | 772 +-----------------
arch/s390/include/asm/kvm_host_arm64.h | 210 +++++
arch/s390/include/asm/kvm_host_arm64_types.h | 129 +++
.../asm/{kvm_host.h => kvm_host_s390.h} | 17 +-
...kvm_host_types.h => kvm_host_s390_types.h} | 6 +-
arch/s390/include/asm/kvm_host_types.h | 351 +-------
arch/s390/include/asm/sae.h | 56 ++
arch/s390/include/asm/sclp.h | 5 +-
arch/s390/include/asm/stacktrace.h | 5 +
arch/s390/kernel/asm-offsets.c | 1 +
arch/s390/kernel/early.c | 2 +-
arch/s390/kernel/entry.S | 35 +-
arch/s390/kernel/perf_event.c | 2 +-
arch/s390/kernel/processor.c | 3 +
arch/s390/kvm/Kconfig | 37 +-
arch/s390/kvm/Makefile | 12 +-
arch/s390/kvm/arm64/Kconfig | 23 +
arch/s390/kvm/arm64/Makefile | 94 +++
arch/s390/kvm/arm64/Makefile.gen | 30 +
arch/s390/kvm/arm64/arm.c | 726 ++++++++++++++++
arch/s390/kvm/arm64/arm.h | 63 ++
arch/s390/kvm/arm64/copy-arm64c.awk | 69 ++
arch/s390/kvm/arm64/guest.c | 169 ++++
arch/s390/kvm/arm64/guest.h | 14 +
arch/s390/kvm/arm64/handle_exit.c | 143 ++++
arch/s390/kvm/arm64/handle_exit.h | 9 +
arch/s390/kvm/arm64/inject_fault.c | 21 +
arch/s390/kvm/arm64/mmio.c | 12 +
arch/s390/kvm/arm64/mmu.c | 178 ++++
arch/s390/kvm/arm64/reset.c | 62 ++
arch/s390/kvm/arm64/reset.h | 11 +
arch/s390/kvm/gmap/Makefile | 12 +
arch/s390/kvm/gmap/cmma.c | 313 +++++++
arch/s390/kvm/gmap/cmma.h | 36 +
arch/s390/kvm/{ => gmap}/dat.c | 552 +------------
arch/s390/kvm/{ => gmap}/dat.h | 20 +-
arch/s390/kvm/{ => gmap}/faultin.c | 11 +-
arch/s390/kvm/{ => gmap}/faultin.h | 6 +-
arch/s390/kvm/{ => gmap}/gmap.c | 114 +--
arch/s390/kvm/{ => gmap}/gmap.h | 44 +-
arch/s390/kvm/gmap/mmu.c | 193 +++++
arch/s390/kvm/gmap/prefix-stubs.c | 21 +
arch/s390/kvm/gmap/prefix.c | 80 ++
arch/s390/kvm/gmap/prefix.h | 68 ++
arch/s390/kvm/gmap/sk.c | 264 ++++++
arch/s390/kvm/gmap/sk.h | 18 +
arch/s390/kvm/gmap/trace-gmap.h | 59 ++
arch/s390/kvm/{ => s390}/Kconfig | 27 +-
arch/s390/kvm/{ => s390}/Makefile | 10 +-
arch/s390/kvm/{ => s390}/diag.c | 2 +-
arch/s390/kvm/{ => s390}/gaccess.c | 3 +-
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 | 4 +-
arch/s390/kvm/{ => s390}/pv.c | 2 +-
arch/s390/kvm/{kvm-s390.c => s390/s390.c} | 146 +---
arch/s390/kvm/{kvm-s390.h => s390/s390.h} | 18 +-
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 | 5 +
arch/s390/tools/Makefile.arm64h | 58 ++
arch/s390/tools/copy-arm64h-full.awk | 43 +
arch/s390/tools/copy-arm64h.awk | 71 ++
arch/s390/tools/opcodes.txt | 3 +
arch/x86/include/asm/kvm_host.h | 2 +
arch/x86/kvm/Kconfig | 1 -
arch/x86/kvm/mmu/tdp_mmu.c | 2 +-
arch/x86/kvm/svm/sev.c | 2 +-
arch/x86/kvm/vmx/nested.h | 4 +-
drivers/s390/char/sclp_early.c | 1 +
drivers/vfio/device_cdev.c | 2 +-
drivers/vfio/group.c | 5 +-
drivers/vfio/vfio.h | 15 +-
drivers/vfio/vfio_main.c | 52 +-
include/linux/kvm_host.h | 17 +-
include/linux/kvm_types.h | 33 +
include/linux/vfio.h | 4 +-
virt/kvm/Kconfig | 3 -
virt/kvm/Makefile.kvm | 3 +-
virt/kvm/coalesced_mmio.c | 3 +
virt/kvm/coalesced_mmio.h | 2 +-
virt/kvm/kvm_main.c | 75 +-
virt/kvm/vfio.c | 4 +-
126 files changed, 3944 insertions(+), 2212 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/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} (98%)
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/Kconfig
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/guest.h
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/gmap/Makefile
create mode 100644 arch/s390/kvm/gmap/cmma.c
create mode 100644 arch/s390/kvm/gmap/cmma.h
rename arch/s390/kvm/{ => gmap}/dat.c (61%)
rename arch/s390/kvm/{ => gmap}/dat.h (96%)
rename arch/s390/kvm/{ => gmap}/faultin.c (96%)
rename arch/s390/kvm/{ => gmap}/faultin.h (96%)
rename arch/s390/kvm/{ => gmap}/gmap.c (93%)
rename arch/s390/kvm/{ => gmap}/gmap.h (94%)
create mode 100644 arch/s390/kvm/gmap/mmu.c
create mode 100644 arch/s390/kvm/gmap/prefix-stubs.c
create mode 100644 arch/s390/kvm/gmap/prefix.c
create mode 100644 arch/s390/kvm/gmap/prefix.h
create mode 100644 arch/s390/kvm/gmap/sk.c
create mode 100644 arch/s390/kvm/gmap/sk.h
create mode 100644 arch/s390/kvm/gmap/trace-gmap.h
copy arch/s390/kvm/{ => s390}/Kconfig (61%)
copy arch/s390/kvm/{ => s390}/Makefile (53%)
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} (97%)
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: 8cdeaa50eae8dad34885515f62559ee83e7e8dda
--
2.53.0
^ permalink raw reply [flat|nested] 41+ messages in thread
* [PATCH v4 01/27] VFIO: take reference to the KVM module
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 19:53 ` Jason Gunthorpe
2026-07-06 8:52 ` [PATCH v4 02/27] KVM, vfio: remove symbol_get(kvm_get_kvm_safe) from vfio Steffen Eiden
` (25 subsequent siblings)
26 siblings, 1 reply; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
From: Paolo Bonzini <pbonzini@redhat.com>
VFIO is implicitly taking a reference to the KVM module between
vfio_device_get_kvm_safe and vfio_device_put_kvm, thanks to
symbol_get and symbol_put.
In preparation for removing symbol_get and symbol_put themselves
from VFIO, actually store a pointer to the KVM module and use
module_get()/module_put() to keep KVM alive.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Acked-by: Alex Williamson <alex@shazbot.org>
---
drivers/vfio/device_cdev.c | 2 +-
drivers/vfio/group.c | 5 +++--
drivers/vfio/vfio.h | 15 ++++++++++-----
drivers/vfio/vfio_main.c | 38 ++++++++++++++++++++++++--------------
include/linux/vfio.h | 3 ++-
virt/kvm/vfio.c | 4 ++--
6 files changed, 42 insertions(+), 25 deletions(-)
diff --git a/drivers/vfio/device_cdev.c b/drivers/vfio/device_cdev.c
index 54abf312cf04..a729be99d06c 100644
--- a/drivers/vfio/device_cdev.c
+++ b/drivers/vfio/device_cdev.c
@@ -56,7 +56,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, df->kvm_module);
spin_unlock(&df->kvm_ref_lock);
}
diff --git a/drivers/vfio/group.c b/drivers/vfio/group.c
index b2299e5bc6df..fc24c0b2cc6f 100644
--- a/drivers/vfio/group.c
+++ b/drivers/vfio/group.c
@@ -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, device->group->kvm_module);
spin_unlock(&device->group->kvm_ref_lock);
}
@@ -860,10 +860,11 @@ 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 kvm *kvm, struct module *kvm_module)
{
spin_lock(&group->kvm_ref_lock);
group->kvm = kvm;
+ group->kvm_module = kvm_module;
spin_unlock(&group->kvm_ref_lock);
}
diff --git a/drivers/vfio/vfio.h b/drivers/vfio/vfio.h
index e4b72e79b7e3..8209da17246c 100644
--- a/drivers/vfio/vfio.h
+++ b/drivers/vfio/vfio.h
@@ -22,8 +22,9 @@ struct vfio_device_file {
u8 access_granted;
u32 devid; /* only valid when iommufd is valid */
- spinlock_t kvm_ref_lock; /* protect kvm field */
+ spinlock_t kvm_ref_lock; /* protect kvm and kvm_module fields */
struct kvm *kvm;
+ struct module *kvm_module;
struct iommufd_ctx *iommufd; /* protected by struct vfio_device_set::lock */
};
@@ -89,6 +90,7 @@ struct vfio_group {
enum vfio_group_type type;
struct mutex group_lock;
struct kvm *kvm;
+ struct module *kvm_module;
struct file *opened_file;
struct iommufd_ctx *iommufd;
spinlock_t kvm_ref_lock;
@@ -107,7 +109,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 kvm *kvm, struct module *kvm_module);
bool vfio_device_has_container(struct vfio_device *device);
int __init vfio_group_init(void);
void vfio_group_cleanup(void);
@@ -170,7 +172,8 @@ static inline bool vfio_group_enforced_coherent(struct vfio_group *group)
return true;
}
-static inline void vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm)
+static inline void vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm,
+ struct module *kvm_module)
{
}
@@ -434,11 +437,13 @@ 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 kvm *kvm,
+ struct module *kvm_module);
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 kvm *kvm,
+ struct module *kvm_module)
{
}
diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
index ed538aebb0b8..8289aca97b6b 100644
--- a/drivers/vfio/vfio_main.c
+++ b/drivers/vfio/vfio_main.c
@@ -448,7 +448,8 @@ 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 kvm *kvm,
+ struct module *kvm_module)
{
void (*pfn)(struct kvm *kvm);
bool (*fn)(struct kvm *kvm);
@@ -459,25 +460,31 @@ void vfio_device_get_kvm_safe(struct vfio_device *device, struct kvm *kvm)
if (!kvm)
return;
+ if (!try_module_get(kvm_module))
+ return;
+
pfn = symbol_get(kvm_put_kvm);
if (WARN_ON(!pfn))
- return;
+ goto out_put_mod;
fn = symbol_get(kvm_get_kvm_safe);
- if (WARN_ON(!fn)) {
- symbol_put(kvm_put_kvm);
- return;
- }
+ if (WARN_ON(!fn))
+ goto out_put_sym;
ret = fn(kvm);
symbol_put(kvm_get_kvm_safe);
- if (!ret) {
- symbol_put(kvm_put_kvm);
- return;
- }
+ if (!ret)
+ goto out_put_sym;
device->put_kvm = pfn;
device->kvm = kvm;
+ device->kvm_module = kvm_module;
+ return;
+
+out_put_sym:
+ symbol_put(kvm_put_kvm);
+out_put_mod:
+ module_put(kvm_module);
}
void vfio_device_put_kvm(struct vfio_device *device)
@@ -496,6 +503,8 @@ void vfio_device_put_kvm(struct vfio_device *device)
clear:
device->kvm = NULL;
+ module_put(device->kvm_module);
+ device->kvm_module = NULL;
}
#endif
@@ -1520,7 +1529,7 @@ bool vfio_file_enforced_coherent(struct file *file)
}
EXPORT_SYMBOL_GPL(vfio_file_enforced_coherent);
-static void vfio_device_file_set_kvm(struct file *file, struct kvm *kvm)
+static void vfio_device_file_set_kvm(struct file *file, struct kvm *kvm, struct module *kvm_module)
{
struct vfio_device_file *df = file->private_data;
@@ -1531,6 +1540,7 @@ static void vfio_device_file_set_kvm(struct file *file, struct kvm *kvm)
*/
spin_lock(&df->kvm_ref_lock);
df->kvm = kvm;
+ df->kvm_module = kvm_module;
spin_unlock(&df->kvm_ref_lock);
}
@@ -1542,16 +1552,16 @@ static void vfio_device_file_set_kvm(struct file *file, struct kvm *kvm)
* When a VFIO device is first opened the KVM will be available in
* device->kvm if one was associated with the file.
*/
-void vfio_file_set_kvm(struct file *file, struct kvm *kvm)
+void vfio_file_set_kvm(struct file *file, struct kvm *kvm, struct module *kvm_module)
{
struct vfio_group *group;
group = vfio_group_from_file(file);
if (group)
- vfio_group_set_kvm(group, kvm);
+ vfio_group_set_kvm(group, kvm, kvm_module);
if (vfio_device_from_file(file))
- vfio_device_file_set_kvm(file, kvm);
+ vfio_device_file_set_kvm(file, kvm, kvm_module);
}
EXPORT_SYMBOL_GPL(vfio_file_set_kvm);
diff --git a/include/linux/vfio.h b/include/linux/vfio.h
index 31b826efba00..5bfec0339804 100644
--- a/include/linux/vfio.h
+++ b/include/linux/vfio.h
@@ -55,6 +55,7 @@ struct vfio_device {
unsigned int migration_flags;
u8 precopy_info_v2;
struct kvm *kvm;
+ struct module *kvm_module;
/* Members below here are private, not for driver use */
unsigned int index;
@@ -377,7 +378,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 *file, struct kvm *kvm, struct module *kvm_module);
#define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long))
diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
index 6cdc4e9a333a..c593f31136f9 100644
--- a/virt/kvm/vfio.c
+++ b/virt/kvm/vfio.c
@@ -37,13 +37,13 @@ struct kvm_vfio {
static void kvm_vfio_file_set_kvm(struct file *file, struct kvm *kvm)
{
- void (*fn)(struct file *file, struct kvm *kvm);
+ void (*fn)(struct file *file, struct kvm *kvm, struct module *kvm_module);
fn = symbol_get(vfio_file_set_kvm);
if (!fn)
return;
- fn(file, kvm);
+ fn(file, kvm, kvm ? THIS_MODULE : NULL);
symbol_put(vfio_file_set_kvm);
}
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 02/27] KVM, vfio: remove symbol_get(kvm_get_kvm_safe) from vfio
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 01/27] VFIO: take reference to the KVM module Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 03/27] KVM, vfio: remove symbol_get(kvm_put_kvm) " Steffen Eiden
` (24 subsequent siblings)
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
From: Paolo Bonzini <pbonzini@redhat.com>
Right now, KVM and VFIO are using symbol_get to access each other's
symbols because of a circular reference between the modules, as well
as to avoid loading them unnecessarily.
However, usage of symbol_get is mostly deprecated and there are just a
handful of users left. In the case of VFIO, in particular, the
functions it calls can be made inline. Start with kvm_get_kvm_safe,
for which it is trivial to do so.
While at it, move the function from kvm_host.h to kvm_types.h.
Unlike e.g. drivers/s390/crypto/vfio_ap_ops.c, there's no need for
VFIO to know any implementation details of KVM, and struct kvm
can be treated as an opaque type.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Acked-by: Alex Williamson <alex@shazbot.org>
---
arch/x86/kvm/mmu/tdp_mmu.c | 2 +-
arch/x86/kvm/svm/sev.c | 2 +-
arch/x86/kvm/vmx/nested.h | 4 ++--
drivers/vfio/vfio_main.c | 8 +-------
include/linux/kvm_host.h | 8 ++++----
include/linux/kvm_types.h | 24 ++++++++++++++++++++++++
virt/kvm/kvm_main.c | 29 +++++++----------------------
7 files changed, 40 insertions(+), 37 deletions(-)
diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
index c1cbae65d239..913edd9403e5 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.c
+++ b/arch/x86/kvm/mmu/tdp_mmu.c
@@ -1089,7 +1089,7 @@ void kvm_tdp_mmu_invalidate_roots(struct kvm *kvm,
* being destroyed in an error path of KVM_CREATE_VM.
*/
if (IS_ENABLED(CONFIG_PROVE_LOCKING) &&
- refcount_read(&kvm->users_count) && kvm->created_vcpus)
+ refcount_read(&kvm->rc.users_count) && kvm->created_vcpus)
lockdep_assert_held_write(&kvm->mmu_lock);
/*
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 427229347876..f588129f7a4f 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -115,7 +115,7 @@ static __always_inline void kvm_lockdep_assert_sev_lock_held(struct kvm *kvm)
* Querying SEV+ support is safe if there are no other references, i.e.
* if concurrent initialization of SEV+ is impossible.
*/
- if (!refcount_read(&kvm->users_count))
+ if (!refcount_read(&kvm->rc.users_count))
return;
/*
diff --git a/arch/x86/kvm/vmx/nested.h b/arch/x86/kvm/vmx/nested.h
index 6d6cd5904ddf..a4647859fe1f 100644
--- a/arch/x86/kvm/vmx/nested.h
+++ b/arch/x86/kvm/vmx/nested.h
@@ -58,7 +58,7 @@ bool nested_vmx_check_io_bitmaps(struct kvm_vcpu *vcpu, unsigned int port,
static inline struct vmcs12 *get_vmcs12(struct kvm_vcpu *vcpu)
{
lockdep_assert_once(lockdep_is_held(&vcpu->mutex) ||
- !refcount_read(&vcpu->kvm->users_count));
+ !refcount_read(&vcpu->kvm->rc.users_count));
return to_vmx(vcpu)->nested.cached_vmcs12;
}
@@ -66,7 +66,7 @@ static inline struct vmcs12 *get_vmcs12(struct kvm_vcpu *vcpu)
static inline struct vmcs12 *get_shadow_vmcs12(struct kvm_vcpu *vcpu)
{
lockdep_assert_once(lockdep_is_held(&vcpu->mutex) ||
- !refcount_read(&vcpu->kvm->users_count));
+ !refcount_read(&vcpu->kvm->rc.users_count));
return to_vmx(vcpu)->nested.cached_shadow_vmcs12;
}
diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
index 8289aca97b6b..b7b8b45f1cec 100644
--- a/drivers/vfio/vfio_main.c
+++ b/drivers/vfio/vfio_main.c
@@ -452,7 +452,6 @@ void vfio_device_get_kvm_safe(struct vfio_device *device, struct kvm *kvm,
struct module *kvm_module)
{
void (*pfn)(struct kvm *kvm);
- bool (*fn)(struct kvm *kvm);
bool ret;
lockdep_assert_held(&device->dev_set->lock);
@@ -467,12 +466,7 @@ void vfio_device_get_kvm_safe(struct vfio_device *device, struct kvm *kvm,
if (WARN_ON(!pfn))
goto out_put_mod;
- fn = symbol_get(kvm_get_kvm_safe);
- if (WARN_ON(!fn))
- goto out_put_sym;
-
- ret = fn(kvm);
- symbol_put(kvm_get_kvm_safe);
+ ret = kvm_get_kvm_safe(kvm);
if (!ret)
goto out_put_sym;
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index ab8cfaec82d3..015d02018109 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -768,6 +768,9 @@ struct kvm_memslots {
};
struct kvm {
+ /* Must be the first field, see function definitions in kvm_types.h. */
+ struct kvm_refcount rc;
+
#ifdef KVM_HAVE_MMU_RWLOCK
rwlock_t mmu_lock;
#else
@@ -831,7 +834,6 @@ struct kvm {
struct list_head ioeventfds;
struct kvm_vm_stat stat;
struct kvm_arch arch;
- refcount_t users_count;
#ifdef CONFIG_KVM_MMIO
struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
spinlock_t ring_lock;
@@ -1070,8 +1072,6 @@ static inline void kvm_irqfd_exit(void)
int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module);
void kvm_exit(void);
-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);
void kvm_put_kvm_no_destroy(struct kvm *kvm);
@@ -1081,7 +1081,7 @@ static inline struct kvm_memslots *__kvm_memslots(struct kvm *kvm, int as_id)
as_id = array_index_nospec(as_id, KVM_MAX_NR_ADDRESS_SPACES);
return srcu_dereference_check(kvm->memslots[as_id], &kvm->srcu,
lockdep_is_held(&kvm->slots_lock) ||
- !refcount_read(&kvm->users_count));
+ !refcount_read(&kvm->rc.users_count));
}
static inline struct kvm_memslots *kvm_memslots(struct kvm *kvm)
diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h
index a568d8e6f4e8..add7cc2016e8 100644
--- a/include/linux/kvm_types.h
+++ b/include/linux/kvm_types.h
@@ -33,6 +33,7 @@
#include <linux/mutex.h>
#include <linux/spinlock_types.h>
+#include <linux/refcount.h>
struct kvm;
struct kvm_async_pf;
@@ -140,6 +141,29 @@ struct kvm_vcpu_stat_generic {
};
#define KVM_STATS_NAME_SIZE 48
+
+struct kvm_refcount {
+ refcount_t users_count;
+};
+
+static inline void kvm_get_kvm(struct kvm *kvm)
+{
+ struct kvm_refcount *rc = (struct kvm_refcount *)kvm;
+
+ refcount_inc(&rc->users_count);
+}
+
+/*
+ * A safe version of kvm_get_kvm(), making sure the vm is not being destroyed.
+ * Return true if kvm referenced successfully, false otherwise.
+ */
+static inline bool kvm_get_kvm_safe(struct kvm *kvm)
+{
+ struct kvm_refcount *rc = (struct kvm_refcount *)kvm;
+
+ return refcount_inc_not_zero(&rc->users_count);
+}
+
#endif /* !__ASSEMBLER__ */
#endif /* __KVM_TYPES_H__ */
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e44c20c04961..7dec697ce35a 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1089,7 +1089,7 @@ static inline struct kvm_io_bus *kvm_get_bus_for_destruction(struct kvm *kvm,
enum kvm_bus idx)
{
return rcu_dereference_protected(kvm->buses[idx],
- !refcount_read(&kvm->users_count));
+ !refcount_read(&kvm->rc.users_count));
}
static int kvm_enable_virtualization(void);
@@ -1146,7 +1146,8 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname)
if (r)
goto out_err_no_irq_routing;
- refcount_set(&kvm->users_count, 1);
+ BUILD_BUG_ON(offsetof(struct kvm, rc) != 0);
+ refcount_set(&kvm->rc.users_count, 1);
for (i = 0; i < kvm_arch_nr_memslot_as_ids(kvm); i++) {
for (j = 0; j < 2; j++) {
@@ -1216,7 +1217,7 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname)
out_err_no_disable:
kvm_arch_destroy_vm(kvm);
out_err_no_arch_destroy_vm:
- WARN_ON_ONCE(!refcount_dec_and_test(&kvm->users_count));
+ WARN_ON_ONCE(!refcount_dec_and_test(&kvm->rc.users_count));
for (i = 0; i < KVM_NR_BUSES; i++)
kfree(kvm_get_bus_for_destruction(kvm, i));
kvm_free_irq_routing(kvm);
@@ -1309,25 +1310,9 @@ static void kvm_destroy_vm(struct kvm *kvm)
mmdrop(mm);
}
-void kvm_get_kvm(struct kvm *kvm)
-{
- refcount_inc(&kvm->users_count);
-}
-EXPORT_SYMBOL_GPL(kvm_get_kvm);
-
-/*
- * Make sure the vm is not during destruction, which is a safe version of
- * kvm_get_kvm(). Return true if kvm referenced successfully, false otherwise.
- */
-bool kvm_get_kvm_safe(struct kvm *kvm)
-{
- return refcount_inc_not_zero(&kvm->users_count);
-}
-EXPORT_SYMBOL_GPL(kvm_get_kvm_safe);
-
void kvm_put_kvm(struct kvm *kvm)
{
- if (refcount_dec_and_test(&kvm->users_count))
+ if (refcount_dec_and_test(&kvm->rc.users_count))
kvm_destroy_vm(kvm);
}
EXPORT_SYMBOL_GPL(kvm_put_kvm);
@@ -1341,7 +1326,7 @@ EXPORT_SYMBOL_GPL(kvm_put_kvm);
*/
void kvm_put_kvm_no_destroy(struct kvm *kvm)
{
- WARN_ON(refcount_dec_and_test(&kvm->users_count));
+ WARN_ON(refcount_dec_and_test(&kvm->rc.users_count));
}
EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_put_kvm_no_destroy);
@@ -3520,7 +3505,7 @@ void mark_page_dirty_in_slot(struct kvm *kvm,
if (WARN_ON_ONCE(vcpu && vcpu->kvm != kvm))
return;
- WARN_ON_ONCE(!vcpu && refcount_read(&kvm->users_count) &&
+ WARN_ON_ONCE(!vcpu && refcount_read(&kvm->rc.users_count) &&
!kvm_arch_allow_write_without_running_vcpu(kvm));
#endif
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 03/27] KVM, vfio: remove symbol_get(kvm_put_kvm) from vfio
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 01/27] VFIO: take reference to the KVM module Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 02/27] KVM, vfio: remove symbol_get(kvm_get_kvm_safe) from vfio Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 04/27] KVM: Make device name configurable Steffen Eiden
` (23 subsequent siblings)
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
From: Paolo Bonzini <pbonzini@redhat.com>
Right now, KVM and VFIO are using symbol_get to access each other's
symbols because of a circular reference between the modules, as well
as to avoid loading them unnecessarily.
The remaining use in VFIO is for kvm_put_kvm, which is not inline
because it needs to call kvm_destroy_vm. However, storing the
address of kvm_destroy_vm in the "struct kvm" is enough to remove
the dependency from VFIO.
This also makes it possible to direct kvm_put_kvm to either the arm64
or the s390 implementation of kvm_destroy_vm.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Acked-by: Alex Williamson <alex@shazbot.org>
---
drivers/vfio/vfio_main.c | 24 +++---------------------
include/linux/kvm_host.h | 1 -
include/linux/kvm_types.h | 9 +++++++++
include/linux/vfio.h | 1 -
virt/kvm/kvm_main.c | 9 ++-------
5 files changed, 14 insertions(+), 30 deletions(-)
diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
index b7b8b45f1cec..6bddea4d384f 100644
--- a/drivers/vfio/vfio_main.c
+++ b/drivers/vfio/vfio_main.c
@@ -17,7 +17,7 @@
#include <linux/idr.h>
#include <linux/iommu.h>
#if IS_ENABLED(CONFIG_KVM)
-#include <linux/kvm_host.h>
+#include <linux/kvm_types.h>
#endif
#include <linux/list.h>
#include <linux/miscdevice.h>
@@ -451,9 +451,6 @@ EXPORT_SYMBOL_GPL(vfio_unregister_group_dev);
void vfio_device_get_kvm_safe(struct vfio_device *device, struct kvm *kvm,
struct module *kvm_module)
{
- void (*pfn)(struct kvm *kvm);
- bool ret;
-
lockdep_assert_held(&device->dev_set->lock);
if (!kvm)
@@ -462,21 +459,13 @@ void vfio_device_get_kvm_safe(struct vfio_device *device, struct kvm *kvm,
if (!try_module_get(kvm_module))
return;
- pfn = symbol_get(kvm_put_kvm);
- if (WARN_ON(!pfn))
+ if (!kvm_get_kvm_safe(kvm))
goto out_put_mod;
- ret = kvm_get_kvm_safe(kvm);
- if (!ret)
- goto out_put_sym;
-
- device->put_kvm = pfn;
device->kvm = kvm;
device->kvm_module = kvm_module;
return;
-out_put_sym:
- symbol_put(kvm_put_kvm);
out_put_mod:
module_put(kvm_module);
}
@@ -488,14 +477,7 @@ void vfio_device_put_kvm(struct vfio_device *device)
if (!device->kvm)
return;
- if (WARN_ON(!device->put_kvm))
- goto clear;
-
- device->put_kvm(device->kvm);
- device->put_kvm = NULL;
- symbol_put(kvm_put_kvm);
-
-clear:
+ kvm_put_kvm(device->kvm);
device->kvm = NULL;
module_put(device->kvm_module);
device->kvm_module = NULL;
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 015d02018109..1f967b1d68b9 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -1072,7 +1072,6 @@ static inline void kvm_irqfd_exit(void)
int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module);
void kvm_exit(void);
-void kvm_put_kvm(struct kvm *kvm);
bool file_is_kvm(struct file *file);
void kvm_put_kvm_no_destroy(struct kvm *kvm);
diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h
index add7cc2016e8..aadee536771a 100644
--- a/include/linux/kvm_types.h
+++ b/include/linux/kvm_types.h
@@ -144,6 +144,7 @@ struct kvm_vcpu_stat_generic {
struct kvm_refcount {
refcount_t users_count;
+ void (*destroy)(struct kvm *kvm);
};
static inline void kvm_get_kvm(struct kvm *kvm)
@@ -164,6 +165,14 @@ static inline bool kvm_get_kvm_safe(struct kvm *kvm)
return refcount_inc_not_zero(&rc->users_count);
}
+static inline void kvm_put_kvm(struct kvm *kvm)
+{
+ struct kvm_refcount *rc = (struct kvm_refcount *)kvm;
+
+ if (refcount_dec_and_test(&rc->users_count))
+ rc->destroy(kvm);
+}
+
#endif /* !__ASSEMBLER__ */
#endif /* __KVM_TYPES_H__ */
diff --git a/include/linux/vfio.h b/include/linux/vfio.h
index 5bfec0339804..81f04e60ebfd 100644
--- a/include/linux/vfio.h
+++ b/include/linux/vfio.h
@@ -67,7 +67,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;
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 7dec697ce35a..271884089f58 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -119,6 +119,7 @@ static struct dentry *kvm_debugfs_dir;
static const struct file_operations stat_fops_per_vm;
+static void kvm_destroy_vm(struct kvm *kvm);
static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl,
unsigned long arg);
#ifdef CONFIG_KVM_COMPAT
@@ -1148,6 +1149,7 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname)
BUILD_BUG_ON(offsetof(struct kvm, rc) != 0);
refcount_set(&kvm->rc.users_count, 1);
+ kvm->rc.destroy = kvm_destroy_vm;
for (i = 0; i < kvm_arch_nr_memslot_as_ids(kvm); i++) {
for (j = 0; j < 2; j++) {
@@ -1310,13 +1312,6 @@ static void kvm_destroy_vm(struct kvm *kvm)
mmdrop(mm);
}
-void kvm_put_kvm(struct kvm *kvm)
-{
- if (refcount_dec_and_test(&kvm->rc.users_count))
- kvm_destroy_vm(kvm);
-}
-EXPORT_SYMBOL_GPL(kvm_put_kvm);
-
/*
* Used to put a reference that was taken on behalf of an object associated
* with a user-visible file descriptor, e.g. a vcpu or device, if installation
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 04/27] KVM: Make device name configurable
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (2 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 03/27] KVM, vfio: remove symbol_get(kvm_put_kvm) " Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 05/27] KVM: Remove KVM_MMIO as config option Steffen Eiden
` (22 subsequent siblings)
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
Allow KVM implementations to choose alternative device names. This is
especially useful for architectures providing multiple KVM
implementations simultaneously.
Co-developed-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
include/linux/kvm_host.h | 4 +++-
virt/kvm/kvm_main.c | 31 +++++++++++++++++++++++--------
2 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 1f967b1d68b9..aa573e2530f7 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -1069,7 +1069,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);
bool file_is_kvm(struct file *file);
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 271884089f58..dcad33cc2f25 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -5542,9 +5542,7 @@ static struct file_operations kvm_chardev_ops = {
};
static struct miscdevice kvm_dev = {
- KVM_MINOR,
- "kvm",
- &kvm_chardev_ops,
+ .fops = &kvm_chardev_ops,
};
#ifdef CONFIG_KVM_GENERIC_HARDWARE_ENABLING
@@ -6322,13 +6320,13 @@ static void kvm_uevent_notify_change(unsigned int type, struct kvm *kvm)
kfree(env);
}
-static void kvm_init_debug(void)
+static void kvm_init_debug(const char *dev_name)
{
const struct file_operations *fops;
const struct kvm_stats_desc *pdesc;
int i;
- kvm_debugfs_dir = debugfs_create_dir("kvm", NULL);
+ kvm_debugfs_dir = debugfs_create_dir(dev_name, NULL);
for (i = 0; i < kvm_vm_stats_header.num_desc; ++i) {
pdesc = &kvm_vm_stats_desc[i];
@@ -6464,11 +6462,22 @@ void kvm_unregister_perf_callbacks(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)
+{
+ return kvm_init_with_dev(vcpu_size, vcpu_align, module, "kvm", KVM_MINOR);
+}
+
+int kvm_init_with_dev(unsigned int vcpu_size, unsigned int vcpu_align,
+ struct module *module, const char *dev_name, int minor)
{
int r;
int cpu;
+ kvm_dev.minor = minor;
+ kvm_dev.name = kstrdup(dev_name, GFP_KERNEL);
+ if (!kvm_dev.name)
+ return -ENOMEM;
+
/* A kmem cache lets us meet the alignment requirements of fx_save. */
if (!vcpu_align)
vcpu_align = __alignof__(struct kvm_vcpu);
@@ -6479,8 +6488,9 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)
offsetofend(struct kvm_vcpu, stats_id)
- offsetof(struct kvm_vcpu, arch),
NULL);
+ r = -ENOMEM;
if (!kvm_vcpu_cache)
- return -ENOMEM;
+ goto err_dev_name;
for_each_possible_cpu(cpu) {
if (!alloc_cpumask_var_node(&per_cpu(cpu_kick_mask, cpu),
@@ -6506,7 +6516,7 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)
kvm_preempt_ops.sched_in = kvm_sched_in;
kvm_preempt_ops.sched_out = kvm_sched_out;
- kvm_init_debug();
+ kvm_init_debug(kvm_dev.name);
r = kvm_vfio_ops_init();
if (WARN_ON_ONCE(r))
@@ -6547,6 +6557,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(kvm_dev.name);
return r;
}
EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_init);
@@ -6572,5 +6584,8 @@ void kvm_exit(void)
kvm_vfio_ops_exit();
kvm_async_pf_deinit();
kvm_irqfd_exit();
+
+ kfree(kvm_dev.name);
+ kvm_dev.name = NULL;
}
EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_exit);
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 05/27] KVM: Remove KVM_MMIO as config option
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (3 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 04/27] KVM: Make device name configurable Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 20:53 ` Marc Zyngier
2026-07-06 8:52 ` [PATCH v4 06/27] arm64: Use proper include variant Steffen Eiden
` (21 subsequent siblings)
26 siblings, 1 reply; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
Defining KVM_MMIO is not flexible enough for multi-KVM systems with
different Kconfig options regarding KVM_MMIO. Therefore, remove KVM_MMIO
from the config space and use the macro HAVE_KVM_MMIO instead.
Suggested-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/arm64/include/asm/kvm_host.h | 2 ++
arch/arm64/kvm/Kconfig | 1 -
arch/loongarch/include/asm/kvm_host.h | 2 ++
arch/loongarch/kvm/Kconfig | 1 -
arch/mips/include/asm/kvm_host.h | 2 ++
arch/mips/kvm/Kconfig | 1 -
arch/powerpc/include/asm/kvm_host.h | 7 +++++++
arch/powerpc/kvm/Kconfig | 4 ----
arch/riscv/include/asm/kvm_host.h | 2 ++
arch/riscv/kvm/Kconfig | 1 -
arch/x86/include/asm/kvm_host.h | 2 ++
arch/x86/kvm/Kconfig | 1 -
include/linux/kvm_host.h | 2 +-
virt/kvm/Kconfig | 3 ---
virt/kvm/Makefile.kvm | 3 +--
virt/kvm/coalesced_mmio.c | 3 +++
virt/kvm/coalesced_mmio.h | 2 +-
virt/kvm/kvm_main.c | 8 ++++----
18 files changed, 27 insertions(+), 20 deletions(-)
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index bae2c4f92ef5..245bda0fb571 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -33,6 +33,8 @@
#define KVM_HALT_POLL_NS_DEFAULT 500000
+#define HAVE_KVM_MMIO
+
#include <kvm/arm_vgic.h>
#include <kvm/arm_arch_timer.h>
#include <kvm/arm_pmu.h>
diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig
index 449154f9a485..dd138b730217 100644
--- a/arch/arm64/kvm/Kconfig
+++ b/arch/arm64/kvm/Kconfig
@@ -22,7 +22,6 @@ menuconfig KVM
select KVM_COMMON
select KVM_GENERIC_HARDWARE_ENABLING
select HAVE_KVM_CPU_RELAX_INTERCEPT
- select KVM_MMIO
select KVM_GENERIC_DIRTYLOG_READ_PROTECT
select VIRT_XFER_TO_GUEST_WORK
select KVM_VFIO
diff --git a/arch/loongarch/include/asm/kvm_host.h b/arch/loongarch/include/asm/kvm_host.h
index 23cfbecebbd7..47003a85b35a 100644
--- a/arch/loongarch/include/asm/kvm_host.h
+++ b/arch/loongarch/include/asm/kvm_host.h
@@ -27,6 +27,8 @@
#define __KVM_HAVE_ARCH_INTC_INITIALIZED
+#define HAVE_KVM_MMIO
+
/* Loongarch KVM register ids */
#define KVM_GET_IOC_CSR_IDX(id) ((id & KVM_CSR_IDX_MASK) >> LOONGARCH_REG_SHIFT)
#define KVM_GET_IOC_CPUCFG_IDX(id) ((id & KVM_CPUCFG_IDX_MASK) >> LOONGARCH_REG_SHIFT)
diff --git a/arch/loongarch/kvm/Kconfig b/arch/loongarch/kvm/Kconfig
index 15da2d88c0c1..f03872ba0ba8 100644
--- a/arch/loongarch/kvm/Kconfig
+++ b/arch/loongarch/kvm/Kconfig
@@ -28,7 +28,6 @@ config KVM
select KVM_COMMON
select KVM_GENERIC_DIRTYLOG_READ_PROTECT
select KVM_GENERIC_HARDWARE_ENABLING
- select KVM_MMIO
select VIRT_XFER_TO_GUEST_WORK
select SCHED_INFO
select GUEST_PERF_EVENTS if PERF_EVENTS
diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h
index c14b10821817..e3cb7c8c9461 100644
--- a/arch/mips/include/asm/kvm_host.h
+++ b/arch/mips/include/asm/kvm_host.h
@@ -26,6 +26,8 @@
#include <kvm/iodev.h>
+#define HAVE_KVM_MMIO
+
/* MIPS KVM register ids */
#define MIPS_CP0_32(_R, _S) \
(KVM_REG_MIPS_CP0 | KVM_REG_SIZE_U32 | (8 * (_R) + (_S)))
diff --git a/arch/mips/kvm/Kconfig b/arch/mips/kvm/Kconfig
index b1b9a1d67758..c65596fdf54f 100644
--- a/arch/mips/kvm/Kconfig
+++ b/arch/mips/kvm/Kconfig
@@ -22,7 +22,6 @@ config KVM
select EXPORT_UASM
select KVM_COMMON
select KVM_GENERIC_DIRTYLOG_READ_PROTECT
- select KVM_MMIO
select KVM_GENERIC_HARDWARE_ENABLING
select HAVE_KVM_READONLY_MEM
help
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index 2d139c807577..92d14438e31b 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -29,6 +29,13 @@
#define __KVM_HAVE_ARCH_VCPU_DEBUGFS
+#if defined(CONFIG_KVM_BOOK3S_32_HANDLER) || \
+ defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE) || \
+ defined(CONFIG_KVM_E500V2) || \
+ defined(CONFIG_KVM_E500MC)
+#define HAVE_KVM_MMIO
+#endif
+
#define KVM_MAX_VCPUS NR_CPUS
#define KVM_MAX_VCORES NR_CPUS
diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
index 9a0d1c1aca6c..d97a4a51ec55 100644
--- a/arch/powerpc/kvm/Kconfig
+++ b/arch/powerpc/kvm/Kconfig
@@ -29,7 +29,6 @@ config KVM_BOOK3S_HANDLER
config KVM_BOOK3S_32_HANDLER
bool
select KVM_BOOK3S_HANDLER
- select KVM_MMIO
config KVM_BOOK3S_64_HANDLER
bool
@@ -37,7 +36,6 @@ config KVM_BOOK3S_64_HANDLER
config KVM_BOOK3S_PR_POSSIBLE
bool
- select KVM_MMIO
config KVM_BOOK3S_HV_POSSIBLE
bool
@@ -200,7 +198,6 @@ config KVM_E500V2
depends on PPC_E500 && !PPC_E500MC
depends on !CONTEXT_TRACKING_USER
select KVM
- select KVM_MMIO
help
Support running unmodified E500 guest kernels in virtual machines on
E500v2 host processors.
@@ -215,7 +212,6 @@ config KVM_E500MC
depends on PPC_E500MC
depends on !CONTEXT_TRACKING_USER
select KVM
- select KVM_MMIO
select KVM_BOOKE_HV
help
Support running unmodified E500MC/E5500/E6500 guest kernels in
diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h
index 60017ceec9d2..38333a01e5bb 100644
--- a/arch/riscv/include/asm/kvm_host.h
+++ b/arch/riscv/include/asm/kvm_host.h
@@ -26,6 +26,8 @@
#include <asm/kvm_vcpu_timer.h>
#include <asm/kvm_vcpu_pmu.h>
+#define HAVE_KVM_MMIO
+
#define KVM_MAX_VCPUS 1024
#define KVM_HALT_POLL_NS_DEFAULT 500000
diff --git a/arch/riscv/kvm/Kconfig b/arch/riscv/kvm/Kconfig
index ec2cee0a39e0..3aea8d4939d2 100644
--- a/arch/riscv/kvm/Kconfig
+++ b/arch/riscv/kvm/Kconfig
@@ -28,7 +28,6 @@ config KVM
select KVM_COMMON
select KVM_GENERIC_DIRTYLOG_READ_PROTECT
select KVM_GENERIC_HARDWARE_ENABLING
- select KVM_MMIO
select VIRT_XFER_TO_GUEST_WORK
select SCHED_INFO
select GUEST_PERF_EVENTS if PERF_EVENTS
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 5f6c1ce9673b..69a374e48fe7 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -46,6 +46,8 @@
#define __KVM_HAVE_ARCH_VCPU_DEBUGFS
+#define HAVE_KVM_MMIO
+
/*
* CONFIG_KVM_MAX_NR_VCPUS is defined iff CONFIG_KVM!=n, provide a dummy max if
* KVM is disabled (arbitrarily use the default from CONFIG_KVM_MAX_NR_VCPUS).
diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig
index 801bf9e520db..da5d9fa8a11c 100644
--- a/arch/x86/kvm/Kconfig
+++ b/arch/x86/kvm/Kconfig
@@ -32,7 +32,6 @@ config KVM_X86
select VHOST_TASK
select KVM_ASYNC_PF
select USER_RETURN_NOTIFIER
- select KVM_MMIO
select SCHED_INFO
select PERF_EVENTS
select GUEST_PERF_EVENTS
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index aa573e2530f7..f179a9230e30 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -834,7 +834,7 @@ struct kvm {
struct list_head ioeventfds;
struct kvm_vm_stat stat;
struct kvm_arch arch;
-#ifdef CONFIG_KVM_MMIO
+#ifdef HAVE_KVM_MMIO
struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
spinlock_t ring_lock;
struct list_head coalesced_zones;
diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig
index 794976b88c6f..c4a983e41765 100644
--- a/virt/kvm/Kconfig
+++ b/virt/kvm/Kconfig
@@ -40,9 +40,6 @@ config NEED_KVM_DIRTY_RING_WITH_BITMAP
bool
depends on HAVE_KVM_DIRTY_RING
-config KVM_MMIO
- bool
-
config KVM_ASYNC_PF
bool
diff --git a/virt/kvm/Makefile.kvm b/virt/kvm/Makefile.kvm
index d047d4cf58c9..3c27c18b49a0 100644
--- a/virt/kvm/Makefile.kvm
+++ b/virt/kvm/Makefile.kvm
@@ -5,9 +5,8 @@
KVM ?= ../../../virt/kvm
-kvm-y := $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/binary_stats.o
+kvm-y := $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/binary_stats.o $(KVM)/coalesced_mmio.o
kvm-$(CONFIG_KVM_VFIO) += $(KVM)/vfio.o
-kvm-$(CONFIG_KVM_MMIO) += $(KVM)/coalesced_mmio.o
kvm-$(CONFIG_KVM_ASYNC_PF) += $(KVM)/async_pf.o
kvm-$(CONFIG_HAVE_KVM_IRQ_ROUTING) += $(KVM)/irqchip.o
kvm-$(CONFIG_HAVE_KVM_DIRTY_RING) += $(KVM)/dirty_ring.o
diff --git a/virt/kvm/coalesced_mmio.c b/virt/kvm/coalesced_mmio.c
index 6b1d90161099..070eba3c6534 100644
--- a/virt/kvm/coalesced_mmio.c
+++ b/virt/kvm/coalesced_mmio.c
@@ -12,6 +12,8 @@
#include <kvm/iodev.h>
#include <linux/kvm_host.h>
+
+#ifdef HAVE_KVM_MMIO
#include <linux/slab.h>
#include <linux/kvm.h>
@@ -188,3 +190,4 @@ int kvm_vm_ioctl_unregister_coalesced_mmio(struct kvm *kvm,
*/
return 0;
}
+#endif /* ifdef HAVE_KVM_MMIO */
diff --git a/virt/kvm/coalesced_mmio.h b/virt/kvm/coalesced_mmio.h
index 36f84264ed25..a8430d41945b 100644
--- a/virt/kvm/coalesced_mmio.h
+++ b/virt/kvm/coalesced_mmio.h
@@ -11,7 +11,7 @@
*
*/
-#ifdef CONFIG_KVM_MMIO
+#ifdef HAVE_KVM_MMIO
#include <linux/list.h>
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index dcad33cc2f25..6ac79d80e7ec 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -4035,7 +4035,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
+#ifdef HAVE_KVM_MMIO
else if (vmf->pgoff == KVM_COALESCED_MMIO_PAGE_OFFSET)
page = virt_to_page(vcpu->kvm->coalesced_mmio_ring);
#endif
@@ -4861,7 +4861,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
+#ifdef HAVE_KVM_MMIO
case KVM_CAP_COALESCED_MMIO:
return KVM_COALESCED_MMIO_PAGE_OFFSET;
case KVM_CAP_COALESCED_PIO:
@@ -5202,7 +5202,7 @@ static long kvm_vm_ioctl(struct file *filp,
break;
}
#endif
-#ifdef CONFIG_KVM_MMIO
+#ifdef HAVE_KVM_MMIO
case KVM_REGISTER_COALESCED_MMIO: {
struct kvm_coalesced_mmio_zone zone;
@@ -5524,7 +5524,7 @@ static long kvm_dev_ioctl(struct file *filp,
#ifdef CONFIG_X86
r += PAGE_SIZE; /* pio data page */
#endif
-#ifdef CONFIG_KVM_MMIO
+#ifdef HAVE_KVM_MMIO
r += PAGE_SIZE; /* coalesced mmio ring page */
#endif
break;
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 06/27] arm64: Use proper include variant
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (4 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 05/27] KVM: Remove KVM_MMIO as config option Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 07/27] arm64: Prepare sharing arm64 headers with s390 Steffen Eiden
` (20 subsequent siblings)
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
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")
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/arm64/include/asm/sysreg.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index 7aa08d59d494..4bfdac9401bd 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -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
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 07/27] arm64: Prepare sharing arm64 headers with s390
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (5 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 06/27] arm64: Use proper include variant Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 21:22 ` Marc Zyngier
2026-07-06 8:52 ` [PATCH v4 08/27] KVM: arm64: Prepare sharing arm64 code " Steffen Eiden
` (19 subsequent siblings)
26 siblings, 1 reply; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
Prepare the sharing of arm64 headers with s390 by marking the shared
regions or add a comment that the whole file is shared.
The regions are marked with:
#define ARM64_S390_COMMON
/* insert shared definitions here */
#endif /* ARM64_S390_COMMON */
The preprocessor symbol ARM64_S390_COMMON is always defined for arm64.
Reduce the include scope where possible and beneficial for s390.
No functional change.
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
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 | 19 ++++++++++++++++++
arch/arm64/include/asm/kvm_host.h | 28 +++++++++++++++++++++++++++
arch/arm64/include/asm/kvm_mmu.h | 6 ++++++
arch/arm64/include/asm/ptrace.h | 9 +++++++++
arch/arm64/include/asm/sysreg.h | 29 +++++++++++++++++++++++++---
9 files changed, 98 insertions(+), 7 deletions(-)
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 6b005c8fef70..1cd7cd94a855 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -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
diff --git a/arch/arm64/include/asm/brk-imm.h b/arch/arm64/include/asm/brk-imm.h
index beb42c62b6ac..dd2d153dc0d8 100644
--- a/arch/arm64/include/asm/brk-imm.h
+++ b/arch/arm64/include/asm/brk-imm.h
@@ -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
diff --git a/arch/arm64/include/asm/esr.h b/arch/arm64/include/asm/esr.h
index 81c17320a588..e25b742b09ac 100644
--- a/arch/arm64/include/asm/esr.h
+++ b/arch/arm64/include/asm/esr.h
@@ -3,11 +3,12 @@
* Copyright (C) 2013 - ARM Ltd
* Author: Marc Zyngier <marc.zyngier@arm.com>
*/
+/* Whole file is shared with s390 */
#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 +436,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)
{
diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h
index 3f9233b5a130..cc4175176f94 100644
--- a/arch/arm64/include/asm/kvm_arm.h
+++ b/arch/arm64/include/asm/kvm_arm.h
@@ -3,14 +3,16 @@
* Copyright (C) 2012,2013 - ARM Ltd
* Author: Marc Zyngier <marc.zyngier@arm.com>
*/
+/* Whole file is shared with s390 */
#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
diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
index 5bf3d7e1d92c..a1c92d2436ae 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -44,13 +44,18 @@ enum exception_type {
bool kvm_condition_valid32(const struct kvm_vcpu *vcpu);
void kvm_skip_instr32(struct kvm_vcpu *vcpu);
+#ifdef ARM64_S390_COMMON
void kvm_inject_undefined(struct kvm_vcpu *vcpu);
+#endif /* ARM64_S390_COMMON */
void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr);
int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr);
+#ifdef ARM64_S390_COMMON
int kvm_inject_sea(struct kvm_vcpu *vcpu, bool iabt, u64 addr);
+#endif /* ARM64_S390_COMMON */
int kvm_inject_dabt_excl_atomic(struct kvm_vcpu *vcpu, u64 addr);
void kvm_inject_size_fault(struct kvm_vcpu *vcpu);
+#ifdef ARM64_S390_COMMON
static inline int kvm_inject_sea_dabt(struct kvm_vcpu *vcpu, u64 addr)
{
return kvm_inject_sea(vcpu, false, addr);
@@ -61,6 +66,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)
{
/*
@@ -159,6 +166,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
@@ -177,6 +185,8 @@ static __always_inline void vcpu_set_reg(struct kvm_vcpu *vcpu, u8 reg_num,
vcpu_gp_regs(vcpu)->regs[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)) {
@@ -360,6 +370,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;
@@ -437,6 +448,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)
{
@@ -477,6 +490,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)) {
@@ -501,6 +515,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;
@@ -536,6 +552,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)
@@ -611,6 +628,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.
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 245bda0fb571..ae9f76378218 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -41,6 +41,7 @@
#define KVM_MAX_VCPUS VGIC_V3_MAX_CPUS
+#ifdef ARM64_S390_COMMON
#define KVM_VCPU_MAX_FEATURES 9
#define KVM_VCPU_VALID_FEATURES (BIT(KVM_VCPU_MAX_FEATURES) - 1)
@@ -58,6 +59,8 @@
#define KVM_REQ_MAP_L1_VNCR_EL2 KVM_ARCH_REQ(10)
#define KVM_REQ_VGIC_PROCESS_UPDATE KVM_ARCH_REQ(11)
+#endif /* ARM64_S390_COMMON */
+
#define KVM_DIRTY_LOG_MANUAL_CAPS (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \
KVM_DIRTY_LOG_INITIALLY_SET)
@@ -340,6 +343,7 @@ struct kvm_arch {
/* Protects VM-scoped configuration data */
struct mutex config_lock;
+#ifdef ARM64_S390_COMMON
/*
* If we encounter a data abort without valid instruction syndrome
* information, report this to user space. User space can (and
@@ -369,6 +373,8 @@ struct kvm_arch {
#define KVM_ARCH_FLAG_WRITABLE_IMP_ID_REGS 10
/* Unhandled SEAs are taken to userspace */
#define KVM_ARCH_FLAG_EXIT_SEA 11
+
+#endif /* ARM64_S390_COMMON */
unsigned long flags;
/* VM-wide vCPU feature set */
@@ -833,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;
@@ -840,6 +848,8 @@ struct vcpu_reset_state {
bool reset;
};
+#endif /* ARM64_S390_COMMON */
+
struct vncr_tlb;
struct kvm_vcpu_arch {
@@ -949,6 +959,7 @@ struct kvm_vcpu_arch {
pid_t pid;
};
+#ifdef ARM64_S390_COMMON
/*
* Each 'flag' is composed of a comma-separated triplet:
*
@@ -982,6 +993,8 @@ struct kvm_vcpu_arch {
READ_ONCE(v->arch.flagset) & (m); \
})
+#endif /* ARM64_S390_COMMON */
+
/*
* Note that the set/clear accessors must be preempt-safe in order to
* avoid nesting them with load/put which also manipulate flags...
@@ -995,6 +1008,7 @@ struct kvm_vcpu_arch {
#define __vcpu_flags_preempt_enable() preempt_enable()
#endif
+#ifdef ARM64_S390_COMMON
#define __vcpu_set_flag(v, flagset, f, m) \
do { \
typeof(v->arch.flagset) *fset; \
@@ -1079,6 +1093,8 @@ struct kvm_vcpu_arch {
#define EXCEPT_AA64_EL2_FIQ __vcpu_except_flags(6)
#define EXCEPT_AA64_EL2_SERR __vcpu_except_flags(7)
+#endif /* ARM64_S390_COMMON */
+
/* Physical CPU not in supported_cpus */
#define ON_UNSUPPORTED_CPU __vcpu_single_flag(sflags, BIT(0))
/* WFIT instruction trapped */
@@ -1236,7 +1252,10 @@ struct kvm_vcpu_stat {
};
unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
+#ifdef ARM64_S390_COMMON
int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices);
+
+#endif /* ARM64_S390_COMMON */
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);
@@ -1321,6 +1340,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);
@@ -1328,6 +1348,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
@@ -1502,8 +1524,11 @@ struct kvm *kvm_arch_alloc_vm(void);
#define kvm_vm_is_protected(kvm) (is_protected_kvm_enabled() && (kvm)->arch.pkvm.is_protected)
+#ifdef ARM64_S390_COMMON
#define vcpu_is_protected(vcpu) kvm_vm_is_protected((vcpu)->kvm)
+#endif /* ARM64_S390_COMMON */
+
int kvm_arm_vcpu_finalize(struct kvm_vcpu *vcpu, int feature);
bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu);
@@ -1528,8 +1553,11 @@ static inline bool __vcpu_has_feature(const struct kvm_arch *ka, int feature)
#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))
+#ifdef ARM64_S390_COMMON
#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;
diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h
index 6eae7e7e2a68..b782cae771fe 100644
--- a/arch/arm64/include/asm/kvm_mmu.h
+++ b/arch/arm64/include/asm/kvm_mmu.h
@@ -142,12 +142,15 @@ static __always_inline unsigned long __kern_hyp_va(unsigned long v)
extern u32 __hyp_va_bits;
+#ifdef ARM64_S390_COMMON
/*
* We currently support using a VM-specified IPA size. For backward
* compatibility, the default IPA size is fixed to 40bits.
*/
#define KVM_PHYS_SHIFT (40)
+#endif /* ARM64_S390_COMMON */
+
#define kvm_phys_shift(mmu) VTCR_EL2_IPA((mmu)->vtcr)
#define kvm_phys_size(mmu) (_AC(1, ULL) << kvm_phys_shift(mmu))
#define kvm_phys_mask(mmu) (kvm_phys_size(mmu) - _AC(1, ULL))
@@ -178,9 +181,12 @@ void stage2_unmap_vm(struct kvm *kvm);
int kvm_init_stage2_mmu(struct kvm *kvm, struct kvm_s2_mmu *mmu, unsigned long type);
void kvm_uninit_stage2_mmu(struct kvm *kvm);
void kvm_free_stage2_pgd(struct kvm_s2_mmu *mmu);
+#ifdef ARM64_S390_COMMON
int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa,
phys_addr_t pa, unsigned long size, bool writable);
+#endif /* ARM64_S390_COMMON */
+
int kvm_handle_guest_sea(struct kvm_vcpu *vcpu);
int kvm_handle_guest_abort(struct kvm_vcpu *vcpu);
diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h
index 39582511ad72..6eb122eb5fa6 100644
--- a/arch/arm64/include/asm/ptrace.h
+++ b/arch/arm64/include/asm/ptrace.h
@@ -10,8 +10,13 @@
#include <asm/cpufeature.h>
+#ifdef ARM64_S390_COMMON
+#include <asm/sysreg.h>
+
#include <uapi/asm/ptrace.h>
+#endif /* ARM64_S390_COMMON */
+
/* Current Exception Level values, as contained in CurrentEL */
#define CurrentEL_EL1 (1 << 2)
#define CurrentEL_EL2 (2 << 2)
@@ -28,6 +33,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)
@@ -68,6 +75,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
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index 4bfdac9401bd..58912a6b6fcd 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -9,13 +9,17 @@
#ifndef __ASM_SYSREG_H
#define __ASM_SYSREG_H
+#ifdef ARM64_S390_COMMON
#include <linux/bits.h>
+#endif /* ARM64_S390_COMMON */
#include <linux/stringify.h>
#include <linux/kasan-tags.h>
#include <linux/kconfig.h>
#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 +54,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__
@@ -79,6 +85,8 @@
#endif /* CONFIG_BROKEN_GAS_INST */
+#ifdef ARM64_S390_COMMON
+
/*
* Instructions for modifying PSTATE fields.
* As per Arm ARM for v8-A, Section "C.5.1.3 op0 == 0b00, architectural hints,
@@ -91,8 +99,6 @@
*/
#define pstate_field(op1, op2) ((op1) << Op1_shift | (op2) << Op2_shift)
#define PSTATE_Imm_shift CRm_shift
-#define ENCODE_PSTATE(x, r) (0xd500401f | PSTATE_ ## r | ((!!x) << PSTATE_Imm_shift))
-#define SET_PSTATE(x, r) __emit_inst(ENCODE_PSTATE(x, r))
#define PSTATE_PAN pstate_field(0, 4)
#define PSTATE_UAO pstate_field(0, 3)
@@ -100,6 +106,11 @@
#define PSTATE_DIT pstate_field(3, 2)
#define PSTATE_TCO pstate_field(3, 4)
+#endif /* ARM64_S390_COMMON */
+
+#define ENCODE_PSTATE(x, r) (0xd500401f | PSTATE_ ## r | ((!!x) << PSTATE_Imm_shift))
+#define SET_PSTATE(x, r) __emit_inst(ENCODE_PSTATE(x, r))
+
#define SET_PSTATE_PAN(x) SET_PSTATE((x), PAN)
#define SET_PSTATE_UAO(x) SET_PSTATE((x), UAO)
#define SET_PSTATE_SSBS(x) SET_PSTATE((x), SSBS)
@@ -123,6 +134,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)
@@ -835,6 +848,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
@@ -869,6 +884,8 @@
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)
@@ -1105,6 +1122,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)
@@ -1254,6 +1273,8 @@
par; \
})
+#ifdef ARM64_S390_COMMON
+
#define SYS_FIELD_VALUE(reg, field, val) reg##_##field##_##val
#define SYS_FIELD_GET(reg, field, val) \
@@ -1266,6 +1287,8 @@
FIELD_PREP(reg##_##field##_MASK, \
SYS_FIELD_VALUE(reg, field, val))
-#endif
+#endif /* ARM64_S390_COMMON */
+
+#endif /* __ASSEMBLER__ */
#endif /* __ASM_SYSREG_H */
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 08/27] KVM: arm64: Prepare sharing arm64 code with s390
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (6 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 07/27] arm64: Prepare sharing arm64 headers with s390 Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 21:28 ` Marc Zyngier
2026-07-06 8:52 ` [PATCH v4 09/27] KVM: arm64: Access elements of vcpu_gp_regs individually Steffen Eiden
` (18 subsequent siblings)
26 siblings, 1 reply; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
Mark functions that s390 can use to implement arm on s390 as shared
functions.
No functional change.
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/arm64/kvm/arm.c | 3 +++
arch/arm64/kvm/guest.c | 3 +++
arch/arm64/kvm/handle_exit.c | 6 ++++++
arch/arm64/kvm/mmio.c | 14 ++++++++++++++
arch/arm64/kvm/reset.c | 3 +++
5 files changed, 29 insertions(+)
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 50adfff75be8..c992308b2dce 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -1580,6 +1580,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)
{
@@ -1628,6 +1629,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;
diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c
index b01d6622b872..5a202cfd27bc 100644
--- a/arch/arm64/kvm/guest.c
+++ b/arch/arm64/kvm/guest.c
@@ -543,6 +543,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 +592,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);
diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
index 54aedf93c78b..d511af145ee6 100644
--- a/arch/arm64/kvm/handle_exit.c
+++ b/arch/arm64/kvm/handle_exit.c
@@ -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.
diff --git a/arch/arm64/kvm/mmio.c b/arch/arm64/kvm/mmio.c
index e2285ed8c91d..876d56dd5b64 100644
--- a/arch/arm64/kvm/mmio.c
+++ b/arch/arm64/kvm/mmio.c
@@ -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;
@@ -135,8 +136,11 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu)
if (!kvm_vcpu_dabt_issf(vcpu))
data = data & 0xffffffff;
+#endif /* ARM64_S390_COMMON */
trace_kvm_mmio(KVM_TRACE_MMIO_READ, len, run->mmio.phys_addr,
&data);
+ //TODO tracing
+#ifdef ARM64_S390_COMMON
data = vcpu_data_host_to_guest(vcpu, data, len);
vcpu_set_reg(vcpu, kvm_vcpu_dabt_get_rd(vcpu), data);
}
@@ -171,8 +175,11 @@ int io_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa)
* though, so directly deliver an exception to the guest.
*/
if (!kvm_vcpu_dabt_isvalid(vcpu)) {
+#endif /* ARM64_S390_COMMON */
trace_kvm_mmio_nisv(*vcpu_pc(vcpu), esr,
kvm_vcpu_get_hfar(vcpu), fault_ipa);
+ //TODO tracing
+#ifdef ARM64_S390_COMMON
if (vcpu_is_protected(vcpu))
return kvm_inject_sea_dabt(vcpu, kvm_vcpu_get_hfar(vcpu));
@@ -223,14 +230,20 @@ int io_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa)
data = vcpu_data_guest_to_host(vcpu, vcpu_get_reg(vcpu, rt),
len);
+#endif /* ARM64_S390_COMMON */
trace_kvm_mmio(KVM_TRACE_MMIO_WRITE, len, fault_ipa, &data);
+ //TODO tracing
+#ifdef ARM64_S390_COMMON
kvm_mmio_write_buf(data_buf, len, data);
ret = kvm_io_bus_write(vcpu, KVM_MMIO_BUS, fault_ipa, len,
data_buf);
} else {
+#endif /* ARM64_S390_COMMON */
trace_kvm_mmio(KVM_TRACE_MMIO_READ_UNSATISFIED, len,
fault_ipa, NULL);
+ //TODO tracing
+#ifdef ARM64_S390_COMMON
ret = kvm_io_bus_read(vcpu, KVM_MMIO_BUS, fault_ipa, len,
data_buf);
@@ -257,3 +270,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 */
diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c
index b963fd975aac..faab6f03f365 100644
--- a/arch/arm64/kvm/reset.c
+++ b/arch/arm64/kvm/reset.c
@@ -34,6 +34,7 @@
static u32 __ro_after_init kvm_ipa_limit;
unsigned int __ro_after_init kvm_host_sve_max_vl;
+#ifdef ARM64_S390_COMMON
/*
* ARMv8 Reset Values
*/
@@ -46,6 +47,8 @@ unsigned int __ro_after_init kvm_host_sve_max_vl;
#define VCPU_RESET_PSTATE_SVC (PSR_AA32_MODE_SVC | PSR_AA32_A_BIT | \
PSR_AA32_I_BIT | PSR_AA32_F_BIT)
+#endif /* ARM64_S390_COMMON */
+
unsigned int __ro_after_init kvm_sve_max_vl;
int __init kvm_arm_init_sve(void)
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 09/27] KVM: arm64: Access elements of vcpu_gp_regs individually
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (7 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 08/27] KVM: arm64: Prepare sharing arm64 code " Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 17:44 ` Marc Zyngier
2026-07-06 8:52 ` [PATCH v4 10/27] KVM: arm64: Refactor core-reset into a separate function Steffen Eiden
` (17 subsequent siblings)
26 siblings, 1 reply; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
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.
Share the gp register functions with s390.
No functional change.
Co-developed-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/arm64/include/asm/kvm_emulate.h | 13 +++++++++----
arch/arm64/include/asm/kvm_host.h | 8 +++++++-
arch/arm64/kvm/guest.c | 19 +++++++++++--------
arch/arm64/kvm/hyp/exception.c | 7 +++++--
arch/arm64/kvm/hyp/include/hyp/adjust_pc.h | 4 ++--
arch/arm64/kvm/hyp/include/hyp/switch.h | 6 +++---
arch/arm64/kvm/reset.c | 6 ++++--
7 files changed, 41 insertions(+), 22 deletions(-)
diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
index a1c92d2436ae..15d6d6a08d37 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -140,12 +140,17 @@ 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 unsigned long *vcpu_sp_el0(const struct kvm_vcpu *vcpu)
+{
+ return (unsigned long *)&vcpu->arch.ctxt.regs.sp;
}
static __always_inline bool vcpu_mode_is_32bit(const struct kvm_vcpu *vcpu)
@@ -175,14 +180,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;
}
#endif /* ARM64_S390_COMMON */
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index ae9f76378218..2fce38fd9152 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -1170,7 +1170,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
@@ -1201,6 +1201,12 @@ static inline u64 *___ctxt_sys_reg(const struct kvm_cpu_context *ctxt, int r)
#define ctxt_sys_reg(c,r) (*__ctxt_sys_reg(c,r))
+#define kvm_vcpu_get_sp_el1(__vcpu) (__ctxt_sys_reg(&(__vcpu)->arch.ctxt, SP_EL1))
+#define kvm_vcpu_get_vreg(__vcpu, _n) (&(__vcpu)->arch.ctxt.fp_regs.vregs[_n])
+#define kvm_vcpu_get_vregs(__vcpu) (&(__vcpu)->arch.ctxt.fp_regs.vregs)
+#define kvm_vcpu_get_fpsr(__vcpu) (&(__vcpu)->arch.ctxt.fp_regs.fpsr)
+#define kvm_vcpu_get_fpcr(__vcpu) (&(__vcpu)->arch.ctxt.fp_regs.fpcr)
+
u64 kvm_vcpu_apply_reg_masks(const struct kvm_vcpu *, enum vcpu_sysreg, u64);
#define __vcpu_assign_sys_reg(v, r, val) \
diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c
index 5a202cfd27bc..5e1e1faa98c2 100644
--- a/arch/arm64/kvm/guest.c
+++ b/arch/arm64/kvm/guest.c
@@ -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) &&
@@ -134,19 +135,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 kvm_vcpu_get_sp_el1(vcpu);
case KVM_REG_ARM_CORE_REG(elr_el1):
return __ctxt_sys_reg(&vcpu->arch.ctxt, ELR_EL1);
@@ -170,13 +171,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 kvm_vcpu_get_vreg(vcpu, off);
case KVM_REG_ARM_CORE_REG(fp_regs.fpsr):
- return &vcpu->arch.ctxt.fp_regs.fpsr;
+ return kvm_vcpu_get_fpsr(vcpu);
case KVM_REG_ARM_CORE_REG(fp_regs.fpcr):
- return &vcpu->arch.ctxt.fp_regs.fpcr;
+ return kvm_vcpu_get_fpcr(vcpu);
default:
return NULL;
@@ -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)))
diff --git a/arch/arm64/kvm/hyp/exception.c b/arch/arm64/kvm/hyp/exception.c
index bef40ddb16db..82611442a2d1 100644
--- a/arch/arm64/kvm/hyp/exception.c
+++ b/arch/arm64/kvm/hyp/exception.c
@@ -277,6 +277,9 @@ static const u8 return_offsets[8][2] = {
[7] = { 4, 4 }, /* FIQ, unused */
};
+#define OFFSETOF_PT_REG(__r) offsetof(struct user_pt_regs, __r)
+#define COMPAT_IDX(__c) ((OFFSETOF_PT_REG(__c) - OFFSETOF_PT_REG(regs[0])) / sizeof(u64))
+
static void enter_exception32(struct kvm_vcpu *vcpu, u32 mode, u32 vect_offset)
{
unsigned long spsr = *vcpu_cpsr(vcpu);
@@ -292,12 +295,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_IDX(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_IDX(compat_lr_und)] = return_address;
break;
}
diff --git a/arch/arm64/kvm/hyp/include/hyp/adjust_pc.h b/arch/arm64/kvm/hyp/include/hyp/adjust_pc.h
index 4fdfeabefeb4..a049983bd5c3 100644
--- a/arch/arm64/kvm/hyp/include/hyp/adjust_pc.h
+++ b/arch/arm64/kvm/hyp/include/hyp/adjust_pc.h
@@ -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);
}
diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h
index 18131e395e24..a57aec6dd854 100644
--- a/arch/arm64/kvm/hyp/include/hyp/switch.h
+++ b/arch/arm64/kvm/hyp/include/hyp/switch.h
@@ -449,7 +449,7 @@ static inline bool __populate_fault_info(struct kvm_vcpu *vcpu)
static inline bool kvm_hyp_handle_mops(struct kvm_vcpu *vcpu, u64 *exit_code)
{
*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);
/*
@@ -895,7 +895,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?
*/
@@ -905,7 +905,7 @@ static inline void synchronize_vcpu_pstate(struct kvm_vcpu *vcpu)
ESR_ELx_EC(read_sysreg_el2(SYS_ESR)) == ESR_ELx_EC_PAC)
write_sysreg_el2(*vcpu_cpsr(vcpu), SYS_SPSR);
- vcpu->arch.ctxt.regs.pstate = read_sysreg_el2(SYS_SPSR);
+ *vcpu_cpsr(vcpu) = read_sysreg_el2(SYS_SPSR);
}
/*
diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c
index faab6f03f365..1ce3b26cc1ae 100644
--- a/arch/arm64/kvm/reset.c
+++ b/arch/arm64/kvm/reset.c
@@ -221,13 +221,15 @@ void kvm_reset_vcpu(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_sp_el0(vcpu) = 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;
/* Reset system registers */
kvm_reset_sys_regs(vcpu);
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 10/27] KVM: arm64: Refactor core-reset into a separate function
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (8 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 09/27] KVM: arm64: Access elements of vcpu_gp_regs individually Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 11/27] s390: Use arm64 headers Steffen Eiden
` (16 subsequent siblings)
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
Move the reset of the arm core register into a separate function and
share it with s390.
No functional change.
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/arm64/kvm/reset.c | 45 ++++++++++++++++++++++++++----------------
1 file changed, 28 insertions(+), 17 deletions(-)
diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c
index 1ce3b26cc1ae..81d9f0faede2 100644
--- a/arch/arm64/kvm/reset.c
+++ b/arch/arm64/kvm/reset.c
@@ -172,6 +172,33 @@ static void kvm_vcpu_reset_sve(struct kvm_vcpu *vcpu)
memset(vcpu->arch.sve_state, 0, vcpu_sve_state_size(vcpu));
}
+#ifdef ARM64_S390_COMMON
+static void kvm_reset_vcpu_core_regs(struct kvm_vcpu *vcpu)
+{
+ u32 pstate;
+
+ if (vcpu_el1_is_32bit(vcpu))
+ pstate = VCPU_RESET_PSTATE_SVC;
+ else if (vcpu_has_nv(vcpu))
+ pstate = VCPU_RESET_PSTATE_EL2;
+ else
+ pstate = VCPU_RESET_PSTATE_EL1;
+
+ memset(vcpu_gp_regs(vcpu), 0, sizeof(vcpu_gp_regs(vcpu)));
+ *vcpu_pc(vcpu) = 0;
+ *vcpu_sp_el0(vcpu) = 0;
+ memset(kvm_vcpu_get_vregs(vcpu), 0, sizeof(*kvm_vcpu_get_vregs(vcpu)));
+ memset(kvm_vcpu_get_fpsr(vcpu), 0, sizeof(*kvm_vcpu_get_fpsr(vcpu)));
+ memset(kvm_vcpu_get_fpcr(vcpu), 0, sizeof(*kvm_vcpu_get_fpcr(vcpu)));
+ 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_cpsr(vcpu) = pstate;
+}
+
+#endif /* ARM64_S390_COMMON */
+
/**
* kvm_reset_vcpu - sets core registers and sys_regs to reset value
* @vcpu: The VCPU pointer
@@ -194,7 +221,6 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
{
struct vcpu_reset_state reset_state;
bool loaded;
- u32 pstate;
spin_lock(&vcpu->arch.mp_state_lock);
reset_state = vcpu->arch.reset_state;
@@ -213,23 +239,8 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
kvm_vcpu_reset_sve(vcpu);
}
- if (vcpu_el1_is_32bit(vcpu))
- pstate = VCPU_RESET_PSTATE_SVC;
- else if (vcpu_has_nv(vcpu))
- pstate = VCPU_RESET_PSTATE_EL2;
- else
- pstate = VCPU_RESET_PSTATE_EL1;
-
/* Reset core registers */
- memset(vcpu_gp_regs(vcpu), 0, sizeof(vcpu_gp_regs(vcpu)));
- *vcpu_pc(vcpu) = 0;
- *vcpu_sp_el0(vcpu) = 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_cpsr(vcpu) = pstate;
+ kvm_reset_vcpu_core_regs(vcpu);
/* Reset system registers */
kvm_reset_sys_regs(vcpu);
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 11/27] s390: Use arm64 headers
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (9 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 10/27] KVM: arm64: Refactor core-reset into a separate function Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 12/27] KVM: s390: Use arm64 code Steffen Eiden
` (15 subsequent siblings)
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
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/asm/...>' 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_S390_ARM64.
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/s390/tools/Makefile | 5 ++
arch/s390/tools/Makefile.arm64h | 58 +++++++++++++++++++++++
arch/s390/tools/copy-arm64h-full.awk | 43 +++++++++++++++++
arch/s390/tools/copy-arm64h.awk | 71 ++++++++++++++++++++++++++++
4 files changed, 177 insertions(+)
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
diff --git a/arch/s390/tools/Makefile b/arch/s390/tools/Makefile
index f2862364fb42..bd2a00d5ce2c 100644
--- a/arch/s390/tools/Makefile
+++ b/arch/s390/tools/Makefile
@@ -3,8 +3,13 @@
# 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
+kapi-hdrs-$(CONFIG_KVM_ARM64) += $(ARM64_TARGETS)
+
+targets += $(addprefix ../../../,$(kapi-hdrs-y))
PHONY += kapi
diff --git a/arch/s390/tools/Makefile.arm64h b/arch/s390/tools/Makefile.arm64h
new file mode 100644
index 000000000000..0b32c124707d
--- /dev/null
+++ b/arch/s390/tools/Makefile.arm64h
@@ -0,0 +1,58 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Share ARM64 headers with s390 KVM
+#
+
+arm64api := $(objtree)/arch/$(ARCH)/include/generated/arm64
+arm64uapi := $(objtree)/arch/$(ARCH)/include/generated/uapi/arm64
+
+# List of ARM64 headers to share with s390 KVM
+# Format: [uapi:]header.h or [uapi:]header-part.h
+#
+# * header.h - from arch/arm64/include/asm/ to arm64/
+# * uapi:header.h - from arch/arm64/include/uapi/asm/ to uapi/arm64/
+# * header-part.h - generated as header-part.h from ARM64 header header.h
+# * uapi:header-part.h - generated as header-part.h from ARM64 UAPI header header.h
+# If a header contains partial markers (#ifdef ARM64_S390_COMMON) only this part will be copied.
+# If the file does not contain any markers the whole file will be copied.
+ARM64_SHARED_HEADERS := \
+ brk-imm.h \
+ esr.h \
+ kvm_arm.h \
+ kvm_emulate-part.h \
+ kvm_host.h \
+ kvm_mmu.h \
+ ptrace.h \
+ sysreg.h \
+ uapi:hwcap.h \
+ uapi:kvm.h \
+ uapi:ptrace.h \
+ uapi:sve_context.h \
+
+quiet_cmd_gen_arm_hdr = GEN $@
+ cmd_gen_arm_hdr = mkdir -p $(dir $@); \
+ $(AWK) -f $(src)/copy-arm64h.awk $< > $@ || \
+ $(AWK) -f $(src)/copy-arm64h-full.awk -v srcfile="$(subst $(srctree)/,,$(subst $(srctree)/../,,$<))" $< > $@
+
+arm64-type = $(firstword $(subst :, ,$(1)))
+arm64-base = $(or $(word 2,$(subst :, ,$(1))),$(1))
+arm64-src-base = $(patsubst %-part.h,%.h,$(call arm64-base,$(1)))
+
+arm64-src = $(srctree)/arch/arm64/include/$(if $(filter uapi,$(call arm64-type,$(1))),uapi/)asm/$(call arm64-src-base,$(1))
+arm64-dst = $(objtree)/$(if $(filter uapi,$(call arm64-type,$(1))),$(arm64uapi),$(arm64api))/$(call arm64-base,$(1))
+
+$(foreach hdr,$(ARM64_SHARED_HEADERS),\
+ $(eval $(call arm64-dst,$(hdr)): $(call arm64-src,$(hdr)) $(src)/copy-arm64h.awk $(src)/copy-arm64h-full.awk))
+
+ARM64_TARGETS := $(sort $(foreach hdr,$(ARM64_SHARED_HEADERS),$(call arm64-dst,$(hdr))))
+
+$(ARM64_TARGETS):
+ $(call cmd,gen_arm_hdr)
+
+quiet_cmd_gen_sysreg_arm64 = GEN $@
+ cmd_gen_sysreg_arm64 = mkdir -p $(dir $@); $(AWK) -f $(srctree)/arch/arm64/tools/gen-sysreg.awk $(srctree)/arch/arm64/tools/sysreg > $@
+
+$(arm64api)/sysreg-defs.h: $(srctree)/arch/arm64/tools/gen-sysreg.awk $(srctree)/arch/arm64/tools/sysreg FORCE
+ $(call if_changed,gen_sysreg_arm64)
+
+ARM64_TARGETS += $(arm64api)/sysreg-defs.h
diff --git a/arch/s390/tools/copy-arm64h-full.awk b/arch/s390/tools/copy-arm64h-full.awk
new file mode 100644
index 000000000000..a9b85b347f78
--- /dev/null
+++ b/arch/s390/tools/copy-arm64h-full.awk
@@ -0,0 +1,43 @@
+#!/usr/bin/awk -f
+# SPDX-License-Identifier: GPL-2.0
+#
+# Process entire ARM64 headers for sharing with s390 KVM
+#
+# Usage: copy-arm64h-full.awk -v srcfile=<source_path> <input_file>
+#
+# This processes the entire file (unlike copy-arm64h.awk which only extracts marked sections)
+
+BEGIN {
+ max_guard_line = 25
+ guard_found = 0
+ header_added = 0
+}
+
+# Find and process the include guard in the first few lines
+NR <= max_guard_line && !guard_found && /^#ifndef [A-Z_]+$/ {
+ guard_name = $2
+ guard_found = 1
+ print "/* This header was copied from " srcfile " */"
+ print ""
+ print
+ header_added = 1
+ next
+}
+
+# Transform include directives
+/^#include <uapi\/asm\// {
+ sub(/<uapi\/asm\//, "<uapi/arm64/")
+ print
+ next
+}
+
+/^#include <asm\// {
+ sub(/<asm\//, "<arm64/")
+ print
+ next
+}
+
+# Pass through all other lines
+{
+ print
+}
diff --git a/arch/s390/tools/copy-arm64h.awk b/arch/s390/tools/copy-arm64h.awk
new file mode 100644
index 000000000000..33ceddd4116b
--- /dev/null
+++ b/arch/s390/tools/copy-arm64h.awk
@@ -0,0 +1,71 @@
+#!/usr/bin/awk -f
+# SPDX-License-Identifier: GPL-2.0
+#
+# Extract marked sections from ARM64 headers for sharing with s390 KVM
+#
+# Usage: share-arm64-header.awk <input_file>
+#
+# Extracts all sections between start/end markers. If no markers found, signals for fallback.
+#TODO verification script or c file for arm to verify the ifdef things keep working
+BEGIN {
+ # Constants
+ start_pattern = "^#ifdef ARM64_S390_COMMON$"
+ end_pattern = "^#endif \\/\\* ARM64_S390_COMMON \\*\\/$"
+ max_guard_line = 25
+
+ # State variables
+ copying = found_marker = 0
+ guard_name = ""
+ file_header_done = 0
+}
+
+NR <= max_guard_line && !guard_name && /^#ifndef [A-Za-z0-9_]+$/ {
+ guard_name = $2
+ filename = FILENAME
+ sub(/^.*arch\/arm64\//, "arch/arm64/", filename)
+ print "/*"
+ print " * This header was automatically generated from " filename
+ print " * Do not modify this file directly."
+ print " */"
+ print "#ifndef " guard_name
+ print "#define " guard_name
+ print ""
+ next
+}
+
+NR > max_guard_line && !guard_name && !file_header_done {
+ print "error: no include guard found in first " max_guard_line " lines" > "/dev/stderr"
+ file_header_done = 1
+ exit 1
+}
+
+!guard_name {
+ print
+ next
+}
+
+$0 ~ start_pattern {
+ copying = found_marker = 1
+ next
+}
+
+guard_name && !found_marker {
+ next
+}
+
+$0 ~ end_pattern { copying = 0; next }
+
+copying {
+ gsub(/#include <asm\//, "#include <arm64/")
+ gsub(/#include <uapi\/asm\//, "#include <uapi/arm64/")
+ print
+ next
+}
+
+END {
+ if (found_marker) {
+ print ""
+ print "#endif /* " guard_name " */"
+ }
+ exit !found_marker
+}
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 12/27] KVM: s390: Use arm64 code
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (10 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 11/27] s390: Use arm64 headers Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 13/27] KVM: s390: Prepare KVM/s390 for a second KVM module Steffen Eiden
` (14 subsequent siblings)
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
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
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/s390/kvm/arm64/Makefile.gen | 30 +++++++++++++
arch/s390/kvm/arm64/copy-arm64c.awk | 69 +++++++++++++++++++++++++++++
2 files changed, 99 insertions(+)
create mode 100644 arch/s390/kvm/arm64/Makefile.gen
create mode 100644 arch/s390/kvm/arm64/copy-arm64c.awk
diff --git a/arch/s390/kvm/arm64/Makefile.gen b/arch/s390/kvm/arm64/Makefile.gen
new file mode 100644
index 000000000000..2e8838bc6921
--- /dev/null
+++ b/arch/s390/kvm/arm64/Makefile.gen
@@ -0,0 +1,30 @@
+# 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 \
+ reset.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 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))
diff --git a/arch/s390/kvm/arm64/copy-arm64c.awk b/arch/s390/kvm/arm64/copy-arm64c.awk
new file mode 100644
index 000000000000..45d9c7034c17
--- /dev/null
+++ b/arch/s390/kvm/arm64/copy-arm64c.awk
@@ -0,0 +1,69 @@
+#!/usr/bin/awk -f
+# SPDX-License-Identifier: GPL-2.0
+#
+# Extract marked sections from ARM64 C files for sharing with s390 KVM
+#
+# Usage: share-arm64-cfile.awk <input_file>
+#
+# Extracts all sections between start/end markers. If no markers found, signals failure.
+
+BEGIN {
+ # Constants
+ start_pattern = "^#ifdef ARM64_S390_COMMON$"
+ end_pattern = "^#endif /\\* ARM64_S390_COMMON \\*/$"
+
+ # State variables
+ copying = found_marker = 0
+ file_header_done = 0
+}
+
+!file_header_done {
+ if (/^\/\*/ || /^\/\/ SPDX-License-Identifier:/) {
+ print
+ next
+ }
+ if (/[[:space:]]\*([[:space:]]|$)/) {
+ print
+ next
+ }
+ if (/\*\//) {
+ print " *"
+ } else {
+ print "/*"
+ }
+
+ filename = FILENAME
+ sub(/^.*arch\/arm64\//, "arch/arm64/", filename)
+ print " * This file was automatically generated from " filename
+ print " * Do not modify this file directly."
+ print " */"
+ print ""
+ print "#ifndef __INCL_GEN_ARM_FILE"
+ print "#error included .inc file w/o proper guard definition"
+ print "#undef __INCL_GEN_ARM_FILE"
+ print "#endif /* __INCL_GEN_ARM_FILE */"
+ print ""
+
+ file_header_done = 1
+}
+
+$0 ~ start_pattern {
+ copying = found_marker = 1
+ next
+}
+
+$0 ~ end_pattern {
+ copying = 0
+ next
+}
+
+copying {
+ gsub(/#include <asm\//, "#include <arm64/")
+ gsub(/#include <uapi\/asm\//, "#include <uapi/arm64/")
+ print
+ next
+}
+
+END {
+ exit !found_marker
+}
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 13/27] KVM: s390: Prepare KVM/s390 for a second KVM module
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (11 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 12/27] KVM: s390: Use arm64 code Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 14/27] KVM: s390: Move s390 kvm code into a subdirectory Steffen Eiden
` (13 subsequent siblings)
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
Lay the groundwork for a second KVM module. Guard KVM/s390 behind the
KVM_S390 config and turn CONFIG_KVM on if selected. Move all the
kvm_host definitions to _s390 postfixed headers. Prepare local header
include guards for a new location. Move gamp related tracing into a
separate file. While at it, rename the main KVM/s390 files from
s390-kvm.{c,h} to just s390.{c,h} to match the naming scheme of other
architectures.
No functional change.
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/s390/Kconfig | 2 +-
arch/s390/boot/ipl_parm.c | 2 +-
arch/s390/boot/uv.c | 2 +-
arch/s390/configs/debug_defconfig | 2 +-
arch/s390/configs/defconfig | 2 +-
arch/s390/include/asm/kvm_host.h | 774 +-----------------
.../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 | 347 +-------
arch/s390/kernel/early.c | 2 +-
arch/s390/kernel/entry.S | 10 +-
arch/s390/kernel/perf_event.c | 2 +-
arch/s390/kvm/Kconfig | 10 +-
arch/s390/kvm/Makefile | 2 +-
arch/s390/kvm/dat.h | 6 +-
arch/s390/kvm/diag.c | 2 +-
arch/s390/kvm/faultin.c | 3 +-
arch/s390/kvm/faultin.h | 6 +-
arch/s390/kvm/gaccess.c | 2 +-
arch/s390/kvm/gaccess.h | 2 +-
arch/s390/kvm/gmap.c | 2 +-
arch/s390/kvm/gmap.h | 6 +-
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/trace-gmap.h | 45 +
arch/s390/kvm/trace.h | 14 -
arch/s390/kvm/vsie.c | 2 +-
include/linux/kvm_host.h | 2 +-
35 files changed, 103 insertions(+), 1176 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%)
rename arch/s390/kvm/{kvm-s390.c => s390.c} (99%)
rename arch/s390/kvm/{kvm-s390.h => s390.h} (99%)
create mode 100644 arch/s390/kvm/trace-gmap.h
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 84404e6778d5..b2eaa2000b10 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -834,7 +834,7 @@ config VFIO_CCW
config VFIO_AP
def_tristate n
prompt "VFIO support for AP devices"
- depends on KVM
+ depends on KVM_S390
depends on VFIO
depends on AP
select VFIO_MDEV
diff --git a/arch/s390/boot/ipl_parm.c b/arch/s390/boot/ipl_parm.c
index 6bc950b92be7..b8906ba7e5e8 100644
--- a/arch/s390/boot/ipl_parm.c
+++ b/arch/s390/boot/ipl_parm.c
@@ -300,7 +300,7 @@ void parse_boot_command_line(void)
stack_protector_debug = 1;
#endif
-#if IS_ENABLED(CONFIG_KVM)
+#if IS_ENABLED(CONFIG_KVM_S390)
if (!strcmp(param, "prot_virt")) {
rc = kstrtobool(val, &enabled);
if (!rc && enabled)
diff --git a/arch/s390/boot/uv.c b/arch/s390/boot/uv.c
index 4568e8f81dac..f7b68bdcedc1 100644
--- a/arch/s390/boot/uv.c
+++ b/arch/s390/boot/uv.c
@@ -26,7 +26,7 @@ void uv_query_info(void)
if (uv_call(0, (uint64_t)&uvcb) && uvcb.header.rc != UVC_RC_MORE_DATA)
return;
- if (IS_ENABLED(CONFIG_KVM)) {
+ if (IS_ENABLED(CONFIG_KVM_S390)) {
memcpy(uv_info.inst_calls_list, uvcb.inst_calls_list, sizeof(uv_info.inst_calls_list));
uv_info.uv_base_stor_len = uvcb.uv_base_stor_len;
uv_info.guest_base_stor_len = uvcb.conf_base_phys_stor_len;
diff --git a/arch/s390/configs/debug_defconfig b/arch/s390/configs/debug_defconfig
index 54637be87fb7..e9ad718a9408 100644
--- a/arch/s390/configs/debug_defconfig
+++ b/arch/s390/configs/debug_defconfig
@@ -63,7 +63,7 @@ CONFIG_IOMMUFD=y
CONFIG_CMM=m
CONFIG_APPLDATA_BASE=y
CONFIG_S390_HYPFS_FS=y
-CONFIG_KVM=m
+CONFIG_KVM_S390=m
CONFIG_KVM_S390_UCONTROL=y
CONFIG_S390_UNWIND_SELFTEST=m
CONFIG_S390_KPROBES_SANITY_TEST=m
diff --git a/arch/s390/configs/defconfig b/arch/s390/configs/defconfig
index 5f5114a253cf..327ab4a3933c 100644
--- a/arch/s390/configs/defconfig
+++ b/arch/s390/configs/defconfig
@@ -61,7 +61,7 @@ CONFIG_IOMMUFD=y
CONFIG_CMM=m
CONFIG_APPLDATA_BASE=y
CONFIG_S390_HYPFS_FS=y
-CONFIG_KVM=m
+CONFIG_KVM_S390=m
CONFIG_S390_UNWIND_SELFTEST=m
CONFIG_S390_KPROBES_SANITY_TEST=m
CONFIG_S390_MODULES_SANITY_TEST=m
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index eaa34c5bd3c1..e76ceee11ef5 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -1,778 +1,8 @@
/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * definition for kernel virtual machines on s390
- *
- * Copyright IBM Corp. 2008, 2018
- *
- * Author(s): Carsten Otte <cotte@de.ibm.com>
- */
-
#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;
- 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;
-};
-
-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 */
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host_s390.h
similarity index 99%
copy from arch/s390/include/asm/kvm_host.h
copy to arch/s390/include/asm/kvm_host_s390.h
index eaa34c5bd3c1..5293b0067422 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host_s390.h
@@ -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>
@@ -775,4 +775,4 @@ struct zpci_kvm_hook {
extern struct zpci_kvm_hook zpci_kvm_hook;
-#endif
+#endif /* ASM_KVM_HOST_S390_H */
diff --git a/arch/s390/include/asm/kvm_host_types.h b/arch/s390/include/asm/kvm_host_s390_types.h
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 3f50942bdfe6..5cf746095bfd 100644
--- a/arch/s390/include/asm/kvm_host_types.h
+++ b/arch/s390/include/asm/kvm_host_s390_types.h
@@ -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>
@@ -344,4 +344,4 @@ struct sie_page {
__u8 reserved700[2304]; /* 0x0700 */
};
-#endif /* _ASM_KVM_HOST_TYPES_H */
+#endif /* _ASM_KVM_HOST_S390_TYPES_H */
diff --git a/arch/s390/include/asm/kvm_host_types.h b/arch/s390/include/asm/kvm_host_types.h
index 3f50942bdfe6..e5bdba07cab0 100644
--- a/arch/s390/include/asm/kvm_host_types.h
+++ b/arch/s390/include/asm/kvm_host_types.h
@@ -1,347 +1,8 @@
/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_KVM_HOST_TYPES_H
-#define _ASM_KVM_HOST_TYPES_H
+#ifndef ASM_KVM_HOST_TYPES_H
+#define ASM_KVM_HOST_TYPES_H
-#include <linux/atomic.h>
-#include <linux/types.h>
+#include <asm/kvm_host_s390_types.h>
-#define KVM_S390_BSCA_CPU_SLOTS 64
-#define KVM_S390_ESCA_CPU_SLOTS 248
-
-#define SIGP_CTRL_C 0x80
-#define SIGP_CTRL_SCN_MASK 0x3f
-
-union bsca_sigp_ctrl {
- __u8 value;
- struct {
- __u8 c : 1;
- __u8 r : 1;
- __u8 scn : 6;
- };
-};
-
-union esca_sigp_ctrl {
- __u16 value;
- struct {
- __u8 c : 1;
- __u8 reserved: 7;
- __u8 scn;
- };
-};
-
-struct esca_entry {
- union esca_sigp_ctrl sigp_ctrl;
- __u16 reserved1[3];
- __u64 sda;
- __u64 reserved2[6];
-};
-
-struct bsca_entry {
- __u8 reserved0;
- union bsca_sigp_ctrl sigp_ctrl;
- __u16 reserved[3];
- __u64 sda;
- __u64 reserved2[2];
-};
-
-union ipte_control {
- unsigned long val;
- struct {
- unsigned long k : 1;
- unsigned long kh : 31;
- unsigned long kg : 32;
- };
-};
-
-/*
- * Utility is defined as two bytes but having it four bytes wide
- * generates more efficient code. Since the following bytes are
- * reserved this makes no functional difference.
- */
-union sca_utility {
- __u32 val;
- struct {
- __u32 mtcr : 1;
- __u32 : 31;
- };
-};
-
-struct bsca_block {
- union ipte_control ipte_control;
- __u64 reserved[5];
- __u64 mcn;
- union sca_utility utility;
- __u8 reserved2[4];
- struct bsca_entry cpu[KVM_S390_BSCA_CPU_SLOTS];
-};
-
-struct esca_block {
- union ipte_control ipte_control;
- __u64 reserved1[6];
- union sca_utility utility;
- __u8 reserved2[4];
- __u64 mcn[4];
- __u64 reserved3[20];
- struct esca_entry cpu[KVM_S390_ESCA_CPU_SLOTS];
-};
-
-/*
- * This struct is used to store some machine check info from lowcore
- * for machine checks that happen while the guest is running.
- * This info in host's lowcore might be overwritten by a second machine
- * check from host when host is in the machine check's high-level handling.
- * The size is 24 bytes.
- */
-struct mcck_volatile_info {
- __u64 mcic;
- __u64 failing_storage_address;
- __u32 ext_damage_code;
- __u32 reserved;
-};
-
-#define CR0_INITIAL_MASK (CR0_UNUSED_56 | CR0_INTERRUPT_KEY_SUBMASK | \
- CR0_MEASUREMENT_ALERT_SUBMASK)
-#define CR14_INITIAL_MASK (CR14_UNUSED_32 | CR14_UNUSED_33 | \
- CR14_EXTERNAL_DAMAGE_SUBMASK)
-
-#define SIDAD_SIZE_MASK 0xff
-#define sida_addr(sie_block) phys_to_virt((sie_block)->sidad & PAGE_MASK)
-#define sida_size(sie_block) \
- ((((sie_block)->sidad & SIDAD_SIZE_MASK) + 1) * PAGE_SIZE)
-
-#define CPUSTAT_STOPPED 0x80000000
-#define CPUSTAT_WAIT 0x10000000
-#define CPUSTAT_ECALL_PEND 0x08000000
-#define CPUSTAT_STOP_INT 0x04000000
-#define CPUSTAT_IO_INT 0x02000000
-#define CPUSTAT_EXT_INT 0x01000000
-#define CPUSTAT_RUNNING 0x00800000
-#define CPUSTAT_RETAINED 0x00400000
-#define CPUSTAT_TIMING_SUB 0x00020000
-#define CPUSTAT_SIE_SUB 0x00010000
-#define CPUSTAT_RRF 0x00008000
-#define CPUSTAT_SLSV 0x00004000
-#define CPUSTAT_SLSR 0x00002000
-#define CPUSTAT_ZARCH 0x00000800
-#define CPUSTAT_MCDS 0x00000100
-#define CPUSTAT_KSS 0x00000200
-#define CPUSTAT_SM 0x00000080
-#define CPUSTAT_IBS 0x00000040
-#define CPUSTAT_GED2 0x00000010
-#define CPUSTAT_G 0x00000008
-#define CPUSTAT_GED 0x00000004
-#define CPUSTAT_J 0x00000002
-#define CPUSTAT_P 0x00000001
-
-struct kvm_s390_sie_block {
- atomic_t cpuflags; /* 0x0000 */
- __u32 : 1; /* 0x0004 */
- __u32 prefix : 19;
- __u32 ibc : 12;
- __u8 reserved08[4]; /* 0x0008 */
-#define PROG_IN_SIE (1<<0)
- __u32 prog0c; /* 0x000c */
- union {
- __u8 reserved10[16]; /* 0x0010 */
- struct {
- __u64 pv_handle_cpu;
- __u64 pv_handle_config;
- };
- };
-#define PROG_BLOCK_SIE (1<<0)
-#define PROG_REQUEST (1<<1)
- atomic_t prog20; /* 0x0020 */
- __u8 reserved24[4]; /* 0x0024 */
- __u64 cputm; /* 0x0028 */
- __u64 ckc; /* 0x0030 */
- __u64 epoch; /* 0x0038 */
- __u32 svcc; /* 0x0040 */
-#define LCTL_CR0 0x8000
-#define LCTL_CR6 0x0200
-#define LCTL_CR9 0x0040
-#define LCTL_CR10 0x0020
-#define LCTL_CR11 0x0010
-#define LCTL_CR14 0x0002
- __u16 lctl; /* 0x0044 */
- __s16 icpua; /* 0x0046 */
-#define ICTL_OPEREXC 0x80000000
-#define ICTL_PINT 0x20000000
-#define ICTL_LPSW 0x00400000
-#define ICTL_STCTL 0x00040000
-#define ICTL_ISKE 0x00004000
-#define ICTL_SSKE 0x00002000
-#define ICTL_RRBE 0x00001000
-#define ICTL_TPROT 0x00000200
- __u32 ictl; /* 0x0048 */
-#define ECA_CEI 0x80000000
-#define ECA_IB 0x40000000
-#define ECA_SIGPI 0x10000000
-#define ECA_MVPGI 0x01000000
-#define ECA_AIV 0x00200000
-#define ECA_VX 0x00020000
-#define ECA_PROTEXCI 0x00002000
-#define ECA_APIE 0x00000008
-#define ECA_SII 0x00000001
- __u32 eca; /* 0x004c */
-#define ICPT_INST 0x04
-#define ICPT_PROGI 0x08
-#define ICPT_INSTPROGI 0x0C
-#define ICPT_EXTREQ 0x10
-#define ICPT_EXTINT 0x14
-#define ICPT_IOREQ 0x18
-#define ICPT_WAIT 0x1c
-#define ICPT_VALIDITY 0x20
-#define ICPT_STOP 0x28
-#define ICPT_OPEREXC 0x2C
-#define ICPT_PARTEXEC 0x38
-#define ICPT_IOINST 0x40
-#define ICPT_KSS 0x5c
-#define ICPT_MCHKREQ 0x60
-#define ICPT_INT_ENABLE 0x64
-#define ICPT_PV_INSTR 0x68
-#define ICPT_PV_NOTIFY 0x6c
-#define ICPT_PV_PREF 0x70
- __u8 icptcode; /* 0x0050 */
- __u8 icptstatus; /* 0x0051 */
- __u16 ihcpu; /* 0x0052 */
- __u8 reserved54; /* 0x0054 */
-#define IICTL_CODE_NONE 0x00
-#define IICTL_CODE_MCHK 0x01
-#define IICTL_CODE_EXT 0x02
-#define IICTL_CODE_IO 0x03
-#define IICTL_CODE_RESTART 0x04
-#define IICTL_CODE_SPECIFICATION 0x10
-#define IICTL_CODE_OPERAND 0x11
- __u8 iictl; /* 0x0055 */
- __u16 ipa; /* 0x0056 */
- __u32 ipb; /* 0x0058 */
- __u32 scaoh; /* 0x005c */
-#define FPF_BPBC 0x20
- __u8 fpf; /* 0x0060 */
-#define ECB_GS 0x40
-#define ECB_TE 0x10
-#define ECB_SPECI 0x08
-#define ECB_SRSI 0x04
-#define ECB_HOSTPROTINT 0x02
-#define ECB_PTF 0x01
- __u8 ecb; /* 0x0061 */
-#define ECB2_CMMA 0x80
-#define ECB2_IEP 0x20
-#define ECB2_PFMFI 0x08
-#define ECB2_ESCA 0x04
-#define ECB2_ZPCI_LSI 0x02
- __u8 ecb2; /* 0x0062 */
-#define ECB3_AISI 0x20
-#define ECB3_AISII 0x10
-#define ECB3_DEA 0x08
-#define ECB3_AES 0x04
-#define ECB3_RI 0x01
- __u8 ecb3; /* 0x0063 */
-#define ESCA_SCAOL_MASK ~0x3fU
- __u32 scaol; /* 0x0064 */
- __u8 sdf; /* 0x0068 */
- __u8 epdx; /* 0x0069 */
- __u8 cpnc; /* 0x006a */
- __u8 reserved6b; /* 0x006b */
- __u32 todpr; /* 0x006c */
-#define GISA_FORMAT1 0x00000001
- __u32 gd; /* 0x0070 */
- __u8 reserved74[12]; /* 0x0074 */
- __u64 mso; /* 0x0080 */
- __u64 msl; /* 0x0088 */
- psw_t gpsw; /* 0x0090 */
- __u64 gg14; /* 0x00a0 */
- __u64 gg15; /* 0x00a8 */
- __u8 reservedb0[8]; /* 0x00b0 */
-#define HPID_KVM 0x4
-#define HPID_VSIE 0x5
- __u8 hpid; /* 0x00b8 */
- __u8 reservedb9[7]; /* 0x00b9 */
- union {
- struct {
- __u32 eiparams; /* 0x00c0 */
- __u16 extcpuaddr; /* 0x00c4 */
- __u16 eic; /* 0x00c6 */
- };
- __u64 mcic; /* 0x00c0 */
- } __packed;
- __u32 reservedc8; /* 0x00c8 */
- union {
- struct {
- __u16 pgmilc; /* 0x00cc */
- __u16 iprcc; /* 0x00ce */
- };
- __u32 edc; /* 0x00cc */
- } __packed;
- union {
- struct {
- __u32 dxc; /* 0x00d0 */
- __u16 mcn; /* 0x00d4 */
- __u8 perc; /* 0x00d6 */
- __u8 peratmid; /* 0x00d7 */
- };
- __u64 faddr; /* 0x00d0 */
- } __packed;
- __u64 peraddr; /* 0x00d8 */
- __u8 eai; /* 0x00e0 */
- __u8 peraid; /* 0x00e1 */
- __u8 oai; /* 0x00e2 */
- __u8 armid; /* 0x00e3 */
- __u8 reservede4[4]; /* 0x00e4 */
- union {
- __u64 tecmc; /* 0x00e8 */
- struct {
- __u16 subchannel_id; /* 0x00e8 */
- __u16 subchannel_nr; /* 0x00ea */
- __u32 io_int_parm; /* 0x00ec */
- __u32 io_int_word; /* 0x00f0 */
- };
- } __packed;
- __u8 reservedf4[8]; /* 0x00f4 */
-#define CRYCB_FORMAT_MASK 0x00000003
-#define CRYCB_FORMAT0 0x00000000
-#define CRYCB_FORMAT1 0x00000001
-#define CRYCB_FORMAT2 0x00000003
- __u32 crycbd; /* 0x00fc */
- __u64 gcr[16]; /* 0x0100 */
- union {
- __u64 gbea; /* 0x0180 */
- __u64 sidad;
- };
- __u8 reserved188[8]; /* 0x0188 */
- __u64 sdnxo; /* 0x0190 */
- __u8 reserved198[8]; /* 0x0198 */
- __u32 fac; /* 0x01a0 */
- __u8 reserved1a4[20]; /* 0x01a4 */
- __u64 cbrlo; /* 0x01b8 */
- __u8 reserved1c0[8]; /* 0x01c0 */
-#define ECD_HOSTREGMGMT 0x20000000
-#define ECD_MEF 0x08000000
-#define ECD_ETOKENF 0x02000000
-#define ECD_ECC 0x00200000
-#define ECD_HMAC 0x00004000
- __u32 ecd; /* 0x01c8 */
- __u8 reserved1cc[18]; /* 0x01cc */
- __u64 pp; /* 0x01de */
- __u8 reserved1e6[2]; /* 0x01e6 */
- __u64 itdba; /* 0x01e8 */
- __u64 riccbd; /* 0x01f0 */
- __u64 gvrd; /* 0x01f8 */
-} __packed __aligned(512);
-
-struct kvm_s390_itdb {
- __u8 data[256];
-};
-
-struct sie_page {
- struct kvm_s390_sie_block sie_block;
- struct mcck_volatile_info mcck_info; /* 0x0200 */
- __u8 reserved218[360]; /* 0x0218 */
- __u64 pv_grregs[16]; /* 0x0380 */
- __u8 reserved400[512]; /* 0x0400 */
- struct kvm_s390_itdb itdb; /* 0x0600 */
- __u8 reserved700[2304]; /* 0x0700 */
-};
-
-#endif /* _ASM_KVM_HOST_TYPES_H */
+#endif /* ASM_KVM_HOST_TYPES_H */
diff --git a/arch/s390/kernel/early.c b/arch/s390/kernel/early.c
index b27239c03d79..464f8918d447 100644
--- a/arch/s390/kernel/early.c
+++ b/arch/s390/kernel/early.c
@@ -57,7 +57,7 @@ decompressor_handled_param(cmma);
decompressor_handled_param(relocate_lowcore);
decompressor_handled_param(bootdebug);
__decompressor_handled_param(debug_alternative, debug-alternative);
-#if IS_ENABLED(CONFIG_KVM)
+#if IS_ENABLED(CONFIG_KVM_S390)
decompressor_handled_param(prot_virt);
#endif
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index 79a45efae23d..9572620fcaa6 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -113,7 +113,7 @@ _LPP_OFFSET = __LC_LPP
"jnz .+8; .insn rrf,0xb2e80000,0,0,13,0", ALT_SPEC(82)
.endm
-#if IS_ENABLED(CONFIG_KVM)
+#if IS_ENABLED(CONFIG_KVM_S390)
.macro SIEEXIT sie_control,lowcore
lg %r9,\sie_control # get control block pointer
ni __SIE_PROG0C+3(%r9),0xfe # no longer in SIE
@@ -184,7 +184,7 @@ EXPORT_SYMBOL(__WARN_trap)
#endif /* CONFIG_BUG && CONFIG_CC_HAS_ASM_IMMEDIATE_STRINGS */
-#if IS_ENABLED(CONFIG_KVM)
+#if IS_ENABLED(CONFIG_KVM_S390)
/*
* __sie64a calling convention:
* %r2 pointer to sie control block phys
@@ -315,7 +315,7 @@ SYM_CODE_START(pgm_check_handler)
xgr %r10,%r10
tmhh %r8,0x0001 # coming from user space?
jo 3f # -> fault in user space
-#if IS_ENABLED(CONFIG_KVM)
+#if IS_ENABLED(CONFIG_KVM_S390)
lg %r11,__LC_CURRENT(%r13)
tm __TI_sie(%r11),0xff
jz 1f
@@ -397,7 +397,7 @@ SYM_CODE_START(\name)
lmg %r8,%r9,\lc_old_psw(%r13)
tmhh %r8,0x0001 # interrupting from user ?
jnz 1f
-#if IS_ENABLED(CONFIG_KVM)
+#if IS_ENABLED(CONFIG_KVM_S390)
lg %r10,__LC_CURRENT(%r13)
tm __TI_sie(%r10),0xff
jz 0f
@@ -475,7 +475,7 @@ SYM_CODE_START(mcck_int_handler)
jnz .Lmcck_user
TSTMSK __LC_MCCK_CODE(%r13),MCCK_CODE_PSW_IA_VALID
jno .Lmcck_panic
-#if IS_ENABLED(CONFIG_KVM)
+#if IS_ENABLED(CONFIG_KVM_S390)
lg %r10,__LC_CURRENT(%r13)
tm __TI_sie(%r10),0xff
jz .Lmcck_user
diff --git a/arch/s390/kernel/perf_event.c b/arch/s390/kernel/perf_event.c
index 606750bae508..6441746b8e72 100644
--- a/arch/s390/kernel/perf_event.c
+++ b/arch/s390/kernel/perf_event.c
@@ -37,7 +37,7 @@ static bool is_in_guest(struct pt_regs *regs)
{
if (user_mode(regs))
return false;
-#if IS_ENABLED(CONFIG_KVM)
+#if IS_ENABLED(CONFIG_KVM_S390)
return instruction_pointer(regs) == (unsigned long) &sie_exit;
#else
return false;
diff --git a/arch/s390/kvm/Kconfig b/arch/s390/kvm/Kconfig
index 8d3ee17a1bcb..fbf4162d6f2d 100644
--- a/arch/s390/kvm/Kconfig
+++ b/arch/s390/kvm/Kconfig
@@ -17,8 +17,12 @@ menuconfig VIRTUALIZATION
if VIRTUALIZATION
config KVM
+ tristate
+
+config KVM_S390
def_tristate y
- prompt "Kernel-based Virtual Machine (KVM) support"
+ prompt "Kernel-based Virtual Machine (KVM) support (s390)"
+ select KVM
select HAVE_KVM_CPU_RELAX_INTERCEPT
select KVM_ASYNC_PF
select KVM_ASYNC_PF_SYNC
@@ -32,7 +36,7 @@ config KVM
select KVM_MMU_LOCKLESS_AGING
select KVM_GENERIC_PRE_FAULT_MEMORY
help
- Support hosting paravirtualized guest machines using the SIE
+ Support hosting paravirtualized s390 guest machines using the SIE
virtualization capability on the mainframe. This should work
on any 64bit machine.
@@ -46,7 +50,7 @@ config KVM
config KVM_S390_UCONTROL
bool "Userspace controlled virtual machines"
- depends on KVM
+ depends on KVM_S390
help
Allow CAP_SYS_ADMIN users to create KVM virtual machines that are
controlled by userspace.
diff --git a/arch/s390/kvm/Makefile b/arch/s390/kvm/Makefile
index dac9d53b23d8..df10063ae042 100644
--- a/arch/s390/kvm/Makefile
+++ b/arch/s390/kvm/Makefile
@@ -7,7 +7,7 @@ include $(srctree)/virt/kvm/Makefile.kvm
ccflags-y := -Ivirt/kvm -Iarch/s390/kvm
-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
diff --git a/arch/s390/kvm/dat.h b/arch/s390/kvm/dat.h
index fad605305e05..711ae2f96107 100644
--- a/arch/s390/kvm/dat.h
+++ b/arch/s390/kvm/dat.h
@@ -6,8 +6,8 @@
* Author(s): Claudio Imbrenda <imbrenda@linux.ibm.com>
*/
-#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 */
diff --git a/arch/s390/kvm/diag.c b/arch/s390/kvm/diag.c
index d89d1c381522..700d9b7b68bc 100644
--- a/arch/s390/kvm/diag.c
+++ b/arch/s390/kvm/diag.c
@@ -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"
diff --git a/arch/s390/kvm/faultin.c b/arch/s390/kvm/faultin.c
index fee80047bd94..740415d494de 100644
--- a/arch/s390/kvm/faultin.c
+++ b/arch/s390/kvm/faultin.c
@@ -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.
diff --git a/arch/s390/kvm/faultin.h b/arch/s390/kvm/faultin.h
index f86176d2769c..f343b6fb6f16 100644
--- a/arch/s390/kvm/faultin.h
+++ b/arch/s390/kvm/faultin.h
@@ -6,8 +6,8 @@
* Author(s): Claudio Imbrenda <imbrenda@linux.ibm.com>
*/
-#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 */
diff --git a/arch/s390/kvm/gaccess.c b/arch/s390/kvm/gaccess.c
index 36102b2727fb..2a4b2525329a 100644
--- a/arch/s390/kvm/gaccess.c
+++ b/arch/s390/kvm/gaccess.c
@@ -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"
diff --git a/arch/s390/kvm/gaccess.h b/arch/s390/kvm/gaccess.h
index b5385cec60f4..ef922b3b4990 100644
--- a/arch/s390/kvm/gaccess.h
+++ b/arch/s390/kvm/gaccess.h
@@ -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
diff --git a/arch/s390/kvm/gmap.c b/arch/s390/kvm/gmap.c
index 298fbaecec28..8773aa34f107 100644
--- a/arch/s390/kvm/gmap.c
+++ b/arch/s390/kvm/gmap.c
@@ -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)
diff --git a/arch/s390/kvm/gmap.h b/arch/s390/kvm/gmap.h
index 39938d363ec9..c54c35e47d6d 100644
--- a/arch/s390/kvm/gmap.h
+++ b/arch/s390/kvm/gmap.h
@@ -7,8 +7,8 @@
* Claudio Imbrenda <imbrenda@linux.ibm.com>
*/
-#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 */
diff --git a/arch/s390/kvm/guestdbg.c b/arch/s390/kvm/guestdbg.c
index 69835e1d4f20..c880ebbdef2f 100644
--- a/arch/s390/kvm/guestdbg.c
+++ b/arch/s390/kvm/guestdbg.c
@@ -8,7 +8,7 @@
*/
#include <linux/kvm_host.h>
#include <linux/errno.h>
-#include "kvm-s390.h"
+#include "s390.h"
#include "gaccess.h"
/*
diff --git a/arch/s390/kvm/intercept.c b/arch/s390/kvm/intercept.c
index 1980df61ef30..ca1205dfac8b 100644
--- a/arch/s390/kvm/intercept.c
+++ b/arch/s390/kvm/intercept.c
@@ -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"
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index 9e3e6b0d72ad..24c41c7a4c3d 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -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"
diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/pci.c
index 5b075c38998e..efdc1ddf6ba8 100644
--- a/arch/s390/kvm/pci.c
+++ b/arch/s390/kvm/pci.c
@@ -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;
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index ad0ddc433a73..21479f0a5e5a 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -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"
diff --git a/arch/s390/kvm/pv.c b/arch/s390/kvm/pv.c
index 1beacc841ca8..f6e03e9d371a 100644
--- a/arch/s390/kvm/pv.c
+++ b/arch/s390/kvm/pv.c
@@ -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"
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/s390.c
similarity index 99%
rename from arch/s390/kvm/kvm-s390.c
rename to arch/s390/kvm/s390.c
index 23c817595e28..26720ffcf5db 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/s390.c
@@ -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"
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/s390.h
similarity index 99%
rename from arch/s390/kvm/kvm-s390.h
rename to arch/s390/kvm/s390.h
index 6d2842fb71a3..e144ca2e6d5e 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/s390.h
@@ -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);
diff --git a/arch/s390/kvm/sigp.c b/arch/s390/kvm/sigp.c
index 55c34cb35428..131b3371ef4f 100644
--- a/arch/s390/kvm/sigp.c
+++ b/arch/s390/kvm/sigp.c
@@ -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,
diff --git a/arch/s390/kvm/trace-gmap.h b/arch/s390/kvm/trace-gmap.h
new file mode 100644
index 000000000000..b4abe4e385f8
--- /dev/null
+++ b/arch/s390/kvm/trace-gmap.h
@@ -0,0 +1,45 @@
+/* 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_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>
diff --git a/arch/s390/kvm/trace.h b/arch/s390/kvm/trace.h
index aa419eb6a0c8..97774fe09a85 100644
--- a/arch/s390/kvm/trace.h
+++ b/arch/s390/kvm/trace.h
@@ -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),
diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
index eea24562e7db..c4a03b310fea 100644
--- a/arch/s390/kvm/vsie.c
+++ b/arch/s390/kvm/vsie.c
@@ -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"
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index f179a9230e30..bd380a259910 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -1538,7 +1538,7 @@ void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu);
void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu);
bool kvm_vcpu_wake_up(struct kvm_vcpu *vcpu);
-#ifndef CONFIG_S390
+#ifndef CONFIG_KVM_S390
void __kvm_vcpu_kick(struct kvm_vcpu *vcpu, bool wait);
static inline void kvm_vcpu_kick(struct kvm_vcpu *vcpu)
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 14/27] KVM: s390: Move s390 kvm code into a subdirectory
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (12 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 13/27] KVM: s390: Prepare KVM/s390 for a second KVM module Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 15/27] KVM: S390: Prepare gmap for a second KVM implementation Steffen Eiden
` (12 subsequent siblings)
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
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.
No functional change.
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/s390/kvm/Kconfig | 38 +--------------------------
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 | 1 +
arch/s390/kvm/{ => s390}/Kconfig | 21 +--------------
arch/s390/kvm/{ => s390}/Makefile | 8 +++---
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
28 files changed, 14 insertions(+), 70 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}/Kconfig (71%)
copy arch/s390/kvm/{ => s390}/Makefile (64%)
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%)
diff --git a/arch/s390/kvm/Kconfig b/arch/s390/kvm/Kconfig
index fbf4162d6f2d..f8d4a9a38dae 100644
--- a/arch/s390/kvm/Kconfig
+++ b/arch/s390/kvm/Kconfig
@@ -19,42 +19,6 @@ if VIRTUALIZATION
config KVM
tristate
-config KVM_S390
- def_tristate y
- prompt "Kernel-based Virtual Machine (KVM) support (s390)"
- select KVM
- select HAVE_KVM_CPU_RELAX_INTERCEPT
- select KVM_ASYNC_PF
- select KVM_ASYNC_PF_SYNC
- select KVM_COMMON
- select HAVE_KVM_IRQCHIP
- select HAVE_KVM_IRQ_ROUTING
- select HAVE_KVM_INVALID_WAKEUPS
- select HAVE_KVM_NO_POLL
- select KVM_VFIO
- select VIRT_XFER_TO_GUEST_WORK
- select KVM_MMU_LOCKLESS_AGING
- select KVM_GENERIC_PRE_FAULT_MEMORY
- help
- Support hosting paravirtualized s390 guest machines using the SIE
- virtualization capability on the mainframe. This should work
- on any 64bit machine.
-
- This module provides access to the hardware capabilities through
- a character device node named /dev/kvm.
-
- To compile this as a module, choose M here: the module
- will be called kvm.
-
- If unsure, say N.
-
-config KVM_S390_UCONTROL
- bool "Userspace controlled virtual machines"
- depends on KVM_S390
- help
- Allow CAP_SYS_ADMIN users to create KVM virtual machines that are
- controlled by userspace.
-
- If unsure, say N.
+source "arch/s390/kvm/s390/Kconfig"
endif # VIRTUALIZATION
diff --git a/arch/s390/kvm/Makefile b/arch/s390/kvm/Makefile
index df10063ae042..c43d7dffca13 100644
--- a/arch/s390/kvm/Makefile
+++ b/arch/s390/kvm/Makefile
@@ -3,13 +3,4 @@
#
# Copyright IBM Corp. 2008
-include $(srctree)/virt/kvm/Makefile.kvm
-
-ccflags-y := -Ivirt/kvm -Iarch/s390/kvm
-
-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) += s390/
diff --git a/arch/s390/kvm/gmap/Makefile b/arch/s390/kvm/gmap/Makefile
new file mode 100644
index 000000000000..21967ed88877
--- /dev/null
+++ b/arch/s390/kvm/gmap/Makefile
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
+GMAP ?= ../gmap
+
+kvm-y += $(GMAP)/dat.o $(GMAP)/gmap.o $(GMAP)/faultin.o
diff --git a/arch/s390/kvm/dat.c b/arch/s390/kvm/gmap/dat.c
similarity index 100%
rename from arch/s390/kvm/dat.c
rename to arch/s390/kvm/gmap/dat.c
diff --git a/arch/s390/kvm/dat.h b/arch/s390/kvm/gmap/dat.h
similarity index 100%
rename from arch/s390/kvm/dat.h
rename to arch/s390/kvm/gmap/dat.h
diff --git a/arch/s390/kvm/faultin.c b/arch/s390/kvm/gmap/faultin.c
similarity index 100%
rename from arch/s390/kvm/faultin.c
rename to arch/s390/kvm/gmap/faultin.c
diff --git a/arch/s390/kvm/faultin.h b/arch/s390/kvm/gmap/faultin.h
similarity index 100%
rename from arch/s390/kvm/faultin.h
rename to arch/s390/kvm/gmap/faultin.h
diff --git a/arch/s390/kvm/gmap.c b/arch/s390/kvm/gmap/gmap.c
similarity index 100%
rename from arch/s390/kvm/gmap.c
rename to arch/s390/kvm/gmap/gmap.c
diff --git a/arch/s390/kvm/gmap.h b/arch/s390/kvm/gmap/gmap.h
similarity index 100%
rename from arch/s390/kvm/gmap.h
rename to arch/s390/kvm/gmap/gmap.h
diff --git a/arch/s390/kvm/trace-gmap.h b/arch/s390/kvm/gmap/trace-gmap.h
similarity index 96%
rename from arch/s390/kvm/trace-gmap.h
rename to arch/s390/kvm/gmap/trace-gmap.h
index b4abe4e385f8..78559298932c 100644
--- a/arch/s390/kvm/trace-gmap.h
+++ b/arch/s390/kvm/gmap/trace-gmap.h
@@ -6,6 +6,7 @@
#undef TRACE_SYSTEM
#define TRACE_SYSTEM kvm
+#define TRACE_INCLUDE_PATH ../gmap
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE trace-gmap
diff --git a/arch/s390/kvm/Kconfig b/arch/s390/kvm/s390/Kconfig
similarity index 71%
copy from arch/s390/kvm/Kconfig
copy to arch/s390/kvm/s390/Kconfig
index fbf4162d6f2d..4b7a7c2945e5 100644
--- a/arch/s390/kvm/Kconfig
+++ b/arch/s390/kvm/s390/Kconfig
@@ -1,23 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
#
-# KVM configuration
-#
-source "virt/kvm/Kconfig"
-
-menuconfig VIRTUALIZATION
- def_bool y
- prompt "KVM"
- help
- Say Y here to get to see options for using your Linux host to run other
- operating systems inside virtual machines (guests).
- This option alone does not add any kernel code.
-
- If you say N, all options in this submenu will be skipped and disabled.
-
-if VIRTUALIZATION
-
-config KVM
- tristate
+# KVM_S390 configuration
config KVM_S390
def_tristate y
@@ -56,5 +39,3 @@ config KVM_S390_UCONTROL
controlled by userspace.
If unsure, say N.
-
-endif # VIRTUALIZATION
diff --git a/arch/s390/kvm/Makefile b/arch/s390/kvm/s390/Makefile
similarity index 64%
copy from arch/s390/kvm/Makefile
copy to arch/s390/kvm/s390/Makefile
index df10063ae042..51aee874b36f 100644
--- a/arch/s390/kvm/Makefile
+++ b/arch/s390/kvm/s390/Makefile
@@ -3,13 +3,15 @@
#
# Copyright IBM Corp. 2008
+KVM := ../../../../virt/kvm
include $(srctree)/virt/kvm/Makefile.kvm
+include $(srctree)/arch/s390/kvm/gmap/Makefile
-ccflags-y := -Ivirt/kvm -Iarch/s390/kvm
+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-$(CONFIG_VFIO_PCI_ZDEV_KVM) += pci.o
-obj-$(CONFIG_KVM) += kvm.o
+
+obj-$(CONFIG_KVM_S390) += kvm.o
diff --git a/arch/s390/kvm/diag.c b/arch/s390/kvm/s390/diag.c
similarity index 100%
rename from arch/s390/kvm/diag.c
rename to arch/s390/kvm/s390/diag.c
diff --git a/arch/s390/kvm/gaccess.c b/arch/s390/kvm/s390/gaccess.c
similarity index 100%
rename from arch/s390/kvm/gaccess.c
rename to arch/s390/kvm/s390/gaccess.c
diff --git a/arch/s390/kvm/gaccess.h b/arch/s390/kvm/s390/gaccess.h
similarity index 100%
rename from arch/s390/kvm/gaccess.h
rename to arch/s390/kvm/s390/gaccess.h
diff --git a/arch/s390/kvm/guestdbg.c b/arch/s390/kvm/s390/guestdbg.c
similarity index 100%
rename from arch/s390/kvm/guestdbg.c
rename to arch/s390/kvm/s390/guestdbg.c
diff --git a/arch/s390/kvm/intercept.c b/arch/s390/kvm/s390/intercept.c
similarity index 100%
rename from arch/s390/kvm/intercept.c
rename to arch/s390/kvm/s390/intercept.c
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/s390/interrupt.c
similarity index 100%
rename from arch/s390/kvm/interrupt.c
rename to arch/s390/kvm/s390/interrupt.c
diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/s390/pci.c
similarity index 100%
rename from arch/s390/kvm/pci.c
rename to arch/s390/kvm/s390/pci.c
diff --git a/arch/s390/kvm/pci.h b/arch/s390/kvm/s390/pci.h
similarity index 100%
rename from arch/s390/kvm/pci.h
rename to arch/s390/kvm/s390/pci.h
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/s390/priv.c
similarity index 100%
rename from arch/s390/kvm/priv.c
rename to arch/s390/kvm/s390/priv.c
diff --git a/arch/s390/kvm/pv.c b/arch/s390/kvm/s390/pv.c
similarity index 100%
rename from arch/s390/kvm/pv.c
rename to arch/s390/kvm/s390/pv.c
diff --git a/arch/s390/kvm/s390.c b/arch/s390/kvm/s390/s390.c
similarity index 100%
rename from arch/s390/kvm/s390.c
rename to arch/s390/kvm/s390/s390.c
diff --git a/arch/s390/kvm/s390.h b/arch/s390/kvm/s390/s390.h
similarity index 100%
rename from arch/s390/kvm/s390.h
rename to arch/s390/kvm/s390/s390.h
diff --git a/arch/s390/kvm/sigp.c b/arch/s390/kvm/s390/sigp.c
similarity index 100%
rename from arch/s390/kvm/sigp.c
rename to arch/s390/kvm/s390/sigp.c
diff --git a/arch/s390/kvm/trace-s390.h b/arch/s390/kvm/s390/trace-s390.h
similarity index 100%
rename from arch/s390/kvm/trace-s390.h
rename to arch/s390/kvm/s390/trace-s390.h
diff --git a/arch/s390/kvm/trace.h b/arch/s390/kvm/s390/trace.h
similarity index 100%
rename from arch/s390/kvm/trace.h
rename to arch/s390/kvm/s390/trace.h
diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/s390/vsie.c
similarity index 100%
rename from arch/s390/kvm/vsie.c
rename to arch/s390/kvm/s390/vsie.c
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 15/27] KVM: S390: Prepare gmap for a second KVM implementation
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (13 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 14/27] KVM: s390: Move s390 kvm code into a subdirectory Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 16/27] KVM: s390: gmap: Refactor storage key and CMMA code into separate files Steffen Eiden
` (11 subsequent siblings)
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
Refactor gmap code such that a second s390 (host) KVM implementation can
use the gmap code as well. Move relevant definitions into the shared
kvm_host.h. Move mmu code from s390 to gmap so the other KVM
implementation can use it as well.
No functional change.
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/s390/include/asm/kvm_host.h | 9 ++
arch/s390/include/asm/kvm_host_s390.h | 11 +-
arch/s390/kvm/gmap/Makefile | 2 +-
arch/s390/kvm/gmap/faultin.c | 1 -
arch/s390/kvm/gmap/gmap.c | 5 -
arch/s390/kvm/gmap/gmap.h | 15 ++
arch/s390/kvm/gmap/mmu.c | 193 ++++++++++++++++++++++++++
arch/s390/kvm/s390/s390.c | 134 ++----------------
arch/s390/kvm/s390/s390.h | 16 +++
9 files changed, 245 insertions(+), 141 deletions(-)
create mode 100644 arch/s390/kvm/gmap/mmu.c
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index e76ceee11ef5..33af8842a71c 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -5,4 +5,13 @@
#include <asm/kvm_host_s390.h>
+#define PGM_PROTECTION 0x04
+#define PGM_ADDRESSING 0x05
+#define PGM_SEGMENT_TRANSLATION 0x10
+#define PGM_PAGE_TRANSLATION 0x11
+#define PGM_ASCE_TYPE 0x38
+#define PGM_REGION_FIRST_TRANS 0x39
+#define PGM_REGION_SECOND_TRANS 0x3a
+#define PGM_REGION_THIRD_TRANS 0x3b
+
#endif /* ASM_KVM_HOST_H */
diff --git a/arch/s390/include/asm/kvm_host_s390.h b/arch/s390/include/asm/kvm_host_s390.h
index 5293b0067422..7b7aa166cff7 100644
--- a/arch/s390/include/asm/kvm_host_s390.h
+++ b/arch/s390/include/asm/kvm_host_s390.h
@@ -153,8 +153,7 @@ struct kvm_vcpu_stat {
#define PGM_OPERATION 0x01
#define PGM_PRIVILEGED_OP 0x02
#define PGM_EXECUTE 0x03
-#define PGM_PROTECTION 0x04
-#define PGM_ADDRESSING 0x05
+/* 0x04 & 0x05 defined in kvm_host.h */
#define PGM_SPECIFICATION 0x06
#define PGM_DATA 0x07
#define PGM_FIXED_POINT_OVERFLOW 0x08
@@ -165,8 +164,7 @@ struct kvm_vcpu_stat {
#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
+/* 0x10 & 0x11 defined in kvm_host.h */
#define PGM_TRANSLATION_SPEC 0x12
#define PGM_SPECIAL_OPERATION 0x13
#define PGM_OPERAND 0x15
@@ -196,10 +194,7 @@ struct kvm_vcpu_stat {
#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
+/* 0x38 - 0x3b defined in kvm_host.h */
#define PGM_SECURE_STORAGE_ACCESS 0x3d
#define PGM_NON_SECURE_STORAGE_ACCESS 0x3e
#define PGM_SECURE_STORAGE_VIOLATION 0x3f
diff --git a/arch/s390/kvm/gmap/Makefile b/arch/s390/kvm/gmap/Makefile
index 21967ed88877..140914c5c14f 100644
--- a/arch/s390/kvm/gmap/Makefile
+++ b/arch/s390/kvm/gmap/Makefile
@@ -2,4 +2,4 @@
GMAP ?= ../gmap
-kvm-y += $(GMAP)/dat.o $(GMAP)/gmap.o $(GMAP)/faultin.o
+kvm-y += $(GMAP)/dat.o $(GMAP)/gmap.o $(GMAP)/faultin.o $(GMAP)/mmu.o
diff --git a/arch/s390/kvm/gmap/faultin.c b/arch/s390/kvm/gmap/faultin.c
index 740415d494de..713914dc8eb2 100644
--- a/arch/s390/kvm/gmap/faultin.c
+++ b/arch/s390/kvm/gmap/faultin.c
@@ -11,7 +11,6 @@
#include "gmap.h"
#include "faultin.h"
-bool kvm_arch_setup_async_pf(struct kvm_vcpu *vcpu);
#define CREATE_TRACE_POINTS
#include "trace-gmap.h"
diff --git a/arch/s390/kvm/gmap/gmap.c b/arch/s390/kvm/gmap/gmap.c
index 8773aa34f107..a04e0a4355a0 100644
--- a/arch/s390/kvm/gmap/gmap.c
+++ b/arch/s390/kvm/gmap/gmap.c
@@ -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)
diff --git a/arch/s390/kvm/gmap/gmap.h b/arch/s390/kvm/gmap/gmap.h
index c54c35e47d6d..4ab7208f50ff 100644
--- a/arch/s390/kvm/gmap/gmap.h
+++ b/arch/s390/kvm/gmap/gmap.h
@@ -10,6 +10,8 @@
#ifndef ARCH_KVM_GMAP_GMAP_H
#define ARCH_KVM_GMAP_GMAP_H
+#include <linux/kvm_host.h>
+
#include "dat.h"
/**
@@ -330,4 +332,17 @@ 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;
}
+int gmap_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log);
+int gmap_prepare_memory_region(struct kvm *kvm,
+ const struct kvm_memory_slot *old,
+ struct kvm_memory_slot *new,
+ enum kvm_mr_change change);
+void gmap_commit_memory_region(struct kvm *kvm,
+ struct kvm_memory_slot *old,
+ const struct kvm_memory_slot *new,
+ enum kvm_mr_change change);
+bool gmap_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range);
+long gmap_pre_fault_memory(struct kvm_vcpu *vcpu,
+ struct kvm_pre_fault_memory *range);
+
#endif /* ARCH_KVM_GMAP_GMAP_H */
diff --git a/arch/s390/kvm/gmap/mmu.c b/arch/s390/kvm/gmap/mmu.c
new file mode 100644
index 000000000000..5bb6609b974b
--- /dev/null
+++ b/arch/s390/kvm/gmap/mmu.c
@@ -0,0 +1,193 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#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 "faultin.h"
+
+/*
+ * Get (and clear) the dirty memory log for a memory slot.
+ */
+int gmap_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
+{
+ int r;
+ unsigned long n;
+ struct kvm_memory_slot *memslot;
+ int is_dirty;
+
+ if (kvm_is_ucontrol(kvm))
+ return -EINVAL;
+
+ mutex_lock(&kvm->slots_lock);
+
+ r = -EINVAL;
+ if (log->slot >= KVM_USER_MEM_SLOTS)
+ goto out;
+
+ r = kvm_get_dirty_log(kvm, log, &is_dirty, &memslot);
+ if (r)
+ goto out;
+
+ /* Clear the dirty log */
+ if (is_dirty) {
+ n = kvm_dirty_bitmap_bytes(memslot);
+ memset(memslot->dirty_bitmap, 0, n);
+ }
+ r = 0;
+out:
+ mutex_unlock(&kvm->slots_lock);
+ return r;
+}
+
+int gmap_prepare_memory_region(struct kvm *kvm,
+ const struct kvm_memory_slot *old,
+ struct kvm_memory_slot *new,
+ enum kvm_mr_change change)
+{
+ if (kvm_is_ucontrol(kvm) && new && new->id < KVM_USER_MEM_SLOTS)
+ return -EINVAL;
+
+ /* When we are protected, we should not change the memory slots */
+ if (kvm_s390_pv_get_handle(kvm))
+ return -EINVAL;
+
+ if (change != KVM_MR_DELETE && change != KVM_MR_FLAGS_ONLY) {
+ /*
+ * A few sanity checks. The memory in userland is ok to be
+ * fragmented into various different vmas. It is okay to mmap()
+ * and munmap() stuff in this slot after doing this call at any
+ * time.
+ */
+ if (new->userspace_addr & ~PAGE_MASK)
+ return -EINVAL;
+ if ((new->base_gfn + new->npages) * PAGE_SIZE > kvm->arch.mem_limit)
+ return -EINVAL;
+ if (!asce_contains_gfn(kvm->arch.gmap->asce, new->base_gfn + new->npages - 1))
+ return -EINVAL;
+ }
+
+ if (!kvm_s390_is_migration_mode(kvm))
+ return 0;
+
+ /*
+ * Turn off migration mode when:
+ * - userspace creates a new memslot with dirty logging off,
+ * - userspace modifies an existing memslot (MOVE or FLAGS_ONLY) and
+ * dirty logging is turned off.
+ * Migration mode expects dirty page logging being enabled to store
+ * its dirty bitmap.
+ */
+ if (change != KVM_MR_DELETE &&
+ !(new->flags & KVM_MEM_LOG_DIRTY_PAGES))
+ WARN(kvm_s390_vm_stop_migration(kvm),
+ "Failed to stop migration mode");
+
+ return 0;
+}
+
+void gmap_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 = NULL;
+ int rc = 0;
+
+ if (change == KVM_MR_FLAGS_ONLY)
+ return;
+
+ mc = kvm_s390_new_mmu_cache();
+ if (!mc) {
+ rc = -ENOMEM;
+ goto out;
+ }
+
+ scoped_guard(write_lock, &kvm->mmu_lock) {
+ switch (change) {
+ case KVM_MR_DELETE:
+ rc = dat_delete_slot(mc, kvm->arch.gmap->asce, old->base_gfn, old->npages);
+ break;
+ case KVM_MR_MOVE:
+ rc = dat_delete_slot(mc, kvm->arch.gmap->asce, old->base_gfn, old->npages);
+ if (rc)
+ break;
+ fallthrough;
+ case KVM_MR_CREATE:
+ rc = dat_create_slot(mc, kvm->arch.gmap->asce, new->base_gfn, new->npages);
+ break;
+ case KVM_MR_FLAGS_ONLY:
+ break;
+ default:
+ WARN(1, "Unknown KVM MR CHANGE: %d\n", change);
+ }
+ }
+out:
+ if (rc)
+ pr_warn("failed to commit memory region\n");
+ kvm_s390_free_mmu_cache(mc);
+}
+
+/**
+ * gmap_test_age_gfn() - test young
+ * @kvm: the kvm instance
+ * @range: the range of guest addresses whose young status needs to be cleared
+ *
+ * Context: called by KVM common code without holding the kvm mmu lock
+ * Return: true if any page in the given range is young, otherwise 0.
+ */
+bool gmap_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);
+}
+
+/**
+ * gmap_pre_fault_memory() - pre-fault and link gmap dat tables
+ * @vcpu: the vcpu that shall appear to have generated the fault-in.
+ * @range: the range that needs to be faulted in.
+ *
+ * The first page of the given range is faulted in and the corresponding gmap
+ * page tables are created, as if the given vCPU had performed a read
+ * operation.
+ * If the range starts outside any memslots, an error is returned. An error is
+ * also returned for UCONTROL VMs, which should instead use the
+ * KVM_S390_VCPU_FAULT ioctl.
+ *
+ * Return:
+ * * %-ENOENT if the range lies outside of a memslot.
+ * * %-EINVAL in case of invalid state (for example if the VM is UCONTROL).
+ * * %-EIO if errors happen while faulting-in the page (will trigger a warning
+ * in the caller).
+ * * other error codes < 0 in case of other errors.
+ * * otherwise a number > 0 of bytes that have been faulted in successfully.
+ */
+long gmap_pre_fault_memory(struct kvm_vcpu *vcpu, struct kvm_pre_fault_memory *range)
+{
+ struct guest_fault f = { .gfn = gpa_to_gfn(range->gpa), };
+ gpa_t end;
+ int rc;
+
+ if (kvm_is_ucontrol(vcpu->kvm))
+ return -EINVAL;
+
+ rc = kvm_s390_faultin_gfn(vcpu, NULL, &f);
+ if (rc == PGM_ADDRESSING)
+ return -ENOENT;
+ if (rc > 0)
+ return -EIO;
+ if (rc < 0)
+ return rc;
+
+ if (f.ptep)
+ return PAGE_SIZE;
+
+ end = ALIGN(range->gpa + PAGE_SIZE, f.crste_region3 ? _REGION3_SIZE : HPAGE_SIZE);
+ return min(range->size, end - range->gpa);
+}
diff --git a/arch/s390/kvm/s390/s390.c b/arch/s390/kvm/s390/s390.c
index 26720ffcf5db..f89bad4e9e04 100644
--- a/arch/s390/kvm/s390/s390.c
+++ b/arch/s390/kvm/s390/s390.c
@@ -746,33 +746,7 @@ static void sca_del_vcpu(struct kvm_vcpu *vcpu);
int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
struct kvm_dirty_log *log)
{
- int r;
- unsigned long n;
- struct kvm_memory_slot *memslot;
- int is_dirty;
-
- if (kvm_is_ucontrol(kvm))
- return -EINVAL;
-
- mutex_lock(&kvm->slots_lock);
-
- r = -EINVAL;
- if (log->slot >= KVM_USER_MEM_SLOTS)
- goto out;
-
- r = kvm_get_dirty_log(kvm, log, &is_dirty, &memslot);
- if (r)
- goto out;
-
- /* Clear the dirty log */
- if (is_dirty) {
- n = kvm_dirty_bitmap_bytes(memslot);
- memset(memslot->dirty_bitmap, 0, n);
- }
- r = 0;
-out:
- mutex_unlock(&kvm->slots_lock);
- return r;
+ return gmap_get_dirty_log(kvm, log);
}
static void icpt_operexc_on_all_vcpus(struct kvm *kvm)
@@ -1268,7 +1242,7 @@ static int kvm_s390_vm_start_migration(struct kvm *kvm)
* Must be called with kvm->slots_lock to avoid races with ourselves,
* kvm_s390_vm_start_migration() and kvm_s390_get_cmma_bits().
*/
-static int kvm_s390_vm_stop_migration(struct kvm *kvm)
+int kvm_s390_vm_stop_migration(struct kvm *kvm)
{
/* migration mode already disabled */
if (!kvm->arch.migration_mode)
@@ -5751,45 +5725,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
struct kvm_memory_slot *new,
enum kvm_mr_change change)
{
- if (kvm_is_ucontrol(kvm) && new && new->id < KVM_USER_MEM_SLOTS)
- return -EINVAL;
-
- /* When we are protected, we should not change the memory slots */
- if (kvm_s390_pv_get_handle(kvm))
- return -EINVAL;
-
- if (change != KVM_MR_DELETE && change != KVM_MR_FLAGS_ONLY) {
- /*
- * A few sanity checks. The memory in userland is ok to be
- * fragmented into various different vmas. It is okay to mmap()
- * and munmap() stuff in this slot after doing this call at any
- * time.
- */
- if (new->userspace_addr & ~PAGE_MASK)
- return -EINVAL;
- if ((new->base_gfn + new->npages) * PAGE_SIZE > kvm->arch.mem_limit)
- return -EINVAL;
- if (!asce_contains_gfn(kvm->arch.gmap->asce, new->base_gfn + new->npages - 1))
- return -EINVAL;
- }
-
- if (!kvm->arch.migration_mode)
- return 0;
-
- /*
- * Turn off migration mode when:
- * - userspace creates a new memslot with dirty logging off,
- * - userspace modifies an existing memslot (MOVE or FLAGS_ONLY) and
- * dirty logging is turned off.
- * Migration mode expects dirty page logging being enabled to store
- * its dirty bitmap.
- */
- if (change != KVM_MR_DELETE &&
- !(new->flags & KVM_MEM_LOG_DIRTY_PAGES))
- WARN(kvm_s390_vm_stop_migration(kvm),
- "Failed to stop migration mode");
-
- return 0;
+ return gmap_prepare_memory_region(kvm, old, new, change);
}
void kvm_arch_commit_memory_region(struct kvm *kvm,
@@ -5797,42 +5733,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
const struct kvm_memory_slot *new,
enum kvm_mr_change change)
{
- struct kvm_s390_mmu_cache *mc = NULL;
- int rc = 0;
-
- if (change == KVM_MR_FLAGS_ONLY)
- return;
-
- mc = kvm_s390_new_mmu_cache();
- if (!mc) {
- rc = -ENOMEM;
- goto out;
- }
-
- scoped_guard(write_lock, &kvm->mmu_lock) {
- switch (change) {
- case KVM_MR_DELETE:
- rc = dat_delete_slot(mc, kvm->arch.gmap->asce, old->base_gfn, old->npages);
- break;
- case KVM_MR_MOVE:
- rc = dat_delete_slot(mc, kvm->arch.gmap->asce, old->base_gfn, old->npages);
- if (rc)
- break;
- fallthrough;
- case KVM_MR_CREATE:
- rc = dat_create_slot(mc, kvm->arch.gmap->asce, new->base_gfn, new->npages);
- break;
- case KVM_MR_FLAGS_ONLY:
- break;
- default:
- WARN(1, "Unknown KVM MR CHANGE: %d\n", change);
- }
- }
-out:
- if (rc)
- pr_warn("failed to commit memory region\n");
- kvm_s390_free_mmu_cache(mc);
- return;
+ gmap_commit_memory_region(kvm, old, new, change);
}
/**
@@ -5855,28 +5756,10 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
* * other error codes < 0 in case of other errors.
* * otherwise a number > 0 of bytes that have been faulted in successfully.
*/
-long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu, struct kvm_pre_fault_memory *range)
+long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu,
+ struct kvm_pre_fault_memory *range)
{
- struct guest_fault f = { .gfn = gpa_to_gfn(range->gpa), };
- gpa_t end;
- int rc;
-
- if (kvm_is_ucontrol(vcpu->kvm))
- return -EINVAL;
-
- rc = kvm_s390_faultin_gfn(vcpu, NULL, &f);
- if (rc == PGM_ADDRESSING)
- return -ENOENT;
- if (rc > 0)
- return -EIO;
- if (rc < 0)
- return rc;
-
- if (f.ptep)
- return PAGE_SIZE;
-
- end = ALIGN(range->gpa + PAGE_SIZE, f.crste_region3 ? _REGION3_SIZE : HPAGE_SIZE);
- return min(range->size, end - range->gpa);
+ return gmap_pre_fault_memory(vcpu, range);
}
/**
@@ -5889,8 +5772,7 @@ long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu, struct kvm_pre_fault_
*/
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);
+ return gmap_test_age_gfn(kvm, range);
}
/**
diff --git a/arch/s390/kvm/s390/s390.h b/arch/s390/kvm/s390/s390.h
index e144ca2e6d5e..aa2061007230 100644
--- a/arch/s390/kvm/s390/s390.h
+++ b/arch/s390/kvm/s390/s390.h
@@ -32,6 +32,11 @@ union kvm_s390_quad {
unsigned char one;
};
+static inline bool kvm_s390_is_in_sie(struct kvm_vcpu *vcpu)
+{
+ return vcpu->arch.sie_block->prog0c & PROG_IN_SIE;
+}
+
static inline void kvm_s390_fpu_store(struct kvm_run *run)
{
fpu_stfpc(&run->s.regs.fpc);
@@ -594,6 +599,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
*
@@ -624,4 +634,10 @@ void kvm_s390_vcpu_pci_enable_interp(struct kvm *kvm);
*/
extern unsigned int diag9c_forwarding_hz;
+/*
+ * Must be called with kvm->slots_lock to avoid races with ourselves and
+ * kvm_s390_vm_start_migration.
+ */
+int kvm_s390_vm_stop_migration(struct kvm *kvm);
+
#endif
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 16/27] KVM: s390: gmap: Refactor storage key and CMMA code into separate files
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (14 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 15/27] KVM: S390: Prepare gmap for a second KVM implementation Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 17/27] KVM: s390: Refactor prefix handling into a separate file Steffen Eiden
` (10 subsequent siblings)
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
Extract storage key and CMMA functionality from the core gmap code into
dedicated compilation units This improves code organization and enables
reuse of the gmap core by other KVM implementations that don't require
s390-specific features.
The gmap core (dat.c, gmap.c, faultin.c, mmu.c) now compiles
independently without storage key or CMMA dependencies, making it
suitable for reuse by other KVM implementations. By default sk and cmma
support is compiled into gmap. If a KVM implementation wishes to not
use those features it has to define KVM_MANAGES_S390_GUEST = n prior to
including the gmap Makefile.
No functional changes.
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/s390/kvm/gmap/Makefile | 5 +
arch/s390/kvm/gmap/cmma.c | 313 ++++++++++++++++++++++
arch/s390/kvm/gmap/cmma.h | 36 +++
arch/s390/kvm/gmap/dat.c | 504 +----------------------------------
arch/s390/kvm/gmap/dat.h | 14 -
arch/s390/kvm/gmap/gmap.c | 80 +-----
arch/s390/kvm/gmap/gmap.h | 12 -
arch/s390/kvm/gmap/sk.c | 264 ++++++++++++++++++
arch/s390/kvm/gmap/sk.h | 18 ++
arch/s390/kvm/s390/gaccess.c | 1 +
arch/s390/kvm/s390/priv.c | 2 +
arch/s390/kvm/s390/s390.c | 2 +
12 files changed, 647 insertions(+), 604 deletions(-)
create mode 100644 arch/s390/kvm/gmap/cmma.c
create mode 100644 arch/s390/kvm/gmap/cmma.h
create mode 100644 arch/s390/kvm/gmap/sk.c
create mode 100644 arch/s390/kvm/gmap/sk.h
diff --git a/arch/s390/kvm/gmap/Makefile b/arch/s390/kvm/gmap/Makefile
index 140914c5c14f..a49c7e36b71c 100644
--- a/arch/s390/kvm/gmap/Makefile
+++ b/arch/s390/kvm/gmap/Makefile
@@ -2,4 +2,9 @@
GMAP ?= ../gmap
+# Enable s390-specific guest management features (storage keys and CMMA)
+KVM_MANAGES_S390_GUEST ?= y
+
kvm-y += $(GMAP)/dat.o $(GMAP)/gmap.o $(GMAP)/faultin.o $(GMAP)/mmu.o
+
+kvm-$(KVM_MANAGES_S390_GUEST) += $(GMAP)/sk.o $(GMAP)/cmma.o
diff --git a/arch/s390/kvm/gmap/cmma.c b/arch/s390/kvm/gmap/cmma.c
new file mode 100644
index 000000000000..db729327aeda
--- /dev/null
+++ b/arch/s390/kvm/gmap/cmma.c
@@ -0,0 +1,313 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/mm.h>
+#include <linux/kvm_host.h>
+#include "cmma.h"
+#include "gmap.h"
+
+int dat_perform_essa(union asce asce, gfn_t gfn, int orc, union essa_state *state, bool *dirty)
+{
+ union crste *crstep;
+ union pgste pgste;
+ union pte *ptep;
+ int res = 0;
+
+ if (dat_entry_walk(NULL, gfn, asce, 0, TABLE_TYPE_PAGE_TABLE, &crstep, &ptep)) {
+ *state = (union essa_state) { .exception = 1 };
+ return -1;
+ }
+
+ pgste = pgste_get_lock(ptep);
+
+ *state = (union essa_state) {
+ .content = (ptep->h.i << 1) + (ptep->h.i && pgste.zero),
+ .nodat = pgste.nodat,
+ .usage = pgste.usage,
+ };
+
+ switch (orc) {
+ case ESSA_GET_STATE:
+ res = -1;
+ break;
+ case ESSA_SET_STABLE:
+ pgste.usage = PGSTE_GPS_USAGE_STABLE;
+ pgste.nodat = 0;
+ break;
+ case ESSA_SET_UNUSED:
+ pgste.usage = PGSTE_GPS_USAGE_UNUSED;
+ if (ptep->h.i)
+ res = 1;
+ break;
+ case ESSA_SET_VOLATILE:
+ pgste.usage = PGSTE_GPS_USAGE_VOLATILE;
+ if (ptep->h.i)
+ res = 1;
+ break;
+ case ESSA_SET_POT_VOLATILE:
+ if (!ptep->h.i) {
+ pgste.usage = PGSTE_GPS_USAGE_POT_VOLATILE;
+ } else if (pgste.zero) {
+ pgste.usage = PGSTE_GPS_USAGE_VOLATILE;
+ } else if (!pgste.gc) {
+ pgste.usage = PGSTE_GPS_USAGE_VOLATILE;
+ res = 1;
+ }
+ break;
+ case ESSA_SET_STABLE_RESIDENT:
+ pgste.usage = PGSTE_GPS_USAGE_STABLE;
+ /*
+ * Since the resident state can go away any time after this
+ * call, we will not make this page resident. We can revisit
+ * this decision if a guest will ever start using this.
+ */
+ break;
+ case ESSA_SET_STABLE_IF_RESIDENT:
+ if (!ptep->h.i)
+ pgste.usage = PGSTE_GPS_USAGE_STABLE;
+ break;
+ case ESSA_SET_STABLE_NODAT:
+ pgste.usage = PGSTE_GPS_USAGE_STABLE;
+ pgste.nodat = 1;
+ break;
+ default:
+ WARN_ONCE(1, "Invalid ORC!");
+ res = -1;
+ break;
+ }
+ /* If we are discarding a page, set it to logical zero. */
+ pgste.zero = res == 1;
+ if (orc > 0) {
+ *dirty = !pgste.cmma_d;
+ pgste.cmma_d = 1;
+ }
+
+ pgste_set_unlock(ptep, pgste);
+
+ return res;
+}
+
+static long dat_reset_cmma_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
+{
+ union pgste pgste;
+
+ pgste = pgste_get_lock(ptep);
+ pgste.usage = 0;
+ pgste.nodat = 0;
+ pgste.cmma_d = 0;
+ pgste_set_unlock(ptep, pgste);
+ if (need_resched())
+ return next;
+ return 0;
+}
+
+long dat_reset_cmma(union asce asce, gfn_t start)
+{
+ const struct dat_walk_ops dat_reset_cmma_ops = {
+ .pte_entry = dat_reset_cmma_pte,
+ };
+
+ return _dat_walk_gfn_range(start, asce_end(asce), asce, &dat_reset_cmma_ops,
+ DAT_WALK_IGN_HOLES, NULL);
+}
+
+struct dat_get_cmma_state {
+ gfn_t start;
+ gfn_t end;
+ unsigned int count;
+ u8 *values;
+ atomic64_t *remaining;
+};
+
+static long __dat_peek_cmma_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
+{
+ struct dat_get_cmma_state *state = walk->priv;
+ union pgste pgste;
+
+ pgste = pgste_get_lock(ptep);
+ state->values[gfn - walk->start] = pgste.usage | (pgste.nodat << 6);
+ pgste_set_unlock(ptep, pgste);
+ state->end = next;
+
+ return 0;
+}
+
+static long __dat_peek_cmma_crste(union crste *crstep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
+{
+ struct dat_get_cmma_state *state = walk->priv;
+
+ if (crstep->h.i)
+ state->end = min(walk->end, next);
+ return 0;
+}
+
+int dat_peek_cmma(gfn_t start, union asce asce, unsigned int *count, u8 *values)
+{
+ const struct dat_walk_ops ops = {
+ .pte_entry = __dat_peek_cmma_pte,
+ .pmd_entry = __dat_peek_cmma_crste,
+ .pud_entry = __dat_peek_cmma_crste,
+ .p4d_entry = __dat_peek_cmma_crste,
+ .pgd_entry = __dat_peek_cmma_crste,
+ };
+ struct dat_get_cmma_state state = { .values = values, };
+ int rc;
+
+ rc = _dat_walk_gfn_range(start, start + *count, asce, &ops, DAT_WALK_DEFAULT, &state);
+ *count = state.end >= start ? state.end - start : 0;
+ /* Return success if at least one value was saved, otherwise an error. */
+ return (rc == -EFAULT && *count > 0) ? 0 : rc;
+}
+
+static long __dat_get_cmma_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
+{
+ struct dat_get_cmma_state *state = walk->priv;
+ union pgste pgste;
+
+ if (state->start != -1) {
+ if ((gfn - state->end) > KVM_S390_MAX_BIT_DISTANCE)
+ return 1;
+ if (gfn - state->start >= state->count)
+ return 1;
+ }
+
+ if (!READ_ONCE(*pgste_of(ptep)).cmma_d)
+ return 0;
+
+ pgste = pgste_get_lock(ptep);
+ if (pgste.cmma_d) {
+ if (state->start == -1)
+ state->start = gfn;
+ pgste.cmma_d = 0;
+ atomic64_dec(state->remaining);
+ state->values[gfn - state->start] = pgste.usage | pgste.nodat << 6;
+ state->end = next;
+ }
+ pgste_set_unlock(ptep, pgste);
+ return 0;
+}
+
+int dat_get_cmma(union asce asce, gfn_t *start, unsigned int *count, u8 *values, atomic64_t *rem)
+{
+ const struct dat_walk_ops ops = { .pte_entry = __dat_get_cmma_pte, };
+ struct dat_get_cmma_state state = {
+ .remaining = rem,
+ .values = values,
+ .count = *count,
+ .start = -1,
+ };
+
+ _dat_walk_gfn_range(*start, asce_end(asce), asce, &ops, DAT_WALK_IGN_HOLES, &state);
+ /* If no dirty pages were found, wrap around and continue searching */
+ if (*start && state.start == -1)
+ _dat_walk_gfn_range(0, *start, asce, &ops, DAT_WALK_IGN_HOLES, &state);
+
+ if (state.start == -1) {
+ *count = 0;
+ } else {
+ *count = state.end - state.start;
+ *start = state.start;
+ }
+
+ return 0;
+}
+
+struct dat_set_cmma_state {
+ unsigned long mask;
+ const u8 *bits;
+};
+
+static long __dat_set_cmma_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
+{
+ struct dat_set_cmma_state *state = walk->priv;
+ union pgste pgste, tmp;
+
+ tmp.val = (state->bits[gfn - walk->start] << 24) & state->mask;
+
+ pgste = pgste_get_lock(ptep);
+ pgste.usage = tmp.usage;
+ pgste.nodat = tmp.nodat;
+ pgste_set_unlock(ptep, pgste);
+
+ return 0;
+}
+
+/**
+ * dat_set_cmma_bits() - Set CMMA bits for a range of guest pages.
+ * @mc: Cache used for allocations.
+ * @asce: The ASCE of the guest.
+ * @gfn: The guest frame of the fist page whose CMMA bits are to set.
+ * @count: How many pages need to be processed.
+ * @mask: Which PGSTE bits should be set.
+ * @bits: Points to an array with the CMMA attributes.
+ *
+ * This function sets the CMMA attributes for the given pages. If the input
+ * buffer has zero length, no action is taken, otherwise the attributes are
+ * set and the mm->context.uses_cmm flag is set.
+ *
+ * Each byte in @bits contains new values for bits 32-39 of the PGSTE.
+ * Currently, only the fields NT and US are applied.
+ *
+ * Return: %0 in case of success, a negative error value otherwise.
+ */
+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)
+{
+ const struct dat_walk_ops ops = { .pte_entry = __dat_set_cmma_pte, };
+ struct dat_set_cmma_state state = { .mask = mask, .bits = bits, };
+ union crste *crstep;
+ union pte *ptep;
+ gfn_t cur;
+ int rc;
+
+ for (cur = ALIGN_DOWN(gfn, _PAGE_ENTRIES); cur < gfn + count; cur += _PAGE_ENTRIES) {
+ rc = dat_entry_walk(mc, cur, asce, DAT_WALK_ALLOC, TABLE_TYPE_PAGE_TABLE,
+ &crstep, &ptep);
+ if (rc)
+ return rc;
+ }
+ return _dat_walk_gfn_range(gfn, gfn + count, asce, &ops, DAT_WALK_IGN_HOLES, &state);
+}
+
+static long __set_cmma_clean_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
+{
+ union pgste pgste;
+
+ pgste = pgste_get_lock(ptep);
+ pgste.cmma_d = 0;
+ pgste_set_unlock(ptep, pgste);
+
+ if (need_resched())
+ return next;
+ return 0;
+}
+
+static long __set_cmma_dirty_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
+{
+ union pgste pgste;
+
+ pgste = pgste_get_lock(ptep);
+ if (!pgste.cmma_d)
+ atomic64_inc(walk->priv);
+ pgste.cmma_d = 1;
+ pgste_set_unlock(ptep, pgste);
+
+ if (need_resched())
+ return next;
+ return 0;
+}
+
+void _gmap_set_cmma_all(struct gmap *gmap, bool dirty)
+{
+ const struct dat_walk_ops ops = {
+ .pte_entry = dirty ? __set_cmma_dirty_pte : __set_cmma_clean_pte,
+ };
+ gfn_t gfn = 0;
+
+ do {
+ scoped_guard(read_lock, &gmap->kvm->mmu_lock)
+ gfn = _dat_walk_gfn_range(gfn, asce_end(gmap->asce), gmap->asce, &ops,
+ DAT_WALK_IGN_HOLES,
+ &gmap->kvm->arch.cmma_dirty_pages);
+ cond_resched();
+ } while (gfn);
+}
diff --git a/arch/s390/kvm/gmap/cmma.h b/arch/s390/kvm/gmap/cmma.h
new file mode 100644
index 000000000000..12b574ecf711
--- /dev/null
+++ b/arch/s390/kvm/gmap/cmma.h
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef ARCH_KVM_GMAP_CMMA_H
+#define ARCH_KVM_GMAP_CMMA_H
+
+#include "dat.h"
+
+#define ESSA_GET_STATE 0
+#define ESSA_SET_STABLE 1
+#define ESSA_SET_UNUSED 2
+#define ESSA_SET_VOLATILE 3
+#define ESSA_SET_POT_VOLATILE 4
+#define ESSA_SET_STABLE_RESIDENT 5
+#define ESSA_SET_STABLE_IF_RESIDENT 6
+#define ESSA_SET_STABLE_NODAT 7
+
+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);
+
+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);
+}
+
+static inline void gmap_set_cmma_all_clean(struct gmap *gmap)
+{
+ _gmap_set_cmma_all(gmap, false);
+}
+
+#endif /* ARCH_KVM_GMAP_CMMA_H */
diff --git a/arch/s390/kvm/gmap/dat.c b/arch/s390/kvm/gmap/dat.c
index 5f1960ec982d..6114ff442837 100644
--- a/arch/s390/kvm/gmap/dat.c
+++ b/arch/s390/kvm/gmap/dat.c
@@ -27,6 +27,9 @@
#include <asm/page-states.h>
#include <asm/tlb.h>
#include "dat.h"
+#include "sk.h"
+#include "cmma.h"
+
int kvm_s390_mmu_cache_topup(struct kvm_s390_mmu_cache *mc)
{
@@ -611,229 +614,6 @@ 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);
}
-int dat_get_storage_key(union asce asce, gfn_t gfn, union skey *skey)
-{
- union crste *crstep;
- union pgste pgste;
- union pte *ptep;
- int rc;
-
- skey->skey = 0;
- rc = dat_entry_walk(NULL, gfn, asce, DAT_WALK_ANY, TABLE_TYPE_PAGE_TABLE, &crstep, &ptep);
- if (rc)
- return rc;
-
- if (!ptep) {
- union crste crste;
-
- crste = READ_ONCE(*crstep);
- if (!crste.h.fc || !crste.s.fc1.pr)
- return 0;
- skey->skey = page_get_storage_key(large_crste_to_phys(crste, gfn));
- return 0;
- }
- pgste = pgste_get_lock(ptep);
- if (ptep->h.i) {
- skey->acc = pgste.acc;
- skey->fp = pgste.fp;
- } else {
- skey->skey = page_get_storage_key(pte_origin(*ptep));
- }
- skey->r |= pgste.gr;
- skey->c |= pgste.gc;
- pgste_set_unlock(ptep, pgste);
- return 0;
-}
-
-static void dat_update_ptep_sd(union pgste old, union pgste pgste, union pte *ptep)
-{
- if (pgste.acc != old.acc || pgste.fp != old.fp || pgste.gr != old.gr || pgste.gc != old.gc)
- __atomic64_or(_PAGE_SD, &ptep->val);
-}
-
-int dat_set_storage_key(struct kvm_s390_mmu_cache *mc, union asce asce, gfn_t gfn,
- union skey skey, bool nq)
-{
- union pgste pgste, old;
- union crste *crstep;
- union pte *ptep;
- int rc;
-
- rc = dat_entry_walk(mc, gfn, asce, DAT_WALK_LEAF_ALLOC, TABLE_TYPE_PAGE_TABLE,
- &crstep, &ptep);
- if (rc)
- return rc;
-
- if (!ptep) {
- page_set_storage_key(large_crste_to_phys(*crstep, gfn), skey.skey, !nq);
- return 0;
- }
-
- old = pgste_get_lock(ptep);
- pgste = old;
-
- pgste.acc = skey.acc;
- pgste.fp = skey.fp;
- pgste.gc = skey.c;
- pgste.gr = skey.r;
-
- if (!ptep->h.i) {
- union skey old_skey;
-
- old_skey.skey = page_get_storage_key(pte_origin(*ptep));
- pgste.hc |= old_skey.c;
- pgste.hr |= old_skey.r;
- old_skey.c = old.gc;
- old_skey.r = old.gr;
- skey.r = 0;
- skey.c = 0;
- page_set_storage_key(pte_origin(*ptep), skey.skey, !nq);
- }
-
- dat_update_ptep_sd(old, pgste, ptep);
- pgste_set_unlock(ptep, pgste);
- return 0;
-}
-
-static bool page_cond_set_storage_key(phys_addr_t paddr, union skey skey, union skey *oldkey,
- bool nq, bool mr, bool mc)
-{
- oldkey->skey = page_get_storage_key(paddr);
- if (oldkey->acc == skey.acc && oldkey->fp == skey.fp &&
- (oldkey->r == skey.r || mr) && (oldkey->c == skey.c || mc))
- return false;
- page_set_storage_key(paddr, skey.skey, !nq);
- return true;
-}
-
-int dat_cond_set_storage_key(struct kvm_s390_mmu_cache *mmc, union asce asce, gfn_t gfn,
- union skey skey, union skey *oldkey, bool nq, bool mr, bool mc)
-{
- union pgste pgste, old;
- union crste *crstep;
- union skey prev;
- union pte *ptep;
- int rc;
-
- rc = dat_entry_walk(mmc, gfn, asce, DAT_WALK_LEAF_ALLOC, TABLE_TYPE_PAGE_TABLE,
- &crstep, &ptep);
- if (rc)
- return rc;
-
- if (!ptep)
- return page_cond_set_storage_key(large_crste_to_phys(*crstep, gfn), skey, oldkey,
- nq, mr, mc);
-
- old = pgste_get_lock(ptep);
- pgste = old;
-
- rc = 1;
- pgste.acc = skey.acc;
- pgste.fp = skey.fp;
- pgste.gc = skey.c;
- pgste.gr = skey.r;
-
- if (!ptep->h.i) {
- rc = page_cond_set_storage_key(pte_origin(*ptep), skey, &prev, nq, mr, mc);
- pgste.hc |= prev.c;
- pgste.hr |= prev.r;
- prev.c |= old.gc;
- prev.r |= old.gr;
- } else {
- prev.acc = old.acc;
- prev.fp = old.fp;
- prev.c = old.gc;
- prev.r = old.gr;
- }
- if (oldkey)
- *oldkey = prev;
-
- dat_update_ptep_sd(old, pgste, ptep);
- pgste_set_unlock(ptep, pgste);
- return rc;
-}
-
-int dat_reset_reference_bit(union asce asce, gfn_t gfn)
-{
- union pgste pgste, old;
- union crste *crstep;
- union pte *ptep;
- int rc;
-
- rc = dat_entry_walk(NULL, gfn, asce, DAT_WALK_ANY, TABLE_TYPE_PAGE_TABLE, &crstep, &ptep);
- if (rc)
- return rc;
-
- if (!ptep) {
- union crste crste = READ_ONCE(*crstep);
-
- if (!crste.h.fc || !crste.s.fc1.pr)
- return 0;
- return page_reset_referenced(large_crste_to_phys(*crstep, gfn));
- }
- old = pgste_get_lock(ptep);
- pgste = old;
-
- if (!ptep->h.i) {
- rc = page_reset_referenced(pte_origin(*ptep));
- pgste.hr = rc >> 1;
- }
- rc |= (pgste.gr << 1) | pgste.gc;
- pgste.gr = 0;
-
- dat_update_ptep_sd(old, pgste, ptep);
- pgste_set_unlock(ptep, pgste);
- return rc;
-}
-
-static long dat_reset_skeys_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
-{
- union pgste pgste;
-
- pgste = pgste_get_lock(ptep);
- pgste.acc = 0;
- pgste.fp = 0;
- pgste.gr = 0;
- pgste.gc = 0;
- if (ptep->s.pr)
- page_set_storage_key(pte_origin(*ptep), PAGE_DEFAULT_KEY, 1);
- pgste_set_unlock(ptep, pgste);
-
- if (need_resched())
- return next;
- return 0;
-}
-
-static long dat_reset_skeys_crste(union crste *crstep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
-{
- phys_addr_t addr, end, origin = crste_origin_large(*crstep);
-
- if (!crstep->h.fc || !crstep->s.fc1.pr)
- return 0;
-
- addr = ((max(gfn, walk->start) - gfn) << PAGE_SHIFT) + origin;
- end = ((min(next, walk->end) - gfn) << PAGE_SHIFT) + origin;
- while (ALIGN(addr + 1, _SEGMENT_SIZE) <= end)
- addr = sske_frame(addr, PAGE_DEFAULT_KEY);
- for ( ; addr < end; addr += PAGE_SIZE)
- page_set_storage_key(addr, PAGE_DEFAULT_KEY, 1);
-
- if (need_resched())
- return next;
- return 0;
-}
-
-long dat_reset_skeys(union asce asce, gfn_t start)
-{
- const struct dat_walk_ops ops = {
- .pte_entry = dat_reset_skeys_pte,
- .pmd_entry = dat_reset_skeys_crste,
- .pud_entry = dat_reset_skeys_crste,
- };
-
- return _dat_walk_gfn_range(start, asce_end(asce), asce, &ops, DAT_WALK_IGN_HOLES, NULL);
-}
-
struct slot_priv {
unsigned long token;
struct kvm_s390_mmu_cache *mc;
@@ -1045,281 +825,3 @@ int dat_set_prefix_notif_bit(union asce asce, gfn_t gfn)
return -EAGAIN;
return 0;
}
-
-/**
- * dat_perform_essa() - Perform ESSA actions on the PGSTE.
- * @asce: The asce to operate on.
- * @gfn: The guest page frame to operate on.
- * @orc: The specific action to perform, see the ESSA_SET_* macros.
- * @state: The storage attributes to be returned to the guest.
- * @dirty: Returns whether the function dirtied a previously clean entry.
- *
- * Context: Called with kvm->mmu_lock held.
- *
- * Return:
- * * %1 if the page state has been altered and the page is to be added to the CBRL
- * * %0 if the page state has been altered, but the page is not to be added to the CBRL
- * * %-1 if the page state has not been altered and the page is not to be added to the CBRL
- */
-int dat_perform_essa(union asce asce, gfn_t gfn, int orc, union essa_state *state, bool *dirty)
-{
- union crste *crstep;
- union pgste pgste;
- union pte *ptep;
- int res = 0;
-
- if (dat_entry_walk(NULL, gfn, asce, 0, TABLE_TYPE_PAGE_TABLE, &crstep, &ptep)) {
- *state = (union essa_state) { .exception = 1 };
- return -1;
- }
-
- pgste = pgste_get_lock(ptep);
-
- *state = (union essa_state) {
- .content = (ptep->h.i << 1) + (ptep->h.i && pgste.zero),
- .nodat = pgste.nodat,
- .usage = pgste.usage,
- };
-
- switch (orc) {
- case ESSA_GET_STATE:
- res = -1;
- break;
- case ESSA_SET_STABLE:
- pgste.usage = PGSTE_GPS_USAGE_STABLE;
- pgste.nodat = 0;
- break;
- case ESSA_SET_UNUSED:
- pgste.usage = PGSTE_GPS_USAGE_UNUSED;
- if (ptep->h.i)
- res = 1;
- break;
- case ESSA_SET_VOLATILE:
- pgste.usage = PGSTE_GPS_USAGE_VOLATILE;
- if (ptep->h.i)
- res = 1;
- break;
- case ESSA_SET_POT_VOLATILE:
- if (!ptep->h.i) {
- pgste.usage = PGSTE_GPS_USAGE_POT_VOLATILE;
- } else if (pgste.zero) {
- pgste.usage = PGSTE_GPS_USAGE_VOLATILE;
- } else if (!pgste.gc) {
- pgste.usage = PGSTE_GPS_USAGE_VOLATILE;
- res = 1;
- }
- break;
- case ESSA_SET_STABLE_RESIDENT:
- pgste.usage = PGSTE_GPS_USAGE_STABLE;
- /*
- * Since the resident state can go away any time after this
- * call, we will not make this page resident. We can revisit
- * this decision if a guest will ever start using this.
- */
- break;
- case ESSA_SET_STABLE_IF_RESIDENT:
- if (!ptep->h.i)
- pgste.usage = PGSTE_GPS_USAGE_STABLE;
- break;
- case ESSA_SET_STABLE_NODAT:
- pgste.usage = PGSTE_GPS_USAGE_STABLE;
- pgste.nodat = 1;
- break;
- default:
- WARN_ONCE(1, "Invalid ORC!");
- res = -1;
- break;
- }
- /* If we are discarding a page, set it to logical zero. */
- pgste.zero = res == 1;
- if (orc > 0) {
- *dirty = !pgste.cmma_d;
- pgste.cmma_d = 1;
- }
-
- pgste_set_unlock(ptep, pgste);
-
- return res;
-}
-
-static long dat_reset_cmma_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
-{
- union pgste pgste;
-
- pgste = pgste_get_lock(ptep);
- pgste.usage = 0;
- pgste.nodat = 0;
- pgste.cmma_d = 0;
- pgste_set_unlock(ptep, pgste);
- if (need_resched())
- return next;
- return 0;
-}
-
-long dat_reset_cmma(union asce asce, gfn_t start)
-{
- const struct dat_walk_ops dat_reset_cmma_ops = {
- .pte_entry = dat_reset_cmma_pte,
- };
-
- return _dat_walk_gfn_range(start, asce_end(asce), asce, &dat_reset_cmma_ops,
- DAT_WALK_IGN_HOLES, NULL);
-}
-
-struct dat_get_cmma_state {
- gfn_t start;
- gfn_t end;
- unsigned int count;
- u8 *values;
- atomic64_t *remaining;
-};
-
-static long __dat_peek_cmma_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
-{
- struct dat_get_cmma_state *state = walk->priv;
- union pgste pgste;
-
- pgste = pgste_get_lock(ptep);
- state->values[gfn - walk->start] = pgste.usage | (pgste.nodat << 6);
- pgste_set_unlock(ptep, pgste);
- state->end = next;
-
- return 0;
-}
-
-static long __dat_peek_cmma_crste(union crste *crstep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
-{
- struct dat_get_cmma_state *state = walk->priv;
-
- if (crstep->h.i)
- state->end = min(walk->end, next);
- return 0;
-}
-
-int dat_peek_cmma(gfn_t start, union asce asce, unsigned int *count, u8 *values)
-{
- const struct dat_walk_ops ops = {
- .pte_entry = __dat_peek_cmma_pte,
- .pmd_entry = __dat_peek_cmma_crste,
- .pud_entry = __dat_peek_cmma_crste,
- .p4d_entry = __dat_peek_cmma_crste,
- .pgd_entry = __dat_peek_cmma_crste,
- };
- struct dat_get_cmma_state state = { .values = values, };
- int rc;
-
- rc = _dat_walk_gfn_range(start, start + *count, asce, &ops, DAT_WALK_DEFAULT, &state);
- *count = state.end >= start ? state.end - start : 0;
- /* Return success if at least one value was saved, otherwise an error. */
- return (rc == -EFAULT && *count > 0) ? 0 : rc;
-}
-
-static long __dat_get_cmma_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
-{
- struct dat_get_cmma_state *state = walk->priv;
- union pgste pgste;
-
- if (state->start != -1) {
- if ((gfn - state->end) > KVM_S390_MAX_BIT_DISTANCE)
- return 1;
- if (gfn - state->start >= state->count)
- return 1;
- }
-
- if (!READ_ONCE(*pgste_of(ptep)).cmma_d)
- return 0;
-
- pgste = pgste_get_lock(ptep);
- if (pgste.cmma_d) {
- if (state->start == -1)
- state->start = gfn;
- pgste.cmma_d = 0;
- atomic64_dec(state->remaining);
- state->values[gfn - state->start] = pgste.usage | pgste.nodat << 6;
- state->end = next;
- }
- pgste_set_unlock(ptep, pgste);
- return 0;
-}
-
-int dat_get_cmma(union asce asce, gfn_t *start, unsigned int *count, u8 *values, atomic64_t *rem)
-{
- const struct dat_walk_ops ops = { .pte_entry = __dat_get_cmma_pte, };
- struct dat_get_cmma_state state = {
- .remaining = rem,
- .values = values,
- .count = *count,
- .start = -1,
- };
-
- _dat_walk_gfn_range(*start, asce_end(asce), asce, &ops, DAT_WALK_IGN_HOLES, &state);
- /* If no dirty pages were found, wrap around and continue searching */
- if (*start && state.start == -1)
- _dat_walk_gfn_range(0, *start, asce, &ops, DAT_WALK_IGN_HOLES, &state);
-
- if (state.start == -1) {
- *count = 0;
- } else {
- *count = state.end - state.start;
- *start = state.start;
- }
-
- return 0;
-}
-
-struct dat_set_cmma_state {
- unsigned long mask;
- const u8 *bits;
-};
-
-static long __dat_set_cmma_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
-{
- struct dat_set_cmma_state *state = walk->priv;
- union pgste pgste, tmp;
-
- tmp.val = (state->bits[gfn - walk->start] << 24) & state->mask;
-
- pgste = pgste_get_lock(ptep);
- pgste.usage = tmp.usage;
- pgste.nodat = tmp.nodat;
- pgste_set_unlock(ptep, pgste);
-
- return 0;
-}
-
-/**
- * dat_set_cmma_bits() - Set CMMA bits for a range of guest pages.
- * @mc: Cache used for allocations.
- * @asce: The ASCE of the guest.
- * @gfn: The guest frame of the fist page whose CMMA bits are to set.
- * @count: How many pages need to be processed.
- * @mask: Which PGSTE bits should be set.
- * @bits: Points to an array with the CMMA attributes.
- *
- * This function sets the CMMA attributes for the given pages. If the input
- * buffer has zero length, no action is taken, otherwise the attributes are
- * set and the mm->context.uses_cmm flag is set.
- *
- * Each byte in @bits contains new values for bits 32-39 of the PGSTE.
- * Currently, only the fields NT and US are applied.
- *
- * Return: %0 in case of success, a negative error value otherwise.
- */
-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)
-{
- const struct dat_walk_ops ops = { .pte_entry = __dat_set_cmma_pte, };
- struct dat_set_cmma_state state = { .mask = mask, .bits = bits, };
- union crste *crstep;
- union pte *ptep;
- gfn_t cur;
- int rc;
-
- for (cur = ALIGN_DOWN(gfn, _PAGE_ENTRIES); cur < gfn + count; cur += _PAGE_ENTRIES) {
- rc = dat_entry_walk(mc, cur, asce, DAT_WALK_ALLOC, TABLE_TYPE_PAGE_TABLE,
- &crstep, &ptep);
- if (rc)
- return rc;
- }
- return _dat_walk_gfn_range(gfn, gfn + count, asce, &ops, DAT_WALK_IGN_HOLES, &state);
-}
diff --git a/arch/s390/kvm/gmap/dat.h b/arch/s390/kvm/gmap/dat.h
index 711ae2f96107..12153a74815f 100644
--- a/arch/s390/kvm/gmap/dat.h
+++ b/arch/s390/kvm/gmap/dat.h
@@ -532,13 +532,6 @@ 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);
-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);
-int dat_cond_set_storage_key(struct kvm_s390_mmu_cache *mmc, union asce asce, gfn_t gfn,
- union skey skey, union skey *oldkey, bool nq, bool mr, bool mc);
-int dat_reset_reference_bit(union asce asce, gfn_t gfn);
-long dat_reset_skeys(union asce asce, gfn_t start);
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);
@@ -548,13 +541,6 @@ 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);
-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);
-
int kvm_s390_mmu_cache_topup(struct kvm_s390_mmu_cache *mc);
#define GFP_KVM_S390_MMU_CACHE (GFP_ATOMIC | __GFP_ACCOUNT | __GFP_NOWARN)
diff --git a/arch/s390/kvm/gmap/gmap.c b/arch/s390/kvm/gmap/gmap.c
index a04e0a4355a0..4ade7794e990 100644
--- a/arch/s390/kvm/gmap/gmap.c
+++ b/arch/s390/kvm/gmap/gmap.c
@@ -20,6 +20,9 @@
#include <asm/gmap_helpers.h>
#include "dat.h"
+#include "sk.h"
+#include "cmma.h"
+
#include "gmap.h"
#include "s390.h"
#include "faultin.h"
@@ -940,39 +943,6 @@ void gmap_split_huge_pages(struct gmap *gmap)
} while (start);
}
-static int _gmap_enable_skeys(struct gmap *gmap)
-{
- gfn_t start = 0;
- int rc;
-
- if (uses_skeys(gmap))
- return 0;
-
- set_bit(GMAP_FLAG_USES_SKEYS, &gmap->flags);
- rc = gmap_helper_disable_cow_sharing();
- if (rc) {
- clear_bit(GMAP_FLAG_USES_SKEYS, &gmap->flags);
- return rc;
- }
-
- do {
- scoped_guard(write_lock, &gmap->kvm->mmu_lock)
- start = dat_reset_skeys(gmap->asce, start);
- cond_resched();
- } while (start);
- return 0;
-}
-
-int gmap_enable_skeys(struct gmap *gmap)
-{
- int rc;
-
- mmap_write_lock(gmap->kvm->mm);
- rc = _gmap_enable_skeys(gmap);
- mmap_write_unlock(gmap->kvm->mm);
- return rc;
-}
-
static long _destroy_pages_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
{
if (!ptep->s.pr)
@@ -1093,50 +1063,6 @@ int gmap_protect_rmap(struct kvm_s390_mmu_cache *mc, struct gmap *sg, gfn_t p_gf
return 0;
}
-static long __set_cmma_clean_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
-{
- union pgste pgste;
-
- pgste = pgste_get_lock(ptep);
- pgste.cmma_d = 0;
- pgste_set_unlock(ptep, pgste);
-
- if (need_resched())
- return next;
- return 0;
-}
-
-static long __set_cmma_dirty_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
-{
- union pgste pgste;
-
- pgste = pgste_get_lock(ptep);
- if (!pgste.cmma_d)
- atomic64_inc(walk->priv);
- pgste.cmma_d = 1;
- pgste_set_unlock(ptep, pgste);
-
- if (need_resched())
- return next;
- return 0;
-}
-
-void _gmap_set_cmma_all(struct gmap *gmap, bool dirty)
-{
- const struct dat_walk_ops ops = {
- .pte_entry = dirty ? __set_cmma_dirty_pte : __set_cmma_clean_pte,
- };
- gfn_t gfn = 0;
-
- do {
- scoped_guard(read_lock, &gmap->kvm->mmu_lock)
- gfn = _dat_walk_gfn_range(gfn, asce_end(gmap->asce), gmap->asce, &ops,
- DAT_WALK_IGN_HOLES,
- &gmap->kvm->arch.cmma_dirty_pages);
- cond_resched();
- } while (gfn);
-}
-
static void gmap_unshadow_level(struct gmap *sg, gfn_t r_gfn, int level)
{
unsigned long align = PAGE_SIZE;
diff --git a/arch/s390/kvm/gmap/gmap.h b/arch/s390/kvm/gmap/gmap.h
index 4ab7208f50ff..aa65fe724fdb 100644
--- a/arch/s390/kvm/gmap/gmap.h
+++ b/arch/s390/kvm/gmap/gmap.h
@@ -100,13 +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);
-int gmap_enable_skeys(struct gmap *gmap);
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);
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);
@@ -200,16 +198,6 @@ static inline bool pte_needs_unshadow(union pte oldpte, union pte newpte, union
return !newpte.h.p || !newpte.s.pr;
}
-static inline void gmap_set_cmma_all_dirty(struct gmap *gmap)
-{
- _gmap_set_cmma_all(gmap, true);
-}
-
-static inline void gmap_set_cmma_all_clean(struct gmap *gmap)
-{
- _gmap_set_cmma_all(gmap, false);
-}
-
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)
{
diff --git a/arch/s390/kvm/gmap/sk.c b/arch/s390/kvm/gmap/sk.c
new file mode 100644
index 000000000000..eedd6eef6709
--- /dev/null
+++ b/arch/s390/kvm/gmap/sk.c
@@ -0,0 +1,264 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/mm.h>
+#include <linux/kvm_host.h>
+#include <linux/pgalloc.h>
+#include <asm/gmap_helpers.h>
+#include "sk.h"
+#include "gmap.h"
+
+static void dat_update_ptep_sd(union pgste old, union pgste pgste, union pte *ptep)
+{
+ if (pgste.acc != old.acc || pgste.fp != old.fp || pgste.gr != old.gr || pgste.gc != old.gc)
+ __atomic64_or(_PAGE_SD, &ptep->val);
+}
+
+int dat_get_storage_key(union asce asce, gfn_t gfn, union skey *skey)
+{
+ union crste *crstep;
+ union pgste pgste;
+ union pte *ptep;
+ int rc;
+
+ skey->skey = 0;
+ rc = dat_entry_walk(NULL, gfn, asce, DAT_WALK_ANY, TABLE_TYPE_PAGE_TABLE, &crstep, &ptep);
+ if (rc)
+ return rc;
+
+ if (!ptep) {
+ union crste crste;
+
+ crste = READ_ONCE(*crstep);
+ if (!crste.h.fc || !crste.s.fc1.pr)
+ return 0;
+ skey->skey = page_get_storage_key(large_crste_to_phys(crste, gfn));
+ return 0;
+ }
+ pgste = pgste_get_lock(ptep);
+ if (ptep->h.i) {
+ skey->acc = pgste.acc;
+ skey->fp = pgste.fp;
+ } else {
+ skey->skey = page_get_storage_key(pte_origin(*ptep));
+ }
+ skey->r |= pgste.gr;
+ skey->c |= pgste.gc;
+ pgste_set_unlock(ptep, pgste);
+ return 0;
+}
+
+int dat_set_storage_key(struct kvm_s390_mmu_cache *mc, union asce asce, gfn_t gfn,
+ union skey skey, bool nq)
+{
+ union pgste pgste, old;
+ union crste *crstep;
+ union pte *ptep;
+ int rc;
+
+ rc = dat_entry_walk(mc, gfn, asce, DAT_WALK_LEAF_ALLOC, TABLE_TYPE_PAGE_TABLE,
+ &crstep, &ptep);
+ if (rc)
+ return rc;
+
+ if (!ptep) {
+ page_set_storage_key(large_crste_to_phys(*crstep, gfn), skey.skey, !nq);
+ return 0;
+ }
+
+ old = pgste_get_lock(ptep);
+ pgste = old;
+
+ pgste.acc = skey.acc;
+ pgste.fp = skey.fp;
+ pgste.gc = skey.c;
+ pgste.gr = skey.r;
+
+ if (!ptep->h.i) {
+ union skey old_skey;
+
+ old_skey.skey = page_get_storage_key(pte_origin(*ptep));
+ pgste.hc |= old_skey.c;
+ pgste.hr |= old_skey.r;
+ old_skey.c = old.gc;
+ old_skey.r = old.gr;
+ skey.r = 0;
+ skey.c = 0;
+ page_set_storage_key(pte_origin(*ptep), skey.skey, !nq);
+ }
+
+ dat_update_ptep_sd(old, pgste, ptep);
+ pgste_set_unlock(ptep, pgste);
+ return 0;
+}
+
+static bool page_cond_set_storage_key(phys_addr_t paddr, union skey skey, union skey *oldkey,
+ bool nq, bool mr, bool mc)
+{
+ oldkey->skey = page_get_storage_key(paddr);
+ if (oldkey->acc == skey.acc && oldkey->fp == skey.fp &&
+ (oldkey->r == skey.r || mr) && (oldkey->c == skey.c || mc))
+ return false;
+ page_set_storage_key(paddr, skey.skey, !nq);
+ return true;
+}
+
+int dat_cond_set_storage_key(struct kvm_s390_mmu_cache *mmc, union asce asce, gfn_t gfn,
+ union skey skey, union skey *oldkey, bool nq, bool mr, bool mc)
+{
+ union pgste pgste, old;
+ union crste *crstep;
+ union skey prev;
+ union pte *ptep;
+ int rc;
+
+ rc = dat_entry_walk(mmc, gfn, asce, DAT_WALK_LEAF_ALLOC, TABLE_TYPE_PAGE_TABLE,
+ &crstep, &ptep);
+ if (rc)
+ return rc;
+
+ if (!ptep)
+ return page_cond_set_storage_key(large_crste_to_phys(*crstep, gfn), skey, oldkey,
+ nq, mr, mc);
+
+ old = pgste_get_lock(ptep);
+ pgste = old;
+
+ rc = 1;
+ pgste.acc = skey.acc;
+ pgste.fp = skey.fp;
+ pgste.gc = skey.c;
+ pgste.gr = skey.r;
+
+ if (!ptep->h.i) {
+ rc = page_cond_set_storage_key(pte_origin(*ptep), skey, &prev, nq, mr, mc);
+ pgste.hc |= prev.c;
+ pgste.hr |= prev.r;
+ prev.c |= old.gc;
+ prev.r |= old.gr;
+ } else {
+ prev.acc = old.acc;
+ prev.fp = old.fp;
+ prev.c = old.gc;
+ prev.r = old.gr;
+ }
+ if (oldkey)
+ *oldkey = prev;
+
+ dat_update_ptep_sd(old, pgste, ptep);
+ pgste_set_unlock(ptep, pgste);
+ return rc;
+}
+
+int dat_reset_reference_bit(union asce asce, gfn_t gfn)
+{
+ union pgste pgste, old;
+ union crste *crstep;
+ union pte *ptep;
+ int rc;
+
+ rc = dat_entry_walk(NULL, gfn, asce, DAT_WALK_ANY, TABLE_TYPE_PAGE_TABLE, &crstep, &ptep);
+ if (rc)
+ return rc;
+
+ if (!ptep) {
+ union crste crste = READ_ONCE(*crstep);
+
+ if (!crste.h.fc || !crste.s.fc1.pr)
+ return 0;
+ return page_reset_referenced(large_crste_to_phys(*crstep, gfn));
+ }
+ old = pgste_get_lock(ptep);
+ pgste = old;
+
+ if (!ptep->h.i) {
+ rc = page_reset_referenced(pte_origin(*ptep));
+ pgste.hr = rc >> 1;
+ }
+ rc |= (pgste.gr << 1) | pgste.gc;
+ pgste.gr = 0;
+
+ dat_update_ptep_sd(old, pgste, ptep);
+ pgste_set_unlock(ptep, pgste);
+ return rc;
+}
+
+static long dat_reset_skeys_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
+{
+ union pgste pgste;
+
+ pgste = pgste_get_lock(ptep);
+ pgste.acc = 0;
+ pgste.fp = 0;
+ pgste.gr = 0;
+ pgste.gc = 0;
+ if (ptep->s.pr)
+ page_set_storage_key(pte_origin(*ptep), PAGE_DEFAULT_KEY, 1);
+ pgste_set_unlock(ptep, pgste);
+
+ if (need_resched())
+ return next;
+ return 0;
+}
+
+static long dat_reset_skeys_crste(union crste *crstep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
+{
+ phys_addr_t addr, end, origin = crste_origin_large(*crstep);
+
+ if (!crstep->h.fc || !crstep->s.fc1.pr)
+ return 0;
+
+ addr = ((max(gfn, walk->start) - gfn) << PAGE_SHIFT) + origin;
+ end = ((min(next, walk->end) - gfn) << PAGE_SHIFT) + origin;
+ while (ALIGN(addr + 1, _SEGMENT_SIZE) <= end)
+ addr = sske_frame(addr, PAGE_DEFAULT_KEY);
+ for ( ; addr < end; addr += PAGE_SIZE)
+ page_set_storage_key(addr, PAGE_DEFAULT_KEY, 1);
+
+ if (need_resched())
+ return next;
+ return 0;
+}
+
+long dat_reset_skeys(union asce asce, gfn_t start)
+{
+ const struct dat_walk_ops ops = {
+ .pte_entry = dat_reset_skeys_pte,
+ .pmd_entry = dat_reset_skeys_crste,
+ .pud_entry = dat_reset_skeys_crste,
+ };
+
+ return _dat_walk_gfn_range(start, asce_end(asce), asce, &ops, DAT_WALK_IGN_HOLES, NULL);
+}
+
+static int _gmap_enable_skeys(struct gmap *gmap)
+{
+ gfn_t start = 0;
+ int rc;
+
+ if (uses_skeys(gmap))
+ return 0;
+
+ set_bit(GMAP_FLAG_USES_SKEYS, &gmap->flags);
+ rc = gmap_helper_disable_cow_sharing();
+ if (rc) {
+ clear_bit(GMAP_FLAG_USES_SKEYS, &gmap->flags);
+ return rc;
+ }
+
+ do {
+ scoped_guard(write_lock, &gmap->kvm->mmu_lock)
+ start = dat_reset_skeys(gmap->asce, start);
+ cond_resched();
+ } while (start);
+ return 0;
+}
+
+int gmap_enable_skeys(struct gmap *gmap)
+{
+ int rc;
+
+ mmap_write_lock(gmap->kvm->mm);
+ rc = _gmap_enable_skeys(gmap);
+ mmap_write_unlock(gmap->kvm->mm);
+ return rc;
+}
diff --git a/arch/s390/kvm/gmap/sk.h b/arch/s390/kvm/gmap/sk.h
new file mode 100644
index 000000000000..113ff8d0b0ab
--- /dev/null
+++ b/arch/s390/kvm/gmap/sk.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef ARCH_KVM_GMAP_SK_H
+#define ARCH_KVM_GMAP_SK_H
+
+#include "dat.h"
+
+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);
+int dat_cond_set_storage_key(struct kvm_s390_mmu_cache *mmc, union asce asce, gfn_t gfn,
+ union skey skey, union skey *oldkey, bool nq, bool mr, bool mc);
+int dat_reset_reference_bit(union asce asce, gfn_t gfn);
+long dat_reset_skeys(union asce asce, gfn_t start);
+
+int gmap_enable_skeys(struct gmap *gmap);
+
+#endif /* ARCH_KVM_GMAP_SK_H */
diff --git a/arch/s390/kvm/s390/gaccess.c b/arch/s390/kvm/s390/gaccess.c
index 2a4b2525329a..2d82c9317597 100644
--- a/arch/s390/kvm/s390/gaccess.c
+++ b/arch/s390/kvm/s390/gaccess.c
@@ -20,6 +20,7 @@
#include "s390.h"
#include "dat.h"
#include "gmap.h"
+#include "sk.h"
#include "gaccess.h"
#include "faultin.h"
diff --git a/arch/s390/kvm/s390/priv.c b/arch/s390/kvm/s390/priv.c
index 21479f0a5e5a..9bd3c07285ba 100644
--- a/arch/s390/kvm/s390/priv.c
+++ b/arch/s390/kvm/s390/priv.c
@@ -29,6 +29,8 @@
#include "s390.h"
#include "trace.h"
#include "gmap.h"
+#include "sk.h"
+#include "cmma.h"
static int handle_ri(struct kvm_vcpu *vcpu)
{
diff --git a/arch/s390/kvm/s390/s390.c b/arch/s390/kvm/s390/s390.c
index f89bad4e9e04..30c273f5377e 100644
--- a/arch/s390/kvm/s390/s390.c
+++ b/arch/s390/kvm/s390/s390.c
@@ -55,6 +55,8 @@
#include "gmap.h"
#include "faultin.h"
#include "pci.h"
+#include "sk.h"
+#include "cmma.h"
#define CREATE_TRACE_POINTS
#include "trace.h"
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 17/27] KVM: s390: Refactor prefix handling into a separate file
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (15 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 16/27] KVM: s390: gmap: Refactor storage key and CMMA code into separate files Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 18/27] KVM: s390: Prepare kvm-s390 for a second kvm module Steffen Eiden
` (9 subsequent siblings)
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
Split prefix page tracking into prefix.c/h with conditional compilation
via prefix-stubs.c for KVM for non-s390 guests. Enables gmap reuse by
other KVM implementations that don't use prefix pages. The prefix
tracking is conditional on the Makefile variable KVM_MANAGES_S390_GUEST.
No functional changes.
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/s390/kvm/gmap/Makefile | 4 +-
arch/s390/kvm/gmap/dat.c | 48 -------------------
arch/s390/kvm/gmap/gmap.c | 23 ---------
arch/s390/kvm/gmap/gmap.h | 11 +----
arch/s390/kvm/gmap/prefix-stubs.c | 21 ++++++++
arch/s390/kvm/gmap/prefix.c | 80 +++++++++++++++++++++++++++++++
arch/s390/kvm/gmap/prefix.h | 68 ++++++++++++++++++++++++++
7 files changed, 173 insertions(+), 82 deletions(-)
create mode 100644 arch/s390/kvm/gmap/prefix-stubs.c
create mode 100644 arch/s390/kvm/gmap/prefix.c
create mode 100644 arch/s390/kvm/gmap/prefix.h
diff --git a/arch/s390/kvm/gmap/Makefile b/arch/s390/kvm/gmap/Makefile
index a49c7e36b71c..4ca7635d1d0e 100644
--- a/arch/s390/kvm/gmap/Makefile
+++ b/arch/s390/kvm/gmap/Makefile
@@ -4,7 +4,9 @@ GMAP ?= ../gmap
# Enable s390-specific guest management features (storage keys and CMMA)
KVM_MANAGES_S390_GUEST ?= y
+USE_PREFIX_STUB := $(if $(filter y,$(KVM_MANAGES_S390_GUEST)),n,y)
kvm-y += $(GMAP)/dat.o $(GMAP)/gmap.o $(GMAP)/faultin.o $(GMAP)/mmu.o
-kvm-$(KVM_MANAGES_S390_GUEST) += $(GMAP)/sk.o $(GMAP)/cmma.o
+kvm-$(KVM_MANAGES_S390_GUEST) += $(GMAP)/sk.o $(GMAP)/cmma.o $(GMAP)/prefix.o
+kvm-$(USE_PREFIX_STUB) += $(GMAP)/prefix-stubs.o
diff --git a/arch/s390/kvm/gmap/dat.c b/arch/s390/kvm/gmap/dat.c
index 6114ff442837..4a9847139534 100644
--- a/arch/s390/kvm/gmap/dat.c
+++ b/arch/s390/kvm/gmap/dat.c
@@ -777,51 +777,3 @@ 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;
}
-
-static long dat_set_pn_crste(union crste *crstep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
-{
- union crste newcrste, oldcrste;
- int *n = walk->priv;
-
- do {
- oldcrste = READ_ONCE(*crstep);
- if (!oldcrste.h.fc || oldcrste.h.i || oldcrste.h.p)
- return 0;
- if (oldcrste.s.fc1.prefix_notif)
- break;
- newcrste = oldcrste;
- newcrste.s.fc1.prefix_notif = 1;
- } while (!dat_crstep_xchg_atomic(crstep, oldcrste, newcrste, gfn, walk->asce));
- *n = 2;
- return 0;
-}
-
-static long dat_set_pn_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
-{
- int *n = walk->priv;
- union pgste pgste;
-
- pgste = pgste_get_lock(ptep);
- if (!ptep->h.i && !ptep->h.p) {
- pgste.prefix_notif = 1;
- *n += 1;
- }
- pgste_set_unlock(ptep, pgste);
- return 0;
-}
-
-int dat_set_prefix_notif_bit(union asce asce, gfn_t gfn)
-{
- static const struct dat_walk_ops ops = {
- .pte_entry = dat_set_pn_pte,
- .pmd_entry = dat_set_pn_crste,
- .pud_entry = dat_set_pn_crste,
- };
-
- int n = 0;
-
- _dat_walk_gfn_range(gfn, gfn + 2, asce, &ops, DAT_WALK_IGN_HOLES, &n);
- if (n != 2)
- return -EAGAIN;
- return 0;
-}
diff --git a/arch/s390/kvm/gmap/gmap.c b/arch/s390/kvm/gmap/gmap.c
index 4ade7794e990..3dcd1d4c6a29 100644
--- a/arch/s390/kvm/gmap/gmap.c
+++ b/arch/s390/kvm/gmap/gmap.c
@@ -254,29 +254,6 @@ int s390_replace_asce(struct gmap *gmap)
return 0;
}
-bool _gmap_unmap_prefix(struct gmap *gmap, gfn_t gfn, gfn_t end, bool hint)
-{
- struct kvm *kvm = gmap->kvm;
- struct kvm_vcpu *vcpu;
- gfn_t prefix_gfn;
- unsigned long i;
-
- if (is_shadow(gmap))
- return false;
- kvm_for_each_vcpu(i, vcpu, kvm) {
- /* Match against both prefix pages */
- prefix_gfn = gpa_to_gfn(kvm_s390_get_prefix(vcpu));
- if (prefix_gfn < end && gfn <= prefix_gfn + 1) {
- if (hint && kvm_s390_is_in_sie(vcpu))
- return false;
- VCPU_EVENT(vcpu, 2, "gmap notifier for %llx-%llx",
- gfn_to_gpa(gfn), gfn_to_gpa(end));
- kvm_s390_sync_request(KVM_REQ_REFRESH_GUEST_PREFIX, vcpu);
- }
- }
- return true;
-}
-
struct clear_young_pte_priv {
struct gmap *gmap;
bool young;
diff --git a/arch/s390/kvm/gmap/gmap.h b/arch/s390/kvm/gmap/gmap.h
index aa65fe724fdb..0500c8c6c9ca 100644
--- a/arch/s390/kvm/gmap/gmap.h
+++ b/arch/s390/kvm/gmap/gmap.h
@@ -13,6 +13,7 @@
#include <linux/kvm_host.h>
#include "dat.h"
+#include "prefix.h"
/**
* enum gmap_flags - Flags of a gmap.
@@ -158,16 +159,6 @@ static inline void gmap_handle_vsie_unshadow_event(struct gmap *parent, gfn_t gf
_gmap_handle_vsie_unshadow_event(parent, gfn);
}
-static inline bool gmap_mkold_prefix(struct gmap *gmap, gfn_t gfn, gfn_t end)
-{
- return _gmap_unmap_prefix(gmap, gfn, end, true);
-}
-
-static inline bool gmap_unmap_prefix(struct gmap *gmap, gfn_t gfn, gfn_t end)
-{
- return _gmap_unmap_prefix(gmap, gfn, end, false);
-}
-
/**
* pte_needs_unshadow() -- Check if the pte operations triggers unshadowing.
* @oldpte: the previous value for the guest pte.
diff --git a/arch/s390/kvm/gmap/prefix-stubs.c b/arch/s390/kvm/gmap/prefix-stubs.c
new file mode 100644
index 000000000000..d1d6286f454a
--- /dev/null
+++ b/arch/s390/kvm/gmap/prefix-stubs.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * These stubs are used when building gmap for non-s390 guests
+ * that don't need prefix page tracking.
+ */
+
+#include <linux/kvm_host.h>
+#include <linux/kvm_types.h>
+
+#include "dat.h"
+#include "prefix.h"
+
+bool _gmap_unmap_prefix(struct gmap *gmap, gfn_t gfn, gfn_t end, bool hint)
+{
+ return true;
+}
+
+int dat_set_prefix_notif_bit(union asce asce, gfn_t gfn)
+{
+ return 0;
+}
diff --git a/arch/s390/kvm/gmap/prefix.c b/arch/s390/kvm/gmap/prefix.c
new file mode 100644
index 000000000000..44caffed2da1
--- /dev/null
+++ b/arch/s390/kvm/gmap/prefix.c
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/kvm_host.h>
+#include <linux/kvm_types.h>
+
+#include "gmap.h"
+#include "dat.h"
+#include "prefix.h"
+#include "../s390/s390.h"
+
+bool _gmap_unmap_prefix(struct gmap *gmap, gfn_t gfn, gfn_t end, bool hint)
+{
+ struct kvm *kvm = gmap->kvm;
+ struct kvm_vcpu *vcpu;
+ gfn_t prefix_gfn;
+ unsigned long i;
+
+ if (is_shadow(gmap))
+ return false;
+ kvm_for_each_vcpu(i, vcpu, kvm) {
+ /* Match against both prefix pages */
+ prefix_gfn = gpa_to_gfn(kvm_s390_get_prefix(vcpu));
+ if (prefix_gfn < end && gfn <= prefix_gfn + 1) {
+ if (hint && kvm_s390_is_in_sie(vcpu))
+ return false;
+ VCPU_EVENT(vcpu, 2, "gmap notifier for %llx-%llx",
+ gfn_to_gpa(gfn), gfn_to_gpa(end));
+ kvm_s390_sync_request(KVM_REQ_REFRESH_GUEST_PREFIX, vcpu);
+ }
+ }
+ return true;
+}
+
+static long dat_set_pn_crste(union crste *crstep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
+{
+ union crste newcrste, oldcrste;
+ int *n = walk->priv;
+
+ do {
+ oldcrste = READ_ONCE(*crstep);
+ if (!oldcrste.h.fc || oldcrste.h.i || oldcrste.h.p)
+ return 0;
+ if (oldcrste.s.fc1.prefix_notif)
+ break;
+ newcrste = oldcrste;
+ newcrste.s.fc1.prefix_notif = 1;
+ } while (!dat_crstep_xchg_atomic(crstep, oldcrste, newcrste, gfn, walk->asce));
+ *n = 2;
+ return 0;
+}
+
+static long dat_set_pn_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
+{
+ int *n = walk->priv;
+ union pgste pgste;
+
+ pgste = pgste_get_lock(ptep);
+ if (!ptep->h.i && !ptep->h.p) {
+ pgste.prefix_notif = 1;
+ *n += 1;
+ }
+ pgste_set_unlock(ptep, pgste);
+ return 0;
+}
+
+int dat_set_prefix_notif_bit(union asce asce, gfn_t gfn)
+{
+ static const struct dat_walk_ops ops = {
+ .pte_entry = dat_set_pn_pte,
+ .pmd_entry = dat_set_pn_crste,
+ .pud_entry = dat_set_pn_crste,
+ };
+
+ int n = 0;
+
+ _dat_walk_gfn_range(gfn, gfn + 2, asce, &ops, DAT_WALK_IGN_HOLES, &n);
+ if (n != 2)
+ return -EAGAIN;
+ return 0;
+}
diff --git a/arch/s390/kvm/gmap/prefix.h b/arch/s390/kvm/gmap/prefix.h
new file mode 100644
index 000000000000..f1f3ace24f03
--- /dev/null
+++ b/arch/s390/kvm/gmap/prefix.h
@@ -0,0 +1,68 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef ARCH_KVM_GMAP_PREFIX_H
+#define ARCH_KVM_GMAP_PREFIX_H
+
+#include <linux/types.h>
+#include <linux/kvm_types.h>
+
+struct gmap;
+union asce;
+
+/**
+ * _gmap_unmap_prefix() - Notify vCPUs if prefix pages are affected
+ * @gmap: The gmap
+ * @gfn: Start of the range
+ * @end: End of the range (exclusive)
+ * @hint: If true, skip notification if vCPU is in SIE
+ *
+ * Check if any vCPU's prefix pages fall within the given range and
+ * request prefix refresh if needed.
+ *
+ * Return: false if notification was skipped due to hint, true otherwise
+ */
+bool _gmap_unmap_prefix(struct gmap *gmap, gfn_t gfn, gfn_t end, bool hint);
+
+/**
+ * dat_set_prefix_notif_bit() - Set prefix notification bits
+ * @asce: The address space control element
+ * @gfn: Guest frame number of the prefix area
+ *
+ * Set the prefix notification bit in the page table entries for the
+ * two prefix pages starting at @gfn.
+ *
+ * Return: 0 on success, -EAGAIN if not all bits could be set
+ */
+int dat_set_prefix_notif_bit(union asce asce, gfn_t gfn);
+
+/**
+ * gmap_mkold_prefix() - Mark prefix pages as old
+ * @gmap: The gmap
+ * @gfn: Start of the range
+ * @end: End of the range (exclusive)
+ *
+ * Inline wrapper that calls _gmap_unmap_prefix with hint=true.
+ *
+ * Return: Result from _gmap_unmap_prefix
+ */
+static inline bool gmap_mkold_prefix(struct gmap *gmap, gfn_t gfn, gfn_t end)
+{
+ return _gmap_unmap_prefix(gmap, gfn, end, true);
+}
+
+/**
+ * gmap_unmap_prefix() - Unconditionally notify about prefix pages
+ * @gmap: The gmap
+ * @gfn: Start of the range
+ * @end: End of the range (exclusive)
+ *
+ * Inline wrapper that calls _gmap_unmap_prefix with hint=false.
+ *
+ * Return: Result from _gmap_unmap_prefix
+ */
+static inline bool gmap_unmap_prefix(struct gmap *gmap, gfn_t gfn, gfn_t end)
+{
+ return _gmap_unmap_prefix(gmap, gfn, end, false);
+}
+
+#endif /* ARCH_KVM_GMAP_PREFIX_H */
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 18/27] KVM: s390: Prepare kvm-s390 for a second kvm module
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (16 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 17/27] KVM: s390: Refactor prefix handling into a separate file Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 19/27] s390: Introduce Start Arm Execution instruction Steffen Eiden
` (8 subsequent siblings)
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
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.
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/s390/kvm/s390/s390.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/arch/s390/kvm/s390/s390.c b/arch/s390/kvm/s390/s390.c
index 30c273f5377e..b560c1e57926 100644
--- a/arch/s390/kvm/s390/s390.c
+++ b/arch/s390/kvm/s390/s390.c
@@ -5808,6 +5808,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;
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 19/27] s390: Introduce Start Arm Execution instruction
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (17 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 18/27] KVM: s390: Prepare kvm-s390 for a second kvm module Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 11:17 ` Janosch Frank
2026-07-06 8:52 ` [PATCH v4 20/27] KVM: s390: arm64: Introduce host definitions Steffen Eiden
` (7 subsequent siblings)
26 siblings, 1 reply; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
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.
Co-developed-by: Andreas Grapentin <gra@linux.ibm.com>
Signed-off-by: Andreas Grapentin <gra@linux.ibm.com>
Co-developed-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/s390/include/asm/asm-prototypes.h | 1 +
arch/s390/include/asm/kvm_host_arm64_types.h | 129 +++++++++++++++++++
arch/s390/include/asm/kvm_host_types.h | 4 +
arch/s390/include/asm/sae.h | 56 ++++++++
arch/s390/include/asm/stacktrace.h | 5 +
arch/s390/kernel/asm-offsets.c | 1 +
arch/s390/kernel/entry.S | 25 ++++
arch/s390/tools/opcodes.txt | 3 +
8 files changed, 224 insertions(+)
create mode 100644 arch/s390/include/asm/kvm_host_arm64_types.h
create mode 100644 arch/s390/include/asm/sae.h
diff --git a/arch/s390/include/asm/asm-prototypes.h b/arch/s390/include/asm/asm-prototypes.h
index d4da4436d02b..faa2afb259a1 100644
--- a/arch/s390/include/asm/asm-prototypes.h
+++ b/arch/s390/include/asm/asm-prototypes.h
@@ -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 */
diff --git a/arch/s390/include/asm/kvm_host_arm64_types.h b/arch/s390/include/asm/kvm_host_arm64_types.h
new file mode 100644
index 000000000000..3882d5462a05
--- /dev/null
+++ b/arch/s390/include/asm/kvm_host_arm64_types.h
@@ -0,0 +1,129 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef ASM_KVM_HOST_ARM64_TYPES_H
+#define ASM_KVM_HOST_ARM64_TYPES_H
+
+#include <linux/types.h>
+#include <linux/kvm_types.h>
+#include <linux/compiler_attributes.h>
+#include <asm/page.h>
+#include <asm/fault.h>
+
+struct kvm_sae_block {
+ u64 _0000[16]; /* 0x0000 */
+#define SAE_ICPTR_SPURIOUS 0x00
+#define SAE_ICPTR_VALIDITY 0x01
+#define SAE_ICPTR_HOST_ACCESS_EXCEPTION 0x02
+#define SAE_ICPTR_SYNCHRONOUS_EXCEPTION 0x03
+#define SAE_ICPTR_TIMER 0x04
+#define SAE_ICPTR_PE_INTERCOMM 0x05
+#define SAE_ICPTR_GUEST_ADDRESS_SIZE 0x06
+#define SAE_ICPTR_STOP 0x07
+#define SAE_ICPTR_SYSTEM_REGISTER 0x08
+#define SAE_ICPTR_PMU 0x09
+#define SAE_ICPTR_MAINTENANCE 0x0a
+ u8 icptr; /* 0x0080 */
+ u8 _0081[7]; /* 0x0081 */
+ u64 scad; /* 0x0088 */
+ u64 _0090[16]; /* 0x00b0 */
+ u32 cntp_ctl; /* 0x0110 */
+ u32 cntv_ctl; /* 0x0114 */
+ u8 irq_ctl; /* 0x0118 */
+ u8 _0119[7]; /* 0x0119 */
+ struct {
+ u64 ich_hcr_el2; /* 0x0120 */
+ u64 ich_vmcr_el2; /* 0x0128 */
+ u64 ich_ap0r0_el2; /* 0x0130 */
+ u64 ich_ap1r0_el2; /* 0x0138 */
+ u64 _0140[2]; /* 0x0140 */
+ u64 ich_lrn_el2[4]; /* 0x0150 */
+ u64 _0170[4]; /* 0x0170 */
+ } ic_regs;
+ u64 _0190[12]; /* 0x0190 */
+ u64 contextidr_el1; /* 0x01f0 */
+ u32 wip; /* 0x01f8 */
+ u32 _01fc; /* 0x01fc */
+#define SAE_SD_FORMAT_0 0x00
+ u8 sdf; /* 0x0200 */
+ u8 _0201[7]; /* 0x0201 */
+ u64 mso; /* 0x0208 */
+ u64 msl; /* 0x0210 */
+ u64 hbasce; /* 0x0218 */
+ u64 _0220; /* 0x0220 */
+ u64 gpto; /* 0x0228 */
+ u64 ic; /* 0x0230 */
+ u64 ec; /* 0x0238 */
+ u64 save_area; /* 0x0240 */
+ u64 _0248[7]; /* 0x0248 */
+ u8 _0280[6]; /* 0x0280 */
+ u16 lrcpua; /* 0x0286 */
+ u64 pstate; /* 0x0288 */
+ u64 pc; /* 0x0290 */
+ u64 sp_el0; /* 0x0298 */
+ u64 sp_el1; /* 0x02a0 */
+ u64 _02a8; /* 0x02a8 */
+ u64 fpcr; /* 0x02b0 */
+ u64 fpsr; /* 0x02b8 */
+ u16 sve_pregs[16]; /* 0x02c0 */
+ u16 sve_ffr; /* 0x02e0 */
+ u8 _02e2[6]; /* 0x02e2 */
+ u64 _02e8[3]; /* 0x02e8 */
+
+ u64 gpr[31]; /* 0x0300 */
+ u64 _03f8; /* 0x03f8 */
+
+ union {
+ u64 icptd[8]; /* 0x0400 */
+ /* validity-interception reason; icptr 0x01 */
+#define SAE_VIR_UNKNOWN 0x00
+#define SAE_VIR_UNSUPP_FORMAT 0x01
+#define SAE_VIR_MSO_BOUNDS 0x02
+#define SAE_VIR_MSLA 0x03
+#define SAE_VIR_MGPAS 0x04
+#define SAE_VIR_INVAL_SYSREG 0x05
+#define SAE_VIR_HOST_CONTROL 0x06
+#define SAE_VIR_SCA 0x07
+#define SAE_VIR_MSO_ALIGN 0x08
+#define SAE_VIR_HLC 0x09
+#define SAE_VIR_IRPTC 0x0a
+ u16 vir; /* 0x0400 */
+ /* host access interception details; icptr 0x02 */
+ struct {
+ u64 esr_elz; /* 0x0400 */
+ u8 _0408[6]; /* 0x0408 */
+ u16 pic; /* 0x040e */
+ union teid teid; /* 0x0410 */
+ gva_t far_elz; /* 0x0418 */
+ gva_t vaddr; /* 0x0420 */
+ u64 suppl; /* 0x0428 */
+ u8 gltl; /* 0x0430 */
+ u8 _0431[7]; /* 0x0431 */
+ u64 _0438; /* 0x0438 */
+ } hai;
+ /* exception-interception details; icptr 0x03 */
+ struct {
+ u64 esr_elz; /* 0x0400 */
+ u64 _0408[2]; /* 0x0408 */
+ gva_t far_elz; /* 0x0418 */
+ } trap;
+ /* timer-interception reason; icptr 0x04 */
+#define SAE_IR_TIMER_ID_VIRT BIT(6)
+#define SAE_IR_TIMER_ID_PHYS BIT(7)
+ u8 tir; /* 0x0400 */
+ };
+ u64 _0440[376]; /* 0x0440 */
+} __packed __aligned(PAGE_SIZE);
+static_assert(sizeof(struct kvm_sae_block) == PAGE_SIZE);
+
+struct kvm_sae_save_area {
+#define SAE_SAVE_AREA_FORMAT_0 0x00
+ u8 saf; /* 0x0000 */
+ u8 _0001[5]; /* 0x0001 */
+#define SAE_SAS_VALID BIT(0)
+ u16 sas; /* 0x0006 */
+ u64 sdo; /* 0x0008 */
+ u64 _0010[2]; /* 0x0010 */
+ u64 regs[508]; /* 0x0020 */
+} __packed __aligned(PAGE_SIZE);
+static_assert(sizeof(struct kvm_sae_save_area) == PAGE_SIZE);
+
+#endif /* ASM_KVM_HOST_ARM64_TYPES_H */
diff --git a/arch/s390/include/asm/kvm_host_types.h b/arch/s390/include/asm/kvm_host_types.h
index e5bdba07cab0..d308739ebcf5 100644
--- a/arch/s390/include/asm/kvm_host_types.h
+++ b/arch/s390/include/asm/kvm_host_types.h
@@ -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 */
diff --git a/arch/s390/include/asm/sae.h b/arch/s390/include/asm/sae.h
new file mode 100644
index 000000000000..fe010a1a7729
--- /dev/null
+++ b/arch/s390/include/asm/sae.h
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_S390_SAE_H
+#define __ASM_S390_SAE_H
+
+#include "linux/linkage.h"
+#include <linux/types.h>
+
+/* defined in arch/s390/kernel/entry.S */
+asmlinkage int __sae64a(phys_addr_t sae_block_phys);
+
+#ifndef __ASSEMBLER__
+#include <linux/io.h>
+#include <asm/kvm_host_arm64_types.h>
+
+/**
+ * __sae64a() - Start Arm Execution
+ */
+static inline void sae64a(struct kvm_sae_block *sae_block)
+{
+ __sae64a(virt_to_phys(sae_block));
+}
+
+/**
+ * stiasrm() - STore and Invalidate Arm System Register Multiple
+ * @save_area: Pointer to SAE save area
+ *
+ * Store the guest system register to the save area.
+ * The values in the guest are not valid anymore..
+ */
+static __always_inline void stiasrm(struct kvm_sae_save_area *save_area)
+{
+ asm volatile(
+ " .insn rre,0xb9a70000,%[r1],0\n"
+ : "+m"(*save_area)
+ : [r1] "a"(save_area)
+ );
+}
+
+/**
+ * lasrm() - Load Arm System Register Multiple
+ *
+ * @save_area: Pointer to SAE save area
+ *
+ * Load the system registers from save_area into the guest.
+ */
+static __always_inline void lasrm(struct kvm_sae_save_area *save_area)
+{
+ asm volatile(
+ " .insn rre,0xb9a60000,%[r1],0\n"
+ :
+ : "m"(*save_area), [r1] "a"(save_area)
+ );
+}
+
+#endif /* !__ASSEMBLER__ */
+#endif /* __ASM_S390_SAE_H */
diff --git a/arch/s390/include/asm/stacktrace.h b/arch/s390/include/asm/stacktrace.h
index ac3606c3babe..2d332d7c8145 100644
--- a/arch/s390/include/asm/stacktrace.h
+++ b/arch/s390/include/asm/stacktrace.h
@@ -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;
diff --git a/arch/s390/kernel/asm-offsets.c b/arch/s390/kernel/asm-offsets.c
index f6dd2b67dcee..f9f9c2246074 100644
--- a/arch/s390/kernel/asm-offsets.c
+++ b/arch/s390/kernel/asm-offsets.c
@@ -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);
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index 9572620fcaa6..248bea26921b 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -244,6 +244,31 @@ 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
+# Let the next instruction be NOP to avoid triggering a machine check
+# and handling it in a guest as result of the instruction execution.
+ nopr 7
+ 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 %r3,%r3
+ xgr %r2,%r2
+ 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.
diff --git a/arch/s390/tools/opcodes.txt b/arch/s390/tools/opcodes.txt
index def2659f6602..0e4773c94af0 100644
--- a/arch/s390/tools/opcodes.txt
+++ b/arch/s390/tools/opcodes.txt
@@ -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
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 20/27] KVM: s390: arm64: Introduce host definitions
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (18 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 19/27] s390: Introduce Start Arm Execution instruction Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 21/27] s390/hwcaps: Report SAE support as hwcap Steffen Eiden
` (6 subsequent siblings)
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
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.
Co-developed-by: Andreas Grapentin <gra@linux.ibm.com>
Signed-off-by: Andreas Grapentin <gra@linux.ibm.com>
Co-developed-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/s390/include/asm/kvm.h | 6 +
arch/s390/include/asm/kvm_host.h | 9 ++
arch/s390/include/asm/kvm_host_arm64.h | 210 +++++++++++++++++++++++++
3 files changed, 225 insertions(+)
create mode 100644 arch/s390/include/asm/kvm.h
create mode 100644 arch/s390/include/asm/kvm_host_arm64.h
diff --git a/arch/s390/include/asm/kvm.h b/arch/s390/include/asm/kvm.h
new file mode 100644
index 000000000000..aeb11dc631d5
--- /dev/null
+++ b/arch/s390/include/asm/kvm.h
@@ -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
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index 33af8842a71c..0c22cc42be7e 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -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_PROTECTION 0x04
#define PGM_ADDRESSING 0x05
diff --git a/arch/s390/include/asm/kvm_host_arm64.h b/arch/s390/include/asm/kvm_host_arm64.h
new file mode 100644
index 000000000000..6d08856fe395
--- /dev/null
+++ b/arch/s390/include/asm/kvm_host_arm64.h
@@ -0,0 +1,210 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef ASM_KVM_HOST_ARM64_H
+#define ASM_KVM_HOST_ARM64_H
+
+#include <linux/bug.h>
+
+#include <asm/kvm_host_types.h>
+#include <asm/debug.h>
+
+#define vcpu_gp_regs(v) ((v)->arch.sae_block.gpr)
+
+#define HAVE_KVM_MMIO
+
+#include <arm64/kvm_host.h>
+#include <asm/sae.h>
+
+#define KVM_HAVE_MMU_RWLOCK
+#define KVM_MAX_VCPUS 1
+
+#define KVM_HALT_POLL_NS_DEFAULT 50000
+
+/* Minimal (=no) vgic definitions */
+#define KVM_IRQCHIP_NUM_PINS 1
+#define irqchip_in_kernel(_v) false;
+
+#define __ctxt_sys_reg(ctx, reg) NULL
+struct kvm_cpu_context {
+ /*
+ * These are just for 32 bit, which we don't have, making them RES0.
+ * They are exposed to user space.
+ */
+ u64 spsr_abt;
+ u64 spsr_und;
+ u64 spsr_irq;
+ u64 spsr_fiq;
+
+ __vector128 __aligned(16) vregs[32];
+};
+
+struct kvm_vcpu_arch {
+ struct kvm_sae_block sae_block;
+ struct kvm_sae_save_area save_area;
+ struct kvm_cpu_context ctxt;
+
+ u32 host_acrs[NUM_ACRS];
+
+ /* Hypervisor Configuration Register */
+ u64 hcr_elz;
+
+ /* Configuration flags, set once and for all before the vcpu can run */
+ u8 cflags;
+
+ /* Input flags to the hypervisor code, potentially cleared after use */
+ u8 iflags;
+
+ /* State flags for kernel bookkeeping, unused by the hypervisor code */
+ u8 sflags;
+
+ /*
+ * Don't run the guest (internal implementation need).
+ *
+ * Contrary to the flags above, this is set/cleared outside of
+ * a vcpu context, and thus cannot be mixed with the flags
+ * themselves (or the flag accesses need to be made atomic).
+ */
+ bool pause;
+
+ /* vcpu power state */
+ struct kvm_mp_state mp_state;
+ /* lock for mp_state & reset_state.reset */
+ spinlock_t mp_state_lock;
+
+ /* vcpu reset state */
+ struct vcpu_reset_state reset_state;
+
+ /* GMAP */
+ struct gmap *gmap;
+ struct kvm_s390_mmu_cache *mc;
+
+ void *debugfs_state_data;
+};
+
+struct kvm_vcpu_stat {
+ struct kvm_vcpu_stat_generic generic;
+ /* ARM64 stats */
+ u64 hvc_exit_stat;
+ u64 wfe_exit_stat;
+ u64 wfi_exit_stat;
+ u64 mmio_exit_user;
+ u64 mmio_exit_kernel;
+ u64 signal_exits;
+ u64 exits;
+ /* GMAP stats */
+ u64 pfault_sync;
+};
+
+#define kvm_vcpu_get_sp_el1(__vcpu) (&((__vcpu)->arch.sae_block.sp_el1))
+#define kvm_vcpu_get_vreg(__vcpu, _off) (&(__vcpu)->arch.ctxt.vregs[_off])
+#define kvm_vcpu_get_vregs(__vcpu) (&(__vcpu)->arch.ctxt.vregs)
+#define kvm_vcpu_get_fpsr(__vcpu) (&(__vcpu)->arch.sae_block.fpsr)
+#define kvm_vcpu_get_fpcr(__vcpu) (&(__vcpu)->arch.sae_block.fpcr)
+
+#define __vcpu_flags_preempt_disable() preempt_disable()
+#define __vcpu_flags_preempt_enable() preempt_enable()
+
+#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__)
+
+#define kvm_has_mte(_kvm) false
+#define vcpu_has_sve(_vcpu) false
+#define vcpu_has_ptrauth(_vcpu) false
+
+struct kvm_arch_memory_slot {
+};
+
+struct kvm_arch {
+ struct gmap *gmap;
+ u64 guest_phys_size;
+
+ /* VM-wide vCPU feature set */
+ unsigned long flags;
+
+ /* Protects VM-scoped configuration data */
+ struct mutex config_lock;
+
+ debug_info_t *dbf;
+
+ DECLARE_BITMAP(vcpu_features, KVM_VCPU_MAX_FEATURES);
+
+ unsigned long mem_limit;
+};
+
+static inline bool __vcpu_has_feature(const struct kvm_arch *ka, int feature)
+{
+ return test_bit(feature, ka->vcpu_features);
+}
+
+#define vcpu_has_feature(v, f) __vcpu_has_feature(&(v)->kvm->arch, (f))
+
+struct kvm_vm_stat {
+ struct kvm_vm_stat_generic generic;
+};
+
+#define kvm_vm_is_protected(_kvm) false
+
+#define vcpu_is_loaded(_vcpu) ((_vcpu)->cpu != -1)
+
+#define KVM_HVA_ERR_BAD -1UL
+#define KVM_HVA_ERR_RO_BAD -2UL
+
+#define kvm_phys_size(__kvm) ((__kvm)->arch.guest_phys_size)
+static inline bool kvm_is_error_hva(unsigned long addr)
+{
+ return IS_ERR_VALUE(addr);
+}
+
+u32 get_kvm_ipa_limit(void);
+
+static inline void kvm_arch_sync_events(struct kvm *kvm) {}
+static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
+
+int kvm_handle_guest_abort(struct kvm_vcpu *vcpu);
+
+/* arm64 guests do not use async-pf. Defined because Kbuild requires it as s390 kvm turns it on. */
+#define ASYNC_PF_PER_VCPU 0
+struct kvm_arch_async_pf {
+ unsigned long pfault_token;
+};
+
+#define __unsupp_async_call(fn) WARN_ONCE(true, "async not supported on kvm-arm64 %s", fn)
+
+static inline bool kvm_arch_can_dequeue_async_page_present(struct kvm_vcpu *vcpu)
+{
+ __unsupp_async_call(__func__);
+ return false;
+};
+
+static inline void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu,
+ struct kvm_async_pf *work)
+{
+ __unsupp_async_call(__func__);
+};
+
+static inline bool kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
+ struct kvm_async_pf *work)
+{
+ __unsupp_async_call(__func__);
+ return false;
+};
+
+static inline void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
+ struct kvm_async_pf *work)
+{
+ __unsupp_async_call(__func__);
+};
+
+static inline void kvm_arch_async_page_present_queued(struct kvm_vcpu *vcpu)
+{
+ __unsupp_async_call(__func__);
+};
+
+#define kvm_supports_32bit_el0() false
+
+#endif /* ASM_KVM_HOST_ARM64_H */
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 21/27] s390/hwcaps: Report SAE support as hwcap
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (19 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 20/27] KVM: s390: arm64: Introduce host definitions Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 11:50 ` Janosch Frank
2026-07-06 8:52 ` [PATCH v4 22/27] KVM: s390: Add basic arm64 kvm module Steffen Eiden
` (5 subsequent siblings)
26 siblings, 1 reply; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
From: Hendrik Brueckner <brueckner@linux.ibm.com>
Report SAE support as hwcap (and /proc/cpuinfo)
Signed-off-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
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(-)
diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
index bb63fa4d20bb..ad3108ecfb07 100644
--- a/arch/s390/include/asm/elf.h
+++ b/arch/s390/include/asm/elf.h
@@ -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.
diff --git a/arch/s390/include/asm/sclp.h b/arch/s390/include/asm/sclp.h
index f2d490558054..f669569cf78d 100644
--- a/arch/s390/include/asm/sclp.h
+++ b/arch/s390/include/asm/sclp.h
@@ -53,7 +53,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;
@@ -106,6 +108,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;
diff --git a/arch/s390/kernel/processor.c b/arch/s390/kernel/processor.c
index e33a3eccda56..6da55a158027 100644
--- a/arch/s390/kernel/processor.c
+++ b/arch/s390/kernel/processor.c
@@ -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;
}
diff --git a/drivers/s390/char/sclp_early.c b/drivers/s390/char/sclp_early.c
index 22dd797e6229..e58d24b95bd1 100644
--- a/drivers/s390/char/sclp_early.c
+++ b/drivers/s390/char/sclp_early.c
@@ -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;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 22/27] KVM: s390: Add basic arm64 kvm module
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (20 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 21/27] s390/hwcaps: Report SAE support as hwcap Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 23/27] KVM: s390: arm64: Implement required functions Steffen Eiden
` (4 subsequent siblings)
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
Add basic code for the new arm64 on s390 KVM implementation.
Add kernel module boilerplate code and trivial functions.
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/s390/kvm/arm64/arm.c | 192 ++++++++++++++++++++++++++++++++++++
arch/s390/kvm/arm64/arm.h | 7 ++
arch/s390/kvm/arm64/guest.c | 102 +++++++++++++++++++
arch/s390/kvm/arm64/guest.h | 9 ++
4 files changed, 310 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/guest.h
diff --git a/arch/s390/kvm/arm64/arm.c b/arch/s390/kvm/arm64/arm.c
new file mode 100644
index 000000000000..19249ec5c539
--- /dev/null
+++ b/arch/s390/kvm/arm64/arm.c
@@ -0,0 +1,192 @@
+// 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"
+
+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:
+ case KVM_CAP_ARM_USER_IRQ:
+ 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)
+{
+}
+
+void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu)
+{
+}
+
+void kvm_arch_vcpu_unblocking(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 *v)
+{
+ return 0;
+}
+
+static unsigned long system_supported_vcpu_features(void)
+{
+ return KVM_VCPU_VALID_FEATURES;
+}
+
+int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
+ bool line_status)
+{
+ return 0;
+}
+
+void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm,
+ struct kvm_memory_slot *slot,
+ gfn_t gfn_offset,
+ unsigned long mask)
+{
+}
+
+bool kvm_arch_irqchip_in_kernel(struct kvm *kvm)
+{
+ return false;
+}
+
+void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot)
+{
+}
+
+void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen)
+{
+}
+
+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;
+}
+
+void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
+ struct kvm_memory_slot *slot)
+{
+}
+
+void kvm_arch_flush_shadow_all(struct kvm *kvm)
+{
+}
+
+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);
diff --git a/arch/s390/kvm/arm64/arm.h b/arch/s390/kvm/arm64/arm.h
new file mode 100644
index 000000000000..a3db254462c0
--- /dev/null
+++ b/arch/s390/kvm/arm64/arm.h
@@ -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 */
diff --git a/arch/s390/kvm/arm64/guest.c b/arch/s390/kvm/arm64/guest.c
new file mode 100644
index 000000000000..097195d446b2
--- /dev/null
+++ b/arch/s390/kvm/arm64/guest.c
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/kvm_host.h>
+#include <linux/kvm.h>
+
+#include <arm64/kvm_emulate.h>
+#include <arm64/kvm_nested.h>
+
+#include "guest.h"
+
+#define __INCL_GEN_ARM_FILE
+#include "generated/guest.inc"
+#undef __INCL_GEN_ARM_FILE
+
+const struct kvm_stats_desc kvm_vm_stats_desc[] = {
+ KVM_GENERIC_VM_STATS()
+};
+
+const struct kvm_stats_header kvm_vm_stats_header = {
+ .name_size = KVM_STATS_NAME_SIZE,
+ .num_desc = ARRAY_SIZE(kvm_vm_stats_desc),
+ .id_offset = sizeof(struct kvm_stats_header),
+ .desc_offset = sizeof(struct kvm_stats_header) + KVM_STATS_NAME_SIZE,
+ .data_offset = sizeof(struct kvm_stats_header) + KVM_STATS_NAME_SIZE +
+ sizeof(kvm_vm_stats_desc),
+};
+
+const struct kvm_stats_desc kvm_vcpu_stats_desc[] = {
+ KVM_GENERIC_VCPU_STATS(),
+ /* ARM64 stats */
+ STATS_DESC_COUNTER(VCPU, hvc_exit_stat),
+ STATS_DESC_COUNTER(VCPU, wfe_exit_stat),
+ STATS_DESC_COUNTER(VCPU, wfi_exit_stat),
+ STATS_DESC_COUNTER(VCPU, mmio_exit_user),
+ STATS_DESC_COUNTER(VCPU, mmio_exit_kernel),
+ STATS_DESC_COUNTER(VCPU, signal_exits),
+ STATS_DESC_COUNTER(VCPU, exits),
+ /* GMAP stats */
+ STATS_DESC_COUNTER(VCPU, pfault_sync),
+};
+
+const struct kvm_stats_header kvm_vcpu_stats_header = {
+ .name_size = KVM_STATS_NAME_SIZE,
+ .num_desc = ARRAY_SIZE(kvm_vcpu_stats_desc),
+ .id_offset = sizeof(struct kvm_stats_header),
+ .desc_offset = sizeof(struct kvm_stats_header) + KVM_STATS_NAME_SIZE,
+ .data_offset = sizeof(struct kvm_stats_header) + KVM_STATS_NAME_SIZE +
+ sizeof(kvm_vcpu_stats_desc),
+};
+
+int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices)
+{
+ return copy_core_reg_indices(vcpu, uindices);
+}
+
+unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu)
+{
+ return num_core_regs(vcpu);
+}
+
+int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
+{
+ return -EINVAL;
+}
+
+int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
+{
+ return -EINVAL;
+}
+
+int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
+ struct kvm_sregs *sregs)
+{
+ return -EINVAL;
+}
+
+int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
+ struct kvm_sregs *sregs)
+{
+ return -EINVAL;
+}
+
+int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
+{
+ return -EINVAL;
+}
+
+int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
+{
+ return -EINVAL;
+}
+
+int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
+ struct kvm_translation *tr)
+{
+ return -EINVAL;
+}
+
+int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
+ struct kvm_guest_debug *dbg)
+{
+ return -EINVAL;
+}
diff --git a/arch/s390/kvm/arm64/guest.h b/arch/s390/kvm/arm64/guest.h
new file mode 100644
index 000000000000..31c8bc799dbe
--- /dev/null
+++ b/arch/s390/kvm/arm64/guest.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef KVM_ARM_GUEST_H
+#define KVM_ARM_GUEST_H
+
+#include <linux/kvm_host.h>
+
+unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
+
+#endif /* KVM_ARM_GUEST_H */
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 23/27] KVM: s390: arm64: Implement required functions
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (21 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 22/27] KVM: s390: Add basic arm64 kvm module Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 12:15 ` Janosch Frank
2026-07-06 20:35 ` Marc Zyngier
2026-07-06 8:52 ` [PATCH v4 24/27] KVM: s390: arm64: Implement vm/vcpu create destroy Steffen Eiden
` (3 subsequent siblings)
26 siblings, 2 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
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.
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/s390/include/arm64/kvm_emulate.h | 135 ++++++++++++++++++++++++++
arch/s390/include/arm64/kvm_nested.h | 11 +++
arch/s390/kvm/arm64/handle_exit.c | 110 +++++++++++++++++++++
arch/s390/kvm/arm64/inject_fault.c | 21 ++++
4 files changed, 277 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/kvm/arm64/handle_exit.c
create mode 100644 arch/s390/kvm/arm64/inject_fault.c
diff --git a/arch/s390/include/arm64/kvm_emulate.h b/arch/s390/include/arm64/kvm_emulate.h
new file mode 100644
index 000000000000..6ad21398f86f
--- /dev/null
+++ b/arch/s390/include/arm64/kvm_emulate.h
@@ -0,0 +1,135 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __S390_ARM64_KVM_EMULATE_H__
+#define __S390_ARM64_KVM_EMULATE_H__
+
+#include <asm/fault.h>
+#include <asm/ptrace.h>
+#include <linux/kvm_host.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 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 __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 void vcpu_reset_hcr(struct kvm_vcpu *vcpu)
+{
+ vcpu->arch.hcr_elz = HCR_E2H | HCR_RW | HCR_AMO | HCR_IMO | HCR_FMO |
+ HCR_PTW;
+ /* traps */
+ vcpu->arch.hcr_elz |= HCR_TSC | HCR_TID1 | HCR_TID2 | HCR_TID3 |
+ HCR_TID4 | HCR_TID5 | HCR_TIDCP;
+}
+
+static inline unsigned long vcpu_get_vsesr(struct kvm_vcpu *vcpu)
+{
+ WARN(true, "not implemented, just feat RAS");
+
+ return 0L;
+}
+
+static inline void vcpu_set_vsesr(struct kvm_vcpu *vcpu, u64 vsesr)
+{
+ WARN(true, "not implemented, just feat RAS");
+}
+
+static inline bool vcpu_el2_tge_is_set(const 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 is_hyp_ctxt(const struct kvm_vcpu *vcpu)
+{
+ return false;
+}
+
+static inline bool is_nested_ctxt(struct kvm_vcpu *vcpu)
+{
+ return false;
+}
+
+static inline bool vcpu_mode_priv(const struct kvm_vcpu *vcpu)
+{
+ u32 mode = *vcpu_cpsr(vcpu) & PSR_MODE_MASK;
+
+ return mode != PSR_MODE_EL0t;
+}
+
+#define SPSR_SS BIT(21)
+
+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_SS;
+}
+
+#include <arm64/kvm_emulate-part.h>
+
+#endif /* __S390_ARM64_KVM_EMULATE_H__ */
diff --git a/arch/s390/include/arm64/kvm_nested.h b/arch/s390/include/arm64/kvm_nested.h
new file mode 100644
index 000000000000..e950b1a10c41
--- /dev/null
+++ b/arch/s390/include/arm64/kvm_nested.h
@@ -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 */
diff --git a/arch/s390/kvm/arm64/handle_exit.c b/arch/s390/kvm/arm64/handle_exit.c
new file mode 100644
index 000000000000..a0ebe5ffa19a
--- /dev/null
+++ b/arch/s390/kvm/arm64/handle_exit.c
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/kvm_host.h>
+
+#include <arm64/esr.h>
+#include <arm64/kvm_emulate.h>
+
+typedef int (*exit_handle_fn)(struct kvm_vcpu *);
+exit_handle_fn arm_exit_handlers[ESR_ELx_EC_MAX + 1];
+
+#define __INCL_GEN_ARM_FILE
+#include "generated/handle_exit.inc"
+#undef __INCL_GEN_ARM_FILE
+
+#define PSCI_0_2_FN_SYSTEM_OFF 0x84000008
+#define PSCI_RET_NOT_SUPPORTED -1
+#define PSCI_RET_INTERNAL_FAILURE -6
+/*
+ * Temporary smc/hvc handler. Non-compliant implementation (features missing).
+ * Implements only system off so that test programs are able to end their execution
+ */
+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) {
+ spin_lock(&vcpu->arch.mp_state_lock);
+ WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_STOPPED);
+ spin_unlock(&vcpu->arch.mp_state_lock);
+ kvm_make_all_cpus_request(vcpu->kvm, KVM_REQ_SLEEP);
+ memset(&vcpu->run->system_event, 0,
+ sizeof(vcpu->run->system_event));
+ vcpu->run->system_event.type = KVM_SYSTEM_EVENT_SHUTDOWN;
+ vcpu->run->system_event.ndata = 1;
+ vcpu->run->system_event.data[0] = 0;
+ vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
+ val = PSCI_RET_INTERNAL_FAILURE;
+ ret = 0;
+ }
+ vcpu_set_reg(vcpu, 0, val);
+
+ return ret;
+}
+
+static int handle_hvc(struct kvm_vcpu *vcpu)
+{
+ vcpu->stat.hvc_exit_stat++;
+ return kvm_smccc_call_handler(vcpu);
+}
+
+exit_handle_fn arm_exit_handlers[] = {
+ [0 ... ESR_ELx_EC_MAX] = kvm_handle_unknown_ec,
+ [ESR_ELx_EC_HVC64] = handle_hvc,
+};
+
+/* manually copied from arch/arm64/kernel/traps.c */
+static const char * const esr_class_str[] = {
+ [0 ... ESR_ELx_EC_MAX] = "UNRECOGNIZED EC",
+ [ESR_ELx_EC_UNKNOWN] = "Unknown/Uncategorized",
+ [ESR_ELx_EC_WFx] = "WFI/WFE",
+ [ESR_ELx_EC_CP15_32] = "CP15 MCR/MRC",
+ [ESR_ELx_EC_CP15_64] = "CP15 MCRR/MRRC",
+ [ESR_ELx_EC_CP14_MR] = "CP14 MCR/MRC",
+ [ESR_ELx_EC_CP14_LS] = "CP14 LDC/STC",
+ [ESR_ELx_EC_FP_ASIMD] = "ASIMD",
+ [ESR_ELx_EC_CP10_ID] = "CP10 MRC/VMRS",
+ [ESR_ELx_EC_PAC] = "PAC",
+ [ESR_ELx_EC_CP14_64] = "CP14 MCRR/MRRC",
+ [ESR_ELx_EC_BTI] = "BTI",
+ [ESR_ELx_EC_ILL] = "PSTATE.IL",
+ [ESR_ELx_EC_SVC32] = "SVC (AArch32)",
+ [ESR_ELx_EC_HVC32] = "HVC (AArch32)",
+ [ESR_ELx_EC_SMC32] = "SMC (AArch32)",
+ [ESR_ELx_EC_SVC64] = "SVC (AArch64)",
+ [ESR_ELx_EC_HVC64] = "HVC (AArch64)",
+ [ESR_ELx_EC_SMC64] = "SMC (AArch64)",
+ [ESR_ELx_EC_SYS64] = "MSR/MRS (AArch64)",
+ [ESR_ELx_EC_SVE] = "SVE",
+ [ESR_ELx_EC_ERET] = "ERET/ERETAA/ERETAB",
+ [ESR_ELx_EC_FPAC] = "FPAC",
+ [ESR_ELx_EC_SME] = "SME",
+ [ESR_ELx_EC_IMP_DEF] = "EL3 IMP DEF",
+ [ESR_ELx_EC_IABT_LOW] = "IABT (lower EL)",
+ [ESR_ELx_EC_IABT_CUR] = "IABT (current EL)",
+ [ESR_ELx_EC_PC_ALIGN] = "PC Alignment",
+ [ESR_ELx_EC_DABT_LOW] = "DABT (lower EL)",
+ [ESR_ELx_EC_DABT_CUR] = "DABT (current EL)",
+ [ESR_ELx_EC_SP_ALIGN] = "SP Alignment",
+ [ESR_ELx_EC_MOPS] = "MOPS",
+ [ESR_ELx_EC_FP_EXC32] = "FP (AArch32)",
+ [ESR_ELx_EC_FP_EXC64] = "FP (AArch64)",
+ [ESR_ELx_EC_GCS] = "Guarded Control Stack",
+ [ESR_ELx_EC_SERROR] = "SError",
+ [ESR_ELx_EC_BREAKPT_LOW] = "Breakpoint (lower EL)",
+ [ESR_ELx_EC_BREAKPT_CUR] = "Breakpoint (current EL)",
+ [ESR_ELx_EC_SOFTSTP_LOW] = "Software Step (lower EL)",
+ [ESR_ELx_EC_SOFTSTP_CUR] = "Software Step (current EL)",
+ [ESR_ELx_EC_WATCHPT_LOW] = "Watchpoint (lower EL)",
+ [ESR_ELx_EC_WATCHPT_CUR] = "Watchpoint (current EL)",
+ [ESR_ELx_EC_BKPT32] = "BKPT (AArch32)",
+ [ESR_ELx_EC_VECTOR32] = "Vector catch (AArch32)",
+ [ESR_ELx_EC_BRK64] = "BRK (AArch64)",
+};
+
+const char *esr_get_class_string(unsigned long esr)
+{
+ return esr_class_str[ESR_ELx_EC(esr)];
+}
diff --git a/arch/s390/kvm/arm64/inject_fault.c b/arch/s390/kvm/arm64/inject_fault.c
new file mode 100644
index 000000000000..425dbeaa421c
--- /dev/null
+++ b/arch/s390/kvm/arm64/inject_fault.c
@@ -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;
+}
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 24/27] KVM: s390: arm64: Implement vm/vcpu create destroy.
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (22 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 23/27] KVM: s390: arm64: Implement required functions Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 25/27] KVM: s390: arm64: Implement vCPU IOCTLs Steffen Eiden
` (2 subsequent siblings)
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
Implement init and destroy IOCTLS for vcpu and vm.
Implement arch vm IOCTL. Use s390 gmap.
Co-developed-by: Janosch Frank <frankja@linux.ibm.com>
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Co-developed-by: Andreas Grapentin <gra@linux.ibm.com>
Signed-off-by: Andreas Grapentin <gra@linux.ibm.com>
Co-developed-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/s390/kvm/arm64/arm.c | 190 ++++++++++++++++++++++++++++++++
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/trace-gmap.h | 13 +++
5 files changed, 268 insertions(+)
diff --git a/arch/s390/kvm/arm64/arm.c b/arch/s390/kvm/arm64/arm.c
index 19249ec5c539..3a4092698fae 100644
--- a/arch/s390/kvm/arm64/arm.c
+++ b/arch/s390/kvm/arm64/arm.c
@@ -8,6 +8,10 @@
#include <linux/kvm_types.h>
#include <linux/kvm_host.h>
+#include <arm64/kvm_mmu.h>
+
+#include <gmap.h>
+
#include "arm.h"
static unsigned long system_supported_vcpu_features(void);
@@ -31,6 +35,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
break;
case KVM_CAP_IOEVENTFD:
case KVM_CAP_ARM_USER_IRQ:
+ case KVM_CAP_PRE_FAULT_MEMORY:
ret = 1;
break;
default:
@@ -51,6 +56,82 @@ 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", current->pid);
+ 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;
@@ -62,6 +143,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;
@@ -72,10 +160,39 @@ 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;
+
+ 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();
+
+ 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");
+}
+
void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu)
{
}
@@ -113,6 +230,58 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
return 0;
}
+int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
+ struct kvm_dirty_log *log)
+{
+ return gmap_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 gmap_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)
+{
+ gmap_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)
+{
+ return gmap_test_age_gfn(kvm, range);
+}
+
+long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu,
+ struct kvm_pre_fault_memory *range)
+{
+ return gmap_pre_fault_memory(vcpu, range);
+}
+
void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm,
struct kvm_memory_slot *slot,
gfn_t gfn_offset,
@@ -120,6 +289,27 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm,
{
}
+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;
diff --git a/arch/s390/kvm/arm64/arm.h b/arch/s390/kvm/arm64/arm.h
index a3db254462c0..244c2b7a136f 100644
--- a/arch/s390/kvm/arm64/arm.h
+++ b/arch/s390/kvm/arm64/arm.h
@@ -2,6 +2,62 @@
#ifndef ARCH_S390_KVM_ARM64_H
#define ARCH_S390_KVM_ARM64_H
+#include <linux/kvm_host.h>
+
#define KVM_DEV_NAME "kvm-arm64"
+#define VM_EVENT(d_kvm, d_loglevel, d_string, d_args...)\
+do { \
+ debug_sprintf_event((d_kvm)->arch.dbf, d_loglevel, KVM_DEV_NAME ": " d_string "\n", d_args); \
+} while (0)
+
+#define VCPU_EVENT(d_vcpu, d_loglevel, d_string, d_args...) \
+ do { \
+ debug_sprintf_event( \
+ (d_vcpu)->kvm->arch.dbf, d_loglevel, \
+ KVM_DEV_NAME " %02d[%016llx-%016llx]: " d_string "\n", \
+ (d_vcpu)->vcpu_id, (d_vcpu)->arch.sae_block.pstate, \
+ (d_vcpu)->arch.sae_block.pc, d_args); \
+ } while (0)
+
+static __always_inline bool kvm_s390_is_in_sie(struct kvm_vcpu *vcpu)
+{
+ return false;
+}
+
+static __always_inline int kvm_is_ucontrol(struct kvm *kvm)
+{
+ return 0;
+}
+
+static __always_inline int __kvm_s390_pv_destroy_page(struct page *page)
+{
+ return 0;
+}
+
+static __always_inline void kvm_s390_vsie_gmap_notifier(struct gmap *gmap, gpa_t start, gpa_t end)
+{
+}
+
+static __always_inline int kvm_s390_pv_get_handle(struct kvm *kvm)
+{
+ return 0;
+}
+
+static __always_inline int kvm_s390_is_migration_mode(struct kvm *kvm)
+{
+ return false;
+}
+
+static __always_inline bool kvm_arch_setup_async_pf(struct kvm_vcpu *vcpu)
+{
+ return false;
+}
+
+/* should never be called */
+static __always_inline int kvm_s390_vm_stop_migration(struct kvm *kvm)
+{
+ return -EINVAL;
+}
+
#endif /* ARCH_S390_KVM_ARM64_H */
diff --git a/arch/s390/kvm/gmap/faultin.c b/arch/s390/kvm/gmap/faultin.c
index 713914dc8eb2..b417ba575e6e 100644
--- a/arch/s390/kvm/gmap/faultin.c
+++ b/arch/s390/kvm/gmap/faultin.c
@@ -10,6 +10,11 @@
#include "gmap.h"
#include "faultin.h"
+#ifdef KVM_S390_ARM64
+#include "arm.h"
+#else
+#include "s390.h"
+#endif
#define CREATE_TRACE_POINTS
#include "trace-gmap.h"
diff --git a/arch/s390/kvm/gmap/gmap.c b/arch/s390/kvm/gmap/gmap.c
index 3dcd1d4c6a29..b2ba6ee85fef 100644
--- a/arch/s390/kvm/gmap/gmap.c
+++ b/arch/s390/kvm/gmap/gmap.c
@@ -24,7 +24,11 @@
#include "cmma.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)
diff --git a/arch/s390/kvm/gmap/trace-gmap.h b/arch/s390/kvm/gmap/trace-gmap.h
index 78559298932c..25f8a527fdde 100644
--- a/arch/s390/kvm/gmap/trace-gmap.h
+++ b/arch/s390/kvm/gmap/trace-gmap.h
@@ -10,6 +10,18 @@
#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)
@@ -20,6 +32,7 @@
#define __KVM_PRINT \
__entry->pswmask,\
__entry->pswaddr
+#endif
TRACE_EVENT(kvm_s390_major_guest_pfault,
TP_PROTO(struct kvm_vcpu *vcpu),
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 25/27] KVM: s390: arm64: Implement vCPU IOCTLs
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (23 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 24/27] KVM: s390: arm64: Implement vm/vcpu create destroy Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 26/27] KVM: s390: arm64: Implement basic page fault handler Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 27/27] KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild Steffen Eiden
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
Implement all vCPU IOCTLs.
Co-developed-by: Andreas Grapentin <gra@linux.ibm.com>
Signed-off-by: Andreas Grapentin <gra@linux.ibm.com>
Co-developed-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/s390/kvm/arm64/arm.c | 344 ++++++++++++++++++++++++++++++
arch/s390/kvm/arm64/guest.c | 67 ++++++
arch/s390/kvm/arm64/guest.h | 5 +
arch/s390/kvm/arm64/handle_exit.c | 31 +++
arch/s390/kvm/arm64/handle_exit.h | 9 +
arch/s390/kvm/arm64/reset.c | 62 ++++++
arch/s390/kvm/arm64/reset.h | 11 +
7 files changed, 529 insertions(+)
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
diff --git a/arch/s390/kvm/arm64/arm.c b/arch/s390/kvm/arm64/arm.c
index 3a4092698fae..6ef47f7010be 100644
--- a/arch/s390/kvm/arm64/arm.c
+++ b/arch/s390/kvm/arm64/arm.c
@@ -7,12 +7,20 @@
#include <linux/kvm.h>
#include <linux/kvm_types.h>
#include <linux/kvm_host.h>
+#include <linux/fpu.h>
+#include <asm/access-regs.h>
+
+#include <arm64/kvm_emulate.h>
#include <arm64/kvm_mmu.h>
+#include <arm64/sysreg.h>
#include <gmap.h>
#include "arm.h"
+#include "guest.h"
+#include "handle_exit.h"
+#include "reset.h"
static unsigned long system_supported_vcpu_features(void);
@@ -201,6 +209,22 @@ void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu)
{
}
+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)
{
@@ -224,12 +248,332 @@ static unsigned long system_supported_vcpu_features(void)
return KVM_VCPU_VALID_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;
+
+ mutex_lock(&kvm->arch.config_lock);
+ set_bit(KVM_ARCH_FLAG_HAS_RAN_ONCE, &kvm->arch.flags);
+ mutex_unlock(&kvm->arch.config_lock);
+
+ 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;
+ int ret = -EINVAL;
+
+ mutex_lock(&kvm->arch.config_lock);
+
+ if (test_bit(KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED, &kvm->arch.flags) &&
+ kvm_vcpu_init_changed(vcpu, init))
+ goto out_unlock;
+
+ 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);
+
+ ret = 0;
+out_unlock:
+ mutex_unlock(&kvm->arch.config_lock);
+ return ret;
+}
+
+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;
+
+ spin_lock(&vcpu->arch.mp_state_lock);
+ WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_RUNNABLE);
+ spin_unlock(&vcpu->arch.mp_state_lock);
+
+ return 0;
+}
+
int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
bool line_status)
{
return 0;
}
+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;
+}
+
+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(®, 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, ®);
+ else
+ ret = kvm_arm_get_reg(vcpu, ®);
+ 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(®_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, ®_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)
{
diff --git a/arch/s390/kvm/arm64/guest.c b/arch/s390/kvm/arm64/guest.c
index 097195d446b2..1197c91e6324 100644
--- a/arch/s390/kvm/arm64/guest.c
+++ b/arch/s390/kvm/arm64/guest.c
@@ -57,6 +57,73 @@ unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu)
return num_core_regs(vcpu);
}
+int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
+{
+ /* We currently use nothing arch-specific in upper 32 bits */
+ if ((reg->id & ~KVM_REG_SIZE_MASK) >> 32 != KVM_REG_ARM64 >> 32)
+ return -EINVAL;
+
+ switch (reg->id & KVM_REG_ARM_COPROC_MASK) {
+ case KVM_REG_ARM_CORE:
+ return get_core_reg(vcpu, reg);
+ default:
+ return -EINVAL;
+ }
+}
+
+int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
+{
+ /* We currently use nothing arch-specific in upper 32 bits */
+ if ((reg->id & ~KVM_REG_SIZE_MASK) >> 32 != KVM_REG_ARM64 >> 32)
+ return -EINVAL;
+
+ switch (reg->id & KVM_REG_ARM_COPROC_MASK) {
+ case KVM_REG_ARM_CORE:
+ return set_core_reg(vcpu, reg);
+ default:
+ return -EINVAL;
+ }
+}
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
{
return -EINVAL;
diff --git a/arch/s390/kvm/arm64/guest.h b/arch/s390/kvm/arm64/guest.h
index 31c8bc799dbe..be367df99e31 100644
--- a/arch/s390/kvm/arm64/guest.h
+++ b/arch/s390/kvm/arm64/guest.h
@@ -5,5 +5,10 @@
#include <linux/kvm_host.h>
unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
+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);
+int kvm_arm_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr);
+int kvm_arm_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr);
+int kvm_arm_vcpu_has_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr);
#endif /* KVM_ARM_GUEST_H */
diff --git a/arch/s390/kvm/arm64/handle_exit.c b/arch/s390/kvm/arm64/handle_exit.c
index a0ebe5ffa19a..1cd19506b133 100644
--- a/arch/s390/kvm/arm64/handle_exit.c
+++ b/arch/s390/kvm/arm64/handle_exit.c
@@ -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 *);
exit_handle_fn arm_exit_handlers[ESR_ELx_EC_MAX + 1];
@@ -55,6 +57,35 @@ 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",
diff --git a/arch/s390/kvm/arm64/handle_exit.h b/arch/s390/kvm/arm64/handle_exit.h
new file mode 100644
index 000000000000..65ae58721537
--- /dev/null
+++ b/arch/s390/kvm/arm64/handle_exit.h
@@ -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 */
diff --git a/arch/s390/kvm/arm64/reset.c b/arch/s390/kvm/arm64/reset.c
new file mode 100644
index 000000000000..46edc792f843
--- /dev/null
+++ b/arch/s390/kvm/arm64/reset.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/kvm_host.h>
+
+#include <arm64/kvm_emulate.h>
+#include <arm64/kvm_nested.h>
+
+#include "reset.h"
+
+#define __INCL_GEN_ARM_FILE
+#include "generated/reset.inc"
+#undef __INCL_GEN_ARM_FILE
+
+bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu)
+{
+ return true;
+}
+
+void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
+{
+ struct vcpu_reset_state reset_state;
+ bool loaded;
+
+ spin_lock(&vcpu->arch.mp_state_lock);
+ reset_state = vcpu->arch.reset_state;
+ vcpu->arch.reset_state.reset = false;
+ spin_unlock(&vcpu->arch.mp_state_lock);
+
+ /*
+ * Disable preemption around the vcpu reset as we might otherwise race with
+ * preempt notifiers which call stiasrm/lasrm from put/load
+ */
+ preempt_disable();
+
+ /* The reset must run with an unloaded save area */
+ loaded = vcpu_is_loaded(vcpu);
+ if (loaded)
+ vcpu_put(vcpu);
+
+ kvm_reset_vcpu_core_regs(vcpu);
+
+ /* Reset special registers */
+ vcpu_reset_hcr(vcpu);
+
+ if (reset_state.reset) {
+ *vcpu_pc(vcpu) = reset_state.pc;
+ vcpu_clear_flag(vcpu, PENDING_EXCEPTION);
+ vcpu_clear_flag(vcpu, EXCEPT_MASK);
+ vcpu_clear_flag(vcpu, INCREMENT_PC);
+ vcpu_set_reg(vcpu, 0, reset_state.r0);
+ }
+
+ if (loaded)
+ vcpu_load(vcpu);
+
+ preempt_enable();
+}
+
+int kvm_arm_vcpu_finalize(struct kvm_vcpu *vcpu, int feature)
+{
+ return 0;
+}
diff --git a/arch/s390/kvm/arm64/reset.h b/arch/s390/kvm/arm64/reset.h
new file mode 100644
index 000000000000..a5c5304e47bc
--- /dev/null
+++ b/arch/s390/kvm/arm64/reset.h
@@ -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 */
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 26/27] KVM: s390: arm64: Implement basic page fault handler
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (24 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 25/27] KVM: s390: arm64: Implement vCPU IOCTLs Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 27/27] KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild Steffen Eiden
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
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.
Co-developed-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/s390/kvm/arm64/handle_exit.c | 2 +
arch/s390/kvm/arm64/mmio.c | 12 ++
arch/s390/kvm/arm64/mmu.c | 178 ++++++++++++++++++++++++++++++
3 files changed, 192 insertions(+)
create mode 100644 arch/s390/kvm/arm64/mmio.c
create mode 100644 arch/s390/kvm/arm64/mmu.c
diff --git a/arch/s390/kvm/arm64/handle_exit.c b/arch/s390/kvm/arm64/handle_exit.c
index 1cd19506b133..96a45483e5b6 100644
--- a/arch/s390/kvm/arm64/handle_exit.c
+++ b/arch/s390/kvm/arm64/handle_exit.c
@@ -55,6 +55,8 @@ static int handle_hvc(struct kvm_vcpu *vcpu)
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,
};
/*
diff --git a/arch/s390/kvm/arm64/mmio.c b/arch/s390/kvm/arm64/mmio.c
new file mode 100644
index 000000000000..cfddfe322196
--- /dev/null
+++ b/arch/s390/kvm/arm64/mmio.c
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/kvm_host.h>
+#include <linux/bitfield.h>
+
+#include <arm64/kvm_emulate.h>
+#include <arm64/kvm_mmu.h>
+#include <arm64/sysreg.h>
+
+#define __INCL_GEN_ARM_FILE
+#include "generated/mmio.inc"
+#undef __INCL_GEN_ARM_FILE
diff --git a/arch/s390/kvm/arm64/mmu.c b/arch/s390/kvm/arm64/mmu.c
new file mode 100644
index 000000000000..d5acabd762ba
--- /dev/null
+++ b/arch/s390/kvm/arm64/mmu.c
@@ -0,0 +1,178 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/kvm_host.h>
+
+#include <arm64/kvm_emulate.h>
+#include <arm64/kvm_mmu.h>
+
+#include <faultin.h>
+
+static inline bool kvm_s390_cur_gmap_fault_is_write(struct kvm_vcpu *vcpu)
+{
+ return vcpu->arch.sae_block.hai.pic == PGM_PROTECTION ||
+ vcpu->arch.sae_block.hai.teid.fsi == TEID_FSI_STORE;
+}
+
+/*
+ * user_mem_abort() - handle a dat fault for the gmap of a vcpu
+ *
+ * Return: 0 on success, < 0 in case of error.
+ * Context: The mm lock must not be held before calling. May sleep.
+ */
+static int user_mem_abort(struct kvm_vcpu *vcpu, gpa_t fault_ipa,
+ struct kvm_memory_slot *slot, hva_t hva)
+{
+ struct guest_fault f = { };
+ int ret;
+
+ if (kvm_s390_cur_gmap_fault_is_write(vcpu))
+ f.write_attempt = FOLL_WRITE;
+ f.gfn = gpa_to_gfn(fault_ipa);
+
+ ret = kvm_s390_faultin_gfn(vcpu, NULL, &f);
+ if (ret <= 0)
+ return ret;
+ if (ret == PGM_ADDRESSING)
+ /*
+ * Without the relevant sysregs we cannot do anything for now.
+ * Go back to userspace with an error. TODO sysreg handling
+ */
+ return -ENOEXEC;
+ KVM_BUG_ON(ret, vcpu->kvm);
+ return -EINVAL;
+}
+
+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:
+ 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");
+ 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;
+}
+
+int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)
+{
+ struct kvm_memory_slot *memslot;
+ bool translation = false;
+ phys_addr_t fault_ipa;
+ unsigned long esr;
+ unsigned long hva;
+ bool write_fault;
+ bool guest_size_err;
+ bool writable;
+ bool is_iabt;
+ int ret;
+ gfn_t gfn;
+ int idx;
+
+ esr = kvm_vcpu_get_esr(vcpu);
+ fault_ipa = kvm_vcpu_get_fault_ipa(vcpu);
+ is_iabt = kvm_vcpu_trap_is_iabt(vcpu);
+ guest_size_err = vcpu->arch.sae_block.icptr == SAE_ICPTR_GUEST_ADDRESS_SIZE;
+
+ if (guest_size_err) {
+ translation = true;
+ } else {
+ ret = kvm_handle_pic(vcpu, &translation);
+ if (ret)
+ return ret;
+ }
+
+ if (translation) {
+ /*
+ * For both cases:
+ * Without the relevant sysregs we cannot do anything for now.
+ * Go back to userspace with an error. TODO sysreg handling
+ */
+ if (fault_ipa >= BIT_ULL(get_kvm_ipa_limit()))
+ return -ENOEXEC;
+
+ if (fault_ipa >= kvm_phys_size(vcpu->kvm))
+ return -ENOEXEC;
+ }
+
+ idx = srcu_read_lock(&vcpu->kvm->srcu);
+
+ gfn = fault_ipa >> PAGE_SHIFT;
+
+ memslot = gfn_to_memslot(vcpu->kvm, gfn);
+ hva = gfn_to_hva_memslot_prot(memslot, gfn, &writable);
+ write_fault = kvm_is_write_fault(vcpu);
+ if (kvm_is_error_hva(hva) || (write_fault && !writable)) {
+ ret = -ENOEXEC;
+ /*
+ * The guest has put either its instructions or its page-tables
+ * somewhere it shouldn't have. Userspace won't be able to do
+ * anything about this (there's no syndrome for a start).
+ *
+ * Without the relevant sysregs we cannot do anything for now.
+ * Go back to userspace with an error. TODO sysreg handling
+ */
+ if (is_iabt)
+ goto out_unlock;
+
+ if (kvm_vcpu_abt_iss1tw(vcpu)) {
+ /*
+ * Without the relevant sysregs we cannot do anything for now.
+ * Go back to userspace with an error. TODO sysreg handling
+ */
+ goto out_unlock;
+ }
+
+ /*
+ * Check for a cache maintenance operation. Assume the guest is
+ * cautious and skip instruction
+ */
+ if (kvm_is_error_hva(hva) && kvm_vcpu_dabt_is_cm(vcpu)) {
+ kvm_incr_pc(vcpu);
+ ret = 1;
+ goto out_unlock;
+ }
+
+ /*
+ * The IPA is reported as [MAX:12], so we need to
+ * complement it with the bottom 12 bits from the
+ * faulting VA. This is always 12 bits, irrespective
+ * of the page size.
+ */
+ fault_ipa |= kvm_vcpu_get_hfar(vcpu) & ((1 << 12) - 1);
+ ret = io_mem_abort(vcpu, fault_ipa);
+ goto out_unlock;
+ }
+
+ /* Userspace should not be able to register out-of-bounds IPAs */
+ VM_BUG_ON(fault_ipa >= kvm_phys_size(vcpu->kvm));
+ /*
+ * Proper guest size faults have been injected.
+ * In theory it's fine to have device memory higher than MSL,
+ * even if not currently possible, but that would have been handled above.
+ * So if we get here with a guest size intercept, we have a bug somewhere.
+ */
+ VM_BUG_ON(guest_size_err);
+
+ ret = user_mem_abort(vcpu, fault_ipa, memslot, hva);
+ if (!ret)
+ ret = 1;
+out_unlock:
+ srcu_read_unlock(&vcpu->kvm->srcu, idx);
+ return ret;
+}
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH v4 27/27] KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
` (25 preceding siblings ...)
2026-07-06 8:52 ` [PATCH v4 26/27] KVM: s390: arm64: Implement basic page fault handler Steffen Eiden
@ 2026-07-06 8:52 ` Steffen Eiden
26 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 8:52 UTC (permalink / raw)
To: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
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.
Co-developed-by: Andreas Grapentin <gra@linux.ibm.com>
Signed-off-by: Andreas Grapentin <gra@linux.ibm.com>
Co-developed-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
Co-developed-by: Gautam Gala <ggala@linux.ibm.com>
Signed-off-by: Gautam Gala <ggala@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
---
arch/s390/configs/defconfig | 1 +
arch/s390/include/asm/Kbuild | 3 ++
arch/s390/kvm/Kconfig | 1 +
arch/s390/kvm/Makefile | 1 +
arch/s390/kvm/arm64/Kconfig | 23 +++++++++
arch/s390/kvm/arm64/Makefile | 94 ++++++++++++++++++++++++++++++++++++
6 files changed, 123 insertions(+)
create mode 100644 arch/s390/kvm/arm64/Kconfig
create mode 100644 arch/s390/kvm/arm64/Makefile
diff --git a/arch/s390/configs/defconfig b/arch/s390/configs/defconfig
index 327ab4a3933c..20de85c96e9e 100644
--- a/arch/s390/configs/defconfig
+++ b/arch/s390/configs/defconfig
@@ -62,6 +62,7 @@ CONFIG_CMM=m
CONFIG_APPLDATA_BASE=y
CONFIG_S390_HYPFS_FS=y
CONFIG_KVM_S390=m
+CONFIG_KVM_ARM64=m
CONFIG_S390_UNWIND_SELFTEST=m
CONFIG_S390_KPROBES_SANITY_TEST=m
CONFIG_S390_MODULES_SANITY_TEST=m
diff --git a/arch/s390/include/asm/Kbuild b/arch/s390/include/asm/Kbuild
index 0c1fc47c3ba0..f6fd67d1c651 100644
--- a/arch/s390/include/asm/Kbuild
+++ b/arch/s390/include/asm/Kbuild
@@ -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-gen-defs.h
+generated-y += kvm_arm64_modname.h
diff --git a/arch/s390/kvm/Kconfig b/arch/s390/kvm/Kconfig
index f8d4a9a38dae..bbae58aa8bc4 100644
--- a/arch/s390/kvm/Kconfig
+++ b/arch/s390/kvm/Kconfig
@@ -20,5 +20,6 @@ config KVM
tristate
source "arch/s390/kvm/s390/Kconfig"
+source "arch/s390/kvm/arm64/Kconfig"
endif # VIRTUALIZATION
diff --git a/arch/s390/kvm/Makefile b/arch/s390/kvm/Makefile
index c43d7dffca13..38bdd7c9b42d 100644
--- a/arch/s390/kvm/Makefile
+++ b/arch/s390/kvm/Makefile
@@ -4,3 +4,4 @@
# Copyright IBM Corp. 2008
obj-$(CONFIG_KVM_S390) += s390/
+obj-$(CONFIG_KVM_ARM64) += arm64/
diff --git a/arch/s390/kvm/arm64/Kconfig b/arch/s390/kvm/arm64/Kconfig
new file mode 100644
index 000000000000..99a7fc3b71c0
--- /dev/null
+++ b/arch/s390/kvm/arm64/Kconfig
@@ -0,0 +1,23 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config KVM_ARM64
+ def_tristate y
+ prompt "Kernel-based Virtual Machine (KVM) support for arm64 guests"
+ depends on HAS_IOMEM
+ select KVM
+ select KVM_VFIO
+ select IRQ_BYPASS_MANAGER
+ select SCHED_INFO
+ select XARRAY_MULTI
+ select KVM_COMMON
+ select HAVE_KVM_CPU_RELAX_INTERCEPT
+ select HAVE_KVM_MSI
+ select HAVE_KVM_IRQCHIP
+ select HAVE_KVM_IRQ_ROUTING
+ select HAVE_KVM_VCPU_RUN_PID_CHANGE
+ select KVM_GENERIC_PRE_FAULT_MEMORY
+ select GUEST_PERF_EVENTS if PERF_EVENTS
+ help
+ Support hosting virtualized arm64 guest machines on s390 host machines.
+
+ If unsure, say N.
diff --git a/arch/s390/kvm/arm64/Makefile b/arch/s390/kvm/arm64/Makefile
new file mode 100644
index 000000000000..566040725ab5
--- /dev/null
+++ b/arch/s390/kvm/arm64/Makefile
@@ -0,0 +1,94 @@
+# SPDX-License-Identifier: GPL-2.0
+
+KVM := ../../../../virt/kvm
+include $(srctree)/virt/kvm/Makefile.kvm
+KVM_MANAGES_S390_GUEST = n
+include $(srctree)/arch/s390/kvm/gmap/Makefile
+include $(src)/Makefile.gen
+
+ccflags-y += -I $(src) -I $(objtree)/$(obj) -I$(srctree)/arch/s390/kvm/gmap -I$(srctree)/arch/arm64/include -I$(srctree)/arch/arm64/kvm -DKVM_S390_ARM64
+
+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))
+
+targets += $(kvm-arm64-obj)
+
+$(obj)/%-arm64.o: $(src)/%.c FORCE
+ @mkdir -p $(dir $@)
+ $(call if_changed_rule,cc_o_c)
+
+ifeq ($(CONFIG_KVM_ARM64),m)
+
+kvm-arm64-y = $(kvm-arm64-obj)
+
+else ifeq ($(CONFIG_KVM_ARM64),y)
+
+KVM_ARM64_GEN_DIR := $(objtree)/arch/${SRCARCH}/include/generated/asm
+KVM_ARM64_MODNAME_H := $(KVM_ARM64_GEN_DIR)/kvm_arm64_modname.h
+ccflags-y += -include $(KVM_ARM64_MODNAME_H)
+
+targets += $(KVM_ARM64_MODNAME_H)
+
+quiet_cmd_kvm_arm64_modname_h = GEN $@
+ cmd_kvm_arm64_modname_h = { \
+ echo '/* Automatically generated; do not edit. */'; \
+ echo '\#ifndef _KVM_ARM64_MODNAME_H'; \
+ echo '\#define _KVM_ARM64_MODNAME_H'; \
+ echo '\#undef KBUILD_MODNAME'; \
+ echo '\#define KBUILD_MODNAME "kvm_arm64"'; \
+ echo '\#endif /* _KVM_ARM64_MODNAME_H */'; \
+ } > $@
+
+$(addprefix $(obj)/,$(kvm-arm64-obj)): $(KVM_ARM64_MODNAME_H)
+
+$(KVM_ARM64_MODNAME_H):
+ @mkdir -p $(KVM_ARM64_GEN_DIR)
+ $(call cmd,kvm_arm64_modname_h)
+
+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
+ $(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)
+
+# Make list of symbols to localize.
+# Collect normal/exported symbols. Use dict as set for deduplication.
+# TODO extract do script
+quiet_cmd_nm_filter = NMFLTR $@
+ cmd_nm_filter = $(NM) -jU $< | sort -u > $@
+
+$(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
+$(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
--
2.53.0
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: [PATCH v4 19/27] s390: Introduce Start Arm Execution instruction
2026-07-06 8:52 ` [PATCH v4 19/27] s390: Introduce Start Arm Execution instruction Steffen Eiden
@ 2026-07-06 11:17 ` Janosch Frank
2026-07-06 11:30 ` Christian Borntraeger
2026-07-06 11:53 ` Steffen Eiden
0 siblings, 2 replies; 41+ messages in thread
From: Janosch Frank @ 2026-07-06 11:17 UTC (permalink / raw)
To: Steffen Eiden, kvm, kvmarm, linux-arm-kernel, linux-kernel,
linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich, Joey Gouly,
Marc Zyngier, Nico Boehr, Nina Schoetterl-Glausch, Oliver Upton,
Paolo Bonzini, Suzuki K Poulose, Sven Schnelle, Ulrich Weigand,
Vasily Gorbik, Will Deacon, Zenghui Yu
On 7/6/26 10:52, Steffen Eiden wrote:
> 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.
>
[...]
> + u64 gpr[31]; /* 0x0300 */
> + u64 _03f8; /* 0x03f8 */
> +
> + union {
> + u64 icptd[8]; /* 0x0400 */
> + /* validity-interception reason; icptr 0x01 */
> +#define SAE_VIR_UNKNOWN 0x00
> +#define SAE_VIR_UNSUPP_FORMAT 0x01
> +#define SAE_VIR_MSO_BOUNDS 0x02
> +#define SAE_VIR_MSLA 0x03
> +#define SAE_VIR_MGPAS 0x04
> +#define SAE_VIR_INVAL_SYSREG 0x05
> +#define SAE_VIR_HOST_CONTROL 0x06
> +#define SAE_VIR_SCA 0x07
> +#define SAE_VIR_MSO_ALIGN 0x08
> +#define SAE_VIR_HLC 0x09
> +#define SAE_VIR_IRPTC 0x0a
Will these ever be used for something?
> + u16 vir; /* 0x0400 */
> + /* host access interception details; icptr 0x02 */
> + struct {
> + u64 esr_elz; /* 0x0400 */
> + u8 _0408[6]; /* 0x0408 */
> + u16 pic; /* 0x040e */
> + union teid teid; /* 0x0410 */
> + gva_t far_elz; /* 0x0418 */
> + gva_t vaddr; /* 0x0420 */
> + u64 suppl; /* 0x0428 */
> + u8 gltl; /* 0x0430 */
> + u8 _0431[7]; /* 0x0431 */
> + u64 _0438; /* 0x0438 */
> + } hai;
> + /* exception-interception details; icptr 0x03 */
> + struct {
> + u64 esr_elz; /* 0x0400 */
> + u64 _0408[2]; /* 0x0408 */
> + gva_t far_elz; /* 0x0418 */
> + } trap;
> + /* timer-interception reason; icptr 0x04 */
> +#define SAE_IR_TIMER_ID_VIRT BIT(6)
> +#define SAE_IR_TIMER_ID_PHYS BIT(7)
> + u8 tir; /* 0x0400 */
> + };
> + u64 _0440[376]; /* 0x0440 */
> +} __packed __aligned(PAGE_SIZE);
> +static_assert(sizeof(struct kvm_sae_block) == PAGE_SIZE);
> +
[...]
> +#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
> +# Let the next instruction be NOP to avoid triggering a machine check
> +# and handling it in a guest as result of the instruction execution.
@Christian:
I have the feeling things got lost in translation when this comment was
written.
How would we trigger a MCHECK by having an instruction after SIE/SAE?
AFAIU this allows us to have a label which we can check in the mcheck
handler to decide who triggered the mcheck.
Without the label the comment and NOP are useless as far as I can see.
So we need to decide if this still applies and then either remove it or
add sae handling to mcck_int_handler and maybe other mcheck functions.
> + nopr 7
> + 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 %r3,%r3
> + xgr %r2,%r2
> + 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.
> diff --git a/arch/s390/tools/opcodes.txt b/arch/s390/tools/opcodes.txt
> index def2659f6602..0e4773c94af0 100644
> --- a/arch/s390/tools/opcodes.txt
> +++ b/arch/s390/tools/opcodes.txt
> @@ -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
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v4 19/27] s390: Introduce Start Arm Execution instruction
2026-07-06 11:17 ` Janosch Frank
@ 2026-07-06 11:30 ` Christian Borntraeger
2026-07-06 11:58 ` Steffen Eiden
2026-07-06 11:53 ` Steffen Eiden
1 sibling, 1 reply; 41+ messages in thread
From: Christian Borntraeger @ 2026-07-06 11:30 UTC (permalink / raw)
To: Janosch Frank, Steffen Eiden, kvm, kvmarm, linux-arm-kernel,
linux-kernel, linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Claudio Imbrenda, David Hildenbrand,
Friedrich Welter, Gautam Gala, Hariharan Mari, Heiko Carstens,
Hendrik Brueckner, Ilya Leoshkevich, Joey Gouly, Marc Zyngier,
Nico Boehr, Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
Am 06.07.26 um 13:17 schrieb Janosch Frank:
>> +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
>> +# Let the next instruction be NOP to avoid triggering a machine check
>> +# and handling it in a guest as result of the instruction execution.
>
> @Christian:
> I have the feeling things got lost in translation when this comment was written.
> How would we trigger a MCHECK by having an instruction after SIE/SAE?
> AFAIU this allows us to have a label which we can check in the mcheck handler to decide who triggered the mcheck.
the original rationale was that some machine checks are nullifying some are terminating. So the PSW might point
to SAE or the instruction afterwards for a guest machine check.
In SIE, we use that nop to account any machine check on that nop as a guest machine check.
>
> Without the label the comment and NOP are useless as far as I can see.
> So we need to decide if this still applies and then either remove it or add sae handling to mcck_int_handler and maybe other mcheck functions.
We plan to get more information on the machine checks for sae so we might no longer need that.
But this series does not yet contain the machine check handling. Maybe its better to remove comment and
nop and introduce that later when we add machine check handling and if still needed.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v4 21/27] s390/hwcaps: Report SAE support as hwcap
2026-07-06 8:52 ` [PATCH v4 21/27] s390/hwcaps: Report SAE support as hwcap Steffen Eiden
@ 2026-07-06 11:50 ` Janosch Frank
0 siblings, 0 replies; 41+ messages in thread
From: Janosch Frank @ 2026-07-06 11:50 UTC (permalink / raw)
To: Steffen Eiden, kvm, kvmarm, linux-arm-kernel, linux-kernel,
linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich, Joey Gouly,
Marc Zyngier, Nico Boehr, Nina Schoetterl-Glausch, Oliver Upton,
Paolo Bonzini, Suzuki K Poulose, Sven Schnelle, Ulrich Weigand,
Vasily Gorbik, Will Deacon, Zenghui Yu
On 7/6/26 10:52, Steffen Eiden wrote:
> From: Hendrik Brueckner <brueckner@linux.ibm.com>
>
> Report SAE support as hwcap (and /proc/cpuinfo)
>
> Signed-off-by: Hendrik Brueckner <brueckner@linux.ibm.com>
> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v4 19/27] s390: Introduce Start Arm Execution instruction
2026-07-06 11:17 ` Janosch Frank
2026-07-06 11:30 ` Christian Borntraeger
@ 2026-07-06 11:53 ` Steffen Eiden
1 sibling, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 11:53 UTC (permalink / raw)
To: Janosch Frank
Cc: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390,
Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich, Joey Gouly,
Marc Zyngier, Nico Boehr, Nina Schoetterl-Glausch, Oliver Upton,
Paolo Bonzini, Suzuki K Poulose, Sven Schnelle, Ulrich Weigand,
Vasily Gorbik, Will Deacon, Zenghui Yu
On Mon, Jul 06, 2026 at 01:17:02PM +0200, Janosch Frank wrote:
> On 7/6/26 10:52, Steffen Eiden wrote:
> > 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.
> >
>
> [...]
>
> > + u64 gpr[31]; /* 0x0300 */
> > + u64 _03f8; /* 0x03f8 */
> > +
> > + union {
> > + u64 icptd[8]; /* 0x0400 */
> > + /* validity-interception reason; icptr 0x01 */
> > +#define SAE_VIR_UNKNOWN 0x00
> > +#define SAE_VIR_UNSUPP_FORMAT 0x01
> > +#define SAE_VIR_MSO_BOUNDS 0x02
> > +#define SAE_VIR_MSLA 0x03
> > +#define SAE_VIR_MGPAS 0x04
> > +#define SAE_VIR_INVAL_SYSREG 0x05
> > +#define SAE_VIR_HOST_CONTROL 0x06
> > +#define SAE_VIR_SCA 0x07
> > +#define SAE_VIR_MSO_ALIGN 0x08
> > +#define SAE_VIR_HLC 0x09
> > +#define SAE_VIR_IRPTC 0x0a
>
> Will these ever be used for something?
I'll remove them.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v4 19/27] s390: Introduce Start Arm Execution instruction
2026-07-06 11:30 ` Christian Borntraeger
@ 2026-07-06 11:58 ` Steffen Eiden
0 siblings, 0 replies; 41+ messages in thread
From: Steffen Eiden @ 2026-07-06 11:58 UTC (permalink / raw)
To: Christian Borntraeger
Cc: Janosch Frank, kvm, kvmarm, linux-arm-kernel, linux-kernel,
linux-s390, Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Claudio Imbrenda, David Hildenbrand,
Friedrich Welter, Gautam Gala, Hariharan Mari, Heiko Carstens,
Hendrik Brueckner, Ilya Leoshkevich, Joey Gouly, Marc Zyngier,
Nico Boehr, Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
On Mon, Jul 06, 2026 at 01:30:20PM +0200, Christian Borntraeger wrote:
>
>
> Am 06.07.26 um 13:17 schrieb Janosch Frank:
>
> > > +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
> > > +# Let the next instruction be NOP to avoid triggering a machine check
> > > +# and handling it in a guest as result of the instruction execution.
> >
> > @Christian:
> > I have the feeling things got lost in translation when this comment was written.
> > How would we trigger a MCHECK by having an instruction after SIE/SAE?
> > AFAIU this allows us to have a label which we can check in the mcheck handler to decide who triggered the mcheck.
>
> the original rationale was that some machine checks are nullifying some are terminating. So the PSW might point
> to SAE or the instruction afterwards for a guest machine check.
> In SIE, we use that nop to account any machine check on that nop as a guest machine check.
>
> >
> > Without the label the comment and NOP are useless as far as I can see.
> > So we need to decide if this still applies and then either remove it or add sae handling to mcck_int_handler and maybe other mcheck functions.
>
> We plan to get more information on the machine checks for sae so we might no longer need that.
> But this series does not yet contain the machine check handling. Maybe its better to remove comment and
> nop and introduce that later when we add machine check handling and if still needed.
Ok I'll remove the comment and the nop for the next round.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v4 23/27] KVM: s390: arm64: Implement required functions
2026-07-06 8:52 ` [PATCH v4 23/27] KVM: s390: arm64: Implement required functions Steffen Eiden
@ 2026-07-06 12:15 ` Janosch Frank
2026-07-06 20:35 ` Marc Zyngier
1 sibling, 0 replies; 41+ messages in thread
From: Janosch Frank @ 2026-07-06 12:15 UTC (permalink / raw)
To: Steffen Eiden, kvm, kvmarm, linux-arm-kernel, linux-kernel,
linux-s390
Cc: Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich, Joey Gouly,
Marc Zyngier, Nico Boehr, Nina Schoetterl-Glausch, Oliver Upton,
Paolo Bonzini, Suzuki K Poulose, Sven Schnelle, Ulrich Weigand,
Vasily Gorbik, Will Deacon, Zenghui Yu
On 7/6/26 10:52, Steffen Eiden wrote:
> 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.
>
> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
> ---
> arch/s390/include/arm64/kvm_emulate.h | 135 ++++++++++++++++++++++++++
> arch/s390/include/arm64/kvm_nested.h | 11 +++
> arch/s390/kvm/arm64/handle_exit.c | 110 +++++++++++++++++++++
> arch/s390/kvm/arm64/inject_fault.c | 21 ++++
> 4 files changed, 277 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/kvm/arm64/handle_exit.c
> create mode 100644 arch/s390/kvm/arm64/inject_fault.c
>
[...]
> +/* manually copied from arch/arm64/kernel/traps.c */
> +static const char * const esr_class_str[] = {
> + [0 ... ESR_ELx_EC_MAX] = "UNRECOGNIZED EC",
> + [ESR_ELx_EC_UNKNOWN] = "Unknown/Uncategorized",
> + [ESR_ELx_EC_WFx] = "WFI/WFE",
> + [ESR_ELx_EC_CP15_32] = "CP15 MCR/MRC",
> + [ESR_ELx_EC_CP15_64] = "CP15 MCRR/MRRC",
> + [ESR_ELx_EC_CP14_MR] = "CP14 MCR/MRC",
> + [ESR_ELx_EC_CP14_LS] = "CP14 LDC/STC",
> + [ESR_ELx_EC_FP_ASIMD] = "ASIMD",
> + [ESR_ELx_EC_CP10_ID] = "CP10 MRC/VMRS",
> + [ESR_ELx_EC_PAC] = "PAC",
> + [ESR_ELx_EC_CP14_64] = "CP14 MCRR/MRRC",
> + [ESR_ELx_EC_BTI] = "BTI",
> + [ESR_ELx_EC_ILL] = "PSTATE.IL",
> + [ESR_ELx_EC_SVC32] = "SVC (AArch32)",
> + [ESR_ELx_EC_HVC32] = "HVC (AArch32)",
> + [ESR_ELx_EC_SMC32] = "SMC (AArch32)",
> + [ESR_ELx_EC_SVC64] = "SVC (AArch64)",
> + [ESR_ELx_EC_HVC64] = "HVC (AArch64)",
> + [ESR_ELx_EC_SMC64] = "SMC (AArch64)",
> + [ESR_ELx_EC_SYS64] = "MSR/MRS (AArch64)",
> + [ESR_ELx_EC_SVE] = "SVE",
> + [ESR_ELx_EC_ERET] = "ERET/ERETAA/ERETAB",
> + [ESR_ELx_EC_FPAC] = "FPAC",
> + [ESR_ELx_EC_SME] = "SME",
> + [ESR_ELx_EC_IMP_DEF] = "EL3 IMP DEF",
> + [ESR_ELx_EC_IABT_LOW] = "IABT (lower EL)",
> + [ESR_ELx_EC_IABT_CUR] = "IABT (current EL)",
> + [ESR_ELx_EC_PC_ALIGN] = "PC Alignment",
> + [ESR_ELx_EC_DABT_LOW] = "DABT (lower EL)",
> + [ESR_ELx_EC_DABT_CUR] = "DABT (current EL)",
> + [ESR_ELx_EC_SP_ALIGN] = "SP Alignment",
> + [ESR_ELx_EC_MOPS] = "MOPS",
> + [ESR_ELx_EC_FP_EXC32] = "FP (AArch32)",
> + [ESR_ELx_EC_FP_EXC64] = "FP (AArch64)",
> + [ESR_ELx_EC_GCS] = "Guarded Control Stack",
> + [ESR_ELx_EC_SERROR] = "SError",
> + [ESR_ELx_EC_BREAKPT_LOW] = "Breakpoint (lower EL)",
> + [ESR_ELx_EC_BREAKPT_CUR] = "Breakpoint (current EL)",
> + [ESR_ELx_EC_SOFTSTP_LOW] = "Software Step (lower EL)",
> + [ESR_ELx_EC_SOFTSTP_CUR] = "Software Step (current EL)",
> + [ESR_ELx_EC_WATCHPT_LOW] = "Watchpoint (lower EL)",
> + [ESR_ELx_EC_WATCHPT_CUR] = "Watchpoint (current EL)",
> + [ESR_ELx_EC_BKPT32] = "BKPT (AArch32)",
> + [ESR_ELx_EC_VECTOR32] = "Vector catch (AArch32)",
> + [ESR_ELx_EC_BRK64] = "BRK (AArch64)",
> +};
> +
We could rip out the 32bit ones.
Not necessarily right now as it's easier to compare to the aarch64
implementation like this but at least at a later time.
I was also wondering if it would make sense to have all the feature
checks for unimplemented features in one file.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v4 09/27] KVM: arm64: Access elements of vcpu_gp_regs individually
2026-07-06 8:52 ` [PATCH v4 09/27] KVM: arm64: Access elements of vcpu_gp_regs individually Steffen Eiden
@ 2026-07-06 17:44 ` Marc Zyngier
0 siblings, 0 replies; 41+ messages in thread
From: Marc Zyngier @ 2026-07-06 17:44 UTC (permalink / raw)
To: Steffen Eiden
Cc: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390,
Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Nico Boehr, Nina Schoetterl-Glausch,
Oliver Upton, Paolo Bonzini, Suzuki K Poulose, Sven Schnelle,
Ulrich Weigand, Vasily Gorbik, Will Deacon, Zenghui Yu
On Mon, 06 Jul 2026 09:52:09 +0100,
Steffen Eiden <seiden@linux.ibm.com> wrote:
>
> 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.
That's an interesting change of semantics, because this excludes PC
from the GPRs. This is valid on AArch64, but wrong for AArch32 (PC
really is R15, and is just another GPR).
It isn't a huge deal, and nothing breaks, but that's something that
you may want to capture.
>
> Share the gp register functions with s390.
>
> No functional change.
>
> Co-developed-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
> Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
> ---
> arch/arm64/include/asm/kvm_emulate.h | 13 +++++++++----
> arch/arm64/include/asm/kvm_host.h | 8 +++++++-
> arch/arm64/kvm/guest.c | 19 +++++++++++--------
> arch/arm64/kvm/hyp/exception.c | 7 +++++--
> arch/arm64/kvm/hyp/include/hyp/adjust_pc.h | 4 ++--
> arch/arm64/kvm/hyp/include/hyp/switch.h | 6 +++---
> arch/arm64/kvm/reset.c | 6 ++++--
> 7 files changed, 41 insertions(+), 22 deletions(-)
>
> diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
> index a1c92d2436ae..15d6d6a08d37 100644
> --- a/arch/arm64/include/asm/kvm_emulate.h
> +++ b/arch/arm64/include/asm/kvm_emulate.h
> @@ -140,12 +140,17 @@ 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 unsigned long *vcpu_sp_el0(const struct kvm_vcpu *vcpu)
> +{
> + return (unsigned long *)&vcpu->arch.ctxt.regs.sp;
> }
>
> static __always_inline bool vcpu_mode_is_32bit(const struct kvm_vcpu *vcpu)
> @@ -175,14 +180,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;
> }
>
> #endif /* ARM64_S390_COMMON */
> diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
> index ae9f76378218..2fce38fd9152 100644
> --- a/arch/arm64/include/asm/kvm_host.h
> +++ b/arch/arm64/include/asm/kvm_host.h
> @@ -1170,7 +1170,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
> @@ -1201,6 +1201,12 @@ static inline u64 *___ctxt_sys_reg(const struct kvm_cpu_context *ctxt, int r)
>
> #define ctxt_sys_reg(c,r) (*__ctxt_sys_reg(c,r))
>
> +#define kvm_vcpu_get_sp_el1(__vcpu) (__ctxt_sys_reg(&(__vcpu)->arch.ctxt, SP_EL1))
> +#define kvm_vcpu_get_vreg(__vcpu, _n) (&(__vcpu)->arch.ctxt.fp_regs.vregs[_n])
> +#define kvm_vcpu_get_vregs(__vcpu) (&(__vcpu)->arch.ctxt.fp_regs.vregs)
> +#define kvm_vcpu_get_fpsr(__vcpu) (&(__vcpu)->arch.ctxt.fp_regs.fpsr)
> +#define kvm_vcpu_get_fpcr(__vcpu) (&(__vcpu)->arch.ctxt.fp_regs.fpcr)
> +
> u64 kvm_vcpu_apply_reg_masks(const struct kvm_vcpu *, enum vcpu_sysreg, u64);
>
> #define __vcpu_assign_sys_reg(v, r, val) \
> diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c
> index 5a202cfd27bc..5e1e1faa98c2 100644
> --- a/arch/arm64/kvm/guest.c
> +++ b/arch/arm64/kvm/guest.c
> @@ -62,6 +62,7 @@ const struct kvm_stats_header kvm_vcpu_stats_header = {
> sizeof(kvm_vcpu_stats_desc),
> };
>
> +#ifdef ARM64_S390_COMMON
I really think this patch (and a few others) needs splitting. What I'd
like to see is a prefix to this series adding the required arm64
rework, and only in a subsequent patch add the "make this shared"
attributes.
Also, quite a lot of this patch is about using the existing accessors
instead of an open-coded version. These changes should be standalone.
> static bool core_reg_offset_is_vreg(u64 off)
> {
> return off >= KVM_REG_ARM_CORE_REG(fp_regs.vregs) &&
> @@ -134,19 +135,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 kvm_vcpu_get_sp_el1(vcpu);
>
> case KVM_REG_ARM_CORE_REG(elr_el1):
> return __ctxt_sys_reg(&vcpu->arch.ctxt, ELR_EL1);
> @@ -170,13 +171,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 kvm_vcpu_get_vreg(vcpu, off);
>
> case KVM_REG_ARM_CORE_REG(fp_regs.fpsr):
> - return &vcpu->arch.ctxt.fp_regs.fpsr;
> + return kvm_vcpu_get_fpsr(vcpu);
>
> case KVM_REG_ARM_CORE_REG(fp_regs.fpcr):
> - return &vcpu->arch.ctxt.fp_regs.fpcr;
> + return kvm_vcpu_get_fpcr(vcpu);
Odd additional spaces (3 instances).
>
> default:
> return NULL;
> @@ -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)))
> diff --git a/arch/arm64/kvm/hyp/exception.c b/arch/arm64/kvm/hyp/exception.c
> index bef40ddb16db..82611442a2d1 100644
> --- a/arch/arm64/kvm/hyp/exception.c
> +++ b/arch/arm64/kvm/hyp/exception.c
> @@ -277,6 +277,9 @@ static const u8 return_offsets[8][2] = {
> [7] = { 4, 4 }, /* FIQ, unused */
> };
>
> +#define OFFSETOF_PT_REG(__r) offsetof(struct user_pt_regs, __r)
> +#define COMPAT_IDX(__c) ((OFFSETOF_PT_REG(__c) - OFFSETOF_PT_REG(regs[0])) / sizeof(u64))
> +
Oh $gawd, this is... awful.
> static void enter_exception32(struct kvm_vcpu *vcpu, u32 mode, u32 vect_offset)
> {
> unsigned long spsr = *vcpu_cpsr(vcpu);
> @@ -292,12 +295,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_IDX(compat_lr_abt)] = return_address;
> break;
Stupid idea: why don't you simply have new #defines that make the
register number standalone, and make ptrace.h use that? Something line
this (which can obviously be extended to all the compat registers):
diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h
index 39582511ad72f..2d3d324d2598e 100644
--- a/arch/arm64/include/asm/ptrace.h
+++ b/arch/arm64/include/asm/ptrace.h
@@ -104,6 +104,10 @@
#define COMPAT_USER_SZ 296
/* Architecturally defined mapping between AArch32 and AArch64 registers */
+enum aarch32_reg_mapping {
+ __compat_lr_und = 22,
+};
+
#define compat_usr(x) regs[(x)]
#define compat_fp regs[11]
#define compat_sp regs[13]
@@ -115,7 +119,7 @@
#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_lr_und regs[__compat_lr_und]
#define compat_sp_und regs[23]
#define compat_r8_fiq regs[24]
#define compat_r9_fiq regs[25]
and then your #defines from hell can go?
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: [PATCH v4 01/27] VFIO: take reference to the KVM module
2026-07-06 8:52 ` [PATCH v4 01/27] VFIO: take reference to the KVM module Steffen Eiden
@ 2026-07-06 19:53 ` Jason Gunthorpe
2026-07-06 21:12 ` Sean Christopherson
0 siblings, 1 reply; 41+ messages in thread
From: Jason Gunthorpe @ 2026-07-06 19:53 UTC (permalink / raw)
To: Steffen Eiden
Cc: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390,
Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
On Mon, Jul 06, 2026 at 10:52:01AM +0200, Steffen Eiden wrote:
> From: Paolo Bonzini <pbonzini@redhat.com>
>
> VFIO is implicitly taking a reference to the KVM module between
> vfio_device_get_kvm_safe and vfio_device_put_kvm, thanks to
> symbol_get and symbol_put.
I thought we weren't doing this approach? Use the struct file as the
kvm handle. I thought I saw patches doing that already?
Jason
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v4 23/27] KVM: s390: arm64: Implement required functions
2026-07-06 8:52 ` [PATCH v4 23/27] KVM: s390: arm64: Implement required functions Steffen Eiden
2026-07-06 12:15 ` Janosch Frank
@ 2026-07-06 20:35 ` Marc Zyngier
1 sibling, 0 replies; 41+ messages in thread
From: Marc Zyngier @ 2026-07-06 20:35 UTC (permalink / raw)
To: Steffen Eiden
Cc: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390,
Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Nico Boehr, Nina Schoetterl-Glausch,
Oliver Upton, Paolo Bonzini, Suzuki K Poulose, Sven Schnelle,
Ulrich Weigand, Vasily Gorbik, Will Deacon, Zenghui Yu
On Mon, 06 Jul 2026 09:52:23 +0100,
Steffen Eiden <seiden@linux.ibm.com> wrote:
>
> 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.
>
> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
> ---
> arch/s390/include/arm64/kvm_emulate.h | 135 ++++++++++++++++++++++++++
> arch/s390/include/arm64/kvm_nested.h | 11 +++
> arch/s390/kvm/arm64/handle_exit.c | 110 +++++++++++++++++++++
> arch/s390/kvm/arm64/inject_fault.c | 21 ++++
> 4 files changed, 277 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/kvm/arm64/handle_exit.c
> create mode 100644 arch/s390/kvm/arm64/inject_fault.c
>
> diff --git a/arch/s390/include/arm64/kvm_emulate.h b/arch/s390/include/arm64/kvm_emulate.h
> new file mode 100644
> index 000000000000..6ad21398f86f
> --- /dev/null
> +++ b/arch/s390/include/arm64/kvm_emulate.h
> @@ -0,0 +1,135 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#ifndef __S390_ARM64_KVM_EMULATE_H__
> +#define __S390_ARM64_KVM_EMULATE_H__
> +
> +#include <asm/fault.h>
> +#include <asm/ptrace.h>
> +#include <linux/kvm_host.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 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 __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 void vcpu_reset_hcr(struct kvm_vcpu *vcpu)
> +{
> + vcpu->arch.hcr_elz = HCR_E2H | HCR_RW | HCR_AMO | HCR_IMO | HCR_FMO |
> + HCR_PTW;
> + /* traps */
> + vcpu->arch.hcr_elz |= HCR_TSC | HCR_TID1 | HCR_TID2 | HCR_TID3 |
> + HCR_TID4 | HCR_TID5 | HCR_TIDCP;
Since this is new code, consider using the generated symbols
(HCR_EL2_*). I intend to get rid of the compat symbols at some point.
> +}
> +
> +static inline unsigned long vcpu_get_vsesr(struct kvm_vcpu *vcpu)
> +{
> + WARN(true, "not implemented, just feat RAS");
WARN_ONCE() should be enough. And really, this code shouldn't be
reachable at all.
> +
> + return 0L;
> +}
> +
> +static inline void vcpu_set_vsesr(struct kvm_vcpu *vcpu, u64 vsesr)
> +{
> + WARN(true, "not implemented, just feat RAS");
Same thing.
> +}
> +
> +static inline bool vcpu_el2_tge_is_set(const 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 is_hyp_ctxt(const struct kvm_vcpu *vcpu)
> +{
> + return false;
> +}
> +
> +static inline bool is_nested_ctxt(struct kvm_vcpu *vcpu)
> +{
> + return false;
> +}
> +
> +static inline bool vcpu_mode_priv(const struct kvm_vcpu *vcpu)
> +{
> + u32 mode = *vcpu_cpsr(vcpu) & PSR_MODE_MASK;
> +
> + return mode != PSR_MODE_EL0t;
> +}
> +
> +#define SPSR_SS BIT(21)
We may be better off defining SPSR_ELx in the sysreg file and use that
all over the place.
> +
> +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_SS;
> +}
> +
> +#include <arm64/kvm_emulate-part.h>
> +
> +#endif /* __S390_ARM64_KVM_EMULATE_H__ */
> diff --git a/arch/s390/include/arm64/kvm_nested.h b/arch/s390/include/arm64/kvm_nested.h
> new file mode 100644
> index 000000000000..e950b1a10c41
> --- /dev/null
> +++ b/arch/s390/include/arm64/kvm_nested.h
> @@ -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 */
> diff --git a/arch/s390/kvm/arm64/handle_exit.c b/arch/s390/kvm/arm64/handle_exit.c
> new file mode 100644
> index 000000000000..a0ebe5ffa19a
> --- /dev/null
> +++ b/arch/s390/kvm/arm64/handle_exit.c
> @@ -0,0 +1,110 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <linux/kvm_host.h>
> +
> +#include <arm64/esr.h>
> +#include <arm64/kvm_emulate.h>
> +
> +typedef int (*exit_handle_fn)(struct kvm_vcpu *);
> +exit_handle_fn arm_exit_handlers[ESR_ELx_EC_MAX + 1];
> +
> +#define __INCL_GEN_ARM_FILE
> +#include "generated/handle_exit.inc"
> +#undef __INCL_GEN_ARM_FILE
> +
> +#define PSCI_0_2_FN_SYSTEM_OFF 0x84000008
> +#define PSCI_RET_NOT_SUPPORTED -1
> +#define PSCI_RET_INTERNAL_FAILURE -6
All of this exists in include/uapi/linux/psci.h.
> +/*
> + * Temporary smc/hvc handler. Non-compliant implementation (features missing).
> + * Implements only system off so that test programs are able to end their execution
> + */
> +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) {
> + spin_lock(&vcpu->arch.mp_state_lock);
> + WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_STOPPED);
> + spin_unlock(&vcpu->arch.mp_state_lock);
scoped_guard()?
> + kvm_make_all_cpus_request(vcpu->kvm, KVM_REQ_SLEEP);
> + memset(&vcpu->run->system_event, 0,
> + sizeof(vcpu->run->system_event));
> + vcpu->run->system_event.type = KVM_SYSTEM_EVENT_SHUTDOWN;
> + vcpu->run->system_event.ndata = 1;
> + vcpu->run->system_event.data[0] = 0;
> + vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
> + val = PSCI_RET_INTERNAL_FAILURE;
> + ret = 0;
> + }
> + vcpu_set_reg(vcpu, 0, val);
> +
> + return ret;
> +}
> +
> +static int handle_hvc(struct kvm_vcpu *vcpu)
> +{
> + vcpu->stat.hvc_exit_stat++;
> + return kvm_smccc_call_handler(vcpu);
> +}
> +
> +exit_handle_fn arm_exit_handlers[] = {
> + [0 ... ESR_ELx_EC_MAX] = kvm_handle_unknown_ec,
> + [ESR_ELx_EC_HVC64] = handle_hvc,
> +};
> +
> +/* manually copied from arch/arm64/kernel/traps.c */
> +static const char * const esr_class_str[] = {
> + [0 ... ESR_ELx_EC_MAX] = "UNRECOGNIZED EC",
> + [ESR_ELx_EC_UNKNOWN] = "Unknown/Uncategorized",
> + [ESR_ELx_EC_WFx] = "WFI/WFE",
> + [ESR_ELx_EC_CP15_32] = "CP15 MCR/MRC",
> + [ESR_ELx_EC_CP15_64] = "CP15 MCRR/MRRC",
> + [ESR_ELx_EC_CP14_MR] = "CP14 MCR/MRC",
> + [ESR_ELx_EC_CP14_LS] = "CP14 LDC/STC",
> + [ESR_ELx_EC_FP_ASIMD] = "ASIMD",
> + [ESR_ELx_EC_CP10_ID] = "CP10 MRC/VMRS",
> + [ESR_ELx_EC_PAC] = "PAC",
> + [ESR_ELx_EC_CP14_64] = "CP14 MCRR/MRRC",
> + [ESR_ELx_EC_BTI] = "BTI",
> + [ESR_ELx_EC_ILL] = "PSTATE.IL",
> + [ESR_ELx_EC_SVC32] = "SVC (AArch32)",
> + [ESR_ELx_EC_HVC32] = "HVC (AArch32)",
> + [ESR_ELx_EC_SMC32] = "SMC (AArch32)",
> + [ESR_ELx_EC_SVC64] = "SVC (AArch64)",
> + [ESR_ELx_EC_HVC64] = "HVC (AArch64)",
> + [ESR_ELx_EC_SMC64] = "SMC (AArch64)",
> + [ESR_ELx_EC_SYS64] = "MSR/MRS (AArch64)",
> + [ESR_ELx_EC_SVE] = "SVE",
> + [ESR_ELx_EC_ERET] = "ERET/ERETAA/ERETAB",
> + [ESR_ELx_EC_FPAC] = "FPAC",
> + [ESR_ELx_EC_SME] = "SME",
> + [ESR_ELx_EC_IMP_DEF] = "EL3 IMP DEF",
> + [ESR_ELx_EC_IABT_LOW] = "IABT (lower EL)",
> + [ESR_ELx_EC_IABT_CUR] = "IABT (current EL)",
> + [ESR_ELx_EC_PC_ALIGN] = "PC Alignment",
> + [ESR_ELx_EC_DABT_LOW] = "DABT (lower EL)",
> + [ESR_ELx_EC_DABT_CUR] = "DABT (current EL)",
> + [ESR_ELx_EC_SP_ALIGN] = "SP Alignment",
> + [ESR_ELx_EC_MOPS] = "MOPS",
> + [ESR_ELx_EC_FP_EXC32] = "FP (AArch32)",
> + [ESR_ELx_EC_FP_EXC64] = "FP (AArch64)",
> + [ESR_ELx_EC_GCS] = "Guarded Control Stack",
> + [ESR_ELx_EC_SERROR] = "SError",
> + [ESR_ELx_EC_BREAKPT_LOW] = "Breakpoint (lower EL)",
> + [ESR_ELx_EC_BREAKPT_CUR] = "Breakpoint (current EL)",
> + [ESR_ELx_EC_SOFTSTP_LOW] = "Software Step (lower EL)",
> + [ESR_ELx_EC_SOFTSTP_CUR] = "Software Step (current EL)",
> + [ESR_ELx_EC_WATCHPT_LOW] = "Watchpoint (lower EL)",
> + [ESR_ELx_EC_WATCHPT_CUR] = "Watchpoint (current EL)",
> + [ESR_ELx_EC_BKPT32] = "BKPT (AArch32)",
> + [ESR_ELx_EC_VECTOR32] = "Vector catch (AArch32)",
> + [ESR_ELx_EC_BRK64] = "BRK (AArch64)",
> +};
There are a lot of AArch32-specific ECs here that you may not need.
Thanks,
M.
--
Jazz isn't dead. It just smells funny.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v4 05/27] KVM: Remove KVM_MMIO as config option
2026-07-06 8:52 ` [PATCH v4 05/27] KVM: Remove KVM_MMIO as config option Steffen Eiden
@ 2026-07-06 20:53 ` Marc Zyngier
0 siblings, 0 replies; 41+ messages in thread
From: Marc Zyngier @ 2026-07-06 20:53 UTC (permalink / raw)
To: Steffen Eiden
Cc: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390,
Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Nico Boehr, Nina Schoetterl-Glausch,
Oliver Upton, Paolo Bonzini, Suzuki K Poulose, Sven Schnelle,
Ulrich Weigand, Vasily Gorbik, Will Deacon, Zenghui Yu
On Mon, 06 Jul 2026 09:52:05 +0100,
Steffen Eiden <seiden@linux.ibm.com> wrote:
>
> Defining KVM_MMIO is not flexible enough for multi-KVM systems with
> different Kconfig options regarding KVM_MMIO. Therefore, remove KVM_MMIO
> from the config space and use the macro HAVE_KVM_MMIO instead.
>
Given that there is only one KVM architecture that doesn't use
KVM_MMIO, it feels like the polarity of this symbol is the wrong way
around.
Something like KVM_NO_MMIO, only exposed by S390 for its native
support, should significantly reduce the churn.
Thanks,
M.
--
Jazz isn't dead. It just smells funny.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v4 01/27] VFIO: take reference to the KVM module
2026-07-06 19:53 ` Jason Gunthorpe
@ 2026-07-06 21:12 ` Sean Christopherson
0 siblings, 0 replies; 41+ messages in thread
From: Sean Christopherson @ 2026-07-06 21:12 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Steffen Eiden, kvm, kvmarm, linux-arm-kernel, linux-kernel,
linux-s390, Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Marc Zyngier, Nico Boehr,
Nina Schoetterl-Glausch, Oliver Upton, Paolo Bonzini,
Suzuki K Poulose, Sven Schnelle, Ulrich Weigand, Vasily Gorbik,
Will Deacon, Zenghui Yu
On Mon, Jul 06, 2026, Jason Gunthorpe wrote:
> On Mon, Jul 06, 2026 at 10:52:01AM +0200, Steffen Eiden wrote:
> > From: Paolo Bonzini <pbonzini@redhat.com>
> >
> > VFIO is implicitly taking a reference to the KVM module between
> > vfio_device_get_kvm_safe and vfio_device_put_kvm, thanks to
> > symbol_get and symbol_put.
>
> I thought we weren't doing this approach? Use the struct file as the
> kvm handle. I thought I saw patches doing that already?
+1, my joking-but-serious NAK stands.
https://lore.kernel.org/all/adf29Rn7q9Db0hxc@google.com
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v4 07/27] arm64: Prepare sharing arm64 headers with s390
2026-07-06 8:52 ` [PATCH v4 07/27] arm64: Prepare sharing arm64 headers with s390 Steffen Eiden
@ 2026-07-06 21:22 ` Marc Zyngier
0 siblings, 0 replies; 41+ messages in thread
From: Marc Zyngier @ 2026-07-06 21:22 UTC (permalink / raw)
To: Steffen Eiden
Cc: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390,
Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Nico Boehr, Nina Schoetterl-Glausch,
Oliver Upton, Paolo Bonzini, Suzuki K Poulose, Sven Schnelle,
Ulrich Weigand, Vasily Gorbik, Will Deacon, Zenghui Yu
On Mon, 06 Jul 2026 09:52:07 +0100,
Steffen Eiden <seiden@linux.ibm.com> wrote:
>
> Prepare the sharing of arm64 headers with s390 by marking the shared
> regions or add a comment that the whole file is shared.
> The regions are marked with:
>
> #define ARM64_S390_COMMON
>
> /* insert shared definitions here */
>
> #endif /* ARM64_S390_COMMON */
>
> The preprocessor symbol ARM64_S390_COMMON is always defined for arm64.
> Reduce the include scope where possible and beneficial for s390.
> No functional change.
>
> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
> ---
> 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 | 19 ++++++++++++++++++
> arch/arm64/include/asm/kvm_host.h | 28 +++++++++++++++++++++++++++
> arch/arm64/include/asm/kvm_mmu.h | 6 ++++++
> arch/arm64/include/asm/ptrace.h | 9 +++++++++
> arch/arm64/include/asm/sysreg.h | 29 +++++++++++++++++++++++++---
> 9 files changed, 98 insertions(+), 7 deletions(-)
>
> diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
> index 6b005c8fef70..1cd7cd94a855 100644
> --- a/arch/arm64/Makefile
> +++ b/arch/arm64/Makefile
> @@ -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
> diff --git a/arch/arm64/include/asm/brk-imm.h b/arch/arm64/include/asm/brk-imm.h
> index beb42c62b6ac..dd2d153dc0d8 100644
> --- a/arch/arm64/include/asm/brk-imm.h
> +++ b/arch/arm64/include/asm/brk-imm.h
> @@ -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
> diff --git a/arch/arm64/include/asm/esr.h b/arch/arm64/include/asm/esr.h
> index 81c17320a588..e25b742b09ac 100644
> --- a/arch/arm64/include/asm/esr.h
> +++ b/arch/arm64/include/asm/esr.h
> @@ -3,11 +3,12 @@
> * Copyright (C) 2013 - ARM Ltd
> * Author: Marc Zyngier <marc.zyngier@arm.com>
> */
> +/* Whole file is shared with s390 */
>
> #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 +436,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)
> {
> diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h
> index 3f9233b5a130..cc4175176f94 100644
> --- a/arch/arm64/include/asm/kvm_arm.h
> +++ b/arch/arm64/include/asm/kvm_arm.h
> @@ -3,14 +3,16 @@
> * Copyright (C) 2012,2013 - ARM Ltd
> * Author: Marc Zyngier <marc.zyngier@arm.com>
> */
> +/* Whole file is shared with s390 */
>
> #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
> diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
> index 5bf3d7e1d92c..a1c92d2436ae 100644
> --- a/arch/arm64/include/asm/kvm_emulate.h
> +++ b/arch/arm64/include/asm/kvm_emulate.h
> @@ -44,13 +44,18 @@ enum exception_type {
> bool kvm_condition_valid32(const struct kvm_vcpu *vcpu);
> void kvm_skip_instr32(struct kvm_vcpu *vcpu);
>
> +#ifdef ARM64_S390_COMMON
> void kvm_inject_undefined(struct kvm_vcpu *vcpu);
> +#endif /* ARM64_S390_COMMON */
> void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr);
> int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr);
> +#ifdef ARM64_S390_COMMON
> int kvm_inject_sea(struct kvm_vcpu *vcpu, bool iabt, u64 addr);
> +#endif /* ARM64_S390_COMMON */
> int kvm_inject_dabt_excl_atomic(struct kvm_vcpu *vcpu, u64 addr);
> void kvm_inject_size_fault(struct kvm_vcpu *vcpu);
>
> +#ifdef ARM64_S390_COMMON
> static inline int kvm_inject_sea_dabt(struct kvm_vcpu *vcpu, u64 addr)
> {
> return kvm_inject_sea(vcpu, false, addr);
> @@ -61,6 +66,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)
> {
> /*
> @@ -159,6 +166,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
> @@ -177,6 +185,8 @@ static __always_inline void vcpu_set_reg(struct kvm_vcpu *vcpu, u8 reg_num,
> vcpu_gp_regs(vcpu)->regs[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)) {
> @@ -360,6 +370,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;
> @@ -437,6 +448,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)
> {
> @@ -477,6 +490,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)) {
> @@ -501,6 +515,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;
> @@ -536,6 +552,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)
> @@ -611,6 +628,8 @@ static __always_inline void kvm_incr_pc(struct kvm_vcpu *vcpu)
> vcpu_set_flag((v), e); \
> } while (0)
>
> +#endif /* ARM64_S390_COMMON */
> +
It'd be worth looking at an initial patch reorganising this file to
minimise the number of such markers. This is equally valid for other
files in this patch.
[...]
> diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h
> index 6eae7e7e2a68..b782cae771fe 100644
> --- a/arch/arm64/include/asm/kvm_mmu.h
> +++ b/arch/arm64/include/asm/kvm_mmu.h
> @@ -142,12 +142,15 @@ static __always_inline unsigned long __kern_hyp_va(unsigned long v)
>
> extern u32 __hyp_va_bits;
>
> +#ifdef ARM64_S390_COMMON
> /*
> * We currently support using a VM-specified IPA size. For backward
> * compatibility, the default IPA size is fixed to 40bits.
> */
> #define KVM_PHYS_SHIFT (40)
>
> +#endif /* ARM64_S390_COMMON */
> +
> #define kvm_phys_shift(mmu) VTCR_EL2_IPA((mmu)->vtcr)
> #define kvm_phys_size(mmu) (_AC(1, ULL) << kvm_phys_shift(mmu))
> #define kvm_phys_mask(mmu) (kvm_phys_size(mmu) - _AC(1, ULL))
> @@ -178,9 +181,12 @@ void stage2_unmap_vm(struct kvm *kvm);
> int kvm_init_stage2_mmu(struct kvm *kvm, struct kvm_s2_mmu *mmu, unsigned long type);
> void kvm_uninit_stage2_mmu(struct kvm *kvm);
> void kvm_free_stage2_pgd(struct kvm_s2_mmu *mmu);
> +#ifdef ARM64_S390_COMMON
> int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa,
> phys_addr_t pa, unsigned long size, bool writable);
This only serves a purpose for GICv2, and I really hope your HW will
not implement this. You should probably find a way to avoid dragging
stuff that doesn't make sense on s390.
>
> +#endif /* ARM64_S390_COMMON */
> +
> int kvm_handle_guest_sea(struct kvm_vcpu *vcpu);
> int kvm_handle_guest_abort(struct kvm_vcpu *vcpu);
>
> diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h
> index 39582511ad72..6eb122eb5fa6 100644
> --- a/arch/arm64/include/asm/ptrace.h
> +++ b/arch/arm64/include/asm/ptrace.h
> @@ -10,8 +10,13 @@
>
> #include <asm/cpufeature.h>
>
> +#ifdef ARM64_S390_COMMON
> +#include <asm/sysreg.h>
> +
> #include <uapi/asm/ptrace.h>
>
> +#endif /* ARM64_S390_COMMON */
> +
> /* Current Exception Level values, as contained in CurrentEL */
> #define CurrentEL_EL1 (1 << 2)
> #define CurrentEL_EL2 (2 << 2)
> @@ -28,6 +33,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)
> @@ -68,6 +75,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
> diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
> index 4bfdac9401bd..58912a6b6fcd 100644
> --- a/arch/arm64/include/asm/sysreg.h
> +++ b/arch/arm64/include/asm/sysreg.h
> @@ -9,13 +9,17 @@
> #ifndef __ASM_SYSREG_H
> #define __ASM_SYSREG_H
>
> +#ifdef ARM64_S390_COMMON
> #include <linux/bits.h>
> +#endif /* ARM64_S390_COMMON */
> #include <linux/stringify.h>
> #include <linux/kasan-tags.h>
> #include <linux/kconfig.h>
>
> #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 +54,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__
> @@ -79,6 +85,8 @@
>
> #endif /* CONFIG_BROKEN_GAS_INST */
>
> +#ifdef ARM64_S390_COMMON
> +
> /*
> * Instructions for modifying PSTATE fields.
> * As per Arm ARM for v8-A, Section "C.5.1.3 op0 == 0b00, architectural hints,
> @@ -91,8 +99,6 @@
> */
> #define pstate_field(op1, op2) ((op1) << Op1_shift | (op2) << Op2_shift)
> #define PSTATE_Imm_shift CRm_shift
> -#define ENCODE_PSTATE(x, r) (0xd500401f | PSTATE_ ## r | ((!!x) << PSTATE_Imm_shift))
> -#define SET_PSTATE(x, r) __emit_inst(ENCODE_PSTATE(x, r))
>
> #define PSTATE_PAN pstate_field(0, 4)
> #define PSTATE_UAO pstate_field(0, 3)
> @@ -100,6 +106,11 @@
> #define PSTATE_DIT pstate_field(3, 2)
> #define PSTATE_TCO pstate_field(3, 4)
>
> +#endif /* ARM64_S390_COMMON */
> +
> +#define ENCODE_PSTATE(x, r) (0xd500401f | PSTATE_ ## r | ((!!x) << PSTATE_Imm_shift))
> +#define SET_PSTATE(x, r) __emit_inst(ENCODE_PSTATE(x, r))
> +
> #define SET_PSTATE_PAN(x) SET_PSTATE((x), PAN)
> #define SET_PSTATE_UAO(x) SET_PSTATE((x), UAO)
> #define SET_PSTATE_SSBS(x) SET_PSTATE((x), SSBS)
> @@ -123,6 +134,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)
What is the reason to avoid dragging these definitions? They seem
extremely similar to the rest.
>
> +#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)
> @@ -835,6 +848,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
> @@ -869,6 +884,8 @@
> 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)
> @@ -1105,6 +1122,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)
>
> @@ -1254,6 +1273,8 @@
> par; \
> })
>
> +#ifdef ARM64_S390_COMMON
> +
> #define SYS_FIELD_VALUE(reg, field, val) reg##_##field##_##val
>
> #define SYS_FIELD_GET(reg, field, val) \
> @@ -1266,6 +1287,8 @@
> FIELD_PREP(reg##_##field##_MASK, \
> SYS_FIELD_VALUE(reg, field, val))
>
> -#endif
> +#endif /* ARM64_S390_COMMON */
> +
> +#endif /* __ASSEMBLER__ */
>
> #endif /* __ASM_SYSREG_H */
Overall, the fine-grained tagging is a bit hard to read, and there is
no obvious rationale on why some bits are needed, and not others are
not.
It definitely looks more manageable than the previous iteration, but
as I said above, it would benefit from a less scattergun approach.
Thanks,
M.
--
Jazz isn't dead. It just smells funny.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH v4 08/27] KVM: arm64: Prepare sharing arm64 code with s390
2026-07-06 8:52 ` [PATCH v4 08/27] KVM: arm64: Prepare sharing arm64 code " Steffen Eiden
@ 2026-07-06 21:28 ` Marc Zyngier
0 siblings, 0 replies; 41+ messages in thread
From: Marc Zyngier @ 2026-07-06 21:28 UTC (permalink / raw)
To: Steffen Eiden
Cc: kvm, kvmarm, linux-arm-kernel, linux-kernel, linux-s390,
Alexander Gordeev, Andreas Grapentin, Arnd Bergmann,
Catalin Marinas, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Friedrich Welter, Gautam Gala, Hariharan Mari,
Heiko Carstens, Hendrik Brueckner, Ilya Leoshkevich,
Janosch Frank, Joey Gouly, Nico Boehr, Nina Schoetterl-Glausch,
Oliver Upton, Paolo Bonzini, Suzuki K Poulose, Sven Schnelle,
Ulrich Weigand, Vasily Gorbik, Will Deacon, Zenghui Yu
On Mon, 06 Jul 2026 09:52:08 +0100,
Steffen Eiden <seiden@linux.ibm.com> wrote:
>
> Mark functions that s390 can use to implement arm on s390 as shared
> functions.
>
> No functional change.
>
> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
> ---
> arch/arm64/kvm/arm.c | 3 +++
> arch/arm64/kvm/guest.c | 3 +++
> arch/arm64/kvm/handle_exit.c | 6 ++++++
> arch/arm64/kvm/mmio.c | 14 ++++++++++++++
> arch/arm64/kvm/reset.c | 3 +++
> 5 files changed, 29 insertions(+)
>
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index 50adfff75be8..c992308b2dce 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
> @@ -1580,6 +1580,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)
> {
> @@ -1628,6 +1629,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;
> diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c
> index b01d6622b872..5a202cfd27bc 100644
> --- a/arch/arm64/kvm/guest.c
> +++ b/arch/arm64/kvm/guest.c
> @@ -543,6 +543,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 +592,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);
> diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
> index 54aedf93c78b..d511af145ee6 100644
> --- a/arch/arm64/kvm/handle_exit.c
> +++ b/arch/arm64/kvm/handle_exit.c
> @@ -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.
> diff --git a/arch/arm64/kvm/mmio.c b/arch/arm64/kvm/mmio.c
> index e2285ed8c91d..876d56dd5b64 100644
> --- a/arch/arm64/kvm/mmio.c
> +++ b/arch/arm64/kvm/mmio.c
> @@ -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;
> @@ -135,8 +136,11 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu)
> if (!kvm_vcpu_dabt_issf(vcpu))
> data = data & 0xffffffff;
>
> +#endif /* ARM64_S390_COMMON */
> trace_kvm_mmio(KVM_TRACE_MMIO_READ, len, run->mmio.phys_addr,
> &data);
> + //TODO tracing
> +#ifdef ARM64_S390_COMMON
Irk. The deal is that you lift full functions, not cherry-pick which
lines you want. Just define empty stubs for the trace nonsense, and be
done with it. But not this, please!
M.
--
Jazz isn't dead. It just smells funny.
^ permalink raw reply [flat|nested] 41+ messages in thread
end of thread, other threads:[~2026-07-06 21:26 UTC | newest]
Thread overview: 41+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-06 8:52 [PATCH v4 00/27] KVM: s390: Introduce arm64 KVM Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 01/27] VFIO: take reference to the KVM module Steffen Eiden
2026-07-06 19:53 ` Jason Gunthorpe
2026-07-06 21:12 ` Sean Christopherson
2026-07-06 8:52 ` [PATCH v4 02/27] KVM, vfio: remove symbol_get(kvm_get_kvm_safe) from vfio Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 03/27] KVM, vfio: remove symbol_get(kvm_put_kvm) " Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 04/27] KVM: Make device name configurable Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 05/27] KVM: Remove KVM_MMIO as config option Steffen Eiden
2026-07-06 20:53 ` Marc Zyngier
2026-07-06 8:52 ` [PATCH v4 06/27] arm64: Use proper include variant Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 07/27] arm64: Prepare sharing arm64 headers with s390 Steffen Eiden
2026-07-06 21:22 ` Marc Zyngier
2026-07-06 8:52 ` [PATCH v4 08/27] KVM: arm64: Prepare sharing arm64 code " Steffen Eiden
2026-07-06 21:28 ` Marc Zyngier
2026-07-06 8:52 ` [PATCH v4 09/27] KVM: arm64: Access elements of vcpu_gp_regs individually Steffen Eiden
2026-07-06 17:44 ` Marc Zyngier
2026-07-06 8:52 ` [PATCH v4 10/27] KVM: arm64: Refactor core-reset into a separate function Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 11/27] s390: Use arm64 headers Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 12/27] KVM: s390: Use arm64 code Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 13/27] KVM: s390: Prepare KVM/s390 for a second KVM module Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 14/27] KVM: s390: Move s390 kvm code into a subdirectory Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 15/27] KVM: S390: Prepare gmap for a second KVM implementation Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 16/27] KVM: s390: gmap: Refactor storage key and CMMA code into separate files Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 17/27] KVM: s390: Refactor prefix handling into a separate file Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 18/27] KVM: s390: Prepare kvm-s390 for a second kvm module Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 19/27] s390: Introduce Start Arm Execution instruction Steffen Eiden
2026-07-06 11:17 ` Janosch Frank
2026-07-06 11:30 ` Christian Borntraeger
2026-07-06 11:58 ` Steffen Eiden
2026-07-06 11:53 ` Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 20/27] KVM: s390: arm64: Introduce host definitions Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 21/27] s390/hwcaps: Report SAE support as hwcap Steffen Eiden
2026-07-06 11:50 ` Janosch Frank
2026-07-06 8:52 ` [PATCH v4 22/27] KVM: s390: Add basic arm64 kvm module Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 23/27] KVM: s390: arm64: Implement required functions Steffen Eiden
2026-07-06 12:15 ` Janosch Frank
2026-07-06 20:35 ` Marc Zyngier
2026-07-06 8:52 ` [PATCH v4 24/27] KVM: s390: arm64: Implement vm/vcpu create destroy Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 25/27] KVM: s390: arm64: Implement vCPU IOCTLs Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 26/27] KVM: s390: arm64: Implement basic page fault handler Steffen Eiden
2026-07-06 8:52 ` [PATCH v4 27/27] KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild Steffen Eiden
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox