2020-12-01 04:16:54

by Jaegeuk Kim

[permalink] [raw]
Subject: [PATCH] scsi: ufs: clear uac for RPMB after ufshcd resets

From: Randall Huang <[email protected]>

If RPMB is not provisioned, we may see RPMB failure after UFS suspend/resume.
Inject request_sense to clear uac in ufshcd reset flow.

Signed-off-by: Randall Huang <[email protected]>
Signed-off-by: Leo Liou <[email protected]>
Signed-off-by: Jaegeuk Kim <[email protected]>
---
drivers/scsi/ufs/ufshcd.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index dba3ee307307..c728c00b58db 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -220,6 +220,7 @@ static int ufshcd_reset_and_restore(struct ufs_hba *hba);
static int ufshcd_eh_host_reset_handler(struct scsi_cmnd *cmd);
static int ufshcd_clear_tm_cmd(struct ufs_hba *hba, int tag);
static void ufshcd_hba_exit(struct ufs_hba *hba);
+static int ufshcd_clear_ua_wluns(struct ufs_hba *hba);
static int ufshcd_probe_hba(struct ufs_hba *hba, bool async);
static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on,
bool skip_ref_clk);
@@ -6814,7 +6815,8 @@ static int ufshcd_host_reset_and_restore(struct ufs_hba *hba)

/* Establish the link again and restore the device */
err = ufshcd_probe_hba(hba, false);
-
+ if (!err)
+ ufshcd_clear_ua_wluns(hba);
out:
if (err)
dev_err(hba->dev, "%s: Host init failed %d\n", __func__, err);
@@ -8304,13 +8306,7 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
* handling context.
*/
hba->host->eh_noresume = 1;
- if (hba->wlun_dev_clr_ua) {
- ret = ufshcd_send_request_sense(hba, sdp);
- if (ret)
- goto out;
- /* Unit attention condition is cleared now */
- hba->wlun_dev_clr_ua = false;
- }
+ ufshcd_clear_ua_wluns(hba);

cmd[4] = pwr_mode << 4;

--
2.29.2.454.gaff20da3a2-goog


2020-12-01 22:14:54

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] scsi: ufs: clear uac for RPMB after ufshcd resets

Hi Jaegeuk,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on scsi/for-next]
[also build test WARNING on mkp-scsi/for-next linux/master linus/master v5.10-rc6 next-20201130]
[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-clear-uac-for-RPMB-after-ufshcd-resets/20201201-121956
base: https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next
config: x86_64-randconfig-a006-20201201 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project ac40a2d8f16b8a8c68fc811d67f647740e965cb8)
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/0636adf2e8880085b18818ce6e7ee878189b52ca
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jaegeuk-Kim/scsi-ufs-clear-uac-for-RPMB-after-ufshcd-resets/20201201-121956
git checkout 0636adf2e8880085b18818ce6e7ee878189b52ca
# 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:8398:1: warning: unused label 'out' [-Wunused-label]
out:
^~~~
1 warning generated.

vim +/out +8398 drivers/scsi/ufs/ufshcd.c

