lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230329141354.516864-42-dhowells@redhat.com>
Date:   Wed, 29 Mar 2023 15:13:47 +0100
From:   David Howells <dhowells@...hat.com>
To:     Matthew Wilcox <willy@...radead.org>,
        "David S. Miller" <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>,
        Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>
Cc:     David Howells <dhowells@...hat.com>,
        Al Viro <viro@...iv.linux.org.uk>,
        Christoph Hellwig <hch@...radead.org>,
        Jens Axboe <axboe@...nel.dk>, Jeff Layton <jlayton@...nel.org>,
        Christian Brauner <brauner@...nel.org>,
        Chuck Lever III <chuck.lever@...cle.com>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        netdev@...r.kernel.org, linux-fsdevel@...r.kernel.org,
        linux-kernel@...r.kernel.org, linux-mm@...ck.org,
        Trond Myklebust <trond.myklebust@...merspace.com>,
        Anna Schumaker <anna@...nel.org>, linux-nfs@...r.kernel.org
Subject: [RFC PATCH v2 41/48] sunrpc: Rely on TCP sendmsg + MSG_SPLICE_PAGES to copy unspliceable data

Rather than copying data in svc_tcp_sendmsg() into page fragments, just
hand in ITER_KVEC iterators as part of the ITER_ITERLIST and rely on TCP to
copy them if the pages they're residing on are belong to the slab or have a
zero refcount.

Signed-off-by: David Howells <dhowells@...hat.com>
cc: Trond Myklebust <trond.myklebust@...merspace.com>
cc: Anna Schumaker <anna@...nel.org>
cc: Chuck Lever <chuck.lever@...cle.com>
cc: Jeff Layton <jlayton@...nel.org>
cc: "David S. Miller" <davem@...emloft.net>
cc: Eric Dumazet <edumazet@...gle.com>
cc: Jakub Kicinski <kuba@...nel.org>
cc: Paolo Abeni <pabeni@...hat.com>
cc: Jens Axboe <axboe@...nel.dk>
cc: Matthew Wilcox <willy@...radead.org>
cc: linux-nfs@...r.kernel.org
cc: netdev@...r.kernel.org
---
 net/sunrpc/svcsock.c | 44 ++++++++++++--------------------------------
 1 file changed, 12 insertions(+), 32 deletions(-)

diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index f1cc53aad6e0..c1421f6fe57a 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -1071,47 +1071,27 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
 static int svc_tcp_sendmsg(struct socket *sock, struct xdr_buf *xdr,
 			   rpc_fraghdr marker, unsigned int *sentp)
 {
-	const struct kvec *head = xdr->head;
-	const struct kvec *tail = xdr->tail;
-	struct iov_iter iters[3];
-	struct bio_vec head_bv, tail_bv;
-	struct msghdr msg = {
-		.msg_flags	= MSG_SPLICE_PAGES,
-	};
-	void *m, *t;
-	int ret, n = 2, size;
+	struct iov_iter iters[4];
+	struct kvec marker_kv;
+	struct msghdr msg = { .msg_flags = MSG_SPLICE_PAGES, };
+	int ret, n = 0, size;
 
 	*sentp = 0;
 	ret = xdr_alloc_bvec(xdr, GFP_KERNEL);
 	if (ret < 0)
 		return ret;
 
-	m = page_frag_alloc(NULL, sizeof(marker) + head->iov_len + tail->iov_len,
-			    GFP_KERNEL);
-	if (!m)
-		return -ENOMEM;
-
-	memcpy(m, &marker, sizeof(marker));
-	if (head->iov_len)
-		memcpy(m + sizeof(marker), head->iov_base, head->iov_len);
-	bvec_set_virt(&head_bv, m, sizeof(marker) + head->iov_len);
-	iov_iter_bvec(&iters[0], ITER_SOURCE, &head_bv, 1,
-		      sizeof(marker) + head->iov_len);
-
-	iov_iter_bvec(&iters[1], ITER_SOURCE, xdr->bvec,
+	marker_kv.iov_base = &marker;
+	marker_kv.iov_len  = sizeof(marker);
+	iov_iter_kvec(&iters[n++], ITER_SOURCE, &marker_kv, 1, sizeof(marker));
+	iov_iter_kvec(&iters[n++], ITER_SOURCE, xdr->head, 1, xdr->head->iov_len);
+	iov_iter_bvec(&iters[n++], ITER_SOURCE, xdr->bvec,
 		      xdr_buf_pagecount(xdr), xdr->page_len);
 
-	if (tail->iov_len) {
-		t = page_frag_alloc(NULL, tail->iov_len, GFP_KERNEL);
-		if (!t)
-			return -ENOMEM;
-		memcpy(t, tail->iov_base, tail->iov_len);
-		bvec_set_virt(&tail_bv,  t, tail->iov_len);
-		iov_iter_bvec(&iters[2], ITER_SOURCE, &tail_bv, 1, tail->iov_len);
-		n++;
-	}
+	if (xdr->tail->iov_len)
+		iov_iter_kvec(&iters[n++], ITER_SOURCE, xdr->tail, 1, xdr->tail->iov_len);
 
-	size = sizeof(marker) + head->iov_len + xdr->page_len + tail->iov_len;
+	size = sizeof(marker) + xdr->head->iov_len + xdr->page_len + xdr->tail->iov_len;
 	iov_iter_iterlist(&msg.msg_iter, ITER_SOURCE, iters, n, size);
 
 	ret = sock_sendmsg(sock, &msg);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