[PATCH] iommu/vt-d: Drop duplicate check in dma_pte_free_pagetable()

2021-10-24 Thread Kefeng Wang
The BUG_ON check exists in dma_pte_clear_range(), kill the duplicate
check.

Signed-off-by: Kefeng Wang 
---
 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 d75f59ae28e6..ea2eec87a1ea 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -1163,10 +1163,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.26.2

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


[PATCH v2 0/7] sections: Unify kernel sections range check and use

2021-07-28 Thread Kefeng Wang
There are three head files(kallsyms.h, kernel.h and sections.h) which
include the kernel sections range check, let's make some cleanup and
unify them.

1. cleanup arch specific text/data check and fix address boundary check
   in kallsyms.h
2. make all the basic/core kernel range check function into sections.h
3. update all the callers, and use the helper in sections.h to simplify
   the code

After this series, we have 5 APIs about kernel sections range check in
sections.h

 * is_kernel_core_data()--- come from core_kernel_data() in kernel.h
 * is_kernel_rodata()   --- already in sections.h
 * is_kernel_text() --- come from kallsyms.h
 * is_kernel_inittext() --- come from kernel.h and kallsyms.h
 * is_kernel()  --- come from kallsyms.h


Cc: linuxppc-...@lists.ozlabs.org
Cc: linux-s...@vger.kernel.org
Cc: linux-a...@vger.kernel.org 
Cc: iommu@lists.linux-foundation.org
Cc: b...@vger.kernel.org 

v2:
- add ACK/RW to patch2, and drop inappropriate fix tag
- keep 'core' to check kernel data, suggestted by Steven Rostedt
  , rename is_kernel_data() to is_kernel_core_data()
- drop patch8 which is merged
- drop patch9 which is resend independently

v1:
https://lore.kernel.org/linux-arch/20210626073439.150586-1-wangkefeng.w...@huawei.com

Kefeng Wang (7):
  kallsyms: Remove arch specific text and data check
  kallsyms: Fix address-checks for kernel related range
  sections: Move and rename core_kernel_data() to is_kernel_core_data()
  sections: Move is_kernel_inittext() into sections.h
  kallsyms: Rename is_kernel() and is_kernel_text()
  sections: Add new is_kernel() and is_kernel_text()
  powerpc/mm: Use is_kernel_text() and is_kernel_inittext() helper

 arch/powerpc/mm/pgtable_32.c   |  7 +---
 arch/x86/kernel/unwind_orc.c   |  2 +-
 arch/x86/net/bpf_jit_comp.c|  2 +-
 include/asm-generic/sections.h | 71 ++
 include/linux/kallsyms.h   | 21 +++---
 include/linux/kernel.h |  2 -
 kernel/cfi.c   |  2 +-
 kernel/extable.c   | 33 ++--
 kernel/locking/lockdep.c   |  3 --
 kernel/trace/ftrace.c  |  2 +-
 mm/kasan/report.c  |  2 +-
 net/sysctl_net.c   |  2 +-
 12 files changed, 72 insertions(+), 77 deletions(-)

-- 
2.26.2

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


[PATCH resend] dma-debug: Use memory_intersects() directly

2021-07-22 Thread Kefeng Wang
There is already a memory_intersects() helper in sections.h,
use memory_intersects() directly instead of private overlap().

Cc: Christoph Hellwig 
Cc: Marek Szyprowski 
Cc: Robin Murphy 
Cc: iommu@lists.linux-foundation.org
Signed-off-by: Kefeng Wang 
---

Resend this patch only.

 kernel/dma/debug.c | 14 ++
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
index dadae6255d05..fe6efd181614 100644
--- a/kernel/dma/debug.c
+++ b/kernel/dma/debug.c
@@ -1064,20 +1064,10 @@ static void check_for_stack(struct device *dev,
}
 }
 
