Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp463625ybl; Wed, 11 Dec 2019 22:37:53 -0800 (PST) X-Google-Smtp-Source: APXvYqz3Cz1CZgSFiIYGgU5IZvEIS6MFJYpYuFJBJg6Gt2hQnkUzHVIkXwjxih+Ys2T5Mi9EgnAg X-Received: by 2002:a05:6830:1097:: with SMTP id y23mr6280595oto.332.1576132673735; Wed, 11 Dec 2019 22:37:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576132673; cv=none; d=google.com; s=arc-20160816; b=vB9jqlvmajGxa23PbRZrim46EvQ3DvkM/i0KdtxGGD0MF4zWCNmpEOOcBaU2FOzrpk +SDoJLZyF/9scF/F90vfjqzoTLI7xQ3/rp7/p44DBLfrg+qTBvRcjaHvS3J0XPaYCWUD MMyORXMGLzF1nvVl9FMTI+fSBEOGjL4KUA0vAhxmdvg5ST9AGiR/r5oWv4hzxoFggSvM he0A6w+b1Fusgsi+cqiqbJv7/MD4JmXuv/33QMiFe+242gQb+XluG+5yV3VgdHs3GEAZ OPP1Dlb7LcUAVar0ugIKyMteqBbjiVkjPnENn0nOMkTDSI88cuOl2G3tUtFM5VoONECU ifMw== 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:dkim-signature; bh=qJp6QFI/CXEddS3idgQBebU9+9D7IVQwILWfO+wS9zI=; b=ieuIeQcaBwS/D3E+SS3G7Lmack9RkzFaUegejdHsHJGZXlv5f8+dl69JTLBaqGycZj yw2Xfa6l64+IUQ2IPaNh9aUO48MjbYJcis3fO5bWzTgat0Cf/v15n4qwiAlT+kVmuBFG 6zymkrtDmWmv+xnPZlhHEqKScCsD+hPbTgbpOm7ReQ3xwjD/bsQtPzrCI+VvQrA+3N5d dC6YjUvN4jmPt7JlT+Mat9aB6fboQL6ZnftZifNe5BpduUb8GnN/Xl4zjREYHMmI9zOl FHc2IGNwYrB+d2iCZuOLQGX+SN4JxvG/hCVYPykiG8AEOn5GDbvIuI0E3+PwhWW5Zf2J haQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QX1Xjhjn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a10si2577262oia.232.2019.12.11.22.37.41; Wed, 11 Dec 2019 22:37:53 -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; dkim=pass header.i=@linaro.org header.s=google header.b=QX1Xjhjn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728009AbfLLGhI (ORCPT + 99 others); Thu, 12 Dec 2019 01:37:08 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:39247 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727891AbfLLGhI (ORCPT ); Thu, 12 Dec 2019 01:37:08 -0500 Received: by mail-pg1-f195.google.com with SMTP id b137so617217pga.6 for ; Wed, 11 Dec 2019 22:37:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=qJp6QFI/CXEddS3idgQBebU9+9D7IVQwILWfO+wS9zI=; b=QX1Xjhjn8I2wfmu+GWGwW8HEiOcpLkpHHHXNAdpADCg1Mm2bQrTXLj97s/z6q2E464 fHmEbiYUnH2OT353KCO/jfAsrXm4vAZDoCx6qwv6XLRVT6qR4TsR9AUYRFFORANZOkrT NNPM/mH1w7Nk4e7e3iIxXjBsA++mGy0R5TD/mbWiE74UqAX4ZJ/xRqj2ijvX7DlngxHQ RAQSdPXjYq69FuvcW7KajIXQtx8aJLEYDpeJDiRW3tVpojVl2HHm/z3xorKArNHyqAuJ DBlZ8BAI85nNGMctOjtBMJKm0Uuk3Fl35CnM+PTSjNWJv0QXcQFPSf1U2eJWtFBoL3Tc 6Vdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=qJp6QFI/CXEddS3idgQBebU9+9D7IVQwILWfO+wS9zI=; b=LPdPMN2EhPs7neT4Cqnwmsjy6SjHtSEriMdw5MpmMvn/sgLDXtcjYQClCuKbW9DlA0 Rv/ONtL4HzncemTO9rTv4kuD/GqexF3wN/EBv5jUsEmaauvbwrd91ePALCmJC7nUgWfS XpsI9B5dV0H7pW9YkhahBFk+3o14Ksu/gJ3mFxyCzUXXvR0n0GC5zO2XeH0iRES8wU9p TOL1qobBJzhj1FLYbV66DW9Q70KfL37xsSoHiCn3hO4jncvI2CAMsTNHn8iqTm5SLfst 8xSXAoFEWeXYJLcAcmO+F5Q3tzrxQynEBp3NnlQ1UEIZ7T5kIYfsxgxz0NMFc9HDy69W evgw== X-Gm-Message-State: APjAAAXAacxkZjCnb9tIUtec7rQo7h0CrjJTn5TLt1S1hTkEEtQxZVQS mZAuT5DzNe0jwhogoFKynsvxAA== X-Received: by 2002:a63:31cf:: with SMTP id x198mr8614969pgx.272.1576132627073; Wed, 11 Dec 2019 22:37:07 -0800 (PST) Received: from yoga (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id b22sm5421427pfd.63.2019.12.11.22.37.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 22:37:06 -0800 (PST) Date: Wed, 11 Dec 2019 22:37:03 -0800 From: Bjorn Andersson To: cang@codeaurora.org Cc: asutoshd@codeaurora.org, nguyenb@codeaurora.org, rnayak@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, saravanak@google.com, salyzyn@google.com, Alim Akhtar , Avri Altman , Pedro Sousa , "James E.J. Bottomley" , "Martin K. Petersen" , Evan Green , Kishon Vijay Abraham I , Stephen Boyd , Stanley Chu , Vignesh Raghavendra , Bean Huo , Bart Van Assche , Venkat Gopalakrishnan , Tomas Winkler , Arnd Bergmann , open list Subject: Re: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg Message-ID: <20191212063703.GC415177@yoga> References: <1576054123-16417-1-git-send-email-cang@codeaurora.org> <0101016ef425ef65-5c4508cc-5e76-4107-bb27-270f66acaa9a-000000@us-west-2.amazonses.com> <20191212045357.GA415177@yoga> <0101016ef8b2e2f8-72260b08-e6ad-42fc-bd4b-4a0a72c5c9b3-000000@us-west-2.amazonses.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0101016ef8b2e2f8-72260b08-e6ad-42fc-bd4b-4a0a72c5c9b3-000000@us-west-2.amazonses.com> User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 11 Dec 22:01 PST 2019, cang@codeaurora.org wrote: > On 2019-12-12 12:53, Bjorn Andersson wrote: > > On Wed 11 Dec 00:49 PST 2019, Can Guo wrote: > > > > > In order to improve the flexibility of ufs-bsg, modulizing it is a > > > good > > > choice. This change introduces tristate to ufs-bsg to allow users > > > compile > > > it as an external module. > > > > Can you please elaborate on what this "flexibility" is and why it's a > > good thing? > > > > ufs-bsg is a helpful gadget for debug/test purpose. But neither > disabling it nor enabling it is the best way on a commercialized > device. Disabling it means we cannot use it, while enabling it > by default will expose all the DEVM/UIC/TM interfaces to user space, > which is not "safe" on a commercialized device to let users play with it. > Making it a module can resolve this, because only vendors can install it > as they have the root permissions. > > > > > > > Signed-off-by: Can Guo > > > --- > > > drivers/scsi/ufs/Kconfig | 3 ++- > > > drivers/scsi/ufs/Makefile | 2 +- > > > drivers/scsi/ufs/ufs_bsg.c | 49 > > > +++++++++++++++++++++++++++++++++++++++++++--- > > > drivers/scsi/ufs/ufs_bsg.h | 8 -------- > > > drivers/scsi/ufs/ufshcd.c | 36 ++++++++++++++++++++++++++++++---- > > > drivers/scsi/ufs/ufshcd.h | 7 ++++++- > > > 6 files changed, 87 insertions(+), 18 deletions(-) > > > > > > diff --git a/drivers/scsi/ufs/Kconfig b/drivers/scsi/ufs/Kconfig > > > index d14c224..72620ce 100644 > > > --- a/drivers/scsi/ufs/Kconfig > > > +++ b/drivers/scsi/ufs/Kconfig > > > @@ -38,6 +38,7 @@ config SCSI_UFSHCD > > > select PM_DEVFREQ > > > select DEVFREQ_GOV_SIMPLE_ONDEMAND > > > select NLS > > > + select BLK_DEV_BSGLIB > > > > Why is this needed? > > > > Because ufshcd.c needs to call some funcs defined in bsg lib. > > > > ---help--- > > > This selects the support for UFS devices in Linux, say Y and make > > > sure that you know the name of your UFS host adapter (the card > > > @@ -143,7 +144,7 @@ config SCSI_UFS_TI_J721E > > > If unsure, say N. > > > > > > config SCSI_UFS_BSG > > > - bool "Universal Flash Storage BSG device node" > > > + tristate "Universal Flash Storage BSG device node" > > > depends on SCSI_UFSHCD > > > select BLK_DEV_BSGLIB > > > help > > > diff --git a/drivers/scsi/ufs/Makefile b/drivers/scsi/ufs/Makefile > > > index 94c6c5d..904eff1 100644 > > > --- a/drivers/scsi/ufs/Makefile > > > +++ b/drivers/scsi/ufs/Makefile > > > @@ -6,7 +6,7 @@ obj-$(CONFIG_SCSI_UFS_CDNS_PLATFORM) += cdns-pltfrm.o > > > obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o > > > obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o > > > ufshcd-core-y += ufshcd.o ufs-sysfs.o > > > -ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o > > > +obj-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o > > > obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o > > > obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o > > > obj-$(CONFIG_SCSI_UFS_HISI) += ufs-hisi.o > > > diff --git a/drivers/scsi/ufs/ufs_bsg.c b/drivers/scsi/ufs/ufs_bsg.c > > > index 3a2e68f..302222f 100644 > > > --- a/drivers/scsi/ufs/ufs_bsg.c > > > +++ b/drivers/scsi/ufs/ufs_bsg.c > > > @@ -164,13 +164,15 @@ static int ufs_bsg_request(struct bsg_job *job) > > > */ > > > void ufs_bsg_remove(struct ufs_hba *hba) > > > { > > > - struct device *bsg_dev = &hba->bsg_dev; > > > + struct device *bsg_dev = hba->bsg_dev; > > > > > > if (!hba->bsg_queue) > > > return; > > > > > > bsg_remove_queue(hba->bsg_queue); > > > > > > + hba->bsg_dev = NULL; > > > + hba->bsg_queue = NULL; > > > device_del(bsg_dev); > > > put_device(bsg_dev); > > > } > > > @@ -178,6 +180,7 @@ void ufs_bsg_remove(struct ufs_hba *hba) > > > static inline void ufs_bsg_node_release(struct device *dev) > > > { > > > put_device(dev->parent); > > > + kfree(dev); > > > } > > > > > > /** > > > @@ -186,14 +189,19 @@ static inline void ufs_bsg_node_release(struct > > > device *dev) > > > * > > > * Called during initial loading of the driver, and before > > > scsi_scan_host. > > > */ > > > -int ufs_bsg_probe(struct ufs_hba *hba) > > > +static int ufs_bsg_probe(struct ufs_hba *hba) > > > { > > > - struct device *bsg_dev = &hba->bsg_dev; > > > + struct device *bsg_dev; > > > struct Scsi_Host *shost = hba->host; > > > struct device *parent = &shost->shost_gendev; > > > struct request_queue *q; > > > int ret; > > > > > > + bsg_dev = kzalloc(sizeof(*bsg_dev), GFP_KERNEL); > > > + if (!bsg_dev) > > > + return -ENOMEM; > > > + > > > + hba->bsg_dev = bsg_dev; > > > device_initialize(bsg_dev); > > > > > > bsg_dev->parent = get_device(parent); > > > @@ -217,6 +225,41 @@ int ufs_bsg_probe(struct ufs_hba *hba) > > > > > > out: > > > dev_err(bsg_dev, "fail to initialize a bsg dev %d\n", > > > shost->host_no); > > > + hba->bsg_dev = NULL; > > > put_device(bsg_dev); > > > return ret; > > > } > > > + > > > +static int __init ufs_bsg_init(void) > > > +{ > > > + struct list_head *hba_list = NULL; > > > + struct ufs_hba *hba; > > > + int ret = 0; > > > + > > > + ufshcd_get_hba_list_lock(&hba_list); > > > + list_for_each_entry(hba, hba_list, list) { > > > + ret = ufs_bsg_probe(hba); > > > + if (ret) > > > + break; > > > + } > > > > So what happens if I go CONFIG_SCSI_UFS_BSG=y and > > CONFIG_SCSI_UFS_QCOM=y? > > > > Wouldn't that mean that ufs_bsg_init() is called before ufshcd_init() > > has added the controller to the list? And even in the even that they are > > both =m, what happens if they are invoked in the "wrong" order? > > > > In the case that CONFIG_SCSI_UFS_BSG=y and CONFIG_SCSI_UFS_QCOM=y, > I give late_initcall_sync(ufs_bsg_init) to make sure ufs_bsg_init > is invoked only after platform driver is probed. I tested this combination. > > In the case that both of them are "m", installing ufs-bsg before ufs-qcom > is installed would have no effect as ufs_hba_list is empty, which is > expected. Why is it the expected behavior that bsg may or may not probe depending on the driver load order and potentially timing of the initialization. > And in real cases, as the UFS is the boot device, UFS driver will always > be probed during bootup. > The UFS driver will load and probe because it's mentioned in the devicetree, but if either the ufs drivers or any of its dependencies (phy, resets, clocks, etc) are built as modules it might very well finish probing after lateinitcall. So in the even that the bsg is =y and any of these drivers are =m, or if you're having bad luck with your timing, the list will be empty. As described below, if bsg=m, then there's nothing that will load the module and the bsg will not probe... [..] > > > diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c [..] > > > void ufshcd_remove(struct ufs_hba *hba) > > > { > > > - ufs_bsg_remove(hba); > > > + struct device *bsg_dev = hba->bsg_dev; > > > + > > > + mutex_lock(&ufs_hba_list_lock); > > > + list_del(&hba->list); > > > + if (hba->bsg_queue) { > > > + bsg_remove_queue(hba->bsg_queue); > > > + device_del(bsg_dev); > > > > Am I reading this correct in that you probe the bsg_dev form initcall > > and you delete it as the ufshcd instance is removed? That's not okay. > > > > Regards, > > Bjorn > > > > If ufshcd is removed, its ufs-bsg, if exists, should also be removed. > Could you please enlighten me a better way to do this? Thanks. > It's the asymmetry that I don't like. Perhaps if you instead make ufshcd platform_device_register_data() the bsg device you would solve the probe ordering, the remove will be symmetric and module autoloading will work as well (although then you need a MODULE_ALIAS of platform:device-name). Regards, Bjorn