summaryrefslogtreecommitdiff
path: root/arch/s390/kvm
AgeCommit message (Collapse)Author
6 daysMerge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvmLinus Torvalds
Pull KVM updates from Paolo Bonzini: "ARM: - pKVM state isolation: years after pKVM started being enabled upstream, we finally get the basics in the form of state isolation. The vcpu state is now off-limit for the host for protected VMs - pKVM also grows a hypervisor-private memory allocator, allowing it to deal with sub-page allocation, much like everywhere else - pKVM also lands a trace_printk() equivalent, which hopefully will make debugging a bit easier - First shot at annotating portions of the KVM/arm64 code to be extracted and built on s390. The real fun is yet to come - Allow pre-faulting of stage-2 canonical mappings from userspace, joining x86 and s390 in implementing this feature - Add a reverse mapping infrastructure for shadow stage-2, significantly improving performance when MMU notifiers kick in, and avoiding full unmap of all shadow tables for this VM - Next step of GICv5 enablement, adding support for the IRS block, and providing both SPI and LPI support. This is the first point where KVM/arm64 can support an SMP GICv5 guest - As a preliminary to eventually enabling CCA, add a bunch of infrastructure to KVM/arm64, splitting some of the basic operations into individual backends (normal VM, normal pKVM VM, protected pKVM VM). This allows CCA to later slot in without polluting the rest of KVM with its firmware-driven nonsense - Make ID registers immutable from the point where a vcpu is able to run, even if it fails to run. This prevents KVM from sampling untrusted values - Restore some type checking to the EL2 object. KVM/arm64 originally had some strong type checking between the kernel and the EL2 object, but lost it along the way when the private hypercall interface was (somewhat pointlessly) converted to SMCCC. Type checking is back, syscall style, and with added sparse goodies - Expand the FFA support to FFA_NOTIFICATION_*, and add some sanitisation of the protocol that pKVM relays to the "trusted" runtime - Make GICv3 RD assignment more robust to userspace nonsense - Convert the remaining MMU fault handler backends to kvm_s2_fault_vma_info and co., fixing a number of bugs in the process - Fix the SError/SEA selftests to be both more robust and less braindead - Fix a smattering of documentation bugs, some of them as a result of our AI friends spitting out credible assertions based on non-existing symbols - The usual collection of low impact bug fixes (SMCCC, timers, PMU) Loongarch: - Add separate vmid support - Simplify MSI interrupt injection - Add crash hypercall support - Allow to set pv_feature until vCPU run - Enable HW page table walk automatically in selftests s390: - rework page allocation for secure guest variable storage - Selftests and documentation improvements - Replace get_zeroed_page with kzalloc - Fix corner cases of floating interrupt injection - Initial arm64 on s390 support x86: - Clean up the handling of vcpu->arch.xen.long_mode to be consistent and correctly handle 32-bit/64-bit alignment, and various other bug fixes have accumulated over the months since v1 - Grab KVM's SRCU "lock" in kvm_zap_gfn_range() to fix a recurring bug where callers fail to do so - Fix a variety of issues in the pre-fault code that are mostly benign in the current code base, but will show up in big ways if/when the pre-faulting logic is used to implementing prefetch-on-fault for the TDP MMU - For PREEMPT_RT=y kernels, drop the rmaps' individual bit-spinlock and just walk the rmaps' with mmu_lock taken. On the write side (which always uses mmu_lock), the bit-spinlock was assuming that preemption was disabled, but that is *not* true when rwlocks become sleepable - Prepare a memory_fault exit (paired with -EFAULT) when KVM hits an error PFN, e.g. so that userspace can resolve transient issues instead of killing the guest. Convert a variety of WARN()+EFAULT paths into KVM_BUG_ON()+EIO so that KVM can hard commit to filling memory_fault on -EFAULTs that occur in the page fault path - Fix a NX hugepage un-accounting bug where KVM would always uncharge the shadow MMU, even when handling TDP MMU pages - Mask off the address space ID when checking for illegal usage of kvm_set_internal_memslot() to prevent false negatives on the sanity check - Explicitly zero reserved flags when delivering a SynIC message to avoid leaking a byte of stack information to the guest - Rework TDX's handling of the canonical MMU root level to not rely on userspace to fill CPUID correctly, as doing so lets userspace trivially trigger a KVM_BUG_ON() - Reject KVM_SET_NESTED_STATE if userspace "restores" L1 with EFER.LMA=1 && EFER.LME=0, which confuses KVM into trying to configure an 64-bit MMU without PAE - Ignore EFER.LMA (clear it from KVM's cached save state) if EFER.LME=0 when preparing L2 state, to fix another way to confuse KVM's MMU (and because real hardware also ignores EFER.LMA) - Improve KVM's sanity checks for a misconfigured MMU to (hopefully) detect all of the ways KVM can botch EFER.LMA vs. CR4.PAE - Remove the "full" out-param from kvm_x86_ops.flush_tlb_gva() as the param is only used to avoid what effectively amounts to a single memory write - Fix a mostly-benign bug where KVM can write through a guest's read-only mapping due to not checking the error code when expediting emulated MMIO page faults - Honor the guest's view of the "EFER.LMSLE must be zero" defeature so that userspace can provide migration compatibility between Rome and Milan+ - Pend a KVM_REQ_EVENT request when an exception is morphed into a nested VM-Exit, otherwise KVM can fail to actually deliver the nested VM-Exit, e.g. when injecting a page fault - Add support for PML on SVM - Add support for virtualizing Bus Lock Detect on SVM, and fix a number of DR6 bugs and warts along the way - Fix a variety of warts in KVM's handling of guest TSC, kvmclock, and timekeeping in general, as a (big) first step towards addressing several longstanding problems with the kvmclock implementation. Most notably, fix a precision issue where get_kvmclock_ns() computed the clock from the *host* TSC without applying guest TSC scaling, causing systemic drift from the values the guest computes from its own TSC - Rip out KVM's shadow timekeeping structures, now that ktime snapshots are powerful enough to replace it - Misc fixes and cleanups x86 (AMD): - Fix a benign-in-practice bug where KVM unintentionally sets a non-zero error code when delivering exceptions to SEV-ES+ guests - Force a new ASID in both VMCBs on pCPU migration to fix a bug where KVM can run a VMCB with a stale ASID due to the tracking being per-CPU, not per-VMCB - Return INVALID_INPUT to the guest instead of exiting to userspace with -EIO if KVM can't access "guest request" buffer, i.e. try to keep the guest alive if the guest or userspace goofs x86 (Intel): - Enable Notify VM-Exits (now called Instruction Timeout in the SDM) and Bus Lock VM-Exits for TDX guests when they're enabled by userspace (KVM forgot to wire up the TDX Module knobs) - Move all common (between VMX and TDX) APIs/helpers to common.h/main.c, and change all namespace prefixes from "vmx" to "vt" - Fix a thankfully benign bug (due to other areas of KVM being hardened) where userspace can bypass INIT_MEM_REGION's address wrap check by providing a nr_pages that will overflow a u64 when converted to bytes, and fix an also- benign off-by-one bug in the check (inclusive vs. exclusive) - Set the vmcs.GUEST_ACTIVITY_STATE back to ACTIVE when userspace sets KVM's mp_state to anything other than HALTED, e.g. so that a vCPU doesn't get stuck in HLT if userspace emulates RESET guest_memfd: - Take the invalidate lock when unbinding a dying file to fix a race with kvm_gmem_invalidate_end() that results in KVM leaving the MMU invalidation count elevated. Not taking the lock in the first place was pure misguided paranoid - When binding a memslot, purge the bindings if storing the new memslot fails, as Xarray's "store range" API can subtly fail partway through - Establish memslot<=>guest_memfd bindings *after* the memslot is ready, as the memslot becomes reachable the instant the binding is installed - Don't grab a page refcount when reloading an SNP VMSA and stop returning a "struct page" from guest_memfd's PFN lookup altogether, to ensure that KVM doesn't hold any unnecessary refcounts (the lifetime of the page is ensured by MMU notifiers and similar hooks). Preventing unnecessary refcounts greatly simplifies supporting in-place SHARED=>PRIVATE conversions - Add support for in-place PRIVATE<=>SHARED conversion, i.e. allow a single guest_memfd instance to be used for both PRIVATE and SHARED variations of CoCo guests' memory (though not at the same time). This eliminates the need to double allocate guest memory for TDX and SNP, and is basically a hard requirement for pKVM, which relies on being able to preserve memory contents on conversions - Hack-a-fix a deadlock bug in ->error_remove_folio() by returning -EBUSY if the filemap invalidate lock is contended. Punt on a proper fix for the moment, as a proper fix likely involves reworking truncate_error_folio() - Add a pile of selftests for in-place conversions - Misc guest_memfd cleanups Generic: - Move some configuration items to preprocessor symbols, to help with arm-on-s390's need to compile the same code twice with different values - Allow KVM implementations to choose alternative device names, also for s390's support of ARM virtualmachines - Switch the KVM-VFIO interface and external consumers over to standard file-based reference counting, eliminating all external KVM symbol exports Selftests: - Rework KVM selftest's handling of memory regions all so that PPC can force its page table allocations to be naturally aligned - PPC support - Fix emulation of VMPTRST and VMPTRLD when eVMCS is in-use to match real Hyper-V's behavior - Saturate L2's TSC frequency if stacking L1 and L2 scaling multipliers exceeds what hardware supports, as attempting to run L2 with an illegal multiplier will either cause VM-Entry to fail (VMX) or trigger a #GP when writing MSR_AMD64_TSC_RATIO (SVM). The #GP is thankfully benign in the grand scheme as even "unsafe" WRMSRs have exception fixup - Rework KVM selftest's handling of memory regions so that PPC can force its page table allocations to be naturally aligned - Clean up selftest's VMX instruction helpers, and drop an absurd number of completely useless return values, e.g. functions that unconditionally return %true and then have every caller assert success - Add selftests support for Zhaoxin CPUs - Overhaul the TSC scaling test to add a regression test for the saturation behavior, and to increase its coverage in general - Fix selftests usage various NUMA syscalls to account for an undocumented, but known since 2007, off-by-one kernel bug. Add helpers to try and avoid re-introducing the same flaws in the future - Automatically run xAPIC IPI migration test (between NUMA nodes) when possible, as the entire point of the test is verify KVM's handling of page migration of the APIC backing page - Misc cleanups" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (506 commits) KVM: always make in-place conversion a compile-time constant when possible KVM: x86: leave the legacy private attribute in for TDX and SEV KVM: split CONFIG_KVM_PRIVATE_MEMATTR_VM out of KVM_VM_MEMORY_ATTRIBUTES selftests: kvm: remove useless comma operator arm64: Use proper include variant MAINTAINERS: Add entry for ARM on s390 KVM KVM: s390: arm64: Integrate arm on s390 KVM: s390: arm64: Implement basic page fault handler KVM: s390: arm64: Implement vCPU IOCTLs KVM: s390: arm64: Implement vm/vcpu create destroy KVM: s390: arm64: Implement required functions KVM: s390: Add basic arm64 kvm module s390/hwcaps: Report SAE support as hwcap KVM: s390: arm64: Introduce host definitions s390: Introduce Start Arm Execution instruction KVM: s390: Use arm64 code s390/tools: Use arm64 headers KVM: s390: Use dedicated function for migration mode s390/Kconfig: remove PCI dependency from HAS_IOMEM KVM: s390: Kick PV cpus at the right time for service irqs ...
9 daysMerge tag 's390-7.4-1' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux Pull s390 updates from Heiko Carstens: - Add support for sclp-vt220 terminal resize events e.g. for QEMU - Warn if kernel command line contains non-printable EBCDIC characters - Improve show_code() disassembly output by using reliable markers for the instruction address and faulting instruction - Rework exception handling to require only a single exception table entry per faulting instruction: convert all inline assemblies from EX_TABLE to the new EX_TABLE_INSN macros. The previous exception handling was error prone since it usually required two EX_TABLE entries: one pointing at the instruction, and one pointing behind it - Disallow kprobes on instructions with exception table entries to avoid exception handlers decoding a breakpoint instead of the original instruction - Preemptible percpu ops changes: - Simplify percpu_entry() and percpu_exit() by encoding the percpu base, offset, and pointer registers into the lowcore marker, allowing percpu_exit() to update the percpu pointer on CPU migration without comparing the interrupted instruction - Convert this_cpu_cmpxchg(), this_cpu_xchg(), and this_cpu_cmpxchg128() to preemptible percpu ops; provide this_cpu_try_cmpxchg() - Emulate virtual timer in appldata via delayed work and remove the s390 specific vtimer infrastructure - Add lock contention tracepoints to rwlock slowpath - Fix incorrect return address in signal frame setup - Fix cpum_cf CPU hotplug handling - Convert various __get_free_pages() / get_zeroed_page() users to kmalloc() / kzalloc() - PCI: - Improve RPCIT instruction tracing - Fix double-free, use-after-free, and resource leaks in zPCI MSI and IRQ setup / cleanup paths - Crypto and zcrypt: - Improve reply message and length verification checks for CCA, EP11, and ICA messages to prevent out-of-bounds reads - Add missing array_index_nospec() for domain index uses in zcrypt to prevent speculative execution bypass - Fix out-of-bounds read in cca_query_crypto_facility() - Various other small fixes and improvements * tag 's390-7.4-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux: (102 commits) s390/signal: Cleanup coding style s390/signal: Fix incorrect return address in signal frame s390/probes: Fix wrong mnemonic comment for clgib s390/probes: Add missing fixup for bctgr and bic s390/probes: Fix wrong opcode for cgrb fixup s390: Select ARCH_MEMORY_ORDER_TSO s390/mm: Cleanup pXXp_flush_lazy() routines s390/pci: Add function handle to RPCIT insn trace s390/pci: Use 32-bit fh outside of inline asm s390/pci: Adjust alignment in insn trace s390/sclp: Remove redundant memset after memblock_alloc_low() s390/entry: Save lowcore on invalid kernel stack s390/entry: Last breaking event vs invalid kernel stack s390/percpu: ImplemenHeiko Carstenst this_cpu_try_cmpxchg() s390/percpu: Drop unused output register from arch_this_cpu_to_op() s390/percpu: Drop unused output register from arch_this_cpu_add() s390/percpu: Use asm_inline for arch_this_cpu_add() s390/extable: Remove EX_TABLE macros and fallback extable search s390/bpf: Simplify exception table entry handling s390/sclp: Convert inline assembly to EX_TABLE_INSN ...
11 daysMerge tag 'kvm-s390-next-7.4-2' of ↵Paolo Bonzini
git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux into HEAD KVM: s390: Changes for 7.4 - rework page allocation for secure guest variable storage - selftests - documentation - replace get_zeroed_page with kzalloc - fix floating interrupt inject for corner cases - initial arm64 on s390 support This also contains the patch "arm64: Use proper include variant" as a build fix. It is also part of the arm tree.
2026-10-15KVM: s390: arm64: Integrate arm on s390Steffen Eiden
Add 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. Co-developed-by: Andreas Grapentin <gra@linux.ibm.com> Signed-off-by: Andreas Grapentin <gra@linux.ibm.com> Co-developed-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com> Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com> Co-developed-by: Gautam Gala <ggala@linux.ibm.com> Signed-off-by: Gautam Gala <ggala@linux.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-10-15KVM: s390: arm64: Implement basic page fault handlerSteffen Eiden
Add host functionality to page in guest memory. If the guest does something unexpected or illegal exit to userspace abort guest execution. This behaviour will be changed to guest error injects once all sysregs are accessible for the host. Add pre-fault handler. Co-developed-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com> Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> [borntraeger@linux.ibm.com: fixup for recent arm changes] Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-10-15KVM: s390: arm64: Implement vCPU IOCTLsSteffen Eiden
Implement all required vCPU (arch) IOCTLs. Co-developed-by: Andreas Grapentin <gra@linux.ibm.com> Signed-off-by: Andreas Grapentin <gra@linux.ibm.com> Co-developed-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com> Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-10-15KVM: s390: arm64: Implement vm/vcpu create destroySteffen Eiden
Implement init and destroy IOCTLS for vcpu and vm. Implement arch vm IOCTL. Use s390 gmap and gmap plumbing. Implement function (stubs) required by gmap. Co-developed-by: Janosch Frank <frankja@linux.ibm.com> Signed-off-by: Janosch Frank <frankja@linux.ibm.com> Co-developed-by: Andreas Grapentin <gra@linux.ibm.com> Signed-off-by: Andreas Grapentin <gra@linux.ibm.com> Co-developed-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com> Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-10-15KVM: s390: arm64: Implement required functionsSteffen Eiden
Implement 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. Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-10-15KVM: s390: Add basic arm64 kvm moduleSteffen Eiden
Add basic code for the new arm64 on s390 KVM implementation. Add kernel module boilerplate code and trivial functions. Add tracing scaffolding. Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> [borntraeger@linux.ibm.com: add struct kvm_vcpu *vcpu to system_supported_vcpu_features] Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-10-15KVM: s390: Use arm64 codeSteffen Eiden
Add 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 Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-10-15KVM: s390: Use dedicated function for migration modeSteffen Eiden
Use 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.. Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-10-15KVM: s390: Kick PV cpus at the right time for service irqsJanosch Frank
Service call handling is a two stage process for PV vms. First we receive the secure instruction intercept and then the secure instruction notification intercept. The secure instruction intercept (104) is analogous to the non-pv instruction intercept (4) with the difference that we're not allowed to inject an IRQ when re-entering SIE. We have to wait for the notification intercept (108) which tells us that we're allowed to inject. Unfortunately we never considered this difference and hence the IRQ injection code will try to kick on the secure instruction intercept where service IRQs are masked. It's time to move the kick to the instruction notification and skip kicking on the instruction interception path. Signed-off-by: Janosch Frank <frankja@linux.ibm.com> Acked-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-10-15KVM: s390: Improve floating IRQ injection behaviorJanosch Frank
Floating IRQs can be handled by any VCPU that opened its masks. The current design does not check if the mask is open when a floating IRQ is injected via the FLIC. It will wakeup the last VCPU that went sleeping hoping it's the correct one. Improve this by checking if the VCPU can deliver that partiqular IRQ and if not try to find another VCPU which can take the IRQ. This is not the final fix around this topic but we'll eventually inject a pending IRQ. The current code can easily deadlock a VM and with this fix we work around that. Signed-off-by: Janosch Frank <frankja@linux.ibm.com> Acked-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-10-15KVM: s390: Replace get_zeroed_page() with kzalloc() for the STHYI bufferMike Rapoport (Microsoft)
handle_sthyi() allocates the buffer that receives the STHYI response block before it is copied to the guest. This buffer can be allocated with kmalloc() as there's nothing special about it to go directly to the page allocator. kmalloc() provides a better API that does not require ugly casts and kfree() does not need to know the size of the freed object. Performance difference between kmalloc() and __get_free_pages() is not measurable as both allocators take an object/page from a per-CPU list for fast path allocations. For the slow path the performance is anyway determined by the amount of reclaim involved rather than by what allocator is used. The only goto in that function does not unwind anything, it merely skips to the exit when the function code is invalid. Turn it into an early return so that the buffer can be freed with __free(kfree). Replace use of get_zeroed_page() with kzalloc() and free_page() with kfree(). Assisted-by: copilot:claude-opus Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Reviewed-by: Janosch Frank <frankja@linux.ibm.com> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Signed-off-by: Janosch Frank <frankja@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-10-15KVM: s390: Replace get_zeroed_page() with kzalloc() for the STSI bufferMike Rapoport (Microsoft)
handle_stsi() allocates the buffer that receives the STSI response block before it is copied to the guest. This buffer can be allocated with kmalloc() as there's nothing special about it to go directly to the page allocator. kmalloc() provides a better API that does not require ugly casts and kfree() does not need to know the size of the freed object. Performance difference between kmalloc() and __get_free_pages() is not measurable as both allocators take an object/page from a per-CPU list for fast path allocations. For the slow path the performance is anyway determined by the amount of reclaim involved rather than by what allocator is used. While on it, make the buffer a void pointer to get rid of the casts. Replace use of get_zeroed_page() with kzalloc() and free_page() with kfree(). Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com Assisted-by: copilot:claude-opus Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Reviewed-by: Janosch Frank <frankja@linux.ibm.com> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Signed-off-by: Janosch Frank <frankja@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-10-15KVM: s390: Replace get_zeroed_page() with kzalloc() for the GIBMike Rapoport (Microsoft)
kvm_s390_gib_init() allocates the guest information block (GIB). The GIB is passed to the hardware as a physical address and must be page aligned. kmalloc() guarantees that a power of two sized allocation is aligned to its size, so a PAGE_SIZE allocation is page aligned as well. This buffer can be allocated with kmalloc() as there's nothing special about it to go directly to the page allocator. kmalloc() provides a better API that does not require ugly casts and kfree() does not need to know the size of the freed object. Performance difference between kmalloc() and __get_free_pages() is not measurable as both allocators take an object/page from a per-CPU list for fast path allocations. For the slow path the performance is anyway determined by the amount of reclaim involved rather than by what allocator is used. Replace use of get_zeroed_page() with kzalloc() and free_page() with kfree(). Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com Assisted-by: copilot:claude-opus Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Reviewed-by: Janosch Frank <frankja@linux.ibm.com> Signed-off-by: Janosch Frank <frankja@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-10-15KVM: s390: Replace get_zeroed_page() with kzalloc() for sie_page2 and CMMAMike Rapoport (Microsoft)
kvm_arch_init_vm() allocates struct sie_page2 that holds the facility list and the crypto control block of a VM and kvm_s390_vcpu_setup_cmma() allocates the CMMA collaborative memory management block referenced by the SIE control block. Both are passed to the hardware as physical addresses and must be page aligned. kmalloc() guarantees that a power of two sized allocation is aligned to its size, so a PAGE_SIZE allocation is page aligned as well. These buffers can be allocated with kmalloc() as there's nothing special about them to go directly to the page allocator. kmalloc() provides a better API that does not require ugly casts and kfree() does not need to know the size of the freed object. Performance difference between kmalloc() and __get_free_pages() is not measurable as both allocators take an object/page from a per-CPU list for fast path allocations. For the slow path the performance is anyway determined by the amount of reclaim involved rather than by what allocator is used. The sie_page allocated in kvm_arch_vcpu_create() is left alone because it is mapped to userspace with virt_to_page() in kvm_arch_vcpu_fault() and therefore really needs a struct page. The SIE hardware stores the offset of the next CBR entry in the low bits of cbrlo, so mask them out before converting cbrlo back to a virtual address. free_page() did not care, kfree() needs the address kzalloc() returned. Replace use of get_zeroed_page() with kzalloc() and free_page() with kfree(). Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com Assisted-by: copilot:claude-opus Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Reviewed-by: Janosch Frank <frankja@linux.ibm.com> Signed-off-by: Janosch Frank <frankja@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-10-15Merge tag 'loongarch-kvm-7.4' of ↵Paolo Bonzini
git://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson into HEAD LoongArch KVM changes for v7.4 1. Add separate vmid support. 2. Simplify MSI interrupt injection. 3. Add crash hypercall support. 4. Allow to set pv_feature until vCPU run. 5. Enable HW page table walk automatically in selftests.
2026-10-14Merge tag 'kvmarm-7.4' of ↵Paolo Bonzini
git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm into HEAD KVM/arm64 updates for 7.4 * New features - pKVM state isolation: years after pKVM started being enabled upstream, we finally get the basics in the form of state isolation. The vcpu state is now off-limit for the host for protected VMs. - pKVM also grows a hypervisor-private memory allocator, allowing it to deal with sub-page allocation, much like everywhere else. - pKVM also lands a trace_printk() equivalent, which hopefully will make debugging a bit easier. - First shot at annotating portions of the KVM/arm64 code to be extracted and built on s390. The real fun is yet to come. - Allow pre-faulting of stage-2 canonical mappings from userspace, joining x86 and s390 in implementing this feature. - Add a reverse mapping infrastructure for shadow stage-2, significantly improving performance when MMU notifiers kick in, and avoiding full unmap of all shadow tables for this VM. - Next step of GICv5 enablement, adding support for the IRS block, and providing both SPI and LPI support. This is the first point where KVM/arm64 can support an SMP GICv5 guest. * Improvements - As a preliminary to eventually enabling CCA, add a bunch of infrastructure to KVM/arm64, splitting some of the basic operations into individual backends (normal VM, normal pKVM VM, protected pKVM VM). This allows CCA to later slot in without polluting the rest of KVM with its firmware-driven nonsense. - Make ID registers immutable from the point where a vcpu is able to run, even if it fails to run. This prevents KVM from sampling untrusted values. - Restore some type checking to the EL2 object. KVM/arm64 originally had some strong type checking between the kernel and the EL2 object, but lost it along the way when the private hypercall interface was (somewhat pointlessly) converted to SMCCC. Type checking is back, syscall style, and with added sparse goodies. - Expand the FFA support to FFA_NOTIFICATION_*, and add some sanitisation of the protocol that pKVM relays to the "trusted" runtime. * Fixes - Make GICv3 RD assignment more robust to userspace nonsense - Convert the remaining MMU fault handler backends to kvm_s2_fault_vma_info and co, fixing a number of bugs in the process. - Fix the SError/SEA selftests to be both more robust and less braindead. - Fix a smattering of documentation bugs, some of them as a result of our AI friends spitting out credible assertions based on non-existing symbols. - The usual collection of low impact bug fixes (SMCCC, timers, PMU).
2026-10-14KVM: Move architecture capability Kconfigs to header definesSteffen Eiden
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 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. Acked-by: Hendrik Brueckner <brueckner@linux.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Link: https://patch.msgid.link/20261013121343.1997112-1-seiden@linux.ibm.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2026-10-13s390/kvm: Convert inline assembly to EX_TABLE_INSNHeiko Carstens
Convert the gaccess mvcos exception table entries to use EX_TABLE_INSN. With EX_TABLE_INSN entries always point to the faulting instruction, so duplicate entries are removed. Acked-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2026-10-12KVM: Make device name configurableSteffen 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 <seanjc@google.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Link: https://patch.msgid.link/20260930173441.66762-2-seiden@linux.ibm.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2026-10-09Merge tag 'kvm-s390-next-7.4-1' of ↵Paolo Bonzini
git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux into HEAD KVM/vfio: Use file-based reference counting for KVM This series switches the KVM-VFIO interface and external consumers over to standard file-based reference counting, eliminating all external KVM symbol exports. Currently, VFIO integrates with KVM by looking up kvm_get_kvm_safe() and kvm_put_kvm() dynamically using symbol_get(), manually tracking module reference counts and storing a put_kvm function pointer in struct vfio_device. In the ARM64-on-s390 architecture, a second concurrent KVM module (kvm-arm64) is introduced alongside native KVM to host hardware-accelerated ARM64 guests. Having exported global symbols (like kvm_get_kvm/kvm_put_kvm) creates symbol conflicts and prevents clean coexistence of two KVM modules. Additionally, the file based counting simplifies the code and reuses the existing fs refcounting. Instead of passing raw KVM pointers and managing module symbols manually, the interface now passes the underlying VM file descriptor throughout VFIO and associated architecture subsystems. To safely extract the KVM instance from a file, an architecture-namespaced helper mechanism is introduced that verifies the file belongs to the expected KVM implementation before accessing its internal state. A back-pointer from the KVM instance to its associated file is maintained across its lifecycle so subsystems can safely acquire file references on demand. Finally, with VFIO, architecture page tracking, and device hooks converted to use file references, the remaining KVM reference- counting exports are restricted strictly to internal KVM modules.
2026-10-02KVM/vfio: Use file-based reference counting for KVMSteffen Eiden
Replace manual module reference counting with file-based reference counting for KVM integration. Previously, VFIO used symbol_get() to obtain function pointers for kvm_get_kvm_safe() and kvm_put_kvm(), then manually tracked module references through these symbols. This approach required storing the put_kvm function pointer in each device and carefully managing symbol references. Pass struct file pointers instead of struct kvm pointers throughout the VFIO-KVM interface, leveraging the kernel's existing file reference counting via get_file()/get_file_active() and fput(). Convert the x86 page-track API and update s390 vfio to use file_to_kvm_<arch>(). This simplifies the code. Suggested-by: Jason Gunthorpe <jgg@nvidia.com> Co-developed-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Acked-by: Alex Williamson <alex@shazbot.org> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Acked-by: Janosch Frank <frankja@linux.ibm.com> Acked-by: Sean Christopherson <seanjc@google.com> [borntraeger@linux.ibm.com remove _safe from vfio_device_get_kvm_safe] Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-09-26KVM: Protect all of kvm_vm_ioctl_create_vcpu() with kvm->lockSean Christopherson
When creating a vCPU, don't drop kvm->lock to when doing the bulk of actual vCPU creation, as allowing multiple vCPUs to be created in parallel adds significant complexity in KVM (as evidenced by the many related bugs), and all known VMMs fully serialize vCPU creation. Remove all manually locking of kvm->lock from kvm_arch_vcpu_{post,}create() for obvious reasons. For many years, "everyone" has assumed that dropping kvm->lock was done for performance reasons optimization, e.g. to allow userspace to create all vCPUs concurrently for latency purposes. But as above, no known VMM does that. Looking at the history of this code, before commit 11ec28047118 ("KVM: Convert vm lock to a mutex"), kvm->lock was a spinlock. I.e. KVM *had* to drop kvm->lock when doing the bulk of vCPU creation, otherwise KVM couldn't do normal memory allocations. When kvm->lock got turned into a mutex for unrelated reasons, no one took advantage updated of the change to simplify vCPU creation. And 19 years later, everyone just assumed that KVM continued to deal with the complexity for performance reasons. Furthermore, naively parallelizing vCPU creation in userspace is likely a net negative due to the overheads of task creation. Unless a VMM carefully avoids the extra overhead related to parallelization, e.g. spawns each vCPU's thread before creating the vCPU, creating vCPUs concurrently is a net *negative* up until about ~64 vCPUs, after which the times are a wash. The absolute speed of light _is_ faster if KVM doesn't hold kvm-lock, but at vCPU counts of ~16 or less, it's probably in the noise when considering total VM creation time, as the added latency is less than 1ms up until 16 or so vCPUs. On top of all that, KVM has had a *lot* of fatal bugs (most often found by syzkaller) related to vCPUs being created while trying to do per-VM operations (basically, see every flow that locks all vCPUs). I.e. the parallel vCPU creation "support" is actively harmful as the only "use case" is for misbehaving userspace to exploit KVM bugs. Serializing vCPU creation will allow reverting commit 97d65b544f48 ("KVM: Check for duplicate vcpu_id as early as possible"), which had "minor" math error: the worst case scenario isn't "256 bytes per VM", it's "256 unsigned longs per VM", i.e. 2048 bytes per VM, which doubles the size of each VM and pushes several architectures into order-1 allocations. Signed-off-by: Sean Christopherson <seanjc@google.com> Tested-by: Jean-Christophe Guillain <jean-christophe@guillain.net> Tested-by: Naveen N Rao (AMD) <naveen@kernel.org> Message-ID: <20260921174445.911676-5-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2026-09-24KVM: Allow architectures to disallow pre-faultLorenzo Stoakes (ARM)
All existing architectures which implement KVM pre-fault (x86, s390) have mechanisms for disallowing pre-faulting. Currently these are open coded as part of kvm_arch_vcpu_pre_fault_memory(). Formalise this by moving them into a new kvm_arch_pre_fault_allowed() hook, which every architecture selecting CONFIG_KVM_GENERIC_PRE_FAULT_MEMORY must implement, returning an error code if the operation is disallowed or 0 otherwise. The hook is called early in the generic code, allowing architectures to disallow the operation prior to vCPU load. This is important, as kvm_vcpu_pre_fault_memory() is the only place where generic code can call vcpu_load() on a vCPU that has not yet been initialised. This lays the foundation for a future change which implements pre-faulting for arm64 which needs to disallow the mechanism for uninitialised vCPUs. Suggested-by: Oliver Upton <oupton@kernel.org> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org> Acked-by: Sean Christopherson <seanjc@google.com> Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev> Tested-by: Fuad Tabba <fuad.tabba@linux.dev> Link: https://patch.msgid.link/20260923-kvm-arm-prefault-v4-1-d4b0b4dfa8c3@kernel.org Signed-off-by: Marc Zyngier <maz@kernel.org>
2026-09-21Merge tag 'kvmarm-fixes-7.3-1' of ↵Paolo Bonzini
https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm into HEAD KVM/arm64 changes for 7.3, take #2 - Invalidate the ITS translation cache when the guest changes the base address of the ITS tables (Fuad Tabba) - Skip saving ITS devices with device IDs that are out-of-bounds rather than failing the entire ITS save ioctl (Fuad Tabba) - Close race between VM teardown and invalidations of nested MMUs when handling MMU operations that are allowed to block (Lorenzo Stoakes) - Various fixes for the handling of the host's untrusted SVE configuration in pKVM (Fuad Tabba) - Make sure that empty SMCCC ranges based at 0 are rejected by the kvm_smccc_set_filter() (Karl Mehltretter) - Revoke the host mapping for pKVM's private stack pages, along with a new sanity check that all mappings in the hyp's private VA range have been correctly marked as hyp-owned (Fuad Tabba) - Lifetime fixes for the array of shadow stage-2 MMUs, ensuring that concurrent vCPU initialization cannot relocate in-use MMUs. Defer the freeing of shadow stage-2 MMUs to the point that no other users (e.g. MMU notifier) could reference them (Marc Zyngier) - Drop useless WARN when rejecting an unsupported ioctl for pKVM (Fuad Tabba) - Fix the steal_time selftest to install correctly-sized mappings for non-4K hosts (Sebastian Ott) - Correct mapping of fine-grained trap for GCSPOPX instruction (Mark Brown) - Fix KVM_BUG_ON() due to missing handling of DBGBXVR<n> from 32-bit guests (Karl Mehltretter)
2026-09-04treewide: refresh kmalloc_obj() conversionsKees Cook
This is another run of the Coccinelle script for converting kmalloc() family of allocations to kmalloc_obj() via the existing rules in scripts/coccinelle/api/kmalloc_objs.cocci This catches both the set of kmalloc() uses added since the first kmalloc_obj() conversions in v7.0 and adds a large group missed in the first pass due to Coccinelle not interacting well with the cleanup.h scoped_...() family of macros[1]. I worked around this with spatch's "--macro-file" argument to a file with all the scoped_...() macros mapped to Coccinelle's YACFE_ITERATOR[2] as that was the closest viable control flow indicator I could find. Build tested allmodconfig on x86, arm64, arm, loongarch, mips, powerpc, riscv, and s390 with no new warnings. Link: https://lore.kernel.org/lkml/202609021314.8A9C0B8@keescook/ [1] Link: https://github.com/coccinelle/coccinelle/blob/master/standard.h [2] Signed-off-by: Kees Cook <kees+treewide@kernel.org>
2026-09-01KVM: s390: Fix race in _destroy_pages_crste()Claudio Imbrenda
Use READ_ONCE() in _destroy_pages_crste() to read the crste, avoid dereferencing the pointer multiple times. Fixes: a2c17f9270cc ("KVM: s390: New gmap code") Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Message-ID: <20260828115439.145885-9-imbrenda@linux.ibm.com>
2026-09-01KVM: s390: Fix potential races in dat skey functionsClaudio Imbrenda
When dat_cond_set_storage_key() finds a large page, it will conditionally set the storage key in absolute memory using large_crste_to_phys() to get the absolute address. There is a race window between dat_entry_walk() and large_crste_to_phys(): the large page could have been split concurrently, and large_crste_to_phys() might be called with a crste that does not designate a large page, leading to crashes. Similar issues were also present in dat_set_storage_key(). dat_get_storage_key() and dat_reset_reference_bit() did instead check for a potential concurrent splitting of the large page, but then handled it incorrectly. Fix by performing a READ_ONCE on the crste pointer, checking and using the result, instead of dereferencing the pointer again. In case a race is detacted, try dat_entry_walk() again. Fixes: 8e03e8316eb2 ("KVM: s390: KVM page table management functions: storage keys") Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Message-ID: <20260828115439.145885-8-imbrenda@linux.ibm.com>
2026-09-01KVM: s390: Add missing srcu in kvm_s390_set_irq_state()Claudio Imbrenda
Like kvm_s390_inject_vcpu(), kvm_s390_set_irq_state() also needs the kvm->srcu or the slots lock when performing the Store status operation. Fix by taking kvm->srcu in kvm_s390_set_irq_state(). Fixes: ba5c1e9b6cee ("KVM: s390: interrupt subsystem, cpu timer, waitpsw") Fixes: 062e44a9319f ("KVM: s390: Use srcu in kvm_arch_vcpu_unlocked_ioctl()") Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Message-ID: <20260828115439.145885-7-imbrenda@linux.ibm.com>
2026-09-01KVM: s390: Move all code into s390_kvm_mmu_prepare_memory_region()Claudio Imbrenda
Move all code from s390_kvm_mmu_commit_memory_region() into s390_kvm_mmu_prepare_memory_region(). This allows the function to fail gracefully if needed. The previous behaviour was to print a warning and continue execution with page tables inconsistent with the memslots. Fixes: e38c884df921 ("KVM: s390: Switch to new gmap") Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Message-ID: <20260828115439.145885-6-imbrenda@linux.ibm.com>
2026-09-01KVM: s390: Refactor dat_set_slot()Claudio Imbrenda
Refactor dat_set_slot(), _dat_slot_pte(), _dat_slot_crste(). Now they only take a struct kvm_s390_mmu_cache as priv. For dat_delete_slot(), mc is NULL, as no allocations should take place. This is needed as a prerequisite to move gmap DAT table setup from kvm_arch_commit_memory_region() to kvm_arch_prepare_memory_region(). Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Message-ID: <20260828115439.145885-5-imbrenda@linux.ibm.com>
2026-09-01KVM: s390: Fix _gaccess_shadow_fault()Claudio Imbrenda
In some circumstances, it is possible that the page of nested guest memory that is being shadowed is not present at all in the parent guest gmap. dat_entry_walk() will not find any leaf entry and return with -ENOENT, which will erroneously be propagated all the way to userspace. Fix by manually calling gmap_link() on the memory of the nested guest that is being shadowed if the mapping was not already present. Fixes: e38c884df921 ("KVM: s390: Switch to new gmap") Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Message-ID: <20260828115439.145885-4-imbrenda@linux.ibm.com>
2026-09-01KVM: s390: Fix compile warning for kvm_s390_update_cmma_dirty()Claudio Imbrenda
The parameter "old" should be marked as const, to prevent compile-time warnings. Fixes: d487a24041c2 ("KVM: s390: Prepare gmap for a second KVM implementation") Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Message-ID: <20260828115439.145885-3-imbrenda@linux.ibm.com>
2026-09-01KVM: s390: Fix dirty marking in adapter_indicators_set*()Claudio Imbrenda
When the indicator and/or summary bits are set in the guest, the accessed page was only marked dirty in KVM if the access was performed using the slow path; accesses through the new kvm_arch_set_irq_inatomic fast inject path would not mark the page as dirty. Fix by adding/moving the missing calls to mark_page_dirty(). Note that for the inatomic path set_page_dirty{,_lock}() is not needed as the page stays pinned; the unpin path correctly marks it as dirty. Opportunistically reorder the local variables to be in reverse Christmas tree order and refactor to use guard(). Fixes: 1e95e3bc6b05 ("KVM: s390: Enable adapter_indicators_set to use mapped pages") Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Message-ID: <20260828115439.145885-2-imbrenda@linux.ibm.com>
2026-08-25Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvmLinus Torvalds
Pull kvm updates from Paolo Bonzini: "ARM64: - Add support for 'slot' based PMU events, paired with new UAPI that compels the user to select a specific PMU implementation - Lazy save/restore of vCPU state for pKVM, along with various fixes and cleanups to the management of vCPU state between the untrusted host and pKVM hypervisor - Disable traps of EL1 registers for nested hypervisors when FEAT_NV2p1 is present, guaranteeing that EL2-specific register bits are stateful in the EL1 counterpart - Leverage FEAT_NV3 to avoid unnecessary ERET/TLBI traps when the scope of those instructions remains 'in host' (i.e. L1 kernel/userspace) - Pile of fixes for the management of the VNCR pseudo-TLB, such as under-invalidations and races with concurrent TLBIs on other vCPUs - Consolidate the non-protected and pKVM view of ICH_VTR_EL2 to a runtime-patched constant, allowing the same data to be shared with pKVM prior to dropping host privileges - Considerable pile of LLM-assisted fixes around the shop but mostly in the VGIC, our in-kernel generator of bugs (and sometimes interrupts) LoongArch: - Advertise already-supported capabilities - Some bug fixes about timer and MMIO - Some hardening about interrupt injection - Replace kvm_err() with kvm_pr_unimpl() - Add FPU/LSX/LASX test cases for selftests RISC-V: - Svadu/Zicfiss/Zicfilp FWFT support for Guest - Use try_cmpxchg for IMSIC MRIF RMW - More arch-specific tracepoints in KVM RISC-V - Eager page splitting when enabling dirty logging - Optimize hfence request handling for SMP Guests - Improve dirty log clearing by skipping zero bits in mask - Guard HFENCE range loops against overflow - CPU PM notifiers in KVM RISC-V for non-retentive idle states - Fix kernel-mode vector context save/restore for Guest s390: - Fixes for vfio-ap - Fixes for the gmap rework - Fixes for vsie - AI triggered fixes all over - diag9c tracing - code move preparation for the additional arm64 support - enable CONTEXT_ANALYSIS x86: - Perform spring cleaning on x86.{c,h} and asm/kvm_host.h, by adding regs.c (the kvm_cache_regs.h => regs.h is already applied) and msrs.{c,h}, and moving relevant code out of x86.c - Split kvm_mmu in three parts, respectively to describe the format of page tables, walking the guest page tables and building the page tables. Always use the same page table walker kvm->arch.gva_walk as the entry point to convert a guest's virtual address, where the previous code used two different kvm_mmu structs depending on whether the walk included nested EPT/NPT or not. Make page fault vmexits reuse the permission checking machinery that is used for guest page faults. This is both a cleanup and a baby step towards supporting XS/XU memory permissions - Document some of the "fun" gotchas with the APIC base when creating IRQCHIPs on x86 - Remove a defunct masterclock update from kvm_xen_shared_info_init(). It could result in incorrect kvmclock due to triggering an unnecessary switch to/from masterclock mode - Skip Xen runstate time updates if time has effectively gone backwards, so that the guest doesn't report 100% steal time for a very, very long time - Drop KVM's runtime updates of the Xen PV timing CPUID leaf, as KVM was updating the wrong sub-leaf, and upstream KVM will soon provide all the information needed by userspace to populate the CPUID field itself - Fix a bug where KVM would walk a newly created rmap without holding the rmap lock (or mmu_lock) during aging - Fix a bug where aging TDP MMU SPTEs could clobber FROZEN SPTEs - Fix a variety of #DB priority bugs - Fix a class of races related to enabling Hyper-V emulation on a vCPU after the vCPU is visible to the rest of KVM - Use static calls for nested virtualization ops - Move more KVM-internal code out of x86's kvm_host.h - Enumerate support for a variety of Zhaoxin instructions that don't require explicit virtualization - Fix missing EFER validation bugs, including in the KVM_SET_SREGS* path - Harden kvm_vcpu_map() against double-mapping and thus leaking references - Misc fixes and cleanups, e.g. for largely benign syzkaller splats x86 (Intel): - Zero a vCPU's entry in VMX's Posted Interrupt Descriptor table used for IPI virtualization when the vCPU is freed, to fix a use-after-free where hardware will write to a freed vCPU's PID - Service local TLB flushes on a failed nested VM-Enter to fix a bug where KVM could miss a TLB on a future, successful VM-Enter with the same L2 VPID - Cap the maximum value shoved into the VMX Preemption Timer to workaround an erratum that affects all existing Intel CPUs that support CPUID 0x15 - Fix VPID virtualization bugs where KVM would fail to flush hardware TLBs - Harden the TDX "populate" ioctls against bad input, and to prepare for supporting in-place private<=>shared conversion x86 (AMD): - Forcefully invalidate SNP VMSA pages if their backing guest_memfd page is zapped/invalidated, e.g. due to a PUNCH_HOLE in response to a Page-State Change request - Remove a dying VM from the GA Log notifier list before the VM is actually destroyed, to fix a potential use-after-free - While FOLL_WRITE was needed in the past to trigger CoW unsharing, nowadays FOLL_LONGTERM does that already even without FOLL_WRITE, and in fact, get_user_pages() actually disallows FOLL_WRITE together with FOLL_LONGTERM. So don't pass FOLL_WRITE when registering encrypted memory regions, i.e. when pinning SEV/SEV-ES guest memory, to fix a regression with file-backed memory introduced by KVM's (correct) usage of long-term pins (This was reviewed by mm maintainers; for more information, see commit ee1a586dd1fa "KVM: SEV: Drop FOLL_WRITE for encrypted region registration") - Allocate full pages for SEV/SEV-ES {DE,EN}CRYPT ops on SNP-enabled hosts to fix a data corruption issue due to the PSP driver assigning to-be-written pages to firmware (as required by the SNP specs) - Unconditionally intercept ICBEP so that KVM generates the correct guest RIP when handling an ICEBP-induced TASK_SWITCH #VMEXIT - Harden the SNP "populate" ioctls against bad input, and to prepare for supporting in-place private<=>shared conversion Generic: - Remove kvm_debugfs_dir if kvm_init() fails after creating KVM's debugfs - Add a per-VM bitmap to track which vCPU IDs have been "claimed" but for which the vCPU isn't yet online, and use the bitmap to reject duplicate IDs before calling into arch code. This allows arch code to consume vcpu_id without having to worry about cross-vCPU clobbering (at least s390 and x86 have had related bugs) - Rework the so called "prepare" and "invalidate" guest_memfd hooks to prepare for in-place private<=>shared conversion, and clean up a few warts along the way Selftests: - Automatically allocate a full page for L2 guest stacks on x86 instead of requiring test-specific L1 guest code to carve out a portion of the L1 stack for L2 usage, and to ensure the L2 stack also adheres to the x86-64 calling convention ABI - Add a selftest to verify {Guest,Host}-Only behavior in x86's mediated PMU - Clean up nested SVM's handling of GPRs on L2<=>L1 transitions, reuse the functionality for nested VMX, and drop the ucall hack that was fudging around the lack of GPR switching on nVMX - Add a stress test to verify KVM doesn't clobber/drop #PF state, e.g. CR2, across save/restore, including when L2 is active - Add a test to verify KVM_CREATE_VM accepts exactly what is reported by KVM_CAP_VM_TYPES - Misc selftests fixes and cleanups - Fix several issues with seeding the pRNG, and rework the pRNG APIs to that the pRNG can be sanely used in host code, not just guest code - Add an IRQ test to validate virtual IRQ deliverty for IRQs wired up via KVM_IRQFD + KVM_SET_GSI_ROUTING, with optional support for triggering IRQs via writes to an assigned VFIO device - Add syscall wrappers to assert success on a variety of pthreads and CPU affinity APIs - Set vCPU pthread affinity as early as possible to reduce contention issues that were surfaced by PREEMPT_LAZY, which result in runtimes of over a minute on large hosts, versus the expected ~5 seconds - Rework the PMU counters test to run each testcase using a single VM with many vCPUs for each sub-testcase, instead of using a unique VM for each sub-testcase. This cuts the runtime by ~20x Miscellaneous: - MAINTAINERS updates for vfio-ap, guest_memfd, kvm-x86. Mostly representing the status quo more accurately, but also... welcome David Hildenbrand as guest_memfd reviewer!" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (413 commits) KVM: arm64: Validate GICv5 timer PPIs before claiming ownership KVM: arm64: vgic: Reject out-of-range GICv5 PPI IDs KVM: arm64: vgic: Prevent speculative SPI array underflow KVM: arm64: vgic: Free gic_kvm_info on initialization failure KVM: arm64: Avoid mismatched accesses to 'struct kvm_nvhe_init_params' s390/vfio-ap: Fix NULL deref in status_show() during queue probe s390/vfio-ap: Fix hot-unplug skipped when last AP adapter or domain removed s390/vfio-ap: fix potential use of uninitialized apm_filtered bitmap s390/vfio-ap: Fix control domain removal in vfio_ap_mdev_cfg_remove s390/vfio-ap: Fix required lock not held during update of ap_matrix_mdev object s390/vfio-ap: Fix missing lock required to access list of ap_matrix_mdev objects s390/vfio-ap: Fix dereference matrix_mdev->kvm without checking for NULL s390/vfio-ap: Fix stale do_remove flag across iterations in vfio_ap_mdev_cfg_remove RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector riscv: vector: allow non-preemptible kernel-mode vector with IRQs off riscv: vector: refactor riscv_v_start_kernel_context KVM: s390: gmap: Make prefix handling optional KVM: s390: gmap: Make CMMA optional KVM: s390: gmap: Make storage keys optional KVM: s390: Prepare gmap for a second KVM implementation ...
2026-08-23Merge tag 's390-7.3-1' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux Pull s390 updates from Vasily Gorbik: - Add a cpuidle driver with polling and enabled wait states using the existing CPU idle infrastructure and idle governor to improve latency for frequent sleep/wakeup cycles. Remove the obsolete tick delay heuristic and generic arch_needs_cpu() hook. Add the corresponding driver entry to MAINTAINERS - Add kCFI support using the generic support provided by Clang - Enable Clang CONTEXT_ANALYSIS for various architecture code and for char, PCI, CIO and virtio drivers. Add required lock annotations, exclude unsupported mm helpers and remove conditional PCI locking - Fix secure storage access exception handling and reintroduce DCACHE_WORD_ACCESS previously removed as a workaround - Fix cpum_cf perf crashes when CPUs are brought online while per-task events are active. Allocate and remove per-CPU counter data from CPU hotplug callbacks - Fix a deadlock when an s390dbf debug area is unregistered while one of its debugfs files is being written to - Fix MVIY_PERCPU() with binutils older than 2.39, where an assembler macro silently omitted an instruction needed to repair interrupted operations after CPU migration - Remove/replace cond_resched() calls which are no-ops with the supported s390 preemption models - Fix AP queue depth and maximum message length decoding according to the architecture. Current hardware is not affected, but future hardware could report values which were handled incorrectly - Reflect the configured CPU state in cpu_enabled_mask so deconfigured CPUs are not presented as available for onlining - Restore the vDSO GNU_EH_FRAME program header which was lost when the build switched to direct linker invocation, and mark it read-only - Add SCLP action qualifiers used by Spyre for card initialization, recoverable error and telemetry reporting - Move KMSAN interrupt flag helpers out of line to fix -Wstatic-in-inline build warnings - Use level-specific page table entry accessors for hugetlb entries and ptep_get() when accessing crashed kernel memory in kdump - Make forced AP bus rescans killable so that a user process blocked behind an ongoing scan can still be terminated with SIGKILL - Rework pkey ioctl error paths to remove duplicated cleanup code and avoid freeing error pointers - Allow the protected guest SWIOTLB buffer to be allocated outside the first 2GB. Also enable dynamic SWIOTLB growth and the coherent atomic pool fallback to improve I/O behavior when the initial pool is exhausted - Add program check statistics and spinlock contention tracepoints. Increase the lockdep chain capacity to keep lockdep enabled for complex code paths such as btrfs - Simplify IPL, trap and syscall code and remove the obsolete unistd_32.h generation entry * tag 's390-7.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux: (59 commits) s390/percpu: Fix MVIY_PERCPU() with older binutils s390/debug: Fix deadlock during unregister s390/cpum_cf: Handle CPU hotplug via prepare/dead callbacks s390: Enable CONTEXT_ANALYSIS for various directories s390/mm: Add __context_unsafe() attribute to gmap helper functions s390/mm: Add __context_unsafe() attribute to do_secure_storage_access() s390/sysinfo: Add context analysis attributes s390/irqflags: Add out-of-line definitions of arch_local_irq_*() for KMSAN s390/virtio: Enable CONTEXT_ANALYSIS s390/cio: Enable CONTEXT_ANALYSIS s390/vfio_ccw: Add __must_hold() attribute to vfio_ccw_sch_quiesce() s390/pci: Enable CONTEXT_ANALYSIS s390/pci: Rework __zpci_event_availability() to remove conditional locking s390/pci: Rework __zpci_event_error() to remove conditional locking s390/char: Enable CONTEXT_ANALYSIS s390/con3215: Add __must_hold() attribute to raw3215_make_room() s390/ap: Fix MAPML computation s390/cio: Remove cond_resched() calls s390: Remove cond_resched() calls KVM: s390: Remove cond_resched() calls ...
2026-08-13KVM: s390: gmap: Make prefix handling optionalSteffen Eiden
Guard guest prefix handling behind `KVM_S390_MANAGES_S390_GUEST`. This enables other KVM implementations to use gmap without implementing prefix handling. The prefix handling is integrated deeply in the gmap implementation. Therefore, provide safe default implementations for the guarded functions. No functional changes. Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-08-13KVM: s390: gmap: Make CMMA optionalSteffen Eiden
Guard guest CMMA behind `KVM_S390_MANAGES_S390_GUEST`. This enables other KVM implementations to use gmap without implementing CMMA. No functional changes. Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-08-13KVM: s390: gmap: Make storage keys optionalSteffen Eiden
Guard guest storage key handling behind `KVM_S390_MANAGES_S390_GUEST`. This enables other KVM implementations to use gmap without implementing storage key infrastructure. Define KVM_S390_MANAGES_S390_GUEST to 1 for KVM hosts managing s390 guests (in kvm_host_s390.h). A KVM implementation not implementing those features must define KVM_S390_MANAGES_S390_GUEST to 0 in its kvm_host_<guest_arch>.h. No functional changes besides the new guard. Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-08-13KVM: s390: Prepare gmap for a second KVM implementationSteffen Eiden
Refactor gmap code such that a second s390 (host) KVM implementation can use the gmap code as well. Move mmu code from s390 to gmap so the other KVM implementation can use it as well. No functional change. Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-08-13KVM: s390: Move s390 kvm code into a subdirectorySteffen Eiden
Move all the code required to run s390 KVM guests on s390 to a s390 subdirectory. Move gmap related code into a gmap directory to later share gmap code between KVM implementations. Update S390 VFIO-PCI MAINTAINERS filepath. No functional change. Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-08-13KVM: s390: Rename kvm-s390.{c,h} to s390.{c,h}Steffen Eiden
Rename kvm-s390.c to s390.c and kvm-s390.h to s390.h for consistency with the new directory structure. Update all include statements and simplify Makefile ccflags from explicit paths to -I$(src). No functional change. Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-08-13KVM: s390: Prepare include guards for a new locationSteffen Eiden
Update include guard names in dat.h, faultin.h, and gmap.h to ARCH_KVM_GMAP_* to reflect their upcoming relocation to a shared gmap directory. No functional change. Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-08-13KVM: s390: Extract gmap tracing to a separate headerSteffen Eiden
Move the kvm_s390_major_guest_pfault trace event from trace.h to a new trace_gmap.h header. This separates gmap-specific tracing from general KVM/s390 tracing, preparing for code sharing between multiple KVM implementations. The trace event definition is updated to use local defines for parameters so that they can be replaced later with ease for when another KVM implementation uses these traces. No functional change. Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
2026-08-12Merge remote-tracking branch 'kvms390/master' into 'kvms390/next'Christian Borntraeger
2026-08-12KVM: s390: Fix potential tiny kernel stack leakClaudio Imbrenda
In some circumstances, one bit of kernel stack could have been leaked from dat_cond_set_storage_key(). Fix by clearing prev before use. Fixes: 8e03e8316eb2 ("KVM: s390: KVM page table management functions: storage keys") Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Message-ID: <20260812104436.109741-9-imbrenda@linux.ibm.com>
2026-08-12KVM: s390: Fix kvm_s390_clear_pv_state()Claudio Imbrenda
kvm_s390_clear_pv_state() needs to also clear the dumping flag, to allow the protected VM to be started again (as non-protected, with all protected state safely destroyed) after a forced reboot while a protected dump was ongoing and not completed. Fixes: e40df9efd68a ("KVM: s390: pv: clear the state without memset") Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Message-ID: <20260812104436.109741-8-imbrenda@linux.ibm.com>
2026-08-12KVM: s390: Fix IRQ injection with SIGP Stop and Store StatusClaudio Imbrenda
When __inject_sigp_stop() is called for a Stop and Store Status operation, if the vCPU is running, the interrupt is marked as pending and the status is stored by the thread performing the KVM_RUN IOCTL. If the vCPU is already stopped, the status is stored immediately. Storing the status means writing into userspace, which might fault, and __inject_sigp_stop() is called from do_inject_vcpu() which in turn is always called holding a spinlock, which is obviously an issue. Fix this by returning -EWOULDBLOCK from __inject_sigp_stop(), and adding a bool flag to indicate whether a store status is needed. The callers of do_inject_vcpu() are modified to pass the pointer to the bool flag; whenever a Store Status operation is needed, the callers can now perform it outside the spinlock. Opportunistically refactor kvm_s390_set_irq_state() to use scoped_guard() and __free(). Fixes: 6cddd432e3da ("KVM: s390: handle stop irqs without action_bits") Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> [ Added Fixes tag while picking -- Claudio ] Message-ID: <20260812104436.109741-7-imbrenda@linux.ibm.com>