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=1681472390; cv=none; d=zohomail.com; s=zohoarc; b=MHI7FkBOM/J5N8Mad2H4N+OMiq5l8sWPAIUX8nJebWmjRJdVml6RLGnAoTArxYJBR1lYe6U7IYBsJshRpv/azNlZBMqHptsZYICx4XHecXHrMtfVEnMi2Us1YhuS4s0kiOZB89fr1RGikaLIBh7X/pJQorjv/dxU6YmuxQuHgb0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681472390; 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=DTaO5RfaUfdq2ayfAOTXEIBt0J8itH8jtXXlLyE4Zo8=; b=kscqULdC3+tEbWm6i7BXSt0BcWhNcxBNnlAeFNZbhcVHd+wk6r9a76NR/MCOECHwuDA4N1qPXqE5Q5gbCvgULBVpI92QxlPoFf3AlDVRQPZcHtr1LGM6/AlR+98fB0z6asq2xvDOhrlKbtxqiDbiZVV+Bfx5UHkay3dNTSjOZbw= 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 1681472390901749.2089681561688; Fri, 14 Apr 2023 04:39:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pnHks-00088n-0K; Fri, 14 Apr 2023 07:38:14 -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 1pnHkl-000884-61 for qemu-devel@nongnu.org; Fri, 14 Apr 2023 07:38:07 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pnHkj-0001BG-5X for qemu-devel@nongnu.org; Fri, 14 Apr 2023 07:38:06 -0400 Received: by mail-pl1-x632.google.com with SMTP id w11so18012500plp.13 for ; Fri, 14 Apr 2023 04:38:04 -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.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 04:38:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1681472283; x=1684064283; 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=DTaO5RfaUfdq2ayfAOTXEIBt0J8itH8jtXXlLyE4Zo8=; b=RPLsC5Z4oWulMVKZeAbCoor0Izt0ZsUgp2wU1yB67cQv7WgEKgRqriB05oHCSZetKH I4+6RdDpcKuisLLR0Ol3KuJEPCfBwZmPKs2uub11rd5+DtiZ4FTLvlcMUo1cqh+PVJeY e6GZhMs0ImkSjkSAs0Y9TEIDoXVGXb+3B3lMrLd4K/AK0lCtMMSmmLncOX53LnMsBzmr H5vVK5wb2izzzcseikq2gsBKJj6XC4/1hEstcegRyuegrSID2Ei+4av5CEiUOGU0FI22 MaHcpNv7M7SO8PB0czzp2Hn43LtFgyk1/eV8MiDHjV3LXmEzLK/UxLxyxhvIucrZwfoX pggg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681472283; x=1684064283; 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=DTaO5RfaUfdq2ayfAOTXEIBt0J8itH8jtXXlLyE4Zo8=; b=VxTIzrst5AQDJzAAVKtGMr5c+SbryR++IuWgv8XycYHAhwoh8iEPkhwOvKidKtPiPD hp99DuPEzp9OU+lDoJlkgVmjeTtaZjzf4wNx/di65gXb8h1fUJp9AesSmavAfHPjfzUg SZHlGRIxyJZVxTXozpmgBKnSPlzJGcZCX0ivyPOBTgmxlzMmr7o+n+3WwpCKPKH8zNtw 9wPAethglBlsUWLEX9p0rGRNy5GjgffzQAKPZFX7f2qE00ZSD30wEqwlXWLqW9CYvZZg fbx7DJlulVEFFsW7tJQz2dv8USkUbSepxbJ2QQIKQywDGWh5bfANRp3JC1uSq1fYgx44 qqsQ== X-Gm-Message-State: AAQBX9cwVPCLBxtq+/r9rM0MVa7u1VR7zbAu9Dy8BWcT4OIONHRiyuF4 7agsYMqupUM9To1msYv5FiBrHQ== X-Google-Smtp-Source: AKy350aC8OF3ikMQxfA2EESN446C8RTWpXiZa+D44Z5t4CZ1h0t67EUNhVyxSWW6VITS9BQxQiydww== X-Received: by 2002:a17:902:c78b:b0:1a0:53f3:3761 with SMTP id w11-20020a170902c78b00b001a053f33761mr2081091pla.15.1681472283293; Fri, 14 Apr 2023 04:38:03 -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 02/40] e1000x: Fix BPRC and MPRC Date: Fri, 14 Apr 2023 20:36:59 +0900 Message-Id: <20230414113737.62803-3-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::632; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x632.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: 1681472391697100015 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 --- hw/net/e1000.c | 6 +++--- hw/net/e1000e_core.c | 20 +++----------------- hw/net/e1000x_common.c | 25 +++++++++++++++++++------ hw/net/e1000x_common.h | 5 +++-- hw/net/igb_core.c | 22 +++++----------------- 5 files changed, 33 insertions(+), 45 deletions(-) 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/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/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