mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maulik Shah <mkshah@codeaurora.org>
To: Douglas Anderson <dianders@chromium.org>,
	Andy Gross <agross@kernel.org>,
	Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: mka@chromium.org, Lina Iyer <ilina@codeaurora.org>,
	Rajendra Nayak <rnayak@codeaurora.org>,
	swboyd@chromium.org, evgreen@chromium.org,
	linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 09/10] drivers: qcom: rpmh-rsc: Caller handles tcs_invalidate() exclusivity
Date: Wed, 8 Apr 2020 18:59:10 +0530	[thread overview]
Message-ID: <6b141a7a-8347-d1a2-b115-5baf0b788820@codeaurora.org> (raw)
In-Reply-To: <20200407164915.v3.9.I07c1f70e0e8f2dc0004bd38970b4e258acdc773e@changeid>

Hi,

On 4/8/2020 5:20 AM, Douglas Anderson wrote:
> Auditing tcs_invalidate() made me worried.  Specifically I saw that it
> used spin_lock(), not spin_lock_irqsave().  That always worries me
> unless I can trace for sure that I'm in the interrupt handler or that
> someone else already disabled interrupts.
>
> Looking more at it, there is actually no reason for these locks
> anyway.  Specifically the only reason you'd ever call
> rpmh_rsc_invalidate() is if you cared that the sleep/wake TCSes were
> empty.  That means that they need to continue to be empty even after
> rpmh_rsc_invalidate() returns.  The only way that can happen is if the
> caller already has done something to keep all other RPMH users out.
> It should be noted that even though the caller is only worried about
> making sleep/wake TCSes empty, they also need to worry about stopping
> active-only transfers if they need to handle the case where
> active-only transfers might borrow the wake TCS.
>
> At the moment rpmh_rsc_invalidate() is only called in PM code from the
> last CPU.  If that later changes the caller will still need to solve
> the above problems themselves, so these locks will never be useful.
>
> Continuing to audit tcs_invalidate(), I found a bug.  The function
> didn't properly check for a borrowed TCS if we hadn't recently written
> anything into the TCS.  Specifically, if we've never written to the
> WAKE_TCS (or we've flushed it recently) then tcs->slots is empty.
> We'll early-out and we'll never call tcs_is_free().
>
> I thought about fixing this bug by either deleting the early check for
> bitmap_empty() or possibly only doing it if we knew we weren't on a
> TCS that could be borrowed.  However, I think it's better to just
> delete the checks.
>
> As argued above it's up to the caller to make sure that all other
> users of RPMH are quiet before tcs_invalidate() is called.  Since
> callers need to handle the zero-active-TCS case anyway that means they
> need to make sure that make sure the active-only transfers are quiet

make sure is twice, can you please drop once.

need to make sure that the active-only.....

other than this.

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

Thanks,
Maulik

> before calling too.  The one way tcs_invalidate() gets called today is
> through rpmh_rsc_cpu_pm_callback() which calls
> rpmh_rsc_ctrlr_is_busy() to handle this.  When we have another path to
> get to tcs_invalidate() it will also need to come up with something
> similar and it won't need this extra check either.  If we later find
> some code path that actually needs this check back in (and somehow
> manages to be race free) we can always add it back in.
>
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> ---
>
> Changes in v3:
> - Replaced ("irqsave()...") + ("...never -EBUSY") w/ ("Caller handles...")
>
> Changes in v2: None
>
>   drivers/soc/qcom/rpmh-internal.h |  2 +-
>   drivers/soc/qcom/rpmh-rsc.c      | 38 +++++++++++---------------------
>   drivers/soc/qcom/rpmh.c          |  5 +----
>   3 files changed, 15 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/soc/qcom/rpmh-internal.h b/drivers/soc/qcom/rpmh-internal.h
> index f06350cbc9a2..dba8510c0669 100644
> --- a/drivers/soc/qcom/rpmh-internal.h
> +++ b/drivers/soc/qcom/rpmh-internal.h
> @@ -132,7 +132,7 @@ struct rsc_drv {
>   int rpmh_rsc_send_data(struct rsc_drv *drv, const struct tcs_request *msg);
>   int rpmh_rsc_write_ctrl_data(struct rsc_drv *drv,
>   			     const struct tcs_request *msg);
> -int rpmh_rsc_invalidate(struct rsc_drv *drv);
> +void rpmh_rsc_invalidate(struct rsc_drv *drv);
>   
>   void rpmh_tx_done(const struct tcs_request *msg, int r);
>   int rpmh_flush(struct rpmh_ctrlr *ctrlr);
> diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c
> index 10c026b2e1bc..a3b015196f15 100644
> --- a/drivers/soc/qcom/rpmh-rsc.c
> +++ b/drivers/soc/qcom/rpmh-rsc.c
> @@ -198,50 +198,38 @@ static bool tcs_is_free(struct rsc_drv *drv, int tcs_id)
>    * This will clear the "slots" variable of the given tcs_group and also
>    * tell the hardware to forget about all entries.
>    *
> - * Return: 0 if no problem, or -EAGAIN if the caller should try again in a
> - *         bit. Caller should make sure to enable interrupts between tries.
> + * The caller must ensure that no other RPMH actions are happening when this
> + * function is called, since otherwise the device may immediately become
> + * used again even before this function exits.
>    */
> -static int tcs_invalidate(struct rsc_drv *drv, int type)
> +static void tcs_invalidate(struct rsc_drv *drv, int type)
>   {
>   	int m;
>   	struct tcs_group *tcs = &drv->tcs[type];
>   
> -	spin_lock(&tcs->lock);
> -	if (bitmap_empty(tcs->slots, MAX_TCS_SLOTS)) {
> -		spin_unlock(&tcs->lock);
> -		return 0;
> -	}
> +	/* Caller ensures nobody else is running so no lock */
> +	if (bitmap_empty(tcs->slots, MAX_TCS_SLOTS))
> +		return;
>   
>   	for (m = tcs->offset; m < tcs->offset + tcs->num_tcs; m++) {
> -		if (!tcs_is_free(drv, m)) {
> -			spin_unlock(&tcs->lock);
> -			return -EAGAIN;
> -		}
>   		write_tcs_reg_sync(drv, RSC_DRV_CMD_ENABLE, m, 0);
>   		write_tcs_reg_sync(drv, RSC_DRV_CMD_WAIT_FOR_CMPL, m, 0);
>   	}
>   	bitmap_zero(tcs->slots, MAX_TCS_SLOTS);
> -	spin_unlock(&tcs->lock);
> -
> -	return 0;
>   }
>   
>   /**
>    * rpmh_rsc_invalidate() - Invalidate sleep and wake TCSes.
>    * @drv: The RSC controller.
>    *
> - * Return: 0 if no problem, or -EAGAIN if the caller should try again in a
> - *         bit. Caller should make sure to enable interrupts between tries.
> + * The caller must ensure that no other RPMH actions are happening when this
> + * function is called, since otherwise the device may immediately become
> + * used again even before this function exits.
>    */
> -int rpmh_rsc_invalidate(struct rsc_drv *drv)
> +void rpmh_rsc_invalidate(struct rsc_drv *drv)
>   {
> -	int ret;
> -
> -	ret = tcs_invalidate(drv, SLEEP_TCS);
> -	if (!ret)
> -		ret = tcs_invalidate(drv, WAKE_TCS);
> -
> -	return ret;
> +	tcs_invalidate(drv, SLEEP_TCS);
> +	tcs_invalidate(drv, WAKE_TCS);
>   }
>   
>   /**
> diff --git a/drivers/soc/qcom/rpmh.c b/drivers/soc/qcom/rpmh.c
> index 88f88015ef03..02171c192aa1 100644
> --- a/drivers/soc/qcom/rpmh.c
> +++ b/drivers/soc/qcom/rpmh.c
> @@ -439,7 +439,6 @@ static int send_single(struct rpmh_ctrlr *ctrlr, enum rpmh_state state,
>    *
>    * Return:
>    * * 0          - Success
> - * * -EAGAIN    - Retry again
>    * * Error code - Otherwise
>    */
>   int rpmh_flush(struct rpmh_ctrlr *ctrlr)
> @@ -453,9 +452,7 @@ int rpmh_flush(struct rpmh_ctrlr *ctrlr)
>   	}
>   
>   	/* Invalidate the TCSes first to avoid stale data */
> -	ret = rpmh_rsc_invalidate(ctrlr_to_drv(ctrlr));
> -	if (ret)
> -		return ret;
> +	rpmh_rsc_invalidate(ctrlr_to_drv(ctrlr));
>   
>   	/* First flush the cached batch requests */
>   	ret = flush_batch(ctrlr);

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

  reply	other threads:[~2020-04-08 13:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-07 23:50 [PATCH v3 00/10] drivers: qcom: rpmh-rsc: Cleanup / add lots of comments Douglas Anderson
2020-04-07 23:50 ` [PATCH v3 01/10] drivers: qcom: rpmh-rsc: Clean code reading/writing TCS regs/cmds Douglas Anderson
2020-04-07 23:50 ` [PATCH v3 02/10] drivers: qcom: rpmh-rsc: Document the register layout better Douglas Anderson
2020-04-08 10:59   ` Maulik Shah
2020-04-07 23:50 ` [PATCH v3 03/10] drivers: qcom: rpmh-rsc: Fold tcs_ctrl_write() into its single caller Douglas Anderson
2020-04-07 23:50 ` [PATCH v3 04/10] drivers: qcom: rpmh-rsc: Remove get_tcs_of_type() abstraction Douglas Anderson
2020-04-07 23:50 ` [PATCH v3 05/10] drivers: qcom: rpmh-rsc: Kill cmd_cache and find_match() with fire Douglas Anderson
2020-04-08 11:11   ` Maulik Shah
2020-04-07 23:50 ` [PATCH v3 06/10] drivers: qcom: rpmh-rsc: A lot of comments Douglas Anderson
2020-04-08 11:25   ` Maulik Shah
2020-04-07 23:50 ` [PATCH v3 07/10] drivers: qcom: rpmh-rsc: tcs_is_free() can just check tcs_in_use Douglas Anderson
2020-04-08 11:25   ` Maulik Shah
2020-04-07 23:50 ` [PATCH v3 08/10] drivers: qcom: rpmh-rsc: Don't double-check rpmh Douglas Anderson
2020-04-08 12:23   ` Maulik Shah
2020-04-09  0:10     ` Doug Anderson
2020-04-07 23:50 ` [PATCH v3 09/10] drivers: qcom: rpmh-rsc: Caller handles tcs_invalidate() exclusivity Douglas Anderson
2020-04-08 13:29   ` Maulik Shah [this message]
2020-04-07 23:50 ` [PATCH v3 10/10] drivers: qcom: rpmh-rsc: read_tcs_reg()/write_tcs_reg() are not for IRQ Douglas Anderson
2020-04-08 13:32   ` Maulik Shah

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6b141a7a-8347-d1a2-b115-5baf0b788820@codeaurora.org \
    --to=mkshah@codeaurora.org \
    --cc=agross@kernel.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=dianders@chromium.org \
    --cc=evgreen@chromium.org \
    --cc=ilina@codeaurora.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mka@chromium.org \
    --cc=rnayak@codeaurora.org \
    --cc=swboyd@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome