All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] [PULL REQUEST] Intel IOMMU Updates for Linux v5.17
@ 2021-12-17  8:38 Lu Baolu
  2021-12-17  8:38 ` [PATCH 1/4] iommu/vt-d: Use bitmap_zalloc() when applicable Lu Baolu
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Lu Baolu @ 2021-12-17  8:38 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: Kefeng Wang, Kees Cook, Yury Norov, Maíra Canal,
	Nick Desaulniers, iommu, Christophe JAILLET

Hi Joerg,

The patches queued in this series are for v5.17. It includes:

 - Various cleanups, no functional changes.

Please pull.

Best regards,
Baolu

Christophe JAILLET (1):
  iommu/vt-d: Use bitmap_zalloc() when applicable

Kees Cook (1):
  iommu/vt-d: Use correctly sized arguments for bit field

Kefeng Wang (1):
  iommu/vt-d: Drop duplicate check in dma_pte_free_pagetable()

Maíra Canal (1):
  iommu/vt-d: Remove unused dma_to_mm_pfn function

 drivers/iommu/intel/iommu.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] iommu/vt-d: Use bitmap_zalloc() when applicable
  2021-12-17  8:38 [PATCH 0/4] [PULL REQUEST] Intel IOMMU Updates for Linux v5.17 Lu Baolu
@ 2021-12-17  8:38 ` Lu Baolu
  2021-12-17  8:38 ` [PATCH 2/4] iommu/vt-d: Drop duplicate check in dma_pte_free_pagetable() Lu Baolu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Lu Baolu @ 2021-12-17  8:38 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: Kefeng Wang, Kees Cook, Yury Norov, Maíra Canal,
	Nick Desaulniers, iommu, Christophe JAILLET

From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

'iommu->domain_ids' is a bitmap. So use 'bitmap_zalloc()' to simplify code
and improve the semantic.

Also change the corresponding 'kfree()' into 'bitmap_free()' to keep
consistency.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/cb7a3e0a8d522447a06298a4f244c3df072f948b.1635018498.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel/iommu.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index b6a8f3282411..4acc97765209 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -1878,17 +1878,16 @@ static void iommu_disable_translation(struct intel_iommu *iommu)
 
 static int iommu_init_domains(struct intel_iommu *iommu)
 {
-	u32 ndomains, nlongs;
+	u32 ndomains;
 	size_t size;
 
 	ndomains = cap_ndoms(iommu->cap);
 	pr_debug("%s: Number of Domains supported <%d>\n",
 		 iommu->name, ndomains);
-	nlongs = BITS_TO_LONGS(ndomains);
 
 	spin_lock_init(&iommu->lock);
 
-	iommu->domain_ids = kcalloc(nlongs, sizeof(unsigned long), GFP_KERNEL);
+	iommu->domain_ids = bitmap_zalloc(ndomains, GFP_KERNEL);
 	if (!iommu->domain_ids)
 		return -ENOMEM;
 
@@ -1903,7 +1902,7 @@ static int iommu_init_domains(struct intel_iommu *iommu)
 	if (!iommu->domains || !iommu->domains[0]) {
 		pr_err("%s: Allocating domain array failed\n",
 		       iommu->name);
-		kfree(iommu->domain_ids);
+		bitmap_free(iommu->domain_ids);
 		kfree(iommu->domains);
 		iommu->domain_ids = NULL;
 		iommu->domains    = NULL;
@@ -1964,7 +1963,7 @@ static void free_dmar_iommu(struct intel_iommu *iommu)
 		for (i = 0; i < elems; i++)
 			kfree(iommu->domains[i]);
 		kfree(iommu->domains);
-		kfree(iommu->domain_ids);
+		bitmap_free(iommu->domain_ids);
 		iommu->domains = NULL;
 		iommu->domain_ids = NULL;
 	}
-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] iommu/vt-d: Drop duplicate check in dma_pte_free_pagetable()
  2021-12-17  8:38 [PATCH 0/4] [PULL REQUEST] Intel IOMMU Updates for Linux v5.17 Lu Baolu
  2021-12-17  8:38 ` [PATCH 1/4] iommu/vt-d: Use bitmap_zalloc() when applicable Lu Baolu
