[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250928190624.3735830-3-skhawaja@google.com>
Date: Sun, 28 Sep 2025 19:06:10 +0000
From: Samiullah Khawaja <skhawaja@...gle.com>
To: David Woodhouse <dwmw2@...radead.org>, Lu Baolu <baolu.lu@...ux.intel.com>,
Joerg Roedel <joro@...tes.org>, Will Deacon <will@...nel.org>,
Pasha Tatashin <pasha.tatashin@...een.com>, Jason Gunthorpe <jgg@...pe.ca>, iommu@...ts.linux.dev
Cc: Samiullah Khawaja <skhawaja@...gle.com>, Robin Murphy <robin.murphy@....com>,
Pratyush Yadav <pratyush@...nel.org>, Kevin Tian <kevin.tian@...el.com>, linux-kernel@...r.kernel.org,
Saeed Mahameed <saeedm@...dia.com>, Adithya Jayachandran <ajayachandra@...dia.com>,
Parav Pandit <parav@...dia.com>, Leon Romanovsky <leonro@...dia.com>, William Tu <witu@...dia.com>,
Vipin Sharma <vipinsh@...gle.com>, dmatlack@...gle.com, zhuyifei@...gle.com,
Chris Li <chrisl@...nel.org>, praan@...gle.com
Subject: [RFC PATCH 02/15] iommu: Add rw_semaphore to serialize live update state
Introduce a rw_semaphore to protect the IOMMU live update state.
When a live update operation (prepare, cancel, etc.) is in progress, the
underlying state of the IOMMU subsystem (e.g., the set of active
hardware units, the state of preserved domains) must not be changed by
concurrent events.
This semaphore acts as a subsystem-wide lock to serialize the LUO
callbacks against any other code path that might modify this state,
such as IOMMU hardware hotplug.
The LUO callbacks take a write lock, as they modify the live update
state. Other code paths should take a read lock to check if a live
update is in progress.
Signed-off-by: Samiullah Khawaja <skhawaja@...gle.com>
---
drivers/iommu/iommu.c | 4 ++++
include/linux/iommu.h | 9 +++++++++
2 files changed, 13 insertions(+)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 060ebe330ee1..bfa7c8653720 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2052,6 +2052,10 @@ struct iommu_domain *iommu_paging_domain_alloc_flags(struct device *dev,
}
EXPORT_SYMBOL_GPL(iommu_paging_domain_alloc_flags);
+#ifdef CONFIG_LIVEUPDATE
+DECLARE_RWSEM(liveupdate_state_rwsem);
+#endif
+
void iommu_domain_free(struct iommu_domain *domain)
{
switch (domain->cookie_type) {
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index c30d12e16473..d23d078f7c18 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -598,6 +598,15 @@ __iommu_copy_struct_to_user(const struct iommu_user_data *dst_data,
__iommu_copy_struct_to_user(user_data, ksrc, data_type, sizeof(*ksrc), \
offsetofend(typeof(*ksrc), min_last))
+#ifdef CONFIG_LIVEUPDATE
+extern struct rw_semaphore liveupdate_state_rwsem;
+#define guard_liveupdate_state_read() guard(rwsem_read)(&liveupdate_state_rwsem)
+#define guard_liveupdate_state_write() guard(rwsem_write)(&liveupdate_state_rwsem)
+#else
+#define guard_liveupdate_state_read()
+#define guard_liveupdate_state_write()
+#endif /* CONFIG_LIVEUPDATE */
+
/**
* struct iommu_ops - iommu ops and capabilities
* @capable: check capability
--
2.51.0.536.g15c5d4f767-goog
Powered by blists - more mailing lists