Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2363574pxb; Mon, 19 Apr 2021 04:08:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6I8Z5fIvbXp3BDaFI1cJNhQQFO5UUzVdrszoC2ftVm3DkvtC0JE6rteWZItBsoyniHlup X-Received: by 2002:a17:90a:684b:: with SMTP id e11mr10307409pjm.87.1618830484087; Mon, 19 Apr 2021 04:08:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618830484; cv=none; d=google.com; s=arc-20160816; b=U+1YIqBJCqt2LF+eclDM3HRKmYVw7klSZCCEfc/sYotx2OtN2hnVjL15QnFsv44ELP weiLtuTfoqh6AKvQCnlHgh7JgJxKlP4KwgOjKwUdCBk+Ge8u1U78jRjsJ63CSGnwqoj5 wFj0VSsf3041kdAYXtQjdxv7ny3z2NzwlwxVFBHDEoo8YYtZ/tdx5DZElDXk26l54z9g g3MnRM7ns7Ypw1UrFilT9zNmBZXQbKBND6QluXGkrMIQsdJetSQSw1FNnh+nrirxE8vN f3Yg7AsFBoYPChgcrwMsGGeYbARrY9W57cIio18KFeXbZetfsd/DT2sYgsPMHCVGhoKt YilQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=5LqvcoPM7aAQAIxRhAZ6fd0FECC20Osn+I0reTRncUE=; b=RVbu2TFHzDQp46YUKxDlQkKeHDuvLniAHfGnBfxtzr4xb5kRw4lBMOXXW/Ft9EnVgz hlanqvQi6Aa+NvdyKNrV+hy9IMbdRAykewYiRT92yd4i4+NeC/w8Vfl2CqFcSWTVTzge kNvXC3scvNaRTeSztRONSJ3XdSm1yqMla2BASO8bW8mbpuLw2BCSgNR/PNSNXXgHA9zc Ie27dx2huNOc4gNXxzblT6wzBit37AJ+b4dNRecGTtl3nSc5312iY9VmIuoUOgVYDB0X 3eP4J5S0bkhJaX468GRP14lq14fKzLEsVa4GzI8NILhCfrWOawNIoslFkFVbxhTKXiqJ dQmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZO9NymKa; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x12si10787185pla.150.2021.04.19.04.07.51; Mon, 19 Apr 2021 04:08:04 -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=@google.com header.s=20161025 header.b=ZO9NymKa; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234399AbhDSLGC (ORCPT + 99 others); Mon, 19 Apr 2021 07:06:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233862AbhDSLF7 (ORCPT ); Mon, 19 Apr 2021 07:05:59 -0400 Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68712C06174A for ; Mon, 19 Apr 2021 04:05:28 -0700 (PDT) Received: by mail-yb1-xb34.google.com with SMTP id v3so35872284ybi.1 for ; Mon, 19 Apr 2021 04:05:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5LqvcoPM7aAQAIxRhAZ6fd0FECC20Osn+I0reTRncUE=; b=ZO9NymKa3LAaawzpOVdexZjSPKp7U4zlElcQBLoqnCDOfmv6CHMcl+Ky0yOyC/AKTc pMtDB4EK2xiMgC3dP5Wtc+dcMGECpkOkSVC3VJ3XonC1vCIbxXjyAYCigsdcNV99x+FN 0NQpXD3+LMz8vsuC1Azj2wVtf2eF68H93ZnL4GB367BO3bDo9cpMc03nGXRK7hwAMxHp mDp8LqQbyc9N+kerBezoq7+coFvdzx/D59UvMJbZv1j+9+RgCSSkbaAuZplSXd2OjG0X evW7lTD7gilOR8VAB5y2M50wCmx+1ws658G/WCiyegX2LnsQGtnKBAApl08QNHL2wHq9 lFJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5LqvcoPM7aAQAIxRhAZ6fd0FECC20Osn+I0reTRncUE=; b=MwA2bidpkCj7wXtPSOd27WHNAmLljP1ZEO5RleQdQIVQpgxhr8s1MyKZfsoME+9WMJ hga+jBTplNJ2KAc6pHiWMgjLkhMXqFaPeu1UJqyZCEVA6VIkfjZD9S5/Rhn4OtKlkwXE L7IbsMHoyVZDs4Q8d+4tTs0pa3z64Akoajv258Gjj93I4tefbp+wvRC0BTAAJLvGc66q S442wi9lOuHJuM8edP7A6+eQxhgpALTm5yhJyFHWJ0MpM5D0v3Z+N+8gx8ZczpD1JzxY Qxe3I9waBUVKvaLoqtmmhlhYiyqkWqslA683e4zd7ESfXibE1O6f4PyOhOfjvEjMB4Hq 3MGg== X-Gm-Message-State: AOAM531NVeSOBaGvvsL0NhCLc5wd/+B/e4dgv3h1gfa9RlkCBxj1024o zrjHFZJVkGr9oCR+r4Av4tpOPjt/TVgejUi72Uj5Kw== X-Received: by 2002:a25:850b:: with SMTP id w11mr16207623ybk.518.1618830327412; Mon, 19 Apr 2021 04:05:27 -0700 (PDT) MIME-Version: 1.0 References: <20210418114200.5839-1-alobakin@pm.me> In-Reply-To: <20210418114200.5839-1-alobakin@pm.me> From: Eric Dumazet Date: Mon, 19 Apr 2021 13:05:16 +0200 Message-ID: Subject: Re: [PATCH net] gro: fix napi_gro_frags() Fast GRO breakage due to IP alignment check To: Alexander Lobakin Cc: "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Wei Wang , Cong Wang , Taehee Yoo , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , "Michael S. Tsirkin" , netdev , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Apr 18, 2021 at 1:43 PM Alexander Lobakin wrote: > > 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. > > Fixes: 38ec4944b593 ("gro: ensure frag0 meets IP header alignment") > 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..965d5f9b6fee 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, > return head; > } > > -static void skb_gro_reset_offset(struct sk_buff *skb) > +static void skb_gro_reset_offset(struct sk_buff *skb, u32 nhoff) > { > const struct skb_shared_info *pinfo = skb_shinfo(skb); > const skb_frag_t *frag0 = &pinfo->frags[0]; > @@ -5925,7 +5925,7 @@ static void skb_gro_reset_offset(struct sk_buff *skb) > > if (!skb_headlen(skb) && pinfo->nr_frags && > !PageHighMem(skb_frag_page(frag0)) && > - (!NET_IP_ALIGN || !(skb_frag_off(frag0) & 3))) { > + (!NET_IP_ALIGN || !((skb_frag_off(frag0) + nhoff) & 3))) { > NAPI_GRO_CB(skb)->frag0 = skb_frag_address(frag0); > NAPI_GRO_CB(skb)->frag0_len = min_t(unsigned int, > skb_frag_size(frag0), > @@ -6143,7 +6143,7 @@ gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb) > skb_mark_napi_id(skb, napi); > trace_napi_gro_receive_entry(skb); > > - skb_gro_reset_offset(skb); > + skb_gro_reset_offset(skb, 0); > > ret = napi_skb_finish(napi, skb, dev_gro_receive(napi, skb)); > trace_napi_gro_receive_exit(ret); > @@ -6232,7 +6232,7 @@ static struct sk_buff *napi_frags_skb(struct napi_struct *napi) > napi->skb = NULL; > > skb_reset_mac_header(skb); > - skb_gro_reset_offset(skb); > + skb_gro_reset_offset(skb, hlen); > > if (unlikely(skb_gro_header_hard(skb, hlen))) { > eth = skb_gro_header_slow(skb, hlen, 0); > -- > 2.31.1 > > Good catch, thanks. This has the unfortunate effect of increasing code length on x86, maybe we should have an exception to normal rules so that skb_gro_reset_offset() is inlined. Reviewed-by: Eric Dumazet