@ 2021-12-17  8:38 ` Lu Baolu
  2021-12-17  8:38 ` [PATCH 3/4] iommu/vt-d: Remove unused dma_to_mm_pfn function Lu Baolu
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Lu Baolu @ 2021-12-17  8:38 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: Kefeng Wang, Kees Cook, Yury Norov, Maíra Canal,
	Nick Desaulniers, iommu, Christophe JAILLET

From: Kefeng Wang <wangkefeng.wang@huawei.com>

The BUG_ON check exists in dma_pte_clear_range(), kill the duplicate
check.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Link: https://lore.kernel.org/r/20211025032307.182974-1-wangkefeng.wang@huawei.com
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel/iommu.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 4acc97765209..e59895af952c 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -1280,10 +1280,6 @@ static void dma_pte_free_pagetable(struct dmar_domain *domain,
 				   unsigned long last_pfn,
 				   int retain_level)
 {
-	BUG_ON(!domain_pfn_supported(domain, start_pfn));
-	BUG_ON(!domain_pfn_supported(domain, last_pfn));
-	BUG_ON(start_pfn > last_pfn);
-
 	dma_pte_clear_range(domain, start_pfn, last_pfn);
 
 	/* We don't need lock here; nobody else touches the iova range */
-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] iommu/vt-d: Remove unused dma_to_mm_pfn function
  2021-12-17  8:38 [PATCH 0/4] [PULL REQUEST] Intel IOMMU Updates for Linux v5.17 Lu Baolu
  2021-12-17  8:38 ` [PATCH 1/4] iommu/vt-d: Use bitmap_zalloc() when applicable Lu Baolu
  2021-12-17  8:38 ` [PATCH 2/4] iommu/vt-d: Drop duplicate check in dma_pte_free_pagetable() Lu Baolu
