]> xenbits.xensource.com Git - xen.git/commit
optee: immediately free buffers that are released by OP-TEE
authorVolodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Fri, 19 Jun 2020 22:33:59 +0000 (22:33 +0000)
committerStefano Stabellini <sstabellini@kernel.org>
Wed, 1 Jul 2020 17:09:38 +0000 (10:09 -0700)
commit5b13eb1d978e9732fe2c9826b60885b687a5c4fc
treec9f8b0b7f4a0c96977730b438b9835bb30b8d558
parent3b7dab93f2401b08c673244c9ae0f92e08bd03ba
optee: immediately free buffers that are released by OP-TEE

Normal World can share a buffer with OP-TEE for two reasons:
1. A client application wants to exchange data with TA
2. OP-TEE asks for shared buffer for internal needs

The second case was handled more strictly than necessary:

1. In RPC request OP-TEE asks for buffer
2. NW allocates buffer and provides it via RPC response
3. Xen pins pages and translates data
4. Xen provides buffer to OP-TEE
5. OP-TEE uses it
6. OP-TEE sends request to free the buffer
7. NW frees the buffer and sends the RPC response
8. Xen unpins pages and forgets about the buffer

The problem is that Xen should forget about buffer in between stages 6
and 7. I.e. the right flow should be like this:

6. OP-TEE sends request to free the buffer
7. Xen unpins pages and forgets about the buffer
8. NW frees the buffer and sends the RPC response

This is because OP-TEE internally frees the buffer before sending the
"free SHM buffer" request. So we have no reason to hold reference for
this buffer anymore. Moreover, in multiprocessor systems NW have time
to reuse the buffer cookie for another buffer. Xen complained about this
and denied the new buffer registration. I have seen this issue while
running tests on iMX SoC.

So, this patch basically corrects that behavior by freeing the buffer
earlier, when handling RPC return from OP-TEE.

Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Release-acked-by: Paul Durrant <paul@xen.org>
xen/arch/arm/tee/optee.c