Skip to content

Commit 115bae9

Browse files
justin-heMarc Zyngier
authored andcommitted
KVM: arm64: Add memcg accounting to KVM allocations
Inspired by commit 254272c ("kvm: x86: Add memcg accounting to KVM allocations"), it would be better to make arm64 KVM 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 3ef2316 commit 115bae9

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
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

0 commit comments

Comments
 (0)