* [PATCH RESEND] i2c: bcm-iproc: Fix bcm_iproc_i2c_isr deadlock issue
@ 2023-07-06 21:14 Chengfeng Ye
2023-07-06 21:21 ` Chengfeng Ye
2023-07-06 23:02 ` Scott Branden
0 siblings, 2 replies; 5+ messages in thread
From: Chengfeng Ye @ 2023-07-06 21:14 UTC (permalink / raw)
To: andi.shyti, rjui, sbranden, wsa
Cc: bcm-kernel-feedback-list, linux-i2c, linux-arm-kernel,
linux-kernel, Chengfeng Ye
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.
Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
---
drivers/i2c/busses/i2c-bcm-iproc.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c
index 85d8a6b04885..d02245e4db8c 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,13 @@ 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);
}
--
2.17.1
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH RESEND] i2c: bcm-iproc: Fix bcm_iproc_i2c_isr deadlock issue
2023-07-06 21:14 [PATCH RESEND] i2c: bcm-iproc: Fix bcm_iproc_i2c_isr deadlock issue Chengfeng Ye
@ 2023-07-06 21:21 ` Chengfeng Ye
2023-07-06 23:19 ` Ray Jui
2023-07-06 23:02 ` Scott Branden
1 sibling, 1 reply; 5+ messages in thread
From: Chengfeng Ye @ 2023-07-06 21:21 UTC (permalink / raw)
To: andi.shyti, rjui, sbranden, wsa
Cc: bcm-kernel-feedback-list, linux-i2c, linux-arm-kernel, linux-kernel
Hi Ray and Wolfram,
> I can't apply it, what version is this against?
The patch is based on 6.4-rc7. I resend the patch with this
email because I had some problems setting up the previous
one with git send-email. That patch was manually pasted
so that might be the reason for not being able to be applied.
Best Regards,
Chengfeng
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RESEND] i2c: bcm-iproc: Fix bcm_iproc_i2c_isr deadlock issue
2023-07-06 21:21 ` Chengfeng Ye
@ 2023-07-06 23:19 ` Ray Jui
2023-07-07 8:52 ` Chengfeng Ye
0 siblings, 1 reply; 5+ messages in thread
From: Ray Jui @ 2023-07-06 23:19 UTC (permalink / raw)
To: Chengfeng Ye, andi.shyti, rjui, sbranden, wsa
Cc: bcm-kernel-feedback-list, linux-i2c, linux-arm-kernel, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 616 bytes --]
On 7/6/2023 2:21 PM, Chengfeng Ye wrote:
> Hi Ray and Wolfram,
>
>> I can't apply it, what version is this against?
>
> The patch is based on 6.4-rc7. I resend the patch with this
> email because I had some problems setting up the previous
> one with git send-email. That patch was manually pasted
> so that might be the reason for not being able to be applied.
>
> Best Regards,
> Chengfeng
I saw your latest patch. You should use prefix of [PATCH V2]
instead of [PATCH RESEND].
Also, can you please add the fix tag I identified to your commit
message. That will save Wolfram some
manual work.
Thanks,
Ray
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4194 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RESEND] i2c: bcm-iproc: Fix bcm_iproc_i2c_isr deadlock issue
2023-07-06 23:19 ` Ray Jui
@ 2023-07-07 8:52 ` Chengfeng Ye
0 siblings, 0 replies; 5+ messages in thread
From: Chengfeng Ye @ 2023-07-07 8:52 UTC (permalink / raw)
To: Ray Jui, andi.shyti, rjui, sbranden, wsa
Cc: bcm-kernel-feedback-list, linux-i2c, linux-arm-kernel, linux-kernel
> Also, can you please add the fix tag I identified to your commit
> message. That will save Wolfram some
> manual work.
> Add newline after variable declarations.
Thanks for the reply.
Fixed these problems in v2 patch.
Best Regards,
Chengfeng
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RESEND] i2c: bcm-iproc: Fix bcm_iproc_i2c_isr deadlock issue
2023-07-06 21:14 [PATCH RESEND] i2c: bcm-iproc: Fix bcm_iproc_i2c_isr deadlock issue Chengfeng Ye
2023-07-06 21:21 ` Chengfeng Ye
@ 2023-07-06 23:02 ` Scott Branden
1 sibling, 0 replies; 5+ messages in thread
From: Scott Branden @ 2023-07-06 23:02 UTC (permalink / raw)
To: Chengfeng Ye, andi.shyti, rjui, sbranden, wsa
Cc: bcm-kernel-feedback-list, linux-i2c, linux-arm-kernel, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2062 bytes --]
Some comments inline
On 2023-07-06 14:14, 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.
>
Add Fixes: tag here.
> Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
> ---
> drivers/i2c/busses/i2c-bcm-iproc.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c
> index 85d8a6b04885..d02245e4db8c 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,13 @@ 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;
Add newline after variable declarations.
> 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);
> }
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4212 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-07-07 8:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-06 21:14 [PATCH RESEND] i2c: bcm-iproc: Fix bcm_iproc_i2c_isr deadlock issue Chengfeng Ye
2023-07-06 21:21 ` Chengfeng Ye
2023-07-06 23:19 ` Ray Jui
2023-07-07 8:52 ` Chengfeng Ye
2023-07-06 23:02 ` Scott Branden
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®