From nobody Sun May 10 22:40:31 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F684C433FE for ; Thu, 21 Apr 2022 17:40:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1390856AbiDURnE (ORCPT ); Thu, 21 Apr 2022 13:43:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1390858AbiDURmf (ORCPT ); Thu, 21 Apr 2022 13:42:35 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 677414A3E7 for ; Thu, 21 Apr 2022 10:39:44 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id s17so5517719plg.9 for ; Thu, 21 Apr 2022 10:39:44 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=PQ4tGevrN4xgfqJr3MXv3Xa9RxM20hPP4zbxzdXNtnU=; b=OdSBDJTt9GRx5dFvx2oT8Tip+hnnqHZ1h7Ik1IQ/hbXSwk6iw8bzcSIn5RmOOG+nuP mnWaN6vQTqVk4+b7j0U4efE/njOd7QPQjRkMXNi28gxTQ5EPZ+lqo6bdbf+G2z1jB5q0 So9+t9GsrY6HHdLSWqhqI1GnhnXE3SmgnPi6U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PQ4tGevrN4xgfqJr3MXv3Xa9RxM20hPP4zbxzdXNtnU=; b=lj/ejvwkaZokJsHR4d0tL/ypMe70JwemDeDbNOhFnmLX7DyEOPMrNF0q2YQf89pBne fu1LjqJutKbf0vI/AmxyJnpZnLhaBM5uCscnsyaXr2NHZ2FyVXTfXXYlzkifFRoIrAqc 8POi8lMQ10ywnn7vCb90SsDAojtz6KEOJiplXNBw7SKdEsUBNojQwfwFssQObF/rinEL FiQo6vooknY0OPNDlyl4JFnT87epLi2jxdCUvku/6+TCQ5NROyvrGku3Ckdb1LZZl1Po mNodD3sdQwF1vxcwhLXJDZHtGa32ZiCfe+K+tv6yZxShGoijADJ3Mv+OJRbuc5X5zJ60 u+Og== X-Gm-Message-State: AOAM5321q0WaOMXc/I5s/TZXpROuDR16Whb8UeCH2j9ZiqZacGOc0p2o Lkc4uyCvZgur9A79HGgTDuAhgg== X-Google-Smtp-Source: ABdhPJyzE2mVhtCPNj/gXz3zxdM6YFcgQJI8mbFf0Pc6aJajgSm+xW9K94/HTOnUhbHMxOvN3qd8Bw== X-Received: by 2002:a17:903:2487:b0:159:bce:4e1a with SMTP id p7-20020a170903248700b001590bce4e1amr648959plw.4.1650562783767; Thu, 21 Apr 2022 10:39:43 -0700 (PDT) Received: from evgreen-glaptop.lan ([98.47.98.87]) by smtp.gmail.com with ESMTPSA id j6-20020a63b606000000b003808b0ea96fsm23237023pgf.66.2022.04.21.10.39.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Apr 2022 10:39:43 -0700 (PDT) From: Evan Green To: Greg Kroah-Hartman Cc: Mathias Nyman , Alan Stern , Rajat Jain , Oliver Neukum , Thomas Gleixner , Evan Green , Razvan Heghedus , Wei Ming Chen , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 1/2] USB: core: Disable remote wakeup for freeze/quiesce Date: Thu, 21 Apr 2022 10:39:26 -0700 Message-Id: <20220421103751.v3.1.I2c636c4decc358f5e6c27b810748904cc69beada@changeid> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20220421173927.2845967-1-evgreen@chromium.org> References: <20220421173927.2845967-1-evgreen@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The PM_EVENT_FREEZE and PM_EVENT_QUIESCE messages should cause the device to stop generating interrupts. USB core was previously allowing devices that were already runtime suspended to keep remote wakeup enabled if they had gone down that way. This violates the contract with pm, and can potentially cause MSI interrupts to be lost. Change that so that if a device is runtime suspended with remote wakeups enabled, it will be resumed to ensure remote wakeup is always disabled across a freeze. Signed-off-by: Evan Green Acked-by: Alan Stern --- Changes in v3: - Fix comment formatting and line wrap Changes in v2: - Introduced the patch to always disable remote wakeups drivers/usb/core/driver.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 355ed33a21792b..b87452e228353d 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -1533,22 +1533,23 @@ static void choose_wakeup(struct usb_device *udev, = pm_message_t msg) { int w; =20 - /* Remote wakeup is needed only when we actually go to sleep. - * For things like FREEZE and QUIESCE, if the device is already - * autosuspended then its current wakeup setting is okay. + /* + * For FREEZE/QUIESCE, disable remote wakeups so no interrupts get + * generated. */ if (msg.event =3D=3D PM_EVENT_FREEZE || msg.event =3D=3D PM_EVENT_QUIESCE= ) { - if (udev->state !=3D USB_STATE_SUSPENDED) - udev->do_remote_wakeup =3D 0; - return; - } + w =3D 0; =20 - /* Enable remote wakeup if it is allowed, even if no interface drivers - * actually want it. - */ - w =3D device_may_wakeup(&udev->dev); + } else { + /* + * Enable remote wakeup if it is allowed, even if no interface + * drivers actually want it. + */ + w =3D device_may_wakeup(&udev->dev); + } =20 - /* If the device is autosuspended with the wrong wakeup setting, + /* + * If the device is autosuspended with the wrong wakeup setting, * autoresume now so the setting can be changed. */ if (udev->state =3D=3D USB_STATE_SUSPENDED && w !=3D udev->do_remote_wake= up) --=20 2.31.0 From nobody Sun May 10 22:40:31 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B903C433EF for ; Thu, 21 Apr 2022 17:40:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1390869AbiDURnK (ORCPT ); Thu, 21 Apr 2022 13:43:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1390879AbiDURmn (ORCPT ); Thu, 21 Apr 2022 13:42:43 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3A52D47 for ; Thu, 21 Apr 2022 10:39:52 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id x80so5666693pfc.1 for ; Thu, 21 Apr 2022 10:39:52 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=aKecDjOh5Hsplgo3DwsxBvjIajRQbWHRMhevzw1bna0=; b=V1hn+scp77WcFmcQyhATr12t5sJq4J1DqwAVjnLg2GNWFaQ3UqKuxkSvEbEuYa3hT1 zwWEQeajgdxjNLgebPYSy3rcnmBWGCJW582DzbymfSaPKVf7POKOqMcPOxOiBoeZP+/5 yto7g2zpFJqGNlDImmXh37tO7Fycv1DC2LAS4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aKecDjOh5Hsplgo3DwsxBvjIajRQbWHRMhevzw1bna0=; b=6uxK2XOb3qisvgjnsWxHR4vlHisHlXRRNR65+B+7FBtnpipSfLoPPhsL+qMRD7NVyP SHw86Ncvb3xg3KhwPxSNTN6C3TjJXQDKbSlc2VgkZTeJS6jDoj0/+fsx9bvKpBx7K7Gj 4ipT/bGVRqMPaOAn3DZKALsB7wYZsVwhAuSLNhC7iC5ys5OkriC3OYi9qOmgC+We4exf tBwbuqk0x7AybsLtEmIFDE+mke9eugBUxtROaLK0PoNLz42RsfzSXio/G3BA7Wdekx7X Qpnj/lRWaBhE72EfB+M1roKTKVrWnQd24LeGC+QrXCSyXS+LtfIyDNC7eKamyNKFX7rT mVWg== X-Gm-Message-State: AOAM533INnAiXCFlNfBhypwVxdf4GUbXPo8MlbD1aCwpHYHAYFua3950 l00xyv6i4esJhwpA0c8379asyA== X-Google-Smtp-Source: ABdhPJwL9UaE6eRPcDU5xb21DeZNmyYxJSDhh/o1itNcLlstR4zRSUJ8oF7krQ403Wz/UTPLZOlAjw== X-Received: by 2002:a05:6a00:856:b0:50a:431b:c298 with SMTP id q22-20020a056a00085600b0050a431bc298mr694589pfk.75.1650562792542; Thu, 21 Apr 2022 10:39:52 -0700 (PDT) Received: from evgreen-glaptop.lan ([98.47.98.87]) by smtp.gmail.com with ESMTPSA id j6-20020a63b606000000b003808b0ea96fsm23237023pgf.66.2022.04.21.10.39.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Apr 2022 10:39:52 -0700 (PDT) From: Evan Green To: Greg Kroah-Hartman Cc: Mathias Nyman , Alan Stern , Rajat Jain , Oliver Neukum , Thomas Gleixner , Evan Green , Bjorn Helgaas , "Rafael J. Wysocki" , Youngjin Jang , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v3 2/2] USB: hcd-pci: Fully suspend across freeze/thaw cycle Date: Thu, 21 Apr 2022 10:39:27 -0700 Message-Id: <20220421103751.v3.2.I8226c7fdae88329ef70957b96a39b346c69a914e@changeid> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20220421173927.2845967-1-evgreen@chromium.org> References: <20220421173927.2845967-1-evgreen@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The documentation for the freeze() method says that it "should quiesce the device so that it doesn't generate IRQs or DMA". The unspoken consequence of not doing this is that MSIs aimed at non-boot CPUs may get fully lost if they're sent during the period where the target CPU is offline. The current callbacks for USB HCD do not fully quiesce interrupts, specifically on XHCI. Change to use the full suspend/resume flow for freeze/thaw to ensure interrupts are fully quiesced. This fixes issues where USB devices fail to thaw during hibernation because XHCI misses its interrupt and cannot recover. Signed-off-by: Evan Green Acked-by: Alan Stern --- (no changes since v2) Changes in v2: - Removed the change to freeze_noirq/thaw_noirq drivers/usb/core/hcd-pci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c index 8176bc81a635d6..ae5e6d572376be 100644 --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c @@ -616,10 +616,10 @@ const struct dev_pm_ops usb_hcd_pci_pm_ops =3D { .suspend_noirq =3D hcd_pci_suspend_noirq, .resume_noirq =3D hcd_pci_resume_noirq, .resume =3D hcd_pci_resume, - .freeze =3D check_root_hub_suspended, + .freeze =3D hcd_pci_suspend, .freeze_noirq =3D check_root_hub_suspended, .thaw_noirq =3D NULL, - .thaw =3D NULL, + .thaw =3D hcd_pci_resume, .poweroff =3D hcd_pci_suspend, .poweroff_noirq =3D hcd_pci_suspend_noirq, .restore_noirq =3D hcd_pci_resume_noirq, --=20 2.31.0