Skip to content

Commit d8312a3

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull kvm updates from Paolo Bonzini: "ARM: - VHE optimizations - EL2 address space randomization - speculative execution mitigations ("variant 3a", aka execution past invalid privilege register access) - bugfixes and cleanups PPC: - improvements for the radix page fault handler for HV KVM on POWER9 s390: - more kvm stat counters - virtio gpu plumbing - documentation - facilities improvements x86: - support for VMware magic I/O port and pseudo-PMCs - AMD pause loop exiting - support for AMD core performance extensions - support for synchronous register access - expose nVMX capabilities to userspace - support for Hyper-V signaling via eventfd - use Enlightened VMCS when running on Hyper-V - allow userspace to disable MWAIT/HLT/PAUSE vmexits - usual roundup of optimizations and nested virtualization bugfixes Generic: - API selftest infrastructure (though the only tests are for x86 as of now)" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (174 commits) kvm: x86: fix a prototype warning kvm: selftests: add sync_regs_test kvm: selftests: add API testing infrastructure kvm: x86: fix a compile warning KVM: X86: Add Force Emulation Prefix for "emulate the next instruction" KVM: X86: Introduce handle_ud() KVM: vmx: unify adjacent #ifdefs x86: kvm: hide the unused 'cpu' variable KVM: VMX: remove bogus WARN_ON in handle_ept_misconfig Revert "KVM: X86: Fix SMRAM accessing even if VM is shutdown" kvm: Add emulation for movups/movupd KVM: VMX: raise internal error for exception during invalid protected mode state KVM: nVMX: Optimization: Dont set KVM_REQ_EVENT when VMExit with nested_run_pending KVM: nVMX: Require immediate-exit when event reinjected to L2 and L1 event pending KVM: x86: Fix misleading comments on handling pending exceptions KVM: x86: Rename interrupt.pending to interrupt.injected KVM: VMX: No need to clear pending NMI/interrupt on inject realmode interrupt x86/kvm: use Enlightened VMCS when running on Hyper-V x86/hyper-v: detect nested features x86/hyper-v: define struct hv_enlightened_vmcs and clean field bits ...
2 parents e9092d0 + e01bca2 commit d8312a3

File tree

150 files changed

