Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3148552ybi; Thu, 18 Jul 2019 21:59:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5KmVmVHuWyNuUrfLwaXX7/QRWAjkrTqFHgFMLITxn4urci28KEayaWckIcwBc/aHQM1D1 X-Received: by 2002:a63:6b46:: with SMTP id g67mr10787157pgc.386.1563512380433; Thu, 18 Jul 2019 21:59:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563512380; cv=none; d=google.com; s=arc-20160816; b=H84llfk+ydLNxKcxv8Lctu85K59AF3kHIwzYqwGQZBKue4fJLad/wDMj6na7veNyBF ij15/WHJ2ryHI7V8E/gqri7anRElcmvapd4tDvcsV6/79q9XZ3vJS2Y8Y8HUaZ43gb66 x/NRHsfToggixtOodXrUfXo8fIFvIiIuV4YpqkxgclXShHK+9BYbhh0m8Kpk0F0gNrVq Tb4dSJOjjVZJyVYWQgDBBgkCRUnAeZrJFTTG+Rc3QwgWvfiX7BRt4yBdOPzqcNH8ytrn 7Zk4Vtp6dYs3l8oAR0jgpqNSU7qQ9pr1AwsAAWpwAdX4O7uJsO39064z7KX9gTV1rQ83 N/hw== 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=HCAisC4IAJzIS+16bNzvy7qfxprSS3qFmECK+Yuz02A=; b=cE/AU+hB6YEDsl8V3R2f16v6dBp2pZpBYDlpac+NwyV2VgpLvtD0ul+9wd5A3wm2lX ZySILvf0Mc4eyx73wOuHBrTj5uiPp5fUG67fWldJUuk60bdRwlonKpqJHqQh2Ckx4gzi N7fEZKOn1FAPUn07tpcf+6Iareh+aTngLsAwt68EJp82jPJK4MnkwF39kJMSUBRhQGk2 qR2iyhHCfMPtop8f13yqT5ll8k0HI8ek0/mGmR2C4+CqVOgx1oru1RYq3zZVnFD7n+L6 fMwiGZLJJxP078Gq97H8TD99tuUqn6HqCGJZF+8yQAQ37Wn1a6qnyoB232HY866eqscY +2nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rDdC5cVd; 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 o127si714082pga.593.2019.07.18.21.59.23; Thu, 18 Jul 2019 21:59:40 -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=rDdC5cVd; 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 S2387473AbfGSE2e (ORCPT + 99 others); Fri, 19 Jul 2019 00:28:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:39544 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732114AbfGSEG0 (ORCPT ); Fri, 19 Jul 2019 00:06:26 -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 A81BC218B8; Fri, 19 Jul 2019 04:06:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563509185; bh=GR4SIol2VzsKNVqc9HUATBFbm3+d6wZOlhp3mC9c6/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rDdC5cVdtZejU1kAM7QhthFlELGj9MhjedA++Yx8pjq1Km2pN1VojdDOpRhjy4qMP ZQi79QfgKdpxwW0oVqxQxzmpT+zKDYHJ7qnXTusLC/0+Y/zKWbhQjtZO+IBalTgiJr 4vsFbR0SZIzLGdTaZbHqow/+MjD59sfu1fHeYJhM= 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.1 113/141] block: init flush rq ref count to 1 Date: Fri, 19 Jul 2019 00:02:18 -0400 Message-Id: <20190719040246.15945-113-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719040246.15945-1-sashal@kernel.org> References: <20190719040246.15945-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 2dd94b3e9ece..aac658392d60 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -116,6 +116,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