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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 CAE13C04FF3 for ; Mon, 24 May 2021 22:40:44 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9C6F66128B for ; Mon, 24 May 2021 22:40:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9C6F66128B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EE52381DC0; Tue, 25 May 2021 00:40:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="dn/hZf2d"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9A42781DC0; Tue, 25 May 2021 00:40:38 +0200 (CEST) Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A92A281DC0 for ; Tue, 25 May 2021 00:40:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wm1-x32c.google.com with SMTP id u133so15640899wmg.1 for ; Mon, 24 May 2021 15:40:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=u1f3WU5JHq4U3r+hELo+fvxRx0ozeLxs2sLYnqTmLQY=; b=dn/hZf2d1u3vYHP7RsCG9t1PBJj30C7V63Qr8LNFcMoqSgmKMrZil72I/gSO8w1hws doC2PpuUOHr5xKJnXByrMTpO/8WLGqrN0B9bX3N3Y0AyD3ryRuNmOJZORrKNWkjMuZaa e89PIHY8GfqNCRxN3Bj7EyYIuhTD4hrk6j8SAfOTyWQETrap8OJArdEVcGsad6CCXOHh j6YC+4SdC1ucpzbvKO6KCkVrBUSESmAwawgd6VeeTBJhsDVBM0JSiE3WTYBttIdjCCjd tesEegSp12K/mHk6MZC0IqG+cFLIRlqLiNiz55EjqJO96anRDyWp736C3ArZFswVrSLd xYqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=u1f3WU5JHq4U3r+hELo+fvxRx0ozeLxs2sLYnqTmLQY=; b=lCWTgQJqFoigRTjrvJFLZkZHBSNxJH+AaSVBax17iGp89hjtCy8Gbrepo6r2kXmwKA tFDz2QRcyJIKxtgHolzsYoP2mC8T0mcBfSG1zit57iod2xDJ/n8qqeFV/tR4JhhfogpV YrNthxWXFF6586oMT10q3IVxAVE83uVJIYC3iF1W1AP3OOWZUb65BMUSPTsvPIwSNoLW wNPjzcVjer/ka6QygQn6HYFT3maKd0GRAEvXBwljWkOiNZMbpia3T8yS+awI64ai5Thb qNLaQ+K/nQNbjf++z/V0mWAQLYsuck9pTEItd5U+Ka1D4c2m3XhZ9rXBePBIo4fzrXDX 8UWg== X-Gm-Message-State: AOAM531eGZ70MnBtiL/XpBeQGn9R+A9pU2uWu3NbcVKLqtCd/smMU8GJ ExZSYf0Ld8vZunKwIueEN095Sw== X-Google-Smtp-Source: ABdhPJzEO8ahZQ5U2/t+/QpGDOVO5tWCiP478Lbel9IotelKkkLhJ9DRm9N4bHrL/uLKdObmY9VK9Q== X-Received: by 2002:a1c:b646:: with SMTP id g67mr20765714wmf.117.1621896035157; Mon, 24 May 2021 15:40:35 -0700 (PDT) Received: from apalos.home ([94.69.77.156]) by smtp.gmail.com with ESMTPSA id l16sm721133wmj.47.2021.05.24.15.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 May 2021 15:40:34 -0700 (PDT) Date: Tue, 25 May 2021 01:40:31 +0300 From: Ilias Apalodimas To: Etienne Carriere Cc: u-boot@lists.denx.de, Jens Wiklander , Simon Glass , Patrick Delaunay Subject: Re: [PATCH v2] tee: optee: sync cache on pre-reloc OP-TEE invocation Message-ID: References: <20210519142741.7782-1-etienne.carriere@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210519142741.7782-1-etienne.carriere@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean On Wed, May 19, 2021 at 04:27:41PM +0200, Etienne Carriere wrote: > This change ensures both U-Boot and OP-TEE see the same content > from shared memory when OP-TEE is invoked prior U-Boot relocation. > > This change is required since U-Boot may execute with data cahce off > while OP-TEE always enables cache on memory shared with U-Boot. > > Signed-off-by: Etienne Carriere > --- > Changes since v1: > - Fix invocation argument buffer size in optee/core.c, using > OPTEE_MSG_GET_ARG_SIZE(). > - add missing #include in tee-uclass.c > --- > drivers/tee/optee/core.c | 21 ++++++++++++++++++++- > drivers/tee/tee-uclass.c | 19 ++++++++++++++++++- > include/tee.h | 6 ++++++ > 3 files changed, 44 insertions(+), 2 deletions(-) > > diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c > index 73dbb22ba0..dad46aa388 100644 > --- a/drivers/tee/optee/core.c > +++ b/drivers/tee/optee/core.c > @@ -1,9 +1,10 @@ > // SPDX-License-Identifier: GPL-2.0+ > /* > - * Copyright (c) 2018 Linaro Limited > + * Copyright (c) 2018-2020 Linaro Limited > */ > > #include > +#include > #include > #include > #include > @@ -295,6 +296,16 @@ static u32 call_err_to_res(u32 call_err) > } > } > > +static void flush_shm_dcache(struct udevice *dev, struct optee_msg_arg *arg) > +{ > + size_t sz = OPTEE_MSG_GET_ARG_SIZE(arg->num_params); > + > + flush_dcache_range(rounddown((ulong)arg, CONFIG_SYS_CACHELINE_SIZE), > + roundup((ulong)arg + sz, CONFIG_SYS_CACHELINE_SIZE)); > + > + tee_flush_all_shm_dcache(dev); > +} > + > static u32 do_call_with_arg(struct udevice *dev, struct optee_msg_arg *arg) > { > struct optee_pdata *pdata = dev_get_plat(dev); > @@ -305,9 +316,17 @@ static u32 do_call_with_arg(struct udevice *dev, struct optee_msg_arg *arg) > while (true) { > struct arm_smccc_res res; > > + /* If cache are off from U-Boot, sync the cache shared with OP-TEE */ > + if (!dcache_status()) > + flush_shm_dcache(dev, arg); > + > pdata->invoke_fn(param.a0, param.a1, param.a2, param.a3, > param.a4, param.a5, param.a6, param.a7, &res); > > + /* If cache are off from U-Boot, sync the cache shared with OP-TEE */ > + if (!dcache_status()) > + flush_shm_dcache(dev, arg); > + > free(page_list); > page_list = NULL; > > diff --git a/drivers/tee/tee-uclass.c b/drivers/tee/tee-uclass.c > index 2cc6b6c407..24321ba1d2 100644 > --- a/drivers/tee/tee-uclass.c > +++ b/drivers/tee/tee-uclass.c > @@ -1,13 +1,15 @@ > // SPDX-License-Identifier: GPL-2.0+ > /* > - * Copyright (c) 2018 Linaro Limited > + * Copyright (c) 2018-2020 Linaro Limited > */ > > #include > +#include > #include > #include > #include > #include > +#include > #include > #include > > @@ -233,3 +235,18 @@ void tee_optee_ta_uuid_to_octets(u8 d[TEE_UUID_LEN], > d[7] = s->time_hi_and_version; > memcpy(d + 8, s->clock_seq_and_node, sizeof(s->clock_seq_and_node)); > } > + > +void tee_flush_all_shm_dcache(struct udevice *dev) > +{ > + struct tee_uclass_priv *priv = dev_get_uclass_priv(dev); > + struct tee_shm *s; > + > + list_for_each_entry(s, &priv->list_shm, link) { > + ulong start = rounddown((ulong)s->addr, > + CONFIG_SYS_CACHELINE_SIZE); > + ulong end = roundup((ulong)s->addr + s->size, > + CONFIG_SYS_CACHELINE_SIZE); > + > + flush_dcache_range(start, end); > + } > +} > diff --git a/include/tee.h b/include/tee.h > index 99367b258e..2ef29bfc8f 100644 > --- a/include/tee.h > +++ b/include/tee.h > @@ -377,4 +377,10 @@ void tee_optee_ta_uuid_from_octets(struct tee_optee_ta_uuid *d, > void tee_optee_ta_uuid_to_octets(u8 d[TEE_UUID_LEN], > const struct tee_optee_ta_uuid *s); > > +/** > + * tee_flush_all_shm_dcache() - Flush data cache for all shared memories > + * @dev: The TEE device > + */ > +void tee_flush_all_shm_dcache(struct udevice *dev); > + > #endif /* __TEE_H */ > -- > 2.17.1 > Acked-by: Ilias Apalodimas