linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] extcon: Release locking when sending the notification of connector state
       [not found] <CGME20180614041448epcas2p400dad902581dc6875461d4c3dd3a231d@epcas2p4.samsung.com>
@ 2018-06-14  4:14 ` Chanwoo Choi
  2018-06-14 10:18   ` Chanwoo Choi
  2018-06-15  7:01   ` Roger Quadros
  0 siblings, 2 replies; 7+ messages in thread
From: Chanwoo Choi @ 2018-06-14  4:14 UTC (permalink / raw)
  To: linux-kernel
  Cc: cw00.choi, chanwoo, myungjoo.ham, stable, Roger Quadros,
	Kishon Vijay Abraham I

Previously, extcon used the spinlock before calling the notifier_call_chain
to prevent the scheduled out of task and to prevent the notification delay.
When spinlock is locked for sending the notification, deadlock issue
occured on the side of extcon consumer device. To fix this issue,
extcon consumer device should always use the work. it is always not
reasonable to use work.

To fix this issue on extcon consumer device, release locking when sending
the notification of connector state.

Fixes: ab11af049f88 ("extcon: Add the synchronization extcon APIs to support the notification")
Cc: stable@vger.kernel.org
Cc: Roger Quadros <rogerq@ti.com>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
 drivers/extcon/extcon.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
index 8bff5fd18185..f75b08a45d4e 100644
--- a/drivers/extcon/extcon.c
+++ b/drivers/extcon/extcon.c
@@ -433,8 +433,8 @@ int extcon_sync(struct extcon_dev *edev, unsigned int id)
 		return index;
 
 	spin_lock_irqsave(&edev->lock, flags);
-
 	state = !!(edev->state & BIT(index));
+	spin_unlock_irqrestore(&edev->lock, flags);
 
 	/*
 	 * Call functions in a raw notifier chain for the specific one
@@ -448,6 +448,7 @@ int extcon_sync(struct extcon_dev *edev, unsigned int id)
 	 */
 	raw_notifier_call_chain(&edev->nh_all, state, edev);
 
+	spin_lock_irqsave(&edev->lock, flags);
 	/* This could be in interrupt handler */
 	prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);
 	if (!prop_buf) {
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] extcon: Release locking when sending the notification of connector state
  2018-06-14  4:14 ` [PATCH] extcon: Release locking when sending the notification of connector state Chanwoo Choi
@ 2018-06-14 10:18   ` Chanwoo Choi
  2018-06-14 10:39     ` H. Nikolaus Schaller
  2018-06-15  7:01   ` Roger Quadros
  1 sibling, 1 reply; 7+ messages in thread
From: Chanwoo Choi @ 2018-06-14 10:18 UTC (permalink / raw)
  To: linux-kernel
  Cc: chanwoo, myungjoo.ham, stable, Roger Quadros,
	Kishon Vijay Abraham I, H. Nikolaus Schaller

+ H. Nikolaus Schaller <hns@goldelico.com>

On 2018년 06월 14일 13:14, Chanwoo Choi wrote:
> Previously, extcon used the spinlock before calling the notifier_call_chain
> to prevent the scheduled out of task and to prevent the notification delay.
> When spinlock is locked for sending the notification, deadlock issue
> occured on the side of extcon consumer device. To fix this issue,
> extcon consumer device should always use the work. it is always not
> reasonable to use work.
> 
> To fix this issue on extcon consumer device, release locking when sending
> the notification of connector state.
> 
> Fixes: ab11af049f88 ("extcon: Add the synchronization extcon APIs to support the notification")
> Cc: stable@vger.kernel.org
> Cc: Roger Quadros <rogerq@ti.com>
> Cc: Kishon Vijay Abraham I <kishon@ti.com>
> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
> ---
>  drivers/extcon/extcon.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
> index 8bff5fd18185..f75b08a45d4e 100644
> --- a/drivers/extcon/extcon.c
> +++ b/drivers/extcon/extcon.c
> @@ -433,8 +433,8 @@ int extcon_sync(struct extcon_dev *edev, unsigned int id)
>  		return index;
>  
>  	spin_lock_irqsave(&edev->lock, flags);
> -
>  	state = !!(edev->state & BIT(index));
> +	spin_unlock_irqrestore(&edev->lock, flags);
>  
>  	/*
>  	 * Call functions in a raw notifier chain for the specific one
> @@ -448,6 +448,7 @@ int extcon_sync(struct extcon_dev *edev, unsigned int id)
>  	 */
>  	raw_notifier_call_chain(&edev->nh_all, state, edev);
>  
> +	spin_lock_irqsave(&edev->lock, flags);
>  	/* This could be in interrupt handler */
>  	prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);
>  	if (!prop_buf) {
> 


-- 
Best Regards,
Chanwoo Choi
Samsung Electronics

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] extcon: Release locking when sending the notification of connector state
  2018-06-14 10:18   ` Chanwoo Choi
