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 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2generic-y += early_ioremap.h2generic-y += early_ioremap.h
3generic-y += kvm_types.h
3generic-y += local64.h4generic-y += local64.h
4generic-y += mcs_spinlock.h5generic-y += mcs_spinlock.h
5generic-y += qrwlock.h6generic-y += qrwlock.h
arch/mips/include/asm/Kbuild+1−0
@@ -5,6 +5,7 @@ generated-y += syscall_table_64_n32.h · 4 unmodified lines
5generated-y += syscall_table_64_n64.h5generated-y += syscall_table_64_n64.h
6generated-y += syscall_table_64_o32.h6generated-y += syscall_table_64_o32.h
7generic-y += export.h7generic-y += export.h
8generic-y += kvm_types.h
8generic-y += local64.h9generic-y += local64.h
9generic-y += mcs_spinlock.h10generic-y += mcs_spinlock.h
10generic-y += parport.h11generic-y += parport.h
arch/powerpc/include/asm/Kbuild+1−0
@@ -4,6 +4,7 @@ generated-y += syscall_table_64.h · 3 unmodified lines
4generated-y += syscall_table_c32.h4generated-y += syscall_table_c32.h
5generated-y += syscall_table_spu.h5generated-y += syscall_table_spu.h
6generic-y += export.h6generic-y += export.h
7generic-y += kvm_types.h
7generic-y += local64.h8generic-y += local64.h
8generic-y += mcs_spinlock.h9generic-y += mcs_spinlock.h
9generic-y += vtime.h10generic-y += vtime.h
arch/s390/include/asm/Kbuild+1−0
@@ -6,5 +6,6 @@ generated-y += unistd_nr.h · 5 unmodified lines
6 6
7generic-y += asm-offsets.h7generic-y += asm-offsets.h
8generic-y += export.h8generic-y += export.h
9generic-y += kvm_types.h
9generic-y += local64.h10generic-y += local64.h
10generic-y += mcs_spinlock.h11generic-y += mcs_spinlock.h
arch/x86/include/asm/kvm_host.h+0−13
@@ -193,8 +193,6 @@ struct x86_exception; · 192 unmodified lines
193enum x86_intercept;193enum x86_intercept;
194enum x86_intercept_stage;194enum x86_intercept_stage;
195 195
196#define KVM_NR_MEM_OBJS 40
197
198#define KVM_NR_DB_REGS 4196#define KVM_NR_DB_REGS 4
199 197
200#define DR6_BD (1 << 13)198#define DR6_BD (1 << 13)
@@ -245,17 +243,6 @@ enum x86_intercept_stage; · 44 unmodified lines
245 243
246struct kvm_kernel_irq_routing_entry;244struct kvm_kernel_irq_routing_entry;
247 245
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 */
252struct 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
259/*246/*
260 * the pages used as guest page table on soft mmu are tracked by247 * the pages used as guest page table on soft mmu are tracked by
261 * kvm_memory_slot.arch.gfn_track which is 16 bits, so the role bits used248 * 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
20 20
21#include <linux/types.h>21#include <linux/types.h>
22 22
23#include <asm/kvm_types.h>
24
23/*25/*
24 * Address types:26 * Address types:
25 *27 *
@@ -58,4 +60,21 @@ struct gfn_to_pfn_cache { · 32 unmodified lines
58 bool dirty;60 bool dirty;
59};61};
60 62
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 */
71struct 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
61#endif /* __KVM_TYPES_H__ */80#endif /* __KVM_TYPES_H__ */