Skip to content

Commit 3ef2316

Browse files
justin-heMarc Zyngier
authored andcommitted
KVM: arm64: vgic: Add memcg accounting to vgic allocations
Inspired by commit 254272c ("kvm: x86: Add memcg accounting to KVM allocations"), it would be better to make arm64 vgic consistent with common kvm codes. The memory allocations of VM scope should be charged into VM process cgroup, hence change GFP_KERNEL to GFP_KERNEL_ACCOUNT. There remain a few cases since these allocations are global, not in VM scope. Signed-off-by: Jia He <[email protected]> Reviewed-by: Oliver Upton <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9e1ff30 commit 3ef2316

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

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
@@ -834,7 +834,7 @@ static int vgic_v3_alloc_redist_region(struct kvm *kvm, uint32_t index,
834834
if (vgic_v3_rdist_overlap(kvm, base, size))
835835
return -EINVAL;
836836

837-
rdreg = kzalloc(sizeof(*rdreg), GFP_KERNEL);
837+
rdreg = kzalloc(sizeof(*rdreg), GFP_KERNEL_ACCOUNT);
838838
if (!rdreg)
839839
return -ENOMEM;
840840

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)