57d104c153d3d6d Subhash Jadavani 2014-09-25 8335
57d104c153d3d6d Subhash Jadavani 2014-09-25 8336 /**
57d104c153d3d6d Subhash Jadavani 2014-09-25 8337 * ufshcd_set_dev_pwr_mode - sends START STOP UNIT command to set device
57d104c153d3d6d Subhash Jadavani 2014-09-25 8338 * power mode
57d104c153d3d6d Subhash Jadavani 2014-09-25 8339 * @hba: per adapter instance
57d104c153d3d6d Subhash Jadavani 2014-09-25 8340 * @pwr_mode: device power mode to set
57d104c153d3d6d Subhash Jadavani 2014-09-25 8341 *
57d104c153d3d6d Subhash Jadavani 2014-09-25 8342 * Returns 0 if requested power mode is set successfully
57d104c153d3d6d Subhash Jadavani 2014-09-25 8343 * Returns non-zero if failed to set the requested power mode
57d104c153d3d6d Subhash Jadavani 2014-09-25 8344 */
57d104c153d3d6d Subhash Jadavani 2014-09-25 8345 static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
57d104c153d3d6d Subhash Jadavani 2014-09-25 8346 enum ufs_dev_pwr_mode pwr_mode)
57d104c153d3d6d Subhash Jadavani 2014-09-25 8347 {
57d104c153d3d6d Subhash Jadavani 2014-09-25 8348 unsigned char cmd[6] = { START_STOP };
57d104c153d3d6d Subhash Jadavani 2014-09-25 8349 struct scsi_sense_hdr sshdr;
7c48bfd038e570c Akinobu Mita 2014-10-23 8350 struct scsi_device *sdp;
7c48bfd038e570c Akinobu Mita 2014-10-23 8351 unsigned long flags;
57d104c153d3d6d Subhash Jadavani 2014-09-25 8352 int ret;
57d104c153d3d6d Subhash Jadavani 2014-09-25 8353
7c48bfd038e570c Akinobu Mita 2014-10-23 8354 spin_lock_irqsave(hba->host->host_lock, flags);
7c48bfd038e570c Akinobu Mita 2014-10-23 8355 sdp = hba->sdev_ufs_device;
7c48bfd038e570c Akinobu Mita 2014-10-23 8356 if (sdp) {
7c48bfd038e570c Akinobu Mita 2014-10-23 8357 ret = scsi_device_get(sdp);
7c48bfd038e570c Akinobu Mita 2014-10-23 8358 if (!ret && !scsi_device_online(sdp)) {
7c48bfd038e570c Akinobu Mita 2014-10-23 8359 ret = -ENODEV;
7c48bfd038e570c Akinobu Mita 2014-10-23 8360 scsi_device_put(sdp);
7c48bfd038e570c Akinobu Mita 2014-10-23 8361 }
7c48bfd038e570c Akinobu Mita 2014-10-23 8362 } else {
7c48bfd038e570c Akinobu Mita 2014-10-23 8363 ret = -ENODEV;
7c48bfd038e570c Akinobu Mita 2014-10-23 8364 }
7c48bfd038e570c Akinobu Mita 2014-10-23 8365 spin_unlock_irqrestore(hba->host->host_lock, flags);
7c48bfd038e570c Akinobu Mita 2014-10-23 8366
7c48bfd038e570c Akinobu Mita 2014-10-23 8367 if (ret)
7c48bfd038e570c Akinobu Mita 2014-10-23 8368 return ret;
57d104c153d3d6d Subhash Jadavani 2014-09-25 8369
57d104c153d3d6d Subhash Jadavani 2014-09-25 8370 /*
57d104c153d3d6d Subhash Jadavani 2014-09-25 8371 * If scsi commands fail, the scsi mid-layer schedules scsi error-
57d104c153d3d6d Subhash Jadavani 2014-09-25 8372 * handling, which would wait for host to be resumed. Since we know
57d104c153d3d6d Subhash Jadavani 2014-09-25 8373 * we are functional while we are here, skip host resume in error
57d104c153d3d6d Subhash Jadavani 2014-09-25 8374 * handling context.
57d104c153d3d6d Subhash Jadavani 2014-09-25 8375 */
57d104c153d3d6d Subhash Jadavani 2014-09-25 8376 hba->host->eh_noresume = 1;
0636adf2e888008 Randall Huang 2020-11-30 8377 ufshcd_clear_ua_wluns(hba);
57d104c153d3d6d Subhash Jadavani 2014-09-25 8378
57d104c153d3d6d Subhash Jadavani 2014-09-25 8379 cmd[4] = pwr_mode << 4;
57d104c153d3d6d Subhash Jadavani 2014-09-25 8380
57d104c153d3d6d Subhash Jadavani 2014-09-25 8381 /*
57d104c153d3d6d Subhash Jadavani 2014-09-25 8382 * Current function would be generally called from the power management
e806402130c9c49 Christoph Hellwig 2016-10-20 8383 * callbacks hence set the RQF_PM flag so that it doesn't resume the
57d104c153d3d6d Subhash Jadavani 2014-09-25 8384 * already suspended childs.
57d104c153d3d6d Subhash Jadavani 2014-09-25 8385 */
fcbfffe2c5cbec0 Christoph Hellwig 2017-02-23 8386 ret = scsi_execute(sdp, cmd, DMA_NONE, NULL, 0, NULL, &sshdr,
fcbfffe2c5cbec0 Christoph Hellwig 2017-02-23 8387 START_STOP_TIMEOUT, 0, 0, RQF_PM, NULL);
57d104c153d3d6d Subhash Jadavani 2014-09-25 8388 if (ret) {
57d104c153d3d6d Subhash Jadavani 2014-09-25 8389 sdev_printk(KERN_WARNING, sdp,
ef61329db7b8b43 Hannes Reinecke 2014-10-24 8390 "START_STOP failed for power mode: %d, result %x\n",
ef61329db7b8b43 Hannes Reinecke 2014-10-24 8391 pwr_mode, ret);
c65be1a63f1df22 Johannes Thumshirn 2018-06-25 8392 if (driver_byte(ret) == DRIVER_SENSE)
2104551969e8011 Hannes Reinecke 2015-01-08 8393 scsi_print_sense_hdr(sdp, NULL, &sshdr);
57d104c153d3d6d Subhash Jadavani 2014-09-25 8394 }
57d104c153d3d6d Subhash Jadavani 2014-09-25 8395
57d104c153d3d6d Subhash Jadavani 2014-09-25 8396 if (!ret)
57d104c153d3d6d Subhash Jadavani 2014-09-25 8397 hba->curr_dev_pwr_mode = pwr_mode;
57d104c153d3d6d Subhash Jadavani 2014-09-25 @8398 out:
7c48bfd038e570c Akinobu Mita 2014-10-23 8399 scsi_device_put(sdp);
57d104c153d3d6d Subhash Jadavani 2014-09-25 8400 hba->host->eh_noresume = 0;
57d104c153d3d6d Subhash Jadavani 2014-09-25 8401 return ret;
57d104c153d3d6d Subhash Jadavani 2014-09-25 8402 }
57d104c153d3d6d Subhash Jadavani 2014-09-25 8403

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


