[v2,2/3] scsi: ufs: Add handling of the return value of pm_runtime_get_sync()
diff mbox series

Message ID 20201224172010.10701-3-huobean@gmail.com
State New, archived
Headers show
Series
  • Two changes of UFS sysfs
Related show

Commit Message

Bean Huo Dec. 24, 2020, 5:20 p.m. UTC
From: Bean Huo <beanhuo@micron.com>

The race issue may exist between UFS access in UFS sysfs context and UFS
shutdown, thus will cause pm_runtime_get_sync() resume failure.
Add handling of the return value of pm_runtime_get_sync(). Let it return
in case pm_runtime_get_sync() resume failed.

Signed-off-by: Bean Huo <beanhuo@micron.com>
---
 drivers/scsi/ufs/ufs-sysfs.c | 38 ++++++++++++++++++++++++++++++------
 1 file changed, 32 insertions(+), 6 deletions(-)

Comments

Can Guo Dec. 28, 2020, 1:50 a.m. UTC | #1
On 2020-12-25 01:20, Bean Huo wrote:
> From: Bean Huo <beanhuo@micron.com>
> 
> The race issue may exist between UFS access in UFS sysfs context and 
> UFS
> shutdown, thus will cause pm_runtime_get_sync() resume failure.

Are you trying to fix the race condition by adding these checks or just
adding these checks in case pm_runtime_get_sync() fails?

Can Guo.

