From mboxrd@z Thu Jan 1 00:00:00 1970 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 2CF56CCA48B for ; Tue, 7 Jun 2022 19:56:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353988AbiFGT4N (ORCPT ); Tue, 7 Jun 2022 15:56:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354537AbiFGSrH (ORCPT ); Tue, 7 Jun 2022 14:47:07 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 774A6A30A9; Tue, 7 Jun 2022 11:01:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 29BB2B82349; Tue, 7 Jun 2022 18:01:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7FF4C36AFE; Tue, 7 Jun 2022 18:01:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654624913; bh=yZbksKnhTJZKRPkmjVlEsaJ1ZAk/xekW2n8IFCtkTMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rvxk+0e1TyILYmnDcFgiMid3iCFlBRCZXoEjKs6bq2s/HP6SQSLLz84Qeb7RFs+cs 0tWKrGg5sNThIjvhS0BbBfl5Xxa92kxXnp1cqAAZCk3aTyD1rRjYxVrHr48q+dIcnV NsA4O+1ybMmXVkfdw0tePp72nV20zCF1bgKKI9dkWy0YTNVyEbnsEeT35KZK5fXHkE 54HkhqeMpRSP+tW55rljYRCa1PWRAhJKJykpYvo1wKcJXHMfLH6w/PyoNY6KvVUNPF BXaOjkn2j0qWOYqNGEfRZSHJyb7ZDm/N7Vmyc2tZVP350hwYGbs5v8eHKJBnNh0yjj +CgZX5TkWH/mw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Duoming Zhou , Greg Kroah-Hartman , Sasha Levin , mailhol.vincent@wanadoo.fr, chi.minghao@zte.com.cn, cai.huoqing@linux.dev, linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 09/27] drivers: usb: host: Fix deadlock in oxu_bus_suspend() Date: Tue, 7 Jun 2022 14:01:13 -0400 Message-Id: <20220607180133.481701-9-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220607180133.481701-1-sashal@kernel.org> References: <20220607180133.481701-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Duoming Zhou [ Upstream commit 4d378f2ae58138d4c55684e1d274e7dd94aa6524 ] There is a deadlock in oxu_bus_suspend(), which is shown below: (Thread 1) | (Thread 2) | timer_action() oxu_bus_suspend() | mod_timer() spin_lock_irq() //(1) | (wait a time) ... | oxu_watchdog() del_timer_sync() | spin_lock_irq() //(2) (wait timer to stop) | ... We hold oxu->lock in position (1) of thread 1, and use del_timer_sync() to wait timer to stop, but timer handler also need oxu->lock in position (2) of thread 2. As a result, oxu_bus_suspend() will block forever. This patch extracts del_timer_sync() from the protection of spin_lock_irq(), which could let timer handler to obtain the needed lock. Signed-off-by: Duoming Zhou Link: https://lore.kernel.org/r/20220417120305.64577-1-duoming@zju.edu.cn Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/host/oxu210hp-hcd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c index 10d97261b433..48533eb707e6 100644 --- a/drivers/usb/host/oxu210hp-hcd.c +++ b/drivers/usb/host/oxu210hp-hcd.c @@ -3476,8 +3476,10 @@ static int oxu_bus_suspend(struct usb_hcd *hcd) } } + spin_unlock_irq(&oxu->lock); /* turn off now-idle HC */ del_timer_sync(&oxu->watchdog); + spin_lock_irq(&oxu->lock); ehci_halt(oxu); hcd->state = HC_STATE_SUSPENDED; -- 2.35.1