LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 1/2] usbip: Remove repeated setting of hcd->state in vhci_bus_suspend()
@ 2019-05-06 12:55 Suwan Kim
  2019-05-06 12:55 ` [PATCH 2/2] usbip: Remove repeated setting of hcd->state in vhci_bus_resume() Suwan Kim
  2019-05-06 15:13 ` [PATCH 1/2] usbip: Remove repeated setting of hcd->state in vhci_bus_suspend() shuah
  0 siblings, 2 replies; 7+ messages in thread
From: Suwan Kim @ 2019-05-06 12:55 UTC (permalink / raw)
  To: shuah, valentina.manea.m, gregkh; +Cc: linux-usb, linux-kernel, Suwan Kim

When hcd suspends execution, hcd_bus_suspend() calls vhci_bus_suspend()
which sets hcd->state as HC_STATE_SUSPENDED. But after calling
vhci_bus_suspend(), hcd_bus_suspend() also sets hcd->state as
HC_STATE_SUSPENDED.
So, setting hcd->state in vhci_hcd_suspend() is unnecessary.

Signed-off-by: Suwan Kim <suwan.kim027@gmail.com>
---
 drivers/usb/usbip/vhci_hcd.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
index 667d9c0ec905..e6f378d00fb6 100644
--- a/drivers/usb/usbip/vhci_hcd.c
+++ b/drivers/usb/usbip/vhci_hcd.c
@@ -1238,10 +1238,6 @@ static int vhci_bus_suspend(struct usb_hcd *hcd)
 
 	dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
 
-	spin_lock_irqsave(&vhci->lock, flags);
-	hcd->state = HC_STATE_SUSPENDED;
-	spin_unlock_irqrestore(&vhci->lock, flags);
-
 	return 0;
 }
 
-- 
2.20.1


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

* [PATCH 2/2] usbip: Remove repeated setting of hcd->state in vhci_bus_resume()
  2019-05-06 12:55 [PATCH 1/2] usbip: Remove repeated setting of hcd->state in vhci_bus_suspend() Suwan Kim
@ 2019-05-06 12:55 ` Suwan Kim
  2019-05-06 15:16   ` shuah
  2019-05-06 15:13 ` [PATCH 1/2] usbip: Remove repeated setting of hcd->state in vhci_bus_suspend() shuah
  1 sibling, 1 reply; 7+ messages in thread
From: Suwan Kim @ 2019-05-06 12:55 UTC (permalink / raw)
  To: shuah, valentina.manea.m, gregkh; +Cc: linux-usb, linux-kernel, Suwan Kim

When hcd resumes, hcd_bus_resume() calls vhci_bus_resume() which sets
hcd->state as HC_STATE_RUNNING. But after calling vhci_bus_resume(),
hcd_bus_resume() also sets hcd->state as HC_STATE_RUNNING. So, setting
hcd->state in vhci_hcd_resume() is unnecessary.

Signed-off-by: Suwan Kim <suwan.kim027@gmail.com>
---
 drivers/usb/usbip/vhci_hcd.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
index e6f378d00fb6..335d61676fb4 100644
--- a/drivers/usb/usbip/vhci_hcd.c
+++ b/drivers/usb/usbip/vhci_hcd.c
@@ -1252,8 +1252,6 @@ static int vhci_bus_resume(struct usb_hcd *hcd)
 	spin_lock_irqsave(&vhci->lock, flags);
 	if (!HCD_HW_ACCESSIBLE(hcd))
 		rc = -ESHUTDOWN;
-	else
-		hcd->state = HC_STATE_RUNNING;
 	spin_unlock_irqrestore(&vhci->lock, flags);
 
 	return rc;
-- 
2.20.1


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

* Re: [PATCH 1/2] usbip: Remove repeated setting of hcd->state in vhci_bus_suspend()
  2019-05-06 12:55 [PATCH 1/2] usbip: Remove repeated setting of hcd->state in vhci_bus_suspend() Suwan Kim
  2019-05-06 12:55 ` [PATCH 2/2] usbip: Remove repeated setting of hcd->state in vhci_bus_resume() Suwan Kim
@ 2019-05-06 15:13 ` shuah
  2019-05-07 15:49   ` Suwan Kim
  1 sibling, 1 reply; 7+ messages in thread
From: shuah @ 2019-05-06 15:13 UTC (permalink / raw)
  To: Suwan Kim, valentina.manea.m, gregkh; +Cc: linux-usb, linux-kernel, shuah

