From: Sean Christopherson <seanjc@google.com>
To: Vipin Sharma <vipinsh@google.com>
Cc: pbonzini@redhat.com, dmatlack@google.com, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] KVM: x86/mmu: Recover NX Huge pages belonging to TDP MMU under MMU read lock
Date: Mon, 26 Aug 2024 12:51:07 -0700 [thread overview]
Message-ID: <Zszcq2Bzt-mEnAbQ@google.com> (raw)
In-Reply-To: <20240826192410.GA2182008.vipinsh@google.com>
On Mon, Aug 26, 2024, Vipin Sharma wrote:
> On 2024-08-26 07:34:35, Sean Christopherson wrote:
> > > } else {
> > > /*
> > > * Try again in future if the page is still in the
> > > * list
> > > */
> > > spin_lock(&kvm->arch.tdp_mmu_pages_lock);
> > > if (!list_empty(&sp->possible_nx_huge_page_link))
> > > list_move_tail(&sp->possible_nx_huge_page_link,
> > > kvm-> &kvm->arch.possible_nx_huge_pages);
> >
> > This is unsafe. The only thing that prevents a use-after-free of "sp" is the fact
> > that this task holds rcu_read_lock(). The sp could already been queued for freeing
> > via call_rcu().
>
> Before call_rcu() happens, that page will be removed from
> kvm->arch.possible_nx_huge_pages list in handle_remove_pt() via
> tdp_mmu_unlink_sp() using kvm->arch.tdp_mmu_pages_lock.
Gah, my bad, I inverted the list_empty() check when reading.
> Here, we are using the same lock and checking if page is in the list or not.
> If it is in the list move to end and if it is not then don't do anything.
>
> Am I missing something else? Otherwise, this logic seems correct to me.
Nope, poor code reading on my part, especially since the _move_ action should have
made it obvious the SP is still live.
> Overall, I will be using your example code, so you won't see this code
> in next version but just want to understand the concern with this else
> part.
next prev parent reply other threads:[~2024-08-26 19:51 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-12 17:13 [PATCH 0/2] KVM: x86/mmu: Run NX huge page recovery under MMU read lock Vipin Sharma
2024-08-12 17:13 ` [PATCH 1/2] KVM: x86/mmu: Split NX hugepage recovery flow into TDP and non-TDP flow Vipin Sharma
2024-08-16 23:29 ` Sean Christopherson
2024-08-19 17:20 ` Vipin Sharma
2024-08-19 17:28 ` David Matlack
2024-08-19 18:31 ` Sean Christopherson
2024-08-19 21:57 ` Vipin Sharma
2024-08-12 17:13 ` [PATCH 2/2] KVM: x86/mmu: Recover NX Huge pages belonging to TDP MMU under MMU read lock Vipin Sharma
2024-08-14 9:33 ` kernel test robot
2024-08-14 18:23 ` Vipin Sharma
2024-08-14 22:50 ` kernel test robot
2024-08-15 16:42 ` Vipin Sharma
2024-08-16 23:38 ` Sean Christopherson
2024-08-19 17:34 ` Vipin Sharma
2024-08-19 22:12 ` Sean Christopherson
2024-08-23 22:38 ` Vipin Sharma
2024-08-26 14:34 ` Sean Christopherson
2024-08-26 19:24 ` Vipin Sharma
2024-08-26 19:51 ` Sean Christopherson [this message]
2024-08-19 22:19 ` Sean Christopherson
2024-08-23 19:27 ` Vipin Sharma
2024-08-23 20:45 ` Sean Christopherson
2024-08-23 21:41 ` Vipin Sharma
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=Zszcq2Bzt-mEnAbQ@google.com \
--to=seanjc@google.com \
--cc=dmatlack@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=vipinsh@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