From patchwork Thu Apr 28 10:56:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830407 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 6D65BC433EF for ; Thu, 28 Apr 2022 10:57:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344734AbiD1LAt (ORCPT ); Thu, 28 Apr 2022 07:00:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244981AbiD1LAn (ORCPT ); Thu, 28 Apr 2022 07:00:43 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AED3090CD9; Thu, 28 Apr 2022 03:57:28 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id w4so6204525wrg.12; Thu, 28 Apr 2022 03:57:28 -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=KTciY6PvBq1fAnq4w68NlQlhBJHjFuI79NLjB9db1OiSiBxq8WVdb5jY9pRWLTpDM4 voTxFI1p1jt7jjHhuRv1d8wrbgR6NSKe1QeVMBJHPpDMqfNKlhXdmUKgVIraL0zOiHOF BQHeGovGAayCOxY1iyz/GMrRKvYssIkKh2l3V7MViYmOyHnGmGB2/y9Q+Oh3hLtJv5lL pPQEyzOc1mGgfym9Vw79AkhfgZj6GMOeclIAwECiJtl6AaLqKQySz/gFTP9ihcXetOvY WfsUWKGJIC+uTOm1qflcn88MkAGw/r6XeGlq4DayFRCwvsN+Lg1a+J/PbfpDeqnFv1eR GIgQ== 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=Ihl9Mn2PJYgXSO2xR31KdF5QFKOY8DyKoe/OIpVnAT/PTQleF82BUTo0MgUBcHIfti P7jjWBNj4Ud8csZQw6K/59dnGx0EneOgOCqAkNfFZMDG2OQKY/5lOh/OEzgvwMoAFHZ9 OyE5xeq92PFpe4FHON3KVjzYuakrBkWOmaGvOcOgWlr/7l3AgVUcZDISnXEVPZ2XJkxG /gBWFLRXMWXQhXbobxkzS3WNOEVZ0wlXszlPA4LIfJ7UDTd/l6a/3ULRdmrHXpxNOv27 u3MnX32rp8BNSSoalr4HPHd4gZ7IIH0sEZNaaWZmsDuzRCznR5gbHmPv32ma/PMaL3C/ NTaw== X-Gm-Message-State: AOAM533Rr9nt1AQJpsEuB66p5xJZXkTDDPsWHJ426l5zrvn2QRXGrItr IMKjXxuw43jz7XJwYxAg6KU2sTEkiBI= X-Google-Smtp-Source: ABdhPJzwmwvrRlcN/KPvdpTzjXIc9JAbsUfzKpvMU2hcfxXqXibaISCptYJWNuTbtb3jelE5ezLtJA== X-Received: by 2002:a05:6000:18c9:b0:203:fb67:debe with SMTP id w9-20020a05600018c900b00203fb67debemr25691169wrq.494.1651143446899; Thu, 28 Apr 2022 03:57:26 -0700 (PDT) Received: from 127.0.0.1localhost (82-132-230-8.dab.02.net. [82.132.230.8]) by smtp.gmail.com with ESMTPSA id z11-20020a7bc14b000000b0039419dfbb39sm7547wmi.33.2022.04.28.03.57.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 03:57:26 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next 01/11] ipv6: optimise ipcm6 cookie init Date: Thu, 28 Apr 2022 11:56:32 +0100 Message-Id: <64341db6ca5a1f4d1eebbe86a7ee0b7d7400335e.1651071843.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 10:56:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830408 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 C22CDC433EF for ; Thu, 28 Apr 2022 10:57:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344476AbiD1LAu (ORCPT ); Thu, 28 Apr 2022 07:00:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344526AbiD1LAp (ORCPT ); Thu, 28 Apr 2022 07:00:45 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63EE491368; Thu, 28 Apr 2022 03:57:30 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id w4so6204628wrg.12; Thu, 28 Apr 2022 03:57:30 -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=NReDgY8SnYmMb+IEoGqOxXCWkRmL5UADdjjFrnsD22OgiPs5rW8jNC3bBrZ9qnaE+Q s+hrSLW4xZfSt1YN8rV8BSBFlPPHPlGFpVrnPGZoRG0whRVWCjJMEbW5FjM5YxuXjnFn fFGVktocBgktRuv7KBK5fLlwyuhDuSePerSEEZhf+dxKLA1XaPlsBIh78KlH5hOGeRUm TfOMR79UV7GLyuQZD50jlQXY8iLrx3Sl/7YIVsya2Si2shsOkj6O7nmoKWyyHSlvSD/H 8yMYVcv0FSo+u0t8g5dFuZGe3A9+0lkR9KPMlFV4XEGIgBbqoMy+i6m+uvx1IoK/9FrA sZqA== 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=7WAm2dqmM5oGF+ucn7D5CmSwBN/KTiGJa2f+0zTmaK09mzP7CSI25UrbUvuNSP4J6V mz501m49QhjBjbOTQzDlmD8abNycMbd5dWRoVOTBBeeVQB9GeKu7GYqy9kv7KuxLDEmI XhkMh6FmE/wQk79qoQA921JkduKohzk6F+mxQ7ws3jxR30YEn3tQfgNy6R9yk5890ZVO pbRrHOYae5vrw8SUe+vhY64IZGjzglGLUJ7C3Ea4XxMq1kPAt1bxWETvQ7rHoNZBrtGI noqUGzcWSNzTy1ffQqVwiVoFH/hlbhvz9f2wZtQSdJCuHcNXyRStHEkAMJx3uDPLXwog hOzQ== X-Gm-Message-State: AOAM532wc3qA5a1otTqIPkqxqI8uUHKiesfkvyfoa+iT662lULhXvj+c O4SEjNGDKMjPQk1uOyokw6RDgTZGpZg= X-Google-Smtp-Source: ABdhPJxteBSGREvfRY+StbvoICJq86d1XIraQhIw5UniH71CHKq4CAn8L5i9irrbztemiak/3zetSg== X-Received: by 2002:a5d:6949:0:b0:20a:e021:f8e0 with SMTP id r9-20020a5d6949000000b0020ae021f8e0mr13677427wrw.231.1651143448613; Thu, 28 Apr 2022 03:57:28 -0700 (PDT) Received: from 127.0.0.1localhost (82-132-230-8.dab.02.net. [82.132.230.8]) by smtp.gmail.com with ESMTPSA id z11-20020a7bc14b000000b0039419dfbb39sm7547wmi.33.2022.04.28.03.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 03:57:28 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next 02/11] udp/ipv6: refactor udpv6_sendmsg udplite checks Date: Thu, 28 Apr 2022 11:56:33 +0100 Message-Id: <33dfdf2119c86e35062f783d405bedec2fde2b4c.1651071843.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 10:56:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830410 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 CC6FAC433F5 for ; Thu, 28 Apr 2022 10:57:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344886AbiD1LAy (ORCPT ); Thu, 28 Apr 2022 07:00:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344584AbiD1LAs (ORCPT ); Thu, 28 Apr 2022 07:00:48 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C994791572; Thu, 28 Apr 2022 03:57:31 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id e2so6231040wrh.7; Thu, 28 Apr 2022 03:57:31 -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=kNRkNepYRjTt3OO/dzEKnflD89KsNKu1Kvbz4prFIzFNNaqhwYJwOuzBIJP6tAFrun RBgWT0YezwcnT3451mLIH3JFwChWNI3VugicPEWt0BhdJzJC5voIsgIF6611VlOQrmf3 NOeCySN/YcYX1L9L4f4mxoFugWaMplUMtP8KHG/fK/tf8lMCBXW4FqTvqoTbB9828l4X ycFxEJwsi1DEe+32v60oVzQfouje+zoSHAho1xJVxRa4YVh3VJLg/L9nrELyV/WqeR57 Ok/b65AapdQpMrAXkh0UDG3on51Zsyab8HgMWz10dUqBLNfXJs1eR1JFJrdF7T9YleLa xDzg== 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=gYsc8hzsuWJ8eEkul3/lYAuJ+WIA1bUff7fkMCFQcW3V5XmyDuReaeJRxz9xhr6VlO RIviPm6+zO7PrhRZ3y0eSkyKoYHn7Q24Y3zGTjHtV9kl5Jlp1RhVI2JXZklX2drRQt9n HxN46YS/lGKOSqRy/Tvaqtiv8xN4PH2xZqqpM8rCdT2Tq0qWRc5PAqzUTfbpK4PnONEj Er4mptKDc2v956klsraDLHUlhEQTqpbGmjOEvCFWwPlFdleFC1cO2PGEXHwAEnvNoo9D CTNXkHu5jZzPn3U3wuijmOvQMysshvn7FupfVFCKuF7aECBNkAVO25ZTFpoir8MpmnHx GKeA== X-Gm-Message-State: AOAM532pqghmPWTPpvz4mRBdul/I56g1GAxAU67H6+DeB4PYPmJUd+tv EAYUDqXplk0cQa1QilxDH6enUBZkwJE= X-Google-Smtp-Source: ABdhPJymMF7tAwz9Q34P4pRLt6oqtcgbCF5jnPFeLNTcEUDZB9szPs7nr15jcgL7ZRVSKdDguuS9Rg== X-Received: by 2002:a5d:4dc7:0:b0:20a:ed1a:2c0 with SMTP id f7-20020a5d4dc7000000b0020aed1a02c0mr6983853wru.448.1651143450190; Thu, 28 Apr 2022 03:57:30 -0700 (PDT) Received: from 127.0.0.1localhost (82-132-230-8.dab.02.net. [82.132.230.8]) by smtp.gmail.com with ESMTPSA id z11-20020a7bc14b000000b0039419dfbb39sm7547wmi.33.2022.04.28.03.57.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 03:57:29 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next 03/11] udp/ipv6: move pending section of udpv6_sendmsg Date: Thu, 28 Apr 2022 11:56:34 +0100 Message-Id: <4087b9a2cb175bca7c10404e33e8ba6c8de2ff1a.1651071843.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 10:56:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830409 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 A2A94C433EF for ; Thu, 28 Apr 2022 10:57:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344835AbiD1LAv (ORCPT ); Thu, 28 Apr 2022 07:00:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344638AbiD1LAs (ORCPT ); Thu, 28 Apr 2022 07:00:48 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32E1C92D00; Thu, 28 Apr 2022 03:57:34 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id m62so2711174wme.5; Thu, 28 Apr 2022 03:57:34 -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=gaPJ1myz3ORkg3khe+GsiTL9USx8RrLhCVgZkf7zj8cbCTNx4nLwRIQTMUWLS4OuWV Li09z4i+uZ86UwNSLtaQdwQcRKFulHUb1PK2n0Wn3nnrFrVsZVuH5+nY0DGDmcy8NR4d GRjhrQhCbNFDX++dCjan1e5XBM0YmtV46Edv+SsPKT67d71vJNgnPss2MuVOLmD7B3IQ s/W2DZp1/vOcAuY4oMJ9vYHMwKAmcr+cAIfS4oC6Z8maRGjTOskjAj/F97UgOB67bhuO duXt1WjiX4KtUIMxIdV24cp1bxxzkwwH2nTNyN58rb1L/FWm7Fj413UQXDDYvFhEts4W gm3Q== 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=33JdMtfWhJAIEG0jpAw7hs3ykC0BHnuIoarnkleX44DFMQK/geZGWmfNwof97RqXYh fVUXO0FUQf9nysHIg26D8IhnoBkfwTn95PcMy3r65/4+7aZo/yvrt0wBUWeguI4bFECN NKvKL9ep8DuhR+qi3uw8wHwQmO9fdXAffOeqPbwsw6im1Wmw2JLeeToqb6LlUAluwcK9 JCHUdSWOsdYBYtP0733ch5Og2alRjcC7KzxELLREZqStw+7laFgcxToTWPSVMFToqh63 UwaJa7Ir/OtX4xqYRInCSIWljIMmdTTWzE/KJPlBprmJdaAVoOMBRhVSai3N0fsb05c8 5EgA== X-Gm-Message-State: AOAM533Ev3O9UijQA0X8G2DEef1yIuVcamuj8oLnKY3LaTFZJ9HsBjN6 Mb+/wub8zg7UnQUoR14STl756mygjmw= X-Google-Smtp-Source: ABdhPJyhqNJkki/+WJX9ucIac/27OlWIn/E7Tz7hztKxMFN4whZom2MlU+VD28AUyn67qHICKdoEGw== X-Received: by 2002:a7b:c7c2:0:b0:394:18b:4220 with SMTP id z2-20020a7bc7c2000000b00394018b4220mr7356397wmk.118.1651143452524; Thu, 28 Apr 2022 03:57:32 -0700 (PDT) Received: from 127.0.0.1localhost (82-132-230-8.dab.02.net. [82.132.230.8]) by smtp.gmail.com with ESMTPSA id z11-20020a7bc14b000000b0039419dfbb39sm7547wmi.33.2022.04.28.03.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 03:57:32 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next 04/11] udp/ipv6: prioritise the ip6 path over ip4 checks Date: Thu, 28 Apr 2022 11:56:35 +0100 Message-Id: <4436ef2b79305e059a9c4c363a3ddd709003eda5.1651071843.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 10:56:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830411 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 898B5C433F5 for ; Thu, 28 Apr 2022 10:57:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344889AbiD1LA4 (ORCPT ); Thu, 28 Apr 2022 07:00:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344874AbiD1LAv (ORCPT ); Thu, 28 Apr 2022 07:00:51 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7263591555; Thu, 28 Apr 2022 03:57:36 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id e24so6211870wrc.9; Thu, 28 Apr 2022 03:57:36 -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=KHmTOEyyRIQseOWLkxAAeS+EbwjSn2HGLqeyy3qFQFbG6ddhltiuXxDZsbqGFVTOj7 BhS9D635h69Uenqkxpz20EXUHhuQNy8PKeKYPrQbOXTn84/5cOGwrFra/30yBG44j/JT ndDniVAQg7cBTr/Ssxlxpf5O+0DfzblWN+PBJvpZ/Rb2vkNQN1G++uKMwncuQzBE4d8M tldXJfaW5rtQ6XCfMkNLLGirZZgTZO9iktnf+Dj0qhScyhxfxmXRcGh5u3uRQnRD/g8J TggB7x+VhLpfbpFnRUYal0m7NdZO1YJRi4/FwJBoh/Gn2VWCl5ZH2SvlyaAp8r2B4fzh injA== 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=Eicr5/tiHe7YacW3CpGLzx3abgr7USkoayjAbrhU24VVSDSW0vD1lqWngcIK6wxbd7 SyNCLnugW8EDCUAPKoAhA+ytAyBuvgObk4Kawffq+xUQaJq5EvWUjEDSFFD7EyD8jYA0 pZpQITH1TNm1w7LE7r2qo3XPKmR5UiY+PufnxWmclIL44YcsPSEVnIJ1QCkZnLdTl+s9 2aia64dr2yt1jtUCucQtYckX/xlN8xzjXfqOgS51BxMBz/xajDhBObl1NrP5sKoAd+PW eoqsbVZVG5NxsYY2NjGhDcHN3Pt4qdZTkgAZkmYzn6Lon29BnQocQWF620FKqyGDAI7X E6JA== X-Gm-Message-State: AOAM532K77g9RC0xOeC5bIT6ClrsdSNeRX30kU5VSZwgoFeAdpj/vsNm RR8xKrSqFLPyGwwLi0pZHIvoTThL7Hk= X-Google-Smtp-Source: ABdhPJwW1CcIYUBS+m4yhZqOXXXcMT7J1rD+0KloFX8VoQY5lBkrSHdUxYsT4GVCiZe/AZ2Nf+AQzw== X-Received: by 2002:adf:fc47:0:b0:20a:d494:3ee5 with SMTP id e7-20020adffc47000000b0020ad4943ee5mr20486085wrs.696.1651143454893; Thu, 28 Apr 2022 03:57:34 -0700 (PDT) Received: from 127.0.0.1localhost (82-132-230-8.dab.02.net. [82.132.230.8]) by smtp.gmail.com with ESMTPSA id z11-20020a7bc14b000000b0039419dfbb39sm7547wmi.33.2022.04.28.03.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 03:57:34 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next 05/11] udp/ipv6: optimise udpv6_sendmsg() daddr checks Date: Thu, 28 Apr 2022 11:56:36 +0100 Message-Id: <785698dcf3e1f62e6fbe5b85a42d9704a3a48793.1651071843.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 10:56:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830412 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 5EA78C4332F for ; Thu, 28 Apr 2022 10:57:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344921AbiD1LA6 (ORCPT ); Thu, 28 Apr 2022 07:00:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344881AbiD1LAw (ORCPT ); Thu, 28 Apr 2022 07:00:52 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23737939A2; Thu, 28 Apr 2022 03:57:38 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id t6so6249550wra.4; Thu, 28 Apr 2022 03:57:38 -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=JyPrwcyF8T9Eff+fQ9huPKkq+0WIAHNOPon9U7CNftVgbHGH1pVjRsUl1MNJNE8VkF RXCGQ3NwpBkmR+i1TB73wUX0CMQ+2mxr6jEnRe4SMiS23IgZAgjziDTcjtxb9MZn9m5J LO0sPwKYJoFlKy0feN8/rJVmaGhcFWY/Ac/VGNESNSor8MF6jN4iOyONTQlfOa9dyxQ7 f6MkAYLthGIlUxvSpqr3UlBohxcI5oMH7Opguox2Rlm12AtAOY5bTKJjRnk17twzY/89 OXRUC57id0QUdKSCnSq+zuVMZcBf1OuVYT7Ds/FDKWFMFgODtEw4XolHYUvC6YQlDwUp fGsQ== 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=dWjDCVa3XlnQ57ix986T72XvalnDb1xFgQBai5CCTMW9ii/NGYXQu01fCbxH/ISxS9 g4DmtPzUUhqcNnV0Dbs7YPafjV4yt8TZ+5ae8iBQzfaCKfNemFNi8m3wHgVrmLbwfBzZ SD4MoIZze2K6zHEzCs4Ub5nkCk+bFh+cR7jGiprM1vIPA/DMdJZIu4ooEcXwfASUaYyF 1Fr25PiCyNkIBpzI815b3OklwjbpnjC1RqSVWwTU4Esll873PPDuOU8NfmL/5abKybec iYjAJhR5NS4B/9plZ3hvlku2G0k/yworAX0mRD+rH51maDOo/VGri0RuLPRiD5H+kx9N RIZg== X-Gm-Message-State: AOAM533/PpR7DaJ+6Hwvz5xJSMOsRxuxuEdH5mEMKgYLHtaiVDPf+vOE yjZbizIf8kelYM87aq+DJvyxhecOLJs= X-Google-Smtp-Source: ABdhPJxbWrCfVQ76VD+tkju8CQX+VznsSkNPVjEMltG6HBvAtcBCwftL+5GYQWFubiXA2t8NYZTlJA== X-Received: by 2002:adf:e10e:0:b0:206:2d7:b4de with SMTP id t14-20020adfe10e000000b0020602d7b4demr25260940wrz.497.1651143456538; Thu, 28 Apr 2022 03:57:36 -0700 (PDT) Received: from 127.0.0.1localhost (82-132-230-8.dab.02.net. [82.132.230.8]) by smtp.gmail.com with ESMTPSA id z11-20020a7bc14b000000b0039419dfbb39sm7547wmi.33.2022.04.28.03.57.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 03:57:36 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next 06/11] udp/ipv6: optimise out daddr reassignment Date: Thu, 28 Apr 2022 11:56:37 +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 10:56:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830413 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 8F388C4332F for ; Thu, 28 Apr 2022 10:57:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344958AbiD1LBC (ORCPT ); Thu, 28 Apr 2022 07:01:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344905AbiD1LA4 (ORCPT ); Thu, 28 Apr 2022 07:00:56 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6015B9548E; Thu, 28 Apr 2022 03:57:41 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id u3so6248310wrg.3; Thu, 28 Apr 2022 03:57:41 -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=Sm8A1q1kxYVEA47HbAXch0kITv+fN1ewep5piymoRTT2yvxRDpNjA5qTb1XHCZk4Ph cswY8xb8/OYBdhrlLvntm4ZMGWOFlJ+fdvKrw9xiHpTynlvhY5NoQnpyrThiik1Lpr+X wTwWXLNd+lYnhBNQOwxvgluJ5yAHGlACFJpw/iMcXdLUvK1cGrdR0tWwlAnk46FSU3b8 AcwjbIdx50IMQyTWtksImz9PQw+OMb+b3sqorwcDE3duSsxDVnEpc2i+z1qHY3MI0rXF n1eHeEEUdBUqARPzBRYKQKdZHUlb3nYXxea+OAu53QPcqloCZkD1tJy4ECEWzIqukD0w u7lA== 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=gIpPWEvl9BcxxvTznftfiHrKzZR0eQ1+8rvvRZYaGZLjY7AYHp/vQfaKyDEJ+ceAy2 aTu84SY9fsDpy9n3/j2TwpajBAYhx5xVLVjbOxtaflJ37PeTEoxG3cfS226VUYPPSiDX bFs+cMsPwX7ecdkvLUapSGdEgHY5ut6JOPHgBRQPi2fl+CieETli47ikiIFTyH7gjxUj G9BZbjJy4sbxM+/5puy0kUlEQbfIfX8BYgwhPDhzFJEBxWWlT6YMSrZyZhOEokBPgzV9 F2E31GZt3ID8YRxvlnA12lkd7yoP9HvIQsDrrpOfzyMmpnfoxQqoXUWP2QYSlIktpPzy JGpQ== X-Gm-Message-State: AOAM530VP1jTEcuBvb1F29u48tjqYD9ZKqabn8JKrLrFn7WzykyeNY4i 4DWXaIJhHYyFtU6+s7mVsjgRPa474Gs= X-Google-Smtp-Source: ABdhPJzZbpxwneCyAF012dB97jHs7fdeootMPA96+c/JS4UFCvxVaef9WC/mJFOT3tvJq0xsc6sRTw== X-Received: by 2002:adf:f152:0:b0:20a:cb56:c20d with SMTP id y18-20020adff152000000b0020acb56c20dmr24137259wro.699.1651143459674; Thu, 28 Apr 2022 03:57:39 -0700 (PDT) Received: from 127.0.0.1localhost (82-132-230-8.dab.02.net. [82.132.230.8]) by smtp.gmail.com with ESMTPSA id z11-20020a7bc14b000000b0039419dfbb39sm7547wmi.33.2022.04.28.03.57.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 03:57:39 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next 07/11] udp/ipv6: clean up udpv6_sendmsg's saddr init Date: Thu, 28 Apr 2022 11:56:38 +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 10:56:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830414 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 987DEC433F5 for ; Thu, 28 Apr 2022 10:57:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344950AbiD1LBK (ORCPT ); Thu, 28 Apr 2022 07:01:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344954AbiD1LBA (ORCPT ); Thu, 28 Apr 2022 07:01:00 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C54D95A08; Thu, 28 Apr 2022 03:57:43 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id n32-20020a05600c3ba000b00393ea7192faso2805540wms.2; Thu, 28 Apr 2022 03:57:43 -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=qJj/oEv/OB0rSmn1HTfjjWX7JmMm0LqkE6Ny+wD7ffBQC9IwmtfWkhybcuDNEKLSXH 1TMbuqCT83AoqUhe0LltembCNXjptESab1BWgXO0WjFJpyHinrhpFfsU0pf5GxnCzss7 /iS3bE5EkMLqPCWo5ovhnxxIu4v4QAW+fXwCxiIBBWBlOIYJaxW8thByM0Wrab3KC4lJ tDxaDqVFn/gK4R+3UCX0j/0xuo26zp+gQtCONKguTflJCOt5OAYbqj9hUtdzfjP5AEnR +qr/l1lg3MIMDaXE8lRF0C/CS2I1wUWxxpzlzrmLSlHBhkF9g5diiUeOciwhICsMKRO/ AKMA== 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=23c5l4vL3Emz16QgrNQAPaBXA/gShOoeZ5X6x8XHX7LafE/B3eyOJdH0o4NcakfwR2 hka75KgkodibG83zAvhxwWwVrpZ1ZmkzGwHYihQnOQlGgDgzJ+K9Vc1v+g+Qfl6KJjR+ JQUtZrT/l7/F+fpptvZ40norkus+mWYEBd4N6uJ6VnBWVPKZObhDHTUkqL/myOaKbLpA yn6kfZGMIncvWK3tD1WmQZmohQtzc0QsYDSnnJTISySCCBpiOSlrQ/RXz1q99yggN3My joXz+0rUPw6lsHwUXrg0RJ5zSqaxg2hs+UzioOOMoX/6N53TdJUqjjSsAa4pliL60tXp VWhQ== X-Gm-Message-State: AOAM533PBcuSfqejjue6+ygf711/BzcSEH5z1xRKki9A0OvoqGOQMO6e 6nAyvqhSoLNQAGSqNwNbo439O0q2vjc= X-Google-Smtp-Source: ABdhPJySLzTTk7rY4bqmlhchQeKjsmfizffgksjQ+iy9cZrJzsT/UfZSHp9F6f2o7/6C5lHxwdGRkA== X-Received: by 2002:a05:600c:3ba8:b0:393:ea84:965d with SMTP id n40-20020a05600c3ba800b00393ea84965dmr19975408wms.35.1651143461820; Thu, 28 Apr 2022 03:57:41 -0700 (PDT) Received: from 127.0.0.1localhost (82-132-230-8.dab.02.net. [82.132.230.8]) by smtp.gmail.com with ESMTPSA id z11-20020a7bc14b000000b0039419dfbb39sm7547wmi.33.2022.04.28.03.57.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 03:57:41 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next 08/11] ipv6: partially inline fl6_update_dst() Date: Thu, 28 Apr 2022 11:56:39 +0100 Message-Id: <997b0b5bf91d23dc40e7002ab863ba2bd75a8ce9.1651071843.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 10:56:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830417 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 60089C433EF for ; Thu, 28 Apr 2022 10:58:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344979AbiD1LBU (ORCPT ); Thu, 28 Apr 2022 07:01:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344973AbiD1LBH (ORCPT ); Thu, 28 Apr 2022 07:01:07 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C73F19682C; Thu, 28 Apr 2022 03:57:48 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id l16-20020a05600c1d1000b00394011013e8so2147183wms.1; Thu, 28 Apr 2022 03:57: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=ul+t6uTHofyRjOEGXVcu4PlOdgwxB5M3MPuVkOzIQ1Y=; b=lgcr47LYHuUcL5xQnY6UqV7tiEtYMcg9xL6rPM6qQ5/1kMIpy8uzthRkZYEntaidTQ YTiKzGUDpNJBCvcbaz3sEdAQ/E5kTjL/Tr3PplQZeYeeJP5Rsk+O2UxwGi3myRBQdyuv SWfei+fWGf/UavE/7Djr+3F0SgypLR1JfpYi5Df8m5UU6Wv7MueGkUAJr8G06XxoI6/4 HnoagrX3bSUKfsvoXLenuNrZS0akIBHs3XQ+/5FuynJFOMFLiGi6GhDVnjnOZhY3mRHm mmPTWBPRspM7maLEoUAWUHbpu+zbwLgRFtnVASvmNkWWCuylKyxfjZvINkaJQxS3hVvF kMug== 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=RoJQkn30t1S00L9WMpMxiaLInEX5Z33q0yDr20eEQ2sAvWhnaijTcN71ozfwOkGSLy +iOsipfhkA+B8Lcscr2+YHD0v/OqkasLlGDGiyoZ9PkJbJtqWlAZZi5V/Z/qdH7vBlwR bkPTTRB2IKksEsSSzTGRX5SE5hTnxzARNui4BnTwFv4Xst0C9KDMEgznTxWxRps+B75d 6lXBlYM2mjNS0baHQrRy+0N4wDLdeQOWXaP0sKx924DmATzzUaj/ru6bwfBIh0pIVaHS 8uNJLSlUsa6xtLzsSXagvb0Qu5UCF5olEB35IUrorp30XQ9mpcYueWwzeyGWRIpp7TBU uREw== X-Gm-Message-State: AOAM530tu9b5AsAJGnspFLuBOkOXmQvTUeSaFJsV4p53R9iysIbhrXUb q/FEmPQCNO5Ry3L9TGNekvOk7X1VRg4= X-Google-Smtp-Source: ABdhPJx8Y2D2f/Xi/57abAfzd0IbqV4YPktjPWzO4FNV+bxENgJIR1hwPXMrm9C3A9oPLx3JIacvKw== X-Received: by 2002:a05:600c:240a:b0:394:18b:d722 with SMTP id 10-20020a05600c240a00b00394018bd722mr7736718wmp.177.1651143466987; Thu, 28 Apr 2022 03:57:46 -0700 (PDT) Received: from 127.0.0.1localhost (82-132-230-8.dab.02.net. [82.132.230.8]) by smtp.gmail.com with ESMTPSA id z11-20020a7bc14b000000b0039419dfbb39sm7547wmi.33.2022.04.28.03.57.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 03:57:46 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next 09/11] ipv6: refactor opts push in __ip6_make_skb() Date: Thu, 28 Apr 2022 11:56:42 +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 10:56:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830420 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 266F3C433FE for ; Thu, 28 Apr 2022 10:58:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344964AbiD1LBW (ORCPT ); Thu, 28 Apr 2022 07:01:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344898AbiD1LBI (ORCPT ); Thu, 28 Apr 2022 07:01:08 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9954972AE; Thu, 28 Apr 2022 03:57:51 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id d5so6239479wrb.6; Thu, 28 Apr 2022 03:57: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=e3JOSUJWrUPvCHFoWua5pWRqSGO0w+9yuqoonKqU/u4=; b=mDPURFRvtz4PhFAu8qIo7xONGmKaaJ1VGF+XLc5rVeQIHkiBZuUPMnoszpQdhGP/nm 6uA259+15VmUzF2PQ1Ud9xR1KFONke8O5UHSoKnSWiSYkErJMjn/9os2HW5rwEZX4PEl lIa36VWGJB/ee4bHEA0Y4T/ahYTPKrm9sI786Mxjl6uKbOOE9gS0bm4Ml8ltPesCcglf cSqGflL/7ovyqBOWK3abyM+ISleVto4aQamSG0YKAU1+cz5WzwtM5NXNsn1xUVpiCn6r M78WjKgJ/WoEYpNP85d/AV4DiB98sYf7Dt1rbYMfehProszzmyUBWfadbYlPUzEXxbZa MHxw== 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=EKuMH/rjUmbbiT6oNDcKIYYTuGvOvidf4h6HK+0a9nHrufllQFeT+38oBw3ortSSVL IHAZ++gq1PpaoDxh2VOsjHpOTKQq2vsEkcg/mtcI+jokuIjfQPeMFTeqI1SS2imH1q9d PKoD9NN+8EJOD6qdr/aHtaLPrBGZ0lfpmoMUz0HEd1giG2eXKLyBiu8dHED31vZkF5R2 QHeLydX7mgW5eZHQnTy00kyrLmZQtuQGJ4bhWwEOsjuFPiBeUOD+EMhUi8rOIqDikVfS haGKHlFkldrBCPwoQ6zHUikZ4DGhe7VFWbwivjcFGWUFLKZz8M4Bm0N+XlCZHladstbn py1w== X-Gm-Message-State: AOAM533myago58mHItelo09zu02xc8/Gweb8l0TeZKbSAehz/5rAKzdm ZYVGwCWPuv83FbExEOxvluK4nrGb4HU= X-Google-Smtp-Source: ABdhPJyBxMBcN7NdsSZPEmmbOLX0TGQiHoWZnbi0R19eR69wcusMSUZG/1ypQUyMJ9K8Rgn5jl+9sQ== X-Received: by 2002:a05:6000:18c9:b0:203:fb67:debe with SMTP id w9-20020a05600018c900b00203fb67debemr25692423wrq.494.1651143470257; Thu, 28 Apr 2022 03:57:50 -0700 (PDT) Received: from 127.0.0.1localhost (82-132-230-8.dab.02.net. [82.132.230.8]) by smtp.gmail.com with ESMTPSA id z11-20020a7bc14b000000b0039419dfbb39sm7547wmi.33.2022.04.28.03.57.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 03:57:49 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next 10/11] ipv6: improve opt-less __ip6_make_skb() Date: Thu, 28 Apr 2022 11:56:44 +0100 Message-Id: <2313cc1d1cdf89c58f327c1be02bd04834824551.1651071843.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 10:56:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830419 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 A30F7C433EF for ; Thu, 28 Apr 2022 10:58:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345016AbiD1LB2 (ORCPT ); Thu, 28 Apr 2022 07:01:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344983AbiD1LBJ (ORCPT ); Thu, 28 Apr 2022 07:01:09 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26092972C0; Thu, 28 Apr 2022 03:57:53 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id n126-20020a1c2784000000b0038e8af3e788so2801673wmn.1; Thu, 28 Apr 2022 03:57: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=YHrgbwGuKsi0qBohJI6HWm6IXg77xQmft6cGgAr+KkM=; b=geUv/xTB1yFlcqVhQ60GzWNNsG614lPO6/6WQ3DoVYqwbcGCewWErkE+ItiL8s7/6K Y0hz8OYfLZ++20kqDQybviBa6UMxi2i9Dhsfi66cWtpM33lKF1PJh/jTKRe/UTvv2UUt WLC8RqXNQ+OdlYOsNwX93WbIaVQS+VtVBi2q7e17IgClmTDWzwNA58FfL6z6bW8OAAoI XjZHIeqANnZH/2VvzzuoWzCdR09LTBSSw0dkaEl2NkVRW09GxelFWnLV8nN5CUVaIYTg xnuc+R/MZSFtl501LtAYGPpsa3paf8GEsFNZPckcr05S2r21xN2VafXUAZgg/M8bPEqe eYzQ== 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=XlFKFd/rhxKgL1KF/dkxP1GNkfpXQ6uWvq+iXTuSrlmiXyBjGRsbDot3qPwwX/ffVL 1MohPgXk9L6XeTjO9Y0uxMWzsdJSNsOm2KpMoaKgtA2blKQIXkRvFksEGxDU2tZ94Q/A cVCwqqNIj2NFCvAn2JY6P7l5d0xJ86Ra9tog2ohbf4qjl9MCtVXp6h7dRlSgorO8v/E6 we9kxksxVfxlDgWk1txECfRgy0tYh0syG8kbfhW3A2uMq03h5ZCE9HmlaPJHLEZE+9cG ttgJ6NzpPDyUIBmk0hX7YYxeP8mVHSQSps2d6y/L2HcHlUwU1I5oevIy0BrkPAAHpGvh gG8Q== X-Gm-Message-State: AOAM531uEIWml06VyEPjvUk6hoiwSv32Gt4LIXlZRDcp5N8C3Q63RMxF o1FpmhvpkXZ05UJFwLwrQ6B3T51ZTLs= X-Google-Smtp-Source: ABdhPJwqKexuoFcmDd5VUkrdgO/u39Kb2z+ybEnox+4E3+l/os8x31qvpzppMSlGlpdKWjQE98Oafg== X-Received: by 2002:a05:600c:3b26:b0:393:ec10:26fb with SMTP id m38-20020a05600c3b2600b00393ec1026fbmr17924924wms.69.1651143472044; Thu, 28 Apr 2022 03:57:52 -0700 (PDT) Received: from 127.0.0.1localhost (82-132-230-8.dab.02.net. [82.132.230.8]) by smtp.gmail.com with ESMTPSA id z11-20020a7bc14b000000b0039419dfbb39sm7547wmi.33.2022.04.28.03.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 03:57:51 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next 11/11] ipv6: clean up ip6_setup_cork Date: Thu, 28 Apr 2022 11:56:45 +0100 Message-Id: <683aab669ffa7db48416137c904a406a37e9a0c9.1651071843.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; }