Re: [PATCH v6 04/11] bus: platform,amba,fsl-mc,PCI: Add device DMA ownership management

2022-02-17 Thread Greg Kroah-Hartman
On Fri, Feb 18, 2022 at 08:55:14AM +0800, Lu Baolu wrote: > The devices on platform/amba/fsl-mc/PCI buses could be bound to drivers > with the device DMA managed by kernel drivers or user-space applications. > Unfortunately, multiple devices may be placed in the same IOMMU group > because they

Re: [PATCH 2/2] iommu/mediatek: Add mt8186 iommu support

2022-02-17 Thread Yong Wu via iommu
On Mon, 2022-01-31 at 10:25 +0100, AngeloGioacchino Del Regno wrote: > Il 28/01/22 10:39, Yong Wu ha scritto: > > On Thu, 2022-01-27 at 12:28 +0100, AngeloGioacchino Del Regno > > wrote: > > > Il 25/01/22 10:32, Yong Wu ha scritto: > > > > Add mt8186 iommu supports. > > > > > > > > Signed-off-by:

Re: [PATCH] iommu/vt-d: Enable ATS for the devices in SATC table

2022-02-17 Thread Lu Baolu
Hi Yian, On 2/17/22 3:36 AM, Yian Chen wrote: Starting from Intel VT-d v3.2, Intel platform BIOS can provide additional SATC table structure. SATC table includes a list of SoC integrated devices that support ATC (Address translation cache). Enabling ATC (via ATS capability) can be a functional

Re: [PATCH v2 1/1] iommu/vt-d: Fix list_add double add when enabling VMD and scalable mode

2022-02-17 Thread Lu Baolu
On 2/16/22 5:13 PM, Adrian Huang wrote: pci_real_dma_dev() in pci_for_each_dma_alias() gets the real dma device which is the VMD device :59:00.5. However, pte of the VMD device :59:00.5 has been configured during this message "pci :59:00.5: Adding to iommu group 42". So, the status

Re: [PATCH v5 00/14] Fix BUG_ON in vfio_iommu_group_notifier()

2022-02-17 Thread Lu Baolu
On 1/4/22 9:56 AM, Lu Baolu wrote: Hi folks, The iommu group is the minimal isolation boundary for DMA. Devices in a group can access each other's MMIO registers via peer to peer DMA and also need share the same I/O address space. Once the I/O address space is assigned to user control it is no

[PATCH v6 01/11] iommu: Add dma ownership management interfaces

2022-02-17 Thread Lu Baolu
Multiple devices may be placed in the same IOMMU group because they cannot be isolated from each other. These devices must either be entirely under kernel control or userspace control, never a mixture. This adds dma ownership management in iommu core and exposes several interfaces for the device

[PATCH v6 08/11] vfio: Remove use of vfio_group_viable()

2022-02-17 Thread Lu Baolu
As DMA ownership is claimed for the iommu group when a VFIO group is added to a VFIO container, the VFIO group viability is guaranteed as long as group->container_users > 0. Remove those unnecessary group viability checks which are only hit when group->container_users is not zero. The only

[PATCH v6 03/11] amba: Stop sharing platform_dma_configure()

2022-02-17 Thread Lu Baolu
Stop sharing platform_dma_configure() helper as they are about to have their own bus dma_configure callbacks. Signed-off-by: Lu Baolu --- include/linux/platform_device.h | 2 -- drivers/amba/bus.c | 19 ++- drivers/base/platform.c | 3 +-- 3 files changed,

[PATCH v6 11/11] iommu: Remove iommu group changes notifier

2022-02-17 Thread Lu Baolu
The iommu group changes notifer is not referenced in the tree. Remove it to avoid dead code. Suggested-by: Christoph Hellwig Signed-off-by: Lu Baolu --- include/linux/iommu.h | 23 - drivers/iommu/iommu.c | 75 --- 2 files changed, 98

[PATCH v6 10/11] vfio: Remove iommu group notifier

2022-02-17 Thread Lu Baolu
The iommu core and driver core have been enhanced to avoid unsafe driver binding to a live group after iommu_group_set_dma_owner(PRIVATE_USER) has been called. There's no need to register iommu group notifier. This removes the iommu group notifer which contains BUG_ON() and WARN(). The commit

