Skip to contentSkip to conversation

Prepare NFS server for RPC-on-TLS

RFC PATCH New Chuck Lever 1 participant 4 messages Feb 12, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Prepare NFS server for RPC-on-TLS

The following series implements changes to the Linux NFS server's socket transport that are pre-requisite to supporting RPC on TLS. The socket transport is made to use the iov_iter-based kernel socket APIs. These changes are modeled after similar changes made to the NFS client-side socket transport.

This is a draft patch series. I have tried it out and it is working, but as it has changed only the Reply-send side, it is incomplete. This posting is a request for comments -- show your work.

One additional change I might make in this series is moving the xpt_mutex into the socket sendto methods. This is because the RDMA sendto method doesn't appear to require serialization. That is still down the road.

---

Chuck Lever (3):
SUNRPC: Move xs_stream_record_marker
SUNRPC: Refactor xs_sendpages()
SUNRPC: Teach server to use xprt_sock_sendmsg for socket sends

 include/linux/sunrpc/msg_prot.h |   13 ++
 include/linux/sunrpc/svcauth.h  |    1 
 include/linux/sunrpc/xdr.h      |   14 ---
 net/sunrpc/socklib.c            |  136 ++++++++++++++++++++++++++
 net/sunrpc/socklib.h            |   15 +++
 net/sunrpc/sunrpc.h             |    4 -
 net/sunrpc/svc.c                |    4 -
 net/sunrpc/svcsock.c            |  203 +++++++++++++--------------------------
 net/sunrpc/xprtsock.c           |  203 ++++++---------------------------------
 9 files changed, 261 insertions(+), 332 deletions(-)
 create mode 100644 net/sunrpc/socklib.h

--
Chuck Lever

#1 lore raw

RFC PATCH 1/3 SUNRPC: Move xs_stream_record_marker

Refactor: Allow the client and server to share this helper function.

msg_prot.h now needs linux/kernel.h for cpu_to_be32. #include <msg_prot.h> is removed anywhere it is not required and causes a compilation failure due to the new header dependency.

---
 include/linux/sunrpc/msg_prot.h |   13 +++++++++++++
 include/linux/sunrpc/svcauth.h  |    1 -
 net/sunrpc/xprtsock.c           |   18 +++---------------
 3 files changed, 16 insertions(+), 16 deletions(-)
