Re: [PATCH v2 1/1] iommu/vtd: Cleanup dma_remapping.h header

2018-11-11 Thread Lu Baolu

Hi,

On 11/12/18 3:20 PM, Liu, Yi L wrote:

boun...@lists.linux-foundation.org] On Behalf Of Lu Baolu
Sent: Monday, November 12, 2018 2:40 PM
Subject: [PATCH v2 1/1] iommu/vtd: Cleanup dma_remapping.h header

Commit e61d98d8dad00 ("x64, x2apic/intr-remap: Intel vt-d, IOMMU
code reorganization") moved dma_remapping.h from drivers/pci/ to
current place. It is entirely VT-d specific, but uses a generic
name. This merges dma_remapping.h with include/linux/intel-iommu.h
and removes dma_remapping.h as the result.

Cc: Ashok Raj 
Cc: Jacob Pan 
Cc: Sohil Mehta 
Suggested-by: Christoph Hellwig 
Signed-off-by: Lu Baolu 
Reviewed-by: Christoph Hellwig 
---


Reviewed-by: Liu, Yi L 

Just out of curious, did you considered to modify the original file
name to be an intel specific file name? What makes you believe
merging the file content to intel-iommu.h is better?


I don't think we need multiple headers for VT-d specific things.

Best regards,
Lu Baolu
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


RE: [PATCH v2 1/1] iommu/vtd: Cleanup dma_remapping.h header

2018-11-11 Thread Liu, Yi L
> boun...@lists.linux-foundation.org] On Behalf Of Lu Baolu
> Sent: Monday, November 12, 2018 2:40 PM
> Subject: [PATCH v2 1/1] iommu/vtd: Cleanup dma_remapping.h header
> 
> Commit e61d98d8dad00 ("x64, x2apic/intr-remap: Intel vt-d, IOMMU
> code reorganization") moved dma_remapping.h from drivers/pci/ to
> current place. It is entirely VT-d specific, but uses a generic
> name. This merges dma_remapping.h with include/linux/intel-iommu.h
> and removes dma_remapping.h as the result.
> 
> Cc: Ashok Raj 
> Cc: Jacob Pan 
> Cc: Sohil Mehta 
> Suggested-by: Christoph Hellwig 
> Signed-off-by: Lu Baolu 
> Reviewed-by: Christoph Hellwig 
> ---

Reviewed-by: Liu, Yi L 

Just out of curious, did you considered to modify the original file
name to be an intel specific file name? What makes you believe
merging the file content to intel-iommu.h is better?

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


[RFC PATCH 4/5] iommu/vt-d: Allocate and free a pasid

2018-11-11 Thread Lu Baolu
This adds the Intel vt-d specific ops to allocate and free a
pasid value.

Cc: Ashok Raj 
Cc: Jacob Pan 
Cc: Kevin Tian 
Signed-off-by: Liu Yi L 
Signed-off-by: Lu Baolu 
---
 drivers/iommu/intel-iommu.c | 33 +
 1 file changed, 33 insertions(+)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 769b7059d52f..8dbd0c601dab 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -5626,6 +5626,37 @@ static int intel_iommu_pasid_init(struct iommu_pasid 
*pasid)
return 0;
 }
 
+static int intel_iommu_pasid_alloc(struct iommu_pasid *pasid, ioasid_t start,
+  ioasid_t end, ioasid_t *ioasid)
+{
+   struct intel_iommu *iommu;
+
+   iommu = pasid->priv;
+   if (!iommu)
+   return -EINVAL;
+
+   /*
+* In caching mode, PASID ID should be allocated and freed
+* through the virtual command registers. Otherwise, rely
+* on the iommu global idr.
+*/
+   if (!cap_caching_mode(iommu->cap))
+   return -EAGAIN;
+
+   return vcmd_alloc_pasid(iommu, ioasid);
+}
+
+static void intel_iommu_pasid_free(struct iommu_pasid *pasid, ioasid_t ioasid)
+{
+   struct intel_iommu *iommu;
+
+   iommu = pasid->priv;
+   if (!iommu || !cap_caching_mode(iommu->cap))
+   return;
+
+   vcmd_free_pasid(iommu, ioasid);
+}
+
 const struct iommu_ops intel_iommu_ops = {
.capable= intel_iommu_capable,
.domain_alloc   = intel_iommu_domain_alloc,
@@ -5646,6 +5677,8 @@ const struct iommu_ops intel_iommu_ops = {
.get_dev_attr   = intel_iommu_get_dev_attr,
.set_dev_attr   = intel_iommu_set_dev_attr,
.pasid_init = intel_iommu_pasid_init,
+   .pasid_alloc= intel_iommu_pasid_alloc,
+   .pasid_free = intel_iommu_pasid_free,
.pgsize_bitmap  = INTEL_IOMMU_PGSIZES,
 };
 
-- 
2.17.1

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


[RFC PATCH 5/5] iommu/vt-d: Use global pasid allocator

2018-11-11 Thread Lu Baolu
This uses global pasid allocator in the Intel iommu driver.

Cc: Ashok Raj 
Cc: Jacob Pan 
Cc: Kevin Tian 
Signed-off-by: Liu Yi L 
Signed-off-by: Lu Baolu 
---
 drivers/iommu/intel-iommu.c | 20 +++-
 drivers/iommu/intel-pasid.c | 36 
 drivers/iommu/intel-pasid.h |  3 ---
 drivers/iommu/intel-svm.c   | 24 +---
 include/linux/intel-iommu.h |  3 +++
 5 files changed, 31 insertions(+), 55 deletions(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 8dbd0c601dab..e15b81afcbbc 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -1698,7 +1698,11 @@ static void free_dmar_iommu(struct intel_iommu *iommu)
if (ecap_prs(iommu->ecap))
intel_svm_finish_prq(iommu);
}
+
+   iommu_pasid_exit(iommu->svm_pasid);
 #endif
+
+   iommu_pasid_exit(iommu->aux_pasid);
 }
 
 static struct dmar_domain *alloc_domain(int flags)
