Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3698910pxv; Mon, 26 Jul 2021 09:40:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeZhu7OFx/lwdadIZbY7rWjtdkIsSPcDc9+PBj2qbemjKE7srYuiKNnx5xMdJnN0R8idAT X-Received: by 2002:a5e:d918:: with SMTP id n24mr15834844iop.173.1627317512361; Mon, 26 Jul 2021 09:38:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627317512; cv=none; d=google.com; s=arc-20160816; b=PviQ5m+ZDtlzQ3ifOsLe4QhIqPeeZ6cFXmotsWDHKKgpvTfqpuDUT8HyLsMMQHw8/j NWQExRUqBPuYHSjURirM+SkwmomokUZvYI5XPOomnQ8cVii8xF3aRwY5+KPbnhuYzeFW 2xEpOnYT8+ltaJCpSpTxr27HwBSx5rJE4aA5YfTc3YRdx7dYOpZkGjXLq4c+/2kI843F wPhelJ5uWFCx7pl/f57OZXWNTcN78i+eGsLUG/Gerf6MgI/mbT4xG9wXemNTxaJuYbSD xgyKTrCZH2iQtjA0Vz4Nm0gQFDSHt5beGyrTm3SSJy/+aPZEp369YK+al34PZluhmaUW 25eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WKiHwfh6hrrF6HJz4agsOuXY132hMiSM1sJNqzQY62Q=; b=M5cJ/XBGC/rh2Z2ICklAv33IpxWv1w//Dn9miCjwF8r1zqcdjsfs2HjCRi1WwKWuvB TUuzXijF1gUlEjHTzVoynpSMfpCICLetZ1r/EcmJowGbwDfrolBFYeP7UFVEZvtdZCf/ MEBIrsVc7CGIXuQMfCLzk0YfErUoj7EaekKDP5tFsupPr3N7PTmhIUIRMIqyIdjOwwQf aHc41Bkyq/j/EUMsPc0VKKlpG66gVFwwLD9nvlmxXzGr7pv2KeVliqLeWq+NWlG/jHDm aDxjYKvu8F+SnTnJRI/j2pRrDfFem/AvOZna811gJKCi+W1Y9/WDbenYObhDqyMiiMiK uQ2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CMgdjqs3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v18si371845ilc.155.2021.07.26.09.38.20; Mon, 26 Jul 2021 09:38:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=CMgdjqs3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239797AbhGZPyZ (ORCPT + 99 others); Mon, 26 Jul 2021 11:54:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:50014 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234076AbhGZPdL (ORCPT ); Mon, 26 Jul 2021 11:33:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7DE5B60F6E; Mon, 26 Jul 2021 16:13:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627316019; bh=qdDUhtH1RMcmf8jAB5w9NHZPD0X2nkHB17/R4wnl74g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CMgdjqs33TStMCzl5Q64GQb7Z89bQ4oMYuB08570U4ZqFU6oOyREn0HdG6BAEWQDA zWf1o8Hbr/Fs/blJXauTLv61a+PX7V1wkiHXaIIs9l0QA2oMUPIVY6G59DZRs+rSuO MAV/cJWAXDWlHEiwyFaN88XEMwX08A478ibx9oUg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 5.13 157/223] xhci: Fix lost USB 2 remote wake Date: Mon, 26 Jul 2021 17:39:09 +0200 Message-Id: <20210726153851.353857680@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153846.245305071@linuxfoundation.org> References: <20210726153846.245305071@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mathias Nyman commit 72f68bf5c756f5ce1139b31daae2684501383ad5 upstream. There's a small window where a USB 2 remote wake may be left unhandled due to a race between hub thread and xhci port event interrupt handler. When the resume event is detected in the xhci interrupt handler it kicks the hub timer, which should move the port from resume to U0 once resume has been signalled for long enough. To keep the hub "thread" running we set a bus_state->resuming_ports flag. This flag makes sure hub timer function kicks itself. checking this flag was not properly protected by the spinlock. Flag was copied to a local variable before lock was taken. The local variable was then checked later with spinlock held. If interrupt is handled right after copying the flag to the local variable we end up stopping the hub thread before it can handle the USB 2 resume. CPU0 CPU1 (hub thread) (xhci event handler) xhci_hub_status_data() status = bus_state->resuming_ports; handle_port_status() spin_lock() bus_state->resuming_ports = 1 set_flag(HCD_FLAG_POLL_RH) spin_unlock() spin_lock() if (!status) clear_flag(HCD_FLAG_POLL_RH) spin_unlock() Fix this by taking the lock a bit earlier so that it covers the resuming_ports flag copy in the hub thread Cc: Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20210715150651.1996099-2-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/xhci-hub.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -1638,11 +1638,12 @@ int xhci_hub_status_data(struct usb_hcd * Inform the usbcore about resume-in-progress by returning * a non-zero value even if there are no status changes. */ + spin_lock_irqsave(&xhci->lock, flags); + status = bus_state->resuming_ports; mask = PORT_CSC | PORT_PEC | PORT_OCC | PORT_PLC | PORT_WRC | PORT_CEC; - spin_lock_irqsave(&xhci->lock, flags); /* For each port, did anything change? If so, set that bit in buf. */ for (i = 0; i < max_ports; i++) { temp = readl(ports[i]->addr);