Skip to content

Commit 63fc9c2

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull KVM fixes from Paolo Bonzini: "A collection of x86 and ARM bugfixes, and some improvements to documentation. On top of this, a cleanup of kvm_para.h headers, which were exported by some architectures even though they not support KVM at all. This is responsible for all the Kbuild changes in the diffstat" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (28 commits) Documentation: kvm: clarify KVM_SET_USER_MEMORY_REGION KVM: doc: Document the life cycle of a VM and its resources KVM: selftests: complete IO before migrating guest state KVM: selftests: disable stack protector for all KVM tests KVM: selftests: explicitly disable PIE for tests KVM: selftests: assert on exit reason in CR4/cpuid sync test KVM: x86: update %rip after emulating IO x86/kvm/hyper-v: avoid spurious pending stimer on vCPU init kvm/x86: Move MSR_IA32_ARCH_CAPABILITIES to array emulated_msrs KVM: x86: Emulate MSR_IA32_ARCH_CAPABILITIES on AMD hosts kvm: don't redefine flags as something else kvm: mmu: Used range based flushing in slot_handle_level_range KVM: export <linux/kvm_para.h> and <asm/kvm_para.h> iif KVM is supported KVM: x86: remove check on nr_mmu_pages in kvm_arch_commit_memory_region() kvm: nVMX: Add a vmentry check for HOST_SYSENTER_ESP and HOST_SYSENTER_EIP fields KVM: SVM: Workaround errata#1096 (insn_len maybe zero on SMAP violation) KVM: Reject device ioctls from processes other than the VM's creator KVM: doc: Fix incorrect word ordering regarding supported use of APIs KVM: x86: fix handling of role.cr4_pae and rename it to 'gpte_size' KVM: nVMX: Do not inherit quadrant and invalid for the root shadow EPT ...
2 parents 915ee0d + 690edec commit 63fc9c2

File tree

60 files changed

+409
-201
lines changed

Some content is hidden

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

60 files changed

+409
-201
lines changed

Documentation/virtual/kvm/api.txt

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,32 @@ The Definitive KVM (Kernel-based Virtual Machine) API Documentation
55
----------------------
66

77
The kvm API is a set of ioctls that are issued to control various aspects
8-
of a virtual machine. The ioctls belong to three classes
8+
of a virtual machine. The ioctls belong to three classes:
99

1010
- System ioctls: These query and set global attributes which affect the
1111
whole kvm subsystem. In addition a system ioctl is used to create
12-
virtual machines
12+
virtual machines.
1313

1414
- VM ioctls: These query and set attributes that affect an entire virtual
1515
machine, for example memory layout. In addition a VM ioctl is used to
16-
create virtual cpus (vcpus).
16+
create virtual cpus (vcpus) and devices.
1717

18-
Only run VM ioctls from the same process (address space) that was used
19-
to create the VM.
18+
VM ioctls must be issued from the same process (address space) that was
19+
used to create the VM.
2020

2121
- vcpu ioctls: These query and set attributes that control the operation
2222
of a single virtual cpu.
2323

24-
Only run vcpu ioctls from the same thread that was used to create the
25-
vcpu.
24+
vcpu ioctls should be issued from the same thread that was used to create
25+
the vcpu, except for asynchronous vcpu ioctl that are marked as such in
26+
the documentation. Otherwise, the first ioctl after switching threads
27+
could see a performance impact.
2628

29+
- device ioctls: These query and set attributes that control the operation
30+
of a single device.
31+
32+
device ioctls must be issued from the same process (address space) that
33+
was used to create the VM.
2734

