[PATCH 02/21] KVM: x86/mmu: Consolidate "page" variant of memory cache helpers

2020-06-05 Thread Sean Christopherson
Drop the "page" variants of the topup/free memory cache helpers, using the existence of an associated kmem_cache to select the correct alloc or free routine. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 37 +++--

[PATCH 12/21] KVM: x86/mmu: Skip filling the gfn cache for guaranteed direct MMU topups

2020-06-05 Thread Sean Christopherson
Don't bother filling the gfn array cache when the caller is a fully direct MMU, i.e. won't need a gfn array for shadow pages. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 18 ++ arch/x86/kvm/mmu/paging_tmpl.h | 4 ++-- 2 files changed, 12

[PATCH 08/21] KVM: x86/mmu: Clean up the gorilla math in mmu_topup_memory_caches()

2020-06-05 Thread Sean Christopherson
Clean up the minimums in mmu_topup_memory_caches() to document the driving mechanisms behind the minimums. Now that encountering an empty cache is unlikely to trigger BUG_ON(), it is less dangerous to be more precise when defining the minimums. For rmaps, the logic is 1 parent PTE per level,

[PATCH 17/21] KVM: arm64: Use common code's approach for __GFP_ZERO with memory caches

2020-06-05 Thread Sean Christopherson
Add a "gfp_zero" member to arm64's 'struct kvm_mmu_memory_cache' to make the struct and its usage compatible with the common 'struct kvm_mmu_memory_cache' in linux/kvm_host.h. This will minimize code churn when arm64 moves to the common implementation in a future patch, at the cost of temporarily

[PATCH 00/21] KVM: Cleanup and unify kvm_mmu_memory_cache usage

2020-06-05 Thread Sean Christopherson
This series resurrects Christoffer Dall's series[1] to provide a common MMU memory cache implementation that can be shared by x86, arm64 and MIPS. It also picks up a suggested change from Ben Gardon[2] to clear shadow page tables during initial allocation so as to avoid clearing entire pages

[PATCH 06/21] KVM: x86/mmu: Move fast_page_fault() call above mmu_topup_memory_caches()

2020-06-05 Thread Sean Christopherson
Avoid refilling the memory caches and potentially slow reclaim/swap when handling a fast page fault, which does not need to allocate any new objects. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git

[PATCH 15/21] KVM: Move x86's MMU memory cache helpers to common KVM code

2020-06-05 Thread Sean Christopherson
Move x86's memory cache helpers to common KVM code so that they can be reused by arm64 and MIPS in future patches. Suggested-by: Christoffer Dall Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 53 -- include/linux/kvm_host.h | 7 +

[PATCH 04/21] KVM: x86/mmu: Remove superfluous gotos from mmu_topup_memory_caches()

2020-06-05 Thread Sean Christopherson
Return errors directly from mmu_topup_memory_caches() instead of branching to a label that does the same. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 8 +++- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git

[PATCH 14/21] KVM: Move x86's version of struct kvm_mmu_memory_cache to common code

2020-06-05 Thread Sean Christopherson
Move x86's 'struct kvm_mmu_memory_cache' to common code in anticipation of moving the entire x86 implementation code to common KVM and reusing it for arm64 and MIPS. Add a new architecture specific asm/kvm_types.h to control the existence and parameters of the struct. The new header is needed to

[PATCH 05/21] KVM: x86/mmu: Try to avoid crashing KVM if a MMU memory cache is empty

2020-06-05 Thread Sean Christopherson
Attempt to allocate a new object instead of crashing KVM (and likely the kernel) if a memory cache is unexpectedly empty. Use GFP_ATOMIC for the allocation as the caches are used while holding mmu_lock. The immediate BUG_ON() makes the code unnecessarily explosive and led to confusing minimums

[PATCH 10/21] KVM: x86/mmu: Make __GFP_ZERO a property of the memory cache

2020-06-05 Thread Sean Christopherson
Add a gfp_zero flag to 'struct kvm_mmu_memory_cache' and use it to control __GFP_ZERO instead of hardcoding a call to kmem_cache_zalloc(). A future patch needs such a flag for the __get_free_page() path, as gfn arrays do not need/want the allocator to zero the memory. Convert the kmem_cache paths

[PATCH 07/21] KVM: x86/mmu: Topup memory caches after walking GVA->GPA

2020-06-05 Thread Sean Christopherson
Topup memory caches after walking the GVA->GPA translation during a shadow page fault, there is no need to ensure the caches are full when walking the GVA. As of commit f5a1e9f89504f ("KVM: MMU: remove call to kvm_mmu_pte_write from walk_addr"), the FNAME(walk_addr) flow no longer add rmaps via

[PATCH 13/21] KVM: x86/mmu: Prepend "kvm_" to memory cache helpers that will be global

2020-06-05 Thread Sean Christopherson
Rename the memory helpers that will soon be moved to common code and be made globaly available via linux/kvm_host.h. "mmu" alone is not a sufficient namespace for globally available KVM symbols. Opportunistically add "nr_" in mmu_memory_cache_free_objects() to make it clear the function returns