+11900
-1982
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+11900
-1982
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,9 @@
19071907
kvm.ignore_msrs=[KVM] Ignore guest accesses to unhandled MSRs.
19081908
Default is 0 (don't ignore, but inject #GP)
19091909

1910+
kvm.enable_vmware_backdoor=[KVM] Support VMware backdoor PV interface.
1911+
Default is false (don't support).
1912+
19101913
kvm.mmu_audit= [KVM] This is a R/W parameter which allows audit
19111914
KVM MMU at runtime.
19121915
Default is 0 (off)

Documentation/arm64/memory.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ Translation table lookup with 64KB pages:
8686
+-------------------------------------------------> [63] TTBR0/1
8787

8888

89-
When using KVM without the Virtualization Host Extensions, the hypervisor
90-
maps kernel pages in EL2 at a fixed offset from the kernel VA. See the
91-
kern_hyp_va macro for more details.
89+
When using KVM without the Virtualization Host Extensions, the
90+
hypervisor maps kernel pages in EL2 at a fixed (and potentially
91+
random) offset from the linear mapping. See the kern_hyp_va macro and
92+
kvm_update_va_mask function for more details. MMIO devices such as
93+
GICv2 gets mapped next to the HYP idmap page, as do vectors when
94+
ARM64_HARDEN_EL2_VECTORS is selected for particular CPUs.
9295

9396
When using KVM with the Virtualization Host Extensions, no additional
9497
mappings are created, since the host kernel runs directly in EL2.

Documentation/virtual/kvm/00-INDEX

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
00-INDEX
22
- this file.
3+
amd-memory-encryption.rst
4+
- notes on AMD Secure Encrypted Virtualization feature and SEV firmware
5+
command description
36
api.txt
47
- KVM userspace API.
8+
arm
9+
- internal ABI between the kernel and HYP (for arm/arm64)
510
cpuid.txt
611
- KVM-specific cpuid leaves (x86).
712
devices/
@@ -26,6 +31,5 @@ s390-diag.txt
2631
- Diagnose hypercall description (for IBM S/390)
2732
timekeeping.txt
2833
- timekeeping virtualization for x86-based architectures.
29-
amd-memory-encryption.txt
30-
- notes on AMD Secure Encrypted Virtualization feature and SEV firmware
31-
command description
34+
vcpu-requests.rst
35+
- internal VCPU request API

Documentation/virtual/kvm/api.txt

Lines changed: 124 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3480,7 +3480,7 @@ encrypted VMs.
34803480

34813481
Currently, this ioctl is used for issuing Secure Encrypted Virtualization
34823482
(SEV) commands on AMD Processors. The SEV commands are defined in
3483-
Documentation/virtual/kvm/amd-memory-encryption.txt.
3483+
Documentation/virtual/kvm/amd-memory-encryption.rst.
34843484

34853485
4.111 KVM_MEMORY_ENCRYPT_REG_REGION
34863486

@@ -3516,6 +3516,38 @@ Returns: 0 on success; -1 on error
35163516
This ioctl can be used to unregister the guest memory region registered
35173517
with KVM_MEMORY_ENCRYPT_REG_REGION ioctl above.
35183518

3519+
4.113 KVM_HYPERV_EVENTFD
3520+
3521+
Capability: KVM_CAP_HYPERV_EVENTFD
3522+
Architectures: x86
3523+
Type: vm ioctl
3524+
Parameters: struct kvm_hyperv_eventfd (in)
3525+
3526+
This ioctl (un)registers an eventfd to receive notifications from the guest on
3527+
the specified Hyper-V connection id through the SIGNAL_EVENT hypercall, without
3528+
causing a user exit. SIGNAL_EVENT hypercall with non-zero event flag number
3529+
(bits 24-31) still triggers a KVM_EXIT_HYPERV_HCALL user exit.
3530+
3531+
struct kvm_hyperv_eventfd {
3532+
__u32 conn_id;
3533+
__s32 fd;
3534+
__u32 flags;
3535+
__u32 padding[3];
3536+
};
3537+
3538+
The conn_id field should fit within 24 bits:
3539+
3540+
#define KVM_HYPERV_CONN_ID_MASK 0x00ffffff
3541+
3542+
The acceptable values for the flags field are:
3543+
3544+
#define KVM_HYPERV_EVENTFD_DEASSIGN (1 << 0)
3545+
3546+
Returns: 0 on success,
3547+
-EINVAL if conn_id or flags is outside the allowed range
3548+
-ENOENT on deassign if the conn_id isn't registered
3549+
-EEXIST on assign if the conn_id is already registered
3550+
35193551

35203552
5. The kvm_run structure
35213553
------------------------
@@ -3873,7 +3905,7 @@ in userspace.
38733905
__u64 kvm_dirty_regs;
38743906
union {
38753907
struct kvm_sync_regs regs;
3876-
char padding[1024];
3908+
char padding[SYNC_REGS_SIZE_BYTES];
38773909
} s;
38783910

38793911
If KVM_CAP_SYNC_REGS is defined, these fields allow userspace to access
@@ -4078,6 +4110,46 @@ Once this is done the KVM_REG_MIPS_VEC_* and KVM_REG_MIPS_MSA_* registers can be
40784110
accessed, and the Config5.MSAEn bit is accessible via the KVM API and also from
40794111
the guest.
40804112

4113+
6.74 KVM_CAP_SYNC_REGS
4114+
Architectures: s390, x86
4115+
Target: s390: always enabled, x86: vcpu
4116+
Parameters: none
4117+
Returns: x86: KVM_CHECK_EXTENSION returns a bit-array indicating which register
4118+
sets are supported (bitfields defined in arch/x86/include/uapi/asm/kvm.h).
4119+
4120+
As described above in the kvm_sync_regs struct info in section 5 (kvm_run):
4121+
KVM_CAP_SYNC_REGS "allow[s] userspace to access certain guest registers
4122+
without having to call SET/GET_*REGS". This reduces overhead by eliminating
4123+
repeated ioctl calls for setting and/or getting register values. This is
4124+
particularly important when userspace is making synchronous guest state
4125+
modifications, e.g. when emulating and/or intercepting instructions in
4126+
userspace.
4127+
4128+
For s390 specifics, please refer to the source code.
4129+
4130+
For x86:
4131+
- the register sets to be copied out to kvm_run are selectable
4132+
by userspace (rather that all sets being copied out for every exit).
4133+
- vcpu_events are available in addition to regs and sregs.
4134+
4135+
For x86, the 'kvm_valid_regs' field of struct kvm_run is overloaded to
4136+
function as an input bit-array field set by userspace to indicate the
4137+
specific register sets to be copied out on the next exit.
4138+
4139+
To indicate when userspace has modified values that should be copied into
4140+
the vCPU, the all architecture bitarray field, 'kvm_dirty_regs' must be set.
4141+
This is done using the same bitflags as for the 'kvm_valid_regs' field.
4142+
If the dirty bit is not set, then the register set values will not be copied
4143+
into the vCPU even if they've been modified.
4144+
4145+
Unused bitfields in the bitarrays must be set to zero.
4146+
4147+
struct kvm_sync_regs {
4148+
struct kvm_regs regs;
4149+
struct kvm_sregs sregs;
4150+
struct kvm_vcpu_events events;
4151+
};
4152+
40814153
7. Capabilities that can be enabled on VMs
40824154
------------------------------------------
40834155

@@ -4286,6 +4358,26 @@ enables QEMU to build error log and branch to guest kernel registered
42864358
machine check handling routine. Without this capability KVM will
42874359
branch to guests' 0x200 interrupt vector.
42884360

4361+
7.13 KVM_CAP_X86_DISABLE_EXITS
4362+
4363+
Architectures: x86
4364+
Parameters: args[0] defines which exits are disabled
4365+
Returns: 0 on success, -EINVAL when args[0] contains invalid exits
4366+
4367+
Valid bits in args[0] are
4368+
4369+
#define KVM_X86_DISABLE_EXITS_MWAIT (1 << 0)
4370+
#define KVM_X86_DISABLE_EXITS_HLT (1 << 1)
4371+
4372+
Enabling this capability on a VM provides userspace with a way to no
4373+
longer intercept some instructions for improved latency in some
4374+
workloads, and is suggested when vCPUs are associated to dedicated
4375+
physical CPUs. More bits can be added in the future; userspace can
4376+
just pass the KVM_CHECK_EXTENSION result to KVM_ENABLE_CAP to disable
4377+
all such vmexits.
4378+
4379+
Do not enable KVM_FEATURE_PV_UNHALT if you disable HLT exits.
4380+
42894381
8. Other capabilities.
42904382
----------------------
42914383

@@ -4398,15 +4490,6 @@ reserved.
43984490
Both registers and addresses are 64-bits wide.
43994491
It will be possible to run 64-bit or 32-bit guest code.
44004492

4401-
8.8 KVM_CAP_X86_GUEST_MWAIT
4402-
4403-
Architectures: x86
4404-
4405-
This capability indicates that guest using memory monotoring instructions
4406-
(MWAIT/MWAITX) to stop the virtual CPU will not cause a VM exit. As such time
4407-
spent while virtual CPU is halted in this way will then be accounted for as
4408-
guest running time on the host (as opposed to e.g. HLT).
4409-
44104493
8.9 KVM_CAP_ARM_USER_IRQ
44114494

44124495
Architectures: arm, arm64
@@ -4483,3 +4566,33 @@ Parameters: none
44834566
This capability indicates if the flic device will be able to get/set the
44844567
AIS states for migration via the KVM_DEV_FLIC_AISM_ALL attribute and allows
44854568
to discover this without having to create a flic device.
4569+
4570+
8.14 KVM_CAP_S390_PSW
4571+
4572+
Architectures: s390
4573+
4574+
This capability indicates that the PSW is exposed via the kvm_run structure.
4575+
4576+
8.15 KVM_CAP_S390_GMAP
4577+
4578+
Architectures: s390
4579+
4580+
This capability indicates that the user space memory used as guest mapping can
4581+
be anywhere in the user memory address space, as long as the memory slots are
4582+
aligned and sized to a segment (1MB) boundary.
4583+
4584+
8.16 KVM_CAP_S390_COW
4585+
4586+
Architectures: s390
4587+
4588+
This capability indicates that the user space memory used as guest mapping can
4589+
use copy-on-write semantics as well as dirty pages tracking via read-only page
4590+
tables.
4591+
4592+
8.17 KVM_CAP_S390_BPB
4593+
4594+
Architectures: s390
4595+
4596+
This capability indicates that kvm will implement the interfaces to handle
4597+
reset, migration and nested KVM for branch prediction blocking. The stfle
4598+
facility 82 should not be provided to the guest without this capability.

Documentation/virtual/kvm/cpuid.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ This function queries the presence of KVM cpuid leafs.
2323

2424

2525
function: define KVM_CPUID_FEATURES (0x40000001)
26-
returns : ebx, ecx, edx = 0
27-
eax = and OR'ed group of (1 << flag), where each flags is:
26+
returns : ebx, ecx
27+
eax = an OR'ed group of (1 << flag), where each flags is:
2828

2929

3030
flag || value || meaning
@@ -66,3 +66,14 @@ KVM_FEATURE_CLOCKSOURCE_STABLE_BIT || 24 || host will warn if no guest-side
6666
|| || per-cpu warps are expected in
6767
|| || kvmclock.
6868
------------------------------------------------------------------------------
69+
70+
edx = an OR'ed group of (1 << flag), where each flags is:
71+
72+
73+
flag || value || meaning
74+
==================================================================================
75+
KVM_HINTS_DEDICATED || 0 || guest checks this feature bit to
76+
|| || determine if there is vCPU pinning
77+
|| || and there is no vCPU over-commitment,
78+
|| || allowing optimizations
79+
----------------------------------------------------------------------------------

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6516,7 +6516,7 @@ S: Maintained
65166516
F: Documentation/networking/netvsc.txt
65176517
F: arch/x86/include/asm/mshyperv.h
65186518
F: arch/x86/include/asm/trace/hyperv.h
6519-
F: arch/x86/include/uapi/asm/hyperv.h
6519+
F: arch/x86/include/asm/hyperv-tlfs.h
65206520
F: arch/x86/kernel/cpu/mshyperv.c
65216521
F: arch/x86/hyperv
65226522
F: drivers/hid/hid-hyperv.c

arch/arm/include/asm/kvm_asm.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ extern void __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu);
7070

7171
extern void __kvm_timer_set_cntvoff(u32 cntvoff_low, u32 cntvoff_high);
7272

73-
extern int __kvm_vcpu_run(struct kvm_vcpu *vcpu);
73+
/* no VHE on 32-bit :( */
74+
static inline int kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu) { BUG(); return 0; }
75+
76+
extern int __kvm_vcpu_run_nvhe(struct kvm_vcpu *vcpu);
7477