2835
2. File descriptors
2936
-------------------
@@ -32,17 +39,34 @@ The kvm API is centered around file descriptors. An initial
3239
open("/dev/kvm") obtains a handle to the kvm subsystem; this handle
3340
can be used to issue system ioctls. A KVM_CREATE_VM ioctl on this
3441
handle will create a VM file descriptor which can be used to issue VM
35-
ioctls. A KVM_CREATE_VCPU ioctl on a VM fd will create a virtual cpu
36-
and return a file descriptor pointing to it. Finally, ioctls on a vcpu
37-
fd can be used to control the vcpu, including the important task of
38-
actually running guest code.
42+
ioctls. A KVM_CREATE_VCPU or KVM_CREATE_DEVICE ioctl on a VM fd will
43+
create a virtual cpu or device and return a file descriptor pointing to
44+
the new resource. Finally, ioctls on a vcpu or device fd can be used
45+
to control the vcpu or device. For vcpus, this includes the important
46+
task of actually running guest code.
3947

4048
In general file descriptors can be migrated among processes by means
4149
of fork() and the SCM_RIGHTS facility of unix domain socket. These
4250
kinds of tricks are explicitly not supported by kvm. While they will
4351
not cause harm to the host, their actual behavior is not guaranteed by
44-
the API. The only supported use is one virtual machine per process,
45-
and one vcpu per thread.
52+
the API. See "General description" for details on the ioctl usage
53+
model that is supported by KVM.
54+
55+
It is important to note that althought VM ioctls may only be issued from
56+
the process that created the VM, a VM's lifecycle is associated with its
57+
file descriptor, not its creator (process). In other words, the VM and
58+
its resources, *including the associated address space*, are not freed
59+
until the last reference to the VM's file descriptor has been released.
60+
For example, if fork() is issued after ioctl(KVM_CREATE_VM), the VM will
61+
not be freed until both the parent (original) process and its child have
62+
put their references to the VM's file descriptor.
63+
64+
Because a VM's resources are not freed until the last reference to its
65+
file descriptor is released, creating additional references to a VM via
66+
via fork(), dup(), etc... without careful consideration is strongly
67+
discouraged and may have unwanted side effects, e.g. memory allocated
68+
by and on behalf of the VM's process may not be freed/unaccounted when
69+
the VM is shut down.
4670

4771

4872
It is important to note that althought VM ioctls may only be issued from
@@ -515,11 +539,15 @@ c) KVM_INTERRUPT_SET_LEVEL
515539
Note that any value for 'irq' other than the ones stated above is invalid
516540
and incurs unexpected behavior.
517541

542+
This is an asynchronous vcpu ioctl and can be invoked from any thread.
543+
518544
MIPS:
519545

520546
Queues an external interrupt to be injected into the virtual CPU. A negative
521547
interrupt number dequeues the interrupt.
522548

549+
This is an asynchronous vcpu ioctl and can be invoked from any thread.
550+
523551

524552
4.17 KVM_DEBUG_GUEST
525553

@@ -1086,14 +1114,12 @@ struct kvm_userspace_memory_region {
10861114
#define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0)
10871115
#define KVM_MEM_READONLY (1UL << 1)
10881116

1089-
This ioctl allows the user to create or modify a guest physical memory
1090-
slot. When changing an existing slot, it may be moved in the guest
1091-
physical memory space, or its flags may be modified. It may not be
1092-
resized. Slots may not overlap in guest physical address space.
1093-
Bits 0-15 of "slot" specifies the slot id and this value should be
1094-
less than the maximum number of user memory slots supported per VM.
1095-
The maximum allowed slots can be queried using KVM_CAP_NR_MEMSLOTS,
1096-
if this capability is supported by the architecture.
1117+
This ioctl allows the user to create, modify or delete a guest physical
1118+
memory slot. Bits 0-15 of "slot" specify the slot id and this value
1119+
should be less than the maximum number of user memory slots supported per
1120+
VM. The maximum allowed slots can be queried using KVM_CAP_NR_MEMSLOTS,
1121+
if this capability is supported by the architecture. Slots may not
1122+
overlap in guest physical address space.
10971123

10981124
If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of "slot"
10991125
specifies the address space which is being modified. They must be
@@ -1102,6 +1128,10 @@ KVM_CAP_MULTI_ADDRESS_SPACE capability. Slots in separate address spaces
11021128
are unrelated; the restriction on overlapping slots only applies within
11031129
each address space.
11041130

1131+
Deleting a slot is done by passing zero for memory_size. When changing
1132+
an existing slot, it may be moved in the guest physical memory space,
1133+
or its flags may be modified, but it may not be resized.
1134+
11051135
Memory for the region is taken starting at the address denoted by the
11061136
field userspace_addr, which must point at user addressable memory for
11071137
the entire memory slot size. Any object may back this memory, including
@@ -2493,7 +2523,7 @@ KVM_S390_MCHK (vm, vcpu) - machine check interrupt; cr 14 bits in parm,
24932523
machine checks needing further payload are not
24942524
supported by this ioctl)
24952525

