Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp777257ybg; Wed, 3 Jun 2020 13:24:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWlFjFKhkmiwjqWl72ylE2FjyV67cVpITXC2nZYwu8gAVOVRPcuKda/zGwY8seE4ghccJ1 X-Received: by 2002:a17:906:e2d5:: with SMTP id gr21mr911948ejb.219.1591215868515; Wed, 03 Jun 2020 13:24:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591215868; cv=none; d=google.com; s=arc-20160816; b=uWoAQhshyPcwKhZUT85NegscdCfRegnvV/LNnMFBShx8RfRGooaix1yLZrU4Y2tE96 JJ5GyEOwFXxwkywT2gxKAZ322BQ6cg1tFEmJ/kB9whZSbQbQ2LqsBl6+fWGjGSE8QnBD JH0d8LFH6wcjf0N/8flhbSxAQaow7PkMl2BJadYWf9NI46ZcF2csE2hadvAZm1Ey+UV6 JUQ8RBkJ/KTf5fClP0z2vIMJPgPHyEYlLlhW0DKhnGwdOtF7hZOq3K3WnS2UEWVRlLDl eafA5PsPaW5O/y8yqDCMTPBgOf0IR9uF7/Li3v1P/mt6I/22GWYDWB00TNKwPceSrcSE srIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=tHrX3xlB9/Ck6H2yHXMw9M9lpn5geMEW0VlHI1L3+6M=; b=O6cZ5vPnjq/KSc1tBrvkQ35ngPoeYQaBWu3tlR11yqgwduf+GkIUmf3p1VvbdGROUE 4eCSAjxLfgBjadX9nFQ8j5QmmBIuLXAobNm4rDPILebERlSPz11vrmeSNaTSv5nztYEV I7i93mN3omBgsy4hvGfYu2g6R9nc7ZydmHbancKcieCF2bgr853Cx6pGIbRf+G6aIFxs gk9oDsih6BLBlPH8LkTOU9nGJgoyvPRWaaGzXPg7Hk9oZOqNAQwU2Igt4sXQ7ML2aL+k uMDa21fjpJtrd85nkzOlCJxPZw3/kgwzaHBZt57wjfLtdViqjhyiIO0oIpXb76l8Pjpd C/0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mx++0jGu; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 36si305698edp.290.2020.06.03.13.23.48; Wed, 03 Jun 2020 13:24:28 -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=@chromium.org header.s=google header.b=mx++0jGu; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725821AbgFCUWc (ORCPT + 99 others); Wed, 3 Jun 2020 16:22:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726076AbgFCUWb (ORCPT ); Wed, 3 Jun 2020 16:22:31 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADC20C08C5C2 for ; Wed, 3 Jun 2020 13:22:31 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id s88so89459pjb.5 for ; Wed, 03 Jun 2020 13:22:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tHrX3xlB9/Ck6H2yHXMw9M9lpn5geMEW0VlHI1L3+6M=; b=mx++0jGuKtq64dlZhGQxV4EMmbblVr3vosFddkncf2n9aCP4dV+FU25/P+2RTCzXSR YQ98u8pItXN34A5TDOzhJGSTUnIRve7DSOCaGMvh1OTRbsHmNUffHrJqGaD+YlUWfIj1 pv4yunKEVA1YaL10TpVE6Vm6ExgZIowgbBetA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tHrX3xlB9/Ck6H2yHXMw9M9lpn5geMEW0VlHI1L3+6M=; b=S/Zn/H4xyM59ZGULzaR2W/siNQDjBQemgwSUJ73TVGgvv3bcXhBPIWpVzkFx4uNAVo 46mxDax5juyQmsPAqFysi6aqjvCHisi9vE0A4XeU7ZEuiUyaaf6nL+pxOO48ejUoRypq V6BByGgd0bZ3yzVJe8gP45mqo9Dr4BUFbPuKasTH9s6Ic8uMF7WTFr632Rmw9r8sg24+ 4uzoD++g8Ot2U6pXbz6vnBgq9mm1Lf6D1BLSDES3OiolWI9e2qSieGI3xPIbw6qSxjaI ztX/T3tf/MTOYLg90tOIg5NsBogfgIkaRddKe4ynHQzrD6JzPoZ/4XJy9f5QEIBjFWPR rExg== X-Gm-Message-State: AOAM530jybVXnoaiV4xa4EePPPKYlmBRwjO3XpyuDuj35SqhG00USiBR GudBETULdtxEOaMKCpmlwmKPIg== X-Received: by 2002:a17:90a:6886:: with SMTP id a6mr2041876pjd.170.1591215751071; Wed, 03 Jun 2020 13:22:31 -0700 (PDT) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:e09a:8d06:a338:aafb]) by smtp.gmail.com with ESMTPSA id b19sm2492180pfi.65.2020.06.03.13.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2020 13:22:30 -0700 (PDT) From: Abhishek Pandit-Subedi To: marcel@holtmann.org, linux-bluetooth@vger.kernel.org Cc: len.brown@intel.com, chromeos-bluetooth-upstreaming@chromium.org, linux-pm@vger.kernel.org, rafael@kernel.org, todd.e.brandt@linux.intel.com, rui.zhang@intel.com, Abhishek Pandit-Subedi , "David S. Miller" , Johan Hedberg , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jakub Kicinski Subject: [PATCH] Bluetooth: Allow suspend even when preparation has failed Date: Wed, 3 Jun 2020 13:21:52 -0700 Message-Id: <20200603132148.1.I0ec31d716619532fc007eac081e827a204ba03de@changeid> X-Mailer: git-send-email 2.27.0.rc2.251.g90737beb825-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org It is preferable to allow suspend even when Bluetooth has problems preparing for sleep. When Bluetooth fails to finish preparing for suspend, log the error and allow the suspend notifier to continue instead. To also make it clearer why suspend failed, change bt_dev_dbg to bt_dev_err when handling the suspend timeout. Signed-off-by: Abhishek Pandit-Subedi --- To verify this is properly working, I added an additional change to hci_suspend_wait_event to always return -16. This validates that suspend continues even when an error has occurred during the suspend preparation. Example on Chromebook: [ 55.834524] PM: Syncing filesystems ... done. [ 55.841930] PM: Preparing system for sleep (s2idle) [ 55.940492] Bluetooth: hci_core.c:hci_suspend_notifier() hci0: Suspend notifier action (3) failed: -16 [ 55.940497] Freezing user space processes ... (elapsed 0.001 seconds) done. [ 55.941692] OOM killer disabled. [ 55.941693] Freezing remaining freezable tasks ... (elapsed 0.000 seconds) done. [ 55.942632] PM: Suspending system (s2idle) I ran this through a suspend_stress_test in the following scenarios: * Peer classic device connected: 50+ suspends * No devices connected: 100 suspends * With the above test case returning -EBUSY: 50 suspends I also ran this through our automated testing for suspend and wake on BT from suspend continues to work. net/bluetooth/hci_core.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index dbe2d79f233fba..54da48441423e0 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -3289,10 +3289,10 @@ static int hci_suspend_wait_event(struct hci_dev *hdev) WAKE_COND, SUSPEND_NOTIFIER_TIMEOUT); if (ret == 0) { - bt_dev_dbg(hdev, "Timed out waiting for suspend"); + bt_dev_err(hdev, "Timed out waiting for suspend events"); for (i = 0; i < __SUSPEND_NUM_TASKS; ++i) { if (test_bit(i, hdev->suspend_tasks)) - bt_dev_dbg(hdev, "Bit %d is set", i); + bt_dev_err(hdev, "Suspend timeout bit: %d", i); clear_bit(i, hdev->suspend_tasks); } @@ -3360,12 +3360,15 @@ static int hci_suspend_notifier(struct notifier_block *nb, unsigned long action, ret = hci_change_suspend_state(hdev, BT_RUNNING); } - /* If suspend failed, restore it to running */ - if (ret && action == PM_SUSPEND_PREPARE) - hci_change_suspend_state(hdev, BT_RUNNING); - done: - return ret ? notifier_from_errno(-EBUSY) : NOTIFY_STOP; + /* We always allow suspend even if suspend preparation failed and + * attempt to recover in resume. + */ + if (ret) + bt_dev_err(hdev, "Suspend notifier action (%x) failed: %d", + action, ret); + + return NOTIFY_STOP; } /* Alloc HCI device */ -- 2.27.0.rc2.251.g90737beb825-goog