linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: ufs: make sure scan sequence for multiple hosts
       [not found] <CGME20201020070519epcas2p27906d7db7c74e45f2acf8243ec2eae1d@epcas2p2.samsung.com>
@ 2020-10-20  7:05 ` Chanho Park
  2020-10-21  3:15   ` Bart Van Assche
  0 siblings, 1 reply; 9+ messages in thread
From: Chanho Park @ 2020-10-20  7:05 UTC (permalink / raw)
  To: jejb, martin.petersen
  Cc: alim.akhtar, avri.altman, linux-scsi, linux-kernel, Chanho Park

By doing scan as asynchronous way, scsi device scannning can be out of
order execution. It is no problem if there is a ufs host but the scsi
device name of each host can be changed according to the scan sequences.

Ideal Case) host0 scan first
host0 will be started from /dev/sda
 -> /dev/sdb (BootLUN0 of host0)
 -> /dev/sdc (BootLUN1 of host1)
host1 will be started from /dev/sdd

This might be an ideal case and we can easily find the host device by
this mappinng.

However, Abnormal Case) host1 scan first,
host1 will be started from /dev/sda and host0 will be followed later.

To make sure the scan sequences according to the host, we can use a
bitmap which hosts are scanned and wait until previous hosts are
finished to scan.

Signed-off-by: Chanho Park <chanho61.park@samsung.com>
---
 drivers/scsi/ufs/ufshcd.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index b8f573a02713..1ced5996e988 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -13,6 +13,7 @@
 #include <linux/devfreq.h>
 #include <linux/nls.h>
 #include <linux/of.h>
+#include <linux/bitmap.h>
 #include <linux/bitfield.h>
 #include <linux/blk-pm.h>
 #include <linux/blkdev.h>
@@ -214,6 +215,10 @@ static struct ufs_dev_fix ufs_fixups[] = {
 	END_FIX
 };
 
+/* Ordered scan host */
+static unsigned long scanned_hosts = 0;
+static wait_queue_head_t scan_wq = __WAIT_QUEUE_HEAD_INITIALIZER(scan_wq);
+
 static irqreturn_t ufshcd_tmc_handler(struct ufs_hba *hba);
 static void ufshcd_async_scan(void *data, async_cookie_t cookie);
 static int ufshcd_reset_and_restore(struct ufs_hba *hba);
@@ -7709,8 +7714,13 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)
 	if (ret)
 		goto out;
 
-	/* Probe and add UFS logical units  */
+	/* Probe and add UFS logical units. Sequential scan by host_no */
+	wait_event(scan_wq,
+		   find_first_zero_bit(&scanned_hosts, hba->host->max_id) ==
+		   hba->host->host_no);
 	ret = ufshcd_add_lus(hba);
