From patchwork Thu Jan 10 12:24:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 155146 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1836227jaa; Thu, 10 Jan 2019 04:26:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN7DVV60RJSP9K+oT1ey4ylEUUnMdAmSf6O1HBehOeAiYI6tZLeJCewWM0U6yQzcg0iccFz5 X-Received: by 2002:a63:8f45:: with SMTP id r5mr9129431pgn.222.1547123163778; Thu, 10 Jan 2019 04:26:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547123163; cv=none; d=google.com; s=arc-20160816; b=z2eDngsB6N9j0bX5bM7GXQE2GUeceV+HaCPSKnJTV5wlPsU4x26L0IzkUeuK4edkhg nCYDYHMTSmBHUxr5qmQbmfprcfgQvOez53j6Fudn3Mgr6Lh9Rs90UGWOn9Y12EHhpyt4 sUpfCT2R9kmRFUNBF2ZFn6N+T2zQRfmzWP5RVCtZklAS4z5A1EdXgTNdsc3ltgZIk1LK Hz+q+WLH7IaybDdxCGI+HKJ4wjJDDbTFfuMB7TgyC8zGE99XHtCkHLcs30Eug3ApF+l/ b27uj2utxLK/nKopYgqPGmJbMZfU3jYhEbkJROEz4Tdr79wsAP9b0DjuYm+BiJyRop82 XfxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=xmkcyMZKGPzMvMKxjtfmwiWNsAxxqPR66jDHmZbAgx0=; b=aWQM3kgr39JZ8XLEunvTb++m82lHnKKZrQhQ2xaP+TFG6pEutUyXUGVG+B+TDKDLNY X1huGY0HuVAwFFMAIESRntHUfbbQ8R+QdHvY2WC536l5orp3zSdasQlXcnyqAPFZadsX Z92tgCWjpcG4nUVCoaWGvcPoHGVsVs9+6knzxAWjTZ9yrPPI9tFGnamPVVTrmOdZ7vHs sW7ME2jvLc7ytEHOgMU7nqCisAvyPRY336SkW6ToqKNiZteLuZYOtJ8nKsuMb3mZKYT1 +/kgowYiA/XeuAxQ6+ec7pk+XXW2/pq6/ZirXTjkpWYp/JWDPnUMn7WMqPNvaEDyd+eW 3TBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J7SKdesZ; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-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. [209.132.180.67]) by mx.google.com with ESMTP id v9si303525pfl.45.2019.01.10.04.26.03; Thu, 10 Jan 2019 04:26:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J7SKdesZ; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-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 S1728595AbfAJM0C (ORCPT + 3 others); Thu, 10 Jan 2019 07:26:02 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:36775 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728593AbfAJM0B (ORCPT ); Thu, 10 Jan 2019 07:26:01 -0500 Received: by mail-pf1-f193.google.com with SMTP id b85so5242917pfc.3 for ; Thu, 10 Jan 2019 04:26:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xmkcyMZKGPzMvMKxjtfmwiWNsAxxqPR66jDHmZbAgx0=; b=J7SKdesZLm6Y9+X6F2SsUmlo3xJzXD6shk9TFdntFYJZFwu+eCwEhAFHjhc5wmSEsm jbvAthFaklKJC+Z3Y78vA8b03Vv60Kcm8Txwoz4qjERSviQU1YXSC0o4tBfXDm96vYHp aemXD3QAeJnkKuq3CUrnnvJNosMSE1XFh2Yic= 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:in-reply-to :references; bh=xmkcyMZKGPzMvMKxjtfmwiWNsAxxqPR66jDHmZbAgx0=; b=iRCPOTaNYZCnQ/3/Ol+OawBg8zBOMeG8Jr+MWRDUIuHnI/fF9VXY5oW9TVwSAcj+ug Vf0hVg0s/wYFFv/1gc120GnNOBeifhI/m1tQnIK/IKMC84KTBUQ54pfxdw2UaPtrgA1v tbKWeSC9Qr3oZeQRH8wtQwcRkL1fcxwp7P6DVNRrfCX2dv17QjjkNCS7Kv71Aq6AllJ8 z3ikRi6Fupj9q8pNLwnvc3pMJZTEW6GgAsKQ3c/DcznS4zXzZwqQxbJmxDGNwgGNO3mx M3X/FC2sNqes+TK7TC0UpuDGDRnTvxAZtZY8QLhxknrGwfUhrM8wYnqO/MONUGpNiTjv iCog== X-Gm-Message-State: AJcUukdS6FERgcuPg8EeNzpo7PzG3+bP46P8wBWa3KJhhrKdtzmYtuJK 65jstm/FU8vXdrwG2b5zE3vvvA== X-Received: by 2002:a63:ea4f:: with SMTP id l15mr9028354pgk.102.1547123161238; Thu, 10 Jan 2019 04:26:01 -0800 (PST) Received: from localhost.localdomain ([117.196.233.251]) by smtp.gmail.com with ESMTPSA id m67sm142985541pfb.25.2019.01.10.04.25.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Jan 2019 04:26:00 -0800 (PST) From: Sumit Garg To: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jens.wiklander@linaro.org, mpm@selenic.com, herbert@gondor.apana.org.au, robh+dt@kernel.org, mark.rutland@arm.com, arnd@arndb.de, gregkh@linuxfoundation.org, daniel.thompson@linaro.org, ard.biesheuvel@linaro.org, bhsharma@redhat.com, tee-dev@lists.linaro.org, Sumit Garg Subject: [PATCH v2 3/4] tee: add supp_nowait flag in tee_context struct Date: Thu, 10 Jan 2019 17:54:56 +0530 Message-Id: <1547123097-16431-4-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1547123097-16431-1-git-send-email-sumit.garg@linaro.org> References: <1547123097-16431-1-git-send-email-sumit.garg@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This flag indicates that requests in this context should not wait for tee-supplicant daemon to be started if not present and just return with an error code. It is needed for requests which should be non-blocking in nature like ones arising from TEE based kernel drivers or any in kernel api that uses TEE internal client interface. Signed-off-by: Sumit Garg --- drivers/tee/optee/supp.c | 10 +++++++++- drivers/tee/tee_core.c | 2 ++ include/linux/tee_drv.h | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/drivers/tee/optee/supp.c b/drivers/tee/optee/supp.c index 43626e1..92f56b8 100644 --- a/drivers/tee/optee/supp.c +++ b/drivers/tee/optee/supp.c @@ -88,10 +88,18 @@ u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params, { struct optee *optee = tee_get_drvdata(ctx->teedev); struct optee_supp *supp = &optee->supp; - struct optee_supp_req *req = kzalloc(sizeof(*req), GFP_KERNEL); + struct optee_supp_req *req; bool interruptable; u32 ret; + /* + * Return in case there is no supplicant available and + * non-blocking request. + */ + if (!supp->ctx && ctx->supp_nowait) + return TEEC_ERROR_COMMUNICATION; + + req = kzalloc(sizeof(*req), GFP_KERNEL); if (!req) return TEEC_ERROR_OUT_OF_MEMORY; diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c index 9ddb89e..5d6c317 100644 --- a/drivers/tee/tee_core.c +++ b/drivers/tee/tee_core.c @@ -105,6 +105,7 @@ static int tee_open(struct inode *inode, struct file *filp) if (IS_ERR(ctx)) return PTR_ERR(ctx); + ctx->supp_nowait = false; filp->private_data = ctx; return 0; } @@ -981,6 +982,7 @@ tee_client_open_context(struct tee_context *start, } while (IS_ERR(ctx) && PTR_ERR(ctx) != -ENOMEM); put_device(put_dev); + ctx->supp_nowait = true; return ctx; } EXPORT_SYMBOL_GPL(tee_client_open_context); diff --git a/include/linux/tee_drv.h b/include/linux/tee_drv.h index ed16bf1..fe1a920 100644 --- a/include/linux/tee_drv.h +++ b/include/linux/tee_drv.h @@ -49,6 +49,11 @@ struct tee_shm_pool; * @releasing: flag that indicates if context is being released right now. * It is needed to break circular dependency on context during * shared memory release. + * @supp_nowait: flag that indicates that requests in this context should not + * wait for tee-supplicant daemon to be started if not present + * and just return with an error code. It is needed for requests + * that arises from TEE based kernel drivers that should be + * non-blocking in nature. */ struct tee_context { struct tee_device *teedev; @@ -56,6 +61,7 @@ struct tee_context { void *data; struct kref refcount; bool releasing; + bool supp_nowait; }; struct tee_param_memref {