OP-TEE fixes for v7.3

- Register the TEE devices only once fully initialized
 - Support FF-A shared memory offsets on large-page kernels
 -----BEGIN PGP SIGNATURE-----
 
 iQJUBAABCgA+FiEE0qerISgy2SKkqO79Wr/6JGat8H4FAmq/vYUgHGplbnMud2lr
 bGFuZGVyQG9zcy5xdWFsY29tbS5jb20ACgkQWr/6JGat8H6RMw/8D8FeS6QFcNCU
 UGfz4tlPorAT+rHPe8mgjmFE41ph40UdVDCW4SW5qSZK3R7Uq8gMgOakW2pkEXHR
 7XCyBo36GRjAi6cBAUM79240Laghgtw1zuZQXqakmtKDWM/9/WkF0rZ+DVMWX56w
 Vi/YxbuRfj3mLjr2tG1tOGHOpPPxaV/PemQO0b57tMGt3Nu+v5k/sIs2ufgkoEJi
 KtCuFlNO+JUZ8ldKR/OcC025q+asjqYuLK13cVmLrTvhEkPXXXu52twbcjVYHiO1
 9P4NNsvmtvNlk40scUsAtdSfZ7PpgTFjYZwbCFDYriqPt7BB9xDwUCXFcatn1I4K
 NhlsQXv27LUPPKz9nmKL9PmLB8jYWs4lNs/4Sz2dnOJmy0dTFYV/3CCoDeR2cK2M
 dCi9IZ2aepnxgUnCckbfvjw/Ap96yFGNf44GbqBpCTCdVRnJ3zuIeLRDwHDfzQiC
 ELwE5gUPdtuyBlmEQV6fLFMnA1lXcTNl91CL2y9vrzn/P9dcxU7HLOABUc4CQm35
 T/jqf5tNbri6g65PCRA4HZJPPZA3OmfoOwpiZKDHedZ6lri8eZ+43rI2xzpQh/q1
 bb+QWngUZuXeYetsx+a+8WxaUJrxpPvgSLiTAxCF5cTIYHxJslZ6ZOMZP204AO/Y
 MZzl5tTbV7li42WxegZSV9eSg9EiLDQ=
 =KtE/
 -----END PGP SIGNATURE-----
gpgsig -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEo6/YBQwIrVS28WGKmmx57+YAGNkFAmrAJH4ACgkQmmx57+YA
 GNlPLw//VgBaLvVruZ8XO65cGWZUSoaOXpZtuAt0s4YuYG6u/hBB69uN3AGPnyuK
 i1uqV2lclFd6cppJrYm/YmnXYe/7Hmuozbj7WzSoot/HSAiTF4H31oAkM4qWBbgi
 tPF/GOUXSLkOkb9jZIzGXGcH+CadbEA6s3+xMAxSaFotw8ibg5fFlbLoLldA5InY
 1Bfm9DlqELmPw2v+4e8eKQt7XALEO1aPRepD614N/JOP4npZb+lF+7GPQnL3Te6g
 uWfcRUSb8GItazwTGCouHrsZyZfH1HZ4PdOMp6GINn4aVlQOeOpfRk4pX7GtUdNG
 6dKXorVCpDkuJ7ziQXvtN2N05YvCw1IXJd2utZNnFVmHwOI9++FaT+y4U4UUKNBF
 W9IS3Jcmx0+9KWUr1CazKNAPXYeMxdIIopzPFFeCrFW4IyVEE/yZN8UxV4iHqshr
 LiTUlxZ6zoFlOkE7GJ8GD6Z5VN/P3M2cW5ql3OMI0EkhmsRmpQkIWmJz/aQ7K2GH
 okMuCkw2gKBRiPr6z1rD3RdCRP5jpTfvM4FAA8+owbjVjKVzniOsvKtIIETpLmS6
 WQv/cwCa0K0OKyK8ndRwVjfpsgBU22Ue2TTQmw7bd3tfg+D/L20FnWmmtcix8TpX
 nEooQeuhg5CS8GLwE7bL5amJItywP1wT8ueEYeJszNr3UjfhAIA=
 =SO92
 -----END PGP SIGNATURE-----

Merge tag 'optee-fixes-for-v7.3' of git://git.kernel.org/pub/scm/linux/kernel/git/jenswi/linux-tee into arm/fixes

OP-TEE fixes for v7.3

- Register the TEE devices only once fully initialized
- Support FF-A shared memory offsets on large-page kernels

* tag 'optee-fixes-for-v7.3' of git://git.kernel.org/pub/scm/linux/kernel/git/jenswi/linux-tee:
  tee: optee: ffa: support shared memory offsets on large-page kernels
  optee: register TEE devices only once fully initialized

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
This commit is contained in:
Arnd Bergmann 2026-10-02 23:39:01 +02:00
commit e984d7bf46
3 changed files with 36 additions and 23 deletions

View File