7578
extern void __init_stage2_translation(void);
7679

arch/arm/include/asm/kvm_emulate.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,17 @@ static inline unsigned long *vcpu_reg32(struct kvm_vcpu *vcpu, u8 reg_num)
4141
return vcpu_reg(vcpu, reg_num);
4242
}
4343

44-
unsigned long *vcpu_spsr(struct kvm_vcpu *vcpu);
44+
unsigned long *__vcpu_spsr(struct kvm_vcpu *vcpu);
45+
46+
static inline unsigned long vpcu_read_spsr(struct kvm_vcpu *vcpu)
47+
{
48+
return *__vcpu_spsr(vcpu);
49+
}
50+
51+
static inline void vcpu_write_spsr(struct kvm_vcpu *vcpu, unsigned long v)
52+
{
53+
*__vcpu_spsr(vcpu) = v;
54+
}
4555

4656
static inline unsigned long vcpu_get_reg(struct kvm_vcpu *vcpu,
4757
u8 reg_num)
@@ -92,14 +102,9 @@ static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu)
92102
vcpu->arch.hcr = HCR_GUEST_MASK;
93103
}
94104

95-
static inline unsigned long vcpu_get_hcr(const struct kvm_vcpu *vcpu)
96-
{
97-
return vcpu->arch.hcr;
98-
}
99-
100-
static inline void vcpu_set_hcr(struct kvm_vcpu *vcpu, unsigned long hcr)
105+
static inline unsigned long *vcpu_hcr(const struct kvm_vcpu *vcpu)
101106
{
102-
vcpu->arch.hcr = hcr;
107+
return (unsigned long *)&vcpu->arch.hcr;
103108
}
104109