@@ -5050,7 +5054,7 @@ static void auxiliary_unlink_device(struct dmar_domain 
*domain,
domain->auxd_refcnt--;
 
if (!domain->auxd_refcnt && domain->default_pasid > 0)
-   intel_pasid_free_id(domain->default_pasid);
+   iommu_pasid_free(info->iommu->aux_pasid, domain->default_pasid);
 }
 
 static int domain_add_dev_auxd(struct dmar_domain *domain,
@@ -5067,9 +5071,10 @@ static int domain_add_dev_auxd(struct dmar_domain 
*domain,
 
spin_lock_irqsave(_domain_lock, flags);
if (domain->default_pasid <= 0) {
-   domain->default_pasid = intel_pasid_alloc_id(domain, PASID_MIN,
-   pci_max_pasids(to_pci_dev(dev)), GFP_ATOMIC);
-   if (domain->default_pasid < 0) {
+   ret = iommu_pasid_alloc(iommu->aux_pasid, PASID_MIN,
+   pci_max_pasids(to_pci_dev(dev)),
+   domain, >default_pasid);
+   if (ret) {
pr_err("Can't allocate default pasid\n");
ret = -ENODEV;
goto pasid_failed;
@@ -5099,7 +5104,7 @@ static int domain_add_dev_auxd(struct dmar_domain *domain,
 attach_failed:
spin_unlock(>lock);
if (!domain->auxd_refcnt && domain->default_pasid > 0)
-   intel_pasid_free_id(domain->default_pasid);
+   iommu_pasid_free(iommu->aux_pasid, domain->default_pasid);
 pasid_failed:
spin_unlock_irqrestore(_domain_lock, flags);
 
@@ -5525,6 +5530,7 @@ static int intel_iommu_enable_auxd(struct device *dev)
 {
struct device_domain_info *info;
struct dmar_domain *domain;
+   struct intel_iommu *iommu;
unsigned long flags;
 
if (!scalable_mode_support())
@@ -5539,6 +5545,10 @@ static int intel_iommu_enable_auxd(struct device *dev)
info->auxd_enabled = 1;
spin_unlock_irqrestore(_domain_lock, flags);
 
+   iommu = info->iommu;
+   if (!iommu->aux_pasid)
+   iommu->aux_pasid = iommu_pasid_init(_bus_type);
+
return 0;
 }
 
diff --git a/drivers/iommu/intel-pasid.c b/drivers/iommu/intel-pasid.c
index fb42f0c2493e..68eaef3bd4fd 100644
--- a/drivers/iommu/intel-pasid.c
+++ b/drivers/iommu/intel-pasid.c
@@ -26,7 +26,6 @@
  */
 static DEFINE_SPINLOCK(pasid_lock);
 u32 intel_pasid_max_id = PASID_MAX;
-static DEFINE_IDR(pasid_idr);
 
 int vcmd_alloc_pasid(struct intel_iommu *iommu, unsigned int *pasid)
 {
@@ -98,41 +97,6 @@ void vcmd_free_pasid(struct intel_iommu *iommu, unsigned int 
pasid)
}
 }
 
-int intel_pasid_alloc_id(void *ptr, int start, int end, gfp_t gfp)
-{
-   int ret, min, max;
-
-   min = max_t(int, start, PASID_MIN);
-   max = min_t(int, end, intel_pasid_max_id);
-
-   WARN_ON(in_interrupt());
-   idr_preload(gfp);
-   spin_lock(_lock);
-   ret = idr_alloc(_idr, ptr, min, max, GFP_ATOMIC);
-   spin_unlock(_lock);
-   idr_preload_end();
-
-   return ret;
-}
-
-void intel_pasid_free_id(int pasid)
-{
-   spin_lock(_lock);
-   idr_remove(_idr, pasid);
-   spin_unlock(_lock);
-}
-
-void *intel_pasid_lookup_id(int pasid)
-{
-   void *p;
-
-   spin_lock(_lock);
-   p = idr_find(_idr, pasid);
-   spin_unlock(_lock);
-
-   return p;
-}
-
 /*
  * Per device pasid table management:
  */
diff --git a/drivers/iommu/intel-pasid.h b/drivers/iommu/intel-pasid.h
index c80787d02e2d..029f82ce9f4a 100644
--- a/drivers/iommu/intel-pasid.h
+++ b/drivers/iommu/intel-pasid.h
@@ -60,9 +60,6 @@ struct pasid_table {
 };
 
 extern u32 intel_pasid_max_id;
-int intel_pasid_alloc_id(void *ptr, int start, int end, gfp_t gfp);
-void intel_pasid_free_id(int pasid);
-void *intel_pasid_lookup_id(int pasid);
 int intel_pasid_alloc_table(struct device *dev);
 void intel_pasid_free_table(struct device *dev);
 struct pasid_table *intel_pasid_get_table(struct device *dev);
diff --git a/drivers/iommu/intel-svm.c 

[RFC PATCH 3/5] iommu/vt-d: Enlightened PASID allocation

2018-11-11 Thread Lu Baolu
If Intel IOMMU runs in caching mode, a.k.a. virtual IOMMU, the
IOMMU driver should rely on the emulation software to allocate
and free PASID IDs. The Intel vt-d spec revision 3.0 defines a
register set to support this. This includes a capability register,
a virtual command register and a virtual response register. Refer
to section 10.4.42, 10.4.43, 10.4.44 for more information.

This patch adds the enlightened PASID allocation/free interfaces
via the virtual command register.

Cc: Ashok Raj 
Cc: Jacob Pan 
Cc: Kevin Tian 
Signed-off-by: Liu Yi L 
Signed-off-by: Lu Baolu 
---
 drivers/iommu/intel-pasid.c | 70 +
 drivers/iommu/intel-pasid.h | 13 ++-
 include/linux/intel-iommu.h |  2 ++
 3 files changed, 84 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/intel-pasid.c b/drivers/iommu/intel-pasid.c
index 839f83974aca..fb42f0c2493e 100644
--- a/drivers/iommu/intel-pasid.c
+++ b/drivers/iommu/intel-pasid.c
@@ -28,6 +28,76 @@ static DEFINE_SPINLOCK(pasid_lock);
 u32 intel_pasid_max_id = PASID_MAX;
 static DEFINE_IDR(pasid_idr);
 
+int vcmd_alloc_pasid(struct intel_iommu *iommu, unsigned int *pasid)
+{
+   u64 res;
+   u64 cap;
+   u8 err_code;
+   unsigned long flags;
+   int ret = 0;
+
+   if (!ecap_vcs(iommu->ecap)) {
+   pr_warn("IOMMU: %s: Hardware doesn't support virtual command\n",
+   iommu->name);
+   return -ENODEV;
+   }
+
+   cap = dmar_readq(iommu->reg + DMAR_VCCAP_REG);
+   if (!(cap & DMA_VCS_PAS)) {
+   pr_warn("IOMMU: %s: Emulation software doesn't support PASID 
allocation\n",
+   iommu->name);
+   return -ENODEV;
+   }
+
+   raw_spin_lock_irqsave(>register_lock, flags);
+   dmar_writeq(iommu->reg + DMAR_VCMD_REG, VCMD_CMD_ALLOC);
+   IOMMU_WAIT_OP(iommu, DMAR_VCRSP_REG, dmar_readq,
+ !(res & VCMD_VRSP_IP), res);
+   raw_spin_unlock_irqrestore(>register_lock, flags);
+
+   err_code = VCMD_VRSP_EC(res);
+   switch (err_code) {
+   case VCMD_VRSP_EC_SUCCESS:
+   *pasid = VCMD_VRSP_RESULE(res);
+   break;
+   case VCMD_VRSP_EC_UNAVAIL:
+   pr_info("IOMMU: %s: No PASID available\n", iommu->name);
+   ret = -ENOMEM;
+   break;
+   default:
+   ret = -ENODEV;
+   pr_warn("IOMMU: %s: Unkonwn error code %d\n",
+   iommu->name, err_code);
+   }
+
+   return ret;
+}
+
+void vcmd_free_pasid(struct intel_iommu *iommu, unsigned int pasid)
+{
+   u64 res;
+   u8 err_code;
+   unsigned long flags;
+
+   raw_spin_lock_irqsave(>register_lock, flags);
+   dmar_writeq(iommu->reg + DMAR_VCMD_REG, (pasid << 8) | VCMD_CMD_FREE);
+   IOMMU_WAIT_OP(iommu, DMAR_VCRSP_REG, dmar_readq,
+ !(res & VCMD_VRSP_IP), res);
+   raw_spin_unlock_irqrestore(>register_lock, flags);
+
+   err_code = VCMD_VRSP_EC(res);
+   switch (err_code) {
+   case VCMD_VRSP_EC_SUCCESS:
+   break;
+   case VCMD_VRSP_EC_INVAL:
+   pr_info("IOMMU: %s: Invalid PASID\n", iommu->name);
+   break;
+   default:
+   pr_warn("IOMMU: %s: Unkonwn error code %d\n",
+   iommu->name, err_code);
+   }
+}
+
 int intel_pasid_alloc_id(void *ptr, int start, int end, gfp_t gfp)
 {
int ret, min, max;
diff --git a/drivers/iommu/intel-pasid.h b/drivers/iommu/intel-pasid.h
index 381545ff9fb7..c80787d02e2d 100644
--- a/drivers/iommu/intel-pasid.h
+++ b/drivers/iommu/intel-pasid.h
@@ -19,6 +19,16 @@
 #define PASID_PDE_SHIFT6
 #define MAX_NR_PASID_BITS  20
 
+/* Virtual command interface for enlightened pasid management. */
+#define VCMD_CMD_ALLOC 0x1
+#define VCMD_CMD_FREE  0x2
+#define VCMD_VRSP_IP   0x1
+#define VCMD_VRSP_EC(e)(((e) >> 1) & 0x3)
+#define VCMD_VRSP_EC_SUCCESS   0
+#define VCMD_VRSP_EC_UNAVAIL   1
+#define VCMD_VRSP_EC_INVAL 1
+#define VCMD_VRSP_RESULE(e)(((e) >> 8) & 0xf)
+
 /*
  * Domain ID reserved for pasid entries programmed for first-level
  * only and pass-through transfer modes.
@@ -69,5 +79,6 @@ int intel_pasid_setup_pass_through(struct intel_iommu *iommu,
   struct device *dev, int pasid);
 void intel_pasid_tear_down_entry(struct intel_iommu *iommu,
 struct device *dev, int pasid);
-
+int vcmd_alloc_pasid(struct intel_iommu *iommu, unsigned int *pasid);
+void vcmd_free_pasid(struct intel_iommu *iommu, unsigned int pasid);
 #endif /* __INTEL_PASID_H */
diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
index b563a61a6c39..4605eef3686c 100644
--- a/include/linux/intel-iommu.h
+++ b/include/linux/intel-iommu.h
@@ -173,6 +173,7 @@
 

[RFC PATCH 1/5] iommu: Add APIs for IOMMU PASID management

2018-11-11 Thread Lu Baolu
This adds APIs for IOMMU drivers and device drivers to manage
the PASIDs used for DMA transfer and translation. It bases on
I/O ASID allocator for PASID namespace management and relies
on vendor specific IOMMU drivers for paravirtual PASIDs.

Below APIs are added:

* iommu_pasid_init(pasid)
  - Initialize a PASID consumer. The vendor specific IOMMU
drivers are able to set the PASID range imposed by IOMMU
hardware through a callback in iommu_ops.

* iommu_pasid_exit(pasid)
  - The PASID consumer stops consuming any PASID.

* iommu_pasid_alloc(pasid, min, max, private, *ioasid)
  - Allocate a PASID and associate a @private data with this
PASID. The PASID value is stored in @ioaisd if returning
success.

* iommu_pasid_free(pasid, ioasid)
  - Free a PASID to the pool so that it could be consumed by
others.

This also adds below helpers to lookup or iterate PASID items
associated with a consumer.

* iommu_pasid_for_each(pasid, func, data)
  - Iterate PASID items of the consumer identified by @pasid,
and call @func() against each item. An error returned from
@func() will break the iteration.

* iommu_pasid_find(pasid, ioasid)
  - Retrieve the private data associated with @ioasid.

Cc: Ashok Raj 
Cc: Jacob Pan 
Cc: Kevin Tian 
Cc: Jean-Philippe Brucker 
Signed-off-by: Lu Baolu 
---
 drivers/iommu/Kconfig |  1 +
 drivers/iommu/iommu.c | 89 +++
 include/linux/iommu.h | 73 +++
 3 files changed, 163 insertions(+)

diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index d9a25715650e..39f2bb76c7b8 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -1,6 +1,7 @@
 # IOMMU_API always gets selected by whoever wants it.
 config IOMMU_API
bool
+   select IOASID
 
 menuconfig IOMMU_SUPPORT
bool "IOMMU Hardware Support"
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 0b7c96d1425e..570b244897bb 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2082,3 +2082,92 @@ void iommu_detach_device_aux(struct iommu_domain 
*domain, struct device *dev)
}
 }
 EXPORT_SYMBOL_GPL(iommu_detach_device_aux);
+
+/*
+ * APIs for PASID used by IOMMU and the device drivers which depend
+ * on IOMMU.
+ */
+struct iommu_pasid *iommu_pasid_init(struct bus_type *bus)
+{
+   struct iommu_pasid *pasid;
+   int ret;
+
+   if (!bus || !bus->iommu_ops)
+   return NULL;
+
+   pasid = kzalloc(sizeof(*pasid), GFP_KERNEL);
+   if (!pasid)
+   return NULL;
+
+   pasid->ops = bus->iommu_ops;
+   /*
+* The default range of an IOMMU PASID is from 0 to the full
+* 20bit integer.
+*/
+   pasid->min = 0;
+   pasid->max = 0x10;
+   /*
+* Give vendor specific iommu drivers a chance to set the pasid
+* limits imposed by the iommu hardware.
+*/
+   if (bus->iommu_ops->pasid_init) {
+   ret = bus->iommu_ops->pasid_init(pasid);
+   if (ret) {
+   kfree(pasid);
+   return NULL;
+   }
+   }
+
+   return pasid;
+}
+EXPORT_SYMBOL_GPL(iommu_pasid_init);
+
+void iommu_pasid_exit(struct iommu_pasid *pasid)
+{
+   kfree(pasid);
+}
+EXPORT_SYMBOL_GPL(iommu_pasid_exit);
+
+int iommu_pasid_alloc(struct iommu_pasid *pasid, ioasid_t min,
+ ioasid_t max, void *private, ioasid_t *ioasid)
+{
+   ioasid_t start, end, hw, val;
+   int ret = -EAGAIN;
+
+   start = max_t(int, min, pasid->min);
+   end = min_t(int, max, pasid->max);
+
+   if (pasid->ops->pasid_alloc)
+   ret = pasid->ops->pasid_alloc(pasid, start, end, );
+
+   if (ret == -EAGAIN)
+val = ioasid_alloc(>set, start, end, private);
+   else if (ret == 0)
+   val = ioasid_alloc(>set, hw, hw + 1, private);
+   else
+   goto hw_ret;
+
+   if (val == INVALID_IOASID)
+   goto ioasid_ret;
+
+   *ioasid = val;
+
+return 0;
+
+ioasid_ret:
+   if (pasid->ops->pasid_free)
+   pasid->ops->pasid_free(pasid, hw);
+
+hw_ret:
+   return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(iommu_pasid_alloc);
+
+void iommu_pasid_free(struct iommu_pasid *pasid, ioasid_t ioasid)
+{
+   if (pasid->ops->pasid_free)
+   pasid->ops->pasid_free(pasid, ioasid);
+
+   ioasid_free(ioasid);
+}
+EXPORT_SYMBOL_GPL(iommu_pasid_free);
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 9bf1b3f2457a..4f5202c8170b 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -20,6 +20,7 @@
 #define __LINUX_IOMMU_H
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -48,6 +49,7 @@ struct bus_type;
 struct device;
 struct iommu_domain;
 struct notifier_block;
+struct iommu_pasid;
 
 /* iommu fault flags */
 #define IOMMU_FAULT_READ   0x0
@@ -194,6 +196,9 @@ enum iommu_dev_attr {
  * @of_xlate: add OF master 

[RFC PATCH 2/5] iommu/vt-d: Initialize a PASID consumer

2018-11-11 Thread Lu Baolu
This adds the Intel vt-d specific ops to initialize a PASID
consumer.

Cc: Ashok Raj 
Cc: Jacob Pan 
Cc: Kevin Tian 
Signed-off-by: Liu Yi L 
Signed-off-by: Lu Baolu 
---
 drivers/iommu/intel-iommu.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 49a278a699b0..769b7059d52f 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -5597,6 +5597,35 @@ static int intel_iommu_domain_get_attr(struct 
iommu_domain *domain,
return ret;
 }
 
+static int intel_iommu_pasid_init(struct iommu_pasid *pasid)
+{
+   struct dmar_drhd_unit *drhd;
+   struct intel_iommu *iommu = NULL, *temp;
+
+   /*
+*  Iterate the iommu units and get a scalable mode capable one
+*  for virtual command usages. Return failure if scalable mode
+*  doesn't support by any unit.
+*/
+   rcu_read_lock();
+   for_each_active_iommu(temp, drhd) {
+   if (sm_supported(temp)) {
+   iommu = temp;
+   break;
+   }
+   }
+   rcu_read_unlock();
+
+   if (!iommu)
+   return -ENODEV;
+
+   pasid->max = intel_pasid_max_id;
+   pasid->min = PASID_MIN;
+   pasid->priv = iommu;
+
+   return 0;
+}
+
 const struct iommu_ops intel_iommu_ops = {
.capable= intel_iommu_capable,
.domain_alloc   = intel_iommu_domain_alloc,
@@ -5616,6 +5645,7 @@ const struct iommu_ops intel_iommu_ops = {
.domain_get_attr= intel_iommu_domain_get_attr,
.get_dev_attr   = intel_iommu_get_dev_attr,
.set_dev_attr   = intel_iommu_set_dev_attr,
+   .pasid_init = intel_iommu_pasid_init,
.pgsize_bitmap  = INTEL_IOMMU_PGSIZES,
 };
 
-- 
2.17.1

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


[RFC PATCH 0/5] iommu: APIs for paravirtual PASID allocation

2018-11-11 Thread Lu Baolu
This adds an uniformed API set for global PASIDs used by IOMMU
and device drivers which depend on IOMMU. It works for drivers
running on bare metal, full virtualized environments and para-
virtualized environment.

When PASID requests come from components running on the bare
metal hardware, the requests will be routed to the system wide
I/O ASID allocator.


^   ^  iommu_pasid_init() 
|   |  iommu_pasid_exit() 
|   |  iommu_pasid_alloc()
|   |  iommu_pasid_free() 
  .---.
  |   IOMMU PASID APIs|
  '---'
   |   ^
   v   |
  ..  .---.
  | I/O ASID   |  |   |
  | allocator  |  | IOMMU drivers |
  | (drivers/  |  |  or   |
  | base/  |  | virtio IOMMU  |
  | ioasid.c)  |  |   |
  ''  '---'

When PASID requests come from components running in full-virtualized
or para-virtualized environments, they will be routed to the vendor-
specific or virtio IOMMU driver, where the requests will be intercepted
and routed to the Host Linux via VFIO interfaces.

..
.Guest Linux .
..
..
. .. .
. |   IOMMU PASID APIs | .
. '' .
.   |.
.   v.
.  .--. .---...-.
.  | I/O ASID | | IOMMU drivers |.|  QEMU   |
.  '--' | /virtio IOMMU |>'-'
.   '---'.| virtio  |
..'-'
   |
   |
...|
.  Host Linux  |   .
...|
.  |---'   .
.  v   .
. ..   .
. |   IOMMU PASID APIs |   .
. ''   .
.   |  .
.   v   .---.  .
. .--.  | IOMMU drivers |  .
. | I/O ASID |  | /virtio IOMMU |  .
. '--'  '---'  .


Below APIs are introduced:

* iommu_pasid_init(pasid)
  - Initialize a PASID consumer. The vendor specific IOMMU
drivers are able to set the PASID range imposed by IOMMU
hardware through a callback in iommu_ops.

* iommu_pasid_exit(pasid)
  - The PASID consumer stops consuming any PASID.

* iommu_pasid_alloc(pasid, min, max, private, *ioasid)
  - Allocate a PASID and associate a @private data with this
PASID. The PASID value is stored in @ioaisd if returning
success.

* iommu_pasid_free(pasid, ioasid)
  - Free a PASID to the pool so that it could be consumed by
others.

It also adds below helpers to lookup or iterate PASID items.

* iommu_pasid_for_each(pasid, func, data)
  - Iterate PASID items of the consumer identified by @pasid,
and call @func() against each item. An error returned from
@func() will break the iteration.

* iommu_pasid_find(pasid, ioasid)
  - Retrieve the private data associated with @ioasid.

This patch set depends on the I/O APSID allocator posted here
[1] for discussion.

[1] https://www.spinics.net/lists/iommu/msg30639.html

Best regards,
Lu Baolu

Lu Baolu (5):
  iommu: Add APIs for IOMMU PASID management
  iommu/vt-d: Initialize a PASID consumer
  iommu/vt-d: Enlightened PASID allocation
  iommu/vt-d: Allocate and free a pasid
  iommu/vt-d: Use global pasid allocator

 drivers/iommu/Kconfig   |  1 +
 drivers/iommu/intel-iommu.c | 83 +++---
 drivers/iommu/intel-pasid.c | 88 +---
 drivers/iommu/intel-pasid.h | 16 +--
 drivers/iommu/intel-svm.c   | 24 +-
 drivers/iommu/iommu.c   | 89 +
 include/linux/intel-iommu.h |  5 +++
 include/linux/iommu.h   | 73 ++
 8 files changed, 332 insertions(+), 47 deletions(-)

-- 
2.17.1

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


Re: [PATCH v2 1/1] iommu/vtd: Cleanup dma_remapping.h header

2018-11-11 Thread Lu Baolu

Hi,

On 11/12/18 2:40 PM, Lu Baolu wrote:

Commit e61d98d8dad00 ("x64, x2apic/intr-remap: Intel vt-d, IOMMU
code reorganization") moved dma_remapping.h from drivers/pci/ to
current place. It is entirely VT-d specific, but uses a generic
name. This merges dma_remapping.h with include/linux/intel-iommu.h
and removes dma_remapping.h as the result.

Cc: Ashok Raj 
Cc: Jacob Pan 
Cc: Sohil Mehta 
Suggested-by: Christoph Hellwig 
Signed-off-by: Lu Baolu 
Reviewed-by: Christoph Hellwig 
---


Just realized that I forgot to add the change log.

Change log:
v1->v2:
 - Add "Reviewed-by: Christoph Hellwig "

Sorry about it.

Best regards,
Lu Baolu


  arch/x86/kernel/tboot.c|  2 +-
  drivers/gpu/drm/i915/i915_gem_execbuffer.c |  2 +-
  drivers/gpu/drm/i915/intel_display.c   |  2 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_drv.c|  2 +-
  drivers/misc/mic/scif/scif_rma.c   |  2 +-
  drivers/misc/mic/scif/scif_rma.h   |  2 +-
  include/linux/dma_remapping.h  | 58 --
  include/linux/intel-iommu.h| 49 +-
  8 files changed, 53 insertions(+), 66 deletions(-)
  delete mode 100644 include/linux/dma_remapping.h

diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
index a2486f444073..6e5ef8fb8a02 100644
--- a/arch/x86/kernel/tboot.c
+++ b/arch/x86/kernel/tboot.c
@@ -19,7 +19,7 @@
   *
   */
  
-#include 

+#include 
  #include 
  #include 
  #include 
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c 
b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 09187286d346..d8ccc77fdbaf 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -26,7 +26,7 @@
   *
   */
  
-#include 

+#include 
  #include 
  #include 
  #include 
diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 9741cc419e1b..45334a84fab1 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -47,7 +47,7 @@
  #include 
  #include 
  #include 
-#include 
+#include 
  #include 
  
  /* Primary plane formats for gen <= 3 */

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 61a84b958d67..c3e80a3b09fc 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -34,7 +34,7 @@
  #include 
  #include 
  #include 
-#include 
+#include 
  
  #define VMWGFX_DRIVER_DESC "Linux drm driver for VMware graphics devices"

  #define VMWGFX_CHIP_SVGAII 0
diff --git a/drivers/misc/mic/scif/scif_rma.c b/drivers/misc/mic/scif/scif_rma.c
index c824329f7012..b441f6b0c743 100644
--- a/drivers/misc/mic/scif/scif_rma.c
+++ b/drivers/misc/mic/scif/scif_rma.c
@@ -15,7 +15,7 @@
   * Intel SCIF driver.
   *
   */
-#include 
+#include 
  #include 
  #include 
  #include 
diff --git a/drivers/misc/mic/scif/scif_rma.h b/drivers/misc/mic/scif/scif_rma.h
index fa6722279196..d90a06d4e93b 100644
--- a/drivers/misc/mic/scif/scif_rma.h
+++ b/drivers/misc/mic/scif/scif_rma.h
@@ -53,7 +53,7 @@
  #ifndef SCIF_RMA_H
  #define SCIF_RMA_H
  
-#include 

+#include 
  #include 
  
  #include "../bus/scif_bus.h"

diff --git a/include/linux/dma_remapping.h b/include/linux/dma_remapping.h
deleted file mode 100644
index 21b3e7d33d68..
--- a/include/linux/dma_remapping.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _DMA_REMAPPING_H
-#define _DMA_REMAPPING_H
-
-/*
- * VT-d hardware uses 4KiB page size regardless of host page size.
- */
-#define VTD_PAGE_SHIFT (12)
-#define VTD_PAGE_SIZE  (1UL << VTD_PAGE_SHIFT)
-#define VTD_PAGE_MASK  (((u64)-1) << VTD_PAGE_SHIFT)
-#define VTD_PAGE_ALIGN(addr)   (((addr) + VTD_PAGE_SIZE - 1) & VTD_PAGE_MASK)
-
-#define VTD_STRIDE_SHIFT(9)
-#define VTD_STRIDE_MASK (((u64)-1) << VTD_STRIDE_SHIFT)
-
-#define DMA_PTE_READ (1)
-#define DMA_PTE_WRITE (2)
-#define DMA_PTE_LARGE_PAGE (1 << 7)
-#define DMA_PTE_SNP (1 << 11)
-
-#define CONTEXT_TT_MULTI_LEVEL 0
-#define CONTEXT_TT_DEV_IOTLB   1
-#define CONTEXT_TT_PASS_THROUGH 2
-/* Extended context entry types */
-#define CONTEXT_TT_PT_PASID4
-#define CONTEXT_TT_PT_PASID_DEV_IOTLB 5
-#define CONTEXT_TT_MASK (7ULL << 2)
-
-#define CONTEXT_DINVE  (1ULL << 8)
-#define CONTEXT_PRS(1ULL << 9)
-#define CONTEXT_PASIDE (1ULL << 11)
-
-struct intel_iommu;
-struct dmar_domain;
-struct root_entry;
-
-
-#ifdef CONFIG_INTEL_IOMMU
-extern int iommu_calculate_agaw(struct intel_iommu *iommu);
-extern int iommu_calculate_max_sagaw(struct intel_iommu *iommu);
-extern int dmar_disabled;
-extern int intel_iommu_enabled;
-extern int intel_iommu_tboot_noforce;
-#else
-static inline int iommu_calculate_agaw(struct intel_iommu *iommu)
-{
-   return 0;
-}
-static inline int iommu_calculate_max_sagaw(struct intel_iommu *iommu)
-{
-   return 0;
-}
-#define dmar_disabled  (1)
-#define intel_iommu_enabled (0)
-#endif
-
-

[PATCH v2 1/1] iommu/vtd: Cleanup dma_remapping.h header

2018-11-11 Thread Lu Baolu
Commit e61d98d8dad00 ("x64, x2apic/intr-remap: Intel vt-d, IOMMU
code reorganization") moved dma_remapping.h from drivers/pci/ to
current place. It is entirely VT-d specific, but uses a generic
name. This merges dma_remapping.h with include/linux/intel-iommu.h
and removes dma_remapping.h as the result.

Cc: Ashok Raj 
Cc: Jacob Pan 
Cc: Sohil Mehta 
Suggested-by: Christoph Hellwig 
Signed-off-by: Lu Baolu 
Reviewed-by: Christoph Hellwig 
---
 arch/x86/kernel/tboot.c|  2 +-
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |  2 +-
 drivers/gpu/drm/i915/intel_display.c   |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c|  2 +-
 drivers/misc/mic/scif/scif_rma.c   |  2 +-
 drivers/misc/mic/scif/scif_rma.h   |  2 +-
 include/linux/dma_remapping.h  | 58 --
 include/linux/intel-iommu.h| 49 +-
 8 files changed, 53 insertions(+), 66 deletions(-)
 delete mode 100644 include/linux/dma_remapping.h

diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
index a2486f444073..6e5ef8fb8a02 100644
--- a/arch/x86/kernel/tboot.c
+++ b/arch/x86/kernel/tboot.c
@@ -19,7 +19,7 @@
  *
  */
 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c 
b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 09187286d346..d8ccc77fdbaf 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -26,7 +26,7 @@
  *
  */
 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 9741cc419e1b..45334a84fab1 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -47,7 +47,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 /* Primary plane formats for gen <= 3 */
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 61a84b958d67..c3e80a3b09fc 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -34,7 +34,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 #define VMWGFX_DRIVER_DESC "Linux drm driver for VMware graphics devices"
 #define VMWGFX_CHIP_SVGAII 0
diff --git a/drivers/misc/mic/scif/scif_rma.c b/drivers/misc/mic/scif/scif_rma.c
index c824329f7012..b441f6b0c743 100644
--- a/drivers/misc/mic/scif/scif_rma.c
+++ b/drivers/misc/mic/scif/scif_rma.c
@@ -15,7 +15,7 @@
  * Intel SCIF driver.
  *
  */
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/drivers/misc/mic/scif/scif_rma.h b/drivers/misc/mic/scif/scif_rma.h
index fa6722279196..d90a06d4e93b 100644
--- a/drivers/misc/mic/scif/scif_rma.h
+++ b/drivers/misc/mic/scif/scif_rma.h
@@ -53,7 +53,7 @@
 #ifndef SCIF_RMA_H
 #define SCIF_RMA_H
 
-#include 
+#include 
 #include 
 
 #include "../bus/scif_bus.h"
diff --git a/include/linux/dma_remapping.h b/include/linux/dma_remapping.h
deleted file mode 100644
index 21b3e7d33d68..
--- a/include/linux/dma_remapping.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _DMA_REMAPPING_H
-#define _DMA_REMAPPING_H
-
-/*
- * VT-d hardware uses 4KiB page size regardless of host page size.
- */
-#define VTD_PAGE_SHIFT (12)
-#define VTD_PAGE_SIZE  (1UL << VTD_PAGE_SHIFT)
-#define VTD_PAGE_MASK  (((u64)-1) << VTD_PAGE_SHIFT)
-#define VTD_PAGE_ALIGN(addr)   (((addr) + VTD_PAGE_SIZE - 1) & VTD_PAGE_MASK)
-
-#define VTD_STRIDE_SHIFT(9)
-#define VTD_STRIDE_MASK (((u64)-1) << VTD_STRIDE_SHIFT)
-
-#define DMA_PTE_READ (1)
-#define DMA_PTE_WRITE (2)
-#define DMA_PTE_LARGE_PAGE (1 << 7)
-#define DMA_PTE_SNP (1 << 11)
-
-#define CONTEXT_TT_MULTI_LEVEL 0
-#define CONTEXT_TT_DEV_IOTLB   1
-#define CONTEXT_TT_PASS_THROUGH 2
-/* Extended context entry types */
-#define CONTEXT_TT_PT_PASID4
-#define CONTEXT_TT_PT_PASID_DEV_IOTLB 5
-#define CONTEXT_TT_MASK (7ULL << 2)
-
-#define CONTEXT_DINVE  (1ULL << 8)
-#define CONTEXT_PRS(1ULL << 9)
-#define CONTEXT_PASIDE (1ULL << 11)
-
-struct intel_iommu;
-struct dmar_domain;
-struct root_entry;
-
-
-#ifdef CONFIG_INTEL_IOMMU
-extern int iommu_calculate_agaw(struct intel_iommu *iommu);
-extern int iommu_calculate_max_sagaw(struct intel_iommu *iommu);
-extern int dmar_disabled;
-extern int intel_iommu_enabled;
-extern int intel_iommu_tboot_noforce;
-#else
-static inline int iommu_calculate_agaw(struct intel_iommu *iommu)
-{
-   return 0;
-}
-static inline int iommu_calculate_max_sagaw(struct intel_iommu *iommu)
-{
-   return 0;
-}
-#define dmar_disabled  (1)
-#define intel_iommu_enabled (0)
-#endif
-
-
-#endif
diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
index b0ae25837361..a58bc05d6798 100644
--- a/include/linux/intel-iommu.h
+++ b/include/linux/intel-iommu.h
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include 
 

Re: [RFC] mm: Replace all open encodings for NUMA_NO_NODE

2018-11-11 Thread Anshuman Khandual



On 11/12/2018 09:40 AM, Anshuman Khandual wrote:
> 
> 
> On 11/12/2018 09:27 AM, Joseph Qi wrote:
>> For ocfs2 part, node means host in the cluster, not NUMA node.
>>
> 
> Does not -1 indicate an invalid node which can never be present ?
> 

My bad, got it wrong. Seems like this is nothing to do with NUMA node
at all. Will drop the changes from ocfs2.
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


Re: [RFC] mm: Replace all open encodings for NUMA_NO_NODE

2018-11-11 Thread Anshuman Khandual



On 11/12/2018 09:27 AM, Joseph Qi wrote:
> For ocfs2 part, node means host in the cluster, not NUMA node.
> 

Does not -1 indicate an invalid node which can never be present ?
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


Re: [RFC] mm: Replace all open encodings for NUMA_NO_NODE

2018-11-11 Thread Joseph Qi
For ocfs2 part, node means host in the cluster, not NUMA node.

Thanks,
Joseph

On 18/11/12 10:41, Anshuman Khandual wrote:
> At present there are multiple places where invalid node number is encoded
> as -1. Even though implicitly understood it is always better to have macros
> in there. Replace these open encodings for an invalid node number with the
> global macro NUMA_NO_NODE. This helps remove NUMA related assumptions like
> 'invalid node' from various places redirecting them to a common definition.
> 
> Signed-off-by: Anshuman Khandual 
> ---
> Build tested this with multiple cross compiler options like alpha, sparc,
> arm64, x86, powerpc64le etc with their default config which might not have
> compiled tested all driver related changes. I will appreciate folks giving
> this a test in their respective build environment.
> 
> All these places for replacement were found by running the following grep
> patterns on the entire kernel code. Please let me know if this might have
> missed some instances. This might also have replaced some false positives.
> I will appreciate suggestions, inputs and review.
> 
> 1. git grep "nid == -1"
> 2. git grep "node == -1"
> 3. git grep "nid = -1"
> 4. git grep "node = -1"
> 
>  arch/alpha/include/asm/topology.h |  2 +-
>  arch/ia64/kernel/numa.c   |  2 +-
>  arch/ia64/mm/discontig.c  |  6 +++---
>  arch/ia64/sn/kernel/io_common.c   |  2 +-
>  arch/powerpc/include/asm/pci-bridge.h |  2 +-
>  arch/powerpc/kernel/paca.c|  2 +-
>  arch/powerpc/kernel/pci-common.c  |  2 +-
>  arch/powerpc/mm/numa.c| 14 +++---
>  arch/powerpc/platforms/powernv/memtrace.c |  4 ++--
>  arch/sparc/kernel/auxio_32.c  |  2 +-
>  arch/sparc/kernel/pci_fire.c  |  2 +-
>  arch/sparc/kernel/pci_schizo.c|  2 +-
>  arch/sparc/kernel/pcic.c  |  6 +++---
>  arch/sparc/kernel/psycho_common.c |  2 +-
>  arch/sparc/kernel/sbus.c  |  2 +-
>  arch/sparc/mm/init_64.c   |  6 +++---
>  arch/sparc/prom/init_32.c |  2 +-
>  arch/sparc/prom/init_64.c |  4 ++--
>  arch/sparc/prom/tree_32.c | 12 ++--
>  arch/sparc/prom/tree_64.c | 18 +-
>  arch/x86/include/asm/pci.h|  2 +-
>  arch/x86/kernel/apic/x2apic_uv_x.c|  6 +++---
>  arch/x86/kernel/smpboot.c |  2 +-
>  arch/x86/platform/olpc/olpc_dt.c  | 16 
>  drivers/block/mtip32xx/mtip32xx.c |  4 ++--
>  drivers/dma/dmaengine.c   |  3 ++-
>  drivers/infiniband/hw/hfi1/affinity.c |  2 +-
>  drivers/infiniband/hw/hfi1/init.c |  2 +-
>  drivers/iommu/dmar.c  |  4 ++--
>  drivers/iommu/intel-iommu.c   |  2 +-
>  drivers/media/pci/ivtv/ivtvfb.c   |  2 +-
>  drivers/media/platform/vivid/vivid-osd.c  |  2 +-
>  drivers/misc/sgi-xp/xpc_uv.c  |  2 +-
>  drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |  4 ++--
>  drivers/video/fbdev/mmp/fb/mmpfb.c|  2 +-
>  drivers/video/fbdev/pxa168fb.c|  2 +-
>  drivers/video/fbdev/w100fb.c  |  2 +-
>  fs/ocfs2/dlm/dlmcommon.h  |  2 +-
>  fs/ocfs2/dlm/dlmdomain.c  | 10 +-
>  fs/ocfs2/dlm/dlmmaster.c  |  2 +-
>  fs/ocfs2/dlm/dlmrecovery.c|  2 +-
>  fs/ocfs2/stack_user.c |  6 +++---
>  init/init_task.c  |  2 +-
>  kernel/kthread.c  |  2 +-
>  kernel/sched/fair.c   | 15 ---
>  lib/cpumask.c |  2 +-
>  mm/huge_memory.c  | 12 ++--
>  mm/hugetlb.c  |  2 +-
>  mm/ksm.c  |  2 +-
>  mm/memory.c   |  6 +++---
>  mm/memory_hotplug.c   | 12 ++--
>  mm/mempolicy.c|  2 +-
>  mm/page_alloc.c   |  4 ++--
>  mm/page_ext.c |  2 +-
>  net/core/pktgen.c |  2 +-
>  net/qrtr/qrtr.c   |  2 +-
>  tools/perf/bench/numa.c   |  6 +++---
>  57 files changed, 125 insertions(+), 123 deletions(-)
> 
> diff --git a/arch/alpha/include/asm/topology.h 
> b/arch/alpha/include/asm/topology.h
> index e6e13a8..f6dc89c 100644
> --- a/arch/alpha/include/asm/topology.h
> +++ b/arch/alpha/include/asm/topology.h
> @@ -29,7 +29,7 @@ static const struct cpumask *cpumask_of_node(int node)
>  {
>   int cpu;
>  
> - if (node 

[RFC] mm: Replace all open encodings for NUMA_NO_NODE

2018-11-11 Thread Anshuman Khandual
At present there are multiple places where invalid node number is encoded
as -1. Even though implicitly understood it is always better to have macros
in there. Replace these open encodings for an invalid node number with the
global macro NUMA_NO_NODE. This helps remove NUMA related assumptions like
'invalid node' from various places redirecting them to a common definition.

Signed-off-by: Anshuman Khandual 
---
Build tested this with multiple cross compiler options like alpha, sparc,
arm64, x86, powerpc64le etc with their default config which might not have
compiled tested all driver related changes. I will appreciate folks giving
this a test in their respective build environment.

All these places for replacement were found by running the following grep
patterns on the entire kernel code. Please let me know if this might have
missed some instances. This might also have replaced some false positives.
I will appreciate suggestions, inputs and review.

1. git grep "nid == -1"
2. git grep "node == -1"
3. git grep "nid = -1"
4. git grep "node = -1"

 arch/alpha/include/asm/topology.h |  2 +-
 arch/ia64/kernel/numa.c   |  2 +-
 arch/ia64/mm/discontig.c  |  6 +++---
 arch/ia64/sn/kernel/io_common.c   |  2 +-
 arch/powerpc/include/asm/pci-bridge.h |  2 +-
 arch/powerpc/kernel/paca.c|  2 +-
 arch/powerpc/kernel/pci-common.c  |  2 +-
 arch/powerpc/mm/numa.c| 14 +++---
 arch/powerpc/platforms/powernv/memtrace.c |  4 ++--
 arch/sparc/kernel/auxio_32.c  |  2 +-
 arch/sparc/kernel/pci_fire.c  |  2 +-
 arch/sparc/kernel/pci_schizo.c|  2 +-
 arch/sparc/kernel/pcic.c  |  6 +++---
 arch/sparc/kernel/psycho_common.c |  2 +-
 arch/sparc/kernel/sbus.c  |  2 +-
 arch/sparc/mm/init_64.c   |  6 +++---
 arch/sparc/prom/init_32.c |  2 +-
 arch/sparc/prom/init_64.c |  4 ++--
 arch/sparc/prom/tree_32.c | 12 ++--
 arch/sparc/prom/tree_64.c | 18 +-
 arch/x86/include/asm/pci.h|  2 +-
 arch/x86/kernel/apic/x2apic_uv_x.c|  6 +++---
 arch/x86/kernel/smpboot.c |  2 +-
 arch/x86/platform/olpc/olpc_dt.c  | 16 
 drivers/block/mtip32xx/mtip32xx.c |  4 ++--
 drivers/dma/dmaengine.c   |  3 ++-
 drivers/infiniband/hw/hfi1/affinity.c |  2 +-
 drivers/infiniband/hw/hfi1/init.c |  2 +-
 drivers/iommu/dmar.c  |  4 ++--
 drivers/iommu/intel-iommu.c   |  2 +-
 drivers/media/pci/ivtv/ivtvfb.c   |  2 +-
 drivers/media/platform/vivid/vivid-osd.c  |  2 +-
 drivers/misc/sgi-xp/xpc_uv.c  |  2 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |  4 ++--
 drivers/video/fbdev/mmp/fb/mmpfb.c|  2 +-
 drivers/video/fbdev/pxa168fb.c|  2 +-
 drivers/video/fbdev/w100fb.c  |  2 +-
 fs/ocfs2/dlm/dlmcommon.h  |  2 +-
 fs/ocfs2/dlm/dlmdomain.c  | 10 +-
 fs/ocfs2/dlm/dlmmaster.c  |  2 +-
 fs/ocfs2/dlm/dlmrecovery.c|  2 +-
 fs/ocfs2/stack_user.c |  6 +++---
 init/init_task.c  |  2 +-
 kernel/kthread.c  |  2 +-
 kernel/sched/fair.c   | 15 ---
 lib/cpumask.c |  2 +-
 mm/huge_memory.c  | 12 ++--
 mm/hugetlb.c  |  2 +-
 mm/ksm.c  |  2 +-
 mm/memory.c   |  6 +++---
 mm/memory_hotplug.c   | 12 ++--
 mm/mempolicy.c|  2 +-
 mm/page_alloc.c   |  4 ++--
 mm/page_ext.c |  2 +-
 net/core/pktgen.c |  2 +-
 net/qrtr/qrtr.c   |  2 +-
 tools/perf/bench/numa.c   |  6 +++---
 57 files changed, 125 insertions(+), 123 deletions(-)

diff --git a/arch/alpha/include/asm/topology.h 
b/arch/alpha/include/asm/topology.h
index e6e13a8..f6dc89c 100644
--- a/arch/alpha/include/asm/topology.h
+++ b/arch/alpha/include/asm/topology.h
@@ -29,7 +29,7 @@ static const struct cpumask *cpumask_of_node(int node)
 {
int cpu;
 
-   if (node == -1)
+   if (node == NUMA_NO_NODE)
return cpu_all_mask;
 
cpumask_clear(_to_cpumask_map[node]);
diff --git a/arch/ia64/kernel/numa.c b/arch/ia64/kernel/numa.c
index 92c3762..1315da6 100644
--- a/arch/ia64/kernel/numa.c
+++ b/arch/ia64/kernel/numa.c
@@ -74,7 +74,7 @@ void 

Re: [PATCH 1/1] iommu/vtd: Cleanup dma_remapping.h header

2018-11-11 Thread Lu Baolu

Hi,

On 11/10/18 4:35 PM, Christoph Hellwig wrote:

On Sat, Nov 10, 2018 at 03:08:44PM +0800, Lu Baolu wrote:

Commit e61d98d8dad00 ("x64, x2apic/intr-remap: Intel vt-d, IOMMU
code reorganization") moved dma_remapping.h from drivers/pci/ to
current place. It is entirely VT-d specific, but uses a generic
name. This merges dma_remapping.h with include/linux/intel-iommu.h
and removes dma_remapping.h as the result.


This looks fine to me, thanks for doing the work.

Reviewed-by: Christoph Hellwig 


Thank you.




--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -34,7 +34,7 @@
  #include 
  #include 
  #include 
-#include 
+#include 


Btw, I don't think this driver has any business looking at Intel
IOMMU driver internals, and the code doing so is more than gross.

Not really your job, but vmw_dma_select_mode really needs a rewrite with
someone that has at least half a clue, and some taste.

Eventually we should also drop the intel_iommu_enabled export.



Yes. Fair enough.

Best regards,
Lu Baolu
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


[PATCH 3.16 032/366] iommu/vt-d: Ratelimit each dmar fault printing

2018-11-11 Thread Ben Hutchings
3.16.61-rc1 review patch.  If anyone has any objections, please let me know.

--

From: Dmitry Safonov 

commit 6c50d79f66382d78918a768374839d6d1b606d3f upstream.

There is a ratelimit for printing, but it's incremented each time the
cpu recives dmar fault interrupt. While one interrupt may signal about
*many* faults.
So, measuring the impact it turns out that reading/clearing one fault
takes < 1 usec, and printing info about the fault takes ~170 msec.

Having in mind that maximum number of fault recording registers per
remapping hardware unit is 256.. IRQ handler may run for (170*256) msec.
And as fault-serving loop runs without a time limit, during servicing
new faults may occur..

Ratelimit each fault printing rather than each irq printing.

Fixes: commit c43fce4eebae ("iommu/vt-d: Ratelimit fault handler")

BUG: spinlock lockup suspected on CPU#0, CliShell/9903
 lock: 0x81a47440, .magic: dead4ead, .owner: kworker/u16:2/8915, 
.owner_cpu: 6
CPU: 0 PID: 9903 Comm: CliShell
Call Trace:$\n'
[..] dump_stack+0x65/0x83$\n'
[..] spin_dump+0x8f/0x94$\n'
[..] do_raw_spin_lock+0x123/0x170$\n'
[..] _raw_spin_lock_irqsave+0x32/0x3a$\n'
[..] uart_chars_in_buffer+0x20/0x4d$\n'
[..] tty_chars_in_buffer+0x18/0x1d$\n'
[..] n_tty_poll+0x1cb/0x1f2$\n'
[..] tty_poll+0x5e/0x76$\n'
[..] do_select+0x363/0x629$\n'
[..] compat_core_sys_select+0x19e/0x239$\n'
[..] compat_SyS_select+0x98/0xc0$\n'
[..] sysenter_dispatch+0x7/0x25$\n'
[..]
NMI backtrace for cpu 6
CPU: 6 PID: 8915 Comm: kworker/u16:2
Workqueue: dmar_fault dmar_fault_work
Call Trace:$\n'
[..] wait_for_xmitr+0x26/0x8f$\n'
[..] serial8250_console_putchar+0x1c/0x2c$\n'
[..] uart_console_write+0x40/0x4b$\n'
[..] serial8250_console_write+0xe6/0x13f$\n'
[..] call_console_drivers.constprop.13+0xce/0x103$\n'
[..] console_unlock+0x1f8/0x39b$\n'
[..] vprintk_emit+0x39e/0x3e6$\n'
[..] printk+0x4d/0x4f$\n'
[..] dmar_fault+0x1a8/0x1fc$\n'
[..] dmar_fault_work+0x15/0x17$\n'
[..] process_one_work+0x1e8/0x3a9$\n'
[..] worker_thread+0x25d/0x345$\n'
[..] kthread+0xea/0xf2$\n'
[..] ret_from_fork+0x58/0x90$\n'

Cc: Alex Williamson 
Cc: David Woodhouse 
Cc: Ingo Molnar 
Cc: Joerg Roedel 
Cc: Lu Baolu 
Cc: iommu@lists.linux-foundation.org
Signed-off-by: Dmitry Safonov 
Signed-off-by: Joerg Roedel 
Signed-off-by: Ben Hutchings 
---
 drivers/iommu/dmar.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

--- a/drivers/iommu/dmar.c
+++ b/drivers/iommu/dmar.c
@@ -1483,17 +1483,13 @@ irqreturn_t dmar_fault(int irq, void *de
int reg, fault_index;
u32 fault_status;
unsigned long flag;
-   bool ratelimited;
static DEFINE_RATELIMIT_STATE(rs,
  DEFAULT_RATELIMIT_INTERVAL,
  DEFAULT_RATELIMIT_BURST);
 
-   /* Disable printing, simply clear the fault when ratelimited */
-   ratelimited = !__ratelimit();
-
raw_spin_lock_irqsave(>register_lock, flag);
fault_status = readl(iommu->reg + DMAR_FSTS_REG);
-   if (fault_status && !ratelimited)
+   if (fault_status && __ratelimit())
pr_err("DRHD: handling fault status reg %x\n", fault_status);
 
/* TBD: ignore advanced fault log currently */
@@ -1503,6 +1499,8 @@ irqreturn_t dmar_fault(int irq, void *de
fault_index = dma_fsts_fault_record_index(fault_status);
reg = cap_fault_reg_offset(iommu->cap);
while (1) {
+   /* Disable printing, simply clear the fault when ratelimited */
+   bool ratelimited = !__ratelimit();
u8 fault_reason;
u16 source_id;
u64 guest_addr;

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


[PATCH v2 2/3] mm: Add support for SLAB_CACHE_DMA32

2018-11-11 Thread Nicolas Boichat
SLAB_CACHE_DMA32 is only available after explicit kmem_cache_create calls,
no default cache is created for kmalloc. Add a test in check_slab_flags
for this.

Fixes: ad67f5a6545f ("arm64: replace ZONE_DMA with ZONE_DMA32")
Signed-off-by: Nicolas Boichat 
---
 include/linux/slab.h |  2 ++
 mm/internal.h|  8 ++--
 mm/slab.c|  4 +++-
 mm/slab.h|  3 ++-
 mm/slab_common.c |  2 +-
 mm/slub.c| 18 +-
 6 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 918f374e7156f4..afc51ee1dae5d4 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -32,6 +32,8 @@
 #define SLAB_HWCACHE_ALIGN ((slab_flags_t __force)0x2000U)
 /* Use GFP_DMA memory */
 #define SLAB_CACHE_DMA ((slab_flags_t __force)0x4000U)
+/* Use GFP_DMA32 memory */
+#define SLAB_CACHE_DMA32   ((slab_flags_t __force)0x8000U)
 /* DEBUG: Store the last owner for bug hunting */
 #define SLAB_STORE_USER((slab_flags_t __force)0x0001U)
 /* Panic if kmem_cache_create() fails */
diff --git a/mm/internal.h b/mm/internal.h
index 7a500b232e4a43..2aa9c8491d2ca2 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 /*
@@ -34,9 +35,12 @@
 #define GFP_CONSTRAINT_MASK (__GFP_HARDWALL|__GFP_THISNODE)
 
 /* Check for flags that must not be used with a slab allocator */
-static inline gfp_t check_slab_flags(gfp_t flags)
+static inline gfp_t check_slab_flags(gfp_t flags, slab_flags_t slab_flags)
 {
-   gfp_t bug_mask = __GFP_DMA32 | __GFP_HIGHMEM | ~__GFP_BITS_MASK;
+   gfp_t bug_mask = __GFP_HIGHMEM | ~__GFP_BITS_MASK;
+
+   if (!IS_ENABLED(CONFIG_ZONE_DMA32) || !(slab_flags & SLAB_CACHE_DMA32))
+   bug_mask |= __GFP_DMA32;
 
if (unlikely(flags & bug_mask)) {
gfp_t invalid_mask = flags & bug_mask;
diff --git a/mm/slab.c b/mm/slab.c
index 251e09a5a3ef5c..6efcaad6a02b70 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2122,6 +2122,8 @@ int __kmem_cache_create(struct kmem_cache *cachep, 
slab_flags_t flags)
cachep->allocflags = __GFP_COMP;
if (flags & SLAB_CACHE_DMA)
cachep->allocflags |= GFP_DMA;
+   if (flags & SLAB_CACHE_DMA32)
+   cachep->allocflags |= GFP_DMA32;
if (flags & SLAB_RECLAIM_ACCOUNT)
cachep->allocflags |= __GFP_RECLAIMABLE;
cachep->size = size;
@@ -2656,7 +2658,7 @@ static struct page *cache_grow_begin(struct kmem_cache 
*cachep,
 * Be lazy and only check for valid flags here,  keeping it out of the
 * critical path in kmem_cache_alloc().
 */
-   flags = check_slab_flags(flags);
+   flags = check_slab_flags(flags, cachep->flags);
WARN_ON_ONCE(cachep->ctor && (flags & __GFP_ZERO));
local_flags = flags & (GFP_CONSTRAINT_MASK|GFP_RECLAIM_MASK);
 
diff --git a/mm/slab.h b/mm/slab.h
index 58c6c1c2a78ee3..9632772e14beb2 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -127,7 +127,8 @@ static inline slab_flags_t kmem_cache_flags(unsigned int 
object_size,
 
 
 /* Legal flag mask for kmem_cache_create(), for various configurations */
-#define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
+#define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | \
+SLAB_CACHE_DMA32 | SLAB_PANIC | \
 SLAB_TYPESAFE_BY_RCU | SLAB_DEBUG_OBJECTS )
 
 #if defined(CONFIG_DEBUG_SLAB)
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 7eb8dc136c1cb8..f204385553bbac 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -53,7 +53,7 @@ static DECLARE_WORK(slab_caches_to_rcu_destroy_work,
SLAB_FAILSLAB | SLAB_KASAN)
 
 #define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \
-SLAB_ACCOUNT)
+SLAB_CACHE_DMA32 | SLAB_ACCOUNT)
 
 /*
  * Merge control. If this is set then no merging of slab caches will occur.
diff --git a/mm/slub.c b/mm/slub.c
index 1cca562bebdc8d..c639bd008e8c11 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1681,7 +1681,7 @@ static struct page *allocate_slab(struct kmem_cache *s, 
gfp_t flags, int node)
 
 static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
 {
-   flags = check_slab_flags(flags);
+   flags = check_slab_flags(flags, s->flags);
 
return allocate_slab(s,
flags & (GFP_RECLAIM_MASK | GFP_CONSTRAINT_MASK), node);
@@ -3571,6 +3571,9 @@ static int calculate_sizes(struct kmem_cache *s, int 
forced_order)
if (s->flags & SLAB_CACHE_DMA)
s->allocflags |= GFP_DMA;
 
+   if (s->flags & SLAB_CACHE_DMA32)
+   s->allocflags |= GFP_DMA32;
+
if (s->flags & SLAB_RECLAIM_ACCOUNT)
s->allocflags |= __GFP_RECLAIMABLE;
 
@@ -5090,6 +5093,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char 
*buf)
 

[PATCH v2 3/3] iommu/io-pgtable-arm-v7s: Request DMA32 memory, and improve debugging

2018-11-11 Thread Nicolas Boichat
For level 1/2 pages, ensure GFP_DMA32 is used if CONFIG_ZONE_DMA32
is defined (e.g. on arm64 platforms).

For level 2 pages, allocate a slab cache in SLAB_CACHE_DMA32.

Also, print an error when the physical address does not fit in
32-bit, to make debugging easier in the future.

Fixes: ad67f5a6545f ("arm64: replace ZONE_DMA with ZONE_DMA32")
Signed-off-by: Nicolas Boichat 
---

Changes since v1:
 - Changed approach to use SLAB_CACHE_DMA32 added by the previous
   commit.
 - Use DMA or DMA32 depending on the architecture (DMA for arm,
   DMA32 for arm64).

drivers/iommu/io-pgtable-arm-v7s.c | 20 
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/io-pgtable-arm-v7s.c 
b/drivers/iommu/io-pgtable-arm-v7s.c
index 445c3bde04800c..996f7b6d00b44a 100644
--- a/drivers/iommu/io-pgtable-arm-v7s.c
+++ b/drivers/iommu/io-pgtable-arm-v7s.c
@@ -161,6 +161,14 @@
 
 #define ARM_V7S_TCR_PD1BIT(5)
 
+#ifdef CONFIG_ZONE_DMA32
+#define ARM_V7S_TABLE_GFP_DMA GFP_DMA32
+#define ARM_V7S_TABLE_SLAB_CACHE SLAB_CACHE_DMA32
+#else
+#define ARM_V7S_TABLE_GFP_DMA GFP_DMA
+#define ARM_V7S_TABLE_SLAB_CACHE SLAB_CACHE_DMA
+#endif
+
 typedef u32 arm_v7s_iopte;
 
 static bool selftest_running;
@@ -198,13 +206,17 @@ static void *__arm_v7s_alloc_table(int lvl, gfp_t gfp,
void *table = NULL;
 
if (lvl == 1)
-   table = (void *)__get_dma_pages(__GFP_ZERO, get_order(size));
+   table = (void *)__get_free_pages(
+   __GFP_ZERO | ARM_V7S_TABLE_GFP_DMA, get_order(size));
else if (lvl == 2)
-   table = kmem_cache_zalloc(data->l2_tables, gfp | GFP_DMA);
+   table = kmem_cache_zalloc(data->l2_tables,
+ gfp | ARM_V7S_TABLE_GFP_DMA);
phys = virt_to_phys(table);
-   if (phys != (arm_v7s_iopte)phys)
+   if (phys != (arm_v7s_iopte)phys) {
/* Doesn't fit in PTE */
+   dev_err(dev, "Page table does not fit in PTE: %pa", );
goto out_free;
+   }
if (table && !(cfg->quirks & IO_PGTABLE_QUIRK_NO_DMA)) {
dma = dma_map_single(dev, table, size, DMA_TO_DEVICE);
if (dma_mapping_error(dev, dma))
@@ -737,7 +749,7 @@ static struct io_pgtable *arm_v7s_alloc_pgtable(struct 
io_pgtable_cfg *cfg,
data->l2_tables = kmem_cache_create("io-pgtable_armv7s_l2",
ARM_V7S_TABLE_SIZE(2),
ARM_V7S_TABLE_SIZE(2),
-   SLAB_CACHE_DMA, NULL);
+   ARM_V7S_TABLE_SLAB_CACHE, NULL);
if (!data->l2_tables)
goto out_free_data;
 
-- 
2.19.1.930.g4563a0d9d0-goog

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


[PATCH v2 1/3] mm: slab/slub: Add check_slab_flags function to check for valid flags

2018-11-11 Thread Nicolas Boichat
Remove duplicated code between slab and slub, and will make it
easier to make the test more complicated in the next commits.

Fixes: ad67f5a6545f ("arm64: replace ZONE_DMA with ZONE_DMA32")
Signed-off-by: Nicolas Boichat 
---
 mm/internal.h | 17 +++--
 mm/slab.c |  8 +---
 mm/slub.c |  8 +---
 3 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/mm/internal.h b/mm/internal.h
index 3b1ec1412fd2cd..7a500b232e4a43 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -33,8 +33,22 @@
 /* Control allocation cpuset and node placement constraints */
 #define GFP_CONSTRAINT_MASK (__GFP_HARDWALL|__GFP_THISNODE)
 
-/* Do not use these with a slab allocator */
-#define GFP_SLAB_BUG_MASK (__GFP_DMA32|__GFP_HIGHMEM|~__GFP_BITS_MASK)
+/* Check for flags that must not be used with a slab allocator */
+static inline gfp_t check_slab_flags(gfp_t flags)
+{
+   gfp_t bug_mask = __GFP_DMA32 | __GFP_HIGHMEM | ~__GFP_BITS_MASK;
+
+   if (unlikely(flags & bug_mask)) {
+   gfp_t invalid_mask = flags & bug_mask;
+
+   flags &= ~bug_mask;
+   pr_warn("Unexpected gfp: %#x (%pGg). Fixing up to gfp: %#x 
(%pGg). Fix your code!\n",
+   invalid_mask, _mask, flags, );
+   dump_stack();
+   }
+
+   return flags;
+}
 
 void page_writeback_init(void);
 
diff --git a/mm/slab.c b/mm/slab.c
index 2a5654bb3b3ff3..251e09a5a3ef5c 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2656,13 +2656,7 @@ static struct page *cache_grow_begin(struct kmem_cache 
*cachep,
 * Be lazy and only check for valid flags here,  keeping it out of the
 * critical path in kmem_cache_alloc().
 */
-   if (unlikely(flags & GFP_SLAB_BUG_MASK)) {
-   gfp_t invalid_mask = flags & GFP_SLAB_BUG_MASK;
-   flags &= ~GFP_SLAB_BUG_MASK;
-   pr_warn("Unexpected gfp: %#x (%pGg). Fixing up to gfp: %#x 
(%pGg). Fix your code!\n",
-   invalid_mask, _mask, flags, );
-   dump_stack();
-   }
+   flags = check_slab_flags(flags);
WARN_ON_ONCE(cachep->ctor && (flags & __GFP_ZERO));
local_flags = flags & (GFP_CONSTRAINT_MASK|GFP_RECLAIM_MASK);
 
diff --git a/mm/slub.c b/mm/slub.c
index e3629cd7aff164..1cca562bebdc8d 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1681,13 +1681,7 @@ static struct page *allocate_slab(struct kmem_cache *s, 
gfp_t flags, int node)
 
 static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
 {
-   if (unlikely(flags & GFP_SLAB_BUG_MASK)) {
-   gfp_t invalid_mask = flags & GFP_SLAB_BUG_MASK;
-   flags &= ~GFP_SLAB_BUG_MASK;
-   pr_warn("Unexpected gfp: %#x (%pGg). Fixing up to gfp: %#x 
(%pGg). Fix your code!\n",
-   invalid_mask, _mask, flags, );
-   dump_stack();
-   }
+   flags = check_slab_flags(flags);
 
return allocate_slab(s,
flags & (GFP_RECLAIM_MASK | GFP_CONSTRAINT_MASK), node);
-- 
2.19.1.930.g4563a0d9d0-goog

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


[PATCH v2 0/3] iommu/io-pgtable-arm-v7s: Use DMA32 zone for page tables

2018-11-11 Thread Nicolas Boichat
This is a follow-up to the discussion in [1], to make sure that the page
tables allocated by iommu/io-pgtable-arm-v7s are contained within 32-bit
physical address space.

[1] https://lists.linuxfoundation.org/pipermail/iommu/2018-November/030876.html

Fixes since v1:
 - Add support for SLAB_CACHE_DMA32 in slab and slub (patches 1/2)
 - iommu/io-pgtable-arm-v7s (patch 3):
   - Changed approach to use SLAB_CACHE_DMA32 added by the previous
 commit.
   - Use DMA or DMA32 depending on the architecture (DMA for arm,
 DMA32 for arm64).

Nicolas Boichat (3):
  mm: slab/slub: Add check_slab_flags function to check for valid flags
  mm: Add support for SLAB_CACHE_DMA32
  iommu/io-pgtable-arm-v7s: Request DMA32 memory, and improve debugging

 drivers/iommu/io-pgtable-arm-v7s.c | 20 
 include/linux/slab.h   |  2 ++
 mm/internal.h  | 21 +++--
 mm/slab.c  | 10 +++---
 mm/slab.h  |  3 ++-
 mm/slab_common.c   |  2 +-
 mm/slub.c  | 24 +---
 7 files changed, 60 insertions(+), 22 deletions(-)

-- 
2.19.1.930.g4563a0d9d0-goog

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