From patchwork Fri Oct 13 19:32:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 10005893 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 F24C060325 for ; Fri, 13 Oct 2017 20:49:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0E50285FE for ; Fri, 13 Oct 2017 20:49:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4FE22893B; Fri, 13 Oct 2017 20:49:23 +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 37F04285FE for ; Fri, 13 Oct 2017 20:49:22 +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=XlyRSKx42GzmPkdZywSjNYHQwOLh7qwo4JX/Jnm/6Zw=; b=E00mFX9b1YHOjE Kv6dDRuA9nbQ+yreWRq9TmG72fJH6cXKOJbWx6AKdyADjh+tt8ZDtyLI1WquT1RxIxtiBGgfIroya argsEGN1ryLpnd2c2kTZrtobP8jq1PFnyfeZRBfyWD2nyFwIqE9Pl4w2FQPj2meHiGuzf0cIyvzkr o0jIv2vB+ZRG226ATseLWctZKH4aVkIroXVHuVNCVv8MoG/hCAq1OApp38TDaOcOLA2Toiy4PotHr a79dl70kGlbv4C/9lYw1ptOr/KDLYFvdXLUDKrYT6giSv+Twdz5p8pWJ3WrkMldW695CgSWf0JhIU MTYlL7lYMvaOEwkUF+KA==; 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 1e36tP-0004kz-Kl; Fri, 13 Oct 2017 20:49:15 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e36tN-0004kf-7z for linux-arm-kernel@bombadil.infradead.org; Fri, 13 Oct 2017 20:49:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=ak6EO8gcAl/9lVqfSJJJlnb7s/nUqpvchjyuvmjmAo4=; b=sFUoXJVmUafMv27TfLdQpExN3 V7Dalb7SnbOW8JG9wYZd5yBtYPaBUZs1K+wkzili1oayFuCqXIn5gthmo0hD2tArPF8lEj9aSFf5b 0DwWUyxQZlmKsisBbwrB2ia2zRjWLJAkWhphNBzpWxmMv/ltG3/wscnsKqAR6S52J7W+wm7E7CPqN +zwh2aD2dDy0l0NhD4xsEpdbNSCUlk+NGJYDIfqzIluYfdADb7kzpzDb2Aidc6/aNoiy/0Kh+Vlw5 0nxlZJYGkK8Va8i8Nh0qahtyWWrViWSyr40zUmpBMHCV2zHbrAhZ9v4RnykNFnY2rmwLZZMiuONTk Un5vorOpw==; Received: from mail-eopbgr00062.outbound.protection.outlook.com ([40.107.0.62] helo=EUR02-AM5-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e35jh-00049Z-8h for linux-arm-kernel@lists.infradead.org; Fri, 13 Oct 2017 19:35:10 +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=ak6EO8gcAl/9lVqfSJJJlnb7s/nUqpvchjyuvmjmAo4=; b=gJmw5iLFKU5ZQs0Zb95+n7hcB77r+pCkUX6E56NaoAQX0pybFo9u8L7uZF3zFDEY7MZpE4s/lHAQav7G6S535EaTBQ2pYOpJyQ+XvnOvknpOEFZXngnDQ344aAs0QAYaT3ajt/dH+MLby8vAZYIDQqReGfkccLU/5MhbeMyZirM= Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.52) by DB6PR0301MB2133.eurprd03.prod.outlook.com (2603:10a6:4:46::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Fri, 13 Oct 2017 19:34:44 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Fri, 13 Oct 2017 22:34:35 +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: Fri, 13 Oct 2017 22:32:43 +0300 Message-Id: <1507923164-12796-14-git-send-email-volodymyr_babchuk@epam.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507923164-12796-1-git-send-email-volodymyr_babchuk@epam.com> References: <1506621851-6929-1-git-send-email-volodymyr_babchuk@epam.com> <1507923164-12796-1-git-send-email-volodymyr_babchuk@epam.com> MIME-Version: 1.0 X-Originating-IP: [85.223.209.52] X-ClientProxiedBy: AM5PR0502CA0015.eurprd05.prod.outlook.com (2603:10a6:203:91::25) To DB6PR0301MB2133.eurprd03.prod.outlook.com (2603:10a6:4:46::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 37f1425d-4fd9-4146-e36f-08d51271753a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:DB6PR0301MB2133; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0301MB2133; 3:URndsGntjiJ9uFV7FJX0t4DZ4FpYhVEJ98itvFVS+fD4dA1s5HdooTnIwVwg41H1KbPBPrDL6vjM5BCGhgYYz+qg0IQ1/mtZmM5i/438vc+KL0rnErBQVpffTZtgcIkO1vlzYgk9d+vLMOJhnJO8bWwmA0zw1vwa8VeR4XkOCvkRDLlmZUvkzVJvyTL7hY/THxZG8CNlNavNI62H2NvxcaebrG1r4iIi5MH0C2jFYtD+RWZXhuUD/DY3H2ae1KX/; 25:Eb49fv0rENRESK1yzzQ+S8bLwYtB3bZbhfzX8N1geEbAS5U0XCFnMzMIMR49wUageFZLP224WvOgx9yiT4VOtZUUS7b0VZ8gh4A/8fzbibVw4ppCeBzKM09W5royMTmQIRO+71Da9qmv4owVr4bKvkQvMSaxurbDWt8JYsKJWhibfFGCCMOwCaTUP9NIUL0zg/Cw08jhMRacSL2wtWsSN7hW6PKsKSNC5aONi3eRO+yugNhLt1wxkCvCx5E7MHB03HNbNmVKAICQxgAsjF3QbRCP2bbcfSYsdBXYkeQXgYMrgDSz/Zkrngo5YzIV4YuwLIeJD5fRSUr3J1LZArNZFQ==; 31:RpF2qnyU9fMqyhyzqpHafRCnJNyC83dLl1bcpHOTwKWbndDXgi5x8PzF4DPs/p1NxKEPQ9yhCAW2jNW0KDCBOJ0fHfARKAyK6tJs7F4QUuECAQmtVe369/1zXjuWhcz8XVtAAFYS27ZfT/5YIv2d1/zbshS4q2YpLPDNFd/zv02fMikqeRq5Dw63vazBtsnwzSfoFkZXtovBRiJrLhQktsMFpMjXHxvN3ovqe6fWONs= X-MS-TrafficTypeDiagnostic: DB6PR0301MB2133: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Volodymyr_Babchuk@epam.com; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0301MB2133; 20:I85dkh1d7xKVYU4ksYYKgkb593qxfLECT5KUeoJ0xSHkwk7Wbypd/X1mn60bY6YvdalzdeFBySKsceGz54gLprLJmjq79mXobIobF/UEr8RvPZXrb7DvLnuefN7Qsb00XLTZnDoCPGwLwhPCtlQpuoJZ6gkeWjx7zvOa9ioI32DSKJ/c2+/nWN4U+UEn5aAU8rkeJB/kGnpqKxVcXgoDPX1UVYImq+nWS7+wE5X6433fLtoj1ObaAQxU6lsagghXO5l50j2mt1rLpjXcC4V1cSq01Hxdi3r6/sz0SPUPctuCIgezIzbgye7Vc10auk7/wnFxKiZ14Eep7vwtOqv0bDhwDgez18qpJKU/rPHJWMUTnx9Xrt9qfnc5TlfcCv+unxARUHKIpikzEfuYvQgTARda1Iui7OliI1tu1qMRHAZmc7N7vu/gJMxHs7LQlKopPDu9wgb1dM+/2YyTuC4vO9PmtsnUwbO7fwKBFMoymBy+4GYVRRKqRbX62svnah7W; 4:u6XkSvPSNUgWnsT/IA+qM0jSq96SdtPW94ROOJgO3H2rtCKOApeiJGiiJoP98XcjpSFeKUS2V+128vjl+rIk+DcFhTzeOclg3FtbfX+Tfesi2JqddZ2AV44k+VUNrPSd2oQA+Jxh6613WqrWtlb6HlSZTXG5B3+VIqShUznxrmyEywSdtx57gEAWS6ojRkXvl8zV4kS6biDT499zlLPuIot29N861DNSI6IfFeyr1DlbrNlX36nKTyzFQaEOQk3L 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)(5005006)(8121501046)(93006095)(93001095)(100000703101)(100105400095)(3002001)(10201501046)(6041248)(20161123564025)(20161123555025)(20161123558100)(20161123562025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DB6PR0301MB2133; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DB6PR0301MB2133; X-Forefront-PRVS: 04599F3534 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(346002)(376002)(199003)(189002)(8936002)(305945005)(81166006)(3846002)(7736002)(6116002)(2950100002)(6916009)(33646002)(2906002)(5003940100001)(8676002)(106356001)(105586002)(81156014)(86362001)(189998001)(5660300001)(42186006)(16586007)(316002)(66066001)(6666003)(36756003)(101416001)(72206003)(478600001)(50466002)(50986999)(76176999)(48376002)(47776003)(68736007)(122856001)(50226002)(80792005)(39060400002)(97736004)(107886003)(4326008)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0301MB2133; H:EPUAKYIW2556.kyiv.epam.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; DB6PR0301MB2133; 23:mTcAAGKT2aI9/qJHFVpsR9er6Joa5OqN7DxpU2+?= =?us-ascii?Q?cAeIUvNOLbH+vba9Y590ABSbnHeDvRQalP8GG3pv/Vhlq/hlYit4VhAV+nlw?= =?us-ascii?Q?TjMZeg7S5tIJTSTveN/xs8XdTZI5Ax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DiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2017 19:34:44.5503 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0301MB2133 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 , volodymyr_babchuk@epam.com 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 177e341..b48f83d 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); @@ -252,6 +256,8 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, return ERR_PTR(-ENOTSUPP); } + teedev_ctx_get(ctx); + shm = kzalloc(sizeof(*shm), GFP_KERNEL); if (!shm) { ret = ERR_PTR(-ENOMEM); @@ -333,6 +339,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 5489c38..9cd4e5f 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 {