From: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
To: "Zhao, Yan Y" <yan.y.zhao@intel.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"Annapurve, Vishal" <vannapurve@google.com>,
"seanjc@google.com" <seanjc@google.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"michael.roth@amd.com" <michael.roth@amd.com>,
"Weiny, Ira" <ira.weiny@intel.com>
Subject: Re: [RFC PATCH 09/12] KVM: TDX: Fold tdx_mem_page_record_premap_cnt() into its sole caller
Date: Thu, 28 Aug 2025 19:08:29 +0000 [thread overview]
Message-ID: <8e5cd292a95cb449e22f63661c54dbb86932159c.camel@intel.com> (raw)
In-Reply-To: <aK/vfyw5lyIZgdH7@yzhao56-desk.sh.intel.com>
On Thu, 2025-08-28 at 13:56 +0800, Yan Zhao wrote:
> > Reasons that tdh_mem_page_add() could get BUSY:
> > 1. If two vCPU's tried to tdh_mem_page_add() the same gpa at the same time
> > they
> > could contend the SEPT entry lock
> > 2. If one vCPU tries to tdh_mem_page_add() while the other zaps (i.e.
> > tdh_mem_range_block()).
> Hmm, two tdh_mem_page_add()s can't contend as they are protected by both
> slot_lock and filemap lock.
>
> With regard to the contention to tdh_mem_range_block(), please check my
> analysis at the above [1].
The analysis missed the tdh_mem_page_add() failure path
>
> tdh_mem_page_add() could get BUSY though, when a misbehaved userspace invokes
> KVM_TDX_INIT_MEM_REGION on one vCPU while initializing another vCPU.
>
> Please check more details at [2].
>
> [2] https://lore.kernel.org/kvm/20250113021050.18828-1-yan.y.zhao@intel.com/
Ah, the TDR lock. I actually referred to an older version of your locking
analysis that didn't have that one. But this means the premap count could get
out of sync for that reason too.
>
>
> > I guess since we don't hold MMU lock while we tdh_mem_page_add(), 2 is a
> > possibility.
> 2 is possible only for paranoid zaps.
> See "case 3. Unexpected zaps" in [1].
Sean's lockdep assert handles half of those cases. Maybe we could also re-
consider a KVM_BUG_ON() in the invalid zap paths again if it comes to it.
>
>
> > > What reasonable use case is there for gracefully handling
> > > tdh_mem_page_add()
> > > failure?
> > >
> > > If there is a need to handle failure, I gotta imagine it's only for the -
> > > EBUSY
> > > case. And if it's only for -EBUSY, why can't that be handled by retrying
> > > in
> > > tdx_vcpu_init_mem_region()? If tdx_vcpu_init_mem_region() guarantees that
> > > all
> > > pages mapped into the S-EPT are ADDed, then it can assert that there are
> > > no
> > > pending pages when it completes (even if it "fails"), and similarly
> > > tdx_td_finalize() can KVM_BUG_ON/WARN_ON the number of pending pages being
> > > non-zero.
> >
> > Maybe we could take mmu write lock for the retry of tdh_mem_page_add(). Or
> > maybe
> > even for a single call of it, until someone wants to parallelize the
> > operation.
> Hmm. I prefer returning -BUSY directly as invoking KVM_TDX_INIT_MEM_REGION
> before finishing initializing all vCPUs are uncommon.
I was looking guaranteeing its success when Sean posted his suggestion to return
to the original pattern. I'm in favor of that direction. If you agree we can
call this moot.
next prev parent reply other threads:[~2025-08-28 19:08 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-27 0:05 [RFC PATCH 00/12] KVM: x86/mmu: TDX post-populate cleanups Sean Christopherson
2025-08-27 0:05 ` [RFC PATCH 01/12] KVM: TDX: Drop PROVE_MMU=y sanity check on to-be-populated mappings Sean Christopherson
2025-08-27 8:14 ` Yan Zhao
2025-08-28 0:37 ` Ira Weiny
2025-08-28 2:13 ` Huang, Kai
2025-08-27 0:05 ` [RFC PATCH 02/12] KVM: x86/mmu: Add dedicated API to map guest_memfd pfn into TDP MMU Sean Christopherson
2025-08-27 8:25 ` Yan Zhao
2025-08-28 0:54 ` Edgecombe, Rick P
2025-08-28 1:26 ` Edgecombe, Rick P
2025-08-28 6:23 ` Yan Zhao
2025-08-28 19:40 ` Sean Christopherson
2025-08-29 1:16 ` Yan Zhao
2025-09-01 0:39 ` Yan Zhao
2025-08-28 6:55 ` Yan Zhao
2025-08-28 0:40 ` Ira Weiny
2025-08-28 1:51 ` Edgecombe, Rick P
2025-08-28 19:57 ` Sean Christopherson
2025-08-27 0:05 ` [RFC PATCH 03/12] Revert "KVM: x86/tdp_mmu: Add a helper function to walk down the TDP MMU" Sean Christopherson
2025-08-27 0:05 ` [RFC PATCH 04/12] KVM: x86/mmu: Rename kvm_tdp_map_page() to kvm_tdp_prefault_page() Sean Christopherson
2025-08-28 2:01 ` Edgecombe, Rick P
2025-08-28 18:50 ` Sean Christopherson
2025-08-28 19:04 ` Edgecombe, Rick P
2025-08-27 0:05 ` [RFC PATCH 05/12] KVM: TDX: Drop superfluous page pinning in S-EPT management Sean Christopherson
2025-08-27 8:33 ` Yan Zhao
2025-08-28 2:05 ` Edgecombe, Rick P
2025-08-28 20:16 ` Sean Christopherson
2025-08-28 0:36 ` Ira Weiny
2025-08-28 7:08 ` Yan Zhao
2025-08-28 15:54 ` Ira Weiny
2025-08-28 2:45 ` Huang, Kai
2025-08-27 0:05 ` [RFC PATCH 06/12] KVM: TDX: Return -EIO, not -EINVAL, on a KVM_BUG_ON() condition Sean Christopherson
2025-08-27 8:39 ` Yan Zhao
2025-08-27 17:26 ` Sean Christopherson
2025-08-28 2:11 ` Edgecombe, Rick P
2025-08-28 19:21 ` Sean Christopherson
2025-08-28 20:13 ` Edgecombe, Rick P
2025-08-28 21:00 ` Sean Christopherson
2025-08-28 21:19 ` Edgecombe, Rick P
2025-08-28 21:34 ` Sean Christopherson
2025-08-28 15:03 ` Ira Weiny
2025-08-27 0:05 ` [RFC PATCH 07/12] KVM: TDX: Avoid a double-KVM_BUG_ON() in tdx_sept_zap_private_spte() Sean Christopherson
2025-08-28 2:19 ` Edgecombe, Rick P
2025-08-28 14:50 ` Edgecombe, Rick P
2025-08-29 1:10 ` Yan Zhao
2025-08-28 15:02 ` Ira Weiny
2025-08-27 0:05 ` [RFC PATCH 08/12] KVM: TDX: Use atomic64_dec_return() instead of a poor equivalent Sean Christopherson
2025-08-28 2:56 ` Edgecombe, Rick P
2025-08-28 6:48 ` Yan Zhao
2025-08-28 19:14 ` Edgecombe, Rick P
2025-08-28 22:33 ` Sean Christopherson
2025-08-28 23:18 ` Edgecombe, Rick P
2025-08-28 15:03 ` Ira Weiny
2025-08-27 0:05 ` [RFC PATCH 09/12] KVM: TDX: Fold tdx_mem_page_record_premap_cnt() into its sole caller Sean Christopherson
2025-08-27 9:02 ` Yan Zhao
2025-08-27 19:08 ` Sean Christopherson
2025-08-28 3:13 ` Edgecombe, Rick P
2025-08-28 5:56 ` Yan Zhao
2025-08-28 19:08 ` Edgecombe, Rick P [this message]
2025-08-28 5:43 ` Yan Zhao
2025-08-28 17:00 ` Sean Christopherson
2025-08-28 18:52 ` Edgecombe, Rick P
2025-08-28 20:26 ` Sean Christopherson
2025-08-28 21:33 ` Edgecombe, Rick P
2025-08-28 21:57 ` Sean Christopherson
2025-08-28 23:17 ` Edgecombe, Rick P
2025-08-29 6:08 ` Yan Zhao
2025-08-28 22:06 ` Ira Weiny
2025-08-28 23:17 ` Sean Christopherson
2025-08-29 0:35 ` Ira Weiny
2025-08-29 6:06 ` Yan Zhao
2025-08-28 21:44 ` Sean Christopherson
2025-08-29 2:42 ` Binbin Wu
2025-08-29 2:31 ` Yan Zhao
2025-08-29 6:33 ` Yan Zhao
2025-08-28 15:30 ` Ira Weiny
2025-08-28 15:28 ` Ira Weiny
2025-08-27 0:05 ` [RFC PATCH 10/12] KVM: TDX: Assert that slots_lock is held when nr_premapped is accessed Sean Christopherson
2025-08-27 0:05 ` [RFC PATCH 11/12] KVM: TDX: Track nr_premapped as an "unsigned long", not an "atomic64_t" Sean Christopherson
2025-08-27 9:12 ` Yan Zhao
2025-08-27 0:05 ` [RFC PATCH 12/12] KVM: TDX: Rename nr_premapped to nr_pending_tdh_mem_page_adds Sean Christopherson
2025-08-27 9:22 ` Yan Zhao
2025-08-28 15:23 ` Ira Weiny
2025-08-27 9:48 ` [RFC PATCH 00/12] KVM: x86/mmu: TDX post-populate cleanups Yan Zhao
2025-08-28 19:01 ` Edgecombe, Rick P
2025-08-28 23:19 ` 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=8e5cd292a95cb449e22f63661c54dbb86932159c.camel@intel.com \
--to=rick.p.edgecombe@intel.com \
--cc=ira.weiny@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=vannapurve@google.com \
--cc=yan.y.zhao@intel.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;
as well as URLs for NNTP newsgroup(s).