Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2089845pxb; Mon, 12 Apr 2021 14:10:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3v4EQnjF+F6B3KmWlD62xxpR/ZkTPB5vwBo7AEYk75K2RpWL0uCFo3/hL57CEtH6VsCTt X-Received: by 2002:a17:907:3f08:: with SMTP id hq8mr2576066ejc.90.1618261837754; Mon, 12 Apr 2021 14:10:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618261837; cv=none; d=google.com; s=arc-20160816; b=aFTwI+9jdcZHAbdg99k2euMzGe+fRA8sLVQBC7dOSRshDwp0uRm3mCYiV8aj5ER34D BcHb5fnZXTmZsgnxEr0D+FgJbECgUqLjTXG5n8+qYuP770y9piKXljrRoTRgyykrzW68 7wqJgJRRGaGjliXLOjufCEi2M4fC+65aZyMgsRFNUIsi2E9Wz2U0hyOLuzo8dNvdB19e S/7nLIrVIuIouhWHp2rLl5LuEjfchnVIKDN2M32EuUXJ0r7+mIuNOMfE06W43UIUadAs G4DR+1dpJC+U4K6PZb9Q8Re14uCztTYN3JAVctAb20B5qI4tMYmZhwnp+YtXJYUqAUgX Mngw== 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=U4TsDXYEpIYxzNK7DMD2rA3XnTnuMz0uuwc4XDiRnc++3CIpC7KTwoKLDVP3IOTaMm 1kA9nWOiigf2I3WOhPyzZItwuR+DpvKlkuQR0Xsp6s0mrktHH1y6A1cY+hodbInhkyjk g419cKOmYY9XwDuiXQZzVCnFxw9O42cZ/Euxb0PQ6MDWrsJXY0nxzCmccxOWv4aljp7s 9yr3JyI8IhZowlLew/y67I3bSm1Pob9t7nZUy9Z8K92RSXz4zB1SjciiJao30exA2xFK rwftY9Yl+2/rJ0RQ4qBYX/ZaCcBABLDkeNV1B5TL8cqn0sn023dBSSBPuWPIMIHW1iHt 7n1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=L1xoyeX7; 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 q11si240728ejz.699.2021.04.12.14.10.12; Mon, 12 Apr 2021 14:10:37 -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=L1xoyeX7; 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 S240787AbhDLJK5 (ORCPT + 99 others); Mon, 12 Apr 2021 05:10:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:48976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238260AbhDLIzv (ORCPT ); Mon, 12 Apr 2021 04:55:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 43E5661019; Mon, 12 Apr 2021 08:55:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618217733; bh=JrfsyBDZZnDZ7gqBeGjqgGHNYnLUNS8dYhXSv4eAzqc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L1xoyeX7ij/CavzxMYZAVBXConblfbvn3qj/CdBQc+TMjjL2X5xkzcLTGPKnv7Qde X6zPqU+1eowlTodDw9hf+qt9HhfIpkM9SHcmqWqEVx/MDSYR8lc126fPpyHSEARI1l O71QVtm59adWKh98eDjw7kGmSK4xBo3J/M5uudzc= 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.10 125/188] net/ncsi: Avoid channel_monitor hrtimer deadlock Date: Mon, 12 Apr 2021 10:40:39 +0200 Message-Id: <20210412084017.804040894@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210412084013.643370347@linuxfoundation.org> References: <20210412084013.643370347@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