KVM: Add gfp_custom flag in struct kvm_mmu_memory_cache
authorAnup Patel <apatel@ventanamicro.com>
Fri, 29 Jul 2022 11:45:00 +0000 (17:15 +0530)
committerAnup Patel <anup@brainfault.org>
Fri, 29 Jul 2022 11:45:00 +0000 (17:15 +0530)
The kvm_mmu_topup_memory_cache() always uses GFP_KERNEL_ACCOUNT for
memory allocation which prevents it's use in atomic context. To address
this limitation of kvm_mmu_topup_memory_cache(), we add gfp_custom flag
in struct kvm_mmu_memory_cache. When the gfp_custom flag is set to some
GFP_xyz flags, the kvm_mmu_topup_memory_cache() will use that instead of
GFP_KERNEL_ACCOUNT.

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Atish Patra <atishp@rivosinc.com>
Signed-off-by: Anup Patel <anup@brainfault.org>
include/linux/kvm_types.h
virt/kvm/kvm_main.c

index ac1ebb3..1dcfba6 100644 (file)
@@ -87,6 +87,7 @@ struct gfn_to_pfn_cache {
 struct kvm_mmu_memory_cache {
        int nobjs;
        gfp_t gfp_zero;
+       gfp_t gfp_custom;
        struct kmem_cache *kmem_cache;
        void *objects[KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE];
 };
index a49df89..e3a6f76 100644 (file)
@@ -386,7 +386,9 @@ int kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int min)
        if (mc->nobjs >= min)
                return 0;
        while (mc->nobjs < ARRAY_SIZE(mc->objects)) {
-               obj = mmu_memory_cache_alloc_obj(mc, GFP_KERNEL_ACCOUNT);
+               obj = mmu_memory_cache_alloc_obj(mc, (mc->gfp_custom) ?
+                                                mc->gfp_custom :
+                                                GFP_KERNEL_ACCOUNT);
                if (!obj)
                        return mc->nobjs >= min ? 0 : -ENOMEM;
                mc->objects[mc->nobjs++] = obj;