+	set_bit(hba->host->host_no, &scanned_hosts);
+	wake_up(&scan_wq);
 out:
 	/*
 	 * If we failed to initialize the device or the device is not
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] scsi: ufs: make sure scan sequence for multiple hosts
  2020-10-20  7:05 ` [PATCH] scsi: ufs: make sure scan sequence for multiple hosts Chanho Park
@ 2020-10-21  3:15   ` Bart Van Assche
  2020-10-21  4:23     ` chanho61.park
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Van Assche @ 2020-10-21  3:15 UTC (permalink / raw)
  To: Chanho Park, jejb, martin.petersen
  Cc: alim.akhtar, avri.altman, linux-scsi, linux-kernel

On 10/20/20 12:05 AM, Chanho Park wrote:
> By doing scan as asynchronous way, scsi device scannning can be out of
> order execution. It is no problem if there is a ufs host but the scsi
> device name of each host can be changed according to the scan sequences.
> 
> Ideal Case) host0 scan first
> host0 will be started from /dev/sda
>  -> /dev/sdb (BootLUN0 of host0)
>  -> /dev/sdc (BootLUN1 of host1)
> host1 will be started from /dev/sdd
> 
> This might be an ideal case and we can easily find the host device by
> this mappinng.
> 
> However, Abnormal Case) host1 scan first,
> host1 will be started from /dev/sda and host0 will be followed later.
> 
> To make sure the scan sequences according to the host, we can use a
> bitmap which hosts are scanned and wait until previous hosts are
> finished to scan.

This sounds completely wrong to me. No code should depend on the order in
which LUNs are scanned. Please use the soft links created by udev instead
of serializing LUN scanning.

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH] scsi: ufs: make sure scan sequence for multiple hosts
  2020-10-21  3:15   ` Bart Van Assche
@ 2020-10-21  4:23     ` chanho61.park
  2020-10-22  0:29       ` Bart Van Assche
  0 siblings, 1 reply; 9+ messages in thread
From: chanho61.park @ 2020-10-21  4:23 UTC (permalink / raw)
  To: 'Bart Van Assche', jejb, martin.petersen
  Cc: alim.akhtar, avri.altman, linux-scsi, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1927 bytes --]

Hi,

> -----Original Message-----
> From: Bart Van Assche <bvanassche@acm.org>
> Sent: Wednesday, October 21, 2020 12:15 PM
> To: Chanho Park <chanho61.park@samsung.com>; jejb@linux.ibm.com;
> martin.petersen@oracle.com
> Cc: alim.akhtar@samsung.com; avri.altman@wdc.com; linux-
> scsi@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] scsi: ufs: make sure scan sequence for multiple
hosts
> 
> On 10/20/20 12:05 AM, Chanho Park wrote:
> > By doing scan as asynchronous way, scsi device scannning can be out of
> > order execution. It is no problem if there is a ufs host but the scsi
> > device name of each host can be changed according to the scan
sequences.
> >
> > Ideal Case) host0 scan first
> > host0 will be started from /dev/sda
> >  -> /dev/sdb (BootLUN0 of host0)
> >  -> /dev/sdc (BootLUN1 of host1)
> > host1 will be started from /dev/sdd
> >
> > This might be an ideal case and we can easily find the host device by
> > this mappinng.
> >
> > However, Abnormal Case) host1 scan first,
> > host1 will be started from /dev/sda and host0 will be followed later.
> >
> > To make sure the scan sequences according to the host, we can use a
> > bitmap which hosts are scanned and wait until previous hosts are
> > finished to scan.
> 
> This sounds completely wrong to me. No code should depend on the order in
> which LUNs are scanned. Please use the soft links created by udev instead
> of serializing LUN scanning.
> 

Thanks for your review.
Did you mean /dev/disk/by-[part]label/ symlink? It's quite reasonable to
use them by udev in userspace such as initramfs but some cases does not use
initramfs or initrd. In that case, we need to load the root
device(/dev/sda[N]) directly from kernel.
Anyway, scsi disk(sd) case, the scan order will not be changed until the
port has changed so they'll have permanent device names. I'd like to make
permanent UFS device names.

Best Regards,
Chanho Park

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 2630 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] scsi: ufs: make sure scan sequence for multiple hosts
  2020-10-21  4:23     ` chanho61.park
@ 2020-10-22  0:29       ` Bart Van Assche
  2020-10-22  4:59         ` Chanho Park
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Van Assche @ 2020-10-22  0:29 UTC (permalink / raw)
  To: chanho61.park, jejb, martin.petersen
  Cc: alim.akhtar, avri.altman, linux-scsi, linux-kernel

On 10/20/20 9:23 PM, chanho61.park wrote:
> Did you mean /dev/disk/by-[part]label/ symlink? It's quite reasonable to
> use them by udev in userspace such as initramfs but some cases does not use
> initramfs or initrd. In that case, we need to load the root
> device(/dev/sda[N]) directly from kernel.

Please use udev or systemd instead of adding code in the UFS driver that is
not necessary when udev or systemd is used.

Thanks,

Bart.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH] scsi: ufs: make sure scan sequence for multiple hosts
  2020-10-22  0:29       ` Bart Van Assche
@ 2020-10-22  4:59         ` Chanho Park
  2020-10-22  6:52           ` Avri Altman
  2020-10-23 15:27           ` Bart Van Assche
  0 siblings, 2 replies; 9+ messages in thread
From: Chanho Park @ 2020-10-22  4:59 UTC (permalink / raw)
  To: 'Bart Van Assche', jejb, martin.petersen
  Cc: alim.akhtar, avri.altman, linux-scsi, linux-kernel

> > Did you mean /dev/disk/by-[part]label/ symlink? It's quite reasonable to
> > use them by udev in userspace such as initramfs but some cases does not
> use
> > initramfs or initrd. In that case, we need to load the root
> > device(/dev/sda[N]) directly from kernel.
> 
> Please use udev or systemd instead of adding code in the UFS driver that
> is
> not necessary when udev or systemd is used.
>

What I mentioned was how it can be handled when we mount rootfs directly from kernel.

1) kernel -> initramfs (mount root) -> systemd
2) kernel (mount root) -> systemd
 -> In this case, we normally use root=/dev/sda1 from kernel commandline to mount the rootfs.

Like fstab can support legacy node mount, ufs driver also needs to provide an option for using the permanent legacy node. If you're really worry about adding a new codes for all UFS driver, we can put this as controller specific or optional feature.

Best Regards,
Chanho Park


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH] scsi: ufs: make sure scan sequence for multiple hosts
  2020-10-22  4:59         ` Chanho Park
@ 2020-10-22  6:52           ` Avri Altman
  2020-10-26 11:20             ` Chanho Park
  2020-10-23 15:27           ` Bart Van Assche
  1 sibling, 1 reply; 9+ messages in thread
From: Avri Altman @ 2020-10-22  6:52 UTC (permalink / raw)
  To: Chanho Park, 'Bart Van Assche', jejb, martin.petersen
  Cc: alim.akhtar, linux-scsi, linux-kernel

> 
> > > Did you mean /dev/disk/by-[part]label/ symlink? It's quite reasonable to
> > > use them by udev in userspace such as initramfs but some cases does not
> > use
> > > initramfs or initrd. In that case, we need to load the root
> > > device(/dev/sda[N]) directly from kernel.
> >
> > Please use udev or systemd instead of adding code in the UFS driver that
> > is
> > not necessary when udev or systemd is used.
> >
> 
> What I mentioned was how it can be handled when we mount rootfs directly
> from kernel.
> 
> 1) kernel -> initramfs (mount root) -> systemd
> 2) kernel (mount root) -> systemd
>  -> In this case, we normally use root=/dev/sda1 from kernel commandline to
> mount the rootfs.
> 
> Like fstab can support legacy node mount, ufs driver also needs to provide an
> option for using the permanent legacy node. If you're really worry about adding
> a new codes for all UFS driver, we can put this as controller specific or optional
> feature.
In case you'll convince Bart that this code is needed, maybe use a IDA handle for that?

Thanks,
Avri

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] scsi: ufs: make sure scan sequence for multiple hosts
  2020-10-22  4:59         ` Chanho Park
  2020-10-22  6:52           ` Avri Altman
@ 2020-10-23 15:27           ` Bart Van Assche
  1 sibling, 0 replies; 9+ messages in thread
From: Bart Van Assche @ 2020-10-23 15:27 UTC (permalink / raw)
  To: Chanho Park, jejb, martin.petersen
  Cc: alim.akhtar, avri.altman, linux-scsi, linux-kernel

On 10/21/20 9:59 PM, Chanho Park wrote:
>> Please use udev or systemd instead of adding code in the UFS driver that
>> is
>> not necessary when udev or systemd is used.
>>
> 
> What I mentioned was how it can be handled when we mount rootfs directly from kernel.
> 
> 1) kernel -> initramfs (mount root) -> systemd
> 2) kernel (mount root) -> systemd
>   -> In this case, we normally use root=/dev/sda1 from kernel commandline to mount the rootfs.
> 
> Like fstab can support legacy node mount, ufs driver also needs to provide
> an option for using the permanent legacy node. If you're really worry about > adding a new codes for all UFS driver, we can put this as controller specific> or optional feature.

The only code that should occur in the UFS driver is code that is specific
to UFS devices. Since the functionality in this patch is not UFS specific,
it should be added elsewhere.

Additionally, since this functionality can be implemented easily in user
space, I think it should be implemented in user space instead of in the
kernel. Even when not using systemd or udev, it is easy to implement a loop
that waits until a certain LUN or WWID appears.

Bart.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH] scsi: ufs: make sure scan sequence for multiple hosts
  2020-10-22  6:52           ` Avri Altman
@ 2020-10-26 11:20             ` Chanho Park
  0 siblings, 0 replies; 9+ messages in thread
From: Chanho Park @ 2020-10-26 11:20 UTC (permalink / raw)
  To: 'Avri Altman', 'Bart Van Assche', jejb, martin.petersen
  Cc: alim.akhtar, linux-scsi, linux-kernel

> In case you'll convince Bart that this code is needed, maybe use a IDA
> handle for that?

Thanks for your suggestion.
IDA is useful to maintain unique IDs with bitmap structure but the patch assumes host_no is the unique number and can be used in the bitmap for making sequential order.

Best Regards,
Chanho Park


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] scsi: ufs: make sure scan sequence for multiple hosts
       [not found] <CGME20201020084429epcas2p3685bcb89c3ab1cacefb183384dcb2b6e@epcas2p3.samsung.com>
@ 2020-10-20  8:44 ` Chanho Park
  0 siblings, 0 replies; 9+ messages in thread
From: Chanho Park @ 2020-10-20  8:44 UTC (permalink / raw)
  To: jejb, martin.petersen
  Cc: alim.akhtar, avri.altman, linux-scsi, linux-kernel, Chanho Park

By doing scan as asynchronous way, scsi device scannning can be out of
order execution. It is no problem if there is a ufs host but the scsi
device name of each host can be changed according to the scan sequences.

Ideal Case) host0 scan first
host0 will be started from /dev/sda
 -> /dev/sdb (BootLUN0 of host0)
 -> /dev/sdc (BootLUN1 of host1)
host1 will be started from /dev/sdd

This might be an ideal case and we can easily find the host device by
this mappinng.

However, Abnormal Case) host1 scan first,
host1 will be started from /dev/sda and host0 will be followed later.

To make sure the scan sequences according to the host, we can use a
bitmap which hosts are scanned and wait until previous hosts are
finished to scan.

Signed-off-by: Chanho Park <chanho61.park@samsung.com>
---
 drivers/scsi/ufs/ufshcd.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index b8f573a02713..1ced5996e988 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -13,6 +13,7 @@
 #include <linux/devfreq.h>
 #include <linux/nls.h>
 #include <linux/of.h>
+#include <linux/bitmap.h>
 #include <linux/bitfield.h>
 #include <linux/blk-pm.h>
 #include <linux/blkdev.h>
@@ -214,6 +215,10 @@ static struct ufs_dev_fix ufs_fixups[] = {
 	END_FIX
 };
 
+/* Ordered scan host */
+static unsigned long scanned_hosts = 0;
+static wait_queue_head_t scan_wq = __WAIT_QUEUE_HEAD_INITIALIZER(scan_wq);
+
 static irqreturn_t ufshcd_tmc_handler(struct ufs_hba *hba);
 static void ufshcd_async_scan(void *data, async_cookie_t cookie);
 static int ufshcd_reset_and_restore(struct ufs_hba *hba);
