stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Oliver Hartkopp <socketcan@hartkopp.net>,
	Marc Kleine-Budde <mkl@pengutronix.de>,
	Sasha Levin <sashal@kernel.org>,
	davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
	linux-can@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 5.10 54/65] can: isotp: set default value for N_As to 50 micro seconds
Date: Fri,  1 Apr 2022 10:41:55 -0400	[thread overview]
Message-ID: <20220401144206.1953700-54-sashal@kernel.org> (raw)
In-Reply-To: <20220401144206.1953700-1-sashal@kernel.org>

From: Oliver Hartkopp <socketcan@hartkopp.net>

[ Upstream commit 530e0d46c61314c59ecfdb8d3bcb87edbc0f85d3 ]

The N_As value describes the time a CAN frame needs on the wire when
transmitted by the CAN controller. Even very short CAN FD frames need
arround 100 usecs (bitrate 1Mbit/s, data bitrate 8Mbit/s).

Having N_As to be zero (the former default) leads to 'no CAN frame
separation' when STmin is set to zero by the receiving node. This 'burst
mode' should not be enabled by default as it could potentially dump a high
number of CAN frames into the netdev queue from the soft hrtimer context.
This does not affect the system stability but is just not nice and
cooperative.

With this N_As/frame_txtime value the 'burst mode' is disabled by default.

As user space applications usually do not set the frame_txtime element
of struct can_isotp_options the new in-kernel default is very likely
overwritten with zero when the sockopt() CAN_ISOTP_OPTS is invoked.
To make sure that a N_As value of zero is only set intentional the
value '0' is now interpreted as 'do not change the current value'.
When a frame_txtime of zero is required for testing purposes this
CAN_ISOTP_FRAME_TXTIME_ZERO u32 value has to be set in frame_txtime.

