From patchwork Thu Sep 28 18:04:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 9976681 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 6D25860375 for ; Thu, 28 Sep 2017 19:04:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CDBB29707 for ; Thu, 28 Sep 2017 19:04:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51E8529716; Thu, 28 Sep 2017 19:04:28 +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 BB8A329707 for ; Thu, 28 Sep 2017 19:04:27 +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=sjzkIyQFolvsvzdVcS7do0Du74wh868rqqSpUXfSqjc=; b=mOPyJJDUEBED1k cTb4hsElFiKJ+JDEqlY/EO+97Nei96kc7LN1UVnj+hPLtt00pR+AUx/srKEmaRj1vD3BIf4k8NeQx RZ0O9YBqmBU9gbwp8RvY1u7DYAUeAKbYjAJfUe1Ca9Tswy0O4ZBMU1P21dWcfBj/CcF5uargfVZvH 1B4neTGqrzZgm1C1a/X+9ehmohQO9dsJUU1n+JOfZ8fcXcHGn/dk9/TYPxMgLI8lmUlhHZcELuR4/ ruNTOC4gtxuBz0iIUxyaR5gDooDjfoTqzfUozR1Ey9lv2RZmqS7OUhZ801lobj3BagtPiLNNtj4aa +Xd9Rq9sJF+RWeXxnc3Q==; 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 1dxe6i-0000sX-Rf; Thu, 28 Sep 2017 19:04:24 +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 1dxds2-000222-Mn for linux-arm-kernel@bombadil.infradead.org; Thu, 28 Sep 2017 18:49:14 +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=VLqFPxaobgTLlmN/NkQz7mzhyE4Xt2UfvmrSt/c626Q=; b=Mv3kWIssUU7umqiWBTv5rqdgy Wmr4ZKL0K1RYpD5LKr7EZCpRJVFGtzfuGjTBqo1eID+fwZm+ncadjLUV6rklExhTG+owBW10VvN0j 6WUBMxjQfyEtoSKvUCM61SM0O6UDvDDB4OftzAO1r32esdcR4zpDyMRO+Fz6bN71FHUdZFQTx3uRk SNVrxdFD/kPAvgDsRWkqejuW8m+0MnL6XsAwVUftZ/X7KaUsopDo+ijfhkzcOAI1S/T7XTglTPgD/ ZQorEewjRaGTOazqS2RhhAIl+nox9X813zhI0/hinFJTDD/vewhSqTI/cLd/5yaBVbG4luPA4McG2 iT1Zad5eQ==; Received: from mail-eopbgr40041.outbound.protection.outlook.com ([40.107.4.41] helo=EUR03-DB5-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dxdBt-00041h-FZ for linux-arm-kernel@lists.infradead.org; Thu, 28 Sep 2017 18:05:42 +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=VLqFPxaobgTLlmN/NkQz7mzhyE4Xt2UfvmrSt/c626Q=; b=R/u1iKzzUGjhXNMZCddRApCUmlVpf4VDZo9guOWwKfB1y4yva5xOXveaZpJVae2Nud8+66PDfU0SR4Ftxdd4GI3A23vmJdhKaInoBI9qwMpSj+KrW39JQUKNoi9y8oBFF8yislvvmBBiPp8r81386NWTWJ2eTqbeZPSfmmoo1TM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Volodymyr_Babchuk@epam.com; Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.59) by DB6PR0301MB2135.eurprd03.prod.outlook.com (2603:10a6:4:46::17) 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:13 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Thu, 28 Sep 2017 21:05:10 +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 06/14] tee: optee: add page list manipulation functions Date: Thu, 28 Sep 2017 21:04:03 +0300 Message-Id: <1506621851-6929-7-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: AM5PR0601CA0046.eurprd06.prod.outlook.com (2603:10a6:203:68::32) To DB6PR0301MB2135.eurprd03.prod.outlook.com (2603:10a6:4:46::17) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 03658376-725d-45b6-29c3-08d5069b77da X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:DB6PR0301MB2135; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0301MB2135; 3:D5KO/1PHvlJjb+oNW7/JBRo8w5hMoIDwYY8ucuRKMWWB1PTjT2LCTKYQsxql2zvXQ+eLxH7ejPLZVzDvruXtoX619bHCeP9o12Aaujlq4KkVK0bRPkFdNQuMSMd8tNiypMAmX7YGblArNJaDyiQIQERxSw4NJBJhzSr3hU3bC4GKxwyDzr3P1JrveV8zOwskwNKONWUEOYlB+yEX9HGFUaP1Q/tlNjxiN7sgC1xMSkuhb9s6M5YxYXicWGcSRRE2; 25:0pVwRx/s+GU8QRNnR0rjm39CjPSvXd5VDu+hbfRUrDNKAvTmNWRaONcOiqnzQNQIsHVMUKSQI85wxcNYDMjW3Nx+O8clGxz4hx7CfkMrYOaec4z4UC/I053WWZkZOKtEuu5TRqoanbbNvKYkhV4k/wk/aLUkht+xoKkAGO3qdXiVzh/NUOjfvVJGFEcfhWhtk3+60vOl/FyAx9ndSYihUnF54mrB6pjyZz0t3R7pqmPBs9tmELmU5uU1bw5G5qqegneMBsv6HVtmyfDRSPZ27kPVN/R2FzUG1kQ6aNKWlupjDubPFcuAbOcJPPS9sXUIddwtW/o+ye4oO93pztfkYQ==; 31:Ii2AM6ddHZ1/vUoutZJcS8bwNfHHoU7U4B+CpaTvPqowPW95Rtq5gLAv98k4jyucC8zkKeaVSwSP29unKBngXPlT2c7v8Mhc3ENh/lH+n9CjozuYH2cG324s4gyAMk4No00TGJ/GUPaiI8oi2gzpewwIyW4ktsb2DF3J0EP95oW4pQF87tP5cH7baQ7Ci+xMfKJ1DHwfGtLOksJNnP4oZ08wn+A3Zfq6M24zsyOAUfk= X-MS-TrafficTypeDiagnostic: DB6PR0301MB2135: X-Microsoft-Exchange-Diagnostics: 1; DB6PR0301MB2135; 20:/O0mvdYT59fMlsXBTxzCTiAEIqNjycLANlYL9QmR5rW67glGrhZTyIIA40+iPlTY144oE0TkrugnCwWJeb3L80yqNjU8OXPCoBauqpmiBvn8b5fuXKaomeKftbTzCcsjin0b3372pxjx8cYiVSbfsZUAPWLIezr0Zm+HesLRmR/3UL6J3UoMktbfi22/oSXAg76mGIslbeACuBn2BYutcUpStDZUjOOrzXKhsgHvF3DfskeX17OWDjht/6e8Y9vzfJTAKGatTpFrQIdHzYfUJvlnUA095xqYKT3aw5rx1v08X2WINsKPQTv81o53O7477/mzVH1JJkgsHmzgOtNJQ2oEFSMcOa9vkV4x6ih47AL9OzUs7a8Of6iGhFpOHFM5W+v0uB7SsugFQHapPWhII40/yONxBCAH4gX+Sk9EpGMQhYbkI7e3wb4O1/jh9feXIyux+fUSYXHnw+QOIfLHSUG4yQrW4TsXZIYt3WgLkMEZyn/tCvTulfQOWwINjn9z; 4:iNce1/2vsNkd8nAKClcE0Z9zFjjuWou+RHo8mAAPbONNKq1YwphEfV71q+d4uB0LIloCLpB9RgIw3665L/G/0LlrpCca05I979XiYCWrrZ/iJiVWNLArlpmqWixtGZuoTx3sZa9O2dGUqOOukFheauQkwCbH3ldF/G3ZrIQbN3nkxlfFzjAgr/PwJf1FJRSZWSATxCXFNB8yiVmVS+f8kHlrnzezlcoVtxJd6W6xj9e1L8qKPdtV4ym2P3rz1xJb 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)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(3002001)(6041248)(20161123562025)(20161123560025)(20161123564025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DB6PR0301MB2135; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DB6PR0301MB2135; X-Forefront-PRVS: 0444EB1997 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(346002)(376002)(199003)(189002)(8936002)(97736004)(81166006)(81156014)(50466002)(5660300001)(5003940100001)(66066001)(8676002)(316002)(86362001)(50226002)(16586007)(42186006)(105586002)(106356001)(68736007)(122856001)(2906002)(80792005)(189998001)(33646002)(3846002)(6116002)(4326008)(50986999)(7736002)(36756003)(76176999)(101416001)(305945005)(53936002)(48376002)(39060400002)(72206003)(2950100002)(6666003)(6916009)(47776003)(478600001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0301MB2135; 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; DB6PR0301MB2135; 23:Pm99EWNcEC8BcEnYX7jt8qRC0TuCuX/LuUaokqH?= =?us-ascii?Q?gQRZOHyDB6Q2Caii3lAjIUHvLSZZTzBfaE3z7q1qRlJdLT2gJFzLHHGZAzy4?= =?us-ascii?Q?MeKmpKrOLWW6DIrindnW68MhnkGEO90xLMpt427UTdLTuaOpd/yxEGPPlSyz?= =?us-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Nc83TA+OLeLl2WJT7rJe?= =?us-ascii?Q?q8vayKruazRz0Zm3cyPdPNTRodIG4?= X-Microsoft-Exchange-Diagnostics: 1; DB6PR0301MB2135; 6:QxtkmWBfLu92TjUOYe6zZKLnB9JXupxe94lNxvKqLP2OvETYffwREc1msLzrzgUN4pMyy4mbWojzK8qqeEfXCEM6/ElKzTlCg4B6mLjp36co/W0LqCpMifDUzZ9bYZp6/+JkY/Y8AYI6NPAMsPt+k1RmVB4Eknc8SZi1nQZyyqSz9DCgioYuMQMnfKgwFdmndMGFfbgdPqD/CK/sA5eOMutWdPiN5iRJTt9K3m3KhOC5ABI7/Woooq3hGVEzyrZxK6N+6kGE6VKYvuLUPUIGzcp7iOjI3jAsgX+q6TANB1oCXUERN4c2vLkNjBZo8olTdML8rk19Miq8ms8fdj4x9g==; 5:VGMY5fSUfvXq12Atas+x9ubhqv4RrlsMWc4SjNDczIijGIHtDOuT3KQ8LM4HU26ZlK59Jdhcanfs3hJFTlH0RGdIyAP6RWPyYr83uN4AZHkh9pbaNGfmyHJpyg02XYN2F/gkZitNVhejXGfwNO4V6g==; 24:M1Sshzb8Sg6LPH7mu6rhBCTN+DsSkhfTKQkPnHlsy/KFPyNnx/px7aTKeL96OvXsKbLwUwRA42KZxhNFg5Pl/AfBDYvkTZzhaE8uOuBEvAY=; 7:jp+IbNWagwqaJ52suMZqgi8FeYktWeklzhg+Gvn1Mgk1dF8jQBeJuKMs8fhFQbKlCbiHf2VatGkwsxEsLtoE68w7+ulLe3nj22uoOx86RVOc8Cih32aOG/4gT+Mhc3NOfkUv6mEfFjsCcdXs805pTGBrX6ucZkUWUoUjcjAyHDZFrkeLvdvsDZ7CP7KqW7RA5NFIlXKgG8Z6A5zCxijmkddSfvuCqFjIU1rxpMOTW4k= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2017 18:05:13.9058 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0301MB2135 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 These functions will be used to pass information about shared buffers to OP-TEE. Signed-off-by: Volodymyr Babchuk --- drivers/tee/optee/call.c | 48 +++++++++++++++++++++++++++++++++++++++ drivers/tee/optee/optee_private.h | 4 ++++ 2 files changed, 52 insertions(+) diff --git a/drivers/tee/optee/call.c b/drivers/tee/optee/call.c index f7b7b40..f8e044d 100644 --- a/drivers/tee/optee/call.c +++ b/drivers/tee/optee/call.c @@ -11,6 +11,7 @@ * GNU General Public License for more details. * */ +#include #include #include #include @@ -442,3 +443,50 @@ void optee_disable_shm_cache(struct optee *optee) } optee_cq_wait_final(&optee->call_queue, &w); } + +/** + * optee_fill_pages_list() - write list of user pages to given shared + * buffer. + * + * @dst: page-aligned buffer where list of pages will be stored + * @pages: array of pages that represents shared buffer + * @num_pages: number of entries in @pages + * + * @dst should be big enough to hold list of user page addresses and + * links to the next pages of buffer + */ +void optee_fill_pages_list(u64 *dst, struct page **pages, size_t num_pages) +{ + size_t i; + + /* TODO: add support for RichOS page sizes that != 4096 */ + BUILD_BUG_ON(PAGE_SIZE != OPTEE_MSG_NONCONTIG_PAGE_SIZE); + for (i = 0; i < num_pages; i++, dst++) { + /* Check if we are going to roll over the page boundary */ + if (IS_ALIGNED((uintptr_t)(dst + 1), + OPTEE_MSG_NONCONTIG_PAGE_SIZE)) { + *dst = virt_to_phys(dst + 1); + dst++; + } + *dst = page_to_phys(pages[i]); + } +} + +static size_t get_pages_array_size(size_t num_entries) +{ + /* Number of user pages + number of pages to hold list of user pages */ + return sizeof(u64) * + (num_entries + (sizeof(u64) * num_entries) / + OPTEE_MSG_NONCONTIG_PAGE_SIZE); +} + +u64 *optee_allocate_pages_array(size_t num_entries) +{ + return alloc_pages_exact(get_pages_array_size(num_entries), GFP_KERNEL); +} + +void optee_free_pages_array(void *array, size_t num_entries) +{ + free_pages_exact(array, get_pages_array_size(num_entries)); +} + diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h index c374cd5..caa3c04 100644 --- a/drivers/tee/optee/optee_private.h +++ b/drivers/tee/optee/optee_private.h @@ -165,6 +165,10 @@ int optee_from_msg_param(struct tee_param *params, size_t num_params, int optee_to_msg_param(struct optee_msg_param *msg_params, size_t num_params, const struct tee_param *params); +u64 *optee_allocate_pages_array(size_t num_entries); +void optee_free_pages_array(void *array, size_t num_entries); +void optee_fill_pages_list(u64 *dst, struct page **pages, size_t num_pages); + /* * Small helpers */