diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2025-10-18 07:07:14 -1000 | 
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2025-10-18 07:07:14 -1000 | 
| commit | 02e5f74ef08d3e6afec438d571487d0d0cec3c48 (patch) | |
| tree | ef67a3baa752d10653dd20cac554257e69142021 /include | |
| parent | 0e622c4b0e02ca1946a9fadb63f00ef733e8ba28 (diff) | |
| parent | 4361f5aa8bfcecbab3fc8db987482b9e08115a6a (diff) | |
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull kvm fixes from Paolo Bonzini:
 "ARM:
   - Fix the handling of ZCR_EL2 in NV VMs
   - Pick the correct translation regime when doing a PTW on the back of
     a SEA
   - Prevent userspace from injecting an event into a vcpu that isn't
     initialised yet
   - Move timer save/restore to the sysreg handling code, fixing EL2
     timer access in the process
   - Add FGT-based trapping of MDSCR_EL1 to reduce the overhead of debug
   - Fix trapping configuration when the host isn't GICv3
   - Improve the detection of HCR_EL2.E2H being RES1
   - Drop a spurious 'break' statement in the S1 PTW
   - Don't try to access SPE when owned by EL3
  Documentation updates:
   - Document the failure modes of event injection
   - Document that a GICv3 guest can be created on a GICv5 host with
     FEAT_GCIE_LEGACY
  Selftest improvements:
   - Add a selftest for the effective value of HCR_EL2.AMO
   - Address build warning in the timer selftest when building with
     clang
   - Teach irqfd selftests about non-x86 architectures
   - Add missing sysregs to the set_id_regs selftest
   - Fix vcpu allocation in the vgic_lpi_stress selftest
   - Correctly enable interrupts in the vgic_lpi_stress selftest
  x86:
   - Expand the KVM_PRE_FAULT_MEMORY selftest to add a regression test
     for the bug fixed by commit 3ccbf6f47098 ("KVM: x86/mmu: Return
     -EAGAIN if userspace deletes/moves memslot during prefault")
   - Don't try to get PMU capabilities from perf when running a CPU with
     hybrid CPUs/PMUs, as perf will rightly WARN.
  guest_memfd:
   - Rework KVM_CAP_GUEST_MEMFD_MMAP (newly introduced in 6.18) into a
     more generic KVM_CAP_GUEST_MEMFD_FLAGS
   - Add a guest_memfd INIT_SHARED flag and require userspace to
     explicitly set said flag to initialize memory as SHARED,
     irrespective of MMAP.
     The behavior merged in 6.18 is that enabling mmap() implicitly
     initializes memory as SHARED, which would result in an ABI
     collision for x86 CoCo VMs as their memory is currently always
     initialized PRIVATE.
   - Allow mmap() on guest_memfd for x86 CoCo VMs, i.e. on VMs with
     private memory, to enable testing such setups, i.e. to hopefully
     flush out any other lurking ABI issues before 6.18 is officially
     released.
   - Add testcases to the guest_memfd selftest to cover guest_memfd
     without MMAP, and host userspace accesses to mmap()'d private
     memory"
* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (46 commits)
  arm64: Revamp HCR_EL2.E2H RES1 detection
  KVM: arm64: nv: Use FGT write trap of MDSCR_EL1 when available
  KVM: arm64: Compute per-vCPU FGTs at vcpu_load()
  KVM: arm64: selftests: Fix misleading comment about virtual timer encoding
  KVM: arm64: selftests: Add an E2H=0-specific configuration to get_reg_list
  KVM: arm64: selftests: Make dependencies on VHE-specific registers explicit
  KVM: arm64: Kill leftovers of ad-hoc timer userspace access
  KVM: arm64: Fix WFxT handling of nested virt
  KVM: arm64: Move CNT*CT_EL0 userspace accessors to generic infrastructure
  KVM: arm64: Move CNT*_CVAL_EL0 userspace accessors to generic infrastructure
  KVM: arm64: Move CNT*_CTL_EL0 userspace accessors to generic infrastructure
  KVM: arm64: Add timer UAPI workaround to sysreg infrastructure
  KVM: arm64: Make timer_set_offset() generally accessible
  KVM: arm64: Replace timer context vcpu pointer with timer_id
  KVM: arm64: Introduce timer_context_to_vcpu() helper
  KVM: arm64: Hide CNTHV_*_EL2 from userspace for nVHE guests
  Documentation: KVM: Update GICv3 docs for GICv5 hosts
  KVM: arm64: gic-v3: Only set ICH_HCR traps for v2-on-v3 or v3 guests
  KVM: arm64: selftests: Actually enable IRQs in vgic_lpi_stress
  KVM: arm64: selftests: Allocate vcpus with correct size
  ...
Diffstat (limited to 'include')
| -rw-r--r-- | include/kvm/arm_arch_timer.h | 24 | ||||
| -rw-r--r-- | include/linux/kvm_host.h | 12 | ||||
| -rw-r--r-- | include/uapi/linux/kvm.h | 5 | 
3 files changed, 30 insertions, 11 deletions
| diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h index 681cf0c8b9df..7310841f4512 100644 --- a/include/kvm/arm_arch_timer.h +++ b/include/kvm/arm_arch_timer.h @@ -51,8 +51,6 @@ struct arch_timer_vm_data {  };  struct arch_timer_context { -	struct kvm_vcpu			*vcpu; -  	/* Emulated Timer (may be unused) */  	struct hrtimer			hrtimer;  	u64				ns_frac; @@ -71,6 +69,9 @@ struct arch_timer_context {  		bool			level;  	} irq; +	/* Who am I? */ +	enum kvm_arch_timers		timer_id; +  	/* Duplicated state from arch_timer.c for convenience */  	u32				host_timer_irq;  }; @@ -106,9 +107,6 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu);  void kvm_timer_init_vm(struct kvm *kvm); -u64 kvm_arm_timer_get_reg(struct kvm_vcpu *, u64 regid); -int kvm_arm_timer_set_reg(struct kvm_vcpu *, u64 regid, u64 value); -  int kvm_arm_timer_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr);  int kvm_arm_timer_get_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr);  int kvm_arm_timer_has_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr); @@ -127,9 +125,9 @@ void kvm_timer_init_vhe(void);  #define vcpu_hvtimer(v)	(&(v)->arch.timer_cpu.timers[TIMER_HVTIMER])  #define vcpu_hptimer(v)	(&(v)->arch.timer_cpu.timers[TIMER_HPTIMER]) -#define arch_timer_ctx_index(ctx)	((ctx) - vcpu_timer((ctx)->vcpu)->timers) - -#define timer_vm_data(ctx)		(&(ctx)->vcpu->kvm->arch.timer_data) +#define arch_timer_ctx_index(ctx)	((ctx)->timer_id) +#define timer_context_to_vcpu(ctx)	container_of((ctx), struct kvm_vcpu, arch.timer_cpu.timers[(ctx)->timer_id]) +#define timer_vm_data(ctx)		(&(timer_context_to_vcpu(ctx)->kvm->arch.timer_data))  #define timer_irq(ctx)			(timer_vm_data(ctx)->ppi[arch_timer_ctx_index(ctx)])  u64 kvm_arm_timer_read_sysreg(struct kvm_vcpu *vcpu, @@ -178,4 +176,14 @@ static inline u64 timer_get_offset(struct arch_timer_context *ctxt)  	return offset;  } +static inline void timer_set_offset(struct arch_timer_context *ctxt, u64 offset) +{ +	if (!ctxt->offset.vm_offset) { +		WARN(offset, "timer %d\n", arch_timer_ctx_index(ctxt)); +		return; +	} + +	WRITE_ONCE(*ctxt->offset.vm_offset, offset); +} +  #endif diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index fa36e70df088..5bd76cf394fa 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -729,7 +729,17 @@ static inline bool kvm_arch_has_private_mem(struct kvm *kvm)  #endif  #ifdef CONFIG_KVM_GUEST_MEMFD -bool kvm_arch_supports_gmem_mmap(struct kvm *kvm); +bool kvm_arch_supports_gmem_init_shared(struct kvm *kvm); + +static inline u64 kvm_gmem_get_supported_flags(struct kvm *kvm) +{ +	u64 flags = GUEST_MEMFD_FLAG_MMAP; + +	if (!kvm || kvm_arch_supports_gmem_init_shared(kvm)) +		flags |= GUEST_MEMFD_FLAG_INIT_SHARED; + +	return flags; +}  #endif  #ifndef kvm_arch_has_readonly_mem diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 6efa98a57ec1..52f6000ab020 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -962,7 +962,7 @@ struct kvm_enable_cap {  #define KVM_CAP_ARM_EL2_E2H0 241  #define KVM_CAP_RISCV_MP_STATE_RESET 242  #define KVM_CAP_ARM_CACHEABLE_PFNMAP_SUPPORTED 243 -#define KVM_CAP_GUEST_MEMFD_MMAP 244 +#define KVM_CAP_GUEST_MEMFD_FLAGS 244  struct kvm_irq_routing_irqchip {  	__u32 irqchip; @@ -1599,7 +1599,8 @@ struct kvm_memory_attributes {  #define KVM_MEMORY_ATTRIBUTE_PRIVATE           (1ULL << 3)  #define KVM_CREATE_GUEST_MEMFD	_IOWR(KVMIO,  0xd4, struct kvm_create_guest_memfd) -#define GUEST_MEMFD_FLAG_MMAP	(1ULL << 0) +#define GUEST_MEMFD_FLAG_MMAP		(1ULL << 0) +#define GUEST_MEMFD_FLAG_INIT_SHARED	(1ULL << 1)  struct kvm_create_guest_memfd {  	__u64 size; | 
