From patchwork Mon Jan 5 16:01:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 5569461 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9F3FABF6C3 for ; Mon, 5 Jan 2015 16:02:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F139B20148 for ; Mon, 5 Jan 2015 16:02:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 177DC2011B for ; Mon, 5 Jan 2015 16:02:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753364AbbAEQBo (ORCPT ); Mon, 5 Jan 2015 11:01:44 -0500 Received: from mail-pd0-f174.google.com ([209.85.192.174]:57892 "EHLO mail-pd0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753152AbbAEQBm (ORCPT ); Mon, 5 Jan 2015 11:01:42 -0500 Received: by mail-pd0-f174.google.com with SMTP id fp1so28251503pdb.5; Mon, 05 Jan 2015 08:01:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=Q//Y+maaqlOUw+ktx2+FdlA2qFFzaGFF4NqKO9GhpcM=; b=UHzMZZDsNkFM13hZXiMaF0Phc1B2AhJvrK1dgWxd9j2tfB75ZKb5lyFtPPDxybwKnq fLQmvRnuFxrtL8mgz2Y6kXlxB9gwWU4wdIZcfM72uqEvGwUvDcGcNZAurvCFscqe3dzE 3Pps/pY30bpBfK1HM8VB11JPkHWEyN1XkxfSrlXwH+VN3DDkz+M7StG/4v4wwf3bmDei /AkdRNWvyawluB/LiBI/Oeqyt0RqdujKN1oY7fDs2Td/UbwR2LY7Lk+XP2fB7y3jj4W9 yQ/tGJ1/ZR5hd9YJ9RtDOoHzk0ZZG0X54NlneYxB/wqfXvaNXoctuRzV6axR/PaCfOKA KTIA== X-Received: by 10.66.119.175 with SMTP id kv15mr149902459pab.30.1420473702236; Mon, 05 Jan 2015 08:01:42 -0800 (PST) Received: from localhost.localdomain ([116.94.66.103]) by mx.google.com with ESMTPSA id jp10sm9822162pbb.2.2015.01.05.08.01.39 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 05 Jan 2015 08:01:41 -0800 (PST) From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Naohiro Aota Subject: [PATCH] btrfs: clear bio reference after submit_one_bio() Date: Tue, 6 Jan 2015 01:01:03 +0900 Message-Id: <1420473663-9315-1-git-send-email-naota@elisp.net> X-Mailer: git-send-email 2.2.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP After submit_one_bio(), `bio' can go away. However submit_extent_page() leave `bio' referable if submit_one_bio() failed (e.g. -ENOMEM on OOM). It will cause invalid paging request when submit_extent_page() is called next time. I reproduced ENOMEM case with the following script (need CONFIG_FAIL_PAGE_ALLOC, and CONFIG_FAULT_INJECTION_DEBUG_FS). #!/bin/bash dmesgout=dmesg.txt start=100000 end=300000 step=1000 # btrfs options device=/dev/vdb1 directory=/mnt/btrfs # fault-injection options percent=100 times=3 mkdir -p $directory || exit 1 mount -o compress $device $directory || exit 1 rm -f $directory/file || exit 1 dd if=/dev/zero of=$directory/file bs=1M count=512 || exit 1 for interval in `seq $start $step $end`; do dmesg -C echo 1 > /proc/sys/vm/drop_caches sync export FAILCMD_TYPE=fail_page_alloc ./failcmd.sh -p $percent -t $times -i $interval \ --ignore-gfp-highmem=N --ignore-gfp-wait=N --min-order=0 \ -- \ cat $directory/file > /dev/null dmesg > ${dmesgout} if grep -q BUG: ${dmesgout}; then cat ${dmesgout} exit 1 fi done umount $directory exit 0 Signed-off-by: Naohiro Aota Tested-by: Satoru Takeuchi --- fs/btrfs/extent_io.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 4ebabd2..4421161 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2816,8 +2816,10 @@ static int submit_extent_page(int rw, struct extent_io_tree *tree, bio_add_page(bio, page, page_size, offset) < page_size) { ret = submit_one_bio(rw, bio, mirror_num, prev_bio_flags); - if (ret < 0) + if (ret < 0) { + *bio_ret = NULL; return ret; + } bio = NULL; } else { return 0;