From nobody Tue Feb 10 19:48:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1681969763; cv=none; d=zohomail.com; s=zohoarc; b=HiqWIj8l31RGTShTtwtXInHD2tw5X8C2iUWKaRvFYs3l+h0lCsw3q/VsFKmQYt0QjeY4T7mappDSRAxCEG/ZLhlJDJontlnHkRco9jY3X2jEz2pCje28KIdhETwNyOQxC7I9w1xTgX5/Ep920/Jrs48z+EM8GLTY28LuaBpiEVA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681969763; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject; bh=v/nrEX4P5E15OsBCheTj+PJDTAJleMbN2kLPc8cL6pw=; b=Y+cIfqMZAKb0q/N/Nt/AjaVtPhjByrFZCIml2RQZBqnEau76U63StijZC5BTZMLiF/CR7jkg+rGDTxIBoXB5Z5MyU+UHtdyNU1bMRy9+csGZPJZXFS3Z6RT8UD6fZTVxLFi2/1oN1PS+e1ZGhSxrisyg9iZhRZXbMPaBNMRn/S0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16819697632391004.5614727775405; Wed, 19 Apr 2023 22:49:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppN9N-0006sw-HW; Thu, 20 Apr 2023 01:48:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppN9G-0006sX-T0 for qemu-devel@nongnu.org; Thu, 20 Apr 2023 01:48:06 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppN9E-00015K-0q for qemu-devel@nongnu.org; Thu, 20 Apr 2023 01:48:02 -0400 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-247122e9845so401981a91.0 for ; Wed, 19 Apr 2023 22:47:59 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:4457:c267:5e09:481b]) by smtp.gmail.com with ESMTPSA id x15-20020a17090a46cf00b00247164c1947sm2769255pjg.0.2023.04.19.22.47.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 22:47:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1681969679; x=1684561679; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v/nrEX4P5E15OsBCheTj+PJDTAJleMbN2kLPc8cL6pw=; b=QF8i2NOaB3Hb1fYgkJRbVs7Q7P5NliQx1g3d6GZlkP1OE1X20cfJdV+dHPyEy2ViEM f89TAlgC/mDQ7Am3SEc9mGQuOuEdyVTdAehUKfq8+c4N4FL994ZpdpWaguhm2S2M274s inx3f+8yFymKNIuqtJw2021n04d23zM6YLocXMcJ2/fj9J/gynsHKeGRmhjcqFTVq4My B98eC1v34oxM8tE92SuOILFVXCM77K5UvWCMkRXXPVaXY+vczHsiAsDjOcA2egk6boRQ wEJJ8ISekyuEhN2gCArI2MM1Atcr8JEhQFa+6ctpJaOuQK2QfqwKCOsl24khhjZt+1V5 +M0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681969679; x=1684561679; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v/nrEX4P5E15OsBCheTj+PJDTAJleMbN2kLPc8cL6pw=; b=O3jlZhNW4hrPkvuv7t0JTiALGTL+FG/ptywvk2l0DxFP9H4czophgU7aa31bnAentb 7cUhnaaoU9fb6n89cPn5KSSLEcNpF45WTjXAE0KWA9Bicuzhgj5HmauaWviDrzDELuZn msx6gFPOiUQAUymbr9ri101M6BOGlwBVXabDMwPzkpVHYKe2EXpWy+DoKcvP9Da552NX /yCc5p9rjwVyt3EFPM10x6nZMDQD65naQElLtOTDKNbNjk30hDopX9xHwhLmhRPPlLtK iIkGZRv/Bktj8EHOQN3+EorW0tCT2zSSTo5PCN9f5M1YX590sbnn1kBZ1LQtazoEGZHN CpWw== X-Gm-Message-State: AAQBX9d3ZdOmKXhwKjSPruRKQf8dQ5qqvFNQTC8qkC9wO0Zbgm6YOZ1f m8PjpGbWVrE72vR2q5LXNkFylw== X-Google-Smtp-Source: AKy350ZhftYITfKxX7ZL7d4rF2gitscOiX2kd0t7MKsJo784VnkEcC31Vn+KOK77AWYxMIniLbLoew== X-Received: by 2002:a17:90b:3507:b0:246:8f9b:d28e with SMTP id ls7-20020a17090b350700b002468f9bd28emr565708pjb.18.1681969678696; Wed, 19 Apr 2023 22:47:58 -0700 (PDT) From: Akihiko Odaki To: Cc: Sriram Yagnaraman , Jason Wang , Dmitry Fleytman , "Michael S . Tsirkin" , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Wainer dos Santos Moschetta , Beraldo Leal , Cleber Rosa , Laurent Vivier , Paolo Bonzini , qemu-devel@nongnu.org, Tomasz Dzieciol , Akihiko Odaki Subject: [PATCH v2 06/41] net/net_rx_pkt: Use iovec for net_rx_pkt_set_protocols() Date: Thu, 20 Apr 2023 14:46:22 +0900 Message-Id: <20230420054657.50367-7-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230420054657.50367-1-akihiko.odaki@daynix.com> References: <20230420054657.50367-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::102d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x102d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1681969764187100003 Content-Type: text/plain; charset="utf-8" igb does not properly ensure the buffer passed to net_rx_pkt_set_protocols() is contiguous for the entire L2/L3/L4 header. Allow it to pass scattered data to net_rx_pkt_set_protocols(). Fixes: 3a977deebe ("Intrdocue igb device emulation") Signed-off-by: Akihiko Odaki Reviewed-by: Sriram Yagnaraman --- hw/net/net_rx_pkt.h | 10 ++++++---- include/net/eth.h | 6 +++--- hw/net/igb_core.c | 2 +- hw/net/net_rx_pkt.c | 14 +++++--------- hw/net/virtio-net.c | 7 +++++-- hw/net/vmxnet3.c | 7 ++++++- net/eth.c | 18 ++++++++---------- 7 files changed, 34 insertions(+), 30 deletions(-) diff --git a/hw/net/net_rx_pkt.h b/hw/net/net_rx_pkt.h index d00b484900..a06f5c2675 100644 --- a/hw/net/net_rx_pkt.h +++ b/hw/net/net_rx_pkt.h @@ -55,12 +55,14 @@ size_t net_rx_pkt_get_total_len(struct NetRxPkt *pkt); * parse and set packet analysis results * * @pkt: packet - * @data: pointer to the data buffer to be parsed - * @len: data length + * @iov: received data scatter-gather list + * @iovcnt: number of elements in iov + * @iovoff: data start offset in the iov * */ -void net_rx_pkt_set_protocols(struct NetRxPkt *pkt, const void *data, - size_t len); +void net_rx_pkt_set_protocols(struct NetRxPkt *pkt, + const struct iovec *iov, size_t iovcnt, + size_t iovoff); =20 /** * fetches packet analysis results diff --git a/include/net/eth.h b/include/net/eth.h index c5ae4493b4..9f19c3a695 100644 --- a/include/net/eth.h +++ b/include/net/eth.h @@ -312,10 +312,10 @@ eth_get_l2_hdr_length(const void *p) } =20 static inline uint32_t -eth_get_l2_hdr_length_iov(const struct iovec *iov, int iovcnt) +eth_get_l2_hdr_length_iov(const struct iovec *iov, size_t iovcnt, size_t i= ovoff) { uint8_t p[sizeof(struct eth_header) + sizeof(struct vlan_header)]; - size_t copied =3D iov_to_buf(iov, iovcnt, 0, p, ARRAY_SIZE(p)); + size_t copied =3D iov_to_buf(iov, iovcnt, iovoff, p, ARRAY_SIZE(p)); =20 if (copied < ARRAY_SIZE(p)) { return copied; @@ -397,7 +397,7 @@ typedef struct eth_l4_hdr_info_st { bool has_tcp_data; } eth_l4_hdr_info; =20 -void eth_get_protocols(const struct iovec *iov, int iovcnt, +void eth_get_protocols(const struct iovec *iov, size_t iovcnt, size_t iovo= ff, bool *hasip4, bool *hasip6, size_t *l3hdr_off, size_t *l4hdr_off, diff --git a/hw/net/igb_core.c b/hw/net/igb_core.c index 96a118b6c1..62d10f971e 100644 --- a/hw/net/igb_core.c +++ b/hw/net/igb_core.c @@ -1650,7 +1650,7 @@ igb_receive_internal(IGBCore *core, const struct iove= c *iov, int iovcnt, =20 ehdr =3D PKT_GET_ETH_HDR(filter_buf); net_rx_pkt_set_packet_type(core->rx_pkt, get_eth_packet_type(ehdr)); - net_rx_pkt_set_protocols(core->rx_pkt, filter_buf, size); + net_rx_pkt_set_protocols(core->rx_pkt, iov, iovcnt, iov_ofs); =20 queues =3D igb_receive_assign(core, ehdr, size, &rss_info, external_tx= ); if (!queues) { diff --git a/hw/net/net_rx_pkt.c b/hw/net/net_rx_pkt.c index 39cdea06de..63be6e05ad 100644 --- a/hw/net/net_rx_pkt.c +++ b/hw/net/net_rx_pkt.c @@ -103,7 +103,7 @@ net_rx_pkt_pull_data(struct NetRxPkt *pkt, iov, iovcnt, ploff, pkt->tot_len); } =20 - eth_get_protocols(pkt->vec, pkt->vec_len, &pkt->hasip4, &pkt->hasip6, + eth_get_protocols(pkt->vec, pkt->vec_len, 0, &pkt->hasip4, &pkt->hasip= 6, &pkt->l3hdr_off, &pkt->l4hdr_off, &pkt->l5hdr_off, &pkt->ip6hdr_info, &pkt->ip4hdr_info, &pkt->l4hdr_in= fo); =20 @@ -186,17 +186,13 @@ size_t net_rx_pkt_get_total_len(struct NetRxPkt *pkt) return pkt->tot_len; } =20 -void net_rx_pkt_set_protocols(struct NetRxPkt *pkt, const void *data, - size_t len) +void net_rx_pkt_set_protocols(struct NetRxPkt *pkt, + const struct iovec *iov, size_t iovcnt, + size_t iovoff) { - const struct iovec iov =3D { - .iov_base =3D (void *)data, - .iov_len =3D len - }; - assert(pkt); =20 - eth_get_protocols(&iov, 1, &pkt->hasip4, &pkt->hasip6, + eth_get_protocols(iov, iovcnt, iovoff, &pkt->hasip4, &pkt->hasip6, &pkt->l3hdr_off, &pkt->l4hdr_off, &pkt->l5hdr_off, &pkt->ip6hdr_info, &pkt->ip4hdr_info, &pkt->l4hdr_in= fo); } diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 53e1c32643..37551fd854 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1835,9 +1835,12 @@ static int virtio_net_process_rss(NetClientState *nc= , const uint8_t *buf, VIRTIO_NET_HASH_REPORT_UDPv6, VIRTIO_NET_HASH_REPORT_UDPv6_EX }; + struct iovec iov =3D { + .iov_base =3D (void *)buf, + .iov_len =3D size + }; =20 - net_rx_pkt_set_protocols(pkt, buf + n->host_hdr_len, - size - n->host_hdr_len); + net_rx_pkt_set_protocols(pkt, &iov, 1, n->host_hdr_len); net_rx_pkt_get_protocols(pkt, &hasip4, &hasip6, &l4hdr_proto); net_hash_type =3D virtio_net_get_hash_type(hasip4, hasip6, l4hdr_proto, n->rss_data.hash_types); diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c index 9acff310e7..05f41b6dfa 100644 --- a/hw/net/vmxnet3.c +++ b/hw/net/vmxnet3.c @@ -2001,7 +2001,12 @@ vmxnet3_receive(NetClientState *nc, const uint8_t *b= uf, size_t size) get_eth_packet_type(PKT_GET_ETH_HDR(buf))); =20 if (vmxnet3_rx_filter_may_indicate(s, buf, size)) { - net_rx_pkt_set_protocols(s->rx_pkt, buf, size); + struct iovec iov =3D { + .iov_base =3D (void *)buf, + .iov_len =3D size + }; + + net_rx_pkt_set_protocols(s->rx_pkt, &iov, 1, 0); vmxnet3_rx_need_csum_calculate(s->rx_pkt, buf, size); net_rx_pkt_attach_data(s->rx_pkt, buf, size, s->rx_vlan_stripping); bytes_indicated =3D vmxnet3_indicate_packet(s) ? size : -1; diff --git a/net/eth.c b/net/eth.c index 70bcd8e355..d7b30df79f 100644 --- a/net/eth.c +++ b/net/eth.c @@ -136,7 +136,7 @@ _eth_tcp_has_data(bool is_ip4, return l4len > TCP_HEADER_DATA_OFFSET(tcp); } =20 -void eth_get_protocols(const struct iovec *iov, int iovcnt, +void eth_get_protocols(const struct iovec *iov, size_t iovcnt, size_t iovo= ff, bool *hasip4, bool *hasip6, size_t *l3hdr_off, size_t *l4hdr_off, @@ -147,26 +147,24 @@ void eth_get_protocols(const struct iovec *iov, int i= ovcnt, { int proto; bool fragment =3D false; - size_t l2hdr_len =3D eth_get_l2_hdr_length_iov(iov, iovcnt); size_t input_size =3D iov_size(iov, iovcnt); size_t copied; uint8_t ip_p; =20 *hasip4 =3D *hasip6 =3D false; + *l3hdr_off =3D iovoff + eth_get_l2_hdr_length_iov(iov, iovcnt, iovoff); l4hdr_info->proto =3D ETH_L4_HDR_PROTO_INVALID; =20 - proto =3D eth_get_l3_proto(iov, iovcnt, l2hdr_len); - - *l3hdr_off =3D l2hdr_len; + proto =3D eth_get_l3_proto(iov, iovcnt, *l3hdr_off); =20 if (proto =3D=3D ETH_P_IP) { struct ip_header *iphdr =3D &ip4hdr_info->ip4_hdr; =20 - if (input_size < l2hdr_len) { + if (input_size < *l3hdr_off) { return; } =20 - copied =3D iov_to_buf(iov, iovcnt, l2hdr_len, iphdr, sizeof(*iphdr= )); + copied =3D iov_to_buf(iov, iovcnt, *l3hdr_off, iphdr, sizeof(*iphd= r)); if (copied < sizeof(*iphdr) || IP_HEADER_VERSION(iphdr) !=3D IP_HEADER_VERSION_4) { return; @@ -175,17 +173,17 @@ void eth_get_protocols(const struct iovec *iov, int i= ovcnt, *hasip4 =3D true; ip_p =3D iphdr->ip_p; ip4hdr_info->fragment =3D IP4_IS_FRAGMENT(iphdr); - *l4hdr_off =3D l2hdr_len + IP_HDR_GET_LEN(iphdr); + *l4hdr_off =3D *l3hdr_off + IP_HDR_GET_LEN(iphdr); =20 fragment =3D ip4hdr_info->fragment; } else if (proto =3D=3D ETH_P_IPV6) { - if (!eth_parse_ipv6_hdr(iov, iovcnt, l2hdr_len, ip6hdr_info)) { + if (!eth_parse_ipv6_hdr(iov, iovcnt, *l3hdr_off, ip6hdr_info)) { return; } =20 *hasip6 =3D true; ip_p =3D ip6hdr_info->l4proto; - *l4hdr_off =3D l2hdr_len + ip6hdr_info->full_hdr_len; + *l4hdr_off =3D *l3hdr_off + ip6hdr_info->full_hdr_len; fragment =3D ip6hdr_info->fragment; } else { return; --=20 2.40.0