Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: Move x86's version of struct kvm_mmu_memory_cache to common code

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 avoid a chicken-and-egg problem with asm/kvm_host.h as all
architectures define instances of the struct in their vCPU structs.

Add an asm-generic version of kvm_types.h to avoid having empty files on
PPC and s390 in the long term, and for arm64 and mips in the short term.

Suggested-by: Christoffer Dall <christoffer.dall@arm.com>
Reviewed-by: Ben Gardon <bgardon@google.com>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Message-Id: <20200703023545.8771-15-sean.j.christopherson@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Sean Christopherson and committed by
Paolo Bonzini
2aa9c199 94ce87ef

+35 -13
+1
arch/arm64/include/asm/Kbuild
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 generic-y += early_ioremap.h 3 + generic-y += kvm_types.h 3 4 generic-y += local64.h 4 5 generic-y += mcs_spinlock.h 5 6 generic-y += qrwlock.h
+1
arch/mips/include/asm/Kbuild
··· 5 5 generated-y += syscall_table_64_n64.h 6 6 generated-y += syscall_table_64_o32.h 7 7 generic-y += export.h 8 + generic-y += kvm_types.h 8 9 generic-y += local64.h 9 10 generic-y += mcs_spinlock.h 10 11 generic-y += parport.h
+1
arch/powerpc/include/asm/Kbuild
··· 4 4 generated-y += syscall_table_c32.h 5 5 generated-y += syscall_table_spu.h 6 6 generic-y += export.h 7 + generic-y += kvm_types.h 7 8 generic-y += local64.h 8 9 generic-y += mcs_spinlock.h 9 10 generic-y += vtime.h
+1
arch/s390/include/asm/Kbuild
··· 6 6 7 7 generic-y += asm-offsets.h 8 8 generic-y += export.h 9 + generic-y += kvm_types.h 9 10 generic-y += local64.h 10 11 generic-y += mcs_spinlock.h
-13
arch/x86/include/asm/kvm_host.h
··· 193 193 enum x86_intercept; 194 194 enum x86_intercept_stage; 195 195 196 - #define KVM_NR_MEM_OBJS 40 197 - 198 196 #define KVM_NR_DB_REGS 4 199 197 200 198 #define DR6_BD (1 << 13) ··· 242 244 #define KVM_APIC_PV_EOI_PENDING 1 243 245 244 246 struct kvm_kernel_irq_routing_entry; 245 - 246 - /* 247 - * We don't want allocation failures within the mmu code, so we preallocate 248 - * enough memory for a single page fault in a cache. 249 - */ 250 - struct kvm_mmu_memory_cache { 251 - int nobjs; 252 - gfp_t gfp_zero; 253 - struct kmem_cache *kmem_cache; 254 - void *objects[KVM_NR_MEM_OBJS]; 255 - }; 256 247 257 248 /* 258 249 * the pages used as guest page table on soft mmu are tracked by
+7
arch/x86/include/asm/kvm_types.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _ASM_X86_KVM_TYPES_H 3 + #define _ASM_X86_KVM_TYPES_H 4 + 5 + #define KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE 40 6 + 7 + #endif /* _ASM_X86_KVM_TYPES_H */
+5
include/asm-generic/kvm_types.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _ASM_GENERIC_KVM_TYPES_H 3 + #define _ASM_GENERIC_KVM_TYPES_H 4 + 5 + #endif
+19
include/linux/kvm_types.h
··· 20 20 21 21 #include <linux/types.h> 22 22 23 + #include <asm/kvm_types.h> 24 + 23 25 /* 24 26 * Address types: 25 27 * ··· 59 57 kvm_pfn_t pfn; 60 58 bool dirty; 61 59 }; 60 + 61 + #ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE 62 + /* 63 + * Memory caches are used to preallocate memory ahead of various MMU flows, 64 + * e.g. page fault handlers. Gracefully handling allocation failures deep in 65 + * MMU flows is problematic, as is triggering reclaim, I/O, etc... while 66 + * holding MMU locks. Note, these caches act more like prefetch buffers than 67 + * classical caches, i.e. objects are not returned to the cache on being freed. 68 + */ 69 + struct kvm_mmu_memory_cache { 70 + int nobjs; 71 + gfp_t gfp_zero; 72 + struct kmem_cache *kmem_cache; 73 + void *objects[KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE]; 74 + }; 75 + #endif 76 + 62 77 63 78 #endif /* __KVM_TYPES_H__ */