include/linux/sunrpc/msg_prot.h +13 -0
index bea40d9f03a1..cceb5a3e39f5 100644
@@ -104,6 +104,19 @@ enum rpc_auth_stat {
 #define	RPC_FRAGMENT_SIZE_MASK		(~RPC_LAST_STREAM_FRAGMENT)
 #define	RPC_MAX_FRAGMENT_SIZE		((1U << 31) - 1)
 
+/**
+ * rpc_stream_record_marker - Construct a 4-octet stream record marker
+ * @size: number of octets in the RPC message to send
+ *
+ * Returns the stream record marker field for a record of length < 2^31-1
+ */
+static inline rpc_fraghdr rpc_stream_record_marker(u32 size)
+{
+	if (!size)
+		return 0;
+	return cpu_to_be32(RPC_LAST_STREAM_FRAGMENT | size);
+}
+
 /*
  * RPC call and reply header size as number of 32bit words (verifier
  * size computed separately, see below)
include/linux/sunrpc/svcauth.h +0 -1
index b0003866a249..aeac5a955cce 100644
@@ -11,7 +11,6 @@
 #define _LINUX_SUNRPC_SVCAUTH_H_
 
 #include <linux/string.h>
-#include <linux/sunrpc/msg_prot.h>
 #include <linux/sunrpc/cache.h>
 #include <linux/sunrpc/gss_api.h>
 #include <linux/hash.h>
net/sunrpc/xprtsock.c +3 -15
index d86c664ea6af..f940179db510 100644
@@ -929,17 +929,6 @@ static int xs_nospace(struct rpc_rqst *req)
 	return transport->xmit.offset != 0 && req->rq_bytes_sent == 0;
 }
 
-/*
- * Return the stream record marker field for a record of length < 2^31-1
- */
-static rpc_fraghdr
-xs_stream_record_marker(struct xdr_buf *xdr)
-{
-	if (!xdr->len)
-		return 0;
-	return cpu_to_be32(RPC_LAST_STREAM_FRAGMENT | (u32)xdr->len);
-}
-
 /**
  * xs_local_send_request - write an RPC request to an AF_LOCAL socket
  * @req: pointer to RPC request
@@ -957,7 +946,7 @@ static int xs_local_send_request(struct rpc_rqst *req)
 	struct sock_xprt *transport =
 				container_of(xprt, struct sock_xprt, xprt);
 	struct xdr_buf *xdr = &req->rq_snd_buf;
-	rpc_fraghdr rm = xs_stream_record_marker(xdr);
+	rpc_fraghdr rm = rpc_stream_record_marker(xdr->len);
 	unsigned int msglen = rm ? req->rq_slen + sizeof(rm) : req->rq_slen;
 	int status;
 	int sent = 0;
@@ -1104,7 +1093,7 @@ static int xs_tcp_send_request(struct rpc_rqst *req)
 	struct rpc_xprt *xprt = req->rq_xprt;
 	struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
 	struct xdr_buf *xdr = &req->rq_snd_buf;
-	rpc_fraghdr rm = xs_stream_record_marker(xdr);
+	rpc_fraghdr rm = rpc_stream_record_marker(xdr->len);
 	unsigned int msglen = rm ? req->rq_slen + sizeof(rm) : req->rq_slen;
 	bool vm_wait = false;
 	int status;
@@ -2652,8 +2641,7 @@ static int bc_sendto(struct rpc_rqst *req)
 	struct msghdr msg = {
 		.msg_flags	= MSG_MORE
 	};
-	rpc_fraghdr marker = cpu_to_be32(RPC_LAST_STREAM_FRAGMENT |
-					 (u32)xbufp->len);
+	rpc_fraghdr marker = rpc_stream_record_marker(xbufp->len);
 	struct kvec iov = {
 		.iov_base	= &marker,
 		.iov_len	= sizeof(marker),
#2 lore raw

RFC PATCH 2/3 SUNRPC: Refactor xs_sendpages()

In reply to Chuck Lever

Refactor: Re-locate xs_sendpages() so that it can be shared with server code.

---
 include/linux/sunrpc/xdr.h |   14 ----
 net/sunrpc/socklib.c       |  136 ++++++++++++++++++++++++++++++++++++++++
 net/sunrpc/socklib.h       |   15 ++++
 net/sunrpc/svcsock.c       |    1 
 net/sunrpc/xprtsock.c      |  148 ++++++--------------------------------------
 5 files changed, 172 insertions(+), 142 deletions(-)
 create mode 100644 net/sunrpc/socklib.h
include/linux/sunrpc/xdr.h +0 -14
index b41f34977995..a1264b19b34c 100644
@@ -188,20 +188,6 @@ static inline void xdr_netobj_dup(struct xdr_netobj *dst,
 extern int read_bytes_from_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int);
 extern int write_bytes_to_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int);
 
-/*
- * Helper structure for copying from an sk_buff.
- */
-struct xdr_skb_reader {
-	struct sk_buff	*skb;
-	unsigned int	offset;
-	size_t		count;
-	__wsum		csum;
-};
-
-typedef size_t (*xdr_skb_read_actor)(struct xdr_skb_reader *desc, void *to, size_t len);
-
-extern int csum_partial_copy_to_xdr(struct xdr_buf *, struct sk_buff *);
-
 extern int xdr_encode_word(struct xdr_buf *, unsigned int, u32);
 extern int xdr_decode_word(struct xdr_buf *, unsigned int, u32 *);
 
net/sunrpc/socklib.c +136 -0

148 lines not on this page · raw message

net/sunrpc/socklib.h new file +15 -0
new file mode 100644
index 000000000000..c48114ad6f00
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 1995-1997 Olaf Kirch <[email protected]>
+ * Copyright (C) 2020, Oracle.
+ */
+
+#ifndef _NET_SUNRPC_SOCKLIB_H_
+#define _NET_SUNRPC_SOCKLIB_H_
+
+int csum_partial_copy_to_xdr(struct xdr_buf *xdr, struct sk_buff *skb);
+int xprt_sock_sendmsg(struct socket *sock, struct msghdr *msg,
+		      struct xdr_buf *xdr, unsigned int base,
+		      rpc_fraghdr marker, unsigned int *sent_p);
+
+#endif /* _NET_SUNRPC_SOCKLIB_H_ */
net/sunrpc/svcsock.c +1 -0
index fe045b3e7e08..47957088d7d3 100644
@@ -55,6 +55,7 @@
 #include <linux/sunrpc/stats.h>
 #include <linux/sunrpc/xprt.h>
 
+#include "socklib.h"
 #include "sunrpc.h"
 
 #define RPCDBG_FACILITY	RPCDBG_SVCXPRT
net/sunrpc/xprtsock.c +20 -128

199 lines not on this page · raw message

#3 lore raw

RFC PATCH 3/3 SUNRPC: Teach server to use xprt_sock_sendmsg for socket sends

In reply to Chuck Lever

xprt_sock_sendmsg uses the more efficient iov_iter-enabled kernel socket API, and is a pre-requisite for server send-side support for TLS.

Note that svc_process no longer needs to reserve a word for the stream record marker, since the TCP transport now provides the record marker automatically in a separate buffer.

The dprintk() in svc_send_common is also removed. It didn't seem crucial for field troubleshooting. If more is needed there, a trace point could be added in xprt_sock_sendmsg().

---
 net/sunrpc/sunrpc.h   |    4 -
 net/sunrpc/svc.c      |    4 -
 net/sunrpc/svcsock.c  |  202 ++++++++++++++++---------------------------------
 net/sunrpc/xprtsock.c |   39 ++-------
 4 files changed, 74 insertions(+), 175 deletions(-)
net/sunrpc/sunrpc.h +0 -4
index c9bacb3c930f..47a756503d11 100644
@@ -50,10 +50,6 @@ static inline int sock_is_loopback(struct sock *sk)
 	return loopback;
 }
 
