From patchwork Thu Mar 8 16:50:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Watson X-Patchwork-Id: 10268423 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 07242602C8 for ; Thu, 8 Mar 2018 16:51:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E74F020748 for ; Thu, 8 Mar 2018 16:51:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D888A2624C; Thu, 8 Mar 2018 16:51:42 +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 2FEE220748 for ; Thu, 8 Mar 2018 16:51:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752158AbeCHQvj (ORCPT ); Thu, 8 Mar 2018 11:51:39 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:34402 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752094AbeCHQvi (ORCPT ); Thu, 8 Mar 2018 11:51:38 -0500 Received: from pps.filterd (m0044008.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w28GopEx023350; Thu, 8 Mar 2018 08:51:03 -0800 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=lh2G6f4MBBM8tcqyhXrnY2HtXvmtTeMoS2jMHEZLomo=; b=dCeAemfWpPgEr6hyKmaePfrOfqbN0XFzSFdRiMW6XCh2v0XKVb3JSM7eu0QQHz94NgQ9 N9XI5xKhAzXN8PetMnN9Po01drjZwlprb8sbzW/qW/yJs2ozUjOAVNGrkIKg15DNTgyd mfG9bqbl1nZJUw2+7nLGMR1q1OTDiSN9lgI= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2gk474ry11-4 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 08 Mar 2018 08:51:03 -0800 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.16) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 8 Mar 2018 08:50:20 -0800 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=lh2G6f4MBBM8tcqyhXrnY2HtXvmtTeMoS2jMHEZLomo=; b=d//key0pz393WxQPF4VRg9pcsbEis69Nt2ccraqa5gzC8AxWxcA96Tf454xNqjfOePVjehEHeRrJgLBcd9pjZZ815pDwLQcDP690uVMbu/nQCxgrBFW84NKe+Ff81lCIYCXlom6CiKCNwRVrW4m3VBreRLCLggyKXBqfzTY6rcw= Received: from localhost (2620:10d:c090:180::1:bce7) by BN6PR15MB1123.namprd15.prod.outlook.com (10.172.205.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.548.13; Thu, 8 Mar 2018 16:50:16 +0000 Date: Thu, 8 Mar 2018 08:50:13 -0800 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 RFC 1/5] tls: Generalize zerocopy_from_iter Message-ID: <20180308165013.GA19496@davejwatson-mba> 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:180::1:bce7] X-ClientProxiedBy: DM5PR20CA0021.namprd20.prod.outlook.com (10.173.136.159) To BN6PR15MB1123.namprd15.prod.outlook.com (10.172.205.13) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b2539505-2c9d-498d-3f78-08d58514abb7 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:BN6PR15MB1123; X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1123; 3:i7uxv/gmwZvMs4AvzOU9uDZyoCttbBNnvxpRtGpMwc2uticZrWlFb4Sxx8YrurudYMSjZl7sPS/ogHQi+sgUKYXIHwYjcV222WLO4dXvMfVre0OqZZDea2jIVpR3SMvfOOd6oTv46Xwf7DspswvTvEQVdIz27XbD0SvIMn963lHFFYtKYWQAOhD+hVor/z3tpqZ/PuFOKAgwLxqTuyg4B4Py4I3rTTVY4vr9Ak8OiPHFkOqvET+4JHS2FTWw+0OQ; 25:9MRnN9xDicmizyLLEhPNvQQdN2RsWO0OPk+3BSHY93/zkfLZ0CC+tos7/Lex/mWVRSdlN/6Hx8PQqBMFKsE1yAr7g3HblYGkmEU9eRCe+6WmCeuzJDlCdWyfhU4FgRQ3Y5OrP5ZAmlL9c0YPfJ667+yac+2Kvtdtsjd+K9W58jbhey31OoNIV+yWXHJeY8b9Uk/4xJVJGu2X8zoHXHGvDIlqJy6k+RG0NgllxpUDlPUXwBDxOEgeCKbhdKXGYxqmRZ+xM9Nq9NWj/u9JhYf8H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0f3W+71CceUU6QEgogrNMSTk83MwLFR3TN/fsDCkJFKjuKidgqlVpz+5rdwzRyfNRUhFx2hLyI64T54cNkVVZbahv4aLxP8mevdw6TqW8WOUhRWm1nD4zw9EcyCBJPiUBe4O0ZQSIMVXmNfx6gWEztK+NxBgkGf+IriTAVfPrCnuxmd/rSdfbui8= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484)(266576461109395); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040501)(2401047)(8121501046)(5005006)(3231220)(11241501184)(944501244)(52105095)(3002001)(10201501046)(93006095)(93001095)(6041288)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123562045)(6072148)(201708071742011); SRVR:BN6PR15MB1123; BCL:0; PCL:0; RULEID:; SRVR:BN6PR15MB1123; X-Forefront-PRVS: 060503E79B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(7916004)(39860400002)(346002)(396003)(366004)(39380400002)(376002)(199004)(189003)(76506005)(6496006)(52396003)(5660300001)(52116002)(54906003)(8676002)(110136005)(81156014)(81166006)(186003)(16526019)(39060400002)(9686003)(53936002)(25786009)(105586002)(33716001)(50466002)(2906002)(97736004)(8656006)(4326008)(305945005)(7416002)(16586007)(386003)(47776003)(59450400001)(46003)(33896004)(478600001)(86362001)(23726003)(7736002)(316002)(8936002)(33656002)(76176011)(106356001)(1076002)(2950100002)(6666003)(68736007)(6486002)(6116002)(58126008)(18370500001)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:BN6PR15MB1123; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; BN6PR15MB1123; 23:umWhiyZ6n0GZeSO/m6R+7GX7LfXMBltf366jXQeLP?= =?us-ascii?Q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szH2x7isECGPms1CkbpqrqpT?= =?us-ascii?Q?+hw0TMYKWdOTCthx/4Kf72A+B/lkWYNg7Ksu26tgIjwuayc8Jj+NA01ZFS6v?= =?us-ascii?Q?EcqcAd44OE9es1x2eezswxmtROGPWoSTi+kf9numeTjA0wwZXCtJ8/OMDCIZ?= =?us-ascii?Q?SXvPwoLRojYc0dmqSAVmkQtyhYkuWvogaAHokEt/qb+yAn0nS0z35j09XxBr?= =?us-ascii?Q?267Y0tol94CP0jnslkTysZxxMUeyZjcYOwxmu//ENLrQNOx1lh+SWKFTYgrR?= =?us-ascii?Q?7udcJ/nZtb7V5tjA2d2gII7YoY9amKE3P5egvBumiGIRhsFFseXI6f96QCHl?= =?us-ascii?Q?1tQnX+wWTW1BcKH6H33vGuud/ul7GHL/BGaWhjWxH1Uwkib5spK93qb8NAfq?= =?us-ascii?Q?444hQcGz+AvPp+S+b8DjI1lC3GMJIvGUdb4SvJ6dcsZ?= X-Microsoft-Antispam-Message-Info: vZJwHm3v+/QQiaoPJYmN3+M+nzvpwCRGtLC10h3yxDytmbJEjT6MQCC6g7psqI+fYNnU1p/UidgKRjEczNMlnciTcvbGMIJ+ld9nJe/7h+8RQ9f6WMbMaLb6fY3jZkV3XQXn8MccRErUlIdCn/T08kBfGH9pdD/ipXgaeLcfYW/RmH2G2XQAkE9cVZ0L1J7G X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1123; 6:8QQFeYpA4sD+DSv+6HogBn4lG/GM0tu/6+69afx7FL7etZa6CdtT6WcHXt61Ilh9nqdOQL+8b9uQksjUqOkDTGYK/CFOKg6A9opuCU5NHUj61q5qbIGX+aKFRnfOYv82+1QZKKJ+en9h03HARd2V5FppC8Cvpjg2aQt6ctAv/Pslt/CU8n3y9oszaBSzlYTagPN2kivis8/bdrPEp/xsrtMQSIsUAUQrXfvA/xvMdh/IWHSepJXQJOIOlgy+urVVKzMQ2UM68sw8czDeC3uucwSTh92rozaIjH4z+Hz+7fHOWYD9PZQUR+pAY2D5RTYZDfs2mkv5tCNMhJS11jm0aih+EStgtZMS9/5YYMmZB1w=; 5:wY6oNqtYP3Q6NLD+9PVXPO/3pkILGM3s+9YTWUdcGXq5giC1vpvhPxbHBHZAuqFoai7I5Mi9aAH4p1eDKVa3V6UcXySlDMEVXZzyQ10rO0P1RWkj1oR+gQbbS8Y+06f6OthriUJclpCbFHeXRSCqNqKtflfGF9CwtgdaDao8Akg=; 24:ioqwXj0crFsO8bld92maSvHMxgqtJ85/jK+/pOKpaxiB5uYg+mep47Prj8FM4wgXOZliWiJ6HpofSqDKsUXMRXA+vOHq4Wc+jLdJ3qGgk9Y=; 7:kTuPcq2e0Z0i5pelChg2FZrmNQIH9FuSU6Hyj8s/tKpLYk+q91UDvXSg6QJT4P1GDcebo3lTvUXLMoWGPpPD3OWrZjCiLxkXLpCvSKasNuxqx2HcPDQg2xvGNyWm2R46m1HYWGNSVK4WomW4Iv9GaeAMp8NF491Pn2HcjfoCPzfEXHYLLT9qeLJ8F5hfWv8UF6ITuA9fe+Sdz6kPOcvrWD0MhivjX1yio9E0SlBY9FxVKPgGBjOEYeBfqAl/7CMP SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1123; 20:xQkiZmcwVW04dbydMYHZAWy/vl/ynVvzcl6af3zou+67+aTeGI0mFmX7tzh05ITrfwV1BRzD9sRhNVe2RPSbw6p/DSxAVhbc9QdeConWLRNjL1MGElU603vxuFRdDcdz3L/rEKQKG9hhZN6mzf8Q56iLgiJJAUPtwy1kz1XX4nI= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2018 16:50:16.7515 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b2539505-2c9d-498d-3f78-08d58514abb7 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR15MB1123 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-08_10:, , 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 f26376e..d58f675 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -281,23 +281,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; @@ -317,10 +318,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; @@ -331,8 +333,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; } @@ -429,7 +432,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;