Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp761087ybt; Fri, 19 Jun 2020 13:04:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0+cV22ykxNtLSR5qMB9ULd8OY4DtzRcVUTqTQ23+YJJE++sNLybPILPwL5SYHZWie/rv5 X-Received: by 2002:a17:906:4e57:: with SMTP id g23mr5087674ejw.522.1592597082057; Fri, 19 Jun 2020 13:04:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592597082; cv=none; d=google.com; s=arc-20160816; b=RoM7R3YA+LgYZQp2QTu/1PP40q6cfuP5oSCNMUBXRAK4ryz41r60SnwTWoUYgPvV/g u9EckogeTheb6E8HLzhVXIoo+wapdxyEbs9wxh2MKGWTSnVPutU2n8zyFvZCrMnqN6b/ h/FJdoLnxgAaWdK6fwQcwTJGabVg23hlr2ONua7DVbHqw1ilAR0ah+uc+SiU9jozCeUO nT1NVVpRo4av4do9kVG2TBxzO3FA36NdEsJcsGu4yiVRP4ArAItjPziz8e0AwVJFWfyw y5dH3hisaMpLsFKTdRmy1X4/HcXNJalQ85S0/jU16HptEQ1XVLi9S5EqzXoR29JLIZm+ ZlNw== 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=kBazbu6QLdMiD0Wi4P3huJromHVyAb8M35rbMLA/wGM=; b=n2Qp3dLYFqhrSMbInPM2rWBFZcy+veNcLmnJteM55TfyQ/miI7M51S+A+GrRUUwUms 2mtsuTJDMZlR/VqVESwUzg6xeGHiVfUqxYWEsbaUYiyODolCqXjsOCeLDSlXLQDpezaP 0Rp3bc+H5iSMfbn4XXyly40Ebp2AWnAASlweoOqOsx4oNTljiqaa/x2EgD9ED2TSPxjc xKPmzJmdOdrOLyvmbmhQpQEtL4H2m4ZKNvbhCmhFYfp61C0K6jZW7sBblaTbOiVCwm7M wzdI3yWVzePr9SBPjav7vgebonelL6ww7EYjfh3NjP/tBYZELLnspRTAgHj+cO6U3Rux hTpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hNu7ITRD; 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 ar22si4229012ejc.434.2020.06.19.13.04.19; Fri, 19 Jun 2020 13:04:42 -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=hNu7ITRD; 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 S2389607AbgFSOwh (ORCPT + 99 others); Fri, 19 Jun 2020 10:52:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:46462 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389572AbgFSOwX (ORCPT ); Fri, 19 Jun 2020 10:52:23 -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 D97CA21556; Fri, 19 Jun 2020 14:52:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592578343; bh=bBcmiQKw5gyq64+scVj1X9IAimDWGQZI6cKI+wHMt/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hNu7ITRDVFvy2YYHI3JZZjeeAhPdALo2eFoOqSVRsregcOMTFPUow5LPDzREo9YZP JXFWw8AzX8FLryuzAJQyL7abGUPuRg2S+G22CP5q6uLX98FzIT4OindVOkSyr+xMQq iwFV6gedLMp+A8dV0v1GZPw3TVS+a3YQa86+bHiM= 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.14 159/190] btrfs: fix error handling when submitting direct I/O bio Date: Fri, 19 Jun 2020 16:33:24 +0200 Message-Id: <20200619141641.687665192@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141633.446429600@linuxfoundation.org> References: <20200619141633.446429600@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 2a196bb134d9..3e65ac2d4869 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8707,7 +8707,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); @@ -8758,7 +8757,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; /* @@ -8798,7 +8798,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