git: ae81fb2db3df - stable/14 - iommu: eliminate iommu_free_ctx()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 09 Nov 2024 20:19:20 UTC
The branch stable/14 has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=ae81fb2db3df71e96fc154c72a1327dd3675f1a6
commit ae81fb2db3df71e96fc154c72a1327dd3675f1a6
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-11-03 14:50:01 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-11-09 19:31:28 +0000
iommu: eliminate iommu_free_ctx()
iommu_free_ctx_locked() alone is enough
Sponsored by: Advanced Micro Devices (AMD)
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
(cherry picked from commit d97838b7c2a605932b6edf36f87abe7ccce74314)
---
sys/arm64/iommu/iommu.c | 19 +++----------------
sys/dev/iommu/busdma_iommu.c | 10 ++++++++--
sys/x86/iommu/amd_ctx.c | 19 -------------------
sys/x86/iommu/amd_drv.c | 1 -
sys/x86/iommu/amd_iommu.h | 1 -
sys/x86/iommu/intel_ctx.c | 19 -------------------
sys/x86/iommu/intel_dmar.h | 1 -
sys/x86/iommu/intel_drv.c | 1 -
sys/x86/iommu/iommu_utils.c | 6 ------
sys/x86/iommu/x86_iommu.h | 1 -
10 files changed, 11 insertions(+), 67 deletions(-)
diff --git a/sys/arm64/iommu/iommu.c b/sys/arm64/iommu/iommu.c
index eb682a4a623f..afb5c7c5e152 100644
--- a/sys/arm64/iommu/iommu.c
+++ b/sys/arm64/iommu/iommu.c
@@ -375,32 +375,19 @@ void
iommu_free_ctx_locked(struct iommu_unit *iommu, struct iommu_ctx *ioctx)
{
struct bus_dma_tag_iommu *tag;
+ int error;
IOMMU_ASSERT_LOCKED(iommu);
tag = ioctx->tag;
IOMMU_CTX_FREE(iommu->dev, ioctx);
+ IOMMU_UNLOCK(iommu);
free(tag, M_IOMMU);
-}
-
-void
-iommu_free_ctx(struct iommu_ctx *ioctx)
-{
- struct iommu_unit *iommu;
- struct iommu_domain *iodom;
- int error;
-
- iodom = ioctx->domain;
- iommu = iodom->iommu;
-
- IOMMU_LOCK(iommu);
- iommu_free_ctx_locked(iommu, ioctx);
- IOMMU_UNLOCK(iommu);
/* Since we have a domain per each ctx, remove the domain too. */
- error = iommu_domain_free(iodom);
+ error = iommu_domain_free(ioctx->domain);
if (error)
device_printf(iommu->dev, "Could not free a domain\n");
}
diff --git a/sys/dev/iommu/busdma_iommu.c b/sys/dev/iommu/busdma_iommu.c
index dbd4ee0ef0f1..8c97965bcdf1 100644
--- a/sys/dev/iommu/busdma_iommu.c
+++ b/sys/dev/iommu/busdma_iommu.c
@@ -400,6 +400,8 @@ iommu_bus_dma_tag_destroy(bus_dma_tag_t dmat1)
{
struct bus_dma_tag_iommu *dmat, *parent;
struct bus_dma_tag_iommu *dmat_copy __unused;
+ struct iommu_unit *iommu;
+ struct iommu_ctx *ctx;
int error;
error = 0;
@@ -414,8 +416,12 @@ iommu_bus_dma_tag_destroy(bus_dma_tag_t dmat1)
parent = (struct bus_dma_tag_iommu *)dmat->common.parent;
if (atomic_fetchadd_int(&dmat->common.ref_count, -1) ==
1) {
- if (dmat == dmat->ctx->tag)
- iommu_free_ctx(dmat->ctx);
+ ctx = dmat->ctx;
+ if (dmat == ctx->tag) {
+ iommu = ctx->domain->iommu;
+ IOMMU_LOCK(iommu);
+ iommu_free_ctx_locked(iommu, dmat->ctx);
+ }
free(dmat->segments, M_IOMMU_DMAMAP);
free(dmat, M_DEVBUF);
dmat = parent;
diff --git a/sys/x86/iommu/amd_ctx.c b/sys/x86/iommu/amd_ctx.c
index 81e284373fc8..7f0e67f37eef 100644
--- a/sys/x86/iommu/amd_ctx.c
+++ b/sys/x86/iommu/amd_ctx.c
@@ -398,16 +398,6 @@ amdiommu_free_ctx_locked(struct amdiommu_unit *unit, struct amdiommu_ctx *ctx)
amdiommu_unref_domain_locked(unit, domain);
}
-static void
-amdiommu_free_ctx(struct amdiommu_ctx *ctx)
-{
- struct amdiommu_unit *unit;
-
- unit = CTX2AMD(ctx);
- AMDIOMMU_LOCK(unit);
- amdiommu_free_ctx_locked(unit, ctx);
-}
-
static void
amdiommu_unref_domain_locked(struct amdiommu_unit *unit,
struct amdiommu_domain *domain)
@@ -628,12 +618,3 @@ amdiommu_free_ctx_locked_method(struct iommu_unit *iommu,
ctx = IOCTX2CTX(context);
amdiommu_free_ctx_locked(unit, ctx);
}
-
-void
-amdiommu_free_ctx_method(struct iommu_ctx *context)
-{
- struct amdiommu_ctx *ctx;
-
- ctx = IOCTX2CTX(context);
- amdiommu_free_ctx(ctx);
-}
diff --git a/sys/x86/iommu/amd_drv.c b/sys/x86/iommu/amd_drv.c
index 513463f21292..2c544dfb60a6 100644
--- a/sys/x86/iommu/amd_drv.c
+++ b/sys/x86/iommu/amd_drv.c
@@ -1072,7 +1072,6 @@ static struct x86_iommu amd_x86_iommu = {
.domain_unload = amdiommu_domain_unload,
.get_ctx = amdiommu_get_ctx,
.free_ctx_locked = amdiommu_free_ctx_locked_method,
- .free_ctx = amdiommu_free_ctx_method,
.alloc_msi_intr = amdiommu_alloc_msi_intr,
.map_msi_intr = amdiommu_map_msi_intr,
.unmap_msi_intr = amdiommu_unmap_msi_intr,
diff --git a/sys/x86/iommu/amd_iommu.h b/sys/x86/iommu/amd_iommu.h
index 2b0db4f8fe6d..64dd13db9745 100644
--- a/sys/x86/iommu/amd_iommu.h
+++ b/sys/x86/iommu/amd_iommu.h
@@ -222,7 +222,6 @@ struct amdiommu_ctx *amdiommu_find_ctx_locked(struct amdiommu_unit *unit,
uint16_t rid);
void amdiommu_free_ctx_locked_method(struct iommu_unit *iommu,
struct iommu_ctx *context);
-void amdiommu_free_ctx_method(struct iommu_ctx *context);
struct amdiommu_domain *amdiommu_find_domain(struct amdiommu_unit *unit,
uint16_t rid);
diff --git a/sys/x86/iommu/intel_ctx.c b/sys/x86/iommu/intel_ctx.c
index c7c7012e94ea..ae74d0456b25 100644
--- a/sys/x86/iommu/intel_ctx.c
+++ b/sys/x86/iommu/intel_ctx.c
@@ -804,16 +804,6 @@ dmar_free_ctx_locked(struct dmar_unit *dmar, struct dmar_ctx *ctx)
TD_PINNED_ASSERT;
}
-static void
-dmar_free_ctx(struct dmar_ctx *ctx)
-{
- struct dmar_unit *dmar;
-
- dmar = CTX2DMAR(ctx);
- DMAR_LOCK(dmar);
- dmar_free_ctx_locked(dmar, ctx);
-}
-
/*
* Returns with the domain locked.
*/
@@ -942,12 +932,3 @@ dmar_free_ctx_locked_method(struct iommu_unit *iommu,
ctx = IOCTX2CTX(context);
dmar_free_ctx_locked(dmar, ctx);
}
-
-void
-dmar_free_ctx_method(struct iommu_ctx *context)
-{
- struct dmar_ctx *ctx;
-
- ctx = IOCTX2CTX(context);
- dmar_free_ctx(ctx);
-}
diff --git a/sys/x86/iommu/intel_dmar.h b/sys/x86/iommu/intel_dmar.h
index 1a9b5041975c..57a66aae69b2 100644
--- a/sys/x86/iommu/intel_dmar.h
+++ b/sys/x86/iommu/intel_dmar.h
@@ -237,7 +237,6 @@ struct dmar_ctx *dmar_get_ctx_for_devpath(struct dmar_unit *dmar, uint16_t rid,
int dmar_move_ctx_to_domain(struct dmar_domain *domain, struct dmar_ctx *ctx);
void dmar_free_ctx_locked_method(struct iommu_unit *dmar,
struct iommu_ctx *ctx);
-void dmar_free_ctx_method(struct iommu_ctx *ctx);
struct dmar_ctx *dmar_find_ctx_locked(struct dmar_unit *dmar, uint16_t rid);
struct iommu_ctx *dmar_get_ctx(struct iommu_unit *iommu, device_t dev,
uint16_t rid, bool id_mapped, bool rmrr_init);
diff --git a/sys/x86/iommu/intel_drv.c b/sys/x86/iommu/intel_drv.c
index 22d04029f9ae..b21c8460e830 100644
--- a/sys/x86/iommu/intel_drv.c
+++ b/sys/x86/iommu/intel_drv.c
@@ -1317,7 +1317,6 @@ static struct x86_iommu dmar_x86_iommu = {
.domain_unload = dmar_domain_unload,
.get_ctx = dmar_get_ctx,
.free_ctx_locked = dmar_free_ctx_locked_method,
- .free_ctx = dmar_free_ctx_method,
.find = dmar_find_method,
.alloc_msi_intr = dmar_alloc_msi_intr,
.map_msi_intr = dmar_map_msi_intr,
diff --git a/sys/x86/iommu/iommu_utils.c b/sys/x86/iommu/iommu_utils.c
index 479e8637ee8e..2db02a98ca91 100644
--- a/sys/x86/iommu/iommu_utils.c
+++ b/sys/x86/iommu/iommu_utils.c
@@ -288,12 +288,6 @@ iommu_free_ctx_locked(struct iommu_unit *iommu, struct iommu_ctx *context)
x86_iommu->free_ctx_locked(iommu, context);
}
-void
-iommu_free_ctx(struct iommu_ctx *context)
-{
- x86_iommu->free_ctx(context);
-}
-
struct iommu_unit *
iommu_find(device_t dev, bool verbose)
{
diff --git a/sys/x86/iommu/x86_iommu.h b/sys/x86/iommu/x86_iommu.h
index 835a4623a95e..1c9ad6529d47 100644
--- a/sys/x86/iommu/x86_iommu.h
+++ b/sys/x86/iommu/x86_iommu.h
@@ -81,7 +81,6 @@ struct x86_iommu {
device_t dev, uint16_t rid, bool id_mapped, bool rmrr_init);
void (*free_ctx_locked)(struct iommu_unit *iommu,
struct iommu_ctx *context);
- void (*free_ctx)(struct iommu_ctx *context);
struct iommu_unit *(*find)(device_t dev, bool verbose);
int (*alloc_msi_intr)(device_t src, u_int *cookies, u_int count);
int (*map_msi_intr)(device_t src, u_int cpu, u_int vector,