[PATCH v6 00/11] Fix BUG_ON in vfio_iommu_group_notifier()

2022-02-17 Thread Lu Baolu
Hi folks, The iommu group is the minimal isolation boundary for DMA. Devices in a group can access each other's MMIO registers via peer to peer DMA and also need share the same I/O address space. Once the I/O address space is assigned to user control it is no longer available to the dma_map*

[PATCH v6 07/11] vfio: Set DMA ownership for VFIO devices

2022-02-17 Thread Lu Baolu
Claim group dma ownership when an IOMMU group is set to a container, and release the dma ownership once the iommu group is unset from the container. Signed-off-by: Lu Baolu --- drivers/vfio/fsl-mc/vfio_fsl_mc.c | 1 + drivers/vfio/pci/vfio_pci.c | 1 +

[PATCH v6 06/11] PCI: portdrv: Set driver_managed_dma

2022-02-17 Thread Lu Baolu
If a switch lacks ACS P2P Request Redirect, a device below the switch can bypass the IOMMU and DMA directly to other devices below the switch, so all the downstream devices must be in the same IOMMU group as the switch itself. The existing VFIO framework allows the portdrv driver to be bound to

[PATCH v6 02/11] driver core: Add dma_cleanup callback in bus_type

2022-02-17 Thread Lu Baolu
The bus_type structure defines dma_configure() callback for bus drivers to configure DMA on the devices. This adds the paired dma_cleanup() callback and calls it during driver unbinding so that bus drivers can do some cleanup work. One use case for this paired DMA callbacks is for the bus driver

[PATCH v6 04/11] bus: platform, amba, fsl-mc, PCI: Add device DMA ownership management

2022-02-17 Thread Lu Baolu
The devices on platform/amba/fsl-mc/PCI buses could be bound to drivers with the device DMA managed by kernel drivers or user-space applications. Unfortunately, multiple devices may be placed in the same IOMMU group because they cannot be isolated from each other. The DMA on these devices must

[PATCH v6 09/11] vfio: Delete the unbound_list

2022-02-17 Thread Lu Baolu
From: Jason Gunthorpe commit 60720a0fc646 ("vfio: Add device tracking during unbind") added the unbound list to plug a problem with KVM where KVM_DEV_VFIO_GROUP_DEL relied on vfio_group_get_external_user() succeeding to return the vfio_group from a group file descriptor. The unbound list allowed

[PATCH v6 05/11] PCI: pci_stub: Set driver_managed_dma

2022-02-17 Thread Lu Baolu
The current VFIO implementation allows pci-stub driver to be bound to a PCI device with other devices in the same IOMMU group being assigned to userspace. The pci-stub driver has no dependencies on DMA or the IOVA mapping of the device, but it does prevent the user from having direct access to the

[PATCH v5 34/34] iommu/mediatek: mt8195: Enable multi banks for infra iommu

2022-02-17 Thread Yong Wu via iommu
Enable the multi-bank functions for infra-iommu. We put PCIE in bank0 and USB in the last bank(bank4). and we don't use the other banks currently, disable them. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 7 +-- 1 file changed, 5

[PATCH v5 33/34] iommu/mediatek: Backup/restore regsiters for multi banks

2022-02-17 Thread Yong Wu via iommu
Each bank has some independent registers. thus backup/restore them for each a bank when suspend and resume. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 46 ++- 1 file changed, 31 insertions(+), 15

[PATCH v5 32/34] iommu/mediatek: Initialise/Remove for multi bank dev

2022-02-17 Thread Yong Wu via iommu
The registers for each bank of the IOMMU base are in order, delta is 0x1000. Initialise the base for each bank. For all the previous SoC, we only have bank0. thus use "do {} while()" to allow bank0 always go. When removing the device, Not always all the banks are initialised, it depend on if

[PATCH v5 31/34] iommu/mediatek: Get the proper bankid for multi banks

