From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0B1AC432BE for ; Fri, 27 Aug 2021 05:29:48 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A338660FC4 for ; Fri, 27 Aug 2021 05:29:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A338660FC4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Rkk+OiB32xh3qT5hj3U9gHRJCqnIxJeXdQSXH6H9Wvk=; b=TDqniGlsxm+0W0 Aa2n80NEISHQf7G42gUxXJLRq7rmJpZzi30j0wSDOm/jtlmD+wsTkU2PJ09mAGSu4g/bk+vK8Ok7m R9DBXFxa1dtp88Z3XzZRtGSUWu670PvbJEtIAm2NaWaGObv9IyWpqtL4eiKbDqi7I420vwBr8CdAr Ni2PWJ7Gd4uLcuVSVJPEx0EeysJZGB0ubXlSIfP3B/O3RSUDrgY5AJSwPrUhExN1BDOMwoo2QyhMf Jxo6ZlKfL6AYDGT9TFfPWj33tJAibRewlmzbu2Zer2+94VsZ7Be0hEboyabChRZ7pwGnGkGHqKJgG +01/AyRdlLDgJxzm3h8w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mJUOg-00Bbph-5G; Fri, 27 Aug 2021 05:27:22 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mJUOY-00BboG-Es for linux-arm-kernel@lists.infradead.org; Fri, 27 Aug 2021 05:27:18 +0000 Received: by mail-lf1-x129.google.com with SMTP id y34so11894670lfa.8 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=jrvTecB/AKIgcMiuG5JlAxo7WxtijZjY2SZ197RDcV/uAfDnrHvubqcNwfWtdT5+Ar 4looS5r4YAqARabeUNhFdg8kVmj3H1zISA+DnTnxVg4ND80m7smacBIsIecdwkFy/jO2 mwQ+QMZi+Kx61YexWKRiveGVD/+xypE7y2VQREdUtsX148bJ9pokOIX2CMLBGaGNyLmB UrkIDKSbGk+wDkSKqo4TLSqzd8lSN6RE3WPSxn/Dlhc7zeza4j9EoonGtJgrrf8JQTHk LJkQ1Hx/LujdGPVlPlbVmB8U2cET52GUKA+3cbUnLtS1n5Gpg1uYmW5nAmVjpJPlGwp7 0fLg== X-Gm-Message-State: AOAM531JchAeiXB96y4XCDhNdddXISBSW4vyUlxNGJIHDuwhd8l69RcV XEvuVLlwEirPI0a8i6hb9t0aKm6OxzZA9nBDqKa5Ew== X-Google-Smtp-Source: ABdhPJw5tu9U0plf944UOLkB6b80+Y1ywSWOvicN6FaE8XCULyPXDzRXt/73+pxFc6FebCmNjRws2R0LO6hcfB36Sd8= 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210826_222714_610785_B286CBDD X-CRM114-Status: GOOD ( 39.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel