From patchwork Thu Mar 22 17:09:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Watson X-Patchwork-Id: 10301943 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 1D139600F6 for ; Thu, 22 Mar 2018 17:12:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8B482885F for ; Thu, 22 Mar 2018 17:12:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D73D928881; Thu, 22 Mar 2018 17:12:30 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D76232893D for ; Thu, 22 Mar 2018 17:11:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752016AbeCVRLO (ORCPT ); Thu, 22 Mar 2018 13:11:14 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:34906 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751798AbeCVRKl (ORCPT ); Thu, 22 Mar 2018 13:10:41 -0400 Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2MH2WAr017732; Thu, 22 Mar 2018 10:10:01 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=facebook; bh=vsTD7tr3mDPOpikY7weTS3ilU2k+p0TjB2RxnbMHqv0=; b=DFXwtXTQ3xHDW+1sLP97c1f3i+z9sGUgOjZ5dnD+TImNzDmn57UiyIfWz5RjJUV/uSgJ 0nuMhSQlk9EydDpYI0Q9GmhOLL+Zw1z+V05OPwrYQpOVc8MCxg3DgE6T2eqHo2/7FpIO DAnqzykwx6NSi15cPbWQmV2evMRxFoJxje8= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2gvfvu85wy-2 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 22 Mar 2018 10:10:01 -0700 Received: from NAM01-BY2-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.22) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 22 Mar 2018 10:09:58 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=vsTD7tr3mDPOpikY7weTS3ilU2k+p0TjB2RxnbMHqv0=; b=c+zprtEQx26xkOjibnL4+IibjD8bOOgYinAe2z40Sb6ZZhAyHEGY/SI1tFHEMx7y156+FrzsyTy9HxaL8Rg8Qsz54HIU7m/V28C6X7AYSMNu3MJgUQyzUvhat3/3vuLJtw4r+wIEqXcPrN2wUDF+RgnPTpU0sCG4tn0IiOy/s5I= Received: from localhost (2620:10d:c090:200::6:9ccb) by CY4PR15MB1128.namprd15.prod.outlook.com (2603:10b6:903:106::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.588.14; Thu, 22 Mar 2018 17:09:57 +0000 Date: Thu, 22 Mar 2018 10:09:53 -0700 From: Dave Watson To: "David S. Miller" , Tom Herbert , Alexei Starovoitov , , , , CC: Atul Gupta , Vakul Garg , Hannes Frederic Sowa , Steffen Klassert , John Fastabend , Daniel Borkmann Subject: [PATCH v2 net-next 1/6] tls: Generalize zerocopy_from_iter Message-ID: <20180322170953.GA67822@GeorgeHnsiPhone.dhcp.thefacebook.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.6.0 (2016-04-01) X-Originating-IP: [2620:10d:c090:200::6:9ccb] X-ClientProxiedBy: DM5PR15CA0040.namprd15.prod.outlook.com (2603:10b6:4:4b::26) To CY4PR15MB1128.namprd15.prod.outlook.com (2603:10b6:903:106::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 34d3f8ae-eaaa-4603-7d46-08d59017bd3a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:CY4PR15MB1128; X-Microsoft-Exchange-Diagnostics: 1; CY4PR15MB1128; 3:8f8XowT43iSQo4mdz4uvoI6CtX4JA7LUOWlrwxyL8jlyPPE7wyFtnHhlK3JbnlBmP9JQTLwV/6hon4uT+U+R5KvPNhOEQg6iV29+JdBtNuLgvNOdjco2yaIl0ZgfHx/bamk1Og+DSzfORDdmdkj4ud2UPs4nf3vel40sQFfettCZhCsFiEayFz7gM2obDz04k5zwZ4XHMg9ArjFNmvt8BH158h3bG29dIZ721IgW4AP5wGgZK+SKzyWR+cx8E3ZH; 25:56V9hh3RiNK0siovJYVf6bemLekcmhTNNw/SFdZzEDD7Y1xNUoVrtQbRC6ssE5ovMG0Jpx1sfHQPmvUaA55VMkTqd3L+YqB6p4GKm3I/9PuLJMSNeCR7En9oqf6u1VYF+oMlszP/YMKgDAwTWoq437iqE63yRuaqf2Keg40k4ZiIPTTDJXzHfehybftCgR1ANL0pcuSyi0KcN3IlWf6S5b2WNs8ovCcL+r5gO+YXKG7G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5qANoD/I3oVwq6xpUlFiNzsfirA+Im/ByIt/faMgUHtewfsJZfr29ozBzl7vFwnNHv58HLYCYzYI+NEQ/YC7d4npv4ORtlOU7SYV7ob3IpLvMmvoWUMqX6m+YPfoIkHa1fRLUjSjCCyU6m1PAe0qKIPHkzYMIZBA6wzLIK0Xew3/mdvl69IwF4m7RuE1rrvLtEg/dxEDHYmYmrYMICYNPnrUS4= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484)(266576461109395); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3231221)(11241501184)(944501327)(52105095)(93006095)(93001095)(3002001)(6041310)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:CY4PR15MB1128; BCL:0; PCL:0; RULEID:; SRVR:CY4PR15MB1128; X-Forefront-PRVS: 0619D53754 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(366004)(396003)(39380400002)(346002)(376002)(39860400002)(189003)(199004)(386003)(105586002)(6666003)(4326008)(33656002)(305945005)(58126008)(316002)(16586007)(59450400001)(110136005)(46003)(8936002)(54906003)(8676002)(7736002)(7416002)(81166006)(81156014)(186003)(6116002)(47776003)(478600001)(39060400002)(33896004)(23726003)(1076002)(97736004)(50466002)(16526019)(76506005)(106356001)(53936002)(25786009)(6496006)(68736007)(8656006)(9686003)(86362001)(6486002)(52396003)(2906002)(76176011)(5660300001)(52116002)(446003)(11346002)(18370500001); DIR:OUT; SFP:1102; SCL:1; SRVR:CY4PR15MB1128; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR15MB1128; 23:puDEn5Tm0YomF5O4dBMA6G7TG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/irtCkAlS7HXAuEI0uyA+apd2vn0lH8/93y411JQc?= =?us-ascii?Q?3ZneyeCcuhi6fpFXImPEP5qFUoX0qeYO8gmR5hIqjewIpmOmzH69EG/EXy+t?= =?us-ascii?Q?wofSEo6bzLLCwwrkjOxkSno6uUNUFfPQyePDPgdnH67b19v3O5k5hVLrC6H7?= =?us-ascii?Q?3RTDLKqsYcSVLLNwCIRIo5ubizQvAMkS6tEUxKAeCG025+X5+by+6kEM8K8F?= =?us-ascii?Q?PG7INPVTRkm7CA+0ILEKj/W4zpwbruVo50lRKOrhlvCHUWHuKN77443RzpVq?= =?us-ascii?Q?ofWMxkpdWNIRqUafwa22B9OoR3OjVn2nZq0CQf2wILIoJ3sgBSLOCDh7cRdJ?= =?us-ascii?Q?3ethl6nw/+zwdkNmcpKc0phXDOcsMooi4iKSWTPymDet/tTBU7//MATmb8MP?= =?us-ascii?B?UT09?= X-Microsoft-Antispam-Message-Info: vXIlRGXVHTKUWzN3bR6pdjCRoANzdU0ISwWpLWoyAO+nYRiZBSNXEBy+ifSkKwLIiNCdGMc2EyQM0vBdMRiD/b2tweKr+W9BvRmBcgMIXPRrF3fhDjkCX3g7Lx/SPer1aetgGRqEqIKC27QOsDRp1KUrVrrEknslzDu2eTsHzESYu455Qgd6GH9j7SAa42E5 X-Microsoft-Exchange-Diagnostics: 1; CY4PR15MB1128; 6:Sjh7jxuHB+/9NXs2muTJF7kgT6jZxhunbJTHGVZt0Y/apcnBm6rxuKao2vkwMfQjWrsr9Jsf8M7jyk3Iv81D5e5Mc4iK3FjJ5erXTBUKDmreAN3KNKeNIG4t0mDaUYvIwOpL9yiAdJVDEdLvi0bEFG7mPBWCt7aKGMUNjrltz48N4FVrHvwRq9kDuVvL/nTiNvHCPUb5QogTsX19/8gRw9jLAsFR/bkRvO9sXF6nqyC9/Ri4qztOodH6hYt5C5rnnvbFCz3IOh9qenfhNQvtiwILOhhrec4YcTV5tlp8Ibq/JVCoNRpn4xmNYfsio9+ql8sZFG44sRvlIcC2dRjiQDy+jaAvwJCjuKObDZvEBQE=; 5:Kyjaf4qNEaa7qCJlGIJMNiV/JJHu3ZZcmMlqE1KeeldVmE4UDxKNbldmy8njHTBalk9HUpTyUuXjCfZmj92mvSykpQavIo2E2N91dI7YKOEai8933WA84d4b8q7akP/UAZVaS1+i9Z4uv/1B7BVCc0WwswyBxZTXaieuxCouoFE=; 24:jyRlB/XVmt/iiY4nA3ibSenH2oJAiV4XAmvWmy7sfF1MPUhmPPhojv190r4d6UUeK3H+l+0L8fAPzgGEN7R0lFZOjRT/+odkE6t7IOQ4yog=; 7:vg1VbCzAB9gWXsTZspRiVSluhSIvEtOIkG/LjBbi2euhDSY7Bav9BKTk5RTYVytP521zbsdsdL7crV1pVkX00cCIF+Cuf4LF1aG0zDfWalkSF5IsM6LpxPIm6k/JqeI3XqtIE8pByJCQEqRPx7v/q71JZ+YRFymTMQmeayVYMS5KK604uXgSTV5K/5/hroiel2NxN5D7Q7qru56blMse8tr8Blr9d2VuYVvifaOscouz3EqxliLMMSXQLDZNiDSU SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR15MB1128; 20:qyCQg253Tzb0kt/xqevm67qXLGHzzkMBKxvSgApeqQgbqkXm9mo9PN2Sr0kfVINgRFZRbYCc88uohRYM4je2q7tZcW7Um6EubLYP0+4u0OyTdBUOfrXzWe/wXA/WDh3aRcfS5A0Xi6LNw50k/2+0ZxIel12dtiLtTtA0PBhSBH4= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2018 17:09:57.4136 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 34d3f8ae-eaaa-4603-7d46-08d59017bd3a X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR15MB1128 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-22_09:, , signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Refactor zerocopy_from_iter to take arguments for pages and size, such that it can be used for both tx and rx. RX will also support zerocopy direct to output iter, as long as the full message can be copied at once (a large enough userspace buffer was provided). Signed-off-by: Dave Watson --- net/tls/tls_sw.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index 057a558..ca1d20d 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -226,23 +226,24 @@ static int tls_sw_push_pending_record(struct sock *sk, int flags) } static int zerocopy_from_iter(struct sock *sk, struct iov_iter *from, - int length) + int length, int *pages_used, + unsigned int *size_used, + struct scatterlist *to, int to_max_pages, + bool charge) { - struct tls_context *tls_ctx = tls_get_ctx(sk); - struct tls_sw_context *ctx = tls_sw_ctx(tls_ctx); struct page *pages[MAX_SKB_FRAGS]; size_t offset; ssize_t copied, use; int i = 0; - unsigned int size = ctx->sg_plaintext_size; - int num_elem = ctx->sg_plaintext_num_elem; + unsigned int size = *size_used; + int num_elem = *pages_used; int rc = 0; int maxpages; while (length > 0) { i = 0; - maxpages = ARRAY_SIZE(ctx->sg_plaintext_data) - num_elem; + maxpages = to_max_pages - num_elem; if (maxpages == 0) { rc = -EFAULT; goto out; @@ -262,10 +263,11 @@ static int zerocopy_from_iter(struct sock *sk, struct iov_iter *from, while (copied) { use = min_t(int, copied, PAGE_SIZE - offset); - sg_set_page(&ctx->sg_plaintext_data[num_elem], + sg_set_page(&to[num_elem], pages[i], use, offset); - sg_unmark_end(&ctx->sg_plaintext_data[num_elem]); - sk_mem_charge(sk, use); + sg_unmark_end(&to[num_elem]); + if (charge) + sk_mem_charge(sk, use); offset = 0; copied -= use; @@ -276,8 +278,9 @@ static int zerocopy_from_iter(struct sock *sk, struct iov_iter *from, } out: - ctx->sg_plaintext_size = size; - ctx->sg_plaintext_num_elem = num_elem; + *size_used = size; + *pages_used = num_elem; + return rc; } @@ -374,7 +377,11 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) if (full_record || eor) { ret = zerocopy_from_iter(sk, &msg->msg_iter, - try_to_copy); + try_to_copy, &ctx->sg_plaintext_num_elem, + &ctx->sg_plaintext_size, + ctx->sg_plaintext_data, + ARRAY_SIZE(ctx->sg_plaintext_data), + true); if (ret) goto fallback_to_reg_send;