The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Narayana Murty N <nnmlinux@linux.ibm.com>
To: Ritesh Harjani <ritesh.list@gmail.com>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org
Cc: Nicholas Piggin <npiggin@gmail.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Christophe Leroy <chleroy@kernel.org>,
	Shrikanth Hegde <sshegde@linux.ibm.com>,
	Alexey Kardashevskiy <aik@ozlabs.ru>,
	Narayana Murty N <nnmlinux@linux.ibm.com>,
	linux-kernel@vger.kernel.org, sbhat@linux.ibm.com,
	harshpb@linux.ibm.com
Subject: [PATCH v2 2/3] KVM: PPC: Book3S: Synchronize TCE hcalls with IOMMU table detach
Date: Thu, 26 Nov 2026 14:20:10 +0530	[thread overview]
Message-ID: <20261126085008.34532-5-nnmlinux@linux.ibm.com> (raw)
In-Reply-To: <20261126085008.34532-4-nnmlinux@linux.ibm.com>

TCE hypercalls traverse stt->iommu_tables while VFIO detach may
remove attachments and return hardware window ownership before
in-flight TCE updates complete.

Use the existing kvm->srcu read-side protection for IOMMU table
traversal and synchronize SRCU readers during detach.

This ensures that TCE hardware updates complete before the
detached window is returned to VFIO.

The following patch addresses safe reclamation of child entries
accessed by these SRCU readers.

Signed-off-by: Narayana Murty N <nnmlinux@linux.ibm.com>
---
 arch/powerpc/kvm/book3s_64_vio.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_64_vio.c b/arch/powerpc/kvm/book3s_64_vio.c
index e9370b0e9afe..afa7ce57f5ae 100644
--- a/arch/powerpc/kvm/book3s_64_vio.c
+++ b/arch/powerpc/kvm/book3s_64_vio.c
@@ -112,6 +112,13 @@ void kvm_spapr_tce_release_iommu_group(struct kvm *kvm,
 		cond_resched_rcu();
 	}
 	rcu_read_unlock();
+
+	/*
+	 * Wait for hcalls that may still be programming the detached
+	 * window. They run under kvm->srcu, so once this returns, no
+	 * TCE update can touch the hardware after ownership is released.
+	 */
+	synchronize_srcu(&kvm->srcu);
 }
 
 long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
@@ -634,7 +641,8 @@ long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
 
 	entry = ioba >> stt->page_shift;
 
-	list_for_each_entry_lockless(stit, &stt->iommu_tables, next) {
+	list_for_each_entry_srcu(stit, &stt->iommu_tables, next,
+				 srcu_read_lock_held(&vcpu->kvm->srcu)) {
 		if (dir == DMA_NONE)
 			ret = kvmppc_tce_iommu_unmap(vcpu->kvm, stt,
 					stit->tbl, entry);
@@ -738,7 +746,8 @@ long kvmppc_h_put_tce_indirect(struct kvm_vcpu *vcpu,
 			goto put_exit;
 		}
 
-		list_for_each_entry_lockless(stit, &stt->iommu_tables, next) {
+		list_for_each_entry_srcu(stit, &stt->iommu_tables, next,
+					 srcu_read_lock_held(&vcpu->kvm->srcu)) {
 			ret = kvmppc_tce_iommu_map(vcpu->kvm, stt,
 					stit->tbl, entry + i, ua,
 					iommu_tce_direction(tce));
@@ -788,7 +797,8 @@ long kvmppc_h_stuff_tce(struct kvm_vcpu *vcpu,
 		goto put_exit;
 	}
 
-	list_for_each_entry_lockless(stit, &stt->iommu_tables, next) {
+	list_for_each_entry_srcu(stit, &stt->iommu_tables, next,
+				 srcu_read_lock_held(&vcpu->kvm->srcu)) {
 		unsigned long entry = ioba >> stt->page_shift;
 
 		for (i = 0; i < npages; ++i) {
-- 
2.54.0


  reply	other threads:[~2026-11-26  8:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  8:43 [PATCH v2 0/3] KVM: PPC: Book3S: Protect TCE IOMMU table walks with RCU Narayana Murty N
2026-11-26  8:50 ` [PATCH v2 1/3] KVM: PPC: Book3S: Hold a reference to sPAPR TCE tables during hcalls Narayana Murty N
2026-11-26  8:50   ` Narayana Murty N [this message]
2026-11-26  8:50   ` [PATCH v2 3/3] KVM: PPC: Book3S: Free child IOMMU tables after an SRCU grace period Narayana Murty N

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=20261126085008.34532-5-nnmlinux@linux.ibm.com \
    --to=nnmlinux@linux.ibm.com \
    --cc=aik@ozlabs.ru \
    --cc=chleroy@kernel.org \
    --cc=harshpb@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=ritesh.list@gmail.com \
    --cc=sbhat@linux.ibm.com \
    --cc=sshegde@linux.ibm.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