All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arkadiusz Bokowy <a.bokowy@samsung.com>
To: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH] Bluetooth: MGMT: Synchronize scan start and LE Meta events
Date: Mon, 9 Oct 2023 11:25:31 +0200	[thread overview]
Message-ID: <94802ffc-9949-c968-ab96-e63f98cb684a@samsung.com> (raw)
In-Reply-To: <CABBYNZ+=c_G9wRRw4BvzypSu980ThzzdcUz_jMthe5_UZnE9Ew@mail.gmail.com>

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 = &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?

Regards,
Arek

  reply	other threads:[~2023-10-09  9:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20230928134517eucas1p296d2f03574a8948e642cfbfb5826539b@eucas1p2.samsung.com>
2023-09-28 13:45 ` [PATCH] Bluetooth: MGMT: Synchronize scan start and LE Meta events Arkadiusz Bokowy
2023-09-28 14:37   ` bluez.test.bot
2023-10-04 19:24   ` [PATCH] " Luiz Augusto von Dentz
2023-10-09  9:25     ` Arkadiusz Bokowy [this message]
2023-10-09 19:42       ` Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=94802ffc-9949-c968-ab96-e63f98cb684a@samsung.com \
    --to=a.bokowy@samsung.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.