[RFC v4 11/16] irqdomain: Add IRQ_DOMAIN_FLAG_MSI_REMAP value

2016-12-13 Thread Eric Auger
This new enum value aims at indicating whether the irq domain implements MSI remapping. This property is useful to assess the IRQ assignment safety at VFIO level. Signed-off-by: Eric Auger --- include/linux/irqdomain.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/irqdomai

[RFC v4 16/16] iommu/arm-smmu: Do not advertise IOMMU_CAP_INTR_REMAP anymore

2016-12-13 Thread Eric Auger
IOMMU_CAP_INTR_REMAP has been advertised in arm-smmu(-v3) although on ARM this property is not attached to the IOMMU but rather is implemented in the MSI controller (GICv3 ITS). Now vfio_iommu_type1 takes into account the MSI domain MSI remapping capability, let's correct this. Signed-off-by: Eri

[RFC v4 15/16] vfio/type1: Check MSI remapping at irq domain level

2016-12-13 Thread Eric Auger
In case the IOMMU does not bypass MSI transactions (typical case on ARM), we check all MSI controllers are IRQ remapping capable. If not the IRQ assignment may be unsafe. At this stage the arm-smmu-(v3) still advertise the IOMMU_CAP_INTR_REMAP capability at IOMMU level. This will be removed in sub

[RFC v4 14/16] vfio/type1: Allow transparent MSI IOVA allocation

2016-12-13 Thread Eric Auger
When attaching a group to the container, check the group's reserved regions and test whether the IOMMU translates MSI transactions. If yes, we initialize an IOVA allocator through the iommu_get_msi_cookie API. This will allow the MSI IOVAs to be transparently allocated on MSI controller's compose()

[RFC v4 12/16] irqdomain: irq_domain_check_msi_remap

2016-12-13 Thread Eric Auger
This new function checks whether all platform and PCI MSI domains implement IRQ remapping. This is useful to understand whether VFIO passthrough is safe with respect to interrupts. On ARM typically an MSI controller can sit downstream to the IOMMU without preventing VFIO passthrough. As such any a

[RFC v4 13/16] irqchip/gicv3-its: Sets IRQ_DOMAIN_FLAG_MSI_REMAP

2016-12-13 Thread Eric Auger
The GICv3 ITS is MSI remapping capable. Let's advertise this property so that VFIO passthrough can assess IRQ safety. Signed-off-by: Eric Auger --- drivers/irqchip/irq-gic-v3-its.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-i

[RFC v4 10/16] iommu/arm-smmu-v3: Implement reserved region get/put callbacks

2016-12-13 Thread Eric Auger
iommu/arm-smmu: Implement reserved region get/put callbacks The get() populates the list with the MSI IOVA reserved window. At the moment an arbitray MSI IOVA window is set at 0x800 of size 1MB. This will allow to report those info in iommu-group sysfs. Signed-off-by: Eric Auger --- v4: c

[RFC v4 08/16] iommu/vt-d: Implement reserved region get/put callbacks

2016-12-13 Thread Eric Auger
This patch registers the [0xfee0 - 0xfeef] 1MB MSI range as a reserved region. This will allow to report that range in the iommu-group sysfs. Signed-off-by: Eric Auger --- RFCv2 -> RFCv3: - use get/put_resv_region callbacks. RFC v1 -> RFC v2: - fix intel_iommu_add_reserved_regions name

[RFC v4 09/16] iommu/arm-smmu: Implement reserved region get/put callbacks

2016-12-13 Thread Eric Auger
The get() populates the list with the MSI IOVA reserved window. At the moment an arbitray MSI IOVA window is set at 0x800 of size 1MB. This will allow to report those info in iommu-group sysfs. Signed-off-by: Eric Auger --- v3 -> v4: - do not handle PCI host bridge windows anymore - encode

[RFC v4 06/16] iommu: iommu_get_group_resv_regions

2016-12-13 Thread Eric Auger
Introduce iommu_get_group_resv_regions whose role consists in enumerating all devices from the group and collecting their reserved regions. The list is sorted and overlaps are checked. Signed-off-by: Eric Auger --- v3 -> v4: - take the iommu_group lock in iommu_get_group_resv_regions - the list

[RFC v4 07/16] iommu: Implement reserved_regions iommu-group sysfs file

2016-12-13 Thread Eric Auger
A new iommu-group sysfs attribute file is introduced. It contains the list of reserved regions for the iommu-group. Each reserved region is described on a separate line: - first field is the start IOVA address, - second is the end IOVA address, Signed-off-by: Eric Auger --- v3 -> v4: - add cast

[RFC v4 04/16] iommu: iommu_alloc_resv_region

2016-12-13 Thread Eric Auger
Introduce a new helper serving the purpose to allocate a reserved region. This will be used in iommu driver implementing reserved region callbacks. Signed-off-by: Eric Auger --- v3 -> v4: - add INIT_LIST_HEAD(®ion->list) - use int for prot param and add int type param - remove implementation ou

[RFC v4 02/16] iommu: Rename iommu_dm_regions into iommu_resv_regions

