From patchwork Wed Aug 29 07:47:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Larry Chen X-Patchwork-Id: 10579623 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 41D6E175A for ; Wed, 29 Aug 2018 07:48:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3433C2A9A3 for ; Wed, 29 Aug 2018 07:48:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2874F2A9A8; Wed, 29 Aug 2018 07:48:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AB1A02A9A3 for ; Wed, 29 Aug 2018 07:48:52 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w7T7hoc4068705; Wed, 29 Aug 2018 07:48:38 GMT Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2m2y2pg5rk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Aug 2018 07:48:37 +0000 Received: from oss.oracle.com (oss-old-reserved.oracle.com [137.254.22.2]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w7T7mUTL006593 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 29 Aug 2018 07:48:30 GMT Received: from localhost ([127.0.0.1] helo=lb-oss.oracle.com) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1fuvDK-0001QB-CL; Wed, 29 Aug 2018 00:48:30 -0700 Received: from userv0021.oracle.com ([156.151.31.71]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1fuvD0-0001PS-1F for ocfs2-devel@oss.oracle.com; Wed, 29 Aug 2018 00:48:10 -0700 Received: from userp2030.oracle.com (userp2030.oracle.com [156.151.31.89]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w7T7m9dJ032456 (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 29 Aug 2018 07:48:09 GMT Received: from pps.filterd (userp2030.oracle.com [127.0.0.1]) by userp2030.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w7T7htlO034287 for ; Wed, 29 Aug 2018 07:48:09 GMT Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) by userp2030.oracle.com with ESMTP id 2m5m6ujrv2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 29 Aug 2018 07:48:03 +0000 Received: from Beta.suse.asia (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Wed, 29 Aug 2018 01:47:52 -0600 From: Larry Chen To: mfasheh@suse.com, jlbec@evilplan.org Date: Wed, 29 Aug 2018 15:47:40 +0800 Message-Id: <20180829074740.9438-1-lchen@suse.com> X-Mailer: git-send-email 2.13.7 X-CLX-Shades: MLX X-CLX-Response: 1TFkXGBwfEQpMehcaEQpZTRdnZnIRCllJFxpxGhAadwYYHh9xGB0SEBp3Bhg aBhoRClleF2hjeREKSUYXRVhLSUZPdVpYRU5fSV5DRUQZdU9LEQpDThdnUBpJSEl5UnxOHx5+U3 1PZ0F/G1J5XEJ7Gk9SbUBvexEKWFwXHwQaBBseHwcfGklMSU4SGgUbGgQbGhoEHhIEHxAbHhofG hEKXlkXeV8FeH8RCk1cFx8THBEKTFoXaUJNXREKRVkXaGsRCk1OF2gRCkNaFxsZHQQcHwQYHxoE EhsRCkJeFxsRCkReFxgRCkRJFxkRCkJGF2cTbWAbW2VCH359EQpCXBcaEQpCRRd6ZntYEltTem4 dHhEKQk4XZx5gGnNFTGFHAUQRCkJMF2tbXm1ERR9CfERFEQpCbBdkXWh4WmhTfWdGYREKQkAXZA FpHxxGW3wYexsRCkJYF2J9b3kBTxgZcHB7EQpaWBcbEQpwaBdjb1tbY2lTXxsYEhAZGhEKcGgXa BISQmRPT1IeX10QGRoRCnBoF21CTV1+WWtDHl5EEBkaEQpwaBdkZxpfBXlren5IWRAZGhEKcGgX aEgdGUZAenpieF0QGRoRCnBsF2wYR0FrY1NsRlBZEB0SEQptfhcaEQpYTRdLESA= X-PDR: PASS X-Source-IP: 137.65.250.81 X-ServerName: smtp2.provo.novell.com X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 include:novell.com ~all X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8999 signatures=668708 X-Proofpoint-DMARC-Record: none X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=0 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=265 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808290085 X-Spam: Clean Cc: linux-kernel@vger.kernel.org, ocfs2-devel@oss.oracle.com Subject: [Ocfs2-devel] [PATCH] fix crash on ocfs2_duplicate_clusters_by_page X-BeenThere: ocfs2-devel@oss.oracle.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ocfs2-devel-bounces@oss.oracle.com Errors-To: ocfs2-devel-bounces@oss.oracle.com X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8999 signatures=668708 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808290085 X-Virus-Scanned: ClamAV using ClamSMTP ocfs2_duplicate_clusters_by_page may crash if one of extent's pages is dirty. When a page has not been written back, it is still in dirty state. If ocfs2_duplicate_clusters_by_page is called against the dirty page, the crash happens. To fix this bug, we can just unlock the page and wait the page until it's not dirty. The following is the buck trace dump: kernel BUG at /root/code/ocfs2/refcounttree.c:2961! [exception RIP: ocfs2_duplicate_clusters_by_page+822] __ocfs2_move_extent+0x80/0x450 [ocfs2] ? __ocfs2_claim_clusters+0x130/0x250 [ocfs2] ocfs2_defrag_extent+0x5b8/0x5e0 [ocfs2] __ocfs2_move_extents_range+0x2a4/0x470 [ocfs2] ocfs2_move_extents+0x180/0x3b0 [ocfs2] ? ocfs2_wait_for_recovery+0x13/0x70 [ocfs2] ocfs2_ioctl_move_extents+0x133/0x2d0 [ocfs2] ocfs2_ioctl+0x253/0x640 [ocfs2] do_vfs_ioctl+0x90/0x5f0 SyS_ioctl+0x74/0x80 do_syscall_64+0x74/0x140 entry_SYSCALL_64_after_hwframe+0x3d/0xa2 Change-log: 1. Once we founce the page is dirty, we do not wait until it's clean, but rather we use write_one_page to write it back 2. write_one_page arguments list changed, adjust and retest this patch. Signed-off-by: Larry Chen --- fs/ocfs2/refcounttree.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index 7869622af22a..d6022e04c35a 100644 --- a/fs/ocfs2/refcounttree.c +++ b/fs/ocfs2/refcounttree.c @@ -2946,6 +2946,7 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle, if (map_end & (PAGE_SIZE - 1)) to = map_end & (PAGE_SIZE - 1); +retry: page = find_or_create_page(mapping, page_index, GFP_NOFS); if (!page) { ret = -ENOMEM; @@ -2957,8 +2958,15 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle, * In case PAGE_SIZE <= CLUSTER_SIZE, This page * can't be dirtied before we CoW it out. */ - if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize) - BUG_ON(PageDirty(page)); + if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize) { + if (PageDirty(page)) { + /* + * write_on_page will unlock the page on return + */ + ret = write_one_page(page); + goto retry; + } + } if (!PageUptodate(page)) { ret = block_read_full_page(page, ocfs2_get_block);