Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp549483pxu; Thu, 15 Oct 2020 10:14:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOJv6PbCSp8lZ9QWr0lhzcA1R38adgAyK7GHKQhx6KbHqfLkW2hGee8CnfKJ5ysMnWfcAQ X-Received: by 2002:a50:d654:: with SMTP id c20mr5667181edj.54.1602782043426; Thu, 15 Oct 2020 10:14:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602782043; cv=none; d=google.com; s=arc-20160816; b=j5c94UsUAslpv286LIo1WUkXmESYSdGp5GI5Q2JSYblB3pnzI9CHHalpr0owuTCk5B iq1cumB75k2IfOz8WV8q6BYCnXj9NApiyAvW3bpze0HYoaNHK5Vm/eUGo9u/tbOBudCk TLnc7GUfQ/NPPF0uDtcMqNIGun66MOqPmY3GWcTEatTbUct0EsfMdt7no6kK3bb11YyK kRWOljkvB4MCHyXFbQYcQW6xcAGy6L573ZoGAsOxeig8OVY2Ix6MPLhi3aZShx5nYF0K 6GewcO2jrBsPxuyOUjhVZeqtY1eUzi1dRicezYvWEzEV/T2B+eRQoN9PdEURQxe2Jook 1DCg== 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=Osw6NqVYNmHUMRwCYRyMfaozlp7BCYpLh7My51/r2BU=; b=DCrIDDES1SgnAtVARjnNO5IvxJoXPHqhnHQYqjMsutLNSK8GMODWhfvZ/NsoYfGQxa X3lN43G42V1aFJN53sA0b2wGy2gHZm1GwrOkK/JOS0G9SIy001N497xeAF3nxx0QiN4P E/Ndx77XRGFi95v2WcPYu6i/wOYYpKeeoSKa4p9nilOGfDn1LfJsPSyiKGY89PiWXX/J ++PvV7i0SwlX9Iw7ssHoUwNcb4mRTIosc1UKSdlLAWCpCWbFT1Ag0Dz2LobwnTLMdzsn xMyfwm4YbefG+As+MIueB8phbRkAApyOx4t2I6bLrd5WxPwAHJY10NfmNxK/a5HCtnzf /2eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eelJr10E; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp6si2587854ejc.610.2020.10.15.10.13.16; Thu, 15 Oct 2020 10:14:03 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eelJr10E; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403901AbgJORNJ (ORCPT + 99 others); Thu, 15 Oct 2020 13:13:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403909AbgJORNI (ORCPT ); Thu, 15 Oct 2020 13:13:08 -0400 Received: from mail-oi1-x244.google.com (mail-oi1-x244.google.com [IPv6:2607:f8b0:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC659C061755 for ; Thu, 15 Oct 2020 10:13:08 -0700 (PDT) Received: by mail-oi1-x244.google.com with SMTP id w141so3908221oia.2 for ; Thu, 15 Oct 2020 10:13:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Osw6NqVYNmHUMRwCYRyMfaozlp7BCYpLh7My51/r2BU=; b=eelJr10EjXooFkYvRC0YgTs8c+BXon2D/IIM/MRqfQr36hrPc0lgQSRYolTlQrlbfe JAD40ziRnWrAWDd2t4138cTrOSZ5BJXbVqtLCi5Rv8BiOaULFHma2bG08dOHPIROxfND kJ6I7GNp3QiPS5CEDT8ISe3S4e7yj880NttWAPrYA0ckrWWyVf0UUkaRP9qbivqmUIwE fCmNyPloLyON0luS8ptD1qNQ6eip0Xx0NQ79kbD/PHjd3JCqKqBsJ5mh6jxVM8RbkB61 dG/p67jc3wNEz9Aj9YJQtWv+HeYWXwlwP4YBKqRbZ4o6tikDv9AwZmExNBwuyFyTownf QVmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Osw6NqVYNmHUMRwCYRyMfaozlp7BCYpLh7My51/r2BU=; b=Oe83Wq/ZGD0Vo1QJ+T3MuFOUiOteh+IM7WViECuGZv+ws9qwVJ9DgcupCPi82p4Twp Sr9gTls4CjvWsdy7LlV+dEwa7mTIbt+reQZB3+ppF0QvvoUhhJUFwV+zfyRwz5wT1TOC knOdw5uMkItfGZzP8FZb6G+RI8oWnPUT3YUWbWaOmYphrFXqIBuAmL391QMcjgp62BKH icepP+VS2tm6JyvDKu/Xo+Okvpq6D8wSvoOVgB4ZXbU2KruuRRJgRhO9ZTMhaP0elhds GY91d8oM78SgOf05Zc5BmXs33+GJ9hBgZczhDurm7LKUF0prBI9+cw8AUuiFFhn23bQ9 4FmA== X-Gm-Message-State: AOAM531ym9wRbc8ny1Mo/P0zq+vHeVtSIjG1mY+FhcQwEBXz8rfNvKW5 Y3OR9fAGzGHINQtxoSb3iY6NNuh+e5p7RoRs3JZ7WQ24 X-Received: by 2002:aca:4c7:: with SMTP id 190mr2906123oie.58.1602781988041; Thu, 15 Oct 2020 10:13:08 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Luiz Augusto von Dentz Date: Thu, 15 Oct 2020 10:12:57 -0700 Message-ID: Subject: Re: [PATCH] 100% CPU usage on keyboard disconnect To: Steven Newbury Cc: "linux-bluetooth@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Steven, On Thu, Oct 15, 2020 at 4:13 AM Steven Newbury wrote: > > There are a couple of issues with g_io_channel usage in bluez which > cause CPUs to spin on half-closed channels. > > This patch fixes bugs where bluetooth keyboards fail to work on initial > connection, and cause 100% cpu on disconnect. > > Also fix bug with similar symptoms triggered by some other HID devices > such as Sony PS3 BD Remotes. > > In the previous discussion on the kernel bugzilla below, it was > suggested to remove sec_watch, and I attached a follow-up patch to do > so, however that change causes problems with current bluez-5 releases > where a fd is used after being closed. > > See https://bugzilla.kernel.org/show_bug.cgi?id=204275 > > Signed-off-by: Steven Newbury > --- > attrib/interactive.c | 4 +++- > profiles/input/device.c | 3 ++- > 2 files changed, 6 insertions(+), 3 deletions(-) > > diff --git a/attrib/interactive.c b/attrib/interactive.c > index 9a7976d34..453ff064e 100644 > --- a/attrib/interactive.c > +++ b/attrib/interactive.c > @@ -64,6 +64,7 @@ static int opt_psm = 0; > static int opt_mtu = 0; > static int start; > static int end; > +static guint gsrc; > > static void cmd_help(int argcp, char **argvp); > > @@ -193,6 +194,7 @@ static void disconnect_io() > attrib = NULL; > opt_mtu = 0; > > + g_source_remove(gsrc); > g_io_channel_shutdown(iochannel, FALSE, NULL); > g_io_channel_unref(iochannel); > iochannel = NULL; > @@ -415,7 +417,7 @@ static void cmd_connect(int argcp, char **argvp) > error("%s\n", gerr->message); > g_error_free(gerr); > } else > - g_io_add_watch(iochannel, G_IO_HUP, channel_watcher, NULL); > + gsrc = g_io_add_watch(iochannel, G_IO_HUP, channel_watcher, NULL); > } I wouldn't bother with the fix above since the attrib part will be going away soon. > static void cmd_disconnect(int argcp, char **argvp) > diff --git a/profiles/input/device.c b/profiles/input/device.c > index a711ef527..9abf595f6 100644 > --- a/profiles/input/device.c > +++ b/profiles/input/device.c > @@ -982,7 +982,8 @@ static int hidp_add_connection(struct input_device *idev) > } > > idev->req = req; > - idev->sec_watch = g_io_add_watch(idev->intr_io, G_IO_OUT, > + if (!idev->sec_watch) > + idev->sec_watch = g_io_add_watch(idev->intr_io, G_IO_IN, > encrypt_notify, idev); If this is happening isn't there a idev->req already set and we are overwriting it? > return 0; > -- > 2.22.0 > > -- Luiz Augusto von Dentz