Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp225475img; Thu, 21 Mar 2019 18:34:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqx1XgDXc/wwqSYzI2m3fjJMnxnDTED32vlffhVx3urBsKRDZ7OApVYCkzPqV7OrLeV7IAkw X-Received: by 2002:a17:902:ba8c:: with SMTP id k12mr6847390pls.193.1553218483867; Thu, 21 Mar 2019 18:34:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553218483; cv=none; d=google.com; s=arc-20160816; b=v2mCz3UUVB5HDeR+mKCFxGwMJF4HXqZwtAFOiTtsaOGtxO8vEV4n6MjvlSKvn6eVWe dL3D3PWwerBlAHy3bgYUxnwm2Hgp4B3pILCbRzIPp3U6U4Yo82DMdAtJaquzpjJIIyLX sHP39XK3x2rZdyAP2aQnWuH94wt/9MTyzi8V0MB5Ef/GmBOUKfDuHFTKfkft5ZVlfDGA WuXIq2JqUKMU3x46YhXSWiV4eyYxtSmvq0+tEHTWxQMTB/ETXKblPiC4J7hCcRPyN6Zz /OLNq1oy5HbHAJPwV2Re5yJwZlVjyQ8SJkwkNZlvdtHLxkTSeiIEa4t1z74aQPM3whBS TwPA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=rPNe7zJivbRfyiuf6ad8qyPDaYBRC871h2UIBIM/fZU=; b=RGTFOVBArrY5GBshC+fjGOEBDL0mCIeuX39lyipxBH3KqEbO2elM5qFCLiTD81w4Oy nJpRL342AR5nk/DD0exkQ/04cIn/0nw284N6ZkjKeLdWUSXWEJnkga/PsCPRMe/fyY9K gJ24MPiBgGS0D2JBW2GehHwJC+mh52T7j9zP/CWxXETPVQwpuRhQUemoRzpkTayxS6sq OgeHqRix8n5lD41u7vWjKVUpACFFAv9xStnRiirx7w1NgUwLeNuqzzwBTRcaSKZzfTEW I+BGbGjmVZgq7gvFbe1dTjr1mTjQpLFYy1YLjONa78GiIdQXr1Pco/GfvpdpFYq4zQ6G clxA== 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 k7si5550063pfb.69.2019.03.21.18.34.26; Thu, 21 Mar 2019 18:34:43 -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 S1727554AbfCVBdP (ORCPT + 99 others); Thu, 21 Mar 2019 21:33:15 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:34378 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727397AbfCVBdP (ORCPT ); Thu, 21 Mar 2019 21:33:15 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id DC447D9B7003816B4A18; Fri, 22 Mar 2019 09:33:06 +0800 (CST) Received: from [127.0.0.1] (10.177.96.203) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.408.0; Fri, 22 Mar 2019 09:33:01 +0800 Subject: Re: [RFC PATCH v2] scsi: fix oops in scsi_uninit_cmd() To: Bart Van Assche , , CC: , , , , References: <20190316020905.14962-1-yanaijie@huawei.com> <1553193542.65329.119.camel@acm.org> From: Jason Yan Message-ID: Date: Fri, 22 Mar 2019 09:33:01 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: <1553193542.65329.119.camel@acm.org> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.177.96.203] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/3/22 2:39, Bart Van Assche wrote: > On Sat, 2019-03-16 at 10:09 +0800, 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: >> >> Unable to handle kernel NULL pointer dereference at virtual address >> 0000000000000000 >> s/sync.c:67, func=xfer, error=In[11347.116050] Mem abort info: >> put/output error >> [11347.121598] ESR = 0x96000006 >> [11347.126200] Exception class = DABT (current EL), IL = 32 bits >> [11347.132117] SET = 0, FnV = 0 >> [11347.135170] EA = 0, S1PTW = 0 >> [11347.138308] Data abort info: >> [11347.141186] ISV = 0, ISS = 0x00000006 >> [11347.145019] CM = 0, WnR = 0 >> [11347.147977] user pgtable: 4k pages, 48-bit VAs, pgdp = >> 00000000a67aece2 >> [11347.154591] [0000000000000000] pgd=0000002f90774003, >> pud=0000002fab098003, pmd=0000000000000000 >> [11347.163304] Internal error: Oops: 96000006 [#1] PREEMPT SMP >> [11347.168870] Modules linked in: hisi_sas_v3_hw hisi_sas_main libsas >> [11347.175044] CPU: 56 PID: 4294 Comm: scsi_eh_2 Not tainted >> 4.19.0-g8052059-dirty #2 >> [11347.182600] Hardware name: Huawei D06/D06, BIOS Hisilicon D06 UEFI >> RC0 - B601 (V6.01) 11/08/2018 >> [11347.191370] pstate: a0c00009 (NzCv daif 㰃繐ε흾㯗 > > Please verify whether the following patch is a valid alternative for your patch: > Thanks Bart, I will verify it later. > diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c > index ed34bfbc3844..745ffdda1bc1 100644 > --- a/drivers/scsi/sd.c > +++ b/drivers/scsi/sd.c > @@ -1408,6 +1408,7 @@ static void sd_release(struct gendisk *disk, fmode_t mode) > { > struct scsi_disk *sdkp = scsi_disk(disk); > struct scsi_device *sdev = sdkp->device; > + struct request_queue *q = sdkp->disk->queue; > > SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp, "sd_release\n")); > > @@ -1417,9 +1418,12 @@ static void sd_release(struct gendisk *disk, fmode_t mode) > } > > /* > - * XXX and what if there are packets in flight and this close() > - * XXX is followed by a "rmmod sd_mod"? > + * Wait until any requests that are in progress have completed. > + * This is necessary to avoid that e.g. scsi_end_request() crashes > + * due to scsi_disk_relase() clearing the disk->private_data pointer. > */ > + blk_mq_freeze_queue(q); > + blk_mq_unfreeze_queue(q); > > scsi_disk_put(sdkp); > } > > Thanks, > > Bart. > > . >