From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751819AbdI2AXT (ORCPT ); Thu, 28 Sep 2017 20:23:19 -0400 Received: from mail-co1nam03on0043.outbound.protection.outlook.com ([104.47.40.43]:60903 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751046AbdI2AXR (ORCPT ); Thu, 28 Sep 2017 20:23:17 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@cavium.com; Date: Fri, 29 Sep 2017 03:23:00 +0300 From: Yury Norov To: Volodymyr Babchuk Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, tee-dev@lists.linaro.org, Jens Wiklander , Volodymyr Babchuk Subject: Re: [PATCH v1 06/14] tee: optee: add page list manipulation functions Message-ID: <20170929002300.zxu4n47m5jdymdyt@yury-thinkpad> References: <1506621851-6929-1-git-send-email-volodymyr_babchuk@epam.com> <1506621851-6929-7-git-send-email-volodymyr_babchuk@epam.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1506621851-6929-7-git-send-email-volodymyr_babchuk@epam.com> User-Agent: NeoMutt/20170113 (1.7.2) X-Originating-IP: [176.59.116.150] X-ClientProxiedBy: VI1PR08CA0126.eurprd08.prod.outlook.com (2603:10a6:800:d4::28) To CY4PR0701MB3825.namprd07.prod.outlook.com (2603:10b6:910:94::31) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5912af81-11d3-456a-5da2-08d506d04688 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075);SRVR:CY4PR0701MB3825; X-Microsoft-Exchange-Diagnostics: 1;CY4PR0701MB3825;3:l+3BKvNMtM9rMbLU8iV+nCKF9WC5+cwP0Wz16Xhm+slY8Bw930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n5lfMstg8jExTcmaWyVNoNKcNlBb8rRbueA1LPAMsQ4PyzvhkOkMOjbHckDlIBx6AfaI/lwvBb33lbXOwLmNPqvSKJUtE/qEY5Vg68gMvPh9GhfeV6CfIr+d3zz8XuncWko37ndUH7kWGdk3VC/8j4IApvCc8juOO7RGUQ73cPW9Xrqf6iqRKxQF8mjssobg1SBp/RA70VXXVm+ORyBKAnO89//yfWNYTQEtc8LYFu82HY5jEB27yHWfQlk9NhqXnelake+ZzlJ/0w9BVDXPFazwB5Gnune417FCP3wjEyJ/ruTLI9PdoHLSBES2AEUHkaeTvzMnoBqJoCUjOQgym4U3Fj0SJeMcL54A/786CdVVE+Nbp9LJdDCLd/UcGZM3VzqgX1KY07a9xgqk4wK6O7yD7QfgA=;4:C1/7eH3+6gEhlGRuYGc0jOyCD4GvuXXwaHI5Z8RTFr1Yd0bd8Ow5gJ3N4JVUtCIJE3SPcGmWRYeUaUFSIm1e0Q1mNUTPQC+2ExcmtjplpjKkEyZHEOZK/J8576/aeWD4XcSxzE/bx8StHdRQ4CX+h9fHGEEZ98W4jlnYgvtEwmPwC1sZoTUHyOYDJ7+1Lhl+u4rgnkMqQvuN5axNrts21M4zEYve9axn5a7Ic/0gemmnhX2DtMziNrDtPcS9l57E 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)(3002001)(10201501046)(93006095)(6041248)(20161123558100)(20161123562025)(20161123555025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CY4PR0701MB3825;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CY4PR0701MB3825; X-Forefront-PRVS: 0445A82F82 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6069001)(6009001)(7916004)(376002)(346002)(51444003)(189002)(199003)(24454002)(9686003)(81156014)(101416001)(33646002)(316002)(305945005)(7736002)(76506005)(5660300001)(81166006)(105586002)(8936002)(8676002)(97736004)(106356001)(72206003)(54356999)(33716001)(2906002)(39060400002)(76176999)(6666003)(50986999)(23726003)(83506001)(3846002)(1076002)(53936002)(68736007)(478600001)(6246003)(6116002)(229853002)(6486002)(16526017)(2950100002)(6916009)(42882006)(58126008)(66066001)(54906003)(25786009)(50466002)(189998001)(47776003)(4326008)(16586007)(6496005);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR0701MB3825;H:localhost;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY4PR0701MB3825;23:+xnsoaeeQatue9Ph4CIjtjibIViJ7p93vXf+YMA?= =?us-ascii?Q?L8g89AM1XRJ5bgwiepWxSY7IaRSknCqVKaQDg1AlxIILF143FO5faoQHaNAo?= =?us-ascii?Q?3p0OVI3RjuRpg78s3SRI+uQ4UyNlsldnnWwc8cdoWaDZWe7dwKm9lMHPh1AJ?= =?us-ascii?Q?yaW0jpyp5mZwuayavVBfFSpjF/Xe2wMZJUiMWlcIxSONL5pNaFvBU5kRa7/x?= =?us-ascii?Q?PqVPBLfFekWXFoZmCN82VgjORH3sSGlI48F82AKthPJw6HKzJ9FMXwNo6nXu?= =?us-ascii?Q?SV6T2jr17sePYAVFg4od01fjyweGlMIb2Qp153vT+soKdPWSI6Dd1fjL+cuJ?= =?us-ascii?Q?Az+rNQufj4xM7gtdmO82nRdSfP/jzbh8DOEkfRuBsbGjzMX9Iky1ewfVueDV?= =?us-ascii?Q?512zO+I8I4n3YwgGmtoCDH2xHytqVz0k3u9Gj6TnFdVnPhDfdabI/VvXoBEf?= =?us-ascii?Q?PVjHEu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 1;CY4PR0701MB3825;6:uqkje3JybMtCgU8uHMSgZNr8HXY9aWcs2i+eJ64mI/aybqRObqKFBolRCCravtLp5dpIgKX5BiEO9CrHn8QYSlAYN7hQpkrfuX9UDljIpYG5MRc36sqjdw4zyFQZqabw1USp3k9qRrsyqidMuRMP9Ft/+84etEyer4Yd28613MceRukrlR+ru+dgmTQLq4vraoHqhNPRFkQwTYl1yV8lHmLaGcu7SHJx3QeVWHa9gb4nNIf/vTqlL2Wj2phmmqjWooMhC8Pa6DLKZ5TphVLWLIQbQoaqsZXkhTtRNWZBFEIT6YufdtfeX4n6S5RoQoxBq3iVJ/uqgwTI1Pw4JOswOg==;5:V+EwmahLKUvBrdQu1IHJUFgq+rgHlqMMzYrPEteDFQVUI9DfeM1NFFhg0FvvE15xTVf2nVPlwUSpM4Mx9Qky/d+RVci2vHYOhzt+41cygqeDxhEMv2MFGRUGtJv6KJuxF+ncsNzIMyegJfbWowakPA==;24:FKTtpmW8I0mZNbDBTBb/xfKXqOIl25PqkSUkjirvE2DNVb6aKlW/Xyg5rE/Df7BPk05gHFzGk4ep91vMQr/86Vr2Bzq6hkOLmat7sFME3sQ=;7:+0zfs3IyxPyJsvDsMFDda8UzH3jdzgm5YLrwDNyVoOBEebU4UXjhga6Byzf6Pu2uF5r44X7gdcY+F1aJCPPyXCyM3lLQaKsx0mJDcaVoE33/iQQ/Z0LTWv6Mpk/5KuvC/PEtj7QTHTYawgSqY+++7H0TnNK1iZf8BcFdBRmwrpJbEVMoNSanwjSubKTqCH6kHGBsfmJDWxcEpfrdou4ReUeI0Mso6GJ7GMffAKV8HdM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2017 00:23:13.8161 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR0701MB3825 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 28, 2017 at 09:04:03PM +0300, Volodymyr Babchuk wrote: > 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 I'm not much familiar with the subsystem you work on, but I don't understand why the type of dst is u64*. If it's just a buffer, it should be void *. Also, if we assuming running it on arm were pointers are 32-bit, the result of page_to_phys() will be u32, and you will waste half of your u64 array for storing zeroes; this line: *dst = page_to_phys(pages[i]); > + * @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); RichOS stands for Linux? Why I am still not a rich OS developer? :) This is the first occurrence of the term in kernel sources, please explain it. Also, I think that it would be more logical to add the dependency on page size to Kconfig, not here, and move the comment there, so user will be simply unable to build the whole module. > + 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++; > + } Is my understanding correct that @dst is not a simple array of buffer page addresses? Instead, it has a complex structure: First 511 records store buffer page entries, and last one points to the next page of dst. Is it somehow documented? Also, did you consider to create a header structure for the buffer page, like memory allocators do? You can place there number of entries, pointer to the next page, maybe some flags. I think it will be more transparent, especially if we consider communication protocol between independent software products. > + *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 > */ > -- > 2.7.4