Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp648044ybi; Wed, 17 Jul 2019 02:42:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYVzUGjPRkAM/ZOIjxws0DgM09kVtAFe5drUVSveIvDrlsoSe0Ycy7viO+gvRnudVC+JY1 X-Received: by 2002:a65:654d:: with SMTP id a13mr24473211pgw.196.1563356559463; Wed, 17 Jul 2019 02:42:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563356559; cv=none; d=google.com; s=arc-20160816; b=EXJWbpkf+ApRt2ov11gVNuJ4zKJjp6HemwA59c3p0YY2o7GQNnEF4Jdx8kuj4mlkyn dQW9tUiGw0iDp/qf4RKOJUVEBIsO9DI6eQ1Jgkd+Kie1NtxURvS8naxr5DGCyCg+xMfr 7N6ImZWgd9O4EHu1ZTvkOCLMdTUEAL2ay/7O8WBS5ZjuPPm24cbZPr4jRoRdKkS9n6l7 s+VkMpuaJLZ4Lhr0oQOGSm9M8wj1fFue4ylp5qBOOWxRw3qcSUL7+O4yXPrteZWkUDnA ynqTssHMMpfVhhJBAPljhiqOUD61JFfZCGkDIImCn62dF6W1uHLpesgMXd/a+f0z3vOO roZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language:mime-version:user-agent :date:message-id:subject:from:cc:to:dkim-signature; bh=mqusmOgw9KPue3mu+4HT2EP0uzeyIIRVSm3w5Ijn9UI=; b=qy7WeqRTLOzotOYzFhmYCcQK7i9a8w5vGwYZ2LXPVpNJ+srWO0hrs7dnIjx5kecscK Ue447xLdMo99BwY9cgoEP6/mq/Wxm2/kOyKa/Bm+sm7OGg6KIPkcZe2JrW1ftLsCBKlX RLM4i2D5aSdqPCtWQWkbZokvTjtB1knv6d/JsNRf72tmqnT68ueEeRHu1LUBOys37v5w Esw0b7UOGrmLjNyt5E1FtkFbgY3OoUhZzXYS4Is2TIGAVDYNr41k9nvoIgpfrdataTEO UgGQzlFE3RLuD74qprRo1k/vSUuj0m9TfFkDblQtvt0AIYS+a4Vx8+UrxClTsRot7DdX kLLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@geanix.com header.s=first header.b="RtUf/zNE"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=geanix.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y82si23324391pfb.58.2019.07.17.02.42.23; Wed, 17 Jul 2019 02:42:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@geanix.com header.s=first header.b="RtUf/zNE"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=geanix.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726438AbfGQJkZ (ORCPT + 99 others); Wed, 17 Jul 2019 05:40:25 -0400 Received: from first.geanix.com ([116.203.34.67]:36452 "EHLO first.geanix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725890AbfGQJkZ (ORCPT ); Wed, 17 Jul 2019 05:40:25 -0400 Received: from [192.168.8.20] (unknown [85.184.140.241]) by first.geanix.com (Postfix) with ESMTPSA id C917C4421F; Wed, 17 Jul 2019 09:39:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1563356388; bh=W6wvd7gLObIcP74LGGkuvXYl3r/mNB18UfupZO1FpvA=; h=To:Cc:From:Subject:Date; b=RtUf/zNEU0Snubdfk4pv8TQciGFosmKUJ5cbmuaXULm3reURA3iC0xPcDuM0Pi6Q/ ASXZ6NZWujvuXkaa5cOD9AY43JCgGafTZJ+XVBMJNmFPdo8zvhPQB5aFpYtmqJpIyX zY8zGUSLZ+7TKxUTD+DGlh+CuDfdcAtMhPnAxmeEQYnfl2NaO0M0MF4jHvVVf3u5ML zAaCscv2z4HKdxTMxP2j7bbOzaevCS+UQqVSRsjttY0AORgsYJq5CfNBVxYEFCzK8t KaZEXWdYGxdF2IgMpzsq+66LdkHaO8gRoLCBzwqpruVK0MzvRVV5K0bVap/wd7tJny oogzq4yoelgzA== To: linux-kernel Cc: Greg Kroah-Hartman , Jiri Slaby , Dirkjan Bussink From: =?UTF-8?Q?Martin_Hundeb=c3=b8ll?= Subject: [BUG] n_gsm: possible recursive locking detected Message-ID: Date: Wed, 17 Jul 2019 11:40:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------7FC9DFE90750F6147532B214" Content-Language: en-US-large X-Spam-Status: No, score=-3.1 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_BLOCKED autolearn=disabled version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on 8945dcc0271d Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a multi-part message in MIME format. --------------7FC9DFE90750F6147532B214 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi, The GSM0710 line discipline driver triggers a lockdep warning when disabling the ldisc while holding a multiplexed virtual tty open: ============================================ WARNING: possible recursive locking detected 5.2.0-00114-gdab52e30156b #6 Not tainted -------------------------------------------- cmux/263 is trying to acquire lock: e1e23b18 (&tty->legacy_mutex){+.+.}, at: __tty_hangup.part.0+0x58/0x27c but task is already holding lock: d6eddf48 (&tty->legacy_mutex){+.+.}, at: tty_set_ldisc+0x3c/0x1bc other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&tty->legacy_mutex); lock(&tty->legacy_mutex); *** DEADLOCK *** May be due to missing lock nesting notation 3 locks held by cmux/263: #0: d6eddf48 (&tty->legacy_mutex){+.+.}, at: tty_set_ldisc+0x3c/0x1bc #1: f28bead9 (&tty->ldisc_sem){++++}, at: tty_ldisc_lock+0x50/0x74 #2: e5d20e4f (&gsm->mutex){+.+.}, at: gsm_cleanup_mux+0x9c/0x15c stack backtrace: CPU: 0 PID: 263 Comm: cmux Not tainted 5.2.0-00114-gdab52e30156b #6 Hardware name: Freescale i.MX6 Ultralite (Device Tree) [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [] (show_stack) from [] (dump_stack+0xd4/0x108) [] (dump_stack) from [] (__lock_acquire+0x6ec/0x1e84) [] (__lock_acquire) from [] (lock_acquire+0xcc/0x204) [] (lock_acquire) from [] (__mutex_lock+0x64/0x90c) [] (__mutex_lock) from [] (mutex_lock_nested+0x1c/0x24) [] (mutex_lock_nested) from [] (__tty_hangup.part.0+0x58/0x27c) [] (__tty_hangup.part.0) from [] (gsm_cleanup_mux+0xe8/0x15c) [] (gsm_cleanup_mux) from [] (gsmld_close+0x48/0x90) [] (gsmld_close) from [] (tty_set_ldisc+0xb8/0x1bc) [] (tty_set_ldisc) from [] (tty_ioctl+0x640/0xcb0) [] (tty_ioctl) from [] (do_vfs_ioctl+0x41c/0xa5c) [] (do_vfs_ioctl) from [] (ksys_ioctl+0x34/0x60) [] (ksys_ioctl) from [] (ret_fast_syscall+0x0/0x28) Exception stack(0xc8ce1fa8 to 0xc8ce1ff0) 1fa0: 00438000 00000000 00000003 00005423 beb6cc04 beb6cc04 1fc0: 00438000 00000000 00000000 00000036 00000000 00000000 00438000 beb6ccd4 1fe0: 00438048 beb6cbfc 00427684 b6f58b88 Steps to reproduce using the attached cmux util: root@iwg26:~# ./cmux & [1] 254 SERIAL_PORT = /dev/ttymxc0 AT+IFC=2: Ie5 +CFUN: 1 +CPIN: READY Call Ready AT+IFC=2,2 OK AT+GMM : AT+GMM Quectel_M95 OK AT : AT OK AT+IPR=1: AT+IPR=115200&w OK AT+CMUX=: AT+CMUX=0,0,5,512,10,3,30,10,2 OK Line dicipline set root@iwg26:~# cat /dev/gsmtty1 & [2] 262 root@iwg26:~# kill %1 [ 74.517449] ============================================ [ 74.522769] WARNING: possible recursive locking detected [ 74.528094] 5.2.0-00114-gdab52e30156b #6 Not tainted [ 74.533065] -------------------------------------------- <...> This has supposedly been fixed before in 4d9b109060f6 ("tty: Prevent deadlock in n_gsm driver"), but the fix was undone in be7065725590 ("TTY/n_gsm: Removing the wrong tty_unlock/lock() in gsm_dlci_release()") -- Kind regards, Martin Hundebøll Embedded Linux Consultant +45 61 65 54 61 martin@geanix.com Geanix ApS https://geanix.com DK39600706 --------------7FC9DFE90750F6147532B214 Content-Type: text/x-csrc; name="cmux.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="cmux.c" /** * Cmux * Enables GSM 0710 multiplex using n_gsm * * Copyright (C) 2013 - Rtone - Nicolas Le Manchet * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* n_gsm ioctl */ #ifndef N_GSM0710 # define N_GSM0710 21 #endif /* attach a line discipline ioctl */ #ifndef TIOCSETD # define TIOCSETD 0x5423 #endif /* serial port of the modem */ #define SERIAL_PORT "/dev/ttymxc0" /* line speed */ #define LINE_SPEED B115200 /* maximum transfert unit (MTU), value in bytes */ #define MTU 512 /** * whether or not to create virtual TTYs for the multiplex * 0 : do not create * 1 : create */ #define CREATE_NODES 0 /* number of virtual TTYs to create (most modems can handle up to 4) */ #define NUM_NODES 4 /* name of the virtual TTYs to create */ #define BASENAME_NODES "/dev/ttyGSM" /* name of the driver, used to get the major number */ #define DRIVER_NAME "gsmtty" /** * whether or not to print debug messages to stderr * 0 : debug off * 1 : debug on */ #define DEBUG 1 /** * whether or not to detach the program from the terminal * 0 : do not daemonize * 1 : daemonize */ #define DAEMONIZE 0 /* size of the reception buffer which gets data from the serial line */ #define SIZE_BUF 256 /** * Prints debug messages to stderr if debug is wanted */ static void dbg(char *fmt, ...) { va_list args; if (DEBUG) { fflush(NULL); va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); fprintf(stderr, "\n"); fflush(NULL); } return; } /** * Sends an AT command to the specified line and gets its result * Returns 0 on success * -1 on failure */ int send_at_command(int serial_fd, char *command) { char buf[SIZE_BUF]; int r; /* write the AT command to the serial line */ if (write(serial_fd, command, strlen(command)) <= 0) err(EXIT_FAILURE, "Cannot write to %s", SERIAL_PORT); /* wait a bit to allow the modem to rest */ sleep(1); /* read the result of the command from the modem */ memset(buf, 0, sizeof(buf)); r = read(serial_fd, buf, sizeof(buf)); if (r == -1) err(EXIT_FAILURE, "Cannot read %s", SERIAL_PORT); /* if there is no result from the modem, return failure */ if (r == 0) { dbg("%s\t: No response", command); return -1; } /* if we have a result and want debug info, strip CR & LF out from the output */ if (DEBUG) { int i; char bufp[SIZE_BUF]; memcpy(bufp, buf, sizeof(buf)); for(i=0; i