@@ -7709,8 +7714,13 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)
 	if (ret)
 		goto out;
 
-	/* Probe and add UFS logical units  */
+	/* Probe and add UFS logical units. Sequential scan by host_no */
+	wait_event(scan_wq,
+		   find_first_zero_bit(&scanned_hosts, hba->host->max_id) ==
+		   hba->host->host_no);
 	ret = ufshcd_add_lus(hba);
+	set_bit(hba->host->host_no, &scanned_hosts);
+	wake_up(&scan_wq);
 out:
 	/*
 	 * If we failed to initialize the device or the device is not
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-10-26 11:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20201020070519epcas2p27906d7db7c74e45f2acf8243ec2eae1d@epcas2p2.samsung.com>
2020-10-20  7:05 ` [PATCH] scsi: ufs: make sure scan sequence for multiple hosts Chanho Park
2020-10-21  3:15   ` Bart Van Assche
2020-10-21  4:23     ` chanho61.park
2020-10-22  0:29       ` Bart Van Assche
2020-10-22  4:59         ` Chanho Park
2020-10-22  6:52           ` Avri Altman
2020-10-26 11:20             ` Chanho Park
2020-10-23 15:27           ` Bart Van Assche
     [not found] <CGME20201020084429epcas2p3685bcb89c3ab1cacefb183384dcb2b6e@epcas2p3.samsung.com>
2020-10-20  8:44 ` Chanho Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).