Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2105221rdb; Mon, 9 Oct 2023 12:42:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF3YUKKQpK1LncU0dYp6EKQ5LpOAfWJxfNjSp03e6k1Zf/iyZt5c8RpVfTuOPRspqzN6F4u X-Received: by 2002:a05:6358:7208:b0:141:3fd:2441 with SMTP id h8-20020a056358720800b0014103fd2441mr18312774rwa.30.1696880576062; Mon, 09 Oct 2023 12:42:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696880576; cv=none; d=google.com; s=arc-20160816; b=bngEISn7/crEzYspks/2Sl5DKk1rwRUGbmqmqRJtlimu/SkYKu8smjA8hKe960Wklr zAAsz+q2QiQhWKMe5lMhb6aKW0L44hOFIa3ti9ZvIoRRM3RmolWJPn/BR9sBBKxa0dZ9 M1QtuGxT2Xeb6nlf1E7drkhMTWJgs5/dm6jqCbtQj+ubGpLKt2Kl8M1w2XBqsFt6DQsj a5ijJfr1qS+1JZoiKSq0apTQdMvYTdSN/cp6Rdi6UHlslsJMfkPPYFBX6xZhMFUdhn8C I89X1AKEL0qY9wqiwAqoFWTbbPvy9A+NCIklsA2OVDf48ojrkCfBRCb9o/M8nkH54fPQ Zamg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=aUCAdcJRNl7fOVahEJi4wyoNXnCF3/Nv5hIB7ql4CN4=; fh=7hY16uJr7wyzBKLrTYSsuBRZYotTJ1XSY+h6grKXRSE=; b=jCr/w7fw48SOZ2UCOZPIHi6XfBDNMtryJmNE0CkrnWfwTNEtak2+0y103H2qrV7trD rj/1O7bm5+MpqG4fkm14M8GFldPxMQYenOERvVt5f4cCcFUJVGQF3Hqx99bgRCPXibYA KITrEJhYLVo2ZBFar4ALdyWndFg/h/YGEM9FT5M2AtP3vFoMtpjlyFOwr9hRzkqz2mPL H5jmFU3Yq5cRqdx2PIey5ltb4QPZvk4wsiRDDTH1R1zbzsOSOXseyRYGXOxVEqpHO3p3 Aejk8Vq+6f5O98TlclfcLrhrGFFLq7vSxiOfL0L1X9plo7zuRacmlfkCRT9f2k6cTLQC 8tHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cpaTsOBT; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id x3-20020a056a00188300b0068fb8fa1e71si8384268pfh.207.2023.10.09.12.42.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 12:42:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cpaTsOBT; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 8F17F811338F; Mon, 9 Oct 2023 12:42:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378420AbjJITml (ORCPT + 99 others); Mon, 9 Oct 2023 15:42:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378443AbjJITml (ORCPT ); Mon, 9 Oct 2023 15:42:41 -0400 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5601B6 for ; Mon, 9 Oct 2023 12:42:39 -0700 (PDT) Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2b9d07a8d84so61781251fa.3 for ; Mon, 09 Oct 2023 12:42:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696880558; x=1697485358; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=aUCAdcJRNl7fOVahEJi4wyoNXnCF3/Nv5hIB7ql4CN4=; b=cpaTsOBTNhHHWrLNaOLkmIhHwHXa2kRD65pVd3cbLwuKKpLWS8b1p4LBzUu3M+lzPy WjHKtAIz9Cq848yBVsq3ungjZY0OBQRhjrlvqg5PXCpuA8trrJQZAh35vJsGcH0YIM3y cJ+dbEz8e8o85vPPDVPDYoNU7om7Q56+FcFKwTYslDNzRHzU4K3gYDN8Yc0x/HBfV6/y 33sMn+CgCa05f29s5TcFPZZ5WS+5kREYvmAWP7wMAfC9XGEDk2q2eyeEjuPOYtQ54YEy YPiPRHJKOA+6/rfpAp5TySYtiARYGewCqYUvuSL3kldZ4X8nvPjHL3RXOmCkB9yMQfC0 iXCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696880558; x=1697485358; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aUCAdcJRNl7fOVahEJi4wyoNXnCF3/Nv5hIB7ql4CN4=; b=P1h4nxkdEkjZLuh8BGrxu2vzo2OR+2hW9KOslZO28fKDvz9TzjbQlk7Y+rYgcZRVMD w2Bo6b0DvWL3d1wCcdBgJ523dJckaTImC2zkpZledhblC+PvcWXb8nez2EKy0S8FAL0e DSiJfWucIsoKsPtmHZEzyJ2WocesQB5MDeAmBqGUjeA8ryPKCzPfsWqFZ2VT1B48dJbn Fqo25eZHXHEA0h/BiXhdiD2klIVv/CmgJEbdXv/4q3ttzfJIb1K+QzQfglO8z89rDIYS wBcawOZVP7L9a1DUmcI0yYwnIvEsFQa2QogPDIH9PYCK8XAiNaTFam+MzcVHiJtjeKf8 bnbw== X-Gm-Message-State: AOJu0YyxC6Z433oKknYMwo3NpnleBr/bI2c6rlyICG9sbv3zqWfcWfis LBzCUcU4tlbVzPuqPYqeJSpclRogBoFS7rDLgUc= X-Received: by 2002:a2e:9001:0:b0:2c1:7df1:14a6 with SMTP id h1-20020a2e9001000000b002c17df114a6mr15020668ljg.9.1696880557717; Mon, 09 Oct 2023 12:42:37 -0700 (PDT) MIME-Version: 1.0 References: <20230928134506.130545-1-a.bokowy@samsung.com> <94802ffc-9949-c968-ab96-e63f98cb684a@samsung.com> In-Reply-To: <94802ffc-9949-c968-ab96-e63f98cb684a@samsung.com> From: Luiz Augusto von Dentz Date: Mon, 9 Oct 2023 12:42:25 -0700 Message-ID: Subject: Re: [PATCH] Bluetooth: MGMT: Synchronize scan start and LE Meta events To: Arkadiusz Bokowy Cc: linux-bluetooth@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 09 Oct 2023 12:42:43 -0700 (PDT) X-Spam-Level: ** Hi Arek, On Mon, Oct 9, 2023 at 2:25=E2=80=AFAM Arkadiusz Bokowy wrote: > > Hi, > > >> +/* Wait for all pending HCI commands to complete. > >> + */ > >> +void hci_cmd_sync_flush(struct hci_dev *hdev) > >> +{ > >> + flush_work(&hdev->cmd_sync_work); > > > > Afaik this will block waiting the work to complete which sounds a > > little dangerous especially if hdev has been locked. > > Yes, this will block wait for all tasks queued on the cmd_synd_work. > Unfortunately, I'm not very familiar (not yet) with BlueZ kernel > component, so I'm not saying that this solution is correct. I hoped > that someone with actual kernel knowledge will review it :) > > Anyway, my simple test case passes with such solution without any lockups= . > > Alternatively, I can move this block wait before hdev lock in > hci_le_*_adv_report_evt() functions. > > > Couldn't we just do: > > > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c > > index 195aea2198a9..78f0a8fb0a19 100644 > > --- a/net/bluetooth/hci_core.c > > +++ b/net/bluetooth/hci_core.c > > @@ -136,6 +136,7 @@ bool hci_discovery_active(struct hci_dev *hdev) > > struct discovery_state *discov =3D &hdev->discovery; > > > > switch (discov->state) { > > + case DISCOVERY_STARTING: > > case DISCOVERY_FINDING: > > case DISCOVERY_RESOLVING: > > return true; > > I'm not sure whether it will fix the issue... I've tested it and it does > not pass my test with a delay added to the start_discovery_complete() > function. The problem here is with synchronization. Since the LE meta > event (device found) and start discovery completion might be processed > simultaneously... Also, it will not be true that discovery is active if > the state is "starting", because HCI might return error when enabling > scanning. > > There is other solution to my problem, though. In a real world case > scenario, it's not an issue that the LE meta event coming just after > scan enabled signal will be dropped, because there will be more such > events later. The problem is with btvirt, which does not "broadcasts" LE > meta events when discovering is enabled. So, I can "fix" btvirt instead > of patching the kernel, by repeatedly signaling LE meta events. This > will slightly increase CPU load with btvirt, but will work. What do you > think? Yeah, I think it is more of an issue with btdev then, perhaps we need to add a delay or something to generate the reports, or we keep generating them based on the scan parameters that way it would emulate a little bit better how it works with real controllers, that said keep in mind that we need to cancel all timers properly as well if we go ahead with this change. > Regards, > Arek --=20 Luiz Augusto von Dentz