From patchwork Wed Nov 29 12:48:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 10082083 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 CDCB96020B for ; Wed, 29 Nov 2017 12:53:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C13152976B for ; Wed, 29 Nov 2017 12:53:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B63BA2976E; Wed, 29 Nov 2017 12:53:12 +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 84BEC2976B for ; Wed, 29 Nov 2017 12:53:11 +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=P9/nLw/WFitmBD PKXVh2gZPVx7JMrskgAg2sZlo7aV3mHhX89whxD621Ci+4DuzWISGB7rC90EBvlY/HxXVMoFia9Wc eXjCuKiUvGLnKqIe8uhvOeT7bh5tVIpcbVIdCjclBH+/+HPytzXsINeWGntpzRoVzPEzq8xtZQ9fy 8ymSvf8XUmx2yas5xbhY2yh+XAudl6T/Lnf41htVRHqn5phCTyDe1/qlsx3MQsKh3u3LDo11Hr64p ppuJWAA/X28Fxx68+SdTQ8NLhq7+CyBKmt05viKvMfByLuXxJfPAGtP65sMcD1A5YG1RZSZVTx/0T MANN+JOSBNmifw3MKORA==; 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 1eK1rS-0007nL-Pv; Wed, 29 Nov 2017 12:53:10 +0000 Received: from mail-db5eur01on0058.outbound.protection.outlook.com ([104.47.2.58] helo=EUR01-DB5-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eK1oj-0004Uv-Lt for linux-arm-kernel@lists.infradead.org; Wed, 29 Nov 2017 12:50:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=QPR87IbnUngJR+f4ooYMgdXOdSuPWqjy17KMp3D0lr4=; b=IivigjIDuzdBcQSpKJHL/M330VjkLDmYClqfiooe3xS9PbOBbdB+QfvApfsmjRg74I199WN1zY+NA9O6aFjInGoRGPcIs7+EY/0lDK3Wzs1MmK2QPZk7JA5herb0OKjL83h1EirMu6bmp2svVWELKJ6pAQy5a8KpSiQBvY9bALY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Volodymyr_Babchuk@epam.com; Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.56) by DB5PR03MB1768.eurprd03.prod.outlook.com (2a01:111:e400:c580::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.260.4; Wed, 29 Nov 2017 12:49:56 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Wed, 29 Nov 2017 14:49:52 +0200 From: Volodymyr Babchuk To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, tee-dev@lists.linaro.org, Jens Wiklander Subject: [RESEND PATCH v2 11/14] tee: optee: add optee-specific shared pool implementation Date: Wed, 29 Nov 2017 14:48:35 +0200 Message-Id: <1511959718-5421-12-git-send-email-volodymyr_babchuk@epam.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511959718-5421-1-git-send-email-volodymyr_babchuk@epam.com> References: <1507923164-12796-1-git-send-email-volodymyr_babchuk@epam.com> <1511959718-5421-1-git-send-email-volodymyr_babchuk@epam.com> MIME-Version: 1.0 X-Originating-IP: [85.223.209.56] X-ClientProxiedBy: HE1PR0102CA0049.eurprd01.prod.exchangelabs.com (2603:10a6:7:7d::26) To DB5PR03MB1768.eurprd03.prod.outlook.com (2a01:111:e400:c580::9) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3a035892-7d53-47a8-3eb4-08d53727b22f X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(7168020)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603199); SRVR:DB5PR03MB1768; X-Microsoft-Exchange-Diagnostics: 1; DB5PR03MB1768; 3:bQf9DzIv0/8JAPu9xFr1OY86CrJmSqEpqL+J2NFI1g8V2DvCxGxd2ZNHt/WHJWZU3ZJ3L0E/KQPDddbSRepOlmwlyi7U3ULdnAOoAfVGSl98AsDnZrp1yb06EHvkqO+RZ6jnVWVqFHcR2Ui3gG/vbUZV2Dp5uIrUk2Oa1KRdci3Z8TY9lK66nTAyIEUCWhYg+pgTssUuoPhZwbAuxMjlXQOoNZnBGpDbL2BQQE0Z2/Ap0kNJj5RTp7cBNSuJz1e6; 25:UOZ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wVXtc+7Zgp3xshJnfXNb3cwI4THM3WdDNcTiD42dP3Rc1ia+PSPgvk61pQ/Rra96TOP5Fy0S6JNwhsVDmWlpTLRQ/1Ose7ewl1NETZwVrt; 4:XZp7NfdK/ZX+7i46a+4QNCaaI8W0YemyV584DaCoCOpiXNr+0s7KEedRh/qUhoQh6U+ErzyVAh/DKiuKwhMk2pRVozUXkCM50rdk4fQrcdGD+/WKTjTTZIXGDm6h2AlnbGw30YvJEl1aTQ+03NsXinXXesMoUJWAm8pOL4Jy21KB2nBBdzOWLNZcTahF8ws3gGmUp3Ddwrm0oZxxzLUV5laphNSDggRvqkKvTOjzb8qzk5t+l/gfj/63OkeNUP8xfTuPvuJ25nTpo127B1ow6g== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231022)(3002001)(10201501046)(6041248)(20161123564025)(20161123558100)(20161123555025)(20161123560025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:DB5PR03MB1768; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:DB5PR03MB1768; X-Forefront-PRVS: 05066DEDBB X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(366004)(376002)(346002)(189002)(199003)(86362001)(101416001)(76176999)(122856001)(50986999)(105586002)(6116002)(68736007)(97736004)(106356001)(305945005)(4326008)(5660300001)(53936002)(66066001)(2906002)(3846002)(189998001)(47776003)(7736002)(16586007)(50226002)(2950100002)(8936002)(6666003)(316002)(8676002)(6916009)(80792005)(33646002)(81156014)(81166006)(72206003)(39060400002)(42186006)(107886003)(50466002)(48376002)(55236003)(51416003)(52116002)(36756003)(478600001)(2004002)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB5PR03MB1768; 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; DB5PR03MB1768; 23:UlVhmMK8+O5JQjzXwWCeCT0R9bF/t6HaT348Af/FZ?= =?us-ascii?Q?c5ClYEAoA2PzO1O1uvfBgvJAXAputhxcrzLNGE7YnGrVOZeWkLNrO4Zi0VVa?= =?us-ascii?Q?7addR7aXQl7N8pZa5o8SnresjtjipY4MmToGsiyMKc+5+TqjJ/WVM+aHXe8u?= =?us-ascii?Q?c3zjOfneicgJGhNe5GS+cHWwH35edIjUTX3GSCML2KFrT6yxXCaItppZQUGs?= =?us-ascii?Q?zfV1LQ1+tdxmxy+7cq1uvp6NZbgsjIecZJZCXI8OaCs2uWMM7CxhX79TZDU+?= =?us-ascii?Q?YDwTucINw7U9FxgKuiP0OheqzDDY4uHz8Tz1W6JyqY0sOykUgXbwljx3UIIU?= =?us-ascii?Q?z8mIX9ShzjU3vEXDn4QRJVem+9LiFmudeOa7sgKYyj4M2d4UU2JhnuaO5++Y?= =?us-ascii?Q?n/Mp/VKn34LP5rdyzSsL3h3vt4/cMIqXOh+3xEBfGL9y7tArRpP/SY585env?= =?us-ascii?Q?43HLyPH+OebpYj1zy3qgM/btPwRduQt4WJXnwPj28C3iEQs9g540FaBKcUK2?= =?us-ascii?Q?+Yps2/s6Vt/8OQ8y/d161j8lIl4G/+AXskSWztWwfHSXjWrKfUxzoN7zGj/+?= =?us-ascii?Q?0I1GluUSQrCNTwW3IvvxjaiTHMGMPQQsIRygVGtfJx82lcWYX5K7GkSk5jse?= =?us-ascii?Q?izUXAi3gyLnS6bnNoeJWlWkM9GJ33AyYNFXTBlj7UKi6t1Vw3291og1C3h1+?= =?us-ascii?Q?1uN1uWyxaZP2Rv0LtK1sJwfumG+6jF3v/Ng9qai+B1ZPYXM+dLyXise61kEa?= =?us-ascii?Q?wd/+omBda7Fw7c1k01dfmTHGdbdkwAW/H62AL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8=; 24:dPM06bwmLmoMgviuZNszWBH2hFkg8Lz+/YTssIJLtMz8FjS4MZ+HDKZoSiKUOCXEHYVIC3uYlOdgAKmOGc+EmJmX8zTJDhajWLwE7mFTi08=; 7:MNFNDfkUGpk3QUzMjSY2Ep0bDmKtmnbUz/hAkiSbH7aokNtt79RCD5+dd5gHzIGIAKW+36ZY5BQG8azDKIaXhFA0hb0MNpufvDNFDQhpnTb2Mo2kBkrJ78GLvoqAP9kAF1MVrUkBo3u95/EbPEQBeLy12K7GE0YTVAtOW4Plcp21Y/UoZFVLnekR8KZAA5dRwfhgXyZZhtXWSBw1Z5bQjRJxdii06RuSJcvOuEubOEMJSB/rppqsSFNndATr/k/j SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2017 12:49:56.6423 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3a035892-7d53-47a8-3eb4-08d53727b22f X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR03MB1768 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171129_045022_643829_F1AA0F9E X-CRM114-Status: GOOD ( 15.54 ) 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