Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp5172296rwb; Mon, 8 Aug 2022 13:34:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR6uS+4XQSJPyvyTvRr6osGaShfkT0OcDiigNOPoX049AOSuEArt7qP3Scft+zekZDfPo5Tw X-Received: by 2002:a17:907:2895:b0:730:9711:ad60 with SMTP id em21-20020a170907289500b007309711ad60mr14682311ejc.159.1659990889488; Mon, 08 Aug 2022 13:34:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659990889; cv=none; d=google.com; s=arc-20160816; b=uoj6cRsLV7jgIQrgnNBfmFoQrYUuQeNHYHLiD4wC3TSARiXcwd5CKLq0L7htn0FSp7 FyRepJdi6KXQ42gC9C5icM4aHPmkYudbqOwkJCt/XBFKqboCyiCNMTti/PzfnPFCE0ir AQAzID7SrZdWnHCzNhmSGqqmIpAJU0FRKS+uwi4rfZPC8fFFl1H+P3UUYBcStrPUf6ol 9knAOlP1cTQH3RNu/S4cFqqlb7XkNSzqrBMg+9LwCsGLOnlIIw5DLpWmRDvBBgxQT/Af cxhG7yMPbtbHk2F5TSS9rMoB6f342eeRY2YPKG5+BvzDWqqhtR1CLMDSVKHFrTvuh8BB gplQ== 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=zBXmaPCVMLZZykpy+uTUBaFhT6YqekGzMMKrnO5HYms=; b=N9bjfsIKjsWKuFnV+LDxU20Q5ym8M5FBBU1XXwbt2BEVMBlznQ4zaY84KDXYUHbaM4 uJhuFDbIuBRExP2i9eB/4jxl2ij2HaRh7O9hneWg8k37lZntHzCcyyNdrbuLC21/uC0J LxZU7+XCEZ6brz9Lu8z+p+r0fgvGLcq+uxh2igVGCVICAzfZjmiHbQy9dXLZAgGYRkOl PPQvdpE4mWLmg/YECSUVtQjT+hRRy8T22wQID0fHuNgSZ2GDEEQJ6oX7pJSZlGrCGfp+ C+bDj+cwbZdgICybXDolrmcSDrJAUnz8NrocnHViPHk+0maDmsqdp3Ka/32GovgSMbzS gFnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MkdgIzJt; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd27-20020a1709076e1b00b007307a4f5102si356995ejc.830.2022.08.08.13.34.05; Mon, 08 Aug 2022 13:34:49 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MkdgIzJt; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244352AbiHHUb7 (ORCPT + 99 others); Mon, 8 Aug 2022 16:31:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235732AbiHHUb6 (ORCPT ); Mon, 8 Aug 2022 16:31:58 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C617D101CF; Mon, 8 Aug 2022 13:31:54 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id uj29so18779694ejc.0; Mon, 08 Aug 2022 13:31:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zBXmaPCVMLZZykpy+uTUBaFhT6YqekGzMMKrnO5HYms=; b=MkdgIzJtrQKFYLEmnwnEVpH9YougA+RMr1tJW1lnJYRdpXSv/w14esVwL/od2bKal6 TGHf+OJw01wDPqHexEYKZeyZpTXBmZr5xx9pwAGBiS5H4sf2GwK/0AnYF7/B+NRi6B10 P9pritKsk9yeKedQ0N6TnGHaUtVcyaSzu39cVyVBJ+qdZ8n5a2JKBaojRjDosB/iFBOz F1drH5sCr29fOp64nVYgICmKehKzJQ5p4+K55jQje8o1gZ3flYNK3Uq+2jSshVoNrfoK E2Sn/KayPz4ACpblqmTpcKWzPijHEvdL8CigPFrEGeC3kKksv1WTz5EarwfdaPGCw2gU VKLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zBXmaPCVMLZZykpy+uTUBaFhT6YqekGzMMKrnO5HYms=; b=wLo+xvgFyxveifoz2SIbMogkYgYM8ac/vHJI7TnAmN7IfIHuGvGyexYKXyhF0w5lJl xG5qPOUhZkG2ludBHmPyIbsRMOlri+cqkcJynl/qw6+TqFqChy1HJiE+Z4gY9MrKB/8T KI46JhckJFUBX1waUbO5OJfyrBnvC90DgcVyfXntgvclzuwrBB0ltFuPdJZDkwAbVxCW yROkrpPr/Kb/WUdFEiWRqb0xO2pGZeWYCxRYRefaBq+0t61MjTpNtqBl8sqi2X6n5J9h dS7PAmL0SOveayjkdrJFOvb2Sp8oclKdf+Xs0m/QdsxDNX7KcfASL37kUhL9kByQhC18 OP/A== X-Gm-Message-State: ACgBeo1BZEABCVlZUA8crtag5MLL9tjFH5gZcM24Ju+hNhaTP6G0gPdO h67h+QTkuh7Rbj22cx38Q7Rq87Lj834RtNb8YA0= X-Received: by 2002:a17:907:a408:b0:730:f106:e692 with SMTP id sg8-20020a170907a40800b00730f106e692mr11683604ejc.132.1659990713286; Mon, 08 Aug 2022 13:31:53 -0700 (PDT) MIME-Version: 1.0 References: <20220808110315.1.I5a39052e33f6f3c7406f53b0304a32ccf9f340fa@changeid> In-Reply-To: <20220808110315.1.I5a39052e33f6f3c7406f53b0304a32ccf9f340fa@changeid> From: Luiz Augusto von Dentz Date: Mon, 8 Aug 2022 13:31:41 -0700 Message-ID: Subject: Re: [PATCH] Bluetooth: Ignore cmd_timeout with HCI_USER_CHANNEL To: Abhishek Pandit-Subedi Cc: "linux-bluetooth@vger.kernel.org" , Abhishek Pandit-Subedi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Johan Hedberg , Marcel Holtmann , Paolo Abeni , Linux Kernel Mailing List , "open list:NETWORKING [GENERAL]" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Abhishek, On Mon, Aug 8, 2022 at 11:04 AM Abhishek Pandit-Subedi wrote: > > From: Abhishek Pandit-Subedi > > When using HCI_USER_CHANNEL, hci traffic is expected to be handled by > userspace entirely. However, it is still possible (and sometimes > desirable) to be able to send commands to the controller directly. In > such cases, the kernel command timeout shouldn't do any error handling. > > Signed-off-by: Abhishek Pandit-Subedi > --- > This was tested by running a userchannel stack and sending commands via > hcitool cmd on an Intel AX200 controller. Without this change, each > command sent via hcitool would result in hci_cmd_timeout being called > and after 5 commands, the controller would reset. > > Hcitool continues working here because it marks the socket as > promiscuous and gets a copy of all traffic while the socket is open (and > does filtering in userspace). There is something not quite right here, if you have a controller using user_channel (addr.hci_channel = HCI_CHANNEL_USER) it probably shouldn't even accept to be opened again by the likes of hcitool which uses HCI_CHANNEL_RAW as it can cause conflicts. If you really need a test tool that does send the command while in HCI_CHANNEL_USER then it must be send on that mode but I wouldn't do it with hcitool anyway as that is deprecated and this exercise seem to revolve to a entire stack on top of HCI_USER_CHANNEL then you shall use tools of that stack and mix with BlueZ userspace tools. > Tested on Chromebook with 5.4 kernel with patch (and applied cleanly on > bluetooth-next). > > net/bluetooth/hci_core.c | 26 +++++++++++++++++--------- > 1 file changed, 17 insertions(+), 9 deletions(-) > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c > index b3a5a3cc9372..c9a15f6633f7 100644 > --- a/net/bluetooth/hci_core.c > +++ b/net/bluetooth/hci_core.c > @@ -1481,17 +1481,25 @@ static void hci_cmd_timeout(struct work_struct *work) > struct hci_dev *hdev = container_of(work, struct hci_dev, > cmd_timer.work); > > - if (hdev->sent_cmd) { > - struct hci_command_hdr *sent = (void *) hdev->sent_cmd->data; > - u16 opcode = __le16_to_cpu(sent->opcode); > + /* Don't trigger the timeout behavior if it happens while we're in > + * userchannel mode. Userspace is responsible for handling any command > + * timeouts. > + */ > + if (!(hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && > + test_bit(HCI_UP, &hdev->flags))) { > + if (hdev->sent_cmd) { > + struct hci_command_hdr *sent = > + (void *)hdev->sent_cmd->data; > + u16 opcode = __le16_to_cpu(sent->opcode); > > - bt_dev_err(hdev, "command 0x%4.4x tx timeout", opcode); > - } else { > - bt_dev_err(hdev, "command tx timeout"); > - } > + bt_dev_err(hdev, "command 0x%4.4x tx timeout", opcode); > + } else { > + bt_dev_err(hdev, "command tx timeout"); > + } > > - if (hdev->cmd_timeout) > - hdev->cmd_timeout(hdev); > + if (hdev->cmd_timeout) > + hdev->cmd_timeout(hdev); > + } I wonder why hci_cmd_timeout is even active if the controller is in HCI_USER_CHANNEL mode, that sounds like a bug already. > atomic_set(&hdev->cmd_cnt, 1); > queue_work(hdev->workqueue, &hdev->cmd_work); > -- > 2.37.1.559.g78731f0fdb-goog > -- Luiz Augusto von Dentz