@ 2018-06-14 10:39     ` H. Nikolaus Schaller
  2018-06-14 11:33       ` H. Nikolaus Schaller
  0 siblings, 1 reply; 7+ messages in thread
From: H. Nikolaus Schaller @ 2018-06-14 10:39 UTC (permalink / raw)
  To: Chanwoo Choi, Roger Quadros
  Cc: Linux Kernel Mailing List, chanwoo, myungjoo.ham, stable,
	Kishon Vijay Abraham I

Hi Roger and Chanwoo,

> Am 14.06.2018 um 12:18 schrieb Chanwoo Choi <cw00.choi@samsung.com>:
> 
> + H. Nikolaus Schaller <hns@goldelico.com>
> 
> On 2018년 06월 14일 13:14, Chanwoo Choi wrote:
>> Previously, extcon used the spinlock before calling the notifier_call_chain
>> to prevent the scheduled out of task and to prevent the notification delay.
>> When spinlock is locked for sending the notification, deadlock issue
>> occured on the side of extcon consumer device. To fix this issue,
>> extcon consumer device should always use the work. it is always not
>> reasonable to use work.
>> 
>> To fix this issue on extcon consumer device, release locking when sending
>> the notification of connector state.
>> 
>> Fixes: ab11af049f88 ("extcon: Add the synchronization extcon APIs to support the notification")
>> Cc: stable@vger.kernel.org
>> Cc: Roger Quadros <rogerq@ti.com>
>> Cc: Kishon Vijay Abraham I <kishon@ti.com>
>> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
>> ---
>> drivers/extcon/extcon.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>> 
>> diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
>> index 8bff5fd18185..f75b08a45d4e 100644
>> --- a/drivers/extcon/extcon.c
>> +++ b/drivers/extcon/extcon.c
>> @@ -433,8 +433,8 @@ int extcon_sync(struct extcon_dev *edev, unsigned int id)
>> 		return index;
>> 
>> 	spin_lock_irqsave(&edev->lock, flags);
>> -
>> 	state = !!(edev->state & BIT(index));
>> +	spin_unlock_irqrestore(&edev->lock, flags);
>> 
>> 	/*
>> 	 * Call functions in a raw notifier chain for the specific one
>> @@ -448,6 +448,7 @@ int extcon_sync(struct extcon_dev *edev, unsigned int id)
>> 	 */
>> 	raw_notifier_call_chain(&edev->nh_all, state, edev);
>> 
>> +	spin_lock_irqsave(&edev->lock, flags);
>> 	/* This could be in interrupt handler */
>> 	prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);
>> 	if (!prop_buf) {
>> 

I have tested on the Pyra handheld prototype and now it works. Plugging in an OTG cable
enables/disables OTG power as expected and there are no kernel oops any more.

So you can add my

Reported-by: H. Nikolaus Schaller <hns@goldelico.com>
Tested-by: H. Nikolaus Schaller <hns@goldelico.com>

BR and thank you for the quick fix,
Nikolaus

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] extcon: Release locking when sending the notification of connector state
  2018-06-14 10:39     ` H. Nikolaus Schaller
@ 2018-06-14 11:33       ` H. Nikolaus Schaller
  2018-06-15  0:52         ` Chanwoo Choi
  2018-06-17  0:31         ` Chanwoo Choi
  0 siblings, 2 replies; 7+ messages in thread
From: H. Nikolaus Schaller @ 2018-06-14 11:33 UTC (permalink / raw)
  To: Chanwoo Choi, Roger Quadros
  Cc: Linux Kernel Mailing List, chanwoo, myungjoo.ham, stable,
	Kishon Vijay Abraham I, Tony Giaccone


