net: rds: convert rds to getsockopt_iter
Subsystems (6)
v3 cover net: rds: convert rds to getsockopt_iter
This series continues the conversion of the remaining proto_ops getsockopt callbacks to the new getsockopt_iter callback introduced in commit 67fab22a7adc ("net: add getsockopt_iter callback to proto_ops"), this time for RDS.
RDS is a little more involved than the protocols converted so far, because the RDS_INFO_* options snapshot kernel state directly into the destination
buffer: the info producers memcpy into the pages under a spinlock via kmap_atomic() and so must not fault.
The conversion preserves that model — it obtains the same page array and starting offset from opt->iter_out with iov_iter_extract_pages(), preallocating the array so the iterator fills it in place, and leaves the rds_info_iterator / rds_info_copy machinery and all producer callbacks unchanged; kernel (ITER_KVEC) buffers remain unsupported on the RDS_INFO path, as before.
I've vibe-coded a kselftest exercising both the simple options and the RDS_INFO_* snapshot path, feel free to drop it in case this is not useful.
---
Changes in v3:
- Resolved the conflict with net-next
- Added additional tags (assisted-by and reviewes)
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- rds: reject non-user-backed buffers with !user_backed_iter() instead of iov_iter_is_kvec() on the RDS_INFO path (Allison Henderson)
- rds: gate the page unpin on iov_iter_extract_will_pin() and comment the implicit pin (Allison Henderson)
- selftest: size the snapshot mmap from the probed length instead of a fixed two pages (Allison Henderson)
- Add a new patch to fix a concern raised by Sashiko.
- Link to v1:
https://lore.kernel.org/r/[email protected]
---
Breno Leitao (2):
selftests: net: rds: add getsockopt() conversion test
rds: convert to getsockopt_iter
net/rds/af_rds.c | 36 ++--- net/rds/info.c | 76 +++++----- net/rds/info.h | 3 +- tools/testing/selftests/net/rds/.gitignore | 1 + tools/testing/selftests/net/rds/Makefile | 4 + tools/testing/selftests/net/rds/getsockopt.c | 208 +++++++++++++++++++++++++++ 6 files changed, 278 insertions(+), 50 deletions(-)
---
base-commit: 903db046d5579bef0ea699eae4b279dd6455fc9f
change-id: 20260603-getsock_more-46be8d1c56fd
Best regards,
Signature · 1 line
Breno Leitao <[email protected]>
PATCH v3 1/2 selftests: net: rds: add getsockopt() conversion test
Add a kselftest that exercises the RDS getsockopt() paths converted to the getsockopt_iter() / sockopt_t callback:
- RDS_RECVERR and SO_RDS_TRANSPORT, which return their int value through copy_to_iter() and report the written length in opt->optlen.
- RDS_INFO_*, which obtains the userspace buffer pages with iov_iter_extract_pages() (including a non-zero starting page offset) and lets the info producers copy the snapshot in under a spinlock.
--- tools/testing/selftests/net/rds/.gitignore | 1 + tools/testing/selftests/net/rds/Makefile | 4 + tools/testing/selftests/net/rds/getsockopt.c | 208 +++++++++++++++++++++++++++ 3 files changed, 213 insertions(+)
tools/testing/selftests/net/rds/.gitignore +1 -0
@@ -1 +1,2 @@ include.sh +getsockopt
tools/testing/selftests/net/rds/Makefile +4 -0
@@ -5,6 +5,8 @@ all: TEST_PROGS := rds_run.sh +TEST_GEN_PROGS := getsockopt + TEST_FILES := \ include.sh \ settings \
@@ -16,4 +18,6 @@ EXTRA_CLEAN := \ /tmp/rds_logs \ # end of EXTRA_CLEAN +CFLAGS += $(KHDR_INCLUDES) + include ../../lib.mk
tools/testing/selftests/net/rds/getsockopt.c new file +208 -0
208 lines not on this page · raw message
Signature · 1 line
2.53.0-Meta
PATCH v3 2/2 rds: convert to getsockopt_iter
In reply to Breno LeitaoConvert RDS socket's getsockopt implementation to use the new getsockopt_iter callback with sockopt_t.
Key changes:
- Replace (char __user *optval, int __user *optlen) with sockopt_t *opt
- Use opt->optlen for buffer length (input) and returned size (output)
- Use copy_to_iter() instead of put_user()/copy_to_user()
The RDS_INFO_* snapshot path in rds_info_getsockopt() used to pin the userspace buffer with pin_user_pages_fast() on the raw optval address; the info producers then memcpy into those pages under a spinlock via kmap_atomic() and so must not fault. Obtain the same page array and starting offset from opt->iter_out with iov_iter_extract_pages(), which pins for write because iter_out is ITER_DEST.
The page array is preallocated here (sized with iov_iter_npages()) and passed in, so iov_iter_extract_pages() fills it in place rather than allocating one for us; RDS therefore keeps ownership of the array on every return path and frees it itself. The rds_info_iterator / rds_info_copy machinery and all producer callbacks are unchanged.
Kernel buffers (ITER_KVEC) are not page-backed in a way the info producers can use, so the RDS_INFO path returns -EOPNOTSUPP for them; this matches the previous behaviour, where a kernel-buffer getsockopt hit the WARN_ONCE() path in do_sock_getsockopt() and returned -EOPNOTSUPP. The simple RDS_RECVERR and SO_RDS_TRANSPORT options keep working for kernel buffers via copy_to_iter().
--- net/rds/af_rds.c | 36 +++++++++++++++------------ net/rds/info.c | 76 ++++++++++++++++++++++++++++++++------------------------ net/rds/info.h | 3 +-- 3 files changed, 65 insertions(+), 50 deletions(-)
net/rds/af_rds.c +20 -16
@@ -37,6 +37,7 @@#include <linux/in.h> #include <linux/ipv6.h> #include <linux/poll.h> +#include <linux/uio.h> #include <net/sock.h> #include "rds.h"
@@ -485,35 +486,36 @@ static int rds_setsockopt(struct socket *sock, int level, int optname, }static int rds_getsockopt (struct socket *sock,int level,int optname, -char __user *optval,int __user *optlen) +sockopt_t *opt) {struct rds_sock *rs =rds_sk_to_rs (sock->sk);int ret = -ENOPROTOOPT , len;int trans; +int val;if (level !=SOL_RDS ) goto out; -if (get_user (len, optlen)) { - ret = -EFAULT ; - goto out; - } + len = opt->optlen;switch (optname) { case RDS_INFO_FIRST ... RDS_INFO_LAST: - ret =rds_info_getsockopt (sock, optname, optval, - optlen); + ret =rds_info_getsockopt (sock, optname, opt);break ;case RDS_RECVERR : -if (len <sizeof (int )) +if (len <sizeof (int )) { ret = -EINVAL ; -else -if (put_user (rs->rs_recverr, (int __user *) optval) || -put_user (sizeof (int ), optlen)) +break ; + } + val = rs->rs_recverr; +if (copy_to_iter (&val,sizeof (int ), &opt->iter_out) != +sizeof (int )) { ret = -EFAULT ; -else + }else { + opt->optlen =sizeof (int ); ret =0 ; + }break ;case SO_RDS_TRANSPORT :if (len <sizeof (int )) {
@@ -522,11 +524,13 @@ static int rds_getsockopt(struct socket *sock, int level, int optname, } trans = (rs->rs_transport ? rs->rs_transport->t_type :RDS_TRANS_NONE );/* unbound */ -if (put_user (trans, (int __user *)optval) || -put_user (sizeof (int ), optlen)) +if (copy_to_iter (&trans,sizeof (int ), &opt->iter_out) != +sizeof (int )) { ret = -EFAULT ; -else + }else { + opt->optlen =sizeof (int ); ret =0 ; + }break ;default :break ;
@@ -653,7 +657,7 @@ static const struct proto_ops rds_proto_ops = { .listen = sock_no_listen, .shutdown = sock_no_shutdown, .setsockopt = rds_setsockopt, - .getsockopt = rds_getsockopt, + .getsockopt_iter = rds_getsockopt, .sendmsg = rds_sendmsg, .recvmsg = rds_recvmsg, .mmap = sock_no_mmap,
net/rds/info.c +44 -32
130 lines not on this page · raw message
net/rds/info.h +1 -2
@@ -21,8 +21,7 @@ typedef void (*rds_info_func)(struct socket *sock, unsigned int len,void rds_info_register_func (int optname,rds_info_func func);void rds_info_deregister_func (int optname,rds_info_func func); -int rds_info_getsockopt (struct socket *sock,int optname,char __user *optval, -int __user *optlen); +int rds_info_getsockopt (struct socket *sock,int optname,sockopt_t *opt);void rds_info_copy (struct rds_info_iterator *iter,void *data,unsigned long bytes);void rds_info_iter_unmap (struct rds_info_iterator *iter);
Signature · 1 line
2.53.0-Meta
Re: [PATCH net-next v3 2/2] rds: convert to getsockopt_iter: manual merge
Hi Breno, Allison,
Quoted 27 lines · Breno Leitao
Convert RDS socket's getsockopt implementation to use the new
getsockopt_itercallback withsockopt_t.Key changes:
- Replace (char__user*optval, int__user*optlen) withsockopt_t*opt
- Useopt->optlenfor buffer length (input) and returned size (output)
- Usecopy_to_iter()instead of put_user()/copy_to_user()The RDS_INFO_* snapshot path in
rds_info_getsockopt()used to pin the userspace buffer withpin_user_pages_fast()on the raw optval address; the info producers then memcpy into those pages under a spinlock viakmap_atomic()and so must not fault. Obtain the same page array and starting offset fromopt->iter_outwithiov_iter_extract_pages(), which pins for write becauseiter_outisITER_DEST.The page array is preallocated here (sized with
iov_iter_npages()) and passed in, soiov_iter_extract_pages()fills it in place rather than allocating one for us; RDS therefore keeps ownership of the array on every return path and frees it itself. Therds_info_iterator/rds_info_copymachinery and all producer callbacks are unchanged.Kernel buffers (
ITER_KVEC) are not page-backed in a way the info producers can use, so theRDS_INFOpath returns-EOPNOTSUPPfor them; this matches the previous behaviour, where a kernel-buffer getsockopt hit theWARN_ONCE()path indo_sock_getsockopt()and returned-EOPNOTSUPP. The simpleRDS_RECVERRandSO_RDS_TRANSPORToptions keep working for kernel buffers viacopy_to_iter().
(...)
Quoted 4 lines
net/rds/info.c +0
-0
(...)
Quoted 6 lines
net/rds/info.c +0
-2@@ -230,13 +239,16 @@ int rds_info_getsockopt(struct socket *sock, int optname, char __user *optval, ret = lens.each; } -if (put_user (len, optlen)) - ret = -EFAULT ;
net/rds/info.c int rds_info_getsockopt(struct socket *sock, int optname, char __user *optval, · line 250
Quoted 10 lines
net/rds/info.c +6
-1+ opt->optlen = len; out: -if (pages) +/* +* iov_iter_extract_pages() pins only user-backed (ubuf) iters; +* iov_iter_extract_will_pin() reports whether an unpin is owed here. +*/ +if (pages &&iov_iter_extract_will_pin (&opt->iter_out))unpin_user_pages (pages, nr_pages);
FYI, we got a small conflict when merging 'net' in 'net-next' in the MPTCP tree due to this patch applied in 'net':
f512db8267b73 ("rds: mark snapshot pages dirty in rds_info_getsockopt()")
and this one from 'net-next':
6e94eeb2a2a6 ("rds: convert to getsockopt_iter")
----- Generic Message -----
The best is to avoid conflicts between 'net' and 'net-next' trees but if they cannot be avoided when preparing patches, a note about how to fix them is much appreciated.
The conflict has been resolved on our side [1] and the resolution we suggest is attached to this email. Please report any issues linked to this conflict resolution as it might be used by others. If you worked on the mentioned patches, don't hesitate to ACK this conflict resolution.
---------------------------
Regarding this conflict, I took the modification from net-next, but using unpin_user_pages_dirty_lock() from net.
Rerere cache is available in [2].
Cheers,
Matt
1: https://github.com/multipath-tcp/mptcp_net-next/commit/a8d41e018cc6
2: https://github.com/multipath-tcp/mptcp-upstream-rr-cache/commit/88eeb
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
net/rds/info.c +0 -0
@@@ -239,16 -230,13 +239,16 @@@ call_func ret = lens.each; } - if (put_user(len, optlen)) - ret = -EFAULT ; + opt->optlen = len; out: - if (pages) +/* + * iov_iter_extract_pages() pins only user-backed (ubuf) iters; + * iov_iter_extract_will_pin() reports whether an unpin is owed here. + */ + if (pages && iov_iter_extract_will_pin(&opt->iter_out)) -unpin_user_pages (pages, nr_pages); +unpin_user_pages_dirty_lock (pages, nr_pages, true); -kfree (pages); +kvfree (pages);return ret; }
Allison Henderson
maintainerRe: [PATCH net-next v3 2/2] rds: convert to getsockopt_iter: manual merge
Quoted 71 lines · Matthieu Baerts
Hi Breno, Allison,
Quoted 27 lines · Breno Leitao
Convert RDS socket's getsockopt implementation to use the new
getsockopt_itercallback withsockopt_t.Key changes:
- Replace (char__user*optval, int__user*optlen) withsockopt_t*opt
- Useopt->optlenfor buffer length (input) and returned size (output)
- Usecopy_to_iter()instead of put_user()/copy_to_user()The RDS_INFO_* snapshot path in
rds_info_getsockopt()used to pin the userspace buffer withpin_user_pages_fast()on the raw optval address; the info producers then memcpy into those pages under a spinlock viakmap_atomic()and so must not fault. Obtain the same page array and starting offset fromopt->iter_outwithiov_iter_extract_pages(), which pins for write becauseiter_outisITER_DEST.The page array is preallocated here (sized with
iov_iter_npages()) and passed in, soiov_iter_extract_pages()fills it in place rather than allocating one for us; RDS therefore keeps ownership of the array on every return path and frees it itself. Therds_info_iterator/rds_info_copymachinery and all producer callbacks are unchanged.Kernel buffers (
ITER_KVEC) are not page-backed in a way the info producers can use, so theRDS_INFOpath returns-EOPNOTSUPPfor them; this matches the previous behaviour, where a kernel-buffer getsockopt hit theWARN_ONCE()path indo_sock_getsockopt()and returned-EOPNOTSUPP. The simpleRDS_RECVERRandSO_RDS_TRANSPORToptions keep working for kernel buffers viacopy_to_iter().(...)
Quoted 4 lines
net/rds/info.c +0
-0(...)
Quoted 6 lines
net/rds/info.c +0
-2@@ -230,13 +239,16 @@ int rds_info_getsockopt(struct socket *sock, int optname, char __user *optval, ret = lens.each; } -if (put_user (len, optlen)) - ret = -EFAULT ;net/rds/info.c int rds_info_getsockopt(struct socket *sock, int optname, char __user *optval, · line 250
Quoted 10 lines
net/rds/info.c +6
-1+ opt->optlen = len; out: -if (pages) +/* +* iov_iter_extract_pages() pins only user-backed (ubuf) iters; +* iov_iter_extract_will_pin() reports whether an unpin is owed here. +*/ +if (pages &&iov_iter_extract_will_pin (&opt->iter_out))unpin_user_pages (pages, nr_pages);FYI, we got a small conflict when merging 'net' in 'net-next' in the MPTCP tree due to this patch applied in 'net':
f512db8267b73("rds: mark snapshot pages dirty inrds_info_getsockopt()")and this one from 'net-next':
6e94eeb2a2a6("rds: convert togetsockopt_iter")----- Generic Message -----
The best is to avoid conflicts between 'net' and 'net-next' trees but if they cannot be avoided when preparing patches, a note about how to fix them is much appreciated.
Quoted 8 lines
The conflict has been resolved on our side [1] and the resolution we suggest is attached to this email. Please report any issues linked to this conflict resolution as it might be used by others. If you worked on the mentioned patches, don't hesitate to ACK this conflict resolution.
---------------------------Regarding this conflict, I took the modification from net-next, but using
unpin_user_pages_dirty_lock()from net.
Hi Matt,
Yes, the conflict resolution looks correct to me.
Thank you for fixing this.
Allison
Quoted 11 lines
Rerere cache is available in [2].
Cheers,
Matt1: https://github.com/multipath-tcp/mptcp_net-next/commit/a8d41e018cc6
2: https://github.com/multipath-tcp/mptcp-upstream-rr-cache/commit/88eebCheers,
Matt
Re: [PATCH net-next v3 2/2] rds: convert to getsockopt_iter: manual merge
In reply to Matthieu BaertsHello Matthieu,
Quoted 10 lines · Matthieu Baerts
Review
Quoted 6 lines
(quoted diff) +5
-0+ /* + * iov_iter_extract_pages() pins only user-backed (ubuf) iters; + * iov_iter_extract_will_pin() reports whether an unpin is owed here. + */ + if (pages && iov_iter_extract_will_pin(&opt->iter_out)) unpin_user_pages(pages, nr_pages);FYI, we got a small conflict when merging 'net' in 'net-next' in the MPTCP tree due to this patch applied in 'net':
Quoted 5 lines
f512db8267b73("rds: mark snapshot pages dirty inrds_info_getsockopt()")and this one from 'net-next':
6e94eeb2a2a6("rds: convert togetsockopt_iter")
I was aware of the conflict but didn't realize a note would be helpful for the merge. I should have included one.
Could you point me to an example commit/patch that contains such a note so I can understand the expected format and procedure?
Apologies for the omission.
--breno
Re: [PATCH net-next v3 2/2] rds: convert to getsockopt_iter: manual merge
Hi Breno,
Quoted 17 lines · Breno Leitao
Hello Matthieu,
Quoted 14 lines · Matthieu Baerts
Review
Quoted 6 lines
(quoted diff) +5
-0+ /* + * iov_iter_extract_pages() pins only user-backed (ubuf) iters; + * iov_iter_extract_will_pin() reports whether an unpin is owed here. + */ + if (pages && iov_iter_extract_will_pin(&opt->iter_out)) unpin_user_pages(pages, nr_pages);FYI, we got a small conflict when merging 'net' in 'net-next' in the MPTCP tree due to this patch applied in 'net':
f512db8267b73("rds: mark snapshot pages dirty inrds_info_getsockopt()")and this one from 'net-next':
Quoted 7 lines
Quoted 1 line
6e94eeb2a2a6("rds: convert togetsockopt_iter")I was aware of the conflict but didn't realize a note would be helpful for the merge. I should have included one.
Could you point me to an example commit/patch that contains such a note so I can understand the expected format and procedure?
In this particular example, I think it would have been easier to have waited for the fix to land in net-next -- after the weekly sync with net -- and then send the net-next patches.
When this cannot be avoided, then you can mention the conflict, and ideally share a diff of the resolution, plus a description, especially when it is not obvious, when simply saying "take the version from X" is helpful, when extra modifications are needed, etc. e.g. [1]. Something similar to what Mark is usually doing on the linux-next ML, or what I did here.
[1]
https://lore.kernel.org/[email protected]
Quoted 1 line
Apologies for the omission.
No problem, it happens fairly regularly ;)
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Jakub Kicinski
maintainerRe: [PATCH net-next v3 2/2] rds: convert to getsockopt_iter: manual merge
Quoted 10 lines · On Fri, 12 Jun 2026 13:41:00 +0200 Matthieu Baerts wrote:
Quoted 5 lines
I was aware of the conflict but didn't realize a note would be helpful for the merge. I should have included one.
Could you point me to an example commit/patch that contains such a note so I can understand the expected format and procedure?
In this particular example, I think it would have been easier to have waited for the fix to land in net-next -- after the weekly sync with net -- and then send the net-next patches.
Quoted 6 lines
When this cannot be avoided, then you can mention the conflict, and ideally share a diff of the resolution, plus a description, especially when it is not obvious, when simply saying "take the version from X" is helpful, when extra modifications are needed, etc. e.g. [1]. Something similar to what Mark is usually doing on the linux-next ML, or what I did here.
Thanks for explaining! This conflict was avoidable but I didn't find the appropriately polite explanation within me :)
When conflicting code is _already committed_ to net-next we can deal with the conflict. If there's a patch only posted but not commited and we notice a bug - the net-next patch should be explicitly withdrawn and reposted once the fix has propagated.
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Mon, 08 Jun 2026 02:44:56 -0700 you wrote:
This series continues the conversion of the remaining
proto_opsgetsockopt callbacks to the newgetsockopt_itercallback introduced in commit67fab22a7adc("net: addgetsockopt_itercallback toproto_ops"), this time for RDS.RDS is a little more involved than the protocols converted so far, because the RDS_INFO_* options snapshot kernel state directly into the destination
buffer: the info producers memcpy into the pages under a spinlock viakmap_atomic()and so must not fault.[...]
Here is the summary with links:
- [net-next,v3,1/2] selftests: net: rds: add getsockopt() conversion test
https://git.kernel.org/netdev/net-next/c/b74360369e13 - [net-next,v3,2/2] rds: convert to getsockopt_iter https://git.kernel.org/netdev/net-next/c/6e94eeb2a2a6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html