Received: by 10.192.165.156 with SMTP id m28csp1419406imm; Mon, 16 Apr 2018 21:48:17 -0700 (PDT) X-Google-Smtp-Source: AIpwx48Zvok9FRJd54YWlU67gRJFag9Ps9S9F2A5MlQM5hZYUCuoGpgVVX8TIXBFxfBRtSSFzs31 X-Received: by 10.99.164.18 with SMTP id c18mr541125pgf.85.1523940497586; Mon, 16 Apr 2018 21:48:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523940497; cv=none; d=google.com; s=arc-20160816; b=arDMN5aMJ6P+K8iu7860AWyMJAqlaMFbl1JgjQ7G9LmKg7oFuPZtb2uYn9nOXn5Ek6 iBf4ciDXEJwF2842B8OgqZsmVA6O2i64RXUiWGTX5SGVodILdEw4QQEr5Kg3BL7fjLAb OHtrkqQddeDi1B0RbJDbCA8ONek95uO7KAroIDNfnvFk32IAdfTzFYKHIr9e5EV1cZ7q FFEwymAenV98D7mnge0DSvzq9CDhPuCDp+p42sx/IcB2tyj6B96vuxsjgyeOA2nTyToG DiMPHnbgrvbRi7+0chgCV2a9gsW66aMTm+Jtst6csHPo9wFDrYWSiDt0N3Uo7SkACRYZ hmMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=eZme3vIdn27OHd3R5zaKCY1CaGZZjoastI5anpnDPxk=; b=WjYvd3wJVmziHgjyIHCgJh4n4kFTe2VL6Ox6P21KaDXUT9PtFzAGXfyPQaxvJk3Dj3 aNYW1uvCnq2COZn8dzHPkj+r8jX7SMpsU5pRgUsb4pHL1Lz9kHVvz+XK9PZ29kzafX77 1caUy6kluJY2IqaHjdJqd7x57GXp2xfzut+7QOAWRT7NjvYiP+uN026chpai/kgmk942 pLuGSlDDUJtVjJyKXpcak1XuR6YIA9swJjVv4tpfrbwIQZ2ERTR/XLayHJZj29FcU+t7 QbSfHqRQzREukp69E/ufrW/cFspmu76OFFb0EixJIHsZp65bZclaz/sJCmPanmFvhaug taMQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a1si4004367pgq.594.2018.04.16.21.48.02; Mon, 16 Apr 2018 21:48:17 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751210AbeDQEq0 (ORCPT + 99 others); Tue, 17 Apr 2018 00:46:26 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43194 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750744AbeDQEqZ (ORCPT ); Tue, 17 Apr 2018 00:46:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A17F67D843; Tue, 17 Apr 2018 04:46:24 +0000 (UTC) Received: from ming.t460p (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 646067C2D; Tue, 17 Apr 2018 04:46:13 +0000 (UTC) Date: Tue, 17 Apr 2018 12:46:08 +0800 From: Ming Lei To: Jianchao Wang Cc: axboe@kernel.dk, bart.vanassche@wdc.com, tj@kernel.org, Martin@Lichtvoll.de, stable@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] blk-mq: start request gstate with gen 1 Message-ID: <20180417044603.GA16286@ming.t460p> References: <1523936780-1589-1-git-send-email-jianchao.w.wang@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1523936780-1589-1-git-send-email-jianchao.w.wang@oracle.com> User-Agent: Mutt/1.9.1 (2017-09-22) X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 17 Apr 2018 04:46:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 17 Apr 2018 04:46:24 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ming.lei@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 17, 2018 at 11:46:20AM +0800, Jianchao Wang wrote: > 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 > --- > block/blk-core.c | 4 ++++ > block/blk-mq.c | 7 +++++++ > 2 files changed, 11 insertions(+) > > diff --git a/block/blk-core.c b/block/blk-core.c > index abcb868..ce62681 100644 > --- a/block/blk-core.c > +++ b/block/blk-core.c > @@ -201,6 +201,10 @@ void blk_rq_init(struct request_queue *q, struct request *rq) > 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); > > diff --git a/block/blk-mq.c b/block/blk-mq.c > index f5c7dbc..d62030a 100644 > --- a/block/blk-mq.c > +++ b/block/blk-mq.c > @@ -2069,6 +2069,13 @@ static int blk_mq_init_request(struct blk_mq_tag_set *set, struct request *rq, > > 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; > } Good catch, blk_mq_check_expired() is bypassed, but it is still hit by blk_mq_terminate_expired(). Reviewed-by: Ming Lei -- Ming