Re: [PATCH v10 1/6] arm64: mte: Sync tags for pages where PTE is untagged

2021-03-26 Thread Catalin Marinas
Hi Steven, On Fri, Mar 12, 2021 at 03:18:57PM +, Steven Price wrote: > A KVM guest could store tags in a page even if the VMM hasn't mapped > the page with PROT_MTE. So when restoring pages from swap we will > need to check to see if there are any saved tags even if !pte_tagged(). > > However

[PATCH 07/18] KVM: x86/mmu: Use leaf-only loop for walking TDP SPTEs when changing SPTE

2021-03-26 Thread Sean Christopherson
Use the leaf-only TDP iterator when changing the SPTE in reaction to a MMU notifier. Practically speaking, this is a nop since the guts of the loop explicitly looks for 4k SPTEs, which are always leaf SPTEs. Switch the iterator to match age_gfn_range() and test_age_gfn() so that a future patch ca

[PATCH 10/18] KVM: Move x86's MMU notifier memslot walkers to generic code

2021-03-26 Thread Sean Christopherson
Move the hva->gfn lookup for MMU notifiers into common code. Every arch does a similar lookup, and some arch code is all but identical across multiple architectures. In addition to consolidating code, this will allow introducing optimizations that will benefit all architectures without incurring

[PATCH 17/18] KVM: x86/mmu: Allow yielding during MMU notifier unmap/zap, if possible

2021-03-26 Thread Sean Christopherson
Let the TDP MMU yield when unmapping a range in response to a MMU notification, if yielding is allowed by said notification. There is no reason to disallow yielding in this case, and in theory the range being invalidated could be quite large. Cc: Ben Gardon Signed-off-by: Sean Christopherson --

[PATCH 02/18] KVM: x86/mmu: Move flushing for "slot" handlers to caller for legacy MMU

2021-03-26 Thread Sean Christopherson
Place the onus on the caller of slot_handle_*() to flush the TLB, rather than handling the flush in the helper, and rename parameters accordingly. This will allow future patches to coalesce flushes between address spaces and between the legacy and TDP MMUs. No functional change intended. Signed-o

[PATCH 18/18] KVM: x86/mmu: Drop trace_kvm_age_page() tracepoint

2021-03-26 Thread Sean Christopherson
Remove x86's trace_kvm_age_page() tracepoint. It's mostly redundant with the common trace_kvm_age_hva() tracepoint, and if there is a need for the extra details, e.g. gfn, referenced, etc... those details should be added to the common tracepoint so that all architectures and MMUs benefit from the

[PATCH 08/18] KVM: Move prototypes for MMU notifier callbacks to generic code

2021-03-26 Thread Sean Christopherson
Move the prototypes for the MMU notifier callbacks out of arch code and into common code. There is no benefit to having each arch replicate the prototypes since any deviation from the invocation in common code will explode. No functional change intended. Signed-off-by: Sean Christopherson ---

[PATCH 06/18] KVM: x86/mmu: Pass address space ID to TDP MMU root walkers

2021-03-26 Thread Sean Christopherson
Move the address space ID check that is performed when iterating over roots into the macro helpers to consolidate code. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu_internal.h | 7 ++- arch/x86/kvm/mmu/tdp_mmu.c | 99 --

[PATCH 16/18] KVM: Don't take mmu_lock for range invalidation unless necessary

2021-03-26 Thread Sean Christopherson
Avoid taking mmu_lock for unrelated .invalidate_range_{start,end}() notifications. Because mmu_notifier_count must be modified while holding mmu_lock for write, and must always be paired across start->end to stay balanced, lock elision must happen in both or none. To meet that requirement, add a

[PATCH 00/18] KVM: Consolidate and optimize MMU notifiers

2021-03-26 Thread Sean Christopherson
The end goal of this series is to optimize the MMU notifiers to take mmu_lock if and only if the notification is relevant to KVM, i.e. the hva range overlaps a memslot. Large VMs (hundreds of vCPUs) are very sensitive to mmu_lock being taken for write at inopportune times, and such VMs also tend

[PATCH 05/18] KVM: x86/mmu: Pass address space ID to __kvm_tdp_mmu_zap_gfn_range()

