From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=81.169.146.216 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796215095; b=LUwdXTMdw8I4Xo/Un+frDqjqAfYrpDrGdMQ99CYP22htxRGfhhtn1boCuWRXeZh3KaQK 9he0OYTvnjJAMnhusewlBDKqTQyQsn99hUfUt/a7qayaaSN2e/niI19humNkjpLe9wX+8 kFnPvHqG5mtw7pvUNZc+cYEWTLGx5H3nU0IUGG6ZNjsr1i6OO96KGszdsMi09YL4/77vM VFPe/EOYpO6NFIcCvPAoD87tOyNdg6Y2mR7QxcV+/o+rss5UKVHIL7OJZNI1zcoMaRo9E 7z9Nj+aP6cc0fjPYN+HzClo0G3Kkbj8Llj7u2ZuUIOSQndikQTMlVABfG9Y84Ple5Og== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796215095; h=DMARC-Filter:X-RZG-CLASS-ID:DKIM-Signature:DKIM-Signature:X-RZG-AUTH: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding:Content-Type; bh=2CE3IFTdxspHv5M9AZ7JlVMMktj+6RCpyYO5snbspV8=; b=Bxwo0NcS/xJbx3SKOnCzT+Gf9crtaDd7j0pUso3lO2+UwZ2+3xY2RctGItBADWBYm1Sl d4fQR+bw42682u7ggK4IYHAb1n/CjiHJDdQ578WYO+Wx5H8smPYkvY3rQhQosT7M1cwj1 0IT7d6byBlqXBoWLDsI1MbJEEYn00JWMC+ttkIbvO5T/8y0jN0nm1PtsWOIbpoTbJBSjD eMyhSnPTs71c3DkiHL2QwLsGCBlcQ/H6dxhwXIbRIeSoYusr9nHCwIrFFE/+7a/zEWlD7 93EOnTgpdFZ0wHzqTVac4cSLwPuDvy/gtnEOjeTJd0+CFkLK5FN49eXrWFObpiQi1VQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=hartkopp.net; spf=fail smtp.mailfrom=hartkopp.net; dkim=pass header.d=hartkopp.net header.i=@hartkopp.net header.a=rsa-sha256 header.s=strato-dkim-0002 header.b=oQWHb3ta; dkim=pass header.d=hartkopp.net header.i=@hartkopp.net header.a=ed25519-sha256 header.s=strato-dkim-0003 header.b=dZQqWENP; arc=pass header.oldest-pass=0 smtp.remote-ip=81.169.146.216 Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.216]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A173C606A323 for ; Wed, 2 Dec 2026 12:38:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A173C606A323 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=hartkopp.net Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=hartkopp.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=hartkopp.net header.i=@hartkopp.net header.a=rsa-sha256 header.s=strato-dkim-0002 header.b=oQWHb3ta; dkim=pass header.d=hartkopp.net header.i=@hartkopp.net header.a=ed25519-sha256 header.s=strato-dkim-0003 header.b=dZQqWENP ARC-Seal: i=1; a=rsa-sha256; t=1796215086; cv=none; d=strato.com; s=strato-dkim-0002; b=qTkDmE82gHhTuz4V7pfrDWfIT9QAGEKMbcNWiCpO6bjNl0wWkcOtlhO8gg3tBuyw77 M/kTNllR28/p/qyPQXQnwo7ES1I4DGezcngprccG4uSvt75NyUPG2Rt+dM7Lve01hknC Tcy8UoSfa2zVYbUQioVPPYgXTuMdROGiYL0LM1JM5dNEbVjRmmoOhqaIRUG9qNX1HcAA UNlBEEXzuNSyfT71uwQz6FcCgu5tXa/JSb+iSFdrukYaFYKVfBZpOuGk1K/CS7s5nM2+ tjjtDSopxpIG+wor4lONFD3gsbwNeywMlX3a0RmZsymF4VA/RM4jyCm3rrF+grFhw2m4 A02g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1796215086; s=strato-dkim-0002; d=strato.com; h=Message-ID:Date:Subject:Cc:To:From:Cc:Date:From:Subject:Sender; bh=2CE3IFTdxspHv5M9AZ7JlVMMktj+6RCpyYO5snbspV8=; b=FON7YdIz+vmdIJVgrrHMEiR4gQ8HjHLOzxwhjLXrRFu7foW8njo/g3ERm1pitc3qRU Fom9jmhbo9bHVCpbOEC4TvbENwkQZYb7SiGm/U3ATAYKNw8DSpW6LSw3L88dr/wi+bfr GqFFNnqloCZqidoWA6id8q2JltWlnxqm4Y6OXElk0b12wNRjz+hUppXYKT6s50m37nPK MW9KL62FcjblAKVoD7Sy46IQonQpZRjZz8sozuTwpfr0lyLEff1VIurvjsM0RuaJDiMm xH7kOnIGgSS50zpDVC+wWH8ognqloJVymCw/d2rauZGV4FV0JxegJ01Wb3UTmEZ7kQR1 G+2w== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1796215086; s=strato-dkim-0002; d=hartkopp.net; h=Message-ID:Date:Subject:Cc:To:From:Cc:Date:From:Subject:Sender; bh=2CE3IFTdxspHv5M9AZ7JlVMMktj+6RCpyYO5snbspV8=; b=oQWHb3taj8+l0bpjdB1qySveQRayOv1SsUhvjabIGY/0Y0B2ShRd1PbWUCpAscWuZK Q9aWlN3u9Y2l8CZ62NHFYn/m17sHWxJ0Xk5I9FXHHTBXYwgdmdt8BGAzwr9NtzZtW3ai CXlMqwjGXsChr6PeQ7mAdJRjMPz5ajJIWVMfpHZiMQVp52c5PU2rThHSH2gQRk57X4pD c4vqNtiaiUQdXRWiVgnh0BxrNuJ5YFS+p1ocal0oV8E+7q8EZqhzbYpO89dzuVyVxwxw D3m7FWTXOVAlyZp2w7aACUJkkjRLONdCjybOFUuQnHiKgMhQ+7pJHwVWaCi+o6RKFzxg Uw0w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1796215086; s=strato-dkim-0003; d=hartkopp.net; h=Message-ID:Date:Subject:Cc:To:From:Cc:Date:From:Subject:Sender; bh=2CE3IFTdxspHv5M9AZ7JlVMMktj+6RCpyYO5snbspV8=; b=dZQqWENPNlHmAzMnpD/QCNZdpFWXbruZdp1BSmzhh+hjKPpUJkqE1VCZKJVaR/Cmug Of/H59ggwDyDxT6BfDAA== X-RZG-AUTH: ":P2MHfkW8eP4Mre39l357AZT/I7AY/7nT2yrDxb8mjH4JKvMdQv2tTUsMrZpkO3Mw3lZ/t54cFxeEQ7s8bDup0Q==" Received: from vivo.lan by smtp.strato.de (RZmta 55.6.3 AUTH) with ESMTPSA id Kfdf2a2B2Cc5LsX (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 2 Dec 2026 13:38:05 +0100 (CET) From: Oliver Hartkopp To: linux-can@vger.kernel.org Cc: Oliver Hartkopp Subject: [PATCH] can: rx-offload: do not count echo frames as received frames Date: Wed, 2 Dec 2026 13:37:55 +0100 Message-ID: <20261202123755.3856-1-socketcan@hartkopp.net> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-can@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="us-ascii" Drivers using rx-offload do not account received frames themselves. The RX statistics (rx_packets, rx_bytes) are updated centrally in can_rx_offload_napi_poll() for every delivered skb except error frames. This also includes the echo skbs of transmitted frames, which drivers queue with can_rx_offload_get_echo_skb_queue_timestamp() or can_rx_offload_get_echo_skb_queue_tail() to deliver them in the right order with the received frames. The drivers already account these frames in the TX statistics (tx_packets, tx_bytes) with the length returned by these functions. As a result the RX statistics of rx-offload based drivers (e.g. mcp251xfd, flexcan, gs_usb, rockchip_canfd, m_can in peripheral mode) increase with every transmitted frame. can_rx_offload_napi_poll() can not distinguish echo skbs from received skbs: __can_get_echo_skb() resets skb->pkt_type from PACKET_LOOPBACK to PACKET_BROADCAST, and skb->sk is not set for all transmitted frames (e.g. frames forwarded by can-gw). Mark the echo skbs in the rx-offload control buffer, which already holds the timestamp for the sorted queue, when they are queued and skip them in the RX statistics. The flag is initialized in all queueing paths as the control buffer of an echo skb may still contain data from the transmit path. Fixes: 55059f2b7f86 ("can: rx-offload: introduce can_rx_offload_get_echo_skb() and can_rx_offload_queue_sorted() functions") Fixes: 8e0e2950c9ef ("can: rx-offload: add can_rx_offload_get_echo_skb_queue_tail()") Tested-by: Oliver Hartkopp Signed-off-by: Oliver Hartkopp --- drivers/net/can/dev/rx-offload.c | 36 +++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/drivers/net/can/dev/rx-offload.c b/drivers/net/can/dev/rx-offload.c index 46e7b6db4a1e..52d138865e84 100644 --- a/drivers/net/can/dev/rx-offload.c +++ b/drivers/net/can/dev/rx-offload.c @@ -8,10 +8,11 @@ #include #include struct can_rx_offload_cb { u32 timestamp; + bool echo; /* looped back TX frame, not counted as RX */ }; static inline struct can_rx_offload_cb * can_rx_offload_get_cb(struct sk_buff *skb) { @@ -50,13 +51,14 @@ static int can_rx_offload_napi_poll(struct napi_struct *napi, int quota) int work_done = 0; while ((work_done < quota) && (skb = skb_dequeue(&offload->skb_queue))) { struct can_frame *cf = (struct can_frame *)skb->data; + const struct can_rx_offload_cb *cb = can_rx_offload_get_cb(skb); work_done++; - if (!(cf->can_id & CAN_ERR_FLAG)) { + if (!(cf->can_id & CAN_ERR_FLAG) && !cb->echo) { stats->rx_packets++; if (!(cf->can_id & CAN_RTR_FLAG)) stats->rx_bytes += cf->len; } netif_receive_skb(skb); @@ -166,10 +168,11 @@ can_rx_offload_offload_one(struct can_rx_offload *offload, unsigned int n) } /* Mailbox was read. */ cb = can_rx_offload_get_cb(skb); cb->timestamp = timestamp; + cb->echo = false; return skb; } int can_rx_offload_irq_offload_timestamp(struct can_rx_offload *offload, @@ -217,12 +220,13 @@ int can_rx_offload_irq_offload_fifo(struct can_rx_offload *offload) return received; } EXPORT_SYMBOL_GPL(can_rx_offload_irq_offload_fifo); -int can_rx_offload_queue_timestamp(struct can_rx_offload *offload, - struct sk_buff *skb, u32 timestamp) +static int __can_rx_offload_queue_timestamp(struct can_rx_offload *offload, + struct sk_buff *skb, u32 timestamp, + bool echo) { struct can_rx_offload_cb *cb; if (skb_queue_len(&offload->skb_queue) > offload->skb_queue_len_max) { @@ -230,16 +234,23 @@ int can_rx_offload_queue_timestamp(struct can_rx_offload *offload, return -ENOBUFS; } cb = can_rx_offload_get_cb(skb); cb->timestamp = timestamp; + cb->echo = echo; __skb_queue_add_sort(&offload->skb_irq_queue, skb, can_rx_offload_compare); return 0; } + +int can_rx_offload_queue_timestamp(struct can_rx_offload *offload, + struct sk_buff *skb, u32 timestamp) +{ + return __can_rx_offload_queue_timestamp(offload, skb, timestamp, false); +} EXPORT_SYMBOL_GPL(can_rx_offload_queue_timestamp); unsigned int can_rx_offload_get_echo_skb_queue_timestamp(struct can_rx_offload *offload, unsigned int idx, u32 timestamp, @@ -253,33 +264,44 @@ can_rx_offload_get_echo_skb_queue_timestamp(struct can_rx_offload *offload, skb = __can_get_echo_skb(dev, idx, &len, frame_len_ptr); if (!skb) return 0; - err = can_rx_offload_queue_timestamp(offload, skb, timestamp); + err = __can_rx_offload_queue_timestamp(offload, skb, timestamp, true); if (err) { stats->rx_errors++; stats->tx_fifo_errors++; } return len; } EXPORT_SYMBOL_GPL(can_rx_offload_get_echo_skb_queue_timestamp); -int can_rx_offload_queue_tail(struct can_rx_offload *offload, - struct sk_buff *skb) +static int __can_rx_offload_queue_tail(struct can_rx_offload *offload, + struct sk_buff *skb, bool echo) { + struct can_rx_offload_cb *cb; + if (skb_queue_len(&offload->skb_queue) > offload->skb_queue_len_max) { dev_kfree_skb_any(skb); return -ENOBUFS; } + cb = can_rx_offload_get_cb(skb); + cb->echo = echo; + __skb_queue_tail(&offload->skb_irq_queue, skb); return 0; } + +int can_rx_offload_queue_tail(struct can_rx_offload *offload, + struct sk_buff *skb) +{ + return __can_rx_offload_queue_tail(offload, skb, false); +} EXPORT_SYMBOL_GPL(can_rx_offload_queue_tail); unsigned int can_rx_offload_get_echo_skb_queue_tail(struct can_rx_offload *offload, unsigned int idx, @@ -293,11 +315,11 @@ can_rx_offload_get_echo_skb_queue_tail(struct can_rx_offload *offload, skb = __can_get_echo_skb(dev, idx, &len, frame_len_ptr); if (!skb) return 0; - err = can_rx_offload_queue_tail(offload, skb); + err = __can_rx_offload_queue_tail(offload, skb, true); if (err) { stats->rx_errors++; stats->tx_fifo_errors++; } -- 2.53.0