Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1690810pxj; Wed, 19 May 2021 11:33:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNdiLZkXNT6/xlhza8k0aRvnp8HA3QQWfwTk0F0x3uQhK2su+vFidiYKdCLePNaKAvmxxY X-Received: by 2002:a17:906:3f86:: with SMTP id b6mr509839ejj.530.1621449203498; Wed, 19 May 2021 11:33:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621449203; cv=none; d=google.com; s=arc-20160816; b=WbZR23ms3UtGFir0msgoMX05OWFp8cpb5Vv9QR1XubnUljKO7nc+MB/rhJQwM/eSqc GQVLZ0j2WmC0OM1KCA+idakSkm5Cgv9FZEyuhreDkd0MrWdK0MKb35i0mzOEnLMl3t2B KEmsgzE8HlzPBN8DC8wBUSjEH13wSOdTasTyv6ChUZuCj2mNZKovTvP/GUOa2h76u5hq ccKQhu9s0uRcl3gRtzsjZTXoZzR3tLjvCXdloDTvTnFK4d3/xRwY6alaaFYrJ6JrcbGa HHSD2tMCM2i//uly7tLK5gOguCSWLXp6yTaUxlZsz8CJ4o796Sq1sBlQKHl+eXQhaf8t ADNw== 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=zuttx+ccp2WJpeVo41ApR4QzlKZXH0hmSVWBq1ylj1s=; b=MtW+9n/gO0qltxO+y1OPxpNdcAqQjd/zxZjjArr+Ik9vuhZOXjdWiSj1Kc7Afe/pDg 2EoaoJ2ALJOcqodXDZ5CGyg+hjdPw0PFp/xGW0GQK+YNtddxDv381Ljwex5R4ZT/Qc4z qbYljG73G2TRCLW9ceVNdVaaIN5NTOTa52suxCuuuv4HqEXoc2e0MUV2UpFg73DGAD67 41pIvuUEg0QzCckzMfqYDS/rACqqoHR/NsVCKuSFPtXRdxFAKcYxqrfA6mSSXoPGQO+x MRnsGzGyAsRJ+5t6YYkqfuEgeUaanQ5qnXBeVd0twvHIdCWWIdkGpWNxX9+krT5cTfek d8DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="r01H/LXo"; 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 ss5si390827ejb.294.2021.05.19.11.32.59; Wed, 19 May 2021 11:33:23 -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="r01H/LXo"; 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 S1345403AbhERTg6 (ORCPT + 99 others); Tue, 18 May 2021 15:36:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229813AbhERTg5 (ORCPT ); Tue, 18 May 2021 15:36:57 -0400 Received: from mail-yb1-xb35.google.com (mail-yb1-xb35.google.com [IPv6:2607:f8b0:4864:20::b35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12BECC061573 for ; Tue, 18 May 2021 12:35:39 -0700 (PDT) Received: by mail-yb1-xb35.google.com with SMTP id n83so3981878ybg.0 for ; Tue, 18 May 2021 12:35:39 -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=zuttx+ccp2WJpeVo41ApR4QzlKZXH0hmSVWBq1ylj1s=; b=r01H/LXoxE+CT6mAOiH2s+UHWFMDnVq1591tvNy96n2aTtUTSY3h/VaXnqcxl/iLGD OwLEiDdAFdMyB2IoSx470QJd9JbJlJQlhcb83zioeUI6+1X1MbEN7p1QyH53aQul3fnM RtE4CAAi3aiTCGFrqdhkyb3b16kTduuxExSy2Tj3hx+as9nD/9AnYnsPtgGKHjzhgFEp IjpWVi124kLu0c3v1bYtx4u/DoGXAM/MElIJaKaNgPzr0yHVFNydcw/WRC2aw59RW52Y TcQWBe3uFU9byEVB6foASvYYAuD0lKmOeNxb7gfPcAFU4CkOELZHQOJXkPmUIiGK9QeD 2WUg== 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=zuttx+ccp2WJpeVo41ApR4QzlKZXH0hmSVWBq1ylj1s=; b=PXqfHUqogDDzT3tFgZAJSyz6gx+4rmP65BjFlerv9ht/i4yJTjsmFfMsfNHoAREWpJ q6/yqmNCPo0nRdrxrk9UrIvL3imjFb71BPR8qwgebGOEXU9hPXihrvRkCOnBDhTzp6HP Bg0R0bzuuo858aRjxkbrzVJ/B+JptuCrx0i3LhGGjL2L0nALWbVCAVVDf5oEMN3oMSjs ILbmPYHPUdRW5m5F4DWTeBr/KYvNfWQUoLs/PxoTi5qR3EiE4wNxkV3MlBR+vbUOUdjw fhSUcVIh75xstuVJntF5JnJqRqwSvJCosFp1SNeFEB/GMSUvjI/9gZRBl5j9JDbYng5w +GYg== X-Gm-Message-State: AOAM5336gYxBzPtbeCO4thKCp9xZw5PpWjrLKlMUm/Qe0bc7Z6Yrb74q GhW0YRpUukBqbzTqv2c1RevL4v88a8F3WCX0eS/X6Ja4Zgw= X-Received: by 2002:a5b:711:: with SMTP id g17mr550659ybq.446.1621366537876; Tue, 18 May 2021 12:35:37 -0700 (PDT) MIME-Version: 1.0 References: <20210412084004.200986670@linuxfoundation.org> <20210412084005.653952525@linuxfoundation.org> <20210412051230-mutt-send-email-mst@kernel.org> In-Reply-To: <20210412051230-mutt-send-email-mst@kernel.org> From: Eric Dumazet Date: Tue, 18 May 2021 21:35:26 +0200 Message-ID: Subject: Re: [PATCH 5.4 042/111] virtio_net: Do not pull payload in skb->head To: "Michael S. Tsirkin" Cc: Greg Kroah-Hartman , LKML , stable@vger.kernel.org, Xuan Zhuo , Jason Wang , virtualization@lists.linux-foundation.org, "David S. Miller" , Sasha Levin Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 12, 2021 at 11:12 AM Michael S. Tsirkin wrote: > > On Mon, Apr 12, 2021 at 10:40:20AM +0200, Greg Kroah-Hartman wrote: > > From: Eric Dumazet > > > > [ Upstream commit 0f6925b3e8da0dbbb52447ca8a8b42b371aac7db ] > > > > Xuan Zhuo reported that commit 3226b158e67c ("net: avoid 32 x truesize > > under-estimation for tiny skbs") brought a ~10% performance drop. > > > > The reason for the performance drop was that GRO was forced > > to chain sk_buff (using skb_shinfo(skb)->frag_list), which > > uses more memory but also cause packet consumers to go over > > a lot of overhead handling all the tiny skbs. > > > > It turns out that virtio_net page_to_skb() has a wrong strategy : > > It allocates skbs with GOOD_COPY_LEN (128) bytes in skb->head, then > > copies 128 bytes from the page, before feeding the packet to GRO stack. > > > > This was suboptimal before commit 3226b158e67c ("net: avoid 32 x truesize > > under-estimation for tiny skbs") because GRO was using 2 frags per MSS, > > meaning we were not packing MSS with 100% efficiency. > > > > Fix is to pull only the ethernet header in page_to_skb() > > > > Then, we change virtio_net_hdr_to_skb() to pull the missing > > headers, instead of assuming they were already pulled by callers. > > > > This fixes the performance regression, but could also allow virtio_net > > to accept packets with more than 128bytes of headers. > > > > Many thanks to Xuan Zhuo for his report, and his tests/help. > > > > Fixes: 3226b158e67c ("net: avoid 32 x truesize under-estimation for tiny skbs") > > Reported-by: Xuan Zhuo > > Link: https://www.spinics.net/lists/netdev/msg731397.html > > Co-Developed-by: Xuan Zhuo > > Signed-off-by: Xuan Zhuo > > Signed-off-by: Eric Dumazet > > Cc: "Michael S. Tsirkin" > > Cc: Jason Wang > > Cc: virtualization@lists.linux-foundation.org > > Acked-by: Jason Wang > > Signed-off-by: David S. Miller > > Signed-off-by: Sasha Levin > > > Note that an issue related to this patch was recently reported. > It's quite possible that the root cause is a bug elsewhere > in the kernel, but it probably makes sense to defer the backport > until we know more ... I think the patch should be backported now, all issues have been sorted out ? > > > > --- > > drivers/net/virtio_net.c | 10 +++++++--- > > include/linux/virtio_net.h | 14 +++++++++----- > > 2 files changed, 16 insertions(+), 8 deletions(-) > > > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > > index b67460864b3c..d8ee001d8e8e 100644 > > --- a/drivers/net/virtio_net.c > > +++ b/drivers/net/virtio_net.c > > @@ -406,9 +406,13 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi, > > offset += hdr_padded_len; > > p += hdr_padded_len; > > > > - copy = len; > > - if (copy > skb_tailroom(skb)) > > - copy = skb_tailroom(skb); > > + /* Copy all frame if it fits skb->head, otherwise > > + * we let virtio_net_hdr_to_skb() and GRO pull headers as needed. > > + */ > > + if (len <= skb_tailroom(skb)) > > + copy = len; > > + else > > + copy = ETH_HLEN + metasize; > > skb_put_data(skb, p, copy); > > > > if (metasize) { > > diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h > > index 98775d7fa696..b465f8f3e554 100644 > > --- a/include/linux/virtio_net.h > > +++ b/include/linux/virtio_net.h > > @@ -65,14 +65,18 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb, > > skb_reset_mac_header(skb); > > > > if (hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) { > > - u16 start = __virtio16_to_cpu(little_endian, hdr->csum_start); > > - u16 off = __virtio16_to_cpu(little_endian, hdr->csum_offset); > > + u32 start = __virtio16_to_cpu(little_endian, hdr->csum_start); > > + u32 off = __virtio16_to_cpu(little_endian, hdr->csum_offset); > > + u32 needed = start + max_t(u32, thlen, off + sizeof(__sum16)); > > + > > + if (!pskb_may_pull(skb, needed)) > > + return -EINVAL; > > > > if (!skb_partial_csum_set(skb, start, off)) > > return -EINVAL; > > > > p_off = skb_transport_offset(skb) + thlen; > > - if (p_off > skb_headlen(skb)) > > + if (!pskb_may_pull(skb, p_off)) > > return -EINVAL; > > } else { > > /* gso packets without NEEDS_CSUM do not set transport_offset. > > @@ -102,14 +106,14 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb, > > } > > > > p_off = keys.control.thoff + thlen; > > - if (p_off > skb_headlen(skb) || > > + if (!pskb_may_pull(skb, p_off) || > > keys.basic.ip_proto != ip_proto) > > return -EINVAL; > > > > skb_set_transport_header(skb, keys.control.thoff); > > } else if (gso_type) { > > p_off = thlen; > > - if (p_off > skb_headlen(skb)) > > + if (!pskb_may_pull(skb, p_off)) > > return -EINVAL; > > } > > } > > -- > > 2.30.2 > > > > >