* [PATCH v2 1/3] ipv6: Use the selected nexthop for source address selection
2026-12-03 23:47 [PATCH v2 0/3] Spread rdma_cm connections across ECMP paths Tim Menninger
@ 2026-12-03 23:47 ` Tim Menninger
2026-12-03 23:47 ` [PATCH v2 2/3] selftests: fib_nexthops: Check the IPv6 multipath source address Tim Menninger
2026-12-03 23:47 ` [PATCH v2 3/3] RDMA/core: Use the CM source port in IP route lookups Tim Menninger
2 siblings, 0 replies; 4+ messages in thread
From: Tim Menninger @ 2026-12-03 23:47 UTC (permalink / raw)
To: leon
Cc: jgg, bharat, dsahern, idosch, davem, edumazet, kuba, pabeni,
horms, shuah, slingappa, rpatil, linux-rdma, netdev,
linux-kselftest, linux-kernel, Tim Menninger
When a route uses a multipath nexthop group and has no preferred
source, ip6_route_get_saddr() selects the source address for
fib6_info_nh_dev(), which is the group's first nexthop. The lookup may
have selected a different nexthop, so the source address can belong to
another interface than the one the packet leaves through:
$ ip -6 route get fd00:ecb:eeee::1
... via fe80::b2cf:eff:feaf:6eb6 dev ens6np0 src fd00:ecb::3 ...
where fd00:ecb::3 is assigned to ens3np0. IPv6 legacy multipath routes
and IPv4 nexthop groups both select the source address for the chosen
path. TCP and UDP can operate with a source address assigned to another
interface, but RoCE address resolution requires a matching GID on the
selected device, and rdma_cm address resolution fails with -ENODEV
whenever the hash selects a nexthop other than the first.
Pass the dst to ip6_route_get_saddr() and, for a multipath nexthop
group, select the source address for the device of the selected path.
A configured preferred source still takes precedence, and routes without
a multipath nexthop group are unchanged.
Tested on a host with two ConnectX-7 ports, an IPv6 route through a
two-member nexthop group and hash policy 1, with rdma_cm resolving the
address and route of 64 IDs per destination. Before this change, every
ID failed for three destinations whose hash selected the second
nexthop. After it, every ID resolved, with the source address on the
egress port. A route with a preferred source on another interface kept
that source, and local destinations resolved as before.
Fixes: f88d8ea67fbd ("ipv6: Plumb support for nexthop object in a fib6_info")
Signed-off-by: Tim Menninger <tmenninger@everpuredata.com>
---
Changes in v2:
- New patch, replacing the addr6_resolve() fix proposed on v1
include/net/ip6_route.h | 9 +++++++--
net/ipv6/ip6_output.c | 3 ++-
net/ipv6/route.c | 2 +-
3 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h
index 95f936be32c6..d5754f6442bb 100644
--- a/include/net/ip6_route.h
+++ b/include/net/ip6_route.h
@@ -143,6 +143,7 @@ void rt6_age_exceptions(struct fib6_info *f6i, struct fib6_gc_args *gc_args,
unsigned long now);
static inline int ip6_route_get_saddr(struct net *net, struct fib6_info *f6i,
+ const struct dst_entry *dst,
const struct in6_addr *daddr,
unsigned int prefs, int l3mdev_index,
struct in6_addr *saddr)
@@ -155,8 +156,12 @@ static inline int ip6_route_get_saddr(struct net *net, struct fib6_info *f6i,
rcu_read_lock();
l3mdev = dev_get_by_index_rcu(net, l3mdev_index);
- if (!f6i || !f6i->fib6_prefsrc.plen || l3mdev)
- dev = f6i ? fib6_info_nh_dev(f6i) : NULL;
+ if (!f6i || !f6i->fib6_prefsrc.plen || l3mdev) {
+ if (dst && f6i && f6i->nh && nexthop_is_multipath(f6i->nh))
+ dev = dst_dev_rcu(dst);
+ else
+ dev = f6i ? fib6_info_nh_dev(f6i) : NULL;
+ }
same_vrf = !l3mdev || l3mdev_master_dev_rcu(dev) == l3mdev;
if (f6i && f6i->fib6_prefsrc.plen && same_vrf)
*saddr = f6i->fib6_prefsrc.addr;
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index cb648c839431..6627dac626e8 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -1162,7 +1162,8 @@ static int ip6_dst_lookup_tail(struct net *net, const struct sock *sk,
rcu_read_lock();
from = rt ? rcu_dereference(rt->from) : NULL;
- err = ip6_route_get_saddr(net, from, &fl6->daddr,
+ err = ip6_route_get_saddr(net, from, rt ? &rt->dst : NULL,
+ &fl6->daddr,
sk ? READ_ONCE(inet6_sk(sk)->srcprefs) : 0,
fl6->flowi6_l3mdev,
&fl6->saddr);
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 1b2dcc066e19..aec54368e1ba 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -5881,7 +5881,7 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb,
goto nla_put_failure;
} else if (dest) {
struct in6_addr saddr_buf;
- if (ip6_route_get_saddr(net, rt, dest, 0, 0, &saddr_buf) == 0 &&
+ if (ip6_route_get_saddr(net, rt, dst, dest, 0, 0, &saddr_buf) == 0 &&
nla_put_in6_addr(skb, RTA_PREFSRC, &saddr_buf))
goto nla_put_failure;
}
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 2/3] selftests: fib_nexthops: Check the IPv6 multipath source address
2026-12-03 23:47 [PATCH v2 0/3] Spread rdma_cm connections across ECMP paths Tim Menninger
2026-12-03 23:47 ` [PATCH v2 1/3] ipv6: Use the selected nexthop for source address selection Tim Menninger
@ 2026-12-03 23:47 ` Tim Menninger
2026-12-03 23:47 ` [PATCH v2 3/3] RDMA/core: Use the CM source port in IP route lookups Tim Menninger
2 siblings, 0 replies; 4+ messages in thread
From: Tim Menninger @ 2026-12-03 23:47 UTC (permalink / raw)
To: leon
Cc: jgg, bharat, dsahern, idosch, davem, edumazet, kuba, pabeni,
horms, shuah, slingappa, rpatil, linux-rdma, netdev,
linux-kselftest, linux-kernel, Tim Menninger
Extend ipv6_mpath_select to check that, for a destination hashed to each
member of a multipath nexthop group, the reported source address belongs
to the device of the selected nexthop. Without "ipv6: Use the selected
nexthop for source address selection", the source address always comes
from the first nexthop's device and the check fails for the other
member.
Signed-off-by: Tim Menninger <tmenninger@everpuredata.com>
---
Changes in v2:
- New patch
tools/testing/selftests/net/fib_nexthops.sh | 35 +++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/tools/testing/selftests/net/fib_nexthops.sh b/tools/testing/selftests/net/fib_nexthops.sh
index adbec51917eb..cdc8d53d87ac 100755
--- a/tools/testing/selftests/net/fib_nexthops.sh
+++ b/tools/testing/selftests/net/fib_nexthops.sh
@@ -387,6 +387,16 @@ get_route_dev()
fi
}
+get_route_prefsrc()
+{
+ local pfx="$1"
+ local out
+
+ if out=$($IP -j route get "$pfx" | jq -re ".[0].prefsrc"); then
+ echo "$out"
+ fi
+}
+
check_route_dev()
{
local pfx="$1"
@@ -867,6 +877,31 @@ ipv6_mpath_select()
done
log_test $rc 0 "Use valid neighbor during multipath selection"
+ # The source address must belong to the selected nexthop's device,
+ # not the device of the group's first nexthop.
+ local -A srcs
+ srcs=([veth1]=2001:db8:91::1 [veth3]=2001:db8:92::1)
+ rc=0
+ for dev in veth1 veth3; do
+ match=0
+ for h in {1..65535}; do
+ addr=$(printf "2001:db8:101::%x" $h)
+ if [ "$(get_route_dev "$addr")" = "$dev" ]; then
+ match=1
+ break
+ fi
+ done
+ if (( match == 0 )); then
+ echo "SKIP: Did not find a route using device $dev"
+ return $ksft_skip
+ fi
+ if ! check_output "$(get_route_prefsrc "$addr")" "${srcs[$dev]}"; then
+ rc=1
+ break
+ fi
+ done
+ log_test $rc 0 "Source address of selected multipath nexthop"
+
run_cmd "$IP neigh add 2001:db8:91::2 dev veth1 nud incomplete"
run_cmd "$IP neigh add 2001:db8:92::2 dev veth3 nud incomplete"
run_cmd "$IP route get 2001:db8:101::1"
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 3/3] RDMA/core: Use the CM source port in IP route lookups
2026-12-03 23:47 [PATCH v2 0/3] Spread rdma_cm connections across ECMP paths Tim Menninger
2026-12-03 23:47 ` [PATCH v2 1/3] ipv6: Use the selected nexthop for source address selection Tim Menninger
2026-12-03 23:47 ` [PATCH v2 2/3] selftests: fib_nexthops: Check the IPv6 multipath source address Tim Menninger
@ 2026-12-03 23:47 ` Tim Menninger
2 siblings, 0 replies; 4+ messages in thread
From: Tim Menninger @ 2026-12-03 23:47 UTC (permalink / raw)
To: leon
Cc: jgg, bharat, dsahern, idosch, davem, edumazet, kuba, pabeni,
horms, shuah, slingappa, rpatil, linux-rdma, netdev,
linux-kselftest, linux-kernel, Tim Menninger
From: Shiva Lingappa <slingappa@everpuredata.com>
addr4_resolve() and addr6_resolve() leave the flow's source port zero.
With wildcard source addresses and identical routing constraints,
connections to the same destination therefore select the same ECMP
nexthop, even when fib_multipath_hash_policy includes L4 ports, leaving
the other paths idle.
Populate fl4_sport/fl6_sport from the source sockaddr, which already
contains the CM-assigned port. This provides per-connection entropy
with hash policy 1, or policy 3 with the source-port field selected.
The normal RoCE CM route setup retains the selected interface and
destination MAC.
This is the CM port-space port, not the RoCEv2 UDP source port, so it
does not reproduce downstream switch hashing. It also changes matching
of source-port FIB rules without an ipproto restriction, independently
of the hash policy. Policies excluding the source port retain the same
multipath hash.
Tested over IPv4 with an NFSv4.1 flexfiles client (nconnect=16), one
data server, two-way ECMP over two 400G ConnectX-7 ports, hash policy 1
and default FIB rules. All 16 connections used one device without the
change. With the change, connections used both devices on every tested
mount. elbencho 1 MiB direct-read throughput increased from 46596 to
92726 MiB/s.
IPv6 relies on "ipv6: Use the selected nexthop for source address
selection". Without it, IDs hashed to a nexthop group member other than
the first fail address resolution. With both changes, address and route
resolution of 64 rdma_cm IDs per destination over two-way IPv6 ECMP with
hash policy 1 split between the devices on every run. A legacy multipath
route went from 64/0 to between 30/34 and 33/31. Four destinations
through a nexthop group, three of which failed for every ID before, split
between 23/41 and 39/25 with no failures.
Reported-by: Rohit Patil <rpatil@everpuredata.com>
Signed-off-by: Shiva Lingappa <slingappa@everpuredata.com>
Co-developed-by: Tim Menninger <tmenninger@everpuredata.com>
Signed-off-by: Tim Menninger <tmenninger@everpuredata.com>
---
Changes in v2:
- Note the dependency on patch 1 for IPv6
- Add the IPv6 nexthop group results
v1: https://lore.kernel.org/all/20261130193648.3170657-1-tmenninger@everpuredata.com/
drivers/infiniband/core/addr.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c
index bdaa3eb83bcc..6b80cc2c84c8 100644
--- a/drivers/infiniband/core/addr.c
+++ b/drivers/infiniband/core/addr.c
@@ -382,6 +382,7 @@ static int addr4_resolve(struct sockaddr *src_sock,
memset(&fl4, 0, sizeof(fl4));
fl4.daddr = dst_ip;
fl4.saddr = src_ip;
+ fl4.fl4_sport = src_in->sin_port;
fl4.flowi4_oif = addr->bound_dev_if;
rt = ip_route_output_key(addr->net, &fl4);
ret = PTR_ERR_OR_ZERO(rt);
@@ -411,6 +412,7 @@ static int addr6_resolve(struct sockaddr *src_sock,
memset(&fl6, 0, sizeof fl6);
fl6.daddr = dst_in->sin6_addr;
fl6.saddr = src_in->sin6_addr;
+ fl6.fl6_sport = src_in->sin6_port;
fl6.flowi6_oif = addr->bound_dev_if;
dst = ip6_dst_lookup_flow(addr->net, NULL, &fl6, NULL);
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread