Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2163550pxb; Mon, 23 Aug 2021 13:34:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwe0TCnOgkwC4Vxk0YYdOArb31VVNWX3Tjl10hSdTwhakdxoAEZJLbA9ZUSi52dRPi8xZOX X-Received: by 2002:aa7:db82:: with SMTP id u2mr40173081edt.299.1629750892951; Mon, 23 Aug 2021 13:34:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629750892; cv=none; d=google.com; s=arc-20160816; b=GAj0g5RsDvL/vt3Kg+qobG9a4kbVBuQ+JnLfYfn2ks8jwviAEELFOtmZqep7Di5luK t0tHms9yqDYfmMlIH3EpPoRHUMwytXKKPu/6rWodsP0Ndgq62EVa3yDxgfqyXieq3cxK usQPH3J0VMEentJX+QLco3b4qYj88Q0xRXho8DMu90Bp1UkqjUmwNgIU/jLjEk5j7uNb eP0FaGSh1BXlf9Yh0O52+smptiAnpz6IocOznweqESpfhKUcGJNQTpYaAQ+j8fa3/Q4q 2eS/8dh9Cs7+B2pQ90GrsbKRqSE0ZXNFuIGuh2FO6HpobRLu1EvLWwhXtmj8h9H2zL4T caVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id; bh=QNWkeO+G10N7PkBmsiigd7533cQwb7wkazAvC7v43e8=; b=ZMCYFJ23HkJ1aOH+IbGsiML74UnurC/aSHLRnrDqp3mXQ7Kx7chsMwvRzD72FxDIp0 zBoGAl84y9eDSieFyzzumICljBI1pI2liGqQ6rFpY5rkQ8SKfeqbcmzz4417/xeURDXL 6KAbwl7U+gYSJ4mJfZ6zO/g1nVQk5YvNw+34LwBSzkKlc2b49zUahzdVSr4Bfvvzd5zJ xJfwawywnj8Y56KewxcAEVHtgXVKw6c18CMkArX/9oXX80UfjmatUkMVt2eOXEX0iz79 E9qnr0pk8O81Lv4iuZ4F5ANA5wfghgto1kSYqVfK6l1J0DANQlUyRcOdKwYhWce7KjNc q1pg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l14si536258edb.467.2021.08.23.13.34.11; Mon, 23 Aug 2021 13:34:52 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232262AbhHWUdc (ORCPT + 99 others); Mon, 23 Aug 2021 16:33:32 -0400 Received: from mga03.intel.com ([134.134.136.65]:57242 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232237AbhHWUdb (ORCPT ); Mon, 23 Aug 2021 16:33:31 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10085"; a="217207074" X-IronPort-AV: E=Sophos;i="5.84,344,1620716400"; d="scan'208";a="217207074" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2021 13:32:48 -0700 X-IronPort-AV: E=Sophos;i="5.84,344,1620716400"; d="scan'208";a="535503407" Received: from trangn-mobl.amr.corp.intel.com ([10.209.102.243]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2021 13:32:47 -0700 Message-ID: <76f1ddc63531da892643527116aeec434d809091.camel@linux.intel.com> Subject: Re: how to cleanly shutdown an application using HCI_CHANNEL_USER From: Tedd Ho-Jeong An To: "Peter A. Bigot" Cc: linux-bluetooth@vger.kernel.org, Marcel Holtmann Date: Mon, 23 Aug 2021 13:32:47 -0700 In-Reply-To: References: Organization: Intel Corporation Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Peter On Thu, 2021-08-19 at 17:01 +0200, 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 > Was bluetoothd running when you test? If then, try to run without running the bluetooth daemon and check to see if you have a same problem. If you have to use the daemon, change the "AutoEnable" flag in the /etc/bluetooth/main.conf to false and restart the bluetooth daemon. This will prevent the HCI interface from powering on after cloing socket. Regards, Tedd