From patchwork Wed May 19 14:27:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 442438 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp1377809jac; Wed, 19 May 2021 07:28:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2N/dk9YwAdEaOc+9GgR0opMJxTt6g4/dlYRCa8EzlVFhMGMlgtVKwC2lUtO2xkiYZItIi X-Received: by 2002:a17:907:105e:: with SMTP id oy30mr13015409ejb.258.1621434521081; Wed, 19 May 2021 07:28:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621434521; cv=none; d=google.com; s=arc-20160816; b=T6cEbB+D4JhTwC851YvmKZfIzWyDht1Dn5W/XjN31KMma0JDvCFaR7yyy0ymq+5C0h PgKcwRN4RdAAPe92lylerVWv2nTGQJ+OhO3F7dJYo55i2chr8vSPnd28FXm/rdfYA06t EIWgkcwjgOdz6ZPEVuk3MMqMDOVB/q/0o8w/kYIS4Q81JKfMO5RyZg9w1WpdWbgsqnjg wQXcymf5/rDBC+lENq5ubaA6x2FyEQ3ZXqiNVYIbk7OeLWP/ftTK8mI34T9lpQ5VNyd/ O1VCMK7XCAp3gTw48y8FOdPFTombTEi3h0jQDVwGrSNZzgetrcpn+Q8gdOCIjT5fkOrZ N+7g== 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=Sle1dw+pH3URHScGWs02Zo3vMqp8avhLOvlOwDe0Fj4=; b=sy9xoysU33E/V8+beJG13SJ4hpbuSggdjmLIhxm2DOYBKCKIYQPiUuGnsU5avafLeZ 4HnHa2Izki80AGL0CYwkg+6pO1pV6w/RPMdzHjJ4pFIsAKZnyB9vBt1IrElfdZri+WGj iSRmiy1Fibx18NBwY4nUbHDQgcUlM0/F+lQNVp8bjLVpyMLUlbQkjfaOHbSsW73ypeE6 I1aCaH0nfxknOc8D0LgSt2bl96acjGTY4uPxrnCTBS69xRZp1BJlcqKDRaDClEfRNIU2 e+NTqLBq0lT9OgVFWp6HMOwHw9xCShFWsLaMoZj785YGIW3EZS9J45Vpz8Nbxa7BDzkF Mk4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QAAHNm5r; 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 da5si20412140edb.538.2021.05.19.07.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 May 2021 07:28:41 -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=QAAHNm5r; 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 BD4A381895; Wed, 19 May 2021 16:28:39 +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="QAAHNm5r"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5D49E82A8B; Wed, 19 May 2021 16:28:37 +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-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (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 3DB96816D2 for ; Wed, 19 May 2021 16:28:34 +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-wm1-x32d.google.com with SMTP id z137-20020a1c7e8f0000b02901774f2a7dc4so3437299wmc.0 for ; Wed, 19 May 2021 07:28:34 -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=Sle1dw+pH3URHScGWs02Zo3vMqp8avhLOvlOwDe0Fj4=; b=QAAHNm5r7eo7Z4+kXcmXIJ3PMHmXZlNVeQZzVGSbkl5b5mZYV8X1sqpIEwHESEnDAy zsxE3bEzvfKhJz9H7XBfA42hMvYjAPR7b0MT4UPQXZpWBYtYXr4GaD/ValvuvB3yneZD RWKcK/uxh5MZhlOgv6fVSgl8ahs9s/87692HDp1hGdYT715YmEPk8iDTEq24TTMP+gJc 5ihS9kCmIa51kdMYlmi1Tsu3G2EmdcGbgLFlqxzP34ROnxm7qEdaMX4hHsSrC0KGVD4J xMIWYcwnz3/5v1P26PgvU2Uq/Yr1nV8daD/LO9qEjocZ0ASx5hD8579uZ69eQ+iV7KKM HyCw== 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=Sle1dw+pH3URHScGWs02Zo3vMqp8avhLOvlOwDe0Fj4=; b=FmAJwe8iEETzIGNiWVEi/ll517P14TpR8wlhGhpdVEvkCwbi2iYcSs7TfnkJkfTLj4 vOScrNPocqgDbscYnEX17L60WmNZ+q/taJOHV/zWL5hxMf4iByTf2CEXzbOXQjgDMCxK bB8O2WrZnamTJrKELM5WMWvPx5A/gjW8MhahySmgSW4/ve+xUdjVNaj0XTsccfHCvj/n tAFYmgeSyFq/YS7737XR24zIpOSKxMZYDDWlPLci4+DA3yb5MjRhmJzesgDhCGKms1Rw fUJqygq6NRANTzHR6xI/mONe80JI40hB2W48OrVOamUD+dN2Ir90COih8/CoLnT9o56h uzjA== X-Gm-Message-State: AOAM530P0caCVI5H8DMcoKlmrNua+lbWJf+h35QdDZ3F5U/Hakgsjxy3 vMNNbpNf57o4HOnKI14x1//4vCMWge0qADEu X-Received: by 2002:a1c:1d8e:: with SMTP id d136mr11701385wmd.80.1621434513616; Wed, 19 May 2021 07:28:33 -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 b8sm26606375wrx.15.2021.05.19.07.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 May 2021 07:28:33 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Jens Wiklander , Simon Glass , Patrick Delaunay , Ilias Apalodimas , Etienne Carriere Subject: [PATCH v2] tee: optee: sync cache on pre-reloc OP-TEE invocation Date: Wed, 19 May 2021 16:27:41 +0200 Message-Id: <20210519142741.7782-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 --- 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(-) -- 2.17.1 Reviewed-by: Jens Wiklander Acked-by: Ilias Apalodimas 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 */