<feed xmlns='http://www.w3.org/2005/Atom'>
<title>user/sven/linux.git/drivers/tee, branch v5.4.171</title>
<subtitle>Linux Kernel
</subtitle>
<id>https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v5.4.171</id>
<link rel='self' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v5.4.171'/>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/'/>
<updated>2022-01-05T11:37:43Z</updated>
<entry>
<title>tee: handle lookup of shm with reference count 0</title>
<updated>2022-01-05T11:37:43Z</updated>
<author>
<name>Jens Wiklander</name>
<email>jens.wiklander@linaro.org</email>
</author>
<published>2021-12-09T14:59:37Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=940e68e57ab69248fabba5889e615305789db8a7'/>
<id>urn:sha1:940e68e57ab69248fabba5889e615305789db8a7</id>
<content type='text'>
commit dfd0743f1d9ea76931510ed150334d571fbab49d upstream.

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;
[JW: backport to 5.4-stable]
Signed-off-by: Jens Wiklander &lt;jens.wiklander@linaro.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tee: optee: Fix incorrect page free bug</title>
<updated>2021-12-29T11:23:37Z</updated>
<author>
<name>Sumit Garg</name>
<email>sumit.garg@linaro.org</email>
</author>
<published>2021-12-16T05:47:25Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=806142c805cacd098e61bdc0f72c778a2389fe4a'/>
<id>urn:sha1:806142c805cacd098e61bdc0f72c778a2389fe4a</id>
<content type='text'>
commit 18549bf4b21c739a9def39f27dcac53e27286ab5 upstream.

Pointer to the allocated pages (struct page *page) has already
progressed towards the end of allocation. It is incorrect to perform
__free_pages(page, order) using this pointer as we would free any
arbitrary pages. Fix this by stop modifying the page pointer.

Fixes: ec185dd3ab25 ("optee: Fix memory leak when failing to register shm pages")
Cc: stable@vger.kernel.org
Reported-by: Patrik Lantz &lt;patrik.lantz@axis.com&gt;
Signed-off-by: Sumit Garg &lt;sumit.garg@linaro.org&gt;
Reviewed-by: Tyler Hicks &lt;tyhicks@linux.microsoft.com&gt;
Signed-off-by: Jens Wiklander &lt;jens.wiklander@linaro.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tee: optee: Fix missing devices unregister during optee_remove</title>
<updated>2021-10-27T07:54:25Z</updated>
<author>
<name>Sumit Garg</name>
<email>sumit.garg@linaro.org</email>
</author>
<published>2021-10-12T07:31:16Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=e7c4819c0b6725abe3e32ebf677a38ea6a7ef643'/>
<id>urn:sha1:e7c4819c0b6725abe3e32ebf677a38ea6a7ef643</id>
<content type='text'>
commit 7f565d0ead264329749c0da488de9c8dfa2f18ce upstream.

When OP-TEE driver is built as a module, OP-TEE client devices
registered on TEE bus during probe should be unregistered during
optee_remove. So implement optee_unregister_devices() accordingly.

Fixes: c3fa24af9244 ("tee: optee: add TEE bus device enumeration support")
Reported-by: Sudeep Holla &lt;sudeep.holla@arm.com&gt;
Signed-off-by: Sumit Garg &lt;sumit.garg@linaro.org&gt;
Signed-off-by: Jens Wiklander &lt;jens.wiklander@linaro.org&gt;
[SG: backport to 5.4, dev name s/optee-ta/optee-clnt/]
Signed-off-by: Sumit Garg &lt;sumit.garg@linaro.org&gt;
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-08-15T11:08:02Z</updated>
<author>
<name>Sumit Garg</name>
<email>sumit.garg@linaro.org</email>
</author>
<published>2021-06-14T22:33:15Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=236aca70929db3aa87dfb8fbc5329aa027a62e91'/>
<id>urn:sha1:236aca70929db3aa87dfb8fbc5329aa027a62e91</id>
<content type='text'>
[ Upstream commit 376e4199e327a5cf29b8ec8fb0f64f3d8b429819 ]

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;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>optee: Fix memory leak when failing to register shm pages</title>
<updated>2021-08-12T11:21:01Z</updated>
<author>
<name>Tyler Hicks</name>
<email>tyhicks@linux.microsoft.com</email>
</author>
<published>2021-06-14T22:33:10Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=3c712f14d8a9354a8807c15c64c8dd334499cc42'/>
<id>urn:sha1:3c712f14d8a9354a8807c15c64c8dd334499cc42</id>
<content type='text'>
commit ec185dd3ab257dc2a60953fdf1b6622f524cc5b7 upstream.

