2020-10-24 15:46:02

by Jaegeuk Kim

[permalink] [raw]
Subject: [PATCH v3 2/5] scsi: ufs: clear UAC for FFU and RPMB LUNs

From: Jaegeuk Kim <[email protected]>

In order to conduct FFU or RPMB operations, UFS needs to clear UAC. This patch
clears it explicitly, so that we could get no failure given early execution.

Signed-off-by: Jaegeuk Kim <[email protected]>
---
drivers/scsi/ufs/ufshcd.c | 70 +++++++++++++++++++++++++++++++++++----
drivers/scsi/ufs/ufshcd.h | 1 +
2 files changed, 65 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index e0b479f9eb8a..011e80a21170 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -7057,7 +7057,6 @@ static inline void ufshcd_blk_pm_runtime_init(struct scsi_device *sdev)
static int ufshcd_scsi_add_wlus(struct ufs_hba *hba)
{
int ret = 0;
- struct scsi_device *sdev_rpmb;
struct scsi_device *sdev_boot;

hba->sdev_ufs_device = __scsi_add_device(hba->host, 0, 0,
@@ -7070,14 +7069,14 @@ static int ufshcd_scsi_add_wlus(struct ufs_hba *hba)
ufshcd_blk_pm_runtime_init(hba->sdev_ufs_device);
scsi_device_put(hba->sdev_ufs_device);

- sdev_rpmb = __scsi_add_device(hba->host, 0, 0,
+ hba->sdev_rpmb = __scsi_add_device(hba->host, 0, 0,
ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_RPMB_WLUN), NULL);
- if (IS_ERR(sdev_rpmb)) {
- ret = PTR_ERR(sdev_rpmb);
+ if (IS_ERR(hba->sdev_rpmb)) {
+ ret = PTR_ERR(hba->sdev_rpmb);
goto remove_sdev_ufs_device;
}
- ufshcd_blk_pm_runtime_init(sdev_rpmb);
- scsi_device_put(sdev_rpmb);
+ ufshcd_blk_pm_runtime_init(hba->sdev_rpmb);
+ scsi_device_put(hba->sdev_rpmb);

sdev_boot = __scsi_add_device(hba->host, 0, 0,
ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_BOOT_WLUN), NULL);
@@ -7601,6 +7600,63 @@ static int ufshcd_add_lus(struct ufs_hba *hba)
return ret;
}

+static int
+ufshcd_send_request_sense(struct ufs_hba *hba, struct scsi_device *sdp);
+
+static int ufshcd_clear_ua_wlun(struct ufs_hba *hba, u8 wlun)
+{
+ struct scsi_device *sdp;
+ unsigned long flags;
+ int ret = 0;
+
+ spin_lock_irqsave(hba->host->host_lock, flags);
+ if (wlun == UFS_UPIU_UFS_DEVICE_WLUN)
+ sdp = hba->sdev_ufs_device;
+ else if (wlun == UFS_UPIU_RPMB_WLUN)
+ sdp = hba->sdev_rpmb;
+ else
+ BUG_ON(1);
+ if (sdp) {
+ ret = scsi_device_get(sdp);
+ if (!ret && !scsi_device_online(sdp)) {
+ ret = -ENODEV;
+ scsi_device_put(sdp);
+ }
+ } else {
+ ret = -ENODEV;
+ }
+ spin_unlock_irqrestore(hba->host->host_lock, flags);
+ if (ret)
+ goto out_err;
+
+ ret = ufshcd_send_request_sense(hba, sdp);
+ scsi_device_put(sdp);
+out_err:
+ if (ret)
+ dev_err(hba->dev, "%s: UAC clear LU=%x ret = %d\n",
+ __func__, wlun, ret);
+ return ret;
+}
+
+static int ufshcd_clear_ua_wluns(struct ufs_hba *hba)
+{
+ int ret = 0;
+
+ if (!hba->wlun_dev_clr_ua)
+ goto out;
+
+ ret = ufshcd_clear_ua_wlun(hba, UFS_UPIU_UFS_DEVICE_WLUN);
+ if (!ret)
+ ret = ufshcd_clear_ua_wlun(hba, UFS_UPIU_RPMB_WLUN);
+ if (!ret)
+ hba->wlun_dev_clr_ua = false;
+out:
+ if (ret)
+ dev_err(hba->dev, "%s: Failed to clear UAC WLUNS ret = %d\n",
+ __func__, ret);
+ return ret;
+}
+
/**
* ufshcd_probe_hba - probe hba to detect device and initialize
* @hba: per-adapter instance
@@ -7720,6 +7776,8 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)
pm_runtime_put_sync(hba->dev);
ufshcd_exit_clk_scaling(hba);
ufshcd_hba_exit(hba);
+ } else {
+ ufshcd_clear_ua_wluns(hba);
}
}

diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index 47eb1430274c..718881d038f5 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -681,6 +681,7 @@ struct ufs_hba {
* "UFS device" W-LU.
*/
struct scsi_device *sdev_ufs_device;
+ struct scsi_device *sdev_rpmb;

enum ufs_dev_pwr_mode curr_dev_pwr_mode;
enum uic_link_state uic_link_state;
--
2.29.0.rc1.297.gfa9743e501-goog


2020-10-27 03:34:40

by Asutosh Das (asd)

[permalink] [raw]
Subject: Re: [PATCH v3 2/5] scsi: ufs: clear UAC for FFU and RPMB LUNs

On 2020-10-24 08:06, Jaegeuk Kim wrote:
> From: Jaegeuk Kim <[email protected]>
>
> In order to conduct FFU or RPMB operations, UFS needs to clear UAC.
> This patch
> clears it explicitly, so that we could get no failure given early
> execution.
>

What's the meaning of 'given early execution'?

> Signed-off-by: Jaegeuk Kim <[email protected]>
> ---
> drivers/scsi/ufs/ufshcd.c | 70 +++++++++++++++++++++++++++++++++++----
> drivers/scsi/ufs/ufshcd.h | 1 +
> 2 files changed, 65 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index e0b479f9eb8a..011e80a21170 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -7057,7 +7057,6 @@ static inline void
> ufshcd_blk_pm_runtime_init(struct scsi_device *sdev)
> static int ufshcd_scsi_add_wlus(struct ufs_hba *hba)
> {
> int ret = 0;
> - struct scsi_device *sdev_rpmb;
> struct scsi_device *sdev_boot;
>
> hba->sdev_ufs_device = __scsi_add_device(hba->host, 0, 0,
> @@ -7070,14 +7069,14 @@ static int ufshcd_scsi_add_wlus(struct ufs_hba
> *hba)
> ufshcd_blk_pm_runtime_init(hba->sdev_ufs_device);
> scsi_device_put(hba->sdev_ufs_device);
>
> - sdev_rpmb = __scsi_add_device(hba->host, 0, 0,
> + hba->sdev_rpmb = __scsi_add_device(hba->host, 0, 0,
> ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_RPMB_WLUN), NULL);
> - if (IS_ERR(sdev_rpmb)) {
> - ret = PTR_ERR(sdev_rpmb);
> + if (IS_ERR(hba->sdev_rpmb)) {
> + ret = PTR_ERR(hba->sdev_rpmb);
> goto remove_sdev_ufs_device;
> }
> - ufshcd_blk_pm_runtime_init(sdev_rpmb);
> - scsi_device_put(sdev_rpmb);
> + ufshcd_blk_pm_runtime_init(hba->sdev_rpmb);
> + scsi_device_put(hba->sdev_rpmb);
>
> sdev_boot = __scsi_add_device(hba->host, 0, 0,
> ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_BOOT_WLUN), NULL);
> @@ -7601,6 +7600,63 @@ static int ufshcd_add_lus(struct ufs_hba *hba)
> return ret;
> }
>
> +static int
> +ufshcd_send_request_sense(struct ufs_hba *hba, struct scsi_device
> *sdp);
> +
> +static int ufshcd_clear_ua_wlun(struct ufs_hba *hba, u8 wlun)
> +{
> + struct scsi_device *sdp;
> + unsigned long flags;
> + int ret = 0;
> +
> + spin_lock_irqsave(hba->host->host_lock, flags);
> + if (wlun == UFS_UPIU_UFS_DEVICE_WLUN)
> + sdp = hba->sdev_ufs_device;
> + else if (wlun == UFS_UPIU_RPMB_WLUN)
> + sdp = hba->sdev_rpmb;
> + else
> + BUG_ON(1);
> + if (sdp) {
> + ret = scsi_device_get(sdp);
> + if (!ret && !scsi_device_online(sdp)) {
> + ret = -ENODEV;
> + scsi_device_put(sdp);
> + }
> + } else {
> + ret = -ENODEV;
> + }
> + spin_unlock_irqrestore(hba->host->host_lock, flags);
> + if (ret)
> + goto out_err;
> +
> + ret = ufshcd_send_request_sense(hba, sdp);
> + scsi_device_put(sdp);
> +out_err:
> + if (ret)
> + dev_err(hba->dev, "%s: UAC clear LU=%x ret = %d\n",
> + __func__, wlun, ret);
> + return ret;
> +}
> +
> +static int ufshcd_clear_ua_wluns(struct ufs_hba *hba)
> +{
> + int ret = 0;
> +
> + if (!hba->wlun_dev_clr_ua)
> + goto out;
> +
> + ret = ufshcd_clear_ua_wlun(hba, UFS_UPIU_UFS_DEVICE_WLUN);
> + if (!ret)
> + ret = ufshcd_clear_ua_wlun(hba, UFS_UPIU_RPMB_WLUN);
> + if (!ret)
> + hba->wlun_dev_clr_ua = false;
> +out:
> + if (ret)
> + dev_err(hba->dev, "%s: Failed to clear UAC WLUNS ret = %d\n",
> + __func__, ret);
> + return ret;
> +}
> +
> /**
> * ufshcd_probe_hba - probe hba to detect device and initialize
> * @hba: per-adapter instance
> @@ -7720,6 +7776,8 @@ static void ufshcd_async_scan(void *data,
> async_cookie_t cookie)
> pm_runtime_put_sync(hba->dev);
> ufshcd_exit_clk_scaling(hba);
> ufshcd_hba_exit(hba);
> + } else {
> + ufshcd_clear_ua_wluns(hba);
> }
> }
>
> diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
> index 47eb1430274c..718881d038f5 100644
> --- a/drivers/scsi/ufs/ufshcd.h
> +++ b/drivers/scsi/ufs/ufshcd.h
> @@ -681,6 +681,7 @@ struct ufs_hba {
> * "UFS device" W-LU.
> */
> struct scsi_device *sdev_ufs_device;
> + struct scsi_device *sdev_rpmb;
>
> enum ufs_dev_pwr_mode curr_dev_pwr_mode;
> enum uic_link_state uic_link_state;

2020-10-27 06:34:47

by Jaegeuk Kim

[permalink] [raw]
Subject: Re: [PATCH v3 2/5] scsi: ufs: clear UAC for FFU and RPMB LUNs

On 10/26, [email protected] wrote:
> On 2020-10-24 08:06, Jaegeuk Kim wrote:
> > From: Jaegeuk Kim <[email protected]>
> >
> > In order to conduct FFU or RPMB operations, UFS needs to clear UAC. This
> > patch
> > clears it explicitly, so that we could get no failure given early
> > execution.
> >
>
> What's the meaning of 'given early execution'?

I saw there's hba->wlun_dev_clr_ua to clear UA at ufshcd_set_dev_pwr_mode(),
and thus, assumed there's other path to clear UA. So, with this patch, user
can try FFU or RPMB requests regardless of that being done.

>
> > Signed-off-by: Jaegeuk Kim <[email protected]>
> > ---
> > drivers/scsi/ufs/ufshcd.c | 70 +++++++++++++++++++++++++++++++++++----
> > drivers/scsi/ufs/ufshcd.h | 1 +
> > 2 files changed, 65 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> > index e0b479f9eb8a..011e80a21170 100644
> > --- a/drivers/scsi/ufs/ufshcd.c
> > +++ b/drivers/scsi/ufs/ufshcd.c
> > @@ -7057,7 +7057,6 @@ static inline void
> > ufshcd_blk_pm_runtime_init(struct scsi_device *sdev)
> > static int ufshcd_scsi_add_wlus(struct ufs_hba *hba)
> > {
> > int ret = 0;
> > - struct scsi_device *sdev_rpmb;
> > struct scsi_device *sdev_boot;
> >
> > hba->sdev_ufs_device = __scsi_add_device(hba->host, 0, 0,
> > @@ -7070,14 +7069,14 @@ static int ufshcd_scsi_add_wlus(struct ufs_hba
> > *hba)
> > ufshcd_blk_pm_runtime_init(hba->sdev_ufs_device);
> > scsi_device_put(hba->sdev_ufs_device);
> >
> > - sdev_rpmb = __scsi_add_device(hba->host, 0, 0,
> > + hba->sdev_rpmb = __scsi_add_device(hba->host, 0, 0,
> > ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_RPMB_WLUN), NULL);
> > - if (IS_ERR(sdev_rpmb)) {
> > - ret = PTR_ERR(sdev_rpmb);
> > + if (IS_ERR(hba->sdev_rpmb)) {
> > + ret = PTR_ERR(hba->sdev_rpmb);
> > goto remove_sdev_ufs_device;
> > }
> > - ufshcd_blk_pm_runtime_init(sdev_rpmb);
> > - scsi_device_put(sdev_rpmb);
> > + ufshcd_blk_pm_runtime_init(hba->sdev_rpmb);
> > + scsi_device_put(hba->sdev_rpmb);
> >
> > sdev_boot = __scsi_add_device(hba->host, 0, 0,
> > ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_BOOT_WLUN), NULL);
> > @@ -7601,6 +7600,63 @@ static int ufshcd_add_lus(struct ufs_hba *hba)
> > return ret;
> > }
> >
> > +static int
> > +ufshcd_send_request_sense(struct ufs_hba *hba, struct scsi_device
> > *sdp);
> > +
> > +static int ufshcd_clear_ua_wlun(struct ufs_hba *hba, u8 wlun)
> > +{
> > + struct scsi_device *sdp;
> > + unsigned long flags;
> > + int ret = 0;
> > +
> > + spin_lock_irqsave(hba->host->host_lock, flags);
> > + if (wlun == UFS_UPIU_UFS_DEVICE_WLUN)
> > + sdp = hba->sdev_ufs_device;
> > + else if (wlun == UFS_UPIU_RPMB_WLUN)
> > + sdp = hba->sdev_rpmb;
> > + else
> > + BUG_ON(1);
> > + if (sdp) {
> > + ret = scsi_device_get(sdp);
> > + if (!ret && !scsi_device_online(sdp)) {
> > + ret = -ENODEV;
> > + scsi_device_put(sdp);
> > + }
> > + } else {
> > + ret = -ENODEV;
> > + }
> > + spin_unlock_irqrestore(hba->host->host_lock, flags);
> > + if (ret)
> > + goto out_err;
> > +
> > + ret = ufshcd_send_request_sense(hba, sdp);
> > + scsi_device_put(sdp);
> > +out_err:
> > + if (ret)
> > + dev_err(hba->dev, "%s: UAC clear LU=%x ret = %d\n",
> > + __func__, wlun, ret);
> > + return ret;
> > +}
> > +
> > +static int ufshcd_clear_ua_wluns(struct ufs_hba *hba)
> > +{
> > + int ret = 0;
> > +
> > + if (!hba->wlun_dev_clr_ua)
> > + goto out;
> > +
> > + ret = ufshcd_clear_ua_wlun(hba, UFS_UPIU_UFS_DEVICE_WLUN);
> > + if (!ret)
> > + ret = ufshcd_clear_ua_wlun(hba, UFS_UPIU_RPMB_WLUN);
> > + if (!ret)
> > + hba->wlun_dev_clr_ua = false;
> > +out:
> > + if (ret)
> > + dev_err(hba->dev, "%s: Failed to clear UAC WLUNS ret = %d\n",
> > + __func__, ret);
> > + return ret;
> > +}
> > +
> > /**
> > * ufshcd_probe_hba - probe hba to detect device and initialize
> > * @hba: per-adapter instance
> > @@ -7720,6 +7776,8 @@ static void ufshcd_async_scan(void *data,
> > async_cookie_t cookie)
> > pm_runtime_put_sync(hba->dev);
> > ufshcd_exit_clk_scaling(hba);
> > ufshcd_hba_exit(hba);
> > + } else {
> > + ufshcd_clear_ua_wluns(hba);
> > }
> > }
> >
> > diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
> > index 47eb1430274c..718881d038f5 100644
> > --- a/drivers/scsi/ufs/ufshcd.h
> > +++ b/drivers/scsi/ufs/ufshcd.h
> > @@ -681,6 +681,7 @@ struct ufs_hba {
> > * "UFS device" W-LU.
> > */
> > struct scsi_device *sdev_ufs_device;
> > + struct scsi_device *sdev_rpmb;
> >
> > enum ufs_dev_pwr_mode curr_dev_pwr_mode;
> > enum uic_link_state uic_link_state;

2020-10-28 17:40:00

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v3 2/5] scsi: ufs: clear UAC for FFU and RPMB LUNs

Hi Jaegeuk,

I love your patch! Perhaps something to improve:

[auto build test WARNING on scsi/for-next]
[also build test WARNING on mkp-scsi/for-next linus/master linux/master v5.10-rc1 next-20201027]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Jaegeuk-Kim/scsi-ufs-atomic-update-for-clkgating_enable/20201025-000720
base: https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next
config: x86_64-randconfig-a012-20201027 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project f2c25c70791de95d2466e09b5b58fc37f6ccd7a4)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/48327c0914e146090df19aaa6df3f0ed569d9669
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jaegeuk-Kim/scsi-ufs-atomic-update-for-clkgating_enable/20201025-000720
git checkout 48327c0914e146090df19aaa6df3f0ed569d9669
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

>> drivers/scsi/ufs/ufshcd.c:7618:3: warning: variable 'sdp' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
BUG_ON(1);
^~~~~~~~~
include/asm-generic/bug.h:63:32: note: expanded from macro 'BUG_ON'
#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
^~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler.h:56:28: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler.h:58:30: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/scsi/ufs/ufshcd.c:7619:6: note: uninitialized use occurs here
if (sdp) {
^~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
drivers/scsi/ufs/ufshcd.c:7618:3: note: remove the 'if' if its condition is always true
BUG_ON(1);
^
include/asm-generic/bug.h:63:32: note: expanded from macro 'BUG_ON'
#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
^
include/linux/compiler.h:56:23: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^
drivers/scsi/ufs/ufshcd.c:7608:25: note: initialize the variable 'sdp' to silence this warning
struct scsi_device *sdp;
^
= NULL
1 warning generated.

vim +7618 drivers/scsi/ufs/ufshcd.c

7605
7606 static int ufshcd_clear_ua_wlun(struct ufs_hba *hba, u8 wlun)
7607 {
7608 struct scsi_device *sdp;
7609 unsigned long flags;
7610 int ret = 0;
7611
7612 spin_lock_irqsave(hba->host->host_lock, flags);
7613 if (wlun == UFS_UPIU_UFS_DEVICE_WLUN)
7614 sdp = hba->sdev_ufs_device;
7615 else if (wlun == UFS_UPIU_RPMB_WLUN)
7616 sdp = hba->sdev_rpmb;
7617 else
> 7618 BUG_ON(1);
7619 if (sdp) {
7620 ret = scsi_device_get(sdp);
7621 if (!ret && !scsi_device_online(sdp)) {
7622 ret = -ENODEV;
7623 scsi_device_put(sdp);
7624 }
7625 } else {
7626 ret = -ENODEV;
7627 }
7628 spin_unlock_irqrestore(hba->host->host_lock, flags);
7629 if (ret)
7630 goto out_err;
7631
7632 ret = ufshcd_send_request_sense(hba, sdp);
7633 scsi_device_put(sdp);
7634 out_err:
7635 if (ret)
7636 dev_err(hba->dev, "%s: UAC clear LU=%x ret = %d\n",
7637 __func__, wlun, ret);
7638 return ret;
7639 }
7640

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (4.99 kB)
.config.gz (30.48 kB)
Download all attachments