> Am 14.06.2018 um 12:39 schrieb H. Nikolaus Schaller <hns@goldelico.com>:
> 
> Hi Roger and Chanwoo,
> 
>> Am 14.06.2018 um 12:18 schrieb Chanwoo Choi <cw00.choi@samsung.com>:
>> 
>> + H. Nikolaus Schaller <hns@goldelico.com>
>> 
>> On 2018년 06월 14일 13:14, Chanwoo Choi wrote:
>>> Previously, extcon used the spinlock before calling the notifier_call_chain
>>> to prevent the scheduled out of task and to prevent the notification delay.
>>> When spinlock is locked for sending the notification, deadlock issue
>>> occured on the side of extcon consumer device. To fix this issue,
>>> extcon consumer device should always use the work. it is always not
>>> reasonable to use work.
>>> 
>>> To fix this issue on extcon consumer device, release locking when sending
>>> the notification of connector state.
>>> 
>>> Fixes: ab11af049f88 ("extcon: Add the synchronization extcon APIs to support the notification")
>>> Cc: stable@vger.kernel.org
>>> Cc: Roger Quadros <rogerq@ti.com>
>>> Cc: Kishon Vijay Abraham I <kishon@ti.com>
>>> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
>>> ---
>>> drivers/extcon/extcon.c | 3 ++-
>>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>> 
>>> diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
>>> index 8bff5fd18185..f75b08a45d4e 100644
>>> --- a/drivers/extcon/extcon.c
>>> +++ b/drivers/extcon/extcon.c
>>> @@ -433,8 +433,8 @@ int extcon_sync(struct extcon_dev *edev, unsigned int id)
>>> 		return index;
>>> 
>>> 	spin_lock_irqsave(&edev->lock, flags);
>>> -
>>> 	state = !!(edev->state & BIT(index));
>>> +	spin_unlock_irqrestore(&edev->lock, flags);
>>> 
>>> 	/*
>>> 	 * Call functions in a raw notifier chain for the specific one
>>> @@ -448,6 +448,7 @@ int extcon_sync(struct extcon_dev *edev, unsigned int id)
>>> 	 */
>>> 	raw_notifier_call_chain(&edev->nh_all, state, edev);
>>> 
>>> +	spin_lock_irqsave(&edev->lock, flags);
>>> 	/* This could be in interrupt handler */
>>> 	prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);
>>> 	if (!prop_buf) {
>>> 
> 
> I have tested on the Pyra handheld prototype and now it works. Plugging in an OTG cable
> enables/disables OTG power as expected and there are no kernel oops any more.

I did take some minutes to check and it now also works again on the OMAP5EVM.

BR,
Nikolaus

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] extcon: Release locking when sending the notification of connector state
  2018-06-14 11:33       ` H. Nikolaus Schaller
@ 2018-06-15  0:52         ` Chanwoo Choi
  2018-06-17  0:31         ` Chanwoo Choi
  1 sibling, 0 replies; 7+ messages in thread
From: Chanwoo Choi @ 2018-06-15  0:52 UTC (permalink / raw)
  To: H. Nikolaus Schaller, Roger Quadros
  Cc: Linux Kernel Mailing List, chanwoo, myungjoo.ham, stable,
	Kishon Vijay Abraham I, Tony Giaccone

Hi Roger,

If possible, Could you please review this patch? 

Regards,
Chanwoo Choi

On 2018년 06월 14일 20:33, H. Nikolaus Schaller wrote:
> 
>> Am 14.06.2018 um 12:39 schrieb H. Nikolaus Schaller <hns@goldelico.com>:
>>
>> Hi Roger and Chanwoo,
>>
>>> Am 14.06.2018 um 12:18 schrieb Chanwoo Choi <cw00.choi@samsung.com>:
>>>
>>> + H. Nikolaus Schaller <hns@goldelico.com>
>>>
>>> On 2018년 06월 14일 13:14, Chanwoo Choi wrote:
>>>> Previously, extcon used the spinlock before calling the notifier_call_chain
>>>> to prevent the scheduled out of task and to prevent the notification delay.
>>>> When spinlock is locked for sending the notification, deadlock issue
>>>> occured on the side of extcon consumer device. To fix this issue,
>>>> extcon consumer device should always use the work. it is always not
>>>> reasonable to use work.
>>>>
>>>> To fix this issue on extcon consumer device, release locking when sending
>>>> the notification of connector state.
>>>>
>>>> Fixes: ab11af049f88 ("extcon: Add the synchronization extcon APIs to support the notification")
>>>> Cc: stable@vger.kernel.org
>>>> Cc: Roger Quadros <rogerq@ti.com>
>>>> Cc: Kishon Vijay Abraham I <kishon@ti.com>
>>>> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
>>>> ---
>>>> drivers/extcon/extcon.c | 3 ++-
>>>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
>>>> index 8bff5fd18185..f75b08a45d4e 100644
>>>> --- a/drivers/extcon/extcon.c
>>>> +++ b/drivers/extcon/extcon.c
>>>> @@ -433,8 +433,8 @@ int extcon_sync(struct extcon_dev *edev, unsigned int id)
>>>> 		return index;
>>>>
>>>> 	spin_lock_irqsave(&edev->lock, flags);
>>>> -
>>>> 	state = !!(edev->state & BIT(index));
>>>> +	spin_unlock_irqrestore(&edev->lock, flags);
>>>>
>>>> 	/*
>>>> 	 * Call functions in a raw notifier chain for the specific one
>>>> @@ -448,6 +448,7 @@ int extcon_sync(struct extcon_dev *edev, unsigned int id)
>>>> 	 */
>>>> 	raw_notifier_call_chain(&edev->nh_all, state, edev);
>>>>
>>>> +	spin_lock_irqsave(&edev->lock, flags);
>>>> 	/* This could be in interrupt handler */
>>>> 	prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);
>>>> 	if (!prop_buf) {
>>>>
>>
>> I have tested on the Pyra handheld prototype and now it works. Plugging in an OTG cable
>> enables/disables OTG power as expected and there are no kernel oops any more.
> 
> I did take some minutes to check and it now also works again on the OMAP5EVM.
> 
> BR,
> Nikolaus
> 
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] extcon: Release locking when sending the notification of connector state
  2018-06-14  4:14 ` [PATCH] extcon: Release locking when sending the notification of connector state Chanwoo Choi
  2018-06-14 10:18   ` Chanwoo Choi
@ 2018-06-15  7:01   ` Roger Quadros
  1 sibling, 0 replies; 7+ messages in thread
