From nobody Tue Feb 10 19:00:21 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=1684809938; cv=none; d=zohomail.com; s=zohoarc; b=MlKVrZaVAPtc3cSGbhFindSf0if/Ity4QkzIqZiXaPXxuaZs0KfmCaVv8dQ3YLBzATkzfQcH4AN+xDPxP1MyTaCEsHdda0mlfLcqmuFnrG1+IemexTsjREPKkgHqMClV5faEDZxphC0bZFRqvfSGy6f812UPoi1OeZQGEbedWOA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684809938; 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=q/ljXeplOjVMDMpVsQpgiVTsGYssFMg5Ie0JSRz6qGk=; b=nMyIQm7K7RIW0x9sambDwIx6a0AXbjTx9/p/fyl4Znw2ZILs5gmBqm8sLhNV3RdvUIIIR/uFcg+3+1MuOYDUE2NtqLgP44DVQ0hJlAY+Uc4GP1ejgt/JmdZtezrEMWja0D6keG1exfPVcABLb7IIe8Qq4s0rLHbnkaxlfTkbPWc= 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 1684809938933508.0122657887499; Mon, 22 May 2023 19:45:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q1I0j-0003Df-Og; Mon, 22 May 2023 22:44:29 -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 1q1I0h-0003DH-0R for qemu-devel@nongnu.org; Mon, 22 May 2023 22:44:27 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q1I0f-00047h-Dc for qemu-devel@nongnu.org; Mon, 22 May 2023 22:44:26 -0400 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-2533a03388dso4624229a91.2 for ; Mon, 22 May 2023 19:44:25 -0700 (PDT) Received: from alarm.. ([157.82.204.253]) by smtp.gmail.com with ESMTPSA id o10-20020a17090aac0a00b002467717fa60sm4769847pjq.16.2023.05.22.19.44.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 19:44:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1684809864; x=1687401864; 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=q/ljXeplOjVMDMpVsQpgiVTsGYssFMg5Ie0JSRz6qGk=; b=b483PDaFF+Fr9PnSSU3xUVZ5hOQN3Kx+OBLpV6XZ/H0PeJkSUSWjNnECeYcnh80qcX nLHR8ybsJoHOeuW6f29z/Db2yMrx5NN+GLsEjN6SpUDkVX26x4XBYF4D9G/LvOU7WToD qxk5AxUJOaMYUXuu5T0wFvROXvbJuau3M23NdEvCKtsYfsMDim7qfdn5xJNRWpX+d4nF 4JO4HIF6C/CR/l6Ebc0qYqboc6Je7FBQ/hvavtPJJOYo3G+yMW+/iMhWUfq754oT+it0 FjAaykXqhz8DUISSOk8LCdhw3dTRtkoTVvN+dbOPWsunFit83xHMauOgeeJb4JHxoY03 4XbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684809864; x=1687401864; 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=q/ljXeplOjVMDMpVsQpgiVTsGYssFMg5Ie0JSRz6qGk=; b=cwN2l7Y+RuPg1sWiL+zeKlqZSNxWB05zbRSYyoll+qzsKvoanUcjLH8I/ORGQycp2n iwIJtiTbhGOAlI+1MjAYgfORDSOitsaJdlu/B8KmdfG1lli1GvBmQ5re2LqoNNBHFr+V gqY9Md5YwdaianXTpHxA3t7BBOgZ5TWGLrAHIwRUmmDkEATDMQ2BA/O7EEAFnHvQDFlD 71WRHygWhwm/kRBK0DBsHOkHuVMkkRoHwm48vsm2Tjq6A84ux70WSQTcZxOPT7US+V15 nTAUtmmc8L8j83HUlytPclaE+C9rpiWK8uli2hLifuDnUjtcfvKThhUpF121TGDnXDww G6mg== X-Gm-Message-State: AC+VfDyB62mu9lbQaZWHdTisi7EEnHApMf4i0O90nLrwNK6NzDzD9TXa SRZLWAGMItwb3V9aBtNID7GV3g== X-Google-Smtp-Source: ACHHUZ4302CUYoYGjY9soxssO2TYFkEO9HJ6/PbOxVLsB12aCPtE/p8t29c423jmZtuerVpHPf24HA== X-Received: by 2002:a17:90a:ea04:b0:24c:df8:8efa with SMTP id w4-20020a17090aea0400b0024c0df88efamr12030932pjy.39.1684809864307; Mon, 22 May 2023 19:44:24 -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 v5 09/48] igb: Always copy ethernet header Date: Tue, 23 May 2023 11:43:00 +0900 Message-Id: <20230523024339.50875-10-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230523024339.50875-1-akihiko.odaki@daynix.com> References: <20230523024339.50875-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::1032; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1032.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: 1684809939710100001 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 Reviewed-by: Sriram Yagnaraman --- hw/net/igb_core.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/hw/net/igb_core.c b/hw/net/igb_core.c index 21a8d9ada4..1123df9e77 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]; + } 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); + if (size < sizeof(buf)) { + iov_to_buf(iov, iovcnt, iov_ofs, &buf, size); + memset(&buf.octets[size], 0, sizeof(buf) - size); e1000x_inc_reg_if_not_full(core->mac, RUC); - min_iov.iov_base =3D filter_buf =3D min_buf; - min_iov.iov_len =3D size =3D sizeof(min_buf); + min_iov.iov_base =3D &buf; + min_iov.iov_len =3D size =3D sizeof(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, &buf, sizeof(buf.l2_header)); } =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(&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, &buf.l2_header, size, + &rss_info, external_tx); if (!queues) { trace_e1000e_rx_flt_dropped(); return orig_size; --=20 2.40.1