Link: https://lore.kernel.org/all/20220309120416.83514-2-socketcan@hartkopp.net
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 include/uapi/linux/can/isotp.h | 28 ++++++++++++++++++++++------
 net/can/isotp.c                | 12 +++++++++++-
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/include/uapi/linux/can/isotp.h b/include/uapi/linux/can/isotp.h
index c55935b64ccc..590f8aea2b6d 100644
--- a/include/uapi/linux/can/isotp.h
+++ b/include/uapi/linux/can/isotp.h
@@ -137,20 +137,16 @@ struct can_isotp_ll_options {
 #define CAN_ISOTP_WAIT_TX_DONE	0x400	/* wait for tx completion */
 #define CAN_ISOTP_SF_BROADCAST	0x800	/* 1-to-N functional addressing */
 
-/* default values */
+/* protocol machine default values */
 
 #define CAN_ISOTP_DEFAULT_FLAGS		0
 #define CAN_ISOTP_DEFAULT_EXT_ADDRESS	0x00
 #define CAN_ISOTP_DEFAULT_PAD_CONTENT	0xCC /* prevent bit-stuffing */
-#define CAN_ISOTP_DEFAULT_FRAME_TXTIME	0
+#define CAN_ISOTP_DEFAULT_FRAME_TXTIME	50000 /* 50 micro seconds */
 #define CAN_ISOTP_DEFAULT_RECV_BS	0
 #define CAN_ISOTP_DEFAULT_RECV_STMIN	0x00
 #define CAN_ISOTP_DEFAULT_RECV_WFTMAX	0
 
-#define CAN_ISOTP_DEFAULT_LL_MTU	CAN_MTU
-#define CAN_ISOTP_DEFAULT_LL_TX_DL	CAN_MAX_DLEN
-#define CAN_ISOTP_DEFAULT_LL_TX_FLAGS	0
-
 /*
  * Remark on CAN_ISOTP_DEFAULT_RECV_* values:
  *
@@ -162,4 +158,24 @@ struct can_isotp_ll_options {
  * consistency and copied directly into the flow control (FC) frame.
  */
 
+/* link layer default values => make use of Classical CAN frames */
+
+#define CAN_ISOTP_DEFAULT_LL_MTU	CAN_MTU
+#define CAN_ISOTP_DEFAULT_LL_TX_DL	CAN_MAX_DLEN
+#define CAN_ISOTP_DEFAULT_LL_TX_FLAGS	0
+
+/*
+ * The CAN_ISOTP_DEFAULT_FRAME_TXTIME has become a non-zero value as
+ * it only makes sense for isotp implementation tests to run without
+ * a N_As value. As user space applications usually do not set the
+ * frame_txtime element of struct can_isotp_options the new in-kernel
+ * default is very likely overwritten with zero when the sockopt()
+ * CAN_ISOTP_OPTS is invoked.
+ * To make sure that a N_As value of zero is only set intentional the
+ * value '0' is now interpreted as 'do not change the current value'.
+ * When a frame_txtime of zero is required for testing purposes this
+ * CAN_ISOTP_FRAME_TXTIME_ZERO u32 value has to be set in frame_txtime.
+ */
+#define CAN_ISOTP_FRAME_TXTIME_ZERO	0xFFFFFFFF
+
 #endif /* !_UAPI_CAN_ISOTP_H */
diff --git a/net/can/isotp.c b/net/can/isotp.c
index d0581dc6a65f..1727298ec323 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -141,6 +141,7 @@ struct isotp_sock {
 	struct can_isotp_options opt;
 	struct can_isotp_fc_options rxfc, txfc;
 	struct can_isotp_ll_options ll;
+	u32 frame_txtime;
 	u32 force_tx_stmin;
 	u32 force_rx_stmin;
 	struct tpcon rx, tx;
@@ -360,7 +361,7 @@ static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
 
 		so->tx_gap = ktime_set(0, 0);
 		/* add transmission time for CAN frame N_As */
-		so->tx_gap = ktime_add_ns(so->tx_gap, so->opt.frame_txtime);
+		so->tx_gap = ktime_add_ns(so->tx_gap, so->frame_txtime);
 		/* add waiting time for consecutive frames N_Cs */
 		if (so->opt.flags & CAN_ISOTP_FORCE_TXSTMIN)
 			so->tx_gap = ktime_add_ns(so->tx_gap,
@@ -1236,6 +1237,14 @@ static int isotp_setsockopt_locked(struct socket *sock, int level, int optname,
 		/* no separate rx_ext_address is given => use ext_address */
 		if (!(so->opt.flags & CAN_ISOTP_RX_EXT_ADDR))
 			so->opt.rx_ext_address = so->opt.ext_address;
+
+		/* check for frame_txtime changes (0 => no changes) */
+		if (so->opt.frame_txtime) {
+			if (so->opt.frame_txtime == CAN_ISOTP_FRAME_TXTIME_ZERO)
+				so->frame_txtime = 0;
+			else
+				so->frame_txtime = so->opt.frame_txtime;
+		}
 		break;
 
 	case CAN_ISOTP_RECV_FC:
@@ -1437,6 +1446,7 @@ static int isotp_init(struct sock *sk)
 	so->opt.rxpad_content = CAN_ISOTP_DEFAULT_PAD_CONTENT;
 	so->opt.txpad_content = CAN_ISOTP_DEFAULT_PAD_CONTENT;
 	so->opt.frame_txtime = CAN_ISOTP_DEFAULT_FRAME_TXTIME;
+	so->frame_txtime = CAN_ISOTP_DEFAULT_FRAME_TXTIME;
 	so->rxfc.bs = CAN_ISOTP_DEFAULT_RECV_BS;
 	so->rxfc.stmin = CAN_ISOTP_DEFAULT_RECV_STMIN;
 	so->rxfc.wftmax = CAN_ISOTP_DEFAULT_RECV_WFTMAX;
-- 
2.34.1


  parent reply	other threads:[~2022-04-01 15:03 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-01 14:41 [PATCH AUTOSEL 5.10 01/65] drm: Add orientation quirk for GPD Win Max Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 02/65] ath5k: fix OOB in ath5k_eeprom_read_pcal_info_5111 Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 03/65] drm/amd/display: Add signal type check when verify stream backends same Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 04/65] drm/amd/amdgpu/amdgpu_cs: fix refcount leak of a dma_fence obj Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 05/65] usb: gadget: tegra-xudc: Do not program SPARAM Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 06/65] usb: gadget: tegra-xudc: Fix control endpoint's definitions Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 07/65] ptp: replace snprintf with sysfs_emit Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 08/65] powerpc: dts: t104xrdb: fix phy type for FMAN 4/5 Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 09/65] ath11k: fix kernel panic during unload/load ath11k modules Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 10/65] ath11k: mhi: use mhi_sync_power_up() Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 11/65] bpf: Make dst_port field in struct bpf_sock 16-bit wide Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 12/65] scsi: mvsas: Replace snprintf() with sysfs_emit() Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 13/65] scsi: bfa: " Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 14/65] power: supply: axp20x_battery: properly report current when discharging Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 15/65] mt76: dma: initialize skip_unmap in mt76_dma_rx_fill Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 16/65] cfg80211: don't add non transmitted BSS to 6GHz scanned channels Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 17/65] libbpf: Fix build issue with llvm-readelf Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 18/65] ipv6: make mc_forwarding atomic Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 19/65] powerpc: Set crashkernel offset to mid of RMA region Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 20/65] drm/amdgpu: Fix recursive locking warning Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 21/65] PCI: aardvark: Fix support for MSI interrupts Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 22/65] iommu/arm-smmu-v3: fix event handling soft lockup Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 23/65] usb: ehci: add pci device support for Aspeed platforms Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 24/65] PCI: endpoint: Fix alignment fault error in copy tests Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 25/65] tcp: Don't acquire inet_listen_hashbucket::lock with disabled BH Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 26/65] PCI: pciehp: Add Qualcomm quirk for Command Completed erratum Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 27/65] power: supply: axp288-charger: Set Vhold to 4.4V Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 28/65] iwlwifi: mvm: Correctly set fragmented EBS Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 29/65] ipv4: Invalidate neighbour for broadcast address upon address addition Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 30/65] dm ioctl: prevent potential spectre v1 gadget Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 31/65] dm: requeue IO if mapping table not yet available Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 32/65] drm/amdkfd: make CRAT table missing message informational only Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 33/65] scsi: pm8001: Fix pm80xx_pci_mem_copy() interface Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 34/65] scsi: pm8001: Fix pm8001_mpi_task_abort_resp() Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 35/65] scsi: pm8001: Fix task leak in pm8001_send_abort_all() Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 36/65] scsi: pm8001: Fix tag leaks on error Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 37/65] scsi: pm8001: Fix memory leak in pm8001_chip_fw_flash_update_req() Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 38/65] mt76: mt7615: Fix assigning negative values to unsigned variable Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 39/65] scsi: aha152x: Fix aha152x_setup() __setup handler return value Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 40/65] scsi: hisi_sas: Free irq vectors in order for v3 HW Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 41/65] net/smc: correct settings of RMB window update limit Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 42/65] mips: ralink: fix a refcount leak in ill_acc_of_setup() Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 43/65] macvtap: advertise link netns via netlink Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 44/65] tuntap: add sanity checks about msg_controllen in sendmsg Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 45/65] iommu/iova: Improve 32-bit free space estimate Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 46/65] Bluetooth: Fix not checking for valid hdev on bt_dev_{info,warn,err,dbg} Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 47/65] Bluetooth: use memset avoid memory leaks Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 48/65] bnxt_en: Eliminate unintended link toggle during FW reset Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 49/65] PCI: endpoint: Fix misused goto label Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 50/65] MIPS: fix fortify panic when copying asm exception handlers Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 51/65] powerpc/code-patching: Pre-map patch area Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 52/65] powerpc/secvar: fix refcount leak in format_show() Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 53/65] scsi: libfc: Fix use after free in fc_exch_abts_resp() Sasha Levin