105110
static inline bool vcpu_mode_is_32bit(const struct kvm_vcpu *vcpu)

arch/arm/include/asm/kvm_host.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ struct kvm_vcpu_arch {
155155
/* HYP trapping configuration */
156156
u32 hcr;
157157

158-
/* Interrupt related fields */
159-
u32 irq_lines; /* IRQ and FIQ levels */
160-
161158
/* Exception Information */
162159
struct kvm_vcpu_fault_info fault;
163160

@@ -315,4 +312,7 @@ static inline bool kvm_arm_harden_branch_predictor(void)
315312
return false;
316313
}
317314

315+
static inline void kvm_vcpu_load_sysregs(struct kvm_vcpu *vcpu) {}
316+
static inline void kvm_vcpu_put_sysregs(struct kvm_vcpu *vcpu) {}
317+
318318
#endif /* __ARM_KVM_HOST_H__ */

arch/arm/include/asm/kvm_hyp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ void __sysreg_restore_state(struct kvm_cpu_context *ctxt);
110110

111111
void __vgic_v3_save_state(struct kvm_vcpu *vcpu);
112112
void __vgic_v3_restore_state(struct kvm_vcpu *vcpu);
113+
void __vgic_v3_activate_traps(struct kvm_vcpu *vcpu);
114+
void __vgic_v3_deactivate_traps(struct kvm_vcpu *vcpu);
115+
void __vgic_v3_save_aprs(struct kvm_vcpu *vcpu);
116+
void __vgic_v3_restore_aprs(struct kvm_vcpu *vcpu);
113117