2022-02-17 Thread Yong Wu via iommu
We preassign some ports in a special bank via the new defined banks_portmsk. Put it in the plat_data means it is not expected to be adjusted dynamically. If the iommu id in the iommu consumer's dtsi node is inside this banks_portmsk, then we switch it to this special iommu bank, and initialise

[PATCH v5 30/34] iommu/mediatek: Change the domid to iova_region_id

2022-02-17 Thread Yong Wu via iommu
Prepare for adding bankid, also no functional change. In the previous SoC, each a iova_region is a domain; In the multi-banks case, each a bank is a domain, then the original function name "mtk_iommu_get_domain_id" is not proper. Use "iova_region_id" instead of "domain_id". Signed-off-by: Yong

[PATCH v5 29/34] iommu/mediatek: Initialise bank HW for each a bank

2022-02-17 Thread Yong Wu via iommu
The mt8195 IOMMU HW max support 5 banks, and regarding the banks' registers, it looks like: |bank0 | bank1 | bank2 | bank3 | bank4| |global | |control| null |regs |

[PATCH v5 28/34] iommu/mediatek: Add mtk_iommu_bank_data structure

2022-02-17 Thread Yong Wu via iommu
Prepare for supporting multi-banks for the IOMMU HW, No functional change. Add a new structure(mtk_iommu_bank_data) for each a bank. Each a bank have the independent HW base/IRQ/tlb-range ops, and each a bank has its special iommu-domain(independent pgtable), thus, also move the domain

[PATCH v5 27/34] iommu/mediatek-v1: Just rename mtk_iommu to mtk_iommu_v1

2022-02-17 Thread Yong Wu via iommu
No functional change. Just rename this for readable. Differentiate this from mtk_iommu.c Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu_v1.c | 211 +-- 1 file changed, 103 insertions(+), 108 deletions(-) diff --git a/drivers/iommu/mtk_iommu_v1.c

[PATCH v5 26/34] iommu/mediatek: Remove mtk_iommu.h

2022-02-17 Thread Yong Wu via iommu
Currently there is only compare_of/release_of/a suspend structure in the header file. I think it is no need to keep a header file only for these. Move these into the c file and rm this header file. I think there should be a common helper for compare_of and release_of. There is many copy in drm,

[PATCH v5 25/34] iommu/mediatek: Separate mtk_iommu_data for v1 and v2

2022-02-17 Thread Yong Wu via iommu
Prepare for adding the structure "mtk_iommu_bank_data". No functional change. The mtk_iommu_domain in v1 and v2 are different, we could not add current data as bank[0] in v1 simplistically. Currently we have no plan to add new SoC for v1, in order to avoid affect v1 when we add many new features

[PATCH v5 24/34] iommu/mediatek: Just move code position in hw_init

2022-02-17 Thread Yong Wu via iommu
No functional change too, prepare for mt8195 IOMMU support bank functions. Some global control settings are in bank0 while the other banks have their bank independent setting. Here only move the global control settings and the independent registers together. Signed-off-by: Yong Wu Reviewed-by:

[PATCH v5 23/34] iommu/mediatek: Only adjust code about register base

2022-02-17 Thread Yong Wu via iommu
No functional change. Use "base" instead of the data->base. This is avoid to touch too many lines in the next patches. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 51 +-- 1 file changed, 27 insertions(+),

[PATCH v5 22/34] iommu/mediatek: Add mt8195 support

2022-02-17 Thread Yong Wu via iommu
mt8195 has 3 IOMMU, containing 2 MM IOMMUs, one is for vdo, the other is for vpp. and 1 INFRA IOMMU. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 43 +++ drivers/iommu/mtk_iommu.h | 1 + 2 files changed, 44

[PATCH v5 21/34] iommu/mediatek: Add PCIe support

