Skip to content

Commit fe489bf

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull KVM fixes from Paolo Bonzini: "On the x86 side, there are some optimizations and documentation updates. The big ARM/KVM change for 3.11, support for AArch64, will come through Catalin Marinas's tree. s390 and PPC have misc cleanups and bugfixes" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (87 commits) KVM: PPC: Ignore PIR writes KVM: PPC: Book3S PR: Invalidate SLB entries properly KVM: PPC: Book3S PR: Allow guest to use 1TB segments KVM: PPC: Book3S PR: Don't keep scanning HPTEG after we find a match KVM: PPC: Book3S PR: Fix invalidation of SLB entry 0 on guest entry KVM: PPC: Book3S PR: Fix proto-VSID calculations KVM: PPC: Guard doorbell exception with CONFIG_PPC_DOORBELL KVM: Fix RTC interrupt coalescing tracking kvm: Add a tracepoint write_tsc_offset KVM: MMU: Inform users of mmio generation wraparound KVM: MMU: document fast invalidate all mmio sptes KVM: MMU: document fast invalidate all pages KVM: MMU: document fast page fault KVM: MMU: document mmio page fault KVM: MMU: document write_flooding_count KVM: MMU: document clear_spte_count KVM: MMU: drop kvm_mmu_zap_mmio_sptes KVM: MMU: init kvm generation close to mmio wrap-around value KVM: MMU: add tracepoint for check_mmio_spte KVM: MMU: fast invalidate all mmio sptes ...
2 parents 3e34131 + a3ff5fb commit fe489bf

62 files changed

Lines changed: 1382 additions & 807 deletions

Some content is hidden

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

‎Documentation/virtual/kvm/api.txt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,7 +2278,7 @@ return indicates the attribute is implemented. It does not necessarily
22782278
indicate that the attribute can be read or written in the device's
22792279
current state. "addr" is ignored.
22802280

2281-
4.77 KVM_ARM_VCPU_INIT
2281+
4.82 KVM_ARM_VCPU_INIT
22822282

22832283
Capability: basic
22842284
Architectures: arm, arm64
@@ -2304,7 +2304,7 @@ Possible features:
23042304
Depends on KVM_CAP_ARM_EL1_32BIT (arm64 only).
23052305

23062306

2307-
4.78 KVM_GET_REG_LIST
2307+
4.83 KVM_GET_REG_LIST
23082308

23092309
Capability: basic
23102310
Architectures: arm, arm64
@@ -2324,7 +2324,7 @@ This ioctl returns the guest registers that are supported for the
23242324
KVM_GET_ONE_REG/KVM_SET_ONE_REG calls.
23252325

23262326

2327-
4.80 KVM_ARM_SET_DEVICE_ADDR
2327+
4.84 KVM_ARM_SET_DEVICE_ADDR
23282328

23292329
Capability: KVM_CAP_ARM_SET_DEVICE_ADDR
23302330
Architectures: arm, arm64
@@ -2362,7 +2362,7 @@ must be called after calling KVM_CREATE_IRQCHIP, but before calling
23622362
KVM_RUN on any of the VCPUs. Calling this ioctl twice for any of the
23632363
base addresses will return -EEXIST.
23642364

2365-
4.82 KVM_PPC_RTAS_DEFINE_TOKEN
2365+
4.85 KVM_PPC_RTAS_DEFINE_TOKEN
23662366

23672367
Capability: KVM_CAP_PPC_RTAS
23682368
Architectures: ppc

