Skip to content

Commit 037d1f9

Browse files
mchehabbonzini
authored andcommitted
docs: kvm: Convert mmu.txt to ReST format
- Use document title and chapter markups; - Add markups for tables; - Add markups for literal blocks; - Add blank lines and adjust indentation. Signed-off-by: Mauro Carvalho Chehab <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 75e7fcd commit 037d1f9

File tree

2 files changed

+49
-14
lines changed

2 files changed

+49
-14
lines changed

Documentation/virt/kvm/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ KVM
1313
halt-polling
1414
hypercalls
1515
locking
16+
mmu
1617
msr
1718
vcpu-requests
1819

Documentation/virt/kvm/mmu.txt renamed to Documentation/virt/kvm/mmu.rst

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
======================
14
The x86 kvm shadow mmu
25
======================
36

@@ -7,27 +10,37 @@ physical addresses to host physical addresses.
710

811
The mmu code attempts to satisfy the following requirements:
912

10-
- correctness: the guest should not be able to determine that it is running
13+
- correctness:
14+
the guest should not be able to determine that it is running
1115
on an emulated mmu except for timing (we attempt to comply
1216
with the specification, not emulate the characteristics of
1317
a particular implementation such as tlb size)
14-
- security: the guest must not be able to touch host memory not assigned
18+
- security:
19+
the guest must not be able to touch host memory not assigned
1520
to it
16-
- performance: minimize the performance penalty imposed by the mmu
17-
- scaling: need to scale to large memory and large vcpu guests
18-
- hardware: support the full range of x86 virtualization hardware
19-
- integration: Linux memory management code must be in control of guest memory
21+
- performance:
22+
minimize the performance penalty imposed by the mmu
23+
- scaling:
24+
need to scale to large memory and large vcpu guests
25+
- hardware:
26+
support the full range of x86 virtualization hardware
27+
- integration:
28+
Linux memory management code must be in control of guest memory
2029
so that swapping, page migration, page merging, transparent
2130
hugepages, and similar features work without change
22-
- dirty tracking: report writes to guest memory to enable live migration
31+
- dirty tracking:
32+
report writes to guest memory to enable live migration
2333
and framebuffer-based displays
24-
- footprint: keep the amount of pinned kernel memory low (most memory
34+
- footprint:
35+
keep the amount of pinned kernel memory low (most memory
2536
should be shrinkable)
26-
- reliability: avoid multipage or GFP_ATOMIC allocations
37+
- reliability:
38+
avoid multipage or GFP_ATOMIC allocations
2739

2840
Acronyms
2941
========
3042

43+
==== ====================================================================
3144
pfn host page frame number
3245
hpa host physical address
3346
hva host virtual address
@@ -41,6 +54,7 @@ pte page table entry (used also to refer generically to paging structure
4154
gpte guest pte (referring to gfns)
4255
spte shadow pte (referring to pfns)
4356
tdp two dimensional paging (vendor neutral term for NPT and EPT)
57+
==== ====================================================================
4458

4559
Virtual and real hardware supported
4660
===================================
@@ -90,11 +104,13 @@ Events
90104
The mmu is driven by events, some from the guest, some from the host.
91105

92106
Guest generated events:
107+
93108
- writes to control registers (especially cr3)
94109
- invlpg/invlpga instruction execution
95110
- access to missing or protected translations
96111

97112
Host generated events:
113+
98114
- changes in the gpa->hpa translation (either through gpa->hva changes or
99115
through hva->hpa changes)
100116
- memory pressure (the shrinker)
@@ -117,16 +133,19 @@ Leaf ptes point at guest pages.
117133
The following table shows translations encoded by leaf ptes, with higher-level
118134
translations in parentheses:
119135

120-
Non-nested guests:
136+
Non-nested guests::
137+
121138
nonpaging: gpa->hpa
122139
paging: gva->gpa->hpa
123140
paging, tdp: (gva->)gpa->hpa
124-
Nested guests:
141+
142+
Nested guests::
143+
125144
non-tdp: ngva->gpa->hpa (*)
126145
tdp: (ngva->)ngpa->gpa->hpa
127146

128-
(*) the guest hypervisor will encode the ngva->gpa translation into its page
129-
tables if npt is not present
147+
(*) the guest hypervisor will encode the ngva->gpa translation into its page
148+
tables if npt is not present
130149

131150
Shadow pages contain the following information:
132151
role.level:
@@ -291,28 +310,41 @@ Handling a page fault is performed as follows:
291310

292311
- if the RSV bit of the error code is set, the page fault is caused by guest
293312
accessing MMIO and cached MMIO information is available.
313+
294314
- walk shadow page table
295315
- check for valid generation number in the spte (see "Fast invalidation of
296316
MMIO sptes" below)
297317
- cache the information to vcpu->arch.mmio_gva, vcpu->arch.mmio_access and
298318
vcpu->arch.mmio_gfn, and call the emulator
319+
299320
- If both P bit and R/W bit of error code are set, this could possibly
300321
be handled as a "fast page fault" (fixed without taking the MMU lock). See
301322
the description in Documentation/virt/kvm/locking.txt.
323+
302324
- if needed, walk the guest page tables to determine the guest translation
303325
(gva->gpa or ngpa->gpa)
326+
304327
- if permissions are insufficient, reflect the fault back to the guest
328+
305329
- determine the host page
330+
306331
- if this is an mmio request, there is no host page; cache the info to
307332
vcpu->arch.mmio_gva, vcpu->arch.mmio_access and vcpu->arch.mmio_gfn
333+
308334
- walk the shadow page table to find the spte for the translation,
309335
instantiating missing intermediate page tables as necessary
336+
310337
- If this is an mmio request, cache the mmio info to the spte and set some
311338
reserved bit on the spte (see callers of kvm_mmu_set_mmio_spte_mask)
339+
312340
- try to unsynchronize the page
341+
313342
- if successful, we can let the guest continue and modify the gpte
343+
314344
- emulate the instruction
345+
315346
- if failed, unshadow the page and let the guest continue
347+
316348
- update any translations that were modified by the instruction
317349

318350
invlpg handling:
@@ -324,10 +356,12 @@ invlpg handling:
324356
Guest control register updates:
325357

326358
- mov to cr3
359+
327360
- look up new shadow roots
328361
- synchronize newly reachable shadow pages
329362

330363
- mov to cr0/cr4/efer
364+
331365
- set up mmu context for new paging mode
332366
- look up new shadow roots
333367
- synchronize newly reachable shadow pages
@@ -358,6 +392,7 @@ on fault type:
358392
(user write faults generate a #PF)
359393

360394
In the first case there are two additional complications:
395+
361396
- if CR4.SMEP is enabled: since we've turned the page into a kernel page,
362397
the kernel may now execute it. We handle this by also setting spte.nx.
363398
If we get a user fetch or read fault, we'll change spte.u=1 and
@@ -446,4 +481,3 @@ Further reading
446481

447482
- NPT presentation from KVM Forum 2008
448483
http://www.linux-kvm.org/images/c/c8/KvmForum2008%24kdf2008_21.pdf
449-

0 commit comments

Comments
 (0)