From nobody Tue Feb 10 19:48:23 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=1681969726; cv=none; d=zohomail.com; s=zohoarc; b=ZvMSjjgSpSZj2mM0LrYOLtsvBHvUTlvw4GA0cygFli5MGq6viK3z4qr6BAak9A/4Rzji+Smrk27Zgp2GB0AygxZgAWiSE5YIh+vUZHQKGiNhs2hqbUb0vtYJqAKK6vCz/rXlIn3o1LB0gD77pA7d7ZyT2e2eM8NwFSeqjdfBlc0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681969726; 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=olsD2xgUqYp8y9KV8yKVW3jfVHpAdqd+kCAwZWJ1hCE=; b=mAW3QA6soWlzYVj6InnTzQmfe/UoIZLDbMnKZAECm4a2X6VddggiHMKw6KH3db+vAwXRB+eRneitKxxPoQMpkq8K90kdCMbTQbX9uJSbwvlXdlJZ+DiNLvYZajwxgGgeoaSNBPr+5mCXKR5C91sPU1NYCzie9bl2TLLqqfcUTWY= 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 1681969726858964.9160216020283; Wed, 19 Apr 2023 22:48:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppN98-0006oo-RM; Thu, 20 Apr 2023 01:47:54 -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 1ppN94-0006nU-W5 for qemu-devel@nongnu.org; Thu, 20 Apr 2023 01:47:51 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppN93-00013Q-6r for qemu-devel@nongnu.org; Thu, 20 Apr 2023 01:47:50 -0400 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-51efefe7814so594942a12.3 for ; Wed, 19 Apr 2023 22:47:48 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 22:47:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1681969668; x=1684561668; 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=olsD2xgUqYp8y9KV8yKVW3jfVHpAdqd+kCAwZWJ1hCE=; b=DDUnNdpSqD+W3P0Jm9SHxBSavOLTWshMioOiLewqX1GNN9vrLynCwAUl1SA8KbEb7w 97ylK0j0XbP+/IiiBodw8OfK/WDyW+rPwoHv5gyAQkW7lCrpldv09rve66wwe9zweldL J26TvDBvYyg0d3FTCZF1gpEndEHfkQyQs+SgKgbCBecvNu+wWzU0zA/zPTBWr0PBKhDr b8D3vOblJsg4sDTMkm3yGWSYT74KnQpiXQHBPgVNE0IK738V9rvr8fEEm+lHxRRIaCEO zYNpGdz8xRvIQCIPEq0q5+Tfr3JFdqjyVUpZp5k1ORG534XXf98q7GD1cqow6TacpsNJ I7Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681969668; x=1684561668; 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=olsD2xgUqYp8y9KV8yKVW3jfVHpAdqd+kCAwZWJ1hCE=; b=V2uiwilT50SqF/mtMVRIcm2pUv7gQYT92bfQumrcnMaK2zJDufyFRkchTYeLMCVN4y BpmXH0S4YHCf+M+Sco1G/vWFbnhz5ujTUy9D3emDENwG+PPPX5VByMqsEtm9r59TPTq9 5Acb5/LtREo6xgYLmyx/Os1PN7pCgi0RahPPnIQv6FtYyfgIYWFGxrIN45YboR0CezW1 zNryDZ9yRYpPl8uh6BxkHiq41PkvHYfVcld4xxuUghRJtEjBH3CGfgx8tCUnZiIwRsLz fa7+w1cVYalg+7qjW62YRayf9zQ9xl+56x1Bm9YbdX0T0XpkLO8N7DnvBFTcAOkm9hyk A1Xg== X-Gm-Message-State: AAQBX9e4ZR+1eIVb42gpXyx2lBQCdv8RugwXd2Xa0uz6izReR2guR7II YzQra7++HJX+oSbuCE0InegDBQ== X-Google-Smtp-Source: AKy350bKur9j2ZHdN8w1Ak8P7NrPG999UGYW43fFT5ITByfJJ7q3i8ZxjuzbIjqYKhQAAXShF/7JyA== X-Received: by 2002:a17:90b:3d8:b0:249:87f0:604b with SMTP id go24-20020a17090b03d800b0024987f0604bmr532307pjb.30.1681969667978; Wed, 19 Apr 2023 22:47:47 -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 03/41] e1000x: Fix BPRC and MPRC Date: Thu, 20 Apr 2023 14:46:19 +0900 Message-Id: <20230420054657.50367-4-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::52e; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x52e.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: 1681969727985100004 Content-Type: text/plain; charset="utf-8" Before this change, e1000 and the common code updated BPRC and MPRC depending on the matched filter, but e1000e and igb decided to update those counters by deriving the packet type independently. This inconsistency caused a multicast packet to be counted twice. Updating BPRC and MPRC depending on are fundamentally flawed anyway as a filter can be used for different types of packets. For example, it is possible to filter broadcast packets with MTA. Always determine what counters to update by inspecting the packets. Fixes: 3b27430177 ("e1000: Implementing various counters") Signed-off-by: Akihiko Odaki Reviewed-by: Sriram Yagnaraman --- hw/net/e1000x_common.h | 5 +++-- hw/net/e1000.c | 6 +++--- hw/net/e1000e_core.c | 20 +++----------------- hw/net/e1000x_common.c | 25 +++++++++++++++++++------ hw/net/igb_core.c | 22 +++++----------------- 5 files changed, 33 insertions(+), 45 deletions(-) diff --git a/hw/net/e1000x_common.h b/hw/net/e1000x_common.h index 911abd8a90..0298e06283 100644 --- a/hw/net/e1000x_common.h +++ b/hw/net/e1000x_common.h @@ -91,8 +91,9 @@ e1000x_update_regs_on_link_up(uint32_t *mac, uint16_t *ph= y) } =20 void e1000x_update_rx_total_stats(uint32_t *mac, - size_t data_size, - size_t data_fcs_size); + eth_pkt_types_e pkt_type, + size_t pkt_size, + size_t pkt_fcs_size); =20 void e1000x_core_prepare_eeprom(uint16_t *eeprom, const uint16_t *templ, diff --git a/hw/net/e1000.c b/hw/net/e1000.c index 59bacb5d3b..18eb6d8876 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -826,12 +826,10 @@ receive_filter(E1000State *s, const uint8_t *buf, int= size) } =20 if (ismcast && (rctl & E1000_RCTL_MPE)) { /* promiscuous mcas= t */ - e1000x_inc_reg_if_not_full(s->mac_reg, MPRC); return 1; } =20 if (isbcast && (rctl & E1000_RCTL_BAM)) { /* broadcast enable= d */ - e1000x_inc_reg_if_not_full(s->mac_reg, BPRC); return 1; } =20 @@ -922,6 +920,7 @@ e1000_receive_iov(NetClientState *nc, const struct iove= c *iov, int iovcnt) size_t desc_offset; size_t desc_size; size_t total_size; + eth_pkt_types_e pkt_type; =20 if (!e1000x_hw_rx_enabled(s->mac_reg)) { return -1; @@ -971,6 +970,7 @@ e1000_receive_iov(NetClientState *nc, const struct iove= c *iov, int iovcnt) size -=3D 4; } =20 + pkt_type =3D get_eth_packet_type(PKT_GET_ETH_HDR(filter_buf)); rdh_start =3D s->mac_reg[RDH]; desc_offset =3D 0; total_size =3D size + e1000x_fcs_len(s->mac_reg); @@ -1036,7 +1036,7 @@ e1000_receive_iov(NetClientState *nc, const struct io= vec *iov, int iovcnt) } } while (desc_offset < total_size); =20 - e1000x_update_rx_total_stats(s->mac_reg, size, total_size); + e1000x_update_rx_total_stats(s->mac_reg, pkt_type, size, total_size); =20 n =3D E1000_ICS_RXT0; if ((rdt =3D s->mac_reg[RDT]) < s->mac_reg[RDH]) diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c index 15821a75e0..c2d864a504 100644 --- a/hw/net/e1000e_core.c +++ b/hw/net/e1000e_core.c @@ -1488,24 +1488,10 @@ e1000e_write_to_rx_buffers(E1000ECore *core, } =20 static void -e1000e_update_rx_stats(E1000ECore *core, - size_t data_size, - size_t data_fcs_size) +e1000e_update_rx_stats(E1000ECore *core, size_t pkt_size, size_t pkt_fcs_s= ize) { - e1000x_update_rx_total_stats(core->mac, data_size, data_fcs_size); - - switch (net_rx_pkt_get_packet_type(core->rx_pkt)) { - case ETH_PKT_BCAST: - e1000x_inc_reg_if_not_full(core->mac, BPRC); - break; - - case ETH_PKT_MCAST: - e1000x_inc_reg_if_not_full(core->mac, MPRC); - break; - - default: - break; - } + eth_pkt_types_e pkt_type =3D net_rx_pkt_get_packet_type(core->rx_pkt); + e1000x_update_rx_total_stats(core->mac, pkt_type, pkt_size, pkt_fcs_si= ze); } =20 static inline bool diff --git a/hw/net/e1000x_common.c b/hw/net/e1000x_common.c index 4c8e7dcf70..7694673bcc 100644 --- a/hw/net/e1000x_common.c +++ b/hw/net/e1000x_common.c @@ -80,7 +80,6 @@ bool e1000x_rx_group_filter(uint32_t *mac, const uint8_t = *buf) f =3D mta_shift[(rctl >> E1000_RCTL_MO_SHIFT) & 3]; f =3D (((buf[5] << 8) | buf[4]) >> f) & 0xfff; if (mac[MTA + (f >> 5)] & (1 << (f & 0x1f))) { - e1000x_inc_reg_if_not_full(mac, MPRC); return true; } =20 @@ -212,13 +211,14 @@ e1000x_rxbufsize(uint32_t rctl) =20 void e1000x_update_rx_total_stats(uint32_t *mac, - size_t data_size, - size_t data_fcs_size) + eth_pkt_types_e pkt_type, + size_t pkt_size, + size_t pkt_fcs_size) { static const int PRCregs[6] =3D { PRC64, PRC127, PRC255, PRC511, PRC1023, PRC1522 }; =20 - e1000x_increase_size_stats(mac, PRCregs, data_fcs_size); + e1000x_increase_size_stats(mac, PRCregs, pkt_fcs_size); e1000x_inc_reg_if_not_full(mac, TPR); e1000x_inc_reg_if_not_full(mac, GPRC); /* TOR - Total Octets Received: @@ -226,8 +226,21 @@ e1000x_update_rx_total_stats(uint32_t *mac, * Address> field through the field, inclusively. * Always include FCS length (4) in size. */ - e1000x_grow_8reg_if_not_full(mac, TORL, data_size + 4); - e1000x_grow_8reg_if_not_full(mac, GORCL, data_size + 4); + e1000x_grow_8reg_if_not_full(mac, TORL, pkt_size + 4); + e1000x_grow_8reg_if_not_full(mac, GORCL, pkt_size + 4); + + switch (pkt_type) { + case ETH_PKT_BCAST: + e1000x_inc_reg_if_not_full(mac, BPRC); + break; + + case ETH_PKT_MCAST: + e1000x_inc_reg_if_not_full(mac, MPRC); + break; + + default: + break; + } } =20 void diff --git a/hw/net/igb_core.c b/hw/net/igb_core.c index abfdce9aaf..464a41d0aa 100644 --- a/hw/net/igb_core.c +++ b/hw/net/igb_core.c @@ -1438,29 +1438,17 @@ igb_write_to_rx_buffers(IGBCore *core, =20 static void igb_update_rx_stats(IGBCore *core, const E1000E_RingInfo *rxi, - size_t data_size, size_t data_fcs_size) + size_t pkt_size, size_t pkt_fcs_size) { - e1000x_update_rx_total_stats(core->mac, data_size, data_fcs_size); - - switch (net_rx_pkt_get_packet_type(core->rx_pkt)) { - case ETH_PKT_BCAST: - e1000x_inc_reg_if_not_full(core->mac, BPRC); - break; - - case ETH_PKT_MCAST: - e1000x_inc_reg_if_not_full(core->mac, MPRC); - break; - - default: - break; - } + eth_pkt_types_e pkt_type =3D net_rx_pkt_get_packet_type(core->rx_pkt); + e1000x_update_rx_total_stats(core->mac, pkt_type, pkt_size, pkt_fcs_si= ze); =20 if (core->mac[MRQC] & 1) { uint16_t pool =3D rxi->idx % IGB_NUM_VM_POOLS; =20 - core->mac[PVFGORC0 + (pool * 64)] +=3D data_size + 4; + core->mac[PVFGORC0 + (pool * 64)] +=3D pkt_size + 4; core->mac[PVFGPRC0 + (pool * 64)]++; - if (net_rx_pkt_get_packet_type(core->rx_pkt) =3D=3D ETH_PKT_MCAST)= { + if (pkt_type =3D=3D ETH_PKT_MCAST) { core->mac[PVFMPRC0 + (pool * 64)]++; } } --=20 2.40.0