‎Documentation/virtual/kvm/mmu.txt‎

Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ Shadow pages contain the following information:
191191
A counter keeping track of how many hardware registers (guest cr3 or
192192
pdptrs) are now pointing at the page. While this counter is nonzero, the
193193
page cannot be destroyed. See role.invalid.
194-
multimapped:
195-
Whether there exist multiple sptes pointing at this page.
196-
parent_pte/parent_ptes:
197-
If multimapped is zero, parent_pte points at the single spte that points at
198-
this page's spt. Otherwise, parent_ptes points at a data structure
199-
with a list of parent_ptes.
194+
parent_ptes:
195+
The reverse mapping for the pte/ptes pointing at this page's spt. If
196+
parent_ptes bit 0 is zero, only one spte points at this pages and
197+
parent_ptes points at this single spte, otherwise, there exists multiple
198+
sptes pointing at this page and (parent_ptes & ~0x1) points at a data
199+
structure with a list of parent_ptes.
200200
unsync:
201201
If true, then the translations in this page may not match the guest's
202202
translation. This is equivalent to the state of the tlb when a pte is
@@ -210,6 +210,24 @@ Shadow pages contain the following information:
210210
A bitmap indicating which sptes in spt point (directly or indirectly) at
211211
pages that may be unsynchronized. Used to quickly locate all unsychronized
212212
pages reachable from a given page.
213+
mmu_valid_gen:
214+
Generation number of the page. It is compared with kvm->arch.mmu_valid_gen
215+
during hash table lookup, and used to skip invalidated shadow pages (see
216+
"Zapping all pages" below.)
217+
clear_spte_count:
218+
Only present on 32-bit hosts, where a 64-bit spte cannot be written
219+
atomically. The reader uses this while running out of the MMU lock
220+
to detect in-progress updates and retry them until the writer has
221+
finished the write.
222+
write_flooding_count:
223+
A guest may write to a page table many times, causing a lot of
224+
emulations if the page needs to be write-protected (see "Synchronized
225+
and unsynchronized pages" below). Leaf pages can be unsynchronized
226+
so that they do not trigger frequent emulation, but this is not
227+
possible for non-leafs. This field counts the number of emulations
228+
since the last time the page table was actually used; if emulation
229+
is triggered too frequently on this page, KVM will unmap the page
230+
to avoid emulation in the future.
213231

214232
Reverse map
215233
===========
@@ -258,14 +276,26 @@ This is the most complicated event. The cause of a page fault can be:
258276

259277
Handling a page fault is performed as follows:
260278

279+
- if the RSV bit of the error code is set, the page fault is caused by guest
280+
accessing MMIO and cached MMIO information is available.
281+
- walk shadow page table
282+
- check for valid generation number in the spte (see "Fast invalidation of
283+
MMIO sptes" below)
284+
- cache the information to vcpu->arch.mmio_gva, vcpu->arch.access and
285+
vcpu->arch.mmio_gfn, and call the emulator
286+
- If both P bit and R/W bit of error code are set, this could possibly
287+
be handled as a "fast page fault" (fixed without taking the MMU lock). See
288+
the description in Documentation/virtual/kvm/locking.txt.
261289
- if needed, walk the guest page tables to determine the guest translation
262290
(gva->gpa or ngpa->gpa)
263291
- if permissions are insufficient, reflect the fault back to the guest
264292
- determine the host page
265-
- if this is an mmio request, there is no host page; call the emulator
266-
to emulate the instruction instead
293+
- if this is an mmio request, there is no host page; cache the info to
294+
vcpu->arch.mmio_gva, vcpu->arch.access and vcpu->arch.mmio_gfn
267295
- walk the shadow page table to find the spte for the translation,
268296
instantiating missing intermediate page tables as necessary
297+
- If this is an mmio request, cache the mmio info to the spte and set some
298+
reserved bit on the spte (see callers of kvm_mmu_set_mmio_spte_mask)
269299
- try to unsynchronize the page
270300
- if successful, we can let the guest continue and modify the gpte
271301
- emulate the instruction
@@ -351,6 +381,51 @@ causes its write_count to be incremented, thus preventing instantiation of
351381
a large spte. The frames at the end of an unaligned memory slot have
352382
artificially inflated ->write_counts so they can never be instantiated.
353383

384+
Zapping all pages (page generation count)
385+
=========================================
386+
387+
For the large memory guests, walking and zapping all pages is really slow
388+
(because there are a lot of pages), and also blocks memory accesses of
389+
all VCPUs because it needs to hold the MMU lock.
390+
391+
To make it be more scalable, kvm maintains a global generation number
392+
which is stored in kvm->arch.mmu_valid_gen. Every shadow page stores
393+
the current global generation-number into sp->mmu_valid_gen when it
394+
is created. Pages with a mismatching generation number are "obsolete".
395+
396+
When KVM need zap all shadow pages sptes, it just simply increases the global
397+
generation-number then reload root shadow pages on all vcpus. As the VCPUs
398+
create new shadow page tables, the old pages are not used because of the
399+
mismatching generation number.
400+
401+
KVM then walks through all pages and zaps obsolete pages. While the zap
402+
operation needs to take the MMU lock, the lock can be released periodically
403+
so that the VCPUs can make progress.
404+
405+
Fast invalidation of MMIO sptes
406+
===============================
407+
408+
As mentioned in "Reaction to events" above, kvm will cache MMIO
409+
information in leaf sptes. When a new memslot is added or an existing
410+
memslot is changed, this information may become stale and needs to be
411+
invalidated. This also needs to hold the MMU lock while walking all
412+
shadow pages, and is made more scalable with a similar technique.
413+
414+
MMIO sptes have a few spare bits, which are used to store a
415+
generation number. The global generation number is stored in
416+
kvm_memslots(kvm)->generation, and increased whenever guest memory info
417+
changes. This generation number is distinct from the one described in
418+
the previous section.
419+
420+
When KVM finds an MMIO spte, it checks the generation number of the spte.
421+
If the generation number of the spte does not equal the global generation
422+
number, it will ignore the cached MMIO information and handle the page
423+
fault through the slow path.
424+
425+
Since only 19 bits are used to store generation-number on mmio spte, all
426+
pages are zapped when there is an overflow.
427+
428+
354429
Further reading
355430
===============
356431

‎MAINTAINERS‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4733,10 +4733,10 @@ F: arch/s390/kvm/
47334733
F: drivers/s390/kvm/
47344734

47354735
KERNEL VIRTUAL MACHINE (KVM) FOR ARM
4736-
M: Christoffer Dall <cdall@cs.columbia.edu>
4736+
M: Christoffer Dall <christoffer.dall@linaro.org>
47374737
L: kvmarm@lists.cs.columbia.edu
47384738
W: http://systems.cs.columbia.edu/projects/kvm-arm
4739-
S: Maintained
4739+
S: Supported
47404740
F: arch/arm/include/uapi/asm/kvm*
47414741
F: arch/arm/include/asm/kvm*
47424742
F: arch/arm/kvm/

‎arch/arm/include/asm/kvm_arm.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@
135135
#define KVM_PHYS_MASK (KVM_PHYS_SIZE - 1ULL)
136136
#define PTRS_PER_S2_PGD (1ULL << (KVM_PHYS_SHIFT - 30))
137137
#define S2_PGD_ORDER get_order(PTRS_PER_S2_PGD * sizeof(pgd_t))
138-
#define S2_PGD_SIZE (1 << S2_PGD_ORDER)
139138

140139
/* Virtualization Translation Control Register (VTCR) bits */
141140
#define VTCR_SH0 (3 << 12)

‎arch/arm/include/asm/kvm_asm.h‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@
3737
#define c5_AIFSR 15 /* Auxilary Instrunction Fault Status R */
3838
#define c6_DFAR 16 /* Data Fault Address Register */
3939
#define c6_IFAR 17 /* Instruction Fault Address Register */
40-
#define c9_L2CTLR 18 /* Cortex A15 L2 Control Register */
41-
#define c10_PRRR 19 /* Primary Region Remap Register */
42-
#define c10_NMRR 20 /* Normal Memory Remap Register */
43-
#define c12_VBAR 21 /* Vector Base Address Register */
44-
#define c13_CID 22 /* Context ID Register */
45-
#define c13_TID_URW 23 /* Thread ID, User R/W */
46-
#define c13_TID_URO 24 /* Thread ID, User R/O */
47-
#define c13_TID_PRIV 25 /* Thread ID, Privileged */
48-
#define c14_CNTKCTL 26 /* Timer Control Register (PL1) */
49-
#define NR_CP15_REGS 27 /* Number of regs (incl. invalid) */
40+
#define c7_PAR 18 /* Physical Address Register */
41+
#define c7_PAR_high 19 /* PAR top 32 bits */
42+
#define c9_L2CTLR 20 /* Cortex A15 L2 Control Register */
43+
#define c10_PRRR 21 /* Primary Region Remap Register */
44+
#define c10_NMRR 22 /* Normal Memory Remap Register */
45+
#define c12_VBAR 23 /* Vector Base Address Register */
46+
#define c13_CID 24 /* Context ID Register */
47+
#define c13_TID_URW 25 /* Thread ID, User R/W */
48+
#define c13_TID_URO 26 /* Thread ID, User R/O */
49+
#define c13_TID_PRIV 27 /* Thread ID, Privileged */
50+
#define c14_CNTKCTL 28 /* Timer Control Register (PL1) */
51+
#define NR_CP15_REGS 29 /* Number of regs (incl. invalid) */
5052

5153
#define ARM_EXCEPTION_RESET 0
5254
#define ARM_EXCEPTION_UNDEFINED 1
@@ -72,8 +74,6 @@ extern char __kvm_hyp_vector[];
7274
extern char __kvm_hyp_code_start[];
7375
extern char __kvm_hyp_code_end[];
7476

75-
extern void __kvm_tlb_flush_vmid(struct kvm *kvm);
76-
7777
extern void __kvm_flush_vm_context(void);
7878
extern void __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa);
7979

‎arch/arm/include/asm/kvm_emulate.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ static inline bool vcpu_mode_priv(struct kvm_vcpu *vcpu)
6565
return cpsr_mode > USR_MODE;;
6666
}
6767

