Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp110101imm; Wed, 29 Aug 2018 15:27:23 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaFqnXGdkJvckcLi4XalAxQcjVv/qczugnL9hh9+7usDO/TqyqBYJfv5YwbyVUS5LWQJKBr X-Received: by 2002:a17:902:42e2:: with SMTP id h89-v6mr7434481pld.69.1535581643719; Wed, 29 Aug 2018 15:27:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535581643; cv=none; d=google.com; s=arc-20160816; b=N5ZUA7WRQauyVg4cYe8u7nKRopBIG4lizOrZq/QE+WUP2T7ZgkjP8LbKKma/VmWSav FJQHqtI8iIYMFwFtZqs9LblTzDNDHe0zsmqMjiwypayrTyaN+bbDlcylxOUJ1XyBu2+J zEBsZQQjZUcqssDqw+WDOoUYLf4eNAyDK7695mE6MXXggK0j6R/o/8bd7bh+cqqEtaVz 2NuK3TYpe46Qm3NUopLiEZBoomkrMeGSLVxG5z3ocNnIQGPSeWkRbbRASwQVLGUMRsxx UH3fW+hdgqEFYVlCM+9mzzJh1CKDUXgYtF8sqoxtat9ZVsmx3bfis9Ww719x58OAWwTU Kumw== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=nAapMAIoT+Ljp/8iiAGN+2xx/WDrW7BV+nLQEmXxQyY=; b=VHWyyde0Z5nr+mEwQfXuaauxysDOhemiQtZpB9fVYdwmtuE+dHnMT9CB7wQDveOf1l cluQc7JnOTAcQ+bLj7cKr0mXLKrh5R7FWUTeG7TM4iP1B7Oa5rdJjaiRB2r0/H4A25fk hwwEd0GAF5RG3EveaNM4RvoXFPGCBxXWH+mi1KoOuAs2zNgn0U0E6+KcX0UaHYMIV1q4 wfs5lGrDzj7xMb2i2u6KL1uQsd30ybLGHR5YR1NjwUboNfhBLD0ytNz7H5Lt1BlSlmH9 JuiYIl5AgTAzsTrEjo41JcaVORf+mBX2J4HkRy//Ssumh9OXNV/+YSob0tSk0yg/bE+U HZhg== 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 q8-v6si4781343pgk.600.2018.08.29.15.27.08; Wed, 29 Aug 2018 15:27:23 -0700 (PDT) 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 S1727237AbeH3CYe (ORCPT + 99 others); Wed, 29 Aug 2018 22:24:34 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:39814 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727187AbeH3CYe (ORCPT ); Wed, 29 Aug 2018 22:24:34 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.8.65]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 9EB18BB6; Wed, 29 Aug 2018 22:25:34 +0000 (UTC) Date: Wed, 29 Aug 2018 15:25:33 -0700 From: Andrew Morton To: Larry Chen Cc: mfasheh@suse.com, jlbec@evilplan.org, linux-kernel@vger.kernel.org, ocfs2-devel@oss.oracle.com Subject: Re: [PATCH] fix crash on ocfs2_duplicate_clusters_by_page Message-Id: <20180829152533.431fd4972ae046943cabc2e3@linux-foundation.org> In-Reply-To: <20180829074740.9438-1-lchen@suse.com> References: <20180829074740.9438-1-lchen@suse.com> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 29 Aug 2018 15:47:40 +0800 Larry Chen wrote: > 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 > > --- 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. > */ Looks sane, but the below change shows that the above comment is untrue. Can we please update the comment as well? > - 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);