Skip to contentSkip to conversation

pull-request: can 2024-09-12

PATCH Applied Marc Kleine-Budde 2 participants 9 messages Sep 12, 2024 – Sep 14, 2024

Subsystems (7)
lore
Share & tools
lore

Marc Kleine-Budde

author maintainer
#0 lore raw

cover pull-request: can 2024-09-12

Hello netdev-team,

this is a pull request of 5 patches for net/master.

Kuniyuki Iwashima's patch fixes an incomplete bug fix in the CAN BCM protocol, which was introduced during v6.11.

A patch by Stefan Mätje removes the unsupported CAN_CTRLMODE_3_SAMPLES mode for CAN-USB/3-FD devices in the esd_usb driver.

The next patch is by Martin Jocic and enables 64-bit DMA addressing for the kvaser_pciefd driver.

The last two patches both affect the m_can driver. Jake Hamby's patch activates NAPI before interrupts are activated, a patch by me moves the stopping of the clock after the device has been shut down.

regards,
Marc

---

The following changes since commit 6513eb3d3191574b58859ef2d6dc26c0277c6f81:

net: tighten bad gso csum offset check in virtio_net_hdr (2024-09-11 20:43:07 -0700)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git tags/linux-can-fixes-for-6.11-20240912

for you to fetch changes up to 717338e2b23309470e218f0c58177ece62b8d458:

Merge patch series "can: m_can: fix struct net_device_ops::{open,stop} callbacks under high bus load" (2024-09-12 09:47:36 +0200)

----------------------------------------------------------------
linux-can-fixes-for-6.11-20240912

----------------------------------------------------------------
Jake Hamby (1):
can: m_can: enable NAPI before enabling interrupts

Kuniyuki Iwashima (1):

      can: bcm: Clear bo->bcm_proc_read after remove_proc_entry().

Marc Kleine-Budde (2):
can: m_can: m_can_close(): stop clocks after device has been shut down
Merge patch series "can: m_can: fix struct net_device_ops::{open,stop} callbacks under high bus load"

Martin Jocic (1):
can: kvaser_pciefd: Enable 64-bit DMA addressing

Stefan Mätje (1):
can: esd_usb: Remove CAN_CTRLMODE_3_SAMPLES for CAN-USB/3-FD

 drivers/net/can/kvaser_pciefd.c |  3 +++
 drivers/net/can/m_can/m_can.c   | 14 +++++++-------
 drivers/net/can/usb/esd_usb.c   |  6 +-----
 net/can/bcm.c                   |  4 +++-
 4 files changed, 14 insertions(+), 13 deletions(-)
author maintainer
#1 lore raw

PATCH 1/5 can: bcm: Clear bo->bcm_proc_read after remove_proc_entry().

From: Kuniyuki Iwashima <[email protected]>

syzbot reported a warning in bcm_release(). [0]

The blamed change fixed another warning that is triggered when connect() is issued again for a socket whose connect()ed device has been unregistered.

However, if the socket is just close()d without the 2nd connect(), the remaining bo->bcm_proc_read triggers unnecessary remove_proc_entry() in bcm_release().

Let's clear bo->bcm_proc_read after remove_proc_entry() in bcm_notify().

[0]
name '4986'

