linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Waiman Long <longman@redhat.com>, Vinod Koul <vkoul@kernel.org>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 4.4 27/32] driver/dma/ioat: Call del_timer_sync() without holding prep_lock
Date: Wed, 31 Oct 2018 19:11:32 -0400	[thread overview]
Message-ID: <20181031231137.29429-27-sashal@kernel.org> (raw)
In-Reply-To: <20181031231137.29429-1-sashal@kernel.org>

From: Waiman Long <longman@redhat.com>

[ 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 <longman@redhat.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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 ac8c28968422..106fa9b327d9 100644
--- a/drivers/dma/ioat/init.c
+++ b/drivers/dma/ioat/init.c
@@ -1210,8 +1210,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


  parent reply	other threads:[~2018-10-31 23:12 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-31 23:11 [PATCH AUTOSEL 4.4 01/32] locking/lockdep: Fix debug_locks off performance problem Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 02/32] ataflop: fix error handling during setup Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 03/32] swim: fix cleanup on setup error Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 04/32] tun: Consistently configure generic netdev params via rtnetlink Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 05/32] perf tools: Free temporary 'sys' string in read_event_files() Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 06/32] perf tools: Cleanup trace-event-info 'tdata' leak Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 07/32] cpupower: Fix coredump on VMWare Sasha Levin
2018-11-12 10:29   ` Rafael David Tinoco
2018-11-12 13:32     ` Greg KH
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 08/32] mmc: sdhci-pci-o2micro: Add quirk for O2 Micro dev 0x8620 rev 0x01 Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 09/32] x86/olpc: Indicate that legacy PC XO-1 platform should not register RTC Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 10/32] regulator: fixed: Default enable high on DT regulators Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 11/32] Bluetooth: btbcm: Add entry for BCM4335C0 UART bluetooth Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 12/32] x86: boot: Fix EFI stub alignment Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 13/32] pinctrl: qcom: spmi-mpp: Fix err handling of pmic_mpp_set_mux Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 14/32] kprobes: Return error if we fail to reuse kprobe instead of BUG_ON() Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 15/32] ACPI / LPSS: Add alternative ACPI HIDs for Cherry Trail DMA controllers Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 16/32] pinctrl: qcom: spmi-mpp: Fix drive strength setting Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 17/32] pinctrl: spmi-mpp: Fix pmic_mpp_config_get() to be compliant Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 18/32] pinctrl: ssbi-gpio: Fix pm8xxx_pin_config_get() " Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 19/32] ath10k: schedule hardware restart if WMI command times out Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 20/32] scsi: esp_scsi: Track residual for PIO transfers Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 21/32] scsi: megaraid_sas: fix a missing-check bug Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 22/32] tpm: suppress transmit cmd error logs when TPM 1.2 is disabled/deactivated Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 23/32] Drivers: hv: kvp: Fix two "this statement may fall through" warnings Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 24/32] ext4: fix argument checking in EXT4_IOC_MOVE_EXT Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 25/32] MD: fix invalid stored role for a disk Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 26/32] usb: chipidea: Prevent unbalanced IRQ disable Sasha Levin
2018-10-31 23:11 ` Sasha Levin [this message]
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 28/32] uio: ensure class is registered before devices Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 29/32] scsi: lpfc: Correct soft lockup when running mds diagnostics Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 30/32] signal: Always deliver the kernel's SIGKILL and SIGSTOP to a pid namespace init Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 31/32] dmaengine: dma-jz4780: Return error if not probed from DT Sasha Levin
2018-10-31 23:11 ` [PATCH AUTOSEL 4.4 32/32] ALSA: hda: Check the non-cached stream buffers more explicitly Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181031231137.29429-27-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).