-static inline bool overlap(void *addr, unsigned long len, void *start, void 
*end)
-{
-   unsigned long a1 = (unsigned long)addr;
-   unsigned long b1 = a1 + len;
-   unsigned long a2 = (unsigned long)start;
-   unsigned long b2 = (unsigned long)end;
-
-   return !(b1 <= a2 || a1 >= b2);
-}
-
 static void check_for_illegal_area(struct device *dev, void *addr, unsigned 
long len)
 {
-   if (overlap(addr, len, _stext, _etext) ||
-   overlap(addr, len, __start_rodata, __end_rodata))
+   if (memory_intersects(_stext, _etext, addr, len) ||
+   memory_intersects(__start_rodata, __end_rodata, addr, len))
err_printk(dev, NULL, "device driver maps memory from kernel 
text or rodata [addr=%p] [len=%lu]\n", addr, len);
 }
 
-- 
2.26.2

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


Re: [PATCH 9/9] dma-debug: Use memory_intersects() directly

2021-06-28 Thread Kefeng Wang



On 2021/6/28 14:11, Christoph Hellwig wrote:

You've sent me a patch 9 out of 9 without the previous 8 patches.  There
is no way I can sensibly review this series.


The full patches is 
https://lore.kernel.org/linux-arch/20210626073439.150586-1-wangkefeng.w...@huawei.com/T/#t


This patch is not very relevant about the above 8 patches, only use the 
existing function to simplify code.


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


[PATCH 9/9] dma-debug: Use memory_intersects() directly

2021-06-26 Thread Kefeng Wang
Use memory_intersects() directly instead of private overlap() function.

Cc: Christoph Hellwig 
Cc: Marek Szyprowski 
Cc: Robin Murphy 
Cc: iommu@lists.linux-foundation.org
Signed-off-by: Kefeng Wang 
---
 kernel/dma/debug.c | 14 ++
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
index 14de1271463f..8ef737223999 100644
--- a/kernel/dma/debug.c
+++ b/kernel/dma/debug.c
@@ -1066,20 +1066,10 @@ static void check_for_stack(struct device *dev,
}
 }
 
