Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3102027ybi; Thu, 18 Jul 2019 21:04:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxnftTh82hZkslXodZt7uJ4oSOxASYQHpuoGtq6ppstGoICDNkA1rOIW0zgDeFP/52k2l/4 X-Received: by 2002:a63:2cd5:: with SMTP id s204mr38334265pgs.95.1563509053737; Thu, 18 Jul 2019 21:04:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563509053; cv=none; d=google.com; s=arc-20160816; b=H0/ULcjYix/kUGevFflM5nXyoMEFRHMcFnvbZ9rUTsFKwNHZ4HRKL9X+i88reQlOYz KazO6JZQjS0Oz7FHnJHOlXMB4jN6APIL3ZHaqOzkbrdoQf4DPkLbqtiUmCOM00fsWGlj p/WmqDZQ4rv9zL0NQMy1y7XWZKc7sXWLx1mZdSH6Uj4JDK2ZMAj9F7ssORsZaveAJfHn 9FuUGwH+KG8U/dPay0r2U9Lu/Ay5rU+5wTNFMI54wpjGc6hKPspCO1D08zcAMDCh2WAV jkHbZELC+C8EHl5b9NRoSgNgy8z6By8xZMLtJ7oLJ6Id6swIEiB7QlyD4hHiY5kdjU98 xvdg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VGOaWxoYRG4+D54VsRNRONEY4Wlj3W6IryjHubEtkDY=; b=E5kl+G3WVdeIF9XvvIPtIKMzK2bYBNX5tym5vjI3dieYkVmPPt3ciC37iKWUXYn1c8 1QPCqVBo6DjMPuPslbcg/IK0WeTSQmyoNYqwCX54XG9GrXpHCp3S6QpWhW1MFQLoH6cR D+U7LYVSBoHj/evWG/yO/fpqcGpnVe4eumuyBPrwXKCjTWi+ey1soexz2hEv0JTt3JPl kUm2yq9xZsFFe+pPCGln0RYCARq6tUVXOM8kw/5pj907l8xT5/ZpsTSCP2dXuuEl/fTA JjXfwIy8AQMVUct6LW/3e5sdMYU7w1BkL62iGO4tbgbQDgiBANcWOxQyF5gKKriwpcj/ lG2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SCVoVyKQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e129si843318pgc.344.2019.07.18.21.03.58; Thu, 18 Jul 2019 21:04:13 -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=SCVoVyKQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729633AbfGSEBo (ORCPT + 99 others); Fri, 19 Jul 2019 00:01:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:33328 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729495AbfGSEBf (ORCPT ); Fri, 19 Jul 2019 00:01:35 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 55035218A6; Fri, 19 Jul 2019 04:01:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563508894; bh=mxrsFRAx3PeEIwmrJvTX63q6ItA8/OWjca6l7bYHLhQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SCVoVyKQrIqdnrW6i465CPDsK4ag8OzMXi0/YNnxnSQzIxGxplyUy69TEqZsx3AXR NpyRiRVqHQgX/1mq83IIk2tC0DPtWER3vukWOLKJ1DozTAnrOkcJ9SGq80ON5vix3+ Hb8aSVQ2/7vt6cpUJlY+XIFPmfScjtChpw+grl8E= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Josef Bacik , Jens Axboe , Sasha Levin , linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 142/171] block: init flush rq ref count to 1 Date: Thu, 18 Jul 2019 23:56:13 -0400 Message-Id: <20190719035643.14300-142-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719035643.14300-1-sashal@kernel.org> References: <20190719035643.14300-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Josef Bacik [ 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