Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp270838ybg; Mon, 1 Jun 2020 00:29:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPJnEpglea1Y4ELPzvyQzAVGwh80ncqmsQXshSG4JJgI7sOqhFdyJC7eW7Rj25opk+LiN9 X-Received: by 2002:a50:99c9:: with SMTP id n9mr20789646edb.1.1590996577873; Mon, 01 Jun 2020 00:29:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590996577; cv=none; d=google.com; s=arc-20160816; b=0Z3jiQ/zds4gafigeEdZaIpdiKPZTNSRwotFC5Ct7xeot31b6FZ5/Q0u+RZN0VoyEr xcN7MJePf7v3ZCeDLu4n5nXs2jYJBRTLgaWD7/II/ttbXX0KwEE1P9lHfKY8B55qhRp7 z6UpQLvMlFvos3PY/qzV5N1Nka4K4OLLzLrWmhoLwRdGkwgyqO0slsITu3N3Rvh/nFWV K0l4tVB00Bs6ntUdwGx50xIiVS6oWzLiKTSPB3UI522F59bzgpqo/H7OIHygsQAyVjLc YHGXtiXv683IxZ3qk4u33q/YHmhw/bsXcQNB4P+atPmhLCXI6kI9ntIhzX+jlquhm1tu zskg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=FAKMpIpHFvQp3zgS4QFpXD2KONnNwtUil2UzoSlI21A=; b=O5oQ+/xq36/QMmlVqr4iInk12kn6P+gOvUtdkZjlyLtWrUdiGj3d/v2/gofVcqWm/b xzKuEYSctEx0T0n2Hh1zscmw9JRwuS5VzST0ZwKv4GLix0IwVb3RwfjrkNGvO/73A3aP XgAzteNuFfa3bwWqmJpcK6t3wrtg6cY6Q7SMEbgld/Qzh1/DYwQHpxMStvm/Ncw4W+pw AmDbRsuq8xhbDUTP1owvdP7L0lbn77cNCR3Om5G8poGPZJej/CwGcbqu2L9s52HI1B5j eY6oJXuHVAOj7pbTp5/67L9yZBuyEkj7yFAUgv/uegTQ7ZWr8ZZaJ1PLssPz1ZSeijh6 ySnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foundries-io.20150623.gappssmtp.com header.s=20150623 header.b="2Bfbk/Vh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g31si10343344edd.232.2020.06.01.00.29.14; Mon, 01 Jun 2020 00:29:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@foundries-io.20150623.gappssmtp.com header.s=20150623 header.b="2Bfbk/Vh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728106AbgFAHYu (ORCPT + 99 others); Mon, 1 Jun 2020 03:24:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725283AbgFAHYu (ORCPT ); Mon, 1 Jun 2020 03:24:50 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCE3EC061A0E for ; Mon, 1 Jun 2020 00:24:49 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id r15so10241801wmh.5 for ; Mon, 01 Jun 2020 00:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foundries-io.20150623.gappssmtp.com; s=20150623; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=FAKMpIpHFvQp3zgS4QFpXD2KONnNwtUil2UzoSlI21A=; b=2Bfbk/Vh3g2NKKULAuwDi+0omjMueFykMBrUZJdsSPf1JxF/+BBFpN553HYvz7aXgf 6WDD/ML9fWpUe7ISNqGrJDzq0x436l2fKzJTXoFMGUrIo3R0lpld5cYORJApUeGVuZCc HIND5FcSNGPR4uZ+njQGcnHKWdkQRD/DmBH3c360mSNpBIilZsJdFnUGvO0CKQdiCRb/ 99qAc95/n9oVB7ZAF+SVwblQ6UsFg72+/pu0lOQyFTrJ+v1GlzCWryEs2ypF0mCCmC8b CD9fTsnjEsguJCk3Q9zQjaW1YCvp58Yze97bInIwJZMOJ0GaERqY1arYvW6wMH0ZKg8F YDzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=FAKMpIpHFvQp3zgS4QFpXD2KONnNwtUil2UzoSlI21A=; b=av4uXQByDs3ZMPcKbSwkyCuJVBpbyRDaoe4IDzLznYo1gTp6diZ3dIOTukaVstLFIS ccwATHvmK0wNjtiw40KZOLYnJc9vn9j2Twt+z6rtY1eiqCxSLTyEw/rytllZK2oCdzxH P+thsjUvip8MzH0HAY6JwkhAzs4srhlrZw7v13h1pdZPtsz4qsVOow1ETUkh4zfwW/ey cWDQF6+1bRKbkk1EfRBuoF1hOBXpppxZyyoUqDvVc+aGJ3tj5d4VToePTgVaGe+zEqR4 UYv+P5nzrgm9s2utIXF1irmHFiWZSBv+GZvA5K5VexazUUqVgk39RWrwuYLFi1cIXNZR k5VQ== X-Gm-Message-State: AOAM5306KV05OxvAPq4Ry1hh8+B+I5As5AbKVwsShg0oPA/As1sHEPv2 zm3JVZfu+5Pn0h4wPN4TvVrEUQ== X-Received: by 2002:a05:600c:21d3:: with SMTP id x19mr22034719wmj.137.1590996288218; Mon, 01 Jun 2020 00:24:48 -0700 (PDT) Received: from trex (108.red-83-34-185.dynamicip.rima-tde.net. [83.34.185.108]) by smtp.gmail.com with ESMTPSA id a3sm3906885wrp.91.2020.06.01.00.24.46 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Jun 2020 00:24:47 -0700 (PDT) From: "Jorge Ramirez-Ortiz, Foundries" X-Google-Original-From: "Jorge Ramirez-Ortiz, Foundries" Date: Mon, 1 Jun 2020 09:24:46 +0200 To: Sumit Garg Cc: Jorge Ramirez-Ortiz , Jens Wiklander , "tee-dev @ lists . linaro . org" , ricardo@foundries.io, mike@foundries.io, Linux Kernel Mailing List Subject: Re: [Tee-dev] [PATCH v2] drivers: optee: allow op-tee to access devices on the i2c bus Message-ID: <20200601072446.GA28120@trex> References: <20200531231135.12670-1-jorge@foundries.io> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/06/20, Sumit Garg wrote: > Hi Jorge, hey > > On Mon, 1 Jun 2020 at 04:41, Jorge Ramirez-Ortiz wrote: > > > > Some secure elements like NXP's SE050 sit on I2C buses. For OP-TEE to > > control this type of cryptographic devices it needs coordinated access > > to the bus, so collisions and RUNTIME_PM dont get in the way. > > > > This trampoline driver allow OP-TEE to access them. > > > > This sounds like an interesting use-case but I would like to > understand how secure is this communication interface with the secure > element? Like in the case of RPMB, secure world data is encrypted > which flows via tee-supplicant to RPMB device. right, the data in the buffer should be encrypted in both directions (in the case of the SE050 [1] we have the option to operate with or without encryption which is what I am doing during development [2]). But ultimately -before any product can be shipped- all comms must be encrypted: this means that when OP-TEE uses the SE050 for crypto, it must encrypt the data on write and decrypt what is comming from the SE050 on read. I am now looking into how to enable this. [1] https://www.nxp.com/docs/en/data-sheet/SE050-DATASHEET.pdf [2] https://github.com/ldts/optee_os/commits/se050 > > -Sumit > > > Signed-off-by: Jorge Ramirez-Ortiz > > --- > > drivers/tee/optee/optee_msg.h | 18 +++++++++++ > > drivers/tee/optee/rpc.c | 57 +++++++++++++++++++++++++++++++++++ > > 2 files changed, 75 insertions(+) > > > > diff --git a/drivers/tee/optee/optee_msg.h b/drivers/tee/optee/optee_msg.h > > index 795bc19ae17a..b6cc964fdeea 100644 > > --- a/drivers/tee/optee/optee_msg.h > > +++ b/drivers/tee/optee/optee_msg.h > > @@ -419,4 +419,22 @@ struct optee_msg_arg { > > */ > > #define OPTEE_MSG_RPC_CMD_SHM_FREE 7 > > > > +/* > > + * Access a device on an i2c bus > > + * > > + * [in] param[0].u.value.a mode: RD(0), WR(1) > > + * [in] param[0].u.value.b i2c adapter > > + * [in] param[0].u.value.c i2c chip > > + * > > + * [io] param[1].u.tmem.buf_ptr physical address > > + * [io] param[1].u.tmem.size transfer size in bytes > > + * [io] param[1].u.tmem.shm_ref shared memory reference > > + * > > + * [out] param[0].u.value.a bytes transferred > > + * > > + */ > > +#define OPTEE_MSG_RPC_CMD_I2C_TRANSFER 8 > > +#define OPTEE_MSG_RPC_CMD_I2C_TRANSFER_RD 0 > > +#define OPTEE_MSG_RPC_CMD_I2C_TRANSFER_WR 1 > > + > > #endif /* _OPTEE_MSG_H */ > > diff --git a/drivers/tee/optee/rpc.c b/drivers/tee/optee/rpc.c > > index b4ade54d1f28..21d452805c6f 100644 > > --- a/drivers/tee/optee/rpc.c > > +++ b/drivers/tee/optee/rpc.c > > @@ -9,6 +9,7 @@ > > #include > > #include > > #include > > +#include > > #include "optee_private.h" > > #include "optee_smc.h" > > > > @@ -48,6 +49,59 @@ static void handle_rpc_func_cmd_get_time(struct optee_msg_arg *arg) > > bad: > > arg->ret = TEEC_ERROR_BAD_PARAMETERS; > > } > > +static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx, > > + struct optee_msg_arg *arg) > > +{ > > + struct i2c_client client; > > + struct tee_shm *shm; > > + int i, ret; > > + char *buf; > > + uint32_t attr[] = { > > + OPTEE_MSG_ATTR_TYPE_VALUE_INPUT, > > + OPTEE_MSG_ATTR_TYPE_TMEM_INOUT, > > + OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT, > > + }; > > + > > + if (arg->num_params != ARRAY_SIZE(attr)) > > + goto bad; > > + > > + for (i = 0; i < ARRAY_SIZE(attr); i++) > > + if ((arg->params[i].attr & OPTEE_MSG_ATTR_TYPE_MASK) != attr[i]) > > + goto bad; > > + > > + shm = (struct tee_shm *)(unsigned long)arg->params[1].u.tmem.shm_ref; > > + buf = (char *)shm->kaddr; > > + > > + client.addr = arg->params[0].u.value.c; > > + client.adapter = i2c_get_adapter(arg->params[0].u.value.b); > > + if (!client.adapter) > > + goto bad; > > + > > + snprintf(client.name, I2C_NAME_SIZE, "i2c%d", client.adapter->nr); > > + > > + switch (arg->params[0].u.value.a) { > > + case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_RD: > > + ret = i2c_master_recv(&client, buf, arg->params[1].u.tmem.size); > > + break; > > + case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_WR: > > + ret = i2c_master_send(&client, buf, arg->params[1].u.tmem.size); > > + break; > > + default: > > + i2c_put_adapter(client.adapter); > > + goto bad; > > + } > > + > > + if (ret >= 0) { > > + arg->params[2].u.value.a = ret; > > + arg->ret = TEEC_SUCCESS; > > + } else > > + arg->ret = TEEC_ERROR_COMMUNICATION; > > + > > + i2c_put_adapter(client.adapter); > > + return; > > +bad: > > + arg->ret = TEEC_ERROR_BAD_PARAMETERS; > > +} > > > > static struct wq_entry *wq_entry_get(struct optee_wait_queue *wq, u32 key) > > { > > @@ -382,6 +436,9 @@ static void handle_rpc_func_cmd(struct tee_context *ctx, struct optee *optee, > > case OPTEE_MSG_RPC_CMD_SHM_FREE: > > handle_rpc_func_cmd_shm_free(ctx, arg); > > break; > > + case OPTEE_MSG_RPC_CMD_I2C_TRANSFER: > > + handle_rpc_func_cmd_i2c_transfer(ctx, arg); > > + break; > > default: > > handle_rpc_supp_cmd(ctx, arg); > > } > > -- > > 2.17.1 > > > > _______________________________________________ > > Tee-dev mailing list > > Tee-dev@lists.linaro.org > > https://lists.linaro.org/mailman/listinfo/tee-dev