All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ray Jui <ray.jui@broadcom.com>
To: Chengfeng Ye <dg573847474@gmail.com>,
	andi.shyti@kernel.org, rjui@broadcom.com, sbranden@broadcom.com,
	wsa@kernel.org
Cc: bcm-kernel-feedback-list@broadcom.com, linux-i2c@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] i2c: bcm-iproc: Fix bcm_iproc_i2c_isr deadlock issue
Date: Fri, 7 Jul 2023 08:50:38 -0700	[thread overview]
Message-ID: <6e6d8cfd-63fd-f3b5-7ab0-a4d99895a17c@broadcom.com> (raw)
In-Reply-To: <20230707084941.28964-1-dg573847474@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2088 bytes --]



On 7/7/2023 1:49 AM, Chengfeng Ye wrote:
> iproc_i2c_rd_reg() and iproc_i2c_wr_reg() are called from both
> interrupt context (e.g. bcm_iproc_i2c_isr) and process context
> (e.g. bcm_iproc_i2c_suspend). Therefore, interrupts should be
> disabled to avoid potential deadlock. To prevent this scenario,
> use spin_lock_irqsave().
> 
> Fixes: 9a1038728037 ("i2c: iproc: add NIC I2C support")
> Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
> ---
>  drivers/i2c/busses/i2c-bcm-iproc.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c
> index 85d8a6b04885..30a2a3200bed 100644
> --- a/drivers/i2c/busses/i2c-bcm-iproc.c
> +++ b/drivers/i2c/busses/i2c-bcm-iproc.c
> @@ -233,13 +233,14 @@ static inline u32 iproc_i2c_rd_reg(struct bcm_iproc_i2c_dev *iproc_i2c,
>  				   u32 offset)
>  {
>  	u32 val;
> +	unsigned long flags;
>  
>  	if (iproc_i2c->idm_base) {
> -		spin_lock(&iproc_i2c->idm_lock);
> +		spin_lock_irqsave(&iproc_i2c->idm_lock, flags);
>  		writel(iproc_i2c->ape_addr_mask,
>  		       iproc_i2c->idm_base + IDM_CTRL_DIRECT_OFFSET);
>  		val = readl(iproc_i2c->base + offset);
> -		spin_unlock(&iproc_i2c->idm_lock);
> +		spin_unlock_irqrestore(&iproc_i2c->idm_lock, flags);
>  	} else {
>  		val = readl(iproc_i2c->base + offset);
>  	}
> @@ -250,12 +251,14 @@ static inline u32 iproc_i2c_rd_reg(struct bcm_iproc_i2c_dev *iproc_i2c,
>  static inline void iproc_i2c_wr_reg(struct bcm_iproc_i2c_dev *iproc_i2c,
>  				    u32 offset, u32 val)
>  {
> +	unsigned long flags;
> +
>  	if (iproc_i2c->idm_base) {
> -		spin_lock(&iproc_i2c->idm_lock);
> +		spin_lock_irqsave(&iproc_i2c->idm_lock, flags);
>  		writel(iproc_i2c->ape_addr_mask,
>  		       iproc_i2c->idm_base + IDM_CTRL_DIRECT_OFFSET);
>  		writel(val, iproc_i2c->base + offset);
> -		spin_unlock(&iproc_i2c->idm_lock);
> +		spin_unlock_irqrestore(&iproc_i2c->idm_lock, flags);
>  	} else {
>  		writel(val, iproc_i2c->base + offset);
>  	}

Acked-by: Ray Jui <ray.jui@broadcom.com>

Thanks, Chengfeng.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4194 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Ray Jui <ray.jui@broadcom.com>
To: Chengfeng Ye <dg573847474@gmail.com>,
	andi.shyti@kernel.org, rjui@broadcom.com, sbranden@broadcom.com,
	wsa@kernel.org
Cc: bcm-kernel-feedback-list@broadcom.com, linux-i2c@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] i2c: bcm-iproc: Fix bcm_iproc_i2c_isr deadlock issue
Date: Fri, 7 Jul 2023 08:50:38 -0700	[thread overview]
Message-ID: <6e6d8cfd-63fd-f3b5-7ab0-a4d99895a17c@broadcom.com> (raw)
In-Reply-To: <20230707084941.28964-1-dg573847474@gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 2088 bytes --]



On 7/7/2023 1:49 AM, Chengfeng Ye wrote:
> iproc_i2c_rd_reg() and iproc_i2c_wr_reg() are called from both
> interrupt context (e.g. bcm_iproc_i2c_isr) and process context
> (e.g. bcm_iproc_i2c_suspend). Therefore, interrupts should be
> disabled to avoid potential deadlock. To prevent this scenario,
> use spin_lock_irqsave().
> 
> Fixes: 9a1038728037 ("i2c: iproc: add NIC I2C support")
> Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
> ---
>  drivers/i2c/busses/i2c-bcm-iproc.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c
> index 85d8a6b04885..30a2a3200bed 100644
> --- a/drivers/i2c/busses/i2c-bcm-iproc.c
> +++ b/drivers/i2c/busses/i2c-bcm-iproc.c
> @@ -233,13 +233,14 @@ static inline u32 iproc_i2c_rd_reg(struct bcm_iproc_i2c_dev *iproc_i2c,
>  				   u32 offset)
>  {
>  	u32 val;
> +	unsigned long flags;
>  
>  	if (iproc_i2c->idm_base) {
> -		spin_lock(&iproc_i2c->idm_lock);
> +		spin_lock_irqsave(&iproc_i2c->idm_lock, flags);
>  		writel(iproc_i2c->ape_addr_mask,
>  		       iproc_i2c->idm_base + IDM_CTRL_DIRECT_OFFSET);
>  		val = readl(iproc_i2c->base + offset);
> -		spin_unlock(&iproc_i2c->idm_lock);
> +		spin_unlock_irqrestore(&iproc_i2c->idm_lock, flags);
>  	} else {
>  		val = readl(iproc_i2c->base + offset);
>  	}
> @@ -250,12 +251,14 @@ static inline u32 iproc_i2c_rd_reg(struct bcm_iproc_i2c_dev *iproc_i2c,
>  static inline void iproc_i2c_wr_reg(struct bcm_iproc_i2c_dev *iproc_i2c,
>  				    u32 offset, u32 val)
>  {
> +	unsigned long flags;
> +
>  	if (iproc_i2c->idm_base) {
> -		spin_lock(&iproc_i2c->idm_lock);
> +		spin_lock_irqsave(&iproc_i2c->idm_lock, flags);
>  		writel(iproc_i2c->ape_addr_mask,
>  		       iproc_i2c->idm_base + IDM_CTRL_DIRECT_OFFSET);
>  		writel(val, iproc_i2c->base + offset);
> -		spin_unlock(&iproc_i2c->idm_lock);
> +		spin_unlock_irqrestore(&iproc_i2c->idm_lock, flags);
>  	} else {
>  		writel(val, iproc_i2c->base + offset);
>  	}

Acked-by: Ray Jui <ray.jui@broadcom.com>

Thanks, Chengfeng.

[-- Attachment #1.2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4194 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2023-07-07 15:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-07  8:49 [PATCH v2] i2c: bcm-iproc: Fix bcm_iproc_i2c_isr deadlock issue Chengfeng Ye
2023-07-07  8:49 ` Chengfeng Ye
2023-07-07 15:50 ` Ray Jui [this message]
2023-07-07 15:50   ` Ray Jui
2023-07-27 20:43 ` Andi Shyti
2023-07-27 20:43   ` Andi Shyti
2023-08-14 16:17 ` Wolfram Sang
2023-08-14 16:17   ` Wolfram Sang

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=6e6d8cfd-63fd-f3b5-7ab0-a4d99895a17c@broadcom.com \
    --to=ray.jui@broadcom.com \
    --cc=andi.shyti@kernel.org \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=dg573847474@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rjui@broadcom.com \
    --cc=sbranden@broadcom.com \
    --cc=wsa@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.