Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp325740rdf; Fri, 3 Nov 2023 01:36:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGKCrhqh/pIgy4mcgqhBQ7SKdfV+IacqlR7fqHb9jbNX4ndu7lEy0zfLvvxNlYJcGo4qmV7 X-Received: by 2002:a05:6a20:734f:b0:172:f4e:5104 with SMTP id v15-20020a056a20734f00b001720f4e5104mr20165987pzc.20.1699000581356; Fri, 03 Nov 2023 01:36:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699000581; cv=none; d=google.com; s=arc-20160816; b=ZzCAEgdaAbjuwb+ESpmIsPVG631dcBhcNMGGOCzZ32x1ZX539+u8pkw9n8UgXWXYnn bDVsjdtpgqOcrt9yzuB0gTJdOZ1I/j7sYCd3m1Ybese4KNGGGeGxSEcAuPC5VGspSEEw /uKLByhDhg7X9aaF4MEkaZk9paxL+TgtyIdIzW+uPrfCnsafS3soDmOg6BJvs9rvUb3y dlyZSfgX/N5Xk612K8NGRr8nQjMX/NUpTfSohnfZeBXQCmCv/kSK1dZ4Aa9DAKnqJ/TZ AL1Gfwz6cqLVAHCQDugu7oI2JIJ8KKWKyEBm7xIBhe76Kgs5+63DVRgE4MgDSCYZA0yX 7/cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=3nQWbcL/T3TlB1kRiOiag95+zWhxfHJr1Pmr2d9D+9g=; fh=5nL8Y7RbZWsRaiFsC+oltFOP2FnimRs4cvMnLmTXzPY=; b=ZY6NGLBM3mm3s5XlEczHX8M1ONrbe6kAVSk+MvaqQaPpNMQXC8P2HIg2rSwY8HsA82 z6T+X8QaGE0B3Cb5+N5/VjuE3SEKvcL3xfGbYGH/7JyE+tIVVzq2b1B2KDIlVhyo8rFj o2nSQGyPqeD4uUPs9iRzJLnlHrhF8AF8gMGTlpVrOj6+OZSAXgTSdKqzlqHUyn9SPrs7 DvDnah0hukPVkbYzALTyroONV/JdUdWGuBT/nT2ckiMqFTn4yEtuoAW0wXaBpZq3Oxzh QBl1WouBITz3gNG6x6HbMXLA2SbPLSxYSnUQ+2zEmmliQkI0jHYt0dTdrG/IClbieGCm gxLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="YQVK7PF/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id m10-20020a170902c44a00b001c9d96cbd97si1096453plm.66.2023.11.03.01.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 01:36:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="YQVK7PF/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 719148075ECC; Fri, 3 Nov 2023 01:35:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346433AbjKCIfO (ORCPT + 99 others); Fri, 3 Nov 2023 04:35:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346462AbjKCIfM (ORCPT ); Fri, 3 Nov 2023 04:35:12 -0400 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DCD9D44 for ; Fri, 3 Nov 2023 01:35:07 -0700 (PDT) Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-6754b4091b6so10227216d6.3 for ; Fri, 03 Nov 2023 01:35:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699000506; x=1699605306; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=3nQWbcL/T3TlB1kRiOiag95+zWhxfHJr1Pmr2d9D+9g=; b=YQVK7PF/aMkEdA4TBNiIHNokXsWd40GWGEq2V2Zl/K+b3tWX1jr3FJ5ii9wWss143S ACLGrbu3Wzpw4U55EPArfsHlBTnnrgDnpV+a4gVw2yP9D0SWlU2/nikaFfVpiLhb1qdk Pe9WJ4+PsvwMwfayGcydLfXnOuNlaVU3kZwLIJXvXKjWqsx2a5ktQ3+DUCQrpI4PTb91 Zu8N5Lohow0UB4ecD0cP6w80YvKtk4CKTpil+7ZILUFiUuk/f7281f2TiN+CAj3huf8z Q4xzZdGBRRcVE0hjv2uuprc/bf2hymLFP6RAUODSPDvlXGi2pUKLTwbdm39JhzKv2v0g 4QzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699000506; x=1699605306; h=content-transfer-encoding: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=3nQWbcL/T3TlB1kRiOiag95+zWhxfHJr1Pmr2d9D+9g=; b=n0WswvDrLJd73LvoxrN2oiIGpDP0qZcPFTDebEOLAAwcWGk6EV2yZrGkIiyKU864pW 7cwQMobbYcXFbRJpMTgEEQUVFYJd5Kg1qqU/FV4k2rZwNqKrBQH06rb4/6aOwCsINr4b G+jF8Vnt7GflHaVJ52usXtojWY91Z+MaP1miPn6a8ehYgmfEezNT/gIEN5dHMU8SXNsk VGtxHEAalsz0rxg4TAnkAG6f4GiDRT5IGewcW2mV4WAPMWxWhDwRZHPaheYRbxYuRth8 VqsXi8s5/tnksQGt65twGxm86PcF8bpkyUDGVttRssQs+kWF8iD/WVo9dU46M7wc3wRj M6jA== X-Gm-Message-State: AOJu0YyxgyCfegKhERSHtJyecnJ+6gyptUXZlOo+EToCi/kYwZcIZKkt I8Px1pcooCdMarvjQKs23tqhb9QnmsUFJmFx2Y16Ew== X-Received: by 2002:ad4:5bc4:0:b0:671:567d:b134 with SMTP id t4-20020ad45bc4000000b00671567db134mr18052970qvt.56.1699000506207; Fri, 03 Nov 2023 01:35:06 -0700 (PDT) MIME-Version: 1.0 References: <20231102073056.174480-1-sumit.garg@linaro.org> <20231102073056.174480-2-sumit.garg@linaro.org> In-Reply-To: From: Jens Wiklander Date: Fri, 3 Nov 2023 09:34:55 +0100 Message-ID: Subject: Re: [PATCH v4 1/2] tee: optee: Fix supplicant based device enumeration To: Sumit Garg Cc: Ilias Apalodimas , op-tee@lists.trustedfirmware.org, jan.kiszka@siemens.com, arnd@linaro.org, ardb@kernel.org, jerome.forissier@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" Content-Transfer-Encoding: quoted-printable 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Fri, 03 Nov 2023 01:35:39 -0700 (PDT) Hi, On Fri, Nov 3, 2023 at 6:52=E2=80=AFAM Sumit Garg w= rote: > > Hi Ilias, > > On Thu, 2 Nov 2023 at 19:58, Ilias Apalodimas > wrote: > > > > Hi Sumit, > > > > On Thu, 2 Nov 2023 at 09:31, Sumit Garg wrote: > > > > > > Currently supplicant dependent optee device enumeration only register= s > > > devices whenever tee-supplicant is invoked for the first time. But it > > > forgets to remove devices when tee-supplicant daemon stops running an= d > > > 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 t= hat > > > the user-space service can detect and detach supplicant devices befor= e > > > closing the supplicant: > > > > > > $ for dev in /sys/bus/tee/devices/*; do if [[ -f "$dev/need_supplican= t" && -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 Checkpatch complains here, we should use "Closes:" instead of "Link:". > > > Fixes: 5f178bb71e3a ("optee: enable support for multi-stage bus enume= ration") > > > 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/Docu= mentation/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 u= nder this directory. The > > > matches Trusted Application (TA) driver and correspon= ding TA in secure OS. Drivers > > > are free to create needed API under optee-ta- d= irectory. > > > + > > > +What: /sys/bus/tee/devices/optee-ta-/need_supplicant > > > +Date: July 2008 > > > > nit, date needs changing > > > > Thanks for catching that. If nothing major comes up then I hope Jens > can correct it while applying. Sure, I can update it to November 2023. I'll fix the date and the "Closes:" tag if there's no v5. Cheers, Jens > > > > +KernelVersion: 6.7 > > > +Contact: op-tee@lists.trustedfirmware.org > > > +Description: > > > + Allows to distinguish whether an OP-TEE based TA/devi= ce requires user-space > > > + tee-supplicant to function properly or not. This attr= ibute 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 *de= v) > > > kfree(optee_device); > > > } > > > > > > -static int optee_register_device(const uuid_t *device_uuid) > > > +static ssize_t > > > > (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 =3D NULL; > > > int rc; > > > @@ -83,6 +92,10 @@ static int optee_register_device(const uuid_t *dev= ice_uuid) > > > put_device(&optee_device->dev); > > > } > > > > > > + if (func =3D=3D 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 =3D shm_size / sizeof(uuid_t); > > > > > > 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; > > > } > > > -- > > > 2.34.1 > > > > > > > Other than that > > Reviewed-by: Ilias Apalodimas > > Thanks. > > -Sumit