amd/iommu: Cleanup and fixes
Subsystems (2)
Vasant Hegde
maintainercover amd/iommu: Cleanup and fixes
This series contains few fixes like better handling of error path, fixing sparse warning and trivial cleanup like removing outdated, etc.
Vasant Hegde (5):
iommu/amd: Free domain id in error path iommu/amd: Protect domain update with domain_lock iommu/amd: Free domain ID after domain_flush_pages iommu/amd: Remove outdated comment iommu/amd: Fix sparse warning
drivers/iommu/amd/amd_iommu_types.h | 2 ++ drivers/iommu/amd/init.c | 2 -- drivers/iommu/amd/iommu.c | 22 ++++++++++++++-------- 3 files changed, 16 insertions(+), 10 deletions(-)
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH 1/5 iommu/amd: Free domain id in error path
Call domain_id_free() in error path.
--- drivers/iommu/amd/iommu.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/iommu/amd/iommu.c +6 -2
@@ -2027,8 +2027,10 @@ static int protection_domain_init_v1(struct protection_domain *domain, int mode)if (mode !=PAGE_MODE_NONE ) { pt_root = (void *)get_zeroed_page (GFP_KERNEL ); -if (!pt_root) +if (!pt_root) { +domain_id_free (domain->id);return -ENOMEM ; + } }amd_iommu_domain_set_pgtable (domain, pt_root, mode);
@@ -2092,8 +2094,10 @@ static struct protection_domain *protection_domain_alloc(unsigned int type) goto out_err; pgtbl_ops =alloc_io_pgtable_ops (pgtable, &domain->iop.pgtbl_cfg, domain); -if (!pgtbl_ops) +if (!pgtbl_ops) { +domain_id_free (domain->id); goto out_err; + }return domain; out_err:
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH 2/5 iommu/amd: Protect domain update with domain_lock
In reply to Vasant HegdeIn protection_domain_free() path it calls amd_iommu_domain_update() to update IOMMU.
protection_domain_free -> free_io_pgtable_ops ->
v1_free_pgtable -> amd_iommu_domain_update
Make sure its protected using domain->lock.
--- drivers/iommu/amd/iommu.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/iommu/amd/iommu.c +6 -0
@@ -2001,15 +2001,21 @@ static void cleanup_domain(struct protection_domain *domain)static void protection_domain_free (struct protection_domain *domain) { +unsigned long flags; +if (!domain)return ;if (domain->id)domain_id_free (domain->id); +spin_lock_irqsave (&domain->lock, flags); +if (domain->iop.pgtbl_cfg.tlb)free_io_pgtable_ops (&domain->iop.iop.ops); +spin_unlock_irqrestore (&domain->lock, flags); +kfree (domain); }
Signature · 1 line
2.31.1
Joerg Roedel
maintainerRe: [PATCH 2/5] iommu/amd: Protect domain update with domain_lock
Hi Vasant,
Quoted 6 lines · Vasant Hegde
In
protection_domain_free()path it callsamd_iommu_domain_update()to update IOMMU.
protection_domain_free->free_io_pgtable_ops->v1_free_pgtable -> amd_iommu_domain_updateMake sure its protected using
domain->lock.
A concurrent access to the domain at this point would be a bug in itself, and the locking wouldn't help here either because the domain including the lock is freed right after release.
Do you see and concurrent accesses to the domain at this point?
Regards,
Joerg
Vasant Hegde
maintainerRe: [PATCH 2/5] iommu/amd: Protect domain update with domain_lock
Hello Joerg,
Quoted 8 lines · Joerg Roedel
Hi Vasant,
Quoted 5 lines · Vasant Hegde
In
protection_domain_free()path it callsamd_iommu_domain_update()to update IOMMU.
protection_domain_free->free_io_pgtable_ops->v1_free_pgtable -> amd_iommu_domain_update
Quoted 7 lines
Quoted 1 line
Make sure its protected using
domain->lock.A concurrent access to the domain at this point would be a bug in itself, and the locking wouldn't help here either because the domain including the lock is freed right after release.
Do you see and concurrent accesses to the domain at this point?
I didn't see any concurrent access. I was going through code and thought lock is required here.
What you said is makes sense. We can drop this patch.
-Vasant
Vasant Hegde
maintainerPATCH 3/5 iommu/amd: Free domain ID after domain_flush_pages
In reply to Vasant Hegdefree_io_pgtable_ops() path uses domain ID to flush pages. Hence free domain ID after flushing everything.
--- drivers/iommu/amd/iommu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iommu/amd/iommu.c +3 -3
@@ -2006,9 +2006,6 @@ static void protection_domain_free(struct protection_domain *domain)if (!domain)return ; -if (domain->id) -domain_id_free (domain->id); -spin_lock_irqsave (&domain->lock, flags);if (domain->iop.pgtbl_cfg.tlb)
@@ -2016,6 +2013,9 @@ static void protection_domain_free(struct protection_domain *domain)spin_unlock_irqrestore (&domain->lock, flags); +if (domain->id) +domain_id_free (domain->id); +kfree (domain); }
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH 4/5 iommu/amd: Remove outdated comment
In reply to Vasant HegdeComment is not related to amd_iommu_ops variable.
--- drivers/iommu/amd/iommu.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/iommu/amd/iommu.c +0 -4
@@ -66,10 +66,6 @@ LIST_HEAD(ioapic_map);LIST_HEAD (hpet_map);LIST_HEAD (acpihid_map); -/* -* Domain for untranslated devices - only allocated -* if iommu=pt passed on kernel cmd line. -*/ const struct iommu_ops amd_iommu_ops;static ATOMIC_NOTIFIER_HEAD (ppr_notifier);
Signature · 1 line
2.31.1
Vasant Hegde
maintainerPATCH 5/5 iommu/amd: Fix sparse warning
In reply to Vasant HegdeCHECK drivers/iommu/amd/iommu.cdrivers/iommu/amd/iommu.c:73:24: warning: symbol 'amd_iommu_ops' was not declared. Should it be static?
--- drivers/iommu/amd/amd_iommu_types.h | 2 ++ drivers/iommu/amd/init.c | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/amd/amd_iommu_types.h +2 -0
@@ -461,6 +461,8 @@ struct irq_remap_table {/* Interrupt remapping feature used? */ extern bool amd_iommu_irq_remap; +extern const struct iommu_ops amd_iommu_ops; +/* IVRS indicates that pre-boot remapping was enabled */ extern bool amdr_ivrs_remap_support;
drivers/iommu/amd/init.c +0 -2
@@ -95,8 +95,6 @@* out of it. */ -extern const struct iommu_ops amd_iommu_ops; -/* * structure describing one IOMMU in the ACPI table. Typically followed by one * or more ivhd_entrys.
Signature · 1 line
2.31.1
Quoted 9 lines · Vasant Hegde
This series contains few fixes like better handling of error path, fixing sparse warning and trivial cleanup like removing outdated, etc.
Vasant Hegde (5):
iommu/amd: Free domain id in error path iommu/amd: Protect domain update withdomain_lockiommu/amd: Free domain ID afterdomain_flush_pagesiommu/amd: Remove outdated comment iommu/amd: Fix sparse warning
Applied patch 1 and 3-5, thanks Vasant.