Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3812948ybi; Mon, 29 Jul 2019 13:07:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxec8U3YYRIiCQ7JHKr7hzPOdRaAmgLqjtFskmQNdyhR/I7sc5LunapWlQ1PiDk5UKCm7/x X-Received: by 2002:a62:754d:: with SMTP id q74mr37288339pfc.211.1564430841754; Mon, 29 Jul 2019 13:07:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430841; cv=none; d=google.com; s=arc-20160816; b=J0tKmT8louBsJucpgrFxBOi+2fbcVB9R8Db6ZV7H0aJrLE8nOdNi9L3GxecSWGW5Hs FKx+8FRot/29Emi1SaRprN0/bONcXUD6gERgPrGVq8Czla8fxstn5Nk4RHV+niaB/nld uoPddfGF4c+CtV6LXCFyPyGI8CCJVAk3LmVhIUwTjCiB5C5s8ExXPdLEJ7XBCV0vNxCu ZAit45WqLLx35sXgJJpF/tREvQz6DavYunEx1otSWLgbv1mPj574AEZ+BHCUoq5LGiws XDhXddJC9uGnAEdihRduOQb3d/g6lrdwbX9QarlLIqat+tP9Wl1yBmxs8YdHei6jRo1a a9hw== 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=W7w/CqeMODKtEu9VLD1CifWA2j5/STVsxlGpSQmR75w=; b=fg0NpxQSbZQ443vRYEFKu8WpqRhqxOH2Vc6MEL8wlMsUFNHqycxx1uHywuyipQFQzF 8eOp7cn2RckAPYwyJCmPjUTw3HVmLIFiBUYrxVqq3IeNczC4Avp90VBYs/Wf79tA0SLW u/bP/GwQRlYlkc/3YpZVVWJPDxPEHlJOWJdb4RG54CdfhLMDQtsaDZf0Hdi3zovvNhar /NzUnN6i3LmYz7/GEeduXaYZcW5PUf/j3gNO7VDTbZEND6u42Lm0EZQ/PXVQiUF9/Iz4 2K4ZZkIURFYzXVaADbleq+SmGjKTgvVuIIH7Nx+GfuvvJPjo8mu45EqyYdGYVu/Bq9KL qH9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="SeKB2/yF"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k98si24771727pje.41.2019.07.29.13.07.06; Mon, 29 Jul 2019 13:07:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="SeKB2/yF"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389570AbfG2Tox (ORCPT + 99 others); Mon, 29 Jul 2019 15:44:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:33404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389834AbfG2Tor (ORCPT ); Mon, 29 Jul 2019 15:44:47 -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 33CC9205F4; Mon, 29 Jul 2019 19:44:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429486; bh=7u/+GiX78diQlZSnpnqu2l4eIo9WSrQyRAj9zKhIdHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SeKB2/yFnql9PaOl0mnQI4OND7DqE6/OJcojsjny+oh+lZrlaG1mlNQRQw+fHsKD9 9igqOcC3kZWjqyGM6QcDiu+WVlNfTiXrIkaeWoJhc5DvnRDTz5p8JXi4O49lB/3CSx 6oJnq+m7Idqvu+FGP+3qZD7gsFwexRvNuD9BARPs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , Jens Axboe , Sasha Levin Subject: [PATCH 4.19 076/113] block: init flush rq ref count to 1 Date: Mon, 29 Jul 2019 21:22:43 +0200 Message-Id: <20190729190713.719362728@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190655.455345569@linuxfoundation.org> References: <20190729190655.455345569@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 [ Upstream commit b554db147feea39617b533ab6bca247c91c6198a ] We discovered a problem in newer kernels where a disconnect of a NBD device while the flush request was pending would result in a hang. This is because the blk mq timeout handler does if (!refcount_inc_not_zero(&rq->ref)) return true; to determine if it's ok to run the timeout handler for the request. Flush_rq's don't have a ref count set, so we'd skip running the timeout handler for this request and it would just sit there in limbo forever. Fix this by always setting the refcount of any request going through blk_init_rq() to 1. I tested this with a nbd-server that dropped flush requests to verify that it hung, and then tested with this patch to verify I got the timeout as expected and the error handling kicked in. Thanks, Signed-off-by: Josef Bacik Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/blk-core.c b/block/blk-core.c index 682bc561b77b..9ca703bcfe3b 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -198,6 +198,7 @@ void blk_rq_init(struct request_queue *q, struct request *rq) rq->internal_tag = -1; rq->start_time_ns = ktime_get_ns(); rq->part = NULL; + refcount_set(&rq->ref, 1); } EXPORT_SYMBOL(blk_rq_init); -- 2.20.1