From: sashiko-bot@kernel.org
To: "Vincent Donnefort" <vdonnefort@google.com>
Cc: "Oliver Upton" <oupton@kernel.org>,
"Marc Zyngier" <maz@kernel.org>,
kvmarm@lists.linux.dev
Subject: Re: [PATCH v2 18/18] KVM: arm64: Alloc simple_buffer_page using pKVM hyp allocator
Date: Mon, 06 Jul 2026 18:19:56 +0000 [thread overview]
Message-ID: <20260706181957.4D01A1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260706175415.2604046-19-vdonnefort@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing validation of host-supplied `nr_page_va` causes EL2 memory leak and host infinite loop.
--
commit 20e38c941fd5614b7d02825f2350aeac0276e149
Author: Vincent Donnefort <vdonnefort@google.com>
KVM: arm64: Alloc simple_buffer_page using pKVM hyp allocator
This patch transitions the allocation of the simple_ring_buffer structures
from the host to the hypervisor in protected mode using the new pKVM heap
allocator. It uses pkvm_call_hyp_req() to handle potential top-up requests
during allocation.
> diff --git a/arch/arm64/kvm/hyp/nvhe/trace.c b/arch/arm64/kvm/hyp/nvhe/trace.c
> index 6e716295247ad..bcfe06bba29bb 100644
> --- a/arch/arm64/kvm/hyp/nvhe/trace.c
> +++ b/arch/arm64/kvm/hyp/nvhe/trace.c
[ ... ]
> @@ -62,18 +63,34 @@ static void __release_host_mem(void *start, u64 size)
> WARN_ON(__pkvm_hyp_donate_host(hyp_virt_to_pfn(start), size >> PAGE_SHIFT));
> }
>
> -static int hyp_trace_buffer_load_bpage_backing(struct hyp_trace_buffer *trace_buffer,
> - struct hyp_trace_desc *desc)
> +static int hyp_trace_buffer_alloc_bpages(struct hyp_trace_buffer *trace_buffer,
> + struct hyp_trace_desc *desc)
> {
> - void *start = (void *)kern_hyp_va(desc->bpages_backing_start);
> - size_t size = desc->bpages_backing_size;
> + void *start;
> + size_t size;
> int ret;
>
> - ret = __admit_host_mem(start, size);
> - if (ret)
> - return ret;
> + if (is_protected_kvm_enabled()) {
> + struct ring_buffer_desc *rb_desc;
> + int cpu;
> +
> + size = 0;
> + for_each_ring_buffer_desc(rb_desc, cpu, &desc->trace_buffer_desc)
> + size += rb_desc->nr_page_va * sizeof(struct simple_buffer_page);
> +
> + start = hyp_alloc(size);
[Severity: High]
Is there a missing bounds check on the host-supplied nr_page_va here?
If the host sets nr_page_va to 0 for all CPUs, size will be 0, but
hyp_alloc(0) will still succeed by allocating MIN_ALLOC_SIZE.
> + if (!start)
> + return hyp_alloc_errno();
> + } else {
> + start = (void *)kern_hyp_va(desc->bpages_backing_start);
> + size = desc->bpages_backing_size;
>
> - memset(start, 0, size);
> + ret = __admit_host_mem(start, size);
> + if (ret)
> + return ret;
> +
> + memset(start, 0, size);
> + }
[ ... ]
> @@ -81,7 +98,7 @@ static int hyp_trace_buffer_load_bpage_backing(struct hyp_trace_buffer *trace_bu
> return 0;
> }
>
> -static void hyp_trace_buffer_unload_bpage_backing(struct hyp_trace_buffer *trace_buffer)
> +static void hyp_trace_buffer_free_bpages(struct hyp_trace_buffer *trace_buffer)
> {
> void *start = trace_buffer->bpages_backing_start;
> size_t size = trace_buffer->bpages_backing_size;
> @@ -89,9 +106,12 @@ static void hyp_trace_buffer_unload_bpage_backing(struct hyp_trace_buffer *trace
> if (!size)
> return;
[Severity: High]
Will this early return permanently leak the memory allocated above?
If size evaluated to 0 during allocation, simple_ring_buffer_init_mm()
fails with -EINVAL and triggers this cleanup path. Since size is 0, this
returns early without calling hyp_free(), leaking the MIN_ALLOC_SIZE chunk
in the EL2 heap.
Could exhausting the EL2 heap this way cause a subsequent 0-page topup
request back to the host, resulting in an infinite loop in the host CPU's
pkvm_call_hyp_req() macro?
> - memset(start, 0, size);
> -
> - __release_host_mem(start, size);
> + if (is_protected_kvm_enabled()) {
> + hyp_free(start);
> + } else {
> + memset(start, 0, size);
> + __release_host_mem(start, size);
> + }
>
> trace_buffer->bpages_backing_start = 0;
> trace_buffer->bpages_backing_size = 0;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260706175415.2604046-1-vdonnefort@google.com?part=18
next prev parent reply other threads:[~2026-07-06 18:19 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 17:53 [PATCH v2 00/18] KVM: arm64: Introduce pKVM hypervisor heap allocator Vincent Donnefort
2026-07-06 17:53 ` [PATCH v2 01/18] KVM: arm64: Add __pkvm_private_range_pa Vincent Donnefort
2026-07-14 16:59 ` Fuad Tabba
2026-07-06 17:53 ` [PATCH v2 02/18] KVM: arm64: Add pkvm_remove_mappings Vincent Donnefort
2026-07-14 17:48 ` Fuad Tabba
2026-07-06 17:54 ` [PATCH v2 03/18] KVM: arm64: Add __hyp_allocator_map for the pKVM hyp Vincent Donnefort
2026-07-14 17:53 ` Fuad Tabba
2026-07-15 8:58 ` Vincent Donnefort
2026-07-15 9:24 ` Fuad Tabba
2026-07-06 17:54 ` [PATCH v2 04/18] KVM: arm64: Add a heap allocator " Vincent Donnefort
2026-07-06 18:12 ` sashiko-bot
2026-07-08 15:54 ` Vincent Donnefort
2026-07-14 18:35 ` Fuad Tabba
2026-07-15 10:59 ` Fuad Tabba
2026-07-20 12:30 ` Vincent Donnefort
2026-07-06 17:54 ` [PATCH v2 05/18] KVM: arm64: Allow kvm_hyp_memcache usage outside of stage-2 Vincent Donnefort
2026-07-14 19:00 ` Fuad Tabba
2026-07-06 17:54 ` [PATCH v2 06/18] KVM: arm64: Add topup interface for the pKVM heap allocator Vincent Donnefort
2026-07-06 18:14 ` sashiko-bot
2026-07-14 19:28 ` Fuad Tabba
2026-07-06 17:54 ` [PATCH v2 07/18] KVM: arm64: Add pkvm_hyp_req infrastructure Vincent Donnefort
2026-07-14 19:45 ` Fuad Tabba
2026-07-06 17:54 ` [PATCH v2 08/18] KVM: arm64: Handle PKVM_HYP_REQ_HYP_ALLOC request Vincent Donnefort
2026-07-15 6:28 ` Fuad Tabba
2026-07-06 17:54 ` [PATCH v2 09/18] KVM: arm64: Add reclaim interface for the pKVM heap alloc Vincent Donnefort
2026-07-14 20:10 ` Fuad Tabba
2026-07-06 17:54 ` [PATCH v2 10/18] KVM: arm64: Add selftests for the pKVM heap allocator Vincent Donnefort
2026-07-15 11:07 ` Fuad Tabba
2026-07-06 17:54 ` [PATCH v2 11/18] KVM: arm64: Add a shrinker for pKVM Vincent Donnefort
2026-07-06 18:13 ` sashiko-bot
2026-07-15 11:20 ` Fuad Tabba
2026-07-15 11:35 ` Vincent Donnefort
2026-07-06 17:54 ` [PATCH v2 12/18] KVM: arm64: Filter out non-kernel addresses in kern_hyp_va Vincent Donnefort
2026-07-15 11:30 ` Fuad Tabba
2026-07-06 17:54 ` [PATCH v2 13/18] KVM: arm64: Move hyp_vm refcount into the structure Vincent Donnefort
2026-07-15 11:35 ` Fuad Tabba
2026-07-06 17:54 ` [PATCH v2 14/18] KVM: arm64: Use noclear for PGD in __pkvm_init_vm error path Vincent Donnefort
2026-07-06 18:17 ` sashiko-bot
2026-07-15 12:09 ` Fuad Tabba
2026-07-20 13:41 ` Vincent Donnefort
2026-07-06 17:54 ` [PATCH v2 15/18] KVM: arm64: Alloc pkvm_hyp_vm using pKVM heap allocator Vincent Donnefort
2026-07-06 18:24 ` sashiko-bot
2026-07-15 12:33 ` Fuad Tabba
2026-07-15 12:55 ` Vincent Donnefort
2026-07-15 12:58 ` Fuad Tabba
2026-07-06 17:54 ` [PATCH v2 16/18] KVM: arm64: Alloc pkvm_hyp_vcpu " Vincent Donnefort
2026-07-06 18:24 ` sashiko-bot
2026-07-15 13:12 ` Fuad Tabba
2026-07-06 17:54 ` [PATCH v2 17/18] KVM: arm64: Reject hyp trace descriptors with fewer CPUs than hyp_nr_cpus Vincent Donnefort
2026-07-15 13:54 ` Fuad Tabba
2026-07-06 17:54 ` [PATCH v2 18/18] KVM: arm64: Alloc simple_buffer_page using pKVM hyp allocator Vincent Donnefort
2026-07-06 18:19 ` sashiko-bot [this message]
2026-07-15 15:07 ` Fuad Tabba
2026-07-20 14:04 ` Vincent Donnefort
2026-07-20 14:10 ` Vincent Donnefort
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=20260706181957.4D01A1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vdonnefort@google.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