Skip to content

Commit 5f8b259

Browse files
author
Marc Zyngier
committed
Merge branch kvm-arm64/memory-accounting into kvmarm-master/next
* kvm-arm64/memory-accounting: : . : Sprinkle a bunch of GFP_KERNEL_ACCOUNT all over the code base : to better track memory allocation made on behalf of a VM. : . KVM: arm64: Add memcg accounting to KVM allocations KVM: arm64: vgic: Add memcg accounting to vgic allocations Signed-off-by: Marc Zyngier <[email protected]>
2 parents 551a133 + 115bae9 commit 5f8b259

File tree

9 files changed

+18
-16
lines changed

9 files changed

+18
-16
lines changed

arch/arm64/kvm/arm.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,12 @@ long kvm_arch_dev_ioctl(struct file *filp,
291291

292292
struct kvm *kvm_arch_alloc_vm(void)
293293
{
294+
size_t sz = sizeof(struct kvm);
295+
294296
if (!has_vhe())
295-
return kzalloc(sizeof(struct kvm), GFP_KERNEL);
297+
return kzalloc(sz, GFP_KERNEL_ACCOUNT);
296298

297-
return vzalloc(sizeof(struct kvm));
299+
return __vmalloc(sz, GFP_KERNEL_ACCOUNT | __GFP_HIGHMEM | __GFP_ZERO);
298300
}
299301

300302
void kvm_arch_free_vm(struct kvm *kvm)

arch/arm64/kvm/mmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ int kvm_init_stage2_mmu(struct kvm *kvm, struct kvm_s2_mmu *mmu)
512512
return -EINVAL;
513513
}
514514

515-
pgt = kzalloc(sizeof(*pgt), GFP_KERNEL);
515+
pgt = kzalloc(sizeof(*pgt), GFP_KERNEL_ACCOUNT);
516516
if (!pgt)
517517
return -ENOMEM;
518518

arch/arm64/kvm/pmu-emul.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
978978
mutex_lock(&vcpu->kvm->lock);
979979

980980
if (!vcpu->kvm->arch.pmu_filter) {
981-
vcpu->kvm->arch.pmu_filter = bitmap_alloc(nr_events, GFP_KERNEL);
981+
vcpu->kvm->arch.pmu_filter = bitmap_alloc(nr_events, GFP_KERNEL_ACCOUNT);
982982
if (!vcpu->kvm->arch.pmu_filter) {
983983
mutex_unlock(&vcpu->kvm->lock);
984984
return -ENOMEM;

arch/arm64/kvm/reset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static int kvm_vcpu_finalize_sve(struct kvm_vcpu *vcpu)
106106
vl > SVE_VL_ARCH_MAX))
107107
return -EIO;
108108

109-
buf = kzalloc(SVE_SIG_REGS_SIZE(sve_vq_from_vl(vl)), GFP_KERNEL);
109+
buf = kzalloc(SVE_SIG_REGS_SIZE(sve_vq_from_vl(vl)), GFP_KERNEL_ACCOUNT);
110110
if (!buf)
111111
return -ENOMEM;
112112

arch/arm64/kvm/vgic/vgic-init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static int kvm_vgic_dist_init(struct kvm *kvm, unsigned int nr_spis)
134134
struct kvm_vcpu *vcpu0 = kvm_get_vcpu(kvm, 0);
135135
int i;
136136

137-
dist->spis = kcalloc(nr_spis, sizeof(struct vgic_irq), GFP_KERNEL);
137+
dist->spis = kcalloc(nr_spis, sizeof(struct vgic_irq), GFP_KERNEL_ACCOUNT);
138138
if (!dist->spis)
139139
return -ENOMEM;
140140

arch/arm64/kvm/vgic/vgic-irqfd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ int kvm_vgic_setup_default_irq_routing(struct kvm *kvm)
139139
u32 nr = dist->nr_spis;
140140
int i, ret;
141141

142-
entries = kcalloc(nr, sizeof(*entries), GFP_KERNEL);
142+
entries = kcalloc(nr, sizeof(*entries), GFP_KERNEL_ACCOUNT);
143143
if (!entries)
144144
return -ENOMEM;
145145