From: Roger Quadros @ 2018-06-15  7:01 UTC (permalink / raw)
  To: Chanwoo Choi, linux-kernel
  Cc: chanwoo, myungjoo.ham, stable, Kishon Vijay Abraham I

On 14/06/18 07:14, Chanwoo Choi wrote:
> Previously, extcon used the spinlock before calling the notifier_call_chain
> to prevent the scheduled out of task and to prevent the notification delay.
> When spinlock is locked for sending the notification, deadlock issue
> occured on the side of extcon consumer device. To fix this issue,
> extcon consumer device should always use the work. it is always not
> reasonable to use work.
> 
> To fix this issue on extcon consumer device, release locking when sending
> the notification of connector state.
> 
> Fixes: ab11af049f88 ("extcon: Add the synchronization extcon APIs to support the notification")
> Cc: stable@vger.kernel.org
> Cc: Roger Quadros <rogerq@ti.com>
> Cc: Kishon Vijay Abraham I <kishon@ti.com>
> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>

Reviewed-by: Roger Quadros <rogerq@ti.com>

> ---
>  drivers/extcon/extcon.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
> index 8bff5fd18185..f75b08a45d4e 100644
> --- a/drivers/extcon/extcon.c
> +++ b/drivers/extcon/extcon.c
> @@ -433,8 +433,8 @@ int extcon_sync(struct extcon_dev *edev, unsigned int id)
>  		return index;
>  
>  	spin_lock_irqsave(&edev->lock, flags);
> -
>  	state = !!(edev->state & BIT(index));
> +	spin_unlock_irqrestore(&edev->lock, flags);
>  
>  	/*
>  	 * Call functions in a raw notifier chain for the specific one
> @@ -448,6 +448,7 @@ int extcon_sync(struct extcon_dev *edev, unsigned int id)
>  	 */
>  	raw_notifier_call_chain(&edev->nh_all, state, edev);
>  
> +	spin_lock_irqsave(&edev->lock, flags);
>  	/* This could be in interrupt handler */
>  	prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);
>  	if (!prop_buf) {
> 

-- 
cheers,
-roger

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] extcon: Release locking when sending the notification of connector state
  2018-06-14 11:33       ` H. Nikolaus Schaller
  2018-06-15  0:52         ` Chanwoo Choi
