[PATCH] iommu/amd: Remove redundant assignment of err

2021-05-18 Thread Shaokun Zhang
'err' will be initialized and cleanup the redundant initialization.

Cc: Joerg Roedel  
Signed-off-by: Shaokun Zhang 
---
 drivers/iommu/amd/iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 80e8e1916dd1..bea91cc73153 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -1773,7 +1773,7 @@ void amd_iommu_domain_update(struct protection_domain 
*domain)
 
 int __init amd_iommu_init_api(void)
 {
-   int ret, err = 0;
+   int ret, err;
 
ret = iova_cache_get();
if (ret)
-- 
2.7.4

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


[PATCH RESEND] iommu/amd: Remove duplicate check of devid

2021-04-08 Thread Shaokun Zhang
'devid' has been checked in function check_device, no need to double
check and clean up this.

Cc: Joerg Roedel 
Cc: Will Deacon 
Signed-off-by: Shaokun Zhang 
---
 drivers/iommu/amd/iommu.c | 9 +
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index b4fa94a97446..cd1a85ff2cf4 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -1677,9 +1677,6 @@ static struct iommu_device *amd_iommu_probe_device(struct 
device *dev)
return ERR_PTR(-ENODEV);
 
devid = get_device_id(dev);
-   if (devid < 0)
-   return ERR_PTR(devid);
-
iommu = amd_iommu_rlookup_table[devid];
 
if (dev_iommu_priv_get(dev))
@@ -1961,16 +1958,12 @@ static void amd_iommu_detach_device(struct iommu_domain 
*dom,
struct device *dev)
 {
struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev);
+   int devid = get_device_id(dev);
struct amd_iommu *iommu;
-   int devid;
 
if (!check_device(dev))
return;
 
-   devid = get_device_id(dev);
-   if (devid < 0)
-   return;
-
if (dev_data->domain != NULL)
detach_device(dev);
 
-- 
2.7.4

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


Re: [PATCH] iommu/amd: Remove duplicate check of devid

2021-04-08 Thread Shaokun Zhang
Apologies for my mistake:

devid = get_device_id(dev) is need, only the check is unnecessary.

Thanks,
Shaokun

On 2021/4/9 9:31, Shaokun Zhang wrote:
> 'devid' has been checked in function check_device, no need to double
> check and clean up this.
> 
> Cc: Joerg Roedel 
> Cc: Will Deacon 
> Signed-off-by: Shaokun Zhang 
> ---
>  drivers/iommu/amd/iommu.c | 8 
>  1 file changed, 8 deletions(-)
> 
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index b4fa94a97446..4130df7c30c6 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -1676,10 +1676,6 @@ static struct iommu_device 
> *amd_iommu_probe_device(struct device *dev)
>   if (!check_device(dev))
>   return ERR_PTR(-ENODEV);
>  
> - devid = get_device_id(dev);
> - if (devid < 0)
> - return ERR_PTR(devid);
> -
>   iommu = amd_iommu_rlookup_table[devid];
>  
>   if (dev_iommu_priv_get(dev))
> @@ -1967,10 +1963,6 @@ static void amd_iommu_detach_device(struct 
> iommu_domain *dom,
>   if (!check_device(dev))
>   return;
>  
> - devid = get_device_id(dev);
> - if (devid < 0)
> - return;
> -
>   if (dev_data->domain != NULL)
>   detach_device(dev);
>  
> 
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


[PATCH] iommu/amd: Remove duplicate check of devid

2021-04-08 Thread Shaokun Zhang
'devid' has been checked in function check_device, no need to double
check and clean up this.

Cc: Joerg Roedel 
Cc: Will Deacon 
Signed-off-by: Shaokun Zhang 
---
 drivers/iommu/amd/iommu.c | 8 
 1 file changed, 8 deletions(-)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index b4fa94a97446..4130df7c30c6 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -1676,10 +1676,6 @@ static struct iommu_device 
*amd_iommu_probe_device(struct device *dev)
if (!check_device(dev))
return ERR_PTR(-ENODEV);
 
-   devid = get_device_id(dev);
-   if (devid < 0)
-   return ERR_PTR(devid);
-
iommu = amd_iommu_rlookup_table[devid];
 
if (dev_iommu_priv_get(dev))
@@ -1967,10 +1963,6 @@ static void amd_iommu_detach_device(struct iommu_domain 
*dom,
if (!check_device(dev))
return;
 
-   devid = get_device_id(dev);
-   if (devid < 0)
-   return;
-
if (dev_data->domain != NULL)
detach_device(dev);
 
-- 
2.7.4

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


[PATCH] iommu/iova: Replace cmpxchg with xchg in queue_iova

2020-08-27 Thread Shaokun Zhang
From: Yuqi Jin 

The performance of the atomic_xchg is better than atomic_cmpxchg because
no comparison is required. While the value of @fq_timer_on can only be 0
or 1. Let's use atomic_xchg instead of atomic_cmpxchg here because we
only need to check that the value changes from 0 to 1 or from 1 to 1.

Cc: Joerg Roedel 
Signed-off-by: Yuqi Jin 
Signed-off-by: Shaokun Zhang 
---
 drivers/iommu/iova.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
index 45a251da5453..30d969a4c5fd 100644
--- a/drivers/iommu/iova.c
+++ b/drivers/iommu/iova.c
@@ -579,7 +579,7 @@ void queue_iova(struct iova_domain *iovad,
 
/* Avoid false sharing as much as possible. */
if (!atomic_read(>fq_timer_on) &&
-   !atomic_cmpxchg(>fq_timer_on, 0, 1))
+   !atomic_xchg(>fq_timer_on, 1))
mod_timer(>fq_timer,
  jiffies + msecs_to_jiffies(IOVA_FQ_TIMEOUT));
 }
-- 
2.7.4

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


[PATCH] iommu/iova: Separate atomic variables to improve performance

2019-04-03 Thread Shaokun Zhang
From: Jinyu Qi  

In struct iova_domain, there are three atomic variables, the former two
are about TLB flush counters which use atomic_add operation, anoter is
used to flush timer that use cmpxhg operation.
These variables are in the same cache line, so it will cause some
performance loss under the condition that many cores call queue_iova
function, Let's isolate the two type atomic variables to different
cache line to reduce cache line conflict.

Cc: Joerg Roedel 
Signed-off-by: Jinyu Qi 
---
 include/linux/iova.h | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/linux/iova.h b/include/linux/iova.h
index 0b93bf96693e..28a5128405f8 100644
--- a/include/linux/iova.h
+++ b/include/linux/iova.h
@@ -76,6 +76,14 @@ struct iova_domain {
unsigned long   start_pfn;  /* Lower limit for this domain */
unsigned long   dma_32bit_pfn;
unsigned long   max32_alloc_size; /* Size of last failed allocation */
+   struct iova_fq __percpu *fq;/* Flush Queue */
+
+   atomic64_t  fq_flush_start_cnt; /* Number of TLB flushes that
+  have been started */
+
+   atomic64_t  fq_flush_finish_cnt;/* Number of TLB flushes that
+  have been finished */
+
struct iova anchor; /* rbtree lookup anchor */
struct iova_rcache rcaches[IOVA_RANGE_CACHE_MAX_SIZE];  /* IOVA range 
caches */
 
@@ -85,14 +93,6 @@ struct iova_domain {
iova_entry_dtor entry_dtor; /* IOMMU driver specific destructor for
   iova entry */
 
-   struct iova_fq __percpu *fq;/* Flush Queue */
-
-   atomic64_t  fq_flush_start_cnt; /* Number of TLB flushes that
-  have been started */
-
-   atomic64_t  fq_flush_finish_cnt;/* Number of TLB flushes that
-  have been finished */
-
struct timer_list fq_timer; /* Timer to regularily empty the
   flush-queues */
atomic_t fq_timer_on;   /* 1 when timer is active, 0
-- 
2.7.4

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


[PATCH] iommu/dma: Remove unused variable

2019-01-23 Thread Shaokun Zhang
end_pfn is never used after commit  ('iommu/iova: Make dma
32bit pfn implicit'), cleanup it.

Cc: Joerg Roedel 
Cc: Robin Murphy 
Cc: Zhen Lei 
Signed-off-by: Shaokun Zhang 
---
 drivers/iommu/dma-iommu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index d19f3d6b43c1..77aabe637a60 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -289,7 +289,7 @@ int iommu_dma_init_domain(struct iommu_domain *domain, 
dma_addr_t base,
 {
struct iommu_dma_cookie *cookie = domain->iova_cookie;
struct iova_domain *iovad = >iovad;
-   unsigned long order, base_pfn, end_pfn;
+   unsigned long order, base_pfn;
int attr;
 
if (!cookie || cookie->type != IOMMU_DMA_IOVA_COOKIE)
@@ -298,7 +298,6 @@ int iommu_dma_init_domain(struct iommu_domain *domain, 
dma_addr_t base,
/* Use the smallest supported page size for IOVA granularity */
order = __ffs(domain->pgsize_bitmap);
base_pfn = max_t(unsigned long, 1, base >> order);
-   end_pfn = (base + size - 1) >> order;
 
/* Check the domain allows at least some access to the device... */
if (domain->geometry.force_aperture) {
-- 
2.7.4

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


[PATCH] iommu/arm-smmu-v3: sync the OVACKFLG to PRIQ consumer register

2018-07-23 Thread Shaokun Zhang
From: Miao Zhong 

When PRI queue occurs overflow, driver should update the OVACKFLG to
the PRIQ consumer register, otherwise subsequent PRI requests will not
be processed.

Cc: Will Deacon 
Cc: Robin Murphy  
Signed-off-by: Miao Zhong 
---
 drivers/iommu/arm-smmu-v3.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
index 1d64710..deacc15 100644
--- a/drivers/iommu/arm-smmu-v3.c
+++ b/drivers/iommu/arm-smmu-v3.c
@@ -1301,6 +1301,7 @@ static irqreturn_t arm_smmu_priq_thread(int irq, void 
*dev)
 
/* Sync our overflow flag, as we believe we're up to speed */
q->cons = Q_OVF(q, q->prod) | Q_WRP(q, q->cons) | Q_IDX(q, q->cons);
+   writel(q->cons, q->cons_reg);
return IRQ_HANDLED;
 }
 
-- 
2.7.4

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


[PATCH] iommu/vt-d, trivial: Remove unused variable

2018-03-22 Thread Shaokun Zhang
Unused after commit <42e8c186b595> ("iommu/vt-d: Simplify io/tlb flushing
in intel_iommu_unmap"), cleanup it.

Cc: David Woodhouse <dw...@infradead.org>
Cc: Joerg Roedel <j...@8bytes.org>
Signed-off-by: Shaokun Zhang <zhangshao...@hisilicon.com>
---
 drivers/iommu/intel-iommu.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 582fd01..d49e0d3 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -5072,7 +5072,6 @@ static size_t intel_iommu_unmap(struct iommu_domain 
*domain,
 {
struct dmar_domain *dmar_domain = to_dmar_domain(domain);
struct page *freelist = NULL;
-   struct intel_iommu *iommu;
unsigned long start_pfn, last_pfn;
unsigned int npages;
int iommu_id, level = 0;
@@ -5091,12 +5090,9 @@ static size_t intel_iommu_unmap(struct iommu_domain 
*domain,
 
npages = last_pfn - start_pfn + 1;
 
-   for_each_domain_iommu(iommu_id, dmar_domain) {
-   iommu = g_iommus[iommu_id];
-
+   for_each_domain_iommu(iommu_id, dmar_domain)
iommu_flush_iotlb_psi(g_iommus[iommu_id], dmar_domain,
  start_pfn, npages, !freelist, 0);
-   }
 
dma_free_pagelist(freelist);
 
-- 
1.9.1

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