From: Yan Zhao <yan.y.zhao@intel.com>
To: Binbin Wu <binbin.wu@linux.intel.com>
Cc: <pbonzini@redhat.com>, <seanjc@google.com>, <kvm@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <rick.p.edgecombe@intel.com>,
<kai.huang@intel.com>, <adrian.hunter@intel.com>,
<reinette.chatre@intel.com>, <xiaoyao.li@intel.com>,
<tony.lindgren@intel.com>, <dmatlack@google.com>,
<isaku.yamahata@intel.com>, <isaku.yamahata@gmail.com>
Subject: Re: [PATCH 4/7] KVM: TDX: Kick off vCPUs when SEAMCALL is busy during TD page removal
Date: Thu, 16 Jan 2025 16:18:18 +0800 [thread overview]
Message-ID: <Z4jAyhtcSWJY9D/K@yzhao56-desk.sh.intel.com> (raw)
In-Reply-To: <8f350bcc-c819-45cf-a1d5-7d72975912d9@linux.intel.com>
On Thu, Jan 16, 2025 at 02:23:24PM +0800, Binbin Wu wrote:
>
>
>
> On 1/13/2025 10:12 AM, Yan Zhao wrote:
> [...]
> > +
> > /* TDH.PHYMEM.PAGE.RECLAIM is allowed only when destroying the TD. */
> > static int __tdx_reclaim_page(hpa_t pa)
> > {
> > @@ -979,6 +999,14 @@ fastpath_t tdx_vcpu_run(struct kvm_vcpu *vcpu, bool force_immediate_exit)
> > return EXIT_FASTPATH_NONE;
> > }
> > + /*
> > + * Wait until retry of SEPT-zap-related SEAMCALL completes before
> > + * allowing vCPU entry to avoid contention with tdh_vp_enter() and
> > + * TDCALLs.
> > + */
> > + if (unlikely(READ_ONCE(to_kvm_tdx(vcpu->kvm)->wait_for_sept_zap)))
> > + return EXIT_FASTPATH_EXIT_HANDLED;
> > +
> > trace_kvm_entry(vcpu, force_immediate_exit);
> > if (pi_test_on(&tdx->pi_desc)) {
> > @@ -1647,15 +1675,23 @@ static int tdx_sept_drop_private_spte(struct kvm *kvm, gfn_t gfn,
> > if (KVM_BUG_ON(!is_hkid_assigned(kvm_tdx), kvm))
> > return -EINVAL;
> > - do {
> > + /*
> > + * When zapping private page, write lock is held. So no race condition
> > + * with other vcpu sept operation.
> > + * Race with TDH.VP.ENTER due to (0-step mitigation) and Guest TDCALLs.
> > + */
> > + err = tdh_mem_page_remove(kvm_tdx->tdr_pa, gpa, tdx_level, &entry,
> > + &level_state);
> > + if ((err & TDX_OPERAND_BUSY)) {
>
> It is not safe to use "err & TDX_OPERAND_BUSY".
> E.g., if the error is TDX_EPT_WALK_FAILED, "err & TDX_OPERAND_BUSY" will be true.
>
> Maybe you can add a helper to check it.
>
> staticinlinebooltdx_operand_busy(u64err)
> {
> return(err &TDX_SEAMCALL_STATUS_MASK) ==TDX_OPERAND_BUSY;
> }
>
Good catch!
Thanks!
>
> > /*
> > - * When zapping private page, write lock is held. So no race
> > - * condition with other vcpu sept operation. Race only with
> > - * TDH.VP.ENTER.
> > + * The second retry is expected to succeed after kicking off all
> > + * other vCPUs and prevent them from invoking TDH.VP.ENTER.
> > */
> > + tdx_no_vcpus_enter_start(kvm);
> > err = tdh_mem_page_remove(kvm_tdx->tdr_pa, gpa, tdx_level, &entry,
> > &level_state);
> > - } while (unlikely(err == TDX_ERROR_SEPT_BUSY));
> > + tdx_no_vcpus_enter_stop(kvm);
> > + }
> > if (unlikely(kvm_tdx->state != TD_STATE_RUNNABLE &&
> > err == (TDX_EPT_WALK_FAILED | TDX_OPERAND_ID_RCX))) {
> > @@ -1726,8 +1762,12 @@ static int tdx_sept_zap_private_spte(struct kvm *kvm, gfn_t gfn,
> > WARN_ON_ONCE(level != PG_LEVEL_4K);
> > err = tdh_mem_range_block(kvm_tdx->tdr_pa, gpa, tdx_level, &entry, &level_state);
> > - if (unlikely(err == TDX_ERROR_SEPT_BUSY))
> > - return -EAGAIN;
> > + if (unlikely(err & TDX_OPERAND_BUSY)) {
> Ditto.
>
> > + /* After no vCPUs enter, the second retry is expected to succeed */
> > + tdx_no_vcpus_enter_start(kvm);
> > + err = tdh_mem_range_block(kvm_tdx->tdr_pa, gpa, tdx_level, &entry, &level_state);
> > + tdx_no_vcpus_enter_stop(kvm);
> > + }
> > if (KVM_BUG_ON(err, kvm)) {
> > pr_tdx_error_2(TDH_MEM_RANGE_BLOCK, err, entry, level_state);
> > return -EIO;
> > @@ -1770,9 +1810,13 @@ static void tdx_track(struct kvm *kvm)
> > lockdep_assert_held_write(&kvm->mmu_lock);
> > - do {
> > + err = tdh_mem_track(kvm_tdx->tdr_pa);
> > + if ((err & TDX_SEAMCALL_STATUS_MASK) == TDX_OPERAND_BUSY) {
> > + /* After no vCPUs enter, the second retry is expected to succeed */
> > + tdx_no_vcpus_enter_start(kvm);
> > err = tdh_mem_track(kvm_tdx->tdr_pa);
> > - } while (unlikely((err & TDX_SEAMCALL_STATUS_MASK) == TDX_OPERAND_BUSY));
> > + tdx_no_vcpus_enter_stop(kvm);
> > + }
> >
> [...]
next prev parent reply other threads:[~2025-01-16 8:19 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-13 2:09 [PATCH 0/7] KVM: TDX SEPT SEAMCALL retry Yan Zhao
2025-01-13 2:10 ` [PATCH 1/7] KVM: TDX: Return -EBUSY when tdh_mem_page_add() encounters TDX_OPERAND_BUSY Yan Zhao
2025-01-14 22:24 ` Edgecombe, Rick P
2025-01-15 4:59 ` Yan Zhao
2025-01-13 2:11 ` [PATCH 2/7] KVM: x86/mmu: Return RET_PF* instead of 1 in kvm_mmu_page_fault() Yan Zhao
2025-01-14 22:24 ` Edgecombe, Rick P
2025-01-15 4:58 ` Yan Zhao
2025-01-13 2:12 ` [PATCH 3/7] KVM: TDX: Retry locally in TDX EPT violation handler on RET_PF_RETRY Yan Zhao
2025-01-17 21:14 ` Sean Christopherson
2025-01-20 8:05 ` Yan Zhao
2025-01-25 1:23 ` Sean Christopherson
2025-01-27 9:24 ` Yan Zhao
2025-01-27 17:04 ` Sean Christopherson
2025-02-05 7:34 ` Yan Zhao
2025-01-13 2:12 ` [PATCH 4/7] KVM: TDX: Kick off vCPUs when SEAMCALL is busy during TD page removal Yan Zhao
2025-01-16 6:23 ` Binbin Wu
2025-01-16 6:28 ` Binbin Wu
2025-01-16 8:18 ` Yan Zhao [this message]
2025-01-13 2:13 ` [PATCH 5/7] fixup! KVM: TDX: Implement hooks to propagate changes of TDP MMU mirror page table Yan Zhao
2025-01-16 6:30 ` Binbin Wu
2025-01-13 2:13 ` [PATCH 6/7] " Yan Zhao
2025-01-13 2:13 ` [PATCH 7/7] fixup! KVM: TDX: Implement TDX vcpu enter/exit path Yan Zhao
2025-01-14 22:27 ` [PATCH 0/7] KVM: TDX SEPT SEAMCALL retry Edgecombe, Rick P
2025-01-15 16:43 ` Paolo Bonzini
2025-01-16 0:52 ` Yan Zhao
2025-01-16 11:07 ` Paolo Bonzini
2025-01-17 9:52 ` Yan Zhao
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=Z4jAyhtcSWJY9D/K@yzhao56-desk.sh.intel.com \
--to=yan.y.zhao@intel.com \
--cc=adrian.hunter@intel.com \
--cc=binbin.wu@linux.intel.com \
--cc=dmatlack@google.com \
--cc=isaku.yamahata@gmail.com \
--cc=isaku.yamahata@intel.com \
--cc=kai.huang@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=reinette.chatre@intel.com \
--cc=rick.p.edgecombe@intel.com \
--cc=seanjc@google.com \
--cc=tony.lindgren@intel.com \
--cc=xiaoyao.li@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
all inboxes | Powered by JetHome®