2021-03-26 Thread Sean Christopherson
Pass the address space ID to TDP MMU's primary "zap gfn range" helper to allow the MMU notifier paths to iterate over memslots exactly once. Currently, both the legacy MMU and TDP MMU iterate over memslots when looking for an overlapping hva range, which can be quite costly if there are a large num

[PATCH 13/18] KVM: PPC: Convert to the gfn-based MMU notifier callbacks

2021-03-26 Thread Sean Christopherson
Move PPC to the gfn-base MMU notifier APIs, and update all 15 bajillion PPC-internal hooks to work with gfns instead of hvas. No meaningful functional change intended, though the exact order of operations is slightly different since the memslot lookups occur before calling into arch code. Signed-

[PATCH 01/18] KVM: x86/mmu: Coalesce TDP MMU TLB flushes when zapping collapsible SPTEs

2021-03-26 Thread Sean Christopherson
When zapping collapsible SPTEs across multiple roots, gather pending flushes and perform a single remote TLB flush at the end, as opposed to flushing after processing every root. Note, flush may be cleared by the result of zap_collapsible_spte_range(). This is intended and correct, e.g. yielding m

[PATCH 04/18] KVM: x86/mmu: Coalesce TLB flushes across address spaces for gfn range zap

2021-03-26 Thread Sean Christopherson
Gather pending TLB flushes across both address spaces when zapping a given gfn range. This requires feeding "flush" back into subsequent calls, but on the plus side sets the stage for further batching between the legacy MMU and TDP MMU. It also allows refactoring the address space iteration to co

[PATCH 14/18] KVM: Kill off the old hva-based MMU notifier callbacks

2021-03-26 Thread Sean Christopherson
Yank out the hva-based MMU notifier APIs now that all architectures that use the notifiers have moved to the gfn-based APIs. No functional change intended. Signed-off-by: Sean Christopherson --- arch/arm64/include/asm/kvm_host.h | 1 - arch/mips/include/asm/kvm_host.h| 1 - arch/powerpc

[PATCH 11/18] KVM: arm64: Convert to the gfn-based MMU notifier callbacks

2021-03-26 Thread Sean Christopherson
Move arm64 to the gfn-base MMU notifier APIs, which do the hva->gfn lookup in common code. Note, due to arch code being called if and only if a memslot is found, the clean_dcache_guest_page() call in kvm_set_spte_*() is will no longer be called for addresses that are not found in the guest memslot

[PATCH 15/18] KVM: Take mmu_lock when handling MMU notifier iff the hva hits a memslot

2021-03-26 Thread Sean Christopherson
Defer acquiring mmu_lock in the MMU notifier paths until a "hit" has been detected in the memslots, i.e. don't take the lock for notifications that don't affect the guest. For small VMs, spurious locking is a minor annoyance. And for "volatile" setups where the majority of notifications _are_ rel

[PATCH 03/18] KVM: x86/mmu: Coalesce TLB flushes when zapping collapsible SPTEs

2021-03-26 Thread Sean Christopherson
Gather pending TLB flushes across both the legacy and TDP MMUs when zapping collapsible SPTEs to avoid multiple flushes if both the legacy MMU (for nested guests) and TDP MMU have mappings for the memslot. Note, this also optimizes the TDP MMU to flush only the relevant range when running as L1 wi

[PATCH 12/18] KVM: MIPS/MMU: Convert to the gfn-based MMU notifier callbacks

2021-03-26 Thread Sean Christopherson
Move MIPS to the gfn-based MMU notifier APIs, which do the hva->gfn lookup in common code, and whose code is nearly identical to MIPS' lookup. No meaningful functional change intended, though the exact order of operations is slightly different since the memslot lookups occur before calling into ar

[PATCH 09/18] KVM: Move arm64's MMU notifier trace events to generic code

2021-03-26 Thread Sean Christopherson
Move arm64's MMU notifier trace events into common code in preparation for doing the hva->gfn lookup in common code. The alternative would be to trace the gfn instead of hva, but that's not obviously better and could also be done in common code. Tracing the notifiers is also quite handy for debug