From patchwork Thu Sep 28 18:04:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 9976655 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 978D360375 for ; Thu, 28 Sep 2017 18:20:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B28C296DE for ; Thu, 28 Sep 2017 18:20:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EE20296F6; Thu, 28 Sep 2017 18:20:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F3700296DE for ; Thu, 28 Sep 2017 18:20:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=junHTiTt3cZ9TlJoTXyuk8gcNL63dsB/1mw51f25amc=; b=b3DJJFR0Tb6E3d R+W7TbospAN8TUwWc8nFaLj1eFQYhJC+R/0yJk0e9kOe+8sTCTJfAQptX2TfVevoH2IbEs3Hrm/by GfpcosnX6BpmyvjvbBG2ZJDTkMuioad1nXpA7plez/B+zfcS7AEbk/WR0XnyJxirzdDhcVGNG6Rvu N7wQUGkg0MaGi7RsgiLQg5wNjj3Bfq0yACqdrW34SW8DDyQBBUVoGCPLQXZ8CHed59BMIGZABMV19 UUvmXZysdIcruNa4Y08uHeP4AjDE06mnu7dl/1TP7BFRwcJDGsaRIFGIC+xTWxpc0C8JJKqisKf+q kq0ZeFZH/iSJ4WM4bYvg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dxdQ9-00006T-7q; Thu, 28 Sep 2017 18:20:25 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dxdO7-0006jO-2g for linux-arm-kernel@bombadil.infradead.org; Thu, 28 Sep 2017 18:18:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=cjVzPI+sdOFH6gWz3mBmh1B9a7LYRjS+SHrL8c/PUS8=; b=jREDMdRTXyFCkfVg70Af5Z7Oe T0MCTuG86S0Z3hpmPhChGx9+fY+h3B/xavCzLXWDMAIQlZi7OPUQ6SBbrR9k1tsVWdCUF9Ukx4pvF BOVFFq7l0tCkyoT6cPipK/to4gp20xoQJCpPnE8AphXwdCX5x2RUMo7LZGBxl9YooaCJqjPRX8guI F3rhiBuNau4WNzsckTKAFkStL6ewwrpDn/bTCQbOAOomnQKdRWMr8FdKGwoBke2OTLbG2pkXHr6MY JBkbjq9+NGROZSnDFmTznCQiTSVdwcJO+8jLegcUOAz5z3ESKELYU1O3qo5ZdfWzWYaMZgYYSVwI+ JLcgs0DJg==; Received: from mail-eopbgr30068.outbound.protection.outlook.com ([40.107.3.68] helo=EUR03-AM5-obe.outbound.protection.outlook.com) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dxdCL-0001JP-Jl for linux-arm-kernel@lists.infradead.org; Thu, 28 Sep 2017 18:06:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=EPAM.onmicrosoft.com; s=selector1-epam-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=cjVzPI+sdOFH6gWz3mBmh1B9a7LYRjS+SHrL8c/PUS8=; b=WBas9sUjV81HUkDVeYJ+SNZ2FQfSJahfY67zjUwImFI61nBbWq+Ohj50dCeJZI4KKrLKhsB9KctO1oXDTgmmWiHot6+1Yqxwqhy+F6oP6PAroOFCsZ1mltjLAYvr7N7NUoxQ8R7Fw19TyXpoinm/rnvy6Psd2I0jlDC3hfKE1hk= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Volodymyr_Babchuk@epam.com; Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.59) by VI1PR0301MB2142.eurprd03.prod.outlook.com (2603:10a6:800:26::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Thu, 28 Sep 2017 18:05:55 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Thu, 28 Sep 2017 21:05:51 +0300 From: Volodymyr Babchuk To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, tee-dev@lists.linaro.org, Jens Wiklander Subject: [PATCH v1 13/14] tee: use reference counting for tee_context Date: Thu, 28 Sep 2017 21:04:10 +0300 Message-Id: <1506621851-6929-14-git-send-email-volodymyr_babchuk@epam.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506621851-6929-1-git-send-email-volodymyr_babchuk@epam.com> References: <1506621851-6929-1-git-send-email-volodymyr_babchuk@epam.com> MIME-Version: 1.0 X-Originating-IP: [85.223.209.59] X-ClientProxiedBy: AM5PR0601CA0048.eurprd06.prod.outlook.com (2603:10a6:203:68::34) To VI1PR0301MB2142.eurprd03.prod.outlook.com (2603:10a6:800:26::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7b6dee52-f0c1-49ef-86e5-08d5069b909e X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:VI1PR0301MB2142; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0301MB2142; 3:xHPdaOUKJzj045zHZ+lO7Nrmz35Ig+vn5WVise38Gpk3JdZWzk76g4D5qeyb8xw2VUKZoAU6mB9T2qk0kjvE+KG9ghmoshAO4jdT+3wdVAMTy4M/A8Rnx2I282Z39S8SRH8z2WlFh1X/oAtFeaHq3uZdchojwEUc+c+PHJ1+1NRTYzAvI9t+TyLhuqEK7pamaM8E5oaNCV5+AvvVh1cLfTE1XJXTbPWEFL6GYBNQIooMuFAO0dp7HCdAz7adqynt; 25:e4pZQsnD4zmEd0sNgZnLVs448G76LYw0EmpKIzY3Dw4sN7rtTSUtL7MzOhR716HaPY58DQHBtcWM5qS8eIM8GFKphQKhUl6TAQgvd8YgZBr/pOFkylNnWg3Ba85IWhvbWJFTDDG96/qgvNdHUO/uimYpfqi6DEpfZlPXgWnJKtv+MU8aEa6c0HqnlVlFJzQGWVtcaB4f/3ofbeG7890dhWRR8uMq9PssD7sCh3MKv+waLth9m7mtP5mDAP3dvdL6N5+8142dWcD9V5i2zb73Ur2rFzP4ggrOKHrCW8ydTVx8fQ/gJUX86kmTW2fIuY3aaKYRON6gRTLni/zXsg59JA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SUHwrjJbXMbjJl X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(93006095)(93001095)(3002001)(10201501046)(6041248)(20161123560025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123562025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:VI1PR0301MB2142; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:VI1PR0301MB2142; X-Forefront-PRVS: 0444EB1997 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(376002)(346002)(189002)(199003)(6116002)(97736004)(42186006)(66066001)(53936002)(80792005)(316002)(16586007)(5660300001)(86362001)(50466002)(122856001)(4326008)(3846002)(478600001)(47776003)(72206003)(6666003)(68736007)(81166006)(36756003)(105586002)(50986999)(5003940100001)(81156014)(8936002)(76176999)(101416001)(106356001)(50226002)(8676002)(189998001)(2950100002)(39060400002)(6916009)(48376002)(33646002)(7736002)(305945005)(2906002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0301MB2142; H:EPUAKYIW2556.kyiv.epam.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: epam.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0301MB2142; 23:wtwGajYLk+7RjDAsq85S9lMu7kZKZmwEqzszCNU?= =?us-ascii?Q?OZmA4FdkAmB/8tMUXluxdDt+Lb2TFp48bpZsXyClv0x0k996cwpFdGZ+omUu?= =?us-ascii?Q?Pvgy5zg7WWQ/dGm/KbVj5RK8PT9rUDS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JmpxlF534QJIWWuNZSKhDIEi6WjZOnWRoOaGeoRH3S+k6cR3mV1afQmtN1Dy?= =?us-ascii?Q?RB/CLAkCT4Nk/7x79I8Z8ffLbz5Gi?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR0301MB2142; 6:O5bxan9duLIZfdQABgTfKyN6zsVnlLnBJ6hY+H64z84Egkwi48hPkkhL2e+xnifQodo2jP8rt1OQsADx0cK/VXzE9XhhVESTWF87NzqmrCyK7s9D9dg/yNo54Y6ozJovTgtqIEVAppiDYyhMddtR030RMuudVL9yGlbfGU69NOg610FNXdY2kAPx3lwQ5hrPxKBiN6lBefyvLX1hvJ14Ud2nQN4ESfbDEcMVqAb+hXalbI6pXDN1aookKFkuI0R/POOBntKecNu1Chiryhygp+kKSRN9hyViU1rvCgUaI/7JCLxXYHFGgU2phliC5x+Ds9OKCRS37lj9WV72mDnbJg==; 5:hmDRpJuy7JYmgfhFvZr6BJU+8YfTDZsMMZOpsOy9u5WwZsKb7X0fjC2y5nD/qijh2pwEB871SF1CFbmOGWoeKJC+zVqq9qhfNwgaIxEP+SURsYaUkjbkOspvhhS+vvxJvgXDdKF6BtgDs7lH1keHPQ==; 24:SGAQL1cy0wcROSLWgIlTbnr1dMWnGxXouYVWKnP9j90atslOr0R9sOeDfkPiGgHxZ31lNfQdC7hceBufPSzuEXMDgyEHUP3IGiefwBBUOUY=; 7:WkOG+IJa6UZI1wS34flRFEAVQY1wrFN6S7wOAWcNBhDFG/NKbd8uJk64ydDZuxHFO7aLaAZ41khZtCaZAY1bni9sN1hJkI7zh3CGbAak9UGG73C2xu5bYnk+9G6LHdmgKUY69jRfn4rUFNv5CKrt5P8rg389JmimZERYUfhrhAWPziwaFf/8wNSrWXCkIaqeTK0GgVNEl/KF6Rt6aNJlcR1Et4xZZKSglS1cXlFy+Vs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2017 18:05:55.4580 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0301MB2142 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170928_190609_744958_A2222D8F X-CRM114-Status: GOOD ( 16.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Volodymyr Babchuk Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Volodymyr Babchuk We need to ensure that tee_context is present until last shared buffer will be freed. Signed-off-by: Volodymyr Babchuk --- drivers/tee/tee_core.c | 40 +++++++++++++++++++++++++++++++--------- drivers/tee/tee_private.h | 3 +++ drivers/tee/tee_shm.c | 7 +++++++ include/linux/tee_drv.h | 7 +++++++ 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c index 295910f..3d49ac2 100644 --- a/drivers/tee/tee_core.c +++ b/drivers/tee/tee_core.c @@ -54,6 +54,7 @@ static int tee_open(struct inode *inode, struct file *filp) goto err; } + kref_init(&ctx->refcount); ctx->teedev = teedev; INIT_LIST_HEAD(&ctx->list_shm); filp->private_data = ctx; @@ -68,19 +69,40 @@ static int tee_open(struct inode *inode, struct file *filp) return rc; } -static int tee_release(struct inode *inode, struct file *filp) +void teedev_ctx_get(struct tee_context *ctx) { - struct tee_context *ctx = filp->private_data; - struct tee_device *teedev = ctx->teedev; - struct tee_shm *shm; + if (ctx->releasing) + return; + + kref_get(&ctx->refcount); +} +static void teedev_ctx_release(struct kref *ref) +{ + struct tee_context *ctx = container_of(ref, struct tee_context, + refcount); + ctx->releasing = true; ctx->teedev->desc->ops->release(ctx); - mutex_lock(&ctx->teedev->mutex); - list_for_each_entry(shm, &ctx->list_shm, link) - shm->ctx = NULL; - mutex_unlock(&ctx->teedev->mutex); kfree(ctx); - tee_device_put(teedev); +} + +void teedev_ctx_put(struct tee_context *ctx) +{ + if (ctx->releasing) + return; + + kref_put(&ctx->refcount, teedev_ctx_release); +} + +static void teedev_close_context(struct tee_context *ctx) +{ + tee_device_put(ctx->teedev); + teedev_ctx_put(ctx); +} + +static int tee_release(struct inode *inode, struct file *filp) +{ + teedev_close_context(filp->private_data); return 0; } diff --git a/drivers/tee/tee_private.h b/drivers/tee/tee_private.h index 2bc2b5a..85d99d6 100644 --- a/drivers/tee/tee_private.h +++ b/drivers/tee/tee_private.h @@ -73,4 +73,7 @@ int tee_shm_get_fd(struct tee_shm *shm); bool tee_device_get(struct tee_device *teedev); void tee_device_put(struct tee_device *teedev); +void teedev_ctx_get(struct tee_context *ctx); +void teedev_ctx_put(struct tee_context *ctx); + #endif /*TEE_PRIVATE_H*/ diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c index 1ed708c..5176c83 100644 --- a/drivers/tee/tee_shm.c +++ b/drivers/tee/tee_shm.c @@ -53,6 +53,9 @@ static void tee_shm_release(struct tee_shm *shm) kfree(shm->pages); } + if (shm->ctx) + teedev_ctx_put(shm->ctx); + kfree(shm); tee_device_put(teedev); @@ -187,6 +190,7 @@ struct tee_shm *__tee_shm_alloc(struct tee_context *ctx, } if (ctx) { + teedev_ctx_get(ctx); mutex_lock(&teedev->mutex); list_add_tail(&shm->link, &ctx->list_shm); mutex_unlock(&teedev->mutex); @@ -256,6 +260,8 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, return ERR_PTR(-EINVAL); } + teedev_ctx_get(ctx); + shm = kzalloc(sizeof(*shm), GFP_KERNEL); if (!shm) { ret = ERR_PTR(-ENOMEM); @@ -332,6 +338,7 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, kfree(shm->pages); } kfree(shm); + teedev_ctx_put(ctx); tee_device_put(teedev); return ret; } diff --git a/include/linux/tee_drv.h b/include/linux/tee_drv.h index d773827..6aaef65 100644 --- a/include/linux/tee_drv.h +++ b/include/linux/tee_drv.h @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -42,11 +43,17 @@ struct tee_shm_pool; * @teedev: pointer to this drivers struct tee_device * @list_shm: List of shared memory object owned by this context * @data: driver specific context data, managed by the driver + * @refcount: reference counter for this structure + * @releasing: flag that indicates if context is being released right now. + * It is needed to break circular dependency on context during + * shared memory release. */ struct tee_context { struct tee_device *teedev; struct list_head list_shm; void *data; + struct kref refcount; + bool releasing; }; struct tee_param_memref {