Received: by 10.192.165.148 with SMTP id m20csp4150837imm; Mon, 30 Apr 2018 12:43:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpzzhcxsJJbbJI9HS+Zv4Hr73gLm3MXdAiSlMYhB8thMWDxXqkc4EjLp/UlhRYoK+anK/uC X-Received: by 10.98.178.4 with SMTP id x4mr13118579pfe.21.1525117411714; Mon, 30 Apr 2018 12:43:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525117411; cv=none; d=google.com; s=arc-20160816; b=tfsC4Ck2bvZygNY+zvrRNBUFKerEhWzOKOQbI8VFAhe3R2RcrDeEbNHTFGgTc1E/7O RebdTiuqTuI7pUPzg0FNVLvg3cZklZKBnN2O4+YzmwrNNkbB+9YmsUE+b+jRIa+ScJCa ruFEhCOjSSB8bdj3btaTptYMag20Ac6f0tyyIBkFeRWWNSDtVrWpLp+cybcx4+MKH0Rp z/rX3LrjA8/9mGGIBBjZ8K8bdgZvOxJ5Q78pJsfLD9yFsYGRuZJsPJBCC3TlGIlEUbqc 9M6XooNR3ANrPzqLUAnjXYlEYodI2lU8OGLqxFILCRb5BfiCB6TL7oDwv5uQpzuLzsDo YsMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=XOTQlK4ZsFRps23EWQim6t8+jA6G3GFJrYTAVjLQ4Kk=; b=Oap5CqDCrCxxicokDxwPlcHvZrH/A7ZSki/j4rzUlTxypIrhxhuBPSaAvqbRLKGm1j Jf7LaGhob0pyhTIljWNbk7T8BwnL3OnVMkhsYlI45YRB0c9FesRcLk/cRMq6oV2suTsi FvHvBZnsNKr0qexdhfdMj9WqjQbbKKLZ6oPOpOQUZB695sRXsFvGsEnn9yFDiZaHrSgu eOYbCt7rVn5nd5HRHh4J/Mchh1Cjr7ba2fafsF64O3Ue+obbRe65PBpUAS7yzeJv3mBE kJOSA9WuYIYHC+LOs3Eyr3NVkA5X62kantH3m+ZHfcp2eyAogo8ETSmZA2YFxl8xNrAS fd1w== ARC-Authentication-Results: i=1; mx.google.com; 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 a23-v6si6601731pgv.429.2018.04.30.12.43.17; Mon, 30 Apr 2018 12:43:31 -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; 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 S1756452AbeD3Tmt (ORCPT + 99 others); Mon, 30 Apr 2018 15:42:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:36150 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756289AbeD3T21 (ORCPT ); Mon, 30 Apr 2018 15:28:27 -0400 Received: from localhost (unknown [104.132.1.102]) (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 4348322DCB; Mon, 30 Apr 2018 19:28:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4348322DCB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , Tejun Heo , Ming Lei , Martin Steigerwald , Jianchao Wang , Jens Axboe Subject: [PATCH 4.16 063/113] blk-mq: start request gstate with gen 1 Date: Mon, 30 Apr 2018 12:24:34 -0700 Message-Id: <20180430184017.887475593@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184015.043892819@linuxfoundation.org> References: <20180430184015.043892819@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jianchao Wang commit f4560231ec42092c6662acccabb28c6cac9f5dfb upstream. rq->gstate and rq->aborted_gstate both are zero before rqs are allocated. If we have a small timeout, when the timer fires, there could be rqs that are never allocated, and also there could be rq that has been allocated but not initialized and started. At the moment, the rq->gstate and rq->aborted_gstate both are 0, thus the blk_mq_terminate_expired will identify the rq is timed out and invoke .timeout early. For scsi, this will cause scsi_times_out to be invoked before the scsi_cmnd is not initialized, scsi_cmnd->device is still NULL at the moment, then we will get crash. Cc: Bart Van Assche Cc: Tejun Heo Cc: Ming Lei Cc: Martin Steigerwald Cc: stable@vger.kernel.org Signed-off-by: Jianchao Wang Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/blk-core.c | 4 ++++ block/blk-mq.c | 7 +++++++ 2 files changed, 11 insertions(+) --- a/block/blk-core.c +++ b/block/blk-core.c @@ -129,6 +129,10 @@ void blk_rq_init(struct request_queue *q rq->part = NULL; seqcount_init(&rq->gstate_seq); u64_stats_init(&rq->aborted_gstate_sync); + /* + * See comment of blk_mq_init_request + */ + WRITE_ONCE(rq->gstate, MQ_RQ_GEN_INC); } EXPORT_SYMBOL(blk_rq_init); --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2076,6 +2076,13 @@ static int blk_mq_init_request(struct bl seqcount_init(&rq->gstate_seq); u64_stats_init(&rq->aborted_gstate_sync); + /* + * start gstate with gen 1 instead of 0, otherwise it will be equal + * to aborted_gstate, and be identified timed out by + * blk_mq_terminate_expired. + */ + WRITE_ONCE(rq->gstate, MQ_RQ_GEN_INC); + return 0; }