@ 2018-06-17  0:31         ` Chanwoo Choi
  1 sibling, 0 replies; 7+ messages in thread
From: Chanwoo Choi @ 2018-06-17  0:31 UTC (permalink / raw)
  To: H. Nikolaus Schaller
  Cc: Chanwoo Choi, Roger Quadros, Linux Kernel Mailing List,
	MyungJoo Ham, stable, Kishon Vijay Abraham I, Tony Giaccone

Hi,

2018-06-14 20:33 GMT+09:00 H. Nikolaus Schaller <hns@goldelico.com>:
>
>> Am 14.06.2018 um 12:39 schrieb H. Nikolaus Schaller <hns@goldelico.com>:
>>
>> Hi Roger and Chanwoo,
>>
>>> Am 14.06.2018 um 12:18 schrieb Chanwoo Choi <cw00.choi@samsung.com>:
>>>
>>> + H. Nikolaus Schaller <hns@goldelico.com>
>>>
>>> On 2018년 06월 14일 13:14, Chanwoo Choi wrote:
>>>> Previously, extcon used the spinlock before calling the notifier_call_chain
>>>> to prevent the scheduled out of task and to prevent the notification delay.
>>>> When spinlock is locked for sending the notification, deadlock issue
>>>> occured on the side of extcon consumer device. To fix this issue,
>>>> extcon consumer device should always use the work. it is always not
>>>> reasonable to use work.
>>>>
>>>> To fix this issue on extcon consumer device, release locking when sending
>>>> the notification of connector state.
>>>>
>>>> Fixes: ab11af049f88 ("extcon: Add the synchronization extcon APIs to support the notification")
>>>> Cc: stable@vger.kernel.org
>>>> Cc: Roger Quadros <rogerq@ti.com>
>>>> Cc: Kishon Vijay Abraham I <kishon@ti.com>
>>>> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
>>>> ---
>>>> drivers/extcon/extcon.c | 3 ++-
>>>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
>>>> index 8bff5fd18185..f75b08a45d4e 100644
>>>> --- a/drivers/extcon/extcon.c
>>>> +++ b/drivers/extcon/extcon.c
>>>> @@ -433,8 +433,8 @@ int extcon_sync(struct extcon_dev *edev, unsigned int id)
>>>>             return index;
>>>>
>>>>     spin_lock_irqsave(&edev->lock, flags);
>>>> -
>>>>     state = !!(edev->state & BIT(index));
>>>> +   spin_unlock_irqrestore(&edev->lock, flags);
>>>>
>>>>     /*
>>>>      * Call functions in a raw notifier chain for the specific one
>>>> @@ -448,6 +448,7 @@ int extcon_sync(struct extcon_dev *edev, unsigned int id)
>>>>      */
>>>>     raw_notifier_call_chain(&edev->nh_all, state, edev);
>>>>
>>>> +   spin_lock_irqsave(&edev->lock, flags);
>>>>     /* This could be in interrupt handler */
>>>>     prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);
>>>>     if (!prop_buf) {
>>>>
>>
>> I have tested on the Pyra handheld prototype and now it works. Plugging in an OTG cable
>> enables/disables OTG power as expected and there are no kernel oops any more.
>
> I did take some minutes to check and it now also works again on the OMAP5EVM.
>
> BR,
> Nikolaus

Applied it.


-- 
Best Regards,
Chanwoo Choi
Samsung Electronics

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-06-17  0:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20180614041448epcas2p400dad902581dc6875461d4c3dd3a231d@epcas2p4.samsung.com>
2018-06-14  4:14 ` [PATCH] extcon: Release locking when sending the notification of connector state Chanwoo Choi
2018-06-14 10:18   ` Chanwoo Choi
2018-06-14 10:39     ` H. Nikolaus Schaller
2018-06-14 11:33       ` H. Nikolaus Schaller
2018-06-15  0:52         ` Chanwoo Choi
2018-06-17  0:31         ` Chanwoo Choi
2018-06-15  7:01   ` Roger Quadros

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).