From patchwork Thu Apr 28 13:57:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830756 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE6F3C433FE for ; Thu, 28 Apr 2022 13:58:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347869AbiD1OCE (ORCPT ); Thu, 28 Apr 2022 10:02:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347858AbiD1OCD (ORCPT ); Thu, 28 Apr 2022 10:02:03 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE85054FB5; Thu, 28 Apr 2022 06:58:48 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id m20so9716288ejj.10; Thu, 28 Apr 2022 06:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OEhPbS9UUEhMm7nsZ+7/eveIRRgkUDZKIVimBlj5lFI=; b=omuFmVbFmUOMDqtROASIHcSfMyZkpFuPF1GwAY9KcxlascuXyE+AMZVGAaGwOWIY1S ym8ZcJYBJPJrn2jN6LDco3YJHgvdfGVSuTwUo4vJMmI/puo26KmCUBUf5/M4oM2X1Xhx aQgaBUeGJUot9+xmWwPmelbGvxRA3m65dqJTVhK5Zkt0h5v4onWTrrilXLEG9L7aXp3t Tia93LSxEpeqUCtQSMc5NtN1jbsUG6bP60x5RNaJ7d7cjYDhrFPNiPM6SNfIr2ViddAD 65NHMZEDzaIlUXuSfEo3Z01raRdYKeFvTR0n8bxzdmT8EbjFe3sfrRHM6RRbKS6wRYYF i6qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OEhPbS9UUEhMm7nsZ+7/eveIRRgkUDZKIVimBlj5lFI=; b=fpxYjI/qXnGtNYtHJH8IsByOU+j/WowkM1yBq84acyNTJE+LPWhNN3u8M+PcH5bA8b La2FWmC1dYcWKP5xzkMEyIsmUhPZFt2K7SBnPq4qMs/iEzjWfpGUhJWHC/xxQyymffMW gFNenSJRgynJGodzo4/oMHHp5y/5RiOHiLnZNSrHJzz/e7FwPZQkUJx5xNtzoQRl3znJ gwJnfwMGvlDJ50aICqdCdaaJhLBowiKq4+c1QcUvLAnjYI8BZDUrWDveDCehBkaOB6tz S7C3I05ct0o5wRv3gHTx0SWBhvYLsBhpDhVFI32JxmVXoCkauGf7ja8sfmJDThV2iAN5 hvng== X-Gm-Message-State: AOAM531/J1cP4cz1tFOBMYmVsP9J/qZc5iv0VNo4g9oWZNq205Des4cX kEPnGc/lv1+TBagUGtrgJzRvAPo9L1Y= X-Google-Smtp-Source: ABdhPJzIqr6TOs8gcajLm7jw8RmYW0yfqZg4ikRYIfxe9F3mWA7FyYyFJfoIT3dcwsRhbDkWxff7iQ== X-Received: by 2002:a17:907:6ea4:b0:6f3:87c8:21cc with SMTP id sh36-20020a1709076ea400b006f387c821ccmr23228049ejc.490.1651154327180; Thu, 28 Apr 2022 06:58:47 -0700 (PDT) Received: from 127.0.0.1localhost ([85.255.235.145]) by smtp.gmail.com with ESMTPSA id t19-20020aa7d4d3000000b0042617ba63c2sm1652568edr.76.2022.04.28.06.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 06:58:46 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH v2 net-next 01/11] ipv6: optimise ipcm6 cookie init Date: Thu, 28 Apr 2022 14:57:56 +0100 Message-Id: <64341db6ca5a1f4d1eebbe86a7ee0b7d7400335e.1651153920.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Users of ipcm6_init() have a somewhat complex post initialisation of ->dontfrag and ->tclass. Not only it adds additional overhead, but also complicates the code. First, replace ipcm6_init() with ipcm6_init_sk(). As it might be not an equivalent change, let's first look at ->dontfrag. The logic was to set it from cmsg if specified and otherwise fallback to np->dontfrag. Now it's initialising to np->dontfrag in the beginning and then potentially overriding with cmsg, which is absolutely the same behaviour. It's a bit more complex with ->tclass as ip6_datagram_send_ctl() might set it to -1, which is a default and not valid value. The solution here is to skip -1's specified in cmsg, so it'll be left with the socket default value getting us to the old behaviour. Signed-off-by: Pavel Begunkov --- include/net/ipv6.h | 9 --------- net/ipv6/datagram.c | 4 ++-- net/ipv6/ip6_output.c | 2 -- net/ipv6/raw.c | 8 +------- net/ipv6/udp.c | 7 +------ net/l2tp/l2tp_ip6.c | 8 +------- 6 files changed, 5 insertions(+), 33 deletions(-) diff --git a/include/net/ipv6.h b/include/net/ipv6.h index 213612f1680c..30a3447e34b4 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h @@ -352,15 +352,6 @@ struct ipcm6_cookie { struct ipv6_txoptions *opt; }; -static inline void ipcm6_init(struct ipcm6_cookie *ipc6) -{ - *ipc6 = (struct ipcm6_cookie) { - .hlimit = -1, - .tclass = -1, - .dontfrag = -1, - }; -} - static inline void ipcm6_init_sk(struct ipcm6_cookie *ipc6, const struct ipv6_pinfo *np) { diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c index 206f66310a88..1b334bc855ae 100644 --- a/net/ipv6/datagram.c +++ b/net/ipv6/datagram.c @@ -1003,9 +1003,9 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk, if (tc < -1 || tc > 0xff) goto exit_f; + if (tc != -1) + ipc6->tclass = tc; err = 0; - ipc6->tclass = tc; - break; } diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 1f3d777e7694..976554d0fdec 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -2001,8 +2001,6 @@ struct sk_buff *ip6_make_skb(struct sock *sk, ip6_cork_release(cork, &v6_cork); return ERR_PTR(err); } - if (ipc6->dontfrag < 0) - ipc6->dontfrag = inet6_sk(sk)->dontfrag; err = __ip6_append_data(sk, &queue, cork, &v6_cork, ¤t->task_frag, getfrag, from, diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c index 0d7c13d33d1a..4582e432fa9f 100644 --- a/net/ipv6/raw.c +++ b/net/ipv6/raw.c @@ -808,7 +808,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) fl6.flowi6_mark = sk->sk_mark; fl6.flowi6_uid = sk->sk_uid; - ipcm6_init(&ipc6); + ipcm6_init_sk(&ipc6, np); ipc6.sockc.tsflags = sk->sk_tsflags; ipc6.sockc.mark = sk->sk_mark; @@ -920,9 +920,6 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) if (hdrincl) fl6.flowi6_flags |= FLOWI_FLAG_KNOWN_NH; - if (ipc6.tclass < 0) - ipc6.tclass = np->tclass; - fl6.flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6.flowlabel); dst = ip6_dst_lookup_flow(sock_net(sk), sk, &fl6, final_p); @@ -933,9 +930,6 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) if (ipc6.hlimit < 0) ipc6.hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst); - if (ipc6.dontfrag < 0) - ipc6.dontfrag = np->dontfrag; - if (msg->msg_flags&MSG_CONFIRM) goto do_confirm; diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index db9449b52dbe..de8382930910 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1313,7 +1313,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) int is_udplite = IS_UDPLITE(sk); int (*getfrag)(void *, char *, int, int, int, struct sk_buff *); - ipcm6_init(&ipc6); + ipcm6_init_sk(&ipc6, np); ipc6.gso_size = READ_ONCE(up->gso_size); ipc6.sockc.tsflags = sk->sk_tsflags; ipc6.sockc.mark = sk->sk_mark; @@ -1518,9 +1518,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) security_sk_classify_flow(sk, flowi6_to_flowi_common(fl6)); - if (ipc6.tclass < 0) - ipc6.tclass = np->tclass; - fl6->flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6->flowlabel); dst = ip6_sk_dst_lookup_flow(sk, fl6, final_p, connected); @@ -1566,8 +1563,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) up->pending = AF_INET6; do_append_data: - if (ipc6.dontfrag < 0) - ipc6.dontfrag = np->dontfrag; up->len += ulen; err = ip6_append_data(sk, getfrag, msg, ulen, sizeof(struct udphdr), &ipc6, fl6, (struct rt6_info *)dst, diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c index 217c7192691e..12406789bb28 100644 --- a/net/l2tp/l2tp_ip6.c +++ b/net/l2tp/l2tp_ip6.c @@ -521,7 +521,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) fl6.flowi6_mark = sk->sk_mark; fl6.flowi6_uid = sk->sk_uid; - ipcm6_init(&ipc6); + ipcm6_init_sk(&ipc6, np); if (lsa) { if (addr_len < SIN6_LEN_RFC2133) @@ -608,9 +608,6 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) security_sk_classify_flow(sk, flowi6_to_flowi_common(&fl6)); - if (ipc6.tclass < 0) - ipc6.tclass = np->tclass; - fl6.flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6.flowlabel); dst = ip6_dst_lookup_flow(sock_net(sk), sk, &fl6, final_p); @@ -622,9 +619,6 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) if (ipc6.hlimit < 0) ipc6.hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst); - if (ipc6.dontfrag < 0) - ipc6.dontfrag = np->dontfrag; - if (msg->msg_flags & MSG_CONFIRM) goto do_confirm; From patchwork Thu Apr 28 13:57:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830757 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2A3DC433EF for ; Thu, 28 Apr 2022 13:59:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347881AbiD1OCP (ORCPT ); Thu, 28 Apr 2022 10:02:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347841AbiD1OCF (ORCPT ); Thu, 28 Apr 2022 10:02:05 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B2F0AFB22; Thu, 28 Apr 2022 06:58:50 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id i19so9713498eja.11; Thu, 28 Apr 2022 06:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mnpdGRyJiicLRHa2IgTDV7oi07PrHAZNJEbFWn+qIEE=; b=A+uJOXp/j0z7GOW61vteBo9ZVMEVCsOZulAkxcSZnlPvNcWxmqsmQjjY8i9V7h5h19 cL1exyl2qXaWU+bMycx9p0kvebfLwR8UTBespx+6IYc+YbRzfn9nNsW7xzMpoUKYbQqp vANrrRlMdfm5Mja0XV+EwiHyusJsxKqkjktpN4xCSNByH0fbVq4cfjATJpENW6bJfBir 8Gh1L8nwcnpri9wsJLZ1f6f0TxqS4Xn5T0g7M9YKsoZAi8z6+5FEVC2QH8+B2IxhHWId loeMl54tmrV9bimmLVJNMlqbLB93nIAB+iiwG1+CrzBVKD0Lf2c8SJZ+xvgij+2qF90l bjdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mnpdGRyJiicLRHa2IgTDV7oi07PrHAZNJEbFWn+qIEE=; b=lvIApdNJa8zj/zL1SCY90hO/nmHcH7BTOBkEPgu1EFCP6aho9Mhqfw6parzMDjZtCt u0p6yHFf52zUh3QSPGKmCTCrx3ihoT9h/p+zHginpGtpO8oteuY3xjBtg2kdekU1jxh0 9p1n01GoYqjXqB45RlVBnf7TiCaKAtFbd3hUIMlzymsV1aYdPmuPhcYlf9xOnSkgRRc/ wuFF7CnDukl6vFmSyUFN7MG2d0FjqoJjzJ2pH5sYhR7S5JZ1dI5jN7N6E0vrxxDXX3nF mOgNCT5HM6UrSdA1VVxJ8k9qIngstzgwqWxS2AQn0tyStba1EyuBF8Nk7S8cHY6WvmQQ B79A== X-Gm-Message-State: AOAM531jnVVC7Svy7A2s4gXr+lX6j44t6q2NiZzgVDrrCOItJB0Fvgy6 iB648qICDfqjj261utYdORZMh7mGeOs= X-Google-Smtp-Source: ABdhPJy9YAqifjCUO6Yv1OvhtoJLZRpJ5O48gsyaDASK26eIGM02T+Cq6Npt0ToouWD54F6k2YRYgA== X-Received: by 2002:a17:907:7ba6:b0:6f3:8f56:793b with SMTP id ne38-20020a1709077ba600b006f38f56793bmr21612573ejc.473.1651154328438; Thu, 28 Apr 2022 06:58:48 -0700 (PDT) Received: from 127.0.0.1localhost ([85.255.235.145]) by smtp.gmail.com with ESMTPSA id t19-20020aa7d4d3000000b0042617ba63c2sm1652568edr.76.2022.04.28.06.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 06:58:48 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH v2 net-next 02/11] udp/ipv6: refactor udpv6_sendmsg udplite checks Date: Thu, 28 Apr 2022 14:57:57 +0100 Message-Id: <33dfdf2119c86e35062f783d405bedec2fde2b4c.1651153920.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Don't save a IS_UDPLITE() result in advance but do when it's really needed, so it doesn't store/load it from the stack. Same for resolving the getfrag callback pointer. Signed-off-by: Pavel Begunkov --- net/ipv6/udp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index de8382930910..705eea080f5e 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1310,7 +1310,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) int ulen = len; int corkreq = READ_ONCE(up->corkflag) || msg->msg_flags&MSG_MORE; int err; - int is_udplite = IS_UDPLITE(sk); int (*getfrag)(void *, char *, int, int, int, struct sk_buff *); ipcm6_init_sk(&ipc6, np); @@ -1371,7 +1370,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) if (len > INT_MAX - sizeof(struct udphdr)) return -EMSGSIZE; - getfrag = is_udplite ? udplite_getfrag : ip_generic_getfrag; if (up->pending) { if (up->pending == AF_INET) return udp_sendmsg(sk, msg, len); @@ -1538,6 +1536,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) if (!corkreq) { struct sk_buff *skb; + getfrag = IS_UDPLITE(sk) ? udplite_getfrag : ip_generic_getfrag; skb = ip6_make_skb(sk, getfrag, msg, ulen, sizeof(struct udphdr), &ipc6, (struct rt6_info *)dst, @@ -1564,6 +1563,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) do_append_data: up->len += ulen; + getfrag = IS_UDPLITE(sk) ? udplite_getfrag : ip_generic_getfrag; err = ip6_append_data(sk, getfrag, msg, ulen, sizeof(struct udphdr), &ipc6, fl6, (struct rt6_info *)dst, corkreq ? msg->msg_flags|MSG_MORE : msg->msg_flags); @@ -1594,7 +1594,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) */ if (err == -ENOBUFS || test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) { UDP6_INC_STATS(sock_net(sk), - UDP_MIB_SNDBUFERRORS, is_udplite); + UDP_MIB_SNDBUFERRORS, IS_UDPLITE(sk)); } return err; From patchwork Thu Apr 28 13:57:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830758 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D860AC433EF for ; Thu, 28 Apr 2022 13:59:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347895AbiD1OCQ (ORCPT ); Thu, 28 Apr 2022 10:02:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347872AbiD1OCG (ORCPT ); Thu, 28 Apr 2022 10:02:06 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B2CEB53C5; Thu, 28 Apr 2022 06:58:51 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id g6so9777133ejw.1; Thu, 28 Apr 2022 06:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6yhw3vAgS0ezr9ZZJU/0JZnt1IXk8RP1bpIj/xq+Zmg=; b=IJzn+Uub+BcVnQ8kpFx9x6zDXCNb2uL51LOFJY46LL2K/41dGUfoZfG2Iuj0iHJ76X zjIDVLaPeCQsLFVU7bbCBrPapS3yowUVs1Dv1PeBoOq5rYDl/1AiG+bQ0mhR9/Bb7F5N 8RNJ/ZIp3oIzgarYAMdpIG4RgAuWdjvOIAWPfkY6TAp43zuoWwq5BG6FuSMHNhsd19nC 4X2A3vWUSb5CUtU7JZilTw+2tRErDDrEOGToAIIEX1t4sN4xUR6A3qmjlxsTURHN422/ w48rbL2DepvkVilSt0fDbcIiM+MjcVcNZpFChoWuceYss+VrZh6/mwh3CKtdf4jnj+7A xc4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6yhw3vAgS0ezr9ZZJU/0JZnt1IXk8RP1bpIj/xq+Zmg=; b=5uqu9VfpwZuMFco6AtBJNkkkZ/1y4zaBpvHZyiCoCkybIVVJvul1ZTHOqkU0Tn1vpT Ds/DekZdNCobPFe5CQlzannRb6uQiPftrs1NVdPaepfDaf4921E4CmJjXUar5zShYYPR aevO/bYA2eOnLeUtRQOUVzQK+vUc6k9mn9YhC9utaChW+DLeBG7qQWMo1B57Q7bBw1ao uKd6z9h62rjaR7ncryHixrojWfTEP3daWgrVuTdjVxCIqq47v/Zo9QfWd4SYjGTBGJ0h ZC+8mOa01z813ixXKoICj8G4SY4lh+a/t3n1LpkFd6VRJgA5RHs8odg/SFW4FvxYPiNM cPFg== X-Gm-Message-State: AOAM532QZYY7pTvIGW83vzsCJvjlTA04w07MN8KPzR2afOPF9p1jGiQk QKCKIvh2PgmLVFoyMlKb70fAg5+iCos= X-Google-Smtp-Source: ABdhPJz7Vh6WP6wbUIx82ccznHAN7Kq+d4typKfpOEjsy3QobDistd5qOS540Z3dajUQDOUa/TYcHA== X-Received: by 2002:a17:907:9621:b0:6d7:355d:6da5 with SMTP id gb33-20020a170907962100b006d7355d6da5mr31343828ejc.195.1651154329631; Thu, 28 Apr 2022 06:58:49 -0700 (PDT) Received: from 127.0.0.1localhost ([85.255.235.145]) by smtp.gmail.com with ESMTPSA id t19-20020aa7d4d3000000b0042617ba63c2sm1652568edr.76.2022.04.28.06.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 06:58:49 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH v2 net-next 03/11] udp/ipv6: move pending section of udpv6_sendmsg Date: Thu, 28 Apr 2022 14:57:58 +0100 Message-Id: <4087b9a2cb175bca7c10404e33e8ba6c8de2ff1a.1651153920.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Move up->pending section of udpv6_sendmsg() to the beginning of the function. Even though it require some code duplication for sin6 parsing, it clearly localises the pending handling in one place, removes an extra if and more importantly will prepare the code for further patches. Signed-off-by: Pavel Begunkov --- net/ipv6/udp.c | 67 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 705eea080f5e..d6aedd4dab25 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1317,6 +1317,44 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ipc6.sockc.tsflags = sk->sk_tsflags; ipc6.sockc.mark = sk->sk_mark; + /* Rough check on arithmetic overflow, + better check is made in ip6_append_data(). + */ + if (unlikely(len > INT_MAX - sizeof(struct udphdr))) + return -EMSGSIZE; + + /* There are pending frames. */ + if (up->pending) { + if (up->pending == AF_INET) + return udp_sendmsg(sk, msg, len); + + /* Do a quick destination sanity check before corking. */ + if (sin6) { + if (msg->msg_namelen < offsetof(struct sockaddr, sa_data)) + return -EINVAL; + if (sin6->sin6_family == AF_INET6) { + if (msg->msg_namelen < SIN6_LEN_RFC2133) + return -EINVAL; + if (ipv6_addr_any(&sin6->sin6_addr) && + ipv6_addr_v4mapped(&np->saddr)) + return -EINVAL; + } else if (sin6->sin6_family != AF_UNSPEC) { + return -EINVAL; + } + } + + /* The socket lock must be held while it's corked. */ + lock_sock(sk); + if (unlikely(up->pending != AF_INET6)) { + /* Just now it was seen corked, userspace is buggy */ + err = up->pending ? -EAFNOSUPPORT : -EINVAL; + release_sock(sk); + return err; + } + dst = NULL; + goto do_append_data; + } + /* destination address check */ if (sin6) { if (addr_len < offsetof(struct sockaddr, sa_data)) @@ -1342,12 +1380,11 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) default: return -EINVAL; } - } else if (!up->pending) { + } else { if (sk->sk_state != TCP_ESTABLISHED) return -EDESTADDRREQ; daddr = &sk->sk_v6_daddr; - } else - daddr = NULL; + } if (daddr) { if (ipv6_addr_v4mapped(daddr)) { @@ -1364,30 +1401,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) } } - /* Rough check on arithmetic overflow, - better check is made in ip6_append_data(). - */ - if (len > INT_MAX - sizeof(struct udphdr)) - return -EMSGSIZE; - - if (up->pending) { - if (up->pending == AF_INET) - return udp_sendmsg(sk, msg, len); - /* - * There are pending frames. - * The socket lock must be held while it's corked. - */ - lock_sock(sk); - if (likely(up->pending)) { - if (unlikely(up->pending != AF_INET6)) { - release_sock(sk); - return -EAFNOSUPPORT; - } - dst = NULL; - goto do_append_data; - } - release_sock(sk); - } ulen += sizeof(struct udphdr); memset(fl6, 0, sizeof(*fl6)); From patchwork Thu Apr 28 13:57:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830759 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E950FC433EF for ; Thu, 28 Apr 2022 13:59:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347885AbiD1OCR (ORCPT ); Thu, 28 Apr 2022 10:02:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347878AbiD1OCH (ORCPT ); Thu, 28 Apr 2022 10:02:07 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96EF5B53DA; Thu, 28 Apr 2022 06:58:52 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id kq17so9757702ejb.4; Thu, 28 Apr 2022 06:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kmcy+WVcUMSTKq+Fw5VOoyUvErPXIVULV+9+XIhSEP4=; b=AhG1ruQbfC+S1+aq8qQZicm+JQ6eFjo9U+seqTxUn6Wdv/069iL+/6wBL+2K11DAiA YjL/C93lBMFqj7WpPFSoPilUlaoiJ4hxO8UhU0SbCDmEsduHi7jdlLlQF4ana6Xwgr9V 2wNgjaUA5EA20JCCLcv3rFiwA6PlyrzgEYGVrofb81Euq3VO59rR+Oap8gKRoDqckxYW YrESuNqWY42sNN4z+a80rAZwAljtUkvh9u5T8yqLX8I/lhKsi90JFpvmEL5trh4KVKY0 x/HD6S4KojJ2elMxoNuKcHW+fMWMWIAxniwM1CVf2/y/Zgh7YoT5J4FKcf7HU+WxSQiv k3KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kmcy+WVcUMSTKq+Fw5VOoyUvErPXIVULV+9+XIhSEP4=; b=0/k/d7p8ojlJXmNPBpn3WZhohUwq5AjCdNjBUP3pNwwzQP6a7MbMi84jGRiOPimzZK b48eGKcULV9dXnZPLHsZmCXetX91svR1Knz4yayIZlzQC+3yLN3iEnIp2mW0mY7nP2pc a9WdrQfibmd3YX5RLmjuP/ZbRFDkF6hM1LKnt7Z4qhz2r9q3c+2mXSFhLNcXKV7EP1e5 SMPpLF1DLoFRhcFiNs/9exmoGYcMbD7fl8Z80PH4ujbYar4n3Icn3MAySIhWv9oEtz7b L0zRNnfEU9tmljtTRyZpPeUJbRtcYg2+34PrBt0u/r/wSvNbA1tp7Kqx9dEZM54JEW+1 rCfA== X-Gm-Message-State: AOAM5320uItftD7gDkuASrXaz5tu2/XRTIoPKASXCXrRm9Le5JvegtJ8 L8jREj4eqnErrSG+WbALr2z0cvaEJHs= X-Google-Smtp-Source: ABdhPJzqAu3nWPsQh1b3nUXS4Fud941GK8pBuVyMMfVxT7x1bNfIZY6rKC3s5Kh19T36gcCnfohP1g== X-Received: by 2002:a17:907:1b02:b0:6ef:ea73:b2ea with SMTP id mp2-20020a1709071b0200b006efea73b2eamr32659309ejc.753.1651154330793; Thu, 28 Apr 2022 06:58:50 -0700 (PDT) Received: from 127.0.0.1localhost ([85.255.235.145]) by smtp.gmail.com with ESMTPSA id t19-20020aa7d4d3000000b0042617ba63c2sm1652568edr.76.2022.04.28.06.58.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 06:58:50 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH v2 net-next 04/11] udp/ipv6: prioritise the ip6 path over ip4 checks Date: Thu, 28 Apr 2022 14:57:59 +0100 Message-Id: <4436ef2b79305e059a9c4c363a3ddd709003eda5.1651153920.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org For AF_INET6 sockets we care the most about ipv6 but not ip4 mappings as it's requires some extra hops anyway. Take AF_INET6 case from the address parsing switch and add an explicit path for it. It removes some extra ifs from the path and removes the switch overhead. Signed-off-by: Pavel Begunkov --- net/ipv6/udp.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index d6aedd4dab25..78ce5fc53b59 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1357,30 +1357,27 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) /* destination address check */ if (sin6) { - if (addr_len < offsetof(struct sockaddr, sa_data)) - return -EINVAL; + if (addr_len < SIN6_LEN_RFC2133 || sin6->sin6_family != AF_INET6) { + if (addr_len < offsetof(struct sockaddr, sa_data)) + return -EINVAL; - switch (sin6->sin6_family) { - case AF_INET6: - if (addr_len < SIN6_LEN_RFC2133) + switch (sin6->sin6_family) { + case AF_INET: + goto do_udp_sendmsg; + case AF_UNSPEC: + msg->msg_name = sin6 = NULL; + msg->msg_namelen = addr_len = 0; + goto no_daddr; + default: return -EINVAL; - daddr = &sin6->sin6_addr; - if (ipv6_addr_any(daddr) && - ipv6_addr_v4mapped(&np->saddr)) - ipv6_addr_set_v4mapped(htonl(INADDR_LOOPBACK), - daddr); - break; - case AF_INET: - goto do_udp_sendmsg; - case AF_UNSPEC: - msg->msg_name = sin6 = NULL; - msg->msg_namelen = addr_len = 0; - daddr = NULL; - break; - default: - return -EINVAL; + } } + + daddr = &sin6->sin6_addr; + if (ipv6_addr_any(daddr) && ipv6_addr_v4mapped(&np->saddr)) + ipv6_addr_set_v4mapped(htonl(INADDR_LOOPBACK), daddr); } else { +no_daddr: if (sk->sk_state != TCP_ESTABLISHED) return -EDESTADDRREQ; daddr = &sk->sk_v6_daddr; From patchwork Thu Apr 28 13:58:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830761 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A4ABC433F5 for ; Thu, 28 Apr 2022 13:59:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233646AbiD1OCV (ORCPT ); Thu, 28 Apr 2022 10:02:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347884AbiD1OCO (ORCPT ); Thu, 28 Apr 2022 10:02:14 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7C0E54FB5; Thu, 28 Apr 2022 06:58:53 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id bv19so9755026ejb.6; Thu, 28 Apr 2022 06:58:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gtTf6OOj87b2Qg9AkM3LVkPT3Rm+KpZX5qOlOG7aTiU=; b=Gx257gqfWgJ/LzNF0zvajSwKTJAdku50mcLTP3RgtgUNB+lwjlaJdnjnqCIa4zcvuC SZvAuIGJB1mplQtiTdUTUtMEcnqnPRlfk3l2QzGYiY6TFgrQqHFhox7JKOfna3xkFL3V DcyfX9hCeIl7+1076cGJ/1aAR5XHbE5/fjvPCbguCikS8OR93DaGfAJh0U3V4JkMbZGi n3oE+9bnjyG7Md/padfxXYhlYBWDcu9iWKDv11fB+F4be5KGh9zZNy4nuktM6RjP66ms fRPpbo0q6U6gdS0T1GuUeY2fMTn55knpj1zH5k+D8zu4eJTCcU3B6eOPG01fL/m0ZOL8 R77A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gtTf6OOj87b2Qg9AkM3LVkPT3Rm+KpZX5qOlOG7aTiU=; b=OoDZfpZpIi4OgoIxyioba4LQgdyY70NVz1fIsqC+jrElaBYJGl0i+acVeDjzB+J+54 /wJGRTt9TKwPUi+FUfYsBv/wmfy8S/cok8TOsY6jzUJAhcoJvDQAdM2F72tjztikfVjb Qucp33dHg4VUZPAs3EmwbhUimr/QlZ+glFq0cETMWMijcFTPUb73IRqd4ZwXe0347r85 klsD1R7PfeDjgKJPmYshHFtNditOWCy2Lzjt0XgdCHyq+t7ZqYlv2CwKcNLNKdiLwxcj 5R0mqEntMaqTI/1WnuxcIgXIGXHAcI9OsGjTt5Th43D5PqMg3Yam+8/XXdWe3Mv9JeVr XU+w== X-Gm-Message-State: AOAM532r4dstBtQTc8VwHjOEC49E3/Iv5NdXSrNIXHaMSIMXJYkz0ZAx AQcCoi9MVKZ0L7OIhm3GFoA4BE26PF0= X-Google-Smtp-Source: ABdhPJxyQ4KMR89VDmB1Dw7z/c306imVzPMyLDhFXKAbPhn3OCj465FmybaXLVGVwBXLhfRo154/sA== X-Received: by 2002:a17:907:9482:b0:6da:a24e:e767 with SMTP id dm2-20020a170907948200b006daa24ee767mr31614783ejc.479.1651154332124; Thu, 28 Apr 2022 06:58:52 -0700 (PDT) Received: from 127.0.0.1localhost ([85.255.235.145]) by smtp.gmail.com with ESMTPSA id t19-20020aa7d4d3000000b0042617ba63c2sm1652568edr.76.2022.04.28.06.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 06:58:51 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH v2 net-next 05/11] udp/ipv6: optimise udpv6_sendmsg() daddr checks Date: Thu, 28 Apr 2022 14:58:00 +0100 Message-Id: <785698dcf3e1f62e6fbe5b85a42d9704a3a48793.1651153920.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org All paths taking udpv6_sendmsg() to the ipv6_addr_v4mapped() check set a non zero daddr, we can safely kill the NULL check just before it. Signed-off-by: Pavel Begunkov --- net/ipv6/udp.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 78ce5fc53b59..1f05e165eb17 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1383,19 +1383,18 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) daddr = &sk->sk_v6_daddr; } - if (daddr) { - if (ipv6_addr_v4mapped(daddr)) { - struct sockaddr_in sin; - sin.sin_family = AF_INET; - sin.sin_port = sin6 ? sin6->sin6_port : inet->inet_dport; - sin.sin_addr.s_addr = daddr->s6_addr32[3]; - msg->msg_name = &sin; - msg->msg_namelen = sizeof(sin); + if (ipv6_addr_v4mapped(daddr)) { + struct sockaddr_in sin; + + sin.sin_family = AF_INET; + sin.sin_port = sin6 ? sin6->sin6_port : inet->inet_dport; + sin.sin_addr.s_addr = daddr->s6_addr32[3]; + msg->msg_name = &sin; + msg->msg_namelen = sizeof(sin); do_udp_sendmsg: - if (__ipv6_only_sock(sk)) - return -ENETUNREACH; - return udp_sendmsg(sk, msg, len); - } + if (__ipv6_only_sock(sk)) + return -ENETUNREACH; + return udp_sendmsg(sk, msg, len); } ulen += sizeof(struct udphdr); From patchwork Thu Apr 28 13:58:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830760 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48E69C433F5 for ; Thu, 28 Apr 2022 13:59:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347890AbiD1OCU (ORCPT ); Thu, 28 Apr 2022 10:02:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347887AbiD1OCO (ORCPT ); Thu, 28 Apr 2022 10:02:14 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDFDDB53CB; Thu, 28 Apr 2022 06:58:54 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id y3so9699875ejo.12; Thu, 28 Apr 2022 06:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3Um7nfo9XPd/rjD8amGsCD9u/7MH/cL46Hqd0sO1U0M=; b=WD7KTtvqIX9d97uuqpFX/9XoDDW/Q9dAINAh5tr4EFrqfpHEnDfAkj1VpSowRSP+6S asG7wHDX7Gqdw3Ef243+nwJVwQ5UASmwjgrz6IdUlxBaNtkP0qZbcKcvVOyDtIES1gk1 ezHSvumLDOEYa4wxWhvCcRYWEJ/w7KSqya+fkfTPQN1tahoG6XuPiu/6wc1/ihoqdKzc fXLUK1nycOPU9x0wziyUB3eB6X1bAJA+rD5EjQGEoPWYJw6UN2yFMy/QDzcF+LJgNP6m PeM9/oJMKRzIRj+P/5SN+cARkTcRvR4KsKVC6FhIbqAnbMoZzz28BwWZbx/c1IkMbZIK X4fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3Um7nfo9XPd/rjD8amGsCD9u/7MH/cL46Hqd0sO1U0M=; b=YJtx+aVROJX0vPDSP77kB4/cIuwj6PmWSfNqwnPaGmIriUg/si/oWG84SS+WcyJqG/ xupZzKOt/+/8FOeB0+TtCu5ENUu+JDYkxlneww8MULYXXtwfqUBI8g92dom5tzYHyaHu 3NiX+KrMe0kVTy251lS69+jPJQnGQzFPfbLmsu8IFLSKWCR/8bPytNc1yCqpRyPZinm9 vSENjn9m7bIIYqc+6wI0GWqrXF7MpNE8U5qaHETEk9k9zCPrNDmLGSHqy0g6EejCZ3IQ w7hqn6hqKZ99i+NMbINbplcu39CjeMqr6o9tjN8rB2uwKNUsISPP4OHjMaMYJlahQpT2 Ae3Q== X-Gm-Message-State: AOAM531EGVcGXBoo+j010uAjyqIUhTQz6PmpYwOK06kZIO9C2KL6LuHX jy18KMVjksNriJQkolvbk7tk2bRrAR8= X-Google-Smtp-Source: ABdhPJwrjWasSGuZDAAAJKhaWNQCpExa3f5CuSI3/IzyNKYK0hmEmFBjz2tQRxlb8jSnfISRXYu1iA== X-Received: by 2002:a17:907:968f:b0:6db:a3c5:ae3e with SMTP id hd15-20020a170907968f00b006dba3c5ae3emr33016761ejc.770.1651154333254; Thu, 28 Apr 2022 06:58:53 -0700 (PDT) Received: from 127.0.0.1localhost ([85.255.235.145]) by smtp.gmail.com with ESMTPSA id t19-20020aa7d4d3000000b0042617ba63c2sm1652568edr.76.2022.04.28.06.58.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 06:58:52 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH v2 net-next 06/11] udp/ipv6: optimise out daddr reassignment Date: Thu, 28 Apr 2022 14:58:01 +0100 Message-Id: X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org There is nothing that checks daddr placement in udpv6_sendmsg(), so the check reassigning it to ->sk_v6_daddr looks like a not needed anymore artifact from the past. Remove it. Signed-off-by: Pavel Begunkov --- net/ipv6/udp.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 1f05e165eb17..34c5919afa3e 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1417,14 +1417,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) } } - /* - * Otherwise it will be difficult to maintain - * sk->sk_dst_cache. - */ - if (sk->sk_state == TCP_ESTABLISHED && - ipv6_addr_equal(daddr, &sk->sk_v6_daddr)) - daddr = &sk->sk_v6_daddr; - if (addr_len >= sizeof(struct sockaddr_in6) && sin6->sin6_scope_id && __ipv6_addr_needs_scope_id(__ipv6_addr_type(daddr))) From patchwork Thu Apr 28 13:58:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830762 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DFEFC433F5 for ; Thu, 28 Apr 2022 13:59:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347816AbiD1OCX (ORCPT ); Thu, 28 Apr 2022 10:02:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347893AbiD1OCO (ORCPT ); Thu, 28 Apr 2022 10:02:14 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 843CBB53F4; Thu, 28 Apr 2022 06:58:56 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id kq17so9758090ejb.4; Thu, 28 Apr 2022 06:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e5oHEvN5cdUAoS8mD1OQl++xLisYKnIOLW+OJZESkSc=; b=B7Ay620N58CnzzJIYv3/eZeSgCBFkaObDPN90zJTsS4BrONhV+NZlmrn6y6ydPNNXz 5k69AVZcE39uD3dCnCNCS+XHkANfqzcUfzT46TdqwXR7u8fKQo55BU5Cdq/yQQ8SJddb t7DlVCyL0eNtE1dFtBRJyMU2cQUEfVCtV2CGJ65cbC+OjeZujhXdoCMq1Mmpdl0LCyj1 mA7gvx2IORw7zk9eJm4JR3W4qFiLyw+eL1VEjcXgje2LTwOmR8GJgIEXsmVRxzAv0HUQ PTHmGFE97hubbcDH9sy3crMaiIDOAK8UE3XeXLdbk3UghbK6Bask48JZuO/v67qA+h4N mcSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e5oHEvN5cdUAoS8mD1OQl++xLisYKnIOLW+OJZESkSc=; b=czRRNl7vWci9bo+jvvaC1r1k1+kAnI3RK30xBml9iGpy2WVj1ywS3S9/xq/nMstC+8 ZEL6cIsPMPMIJLCDTZ0Ks9S/UmfOgslGeqeeLs0/ujQ6S8EheUsnvMUl0x63LL+bfWS6 5eqlBCOy2ENrMuUZuia+UX2CioNFeSqb5qE9SiaixeuEYbNvUiDft0SoswTr9WP9vojA Gj8O1OYkYer7sM8Ol23P2rvVEvtiBNRiPydE5j+Xurj4qycYLaehgTXSwGdP5PwVjYaZ NDvCxy3goTsShg1J2wKGjL7ZQu72xgt2M9kCN1VRxzxUDNbW4FuYq1AFvvZmaWfjYgYf d9jQ== X-Gm-Message-State: AOAM533uICAjMf3qCXnNrBdbma2FRSaiJeBAHfiAqs5zjEOhKUy93u9p E/nMh7dUqgpoHpRWUXCR6KYZ9KqxITQ= X-Google-Smtp-Source: ABdhPJyZ0rR8NSm+QymuJOkEhtZQ5MCz8DRDPpnA77mAmSTd77k4CSZwTyBjeQkEfcwmBKAs7+dmWg== X-Received: by 2002:a17:907:9705:b0:6f0:2b25:784e with SMTP id jg5-20020a170907970500b006f02b25784emr9396865ejc.76.1651154334833; Thu, 28 Apr 2022 06:58:54 -0700 (PDT) Received: from 127.0.0.1localhost ([85.255.235.145]) by smtp.gmail.com with ESMTPSA id t19-20020aa7d4d3000000b0042617ba63c2sm1652568edr.76.2022.04.28.06.58.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 06:58:54 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH v2 net-next 07/11] udp/ipv6: clean up udpv6_sendmsg's saddr init Date: Thu, 28 Apr 2022 14:58:02 +0100 Message-Id: X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org We initialise fl6 in udpv6_sendmsg() to zeroes, that sets saddr to any addr, then it might be changed in by cmsg but only to a non-any addr. After we check again for it left set to "any", which is likely to be so, and try to initialise it from socket saddr. The result of it is that fl6->saddr is set to cmsg's saddr if specified and inet6_sk(sk)->saddr otherwise. We can achieve the same by pre-setting it to the sockets saddr and potentially overriding by cmsg after. This looks a bit cleaner comparing to conditional init and also removes extra checks from the way. Signed-off-by: Pavel Begunkov --- net/ipv6/udp.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 34c5919afa3e..ae774766c116 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1431,14 +1431,15 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) connected = true; } + fl6->flowi6_uid = sk->sk_uid; + fl6->saddr = np->saddr; + fl6->daddr = *daddr; + if (!fl6->flowi6_oif) fl6->flowi6_oif = sk->sk_bound_dev_if; - if (!fl6->flowi6_oif) fl6->flowi6_oif = np->sticky_pktinfo.ipi6_ifindex; - fl6->flowi6_uid = sk->sk_uid; - if (msg->msg_controllen) { opt = &opt_space; memset(opt, 0, sizeof(struct ipv6_txoptions)); @@ -1473,9 +1474,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) fl6->flowi6_proto = sk->sk_protocol; fl6->flowi6_mark = ipc6.sockc.mark; - fl6->daddr = *daddr; - if (ipv6_addr_any(&fl6->saddr) && !ipv6_addr_any(&np->saddr)) - fl6->saddr = np->saddr; fl6->fl6_sport = inet->inet_sport; if (cgroup_bpf_enabled(CGROUP_UDP6_SENDMSG) && !connected) { From patchwork Thu Apr 28 13:58:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830765 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF55EC433EF for ; Thu, 28 Apr 2022 13:59:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347878AbiD1OC2 (ORCPT ); Thu, 28 Apr 2022 10:02:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347899AbiD1OCO (ORCPT ); Thu, 28 Apr 2022 10:02:14 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F054B53FD; Thu, 28 Apr 2022 06:58:57 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id i19so9714204eja.11; Thu, 28 Apr 2022 06:58:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jDy/baqCrS7ciidt4u0hxQhcY5iVuejvnMqLkeL0Gp4=; b=Nv84QzVfOaj7yhylmcHRpG0PCFknDRzqZrfcfaKlok4O+NaLStjQE1wHTODpqlp8+Q hkqhAADE+Ntj/Be/Lk+ckKuD6Au2Puzk8KmwCQvf29VBjv0VAYKTEuLikXuIPpLPnubA 818CnLl0TJxJZYJQkah7E0BkEr6RMnAZfFB+J3Q4SepACi2uqMPMWPqYF5qJWfVH9bdP +VCP4wXOcoYbYp1/32Hmk9Hr3sKrmueFfImZCt1cPW4nPxHxp/j05Q22TPInxROxPHbP BrQT8tWlbACS3e0bCehrzjdk/vuXD+UF5mOlZgKv4ceBDfGONYBHfqAv8nzBSOPE5OWi uoOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jDy/baqCrS7ciidt4u0hxQhcY5iVuejvnMqLkeL0Gp4=; b=Tf0n+zvIPiGFyWg1BOFHjGWnt4KJ7rfYdxyNdtUaMmI/xK4ZaID9bA2a5LB5BTxf1f x0SJwEvG3ZLEUo3XHGCrGhD8ubX0oe+hHanKKu5HeoDqjpEmgWa0BcoVeOQ2KEaqovQd izgy2VPX07pKt23zkZRNrcbu/R0HmNWPH/jR5Yg26KJbS6eYs4WW0SCvV/rE0gT2dm7Z U99/vbmCokghiDwNkWuuVOKrIROBCABOU7358XF+PNTI7hC4/0k0ZdCwrgfo7DNqQH3X 8rwwuxZrOV7uKY7Wlw00H88Ykw6b9ZUnDV2mJnqTQnftoLD1anGnoOla43VofIv93/22 12iA== X-Gm-Message-State: AOAM531iywge46f7nR3jXGVuBexP7nxpr92kHpjDbaUp3sMxha0fRiCz S3sbSUUpQ4XAy2G2eEDarydJICOfk78= X-Google-Smtp-Source: ABdhPJzo88a4QiTQ8zybcIfjUzFWnrDVXK1ojqd5k6aG0Npx6wJ1wsSsE3kDmaB6COsHFE3PqvxyNQ== X-Received: by 2002:a17:906:c147:b0:6df:f047:1677 with SMTP id dp7-20020a170906c14700b006dff0471677mr31371204ejc.4.1651154336018; Thu, 28 Apr 2022 06:58:56 -0700 (PDT) Received: from 127.0.0.1localhost ([85.255.235.145]) by smtp.gmail.com with ESMTPSA id t19-20020aa7d4d3000000b0042617ba63c2sm1652568edr.76.2022.04.28.06.58.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 06:58:55 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH v2 net-next 08/11] ipv6: partially inline fl6_update_dst() Date: Thu, 28 Apr 2022 14:58:03 +0100 Message-Id: <997b0b5bf91d23dc40e7002ab863ba2bd75a8ce9.1651153920.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org fl6_update_dst() doesn't do anything when there are no opts passed. Inline the null checking part. Signed-off-by: Pavel Begunkov --- include/net/ipv6.h | 15 ++++++++++++--- net/ipv6/exthdrs.c | 15 ++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/include/net/ipv6.h b/include/net/ipv6.h index 30a3447e34b4..b9848fcd6954 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h @@ -1094,9 +1094,18 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, int target, int ipv6_find_tlv(const struct sk_buff *skb, int offset, int type); -struct in6_addr *fl6_update_dst(struct flowi6 *fl6, - const struct ipv6_txoptions *opt, - struct in6_addr *orig); +struct in6_addr *__fl6_update_dst(struct flowi6 *fl6, + const struct ipv6_txoptions *opt, + struct in6_addr *orig); + +static inline struct in6_addr *fl6_update_dst(struct flowi6 *fl6, + const struct ipv6_txoptions *opt, + struct in6_addr *orig) +{ + if (!opt || !opt->srcrt) + return NULL; + return __fl6_update_dst(fl6, opt, orig); +} /* * socket options (ipv6_sockglue.c) diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c index a8d961d3a477..d02c27d4f2c2 100644 --- a/net/ipv6/exthdrs.c +++ b/net/ipv6/exthdrs.c @@ -1367,8 +1367,8 @@ struct ipv6_txoptions *__ipv6_fixup_options(struct ipv6_txoptions *opt_space, EXPORT_SYMBOL_GPL(__ipv6_fixup_options); /** - * fl6_update_dst - update flowi destination address with info given - * by srcrt option, if any. + * __fl6_update_dst - update flowi destination address with info given + * by srcrt option. * * @fl6: flowi6 for which daddr is to be updated * @opt: struct ipv6_txoptions in which to look for srcrt opt @@ -1377,13 +1377,10 @@ EXPORT_SYMBOL_GPL(__ipv6_fixup_options); * Returns NULL if no txoptions or no srcrt, otherwise returns orig * and initial value of fl6->daddr set in orig */ -struct in6_addr *fl6_update_dst(struct flowi6 *fl6, - const struct ipv6_txoptions *opt, - struct in6_addr *orig) +struct in6_addr *__fl6_update_dst(struct flowi6 *fl6, + const struct ipv6_txoptions *opt, + struct in6_addr *orig) { - if (!opt || !opt->srcrt) - return NULL; - *orig = fl6->daddr; switch (opt->srcrt->type) { @@ -1405,4 +1402,4 @@ struct in6_addr *fl6_update_dst(struct flowi6 *fl6, return orig; } -EXPORT_SYMBOL_GPL(fl6_update_dst); +EXPORT_SYMBOL_GPL(__fl6_update_dst); From patchwork Thu Apr 28 13:58:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830763 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDC60C433EF for ; Thu, 28 Apr 2022 13:59:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347958AbiD1OCZ (ORCPT ); Thu, 28 Apr 2022 10:02:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347905AbiD1OCP (ORCPT ); Thu, 28 Apr 2022 10:02:15 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C09C8B6447; Thu, 28 Apr 2022 06:58:58 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id gh6so9839825ejb.0; Thu, 28 Apr 2022 06:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ul+t6uTHofyRjOEGXVcu4PlOdgwxB5M3MPuVkOzIQ1Y=; b=lHba1uLAwlEqeDX0O18Zy79If8Dbj7fnO680n35KyJfb1TKelYJ/nLf0g+m0ab8qjO ri3zNmYRInXinUjVYLoDjax7bk91SCtscPtpwQ6VVIq1ZOtFo+53YOo5xi6qu80B4NPQ m3rQ+OLm5qi1wgDizKcHHVkhohPAdxwh6Jt8PeDKGTyOwHLlmnIaozDohee1OWi8Ml0j PFGsw+yyQZZlLLUe/sMMdJnvnHgXlAR0jwKjC/smtOk5dYQMHgpX8hPnSYCWzVX01k+2 cfkRcMbTOYpodZoGgQlWWoYtAua8k0qEkAhx0K7BfHCo7rnPXlphGiEqDIANkxdbp6ct dFhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ul+t6uTHofyRjOEGXVcu4PlOdgwxB5M3MPuVkOzIQ1Y=; b=KU0zpFvs+YQi2EuW70seABBmR3IoV1Hr0tMh29M6gS4hDvkJ4BFnNvdvD9al8QFoTh dsVQfvzUm8StcD1LU80HhgIPXJqva1hEMavPwYLc3UaC7Ln9qFK4rY6hTqudVjP+45Zw MbtCMBO5ZT/cIiEiAyPbqVD1jh4DWdqN/ktC7JzEIsoR97G/6bFtmiLYM58FnaqAF7Gq tNQ6Z2wJUkt6HZZ4n1V2tPGLBAu0YSOm9mssJc32lwumXSDF4ZLgBnth2186GrINNER/ l05fiFfKYq72vSwCROwuL0tZvtGJ6Zpjfu+Jc/SRTPbMsnx/p/MKPg8kVulooPixDxm8 2FdA== X-Gm-Message-State: AOAM531VBCwGDqiyEJsnzzeoCxqu703kCxGUalqcluB8I0nAiTNK8r1V fFnrqUOLt2JANcN4DuYLiGC7PyC2E64= X-Google-Smtp-Source: ABdhPJxtJm7d9+qlR3zeTV28IucfFTW4EzoAs5iOpC4iOUxIdQJjfnrHKXavxaA57z4/qGxZOhcozg== X-Received: by 2002:a17:906:3ad3:b0:6cd:382b:86e5 with SMTP id z19-20020a1709063ad300b006cd382b86e5mr30032084ejd.145.1651154337065; Thu, 28 Apr 2022 06:58:57 -0700 (PDT) Received: from 127.0.0.1localhost ([85.255.235.145]) by smtp.gmail.com with ESMTPSA id t19-20020aa7d4d3000000b0042617ba63c2sm1652568edr.76.2022.04.28.06.58.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 06:58:56 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH v2 net-next 09/11] ipv6: refactor opts push in __ip6_make_skb() Date: Thu, 28 Apr 2022 14:58:04 +0100 Message-Id: X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Don't preload v6_cork->opt before we actually need it, it likely to be saved on the stack and read again for no good reason. Signed-off-by: Pavel Begunkov --- net/ipv6/ip6_output.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 976554d0fdec..43a541bbcf5f 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1855,7 +1855,6 @@ struct sk_buff *__ip6_make_skb(struct sock *sk, struct ipv6_pinfo *np = inet6_sk(sk); struct net *net = sock_net(sk); struct ipv6hdr *hdr; - struct ipv6_txoptions *opt = v6_cork->opt; struct rt6_info *rt = (struct rt6_info *)cork->base.dst; struct flowi6 *fl6 = &cork->fl.u.ip6; unsigned char proto = fl6->flowi6_proto; @@ -1884,10 +1883,14 @@ struct sk_buff *__ip6_make_skb(struct sock *sk, __skb_pull(skb, skb_network_header_len(skb)); final_dst = &fl6->daddr; - if (opt && opt->opt_flen) - ipv6_push_frag_opts(skb, opt, &proto); - if (opt && opt->opt_nflen) - ipv6_push_nfrag_opts(skb, opt, &proto, &final_dst, &fl6->saddr); + if (v6_cork->opt) { + struct ipv6_txoptions *opt = v6_cork->opt; + + if (opt->opt_flen) + ipv6_push_frag_opts(skb, opt, &proto); + if (opt->opt_nflen) + ipv6_push_nfrag_opts(skb, opt, &proto, &final_dst, &fl6->saddr); + } skb_push(skb, sizeof(struct ipv6hdr)); skb_reset_network_header(skb); From patchwork Thu Apr 28 13:58:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830764 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F164C4332F for ; Thu, 28 Apr 2022 13:59:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347963AbiD1OC1 (ORCPT ); Thu, 28 Apr 2022 10:02:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347888AbiD1OCP (ORCPT ); Thu, 28 Apr 2022 10:02:15 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBA2CB644E; Thu, 28 Apr 2022 06:58:59 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id i19so9714486eja.11; Thu, 28 Apr 2022 06:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e3JOSUJWrUPvCHFoWua5pWRqSGO0w+9yuqoonKqU/u4=; b=bu9hJGnpENGbvrQtkrbIXAPf4Sw3vEjeYxCmfzAqOM7GCOnajGxM78ci9ALZmaZAKr AcFhx8L+I2FlkTJl1uQvGfTOb0iR/IzfO7ovCL5TV+IFBQbheCjHPrNTJkVB6jrIUZaG p265sruCfLBHpPBB0FvJmwsuuphASy2KV1M8O4mBwkHaike/R7d8VSAKAfnEzbTqpRfU Bi+AmFh/aYYTJ90E8VCgyfdPnqaBMFvA/w0U0ufeNfzMNasb5+bgPpAnxOmLq16C+VM5 eVyxs/5vlw4w4QRS4P9SFK0hl5uge3V14UBfcCGb+8P6j1oaG95G3HvNAzIXGS5g34pZ p1Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e3JOSUJWrUPvCHFoWua5pWRqSGO0w+9yuqoonKqU/u4=; b=apWxoviwwRe6eeet8oe/FRWruDaXL8mCAsLNtmmmqFvJVdpeSSZMgBP+a/rmoi6x9L zsZLS44etYBEcHxOEzoXUg8MOgl6pMY5uu0zICoCMrO51aL91y522KPueHQiyaWvXADx 7AovxXWQlWsmTJykyNYBaYnfn1H/prsjgGFSgOOTfwx4t5poMyQqm0lKS4vHMQMkMIqt GTcbdiE/GOFMDHVif7Ser8Z+4yUw3RjHOCMAEmb8+ud8U8Xd6nXD57NiNkgXYImlbAb1 NnudSTTWYVKGOc2GQqmkLOSal80zcPpaiKYp20O6xoiImNc+gLMvLnxgJjTJvfboVyIQ qDVA== X-Gm-Message-State: AOAM530eBH30mQ0ONTRXLpdaVrPEuNNfkVz/TA9zi8BNzPuk1OhcOWbx +LOr6fUXswPp0V/SnU47AAuIp3zdFas= X-Google-Smtp-Source: ABdhPJzKCmlMsd5GcW/oVPQuRZeT1nKL2uqXvvyhw7YvkiV74YNikUr5s4g2YZz+8dM/RgLU3Z63ww== X-Received: by 2002:a17:907:3f91:b0:6d7:16c0:ae1b with SMTP id hr17-20020a1709073f9100b006d716c0ae1bmr31513700ejc.74.1651154338239; Thu, 28 Apr 2022 06:58:58 -0700 (PDT) Received: from 127.0.0.1localhost ([85.255.235.145]) by smtp.gmail.com with ESMTPSA id t19-20020aa7d4d3000000b0042617ba63c2sm1652568edr.76.2022.04.28.06.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 06:58:57 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH v2 net-next 10/11] ipv6: improve opt-less __ip6_make_skb() Date: Thu, 28 Apr 2022 14:58:05 +0100 Message-Id: <2313cc1d1cdf89c58f327c1be02bd04834824551.1651153920.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org We do a bit of a network header pointer shuffling in __ip6_make_skb() expecting that ipv6_push_*frag_opts() might change the layout. Avoid it with associated overhead when there are no opts. Signed-off-by: Pavel Begunkov --- net/ipv6/ip6_output.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 43a541bbcf5f..416d14299242 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1880,22 +1880,20 @@ struct sk_buff *__ip6_make_skb(struct sock *sk, /* Allow local fragmentation. */ skb->ignore_df = ip6_sk_ignore_df(sk); - __skb_pull(skb, skb_network_header_len(skb)); - final_dst = &fl6->daddr; if (v6_cork->opt) { struct ipv6_txoptions *opt = v6_cork->opt; + __skb_pull(skb, skb_network_header_len(skb)); if (opt->opt_flen) ipv6_push_frag_opts(skb, opt, &proto); if (opt->opt_nflen) ipv6_push_nfrag_opts(skb, opt, &proto, &final_dst, &fl6->saddr); + skb_push(skb, sizeof(struct ipv6hdr)); + skb_reset_network_header(skb); } - skb_push(skb, sizeof(struct ipv6hdr)); - skb_reset_network_header(skb); hdr = ipv6_hdr(skb); - ip6_flow_hdr(hdr, v6_cork->tclass, ip6_make_flowlabel(net, skb, fl6->flowlabel, ip6_autoflowlabel(net, np), fl6)); From patchwork Thu Apr 28 13:58:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830766 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B5B5C433F5 for ; Thu, 28 Apr 2022 13:59:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347887AbiD1OCf (ORCPT ); Thu, 28 Apr 2022 10:02:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347910AbiD1OCS (ORCPT ); Thu, 28 Apr 2022 10:02:18 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B999B53C7; Thu, 28 Apr 2022 06:59:00 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id m20so9717436ejj.10; Thu, 28 Apr 2022 06:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YHrgbwGuKsi0qBohJI6HWm6IXg77xQmft6cGgAr+KkM=; b=D/HtnO6Aq48sBMFVHSTn0tBOvJAS5dJDgM08hwx7/5YbiCOLqMka9aC35l1YEEEBAc AdvVf4YC6yaPDNKm0TndoQommkvI+axGOg+U8cq6/nHZvR1MiDjpVSmpOdqXgfaWG0Qm mQV81m14BxeKQyjtoutd/0XL2F9Cx+j3506jw6aI/uRhWpyYkwqi1ldfxQRgfVkpmotx TKQAIevVT84OeGwocHNI3aHsxz9E1ebWMMeshawlonpisRA0jfU/B6Zjjq+CdHcs6MEP LbGtzqtRjoC+rbkP1S6i5xTfLRRbmxj6Gy90AROgTZYbDyuYllzU3jnvbTJBiqywjUg9 Maag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YHrgbwGuKsi0qBohJI6HWm6IXg77xQmft6cGgAr+KkM=; b=Au1HzMf9hwN1r28YshtG6TNlrRHYP5MfyxpT/GftBus+oPtiOK3tDwDuqQaOeBOmz0 kop9fx6RsD4b/9sNXkaH5fRQ6M6CjWxEepP6Es2MG/7VjldNCP55gKTigM7LPdDnbt0z sX32aN1E5IPikceBzzT1Gn1MSx2cVV+e8BpcALdorQtm0Ap01BG9NdwRZy+Ljjje3y4j 4U4IR4M2C22iE5dJd+GpGN1Lnab+m8E0EBXmE2J7GrhxAMgXopBY1nFta6/ameGGWEGL mkyeLgkFZjAU5DWJZSq0l0iB58bvtIsk54KG+PuRfIzrIT38DrgmmZDQr57lcxjgUyul G16w== X-Gm-Message-State: AOAM532CKHTYlZ7m8lhMYGBv+M4Nz5DsXDbG27ar1V6cRpc68uhir2A8 DOpIL82jprxQuw27HkHxQepbqq2p3cs= X-Google-Smtp-Source: ABdhPJzqaDZwQbXPQRg01MR4TeZZwO5015Um2IKY51lgJLpQa73xeqWoAZyG4Eq8glJMto3TJeg7Ow== X-Received: by 2002:a17:907:160e:b0:6ef:ec95:f9e1 with SMTP id hb14-20020a170907160e00b006efec95f9e1mr32436049ejc.10.1651154339253; Thu, 28 Apr 2022 06:58:59 -0700 (PDT) Received: from 127.0.0.1localhost ([85.255.235.145]) by smtp.gmail.com with ESMTPSA id t19-20020aa7d4d3000000b0042617ba63c2sm1652568edr.76.2022.04.28.06.58.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 06:58:58 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH v2 net-next 11/11] ipv6: clean up ip6_setup_cork Date: Thu, 28 Apr 2022 14:58:06 +0100 Message-Id: <683aab669ffa7db48416137c904a406a37e9a0c9.1651153920.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Do a bit of refactoring for ip6_setup_cork(). Cache a xfrm_dst_path() result to not call it twice, reshuffle ifs to not repeat some parts twice and so. Signed-off-by: Pavel Begunkov --- net/ipv6/ip6_output.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 416d14299242..a17b26d5f34d 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1358,15 +1358,13 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork, struct ipv6_pinfo *np = inet6_sk(sk); unsigned int mtu; struct ipv6_txoptions *nopt, *opt = ipc6->opt; + struct dst_entry *xrfm_dst; /* callers pass dst together with a reference, set it first so * ip6_cork_release() can put it down even in case of an error. */ cork->base.dst = &rt->dst; - /* - * setup for corking - */ if (opt) { if (WARN_ON(v6_cork->opt)) return -EINVAL; @@ -1399,28 +1397,26 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork, } v6_cork->hop_limit = ipc6->hlimit; v6_cork->tclass = ipc6->tclass; - if (rt->dst.flags & DST_XFRM_TUNNEL) - mtu = np->pmtudisc >= IPV6_PMTUDISC_PROBE ? - READ_ONCE(rt->dst.dev->mtu) : dst_mtu(&rt->dst); + + xrfm_dst = xfrm_dst_path(&rt->dst); + if (dst_allfrag(xrfm_dst)) + cork->base.flags |= IPCORK_ALLFRAG; + + if (np->pmtudisc < IPV6_PMTUDISC_PROBE) + mtu = dst_mtu(rt->dst.flags & DST_XFRM_TUNNEL ? &rt->dst : xrfm_dst); else - mtu = np->pmtudisc >= IPV6_PMTUDISC_PROBE ? - READ_ONCE(rt->dst.dev->mtu) : dst_mtu(xfrm_dst_path(&rt->dst)); - if (np->frag_size < mtu) { - if (np->frag_size) - mtu = np->frag_size; - } + mtu = READ_ONCE(rt->dst.dev->mtu); + + if (np->frag_size < mtu && np->frag_size) + mtu = np->frag_size; + cork->base.fragsize = mtu; cork->base.gso_size = ipc6->gso_size; cork->base.tx_flags = 0; cork->base.mark = ipc6->sockc.mark; sock_tx_timestamp(sk, ipc6->sockc.tsflags, &cork->base.tx_flags); - - if (dst_allfrag(xfrm_dst_path(&rt->dst))) - cork->base.flags |= IPCORK_ALLFRAG; cork->base.length = 0; - cork->base.transmit_time = ipc6->sockc.transmit_time; - return 0; }