powerpc/iommu: TCEs are incorrectly manipulated with DLPAR add/remove of memory
authorGaurav Batra <gbatra@linux.vnet.ibm.com>
Tue, 13 Jun 2023 17:16:41 +0000 (12:16 -0500)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 26 Jun 2023 04:57:31 +0000 (14:57 +1000)
commitd61cd13e732c0eaa7d66b45edb2d0de8eab65a1e
treed963c5d50e6222c8d3d5d57cef0670d6cfbd144a
parentbfd8d989210cb6bb1c8e87b7c525831dceb91418
powerpc/iommu: TCEs are incorrectly manipulated with DLPAR add/remove of memory

When memory is dynamically added/removed, iommu_mem_notifier() is invoked. This
routine traverses through all the DMA windows (DDW only, not default windows)
to add/remove "direct" TCE mappings. The routines for this purpose are
tce_clearrange_multi_pSeriesLP() and tce_clearrange_multi_pSeriesLP().

Both these routines are designed for Direct mapped DMA windows only.

The issue is that there could be some DMA windows in the list which are not
"direct" mapped. Calling these routines will either,

1) remove some dynamically mapped TCEs, Or
2) try to add TCEs which are out of bounds and HCALL returns H_PARAMETER

Here are the side affects when these routines are incorrectly invoked for
"dynamically" mapped DMA windows.

tce_setrange_multi_pSeriesLP()

This adds direct mapped TCEs. Now, this could invoke HCALL to add TCEs with
out-of-bound range. In this scenario, HCALL will return H_PARAMETER and DLAR
ADD of memory will fail.

tce_clearrange_multi_pSeriesLP()

This will remove range of TCEs. The TCE range that is calculated, depending on
the memory range being added, could infact be mapping some other memory
address (for dynamic DMA window scenario). This will wipe out those TCEs.

The solution is for iommu_mem_notifier() to only invoke these routines for
"direct" mapped DMA windows.

Signed-off-by: Gaurav Batra <gbatra@linux.vnet.ibm.com>
Reviewed-by: Brian King <brking@linux.vnet.ibm.com>
[mpe: Initialise direct at allocation time in ddw_list_new_entry()]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20230613171641.15641-1-gbatra@linux.vnet.ibm.com
arch/powerpc/platforms/pseries/iommu.c