<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/arch/powerpc/kernel/iommu.c, branch linux-5.13.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.13.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.13.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2021-06-01T01:17:08Z</updated>
<entry>
<title>Revert "powerpc/kernel/iommu: Align size for IOMMU_PAGE_SIZE() to save TCEs"</title>
<updated>2021-06-01T01:17:08Z</updated>
<author>
<name>Frederic Barrat</name>
</author>
<published>2021-05-26T14:45:40Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=59cc84c802eb923805e7bba425976a3df5ce35d8'/>
<id>urn:sha1:59cc84c802eb923805e7bba425976a3df5ce35d8</id>
<content type='text'>
This reverts commit 3c0468d4451eb6b4f6604370639f163f9637a479.

That commit was breaking alignment guarantees for the DMA address when
allocating coherent mappings, as described in
Documentation/core-api/dma-api-howto.rst

It was also noticed by Mellanox' driver:
[ 1515.763621] mlx5_core c002:01:00.0: mlx5_frag_buf_alloc_node:146:(pid 13402): unexpected map alignment: 0x0800000000c61000, page_shift=16
[ 1515.763635] mlx5_core c002:01:00.0: mlx5_cqwq_create:181:(pid
13402): mlx5_frag_buf_alloc_node() failed, -12

Fixes: 3c0468d4451e ("powerpc/kernel/iommu: Align size for  IOMMU_PAGE_SIZE() to save TCEs")
Signed-off-by: Frederic Barrat &lt;fbarrat@linux.ibm.com&gt;
Reviewed-by: Alexey Kardashevskiy &lt;aik@ozlabs.ru&gt;
Signed-off-by: Michael Ellerman &lt;mpe@ellerman.id.au&gt;
Link: https://lore.kernel.org/r/20210526144540.117795-1-fbarrat@linux.ibm.com

</content>
</entry>
<entry>
<title>powerpc/kernel/iommu: Use largepool as a last resort when !largealloc</title>
<updated>2021-04-23T02:54:58Z</updated>
<author>
<name>Leonardo Bras</name>
</author>
<published>2021-03-18T17:44:17Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=fc5590fd56c9608f317729b59a56dad2a75d633f'/>
<id>urn:sha1:fc5590fd56c9608f317729b59a56dad2a75d633f</id>
<content type='text'>
As of today, doing iommu_range_alloc() only for !largealloc (npages &lt;= 15)
will only be able to use 3/4 of the available pages, given pages on
largepool  not being available for !largealloc.

This could mean some drivers not being able to fully use all the available
pages for the DMA window.

Add pages on largepool as a last resort for !largealloc, making all pages
of the DMA window available.

Signed-off-by: Leonardo Bras &lt;leobras.c@gmail.com&gt;
Reviewed-by: Alexey Kardashevskiy &lt;aik@ozlabs.ru&gt;
Signed-off-by: Michael Ellerman &lt;mpe@ellerman.id.au&gt;
Link: https://lore.kernel.org/r/20210318174414.684630-2-leobras.c@gmail.com

</content>
</entry>
<entry>
<title>powerpc/kernel/iommu: Align size for IOMMU_PAGE_SIZE() to save TCEs</title>
<updated>2021-04-23T02:54:50Z</updated>
<author>
<name>Leonardo Bras</name>
</author>
<published>2021-03-18T17:44:14Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=3c0468d4451eb6b4f6604370639f163f9637a479'/>
<id>urn:sha1:3c0468d4451eb6b4f6604370639f163f9637a479</id>
<content type='text'>
Currently both iommu_alloc_coherent() and iommu_free_coherent() align the
desired allocation size to PAGE_SIZE, and gets system pages and IOMMU
mappings (TCEs) for that value.

When IOMMU_PAGE_SIZE &lt; PAGE_SIZE, this behavior may cause unnecessary
TCEs to be created for mapping the whole system page.

Example:
- PAGE_SIZE = 64k, IOMMU_PAGE_SIZE() = 4k
- iommu_alloc_coherent() is called for 128 bytes
- 1 system page (64k) is allocated
- 16 IOMMU pages (16 x 4k) are allocated (16 TCEs used)

It would be enough to use a single TCE for this, so 15 TCEs are
wasted in the process.

Update iommu_*_coherent() to make sure the size alignment happens only
for IOMMU_PAGE_SIZE() before calling iommu_alloc() and iommu_free().

Also, on iommu_range_alloc(), replace ALIGN(n, 1 &lt;&lt; tbl-&gt;it_page_shift)
with IOMMU_PAGE_ALIGN(n, tbl), which is easier to read and does the
same.

Signed-off-by: Leonardo Bras &lt;leobras.c@gmail.com&gt;
Reviewed-by: Alexey Kardashevskiy &lt;aik@ozlabs.ru&gt;
Signed-off-by: Michael Ellerman &lt;mpe@ellerman.id.au&gt;
Link: https://lore.kernel.org/r/20210318174414.684630-1-leobras.c@gmail.com

