Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1020854pxb; Thu, 26 Aug 2021 22:28:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyg3greAyL0pzdfYM6W3VQlED/xsf8VK1EZCXnrj4gua0KwWaQizZRZyMT/w2tyP9iS7ZIR X-Received: by 2002:a17:907:7755:: with SMTP id kx21mr8017703ejc.463.1630042137204; Thu, 26 Aug 2021 22:28:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630042137; cv=none; d=google.com; s=arc-20160816; b=HquFlhpfe4fpEdIrrkEjopaL02guB5N4MDybgP+bezUItu220PAqLpXwlh6suNPFSq 1w98+vn4ZWkDsG/mfmFq2Zyhq903EHzxnUDBRuighjmyQDyfIjN1mS9wXQAV9FY37NJx I4grss13+9l5RjD4+NKGI10FNi8c0cdTi1pjyfIi2a/nvhROV7c3tYTawg4d3/B11ACb vvvXcx6Fyut4kHRkjYjCw6UQw9WWoGhjNhk5gJNapNQXzejUCy4pngq6VY2EPfPGprFm Tb210fvO4Rj/i3W8M+ulkFnWTozOKngO3J6rohThbmkzi7traW4feoLFbS03ydHs5P4M JwkQ== 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=aCNGlXY6361ZigaIW6incXr5mbnDjyMCYDuUlz3Yj5o=; b=zqDPS7ocyIHszqi/2UVXCE5tmtGMc4TTlW75mZ7S16MPXjRVEn9/QXouYH0ocbRO5f mwtEglxP+SZ4EyaWt1muDE385UxgJgmYiLQ9CU0LB9QbxUISIDPyVRDU7xPWsbL5/dFN I5fbtCyfte7TlYhzEVLBBZ7tRR0FcRLwBorxUQ8teBB6RLBcXlgFeUeLO1XaVGWMDDyH GeRAlCrp1OrdcTX7QdvnPnjB2r6blHu3GhLaHI4RmrfKz0Rm9ztPo8LK+GaF/zI0jIhJ BOj+B67Yz3NW9XPZKPqVX6dAnZAJKe83/+uXMU7C52ET9vQF2NT/DGlr5VQPcaPWs3g1 MjMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oqzvMaeI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u12si3242630eds.392.2021.08.26.22.28.34; Thu, 26 Aug 2021 22:28:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oqzvMaeI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S244218AbhH0F2D (ORCPT + 99 others); Fri, 27 Aug 2021 01:28:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229645AbhH0F2C (ORCPT ); Fri, 27 Aug 2021 01:28:02 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A31ACC061757 for ; Thu, 26 Aug 2021 22:27:13 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id bq28so11897934lfb.7 for ; Thu, 26 Aug 2021 22:27:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aCNGlXY6361ZigaIW6incXr5mbnDjyMCYDuUlz3Yj5o=; b=oqzvMaeIs4iTOzMP6wvTn2+1nJhI0RmOfTsl15fEzOJgN4u+b4TXv02mvvwjb78HtJ K04ToZZHp3fgqTptx3kNY+aUf2oQPYWcWPBp6tddPPiFq+xNvQNnpH/5oP2ls3J0a/u0 XXPl5CDSP5u4li6Nu74m5jLGmmJxw6FvQbXUQWBtDAZz5L79Evx3oHyv3BLhcmViZjHt uBecX5sD7TDTog+pxuazs6325QK7eFb40ERjNgOgFYr1TXRCrWqdtuEKqQq1Kg8AeHMv KsINC8AnwVjpkX9JCfnosFfxAW+Z9h+nXz1Vdtvgx7EHmaP+LVG8yISs3+xu9Yx1LzQ5 4OzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aCNGlXY6361ZigaIW6incXr5mbnDjyMCYDuUlz3Yj5o=; b=Kl7vmdh7L1+3SmL9a1ZpV9OgFxGcjFswSMIGQQ7c4L92GLBovWbi1t5RddW+oO/Qhf UzRTW0EWbjUYbBOGKxcCg2B/CTIgnD0YPEcrpdS4afQNA+yoSlN4KV7NwYUDheIooF3g J8u6V54SlggoTb2GkANGkO24Q4hljrCwhS2tp+JiwH3+Q879syC4sjLj9tx/byRB9tJL hlWU2ykJWwDgO/p0dIQeAk8vwA5/gBWyi91Y1ged/fAL1thXAxAF/k05fOvaw9NIMdL7 bg26LqiKN6X1ETrscBNt3F2Hphx62Wx6slayVOUB2wMmaZ9/7EjDd4Om3dcYJTMFCVeU D74w== X-Gm-Message-State: AOAM531k1F7nDt+a5IEauMlK/itgOuM5xqoOgiz4vNxfq0RuEJN2O8fq LjCXakxW9ktZJDqCbjZ/wHSPMYc9eMv+8jVmrrLmBw== X-Received: by 2002:ac2:5c4c:: with SMTP id s12mr5211187lfp.108.1630042031913; Thu, 26 Aug 2021 22:27:11 -0700 (PDT) MIME-Version: 1.0 References: <20210819110655.739318-1-jens.wiklander@linaro.org> <20210819110655.739318-6-jens.wiklander@linaro.org> <20210826145213.GA1739293@jade> In-Reply-To: <20210826145213.GA1739293@jade> From: Sumit Garg Date: Fri, 27 Aug 2021 10:57:00 +0530 Message-ID: Subject: Re: [PATCH v4 5/5] optee: add FF-A support To: Jens Wiklander Cc: Linux Kernel Mailing List , linux-arm-kernel , OP-TEE TrustedFirmware , Sudeep Holla , Marc Bonnici , Jerome Forissier , Sughosh Ganu Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 26 Aug 2021 at 20:22, Jens Wiklander wrote: > > On Wed, Aug 25, 2021 at 05:12:45PM +0530, Sumit Garg wrote: > > On Thu, 19 Aug 2021 at 16:37, Jens Wiklander wrote: > > > > > > Adds support for using FF-A [1] as transport to the OP-TEE driver. > > > > > > Introduces struct optee_msg_param_fmem which carries all information > > > needed when OP-TEE is calling FFA_MEM_RETRIEVE_REQ to get the shared > > > memory reference mapped by the hypervisor in S-EL2. Register usage is > > > also updated to include the information needed. > > > > > > The FF-A part of this driver is enabled if CONFIG_ARM_FFA_TRANSPORT is > > > enabled. > > > > > > [1] https://developer.arm.com/documentation/den0077/latest > > > Signed-off-by: Jens Wiklander > > > --- > > > drivers/tee/optee/Makefile | 3 +- > > > drivers/tee/optee/call.c | 13 +- > > > drivers/tee/optee/core.c | 16 +- > > > drivers/tee/optee/ffa_abi.c | 907 ++++++++++++++++++++++++++++++ > > > drivers/tee/optee/optee_ffa.h | 153 +++++ > > > drivers/tee/optee/optee_msg.h | 27 +- > > > drivers/tee/optee/optee_private.h | 43 +- > > > 7 files changed, 1148 insertions(+), 14 deletions(-) > > > create mode 100644 drivers/tee/optee/ffa_abi.c > > > create mode 100644 drivers/tee/optee/optee_ffa.h > > > > [snip] > > > --- /dev/null > > > +++ b/drivers/tee/optee/ffa_abi.c > > > @@ -0,0 +1,907 @@ > > > +// SPDX-License-Identifier: GPL-2.0-only > > > +/* > > > + * Copyright (c) 2021, Linaro Limited > > > + */ > > > + > > > +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt > > > + > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include "optee_private.h" > > > +#include "optee_ffa.h" > > > +#include "optee_rpc_cmd.h" > > > + > > > +/* > > > + * This file implement the FF-A ABI used when communicating with secure world > > > + * OP-TEE OS via FF-A. > > > + * This file is divided into the follow sections: > > > > s/follow/following/ > > Thanks, I'll fix. > > [snip] > > > +static bool optee_ffa_exchange_caps(struct ffa_device *ffa_dev, > > > + const struct ffa_dev_ops *ops, > > > + unsigned int *rpc_arg_count) > > > +{ > > > + struct ffa_send_direct_data data = { OPTEE_FFA_EXCHANGE_CAPABILITIES }; > > > + int rc; > > > + > > > + rc = ops->sync_send_receive(ffa_dev, &data); > > > + if (rc) { > > > + pr_err("Unexpected error %d", rc); > > > + return false; > > > + } > > > + if (data.data0) { > > > + pr_err("Unexpected exchange error %lu", data.data0); > > > + return false; > > > + } > > > + > > > + *rpc_arg_count = (u8)data.data1; > > > > Why is this special capability required in case of FF-A? Is it true > > that RPC arguments count will be fixed for all RPC commands? > > It's to allow this driver to preallocate the argument struct used when > doing RPC. That way we can avoid the chicken and egg problem of allocating > an RPC argumet struct just before doing the real RPC. > > This is the maximum number of arguments needed by secure world. In case > a larger value ever is needed, secure world will be able to supply the > needed value. > > I plan to update the SMC based ABI with this also, but not in the patch > set. > Okay, I see the requirement with FF-A ABI that we need to pass memory reference to "struct thread_rpc_arg" while in case of SMC ABI we directly pass the RPC commands in registers which allows it to work without pre-allocation. So I am fine with this approach as well given that the pre-allocated memory for RPC arguments may be left unused in some cases but that's fine when compared with the overhead of extra RPC calls with SMC ABI. > > > > > + > > > + return true; > > > +} > > [snip] > > > +static int optee_ffa_probe(struct ffa_device *ffa_dev) > > > +{ > > > + const struct ffa_dev_ops *ffa_ops; > > > + unsigned int rpc_arg_count; > > > + struct tee_device *teedev; > > > + struct optee *optee; > > > + int rc; > > > + > > > + ffa_ops = ffa_dev_ops_get(ffa_dev); > > > + if (!ffa_ops) { > > > + pr_warn("failed \"method\" init: ffa\n"); > > > + return -ENOENT; > > > + } > > > + > > > + if (!optee_ffa_api_is_compatbile(ffa_dev, ffa_ops)) > > > + return -EINVAL; > > > + > > > + if (!optee_ffa_exchange_caps(ffa_dev, ffa_ops, &rpc_arg_count)) > > > + return -EINVAL; > > => + > > > + optee = kzalloc(sizeof(*optee), GFP_KERNEL); > > > + if (!optee) { > > > + rc = -ENOMEM; > > > + goto err; > > > + } > > > + optee->pool = optee_ffa_config_dyn_shm(); > > > + if (IS_ERR(optee->pool)) { > > > + rc = PTR_ERR(optee->pool); > > > + optee->pool = NULL; > > > + goto err; > > > + } > > > > IIUC, with FF-A we will only be supporting dynamic shared memory. So > > CFG_CORE_DYN_SHM=y should be enforced in OP-TEE OS when > > CFG_CORE_FFA=y, but I don't see that currently. Am I missing > > something? > > You mean in optee_os.git? With FF-A dynamic shared memory is always > handled, so that flag in irrelevant in that case. However, feel free to > start a discussion on that topic at github. Ah, I see. You are correct that FF-A enables dynamic shared memory by default. FWIW, feel free to add: Acked-by: Sumit Garg -Sumit > > Thanks, > Jens