Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1411284iob; Thu, 5 May 2022 00:02:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydmXxXng790ELw1OCUUOsnj9uJzhmmbceDagtIgUwkgbCWG60EbrqaocAiMFK9gGkl/Tsl X-Received: by 2002:a63:2486:0:b0:3ab:84c3:864a with SMTP id k128-20020a632486000000b003ab84c3864amr20878900pgk.358.1651734144224; Thu, 05 May 2022 00:02:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651734144; cv=none; d=google.com; s=arc-20160816; b=vLa8BPpTNRBEXCK1Tbej/t1fDIa0sFbkFjtK4pXKTb2MxfPkTAdOm53z8Dt46YZ4Pu RZl5+PAbNKd4yxvi4dehf4KX6JrXKQFYPr/pwZtUAeeCjlBNw6xGjN4semtM8d5NXrzK 0W0IayGssTlfpSeC8rTu4crJem68S40vnpJLkWh5YNsJoxw0wHMe/vMn1qqWsmaOZVhS SDsFtmubU5BXivkjhbCYln8N8IV3mXZUoP3Y9DtH7d2deO6jFRQfmR/eUAIUjURoj3Fn rgxEfffxkdirASXticVTANZ0Ib4KIp0doa3Exqr9fRfE0QhSa6PgGcB1Evw/MZ6ASA/e Qwuw== 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=M3se03vIEi9lxNqGgv7/ljKKyzUc3D+e8cr8+A6ODGQ=; b=jDcWBmWxVF9m0runKOA6I+kGt9NObyiLJev8lLaWZYYdEPHlSJ8ftkxpWdEMpvytAd r+ESf+pkVNkg6LrxAb9GQN5XtwH1do59SWpvQtYPWC28HwYrv++baEYA2YAjcNUPoR6x XGtsnAMoNYqZOIrIjTLMNlDP6KcJvqy4A0VqTBVAlviVUmjM6QRTdOoCrSo+2lKgJBiI yHAamVCi+lNZkIypKqAFESbBJf5OIkvpF1rOiEkCAjpuxMvC/EwNQCLosn8uvIZvNbzM Z0/1XhVgvnPeDXm4OXadLbti429/xkO0V0zdiMK6NStId0nc6ChhboW8LwcooDDG+2IM 2GfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uAcpCgZh; 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 d3-20020a634f03000000b003aaf76cfd76si663999pgb.835.2022.05.05.00.02.06; Thu, 05 May 2022 00:02:24 -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=uAcpCgZh; 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 S1359177AbiEDRn5 (ORCPT + 99 others); Wed, 4 May 2022 13:43:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355967AbiEDRI5 (ORCPT ); Wed, 4 May 2022 13:08:57 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 433E5522FD; Wed, 4 May 2022 09:54:46 -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 D6DD6B82795; Wed, 4 May 2022 16:54:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8905AC385AA; Wed, 4 May 2022 16:54:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683283; bh=D393BtSYLwAHXD0I165NpZZJKw/jq3qoPsQLyLfQj3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uAcpCgZhwWUPI1AWEfpcBejEv+Nrv6wNwIikBNm14p+3zkme+5OnNGULiuhcfEAHK 517qUEalIo17qgZoIuNV4fKFpuvzMSzn+sOGTWShBmlqW5MGFhyOh3bVXAmmSg6X2D JosxiN8dbC6gdHY+xv5Tx7yZAcowYrpZOw7olkw0= 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.15 136/177] drivers: net: hippi: Fix deadlock in rr_close() Date: Wed, 4 May 2022 18:45:29 +0200 Message-Id: <20220504153105.388616683@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153053.873100034@linuxfoundation.org> References: <20220504153053.873100034@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 7661dbb31162..50e4bea46d67 100644 --- a/drivers/net/hippi/rrunner.c +++ b/drivers/net/hippi/rrunner.c @@ -1353,7 +1353,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