Skip to content

Commit 4ab0e47

Browse files
committed
KVM: Add gfp_custom flag in struct kvm_mmu_memory_cache
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>
1 parent 8a06156 commit 4ab0e47

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

include/linux/kvm_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ struct gfn_to_pfn_cache {
8787
struct kvm_mmu_memory_cache {
8888
int nobjs;
8989
gfp_t gfp_zero;
90+
gfp_t gfp_custom;
9091
struct kmem_cache *kmem_cache;
9192
void *objects[KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE];
9293
};

virt/kvm/kvm_main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,9 @@ int kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int min)
386386
if (mc->nobjs >= min)
387387
return 0;
388388
while (mc->nobjs < ARRAY_SIZE(mc->objects)) {
389-
obj = mmu_memory_cache_alloc_obj(mc, GFP_KERNEL_ACCOUNT);
389+
obj = mmu_memory_cache_alloc_obj(mc, (mc->gfp_custom) ?
390+
mc->gfp_custom :
391+
GFP_KERNEL_ACCOUNT);
390392
if (!obj)
391393
return mc->nobjs >= min ? 0 : -ENOMEM;
392394
mc->objects[mc->nobjs++] = obj;

0 commit comments

Comments
 (0)