Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp215441rdb; Thu, 2 Nov 2023 01:10:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGWtxXGmt5tiglI05g+FmvPcLwm64XEzN+4y2mmCC0VENJmHXCUJkQfRI/rDXsovulyA+X8 X-Received: by 2002:a17:903:2351:b0:1cc:37b9:4953 with SMTP id c17-20020a170903235100b001cc37b94953mr13840512plh.67.1698912604905; Thu, 02 Nov 2023 01:10:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698912604; cv=none; d=google.com; s=arc-20160816; b=wyexRw/Ig0gJKveJ4yO/JsfUWsBzMCe7hg0cXcWPkiuIJCIuSlDOl5tVAAZcAthQP+ IkEOUsLgAKn0kmD71imCO7g+dc99pyDhBe+5kyRKwXo5mtsUKHY0lQQXdpcj6SU2Zdza JqTOqwjyZlMwgQhcBBP2KQY/6AnbIu8fCVWbIU8BgaXJT9IP75OWC71tv+aLA0cuCSuK hO5R3rJeslOnS09yyeex39VN8DaFhdFvOk59jcj14Xv3Cy05p9bH5CacvT2Kk98bXocG prQBAnNPQ6znqLNpGzxs0YffjZPBzZywaHOiDhXovHrtbLe3qAM4/vDq2OjkTqhIizWE 3JHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=3yGEMJ9IFoeOVwT4DcSTqO8vZq3/GXtKgmjkxRhuWPU=; fh=6jvnDHLMWK61LUhd+FoawwXyGllFHdSI8zSvU29Dwzw=; b=d8FYGEc9JJoFWgnWQRfzJqlMKRgkKhfhXlMlV8Q+8Oq9YtngYhgWZlmwRocCl6q+tI mMj8YQ7YS2CrDLqJm/PeY/TkSsb12d2WcFAQUA2ShG3DL8Yuaza/dv8NMl5OEkTAVVCb TdoN6KHBMgD94NuqNCjkhXpSplF3zjjVhaP/6JNzuB6WXNgNSuTk4Esdt3d/D6SP/Lwx g04cvDQQLUw+6mArVZkZGGS/PO8zNw0vJh2H+k6r12h3az8YaZMamPk0mDhIW1sGZAQy NEfXeasPZZffCpm4ery6sHuzRU+hI3QfPgKL7thN4h649Z0Z5jHMEGdugKrhQztSPkCs yaaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XhuW3sxh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id t17-20020a170902d29100b001b8a56b9895si4373801plc.616.2023.11.02.01.10.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 01:10:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XhuW3sxh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id F232C80F61B7; Thu, 2 Nov 2023 01:09:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233093AbjKBIJU (ORCPT + 99 others); Thu, 2 Nov 2023 04:09:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbjKBIJT (ORCPT ); Thu, 2 Nov 2023 04:09:19 -0400 Received: from mail-ua1-x92a.google.com (mail-ua1-x92a.google.com [IPv6:2607:f8b0:4864:20::92a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEB72128 for ; Thu, 2 Nov 2023 01:09:13 -0700 (PDT) Received: by mail-ua1-x92a.google.com with SMTP id a1e0cc1a2514c-7b9dc92881eso283283241.2 for ; Thu, 02 Nov 2023 01:09:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698912553; x=1699517353; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=3yGEMJ9IFoeOVwT4DcSTqO8vZq3/GXtKgmjkxRhuWPU=; b=XhuW3sxhyyKDQ/pP/FJ/3t5TfI9rdc6jGwLKEZIoVtuYee1PM3JnpVW3ieLtHWzz6T 1Sp7uGamcMXDoV8q3eOcdlreNGHKTWu9eMODqQTrnJ5i29R8YfGU6og072iYGv2QQFxZ yXdcauID5BkLhasPSVO+h4nVIc3R7/gi0THQVALLouKQ+4DInTd3GAybpC/v6BHy+AtF MihBC+NOv8YWZ2Opf41ypWl38veUbyLYpMyHjGxoKhMIHUp5qOttNrVXw1mAlkg8mJG3 lxIMhxHN7pkdmbc7EnFwbbHqNuo3nUiWQ/qtnKroOSqEPTWW1EoSHp7xB/HwHywCq3on XKDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698912553; x=1699517353; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3yGEMJ9IFoeOVwT4DcSTqO8vZq3/GXtKgmjkxRhuWPU=; b=er/JPQI61O7ON+5U9ArZytVtKIEstHi9+l5eJAW1oURRDGT68w/uvdeocDsC+kceQ+ cPcefm/9IM5KMaG9T0Om6OMzycg7iYsvh/b7ntuqq4pSH08b7w22vwt9WLTByQJbDxRJ mRNvU+G/hJTdEbJHa9SDHwe+FNQN2WnRITF+0MMaW5PIfK2fWIkaeOQHZ780IsOjpROB Lkz0e892LLL/L/yvlyrw4AGr3oIABORvSl9HeZZl+hzd74uCJEOuouLBBtURMzqHMqvb WlQP7tpP2VIidB+mA8ae3YJcx/8DyISrBo1PTJoGKfGzVGKDjiIZoQsVQtcGLHZve3uU BArA== X-Gm-Message-State: AOJu0Yz700OI1wvlPyGZ84MSCwSENm/HPIMF5/MWDuJAdKRzn/zz6dKa r3Nn3C/rjOH2X9ot26ZUaXje6JGW0R/P6BQ0wr04VpwmufKDrzXL X-Received: by 2002:a67:c199:0:b0:452:7f81:1502 with SMTP id h25-20020a67c199000000b004527f811502mr17046562vsj.26.1698912552860; Thu, 02 Nov 2023 01:09:12 -0700 (PDT) MIME-Version: 1.0 References: <20231030155901.80673-1-sumit.garg@linaro.org> <20231030155901.80673-2-sumit.garg@linaro.org> <1418e74e-175f-4b04-90d7-8bec2987c207@siemens.com> <61eb38c9-e40d-456a-86c8-e2d851b947f8@siemens.com> In-Reply-To: <61eb38c9-e40d-456a-86c8-e2d851b947f8@siemens.com> From: Sumit Garg Date: Thu, 2 Nov 2023 13:39:01 +0530 Message-ID: Subject: Re: [PATCH v3 1/2] tee: optee: Fix supplicant based device enumeration To: Jan Kiszka Cc: Jerome Forissier , jens.wiklander@linaro.org, op-tee@lists.trustedfirmware.org, arnd@linaro.org, ardb@kernel.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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 02 Nov 2023 01:09:55 -0700 (PDT) On Thu, 2 Nov 2023 at 13:35, Jan Kiszka wrote: > > On 02.11.23 09:02, Sumit Garg wrote: > > On Thu, 2 Nov 2023 at 13:28, Jan Kiszka wrote: > >> > >> On 02.11.23 08:37, Sumit Garg wrote: > >>> On Tue, 31 Oct 2023 at 17:14, Jan Kiszka wrote: > >>>> > >>>> On 31.10.23 12:04, Jerome Forissier wrote: > >>>>> > >>>>> > >>>>> On 10/30/23 16:59, Sumit Garg wrote: > >>>>>> 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); > >>>>>> } > >>>>>> > >>>>>> -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 = NULL; > >>>>>> + const char *dev_name_fmt = NULL; > >>>>>> int rc; > >>>>>> > >>>>>> optee_device = kzalloc(sizeof(*optee_device), GFP_KERNEL); > >>>>>> @@ -71,7 +72,13 @@ static int optee_register_device(const uuid_t *device_uuid) > >>>>>> > >>>>>> optee_device->dev.bus = &tee_bus_type; > >>>>>> optee_device->dev.release = optee_release_device; > >>>>>> - if (dev_set_name(&optee_device->dev, "optee-ta-%pUb", device_uuid)) { > >>>>>> + > >>>>>> + if (func == PTA_CMD_GET_DEVICES_SUPP) > >>>>>> + dev_name_fmt = "optee-ta-supp-%pUb"; > >>>>>> + else > >>>>>> + dev_name_fmt = "optee-ta-%pUb"; > >>>>> > >>>>> That's an ABI change, isn't it? > >>>> > >>> > >>> Indeed it is an ABI break although we would like this to be backported > >>> but don't want to break existing users. So I brainstormed on it and > >>> came up with an alternative fix via device attribute in v4. Please > >>> have a look. > >>> > >>>> Oh, here did this come from! Yes, I recently had to adjust some systemd > >>>> service due to carrying this patch but looking for the change only in > >>>> upstream: > >>>> > >>>> https://github.com/ilbers/isar/commit/83644ddf694e51f11793e6107e4aaf68dc0043a5 > >>>> > >>> > >>> You don't need to unbind all of the optee devices. v4 would help you > >>> to maintain backwards compatibility, can you retest it? > >> > >> How do I know from tee-supplicant perspective which devices I need to > >> unbind? There could be one in the future that will also use storage and > >> will therefore also fail once the supplicant is gone. > >> > > > > With v4, the devices where the below attribute is present need to > > unbind before closing tee-supplicant. > > > > /sys/bus/tee/devices/optee-ta-/need_supplicant > > OK - but that will only help in future kernels, nothing we have today. > Thus, the shutdown script cannot assume to alone kill those devices > unless it find a certain upcoming kernel release. > This v4 fix will be backported to stable kernels. So you can update your scripts once it lands into your stable tree. -Sumit > Jan > > -- > Siemens AG, Technology > Linux Expert Center >