2022-02-17 Thread Yong Wu via iommu
Currently the code for of_iommu_configure_dev_id is like this: static int of_iommu_configure_dev_id(struct device_node *master_np, struct device *dev, const u32 *id) { struct of_phandle_args iommu_spec = {

[PATCH v5 20/34] iommu/mediatek: Add infra iommu support

2022-02-17 Thread Yong Wu via iommu
The infra iommu enable bits in mt8195 is in the pericfg register segment, use regmap to update it. If infra iommu master translation fault, It doesn't have the larbid/portid, thus print out the whole register value. Since regmap_update_bits may fail, add return value for mtk_iommu_config.

[PATCH v5 19/34] iommu/mediatek: Add a PM_CLK_AO flag for infra iommu

2022-02-17 Thread Yong Wu via iommu
The power/clock of infra iommu is always on, and it doesn't have the device link with the master devices, then the infra iommu device's pm statua is not active, thus we add A PM_CLK_AO flag for infra iommu. The tlb operation is a bit not clear in this file, Comment them in the code here.

[PATCH v5 18/34] iommu/mediatek: Allow IOMMU_DOMAIN_UNMANAGED for PCIe VFIO

2022-02-17 Thread Yong Wu via iommu
Allow the type IOMMU_DOMAIN_UNMANAGED since vfio_iommu_type1.c always call iommu_domain_alloc. The PCIe EP works ok when going through vfio. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff

[PATCH v5 17/34] iommu/mediatek: Adjust device link when it is sub-common

2022-02-17 Thread Yong Wu via iommu
For MM IOMMU, We always add device link between smi-common and IOMMU HW. In mt8195, we add smi-sub-common. Thus, if the node is sub-common, we still need find again to get smi-common, then do device link. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno ---

[PATCH v5 16/34] iommu/mediatek: Contain MM IOMMU flow with the MM TYPE

2022-02-17 Thread Yong Wu via iommu
Prepare for supporting INFRA_IOMMU, and APU_IOMMU later. For Infra IOMMU/APU IOMMU, it doesn't have the "larb""port". thus, Use the MM flag contain the MM_IOMMU special flow, Also, it moves a big chunk code about parsing the mediatek,larbs into a function, this is only needed for MM IOMMU. and

[PATCH v5 15/34] iommu/mediatek: Add IOMMU_TYPE flag

2022-02-17 Thread Yong Wu via iommu
Add IOMMU_TYPE definition. In the mt8195, we have another IOMMU_TYPE: infra iommu, also there will be another APU_IOMMU, thus, use 2bits for the IOMMU_TYPE. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 12 ++-- 1 file changed, 10

[PATCH v5 14/34] iommu/mediatek: Add SUB_COMMON_3BITS flag

2022-02-17 Thread Yong Wu via iommu
In prevous SoC, the sub common id occupy 2 bits. the mt8195's sub common id has 3bits. Add a new flag for this. and rename the previous flag to _2BITS. For readable, I put these two flags together, then move the other flags. no functional change. Signed-off-by: Yong Wu Reviewed-by:

[PATCH v5 13/34] iommu/mediatek: Always enable output PA over 32bits in isr

2022-02-17 Thread Yong Wu via iommu
Currently the output PA[32:33] is contained by the flag IOVA_34. This is not right. the iova_34 has no relation with pa[32:33], the 32bits iova still could map to pa[32:33]. Move it out from the flag. No need fix tag since currently only mt8192 use the calulation and it always has this IOVA_34

[PATCH v5 12/34] iommu/mediatek: Remove the granule in the tlb flush

2022-02-17 Thread Yong Wu via iommu
The MediaTek IOMMU don't care about granule when tlb flushing. Remove this variable. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c

[PATCH v5 11/34] iommu/mediatek: Add a flag NON_STD_AXI

2022-02-17 Thread Yong Wu via iommu
Add a new flag NON_STD_AXI, All the previous SoC support this flag. Prepare for adding infra and apu iommu which don't support this. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 16 ++-- 1 file changed, 10 insertions(+), 6

[PATCH v5 10/34] iommu/mediatek: Add a flag DCM_DISABLE

2022-02-17 Thread Yong Wu via iommu
In the infra iommu, we should disable DCM. add a new flag for this. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c | 9 - 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c

[PATCH v5 09/34] iommu/mediatek: Add 12G~16G support for multi domains

2022-02-17 Thread Yong Wu via iommu
In mt8192, we preassign 0-4G; 4G-8G; 8G-12G for different multimedia engines. This depends on the "dma-ranges=" in the iommu consumer's dtsi node. Adds 12G-16G region here. and reword the previous comment. we don't limit which master locate in which region. CCU still is 8G-12G. Don't change it

[PATCH v5 08/34] iommu/mediatek: Adapt sharing and non-sharing pgtable case

2022-02-17 Thread Yong Wu via iommu
In previous mt2712, Both IOMMUs are MM IOMMU, and they will share pgtable. However in the latest SoC, another is infra IOMMU, there is no reason to share pgtable between MM with INFRA IOMMU. This patch manage to implement the two case(sharing and non-sharing pgtable). Currently we use

[PATCH v5 07/34] iommu/mediatek: Add mutex for data in the mtk_iommu_domain

2022-02-17 Thread Yong Wu via iommu
Same with the previous patch, add a mutex for the "data" in the mtk_iommu_domain. Just improve the safety for multi devices enter attach_device at the same time. We don't get the real issue for this. Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu.c

[PATCH v5 06/34] iommu/mediatek: Add mutex for m4u_group and m4u_dom in data

2022-02-17 Thread Yong Wu via iommu
Add a mutex to protect the data in the structure mtk_iommu_data, like ->"m4u_group" ->"m4u_dom". For the internal data, we should protect it in ourselves driver. Add a mutex for this. This could be a fix for the multi-groups support. Fixes: c3045f39244e ("iommu/mediatek: Support for multi

[PATCH v5 05/34] iommu/mediatek: Remove clk_disable in mtk_iommu_remove

2022-02-17 Thread Yong Wu via iommu
After the commit b34ea31fe013 ("iommu/mediatek: Always enable the clk on resume"), the iommu clock is controlled by the runtime callback. thus remove the clk control in the mtk_iommu_remove. Otherwise, it will warning like: echo 14018000.iommu > /sys/bus/platform/drivers/mtk-iommu/unbind [

[PATCH v5 04/34] iommu/mediatek: Add list_del in mtk_iommu_remove

2022-02-17 Thread Yong Wu via iommu
Lack the list_del in the mtk_iommu_remove, and remove bus_set_iommu(*, NULL) since there may be several iommu HWs. we can not bus_set_iommu null when one iommu driver unbind. This could be a fix for mt2712 which support 2 M4U HW and list them. Fixes: 7c3a2ec02806 ("iommu/mediatek: Merge 2 M4U

[PATCH v5 03/34] iommu/mediatek: Fix 2 HW sharing pgtable issue

2022-02-17 Thread Yong Wu via iommu
In the commit 4f956c97d26b ("iommu/mediatek: Move domain_finalise into attach_device"), I overlooked the sharing pgtable case. After that commit, the "data" in the mtk_iommu_domain_finalise always is the data of the current IOMMU HW. Fix this for the sharing pgtable case. Only affect mt2712 which

[PATCH v5 02/34] dt-bindings: mediatek: mt8195: Add binding for infra IOMMU

2022-02-17 Thread Yong Wu via iommu
In mt8195, we have a new IOMMU that is for INFRA IOMMU. its masters mainly are PCIe and USB. Different with MM IOMMU, all these masters connect with IOMMU directly, there is no mediatek,larbs property for infra IOMMU. Another thing is about PCIe ports. currently the function

[PATCH v5 01/34] dt-bindings: mediatek: mt8195: Add binding for MM IOMMU

2022-02-17 Thread Yong Wu via iommu
This patch adds descriptions for mt8195 IOMMU which also use ARM Short-Descriptor translation table format. In mt8195, there are two smi-common HW and IOMMU, one is for vdo(video output), the other is for vpp(video processing pipe). They connects with different smi-larbs, then some

[PATCH v5 00/34] MT8195 IOMMU SUPPORT

2022-02-17 Thread Yong Wu via iommu
This patchset adds MT8195 iommu support. MT8195 have 3 IOMMU HWs. 2 IOMMU HW is for multimedia, and 1 IOMMU HW is for infra-master, like PCIe/USB. About the 2 MM IOMMU HW, something like this: IOMMU(VDO) IOMMU(VPP) | | SMI_COMMON(VDO)