Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp877545ybt; Fri, 19 Jun 2020 16:41:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1lZFAvz1Hfup1mdmM61kiUO/bhcWhColtSIipYHzPDm1AbVa9CiS/6LWxuBH6R7TYNNUz X-Received: by 2002:a50:9b13:: with SMTP id o19mr5659802edi.143.1592610114185; Fri, 19 Jun 2020 16:41:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592610114; cv=none; d=google.com; s=arc-20160816; b=0bw07HeWnAQw/Oo3nLKv9NpWdsGYT8aKTPAqiKQ1opWm/KIVWR4mSC80l2t1P/fLcN 5+/IiNO9DvScM49DX7ejD6VEwbkctW4CLSYQzfrwQTmmZwm8BfGBkIUS/lcKURf7b8Ou meyMN+RLbgNf/CdnFPK6uJgHQFDhzVFZQrM4dQSK4Sqki73qVo9z1/CmaccsIXeigDoJ 3KL9GVQorakJkpR6BjJZtb1b9gzcHdXgv4lZAXu57eb1CODo35VZ6vB7BixklbB6UpiF /8gnHHfnTenZ2KXyq1fa6yOMkv0WMZ1+gRJv7g7UczXW0Gyen19ozyq+hUBG9HAbhdbn eaVA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Vi0w0pQfCgTB6OmID3OXaIZ+G6pYoeWXwVOFDzXxZAE=; b=aeZieHINw8/PmUwp4REnok53QZG3GzYew7VKAMxOveJEDb6i10ux2TORWUV3Me9zKu M101l/uyLvh7UbqWR9VXTiBoL5+8+rbi/yuXK0/1C5pYQybp8GwKan+xknOst7luUY6e PraMDJi5aPUYNS9DfiqD0pgJwvk0iqgYsb2URSgvSnB8EO5jrD2JDGxjhNmuU8Eh84DP Y6a2MSyOQP7phd9C9RNRp9vUYDe5nzw0Hnfva5tY0ghizTV1kENJQ0V5sBElts7OQ8vZ NVqHHKFd/lTgdxyYZBEOJaUUdIn6o9AN72i5h9RFaelObO46fywIu0kDnXAdvhTmT9Ju Y2Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=u1sYx2Jl; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y14si4680155edu.550.2020.06.19.16.41.28; Fri, 19 Jun 2020 16:41:54 -0700 (PDT) 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=u1sYx2Jl; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404561AbgFSP2Y (ORCPT + 99 others); Fri, 19 Jun 2020 11:28:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:59650 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404431AbgFSP1v (ORCPT ); Fri, 19 Jun 2020 11:27:51 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 714F021919; Fri, 19 Jun 2020 15:27:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592580471; bh=tuDRqiH3z8t+Tcn348TH6OdYItS+4lbNyFSc6Krzucs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u1sYx2Jl6HeVLTmdg7XAcrEbPRhxGZyAcM46q4XZV8hQBFjL3zDIIZpNz5uR/aaHL kZlLe5lTHCCSXawDQayPawuWJc8XfoIWGITKVmdVWOaWXWxOukhEFi/DuZHzdaCx2l awgM4zB1YDQb8vAYWyl6qG0qD4GN8tnw9Z18arg4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikolay Borisov , Josef Bacik , Johannes Thumshirn , Omar Sandoval , David Sterba Subject: [PATCH 5.7 262/376] btrfs: fix error handling when submitting direct I/O bio Date: Fri, 19 Jun 2020 16:33:00 +0200 Message-Id: <20200619141722.730040941@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141710.350494719@linuxfoundation.org> References: <20200619141710.350494719@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Omar Sandoval commit 6d3113a193e3385c72240096fe397618ecab6e43 upstream. In btrfs_submit_direct_hook(), if a direct I/O write doesn't span a RAID stripe or chunk, we submit orig_bio without cloning it. In this case, we don't increment pending_bios. Then, if btrfs_submit_dio_bio() fails, we decrement pending_bios to -1, and we never complete orig_bio. Fix it by initializing pending_bios to 1 instead of incrementing later. Fixing this exposes another bug: we put orig_bio prematurely and then put it again from end_io. Fix it by not putting orig_bio. After this change, pending_bios is really more of a reference count, but I'll leave that cleanup separate to keep the fix small. Fixes: e65e15355429 ("btrfs: fix panic caused by direct IO") CC: stable@vger.kernel.org # 4.4+ Reviewed-by: Nikolay Borisov Reviewed-by: Josef Bacik Reviewed-by: Johannes Thumshirn Signed-off-by: Omar Sandoval Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/inode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7939,7 +7939,6 @@ static int btrfs_submit_direct_hook(stru /* bio split */ ASSERT(geom.len <= INT_MAX); - atomic_inc(&dip->pending_bios); do { clone_len = min_t(int, submit_len, geom.len); @@ -7989,7 +7988,8 @@ submit: if (!status) return 0; - bio_put(bio); + if (bio != orig_bio) + bio_put(bio); out_err: dip->errors = 1; /* @@ -8030,7 +8030,7 @@ static void btrfs_submit_direct(struct b bio->bi_private = dip; dip->orig_bio = bio; dip->dio_bio = dio_bio; - atomic_set(&dip->pending_bios, 0); + atomic_set(&dip->pending_bios, 1); io_bio = btrfs_io_bio(bio); io_bio->logical = file_offset;