114118
asmlinkage void __vfp_save_state(struct vfp_hard_struct *vfp);
115119
asmlinkage void __vfp_restore_state(struct vfp_hard_struct *vfp);

arch/arm/include/asm/kvm_mmu.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
*/
2929
#define kern_hyp_va(kva) (kva)
3030

31+
/* Contrary to arm64, there is no need to generate a PC-relative address */
32+
#define hyp_symbol_addr(s) \
33+
({ \
34+
typeof(s) *addr = &(s); \
35+
addr; \
36+
})
37+
3138
/*
3239
* KVM_MMU_CACHE_MIN_PAGES is the number of stage2 page table translation levels.
3340
*/
@@ -42,8 +49,15 @@
4249
#include <asm/pgalloc.h>
4350
#include <asm/stage2_pgtable.h>
4451

52+
/* Ensure compatibility with arm64 */
53+
#define VA_BITS 32
54+
4555
int create_hyp_mappings(void *from, void *to, pgprot_t prot);
46-
int create_hyp_io_mappings(void *from, void *to, phys_addr_t);
56+
int create_hyp_io_mappings(phys_addr_t phys_addr, size_t size,
57+
void __iomem **kaddr,
58+
void __iomem **haddr);
59+
int create_hyp_exec_mappings(phys_addr_t phys_addr, size_t size,
60+
void **haddr);
4761
void free_hyp_pgds(void);
4862

4963
void stage2_unmap_vm(struct kvm *kvm);

arch/arm/include/uapi/asm/kvm.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@ struct kvm_arch_memory_slot {
135135
#define KVM_REG_ARM_CRM_SHIFT 7
136136
#define KVM_REG_ARM_32_CRN_MASK 0x0000000000007800
137137
#define KVM_REG_ARM_32_CRN_SHIFT 11
138+
/*
139+
* For KVM currently all guest registers are nonsecure, but we reserve a bit
140+
* in the encoding to distinguish secure from nonsecure for AArch32 system
141+
* registers that are banked by security. This is 1 for the secure banked
142+
* register, and 0 for the nonsecure banked register or if the register is
143+
* not banked by security.
144+
*/
145+
#define KVM_REG_ARM_SECURE_MASK 0x0000000010000000
146+
#define KVM_REG_ARM_SECURE_SHIFT 28
138147

139148
#define ARM_CP15_REG_SHIFT_MASK(x,n) \
140149
(((x) << KVM_REG_ARM_ ## n ## _SHIFT) & KVM_REG_ARM_ ## n ## _MASK)

0 commit comments

Comments
 (0)