2496-
Note that the vcpu ioctl is asynchronous to vcpu execution.
2526+
This is an asynchronous vcpu ioctl and can be invoked from any thread.
24972527

24982528
4.78 KVM_PPC_GET_HTAB_FD
24992529

@@ -3042,8 +3072,7 @@ KVM_S390_INT_EMERGENCY - sigp emergency; parameters in .emerg
30423072
KVM_S390_INT_EXTERNAL_CALL - sigp external call; parameters in .extcall
30433073
KVM_S390_MCHK - machine check interrupt; parameters in .mchk
30443074

3045-
3046-
Note that the vcpu ioctl is asynchronous to vcpu execution.
3075+
This is an asynchronous vcpu ioctl and can be invoked from any thread.
30473076

30483077
4.94 KVM_S390_GET_IRQ_STATE
30493078

Documentation/virtual/kvm/mmu.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Shadow pages contain the following information:
142142
If clear, this page corresponds to a guest page table denoted by the gfn
143143
field.
144144
role.quadrant:
145-
When role.cr4_pae=0, the guest uses 32-bit gptes while the host uses 64-bit
145+
When role.gpte_is_8_bytes=0, the guest uses 32-bit gptes while the host uses 64-bit
146146
sptes. That means a guest page table contains more ptes than the host,
147147
so multiple shadow pages are needed to shadow one guest page.
148148
For first-level shadow pages, role.quadrant can be 0 or 1 and denotes the
@@ -158,9 +158,9 @@ Shadow pages contain the following information:
158158
The page is invalid and should not be used. It is a root page that is
159159
currently pinned (by a cpu hardware register pointing to it); once it is
160160
unpinned it will be destroyed.
161-
role.cr4_pae:
162-
Contains the value of cr4.pae for which the page is valid (e.g. whether
163-
32-bit or 64-bit gptes are in use).
161+
role.gpte_is_8_bytes:
162+
Reflects the size of the guest PTE for which the page is valid, i.e. '1'
163+
if 64-bit gptes are in use, '0' if 32-bit gptes are in use.
164164
role.nxe:
165165
Contains the value of efer.nxe for which the page is valid.
166166
role.cr0_wp:
@@ -173,6 +173,9 @@ Shadow pages contain the following information:
173173
Contains the value of cr4.smap && !cr0.wp for which the page is valid
174174
(pages for which this is true are different from other pages; see the
175175
treatment of cr0.wp=0 below).
176+
role.ept_sp:
177+
This is a virtual flag to denote a shadowed nested EPT page. ept_sp
178+
is true if "cr0_wp && smap_andnot_wp", an otherwise invalid combination.
176179
role.smm:
177180
Is 1 if the page is valid in system management mode. This field
178181
determines which of the kvm_memslots array was used to build this

arch/alpha/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ generic-y += exec.h
66
generic-y += export.h
77
generic-y += fb.h
88
generic-y += irq_work.h
9+
generic-y += kvm_para.h
910
generic-y += mcs_spinlock.h
1011
generic-y += mm-arch-hooks.h
1112
generic-y += preempt.h

arch/alpha/include/uapi/asm/kvm_para.h

Lines changed: 0 additions & 2 deletions
This file was deleted.

arch/arc/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ generic-y += hardirq.h
1111
generic-y += hw_irq.h
1212
generic-y += irq_regs.h
1313
generic-y += irq_work.h
14+
generic-y += kvm_para.h
1415
generic-y += local.h
1516
generic-y += local64.h
1617
generic-y += mcs_spinlock.h

