<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/drivers/tee/tee_shm.c, branch linux-5.16.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.16.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.16.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2021-12-16T08:30:14Z</updated>
<entry>
<title>tee: handle lookup of shm with reference count 0</title>
<updated>2021-12-16T08:30:14Z</updated>
<author>
<name>Jens Wiklander</name>
</author>
<published>2021-12-09T14:59:37Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=dfd0743f1d9ea76931510ed150334d571fbab49d'/>
<id>urn:sha1:dfd0743f1d9ea76931510ed150334d571fbab49d</id>
<content type='text'>
Since the tee subsystem does not keep a strong reference to its idle
shared memory buffers, it races with other threads that try to destroy a
shared memory through a close of its dma-buf fd or by unmapping the
memory.

In tee_shm_get_from_id() when a lookup in teedev-&gt;idr has been
successful, it is possible that the tee_shm is in the dma-buf teardown
path, but that path is blocked by the teedev mutex. Since we don't have
an API to tell if the tee_shm is in the dma-buf teardown path or not we
must find another way of detecting this condition.

Fix this by doing the reference counting directly on the tee_shm using a
new refcount_t refcount field. dma-buf is replaced by using
anon_inode_getfd() instead, this separates the life-cycle of the
underlying file from the tee_shm. tee_shm_put() is updated to hold the
mutex when decreasing the refcount to 0 and then remove the tee_shm from
teedev-&gt;idr before releasing the mutex. This means that the tee_shm can
never be found unless it has a refcount larger than 0.

Fixes: 967c9cca2cc5 ("tee: generic TEE subsystem")
Cc: stable@vger.kernel.org
Reviewed-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Reviewed-by: Lars Persson &lt;larper@axis.com&gt;
Reviewed-by: Sumit Garg &lt;sumit.garg@linaro.org&gt;
Reported-by: Patrik Lantz &lt;patrik.lantz@axis.com&gt;
Signed-off-by: Jens Wiklander &lt;jens.wiklander@linaro.org&gt;
</content>
</entry>
<entry>
<title>dma-buf: move dma-buf symbols into the DMA_BUF module namespace</title>
<updated>2021-10-25T12:53:08Z</updated>
<author>
<name>Greg Kroah-Hartman</name>
</author>
<published>2021-10-10T12:46:28Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=16b0314aa746be6c84c0bc6eca9dde0dce2e99df'/>
<id>urn:sha1:16b0314aa746be6c84c0bc6eca9dde0dce2e99df</id>
<content type='text'>
In order to better track where in the kernel the dma-buf code is used,
put the symbols in the namespace DMA_BUF and modify all users of the
symbols to properly import the namespace to not break the build at the
same time.

Now the output of modinfo shows the use of these symbols, making it
easier to watch for users over time:

$ modinfo drivers/misc/fastrpc.ko | grep import
import_ns:      DMA_BUF

Cc: "Pan, Xinhui" &lt;Xinhui.Pan@amd.com&gt;
Cc: David Airlie &lt;airlied@linux.ie&gt;
Cc: Maarten Lankhorst &lt;maarten.lankhorst@linux.intel.com&gt;
Cc: Maxime Ripard &lt;mripard@kernel.org&gt;
Cc: Thomas Zimmermann &lt;tzimmermann@suse.de&gt;
Cc: Mauro Carvalho Chehab &lt;mchehab@kernel.org&gt;
Cc: dri-devel@lists.freedesktop.org
Acked-by: Daniel Vetter &lt;daniel.vetter@ffwll.ch&gt;
Acked-by: Christian König &lt;christian.koenig@amd.com&gt;
Acked-by: Arnd Bergmann &lt;arnd@arndb.de&gt;
Acked-by: Sumit Semwal &lt;sumit.semwal@linaro.org&gt;
Acked-by: Alex Deucher &lt;alexander.deucher@amd.com&gt;
Link: https://lore.kernel.org/r/20211010124628.17691-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tee: Correct inappropriate usage of TEE_SHM_DMA_BUF flag</title>
<updated>2021-07-21T05:55:50Z</updated>
<author>
<name>Sumit Garg</name>
</author>
<published>2021-06-14T22:33:15Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=376e4199e327a5cf29b8ec8fb0f64f3d8b429819'/>
<id>urn:sha1:376e4199e327a5cf29b8ec8fb0f64f3d8b429819</id>
<content type='text'>
Currently TEE_SHM_DMA_BUF flag has been inappropriately used to not
register shared memory allocated for private usage by underlying TEE
driver: OP-TEE in this case. So rather add a new flag as TEE_SHM_PRIV
that can be utilized by underlying TEE drivers for private allocation
and usage of shared memory.

