[Patch Part3 V4 00/21] Enable support of Intel DMAR device hotplug

2014-07-11 Thread Jiang Liu
When hot plugging a descrete IOH or a physical processor with embedded IIO, we need to handle DMAR(or IOMMU) unit in the PCIe host bridge if DMAR is in use. This patch set tries to enhance current DMAR/IOMMU/IR drivers to support hotplug and is based on latest Joerg's iommu/next branch. Patch

[Patch Part3 V4 01/21] iommu/vt-d: Match segment number when searching for dev_iotlb capable devices

2014-07-11 Thread Jiang Liu
For virtual machine and static identity domains, there may be devices from different PCI segments associated with the same domain. So function iommu_support_dev_iotlb() should also match PCI segment number (iommu unit) when searching for dev_iotlb capable devices. Signed-off-by: Jiang Liu

[Patch Part3 V4 03/21] iommu/vt-d: Introduce helper functions to improve code readability

2014-07-11 Thread Jiang Liu
Introduce domain_type_is_vm() and domain_type_is_vm_or_si() to improve code readability. Also kill useless macro DOMAIN_FLAG_P2P_MULTIPLE_DEVICES. Signed-off-by: Jiang Liu jiang@linux.intel.com --- drivers/iommu/intel-iommu.c | 59 +++ 1 file

[Patch Part3 V4 04/21] iommu/vt-d: Introduce helper functions to make code symmetric for readability

2014-07-11 Thread Jiang Liu
Introduce domain_attach_iommu()/domain_detach_iommu() and refine iommu_attach_domain()/iommu_detach_domain() to make code symmetric and improve readability. Signed-off-by: Jiang Liu jiang@linux.intel.com --- drivers/iommu/intel-iommu.c | 147 +++ 1

[Patch Part3 V4 02/21] iommu/vt-d: Use correct domain id to flush virtual machine domains

2014-07-11 Thread Jiang Liu
For virtual machine domains, domain-id is a virtual id, and the real domain id written into context entry is dynamically allocated. So use the real domain id instead of domain-id when flushing iotlbs for virtual machine domains. Signed-off-by: Jiang Liu jiang@linux.intel.com ---

[Patch Part3 V4 05/21] iommu/vt-d: Allocate dynamic domain id for virtual domains only

2014-07-11 Thread Jiang Liu
Check the same domain id is allocated for si_domain on each IOMMU, otherwise the IOTLB flush for si_domain will fail. Now the rules to allocate and manage domain id are: 1) For normal and static identity domains, domain id is allocated when creating domain structure. And this id will be

[Patch Part3 V4 13/21] iommu/vt-d: Fix issue in computing domain's iommu_snooping flag

2014-07-11 Thread Jiang Liu
IOMMU units may dynamically attached to/detached from domains, so we should scan all active IOMMU units when computing iommu_snooping flag for a domain instead of only scanning IOMMU units associated with the domain. Also check snooping and superpage capabilities when hot-adding DMAR units.

[Patch Part3 V4 08/21] iommu/vt-d: Simplify include/linux/dmar.h

2014-07-11 Thread Jiang Liu
Simplify include/linux/dmar.h a bit based on the fact that both CONFIG_INTEL_IOMMU and CONFIG_IRQ_REMAP select CONFIG_DMAR_TABLE. Signed-off-by: Jiang Liu jiang@linux.intel.com --- include/linux/dmar.h | 50 ++ 1 file changed, 18

[Patch Part3 V4 09/21] iommu/vt-d: Change iommu_enable/disable_translation to return void

2014-07-11 Thread Jiang Liu
Simplify error handling path by changing iommu_{enable|disable}_translation to return void. Signed-off-by: Jiang Liu jiang@linux.intel.com --- drivers/iommu/intel-iommu.c | 18 +- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/drivers/iommu/intel-iommu.c

[Patch Part3 V4 11/21] iommu/vt-d: Introduce helper domain_pfn_within_range() to simplify code

2014-07-11 Thread Jiang Liu
Introduce helper function domain_pfn_within_range() to simplify code and improve readability. Signed-off-by: Jiang Liu jiang@linux.intel.com --- drivers/iommu/intel-iommu.c | 30 -- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git

[Patch Part3 V4 12/21] iommu/vt-d: Introduce helper function iova_size() to improve code readability

2014-07-11 Thread Jiang Liu
Signed-off-by: Jiang Liu jiang@linux.intel.com --- drivers/iommu/intel-iommu.c |7 +++ include/linux/iova.h|5 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index c9e65edaa2ad..cd1ba24c766a

[Patch Part3 V4 18/21] iommu/vt-d: Enhance intel_irq_remapping driver to support DMAR unit hotplug

2014-07-11 Thread Jiang Liu
Implement required callback functions for intel_irq_remapping driver to support DMAR unit hotplug. Signed-off-by: Jiang Liu jiang@linux.intel.com --- drivers/iommu/intel_irq_remapping.c | 222 ++- 1 file changed, 169 insertions(+), 53 deletions(-) diff --git

