Received: by 2002:a19:ef0c:0:0:0:0:0 with SMTP id n12csp979948lfh; Thu, 27 Jan 2022 04:43:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxOBvBa5+uS0h29p26xtsKR7+s+ZFDguDn/mW25v8gaxerbm+eqAoTUkIaMX3XWhzFrbecF X-Received: by 2002:a05:6402:268d:: with SMTP id w13mr3442644edd.287.1643287384662; Thu, 27 Jan 2022 04:43:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643287384; cv=none; d=google.com; s=arc-20160816; b=nuW9ktvOl2Nk29u0pC3tmIhkLEDw+XmnVQ8NsSJ9ECdENHr1pUqKIvOoBGTqGkoYZl mwzUU40VE5yrNsy/VZqpGPYDEaNb4aR1OqcrsoCSuqRy5AIt9b2M4FiaOHrnqCdk4/63 Ln+EOFd9t66zkQa8HGbbuWaa44z5QUVmQ4EbXsO6bOOAW7hlLct67oY7NiZ0mRk0Zyis hywfjHiqVRCbOUxln01+BXW/e6TfRrrRe2FjsJRL/m9Tc9eypWuz8QQAnMpqGlMASQ76 TKgc7t3NwgRkss0Ps00Xuc1TeIyh24nUiT4Fbb26ofPP83L3el5cdi8M8iyqr0RFWkoF qlbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Hn+2ril8pqAtt7/6Z1JQegT9LE4NfpF4eSDSr3S6Kuo=; b=GRhZ37b24zy/NhjlgloRdFm1nrXtFdL/ZlGJ1KfPNSWVr0qcPyF4wI/5fultOseHBf aD3Lss1WqyvEGEwYvuYdueYl/PYc7nsk9CuvjRs5qdf/FdMnShNJQJ3ZQBsvRlIZRndk P7Gl0wLPD9B2QKJ++RD6+VlXvrQLwVa9t2vXj3sv6XW61yWTMgYXbge9X1H1wTgYCdAA 9sff4l1ifhijkIkBEWsd5gnjBLg21gZ+QWdSGOFDpBlnyyQ3GOi6VgTMdYyZ+RymWGWs DeNpJKeBnPT3Prhl4FUwL1FkQ1R0/mHhvlr+2FtYcCXNZhnyH/WiF4fweRHNtnlUc/av M9wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yoJPLJc6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q20si1251637eds.627.2022.01.27.04.42.39; Thu, 27 Jan 2022 04:43:04 -0800 (PST) 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=@linaro.org header.s=google header.b=yoJPLJc6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236736AbiA0Gcg (ORCPT + 99 others); Thu, 27 Jan 2022 01:32:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbiA0Gce (ORCPT ); Thu, 27 Jan 2022 01:32:34 -0500 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA6B1C061714 for ; Wed, 26 Jan 2022 22:32:33 -0800 (PST) Received: by mail-lj1-x230.google.com with SMTP id e9so2837008ljq.1 for ; Wed, 26 Jan 2022 22:32:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Hn+2ril8pqAtt7/6Z1JQegT9LE4NfpF4eSDSr3S6Kuo=; b=yoJPLJc6p/zsMhYPBqvSer6vmRAMjwQNpelLD881lDqdAZoCWvvHeuhX7VsG4Anrr2 DjP/+uB17Zmdrwi8P1Saj3EWMVt1mtdfIZmuLItnEdy3r1BqDjQmEUrB68Bi6I/exOP2 JPc9lVr1SJPoYJu2qt9Slhtavi8Zwga8kyMzzI78AAiGWVVPLdVgKbXSMc6+3qVzLIw1 F70PYmZwnhEDsJbgV9tRs+fEJKOcp0ucB1muBDtoCsMA3WRcYqEHayBvqmGkBIRGVh/m dBPCH09XTcCIXzpCUnYp7knTdu/ZMReTbf69Q+dX8pScVcKpZMBKIhm2+H37fT0vuhYt bC+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Hn+2ril8pqAtt7/6Z1JQegT9LE4NfpF4eSDSr3S6Kuo=; b=JqtYq5m6+AbZbZxgHd8p9mK2eGN09mA9YrwC+wp9V9JCbTG6srsmmS/dFfeg9+QKCr 5Toe7wfZ1CDXDCxZB+ZQpBVJQRuPucq18BkLzVrbGpD22VLyBFe29ypdElHQa2ejjP5l vfSh9Bdfl9wEeRjSPSjyVVPF+tNuWqYaA9wlw9BTvde5Q4ytyQbG6ThBkEbSvLISI3rh DohfZiYNYdYUuZbEYZraZ21DL8w+JuGC+383fKoKgn5TV8sQdklsVtOaWlb0Gf3N/tl+ WOwanyUakpnMKBadKLYQjWSQI7J+6Ndj4cOwe98i6HTJfzgyxjEX2q9IYYVAJn5bNVqQ iucA== X-Gm-Message-State: AOAM5313UYxf+ZD4iBcyVRP/L81CVcy2PAPL76wZEnx9eJneXn9mb4T+ KStSEE5sZszFBkFh6mxzDLl3iGyvVgUp//rRdzzBkA== X-Received: by 2002:a05:651c:1987:: with SMTP id bx7mr1916173ljb.136.1643265152075; Wed, 26 Jan 2022 22:32:32 -0800 (PST) MIME-Version: 1.0 References: <20220125162938.838382-1-jens.wiklander@linaro.org> <20220125162938.838382-8-jens.wiklander@linaro.org> In-Reply-To: <20220125162938.838382-8-jens.wiklander@linaro.org> From: Sumit Garg Date: Thu, 27 Jan 2022 12:02:20 +0530 Message-ID: Subject: Re: [PATCH v3 07/12] optee: use driver internal tee_contex for some rpc To: Jens Wiklander Cc: linux-kernel@vger.kernel.org, op-tee@lists.trustedfirmware.org, Herbert Xu , Devaraj Rangasamy , Rijo Thomas , David Howells , Tyler Hicks , stable@vger.kernel.org, Lars Persson Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +Lars Hi Jens, On Tue, 25 Jan 2022 at 21:59, Jens Wiklander wrote: > > Uses the new driver internal tee_context when allocating driver private > shared memory. This decouples the shared memory object from its original > tee_context. This is needed when the life time of such a memory > allocation outlives the client tee_context. > > Fixes: 217e0250cccb ("tee: use reference counting for tee_context") > Cc: stable@vger.kernel.org > Reviewed-by: Sumit Garg > Signed-off-by: Jens Wiklander > --- > drivers/tee/optee/ffa_abi.c | 17 +++++++++-------- > drivers/tee/optee/smc_abi.c | 7 ++++--- > 2 files changed, 13 insertions(+), 11 deletions(-) > As this commit fixes multiple issues seen earlier due to pre-allocated SHM cache in client's context. I think it makes sense to separate this as a standalone fix with few bits from patch #6 to target 5.17 release. As otherwise it will take a long path via 5.18 and then backport to stable trees. In the meantime there can be other side effects noticed similar to one from Lars. -Sumit > diff --git a/drivers/tee/optee/ffa_abi.c b/drivers/tee/optee/ffa_abi.c > index 954e88866968..fb7345941024 100644 > --- a/drivers/tee/optee/ffa_abi.c > +++ b/drivers/tee/optee/ffa_abi.c > @@ -424,6 +424,7 @@ static struct tee_shm_pool *optee_ffa_shm_pool_alloc_pages(void) > */ > > static void handle_ffa_rpc_func_cmd_shm_alloc(struct tee_context *ctx, > + struct optee *optee, > struct optee_msg_arg *arg) > { > struct tee_shm *shm; > @@ -439,7 +440,8 @@ static void handle_ffa_rpc_func_cmd_shm_alloc(struct tee_context *ctx, > shm = optee_rpc_cmd_alloc_suppl(ctx, arg->params[0].u.value.b); > break; > case OPTEE_RPC_SHM_TYPE_KERNEL: > - shm = tee_shm_alloc_priv_buf(ctx, arg->params[0].u.value.b); > + shm = tee_shm_alloc_priv_buf(optee->ctx, > + arg->params[0].u.value.b); > break; > default: > arg->ret = TEEC_ERROR_BAD_PARAMETERS; > @@ -492,14 +494,13 @@ static void handle_ffa_rpc_func_cmd_shm_free(struct tee_context *ctx, > } > > static void handle_ffa_rpc_func_cmd(struct tee_context *ctx, > + struct optee *optee, > struct optee_msg_arg *arg) > { > - struct optee *optee = tee_get_drvdata(ctx->teedev); > - > arg->ret_origin = TEEC_ORIGIN_COMMS; > switch (arg->cmd) { > case OPTEE_RPC_CMD_SHM_ALLOC: > - handle_ffa_rpc_func_cmd_shm_alloc(ctx, arg); > + handle_ffa_rpc_func_cmd_shm_alloc(ctx, optee, arg); > break; > case OPTEE_RPC_CMD_SHM_FREE: > handle_ffa_rpc_func_cmd_shm_free(ctx, optee, arg); > @@ -509,12 +510,12 @@ static void handle_ffa_rpc_func_cmd(struct tee_context *ctx, > } > } > > -static void optee_handle_ffa_rpc(struct tee_context *ctx, u32 cmd, > - struct optee_msg_arg *arg) > +static void optee_handle_ffa_rpc(struct tee_context *ctx, struct optee *optee, > + u32 cmd, struct optee_msg_arg *arg) > { > switch (cmd) { > case OPTEE_FFA_YIELDING_CALL_RETURN_RPC_CMD: > - handle_ffa_rpc_func_cmd(ctx, arg); > + handle_ffa_rpc_func_cmd(ctx, optee, arg); > break; > case OPTEE_FFA_YIELDING_CALL_RETURN_INTERRUPT: > /* Interrupt delivered by now */ > @@ -581,7 +582,7 @@ static int optee_ffa_yielding_call(struct tee_context *ctx, > * above. > */ > cond_resched(); > - optee_handle_ffa_rpc(ctx, data->data1, rpc_arg); > + optee_handle_ffa_rpc(ctx, optee, data->data1, rpc_arg); > cmd = OPTEE_FFA_YIELDING_CALL_RESUME; > data->data0 = cmd; > data->data1 = 0; > diff --git a/drivers/tee/optee/smc_abi.c b/drivers/tee/optee/smc_abi.c > index b1082a34cda2..0dc383c974a3 100644 > --- a/drivers/tee/optee/smc_abi.c > +++ b/drivers/tee/optee/smc_abi.c > @@ -621,6 +621,7 @@ static void handle_rpc_func_cmd_shm_free(struct tee_context *ctx, > } > > static void handle_rpc_func_cmd_shm_alloc(struct tee_context *ctx, > + struct optee *optee, > struct optee_msg_arg *arg, > struct optee_call_ctx *call_ctx) > { > @@ -650,7 +651,7 @@ static void handle_rpc_func_cmd_shm_alloc(struct tee_context *ctx, > shm = optee_rpc_cmd_alloc_suppl(ctx, sz); > break; > case OPTEE_RPC_SHM_TYPE_KERNEL: > - shm = tee_shm_alloc_priv_buf(ctx, sz); > + shm = tee_shm_alloc_priv_buf(optee->ctx, sz); > break; > default: > arg->ret = TEEC_ERROR_BAD_PARAMETERS; > @@ -746,7 +747,7 @@ static void handle_rpc_func_cmd(struct tee_context *ctx, struct optee *optee, > switch (arg->cmd) { > case OPTEE_RPC_CMD_SHM_ALLOC: > free_pages_list(call_ctx); > - handle_rpc_func_cmd_shm_alloc(ctx, arg, call_ctx); > + handle_rpc_func_cmd_shm_alloc(ctx, optee, arg, call_ctx); > break; > case OPTEE_RPC_CMD_SHM_FREE: > handle_rpc_func_cmd_shm_free(ctx, arg); > @@ -775,7 +776,7 @@ static void optee_handle_rpc(struct tee_context *ctx, > > switch (OPTEE_SMC_RETURN_GET_RPC_FUNC(param->a0)) { > case OPTEE_SMC_RPC_FUNC_ALLOC: > - shm = tee_shm_alloc_priv_buf(ctx, param->a1); > + shm = tee_shm_alloc_priv_buf(optee->ctx, param->a1); > if (!IS_ERR(shm) && !tee_shm_get_pa(shm, 0, &pa)) { > reg_pair_from_64(¶m->a1, ¶m->a2, pa); > reg_pair_from_64(¶m->a4, ¶m->a5, > -- > 2.31.1 >