Received: by 10.192.165.148 with SMTP id m20csp2128387imm; Sun, 22 Apr 2018 00:49:52 -0700 (PDT) X-Google-Smtp-Source: AIpwx48nWsEwgezMsJTqk9dnPTg1Ao/Ai9OZcgLcmzGeeunoViAk2jx+bOq7CLrR326o4H4dG2M6 X-Received: by 2002:a17:902:aa03:: with SMTP id be3-v6mr15930705plb.299.1524383392337; Sun, 22 Apr 2018 00:49:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524383392; cv=none; d=google.com; s=arc-20160816; b=H4kaGS1V/gubzxQG7Fh8wO9fx1s4037BpNPvExJGfZiXYZQ7nLWLs9DEQhiCL7gCyu 4OUlhja3C0Fm3eN/DBDbeMiRqc2DVUKsgt5dxTZgrUcXTIcZbGV264vuxX/Xt171Sgq2 OSUHf6iBYXWdG0k0grAA4ujcLvpql4j334cpUTh1KrgfXsxT3Ti81UMuTWI2oiU7jHiq fLvdID9zen1wzkc/Axu5xBMpFxi5z2AgJj0Op3NRBQQvvnMNBXaxbNWTsca2UmY3yT/F gFLc1b6RkJui26fqC8dSGfofSjLTdiZ1ZHIufNAR9sLbOIZfscrCyHSsyGi0fi14OcqT Mq9g== 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:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature:arc-authentication-results; bh=WE1GfN2fcBZY0zCQa6mqVpQ/NOMQtxVrT+1a1/a6XpQ=; b=o+iw4k9z/wCDGUCD9FlJUcqxH1uuQwyBvGfGN7nj0/51S0aWXXilKQMtaMObWj5StO 0dZCBhJfmYsmxFUMoSxMtoLJtDaYlYcg2EQj2xOABf1Ts2/iOR7vnNEk+ST3z9zXclyV 7tKOVl9YJ6L+IYy5jO3DPapSSWEXcgchTNYhQd+zgSV9mOysfjOO/e1jWiS5abY5Y7bo 91fX98Kdt/cQKs1McWdt9KQyp6qkFYvKFN+zEUPI+X6zGgUSb6F3kG5k4mbXYdiXib1X Au+PPbOlWPyA9PRo8fCMuC1aDVWMUUKH2u8vTUe/Gu4ruYZ1G+OhrFTOObFOjdUi9FSI HUJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=nGB52N9R; 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=hansenpartnership.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n13si8572683pfg.227.2018.04.22.00.49.37; Sun, 22 Apr 2018 00:49:52 -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; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=nGB52N9R; 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=hansenpartnership.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751567AbeDVHsS (ORCPT + 99 others); Sun, 22 Apr 2018 03:48:18 -0400 Received: from bedivere.hansenpartnership.com ([66.63.167.143]:39470 "EHLO bedivere.hansenpartnership.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750826AbeDVHsR (ORCPT ); Sun, 22 Apr 2018 03:48:17 -0400 Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id 846788EE293; Sun, 22 Apr 2018 00:48:16 -0700 (PDT) Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mrB6yD9OLZrO; Sun, 22 Apr 2018 00:48:16 -0700 (PDT) Received: from [192.168.40.139] (unknown [80.169.201.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id ED7428EE062; Sun, 22 Apr 2018 00:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1524383296; bh=VDerws/3ODlS9bN+VV6iSgfXGCFPUGee3qqKl6DLj1s=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=nGB52N9R3ZzT5elfYG2soJ5BKQKNpJneRIbHIY0OLlf6tdKkSBuOJm8Oq7SRG9I0u O7cUz6onyF6+qf12+wSJiwMQuwlVIazkIbYwDX3fY4jJ4/cX3ZuZhNoQfLzqZRfGZS EHS43VyhIiX61tE+Z72/bXuFWYmm31vLuHs9AJlY= Message-ID: <1524383279.3389.7.camel@HansenPartnership.com> Subject: Re: [PATCH] bsg referencing bus driver module From: James Bottomley To: Anatoliy Glagolev Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, axboe@kernel.dk, fujita.tomonori@lab.ntt.co.jp, martin.petersen@oracle.com, jthumshirn@suse.de, hare@suse.com, bblock@linux.vnet.ibm.com, linux-kernel@vger.kernel.org Date: Sun, 22 Apr 2018 08:47:59 +0100 In-Reply-To: <20180420224404.GC32372@xldev-tmpl.dev.purestorage.com> References: <1524218126.3321.6.camel@HansenPartnership.com> <20180420224404.GC32372@xldev-tmpl.dev.purestorage.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2018-04-20 at 16:44 -0600, Anatoliy Glagolev wrote: >   > > This patch isn't applyable because your mailer has changed all the > > tabs to spaces. > > > > I also think there's no need to do it this way.  I think what we > > need is for fc_bsg_remove() to wait until the bsg queue is > > drained.  It does look like the author thought this happened > > otherwise the code wouldn't have the note.  If we fix it that way > > we can do the same thing in all the other transport classes that > > use bsg (which all have a similar issue). > > > > James > > > > Thanks, James. Sorry about the tabs; re-sending. > > On fc_bsg_remove()...: are you suggesting to implement the whole fix > in scsi_transport_fc.c? Yes, but it's not just scsi_transport_fc, scsi_transport_sas has the same issue. I think it's probably just the one liner addition of blk_drain_queue() that fixes this. There should probably be a block primitive that does the correct queue reference dance and calls blk_cleanup_queue() and blk_drain_queue() in order. > That would be nice, but I do not see how that > is possible. Even with the queue drained bsg still holds a reference > to the Scsi_Host via bsg_class_device; bsg_class_device itself is > referenced on bsg_open and kept around while a user-mode process > keeps a handle to bsg. Once you've called bsg_unregister_queue(), the queue will be destroyed and the reference released once the last job is drained, meaning the user can keep the bsg device open, but it will just return errors because of the lack of queue. This scenario allows removal to proceed without being held hostage by open devices. > Even if we somehow implement the waiting the call may be stuck > forever if the user-mode process keeps the handle. No it won't: after blk_cleanup_queue(), the queue is in bypass mode: no requests queued after this do anything other than complete with error, so they never make it into SCSI. > I think handling it via a rererence to the module is more consistent > with the way things are done in Linux. You suggested the approach > youself back in "Waiting for scsi_host_template release" discussion. That was before I analyzed the code paths. Module release is tricky, because the module exit won't be called until the references drop to zero, so you have to be careful about not creating a situation where module exit never gets called and module exit code should force stuff to detach and wait for the forcing to complete to make up for the reference circularity problem. If you do it purely by refcounting, the module actually may never release (that's why scsi_remove_host works the way it does, for instance). James