[PATCH 11/21] KVM: x86/mmu: Zero allocate shadow pages (outside of mmu_lock)

2020-06-05 Thread Sean Christopherson
Set __GFP_ZERO for the shadow page memory cache and drop the explicit clear_page() from kvm_mmu_get_page(). This moves the cost of zeroing a page to the allocation time of the physical page, i.e. when topping up the memory caches, and thus avoids having to zero out an entire page while holding

[PATCH 16/21] KVM: arm64: Drop @max param from mmu_topup_memory_cache()

2020-06-05 Thread Sean Christopherson
Replace the @max param in mmu_topup_memory_cache() and instead use ARRAY_SIZE() to terminate the loop to fill the cache. This removes a BUG_ON() and sets the stage for moving arm64 to the common memory cache implementation. No functional change intended. Signed-off-by: Sean Christopherson ---

[PATCH 03/21] KVM: x86/mmu: Use consistent "mc" name for kvm_mmu_memory_cache locals

2020-06-05 Thread Sean Christopherson
Use "mc" for local variables to shorten line lengths and provide consistent names, which will be especially helpful when some of the helpers are moved to common KVM code in future patches. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 24

[PATCH 09/21] KVM: x86/mmu: Separate the memory caches for shadow pages and gfn arrays

2020-06-05 Thread Sean Christopherson
Use separate caches for allocating shadow pages versus gfn arrays. This sets the stage for specifying __GFP_ZERO when allocating shadow pages without incurring extra cost for gfn arrays. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 3

[PATCH 18/21] KVM: arm64: Use common KVM implementation of MMU memory caches

2020-06-05 Thread Sean Christopherson
Move to the common MMU memory cache implementation now that the common code and arm64's existing code are semantically compatible. No functional change intended. Suggested-by: Christoffer Dall Signed-off-by: Sean Christopherson --- arch/arm64/include/asm/kvm_host.h | 12 ---

[PATCH 01/21] KVM: x86/mmu: Track the associated kmem_cache in the MMU caches

2020-06-05 Thread Sean Christopherson
Track the kmem_cache used for non-page KVM MMU memory caches instead of passing in the associated kmem_cache when filling the cache. This will allow consolidating code and other cleanups. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h |

[PATCH 21/21] KVM: MIPS: Use common KVM implementation of MMU memory caches

2020-06-05 Thread Sean Christopherson
Move to the common MMU memory cache implementation now that the common code and MIPS's existing code are semantically compatible. No functional change intended. Suggested-by: Christoffer Dall Signed-off-by: Sean Christopherson --- arch/mips/include/asm/kvm_host.h | 11 -

[PATCH 19/21] KVM: MIPS: Drop @max param from mmu_topup_memory_cache()

2020-06-05 Thread Sean Christopherson
Replace the @max param in mmu_topup_memory_cache() and instead use ARRAY_SIZE() to terminate the loop to fill the cache. This removes a BUG_ON() and sets the stage for moving MIPS to the common memory cache implementation. No functional change intended. Signed-off-by: Sean Christopherson ---

[PATCH 20/21] KVM: MIPS: Account pages used for GPA page tables

2020-06-05 Thread Sean Christopherson
Use GFP_KERNEL_ACCOUNT instead of GFP_KERNEL when allocating pages for the the GPA page tables. The primary motivation for accounting the allocations is to align with the common KVM memory cache helpers in preparation for moving to the common implementation in a future patch. The actual

[PATCH] KVM: arm64: Remove host_cpu_context member from vcpu structure

2020-06-05 Thread Marc Zyngier
For very long, we have kept this pointer back to the per-cpu host state, despite having working per-cpu accessors at EL2 for some time now. Recent investigations have shown that this pointer is easy to abuse in preemptible context, which is a sure sign that it would better be gone. Not to mention

Re: [kvmtool][PATCH] arm64: Obtain text offset from kernel image

2020-06-05 Thread Marc Zyngier
Hi Alex, On 2020-06-05 13:16, Alexandru Elisei wrote: Hi Marc, On 6/5/20 11:49 AM, Marc Zyngier wrote: Recent changes made to Linux 5.8 have outlined that kvmtool hardcodes the text offset instead of reading it from the arm64 image itself. To address this, import the image header structure

Re: [kvmtool][PATCH] arm64: Obtain text offset from kernel image

2020-06-05 Thread Alexandru Elisei
Hi Marc, On 6/5/20 11:49 AM, Marc Zyngier wrote: > Recent changes made to Linux 5.8 have outlined that kvmtool > hardcodes the text offset instead of reading it from the arm64 > image itself. > > To address this, import the image header structure into kvmtool > and do the right thing. 32bit

[kvmtool][PATCH] arm64: Obtain text offset from kernel image

2020-06-05 Thread Marc Zyngier
Recent changes made to Linux 5.8 have outlined that kvmtool hardcodes the text offset instead of reading it from the arm64 image itself. To address this, import the image header structure into kvmtool and do the right thing. 32bit guests are still loaded to their usual locations. Reported-by: