Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp2430352ybg; Fri, 5 Jun 2020 13:51:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5n17RDdv1DBL6Ib3LgAeDcG1+pRxNkPi/bVyw7p/lK+LpBLQkKNove0AQ2pkDS99SgBsJ X-Received: by 2002:a17:906:f0c6:: with SMTP id dk6mr10761034ejb.157.1591390280040; Fri, 05 Jun 2020 13:51:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591390280; cv=none; d=google.com; s=arc-20160816; b=kiBMCi0zm1F35wTLufMo2czTMk1LCnlYmHKZPh5Z4k1668+pyF3Wt8ZIpRwpmqic9b S/ugUrK65sLkEx7+oEYo2lOJ0uDI3GkvKlvvMrxjAlc9GNfhJJ/4ewl/0Hs6pesykdpC mprUEoDFNWEAr980PyznY4d71Ez6MEuMtbCAGSQTNkGH9qcgZJwqPinpWOJa5aLbQEs7 Ft7/k+U8IczeRfWEamvCSsH9r/wmo91t68X/zleS28RrAcjvH6wmOUfStWIn7G7IWpil ALseTsoLpDSemRpGDvopEAfyjZJ16hB1d9StQHjOh+wWVqGcfIYr5tlh1w3or+43bvdf JHdA== 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=nOiKknFW8NZXsdzDqOG6mcYAn5/jYpz6ewpTk+cA3EU=; b=ua0XeI3rKlMGlyr8FlvVCIKndvuSMxcqM14d6E9210dAvvaBB3NSFFh4C36x0cVgb3 sj2l0IAN7/zT9bkn3fpate/dghoTbVskt7Jev/LB3E4jl0cUyHoF+g/V3fFBruMZoKCb Gr+cNAIsxHsLjp8sntiKKtV614gA0FRF2Mn5v21CLezTWd8JLqRZXoG5LghOE/EXT99K RTkk0sMcPHuGn6hhF3d6f13+aecRLXofFKAJcYWyBnsyPIbDKs4vNU6dFlFpHbGIToIL 2GrOHqHW1dlwmj7zp2NxE5KKHNeLewigMIUavpKqz6yzbEFLRumqI1S+6Qb9EigDLUjc jb9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dfwQ7fK2; 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 d15si4264203ejt.482.2020.06.05.13.50.56; Fri, 05 Jun 2020 13:51:20 -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=dfwQ7fK2; 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 S1728277AbgFEUuY (ORCPT + 99 others); Fri, 5 Jun 2020 16:50:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728227AbgFEUuX (ORCPT ); Fri, 5 Jun 2020 16:50:23 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D94CC08C5C5 for ; Fri, 5 Jun 2020 13:50:23 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id 64so5501008pfg.8 for ; Fri, 05 Jun 2020 13:50:23 -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=nOiKknFW8NZXsdzDqOG6mcYAn5/jYpz6ewpTk+cA3EU=; b=dfwQ7fK2Xky7i0j86o9Lh3WLEhaSimawUnAPO83BlEeX3Ub6v3sq67ZLvBVxJHD3vP BxHfnJCIXhewm5tjT3dmjJZOEExpl0d0SdQH93CanTMt43MM+S7qQvkOytNlhWp8oISy 1KwcRIbn4xMkCiB8szpJGuAeGKNR/Q4fi2qFk= 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=nOiKknFW8NZXsdzDqOG6mcYAn5/jYpz6ewpTk+cA3EU=; b=Q6TYuqXlD2LFnAF+Rmph8Bf1b9rm3Z0v6ZhNNHnc/0RjAHZz5yyJK/u2dOa6JSRZxT Os8xju6gUqvckh1da9upwgguvuNYyR+7Kr1UNuNW/w6VwXdFdlrWOd3qCTrDT3niahep GnpWiY63bPbWJCG9v6hqRIVW/JjGe3E4bBUhpMeyb1AJDof8MaGyqe1PiypEXmKHHkJF 9aTAfIxy+vZEILdmNXqkMacSeatPc6IX0auW0PRvKiJXgK42VbV5cnqgDNU344SrwkLG Z6wOA6n6ZCIuRcwMNwF5LZUh3h3PCQcRF9vQE7iCXBRmiqVn2wLX1tNjPwWR6XxtnJ0g +iYQ== X-Gm-Message-State: AOAM531vDMCHThivU8jsmlbOMWnEMfl+PhnJe+Xx6zeK8fjrXR34Q50k TCSVV41sjuWusUZH/9FQ3LFoh3/2Z7E= X-Received: by 2002:a63:658:: with SMTP id 85mr10808736pgg.181.1591390222418; Fri, 05 Jun 2020 13:50:22 -0700 (PDT) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:e09a:8d06:a338:aafb]) by smtp.gmail.com with ESMTPSA id 63sm445152pfd.65.2020.06.05.13.50.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 13:50:21 -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 v3] Bluetooth: Allow suspend even when preparation has failed Date: Fri, 5 Jun 2020 13:50:15 -0700 Message-Id: <20200605135009.v3.1.I0ec31d716619532fc007eac081e827a204ba03de@changeid> X-Mailer: git-send-email 2.27.0.278.ge193c7cf3a9-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. Fixes: dd522a7429b07e ("Bluetooth: Handle LE devices during suspend") Reported-by: Len Brown 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. Changes in v3: - Changed printf format for unsigned long Changes in v2: - Added fixes and reported-by tags 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..83ce665d3cbfb0 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 (%lu) failed: %d", + action, ret); + + return NOTIFY_STOP; } /* Alloc HCI device */ -- 2.27.0.278.ge193c7cf3a9-goog