All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Ritesh Harjani <ritesh.list@gmail.com>
Cc: sashiko-reviews@lists.linux.dev, kvm@vger.kernel.org,
	 Gautam Menghani <gautam@linux.ibm.com>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	 Nicholas Piggin <npiggin@gmail.com>,
	linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v4 12/23] KVM: Destroy memslots immediately after mmu_notifiers are unregistered
Date: Tue, 3 Nov 2026 16:17:15 -0800	[thread overview]
Message-ID: <aup5i73T5aOKqcYS@google.com> (raw)
In-Reply-To: <se1h6b4t.ritesh.list@gmail.com>

On Tue, Nov 03, 2026, Ritesh Harjani wrote:
> Sean Christopherson <seanjc@google.com> writes:
> > +Gautam and PPC lists/maintainers
> > On Fri, Oct 30, 2026, sashiko-bot@kernel.org wrote:
> >> 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()
> >> > @@ -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?
> >
> > I don't think so?  Patch 3[*], "KVM: PPC: Flush/zap all memslots on kvm_arch_flush_shadow_all()",
> > should free the rmaps in response to kvm_arch_flush_shadow_all().   From what I
> > can tell, the page tables have to be in radix mode, and so the rmaps are freed via:
> >
> >   kvmppc_radix_flush_memslot()
> >   |
> >   -> kvmppc_unmap_pte()
> >      |
> >      -> kvmhv_remove_nest_rmap_range()
> >         |
> >         -> kvmhv_remove_nest_rmap_list()
> >
> 
> That's correct. Maybe, I think Sashiko didn't consider patch-3 of the series
> during review of this patch-12.
> 
> > And if that doesn't work, it means memslot deletion on an active VM is completely
> > broken.
> >
> > However, it means the memslot code in kvmhv_release_all_nested() is
> > dead code,
> 
> Not really. I do see a caller of this, for when we switch from radix
> to HPT. So we still need it.

Oh, nice, I somehow missed that.  Yay, less work to do!

> INCOMING CALLS
> - f kvmhv_release_all_nested
>   - f kvmppc_switch_mmu_to_hpt    [arch/powerpc/kvm/book3s_hv.c:5591]
>     + f kvmppc_alloc_reset_hpt    [arch/powerpc/kvm/book3s_64_mmu_hv.c:144]
>     + f kvmhv_configure_mmu       [arch/powerpc/kvm/book3s_hv.c:6330]
>   + f kvmppc_core_destroy_vm_hv   [arch/powerpc/kvm/book3s_hv.c:5930]
> 
> 
> 
> So FWIW patch-12 as such looks good to me from PowerPC perspective,
> since those rmap entries will get freed up as part of the
> mmu_notifier_unregister() (after patch-3). Agreed that Sashiko
> comment does not look correct.


  reply	other threads:[~2026-11-04  0:17 UTC|newest]

Thread overview: 35+ 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-11-02 22:03   ` Jim Mattson
2026-10-30 21:20 ` [PATCH v4 03/23] KVM: PPC: Flush/zap all memslots on kvm_arch_flush_shadow_all() Sean Christopherson
2026-11-03 17:21   ` Ritesh Harjani
2026-11-04  8:56   ` Narayana Murty N
2026-11-04 13:32     ` Sean Christopherson
2026-11-04 17:35       ` Narayana Murty N
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
2026-11-02 15:33     ` Sean Christopherson
2026-11-02 16:08       ` Sean Christopherson
2026-11-03 18:08       ` Ritesh Harjani
2026-11-04  0:17         ` Sean Christopherson [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=aup5i73T5aOKqcYS@google.com \
    --to=seanjc@google.com \
    --cc=gautam@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=ritesh.list@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.