From: sashiko-bot@kernel.org
To: "Sean Christopherson" <seanjc@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v4 12/23] KVM: Destroy memslots immediately after mmu_notifiers are unregistered
Date: Fri, 30 Oct 2026 23:16:45 +0000 [thread overview]
Message-ID: <sashiko-outbox-191627@kernel.org> (raw)
In-Reply-To: <20261030212112.2598640-13-seanjc@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] KVM: PPC: Book3S HV: rmap_nested memory leak in kvmhv_release_all_nested()
--
commit 9c25a1b4a76e8526eb8a2b11e1b9e63893b0de80
Author: Sean Christopherson <seanjc@google.com>
KVM: Destroy memslots immediately after mmu_notifiers are unregistered
This commit replaces active memslots with an empty memslot set and frees all
memslots immediately after unregistering the MMU notifier in kvm_destroy_vm(),
prior to calling kvm_arch_destroy_vm().
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index fa548b12228ff..2eda12a52bf4b 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
[ ... ]
> @@ -1310,12 +1329,10 @@ static void kvm_destroy_vm(struct kvm *kvm)
> kvm->mn_active_invalidate_count = 0;
> else
> WARN_ON(kvm->mmu_invalidate_in_progress);
> + kvm_destroy_memslots(kvm);
> +
> kvm_arch_destroy_vm(kvm);
> kvm_destroy_devices(kvm);
> - for (i = 0; i < kvm_arch_nr_memslot_as_ids(kvm); i++) {
> - kvm_free_memslots(kvm, &kvm->__memslots[i][0]);
> - kvm_free_memslots(kvm, &kvm->__memslots[i][1]);
> - }
[Severity: Medium]
Does hoisting kvm_destroy_memslots() above kvm_arch_destroy_vm() leak
struct rmap_nested allocations in slot->arch.rmap on PowerPC Book3S HV when
destroying a VM with nested virtualization enabled?
In virt/kvm/kvm_main.c, kvm_destroy_memslots() replaces kvm->memslots[i]
with kvm_empty_memslots and frees each memslot via
kvm_free_memslot() -> kvm_arch_free_memslot() -> kvmppc_core_free_memslot_hv()
in arch/powerpc/kvm/book3s_hv.c:
static void kvmppc_core_free_memslot_hv(struct kvm_memory_slot *slot)
{
vfree(slot->arch.rmap);
slot->arch.rmap = NULL;
}
which frees the slot->arch.rmap array without freeing the linked
struct rmap_nested entries.
Previously, those entries were freed before memslot destruction via
kvm_arch_destroy_vm() -> kvmppc_core_destroy_vm_hv() ->
kvmhv_release_all_nested() in arch/powerpc/kvm/book3s_hv_nested.c:
srcu_idx = srcu_read_lock(&kvm->srcu);
kvm_for_each_memslot(memslot, bkt, kvm_memslots(kvm))
kvmhv_free_memslot_nest_rmap(memslot);
srcu_read_unlock(&kvm->srcu, srcu_idx);
With kvm_destroy_memslots() running before kvm_arch_destroy_vm(),
kvm_memslots(kvm) now returns kvm_empty_memslots and the memslots have
already been freed when kvmhv_release_all_nested() runs, so
kvmhv_free_memslot_nest_rmap() is never called. Any struct rmap_nested
entries remaining in slot->arch.rmap at teardown (for example, when
KVMPPC_SECURE_INIT_DONE causes kvmppc_radix_flush_memslot() to return early,
or when 4KB PTEs were replaced by a huge page in kvmppc_unmap_free_pte())
will be leaked.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261030212112.2598640-1-seanjc@google.com?part=12
next prev parent reply other threads:[~2026-10-30 23:16 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 21:20 [PATCH v4 00/23] KVM: Fix+harden against bad uaccess using dying VM Sean Christopherson
2026-10-30 21:20 ` [PATCH v4 01/23] KVM: Reject user accesses to guest memory if current->mm != kvm->mm Sean Christopherson
2026-10-30 21:20 ` [PATCH v4 02/23] KVM: nVMX: Don't force a full nested VM-Exit when destroying a vCPU Sean Christopherson
2026-10-30 21:20 ` [PATCH v4 03/23] KVM: PPC: Flush/zap all memslots on kvm_arch_flush_shadow_all() Sean Christopherson
2026-10-30 21:20 ` [PATCH v4 04/23] KVM: x86: Drop dead check on an existing memslot not having any pages Sean Christopherson
2026-10-30 21:20 ` [PATCH v4 05/23] KVM: WARN and error out if memslot update encounters existing slot with no pages Sean Christopherson
2026-10-30 21:20 ` [PATCH v4 06/23] KVM: x86: Unmap VMAs for KVM-internal memslots when the memslot is freed Sean Christopherson
2026-10-30 21:20 ` [PATCH v4 07/23] KVM: x86: Delete non-SMM internal memslot if creating SMM memslot fails Sean Christopherson
2026-10-30 21:20 ` [PATCH v4 08/23] KVM: x86: Process all address spaces when deleting internal memslot Sean Christopherson
2026-10-30 21:20 ` [PATCH v4 09/23] KVM: x86: Re-queue APICv update request if inhibiting APIC access page fails Sean Christopherson
2026-10-30 21:20 ` [PATCH v4 10/23] KVM: x86: Map a separate VMA for each address space for internal memslots Sean Christopherson
2026-10-30 22:54 ` sashiko-bot
2026-10-30 21:20 ` [PATCH v4 11/23] KVM: Disallow setting memslots when the VM is being destroyed Sean Christopherson
2026-10-30 21:21 ` [PATCH v4 12/23] KVM: Destroy memslots immediately after mmu_notifiers are unregistered Sean Christopherson
2026-10-30 23:16 ` sashiko-bot [this message]
2026-10-30 21:21 ` [PATCH v4 13/23] KVM: WARN if KVM attempts to do guest-related uaccess with "wrong" process Sean Christopherson
2026-10-30 21:21 ` [PATCH v4 14/23] KVM: WARN and reject guest-based uaccess if VM is dying Sean Christopherson
2026-10-30 21:21 ` [PATCH v4 15/23] KVM: Pre-check uaccesses in KVM's APIs to read/write guest memory Sean Christopherson
2026-10-30 21:21 ` [PATCH v4 16/23] KVM: VMX: Explicility free vmcs01, not the current VMCS, in vCPU free paths Sean Christopherson
2026-10-30 21:21 ` [PATCH v4 17/23] KVM: nVMX: Don't explicitly VMCLEAR+free() vmcs01's shadow VMCS when freeing vCPU Sean Christopherson
2026-10-30 21:21 ` [PATCH v4 18/23] KVM: nVMX: Cancel the nested VMX Preemption Timer's hrtimer in free_nested() Sean Christopherson
2026-10-30 21:21 ` [PATCH v4 19/23] KVM: Add lockdep-only APIs to query and assert that a vCPU is unreachable Sean Christopherson
2026-10-30 21:21 ` [PATCH v4 20/23] KVM: VMX: Explicitly remove dying vCPUs from the PI wakeup list Sean Christopherson
2026-10-30 21:21 ` [PATCH v4 21/23] KVM: nVMX: Don't switch to vmcs01 when freeing a vCPU Sean Christopherson
2026-10-30 21:21 ` [PATCH v4 22/23] KVM: nVMX: Don't load+put the vCPU when freeing nested state for a dying vCPU Sean Christopherson
2026-10-30 21:21 ` [PATCH v4 23/23] KVM: x86: Rename __x86_set_memory_region() => x86_set_internal_memslot() Sean Christopherson
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=sashiko-outbox-191627@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=seanjc@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