Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp246987rdb; Thu, 2 Nov 2023 02:26:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGxEadpB48rZW3SPtvHobvpct3ceLOrvnXwhLt5WMuu8gDIFgRJe7qdBWH+kUrBjQjlKe/v X-Received: by 2002:a05:6358:6f9c:b0:168:e8f8:c5cb with SMTP id s28-20020a0563586f9c00b00168e8f8c5cbmr22443079rwn.0.1698917200983; Thu, 02 Nov 2023 02:26:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698917200; cv=none; d=google.com; s=arc-20160816; b=lxApav36EhJKAq1cXvYlBjoxODa5MhhrgtLisNR0R1GC84GLdrsYlPomuCauRRAPnx J/kfrPnVkN/D+djAS/WNINqZj3lzgAr+hKiddpVGXyCsJS4rzxObk+bQa/OdiLR3oG7h xuhU9M3zzMV2Rl/0AAYejddFq8XA1FdMdRLPpOZ2T23GPqfu+TUb+EtLNTkf5/UkJq7L 9W39XyNgz0W52iS/frdcLSZF7b7reRCat1o/Sem10a8g0aijVGPpTF/xZtvsAbUHHLbR Kt+mRWg6KRoseDkiLs5T9Jp3Hg00BsPZzQPlCKbJuz9sMDVJPQuJWWyJl9wCdv2LLoRy 0uDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=y2j4aw7YBp5jH3zoZ5P27fk/bBVV//KerAOJCMIxdxw=; fh=m6nDvpRMvPWQKh2pDAsIIDvW7jSxS+ozBpbnJBViqZY=; b=u2Xv5LR3FNHYkcix4xJyzgv9/AVSP4U7EnUHihMGILQ29qgtx6M4FyuDOwDBXzrgfm sdtAhzHup+jxDrdUJ4vTTVXIr3RfGhSqp+Z8uUM4hv8snBF1mZjVpjftJSppGvBBL2E4 jkeguUCUkLXwihD/Gsxv/m81QwF8jTzmu2r733kJPsnyQiI2NJtKJyyQ9SlUY/z+mH3S 9TPlFhdKRq7xe7WRJh3MLN82/YsdvAgzSe5hqcOyjtK56gp1MXRU9JcrurozV5xt+aml qcZ5fl0SUgdxNPezOWU4ZTlWrIeoj0VNv/vje2KdgzqaHiRb+JxhZKi9lgIvCYyPKBMR Wz2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VSzvlD7l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id l71-20020a633e4a000000b005b95fa863c6si161277pga.661.2023.11.02.02.26.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 02:26:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VSzvlD7l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id CE7C3820E527; Thu, 2 Nov 2023 02:26:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345474AbjKBJ0i (ORCPT + 99 others); Thu, 2 Nov 2023 05:26:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229762AbjKBJ0g (ORCPT ); Thu, 2 Nov 2023 05:26:36 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4767123 for ; Thu, 2 Nov 2023 02:26:30 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-9c53e8b7cf4so101071766b.1 for ; Thu, 02 Nov 2023 02:26:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698917188; x=1699521988; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=y2j4aw7YBp5jH3zoZ5P27fk/bBVV//KerAOJCMIxdxw=; b=VSzvlD7lMjsGMtvRoZEVIiSbjxR5v8YfOeVLxUVXL+yPq9r/Q1qjMmCpEQApfS4ule sRyKWui9lAQDB+voot9LPfCbTaWbEhHLdGcpdLmsGcJXcB0dn4IX4tzTgH9PvmzcsyIO 5AtvGUaXs73FYqwUUhOrw6L0m5qI6FtFDjLUKf5I7vY440GGlT6r5wtZPb066ryetHLR qbAAYpmlrogP7+DhoGZ7xEgf/7r3gR7JS/zowj67uEh99WuU4Ovpd2XTA9QxOBLnghle kwYjVNed/p86HV8VelDLov5Pt4cL+n6hjvwcZSWV7RK3Dk1bgrWjiZhZqzgiqAOZCTd6 Z9FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698917188; x=1699521988; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=y2j4aw7YBp5jH3zoZ5P27fk/bBVV//KerAOJCMIxdxw=; b=KMqlwkq5Uu0NCK8PGtHjerJeIlwq36urutxjozvHYonR+h5rfy5sejPskKDqYVoNZO LH3sJ898VgKXLFYhoTkLGtSZ5XaXPK7J1hLTAC2Vv44sTae7EKnLvKSWAQfT3j3gzujs MTh/mi5uiG/sEjmH8jSW/RSp3AO4I7FxFtA2cZ2ZNVWIHkP0VznecHWM9bRIJV6EpzqC R7umGHenDcuMrTHLLd9PtS2UpYl3uoJD6G2MLa5ymMIcmDJddhnwQ3Y6J5J2aWwxAdX+ zDH4kLENzyyk9lhklmy03Z8j5nnHWOoN8KCgdFpGs1FliwDr3utufRhYMRqG11C+57cQ 6Xnw== X-Gm-Message-State: AOJu0YyZi/Bz6rYQsLLEkqCYhJZzt+i0pdgq08s173eGdssVXJGLw8bD c+5e620Bmar23I7+4uyL1gqEQQ== X-Received: by 2002:a17:907:c1d:b0:9d2:20ee:b1d0 with SMTP id ga29-20020a1709070c1d00b009d220eeb1d0mr3288072ejc.53.1698917187873; Thu, 02 Nov 2023 02:26:27 -0700 (PDT) Received: from ?IPV6:2a01:e0a:3cb:7bb0:12df:4a29:baa:4874? ([2a01:e0a:3cb:7bb0:12df:4a29:baa:4874]) by smtp.gmail.com with ESMTPSA id lo10-20020a170906fa0a00b009b947aacb4bsm881718ejb.191.2023.11.02.02.26.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 Nov 2023 02:26:27 -0700 (PDT) Message-ID: Date: Thu, 2 Nov 2023 10:26:26 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 1/2] tee: optee: Fix supplicant based device enumeration To: Sumit Garg , jens.wiklander@linaro.org, op-tee@lists.trustedfirmware.org Cc: jan.kiszka@siemens.com, 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 References: <20231102073056.174480-1-sumit.garg@linaro.org> <20231102073056.174480-2-sumit.garg@linaro.org> Content-Language: en-US From: Jerome Forissier In-Reply-To: <20231102073056.174480-2-sumit.garg@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Thu, 02 Nov 2023 02:26:39 -0700 (PDT) On 11/2/23 08:30, 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 adding an attribute for supplicant dependent devices so that > the user-space service can detect and detach supplicant devices before > closing the supplicant: > > $ for dev in /sys/bus/tee/devices/*; do if [[ -f "$dev/need_supplicant" && -f "$dev/driver/unbind" ]]; \ > then echo $(basename "$dev") > $dev/driver/unbind; fi done > > Reported-by: Jan Kiszka > Link: https://github.com/OP-TEE/optee_os/issues/6094 > Fixes: 5f178bb71e3a ("optee: enable support for multi-stage bus enumeration") > Signed-off-by: Sumit Garg > --- > .../ABI/testing/sysfs-bus-optee-devices | 9 +++++++++ > drivers/tee/optee/device.c | 17 +++++++++++++++-- > 2 files changed, 24 insertions(+), 2 deletions(-) > > diff --git a/Documentation/ABI/testing/sysfs-bus-optee-devices b/Documentation/ABI/testing/sysfs-bus-optee-devices > index 0f58701367b6..d914f6629662 100644 > --- a/Documentation/ABI/testing/sysfs-bus-optee-devices > +++ b/Documentation/ABI/testing/sysfs-bus-optee-devices > @@ -6,3 +6,12 @@ Description: > OP-TEE bus provides reference to registered drivers under this directory. The > matches Trusted Application (TA) driver and corresponding TA in secure OS. Drivers > are free to create needed API under optee-ta- directory. > + > +What: /sys/bus/tee/devices/optee-ta-/need_supplicant > +Date: July 2008 > +KernelVersion: 6.7 > +Contact: op-tee@lists.trustedfirmware.org > +Description: > + Allows to distinguish whether an OP-TEE based TA/device requires user-space > + tee-supplicant to function properly or not. This attribute will be present for > + devices which depend on tee-supplicant to be running. > diff --git a/drivers/tee/optee/device.c b/drivers/tee/optee/device.c > index 64f0e047c23d..4b1092127694 100644 > --- a/drivers/tee/optee/device.c > +++ b/drivers/tee/optee/device.c > @@ -60,7 +60,16 @@ static void optee_release_device(struct device *dev) > kfree(optee_device); > } > > -static int optee_register_device(const uuid_t *device_uuid) > +static ssize_t need_supplicant_show(struct device *dev, > + struct device_attribute *attr, > + char *buf) > +{ > + return 0; > +} > + > +static DEVICE_ATTR_RO(need_supplicant); > + > +static int optee_register_device(const uuid_t *device_uuid, u32 func) > { > struct tee_client_device *optee_device = NULL; > int rc; > @@ -83,6 +92,10 @@ static int optee_register_device(const uuid_t *device_uuid) > put_device(&optee_device->dev); > } > > + if (func == PTA_CMD_GET_DEVICES_SUPP) > + device_create_file(&optee_device->dev, > + &dev_attr_need_supplicant); > + > return rc; > } > > @@ -142,7 +155,7 @@ static int __optee_enumerate_devices(u32 func) > num_devices = shm_size / sizeof(uuid_t); > > for (idx = 0; idx < num_devices; idx++) { > - rc = optee_register_device(&device_uuid[idx]); > + rc = optee_register_device(&device_uuid[idx], func); > if (rc) > goto out_shm; > } Acked-by: Jerome Forissier Thanks! -- Jerome