Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp944105ybp; Thu, 17 Oct 2019 05:59:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqxeO+EwNA7T1dN/JsQ9eN6gYxJOz/tczdmFkKMOXQ4+jjTBqrBq31QP43MuYzdJzne0G0NJ X-Received: by 2002:aa7:da4a:: with SMTP id w10mr3504253eds.209.1571317187744; Thu, 17 Oct 2019 05:59:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571317187; cv=none; d=google.com; s=arc-20160816; b=NLQ48M3Xv1gt94QyWbm0blTnp2UhXfwtQj7UmT7bc2YOXo+4Xl3yNYhV4YNukBafEm uzxBTHdl/+naLCCGECKDbs9yFaI7rdpPy6kzAcnlfTOwdK4019LaQ2aFKHEMl7XV56On hbX5N2POuM2dre6MByJoqYPG0aOIzIoVQ9AhbNJwdV4fI/2x3dfqsHt/zclNEgJ+lnKY ir05YhGqIc/GbmJMkirrAfZstyqQ19AZfnrmeOqCCI4g5w6VpM6fpjIKWvrwhX0tpm/S kHuk6MUipzjpbAOx7+QtTUcxPPQ2oifto1lH6eVDWPfwnFur+b5iWej0LhBm8/+qHhVC /9kg== 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:mime-version :message-id:date:in-reply-to:subject:cc:to:from:user-agent :references:dkim-signature; bh=A96DxtMYbVnBC5BawUeHIwdFetpJSaKB+Iosg4eUKN4=; b=pQZsNfcDqsLW+LAwcWqocThm9uRZTSwMidfUT8bktJ3FIv12L6nPVuiX7OYmyAVXzN WdlVoragcIFWWsPxsO43Tp8tZbHzjbYeEQPqD+Te+T1jLQf34pY+NxTc9z2dX7TvPHdD ACcN5PH3ryKF8FgYHxpHxdDvmfUksszJjMS6nLjZTXNle7NtLx3PjSFa4tTonFLDrYFZ Y7dh9In1kc6x3aJ/FgXCkv1y56v520NI7dWUI5tGKW8pImCLq13zRQrkVLnBHYd4/5kB nlVhWdkHez/AvGrTaBOKbAN8YqT5NbM4PvnvNe6hMfVBKnomujZQValwazrcb1QTBhGg dyUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=CNtR654p; 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 u8si1459722edq.84.2019.10.17.05.59.24; Thu, 17 Oct 2019 05:59:47 -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; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=CNtR654p; 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 S2389418AbfJPTxY (ORCPT + 99 others); Wed, 16 Oct 2019 15:53:24 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:43262 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727148AbfJPTxY (ORCPT ); Wed, 16 Oct 2019 15:53:24 -0400 Received: by mail-pf1-f193.google.com with SMTP id a2so35533pfo.10 for ; Wed, 16 Oct 2019 12:53:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version:content-transfer-encoding; bh=A96DxtMYbVnBC5BawUeHIwdFetpJSaKB+Iosg4eUKN4=; b=CNtR654pMu4sToO/k+dQ2GmkEMAIHlmjNOjDYMR8bYdZYKUD21TINej7dKnV7arjeF wax7tzf9aVQjOqlzitRy3XD/6B4bRZCWkMCqdBUKEAe3xF2DpNAuKVbi/+CPdZrxjGhJ bY1YTjq6KqzoGBLT0HadBoOXyrWkA29Cq259Z549J0qsrI2jTwM9wJEuChZ7efLdJwXm GzeAqpn3yAuGBHtGE1L4hcmr/pVbH6vtSkyTVnJRkP+FELWDodoyjBvdeFsDmrWHLOQm 3MchZgFBNxAbUoiK5y+MefpsaqXMQgfq6kifT/YXm6IB2uRJHolFT/XwRp4c6t/4ajYq TJzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version:content-transfer-encoding; bh=A96DxtMYbVnBC5BawUeHIwdFetpJSaKB+Iosg4eUKN4=; b=tLK1yjPccfssm+AzfQFn5trw86G5dVf0jvMgVGz2kra6ALR/awqd57e8EP/Q3MUaTp guJ7nSlDXUErwSa2M8QBcxS0NVX0cOgQJMZYErwj5dJS6pGX3t6iyjsqelPECnV2VilG q31LFi9Wby3G3DYf+4dyT9Kn1RnZtOQIs6w6L9vNQoE3iPXbdqTJL0YPxLRm+DuL8kJO RarDZUSfZ7CiAAi2ThbPTa12PDRSJ+7nQ3NVWxzZz29LNgZTBV+yjTsG0CTsndar53Rb Yz8I/MpNfMEIl/xqNmxJUUfOtTm2imgiEHLnqHcGgc5fmFgaZTFBZELAjmXLZrJra6tQ CVow== X-Gm-Message-State: APjAAAVcfXOEDMKSiganAe+4flZy1CsUx/xcegNcqjAHlNT/87nMnzmE Awov1ej63vmDWZvV84YT5uQvZg== X-Received: by 2002:a17:90a:c306:: with SMTP id g6mr7057586pjt.38.1571255603146; Wed, 16 Oct 2019 12:53:23 -0700 (PDT) Received: from localhost ([2601:647:5700:f97e:1021:e5a8:28ca:ce5f]) by smtp.gmail.com with ESMTPSA id f13sm19053148pgr.6.2019.10.16.12.53.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2019 12:53:22 -0700 (PDT) References: <20191004000933.24575-1-mkorpershoek@baylibre.com> <474814D3-A97F-48D1-8268-3D200BE60795@holtmann.org> User-agent: mu4e 1.0; emacs 26.1 From: Mattijs Korpershoek To: Marcel Holtmann Cc: Bluez mailing list , Sean Wang , Johan Hedberg , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Bluetooth: hci_core: fix init with HCI_QUIRK_NON_PERSISTENT_SETUP In-reply-to: <474814D3-A97F-48D1-8268-3D200BE60795@holtmann.org> Date: Wed, 16 Oct 2019 12:53:21 -0700 Message-ID: <87sgnsfowe.fsf@baylibre.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Marcel, Marcel Holtmann writes: > Hi Mattijs, > >> Some HCI devices which have the HCI_QUIRK_NON_PERSISTENT_SETUP=20 >> [1] >> require a call to setup() to be ran after every open(). >>=20 >> During the setup() stage, these devices expect the chip to=20 >> acknowledge >> its setup() completion via vendor specific frames. >>=20 >> If userspace opens() such HCI device in HCI_USER_CHANNEL [2]=20 >> mode, >> the vendor specific frames are never tranmitted to the driver,=20 >> as >> they are filtered in hci_rx_work(). >>=20 >> Allow HCI devices which have HCI_QUIRK_NON_PERSISTENT_SETUP to=20 >> process >> frames if the HCI device is is HCI_INIT state. >>=20 >> [1] https://lore.kernel.org/patchwork/patch/965071/ >> [2] https://www.spinics.net/lists/linux-bluetooth/msg37345.html >>=20 >> Fixes: 740011cfe948 ("Bluetooth: Add new quirk for=20 >> non-persistent setup settings") >> Signed-off-by: Mattijs Korpershoek >> --- >> Some more background on the change follows: >>=20 >> The Android bluetooth stack (Bluedroid) also has a HAL=20 >> implementation >> which follows Linux's standard rfkill interface [1]. >>=20 >> This implementation relies on the HCI_CHANNEL_USER feature to=20 >> get >> exclusive access to the underlying bluetooth device. >>=20 >> When testing this along with the btkmtksdio driver, the >> chip appeared unresponsive when calling the following from=20 >> userspace: >>=20 >> struct sockaddr_hci addr; >> int fd; >>=20 >> fd =3D socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); >>=20 >> memset(&addr, 0, sizeof(addr)); >> addr.hci_family =3D AF_BLUETOOTH; >> addr.hci_dev =3D 0; >> addr.hci_channel =3D HCI_CHANNEL_USER; >>=20 >> bind(fd, (struct sockaddr *) &addr, sizeof(addr)); # device=20 >> hangs >>=20 >> In the case of bluetooth drivers exposing=20 >> QUIRK_NON_PERSISTENT_SETUP >> such as btmtksdio, setup() is called each multiple times. >> In particular, when userspace calls bind(), the setup() is=20 >> called again >> and vendor specific commands might be send to re-initialize the=20 >> chip. >>=20 >> Those commands are filtered out by hci_core in HCI_CHANNEL_USER=20 >> mode, >> preventing setup() from completing successfully. >>=20 >> This has been tested on a 4.19 kernel based on Android Common=20 >> Kernel. >> It has also been compile tested on bluetooth-next. >>=20 >> [1]=20 >> https://android.googlesource.com/platform/system/bt/+/refs/heads/master/= vendor_libs/linux/interface/ >>=20 >> net/bluetooth/hci_core.c | 15 +++++++++++++-- >> 1 file changed, 13 insertions(+), 2 deletions(-) >>=20 >> diff --git a/net/bluetooth/hci_core.c=20 >> b/net/bluetooth/hci_core.c >> index 04bc79359a17..5f12e8574d54 100644 >> --- a/net/bluetooth/hci_core.c >> +++ b/net/bluetooth/hci_core.c >> @@ -4440,9 +4440,20 @@ static void hci_rx_work(struct=20 >> work_struct *work) >> hci_send_to_sock(hdev, skb); >> } >>=20 >> + /* If the device has been opened in HCI_USER_CHANNEL, >> + * the userspace has exclusive access to device. >> + * When HCI_QUIRK_NON_PERSISTENT_SETUP is set and >> + * device is HCI_INIT, we still need to process >> + * the data packets to the driver in order >> + * to complete its setup(). >> + */ >> if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { >> - kfree_skb(skb); >> - continue; >> + if (!test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, >> + &hdev->quirks) || >> + !test_bit(HCI_INIT, &hdev->flags)) { >> + kfree_skb(skb); >> + continue; >> + } >> } > > if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && > !test_bit(HCI_INIT, &hdev->flags)) { > kfree_skb(skb); > continue; > } > > Wouldn=E2=80=99t it be enough to just add a check for HCI_INIT to this.=20 > I mean it makes no difference if ->setup is repeated on each=20 > device open or not. We want to process event during HCI_INIT=20 > when in user channel mode. Thank you for your review. You are right. We always want to=20 process events during HCI_INIT in user channel mode. I'll send a v2 Regards, Mattijs > > Regards > > Marcel