68-
static inline bool kvm_vcpu_reg_is_pc(struct kvm_vcpu *vcpu, int reg)
69-
{
70-
return reg == 15;
71-
}
72-
7368
static inline u32 kvm_vcpu_get_hsr(struct kvm_vcpu *vcpu)
7469
{
7570
return vcpu->arch.fault.hsr;

‎arch/arm/include/asm/kvm_host.h‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@
2323
#include <asm/kvm_asm.h>
2424
#include <asm/kvm_mmio.h>
2525
#include <asm/fpstate.h>
26-
#include <asm/kvm_arch_timer.h>
26+
#include <kvm/arm_arch_timer.h>
2727

28+
#if defined(CONFIG_KVM_ARM_MAX_VCPUS)
2829
#define KVM_MAX_VCPUS CONFIG_KVM_ARM_MAX_VCPUS
30+
#else
31+
#define KVM_MAX_VCPUS 0
32+
#endif
33+
2934
#define KVM_USER_MEM_SLOTS 32
3035
#define KVM_PRIVATE_MEM_SLOTS 4
3136
#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
@@ -38,7 +43,7 @@
3843
#define KVM_NR_PAGE_SIZES 1
3944
#define KVM_PAGES_PER_HPAGE(x) (1UL<<31)
4045

41-
#include <asm/kvm_vgic.h>
46+
#include <kvm/arm_vgic.h>
4247

4348
struct kvm_vcpu;
4449
u32 *kvm_vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num, u32 mode);
@@ -190,8 +195,8 @@ int kvm_arm_coproc_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *);
190195
int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
191196
int exception_index);
192197