WARNING: CPU: 0 PID: 5234 at fs/proc/generic.c:711 remove_proc_entry+0x2e7/0x5d0 fs/proc/generic.c:711
Modules linked in:
CPU: 0 UID: 0 PID: 5234 Comm: syz-executor606 Not tainted 6.11.0-rc5-syzkaller-00178-g5517ae241919 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
RIP: 0010:remove_proc_entry+0x2e7/0x5d0 fs/proc/generic.c:711
Code: ff eb 05 e8 cb 1e 5e ff 48 8b 5c 24 10 48 c7 c7 e0 f7 aa 8e e8 2a 38 8e 09 90 48 c7 c7 60 3a 1b 8c 48 89 de e8 da 42 20 ff 90 <0f> 0b 90 90 48 8b 44 24 18 48 c7 44 24 40 0e 36 e0 45 49 c7 04 07
RSP: 0018:ffffc9000345fa20 EFLAGS: 00010246
RAX: 2a2d0aee2eb64600 RBX: ffff888032f1f548 RCX: ffff888029431e00
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
RBP: ffffc9000345fb08 R08: ffffffff8155b2f2 R09: 1ffff1101710519a
R10: dffffc0000000000 R11: ffffed101710519b R12: ffff888011d38640
R13: 0000000000000004 R14: 0000000000000000 R15: dffffc0000000000
FS:  0000000000000000(0000) GS:ffff8880b8800000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fcfb52722f0 CR3: 000000000e734000 CR4: 00000000003506f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 bcm_release+0x250/0x880 net/can/bcm.c:1578
 __sock_release net/socket.c:659 [inline]
 sock_close+0xbc/0x240 net/socket.c:1421
 __fput+0x24a/0x8a0 fs/file_table.c:422
 task_work_run+0x24f/0x310 kernel/task_work.c:228
 exit_task_work include/linux/task_work.h:40 [inline]
 do_exit+0xa2f/0x27f0 kernel/exit.c:882
 do_group_exit+0x207/0x2c0 kernel/exit.c:1031
 __do_sys_exit_group kernel/exit.c:1042 [inline]
 __se_sys_exit_group kernel/exit.c:1040 [inline]
 __x64_sys_exit_group+0x3f/0x40 kernel/exit.c:1040
 x64_sys_call+0x2634/0x2640 arch/x86/include/generated/asm/syscalls_64.h:232
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fcfb51ee969
Code: Unable to access opcode bytes at 0x7fcfb51ee93f.
RSP: 002b:00007ffce0109ca8 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7
RAX: ffffffffffffffda RBX: 0000000000000001 RCX: 00007fcfb51ee969
RDX: 000000000000003c RSI: 00000000000000e7 RDI: 0000000000000001
RBP: 00007fcfb526f3b0 R08: ffffffffffffffb8 R09: 0000555500000000
R10: 0000555500000000 R11: 0000000000000246 R12: 00007fcfb526f3b0
R13: 0000000000000000 R14: 00007fcfb5271ee0 R15: 00007fcfb51bf160
 </TASK>
---
 net/can/bcm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/can/bcm.c +3 -1
