diff mbox series

soc: qcom: rpmh-rsc: Don't use ktime for timeout in write_tcs_reg_sync()

Message ID 20200528074530.1.Ib86e5b406fe7d16575ae1bb276d650faa144b63c@changeid
State Accepted
Commit be24c6a71ecfbd9436ea1f496eb518a53e06368c
Headers show
Series soc: qcom: rpmh-rsc: Don't use ktime for timeout in write_tcs_reg_sync() | expand

Commit Message

Doug Anderson May 28, 2020, 2:48 p.m. UTC
The write_tcs_reg_sync() may be called after timekeeping is suspended
so it's not OK to use ktime.  The readl_poll_timeout_atomic() macro
implicitly uses ktime.  This was causing a warning at suspend time.

Change to just loop 1000000 times with a delay of 1 us between loops.
This may give a timeout of more than 1 second but never less and is
safe even if timekeeping is suspended.

NOTE: I don't have any actual evidence that we need to loop here.
It's possibly that all we really need to do is just read the value
back to ensure that the pipes are cleaned and the looping/comparing is
totally not needed.  I never saw the loop being needed in my tests.
However, the loop shouldn't hurt.

Fixes: 91160150aba0 ("soc: qcom: rpmh-rsc: Timeout after 1 second in write_tcs_reg_sync()")
Reported-by: Maulik Shah <mkshah@codeaurora.org>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

 drivers/soc/qcom/rpmh-rsc.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

Comments

Doug Anderson June 18, 2020, 9:52 p.m. UTC | #1
Bjorn and Andy,

On Thu, May 28, 2020 at 7:48 AM Douglas Anderson <dianders@chromium.org> wrote:
>

> The write_tcs_reg_sync() may be called after timekeeping is suspended

> so it's not OK to use ktime.  The readl_poll_timeout_atomic() macro

> implicitly uses ktime.  This was causing a warning at suspend time.

>

> Change to just loop 1000000 times with a delay of 1 us between loops.

> This may give a timeout of more than 1 second but never less and is

> safe even if timekeeping is suspended.

>

> NOTE: I don't have any actual evidence that we need to loop here.

> It's possibly that all we really need to do is just read the value

> back to ensure that the pipes are cleaned and the looping/comparing is

> totally not needed.  I never saw the loop being needed in my tests.

> However, the loop shouldn't hurt.

>

> Fixes: 91160150aba0 ("soc: qcom: rpmh-rsc: Timeout after 1 second in write_tcs_reg_sync()")

> Reported-by: Maulik Shah <mkshah@codeaurora.org>

> Signed-off-by: Douglas Anderson <dianders@chromium.org>

> ---

>

>  drivers/soc/qcom/rpmh-rsc.c | 18 +++++++++++++-----

>  1 file changed, 13 insertions(+), 5 deletions(-)


Is it a good time to land this change now that -rc1 has come out?
It'd be nice to get this resolved.

Thanks!

-Doug
Maulik Shah June 24, 2020, 4:41 a.m. UTC | #2
Reviewed-by: Maulik Shah <mkshah@codeaurora.org>


Thanks,
Maulik

On 5/28/2020 8:18 PM, Douglas Anderson wrote:
> The write_tcs_reg_sync() may be called after timekeeping is suspended

> so it's not OK to use ktime.  The readl_poll_timeout_atomic() macro

> implicitly uses ktime.  This was causing a warning at suspend time.

>

> Change to just loop 1000000 times with a delay of 1 us between loops.

> This may give a timeout of more than 1 second but never less and is

> safe even if timekeeping is suspended.

>

> NOTE: I don't have any actual evidence that we need to loop here.

> It's possibly that all we really need to do is just read the value

> back to ensure that the pipes are cleaned and the looping/comparing is

> totally not needed.  I never saw the loop being needed in my tests.

> However, the loop shouldn't hurt.

>

> Fixes: 91160150aba0 ("soc: qcom: rpmh-rsc: Timeout after 1 second in write_tcs_reg_sync()")

> Reported-by: Maulik Shah <mkshah@codeaurora.org>

> Signed-off-by: Douglas Anderson <dianders@chromium.org>

> ---

>

>   drivers/soc/qcom/rpmh-rsc.c | 18 +++++++++++++-----

>   1 file changed, 13 insertions(+), 5 deletions(-)

>

> diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c

> index 076fd27f3081..906778e2c1fa 100644

> --- a/drivers/soc/qcom/rpmh-rsc.c

> +++ b/drivers/soc/qcom/rpmh-rsc.c

> @@ -175,13 +175,21 @@ static void write_tcs_reg(const struct rsc_drv *drv, int reg, int tcs_id,

>   static void write_tcs_reg_sync(const struct rsc_drv *drv, int reg, int tcs_id,

>   			       u32 data)

>   {

> -	u32 new_data;

> +	int i;

>   

>   	writel(data, tcs_reg_addr(drv, reg, tcs_id));

> -	if (readl_poll_timeout_atomic(tcs_reg_addr(drv, reg, tcs_id), new_data,

> -				      new_data == data, 1, USEC_PER_SEC))

> -		pr_err("%s: error writing %#x to %d:%#x\n", drv->name,

> -		       data, tcs_id, reg);

> +

> +	/*

> +	 * Wait until we read back the same value.  Use a counter rather than

> +	 * ktime for timeout since this may be called after timekeeping stops.

> +	 */

> +	for (i = 0; i < USEC_PER_SEC; i++) {

> +		if (readl(tcs_reg_addr(drv, reg, tcs_id)) == data)

> +			return;

> +		udelay(1);

> +	}

> +	pr_err("%s: error writing %#x to %d:%#x\n", drv->name,

> +	       data, tcs_id, reg);

>   }

>   

>   /**


-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
diff mbox series

Patch

diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c
index 076fd27f3081..906778e2c1fa 100644
--- a/drivers/soc/qcom/rpmh-rsc.c
+++ b/drivers/soc/qcom/rpmh-rsc.c
@@ -175,13 +175,21 @@  static void write_tcs_reg(const struct rsc_drv *drv, int reg, int tcs_id,
 static void write_tcs_reg_sync(const struct rsc_drv *drv, int reg, int tcs_id,
 			       u32 data)
 {
-	u32 new_data;
+	int i;
 
 	writel(data, tcs_reg_addr(drv, reg, tcs_id));
-	if (readl_poll_timeout_atomic(tcs_reg_addr(drv, reg, tcs_id), new_data,
-				      new_data == data, 1, USEC_PER_SEC))
-		pr_err("%s: error writing %#x to %d:%#x\n", drv->name,
-		       data, tcs_id, reg);
+
+	/*
+	 * Wait until we read back the same value.  Use a counter rather than
+	 * ktime for timeout since this may be called after timekeeping stops.
+	 */
+	for (i = 0; i < USEC_PER_SEC; i++) {
+		if (readl(tcs_reg_addr(drv, reg, tcs_id)) == data)
+			return;
+		udelay(1);
+	}
+	pr_err("%s: error writing %#x to %d:%#x\n", drv->name,
+	       data, tcs_id, reg);
 }
 
 /**