History

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.

Sean Christopherson committed 6 years ago

Commit 2aa9c191 parent 94ce87e8 files · +35 −13Browse files

Unified · Split

8 files
  1. arch/arm64/include/asm/Kbuild +1 −0
  2. arch/mips/include/asm/Kbuild +1 −0
  3. arch/powerpc/include/asm/Kbuild +1 −0
  4. arch/s390/include/asm/Kbuild +1 −0
  5. arch/x86/include/asm/kvm_host.h +0 −13
  6. arch/x86/include/asm/kvm_types.h +7 −0
  7. include/asm-generic/kvm_types.h +5 −0
  8. include/linux/kvm_types.h +19 −0
arch/arm64/include/asm/Kbuild+1−0
@@ -1,5 +1,6 @@
11 # SPDX-License-Identifier: GPL-2.0
22 generic-y += early_ioremap.h
3+generic-y += kvm_types.h
34 generic-y += local64.h
45 generic-y += mcs_spinlock.h
56 generic-y += qrwlock.h
arch/mips/include/asm/Kbuild+1−0
@@ -5,6 +5,7 @@ generated-y += syscall_table_64_n32.h · 4 unmodified lines
55 generated-y += syscall_table_64_n64.h
66 generated-y += syscall_table_64_o32.h
77 generic-y += export.h
8+generic-y += kvm_types.h
89 generic-y += local64.h
910 generic-y += mcs_spinlock.h
1011 generic-y += parport.h
arch/powerpc/include/asm/Kbuild+1−0
@@ -4,6 +4,7 @@ generated-y += syscall_table_64.h · 3 unmodified lines
44 generated-y += syscall_table_c32.h
55 generated-y += syscall_table_spu.h
66 generic-y += export.h
7+generic-y += kvm_types.h
78 generic-y += local64.h
89 generic-y += mcs_spinlock.h
910 generic-y += vtime.h
arch/s390/include/asm/Kbuild+1−0
@@ -6,5 +6,6 @@ generated-y += unistd_nr.h · 5 unmodified lines
66
77 generic-y += asm-offsets.h
88 generic-y += export.h
9+generic-y += kvm_types.h
910 generic-y += local64.h
1011 generic-y += mcs_spinlock.h
arch/x86/include/asm/kvm_host.h+0−13
@@ -193,8 +193,6 @@ struct x86_exception; · 192 unmodified lines
193193 enum x86_intercept;
194194 enum x86_intercept_stage;
195195
196−#define KVM_NR_MEM_OBJS 40
197−
198196 #define KVM_NR_DB_REGS 4
199197
200198 #define DR6_BD (1 << 13)
@@ -245,17 +243,6 @@ enum x86_intercept_stage; · 44 unmodified lines
245243
246244 struct kvm_kernel_irq_routing_entry;
247245
248−/*
249− * We don't want allocation failures within the mmu code, so we preallocate
250− * enough memory for a single page fault in a cache.
251− */
252−struct kvm_mmu_memory_cache {
253− int nobjs;
254− gfp_t gfp_zero;
255− struct kmem_cache *kmem_cache;
256− void *objects[KVM_NR_MEM_OBJS];
257−};
258−
259246 /*
260247 * the pages used as guest page table on soft mmu are tracked by
261248 * kvm_memory_slot.arch.gfn_track which is 16 bits, so the role bits used
arch/x86/include/asm/kvm_types.h+7−0
@@ -0,0 +1,7 @@
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 */
include/asm-generic/kvm_types.h+5−0
@@ -0,0 +1,5 @@
1+/* SPDX-License-Identifier: GPL-2.0 */
2+#ifndef _ASM_GENERIC_KVM_TYPES_H
3+#define _ASM_GENERIC_KVM_TYPES_H
4+
5+#endif
include/linux/kvm_types.h+19−0
@@ -20,6 +20,8 @@ enum kvm_mr_change; · 19 unmodified lines
2020
2121 #include <linux/types.h>
2222
23+#include <asm/kvm_types.h>
24+
2325 /*
2426 * Address types:
2527 *
@@ -58,4 +60,21 @@ struct gfn_to_pfn_cache { · 32 unmodified lines
5860 bool dirty;
5961 };
6062
63+#ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE
64+/*
65+ * Memory caches are used to preallocate memory ahead of various MMU flows,
66+ * e.g. page fault handlers. Gracefully handling allocation failures deep in
67+ * MMU flows is problematic, as is triggering reclaim, I/O, etc... while
68+ * holding MMU locks. Note, these caches act more like prefetch buffers than
69+ * classical caches, i.e. objects are not returned to the cache on being freed.
70+ */
71+struct kvm_mmu_memory_cache {
72+ int nobjs;
73+ gfp_t gfp_zero;
74+ struct kmem_cache *kmem_cache;
75+ void *objects[KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE];
76+};
77+#endif
78+
79+
6180 #endif /* __KVM_TYPES_H__ */