[Patch Part3 V4 16/21] iommu/vt-d: Implement DMAR unit hotplug framework

2014-07-11 Thread Jiang Liu
On Intel platforms, an IO Hub (PCI/PCIe host bridge) may contain DMAR units, so we need to support DMAR hotplug when supporting PCI host bridge hotplug on Intel platforms. According to Section 8.8 Remapping Hardware Unit Hot Plug in Intel Virtualization Technology for Directed IO Architecture

[Patch Part3 V4 06/21] iommu/vt-d: Fix possible invalid memory access caused by free_dmar_iommu()

2014-07-11 Thread Jiang Liu
Static identity and virtual machine domains may be cached in iommu-domain_ids array after corresponding IOMMUs have been removed from domain-iommu_bmp. So we should check domain-iommu_bmp before decreasing domain-iommu_count in function free_dmar_iommu(), otherwise it may cause free of inuse

[Patch Part3 V4 15/21] iommu/vt-d: Dynamically allocate and free seq_id for DMAR units

2014-07-11 Thread Jiang Liu
Introduce functions to support dynamic IOMMU seq_id allocating and releasing, which will be used to support DMAR hotplug. Also rename IOMMU_UNITS_SUPPORTED as DMAR_UNITS_SUPPORTED. Signed-off-by: Jiang Liu jiang@linux.intel.com --- drivers/iommu/dmar.c| 40

[Patch Part3 V4 07/21] iommu/vt-d: Avoid freeing virtual machine domain in free_dmar_iommu()

2014-07-11 Thread Jiang Liu
Virtual machine domains are created by intel_iommu_domain_init() and should be destroyed by intel_iommu_domain_destroy(). So avoid freeing virtual machine domain data structure in free_dmar_iommu() when doamin-iommu_count reaches zero, otherwise it may cause invalid memory access because the IOMMU

[Patch Part3 V4 17/21] iommu/vt-d: Search for ACPI _DSM method for DMAR hotplug

2014-07-11 Thread Jiang Liu
According to Intel VT-d specification, _DSM method to support DMAR hotplug should exist directly under corresponding ACPI object representing PCI host bridge. But some BIOSes doesn't conform to this, so search for _DSM method in the subtree starting from the ACPI object representing the PCI host

[Patch Part3 V4 10/21] iommu/vt-d: Simplify intel_unmap_sg() and kill duplicated code

2014-07-11 Thread Jiang Liu
Introduce intel_unmap() to reduce duplicated code in intel_unmap_sg() and intel_unmap_page(). Also let dma_pte_free_pagetable() to call dma_pte_clear_range() directly, so caller only needs to call dma_pte_free_pagetable(). Signed-off-by: Jiang Liu jiang@linux.intel.com ---

[Patch Part3 V4 14/21] iommu/vt-d: Introduce helper function dmar_walk_resources()

2014-07-11 Thread Jiang Liu
Introduce helper function dmar_walk_resources to walk resource entries in DMAR table and ACPI buffer object returned by ACPI _DSM method for IOMMU hot-plug. Signed-off-by: Jiang Liu jiang@linux.intel.com --- drivers/iommu/dmar.c| 208 +++

[Patch Part3 V4 20/21] iommu/vt-d: Enhance intel-iommu driver to support DMAR unit hotplug

2014-07-11 Thread Jiang Liu
Implement required callback functions for intel-iommu driver to support DMAR unit hotplug. Signed-off-by: Jiang Liu jiang@linux.intel.com --- drivers/iommu/intel-iommu.c | 206 +++ 1 file changed, 151 insertions(+), 55 deletions(-) diff --git

Re: [PATCH v2] devicetree: Add generic IOMMU device tree bindings

2014-07-11 Thread Will Deacon
On Thu, Jul 10, 2014 at 11:32:16PM +0100, Olav Haugan wrote: On 7/9/2014 3:54 AM, Will Deacon wrote: On Wed, Jul 09, 2014 at 02:07:38AM +0100, Olav Haugan wrote: So how does an algorithm figure this out in both my examples? The algorithm would have to know about both (all) bus masters and

Re: [PATCH 0/8] iommu/vt-d: Fix crash dump failure caused by legacy DMA/IO

2014-07-11 Thread Jerry Hoemann
On Wed, Jul 02, 2014 at 03:32:59PM +0200, Joerg Roedel wrote: Hi David, On Wed, Apr 30, 2014 at 11:49:33AM +0100, David Woodhouse wrote: There could be all kinds of existing mappings in the DMA page tables, and I'm not sure it's safe to preserve them. What prevents the crashdump kernel

Re: [PATCH v4] devicetree: Add generic IOMMU device tree bindings

2014-07-11 Thread Rob Clark
On Fri, Jul 4, 2014 at 11:29 AM, Thierry Reding thierry.red...@gmail.com wrote: From: Thierry Reding tred...@nvidia.com This commit introduces a generic device tree binding for IOMMU devices. Only a very minimal subset is described here, but it is enough to cover the requirements of both the