KVM: s390: Introduce arm64 KVM
Subsystems (15)
Steffen Eiden
reviewerPATCH v5 2/31 KVM: Make device name configurable
In reply to Steffen EidenAllow KVM implementations to choose alternative device names. This is especially useful for architectures providing multiple KVM implementations simultaneously.
--- include/linux/kvm_host.h | 4 +++- virt/kvm/kvm_main.c | 38 +++++++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 10 deletions(-)
include/linux/kvm_host.h +3 -1
@@ -1068,7 +1068,9 @@ static inline void kvm_irqfd_exit(void) { }#endif -int kvm_init (unsigned vcpu_size,unsigned vcpu_align,struct module *module); +int kvm_init (unsigned int vcpu_size,unsigned int vcpu_align,struct module *module); +int kvm_init_with_dev (unsigned int vcpu_size,unsigned int vcpu_align, +struct module *module,const char *dev_name,int minor);void kvm_exit (void );void kvm_get_kvm (struct kvm *kvm);
virt/kvm/kvm_main.c +29 -9
@@ -10,6 +10,7 @@* Yaniv Kamay <[email protected]> */ +#include "linux/sprintf.h" #include <kvm/iodev.h> #include <linux/kvm_host.h>
@@ -5575,9 +5576,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
@@ -6349,13 +6348,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];
@@ -6491,23 +6490,39 @@ 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) +{ + char *cache_name __free(kfree) = NULL; int r; int cpu; + kvm_dev.minor = minor; + kvm_dev.name = kstrdup_const(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); + cache_name = kasprintf(GFP_KERNEL, "%s_vcpu", dev_name); + if (!cache_name) + return -ENOMEM; kvm_vcpu_cache = - kmem_cache_create_usercopy("kvm_vcpu", vcpu_size, vcpu_align, + kmem_cache_create_usercopy(cache_name, vcpu_size, vcpu_align, SLAB_ACCOUNT, offsetof(struct kvm_vcpu, arch), 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),
@@ -6533,7 +6548,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))
@@ -6574,6 +6589,8 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)for_each_possible_cpu (cpu)free_cpumask_var (per_cpu (cpu_kick_mask, cpu));kmem_cache_destroy (kvm_vcpu_cache); +err_dev_name: +kfree_const (kvm_dev.name);return r; }EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_init);
@@ -6599,5 +6616,8 @@ void kvm_exit(void)kvm_vfio_ops_exit ();kvm_async_pf_deinit ();kvm_irqfd_exit (); + +kfree_const (kvm_dev.name); + kvm_dev.name =NULL ; }EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_exit);
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 6/31 arm64/sysreg: Convert SPSR_ELx to automatic register generation
In reply to Steffen EidenConvert SPSR_EL{1, 2, 12} to automatic register generation as per DDIO616 2026-06. No functional change.
--- arch/arm64/include/asm/sysreg.h | 3 -- arch/arm64/tools/sysreg | 72 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 3 deletions(-)
arch/arm64/include/asm/sysreg.h +0 -3
@@ -295,7 +295,6 @@#define SYS_APGAKEYLO_EL1 sys_reg(3, 0, 2, 3, 0)#define SYS_APGAKEYHI_EL1 sys_reg(3, 0, 2, 3, 1) -#define SYS_SPSR_EL1 sys_reg(3, 0, 4, 0, 0)#define SYS_ELR_EL1 sys_reg(3, 0, 4, 0, 1)#define SYS_ICC_PMR_EL1 sys_reg(3, 0, 4, 6, 0)
@@ -518,7 +517,6 @@#define SYS_VTTBR_EL2 sys_reg(3, 4, 2, 1, 0)#define SYS_HAFGRTR_EL2 sys_reg(3, 4, 3, 1, 6) -#define SYS_SPSR_EL2 sys_reg(3, 4, 4, 0, 0)#define SYS_ELR_EL2 sys_reg(3, 4, 4, 0, 1)#define SYS_SP_EL1 sys_reg(3, 4, 4, 1, 0)#define SYS_SPSR_irq sys_reg(3, 4, 4, 3, 0)
@@ -604,7 +602,6 @@#define SYS_BRBCR_EL12 sys_reg(2, 5, 9, 0, 0)#define SYS_TTBR0_EL12 sys_reg(3, 5, 2, 0, 0)#define SYS_TTBR1_EL12 sys_reg(3, 5, 2, 0, 1) -#define SYS_SPSR_EL12 sys_reg(3, 5, 4, 0, 0)#define SYS_ELR_EL12 sys_reg(3, 5, 4, 0, 1)#define SYS_AFSR0_EL12 sys_reg(3, 5, 5, 1, 0)#define SYS_AFSR1_EL12 sys_reg(3, 5, 5, 1, 1)
arch/arm64/tools/sysreg +72 -0
78 lines not on this page · raw message
Signature · 1 line
2.53.0
Steffen Eiden
reviewerv5 cover KVM: s390: Introduce arm64 KVM
Introduce arm-on-s390. Enable KVM-accelerated ARM CPU virtualisation on s390.
For the original, now partially outdated, cover letter, have a look at versions one to three [1].
To share arm64 code with arm-on-s390 KVM, s390 extracts relevant parts of arm64 definitions and implementation and uses them locally. This results in minimal changes to existing arm64 code and headers.
To enable s390 to selectively extract relevant definitions while skipping architecture-specific code (e.g., arm64 assembly), a shared marker is introduced. The ARM64_S390_COMMON macro marks regions of arm64 code that are shared with s390:
in arch/arm64/kvm/<code>.c
<arm64 local code> #ifdef ARM64_S390_COMMON <shared code> #endif /* ARM64_S390_COMMON */ <arm64 local code>
ARM64_S390_COMMON is defined for all arm64 compilation units.
During the s390 build, an allow-list of arm64 headers is extracted into arch/s390/include/generated/arm64/. If a header contains at least one shared region, only those regions are copied along with the include guard. If no shared region is found, s390 uses the full header, which is copied in its entirety. In such cases, a comment is added at the top of the header to notify arm64 developers that the file is shared with s390 and changes may impact s390.
For C files, the process is similar. Selected KVM/arm64 C files are partially extracted into arch/s390/kvm/arm64/generated/code.inc. The s390 arm64 KVM implementation includes these snippets to reuse arm64 code without changing linkage.
Userspace tools requiring KVM/arm64 uapi on s390 must use a vendored KVM API, as s390 will not ship nor install arm64 KVM uapi headers.
This approach reduces the churn, especially for arm64 while keeping the maintenance burden low.
Series structure
A) KVM symbol cleanup and refactoring (patches 1-3):
Prepare KVM to support two KVM modules in parallel. Clean up KVM module symbol exports, making it possible to load two KVM modules side by side. Make the KVM device name configurable and remove KVM_MMIO as a config option.
B) Arm64 header and code sharing preparation (patches 4-12):
Mark shareable parts with ARM64_S390_COMMON. Perform minor refactoring to ease integration into s390.
C) KVM/s390 reorganization (patches 13-20):
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.
D) Code sharing infrastructure for s390 (patches 21 & 22):
Add Makefile and scripts to extract and build arm64 headers and code for use by s390.
E) KVM on s390 (patches 23-32):
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. A, B, C and D could be picked without the others so they could go through different trees if required. E requires A-D to be picked before.
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.
I think that there is no way around it: In the future arm64 maintainers should at least build s390 before sending merge request.
Steffen
Changes from v4 [2]:
- do not remove CONFIG_KVM_MMIO but let KVM/s390 opt out of MMIO
- use kstrdup_const for copying the kvm-device name
- use file based vfio tracking instead of inlining struct kvm refcounting arm64:
- reorganized arm64 code share & refactoring - first refactoring then sharing
- add arm64 refactoring to reduce shared regions
- shared a bit more function (definitions) to reduce no of shared regions (which would be shared in later series anyways)
- add patch to generate SPSR sysreg definitions
- add patch which defines an enum for the arm32 compat registers
s390:
- fix arm64 header generation wiring
- awk scripts are more robust and error out if an end marker is missing
- postfix combined headers with -gen instead of -part
- removed pre-fault-memory implementation
- implemented system supported feature sanitisation
- removed some unnecessary functions
- moved prefix, cmma, and storage key code from gmap to kvm/s390
- properly reset vxregs
Changes from v3
- Complete rework of the code sharing approach
- Introduced ARM64_S390_COMMON marker for selective extraction
- Build-time extraction instead of development-time sharing
- Minimal impact on arm64 codebase
- Improved gmap refactoring and integration
[1] Previous versions:
v1 https://lore.kernel.org/all/[email protected]/
v2 https://lore.kernel.org/all/[email protected]/
v3 https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Hendrik Brueckner (1):
s390/hwcaps: Report SAE support as hwcap
Steffen Eiden (30):
vfio: Use file-based reference counting for KVM
KVM: Make device name configurable
KVM: Allow KVM implementations to switch off MMIO independent of
Kconfig
arm64: Use proper include variant
arm64: ptrace: Use constants for compat register numbers arm64/sysreg: Convert SPSR_ELx to automatic register generation
KVM: arm64: Access elements of vcpu_gp_regs individually
KVM: arm64: Use accessor functions for gprs during reset
KVM: arm64: Refactor core-reset into a separate function
arm64: Prepare sharing arm64 headers with s390
arm64: Share arm64 headers with s390
KVM: arm64: Share arm64 code with s390
KVM: s390: Prepare moving KVM/s390 to arch/s390/kvm/s390
KVM: s390: Move s390 kvm code into a subdirectory
KVM: s390: Guard KVM/s390 behind CONFIG_KVM_S390
KVM: s390: Move PGM code definitions to asm/kvm_host.h
KVM: s390: Prepare gmap for a second KVM implementation
KVM: s390: gmap: Move storage key and CMMA code to kvm/s390
KVM: s390: gmap: Move prefix handling to kvm/s390
KVM: s390: Prepare KVM/s390 for a second KVM module
s390: Use arm64 headers
KVM: s390: Use arm64 code
s390: Introduce Start Arm Execution instruction
KVM: s390: arm64: Introduce host definitions
KVM: s390: Add basic arm64 kvm module
KVM: s390: arm64: Implement required functions
KVM: s390: arm64: Implement vm/vcpu create destroy.
KVM: s390: arm64: Implement vCPU IOCTLs
KVM: s390: arm64: Implement basic page fault handler
KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild
MAINTAINERS | 2 +-
arch/arm64/Makefile | 2 +
arch/arm64/include/asm/brk-imm.h | 1 +
arch/arm64/include/asm/esr.h | 5 +-
arch/arm64/include/asm/kvm_arm.h | 6 +-
arch/arm64/include/asm/kvm_emulate.h | 33 +-
arch/arm64/include/asm/kvm_host.h | 87 +-
arch/arm64/include/asm/ptrace.h | 64 +-
arch/arm64/include/asm/sysreg.h | 22 +-
arch/arm64/kvm/arm.c | 3 +
arch/arm64/kvm/guest.c | 22 +-
arch/arm64/kvm/handle_exit.c | 6 +
arch/arm64/kvm/hyp/exception.c | 4 +-
arch/arm64/kvm/hyp/include/hyp/adjust_pc.h | 4 +-
arch/arm64/kvm/hyp/include/hyp/switch.h | 4 +-
arch/arm64/kvm/mmio.c | 2 +
arch/arm64/kvm/reset.c | 46 +-
arch/arm64/tools/sysreg | 72 ++
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 | 102 +++
arch/s390/include/arm64/kvm_nested.h | 11 +
arch/s390/include/arm64/ptrace.h | 11 +
arch/s390/include/arm64/sysreg.h | 13 +
arch/s390/include/asm/Kbuild | 3 +
arch/s390/include/asm/asm-prototypes.h | 1 +
arch/s390/include/asm/elf.h | 2 +
arch/s390/include/asm/kvm.h | 6 +
arch/s390/include/asm/kvm_host.h | 729 +----------------
arch/s390/include/asm/kvm_host_arm64.h | 224 ++++++
arch/s390/include/asm/kvm_host_arm64_types.h | 118 +++
.../asm/{kvm_host.h => kvm_host_s390.h} | 66 +-
...kvm_host_types.h => kvm_host_s390_types.h} | 6 +-
arch/s390/include/asm/kvm_host_types.h | 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 | 32 +-
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/.gitignore | 2 +
arch/s390/kvm/arm64/Kconfig | 22 +
arch/s390/kvm/arm64/Makefile | 91 +++
arch/s390/kvm/arm64/Makefile.gen | 30 +
arch/s390/kvm/arm64/arm.c | 744 ++++++++++++++++++
arch/s390/kvm/arm64/arm.h | 58 ++
arch/s390/kvm/arm64/copy-arm64c.awk | 70 ++
arch/s390/kvm/arm64/guest.c | 135 ++++
arch/s390/kvm/arm64/handle_exit.c | 131 +++
arch/s390/kvm/arm64/handle_exit.h | 9 +
arch/s390/kvm/arm64/inject_fault.c | 21 +
arch/s390/kvm/arm64/mmio.c | 15 +
arch/s390/kvm/arm64/mmu.c | 177 +++++
arch/s390/kvm/arm64/reset.c | 77 ++
arch/s390/kvm/arm64/reset.h | 11 +
arch/s390/kvm/arm64/trace.h | 67 ++
arch/s390/kvm/gmap/Makefile | 5 +
arch/s390/kvm/{ => gmap}/dat.c | 548 -------------
arch/s390/kvm/{ => gmap}/dat.h | 14 +-
arch/s390/kvm/{ => gmap}/faultin.c | 8 +-
arch/s390/kvm/{ => gmap}/faultin.h | 6 +-
arch/s390/kvm/{ => gmap}/gmap.c | 111 +--
arch/s390/kvm/{ => gmap}/gmap.h | 29 +-
arch/s390/kvm/gmap/kvm_mmu.c | 135 ++++
arch/s390/kvm/gmap/kvm_mmu.h | 18 +
arch/s390/kvm/gmap/prefix.h | 39 +
arch/s390/kvm/gmap/trace-gmap.h | 59 ++
arch/s390/kvm/{ => s390}/Kconfig | 27 +-
arch/s390/kvm/s390/Makefile | 15 +
arch/s390/kvm/s390/dat.c | 554 +++++++++++++
arch/s390/kvm/{ => s390}/diag.c | 2 +-
arch/s390/kvm/{ => s390}/gaccess.c | 2 +-
arch/s390/kvm/{ => s390}/gaccess.h | 2 +-
arch/s390/kvm/s390/gmap.c | 113 +++
arch/s390/kvm/{ => s390}/guestdbg.c | 2 +-
arch/s390/kvm/{ => s390}/intercept.c | 2 +-
arch/s390/kvm/{ => s390}/interrupt.c | 2 +-
arch/s390/kvm/{ => s390}/pci.c | 2 +-
arch/s390/kvm/{ => s390}/pci.h | 0
arch/s390/kvm/{ => s390}/priv.c | 2 +-
arch/s390/kvm/{ => s390}/pv.c | 2 +-
arch/s390/kvm/{kvm-s390.c => s390/s390.c} | 121 +--
arch/s390/kvm/{kvm-s390.h => s390/s390.h} | 36 +-
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 | 10 +-
arch/s390/tools/Makefile.arm64h | 57 ++
arch/s390/tools/copy-arm64h-full.awk | 47 ++
arch/s390/tools/copy-arm64h.awk | 72 ++
arch/s390/tools/opcodes.txt | 3 +
arch/x86/include/asm/kvm_page_track.h | 8 +-
arch/x86/kvm/Makefile | 3 -
arch/x86/kvm/mmu/page_track.c | 16 +-
drivers/s390/char/sclp_early.c | 1 +
drivers/s390/crypto/vfio_ap_ops.c | 24 +-
drivers/vfio/group.c | 2 +-
drivers/vfio/pci/vfio_pci_zdev.c | 7 +-
drivers/vfio/vfio.h | 10 +-
drivers/vfio/vfio_main.c | 49 +-
include/linux/kvm_host.h | 8 +-
include/linux/vfio.h | 4 +-
virt/kvm/coalesced_mmio.c | 4 +
virt/kvm/coalesced_mmio.h | 2 +-
virt/kvm/kvm_main.c | 69 +-
virt/kvm/vfio.c | 8 +-
114 files changed, 3917 insertions(+), 2215 deletions(-)
create mode 100644 arch/s390/include/arm64/kvm_emulate.h
create mode 100644 arch/s390/include/arm64/kvm_nested.h
create mode 100644 arch/s390/include/arm64/ptrace.h
create mode 100644 arch/s390/include/arm64/sysreg.h
create mode 100644 arch/s390/include/asm/kvm.h
create mode 100644 arch/s390/include/asm/kvm_host_arm64.h
create mode 100644 arch/s390/include/asm/kvm_host_arm64_types.h
copy arch/s390/include/asm/{kvm_host.h => kvm_host_s390.h} (90%)
copy arch/s390/include/asm/{kvm_host_types.h => kvm_host_s390_types.h} (98%)
create mode 100644 arch/s390/include/asm/sae.h
create mode 100644 arch/s390/kvm/arm64/.gitignore
create mode 100644 arch/s390/kvm/arm64/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/handle_exit.c
create mode 100644 arch/s390/kvm/arm64/handle_exit.h
create mode 100644 arch/s390/kvm/arm64/inject_fault.c
create mode 100644 arch/s390/kvm/arm64/mmio.c
create mode 100644 arch/s390/kvm/arm64/mmu.c
create mode 100644 arch/s390/kvm/arm64/reset.c
create mode 100644 arch/s390/kvm/arm64/reset.h
create mode 100644 arch/s390/kvm/arm64/trace.h
create mode 100644 arch/s390/kvm/gmap/Makefile
rename arch/s390/kvm/{ => gmap}/dat.c (61%)
rename arch/s390/kvm/{ => gmap}/dat.h (97%)
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/kvm_mmu.c
create mode 100644 arch/s390/kvm/gmap/kvm_mmu.h
create mode 100644 arch/s390/kvm/gmap/prefix.h
create mode 100644 arch/s390/kvm/gmap/trace-gmap.h
copy arch/s390/kvm/{ => s390}/Kconfig (61%)
create mode 100644 arch/s390/kvm/s390/Makefile
create mode 100644 arch/s390/kvm/s390/dat.c
rename arch/s390/kvm/{ => s390}/diag.c (99%)
rename arch/s390/kvm/{ => s390}/gaccess.c (99%)
rename arch/s390/kvm/{ => s390}/gaccess.h (99%)
create mode 100644 arch/s390/kvm/s390/gmap.c
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} (94%)
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.awkbase-commit: 8ba098e6b6ff0db8edf28528d1552be261af30d4
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 3/31 KVM: Allow KVM implementations to switch off MMIO independent of Kconfig
Only defining KVM_MMIO is not flexible enough for multi-KVM systems where one KVM implements MMIO but others do not. Solve this by additionally testing for the non-existence of KVM_NO_MMIO before including MMIO code to KVM.
--- virt/kvm/coalesced_mmio.c | 4 ++++ virt/kvm/coalesced_mmio.h | 2 +- virt/kvm/kvm_main.c | 8 ++++---- 3 files changed, 9 insertions(+), 5 deletions(-)
virt/kvm/coalesced_mmio.c +4 -0
@@ -15,6 +15,8 @@#include <linux/slab.h> #include <linux/kvm.h> +#ifndef KVM_NO_MMIO +#include "coalesced_mmio.h" static inline struct kvm_coalesced_mmio_dev *to_mmio (struct kvm_io_device *dev)
@@ -188,3 +190,5 @@ int kvm_vm_ioctl_unregister_coalesced_mmio(struct kvm *kvm,*/ return 0; } + +#endif /* ifndef KVM_NO_MMIO */
virt/kvm/coalesced_mmio.h +1 -1
@@ -11,7 +11,7 @@* */ -#ifdef CONFIG_KVM_MMIO +#if defined(CONFIG_KVM_MMIO ) && !defined(KVM_NO_MMIO )#include <linux/list.h>
virt/kvm/kvm_main.c +4 -4
@@ -4056,7 +4056,7 @@ static vm_fault_t kvm_vcpu_fault(struct vm_fault *vmf) else if (vmf->pgoff == KVM_PIO_PAGE_OFFSET) page =virt_to_page (vcpu->arch.pio_data);#endif -#ifdef CONFIG_KVM_MMIO +#if defined(CONFIG_KVM_MMIO ) && !defined(KVM_NO_MMIO ) else if (vmf->pgoff == KVM_COALESCED_MMIO_PAGE_OFFSET) page =virt_to_page (vcpu->kvm->coalesced_mmio_ring);#endif
@@ -4882,7 +4882,7 @@ static int kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)case KVM_CAP_ENABLE_CAP_VM :case KVM_CAP_HALT_POLL :return 1 ; -#ifdef CONFIG_KVM_MMIO +#if defined(CONFIG_KVM_MMIO ) && !defined(KVM_NO_MMIO )case KVM_CAP_COALESCED_MMIO :return KVM_COALESCED_MMIO_PAGE_OFFSET ;case KVM_CAP_COALESCED_PIO :
@@ -5223,7 +5223,7 @@ static long kvm_vm_ioctl(struct file *filp,break ; }#endif -#ifdef CONFIG_KVM_MMIO +#if defined(CONFIG_KVM_MMIO ) && !defined(KVM_NO_MMIO )case KVM_REGISTER_COALESCED_MMIO : {struct kvm_coalesced_mmio_zone zone;
@@ -5558,7 +5558,7 @@ static long kvm_dev_ioctl(struct file *filp,#ifdef CONFIG_X86 r +=PAGE_SIZE ;/* pio data page */ #endif -#ifdef CONFIG_KVM_MMIO +#if defined(CONFIG_KVM_MMIO ) && !defined(KVM_NO_MMIO ) r +=PAGE_SIZE ;/* coalesced mmio ring page */ #endif break ;
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 8/31 KVM: arm64: Use accessor functions for gprs during reset
In reply to Steffen EidenInstead of accessing the value directly use assessor function that abstract the actual location of the register values. Enable other KVM implementations to reuse this code.
No functional changes.
--- arch/arm64/include/asm/kvm_emulate.h | 5 +++++ arch/arm64/include/asm/kvm_host.h | 6 ++++++ arch/arm64/kvm/guest.c | 16 ++++++++-------- arch/arm64/kvm/reset.c | 2 +- 4 files changed, 20 insertions(+), 9 deletions(-)
arch/arm64/include/asm/kvm_emulate.h +5 -0
@@ -141,6 +141,11 @@ static __always_inline unsigned long *vcpu_cpsr(const struct kvm_vcpu *vcpu)return (unsigned long *)&vcpu->arch.ctxt.regs.pstate; } +static __always_inline unsigned long *vcpu_sp_el0 (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) {return !!(*vcpu_cpsr (vcpu) &PSR_MODE32_BIT );
arch/arm64/include/asm/kvm_host.h +6 -0
@@ -1183,6 +1183,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) \
arch/arm64/kvm/guest.c +8 -8
@@ -134,19 +134,19 @@ static void *core_reg_addr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) KVM_REG_ARM_CORE_REG(regs.regs[30]): off -=KVM_REG_ARM_CORE_REG (regs.regs[0 ]); off /=2 ; -return &vcpu->arch.ctxt.regs.regs[off]; +return &vcpu_gp_regs (vcpu)[off];case KVM_REG_ARM_CORE_REG (regs.sp): -return &vcpu->arch.ctxt.regs.sp; +return vcpu_sp_el0 (vcpu);case KVM_REG_ARM_CORE_REG (regs.pc): -return &vcpu->arch.ctxt.regs.pc; +return vcpu_pc (vcpu);case KVM_REG_ARM_CORE_REG (regs.pstate): -return &vcpu->arch.ctxt.regs.pstate; +return vcpu_cpsr (vcpu);case KVM_REG_ARM_CORE_REG (sp_el1): -return __ctxt_sys_reg (&vcpu->arch.ctxt,SP_EL1 ); +return 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 +170,13 @@ static void *core_reg_addr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) KVM_REG_ARM_CORE_REG(fp_regs.vregs[31]): off -=KVM_REG_ARM_CORE_REG (fp_regs.vregs[0 ]); off /=4 ; -return &vcpu->arch.ctxt.fp_regs.vregs[off]; +return 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 ;
arch/arm64/kvm/reset.c +1 -1
@@ -220,7 +220,7 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)/* Reset core registers */ memset (vcpu_gp_regs (vcpu),0 ,sizeof (vcpu_gp_regs (vcpu))); *vcpu_pc (vcpu) =0 ; - vcpu->arch.ctxt.regs.sp =0 ; + *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 ;
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 5/31 arm64: ptrace: Use constants for compat register numbers
In reply to Steffen EidenDefine an enum to determine the register number for the mapping from AArch32 and AArch64 registers. This allows for a more flexible use of the register mappings.
--- arch/arm64/include/asm/ptrace.h | 60 ++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 19 deletions(-)
arch/arm64/include/asm/ptrace.h +41 -19
@@ -104,26 +104,48 @@#define COMPAT_USER_SZ 296/* Architecturally defined mapping between AArch32 and AArch64 registers */ +enum { + __compat_fp =11 , + __compat_sp =13 , + __compat_lr =14 , + __compat_sp_hyp =15 , + __compat_lr_irq =16 , + __compat_sp_irq =17 , + __compat_lr_svc =18 , + __compat_sp_svc =19 , + __compat_lr_abt =20 , + __compat_sp_abt =21 , + __compat_lr_und =22 , + __compat_sp_und =23 , + __compat_r8_fiq =24 , + __compat_r9_fiq =25 , + __compat_r10_fi =26 , + __compat_r11_fi =27 , + __compat_r12_fi =28 , + __compat_sp_fiq =29 , + __compat_lr_fiq =30 , +}; +#define compat_usr (x) regs[(x)] -#define compat_fp regs[11] -#define compat_sp regs[13] -#define compat_lr regs[14] -#define compat_sp_hyp regs[15] -#define compat_lr_irq regs[16] -#define compat_sp_irq regs[17] -#define compat_lr_svc regs[18] -#define compat_sp_svc regs[19] -#define compat_lr_abt regs[20] -#define compat_sp_abt regs[21] -#define compat_lr_und regs[22] -#define compat_sp_und regs[23] -#define compat_r8_fiq regs[24] -#define compat_r9_fiq regs[25] -#define compat_r10_fiq regs[26] -#define compat_r11_fiq regs[27] -#define compat_r12_fiq regs[28] -#define compat_sp_fiq regs[29] -#define compat_lr_fiq regs[30] +#define compat_fp regs[__compat_fp] +#define compat_sp regs[__compat_sp] +#define compat_lr regs[__compat_lr] +#define compat_sp_hyp regs[__compat_sp_hyp] +#define compat_lr_irq regs[__compat_lr_irq] +#define compat_sp_irq regs[__compat_sp_irq] +#define compat_lr_svc regs[__compat_lr_svc] +#define compat_sp_svc regs[__compat_sp_svc] +#define compat_lr_abt regs[__compat_lr_ab] +#define compat_sp_abt regs[__compat_sp_abt] +#define compat_lr_und regs[__compat_lr_und] +#define compat_sp_und regs[__compat_sp_und] +#define compat_r8_fiq regs[__compat_r8_fiq] +#define compat_r9_fiq regs[__compat_r9_fiq] +#define compat_r10_fiq regs[__compat_r10_fi] +#define compat_r11_fiq regs[__compat_r11_fi] +#define compat_r12_fiq regs[__compat_r12_fi] +#define compat_sp_fiq regs[__compat_sp_fiq] +#define compat_lr_fiq regs[__compat_lr_fiq]static inline unsigned long compat_psr_to_pstate (const unsigned long psr) {
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 14/31 KVM: s390: Move s390 kvm code into a subdirectory
In reply to Steffen EidenMove all the code required to run s390 KVM guests on s390 to a s390 subdirectory. Move gmap related code into a gmap directory to later share gmap code between KVM implementations.
Update S390 VFIO-PCI MAINTAINERS filepath.
No functional change.
---
MAINTAINERS | 2 +-
arch/s390/kvm/Kconfig | 37 +--------------------------
arch/s390/kvm/Makefile | 11 +-------
arch/s390/kvm/gmap/Makefile | 5 ++++
arch/s390/kvm/{ => gmap}/dat.c | 0
arch/s390/kvm/{ => gmap}/dat.h | 0
arch/s390/kvm/{ => gmap}/faultin.c | 0
arch/s390/kvm/{ => gmap}/faultin.h | 0
arch/s390/kvm/{ => gmap}/gmap.c | 0
arch/s390/kvm/{ => gmap}/gmap.h | 0
arch/s390/kvm/{ => gmap}/trace-gmap.h | 2 +-
arch/s390/kvm/{ => s390}/Kconfig | 18 -------------
arch/s390/kvm/{ => s390}/Makefile | 9 +++----
arch/s390/kvm/{ => s390}/diag.c | 0
arch/s390/kvm/{ => s390}/gaccess.c | 0
arch/s390/kvm/{ => s390}/gaccess.h | 0
arch/s390/kvm/{ => s390}/guestdbg.c | 0
arch/s390/kvm/{ => s390}/intercept.c | 0
arch/s390/kvm/{ => s390}/interrupt.c | 0
arch/s390/kvm/{ => s390}/pci.c | 0
arch/s390/kvm/{ => s390}/pci.h | 0
arch/s390/kvm/{ => s390}/priv.c | 0
arch/s390/kvm/{ => s390}/pv.c | 0
arch/s390/kvm/{ => s390}/s390.c | 0
arch/s390/kvm/{ => s390}/s390.h | 0
arch/s390/kvm/{ => s390}/sigp.c | 0
arch/s390/kvm/{ => s390}/trace-s390.h | 0
arch/s390/kvm/{ => s390}/trace.h | 0
arch/s390/kvm/{ => s390}/vsie.c | 0
29 files changed, 13 insertions(+), 71 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 (65%)
rename arch/s390/kvm/{ => s390}/diag.c (100%)
rename arch/s390/kvm/{ => s390}/gaccess.c (100%)
rename arch/s390/kvm/{ => s390}/gaccess.h (100%)
rename arch/s390/kvm/{ => s390}/guestdbg.c (100%)
rename arch/s390/kvm/{ => s390}/intercept.c (100%)
rename arch/s390/kvm/{ => s390}/interrupt.c (100%)
rename arch/s390/kvm/{ => s390}/pci.c (100%)
rename arch/s390/kvm/{ => s390}/pci.h (100%)
rename arch/s390/kvm/{ => s390}/priv.c (100%)
rename arch/s390/kvm/{ => s390}/pv.c (100%)
rename arch/s390/kvm/{ => s390}/s390.c (100%)
rename arch/s390/kvm/{ => s390}/s390.h (100%)
rename arch/s390/kvm/{ => s390}/sigp.c (100%)
rename arch/s390/kvm/{ => s390}/trace-s390.h (100%)
rename arch/s390/kvm/{ => s390}/trace.h (100%)
rename arch/s390/kvm/{ => s390}/vsie.c (100%)MAINTAINERS +1 -1
@@ -23918,7 +23918,7 @@ R: Eric Farman <[email protected]> L: [email protected] L: [email protected] S: Supported -F: arch/s390/kvm/pci* +F: arch/s390/kvm/s390/pci* F: drivers/vfio/pci/vfio_pci_zdev.c F: include/uapi/linux/vfio_zdev.h
arch/s390/kvm/Kconfig +1 -36
@@ -16,41 +16,6 @@ menuconfig VIRTUALIZATION if VIRTUALIZATION -config KVM - def_tristate y - prompt "Kernel-based Virtual Machine (KVM) support (s390)" - 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 - 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
arch/s390/kvm/Makefile +1 -10
@@ -3,13 +3,4 @@ # # Copyright IBM Corp. 2008 -include $(srctree)/virt/kvm/Makefile.kvm - -ccflags-y := -I$(src) - -kvm-y += s390.o intercept.o interrupt.o priv.o sigp.o -kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o -kvm-y += dat.o gmap.o faultin.o - -kvm-$(CONFIG_VFIO_PCI_ZDEV_KVM) += pci.o -obj-$(CONFIG_KVM) += kvm.o +obj-$(CONFIG_KVM) += s390/
arch/s390/kvm/gmap/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +GMAP ?= ../gmap + +kvm-y += $(GMAP)/dat.o $(GMAP)/gmap.o $(GMAP)/faultin.o
arch/s390/kvm/gmap/dat.c renamed from arch/s390/kvm/dat.c +0 -0
arch/s390/kvm/gmap/dat.h renamed from arch/s390/kvm/dat.h +0 -0
arch/s390/kvm/gmap/faultin.c renamed from arch/s390/kvm/faultin.c +0 -0
arch/s390/kvm/gmap/faultin.h renamed from arch/s390/kvm/faultin.h +0 -0
arch/s390/kvm/gmap/gmap.c renamed from arch/s390/kvm/gmap.c +0 -0
arch/s390/kvm/gmap/gmap.h renamed from arch/s390/kvm/gmap.h +0 -0
arch/s390/kvm/gmap/trace-gmap.h renamed from arch/s390/kvm/trace-gmap.h +1 -1
@@ -6,7 +6,7 @@#undef TRACE_SYSTEM#define TRACE_SYSTEM kvm -#define TRACE_INCLUDE_PATH . +#define TRACE_INCLUDE_PATH ../gmap#undef TRACE_INCLUDE_FILE#define TRACE_INCLUDE_FILE trace-gmap
arch/s390/kvm/s390/Kconfig renamed from arch/s390/kvm/Kconfig +0 -18
@@ -1,20 +1,4 @@ # 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 def_tristate y
@@ -52,5 +36,3 @@ config KVM_S390_UCONTROL controlled by userspace. If unsure, say N. - -endif # VIRTUALIZATION
arch/s390/kvm/s390/Makefile renamed from arch/s390/kvm/Makefile +4 -5
@@ -1,15 +1,14 @@ # SPDX-License-Identifier: GPL-2.0 -# Makefile for kernel virtual machines on s390 -# -# Copyright IBM Corp. 2008 +KVM := ../../../../virt/kvm include $(srctree)/virt/kvm/Makefile.kvm +include $(srctree)/arch/s390/kvm/gmap/Makefile -ccflags-y := -I$(src) +ccflags-y := -I$(src) -I$(srctree)/arch/s390/kvm/gmap kvm-y += s390.o intercept.o interrupt.o priv.o sigp.o kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o -kvm-y += dat.o gmap.o faultin.o kvm-$(CONFIG_VFIO_PCI_ZDEV_KVM) += pci.o + obj-$(CONFIG_KVM) += kvm.o
arch/s390/kvm/s390/diag.c renamed from arch/s390/kvm/diag.c +0 -0
arch/s390/kvm/s390/gaccess.c renamed from arch/s390/kvm/gaccess.c +0 -0
arch/s390/kvm/s390/gaccess.h renamed from arch/s390/kvm/gaccess.h +0 -0
arch/s390/kvm/s390/guestdbg.c renamed from arch/s390/kvm/guestdbg.c +0 -0
arch/s390/kvm/s390/intercept.c renamed from arch/s390/kvm/intercept.c +0 -0
arch/s390/kvm/s390/interrupt.c renamed from arch/s390/kvm/interrupt.c +0 -0
arch/s390/kvm/s390/pci.c renamed from arch/s390/kvm/pci.c +0 -0
arch/s390/kvm/s390/pci.h renamed from arch/s390/kvm/pci.h +0 -0
arch/s390/kvm/s390/priv.c renamed from arch/s390/kvm/priv.c +0 -0
arch/s390/kvm/s390/pv.c renamed from arch/s390/kvm/pv.c +0 -0
arch/s390/kvm/s390/s390.c renamed from arch/s390/kvm/s390.c +0 -0
arch/s390/kvm/s390/s390.h renamed from arch/s390/kvm/s390.h +0 -0
arch/s390/kvm/s390/sigp.c renamed from arch/s390/kvm/sigp.c +0 -0
arch/s390/kvm/s390/trace-s390.h renamed from arch/s390/kvm/trace-s390.h +0 -0
arch/s390/kvm/s390/trace.h renamed from arch/s390/kvm/trace.h +0 -0
arch/s390/kvm/s390/vsie.c renamed from arch/s390/kvm/vsie.c +0 -0
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 9/31 KVM: arm64: Refactor core-reset into a separate function
In reply to Steffen EidenMove the reset of the arm core register into a separate function for later reuse.
No functional change.
--- arch/arm64/kvm/reset.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-)
arch/arm64/kvm/reset.c +25 -17
@@ -169,6 +169,30 @@ static void kvm_vcpu_reset_sve(struct kvm_vcpu *vcpu)memset (vcpu->arch.sve_state,0 ,vcpu_sve_state_size (vcpu)); } +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; +} +/** * kvm_reset_vcpu - sets core registers and sys_regs to reset value * @vcpu: The VCPU pointer
@@ -191,7 +215,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;
@@ -210,23 +233,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);
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 1/31 vfio: Use file-based reference counting for KVM
In reply to Steffen EidenReplace manual module reference counting with file-based reference counting for KVM integration. Previously, VFIO used symbol_get() to obtain function pointers for kvm_get_kvm_safe() and kvm_put_kvm(), then manually tracked module references through these symbols. This approach required storing the put_kvm function pointer in each device and carefully managing symbol references.
Pass struct file pointers instead of struct kvm pointers throughout the VFIO-KVM interface. This leverages the kernel's existing file reference counting mechanism via get_file_active() and fput(), eliminating the need for manual module reference tracking. The file->private_data field provides access to the underlying struct kvm when needed.
This simplifies the code and removes all remaining externally exported symbols for KVM, paving the path for a second concurrent KVM module.
--- arch/x86/include/asm/kvm_page_track.h | 8 ++--- arch/x86/kvm/Makefile | 3 -- arch/x86/kvm/mmu/page_track.c | 16 +++++---- drivers/s390/crypto/vfio_ap_ops.c | 24 ++++++++++--- drivers/vfio/group.c | 2 +- drivers/vfio/pci/vfio_pci_zdev.c | 7 +++- drivers/vfio/vfio.h | 10 +++--- drivers/vfio/vfio_main.c | 49 ++++++--------------------- include/linux/kvm_host.h | 2 ++ include/linux/vfio.h | 4 +-- virt/kvm/kvm_main.c | 23 ++++++++++--- virt/kvm/vfio.c | 8 ++--- 12 files changed, 81 insertions(+), 75 deletions(-)
arch/x86/include/asm/kvm_page_track.h +4 -4
@@ -44,13 +44,13 @@ struct kvm_page_track_notifier_node { struct kvm_page_track_notifier_node *node); }; -int kvm_page_track_register_notifier (struct kvm *kvm, +int kvm_page_track_register_notifier (struct file *file,struct kvm_page_track_notifier_node *n); -void kvm_page_track_unregister_notifier (struct kvm *kvm, +void kvm_page_track_unregister_notifier (struct file *file,struct kvm_page_track_notifier_node *n); -int kvm_write_track_add_gfn (struct kvm *kvm,gfn_t gfn); -int kvm_write_track_remove_gfn (struct kvm *kvm,gfn_t gfn); +int kvm_write_track_add_gfn (struct file *file,gfn_t gfn); +int kvm_write_track_remove_gfn (struct file *file,gfn_t gfn);#else /* * Allow defining a node in a structure even if page tracking is disabled, e.g.
arch/x86/kvm/Makefile +0 -3
@@ -61,9 +61,6 @@ exports_grep_trailer := --include='*.[ch]' -nrw $(srctree)/virt/kvm $(srctree)/a -e kvm_page_track_unregister_notifier \ -e kvm_write_track_add_gfn \ -e kvm_write_track_remove_gfn \ - -e kvm_get_kvm \ - -e kvm_get_kvm_safe \ - -e kvm_put_kvm # Force grep to emit a goofy group separator that can in turn be replaced with # the above newline macro (newlines in Make are a nightmare). Note, grep only
arch/x86/kvm/mmu/page_track.c +10 -6
@@ -237,10 +237,11 @@ static int kvm_enable_external_write_tracking(struct kvm *kvm)* register the notifier so that event interception for the tracked guest * pages can be received. */ -int kvm_page_track_register_notifier (struct kvm *kvm, +int kvm_page_track_register_notifier (struct file *file,struct kvm_page_track_notifier_node *n) {struct kvm_page_track_notifier_head *head; +struct kvm *kvm =file_to_kvm (file);int r;if (!kvm || kvm->mm != current->mm)
@@ -252,7 +253,7 @@ int kvm_page_track_register_notifier(struct kvm *kvm,return r; } -kvm_get_kvm (kvm); +get_file (file); head = &kvm->arch.track_notifier_head;
@@ -267,10 +268,11 @@ EXPORT_SYMBOL_GPL(kvm_page_track_register_notifier);* stop receiving the event interception. It is the opposed operation of * kvm_page_track_register_notifier(). */ -void kvm_page_track_unregister_notifier (struct kvm *kvm, +void kvm_page_track_unregister_notifier (struct file *file,struct kvm_page_track_notifier_node *n) {struct kvm_page_track_notifier_head *head; +struct kvm *kvm =file_to_kvm (file); head = &kvm->arch.track_notifier_head;
@@ -279,7 +281,7 @@ void kvm_page_track_unregister_notifier(struct kvm *kvm,write_unlock (&kvm->mmu_lock);synchronize_srcu (&head->track_srcu); -kvm_put_kvm (kvm); +fput (file); }EXPORT_SYMBOL_GPL (kvm_page_track_unregister_notifier);
@@ -339,8 +341,9 @@ void kvm_page_track_delete_slot(struct kvm *kvm, struct kvm_memory_slot *slot)* @kvm: the guest instance we are interested in. * @gfn: the guest page. */ -int kvm_write_track_add_gfn (struct kvm *kvm,gfn_t gfn) +int kvm_write_track_add_gfn (struct file *file,gfn_t gfn) { +struct kvm *kvm =file_to_kvm (file);struct kvm_memory_slot *slot;int idx;
@@ -369,8 +372,9 @@ EXPORT_SYMBOL_GPL(kvm_write_track_add_gfn);* @kvm: the guest instance we are interested in. * @gfn: the guest page. */ -int kvm_write_track_remove_gfn (struct kvm *kvm,gfn_t gfn) +int kvm_write_track_remove_gfn (struct file *file,gfn_t gfn) { +struct kvm *kvm =file_to_kvm (file);struct kvm_memory_slot *slot;int idx;
drivers/s390/crypto/vfio_ap_ops.c +19 -5
@@ -8,6 +8,7 @@* Halil Pasic <[email protected]> * Pierre Morel <[email protected]> */ +#include "linux/cleanup.h" #include <linux/string.h> #include <linux/vfio.h> #include <linux/device.h>
@@ -1815,13 +1816,26 @@ static const struct attribute_group *vfio_ap_mdev_attr_groups[] = {* @matrix_mdev: a mediated matrix device * @kvm: reference to KVM instance * -* Return: 0 if no other mediated matrix device has a reference to @kvm; -* otherwise, returns an -EPERM. +* Returns: 0 if the reference to kvm is successfully retrieved from @kvm_file +* and set into @matrix_mdev; otherwise, returns: +* -ENOENT if a reference to kvm could not be retrieved from @kvm_file +* -EPERM if another mediated matrix device already has a reference to the same kvm instance +* */ static int vfio_ap_mdev_set_kvm (struct ap_matrix_mdev *matrix_mdev, -struct kvm *kvm) +struct file *kvm_file) { + struct file *kvm_file_ref __free(fput) = NULL;struct ap_matrix_mdev *m; +struct kvm *kvm; + + kvm_file_ref =get_file_active (&kvm_file); +if (!kvm_file_ref) +return -ENOENT ; + + kvm = kvm_file->private_data; +if (!kvm) +return -ENOENT ;if (kvm->arch.crypto.crycbd) {down_write (&kvm->arch.crypto.pqap_hook_rwsem);
@@ -1837,13 +1851,13 @@ static int vfio_ap_mdev_set_kvm(struct ap_matrix_mdev *matrix_mdev, } } -kvm_get_kvm (kvm); matrix_mdev->kvm = kvm;vfio_ap_mdev_update_guest_apcb (matrix_mdev);release_update_locks_for_kvm (kvm); } +no_free_ptr (kvm_file_ref);return 0 ; }
@@ -1891,7 +1905,7 @@ static void vfio_ap_mdev_unset_kvm(struct ap_matrix_mdev *matrix_mdev)kvm_arch_crypto_clear_masks (kvm);vfio_ap_mdev_reset_queues (matrix_mdev); -kvm_put_kvm (kvm); +fput (kvm->file); matrix_mdev->kvm =NULL ;release_update_locks_for_kvm (kvm);
drivers/vfio/group.c +1 -1
@@ -860,7 +860,7 @@ bool vfio_group_enforced_coherent(struct vfio_group *group)return ret; } -void vfio_group_set_kvm (struct vfio_group *group,struct kvm *kvm) +void vfio_group_set_kvm (struct vfio_group *group,struct file *kvm) {spin_lock (&group->kvm_ref_lock); group->kvm = kvm;
drivers/vfio/pci/vfio_pci_zdev.c +6 -1
@@ -144,6 +144,7 @@ int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,int vfio_pci_zdev_open_device (struct vfio_pci_core_device *vdev) {struct zpci_dev *zdev =to_zpci (vdev->pdev); +struct kvm *kvm;if (!zdev)return -ENODEV ;
@@ -151,8 +152,12 @@ int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev)if (!vdev->vdev.kvm)return 0 ; + kvm = vdev->vdev.kvm->private_data; +if (!kvm) +return -ENOENT ; +if (zpci_kvm_hook.kvm_register) -return zpci_kvm_hook.kvm_register (zdev, vdev->vdev.kvm); +return zpci_kvm_hook.kvm_register (zdev, kvm);return -ENOENT ; }
drivers/vfio/vfio.h +5 -5
@@ -23,7 +23,7 @@ struct vfio_device_file {u8 access_granted;u32 devid;/* only valid when iommufd is valid */ spinlock_t kvm_ref_lock;/* protect kvm field */ -struct kvm *kvm; +struct file *kvm;struct iommufd_ctx *iommufd;/* protected by struct vfio_device_set::lock */ };
@@ -88,7 +88,7 @@ struct vfio_group {#endif enum vfio_group_type type;struct mutex group_lock; -struct kvm *kvm; +struct file *kvm;struct file *opened_file;struct iommufd_ctx *iommufd;spinlock_t kvm_ref_lock;
@@ -107,7 +107,7 @@ void vfio_device_group_unuse_iommu(struct vfio_device *device);void vfio_df_group_close (struct vfio_device_file *df);struct vfio_group *vfio_group_from_file (struct file *file);bool vfio_group_enforced_coherent (struct vfio_group *group); -void vfio_group_set_kvm (struct vfio_group *group,struct kvm *kvm); +void vfio_group_set_kvm (struct vfio_group *group,struct file *kvm);bool vfio_device_has_container (struct vfio_device *device);int __init vfio_group_init (void );void vfio_group_cleanup (void );
@@ -434,11 +434,11 @@ static inline void vfio_virqfd_exit(void)#endif #if IS_ENABLED (CONFIG_KVM ) -void vfio_device_get_kvm_safe (struct vfio_device *device,struct kvm *kvm); +void vfio_device_get_kvm_safe (struct vfio_device *device,struct file *kvm);void vfio_device_put_kvm (struct vfio_device *device);#else static inline void vfio_device_get_kvm_safe (struct vfio_device *device, -struct kvm *kvm) +struct file *kvm) { }
drivers/vfio/vfio_main.c +10 -39
88 lines not on this page · raw message
include/linux/kvm_host.h +2 -0
@@ -784,6 +784,7 @@ struct kvm {* kvm_swap_active_memslots(). */ struct mutex slots_arch_lock; +struct file *file;/* Back-reference to VM file descriptor */ struct mm_struct *mm;/* userspace tied to this vm */ unsigned long nr_memslot_pages;/* The two memslot sets - active and inactive (per address space) */
@@ -1074,6 +1075,7 @@ void kvm_get_kvm(struct kvm *kvm);bool kvm_get_kvm_safe (struct kvm *kvm);void kvm_put_kvm (struct kvm *kvm);bool file_is_kvm (struct file *file); +struct kvm *file_to_kvm (struct file *file);void kvm_put_kvm_no_destroy (struct kvm *kvm);static inline struct kvm_memslots *__kvm_memslots (struct kvm *kvm,int as_id)
include/linux/vfio.h +2 -2
@@ -54,7 +54,7 @@ struct vfio_device {struct list_head dev_set_list;unsigned int migration_flags;u8 precopy_info_v2; -struct kvm *kvm; +struct file *kvm;/* Holds reference to KVM file */ /* Members below here are private, not for driver use */ unsigned int index;
@@ -377,7 +377,7 @@ static inline bool vfio_file_has_dev(struct file *file, struct vfio_device *devi#endif bool vfio_file_is_valid (struct file *file);bool vfio_file_enforced_coherent (struct file *file); -void vfio_file_set_kvm (struct file *file,struct kvm *kvm); +void vfio_file_set_kvm (struct file *vfio_file,struct file *kvm);#define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long))
virt/kvm/kvm_main.c +18 -5
@@ -1313,7 +1313,7 @@ void kvm_get_kvm(struct kvm *kvm) {refcount_inc (&kvm->users_count); } -EXPORT_SYMBOL_GPL (kvm_get_kvm); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_get_kvm);/* * Make sure the vm is not during destruction, which is a safe version of
@@ -1323,14 +1323,14 @@ bool kvm_get_kvm_safe(struct kvm *kvm) {return refcount_inc_not_zero (&kvm->users_count); } -EXPORT_SYMBOL_GPL (kvm_get_kvm_safe); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_get_kvm_safe);void kvm_put_kvm (struct kvm *kvm) {if (refcount_dec_and_test (&kvm->users_count))kvm_destroy_vm (kvm); } -EXPORT_SYMBOL_GPL (kvm_put_kvm); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_put_kvm);/* * Used to put a reference that was taken on behalf of an object associated
@@ -4802,7 +4802,7 @@ void kvm_unregister_device_ops(u32 type) kvm_device_ops_table[type] =NULL ; } -static int kvm_ioctl_create_device (struct kvm *kvm, +static int kvm_ioctl_create_device (struct file *file,struct kvm *kvm,struct kvm_create_device *cd) {const struct kvm_device_ops *ops;
@@ -5345,7 +5345,7 @@ static long kvm_vm_ioctl(struct file *filp,if (copy_from_user (&cd, argp,sizeof (cd))) goto out; - r =kvm_ioctl_create_device (kvm, &cd); + r =kvm_ioctl_create_device (filp, kvm, &cd);if (r) goto out;
@@ -5477,6 +5477,15 @@ bool file_is_kvm(struct file *file) }EXPORT_SYMBOL_FOR_KVM_INTERNAL (file_is_kvm); +struct kvm *file_to_kvm (struct file *file) +{ +if (!file_is_kvm (file)) +return NULL ; + +return file->private_data; +} +EXPORT_SYMBOL_FOR_KVM_INTERNAL (file_to_kvm); +static int kvm_dev_ioctl_create_vm (unsigned long type) {char fdname[ITOA_MAX_LEN +1 ];
@@ -5508,6 +5517,10 @@ static int kvm_dev_ioctl_create_vm(unsigned long type)* cases it will be called by the final fput(file) and will take * care of doing kvm_put_kvm(kvm). */ + +/* Store back-reference for VFIO and other subsystems */ + kvm->file = file; +kvm_uevent_notify_change (KVM_EVENT_CREATE_VM , kvm);fd_install (fd, file);
virt/kvm/vfio.c +4 -4
@@ -35,15 +35,15 @@ struct kvm_vfio {bool noncoherent; }; -static void kvm_vfio_file_set_kvm (struct file *file,struct kvm *kvm) +static void kvm_vfio_file_set_kvm (struct file *vfio_file,struct file *kvm) { -void (*fn)(struct file *file,struct kvm *kvm); +void (*fn)(struct file *vfio_file,struct file *kvm); fn =symbol_get (vfio_file_set_kvm);if (!fn)return ; -fn (file, kvm); +fn (vfio_file, kvm);symbol_put (vfio_file_set_kvm); }
@@ -168,7 +168,7 @@ static int kvm_vfio_file_add(struct kvm_device *dev, unsigned int fd) kvf->file =get_file (filp);list_add_tail (&kvf->node, &kv->file_list); -kvm_vfio_file_set_kvm (kvf->file, dev->kvm); +kvm_vfio_file_set_kvm (kvf->file, dev->kvm->file);kvm_vfio_update_coherency (dev);return 0 ;
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 4/31 arm64: Use proper include variant
In reply to Steffen EidenUse <> for including the sysreg header as it is not discoverable from the current directory.
--- arch/arm64/include/asm/sysreg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/sysreg.h +1 -1
@@ -173,7 +173,7 @@* come from here. The header relies on the definition of sys_reg() * earlier in this file. */ -#include "asm/sysreg-defs.h" +#include <asm/sysreg-defs.h> /* * System registers, organised loosely by encoding but grouped together
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 7/31 KVM: arm64: Access elements of vcpu_gp_regs individually
In reply to Steffen EidenWhile for arm64 the members of vcpu_gp_regs are allocated continuous this is not necessarily true for other architectures implementing ARM.
Let vcpu_gp_regs() no longer return the address of the user_pt_regs in the vcpu context but the address of the gp-register array field in the user_pt_reg struct. Note, this change semantically excludes pc from the GPRs.
No functional change.
--- arch/arm64/include/asm/kvm_emulate.h | 8 ++++---- arch/arm64/include/asm/kvm_host.h | 2 +- arch/arm64/kvm/hyp/exception.c | 4 ++-- arch/arm64/kvm/hyp/include/hyp/adjust_pc.h | 4 ++-- arch/arm64/kvm/hyp/include/hyp/switch.h | 4 ++-- arch/arm64/kvm/reset.c | 6 ++++-- 6 files changed, 15 insertions(+), 13 deletions(-)
arch/arm64/include/asm/kvm_emulate.h +4 -4
@@ -133,12 +133,12 @@ static inline void vcpu_set_vsesr(struct kvm_vcpu *vcpu, u64 vsesr)static __always_inline unsigned long *vcpu_pc (const struct kvm_vcpu *vcpu) { -return (unsigned long *)&vcpu_gp_regs (vcpu)->pc; +return (unsigned long *)&vcpu->arch.ctxt.regs.pc; }static __always_inline unsigned long *vcpu_cpsr (const struct kvm_vcpu *vcpu) { -return (unsigned long *)&vcpu_gp_regs (vcpu)->pstate; +return (unsigned long *)&vcpu->arch.ctxt.regs.pstate; } static __always_inline bool vcpu_mode_is_32bit(const struct kvm_vcpu *vcpu)
@@ -167,14 +167,14 @@ static inline void vcpu_set_thumb(struct kvm_vcpu *vcpu)static __always_inline unsigned long vcpu_get_reg (const struct kvm_vcpu *vcpu,u8 reg_num) { -return (reg_num ==31 ) ?0 :vcpu_gp_regs (vcpu)->regs[reg_num]; +return (reg_num ==31 ) ?0 :vcpu_gp_regs (vcpu)[reg_num]; } static __always_inline void vcpu_set_reg(struct kvm_vcpu *vcpu, u8 reg_num,unsigned long val) {if (reg_num !=31 ) -vcpu_gp_regs (vcpu)->regs[reg_num] = val; +vcpu_gp_regs (vcpu)[reg_num] = val; }static inline bool vcpu_is_el2_ctxt (const struct kvm_cpu_context *ctxt)
arch/arm64/include/asm/kvm_host.h +1 -1
@@ -1152,7 +1152,7 @@ struct kvm_vcpu_arch {#define vcpu_clear_on_unsupported_cpu (vcpu) \ vcpu_clear_flag(vcpu, ON_UNSUPPORTED_CPU) -#define vcpu_gp_regs (v) (&(v)->arch.ctxt.regs) +#define vcpu_gp_regs (v) ((v)->arch.ctxt.regs.regs)/* * Only use __vcpu_sys_reg/ctxt_sys_reg if you know you want the
arch/arm64/kvm/hyp/exception.c +2 -2
@@ -292,12 +292,12 @@ static void enter_exception32(struct kvm_vcpu *vcpu, u32 mode, u32 vect_offset)switch (mode) {case PSR_AA32_MODE_ABT :__vcpu_write_spsr_abt (vcpu,host_spsr_to_spsr32 (spsr)); -vcpu_gp_regs (vcpu)->compat_lr_abt = return_address; +vcpu_gp_regs (vcpu)[__compat_lr_abt] = return_address;break ;case PSR_AA32_MODE_UND :__vcpu_write_spsr_und (vcpu,host_spsr_to_spsr32 (spsr)); -vcpu_gp_regs (vcpu)->compat_lr_und = return_address; +vcpu_gp_regs (vcpu)[__compat_lr_und] = return_address;break ; }
arch/arm64/kvm/hyp/include/hyp/adjust_pc.h +2 -2
@@ -33,11 +33,11 @@ static inline void kvm_skip_instr(struct kvm_vcpu *vcpu)static inline void __kvm_skip_instr (struct kvm_vcpu *vcpu) { *vcpu_pc (vcpu) =read_sysreg_el2 (SYS_ELR ); -vcpu_gp_regs (vcpu)->pstate =read_sysreg_el2 (SYS_SPSR ); + *vcpu_cpsr (vcpu) =read_sysreg_el2 (SYS_SPSR );kvm_skip_instr (vcpu); -write_sysreg_el2 (vcpu_gp_regs (vcpu)->pstate,SYS_SPSR ); +write_sysreg_el2 (*vcpu_cpsr (vcpu),SYS_SPSR );write_sysreg_el2 (*vcpu_pc (vcpu),SYS_ELR ); }
arch/arm64/kvm/hyp/include/hyp/switch.h +2 -2
@@ -451,7 +451,7 @@ static inline bool kvm_hyp_handle_mops(struct kvm_vcpu *vcpu, u64 *exit_code)u64 spsr; *vcpu_pc (vcpu) =read_sysreg_el2 (SYS_ELR ); -arm64_mops_reset_regs (vcpu_gp_regs (vcpu), vcpu->arch.fault.esr_el2); +arm64_mops_reset_regs (&vcpu->arch.ctxt.regs, vcpu->arch.fault.esr_el2);write_sysreg_el2 (*vcpu_pc (vcpu),SYS_ELR );/*
@@ -896,7 +896,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? */
arch/arm64/kvm/reset.c +4 -2
@@ -218,13 +218,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->arch.ctxt.regs.sp =0 ;memset (&vcpu->arch.ctxt.fp_regs,0 ,sizeof (vcpu->arch.ctxt.fp_regs)); vcpu->arch.ctxt.spsr_abt =0 ; vcpu->arch.ctxt.spsr_und =0 ; vcpu->arch.ctxt.spsr_irq =0 ; vcpu->arch.ctxt.spsr_fiq =0 ; -vcpu_gp_regs (vcpu)->pstate = pstate; + *vcpu_cpsr (vcpu) = pstate;/* Reset system registers */ kvm_reset_sys_regs (vcpu);
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 16/31 KVM: s390: Move PGM code definitions to asm/kvm_host.h
In reply to Steffen EidenMove the PGM definitions from kvm_host_s390.h (back) to kvm_host.h so they can be used by a second KVM implementation.
No functional change.
--- arch/s390/include/asm/kvm_host.h | 57 +++++++++++++++++++++++++++ arch/s390/include/asm/kvm_host_s390.h | 57 --------------------------- 2 files changed, 57 insertions(+), 57 deletions(-)
arch/s390/include/asm/kvm_host.h +57 -0
@@ -5,4 +5,61 @@#include <asm/kvm_host_s390.h> +#define PGM_OPERATION 0x01 +#define PGM_PRIVILEGED_OP 0x02 +#define PGM_EXECUTE 0x03 +#define PGM_PROTECTION 0x04 +#define PGM_ADDRESSING 0x05 +#define PGM_SPECIFICATION 0x06 +#define PGM_DATA 0x07 +#define PGM_FIXED_POINT_OVERFLOW 0x08 +#define PGM_FIXED_POINT_DIVIDE 0x09 +#define PGM_DECIMAL_OVERFLOW 0x0a +#define PGM_DECIMAL_DIVIDE 0x0b +#define PGM_HFP_EXPONENT_OVERFLOW 0x0c +#define PGM_HFP_EXPONENT_UNDERFLOW 0x0d +#define PGM_HFP_SIGNIFICANCE 0x0e +#define PGM_HFP_DIVIDE 0x0f +#define PGM_SEGMENT_TRANSLATION 0x10 +#define PGM_PAGE_TRANSLATION 0x11 +#define PGM_TRANSLATION_SPEC 0x12 +#define PGM_SPECIAL_OPERATION 0x13 +#define PGM_OPERAND 0x15 +#define PGM_TRACE_TABEL 0x16 +#define PGM_VECTOR_PROCESSING 0x1b +#define PGM_SPACE_SWITCH 0x1c +#define PGM_HFP_SQUARE_ROOT 0x1d +#define PGM_PC_TRANSLATION_SPEC 0x1f +#define PGM_AFX_TRANSLATION 0x20 +#define PGM_ASX_TRANSLATION 0x21 +#define PGM_LX_TRANSLATION 0x22 +#define PGM_EX_TRANSLATION 0x23 +#define PGM_PRIMARY_AUTHORITY 0x24 +#define PGM_SECONDARY_AUTHORITY 0x25 +#define PGM_LFX_TRANSLATION 0x26 +#define PGM_LSX_TRANSLATION 0x27 +#define PGM_ALET_SPECIFICATION 0x28 +#define PGM_ALEN_TRANSLATION 0x29 +#define PGM_ALE_SEQUENCE 0x2a +#define PGM_ASTE_VALIDITY 0x2b +#define PGM_ASTE_SEQUENCE 0x2c +#define PGM_EXTENDED_AUTHORITY 0x2d +#define PGM_LSTE_SEQUENCE 0x2e +#define PGM_ASTE_INSTANCE 0x2f +#define PGM_STACK_FULL 0x30 +#define PGM_STACK_EMPTY 0x31 +#define PGM_STACK_SPECIFICATION 0x32 +#define PGM_STACK_TYPE 0x33 +#define PGM_STACK_OPERATION 0x34 +#define PGM_ASCE_TYPE 0x38 +#define PGM_REGION_FIRST_TRANS 0x39 +#define PGM_REGION_SECOND_TRANS 0x3a +#define PGM_REGION_THIRD_TRANS 0x3b +#define PGM_SECURE_STORAGE_ACCESS 0x3d +#define PGM_NON_SECURE_STORAGE_ACCESS 0x3e +#define PGM_SECURE_STORAGE_VIOLATION 0x3f +#define PGM_MONITOR 0x40 +#define PGM_PER 0x80 +#define PGM_CRYPTO_OPERATION 0x119 +#endif /* ASM_KVM_HOST_H */
arch/s390/include/asm/kvm_host_s390.h +0 -57
63 lines not on this page · raw message
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 10/31 arm64: Prepare sharing arm64 headers with s390
In reply to Steffen EidenPrepare the sharing of arm64 headers with s390 by moving a few definitions inside headers to reduce the number of shared markers. Clean up some includes to further streamline the sharing of headers.
No functional change.
--- arch/arm64/include/asm/esr.h | 4 +- arch/arm64/include/asm/kvm_arm.h | 5 ++- arch/arm64/include/asm/kvm_emulate.h | 5 ++- arch/arm64/include/asm/kvm_host.h | 59 ++++++++++++++-------------- arch/arm64/include/asm/sysreg.h | 2 +- 5 files changed, 39 insertions(+), 36 deletions(-)
arch/arm64/include/asm/esr.h +2 -2
@@ -7,7 +7,7 @@#ifndef __ASM_ESR_H#define __ASM_ESR_H -#include <asm/memory.h> +#include <asm/brk-imm.h> #include <asm/sysreg.h> #define ESR_ELx_EC_UNKNOWN UL(0x00)
@@ -435,7 +435,7 @@#define ESR_ELx_IT_GCSPOPX 7#ifndef __ASSEMBLER__ -#include <asm/types.h> +#include <linux/types.h> static inline unsigned long esr_brk_comment (unsigned long esr) {
arch/arm64/include/asm/kvm_arm.h +3 -2
@@ -7,10 +7,11 @@#ifndef __ARM64_KVM_ARM_H__#define __ARM64_KVM_ARM_H__ +#include <linux/const.h> +#include <linux/bits.h> +#include <linux/types.h> #include <asm/esr.h> -#include <asm/memory.h> #include <asm/sysreg.h> -#include <asm/types.h> /* * Because I'm terribly lazy and that repainting the whole of the KVM
arch/arm64/include/asm/kvm_emulate.h +3 -2
@@ -44,11 +44,12 @@ enum exception_type {bool kvm_condition_valid32 (const struct kvm_vcpu *vcpu);void kvm_skip_instr32 (struct kvm_vcpu *vcpu); +int kvm_inject_dabt_excl_atomic (struct kvm_vcpu *vcpu,u64 addr); +int kvm_inject_serror_esr (struct kvm_vcpu *vcpu,u64 esr); +void kvm_inject_undefined (struct kvm_vcpu *vcpu);void kvm_inject_sync (struct kvm_vcpu *vcpu,u64 esr); -int kvm_inject_serror_esr (struct kvm_vcpu *vcpu,u64 esr);int kvm_inject_sea (struct kvm_vcpu *vcpu,bool iabt,u64 addr); -int kvm_inject_dabt_excl_atomic (struct kvm_vcpu *vcpu,u64 addr);void kvm_inject_size_fault (struct kvm_vcpu *vcpu);static inline int kvm_inject_sea_dabt (struct kvm_vcpu *vcpu,u64 addr)
arch/arm64/include/asm/kvm_host.h +30 -29
71 lines not on this page · raw message
arch/arm64/include/asm/sysreg.h +1 -1
@@ -1263,6 +1263,6 @@ FIELD_PREP(reg##_##field##_MASK, \ SYS_FIELD_VALUE(reg, field, val)) -#endif +#endif /* __ASSEMBLER__ */ #endif /* __ASM_SYSREG_H */
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 11/31 arm64: Share arm64 headers with s390
In reply to Steffen EidenAllow sharing of arm64 headers with s390 by marking the shared regions or add a comment that the whole file is shared.
The shared regions are marked with:
#define ARM64_S390_COMMON
/* insert shared definitions here */
#endif /* ARM64_S390_COMMON */
The preprocessor symbol ARM64_S390_COMMON is always defined for arm64. No functional change.
--- arch/arm64/Makefile | 2 ++ arch/arm64/include/asm/brk-imm.h | 1 + arch/arm64/include/asm/esr.h | 1 + arch/arm64/include/asm/kvm_arm.h | 1 + arch/arm64/include/asm/kvm_emulate.h | 15 +++++++++++++++ arch/arm64/include/asm/kvm_host.h | 20 ++++++++++++++++++++ arch/arm64/include/asm/ptrace.h | 4 ++++ arch/arm64/include/asm/sysreg.h | 15 +++++++++++++++ 8 files changed, 59 insertions(+)
arch/arm64/Makefile +2 -0
@@ -43,7 +43,9 @@ CC_FLAGS_NO_FPU := -mgeneral-regs-only KBUILD_CFLAGS += $(CC_FLAGS_NO_FPU) \ $(compat_vdso) $(cc_has_k_constraint) KBUILD_CFLAGS += $(call cc-disable-warning, psabi) +KBUILD_CFLAGS += -DARM64_S390_COMMON KBUILD_AFLAGS += $(compat_vdso) +KBUILD_AFLAGS += -DARM64_S390_COMMON ifeq ($(call rustc-min-version, 108500),y) KBUILD_RUSTFLAGS += --target=aarch64-unknown-none-softfloat
arch/arm64/include/asm/brk-imm.h +1 -0
@@ -2,6 +2,7 @@/* * Copyright (C) 2012 ARM Ltd. */ +/* Whole file is shared with s390 */ #ifndef __ASM_BRK_IMM_H#define __ASM_BRK_IMM_H
arch/arm64/include/asm/esr.h +1 -0
@@ -3,6 +3,7 @@* Copyright (C) 2013 - ARM Ltd * Author: Marc Zyngier <[email protected]> */ +/* Whole file is shared with s390 */ #ifndef __ASM_ESR_H#define __ASM_ESR_H
arch/arm64/include/asm/kvm_arm.h +1 -0
@@ -3,6 +3,7 @@* Copyright (C) 2012,2013 - ARM Ltd * Author: Marc Zyngier <[email protected]> */ +/* Whole file is shared with s390 */ #ifndef __ARM64_KVM_ARM_H__#define __ARM64_KVM_ARM_H__
arch/arm64/include/asm/kvm_emulate.h +15 -0
@@ -47,6 +47,7 @@ void kvm_skip_instr32(struct kvm_vcpu *vcpu);int kvm_inject_dabt_excl_atomic (struct kvm_vcpu *vcpu,u64 addr);int kvm_inject_serror_esr (struct kvm_vcpu *vcpu,u64 esr); +#ifdef ARM64_S390_COMMON void kvm_inject_undefined (struct kvm_vcpu *vcpu);void kvm_inject_sync (struct kvm_vcpu *vcpu,u64 esr);int kvm_inject_sea (struct kvm_vcpu *vcpu,bool iabt,u64 addr);
@@ -62,6 +63,8 @@ static inline int kvm_inject_sea_iabt(struct kvm_vcpu *vcpu, u64 addr) return kvm_inject_sea(vcpu, true, addr); } +#endif /* ARM64_S390_COMMON */ +static inline int kvm_inject_serror (struct kvm_vcpu *vcpu) {/*
@@ -165,6 +168,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
@@ -183,6 +187,8 @@ static __always_inline void vcpu_set_reg(struct kvm_vcpu *vcpu, u8 reg_num, vcpu_gp_regs(vcpu)[reg_num] = val; } +#endif /* ARM64_S390_COMMON */ +static inline bool vcpu_is_el2_ctxt (const struct kvm_cpu_context *ctxt) {switch (ctxt->regs.pstate & (PSR_MODE32_BIT |PSR_MODE_MASK )) {
@@ -366,6 +372,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;
@@ -443,6 +450,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) {
@@ -483,6 +492,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)) {
@@ -507,6 +517,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 ;
@@ -542,6 +554,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)
@@ -617,6 +630,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.
arch/arm64/include/asm/kvm_host.h +20 -0
@@ -39,6 +39,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)
@@ -86,6 +87,8 @@/* Unhandled SEAs are taken to userspace */ #define KVM_ARCH_FLAG_EXIT_SEA 11 +#endif /* ARM64_S390_COMMON */ +#define KVM_DIRTY_LOG_MANUAL_CAPS (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \ KVM_DIRTY_LOG_INITIALLY_SET)
@@ -832,6 +835,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;
@@ -839,6 +844,8 @@ struct vcpu_reset_state {bool reset; }; +#endif /* ARM64_S390_COMMON */ +struct vncr_tlb ;struct kvm_vcpu_arch {
@@ -948,6 +955,7 @@ struct kvm_vcpu_arch {pid_t pid; }; +#ifdef ARM64_S390_COMMON /* * Each 'flag' is composed of a comma-separated triplet: *
@@ -1099,6 +1107,8 @@ struct kvm_vcpu_arch {/* KVM is currently emulating an L2 to L1 exception */ #define IN_NESTED_EXCEPTION __vcpu_single_flag(sflags, BIT(9)) +#endif /* ARM64_S390_COMMON */ +#define vcpu_sve_max_vq (vcpu) sve_vq_from_vl((vcpu)->arch.sve_max_vl)#define vcpu_sve_zcr_elx (vcpu) \
@@ -1240,6 +1250,7 @@ struct kvm_vcpu_stat {u64 exits; }; +#ifdef ARM64_S390_COMMON unsigned long kvm_arm_num_regs (struct kvm_vcpu *vcpu);int kvm_arm_copy_reg_indices (struct kvm_vcpu *vcpu,u64 __user *indices);int kvm_arm_get_reg (struct kvm_vcpu *vcpu,const struct kvm_one_reg *reg);
@@ -1248,6 +1259,8 @@ int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);unsigned long kvm_arm_num_sys_reg_descs (struct kvm_vcpu *vcpu);int kvm_arm_copy_sys_reg_indices (struct kvm_vcpu *vcpu,u64 __user *uindices); +#endif /* ARM64_S390_COMMON */ +int __kvm_arm_vcpu_get_events (struct kvm_vcpu *vcpu,struct kvm_vcpu_events *events);
@@ -1326,6 +1339,7 @@ int __init populate_nv_trap_config(void);void kvm_calculate_traps (struct kvm_vcpu *vcpu); +#ifdef ARM64_S390_COMMON /* MMIO helpers */ void kvm_mmio_write_buf (void *buf,unsigned int len,unsigned long data);unsigned long kvm_mmio_read_buf (const void *buf,unsigned int len);
@@ -1333,6 +1347,8 @@ unsigned long kvm_mmio_read_buf(const void *buf, unsigned int len);int kvm_handle_mmio_return (struct kvm_vcpu *vcpu);int io_mem_abort (struct kvm_vcpu *vcpu,phys_addr_t fault_ipa); +#endif /* ARM64_S390_COMMON */ +/* * Returns true if a Performance Monitoring Interrupt (PMI), a.k.a. perf event, * arrived in guest context. For arm64, any event that arrives while a vCPU is
@@ -1530,11 +1546,15 @@ static inline bool __vcpu_has_feature(const struct kvm_arch *ka, int feature)return test_bit (feature, ka->vcpu_features); } +#ifdef ARM64_S390_COMMON +#define kvm_vcpu_has_feature (k, f) __vcpu_has_feature(&(k)->arch, (f))#define vcpu_has_feature (v, f) __vcpu_has_feature(&(v)->kvm->arch, (f))#define kvm_vcpu_initialized (v) vcpu_get_flag(v, VCPU_INITIALIZED) +#endif /* ARM64_S390_COMMON */ +int kvm_trng_call (struct kvm_vcpu *vcpu);#ifdef CONFIG_KVM extern phys_addr_t hyp_mem_base;
arch/arm64/include/asm/ptrace.h +4 -0
@@ -28,6 +28,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 +70,8 @@#define PSR_AA32_IT_MASK 0x0600fc00/* If-Then execution state mask */ #define PSR_AA32_GE_MASK 0x000f0000 +#endif /* ARM64_S390_COMMON */ +#ifdef CONFIG_CPU_BIG_ENDIAN #define PSR_AA32_ENDSTATE PSR_AA32_E_BIT#else
arch/arm64/include/asm/sysreg.h +15 -0
@@ -16,6 +16,8 @@#include <asm/gpr-num.h> +#ifdef ARM64_S390_COMMON +/* * ARMv8 ARM reserves the following encoding for system registers: * (Ref: ARMv8 ARM, Section: "System instruction class encoding overview",
@@ -50,6 +52,8 @@#define sys_reg_CRm (id) (((id) >> CRm_shift) & CRm_mask)#define sys_reg_Op2 (id) (((id) >> Op2_shift) & Op2_mask) +#endif /* ARM64_S390_COMMON */ +#ifndef CONFIG_BROKEN_GAS_INST #ifdef __ASSEMBLER__
@@ -123,6 +127,8 @@#define GSB_SYS_BARRIER_INSN __SYS_BARRIER_INSN(1, 0, 12, 0, 0, 31)#define GSB_ACK_BARRIER_INSN __SYS_BARRIER_INSN(1, 0, 12, 0, 1, 31) +#ifdef ARM64_S390_COMMON +/* Data cache zero operations */ #define SYS_DC_ISW sys_insn(1, 0, 7, 6, 2)#define SYS_DC_IGSW sys_insn(1, 0, 7, 6, 4)
@@ -832,6 +838,8 @@#define SCTLR_ELx_A (BIT(1))#define SCTLR_ELx_M (BIT(0)) +#endif /* ARM64_S390_COMMON */ +#ifdef CONFIG_CPU_BIG_ENDIAN #define ENDIAN_SET_EL2 SCTLR_ELx_EE#else
@@ -866,6 +874,7 @@ SCTLR_EL1_LSMAOE | SCTLR_EL1_nTLSMD | SCTLR_EL1_EIS | \ SCTLR_EL1_TSCXT | SCTLR_EL1_EOS) +#ifdef ARM64_S390_COMMON /* MAIR_ELx memory attributes (used by Linux) */ #define MAIR_ATTR_DEVICE_nGnRnE UL(0x00)#define MAIR_ATTR_DEVICE_nGnRE UL(0x04)
@@ -1102,6 +1111,8 @@#define GICV5_GICR_CDNMIA_TYPE_MASK GENMASK_ULL(31, 29)#define GICV5_GICR_CDNMIA_ID_MASK GENMASK_ULL(23, 0) +#endif /* ARM64_S390_COMMON */ +#define gicr_insn (insn) read_sysreg_s(GICV5_OP_GICR_##insn)#define gic_insn (v, insn) write_sysreg_s(v, GICV5_OP_GIC_##insn)
@@ -1251,6 +1262,8 @@ par; \ }) +#ifdef ARM64_S390_COMMON +#define SYS_FIELD_VALUE (reg, field, val) reg##_##field##_##val#define SYS_FIELD_GET (reg, field, val) \
@@ -1263,6 +1276,8 @@ FIELD_PREP(reg##_##field##_MASK, \ SYS_FIELD_VALUE(reg, field, val)) +#endif /* ARM64_S390_COMMON */ +#endif /* __ASSEMBLER__ */ #endif /* __ASM_SYSREG_H */
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 19/31 KVM: s390: gmap: Move prefix handling to kvm/s390
In reply to Steffen EidenMove code handling prefix page tracking from kvm/gmap to kvm/s390. This enables other KVM implementations to use gmap without implementing prefix handling. The prefix tracking is turned on if KVM_S390_GUEST_HAS_PREFIX is defined.
No functional changes.
--- arch/s390/include/asm/kvm_host_s390.h | 2 ++ arch/s390/kvm/gmap/dat.c | 48 --------------------------- arch/s390/kvm/gmap/dat.h | 1 - arch/s390/kvm/gmap/gmap.c | 28 ---------------- arch/s390/kvm/gmap/gmap.h | 12 +------ arch/s390/kvm/gmap/prefix.h | 39 ++++++++++++++++++++++ arch/s390/kvm/s390/dat.c | 48 +++++++++++++++++++++++++++ arch/s390/kvm/s390/gmap.c | 29 ++++++++++++++++ 8 files changed, 119 insertions(+), 88 deletions(-) create mode 100644 arch/s390/kvm/gmap/prefix.h
arch/s390/include/asm/kvm_host_s390.h +2 -0
@@ -32,6 +32,8 @@#define KVM_INTERNAL_MEM_SLOTS 1 +#define KVM_S390_GUEST_HAS_PREFIX +/* * These seem to be used for allocating ->chip in the routing table, which we * don't use. 1 is as small as we can get to reduce the needed memory. If we
arch/s390/kvm/gmap/dat.c +0 -48
51 lines not on this page · raw message
arch/s390/kvm/gmap/dat.h +0 -1
@@ -538,7 +538,6 @@ void dat_set_ptval(struct page_table *table, struct ptval_param param, unsignedint dat_set_slot (struct kvm_s390_mmu_cache *mc,union asce asce,gfn_t start,gfn_t end,u16 type,u16 param); -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);
arch/s390/kvm/gmap/gmap.c +0 -28
@@ -24,11 +24,6 @@#include "s390.h" #include "faultin.h" -static inline bool kvm_s390_is_in_sie (struct kvm_vcpu *vcpu) -{ -return vcpu->arch.sie_block->prog0c &PROG_IN_SIE ; -} -static int gmap_limit_to_type (gfn_t limit) {if (!limit)
@@ -256,29 +251,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;
arch/s390/kvm/gmap/gmap.h +1 -11
@@ -11,6 +11,7 @@#define ARCH_KVM_GMAP_GMAP_H #include "dat.h" +#include "prefix.h" /** * enum gmap_flags - Flags of a gmap.
@@ -83,7 +84,6 @@ struct gmap_cache {for (pos = (head); n = pos ? pos->next :NULL , pos; pos = n) int s390_replace_asce(struct gmap *gmap); -bool _gmap_unmap_prefix (struct gmap *gmap,gfn_t gfn,gfn_t end,bool hint);bool gmap_age_gfn (struct gmap *gmap,gfn_t start,gfn_t end);bool gmap_unmap_gfn_range (struct gmap *gmap,struct kvm_memory_slot *slot,gfn_t start,gfn_t end);int gmap_try_fixup_minor (struct gmap *gmap,struct guest_fault *fault);
@@ -157,16 +157,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.
arch/s390/kvm/gmap/prefix.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef ARCH_KVM_GMAP_PREFIX_H +#define ARCH_KVM_GMAP_PREFIX_H + +#include "asm/dat-bits.h" +#include <linux/types.h> +#include <linux/kvm_types.h> +#include <linux/kvm_host.h> + +struct gmap ; +union asce ; + +#ifdef KVM_S390_GUEST_HAS_PREFIX +bool _gmap_unmap_prefix (struct gmap *gmap,gfn_t gfn,gfn_t end,bool hint); +int dat_set_prefix_notif_bit (union asce asce,gfn_t gfn); +#else +static inline bool _gmap_unmap_prefix (struct gmap *gmap,gfn_t gfn,gfn_t end,bool hint) +{ +return true; +} + +static inline int dat_set_prefix_notif_bit (union asce asce,gfn_t gfn) +{ +return 0 ; +} +#endif /* KVM_S390_GUEST_HAS_PREFIX */ + +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); +} + +#endif /* ARCH_KVM_GMAP_PREFIX_H */
arch/s390/kvm/s390/dat.c +48 -0
51 lines not on this page · raw message
arch/s390/kvm/s390/gmap.c +29 -0
@@ -3,6 +3,7 @@#include <linux/kvm_host.h> #include <asm/gmap_helpers.h> #include <gmap.h> +#include <prefix.h> #include "s390.h" static int _gmap_enable_skeys (struct gmap *gmap)
@@ -82,3 +83,31 @@ void _gmap_set_cmma_all(struct gmap *gmap, bool dirty) }while (gfn); } +static inline bool kvm_s390_is_in_sie (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.sie_block->prog0c &PROG_IN_SIE ; +} + +bool _gmap_unmap_prefix (struct gmap *gmap,gfn_t gfn,gfn_t end,bool hint) +{ +struct kvm *kvm = gmap->kvm; +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; +} +
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 17/31 KVM: s390: Prepare gmap for a second KVM implementation
In reply to Steffen EidenRefactor gmap code such that a second s390 (host) KVM implementation can use the gmap code as well. Move mmu code from s390 to gmap so the other KVM implementation can use it as well.
No functional change.
--- arch/s390/kvm/gmap/Makefile | 2 +- arch/s390/kvm/gmap/kvm_mmu.c | 131 +++++++++++++++++++++++++++++++++++ arch/s390/kvm/gmap/kvm_mmu.h | 18 +++++ arch/s390/kvm/s390/s390.c | 111 ++--------------------------- arch/s390/kvm/s390/s390.h | 11 +++ 5 files changed, 168 insertions(+), 105 deletions(-) create mode 100644 arch/s390/kvm/gmap/kvm_mmu.c create mode 100644 arch/s390/kvm/gmap/kvm_mmu.h
arch/s390/kvm/gmap/Makefile +1 -1
@@ -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)/kvm_mmu.o
arch/s390/kvm/gmap/kvm_mmu.c new file +131 -0
131 lines not on this page · raw message
arch/s390/kvm/gmap/kvm_mmu.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef ARCH_KVM_GMAP_MMU_H +#define ARCH_KVM_GMAP_MMU_H + +#include <linux/kvm_host.h> + +int s390_kvm_mmu_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log); +int s390_kvm_mmu_prepare_memory_region (struct kvm *kvm, +const struct kvm_memory_slot *old, +struct kvm_memory_slot *new, +enum kvm_mr_change change); +void s390_kvm_mmu_commit_memory_region (struct kvm *kvm, +struct kvm_memory_slot *old, +const struct kvm_memory_slot *new, +enum kvm_mr_change change); + +#endif /* ARCH_KVM_GMAP_MMU_H */
arch/s390/kvm/s390/s390.c +7 -104
147 lines not on this page · raw message
arch/s390/kvm/s390/s390.h +11 -0
@@ -594,6 +594,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 +629,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
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 13/31 KVM: s390: Prepare moving KVM/s390 to arch/s390/kvm/s390
In reply to Steffen EidenLay the groundwork for moving the native KVM/s390 to s390/kvm/s390 to allow for a second KVM module. 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. Cleanup the KVM/s390 makefile.
No functional change.
---
arch/s390/include/asm/kvm_host.h | 779 +-----------------
.../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/kvm/Kconfig | 4 +-
arch/s390/kvm/Makefile | 4 +-
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 | 46 ++
arch/s390/kvm/trace.h | 14 -
arch/s390/kvm/vsie.c | 2 +-
26 files changed, 87 insertions(+), 1168 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.harch/s390/include/asm/kvm_host.h +2 -777
@@ -1,783 +1,8 @@/* SPDX-License-Identifier: GPL-2.0 */ -/* -* definition for kernel virtual machines on s390 -* -* Copyright IBM Corp. 2008, 2018 -* -* Author(s): Carsten Otte <[email protected]> -*/ -#ifndef ASM_KVM_HOST_H #define ASM_KVM_HOST_H -#include <linux/types.h> -#include <linux/hrtimer.h> -#include <linux/interrupt.h> -#include <linux/kvm_types.h> -#include <linux/kvm.h> -#include <linux/seqlock.h> -#include <linux/module.h> -#include <linux/pci.h> -#include <linux/mmu_notifier.h> -#include <asm/kvm_host_types.h> -#include <asm/debug.h> -#include <asm/cpu.h> -#include <asm/fpu.h> -#include <asm/isc.h> -#include <asm/guarded_storage.h> - -#define KVM_HAVE_MMU_RWLOCK -#define KVM_MAX_VCPUS 255 - -#define KVM_INTERNAL_MEM_SLOTS 1 - -/* -* These seem to be used for allocating ->chip in the routing table, which we -* don't use. 1 is as small as we can get to reduce the needed memory. If we -* need to look at ->chip later on, we'll need to revisit this. -*/ -#define KVM_NR_IRQCHIPS 1 -#define KVM_IRQCHIP_NUM_PINS 1 -#define KVM_HALT_POLL_NS_DEFAULT 50000 - -/* s390-specific vcpu->requests bit members */ -#define KVM_REQ_ENABLE_IBS KVM_ARCH_REQ(0) -#define KVM_REQ_DISABLE_IBS KVM_ARCH_REQ(1) -#define KVM_REQ_ICPT_OPEREXC KVM_ARCH_REQ(2) -#define KVM_REQ_START_MIGRATION KVM_ARCH_REQ(3) -#define KVM_REQ_STOP_MIGRATION KVM_ARCH_REQ(4) -#define KVM_REQ_VSIE_RESTART KVM_ARCH_REQ(5) -#define KVM_REQ_REFRESH_GUEST_PREFIX \ - KVM_ARCH_REQ_FLAGS(6, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP) - -struct kvm_vcpu_stat { -struct kvm_vcpu_stat_generic generic; -u64 exit_userspace; -u64 exit_null; -u64 exit_external_request; -u64 exit_io_request; -u64 exit_external_interrupt; -u64 exit_stop_request; -u64 exit_validity; -u64 exit_instruction; -u64 exit_pei; -u64 halt_no_poll_steal; -u64 instruction_lctl; -u64 instruction_lctlg; -u64 instruction_stctl; -u64 instruction_stctg; -u64 exit_program_interruption; -u64 exit_instr_and_program; -u64 exit_operation_exception; -u64 deliver_ckc; -u64 deliver_cputm; -u64 deliver_external_call; -u64 deliver_emergency_signal; -u64 deliver_service_signal; -u64 deliver_virtio; -u64 deliver_stop_signal; -u64 deliver_prefix_signal; -u64 deliver_restart_signal; -u64 deliver_program; -u64 deliver_io; -u64 deliver_machine_check; -u64 exit_wait_state; -u64 inject_ckc; -u64 inject_cputm; -u64 inject_external_call; -u64 inject_emergency_signal; -u64 inject_mchk; -u64 inject_pfault_init; -u64 inject_program; -u64 inject_restart; -u64 inject_set_prefix; -u64 inject_stop_signal; -u64 instruction_epsw; -u64 instruction_gs; -u64 instruction_io_other; -u64 instruction_lpsw; -u64 instruction_lpswe; -u64 instruction_lpswey; -u64 instruction_pfmf; -u64 instruction_ptff; -u64 instruction_sck; -u64 instruction_sckpf; -u64 instruction_stidp; -u64 instruction_spx; -u64 instruction_stpx; -u64 instruction_stap; -u64 instruction_iske; -u64 instruction_ri; -u64 instruction_rrbe; -u64 instruction_sske; -u64 instruction_ipte_interlock; -u64 instruction_stsi; -u64 instruction_stfl; -u64 instruction_tb; -u64 instruction_tpi; -u64 instruction_tprot; -u64 instruction_tsch; -u64 instruction_sie; -u64 instruction_essa; -u64 instruction_sthyi; -u64 instruction_sigp_sense; -u64 instruction_sigp_sense_running; -u64 instruction_sigp_external_call; -u64 instruction_sigp_emergency; -u64 instruction_sigp_cond_emergency; -u64 instruction_sigp_start; -u64 instruction_sigp_stop; -u64 instruction_sigp_stop_store_status; -u64 instruction_sigp_store_status; -u64 instruction_sigp_store_adtl_status; -u64 instruction_sigp_arch; -u64 instruction_sigp_prefix; -u64 instruction_sigp_restart; -u64 instruction_sigp_init_cpu_reset; -u64 instruction_sigp_cpu_reset; -u64 instruction_sigp_unknown; -u64 instruction_diagnose_10; -u64 instruction_diagnose_44; -u64 instruction_diagnose_9c; -u64 diag_9c_ignored; -u64 diag_9c_forward; -u64 instruction_diagnose_258; -u64 instruction_diagnose_308; -u64 instruction_diagnose_500; -u64 instruction_diagnose_other; -u64 pfault_sync; -u64 signal_exits; -}; - -#define PGM_OPERATION 0x01 -#define PGM_PRIVILEGED_OP 0x02 -#define PGM_EXECUTE 0x03 -#define PGM_PROTECTION 0x04 -#define PGM_ADDRESSING 0x05 -#define PGM_SPECIFICATION 0x06 -#define PGM_DATA 0x07 -#define PGM_FIXED_POINT_OVERFLOW 0x08 -#define PGM_FIXED_POINT_DIVIDE 0x09 -#define PGM_DECIMAL_OVERFLOW 0x0a -#define PGM_DECIMAL_DIVIDE 0x0b -#define PGM_HFP_EXPONENT_OVERFLOW 0x0c -#define PGM_HFP_EXPONENT_UNDERFLOW 0x0d -#define PGM_HFP_SIGNIFICANCE 0x0e -#define PGM_HFP_DIVIDE 0x0f -#define PGM_SEGMENT_TRANSLATION 0x10 -#define PGM_PAGE_TRANSLATION 0x11 -#define PGM_TRANSLATION_SPEC 0x12 -#define PGM_SPECIAL_OPERATION 0x13 -#define PGM_OPERAND 0x15 -#define PGM_TRACE_TABEL 0x16 -#define PGM_VECTOR_PROCESSING 0x1b -#define PGM_SPACE_SWITCH 0x1c -#define PGM_HFP_SQUARE_ROOT 0x1d -#define PGM_PC_TRANSLATION_SPEC 0x1f -#define PGM_AFX_TRANSLATION 0x20 -#define PGM_ASX_TRANSLATION 0x21 -#define PGM_LX_TRANSLATION 0x22 -#define PGM_EX_TRANSLATION 0x23 -#define PGM_PRIMARY_AUTHORITY 0x24 -#define PGM_SECONDARY_AUTHORITY 0x25 -#define PGM_LFX_TRANSLATION 0x26 -#define PGM_LSX_TRANSLATION 0x27 -#define PGM_ALET_SPECIFICATION 0x28 -#define PGM_ALEN_TRANSLATION 0x29 -#define PGM_ALE_SEQUENCE 0x2a -#define PGM_ASTE_VALIDITY 0x2b -#define PGM_ASTE_SEQUENCE 0x2c -#define PGM_EXTENDED_AUTHORITY 0x2d -#define PGM_LSTE_SEQUENCE 0x2e -#define PGM_ASTE_INSTANCE 0x2f -#define PGM_STACK_FULL 0x30 -#define PGM_STACK_EMPTY 0x31 -#define PGM_STACK_SPECIFICATION 0x32 -#define PGM_STACK_TYPE 0x33 -#define PGM_STACK_OPERATION 0x34 -#define PGM_ASCE_TYPE 0x38 -#define PGM_REGION_FIRST_TRANS 0x39 -#define PGM_REGION_SECOND_TRANS 0x3a -#define PGM_REGION_THIRD_TRANS 0x3b -#define PGM_SECURE_STORAGE_ACCESS 0x3d -#define PGM_NON_SECURE_STORAGE_ACCESS 0x3e -#define PGM_SECURE_STORAGE_VIOLATION 0x3f -#define PGM_MONITOR 0x40 -#define PGM_PER 0x80 -#define PGM_CRYPTO_OPERATION 0x119 - -/* irq types in ascend order of priorities */ -enum irq_types { -IRQ_PEND_SET_PREFIX =0 , -IRQ_PEND_RESTART , -IRQ_PEND_SIGP_STOP , -IRQ_PEND_IO_ISC_7 , -IRQ_PEND_IO_ISC_6 , -IRQ_PEND_IO_ISC_5 , -IRQ_PEND_IO_ISC_4 , -IRQ_PEND_IO_ISC_3 , -IRQ_PEND_IO_ISC_2 , -IRQ_PEND_IO_ISC_1 , -IRQ_PEND_IO_ISC_0 , -IRQ_PEND_VIRTIO , -IRQ_PEND_PFAULT_DONE , -IRQ_PEND_PFAULT_INIT , -IRQ_PEND_EXT_HOST , -IRQ_PEND_EXT_SERVICE , -IRQ_PEND_EXT_SERVICE_EV , -IRQ_PEND_EXT_TIMING , -IRQ_PEND_EXT_CPU_TIMER , -IRQ_PEND_EXT_CLOCK_COMP , -IRQ_PEND_EXT_EXTERNAL , -IRQ_PEND_EXT_EMERGENCY , -IRQ_PEND_EXT_MALFUNC , -IRQ_PEND_EXT_IRQ_KEY , -IRQ_PEND_MCHK_REP , -IRQ_PEND_PROG , -IRQ_PEND_SVC , -IRQ_PEND_MCHK_EX , -IRQ_PEND_COUNT -}; - -/* We have 2M for virtio device descriptor pages. Smallest amount of -* memory per page is 24 bytes (1 queue), so (2048*1024) / 24 = 87381 -*/ -#define KVM_S390_MAX_VIRTIO_IRQS 87381 - -/* -* Repressible (non-floating) machine check interrupts -* subclass bits in MCIC -*/ -#define MCHK_EXTD_BIT 58 -#define MCHK_DEGR_BIT 56 -#define MCHK_WARN_BIT 55 -#define MCHK_REP_MASK ((1UL << MCHK_DEGR_BIT) | \ - (1UL << MCHK_EXTD_BIT) | \ - (1UL << MCHK_WARN_BIT)) - -/* Exigent machine check interrupts subclass bits in MCIC */ -#define MCHK_SD_BIT 63 -#define MCHK_PD_BIT 62 -#define MCHK_EX_MASK ((1UL << MCHK_SD_BIT) | (1UL << MCHK_PD_BIT)) - -#define IRQ_PEND_EXT_MASK ((1UL << IRQ_PEND_EXT_IRQ_KEY) | \ - (1UL << IRQ_PEND_EXT_CLOCK_COMP) | \ - (1UL << IRQ_PEND_EXT_CPU_TIMER) | \ - (1UL << IRQ_PEND_EXT_MALFUNC) | \ - (1UL << IRQ_PEND_EXT_EMERGENCY) | \ - (1UL << IRQ_PEND_EXT_EXTERNAL) | \ - (1UL << IRQ_PEND_EXT_TIMING) | \ - (1UL << IRQ_PEND_EXT_HOST) | \ - (1UL << IRQ_PEND_EXT_SERVICE) | \ - (1UL << IRQ_PEND_EXT_SERVICE_EV) | \ - (1UL << IRQ_PEND_VIRTIO) | \ - (1UL << IRQ_PEND_PFAULT_INIT) | \ - (1UL << IRQ_PEND_PFAULT_DONE)) - -#define IRQ_PEND_IO_MASK ((1UL << IRQ_PEND_IO_ISC_0) | \ - (1UL << IRQ_PEND_IO_ISC_1) | \ - (1UL << IRQ_PEND_IO_ISC_2) | \ - (1UL << IRQ_PEND_IO_ISC_3) | \ - (1UL << IRQ_PEND_IO_ISC_4) | \ - (1UL << IRQ_PEND_IO_ISC_5) | \ - (1UL << IRQ_PEND_IO_ISC_6) | \ - (1UL << IRQ_PEND_IO_ISC_7)) - -#define IRQ_PEND_MCHK_MASK ((1UL << IRQ_PEND_MCHK_REP) | \ - (1UL << IRQ_PEND_MCHK_EX)) - -#define IRQ_PEND_EXT_II_MASK ((1UL << IRQ_PEND_EXT_CPU_TIMER) | \ - (1UL << IRQ_PEND_EXT_CLOCK_COMP) | \ - (1UL << IRQ_PEND_EXT_EMERGENCY) | \ - (1UL << IRQ_PEND_EXT_EXTERNAL) | \ - (1UL << IRQ_PEND_EXT_SERVICE) | \ - (1UL << IRQ_PEND_EXT_SERVICE_EV)) - -struct kvm_s390_interrupt_info { -struct list_head list; -u64 type; -union { -struct kvm_s390_io_info io; -struct kvm_s390_ext_info ext; -struct kvm_s390_pgm_info pgm; -struct kvm_s390_emerg_info emerg; -struct kvm_s390_extcall_info extcall; -struct kvm_s390_prefix_info prefix; -struct kvm_s390_stop_info stop; -struct kvm_s390_mchk_info mchk; - }; -}; - -struct kvm_s390_irq_payload { -struct kvm_s390_io_info io; -struct kvm_s390_ext_info ext; -struct kvm_s390_pgm_info pgm; -struct kvm_s390_emerg_info emerg; -struct kvm_s390_extcall_info extcall; -struct kvm_s390_prefix_info prefix; -struct kvm_s390_stop_info stop; -struct kvm_s390_mchk_info mchk; -}; - -struct kvm_s390_local_interrupt { -spinlock_t lock; - DECLARE_BITMAP(sigp_emerg_pending, KVM_MAX_VCPUS); -struct kvm_s390_irq_payload irq; -unsigned long pending_irqs; -}; - -#define FIRQ_LIST_IO_ISC_0 0 -#define FIRQ_LIST_IO_ISC_1 1 -#define FIRQ_LIST_IO_ISC_2 2 -#define FIRQ_LIST_IO_ISC_3 3 -#define FIRQ_LIST_IO_ISC_4 4 -#define FIRQ_LIST_IO_ISC_5 5 -#define FIRQ_LIST_IO_ISC_6 6 -#define FIRQ_LIST_IO_ISC_7 7 -#define FIRQ_LIST_PFAULT 8 -#define FIRQ_LIST_VIRTIO 9 -#define FIRQ_LIST_COUNT 10 -#define FIRQ_CNTR_IO 0 -#define FIRQ_CNTR_SERVICE 1 -#define FIRQ_CNTR_VIRTIO 2 -#define FIRQ_CNTR_PFAULT 3 -#define FIRQ_MAX_COUNT 4 - -/* mask the AIS mode for a given ISC */ -#define AIS_MODE_MASK (isc) (0x80 >> isc) - -#define KVM_S390_AIS_MODE_ALL 0 -#define KVM_S390_AIS_MODE_SINGLE 1 - -struct kvm_s390_float_interrupt { -unsigned long pending_irqs; -unsigned long masked_irqs; -spinlock_t lock; -struct list_head lists[FIRQ_LIST_COUNT ]; -int counters[FIRQ_MAX_COUNT ]; -struct kvm_s390_mchk_info mchk; -struct kvm_s390_ext_info srv_signal; -int last_sleep_cpu; -spinlock_t ais_lock; -u8 simm; -u8 nimm; -}; - -struct kvm_hw_wp_info_arch { -unsigned long addr; -unsigned long phys_addr; -int len; -char *old_data; -}; - -struct kvm_hw_bp_info_arch { -unsigned long addr; -int len; -}; - -/* -* Only the upper 16 bits of kvm_guest_debug->control are arch specific. -* Further KVM_GUESTDBG flags which an be used from userspace can be found in -* arch/s390/include/uapi/asm/kvm.h -*/ -#define KVM_GUESTDBG_EXIT_PENDING 0x10000000 - -#define guestdbg_enabled (vcpu) \ - (vcpu->guest_debug & KVM_GUESTDBG_ENABLE) -#define guestdbg_sstep_enabled (vcpu) \ - (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) -#define guestdbg_hw_bp_enabled (vcpu) \ - (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP) -#define guestdbg_exit_pending (vcpu) (guestdbg_enabled(vcpu) && \ - (vcpu->guest_debug & KVM_GUESTDBG_EXIT_PENDING)) - -#define KVM_GUESTDBG_VALID_MASK \ - (KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLESTEP |\ - KVM_GUESTDBG_USE_HW_BP | KVM_GUESTDBG_EXIT_PENDING) - -struct kvm_guestdbg_info_arch { -unsigned long cr0; -unsigned long cr9; -unsigned long cr10; -unsigned long cr11; -struct kvm_hw_bp_info_arch *hw_bp_info; -struct kvm_hw_wp_info_arch *hw_wp_info; -int nr_hw_bp; -int nr_hw_wp; -unsigned long last_bp; -}; - -struct kvm_s390_pv_vcpu { -u64 handle; -unsigned long stor_base; -}; - -struct kvm_vcpu_arch { -struct kvm_s390_sie_block *sie_block; -/* if vsie is active, currently executed shadow sie control block */ -struct kvm_s390_sie_block *vsie_block; -unsigned int host_acrs[NUM_ACRS ]; -struct gs_cb *host_gscb; -struct kvm_s390_local_interrupt local_int; -struct hrtimer ckc_timer; -struct kvm_s390_pgm_info pgm; -struct gmap *gmap; -struct kvm_guestdbg_info_arch guestdbg; -unsigned long pfault_token; -unsigned long pfault_select; -unsigned long pfault_compare; -bool cputm_enabled; -/* -* The seqcount protects updates to cputm_start and sie_block.cputm, -* this way we can have non-blocking reads with consistent values. -* Only the owning VCPU thread (vcpu->cpu) is allowed to change these -* values and to start/stop/enable/disable cpu timer accounting. -*/ -seqcount_t cputm_seqcount; -__u64 cputm_start; -bool gs_enabled; -bool skey_enabled; -/* Indicator if the access registers have been loaded from guest */ -bool acrs_loaded; -struct kvm_s390_pv_vcpu pv; -union diag318_info diag318_info; -struct kvm_s390_mmu_cache *mc; -}; - -struct kvm_vm_stat { -struct kvm_vm_stat_generic generic; -u64 inject_io; -u64 io_390_adapter_map; -u64 io_390_adapter_unmap; -u64 io_390_inatomic; -u64 io_flic_inject_airq; -u64 io_set_adapter_int; -u64 io_390_inatomic_no_inject; -u64 inject_float_mchk; -u64 inject_pfault_done; -u64 inject_service_signal; -u64 inject_virtio; -u64 aen_forward; -u64 gmap_shadow_create; -u64 gmap_shadow_reuse; -u64 gmap_shadow_r1_entry; -u64 gmap_shadow_r2_entry; -u64 gmap_shadow_r3_entry; -u64 gmap_shadow_sg_entry; -u64 gmap_shadow_pg_entry; -}; - -struct kvm_arch_memory_slot { -}; - -struct s390_map_info { -struct list_head list; -__u64 guest_addr; -__u64 addr; -struct page *page; -/* -* True if the page is long-term pinned. False if long-term pinning -* failed and this entry exists only to preserve MAP/UNMAP symmetry. -*/ -bool pinned; -}; - -struct s390_io_adapter { -unsigned int id; -int isc; -bool maskable; -bool masked; -bool swap; -bool suppressible; -spinlock_t maps_lock; -struct list_head maps; -unsigned int nr_maps; -}; - -#define MAX_S390_IO_ADAPTERS ((MAX_ISC + 1) * 8) -#define MAX_S390_ADAPTER_MAPS 256 - -/* maximum size of facilities and facility mask is 2k bytes */ -#define S390_ARCH_FAC_LIST_SIZE_BYTE (1<<11) -#define S390_ARCH_FAC_LIST_SIZE_U64 \ - (S390_ARCH_FAC_LIST_SIZE_BYTE / sizeof(u64)) -#define S390_ARCH_FAC_MASK_SIZE_BYTE S390_ARCH_FAC_LIST_SIZE_BYTE -#define S390_ARCH_FAC_MASK_SIZE_U64 \ - (S390_ARCH_FAC_MASK_SIZE_BYTE / sizeof(u64)) - -struct kvm_s390_cpu_model { -/* facility mask supported by kvm & hosting machine */ -__u64 fac_mask[S390_ARCH_FAC_MASK_SIZE_U64 ]; -struct kvm_s390_vm_cpu_subfunc subfuncs; -/* facility list requested by guest (in dma page) */ -__u64 *fac_list; -u64 cpuid; -unsigned short ibc; -/* subset of available UV-features for pv-guests enabled by user space */ -struct kvm_s390_vm_cpu_uv_feat uv_feat_guest; -}; - -#define S390_ARCH_FAC_FORMAT_2 2 -struct kvm_s390_flcb2 { -union { -struct { -u8 reserved0[7 ]; -u8 length; - }; -u64 header_val; - }; -u64 facilities[S390_ARCH_FAC_LIST_SIZE_U64 ]; -}; - -typedef int (*crypto_hook )(struct kvm_vcpu *vcpu); - -struct kvm_s390_crypto { -struct kvm_s390_crypto_cb *crycb; -struct rw_semaphore pqap_hook_rwsem; -crypto_hook *pqap_hook; -__u32 crycbd; -__u8 aes_kw; -__u8 dea_kw; -__u8 apie; -}; - -#define APCB0_MASK_SIZE 1 -struct kvm_s390_apcb0 { -__u64 apm[APCB0_MASK_SIZE ];/* 0x0000 */ -__u64 aqm[APCB0_MASK_SIZE ];/* 0x0008 */ -__u64 adm[APCB0_MASK_SIZE ];/* 0x0010 */ -__u64 reserved18;/* 0x0018 */ -}; - -#define APCB1_MASK_SIZE 4 -struct kvm_s390_apcb1 { -__u64 apm[APCB1_MASK_SIZE ];/* 0x0000 */ -__u64 aqm[APCB1_MASK_SIZE ];/* 0x0020 */ -__u64 adm[APCB1_MASK_SIZE ];/* 0x0040 */ -__u64 reserved60[4 ];/* 0x0060 */ -}; - -struct kvm_s390_crypto_cb { -struct kvm_s390_apcb0 apcb0;/* 0x0000 */ -__u8 reserved20[0x0048 -0x0020 ];/* 0x0020 */ -__u8 dea_wrapping_key_mask[24 ];/* 0x0048 */ -__u8 aes_wrapping_key_mask[32 ];/* 0x0060 */ -struct kvm_s390_apcb1 apcb1;/* 0x0080 */ -}; - -struct kvm_s390_gisa { -union { -struct {/* common to all formats */ -u32 next_alert; -u8 ipm; -u8 reserved01[2 ]; -u8 iam; - }; -struct {/* format 0 */ -u32 next_alert; -u8 ipm; -u8 reserved01; - u8 : 6; -u8 g :1 ; -u8 c :1 ; -u8 iam; -u8 reserved02[4 ]; -u32 airq_count; - } g0; -struct {/* format 1 */ -u32 next_alert; -u8 ipm; -u8 simm; -u8 nimm; -u8 iam; -u8 aism[8 ]; - u8 : 6; -u8 g :1 ; -u8 c :1 ; -u8 reserved03[11 ]; -u32 airq_count; - } g1; -struct { -u64 word[4 ]; - } u64; - }; -}; - -struct kvm_s390_gib { -u32 alert_list_origin; -u32 reserved01; - u8:5; -u8 nisc:3 ; -u8 reserved03[3 ]; -u32 reserved04[5 ]; -}; - -/* -* sie_page2 has to be allocated as DMA because fac_list, crycb and -* gisa need 31bit addresses in the sie control block. -*/ -struct sie_page2 { -__u64 fac_list[S390_ARCH_FAC_LIST_SIZE_U64 ];/* 0x0000 */ -struct kvm_s390_crypto_cb crycb;/* 0x0800 */ -struct kvm_s390_gisa gisa;/* 0x0900 */ -struct kvm *kvm;/* 0x0920 */ -u8 reserved928[0x1000 -0x928 ];/* 0x0928 */ -}; - -struct vsie_page ; - -struct kvm_s390_vsie { -struct mutex mutex; -struct radix_tree_root addr_to_page; -int page_count; -int next; -struct vsie_page *pages[KVM_MAX_VCPUS ]; -}; - -struct kvm_s390_gisa_iam { -u8 mask; -spinlock_t ref_lock; -u32 ref_count[MAX_ISC +1 ]; -}; - -struct kvm_s390_gisa_interrupt { -struct kvm_s390_gisa *origin; -struct kvm_s390_gisa_iam alert; -struct hrtimer timer; -u64 expires; - DECLARE_BITMAP(kicked_mask, KVM_MAX_VCPUS); -}; - -struct kvm_s390_pv { -u64 handle; -u64 guest_len; -unsigned long stor_base; -void *stor_var; -bool dumping; -void *set_aside; -struct list_head need_cleanup; -struct mmu_notifier mmu_notifier; -/* Protects against concurrent import-like operations */ -struct mutex import_lock; -}; - -struct kvm_s390_mmu_cache ; - -struct kvm_arch { -struct esca_block *sca; -debug_info_t *dbf; -struct kvm_s390_float_interrupt float_int; -struct kvm_device *flic; -struct gmap *gmap; -unsigned long mem_limit; -int css_support; -int use_irqchip; -int use_cmma; -int use_pfmfi; -int use_skf; -int use_zpci_interp; -int user_cpu_state_ctrl; -int user_sigp; -int user_stsi; -int user_instr0; -int user_operexec; -int allow_vsie_esamode; -struct s390_io_adapter *adapters[MAX_S390_IO_ADAPTERS ]; -wait_queue_head_t ipte_wq; -int ipte_lock_count; -struct mutex ipte_mutex; -spinlock_t start_stop_lock; -struct sie_page2 *sie_page2; -struct kvm_s390_cpu_model model; -struct kvm_s390_crypto crypto; -struct kvm_s390_vsie vsie; -u8 epdx; -u64 epoch; -int migration_mode; -atomic64_t cmma_dirty_pages; -/* subset of available cpu features enabled by user space */ - DECLARE_BITMAP(cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS); -/* indexed by vcpu_idx */ - DECLARE_BITMAP(idle_mask, KVM_MAX_VCPUS); -struct kvm_s390_gisa_interrupt gisa_int; -struct kvm_s390_pv pv; -struct list_head kzdev_list; -spinlock_t kzdev_list_lock; -struct kvm_s390_mmu_cache *mc; -}; - -#define KVM_HVA_ERR_BAD (-1UL) -#define KVM_HVA_ERR_RO_BAD (-2UL) - -static inline bool kvm_is_error_hva (unsigned long addr) -{ -return IS_ERR_VALUE (addr); -} - -#define ASYNC_PF_PER_VCPU 64 -struct kvm_arch_async_pf { -unsigned long pfault_token; -}; - -bool kvm_arch_can_dequeue_async_page_present (struct kvm_vcpu *vcpu); - -void kvm_arch_async_page_ready (struct kvm_vcpu *vcpu, -struct kvm_async_pf *work); - -bool kvm_arch_async_page_not_present (struct kvm_vcpu *vcpu, -struct kvm_async_pf *work); - -void kvm_arch_async_page_present (struct kvm_vcpu *vcpu, -struct kvm_async_pf *work); - -static inline void kvm_arch_async_page_present_queued (struct kvm_vcpu *vcpu) {} - -void kvm_arch_crypto_clear_masks (struct kvm *kvm); -void kvm_arch_crypto_set_masks (struct kvm *kvm,unsigned long *apm, -unsigned long *aqm,unsigned long *adm); - -#define SIE64_RETURN_NORMAL 0 -#define SIE64_RETURN_MCCK 1 - -int __sie64a (phys_addr_t sie_block_phys,struct kvm_s390_sie_block *sie_block,u64 *rsa, -unsigned long gasce); - -static inline int sie64a (struct kvm_s390_sie_block *sie_block,u64 *rsa,unsigned long gasce) -{ -return __sie64a (virt_to_phys (sie_block), sie_block, rsa, gasce); -} - -extern char sie_exit; - -bool kvm_s390_pv_is_protected (struct kvm *kvm); -bool kvm_s390_pv_cpu_is_protected (struct kvm_vcpu *vcpu); - -extern int kvm_s390_enter_exit_sie (struct kvm_s390_sie_block *scb, -u64 *gprs,unsigned long gasce); - -extern int kvm_s390_gisc_register (struct kvm *kvm,u32 gisc); -extern int kvm_s390_gisc_unregister (struct kvm *kvm,u32 gisc); - -bool kvm_s390_is_gpa_in_memslot (struct kvm *kvm,gpa_t gpa); - -static inline void kvm_arch_free_memslot (struct kvm *kvm, -struct kvm_memory_slot *slot) {} -static inline void kvm_arch_memslots_updated (struct kvm *kvm,u64 gen) {} -static inline void kvm_arch_flush_shadow_all (struct kvm *kvm) {} -static inline void kvm_arch_flush_shadow_memslot (struct kvm *kvm, -struct kvm_memory_slot *slot) {} -static inline void kvm_arch_vcpu_blocking (struct kvm_vcpu *vcpu) {} -static inline void kvm_arch_vcpu_unblocking (struct kvm_vcpu *vcpu) {} - -#define __KVM_HAVE_ARCH_VM_FREE -void kvm_arch_free_vm (struct kvm *kvm); - -struct zpci_kvm_hook { -int (*kvm_register)(void *opaque,struct kvm *kvm); -void (*kvm_unregister)(void *opaque); -}; - -extern struct zpci_kvm_hook zpci_kvm_hook; +#include <asm/kvm_host_s390.h> -#endif +#endif /* ASM_KVM_HOST_H */
arch/s390/include/asm/kvm_host_s390.h renamed from arch/s390/include/asm/kvm_host.h +3 -3
@@ -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>
@@ -780,4 +780,4 @@ struct zpci_kvm_hook {extern struct zpci_kvm_hook zpci_kvm_hook; -#endif +#endif /* ASM_KVM_HOST_S390_H */
arch/s390/include/asm/kvm_host_s390_types.h renamed from arch/s390/include/asm/kvm_host_types.h +3 -3
@@ -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 */
arch/s390/include/asm/kvm_host_types.h +4 -343
351 lines not on this page · raw message
arch/s390/kvm/Kconfig +2 -2
@@ -18,7 +18,7 @@ if VIRTUALIZATION config KVM def_tristate y - prompt "Kernel-based Virtual Machine (KVM) support" + prompt "Kernel-based Virtual Machine (KVM) support (s390)" select HAVE_KVM_CPU_RELAX_INTERCEPT select KVM_ASYNC_PF select KVM_ASYNC_PF_SYNC
@@ -32,7 +32,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.
arch/s390/kvm/Makefile +2 -2
@@ -5,9 +5,9 @@ include $(srctree)/virt/kvm/Makefile.kvm -ccflags-y := -Ivirt/kvm -Iarch/s390/kvm +ccflags-y := -I$(src) -kvm-y += kvm-s390.o intercept.o interrupt.o priv.o sigp.o +kvm-y += s390.o intercept.o interrupt.o priv.o sigp.o kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o kvm-y += dat.o gmap.o faultin.o
arch/s390/kvm/dat.h +3 -3
@@ -6,8 +6,8 @@* Author(s): Claudio Imbrenda <[email protected]> */ -#ifndef __KVM_S390_DAT_H -#define __KVM_S390_DAT_H +#ifndef ARCH_KVM_GMAP_DAT_H +#define ARCH_KVM_GMAP_DAT_H #include <linux/radix-tree.h> #include <linux/refcount.h>
@@ -975,4 +975,4 @@ static inline bool crste_is_ucas(union crste crste) return is_pmd(crste) && crste.h.i && crste.h.fc0.tl == 1 && crste.h.fc == 0; } -#endif /* __KVM_S390_DAT_H */ +#endif /* ARCH_KVM_GMAP_DAT_H */
arch/s390/kvm/diag.c +1 -1
@@ -12,7 +12,7 @@#include <linux/kvm_host.h> #include <asm/gmap_helpers.h> #include <asm/virtio-ccw.h> -#include "kvm-s390.h" +#include "s390.h" #include "trace.h" #include "trace-s390.h" #include "gaccess.h"
arch/s390/kvm/faultin.c +2 -1
@@ -9,10 +9,11 @@#include <linux/kvm_host.h> #include "gmap.h" -#include "trace.h" #include "faultin.h" bool kvm_arch_setup_async_pf (struct kvm_vcpu *vcpu); +#define CREATE_TRACE_POINTS +#include "trace-gmap.h" /* * kvm_s390_faultin_gfn() - handle a dat fault.
arch/s390/kvm/faultin.h +3 -3
@@ -6,8 +6,8 @@* Author(s): Claudio Imbrenda <[email protected]> */ -#ifndef __KVM_S390_FAULTIN_H -#define __KVM_S390_FAULTIN_H +#ifndef ARCH_KVM_GMAP_FAULTIN_H +#define ARCH_KVM_GMAP_FAULTIN_H #include <linux/kvm_host.h>
@@ -89,4 +89,4 @@ static inline int kvm_s390_get_guest_pages(struct kvm *kvm, struct guest_fault *#define kvm_s390_array_needs_retry_safe (kvm, seq, array) \ kvm_s390_multiple_faults_need_retry(kvm, seq, array, ARRAY_SIZE(array), false) -#endif /* __KVM_S390_FAULTIN_H */ +#endif /* ARCH_KVM_GMAP_FAULTIN_H */
arch/s390/kvm/gaccess.c +1 -1
@@ -17,7 +17,7 @@#include <asm/access-regs.h> #include <asm/fault.h> #include <asm/dat-bits.h> -#include "kvm-s390.h" +#include "s390.h" #include "dat.h" #include "gmap.h" #include "gaccess.h"
arch/s390/kvm/gaccess.h +1 -1
@@ -14,7 +14,7 @@#include <linux/kvm_host.h> #include <linux/uaccess.h> #include <linux/ptrace.h> -#include "kvm-s390.h" +#include "s390.h" /** * kvm_s390_real_to_abs - convert guest real address to guest absolute address
arch/s390/kvm/gmap.c +1 -1
@@ -21,7 +21,7 @@#include "dat.h" #include "gmap.h" -#include "kvm-s390.h" +#include "s390.h" #include "faultin.h" static inline bool kvm_s390_is_in_sie (struct kvm_vcpu *vcpu)
arch/s390/kvm/gmap.h +3 -3
@@ -7,8 +7,8 @@* Claudio Imbrenda <[email protected]> */ -#ifndef ARCH_KVM_S390_GMAP_H -#define ARCH_KVM_S390_GMAP_H +#ifndef ARCH_KVM_GMAP_GMAP_H +#define ARCH_KVM_GMAP_GMAP_H #include "dat.h"
@@ -330,4 +330,4 @@ static inline bool gmap_is_shadow_valid(struct gmap *sg, union asce asce, int ed return sg->guest_asce.val == asce.val && sg->edat_level == edat_level; } -#endif /* ARCH_KVM_S390_GMAP_H */ +#endif /* ARCH_KVM_GMAP_GMAP_H */
arch/s390/kvm/guestdbg.c +1 -1
@@ -8,7 +8,7 @@*/ #include <linux/kvm_host.h> #include <linux/errno.h> -#include "kvm-s390.h" +#include "s390.h" #include "gaccess.h" /*
arch/s390/kvm/intercept.c +1 -1
@@ -17,7 +17,7 @@#include <asm/sysinfo.h> #include <asm/uv.h> -#include "kvm-s390.h" +#include "s390.h" #include "gaccess.h" #include "trace.h" #include "trace-s390.h"
arch/s390/kvm/interrupt.c +1 -1
@@ -29,7 +29,7 @@#include <asm/nmi.h> #include <asm/airq.h> #include <asm/tpi.h> -#include "kvm-s390.h" +#include "s390.h" #include "gaccess.h" #include "trace-s390.h" #include "pci.h"
arch/s390/kvm/pci.c +1 -1
@@ -14,7 +14,7 @@#include <asm/pci_io.h> #include <asm/sclp.h> #include "pci.h" -#include "kvm-s390.h" +#include "s390.h" struct zpci_aift *aift;
arch/s390/kvm/priv.c +1 -1
@@ -26,7 +26,7 @@#include <asm/ap.h> #include <asm/gmap_helpers.h> #include "gaccess.h" -#include "kvm-s390.h" +#include "s390.h" #include "trace.h" #include "gmap.h"
arch/s390/kvm/pv.c +1 -1
@@ -18,7 +18,7 @@#include <linux/sched/mm.h> #include <linux/mmu_notifier.h> #include <asm/gmap_helpers.h> -#include "kvm-s390.h" +#include "s390.h" #include "dat.h" #include "gaccess.h" #include "gmap.h"
arch/s390/kvm/s390.c renamed from arch/s390/kvm/kvm-s390.c +1 -1
@@ -50,7 +50,7 @@#include <asm/fpu.h> #include <asm/ap.h> #include <asm/uv.h> -#include "kvm-s390.h" +#include "s390.h" #include "gaccess.h" #include "gmap.h" #include "faultin.h"
arch/s390/kvm/s390.h renamed from arch/s390/kvm/kvm-s390.h +1 -1
@@ -452,7 +452,7 @@ void kvm_s390_vsie_destroy(struct kvm *kvm);int kvm_s390_handle_sigp (struct kvm_vcpu *vcpu);int kvm_s390_handle_sigp_pei (struct kvm_vcpu *vcpu); -/* implemented in kvm-s390.c */ +/* implemented in s390.c */ int kvm_s390_try_set_tod_clock (struct kvm *kvm,const struct kvm_s390_vm_tod_clock *gtod);int kvm_s390_store_status_unloaded (struct kvm_vcpu *vcpu,unsigned long addr);int kvm_s390_vcpu_store_status (struct kvm_vcpu *vcpu,unsigned long addr);
arch/s390/kvm/sigp.c +1 -1
@@ -14,7 +14,7 @@#include <linux/slab.h> #include <asm/sigp.h> #include "gaccess.h" -#include "kvm-s390.h" +#include "s390.h" #include "trace.h" static int __sigp_sense(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu,
arch/s390/kvm/trace-gmap.h new file +46 -0
46 lines not on this page · raw message
arch/s390/kvm/trace.h +0 -14
@@ -45,20 +45,6 @@ TRACE_EVENT(kvm_s390_skey_related_inst,VCPU_TP_PRINTK ("%s" ,"storage key related instruction" ) ); -TRACE_EVENT (kvm_s390_major_guest_pfault, -TP_PROTO (VCPU_PROTO_COMMON ), -TP_ARGS (VCPU_ARGS_COMMON ), - -TP_STRUCT__entry ( -VCPU_FIELD_COMMON - ), - -TP_fast_assign ( -VCPU_ASSIGN_COMMON - ), -VCPU_TP_PRINTK ("%s" ,"major fault, maybe applicable for pfault" ) - ); - TRACE_EVENT(kvm_s390_pfault_init, TP_PROTO(VCPU_PROTO_COMMON, long pfault_token), TP_ARGS(VCPU_ARGS_COMMON, pfault_token),
arch/s390/kvm/vsie.c +1 -1
@@ -23,7 +23,7 @@#include <asm/nmi.h> #include <asm/dis.h> #include <asm/facility.h> -#include "kvm-s390.h" +#include "s390.h" #include "gaccess.h" #include "gmap.h"
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 20/31 KVM: s390: Prepare KVM/s390 for a second KVM module
In reply to Steffen EidenThe second KVM module will have a different Kconfig set. When both modules are compiled the Kconfig sets get merged and the native s390 KVM needs to implement functionality required by the respective config options. Ensure that s390-KVM will still compile by implementing a stub for kvm_arch_vcpu_run_pid_change if CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE is enabled and defining KVM_NO_MMIO to disable KVM_MMIO.
--- arch/s390/include/asm/kvm_host_s390.h | 1 + arch/s390/kvm/s390/s390.c | 8 ++++++++ 2 files changed, 9 insertions(+)
arch/s390/include/asm/kvm_host_s390.h +1 -0
@@ -29,6 +29,7 @@#define KVM_HAVE_MMU_RWLOCK #define KVM_MAX_VCPUS 255 +#define KVM_NO_MMIO #define KVM_INTERNAL_MEM_SLOTS 1
arch/s390/kvm/s390/s390.c +8 -0
@@ -5829,6 +5829,14 @@ bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range)return gmap_unmap_gfn_range (kvm->arch.gmap, range->slot, range->start, range->end); } +#ifdef CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE +/* Make s390 compile if arm64-on-s390 is selected */ +int kvm_arch_vcpu_run_pid_change (struct kvm_vcpu *vcpu) +{ +return 0 ; +} +#endif /* CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE */ +static inline unsigned long nonhyp_mask (int i) {unsigned int nonhyp_fai = (sclp.hmfai << i *2 ) >>30 ;
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 26/31 KVM: s390: Add basic arm64 kvm module
In reply to Steffen EidenAdd basic code for the new arm64 on s390 KVM implementation. Add kernel module boilerplate code and trivial functions. Add tracing scaffolding.
--- arch/s390/kvm/arm64/arm.c | 157 ++++++++++++++++++++++++++++++++++++ arch/s390/kvm/arm64/arm.h | 7 ++ arch/s390/kvm/arm64/guest.c | 92 +++++++++++++++++++++ arch/s390/kvm/arm64/trace.h | 18 +++++ 4 files changed, 274 insertions(+) create mode 100644 arch/s390/kvm/arm64/arm.c create mode 100644 arch/s390/kvm/arm64/arm.h create mode 100644 arch/s390/kvm/arm64/guest.c create mode 100644 arch/s390/kvm/arm64/trace.h
arch/s390/kvm/arm64/arm.c new file +157 -0
@@ -0,0 +1,157 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define KMSG_COMPONENT "kvm-s390-arm64" +#define pr_fmt (fmt) KMSG_COMPONENT ": " fmt + +#include <linux/miscdevice.h> +#include <linux/kvm.h> +#include <linux/kvm_types.h> +#include <linux/kvm_host.h> + +#include "arm.h" + +#define CREATE_TRACE_POINTS +#include "trace.h" + +static unsigned long system_supported_vcpu_features (void ); + +#define __INCL_GEN_ARM_FILE +#include "generated/arm.inc" +#undef __INCL_GEN_ARM_FILE + +int kvm_vm_ioctl_check_extension (struct kvm *kvm,long ext) +{ +int ret; + +switch (ext) { +case KVM_CAP_NR_VCPUS : +case KVM_CAP_MAX_VCPUS : +case KVM_CAP_MAX_VCPU_ID : + ret =KVM_MAX_VCPUS ; +break ; +case KVM_CAP_ARM_VM_IPA_SIZE : + ret =get_kvm_ipa_limit (); +break ; +case KVM_CAP_IOEVENTFD : + ret =1 ; +break ; +default : + ret =0 ; + } + +return ret; +} + +static u64 kvm_max_guest_address (void ) +{ +u64 max_addr; + +if (sclp.hamax ==U64_MAX ) + max_addr =TASK_SIZE_MAX ; +else + max_addr =min_t (u64,TASK_SIZE_MAX , sclp.hamax); +return ALIGN_DOWN (max_addr +1 ,1 <<30 ) -1 ; +} + +vm_fault_t kvm_arch_vcpu_fault (struct kvm_vcpu *vcpu,struct vm_fault *vmf) +{ +return VM_FAULT_SIGBUS ; +} + +long kvm_arch_dev_ioctl (struct file *filp, +unsigned int ioctl,unsigned long arg) +{ +return -EINVAL ; +} + +u32 get_kvm_ipa_limit (void ) +{ +return fls64 (kvm_max_guest_address () +1 ) -1 ; +} + +int kvm_arch_vcpu_precreate (struct kvm *kvm,unsigned int id) +{ +return 0 ; +} + +void kvm_arch_vcpu_postcreate (struct kvm_vcpu *vcpu) +{ +} + +int kvm_arch_vcpu_ioctl_get_mpstate (struct kvm_vcpu *vcpu, +struct kvm_mp_state *mp_state) +{ + *mp_state =READ_ONCE (vcpu->arch.mp_state); +return 0 ; +} + +int kvm_arch_vcpu_ioctl_set_mpstate (struct kvm_vcpu *vcpu, +struct kvm_mp_state *mp_state) +{ +return -EINVAL ; +} + +int kvm_arch_vcpu_runnable (struct kvm_vcpu *vcpu) +{ +return 0 ; +} + +static unsigned long system_supported_vcpu_features (void ) +{ +unsigned long features =KVM_S390_ARM64_IMPL_FEATURES ; + +return features; +} + +bool kvm_arch_irqchip_in_kernel (struct kvm *kvm) +{ +return false; +} + +int kvm_set_msi (struct kvm_kernel_irq_routing_entry *e,struct kvm *kvm, +int irq_source_id,int level,bool line_status) +{ +return -EINVAL ; +} + +int kvm_set_routing_entry (struct kvm *kvm, +struct kvm_kernel_irq_routing_entry *e, +const struct kvm_irq_routing_entry *ue) +{ +return -EINVAL ; +} + +int kvm_cpu_has_pending_timer (struct kvm_vcpu *vcpu) +{ +return 0 ; +} + +#ifdef CONFIG_HAVE_KVM_NO_POLL +__weak bool kvm_arch_no_poll (struct kvm_vcpu *vcpu) +{ +return false; +} +#endif + +long kvm_arch_vcpu_unlocked_ioctl (struct file *filp,unsigned int ioctl, +unsigned long arg) +{ +return -ENOIOCTLCMD ; +} + +static int __init kvm_s390_arm64_init (void ) +{ +if (!sclp.has_aef) +return -ENXIO ; + +return kvm_init_with_dev (sizeof (struct kvm_vcpu ),0 ,THIS_MODULE , +KVM_DEV_NAME ,MISC_DYNAMIC_MINOR ); +} + +static __exit void kvm_s390_arm64_exit(void) +{ +kvm_exit (); +} + +module_init (kvm_s390_arm64_init); +module_exit (kvm_s390_arm64_exit);
arch/s390/kvm/arm64/arm.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef ARCH_S390_KVM_ARM64_H +#define ARCH_S390_KVM_ARM64_H + +#define KVM_DEV_NAME "kvm-arm64" + +#endif /* ARCH_S390_KVM_ARM64_H */
arch/s390/kvm/arm64/guest.c new file +92 -0
92 lines not on this page · raw message
arch/s390/kvm/arm64/trace.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#if !defined(KVM_ARM64_TRACE_KVM_H ) || defined(TRACE_HEADER_MULTI_READ ) +#define KVM_ARM64_TRACE_KVM_H + +#include <linux/tracepoint.h> + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM kvm + +#endif /* KVM_ARM64_TRACE_KVM_H */ + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE trace + +/* This part must be outside protection */ +#include <trace/define_trace.h>
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 27/31 KVM: s390: arm64: Implement required functions
In reply to Steffen EidenImplement the mostly trivial functions that the shared arm64 (kvm) code & headers oblige s390 to implement.
Implement a very basic smccc handler that (non-compliantly) is just able to stop a vcpu.
--- arch/s390/include/arm64/kvm_emulate.h | 102 ++++++++++++++++++++++++++ arch/s390/include/arm64/kvm_nested.h | 11 +++ arch/s390/include/arm64/ptrace.h | 11 +++ arch/s390/include/arm64/sysreg.h | 13 ++++ arch/s390/kvm/arm64/handle_exit.c | 98 +++++++++++++++++++++++++ arch/s390/kvm/arm64/inject_fault.c | 21 ++++++ 6 files changed, 256 insertions(+) create mode 100644 arch/s390/include/arm64/kvm_emulate.h create mode 100644 arch/s390/include/arm64/kvm_nested.h create mode 100644 arch/s390/include/arm64/ptrace.h create mode 100644 arch/s390/include/arm64/sysreg.h create mode 100644 arch/s390/kvm/arm64/handle_exit.c create mode 100644 arch/s390/kvm/arm64/inject_fault.c
arch/s390/include/arm64/kvm_emulate.h new file +102 -0
@@ -0,0 +1,102 @@ +/* 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 inline unsigned long *vcpu_hcr (struct kvm_vcpu *vcpu) +{ +return (unsigned long *)&vcpu->arch.hcr_elz; +} + +static __always_inline unsigned long kvm_vcpu_get_hfar (const struct kvm_vcpu *vcpu) +{ +return vcpu->arch.sae_block.hai.far_elz; +} + +static __always_inline phys_addr_t kvm_vcpu_get_fault_ipa(const struct kvm_vcpu *vcpu) +{ +return vcpu->arch.sae_block.hai.teid.addr *PAGE_SIZE ; +} + +static inline u16 kvm_vcpu_fault_pic (const struct kvm_vcpu *vcpu) +{ +return vcpu->arch.sae_block.hai.pic &PGM_INT_CODE_MASK ; +} + +static __always_inline +bool kvm_vcpu_trap_is_permission_fault(const struct kvm_vcpu *vcpu) +{ +return kvm_vcpu_fault_pic (vcpu) ==PGM_PROTECTION ; +} + +static __always_inline bool kvm_condition_valid(const struct kvm_vcpu *vcpu) +{ +return true; +} + +static __always_inline bool vcpu_el1_is_32bit(struct kvm_vcpu *vcpu) +{ +return false; +} + +static inline bool kvm_vcpu_is_be (struct kvm_vcpu *vcpu) +{ +return false; +} + +static inline int kvm_vcpu_abt_gltl (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.sae_block.hai.gltl; +} + +static inline bool vcpu_mode_priv (const struct kvm_vcpu *vcpu) +{ +u32 mode = *vcpu_cpsr (vcpu) &PSR_MODE_MASK ; + +return mode != PSR_MODE_EL0t; +} + +static inline void kvm_skip_instr (struct kvm_vcpu *vcpu) +{ + *vcpu_pc (vcpu) +=4 ; + *vcpu_cpsr (vcpu) &= ~PSR_BTYPE_MASK ; + +/* advance the singlestep state machine */ + *vcpu_cpsr (vcpu) &= ~SPSR_EL1_SS ; +} + +#include <arm64/kvm_emulate-gen.h> + +#endif /* __S390_ARM64_KVM_EMULATE_H__ */
arch/s390/include/arm64/kvm_nested.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef ASM_KVM_NESTED_H +#define ASM_KVM_NESTED_H + +static inline bool vcpu_has_nv (const struct kvm_vcpu *vcpu) +{ +return false; +} + +#endif /* ASM_KVM_NESTED_H */
arch/s390/include/arm64/ptrace.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __S390_ARM64_PTRACE_H__ +#define __S390_ARM64_PTRACE_H__ + +#include <arm64/sysreg.h> +#include <uapi/arm64/ptrace.h> + +#include <arm64/ptrace-gen.h> + +#endif /* __S390_ARM64_PTRACE_H__ */
arch/s390/include/arm64/sysreg.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __S390_ARM64_SYSREG_H__ +#define __S390_ARM64_SYSREG_H__ + +#include <linux/bits.h> +#include <linux/stringify.h> +#include <linux/kasan-tags.h> +#include <linux/kconfig.h> + +#include <arm64/sysreg-gen.h> + +#endif /* __S390_ARM64_SYSREG_H__ */
arch/s390/kvm/arm64/handle_exit.c new file +98 -0
98 lines not on this page · raw message
arch/s390/kvm/arm64/inject_fault.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <arm64/kvm_emulate.h> + +/** +* kvm_inject_undefined - inject an undefined instruction into the guest +* @vcpu: The vCPU in which to inject the exception +* +* It is assumed that this code is called from the VCPU thread and that the +* VCPU therefore is not currently executing guest code. +*/ +void kvm_inject_undefined (struct kvm_vcpu *vcpu) +{ +/* Stub until s390 supports arm64 sysregs TODO sysregs*/ +} + +int kvm_inject_sea (struct kvm_vcpu *vcpu,bool iabt,u64 addr) +{ +/* Stub until s390 supports arm64 sysregs TODO sysregs*/ +return 1 ; +}
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 15/31 KVM: s390: Guard KVM/s390 behind CONFIG_KVM_S390
In reply to Steffen EidenTo allow for a second KVM Module guard KVM/s390 behind CONIG_KVM_S390 instead of CONFIG_KVM and turn CONFIG_KVM on if selected.
--- 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/kernel/early.c | 2 +- arch/s390/kernel/entry.S | 10 +++++----- arch/s390/kernel/perf_event.c | 2 +- arch/s390/kvm/Kconfig | 3 +++ arch/s390/kvm/Makefile | 2 +- arch/s390/kvm/s390/Kconfig | 5 +++-- arch/s390/kvm/s390/Makefile | 2 +- include/linux/kvm_host.h | 2 +- 13 files changed, 21 insertions(+), 17 deletions(-)
arch/s390/Kconfig +1 -1
@@ -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
arch/s390/boot/ipl_parm.c +1 -1
@@ -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)
arch/s390/boot/uv.c +1 -1
@@ -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;
arch/s390/configs/debug_defconfig +1 -1
@@ -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
arch/s390/configs/defconfig +1 -1
@@ -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
arch/s390/kernel/early.c +1 -1
@@ -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
arch/s390/kernel/entry.S +5 -5
@@ -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
arch/s390/kernel/perf_event.c +1 -1
@@ -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;
arch/s390/kvm/Kconfig +3 -0
@@ -16,6 +16,9 @@ menuconfig VIRTUALIZATION if VIRTUALIZATION +config KVM + tristate + source "arch/s390/kvm/s390/Kconfig" endif # VIRTUALIZATION
arch/s390/kvm/Makefile +1 -1
@@ -3,4 +3,4 @@ # # Copyright IBM Corp. 2008 -obj-$(CONFIG_KVM) += s390/ +obj-$(CONFIG_KVM_S390) += s390/
arch/s390/kvm/s390/Kconfig +3 -2
@@ -1,12 +1,13 @@ # SPDX-License-Identifier: GPL-2.0 -config KVM +config KVM_S390 def_tristate y prompt "Kernel-based Virtual Machine (KVM) support (s390)" select HAVE_KVM_CPU_RELAX_INTERCEPT select KVM_ASYNC_PF select KVM_ASYNC_PF_SYNC select KVM_COMMON + select KVM select HAVE_KVM_IRQCHIP select HAVE_KVM_IRQ_ROUTING select HAVE_KVM_INVALID_WAKEUPS
@@ -30,7 +31,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.
arch/s390/kvm/s390/Makefile +1 -1
@@ -11,4 +11,4 @@ kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o kvm-$(CONFIG_VFIO_PCI_ZDEV_KVM) += pci.o -obj-$(CONFIG_KVM) += kvm.o +obj-$(CONFIG_KVM_S390) += kvm.o
include/linux/kvm_host.h +1 -1
@@ -1541,7 +1541,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)
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 21/31 s390: Use arm64 headers
In reply to Steffen EidenIntroduce a flexible system for sharing ARM64 headers with s390 KVM. Selected arm64 headers or snippet of headers will be reachable by s390 code through asm/header.h.
Add copy-arm64h.awk that detects ARM64_S390_COMMON markers and extracts marked section into a generated header consumable by s390. Falls back to full file copy when no markers are found.
Transform copied includes by replacing '#include <asm/...>' with '#include <arm64/...>' and similar for uapi headers to ensure correct path resolution on s390 and allow for a clear separation of s390 asm headers and arm64 asm headers.
Integrate this extraction into the s390/kapi target, conditional on (the not yet existing) CONFIG_KVM_S390_ARM64.
--- arch/s390/tools/Makefile | 10 +++- arch/s390/tools/Makefile.arm64h | 57 ++++++++++++++++++++++ arch/s390/tools/copy-arm64h-full.awk | 47 ++++++++++++++++++ arch/s390/tools/copy-arm64h.awk | 72 ++++++++++++++++++++++++++++ 4 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 arch/s390/tools/Makefile.arm64h create mode 100644 arch/s390/tools/copy-arm64h-full.awk create mode 100644 arch/s390/tools/copy-arm64h.awk
arch/s390/tools/Makefile +9 -1
@@ -3,12 +3,20 @@ # Makefile for s390 specific build tools # +include $(srctree)/arch/s390/tools/Makefile.arm64h + kapi := arch/$(ARCH)/include/generated/asm kapi-hdrs-y := $(kapi)/facility-defs.h $(kapi)/dis-defs.h +targets += $(addprefix ../../../,$(kapi-hdrs-y)) +# Convert ARM64 absolute paths to relative before Kbuild adds $(obj)/ prefix +targets += $(patsubst $(objtree)/%,../../../%,$(ARM64_TARGETS)) + +kapi-hdrs-$(CONFIG_KVM_ARM64) += $(ARM64_TARGETS) + PHONY += kapi -kapi: $(kapi-hdrs-y) +kapi: $(kapi-hdrs-y) $(ARM64_TARGETS) hostprogs += gen_facilities hostprogs += gen_opcode_table
arch/s390/tools/Makefile.arm64h new file +57 -0
57 lines not on this page · raw message
arch/s390/tools/copy-arm64h-full.awk new file +47 -0
47 lines not on this page · raw message
arch/s390/tools/copy-arm64h.awk new file +72 -0
72 lines not on this page · raw message
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 24/31 KVM: s390: arm64: Introduce host definitions
In reply to Steffen EidenAdd all basic definitions the arm on s390 KVM host requires. Including, but not limited to, struct kvm*arch definitions, various functions (to be implemented in the following patches), and various defines required to run arm64 guests.
Enlighten asm/kvm_host.h for the new header variant. The new header is chosen instead of asm/kvm_host_s390.h if KVM_S390_ARM64 is defined.
--- arch/s390/include/asm/kvm.h | 6 + arch/s390/include/asm/kvm_host.h | 9 + arch/s390/include/asm/kvm_host_arm64.h | 224 +++++++++++++++++++++++++ arch/s390/kernel/entry.S | 3 - 4 files changed, 239 insertions(+), 3 deletions(-) create mode 100644 arch/s390/include/asm/kvm.h create mode 100644 arch/s390/include/asm/kvm_host_arm64.h
arch/s390/include/asm/kvm.h new file +6 -0
@@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifdef KVM_S390_ARM64 +#include <uapi/arm64/kvm.h> +#else +#include <uapi/asm/kvm.h> +#endif
arch/s390/include/asm/kvm_host.h +9 -0
@@ -3,7 +3,16 @@#ifndef ASM_KVM_HOST_H #define ASM_KVM_HOST_H +#ifdef KVM_S390_ARM64 +#include <asm/kvm_host_arm64.h> +#else #include <asm/kvm_host_s390.h> +#endif + +static inline bool kvm_arch_pmi_in_guest (struct kvm_vcpu *vcpu) +{ +return false; +}#define PGM_OPERATION 0x01#define PGM_PRIVILEGED_OP 0x02
arch/s390/include/asm/kvm_host_arm64.h new file +224 -0
224 lines not on this page · raw message
arch/s390/kernel/entry.S +0 -3
@@ -253,9 +253,6 @@ 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
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 25/31 s390/hwcaps: Report SAE support as hwcap
In reply to Steffen EidenFrom: Hendrik Brueckner <[email protected]>
Report SAE support as hwcap (and /proc/cpuinfo)
--- arch/s390/include/asm/elf.h | 2 ++ arch/s390/include/asm/sclp.h | 5 ++++- arch/s390/kernel/processor.c | 3 +++ drivers/s390/char/sclp_early.c | 1 + 4 files changed, 10 insertions(+), 1 deletion(-)
arch/s390/include/asm/elf.h +2 -0
@@ -123,6 +123,7 @@ enum {HWCAP_NR_NNPA =20 ,HWCAP_NR_PCI_MIO =21 ,HWCAP_NR_SIE =22 , +HWCAP_NR_SAE =23 , HWCAP_NR_MAX };
@@ -150,6 +151,7 @@ enum {#define HWCAP_NNPA BIT(HWCAP_NR_NNPA)#define HWCAP_PCI_MIO BIT(HWCAP_NR_PCI_MIO)#define HWCAP_SIE BIT(HWCAP_NR_SIE) +#define HWCAP_SAE BIT(HWCAP_NR_SAE)/* * These are used to set parameters in the core dumps.
arch/s390/include/asm/sclp.h +4 -1
@@ -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;
arch/s390/kernel/processor.c +3 -0
@@ -150,6 +150,7 @@ static void show_cpu_summary(struct seq_file *m, void *v) [HWCAP_NR_NNPA] = "nnpa", [HWCAP_NR_PCI_MIO] = "pcimio", [HWCAP_NR_SIE] = "sie", + [HWCAP_NR_SAE] = "sae", };int i, cpu;
@@ -254,6 +255,8 @@ static int __init setup_hwcaps(void)/* virtualization support */ if (sclp.has_sief2) elf_hwcap |=HWCAP_SIE ; +if (sclp.has_aef) + elf_hwcap |=HWCAP_SAE ;return 0 ; }
drivers/s390/char/sclp_early.c +1 -0
@@ -96,6 +96,7 @@ static void __init sclp_early_facilities_detect(void) sclp.has_ib = cpue->ib; sclp.has_cei = cpue->cei; sclp.has_skey = cpue->skey; + sclp.has_aef = cpue->aef;break ; }
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 18/31 KVM: s390: gmap: Move storage key and CMMA code to kvm/s390
In reply to Steffen EidenExtract storage key and CMMA functionality from kvm/gmap to kvm/s390. This enables other KVM implementations to use gmap without implementing storage key or CMMA handling which only makes sense for s390 guests.
No functional changes.
--- arch/s390/kvm/gmap/dat.c | 500 ----------------------------------- arch/s390/kvm/gmap/dat.h | 7 - arch/s390/kvm/gmap/gmap.c | 77 ------ arch/s390/kvm/gmap/gmap.h | 11 - arch/s390/kvm/s390/Makefile | 1 + arch/s390/kvm/s390/dat.c | 506 ++++++++++++++++++++++++++++++++++++ arch/s390/kvm/s390/gmap.c | 84 ++++++ arch/s390/kvm/s390/s390.h | 23 ++ 8 files changed, 614 insertions(+), 595 deletions(-) create mode 100644 arch/s390/kvm/s390/dat.c create mode 100644 arch/s390/kvm/s390/gmap.c
arch/s390/kvm/gmap/dat.c +0 -500
@@ -613,229 +613,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;
@@ -1048,280 +825,3 @@ int dat_set_prefix_notif_bit(union asce asce, gfn_t gfn)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); -}
arch/s390/kvm/gmap/dat.h +0 -7
@@ -532,13 +532,6 @@ int dat_entry_walk(struct kvm_s390_mmu_cache *mc, gfn_t gfn, union asce asce, invoid 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);
arch/s390/kvm/gmap/gmap.c +0 -77
89 lines not on this page · raw message
arch/s390/kvm/gmap/gmap.h +0 -11
@@ -104,7 +104,6 @@ int gmap_insert_rmap(struct kvm_s390_mmu_cache *mc, struct gmap *sg, gfn_t p_gfn gfn_t r_gfn, int level);int gmap_protect_rmap (struct kvm_s390_mmu_cache *mc,struct gmap *sg,gfn_t p_gfn,gfn_t r_gfn,kvm_pfn_t pfn,int level,bool wr); -void _gmap_set_cmma_all (struct gmap *gmap,bool dirty);void _gmap_handle_vsie_unshadow_event (struct gmap *parent,gfn_t gfn);struct gmap *gmap_create_shadow (struct kvm_s390_mmu_cache *mc,struct gmap *gmap,union asce asce,int edat_level);
@@ -198,16 +197,6 @@ static inline bool pte_needs_unshadow(union pte oldpte, union pte newpte, unionreturn !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) {
arch/s390/kvm/s390/Makefile +1 -0
@@ -8,6 +8,7 @@ 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 kvm-$(CONFIG_VFIO_PCI_ZDEV_KVM) += pci.o
arch/s390/kvm/s390/dat.c new file +506 -0
506 lines not on this page · raw message
arch/s390/kvm/s390/gmap.c new file +84 -0
84 lines not on this page · raw message
arch/s390/kvm/s390/s390.h +23 -0
@@ -635,4 +635,27 @@ extern unsigned int diag9c_forwarding_hz;*/ int kvm_s390_vm_stop_migration (struct kvm *kvm); +/* implemented in dat.c */ +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); + +/* implemented in gmap.c */ +int gmap_enable_skeys (struct gmap *gmap); +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
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 31/31 KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild
In reply to Steffen EidenAdd all Kbuild/Makefile configurations to build a second KVM module on s390 implementing the arm64-KVM API. To prevent symbol conflicts with kvm-s390 all internal symbols in kvm-arm64 are mangled if compiled as built-in. The new module ins named kvm-arm64.
As in this case the build does not go through the normal build process the module parameter handling would be messed up. By forcing KBUILD_MODNAME to kvm-arm64 all parameters are at the same location and not at object/basename of the object file the parameter is introduced.
--- arch/s390/configs/defconfig | 1 + arch/s390/include/asm/Kbuild | 3 ++ arch/s390/kvm/Kconfig | 1 + arch/s390/kvm/Makefile | 1 + arch/s390/kvm/arm64/Kconfig | 22 +++++++++ arch/s390/kvm/arm64/Makefile | 91 ++++++++++++++++++++++++++++++++++++ 6 files changed, 119 insertions(+) create mode 100644 arch/s390/kvm/arm64/Kconfig create mode 100644 arch/s390/kvm/arm64/Makefile
arch/s390/configs/defconfig +1 -0
@@ -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
arch/s390/include/asm/Kbuild +3 -0
@@ -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
arch/s390/kvm/Kconfig +1 -0
@@ -20,5 +20,6 @@ config KVM tristate source "arch/s390/kvm/s390/Kconfig" +source "arch/s390/kvm/arm64/Kconfig" endif # VIRTUALIZATION
arch/s390/kvm/Makefile +1 -0
@@ -4,3 +4,4 @@ # Copyright IBM Corp. 2008 obj-$(CONFIG_KVM_S390) += s390/ +obj-$(CONFIG_KVM_ARM64) += arm64/
arch/s390/kvm/arm64/Kconfig new file +22 -0
@@ -0,0 +1,22 @@ +# 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 GUEST_PERF_EVENTS if PERF_EVENTS + select HAVE_KVM_CPU_RELAX_INTERCEPT + select HAVE_KVM_IRQCHIP + select HAVE_KVM_MSI + select HAVE_KVM_VCPU_RUN_PID_CHANGE + select IRQ_BYPASS_MANAGER + select KVM_COMMON + select KVM_MMIO + select KVM_VFIO + select SCHED_INFO + select XARRAY_MULTI + help + Support hosting virtualized arm64 guest machines on s390 host machines. + + If unsure, say N.
arch/s390/kvm/arm64/Makefile new file +91 -0
91 lines not on this page · raw message
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 22/31 KVM: s390: Use arm64 code
In reply to Steffen EidenAdd the infrastructure to extract KVM/arm64 code into s390 at built time similar to the arm64 header sharing. Add copy-arm64c.awk hat detects ARM64_S390_COMMON markers and extracts marked section into an .inc file that can be consumed by arm on s390 host code. If no marker is found make will fail.
To ensure that no code is consumed twice by accident a guard is added during file generation. A s390 C file wanting to consume such an inc file must first define __INCL_GEN_ARM_FILE otherwise the inc file will emit a compile error.
Example:
#define __INCL_GEN_ARM_FILE #include <generated/arm.inc> #undef __INCL_GEN_ARM_FILE
--- arch/s390/kvm/arm64/.gitignore | 2 + arch/s390/kvm/arm64/Makefile.gen | 30 +++++++++++++ arch/s390/kvm/arm64/copy-arm64c.awk | 70 +++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 arch/s390/kvm/arm64/.gitignore create mode 100644 arch/s390/kvm/arm64/Makefile.gen create mode 100644 arch/s390/kvm/arm64/copy-arm64c.awk
arch/s390/kvm/arm64/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +generated/*
arch/s390/kvm/arm64/Makefile.gen new file +30 -0
@@ -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 or unbalanced ARM64_S390_COMMON markers in $<" >&2; rm -f $@; exit 1; } + +$(obj)/generated/%.inc: $(srctree)/arch/arm64/kvm/%.c $(src)/copy-arm64c.awk FORCE + $(call if_changed,extract_inc) + +ARM64_INC_FILES := $(foreach cfile,$(ARM64_CFILES),generated/$(basename $(cfile)).inc) + +targets += $(ARM64_INC_FILES) +clean-files += generated/*.inc + +$(addprefix $(obj)/,$(kvm-arm64-obj)): $(addprefix $(obj)/,$(ARM64_INC_FILES)) + +$(foreach cfile,$(basename $(ARM64_CFILES)),\ + $(eval $(obj)/$(cfile).o: $(obj)/generated/$(cfile).inc))
arch/s390/kvm/arm64/copy-arm64c.awk new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 23/31 s390: Introduce Start Arm Execution instruction
In reply to Steffen EidenThe Start Arm Execution (SAE) instruction is the centerpiece for executing arm64 (KVM) guests on s390. Its purpose is, similar to SIE, to enable accelerated execution of arm64 virtual machines. SAE expects the physical address of a control block as the only argument.
The host is responsible to save & restore
- GPRs 0-13
- access register 0-15
- breaking event register (BEAR)
- vector/floating point registers
between SAE executions to guarantee host consistency.
GPRs and BEAR are save and restores in the asm functions. The other register are handled in within C code. Access registers are handled in a later patch and SVEs will be handled when they are introduced in a future series. Most arm64 registers are handled by a satellite block called save_area. Some registers, frequently used by hypervisors, are placed into the SAE control block itself.
Enlighten asm/kvm_host_types.h for the new header variant. The new header is chosen instead of asm/kvm_host_s390_types.h if KVM_S390_ARM64 is defined.
--- arch/s390/include/asm/asm-prototypes.h | 1 + arch/s390/include/asm/kvm_host_arm64_types.h | 118 +++++++++++++++++++ arch/s390/include/asm/kvm_host_types.h | 4 + arch/s390/include/asm/sae.h | 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, 213 insertions(+) create mode 100644 arch/s390/include/asm/kvm_host_arm64_types.h create mode 100644 arch/s390/include/asm/sae.h
arch/s390/include/asm/asm-prototypes.h +1 -0
@@ -6,6 +6,7 @@#include <asm/bug.h> #include <asm/fpu.h> #include <asm/nospec-branch.h> +#include <asm/sae.h> #include <asm-generic/asm-prototypes.h> #endif /* _ASM_S390_PROTOTYPES_H */
arch/s390/include/asm/kvm_host_arm64_types.h new file +118 -0
118 lines not on this page · raw message
arch/s390/include/asm/kvm_host_types.h +4 -0
@@ -3,6 +3,10 @@#ifndef ASM_KVM_HOST_TYPES_H #define ASM_KVM_HOST_TYPES_H +#ifdef KVM_S390_ARM64 +#include <asm/kvm_host_arm64_types.h> +#else #include <asm/kvm_host_s390_types.h> +#endif /* KVM_S390_ARM64 */ #endif /* ASM_KVM_HOST_TYPES_H */
arch/s390/include/asm/sae.h new file +56 -0
56 lines not on this page · raw message
arch/s390/include/asm/stacktrace.h +5 -0
@@ -59,6 +59,7 @@ static inline bool on_stack(struct stack_info *info, struct stack_frame { union { unsigned long empty[9]; + /* SIE stack frame */ struct { unsigned long sie_control_block; unsigned long sie_savearea;
@@ -68,6 +69,10 @@ struct stack_frame {unsigned long sie_guest_asce;unsigned long sie_irq; }; +/* SAE stack frame */ +struct { +unsigned long sae_bear; + }; };unsigned long gprs[10 ];unsigned long back_chain;
arch/s390/kernel/asm-offsets.c +1 -0
@@ -70,6 +70,7 @@ int main(void)OFFSET (__SF_SIE_CONTROL_PHYS, stack_frame, sie_control_block_phys);OFFSET (__SF_SIE_GUEST_ASCE, stack_frame, sie_guest_asce);OFFSET (__SF_SIE_IRQ, stack_frame, sie_irq); +OFFSET (__SF_SAE_BEAR, stack_frame, sae_bear);DEFINE (STACK_FRAME_OVERHEAD ,sizeof (struct stack_frame ));BLANK ();OFFSET (__SFUSER_BACKCHAIN, stack_frame_user, back_chain);
arch/s390/kernel/entry.S +25 -0
@@ -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.
arch/s390/tools/opcodes.txt +3 -0
@@ -594,6 +594,9 @@ b9a0 clp RRF_U0RR b9a1 tpei RRE_RR b9a2 ptf RRE_R0 b9a4 uvc RRF_URR +b9a5 sae RRE_R0 +b9a6 lasrm RRE_R0 +b9a7 stiasrm RRE_R0 b9aa lptea RRF_RURR2 b9ab essa RRF_U0RR b9ac irbm RRE_RR
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 28/31 KVM: s390: arm64: Implement vm/vcpu create destroy.
In reply to Steffen EidenImplement init and destroy IOCTLS for vcpu and vm. Implement arch vm IOCTL. Use s390 gmap and gmap plumbing.
--- arch/s390/kvm/arm64/arm.c | 195 ++++++++++++++++++++++++++++++++ arch/s390/kvm/arm64/arm.h | 51 +++++++++ arch/s390/kvm/gmap/faultin.c | 5 + arch/s390/kvm/gmap/gmap.c | 4 + arch/s390/kvm/gmap/kvm_mmu.c | 4 + arch/s390/kvm/gmap/trace-gmap.h | 13 +++ 6 files changed, 272 insertions(+)
arch/s390/kvm/arm64/arm.c +195 -0
@@ -8,6 +8,9 @@#include <linux/kvm_types.h> #include <linux/kvm_host.h> +#include <gmap.h> +#include <kvm_mmu.h> +#include "arm.h" #define CREATE_TRACE_POINTS
@@ -19,6 +22,8 @@ static unsigned long system_supported_vcpu_features(void);#include "generated/arm.inc" #undef __INCL_GEN_ARM_FILE +#define KVM_PHYS_SHIFT (40) +int kvm_vm_ioctl_check_extension (struct kvm *kvm,long ext) {int ret;
@@ -53,6 +58,83 @@ static u64 kvm_max_guest_address(void)return ALIGN_DOWN (max_addr +1 ,1 <<30 ) -1 ; } +static int kvm_gmap_init (struct kvm *kvm) +{ +struct crst_table *table; + + kvm->arch.gmap =gmap_new (kvm,gpa_to_gfn (kvm->arch.guest_phys_size)); + +if (!kvm->arch.gmap) +return -ENOMEM ; + +/* arm64 (on s390) do not have pfault */ +clear_bit (GMAP_FLAG_PFAULT_ENABLED , &kvm->arch.gmap->flags); +set_bit (GMAP_FLAG_ALLOW_HPAGE_1M , &kvm->arch.gmap->flags); + + table =dereference_asce (kvm->arch.gmap->asce); +crst_table_init ((void *)table,_CRSTE_HOLE (table->crstes[0 ].h.tt).val); + +return 0 ; +} + +static int kvm_vm_type_ipa_size_shift (unsigned long type) +{ +int phys_shift; + + phys_shift =KVM_VM_TYPE_ARM_IPA_SIZE (type); +if (phys_shift) { +if (phys_shift >get_kvm_ipa_limit () || + phys_shift <ARM64_MIN_PARANGE_BITS ) +return -EINVAL ; + }else { + phys_shift =KVM_PHYS_SHIFT ; +if (phys_shift >get_kvm_ipa_limit ()) { +pr_warn_once ("%s using unsupported default IPA limit\n" , + current->comm); +return -EINVAL ; + } + } + +return phys_shift; +} + +int kvm_arch_init_vm (struct kvm *kvm,unsigned long type) +{ +char debug_name[32 ]; +int ret; + +if (type & ~KVM_VM_TYPE_ARM_IPA_SIZE_MASK ) +return -EINVAL ; + + ret =kvm_vm_type_ipa_size_shift (type); +if (ret <0 ) +return ret; + kvm->arch.guest_phys_size =1UL << ret; + +mutex_init (&kvm->arch.config_lock); +bitmap_zero (kvm->arch.vcpu_features,KVM_VCPU_MAX_FEATURES ); + +snprintf (debug_name,sizeof (debug_name),"kvm-arm64-%u-%u" , + current->pid,get_random_u32 ()); + kvm->arch.dbf =debug_register (debug_name,32 ,1 ,7 *sizeof (long )); +if (!kvm->arch.dbf) +return -ENOMEM ; +debug_register_view (kvm->arch.dbf, &debug_sprintf_view); + + ret =kvm_gmap_init (kvm); +if (ret) + goto out_err; + kvm->arch.mem_limit =kvm_max_guest_address (); + +VM_EVENT (kvm,3 ,"vm created with type %lu" , type); +return 0 ; + +out_err: +debug_unregister (kvm->arch.dbf); + +return ret; +} +vm_fault_t kvm_arch_vcpu_fault (struct kvm_vcpu *vcpu,struct vm_fault *vmf) {return VM_FAULT_SIGBUS ;
@@ -64,6 +146,13 @@ long kvm_arch_dev_ioctl(struct file *filp,return -EINVAL ; } +void kvm_arch_destroy_vm (struct kvm *kvm) +{ +kvm_destroy_vcpus (kvm); +debug_unregister (kvm->arch.dbf); + kvm->arch.gmap =gmap_put (kvm->arch.gmap); +} +u32 get_kvm_ipa_limit (void ) {return fls64 (kvm_max_guest_address () +1 ) -1 ;
@@ -74,10 +163,41 @@ 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" ); +} +int kvm_arch_vcpu_ioctl_get_mpstate (struct kvm_vcpu *vcpu,struct kvm_mp_state *mp_state) {
@@ -103,6 +223,81 @@ static unsigned long system_supported_vcpu_features(void)return features; } +int kvm_vm_ioctl_get_dirty_log (struct kvm *kvm, +struct kvm_dirty_log *log) +{ +return s390_kvm_mmu_get_dirty_log (kvm, log); +} + +bool kvm_age_gfn (struct kvm *kvm,struct kvm_gfn_range *range) +{ + scoped_guard(read_lock, &kvm->mmu_lock) +return gmap_age_gfn (kvm->arch.gmap, range->start, range->end); +} + +void kvm_arch_sync_dirty_log (struct kvm *kvm,struct kvm_memory_slot *memslot) +{ +gfn_t last_gfn = memslot->base_gfn + memslot->npages; + + scoped_guard(read_lock, &kvm->mmu_lock) +gmap_sync_dirty_log (kvm->arch.gmap, memslot->base_gfn, last_gfn); +} + +int kvm_arch_prepare_memory_region (struct kvm *kvm, +const struct kvm_memory_slot *old, +struct kvm_memory_slot *new, +enum kvm_mr_change change) +{ +return s390_kvm_mmu_prepare_memory_region (kvm, old, new, change); +} + +void kvm_arch_commit_memory_region (struct kvm *kvm,struct kvm_memory_slot *old, +const struct kvm_memory_slot *new, +enum kvm_mr_change change) +{ +s390_kvm_mmu_commit_memory_region (kvm, old, new, change); +} + +bool kvm_unmap_gfn_range (struct kvm *kvm,struct kvm_gfn_range *range) +{ +return gmap_unmap_gfn_range (kvm->arch.gmap, range->slot, range->start, range->end); +} + +bool kvm_test_age_gfn (struct kvm *kvm,struct kvm_gfn_range *range) +{ + scoped_guard(read_lock, &kvm->mmu_lock) +return dat_test_age_gfn (kvm->arch.gmap->asce, range->start, range->end); +} + +#ifdef CONFIG_KVM_GENERIC_PRE_FAULT_MEMORY +long kvm_arch_vcpu_pre_fault_memory (struct kvm_vcpu *vcpu, +struct kvm_pre_fault_memory *range) +{ +return -EOPNOTSUPP ; +} +#endif /* ifdef CONFIG_ */ + +int kvm_arch_vm_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) +{ +void __user *argp = (void __user *)arg; + +switch (ioctl) { +case KVM_ARM_PREFERRED_TARGET : { +struct kvm_vcpu_init init = { + .target =KVM_ARM_TARGET_GENERIC_V8 , + }; + +if (copy_to_user (argp, &init,sizeof (init))) +return -EFAULT ; + +return 0 ; + } + +default : +return -EINVAL ; + } +} +bool kvm_arch_irqchip_in_kernel (struct kvm *kvm) {return false;
arch/s390/kvm/arm64/arm.h +51 -0
57 lines not on this page · raw message
arch/s390/kvm/gmap/faultin.c +5 -0
@@ -10,6 +10,11 @@#include "gmap.h" #include "faultin.h" +#ifdef KVM_S390_ARM64 +#include "arm.h" +#else +#include "s390.h" +#endif bool kvm_arch_setup_async_pf (struct kvm_vcpu *vcpu);#define CREATE_TRACE_POINTS
arch/s390/kvm/gmap/gmap.c +4 -0
@@ -21,7 +21,11 @@#include "dat.h" #include "gmap.h" +#ifdef KVM_S390_ARM64 +#include "arm.h" +#else #include "s390.h" +#endif #include "faultin.h" static int gmap_limit_to_type (gfn_t limit)
arch/s390/kvm/gmap/kvm_mmu.c +4 -0
@@ -3,7 +3,11 @@#include <linux/kvm_types.h> #include <linux/kvm_host.h> +#ifdef KVM_S390_ARM64 +#include "arm.h" +#else #include "s390.h" +#endif #include "gmap.h" #include "dat.h" #include "kvm_mmu.h"
arch/s390/kvm/gmap/trace-gmap.h +13 -0
@@ -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),
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 30/31 KVM: s390: arm64: Implement basic page fault handler
In reply to Steffen EidenAdd host functionality to page in guest memory. If the guest does something unexpected or illegal exit to userspace abort guest execution. This behaviour will be changed to guest error injects once all sysregs are accessible for the host.
--- arch/s390/kvm/arm64/handle_exit.c | 2 + arch/s390/kvm/arm64/mmio.c | 15 +++ arch/s390/kvm/arm64/mmu.c | 177 ++++++++++++++++++++++++++++++ arch/s390/kvm/arm64/trace.h | 24 ++++ 4 files changed, 218 insertions(+) create mode 100644 arch/s390/kvm/arm64/mmio.c create mode 100644 arch/s390/kvm/arm64/mmu.c
arch/s390/kvm/arm64/handle_exit.c +2 -0
@@ -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, };/*
arch/s390/kvm/arm64/mmio.c new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/kvm_host.h> +#include <linux/bitfield.h> + +#include <trace/events/kvm.h> + +#include <arm64/kvm_emulate.h> +#include <arm64/sysreg.h> + +#include "trace.h" + +#define __INCL_GEN_ARM_FILE +#include "generated/mmio.inc" +#undef __INCL_GEN_ARM_FILE
arch/s390/kvm/arm64/mmu.c new file +177 -0
177 lines not on this page · raw message
arch/s390/kvm/arm64/trace.h +24 -0
@@ -32,6 +32,30 @@ TRACE_EVENT(kvm_irq_line, __entry->type, __entry->vcpu_idx, __entry->irq_num, __entry->level) ); +TRACE_EVENT (kvm_mmio_nisv, + TP_PROTO(unsigned long vcpu_pc, unsigned long esr, + unsigned long far, unsigned long ipa), +TP_ARGS (vcpu_pc, esr, far, ipa), + +TP_STRUCT__entry ( + __field( unsigned long, vcpu_pc ) + __field( unsigned long, esr ) + __field( unsigned long, far ) + __field( unsigned long, ipa ) + ), + +TP_fast_assign ( + __entry->vcpu_pc = vcpu_pc; + __entry->esr = esr; + __entry->far = far; + __entry->ipa = ipa; + ), + +TP_printk ("ipa %#016lx, esr %#016lx, far %#016lx, pc %#016lx" , + __entry->ipa, __entry->esr, + __entry->far, __entry->vcpu_pc) +); +#endif /* KVM_ARM64_TRACE_KVM_H */ #undef TRACE_INCLUDE_PATH
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 12/31 KVM: arm64: Share arm64 code with s390
In reply to Steffen EidenMark functions that s390 can use to implement arm on s390 as shared functions.
No functional change.
--- arch/arm64/kvm/arm.c | 3 +++ arch/arm64/kvm/guest.c | 6 ++++++ arch/arm64/kvm/handle_exit.c | 6 ++++++ arch/arm64/kvm/mmio.c | 2 ++ arch/arm64/kvm/reset.c | 6 ++++++ 5 files changed, 23 insertions(+)
arch/arm64/kvm/arm.c +3 -0
@@ -1593,6 +1593,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) {
@@ -1641,6 +1642,8 @@ static bool kvm_vcpu_init_changed(struct kvm_vcpu *vcpu, KVM_VCPU_MAX_FEATURES); } +#endif /* ARM64_S390_COMMON */ +static int kvm_setup_vcpu (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm;
arch/arm64/kvm/guest.c +6 -0
@@ -62,6 +62,7 @@ const struct kvm_stats_header kvm_vcpu_stats_header = { sizeof(kvm_vcpu_stats_desc), }; +#ifdef ARM64_S390_COMMON static bool core_reg_offset_is_vreg (u64 off) { return off >= KVM_REG_ARM_CORE_REG(fp_regs.vregs) &&
@@ -306,6 +307,8 @@ static int set_core_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) return err; } +#endif /* ARM64_S390_COMMON */ +#define vq_word (vq) (((vq) - SVE_VQ_MIN) / 64)#define vq_mask (vq) ((u64)1 << ((vq) - SVE_VQ_MIN) % 64)#define vq_present (vqs, vq) (!!((vqs)[vq_word(vq)] & vq_mask(vq)))
@@ -543,6 +546,7 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)return -EINVAL ; } +#ifdef ARM64_S390_COMMON static int copy_core_reg_indices (const struct kvm_vcpu *vcpu,u64 __user *uindices) {
@@ -591,6 +595,8 @@ static unsigned long num_core_regs(const struct kvm_vcpu *vcpu) return copy_core_reg_indices(vcpu, NULL); } +#endif /* ARM64_S390_COMMON */ +static unsigned long num_sve_regs (const struct kvm_vcpu *vcpu) {const unsigned int slices =vcpu_sve_slices (vcpu);
arch/arm64/kvm/handle_exit.c +6 -0
@@ -213,6 +213,7 @@ static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu)return 0 ; } +#ifdef ARM64_S390_COMMON static int kvm_handle_unknown_ec (struct kvm_vcpu *vcpu) {u64 esr =kvm_vcpu_get_esr (vcpu);
@@ -224,6 +225,8 @@ static int kvm_handle_unknown_ec(struct kvm_vcpu *vcpu) return 1; } +#endif /* ARM64_S390_COMMON */ +/* * Guest access to SVE registers should be routed to this handler only * when the system doesn't support SVE.
@@ -404,6 +407,7 @@ static exit_handle_fn arm_exit_handlers[] = { [ESR_ELx_EC_GCS] = kvm_handle_gcs, }; +#ifdef ARM64_S390_COMMON static exit_handle_fn kvm_get_exit_handler (struct kvm_vcpu *vcpu) {u64 esr =kvm_vcpu_get_esr (vcpu);
@@ -439,6 +443,8 @@ static int handle_trap_exceptions(struct kvm_vcpu *vcpu) return handled; } +#endif /* ARM64_S390_COMMON */ +/* * Return > 0 to return to guest, < 0 on error, 0 (and set exit_reason) on * proper exit to userspace.
arch/arm64/kvm/mmio.c +2 -0
@@ -10,6 +10,7 @@#include "trace.h" +#ifdef ARM64_S390_COMMON void kvm_mmio_write_buf (void *buf,unsigned int len,unsigned long data) {void *datap =NULL ;
@@ -258,3 +259,4 @@ int io_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa) run->exit_reason =KVM_EXIT_MMIO ; return 0; } +#endif /* ARM64_S390_COMMON */
arch/arm64/kvm/reset.c +6 -0
@@ -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 )
@@ -169,6 +172,7 @@ 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;
@@ -193,6 +197,8 @@ static void kvm_reset_vcpu_core_regs(struct kvm_vcpu *vcpu) *vcpu_cpsr(vcpu) = pstate; } +#endif /* ARM64_S390_COMMON */ +/** * kvm_reset_vcpu - sets core registers and sys_regs to reset value * @vcpu: The VCPU pointer
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v5 29/31 KVM: s390: arm64: Implement vCPU IOCTLs
In reply to Steffen EidenImplement all required vCPU IOCTLs.
--- arch/s390/kvm/arm64/arm.c | 392 ++++++++++++++++++++++++++++++ arch/s390/kvm/arm64/guest.c | 47 +++- arch/s390/kvm/arm64/handle_exit.c | 31 +++ arch/s390/kvm/arm64/handle_exit.h | 9 + arch/s390/kvm/arm64/reset.c | 77 ++++++ arch/s390/kvm/arm64/reset.h | 11 + arch/s390/kvm/arm64/trace.h | 25 ++ 7 files changed, 590 insertions(+), 2 deletions(-) create mode 100644 arch/s390/kvm/arm64/handle_exit.h create mode 100644 arch/s390/kvm/arm64/reset.c create mode 100644 arch/s390/kvm/arm64/reset.h
arch/s390/kvm/arm64/arm.c +392 -0
@@ -7,11 +7,20 @@#include <linux/kvm.h> #include <linux/kvm_types.h> #include <linux/kvm_host.h> +#include "linux/cleanup.h" +#include <linux/fpu.h> + +#include <asm/access-regs.h> + +#include <arm64/kvm_emulate.h> +#include <arm64/sysreg.h> #include <gmap.h> #include <kvm_mmu.h> #include "arm.h" +#include "handle_exit.h" +#include "reset.h" #define CREATE_TRACE_POINTS #include "trace.h"
@@ -198,6 +207,22 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)VCPU_EVENT (vcpu,3 ,"%s" ,"free cpu" ); } +void kvm_arch_vcpu_load (struct kvm_vcpu *vcpu,int cpu) +{ +save_access_regs (&vcpu->arch.host_acrs[0 ]); + vcpu->cpu = cpu; + +lasrm (&vcpu->arch.save_area); +} + +void kvm_arch_vcpu_put (struct kvm_vcpu *vcpu) +{ +stiasrm (&vcpu->arch.save_area); + + vcpu->cpu =-1 ; +restore_access_regs (&vcpu->arch.host_acrs[0 ]); +} +int kvm_arch_vcpu_ioctl_get_mpstate (struct kvm_vcpu *vcpu,struct kvm_mp_state *mp_state) {
@@ -223,6 +248,373 @@ static unsigned long system_supported_vcpu_features(void)return features; } +bool kvm_arch_vcpu_in_kernel (struct kvm_vcpu *vcpu) +{ +return vcpu_mode_priv (vcpu); +} + +int kvm_arch_vcpu_run_pid_change (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; + +if (!kvm_vcpu_initialized (vcpu)) +return -ENOEXEC ; + +if (!kvm_arm_vcpu_is_finalized (vcpu)) +return -EPERM ; + +if (likely (READ_ONCE (vcpu->pid))) +return 0 ; + + scoped_guard(mutex, &kvm->arch.config_lock) +set_bit (KVM_ARCH_FLAG_HAS_RAN_ONCE , &kvm->arch.flags); + +return 0 ; +} + +/** +* check_vcpu_requests - check and handle pending vCPU requests +* @vcpu: the VCPU pointer +* +* Return: 1 if we should enter the guest +* 0 if we should exit to userspace +* < 0 if we should exit to userspace, where the return value indicates +* an error +*/ +static int check_vcpu_requests (struct kvm_vcpu *vcpu) +{ +if (kvm_request_pending (vcpu)) { +if (kvm_check_request (KVM_REQ_VCPU_RESET , vcpu)) +kvm_reset_vcpu (vcpu); +/* +* Clear IRQ_PENDING requests that were made to guarantee +* that a VCPU sees new virtual interrupts. +*/ +kvm_check_request (KVM_REQ_IRQ_PENDING , vcpu); + } + +return 1 ; +} + +static int kvm_vcpu_initialize (struct kvm_vcpu *vcpu, +const struct kvm_vcpu_init *init) +{ +unsigned long features = init->features[0 ]; +struct kvm *kvm = vcpu->kvm; + + scoped_guard(mutex, &kvm->arch.config_lock) { +if (test_bit (KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED , + &kvm->arch.flags) && +kvm_vcpu_init_changed (vcpu, init)) +return -EINVAL ; + +bitmap_copy (kvm->arch.vcpu_features, &features, +KVM_VCPU_MAX_FEATURES ); + +kvm_reset_vcpu (vcpu); + +set_bit (KVM_ARCH_FLAG_VCPU_FEATURES_CONFIGURED , + &kvm->arch.flags); +vcpu_set_flag (vcpu,VCPU_INITIALIZED ); + } + +return 0 ; +} + +static int kvm_vcpu_set_target (struct kvm_vcpu *vcpu, +const struct kvm_vcpu_init *init) +{ +int ret; + +if (init->target !=KVM_ARM_TARGET_GENERIC_V8 ) +return -EINVAL ; + + ret =kvm_vcpu_init_check_features (vcpu, init); +if (ret) +return ret; + +if (!kvm_vcpu_initialized (vcpu)) +return kvm_vcpu_initialize (vcpu, init); + +if (kvm_vcpu_init_changed (vcpu, init)) +return -EINVAL ; + +kvm_reset_vcpu (vcpu); + +return 0 ; +} + +static int kvm_arch_vcpu_ioctl_vcpu_init (struct kvm_vcpu *vcpu, +struct kvm_vcpu_init *init) +{ +struct kvm_sae_save_area *save_area = &vcpu->arch.save_area; +struct kvm_sae_block *sae_block = &vcpu->arch.sae_block; +int ret; + + sae_block->save_area =virt_to_phys (save_area); + save_area->sdo =virt_to_phys (sae_block); + + ret =kvm_vcpu_set_target (vcpu, init); +if (ret) +return ret; + + scoped_guard(spinlock, &vcpu->arch.mp_state_lock) { +WRITE_ONCE (vcpu->arch.mp_state.mp_state,KVM_MP_STATE_RUNNABLE ); + } + +return 0 ; +} + +int kvm_vm_ioctl_irq_line (struct kvm *kvm,struct kvm_irq_level *irq_level, +bool line_status) +{ +/* stub for now*/ +return -EINVAL ; +} + +static void adjust_pc (struct kvm_vcpu *vcpu) +{ +if (vcpu_get_flag (vcpu,INCREMENT_PC )) { +kvm_skip_instr (vcpu); +vcpu_clear_flag (vcpu,INCREMENT_PC ); + } +} + +static void arm_vcpu_run (struct kvm_vcpu *vcpu) +{ +struct kvm_sae_block *sae_block = &vcpu->arch.sae_block; + +adjust_pc (vcpu); + +local_irq_disable (); +guest_enter_irqoff (); +local_irq_enable (); + + sae_block->icptr =0 ; + +sae64a (sae_block); + +local_irq_disable (); +guest_exit_irqoff (); +local_irq_enable (); +} + +/** kvm_arch_vcpu_ioctl_run() - run arm64 vCPU +* +* Execute arm64 guest instructions using SAE. +* +* Returns: +* 1 enter the guest (should not be observed by userspace) +* 0 exit to userspace +* < 0 exit to userspace, where the return value indicates n error +* +* +*/ +int kvm_arch_vcpu_ioctl_run (struct kvm_vcpu *vcpu) +{ +DECLARE_KERNEL_FPU_ONSTACK32 (fpu_save); +struct kvm_run *kvm_run = vcpu->run; +int ret; + +if (kvm_run->exit_reason ==KVM_EXIT_MMIO ) { + ret =kvm_handle_mmio_return (vcpu); +if (ret <=0 ) +return ret; + } + +vcpu_load (vcpu); + +kernel_fpu_begin (&fpu_save,KERNEL_FPC |KERNEL_VXR ); +load_vx_regs ((vcpu->arch.ctxt.vregs)); + +if (!vcpu->wants_to_run) { + ret = -EINTR ; + goto out; + } + +kvm_sigset_activate (vcpu); + +might_fault (); + + ret =1 ; +do { +if (signal_pending (current)) { + kvm_run->exit_reason =KVM_EXIT_INTR ; + ret = -EINTR ; +continue ; + } + +if (need_resched ()) +schedule (); + +if (ret >0 ) + ret =check_vcpu_requests (vcpu); + + vcpu->arch.sae_block.icptr =0 ; + +arm_vcpu_run (vcpu); + + ret =handle_exit (vcpu); + + }while (ret >0 ); + +kvm_sigset_deactivate (vcpu); +out: +if (unlikely (vcpu_get_flag (vcpu,INCREMENT_PC ))) +adjust_pc (vcpu); + +save_vx_regs (vcpu->arch.ctxt.vregs); +kernel_fpu_end (&fpu_save,KERNEL_FPC |KERNEL_VXR ); +vcpu_put (vcpu); + +return ret; +} + +static int kvm_arm_vcpu_set_attr (struct kvm_vcpu *vcpu, +struct kvm_device_attr *attr) +{ +int ret; + +switch (attr->group) { +default : + ret = -ENXIO ; +break ; + } + +return ret; +} + +static int kvm_arm_vcpu_get_attr (struct kvm_vcpu *vcpu, +struct kvm_device_attr *attr) +{ +int ret; + +switch (attr->group) { +default : + ret = -ENXIO ; +break ; + } + +return ret; +} + +static int kvm_arm_vcpu_has_attr (struct kvm_vcpu *vcpu, +struct kvm_device_attr *attr) +{ +int ret; + +switch (attr->group) { +default : + ret = -ENXIO ; +break ; + } + +return ret; +} + +long kvm_arch_vcpu_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) +{ +struct kvm_vcpu *vcpu = filp->private_data; +void __user *argp = (void __user *)arg; +struct kvm_device_attr attr; +int ret; + +switch (ioctl) { +case KVM_ARM_VCPU_INIT : { +struct kvm_vcpu_init init; + + ret = -EFAULT ; +if (copy_from_user (&init, argp,sizeof (init))) +break ; + + ret =kvm_arch_vcpu_ioctl_vcpu_init (vcpu, &init); +break ; + } +case KVM_SET_ONE_REG : +case KVM_GET_ONE_REG : { +struct kvm_one_reg reg; + + ret = -ENOEXEC ; +if (unlikely (!kvm_vcpu_initialized (vcpu))) +break ; + + ret = -EFAULT ; +if (copy_from_user (®, 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) {
arch/s390/kvm/arm64/guest.c +45 -2
59 lines not on this page · raw message
arch/s390/kvm/arm64/handle_exit.c +31 -0
@@ -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" ,
arch/s390/kvm/arm64/handle_exit.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef KVM_ARM64_HANDLE_EXIT_H +#define KVM_ARM64_HANDLE_EXIT_H + +#include <linux/kvm_host.h> + +int handle_exit (struct kvm_vcpu *vcpu); + +#endif /* KVM_ARM64_HANDLE_EXIT_H */
arch/s390/kvm/arm64/reset.c new file +77 -0
77 lines not on this page · raw message
arch/s390/kvm/arm64/reset.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef KVM_ARM_RESET_H +#define KVM_ARM_RESET_H + +#include <linux/kvm_host.h> + +bool kvm_arm_vcpu_is_finalized (struct kvm_vcpu *vcpu); +void kvm_reset_vcpu (struct kvm_vcpu *vcpu); +int kvm_arm_vcpu_finalize (struct kvm_vcpu *vcpu,int feature); + +#endif /* KVM_ARM_RESET_H */
arch/s390/kvm/arm64/trace.h +25 -0
@@ -7,6 +7,31 @@#undef TRACE_SYSTEM#define TRACE_SYSTEM kvm +TRACE_EVENT (kvm_irq_line, + TP_PROTO(unsigned int type, int vcpu_idx, int irq_num, int level), +TP_ARGS (type, vcpu_idx, irq_num, level), + +TP_STRUCT__entry ( + __field( unsigned int, type ) + __field( int, vcpu_idx ) + __field( int, irq_num ) +__field ( int, level ) + ), + +TP_fast_assign ( + __entry->type = type; + __entry->vcpu_idx = vcpu_idx; + __entry->irq_num = irq_num; + __entry->level = level; + ), + +TP_printk ("Inject %s interrupt (%d), vcpu->idx: %d, num: %d, level: %d" , + (__entry->type ==KVM_ARM_IRQ_TYPE_CPU ) ?"CPU" : + (__entry->type ==KVM_ARM_IRQ_TYPE_PPI ) ?"VGIC PPI" : + (__entry->type ==KVM_ARM_IRQ_TYPE_SPI ) ?"VGIC SPI" :"UNKNOWN" , + __entry->type, __entry->vcpu_idx, __entry->irq_num, __entry->level) +); +#endif /* KVM_ARM64_TRACE_KVM_H */ #undef TRACE_INCLUDE_PATH
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v5 04/31] arm64: Use proper include variant
In reply to Steffen EidenSashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines
Use <> for including the sysreg header as it is not discoverable from the current directory.
Fixes c07d8017bceb ("arm64/sysreg: Enable automatic generation of system register definitions")Signed-off-by Steffen Eiden <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH v5 05/31] arm64: ptrace: Use constants for compat register numbers
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] Build breakage due to undeclared identifier `__compat_lr_ab` in macro expansion. - [Low]…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] Build breakage due to undeclared identifier __compat_lr_ab in macro expansion.
- [Low] Inconsistent enum naming for FIQ registers (_fi instead of _fiq). --
--- Patch [5]: [PATCH v5 05/31] arm64: ptrace: Use constants for compat register numbers --- commit 6ee1891b95815ce41b1528d3c9d07b5939a2f802
Author: Steffen Eiden <[email protected]>
arm64: ptrace: Use constants for compat register numbers
This commit defines an enum for the register numbers used in mapping between AArch32 and AArch64 registers. It updates the compat macros to use these new enum values instead of hardcoded numbers.
Quoted 10 lines
arch/arm64/include/asm/ptrace.h +2
-0@@ -104,26 +104,48 @@#define COMPAT_USER_SZ 296/* Architecturally defined mapping between AArch32 and AArch64 registers */ +enum { + __compat_fp =11 ,
[ ... ]
arch/arm64/include/asm/ptrace.h line 124
Quoted 5 lines
arch/arm64/include/asm/ptrace.h +5
-0+ __compat_r8_fiq =24 , + __compat_r9_fiq =25 , + __compat_r10_fi =26 , + __compat_r11_fi =27 , + __compat_r12_fi = 28,
[Severity: Low]
This isn't a bug, but could the naming be made consistent here? The enum variants for r8 and r9 use the _fiq suffix (e.g., __compat_r8_fiq), while r10, r11, and r12 are truncated to _fi.
Quoted 5 lines
arch/arm64/include/asm/ptrace.h +4
-0+ __compat_sp_fiq =29 , + __compat_lr_fiq = 30, +}; +#define compat_usr (x) regs[(x)]
[ ... ]
arch/arm64/include/asm/ptrace.h line 138
Quoted 4 lines
arch/arm64/include/asm/ptrace.h +2
-2-#define compat_sp_svc regs[19] -#define compat_lr_abt regs[20] +#define compat_sp_svc regs[__compat_sp_svc] +#define compat_lr_abt regs[__compat_lr_ab]
[Severity: Low]
Does this cause a build failure? The enum value is defined as __compat_lr_abt above, but this macro attempts to use the undeclared __compat_lr_ab identifier. Code using this macro, such as enter_exception32() in arch/arm64/kvm/hyp/exception.c, will fail to compile.
Quoted 10 lines
arch/arm64/include/asm/ptrace.h +10
-0+#define compat_sp_abt regs[__compat_sp_abt] +#define compat_lr_und regs[__compat_lr_und] +#define compat_sp_und regs[__compat_sp_und] +#define compat_r8_fiq regs[__compat_r8_fiq] +#define compat_r9_fiq regs[__compat_r9_fiq] +#define compat_r10_fiq regs[__compat_r10_fi] +#define compat_r11_fiq regs[__compat_r11_fi] +#define compat_r12_fiq regs[__compat_r12_fi] +#define compat_sp_fiq regs[__compat_sp_fiq] +#define compat_lr_fiq regs[__compat_lr_fiq]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
[email protected]
AI reviewRe: [PATCH v5 02/31] KVM: Make device name configurable
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] Memory allocated for `kvm_dev.name` is leaked if the subsequent `cache_name` allocation fails.…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Memory allocated for kvm_dev.name is leaked if the subsequent cache_name allocation fails.
- [Medium] Mixing goto-based error handling and __free() scope-based cleanup within the same function. --
--- Patch [2]: [PATCH v5 02/31] KVM: Make device name configurable --- commit bb225c1b3b23a0088c5fdee909b0a0007a39479e
Author: Steffen Eiden <[email protected]>
KVM: Make device name configurable
This commit allows KVM implementations to choose alternative device names. This is especially useful for architectures providing multiple KVM implementations simultaneously.
Quoted 4 lines
virt/kvm/kvm_main.c +0
-0
[ ... ]
Quoted 18 lines
virt/kvm/kvm_main.c +9
-1@@ -6491,23 +6490,39 @@ 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) +{ + char *cache_name __free(kfree) = NULL;int r;int cpu; + kvm_dev.minor = minor;
virt/kvm/kvm_main.c void kvm_unregister_perf_callbacks(void) · line 6515
Quoted 10 lines
virt/kvm/kvm_main.c +7
-0+ kvm_dev.name =kstrdup_const (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 ); + cache_name =kasprintf (GFP_KERNEL ,"%s_vcpu" , dev_name); +if (!cache_name) +return -ENOMEM ;
[Severity: Medium]
Does this direct return leak kvm_dev.name?
The kvm_dev.name pointer is allocated via kstrdup_const() just above. If kasprintf() fails, this path returns -ENOMEM directly instead of jumping to the err_dev_name label to free the previously allocated memory.
virt/kvm/kvm_main.c void kvm_unregister_perf_callbacks(void) · line 6525
Quoted 12 lines
virt/kvm/kvm_main.c +3
-2kvm_vcpu_cache = -kmem_cache_create_usercopy ("kvm_vcpu" , vcpu_size, vcpu_align, +kmem_cache_create_usercopy (cache_name, vcpu_size, vcpu_align,SLAB_ACCOUNT , offsetof(struct kvm_vcpu , arch), offsetofend(struct kvm_vcpu, stats_id) - offsetof(struct kvm_vcpu , arch),NULL ); + r = -ENOMEM ;if (!kvm_vcpu_cache) -return -ENOMEM ; + goto err_dev_name;
[Severity: Medium]
Is it intended to mix scope-based cleanup with goto error labels here?
The kvm_init_with_dev() function declares cache_name using __free(kfree):
char *cache_name __free(kfree) = NULL;
But it also uses traditional goto-based error unwinding throughout the rest of the function, such as the goto err_dev_name seen here. The cleanup subsystem guidelines require that functions either convert all resources to scope-based cleanup or use goto labels exclusively. Mixing them in the same function can lead to confusing ownership semantics.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH v5 07/31] KVM: arm64: Access elements of vcpu_gp_regs individually
In reply to Steffen EidenSashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines
While for arm64 the members of
vcpu_gp_regsare allocated continuous this is not necessarily true for other architectures implementing ARM.Let
vcpu_gp_regs()no longer return the address of theuser_pt_regsin the vcpu context but the address of the gp-register array field in theuser_pt_regstruct. Note, this change semantically excludes pc from the GPRs.
Quoted 5 lines
No functional change.
Co-developed-by Nina Schoetterl-Glausch <[email protected]>Signed-off-by Nina Schoetterl-Glausch <[email protected]>Signed-off-by Steffen Eiden <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
[email protected]
AI reviewRe: [PATCH v5 01/31] vfio: Use file-based reference counting for KVM
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Critical] Architectural Use-After-Free and Type Confusion due to dangling `kvm->file` and…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] Architectural Use-After-Free and Type Confusion due to dangling kvm->file and get_file_active API misuse.
- [High] The KVM file reference is permanently leaked in vfio_ap_mdev_set_kvm() when KVM crypto is unavailable.
- [Low] Unused parameter 'file' added to kvm_ioctl_create_device.
--
--- Patch [1]: [PATCH v5 01/31] vfio: Use file-based reference counting for KVM --- commit 0d6533aa3c5f21c080ec0d95c626b95fd5fb711d
Author: Steffen Eiden <[email protected]>
vfio: Use file-based reference counting for KVM
Replace manual module reference counting with file-based reference counting for KVM integration. Previously, VFIO used symbol_get() to obtain function pointers for kvm_get_kvm_safe() and kvm_put_kvm(), then manually tracked module references through these symbols. This approach required storing the put_kvm function pointer in each device and carefully managing symbol references.
Pass struct file pointers instead of struct kvm pointers throughout the VFIO-KVM interface. This leverages the kernel's existing file reference counting mechanism via get_file_active() and fput(), eliminating the need for manual module reference tracking. The file->private_data field provides access to the underlying struct kvm when needed.
This simplifies the code and removes all remaining externally exported symbols for KVM, paving the path for a second concurrent KVM module.
Quoted 4 lines
drivers/s390/crypto/vfio_ap_ops.c +0
-0
[ ... ]
Quoted 11 lines
drivers/s390/crypto/vfio_ap_ops.c +4
-2@@ -1815,13 +1816,26 @@ static const struct attribute_group *vfio_ap_mdev_attr_groups[] = {* @matrix_mdev: a mediated matrix device * @kvm: reference to KVM instance * -* Return: 0 if no other mediated matrix device has a reference to @kvm; -* otherwise, returns an -EPERM. +* Returns: 0 if the reference to kvm is successfully retrieved from @kvm_file +* and set into @matrix_mdev; otherwise, returns: +* -ENOENT if a reference to kvm could not be retrieved from @kvm_file +* -EPERM if another mediated matrix device already has a reference to the same kvm instance *
drivers/s390/crypto/vfio_ap_ops.c static const struct attribute_group *vfio_ap_mdev_attr_groups[] = { · line 1832
Quoted 10 lines
drivers/s390/crypto/vfio_ap_ops.c +5
-1*/ static int vfio_ap_mdev_set_kvm (struct ap_matrix_mdev *matrix_mdev, -struct kvm *kvm) +struct file *kvm_file) { + struct file *kvm_file_ref __free(fput) = NULL;struct ap_matrix_mdev *m; +struct kvm *kvm; + + kvm_file_ref =get_file_active (&kvm_file);
[Severity: Critical]
Because kvm_file is passed by value, &kvm_file is a stack address. Doesn't this bypass the RCU validation in get_file_active()? Since it checks the address on the stack, the RCU validation will always succeed even if the underlying struct file was reallocated.
Quoted 9 lines
drivers/s390/crypto/vfio_ap_ops.c +6
-0+if (!kvm_file_ref) +return -ENOENT ; + + kvm = kvm_file->private_data; +if (!kvm) +return -ENOENT ;if (kvm->arch.crypto.crycbd) {down_write (&kvm->arch.crypto.pqap_hook_rwsem);
[ ... ]
Quoted 4 lines
drivers/s390/crypto/vfio_ap_ops.c +0
-0@@ -1837,13 +1851,13 @@ static int vfio_ap_mdev_set_kvm(struct ap_matrix_mdev *matrix_mdev, } }
drivers/s390/crypto/vfio_ap_ops.c static int vfio_ap_mdev_set_kvm(struct ap_matrix_mdev *matrix_mdev, · line 1862
Quoted 10 lines
drivers/s390/crypto/vfio_ap_ops.c +1
-1-kvm_get_kvm (kvm); matrix_mdev->kvm = kvm;vfio_ap_mdev_update_guest_apcb (matrix_mdev);release_update_locks_for_kvm (kvm); } +no_free_ptr (kvm_file_ref);return 0 ; }
[Severity: High]
Does this unconditionally leak the file reference if kvm->arch.crypto.crycbd is false?
In the false case, matrix_mdev->kvm is not set, but no_free_ptr(kvm_file_ref) is still called, which inhibits the __free(fput) cleanup. Later, when the device is released, vfio_ap_mdev_unset_kvm() will see a NULL matrix_mdev->kvm and do nothing, permanently leaking the struct file reference.
Quoted 4 lines
drivers/vfio/vfio_main.c +0
-0
[ ... ]
Quoted 10 lines
drivers/vfio/vfio_main.c +1
-4@@ -448,35 +448,13 @@ void vfio_unregister_group_dev(struct vfio_device *device)EXPORT_SYMBOL_GPL (vfio_unregister_group_dev);#if IS_ENABLED (CONFIG_KVM ) -void vfio_device_get_kvm_safe (struct vfio_device *device,struct kvm *kvm) +void vfio_device_get_kvm_safe (struct vfio_device *device,struct file *kvm) { -void (*pfn)(struct kvm *kvm); -bool (*fn)(struct kvm *kvm); -bool ret;
drivers/vfio/vfio_main.c void vfio_unregister_group_dev(struct vfio_device *device) · line 456
Quoted 10 lines
drivers/vfio/vfio_main.c +1
-6-lockdep_assert_held (&device->dev_set->lock); -if (!kvm) -return ; - - pfn =symbol_get (kvm_put_kvm); -if (WARN_ON (!pfn)) +if (!get_file_active (&kvm))return ;
[Severity: Critical]
Does this usage of get_file_active() defeat its RCU reallocation safety checks? Similar to the vfio_ap_mdev_set_kvm() case above, kvm is a stack variable here, so get_file_active() is checking a stack address rather than the original pointer location.
If the struct file is reallocated (which can happen because the weak back reference kvm->file can outlive the file descriptor, as noted below), couldn't this increment the f_count of an arbitrarily reallocated file and lead to type confusion?
Quoted 4 lines
virt/kvm/kvm_main.c +0
-0
[ ... ]
virt/kvm/kvm_main.c void kvm_unregister_device_ops(u32 type) · line 4808
Quoted 9 lines
virt/kvm/kvm_main.c +1
-1@@ -4802,7 +4802,7 @@ void kvm_unregister_device_ops(u32 type) kvm_device_ops_table[type] =NULL ; } -static int kvm_ioctl_create_device (struct kvm *kvm, +static int kvm_ioctl_create_device (struct file *file,struct kvm *kvm,struct kvm_create_device *cd) {const struct kvm_device_ops *ops;
[Severity: Low]
Is the new file parameter intended to be used in this function? It looks like the function body still relies on kvm_get_kvm(kvm) and ignores this argument.
[ ... ]
virt/kvm/kvm_main.c static int kvm_dev_ioctl_create_vm(unsigned long type) · line 5526
Quoted 11 lines
virt/kvm/kvm_main.c +4
-0@@ -5508,6 +5517,10 @@ static int kvm_dev_ioctl_create_vm(unsigned long type)* cases it will be called by the final fput(file) and will take * care of doing kvm_put_kvm(kvm). */ + +/* Store back-reference for VFIO and other subsystems */ + kvm->file = file; +kvm_uevent_notify_change (KVM_EVENT_CREATE_VM , kvm);fd_install (fd, file);
[Severity: Critical]
Could this lead to a use-after-free or type confusion?
When userspace closes the KVM VM fd, the file is destroyed and freed by RCU. However, the kvm object remains alive if kvm_vfio holds a reference to it (since kvm_vfio_file_add passes dev->kvm->file to VFIO). This would leave kvm->file as a dangling pointer.
If a VFIO operation later calls vfio_device_get_kvm_safe() on that dangling pointer, it might operate on a reallocated struct file.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH v5 03/31] KVM: Allow KVM implementations to switch off MMIO independent of Kconfig
In reply to Steffen EidenSashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
Only defining
KVM_MMIOis not flexible enough for multi-KVM systems where one KVM implements MMIO but others do not. Solve this by additionally testing for the non-existence ofKVM_NO_MMIObefore including MMIO code to KVM.Signed-off-by Steffen Eiden <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH v5 06/31] arm64/sysreg: Convert SPSR_ELx to automatic register generation
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] SPSR_EL2 enum M incorrectly maps mode value 0b1001 to EL3h instead of EL2h. - [Low] SPSR_EL1 and…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] SPSR_EL2 enum M incorrectly maps mode value 0b1001 to EL3h instead of EL2h.
- [Low] SPSR_EL1 and SPSR_EL2 mode enums use non-standard names (EL0, EL1tnv, EL1hnv). --
--- Patch [6]: [PATCH v5 06/31] arm64/sysreg: Convert SPSR_ELx to automatic register generation --- commit ca584536167a8b3942fb084c2775b73ad663d641
Author: Steffen Eiden <[email protected]>
arm64/sysreg: Convert SPSR_ELx to automatic register generation
This commit converts the SPSR_EL1, SPSR_EL2, and SPSR_EL12 registers to automatic register generation. It removes the manual definitions in the sysreg header and adds them to the sysreg generator tool.
Quoted 4 lines
arch/arm64/tools/sysreg +0
-0
[ ... ]
Quoted 5 lines
arch/arm64/tools/sysreg +1
-0@@ -401,6 +401,78 @@ Res0 3:1 Field 0 SO EndSysreg +Sysreg SPSR_EL1 3 0 4 0 0
[ ... ]
arch/arm64/tools/sysreg Res0 3:1 · line 430
Quoted 4 lines
arch/arm64/tools/sysreg +4
-0+Field 5 T +Field 4 M4 +Enum 3:0 M + 0b0000 EL0
[Severity: Low]
Does this code deviate from the standard architectural nomenclature? The architectural manual and existing kernel constants (like PSR_MODE_EL0t) refer to this as EL0t rather than EL0.
arch/arm64/tools/sysreg Res0 3:1 · line 434
Quoted 4 lines
arch/arm64/tools/sysreg +4
-0+ 0b0100 EL1t + 0b0101 EL1h + 0b1000 EL1tnv + 0b1001 EL1hnv
[Severity: Low]
Are these names intended to be EL2t and EL2h instead? When FEAT_NV is implemented, the architectural manual refers to these as EL2t and EL2h. Using EL1tnv and EL1hnv might lead to mismatching macros when compared to existing constants like PSR_MODE_EL2t.
Quoted 4 lines
arch/arm64/tools/sysreg +4
-0+EndEnum +EndSysreg + +Sysreg SPSR_EL2 3 4 4 0 0
[ ... ]
arch/arm64/tools/sysreg Res0 3:1 · line 468
Quoted 8 lines
arch/arm64/tools/sysreg +8
-0+Field 5 T +Field 4 M4 +Enum 3:0 M + 0b0000 EL0 + 0b0100 EL1t + 0b0101 EL1h + 0b1000 EL2t + 0b1001 EL3h
[Severity: Medium]
Could EL3h be a typo for EL2h here? According to the ARM Architecture Reference Manual, 0b1001 corresponds to EL2h. Since SPSR_EL2 cannot hold EL3 exception states, this might generate an incorrect SPSR_EL2_M_EL3h macro while leaving out the definition for EL2h.
Quoted 2 lines
arch/arm64/tools/sysreg +2
-0+EndEnum +EndSysreg
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
[email protected]
AI reviewRe: [PATCH v5 09/31] KVM: arm64: Refactor core-reset into a separate function
In reply to Steffen EidenSashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
Move the reset of the arm core register into a separate function for later reuse.
No functional change.
Signed-off-by Steffen Eiden <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
[email protected]
AI reviewRe: [PATCH v5 10/31] arm64: Prepare sharing arm64 headers with s390
In reply to Steffen EidenSashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
Prepare the sharing of arm64 headers with s390 by moving a few definitions inside headers to reduce the number of shared markers. Clean up some includes to further streamline the sharing of headers.
No functional change.
Signed-off-by Steffen Eiden <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
[email protected]
AI reviewRe: [PATCH v5 08/31] KVM: arm64: Use accessor functions for gprs during reset
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The macro `kvm_vcpu_get_vregs` incorrectly applies the address-of operator (`&`) to an array…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The macro kvm_vcpu_get_vregs incorrectly applies the address-of operator (&) to an array, altering its C semantics.
- [Low] The macro compat_lr_abt expands to an undeclared identifier __compat_lr_ab instead of __compat_lr_abt. --
--- Patch [8]: [PATCH v5 08/31] KVM: arm64: Use accessor functions for gprs during reset --- commit 2e02b3a81c0140da07e44b13884114278108bf3e
Author: Steffen Eiden <[email protected]>
KVM: arm64: Use accessor functions for gprs during reset
Instead of accessing the value directly use assessor function that abstract the actual location of the register values. Enable other KVM implementations to reuse this code.
arch/arm64/include/asm/kvm_host.h static inline u64 *___ctxt_sys_reg(const struct kvm_cpu_context *ctxt, int r) · line 1188
Quoted 11 lines
arch/arm64/include/asm/kvm_host.h +3
-0@@ -1183,6 +1183,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)
[Severity: Medium]
Does this macro incorrectly apply the address-of operator (&) to the vregs array, altering its C semantics?
If a developer uses this macro with sizeof(), for example:memset(kvm_vcpu_get_vregs(vcpu), 0, sizeof(kvm_vcpu_get_vregs(vcpu)))
sizeof() will evaluate to 8 bytes (the size of a pointer) instead of the actual array size (512 bytes). This can lead to a silent partial memory operation.
Could this accessor provide unexpected pointer-to-array semantics rather than decaying to a normal pointer?
arch/arm64/include/asm/kvm_host.h static inline u64 *___ctxt_sys_reg(const struct kvm_cpu_context *ctxt, int r) · line 1192
Quoted 4 lines
arch/arm64/include/asm/kvm_host.h +3
-0+#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 );
I also noticed an issue in arch/arm64/include/asm/ptrace.h introduced in the patch "arm64: ptrace: Use constants for compat register numbers":
arch/arm64/include/asm/ptrace.h:
arch/arm64/include/asm/kvm_host.h static inline u64 *___ctxt_sys_reg(const struct kvm_cpu_context *ctxt, int r) · line 1193
Quoted 1 line
arch/arm64/include/asm/kvm_host.h +0
-0#define compat_lr_abt regs[__compat_lr_ab]
[Severity: Low]
Can the compat_lr_abt macro fail to compile? It expands to an undeclared identifier __compat_lr_ab instead of __compat_lr_abt.
Any code attempting to use the compat_lr_abt macro will fail to compile because __compat_lr_ab is undefined.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
[email protected]
AI reviewRe: [PATCH v5 13/31] KVM: s390: Prepare moving KVM/s390 to arch/s390/kvm/s390
In reply to Steffen EidenSashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines
Lay the groundwork for moving the native KVM/s390 to s390/kvm/s390 to allow for a second KVM module. Move all the
kvm_hostdefinitions to_s390postfixed 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. Cleanup the KVM/s390 makefile.No functional change.
Signed-off-by Steffen Eiden <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
[email protected]
AI reviewRe: [PATCH v5 11/31] arm64: Share arm64 headers with s390
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Sharing architecture-private headers directly with another architecture (s390) violates…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Sharing architecture-private headers directly with another architecture (s390) violates fundamental kernel design principles.
- [High] The #ifdef ARM64_S390_COMMON macro creates an incomplete type build breakage and inverted logic.
--
--- Patch [11]: [PATCH v5 11/31] arm64: Share arm64 headers with s390 --- commit ab90259bd4d46a7a1b7b9c187fcf2bfc3985993e
Author: Steffen Eiden <[email protected]>
arm64: Share arm64 headers with s390
This commit modifies arm64 Makefiles and headers to allow sharing them with the s390 architecture. It introduces an ARM64_S390_COMMON preprocessor macro and adds comments to mark shared regions.
arch/arm64/Makefile CC_FLAGS_NO_FPU := -mgeneral-regs-only · line 46
Quoted 9 lines
arch/arm64/Makefile +1
-0@@ -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
[Severity: High]
Is it appropriate to add a cross-architecture define directly to the arm64 Makefile?
Sharing architecture-private headers directly with another architecture (s390) violates strict architectural separation. Could this shared code be abstracted into generic kernel headers (e.g., under include/linux/, include/kvm/, or include/asm-generic/) instead of exposing arch/arm64/ headers to s390?
[ ... ]
Quoted 4 lines
arch/arm64/include/asm/kvm_host.h +0
-0
[ ... ]
Quoted 10 lines
arch/arm64/include/asm/kvm_host.h +2
-0@@ -832,6 +835,8 @@ extern s64 kvm_nvhe_sym(hyp_physvirt_offset);extern u64 kvm_nvhe_sym (hyp_cpu_logical_map )[NR_CPUS ];#define hyp_cpu_logical_map CHOOSE_NVHE_SYM(hyp_cpu_logical_map) +#ifdef ARM64_S390_COMMON + struct vcpu_reset_state { unsigned long pc; unsigned long r0;
arch/arm64/include/asm/kvm_host.h struct vcpu_reset_state { · line 848
Quoted 5 lines
arch/arm64/include/asm/kvm_host.h +2
-0@@ -839,6 +844,8 @@ struct vcpu_reset_state { bool reset; }; +#endif /* ARM64_S390_COMMON */ +
[Severity: High]
Will this cause an incomplete type compilation error if ARM64_S390_COMMON is not defined?
Looking further down in this file, struct kvm_vcpu_arch instantiates this struct by value outside of any macro guards:
struct kvm_vcpu_arch {
struct kvm_cpu_context ctxt;
...
/* Additional reset state */
struct vcpu_reset_state reset_state;...
};
If an architecture includes asm/kvm_host.h without defining the macro, the compiler skips the definition of struct vcpu_reset_state, leading to a hard build failure when it parses struct kvm_vcpu_arch.
Additionally, does it make sense that ARM64_S390_COMMON guards strictly ARM-specific registers (like pc, r0, and pstate)? If s390 defines this macro to access shared code, it will also pull in these architecture specific definitions that it cannot use.
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
[email protected]
AI reviewRe: [PATCH v5 16/31] KVM: s390: Move PGM code definitions to asm/kvm_host.h
In reply to Steffen EidenSashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
Move the PGM definitions from
kvm_host_s390.h(back) tokvm_host.hso they can be used by a second KVM implementation.No functional change.
Signed-off-by Steffen Eiden <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16
[email protected]
AI reviewRe: [PATCH v5 14/31] KVM: s390: Move s390 kvm code into a subdirectory
In reply to Steffen EidenSashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
Move all the code required to run s390 KVM guests on s390 to a s390 subdirectory. Move gmap related code into a gmap directory to later share gmap code between KVM implementations.
Update S390 VFIO-PCI
MAINTAINERSfilepath.No functional change.
Signed-off-by Steffen Eiden <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
[email protected]
AI reviewRe: [PATCH v5 12/31] KVM: arm64: Share arm64 code with s390
In reply to Steffen EidenSashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
Mark functions that s390 can use to implement arm on s390 as shared functions.
No functional change.
Signed-off-by Steffen Eiden <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
[email protected]
AI reviewRe: [PATCH v5 17/31] KVM: s390: Prepare gmap for a second KVM implementation
In reply to Steffen EidenSashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
Refactor gmap code such that a second s390 (host) KVM implementation can use the gmap code as well. Move mmu code from s390 to gmap so the other KVM implementation can use it as well.
No functional change.
Signed-off-by Steffen Eiden <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
[email protected]
AI reviewRe: [PATCH v5 15/31] KVM: s390: Guard KVM/s390 behind CONFIG_KVM_S390
In reply to Steffen EidenSashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines
To allow for a second KVM Module guard KVM/s390 behind
CONIG_KVM_S390instead ofCONFIG_KVMand turnCONFIG_KVMon if selected.Signed-off-by Steffen Eiden <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
[email protected]
AI reviewRe: [PATCH v5 19/31] KVM: s390: gmap: Move prefix handling to kvm/s390
In reply to Steffen EidenSashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines
Move code handling prefix page tracking from kvm/gmap to kvm/s390. This enables other KVM implementations to use gmap without implementing prefix handling. The prefix tracking is turned on if
KVM_S390_GUEST_HAS_PREFIXis defined.No functional changes.
Signed-off-by Steffen Eiden <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=19
[email protected]
AI reviewRe: [PATCH v5 20/31] KVM: s390: Prepare KVM/s390 for a second KVM module
In reply to Steffen EidenSashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines
The second KVM module will have a different
Kconfigset. When both modules are compiled theKconfigsets 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 forkvm_arch_vcpu_run_pid_changeifCONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGEis enabled and definingKVM_NO_MMIOto disableKVM_MMIO.Signed-off-by Steffen Eiden <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=20
[email protected]
AI reviewRe: [PATCH v5 22/31] KVM: s390: Use arm64 code
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] The generated `#undef __INCL_GEN_ARM_FILE` is placed inside the `#ifndef __INCL_GEN_ARM_FILE`…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] The generated #undef __INCL_GEN_ARM_FILE is placed inside the #ifndef __INCL_GEN_ARM_FILE block, making it dead code.
- [Low] The awk script fails to detect unbalanced/duplicate end markers.
--
--- Patch [22]: [PATCH v5 22/31] KVM: s390: Use arm64 code --- commit ae7db48a91d4b61d3d1ccc6f0b0c6c7d8f856a81
Author: Steffen Eiden <[email protected]>
KVM: s390: Use arm64 code
This commit adds infrastructure to extract marked sections of ARM64 KVM code into generated .inc files for sharing with s390. It introduces an awk script and Makefile rules to detect start and end markers and extract the code at build time.
Quoted 5 lines
arch/s390/kvm/arm64/copy-arm64c.awk new file +0
-0
[ ... ]
arch/s390/kvm/arm64/copy-arm64c.awk line 43
Quoted 7 lines
arch/s390/kvm/arm64/copy-arm64c.awk new file +7
-0+ 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"
[Severity: Low]
This isn't a bug, but is this generated undef reachable?
Since it is emitted inside the #ifndef __INCL_GEN_ARM_FILE block, if the macro is not defined, the compiler will halt at the #error. If the macro is defined, the preprocessor will skip this entire block.
Should this undef be removed, since the commit message states that the consumer must undef it themselves?
Quoted 4 lines
arch/s390/kvm/arm64/copy-arm64c.awk new file +4
-0+ print "#endif /* __INCL_GEN_ARM_FILE */" + print "" + + file_header_done = 1
arch/s390/kvm/arm64/copy-arm64c.awk line 57
Quoted 10 lines
arch/s390/kvm/arm64/copy-arm64c.awk new file +10
-0+} + +$0 ~ start_pattern { + if (copying) { exit 1 } + copying = found_marker = 1 + next +} + +$0 ~ end_pattern { + copying = 0
[Severity: Low]
Does this correctly handle an unbalanced end marker?
While the start_pattern rule catches nested start markers by checking if copying is already set, this end_pattern rule just resets the state.
If a source file has an extra end marker without a preceding start marker, wouldn't this silently process it instead of failing as the Makefile's "unbalanced" error message suggests?
Could we add a check like if (!copying) { exit 1 } here to properly catch extraneous end markers?
Quoted 4 lines
arch/s390/kvm/arm64/copy-arm64c.awk new file +4
-0+ next +} + +copying {
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=22
[email protected]
AI reviewRe: [PATCH v5 21/31] s390: Use arm64 headers
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] ARM64 headers are extracted unconditionally on s390 because they are explicitly listed as a…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] ARM64 headers are extracted unconditionally on s390 because they are explicitly listed as a dependency in the kapi target, and the conditional assignment uses the wrong Kconfig variable.
- [Low] The generated ARM64 headers are written to a path with a duplicated $(objtree) prefix, which causes them to be placed in an incorrect nested directory during out-of-tree builds and silently breaks Kbuild dependency tracking.
- [Low] Using AWK scripts to parse C headers and extract snippets based on s390-specific markers (ARM64_S390_COMMON) inside ARM64 architectural headers is a brittle design pattern.
--
--- Patch [21]: [PATCH v5 21/31] s390: Use arm64 headers --- commit 0aa161b5c002de946626485d254baf5277503c38
Author: Steffen Eiden <[email protected]>
s390: Use arm64 headers
This commit introduces a system for sharing ARM64 headers with s390 KVM. It uses awk scripts to extract marked sections from arm64 headers and integrates this into the s390 build process.
Quoted 4 lines
arch/s390/tools/Makefile +0
-0
[ ... ]
Quoted 9 lines
arch/s390/tools/Makefile +2
-0@@ -3,12 +3,20 @@ # 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
arch/s390/tools/Makefile line 19
Quoted 10 lines
arch/s390/tools/Makefile +6
-1+targets += $(addprefix ../../../,$(kapi-hdrs-y)) +# Convert ARM64 absolute paths to relative before Kbuild adds $(obj)/ prefix +targets += $(patsubst $(objtree)/%,../../../%,$(ARM64_TARGETS)) + +kapi-hdrs-$(CONFIG_KVM_ARM64) += $(ARM64_TARGETS) PHONY += kapi -kapi: $(kapi-hdrs-y) +kapi: $(kapi-hdrs-y) $(ARM64_TARGETS)
[Severity: Medium]
The commit message mentions this should be conditional on CONFIG_KVM_S390_ARM64, but the code uses CONFIG_KVM_ARM64 instead.
Additionally, since $(ARM64_TARGETS) is added directly as an unconditional dependency to the kapi target here, does this mean the headers will be extracted unconditionally on every s390 build regardless of the Kconfig value?
Quoted 5 lines
arch/s390/tools/Makefile.arm64h new file +0
-0
[ ... ]
Quoted 2 lines
arch/s390/tools/Makefile.arm64h new file +2
-0+arm64api := $(objtree)/arch/$(ARCH)/include/generated/arm64 +arm64uapi := $(objtree)/arch/$(ARCH)/include/generated/uapi/arm64
[ ... ]
arch/s390/tools/Makefile.arm64h line 41
Quoted 2 lines
arch/s390/tools/Makefile.arm64h new file +2
-0+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))
[Severity: Low]
Does this result in a duplicated $(objtree) prefix? The arm64api and arm64uapi variables defined earlier already contain $(objtree)/, so prepending it again here could cause Kbuild to generate files in a malformed path like $(objtree)/$(objtree)/... during out-of-tree builds and break dependency tracking.
[ ... ]
arch/s390/tools/Makefile.arm64h line 52
Quoted 2 lines
arch/s390/tools/Makefile.arm64h new file +2
-0+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 > $@
[Severity: Low]
This invokes an ARM64 internal build script directly from the s390 Makefile. Could this tight coupling cause the s390 build to break silently if the ARM64 generator scripts are refactored?
Quoted 5 lines
arch/s390/tools/copy-arm64h.awk new file +0
-0
[ ... ]
arch/s390/tools/copy-arm64h.awk line 12
Quoted 3 lines
arch/s390/tools/copy-arm64h.awk new file +3
-0+BEGIN { + # Constants + start_pattern = "^#ifdef ARM64_S390_COMMON$"
[Severity: Low]
Relying on rigid regex patterns to extract C code blocks and forcing s390-specific markers into ARM64 headers appears brittle. Could minor whitespace changes or formatting updates in the ARM64 headers break this parsing pattern?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=21
[email protected]
AI reviewRe: [PATCH v5 18/31] KVM: s390: gmap: Move storage key and CMMA code to kvm/s390
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] CMMA and storage key function declarations were not fully extracted from generic gmap headers. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] CMMA and storage key function declarations were not fully extracted from generic gmap headers. --
--- Patch [18]: [PATCH v5 18/31] KVM: s390: gmap: Move storage key and CMMA code to kvm/s390 --- commit bde63a0d30be0c82cba34cb31a22562bc02b69e0
Author: Steffen Eiden <[email protected]>
Subject: KVM: s390: gmap: Move storage key and CMMA code to kvm/s390
This commit extracts storage key and CMMA functionality from kvm/gmap to kvm/s390. This enables other KVM implementations to use gmap without implementing s390-specific storage key or CMMA handling.
Quoted 17 lines
arch/s390/kvm/gmap/dat.h +0
-7@@ -532,13 +532,6 @@ int dat_entry_walk(struct kvm_s390_mmu_cache *mc, gfn_t gfn, union asce asce, invoid 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);
[ ... ]
Quoted 4 lines
int
dat_set_prefix_notif_bit(union asce asce, gfn_t gfn); booldat_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);
[Severity: Low]
Does this commit fully extract CMMA functionality from the generic headers?
It appears that while the implementations were moved to kvm/s390, several CMMA function declarations like dat_perform_essa() and dat_reset_cmma() were left behind in arch/s390/kvm/gmap/dat.h.
Since the stated goal is to decouple these subsystems so other KVM implementations can use gmap without s390-specific handling, shouldn't these prototypes also be moved out of the generic headers alongside their newly relocated implementations?
arch/s390/kvm/gmap/gmap.h int gmap_ucas_map(struct gmap *gmap, gfn_t p_gfn, gfn_t c_gfn, unsigned long cou · line 107
Quoted 13 lines
arch/s390/kvm/gmap/gmap.h +0
-1@@ -100,10 +100,9 @@ int gmap_ucas_map(struct gmap *gmap, gfn_t p_gfn, gfn_t c_gfn, unsigned long couvoid 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);
[Severity: Low]
Are there duplicate or leftover declarations here?
While gmap_enable_skeys() was correctly duplicated into arch/s390/kvm/s390/s390.h where it is now implemented, it seems the original prototype was not removed from arch/s390/kvm/gmap/gmap.h.
Leaving it here continues to unnecessarily expose s390-specific storage key operations through the generic gmap headers.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=18
[email protected]
AI reviewRe: [PATCH v5 25/31] s390/hwcaps: Report SAE support as hwcap
In reply to Steffen EidenSashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
From: Hendrik Brueckner <[email protected]>
Report SAE support as hwcap (and
/proc/cpuinfo)Signed-off-by Hendrik Brueckner <[email protected]>Reviewed-by Steffen Eiden <[email protected]>Signed-off-by Steffen Eiden <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=25
[email protected]
AI reviewRe: [PATCH v5 23/31] s390: Introduce Start Arm Execution instruction
In reply to Steffen EidenSashiko has reviewed this patch and found no issues. It looks great!
Quoted 23 lines
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.hfor the new header variant. The new header is chosen instead ofasm/kvm_host_s390_types.hifKVM_S390_ARM64is defined.
Quoted 5 lines
Co-developed-by Andreas Grapentin <[email protected]>Signed-off-by Andreas Grapentin <[email protected]>Co-developed-by Nina Schoetterl-Glausch <[email protected]>Signed-off-by Nina Schoetterl-Glausch <[email protected]>Signed-off-by Steffen Eiden <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=23
[email protected]
AI reviewRe: [PATCH v5 26/31] KVM: s390: Add basic arm64 kvm module
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Integer underflow in `kvm_max_guest_address()` leading to validation bypass. - [Low] Missing…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Integer underflow in kvm_max_guest_address() leading to validation bypass.
- [Low] Missing EXPORT_SYMBOL for kvm_init_with_dev causes linker failure for modules. --
--- Patch [26]: [PATCH v5 26/31] KVM: s390: Add basic arm64 kvm module --- commit 0b59f30d55223ee112ff6a32812059d6b6bf4d71
Author: Steffen Eiden <[email protected]>
KVM: s390: Add basic arm64 kvm module
This commit adds the basic code and boilerplate for the new arm64 on s390 KVM implementation. It includes kernel module initialization, tracing scaffolding, and initial VCPU interaction functions.
Quoted 5 lines
arch/s390/kvm/arm64/arm.c new file +0
-0
[ ... ]
arch/s390/kvm/arm64/arm.c line 54
Quoted 10 lines
arch/s390/kvm/arm64/arm.c new file +10
-0+static u64 kvm_max_guest_address (void ) +{ +u64 max_addr; + +if (sclp.hamax ==U64_MAX ) + max_addr =TASK_SIZE_MAX ; +else + max_addr =min_t (u64,TASK_SIZE_MAX , sclp.hamax); +return ALIGN_DOWN (max_addr +1 ,1 <<30 ) -1 ; +}
[Severity: High]
Does this calculation risk an integer underflow if max_addr + 1 is less than 1GB (1 << 30)?
If the host machine (such as a small LPAR or z/VM guest) has a hardware absolute memory limit (sclp.hamax) below 1GB minus 1, ALIGN_DOWN() will return 0. Subtracting 1 from 0 in unsigned 64-bit arithmetic causes an underflow to U64_MAX.
This underflow propagates to get_kvm_ipa_limit(), turning into an invalid 0xFFFFFFFF limit that bypasses the IPA size check in kvm_vm_type_ipa_size_shift(). This could allow untrusted user space to request arbitrarily large IPA sizes, resulting in massive unbounded page table allocations in gmap_new().
[ ... ]
arch/s390/kvm/arm64/arm.c line 149
Quoted 8 lines
arch/s390/kvm/arm64/arm.c new file +8
-0+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 ); +}
[Severity: Low]
Does kvm_init_with_dev() need an EXPORT_SYMBOL or EXPORT_SYMBOL_FOR_KVM_INTERNAL in virt/kvm/kvm_main.c?
If CONFIG_KVM is built as a loadable module, calling the unexported kvm_init_with_dev() here will cause an undefined reference linker failure during kernel compilation.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=26
[email protected]
AI reviewRe: [PATCH v5 24/31] KVM: s390: arm64: Introduce host definitions
In reply to Steffen EidenSashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
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.hfor the new header variant. The new header is chosen instead ofasm/kvm_host_s390.hifKVM_S390_ARM64is defined.
Quoted 5 lines
Co-developed-by Andreas Grapentin <[email protected]>Signed-off-by Andreas Grapentin <[email protected]>Co-developed-by Nina Schoetterl-Glausch <[email protected]>Signed-off-by Nina Schoetterl-Glausch <[email protected]>Signed-off-by Steffen Eiden <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=24
[email protected]
AI reviewRe: [PATCH v5 30/31] KVM: s390: arm64: Implement basic page fault handler
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The check for `PGM_PROTECTION` in `kvm_s390_cur_gmap_fault_is_write()` does not apply…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The check for PGM_PROTECTION in kvm_s390_cur_gmap_fault_is_write() does not apply PGM_INT_CODE_MASK to hai.pic.
- [Low] The local variable esr is assigned but never used.
--
--- Patch [30]: [PATCH v5 30/31] KVM: s390: arm64: Implement basic page fault handler --- commit 4547e2330db1908b3d5e4eeca0c723949d349711
Author: Steffen Eiden <[email protected]>
KVM: s390: arm64: Implement basic page fault handler
Add host functionality to page in guest memory. If the guest does something unexpected or illegal exit to userspace abort guest execution.
Quoted 8 lines
arch/s390/kvm/arm64/mmu.c new file +2
-0@@ -0,0 +1,177 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/kvm_host.h>
arch/s390/kvm/arm64/mmu.c line 12
Quoted 10 lines
arch/s390/kvm/arm64/mmu.c new file +10
-0+ +#include <arm64/kvm_emulate.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 ; +}
[Severity: High]
Does this code handle concurrent event flags correctly?
If a protection fault occurs with concurrent event flags set (e.g., the PER bit 0x80) in the Program Interruption Code, hai.pic will contain a value like 0x84.
Since this compares hai.pic directly to PGM_PROTECTION (0x04) without applying PGM_INT_CODE_MASK, won't this result in a false evaluation?
If it fails to recognize it as a write fault, user_mem_abort() would call kvm_s390_faultin_gfn() with f.write_attempt = 0, causing the host to map the page read-only instead of making it writable. When the guest resumes, it could immediately trap again with the same protection fault, leading to an infinite page fault loop.
[ ... ]
Quoted 6 lines
arch/s390/kvm/arm64/mmu.c new file +6
-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;
arch/s390/kvm/arm64/mmu.c line 86
Quoted 10 lines
arch/s390/kvm/arm64/mmu.c new file +10
-0+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);
[Severity: Low]
This isn't a bug, but is esr used anywhere else in this function?
It appears this local variable is assigned but never used, which could lead to a -Wunused-but-set-variable compiler warning.
Quoted 2 lines
arch/s390/kvm/arm64/mmu.c new file +2
-0+ fault_ipa =kvm_vcpu_get_fault_ipa (vcpu); + is_iabt =kvm_vcpu_trap_is_iabt (vcpu);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=30
Marc Zyngier
maintainerRe: [PATCH v5 06/31] arm64/sysreg: Convert SPSR_ELx to automatic register generation
In reply to Steffen EidenQuoted 55 lines · Steffen Eiden
Convert SPSR_EL{1, 2, 12} to automatic register generation as per DDIO616 2026-06. No functional change.
Signed-off-by Steffen Eiden <[email protected]>--- arch/arm64/include/asm/sysreg.h | 3 -- arch/arm64/tools/sysreg | 72 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 3 deletions(-)arch/arm64/include/asm/sysreg.h +0
-3@@ -295,7 +295,6 @@#define SYS_APGAKEYLO_EL1 sys_reg(3, 0, 2, 3, 0)#define SYS_APGAKEYHI_EL1 sys_reg(3, 0, 2, 3, 1) -#define SYS_SPSR_EL1 sys_reg(3, 0, 4, 0, 0)#define SYS_ELR_EL1 sys_reg(3, 0, 4, 0, 1)#define SYS_ICC_PMR_EL1 sys_reg(3, 0, 4, 6, 0)@@ -518,7 +517,6 @@#define SYS_VTTBR_EL2 sys_reg(3, 4, 2, 1, 0)#define SYS_HAFGRTR_EL2 sys_reg(3, 4, 3, 1, 6) -#define SYS_SPSR_EL2 sys_reg(3, 4, 4, 0, 0)#define SYS_ELR_EL2 sys_reg(3, 4, 4, 0, 1)#define SYS_SP_EL1 sys_reg(3, 4, 4, 1, 0)#define SYS_SPSR_irq sys_reg(3, 4, 4, 3, 0)@@ -604,7 +602,6 @@#define SYS_BRBCR_EL12 sys_reg(2, 5, 9, 0, 0)#define SYS_TTBR0_EL12 sys_reg(3, 5, 2, 0, 0)#define SYS_TTBR1_EL12 sys_reg(3, 5, 2, 0, 1) -#define SYS_SPSR_EL12 sys_reg(3, 5, 4, 0, 0)#define SYS_ELR_EL12 sys_reg(3, 5, 4, 0, 1)#define SYS_AFSR0_EL12 sys_reg(3, 5, 5, 1, 0)#define SYS_AFSR1_EL12 sys_reg(3, 5, 5, 1, 1)arch/arm64/tools/sysreg +9
-0@@ -401,6 +401,78 @@ Res0 3:1 Field 0 SO EndSysreg +Sysreg SPSR_EL1 3 0 4 0 0 +Res0 63:37 +Field 36 UNIJ +Res0 35:34 +Field 33 PPEND +Res0 32 +Field 31 N +Field 30 Z +Field 29 C
arch/arm64/tools/sysreg Res0 3:1 · line 422
Quoted 10 lines
arch/arm64/tools/sysreg +10
-0+Field 28 V +Field 27 Q +Field 26:25 IT01 +Field 24 DIT +Field 23 SSBS +Field 22 PAN +Field 21 SS +Field 20 IL +Field 19:16 GE +Field 15:10 IT27
I'm sorry, but this is complete nonsense. It looks like you have lifted the AArch32 version of the definition, and not the AArch64 view (which really is what matters here).
arch/arm64/tools/sysreg Res0 3:1 · line 429
Quoted 7 lines
arch/arm64/tools/sysreg +7
-0+Field 9 E +Field 8 A +Field 7 I +Field 6 F +Field 5 T +Field 4 M4 +Enum 3:0 M
I don't think you should split the M field as such. The AArch32 encoding uses bit 4, and should be described.
arch/arm64/tools/sysreg Res0 3:1 · line 434
Quoted 5 lines
arch/arm64/tools/sysreg +5
-0+ 0b0000 EL0 + 0b0100 EL1t + 0b0101 EL1h + 0b1000 EL1tnv + 0b1001 EL1hnv
Please do *not* invent names. These are EL2t/EL2h, and cannot be anything else.
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
[email protected]
AI reviewRe: [PATCH v5 28/31] KVM: s390: arm64: Implement vm/vcpu create destroy.
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] Integer underflow in kvm_max_guest_address() when host memory is less than 1GB bypasses guest physical memory boundaries.
- [High] Incorrect calculation of KVM IPA limit causes VM creation failure for non-power-of-two maximum memory sizes.
Pre-existing issues:
- [High] s390_kvm_mmu_commit_memory_region silently ignores ENOMEM, leaving hardware page tables out of sync with KVM memslots. --
--- Patch [28]: [PATCH v5 28/31] KVM: s390: arm64: Implement vm/vcpu create destroy. --- commit 1d8cc2e3c6c2245e41621c3d2e7a8e11e5053070
Author: Steffen Eiden <[email protected]>
KVM: s390: arm64: Implement vm/vcpu create destroy.
Implement init and destroy IOCTLS for vcpu and vm. Implement arch vm IOCTL. Use s390 gmap and gmap plumbing.
Quoted 4 lines
arch/s390/kvm/arm64/arm.c +0
-0
[ ... ]
arch/s390/kvm/arm64/arm.c static u64 kvm_max_guest_address(void) · line 58
Quoted 2 lines
arch/s390/kvm/arm64/arm.c +0
-0@@ -53,6 +58,83 @@ static u64 kvm_max_guest_address(void)return ALIGN_DOWN (max_addr +1 ,1 <<30 ) -1 ;
[Severity: High]
If the host maximum address (sclp.hamax) is less than 1GB - 1, could max_addr + 1 be strictly less than 1GB?
If so, ALIGN_DOWN(..., 1 << 30) would evaluate to 0, which would underflow to U64_MAX when subtracting 1.
This U64_MAX value is then used in kvm_arch_vcpu_create() to set the hardware execution block's memory size limit (msl):
sae_block->msl = kvm_max_guest_address();
Could this eliminate hardware-enforced limits on guest physical memory, allowing unprivileged guest VMs to bypass their memory bounds?
Quoted 2 lines
arch/s390/kvm/arm64/arm.c +0
-0}
[ ... ]
Quoted 1 line
arch/s390/kvm/arm64/arm.c +0
-0@@ -64,6 +146,13 @@ long kvm_arch_dev_ioctl(struct file *filp,
[ ... ]
Quoted 3 lines
u32
get_kvm_ipa_limit(void)
{
returnfls64(kvm_max_guest_address() + 1)- 1;
[Severity: High]
Does this formula improperly compute the number of bits required to address the memory when the maximum address is not a perfect power of two?
For example, if max_addr + 1 is 3GB, fls64(3GB) - 1 evaluates to 31 bits, but addressing 3GB actually requires 32 bits.
Because ARM64_MIN_PARANGE_BITS is 32, if the calculated limit drops to 31, kvm_vm_type_ipa_size_shift() will return -EINVAL, which could prevent VM creation on hosts with memory limits like 3GB.
Quoted 2 lines
}
[ ... ]
Quoted 1 line
arch/s390/kvm/arm64/arm.c +0
-0@@ -103,6 +223,81 @@ static unsigned long system_supported_vcpu_features(void)
[ ... ]
arch/s390/kvm/arm64/arm.c static unsigned long system_supported_vcpu_features(void) · line 258
Quoted 5 lines
arch/s390/kvm/arm64/arm.c +5
-0+void kvm_arch_commit_memory_region (struct kvm *kvm,struct kvm_memory_slot *old, +const struct kvm_memory_slot *new, +enum kvm_mr_change change) +{ +s390_kvm_mmu_commit_memory_region (kvm, old, new, change);
[Severity: High]
This isn't a bug introduced by this patch, but by wiring up s390_kvm_mmu_commit_memory_region() here, are we exposing a pre-existing error handling flaw?
In s390_kvm_mmu_commit_memory_region(), if kvm_s390_new_mmu_cache() fails:
if (!mc) {
rc = -ENOMEM;
goto out;
}The function returns without performing the dat_delete_slot() or dat_create_slot() updates.
Because kvm_arch_commit_memory_region() is called after active memslots are swapped and cannot return an error, does this leave KVM and the hardware page tables permanently out of sync?
If a memslot deletion fails to reach the hardware page tables, could the guest retain access to host memory that has been formally released, leading to a use-after-free?
Quoted 2 lines
arch/s390/kvm/arm64/arm.c +2
-0+} +
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=28
[email protected]
AI reviewRe: [PATCH v5 27/31] KVM: s390: arm64: Implement required functions
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [Critical] Uninitialized spinlock `mp_state_lock` triggers guest-to-host kernel panic - [Critical]…
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [Critical] Uninitialized spinlock mp_state_lock triggers guest-to-host kernel panic
- [Critical] Infinite VM-Exit Loop on Stubbed Exception Injection
- [High] Incomplete SMP System Shutdown in PSCI SYSTEM_OFF handler
- [Medium] KVM Feature Enumeration Violation (HVC trapping unconditionally enabled)
- [Low] Compilation Errors / Undefined Constants
--
--- Patch [27]: [PATCH v5 27/31] KVM: s390: arm64: Implement required functions --- commit 9ebfb4dc7b6b58f4a7a2e0419672a287a40a3f1e
Author: Steffen Eiden <[email protected]>
KVM: s390: arm64: Implement required functions
This commit implements the mostly trivial functions required by the shared arm64 KVM code for s390. It also adds a very basic smccc handler that can stop a vcpu.
Quoted 4 lines
arch/s390/include/arm64/kvm_emulate.h new file +0
-0
[ ... ]
arch/s390/include/arm64/kvm_emulate.h line 89
Quoted 6 lines
arch/s390/include/arm64/kvm_emulate.h new file +6
-0+static inline bool vcpu_mode_priv (const struct kvm_vcpu *vcpu) +{ +u32 mode = *vcpu_cpsr (vcpu) &PSR_MODE_MASK ; + +return mode != PSR_MODE_EL0t; +}
[Severity: Low]
Does s390 have definitions for PSR_MODE_MASK or PSR_MODE_EL0t? This file includes the host's <asm/ptrace.h> instead of the newly created <arm64/ptrace.h>, which might result in missing macros and build failures.
arch/s390/include/arm64/kvm_emulate.h line 98
Quoted 8 lines
arch/s390/include/arm64/kvm_emulate.h new file +8
-0+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_EL1_SS ; +}
[Severity: Low]
Is SPSR_EL1_SS defined anywhere in this tree? The ARM64 macro is usually named DBG_SPSR_SS, so this looks like it might fail to compile. Additionally, PSR_BTYPE_MASK would also require the <arm64/ptrace.h> header to be included.
[ ... ]
Quoted 4 lines
arch/s390/kvm/arm64/handle_exit.c new file +0
-0
[ ... ]
arch/s390/kvm/arm64/handle_exit.c line 28
Quoted 7 lines
arch/s390/kvm/arm64/handle_exit.c new file +7
-0+static int kvm_smccc_call_handler (struct kvm_vcpu *vcpu) +{ +u32 func_id =vcpu_get_reg (vcpu,0 ); +u64 val =PSCI_RET_NOT_SUPPORTED ; +int ret =1 ; + +if (func_id ==PSCI_0_2_FN_SYSTEM_OFF ) {
[Severity: Medium]
Should the PSCI SYSTEM_OFF feature be unconditionally exposed to the guest? According to KVM subsystem guidelines, any new guest-visible behavior must be off by default and discoverable through standard capability enumeration interfaces to ensure capability negotiation and live migration work properly.
arch/s390/kvm/arm64/handle_exit.c line 29
Quoted 1 line
arch/s390/kvm/arm64/handle_exit.c new file +1
-0+ scoped_guard(spinlock, &vcpu->arch.mp_state_lock) {
[Severity: Critical]
Has the vcpu->arch.mp_state_lock been initialized for s390 vCPUs? If this is a zero-allocated structure and the spinlock lacks the required magic number, could an untrusted guest executing an HVC call trigger a host kernel panic on kernels configured with CONFIG_DEBUG_SPINLOCK?
arch/s390/kvm/arm64/handle_exit.c line 32
Quoted 3 lines
arch/s390/kvm/arm64/handle_exit.c new file +3
-0+WRITE_ONCE (vcpu->arch.mp_state.mp_state,KVM_MP_STATE_STOPPED ); + } +kvm_make_all_cpus_request (vcpu->kvm,KVM_REQ_SLEEP );
[Severity: Low]
Is KVM_REQ_SLEEP defined for s390? This macro is typically specific to ARM64 and RISC-V, which might cause a compilation error here.
[Severity: High]
Will this properly stop all vCPUs in an SMP guest? The code updates the power state to KVM_MP_STATE_STOPPED only for the currently executing vCPU. When the broadcasted KVM_REQ_SLEEP request is processed by the other vCPUs, won't they check their own unmodified states and immediately resume guest execution?
Quoted 2 lines
arch/s390/kvm/arm64/handle_exit.c new file +2
-0+memset (&vcpu->run->system_event,0 , +sizeof (vcpu->run->system_event));
[ ... ]
arch/s390/kvm/arm64/handle_exit.c line 56
Quoted 10 lines
arch/s390/kvm/arm64/handle_exit.c new file +10
-0+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, +};
[Severity: Medium]
Similar to the PSCI SYSTEM_OFF issue above, should HVC64 trapping be unconditionally enabled and mapped to handle_hvc without any capability checks? KVM guidelines require new emulated instructions and exit reasons to be enumerable and default to off.
[ ... ]
Quoted 10 lines
arch/s390/kvm/arm64/inject_fault.c new file +5
-0@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <arm64/kvm_emulate.h> + +/**
arch/s390/kvm/arm64/inject_fault.c line 15
Quoted 10 lines
arch/s390/kvm/arm64/inject_fault.c new file +10
-0+* 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*/ +}
[Severity: Critical]
Since this is an empty stub, will it cause an infinite VM-exit loop? If kvm_handle_unknown_ec() calls kvm_inject_undefined() to handle an unknown instruction, it will immediately return 1 to KVM's run loop. Because this stub fails to advance the guest PC or inject an actual fault, won't the guest re-execute the exact same faulting instruction and immediately trap again, leading to a 100% host CPU lockup?
arch/s390/kvm/arm64/inject_fault.c line 21
Quoted 6 lines
arch/s390/kvm/arm64/inject_fault.c new file +6
-0+ +int kvm_inject_sea (struct kvm_vcpu *vcpu,bool iabt,u64 addr) +{ +/* Stub until s390 supports arm64 sysregs TODO sysregs*/ +return 1 ; +}
[Severity: Critical]
Similar to kvm_inject_undefined(), won't returning 1 from this empty stub immediately resume the guest without altering its execution state, resulting in an inescapable infinite loop if a synchronous external abort occurs?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=27
[email protected]
AI reviewRe: [PATCH v5 31/31] KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] The namespace-mangling logic for built-in compilation (CONFIG_KVM_ARM64=y) uses invalid toolchain…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] The namespace-mangling logic for built-in compilation (CONFIG_KVM_ARM64=y) uses invalid toolchain flags and incorrectly localizes exported symbols, breaking the build.
- [Low] Duplicate exported symbols cause a fatal modpost failure when both KVM modules are compiled as loadable modules (CONFIG_KVM_ARM64=m and CONFIG_KVM_S390=m). --
--- Patch [31]: [PATCH v5 31/31] KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild --- commit c83e4eeb21e3c1207840240024b39a24634ecae4
Author: Steffen Eiden <[email protected]>
KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild
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.
Quoted 5 lines
arch/s390/kvm/arm64/Makefile new file +0
-0
[ ... ]
arch/s390/kvm/arm64/Makefile line 30
Quoted 3 lines
arch/s390/kvm/arm64/Makefile new file +3
-0+ifeq ($(CONFIG_KVM_ARM64),m) + +kvm-arm64-y = $(kvm-arm64-obj)
[Severity: Low]
Does this module build lead to identical global exported symbols?
If both CONFIG_KVM_ARM64=m and CONFIG_KVM_S390=m are selected, both modules include the core virt/kvm files without symbol localization, which causes a fatal modpost failure due to duplicate EXPORT_SYMBOL definitions.
Quoted 2 lines
arch/s390/kvm/arm64/Makefile new file +2
-0+ +else ifeq ($(CONFIG_KVM_ARM64),y)
[ ... ]
arch/s390/kvm/arm64/Makefile line 70
Quoted 2 lines
arch/s390/kvm/arm64/Makefile new file +2
-0+quiet_cmd_nm_filter = NMFLTR $@ + cmd_nm_filter = $(NM) -jU $< | sort -u > $@
[Severity: Low]
Are the -jU flags supported by GNU nm? Using unsupported flags causes a fatal build error here.
arch/s390/kvm/arm64/Makefile line 81
Quoted 11 lines
arch/s390/kvm/arm64/Makefile new file +11
-0+ +$(obj)/kvm_symbol_list: $(obj)/kvm-unnamespaced.o FORCE + $(call if_changed,nm_filter) + +define rule_oc_o_o + $(call cmd_and_savecmd,objcopy) + $(call cmd,gen_objtooldep) + $(call cmd,gen_symversions_o) +endef + +OBJCOPYFLAGS_kvm-namespaced.o := -O default --localize-symbols=$(obj)/kvm_symbol_list
[Severity: Low]
Is -O default a valid objcopy flag?
Additionally, does this incorrectly localize exported symbols? This breaks the build by causing modpost to abort.
Quoted 2 lines
+$(obj)/kvm-namespaced.o: $(obj)/kvm-unnamespaced.o $(obj)/kvm_symbol_list FORCE
arch/s390/kvm/arm64/Makefile new file +1
-0+ $(call if_changed_rule,oc_o_o)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=31
[email protected]
AI reviewRe: [PATCH v5 29/31] KVM: s390: arm64: Implement vCPU IOCTLs
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [Critical] VCPU run loop calls schedule() and might_fault() while preemption is disabled by…
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [Critical] VCPU run loop calls schedule() and might_fault() while preemption is disabled by kernel_fpu_begin().
- [High] Guest- or host-userspace-reachable WARN_ONCE triggers allow log spamming and potential kernel panics.
- [High] Calling local_irq_enable() immediately after guest_enter_irqoff() breaks RCU extended quiescent state invariants.
- [High] The vCPU run loop fails to set IN_GUEST_MODE, leading to lost cross-vCPU IPIs.
- [Medium] KVM_ARM_VCPU_FINALIZE silently accepts all feature requests by returning success (0) unconditionally. --
--- Patch [29]: [PATCH v5 29/31] KVM: s390: arm64: Implement vCPU IOCTLs --- commit 5a1c5a40e465ee169cdb685d1f98ec6e23195cc2
Author: Steffen Eiden <[email protected]>
KVM: s390: arm64: Implement vCPU IOCTLs
This commit implements all required vCPU IOCTLs for KVM s390 arm64. It introduces handlers for KVM_RUN, KVM_SET_ONE_REG, and feature finalization logic.
Quoted 3 lines
arch/s390/kvm/arm64/arm.c +0
-0
[ ... ]
arch/s390/kvm/arm64/arm.c static void arm_vcpu_run(struct kvm_vcpu *vcpu) · line 389
Quoted 6 lines
arch/s390/kvm/arm64/arm.c +0
-0@@ -385,8 +385,11 @@ static void arm_vcpu_run(struct kvm_vcpu *vcpu)adjust_pc (vcpu);local_irq_disable ();guest_enter_irqoff ();local_irq_enable ();
[Severity: High]
Does calling local_irq_enable() immediately after guest_enter_irqoff() break RCU extended quiescent state invariants? guest_enter_irqoff() explicitly transitions the CPU into an RCU Extended Quiescent State (EQS), instructing RCU to ignore this CPU. Enabling hardware interrupts here allows them to fire while the CPU is still marked as being in an EQS. Any interrupt handler that executes would run with RCU not watching, bypassing read-side protections.
Quoted 5 lines
arch/s390/kvm/arm64/arm.c +0
-0sae_block->icptr =0 ;sae64a (sae_block);
[ ... ]
Quoted 15 lines
arch/s390/kvm/arm64/arm.c +0
-0@@ -420,25 +420,38 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)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 ();
arch/s390/kvm/arm64/arm.c int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) · line 443
Quoted 10 lines
arch/s390/kvm/arm64/arm.c +0
-0ret =1 ; do { if (signal_pending(current)) { kvm_run->exit_reason = KVM_EXIT_INTR; ret = -EINTR; continue; } if (need_resched()) schedule();
[Severity: Critical]
Does this code call schedule() and might_fault() while preemption is disabled? kernel_fpu_begin() disables preemption to safely manage hardware FPU state. Inside this atomic section, the code calls might_fault() and schedule(), which will trigger a fatal scheduling while atomic BUG or cause silent FPU state corruption.
arch/s390/kvm/arm64/arm.c int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
Quoted 7 lines
arch/s390/kvm/arm64/arm.c +0
-0if (ret >0 ) ret =check_vcpu_requests (vcpu); vcpu->arch.sae_block.icptr =0 ;arm_vcpu_run (vcpu);
[Severity: High]
Does this loop need to set vcpu->mode = IN_GUEST_MODE before entering the guest execution phase? When another thread or vCPU makes a request (like injecting an IRQ via kvm_make_request()), it checks the target vCPU mode and issues an IPI via kvm_vcpu_kick() if the target is in IN_GUEST_MODE. Because this run loop never sets vcpu->mode, kicks might be silently ignored and the guest might not be interrupted to process requests.
Quoted 4 lines
arch/s390/kvm/arm64/arm.c +0
-0ret =handle_exit (vcpu); }while (ret >0 );
[ ... ]
arch/s390/kvm/arm64/handle_exit.c int handle_exit(struct kvm_vcpu *vcpu) · line 66
Quoted 13 lines
arch/s390/kvm/arm64/handle_exit.c +0
-0@@ -58,15 +58,18 @@ int handle_exit(struct kvm_vcpu *vcpu)u8 icptr = vcpu->arch.sae_block.icptr;int ret =1 ;switch (icptr) {case SAE_ICPTR_SPURIOUS :break ;case SAE_ICPTR_VALIDITY :WARN_ONCE (true,"SAE: validity intercept. vir: 0x%04x" , vcpu->arch.sae_block.vir);
[Severity: High]
Is it safe to use a WARN_ONCE here that can be triggered by userspace? Host userspace could use KVM_SET_ONE_REG to configure an invalid vCPU state, then invoke KVM_RUN. The hardware would immediately exit with a validity intercept (SAE_ICPTR_VALIDITY), hitting this macro. A malicious guest or unprivileged host userspace could trigger this to spam the host logs, or cause a full host kernel panic if panic_on_warn is set.
arch/s390/kvm/arm64/handle_exit.c int handle_exit(struct kvm_vcpu *vcpu)
Quoted 9 lines
arch/s390/kvm/arm64/handle_exit.c +0
-0ret = -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);
[Severity: High]
Could this WARN_ONCE also be triggered by an unprivileged host userspace process controlling the VM, leading to a potential kernel panic?
Quoted 4 lines
arch/s390/kvm/arm64/handle_exit.c +0
-0ret = -EINVAL ; }return ret; }
[ ... ]
arch/s390/kvm/arm64/reset.c void kvm_reset_vcpu(struct kvm_vcpu *vcpu) · line 75
Quoted 9 lines
arch/s390/kvm/arm64/reset.c +0
-0@@ -71,6 +71,6 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)int kvm_arm_vcpu_finalize (struct kvm_vcpu *vcpu,int feature) {return 0 ; }
[Severity: Medium]
Should this function validate the feature ID instead of unconditionally returning 0? Returning success for all requests could mislead userspace into believing unsupported features were successfully enabled, potentially causing subtle runtime misconfigurations or migration failures.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=29
Steffen Eiden
reviewerRe: [PATCH v5 06/31] arm64/sysreg: Convert SPSR_ELx to automatic register generation
In reply to Marc ZyngierQuoted 63 lines · Marc Zyngier
Quoted 61 lines · Steffen Eiden
Convert SPSR_EL{1, 2, 12} to automatic register generation as per DDIO616 2026-06. No functional change.
Signed-off-by Steffen Eiden <[email protected]>--- arch/arm64/include/asm/sysreg.h | 3 -- arch/arm64/tools/sysreg | 72 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 3 deletions(-)arch/arm64/include/asm/sysreg.h +0
-3@@ -295,7 +295,6 @@#define SYS_APGAKEYLO_EL1 sys_reg(3, 0, 2, 3, 0)#define SYS_APGAKEYHI_EL1 sys_reg(3, 0, 2, 3, 1) -#define SYS_SPSR_EL1 sys_reg(3, 0, 4, 0, 0)#define SYS_ELR_EL1 sys_reg(3, 0, 4, 0, 1)#define SYS_ICC_PMR_EL1 sys_reg(3, 0, 4, 6, 0)@@ -518,7 +517,6 @@#define SYS_VTTBR_EL2 sys_reg(3, 4, 2, 1, 0)#define SYS_HAFGRTR_EL2 sys_reg(3, 4, 3, 1, 6) -#define SYS_SPSR_EL2 sys_reg(3, 4, 4, 0, 0)#define SYS_ELR_EL2 sys_reg(3, 4, 4, 0, 1)#define SYS_SP_EL1 sys_reg(3, 4, 4, 1, 0)#define SYS_SPSR_irq sys_reg(3, 4, 4, 3, 0)@@ -604,7 +602,6 @@#define SYS_BRBCR_EL12 sys_reg(2, 5, 9, 0, 0)#define SYS_TTBR0_EL12 sys_reg(3, 5, 2, 0, 0)#define SYS_TTBR1_EL12 sys_reg(3, 5, 2, 0, 1) -#define SYS_SPSR_EL12 sys_reg(3, 5, 4, 0, 0)#define SYS_ELR_EL12 sys_reg(3, 5, 4, 0, 1)#define SYS_AFSR0_EL12 sys_reg(3, 5, 5, 1, 0)#define SYS_AFSR1_EL12 sys_reg(3, 5, 5, 1, 1)arch/arm64/tools/sysreg +15
-0@@ -401,6 +401,78 @@ Res0 3:1 Field 0 SO EndSysreg +Sysreg SPSR_EL1 3 0 4 0 0 +Res0 63:37 +Field 36 UNIJ +Res0 35:34 +Field 33 PPEND +Res0 32 +Field 31 N +Field 30 Z +Field 29 C +Field 28 V +Field 27 Q +Field 26:25 IT01 +Field 24 DIT +Field 23 SSBS +Field 22 PAN
Quoted 8 lines
arch/arm64/tools/sysreg Res0 3:1 · line 422
Quoted 4 lines
arch/arm64/tools/sysreg +4
-0+Field 21 SS +Field 20 IL +Field 19:16 GE +Field 15:10 IT27I'm sorry, but this is complete nonsense. It looks like you have lifted the AArch32 version of the definition, and not the AArch64 view (which really is what matters here).
dang. Yes, I successfully confused myself here. You are absoultely right I accidentlially picked the AArch32 variant. I will fix this with the next round.
Quoted 11 lines
arch/arm64/tools/sysreg Res0 3:1 · line 429
Quoted 8 lines
arch/arm64/tools/sysreg +7
-0+Field 9 E +Field 8 A +Field 7 I +Field 6 F +Field 5 T +Field 4 M4 +Enum 3:0 MI don't think you should split the M field as such. The AArch32 encoding uses bit 4, and should be described.
Ok. I copied the defenitions directly from the arm architecure and it differntiated between the frist 3 bits of M and the 4th. (for 32 and 64 bit). I will merge it.
Quoted 9 lines
arch/arm64/tools/sysreg Res0 3:1 · line 434
Quoted 6 lines
arch/arm64/tools/sysreg +5
-0+ 0b0000 EL0 + 0b0100 EL1t + 0b0101 EL1h + 0b1000 EL1tnv + 0b1001 EL1hnvPlease do *not* invent names. These are EL2t/EL2h, and cannot be anything else.
will change.
thanks.
Steffen
Quoted 5 lines
M.Signature · 1 line
Without deviation from the norm, progress is not possible.
Steffen Eiden
reviewerRe: [PATCH v5 01/31] vfio: Use file-based reference counting for KVM
In reply to Steffen EidenQuoted 19 lines · Steffen Eiden
Replace manual module reference counting with file-based reference counting for KVM integration. Previously, VFIO used
symbol_get()to obtain function pointers forkvm_get_kvm_safe()andkvm_put_kvm(), then manually tracked module references through these symbols. This approach required storing theput_kvmfunction pointer in each device and carefully managing symbol references.Pass struct file pointers instead of struct kvm pointers throughout the VFIO-KVM interface. This leverages the kernel's existing file reference counting mechanism via
get_file_active()andfput(), eliminating the need for manual module reference tracking. Thefile->private_datafield provides access to the underlying struct kvm when needed.This simplifies the code and removes all remaining externally exported symbols for KVM, paving the path for a second concurrent KVM module.
Suggested-by Jason Gunthorpe <[email protected]>Suggested-by Sean Christopherson <[email protected]>Signed-off-by Steffen Eiden <[email protected]>
Quoted 14 lines
--- arch/x86/include/asm/kvm_page_track.h | 8 ++--- arch/x86/kvm/Makefile | 3 -- arch/x86/kvm/mmu/page_track.c | 16 +++++---- drivers/s390/crypto/vfio_ap_ops.c | 24 ++++++++++--- drivers/vfio/group.c | 2 +- drivers/vfio/pci/vfio_pci_zdev.c | 7 +++- drivers/vfio/vfio.h | 10 +++--- drivers/vfio/vfio_main.c | 49 ++++++--------------------- include/linux/kvm_host.h | 2 ++ include/linux/vfio.h | 4 +-- virt/kvm/kvm_main.c | 23 ++++++++++--- virt/kvm/vfio.c | 8 ++--- 12 files changed, 81 insertions(+), 75 deletions(-)
@sean: This is based on your draft in https://lore.kernel.org/all/[email protected]/
do you want another/more attribution? If yes which?
Steffen
Sean Christopherson
maintainerRe: [PATCH v5 01/31] vfio: Use file-based reference counting for KVM
Quoted 35 lines · Steffen Eiden
Quoted 19 lines · Steffen Eiden
Replace manual module reference counting with file-based reference counting for KVM integration. Previously, VFIO used
symbol_get()to obtain function pointers forkvm_get_kvm_safe()andkvm_put_kvm(), then manually tracked module references through these symbols. This approach required storing theput_kvmfunction pointer in each device and carefully managing symbol references.Pass struct file pointers instead of struct kvm pointers throughout the VFIO-KVM interface. This leverages the kernel's existing file reference counting mechanism via
get_file_active()andfput(), eliminating the need for manual module reference tracking. Thefile->private_datafield provides access to the underlying struct kvm when needed.This simplifies the code and removes all remaining externally exported symbols for KVM, paving the path for a second concurrent KVM module.
Suggested-by Jason Gunthorpe <[email protected]>Suggested-by Sean Christopherson <[email protected]>Signed-off-by Steffen Eiden <[email protected]>Quoted 14 lines
--- arch/x86/include/asm/kvm_page_track.h | 8 ++--- arch/x86/kvm/Makefile | 3 -- arch/x86/kvm/mmu/page_track.c | 16 +++++---- drivers/s390/crypto/vfio_ap_ops.c | 24 ++++++++++--- drivers/vfio/group.c | 2 +- drivers/vfio/pci/vfio_pci_zdev.c | 7 +++- drivers/vfio/vfio.h | 10 +++--- drivers/vfio/vfio_main.c | 49 ++++++--------------------- include/linux/kvm_host.h | 2 ++ include/linux/vfio.h | 4 +-- virt/kvm/kvm_main.c | 23 ++++++++++--- virt/kvm/vfio.c | 8 ++--- 12 files changed, 81 insertions(+), 75 deletions(-)
Quoted 2 lines
@sean: This is based on your draft in https://lore.kernel.org/all/[email protected]/
do you want another/more attribution?
No preference. Do whatever feels right to you, you'll know better than me how much of the final code came from me. If you want to give me a Co-developed-by, here's my:
Christian Borntraeger
maintainerRe: [PATCH v5 13/31] KVM: s390: Prepare moving KVM/s390 to arch/s390/kvm/s390
In reply to Steffen EidenAm 31.07.26 um 15:08 schrieb Steffen Eiden:
Quoted 9 lines
Lay the groundwork for moving the native KVM/s390 to s390/kvm/s390 to allow for a second KVM module. Move all the
kvm_hostdefinitions to_s390postfixed 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. Cleanup the KVM/s390 makefile.No functional change.
Would it be possible to split every single semantic change into one a separate patch?
1. kvm-s390.[ch] -> s390.[ch]
2. kvm_host definitions
maybe also
3. gmap-trace change
That would make the patch easier to consume.
We can also handle that in a separate patch series (with the other s390only changes).
Christian Borntraeger
maintainerRe: [PATCH v5 15/31] KVM: s390: Guard KVM/s390 behind CONFIG_KVM_S390
In reply to Steffen Eideninclude/linux/kvm_host.h void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu); · line 1544
Quoted 8 lines
include/linux/kvm_host.h +1
-1@@ -1541,7 +1541,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
CONFIG_KVM_S390 is a tristate, ifndef is wrong.
Christian Borntraeger
maintainerRe: [PATCH v5 24/31] KVM: s390: arm64: Introduce host definitions
In reply to Steffen EidenAm 31.07.26 um 15:08 schrieb Steffen Eiden:
arch/s390/kernel/entry.S SYM_FUNC_START(__sae64a) · line 258
Quoted 9 lines
arch/s390/kernel/entry.S +0
-3@@ -253,9 +253,6 @@ 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
rebase artifact. This was introduced by patch 23.
Christian Borntraeger
maintainerRe: [PATCH v5 14/31] KVM: s390: Move s390 kvm code into a subdirectory
In reply to Steffen EidenQuoted 12 lines
arch/s390/kvm/s390/Makefile renamed from arch/s390/kvm/Makefile +2
-3@@ -1,15 +1,14 @@ # SPDX-License-Identifier: GPL-2.0 -# Makefile for kernel virtual machines on s390 -# -# Copyright IBM Corp. 2008 +KVM := ../../../../virt/kvm include $(srctree)/virt/kvm/Makefile.kvm +include $(srctree)/arch/s390/kvm/gmap/Makefile
arch/s390/kvm/s390/Makefile line 13
Quoted 10 lines
arch/s390/kvm/s390/Makefile renamed from arch/s390/kvm/Makefile +2
-2-ccflags-y := -I$(src) +ccflags-y := -I$(src) -I$(srctree)/arch/s390/kvm/gmap kvm-y += s390.o intercept.o interrupt.o priv.o sigp.o kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o -kvm-y += dat.o gmap.o faultin.o kvm-$(CONFIG_VFIO_PCI_ZDEV_KVM) += pci.o +
unrelated whitespace change.
Quoted 1 line
arch/s390/kvm/s390/Makefile renamed from arch/s390/kvm/Makefile +0
-0obj-$(CONFIG_KVM) += kvm.o
Steffen Eiden
reviewerRe: [PATCH v5 13/31] KVM: s390: Prepare moving KVM/s390 to arch/s390/kvm/s390
In reply to Christian BorntraegerQuoted 13 lines · Christian Borntraeger
Am 31.07.26 um 15:08 schrieb Steffen Eiden:
Quoted 9 lines
Lay the groundwork for moving the native KVM/s390 to s390/kvm/s390 to allow for a second KVM module. Move all the
kvm_hostdefinitions to_s390postfixed 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. Cleanup the KVM/s390 makefile.No functional change.
Would it be possible to split every single semantic change into one a separate patch?
Quoted 7 lines
1. kvm-s390.[ch] -> s390.[ch]
2.kvm_hostdefinitionsmaybe also
3. gmap-trace changeThat would make the patch easier to consume.
Makes sense, I'll split into three.
Steffen