From owner-svn-src-projects@freebsd.org Sun May 10 00:24:41 2020 Return-Path: Delivered-To: svn-src-projects@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 424002D3057 for ; Sun, 10 May 2020 00:24:41 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49KPvs11qcz4V9K; Sun, 10 May 2020 00:24:41 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1DCE424612; Sun, 10 May 2020 00:24:41 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 04A0OfEe065001; Sun, 10 May 2020 00:24:41 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 04A0Oe5D065000; Sun, 10 May 2020 00:24:41 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <202005100024.04A0Oe5D065000@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Sun, 10 May 2020 00:24:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r360860 - projects/nfs-over-tls/sys/kern X-SVN-Group: projects X-SVN-Commit-Author: rmacklem X-SVN-Commit-Paths: projects/nfs-over-tls/sys/kern X-SVN-Commit-Revision: 360860 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.32 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 May 2020 00:24:41 -0000 Author: rmacklem Date: Sun May 10 00:24:40 2020 New Revision: 360860 URL: https://svnweb.freebsd.org/changeset/base/360860 Log: Modify ktls_decrypt() slightly, so that a small iov is allocated on the stack. As such, it only needs to malloc larger ones. Since most NFS RPC messages only need an iov of size 1 or 2, it seemed to be overkill to malloc/free for those cases. This is not needed for correct behaviour and it will be up to jhb@ whether or not this patch gets applied to his KTLS RX patch. Modified: projects/nfs-over-tls/sys/kern/uipc_ktls.c Modified: projects/nfs-over-tls/sys/kern/uipc_ktls.c ============================================================================== --- projects/nfs-over-tls/sys/kern/uipc_ktls.c Sun May 10 00:17:39 2020 (r360859) +++ projects/nfs-over-tls/sys/kern/uipc_ktls.c Sun May 10 00:24:40 2020 (r360860) @@ -1665,6 +1665,7 @@ m_segments(struct mbuf *m, int skip) return (count); } +#define KTLS_SMALLIOVEC 2 static void ktls_decrypt(struct socket *so) { @@ -1672,7 +1673,7 @@ ktls_decrypt(struct socket *so) struct ktls_session *tls; struct sockbuf *sb; struct tls_record_layer *hdr; - struct iovec *iov; + struct iovec *iov, iv[KTLS_SMALLIOVEC]; struct tls_get_record tgr; struct mbuf *control, *data, *m; uint64_t seqno; @@ -1687,8 +1688,8 @@ ktls_decrypt(struct socket *so) tls = sb->sb_tls_info; MPASS(tls != NULL); - iov = NULL; - iov_cap = 0; + iov = iv; + iov_cap = KTLS_SMALLIOVEC; for (;;) { /* Is there enough queued for a TLS header? */ if (sb->sb_tlscc < tls->params.tls_hlen) @@ -1746,7 +1747,8 @@ ktls_decrypt(struct socket *so) */ iov_count = m_segments(data, tls->params.tls_hlen); if (iov_count > iov_cap) { - free(iov, M_KTLS); + if (iov_cap > KTLS_SMALLIOVEC) + free(iov, M_KTLS); iov = malloc(sizeof(*iov) * iov_count, M_KTLS, M_WAITOK); iov_cap = iov_count; @@ -1865,7 +1867,8 @@ ktls_decrypt(struct socket *so) sorwakeup_locked(so); deref: - free(iov, M_KTLS); + if (iov_cap > KTLS_SMALLIOVEC) + free(iov, M_KTLS); SOCKBUF_UNLOCK_ASSERT(sb); CURVNET_SET(so->so_vnet);