193-
static inline void __cpu_init_hyp_mode(unsigned long long boot_pgd_ptr,
194-
unsigned long long pgd_ptr,
198+
static inline void __cpu_init_hyp_mode(phys_addr_t boot_pgd_ptr,
199+
phys_addr_t pgd_ptr,
195200
unsigned long hyp_stack_ptr,
196201
unsigned long vector_ptr)
197202
{

‎arch/arm/kvm/Kconfig‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ config KVM_ARM_HOST
4141
Provides host support for ARM processors.
4242

4343
config KVM_ARM_MAX_VCPUS
44-
int "Number maximum supported virtual CPUs per VM" if KVM_ARM_HOST
45-
default 4 if KVM_ARM_HOST
46-
default 0
44+
int "Number maximum supported virtual CPUs per VM"
45+
depends on KVM_ARM_HOST
46+
default 4
4747
help
4848
Static number of max supported virtual CPUs per VM.
4949

@@ -67,6 +67,4 @@ config KVM_ARM_TIMER
6767
---help---
6868
Adds support for the Architected Timers in virtual machines
6969

70-
source drivers/virtio/Kconfig
71-
7270
endif # VIRTUALIZATION

‎arch/arm/kvm/Makefile‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ CFLAGS_mmu.o := -I.
1414
AFLAGS_init.o := -Wa,-march=armv7-a$(plus_virt)
1515
AFLAGS_interrupts.o := -Wa,-march=armv7-a$(plus_virt)
1616

17-
kvm-arm-y = $(addprefix ../../../virt/kvm/, kvm_main.o coalesced_mmio.o)
17+
KVM := ../../../virt/kvm
18+
kvm-arm-y = $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o
1819

1920
obj-y += kvm-arm.o init.o interrupts.o
2021
obj-y += arm.o handle_exit.o guest.o mmu.o emulate.o reset.o
2122
obj-y += coproc.o coproc_a15.o mmio.o psci.o perf.o
22-
obj-$(CONFIG_KVM_ARM_VGIC) += vgic.o
23-
obj-$(CONFIG_KVM_ARM_TIMER) += arch_timer.o
23+
obj-$(CONFIG_KVM_ARM_VGIC) += $(KVM)/arm/vgic.o
24+
obj-$(CONFIG_KVM_ARM_TIMER) += $(KVM)/arm/arch_timer.o

‎arch/arm/kvm/arm.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -800,17 +800,17 @@ long kvm_arch_vm_ioctl(struct file *filp,
800800

801801
static void cpu_init_hyp_mode(void *dummy)
802802
{
803-
unsigned long long boot_pgd_ptr;
804-
unsigned long long pgd_ptr;
803+
phys_addr_t boot_pgd_ptr;
804+
phys_addr_t pgd_ptr;
805805
unsigned long hyp_stack_ptr;
806806
unsigned long stack_page;
807807
unsigned long vector_ptr;
808808

809809
/* Switch from the HYP stub to our own HYP init vector */
810810
__hyp_set_vectors(kvm_get_idmap_vector());
811811

812-
boot_pgd_ptr = (unsigned long long)kvm_mmu_get_boot_httbr();
813-
pgd_ptr = (unsigned long long)kvm_mmu_get_httbr();
812+
boot_pgd_ptr = kvm_mmu_get_boot_httbr();
813+
pgd_ptr = kvm_mmu_get_httbr();
814814
stack_page = __get_cpu_var(kvm_arm_hyp_stack_page);
815815
hyp_stack_ptr = stack_page + PAGE_SIZE;
816816
vector_ptr = (unsigned long)__kvm_hyp_vector;

0 commit comments

Comments
 (0)