Skip to contentSkip to conversation

trivial cleanup for iommu/vt-d

PATCH Applied Yijing Wang 2 participants 12 messages May 20, 2014 – Jul 4, 2014 IOMMU

lore
Share & tools
lore
#0 lore raw

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(-)
#1 lore raw

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
index f256ffc..e020dcf 100644
@@ -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
#2 lore raw

PATCH 2/6 iommu/vt-d: move up no_iommu and dmar_disabled check

In reply to Yijing Wang

Move 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
index e020dcf..6b71608 100644
@@ -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
maintainer
#3 lore raw

Re: [PATCH 2/6] iommu/vt-d: move up no_iommu and dmar_disabled check

Quoted 23 lines · Yijing Wang

Move 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 -0
index e020dcf..6b71608 100644
@@ -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

#4 lore raw

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
index e020dcf..6b71608 100644
@@ -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
#5 lore raw

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
index 39f8b71..1168469 100644
@@ -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
#6 lore raw

PATCH 4/6 iommu/vt-d: clear the redundant assignment for domain->nid

In reply to Yijing Wang

Alloc_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
index 6b71608..d1d6636 100644
@@ -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
#7 lore raw

PATCH 5/6 iommu/vt-d: use inline function dma_pte_superpage instead of macros

In reply to Yijing Wang

Use 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
index d1d6636..455896c 100644
@@ -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
#8 lore raw

PATCH 6/6 iommu/vt-d: fix reference count in iommu_prepare_isa

In reply to Yijing Wang

Decrease 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
index 455896c..a78a824 100644
@@ -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
#9 lore raw
In reply to Yijing Wang

ping...

Quoted 18 lines · Yijing Wang

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(-)

.

Signature · 2 lines
Thanks!
Yijing
maintainer Applied
#10 lore raw
In reply to Yijing Wang
Quoted 8 lines · Yijing Wang

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

Applied patches 1, 3, 4, 5 and 6, thanks. Also added another patch on-top, see below.

Quoted 1 line

From 77c704bebc5d023ece7af32ea18bc3508cdb0007 Mon 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
index 9b9f28e..5d86e93 100644
@@ -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
#11 lore raw
Quoted 10 lines · Joerg Roedel
Quoted 8 lines · Yijing Wang

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

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 77c704bebc5d023ece7af32ea18bc3508cdb0007 Mon 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
index 9b9f28e..5d86e93 100644
@@ -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