Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp918982rwd; Wed, 7 Jun 2023 08:32:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6j21HrDPTsn+uBRpaQ6OOPiSmxoSrVag6jdrbtDrfOycuIRb821ZLpXd8DTOTRJfj2Su42 X-Received: by 2002:a17:903:189:b0:1b1:76c2:2966 with SMTP id z9-20020a170903018900b001b176c22966mr6585598plg.20.1686151968656; Wed, 07 Jun 2023 08:32:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686151968; cv=none; d=google.com; s=arc-20160816; b=1GGW490bilWCr8izTguB/qw7XASeOjYfLN7UpAdyGrORO3fgXH2hpHbN+Q50m9TpYr eVNX/48EszJaOD8Y2kudKtFjURdveLCgIwdDI0M4wn1ONPmMDdchB1UWhSEfRmCo0DjC rtlSoszkqB8x/0xJv9mm57kfcBcB//PtYHwh0G4lRCzzx2eIJ9O373ekEfJGIxQeC2Qg vD0AlY++31nzcsdE2kThDEntNRwtgmyJt856ZVtkO7AfAXut5otc/LVz5kYi4aogZ8GH bCE0hhXoqdxBVkbS7ee73bN977Fj015xu/HOhCn58d3sDV94MFSSbF/sVe1SV23bcFOg kzRQ== 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=mTsukKw+BIS5VUrX2hZ7HJxEmat0w3WDB9Ehs58lLcs=; b=Tbi/N16j21kYeCstflUSQa6LRpdo6G/iCOzY8geXpUFo3277eZRCZfKuZghyA6SqyH TIYCbNmain11H8+D+crSKCvMylSbGiY1SrSuTqdbeBzkLFLKO37bE+0SBnW7mhoqn4TR XoFqMrKOh2gGBFwFnVugdulQgQGcTkjuhJXBfXm3aSiGGY+wRlRuE7D34q4r0+wcGz8+ cXDqJuGM817892MSYA6gWPv1MYS4/lCVfSyCBPVwxtjtfOfmBSXqhRkYS/cfXYpM1luk qvenlmuRjN0UFR03vgdcbjWweyret7Uq+OgPtLcLVfSPFn6B5S+LSEv/IQZJpKq/9Dlu +8Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v0JwFjF3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v4-20020a170902b7c400b001b0266579desi8819939plz.608.2023.06.07.08.32.32; Wed, 07 Jun 2023 08:32:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v0JwFjF3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241285AbjFGPTA (ORCPT + 99 others); Wed, 7 Jun 2023 11:19:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241290AbjFGPSx (ORCPT ); Wed, 7 Jun 2023 11:18:53 -0400 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 823D61BFF for ; Wed, 7 Jun 2023 08:18:51 -0700 (PDT) Received: by mail-qt1-x82d.google.com with SMTP id d75a77b69052e-3f83971680eso4625601cf.0 for ; Wed, 07 Jun 2023 08:18:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686151130; x=1688743130; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=mTsukKw+BIS5VUrX2hZ7HJxEmat0w3WDB9Ehs58lLcs=; b=v0JwFjF3phSowDl0fS5dmxunvl8Gs6shwjlrdjCjLHWeHEfCexXx+34/kpgEc33WNb rSpSpeSWfD46k1frYJEcDqrMnfp07wcMri9RMpwfn+XB5mmJnJYPYHmcd3NFfAtMlryD faKxikZcA6aHNdrRzfCBtEBRdzFB/sGw1G145erEuh2wj67V+trv5+s8mTZJRejq5yrx xnhpdVIsfkbPaw+NEszd7QRLR1ujD1o0izxSZmIaORc7sQmc/HxidCWVaa77y+lDUVi1 szsTZQ0gjktBuy5t39kZIebzTcEYOu2UKui2NpecWUqfc9X54Tfskjtom++ivPCOV60Z EX/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686151130; x=1688743130; 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=mTsukKw+BIS5VUrX2hZ7HJxEmat0w3WDB9Ehs58lLcs=; b=A9G5BIH/+aB758M5M5COo4bnVqEzQ0AwuWN+yuuvnGk157fJS/xGNjItetXI8P//Da 3Wi5bNTLNkxJzUrbZFZdqLUZtosbNzx8o0HB9BHTlLJnV4r+Ns0vZ2cNaOjL6iffJa5F 8loOEAE0CxTDOgdSN5K1AcdWA79PYEALaDbrbw7tDRQJZy5yDiWGRsZugQB8WJGH/gfs 5H1uwss2pee5qFO7rnF1oyog1fuI2oQUgWVnu0RFhIaYiMTTe9yqLpDYq0PCnw0BudVZ yPjN3dtlcJmWuQNWGtpQAukZu7sGO0SS+CQb8b2KyVJgr1uLtmPjPnqkdgcQPpr0PnFA fzNw== X-Gm-Message-State: AC+VfDyHb7Tc4d2NINwhoJUmZWHZ6C3q3/E7FVpPWT0IKLT16Xgt07R7 AyyNlTMfnXV5Z3DNPCN+rRZzRQ0703ezmQ5nUSP48Q== X-Received: by 2002:ad4:5bc4:0:b0:625:aa49:ea0a with SMTP id t4-20020ad45bc4000000b00625aa49ea0amr3393123qvt.29.1686151130576; Wed, 07 Jun 2023 08:18:50 -0700 (PDT) MIME-Version: 1.0 References: <20230526010748.1222-1-masahisa.kojima@linaro.org> <20230526010748.1222-4-masahisa.kojima@linaro.org> <0d3e0370-eb76-010f-3d30-9acc9b59645c@siemens.com> <4ff09002-e871-38b9-43ec-227a64bac731@siemens.com> <76da826f-b608-6add-5401-6de818b180e3@siemens.com> In-Reply-To: <76da826f-b608-6add-5401-6de818b180e3@siemens.com> From: Sumit Garg Date: Wed, 7 Jun 2023 20:48:38 +0530 Message-ID: Subject: Re: [PATCH v5 3/3] efi: Add tee-based EFI variable driver To: Jan Kiszka Cc: Ilias Apalodimas , Ard Biesheuvel , Masahisa Kojima , Jens Wiklander , linux-kernel@vger.kernel.org, op-tee@lists.trustedfirmware.org, Johan Hovold , Maxime Coquelin , Alexandre Torgue , linux-efi@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, "Su, Bao Cheng (RC-CN DF FA R&D)" Content-Type: text/plain; charset="UTF-8" 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_NONE, 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 On Wed, 7 Jun 2023 at 18:10, Jan Kiszka wrote: > > On 07.06.23 10:25, Ilias Apalodimas wrote: > > Hi Sumit, > > > > On Wed, 7 Jun 2023 at 10:25, Sumit Garg wrote: > >> > >> Hi Ilias, > >> > >> On Wed, 7 Jun 2023 at 12:05, Ilias Apalodimas > >> wrote: > >>> > >>> Hi Jan, > >>> > >>> [...] > >>> > >>>>>>>> > >>>>> ... > >>>>>>> > >>>>>>> I think we have a probe ordering issue with this driver: > >>>>>>> efivarfs_fill_super() may be called before the TEE bus was probed, thus > >>>>>>> with the default efivar ops still registered. And that means > >>>>>>> efivar_supports_writes() will return false, and the fs declares itself > >>>>>>> as readonly. I've seen systemd mounting it r/o initialling, and you need > >>>>>>> to remount the fs to enable writability. > >>>>>>> > >>>>>>> Is there anything that could be done to re-order things reliably, probe > >>>>>>> the tee bus earlier etc.? > >>>>>> > >>>>>> This driver has a dependency on user-space daemon: tee-supplicant to > >>>>>> be running for RPMB access. So once you start that daemon the > >>>>>> corresponding device will be enumerated on the TEE bus and this driver > >>>>>> probe will be invoked. So I would suggest you to load this daemon very > >>>>>> early in the boot process or better to make it a part of initramfs. > >>>>>> > >>>>> > >>>>> That is not the point, really. > >>>>> > >>>>> If this dependency exists, the code should be aware of that, and made > >>>>> to work correctly in spite of it. Requiring a module to be part of > >>>>> initramfs is not a reasonable fix. > >>>> > >>>> In fact, I've tested a non-modularized build as well, just to exclude > >>>> that issue. The daemon dependency is more likely the problem here. > >>>> > >>>>> > >>>>> IIUC, this also means that the efivar ops are updated while there is > >>>>> already a client. This seems less than ideal as well > >>> > >>> As Sumit pointed out, the 'device' won't be available from OP-TEE > >>> until the supplicant is up and running and as a result, the module > >>> _probe() function won't run. Unfortunately, this isn't something we > >>> can avoid since the supplicant is responsible for the RPMB writes. > >>> The only thing I can think of is moving parts of the supplicant to the > >>> kernel and wiring up the RPC calls for reading/writing data to the > >>> eMMC subsystem. There was another discussion here [0] requesting the > >>> same thing for different reasons. But unless I am missing something > >>> this won't solve the problem completely either. You still have a > >>> timing dependency of "when did the RT callbacks change" -- "when was > >>> my efivarfs mounted". > >> > >> With the RPMB writes wired through the kernel [1], the only dependency > >> left is when do you load the tee-stmm-efi driver to have real EFI > >> runtime variables support. IMO, tee-stmm-efi driver should be built-in > >> to support systems without initramfs. The distro installers may choose > >> to bundle it in initramfs. Do you still see a timing dependency with > >> this approach? > > > > No I don't, this will work reliably without the need to remount the efivarfs. > > As you point out you will still have this dependency if you end up > > building them as modules and you manage to mount the efivarfs before > > those get inserted. Does anyone see a reasonable workaround? > > Deceiving the kernel and making the bootloader set the RT property bit > > to force the filesystem being mounted as rw is a nasty hack that we > > should avoid. Maybe adding a kernel command line parameter that says > > "Ignore the RTPROP I know what I am doing"? I don't particularly love > > this either, but it's not unreasonable. > > In the context of https://github.com/OP-TEE/optee_os/issues/6094, > basically this issue mapped on reboot/shutdown, I would really love to > see the unhandy tee-supplicant daemon to be overcome. I have seen this error before and it has been on my todo list. So I have tried to fix it here [1]. Feel free to test it and let me know if you see any further issues. [1] https://lkml.org/lkml/2023/6/7/927 -Sumit > > Jan > > -- > Siemens AG, Technology > Competence Center Embedded Linux >