Message ID | 20200605213853.14959-15-sean.j.christopherson@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | KVM: Cleanup and unify kvm_mmu_memory_cache usage | expand |
On Fri, Jun 5, 2020 at 2:39 PM Sean Christopherson <sean.j.christopherson@intel.com> wrote: > > 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. > > Suggested-by: Christoffer Dall <christoffer.dall@arm.com> > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Reviewed-by: Ben Gardon <bgardon@google.com> > --- > arch/arm64/include/asm/kvm_types.h | 6 ++++++ > arch/mips/include/asm/kvm_types.h | 5 +++++ > arch/powerpc/include/asm/kvm_types.h | 5 +++++ > arch/s390/include/asm/kvm_types.h | 5 +++++ > arch/x86/include/asm/kvm_host.h | 13 ------------- > arch/x86/include/asm/kvm_types.h | 7 +++++++ > include/linux/kvm_types.h | 19 +++++++++++++++++++ > 7 files changed, 47 insertions(+), 13 deletions(-) > create mode 100644 arch/arm64/include/asm/kvm_types.h > create mode 100644 arch/mips/include/asm/kvm_types.h > create mode 100644 arch/powerpc/include/asm/kvm_types.h > create mode 100644 arch/s390/include/asm/kvm_types.h > create mode 100644 arch/x86/include/asm/kvm_types.h > > diff --git a/arch/arm64/include/asm/kvm_types.h b/arch/arm64/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..d0987007d581 > --- /dev/null > +++ b/arch/arm64/include/asm/kvm_types.h > @@ -0,0 +1,6 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_ARM64_KVM_TYPES_H > +#define _ASM_ARM64_KVM_TYPES_H > + > +#endif /* _ASM_ARM64_KVM_TYPES_H */ > + > diff --git a/arch/mips/include/asm/kvm_types.h b/arch/mips/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..5efeb32a5926 > --- /dev/null > +++ b/arch/mips/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_MIPS_KVM_TYPES_H > +#define _ASM_MIPS_KVM_TYPES_H > + > +#endif /* _ASM_MIPS_KVM_TYPES_H */ > diff --git a/arch/powerpc/include/asm/kvm_types.h b/arch/powerpc/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..f627eceaa314 > --- /dev/null > +++ b/arch/powerpc/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_POWERPC_KVM_TYPES_H > +#define _ASM_POWERPC_KVM_TYPES_H > + > +#endif /* _ASM_POWERPC_KVM_TYPES_H */ > diff --git a/arch/s390/include/asm/kvm_types.h b/arch/s390/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..b66a81f8a354 > --- /dev/null > +++ b/arch/s390/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_S390_KVM_TYPES_H > +#define _ASM_S390_KVM_TYPES_H > + > +#endif /* _ASM_S390_KVM_TYPES_H */ > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index fb99e6776e27..8e8fea13b6c7 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -193,8 +193,6 @@ struct x86_exception; > enum x86_intercept; > enum x86_intercept_stage; > > -#define KVM_NR_MEM_OBJS 40 > - > #define KVM_NR_DB_REGS 4 > > #define DR6_BD (1 << 13) > @@ -245,17 +243,6 @@ enum x86_intercept_stage; > > struct kvm_kernel_irq_routing_entry; > > -/* > - * We don't want allocation failures within the mmu code, so we preallocate > - * enough memory for a single page fault in a cache. > - */ > -struct kvm_mmu_memory_cache { > - int nobjs; > - gfp_t gfp_zero; > - struct kmem_cache *kmem_cache; > - void *objects[KVM_NR_MEM_OBJS]; > -}; > - > /* > * the pages used as guest page table on soft mmu are tracked by > * kvm_memory_slot.arch.gfn_track which is 16 bits, so the role bits used > diff --git a/arch/x86/include/asm/kvm_types.h b/arch/x86/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..08f1b57d3b62 > --- /dev/null > +++ b/arch/x86/include/asm/kvm_types.h > @@ -0,0 +1,7 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_X86_KVM_TYPES_H > +#define _ASM_X86_KVM_TYPES_H > + > +#define KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE 40 > + > +#endif /* _ASM_X86_KVM_TYPES_H */ > diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h > index 68e84cf42a3f..a7580f69dda0 100644 > --- a/include/linux/kvm_types.h > +++ b/include/linux/kvm_types.h > @@ -20,6 +20,8 @@ enum kvm_mr_change; > > #include <linux/types.h> > > +#include <asm/kvm_types.h> > + > /* > * Address types: > * > @@ -58,4 +60,21 @@ struct gfn_to_pfn_cache { > bool dirty; > }; > > +#ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE > +/* > + * Memory caches are used to preallocate memory ahead of various MMU flows, > + * e.g. page fault handlers. Gracefully handling allocation failures deep in > + * MMU flows is problematic, as is triggering reclaim, I/O, etc... while > + * holding MMU locks. Note, these caches act more like prefetch buffers than > + * classical caches, i.e. objects are not returned to the cache on being freed. > + */ > +struct kvm_mmu_memory_cache { > + int nobjs; > + gfp_t gfp_zero; > + struct kmem_cache *kmem_cache; > + void *objects[KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE]; > +}; > +#endif > + > + > #endif /* __KVM_TYPES_H__ */ > -- > 2.26.0 >
On Wed, Jun 10, 2020 at 12:01 PM Ben Gardon <bgardon@google.com> wrote: > > On Fri, Jun 5, 2020 at 2:39 PM Sean Christopherson > <sean.j.christopherson@intel.com> wrote: > > > > 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. > > > > Suggested-by: Christoffer Dall <christoffer.dall@arm.com> > > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> > Reviewed-by: Ben Gardon <bgardon@google.com> > > --- > > arch/arm64/include/asm/kvm_types.h | 6 ++++++ > > arch/mips/include/asm/kvm_types.h | 5 +++++ > > arch/powerpc/include/asm/kvm_types.h | 5 +++++ > > arch/s390/include/asm/kvm_types.h | 5 +++++ > > arch/x86/include/asm/kvm_host.h | 13 ------------- > > arch/x86/include/asm/kvm_types.h | 7 +++++++ > > include/linux/kvm_types.h | 19 +++++++++++++++++++ > > 7 files changed, 47 insertions(+), 13 deletions(-) > > create mode 100644 arch/arm64/include/asm/kvm_types.h > > create mode 100644 arch/mips/include/asm/kvm_types.h > > create mode 100644 arch/powerpc/include/asm/kvm_types.h > > create mode 100644 arch/s390/include/asm/kvm_types.h > > create mode 100644 arch/x86/include/asm/kvm_types.h > > > > diff --git a/arch/arm64/include/asm/kvm_types.h b/arch/arm64/include/asm/kvm_types.h > > new file mode 100644 > > index 000000000000..d0987007d581 > > --- /dev/null > > +++ b/arch/arm64/include/asm/kvm_types.h > > @@ -0,0 +1,6 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +#ifndef _ASM_ARM64_KVM_TYPES_H > > +#define _ASM_ARM64_KVM_TYPES_H > > + > > +#endif /* _ASM_ARM64_KVM_TYPES_H */ > > + > > diff --git a/arch/mips/include/asm/kvm_types.h b/arch/mips/include/asm/kvm_types.h > > new file mode 100644 > > index 000000000000..5efeb32a5926 > > --- /dev/null > > +++ b/arch/mips/include/asm/kvm_types.h > > @@ -0,0 +1,5 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +#ifndef _ASM_MIPS_KVM_TYPES_H > > +#define _ASM_MIPS_KVM_TYPES_H > > + > > +#endif /* _ASM_MIPS_KVM_TYPES_H */ > > diff --git a/arch/powerpc/include/asm/kvm_types.h b/arch/powerpc/include/asm/kvm_types.h > > new file mode 100644 > > index 000000000000..f627eceaa314 > > --- /dev/null > > +++ b/arch/powerpc/include/asm/kvm_types.h > > @@ -0,0 +1,5 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +#ifndef _ASM_POWERPC_KVM_TYPES_H > > +#define _ASM_POWERPC_KVM_TYPES_H > > + > > +#endif /* _ASM_POWERPC_KVM_TYPES_H */ > > diff --git a/arch/s390/include/asm/kvm_types.h b/arch/s390/include/asm/kvm_types.h > > new file mode 100644 > > index 000000000000..b66a81f8a354 > > --- /dev/null > > +++ b/arch/s390/include/asm/kvm_types.h > > @@ -0,0 +1,5 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +#ifndef _ASM_S390_KVM_TYPES_H > > +#define _ASM_S390_KVM_TYPES_H > > + > > +#endif /* _ASM_S390_KVM_TYPES_H */ > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > > index fb99e6776e27..8e8fea13b6c7 100644 > > --- a/arch/x86/include/asm/kvm_host.h > > +++ b/arch/x86/include/asm/kvm_host.h > > @@ -193,8 +193,6 @@ struct x86_exception; > > enum x86_intercept; > > enum x86_intercept_stage; > > > > -#define KVM_NR_MEM_OBJS 40 > > - Oops I didn't catch this on my first read through, but in patch 16 in this series I see some references to KVM_NR_MEM_OBJS being removed. As a result I would not expect this patch to build. Other references to this value should probably replaced with KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE as well. > > #define KVM_NR_DB_REGS 4 > > > > #define DR6_BD (1 << 13) > > @@ -245,17 +243,6 @@ enum x86_intercept_stage; > > > > struct kvm_kernel_irq_routing_entry; > > > > -/* > > - * We don't want allocation failures within the mmu code, so we preallocate > > - * enough memory for a single page fault in a cache. > > - */ > > -struct kvm_mmu_memory_cache { > > - int nobjs; > > - gfp_t gfp_zero; > > - struct kmem_cache *kmem_cache; > > - void *objects[KVM_NR_MEM_OBJS]; > > -}; > > - > > /* > > * the pages used as guest page table on soft mmu are tracked by > > * kvm_memory_slot.arch.gfn_track which is 16 bits, so the role bits used > > diff --git a/arch/x86/include/asm/kvm_types.h b/arch/x86/include/asm/kvm_types.h > > new file mode 100644 > > index 000000000000..08f1b57d3b62 > > --- /dev/null > > +++ b/arch/x86/include/asm/kvm_types.h > > @@ -0,0 +1,7 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +#ifndef _ASM_X86_KVM_TYPES_H > > +#define _ASM_X86_KVM_TYPES_H > > + > > +#define KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE 40 > > + > > +#endif /* _ASM_X86_KVM_TYPES_H */ > > diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h > > index 68e84cf42a3f..a7580f69dda0 100644 > > --- a/include/linux/kvm_types.h > > +++ b/include/linux/kvm_types.h > > @@ -20,6 +20,8 @@ enum kvm_mr_change; > > > > #include <linux/types.h> > > > > +#include <asm/kvm_types.h> > > + > > /* > > * Address types: > > * > > @@ -58,4 +60,21 @@ struct gfn_to_pfn_cache { > > bool dirty; > > }; > > > > +#ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE > > +/* > > + * Memory caches are used to preallocate memory ahead of various MMU flows, > > + * e.g. page fault handlers. Gracefully handling allocation failures deep in > > + * MMU flows is problematic, as is triggering reclaim, I/O, etc... while > > + * holding MMU locks. Note, these caches act more like prefetch buffers than > > + * classical caches, i.e. objects are not returned to the cache on being freed. > > + */ > > +struct kvm_mmu_memory_cache { > > + int nobjs; > > + gfp_t gfp_zero; > > + struct kmem_cache *kmem_cache; > > + void *objects[KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE]; > > +}; > > +#endif > > + > > + > > #endif /* __KVM_TYPES_H__ */ > > -- > > 2.26.0 > >
Hi Sean, On 2020-06-05 22:38, Sean Christopherson wrote: > 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. > > Suggested-by: Christoffer Dall <christoffer.dall@arm.com> > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> > --- > arch/arm64/include/asm/kvm_types.h | 6 ++++++ > arch/mips/include/asm/kvm_types.h | 5 +++++ > arch/powerpc/include/asm/kvm_types.h | 5 +++++ > arch/s390/include/asm/kvm_types.h | 5 +++++ > arch/x86/include/asm/kvm_host.h | 13 ------------- > arch/x86/include/asm/kvm_types.h | 7 +++++++ > include/linux/kvm_types.h | 19 +++++++++++++++++++ > 7 files changed, 47 insertions(+), 13 deletions(-) > create mode 100644 arch/arm64/include/asm/kvm_types.h > create mode 100644 arch/mips/include/asm/kvm_types.h > create mode 100644 arch/powerpc/include/asm/kvm_types.h > create mode 100644 arch/s390/include/asm/kvm_types.h > create mode 100644 arch/x86/include/asm/kvm_types.h > > diff --git a/arch/arm64/include/asm/kvm_types.h > b/arch/arm64/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..d0987007d581 > --- /dev/null > +++ b/arch/arm64/include/asm/kvm_types.h > @@ -0,0 +1,6 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_ARM64_KVM_TYPES_H > +#define _ASM_ARM64_KVM_TYPES_H > + > +#endif /* _ASM_ARM64_KVM_TYPES_H */ > + > diff --git a/arch/mips/include/asm/kvm_types.h > b/arch/mips/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..5efeb32a5926 > --- /dev/null > +++ b/arch/mips/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_MIPS_KVM_TYPES_H > +#define _ASM_MIPS_KVM_TYPES_H > + > +#endif /* _ASM_MIPS_KVM_TYPES_H */ > diff --git a/arch/powerpc/include/asm/kvm_types.h > b/arch/powerpc/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..f627eceaa314 > --- /dev/null > +++ b/arch/powerpc/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_POWERPC_KVM_TYPES_H > +#define _ASM_POWERPC_KVM_TYPES_H > + > +#endif /* _ASM_POWERPC_KVM_TYPES_H */ > diff --git a/arch/s390/include/asm/kvm_types.h > b/arch/s390/include/asm/kvm_types.h > new file mode 100644 > index 000000000000..b66a81f8a354 > --- /dev/null > +++ b/arch/s390/include/asm/kvm_types.h > @@ -0,0 +1,5 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _ASM_S390_KVM_TYPES_H > +#define _ASM_S390_KVM_TYPES_H > + > +#endif /* _ASM_S390_KVM_TYPES_H */ Instead of carrying an empty include file for at least two of the architectures (s390 and Power), how about having it in asm-generic, and updating arch/$ARCH/include/asm/Kbuild to point to the generic one? Thanks, M.
On Wed, Jun 10, 2020 at 02:58:21PM -0700, Ben Gardon wrote: > On Wed, Jun 10, 2020 at 12:01 PM Ben Gardon <bgardon@google.com> wrote: > > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > > > index fb99e6776e27..8e8fea13b6c7 100644 > > > --- a/arch/x86/include/asm/kvm_host.h > > > +++ b/arch/x86/include/asm/kvm_host.h > > > @@ -193,8 +193,6 @@ struct x86_exception; > > > enum x86_intercept; > > > enum x86_intercept_stage; > > > > > > -#define KVM_NR_MEM_OBJS 40 > > > - > Oops I didn't catch this on my first read through, but in patch 16 in > this series I see some references to KVM_NR_MEM_OBJS being removed. As > a result I would not expect this patch to build. Other references to > this value should probably replaced with > KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE as well. This patch intentionally uses a different name for the #define (see below) so that the existing arm64 and MIPS declarations don't get picked up by common KVM code. This is required so that arm64 and MIPS continue to use their versions of the cache implementation until they are converted to the common implementation later in the series, e.g. in patch 16 when the references to KVM_NR_MEM_OBJS are removed. I confirmed the above (after sending v1) by compiling all non-x86 changes on arm64, MIPS, s390 and PPC to verify that this doesn't break bisection. > > > #define KVM_NR_DB_REGS 4 > > > > > > #define DR6_BD (1 << 13) > > > @@ -245,17 +243,6 @@ enum x86_intercept_stage; > > > > > > struct kvm_kernel_irq_routing_entry; ... > > > +#ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE > > > +/* > > > + * Memory caches are used to preallocate memory ahead of various MMU flows, > > > + * e.g. page fault handlers. Gracefully handling allocation failures deep in > > > + * MMU flows is problematic, as is triggering reclaim, I/O, etc... while > > > + * holding MMU locks. Note, these caches act more like prefetch buffers than > > > + * classical caches, i.e. objects are not returned to the cache on being freed. > > > + */ > > > +struct kvm_mmu_memory_cache { > > > + int nobjs; > > > + gfp_t gfp_zero; > > > + struct kmem_cache *kmem_cache; > > > + void *objects[KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE]; > > > +}; > > > +#endif > > > + > > > + > > > #endif /* __KVM_TYPES_H__ */ > > > -- > > > 2.26.0 > > >
diff --git a/arch/arm64/include/asm/kvm_types.h b/arch/arm64/include/asm/kvm_types.h new file mode 100644 index 000000000000..d0987007d581 --- /dev/null +++ b/arch/arm64/include/asm/kvm_types.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_ARM64_KVM_TYPES_H +#define _ASM_ARM64_KVM_TYPES_H + +#endif /* _ASM_ARM64_KVM_TYPES_H */ + diff --git a/arch/mips/include/asm/kvm_types.h b/arch/mips/include/asm/kvm_types.h new file mode 100644 index 000000000000..5efeb32a5926 --- /dev/null +++ b/arch/mips/include/asm/kvm_types.h @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_MIPS_KVM_TYPES_H +#define _ASM_MIPS_KVM_TYPES_H + +#endif /* _ASM_MIPS_KVM_TYPES_H */ diff --git a/arch/powerpc/include/asm/kvm_types.h b/arch/powerpc/include/asm/kvm_types.h new file mode 100644 index 000000000000..f627eceaa314 --- /dev/null +++ b/arch/powerpc/include/asm/kvm_types.h @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_POWERPC_KVM_TYPES_H +#define _ASM_POWERPC_KVM_TYPES_H + +#endif /* _ASM_POWERPC_KVM_TYPES_H */ diff --git a/arch/s390/include/asm/kvm_types.h b/arch/s390/include/asm/kvm_types.h new file mode 100644 index 000000000000..b66a81f8a354 --- /dev/null +++ b/arch/s390/include/asm/kvm_types.h @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_S390_KVM_TYPES_H +#define _ASM_S390_KVM_TYPES_H + +#endif /* _ASM_S390_KVM_TYPES_H */ diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index fb99e6776e27..8e8fea13b6c7 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -193,8 +193,6 @@ struct x86_exception; enum x86_intercept; enum x86_intercept_stage; -#define KVM_NR_MEM_OBJS 40 - #define KVM_NR_DB_REGS 4 #define DR6_BD (1 << 13) @@ -245,17 +243,6 @@ enum x86_intercept_stage; struct kvm_kernel_irq_routing_entry; -/* - * We don't want allocation failures within the mmu code, so we preallocate - * enough memory for a single page fault in a cache. - */ -struct kvm_mmu_memory_cache { - int nobjs; - gfp_t gfp_zero; - struct kmem_cache *kmem_cache; - void *objects[KVM_NR_MEM_OBJS]; -}; - /* * the pages used as guest page table on soft mmu are tracked by * kvm_memory_slot.arch.gfn_track which is 16 bits, so the role bits used diff --git a/arch/x86/include/asm/kvm_types.h b/arch/x86/include/asm/kvm_types.h new file mode 100644 index 000000000000..08f1b57d3b62 --- /dev/null +++ b/arch/x86/include/asm/kvm_types.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_KVM_TYPES_H +#define _ASM_X86_KVM_TYPES_H + +#define KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE 40 + +#endif /* _ASM_X86_KVM_TYPES_H */ diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h index 68e84cf42a3f..a7580f69dda0 100644 --- a/include/linux/kvm_types.h +++ b/include/linux/kvm_types.h @@ -20,6 +20,8 @@ enum kvm_mr_change; #include <linux/types.h> +#include <asm/kvm_types.h> + /* * Address types: * @@ -58,4 +60,21 @@ struct gfn_to_pfn_cache { bool dirty; }; +#ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE +/* + * Memory caches are used to preallocate memory ahead of various MMU flows, + * e.g. page fault handlers. Gracefully handling allocation failures deep in + * MMU flows is problematic, as is triggering reclaim, I/O, etc... while + * holding MMU locks. Note, these caches act more like prefetch buffers than + * classical caches, i.e. objects are not returned to the cache on being freed. + */ +struct kvm_mmu_memory_cache { + int nobjs; + gfp_t gfp_zero; + struct kmem_cache *kmem_cache; + void *objects[KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE]; +}; +#endif + + #endif /* __KVM_TYPES_H__ */
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. Suggested-by: Christoffer Dall <christoffer.dall@arm.com> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> --- arch/arm64/include/asm/kvm_types.h | 6 ++++++ arch/mips/include/asm/kvm_types.h | 5 +++++ arch/powerpc/include/asm/kvm_types.h | 5 +++++ arch/s390/include/asm/kvm_types.h | 5 +++++ arch/x86/include/asm/kvm_host.h | 13 ------------- arch/x86/include/asm/kvm_types.h | 7 +++++++ include/linux/kvm_types.h | 19 +++++++++++++++++++ 7 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 arch/arm64/include/asm/kvm_types.h create mode 100644 arch/mips/include/asm/kvm_types.h create mode 100644 arch/powerpc/include/asm/kvm_types.h create mode 100644 arch/s390/include/asm/kvm_types.h create mode 100644 arch/x86/include/asm/kvm_types.h