Skip to contentSkip to conversation

tty/serial: Cancel work queue before closing uart

PATCH In review Wenhua Lin 5 participants 6 messages Aug 18, 2023 – Aug 24, 2023

Subsystems (2)
lore
Share & tools
lore

Wenhua Lin

author
#0 lore raw

PATCH 1/1 tty/serial: Cancel work queue before closing uart

When the system constantly sleeps and wankes up, plugging and unplugging the USB will probalility trigger a kernel crash problem. The reason is that at this time, the system entered deep and turned off uart, and the abnormal behavior of plugging and upplugging the USB triggered the read data process of uart, causing access to uart to hang. The final solution we came up with is to cancel the work queue before shutting down uart , while ensuring that there is no uart business.

---
 drivers/tty/serial/sprd_serial.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/tty/serial/sprd_serial.c +4 -0
index b58f51296ace..eddff4360155 100644
@@ -20,6 +20,7 @@
 #include <linux/slab.h>
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
+#include "../tty.h"
 
 /* device name */
 #define UART_NR_MAX		8
@@ -1221,7 +1222,10 @@ static int sprd_probe(struct platform_device *pdev)
 static int sprd_suspend(struct device *dev)
 {
 	struct sprd_uart_port *sup = dev_get_drvdata(dev);
+	struct uart_port *uport = &sup->port;
+	struct tty_port *tty = &uport->state->port;
 
+	tty_buffer_cancel_work(tty);
 	uart_suspend_port(&sprd_uart_driver, &sup->port);
 
 	return 0;
Signature · 1 line
2.17.1
#1 lore raw
kernel test robot noticed the following build errors:

Hi Wenhua,

kernel test robot noticed the following build errors:

[auto build test ERROR on tty/tty-testing]
[also build test ERROR on tty/tty-next tty/tty-linus usb/usb-testing usb/usb-next usb/usb-linus linus/master v6.5-rc7 next-20230821] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Wenhua-Lin/tty-serial-Cancel-work-queue-before-closing-uart/20230818-111905
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing
patch link:    https://lore.kernel.org/r/20230818031532.15591-1-Wenhua.Lin%40unisoc.com
patch subject: [PATCH] tty/serial: Cancel work queue before closing uart
config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20230822/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230822/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>, old ones prefixed by <<):

WARNING: modpost: missing MODULE_DESCRIPTION() in net/netfilter/ipvs/ip_vs_lc.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/netfilter/ipvs/ip_vs_wlc.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/netfilter/ipvs/ip_vs_fo.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/netfilter/ipvs/ip_vs_ovf.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/netfilter/ipvs/ip_vs_lblc.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/netfilter/ipvs/ip_vs_lblcr.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/netfilter/ipvs/ip_vs_dh.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/netfilter/ipvs/ip_vs_sh.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/netfilter/ipvs/ip_vs_sed.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/netfilter/ipvs/ip_vs_nq.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/netfilter/ipvs/ip_vs_twos.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/netfilter/ipvs/ip_vs_ftp.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/netfilter/ipvs/ip_vs_pe_sip.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv4/netfilter/nf_defrag_ipv4.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv4/netfilter/nf_reject_ipv4.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv4/netfilter/iptable_nat.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv4/netfilter/iptable_raw.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv4/ip_tunnel.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv4/ipip.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv4/ip_gre.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv4/udp_tunnel.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv4/ip_vti.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv4/ah4.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv4/esp4.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv4/xfrm4_tunnel.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv4/tunnel4.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv4/inet_diag.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv4/tcp_diag.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv4/udp_diag.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv4/raw_diag.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/xfrm/xfrm_algo.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/xfrm/xfrm_user.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/unix/unix_diag.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv6/netfilter/ip6table_raw.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv6/netfilter/ip6table_nat.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv6/netfilter/nf_defrag_ipv6.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv6/netfilter/nf_reject_ipv6.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv6/ah6.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv6/esp6.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv6/xfrm6_tunnel.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv6/tunnel6.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv6/mip6.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv6/sit.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ipv6/ip6_udp_tunnel.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/bpfilter/bpfilter.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_ar9331.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_brcm.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_dsa.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_gswip.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_hellcreek.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_ksz.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_lan9303.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_mtk.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_none.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_ocelot.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_ocelot_8021q.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_qca.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_rtl4_a.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_rtl8_4.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_rzn1_a5psw.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_sja1105.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_trailer.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/dsa/tag_xrs700x.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/8021q/8021q.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/xdp/xsk_diag.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/mptcp/mptcp_diag.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/mptcp/mptcp_crypto_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/mptcp/mptcp_token_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/packet/af_packet.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/packet/af_packet_diag.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/key/af_key.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/bridge/netfilter/nf_conntrack_bridge.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/bridge/netfilter/ebtables.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/bridge/netfilter/ebtable_broute.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/bridge/netfilter/ebtable_filter.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/bridge/netfilter/ebtable_nat.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/bridge/bridge.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/sunrpc/sunrpc.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/sunrpc/auth_gss/auth_rpcgss.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/sunrpc/auth_gss/rpcsec_gss_krb5.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/kcm/kcm.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/atm/atm.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/atm/lec.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/atm/mpoa.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/sctp/sctp_diag.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/tipc/diag.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/smc/smc_diag.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/caif/caif.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/caif/chnl_net.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/caif/caif_socket.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/caif/caif_usb.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/6lowpan/6lowpan.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ieee802154/6lowpan/ieee802154_6lowpan.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/ieee802154/ieee802154_socket.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/nfc/nci/nci.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/nfc/nci/nci_spi.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/nfc/nfc_digital.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/vmw_vsock/vsock_diag.o
WARNING: modpost: missing MODULE_DESCRIPTION() in net/hsr/hsr.o
WARNING: modpost: missing MODULE_DESCRIPTION() in arch/x86/video/fbdev.o

