Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1593841pxb; Mon, 12 Apr 2021 01:45:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZ1fQNv3Y1rR8Z/M1/mBN6byPdxhQUMNYajTLVyThtKQnPWxsCTNv1wja5uu9vPnpILTw4 X-Received: by 2002:a17:902:e211:b029:e9:a266:53a7 with SMTP id u17-20020a170902e211b02900e9a26653a7mr18319985plb.11.1618217121558; Mon, 12 Apr 2021 01:45:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618217121; cv=none; d=google.com; s=arc-20160816; b=aafIBY/0JKE+smpLWRlEl+Jxi6X4Uiwfcpk9BlKwUfDdXR6uDe1FLey+CgeQ1qLMDb l2deQE9UWKX93KqYPa5T3Qfya6wbQIzj6Lelylo+ctSKervOgJvfwQ0iOP7JHC0kCbe7 DYbVSdeQyXLb7nNmzdCvJiXvcAwCZtMD3pcozXQys0zbSvFsUn/h4gbjYi/QoZnSZnE8 snUg5O6+vjyKb7IptT15TUgaAyoh17hT8ykN5P1j6cqxJNwLMaIthf+kwJUC9f1heYVJ lfwiSxHxxmVnTvm2+pyaCJJLwYgHjdMrel/KiwkiuKVz0bVNWUOSwgP0xpeAaR5hoavi 5e7g== 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=5H6r112hwfaV+pOSESHCp6D4fkNHbpMxNIq3MSyCGWs=; b=If1a+720YjKVPTOtGostCGWzZ0c3LY7Hqq9OZ8Q8/bkiHEIyLBZBqIV0YzZ1pRETrL NwHIwdTMZxqDpRgpzYjJTr+Lkizq/d3HZdtxYqcl8sjh54VSr7ZoD6bDV6nFQcjOaRir xlDP+DN0eGAm7uhEvg82PKN614h1+xUvwf0VY0DW4Q5AL6BXR1/01hev0I6cJJApEtSJ oB4qhSDaSiVrnKU3CZv6l3q9iLkdfGHaoTK74BoOLN9fgsN/izKCO52DKq7ACTxCRt9T G5h5y2zpArSDX0kG9ctHREI/ftiW8xcpafcvk311e3RQEw/2lzp50dK/BZChm2WvMqfj z8kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gRcCwyfb; 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 g6si12944723plq.57.2021.04.12.01.45.09; Mon, 12 Apr 2021 01:45:21 -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=gRcCwyfb; 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 S237594AbhDLIo1 (ORCPT + 99 others); Mon, 12 Apr 2021 04:44:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:35872 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237103AbhDLIn7 (ORCPT ); Mon, 12 Apr 2021 04:43:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E363961220; Mon, 12 Apr 2021 08:43:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618217021; bh=gBK3iylDQrckbLEAA2FRdPbgaHvMrUPheHbwqgJW+bY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gRcCwyfb49FN9esW7XMjD795dBpjd3pUt2aUZhrBA75EHIpEeyExtuvaZTWWAElJo 2V1PGre8Wzpl1xSjPeF8zwL6J29Ipt5zwht0C/v6s6pL4dNbgNKOp2tfYmsZZfIPpm 6qChQp7ZaEXQF3lEbHKP3cKSw75Ce39WP3AkyuvI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Milton Miller , Eddie James , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 41/66] net/ncsi: Avoid channel_monitor hrtimer deadlock Date: Mon, 12 Apr 2021 10:40:47 +0200 Message-Id: <20210412083959.452160115@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210412083958.129944265@linuxfoundation.org> References: <20210412083958.129944265@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: Milton Miller [ Upstream commit 03cb4d05b4ea9a3491674ca40952adb708d549fa ] Calling ncsi_stop_channel_monitor from channel_monitor is a guaranteed deadlock on SMP because stop calls del_timer_sync on the timer that invoked channel_monitor as its timer function. Recognise the inherent race of marking the monitor disabled before deleting the timer by just returning if enable was cleared. After a timeout (the default case -- reset to START when response received) just mark the monitor.enabled false. If the channel has an entry on the channel_queue list, or if the state is not ACTIVE or INACTIVE, then warn and mark the timer stopped and don't restart, as the locking is broken somehow. Fixes: 0795fb2021f0 ("net/ncsi: Stop monitor if channel times out or is inactive") Signed-off-by: Milton Miller Signed-off-by: Eddie James Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ncsi/ncsi-manage.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c index f65afa7e7d28..9fd20fa90000 100644 --- a/net/ncsi/ncsi-manage.c +++ b/net/ncsi/ncsi-manage.c @@ -84,13 +84,20 @@ static void ncsi_channel_monitor(struct timer_list *t) monitor_state = nc->monitor.state; spin_unlock_irqrestore(&nc->lock, flags); - if (!enabled || chained) { - ncsi_stop_channel_monitor(nc); - return; - } + if (!enabled) + return; /* expected race disabling timer */ + if (WARN_ON_ONCE(chained)) + goto bad_state; + if (state != NCSI_CHANNEL_INACTIVE && state != NCSI_CHANNEL_ACTIVE) { - ncsi_stop_channel_monitor(nc); +bad_state: + netdev_warn(ndp->ndev.dev, + "Bad NCSI monitor state channel %d 0x%x %s queue\n", + nc->id, state, chained ? "on" : "off"); + spin_lock_irqsave(&nc->lock, flags); + nc->monitor.enabled = false; + spin_unlock_irqrestore(&nc->lock, flags); return; } @@ -117,10 +124,9 @@ static void ncsi_channel_monitor(struct timer_list *t) ndp->flags |= NCSI_DEV_RESHUFFLE; } - ncsi_stop_channel_monitor(nc); - ncm = &nc->modes[NCSI_MODE_LINK]; spin_lock_irqsave(&nc->lock, flags); + nc->monitor.enabled = false; nc->state = NCSI_CHANNEL_INVISIBLE; ncm->data[2] &= ~0x1; spin_unlock_irqrestore(&nc->lock, flags); -- 2.30.2