2016-12-13 Thread Eric Auger
We want to extend the callbacks used for dm regions and use them for reserved regions. Reserved regions can be - directly mapped regions - regions that cannot be iommu mapped (PCI host bridge windows, ...) - MSI regions (because they belong to another address space or because they are not transla

[RFC v4 01/16] iommu/dma: Allow MSI-only cookies

2016-12-13 Thread Eric Auger
IOMMU domain users such as VFIO face a similar problem to DMA API ops with regard to mapping MSI messages in systems where the MSI write is subject to IOMMU translation. With the relevant infrastructure now in place for managed DMA domains, it's actually really simple for other users to piggyback o

[RFC v4 03/16] iommu: Add a new type field in iommu_resv_region

2016-12-13 Thread Eric Auger
We introduce a new field to differentiate the reserved region types and specialize the apply_resv_region implementation. Legacy direct mapped regions have IOMMU_RESV_DIRECT type. We introduce 2 new reserved memory types: - IOMMU_RESV_MSI will characterize MSI regions - IOMMU_RESV_NOMAP characteriz

[RFC v4 05/16] iommu: Only map direct mapped regions

2016-12-13 Thread Eric Auger
As we introduced new reserved region types which do not require mapping, let's make sure we only map direct mapped regions. Signed-off-by: Eric Auger --- v3 -> v4: - use region's type and reword commit message and title --- drivers/iommu/iommu.c | 3 +++ 1 file changed, 3 insertions(+) diff -

[RFC v4 00/16] KVM PCIe/MSI passthrough on ARM/ARM64 and IOVA reserved regions

2016-12-13 Thread Eric Auger
Following LPC discussions, we now report reserved regions through iommu-group sysfs reserved_regions attribute file. Reserved regions are populated through the IOMMU get_resv_region callback (former get_dm_regions), now implemented by amd-iommu, intel-iommu and arm-smmu: - the amd-iommu reports de

Re: [PATCH V7 5/8] arm64/dma-mapping: Implement DMA_ATTR_PRIVILEGED

2016-12-13 Thread Robin Murphy
ize, >>>>> - dma_direction_to_prot(dir, false) | IOMMU_MMIO); >>>>> + dma_info_to_prot(dir, false, attrs) | IOMMU_MMIO); >>>>> } >>>>> >>>>> void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle, &

RE: [PATCH V7 5/8] arm64/dma-mapping: Implement DMA_ATTR_PRIVILEGED

2016-12-13 Thread Sricharan
+ dma_info_to_prot(dir, false, attrs) | IOMMU_MMIO); >>>> } >>>> >>>> void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle, >>>> >>>> With those two issues fixed up, I've given the series (applied to >>>

RE: [PATCH V7 5/8] arm64/dma-mapping: Implement DMA_ATTR_PRIVILEGED

2016-12-13 Thread Sricharan
-coherent? >>>> + * @attrs: DMA attributes for the mapping >>>> * >>>> * Return: corresponding IOMMU API page protection flags >>>> */ >>>> -int dma_direction_to_prot(enum dma_data_direction dir, bool coherent) >>>> +int dma_info_t

Re: [PATCH V7 5/8] arm64/dma-mapping: Implement DMA_ATTR_PRIVILEGED

2016-12-13 Thread Robin Murphy
t;> +unsigned long attrs) >>> { >>> int prot = coherent ? IOMMU_CACHE : 0; >>> >>> + if (attrs & DMA_ATTR_PRIVILEGED) >>> + prot |= IOMMU_PRIV; >>> + >>> switch (dir) { >>> case DMA_BIDIREC

RE: [PATCH V7 5/8] arm64/dma-mapping: Implement DMA_ATTR_PRIVILEGED

2016-12-13 Thread Sricharan
? IOMMU_CACHE : 0; >> >> +if (attrs & DMA_ATTR_PRIVILEGED) >> +prot |= IOMMU_PRIV; >> + >> switch (dir) { >> case DMA_BIDIRECTIONAL: >> return prot | IOMMU_READ | IOMMU_WRITE; > >...and applying against -next now also

Re: [PATCH V7 5/8] arm64/dma-mapping: Implement DMA_ATTR_PRIVILEGED

2016-12-13 Thread Robin Murphy
mu_dma_map_resource(struct device *dev, phys_addr_t phys, size_t size, enum dma_data_direction dir, unsigned long attrs) { return __iommu_dma_map(dev, phys, size, - dma_direction_to_prot(dir, false) | IOMMU_MMIO); + dma_info_to_prot(dir, fal

Re: [PATCH V7 4/8] common: DMA-mapping: add DMA_ATTR_PRIVILEGED attribute

2016-12-13 Thread Robin Murphy
On 12/12/16 18:38, Sricharan R wrote: > From: Mitchel Humpherys > > This patch adds the DMA_ATTR_PRIVILEGED attribute to the DMA-mapping > subsystem. > > Some advanced peripherals such as remote processors and GPUs perform > accesses to DMA buffers in both privileged "supervisor" and unprivilege

Re: [PATCH V7 7/8] iommu/arm-smmu: Set privileged attribute to 'default' instead of 'unprivileged'

2016-12-13 Thread Robin Murphy
On 12/12/16 18:38, Sricharan R wrote: > Currently the driver sets all the device transactions privileges > to UNPRIVILEGED, but there are cases where the iommu masters wants > to isolate privileged supervisor and unprivileged user. > So don't override the privileged setting to unprivileged, instead