> Add handling of the return value of pm_runtime_get_sync(). Let it 
> return
> in case pm_runtime_get_sync() resume failed.
> 
> Signed-off-by: Bean Huo <beanhuo@micron.com>
> ---
>  drivers/scsi/ufs/ufs-sysfs.c | 38 ++++++++++++++++++++++++++++++------
>  1 file changed, 32 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/scsi/ufs/ufs-sysfs.c 
> b/drivers/scsi/ufs/ufs-sysfs.c
> index 0e1438485133..8e5e36e01bee 100644
> --- a/drivers/scsi/ufs/ufs-sysfs.c
> +++ b/drivers/scsi/ufs/ufs-sysfs.c
> @@ -154,12 +154,17 @@ static ssize_t auto_hibern8_show(struct device 
> *dev,
>  				 struct device_attribute *attr, char *buf)
>  {
>  	u32 ahit;
> +	int ret;
>  	struct ufs_hba *hba = dev_get_drvdata(dev);
> 
>  	if (!ufshcd_is_auto_hibern8_supported(hba))
>  		return -EOPNOTSUPP;
> 
> -	pm_runtime_get_sync(hba->dev);
> +	ret = pm_runtime_get_sync(hba->dev);
> +	if (ret < 0) {
> +		pm_runtime_put_noidle(hba->dev);
> +		return ret;
> +	}
>  	ufshcd_hold(hba, false);
>  	ahit = ufshcd_readl(hba, REG_AUTO_HIBERNATE_IDLE_TIMER);
>  	ufshcd_release(hba);
> @@ -225,7 +230,12 @@ static ssize_t ufs_sysfs_read_desc_param(struct
> ufs_hba *hba,
>  	if (param_size > 8)
>  		return -EINVAL;
> 
> -	pm_runtime_get_sync(hba->dev);
> +	ret = pm_runtime_get_sync(hba->dev);
> +	if (ret < 0) {
> +		pm_runtime_put_noidle(hba->dev);
> +		return ret;
> +	}
> +
>  	ret = ufshcd_read_desc_param(hba, desc_id, desc_index,
>  				param_offset, desc_buf, param_size);
>  	pm_runtime_put_sync(hba->dev);
> @@ -594,7 +604,11 @@ static ssize_t _name##_show(struct device 
> *dev,				\
>  	desc_buf = kzalloc(QUERY_DESC_MAX_SIZE, GFP_ATOMIC);		\
>  	if (!desc_buf)                                                  \
>  		return -ENOMEM;                                         \
> -	pm_runtime_get_sync(hba->dev);					\
> +	ret = pm_runtime_get_sync(hba->dev);				\
> +	if (ret < 0) {							\
> +		pm_runtime_put_noidle(hba->dev);			\
> +		return ret;						\
> +	}								\
>  	ret = ufshcd_query_descriptor_retry(hba,			\
>  		UPIU_QUERY_OPCODE_READ_DESC, QUERY_DESC_IDN_DEVICE,	\
>  		0, 0, desc_buf, &desc_len);				\
> @@ -653,7 +667,11 @@ static ssize_t _name##_show(struct device 
> *dev,				\
>  	struct ufs_hba *hba = dev_get_drvdata(dev);			\
>  	if (ufshcd_is_wb_flags(QUERY_FLAG_IDN##_uname))			\
>  		index = ufshcd_wb_get_query_index(hba);			\
> -	pm_runtime_get_sync(hba->dev);					\
> +	ret = pm_runtime_get_sync(hba->dev);				\
> +	if (ret < 0) {							\
> +		pm_runtime_put_noidle(hba->dev);			\
> +		return ret;						\
> +	}								\
>  	ret = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG,	\
>  		QUERY_FLAG_IDN##_uname, index, &flag);			\
>  	pm_runtime_put_sync(hba->dev);					\
> @@ -711,7 +729,11 @@ static ssize_t _name##_show(struct device 
> *dev,				\
>  	u8 index = 0;							\
>  	if (ufshcd_is_wb_attrs(QUERY_ATTR_IDN##_uname))			\
>  		index = ufshcd_wb_get_query_index(hba);			\
> -	pm_runtime_get_sync(hba->dev);					\
> +	ret = pm_runtime_get_sync(hba->dev);				\
> +	if (ret < 0) {							\
> +		pm_runtime_put_noidle(hba->dev);			\
> +		return ret;						\
> +	}								\
>  	ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR,	\
>  		QUERY_ATTR_IDN##_uname, index, 0, &value);		\
>  	pm_runtime_put_sync(hba->dev);					\
> @@ -850,7 +872,11 @@ static ssize_t
> dyn_cap_needed_attribute_show(struct device *dev,
>  	u8 lun = ufshcd_scsi_to_upiu_lun(sdev->lun);
>  	int ret;
> 
> -	pm_runtime_get_sync(hba->dev);
> +	ret = pm_runtime_get_sync(hba->dev);
> +	if (ret < 0) {
> +		pm_runtime_put_noidle(hba->dev);
> +		return ret;
> +	}
>  	ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR,
>  		QUERY_ATTR_IDN_DYN_CAP_NEEDED, lun, 0, &value);
>  	pm_runtime_put_sync(hba->dev);
Bean Huo Jan. 4, 2021, 5:39 p.m. UTC | #2
On Mon, 2020-12-28 at 09:50 +0800, Can Guo wrote:
> > The race issue may exist between UFS access in UFS sysfs context
> > and 
> > UFS
> > shutdown, thus will cause pm_runtime_get_sync() resume failure.
> 
> Are you trying to fix the race condition by adding these checks or
> just
> adding these checks in case pm_runtime_get_sync() fails?
> 
> Can Guo.

Can,
thanks for your review. Sorry, I didn't quite get your point.
This patch is just to add checkup in case pm_runtime_get_sync() failed.

what else should be added?

Bean

Patch
diff mbox series

diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c
index 0e1438485133..8e5e36e01bee 100644
--- a/drivers/scsi/ufs/ufs-sysfs.c
+++ b/drivers/scsi/ufs/ufs-sysfs.c
@@ -154,12 +154,17 @@  static ssize_t auto_hibern8_show(struct device *dev,
 				 struct device_attribute *attr, char *buf)
 {
 	u32 ahit;
+	int ret;
 	struct ufs_hba *hba = dev_get_drvdata(dev);
 
 	if (!ufshcd_is_auto_hibern8_supported(hba))
 		return -EOPNOTSUPP;
 
-	pm_runtime_get_sync(hba->dev);
+	ret = pm_runtime_get_sync(hba->dev);
+	if (ret < 0) {
+		pm_runtime_put_noidle(hba->dev);
+		return ret;
+	}
 	ufshcd_hold(hba, false);
 	ahit = ufshcd_readl(hba, REG_AUTO_HIBERNATE_IDLE_TIMER);
 	ufshcd_release(hba);
@@ -225,7 +230,12 @@  static ssize_t ufs_sysfs_read_desc_param(struct ufs_hba *hba,
 	if (param_size > 8)
 		return -EINVAL;
 
-	pm_runtime_get_sync(hba->dev);
+	ret = pm_runtime_get_sync(hba->dev);
+	if (ret < 0) {
+		pm_runtime_put_noidle(hba->dev);
+		return ret;
+	}
+
 	ret = ufshcd_read_desc_param(hba, desc_id, desc_index,
 				param_offset, desc_buf, param_size);
 	pm_runtime_put_sync(hba->dev);
@@ -594,7 +604,11 @@  static ssize_t _name##_show(struct device *dev,				\
 	desc_buf = kzalloc(QUERY_DESC_MAX_SIZE, GFP_ATOMIC);		\
 	if (!desc_buf)                                                  \
 		return -ENOMEM;                                         \
-	pm_runtime_get_sync(hba->dev);					\
+	ret = pm_runtime_get_sync(hba->dev);				\
+	if (ret < 0) {							\
+		pm_runtime_put_noidle(hba->dev);			\
+		return ret;						\
+	}								\
 	ret = ufshcd_query_descriptor_retry(hba,			\
 		UPIU_QUERY_OPCODE_READ_DESC, QUERY_DESC_IDN_DEVICE,	\
 		0, 0, desc_buf, &desc_len);				\
@@ -653,7 +667,11 @@  static ssize_t _name##_show(struct device *dev,				\
 	struct ufs_hba *hba = dev_get_drvdata(dev);			\
 	if (ufshcd_is_wb_flags(QUERY_FLAG_IDN##_uname))			\
 		index = ufshcd_wb_get_query_index(hba);			\
-	pm_runtime_get_sync(hba->dev);					\
+	ret = pm_runtime_get_sync(hba->dev);				\
+	if (ret < 0) {							\
+		pm_runtime_put_noidle(hba->dev);			\
+		return ret;						\
+	}								\
 	ret = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG,	\
 		QUERY_FLAG_IDN##_uname, index, &flag);			\
 	pm_runtime_put_sync(hba->dev);					\
@@ -711,7 +729,11 @@  static ssize_t _name##_show(struct device *dev,				\
 	u8 index = 0;							\
 	if (ufshcd_is_wb_attrs(QUERY_ATTR_IDN##_uname))			\
 		index = ufshcd_wb_get_query_index(hba);			\
-	pm_runtime_get_sync(hba->dev);					\
+	ret = pm_runtime_get_sync(hba->dev);				\
+	if (ret < 0) {							\
+		pm_runtime_put_noidle(hba->dev);			\
+		return ret;						\
+	}								\
 	ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR,	\
 		QUERY_ATTR_IDN##_uname, index, 0, &value);		\
 	pm_runtime_put_sync(hba->dev);					\
@@ -850,7 +872,11 @@  static ssize_t dyn_cap_needed_attribute_show(struct device *dev,
 	u8 lun = ufshcd_scsi_to_upiu_lun(sdev->lun);
 	int ret;
 
-	pm_runtime_get_sync(hba->dev);
+	ret = pm_runtime_get_sync(hba->dev);
+	if (ret < 0) {
+		pm_runtime_put_noidle(hba->dev);
+		return ret;
+	}
 	ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR,
 		QUERY_ATTR_IDN_DYN_CAP_NEEDED, lun, 0, &value);
 	pm_runtime_put_sync(hba->dev);