Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp775751pxb; Thu, 19 Aug 2021 10:54:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOwrfceksejFPZJ190IrSiP7lm7ASEA6o8mSia8ku4tbRRtilt7BivU3KhlgGEBlLnP9ll X-Received: by 2002:a05:6e02:2199:: with SMTP id j25mr10732797ila.97.1629395659738; Thu, 19 Aug 2021 10:54:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629395659; cv=none; d=google.com; s=arc-20160816; b=nmvKiV4OrhWxdcbTDMl/7NtkzIMwDqvOrie2rscvm+qOxKA1VeYwLhWEYB0+8mdSQ6 X2L8lBevrGxGpfOlY8mGlW9v3CLunuPYrLetlpELIPgFW5D/DPvEMNXbfT/yMKZH8xE1 rK8knnQggrWivEk244KSlAha0eKeoVGS8ZYM2nIdRmEPnlg3E+47kma2ey5tVyhnENtP 6Ib6oFbCJMm7mf5aG+hJfWCRnN3T5Xn1kvA3zSBh5Li/YtyXPkPpaPSmqa4BPGf+qkAL 91Xq282wPWFjuezEICVWjveJjPqN1i1YD2iSlHIvq7NKFS4Vdsie6JXlzlOzpJflpDhu TRMQ== 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=MaS1SUAQmdtqY+NjJV5NNuqZc5tJAZy4kKZdDjcHQzE=; b=PRmvCIMH6QapmUHEgdO5pqTVMkm17NGjFtSi04ijT0SE+a4rd8rctmwcKahqzk2e3F 5IoTHDSDSD2HaUTqSSrCtEKckPNUfpL5WScsPEnJH/f9Xb3aAvKgeZmHJ3rIdaE5j+/Q bnur5u78rpoWGbfUCbx4mIv3QuJ6VC5dHQxLW/1xmq0RpAee4JpRKZUnCSMqSk7Bsc8e luaOYPFyWghbt+VMUygqN/hVah5aVldVQ52sf6IG23refEqAukWFCNSbowrGdQB8RAwB JD2k9eskwuoURwm3mMNgWSmBlk0wK87ahY3h0jsbNjZGNV56ZfG1lwud6OvDu4zpQXfW rY7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Uf5vGzk9; 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 b16si4706483ilf.63.2021.08.19.10.53.55; Thu, 19 Aug 2021 10:54:19 -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=Uf5vGzk9; 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 S232328AbhHSRwK (ORCPT + 99 others); Thu, 19 Aug 2021 13:52:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229549AbhHSRwJ (ORCPT ); Thu, 19 Aug 2021 13:52:09 -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 0D744C061575 for ; Thu, 19 Aug 2021 10:51:33 -0700 (PDT) Received: by mail-yb1-xb33.google.com with SMTP id k65so13755968yba.13 for ; Thu, 19 Aug 2021 10:51:33 -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=MaS1SUAQmdtqY+NjJV5NNuqZc5tJAZy4kKZdDjcHQzE=; b=Uf5vGzk9ytP+dFki+RzSxPf+wfzTi1X4J7UuSwGqJdFS/E4WWTvR2hFNLj1EQm9eRy 40LdJcihH5h3yCR8a/x2N41TTlwhvDOBcd+4VE2KF7yVqRD0r6LkEqQGHfp6Tn+WbPRF QcMjyiQ27yKPHwH4TVK3MwxgdPsr/C2ebz49Ul3Ne7clIFulRt+fKlgiaIhapbmQauot gXLcFd/bv6y15Q6bF07VZkbpmZ1SR2OTtAzEvtI6nimOd3gZ8Rc7KvXkbwHTS8OzVxS3 gJZbN2UoyUq/tnh4fVcgJ1OyQKqQnC0kzKecQanEC+p/y1ucrHUep7NInW/U7eEWB8h6 J/BA== 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=MaS1SUAQmdtqY+NjJV5NNuqZc5tJAZy4kKZdDjcHQzE=; b=OG/Qt4JQqJsTfCArXlz71dAZ2hqZohTM62yZQX5YuTHZp7QttfBUAROj8Kp5rLsGZ1 pjrjV/9eZxg61XQpso8BkjDXsWaVzhnO7PHj49yK84dkbGMn6lm4rlG/V/Bi34DAHL+S 0oE0ekvP00vBntP80pl/Fy1WMYlht8DkoW6T3R14qRI4IuReMHdryZ3fu43mZhroLPMb DzWLmnwWtxwCm1Rcntu7JHPZTDFI43qwEqFYDqNW4KMM21Y83ewX8ueJzgAo5y9Xj5ep uVQwwWyrtil79NyQ7xAAPEcBKQ78SpmgdGuF2bBNN7O60Kw/9Yu4CLVtyxWcU5HTk6j+ OgEg== X-Gm-Message-State: AOAM531p0em3hpDSCXVgsSSXwQDw0KFcxj2WkT8MTEPDZSz3ZyGEFXEg btECk0nJtQPWQmKrokryUHP7J6cAcnQ5TlDZL2OyeCOncnY= X-Received: by 2002:a25:d183:: with SMTP id i125mr21290308ybg.408.1629395492116; Thu, 19 Aug 2021 10:51:32 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Luiz Augusto von Dentz Date: Thu, 19 Aug 2021 10:51:21 -0700 Message-ID: Subject: Re: how to cleanly shutdown an application using HCI_CHANNEL_USER To: Marcel Holtmann Cc: "Peter A. Bigot" , "linux-bluetooth@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Marcel, Peter, On Thu, Aug 19, 2021 at 8:04 AM Marcel Holtmann wrote: > > Hi Peter, > > > I'm using an AF_BLUETOOTH socket bound with HCI_CHANNEL_USER from a > > user-mode application with cap_net_admin=ep. As expected this > > requires the device be down, and brings the device up automatically. > > > > When I close that socket and exit the application, the device appears > > to remain up forever. Which prevents me from re-starting the > > application. > > > > I tried to issue HCIDEVDOWN before closing, but that produces EBADFD > > because ioctls cannot be performed with HCI_CHANNEL_RAW. > > > > I can bring the interface down from within the application if, after > > closing the socket, I wait a second or so, then create a new bound > > HCI_CHANNEL_RAW socket and issue HCIDEVDOWN on it. > > > > Is there some other way to cleanly shut down an application that used > > HCI_CHANNEL_USER so that the device is returned to down state on exit? > > Or is this supposed to happen automatically (I see code that suggests > > it should)? > > > > Kernel version is 5.11.0-7620-generic (System76), and I'm using go > > 1.16, if that's relevant. > > I think you found a regression. Calling close() on the HCI User Channel should bring the device back down. This used to work correctly, can you please bisect which kernel patch broke this. > > Back in the days I added tools/userchan-tester, but it seems I never included enough test cases to catch this regression. > > Regards > > Marcel It is worth checking if this is affected by the following fix: https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/commit/?id=58ce6d5b271ab25fb2056f84a8e5546945eb5fc9 -- Luiz Augusto von Dentz