From patchwork Fri Oct 13 19:32:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 10005779 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 A53C7602B3 for ; Fri, 13 Oct 2017 19:37:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 977F32915A for ; Fri, 13 Oct 2017 19:37:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8BC8D2915F; Fri, 13 Oct 2017 19:37:02 +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 2A33A2915D for ; Fri, 13 Oct 2017 19:37:01 +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=QiHp7XmRLwtPSt1R1Y9s5BPbPMqXLKAzqZpVSexxcBE=; b=Dwmg1GMz0EX5PG Z0xNwqosytI0piChqcxPrmY7TiuQhaXk/kh5LJmxDt6j+ChtjqmxBxWBkPJI+ObtuRiC35nkkqdOj /n8zHHsinGRdhnzv/Oc0zRsOHKa0QVDuezhUEHwjeQDX1YwCvC9yLL1LGCzPpz27ypDsWGuyMhk7Q FRNDrT7bK5ynf5iIETv6u7i+txVNC1dQDVUN/tNC8w7qBxIP0bsODwOR8b9dlFIa4AZHO00nc8WoA vaG04n1PLeUHT1fPN180xqm2C5Y5YbwObGc5GtntQKADQlhzX0i8Ro0U+gVh5BX51UHDJYgymVnEu tPgRtyomSCBg0DyjY12g==; 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 1e35lO-00027o-V1; Fri, 13 Oct 2017 19:36:55 +0000 Received: from mail-he1eur01on061d.outbound.protection.outlook.com ([2a01:111:f400:fe1e::61d] helo=EUR01-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e35jS-0007eX-13 for linux-arm-kernel@lists.infradead.org; Fri, 13 Oct 2017 19:35:13 +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=QPR87IbnUngJR+f4ooYMgdXOdSuPWqjy17KMp3D0lr4=; b=GaWnQKATGdAIxoN40Rc8zJyams+l9TUUK1/qgoMFQvKPHhkaN+pBwVwnW3rhDZ7TRGZWSXRmv7SMm06SqiBYaoTAPpP+sfkqpvNiszqDhuuppDcJMml/jvKbytyjvXhn+tDivzJKBqwT4z6igFHXs9Rh7pxzEgVDwM+/j3/VQ5M= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Volodymyr_Babchuk@epam.com; Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.52) by HE1PR0301MB2137.eurprd03.prod.outlook.com (2603:10a6:3:21::14) 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:27 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Fri, 13 Oct 2017 22:34:21 +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 11/14] tee: optee: add optee-specific shared pool implementation Date: Fri, 13 Oct 2017 22:32:41 +0300 Message-Id: <1507923164-12796-12-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: AM5PR0502CA0008.eurprd05.prod.outlook.com (2603:10a6:203:91::18) To HE1PR0301MB2137.eurprd03.prod.outlook.com (2603:10a6:3:21::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c27cfe51-4a26-4285-1edc-08d512716afc X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:HE1PR0301MB2137; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0301MB2137; 3:u+6tF6VDgWzdkiebtxC5FP1tT8iwS2SZeH8ef7XXBf2/FB0LMMLr8hUdo4ig806TdIHA4qj3U5bEVOygnhXJXlv/iHVQ85AILZilknffSljN1RB0EQt4hkKpScBvMGpLKNwuDh5KYCJ2ThfQkHuGxI0xKxNUojIbKjYFZgqjlFuY+fVRRWVqBqnHRY6RedbZ96DpN5CJBFMuM5Ua0rORQuYJ3gn9GZeLnz0ygHA7//noD+iOZh0SgYa6Y/T/6My+; 25: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epuDMb4scqRAgbm0esXes69undy0avWOJm4B0FvK5hlTq3zkM35pWuGxS4Dqj6al4icRlDrwo5O1bA9hyHrKBCeUVpijGGDjx; 4:Y3Dbz9N6ZrdJRVviPhAGeLS1hgRE7SxisJ2FCR3v/gPk8PwdcQ9GrDxT8HsiPQn1xeu8t8GqkC4x2+VTQ8X37+Ewb962U7aLDNwmuVhKXMsi1CHHhyVYq37XbdKdjH7u/Hn2sAcGoou+KqJSHqkAvhqwJGOo31+OvmTJN1suapZtuHiGbsiwrJOqeDrm/8+zzimYho2S6TTA4URgCVr7wOmwQv+WNAYAmpfZ8PAvSwsYRBBTY9Bkrd2jmVkIDMvY 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)(93006095)(93001095)(3002001)(10201501046)(100000703101)(100105400095)(6041248)(20161123564025)(20161123560025)(20161123555025)(20161123558100)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:HE1PR0301MB2137; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:HE1PR0301MB2137; X-Forefront-PRVS: 04599F3534 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(376002)(346002)(189002)(199003)(478600001)(72206003)(36756003)(101416001)(5660300001)(50986999)(122856001)(76176999)(86362001)(66066001)(47776003)(50466002)(48376002)(4326008)(105586002)(106356001)(97736004)(80792005)(33646002)(107886003)(39060400002)(53936002)(5003940100001)(81156014)(81166006)(68736007)(50226002)(8676002)(6666003)(2906002)(3846002)(6116002)(8936002)(16586007)(7736002)(316002)(42186006)(2950100002)(6916009)(189998001)(305945005)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0301MB2137; 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; HE1PR0301MB2137; 23:SnO+8niUMzDpn0csMZ7L8rA7QIIxDrlxfuQ5ap2?= =?us-ascii?Q?5P/Z8Q+IIZ6siA32ww3bMe4gbSq0MK+9RSh5JhONCP+aCBZqRN4x8V5lWLEA?= =?us-ascii?Q?UsSYNAUoBkeko9FzPE/ftNvou5SV6yxiupnpGHb+QGLLwN01h+WwABRNOk+M?= =?us-ascii?Q?3JgOLH0eLVlpvj3YOef2Y6kcJCApVhGymXtjMYHyx2NmnUMrq/DdhKCTqJmx?= =?us-ascii?Q?PM6s4bDT7dwR0XPimZOcZeU+wFOkIh/me4FMFMzyHmOsi/lqxTGy1QgOndtR?= =?us-ascii?Q?DgtYQl3VA+3BcFr3UK0q7MQAieFkJI3I0pUiovnsZB+/8NDiw7wgpA/Rc32S?= =?us-ascii?Q?xbEBGYdySQD3Aml6iSgW2a+5PcagomBoIx7cN4sle/+81jUkbiYwH4rLCk9a?= =?us-ascii?Q?mf3y8s3boQEDoQ+CV3xQ0f8RebwuM3dEukL5hOMYe7eJGx2UXaUGnn3jUjxZ?= =?us-ascii?Q?+uc7a+KdzlQvkf6e3lEQtmW2j029M8TvjZbgffxKhwVUEp6ONOY3Rcx0kLaP?= =?us-ascii?Q?iRkck6BK9mXy9fP+6ipR3N1RNwd9i6EKWAd+gAmoXgVay7bZikSxPDU8dsRP?= =?us-ascii?Q?ZpQbBJ8z+HFDhKqfG7kZZMWDq4+tjT94cfhfLGHRItFq9FvyMwvggMDopMJ+?= =?us-ascii?Q?6gXLSOihuK2py12mEb3ChQgX9UYtsP2nbCxLoLkr2veaCfs7F9JomJN3MieV?= =?us-ascii?Q?p22SpWHHKZjY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uDFfHnwrdA+wNfkuvDC1eYvq9JljzecaN03VCYQtOZ4wcpBwwe4tUt9YuyQCJDrQHasE2Od5OYczHqmUDiMfI5eojLS2NS0uozDfq2a7qXs=; 7:YVnUwO09FIe6zsSUBdoWaL67AnXxGsNzFHT8RzqEouWGtyjuSp8IU1AivBO0vLP6L3VYsaoU0d94fHcrOg9PEngqXtVV+12LLOnlg134RctQfS7Hd+tdLvvzfJosxXXN3XLj4/X4NaUmHgW2FfOHVOK2xXXqLh82aT2QQalKJQ15PBEq1jCQNDUSewlJaL1m0YWzsvm5m8Iernr+5Amkfm7OE+WWKXi558hbDRbsiBw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2017 19:34:27.2836 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0301MB2137 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171013_123454_612006_7137BF2F X-CRM114-Status: GOOD ( 14.68 ) 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 This is simple pool that uses kernel page allocator. This pool can be used in case OP-TEE supports dynamic shared memory. Signed-off-by: Volodymyr Babchuk --- drivers/tee/optee/Makefile | 1 + drivers/tee/optee/shm_pool.c | 75 ++++++++++++++++++++++++++++++++++++++++++++ drivers/tee/optee/shm_pool.h | 23 ++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 drivers/tee/optee/shm_pool.c create mode 100644 drivers/tee/optee/shm_pool.h diff --git a/drivers/tee/optee/Makefile b/drivers/tee/optee/Makefile index 92fe578..220cf42 100644 --- a/drivers/tee/optee/Makefile +++ b/drivers/tee/optee/Makefile @@ -3,3 +3,4 @@ optee-objs += core.o optee-objs += call.o optee-objs += rpc.o optee-objs += supp.o +optee-objs += shm_pool.o diff --git a/drivers/tee/optee/shm_pool.c b/drivers/tee/optee/shm_pool.c new file mode 100644 index 0000000..4939781 --- /dev/null +++ b/drivers/tee/optee/shm_pool.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2015, Linaro Limited + * Copyright (c) 2017, EPAM Systems + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ +#include +#include +#include +#include +#include +#include "optee_private.h" +#include "optee_smc.h" +#include "shm_pool.h" + +static int pool_op_alloc(struct tee_shm_pool_mgr *poolm, + struct tee_shm *shm, size_t size) +{ + unsigned int order = get_order(size); + struct page *page; + + page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order); + if (!page) + return -ENOMEM; + + shm->kaddr = page_address(page); + shm->paddr = page_to_phys(page); + shm->size = PAGE_SIZE << order; + + return 0; +} + +static void pool_op_free(struct tee_shm_pool_mgr *poolm, + struct tee_shm *shm) +{ + free_pages((unsigned long)shm->kaddr, get_order(shm->size)); + shm->kaddr = NULL; +} + +static void pool_op_destroy_poolmgr(struct tee_shm_pool_mgr *poolm) +{ + kfree(poolm); +} + +static const struct tee_shm_pool_mgr_ops pool_ops = { + .alloc = pool_op_alloc, + .free = pool_op_free, + .destroy_poolmgr = pool_op_destroy_poolmgr, +}; + +/** + * optee_shm_pool_alloc_pages() - create page-based allocator pool + * + * This pool is used when OP-TEE supports dymanic SHM. In this case + * command buffers and such are allocated from kernel's own memory. + */ +struct tee_shm_pool_mgr *optee_shm_pool_alloc_pages(void) +{ + struct tee_shm_pool_mgr *mgr = kzalloc(sizeof(*mgr), GFP_KERNEL); + + if (!mgr) + return ERR_PTR(-ENOMEM); + + mgr->ops = &pool_ops; + + return mgr; +} diff --git a/drivers/tee/optee/shm_pool.h b/drivers/tee/optee/shm_pool.h new file mode 100644 index 0000000..4e753c3 --- /dev/null +++ b/drivers/tee/optee/shm_pool.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2015, Linaro Limited + * Copyright (c) 2016, EPAM Systems + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef SHM_POOL_H +#define SHM_POOL_H + +#include + +struct tee_shm_pool_mgr *optee_shm_pool_alloc_pages(void); + +#endif