-int svc_send_common(struct socket *sock, struct xdr_buf *xdr,
-		    struct page *headpage, unsigned long headoffset,
-		    struct page *tailpage, unsigned long tailoffset);
-
 int rpc_clients_notifier_register(void);
 void rpc_clients_notifier_unregister(void);
 #endif /* _NET_SUNRPC_SUNRPC_H */
net/sunrpc/svc.c +0 -4
index d4a0134f1ca1..73b536cdb818 100644
@@ -1529,10 +1529,6 @@ static __printf(2,3) void svc_printk(struct svc_rqst *rqstp, const char *fmt, ..
 		goto out_drop;
 	}
 
-	/* Reserve space for the record marker */
-	if (rqstp->rq_prot == IPPROTO_TCP)
-		svc_putnl(resv, 0);
-
 	/* Returns 1 for send, 0 for drop */
 	if (likely(svc_process_common(rqstp, argv, resv)))
 		return svc_send(rqstp);
net/sunrpc/svcsock.c +65 -137

228 lines not on this page · raw message

net/sunrpc/xprtsock.c +9 -30
index 0380d72d8485..4fc38bd2f41e 100644
@@ -2517,45 +2517,24 @@ static void bc_free(struct rpc_task *task)
 	free_page((unsigned long)buf);
 }
 
-/*
- * Use the svc_sock to send the callback. Must be called with svsk->sk_mutex
- * held. Borrows heavily from svc_tcp_sendto and xs_tcp_send_request.
- */
 static int bc_sendto(struct rpc_rqst *req)
 {
-	int len;
-	struct xdr_buf *xbufp = &req->rq_snd_buf;
+	struct xdr_buf *xdr = &req->rq_snd_buf;
 	struct sock_xprt *transport =
 			container_of(req->rq_xprt, struct sock_xprt, xprt);
-	unsigned long headoff;
-	unsigned long tailoff;
-	struct page *tailpage;
 	struct msghdr msg = {
-		.msg_flags	= MSG_MORE
-	};
-	rpc_fraghdr marker = rpc_stream_record_marker(xbufp->len);
-	struct kvec iov = {
-		.iov_base	= &marker,
-		.iov_len	= sizeof(marker),
+		.msg_flags	= 0,
 	};
+	rpc_fraghdr marker = rpc_stream_record_marker(xdr->len);
+	unsigned int sent = 0;
+	int err;
 
 	req->rq_xtime = ktime_get();
-
-	len = kernel_sendmsg(transport->sock, &msg, &iov, 1, iov.iov_len);
-	if (len != iov.iov_len)
+	err = xprt_sock_sendmsg(transport->sock, &msg, xdr, 0, marker, &sent);
+	xdr_free_bvec(xdr);
+	if (err < 0 || sent != (xdr->len + sizeof(marker)))
 		return -EAGAIN;
-
-	tailpage = NULL;
-	if (xbufp->tail[0].iov_len)
-		tailpage = virt_to_page(xbufp->tail[0].iov_base);
-	tailoff = (unsigned long)xbufp->tail[0].iov_base & ~PAGE_MASK;
-	headoff = (unsigned long)xbufp->head[0].iov_base & ~PAGE_MASK;
-	len = svc_send_common(transport->sock, xbufp,
-			      virt_to_page(xbufp->head[0].iov_base), headoff,
-			      tailpage, tailoff);
-	if (len != xbufp->len)
-		return -EAGAIN;
-	return len;
+	return sent;
 }
 
 /*