Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1735790ybl; Sat, 11 Jan 2020 01:44:41 -0800 (PST) X-Google-Smtp-Source: APXvYqwKTaO9NVlrb364Xpr9NSQoTmYF2lJhVry8A9QWhrbxJef4tyOn7bneFOozEJtsofDC61uz X-Received: by 2002:a9d:4706:: with SMTP id a6mr5718336otf.331.1578735881598; Sat, 11 Jan 2020 01:44:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578735881; cv=none; d=google.com; s=arc-20160816; b=k9HzDa3CkkeKRuilr+O+KuNjN+7G0kCf09NgpEpHTxc5SfrYIsB128TVPMHs6b02Zo mzivocJg9pbrG68/KBmZcrdpy9kkiEvd52FsYIIDSHG9+1uj7k0sdmUAy3dwVKKRO+6V P+BvU0sZxlpU/YPXuiKMgxWgJAHMU37y1QtfDmFC3RoLdQoScUhT0wXVKX99khQS8dwn nqaDYz2JItxK8OtgwUvgAlBE6m7I0NIXpXqCZLvKBUoVw8jF5Nk38oLwbLsDnrVz7xCD 7YmTBE01i25R3GPT0eioHKbnK7uc3MKsnII/q5QXtBiKolmcQCohr2t2WNkqUm1xrjX+ m3ZQ== 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 :message-id:date:subject:cc:to:from; bh=ktw6xcUN30GkeSkd/vZNl96Nx6gtVCW/TGu0JAqcb2I=; b=xwzA8rJC+B43IHBpxI68uYfyu3+jxnJmQQWEw49tCQk1vKRZdJproeaHHXL5e4HvWE B4VEjTC6lSrFVF5YOymPlgVN8r4Y+kt5fozqe+IMSxfTVyIBcDybXEBs9lgdDggsV9y5 KCQ8cKsufU2yU11exUrjLJ+Nnk0Zew6nzxLCHmv4jijbicVhU2xjxbLt+FqjW/cLo+HV n8kung2DiqYZO87FMZh2AT87fcL40FTv6HEBbc4gS+K9j7pQQZ2kchhsJEsPyywDnbf/ hMk/9kTUn3b03IGYFzSA8PIPB/eHnIcwtl3O2i3Os/Y+1O/BE7T5NGw2nr1Qcf/67mas nrrA== 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 r202si2912427oie.247.2020.01.11.01.44.29; Sat, 11 Jan 2020 01:44:41 -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 S1728747AbgAKJnd (ORCPT + 99 others); Sat, 11 Jan 2020 04:43:33 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8699 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728737AbgAKJnd (ORCPT ); Sat, 11 Jan 2020 04:43:33 -0500 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id E12A9E2B3071DDC9B529; Sat, 11 Jan 2020 17:43:30 +0800 (CST) Received: from huawei.com (10.90.53.225) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.439.0; Sat, 11 Jan 2020 17:43:20 +0800 From: Zhihao Cheng To: , , CC: , Subject: [PATCH v2] ubifs: Fix deadlock in concurrent bulk-read and writepage Date: Sat, 11 Jan 2020 17:50:36 +0800 Message-ID: <1578736236-141308-1-git-send-email-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.90.53.225] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In ubifs, concurrent execution of writepage and bulk read on the same file may cause ABBA deadlock, for example (Reproduce method see Link): Process A(Bulk-read starts from page4) Process B(write page4 back) vfs_read wb_workfn or fsync ... ... generic_file_buffered_read write_cache_pages ubifs_readpage LOCK(page4) ubifs_bulk_read ubifs_writepage LOCK(ui->ui_mutex) ubifs_write_inode ubifs_do_bulk_read LOCK(ui->ui_mutex) find_or_create_page(alloc page4) ↑ LOCK(page4) <-- ABBA deadlock occurs! In order to ensure the serialization execution of bulk read, we can't remove the big lock 'ui->ui_mutex' in ubifs_bulk_read(). Instead, we allow ubifs_do_bulk_read() to lock page failed by replacing find_or_create_page(FGP_LOCK) with pagecache_get_page(FGP_LOCK | FGP_NOWAIT). Signed-off-by: Zhihao Cheng Suggested-by: zhangyi (F) Cc: Fixes: 4793e7c5e1c ("UBIFS: add bulk-read facility") Link: https://bugzilla.kernel.org/show_bug.cgi?id=206153 --- fs/ubifs/file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index cd52585..c649048 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c @@ -786,7 +786,9 @@ static int ubifs_do_bulk_read(struct ubifs_info *c, struct bu_info *bu, if (page_offset > end_index) break; - page = find_or_create_page(mapping, page_offset, ra_gfp_mask); + page = pagecache_get_page(mapping, page_offset, + FGP_LOCK|FGP_ACCESSED|FGP_CREAT|FGP_NOWAIT, + ra_gfp_mask); if (!page) break; if (!PageUptodate(page)) -- 2.7.4