arch/arc/include/uapi/asm/Kbuild

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
generic-y += kvm_para.h
21
generic-y += ucontext.h

arch/arm/include/asm/kvm_mmu.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,17 @@ static inline int kvm_read_guest_lock(struct kvm *kvm,
381381
return ret;
382382
}
383383

384+
static inline int kvm_write_guest_lock(struct kvm *kvm, gpa_t gpa,
385+
const void *data, unsigned long len)
386+
{
387+
int srcu_idx = srcu_read_lock(&kvm->srcu);
388+
int ret = kvm_write_guest(kvm, gpa, data, len);
389+
390+
srcu_read_unlock(&kvm->srcu, srcu_idx);
391+
392+
return ret;
393+
}
394+
384395
static inline void *kvm_get_hyp_vector(void)
385396
{
386397
switch(read_cpuid_part()) {

arch/arm/include/asm/stage2_pgtable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ static inline bool kvm_stage2_has_pud(struct kvm *kvm)
7575

7676
#define S2_PMD_MASK PMD_MASK
7777
#define S2_PMD_SIZE PMD_SIZE
78+
#define S2_PUD_MASK PUD_MASK
79+
#define S2_PUD_SIZE PUD_SIZE
7880

7981
static inline bool kvm_stage2_has_pmd(struct kvm *kvm)
8082
{

arch/arm/include/uapi/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
generated-y += unistd-common.h
44
generated-y += unistd-oabi.h
55
generated-y += unistd-eabi.h
6+
generic-y += kvm_para.h

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

Lines changed: 0 additions & 2 deletions
This file was deleted.

arch/arm64/include/asm/kvm_mmu.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,17 @@ static inline int kvm_read_guest_lock(struct kvm *kvm,
445445
return ret;
446446
}
447447

448+
static inline int kvm_write_guest_lock(struct kvm *kvm, gpa_t gpa,
449+
const void *data, unsigned long len)
450+
{
451+
int srcu_idx = srcu_read_lock(&kvm->srcu);
452+
int ret = kvm_write_guest(kvm, gpa, data, len);
453+
454+
srcu_read_unlock(&kvm->srcu, srcu_idx);
455+
456+
return ret;
457+
}
458+
448459
#ifdef CONFIG_KVM_INDIRECT_VECTORS
449460
/*
450461
* EL2 vectors can be mapped and rerouted in a number of ways,

arch/arm64/kvm/reset.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
123123
int ret = -EINVAL;
124124
bool loaded;
125125

126+
/* Reset PMU outside of the non-preemptible section */
127+
kvm_pmu_vcpu_reset(vcpu);
128+
126129
preempt_disable();
127130
loaded = (vcpu->cpu != -1);
128131
if (loaded)
@@ -170,9 +173,6 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
170173
vcpu->arch.reset_state.reset = false;
171174
}
172175

173-
/* Reset PMU */
174-
kvm_pmu_vcpu_reset(vcpu);
175-
176176
/* Default workaround setup is enabled (if supported) */
177177
if (kvm_arm_have_ssbd() == KVM_SSBD_KERNEL)
178178
vcpu->arch.workaround_flags |= VCPU_WORKAROUND_2_FLAG;

arch/c6x/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ generic-y += irq_work.h
1919
generic-y += kdebug.h
2020
generic-y += kmap_types.h
2121
generic-y += kprobes.h
22+
generic-y += kvm_para.h
2223
generic-y += local.h
2324
generic-y += mcs_spinlock.h
2425
generic-y += mm-arch-hooks.h

arch/c6x/include/uapi/asm/Kbuild

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
generic-y += kvm_para.h
21
generic-y += ucontext.h

arch/h8300/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ generic-y += irq_work.h
2323
generic-y += kdebug.h
2424
generic-y += kmap_types.h
2525
generic-y += kprobes.h
26+
generic-y += kvm_para.h
2627
generic-y += linkage.h
2728
generic-y += local.h
2829
generic-y += local64.h

arch/h8300/include/uapi/asm/Kbuild

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
generic-y += kvm_para.h
21
generic-y += ucontext.h

arch/hexagon/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ generic-y += irq_work.h
1919
generic-y += kdebug.h
2020
generic-y += kmap_types.h
2121
generic-y += kprobes.h
22+
generic-y += kvm_para.h
2223
generic-y += local.h
2324
generic-y += local64.h
2425
generic-y += mcs_spinlock.h

arch/hexagon/include/uapi/asm/kvm_para.h

Lines changed: 0 additions & 2 deletions
This file was deleted.

arch/ia64/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ generated-y += syscall_table.h
22
generic-y += compat.h
33
generic-y += exec.h
44
generic-y += irq_work.h
5+
generic-y += kvm_para.h
56
generic-y += mcs_spinlock.h
67
generic-y += mm-arch-hooks.h
78
generic-y += preempt.h

arch/ia64/include/uapi/asm/Kbuild

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
generated-y += unistd_64.h
2-
generic-y += kvm_para.h

arch/m68k/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ generic-y += irq_work.h
1313
generic-y += kdebug.h
1414
generic-y += kmap_types.h
1515
generic-y += kprobes.h
16+
generic-y += kvm_para.h
1617
generic-y += local.h
1718
generic-y += local64.h
1819
generic-y += mcs_spinlock.h

arch/m68k/include/uapi/asm/Kbuild

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
generated-y += unistd_32.h
2-
generic-y += kvm_para.h

arch/microblaze/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ generic-y += irq_work.h
1717
generic-y += kdebug.h
1818
generic-y += kmap_types.h
1919
generic-y += kprobes.h
20+
generic-y += kvm_para.h
2021
generic-y += linkage.h
2122
generic-y += local.h
2223
generic-y += local64.h
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
generated-y += unistd_32.h
2-
generic-y += kvm_para.h
32
generic-y += ucontext.h

arch/nios2/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ generic-y += irq_work.h
2323
generic-y += kdebug.h
2424
generic-y += kmap_types.h
2525
generic-y += kprobes.h
26+
generic-y += kvm_para.h
2627
generic-y += local.h
2728
generic-y += mcs_spinlock.h
2829
generic-y += mm-arch-hooks.h

arch/nios2/include/uapi/asm/Kbuild

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
generic-y += kvm_para.h
21
generic-y += ucontext.h

arch/openrisc/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ generic-y += irq_work.h
2020
generic-y += kdebug.h
2121
generic-y += kmap_types.h
2222
generic-y += kprobes.h
23+
generic-y += kvm_para.h
2324
generic-y += local.h
2425
generic-y += mcs_spinlock.h
2526
generic-y += mm-arch-hooks.h

arch/openrisc/include/uapi/asm/Kbuild

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
generic-y += kvm_para.h
21
generic-y += ucontext.h

arch/parisc/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ generic-y += irq_regs.h
1111
generic-y += irq_work.h
1212
generic-y += kdebug.h
1313
generic-y += kprobes.h
14+
generic-y += kvm_para.h
1415
generic-y += local.h
1516
generic-y += local64.h
1617
generic-y += mcs_spinlock.h

arch/parisc/include/uapi/asm/Kbuild

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
generated-y += unistd_32.h
22
generated-y += unistd_64.h
3-
generic-y += kvm_para.h

arch/sh/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ generic-y += emergency-restart.h
99
generic-y += exec.h
1010
generic-y += irq_regs.h
1111
generic-y += irq_work.h
12+
generic-y += kvm_para.h
1213
generic-y += local.h
1314
generic-y += local64.h
1415
generic-y += mcs_spinlock.h

arch/sh/include/uapi/asm/Kbuild

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# SPDX-License-Identifier: GPL-2.0
22

33
generated-y += unistd_32.h
4-
generic-y += kvm_para.h
54
generic-y += ucontext.h

arch/sparc/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ generic-y += exec.h
99
generic-y += export.h
1010
generic-y += irq_regs.h
1111
generic-y += irq_work.h
12+
generic-y += kvm_para.h
1213
generic-y += linkage.h
1314
generic-y += local.h
1415
generic-y += local64.h

0 commit comments

Comments
 (0)