From patchwork Wed May 12 15:07:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 1477663 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=AOMkZvFQ; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FgJ8H54rvz9sRR for ; Thu, 13 May 2021 01:08:31 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D45A682D4C; Wed, 12 May 2021 17:08:28 +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="AOMkZvFQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EC1A282D50; Wed, 12 May 2021 17:08:26 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) (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 C2F9982CC0 for ; Wed, 12 May 2021 17:08:23 +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=etienne.carriere@linaro.org Received: by mail-wr1-x430.google.com with SMTP id z17so4911876wrq.7 for ; Wed, 12 May 2021 08:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=H+OpBMhlMl229sxDVlJAU01N/FJtD1wNNi8yhjrk8DQ=; b=AOMkZvFQlqmMAV+gjD0uDLANu0/ziD/H0jghatH8RANqVl6/yDMegAxh/9Y0eBFcos hJSQ6vg1AUiVCUnimNsbDkMQ+8bIpEcxC9NZ3H1nTBBFLAlkOekUsaLD87bPn6er65O4 Eg4l5ve/EsziHNH5gxqp3jAi+i7ZLWqe0TD1oid2kwvL0m0/uANccWT/CAZF9IGHBIr1 OSKx5/VhYpp1xdFslWScm3kfOjEHWDEjRnJdIR9oedsXkF56ulfCmXXl7vo9Uz7noDFp eTTOs/tDj/bjw82bslhao9iVJbd6Rem2DfDSXscysWf352vN0LxrDMHXJJnSiq8GnJz4 4YwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=H+OpBMhlMl229sxDVlJAU01N/FJtD1wNNi8yhjrk8DQ=; b=RI0m20DF0NPSqnh1RDU43LDkWufCeYqA2TgG4cUOGqnX6Yg3R9pS+DVHS3whln5p9O ZUr3O0MttvLivsvqFZKsop7hF6L44aBib1llFymIbT9Vp3gWyzB5FZ3ZA6j393z1PDS3 DXfoWupb1H1/DHgHjWJL4uFQN3pSHmIROMg6T5xB30OjWPZYQ480S5OL5xScnCq4Y1J7 pdAl28Ska6twv1IR87Y8OeZomocg2awMj4Y4jP6zuk3aBkr9K+pioQumJoegmzvYHZJx /VgFECFWnLVtc44CCourVeeoh3rMuoN6fMwHqMnq97E98GdpCAAAnjwSDODjsiacmUy9 xqXw== X-Gm-Message-State: AOAM530R5VDmhECMgxKRJj9fLekiPhNJQwkQw+OnymX/ts1S5sUoIa4b G8JiSJhKr5LGb106TCNoB+bC9VCoNPChSOZnCZY= X-Google-Smtp-Source: ABdhPJzmLYMajZMBsdCSkmqdfEnvSwn16O9ZwYls+H+H+B4qMNy9ViAAESM+CQnRwpBpYToGNDbnNw== X-Received: by 2002:a05:6000:1549:: with SMTP id 9mr45839748wry.367.1620832103173; Wed, 12 May 2021 08:08:23 -0700 (PDT) Received: from lmecxl0524.lme.st.com (2a01cb058b850800452ff0effb46d5f4.ipv6.abo.wanadoo.fr. [2a01:cb05:8b85:800:452f:f0ef:fb46:d5f4]) by smtp.gmail.com with ESMTPSA id j10sm31052608wrt.32.2021.05.12.08.08.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 08:08:22 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Jens Wiklander , Simon Glass , Patrick Delaunay , Etienne Carriere Subject: [PATCH] tee: optee: sync cache on pre-reloc OP-TEE invocation Date: Wed, 12 May 2021 17:07:42 +0200 Message-Id: <20210512150742.15018-1-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 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 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 --- drivers/tee/optee/core.c | 20 +++++++++++++++++++- drivers/tee/tee-uclass.c | 18 +++++++++++++++++- include/tee.h | 6 ++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index 73dbb22ba0..120d315813 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,15 @@ static u32 call_err_to_res(u32 call_err) } } +static void flush_shm_dcache(struct udevice *dev, struct optee_msg_arg *arg) +{ + flush_dcache_range(rounddown((ulong)arg, CONFIG_SYS_CACHELINE_SIZE), + roundup((ulong)arg + sizeof(*arg), + 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 +315,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..81fcd4e801 100644 --- a/drivers/tee/tee-uclass.c +++ b/drivers/tee/tee-uclass.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 @@ -233,3 +234,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 */