Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2974836imu; Mon, 19 Nov 2018 08:51:24 -0800 (PST) X-Google-Smtp-Source: AJdET5d8illC/DzT6dUqdcjZt/uTmOnFO0mZ4QVvGnbZAVLaBPOwp2MSq+dxxLVtN4kNA2XJeABm X-Received: by 2002:a17:902:14e:: with SMTP id 72-v6mr22363313plb.299.1542646284191; Mon, 19 Nov 2018 08:51:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542646284; cv=none; d=google.com; s=arc-20160816; b=ru9bM+2P/rh7nLcdFcYWdJ7xGNYWTXAZHHP/8tB0vWF8iSIFGBimR/cyHB0moOAxgv 3+/Jd2yMj1/H8+6KxCDoyyzw7LaOZ6j+0mvYxDUTUSP2KcUY1cKEMG5xf9ZnuI423xMs StpS12pKU1ue1cH6MVOH1gd9vNadmg/7na/L7MrNoKHbmaISvtns7q2RtQo0qFbZ9dTv gTRq3866E7c08YalxpNtvwKLXPcdBV0Ar4PtKh9x9gBPRTO5HnjGksZqNCnlUn/iOMpv 2bdMnwCQQ8q+6+ASfNM62/JpreRVb72K/XRl5iMcRKsVwoRPre/iDIvzJRMVjJosRaZ/ Cidg== 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=fvVSg7sQYevmO/VQJWcBgIC+RrU2VKKa1KwSe9b1Pj4=; b=FRxgufuFtDjMCqkcYg6U9D+6iEmFb385SctY/em5KpsvyERqlVigzePDdx4A3xz7cl TQ/vt6bj5tx2kaJbj/cfqZu6y9S7+LLvC2zPtFOjSOiIHG7jjByompvFTF+8pM5tf0eI SJtYwOyY3Yo8W+ow3H8y9Y9ElNZ9hPsIJ1hWN1xNAZR7ywQA3FOFS6DpQdvGB0YPTmEy irHhJ2Jqe5CYqmv0Pf2tLBK/+irnFdWLkG0L4mOopeXDXjWU6fY8YwvntWgavU1VvSyX edcB96UXfuMD93RrmcYm3WxCHgnltac2ZjKMBQIyH/o8Pg+DSx74Qdz6u28mmx0jzBAc lKyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=s31oYwVN; 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 d12si30006929pln.340.2018.11.19.08.51.09; Mon, 19 Nov 2018 08:51:24 -0800 (PST) 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=s31oYwVN; 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 S2389648AbeKTDNU (ORCPT + 99 others); Mon, 19 Nov 2018 22:13:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:50024 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389110AbeKTDNU (ORCPT ); Mon, 19 Nov 2018 22:13:20 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 9FC51206BA; Mon, 19 Nov 2018 16:49:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542646147; bh=piQbWpmKejRE+ACLR+9DwHSjirW4NhNtg7n9xp7WwGo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s31oYwVN3dWj9CG2D7hPS4uINkDe13dyyypbkHFhe4IyyHqu+2wRHEHaGQbl7OVcK n6V7Cr8/AUU1s0KUKZFUCovDAF7Qu/6AAsq9YQ/NqkWKBBMFbA348vaH4nR5HV5alv IM/ewwUvleBbYW2D/wab1G3yZa3dQIdHEvn4i+Yg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrew Jones , Bart Van Assche , linux-scsi@vger.kernel.org, "Martin K. Petersen" , Christoph Hellwig , "James E.J. Bottomley" , "jianchao.wang" , Ming Lei , Jens Axboe Subject: [PATCH 4.14 054/124] SCSI: fix queue cleanup race before queue initialization is done Date: Mon, 19 Nov 2018 17:28:28 +0100 Message-Id: <20181119162623.999392166@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162612.951907286@linuxfoundation.org> References: <20181119162612.951907286@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ming Lei commit 8dc765d438f1e42b3e8227b3b09fad7d73f4ec9a upstream. c2856ae2f315d ("blk-mq: quiesce queue before freeing queue") has already fixed this race, however the implied synchronize_rcu() in blk_mq_quiesce_queue() can slow down LUN probe a lot, so caused performance regression. Then 1311326cf4755c7 ("blk-mq: avoid to synchronize rcu inside blk_cleanup_queue()") tried to quiesce queue for avoiding unnecessary synchronize_rcu() only when queue initialization is done, because it is usual to see lots of inexistent LUNs which need to be probed. However, turns out it isn't safe to quiesce queue only when queue initialization is done. Because when one SCSI command is completed, the user of sending command can be waken up immediately, then the scsi device may be removed, meantime the run queue in scsi_end_request() is still in-progress, so kernel panic can be caused. In Red Hat QE lab, there are several reports about this kind of kernel panic triggered during kernel booting. This patch tries to address the issue by grabing one queue usage counter during freeing one request and the following run queue. Fixes: 1311326cf4755c7 ("blk-mq: avoid to synchronize rcu inside blk_cleanup_queue()") Cc: Andrew Jones Cc: Bart Van Assche Cc: linux-scsi@vger.kernel.org Cc: Martin K. Petersen Cc: Christoph Hellwig Cc: James E.J. Bottomley Cc: stable Cc: jianchao.wang Signed-off-by: Ming Lei Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/blk-core.c | 5 ++--- drivers/scsi/scsi_lib.c | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) --- a/block/blk-core.c +++ b/block/blk-core.c @@ -671,9 +671,8 @@ void blk_cleanup_queue(struct request_qu * dispatch may still be in-progress since we dispatch requests * from more than one contexts. * - * No need to quiesce queue if it isn't initialized yet since - * blk_freeze_queue() should be enough for cases of passthrough - * request. + * We rely on driver to deal with the race in case that queue + * initialization isn't done. */ if (q->mq_ops && blk_queue_init_done(q)) blk_mq_quiesce_queue(q); --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -683,6 +683,12 @@ static bool scsi_end_request(struct requ */ scsi_mq_uninit_cmd(cmd); + /* + * queue is still alive, so grab the ref for preventing it + * from being cleaned up during running queue. + */ + percpu_ref_get(&q->q_usage_counter); + __blk_mq_end_request(req, error); if (scsi_target(sdev)->single_lun || @@ -690,6 +696,8 @@ static bool scsi_end_request(struct requ kblockd_schedule_work(&sdev->requeue_work); else blk_mq_run_hw_queues(q, true); + + percpu_ref_put(&q->q_usage_counter); } else { unsigned long flags;