KVM: s390: Introduce arm64 KVM
Steffen Eiden
reviewerv9 cover KVM: s390: Introduce arm64 KVM
Introduce arm-on-s390. Enable KVM-accelerated ARM CPU virtualisation on s390.
The new KVM functionally depends on KVM/vfio: Use file-based reference counting for KVM [5] The series itself should apply w/o those.
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 == 1 <shared code> #endif /* ARM64_S390_COMMON == 1*/ <arm64 local code>
ARM64_S390_COMMON is set to 1 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.
The goal is to share as much functionality as possible.
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
0) as prereq [5]
Prepare KVM to support two KVM modules in parallel. Clean up KVM module symbol exports, making it possible to load two KVM modules side by side.
A) KVM refactoring (patches 1-3):
Make the KVM device name configurable and allow KVM implementations
to disable MMIO regardless of CONFIG_KVM_MMIO. Move some more KVM configs to defines so that concurrent KVMs can select them at need.
B) Arm64 header and code sharing preparation (patches 4-11):
Mark shareable parts with ARM64_S390_COMMON. But first perform minor refactoring to ease integration into s390. All the refactoring/cleanup/fix patches could be picked separately before the actual share-marker commits (13/14) FYI Patch 04 is already picked but not on a Linus-tag yet,
C) a: Small refactoring (12 & 13)
simplify config space and cleat the way for kvm_arm64 remove direct access from kvm_arch struct in shared gmap code.
b: Code sharing infrastructure for s390 (patches 14 & 15):
Add Makefile and scripts to extract and build arm64 headers and code for use by s390.
D) KVM on s390 (patches 16-24):
Introduce the SAE (Start Arm Execution) instruction as the s390 mechanism for running arm64 guests. Build up the new kvm-arm64 module incrementally.
A, B, and C could be picked individually without requiring the others so they could go through different trees if required. D obviously requires A-C.
Steffen
--
Changed from v8[7]:
- Use #if ARM64_S390_COMMON == 1 for sharing markers to benefit from PP complaints in case of an e.g. typo
- Improved device name selection, streamlined the use of the kvm device name
- Fixed inconsistencies in the device naming patch
- dropped vfio/kvm prep series and let this series rely on it. It is still functionally required to get rid of any double exported symbol
- Remove Pre fault memory from migrated Kconfigs
- Add r-b/acks from Janosch, Ilya, Mark, and Catalin
- Fixed multiple minor issues outlined by sashiko (and other AI tools)
s390:
- Improve header/code generation (emit diagnostics information)
- Make header/code generation more robust against bogus sections
- Use filechk for generating headers
- Improve integration of kvm_arm64 into the kbuild system
- Drop the verification of exported symbols for now. They will come once this series is merged.
- Add prefault memory support as native ARM-KVM support is picked.
arm64:
- Move less header code in preparation patch as some of the previously moved functions are shared in later batches anyways (reduces overall churn)
Changes from v7 [6]:
- KVM_DEV_NAME and KVM_DEV_MINOR` are now set at compile time
- fix tracing so it uses KVM_DEV_NAME as tracing base
- convert Kconfig options to defines where applicable remove now unnecessary stubs
- convert KVM_MMIO Kconfig to KVM_NO_MMIO define
- rework KVM file based rc and export symbol handling
- add an arch tagged opt-in helper function to convert the file handle into kvm if needed by e.g. vfio
-split the one patch into 5
1) introduce file_to_kvm_<arch> helper
2) add file backpointer in kvm
3) refactor x86 sev to use the new helper
4) refactor kvm+vfio to use file rc
5) only internally export the kvm_get/put symbols
- share x86's export symbol verification with all architectures that want it
s390:
- arm-ons390 and kvm/s390 now hang on the same config Symbol KVM. there is no extra config for arm-on-s390
- handle_exit.c` is no longer in the shared ARM64 C-files list; the s390 tree
provides its own local handle_exit.c until enough infrastructure on s390
side is there to share the complete architectural exit handling
- rename module from kvm-arm64 to kvm_arm64 to simplify handling all around the code
- rename *_elz fields to *_el2
- use 32bit field and accessor for fpcr and fpsr to satisfy 32bit UAPI
- verify the set of exported symbols like x86
Changes from v6 [4]:
- Fix vfio <-> kvm keepalive
- add Reviewed-bys and ACKs
arm64:
- fix SPSR_ELx description
- use kvm_arch_flag_bits enum instead of multiple defines
- minor requested changes
s390:
- fix various smaller issues
- removed picked s390 refactoring patches (thanks Christian)
Changes from v5 [3]:
- fix multiple rcu and use after free issues in vfio
- multiple smaller mostly cosmetic improvements
arm64:
- fixed regression in compat enum & cleaned up
- fixed SPSR_ELx definitions
- removed reset_core_reg extracting which is now is already done (thanks Fuad)
- renamed and moved register access function to vcpu_<foo> to kvm_emulate.h they are now at the same position and naming scheme like the preexisting ones
- fix resetting reserved field in fpsimd
s390:
- gmap: Guard and not move s390-guest only gmap-code
- split refactoring into more patches to ease review
- fixed minor bugs in header/code shared code generation
- Kconfig reorganization:
- removed KVM_S390, the KVM for s390 guests keeps using by CONFIG_KVM
- KVM_ARM64 now depends on KVM
- KVM is selectable (as it was before this series)
- All (s390) KVM configs are in arch/s390/kvm/Kconfig
Changes from v4 [2]:
- do not remove CONFIG_KVM_MMIO but let KVM/s390 opt out of MMIO
- use kstrdup_const for copying the kvm-device name
- use file based vfio tracking instead of inlining struct kvm refcounting arm64:
- reorganized arm64 code share & refactoring - first refactoring then sharing
- add arm64 refactoring to reduce shared regions
- shared a bit more function (definitions) to reduce no of shared regions (which would be shared in later series anyways)
- add patch to generate SPSR sysreg definitions
- add patch which defines an enum for the arm32 compat registers
s390:
- fix arm64 header generation wiring
- awk scripts are more robust and error out if an end marker is missing
- postfix combined headers with -gen instead of -part
- removed pre-fault-memory implementation
- implemented system supported feature sanitisation
- removed some unnecessary functions
- moved prefix, cmma, and storage key code from gmap to kvm/s390
- properly reset vxregs
Changes from v3
- Complete rework of the code sharing approach
- Introduced ARM64_S390_COMMON marker for selective extraction
- Build-time extraction instead of development-time sharing
- Minimal impact on arm64 codebase
- Improved gmap refactoring and integration
[1] Previous versions:
v1 https://lore.kernel.org/all/[email protected]/
v2 https://lore.kernel.org/all/[email protected]/
v3 https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/
[5] https://lore.kernel.org/all/[email protected]/
[6] https://lore.kernel.org/all/[email protected]/
[7] https://lore.kernel.org/all/[email protected]/
Hendrik Brueckner (1):
s390/hwcaps: Report SAE support as hwcap
Steffen Eiden (23):
KVM: Make device name configurable
KVM: Move architecture capability Kconfigs to header defines
KVM: Replace CONFIG_KVM_MMIO with KVM_NO_MMIO
arm64: Use proper include variant
arm64: ptrace: Use constants for compat register numbers
arm64: sysreg: Convert SPSR_ELx to automatic register generation
KVM: arm64: Access elements of vcpu_gp_regs individually
KVM: arm64: Use accessor functions for core regs
arm64: Prepare sharing arm64 headers with s390
arm64: Share arm64 headers with s390
KVM: arm64: Share arm64 code with s390
s390/Kconfig: remove PCI dependency from HAS_IOMEM
KVM: s390: Use dedicated function for migration mode s390/tools: 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: Integrate arm on s390
MAINTAINERS | 1 + arch/arm64/Makefile | 3 + 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 | 64 +- arch/arm64/include/asm/kvm_host.h | 120 +-- arch/arm64/include/asm/ptrace.h | 64 +- arch/arm64/include/asm/sysreg.h | 22 +- arch/arm64/kvm/Kconfig | 4 - arch/arm64/kvm/arm.c | 3 + arch/arm64/kvm/guest.c | 22 +- arch/arm64/kvm/hyp/exception.c | 4 +- arch/arm64/kvm/hyp/include/hyp/adjust_pc.h | 4 +- arch/arm64/kvm/hyp/include/hyp/switch.h | 4 +- arch/arm64/kvm/mmio.c | 2 + arch/arm64/tools/sysreg | 51 ++ arch/loongarch/include/asm/kvm_host.h | 2 + arch/loongarch/kvm/Kconfig | 3 - arch/mips/include/asm/kvm_host.h | 1 + arch/mips/kvm/Kconfig | 2 - arch/powerpc/include/asm/kvm_host.h | 10 + arch/powerpc/kvm/Kconfig | 5 - arch/riscv/include/asm/kvm_host.h | 2 + arch/riscv/kvm/Kconfig | 3 - arch/s390/Kconfig | 5 +- arch/s390/include/arm64/kvm_emulate.h | 130 ++++ arch/s390/include/arm64/kvm_nested.h | 11 + arch/s390/include/arm64/ptrace.h | 11 + arch/s390/include/arm64/sysreg.h | 13 + arch/s390/include/asm/asm-prototypes.h | 1 + arch/s390/include/asm/elf.h | 2 + arch/s390/include/asm/io.h | 12 +- arch/s390/include/asm/kvm.h | 6 + arch/s390/include/asm/kvm_host.h | 4 + arch/s390/include/asm/kvm_host_arm64.h | 209 +++++ arch/s390/include/asm/kvm_host_arm64_types.h | 124 +++ arch/s390/include/asm/kvm_host_s390.h | 5 + arch/s390/include/asm/kvm_host_types.h | 4 + arch/s390/include/asm/sae.h | 49 ++ arch/s390/include/asm/sclp.h | 5 +- arch/s390/include/asm/stacktrace.h | 5 + arch/s390/include/uapi/Kbuild | 6 + arch/s390/kernel/asm-offsets.c | 1 + arch/s390/kernel/entry.S | 22 + arch/s390/kernel/processor.c | 3 + arch/s390/kvm/Kconfig | 27 +- arch/s390/kvm/Makefile | 1 + arch/s390/kvm/arm64/.gitignore | 2 + arch/s390/kvm/arm64/Makefile | 110 +++ arch/s390/kvm/arm64/Makefile.gen | 28 + arch/s390/kvm/arm64/arm.c | 754 +++++++++++++++++++ arch/s390/kvm/arm64/arm.h | 58 ++ arch/s390/kvm/arm64/copy-arm64c.awk | 82 ++ arch/s390/kvm/arm64/guest.c | 135 ++++ arch/s390/kvm/arm64/handle_exit.c | 161 ++++ 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 | 200 +++++ arch/s390/kvm/arm64/reset.c | 71 ++ arch/s390/kvm/arm64/trace.h | 101 +++ arch/s390/kvm/gmap/faultin.c | 5 + arch/s390/kvm/gmap/gmap.c | 4 + arch/s390/kvm/gmap/kvm_mmu.c | 6 +- arch/s390/kvm/gmap/trace_gmap.h | 17 +- arch/s390/kvm/s390/Makefile | 2 +- arch/s390/tools/Makefile | 6 +- arch/s390/tools/Makefile.arm64h | 55 ++ arch/s390/tools/copy-arm64h-full.awk | 50 ++ arch/s390/tools/copy-arm64h.awk | 83 ++ arch/s390/tools/opcodes.txt | 3 + arch/x86/include/asm/kvm_host.h | 3 + arch/x86/kvm/Kconfig | 4 - drivers/s390/char/sclp_early.c | 1 + include/linux/kvm_host.h | 24 +- include/trace/events/kvm.h | 8 +- virt/kvm/Kconfig | 18 - virt/kvm/Makefile.kvm | 9 +- virt/kvm/async_pf.c | 5 +- virt/kvm/coalesced_mmio.c | 4 + virt/kvm/coalesced_mmio.h | 2 +- virt/kvm/eventfd.c | 3 +- virt/kvm/kvm_main.c | 44 +- 84 files changed, 2968 insertions(+), 199 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 create mode 100644 arch/s390/include/asm/sae.h create mode 100644 arch/s390/include/uapi/Kbuild create mode 100644 arch/s390/kvm/arm64/.gitignore create mode 100644 arch/s390/kvm/arm64/Makefile create mode 100644 arch/s390/kvm/arm64/Makefile.gen create mode 100644 arch/s390/kvm/arm64/arm.c create mode 100644 arch/s390/kvm/arm64/arm.h create mode 100644 arch/s390/kvm/arm64/copy-arm64c.awk create mode 100644 arch/s390/kvm/arm64/guest.c create mode 100644 arch/s390/kvm/arm64/handle_exit.c create mode 100644 arch/s390/kvm/arm64/handle_exit.h create mode 100644 arch/s390/kvm/arm64/inject_fault.c create mode 100644 arch/s390/kvm/arm64/mmio.c create mode 100644 arch/s390/kvm/arm64/mmu.c create mode 100644 arch/s390/kvm/arm64/reset.c create mode 100644 arch/s390/kvm/arm64/trace.h create mode 100644 arch/s390/tools/Makefile.arm64h create mode 100644 arch/s390/tools/copy-arm64h-full.awk create mode 100644 arch/s390/tools/copy-arm64h.awk
base-commit: 16096aadaa3d15c11d37bbea750bad0917e8eadf
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v9 1/24 KVM: Make device name configurable
Allow KVM implementations to choose alternative device names. This is especially useful for architectures providing multiple KVM implementations simultaneously. Architectures providing multiple KVM implementations must compile the KVM common code once per implementation and mangle symbols.
--- arch/s390/kvm/gmap/trace_gmap.h | 4 +++- arch/s390/kvm/s390/Makefile | 2 +- include/linux/kvm_host.h | 4 ++++ include/trace/events/kvm.h | 8 +++++++- virt/kvm/Makefile.kvm | 5 +++++ virt/kvm/async_pf.c | 5 ++++- virt/kvm/eventfd.c | 3 ++- virt/kvm/kvm_main.c | 32 +++++++++++++++++--------------- 8 files changed, 43 insertions(+), 20 deletions(-)
arch/s390/kvm/gmap/trace_gmap.h +3 -1
@@ -4,8 +4,10 @@#include <linux/tracepoint.h> +#undef UNPACK_KVM +#define UNPACK_KVM (name) name#undef TRACE_SYSTEM -#define TRACE_SYSTEM kvm +#define TRACE_SYSTEM UNPACK_KVM(KVM_DEV_NAME)#undef TRACE_INCLUDE_PATH#define TRACE_INCLUDE_PATH ../gmap#undef TRACE_INCLUDE_FILE
arch/s390/kvm/s390/Makefile +1 -1
@@ -4,7 +4,7 @@ KVM := ../../../../virt/kvm include $(srctree)/virt/kvm/Makefile.kvm include $(srctree)/arch/s390/kvm/gmap/Makefile -ccflags-y := -I$(src) -I$(srctree)/arch/s390/kvm/gmap +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
include/linux/kvm_host.h +4 -0
@@ -45,6 +45,10 @@#include <asm/kvm_host.h> #include <linux/kvm_dirty_ring.h> +#define __KVM_DEV_STRING (name, x) __stringify(name ## _ ## x) +#define _KVM_DEV_STRING (name, x) __KVM_DEV_STRING(name, x) +#define KVM_DEV_STRING (x) _KVM_DEV_STRING(KVM_DEV_NAME, x) +#ifndef KVM_MAX_VCPU_IDS #define KVM_MAX_VCPU_IDS KVM_MAX_VCPUS#endif
include/trace/events/kvm.h +7 -1
@@ -4,8 +4,14 @@#include <linux/tracepoint.h> +#undef UNPACK_KVM +#define UNPACK_KVM (name) name#undef TRACE_SYSTEM -#define TRACE_SYSTEM kvm +#define TRACE_SYSTEM UNPACK_KVM(KVM_DEV_NAME) +#undef TRACE_SYSTEM_VAR +#define TRACE_SYSTEM_VAR kvm +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE kvm#define ERSN (x) { KVM_EXIT_##x, "KVM_EXIT_" #x }
virt/kvm/Makefile.kvm +5 -0
@@ -5,6 +5,11 @@ KVM ?= ../../../virt/kvm +KVM_DEV_NAME ?= kvm +KVM_DEV_MINOR ?= KVM_MINOR + +ccflags-y +=-DKVM_DEV_NAME=$(KVM_DEV_NAME) -DKVM_DEV_MINOR=$(KVM_DEV_MINOR) + kvm-y := $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/binary_stats.o kvm-$(CONFIG_KVM_VFIO) += $(KVM)/vfio.o kvm-$(CONFIG_KVM_MMIO) += $(KVM)/coalesced_mmio.o
virt/kvm/async_pf.c +4 -1
@@ -21,7 +21,10 @@ static struct kmem_cache *async_pf_cache;int kvm_async_pf_init (void ) { - async_pf_cache =KMEM_CACHE (kvm_async_pf,0 ); + async_pf_cache =kmem_cache_create (KVM_DEV_STRING (async_pf), +sizeof (struct kvm_async_pf ), + __alignof__(struct kvm_async_pf ), +0 ,NULL );if (!async_pf_cache)return -ENOMEM ;
virt/kvm/eventfd.c +2 -1
@@ -711,7 +711,8 @@ bool kvm_notify_irqfd_resampler(struct kvm *kvm,*/ int kvm_irqfd_init (void ) { - irqfd_cleanup_wq =alloc_workqueue ("kvm-irqfd-cleanup" ,WQ_PERCPU ,0 ); + irqfd_cleanup_wq = alloc_workqueue(__stringify(KVM_DEV_NAME) "-irqfd-cleanup", +WQ_PERCPU ,0 );if (!irqfd_cleanup_wq)return -ENOMEM ;
virt/kvm/kvm_main.c +17 -15
@@ -10,6 +10,8 @@* Yaniv Kamay <[email protected]> */ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <kvm/iodev.h> #include <linux/kvm_host.h>
@@ -1013,7 +1015,7 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, const char *fdname)mutex_lock (&kvm_debugfs_lock); dent =debugfs_lookup (dir_name, kvm_debugfs_dir);if (dent) { -pr_warn_ratelimited ("KVM: debugfs: duplicate directory %s\n" , dir_name); +pr_warn_ratelimited ("debugfs: duplicate directory %s\n" , dir_name);dput (dent);mutex_unlock (&kvm_debugfs_lock);return 0 ;
@@ -4138,9 +4140,9 @@ static struct file_operations kvm_vcpu_fops = {*/ static int create_vcpu_fd (struct kvm_vcpu *vcpu) { -char name[8 +1 +ITOA_MAX_LEN +1 ]; + char name[sizeof(__stringify(KVM_DEV_NAME) "-vcpu:") + ITOA_MAX_LEN + 1]; -snprintf (name,sizeof (name),"kvm-vcpu:%d" , vcpu->vcpu_id); + snprintf(name, sizeof(name), __stringify(KVM_DEV_NAME) "-vcpu:%d", vcpu->vcpu_id);return anon_inode_getfd (name, &kvm_vcpu_fops, vcpu,O_RDWR |O_CLOEXEC ); }
@@ -4353,9 +4355,9 @@ static int kvm_vcpu_ioctl_get_stats_fd(struct kvm_vcpu *vcpu) {int fd;struct file *file; -char name[15 +ITOA_MAX_LEN +1 ]; + char name[sizeof(__stringify(KVM_DEV_NAME) "-vcpu-stats:") + ITOA_MAX_LEN + 1]; -snprintf (name,sizeof (name),"kvm-vcpu-stats:%d" , vcpu->vcpu_id); + snprintf(name, sizeof(name), __stringify(KVM_DEV_NAME) "-vcpu-stats:%d", vcpu->vcpu_id); fd =get_unused_fd_flags (O_CLOEXEC );if (fd <0 )
@@ -5168,7 +5170,7 @@ static int kvm_vm_ioctl_get_stats_fd(struct kvm *kvm)if (fd <0 )return fd; - file =anon_inode_getfile_fmode ("kvm-vm-stats" , + file = anon_inode_getfile_fmode(__stringify(KVM_DEV_NAME) "-vm-stats", &kvm_vm_stats_fops, kvm,O_RDONLY ,FMODE_PREAD );if (IS_ERR (file)) {put_unused_fd (fd);
@@ -5545,7 +5547,7 @@ static int kvm_dev_ioctl_create_vm(unsigned long type) goto put_fd; } - file =anon_inode_getfile ("kvm-vm" , &kvm_vm_fops, kvm,O_RDWR ); + file = anon_inode_getfile(__stringify(KVM_DEV_NAME) "-vm", &kvm_vm_fops, kvm, O_RDWR);if (IS_ERR (file)) { r =PTR_ERR (file); goto put_kvm;
@@ -5613,8 +5615,8 @@ static struct file_operations kvm_chardev_ops = { };static struct miscdevice kvm_dev = { -KVM_MINOR , -"kvm" , +KVM_DEV_MINOR , +__stringify (KVM_DEV_NAME ), &kvm_chardev_ops, };
@@ -5648,7 +5650,7 @@ static int kvm_enable_virtualization_cpu(void)return 0 ;if (kvm_arch_enable_virtualization_cpu ()) { -pr_info ("kvm: enabling virtualization on CPU%d failed\n" , +pr_info ("enabling virtualization on CPU%d failed\n" ,raw_smp_processor_id ());return -EIO ; }
@@ -5695,7 +5697,7 @@ static void kvm_shutdown(void *data)* is used for both shutdown and reboot scenarios, i.e. neither name is * 100% comprehensive. */ -pr_info ("kvm: exiting hardware virtualization\n" ); +pr_info ("exiting hardware virtualization\n" );on_each_cpu (kvm_disable_virtualization_cpu,NULL ,1 ); }
@@ -6106,7 +6108,7 @@ int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,* attached devices. Otherwise, destroy the caller's device only. */ if (!new_bus) { -pr_err ("kvm: failed to shrink bus, removing it completely\n" ); +pr_err ("failed to shrink bus, removing it completely\n" );kvm_io_bus_destroy (bus);return -ENOMEM ; }
@@ -6393,7 +6395,7 @@ static void kvm_init_debug(void)const struct kvm_stats_desc *pdesc;int i; - kvm_debugfs_dir =debugfs_create_dir ("kvm" ,NULL ); + kvm_debugfs_dir =debugfs_create_dir (__stringify (KVM_DEV_NAME ),NULL );for (i =0 ; i < kvm_vm_stats_header.num_desc; ++i) { pdesc = &kvm_vm_stats_desc[i];
@@ -6538,7 +6540,7 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)if (!vcpu_align) vcpu_align = __alignof__(struct kvm_vcpu ); kvm_vcpu_cache = -kmem_cache_create_usercopy ("kvm_vcpu" , vcpu_size, vcpu_align, +kmem_cache_create_usercopy (KVM_DEV_STRING (vcpu), vcpu_size, vcpu_align,SLAB_ACCOUNT , offsetof(struct kvm_vcpu , arch), offsetofend(struct kvm_vcpu, stats_id)
@@ -6591,7 +6593,7 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)*/ r =misc_register (&kvm_dev);if (r) { -pr_err ("kvm: misc device register failed\n" ); +pr_err ("misc device register failed\n" ); goto err_register; }
Signature · 1 line
2.53.0
Re: [PATCH v9 01/24] KVM: Make device name configurable
Quoted 9 lines · Steffen Eiden
Allow KVM implementations to choose alternative device names. This is especially useful for architectures providing multiple KVM implementations simultaneously. Architectures providing multiple KVM implementations must compile the KVM common code once per implementation and mangle symbols.
Suggested-by Sean Christopherson <[email protected]>Signed-off-by Steffen Eiden <[email protected]>---
lgtm. Thanks Sean and Steffen.
Steffen Eiden
reviewerPATCH v9 2/24 KVM: Move architecture capability Kconfigs to header defines
In reply to Steffen EidenHistorically, KVM feature opt-ins and callbacks were configured globally via Kconfig symbols (CONFIG_HAVE_KVM_* and CONFIG_KVM_*).
With s390 hosting multiple independent KVM implementations within the same kernel build (native s390 KVM and arm64 on s390), global Kconfig selections force both implementations to inherit options that only apply to one of them.
Replace these global Kconfig options with architecture-specific opt-in defines in <asm/kvm_host.h> and standardize their naming by dropping the HAVE_ prefix:
- KVM_INVALID_WAKEUPS
- KVM_MSI (formerly HAVE_KVM_MSI)
- KVM_NO_POLL (formerly HAVE_KVM_NO_POLL)
- KVM_READONLY_MEM (formerly HAVE_KVM_READONLY_MEM)
- KVM_VCPU_RUN_PID_CHANGE (formerly HAVE_KVM_VCPU_RUN_PID_CHANGE)
This allows each architecture and guest implementation to configure its supported capabilities independently in its kvm_host header and eliminates unnecessary fallback stubs across different KVM targets.
--- arch/arm64/include/asm/kvm_host.h | 3 +++ arch/arm64/kvm/Kconfig | 3 --- arch/loongarch/include/asm/kvm_host.h | 2 ++ arch/loongarch/kvm/Kconfig | 2 -- arch/mips/include/asm/kvm_host.h | 1 + arch/mips/kvm/Kconfig | 1 - arch/powerpc/include/asm/kvm_host.h | 3 +++ arch/powerpc/kvm/Kconfig | 1 - arch/riscv/include/asm/kvm_host.h | 2 ++ arch/riscv/kvm/Kconfig | 2 -- arch/s390/include/asm/kvm_host_s390.h | 3 +++ arch/s390/kvm/Kconfig | 2 -- arch/x86/include/asm/kvm_host.h | 3 +++ arch/x86/kvm/Kconfig | 3 --- include/linux/kvm_host.h | 18 +++++++++++------- virt/kvm/Kconfig | 15 --------------- virt/kvm/kvm_main.c | 4 ++-- 17 files changed, 30 insertions(+), 38 deletions(-)
arch/arm64/include/asm/kvm_host.h +3 -0
@@ -30,6 +30,9 @@#include <asm/vncr_mapping.h> #define __KVM_HAVE_ARCH_INTC_INITIALIZED +#define KVM_MSI +#define KVM_READONLY_MEM +#define KVM_VCPU_RUN_PID_CHANGE #define KVM_HALT_POLL_NS_DEFAULT 500000
arch/arm64/kvm/Kconfig +0 -3
@@ -28,12 +28,9 @@ menuconfig KVM select KVM_VFIO select HAVE_KVM_DIRTY_RING_ACQ_REL select NEED_KVM_DIRTY_RING_WITH_BITMAP - select HAVE_KVM_MSI select HAVE_KVM_IRQCHIP select HAVE_KVM_IRQ_ROUTING select HAVE_KVM_IRQ_BYPASS - select HAVE_KVM_READONLY_MEM - select HAVE_KVM_VCPU_RUN_PID_CHANGE select SCHED_INFO select GUEST_PERF_EVENTS if PERF_EVENTS select KVM_GUEST_MEMFD
arch/loongarch/include/asm/kvm_host.h +2 -0
@@ -26,6 +26,8 @@#include <asm/loongarch.h> #define __KVM_HAVE_ARCH_INTC_INITIALIZED +#define KVM_MSI +#define KVM_READONLY_MEM /* Loongarch KVM register ids */ #define KVM_GET_IOC_CSR_IDX (id) ((id & KVM_CSR_IDX_MASK) >> LOONGARCH_REG_SHIFT)
arch/loongarch/kvm/Kconfig +0 -2
@@ -23,8 +23,6 @@ config KVM select HAVE_KVM_DIRTY_RING_ACQ_REL select HAVE_KVM_IRQ_ROUTING select HAVE_KVM_IRQCHIP - select HAVE_KVM_MSI - select HAVE_KVM_READONLY_MEM select KVM_COMMON select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_GENERIC_HARDWARE_ENABLING
arch/mips/include/asm/kvm_host.h +1 -0
@@ -893,5 +893,6 @@ 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_FLUSH_REMOTE_TLBS +#define KVM_READONLY_MEM #endif /* __MIPS_KVM_HOST_H__ */
arch/mips/kvm/Kconfig +0 -1
@@ -24,7 +24,6 @@ config KVM select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_MMIO select KVM_GENERIC_HARDWARE_ENABLING - select HAVE_KVM_READONLY_MEM help Support for hosting Guest kernels.
arch/powerpc/include/asm/kvm_host.h +3 -0
@@ -49,6 +49,9 @@#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #define __KVM_HAVE_ARCH_INTC_INITIALIZED +#ifdef CONFIG_KVM_MPIC +#define KVM_MSI +#endif #define KVM_HALT_POLL_NS_DEFAULT 10000/* 10 us */
arch/powerpc/kvm/Kconfig +0 -1
@@ -232,7 +232,6 @@ config KVM_MPIC depends on KVM && PPC_E500 select HAVE_KVM_IRQCHIP select HAVE_KVM_IRQ_ROUTING - select HAVE_KVM_MSI help Enable support for emulating MPIC devices inside the host kernel, rather than relying on userspace to emulate.
arch/riscv/include/asm/kvm_host.h +2 -0
@@ -47,6 +47,8 @@#define KVM_REQ_STEAL_UPDATE KVM_ARCH_REQ(6)#define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLBS_RANGE +#define KVM_MSI +#define KVM_READONLY_MEM #define KVM_HAVE_MMU_RWLOCK
arch/riscv/kvm/Kconfig +0 -2
@@ -22,8 +22,6 @@ config KVM depends on RISCV_SBI && MMU select HAVE_KVM_IRQCHIP select HAVE_KVM_IRQ_ROUTING - select HAVE_KVM_MSI - select HAVE_KVM_READONLY_MEM select HAVE_KVM_DIRTY_RING_ACQ_REL select KVM_COMMON select KVM_GENERIC_DIRTYLOG_READ_PROTECT
arch/s390/include/asm/kvm_host_s390.h +3 -0
@@ -34,6 +34,9 @@#define KVM_INTERNAL_MEM_SLOTS 1 +#define KVM_INVALID_WAKEUPS +#define KVM_NO_POLL +#define KVM_S390_MANAGES_S390_GUEST 1/*
arch/s390/kvm/Kconfig +0 -2
@@ -25,8 +25,6 @@ config KVM 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
arch/x86/include/asm/kvm_host.h +3 -0
@@ -47,6 +47,9 @@#define kvm_file_to_kvm_arch x86#define __KVM_HAVE_ARCH_VCPU_DEBUGFS +#define KVM_MSI +#define KVM_NO_POLL +#define KVM_READONLY_MEM /* * CONFIG_KVM_MAX_NR_VCPUS is defined iff CONFIG_KVM!=n, provide a dummy max if
arch/x86/kvm/Kconfig +0 -3
@@ -28,7 +28,6 @@ config KVM_X86 select HAVE_KVM_DIRTY_RING_ACQ_REL select HAVE_KVM_IRQ_BYPASS select HAVE_KVM_IRQ_ROUTING - select HAVE_KVM_READONLY_MEM select VHOST_TASK select KVM_ASYNC_PF select USER_RETURN_NOTIFIER
@@ -37,9 +36,7 @@ config KVM_X86 select PERF_EVENTS select GUEST_PERF_EVENTS select PERF_GUEST_MEDIATED_PMU - select HAVE_KVM_MSI select HAVE_KVM_CPU_RELAX_INTERCEPT - select HAVE_KVM_NO_POLL select VIRT_XFER_TO_GUEST_WORK select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_VFIO
include/linux/kvm_host.h +11 -7
@@ -750,7 +750,11 @@ static inline u64 kvm_gmem_get_supported_flags(struct kvm *kvm)#ifndef kvm_arch_has_readonly_memstatic inline bool kvm_arch_has_readonly_mem (struct kvm *kvm) { -return IS_ENABLED (CONFIG_HAVE_KVM_READONLY_MEM ); +#ifdef KVM_READONLY_MEM +return true; +#else +return false; +#endif }#endif
@@ -2486,7 +2490,7 @@ void kvm_arch_update_irqfd_routing(struct kvm_kernel_irqfd *irqfd, struct kvm_kernel_irq_routing_entry *new);#endif /* CONFIG_HAVE_KVM_IRQ_BYPASS */ -#ifdef CONFIG_HAVE_KVM_INVALID_WAKEUPS +#ifdef KVM_INVALID_WAKEUPS /* If we wakeup during the poll time, was it a sucessful poll? */ static inline bool vcpu_valid_wakeup (struct kvm_vcpu *vcpu) {
@@ -2498,9 +2502,9 @@ static inline bool vcpu_valid_wakeup(struct kvm_vcpu *vcpu) {return true; } -#endif /* CONFIG_HAVE_KVM_INVALID_WAKEUPS */ +#endif /* KVM_INVALID_WAKEUPS */ -#ifdef CONFIG_HAVE_KVM_NO_POLL +#ifdef KVM_NO_POLL /* Callback that tells if we must not poll */ bool kvm_arch_no_poll (struct kvm_vcpu *vcpu);#else
@@ -2508,18 +2512,18 @@ static inline bool kvm_arch_no_poll(struct kvm_vcpu *vcpu) {return false; } -#endif /* CONFIG_HAVE_KVM_NO_POLL */ +#endif /* KVM_NO_POLL */ void kvm_arch_guest_memory_reclaimed (struct kvm *kvm); -#ifdef CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE +#ifdef KVM_VCPU_RUN_PID_CHANGE int kvm_arch_vcpu_run_pid_change (struct kvm_vcpu *vcpu);#else static inline int kvm_arch_vcpu_run_pid_change (struct kvm_vcpu *vcpu) {return 0 ; } -#endif /* CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE */ +#endif /* KVM_VCPU_RUN_PID_CHANGE */ #ifdef CONFIG_VIRT_XFER_TO_GUEST_WORK static inline void kvm_handle_signal_exit (struct kvm_vcpu *vcpu)
virt/kvm/Kconfig +0 -15
@@ -50,21 +50,12 @@ config KVM_ASYNC_PF config KVM_ASYNC_PF_SYNC bool -config HAVE_KVM_MSI - bool - -config HAVE_KVM_READONLY_MEM - bool - config HAVE_KVM_CPU_RELAX_INTERCEPT bool config KVM_VFIO bool -config HAVE_KVM_INVALID_WAKEUPS - bool - config KVM_GENERIC_DIRTYLOG_READ_PROTECT bool
@@ -79,12 +70,6 @@ config HAVE_KVM_IRQ_BYPASS tristate select IRQ_BYPASS_MANAGER -config HAVE_KVM_VCPU_RUN_PID_CHANGE - bool - -config HAVE_KVM_NO_POLL - bool - config VIRT_XFER_TO_GUEST_WORK bool
virt/kvm/kvm_main.c +2 -2
@@ -4916,7 +4916,7 @@ static int kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)case KVM_CAP_DESTROY_MEMORY_REGION_WORKS :case KVM_CAP_JOIN_MEMORY_REGIONS_WORKS :case KVM_CAP_INTERNAL_ERROR_DATA : -#ifdef CONFIG_HAVE_KVM_MSI +#ifdef KVM_MSI case KVM_CAP_SIGNAL_MSI :#endif #ifdef CONFIG_HAVE_KVM_IRQCHIP
@@ -5306,7 +5306,7 @@ static long kvm_vm_ioctl(struct file *filp, r =kvm_ioeventfd (kvm, &data);break ; } -#ifdef CONFIG_HAVE_KVM_MSI +#ifdef KVM_MSI case KVM_SIGNAL_MSI : {struct kvm_msi msi;
Signature · 1 line
2.53.0
Re: [PATCH v9 02/24] KVM: Move architecture capability Kconfigs to header defines
On Wed, Sep 30, 2026 at 07:34:17PM +0200, Steffen Eiden wrote:
[...]
Quoted 4 lines
include/linux/kvm_host.h +0
-0@@ -750,7 +750,11 @@ static inline u64 kvm_gmem_get_supported_flags(struct kvm *kvm)#ifndef kvm_arch_has_readonly_mem
include/linux/kvm_host.h static inline u64 kvm_gmem_get_supported_flags(struct kvm *kvm) · line 759
Quoted 10 lines
include/linux/kvm_host.h +5
-1static inline bool kvm_arch_has_readonly_mem (struct kvm *kvm) { -return IS_ENABLED (CONFIG_HAVE_KVM_READONLY_MEM ); +#ifdef KVM_READONLY_MEM +return true; +#else +return false; +#endif }#endif
Minor style nit: maybe remove the preprocessor "noise" from within the function by defining two versions of them. Looks a bit cleaner then:
#ifdef KVM_READONLY_MEM
static inline bool kvm_arch_has_readonly_mem(struct kvm *kvm)
{
return true;
}
#else
static inline bool kvm_arch_has_readonly_mem(struct kvm *kvm)
{
return false;
}
#endifHowever, both versions are fine with me.
Paolo Bonzini
maintainerRe: [PATCH v9 02/24] KVM: Move architecture capability Kconfigs to header defines
In reply to Steffen EidenQuoted 2 lines · Steffen Eiden
Historically, KVM feature opt-ins and callbacks were configured globally via
Kconfigsymbols (CONFIG_HAVE_KVM_* and CONFIG_KVM_*).
Not all of them - there are many __KVM_HAVE_* symbols already. In particular now there's both KVM_MSI and __KVM_HAVE_MSI/__KVM_HAVE_MSIX (but the latter is dead, so I have sent a patch to remove it).
There are several remaining CONFIG_HAVE_KVM_ARCH_* Kconfig symbols as well. That's okay, but it should be noted in the changelog that not all symbols were fixed.
Can you at least quickly provide a v2, that changes all symbols to __KVM_HAVE_<function-name> (and when not applicable __KVM_*, for example __KVM_HAVE_READONLY_MEM)? I have already changed KVM_NO_MMIO to __KVM_NO_MMIO in kvm/queue.
Thanks,
Paolo
Quoted 350 lines
Replace these global
Kconfigoptions with architecture-specific opt-in defines in <asm/kvm_host.h> and standardize their naming by dropping theHAVE_prefix:
-KVM_INVALID_WAKEUPS
-KVM_MSI(formerlyHAVE_KVM_MSI)
-KVM_NO_POLL(formerlyHAVE_KVM_NO_POLL)
-KVM_READONLY_MEM(formerlyHAVE_KVM_READONLY_MEM)
-KVM_VCPU_RUN_PID_CHANGE(formerlyHAVE_KVM_VCPU_RUN_PID_CHANGE)This allows each architecture and guest implementation to configure its supported capabilities independently in its
kvm_hostheader and eliminates unnecessary fallback stubs across different KVM targets.Signed-off-by Steffen Eiden <[email protected]>--- arch/arm64/include/asm/kvm_host.h | 3 +++ arch/arm64/kvm/Kconfig | 3 --- arch/loongarch/include/asm/kvm_host.h | 2 ++ arch/loongarch/kvm/Kconfig | 2 -- arch/mips/include/asm/kvm_host.h | 1 + arch/mips/kvm/Kconfig | 1 - arch/powerpc/include/asm/kvm_host.h | 3 +++ arch/powerpc/kvm/Kconfig | 1 - arch/riscv/include/asm/kvm_host.h | 2 ++ arch/riscv/kvm/Kconfig | 2 -- arch/s390/include/asm/kvm_host_s390.h | 3 +++ arch/s390/kvm/Kconfig | 2 -- arch/x86/include/asm/kvm_host.h | 3 +++ arch/x86/kvm/Kconfig | 3 --- include/linux/kvm_host.h | 18 +++++++++++------- virt/kvm/Kconfig | 15 --------------- virt/kvm/kvm_main.c | 4 ++-- 17 files changed, 30 insertions(+), 38 deletions(-)arch/arm64/include/asm/kvm_host.h +3
-0@@ -30,6 +30,9 @@#include <asm/vncr_mapping.h> #define __KVM_HAVE_ARCH_INTC_INITIALIZED +#define KVM_MSI +#define KVM_READONLY_MEM +#define KVM_VCPU_RUN_PID_CHANGE #define KVM_HALT_POLL_NS_DEFAULT 500000arch/arm64/kvm/Kconfig +0
-3@@ -28,12 +28,9 @@ menuconfig KVM select KVM_VFIO select HAVE_KVM_DIRTY_RING_ACQ_REL select NEED_KVM_DIRTY_RING_WITH_BITMAP - select HAVE_KVM_MSI select HAVE_KVM_IRQCHIP select HAVE_KVM_IRQ_ROUTING select HAVE_KVM_IRQ_BYPASS - select HAVE_KVM_READONLY_MEM - select HAVE_KVM_VCPU_RUN_PID_CHANGE select SCHED_INFO select GUEST_PERF_EVENTS if PERF_EVENTS select KVM_GUEST_MEMFDarch/loongarch/include/asm/kvm_host.h +2
-0@@ -26,6 +26,8 @@#include <asm/loongarch.h> #define __KVM_HAVE_ARCH_INTC_INITIALIZED +#define KVM_MSI +#define KVM_READONLY_MEM /* Loongarch KVM register ids */ #define KVM_GET_IOC_CSR_IDX (id) ((id & KVM_CSR_IDX_MASK) >> LOONGARCH_REG_SHIFT)arch/loongarch/kvm/Kconfig +0
-2@@ -23,8 +23,6 @@ config KVM select HAVE_KVM_DIRTY_RING_ACQ_REL select HAVE_KVM_IRQ_ROUTING select HAVE_KVM_IRQCHIP - select HAVE_KVM_MSI - select HAVE_KVM_READONLY_MEM select KVM_COMMON select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_GENERIC_HARDWARE_ENABLINGarch/mips/include/asm/kvm_host.h +1
-0@@ -893,5 +893,6 @@ 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_FLUSH_REMOTE_TLBS +#define KVM_READONLY_MEM #endif /* __MIPS_KVM_HOST_H__ */ arch/mips/kvm/Kconfig +0
-1@@ -24,7 +24,6 @@ config KVM select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_MMIO select KVM_GENERIC_HARDWARE_ENABLING - select HAVE_KVM_READONLY_MEM help Support for hosting Guest kernels.arch/powerpc/include/asm/kvm_host.h +3
-0@@ -49,6 +49,9 @@#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #define __KVM_HAVE_ARCH_INTC_INITIALIZED +#ifdef CONFIG_KVM_MPIC +#define KVM_MSI +#endif #define KVM_HALT_POLL_NS_DEFAULT 10000/* 10 us */ arch/powerpc/kvm/Kconfig +0
-1@@ -232,7 +232,6 @@ config KVM_MPIC depends on KVM && PPC_E500 select HAVE_KVM_IRQCHIP select HAVE_KVM_IRQ_ROUTING - select HAVE_KVM_MSI help Enable support for emulating MPIC devices inside the host kernel, rather than relying on userspace to emulate.arch/riscv/include/asm/kvm_host.h +2
-0@@ -47,6 +47,8 @@#define KVM_REQ_STEAL_UPDATE KVM_ARCH_REQ(6)#define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLBS_RANGE +#define KVM_MSI +#define KVM_READONLY_MEM #define KVM_HAVE_MMU_RWLOCK arch/riscv/kvm/Kconfig +0
-2@@ -22,8 +22,6 @@ config KVM depends on RISCV_SBI && MMU select HAVE_KVM_IRQCHIP select HAVE_KVM_IRQ_ROUTING - select HAVE_KVM_MSI - select HAVE_KVM_READONLY_MEM select HAVE_KVM_DIRTY_RING_ACQ_REL select KVM_COMMON select KVM_GENERIC_DIRTYLOG_READ_PROTECTarch/s390/include/asm/kvm_host_s390.h +3
-0@@ -34,6 +34,9 @@#define KVM_INTERNAL_MEM_SLOTS 1 +#define KVM_INVALID_WAKEUPS +#define KVM_NO_POLL +#define KVM_S390_MANAGES_S390_GUEST 1/* arch/s390/kvm/Kconfig +0
-2@@ -25,8 +25,6 @@ config KVM 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_AGINGarch/x86/include/asm/kvm_host.h +3
-0@@ -47,6 +47,9 @@#define kvm_file_to_kvm_arch x86#define __KVM_HAVE_ARCH_VCPU_DEBUGFS +#define KVM_MSI +#define KVM_NO_POLL +#define KVM_READONLY_MEM /* * CONFIG_KVM_MAX_NR_VCPUS is defined iff CONFIG_KVM!=n, provide a dummy max if arch/x86/kvm/Kconfig +0
-3@@ -28,7 +28,6 @@ config KVM_X86 select HAVE_KVM_DIRTY_RING_ACQ_REL select HAVE_KVM_IRQ_BYPASS select HAVE_KVM_IRQ_ROUTING - select HAVE_KVM_READONLY_MEM select VHOST_TASK select KVM_ASYNC_PF select USER_RETURN_NOTIFIER@@ -37,9 +36,7 @@ config KVM_X86 select PERF_EVENTS select GUEST_PERF_EVENTS select PERF_GUEST_MEDIATED_PMU - select HAVE_KVM_MSI select HAVE_KVM_CPU_RELAX_INTERCEPT - select HAVE_KVM_NO_POLL select VIRT_XFER_TO_GUEST_WORK select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_VFIOinclude/linux/kvm_host.h +11
-7@@ -750,7 +750,11 @@ static inline u64 kvm_gmem_get_supported_flags(struct kvm *kvm)#ifndef kvm_arch_has_readonly_memstatic inline bool kvm_arch_has_readonly_mem (struct kvm *kvm) { -return IS_ENABLED (CONFIG_HAVE_KVM_READONLY_MEM ); +#ifdef KVM_READONLY_MEM +return true; +#else +return false; +#endif }#endif @@ -2486,7 +2490,7 @@ void kvm_arch_update_irqfd_routing(struct kvm_kernel_irqfd *irqfd, struct kvm_kernel_irq_routing_entry *new);#endif /* CONFIG_HAVE_KVM_IRQ_BYPASS */ -#ifdef CONFIG_HAVE_KVM_INVALID_WAKEUPS +#ifdef KVM_INVALID_WAKEUPS /* If we wakeup during the poll time, was it a sucessful poll? */ static inline bool vcpu_valid_wakeup (struct kvm_vcpu *vcpu) {@@ -2498,9 +2502,9 @@ static inline bool vcpu_valid_wakeup(struct kvm_vcpu *vcpu) {return true; } -#endif /* CONFIG_HAVE_KVM_INVALID_WAKEUPS */ +#endif /* KVM_INVALID_WAKEUPS */ -#ifdef CONFIG_HAVE_KVM_NO_POLL +#ifdef KVM_NO_POLL /* Callback that tells if we must not poll */ bool kvm_arch_no_poll (struct kvm_vcpu *vcpu);#else @@ -2508,18 +2512,18 @@ static inline bool kvm_arch_no_poll(struct kvm_vcpu *vcpu) {return false; } -#endif /* CONFIG_HAVE_KVM_NO_POLL */ +#endif /* KVM_NO_POLL */ void kvm_arch_guest_memory_reclaimed (struct kvm *kvm); -#ifdef CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE +#ifdef KVM_VCPU_RUN_PID_CHANGE int kvm_arch_vcpu_run_pid_change (struct kvm_vcpu *vcpu);#else static inline int kvm_arch_vcpu_run_pid_change (struct kvm_vcpu *vcpu) {return 0 ; } -#endif /* CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE */ +#endif /* KVM_VCPU_RUN_PID_CHANGE */ #ifdef CONFIG_VIRT_XFER_TO_GUEST_WORK static inline void kvm_handle_signal_exit (struct kvm_vcpu *vcpu)virt/kvm/Kconfig +0
-15@@ -50,21 +50,12 @@ config KVM_ASYNC_PF config KVM_ASYNC_PF_SYNC bool -config HAVE_KVM_MSI - bool - -config HAVE_KVM_READONLY_MEM - bool - config HAVE_KVM_CPU_RELAX_INTERCEPT bool config KVM_VFIO bool -config HAVE_KVM_INVALID_WAKEUPS - bool - config KVM_GENERIC_DIRTYLOG_READ_PROTECT bool@@ -79,12 +70,6 @@ config HAVE_KVM_IRQ_BYPASS tristate select IRQ_BYPASS_MANAGER -config HAVE_KVM_VCPU_RUN_PID_CHANGE - bool - -config HAVE_KVM_NO_POLL - bool - config VIRT_XFER_TO_GUEST_WORK boolvirt/kvm/kvm_main.c +2
-2@@ -4916,7 +4916,7 @@ static int kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)case KVM_CAP_DESTROY_MEMORY_REGION_WORKS :case KVM_CAP_JOIN_MEMORY_REGIONS_WORKS :case KVM_CAP_INTERNAL_ERROR_DATA : -#ifdef CONFIG_HAVE_KVM_MSI +#ifdef KVM_MSI case KVM_CAP_SIGNAL_MSI :#endif #ifdef CONFIG_HAVE_KVM_IRQCHIP @@ -5306,7 +5306,7 @@ static long kvm_vm_ioctl(struct file *filp, r =kvm_ioeventfd (kvm, &data);break ; } -#ifdef CONFIG_HAVE_KVM_MSI +#ifdef KVM_MSI case KVM_SIGNAL_MSI : {struct kvm_msi msi;
Steffen Eiden
reviewerRe: [PATCH v9 02/24] KVM: Move architecture capability Kconfigs to header defines
Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Steffen Eiden
Historically, KVM feature opt-ins and callbacks were configured globally via
Kconfigsymbols (CONFIG_HAVE_KVM_* and CONFIG_KVM_*).Not all of them - there are many __KVM_HAVE_* symbols already. In particular now there's both
KVM_MSIand __KVM_HAVE_MSI/__KVM_HAVE_MSIX (but the latter is dead, so I have sent a patch to remove it).
Quoted 9 lines
There are several remaining CONFIG_HAVE_KVM_ARCH_*
Kconfigsymbols as well. That's okay, but it should be noted in the changelog that not all symbols were fixed.Can you at least quickly provide a v2, that changes all symbols to __KVM_HAVE_<function-name> (and when not applicable __KVM_*, for example
__KVM_HAVE_READONLY_MEM)? I have already changedKVM_NO_MMIOto__KVM_NO_MMIOin kvm/queue.
Yes, no problem.
Using this pattern would reintroduce __KVM_HAVE_MSI then, right? I would create those symbols:
- __KVM_HAVE_INVALID_WAKEUPS (formerly KVM_INVALID_WAKEUPS)
- __KVM_HAVE_MSI (formerly HAVE_KVM_MSI)
- __KVM_HAVE_NO_POLL (formerly HAVE_KVM_NO_POLL)
- __KVM_HAVE_READONLY_MEM (formerly HAVE_KVM_READONLY_MEM)
- __KVM_HAVE_VCPU_RUN_PID_CHANGE (formerly HAVE_KVM_VCPU_RUN_PID_CHANGE)
OK?
Steffen
Quoted 18 lines
Thanks,
Paolo
Quoted 14 lines
Replace these global
Kconfigoptions with architecture-specific opt-in defines in <asm/kvm_host.h> and standardize their naming by dropping theHAVE_prefix:
-KVM_INVALID_WAKEUPS
-KVM_MSI(formerlyHAVE_KVM_MSI)
-KVM_NO_POLL(formerlyHAVE_KVM_NO_POLL)
-KVM_READONLY_MEM(formerlyHAVE_KVM_READONLY_MEM)
-KVM_VCPU_RUN_PID_CHANGE(formerlyHAVE_KVM_VCPU_RUN_PID_CHANGE)This allows each architecture and guest implementation to configure its supported capabilities independently in its
kvm_hostheader and eliminates unnecessary fallback stubs across different KVM targets.Signed-off-by Steffen Eiden <[email protected]>
Steffen Eiden
reviewerPATCH v10 2/24 KVM: Move architecture capability Kconfigs to header defines
In reply to Steffen EidenWith s390 hosting multiple independent KVM implementations within the same kernel build (native s390 KVM and arm64 on s390), global Kconfig selections force both implementations to inherit options that only apply to one of them.
Replace global Kconfig options which only apply to one KVM implementation with architecture-specific opt-in defines in the respective <asm/kvm_host.h>. Only remove Kconfig symbols that would be different on both s390 KVM implementations
- __KVM_HAVE_INVALID_WAKEUPS (formerly HAVE_KVM_INVALID_WAKEUPS)
- __KVM_HAVE_MSI (formerly HAVE_KVM_MSI)
- __KVM_HAVE_NO_POLL (formerly HAVE_KVM_NO_POLL)
- __KVM_HAVE_READONLY_MEM (formerly HAVE_KVM_READONLY_MEM)
- __KVM_HAVE_VCPU_RUN_PID_CHANGE (formerly HAVE_KVM_VCPU_RUN_PID_CHANGE)
This allows each architecture and guest implementation to configure its supported capabilities independently in its kvm_host header and eliminates adding unnecessary fallback stubs across different KVM targets.
---
Sending this patch alone. All others are OK or already picked.
Changes for v10:
- Use __KVM_HAVE_ as prefix
- Clarify that this patch touches only selected Kconfig options and not all.
arch/arm64/include/asm/kvm_host.h | 3 +++ arch/arm64/kvm/Kconfig | 3 --- arch/loongarch/include/asm/kvm_host.h | 2 ++ arch/loongarch/kvm/Kconfig | 2 -- arch/mips/include/asm/kvm_host.h | 1 + arch/mips/kvm/Kconfig | 1 - arch/powerpc/include/asm/kvm_host.h | 3 +++ arch/powerpc/kvm/Kconfig | 1 - arch/riscv/include/asm/kvm_host.h | 2 ++ arch/riscv/kvm/Kconfig | 2 -- arch/s390/include/asm/kvm_host_s390.h | 3 +++ arch/s390/kvm/Kconfig | 2 -- arch/x86/include/asm/kvm_host.h | 3 +++ arch/x86/kvm/Kconfig | 3 --- include/linux/kvm_host.h | 18 +++++++++++------- virt/kvm/Kconfig | 15 --------------- virt/kvm/kvm_main.c | 4 ++-- 17 files changed, 30 insertions(+), 38 deletions(-)
arch/arm64/include/asm/kvm_host.h +3 -0
@@ -32,6 +32,9 @@#include <asm/vncr_mapping.h> #define __KVM_HAVE_ARCH_INTC_INITIALIZED +#define __KVM_HAVE_MSI +#define __KVM_HAVE_READONLY_MEM +#define __KVM_HAVE_VCPU_RUN_PID_CHANGE#define KVM_HALT_POLL_NS_DEFAULT 500000
arch/arm64/kvm/Kconfig +0 -3
@@ -28,12 +28,9 @@ menuconfig KVM select KVM_VFIO select HAVE_KVM_DIRTY_RING_ACQ_REL select NEED_KVM_DIRTY_RING_WITH_BITMAP - select HAVE_KVM_MSI select HAVE_KVM_IRQCHIP select HAVE_KVM_IRQ_ROUTING select HAVE_KVM_IRQ_BYPASS - select HAVE_KVM_READONLY_MEM - select HAVE_KVM_VCPU_RUN_PID_CHANGE select SCHED_INFO select GUEST_PERF_EVENTS if PERF_EVENTS select KVM_GUEST_MEMFD
arch/loongarch/include/asm/kvm_host.h +2 -0
@@ -26,6 +26,8 @@#include <asm/loongarch.h> #define __KVM_HAVE_ARCH_INTC_INITIALIZED +#define __KVM_HAVE_MSI +#define __KVM_HAVE_READONLY_MEM/* Loongarch KVM register ids */ #define KVM_GET_IOC_CSR_IDX (id) ((id & KVM_CSR_IDX_MASK) >> LOONGARCH_REG_SHIFT)
arch/loongarch/kvm/Kconfig +0 -2
@@ -23,8 +23,6 @@ config KVM select HAVE_KVM_DIRTY_RING_ACQ_REL select HAVE_KVM_IRQ_ROUTING select HAVE_KVM_IRQCHIP - select HAVE_KVM_MSI - select HAVE_KVM_READONLY_MEM select KVM_COMMON select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_GENERIC_HARDWARE_ENABLING
arch/mips/include/asm/kvm_host.h +1 -0
@@ -893,5 +893,6 @@ 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_FLUSH_REMOTE_TLBS +#define __KVM_HAVE_READONLY_MEM#endif /* __MIPS_KVM_HOST_H__ */
arch/mips/kvm/Kconfig +0 -1
@@ -24,7 +24,6 @@ config KVM select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_MMIO select KVM_GENERIC_HARDWARE_ENABLING - select HAVE_KVM_READONLY_MEM help Support for hosting Guest kernels.
arch/powerpc/include/asm/kvm_host.h +3 -0
@@ -49,6 +49,9 @@#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #define __KVM_HAVE_ARCH_INTC_INITIALIZED +#ifdef CONFIG_KVM_MPIC +#define __KVM_HAVE_MSI +#endif #define KVM_HALT_POLL_NS_DEFAULT 10000/* 10 us */
arch/powerpc/kvm/Kconfig +0 -1
@@ -232,7 +232,6 @@ config KVM_MPIC depends on KVM && PPC_E500 select HAVE_KVM_IRQCHIP select HAVE_KVM_IRQ_ROUTING - select HAVE_KVM_MSI help Enable support for emulating MPIC devices inside the host kernel, rather than relying on userspace to emulate.
arch/riscv/include/asm/kvm_host.h +2 -0
@@ -47,6 +47,8 @@#define KVM_REQ_STEAL_UPDATE KVM_ARCH_REQ(6)#define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLBS_RANGE +#define __KVM_HAVE_MSI +#define __KVM_HAVE_READONLY_MEM#define KVM_HAVE_MMU_RWLOCK
arch/riscv/kvm/Kconfig +0 -2
@@ -22,8 +22,6 @@ config KVM depends on RISCV_SBI && MMU select HAVE_KVM_IRQCHIP select HAVE_KVM_IRQ_ROUTING - select HAVE_KVM_MSI - select HAVE_KVM_READONLY_MEM select HAVE_KVM_DIRTY_RING_ACQ_REL select KVM_COMMON select KVM_GENERIC_DIRTYLOG_READ_PROTECT
arch/s390/include/asm/kvm_host_s390.h +3 -0
@@ -34,6 +34,9 @@#define KVM_INTERNAL_MEM_SLOTS 1 +#define __KVM_HAVE_INVALID_WAKEUPS +#define __KVM_HAVE_NO_POLL +#define KVM_S390_MANAGES_S390_GUEST 1/*
arch/s390/kvm/Kconfig +0 -2
@@ -25,8 +25,6 @@ config KVM 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
arch/x86/include/asm/kvm_host.h +3 -0
@@ -47,6 +47,9 @@#define kvm_file_to_kvm_arch x86#define __KVM_HAVE_ARCH_VCPU_DEBUGFS +#define __KVM_HAVE_MSI +#define __KVM_HAVE_NO_POLL +#define __KVM_HAVE_READONLY_MEM/* * CONFIG_KVM_MAX_NR_VCPUS is defined iff CONFIG_KVM!=n, provide a dummy max if
arch/x86/kvm/Kconfig +0 -3
@@ -28,7 +28,6 @@ config KVM_X86 select HAVE_KVM_DIRTY_RING_ACQ_REL select HAVE_KVM_IRQ_BYPASS select HAVE_KVM_IRQ_ROUTING - select HAVE_KVM_READONLY_MEM select VHOST_TASK select KVM_ASYNC_PF select USER_RETURN_NOTIFIER
@@ -37,9 +36,7 @@ config KVM_X86 select PERF_EVENTS select GUEST_PERF_EVENTS select PERF_GUEST_MEDIATED_PMU - select HAVE_KVM_MSI select HAVE_KVM_CPU_RELAX_INTERCEPT - select HAVE_KVM_NO_POLL select VIRT_XFER_TO_GUEST_WORK select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_VFIO
include/linux/kvm_host.h +11 -7
@@ -750,7 +750,11 @@ static inline u64 kvm_gmem_get_supported_flags(struct kvm *kvm)#ifndef kvm_arch_has_readonly_memstatic inline bool kvm_arch_has_readonly_mem (struct kvm *kvm) { -return IS_ENABLED (CONFIG_HAVE_KVM_READONLY_MEM ); +#ifdef __KVM_HAVE_READONLY_MEM +return true; +#else +return false; +#endif }#endif
@@ -2481,7 +2485,7 @@ void kvm_arch_update_irqfd_routing(struct kvm_kernel_irqfd *irqfd, struct kvm_kernel_irq_routing_entry *new);#endif /* CONFIG_HAVE_KVM_IRQ_BYPASS */ -#ifdef CONFIG_HAVE_KVM_INVALID_WAKEUPS +#ifdef __KVM_HAVE_INVALID_WAKEUPS/* If we wakeup during the poll time, was it a sucessful poll? */ static inline bool vcpu_valid_wakeup (struct kvm_vcpu *vcpu) {
@@ -2493,9 +2497,9 @@ static inline bool vcpu_valid_wakeup(struct kvm_vcpu *vcpu) {return true; } -#endif /* CONFIG_HAVE_KVM_INVALID_WAKEUPS */ +#endif /* __KVM_HAVE_INVALID_WAKEUPS */ -#ifdef CONFIG_HAVE_KVM_NO_POLL +#ifdef __KVM_HAVE_NO_POLL/* Callback that tells if we must not poll */ bool kvm_arch_no_poll (struct kvm_vcpu *vcpu);#else
@@ -2503,18 +2507,18 @@ static inline bool kvm_arch_no_poll(struct kvm_vcpu *vcpu) {return false; } -#endif /* CONFIG_HAVE_KVM_NO_POLL */ +#endif /* __KVM_HAVE_NO_POLL */ void kvm_arch_guest_memory_reclaimed (struct kvm *kvm); -#ifdef CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE +#ifdef __KVM_HAVE_VCPU_RUN_PID_CHANGEint kvm_arch_vcpu_run_pid_change (struct kvm_vcpu *vcpu);#else static inline int kvm_arch_vcpu_run_pid_change (struct kvm_vcpu *vcpu) {return 0 ; } -#endif /* CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE */ +#endif /* __KVM_HAVE_VCPU_RUN_PID_CHANGE */ #ifdef CONFIG_VIRT_XFER_TO_GUEST_WORK static inline void kvm_handle_signal_exit (struct kvm_vcpu *vcpu)
virt/kvm/Kconfig +0 -15
@@ -50,21 +50,12 @@ config KVM_ASYNC_PF config KVM_ASYNC_PF_SYNC bool -config HAVE_KVM_MSI - bool - -config HAVE_KVM_READONLY_MEM - bool - config HAVE_KVM_CPU_RELAX_INTERCEPT bool config KVM_VFIO bool -config HAVE_KVM_INVALID_WAKEUPS - bool - config KVM_GENERIC_DIRTYLOG_READ_PROTECT bool
@@ -79,12 +70,6 @@ config HAVE_KVM_IRQ_BYPASS tristate select IRQ_BYPASS_MANAGER -config HAVE_KVM_VCPU_RUN_PID_CHANGE - bool - -config HAVE_KVM_NO_POLL - bool - config VIRT_XFER_TO_GUEST_WORK bool
virt/kvm/kvm_main.c +2 -2
@@ -4901,7 +4901,7 @@ static int kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)case KVM_CAP_DESTROY_MEMORY_REGION_WORKS :case KVM_CAP_JOIN_MEMORY_REGIONS_WORKS :case KVM_CAP_INTERNAL_ERROR_DATA : -#ifdef CONFIG_HAVE_KVM_MSI +#ifdef __KVM_HAVE_MSIcase KVM_CAP_SIGNAL_MSI :#endif #ifdef CONFIG_HAVE_KVM_IRQCHIP
@@ -5291,7 +5291,7 @@ static long kvm_vm_ioctl(struct file *filp, r =kvm_ioeventfd (kvm, &data);break ; } -#ifdef CONFIG_HAVE_KVM_MSI +#ifdef __KVM_HAVE_MSIcase KVM_SIGNAL_MSI : {struct kvm_msi msi;
Signature · 1 line
2.53.0
Steffen Eiden
reviewerRe: [PATCH v10 02/24] KVM: Move architecture capability Kconfigs to header defines
Quoted 22 lines · Steffen Eiden
With s390 hosting multiple independent KVM implementations within the same kernel build (native s390 KVM and arm64 on s390), global
Kconfigselections force both implementations to inherit options that only apply to one of them.Replace global
Kconfigoptions which only apply to one KVM implementation with architecture-specific opt-in defines in the respective <asm/kvm_host.h>. Only removeKconfigsymbols that would be different on both s390 KVM implementations-
__KVM_HAVE_INVALID_WAKEUPS(formerlyHAVE_KVM_INVALID_WAKEUPS)
-__KVM_HAVE_MSI(formerlyHAVE_KVM_MSI)
-__KVM_HAVE_NO_POLL(formerlyHAVE_KVM_NO_POLL)
-__KVM_HAVE_READONLY_MEM(formerlyHAVE_KVM_READONLY_MEM)
-__KVM_HAVE_VCPU_RUN_PID_CHANGE(formerlyHAVE_KVM_VCPU_RUN_PID_CHANGE)This allows each architecture and guest implementation to configure its supported capabilities independently in its
kvm_hostheader and eliminates adding unnecessary fallback stubs across different KVM targets.Signed-off-by Steffen Eiden <[email protected]>
Quoted 8 lines
---
Sending this patch alone. All others are OK or already picked.
Changes for v10:
- Use__KVM_HAVE_as prefix
- Clarify that this patch touches only selectedKconfigoptions and not all.
Paolo,
Sorry, I somehow managed to not CC you, doing that now.
FWIW:
Original patch v10:
https://lore.kernel.org/all/[email protected]/
Steffen
Re: [PATCH v10 02/24] KVM: Move architecture capability Kconfigs to header defines
Quoted 27 lines · Steffen Eiden
Quoted 26 lines · Steffen Eiden
With s390 hosting multiple independent KVM implementations within the same kernel build (native s390 KVM and arm64 on s390), global
Kconfigselections force both implementations to inherit options that only apply to one of them.Replace global
Kconfigoptions which only apply to one KVM implementation with architecture-specific opt-in defines in the respective <asm/kvm_host.h>. Only removeKconfigsymbols that would be different on both s390 KVM implementations-
__KVM_HAVE_INVALID_WAKEUPS(formerlyHAVE_KVM_INVALID_WAKEUPS)
-__KVM_HAVE_MSI(formerlyHAVE_KVM_MSI)
-__KVM_HAVE_NO_POLL(formerlyHAVE_KVM_NO_POLL)
-__KVM_HAVE_READONLY_MEM(formerlyHAVE_KVM_READONLY_MEM)
-__KVM_HAVE_VCPU_RUN_PID_CHANGE(formerlyHAVE_KVM_VCPU_RUN_PID_CHANGE)This allows each architecture and guest implementation to configure its supported capabilities independently in its
kvm_hostheader and eliminates adding unnecessary fallback stubs across different KVM targets.Signed-off-by Steffen Eiden <[email protected]>---
Sending this patch alone. All others are OK or already picked.
Quoted 8 lines
Quoted 4 lines
Changes for v10:
- Use__KVM_HAVE_as prefix
- Clarify that this patch touches only selectedKconfigoptions and not all.Paolo,
Sorry, I somehow managed to not CC you, doing that now.
Applied to kvm/next, thanks.
Paolo
Quoted 5 lines
FWIW:
Original patch v10:
https://lore.kernel.org/all/[email protected]/Steffen
Steffen Eiden
reviewerPATCH v9 3/24 KVM: Replace CONFIG_KVM_MMIO with KVM_NO_MMIO
In reply to Steffen EidenDefining KVM_MMIO is not flexible enough for multi-KVM systems where one KVM implements MMIO but others do not. Therefore, remove KVM_MMIO from the config space and use the macro KVM_NO_MMIO instead. Define KVM_NO_MMIO for KVM/s390 and for selected KVM/powerpc configurations.
coalesced_mmio.c is now always compiled&linked. However, for architectures/configurations defining KVM_NO_MMIO this effectively collapses to an empty object with no mmio code.
No functional changes.
--- arch/arm64/kvm/Kconfig | 1 - arch/loongarch/kvm/Kconfig | 1 - arch/mips/kvm/Kconfig | 1 - arch/powerpc/include/asm/kvm_host.h | 7 +++++++ arch/powerpc/kvm/Kconfig | 4 ---- arch/riscv/kvm/Kconfig | 1 - arch/s390/include/asm/kvm_host_s390.h | 2 ++ arch/x86/kvm/Kconfig | 1 - include/linux/kvm_host.h | 2 +- virt/kvm/Kconfig | 3 --- virt/kvm/Makefile.kvm | 4 ++-- virt/kvm/coalesced_mmio.c | 4 ++++ virt/kvm/coalesced_mmio.h | 2 +- virt/kvm/kvm_main.c | 8 ++++---- 14 files changed, 21 insertions(+), 20 deletions(-)
arch/arm64/kvm/Kconfig +0 -1
@@ -22,7 +22,6 @@ menuconfig KVM select KVM_COMMON select KVM_GENERIC_HARDWARE_ENABLING select HAVE_KVM_CPU_RELAX_INTERCEPT - select KVM_MMIO select KVM_GENERIC_DIRTYLOG_READ_PROTECT select VIRT_XFER_TO_GUEST_WORK select KVM_VFIO
arch/loongarch/kvm/Kconfig +0 -1
@@ -26,7 +26,6 @@ config KVM select KVM_COMMON select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_GENERIC_HARDWARE_ENABLING - select KVM_MMIO select VIRT_XFER_TO_GUEST_WORK select SCHED_INFO select GUEST_PERF_EVENTS if PERF_EVENTS
arch/mips/kvm/Kconfig +0 -1
@@ -22,7 +22,6 @@ config KVM select EXPORT_UASM select KVM_COMMON select KVM_GENERIC_DIRTYLOG_READ_PROTECT - select KVM_MMIO select KVM_GENERIC_HARDWARE_ENABLING help Support for hosting Guest kernels.
arch/powerpc/include/asm/kvm_host.h +7 -0
@@ -29,6 +29,13 @@#define __KVM_HAVE_ARCH_VCPU_DEBUGFS +#if !defined(CONFIG_KVM_BOOK3S_32_HANDLER ) && \ + !defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE ) && \ + !defined(CONFIG_KVM_E500V2 ) && \ + !defined(CONFIG_KVM_E500MC ) +#define KVM_NO_MMIO +#endif +#define KVM_MAX_VCPUS NR_CPUS#define KVM_MAX_VCORES NR_CPUS
arch/powerpc/kvm/Kconfig +0 -4
@@ -30,7 +30,6 @@ config KVM_BOOK3S_HANDLER config KVM_BOOK3S_32_HANDLER bool select KVM_BOOK3S_HANDLER - select KVM_MMIO config KVM_BOOK3S_64_HANDLER bool
@@ -38,7 +37,6 @@ config KVM_BOOK3S_64_HANDLER config KVM_BOOK3S_PR_POSSIBLE bool - select KVM_MMIO config KVM_BOOK3S_HV_POSSIBLE bool
@@ -201,7 +199,6 @@ config KVM_E500V2 depends on PPC_E500 && !PPC_E500MC depends on !CONTEXT_TRACKING_USER select KVM - select KVM_MMIO help Support running unmodified E500 guest kernels in virtual machines on E500v2 host processors.
@@ -216,7 +213,6 @@ config KVM_E500MC depends on PPC_E500MC depends on !CONTEXT_TRACKING_USER select KVM - select KVM_MMIO select KVM_BOOKE_HV help Support running unmodified E500MC/E5500/E6500 guest kernels in
arch/riscv/kvm/Kconfig +0 -1
@@ -26,7 +26,6 @@ config KVM select KVM_COMMON select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_GENERIC_HARDWARE_ENABLING - select KVM_MMIO select VIRT_XFER_TO_GUEST_WORK select SCHED_INFO select GUEST_PERF_EVENTS if PERF_EVENTS
arch/s390/include/asm/kvm_host_s390.h +2 -0
@@ -39,6 +39,8 @@#define KVM_S390_MANAGES_S390_GUEST 1 +#define KVM_NO_MMIO +/* * 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/x86/kvm/Kconfig +0 -1
@@ -31,7 +31,6 @@ config KVM_X86 select VHOST_TASK select KVM_ASYNC_PF select USER_RETURN_NOTIFIER - select KVM_MMIO select SCHED_INFO select PERF_EVENTS select GUEST_PERF_EVENTS
include/linux/kvm_host.h +1 -1
@@ -847,7 +847,7 @@ struct kvm {struct kvm_vm_stat stat;struct kvm_arch arch;refcount_t users_count; -#ifdef CONFIG_KVM_MMIO +#ifndef KVM_NO_MMIO struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;spinlock_t ring_lock;struct list_head coalesced_zones;
virt/kvm/Kconfig +0 -3
@@ -40,9 +40,6 @@ config NEED_KVM_DIRTY_RING_WITH_BITMAP bool depends on HAVE_KVM_DIRTY_RING -config KVM_MMIO - bool - config KVM_ASYNC_PF bool
virt/kvm/Makefile.kvm +2 -2
@@ -10,9 +10,9 @@ KVM_DEV_MINOR ?= KVM_MINOR ccflags-y +=-DKVM_DEV_NAME=$(KVM_DEV_NAME) -DKVM_DEV_MINOR=$(KVM_DEV_MINOR) -kvm-y := $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/binary_stats.o +kvm-y := $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/binary_stats.o \ + $(KVM)/coalesced_mmio.o kvm-$(CONFIG_KVM_VFIO) += $(KVM)/vfio.o -kvm-$(CONFIG_KVM_MMIO) += $(KVM)/coalesced_mmio.o kvm-$(CONFIG_KVM_ASYNC_PF) += $(KVM)/async_pf.o kvm-$(CONFIG_HAVE_KVM_IRQ_ROUTING) += $(KVM)/irqchip.o kvm-$(CONFIG_HAVE_KVM_DIRTY_RING) += $(KVM)/dirty_ring.o
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 /* !KVM_NO_MMIO */
virt/kvm/coalesced_mmio.h +1 -1
@@ -11,7 +11,7 @@* */ -#ifdef CONFIG_KVM_MMIO +#ifndef KVM_NO_MMIO #include <linux/list.h>
virt/kvm/kvm_main.c +4 -4
@@ -4086,7 +4086,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 +#ifndef KVM_NO_MMIO else if (vmf->pgoff == KVM_COALESCED_MMIO_PAGE_OFFSET) page =virt_to_page (vcpu->kvm->coalesced_mmio_ring);#endif
@@ -4927,7 +4927,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 +#ifndef KVM_NO_MMIO case KVM_CAP_COALESCED_MMIO :return KVM_COALESCED_MMIO_PAGE_OFFSET ;case KVM_CAP_COALESCED_PIO :
@@ -5268,7 +5268,7 @@ static long kvm_vm_ioctl(struct file *filp,break ; }#endif -#ifdef CONFIG_KVM_MMIO +#ifndef KVM_NO_MMIO case KVM_REGISTER_COALESCED_MMIO : {struct kvm_coalesced_mmio_zone zone;
@@ -5597,7 +5597,7 @@ static long kvm_dev_ioctl(struct file *filp,#ifdef CONFIG_X86 r +=PAGE_SIZE ;/* pio data page */ #endif -#ifdef CONFIG_KVM_MMIO +#ifndef KVM_NO_MMIO r +=PAGE_SIZE ;/* coalesced mmio ring page */ #endif break ;
Signature · 1 line
2.53.0
Re: [PATCH v9 03/24] KVM: Replace CONFIG_KVM_MMIO with KVM_NO_MMIO
Quoted 11 lines · Steffen Eiden
Defining
KVM_MMIOis not flexible enough for multi-KVM systems where one KVM implements MMIO but others do not. Therefore, removeKVM_MMIOfrom the config space and use the macroKVM_NO_MMIOinstead. DefineKVM_NO_MMIOfor KVM/s390 and for selected KVM/powerpc configurations.
coalesced_mmio.cis now always compiled&linked. However, for architectures/configurations definingKVM_NO_MMIOthis effectively collapses to an empty object with no mmio code.No functional changes.
Changes look good to me.
Quoted 3 lines
Suggested-by Marc Zyngier <[email protected]>Signed-off-by Steffen Eiden <[email protected]>
Thanks!
Paolo Bonzini
maintainerRe: [PATCH v9 03/24] KVM: Replace CONFIG_KVM_MMIO with KVM_NO_MMIO
In reply to Steffen EidenQuoted 5 lines · Steffen Eiden
Defining
KVM_MMIOis not flexible enough for multi-KVM systems where one KVM implements MMIO but others do not. Therefore, removeKVM_MMIOfrom the config space and use the macroKVM_NO_MMIOinstead. DefineKVM_NO_MMIOfor KVM/s390 and for selected KVM/powerpc configurations.
...
arch/powerpc/include/asm/kvm_host.h line 37
Quoted 6 lines
arch/powerpc/include/asm/kvm_host.h +6
-0+#if !defined(CONFIG_KVM_BOOK3S_32_HANDLER ) && \ + !defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE ) && \ + !defined(CONFIG_KVM_E500V2 ) && \ + !defined(CONFIG_KVM_E500MC ) +#define KVM_NO_MMIO +#endif
This can be simplified to
#if defined(KVM_BOOK3S_HV_POSSIBLE) && \
!defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE)
which I have done.
Paolo
Steffen Eiden
reviewerPATCH v9 4/24 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 v9 5/24 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
@@ -102,26 +102,48 @@#define COMPAT_USER_SZ 296/* Architecturally defined mapping between AArch32 and AArch64 registers */ +enum { + __compat_fp =11 , + __compat_sp =13 , + __compat_lr =14 , + __compat_sp_hyp =15 , + __compat_lr_irq =16 , + __compat_sp_irq =17 , + __compat_lr_svc =18 , + __compat_sp_svc =19 , + __compat_lr_abt =20 , + __compat_sp_abt =21 , + __compat_lr_und =22 , + __compat_sp_und =23 , + __compat_r8_fiq =24 , + __compat_r9_fiq =25 , + __compat_r10_fiq =26 , + __compat_r11_fiq =27 , + __compat_r12_fiq =28 , + __compat_sp_fiq =29 , + __compat_lr_fiq =30 , +}; +#define compat_usr (x) regs[(x)] -#define compat_fp regs[11] -#define compat_sp regs[13] -#define compat_lr regs[14] -#define compat_sp_hyp regs[15] -#define compat_lr_irq regs[16] -#define compat_sp_irq regs[17] -#define compat_lr_svc regs[18] -#define compat_sp_svc regs[19] -#define compat_lr_abt regs[20] -#define compat_sp_abt regs[21] -#define compat_lr_und regs[22] -#define compat_sp_und regs[23] -#define compat_r8_fiq regs[24] -#define compat_r9_fiq regs[25] -#define compat_r10_fiq regs[26] -#define compat_r11_fiq regs[27] -#define compat_r12_fiq regs[28] -#define compat_sp_fiq regs[29] -#define compat_lr_fiq regs[30] +#define compat_fp regs[__compat_fp] +#define compat_sp regs[__compat_sp] +#define compat_lr regs[__compat_lr] +#define compat_sp_hyp regs[__compat_sp_hyp] +#define compat_lr_irq regs[__compat_lr_irq] +#define compat_sp_irq regs[__compat_sp_irq] +#define compat_lr_svc regs[__compat_lr_svc] +#define compat_sp_svc regs[__compat_sp_svc] +#define compat_lr_abt regs[__compat_lr_abt] +#define compat_sp_abt regs[__compat_sp_abt] +#define compat_lr_und regs[__compat_lr_und] +#define compat_sp_und regs[__compat_sp_und] +#define compat_r8_fiq regs[__compat_r8_fiq] +#define compat_r9_fiq regs[__compat_r9_fiq] +#define compat_r10_fiq regs[__compat_r10_fiq] +#define compat_r11_fiq regs[__compat_r11_fiq] +#define compat_r12_fiq regs[__compat_r12_fiq] +#define compat_sp_fiq regs[__compat_sp_fiq] +#define compat_lr_fiq regs[__compat_lr_fiq]static inline unsigned long compat_psr_to_pstate (const unsigned long psr) {
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v9 6/24 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 DDI0601.
No functional change.
--- arch/arm64/include/asm/sysreg.h | 3 -- arch/arm64/tools/sysreg | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 51 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 +51 -0
57 lines not on this page · raw message
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v9 7/24 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 | 14 ++++++++------ arch/arm64/include/asm/kvm_host.h | 2 +- arch/arm64/kvm/guest.c | 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 ++-- 6 files changed, 16 insertions(+), 14 deletions(-)
arch/arm64/include/asm/kvm_emulate.h +8 -6
@@ -133,12 +133,12 @@ static inline void vcpu_set_vsesr(struct kvm_vcpu *vcpu, u64 vsesr)static __always_inline unsigned long *vcpu_pc (const struct kvm_vcpu *vcpu) { -return (unsigned long *)&vcpu_gp_regs (vcpu)->pc; +return (unsigned long *)&vcpu->arch.ctxt.regs.pc; }static __always_inline unsigned long *vcpu_cpsr (const struct kvm_vcpu *vcpu) { -return (unsigned long *)&vcpu_gp_regs (vcpu)->pstate; +return (unsigned long *)&vcpu->arch.ctxt.regs.pstate; } static __always_inline bool vcpu_mode_is_32bit(const struct kvm_vcpu *vcpu)
@@ -167,14 +167,14 @@ static inline void vcpu_set_thumb(struct kvm_vcpu *vcpu)static __always_inline unsigned long vcpu_get_reg (const struct kvm_vcpu *vcpu,u8 reg_num) { -return (reg_num ==31 ) ?0 :vcpu_gp_regs (vcpu)->regs[reg_num]; +return (reg_num ==31 ) ?0 :vcpu_gp_regs (vcpu)[reg_num]; } static __always_inline void vcpu_set_reg(struct kvm_vcpu *vcpu, u8 reg_num,unsigned long val) {if (reg_num !=31 ) -vcpu_gp_regs (vcpu)->regs[reg_num] = val; +vcpu_gp_regs (vcpu)[reg_num] = val; }static inline bool vcpu_is_el2_ctxt (const struct kvm_cpu_context *ctxt)
@@ -750,13 +750,15 @@ static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu) pstate =VCPU_RESET_PSTATE_EL1 ;/* Reset core registers */ -memset (vcpu_gp_regs (vcpu),0 ,sizeof (*vcpu_gp_regs (vcpu))); +memset (vcpu_gp_regs (vcpu),0 ,sizeof (vcpu_gp_regs (vcpu))); + *vcpu_pc (vcpu) =0 ; + vcpu->arch.ctxt.regs.sp =0 ;memset (&vcpu->arch.ctxt.fp_regs,0 ,sizeof (vcpu->arch.ctxt.fp_regs)); vcpu->arch.ctxt.spsr_abt =0 ; vcpu->arch.ctxt.spsr_und =0 ; vcpu->arch.ctxt.spsr_irq =0 ; vcpu->arch.ctxt.spsr_fiq =0 ; -vcpu_gp_regs (vcpu)->pstate = pstate; + *vcpu_cpsr (vcpu) = pstate; }/* PSCI reset handling for a vcpu. */
arch/arm64/include/asm/kvm_host.h +1 -1
@@ -1161,7 +1161,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/guest.c +1 -1
@@ -134,7 +134,7 @@ 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;
arch/arm64/kvm/hyp/exception.c +2 -2
@@ -276,12 +276,12 @@ static void enter_exception32(struct kvm_vcpu *vcpu, u32 mode, u32 vect_offset)switch (mode) {case PSR_AA32_MODE_ABT :__vcpu_write_spsr_abt (vcpu,host_spsr_to_spsr32 (spsr)); -vcpu_gp_regs (vcpu)->compat_lr_abt = return_address; +vcpu_gp_regs (vcpu)[__compat_lr_abt] = return_address;break ;case PSR_AA32_MODE_UND :__vcpu_write_spsr_und (vcpu,host_spsr_to_spsr32 (spsr)); -vcpu_gp_regs (vcpu)->compat_lr_und = return_address; +vcpu_gp_regs (vcpu)[__compat_lr_und] = return_address;break ; }
arch/arm64/kvm/hyp/include/hyp/adjust_pc.h +2 -2
@@ -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
@@ -470,7 +470,7 @@ static inline bool kvm_hyp_handle_mops(struct kvm_vcpu *vcpu, u64 *exit_code)u64 spsr; *vcpu_pc (vcpu) =read_sysreg_el2 (SYS_ELR ); -arm64_mops_reset_regs (vcpu_gp_regs (vcpu), vcpu->arch.fault.esr_el2); +arm64_mops_reset_regs (&vcpu->arch.ctxt.regs, vcpu->arch.fault.esr_el2);write_sysreg_el2 (*vcpu_pc (vcpu),SYS_ELR );/*
@@ -902,7 +902,7 @@ static inline void synchronize_vcpu_pstate(struct kvm_vcpu *vcpu)/* * Check for the conditions of Cortex-A510's #2077057. When these occur * SPSR_EL2 can't be trusted, but isn't needed either as it is -* unchanged from the value in vcpu_gp_regs(vcpu)->pstate. +* unchanged from the value in vcpu_cpsr(vcpu). * Are we single-stepping the guest, and took a PAC exception from the * active-not-pending state? */
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v9 8/24 KVM: arm64: Use accessor functions for core regs
In reply to Steffen EidenInstead of accessing the value directly use accessor functions that abstract the actual location of the register values. Add a helper function to reset fpsimd registers. Enables other KVM implementations to reuse this code.
No functional changes.
--- arch/arm64/include/asm/kvm_emulate.h | 34 ++++++++++++++++++++++++++-- arch/arm64/kvm/guest.c | 14 ++++++------ 2 files changed, 39 insertions(+), 9 deletions(-)
arch/arm64/include/asm/kvm_emulate.h +32 -2
@@ -141,6 +141,31 @@ static __always_inline unsigned long *vcpu_cpsr(const struct kvm_vcpu *vcpu)return (unsigned long *)&vcpu->arch.ctxt.regs.pstate; } +static __always_inline unsigned long *vcpu_sp_el0 (struct kvm_vcpu *vcpu) +{ +return (unsigned long *)&vcpu->arch.ctxt.regs.sp; +} + +static __always_inline u64 *vcpu_sp_el1(struct kvm_vcpu *vcpu) +{ +return __ctxt_sys_reg (&vcpu->arch.ctxt,SP_EL1 ); +} + +static __always_inline __u128 *vcpu_vreg(struct kvm_vcpu *vcpu, int n) +{ +return &vcpu->arch.ctxt.fp_regs.vregs[n]; +} + +static __always_inline __u32 *vcpu_fpsr(struct kvm_vcpu *vcpu) +{ +return &vcpu->arch.ctxt.fp_regs.fpsr; +} + +static __always_inline __u32 *vcpu_fpcr(struct kvm_vcpu *vcpu) +{ +return &vcpu->arch.ctxt.fp_regs.fpcr; +} + static __always_inline bool vcpu_mode_is_32bit(const struct kvm_vcpu *vcpu) {return !!(*vcpu_cpsr (vcpu) &PSR_MODE32_BIT );
@@ -737,6 +762,11 @@ static inline void vcpu_set_hcrx(struct kvm_vcpu *vcpu) } } +static inline void kvm_reset_fpsimd (struct kvm_vcpu *vcpu) +{ +memset (&vcpu->arch.ctxt.fp_regs,0 ,sizeof (vcpu->arch.ctxt.fp_regs)); +} +/* Reset a vcpu's core registers. */ static inline void kvm_reset_vcpu_core (struct kvm_vcpu *vcpu) {
@@ -752,8 +782,8 @@ static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu)/* Reset core registers */ memset (vcpu_gp_regs (vcpu),0 ,sizeof (vcpu_gp_regs (vcpu))); *vcpu_pc (vcpu) =0 ; - vcpu->arch.ctxt.regs.sp =0 ; -memset (&vcpu->arch.ctxt.fp_regs,0 ,sizeof (vcpu->arch.ctxt.fp_regs)); + *vcpu_sp_el0 (vcpu) =0 ; +kvm_reset_fpsimd (vcpu); vcpu->arch.ctxt.spsr_abt =0 ; vcpu->arch.ctxt.spsr_und =0 ; vcpu->arch.ctxt.spsr_irq =0 ;
arch/arm64/kvm/guest.c +7 -7
@@ -137,16 +137,16 @@ static void *core_reg_addr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)return &vcpu_gp_regs (vcpu)[off];case KVM_REG_ARM_CORE_REG (regs.sp): -return &vcpu->arch.ctxt.regs.sp; +return vcpu_sp_el0 (vcpu);case KVM_REG_ARM_CORE_REG (regs.pc): -return &vcpu->arch.ctxt.regs.pc; +return vcpu_pc (vcpu);case KVM_REG_ARM_CORE_REG (regs.pstate): -return &vcpu->arch.ctxt.regs.pstate; +return vcpu_cpsr (vcpu);case KVM_REG_ARM_CORE_REG (sp_el1): -return __ctxt_sys_reg (&vcpu->arch.ctxt,SP_EL1 ); +return vcpu_sp_el1 (vcpu);case KVM_REG_ARM_CORE_REG (elr_el1):return __ctxt_sys_reg (&vcpu->arch.ctxt,ELR_EL1 );
@@ -170,13 +170,13 @@ static void *core_reg_addr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) KVM_REG_ARM_CORE_REG(fp_regs.vregs[31]): off -=KVM_REG_ARM_CORE_REG (fp_regs.vregs[0 ]); off /=4 ; -return &vcpu->arch.ctxt.fp_regs.vregs[off]; +return vcpu_vreg (vcpu, off);case KVM_REG_ARM_CORE_REG (fp_regs.fpsr): -return &vcpu->arch.ctxt.fp_regs.fpsr; +return vcpu_fpsr (vcpu);case KVM_REG_ARM_CORE_REG (fp_regs.fpcr): -return &vcpu->arch.ctxt.fp_regs.fpcr; +return vcpu_fpcr (vcpu);default :return NULL ;
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v9 9/24 arm64: Prepare sharing arm64 headers with s390
In reply to Steffen EidenPrepare the sharing of arm64 headers with s390 by moving definitions inside headers to reduce the number of shared markers. Clean up 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_host.h | 102 ++++++++++++++++-------------- arch/arm64/include/asm/sysreg.h | 2 +- 4 files changed, 59 insertions(+), 54 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_host.h +53 -49
144 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 v9 10/24 arm64: Share arm64 headers with s390
In reply to Steffen EidenAllow sharing of arm64 headers with s390 by marking the shared regions or by adding a comment that the whole file is shared.
The shared regions are marked with:
#if ARM64_S390_COMMON == 1
/* insert shared definitions here */
#endif /* ARM64_S390_COMMON == 1 */
The preprocessor symbol ARM64_S390_COMMON is always defined to 1 for any arm64 build. s390 later will generate its own view of arm64 headers based on the content inside the #if/#endif block.
No functional change.
--- arch/arm64/Makefile | 3 +++ arch/arm64/include/asm/brk-imm.h | 1 + arch/arm64/include/asm/esr.h | 1 + arch/arm64/include/asm/kvm_arm.h | 1 + arch/arm64/include/asm/kvm_emulate.h | 18 ++++++++++++++++++ arch/arm64/include/asm/kvm_host.h | 13 +++++++++++++ arch/arm64/include/asm/ptrace.h | 4 ++++ arch/arm64/include/asm/sysreg.h | 15 +++++++++++++++ 8 files changed, 56 insertions(+)
arch/arm64/Makefile +3 -0
@@ -45,6 +45,9 @@ KBUILD_CFLAGS += $(CC_FLAGS_NO_FPU) \ KBUILD_CFLAGS += $(call cc-disable-warning, psabi) KBUILD_AFLAGS += $(compat_vdso) +# Enable all code shared to s390 +KBUILD_CPPFLAGS += -DARM64_S390_COMMON=1 + ifeq ($(call rustc-min-version, 108500),y) KBUILD_RUSTFLAGS += --target=aarch64-unknown-none-softfloat else
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 +18 -0
@@ -44,6 +44,7 @@ enum exception_type {bool kvm_condition_valid32 (const struct kvm_vcpu *vcpu);void kvm_skip_instr32 (struct kvm_vcpu *vcpu); +#if ARM64_S390_COMMON ==1 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);
@@ -75,6 +76,8 @@ static inline int kvm_inject_serror(struct kvm_vcpu *vcpu)void kvm_vcpu_wfi (struct kvm_vcpu *vcpu); +#endif /* ARM64_S390_COMMON == 1 */ +void kvm_emulate_nested_eret (struct kvm_vcpu *vcpu);int kvm_inject_nested_sync (struct kvm_vcpu *vcpu,u64 esr_el2);int kvm_inject_nested_irq (struct kvm_vcpu *vcpu);
@@ -184,6 +187,7 @@ static inline void vcpu_set_thumb(struct kvm_vcpu *vcpu) *vcpu_cpsr (vcpu) |=PSR_AA32_T_BIT ; } +#if ARM64_S390_COMMON ==1 /* * 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
@@ -202,6 +206,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 == 1 */ +static inline bool vcpu_is_el2_ctxt (const struct kvm_cpu_context *ctxt) {switch (ctxt->regs.pstate & (PSR_MODE32_BIT |PSR_MODE_MASK )) {
@@ -404,6 +410,7 @@ static inline u64 kvm_vcpu_get_disr(const struct kvm_vcpu *vcpu)return vcpu->arch.fault.disr_el1; } +#if ARM64_S390_COMMON ==1 static inline u32 kvm_vcpu_hvc_get_imm (const struct kvm_vcpu *vcpu) {return kvm_vcpu_get_esr (vcpu) & ESR_ELx_xVC_IMM_MASK;
@@ -481,6 +488,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 == 1 */ +static inline bool kvm_vcpu_trap_is_permission_fault (const struct kvm_vcpu *vcpu) {
@@ -521,6 +530,7 @@ static __always_inline int kvm_vcpu_sys_get_rt(struct kvm_vcpu *vcpu)return ESR_ELx_SYS64_ISS_RT (esr); } +#if ARM64_S390_COMMON ==1 static inline bool kvm_is_write_fault (struct kvm_vcpu *vcpu) {if (kvm_vcpu_abt_iss1tw (vcpu)) {
@@ -545,6 +555,8 @@ static inline bool kvm_is_write_fault(struct kvm_vcpu *vcpu) return kvm_vcpu_dabt_iswrite(vcpu); } +#endif /* ARM64_S390_COMMON == 1 */ +static inline unsigned long kvm_vcpu_get_mpidr_aff (struct kvm_vcpu *vcpu) {return __vcpu_sys_reg (vcpu,MPIDR_EL1 ) &MPIDR_HWID_BITMASK ;
@@ -586,6 +598,7 @@ static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu)return vcpu_read_sys_reg (vcpu, r) & bit; } +#if ARM64_S390_COMMON ==1 static inline unsigned long vcpu_data_guest_to_host (struct kvm_vcpu *vcpu,unsigned long data,unsigned int len)
@@ -661,6 +674,8 @@ static __always_inline void kvm_incr_pc(struct kvm_vcpu *vcpu)vcpu_set_flag ((v), e); \ } while (0) +#endif /* ARM64_S390_COMMON == 1 */ +/* * Returns a 'sanitised' view of CPTR_EL2, translating from nVHE to the VHE * format if E2H isn't set.
@@ -767,6 +782,7 @@ static inline void kvm_reset_fpsimd(struct kvm_vcpu *vcpu)memset (&vcpu->arch.ctxt.fp_regs,0 ,sizeof (vcpu->arch.ctxt.fp_regs)); } +#if ARM64_S390_COMMON ==1 /* Reset a vcpu's core registers. */ static inline void kvm_reset_vcpu_core (struct kvm_vcpu *vcpu) {
@@ -791,6 +807,8 @@ static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu) *vcpu_cpsr(vcpu) = pstate; } +#endif /* ARM64_S390_COMMON == 1 */ +/* PSCI reset handling for a vcpu. */ static inline void kvm_reset_vcpu_psci (struct kvm_vcpu *vcpu,struct vcpu_reset_state *reset_state)
arch/arm64/include/asm/kvm_host.h +13 -0
@@ -42,6 +42,7 @@#define KVM_MAX_VCPUS VGIC_V3_MAX_CPUS +#if ARM64_S390_COMMON ==1 #define KVM_VCPU_MAX_FEATURES 10#define KVM_VCPU_VALID_FEATURES (BIT(KVM_VCPU_MAX_FEATURES) - 1)
@@ -99,6 +100,8 @@ struct vcpu_reset_state { bool reset; }; +#endif /* ARM64_S390_COMMON == 1 */ +#define KVM_DIRTY_LOG_MANUAL_CAPS (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \ KVM_DIRTY_LOG_INITIALLY_SET)
@@ -958,6 +961,7 @@ struct kvm_vcpu_arch {pid_t pid; }; +#if ARM64_S390_COMMON ==1 /* * Each 'flag' is composed of a comma-separated triplet: *
@@ -1116,6 +1120,8 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu);/* KVM is currently emulating an L2 to L1 exception */ #define IN_NESTED_EXCEPTION __vcpu_single_flag(sflags, BIT(9)) +#endif /* ARM64_S390_COMMON == 1 */ +#define vcpu_sve_max_vq (vcpu) sve_vq_from_vl((vcpu)->arch.sve_max_vl)#define vcpu_sve_zcr_elx (vcpu) \
@@ -1329,6 +1335,7 @@ int __init populate_nv_trap_config(void);void kvm_calculate_traps (struct kvm_vcpu *vcpu); +#if ARM64_S390_COMMON ==1 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);
@@ -1344,6 +1351,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 == 1 */ +/* * 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
@@ -1536,11 +1545,15 @@ static inline bool __vcpu_has_feature(const struct kvm_arch *ka, int feature)return test_bit (feature, ka->vcpu_features); } +#if ARM64_S390_COMMON ==1 +#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 == 1 */ +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
@@ -26,6 +26,8 @@#define GIC_PRIO_PSR_I_SET GICV3_PRIO_PSR_I_SET +#if ARM64_S390_COMMON ==1 +/* Additional SPSR bits not exposed in the UABI */ #define PSR_MODE_THREAD_BIT (1 << 0)#define PSR_IL_BIT (1 << 20)
@@ -66,6 +68,8 @@#define PSR_AA32_IT_MASK 0x0600fc00/* If-Then execution state mask */ #define PSR_AA32_GE_MASK 0x000f0000 +#endif /* ARM64_S390_COMMON == 1 */ +#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> +#if ARM64_S390_COMMON ==1 +/* * 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 == 1 */ +#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) +#if ARM64_S390_COMMON ==1 +/* 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 == 1 */ +#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) +#if ARM64_S390_COMMON ==1 /* 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 == 1 */ +#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; \ }) +#if ARM64_S390_COMMON ==1 +#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 == 1 */ +#endif /* __ASSEMBLER__ */ #endif /* __ASM_SYSREG_H */
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v9 11/24 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/mmio.c | 2 ++ 3 files changed, 11 insertions(+)
arch/arm64/kvm/arm.c +3 -0
@@ -1607,6 +1607,7 @@ static unsigned long system_supported_vcpu_features(void)return features; } +#if ARM64_S390_COMMON ==1 static int kvm_vcpu_init_check_features (struct kvm_vcpu *vcpu,const struct kvm_vcpu_init *init) {
@@ -1660,6 +1661,8 @@ static bool kvm_vcpu_init_changed(struct kvm_vcpu *vcpu, KVM_VCPU_MAX_FEATURES); } +#endif /* ARM64_S390_COMMON == 1 */ +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), }; +#if ARM64_S390_COMMON ==1 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 == 1 */ +#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 ; } +#if ARM64_S390_COMMON ==1 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 == 1 */ +static unsigned long num_sve_regs (const struct kvm_vcpu *vcpu) {const unsigned int slices =vcpu_sve_slices (vcpu);
arch/arm64/kvm/mmio.c +2 -0
@@ -10,6 +10,7 @@#include "trace.h" +#if ARM64_S390_COMMON ==1 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 == 1 */
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v9 12/24 s390/Kconfig: remove PCI dependency from HAS_IOMEM
In reply to Steffen EidenHAS_IOMEM was defined as def_bool PCI on s390, making it false on kernels built without PCI support. This made sense until now as the IOMEM code was only required if PCI was enabled. This will change as KVM will require IOMEM in the future. To simplify the config space, turn HAS_IOMEM on unconditionally by default.
All other architectures either do not override HAS_IOMEM or set it unconditionally. s390 was the only architecture where HAS_IOMEM could be false on a real system.
Since HAS_IOMEM=y now causes kernel/iomem.o and lib/devres.o to be built unconditionally, ioremap()/iounmap() must always be available. Select GENERIC_IOREMAP unconditionally to provide the generic implementations for the PCI=n case.
Previously GENERIC_IOREMAP was conditioned on CONFIG_PCI in lockstep with HAS_IOMEM, so mm/ioremap.c was never built without PCI. Therefore, guard the PCI override macros ioremap_prot, iounmap, and ioremap_wc with CONFIG_PCI.
--- arch/s390/Kconfig | 5 +---- arch/s390/include/asm/io.h | 12 ++++++------ 2 files changed, 7 insertions(+), 10 deletions(-)
arch/s390/Kconfig +1 -4
@@ -181,7 +181,7 @@ config S390 select GENERIC_ENTRY select GENERIC_GETTIMEOFDAY select GENERIC_SMP_IDLE_THREAD - select GENERIC_IOREMAP if PCI + select GENERIC_IOREMAP select GLOB select HAVE_ALIGNED_STRUCT_PAGE select HAVE_ARCH_AUDITSYSCALL
@@ -768,9 +768,6 @@ config PCI_NR_FUNCTIONS endif # PCI -config HAS_IOMEM - def_bool PCI - config CHSC_SCH def_tristate m prompt "Support for CHSC subchannels"
arch/s390/include/asm/io.h +6 -6
@@ -27,14 +27,8 @@ void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr);/* * I/O memory mapping functions. */ -#define ioremap_prot ioremap_prot -#define iounmap iounmap -#define _PAGE_IOREMAP pgprot_val(PAGE_KERNEL) -#define ioremap_wc (addr, size) \ - ioremap_prot((addr), (size), pgprot_writecombine(PAGE_KERNEL)) -static inline void __iomem *ioport_map (unsigned long port,unsigned int nr) {return NULL ;
@@ -46,6 +40,12 @@ static inline void ioport_unmap(void __iomem *p)#ifdef CONFIG_PCI +#define ioremap_prot ioremap_prot +#define iounmap iounmap + +#define ioremap_wc (addr, size) \ + ioremap_prot((addr), (size), pgprot_writecombine(PAGE_KERNEL)) +/* * s390 needs a private implementation of pci_iomap since ioremap with its * offset parameter isn't sufficient. That's because BAR spaces are not
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v9 13/24 KVM: s390: Use dedicated function for migration mode
In reply to Steffen EidenUse kvm_s390_is_migration_mode() instead of kvm.arch->migration_mode. The function is independent of the actual kvm_arch implementation which is different for the second parallel KVM module..
--- arch/s390/kvm/gmap/kvm_mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kvm/gmap/kvm_mmu.c +1 -1
@@ -76,7 +76,7 @@ int s390_kvm_mmu_prepare_memory_region(struct kvm *kvm,return -EINVAL ; } -if (kvm->arch.migration_mode) { +if (kvm_s390_is_migration_mode (kvm)) {/* * Turn off migration mode when: * - userspace creates a new memslot with dirty logging off,
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v9 14/24 s390/tools: 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 CONFIG_KVM.
--- arch/s390/include/uapi/Kbuild | 6 ++ arch/s390/tools/Makefile | 6 +- arch/s390/tools/Makefile.arm64h | 55 ++++++++++++++++++ arch/s390/tools/copy-arm64h-full.awk | 50 +++++++++++++++++ arch/s390/tools/copy-arm64h.awk | 83 ++++++++++++++++++++++++++++ 5 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 arch/s390/include/uapi/Kbuild 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/include/uapi/Kbuild new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 + +# The ARM64 uapi headers under generated/uapi/arm64/ are private copies used +# internally by the s390 KVM ARM64 implementation. They contain #line +# directives and rewritten include paths and must not be shipped to userspace. +no-export-headers += arm64/%
arch/s390/tools/Makefile +5 -1
@@ -3,12 +3,16 @@ # Makefile for s390 specific build tools # +include $(srctree)/arch/s390/tools/Makefile.arm64h + kapi := arch/$(ARCH)/include/generated/asm kapi-hdrs-y := $(kapi)/facility-defs.h $(kapi)/dis-defs.h +kapi-hdrs-$(CONFIG_KVM) += $(ARM64_TARGETS) + PHONY += kapi -kapi: $(kapi-hdrs-y) +kapi: $(kapi-hdrs-y) $(kapi-hdrs-m) hostprogs += gen_facilities hostprogs += gen_opcode_table
arch/s390/tools/Makefile.arm64h new file +55 -0
55 lines not on this page · raw message
arch/s390/tools/copy-arm64h-full.awk new file +50 -0
50 lines not on this page · raw message
arch/s390/tools/copy-arm64h.awk new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v9 14/24] s390/tools: Use arm64 headers
Quoted 16 lines · Steffen Eiden
Introduce a flexible system for sharing ARM64 headers with s390 KVM. Selected arm64 headers or snippet of headers will be reachable by s390 code through
asm/header.h.Add copy-arm64h.awk that detects
ARM64_S390_COMMONmarkers 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
CONFIG_KVM.
Quoted 7 lines
Signed-off-by Steffen Eiden <[email protected]>--- arch/s390/include/uapi/Kbuild | 6 ++ arch/s390/tools/Makefile | 6 +- arch/s390/tools/Makefile.arm64h | 55 ++++++++++++++++++ arch/s390/tools/copy-arm64h-full.awk | 50 +++++++++++++++++ arch/s390/tools/copy-arm64h.awk | 83 ++++++++++++++++++++++++++++
Thanks for the updates.
Steffen Eiden
reviewerPATCH v9 15/24 KVM: s390: Use arm64 code
In reply to Steffen EidenAdd the infrastructure to extract KVM/arm64 code into s390 at build time similar to the arm64 header sharing. Add copy-arm64c.awk that 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 | 28 ++++++++++ arch/s390/kvm/arm64/copy-arm64c.awk | 82 +++++++++++++++++++++++++++++ 3 files changed, 112 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 +28 -0
@@ -0,0 +1,28 @@ +# 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 \ + 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; } + +ARM64_INC_FILES := $(foreach cfile,$(ARM64_CFILES),generated/$(basename $(cfile)).inc) + +$(addprefix $(obj)/,$(ARM64_INC_FILES)): $(obj)/generated/%.inc: $(srctree)/arch/arm64/kvm/%.c $(src)/copy-arm64c.awk FORCE + $(call if_changed,extract_inc) + +targets += $(ARM64_INC_FILES) +clean-files += generated/*.inc + +$(foreach cfile,$(basename $(ARM64_CFILES)),\ + $(eval $(obj)/$(cfile).o $(obj)/$(cfile).i $(obj)/$(cfile).s \ + $(obj)/$(cfile).ll $(obj)/$(cfile).lst: \ + $(obj)/generated/$(cfile).inc))
arch/s390/kvm/arm64/copy-arm64c.awk new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v9 16/24 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 registers 0-15
- breaking event register (BEAR)
- vector/floating point registers
between SAE executions to guarantee host consistency.
GPRs and BEAR are saved and restored in the asm functions. The other registers are handled 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 | 124 +++++++++++++++++++ arch/s390/include/asm/kvm_host_types.h | 4 + arch/s390/include/asm/sae.h | 49 ++++++++ arch/s390/include/asm/stacktrace.h | 5 + arch/s390/kernel/asm-offsets.c | 1 + arch/s390/kernel/entry.S | 22 ++++ arch/s390/tools/opcodes.txt | 3 + 8 files changed, 209 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 +124 -0
124 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 +49 -0
49 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 +22 -0
@@ -245,6 +245,28 @@ EXPORT_SYMBOL(__sie64a) EXPORT_SYMBOL(sie_exit) #endif +#if IS_ENABLED(CONFIG_KVM) +/* + * SAE calling convention: + * %r2 physical address of the SAE control block + */ +SYM_FUNC_START(sae) + stmg %r6,%r14,__SF_GPRS(%r15) # store kernel registers + STBEAR __SF_SAE_BEAR(%r15) # save breaking event address register + .insn rre,0xb9a50000,%r2,0 # Start Arm Execution + LBEAR __SF_SAE_BEAR(%r15) # restore breaking event address register + lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers + xgr %r0,%r0 # clear guest registers to + xgr %r1,%r1 # prevent speculative use + xgr %r2,%r2 + xgr %r3,%r3 + xgr %r4,%r4 + xgr %r5,%r5 + BR_EX %r14 +SYM_FUNC_END(sae) +EXPORT_SYMBOL(sae) +#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 v9 17/24 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 | 4 + arch/s390/include/asm/kvm_host_arm64.h | 209 +++++++++++++++++++++++++ 3 files changed, 219 insertions(+) create mode 100644 arch/s390/include/asm/kvm.h create mode 100644 arch/s390/include/asm/kvm_host_arm64.h
arch/s390/include/asm/kvm.h new file +6 -0
@@ -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 +4 -0
@@ -3,7 +3,11 @@#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 #define PGM_OPERATION 0x01#define PGM_PRIVILEGED_OP 0x02
arch/s390/include/asm/kvm_host_arm64.h new file +209 -0
209 lines not on this page · raw message
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v9 18/24 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
@@ -56,7 +56,9 @@ struct sclp_core_entry { u8 siif : 1; u8 sigpif : 1; u8 :3 ; -u8 reserved2[3 ]; + u8 aef: 1; + u8 :7 ; +u8 reserved2[2 ]; u8 :2 ; u8 ib : 1; u8 cei : 1;
@@ -109,6 +111,7 @@ struct sclp_info { unsigned char has_aeni : 1; unsigned char has_aisi : 1; unsigned char has_astfleie2 : 1; + unsigned char has_aef : 1;unsigned int ibc;unsigned int mtid;unsigned int mtid_cp;
arch/s390/kernel/processor.c +3 -0
@@ -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 v9 19/24 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 | 147 ++++++++++++++++++++++++++++++++++++ arch/s390/kvm/arm64/arm.h | 44 +++++++++++ arch/s390/kvm/arm64/guest.c | 90 ++++++++++++++++++++++ arch/s390/kvm/arm64/trace.h | 18 +++++ 4 files changed, 299 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 +147 -0
@@ -0,0 +1,147 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define pr_fmt (fmt) KBUILD_MODNAME ": " 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 : +case KVM_CAP_PRE_FAULT_MEMORY : + ret =1 ; +break ; +default : + ret =0 ; + } + +return ret; +} + +static u64 kvm_max_guest_address (void ) +{ +u64 max_addr; + + max_addr =min_t (u64,TASK_SIZE_MAX , sclp.hamax); + max_addr =max_t (u64, max_addr,SZ_1G -1 ); +return ALIGN_DOWN (max_addr +1 ,SZ_1G ) -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 ; +} + +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 -ENODEV ; + +return kvm_init (sizeof (struct kvm_vcpu ),0 ,THIS_MODULE ); +} + +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 +44 -0
44 lines not on this page · raw message
arch/s390/kvm/arm64/guest.c new file +90 -0
90 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 v9 20/24 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.
MAINTAINERS: Add arch/s390/include/arm64/* to KVM/s390
Implement a very basic smccc handler that (non-compliantly) is just able to stop a vcpu.
--- MAINTAINERS | 1 + arch/s390/include/arm64/kvm_emulate.h | 130 ++++++++++++++++++++++++++ arch/s390/include/arm64/kvm_nested.h | 11 +++ arch/s390/include/arm64/ptrace.h | 11 +++ arch/s390/include/arm64/sysreg.h | 13 +++ arch/s390/kvm/arm64/handle_exit.c | 127 +++++++++++++++++++++++++ arch/s390/kvm/arm64/inject_fault.c | 21 +++++ 7 files changed, 314 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
MAINTAINERS +1 -0
@@ -14374,6 +14374,7 @@ L: [email protected] S: Supported T: git git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git F: Documentation/virt/kvm/s390* +F: arch/s390/include/arm64/* F: arch/s390/include/asm/gmap_helpers.h F: arch/s390/include/asm/kvm* F: arch/s390/include/uapi/asm/kvm*
arch/s390/include/arm64/kvm_emulate.h new file +130 -0
130 lines not on this page · raw message
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 +127 -0
127 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 v9 21/24 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. Implement function (stubs) required by gmap.
--- arch/s390/kvm/arm64/arm.c | 190 ++++++++++++++++++++++++++++++++ arch/s390/kvm/arm64/arm.h | 14 +++ 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, 230 insertions(+)
arch/s390/kvm/arm64/arm.c +190 -0
@@ -7,6 +7,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
@@ -18,6 +21,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;
@@ -51,6 +56,83 @@ static u64 kvm_max_guest_address(void)return ALIGN_DOWN (max_addr +1 ,SZ_1G ) -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->arch.guest_phys_size; + +VM_EVENT (kvm,3 ,"vm created with type %lu" , type); +return 0 ; + +out_err: +debug_unregister (kvm->arch.dbf); + +return ret; +} +vm_fault_t kvm_arch_vcpu_fault (struct kvm_vcpu *vcpu,struct vm_fault *vmf) {return VM_FAULT_SIGBUS ;
@@ -62,6 +144,13 @@ long kvm_arch_dev_ioctl(struct file *filp,return -EINVAL ; } +void kvm_arch_destroy_vm (struct kvm *kvm) +{ +kvm_destroy_vcpus (kvm); +debug_unregister (kvm->arch.dbf); + kvm->arch.gmap =gmap_put (kvm->arch.gmap); +} +u32 get_kvm_ipa_limit (void ) {return fls64 (kvm_max_guest_address () +1 ) -1 ;
@@ -72,10 +161,45 @@ int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id)return 0 ; } +int kvm_arch_vcpu_create (struct kvm_vcpu *vcpu) +{ +struct kvm_sae_block *sae_block = &vcpu->arch.sae_block; +struct kvm_sae_save_area *save_area = &vcpu->arch.save_area; + +spin_lock_init (&vcpu->arch.mp_state_lock); + +/* Force users to call KVM_ARM_VCPU_INIT */ +vcpu_clear_flag (vcpu,VCPU_INITIALIZED ); + + vcpu->arch.mc =kvm_s390_new_mmu_cache (); +if (!vcpu->arch.mc) +return -ENOMEM ; + + save_area->sdo =virt_to_phys (sae_block); + + sae_block->hbasce = vcpu->kvm->arch.gmap->asce.val; + sae_block->mso =0L ; + sae_block->msl = vcpu->kvm->arch.mem_limit -1 ; + sae_block->save_area =virt_to_phys (save_area); + +VM_EVENT (vcpu->kvm,3 , +"create cpu %d at 0x%p, sae block at 0x%p, satellite at 0x%p" , + vcpu->vcpu_id, vcpu, &vcpu->arch.sae_block, + &vcpu->arch.save_area); +return 0 ; +} +void kvm_arch_vcpu_postcreate (struct kvm_vcpu *vcpu) { } +void kvm_arch_vcpu_destroy (struct kvm_vcpu *vcpu) +{ +kvm_s390_free_mmu_cache (vcpu->arch.mc); + +VCPU_EVENT (vcpu,3 ,"%s" ,"free cpu" ); +} +int kvm_arch_vcpu_ioctl_get_mpstate (struct kvm_vcpu *vcpu,struct kvm_mp_state *mp_state) {
@@ -101,6 +225,72 @@ 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) +{ +} + +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); +} + +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 +14 -0
@@ -2,6 +2,20 @@#ifndef ARCH_S390_KVM_ARM64_H #define ARCH_S390_KVM_ARM64_H +#include <linux/compiler_attributes.h> +#include <linux/kvm_host.h> + +#define VM_EVENT(d_kvm, d_loglevel, d_string, d_args...) \ + debug_sprintf_event((d_kvm)->arch.dbf, d_loglevel, \ + __stringify(KVM_DEV_NAME) ": " d_string "\n", \ + d_args) + +#define VCPU_EVENT(d_vcpu, d_loglevel, d_string, d_args...) \ + debug_sprintf_event((d_vcpu)->kvm->arch.dbf, d_loglevel, \ + __stringify(KVM_DEV_NAME) " %02d[%016llx-%016llx]: " d_string "\n", \ + (d_vcpu)->vcpu_id, (d_vcpu)->arch.sae_block.pstate, \ + (d_vcpu)->arch.sae_block.pc, d_args) + static __always_inline int kvm_is_ucontrol(struct kvm *kvm) {return 0 ;
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
@@ -13,6 +13,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)
@@ -23,6 +35,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 v9 22/24 KVM: s390: arm64: Implement vCPU IOCTLs
In reply to Steffen EidenImplement all required vCPU (arch) IOCTLs.
--- arch/s390/kvm/arm64/arm.c | 417 ++++++++++++++++++++++++++++++ arch/s390/kvm/arm64/guest.c | 45 ++++ arch/s390/kvm/arm64/handle_exit.c | 32 +++ arch/s390/kvm/arm64/handle_exit.h | 9 + arch/s390/kvm/arm64/reset.c | 71 +++++ arch/s390/kvm/arm64/trace.h | 36 ++- 6 files changed, 609 insertions(+), 1 deletion(-) create mode 100644 arch/s390/kvm/arm64/handle_exit.h create mode 100644 arch/s390/kvm/arm64/reset.c
arch/s390/kvm/arm64/arm.c +417 -0
@@ -6,11 +6,19 @@#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" #define CREATE_TRACE_POINTS #include "trace.h"
@@ -200,6 +208,22 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)VCPU_EVENT (vcpu,3 ,"%s" ,"free cpu" ); } +void kvm_arch_vcpu_load (struct kvm_vcpu *vcpu,int cpu) +{ +save_access_regs (&vcpu->arch.host_acrs[0 ]); + vcpu->cpu = cpu; + +lasrm (&vcpu->arch.save_area); +} + +void kvm_arch_vcpu_put (struct kvm_vcpu *vcpu) +{ +stiasrm (&vcpu->arch.save_area); + + vcpu->cpu =-1 ; +restore_access_regs (&vcpu->arch.host_acrs[0 ]); +} +int kvm_arch_vcpu_ioctl_get_mpstate (struct kvm_vcpu *vcpu,struct kvm_mp_state *mp_state) {
@@ -225,6 +249,399 @@ 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_test_request (KVM_REQ_VM_DEAD , vcpu)) +return -EIO ; +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); + +if (kvm_check_request (KVM_REQ_TLB_FLUSH , vcpu)) +asce_flush_tlb (vcpu->kvm->arch.gmap->asce); + } + +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; + +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 noinstr void arm_vcpu_enter_exit(phys_addr_t sae_block) +{ +guest_timing_enter_irqoff (); +guest_state_enter_irqoff (); + +/* +* External interrupts may occur while the SAE instruction is executing +* and must preempt guest execution to maintain responsiveness of the +* host. +* +* As a temporary workaround, run SAE with interrupts enabled so that any +* interrupt is taken via the normal host interrupt path rather than +* being subsumed inside the SAE window. +*/ +raw_local_irq_enable (); +sae (sae_block); +raw_local_irq_disable (); + +guest_state_exit_irqoff (); +guest_timing_exit_irqoff (); +} + +/** 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 an 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 ; + kvm_run->exit_reason =KVM_EXIT_UNKNOWN ; +while (ret >0 ) { + ret =kvm_xfer_to_guest_mode_handle_work (vcpu); +if (!ret) + ret =1 ; + +if (ret >0 ) + ret =check_vcpu_requests (vcpu); + + vcpu->arch.sae_block.icptr =0 ; + +local_irq_disable (); +xfer_to_guest_mode_prepare (); +/* +* The full memory barrier in smp_store_mb() orders the mode +* store against the kvm_request_pending() check below, so +* any pending kick is visible before we decide to enter the +* guest. +*/ +smp_store_mb (vcpu->mode,IN_GUEST_MODE ); + +if (ret <=0 ||kvm_request_pending (vcpu) || +xfer_to_guest_mode_work_pending ()) { + vcpu->mode =OUTSIDE_GUEST_MODE ; +local_irq_enable (); +continue ; + } + +trace_kvm_entry (*vcpu_pc (vcpu)); + +adjust_pc (vcpu); + +arm_vcpu_enter_exit (virt_to_phys (&vcpu->arch.sae_block)); + + vcpu->mode =OUTSIDE_GUEST_MODE ; + vcpu->stat.exits++; + +local_irq_enable (); +trace_kvm_exit (kvm_vcpu_trap_get_class (vcpu), *vcpu_pc (vcpu)); + + ret =handle_exit (vcpu); + } + +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 -0
51 lines not on this page · raw message
arch/s390/kvm/arm64/handle_exit.c +32 -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 *);#define PSCI_0_2_FN_SYSTEM_OFF 0x84000008
@@ -84,6 +86,36 @@ static int handle_trap_exceptions(struct kvm_vcpu *vcpu)return exit_handler (vcpu); } +/* +* 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); + vcpu->run->exit_reason =KVM_EXIT_FAIL_ENTRY ; + ret =0 ; +break ; +case SAE_ICPTR_GUEST_ADDRESS_SIZE : +case SAE_ICPTR_HOST_ACCESS_EXCEPTION : +case SAE_ICPTR_SYNCHRONOUS_EXCEPTION : + ret =handle_trap_exceptions (vcpu); +break ; +default : + vcpu->run->exit_reason =KVM_EXIT_FAIL_ENTRY ; + ret =0 ; + } +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 +71 -0
71 lines not on this page · raw message
arch/s390/kvm/arm64/trace.h +35 -1
@@ -5,7 +5,41 @@#include <linux/tracepoint.h> #undef TRACE_SYSTEM -#define TRACE_SYSTEM kvm +#define TRACE_SYSTEM kvm_arm64 +#undef TRACE_SYSTEM_VAR +#define TRACE_SYSTEM_VAR kvm_arm64 + +TRACE_EVENT (kvm_entry, + TP_PROTO(unsigned long vcpu_pc), +TP_ARGS (vcpu_pc), + +TP_STRUCT__entry ( + __field(unsigned long, vcpu_pc) + ), + + TP_fast_assign(__entry->vcpu_pc = vcpu_pc;), + +TP_printk ("PC: 0x%016lx" , __entry->vcpu_pc) +); + +TRACE_EVENT (kvm_exit, + TP_PROTO(unsigned int esr_ec, unsigned long vcpu_pc), +TP_ARGS (esr_ec, vcpu_pc), + +TP_STRUCT__entry ( + __field(unsigned int, esr_ec ) + __field(unsigned long, vcpu_pc ) + ), + +TP_fast_assign ( + __entry->esr_ec = esr_ec; + __entry->vcpu_pc = vcpu_pc; + ), + +TP_printk ("HSR_EC: 0x%04x, PC: 0x%016lx" , + __entry->esr_ec, + __entry->vcpu_pc) +);#endif /* KVM_ARM64_TRACE_KVM_H */
Signature · 1 line
2.53.0
Steffen Eiden
reviewerPATCH v9 23/24 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. Add pre-fault handler.
--- arch/s390/kvm/arm64/handle_exit.c | 2 + arch/s390/kvm/arm64/mmio.c | 15 +++ arch/s390/kvm/arm64/mmu.c | 200 ++++++++++++++++++++++++++++++ arch/s390/kvm/arm64/trace.h | 49 ++++++++ 4 files changed, 266 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
@@ -62,6 +62,8 @@ static int kvm_handle_unknown_ec(struct kvm_vcpu *vcpu)static exit_handle_fn arm_exit_handlers[] = { [0 ... ESR_ELx_EC_MAX] = kvm_handle_unknown_ec, [ESR_ELx_EC_HVC64] = handle_hvc, + [ESR_ELx_EC_IABT_LOW] = kvm_handle_guest_abort, + [ESR_ELx_EC_DABT_LOW] = kvm_handle_guest_abort, };static exit_handle_fn kvm_get_exit_handler (struct kvm_vcpu *vcpu)
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 +200 -0
200 lines not on this page · raw message
arch/s390/kvm/arm64/trace.h +49 -0
55 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v9 23/24] KVM: s390: arm64: Implement basic page fault handler
Review
Quoted 9 lines
(quoted diff) +8
-0+ /* + * Check for a cache maintenance operation. Assume the guest is + * cautious and skip instruction + */ + if (kvm_is_error_hva(hva) && kvm_vcpu_dabt_is_cm(vcpu)) { + kvm_incr_pc(vcpu); + ret = 1; + goto out_unlock;
Hi Steffen,
[Adding Lorenzo Stoakes to Cc]
I see this function fails to build on top of linux-next, as the kvm_vcpu_dabt_is_cm() function was removed by commit 18b94675b1fb ("KVM: arm64: Use ESR helpers in guest abort handling").
I used this patch to make it build, but I'm not sure if this is the correct fix:
arch/s390/kvm/arm64/mmu.c +2 -1
@@ -119,6 +119,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) hva =gfn_to_hva_memslot_prot (memslot, gfn, &writable); write_fault =kvm_s390_cur_gmap_fault_is_write (vcpu);if (kvm_is_error_hva (hva) || (write_fault && !writable)) { +unsigned long esr =kvm_vcpu_get_esr (vcpu); ret = -ENOEXEC ;/* * The guest has put either its instructions or its page-tables
@@ -143,7 +144,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)* Check for a cache maintenance operation. Assume the guest is * cautious and skip instruction */ -if (kvm_is_error_hva (hva) &&kvm_vcpu_dabt_is_cm (vcpu)) { +if (kvm_is_error_hva (hva) &&esr_dabt_is_cm (esr)) {kvm_incr_pc (vcpu); ret =1 ; goto out_unlock;
Arnd
Re: [PATCH v9 23/24] KVM: s390: arm64: Implement basic page fault handler
Quoted 11 lines · Arnd Bergmann
Review
Quoted 8 lines
(quoted diff) +8
-0+ /* + * Check for a cache maintenance operation. Assume the guest is + * cautious and skip instruction + */ + if (kvm_is_error_hva(hva) && kvm_vcpu_dabt_is_cm(vcpu)) { + kvm_incr_pc(vcpu); + ret = 1; + goto out_unlock;Hi Steffen,
Quoted 5 lines
[Adding Lorenzo Stoakes to Cc]
I see this function fails to build on top of linux-next, as the
kvm_vcpu_dabt_is_cm()function was removed by commit18b94675b1fb("KVM: arm64: Use ESR helpers in guest abort handling").
Another ones: after 34cfa9b3af17 ("KVM: arm64: Implement KVM_PRE_FAULT_MEMORY"), we are now missing a kvm_arch_pre_fault_allowed() definition in arch/s390/kvm/arm64/mmu.c:
ERROR: modpost: arch/s390/kvm/arm64/kvm-arm64.ko: symbol 'kvm_arch_pre_fault_allowed' undefined!
I copied the arm64 version without the pkvm reference to make it build for me.
Arnd
arch/s390/kvm/arm64/mmu.c +8 -0
@@ -179,6 +179,14 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)return ret; } +int kvm_arch_pre_fault_allowed (struct kvm_vcpu *vcpu) +{ +if (!kvm_vcpu_initialized (vcpu)) +return -ENOEXEC ; + +return 0 ; +} +long kvm_arch_vcpu_pre_fault_memory (struct kvm_vcpu *vcpu,struct kvm_pre_fault_memory *range) {struct guest_fault f = { .gfn =gpa_to_gfn (range->gpa), };
Re: [PATCH v9 23/24] KVM: s390: arm64: Implement basic page fault handler
Quoted 17 lines · Arnd Bergmann
Another ones: after
34cfa9b3af17("KVM: arm64: ImplementKVM_PRE_FAULT_MEMORY"), we are now missing akvm_arch_pre_fault_allowed()definition inarch/s390/kvm/arm64/mmu.c:ERROR: modpost:
arch/s390/kvm/arm64/kvm-arm64.ko: symbol 'kvm_arch_pre_fault_allowed' undefined!I copied the arm64 version without the pkvm reference to make it build for me.
Arnd
arch/s390/kvm/arm64/mmu.c +0
-0@@ -179,6 +179,14 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)return ret;
arch/s390/kvm/arm64/mmu.c int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) · line 189
Quoted 10 lines
arch/s390/kvm/arm64/mmu.c +8
-0} +int kvm_arch_pre_fault_allowed (struct kvm_vcpu *vcpu) +{ +if (!kvm_vcpu_initialized (vcpu)) +return -ENOEXEC ; + +return 0 ; +} +
Ah the s390 <-> kvm emulation stuff.
Yep if it's meant to behave like arm64 then that should be correct.
It's odd to me that pre-faulting was not previously implemented for actual-arm64 but was added as part of the virtualised s390/arm64 thing automatically :)
Not sure if this implementation requires what s390 does with:
+int kvm_arch_pre_fault_allowed(struct kvm_vcpu *vcpu) +{
+ if (kvm_is_ucontrol(vcpu->kvm))
+ return -EINVAL;
+
+ return 0;
+}
Or both conditions? One for the s390 guys.
--
Cheers, Lorenzo
Steffen Eiden
reviewerRe: [PATCH v9 23/24] KVM: s390: arm64: Implement basic page fault handler
Quoted 20 lines · Lorenzo Stoakes (ARM)
Quoted 19 lines · Arnd Bergmann
Another ones: after
34cfa9b3af17("KVM: arm64: ImplementKVM_PRE_FAULT_MEMORY"), we are now missing akvm_arch_pre_fault_allowed()definition inarch/s390/kvm/arm64/mmu.c:ERROR: modpost:
arch/s390/kvm/arm64/kvm-arm64.ko: symbol 'kvm_arch_pre_fault_allowed' undefined!I copied the arm64 version without the pkvm reference to make it build for me.
Arnd
arch/s390/kvm/arm64/mmu.c +0
-0@@ -179,6 +179,14 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)return ret; }
Quoted 8 lines
arch/s390/kvm/arm64/mmu.c int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) · line 189
Quoted 8 lines
arch/s390/kvm/arm64/mmu.c +8
-0+int kvm_arch_pre_fault_allowed (struct kvm_vcpu *vcpu) +{ +if (!kvm_vcpu_initialized (vcpu)) +return -ENOEXEC ; + +return 0 ; +} +
thanks. This must have slipped through somehow.
Quoted 2 lines
Ah the s390 <-> kvm emulation stuff.
no, its not emulation :)
We use a hardware based acclearaion approach.
arch/s390/kvm/arm64/mmu.c int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)
Quoted 12 lines
Yep if it's meant to behave like arm64 then that should be correct.
It's odd to me that pre-faulting was not previously implemented for actual-arm64 but was added as part of the virtualised s390/arm64 thing automatically :)
Not sure if this implementation requires what s390 does with:
arch/s390/kvm/arm64/mmu.c +4
-0+int kvm_arch_pre_fault_allowed (struct kvm_vcpu *vcpu) +{ +if (kvm_is_ucontrol (vcpu->kvm)) +return -EINVAL ;
no, ucontrol is a feature only for native s390 guests. kvm_arm64 on s390 always evaluates kvm_is_ucontrol() to false if it appears in shared (between both s390 KVMs) code.
Quoted 6 lines
arch/s390/kvm/arm64/mmu.c +3
-0+ +return 0 ; +}Or both conditions? One for the s390 guys.
so just the initialized test.
thanks
Steffen
Re: [PATCH v9 23/24] KVM: s390: arm64: Implement basic page fault handler
Quoted 6 lines · Steffen Eiden
Quoted 1 line · Lorenzo Stoakes (ARM)
Ah the s390 <-> kvm emulation stuff.
no, its not emulation :)
We use a hardware based acclearaion approach.
Sorry my apologies, I did know this but mr. brain didn't engage there :) rushing through mails (and been sick these last few days)...
Quoted 3 lines
Quoted 2 lines
Or both conditions? One for the s390 guys.
so just the initialized test.
OK cool, so Arnd's suggestion as-is, then. LGTM!
--
Cheers, Lorenzo
Steffen Eiden
reviewerRe: [PATCH v9 23/24] KVM: s390: arm64: Implement basic page fault handler
In reply to Arnd BergmannQuoted 12 lines · Arnd Bergmann
Review
Quoted 9 lines
(quoted diff) +8
-0+ /* + * Check for a cache maintenance operation. Assume the guest is + * cautious and skip instruction + */ + if (kvm_is_error_hva(hva) && kvm_vcpu_dabt_is_cm(vcpu)) { + kvm_incr_pc(vcpu); + ret = 1; + goto out_unlock;Hi Steffen,
Quoted 9 lines
[Adding Lorenzo Stoakes to Cc]
I see this function fails to build on top of linux-next, as the
kvm_vcpu_dabt_is_cm()function was removed by commit18b94675b1fb("KVM: arm64: Use ESR helpers in guest abort handling").I used this patch to make it build, but I'm not sure if this is the correct fix:
yes, it is the functional correct fix.
arch/s390/kvm/arm64/mmu.c int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) · line 122
Quoted 9 lines
arch/s390/kvm/arm64/mmu.c +1
-0@@ -119,6 +119,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) hva =gfn_to_hva_memslot_prot (memslot, gfn, &writable); write_fault =kvm_s390_cur_gmap_fault_is_write (vcpu);if (kvm_is_error_hva (hva) || (write_fault && !writable)) { +unsigned long esr =kvm_vcpu_get_esr (vcpu);
move this on top of the function. I need the esr in the function for the full pfault handling later anyways.
arch/s390/kvm/arm64/mmu.c int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) · line 150
Quoted 13 lines
arch/s390/kvm/arm64/mmu.c +1
-1ret = -ENOEXEC ;/* * The guest has put either its instructions or its page-tables @@ -143,7 +144,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)* Check for a cache maintenance operation. Assume the guest is * cautious and skip instruction */ -if (kvm_is_error_hva (hva) &&kvm_vcpu_dabt_is_cm (vcpu)) { +if (kvm_is_error_hva (hva) &&esr_dabt_is_cm (esr)) {kvm_incr_pc (vcpu); ret =1 ; goto out_unlock;
Steffen
Re: [PATCH v9 23/24] KVM: s390: arm64: Implement basic page fault handler
In reply to Arnd BergmannQuoted 24 lines · Arnd Bergmann
Hi Steffen,
[Adding Lorenzo Stoakes to Cc]
I see this function fails to build on top of linux-next, as the
kvm_vcpu_dabt_is_cm()function was removed by commit18b94675b1fb("KVM: arm64: Use ESR helpers in guest abort handling").I used this patch to make it build, but I'm not sure if this is the correct fix:
arch/s390/kvm/arm64/mmu.c +1
-0@@ -119,6 +119,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) hva =gfn_to_hva_memslot_prot (memslot, gfn, &writable); write_fault =kvm_s390_cur_gmap_fault_is_write (vcpu);if (kvm_is_error_hva (hva) || (write_fault && !writable)) { +unsigned long esr =kvm_vcpu_get_esr (vcpu); ret = -ENOEXEC ;/* * The guest has put either its instructions or its page-tables
arch/s390/kvm/arm64/mmu.c int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) · line 150
Quoted 8 lines
arch/s390/kvm/arm64/mmu.c +1
-1@@ -143,7 +144,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)* Check for a cache maintenance operation. Assume the guest is * cautious and skip instruction */ -if (kvm_is_error_hva (hva) &&kvm_vcpu_dabt_is_cm (vcpu)) { +if (kvm_is_error_hva (hva) &&esr_dabt_is_cm (esr)) {kvm_incr_pc (vcpu); ret =1 ; goto out_unlock;
Thanks for the report!
The original function was:
static inline bool kvm_vcpu_dabt_is_cm(const struct kvm_vcpu *vcpu)
{
return !!(kvm_vcpu_get_esr(vcpu) & ESR_ELx_CM);
}And esr_dabt_is_cm() is:
static __always_inline bool esr_dabt_is_cm(unsigned long esr)
{
return esr & ESR_ELx_CM;
}So looks good to me at a glance!
--
Cheers, Lorenzo
Steffen Eiden
reviewerPATCH v9 24/24 KVM: s390: arm64: Integrate arm on s390
In reply to Steffen EidenAdd all Kbuild/Makefile configurations to build a second KVM module on s390 implementing the arm64 KVM API. The new module is named kvm_arm64.
Symbol conflicts with kvm_s390 are prevented by localising all internal symbols in kvm_arm64 when compiled as built-in (=y): kvm-unnamespaced.o holds all constituent objects. objcopy --localize-symbols then produces kvm-namespaced.o which is what kvm-arm64.o resolves to. For =m the normal module symbol scoping applies and no localisation step is needed.
Because the %-arm64.o pattern targets do not match any kvm-arm64-y entry, kbuild would derive a wrong KBUILD_MODNAME (e.g. "kvm_main_arm64") and a wrong KBUILD_MODFILE for the virt/kvm and gmap copies.
--- arch/s390/kvm/Kconfig | 25 +++++--- arch/s390/kvm/Makefile | 1 + arch/s390/kvm/arm64/Makefile | 110 +++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 9 deletions(-) create mode 100644 arch/s390/kvm/arm64/Makefile
arch/s390/kvm/Kconfig +16 -9
@@ -30,15 +30,22 @@ config KVM select KVM_MMU_LOCKLESS_AGING select KVM_GENERIC_PRE_FAULT_MEMORY help - Support hosting paravirtualized 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. + Enable support for hosting virtualized, hardware-accelerated + virtual machines via two modules: kvm and kvm_arm64. + + The kvm module provides access to host hardware-accelerated s390 + guests using the Start Interpretive Execution (SIE) instruction via a + character device node named /dev/kvm. This requires a 64-bit machine + (hardware model). + + The kvm_arm64 module provides access to host hardware-accelerated + arm64 guests using the Start ARM Execution (SAE) instruction via a + character device node named /dev/kvm_arm64. This requires hardware + models that support the Arm execution facility (AEF). + + To compile this driver as a module, choose M here. The module will be + called kvm for the SIE acceleration and kvm_arm64 for the SAE + acceleration. If unsure, say N.
arch/s390/kvm/Makefile +1 -0
@@ -4,3 +4,4 @@ # Copyright IBM Corp. 2008 obj-$(CONFIG_KVM) += s390/ +obj-$(CONFIG_KVM) += arm64/
arch/s390/kvm/arm64/Makefile new file +110 -0
110 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: (subset) [PATCH v9 00/24] KVM: s390: Introduce arm64 KVM
In reply to Steffen EidenQuoted 9 lines · Steffen Eiden
Introduce arm-on-s390. Enable KVM-accelerated ARM CPU virtualisation on s390.
The new KVM functionally depends on KVM/vfio: Use file-based reference counting for KVM [5] The series itself should apply w/o those.
For the original, now partially outdated, cover letter, have a look at versions one to three [1].
[...]
Applied to next, thanks!
[05/24] arm64: ptrace: Use constants for compat register numbers
commit: 295d3df9b1e425099a4eb37954a02c4a08fdb496
[06/24] arm64: sysreg: Convert SPSR_ELx to automatic register generation
commit: d3d78520068779779e1ed7aa0dd8a3ce63e1ca43
[07/24] KVM: arm64: Access elements of vcpu_gp_regs individually
commit: 29d92585ab987bb80b1e78d811aaea2a8db86e62
[08/24] KVM: arm64: Use accessor functions for core regs
commit: 89ed62818f10e38e64fea46d43ee6455a1beb647
[09/24] arm64: Prepare sharing arm64 headers with s390
commit: df6a70516adec8b7f5fa49e1755d8ee33d980d9c
[10/24] arm64: Share arm64 headers with s390
commit: c7e18ba462536e870b0ff4deca581babcac9135b
[11/24] KVM: arm64: Share arm64 code with s390
commit: dcb776bfcccc9662001a75b99dbfbef55f46eb31Note that there were a few conflicts. Please check that I resolved them correctly.
Cheers,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Steffen Eiden
reviewerRe: (subset) [PATCH v9 00/24] KVM: s390: Introduce arm64 KVM
Quoted 28 lines · Marc Zyngier
Quoted 9 lines · Steffen Eiden
Introduce arm-on-s390. Enable KVM-accelerated ARM CPU virtualisation on s390.
The new KVM functionally depends on KVM/vfio: Use file-based reference counting for KVM [5] The series itself should apply w/o those.
For the original, now partially outdated, cover letter, have a look at versions one to three [1].
[...]
Applied to next, thanks!
[05/24] arm64: ptrace: Use constants for compat register numbers
commit: 295d3df9b1e425099a4eb37954a02c4a08fdb496 [06/24] arm64: sysreg: Convert SPSR_ELx to automatic register generation commit: d3d78520068779779e1ed7aa0dd8a3ce63e1ca43 [07/24] KVM: arm64: Access elements of vcpu_gp_regs individually commit: 29d92585ab987bb80b1e78d811aaea2a8db86e62 [08/24] KVM: arm64: Use accessor functions for core regs commit: 89ed62818f10e38e64fea46d43ee6455a1beb647 [09/24] arm64: Prepare sharing arm64 headers with s390 commit: df6a70516adec8b7f5fa49e1755d8ee33d980d9c [10/24] arm64: Share arm64 headers with s390 commit: c7e18ba462536e870b0ff4deca581babcac9135b [11/24] KVM: arm64: Share arm64 code with s390 commit: dcb776bfcccc9662001a75b99dbfbef55f46eb31
Quoted 2 lines
Note that there were a few conflicts. Please check that I resolved them correctly.
After rebasing on those the arm-on-s390 part does not build anymore :(
We are missing the definition of
static __always_inline bool esr_abt_is_s1ptw(unsigned long esr)
quick fix:
on top of [10/24] arm64: Share arm64 headers with s390
arch/arm64/include/asm/kvm_emulate.h +3 -0
@@ -367,10 +367,13 @@ static __always_inline u64 kvm_vcpu_get_esr(const struct kvm_vcpu *vcpu)return vcpu->arch.fault.esr_el2; } +#if ARM64_S390_COMMON ==1 static __always_inline bool esr_abt_is_s1ptw(unsigned long esr) {return esr & ESR_ELx_S1PTW; } + +#endif /* ARM64_S390_COMMON == 1 */ static __always_inline bool esr_abt_is_exec_fault(unsigned long esr) {
A cleaner solution it to move this defenition just below void kvm_vcpu_wfi(struct kvm_vcpu *vcpu) in [09/24] arm64: Prepare sharing arm64 headers with s390 and expand the shared region in the following patch.
I can send the two fixup patches as a reply here for this tomorrow or later today if you want.
Steffen
Re: (subset) [PATCH v9 00/24] KVM: s390: Introduce arm64 KVM
Quoted 3 lines · Steffen Eiden
On Thu, Oct 01, 2026 at 12:04:51PM +0100, Marc Zyngier wrote:
quick fix:
Ah, I was about to send the same thing.
Quoted 2 lines
I can send the two fixup patches as a reply here for this tomorrow or later today if you want.
My build bot is churning away looking for more corner cases. I initially had the wrong base, but with this one and the other two I sent, things are starting to look good. I'll keep it running over night, but if you don't hear from me for any additional build regressions in the next hour, it's probably fine.
Arnd
Re: (subset) [PATCH v9 00/24] KVM: s390: Introduce arm64 KVM
Quoted 10 lines · Arnd Bergmann
Quoted 2 lines · Steffen Eiden
I can send the two fixup patches as a reply here for this tomorrow or later today if you want.
My build bot is churning away looking for more corner cases. I initially had the wrong base, but with this one and the other two I sent, things are starting to look good. I'll keep it running over night, but if you don't hear from me for any additional build regressions in the next hour, it's probably fine.
No more build failures overnight, but after changing to gcc-10.5.0, I get link failures for the namespaced module:
__s390_indirect_jump_r1' referenced in section .text' of arch/s390/kvm/arm64/kvm-namespaced.o: defined in discarded section .text.__s390_indirect_jump_r1[__s390_indirect_jump_r1]' of arch/s390/kvm/arm64/kvm-namespaced.o __s390_indirect_jump_r4' referenced in section .text' of arch/s390/kvm/arm64/kvm-namespaced.o: defined in discarded section .text.__s390_indirect_jump_r4[__s390_indirect_jump_r4]' of arch/s390/kvm/arm64/kvm-namespaced.o __s390_indirect_jump_r14' referenced in section .text' of arch/s390/kvm/arm64/kvm-namespaced.o: defined in discarded section .text.__s390_indirect_jump_r14[__s390_indirect_jump_r14]' of arch/s390/kvm/arm64/kvm-namespaced.o __s390_indirect_jump_r1' referenced in section .text' of arch/s390/kvm/arm64/kvm-namespaced.o: defined in discarded section .text.__s390_indirect_jump_r1[__s390_indirect_jump_r1]' of arch/s390/kvm/arm64/kvm-namespaced.o __s390_indirect_jump_r4' referenced in section .text' of arch/s390/kvm/arm64/kvm-namespaced.o: defined in discarded section .text.__s390_indirect_jump_r4[__s390_indirect_jump_r4]' of arch/s390/kvm/arm64/kvm-namespaced.o __s390_indirect_jump_r14' referenced in section .text' of arch/s390/kvm/arm64/kvm-namespaced.o: defined in discarded section .text.__s390_indirect_jump_r14[__s390_indirect_jump_r14]' of arch/s390/kvm/arm64/kvm-namespaced.o
See https://pastebin.com/raw/pJYu8UAb for the .config that triggered it. Later compilers get CONFIG_EXPOLINE_EXTERN=y, which avoids the problem, so an easy workaround would be to make the module depend on that symbol:
arch/s390/kvm/Kconfig +1 -0
@@ -19,6 +19,7 @@ if VIRTUALIZATION config KVM def_tristate y prompt "Kernel-based Virtual Machine (KVM) support" + depends on !EXPOLINE || EXPOLINE_EXTERN select HAVE_KVM_CPU_RELAX_INTERCEPT select KVM_ASYNC_PF select KVM_ASYNC_PF_SYNC
Arnd
Marc Zyngier
maintainerRe: (subset) [PATCH v9 00/24] KVM: s390: Introduce arm64 KVM
In reply to Steffen EidenQuoted 30 lines · Steffen Eiden
Quoted 28 lines · Marc Zyngier
Quoted 9 lines · Steffen Eiden
Introduce arm-on-s390. Enable KVM-accelerated ARM CPU virtualisation on s390.
The new KVM functionally depends on KVM/vfio: Use file-based reference counting for KVM [5] The series itself should apply w/o those.
For the original, now partially outdated, cover letter, have a look at versions one to three [1].
[...]
Applied to next, thanks!
[05/24] arm64: ptrace: Use constants for compat register numbers
commit: 295d3df9b1e425099a4eb37954a02c4a08fdb496 [06/24] arm64: sysreg: Convert SPSR_ELx to automatic register generation commit: d3d78520068779779e1ed7aa0dd8a3ce63e1ca43 [07/24] KVM: arm64: Access elements of vcpu_gp_regs individually commit: 29d92585ab987bb80b1e78d811aaea2a8db86e62 [08/24] KVM: arm64: Use accessor functions for core regs commit: 89ed62818f10e38e64fea46d43ee6455a1beb647 [09/24] arm64: Prepare sharing arm64 headers with s390 commit: df6a70516adec8b7f5fa49e1755d8ee33d980d9c [10/24] arm64: Share arm64 headers with s390 commit: c7e18ba462536e870b0ff4deca581babcac9135b [11/24] KVM: arm64: Share arm64 code with s390 commit: dcb776bfcccc9662001a75b99dbfbef55f46eb31
Quoted 5 lines
Quoted 2 lines
Note that there were a few conflicts. Please check that I resolved them correctly.
After rebasing on those the arm-on-s390 part does not build anymore :(
Well, that's sort of expected. The kvmarm tree doesn't have the S390 stuff yet, and contains tons of new stuff.
Quoted 29 lines
We are missing the definition of
static__always_inlineboolesr_abt_is_s1ptw(unsigned long esr)quick fix:
on top of [10/24] arm64: Share arm64 headers with s390
arch/arm64/include/asm/kvm_emulate.h +3
-0@@ -367,10 +367,13 @@ static __always_inline u64 kvm_vcpu_get_esr(const struct kvm_vcpu *vcpu)return vcpu->arch.fault.esr_el2; } +#if ARM64_S390_COMMON ==1 static __always_inline bool esr_abt_is_s1ptw(unsigned long esr) {return esr & ESR_ELx_S1PTW; } + +#endif /* ARM64_S390_COMMON == 1 */ static __always_inline bool esr_abt_is_exec_fault(unsigned long esr) {
Quoted 4 lines
A cleaner solution it to move this defenition just below void
kvm_vcpu_wfi(struct kvm_vcpu *vcpu)in [09/24] arm64: Prepare sharing arm64 headers with s390 and expand the shared region in the following patch.
I'm redoing the merge and fixing it as follows (note that the ARM64_S390_COMMON guards are already present):
@@ -336,16 +367,6 @@ static __always_inline u64 kvm_vcpu_get_esr(const struct kvm_vcpu *vcpu)
return vcpu->arch.fault.esr_el2;
}
-static __always_inline bool esr_abt_is_s1ptw(unsigned long esr)
-{
- return esr & ESR_ELx_S1PTW;
-}
-
-static __always_inline bool esr_abt_is_exec_fault(unsigned long esr) -{
- return esr_trap_is_iabt(esr) && !esr_abt_is_s1ptw(esr);
-}
-
static inline bool guest_hyp_wfx_traps_enabled(const struct kvm_vcpu *vcpu) {
u64 esr = kvm_vcpu_get_esr(vcpu);
@@ -389,6 +410,12 @@ static inline u64 kvm_vcpu_get_disr(const struct kvm_vcpu *vcpu)
return vcpu->arch.fault.disr_el1;
}
+#if ARM64_S390_COMMON == 1
+static __always_inline bool esr_abt_is_s1ptw(unsigned long esr)
+{
+ return esr & ESR_ELx_S1PTW;
+}
+
static inline u32 kvm_vcpu_hvc_get_imm(const struct kvm_vcpu *vcpu)
{
return kvm_vcpu_get_esr(vcpu) & ESR_ELx_xVC_IMM_MASK;
@@ -456,6 +483,13 @@ 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 == 1 */
+
+static __always_inline bool esr_abt_is_exec_fault(unsigned long esr) +{
+ return esr_trap_is_iabt(esr) && !esr_abt_is_s1ptw(esr);
+}
+
static inline
bool kvm_vcpu_trap_is_permission_fault(const struct kvm_vcpu *vcpu) {
Does this work for you?
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Steffen Eiden
reviewerRe: (subset) [PATCH v9 00/24] KVM: s390: Introduce arm64 KVM
Quoted 32 lines · Marc Zyngier
Quoted 30 lines · Steffen Eiden
Quoted 28 lines · Marc Zyngier
Quoted 9 lines · Steffen Eiden
Introduce arm-on-s390. Enable KVM-accelerated ARM CPU virtualisation on s390.
The new KVM functionally depends on KVM/vfio: Use file-based reference counting for KVM [5] The series itself should apply w/o those.
For the original, now partially outdated, cover letter, have a look at versions one to three [1].
[...]
Applied to next, thanks!
[05/24] arm64: ptrace: Use constants for compat register numbers
commit: 295d3df9b1e425099a4eb37954a02c4a08fdb496 [06/24] arm64: sysreg: Convert SPSR_ELx to automatic register generation commit: d3d78520068779779e1ed7aa0dd8a3ce63e1ca43 [07/24] KVM: arm64: Access elements of vcpu_gp_regs individually commit: 29d92585ab987bb80b1e78d811aaea2a8db86e62 [08/24] KVM: arm64: Use accessor functions for core regs commit: 89ed62818f10e38e64fea46d43ee6455a1beb647 [09/24] arm64: Prepare sharing arm64 headers with s390 commit: df6a70516adec8b7f5fa49e1755d8ee33d980d9c [10/24] arm64: Share arm64 headers with s390 commit: c7e18ba462536e870b0ff4deca581babcac9135b [11/24] KVM: arm64: Share arm64 code with s390 commit: dcb776bfcccc9662001a75b99dbfbef55f46eb31
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
Note that there were a few conflicts. Please check that I resolved them correctly.
After rebasing on those the arm-on-s390 part does not build anymore :(
Well, that's sort of expected. The kvmarm tree doesn't have the S390 stuff yet, and contains tons of new stuff.
yes, but sometimes I like to dream
Quoted 83 lines
Quoted 29 lines
We are missing the definition of
static__always_inlineboolesr_abt_is_s1ptw(unsigned long esr)quick fix:
on top of [10/24] arm64: Share arm64 headers with s390
arch/arm64/include/asm/kvm_emulate.h +3
-0@@ -367,10 +367,13 @@ static __always_inline u64 kvm_vcpu_get_esr(const struct kvm_vcpu *vcpu)return vcpu->arch.fault.esr_el2; } +#if ARM64_S390_COMMON ==1 static __always_inline bool esr_abt_is_s1ptw(unsigned long esr) {return esr & ESR_ELx_S1PTW; } + +#endif /* ARM64_S390_COMMON == 1 */ static __always_inline bool esr_abt_is_exec_fault(unsigned long esr) {Quoted 4 lines
A cleaner solution it to move this defenition just below void
kvm_vcpu_wfi(struct kvm_vcpu *vcpu)in [09/24] arm64: Prepare sharing arm64 headers with s390 and expand the shared region in the following patch.I'm redoing the merge and fixing it as follows (note that the
ARM64_S390_COMMONguards are already present):(quoted diff) +13
-10@@ -336,16 +367,6 @@ static __always_inline u64 kvm_vcpu_get_esr(const struct kvm_vcpu *vcpu) return vcpu->arch.fault.esr_el2; } -static __always_inline bool esr_abt_is_s1ptw(unsigned long esr) -{ - return esr & ESR_ELx_S1PTW; -} - -static __always_inline bool esr_abt_is_exec_fault(unsigned long esr) -{ - return esr_trap_is_iabt(esr) && !esr_abt_is_s1ptw(esr); -} - static inline bool guest_hyp_wfx_traps_enabled(const struct kvm_vcpu *vcpu) { u64 esr = kvm_vcpu_get_esr(vcpu);@@ -389,6 +410,12 @@ static inline u64 kvm_vcpu_get_disr(const struct kvm_vcpu *vcpu) return vcpu->arch.fault.disr_el1; } +#if ARM64_S390_COMMON == 1 +static __always_inline bool esr_abt_is_s1ptw(unsigned long esr) +{ + return esr & ESR_ELx_S1PTW; +} + static inline u32 kvm_vcpu_hvc_get_imm(const struct kvm_vcpu *vcpu) { return kvm_vcpu_get_esr(vcpu) & ESR_ELx_xVC_IMM_MASK;@@ -456,6 +483,13 @@ 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 == 1 */ + +static __always_inline bool esr_abt_is_exec_fault(unsigned long esr) +{ + return esr_trap_is_iabt(esr) && !esr_abt_is_s1ptw(esr); +} + static inline bool kvm_vcpu_trap_is_permission_fault(const struct kvm_vcpu *vcpu) {
Quoted 2 lines
Does this work for you?
Yes the positioning of the functions look good. It builds on top of kvmarm/next + this (sightly relocated (line numbes are different) patch
+ arm on s390 stuff.
I'll work on a verification tool for you guys to make this process easier.
Thank you.
Steffen
Marc Zyngier
maintainerRe: (subset) [PATCH v9 00/24] KVM: s390: Introduce arm64 KVM
Quoted 4 lines · Steffen Eiden
Yes the positioning of the functions look good. It builds on top of kvmarm/next + this (sightly relocated (line numbes are different) patch
+ arm on s390 stuff.
Cool. I've now pushed out the rebuilt kvmarm/next branch with this, and hopefully it will make it into -next today.
Let me know if anything else is amiss.
Quoted 2 lines
I'll work on a verification tool for you guys to make this process easier.
I guess the ultimate verification tool is to build s390 with the rest of the patches, which I've just done. This doesn't lead to any error that wasn't already reported.
Thanks,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Steffen Eiden
reviewerRe: (subset) [PATCH v9 00/24] KVM: s390: Introduce arm64 KVM
Quoted 10 lines · Marc Zyngier
Quoted 4 lines · Steffen Eiden
Yes the positioning of the functions look good. It builds on top of kvmarm/next + this (sightly relocated (line numbes are different) patch
+ arm on s390 stuff.Cool. I've now pushed out the rebuilt kvmarm/next branch with this, and hopefully it will make it into -next today.
Quoted 8 lines
Let me know if anything else is amiss.
Quoted 2 lines
I'll work on a verification tool for you guys to make this process easier.
I guess the ultimate verification tool is to build s390 with the rest of the patches, which I've just done. This doesn't lead to any error that wasn't already reported.
Yes. Fortuinately this will be availabel soon :)
I wanted to create a simple build target or similar for arm64 that mimics the s390 use of arm64 shared code but compiles using an arm64 toolchain to reduce friction for esp non-maintainers.
I have some ideas. They may work. Let's talk at plumbers about that.
Steffen
Steffen Eiden
reviewerQuoted 2 lines · Steffen Eiden
Introduce arm-on-s390. Enable KVM-accelerated ARM CPU virtualisation on s390.
....
The s390 patches (12..) of this series currently have 3 **build** conflicts with linux-next / armkvm-next. But git will apply them clean.
Triggered by:a467f39afc2a ("KVM: arm64: Prevent unsupported vcpu features for VM types")
eb2eb48c8d72 ("arm64: Add ESR fault helpers") caa63620f9e3 ("KVM: Allow architectures to disallow pre-fault")
They can be solved by applying the following patches while merging. Fix is below the patch they fixup.
Quoted 15 lines
Hendrik Brueckner (1):
s390/hwcaps: Report SAE support as hwcapSteffen Eiden (23):
KVM: Make device name configurable
KVM: Move architecture capability Kconfigs to header defines
KVM: ReplaceCONFIG_KVM_MMIOwithKVM_NO_MMIO
arm64: Use proper include variant
arm64: ptrace: Use constants for compat register numbers
arm64: sysreg: ConvertSPSR_ELxto automatic register generation
KVM: arm64: Access elements ofvcpu_gp_regsindividually
KVM: arm64: Use accessor functions for core regs
arm64: Prepare sharing arm64 headers with s390
arm64: Share arm64 headers with s390
Quoted 8 lines
KVM: arm64: Share arm64 code with s390 s390/Kconfig: remove PCI dependency from
HAS_IOMEM
KVM: s390: Use dedicated function for migration mode s390/tools: 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
arch/s390/kvm/arm64/arm.c +2 -2
@@ -23,7 +23,7 @@#define CREATE_TRACE_POINTS #include "trace.h" -static unsigned long system_supported_vcpu_features (void ); +static unsigned long system_supported_vcpu_features (struct kvm_vcpu *vcpu);#define __INCL_GEN_ARM_FILE#include "generated/arm.inc"
@@ -242,7 +242,7 @@ int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)return 0 ; } -static unsigned long system_supported_vcpu_features (void ) +static unsigned long system_supported_vcpu_features (struct kvm_vcpu *vcpu) {unsigned long features =KVM_S390_ARM64_IMPL_FEATURES ;
Quoted 4 lines
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
arch/s390/kvm/arm64/mmu.c +11 -1
@@ -76,6 +76,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)bool translation = false;phys_addr_t fault_ipa;unsigned long hva; +unsigned long esr;bool write_fault;bool guest_size_err;bool writable;
@@ -83,6 +84,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)int ret;gfn_t gfn; + esr =kvm_vcpu_get_esr (vcpu); fault_ipa =kvm_vcpu_get_fault_ipa (vcpu); is_iabt =kvm_vcpu_trap_is_iabt (vcpu); guest_size_err = vcpu->arch.sae_block.icptr ==SAE_ICPTR_GUEST_ADDRESS_SIZE ;
@@ -143,7 +145,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)* Check for a cache maintenance operation. Assume the guest is * cautious and skip instruction */ -if (kvm_is_error_hva (hva) &&kvm_vcpu_dabt_is_cm (vcpu)) { +if (kvm_is_error_hva (hva) &&esr_dabt_is_cm (esr)) {kvm_incr_pc (vcpu); ret =1 ; goto out_unlock;
@@ -198,3 +200,11 @@ long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu, struct kvm_pre_fault_ end =ALIGN (range->gpa +PAGE_SIZE , f.crste_region3 ? _REGION3_SIZE :HPAGE_SIZE );return min (range->size, end - range->gpa); } + +int kvm_arch_pre_fault_allowed (struct kvm_vcpu *vcpu) +{ +if (!kvm_vcpu_initialized (vcpu)) +return -ENOEXEC ; + +return 0 ; +}
Quoted 2 lines
KVM: s390: arm64: Integrate arm on s390
Steffen
Quoted 117 lines
MAINTAINERS | 1 + arch/arm64/Makefile | 3 + 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 | 64 +- arch/arm64/include/asm/kvm_host.h | 120 +-- arch/arm64/include/asm/ptrace.h | 64 +- arch/arm64/include/asm/sysreg.h | 22 +- arch/arm64/kvm/Kconfig | 4 - arch/arm64/kvm/arm.c | 3 + arch/arm64/kvm/guest.c | 22 +- arch/arm64/kvm/hyp/exception.c | 4 +- arch/arm64/kvm/hyp/include/hyp/adjust_pc.h | 4 +- arch/arm64/kvm/hyp/include/hyp/switch.h | 4 +- arch/arm64/kvm/mmio.c | 2 + arch/arm64/tools/sysreg | 51 ++ arch/loongarch/include/asm/kvm_host.h | 2 + arch/loongarch/kvm/Kconfig | 3 - arch/mips/include/asm/kvm_host.h | 1 + arch/mips/kvm/Kconfig | 2 - arch/powerpc/include/asm/kvm_host.h | 10 + arch/powerpc/kvm/Kconfig | 5 - arch/riscv/include/asm/kvm_host.h | 2 + arch/riscv/kvm/Kconfig | 3 - arch/s390/Kconfig | 5 +- arch/s390/include/arm64/kvm_emulate.h | 130 ++++ arch/s390/include/arm64/kvm_nested.h | 11 + arch/s390/include/arm64/ptrace.h | 11 + arch/s390/include/arm64/sysreg.h | 13 + arch/s390/include/asm/asm-prototypes.h | 1 + arch/s390/include/asm/elf.h | 2 + arch/s390/include/asm/io.h | 12 +- arch/s390/include/asm/kvm.h | 6 + arch/s390/include/asm/kvm_host.h | 4 + arch/s390/include/asm/kvm_host_arm64.h | 209 +++++ arch/s390/include/asm/kvm_host_arm64_types.h | 124 +++ arch/s390/include/asm/kvm_host_s390.h | 5 + arch/s390/include/asm/kvm_host_types.h | 4 + arch/s390/include/asm/sae.h | 49 ++ arch/s390/include/asm/sclp.h | 5 +- arch/s390/include/asm/stacktrace.h | 5 + arch/s390/include/uapi/Kbuild | 6 + arch/s390/kernel/asm-offsets.c | 1 + arch/s390/kernel/entry.S | 22 + arch/s390/kernel/processor.c | 3 + arch/s390/kvm/Kconfig | 27 +- arch/s390/kvm/Makefile | 1 + arch/s390/kvm/arm64/.gitignore | 2 + arch/s390/kvm/arm64/Makefile | 110 +++ arch/s390/kvm/arm64/Makefile.gen | 28 + arch/s390/kvm/arm64/arm.c | 754 +++++++++++++++++++ arch/s390/kvm/arm64/arm.h | 58 ++ arch/s390/kvm/arm64/copy-arm64c.awk | 82 ++ arch/s390/kvm/arm64/guest.c | 135 ++++ arch/s390/kvm/arm64/handle_exit.c | 161 ++++ 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 | 200 +++++ arch/s390/kvm/arm64/reset.c | 71 ++ arch/s390/kvm/arm64/trace.h | 101 +++ arch/s390/kvm/gmap/faultin.c | 5 + arch/s390/kvm/gmap/gmap.c | 4 + arch/s390/kvm/gmap/kvm_mmu.c | 6 +- arch/s390/kvm/gmap/trace_gmap.h | 17 +- arch/s390/kvm/s390/Makefile | 2 +- arch/s390/tools/Makefile | 6 +- arch/s390/tools/Makefile.arm64h | 55 ++ arch/s390/tools/copy-arm64h-full.awk | 50 ++ arch/s390/tools/copy-arm64h.awk | 83 ++ arch/s390/tools/opcodes.txt | 3 + arch/x86/include/asm/kvm_host.h | 3 + arch/x86/kvm/Kconfig | 4 - drivers/s390/char/sclp_early.c | 1 + include/linux/kvm_host.h | 24 +- include/trace/events/kvm.h | 8 +- virt/kvm/Kconfig | 18 - virt/kvm/Makefile.kvm | 9 +- virt/kvm/async_pf.c | 5 +- virt/kvm/coalesced_mmio.c | 4 + virt/kvm/coalesced_mmio.h | 2 +- virt/kvm/eventfd.c | 3 +- virt/kvm/kvm_main.c | 44 +- 84 files changed, 2968 insertions(+), 199 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 create mode 100644 arch/s390/include/asm/sae.h create mode 100644 arch/s390/include/uapi/Kbuild create mode 100644 arch/s390/kvm/arm64/.gitignore create mode 100644 arch/s390/kvm/arm64/Makefile create mode 100644 arch/s390/kvm/arm64/Makefile.gen create mode 100644 arch/s390/kvm/arm64/arm.c create mode 100644 arch/s390/kvm/arm64/arm.h create mode 100644 arch/s390/kvm/arm64/copy-arm64c.awk create mode 100644 arch/s390/kvm/arm64/guest.c create mode 100644 arch/s390/kvm/arm64/handle_exit.c create mode 100644 arch/s390/kvm/arm64/handle_exit.h create mode 100644 arch/s390/kvm/arm64/inject_fault.c create mode 100644 arch/s390/kvm/arm64/mmio.c create mode 100644 arch/s390/kvm/arm64/mmu.c create mode 100644 arch/s390/kvm/arm64/reset.c create mode 100644 arch/s390/kvm/arm64/trace.h 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:
16096aadaa3d15c11d37bbea750bad0917e8eadfSignature · 1 line
2.53.0