From: sashiko-bot@kernel.org
To: yhchen312@gmail.com
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] RISC-V: KVM: Account VM-scoped allocations to the VM cgroup
Date: Thu, 16 Jul 2026 06:54:37 +0000 [thread overview]
Message-ID: <20260716065437.ADDCB1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260716064112.2387938-1-yhchen312@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Medium] The `kvpmu->sdata` allocation uses `GFP_ATOMIC | __GFP_ACCOUNT` in a context that can safely sleep, draining atomic reserves and causing spurious memcg allocation failures.
Pre-existing issues:
- [High] Unconditional memory allocation for the PMU snapshot area leads to a memory leak if the guest repeatedly configures the snapshot.
--
--- Patch [1]: [PATCH] RISC-V: KVM: Account VM-scoped allocations to the VM cgroup ---
commit 7f2fdf55e4a9227b8c7e4853c498204f0c3f9d48
Author: Yuhang.chen <yhchen312@gmail.com>
RISC-V: KVM: Account VM-scoped allocations to the VM cgroup
Charge the per-VM and per-vCPU allocations (stage-2 PGD, APLIC state,
IMSIC context, vector context, FWFT config, PMU snapshot) to the
allocating process's memory cgroup via GFP_KERNEL_ACCOUNT / __GFP_ACCOUNT.
> diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c
> index bb46dcbfb24da..e5018784779d5 100644
> --- a/arch/riscv/kvm/vcpu_pmu.c
> +++ b/arch/riscv/kvm/vcpu_pmu.c
> @@ -452,7 +452,7 @@ int kvm_riscv_vcpu_pmu_snapshot_set_shmem(struct kvm_vcpu *vcpu, unsigned long s
> }
> }
>
> - kvpmu->sdata = kzalloc(snapshot_area_size, GFP_ATOMIC);
> + kvpmu->sdata = kzalloc(snapshot_area_size, GFP_ATOMIC | __GFP_ACCOUNT);
[Severity: High]
This isn't a bug introduced by this patch, but does this leak memory if the
guest repeatedly configures the snapshot?
If a guest makes multiple SBI_EXT_PMU_SNAPSHOT_SET_SHMEM calls, it looks
like this unconditionally allocates and overwrites kvpmu->sdata without
freeing the previous allocation.
[Severity: Medium]
Is it necessary to use GFP_ATOMIC here?
Since the immediate next call is kvm_vcpu_write_guest(), which can sleep:
/* No need to check writable slot explicitly as kvm_vcpu_write_guest does it internally */
if (kvm_vcpu_write_guest(vcpu, saddr, kvpmu->sdata, snapshot_area_size)) {
kfree(kvpmu->sdata);
kvpmu->sdata = NULL;
sbiret = SBI_ERR_INVALID_ADDRESS;
goto out;
}
it seems this allocation could safely use GFP_KERNEL_ACCOUNT instead.
Combining __GFP_ACCOUNT with GFP_ATOMIC prevents the allocation from sleeping
to perform direct reclaim, which might cause spurious memcg allocation
failures when the cgroup is under pressure.
> if (!kvpmu->sdata) {
> sbiret = SBI_ERR_FAILURE;
> goto out;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260716064112.2387938-1-yhchen312@gmail.com?part=1
prev parent reply other threads:[~2026-07-16 6:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 6:41 [PATCH] RISC-V: KVM: Account VM-scoped allocations to the VM cgroup yhchen312
2026-07-16 6:41 ` yhchen312
2026-07-16 6:41 ` yhchen312
2026-07-16 6:54 ` sashiko-bot [this message]
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=20260716065437.ADDCB1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yhchen312@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.