Free the previously allocated pages when we encounter an error condition
while attempting to register the pages with the secure world.

Fixes: a249dd200d03 ("tee: optee: Fix dynamic shm pool allocations")
Fixes: 5a769f6ff439 ("optee: Fix multi page dynamic shm pool alloc")
Cc: stable@vger.kernel.org
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;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tee: add tee_shm_alloc_kernel_buf()</title>
<updated>2021-08-12T11:21:01Z</updated>
<author>
<name>Jens Wiklander</name>
<email>jens.wiklander@linaro.org</email>
</author>
<published>2021-06-14T22:33:14Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=0572199b78b39d09757688217245fb933d2e4752'/>
<id>urn:sha1:0572199b78b39d09757688217245fb933d2e4752</id>
<content type='text'>
commit dc7019b7d0e188d4093b34bd0747ed0d668c63bf upstream.

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;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>optee: Clear stale cache entries during initialization</title>
<updated>2021-08-12T11:21:01Z</updated>
<author>
<name>Tyler Hicks</name>
<email>tyhicks@linux.microsoft.com</email>
</author>
<published>2021-06-14T22:33:13Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=b247bf412cc235c0d9e33407364f620be5a43d56'/>
<id>urn:sha1:b247bf412cc235c0d9e33407364f620be5a43d56</id>
<content type='text'>
commit b5c10dd04b7418793517e3286cde5c04759a86de upstream.

The shm cache could contain invalid addresses if
optee_disable_shm_cache() was not called from the .shutdown hook of the
previous kernel before a kexec. These addresses could be unmapped or
they could point to mapped but unintended locations in memory.

Clear the shared memory cache, while being careful to not translate the
addresses returned from OPTEE_SMC_DISABLE_SHM_CACHE, during driver
initialization. Once all pre-cache shm objects are removed, proceed with
enabling the cache so that we know that we can handle cached shm objects
with confidence later in the .shutdown hook.

Cc: stable@vger.kernel.org
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;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tee: optee: do not check memref size on return from Secure World</title>
<updated>2021-05-11T12:04:06Z</updated>
<author>
<name>Jerome Forissier</name>
<email>jerome@forissier.org</email>
</author>
<published>2021-03-22T10:40:37Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=fe53f8fd64d7ef200a189a4430e9cd6bc7f5d537'/>
<id>urn:sha1:fe53f8fd64d7ef200a189a4430e9cd6bc7f5d537</id>
<content type='text'>
[ Upstream commit c650b8dc7a7910eb25af0aac1720f778b29e679d ]

When Secure World returns, it may have changed the size attribute of the
memory references passed as [in/out] parameters. The GlobalPlatform TEE
Internal Core API specification does not restrict the values that this
size can take. In particular, Secure World may increase the value to be
larger than the size of the input buffer to indicate that it needs more.

Therefore, the size check in optee_from_msg_param() is incorrect and
needs to be removed. This fixes a number of failed test cases in the
GlobalPlatform TEE Initial Configuratiom Test Suite v2_0_0_0-2017_06_09
when OP-TEE is compiled without dynamic shared memory support
(CFG_CORE_DYN_SHM=n).

