Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp405528rwb; Thu, 27 Jul 2023 14:53:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlGqtG5AE5VC20xdI78Vw2cVzT8vt6MqR47LiCMH/78ru3+ur3ioM9OveSmY0760nxehiSIs X-Received: by 2002:a17:903:2288:b0:1bb:4861:d39e with SMTP id b8-20020a170903228800b001bb4861d39emr646290plh.12.1690494825862; Thu, 27 Jul 2023 14:53:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690494825; cv=none; d=google.com; s=arc-20160816; b=O6+/ZrtBHOYgJmGAyrMEElWA1DNyV9kTo0z1zb5er78OIOMDw+hYdF8wzHfwZP2UhG jcQ2tLOklHDYfQHoSrKUrXf+eeto2F1ED4t0bFr6Mik5gSqvC8beY6v8AoDQRMaJ5FU9 UcxJllRJO2My6HPGdh460oT/ea71FAucuNHo2ld9zUY+Y1ATIDgCbPDOEb5pLrbujCmq W44R5pDW9FiuTASCsn7P5oN7q5OdubJKjgDXUiouj7CLpUj2U/SaZvuKnXrcdBecB9XU IRNio0BPvcTlBnla0Fv6IJn95+szVoY7kKEHCrmIU1wnXjRwzwx5Tc6GXI3TEBtkNRzb FrbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:date:cc:to:from:subject:message-id; bh=/PwxItQ3dQpYPxtTQjgW1QwMEKUquEnVL+3irEfWstg=; fh=Ny21H2BzzfdO1ejjvbyZq4/RBRQjXE7ntloLSg2XeFM=; b=Qk+Uyom2sBh2sULtVTgR52u/GCam6ZEdiy7I/GE4Nlr+ZrWYvFkazJ6vtLVEjbpHec C/nZkUg9bWJSLgvGwhpAHYWHoaqaxJcC3ycupDT/78jh9WE07AE3hEAdYzz5oU4JEi/z VSg5BdxMNraJFsd7CjsPl2egmzk2nCczlFEeH4cyt/nr9yTlnS+B5vrrhLlK1QQEAJEg ec3ctCsqxSNE62ESBRWaQ4XbN2ssV6jJi+66xRsjLR/+/bXsM4cz0+Grv3DBsZ20uDvN CFKg9GneqlUgkfp2emUIUof9vdKm4aZYmWdUFDuYudczzPh/xbxXFVxHgQGwZBIpmSes adSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q9-20020a170902f34900b001bb993ef736si1737886ple.386.2023.07.27.14.53.17; Thu, 27 Jul 2023 14:53:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231254AbjG0Vfn convert rfc822-to-8bit (ORCPT + 99 others); Thu, 27 Jul 2023 17:35:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230509AbjG0Vfn (ORCPT ); Thu, 27 Jul 2023 17:35:43 -0400 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41717C3 for ; Thu, 27 Jul 2023 14:35:32 -0700 (PDT) Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id B53ED240103 for ; Thu, 27 Jul 2023 23:35:29 +0200 (CEST) Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RBkZn0Lb0z9rxR; Thu, 27 Jul 2023 23:35:28 +0200 (CEST) Message-ID: <15a7a714e1f16a2b215accf451927378417c0929.camel@iki.fi> Subject: Re: [PATCH RFC 6/6] Bluetooth: ISO: handle bound CIS cleanup via hci_conn From: Pauli Virtanen To: Luiz Augusto von Dentz Cc: linux-bluetooth@vger.kernel.org Date: Thu, 27 Jul 2023 21:35:27 +0000 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NO_DNS_FOR_FROM, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,T_SPF_TEMPERROR autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Luiz, to, 2023-07-27 kello 14:14 -0700, Luiz Augusto von Dentz kirjoitti: > On Wed, Jul 26, 2023 at 2:37 PM Pauli Virtanen wrote: > > > > Calling hci_conn_del in __iso_sock_close is invalid. It needs > > hdev->lock, but it cannot be acquired there due to lock ordering. > > > > Fix this by doing cleanup via hci_conn_drop. > > > > Return hci_conn with refcount 1 from hci_bind_cis and hci_connect_cis, > > so that the iso_conn always holds one reference. This also fixes > > refcounting when error handling. > > > > Since hci_conn_abort shall handle termination of connections in any > > state properly, we can handle BT_CONNECT socket state in the same way as > > BT_CONNECTED. > > > > Signed-off-by: Pauli Virtanen > > --- > > net/bluetooth/hci_conn.c | 5 +++++ > > net/bluetooth/iso.c | 14 +------------- > > 2 files changed, 6 insertions(+), 13 deletions(-) > > > > diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c > > index ba339a0eb851..33fbdc8e0748 100644 > > --- a/net/bluetooth/hci_conn.c > > +++ b/net/bluetooth/hci_conn.c > > @@ -1901,6 +1901,8 @@ struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst, > > return ERR_PTR(-EINVAL); > > } > > > > + hci_conn_hold(cis); > > + > > cis->iso_qos = *qos; > > cis->state = BT_BOUND; > > > > @@ -2254,6 +2256,9 @@ struct hci_conn *hci_connect_cis(struct hci_dev *hdev, bdaddr_t *dst, > > return ERR_PTR(-ENOLINK); > > } > > > > + /* Link takes the refcount */ > > + hci_conn_drop(cis); > > + > > cis->state = BT_CONNECT; > > > > hci_le_create_cis_pending(hdev); > > diff --git a/net/bluetooth/iso.c b/net/bluetooth/iso.c > > index cbe3299b4a41..358954bfbb32 100644 > > --- a/net/bluetooth/iso.c > > +++ b/net/bluetooth/iso.c > > @@ -628,6 +628,7 @@ static void __iso_sock_close(struct sock *sk) > > iso_sock_cleanup_listen(sk); > > break; > > > > + case BT_CONNECT: > > case BT_CONNECTED: > > case BT_CONFIG: > > if (iso_pi(sk)->conn->hcon) { > > @@ -643,19 +644,6 @@ static void __iso_sock_close(struct sock *sk) > > break; > > > > case BT_CONNECT2: > > - iso_chan_del(sk, ECONNRESET); > > - break; > > - case BT_CONNECT: > > - /* In case of DEFER_SETUP the hcon would be bound to CIG which > > - * needs to be removed so just call hci_conn_del so the cleanup > > - * callback do what is needed. > > - */ > > - if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags) && > > - iso_pi(sk)->conn->hcon) { > > - hci_conn_del(iso_pi(sk)->conn->hcon); > > - iso_pi(sk)->conn->hcon = NULL; > > - } > > - > > iso_chan_del(sk, ECONNRESET); > > break; > > case BT_DISCONN: > > -- > > 2.41.0 > > I guess this sort of fix can be sent separately which I guess helps > here since we can prioritize the ones that don't have side effects. Right, I can send these separately in the actual patch series. This one requires hci_conn_abort deletes conns with no handle yet though, otherwise it introduces failure to cleanup in a race condition. -- Pauli Virtanen