Received: by 10.223.164.202 with SMTP id h10csp4691863wrb; Wed, 29 Nov 2017 10:14:55 -0800 (PST) X-Google-Smtp-Source: AGs4zMYrLysEoe59bWjYYebq+4JtKrcsiFacAVRb3oeZNQGjnB7A0XvUdMUnIJmQJfC2OMTSMFlP X-Received: by 10.84.128.98 with SMTP id 89mr3763199pla.40.1511979295369; Wed, 29 Nov 2017 10:14:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511979295; cv=none; d=google.com; s=arc-20160816; b=d0SxhVwMffN8zpnFT74afd8iOG6052r+PRCdj5vqSur3ZQsd+zpZBjWG9Wk6lookkR KPh09ILykx1iU/efvfW+oQY8JvymI7vzRPVfpEq8Dwc2wrpyg20Gt4QnA9EL0F0QMuuT lTEWfIJaXYJxjxLtVKjO8cxgjWDoCISZ4GcktQCYSZO99hRQPflFpzBVB87peAQldZO8 cbSwKpRBqoirOTo39G5BHlNL3YdOFn/nZEZVKSxf5NstSjU9nn7r9WAtLJvZYRFungen QrTeBgyfJRG9OSjXoEr8fW227QrfMLGrqKq9XzqcPzPCe0CvHdvmmCxIf+zZnVwFGQLs 8Pqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:arc-authentication-results; bh=/SuM8eTyFNj6YnFUWGW4p1gc4Z2B6+Bzt5cPs0kHKxg=; b=WMEmKXd+4SowT7ktC6tiwtY7m9vF4FhQWHZalEyeIZm4YsK6zFPNgxC/x1fVzcwVFB hWShFTZ3GTYKxdSSq+Kg+fgdH0sptCcyxQ5SZjRh9lkCsU6WuHpRvvMiKvi42dUzGBGY j2Tvq12H4MdUjO13cHBdiwGBzKxlfuUL34bc1mUeQpUjSv0o6x6oNzrnrPjBGXVmjs9J 6Qw77nHiQvGfDaSk6ho9ykItzvcAzOZoEPljHcuiqNyL5xuoZuYX0vz/bdyVOL7+ERez 9l1VSlGTpiql+xTiQHQUsFs4CG0zqGNIDO6k87lP49c9gp5MwlKe0EZeEi9OWkO/CmYo +pbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@epam.com header.s=selector1 header.b=CfqLIWtS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l80si1741972pfb.76.2017.11.29.10.14.45; Wed, 29 Nov 2017 10:14:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@epam.com header.s=selector1 header.b=CfqLIWtS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932616AbdK2Mtp (ORCPT + 70 others); Wed, 29 Nov 2017 07:49:45 -0500 Received: from mail-db5eur01on0047.outbound.protection.outlook.com ([104.47.2.47]:49632 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754874AbdK2Mtk (ORCPT ); Wed, 29 Nov 2017 07:49:40 -0500 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=/SuM8eTyFNj6YnFUWGW4p1gc4Z2B6+Bzt5cPs0kHKxg=; b=CfqLIWtSvRxZVInmzxUmEUMr5qcWjkUaPoL6iLwnW5CQTrVWVrlHwem71ArvmcdE/907u87hYNfNdQPYNb9bxMZh4uhydf5+m4RG1/japCD2yVOWo2QgohoOx+CqcDNdyl02Tp/CswzEFT3pOOrbg1cPweUtwLQN9nFvUoC6N8Y= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Volodymyr_Babchuk@epam.com; Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.56) by VI1PR03MB1773.eurprd03.prod.outlook.com (2a01:111:e400:7bdd::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.282.5; Wed, 29 Nov 2017 12:49:37 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Wed, 29 Nov 2017 14:49:33 +0200 From: Volodymyr Babchuk To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, tee-dev@lists.linaro.org, Jens Wiklander Cc: Volodymyr Babchuk , volodymyr_babchuk@epam.com Subject: [RESEND PATCH v2 08/14] tee: optee: add registered shared parameters handling Date: Wed, 29 Nov 2017 14:48:32 +0200 Message-Id: <1511959718-5421-9-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 Content-Type: text/plain X-Originating-IP: [85.223.209.56] X-ClientProxiedBy: VI1P18901CA0011.EURP189.PROD.OUTLOOK.COM (2603:10a6:801::21) To VI1PR03MB1773.eurprd03.prod.outlook.com (2a01:111:e400:7bdd::7) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 904ce224-a000-4b0b-13d5-08d53727a652 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(7168020)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603270);SRVR:VI1PR03MB1773; X-Microsoft-Exchange-Diagnostics: 1;VI1PR03MB1773;3:RRO9G8/cMJ1UaNvKcxGRE07QqPLLJQzJWuf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dYlYWfgt2H8b7JzMFvw5RScoRtATx1DOK7F6IUxmaQ6kHvI37pCAF2A0DG9/xsqXOwbr5hrFcHeyy6sihypVFGoMmlYiy3jrE2mhs8cRpL9l8qoPQRHkOOXlbWTXJvnHmQlF1Fc0MFA+CdnPe4ud/QZ0jfqxEiQKxYTsCNcx3K/A85/CNL2xx///J+/zD4qfhMXLvoMNi/6szwVwsJQu1ruj/STzeUxQCB0OaUr+kl4eJjd8+T8aCXPHFObsqYjRFUbH0R6z2RhmuxX+r4QuBzabojY+eNCaLGUBvSZ+t2B0AjnwBi3S+9GjtwuNKkvM;4:wFvpuks5Cen+AhotRu1XYl3p3ISVbFh0CAcAp1X4yCvIeLiPKGbdHyMYSl9suWLPkmneEgrHMp3m1BcSdgcyXy40odIHeTgat1oCLoKH2mVFNwXSYgiiAQk2eIXBrRBjG7b45IVdiyT/Y1iJ7EE26DcspoSYCU0MQ3WfRIdQkWvNg7zKX4bR/SAsFVit0Oq7cakLdXGJQ8IPeAnk3UdjPbrg0Uk9opqTq8vgawSjwF48HFrGZx+w42rV20DDZXCOl3GfL03/HzHcUGlm9RKDzB1Cfu3bFLENP5h4jtBWwreg5dluzH+dxtZyLOxHOZB7 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(278428928389397); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231022)(3002001)(10201501046)(6041248)(20161123564025)(20161123562025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123558100)(6072148)(201708071742011);SRVR:VI1PR03MB1773;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:VI1PR03MB1773; X-Forefront-PRVS: 05066DEDBB X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6009001)(376002)(346002)(366004)(189002)(199003)(42186006)(53936002)(316002)(4326008)(107886003)(189998001)(16586007)(105586002)(50226002)(6116002)(33646002)(3846002)(106356001)(48376002)(50466002)(76176999)(50986999)(101416001)(86362001)(5660300001)(39060400002)(36756003)(8936002)(2950100002)(47776003)(6916009)(66066001)(72206003)(55236003)(81156014)(478600001)(81166006)(97736004)(80792005)(68736007)(2906002)(305945005)(51416003)(122856001)(7736002)(8676002)(52116002)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR03MB1773;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;VI1PR03MB1773;23:Tj655zMXdZWdsxIBpHxJX4k6JSRKg1ftk3mF2KwQW?= =?us-ascii?Q?3S7csDH9Wy7tAXFx8GFqqvHVfMppb0ir0kSSSmbbDIrlgHkCDkibdb4sz9Bv?= =?us-ascii?Q?hnC0SFsWTthvULZUDoWp0Cl0jtMQvZw/3Em4R7yDUL+F1/ZgMcdfGROzqYW/?= =?us-ascii?Q?DtpYb+v9F/zdZCVEdiNPpqnkjbR0Df94TYuapkPuhAjS2iqvXhUvN3omM6sy?= =?us-ascii?Q?tZKXec7Ov0GDA/zbfvopSh1lRrk+EIHLSrCLoF3Hkj1kOVrP0ttex/X8o4PL?= =?us-ascii?Q?dHLPkqR57vOGWE/6IWtIQvVzFuXkKMa0iwxuKuhmJ2w83jbiPrXjrm5F8kXW?= =?us-ascii?Q?+W3IR9rlbtmKlaKICHPmfgviH7Vp31TME4dOWqTP8d6O6qFEob4LN2Ccv+aJ?= =?us-ascii?Q?VoRQsWcm+35TmWTipPsg7wPNVFboZfJLAQ+lW0tV7u0kEioSv6saN6C4IA+r?= =?us-ascii?Q?gZ8++9/TZgXr5Ljs8Z+iHouDrmHxBJ1rMAR+x/epH2RoYLVZyO3Pkx2WRDEW?= =?us-ascii?Q?USMatPusU2HvE1z7F/U+wVC/0Y/ujxpQQvNVtUAHXWWh926ncnT/TelEPlre?= =?us-ascii?Q?1/cT5/kffs6Phm9puLh7ln95BzLBB8RujOETv2yDFhgcSPxmNgIlWhTcXaxi?= =?us-ascii?Q?ppp4BBQLZmVh0o4hOOGJiB8wXlgRA4ZEs29z/KAPANsXujGxflb+5RxObee9?= =?us-ascii?Q?g5UUa7kzNz7jqPposwWhHymQ1HzefZNbtI+1Li0HZStVbnltZVVvHfp0/1hT?= =?us-ascii?Q?taDibnCj6ZscQPjSR2nHEykExo5xEw3sjwaNrn/ofQ8LvE//IWfwR6EJjUHq?= =?us-ascii?Q?EOJA3mIbWlmgNtxRwPbVtA+M5BLZLj7Xf7p4i5XYHTsfUD6XfZzA+IpSBzwe?= =?us-ascii?Q?3vBD0FLT8v5aSh9VJ7sufBeI+fRctkWJYxy06K9NGFiZA8Lt2OhZF2DVpT89?= =?us-ascii?Q?qv+CJajNsLGiJH2LOlzguXOVdREa+x/hesDgdDV186JXFgbNEmjaoB6k3+/j?= =?us-ascii?Q?7OiFANf+R8YL9HGHfd44n13xAMLO2yJkI1+aruqirep887R2M13SFnx0j92D?= =?us-ascii?Q?jPvNj+fiKrCdMH2ZrH6W9pEYmFt/writqt65dCClPwsyGxtL28CaVjXhZJKc?= =?us-ascii?Q?f0eBQnmZgA2wipvaicqHQfoYJcuReyR?= X-Microsoft-Exchange-Diagnostics: 1;VI1PR03MB1773;6:gcVMgfGCtc8I2hL+8pRXbzMIkA4V4wKUNgT0rPX0PbqE93Ag2m+SupzDubVt287SjnJtYNU3tp849cF62VtS1Zf7rWMUxUtj1XZAKNod8y/bNiOWg8yR9IQ84cnyWtYMLTb9fLzYwgAPhZ8aTO+4orVrkNJfIrJZ2hSfVsK8DA11SEXOAbl4lJh+4PSPQgzMtxL/g1ne698VmNJk8Yl8gs9gjYPyFh6EpqSPzwswSJSyYz3WqAs8caGBR2TB6Uv5kjR7YPKzWygEodgDmwiSWaexKx5z9zwyvf6JoWTMzS8UrqIT4JbQA7Ssm4Ahk6YQbdckcfj8EW9vU/m0NfBD+5tUizFMddXGsGwD9OxfDyU=;5:9bCJg3XoOltb9+Of9HQL0R4YVq0u7hvfS6+NGzrUslIYcwrnQu+auuoARP3EoJUN9m4XK1sZiHQ5FYpuQIrHQygKLh9OuUAER93nrvRr99CA0TcPIId3meyZ2lNElRsC5z+bHYrNj2ipmcSF1aBwFv7txXnMyhVMxV1ia8SlwhA=;24:g7gJNSANtYULl+7YoCU22rW3esY9Pxj3JhTpBpCXcU8quQVE+iTJy6sUloIMIkUKJNozuVwwVlpY+rxgTz0uG1oiiURSztmSfH6Lo+ogmN8=;7:zZnZtmRCdMPU2G+qCqoweXJlZCIs68TchxPn/jIy+fUh44tuZ0qxV2oqshP+iPWSbJrjZeV2pe+yE0Jux0LCIj4qC+JitWM8zcseceghYKNq0Y4qkt/LbCxnF+MyekHsIqD673/1S48buomBabkV13PVe1RsGZ+inR4jGnD5d8oC28H6pCz+u/UUV69Ab1MTsm9s2fABF3+lc+8OH25yMePcidNRV98ked2ydN/Jmnigq9OxOltCLgeFqvkYfl5J SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2017 12:49:37.2692 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 904ce224-a000-4b0b-13d5-08d53727a652 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR03MB1773 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Volodymyr Babchuk Now, when client applications can register own shared buffers in OP-TEE, we need to extend ABI for parameter passing to/from OP-TEE. So, if OP-TEE core detects that parameter belongs to registered shared memory, it will use corresponding parameter attribute. Signed-off-by: Volodymyr Babchuk --- drivers/tee/optee/core.c | 78 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 15 deletions(-) diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index 4d448bf..3729ebb 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -97,6 +97,25 @@ int optee_from_msg_param(struct tee_param *params, size_t num_params, return rc; } break; + case OPTEE_MSG_ATTR_TYPE_RMEM_INPUT: + case OPTEE_MSG_ATTR_TYPE_RMEM_OUTPUT: + case OPTEE_MSG_ATTR_TYPE_RMEM_INOUT: + p->attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT + + attr - OPTEE_MSG_ATTR_TYPE_RMEM_INPUT; + p->u.memref.size = mp->u.rmem.size; + shm = (struct tee_shm *)(unsigned long) + mp->u.rmem.shm_ref; + + if (!shm) { + p->u.memref.shm_offs = 0; + p->u.memref.shm = NULL; + break; + } + p->u.memref.shm_offs = mp->u.rmem.offs; + p->u.memref.shm = shm; + + break; + default: return -EINVAL; } @@ -104,6 +123,46 @@ int optee_from_msg_param(struct tee_param *params, size_t num_params, return 0; } +static int to_msg_param_tmp_mem(struct optee_msg_param *mp, + const struct tee_param *p) +{ + int rc; + phys_addr_t pa; + + mp->attr = OPTEE_MSG_ATTR_TYPE_TMEM_INPUT + p->attr - + TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT; + + mp->u.tmem.shm_ref = (unsigned long)p->u.memref.shm; + mp->u.tmem.size = p->u.memref.size; + + if (!p->u.memref.shm) { + mp->u.tmem.buf_ptr = 0; + return 0; + } + + rc = tee_shm_get_pa(p->u.memref.shm, p->u.memref.shm_offs, &pa); + if (rc) + return rc; + + mp->u.tmem.buf_ptr = pa; + mp->attr |= OPTEE_MSG_ATTR_CACHE_PREDEFINED << + OPTEE_MSG_ATTR_CACHE_SHIFT; + + return 0; +} + +static int to_msg_param_reg_mem(struct optee_msg_param *mp, + const struct tee_param *p) +{ + mp->attr = OPTEE_MSG_ATTR_TYPE_RMEM_INPUT + p->attr - + TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT; + + mp->u.rmem.shm_ref = (unsigned long)p->u.memref.shm; + mp->u.rmem.size = p->u.memref.size; + mp->u.rmem.offs = p->u.memref.shm_offs; + return 0; +} + /** * optee_to_msg_param() - convert from struct tee_params to OPTEE_MSG parameters * @msg_params: OPTEE_MSG parameters @@ -116,7 +175,6 @@ int optee_to_msg_param(struct optee_msg_param *msg_params, size_t num_params, { int rc; size_t n; - phys_addr_t pa; for (n = 0; n < num_params; n++) { const struct tee_param *p = params + n; @@ -139,22 +197,12 @@ int optee_to_msg_param(struct optee_msg_param *msg_params, size_t num_params, case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT: case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT: case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT: - mp->attr = OPTEE_MSG_ATTR_TYPE_TMEM_INPUT + - p->attr - - TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT; - mp->u.tmem.shm_ref = (unsigned long)p->u.memref.shm; - mp->u.tmem.size = p->u.memref.size; - if (!p->u.memref.shm) { - mp->u.tmem.buf_ptr = 0; - break; - } - rc = tee_shm_get_pa(p->u.memref.shm, - p->u.memref.shm_offs, &pa); + if (tee_shm_is_registered(p->u.memref.shm)) + rc = to_msg_param_reg_mem(mp, p); + else + rc = to_msg_param_tmp_mem(mp, p); if (rc) return rc; - mp->u.tmem.buf_ptr = pa; - mp->attr |= OPTEE_MSG_ATTR_CACHE_PREDEFINED << - OPTEE_MSG_ATTR_CACHE_SHIFT; break; default: return -EINVAL; -- 2.7.4 From 1581172205186818883@xxx Fri Oct 13 19:35:21 +0000 2017 X-GM-THRID: 1579807677666738661 X-Gmail-Labels: Inbox,Category Forums