Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3800616ybi; Mon, 29 Jul 2019 12:53:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyE9Aq09H7vxaKwOqgfpjU5eTIIg3wdNHLB1PdW4pFYCYSPwDRRnGHmf6L7fxIu8Surhztz X-Received: by 2002:a17:902:846:: with SMTP id 64mr111885324plk.265.1564430017005; Mon, 29 Jul 2019 12:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430016; cv=none; d=google.com; s=arc-20160816; b=TmRkNFOIpVJOAfSTWP+AUxIcWaZ7Kpy1QSYkWcdkm5jZWjPplkCquK9QlRCwquvxyB T/xdFtzkW3qtt/ySgjlGlj1LW/eGXIYnXEhMATC36AtBJA4EkuNykdS9RGXxdwyMU3Sg jezZHOEMwfGb9ZANjwrauV4+mCXbBxdUh7E+FWQnEXJINTDvDzbghQrJ1zVdeisXH1ID +q+LKmVtlFfoyXbiuZizrdGQZShNpK6CV1JXF1k9u9YRpFWxenDbJ0OH+Js4dbeZVCev oPBEFXVqbKaJZqGKwK6OkW/Pf64UkIVSmH0ti3fvfigp3gEChgqAuJGOCwwmiv36+8ny EhvA== 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=+6Yr9u9kwO/2pqDkIKkl+9ed5eoi9KRKeCZZo/3RCwg=; b=Rj1ByDTlwYNWacoume7Uy4EdXeL2PB5nqKx20t7Tm9Sf+3jlGNjEj1KTrAvyFkJN7e wgTkYn7A3QBK5BVgrdtilWuFDJehmEulEtxmCeDYrq9s+L49XQwfaNBUvdMO6Il7Cax7 FSM9d/4KEnt25NIwzOkycfTP+5CNJXQ7n/K4pW/RNNLtvId4Dqe62mrugqCipWFd+QFO Wsqup3Mwjpih0qyhkWZXTh32aQ0ZYc0Fk3qJ+vl3wwI81crP7bxg4e6zGQASePtJHFrs 10tpEvN38q/LtByiCuTwd3jttMMv9NTWkBLYXe68nxEjD4cHrKpnjmjomDhomWeuErsX T4LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BGiNhD97; 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 o4si26298603pgv.157.2019.07.29.12.53.22; Mon, 29 Jul 2019 12:53:36 -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=BGiNhD97; 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 S2390849AbfG2TwJ (ORCPT + 99 others); Mon, 29 Jul 2019 15:52:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:43830 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390633AbfG2TwE (ORCPT ); Mon, 29 Jul 2019 15:52:04 -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 A858121849; Mon, 29 Jul 2019 19:52:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429923; bh=PNDGmWQI7cDkfKFaBd1EUA/CM2aZJfNnIxTpY9WEvi0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BGiNhD97JLkgxiNweLPOCiZknrrBuESDzPTq+WOMai7McFsTmVkNy2ZEiJgzGRju2 6Wq9kzTcga05vtVz4B8BHZClsJwIdSaEdeyr/Fk+352Ioe8gROBprzipyKrdiQPFY7 kRtxnju8lERx97eU22jEOjqWkakYovNfEsIRiNoM= 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 5.2 139/215] block: init flush rq ref count to 1 Date: Mon, 29 Jul 2019 21:22:15 +0200 Message-Id: <20190729190803.642305760@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@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 8340f69670d8..5183fca0818a 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -117,6 +117,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