arch/arm64/kvm/vgic/vgic-its.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static struct vgic_irq *vgic_add_lpi(struct kvm *kvm, u32 intid,
4848
if (irq)
4949
return irq;
5050

51-
irq = kzalloc(sizeof(struct vgic_irq), GFP_KERNEL);
51+
irq = kzalloc(sizeof(struct vgic_irq), GFP_KERNEL_ACCOUNT);
5252
if (!irq)
5353
return ERR_PTR(-ENOMEM);
5454

@@ -332,7 +332,7 @@ int vgic_copy_lpi_list(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 **intid_ptr)
332332
* we must be careful not to overrun the array.
333333
*/
334334
irq_count = READ_ONCE(dist->lpi_list_count);
335-
intids = kmalloc_array(irq_count, sizeof(intids[0]), GFP_KERNEL);
335+
intids = kmalloc_array(irq_count, sizeof(intids[0]), GFP_KERNEL_ACCOUNT);
336336
if (!intids)
337337
return -ENOMEM;
338338

@@ -985,7 +985,7 @@ static int vgic_its_alloc_collection(struct vgic_its *its,
985985
if (!vgic_its_check_id(its, its->baser_coll_table, coll_id, NULL))
986986
return E_ITS_MAPC_COLLECTION_OOR;
987987

988-
collection = kzalloc(sizeof(*collection), GFP_KERNEL);
988+
collection = kzalloc(sizeof(*collection), GFP_KERNEL_ACCOUNT);
989989
if (!collection)
990990
return -ENOMEM;
991991

@@ -1029,7 +1029,7 @@ static struct its_ite *vgic_its_alloc_ite(struct its_device *device,
10291029
{
10301030
struct its_ite *ite;
10311031

1032-
ite = kzalloc(sizeof(*ite), GFP_KERNEL);
1032+
ite = kzalloc(sizeof(*ite), GFP_KERNEL_ACCOUNT);
10331033
if (!ite)
10341034
return ERR_PTR(-ENOMEM);
10351035

@@ -1150,7 +1150,7 @@ static struct its_device *vgic_its_alloc_device(struct vgic_its *its,
11501150
{
11511151
struct its_device *device;
11521152

1153-
device = kzalloc(sizeof(*device), GFP_KERNEL);
1153+
device = kzalloc(sizeof(*device), GFP_KERNEL_ACCOUNT);
11541154
if (!device)
11551155
return ERR_PTR(-ENOMEM);
11561156

@@ -1847,7 +1847,7 @@ void vgic_lpi_translation_cache_init(struct kvm *kvm)
18471847
struct vgic_translation_cache_entry *cte;
18481848

18491849
/* An allocation failure is not fatal */
1850-
cte = kzalloc(sizeof(*cte), GFP_KERNEL);
1850+
cte = kzalloc(sizeof(*cte), GFP_KERNEL_ACCOUNT);
18511851
if (WARN_ON(!cte))
18521852
break;
18531853

@@ -1888,7 +1888,7 @@ static int vgic_its_create(struct kvm_device *dev, u32 type)
18881888
if (type != KVM_DEV_TYPE_ARM_VGIC_ITS)
18891889
return -ENODEV;
18901890

1891-
its = kzalloc(sizeof(struct vgic_its), GFP_KERNEL);
1891+
its = kzalloc(sizeof(struct vgic_its), GFP_KERNEL_ACCOUNT);
18921892
if (!its)
18931893
return -ENOMEM;
18941894

arch/arm64/kvm/vgic/vgic-mmio-v3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ static int vgic_v3_alloc_redist_region(struct kvm *kvm, uint32_t index,
836836
if (vgic_v3_rdist_overlap(kvm, base, size))
837837
return -EINVAL;
838838

839-
rdreg = kzalloc(sizeof(*rdreg), GFP_KERNEL);
839+
rdreg = kzalloc(sizeof(*rdreg), GFP_KERNEL_ACCOUNT);
840840
if (!rdreg)
841841
return -ENOMEM;
842842

arch/arm64/kvm/vgic/vgic-v4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ int vgic_v4_init(struct kvm *kvm)
246246
nr_vcpus = atomic_read(&kvm->online_vcpus);
247247

248248
dist->its_vm.vpes = kcalloc(nr_vcpus, sizeof(*dist->its_vm.vpes),
249-
GFP_KERNEL);
249+
GFP_KERNEL_ACCOUNT);
250250
if (!dist->its_vm.vpes)
251251
return -ENOMEM;
252252

0 commit comments

Comments
 (0)