Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Revert "tty: n_gsm: avoid call of sleeping functions from atomic context"

This reverts commit 902e02ea9385373ce4b142576eef41c642703955.

The above commit is reverted as the usage of tx_mutex seems not to solve
the problem described in 902e02ea9385 ("tty: n_gsm: avoid call of sleeping
functions from atomic context") and just moves the bug to another place.

Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Reviewed-by: Daniel Starke <daniel.starke@siemens.com>
Link: https://lore.kernel.org/r/20221008110221.13645-2-pchelkin@ispras.ru
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Fedor Pchelkin and committed by
Greg Kroah-Hartman
acdab4cb 4561d800

+29 -24
+29 -24
drivers/tty/n_gsm.c
··· 264 264 bool constipated; /* Asked by remote to shut up */ 265 265 bool has_devices; /* Devices were registered */ 266 266 267 - struct mutex tx_mutex; 267 + spinlock_t tx_lock; 268 268 unsigned int tx_bytes; /* TX data outstanding */ 269 269 #define TX_THRESH_HI 8192 270 270 #define TX_THRESH_LO 2048 ··· 700 700 struct gsm_msg *msg; 701 701 u8 *dp; 702 702 int ocr; 703 + unsigned long flags; 703 704 704 705 msg = gsm_data_alloc(gsm, addr, 0, control); 705 706 if (!msg) ··· 722 721 723 722 gsm_print_packet("Q->", addr, cr, control, NULL, 0); 724 723 725 - mutex_lock(&gsm->tx_mutex); 724 + spin_lock_irqsave(&gsm->tx_lock, flags); 726 725 list_add_tail(&msg->list, &gsm->tx_ctrl_list); 727 726 gsm->tx_bytes += msg->len; 728 - mutex_unlock(&gsm->tx_mutex); 727 + spin_unlock_irqrestore(&gsm->tx_lock, flags); 729 728 gsmld_write_trigger(gsm); 730 729 731 730 return 0; ··· 750 749 spin_unlock_irqrestore(&dlci->lock, flags); 751 750 752 751 /* Clear data packets in MUX write queue */ 753 - mutex_lock(&gsm->tx_mutex); 752 + spin_lock_irqsave(&gsm->tx_lock, flags); 754 753 list_for_each_entry_safe(msg, nmsg, &gsm->tx_data_list, list) { 755 754 if (msg->addr != addr) 756 755 continue; ··· 758 757 list_del(&msg->list); 759 758 kfree(msg); 760 759 } 761 - mutex_unlock(&gsm->tx_mutex); 760 + spin_unlock_irqrestore(&gsm->tx_lock, flags); 762 761 } 763 762 764 763 /** ··· 1044 1043 1045 1044 static void gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg) 1046 1045 { 1047 - mutex_lock(&dlci->gsm->tx_mutex); 1046 + unsigned long flags; 1047 + spin_lock_irqsave(&dlci->gsm->tx_lock, flags); 1048 1048 __gsm_data_queue(dlci, msg); 1049 - mutex_unlock(&dlci->gsm->tx_mutex); 1049 + spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); 1050 1050 } 1051 1051 1052 1052 /** ··· 1059 1057 * is data. Keep to the MRU of the mux. This path handles the usual tty 1060 1058 * interface which is a byte stream with optional modem data. 1061 1059 * 1062 - * Caller must hold the tx_mutex of the mux. 1060 + * Caller must hold the tx_lock of the mux. 1063 1061 */ 1064 1062 1065 1063 static int gsm_dlci_data_output(struct gsm_mux *gsm, struct gsm_dlci *dlci) ··· 1119 1117 * is data. Keep to the MRU of the mux. This path handles framed data 1120 1118 * queued as skbuffs to the DLCI. 1121 1119 * 1122 - * Caller must hold the tx_mutex of the mux. 1120 + * Caller must hold the tx_lock of the mux. 1123 1121 */ 1124 1122 1125 1123 static int gsm_dlci_data_output_framed(struct gsm_mux *gsm, ··· 1135 1133 if (dlci->adaption == 4) 1136 1134 overhead = 1; 1137 1135 1138 - /* dlci->skb is locked by tx_mutex */ 1136 + /* dlci->skb is locked by tx_lock */ 1139 1137 if (dlci->skb == NULL) { 1140 1138 dlci->skb = skb_dequeue_tail(&dlci->skb_list); 1141 1139 if (dlci->skb == NULL) ··· 1189 1187 * Push an empty frame in to the transmit queue to update the modem status 1190 1188 * bits and to transmit an optional break. 1191 1189 * 1192 - * Caller must hold the tx_mutex of the mux. 1190 + * Caller must hold the tx_lock of the mux. 1193 1191 */ 1194 1192 1195 1193 static int gsm_dlci_modem_output(struct gsm_mux *gsm, struct gsm_dlci *dlci, ··· 1303 1301 1304 1302 static void gsm_dlci_data_kick(struct gsm_dlci *dlci) 1305 1303 { 1304 + unsigned long flags; 1306 1305 int sweep; 1307 1306 1308 1307 if (dlci->constipated) 1309 1308 return; 1310 1309 1311 - mutex_lock(&dlci->gsm->tx_mutex); 1310 + spin_lock_irqsave(&dlci->gsm->tx_lock, flags); 1312 1311 /* If we have nothing running then we need to fire up */ 1313 1312 sweep = (dlci->gsm->tx_bytes < TX_THRESH_LO); 1314 1313 if (dlci->gsm->tx_bytes == 0) { ··· 1320 1317 } 1321 1318 if (sweep) 1322 1319 gsm_dlci_data_sweep(dlci->gsm); 1323 - mutex_unlock(&dlci->gsm->tx_mutex); 1320 + spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); 1324 1321 } 1325 1322 1326 1323 /* ··· 2032 2029 static void gsm_kick_timeout(struct work_struct *work) 2033 2030 { 2034 2031 struct gsm_mux *gsm = container_of(work, struct gsm_mux, kick_timeout.work); 2032 + unsigned long flags; 2035 2033 int sent = 0; 2036 2034 2037 - mutex_lock(&gsm->tx_mutex); 2035 + spin_lock_irqsave(&gsm->tx_lock, flags); 2038 2036 /* If we have nothing running then we need to fire up */ 2039 2037 if (gsm->tx_bytes < TX_THRESH_LO) 2040 2038 sent = gsm_dlci_data_sweep(gsm); 2041 - mutex_unlock(&gsm->tx_mutex); 2039 + spin_unlock_irqrestore(&gsm->tx_lock, flags); 2042 2040 2043 2041 if (sent && debug & DBG_DATA) 2044 2042 pr_info("%s TX queue stalled\n", __func__); ··· 2569 2565 break; 2570 2566 } 2571 2567 } 2572 - mutex_destroy(&gsm->tx_mutex); 2573 2568 mutex_destroy(&gsm->mutex); 2574 2569 kfree(gsm->txframe); 2575 2570 kfree(gsm->buf); ··· 2640 2637 } 2641 2638 spin_lock_init(&gsm->lock); 2642 2639 mutex_init(&gsm->mutex); 2643 - mutex_init(&gsm->tx_mutex); 2644 2640 kref_init(&gsm->ref); 2645 2641 INIT_LIST_HEAD(&gsm->tx_ctrl_list); 2646 2642 INIT_LIST_HEAD(&gsm->tx_data_list); ··· 2648 2646 INIT_WORK(&gsm->tx_work, gsmld_write_task); 2649 2647 init_waitqueue_head(&gsm->event); 2650 2648 spin_lock_init(&gsm->control_lock); 2649 + spin_lock_init(&gsm->tx_lock); 2651 2650 2652 2651 gsm->t1 = T1; 2653 2652 gsm->t2 = T2; ··· 2673 2670 } 2674 2671 spin_unlock(&gsm_mux_lock); 2675 2672 if (i == MAX_MUX) { 2676 - mutex_destroy(&gsm->tx_mutex); 2677 2673 mutex_destroy(&gsm->mutex); 2678 2674 kfree(gsm->txframe); 2679 2675 kfree(gsm->buf); ··· 2828 2826 static void gsmld_write_task(struct work_struct *work) 2829 2827 { 2830 2828 struct gsm_mux *gsm = container_of(work, struct gsm_mux, tx_work); 2829 + unsigned long flags; 2831 2830 int i, ret; 2832 2831 2833 2832 /* All outstanding control channel and control messages and one data 2834 2833 * frame is sent. 2835 2834 */ 2836 2835 ret = -ENODEV; 2837 - mutex_lock(&gsm->tx_mutex); 2836 + spin_lock_irqsave(&gsm->tx_lock, flags); 2838 2837 if (gsm->tty) 2839 2838 ret = gsm_data_kick(gsm); 2840 - mutex_unlock(&gsm->tx_mutex); 2839 + spin_unlock_irqrestore(&gsm->tx_lock, flags); 2841 2840 2842 2841 if (ret >= 0) 2843 2842 for (i = 0; i < NUM_DLCI; i++) ··· 3045 3042 const unsigned char *buf, size_t nr) 3046 3043 { 3047 3044 struct gsm_mux *gsm = tty->disc_data; 3045 + unsigned long flags; 3048 3046 int space; 3049 3047 int ret; 3050 3048 ··· 3053 3049 return -ENODEV; 3054 3050 3055 3051 ret = -ENOBUFS; 3056 - mutex_lock(&gsm->tx_mutex); 3052 + spin_lock_irqsave(&gsm->tx_lock, flags); 3057 3053 space = tty_write_room(tty); 3058 3054 if (space >= nr) 3059 3055 ret = tty->ops->write(tty, buf, nr); 3060 3056 else 3061 3057 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 3062 - mutex_unlock(&gsm->tx_mutex); 3058 + spin_unlock_irqrestore(&gsm->tx_lock, flags); 3063 3059 3064 3060 return ret; 3065 3061 } ··· 3356 3352 static void gsm_modem_upd_via_data(struct gsm_dlci *dlci, u8 brk) 3357 3353 { 3358 3354 struct gsm_mux *gsm = dlci->gsm; 3355 + unsigned long flags; 3359 3356 3360 3357 if (dlci->state != DLCI_OPEN || dlci->adaption != 2) 3361 3358 return; 3362 3359 3363 - mutex_lock(&gsm->tx_mutex); 3360 + spin_lock_irqsave(&gsm->tx_lock, flags); 3364 3361 gsm_dlci_modem_output(gsm, dlci, brk); 3365 - mutex_unlock(&gsm->tx_mutex); 3362 + spin_unlock_irqrestore(&gsm->tx_lock, flags); 3366 3363 } 3367 3364 3368 3365 /**