From nobody Tue Feb 10 19:48:28 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=1681969891; cv=none; d=zohomail.com; s=zohoarc; b=ODCK7vXUiZ/ZT1EwcDMbuSjWFr8iAo45/MRT/1u+T7022nJVWAq/shy2TkXKcZMvEGd6/SJcpEn++dHmm3pw/U4ar/VOoEYIdZQTM8KNlUHIA9DX+nJwH/3kbETwU9sBiDnIi26+qOSwtFUmiRQOE0AQ25kM/Z+JmUylUJ0bIQ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681969891; 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=JZLZ6syDe67wGHmQM3Z+1cpabxDcSS1kb2HPMg6PeUo=; b=IYpDZurNsIeQRuq5TM9CpYoMDJVBidUZa98OZLYjoqoOzgQ1UtF+8vMqQilPq5oVOg8eZfe2zR0TRZPgw2LWVHii/oBmQhkm7itQ+03Ze25Hl+RbP/LTPIJ4vAkdPI+5ehjcI+IMBa7zGQbLOV0dQ+a4zXODAEQpngLKwASh8Tc= 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 1681969891242717.0943974459933; Wed, 19 Apr 2023 22:51:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppN9P-0006tg-V0; Thu, 20 Apr 2023 01:48:11 -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 1ppN9O-0006t3-1p for qemu-devel@nongnu.org; Thu, 20 Apr 2023 01:48:10 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppN9L-00019a-27 for qemu-devel@nongnu.org; Thu, 20 Apr 2023 01:48:09 -0400 Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-517bdd9957dso447718a12.1 for ; Wed, 19 Apr 2023 22:48:06 -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.48.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 22:48:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1681969685; x=1684561685; 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=JZLZ6syDe67wGHmQM3Z+1cpabxDcSS1kb2HPMg6PeUo=; b=rrd7aVqFNAF+fROBmytWuNEakpMBCa4rTe4ORjshciqGFJEg0WZkYaOL5Cgy7n2MS+ WQyYVQZ7LyCn6RmZBNJgPuEUNslvcLs8QIbGnKAMYMja7SZBjE38QHV3qpBjBFiGS/uF GxtSqANwHRUvOZ4JH2Xva9M1E+rMa5qZtMxaXj+0CpvmgufIv2cTFOxjPVCAWQwKCdB+ 5RRC7E9ImgE5rdYhEEA0JMi3MvvOnjNor/IPwPenjKTX5F0Vum/kpJgozcwdjEnax+Z4 7tP9R/HqFGJ+ofnWPawfmQC5aKbQF813dv4GSPCNW/ijuw06Y6WR3Jix4S84pqMxkzrE x7Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681969685; x=1684561685; 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=JZLZ6syDe67wGHmQM3Z+1cpabxDcSS1kb2HPMg6PeUo=; b=GFdSkKymfJTpCIYlTu2+zPLgUR/ea7g648V+AaM+j+LkmuqXAvRwQty0UT/iSoiktL 1odXssqyfzPCSLWxJkjjxg5dpaWhzk9tTx/jNtR4otb8zgRNrp9SF0mUT/12wUmgen5g uH+gQnH+VFfc4HMlcUrN87lEDqs09AFa8JVx8Ep3vZSAAzm1g/ShnDABPqpF+WWaCcZn Mi4PyeIxtCFdH0/XWEm1GVTOAmqpaKPUZYqoR+8TRI1wOW5koORaqWOu6hBJlgFTuNFI hC6nts7NthVYLZg0+cM39DXJShfrXh3jRzJQB375b9VjbQsoBv7LHeJ4E45SA84GeUrW 4eww== X-Gm-Message-State: AAQBX9c7hBN6YF9/T6HgM9XTuJ/DZUPQDren//Bu7yAF36E/hpd+r1DH X+DY6uVBJg209rq37HYQ1TKfLg== X-Google-Smtp-Source: AKy350bLoc/+vJ1uBXHzeBmdTDlGwt3BJ/FTIdw5uGGnT5h/hk+tYp4HuIa5WnMTk1EihNEek46Tbw== X-Received: by 2002:a17:90b:3144:b0:247:6c32:37e5 with SMTP id ip4-20020a17090b314400b002476c3237e5mr577351pjb.13.1681969685645; Wed, 19 Apr 2023 22:48:05 -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 08/41] igb: Always copy ethernet header Date: Thu, 20 Apr 2023 14:46:24 +0900 Message-Id: <20230420054657.50367-9-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::534; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x534.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: 1681969893232100003 Content-Type: text/plain; charset="utf-8" igb_receive_internal() used to check the iov length to determine copy the iovs to a contiguous buffer, but the check is flawed in two ways: - It does not ensure that iovcnt > 0. - It does not take virtio-net header into consideration. The size of this copy is just 22 octets, which can be even less than the code size required for checks. This (wrong) optimization is probably not worth so just remove it. Removing this also allows igb to assume aligned accesses for the ethernet header. Fixes: 3a977deebe ("Intrdocue igb device emulation") Signed-off-by: Akihiko Odaki --- hw/net/igb_core.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/hw/net/igb_core.c b/hw/net/igb_core.c index 62d10f971e..72a00564cf 100644 --- a/hw/net/igb_core.c +++ b/hw/net/igb_core.c @@ -67,6 +67,11 @@ typedef struct IGBTxPktVmdqCallbackContext { NetClientState *nc; } IGBTxPktVmdqCallbackContext; =20 +typedef struct L2Header { + struct eth_header eth; + struct vlan_header vlan; +} L2Header; + static ssize_t igb_receive_internal(IGBCore *core, const struct iovec *iov, int iovcnt, bool has_vnet, bool *external_tx); @@ -961,15 +966,16 @@ igb_rx_is_oversized(IGBCore *core, uint16_t qn, size_= t size) return size > (lpe ? max_ethernet_lpe_size : max_ethernet_vlan_size); } =20 -static uint16_t igb_receive_assign(IGBCore *core, const struct eth_header = *ehdr, +static uint16_t igb_receive_assign(IGBCore *core, const L2Header *l2_heade= r, size_t size, E1000E_RSSInfo *rss_info, bool *external_tx) { static const int ta_shift[] =3D { 4, 3, 2, 0 }; + const struct eth_header *ehdr =3D &l2_header->eth; uint32_t f, ra[2], *macp, rctl =3D core->mac[RCTL]; uint16_t queues =3D 0; uint16_t oversized =3D 0; - uint16_t vid =3D lduw_be_p(&PKT_GET_VLAN_HDR(ehdr)->h_tci) & VLAN_VID_= MASK; + uint16_t vid =3D be16_to_cpu(l2_header->vlan.h_tci) & VLAN_VID_MASK; bool accepted =3D false; int i; =20 @@ -1590,14 +1596,13 @@ static ssize_t igb_receive_internal(IGBCore *core, const struct iovec *iov, int iovcnt, bool has_vnet, bool *external_tx) { - static const int maximum_ethernet_hdr_len =3D (ETH_HLEN + 4); - uint16_t queues =3D 0; uint32_t n =3D 0; - uint8_t min_buf[ETH_ZLEN]; + union { + L2Header l2_header; + uint8_t octets[ETH_ZLEN]; + } min_buf; struct iovec min_iov; - struct eth_header *ehdr; - uint8_t *filter_buf; size_t size, orig_size; size_t iov_ofs =3D 0; E1000E_RxRing rxr; @@ -1623,24 +1628,21 @@ igb_receive_internal(IGBCore *core, const struct io= vec *iov, int iovcnt, net_rx_pkt_unset_vhdr(core->rx_pkt); } =20 - filter_buf =3D iov->iov_base + iov_ofs; orig_size =3D iov_size(iov, iovcnt); size =3D orig_size - iov_ofs; =20 /* Pad to minimum Ethernet frame length */ if (size < sizeof(min_buf)) { - iov_to_buf(iov, iovcnt, iov_ofs, min_buf, size); - memset(&min_buf[size], 0, sizeof(min_buf) - size); + iov_to_buf(iov, iovcnt, iov_ofs, &min_buf, size); + memset(&min_buf.octets[size], 0, sizeof(min_buf) - size); e1000x_inc_reg_if_not_full(core->mac, RUC); - min_iov.iov_base =3D filter_buf =3D min_buf; + min_iov.iov_base =3D &min_buf; min_iov.iov_len =3D size =3D sizeof(min_buf); iovcnt =3D 1; iov =3D &min_iov; iov_ofs =3D 0; - } else if (iov->iov_len < maximum_ethernet_hdr_len) { - /* This is very unlikely, but may happen. */ - iov_to_buf(iov, iovcnt, iov_ofs, min_buf, maximum_ethernet_hdr_len= ); - filter_buf =3D min_buf; + } else { + iov_to_buf(iov, iovcnt, iov_ofs, &min_buf, sizeof(min_buf.l2_heade= r)); } =20 /* Discard oversized packets if !LPE and !SBP. */ @@ -1648,11 +1650,12 @@ igb_receive_internal(IGBCore *core, const struct io= vec *iov, int iovcnt, return orig_size; } =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_packet_type(core->rx_pkt, + get_eth_packet_type(&min_buf.l2_header.eth)= ); 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= ); + queues =3D igb_receive_assign(core, &min_buf.l2_header, size, + &rss_info, external_tx); if (!queues) { trace_e1000e_rx_flt_dropped(); return orig_size; --=20 2.40.0