From nobody Wed Feb 11 08:39:54 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=1681472340; cv=none; d=zohomail.com; s=zohoarc; b=YADaYrLdOFYxy/74BGbhXvjgz0Cpbn7fyiFnzAvJekFp06q1CKgHCOG4ogRwScWrWp56Msgk5SNTQctPmMegZu1Egl0cbsvyvf1Gitwi4S0YJY2XgU0MyBgIcaioh/uLhPC5ZW3Pr0pxt8pA0+M7JCr7CvpvvAXng0QA0/ttOJc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681472340; 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=S+cGOw4iIJzD8cYp6+9ekWQTwlNMy9274OltiMEKS3Q=; b=IF/VHqh79IqKg3GZ/oaR9P1txalLtlpoPnR5MA0O9R3XHDIZwtZHj2e2MbOHvdL6iOQ3sQA8fkIDukbYQyhAcFXGQbI/d19TzZF1NGxa7aTV2xASU0M0Pvx5mg7iZEt+io5VwmAEDw3wdD5nh0s6CllDa8jVqCyAIkzTAkYxOmo= 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 168147234067091.67249813976912; Fri, 14 Apr 2023 04:39:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pnHkz-0008BN-Tf; Fri, 14 Apr 2023 07:38:21 -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 1pnHky-0008B2-Fp for qemu-devel@nongnu.org; Fri, 14 Apr 2023 07:38:20 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pnHku-0001A2-Qq for qemu-devel@nongnu.org; Fri, 14 Apr 2023 07:38:19 -0400 Received: by mail-pj1-x102a.google.com with SMTP id my14-20020a17090b4c8e00b0024708e8e2ddso7419097pjb.4 for ; Fri, 14 Apr 2023 04:38:16 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:4457:c267:5e09:481b]) by smtp.gmail.com with ESMTPSA id u19-20020a170902a61300b001a20b31a23fsm2889249plq.293.2023.04.14.04.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 04:38:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1681472296; x=1684064296; 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=S+cGOw4iIJzD8cYp6+9ekWQTwlNMy9274OltiMEKS3Q=; b=Jo/57qpXjEShrnsNxEer7+FKhR1C4Ag0HmVXyyIw/TLI9nF4ydzIxlL4nTrHhOcgq3 SSYs7kUqz1kVHtnhMgMa8sm+FbAEvOCMeKnxaFrVkmaxfne/X9/ObFwZzZSzM2v4wTiv mp2WU3gom0yjofwoH2yPuNSlpurVtayPA3nwmB4jpL6jS2V3wfqHUpTa9Md4sZSD6LJL hrSRKtpAaaTADLs1MWgaSR8ueTkGc/9vpTZ53hIqJyoXnUuTs1Oa92PIE6YnOXAiCE1b Z8hUIHjjwAcDrzRFM1zWbS4Uj3LbdGG9wsx04FQ8LKP7HY1//WOIVf3fyCbCkLst79Iq r2Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681472296; x=1684064296; 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=S+cGOw4iIJzD8cYp6+9ekWQTwlNMy9274OltiMEKS3Q=; b=Qk5eQYaEJQbqPHlru6YRtqfpnIgPOIeiCuOud7gcCtqXWsgDZDrpYzDyNOsSq9ezo+ SR/FhZSz+1nVcD2yk7hYCtMhD97yExQKAjEhsRq0OC2ALU8L22jPGEkKmqT1LzhBjDZS d3uzKONVWrh98YUycVVUfwG+anitmctG4QqLXdwZ53LbwB/kDM1DxY85L6rxI4G+U4O8 m97u/qzlCG+rkaIhowOsCx3VvCzdBqWvRCmf3mvu5ATMrGMaJnpPIFuSeJpscMOmuEdj 6UeokQcXzBYQFIWfFa+2lDsQykUAVRZHGpGfm6H3L+FpzCZGhbvHU+d3SqGfpBuXKwcg Wr9Q== X-Gm-Message-State: AAQBX9fogl72TWlo5UNrdKpAry1WsBhO059Gvkc82+wziIVCpGwwODPR zlcX/ZOAKjjTNRQpF9zX9KmO6Q== X-Google-Smtp-Source: AKy350Y/niwAke+iN6Ov14NkSUmgHzoZWoyCjDivqb2ZHHX7jY+cEjjAuvo9evziv5qHz/ohui2lHg== X-Received: by 2002:a17:902:e54f:b0:19c:a9b8:4349 with SMTP id n15-20020a170902e54f00b0019ca9b84349mr3174734plf.32.1681472296184; Fri, 14 Apr 2023 04:38:16 -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, Akihiko Odaki Subject: [PATCH 06/40] net/net_rx_pkt: Use iovec for net_rx_pkt_set_protocols() Date: Fri, 14 Apr 2023 20:37:03 +0900 Message-Id: <20230414113737.62803-7-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230414113737.62803-1-akihiko.odaki@daynix.com> References: <20230414113737.62803-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::102a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x102a.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: 1681472341538100006 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/igb_core.c | 2 +- hw/net/net_rx_pkt.c | 14 +++++--------- hw/net/net_rx_pkt.h | 10 ++++++---- hw/net/virtio-net.c | 7 +++++-- hw/net/vmxnet3.c | 7 ++++++- include/net/eth.h | 6 +++--- net/eth.c | 18 ++++++++---------- 7 files changed, 34 insertions(+), 30 deletions(-) diff --git a/hw/net/igb_core.c b/hw/net/igb_core.c index 5d4884b834..53f60fc3d3 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/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/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/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/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