index 46d3ec3aa44b..217049fa496e 100644
@@ -1471,8 +1471,10 @@ static void bcm_notify(struct bcm_sock *bo, unsigned long msg,
 		/* remove device reference, if this is our bound device */
 		if (bo->bound && bo->ifindex == dev->ifindex) {
 #if IS_ENABLED(CONFIG_PROC_FS)
-			if (sock_net(sk)->can.bcmproc_dir && bo->bcm_proc_read)
+			if (sock_net(sk)->can.bcmproc_dir && bo->bcm_proc_read) {
 				remove_proc_entry(bo->procname, sock_net(sk)->can.bcmproc_dir);
+				bo->bcm_proc_read = NULL;
+			}
 #endif
 			bo->bound   = 0;
 			bo->ifindex = 0;

base-commit: 6513eb3d3191574b58859ef2d6dc26c0277c6f81

Signature · 1 line
2.45.2
#2 lore raw

Re: [PATCH net 1/5] can: bcm: Clear bo->bcm_proc_read after remove_proc_entry().

This series was applied to netdev/net.git (main) by Marc Kleine-Budde <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Marc Kleine-Budde <[email protected]>:

Quoted 9 lines · On Thu, 12 Sep 2024 09:50:50 +0200 you wrote:

From: Kuniyuki Iwashima <[email protected]>

syzbot reported a warning in bcm_release(). [0]

The blamed change fixed another warning that is triggered when connect() is issued again for a socket whose connect()ed device has been unregistered.

[...]

Here is the summary with links:
- [net,1/5] can: bcm: Clear bo->bcm_proc_read after remove_proc_entry().

    https://git.kernel.org/netdev/net/c/94b0818fa635
  - [net,2/5] can: esd_usb: Remove CAN_CTRLMODE_3_SAMPLES for CAN-USB/3-FD
    https://git.kernel.org/netdev/net/c/75b318954057
  - [net,3/5] can: kvaser_pciefd: Enable 64-bit DMA addressing
    https://git.kernel.org/netdev/net/c/d0fa06408ccf
  - [net,5/5] can: m_can: m_can_close(): stop clocks after device has been shut down
    https://git.kernel.org/netdev/net/c/2c09b50efcad

- [net-next,4/5] can: rockchip_canfd: rkcanfd_timestamp_init(): rework delay calculation (no matching commit)

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#3 lore raw

Re: [PATCH net 1/5] can: bcm: Clear bo->bcm_proc_read after remove_proc_entry().

In reply to Marc Kleine-Budde
This series was applied to netdev/net-next.git (main) by Marc Kleine-Budde <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Marc Kleine-Budde <[email protected]>:

Quoted 9 lines · On Thu, 12 Sep 2024 09:50:50 +0200 you wrote:

From: Kuniyuki Iwashima <[email protected]>

syzbot reported a warning in bcm_release(). [0]

The blamed change fixed another warning that is triggered when connect() is issued again for a socket whose connect()ed device has been unregistered.

[...]

Here is the summary with links:
- [net,1/5] can: bcm: Clear bo->bcm_proc_read after remove_proc_entry(). (no matching commit)
- [net,2/5] can: esd_usb: Remove CAN_CTRLMODE_3_SAMPLES for CAN-USB/3-FD (no matching commit)
- [net,3/5] can: kvaser_pciefd: Enable 64-bit DMA addressing
(no matching commit)
- [net,5/5] can: m_can: m_can_close(): stop clocks after device has been shut down (no matching commit)
- [net-next,4/5] can: rockchip_canfd: rkcanfd_timestamp_init(): rework delay calculation

    https://git.kernel.org/netdev/net-next/c/cd0983c7f880

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
author maintainer
#4 lore raw

PATCH 2/5 can: esd_usb: Remove CAN_CTRLMODE_3_SAMPLES for CAN-USB/3-FD

In reply to Marc Kleine-Budde

From: Stefan Mätje <[email protected]>

Remove the CAN_CTRLMODE_3_SAMPLES announcement for CAN-USB/3-FD devices because these devices don't support it.

The hardware has a Microchip SAM E70 microcontroller that uses a Bosch MCAN IP core as CAN FD controller. But this MCAN core doesn't support triple sampling.

---
 drivers/net/can/usb/esd_usb.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/net/can/usb/esd_usb.c +1 -5
index 41a0e4261d15..03ad10b01867 100644
@@ -3,7 +3,7 @@
  * CAN driver for esd electronics gmbh CAN-USB/2, CAN-USB/3 and CAN-USB/Micro
  *
  * Copyright (C) 2010-2012 esd electronic system design gmbh, Matthias Fuchs <[email protected]>
- * Copyright (C) 2022-2023 esd electronics gmbh, Frank Jungclaus <[email protected]>
+ * Copyright (C) 2022-2024 esd electronics gmbh, Frank Jungclaus <[email protected]>
  */
 
 #include <linux/can.h>
@@ -1116,9 +1116,6 @@ static int esd_usb_3_set_bittiming(struct net_device *netdev)
 	if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
 		flags |= ESD_USB_3_BAUDRATE_FLAG_LOM;
 
-	if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES)
-		flags |= ESD_USB_3_BAUDRATE_FLAG_TRS;
-
 	baud_x->nom.brp = cpu_to_le16(nom_bt->brp & (nom_btc->brp_max - 1));
 	baud_x->nom.sjw = cpu_to_le16(nom_bt->sjw & (nom_btc->sjw_max - 1));
 	baud_x->nom.tseg1 = cpu_to_le16((nom_bt->prop_seg + nom_bt->phase_seg1)
@@ -1219,7 +1216,6 @@ static int esd_usb_probe_one_net(struct usb_interface *intf, int index)
 	switch (le16_to_cpu(dev->udev->descriptor.idProduct)) {
 	case ESD_USB_CANUSB3_PRODUCT_ID:
 		priv->can.clock.freq = ESD_USB_3_CAN_CLOCK;
-		priv->can.ctrlmode_supported |= CAN_CTRLMODE_3_SAMPLES;
 		priv->can.ctrlmode_supported |= CAN_CTRLMODE_FD;
 		priv->can.bittiming_const = &esd_usb_3_nom_bittiming_const;
 		priv->can.data_bittiming_const = &esd_usb_3_data_bittiming_const;
Signature · 1 line
2.45.2
author maintainer
#5 lore raw

PATCH 3/5 can: kvaser_pciefd: Enable 64-bit DMA addressing

In reply to Marc Kleine-Budde

From: Martin Jocic <[email protected]>

Enabling 64-bit addressing for DMA buffers will prevent issues on some memory constrained platforms like e.g. Raspberry Pi 5, where the driver won't load because it cannot allocate enough continuous memory in the default 32-bit memory address range.

---
 drivers/net/can/kvaser_pciefd.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/can/kvaser_pciefd.c +3 -0
index 9ffc3ffb4e8f..f86c9671a03a 100644
@@ -1104,6 +1104,9 @@ static int kvaser_pciefd_setup_dma(struct kvaser_pciefd *pcie)
 
 	/* Disable the DMA */
 	iowrite32(0, KVASER_PCIEFD_SRB_ADDR(pcie) + KVASER_PCIEFD_SRB_CTRL_REG);
+
+	dma_set_mask_and_coherent(&pcie->pci->dev, DMA_BIT_MASK(64));
+
 	for (i = 0; i < KVASER_PCIEFD_DMA_COUNT; i++) {
 		pcie->dma_data[i] = dmam_alloc_coherent(&pcie->pci->dev,
 							KVASER_PCIEFD_DMA_SIZE,
Signature · 1 line
2.45.2
author maintainer
#6 lore raw

PATCH 4/5 can: m_can: enable NAPI before enabling interrupts

In reply to Marc Kleine-Budde

From: Jake Hamby <[email protected]>

If an interrupt (RX-complete or error flag) is set when bringing up the CAN device, e.g. due to CAN bus traffic before initializing the device, when m_can_start() is called and interrupts are enabled, m_can_isr() is called immediately, which disables all CAN interrupts and calls napi_schedule().

Because napi_enable() isn't called until later in m_can_open(), the call to napi_schedule() never schedules the m_can_poll() callback and the device is left with interrupts disabled and can't receive any CAN packets until rebooted.

This can be verified by running "cansend" from another device before setting the bitrate and calling "ip link set up can0" on the test device. Adding debug lines to m_can_isr() shows it's called with flags (IR_EP | IR_EW | IR_CRCE), which calls m_can_disable_all_interrupts() and napi_schedule(), and then m_can_poll() is never called.

Move the call to napi_enable() above the call to m_can_start() to enable any initial interrupt flags to be handled by m_can_poll() so that interrupts are reenabled. Add a call to napi_disable() in the error handling section of m_can_open(), to handle the case where later functions return errors.

Also, in m_can_close(), move the call to napi_disable() below the call to m_can_stop() to ensure all interrupts are handled when bringing down the device. This race condition is much less likely to occur.

Tested on a Microchip SAMA7G54 MPU. The fix should be applicable to any SoC with a Bosch M_CAN controller.

Fixes e0d1f4816f2a ("can: m_can: add Bosch M_CAN controller support")
---
 drivers/net/can/m_can/m_can.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/can/m_can/m_can.c +6 -6
index 012c3d22b01d..c1a07013433e 100644
@@ -1763,9 +1763,6 @@ static int m_can_close(struct net_device *dev)
 
 	netif_stop_queue(dev);
 
-	if (!cdev->is_peripheral)
-		napi_disable(&cdev->napi);
-
 	m_can_stop(dev);
 	m_can_clk_stop(cdev);
 	free_irq(dev->irq, dev);
@@ -1776,6 +1773,8 @@ static int m_can_close(struct net_device *dev)
 		destroy_workqueue(cdev->tx_wq);
 		cdev->tx_wq = NULL;
 		can_rx_offload_disable(&cdev->offload);
+	} else {
+		napi_disable(&cdev->napi);
 	}
 
 	close_candev(dev);
@@ -2030,6 +2029,8 @@ static int m_can_open(struct net_device *dev)
 
 	if (cdev->is_peripheral)
 		can_rx_offload_enable(&cdev->offload);
+	else
+		napi_enable(&cdev->napi);
 
 	/* register interrupt handler */
 	if (cdev->is_peripheral) {
@@ -2063,9 +2064,6 @@ static int m_can_open(struct net_device *dev)
 	if (err)
 		goto exit_start_fail;
 
-	if (!cdev->is_peripheral)
-		napi_enable(&cdev->napi);
-
 	netif_start_queue(dev);
 
 	return 0;
@@ -2079,6 +2077,8 @@ static int m_can_open(struct net_device *dev)
 out_wq_fail:
 	if (cdev->is_peripheral)
 		can_rx_offload_disable(&cdev->offload);
+	else
+		napi_disable(&cdev->napi);
 	close_candev(dev);
 exit_disable_clks:
 	m_can_clk_stop(cdev);
Signature · 1 line
2.45.2
#7 lore raw

Re: [PATCH net 4/5] can: m_can: enable NAPI before enabling interrupts

This patch was applied to netdev/net.git (main) by Marc Kleine-Budde <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Marc Kleine-Budde <[email protected]>:

Quoted 9 lines · On Thu, 12 Sep 2024 09:50:53 +0200 you wrote:

From: Jake Hamby <[email protected]>

If an interrupt (RX-complete or error flag) is set when bringing up the CAN device, e.g. due to CAN bus traffic before initializing the device, when m_can_start() is called and interrupts are enabled, m_can_isr() is called immediately, which disables all CAN interrupts and calls napi_schedule().

[...]

Here is the summary with links:
- [net,4/5] can: m_can: enable NAPI before enabling interrupts

    https://git.kernel.org/netdev/net/c/801ad2f87b0c

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
author maintainer
#8 lore raw

PATCH 5/5 can: m_can: m_can_close(): stop clocks after device has been shut down

In reply to Marc Kleine-Budde

After calling m_can_stop() an interrupt may be pending or NAPI might still be executed. This means the driver might still touch registers of the IP core after the clocks have been disabled. This is not good practice and might lead to aborts depending on the SoC integration.

To avoid these potential problems, make m_can_close() symmetric to m_can_open(), i.e. stop the clocks at the end, right before shutting down the transceiver.

Fixes e0d1f4816f2a ("can: m_can: add Bosch M_CAN controller support")
---
 drivers/net/can/m_can/m_can.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/m_can/m_can.c +1 -1
index c1a07013433e..7fec04b024d5 100644
@@ -1764,7 +1764,6 @@ static int m_can_close(struct net_device *dev)
 	netif_stop_queue(dev);
 
 	m_can_stop(dev);
-	m_can_clk_stop(cdev);
 	free_irq(dev->irq, dev);
 
 	m_can_clean(dev);
@@ -1779,6 +1778,7 @@ static int m_can_close(struct net_device *dev)
 
 	close_candev(dev);
 
+	m_can_clk_stop(cdev);
 	phy_power_off(cdev->transceiver);
 
 	return 0;
Signature · 1 line
2.45.2