Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2561781imn; Tue, 2 Aug 2022 07:40:25 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vfYPXEi0qKMIvPFYIno8c856aCwmqcXt+I468sXLyzy/MwOcyln5UuqKE6BKOSBp9gpZJV X-Received: by 2002:a17:907:6087:b0:72f:36ff:7fa2 with SMTP id ht7-20020a170907608700b0072f36ff7fa2mr16590174ejc.162.1659451225296; Tue, 02 Aug 2022 07:40:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659451225; cv=none; d=google.com; s=arc-20160816; b=BBMdWBspxMizFD/pMUdXZwgY8Sy45aMMonc6F08GunK9Y44LWDQAf5Gcug6hZH4V72 H3UEHiVcp0nxfKH7xUDiu/Xo3u5WJRHS4HTRXGS9lrEN6n/oN/LAnCVITZhp+uzRXOB5 v+5RsNmt+NbDLR4Q4UJiOOYHgQB4UAzUPeLyDhCtsMA6lnz3XckrwZafstIzQuOUlnF1 wYQojmU7BnLL6ugh7ctkDqZFMYuxzzA5lCCtBDcxA65nT3IsqXA/L2C9W553yL7IdN3w X3Udii7yy94PqFFnuScwlnDMOPnE98DA16183vWrtBCvD6uUab7TxzVFwU9WWwUM9JAI A1zQ== 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=+sYeDl9rp/TeBfB2n6kjUtAp39pXLT7aY/zLB/keaxU=; b=0o3OmeBIqVrBcT0MbMsbtvFOYsuz8gN9SgDqFEbBDq4L+iolu9v2YgIzEeGmnSjn9q Xeb39T+V8bub3OufigWpd78ZkZfDFaXq8pfrwYG6ziHCLq3aPRM/mIzOf7Y0SX0fhoZd 2BJazKwjMjksXM1+pVvZ5WGhQ+fB4IBCp1rBmUk54LVAwfTg78xAipKyoaB19gTftMVf 3mtJEh/QSXziMnbNpUWWibWpWAI9OwLaknQVwvmzu2+NOn3Qw85G375pu6sVvW5geAqd +SMhawKb6AMEA+jsBw8UO1uqcpjrT7e7kw7LIcN2QMffWS5CCWL+/H7h+tw+9pqhIJvC Rfeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vDblaSuP; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a6-20020a1709063a4600b0072b57c1f238si13375311ejf.291.2022.08.02.07.40.00; Tue, 02 Aug 2022 07:40:25 -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=@kernel.org header.s=k20201202 header.b=vDblaSuP; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237133AbiHBODD (ORCPT + 99 others); Tue, 2 Aug 2022 10:03:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237219AbiHBOCj (ORCPT ); Tue, 2 Aug 2022 10:02:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CA3C2CCBB; Tue, 2 Aug 2022 07:02:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 18B8861470; Tue, 2 Aug 2022 14:02:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75E3FC433C1; Tue, 2 Aug 2022 14:02:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659448949; bh=9x8ASZ0DiQgO5GNP2Mu6gvzA5hkYQ45AJslM0qDehok=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=vDblaSuPvLl+nPY4rTYEgQYQmOu7xnBbaFZQ1DS6DpW29hypZFzjTo2dZORIMQEog 4HYtAhBYTBUHrqnwX/sK65wjMCec1VYVM9xeYqSkHAM+tuYfFWkhVugNJceDjeSxx2 +jxKBkyJL0xsfBLV5Hh3Rj8rrrgBQcdrr7eSgKOPQfB5hcXLxPaTwdrTFGkTHJvkWZ 3Sh6/9Kq8A1kw5sRKBt5gybbcyKhv/loE5AzXiPldDsyw5m65F7i2n8+atBot+PQT3 Vo6MS0yKGg2sZQTVgEGetNeb/0YeM4PJnmT5Q45y1mrRD6mPcigGptJ/a67+ntU3L9 Vv+ElTHoEuMbw== Received: by mail-oi1-f179.google.com with SMTP id u9so16582429oiv.12; Tue, 02 Aug 2022 07:02:29 -0700 (PDT) X-Gm-Message-State: AJIora9hc1sl82UhiFy6Qwj1Kfs7ZppOdS4j53UnNfxTzw1hrBoQP7d+ 9fovh1dVVbcjotOPQ6qUy7o8mq11Xve3bE6biSQ= X-Received: by 2002:a05:6808:1489:b0:33a:861c:838e with SMTP id e9-20020a056808148900b0033a861c838emr8253279oiw.228.1659448948586; Tue, 02 Aug 2022 07:02:28 -0700 (PDT) MIME-Version: 1.0 References: <20220723224949.1089973-1-luzmaximilian@gmail.com> In-Reply-To: From: Ard Biesheuvel Date: Tue, 2 Aug 2022 16:02:17 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 0/4] firmware: Add support for Qualcomm UEFI Secure Application To: Maximilian Luz Cc: Srinivas Kandagatla , Andy Gross , Bjorn Andersson , Konrad Dybcio , Rob Herring , Krzysztof Kozlowski , Steev Klimaszewski , Shawn Guo , Sudeep Holla , Cristian Marussi , Greg Kroah-Hartman , linux-arm-msm , linux-efi , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 Tue, 2 Aug 2022 at 15:22, Maximilian Luz wrote: > > > > On 8/2/22 13:51, Srinivas Kandagatla wrote: > > Hi Maximilian, > > > > On 23/07/2022 23:49, Maximilian Luz wrote: > >> On modern Qualcomm platforms, access to EFI variables is restricted to > >> the secure world / TrustZone, i.e. the Trusted Execution Environment > >> (TrEE or TEE) as Qualcomm seems to call it. To access EFI variables, we > >> therefore need to talk to the UEFI Secure Application (uefisecapp), > >> residing in the TrEE. > >> > >> This series adds support for accessing EFI variables on those platforms. > >> > >> To do this, we first need to add some SCM call functions used to manage > >> and talk to Secure Applications. A very small subset of this interface > >> is added in the second patch (whereas the first one exports the required > >> functions for that). Interface specifications are extracted from [1]. > >> While this does not (yet) support re-entrant SCM calls (including > >> callbacks and listeners), this is enough to talk to the aforementioned > >> uefisecapp on a couple of platforms (I've tested this on a Surface Pro X > >> and heard reports from Lenovo Flex 5G, Lenovo Thinkpad x13s, and Lenovo > >> Yoga C630 devices). > >> > >> The third patch adds a client driver for uefisecapp, installing the > >> respective efivar operations. The application interface has been reverse > >> engineered from the Windows QcTrEE8180.sys driver. > >> > >> Apart from uefisecapp, there are more Secure Applications running that > >> we might want to support in the future. For example, on the Surface Pro > >> X (sc8180x-based), the TPM is also managed via one. > >> > >> I'm not sure whether this should go to drivers/firmware or to > >> drivers/soc/qcom. I've put this into firmware as all of this is > >> essentially an interface to the secure firmware running in the TrustZone > >> (and SCM stuff is handled here already), but please let me know if I > >> should move this. > > > > From what I see so far is that this is adapted from downstream qseecom driver, this approach could work for a limited usecases but not scalable, as we cannot add drivers for each Qualcomm specific TA in kernel. > > This has to be handled in much generic way using Linux TEE framework, and let the userspace side deal with TA specific bits. > > I generally agree with the sentiment, however UEFI variables should IMHO be > handled by the kernel. Moving handling of those to userspace breaks things like > EFI-based pstore and efivarfs. The latter will in turn break some user-space > tools (most notably efibootmgr used by e.g. GRUB and I think fwupdmgr which > needs to set some capsule variables). Ideally, we would find a way to not break > these, i.e. have them work out-of-the-box. > Only capsule-on-disk requires SetVariable() at runtime, and I doubt whether these platforms implement any of that. > A similar argumentation might apply to the TPM app. > There is a difference, though - the TPM is modeled as a device and runtime access to it is implemented as a device driver, which is only accessed from user space. > > AFAIU, Qualcomm is moving away from qseecom interface to new smc-invoke interface, most of Qualcomm SoCs starting from SDM660 already have support to this. > > > > This interface provides a better abstracted IPC mechanism to talk to TA. Most of these TA specific interfaces are packed in closed userspace source. > > Having said that QTEE smcinvoke driver can be modeled as a proper TEE driver with Userspace driving the TA specific bits using existing tee uapis. > > This also brings in other features like loading, Listeners aka callbacks, secure memory allocations..etc. > > > > In the past, I have tried to do a prototype of this smcinvoke driver as a proper tee driver, incase you are interested patches are at https://git.linaro.org/landing-teams/working/qualcomm/kernel.git/log/?h=tracking-qcomlt-qcomtee > > Plan is to discuss with Qualcomm and send it for upstream review. > > Thanks for this information! So as far as I understand it, this is currently an > interface to user-space only, i.e. does not allow in-kernel drivers for apps? > It would be great if this could then be extended to handle (the bare minimum > of) in-kernel drivers (i.e. only things that the kernel itself needs, like EFI > variables). Alternatively, I'm happy to hear suggestions on how we not break > the aforementioned things while moving handling off to userspace. > > > I think its worth exploring if uefisecapp can talk smcinvoke. > > I can ping Qualcomm engineers to see if that is doable. > > I think that would be great! Thanks! > > Regards, > Max