From patchwork Thu Jan 17 00:27:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10767223 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 910E01390 for ; Thu, 17 Jan 2019 00:27:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 819542F869 for ; Thu, 17 Jan 2019 00:27:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 763222F8F0; Thu, 17 Jan 2019 00:27:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 032B82F869 for ; Thu, 17 Jan 2019 00:27:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728713AbfAQA1h (ORCPT ); Wed, 16 Jan 2019 19:27:37 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:59001 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728247AbfAQA1h (ORCPT ); Wed, 16 Jan 2019 19:27:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=xk8aMi586fKGg3XV8r593/dKqXC2GQwI1BWmFt16bjk=; b=qIZG26nJS5iu R0mBqRIpCk7isuQxxuQVoyjmPulsx2dN7zADScx1f2spwgI7XmKkpBEUyRskdhPHwM5BKb14bwCRZ jFFYUNcVQhF5x3/1y32URd/AKFiAxTMwWScDl3R4UPVj2ubOiBr2cOMsbGl+KBuV+UH3A88AwNNqJ QXb/DroWC7EV0S4uCEUUC42myw2DVoDKecxn5WoW/Q1UduTv3Jbpd2p3UbNIUsP4Wrfb0opK3YLiM oskP79mrSglhduerQ8eCtNQX+CmxWrXM7a0DNS5vSHrtJFlZDabdnD0q4UTBI8sZJsVukkRgFpgCm fcTNU8pG8FYF3qtQbu/icg==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gjvWu-0007EV-SU; Thu, 17 Jan 2019 01:27:33 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 0F3C8C088D; Thu, 17 Jan 2019 01:27:29 +0100 (CET) From: Bart Van Assche To: Jason Gunthorpe Cc: Doug Ledford , linux-rdma@vger.kernel.org, Bart Van Assche , Sergey Gorenko , Max Gurtovoy , Laurence Oberman , stable@vger.kernel.org Subject: [PATCH 2/2] RDMA/srp: Rework SCSI device reset handling Date: Wed, 16 Jan 2019 16:27:17 -0800 Message-Id: <20190117002717.84686-3-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190117002717.84686-1-bvanassche@acm.org> References: <20190117002717.84686-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outg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UNtTnccFhhwn2/Dj1pgXRdkG FXml68sVQdV8jHytZ27+31Y2za3muS2OYzrgPLHf0Rbu9udKEy7bP5gIt23U7fpAnNPRUBWWBSDR x5OeloKLHRs0g0z5EfZrz6E5xburfSl74HBEn95eECKi3gxjzXac2CIo7bSWHMwv14kxH53zEku4 6CxjyQf09M5rialBcVt4x9u3hHG5f/LZAZC2bUhjWf0= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since .scsi_done() must only be called after scsi_queue_rq() has finished, make sure that the SRP initiator driver does not call .scsi_done() while scsi_queue_rq() is in progress. Although invoking sg_reset -d while I/O is in progress works fine with kernel v4.20 and before, that is not the case with kernel v5.0-rc1. This patch avoids that the following crash is triggered with kernel v5.0-rc1: BUG: unable to handle kernel NULL pointer dereference at 0000000000000138 CPU: 0 PID: 360 Comm: kworker/0:1H Tainted: G B 5.0.0-rc1-dbg+ #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014 Workqueue: kblockd blk_mq_run_work_fn RIP: 0010:blk_mq_dispatch_rq_list+0x116/0xb10 Call Trace: blk_mq_sched_dispatch_requests+0x2f7/0x300 __blk_mq_run_hw_queue+0xd6/0x180 blk_mq_run_work_fn+0x27/0x30 process_one_work+0x4f1/0xa20 worker_thread+0x67/0x5b0 kthread+0x1cf/0x1f0 ret_from_fork+0x24/0x30 Cc: Sergey Gorenko Cc: Max Gurtovoy Cc: Laurence Oberman Cc: Fixes: 94a9174c630c ("IB/srp: reduce lock coverage of command completion") # v2.6.38 Signed-off-by: Bart Van Assche --- drivers/infiniband/ulp/srp/ib_srp.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c index 23e5c9afb8fb..f7ccbb07321b 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -3036,9 +3036,11 @@ static int srp_abort(struct scsi_cmnd *scmnd) static int srp_reset_device(struct scsi_cmnd *scmnd) { - struct srp_target_port *target = host_to_target(scmnd->device->host); + struct scsi_device *sdev = scmnd->device; + struct srp_target_port *target = host_to_target(sdev->host); struct srp_rdma_ch *ch; - int i, j; + struct request_queue *q = sdev->request_queue; + int time_left; u8 status; shost_printk(KERN_ERR, target->scsi_host, "SRP reset_device called\n"); @@ -3050,16 +3052,12 @@ static int srp_reset_device(struct scsi_cmnd *scmnd) if (status) return FAILED; - for (i = 0; i < target->ch_count; i++) { - ch = &target->ch[i]; - for (j = 0; j < target->req_ring_size; ++j) { - struct srp_request *req = &ch->req_ring[j]; - - srp_finish_req(ch, req, scmnd->device, DID_RESET << 16); - } - } + /* Check whether all requests have finished. */ + blk_freeze_queue_start(q); + time_left = blk_mq_freeze_queue_wait_timeout(q, 1 * HZ); + blk_mq_unfreeze_queue(q); - return SUCCESS; + return time_left > 0 ? SUCCESS : FAILED; } static int srp_reset_host(struct scsi_cmnd *scmnd)