Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2488145pxb; Mon, 19 Apr 2021 06:57:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgBtBf/Ci36fyrClaEI0PADzwZ3TbwXFiw7jlC1lLgoRK/r3+cyUTno8dfdH6Lmy0W09mJ X-Received: by 2002:aa7:db14:: with SMTP id t20mr25110176eds.311.1618840677809; Mon, 19 Apr 2021 06:57:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618840677; cv=none; d=google.com; s=arc-20160816; b=hYQS5/d+G50u6Nw+cP/U4L5YWaVVovPFTNTarQ7LsKfEno+L7SnV5bOP7RYRhl2pCb cng0eRNGn0nLrCb+Ae/uKhYofSNphttmgsMIGajZJ4UGM99aDVtjyTx9D1BGPWrfwQQq lgf5nlm/ucZ+YFJILo4bC87fQjVWUqxn3ANYYidRehz6jplYopb9R9dooEAK0fv8RvbI /T38Zxv/c/1GnJ3Hu+E7MFo03cBXYJ2Xc9ew63qi6F4yZd/lCZgqye9RY+uGjP/VQHM0 dUDw7MvTMwx3wEUFpv6L2OYo2RZ5JAAgynZo+vS7ux/5CI9HJ4OLmxkWZCkJPgCFzs3D hRrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:subject:reply-to:cc:from:to:dkim-signature:date; bh=dPP56wqBhSWGV3YL8whhYttyE2wvgRvYvvsmV73KBL8=; b=Un3EBITLzHhehLNQ2I3iq7+djfbiya9T4VVnftzVlRHbSqjbxir3NV8f9x2m8ZDFN3 3uXy6Pfk4nmDNWs/LmCpdWfAcQ3ZHunR0bjC7yjgSHBZe1rmRaDdc7eKfaFqnAXqKFYb 4bm7Qt15UFFCGlDO20BOBCLVp6+kQSr4IVGqq34qP/9d5yRVqCoC7RHA6+GPeH0PLd9f tATA4xPFcALiWHZg49gVdH/d15CJ/u2CVpM8o4FQh1pRYm54BnA3gJhg5oH/H2zWk5GI oFMhdmx6QQ88zV7IS3r4WdxFUVjQU3TQu7u+ILkHrruKRROrdzwBMx6gJ87Qw2Kc4lEd gGUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=VQ66dxJg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o4si7173281edv.69.2021.04.19.06.57.34; Mon, 19 Apr 2021 06:57:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=VQ66dxJg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239243AbhDSMxo (ORCPT + 99 others); Mon, 19 Apr 2021 08:53:44 -0400 Received: from mail1.protonmail.ch ([185.70.40.18]:55506 "EHLO mail1.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239146AbhDSMxm (ORCPT ); Mon, 19 Apr 2021 08:53:42 -0400 Date: Mon, 19 Apr 2021 12:53:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1618836790; bh=dPP56wqBhSWGV3YL8whhYttyE2wvgRvYvvsmV73KBL8=; h=Date:To:From:Cc:Reply-To:Subject:From; b=VQ66dxJg3jgoswOeS3xpbnyhVPlSx8ucuj1ksjlNOOEm1PAZ7p54Pl38zGyj0yhSC weNZ1pV5AHdYHe8RGcfslkMoXPH3iTM6wcGayltsEZRL1fSUEzKnI99XR63YTX6J7f KBysTMm8eenjEa+1jAYcNIz9zrJT94N3/b9iDbz/0ZpKspsum/rVG36N0LBBo05+7b wXC9hL4cuuEoMBAAIQpnxOOi1A099a/6ZrPtStRk3uE9yZBXwonGggrrSyORve9uf6 3yNaBVTRR0j/ckeysM74vKK3D6FDOjqmgg4R9w7nWx4JgfdulIVamP2yyejE0QxEBO Q+yc4k37PiHAw== To: "David S. Miller" , Jakub Kicinski From: Alexander Lobakin Cc: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Eric Dumazet , Wei Wang , Cong Wang , Taehee Yoo , =?utf-8?Q?Bj=C3=B6rn_T=C3=B6pel?= , "Michael S. Tsirkin" , Alexander Lobakin , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Reply-To: Alexander Lobakin Subject: [PATCH v2 net] gro: fix napi_gro_frags() Fast GRO breakage due to IP alignment check Message-ID: <20210419125258.5969-1-alobakin@pm.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 38ec4944b593 ("gro: ensure frag0 meets IP header alignment") did the right thing, but missed the fact that napi_gro_frags() logics calls for skb_gro_reset_offset() *before* pulling Ethernet header to the skb linear space. That said, the introduced check for frag0 address being aligned to 4 always fails for it as Ethernet header is obviously 14 bytes long, and in case with NET_IP_ALIGN its start is not aligned to 4. Fix this by adding @nhoff argument to skb_gro_reset_offset() which tells if an IP header is placed right at the start of frag0 or not. This restores Fast GRO for napi_gro_frags() that became very slow after the mentioned commit, and preserves the introduced check to avoid silent unaligned accesses. From v1 [0]: - inline tiny skb_gro_reset_offset() to let the code be optimized more efficively (esp. for the !NET_IP_ALIGN case) (Eric); - pull in Reviewed-by from Eric. [0] https://lore.kernel.org/netdev/20210418114200.5839-1-alobakin@pm.me Fixes: 38ec4944b593 ("gro: ensure frag0 meets IP header alignment") Reviewed-by: Eric Dumazet Signed-off-by: Alexander Lobakin --- net/core/dev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 1f79b9aa9a3f..15fe36332fb8 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5914,7 +5914,7 @@ static struct list_head *gro_list_prepare(struct napi= _struct *napi, =09return head; } -static void skb_gro_reset_offset(struct sk_buff *skb) +static inline void skb_gro_reset_offset(struct sk_buff *skb, u32 nhoff) { =09const struct skb_shared_info *pinfo =3D skb_shinfo(skb); =09const skb_frag_t *frag0 =3D &pinfo->frags[0]; @@ -5925,7 +5925,7 @@ static void skb_gro_reset_offset(struct sk_buff *skb) =09if (!skb_headlen(skb) && pinfo->nr_frags && =09 !PageHighMem(skb_frag_page(frag0)) && -=09 (!NET_IP_ALIGN || !(skb_frag_off(frag0) & 3))) { +=09 (!NET_IP_ALIGN || !((skb_frag_off(frag0) + nhoff) & 3))) { =09=09NAPI_GRO_CB(skb)->frag0 =3D skb_frag_address(frag0); =09=09NAPI_GRO_CB(skb)->frag0_len =3D min_t(unsigned int, =09=09=09=09=09=09 skb_frag_size(frag0), @@ -6143,7 +6143,7 @@ gro_result_t napi_gro_receive(struct napi_struct *nap= i, struct sk_buff *skb) =09skb_mark_napi_id(skb, napi); =09trace_napi_gro_receive_entry(skb); -=09skb_gro_reset_offset(skb); +=09skb_gro_reset_offset(skb, 0); =09ret =3D napi_skb_finish(napi, skb, dev_gro_receive(napi, skb)); =09trace_napi_gro_receive_exit(ret); @@ -6232,7 +6232,7 @@ static struct sk_buff *napi_frags_skb(struct napi_str= uct *napi) =09napi->skb =3D NULL; =09skb_reset_mac_header(skb); -=09skb_gro_reset_offset(skb); +=09skb_gro_reset_offset(skb, hlen); =09if (unlikely(skb_gro_header_hard(skb, hlen))) { =09=09eth =3D skb_gro_header_slow(skb, hlen, 0); -- 2.31.1