From patchwork Thu Aug 30 03:06:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Larry Chen X-Patchwork-Id: 10581169 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 780A0175A for ; Thu, 30 Aug 2018 03:08:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8F9D2B33D for ; Thu, 30 Aug 2018 03:08:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DBE372B34A; Thu, 30 Aug 2018 03:08:02 +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 userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 640432B33D for ; Thu, 30 Aug 2018 03:08:02 +0000 (UTC) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w7U33aaX189966; Thu, 30 Aug 2018 03:07:50 GMT Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2m2yrqdh0s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Aug 2018 03:07:50 +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 w7U37lj2008915 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 30 Aug 2018 03:07:47 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 1fvDJD-00018I-Az; Wed, 29 Aug 2018 20:07:47 -0700 Received: from userv0021.oracle.com ([156.151.31.71]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1fvDIq-00017X-4N for ocfs2-devel@oss.oracle.com; Wed, 29 Aug 2018 20:07:24 -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 w7U37NYc028879 (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 03:07:23 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 w7U341h9007205 for ; Thu, 30 Aug 2018 03:07:23 GMT Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) by userp2030.oracle.com with ESMTP id 2m615vf78m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 30 Aug 2018 03:07:17 +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 21:07:08 -0600 From: Larry Chen To: mark@fasheh.com, jlbec@evilplan.org Date: Thu, 30 Aug 2018 11:06:54 +0800 Message-Id: <20180830030654.20872-1-lchen@suse.com> X-Mailer: git-send-email 2.13.7 X-CLX-Shades: MLX X-CLX-Response: 1TFkXGB8cEQpMehcbHhkRCllNF2dmchEKWUkXGnEaEBp3BhgZHHEYGBIQGnc GGBoGGhEKWV4XaGN5EQpJRhdFWEtJRk91WlhFTl9JXkNFRBl1T0sRCkNOF1hSXF5JdXhAelBtTU QSUGFCHFJzZWt4W2x7dUFkEx1aEQpYXBcfBBoEGx4fBx8aSUxJThIaBRsaBBsaGgQeEgQbEBseG h8aEQpeWRd5XHt7bREKTVwXHxMZEQpMWhdpTU1dEQpFWRdoaxEKQ1oXGxkdBBwfBBgfGgQSGxEK Ql4XGxEKRF4XGBEKREkXGREKQkYXaVJeRWIBY3lBSRkRCkJcFxoRCkJFF3pme1gSW1N6bh0eEQp CThdnHmAac0VMYUcBRBEKQkwXa1tebURFH0J8REURCkJsF2RdaHhaaFN9Z0ZhEQpCQBdrWVl8XQ VtGmxsexEKQlgXYn1veQFPGBlwcHsRClpYFxsRCnBoF2NvW1tjaVNfGxgSEBoRCnBoF2xsH1NdH Ux6AVJ4EBoRCnBoF2VhSx0TXXgcbRhLEBoRCnBoF2RnGl8FeWt6fkhZEBkaEQpwaBdmARNNSV4a YV0fZRAaEQpwbBdsGEdBa2NTbEZQWRAdGhEKbX4XGhEKWE0XSxEg 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=9000 signatures=668708 X-Proofpoint-DMARC-Record: none X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=143 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=256 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-1808300029 X-Spam: Clean Cc: linux-kernel@vger.kernel.org, ocfs2-devel@oss.oracle.com Subject: [Ocfs2-devel] [PATCH v4] 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=9000 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-1808300029 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 write back the page rather than just wait. The following is the back trace dump: kernel BUG at /root/code/ocfs2/refcounttree.c:2961! BUG_ON(PageDirty(page)); [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 find 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. 3. Comments has been changed Signed-off-by: Larry Chen --- fs/ocfs2/refcounttree.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index 7869622af22a..ed84d05c7d00 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; @@ -2954,11 +2955,18 @@ 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. + * In case PAGE_SIZE <= CLUSTER_SIZE, we do not expect a dirty page, + * so write it back. */ - 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);