Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp289518pxu; Thu, 15 Oct 2020 04:10:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzS+SWA3E2B/tFqV9c6myw6+qQvpeyfFfJtDGMsh0lExmxAIgib8S+fmngpSOYu8tyX6it+ X-Received: by 2002:a17:906:aecf:: with SMTP id me15mr3977193ejb.423.1602760256055; Thu, 15 Oct 2020 04:10:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602760256; cv=none; d=google.com; s=arc-20160816; b=dhkqEj1Bdrppw6acIU77zM+MSPfekTKijmguUqEjfjvivoDpf7Bay6ZP+j+NQE71ER cJOwYVNIhNBwDBo8lUJG0uul0Z5eUggVZkfOv8BxKLEncC4JRIn60M6RXngMhAogmpl9 ucTzXzFixqPgFa0Ldvvplw3NOH1uuDThvibCJ12EqGuE4buI67ILPIKF6PJHcaQ+yMQE JROMm0OwYW6/tUOkE1l2hMWKi5oBjiUsG5JSRMa6zCWK5hCpFP3ueckBZJDfWoJsTtSm 3IQh49XY+K6GeJ48zcScGbu7XTPRRnwmC25zB9hm8iTacNnHiW0X2yinxw1nFTov5LrN fqag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:date:to:from:subject:message-id:dkim-signature; bh=gwm9+PTRIPpcOaX9nBD3WcxVmW3rsmhDGKtUOGgfSgo=; b=VoMqHT7qBnB1/GB9Pf/TMvxbk8O8y4Wz+CWBKuL+a+GxG9aBIwWLD3qd4vWDefDwZ2 fbtCYHZWJ6x6HJ1VFXlzMv3jghkNRVRwEIekY25y6ZNIO5E0zBn8raIJk4WI3hnOLJxM wGXR0cS3Hvg+ImWHKVZdsxeQRdOczy2MSB9gPiw+xTkQguBvpM56Bg7rCHPkq1t2Q8uf 6pRdUT92CiH9H+AvsfZAvniDssPxn9iOCal+1CEFjK11kDO1lmTbfPiPAr8eb3SAD00+ wIbyrM3J1eOTQwBo0pIm8oGPo7zRSM88zpsNNx6yuhJTENO8vKvASeWzQiLGZBATkFMB J6DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@snewbury.org.uk header.s=eater header.b=pB9UK59L; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h20si1790394eja.402.2020.10.15.04.10.18; Thu, 15 Oct 2020 04:10:55 -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=@snewbury.org.uk header.s=eater header.b=pB9UK59L; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727893AbgJOHVw (ORCPT + 99 others); Thu, 15 Oct 2020 03:21:52 -0400 Received: from know-smtprelay-omc-9.server.virginmedia.net ([80.0.253.73]:38625 "EHLO know-smtprelay-omc-9.server.virginmedia.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726462AbgJOHVv (ORCPT ); Thu, 15 Oct 2020 03:21:51 -0400 X-Greylist: delayed 334 seconds by postgrey-1.27 at vger.kernel.org; Thu, 15 Oct 2020 03:21:51 EDT Received: from mail.snewbury.org.uk ([86.24.188.28]) by cmsmtp with ESMTPA id SxUjkDrYVq8OASxUjkJBI5; Thu, 15 Oct 2020 08:16:14 +0100 X-Originating-IP: [86.24.188.28] X-Authenticated-User: sjnewbury@virginmedia.com X-Spam: 0 X-Authority: v=2.3 cv=WuMFz+Xv c=1 sm=1 tr=0 a=1Au+4VMCrm8g9YIHxruHCQ==:117 a=1Au+4VMCrm8g9YIHxruHCQ==:17 a=xqWC_Br6kY4A:10 a=IkcTkHD0fZMA:10 a=afefHYAZSVUA:10 a=VwQbUJbxAAAA:8 a=N1CowNylAAAA:8 a=UZ73P_w1n-BTV5vS_wMA:9 a=K8SlBP7GSjnIyugU:21 a=NnTW0SDxVMPq-83p:21 a=QEXdDO2ut3YA:10 a=AjGcO6oz07-iQ99wixmX:22 a=sPYuha5Ws6K-Rx_L469D:22 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=snewbury.org.uk; h=content-transfer-encoding:mime-version:user-agent :content-type:content-type:date:date:from:from:subject:subject :message-id; s=eater; t=1602745986; x=1604560387; bh=dTtpDHmLF/F xSta1ppJY67m+4/DzF2TaW56Kftc4E+s=; b=pB9UK59Lqplhpf0hUYyUzzCm0xB gy6Gmq/E8NF7rhPTStQn1UtMjt9cAfyGz+wYOIqxwa4e1WXwXueTur86A5t3CXFy e07+EQhazi+R3vjHx0pEXAB29I73EwOmLWsaPTdZnWbFbkVIB4iTYn/Ch5o2GaXC whd3LCe1QRV7GHWE= X-Virus-Scanned: amavisd-new at snewbury.org.uk Received: from artifact.local ([IPv6:2001:470:6efd:f101:0:0:0:a58]) (authenticated bits=0) by mail.snewbury.org.uk (8.16.1/8.16.1) with ESMTPSA id 09F7D6XU384179 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO) for ; Thu, 15 Oct 2020 08:13:06 +0100 Message-ID: Subject: [PATCH] 100% CPU usage on keyboard disconnect From: Steven Newbury To: linux-bluetooth@vger.kernel.org Date: Thu, 15 Oct 2020 08:16:18 +0100 Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfJCyJ++rpvgTVYS+j392wwaeFwQNPqIP30kYEdaSOdI0znHSJXA1lhPK5NA1zyOMqpMZ0tazl/Jiut4THeZ3vXi77oDikmuN2UuDXBI6ToXTGb08tbLb iLNYmoSI1R3ENjiuefezlN4sdk+eJ9AQakuZtMPzUjm4iCE5CNEipFfRsoyWzlJ5vGO4dmb0jCETJA== Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org 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); } 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); return 0; -- 2.22.0