trivial cleanup for iommu/vt-d
cover trivial cleanup for iommu/vt-d
Some cleanup patches for iommu/vt-d.
Yijing Wang (6):
iommu/vt-d: Use list_for_each_safe() to simplify code iommu/vt-d: move up no_iommu and dmar_disabled check iommu/vt-d: clear the redundant assignment in dmar_enable_qi iommu/vt-d: clear the redundant assignment for domain->nid iommu/vt-d: use inline function dma_pte_superpage instead of macros iommu/vt-d: fix reference count in iommu_prepare_isa
drivers/iommu/dmar.c | 3 --- drivers/iommu/intel-iommu.c | 18 ++++++++---------- 2 files changed, 8 insertions(+), 13 deletions(-)
PATCH 1/6 iommu/vt-d: Use list_for_each_safe() to simplify code
Use list_for_each_entry_safe() instead of list_entry() to simplify code.
--- drivers/iommu/intel-iommu.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/iommu/intel-iommu.c +2 -4
@@ -2101,13 +2101,11 @@ static inline void unlink_domain_info(struct device_domain_info *info)static void domain_remove_dev_info (struct dmar_domain *domain) { -struct device_domain_info *info; +struct device_domain_info *info, *tmp;unsigned long flags, flags2;spin_lock_irqsave (&device_domain_lock, flags); -while (!list_empty (&domain->devices)) { - info =list_entry (domain->devices.next, - struct device_domain_info, link); +list_for_each_entry_safe (info, tmp, &domain->devices, link) {unlink_domain_info (info);spin_unlock_irqrestore (&device_domain_lock, flags);
Signature · 1 line
1.7.1
PATCH 2/6 iommu/vt-d: move up no_iommu and dmar_disabled check
In reply to Yijing WangMove up the no_iommu and dmar_disabled check, avoid the useless initialization for dmar.
--- drivers/iommu/intel-iommu.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/iommu/intel-iommu.c +3 -3
@@ -3948,6 +3948,9 @@ int __init intel_iommu_init(void)/* VT-d is required for a TXT/tboot launch, so enforce that */ force_on =tboot_force_iommu (); +if (no_iommu || dmar_disabled) +return ret; +if (iommu_init_mempool ()) {if (force_on)panic ("tboot: Failed to initialize iommu memory\n" );
@@ -3974,9 +3977,6 @@ int __init intel_iommu_init(void) goto out_free_dmar; } -if (no_iommu || dmar_disabled) - goto out_free_dmar; -if (list_empty (&dmar_rmrr_units))printk (KERN_INFO "DMAR: No RMRR found\n" );
Signature · 1 line
1.7.1
Joerg Roedel
maintainerRe: [PATCH 2/6] iommu/vt-d: move up no_iommu and dmar_disabled check
Quoted 23 lines · Yijing Wang
Move up the
no_iommuanddmar_disabledcheck, avoid the useless initialization for dmar.Signed-off-by Yijing Wang <[email protected]>--- drivers/iommu/intel-iommu.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)drivers/iommu/intel-iommu.c +3
-0@@ -3948,6 +3948,9 @@ int __init intel_iommu_init(void)/* VT-d is required for a TXT/tboot launch, so enforce that */ force_on =tboot_force_iommu (); +if (no_iommu || dmar_disabled) +return ret; +if (iommu_init_mempool ()) {if (force_on)panic ("tboot: Failed to initialize iommu memory\n" );
drivers/iommu/intel-iommu.c int __init intel_iommu_init(void) · line 3981
Quoted 8 lines
drivers/iommu/intel-iommu.c +0
-3@@ -3974,9 +3977,6 @@ int __init intel_iommu_init(void) goto out_free_dmar; } -if (no_iommu || dmar_disabled) - goto out_free_dmar; -if (list_empty (&dmar_rmrr_units))printk (KERN_INFO "DMAR: No RMRR found\n" );
This breaks the kexec case were the old kernel had VT-d enabled and the new one disabled. In this case the new kernel might need to disable the IOMMUs.
Joerg
Re: [PATCH 2/6] iommu/vt-d: move up no_iommu and dmar_disabled check
Quoted 18 lines
Quoted 18 lines
drivers/iommu/intel-iommu.c +3
-0@@ -3948,6 +3948,9 @@ int __init intel_iommu_init(void)/* VT-d is required for a TXT/tboot launch, so enforce that */ force_on =tboot_force_iommu (); +if (no_iommu || dmar_disabled) +return ret; +if (iommu_init_mempool ()) {if (force_on)panic ("tboot: Failed to initialize iommu memory\n" );@@ -3974,9 +3977,6 @@ int __init intel_iommu_init(void) goto out_free_dmar; }
Quoted 9 lines
drivers/iommu/intel-iommu.c int __init intel_iommu_init(void) · line 3981
Quoted 5 lines
drivers/iommu/intel-iommu.c +0
-3-if (no_iommu || dmar_disabled) - goto out_free_dmar; -if (list_empty (&dmar_rmrr_units))printk (KERN_INFO "DMAR: No RMRR found\n" );This breaks the kexec case were the old kernel had VT-d enabled and the new one disabled. In this case the new kernel might need to disable the IOMMUs.
Hi Joerg,
Thanks for your review and comments! You are right, I didn't consider the kexec case,
I will drop this patch.
Thanks!
Yijing.
Quoted 9 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 2 lines
Thanks! Yijing
PATCH 3/6 iommu/vt-d: clear the redundant assignment in dmar_enable_qi
In reply to Yijing Wang__dmar_enable_qi() will initialize free_head,free_tail and free_cnt for q_inval. Remove the redundant initialization in dmar_enable_qi().
--- drivers/iommu/dmar.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)
drivers/iommu/dmar.c +0 -3
@@ -1339,9 +1339,6 @@ int dmar_enable_qi(struct intel_iommu *iommu)return -ENOMEM ; } - qi->free_head = qi->free_tail =0 ; - qi->free_cnt =QI_LENGTH ; -raw_spin_lock_init (&qi->q_lock);__dmar_enable_qi (iommu);
Signature · 1 line
1.7.1
PATCH 4/6 iommu/vt-d: clear the redundant assignment for domain->nid
In reply to Yijing WangAlloc_domain() will initialize domain->nid to -1. So the initialization for domain->nid in md_domain_init() is redundant, clear it.
--- drivers/iommu/intel-iommu.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/iommu/intel-iommu.c +0 -1
@@ -4134,7 +4134,6 @@ static int md_domain_init(struct dmar_domain *domain, int guest_width) domain->iommu_snooping =0 ; domain->iommu_superpage =0 ; domain->max_addr =0 ; - domain->nid =-1 ;/* always allocate the top pgd */ domain->pgd = (struct dma_pte *)alloc_pgtable_page (domain->nid);
Signature · 1 line
1.7.1
PATCH 5/6 iommu/vt-d: use inline function dma_pte_superpage instead of macros
In reply to Yijing WangUse inline function dma_pte_superpage() instead of macro for better readability.
--- drivers/iommu/intel-iommu.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/iommu/intel-iommu.c +1 -1
@@ -891,7 +891,7 @@ static struct dma_pte *dma_pfn_level_pte(struct dmar_domain *domain,break ; } -if (pte->val &DMA_PTE_LARGE_PAGE ) { +if (dma_pte_superpage (pte)) { *large_page = total;return pte; }
Signature · 1 line
1.7.1
PATCH 6/6 iommu/vt-d: fix reference count in iommu_prepare_isa
In reply to Yijing WangDecrease the device reference count avoid memory leak.
--- drivers/iommu/intel-iommu.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/iommu/intel-iommu.c +2 -1
@@ -2401,7 +2401,8 @@ static inline void iommu_prepare_isa(void)if (ret)printk (KERN_ERR "IOMMU: Failed to create 0-16MiB identity map; " "floppy might not work\n" ); - + + pci_dev_put(pdev); }#else static inline void iommu_prepare_isa (void )
Signature · 1 line
1.7.1
ping...
Quoted 18 lines · Yijing Wang
Some cleanup patches for iommu/vt-d.
Yijing Wang (6):
iommu/vt-d: Uselist_for_each_safe()to simplify code iommu/vt-d: move upno_iommuanddmar_disabledcheck iommu/vt-d: clear the redundant assignment indmar_enable_qiiommu/vt-d: clear the redundant assignment fordomain->nidiommu/vt-d: use inline functiondma_pte_superpageinstead of macros iommu/vt-d: fix reference count iniommu_prepare_isadrivers/iommu/dmar.c | 3 --- drivers/iommu/intel-iommu.c | 18 ++++++++---------- 2 files changed, 8 insertions(+), 13 deletions(-).
Signature · 2 lines
Thanks! Yijing
Quoted 8 lines · Yijing Wang
Yijing Wang (6):
iommu/vt-d: Uselist_for_each_safe()to simplify code iommu/vt-d: move upno_iommuanddmar_disabledcheck iommu/vt-d: clear the redundant assignment indmar_enable_qiiommu/vt-d: clear the redundant assignment fordomain->nidiommu/vt-d: use inline functiondma_pte_superpageinstead of macros iommu/vt-d: fix reference count iniommu_prepare_isa
Applied patches 1, 3, 4, 5 and 6, thanks. Also added another patch on-top, see below.
Quoted 1 line
From
77c704bebc5d023ece7af32ea18bc3508cdb0007Mon Sep 17 00:00:00 2001
From: Joerg Roedel <[email protected]>
Date: Fri, 4 Jul 2014 11:19:10 +0200
Subject: [PATCH] iommu/vt-d: Don't use magic number in dma_pte_superpage
Use the already defined DMA_PTE_LARGE_PAGE for testing instead of hardcoding the value again.
--- drivers/iommu/intel-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/intel-iommu.c +1 -1
@@ -304,7 +304,7 @@ static inline bool dma_pte_present(struct dma_pte *pte)static inline bool dma_pte_superpage (struct dma_pte *pte) { -return (pte->val & (1 <<7 )); +return (pte->val &DMA_PTE_LARGE_PAGE ); }static inline int first_pte_in_page (struct dma_pte *pte)
Signature · 1 line
1.8.4.5
Quoted 10 lines · Joerg Roedel
Quoted 8 lines · Yijing Wang
Yijing Wang (6):
iommu/vt-d: Uselist_for_each_safe()to simplify code iommu/vt-d: move upno_iommuanddmar_disabledcheck iommu/vt-d: clear the redundant assignment indmar_enable_qiiommu/vt-d: clear the redundant assignment fordomain->nidiommu/vt-d: use inline functiondma_pte_superpageinstead of macros iommu/vt-d: fix reference count iniommu_prepare_isa
Quoted 2 lines
Applied patches 1, 3, 4, 5 and 6, thanks. Also added another patch on-top, see below.
Thanks a lot!
Yijing.
Quoted 28 lines
Quoted 2 lines
From
77c704bebc5d023ece7af32ea18bc3508cdb0007Mon Sep 17 00:00:00 2001From: Joerg Roedel <[email protected]>
Date: Fri, 4 Jul 2014 11:19:10 +0200
Subject: [PATCH] iommu/vt-d: Don't use magic number indma_pte_superpageUse the already defined
DMA_PTE_LARGE_PAGEfor testing instead of hardcoding the value again.Signed-off-by Joerg Roedel <[email protected]>--- drivers/iommu/intel-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iommu/intel-iommu.c +1
-1@@ -304,7 +304,7 @@ static inline bool dma_pte_present(struct dma_pte *pte)static inline bool dma_pte_superpage (struct dma_pte *pte) { -return (pte->val & (1 <<7 )); +return (pte->val &DMA_PTE_LARGE_PAGE ); }static inline int first_pte_in_page (struct dma_pte *pte)
Signature · 2 lines
Thanks! Yijing