diff mbox series

[net] udp: don't be set unconnected if only UDP cmsg

Message ID 20240414195213.106209-1-yick.xie@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net] udp: don't be set unconnected if only UDP cmsg | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 934 this patch: 934
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 4 maintainers not CCed: pabeni@redhat.com edumazet@google.com kuba@kernel.org dsahern@kernel.org
netdev/build_clang success Errors and warnings before: 938 this patch: 938
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 945 this patch: 945
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 19 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 3 this patch: 3
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-04-15--15-00 (tests: 961)

Commit Message

Yick Xie April 14, 2024, 7:52 p.m. UTC
If "udp_cmsg_send()" returned 0 (i.e. only UDP cmsg),
"connected" should not be set to 0. Otherwise it stops
the connected socket from using the cached route.

Signed-off-by: Yick Xie <yick.xie@gmail.com>
---
 net/ipv4/udp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Willem de Bruijn April 15, 2024, 2:11 p.m. UTC | #1
Yick Xie wrote:
> If "udp_cmsg_send()" returned 0 (i.e. only UDP cmsg),
> "connected" should not be set to 0. Otherwise it stops
> the connected socket from using the cached route.
> 
> Signed-off-by: Yick Xie <yick.xie@gmail.com>

This either needs to target net-next, or have

Fixes: 2e8de8576343 ("udp: add gso segment cmsg")

I think it can be argued either way. This situation existed from the
start, and is true for other cmsg that don't affect routing as well.

If the impact of the route lookup is significant, it couls be argued
to be a performance bug.

I steer towards net-next. In which case it would be nice to also
move the ipc.opt branch and perhaps even exclude other common cmsgs,
such as SCM_TXTIME and SCM_TIMESTAMPING.
Yick Xie April 15, 2024, 11:30 p.m. UTC | #2
On Mon, Apr 15, 2024 at 10:11 PM Willem de Bruijn
<willemdebruijn.kernel@gmail.com> wrote:
>
> Yick Xie wrote:
> > If "udp_cmsg_send()" returned 0 (i.e. only UDP cmsg),
> > "connected" should not be set to 0. Otherwise it stops
> > the connected socket from using the cached route.
> >
> > Signed-off-by: Yick Xie <yick.xie@gmail.com>
>
> This either needs to target net-next, or have
>
> Fixes: 2e8de8576343 ("udp: add gso segment cmsg")

I should have added that, sorry for the mess.

> I think it can be argued either way. This situation existed from the
> start, and is true for other cmsg that don't affect routing as well.
>
> If the impact of the route lookup is significant, it couls be argued
> to be a performance bug.

With sendmsg(), any smaller gso_size could be picked up dynamically.
Then it depends, "ip_route_output_flow()" could be as expensive as
"ip_make_skb()".

> I steer towards net-next. In which case it would be nice to also
> move the ipc.opt branch and perhaps even exclude other common cmsgs,
> such as SCM_TXTIME and SCM_TIMESTAMPING.

Both are fine. Though could it be better to take an easy backporting at first?
Willem de Bruijn April 16, 2024, 2:51 p.m. UTC | #3
Yick Xie wrote:
> On Mon, Apr 15, 2024 at 10:11 PM Willem de Bruijn
> <willemdebruijn.kernel@gmail.com> wrote:
> >
> > Yick Xie wrote:
> > > If "udp_cmsg_send()" returned 0 (i.e. only UDP cmsg),
> > > "connected" should not be set to 0. Otherwise it stops
> > > the connected socket from using the cached route.
> > >
> > > Signed-off-by: Yick Xie <yick.xie@gmail.com>
> >
> > This either needs to target net-next, or have
> >
> > Fixes: 2e8de8576343 ("udp: add gso segment cmsg")
> 
> I should have added that, sorry for the mess.

No worries.

> > I think it can be argued either way. This situation existed from the
> > start, and is true for other cmsg that don't affect routing as well.
> >
> > If the impact of the route lookup is significant, it couls be argued
> > to be a performance bug.
> 
> With sendmsg(), any smaller gso_size could be picked up dynamically.
> Then it depends, "ip_route_output_flow()" could be as expensive as
> "ip_make_skb()".
> 
> > I steer towards net-next. In which case it would be nice to also
> > move the ipc.opt branch and perhaps even exclude other common cmsgs,
> > such as SCM_TXTIME and SCM_TIMESTAMPING.
> 
> Both are fine. Though could it be better to take an easy backporting at first?

Sounds good. Please just resend with the Fixes tag.
diff mbox series

Patch

diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index c02bf011d4a6..420905be5f30 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1123,16 +1123,17 @@  int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 
 	if (msg->msg_controllen) {
 		err = udp_cmsg_send(sk, msg, &ipc.gso_size);
-		if (err > 0)
+		if (err > 0) {
 			err = ip_cmsg_send(sk, msg, &ipc,
 					   sk->sk_family == AF_INET6);
+			connected = 0;
+		}
 		if (unlikely(err < 0)) {
 			kfree(ipc.opt);
 			return err;
 		}
 		if (ipc.opt)
 			free = 1;
-		connected = 0;
 	}
 	if (!ipc.opt) {
 		struct ip_options_rcu *inet_opt;