Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp825470pxb; Tue, 3 Nov 2020 13:37:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJxLinBRPzhYJniyK5ySKkCNjqklQRXLrfO7LdP01BuJ1LXcp2X1pPl+dibbj0C/mKJLv+nH X-Received: by 2002:a17:906:4351:: with SMTP id z17mr21731288ejm.110.1604439437309; Tue, 03 Nov 2020 13:37:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604439437; cv=none; d=google.com; s=arc-20160816; b=h7g6TNJHvVFCdf7MhZz4u9adYh/+OS8f0zzvAnRvUkPNp7+JWKp2tIvraWL8oMZg5Z 2C6ibqGgUlyNrfFvLbOhTA19PIDxwqzXu+LS4wy9Lq5NkCMVVgwA5M6eYZgT1ZaBG/86 g/zWCiCRSq8ERGyZL7LaNvBu8dPyNjHujj9IFktdwK8TgtRdHSjctJNlBCjJmUFbuxc0 4M7ACabdI4UYHKXbM/anyheaIP6Uj7Zg3HFtUOe160usN2B9n8J8s35smwYloGr31j04 FAzml58AzVZObOzuzjuVOJhGbLqu7YicqHArlsWJjl4zV79+8J6PVQRZNhDqCe18vzkB qF1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FQ+aO4x9oigDCAKPGm+//7fKGCJaBV7DY+iBPeV3IYM=; b=s+mtvc5LlnS7y+OQxoT98rHk5GRyHpkjiLKi7KF3nuWoOJtFdWC9D+MowXgdKYK8Uh HpBDVlnScPyeF8VmIymiWhN3udNjkEtYx6Mjssupnr18QgUUQbLCFQjyoNmFPVxd1giK SOvXvBpxNjV16hsN2znsRHErRtvrpVl2BsYi+XbsEt2M8WKZlvHCbmJPWCN8l5IzyWnQ Twx6VIABoOf5sYTkDrljG9ek/EzFD77MFN5wYlHVvWwBzyGF9dV7M7Rhn6hznsW89IMD cdsdvhV495DFKgzWNX8GzAaiNrkRZ/cXwzt3NWLb+FyklyUmyxXHzMBgDpj/yUA8nkar 3K5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="y/wonh04"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g9si15085120edn.361.2020.11.03.13.36.54; Tue, 03 Nov 2020 13:37:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="y/wonh04"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733169AbgKCVdj (ORCPT + 99 others); Tue, 3 Nov 2020 16:33:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:58972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731056AbgKCU4z (ORCPT ); Tue, 3 Nov 2020 15:56:55 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6B313223AC; Tue, 3 Nov 2020 20:56:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437013; bh=V/h0iU22BbFnuaIA3QjjWMd2xgWKC84o4RQKOWvD6Gc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y/wonh04RijxGBh345d+c6LkMIsOzJgwH6SFpuPCW+3FjSmfpe1fwo2AzI4b/F8Xf cxKMjmbLc1Af39IN4wa+4/aEQyIRuThP2lV0P63nNkWLZvNRvacxS9a5RIhMcR0hQi N8p7bcM0d/SG5TDVmljhoPj/9Zci/62sWYPcDYms= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ye Bin , Jan Kara , Christoph Hellwig , Jens Axboe Subject: [PATCH 5.4 108/214] fs: Dont invalidate page buffers in block_write_full_page() Date: Tue, 3 Nov 2020 21:35:56 +0100 Message-Id: <20201103203301.075990643@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Kara commit 6dbf7bb555981fb5faf7b691e8f6169fc2b2e63b upstream. If block_write_full_page() is called for a page that is beyond current inode size, it will truncate page buffers for the page and return 0. This logic has been added in 2.5.62 in commit 81eb69062588 ("fix ext3 BUG due to race with truncate") in history.git tree to fix a problem with ext3 in data=ordered mode. This particular problem doesn't exist anymore because ext3 is long gone and ext4 handles ordered data differently. Also normally buffers are invalidated by truncate code and there's no need to specially handle this in ->writepage() code. This invalidation of page buffers in block_write_full_page() is causing issues to filesystems (e.g. ext4 or ocfs2) when block device is shrunk under filesystem's hands and metadata buffers get discarded while being tracked by the journalling layer. Although it is obviously "not supported" it can cause kernel crashes like: [ 7986.689400] BUG: unable to handle kernel NULL pointer dereference at +0000000000000008 [ 7986.697197] PGD 0 P4D 0 [ 7986.699724] Oops: 0002 [#1] SMP PTI [ 7986.703200] CPU: 4 PID: 203778 Comm: jbd2/dm-3-8 Kdump: loaded Tainted: G +O --------- - - 4.18.0-147.5.0.5.h126.eulerosv2r9.x86_64 #1 [ 7986.716438] Hardware name: Huawei RH2288H V3/BC11HGSA0, BIOS 1.57 08/11/2015 [ 7986.723462] RIP: 0010:jbd2_journal_grab_journal_head+0x1b/0x40 [jbd2] ... [ 7986.810150] Call Trace: [ 7986.812595] __jbd2_journal_insert_checkpoint+0x23/0x70 [jbd2] [ 7986.818408] jbd2_journal_commit_transaction+0x155f/0x1b60 [jbd2] [ 7986.836467] kjournald2+0xbd/0x270 [jbd2] which is not great. The crash happens because bh->b_private is suddently NULL although BH_JBD flag is still set (this is because block_invalidatepage() cleared BH_Mapped flag and subsequent bh lookup found buffer without BH_Mapped set, called init_page_buffers() which has rewritten bh->b_private). So just remove the invalidation in block_write_full_page(). Note that the buffer cache invalidation when block device changes size is already careful to avoid similar problems by using invalidate_mapping_pages() which skips busy buffers so it was only this odd block_write_full_page() behavior that could tear down bdev buffers under filesystem's hands. Reported-by: Ye Bin Signed-off-by: Jan Kara Reviewed-by: Christoph Hellwig CC: stable@vger.kernel.org Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/buffer.c | 16 ---------------- 1 file changed, 16 deletions(-) --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2739,16 +2739,6 @@ int nobh_writepage(struct page *page, ge /* Is the page fully outside i_size? (truncate in progress) */ offset = i_size & (PAGE_SIZE-1); if (page->index >= end_index+1 || !offset) { - /* - * The page may have dirty, unmapped buffers. For example, - * they may have been added in ext3_writepage(). Make them - * freeable here, so the page does not leak. - */ -#if 0 - /* Not really sure about this - do we need this ? */ - if (page->mapping->a_ops->invalidatepage) - page->mapping->a_ops->invalidatepage(page, offset); -#endif unlock_page(page); return 0; /* don't care */ } @@ -2943,12 +2933,6 @@ int block_write_full_page(struct page *p /* Is the page fully outside i_size? (truncate in progress) */ offset = i_size & (PAGE_SIZE-1); if (page->index >= end_index+1 || !offset) { - /* - * The page may have dirty, unmapped buffers. For example, - * they may have been added in ext3_writepage(). Make them - * freeable here, so the page does not leak. - */ - do_invalidatepage(page, 0, PAGE_SIZE); unlock_page(page); return 0; /* don't care */ }