All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH kernel] powerpc/iommu: Fix iommu_table_in_use for a small default DMA window case
@ 2022-07-14  8:11 Alexey Kardashevskiy
  2022-07-29 13:02 ` Michael Ellerman
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey Kardashevskiy @ 2022-07-14  8:11 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Alexey Kardashevskiy, Leonardo Bras, Fabiano Rosas

The existing iommu_table_in_use() helper checks if the kernel is using
any of TCEs. There are some reserved TCEs:
1) the very first one if DMA window starts from 0 to avoid having a zero
but still valid DMA handle;
2) it_reserved_start..it_reserved_end to exclude MMIO32 window in case
the default window spans across that - this is the default for the first
DMA window on PowerNV.

When 1) is the case and 2) is not the helper does not skip 1) and returns
wrong status.

This only seems occurring when passing through a PCI device to a nested
guest (not something we support really well) so it has not been seen
before.

This fixes the bug by adding a special case for no MMIO32 reservation.

Fixes: 3c33066a2190 ("powerpc/kernel/iommu: Add new iommu_table_in_use() helper")
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
 arch/powerpc/kernel/iommu.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
index 7e56ddb3e0b9..caebe1431596 100644
--- a/arch/powerpc/kernel/iommu.c
+++ b/arch/powerpc/kernel/iommu.c
@@ -775,6 +775,11 @@ bool iommu_table_in_use(struct iommu_table *tbl)
 	/* ignore reserved bit0 */
 	if (tbl->it_offset == 0)
 		start = 1;
+
+	/* Simple case with no reserved MMIO32 region */
+	if (!tbl->it_reserved_start && !tbl->it_reserved_end)
+		return find_next_bit(tbl->it_map, tbl->it_size, start) != tbl->it_size;
+
 	end = tbl->it_reserved_start - tbl->it_offset;
 	if (find_next_bit(tbl->it_map, end, start) != end)
 		return true;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH kernel] powerpc/iommu: Fix iommu_table_in_use for a small default DMA window case
  2022-07-14  8:11 [PATCH kernel] powerpc/iommu: Fix iommu_table_in_use for a small default DMA window case Alexey Kardashevskiy
@ 2022-07-29 13:02 ` Michael Ellerman
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Ellerman @ 2022-07-29 13:02 UTC (permalink / raw)
  To: Alexey Kardashevskiy, linuxppc-dev; +Cc: Leonardo Bras, Fabiano Rosas

On Thu, 14 Jul 2022 18:11:19 +1000, Alexey Kardashevskiy wrote:
> The existing iommu_table_in_use() helper checks if the kernel is using
> any of TCEs. There are some reserved TCEs:
> 1) the very first one if DMA window starts from 0 to avoid having a zero
> but still valid DMA handle;
> 2) it_reserved_start..it_reserved_end to exclude MMIO32 window in case
> the default window spans across that - this is the default for the first
> DMA window on PowerNV.
> 
> [...]

Applied to powerpc/next.

[1/1] powerpc/iommu: Fix iommu_table_in_use for a small default DMA window case
      https://git.kernel.org/powerpc/c/d80f6de9d601c30b53c17f00cb7cfe3169f2ddad

cheers

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-29 13:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-14  8:11 [PATCH kernel] powerpc/iommu: Fix iommu_table_in_use for a small default DMA window case Alexey Kardashevskiy
2022-07-29 13:02 ` Michael Ellerman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.