From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Subject: [PATCH] net-udp: deprioritize cpu match for udp socket lookup Date: Wed, 5 Dec 2018 12:59:17 -0800 Message-ID: <20181205205917.169177-1-zenczykowski@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: netdev@vger.kernel.org To: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= , "David S . Miller" , Eric Dumazet Return-path: Received: from mail-pf1-f194.google.com ([209.85.210.194]:36863 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728423AbeLEVAH (ORCPT ); Wed, 5 Dec 2018 16:00:07 -0500 Received: by mail-pf1-f194.google.com with SMTP id b85so10617759pfc.3 for ; Wed, 05 Dec 2018 13:00:07 -0800 (PST) Sender: netdev-owner@vger.kernel.org List-ID: From: Maciej Żenczykowski During udp socket lookup cpu match should be lowest priority, hence it should increase score by only 1. The next priority is delivering v4 to v4 sockets, and v6 to v6 sockets. The v6 code path doesn't have to deal with this so it always gets a score of '4'. The v4 code path uses '4' or '2' depending on whether we're delivering to a v4 socket or a dualstack v6 socket. This is more important than cpu match, so has to be greater than the '1' bump in score from cpu match. All other matches (src/dst ip, src port) are even *more* important, so need to bump score by 4 for ipv4. For ipv6 we could simply bump by 2, but let's keep the two code paths as similar as possible. (also, while at it, remove two unnecessary unconditional score bumps) Signed-off-by: Maciej Żenczykowski --- net/ipv4/udp.c | 3 +-- net/ipv6/udp.c | 9 ++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index aff2a8e99e01..0c0ab0383cec 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -380,7 +380,7 @@ static int compute_score(struct sock *sk, struct net *net, ipv6_only_sock(sk)) return -1; - score = (sk->sk_family == PF_INET) ? 2 : 1; + score = (sk->sk_family == PF_INET) ? 4 : 2; inet = inet_sk(sk); if (inet->inet_rcv_saddr) { @@ -405,7 +405,6 @@ static int compute_score(struct sock *sk, struct net *net, dif, sdif); if (!dev_match) return -1; - score += 4; if (sk->sk_incoming_cpu == raw_smp_processor_id()) score++; diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 09cba4cfe31f..5441062d7d5e 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -125,31 +125,30 @@ static int compute_score(struct sock *sk, struct net *net, sk->sk_family != PF_INET6) return -1; - score = 0; + score = 4; inet = inet_sk(sk); if (inet->inet_dport) { if (inet->inet_dport != sport) return -1; - score++; + score += 4; } if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) { if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr)) return -1; - score++; + score += 4; } if (!ipv6_addr_any(&sk->sk_v6_daddr)) { if (!ipv6_addr_equal(&sk->sk_v6_daddr, saddr)) return -1; - score++; + score += 4; } dev_match = udp_sk_bound_dev_eq(net, sk->sk_bound_dev_if, dif, sdif); if (!dev_match) return -1; - score++; if (sk->sk_incoming_cpu == raw_smp_processor_id()) score++; -- 2.20.0.rc1.387.gf8505762e3-goog