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: 435551 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp4915381jao; Wed, 12 May 2021 08:08:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmSWSq6KorXnZ30zxjLbaswk2w2NkJID5d0ua2fD2Qv+M175hJ7li/UiA3J1djxIUrdgCU X-Received: by 2002:a17:906:7fd3:: with SMTP id r19mr37574227ejs.2.1620832114853; Wed, 12 May 2021 08:08:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620832114; cv=none; d=google.com; s=arc-20160816; b=zw+JzoWRMfckyUbBFg1pDXXfse4PxccGHOinJLWRvGcyfZ9xB9GkkuMh3Ukt9IC+Qc zcsTLyWhIxRwcxRBeWaHtJAQqR0cEWfeK1aXZgxMatv8gOM863n6lT4eb2nlZ4a70bBQ se+XZNOpJERTf/2T2C00pfEO1oHjPsbbvo0P7PUDbxfpmR5tSpjhDn8Iis/L30LlyYW9 +B18IfDhuC7SA+GFliR1O4KcOhFJ7cyMMRdm/oSY97oz52nzvIjdtBbYNzW1bMwvUARx kP3FgYzitLhBLVzIwH+vrvIUrBIIs8CRiYA7fmbOOei7hV2YrePFZkT2sDNZR1kWbuG0 1R5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=H+OpBMhlMl229sxDVlJAU01N/FJtD1wNNi8yhjrk8DQ=; b=u6MRvUoHwnAM4G2sL91x62k5XyefSdT9UmVYByzIcGNEk2UAXqyaAzJCIqp4cwjhjM hFUKpCi2nE9A/WUqq4o/I57ynYY1TG/nbUra8IfO2pDNL2sZmkKm3ag/trCoHK59pTo3 V4XGcVtF4DDs3mZ4ptlES0jkrj1u6eVGGWkpR5WmXeBq/4qUGTd+iy4o2Be2wRaSF93Q fzmkobABpFM+yFVXfMZNbOyL644+JDpy01uXUNLNBaM60Bmex3rJT7kp2/d/OGHXkeoR koy8yukBTUIlhFOfxqLtWbb+syWkMM8/FpUjX146a0Cw4mB+cXHIpJllWAKFfJFTRzkT LnyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AOMkZvFQ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id b15si22148edd.87.2021.05.12.08.08.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 08:08:34 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AOMkZvFQ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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-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(-) -- 2.17.1 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 */