Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp2734128pxv; Sat, 17 Jul 2021 23:54:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZB6FfQmmCQ9QkQutYwxKHMk1MdHuOeHZrcPhofVJRv9fTO36XlRavkDrGlqvfS3ERZV+9 X-Received: by 2002:a17:906:69cc:: with SMTP id g12mr21157154ejs.550.1626591244168; Sat, 17 Jul 2021 23:54:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626591244; cv=none; d=google.com; s=arc-20160816; b=0zXcTUQBI2qoNBdZVNsvwDHJsf2eGtWIC4aglDrEph0hOBFO5Mxh36+pwqIGAuYVZY omk2XGYkYl7K4qfi9anSW7FkANltUwv16MDKsrsrfDDdJPGoPjmGodyVTRtYfn15iXUi kOEfMYiCaFUQQ9EAoimFkbaTvqAnkDH+pvIHYb8ZZRTogkkrdr6pfvKGBx5WBGjSnyiV 3uj7zz3bz12M+nxWG2QmqXFSwsLAYncx9XL5dT+oYIyzb8k68RKLBAj49yO7WQ2RozJR 5PjM6N4VU/wP7CNCdDKUxKthXYJJpS71T9Nrcvx6kOccj/fwhHhHV1PBo0YewgE2L8wy D4Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=fkeS3d9zkV5UugREVkpK+fBURGhl+uNRLB6rfN3cNw4=; b=g+bpTk99A70vTt4gtPrM7KQyygLYEA7MpM/XS4jEIeTddoIhD4XdLFQ7xuemUihTFR Hv5+G3jCG+Q7EvJm1egu9d74UeDnwJ7lOvPTriUQQ/AwJ9MzBazdLF0ml+t6zaToBR6g DC8W69GZHkMpy2BXn8ThpZNAc4eY7RB1D0yGkn3OevYAxd7qEbjuvhdT1ZZOrJXCzvG6 zOupR6V0FemaklMGjtco9zjHFcxlxCu/CTdZPQURYu7exMrrTi69/rSxM+drDWlgs6qR trNu1c7U4szZJ0jyVZ9F94VckTTN6FHogTWj2fx/TYG3jFiEdDJXLrOgL6xfqRBveDbG nlTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mUbuBmNS; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ox14si16828069ejb.694.2021.07.17.23.53.19; Sat, 17 Jul 2021 23:54:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mUbuBmNS; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229578AbhGRGyt (ORCPT + 99 others); Sun, 18 Jul 2021 02:54:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229480AbhGRGyt (ORCPT ); Sun, 18 Jul 2021 02:54:49 -0400 Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31436C061762 for ; Sat, 17 Jul 2021 23:51:51 -0700 (PDT) Received: by mail-yb1-xb33.google.com with SMTP id g19so22197763ybe.11 for ; Sat, 17 Jul 2021 23:51:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fkeS3d9zkV5UugREVkpK+fBURGhl+uNRLB6rfN3cNw4=; b=mUbuBmNSUllRTJfIDaFuOYo31S3GR32n9AMR8Epk1iVYPQQ6iEE+dti3Q4TWzKCOhx XbubTWKcVB2JCY9MSEWolqivFNRUwSWkwD5b2iDBIpTU1lePQjl9sOyARbQwgGV/w/iL /UjbWy77+2bWlPYeDrZi4+lLjqLyVdyjO1n3QX88ldAi3ouut02sQB1d8CmdJm+4bGL3 61lbAk3nrWr2G1cHRcTcj5nA5BxdKBNvNQyCTItjgXvbWFw2a5CaPPQ/pGZ5QBy0f4Tg TCe3GzGnAgVCHG65uxlc93vHdn1yjXWxp5qWI4IgxD3bZ97CVBHDP+GqiPW940DVwBP/ VIiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fkeS3d9zkV5UugREVkpK+fBURGhl+uNRLB6rfN3cNw4=; b=hxe7JnQYFIHghKWo4sSY3VDK+ZhisqFSD11sSWJjleZ5DuKnE8563dihbUIoG+NsZ+ ZehKucX4Qz8b6coGzDps+Dgsc1fLDlslFABg3Elyj5blOUbk47+bijC83nzutqJa6xpl f9f5lz7YKcXhgtZ1ivk+oTHDRwEhUg03Wd2lhtHjHd7tS9zDMIocdbwdxPNr9coCL7mS s6vqrklr+ervHRlfZIhYsqsW/ovUDH4OVpzPi+Z3FL+5Kd8p4iBSBRdUJ/1k4vvqVpLE zKRK/sSjlPHPUB2itkq9eGIBPIJE7Vd9g5VnoHsZhmCA3GtcYGmNUBfjC2wHSqXabBn4 4vIg== X-Gm-Message-State: AOAM5333TA8V0ffufrR1SzZqTBoQpo0PsWJKw5PQtBrIY7CjoLObuhmX o/N7lzngrWo/Ip2Kzmq5sqWnXoS6VwgAYxE48xuTxwXO5Dg= X-Received: by 2002:a25:7647:: with SMTP id r68mr23185462ybc.432.1626591110115; Sat, 17 Jul 2021 23:51:50 -0700 (PDT) MIME-Version: 1.0 References: <20210717000731.3836303-1-luiz.dentz@gmail.com> <7a0405c7-63ba-3e5c-7b22-503d7b326a11@i-love.sakura.ne.jp> <166a8c6d-9928-4edf-8082-111e555f5808@i-love.sakura.ne.jp> In-Reply-To: <166a8c6d-9928-4edf-8082-111e555f5808@i-love.sakura.ne.jp> From: Luiz Augusto von Dentz Date: Sat, 17 Jul 2021 23:51:39 -0700 Message-ID: Subject: Re: [RFC] Bluetooth: hci_sock: Fix calling lock_sock when handling HCI_DEV_UNREG To: Tetsuo Handa Cc: "linux-bluetooth@vger.kernel.org" , LinMa Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Tetsuo, On Sat, Jul 17, 2021 at 11:22 PM Tetsuo Handa wrote: > > On 2021/07/18 14:16, Luiz Augusto von Dentz wrote: > > Anyway after all these discussion Im even > > more convinced that the real problem lies in hci_dev_get/hold, after > > all references are usually used to prevent the objects to be freed but > > in this case it doesn't and no locking will gonna fix that. > > If hci_dev_hold() calls atomic_long_add_unless(&file->f_count, 1, 0) under RCU, > vhci_release(file) would not be called until all sockets using that hdev drops > the reference, and hci_sock_dev_event(hdev, HCI_DEV_UNREG) no longer needs to > traverse sockets on hci_sk_list.head list. This requires adding "struct file *" to > "struct hci_dev". My patch keeps changes be confined to only hci_sock_dev_event(). Being confined doesn't mean that it simple, your changes are doing a loop locking, and I also didn't touch hci_dev_hold because it would affect all drivers but if there is a way to do it by all means we should do it, but notice that we do need a way to cleanup if the device is unregistered so I don't think holding the file directly would be a good idea since it prevents release but it would also prevent cleanup, in other words if the process which open the vhci terminates or close, all bluetooth sockets should receive a proper error so we cannot really change this behavior. From the brief look at it I think we should remove the function hci_dev_free and leave hci_dev_unregister to cleanup everything, but I'm afraid there could be extra references that are not being cleanup properly and finding out where could take a lot more time, well even with your suggestion that could be a problem since we also would need to inspect every time we hold a reference in the same manner. -- Luiz Augusto von Dentz