@ -198,7 +198,8 @@ static int to_msg_param_ffa_mem(struct optee_msg_param *mp,
if (shm) {
u64 shm_offs = p->u.memref.shm_offs;
mp->u.fmem.internal_offs = shm->offset;
mp->u.fmem.internal_offs = tee_shm_get_page_offset(shm) &
(FFA_PAGE_SIZE - 1);
mp->u.fmem.offs_low = shm_offs;
mp->u.fmem.offs_high = shm_offs >> 32;
@ -284,14 +285,26 @@ static int optee_ffa_shm_register(struct tee_context *ctx, struct tee_shm *shm,
.nattrs = 1,
};
struct sg_table sgt;
size_t ffa_offs;
int rc;
if (!num_pages)
return -EINVAL;
rc = optee_check_mem_type(start, num_pages);
if (rc)
return rc;
rc = sg_alloc_table_from_pages(&sgt, pages, num_pages, 0,
num_pages * PAGE_SIZE, GFP_KERNEL);
/*
* Start the FF-A descriptor at the 4 KiB page containing the shared
* buffer, skipping unused leading 4 KiB pages when PAGE_SIZE is
* larger. Same approach as optee_fill_pages_list() in the SMC ABI.
* This leaves only the offset into that 4 KiB page for internal_offs.
*/
ffa_offs = round_down(tee_shm_get_page_offset(shm), FFA_PAGE_SIZE);
rc = sg_alloc_table_from_pages(&sgt, pages, num_pages, ffa_offs,
num_pages * PAGE_SIZE - ffa_offs,
GFP_KERNEL);
if (rc)
return rc;
args.sg = sgt.sgl;
@ -458,7 +471,8 @@ static void handle_ffa_rpc_func_cmd_shm_alloc(struct tee_context *ctx,
.attr = OPTEE_MSG_ATTR_TYPE_FMEM_OUTPUT,
.u.fmem.size = tee_shm_get_size(shm),
.u.fmem.global_id = shm->sec_world_id,
.u.fmem.internal_offs = shm->offset,
.u.fmem.internal_offs = tee_shm_get_page_offset(shm) &
(FFA_PAGE_SIZE - 1),
};
arg->ret = TEEC_SUCCESS;
@ -1123,14 +1137,6 @@ static int optee_ffa_probe(struct ffa_device *ffa_dev)
optee_set_dev_group(optee);
rc = tee_device_register(optee->teedev);
if (rc)
goto err_unreg_supp_teedev;
rc = tee_device_register(optee->supp_teedev);
if (rc)
goto err_unreg_supp_teedev;
rc = rhashtable_init(&optee->ffa.global_ids, &shm_rhash_params);
if (rc)
goto err_unreg_supp_teedev;
@ -1159,6 +1165,14 @@ static int optee_ffa_probe(struct ffa_device *ffa_dev)
if (optee_ffa_protmem_pool_init(optee, sec_caps))
pr_info("Protected memory service not available\n");
rc = tee_device_register(optee->teedev);
if (rc)
goto err_unregister_devices;
rc = tee_device_register(optee->supp_teedev);
if (rc)
goto err_unregister_devices;
rc = optee_enumerate_devices(PTA_CMD_GET_DEVICES);
if (rc)
goto err_unregister_devices;

View File

@ -136,8 +136,8 @@ struct optee_msg_param_rmem {
* struct optee_msg_param_fmem - FF-A memory reference parameter
* @offs_low: lower bits of offset into shared memory reference
* @offs_high: higher bits of offset into shared memory reference
* @internal_offs: internal offset into the first page of shared memory
* reference
* @internal_offs: offset into the first 4 KiB page of the FF-A shared
* memory region
* @size: size of the buffer
* @global_id: global identifier of the shared memory
*/

View File

@ -1849,14 +1849,6 @@ static int optee_probe(struct platform_device *pdev)
optee_set_dev_group(optee);
rc = tee_device_register(optee->teedev);
if (rc)
goto err_unreg_supp_teedev;
rc = tee_device_register(optee->supp_teedev);
if (rc)
goto err_unreg_supp_teedev;
optee_cq_init(&optee->call_queue, thread_count);
optee_supp_init(&optee->supp);
optee->smc.memremaped_shm = memremaped_shm;
@ -1916,6 +1908,14 @@ static int optee_probe(struct platform_device *pdev)
if (optee->smc.sec_caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM)
pr_info("dynamic shared memory is enabled\n");
rc = tee_device_register(optee->teedev);
if (rc)
goto err_disable_shm_cache;
rc = tee_device_register(optee->supp_teedev);
if (rc)
goto err_disable_shm_cache;
rc = optee_enumerate_devices(PTA_CMD_GET_DEVICES);
if (rc)
goto err_disable_shm_cache;
@ -1942,7 +1942,6 @@ static int optee_probe(struct platform_device *pdev)
optee_shm_arg_cache_uninit(optee);
optee_supp_uninit(&optee->supp);
mutex_destroy(&optee->call_queue.mutex);
err_unreg_supp_teedev:
tee_device_unregister(optee->supp_teedev);
err_unreg_teedev:
tee_device_unregister(optee->teedev);