Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp173574pxb; Wed, 24 Feb 2021 22:31:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbcbp85MacBZwkymkHC1P/DwxkBpmQy1Uh74Oc+KFVHqSkT/ZQmeyNeEqLP7uFoV/OrFzq X-Received: by 2002:a17:906:2755:: with SMTP id a21mr1252986ejd.374.1614234702377; Wed, 24 Feb 2021 22:31:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614234702; cv=none; d=google.com; s=arc-20160816; b=Yoyu7iV/ZQWf3b1C7HERGXD3fHpYP42Hp2CwjNK9IthFmgPI3P9QXkuZo0h2Q48pHh O2ozmfNp4iIVECeq5+NnhU4KsqvdUbM+/yQhB+tlPWv2epmDCTlNsPFvK7wzuPCPLSKr wQAJU2/HSkjBE3wMnMosd+B3pp1vbTIpegWgPx1Or0AHHVdTxrR93NkVfwySj+9Ww/di drCSBsCihroO4tSN2ZGC6IrMPmsKBNvXQH9X+X206kmbPxa2kuIeokZvzKxi4LUR6AjL s5RjYrSdwAWFRL96Cy+3HutLNaKzX+2XAgxLeAYS2dZPtY2eqBNCvfEE+AeDC4aoh06U kGLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=7tkzcW/y/bvCT9d3U/1K/UJ3epjJo9CBC3PUKZ73nKY=; b=uN2+NMg+e+idvLcxkbMQ2uo17crbVMbatrO+TaSN4hfsUsme8p98t3kpoUEf63V5/o /TiuyKq+FW2Q00r5gmWCu8ajR6hhN9+PD2L8edx4d1S6pbWbQosfaT+YagJnxX1cMxKU 9/OBGFGi+F6YQmRRppJ3HpnZ72oEEBS9eOwLhJZ8s0wgXFdSk6NVFKfIlJmOF1RdZnrp Hf2jdPtUfRLq0VwnRuetu6a0DG+AgQ/T5QeawLxfqwU0DcBmOfqBeSRXllv2boR2pNVA Em/GIWDYT37dxWDPHflvHECG/vQARjCmMpytmMSYHLx1idwq0hRppW7RUdA9zYbGrdVw lFCg== 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hq30si2992091ejc.677.2021.02.24.22.31.02; Wed, 24 Feb 2021 22:31:42 -0800 (PST) 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231974AbhBYEiH (ORCPT + 99 others); Wed, 24 Feb 2021 23:38:07 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:50520 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232197AbhBYEiG (ORCPT ); Wed, 24 Feb 2021 23:38:06 -0500 Received: from [123.112.65.122] (helo=[192.168.0.106]) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lF8Ov-0006AJ-Df; Thu, 25 Feb 2021 04:37:21 +0000 Subject: Re: [PATCH 5.12 regression fix] Bluetooth: btusb: Revert Fix the autosuspend enable and disable To: Hans de Goede , Luiz Augusto von Dentz Cc: Marcel Holtmann , Johan Hedberg , "linux-bluetooth@vger.kernel.org" References: <20210218123728.17067-1-hdegoede@redhat.com> <20210218123728.17067-2-hdegoede@redhat.com> <90d8996d-a376-2e9c-37ce-ce50b8660fd1@canonical.com> <4510935f-a30b-445d-a048-683619f2855b@redhat.com> <6CE927B6-449A-472C-9196-AF98895AA5E1@holtmann.org> <2bf12891-eeae-e55f-ab46-7434dffbad76@redhat.com> <2fc373c2-0255-63b6-3e4a-9aa83f6986e1@redhat.com> From: Hui Wang Message-ID: Date: Thu, 25 Feb 2021 12:37:14 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <2fc373c2-0255-63b6-3e4a-9aa83f6986e1@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org On 2/19/21 5:24 PM, Hans de Goede wrote: > Hi, > > On 2/19/21 12:41 AM, Luiz Augusto von Dentz wrote: >> Hi Hans, >> >> On Thu, Feb 18, 2021 at 2:08 PM Hans de Goede wrote: >>> Hi Marcel, >>> >>> On 2/18/21 9:01 PM, Marcel Holtmann wrote: >>>> Hi Hans, >>>> >>>> Hi Marcel and Hans, Looks like this reverting patch is not applied yet, If it is already applied, please ignore the below content. My patch really introduces a regression, that makes the autosuspend can't be enabled by btusb.c anymore. When the usb core layer calls the usb_driver->probe(), the autosuspend is disabled by pm_runtime_forbid(), if users set btusb.enable_autosuspend=1 or enable the CONFIG_BT_HCIBTUSB_AUTOSUSPEND, the probe() should enable the autosuspend by calling usb_enable_autosuspend() which will call pm_runtime_allow(). For keeping balance, when executing disconnect(), if probe() enabled the autosuspend, disconect() should disable it by calling usb_disable_autosuspend() which will call pm_runtime_forbid(). This could guarantee the kernel parameter enable_autosuspend works as expected when users repeatedly run "rmmod btusb;modporbe btusb enable_autosuspend=1/0". The users could also enable or disable autosuspend by echoing "auto" or "on" to /sys/.../power/control, btusb doesn't know users change the autosuspend from userspace, so btusb only keeps the autosuspend balanced in itself, and userspace should keep balance from userspace, btusb has no capability to detect and control the userspace operation. According to this idea, the fixing patch is like below: diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 52683fd22e05..a0811e00a5a7 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -4849,8 +4849,8 @@ static int btusb_probe(struct usb_interface *intf,                         data->diag = NULL;         } -       if (!enable_autosuspend) -               usb_disable_autosuspend(data->udev); +       if (enable_autosuspend) +               usb_enable_autosuspend(data->udev);         err = hci_register_dev(hdev);         if (err < 0) @@ -4888,6 +4888,10 @@ static void btusb_disconnect(struct usb_interface *intf)         hci_unregister_dev(hdev); +       /* if the autosuspend is enabled in _probe, we disable it here for keeping balance */ +       if (enable_autosuspend) +               usb_disable_autosuspend(data->udev); +         if (intf == data->intf) {                 if (data->isoc) usb_driver_release_interface(&btusb_driver, data->isoc); @@ -4910,9 +4914,6 @@ static void btusb_disconnect(struct usb_interface *intf)                 gpiod_put(data->reset_gpio);         hci_free_dev(hdev); - -       if (!enable_autosuspend) -               usb_enable_autosuspend(data->udev);  } Regards, Hui. > } > > static int btusb_close(struct hci_dev *hdev) > { > ... > data->intf->needs_remote_wakeup = 0; > ... > } > > Regards, > > Hans >