Received: by 10.223.185.116 with SMTP id b49csp818875wrg; Sat, 10 Feb 2018 21:06:06 -0800 (PST) X-Google-Smtp-Source: AH8x225YnZIXAjaruD0ppOJp1K+Fd7Fp05Iq1C55lz6vwZof9CAe943DsGG7D7ynxqJc90U9ye6K X-Received: by 2002:a17:902:5269:: with SMTP id z96-v6mr7392134plh.392.1518325566243; Sat, 10 Feb 2018 21:06:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518325566; cv=none; d=google.com; s=arc-20160816; b=blmrS2Tq9L+W2VRCZba2cKF6ZhZ97h+p0RKNOo9LcFNZSk34L7DvYeU/ezXv0Fuo44 7HdxDLYlF5wzTN9m31bsbHHvuC1YBzcgbuJ4VqPnXsBrc4EMKXnnEd/toTQxGGq5qm7A m5B4ch/oxxWfO5qAd6m/uOGyCVBNsanT4EFgF5ALak7YrfyLhppKqFoOKJpcsn1CaP0F Vx+laQ8/eQOMUSvSUaLMCmpn/d+dpWe2yqylzDq9LtfVOhhaatfW3tnBn6VBqoErwz13 NaKTt8ATG7wFjoc8vRm0qS8t8MVfg2gRp5gUfI/LJ0WA4w6XboY33bO7iCOVBLhj21hE 8ZoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=NRbyjy8xNAL9LkSsGP1pwwqjk/HGbTRgLXi402IDA4U=; b=fSQ/KF/2Xilvc3aKz2cVrZN3BzY5POdyfzYcdeXs/fszxZS3MfnDZRjG+2VPETyYa1 4Ybs8/uIipy9kNA3SRyjPUl/J5i8GvJ5neKv9uLrXAgy7rf2CRBkp6ZjwibzP3kKi6c6 FpPFtCGpxxbz5GSM4CrXNhYepYIUpieNafFoj/y6V0O6WuBGq7mi5MzK/Ww8w99h0wnG 4NEjGPjZHWlsbgM48OjwlEUcruzzpUiLFEAUi9lMV7JGrrqPozWmK8ecxSBsjYcrx0BC fn/UKY0tDIZ1hdLkKFUJkJto2w+r84oMAbk+n0OsHH4WTDd4fM4KOvT7HY1TPd3Sqqrr O4HQ== ARC-Authentication-Results: i=1; mx.google.com; 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 w10-v6si375851plz.107.2018.02.10.21.05.52; Sat, 10 Feb 2018 21:06:06 -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; 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 S1753714AbeBKFD7 (ORCPT + 99 others); Sun, 11 Feb 2018 00:03:59 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41556 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752709AbeBKEdn (ORCPT ); Sat, 10 Feb 2018 23:33:43 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ekjKe-0002hR-Ap; Sun, 11 Feb 2018 04:33:40 +0000 Received: from ben by deadeye with local (Exim 4.90) (envelope-from ) id 1ekjKY-0004UZ-1X; Sun, 11 Feb 2018 04:33:34 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "alex chen" , "Joel Becker" , "Joseph Qi" , "Jun Piao" , "Mark Fasheh" , "Changwei Ge" , "Junxiao Bi" , "Linus Torvalds" Date: Sun, 11 Feb 2018 04:20:06 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.2 39/79] ocfs2: should wait dio before inode lock in ocfs2_setattr() In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.2.99-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: alex chen commit 28f5a8a7c033cbf3e32277f4cc9c6afd74f05300 upstream. we should wait dio requests to finish before inode lock in ocfs2_setattr(), otherwise the following deadlock will happen: process 1 process 2 process 3 truncate file 'A' end_io of writing file 'A' receiving the bast messages ocfs2_setattr ocfs2_inode_lock_tracker ocfs2_inode_lock_full inode_dio_wait __inode_dio_wait -->waiting for all dio requests finish dlm_proxy_ast_handler dlm_do_local_bast ocfs2_blocking_ast ocfs2_generic_handle_bast set OCFS2_LOCK_BLOCKED flag dio_end_io dio_bio_end_aio dio_complete ocfs2_dio_end_io ocfs2_dio_end_io_write ocfs2_inode_lock __ocfs2_cluster_lock ocfs2_wait_for_mask -->waiting for OCFS2_LOCK_BLOCKED flag to be cleared, that is waiting for 'process 1' unlocking the inode lock inode_dio_end -->here dec the i_dio_count, but will never be called, so a deadlock happened. Link: http://lkml.kernel.org/r/59F81636.70508@huawei.com Signed-off-by: Alex Chen Reviewed-by: Jun Piao Reviewed-by: Joseph Qi Acked-by: Changwei Ge Cc: Mark Fasheh Cc: Joel Becker Cc: Junxiao Bi Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Ben Hutchings --- fs/ocfs2/file.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c @@ -1130,6 +1130,13 @@ int ocfs2_setattr(struct dentry *dentry, dquot_initialize(inode); size_change = S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_SIZE; if (size_change) { + /* + * Here we should wait dio to finish before inode lock + * to avoid a deadlock between ocfs2_setattr() and + * ocfs2_dio_end_io_write() + */ + inode_dio_wait(inode); + status = ocfs2_rw_lock(inode, 1); if (status < 0) { mlog_errno(status); @@ -1149,8 +1156,6 @@ int ocfs2_setattr(struct dentry *dentry, if (status) goto bail_unlock; - inode_dio_wait(inode); - if (i_size_read(inode) >= attr->ia_size) { if (ocfs2_should_order_data(inode)) { status = ocfs2_begin_ordered_truncate(inode,