Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp402939ybe; Wed, 4 Sep 2019 01:21:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAf/4eA+twG8luVS/PGtTS4ZocZAhFrU+QknR2HOV5qLFrm8ixfL2Ba/YQOjygWRCvSbcF X-Received: by 2002:a17:902:c9:: with SMTP id a67mr32839046pla.178.1567585293776; Wed, 04 Sep 2019 01:21:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567585293; cv=none; d=google.com; s=arc-20160816; b=Sy+sV2Y8d4MLheoqJJnA//ZjKJvT++C2JouvJTeaEKnDXfOD76WjbsR3AweJqbQbIM L4OJvgBNVfYTuzCxeCpJI7LZEjdjT33ZMzkIs/gQiX6quF98zZxNP2sGalxtoElxAA8F 334rZ7/Pq864LYGq6Q1X7Ry/q6wE8hrTeuXthxPXPLFdd/dwrRk9iOXhmrqxVI4dclVY uz9eE0o8YijArUziXJSMfNjmtzObo1ztTUdUWSN/KoYL2HGAnNKJUbBDaRUPWPVLFXbM /PBvhkvPXkrYPk/O/fh/LjPIT3xduc/tZiEjzBTnCEVfg7xZLp+WMxaWQn1Lxx2DhjTg Ljeg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject; bh=wXlhTHnCqCuoS2oZOppVtx2C0vLH0wnifUMnQtFNdrw=; b=AsikKVX4BfOJAvdjczWZubDotE9WkMZgI/XQVmabiF7ZqTnP+J8il7b2rG284Tc96b 9QHbT755OKbwVdmLDzjBqnmfeXq5S+0cC66jXyDKY8oqAA/zM43Mj7NBtl/kT5WhtFau 7uzoO/DbZPVJtCUDFBiJVCV6MfzAk7jJalkiHnav0JPL2MfMja1wVH0X43rvrCXMxm+o /4O0ZS0AZiLK+IpTHGPbzUnG7xk+0/Zdpduf1l5IpehnJHjP6m/u526radm7Eo+kDF5u g0TcL1c9eH7ykQW83GLxxz6hrAL/7OAGXnPERvQaengV+3zoOtZ2YO5NBgwn2mzsIFUD gfGA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q2si1964341pjq.29.2019.09.04.01.21.18; Wed, 04 Sep 2019 01:21:33 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728637AbfIDITF (ORCPT + 99 others); Wed, 4 Sep 2019 04:19:05 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:55778 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725774AbfIDITE (ORCPT ); Wed, 4 Sep 2019 04:19:04 -0400 Received: by mail-wm1-f66.google.com with SMTP id g207so2213306wmg.5 for ; Wed, 04 Sep 2019 01:19:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=wXlhTHnCqCuoS2oZOppVtx2C0vLH0wnifUMnQtFNdrw=; b=ZznL0+wCy9mDEamIk82dUbMr4JhTw8jBTe/6+kyVnTLpJmnYojGSc6v7vS6ZqJzF6W b7ipmLKP3stIiJxSkmURI28Pit++EUK+QHtK1LVF3ZaSVj9Gc5lLp3AW4czmCyCudHhV IUEyurkkMFEn/O1ldFHtV5r7YhqBHhMm8Rsnyho+zk5CI7ddkfPxKJnZH3AKtjMgclOn GX7c+A6VybsRxBLHWqeJP3RO+nj2TPxbQol1SlrYTiTTLhVYV6PzY9tX+F7MpSRMOQYC qzvbBaBS1jz+f87j+VV5PVFm3JbVHDfliHmToxltutvLOXXlcgmc4JCKmHe66OIlxwjR 0AXg== X-Gm-Message-State: APjAAAU+AwqfrjDtFnzqp4RGxxlgb6nJoOt9XkR7eWBxTSCQRaNLDeHq sM787/jhHWHLQUESwEIM/0to93rm884= X-Received: by 2002:a1c:6a0a:: with SMTP id f10mr3208579wmc.121.1567585141750; Wed, 04 Sep 2019 01:19:01 -0700 (PDT) Received: from ?IPv6:2a0b:e7c0:0:107::70f? ([2a0b:e7c0:0:107::70f]) by smtp.gmail.com with ESMTPSA id j18sm16173614wrr.20.2019.09.04.01.19.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Sep 2019 01:19:00 -0700 (PDT) Subject: Re: [PATCH] tty: n_gsm: avoid recursive locking with async port hangup To: =?UTF-8?Q?Martin_Hundeb=c3=b8ll?= , Greg Kroah-Hartman , Alan Cox , linux-kernel@vger.kernel.org Cc: Esben Haabendal , =?UTF-8?Q?Sean_Nyekj=c3=a6r?= References: <20190822215601.9028-1-martin@geanix.com> <4fd2d737-14a8-6fe6-16a1-c5e6d924f9e6@geanix.com> From: Jiri Slaby Openpgp: preference=signencrypt Autocrypt: addr=jslaby@suse.com; prefer-encrypt=mutual; keydata= mQINBE6S54YBEACzzjLwDUbU5elY4GTg/NdotjA0jyyJtYI86wdKraekbNE0bC4zV+ryvH4j rrcDwGs6tFVrAHvdHeIdI07s1iIx5R/ndcHwt4fvI8CL5PzPmn5J+h0WERR5rFprRh6axhOk rSD5CwQl19fm4AJCS6A9GJtOoiLpWn2/IbogPc71jQVrupZYYx51rAaHZ0D2KYK/uhfc6neJ i0WqPlbtIlIrpvWxck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3R5RW d6ozZNRBBsr4qHsnCYZWtEY2pCsOT6BE28qcbAU15ORMq0nQ/yNh3s/WBlv0XCP1gvGOGf+x UiE2YQEsGgjs8v719sguok8eADBbfmumerh/8RhPKRuTWxrXdNq/pu0n7hA6Btx7NYjBnnD8 lV8Qlb0lencEUBXNFDmdWussMAlnxjmKhZyb30m1IgjFfG30UloZzUGCyLkr/53JMovAswmC IHNtXHwb58Ikn1i2U049aFso+WtDz4BjnYBqCL1Y2F7pd8l2HmDqm2I4gubffSaRHiBbqcSB lXIjJOrd6Q66u5+1Yv32qk/nOL542syYtFDH2J5wM2AWvfjZH1tMOVvVMu5Fv7+0n3x/9shY ivRypCapDfcWBGGsbX5eaXpRfInaMTGaU7wmWO44Z5diHpmQgTLOrN9/MEtdkK6OVhAMVenI w1UnZnA+ZfaZYShi5oFTQk3vAz7/NaA5/bNHCES4PcDZw7Y/GiIh/JQR8H1JKZ99or9LjFeg HrC8YQ1nzkeDfsLtYM11oC3peHa5AiXLmCuSC9ammQ3LhkfET6N42xTu2A== Message-ID: Date: Wed, 4 Sep 2019 10:18:58 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <4fd2d737-14a8-6fe6-16a1-c5e6d924f9e6@geanix.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 29. 08. 19, 21:42, Martin Hundebøll wrote: > On 22/08/2019 23.56, Martin Hundebøll wrote: >> 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. > > Any comments? I did not manage to reply before vacation, and after having "work = NULL" in my head, I forgot, sorry. At the same time, I am a bit lost in the lockdep chain above. It mixes close (#0), open (#1) and ioctl (#2), so how is this a "chain" in the first place? BTW, do you see an actual deadlock? And what tty driver do you use for backend devices? I.e. what ttys do you set this ldisc to? See also the comment below. >> 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); I am afraid there is changed semantics now: the scheduled hangup will likely happen when the tty in tty_port is set to NULL already, so some operations done in tty->ops->hangup might be a nop now. For example the commonly used tty_port_hangup won't set TTY_IO_ERROR on the tty and won't lower DTR and RTS on the line either. >>           tty_kref_put(tty); thanks, -- js suse labs