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.
Unified · Split
| @@ -1,5 +1,6 @@ | |||
| 1 | # SPDX-License-Identifier: GPL-2.0 | 1 | # SPDX-License-Identifier: GPL-2.0 |
| 2 | generic-y += early_ioremap.h | 2 | generic-y += early_ioremap.h |
| 3 | generic-y += kvm_types.h | ||
| 3 | generic-y += local64.h | 4 | generic-y += local64.h |
| 4 | generic-y += mcs_spinlock.h | 5 | generic-y += mcs_spinlock.h |
| 5 | generic-y += qrwlock.h | 6 | generic-y += qrwlock.h |
| @@ -5,6 +5,7 @@ generated-y += syscall_table_64_n32.h · 4 unmodified lines | |||
| 5 | generated-y += syscall_table_64_n64.h | 5 | generated-y += syscall_table_64_n64.h |
| 6 | generated-y += syscall_table_64_o32.h | 6 | generated-y += syscall_table_64_o32.h |
| 7 | generic-y += export.h | 7 | generic-y += export.h |
| 8 | generic-y += kvm_types.h | ||
| 8 | generic-y += local64.h | 9 | generic-y += local64.h |
| 9 | generic-y += mcs_spinlock.h | 10 | generic-y += mcs_spinlock.h |
| 10 | generic-y += parport.h | 11 | generic-y += parport.h |
| @@ -4,6 +4,7 @@ generated-y += syscall_table_64.h · 3 unmodified lines | |||
| 4 | generated-y += syscall_table_c32.h | 4 | generated-y += syscall_table_c32.h |
| 5 | generated-y += syscall_table_spu.h | 5 | generated-y += syscall_table_spu.h |
| 6 | generic-y += export.h | 6 | generic-y += export.h |
| 7 | generic-y += kvm_types.h | ||
| 7 | generic-y += local64.h | 8 | generic-y += local64.h |
| 8 | generic-y += mcs_spinlock.h | 9 | generic-y += mcs_spinlock.h |
| 9 | generic-y += vtime.h | 10 | generic-y += vtime.h |
| @@ -6,5 +6,6 @@ generated-y += unistd_nr.h · 5 unmodified lines | |||
| 6 | 6 | ||
| 7 | generic-y += asm-offsets.h | 7 | generic-y += asm-offsets.h |
| 8 | generic-y += export.h | 8 | generic-y += export.h |
| 9 | generic-y += kvm_types.h | ||
| 9 | generic-y += local64.h | 10 | generic-y += local64.h |
| 10 | generic-y += mcs_spinlock.h | 11 | generic-y += mcs_spinlock.h |
| @@ -193,8 +193,6 @@ struct x86_exception; · 192 unmodified lines | |||
| 193 | enum x86_intercept; | 193 | enum x86_intercept; |
| 194 | enum x86_intercept_stage; | 194 | enum x86_intercept_stage; |
| 195 | 195 | ||
| 196 | #define KVM_NR_MEM_OBJS 40 | ||
| 197 | |||
| 198 | #define KVM_NR_DB_REGS 4 | 196 | #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 | ||
| 246 | struct kvm_kernel_irq_routing_entry; | 244 | struct 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 | */ | ||
| 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 | |||
| 259 | /* | 246 | /* |
| 260 | * the pages used as guest page table on soft mmu are tracked by | 247 | * 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 used | 248 | * kvm_memory_slot.arch.gfn_track which is 16 bits, so the role bits used |
| @@ -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 */ | ||
| @@ -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 | ||
| @@ -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 | */ | ||
| 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 | |||
| 61 | #endif /* __KVM_TYPES_H__ */ | 80 | #endif /* __KVM_TYPES_H__ */ |