Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp620301rdh; Thu, 23 Nov 2023 13:25:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEx4cZZjyEevePD08sSFHQ+SkWRUCfpigfAMnbJh5lL7dlLrUS5B+Cdpdnvrvf1o3FXbaNj X-Received: by 2002:a17:902:da8b:b0:1cf:9ffa:db03 with SMTP id j11-20020a170902da8b00b001cf9ffadb03mr724235plx.26.1700774717980; Thu, 23 Nov 2023 13:25:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700774717; cv=none; d=google.com; s=arc-20160816; b=PoioaWA03mGd5B5MWzvOsB3xI9jN2BRgpN5R4u3xDw21PNu8hsKGOkd7eEE64QP5E2 oVMbe53HJEuFON6by+xDOzWPVIfStniG+DzoHFdZTO8NDhh20tMnXTg2lUdFewY5ZURm 1tXGCOTq0fG8DdCX3L1kDfSHejEf2IAdJxTsrJ9a/nwP3KO1qmGTVNjdY8kSYK5mDv7n y4r4xsOLWU84neMFpNry68n4kWmjOGU+MjIQ/APBGotRswFExPr36W4uVqyisga1iNy2 j9G9FQVgFzSZ5jET9sFZRr3hJR5rnbnqHC4E46fZvsyUEjZXdX5ALinF+lEHEir2a8UO A+VQ== 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:subject :references:in-reply-to:message-id:cc:to:from:date:dkim-signature; bh=06m9r8pewc3sAhhWhDQGbaOQDXI7LPtwjYRXQISAdy0=; fh=o34eI2G7szlr24SIsDdqffxZodvPnruFme6xaxm4/aY=; b=MRHjolYB2nrm6CsV9nxd/vep2YAyVg2/jZhOtyRC+a7JjYdlDZro+A564n/6XCluVP jzzpB03DeW8sSg9iofv9VinwdCpjQQs0oYX8hoJySCnMw970aJo0cJ0aq3kEF3yN88Tr Nod+jKJ3yorWu/x2jFh4sGfg9YTiJyhw2nHFEY84248a21DajgfOecKu3InmGZzLR3WL 8iuY2+sQKyd2rRH7ui6KXn1iNhgSyFL5WiaADFeZ9VYgghphlweIAaX6j4iCuX4lZdyn sXPU0NMT1YSHZNa+EZ1yoCaQPso478CVqQdo6tzZ+LRcMTFjZ3U1vvO0DASHi1T3jq6l mVKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FOziBpbm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id g6-20020a170902c38600b001c9af7debbasi1835755plg.520.2023.11.23.13.25.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 13:25:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FOziBpbm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 521C6828C4BC; Thu, 23 Nov 2023 13:25:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229477AbjKWVYz (ORCPT + 99 others); Thu, 23 Nov 2023 16:24:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjKWVYy (ORCPT ); Thu, 23 Nov 2023 16:24:54 -0500 Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FEAFD42; Thu, 23 Nov 2023 13:25:01 -0800 (PST) Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-3b845ba9ba9so740222b6e.3; Thu, 23 Nov 2023 13:25:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700774700; x=1701379500; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=06m9r8pewc3sAhhWhDQGbaOQDXI7LPtwjYRXQISAdy0=; b=FOziBpbmjKT9iRgjJNBxzFnOcZax01LXmuAEvbi+Ic88cNcKpLHqcplzesSWEIjHg7 w5kdOmY6i/0vRL66GGpgj8C+TYprZtJb/w9thXpxo7H3wgTkM3gYV3VALa0uMEzh3jbn UESqvhyh3p8ZJXbAD85NRxqC9NIRsEguMtdA7Jyom1dPCGErYZ9DFxJKgLukVnhZeIHM EpLHHv6oEKTWcLVw6qvHId3xlg2Gk1kWpDcMOlYoVO02iErqXQnhMLeyfKnnehfPu4fo abTiWU92LXU4c4B3uFBcxIJsH6uux3AvtCtA+ehjkw9zaAX9VC53kYUY7xb9K+xJGWI+ deWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700774700; x=1701379500; h=content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=06m9r8pewc3sAhhWhDQGbaOQDXI7LPtwjYRXQISAdy0=; b=Fev+g9/dw7pUOOsRSzUlM6zAy7ASv3kwjJ9vvA4p5X1VgqSW/Av8YCvEPUOazVcXlS 3aNMQz8PWviQyBOabom+dpUpqnhfn8qMWXdMgeuPnia3VDrkhKYTjEhqYzMzJuSnHkJB 18Sl8pywj4NFkD/ner4+mBmB7LiIaU4HcJwWDj5x3F9KP7w+MxpkaW5w0Wu8DlifQKq3 7MYVTNyd7a0Ta4cQkd+tPuA/VOUEfmAark9syaJZV3uCfirvqbsVxVn+ydTqOrUEBtKU oCHRImEJACMVi1X6vQfGf92P1F79ibAhA+lQ/15B8Gz9l2tjNnqPn2acU1yYWQ5WKgiA E+/A== X-Gm-Message-State: AOJu0YwEv5VXgS9ud7/2ncC2jRTLwwzwY3LBcl/KIcKJigXlMDS1UaeP BnRrvw1y5Fg48QAmaeaHJEI= X-Received: by 2002:a05:6808:20a4:b0:3af:585:402a with SMTP id s36-20020a05680820a400b003af0585402amr777803oiw.39.1700774700496; Thu, 23 Nov 2023 13:25:00 -0800 (PST) Received: from localhost (240.157.150.34.bc.googleusercontent.com. [34.150.157.240]) by smtp.gmail.com with ESMTPSA id o11-20020ae9f50b000000b0076cdc3b5beasm729367qkg.86.2023.11.23.13.24.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 13:24:59 -0800 (PST) Date: Thu, 23 Nov 2023 16:24:59 -0500 From: Willem de Bruijn To: Mike Pattrick , netdev@vger.kernel.org Cc: willemdebruijn.kernel@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, Mike Pattrick Message-ID: <655fc32bb506e_d14d4294b3@willemb.c.googlers.com.notmuch> In-Reply-To: <20231123183835.635210-1-mkp@redhat.com> References: <20231123183835.635210-1-mkp@redhat.com> Subject: Re: [PATCH net-next] packet: Account for VLAN_HLEN in csum_start when virtio_net_hdr is enabled Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 23 Nov 2023 13:25:15 -0800 (PST) Mike Pattrick wrote: > Af_packet provides checksum offload offsets to usermode applications > through struct virtio_net_hdr when PACKET_VNET_HDR is enabled on the > socket. For skbuffs with a vlan being sent to a SOCK_RAW socket, > af_packet will include the link level header and so csum_start needs > to be adjusted accordingly. Is this patch based on observing an incorrect offset in a workload, or on code inspection? As the referenced patch mentions, VLAN_HLEN adjustment is needed in macvtap because it pulls the vlan header from skb->vlan_tci. At which point skb->csum_start is wrong. "Commit f09e2249c4f5 ("macvtap: restore vlan header on user read") added this feature to macvtap. Commit 3ce9b20f1971 ("macvtap: Fix csum_start when VLAN tags are present") then fixed up csum_start." But the commit also mentions "Virtio, packet and uml do not insert the vlan header in the user buffer.". This situation has not changed. Packet sockets may receive packets with VLAN headers present, but unless they were inserted manually before passing to user, as macvtap does, this does not affect csum_start. Packet sockets support reading those skb->vlan_tci stored VLAN headers using AUXDATA. > Fixes: fd3a88625844 ("net: in virtio_net_hdr only add VLAN_HLEN to csum_start if payload holds vlan") The fix should target net, not net-next. > Signed-off-by: Mike Pattrick > --- > net/packet/af_packet.c | 36 ++++++++++++++++++++++++++---------- > 1 file changed, 26 insertions(+), 10 deletions(-) > > diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c > index a84e00b5904b..f6b602ffe383 100644 > --- a/net/packet/af_packet.c > +++ b/net/packet/af_packet.c > @@ -2092,15 +2092,23 @@ static unsigned int run_filter(struct sk_buff *skb, > } > > static int packet_rcv_vnet(struct msghdr *msg, const struct sk_buff *skb, > - size_t *len, int vnet_hdr_sz) > + size_t *len, int vnet_hdr_sz, > + const struct sock *sk) > { > struct virtio_net_hdr_mrg_rxbuf vnet_hdr = { .num_buffers = 0 }; > + int vlan_hlen; > > if (*len < vnet_hdr_sz) > return -EINVAL; > *len -= vnet_hdr_sz; > > - if (virtio_net_hdr_from_skb(skb, (struct virtio_net_hdr *)&vnet_hdr, vio_le(), true, 0)) > + if (sk->sk_type == SOCK_RAW && skb_vlan_tag_present(skb)) > + vlan_hlen = VLAN_HLEN; > + else > + vlan_hlen = 0; > + > + if (virtio_net_hdr_from_skb(skb, (struct virtio_net_hdr *)&vnet_hdr, > + vio_le(), true, vlan_hlen)) > return -EINVAL; > > return memcpy_to_msg(msg, (void *)&vnet_hdr, vnet_hdr_sz); > @@ -2368,13 +2376,21 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, > __set_bit(slot_id, po->rx_ring.rx_owner_map); > } > > - if (vnet_hdr_sz && > - virtio_net_hdr_from_skb(skb, h.raw + macoff - > - sizeof(struct virtio_net_hdr), > - vio_le(), true, 0)) { > - if (po->tp_version == TPACKET_V3) > - prb_clear_blk_fill_status(&po->rx_ring); > - goto drop_n_account; > + if (vnet_hdr_sz) { > + int vlan_hlen; > + > + if (sk->sk_type == SOCK_RAW && skb_vlan_tag_present(skb)) > + vlan_hlen = VLAN_HLEN; > + else > + vlan_hlen = 0; > + > + if (virtio_net_hdr_from_skb(skb, h.raw + macoff - > + sizeof(struct virtio_net_hdr), > + vio_le(), true, vlan_hlen)) { > + if (po->tp_version == TPACKET_V3) > + prb_clear_blk_fill_status(&po->rx_ring); > + goto drop_n_account; > + } > } > > if (po->tp_version <= TPACKET_V2) { > @@ -3464,7 +3480,7 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, > packet_rcv_try_clear_pressure(pkt_sk(sk)); > > if (vnet_hdr_len) { > - err = packet_rcv_vnet(msg, skb, &len, vnet_hdr_len); > + err = packet_rcv_vnet(msg, skb, &len, vnet_hdr_len, sk); > if (err) > goto out_free; > } > -- > 2.40.1 >