</content>
</entry>
<entry>
<title>powerpc/iommu: Annotate nested lock for lockdep</title>
<updated>2021-04-22T15:38:04Z</updated>
<author>
<name>Alexey Kardashevskiy</name>
</author>
<published>2021-03-01T06:36:53Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=cc7130bf119add37f36238343a593b71ef6ecc1e'/>
<id>urn:sha1:cc7130bf119add37f36238343a593b71ef6ecc1e</id>
<content type='text'>
The IOMMU table is divided into pools for concurrent mappings and each
pool has a separate spinlock. When taking the ownership of an IOMMU group
to pass through a device to a VM, we lock these spinlocks which triggers
a false negative warning in lockdep (below).

This fixes it by annotating the large pool's spinlock as a nest lock
which makes lockdep not complaining when locking nested locks if
the nest lock is locked already.

===
WARNING: possible recursive locking detected
5.11.0-le_syzkaller_a+fstn1 #100 Not tainted
--------------------------------------------
qemu-system-ppc/4129 is trying to acquire lock:
c0000000119bddb0 (&amp;(p-&gt;lock)/1){....}-{2:2}, at: iommu_take_ownership+0xac/0x1e0

but task is already holding lock:
c0000000119bdd30 (&amp;(p-&gt;lock)/1){....}-{2:2}, at: iommu_take_ownership+0xac/0x1e0

other info that might help us debug this:
 Possible unsafe locking scenario:

       CPU0
       ----
  lock(&amp;(p-&gt;lock)/1);
  lock(&amp;(p-&gt;lock)/1);
===

Signed-off-by: Alexey Kardashevskiy &lt;aik@ozlabs.ru&gt;
Signed-off-by: Michael Ellerman &lt;mpe@ellerman.id.au&gt;
Link: https://lore.kernel.org/r/20210301063653.51003-1-aik@ozlabs.ru

</content>
</entry>
<entry>
<title>powerpc/iommu: Do not immediately panic when failed IOMMU table allocation</title>
<updated>2021-04-22T15:38:04Z</updated>
<author>
<name>Alexey Kardashevskiy</name>
</author>
<published>2021-02-16T03:33:07Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=4be518d838809e21354f32087aa9c26efc50b410'/>
<id>urn:sha1:4be518d838809e21354f32087aa9c26efc50b410</id>
<content type='text'>
Most platforms allocate IOMMU table structures (specifically it_map)
at the boot time and when this fails - it is a valid reason for panic().

However the powernv platform allocates it_map after a device is returned
to the host OS after being passed through and this happens long after
the host OS booted. It is quite possible to trigger the it_map allocation
panic() and kill the host even though it is not necessary - the host OS
can still use the DMA bypass mode (requires a tiny fraction of it_map's
memory) and even if that fails, the host OS is runnnable as it was without
the device for which allocating it_map causes the panic.

Instead of immediately crashing in a powernv/ioda2 system, this prints
an error and continues. All other platforms still call panic().

Signed-off-by: Alexey Kardashevskiy &lt;aik@ozlabs.ru&gt;
Reviewed-by: David Gibson &lt;david@gibson.dropbear.id.au&gt;
Reviewed-by: Leonardo Bras &lt;leobras.c@gmail.com&gt;
Signed-off-by: Michael Ellerman &lt;mpe@ellerman.id.au&gt;
Link: https://lore.kernel.org/r/20210216033307.69863-3-aik@ozlabs.ru

</content>
</entry>
<entry>
<title>powerpc/iommu: Allocate it_map by vmalloc</title>
<updated>2021-04-22T15:38:04Z</updated>
<author>
<name>Alexey Kardashevskiy</name>
</author>
<published>2021-02-16T03:33:06Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7f1fa82d79947dfabb4046e1d787da9db2bc1c20'/>
<id>urn:sha1:7f1fa82d79947dfabb4046e1d787da9db2bc1c20</id>
<content type='text'>
The IOMMU table uses the it_map bitmap to keep track of allocated DMA
pages. This has always been a contiguous array allocated at either
the boot time or when a passed through device is returned to the host OS.
The it_map memory is allocated by alloc_pages() which allocates
contiguous physical memory.

Such allocation method occasionally creates a problem when there is
no big chunk of memory available (no free memory or too fragmented).
On powernv/ioda2 the default DMA window requires 16MB for it_map.

This replaces alloc_pages_node() with vzalloc_node() which allocates
contiguous block but in virtual memory. This should reduce changes of
failure but should not cause other behavioral changes as it_map is only
used by the kernel's DMA hooks/api when MMU is on.

Signed-off-by: Alexey Kardashevskiy &lt;aik@ozlabs.ru&gt;
Reviewed-by: David Gibson &lt;david@gibson.dropbear.id.au&gt;
Signed-off-by: Michael Ellerman &lt;mpe@ellerman.id.au&gt;
Link: https://lore.kernel.org/r/20210216033307.69863-2-aik@ozlabs.ru

