mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pankaj Patil <pankaj.patil@oss.qualcomm.com>
To: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>,
	Amit Kucheria <amitk@kernel.org>,
	Thara Gopinath <thara.gopinath@gmail.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Daniel Lezcano <daniel.lezcano@kernel.org>,
	Zhang Rui <rui.zhang@intel.com>,
	Lukasz Luba <lukasz.luba@arm.com>,
	Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org, kamal.wadhwa@oss.qualcomm.com
Subject: Re: [PATCH v3] thermal: qcom-spmi-adc-tm5-gen3: move hardirq actions into threaded handler
Date: Tue, 24 Nov 2026 17:39:45 +0530	[thread overview]
Message-ID: <8d6ab328-32f1-4ddf-bff6-05f7d58d3222@oss.qualcomm.com> (raw)
In-Reply-To: <20261124-adctm5_gen3_hardirq_removal-v3-1-c7923e9a54c1@oss.qualcomm.com>

On 11/24/2026 2:33 PM, Jishnu Prakash wrote:
> adc_tm5_probe() registers the ADC_TM interrupt with both a primary
> handler and thread function (adctm5_gen3_isr/adctm5_gen3_isr_thread)
> with IRQF_ONESHOT. The primary handler calls adc5_gen3_read(), which
> takes the SPMI regmap's lock (a regular, non-raw spinlock) from hardirq
> context. With CONFIG_PROVE_LOCKING enabled, this leads to a warning
> about an attempt to take a lock in an invalid wait context:
> 
>   swapper/0/0 is trying to lock:
>   ffff000b67201018
>   (qcom_spmi_pmic:259:(&spmi_regmap_config)->lock){....}-{3:3}, at:
>   regmap_lock_spinlock+0x20/0x40
>   other info that might help us debug this:
>   context-{2:2}
> 
>   Call trace:
>   regmap_lock_spinlock+0x20/0x40
>   regmap_raw_read+0x88/0x328
>   regmap_bulk_read+0x10c/0x340
>   adc5_gen3_read+0x38/0x50 [qcom_spmi_adc5_gen3]
>   adctm5_gen3_isr+0x90/0x130 [qcom_spmi_adc_tm5_gen3]
> 
> There is no requirement for any of the work done in the primary handler
> to run in hardirq context. Drop the primary handler and move all the
> actions in it to the threaded handler, which removes the invalid wait
> context warning.
> 
> Note that both handlers used a local variable to hold the index of the
> SDAM whose IRQ was triggered ('sdam_num' in the primary handler and
> 'sdam_index' in the thread function). These are the same value under
> different names and 'sdam_index' is kept now, since the variable
> represents an index, not a count.
> 
> Reported-by: Pankaj Patil <pankaj.patil@oss.qualcomm.com>
> Closes: https://lore.kernel.org/all/1cb6d902-73f3-4d65-96f4-4b3c5217253c@oss.qualcomm.com/
> Fixes: 948ee3a74f35 ("thermal/drivers/qcom: add support for PMIC5 Gen3 ADC thermal monitoring")
> Signed-off-by: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>
> ---
> Changes in v3:
> - Updated commit message with right justification for using the variable
>   name 'sdam_index' and moved its declaration to separate line in
>   adctm5_gen3_isr_thread(), as suggested by Andy.
> - Link to v2: https://patch.msgid.link/20261113-adctm5_gen3_hardirq_removal-v2-1-a0c9c4800941@oss.qualcomm.com
> 
> Changes in v2:
> - Trimmed call stack and error lines and added clarification about sdam_index
>   in commit message, as suggested by Andy.
> - Link to v1: https://patch.msgid.link/20261111-adctm5_gen3_hardirq_removal-v1-1-536ed503396c@oss.qualcomm.com
> ---
>  drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c | 42 +++++++--------------------
>  1 file changed, 11 insertions(+), 31 deletions(-)
> 
> diff --git a/drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c b/drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c
> index 910b241fa94d..9e9019f5009d 100644
> --- a/drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c
> +++ b/drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c
> @@ -73,58 +73,39 @@ static int get_sdam_from_irq(struct adc_tm5_gen3_chip *adc_tm5, int irq)
>  	return -ENOENT;
>  }
>  
> -static irqreturn_t adctm5_gen3_isr(int irq, void *dev_id)
> +static irqreturn_t adctm5_gen3_isr_thread(int irq, void *dev_id)
>  {
>  	struct adc_tm5_gen3_chip *adc_tm5 = dev_id;
> -	int ret, sdam_num;
>  	u8 tm_status[2];
>  	u8 status, val;
> +	int sdam_index;
> +	int ret;
>  
> -	sdam_num = get_sdam_from_irq(adc_tm5, irq);
> -	if (sdam_num < 0)
> +	sdam_index = get_sdam_from_irq(adc_tm5, irq);
> +	if (sdam_index < 0)
>  		return IRQ_NONE;
>  
> -	ret = adc5_gen3_read(adc_tm5->dev_data, sdam_num, ADC5_GEN3_STATUS1,
> +	ret = adc5_gen3_read(adc_tm5->dev_data, sdam_index, ADC5_GEN3_STATUS1,
>  			     &status, sizeof(status));
>  	if (ret)
>  		return IRQ_NONE;
>  
>  	if (status & ADC5_GEN3_STATUS1_CONV_FAULT) {
>  		val = ADC5_GEN3_CONV_ERR_CLR_REQ;
> -		adc5_gen3_status_clear(adc_tm5->dev_data, sdam_num,
> +		adc5_gen3_status_clear(adc_tm5->dev_data, sdam_index,
>  				       ADC5_GEN3_CONV_ERR_CLR, &val, 1);
>  		return IRQ_HANDLED;
>  	}
>  
> -	ret = adc5_gen3_read(adc_tm5->dev_data, sdam_num, ADC5_GEN3_TM_HIGH_STS,
> -			     tm_status, sizeof(tm_status));
> -	if (ret)
> -		return IRQ_NONE;
> -
> -	if (tm_status[0] || tm_status[1])
> -		return IRQ_WAKE_THREAD;
> -
> -	return IRQ_NONE;
> -}
> -
> -static irqreturn_t adctm5_gen3_isr_thread(int irq, void *dev_id)
> -{
> -	struct adc_tm5_gen3_chip *adc_tm5 = dev_id;
> -	u8 tm_status[2];
> -	int sdam_index;
> -
> -	sdam_index = get_sdam_from_irq(adc_tm5, irq);
> -	if (sdam_index < 0)
> -		return IRQ_NONE;
> -
>  	scoped_guard(adc5_gen3, adc_tm5) {
> -		int ret;
> -
>  		ret = adc5_gen3_read(adc_tm5->dev_data, sdam_index, ADC5_GEN3_TM_HIGH_STS,
>  				     tm_status, sizeof(tm_status));
>  		if (ret)
>  			return IRQ_NONE;
>  
> +		if (!(tm_status[0] || tm_status[1]))
> +			return IRQ_NONE;
> +
>  		ret = adc5_gen3_status_clear(adc_tm5->dev_data, sdam_index,
>  					     ADC5_GEN3_TM_HIGH_STS_CLR, tm_status,
>  					     sizeof(tm_status));
> @@ -405,8 +386,7 @@ static int adc_tm5_probe(struct auxiliary_device *aux_dev,
>  
>  		ret = devm_request_threaded_irq(dev,
>  						adc_tm5->dev_data->base[i].irq,
> -						adctm5_gen3_isr,
> -						adctm5_gen3_isr_thread,
> +						NULL, adctm5_gen3_isr_thread,
>  						irq_flags,
>  						adc_tm5->dev_data->base[i].irq_name,
>  						adc_tm5);
> 
> ---
> base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
> change-id: 20261111-adctm5_gen3_hardirq_removal-467a437a78e1
> 
> Best regards,
> --  
> Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>
> 

Tested on Glymur-CRD
Tested-by: Pankaj Patil <pankaj.patil@oss.qualcomm.com>


      parent reply	other threads:[~2026-11-24 12:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  9:03 Jishnu Prakash
2026-11-24  9:53 ` Andy Shevchenko
2026-11-24 12:09 ` Pankaj Patil [this message]

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=8d6ab328-32f1-4ddf-bff6-05f7d58d3222@oss.qualcomm.com \
    --to=pankaj.patil@oss.qualcomm.com \
    --cc=amitk@kernel.org \
    --cc=andriy.shevchenko@intel.com \
    --cc=daniel.lezcano@kernel.org \
    --cc=jishnu.prakash@oss.qualcomm.com \
    --cc=kamal.wadhwa@oss.qualcomm.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=thara.gopinath@gmail.com \
    /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

all inboxes | Powered by JetHome®