Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2138365pxb; Mon, 12 Apr 2021 15:44:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwwwr9PuB7KAvgzat1MzrSMykS+5d5DUCU9sfsqgAgKakL7D+ZDz4SOCfbou1QW/dmS1c1 X-Received: by 2002:a63:5322:: with SMTP id h34mr29773486pgb.182.1618267478816; Mon, 12 Apr 2021 15:44:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618267478; cv=none; d=google.com; s=arc-20160816; b=i1ukcSQBbuRBVsnZC8YCHNsKHD095ksu8IzArz1sITuMwTe2SP0ZAz36NRYSmcXsHF Z4jHYSu/cAXB34LRz+7JkrhA/NVs/H6TdT4u5NErd5KqkACygb9dy97qYaJxrjdXwkZY YdilAxgawZK0y1Zbmsm+8BNmgs+ouwtHHnMJdpPA0nEJTZGp09YtEyYaDEFUfozMnvaR JnF1pwXHug2buQlLFvDA3FozjWQSWv9Mvfk8ra8achtVknsJmqXE+dKWllvtz+IIlGP2 5OQfV0NekwO8y/V7UJxTK1dx7ZVRYkSnYX+bt+knxhA3Ac6dsXkWdI7+4IombMVB4ccl WT1g== 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=BDrhM0M+VLkPqw/GOzdkFxLADEr2j1zXT4jNUaxflYw=; b=U8bXLkpks/cFwDf9ooT47HCnoi1PwTXhmX5ID8OW5vF4vvSkagEXspIV14PR3enIcc xeRJwBcInd2nLq3ETMnUby+oaGCvkg+AdDUVCAUtZdLEW039RlwHcpAu8vPsDGxXqlDI S78XXaTaAGTP8y5TTVC0x+CI3A7X8DRG3FyZk3E02Tt0Cd8piExzaafzcyxh+UZPLhoC pf9tb/FGVT3TamZkDDb4g8ZLAwObNWOL4ze7MqhB0/K7P+3DEX9Q8FWxQTz6Ktq0+31z XIyLFLTdQdyNwQG/RDiQpbtfjB8QO8WLctkTeMZl+Xc3f03hW2AMF0l34419hn1SvqJN dQGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wx4pBhQu; 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 34si15104160plf.51.2021.04.12.15.44.25; Mon, 12 Apr 2021 15:44:38 -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=wx4pBhQu; 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 S238573AbhDLJeh (ORCPT + 99 others); Mon, 12 Apr 2021 05:34:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:34436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239376AbhDLJJL (ORCPT ); Mon, 12 Apr 2021 05:09:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 368FD61283; Mon, 12 Apr 2021 09:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618218274; bh=JrfsyBDZZnDZ7gqBeGjqgGHNYnLUNS8dYhXSv4eAzqc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wx4pBhQuQa4blm5SexpIb9GFsjr7YRlZzkOFHuOwIVtU5gYu33keRPzSDNnH1qbLC 4YQenbmant94P3viB4iFmmFyMDTZzIcrMTjxA/gNV6XeTmCJTR9xYBnWSLWhXQT2QT AWTQPe9t7yTj/RioGib/1IOaf8x/dZgUteuJlQLs= 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 5.11 137/210] net/ncsi: Avoid channel_monitor hrtimer deadlock Date: Mon, 12 Apr 2021 10:40:42 +0200 Message-Id: <20210412084020.563808473@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210412084016.009884719@linuxfoundation.org> References: <20210412084016.009884719@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 a9cb355324d1..ffff8da707b8 100644 --- a/net/ncsi/ncsi-manage.c +++ b/net/ncsi/ncsi-manage.c @@ -105,13 +105,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; } @@ -136,10 +143,9 @@ static void ncsi_channel_monitor(struct timer_list *t) ncsi_report_link(ndp, true); 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