2020-10-20 09:46:33

by Chanho Park

[permalink] [raw]
Subject: [PATCH] scsi: ufs: make sure scan sequence for multiple hosts

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 <[email protected]>
---
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


2020-10-21 12:18:58

by Bart Van Assche

[permalink] [raw]
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,

Bart.

2020-10-21 12:26:24

by Chanho Park

[permalink] [raw]
Subject: RE: [PATCH] scsi: ufs: make sure scan sequence for multiple hosts

Hi,

> -----Original Message-----
> From: Bart Van Assche <[email protected]>
> Sent: Wednesday, October 21, 2020 12:15 PM
> To: Chanho Park <[email protected]>; [email protected];
> [email protected]
> Cc: [email protected]; [email protected]; linux-
> [email protected]; [email protected]
> 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


Attachments:
winmail.dat (2.57 kB)

2020-10-22 13:04:59

by Bart Van Assche

[permalink] [raw]
Subject: Re: [PATCH] scsi: ufs: make sure scan sequence for multiple hosts

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.