-static inline bool overlap(void *addr, unsigned long len, void *start, void 
*end)
-{
-   unsigned long a1 = (unsigned long)addr;
-   unsigned long b1 = a1 + len;
-   unsigned long a2 = (unsigned long)start;
-   unsigned long b2 = (unsigned long)end;
-
-   return !(b1 <= a2 || a1 >= b2);
-}
-
 static void check_for_illegal_area(struct device *dev, void *addr, unsigned 
long len)
 {
-   if (overlap(addr, len, _stext, _etext) ||
-   overlap(addr, len, __start_rodata, __end_rodata))
+   if (memory_intersects(_stext, _etext, addr, len) ||
+   memory_intersects(__start_rodata, __end_rodata, addr, len))
err_printk(dev, NULL, "device driver maps memory from kernel 
text or rodata [addr=%p] [len=%lu]\n", addr, len);
 }
 
-- 
2.26.2

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


[PATCH 0/9] sections: Unify kernel sections range check and use

2021-06-26 Thread Kefeng Wang
There are three head files(kallsyms.h, kernel.h and sections.h) which
include the kernel sections range check, let's make some cleanup and
unify them.

1. cleanup arch specific text/data check and fix address boundary check in 
kallsyms.h
2. make all the basic kernel range check function into sections.h
3. update all the callers, and use the helper in sections.h to simplify the code
4. use memory_intersects() in sections.h instead of private overlap for 
dma-debug

Cc: linuxppc-...@lists.ozlabs.org
Cc: linux-s...@vger.kernel.org
Cc: linux-a...@vger.kernel.org 
Cc: iommu@lists.linux-foundation.org
Cc: b...@vger.kernel.org 

Kefeng Wang (9):
  kallsyms: Remove arch specific text and data check
  kallsyms: Fix address-checks for kernel related range
  sections: Move and rename core_kernel_data() to is_kernel_data()
  sections: Move is_kernel_inittext() into sections.h
  kallsyms: Rename is_kernel() and is_kernel_text()
  sections: Add new is_kernel() and is_kernel_text()
  s390: kprobes: Use is_kernel() helper
  powerpc/mm: Use is_kernel_text() and is_kernel_inittext() helper
  dma-debug: Use memory_intersects() directly

 arch/powerpc/mm/pgtable_32.c   |  7 +---
 arch/s390/kernel/kprobes.c |  9 +
 arch/x86/kernel/unwind_orc.c   |  2 +-
 arch/x86/net/bpf_jit_comp.c|  2 +-
 include/asm-generic/sections.h | 71 ++
 include/linux/kallsyms.h   | 21 +++---
 include/linux/kernel.h |  2 -
 kernel/cfi.c   |  2 +-
 kernel/dma/debug.c | 14 +--
 kernel/extable.c   | 33 ++--
 kernel/locking/lockdep.c   |  3 --
 kernel/trace/ftrace.c  |  2 +-
 mm/kasan/report.c  |  2 +-
 net/sysctl_net.c   |  2 +-
 14 files changed, 76 insertions(+), 96 deletions(-)

-- 
2.26.2

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


[PATCH next 13/25] iommu/omap: Use dev_get_drvdata()

2019-04-23 Thread Kefeng Wang
Using dev_get_drvdata directly.

Cc: Joerg Roedel 
Cc: iommu@lists.linux-foundation.org
Signed-off-by: Kefeng Wang 
---
 drivers/iommu/omap-iommu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index d2fb347aa4ff..b16c711fc5fc 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -38,8 +38,7 @@
 
 static const struct iommu_ops omap_iommu_ops;
 
-#define to_iommu(dev)  \
-   ((struct omap_iommu *)platform_get_drvdata(to_platform_device(dev)))
+#define to_iommu(dev)  ((struct omap_iommu *)dev_get_drvdata(dev))
 
 /* bitmap of the page sizes currently supported */
 #define OMAP_IOMMU_PGSIZES (SZ_4K | SZ_64K | SZ_1M | SZ_16M)
-- 
2.20.1

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


[PATCH] iommu: msm: use devm_ioremap_resource to simplify code

2014-05-27 Thread Kefeng Wang
Use devm_ioremap_resource() to make the code simpler, drop unused variable,
redundant return value check, and error-handing code.

Signed-off-by: Kefeng Wang wangkefeng.w...@huawei.com
---
 drivers/iommu/msm_iommu_dev.c |   38 +++---
 1 files changed, 7 insertions(+), 31 deletions(-)

diff --git a/drivers/iommu/msm_iommu_dev.c b/drivers/iommu/msm_iommu_dev.c
index 08ba497..61def7c 100644
--- a/drivers/iommu/msm_iommu_dev.c
+++ b/drivers/iommu/msm_iommu_dev.c
@@ -127,13 +127,12 @@ static void msm_iommu_reset(void __iomem *base, int ncb)
 
 static int msm_iommu_probe(struct platform_device *pdev)
 {
-   struct resource *r, *r2;
+   struct resource *r;
struct clk *iommu_clk;
struct clk *iommu_pclk;
struct msm_iommu_drvdata *drvdata;
struct msm_iommu_dev *iommu_dev = pdev-dev.platform_data;
void __iomem *regs_base;
-   resource_size_t len;
int ret, irq, par;
 
if (pdev-id == -1) {
@@ -178,35 +177,16 @@ static int msm_iommu_probe(struct platform_device *pdev)
iommu_clk = NULL;
 
r = platform_get_resource_byname(pdev, IORESOURCE_MEM, physbase);
-
-   if (!r) {
-   ret = -ENODEV;
-   goto fail_clk;
-   }
-
-   len = resource_size(r);
-
-   r2 = request_mem_region(r-start, len, r-name);
-   if (!r2) {
-   pr_err(Could not request memory region: start=%p, len=%d\n,
-   (void *) r-start, len);
-   ret = -EBUSY;
+   regs_base = devm_ioremap_resource(pdev-dev, r);
+   if (IS_ERR(regs_base)) {
+   ret = PTR_ERR(regs_base);
goto fail_clk;
}
 
-   regs_base = ioremap(r2-start, len);
-
-   if (!regs_base) {
-   pr_err(Could not ioremap: start=%p, len=%d\n,
-(void *) r2-start, len);
-   ret = -EBUSY;
-   goto fail_mem;
-   }
-
irq = platform_get_irq_byname(pdev, secure_irq);
if (irq  0) {
ret = -ENODEV;
-   goto fail_io;
+   goto fail_clk;
}
 
msm_iommu_reset(regs_base, iommu_dev-ncb);
@@ -222,14 +202,14 @@ static int msm_iommu_probe(struct platform_device *pdev)
if (!par) {
pr_err(%s: Invalid PAR value detected\n, iommu_dev-name);
ret = -ENODEV;
-   goto fail_io;
+   goto fail_clk;
}
 
ret = request_irq(irq, msm_iommu_fault_handler, 0,
msm_iommu_secure_irpt_handler, drvdata);
if (ret) {
pr_err(Request IRQ %d failed with ret=%d\n, irq, ret);
-   goto fail_io;
+   goto fail_clk;
}
 
 
@@ -250,10 +230,6 @@ static int msm_iommu_probe(struct platform_device *pdev)
clk_disable(iommu_pclk);
 
return 0;
-fail_io:
-   iounmap(regs_base);
-fail_mem:
-   release_mem_region(r-start, len);
 fail_clk:
if (iommu_clk) {
clk_disable(iommu_clk);
-- 
1.7.1


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


Re: [PATCH] iommu/arm-smmu: fix incorrect use of S2CR_TYPE_SHIFT

2014-04-21 Thread Kefeng Wang
On 04/18 10:07, Kefeng Wang wrote:
 There is already S2CR_TYPE_TRANS in S2CR_TYPE_TRANS macro,
 so drop the second shift.

Typo issue, please use following patch.

 
 Signed-off-by: Kefeng Wang wangkefeng.w...@huawei.com
 ---
  drivers/iommu/arm-smmu.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
 
 diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
 index 8b89e33..96755ec 100644
 --- a/drivers/iommu/arm-smmu.c
 +++ b/drivers/iommu/arm-smmu.c
 @@ -1167,7 +1167,7 @@ static int arm_smmu_domain_add_master(struct 
 arm_smmu_domain *smmu_domain,
   for (i = 0; i  master-num_streamids; ++i) {
   u32 idx, s2cr;
   idx = master-smrs ? master-smrs[i].idx : master-streamids[i];
 - s2cr = (S2CR_TYPE_TRANS  S2CR_TYPE_SHIFT) |
 + s2cr = S2CR_TYPE_TRANS |
  (smmu_domain-root_cfg.cbndx  S2CR_CBNDX_SHIFT);
   writel_relaxed(s2cr, gr0_base + ARM_SMMU_GR0_S2CR(idx));
   }
 


From bfcdbee6f5e71c561dfddf8751c4eabdca1e3a56 Mon Sep 17 00:00:00 2001
From: Kefeng Wang wangkefeng.w...@huawei.com
Date: Fri, 18 Apr 2014 10:20:48 +0800
Subject: [PATCH] iommu/arm-smmu: fix incorrect use of S2CR_TYPE_SHIFT

There is already S2CR_TYPE_SHIFT in S2CR_TYPE_TRANS macro,
so drop the second shift.

Signed-off-by: Kefeng Wang wangkefeng.w...@huawei.com
---
 drivers/iommu/arm-smmu.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 8b89e33..96755ec 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -1167,7 +1167,7 @@ static int arm_smmu_domain_add_master(struct 
arm_smmu_domain *smmu_domain,
for (i = 0; i  master-num_streamids; ++i) {
u32 idx, s2cr;
idx = master-smrs ? master-smrs[i].idx : master-streamids[i];
-   s2cr = (S2CR_TYPE_TRANS  S2CR_TYPE_SHIFT) |
+   s2cr = S2CR_TYPE_TRANS |
   (smmu_domain-root_cfg.cbndx  S2CR_CBNDX_SHIFT);
writel_relaxed(s2cr, gr0_base + ARM_SMMU_GR0_S2CR(idx));
}
-- 
1.7.1


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


[PATCH] iommu/arm-smmu: fix incorrect use of S2CR_TYPE_SHIFT

2014-04-21 Thread Kefeng Wang
There is already S2CR_TYPE_TRANS in S2CR_TYPE_TRANS macro,
so drop the second shift.

Signed-off-by: Kefeng Wang wangkefeng.w...@huawei.com
---
 drivers/iommu/arm-smmu.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 8b89e33..96755ec 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -1167,7 +1167,7 @@ static int arm_smmu_domain_add_master(struct 
arm_smmu_domain *smmu_domain,
for (i = 0; i  master-num_streamids; ++i) {
u32 idx, s2cr;
idx = master-smrs ? master-smrs[i].idx : master-streamids[i];
-   s2cr = (S2CR_TYPE_TRANS  S2CR_TYPE_SHIFT) |
+   s2cr = S2CR_TYPE_TRANS |
   (smmu_domain-root_cfg.cbndx  S2CR_CBNDX_SHIFT);
writel_relaxed(s2cr, gr0_base + ARM_SMMU_GR0_S2CR(idx));
}
-- 
1.7.1


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