Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3384320imj; Tue, 19 Feb 2019 02:33:23 -0800 (PST) X-Google-Smtp-Source: AHgI3IbBuICEFU9mcQCpjD5KwnWkQ1VSJWwWvdYMyHSCLsBspPywnHJlRWRd6HH5IjxYYq2c/fSr X-Received: by 2002:a63:da45:: with SMTP id l5mr23525599pgj.111.1550572403822; Tue, 19 Feb 2019 02:33:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550572403; cv=none; d=google.com; s=arc-20160816; b=wX1N4y+K+5vlABB+ZdVhHXhlCMWzb7jwBDjTUCcs+Fpmecjo9hdxX7XLCZzYCk2CQh pQL2+qXSOIj0zpKOGNRK8NQrPkWLga7LvbBlXpFDPoSPf8YsjWbL7RZ79jkyQlHmvvWY G9G1joJWqLmqNLKsCJj6+we95xRec0yKPgGrdDokHnfYTpt40C/nj4LJe4g8XFVaKHBS xAQ/GvgeVwQVLMrCp8qQ7rLsF7YBlNXlRpGVg3kqGtoGKb/m1BQcIWdp9MRKwKlQwoWb 3fqu2OPpOAy9js/BQwCl3v+FeKiLbj2q/GfD8mMOwmFVFNqThgcVvNQVQkdj3okRitoS N9fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date:from :references:cc:to:subject; bh=fRPDoCkVkIMvUp/FZBBFZCwDsVtciuRzeIC6CDkiRhY=; b=BJ68hohDsQYOZTJCP6j1xcOZtFO99en6KQ2QPUgE7azrZAJ85xIOEsmjd78fslnCZe FOUC7Y3Jf+bXRw2FczUyVb3fnu40XTRpZ2lIqSGk2rQdymzlHrICB7Vn/P0LrytpOhxg tmj1ddOPRHvY7MXYvzwP6TBXNzHOz5EVMsGkv3ZCofy/s/pkPoowwkvB9i3ZV1pyC/xM 4I65/rK8zlVLmRIcIF80XLcepeyJsi3nsQRSYkZXEfn4j4DYfrdjhBNDmI59ZzLY6szN Axf9mBAk9SaeVAu4rn2OkNgb9tNfW0KUIr0JnaqqWRQIE9KWXxJaaCriZ6tGAU8Ctrs2 Wmcw== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q18si14009257pgh.116.2019.02.19.02.33.08; Tue, 19 Feb 2019 02:33:23 -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; 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728036AbfBSKcg (ORCPT + 99 others); Tue, 19 Feb 2019 05:32:36 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:37950 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726969AbfBSKcf (ORCPT ); Tue, 19 Feb 2019 05:32:35 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x1JAOQ42112381 for ; Tue, 19 Feb 2019 05:32:34 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 2qrd5tj95r-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 19 Feb 2019 05:32:33 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 19 Feb 2019 10:32:29 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 19 Feb 2019 10:32:26 -0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x1JAWPHN55181366 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Feb 2019 10:32:25 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D8A4BA405F; Tue, 19 Feb 2019 10:32:25 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 59E76A4054; Tue, 19 Feb 2019 10:32:25 +0000 (GMT) Received: from oc4120165700.ibm.com (unknown [9.152.99.189]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 19 Feb 2019 10:32:25 +0000 (GMT) Subject: Re: [RFC PATCH] scsi: fix oops in scsi_uninit_cmd() To: Jason Yan , martin.petersen@oracle.com, jejb@linux.vnet.ibm.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, hare@suse.com, dan.j.williams@intel.com, jthumshirn@suse.de, hch@lst.de References: <20190219072743.13606-1-yanaijie@huawei.com> From: Steffen Maier Date: Tue, 19 Feb 2019 11:32:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190219072743.13606-1-yanaijie@huawei.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 19021910-0012-0000-0000-000002F778F7 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19021910-0013-0000-0000-0000212F054D Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-02-19_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902190078 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/19/2019 08:27 AM, Jason Yan wrote: > If we remove the scsi disk when running io with fio, oops occured with > the following condition. > > [scsi_eh_0] [fio] > scsi_end_request > ->blk_update_request > ->end_bio(io returned to userspace) > close > ->sd_release > ->scsi_disk_put > ->scsi_disk_release > ->disk->private_data = NULL; > > ->scsi_mq_uninit_cmd > ->scsi_uninit_cmd > ->scsi_cmd_to_driver > ->drv is NULL, Oops > > There is a small window between blk_update_request() and > scsi_mq_uninit_cmd() that scsi disk may have been released. This will > cause a oops like below: > To fix this, get a refcount of scsi_disk in sd_init_command() to ensure > it will not be released before sd_uninit_command(). > > Signed-off-by: Jason Yan > --- > drivers/scsi/sd.c | 46 +++++++++++++++++++++++++++++++++++----------- > 1 file changed, 35 insertions(+), 11 deletions(-) > > diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c > index 5464d467e23e..6bdb8fbb570f 100644 > --- a/drivers/scsi/sd.c > +++ b/drivers/scsi/sd.c > @@ -1249,42 +1249,64 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) > static blk_status_t sd_init_command(struct scsi_cmnd *cmd) > { > struct request *rq = cmd->request; > + struct scsi_disk *sdkp = NULL; This pre-init with NULL kinda prevents static compile warnings on uninitialized use? > + blk_status_t ret; > > switch (req_op(rq)) { > } > + > + if (!ret) { > + sdkp = scsi_disk(rq->rq_disk); > + get_device(&sdkp->dev); > + } > + > + return ret; > } > > static void sd_uninit_command(struct scsi_cmnd *SCpnt) > { > struct request *rq = SCpnt->request; > u8 *cmnd; > + struct scsi_disk *sdkp = NULL; dito > > if (rq->rq_flags & RQF_SPECIAL_PAYLOAD) > mempool_free(rq->special_vec.bv_page, sd_page_pool); > @@ -1295,6 +1317,8 @@ static void sd_uninit_command(struct scsi_cmnd *SCpnt) > SCpnt->cmd_len = 0; > mempool_free(cmnd, sd_cdb_pool); > } > + sdkp = scsi_disk(rq->rq_disk); > + put_device(&sdkp->dev); > } > > /** > -- Mit freundlichen Gruessen / Kind regards Steffen Maier Linux on IBM Z Development https://www.ibm.com/privacy/us/en/ IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Matthias Hartmann Geschaeftsfuehrung: Dirk Wittkopp Sitz der Gesellschaft: Boeblingen Registergericht: Amtsgericht Stuttgart, HRB 243294