>> ERROR: modpost: "tty_buffer_cancel_work" [drivers/tty/serial/sprd_serial.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#2 lore raw
In reply to Wenhua Lin

On Fri, 18 Aug 2023, Wenhua Lin wrote:

I've problems following your description below due to grammar errors.

Quoted 1 line

When the system constantly sleeps and wankes up, plugging and unplugging

wakes

Quoted 1 line

the USB will probalility trigger a kernel crash problem.

probalility is typoed and I cannot guess which of the words you meant, please fix.

If there's a known crash you're fixing here, please quote the crash message in the changelog (and you should probably add Fixes: tag too in that case).

Quoted 2 lines

The reason is
that at this time, the system entered deep and turned off uart, and the

"entered deep" lacks probably some word?

Quoted 1 line

abnormal behavior of plugging and upplugging the USB triggered the read

unplugging.

Why call that abnormal behavior? Isn't USB expected to removed.

Quoted 1 line

data process of uart, causing access to uart to hang.

Are you saying a read was triggered while the UART was suspended or what?

Quoted 3 lines

The final solution
we came up with is to cancel the work queue before shutting down uart , while ensuring that there is no uart business.

", while ensuring" -> to ensure

"uart business" is too vague, you should replace it with something more concrete.

Thanks.

--
i.

Quoted 30 lines
---
 drivers/tty/serial/sprd_serial.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/tty/serial/sprd_serial.c +4 -0
index b58f51296ace..eddff4360155 100644
@@ -20,6 +20,7 @@
 #include <linux/slab.h>
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
+#include "../tty.h"
 
 /* device name */
 #define UART_NR_MAX		8
@@ -1221,7 +1222,10 @@ static int sprd_probe(struct platform_device *pdev)
 static int sprd_suspend(struct device *dev)
 {
 	struct sprd_uart_port *sup = dev_get_drvdata(dev);
+	struct uart_port *uport = &sup->port;
+	struct tty_port *tty = &uport->state->port;
 
+	tty_buffer_cancel_work(tty);
 	uart_suspend_port(&sprd_uart_driver, &sup->port);
 
 	return 0;
#3 lore raw
Quoted 33 lines · Ilpo Järvinen

On Fri, 18 Aug 2023, Wenhua Lin wrote:

I've problems following your description below due to grammar errors.

Quoted 1 line

When the system constantly sleeps and wankes up, plugging and unplugging

wakes

Quoted 1 line

the USB will probalility trigger a kernel crash problem.

probalility is typoed and I cannot guess which of the words you meant, please fix.

If there's a known crash you're fixing here, please quote the crash message in the changelog (and you should probably add Fixes: tag too in that case).

Quoted 2 lines

The reason is
that at this time, the system entered deep and turned off uart, and the

"entered deep" lacks probably some word?

Quoted 1 line

abnormal behavior of plugging and upplugging the USB triggered the read

unplugging.

Why call that abnormal behavior? Isn't USB expected to removed.

Quoted 1 line

data process of uart, causing access to uart to hang.

Are you saying a read was triggered while the UART was suspended or what?

Quoted 8 lines
Quoted 3 lines

The final solution
we came up with is to cancel the work queue before shutting down uart , while ensuring that there is no uart business.

", while ensuring" -> to ensure

"uart business" is too vague, you should replace it with something more concrete.

We will fix it in patch v2, thank you for your review.

Quoted 36 lines

Thanks.

--
i.

Quoted 30 lines
---
 drivers/tty/serial/sprd_serial.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/tty/serial/sprd_serial.c +4 -0
index b58f51296ace..eddff4360155 100644
@@ -20,6 +20,7 @@
 #include <linux/slab.h>
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
+#include "../tty.h"
 
 /* device name */
 #define UART_NR_MAX          8
@@ -1221,7 +1222,10 @@ static int sprd_probe(struct platform_device *pdev)
 static int sprd_suspend(struct device *dev)
 {
      struct sprd_uart_port *sup = dev_get_drvdata(dev);
+     struct uart_port *uport = &sup->port;
+     struct tty_port *tty = &uport->state->port;
 
+     tty_buffer_cancel_work(tty);
      uart_suspend_port(&sprd_uart_driver, &sup->port);
 
      return 0;
#4 lore raw
In reply to Wenhua Lin
Quoted 26 lines · Wenhua Lin

When the system constantly sleeps and wankes up, plugging and unplugging the USB will probalility trigger a kernel crash problem. The reason is that at this time, the system entered deep and turned off uart, and the abnormal behavior of plugging and upplugging the USB triggered the read data process of uart, causing access to uart to hang. The final solution we came up with is to cancel the work queue before shutting down uart , while ensuring that there is no uart business.

---
 drivers/tty/serial/sprd_serial.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/tty/serial/sprd_serial.c +1 -0
index b58f51296ace..eddff4360155 100644
@@ -20,6 +20,7 @@
 #include <linux/slab.h>
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
+#include "../tty.h"
 
 /* device name */
 #define UART_NR_MAX		8

drivers/tty/serial/sprd_serial.c static int sprd_probe(struct platform_device *pdev) · line 1228

Quoted 7 lines
drivers/tty/serial/sprd_serial.c +3 -0
@@ -1221,7 +1222,10 @@ static int sprd_probe(struct platform_device *pdev)
 static int sprd_suspend(struct device *dev)
 {
 	struct sprd_uart_port *sup = dev_get_drvdata(dev);
+	struct uart_port *uport = &sup->port;
+	struct tty_port *tty = &uport->state->port;
 
+	tty_buffer_cancel_work(tty);

What does this serial port have to do with the USB subsystem in your changelog text?

And as the kernel bot said, this breaks the build, you can't do this within a serial driver, sorry.

greg k-h

#5 lore raw
Quoted 34 lines · Greg Kroah-Hartman
Quoted 32 lines · Wenhua Lin

When the system constantly sleeps and wankes up, plugging and unplugging the USB will probalility trigger a kernel crash problem. The reason is that at this time, the system entered deep and turned off uart, and the abnormal behavior of plugging and upplugging the USB triggered the read data process of uart, causing access to uart to hang. The final solution we came up with is to cancel the work queue before shutting down uart , while ensuring that there is no uart business.

---
 drivers/tty/serial/sprd_serial.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/tty/serial/sprd_serial.c +3 -0
index b58f51296ace..eddff4360155 100644
@@ -20,6 +20,7 @@
 #include <linux/slab.h>
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
+#include "../tty.h"
 
 /* device name */
 #define UART_NR_MAX          8
@@ -1221,7 +1222,10 @@ static int sprd_probe(struct platform_device *pdev)
 static int sprd_suspend(struct device *dev)
 {
      struct sprd_uart_port *sup = dev_get_drvdata(dev);
+     struct uart_port *uport = &sup->port;
+     struct tty_port *tty = &uport->state->port;
 
Quoted 7 lines

drivers/tty/serial/sprd_serial.c static int sprd_probe(struct platform_device *pdev) · line 1228

Quoted 1 line
drivers/tty/serial/sprd_serial.c +1 -0
+     tty_buffer_cancel_work(tty);

What does this serial port have to do with the USB subsystem in your changelog text?

And as the kernel bot said, this breaks the build, you can't do this within a serial driver, sorry.

This modification is not directly related to the usb subsystem. I just described a problem scenario, such as the previous comment. There may be problems with this solution. I will make changes on patch v2, thank you for your review

Quoted 2 lines

greg k-h