@@ -163,7 +163,6 @@ struct kvm_shadow_walk_iterator {
__shadow_walk_next(&(_walker), spte))
static struct kmem_cache *pte_list_desc_cache;
-struct kmem_cache *mmu_page_header_cache;
static struct percpu_counter kvm_total_used_mmu_pages;
static void mmu_spte_set(u64 *sptep, u64 spte);
@@ -674,7 +673,7 @@ static int mmu_topup_memory_caches(struct kvm_vcpu *vcpu, bool maybe_indirect)
if (r)
return r;
}
- return kvm_mmu_topup_memory_cache(&vcpu->arch.mmu_page_header_cache,
+ return kvm_mmu_topup_memory_cache(&vcpu->mmu_page_header_cache,
PT64_ROOT_MAX_LEVEL);
}
@@ -683,7 +682,7 @@ static void mmu_free_memory_caches(struct kvm_vcpu *vcpu)
kvm_mmu_free_memory_cache(&vcpu->arch.mmu_pte_list_desc_cache);
kvm_mmu_free_memory_cache(&vcpu->mmu_page_table_cache);
kvm_mmu_free_memory_cache(&vcpu->arch.mmu_shadowed_info_cache);
- kvm_mmu_free_memory_cache(&vcpu->arch.mmu_page_header_cache);
+ kvm_mmu_free_memory_cache(&vcpu->mmu_page_header_cache);
}
static void mmu_free_pte_list_desc(struct pte_list_desc *pte_list_desc)
@@ -2217,7 +2216,7 @@ static struct kvm_mmu_page *kvm_mmu_get_shadow_page(struct kvm_vcpu *vcpu,
union kvm_mmu_page_role role)
{
struct shadow_page_caches caches = {
- .page_header_cache = &vcpu->arch.mmu_page_header_cache,
+ .page_header_cache = &vcpu->mmu_page_header_cache,
.shadow_page_cache = &vcpu->mmu_page_table_cache,
.shadowed_info_cache = &vcpu->arch.mmu_shadowed_info_cache,
};
@@ -5917,8 +5916,8 @@ int kvm_mmu_create(struct kvm_vcpu *vcpu)
vcpu->arch.mmu_pte_list_desc_cache.kmem_cache = pte_list_desc_cache;
vcpu->arch.mmu_pte_list_desc_cache.gfp_zero = __GFP_ZERO;
- vcpu->arch.mmu_page_header_cache.kmem_cache = mmu_page_header_cache;
- vcpu->arch.mmu_page_header_cache.gfp_zero = __GFP_ZERO;
+ vcpu->mmu_page_header_cache.kmem_cache = mmu_page_header_cache;
+ vcpu->mmu_page_header_cache.gfp_zero = __GFP_ZERO;
vcpu->mmu_page_table_cache.gfp_zero = __GFP_ZERO;
@@ -44,8 +44,6 @@ extern bool dbg;
#define INVALID_PAE_ROOT 0
#define IS_VALID_PAE_ROOT(x) (!!(x))
-extern struct kmem_cache *mmu_page_header_cache;
-
static inline bool kvm_mmu_page_ad_need_write_protect(struct kvm_mmu_page *sp)
{
/*
@@ -263,7 +263,7 @@ static struct kvm_mmu_page *tdp_mmu_alloc_sp(struct kvm_vcpu *vcpu)
{
struct kvm_mmu_page *sp;
- sp = kvm_mmu_memory_cache_alloc(&vcpu->arch.mmu_page_header_cache);
+ sp = kvm_mmu_memory_cache_alloc(&vcpu->mmu_page_header_cache);
sp->spt = kvm_mmu_memory_cache_alloc(&vcpu->mmu_page_table_cache);
return sp;
@@ -4,6 +4,8 @@
#include <kvm/mmu_types.h>
+extern struct kmem_cache *mmu_page_header_cache;
+
static inline struct kvm_mmu_page *to_shadow_page(hpa_t shadow_page)
{
struct page *page = pfn_to_page((shadow_page) >> PAGE_SHIFT);
@@ -391,6 +391,9 @@ struct kvm_vcpu {
#ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE
/* Cache used to allocate pages for use as page tables. */
struct kvm_mmu_memory_cache mmu_page_table_cache;
+
+ /* Cache used to allocate kvm_mmu_page structs. */
+ struct kvm_mmu_memory_cache mmu_page_header_cache;
#endif
};
@@ -108,6 +108,7 @@ static int kvm_usage_count;
static atomic_t hardware_enable_failed;
static struct kmem_cache *kvm_vcpu_cache;
+struct kmem_cache *mmu_page_header_cache;
static __read_mostly struct preempt_ops kvm_preempt_ops;
static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_running_vcpu);
Move vcpu->arch.mmu_page_header_cache and its backing kmem_cache to common code in preparation for moving the TDP MMU to common code in a future commit. The kmem_cache is still only initialized and used on x86 for the time being to avoid affecting other architectures. A future commit can move the code to manage this cache to common code. No functional change intended. Signed-off-by: David Matlack <dmatlack@google.com> --- arch/x86/kvm/mmu/mmu.c | 11 +++++------ arch/x86/kvm/mmu/mmu_internal.h | 2 -- arch/x86/kvm/mmu/tdp_mmu.c | 2 +- include/kvm/mmu.h | 2 ++ include/linux/kvm_host.h | 3 +++ virt/kvm/kvm_main.c | 1 + 6 files changed, 12 insertions(+), 9 deletions(-)