With this corrected, allow tee_shm_alloc_kernel_buf() to allocate a
shared memory region without the backing of dma-buf.

Cc: stable@vger.kernel.org
Signed-off-by: Sumit Garg &lt;sumit.garg@linaro.org&gt;
Co-developed-by: Tyler Hicks &lt;tyhicks@linux.microsoft.com&gt;
Signed-off-by: Tyler Hicks &lt;tyhicks@linux.microsoft.com&gt;
Reviewed-by: Jens Wiklander &lt;jens.wiklander@linaro.org&gt;
Reviewed-by: Sumit Garg &lt;sumit.garg@linaro.org&gt;
Signed-off-by: Jens Wiklander &lt;jens.wiklander@linaro.org&gt;
</content>
</entry>
<entry>
<title>tee: add tee_shm_alloc_kernel_buf()</title>
<updated>2021-07-21T05:55:44Z</updated>
<author>
<name>Jens Wiklander</name>
</author>
<published>2021-06-14T22:33:14Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=dc7019b7d0e188d4093b34bd0747ed0d668c63bf'/>
<id>urn:sha1:dc7019b7d0e188d4093b34bd0747ed0d668c63bf</id>
<content type='text'>
Adds a new function tee_shm_alloc_kernel_buf() to allocate shared memory
from a kernel driver. This function can later be made more lightweight
by unnecessary dma-buf export.

Cc: stable@vger.kernel.org
Reviewed-by: Tyler Hicks &lt;tyhicks@linux.microsoft.com&gt;
Reviewed-by: Sumit Garg &lt;sumit.garg@linaro.org&gt;
Signed-off-by: Jens Wiklander &lt;jens.wiklander@linaro.org&gt;
</content>
</entry>
<entry>
<title>tee: convert get_user_pages() --&gt; pin_user_pages()</title>
<updated>2020-08-25T09:01:06Z</updated>
<author>
<name>John Hubbard</name>
</author>
<published>2020-08-24T21:11:25Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=4300cd6374a5192a2c8122a4a48ed647bdcb0214'/>
<id>urn:sha1:4300cd6374a5192a2c8122a4a48ed647bdcb0214</id>
<content type='text'>
This code was using get_user_pages*(), in a "Case 2" scenario
(DMA/RDMA), using the categorization from [1]. That means that it's
time to convert the get_user_pages*() + put_page() calls to
pin_user_pages*() + unpin_user_pages() calls.

Factor out a new, small release_registered_pages() function, in
order to consolidate the logic for discerning between
TEE_SHM_USER_MAPPED and TEE_SHM_KERNEL_MAPPED pages. This also
absorbs the kfree() call that is also required there.

There is some helpful background in [2]: basically, this is a small
part of fixing a long-standing disconnect between pinning pages, and
file systems' use of those pages.

[1] Documentation/core-api/pin_user_pages.rst

[2] "Explicit pinning of user-space pages":
    https://lwn.net/Articles/807108/

