Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp715980ybl; Fri, 23 Aug 2019 07:23:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxqKQpVTgQojzW6DB0GQs9kPyUuW8SETyip/ufrlYpA/FSP4c0nkveK0zfgkFwqrM+at6QQ X-Received: by 2002:a63:7a06:: with SMTP id v6mr4268794pgc.115.1566570230322; Fri, 23 Aug 2019 07:23:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566570230; cv=none; d=google.com; s=arc-20160816; b=KhCGnTAUOISjbB7xlVq3hRJZL3209F5C4VujME97ewRffIwksnNTwo+eDxTWLv2+py viWfMu2j6xMAzvmFOQGg1uabhwBeM+ZG0HeEo53MLm3sQL40uvLnOvkUM6VwZQmnROfU yC+kvAsQY+uM30OZZA8BAqfBkZSdIXII5EXmBPZIVxz71yxP03j2pxUrdbru/e4yXO1H XxsDWctRr41OHmJr7e5BwbepWz9n1DWsRiYS+22rrMWeemsY2kGX3KAViQeqEj0F6DyB e6AurbPqLQhzANDaLzOVpPT4CrzUnnMI618RuUu9il0H247Js4is/cy56OQkTvli36EI e58Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=AY30r+PpS9HLQ2Y1Au2IugGjV4aH0i9rSf9HCMGNQrU=; b=mQWKjW7auzFrg4bJNcH3t5BIhnyEI5zR89Ms2Z12lzM/1eLD9jgEVBx6zFDidmbzyu nele1g8GK/v5GvVlt8VTNiPNxpyPtligG3jEQbpKX1jhTOFXGxqwyXVAuvPtTzznESMK skXhRePfdAXEi5tjxNKGPnfbFzr4deQChFpSpDrIPIlf+fZoVm5t1LimjltRJUDU5SxN dZMy5oTQefCegCU5fDYHb60k/PDJucdJwTyiEXtKMBpzkWbdTeiU/qdri97EcLFqPUST yXZar7NWrj4gmaAa177IbBlAi8DwkGRD09PfR0OQn9rptc8wkl5Q0eN/Gnys/D7HgaFw vwPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@geanix.com header.s=first header.b=F8Qu46Ir; 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 a24si2755407pfi.205.2019.08.23.07.23.34; Fri, 23 Aug 2019 07:23:50 -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=F8Qu46Ir; 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 S2393697AbfHVV4L (ORCPT + 99 others); Thu, 22 Aug 2019 17:56:11 -0400 Received: from first.geanix.com ([116.203.34.67]:40756 "EHLO first.geanix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393690AbfHVV4L (ORCPT ); Thu, 22 Aug 2019 17:56:11 -0400 Received: from zen.localdomain (unknown [85.184.140.241]) by first.geanix.com (Postfix) with ESMTPSA id D2EF3370; Thu, 22 Aug 2019 21:55:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1566510953; bh=qLRAlPD3627rR29j3REKnBtsuDGN1Jwkm77I1FouPuQ=; h=From:To:Cc:Subject:Date; b=F8Qu46IreSsV7GSHXVRoSuVnY3+44+XV4/SOznT+QYsEC927NLbpyxMPC7tiM81/w j+Vw3h9aUBBNMTi4qeOrSyjqgjl6w4Wmy1uJna6YHpV50xHNBnHiX2uAF3+UnJZCty Lsha3/rRMKq1EB+qZTDWP1V/Zrf0qie0BxQ6Gg2UHItb8XKJru4N8NQFhNDdQkAINO JF6DjgsS3n+5sFhoY9QSLFoTt05Snj5nmGsjbYxS21a3ag0KJjbwmAWM3XDMt4tuI8 0y8BnmfPK7D/cppc8ZIeCxiE2/z89n6kdOFUVxzDri0101co/HtPW8zdAbeXvMp2ba ZrQzIHYcvJHmw== From: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= To: Greg Kroah-Hartman , Jiri Slaby , Alan Cox , linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= , =?UTF-8?q?Sean=20Nyekj=C3=A6r?= , Esben Haabendal Subject: [PATCH] tty: n_gsm: avoid recursive locking with async port hangup Date: Thu, 22 Aug 2019 23:56:01 +0200 Message-Id: <20190822215601.9028-1-martin@geanix.com> X-Mailer: git-send-email 2.22.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=4.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=disabled version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on 77834cc0481d Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When tearing down the n_gsm ldisc while one or more of its child ports are open, a lock dep warning occurs: [ 56.254258] ====================================================== [ 56.260447] WARNING: possible circular locking dependency detected [ 56.266641] 5.2.0-00118-g1fd58e20e5b0 #30 Not tainted [ 56.271701] ------------------------------------------------------ [ 56.277890] cmux/271 is trying to acquire lock: [ 56.282436] 8215283a (&tty->legacy_mutex){+.+.}, at: __tty_hangup.part.0+0x58/0x27c [ 56.290128] [ 56.290128] but task is already holding lock: [ 56.295970] e9e2b842 (&gsm->mutex){+.+.}, at: gsm_cleanup_mux+0x9c/0x15c [ 56.302699] [ 56.302699] which lock already depends on the new lock. [ 56.302699] [ 56.310884] [ 56.310884] the existing dependency chain (in reverse order) is: [ 56.318372] [ 56.318372] -> #2 (&gsm->mutex){+.+.}: [ 56.323624] mutex_lock_nested+0x1c/0x24 [ 56.328079] gsm_cleanup_mux+0x9c/0x15c [ 56.332448] gsmld_ioctl+0x418/0x4e8 [ 56.336554] tty_ioctl+0x96c/0xcb0 [ 56.340492] do_vfs_ioctl+0x41c/0xa5c [ 56.344685] ksys_ioctl+0x34/0x60 [ 56.348535] ret_fast_syscall+0x0/0x28 [ 56.352815] 0xbe97cc04 [ 56.355791] [ 56.355791] -> #1 (&tty->ldisc_sem){++++}: [ 56.361388] tty_ldisc_lock+0x50/0x74 [ 56.365581] tty_init_dev+0x88/0x1c4 [ 56.369687] tty_open+0x1c8/0x430 [ 56.373536] chrdev_open+0xa8/0x19c [ 56.377560] do_dentry_open+0x118/0x3c4 [ 56.381928] path_openat+0x2fc/0x1190 [ 56.386123] do_filp_open+0x68/0xd4 [ 56.390146] do_sys_open+0x164/0x220 [ 56.394257] kernel_init_freeable+0x328/0x3e4 [ 56.399146] kernel_init+0x8/0x110 [ 56.403078] ret_from_fork+0x14/0x20 [ 56.407183] 0x0 [ 56.409548] [ 56.409548] -> #0 (&tty->legacy_mutex){+.+.}: [ 56.415402] __mutex_lock+0x64/0x90c [ 56.419508] mutex_lock_nested+0x1c/0x24 [ 56.423961] __tty_hangup.part.0+0x58/0x27c [ 56.428676] gsm_cleanup_mux+0xe8/0x15c [ 56.433043] gsmld_close+0x48/0x90 [ 56.436979] tty_ldisc_kill+0x2c/0x6c [ 56.441173] tty_ldisc_release+0x88/0x194 [ 56.445715] tty_release_struct+0x14/0x44 [ 56.450254] tty_release+0x36c/0x43c [ 56.454365] __fput+0x94/0x1e8 Avoid the warning by doing the port hangup asynchronously. Signed-off-by: Martin Hundebøll --- drivers/tty/n_gsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index d30525946892..36a3eb4ad4c5 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -1716,7 +1716,7 @@ static void gsm_dlci_release(struct gsm_dlci *dlci) gsm_destroy_network(dlci); mutex_unlock(&dlci->mutex); - tty_vhangup(tty); + tty_hangup(tty); tty_port_tty_set(&dlci->port, NULL); tty_kref_put(tty); -- 2.22.1