2022-04-01 14:41 ` Sasha Levin [this message]
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 55/65] net: account alternate interface name memory Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 56/65] net: limit altnames to 64k total Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 57/65] net: sfp: add 2500base-X quirk for Lantech SFP module Sasha Levin
2022-04-01 14:41 ` [PATCH AUTOSEL 5.10 58/65] usb: dwc3: omap: fix "unbalanced disables for smps10_out1" on omap5evm Sasha Levin
2022-04-01 14:42 ` [PATCH AUTOSEL 5.10 59/65] xtensa: fix DTC warning unit_address_format Sasha Levin
2022-04-01 14:42 ` [PATCH AUTOSEL 5.10 60/65] MIPS: ingenic: correct unit node address Sasha Levin
2022-04-01 14:42 ` [PATCH AUTOSEL 5.10 61/65] Bluetooth: Fix use after free in hci_send_acl Sasha Levin
2022-04-01 14:42 ` [PATCH AUTOSEL 5.10 62/65] netlabel: fix out-of-bounds memory accesses Sasha Levin
2022-04-01 14:42 ` [PATCH AUTOSEL 5.10 63/65] ceph: fix memory leak in ceph_readdir when note_last_dentry returns error Sasha Levin
2022-04-01 14:42 ` [PATCH AUTOSEL 5.10 64/65] init/main.c: return 1 from handled __setup() functions Sasha Levin
2022-04-01 14:42 ` [PATCH AUTOSEL 5.10 65/65] minix: fix bug when opening a file with O_DIRECT Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220401144206.1953700-54-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=socketcan@hartkopp.net \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).