Cc: Jens Wiklander &lt;jens.wiklander@linaro.org&gt;
Cc: Sumit Semwal &lt;sumit.semwal@linaro.org&gt;
Cc: tee-dev@lists.linaro.org
Cc: linux-media@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
Cc: linaro-mm-sig@lists.linaro.org
Signed-off-by: John Hubbard &lt;jhubbard@nvidia.com&gt;
Signed-off-by: Jens Wiklander &lt;jens.wiklander@linaro.org&gt;
</content>
</entry>
<entry>
<title>Merge tag 'tee-smatch-for-5.8' of git://git.linaro.org/people/jens.wiklander/linux-tee into arm/drivers</title>
<updated>2020-05-25T14:56:33Z</updated>
<author>
<name>Arnd Bergmann</name>
</author>
<published>2020-05-25T14:56:33Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=6d83d800b2456122299dcfce4a7da4b86d7cec8e'/>
<id>urn:sha1:6d83d800b2456122299dcfce4a7da4b86d7cec8e</id>
<content type='text'>
tee: remove unnecessary NULL check in tee_shm_alloc()

* tag 'tee-smatch-for-5.8' of git://git.linaro.org/people/jens.wiklander/linux-tee:
  tee: remove unnecessary NULL check in tee_shm_alloc()

Link: https://lore.kernel.org/r/20200504181333.GA11018@jade
Signed-off-by: Arnd Bergmann &lt;arnd@arndb.de&gt;
</content>
</entry>
<entry>
<title>tee: enable support to register kernel memory</title>
<updated>2020-04-20T13:49:56Z</updated>
<author>
<name>Sumit Garg</name>
</author>
<published>2020-03-27T05:29:47Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=2a6ba3f794e892c37d67b8ebb19487ce105eabc2'/>
<id>urn:sha1:2a6ba3f794e892c37d67b8ebb19487ce105eabc2</id>
<content type='text'>
Enable support to register kernel memory reference with TEE. This change
will allow TEE bus drivers to register memory references.

Signed-off-by: Sumit Garg &lt;sumit.garg@linaro.org&gt;
Signed-off-by: Jens Wiklander &lt;jens.wiklander@linaro.org&gt;
</content>
</entry>
<entry>
<title>tee: remove unnecessary NULL check in tee_shm_alloc()</title>
<updated>2020-04-20T11:12:01Z</updated>
<author>
<name>Dan Carpenter</name>
</author>
<published>2020-04-07T09:30:28Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=1115899e7aad71bc36100c3fa1d0b99cff9263e6'/>
<id>urn:sha1:1115899e7aad71bc36100c3fa1d0b99cff9263e6</id>
<content type='text'>
Smatch complains that "ctx" isn't checked consistently:

    drivers/tee/tee_shm.c:164 tee_shm_alloc()
    warn: variable dereferenced before check 'ctx' (see line 95)

I audited the callers and "ctx" can't be NULL so the check can be
removed.

Signed-off-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Signed-off-by: Jens Wiklander &lt;jens.wiklander@linaro.org&gt;
</content>
</entry>
<entry>
<title>tee: tee_shm_op_mmap(): use TEE_SHM_USER_MAPPED</title>
<updated>2020-02-28T12:37:42Z</updated>
<author>
<name>Jens Wiklander</name>
</author>
<published>2019-11-07T10:43:02Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=758ecf13a41a9dc4f019c1381566132ef46c08ee'/>
<id>urn:sha1:758ecf13a41a9dc4f019c1381566132ef46c08ee</id>
<content type='text'>
tee_shm_op_mmap() uses the TEE_SHM_USER_MAPPED flag instead of the
TEE_SHM_REGISTER flag to tell if a shared memory object is originating
from registered user space memory.

Signed-off-by: Jens Wiklander &lt;jens.wiklander@linaro.org&gt;
</content>
</entry>
<entry>
<title>tee: remove redundant teedev in struct tee_shm</title>
<updated>2020-02-28T12:37:42Z</updated>
<author>
<name>Jens Wiklander</name>
</author>
<published>2019-11-07T10:42:59Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=5271b2011e448f1be7433554e4684e91951476fa'/>
<id>urn:sha1:5271b2011e448f1be7433554e4684e91951476fa</id>
<content type='text'>
The ctx element in struct tee_shm is always valid. So remove the now
redundant teedev element.

Signed-off-by: Jens Wiklander &lt;jens.wiklander@linaro.org&gt;
</content>
</entry>
</feed>