On 5/6/19 6:55 AM, Suwan Kim wrote:
> When hcd suspends execution, hcd_bus_suspend() calls vhci_bus_suspend()
> which sets hcd->state as HC_STATE_SUSPENDED. But after calling
> vhci_bus_suspend(), hcd_bus_suspend() also sets hcd->state as
> HC_STATE_SUSPENDED.
> So, setting hcd->state in vhci_hcd_suspend() is unnecessary.
> 
> Signed-off-by: Suwan Kim <suwan.kim027@gmail.com>
> ---
>   drivers/usb/usbip/vhci_hcd.c | 4 ----
>   1 file changed, 4 deletions(-)
> 
> diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
> index 667d9c0ec905..e6f378d00fb6 100644
> --- a/drivers/usb/usbip/vhci_hcd.c
> +++ b/drivers/usb/usbip/vhci_hcd.c
> @@ -1238,10 +1238,6 @@ static int vhci_bus_suspend(struct usb_hcd *hcd)
>   
>   	dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
>   
> -	spin_lock_irqsave(&vhci->lock, flags);
> -	hcd->state = HC_STATE_SUSPENDED;
> -	spin_unlock_irqrestore(&vhci->lock, flags);
> -
>   	return 0;
>   }
>   
> 

Tell me more about why you think this change is needed? How did you test
this change?

thanks,
-- Shuah

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

* Re: [PATCH 2/2] usbip: Remove repeated setting of hcd->state in vhci_bus_resume()
  2019-05-06 12:55 ` [PATCH 2/2] usbip: Remove repeated setting of hcd->state in vhci_bus_resume() Suwan Kim
@ 2019-05-06 15:16   ` shuah
  0 siblings, 0 replies; 7+ messages in thread
From: shuah @ 2019-05-06 15:16 UTC (permalink / raw)
  To: Suwan Kim, valentina.manea.m, gregkh; +Cc: linux-usb, linux-kernel, shuah

On 5/6/19 6:55 AM, Suwan Kim wrote:
> When hcd resumes, hcd_bus_resume() calls vhci_bus_resume() which sets
> hcd->state as HC_STATE_RUNNING. But after calling vhci_bus_resume(),
> hcd_bus_resume() also sets hcd->state as HC_STATE_RUNNING. So, setting
> hcd->state in vhci_hcd_resume() is unnecessary.
> 
> Signed-off-by: Suwan Kim <suwan.kim027@gmail.com>
> ---
>   drivers/usb/usbip/vhci_hcd.c | 2 --
>   1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
> index e6f378d00fb6..335d61676fb4 100644
> --- a/drivers/usb/usbip/vhci_hcd.c
> +++ b/drivers/usb/usbip/vhci_hcd.c
> @@ -1252,8 +1252,6 @@ static int vhci_bus_resume(struct usb_hcd *hcd)
>   	spin_lock_irqsave(&vhci->lock, flags);
>   	if (!HCD_HW_ACCESSIBLE(hcd))
>   		rc = -ESHUTDOWN;
> -	else
> -		hcd->state = HC_STATE_RUNNING;
>   	spin_unlock_irqrestore(&vhci->lock, flags);
>   
>   	return rc;
> 

Tell me more about why you think this change is needed? How did you test
this change?

thanks,
-- Shuah

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

* Re: [PATCH 1/2] usbip: Remove repeated setting of hcd->state in vhci_bus_suspend()
  2019-05-06 15:13 ` [PATCH 1/2] usbip: Remove repeated setting of hcd->state in vhci_bus_suspend() shuah
@ 2019-05-07 15:49   ` Suwan Kim
  2019-05-08 17:28     ` shuah
  0 siblings, 1 reply; 7+ messages in thread
From: Suwan Kim @ 2019-05-07 15:49 UTC (permalink / raw)
  To: shuah; +Cc: valentina.manea.m, gregkh, linux-usb, linux-kernel

Hi Shuah,

On Mon, May 06, 2019 at 09:13:02AM -0600, shuah wrote:
> On 5/6/19 6:55 AM, Suwan Kim wrote:
> > When hcd suspends execution, hcd_bus_suspend() calls vhci_bus_suspend()
> > which sets hcd->state as HC_STATE_SUSPENDED. But after calling
> > vhci_bus_suspend(), hcd_bus_suspend() also sets hcd->state as
> > HC_STATE_SUSPENDED.
> > So, setting hcd->state in vhci_hcd_suspend() is unnecessary.
> > 
> > Signed-off-by: Suwan Kim <suwan.kim027@gmail.com>
> > ---
> >   drivers/usb/usbip/vhci_hcd.c | 4 ----
> >   1 file changed, 4 deletions(-)
> > 
> > diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
> > index 667d9c0ec905..e6f378d00fb6 100644
> > --- a/drivers/usb/usbip/vhci_hcd.c
> > +++ b/drivers/usb/usbip/vhci_hcd.c
> > @@ -1238,10 +1238,6 @@ static int vhci_bus_suspend(struct usb_hcd *hcd)
> >   	dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
> > -	spin_lock_irqsave(&vhci->lock, flags);
> > -	hcd->state = HC_STATE_SUSPENDED;
> > -	spin_unlock_irqrestore(&vhci->lock, flags);
> > -
> >   	return 0;
> >   }
> > 
> 
> Tell me more about why you think this change is needed? How did you test
> this change?

I think that host controller specific functions, vhci_bus_resume()
or vhci_bus_suspend() in the case of vhci, usually process host
controller specific data (struct vhci_hcd) not a generic data
(struct usb_hcd). The generic data is usually processed by generic HCD
layer. But vhci_bus_resume() and vhci_bus_suspend() set generic data
(hcd->state) and moreover this variable is set in generic HCD layer
once again(hcd_bus_resume() and hcd_bus_suspend()).

So, i think host controller specific functions (vhci_bus_resume()
and vhci_bus_suspend()) don't need to set the generic data that is
"hcd->state = HC_STATE_RUNNING or HC_STATE_SUSPEND".

For test, I loaded vhci-hcd module, suspended and resumed my computer
and checked hcd->state variable. There is no difference compared with
not modified version because my patch just removes repeated and
unnecessary part.

Regards

Suwan Kim

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

* Re: [PATCH 1/2] usbip: Remove repeated setting of hcd->state in vhci_bus_suspend()
  2019-05-07 15:49   ` Suwan Kim
