Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1200051ybg; Thu, 4 Jun 2020 03:47:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKbqTNuVzC2BWaUokTXpXVpELHCbxaznS0XjQhmw05HX6aqQ+2nXYaTWEc6alsNkqQLI5N X-Received: by 2002:a50:e711:: with SMTP id a17mr3691282edn.369.1591267671055; Thu, 04 Jun 2020 03:47:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591267671; cv=none; d=google.com; s=arc-20160816; b=ui0E8UH1lUsyXzLCTg/zBE1AWfeS8DEArffFDd22emcnxQLFgs3hK5eX+eplWWtEQQ uMw9cyJBKg3XtEjWgGG1KwDulaBJVzuBEJwQJ/hzON89TuRnu3yJZi8ddrmizbwwsVo9 8BZd2J+CWX66KzSGA6l+FkdEuCK3Lt+BwAFcP000ZuVElL4gVjUJwLQeYg7k4Yw0NSH2 VMNhTbdGm8slnpiNoh2YNwc39BFGpqEhdJ3igvThsUrBzUp7bU/aCa/GrUSjZFi5JwLT tHOTurX5rp2qgHKWntBwu4sjR7dAqvRSRbysutPvtDtUpvg3mh7zsvGLUMf6UaOo9SOU J8bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=wapTXlNyzxQxPAMAYQm5d6AJvGc7ALvZ5d5MGvh545A=; b=JcvOzL2+d2srO/nedVkhYYNvXwBg3ER4FddwCPPlpY0A4MB5Zp/8p5VEPa0X0KC795 cr3AIPwyw6tUzrqEwnRbK9jLtADXlBj6wJBBb/M3Hde56XbgcM45yD8QPMau4tXEsQm8 dujg/bx7omRytx3JBnYEUUANYrd3s7qARV9IFo3mI2pHTb7OBT7jfL7wWbA+s5XzuEqr fGCpMyhB8W1mKTglcn1FKlte1VNeKC5nNzaUiIVkaCiTcpUWsd/aP4A8MYtBS+AZTX7x xWO4acxUBg5HhrjOmh09WlibMMkPFWJPzF/2ULzHrxbLNS4BZStOlcxxRaFLnWPoDpmq nduQ== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y16si1377334ejb.177.2020.06.04.03.47.07; Thu, 04 Jun 2020 03:47:51 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726084AbgFDKq0 (ORCPT + 99 others); Thu, 4 Jun 2020 06:46:26 -0400 Received: from mail-oi1-f193.google.com ([209.85.167.193]:32879 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725854AbgFDKq0 (ORCPT ); Thu, 4 Jun 2020 06:46:26 -0400 Received: by mail-oi1-f193.google.com with SMTP id i74so4679280oib.0; Thu, 04 Jun 2020 03:46:25 -0700 (PDT) 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=wapTXlNyzxQxPAMAYQm5d6AJvGc7ALvZ5d5MGvh545A=; b=Jyl1oNuC+bkxtq1gHg/rwsDmgdli1tTgjWvzrPiTJ94sQzXuweLxRFkrJg+NcEHWTe tL+y39bJtb6Y5QUZuug+1rZoRdaLqz7cvavZxUN/eLZHiavKMp+m3Xqb65K8c9sYQN6D 2aiWxd9QJjbPUWiQq+rRzAbIeWOdF2st7YFvLfL8z14Bnpsq+/hAHmrpvXyo8gTtBIpH k2zDamF/blUZR1JDexzNSKAuvXKh3bzMR8FGRsTC2MQFpjaVjKiZm7sSM158hWXZDjTE Buos6J36uiU3d6IXknTMti+yJjbWYF01EyEipzaRbRn5Lowb/ahiyipTRSBDao/bzouk xrNA== X-Gm-Message-State: AOAM530+a2N5AbP5j/9Da95J1yYJgxkVGs7fFxVxJvGqD7e4ZoLnjosD OnHEG1VgpUr/MuCzBF6FttacXGAKjj5rxg5iw+I= X-Received: by 2002:aca:eb56:: with SMTP id j83mr2762270oih.110.1591267584968; Thu, 04 Jun 2020 03:46:24 -0700 (PDT) MIME-Version: 1.0 References: <20200603132148.1.I0ec31d716619532fc007eac081e827a204ba03de@changeid> In-Reply-To: <20200603132148.1.I0ec31d716619532fc007eac081e827a204ba03de@changeid> From: "Rafael J. Wysocki" Date: Thu, 4 Jun 2020 12:46:13 +0200 Message-ID: Subject: Re: [PATCH] Bluetooth: Allow suspend even when preparation has failed To: Abhishek Pandit-Subedi , Len Brown , Todd Brandt Cc: Marcel Holtmann , "open list:BLUETOOTH DRIVERS" , chromeos-bluetooth-upstreaming@chromium.org, Linux PM , "Rafael J. Wysocki" , "Zhang, Rui" , "David S. Miller" , Johan Hedberg , netdev , Linux Kernel Mailing List , Jakub Kicinski Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org On Wed, Jun 3, 2020 at 10:22 PM Abhishek Pandit-Subedi wrote: > > 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 Thanks for the patch, it looks reasonable to me. It would be good to add a Fixes tag to it to indicate that it works around an issue introduced by an earlier commit. Len, Todd, would it be possible to test this one on the affected machines? > --- > 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 >