Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2982779imu; Mon, 19 Nov 2018 08:58:28 -0800 (PST) X-Google-Smtp-Source: AJdET5ckbpoV2H8DZuh0S/BJ3w8sYKjc36s1hoQebmiVnFmkQ7MjLIBAJnjBKgV8SdlkrnvymtPT X-Received: by 2002:a62:c302:: with SMTP id v2mr7916444pfg.155.1542646708600; Mon, 19 Nov 2018 08:58:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542646708; cv=none; d=google.com; s=arc-20160816; b=zskTEwQmnrHaNBhGO1mQnrlAoR3HV5q8BNVFE/dCM9ayeJUUdAaHp0w0jjdc5ZSBxk OuFoyQqXqo5371Gdx9ZZMYL5JNRofRGTYmZYtGAvVYxMdzt3YKKuj8sAAlOWa+2pogwT F5xETGhnqSGt847sZt5YnjTw5LIp5LIp/I9sR452tFGwhNbjw48ajZtXH6PwBMhIJc3o B3sO9Qn0GAiM4SkQWj+1oAyUUAr7WNJVb7HwzXS3VDxFT1ffAh/TZpWiSIjbcLSDW0fU NXx2H08Qfu55o5vmu2T8H8DGclwNBKt9qK8sdbkqV6Dd/Pb5eoDeTU5eLxi228o1k3Mp Z1Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=e5/VYKkrJV0A6LZuFNd+aqYohRiFB3ZSONUMum5IRiI=; b=zTCaX+4I/67MJ3LKeqmuixRRg+2Et0/idX2b+Q2FlmjjDlPB88OKeGLaNwPfAZgaKE +g0qheUwdxz0GvPpi4CDI4p9sZqEQ+UXSKccUiXMsbefbBb+DnqRB2jBdavxQ0zJy/hy J327VfmEoH10e+HzUpDGEj2vuKq62m/ZTcQp7oaq1kTOrBO5ft5Q6I5STRaoTyubvEhT HdtKqlhvp9g4v8Z7WYbgc8czc49z2L7agS8CRePiEgLRXislLnsCryov+lKu5MsimYtH 60Lx3SIfJO/jF/NzA9qs/ByCcjCgRrgfoH9h4fHfQqc5OkljCDayQrJiye6yfdqVLKya SdLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tFt7EYNK; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k19-v6si40495331pls.211.2018.11.19.08.58.13; Mon, 19 Nov 2018 08:58:28 -0800 (PST) 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=tFt7EYNK; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404548AbeKTDVp (ORCPT + 99 others); Mon, 19 Nov 2018 22:21:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:33214 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403956AbeKTDVo (ORCPT ); Mon, 19 Nov 2018 22:21:44 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C74092147A; Mon, 19 Nov 2018 16:57:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542646649; bh=PZYaL5uC/JYy4Btj3aF8xwNn3T/ifkrrd5JF4K9kMVc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tFt7EYNKK0hf3RWBXgQQQ+1HXFJMvKP/5o7S/Da3x4xEYOx+VV7Co4rNEOSUxl5aV XfVRT9VuTrUv7q2cL02BnHxaNpzuU8uAZewsPO+i/bQWcReHbEcqq4qG77c/WyVNE7 DcjbgFd56IzYFG/GMgpqGYHdwJPXpGFVxqtvGll8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Waiman Long , Dave Jiang , Vinod Koul , Sasha Levin Subject: [PATCH 4.4 038/160] driver/dma/ioat: Call del_timer_sync() without holding prep_lock Date: Mon, 19 Nov 2018 17:27:57 +0100 Message-Id: <20181119162634.800470942@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162630.031306128@linuxfoundation.org> References: <20181119162630.031306128@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- drivers/dma/ioat/init.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/drivers/dma/ioat/init.c +++ b/drivers/dma/ioat/init.c @@ -1210,8 +1210,15 @@ static void ioat_shutdown(struct pci_dev 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); }