@ 2019-05-08 17:28     ` shuah
  2019-05-14 11:58       ` Suwan Kim
  0 siblings, 1 reply; 7+ messages in thread
From: shuah @ 2019-05-08 17:28 UTC (permalink / raw)
  To: Suwan Kim; +Cc: valentina.manea.m, gregkh, linux-usb, linux-kernel, shuah

On 5/7/19 9:49 AM, Suwan Kim wrote:
> Hi Shuah,
> 
> On Mon, May 06, 2019 at 09:13:02AM -0600, shuah wrote:
>> On 5/6/19 6:55 AM, Suwan Kim wrote:
>>> When hcd suspends execution, hcd_bus_suspend() calls vhci_bus_suspend()
>>> which sets hcd->state as HC_STATE_SUSPENDED. But after calling
>>> vhci_bus_suspend(), hcd_bus_suspend() also sets hcd->state as
>>> HC_STATE_SUSPENDED.
>>> So, setting hcd->state in vhci_hcd_suspend() is unnecessary.
>>>
>>> Signed-off-by: Suwan Kim <suwan.kim027@gmail.com>
>>> ---
>>>    drivers/usb/usbip/vhci_hcd.c | 4 ----
>>>    1 file changed, 4 deletions(-)
>>>
>>> diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
>>> index 667d9c0ec905..e6f378d00fb6 100644
>>> --- a/drivers/usb/usbip/vhci_hcd.c
>>> +++ b/drivers/usb/usbip/vhci_hcd.c
>>> @@ -1238,10 +1238,6 @@ static int vhci_bus_suspend(struct usb_hcd *hcd)
>>>    	dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
>>> -	spin_lock_irqsave(&vhci->lock, flags);
>>> -	hcd->state = HC_STATE_SUSPENDED;
>>> -	spin_unlock_irqrestore(&vhci->lock, flags);
>>> -
>>>    	return 0;
>>>    }
>>>
>>
>> Tell me more about why you think this change is needed? How did you test
>> this change?
> 
> I think that host controller specific functions, vhci_bus_resume()
> or vhci_bus_suspend() in the case of vhci, usually process host
> controller specific data (struct vhci_hcd) not a generic data
> (struct usb_hcd). The generic data is usually processed by generic HCD
> layer. But vhci_bus_resume() and vhci_bus_suspend() set generic data
> (hcd->state) and moreover this variable is set in generic HCD layer
> once again(hcd_bus_resume() and hcd_bus_suspend()).
> 
> So, i think host controller specific functions (vhci_bus_resume()
> and vhci_bus_suspend()) don't need to set the generic data that is
> "hcd->state = HC_STATE_RUNNING or HC_STATE_SUSPEND".
> 

It depends. In this case, vhci_hcd is virtual driver and maintains
port status for devices that are remote. It checks hcd->state in
vhci_hub_status().

It updates the hcd->state in suspend with vhci->lock hold and checks
status from vhci_hub_status(). Removing updating hcd->state from 
vhci_bus_suspend()will open a window where vhci_hub_status() might
find it wrong state.

Same thing for HC_STATE_RUNNING. There are few other drivers that
do the same for similar reasons. xhci_hcd, and dummy_hcd and a few
more. This is the same comment on your patch that removes
HC_STATE_RUNNING update from resume.

