From nobody Wed Dec 31 18:57:46 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 619E3C4332F for ; Mon, 30 Oct 2023 15:59:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233795AbjJ3P72 (ORCPT ); Mon, 30 Oct 2023 11:59:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233789AbjJ3P7Z (ORCPT ); Mon, 30 Oct 2023 11:59:25 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1847F9 for ; Mon, 30 Oct 2023 08:59:22 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6c10f098a27so840582b3a.2 for ; Mon, 30 Oct 2023 08:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698681562; x=1699286362; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qxLGrTrVdS6twyTFJiULc4e3eYbN7qH6nv+rg3gSjBE=; b=jxP5rR+u79T4jWxvyDDK0ThdlJFd7ALytj+uOuH9L71bKUeS2IAsUERVTVewozUgmu LLeBgtl88vkfn/sPIygpGq+MdX7cT6s0ejt2wdbw2LiqETZE6gpSuBS9D6ljlE/HheXl FBLEceTgUz+aWkU3V/12r39Zv29YYVYur5f27arf/6VtunjIKlJoN1nE2/KEVNlzJyhE plFUeRze+p2OMg7GCGkJ60W9cekFYXU8XJ1IvMVp3JrlyzU/fKNc5Mc2AB/CFUvahbxu ozLSXeYaLJ1xDyJiEKYL5rsqHYui3jwFWhj8uRGtdF1hrKMNNRS9Z3VQvHv3tpT0oC/A eUIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698681562; x=1699286362; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qxLGrTrVdS6twyTFJiULc4e3eYbN7qH6nv+rg3gSjBE=; b=BpqbKqR2i0IVth8NtQKDVWZjR4hz2Wh7dXvU0XcXB07tt9rLr7YCH3W2t2bcYtHUfU SRSojgzNiXF56G7kKjag7UT/p+qL75pdVE7K3S5lCHrnigU0SAP0+FSm40b/iSIoTkeQ ac/8H4kKx7UHtr4BjxKS+nw+tReM4N+uZnshizVYjq2ddKieSnxOFY8aoeAYJkH4Fxxg +IV0A/yJbjP6GhvRC3wdIskxODtZKtUFpk8Tw9bY/VbPp6LLrR3Zh6yB78/uuuqSlzey niU2thND1102uudoH1/ssZ8Xn/dWcNF9DHcYa33KZi4gWYp8XMdAgd9KnFvKuBH+Pqwi QODA== X-Gm-Message-State: AOJu0YxWWA8CQQb9gVQ/suJoSsZGiM4zp8iDBT9j16qcRaDdE2SYNs91 tiiEZyrqCNu9C5b+VwCl3iisuw== X-Google-Smtp-Source: AGHT+IFSS55x0t8mv4Kc7dzeTt1buEbF1zdSPp+l7eBsm6xcdSE+t+kqzPzd4iWmgH8HcZup1Q/iig== X-Received: by 2002:a05:6a00:24d6:b0:68e:2478:d6c9 with SMTP id d22-20020a056a0024d600b0068e2478d6c9mr8654507pfv.2.1698681562102; Mon, 30 Oct 2023 08:59:22 -0700 (PDT) Received: from sumit-X1.. ([223.178.210.245]) by smtp.gmail.com with ESMTPSA id z8-20020a056a00240800b006c148c6767bsm176632pfh.218.2023.10.30.08.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 08:59:21 -0700 (PDT) From: Sumit Garg To: jens.wiklander@linaro.org, op-tee@lists.trustedfirmware.org Cc: jan.kiszka@siemens.com, arnd@linaro.org, ardb@kernel.org, jerome.forissier@linaro.org, ilias.apalodimas@linaro.org, masahisa.kojima@linaro.org, maxim.uvarov@linaro.org, jarkko.sakkinen@linux.intel.com, linux-kernel@vger.kernel.org, diogo.ivo@siemens.com, Sumit Garg Subject: [PATCH v3 1/2] tee: optee: Fix supplicant based device enumeration Date: Mon, 30 Oct 2023 21:29:00 +0530 Message-Id: <20231030155901.80673-2-sumit.garg@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030155901.80673-1-sumit.garg@linaro.org> References: <20231030155901.80673-1-sumit.garg@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently supplicant dependent optee device enumeration only registers devices whenever tee-supplicant is invoked for the first time. But it forgets to remove devices when tee-supplicant daemon stops running and closes its context gracefully. This leads to following error for fTPM driver during reboot/shutdown: [ 73.466791] tpm tpm0: ftpm_tee_tpm_op_send: SUBMIT_COMMAND invoke error:= 0xffff3024 Fix this by separating supplicant dependent devices so that the user-space service can detach supplicant devices before closing the supplicant. Reported-by: Jan Kiszka Link: https://github.com/OP-TEE/optee_os/issues/6094 Fixes: 5f178bb71e3a ("optee: enable support for multi-stage bus enumeration= ") Tested-by: Jan Kiszka Tested-by: Masahisa Kojima Signed-off-by: Sumit Garg --- drivers/tee/optee/device.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/tee/optee/device.c b/drivers/tee/optee/device.c index 64f0e047c23d..78fc0a15c463 100644 --- a/drivers/tee/optee/device.c +++ b/drivers/tee/optee/device.c @@ -60,9 +60,10 @@ static void optee_release_device(struct device *dev) kfree(optee_device); } =20 -static int optee_register_device(const uuid_t *device_uuid) +static int optee_register_device(const uuid_t *device_uuid, u32 func) { struct tee_client_device *optee_device =3D NULL; + const char *dev_name_fmt =3D NULL; int rc; =20 optee_device =3D kzalloc(sizeof(*optee_device), GFP_KERNEL); @@ -71,7 +72,13 @@ static int optee_register_device(const uuid_t *device_uu= id) =20 optee_device->dev.bus =3D &tee_bus_type; optee_device->dev.release =3D optee_release_device; - if (dev_set_name(&optee_device->dev, "optee-ta-%pUb", device_uuid)) { + + if (func =3D=3D PTA_CMD_GET_DEVICES_SUPP) + dev_name_fmt =3D "optee-ta-supp-%pUb"; + else + dev_name_fmt =3D "optee-ta-%pUb"; + + if (dev_set_name(&optee_device->dev, dev_name_fmt, device_uuid)) { kfree(optee_device); return -ENOMEM; } @@ -142,7 +149,7 @@ static int __optee_enumerate_devices(u32 func) num_devices =3D shm_size / sizeof(uuid_t); =20 for (idx =3D 0; idx < num_devices; idx++) { - rc =3D optee_register_device(&device_uuid[idx]); + rc =3D optee_register_device(&device_uuid[idx], func); if (rc) goto out_shm; } --=20 2.34.1 From nobody Wed Dec 31 18:57:46 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6ADECC4332F for ; Mon, 30 Oct 2023 15:59:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233804AbjJ3P7f (ORCPT ); Mon, 30 Oct 2023 11:59:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233769AbjJ3P7a (ORCPT ); Mon, 30 Oct 2023 11:59:30 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 943E7109 for ; Mon, 30 Oct 2023 08:59:27 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-5b93ddb10b8so2273291a12.0 for ; Mon, 30 Oct 2023 08:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698681567; x=1699286367; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=E1Kwz19o9ECsWczdBnTg7G4Gn09yWEPDImb0+FUx/2U=; b=NyUb1yHrmOTYdbCcnLWhw6V8s7Th1M/XkaLVYHRClYnXHOyr5MZwxEKA/r2mN0HkbI qevJzzSwJXVrIwHp3bJ7RBr02k/HJb8WUv1lpaO17VCjyQd5epRY7W5x563ie5mbz519 DFS96tB1astVN0MxHMKHlJJhuDQwy/WbkLqB2XZHxwgSW3rD2RSUfPH4lza4GlIW1FWO NkTNAfaPPNXHNj0eSW8ClE2H6qkaH3rzQIr8BETb3HlHxf1dZbvm/2UIxGTAmTQWWqaf 74Wf3sszOu1LBXiLv9rAH0pw9SXJ7Gg+7UNbjnl4k5i28hxBFaL778iK1b5Z20IOlN/0 bN2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698681567; x=1699286367; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E1Kwz19o9ECsWczdBnTg7G4Gn09yWEPDImb0+FUx/2U=; b=vJUojS6LoiChm0d87Ixu73FIwLZcjMJXqip/oOgz4aRmvxIXm8QwyejEQfGtxK3PAY a3tUAP1MWK+k4Shho5iTfdYF96KqA4W03GFEms384aLn76pEkMIv1D5UqIIuvkObpx69 y7q9UnZae3QZpi513cXD5YnsP5pHlrWJOu2Ii7Ot2rDkdXJsU2MyUu4NhHqilHr1ChaX f+T5V6LGRGoB+9AIcAM3lRv1/4ynzmcLVUpuxLnXKBelzzT0XKQRz+1mPxHAYvgII0+N uJU2mIgECf7Duq5vlnrhGbQiqx28vLQDvRM/wtXodmkI3bNqQkr0kfanYQtlvuRnsWYK kYyA== X-Gm-Message-State: AOJu0Yx8KKSNX20ZgzpiU1mzYlb8CEBKRKl7m8Uyc/41Kiv70bHksb48 aFFzT8WMbVBiPZSsPy3hu9pQSg== X-Google-Smtp-Source: AGHT+IFEwYP53b8AOG7wf6tbFdhWzmLroYVe5KPNPRyOz2fC8o69KMnkBczSXIZzb8ihnoxuqLhGyw== X-Received: by 2002:a05:6a20:1443:b0:17e:aa00:ca62 with SMTP id a3-20020a056a20144300b0017eaa00ca62mr29299pzi.17.1698681566964; Mon, 30 Oct 2023 08:59:26 -0700 (PDT) Received: from sumit-X1.. ([223.178.210.245]) by smtp.gmail.com with ESMTPSA id z8-20020a056a00240800b006c148c6767bsm176632pfh.218.2023.10.30.08.59.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 08:59:26 -0700 (PDT) From: Sumit Garg To: jens.wiklander@linaro.org, op-tee@lists.trustedfirmware.org Cc: jan.kiszka@siemens.com, arnd@linaro.org, ardb@kernel.org, jerome.forissier@linaro.org, ilias.apalodimas@linaro.org, masahisa.kojima@linaro.org, maxim.uvarov@linaro.org, jarkko.sakkinen@linux.intel.com, linux-kernel@vger.kernel.org, diogo.ivo@siemens.com, Sumit Garg Subject: [PATCH v3 2/2] tee: optee: Remove redundant custom workqueue Date: Mon, 30 Oct 2023 21:29:01 +0530 Message-Id: <20231030155901.80673-3-sumit.garg@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030155901.80673-1-sumit.garg@linaro.org> References: <20231030155901.80673-1-sumit.garg@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Global system workqueue is sufficient to suffice OP-TEE bus scanning work needs. So drop redundant usage of the custom workqueue. Tested-by: Jan Kiszka Tested-by: Masahisa Kojima Signed-off-by: Sumit Garg --- drivers/tee/optee/core.c | 13 ++----------- drivers/tee/optee/optee_private.h | 2 -- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index 2a258bd3b6b5..1eaa191b6ff6 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -15,7 +15,6 @@ #include #include #include -#include #include "optee_private.h" =20 int optee_pool_op_alloc_helper(struct tee_shm_pool *pool, struct tee_shm *= shm, @@ -110,12 +109,7 @@ int optee_open(struct tee_context *ctx, bool cap_memre= f_null) =20 if (!optee->scan_bus_done) { INIT_WORK(&optee->scan_bus_work, optee_bus_scan); - optee->scan_bus_wq =3D create_workqueue("optee_bus_scan"); - if (!optee->scan_bus_wq) { - kfree(ctxdata); - return -ECHILD; - } - queue_work(optee->scan_bus_wq, &optee->scan_bus_work); + schedule_work(&optee->scan_bus_work); optee->scan_bus_done =3D true; } } @@ -158,10 +152,7 @@ void optee_release_supp(struct tee_context *ctx) struct optee *optee =3D tee_get_drvdata(ctx->teedev); =20 optee_release_helper(ctx, optee_close_session_helper); - if (optee->scan_bus_wq) { - destroy_workqueue(optee->scan_bus_wq); - optee->scan_bus_wq =3D NULL; - } + optee_supp_release(&optee->supp); } =20 diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_pr= ivate.h index 6bb5cae09688..94c0ee381894 100644 --- a/drivers/tee/optee/optee_private.h +++ b/drivers/tee/optee/optee_private.h @@ -178,7 +178,6 @@ struct optee_ops { * @pool: shared memory pool * @rpc_param_count: If > 0 number of RPC parameters to make room for * @scan_bus_done flag if device registation was already done. - * @scan_bus_wq workqueue to scan optee bus and register optee drivers * @scan_bus_work workq to scan optee bus and register optee drivers */ struct optee { @@ -197,7 +196,6 @@ struct optee { struct tee_shm_pool *pool; unsigned int rpc_param_count; bool scan_bus_done; - struct workqueue_struct *scan_bus_wq; struct work_struct scan_bus_work; }; =20 --=20 2.34.1