From: Marc Zyngier <maz@kernel.org>
To: Wanpeng Li <kernellwp@gmail.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH] KVM: arm: memcg awareness
Date: Wed, 17 Mar 2021 09:10:20 +0000 [thread overview]
Message-ID: <87mtv2i1s3.wl-maz@kernel.org> (raw)
In-Reply-To: <1615959984-7122-1-git-send-email-wanpengli@tencent.com>
On Wed, 17 Mar 2021 05:46:24 +0000,
Wanpeng Li <kernellwp@gmail.com> wrote:
>
> From: Wanpeng Li <wanpengli@tencent.com>
>
> KVM allocations in the arm kvm code which are tied to the life
> of the VM process should be charged to the VM process's cgroup.
> This will help the memcg controler to do the right decisions.
>
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> ---
> arch/arm64/kvm/arm.c | 5 +++--
> arch/arm64/kvm/hyp/pgtable.c | 4 ++--
> arch/arm64/kvm/mmu.c | 4 ++--
> arch/arm64/kvm/pmu-emul.c | 2 +-
> arch/arm64/kvm/reset.c | 2 +-
> arch/arm64/kvm/vgic/vgic-debug.c | 2 +-
> arch/arm64/kvm/vgic/vgic-init.c | 2 +-
> arch/arm64/kvm/vgic/vgic-irqfd.c | 2 +-
> arch/arm64/kvm/vgic/vgic-its.c | 14 +++++++-------
> arch/arm64/kvm/vgic/vgic-mmio-v3.c | 2 +-
> arch/arm64/kvm/vgic/vgic-v4.c | 2 +-
> 11 files changed, 21 insertions(+), 20 deletions(-)
>
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index 7f06ba7..8040874 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
> @@ -278,9 +278,10 @@ long kvm_arch_dev_ioctl(struct file *filp,
> struct kvm *kvm_arch_alloc_vm(void)
> {
> if (!has_vhe())
> - return kzalloc(sizeof(struct kvm), GFP_KERNEL);
> + return kzalloc(sizeof(struct kvm), GFP_KERNEL_ACCOUNT);
>
> - return vzalloc(sizeof(struct kvm));
> + return __vmalloc(sizeof(struct kvm),
> + GFP_KERNEL_ACCOUNT | __GFP_ZERO);
> }
>
> void kvm_arch_free_vm(struct kvm *kvm)
> diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
> index 926fc07..a0845d3 100644
> --- a/arch/arm64/kvm/hyp/pgtable.c
> +++ b/arch/arm64/kvm/hyp/pgtable.c
> @@ -366,7 +366,7 @@ static int hyp_map_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep,
> if (WARN_ON(level == KVM_PGTABLE_MAX_LEVELS - 1))
> return -EINVAL;
>
> - childp = (kvm_pte_t *)get_zeroed_page(GFP_KERNEL);
> + childp = (kvm_pte_t *)get_zeroed_page(GFP_KERNEL_ACCOUNT);
No, this is wrong.
You cannot account the hypervisor page tables to the guest because we
don't ever unmap them, and that we can't distinguish two data
structures from two different VMs occupying the same page.
> if (!childp)
> return -ENOMEM;
>
> @@ -401,7 +401,7 @@ int kvm_pgtable_hyp_init(struct kvm_pgtable *pgt, u32 va_bits)
> {
> u64 levels = ARM64_HW_PGTABLE_LEVELS(va_bits);
>
> - pgt->pgd = (kvm_pte_t *)get_zeroed_page(GFP_KERNEL);
> + pgt->pgd = (kvm_pte_t *)get_zeroed_page(GFP_KERNEL_ACCOUNT);
There is no VM in this context. There isn't even any userspace
whatsoever in the system when this is called.
[...]
> diff --git a/arch/arm64/kvm/vgic/vgic-v4.c b/arch/arm64/kvm/vgic/vgic-v4.c
> index 66508b0..a80cc37 100644
> --- a/arch/arm64/kvm/vgic/vgic-v4.c
> +++ b/arch/arm64/kvm/vgic/vgic-v4.c
> @@ -227,7 +227,7 @@ int vgic_v4_init(struct kvm *kvm)
> nr_vcpus = atomic_read(&kvm->online_vcpus);
>
> dist->its_vm.vpes = kcalloc(nr_vcpus, sizeof(*dist->its_vm.vpes),
> - GFP_KERNEL);
> + GFP_KERNEL_ACCOUNT);
And now for the elephant in the room: what you do for the GICv4 VPTs
that are allocated for each vPE?
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2021-03-17 9:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-17 5:46 [PATCH] KVM: arm: memcg awareness Wanpeng Li
2021-03-17 7:57 ` Michal Hocko
2021-03-17 8:04 ` Wanpeng Li
2021-03-17 8:04 ` Wanpeng Li
2021-03-17 9:44 ` Michal Hocko
2021-03-17 9:15 ` Marc Zyngier
2021-03-17 9:10 ` Marc Zyngier [this message]
2021-03-17 10:40 ` Paolo Bonzini
2021-03-17 10:53 ` Marc Zyngier
2021-03-17 10:55 ` Paolo Bonzini
2021-03-17 11:03 ` Marc Zyngier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mtv2i1s3.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=kernellwp@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox