netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Andersson <bjorn.andersson@linaro.org>
To: Alex Elder <elder@linaro.org>
Cc: davem@davemloft.net, kuba@kernel.org, evgreen@chromium.org,
	subashab@codeaurora.org, cpratapa@codeaurora.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v2 3/7] net: ipa: verify reference flag values
Date: Sat, 12 Sep 2020 21:25:30 -0500	[thread overview]
Message-ID: <20200913022530.GL3715@yoga> (raw)
In-Reply-To: <20200912004532.1386-4-elder@linaro.org>

On Fri 11 Sep 19:45 CDT 2020, Alex Elder wrote:

> We take a single IPA clock reference to keep the clock running until
> we get a system suspend operation, and maintain a flag indicating
> whether that reference has been taken.  When a suspend request
> arrives, we drop that reference and clear the flag.
> 
> In most places we simply set or clear the extra-reference flag.
> Instead--primarily to catch coding errors--test the previous value
> of the flag and report an error in the event the previous value is
> unexpected.  And if the clock reference is already taken, don't take
> another.
> 
> In a couple of cases it's pretty clear atomic access is not
> necessary and an error should never be reported.  Report these
> anyway, conveying our surprise with an added exclamation point.
> 
> Signed-off-by: Alex Elder <elder@linaro.org>
> ---
> v2: Updated to operate on a bitmap bit rather than an atomic_t.
> 
>  drivers/net/ipa/ipa_main.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/ipa/ipa_main.c b/drivers/net/ipa/ipa_main.c
> index 409375b96eb8f..cfdf60ded86ca 100644
> --- a/drivers/net/ipa/ipa_main.c
> +++ b/drivers/net/ipa/ipa_main.c
> @@ -83,6 +83,7 @@ static void ipa_suspend_handler(struct ipa *ipa, enum ipa_irq_id irq_id)
>  	/* Take a a single clock reference to prevent suspend.  All
>  	 * endpoints will be resumed as a result.  This reference will
>  	 * be dropped when we get a power management suspend request.
> +	 * The first call activates the clock; ignore any others.
>  	 */
>  	if (!test_and_set_bit(IPA_FLAG_CLOCK_HELD, ipa->flags))
>  		ipa_clock_get(ipa);
> @@ -502,14 +503,17 @@ static void ipa_resource_deconfig(struct ipa *ipa)
>   */
>  static int ipa_config(struct ipa *ipa, const struct ipa_data *data)
>  {
> +	struct device *dev = &ipa->pdev->dev;
>  	int ret;
>  
>  	/* Get a clock reference to allow initialization.  This reference
>  	 * is held after initialization completes, and won't get dropped
>  	 * unless/until a system suspend request arrives.
>  	 */
> -	__set_bit(IPA_FLAG_CLOCK_HELD, ipa->flags);
> -	ipa_clock_get(ipa);
> +	if (!__test_and_set_bit(IPA_FLAG_CLOCK_HELD, ipa->flags))
> +		ipa_clock_get(ipa);
> +	else
> +		dev_err(dev, "suspend clock reference already taken!\n");
>  
>  	ipa_hardware_config(ipa);
>  
> @@ -544,7 +548,8 @@ static int ipa_config(struct ipa *ipa, const struct ipa_data *data)
>  err_hardware_deconfig:
>  	ipa_hardware_deconfig(ipa);
>  	ipa_clock_put(ipa);
> -	__clear_bit(IPA_FLAG_CLOCK_HELD, ipa->flags);
> +	if (!__test_and_clear_bit(IPA_FLAG_CLOCK_HELD, ipa->flags))
> +		dev_err(dev, "suspend clock reference already dropped!\n");
>  
>  	return ret;
>  }
> @@ -562,7 +567,8 @@ static void ipa_deconfig(struct ipa *ipa)
>  	ipa_endpoint_deconfig(ipa);
>  	ipa_hardware_deconfig(ipa);
>  	ipa_clock_put(ipa);
> -	__clear_bit(IPA_FLAG_CLOCK_HELD, ipa->flags);
> +	if (!test_and_clear_bit(IPA_FLAG_CLOCK_HELD, ipa->flags))

Doesn't this imply that we ran with the clocks disabled, which
presumably would have nasty side effects?

This seems like something that is worthy of more than just a simple
printout - which no one will actually read.  If you instead use a
WARN_ON() to highlight this at least some of the test environments out
there will pick it up and report it...

Regards,
Bjorn

> +		dev_err(&ipa->pdev->dev, "no suspend clock reference\n");
>  }
>  
>  static int ipa_firmware_load(struct device *dev)
> @@ -913,7 +919,8 @@ static int ipa_suspend(struct device *dev)
>  	struct ipa *ipa = dev_get_drvdata(dev);
>  
>  	ipa_clock_put(ipa);
> -	__clear_bit(IPA_FLAG_CLOCK_HELD, ipa->flags);
> +	if (!test_and_clear_bit(IPA_FLAG_CLOCK_HELD, ipa->flags))
> +		dev_err(dev, "suspend: missing suspend clock reference\n");
>  
>  	return 0;
>  }
> @@ -933,8 +940,10 @@ static int ipa_resume(struct device *dev)
>  	/* This clock reference will keep the IPA out of suspend
>  	 * until we get a power management suspend request.
>  	 */
> -	__set_bit(IPA_FLAG_CLOCK_HELD, ipa->flags);
> -	ipa_clock_get(ipa);
> +	if (!test_and_set_bit(IPA_FLAG_CLOCK_HELD, ipa->flags))
> +		ipa_clock_get(ipa);
> +	else
> +		dev_err(dev, "resume: duplicate suspend clock reference\n");
>  
>  	return 0;
>  }
> -- 
> 2.20.1
> 

  reply	other threads:[~2020-09-13  2:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-12  0:45 [PATCH net-next v2 0/7] net: ipa: wake up system on RX available Alex Elder
2020-09-12  0:45 ` [PATCH net-next v2 1/7] net: ipa: use refcount_t for IPA clock reference count Alex Elder
2020-09-12  0:45 ` [PATCH net-next v2 2/7] net: ipa: replace ipa->suspend_ref with a flag bit Alex Elder
2020-09-12  0:45 ` [PATCH net-next v2 3/7] net: ipa: verify reference flag values Alex Elder
2020-09-13  2:25   ` Bjorn Andersson [this message]
2020-09-13 13:36     ` Alex Elder
2020-09-12  0:45 ` [PATCH net-next v2 4/7] net: ipa: manage endpoints separate from clock Alex Elder
2020-09-13  2:30   ` Bjorn Andersson
2020-09-12  0:45 ` [PATCH net-next v2 5/7] net: ipa: use device_init_wakeup() Alex Elder
2020-09-13  2:27   ` Bjorn Andersson
2020-09-12  0:45 ` [PATCH net-next v2 6/7] net: ipa: enable wakeup on IPA interrupt Alex Elder
2020-09-13  2:47   ` Bjorn Andersson
2020-09-12  0:45 ` [PATCH net-next v2 7/7] net: ipa: do not enable GSI interrupt for wakeup Alex Elder
2020-09-13  2:50   ` Bjorn Andersson

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=20200913022530.GL3715@yoga \
    --to=bjorn.andersson@linaro.org \
    --cc=cpratapa@codeaurora.org \
    --cc=davem@davemloft.net \
    --cc=elder@linaro.org \
    --cc=evgreen@chromium.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=subashab@codeaurora.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;
as well as URLs for NNTP newsgroup(s).