</content>
</entry>
<entry>
<title>powerpc/iommu/debug: fix ifnullfree.cocci warnings</title>
<updated>2021-03-29T02:22:17Z</updated>
<author>
<name>kernel test robot</name>
</author>
<published>2021-03-18T23:44:41Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=bbbe563f8490958861777d98871e16960163ea1b'/>
<id>urn:sha1:bbbe563f8490958861777d98871e16960163ea1b</id>
<content type='text'>
arch/powerpc/kernel/iommu.c:76:2-16: WARNING: NULL check before some freeing functions is not needed.

 NULL check before some freeing functions is not needed.

 Based on checkpatch warning
 "kfree(NULL) is safe this check is probably not required"
 and kfreeaddr.cocci by Julia Lawall.

Generated by: scripts/coccinelle/free/ifnullfree.cocci

Fixes: 691602aab9c3 ("powerpc/iommu/debug: Add debugfs entries for IOMMU tables")
Reported-by: kernel test robot &lt;lkp@intel.com&gt;
Signed-off-by: kernel test robot &lt;lkp@intel.com&gt;
Signed-off-by: Michael Ellerman &lt;mpe@ellerman.id.au&gt;
Link: https://lore.kernel.org/r/20210318234441.GA63469@f8e20a472e81
</content>
</entry>
<entry>
<title>powerpc/iommu/debug: Add debugfs entries for IOMMU tables</title>
<updated>2021-01-30T00:39:31Z</updated>
<author>
<name>Alexey Kardashevskiy</name>
</author>
<published>2021-01-13T10:20:14Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=691602aab9c3cce31d3ff9529c09b7922a5f6224'/>
<id>urn:sha1:691602aab9c3cce31d3ff9529c09b7922a5f6224</id>
<content type='text'>
This adds a folder per LIOBN under /sys/kernel/debug/iommu with IOMMU
table parameters.

This is enabled by CONFIG_IOMMU_DEBUGFS.

Signed-off-by: Alexey Kardashevskiy &lt;aik@ozlabs.ru&gt;
Signed-off-by: Michael Ellerman &lt;mpe@ellerman.id.au&gt;
Link: https://lore.kernel.org/r/20210113102014.124452-1-aik@ozlabs.ru
</content>
</entry>
<entry>
<title>dma-mapping: introduce dma_get_seg_boundary_nr_pages()</title>
<updated>2020-09-03T16:12:15Z</updated>
<author>
<name>Nicolin Chen</name>
</author>
<published>2020-09-01T22:16:45Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=1e9d90dbed120ec98517428ffff4dacd9797e39d'/>
<id>urn:sha1:1e9d90dbed120ec98517428ffff4dacd9797e39d</id>
<content type='text'>
We found that callers of dma_get_seg_boundary mostly do an ALIGN
with page mask and then do a page shift to get number of pages:
    ALIGN(boundary + 1, 1 &lt;&lt; shift) &gt;&gt; shift

However, the boundary might be as large as ULONG_MAX, which means
that a device has no specific boundary limit. So either "+ 1" or
passing it to ALIGN() would potentially overflow.

According to kernel defines:
    #define ALIGN_MASK(x, mask) (((x) + (mask)) &amp; ~(mask))
    #define ALIGN(x, a)	ALIGN_MASK(x, (typeof(x))(a) - 1)

We can simplify the logic here into a helper function doing:
  ALIGN(boundary + 1, 1 &lt;&lt; shift) &gt;&gt; shift
= ALIGN_MASK(b + 1, (1 &lt;&lt; s) - 1) &gt;&gt; s
= {[b + 1 + (1 &lt;&lt; s) - 1] &amp; ~[(1 &lt;&lt; s) - 1]} &gt;&gt; s
= [b + 1 + (1 &lt;&lt; s) - 1] &gt;&gt; s
= [b + (1 &lt;&lt; s)] &gt;&gt; s
= (b &gt;&gt; s) + 1

This patch introduces and applies dma_get_seg_boundary_nr_pages()
as an overflow-free helper for the dma_get_seg_boundary() callers
to get numbers of pages. It also takes care of the NULL dev case
for non-DMA API callers.

Suggested-by: Christoph Hellwig &lt;hch@lst.de&gt;
Signed-off-by: Nicolin Chen &lt;nicoleotsuka@gmail.com&gt;
Acked-by: Niklas Schnelle &lt;schnelle@linux.ibm.com&gt;
Acked-by: Michael Ellerman &lt;mpe@ellerman.id.au&gt; (powerpc)
Signed-off-by: Christoph Hellwig &lt;hch@lst.de&gt;
</content>
</entry>
<entry>
<title>Merge branch 'topic/ppc-kvm' into next</title>
<updated>2019-08-29T23:52:57Z</updated>
<author>
<name>Michael Ellerman</name>
</author>
<published>2019-08-29T23:52:57Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9044adca782c065de182d28876808446b3a8ccde'/>
<id>urn:sha1:9044adca782c065de182d28876808446b3a8ccde</id>
<content type='text'>
Merge our ppc-kvm topic branch to bring in the Ultravisor support
patches.
</content>
</entry>
</feed>