Attachments:
(No filename) (7.35 kB)
.config.gz (29.52 kB)
Download all attachments

2020-12-08 21:55:48

by Jaegeuk Kim

[permalink] [raw]
Subject: Re: [PATCH v2] scsi: ufs: clear uac for RPMB after ufshcd resets

From 902e313f0d7ccf5e24491c2badc6dc173ce35fb1 Mon Sep 17 00:00:00 2001
From: Randall Huang <[email protected]>
Date: Tue, 24 Nov 2020 15:29:58 +0800
Subject: [PATCH] scsi: ufs: clear uac for RPMB after ufshcd resets

If RPMB is not provisioned, we may see RPMB failure after UFS suspend/resume.
Inject request_sense to clear uac in ufshcd reset flow.

Signed-off-by: Randall Huang <[email protected]>
Signed-off-by: Leo Liou <[email protected]>
Signed-off-by: Jaegeuk Kim <[email protected]>
---

v2:
- fix build warning

drivers/scsi/ufs/ufshcd.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index dba3ee307307..d6a3a0ba6960 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -220,6 +220,7 @@ static int ufshcd_reset_and_restore(struct ufs_hba *hba);
static int ufshcd_eh_host_reset_handler(struct scsi_cmnd *cmd);
static int ufshcd_clear_tm_cmd(struct ufs_hba *hba, int tag);
static void ufshcd_hba_exit(struct ufs_hba *hba);
+static int ufshcd_clear_ua_wluns(struct ufs_hba *hba);
static int ufshcd_probe_hba(struct ufs_hba *hba, bool async);
static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on,
bool skip_ref_clk);
@@ -6814,7 +6815,8 @@ static int ufshcd_host_reset_and_restore(struct ufs_hba *hba)

/* Establish the link again and restore the device */
err = ufshcd_probe_hba(hba, false);
-
+ if (!err)
+ ufshcd_clear_ua_wluns(hba);
out:
if (err)
dev_err(hba->dev, "%s: Host init failed %d\n", __func__, err);
@@ -8304,13 +8306,7 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
* handling context.
*/
hba->host->eh_noresume = 1;
- if (hba->wlun_dev_clr_ua) {
- ret = ufshcd_send_request_sense(hba, sdp);
- if (ret)
- goto out;
- /* Unit attention condition is cleared now */
- hba->wlun_dev_clr_ua = false;
- }
+ ufshcd_clear_ua_wluns(hba);

cmd[4] = pwr_mode << 4;

@@ -8331,7 +8327,7 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,

if (!ret)
hba->curr_dev_pwr_mode = pwr_mode;
-out:
+
scsi_device_put(sdp);
hba->host->eh_noresume = 0;
return ret;
--
2.29.2.576.ga3fc446d84-goog

2020-12-09 01:16:59

by Stanley Chu

[permalink] [raw]
Subject: Re: [PATCH v2] scsi: ufs: clear uac for RPMB after ufshcd resets

On Tue, 2020-12-08 at 13:51 -0800, Jaegeuk Kim wrote:
> From 902e313f0d7ccf5e24491c2badc6dc173ce35fb1 Mon Sep 17 00:00:00 2001
> From: Randall Huang <[email protected]>
> Date: Tue, 24 Nov 2020 15:29:58 +0800
> Subject: [PATCH] scsi: ufs: clear uac for RPMB after ufshcd resets
>
> If RPMB is not provisioned, we may see RPMB failure after UFS suspend/resume.
> Inject request_sense to clear uac in ufshcd reset flow.
>
> Signed-off-by: Randall Huang <[email protected]>
> Signed-off-by: Leo Liou <[email protected]>
> Signed-off-by: Jaegeuk Kim <[email protected]>

Reviewed-by: Stanley Chu <[email protected]>

2020-12-09 03:37:09

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH v2] scsi: ufs: clear uac for RPMB after ufshcd resets


Jaegeuk,

> If RPMB is not provisioned, we may see RPMB failure after UFS suspend/resume.
> Inject request_sense to clear uac in ufshcd reset flow.

Applied to 5.11/scsi-staging, thanks!

--
Martin K. Petersen Oracle Linux Engineering