Reviewed-by: Sumit Garg &lt;sumit.garg@linaro.org&gt;
Suggested-by: Jens Wiklander &lt;jens.wiklander@linaro.org&gt;
Signed-off-by: Jerome Forissier &lt;jerome@forissier.org&gt;
Signed-off-by: Jens Wiklander &lt;jens.wiklander@linaro.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>tee: optee: replace might_sleep with cond_resched</title>
<updated>2021-02-03T22:25:58Z</updated>
<author>
<name>Rouven Czerwinski</name>
<email>r.czerwinski@pengutronix.de</email>
</author>
<published>2021-01-05T10:28:44Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=65543408f25750c0dbf46cd43c5866c7678d776e'/>
<id>urn:sha1:65543408f25750c0dbf46cd43c5866c7678d776e</id>
<content type='text'>
commit dcb3b06d9c34f33a249f65c08805461fb0c4325b upstream.

might_sleep() is a debugging aid and triggers rescheduling only for
certain kernel configurations. Replace with an explicit check and
reschedule to work for all kernel configurations. Fixes the following
trace:

  [  572.945146] rcu: INFO: rcu_sched self-detected stall on CPU
  [  572.949275] rcu:     0-....: (2099 ticks this GP) idle=572/1/0x40000002 softirq=7412/7412 fqs=974
  [  572.957964]  (t=2100 jiffies g=10393 q=21)
  [  572.962054] NMI backtrace for cpu 0
  [  572.965540] CPU: 0 PID: 165 Comm: xtest Not tainted 5.8.7 #1
  [  572.971188] Hardware name: STM32 (Device Tree Support)
  [  572.976354] [&lt;c011163c&gt;] (unwind_backtrace) from [&lt;c010b7f8&gt;] (show_stack+0x10/0x14)
  [  572.984080] [&lt;c010b7f8&gt;] (show_stack) from [&lt;c0511e4c&gt;] (dump_stack+0xc4/0xd8)
  [  572.991300] [&lt;c0511e4c&gt;] (dump_stack) from [&lt;c0519abc&gt;] (nmi_cpu_backtrace+0x90/0xc4)
  [  572.999130] [&lt;c0519abc&gt;] (nmi_cpu_backtrace) from [&lt;c0519bdc&gt;] (nmi_trigger_cpumask_backtrace+0xec/0x130)
  [  573.008706] [&lt;c0519bdc&gt;] (nmi_trigger_cpumask_backtrace) from [&lt;c01a5184&gt;] (rcu_dump_cpu_stacks+0xe8/0x110)
  [  573.018453] [&lt;c01a5184&gt;] (rcu_dump_cpu_stacks) from [&lt;c01a4234&gt;] (rcu_sched_clock_irq+0x7fc/0xa88)
  [  573.027416] [&lt;c01a4234&gt;] (rcu_sched_clock_irq) from [&lt;c01acdd0&gt;] (update_process_times+0x30/0x8c)
  [  573.036291] [&lt;c01acdd0&gt;] (update_process_times) from [&lt;c01bfb90&gt;] (tick_sched_timer+0x4c/0xa8)
  [  573.044905] [&lt;c01bfb90&gt;] (tick_sched_timer) from [&lt;c01adcc8&gt;] (__hrtimer_run_queues+0x174/0x358)
  [  573.053696] [&lt;c01adcc8&gt;] (__hrtimer_run_queues) from [&lt;c01aea2c&gt;] (hrtimer_interrupt+0x118/0x2bc)
  [  573.062573] [&lt;c01aea2c&gt;] (hrtimer_interrupt) from [&lt;c09ad664&gt;] (arch_timer_handler_virt+0x28/0x30)
  [  573.071536] [&lt;c09ad664&gt;] (arch_timer_handler_virt) from [&lt;c0190f50&gt;] (handle_percpu_devid_irq+0x8c/0x240)
  [  573.081109] [&lt;c0190f50&gt;] (handle_percpu_devid_irq) from [&lt;c018ab8c&gt;] (generic_handle_irq+0x34/0x44)
  [  573.090156] [&lt;c018ab8c&gt;] (generic_handle_irq) from [&lt;c018b194&gt;] (__handle_domain_irq+0x5c/0xb0)
  [  573.098857] [&lt;c018b194&gt;] (__handle_domain_irq) from [&lt;c052ac50&gt;] (gic_handle_irq+0x4c/0x90)
  [  573.107209] [&lt;c052ac50&gt;] (gic_handle_irq) from [&lt;c0100b0c&gt;] (__irq_svc+0x6c/0x90)
  [  573.114682] Exception stack(0xd90dfcf8 to 0xd90dfd40)
  [  573.119732] fce0:                                                       ffff0004 00000000
  [  573.127917] fd00: 00000000 00000000 00000000 00000000 00000000 00000000 d93493cc ffff0000
  [  573.136098] fd20: d2bc39c0 be926998 d90dfd58 d90dfd48 c09f3384 c01151f0 400d0013 ffffffff
  [  573.144281] [&lt;c0100b0c&gt;] (__irq_svc) from [&lt;c01151f0&gt;] (__arm_smccc_smc+0x10/0x20)
  [  573.151854] [&lt;c01151f0&gt;] (__arm_smccc_smc) from [&lt;c09f3384&gt;] (optee_smccc_smc+0x3c/0x44)
  [  573.159948] [&lt;c09f3384&gt;] (optee_smccc_smc) from [&lt;c09f4170&gt;] (optee_do_call_with_arg+0xb8/0x154)
  [  573.168735] [&lt;c09f4170&gt;] (optee_do_call_with_arg) from [&lt;c09f4638&gt;] (optee_invoke_func+0x110/0x190)
  [  573.177786] [&lt;c09f4638&gt;] (optee_invoke_func) from [&lt;c09f1ebc&gt;] (tee_ioctl+0x10b8/0x11c0)
  [  573.185879] [&lt;c09f1ebc&gt;] (tee_ioctl) from [&lt;c029f62c&gt;] (ksys_ioctl+0xe0/0xa4c)
  [  573.193101] [&lt;c029f62c&gt;] (ksys_ioctl) from [&lt;c0100060&gt;] (ret_fast_syscall+0x0/0x54)
  [  573.200750] Exception stack(0xd90dffa8 to 0xd90dfff0)
  [  573.205803] ffa0:                   be926bf4 be926a78 00000003 8010a403 be926908 004e3cf8
  [  573.213987] ffc0: be926bf4 be926a78 00000000 00000036 be926908 be926918 be9269b0 bffdf0f8
  [  573.222162] ffe0: b6d76fb0 be9268fc b6d66621 b6c7e0d8

