sunrpc: allocate a separate bvec array for socket sends
Subsystems (4)
Jeff Layton
maintainerPATCH v6 1/1 sunrpc: allocate a separate bvec array for socket sends
svc_tcp_sendmsg() calls xdr_buf_to_bvec() with the second slot of rq_bvec as the start, but doesn't reduce the array length by one, which could lead to an array overrun. Also, rq_bvec is always rq_maxpages in length, which can be too short in some cases, since the TCP record marker consumes a slot.
Fix both problems by adding a separate bvec array to the svc_sock that is specifically for sending. For TCP, make this array one slot longer than rq_maxpages, to account for the record marker. For UDP, only allocate as large an array as we need since it's limited to 64k of payload.
---
Another update based on Neil's feedback. This version allocates the array when the socket is allocated, and fixes the UDP length calculation.
---
Changes in v6:
- allocate sk_bvec in ->xpo_create
- fix the array-length calculation for UDP
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- reduce the size of sk_bvec on UDP sockets
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- switch to allocating a separate bvec for sends in the svc_sock
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Add rq_bvec_len field and use it in appropriate places
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Better changelog message for patch #2
- Link to v1: https://lore.kernel.org/r/[email protected]
--- include/linux/sunrpc/svcsock.h | 3 +++ net/sunrpc/svcsock.c | 54 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 50 insertions(+), 7 deletions(-)
include/linux/sunrpc/svcsock.h +3 -0
@@ -26,6 +26,9 @@ struct svc_sock {void (*sk_odata)(struct sock *);void (*sk_owspace)(struct sock *); +/* For sends (protected by xpt_mutex) */ +struct bio_vec *sk_bvec; +/* private TCP part */ /* On-the-wire fragment header: */ __be32 sk_marker;
net/sunrpc/svcsock.c +47 -7
115 lines not on this page · raw message
---
base-commit: 05d2192090744b16ce05bd221c459a9357c17525
change-id: 20251008-rq_bvec-b66afd0fdbbb
Best regards,
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 8 lines · Jeff Layton
net/sunrpc/svcsock.c +0
-0@@ -68,6 +68,16 @@#define RPCDBG_FACILITY RPCDBG_SVCXPRT
net/sunrpc/svcsock.c line 80
Quoted 10 lines
net/sunrpc/svcsock.c +10
-0+/* +* For UDP: +* 1 for header page +* 16 for up to 64kb of payload + 1 in case it's not aligned +* 1 for tail page +*/ +enum { +SUNRPC_MAX_UDP_SENDPAGES =1 +16 +1 +1 +}; +
Remember last week we found the maximum payload size on UDP was actually 32KB. Should you use RPCSVC_MAXPAYLOAD_UDP instead of a raw integer?
Otherwise, LGTM.
Signature · 1 line
Chuck Lever