@ 2021-12-17  8:38 ` Lu Baolu
  2021-12-17  8:38 ` [PATCH 4/4] iommu/vt-d: Use correctly sized arguments for bit field Lu Baolu
  2021-12-17  8:41 ` [PATCH 0/4] [PULL REQUEST] Intel IOMMU Updates for Linux v5.17 Joerg Roedel
  4 siblings, 0 replies; 6+ messages in thread
From: Lu Baolu @ 2021-12-17  8:38 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: Kefeng Wang, Kees Cook, Yury Norov, Maíra Canal,
	Nick Desaulniers, iommu, Christophe JAILLET

From: Maíra Canal <maira.canal@usp.br>

Remove dma_to_buf_pfn function, which is not used in the codebase.

This was pointed by clang with the following warning:

drivers/iommu/intel/iommu.c:136:29: warning: unused function
'dma_to_mm_pfn' [-Wunused-function]
static inline unsigned long dma_to_mm_pfn(unsigned long dma_pfn)
                            ^
Signed-off-by: Maíra Canal <maira.canal@usp.br>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
https://lore.kernel.org/r/YYhY7GqlrcTZlzuA@fedora
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel/iommu.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index e59895af952c..73ad4578de25 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -133,11 +133,6 @@ static inline unsigned long lvl_to_nr_pages(unsigned int lvl)
 
 /* VT-d pages must always be _smaller_ than MM pages. Otherwise things
    are never going to work. */
-static inline unsigned long dma_to_mm_pfn(unsigned long dma_pfn)
-{
-	return dma_pfn >> (PAGE_SHIFT - VTD_PAGE_SHIFT);
-}
-
 static inline unsigned long mm_to_dma_pfn(unsigned long mm_pfn)
 {
 	return mm_pfn << (PAGE_SHIFT - VTD_PAGE_SHIFT);
-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] iommu/vt-d: Use correctly sized arguments for bit field
  2021-12-17  8:38 [PATCH 0/4] [PULL REQUEST] Intel IOMMU Updates for Linux v5.17 Lu Baolu
                   ` (2 preceding siblings ...)
  2021-12-17  8:38 ` [PATCH 3/4] iommu/vt-d: Remove unused dma_to_mm_pfn function Lu Baolu
@ 2021-12-17  8:38 ` Lu Baolu
  2021-12-17  8:41 ` [PATCH 0/4] [PULL REQUEST] Intel IOMMU Updates for Linux v5.17 Joerg Roedel
  4 siblings, 0 replies; 6+ messages in thread
From: Lu Baolu @ 2021-12-17  8:38 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: Kefeng Wang, Kees Cook, Yury Norov, Maíra Canal,
	Nick Desaulniers, iommu, Christophe JAILLET

From: Kees Cook <keescook@chromium.org>

The find.h APIs are designed to be used only on unsigned long arguments.
This can technically result in a over-read, but it is harmless in this
case. Regardless, fix it to avoid the warning seen under -Warray-bounds,
which we'd like to enable globally:

In file included from ./include/linux/bitmap.h:9,
                 from drivers/iommu/intel/iommu.c:17:
drivers/iommu/intel/iommu.c: In function 'domain_context_mapping_one':
./include/linux/find.h:119:37: warning: array subscript 'long unsigned int[0]' is partly outside array bounds of 'int[1]' [-Warray-bounds]
  119 |                 unsigned long val = *addr & GENMASK(size - 1, 0);
      |                                     ^~~~~
drivers/iommu/intel/iommu.c:2115:18: note: while referencing 'max_pde'
 2115 |         int pds, max_pde;
      |                  ^~~~~~~

Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Yury Norov <yury.norov@gmail.com>
Link: https://lore.kernel.org/r/20211215232432.2069605-1-keescook@chromium.org
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel/iommu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 73ad4578de25..56671c7f4c08 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -2102,10 +2102,10 @@ static void domain_exit(struct dmar_domain *domain)
  */
 static inline unsigned long context_get_sm_pds(struct pasid_table *table)
 {
-	int pds, max_pde;
+	unsigned long pds, max_pde;
 
 	max_pde = table->max_pasid >> PASID_PDE_SHIFT;
-	pds = find_first_bit((unsigned long *)&max_pde, MAX_NR_PASID_BITS);
+	pds = find_first_bit(&max_pde, MAX_NR_PASID_BITS);
 	if (pds < 7)
 		return 0;
 
-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] [PULL REQUEST] Intel IOMMU Updates for Linux v5.17
  2021-12-17  8:38 [PATCH 0/4] [PULL REQUEST] Intel IOMMU Updates for Linux v5.17 Lu Baolu
                   ` (3 preceding siblings ...)
  2021-12-17  8:38 ` [PATCH 4/4] iommu/vt-d: Use correctly sized arguments for bit field Lu Baolu
@ 2021-12-17  8:41 ` Joerg Roedel
  4 siblings, 0 replies; 6+ messages in thread
From: Joerg Roedel @ 2021-12-17  8:41 UTC (permalink / raw)
  To: Lu Baolu
  Cc: Kefeng Wang, Kees Cook, Yury Norov, Maíra Canal,
	Nick Desaulniers, iommu, Christophe JAILLET

On Fri, Dec 17, 2021 at 04:38:13PM +0800, Lu Baolu wrote:
> Hi Joerg,
> 
> The patches queued in this series are for v5.17. It includes:
> 
>  - Various cleanups, no functional changes.
> 
> Please pull.

Applied, thanks Baolu.

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-12-17  8:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-17  8:38 [PATCH 0/4] [PULL REQUEST] Intel IOMMU Updates for Linux v5.17 Lu Baolu
2021-12-17  8:38 ` [PATCH 1/4] iommu/vt-d: Use bitmap_zalloc() when applicable Lu Baolu
2021-12-17  8:38 ` [PATCH 2/4] iommu/vt-d: Drop duplicate check in dma_pte_free_pagetable() Lu Baolu
2021-12-17  8:38 ` [PATCH 3/4] iommu/vt-d: Remove unused dma_to_mm_pfn function Lu Baolu
2021-12-17  8:38 ` [PATCH 4/4] iommu/vt-d: Use correctly sized arguments for bit field Lu Baolu
2021-12-17  8:41 ` [PATCH 0/4] [PULL REQUEST] Intel IOMMU Updates for Linux v5.17 Joerg Roedel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.