> For test, I loaded vhci-hcd module, suspended and resumed my computer
> and checked hcd->state variable. There is no difference compared with
> not modified version because my patch just removes repeated and
> unnecessary part.
> 

This won't fully test the condition since there are remote devices
attached and triggering suspend while attach/detach is in progress.

thanks,
-- Shuah


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

* Re: [PATCH 1/2] usbip: Remove repeated setting of hcd->state in vhci_bus_suspend()
  2019-05-08 17:28     ` shuah
@ 2019-05-14 11:58       ` Suwan Kim
  0 siblings, 0 replies; 7+ messages in thread
From: Suwan Kim @ 2019-05-14 11:58 UTC (permalink / raw)
  To: shuah; +Cc: valentina.manea.m, gregkh, linux-usb, linux-kernel

On Wed, May 08, 2019 at 11:28:05AM -0600, shuah wrote:
> On 5/7/19 9:49 AM, Suwan Kim wrote:
> > Hi Shuah,
> > 
> > On Mon, May 06, 2019 at 09:13:02AM -0600, shuah wrote:
> > > On 5/6/19 6:55 AM, Suwan Kim wrote:
> > > > When hcd suspends execution, hcd_bus_suspend() calls vhci_bus_suspend()
> > > > which sets hcd->state as HC_STATE_SUSPENDED. But after calling
> > > > vhci_bus_suspend(), hcd_bus_suspend() also sets hcd->state as
> > > > HC_STATE_SUSPENDED.
> > > > So, setting hcd->state in vhci_hcd_suspend() is unnecessary.
> > > > 
> > > > Signed-off-by: Suwan Kim <suwan.kim027@gmail.com>
> > > > ---
> > > >    drivers/usb/usbip/vhci_hcd.c | 4 ----
> > > >    1 file changed, 4 deletions(-)
> > > > 
> > > > diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
> > > > index 667d9c0ec905..e6f378d00fb6 100644
> > > > --- a/drivers/usb/usbip/vhci_hcd.c
> > > > +++ b/drivers/usb/usbip/vhci_hcd.c
> > > > @@ -1238,10 +1238,6 @@ static int vhci_bus_suspend(struct usb_hcd *hcd)
> > > >    	dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
> > > > -	spin_lock_irqsave(&vhci->lock, flags);
> > > > -	hcd->state = HC_STATE_SUSPENDED;
> > > > -	spin_unlock_irqrestore(&vhci->lock, flags);
> > > > -
> > > >    	return 0;
> > > >    }
> > > > 
> > > 
> > > Tell me more about why you think this change is needed? How did you test
> > > this change?
> > 
> > I think that host controller specific functions, vhci_bus_resume()
> > or vhci_bus_suspend() in the case of vhci, usually process host
> > controller specific data (struct vhci_hcd) not a generic data
> > (struct usb_hcd). The generic data is usually processed by generic HCD
> > layer. But vhci_bus_resume() and vhci_bus_suspend() set generic data
> > (hcd->state) and moreover this variable is set in generic HCD layer
> > once again(hcd_bus_resume() and hcd_bus_suspend()).
> > 
> > So, i think host controller specific functions (vhci_bus_resume()
> > and vhci_bus_suspend()) don't need to set the generic data that is
> > "hcd->state = HC_STATE_RUNNING or HC_STATE_SUSPEND".
> > 
> 
> It depends. In this case, vhci_hcd is virtual driver and maintains
> port status for devices that are remote. It checks hcd->state in
> vhci_hub_status().
> 
> It updates the hcd->state in suspend with vhci->lock hold and checks
> status from vhci_hub_status(). Removing updating hcd->state from
> vhci_bus_suspend()will open a window where vhci_hub_status() might
> find it wrong state.
> 

I didn't know that and I missed. Thank you for pointing out my fault.
I agree that removing updating hcd->state which is protected by vhci
lock is not correct.

But I still have not fully understood the relationship between
vhci_bus_suspend() and vhci_hub_status() yet. I will look at it in
more detail. Again, thank you for reviewing my patch.

Regards

Suwan Kim

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

end of thread, other threads:[~2019-05-14 11:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-06 12:55 [PATCH 1/2] usbip: Remove repeated setting of hcd->state in vhci_bus_suspend() Suwan Kim
2019-05-06 12:55 ` [PATCH 2/2] usbip: Remove repeated setting of hcd->state in vhci_bus_resume() Suwan Kim
2019-05-06 15:16   ` shuah
2019-05-06 15:13 ` [PATCH 1/2] usbip: Remove repeated setting of hcd->state in vhci_bus_suspend() shuah
2019-05-07 15:49   ` Suwan Kim
2019-05-08 17:28     ` shuah
2019-05-14 11:58       ` Suwan Kim

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