Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp169587imd; Wed, 31 Oct 2018 16:43:22 -0700 (PDT) X-Google-Smtp-Source: AJdET5cZJLceVEN49dTV/V5CLbbylp87XupoDE3ydIiNl6ilBdWemGa6H6/6vtCI6LsmeLbaqfap X-Received: by 2002:a62:1745:: with SMTP id 66-v6mr5354377pfx.236.1541029402570; Wed, 31 Oct 2018 16:43:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029402; cv=none; d=google.com; s=arc-20160816; b=OeJoRSq6hwDQLU3T/LysnfwjZVd52Z1ucswA6qb470DSnZEx6nMcHH3fYsN/ACDD2B SVCU8TtAUU5g9QmOekRjgzbP3T15h1SyaBxGss4fCOCuTMuCkvfsCHLKaZSSAuHrpc/I lTxqnnGAxr/Ac/VOqRmJoZz9aBWem5byczrqri+qeXRuOpEAScsUxTu2VWRALemJbo78 yQ3ue27hmV2XH+/GBivXQ2+41UxluY16b71ceh7Tuvd5WrAKfKXZvB/E313smkBobIC6 5eXftdi1FF54DX/ZWURTs/uamWI2oaesitQgTLhuew4ABbMpyQKOCt6KsqY8/L3f23M9 XKHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=1W/8LrBYyNLFYCKnid7xt+4xDCy/4iIQSdYw0jDkY3I=; b=VwVsfP4dWq0SXmk3Fsxa65mL2nLIF2p/CpXkGOptmaW4Q78GdlDOoW3cX+5Hl6bUVY SiZkPHiMnQq5eDDtulLc5acu0YNI4DPS16Mb40ogXJcc7ueGUtEbFHpkTccUVTtH/AUD mn3g/geN88I91xmRUIonf0xr+8ISkhIvOTUlQpIrkgfcsTSBsAaLRzw+Wk6U9HP9V3O2 gUbA5A4XYFhE5cVKCGwgQsR2PnNIl4lWcTBLwmhuPV3hV7DGDNlM5gI38X6jiJiYCTr8 b9pGfL+hUoWp0c+ck6LRI0njdIZYt3gOrb4aYxM22dZBbnG0gqiev0iYmYxEFIrUJagp m04w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0Xzrdbxj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b20-v6si29406594pgk.360.2018.10.31.16.43.07; Wed, 31 Oct 2018 16:43:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0Xzrdbxj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729236AbeKAIHv (ORCPT + 99 others); Thu, 1 Nov 2018 04:07:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:56036 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729216AbeKAIHv (ORCPT ); Thu, 1 Nov 2018 04:07:51 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 69B5520838; Wed, 31 Oct 2018 23:07:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027260; bh=vDFYdcSD+5oXn5B561i6ag9A7XSVDa14OOAjgL7QHA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0Xzrdbxj2ReYvI2EMFTbLGNvHH1yze79EJ0VH3WIc4li8jYpG0h5vCQUw1dSeEU4J 5vibiYGX4XIAzjRbGyjhwzeTSZ+laXrOB+b4haikMiCfbJGW4Lb/v2ELVFTHk4+xvM KFFnd5iIxtkNyPrF9Vuy5xeI5sIo308vwYhyclSs= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Waiman Long , Vinod Koul , Sasha Levin Subject: [PATCH AUTOSEL 4.19 131/146] driver/dma/ioat: Call del_timer_sync() without holding prep_lock Date: Wed, 31 Oct 2018 19:05:26 -0400 Message-Id: <20181031230541.28822-131-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Waiman Long [ Upstream commit cfb03be6c7e8a1591285849c361d67b09f5149f7 ] The following lockdep splat was observed: [ 1222.241750] ====================================================== [ 1222.271301] WARNING: possible circular locking dependency detected [ 1222.301060] 4.16.0-10.el8+5.x86_64+debug #1 Not tainted [ 1222.326659] ------------------------------------------------------ [ 1222.356565] systemd-shutdow/1 is trying to acquire lock: [ 1222.382660] ((&ioat_chan->timer)){+.-.}, at: [<00000000f71e1a28>] del_timer_sync+0x5/0xf0 [ 1222.422928] [ 1222.422928] but task is already holding lock: [ 1222.451743] (&(&ioat_chan->prep_lock)->rlock){+.-.}, at: [<000000008ea98b12>] ioat_shutdown+0x86/0x100 [ioatdma] : [ 1223.524987] Chain exists of: [ 1223.524987] (&ioat_chan->timer) --> &(&ioat_chan->cleanup_lock)->rlock --> &(&ioat_chan->prep_lock)->rlock [ 1223.524987] [ 1223.594082] Possible unsafe locking scenario: [ 1223.594082] [ 1223.622630] CPU0 CPU1 [ 1223.645080] ---- ---- [ 1223.667404] lock(&(&ioat_chan->prep_lock)->rlock); [ 1223.691535] lock(&(&ioat_chan->cleanup_lock)->rlock); [ 1223.728657] lock(&(&ioat_chan->prep_lock)->rlock); [ 1223.765122] lock((&ioat_chan->timer)); [ 1223.784095] [ 1223.784095] *** DEADLOCK *** [ 1223.784095] [ 1223.813492] 4 locks held by systemd-shutdow/1: [ 1223.834677] #0: (reboot_mutex){+.+.}, at: [<0000000056d33456>] SYSC_reboot+0x10f/0x300 [ 1223.873310] #1: (&dev->mutex){....}, at: [<00000000258dfdd7>] device_shutdown+0x1c8/0x660 [ 1223.913604] #2: (&dev->mutex){....}, at: [<0000000068331147>] device_shutdown+0x1d6/0x660 [ 1223.954000] #3: (&(&ioat_chan->prep_lock)->rlock){+.-.}, at: [<000000008ea98b12>] ioat_shutdown+0x86/0x100 [ioatdma] In the ioat_shutdown() function: spin_lock_bh(&ioat_chan->prep_lock); set_bit(IOAT_CHAN_DOWN, &ioat_chan->state); del_timer_sync(&ioat_chan->timer); spin_unlock_bh(&ioat_chan->prep_lock); According to the synchronization rule for the del_timer_sync() function, the caller must not hold locks which would prevent completion of the timer's handler. The timer structure has its own lock that manages its synchronization. Setting the IOAT_CHAN_DOWN bit should prevent other CPUs from trying to use that device anyway, there is probably no need to call del_timer_sync() while holding the prep_lock. So the del_timer_sync() call is now moved outside of the prep_lock critical section to prevent the circular lock dependency. Signed-off-by: Waiman Long Reviewed-by: Dave Jiang Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/ioat/init.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/dma/ioat/init.c b/drivers/dma/ioat/init.c index 4fa4c06c9edb..21a5708985bc 100644 --- a/drivers/dma/ioat/init.c +++ b/drivers/dma/ioat/init.c @@ -1205,8 +1205,15 @@ static void ioat_shutdown(struct pci_dev *pdev) spin_lock_bh(&ioat_chan->prep_lock); set_bit(IOAT_CHAN_DOWN, &ioat_chan->state); - del_timer_sync(&ioat_chan->timer); spin_unlock_bh(&ioat_chan->prep_lock); + /* + * Synchronization rule for del_timer_sync(): + * - The caller must not hold locks which would prevent + * completion of the timer's handler. + * So prep_lock cannot be held before calling it. + */ + del_timer_sync(&ioat_chan->timer); + /* this should quiesce then reset */ ioat_reset_hw(ioat_chan); } -- 2.17.1