From patchwork Thu Nov 25 17:20:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol X-Patchwork-Id: 12693688 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6DFE7C433F5 for ; Thu, 25 Nov 2021 17:23:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=UmqEkfdv+pfzk4hbyqNGXiVKv/GaWYxBwwmaWVQ0DG4=; b=cFfc3sNFDjieI6 /6dHyKsMKTvoTuQPHRzsswmHwJrxE+lIxBXIWdX4OHWTBAeD9rrWsp1tMwYnxAQP0Km8LqyoRpqBB dqWOUJd7Yx3LwVUUIaAIDnjXNpZ1so85QrcloymrB/X1qAQ4jt+rLZT7smTchuetPGk1CijsdgPXb hEK7GsXvOmkbUJ63gNMKil8K+TJBYAJMeo8kKWWZwEUKkkAPu32UXeoGORorY0r/2Ttud6UhNn9Vq hRq7f0b4XJMTLav/AnoSn3Ri4zNdO44gqcv2NSSlYbO+TU+O+AY6Q5shuWK37JdR0Kjq4keiIxUmb OFyGNrcrbVEaNAvyoCPA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqIQi-008MFW-9l; Thu, 25 Nov 2021 17:21:04 +0000 Received: from smtp09.smtpout.orange.fr ([80.12.242.131] helo=smtp.smtpout.orange.fr) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqIQc-008MFC-RO for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 17:21:01 +0000 Received: from tomoyo.flets-east.jp ([114.149.34.46]) by smtp.orange.fr with ESMTPA id qIQDm0ronE8xTqIQKm0kjf; Thu, 25 Nov 2021 18:20:45 +0100 X-ME-Helo: tomoyo.flets-east.jp X-ME-Auth: MDU0YmViZGZmMDIzYiBlMiM2NTczNTRjNWZkZTMwOGRiOGQ4ODf3NWI1ZTMyMzdiODlhOQ== X-ME-Date: Thu, 25 Nov 2021 18:20:45 +0100 X-ME-IP: 114.149.34.46 From: Vincent Mailhol To: Marc Kleine-Budde , linux-can@vger.kernel.org Cc: Oliver Hartkopp , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Vincent Mailhol Subject: [PATCH v2 0/5] fix statistics and payload issues for error Date: Fri, 26 Nov 2021 02:20:16 +0900 Message-Id: <20211125172021.976384-1-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_092059_459853_A6E5E7ED X-CRM114-Status: GOOD ( 22.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Important: this patch series depends on below patch: https://lore.kernel.org/linux-can/20211123111654.621610-1-mailhol.vincent@wanadoo.fr/T/#u There are some common errors which are made when updating the network statistics or processing the CAN payload: 1. Incrementing the "normal" stats when generating or sending a CAN error message frame. Error message frames are an abstraction of Socket CAN and do not exist on the wire. The first patch of this series fixes the RX stats for 22 different drivers, the second one fixes the TX stasts for the kvaser driver (N.B. only this driver is capable of sending error on the bus). 2. Copying the payload of RTR frames: RTR frames have no payload and the data buffer only contains garbage. The DLC/length should not be used to do a memory copy. The third patch of this series address this issue for 3 different drivers. 3. Counting the length of the Remote Transmission Frames (RTR). The length of an RTR frame is the length of the requested frame not the actual payload. In reality the payload of an RTR frame is always 0 bytes long. The fourth patch of this series fixes the RX stats for 27 different drivers and the fifth one fixes the TX stats for 25 different ones. * Changelog * v1 -> v2: * can_rx_offload_napi_poll: v1 used CAN_ERR_MASK instead of CAN_ERR_FLAG. Fixed the issue. * use correct vocabulary. The correct term to designate the Socket CAN specific error skb is "error message frames" not "error frames". "error frames" is used in the standard and has a different meaning. * better factorize code for the rx RTR frames. Most of the driver already has a switch to check if the frame is a RTR. Moved the instruction to increase net_device_stats:rx_bytes inside the else branch of those switches whenever possible (for some drivers with some complex logic, putting and additional RTR check was easier). * add a patch which prevent drivers to copy the payload of RTR frames. * add a patch to cover the tx RTR frames (the fifth patch of v2). The tx RTR frames issue was supposedly covered by the can_get_echo_skb() function which returns the correct length for drivers to increase their stats. However, the reality is that most of the drivers do not check this value and instead use a local copy of the length/dlc. Vincent Mailhol (5): can: do not increase rx statistics when generating a CAN rx error message frame can: kvaser_usb: do not increase tx statistics when sending error message frames can: do not copy the payload of RTR frames can: do not increase rx_bytes statistics for RTR frames can: do not increase tx_bytes statistics for RTR frames drivers/net/can/at91_can.c | 18 ++--- drivers/net/can/c_can/c_can.h | 1 - drivers/net/can/c_can/c_can_main.c | 16 +--- drivers/net/can/cc770/cc770.c | 16 ++-- drivers/net/can/dev/dev.c | 4 - drivers/net/can/dev/rx-offload.c | 7 +- drivers/net/can/grcan.c | 6 +- drivers/net/can/ifi_canfd/ifi_canfd.c | 11 +-- drivers/net/can/janz-ican3.c | 6 +- drivers/net/can/kvaser_pciefd.c | 16 ++-- drivers/net/can/m_can/m_can.c | 13 +--- drivers/net/can/mscan/mscan.c | 14 ++-- drivers/net/can/pch_can.c | 33 ++++---- drivers/net/can/peak_canfd/peak_canfd.c | 14 ++-- drivers/net/can/rcar/rcar_can.c | 22 +++--- drivers/net/can/rcar/rcar_canfd.c | 13 +--- drivers/net/can/sja1000/sja1000.c | 11 +-- drivers/net/can/slcan.c | 7 +- drivers/net/can/softing/softing_main.c | 8 +- drivers/net/can/spi/hi311x.c | 31 ++++---- drivers/net/can/spi/mcp251x.c | 31 ++++---- drivers/net/can/sun4i_can.c | 22 +++--- drivers/net/can/usb/ems_usb.c | 14 ++-- drivers/net/can/usb/esd_usb2.c | 13 ++-- drivers/net/can/usb/etas_es58x/es58x_core.c | 7 -- drivers/net/can/usb/gs_usb.c | 7 +- drivers/net/can/usb/kvaser_usb/kvaser_usb.h | 5 +- .../net/can/usb/kvaser_usb/kvaser_usb_core.c | 4 +- .../net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 78 +++++++++---------- .../net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 20 ++--- drivers/net/can/usb/mcba_usb.c | 23 +++--- drivers/net/can/usb/peak_usb/pcan_usb.c | 9 +-- drivers/net/can/usb/peak_usb/pcan_usb_core.c | 20 +++-- drivers/net/can/usb/peak_usb/pcan_usb_core.h | 1 - drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 11 +-- drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 12 +-- drivers/net/can/usb/ucan.c | 17 ++-- drivers/net/can/usb/usb_8dev.c | 17 ++-- drivers/net/can/vcan.c | 7 +- drivers/net/can/vxcan.c | 2 +- drivers/net/can/xilinx_can.c | 19 ++--- include/linux/can/skb.h | 5 +- 42 files changed, 258 insertions(+), 353 deletions(-) base-commit: 4cc19cc269921210f3da65e4b038ad987835b342