-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KVM: Reinstate gfn_to_pfn_cache with invalidation support
This can be used in two modes. There is an atomic mode where the cached mapping is accessed while holding the rwlock, and a mode where the physical address is used by a vCPU in guest mode. For the latter case, an invalidation will wake the vCPU with the new KVM_REQ_GPC_INVALIDATE, and the architecture will need to refresh any caches it still needs to access before entering guest mode again. Only one vCPU can be targeted by the wake requests; it's simple enough to make it wake all vCPUs or even a mask but I don't see a use case for that additional complexity right now. Invalidation happens from the invalidate_range_start MMU notifier, which needs to be able to sleep in order to wake the vCPU and wait for it. This means that revalidation potentially needs to "wait" for the MMU operation to complete and the invalidate_range_end notifier to be invoked. Like the vCPU when it takes a page fault in that period, we just spin — fixing that in a future patch by implementing an actual *wait* may be another part of shaving this particularly hirsute yak. As noted in the comments in the function itself, the only case where the invalidate_range_start notifier is expected to be called *without* being able to sleep is when the OOM reaper is killing the process. In that case, we expect the vCPU threads already to have exited, and thus there will be nothing to wake, and no reason to wait. So we clear the KVM_REQUEST_WAIT bit and send the request anyway, then complain loudly if there actually *was* anything to wake up. Signed-off-by: David Woodhouse <dwmw@amazon.co.uk> Message-Id: <20211210163625.2886-3-dwmw2@infradead.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
- Loading branch information
David Woodhouse
authored and
Paolo Bonzini
committed
Jan 7, 2022
1 parent
2efd61a
commit 982ed0d
Showing
10 changed files
with
517 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ | |
config HAVE_KVM | ||
bool | ||
|
||
config HAVE_KVM_PFNCACHE | ||
bool | ||
|
||
config HAVE_KVM_IRQCHIP | ||
bool | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
|
||
#ifndef __KVM_MM_H__ | ||
#define __KVM_MM_H__ 1 | ||
|
||
/* | ||
* Architectures can choose whether to use an rwlock or spinlock | ||
* for the mmu_lock. These macros, for use in common code | ||
* only, avoids using #ifdefs in places that must deal with | ||
* multiple architectures. | ||
*/ | ||
|
||
#ifdef KVM_HAVE_MMU_RWLOCK | ||
#define KVM_MMU_LOCK_INIT(kvm) rwlock_init(&(kvm)->mmu_lock) | ||
#define KVM_MMU_LOCK(kvm) write_lock(&(kvm)->mmu_lock) | ||
#define KVM_MMU_UNLOCK(kvm) write_unlock(&(kvm)->mmu_lock) | ||
#define KVM_MMU_READ_LOCK(kvm) read_lock(&(kvm)->mmu_lock) | ||
#define KVM_MMU_READ_UNLOCK(kvm) read_unlock(&(kvm)->mmu_lock) | ||
#else | ||
#define KVM_MMU_LOCK_INIT(kvm) spin_lock_init(&(kvm)->mmu_lock) | ||
#define KVM_MMU_LOCK(kvm) spin_lock(&(kvm)->mmu_lock) | ||
#define KVM_MMU_UNLOCK(kvm) spin_unlock(&(kvm)->mmu_lock) | ||
#define KVM_MMU_READ_LOCK(kvm) spin_lock(&(kvm)->mmu_lock) | ||
#define KVM_MMU_READ_UNLOCK(kvm) spin_unlock(&(kvm)->mmu_lock) | ||
#endif /* KVM_HAVE_MMU_RWLOCK */ | ||
|
||
kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async, | ||
bool write_fault, bool *writable); | ||
|
||
#ifdef CONFIG_HAVE_KVM_PFNCACHE | ||
void gfn_to_pfn_cache_invalidate_start(struct kvm *kvm, | ||
unsigned long start, | ||
unsigned long end, | ||
bool may_block); | ||
#else | ||
static inline void gfn_to_pfn_cache_invalidate_start(struct kvm *kvm, | ||
unsigned long start, | ||
unsigned long end, | ||
bool may_block) | ||
{ | ||
} | ||
#endif /* HAVE_KVM_PFNCACHE */ | ||
|
||
#endif /* __KVM_MM_H__ */ |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.