Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp992128ybt; Fri, 19 Jun 2020 20:51:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFvmRrqcj5jaoyFjriesoWLM3gw7P6qWHbrZzkPE/YRdG7guH8D0HbuzjU1JB5wjomnK2A X-Received: by 2002:a05:6402:897:: with SMTP id e23mr6465298edy.217.1592625092749; Fri, 19 Jun 2020 20:51:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592625092; cv=none; d=google.com; s=arc-20160816; b=kZwaPfbwij8L7fwmiBDJ9VaImnpAJZzWFFYH9BdVfTW3/Zd4T250NiB5B/QSi+8OYf fUlrkuzPSQ63i/JeVlWDv90d/yuKrkL5l34LhYhg/QfPHzd71+xdZqDkwVTsDAVI6DMz 0krxqmShXIB2Xt15TSmrC1VPQtNimgYQ2cKNzvKPsxScnnvxwhM7R4J5BGqgePEmrKpt GsyWSRqUPPAPI5TNICsNNYy0/0E7u+4C5XiHFzSyvNTRjsCtLxEIJvPaPIQcOmvb2JFC VGRF+s5gY0XjmG5h+Av5o3uNBwa+lsEAvQEqLvHFhW/4x9Zi9ALNUatRyQqovkucpwud uPRw== 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=k0VSVxrlpWWrOAhM/06A7p6nxkET2a4B4USmDVQZmo8=; b=Q8myKM3QOHZ3vbFxnN2m3xfrpw/5tZM0BPZmFuDn6UZ29C6KqDUmCsL7QfMj6hhd+Y ic+yYJyOCjfGKcxZxOfnGu0u6zvoMpeaoFTzJd1MgEA70nsz0DGrHQyUuf8BfJUO91K/ dx1gOoSV2/4cNqPkf9VZZJSUNivxRuIazmzK7oYxb5HFTEvwFiSfWDrtHF2yg1lCuOpI DSkbhBAt6VeEExwnsF831eNj7TD3/o8STmm5BBMeax/JVkqKu9PI0OMhql7QtWYyJ+FT 7Fey/2qRIi71E68YtUaGcQocQ/GM6zKh/33RjWz3IKUXuqcTveTC4CrmIXe+z66l8Vjh Gxcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="R722oo/Y"; 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 dd12si5093701ejb.59.2020.06.19.20.51.10; Fri, 19 Jun 2020 20:51:32 -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="R722oo/Y"; 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 S2391523AbgFSQRG (ORCPT + 99 others); Fri, 19 Jun 2020 12:17:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:59618 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390902AbgFSPCw (ORCPT ); Fri, 19 Jun 2020 11:02:52 -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 6DB2120776; Fri, 19 Jun 2020 15:02:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592578972; bh=dFj03ieTKPIxULsHQ9pqrB5XgXCDpm1ISDBdSJI9s9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R722oo/Y8mAvhHm0JYEgDwk1Ai3s7PgDii9qGgGbRD2jV/JbvdMpElrxTm4QYgzBs 4Ywakbe3q8uKxPmNyDiw9COYzopX1kw+iB9J2jCa5Sxdasp5EpwiY58jeu/4yewQdR blTDXe5g+SyKvAG9lExBaRcNtTdmkVmGgqHOP42c= 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 , Sasha Levin Subject: [PATCH 4.19 228/267] btrfs: fix error handling when submitting direct I/O bio Date: Fri, 19 Jun 2020 16:33:33 +0200 Message-Id: <20200619141659.635299828@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141648.840376470@linuxfoundation.org> References: <20200619141648.840376470@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 [ Upstream commit 6d3113a193e3385c72240096fe397618ecab6e43 ] 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: Sasha Levin --- fs/btrfs/inode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index c69e5b255745..b4f295a058d8 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8399,7 +8399,6 @@ static int btrfs_submit_direct_hook(struct btrfs_dio_private *dip) /* bio split */ ASSERT(map_length <= INT_MAX); - atomic_inc(&dip->pending_bios); do { clone_len = min_t(int, submit_len, map_length); @@ -8450,7 +8449,8 @@ static int btrfs_submit_direct_hook(struct btrfs_dio_private *dip) if (!status) return 0; - bio_put(bio); + if (bio != orig_bio) + bio_put(bio); out_err: dip->errors = 1; /* @@ -8491,7 +8491,7 @@ static void btrfs_submit_direct(struct bio *dio_bio, struct inode *inode, 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; -- 2.25.1