Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1921825iob; Thu, 5 May 2022 10:55:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0zKvsCuY2bwB6eDgRZMzfA+LmHltDgSRHKSL90yV+8W5w5STIWP8PSbBmNx+Q1QbZXNsR X-Received: by 2002:a17:907:60cc:b0:6f4:ffba:489 with SMTP id hv12-20020a17090760cc00b006f4ffba0489mr3167887ejc.666.1651773358310; Thu, 05 May 2022 10:55:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651773358; cv=none; d=google.com; s=arc-20160816; b=fwuJIDkSQTuRuxphvoPP1CvFeHyAlXjM2LRUH4d5U0A97Ry/EM/zQ8GLcGzZmFuiyp aXkXt0zUcZYoi3pRViKb9oeMrs4Cu612ZBImu7ntr0Hzraek++vzmdWw2T+6OMwtj1r4 CAQw5bdGmdfRYiRvl1V7jKhVg0FC8WfbAWA/+E/FmmzhNzhau3H6reHFYC1vrIrZeTG+ iuj0E/pDZq8WXzV2b2tkwbbvPRuA95XmltaiKxQ8pNM/Bw4Px/K78S2MaIuEf1WSnld1 GPCn5tQ0Lyrf2S9+d4BBBoqMrYPbBUgLvbAXHaQg3uSphlFROi1tipF3u4/dgpRtfCcn 8ssA== 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=FvzoxDyEl7xqy8WZ9C7HXhcBYsjDxJSOXaIAYh8pSX0=; b=sxG3l7W4TA4hmZCFsVtRsVvHuT1P3xzV8CFIACCm3SD/LvxZWOeb355idMzgZl53N4 Iarb6hTdoxcEhTw3Z7/LLz5nixTBrm3lYkDWDV7ZRxwIFb8OeVnwT8xGyXYNpobKBZM2 HpjSnZzWMw9fuMp3wYIzf2HjYK4hjEQD8Xg1+vPJrpGe1LCCYlnpvuBjqrBwIAXo65To OZQ/2A/pqkOKg0VVGYKjEMqnUdCxcaGuj3xOl6wQWClTMNWU+DzElQBkzXoOTy/tHtzq b2GL2OBgSt3xJP3d/nI7HvZt7jDv6aar6Ee50mqSeQytZHaNUBEZ7mI0GKRCw+CekXNC qAsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NzkMGtWy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n12-20020a17090625cc00b006ec0acfe30esi2791440ejb.877.2022.05.05.10.55.34; Thu, 05 May 2022 10:55:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NzkMGtWy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1354449AbiEDQ54 (ORCPT + 99 others); Wed, 4 May 2022 12:57:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354505AbiEDQyb (ORCPT ); Wed, 4 May 2022 12:54:31 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4210947385; Wed, 4 May 2022 09:49:42 -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 C4785B827A0; Wed, 4 May 2022 16:49:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73BCAC385A5; Wed, 4 May 2022 16:49:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651682979; bh=C3Yvy/qzZwrx37raEwVDeS3Z2P4nQvqPOYKe2HSqq5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NzkMGtWyyePC2/sccrPMdS+GAZXR/YqZsEMP4u422PBcweNz9Uk+4T6g/1d82qUKo SC6XjegujByw14fHwJxVKztFpjtZ5kJwV0BSut29rTako7feT93o+gFAI/41GXi24r kPkfm5B+P9JP60q8lIkvRqxOQe6zP/j35kRLb1yo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Duoming Zhou , Paolo Abeni , Sasha Levin Subject: [PATCH 5.4 72/84] drivers: net: hippi: Fix deadlock in rr_close() Date: Wed, 4 May 2022 18:44:53 +0200 Message-Id: <20220504152933.080098207@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504152927.744120418@linuxfoundation.org> References: <20220504152927.744120418@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Duoming Zhou [ Upstream commit bc6de2878429e85c1f1afaa566f7b5abb2243eef ] There is a deadlock in rr_close(), which is shown below: (Thread 1) | (Thread 2) | rr_open() rr_close() | add_timer() spin_lock_irqsave() //(1) | (wait a time) ... | rr_timer() del_timer_sync() | spin_lock_irqsave() //(2) (wait timer to stop) | ... We hold rrpriv->lock in position (1) of thread 1 and use del_timer_sync() to wait timer to stop, but timer handler also need rrpriv->lock in position (2) of thread 2. As a result, rr_close() will block forever. This patch extracts del_timer_sync() from the protection of spin_lock_irqsave(), which could let timer handler to obtain the needed lock. Signed-off-by: Duoming Zhou Link: https://lore.kernel.org/r/20220417125519.82618-1-duoming@zju.edu.cn Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- drivers/net/hippi/rrunner.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/hippi/rrunner.c b/drivers/net/hippi/rrunner.c index a4b3fce69ecd..6016e182f008 100644 --- a/drivers/net/hippi/rrunner.c +++ b/drivers/net/hippi/rrunner.c @@ -1346,7 +1346,9 @@ static int rr_close(struct net_device *dev) rrpriv->fw_running = 0; + spin_unlock_irqrestore(&rrpriv->lock, flags); del_timer_sync(&rrpriv->timer); + spin_lock_irqsave(&rrpriv->lock, flags); writel(0, ®s->TxPi); writel(0, ®s->IpRxPi); -- 2.35.1