seen on STM32 DK2 with CONFIG_PREEMPT_NONE.

Fixes: 9f02b8f61f29 ("tee: optee: add might_sleep for RPC requests")
Signed-off-by: Rouven Czerwinski &lt;r.czerwinski@pengutronix.de&gt;
Tested-by: Sumit Garg &lt;sumit.garg@linaro.org&gt;
[jw: added fixes tag + small adjustments in the code]
Signed-off-by: Jens Wiklander &lt;jens.wiklander@linaro.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>optee: add writeback to valid memory type</title>
<updated>2020-12-02T07:49:53Z</updated>
<author>
<name>Rui Miguel Silva</name>
<email>rui.silva@linaro.org</email>
</author>
<published>2020-11-13T15:06:04Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=5c4c6b2be717f1bcec6f6b0373f93761a76375ba'/>
<id>urn:sha1:5c4c6b2be717f1bcec6f6b0373f93761a76375ba</id>
<content type='text'>
[ Upstream commit 853735e404244f5496cdb6188c5ed9a0f9627ee6 ]

Only in smp systems the cache policy is setup as write alloc, in
single cpu systems the cache policy is set as writeback and it is
normal memory, so, it should pass the is_normal_memory check in the
share memory registration.

Add the right condition to make it work in no smp systems.

Fixes: cdbcf83d29c1 ("tee: optee: check type of registered shared memory")
Signed-off-by: Rui Miguel Silva &lt;rui.silva@linaro.org&gt;
Signed-off-by: Jens Wiklander &lt;jens.wiklander@linaro.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
</feed>
