linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: yurex: Rearrange code not to need GFP_ATOMIC
@ 2020-09-20  8:44 Pavel Machek
  2020-09-21 12:24 ` Oliver Neukum
  0 siblings, 1 reply; 5+ messages in thread
From: Pavel Machek @ 2020-09-20  8:44 UTC (permalink / raw)
  To: gregkh, stern, johan, gustavoars, linux-usb, linux-kernel

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


Move prepare to wait around, so that normal GFP_KERNEL allocation can
be used.

Signed-off-by: Pavel Machek (CIP) <pavel@denx.de>
Acked-by: Alan Stern <stern@rowland.harvard.edu>

diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c
index b2e09883c7e2..071f1debebba 100644
--- a/drivers/usb/misc/yurex.c
+++ b/drivers/usb/misc/yurex.c
@@ -489,10 +489,10 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
 	}
 
 	/* send the data as the control msg */
-	prepare_to_wait(&dev->waitq, &wait, TASK_INTERRUPTIBLE);
 	dev_dbg(&dev->interface->dev, "%s - submit %c\n", __func__,
 		dev->cntl_buffer[0]);
-	retval = usb_submit_urb(dev->cntl_urb, GFP_ATOMIC);
+	retval = usb_submit_urb(dev->cntl_urb, GFP_KERNEL);
+	prepare_to_wait(&dev->waitq, &wait, TASK_INTERRUPTIBLE);
 	if (retval >= 0)
 		timeout = schedule_timeout(YUREX_WRITE_TIMEOUT);
 	finish_wait(&dev->waitq, &wait);

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

* Re: [PATCH] usb: yurex: Rearrange code not to need GFP_ATOMIC
  2020-09-20  8:44 [PATCH] usb: yurex: Rearrange code not to need GFP_ATOMIC Pavel Machek
@ 2020-09-21 12:24 ` Oliver Neukum
  2020-09-21 12:52   ` Pavel Machek
  2020-09-21 14:45   ` Alan Stern
  0 siblings, 2 replies; 5+ messages in thread
From: Oliver Neukum @ 2020-09-21 12:24 UTC (permalink / raw)
  To: Pavel Machek, gregkh, stern, johan, gustavoars, linux-usb, linux-kernel

Am Sonntag, den 20.09.2020, 10:44 +0200 schrieb Pavel Machek:
> Move prepare to wait around, so that normal GFP_KERNEL allocation can
> be used.
> 
> Signed-off-by: Pavel Machek (CIP) <pavel@denx.de>
> Acked-by: Alan Stern <stern@rowland.harvard.edu>

Ehm. Please recheck.

> diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c
> index b2e09883c7e2..071f1debebba 100644
> --- a/drivers/usb/misc/yurex.c
> +++ b/drivers/usb/misc/yurex.c
> @@ -489,10 +489,10 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
>  	}
>  
>  	/* send the data as the control msg */
> -	prepare_to_wait(&dev->waitq, &wait, TASK_INTERRUPTIBLE);
>  	dev_dbg(&dev->interface->dev, "%s - submit %c\n", __func__,
>  		dev->cntl_buffer[0]);
> -	retval = usb_submit_urb(dev->cntl_urb, GFP_ATOMIC);
> +	retval = usb_submit_urb(dev->cntl_urb, GFP_KERNEL);

URB completes here. wake_up() returns the task to RUNNING.

> +	prepare_to_wait(&dev->waitq, &wait, TASK_INTERRUPTIBLE);

Task goes to TASK_INTERRUPTIBLE

>  	if (retval >= 0)
>  		timeout = schedule_timeout(YUREX_WRITE_TIMEOUT);

Task turns into Sleeping Beauty until timeout

>  	finish_wait(&dev->waitq, &wait);

And here task goes into error reporting as it checks timeout.

	Regards
		Oliver


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

* Re: [PATCH] usb: yurex: Rearrange code not to need GFP_ATOMIC
  2020-09-21 12:24 ` Oliver Neukum
@ 2020-09-21 12:52   ` Pavel Machek
  2020-09-21 13:00     ` Oliver Neukum
  2020-09-21 14:45   ` Alan Stern
  1 sibling, 1 reply; 5+ messages in thread
From: Pavel Machek @ 2020-09-21 12:52 UTC (permalink / raw)
  To: Oliver Neukum
  Cc: Pavel Machek, gregkh, stern, johan, gustavoars, linux-usb, linux-kernel

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

Hi!

> > Move prepare to wait around, so that normal GFP_KERNEL allocation can
> > be used.
> > 
> > Signed-off-by: Pavel Machek (CIP) <pavel@denx.de>
> > Acked-by: Alan Stern <stern@rowland.harvard.edu>
> 
> Ehm. Please recheck.

Sorry about that.

> > +++ b/drivers/usb/misc/yurex.c
> > @@ -489,10 +489,10 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
> >  	}
> >  
> >  	/* send the data as the control msg */
> > -	prepare_to_wait(&dev->waitq, &wait, TASK_INTERRUPTIBLE);
> >  	dev_dbg(&dev->interface->dev, "%s - submit %c\n", __func__,
> >  		dev->cntl_buffer[0]);
> > -	retval = usb_submit_urb(dev->cntl_urb, GFP_ATOMIC);
> > +	retval = usb_submit_urb(dev->cntl_urb, GFP_KERNEL);
> 
> URB completes here. wake_up() returns the task to RUNNING.
> 
> > +	prepare_to_wait(&dev->waitq, &wait, TASK_INTERRUPTIBLE);
> 
> Task goes to TASK_INTERRUPTIBLE
> 
> >  	if (retval >= 0)
> >  		timeout = schedule_timeout(YUREX_WRITE_TIMEOUT);
> 
> Task turns into Sleeping Beauty until timeout

Is there way to do the allocations for submit_urb before the
prepare_to_wait? GFP_ATOMIC would be nice to avoid... and doing
GFP_ATOMIC from normal process context just because of task_state
seems ... wrong.

								Pavel
-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

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

* Re: [PATCH] usb: yurex: Rearrange code not to need GFP_ATOMIC
  2020-09-21 12:52   ` Pavel Machek
@ 2020-09-21 13:00     ` Oliver Neukum
  0 siblings, 0 replies; 5+ messages in thread
From: Oliver Neukum @ 2020-09-21 13:00 UTC (permalink / raw)
  To: Pavel Machek; +Cc: gregkh, stern, johan, gustavoars, linux-usb, linux-kernel

Am Montag, den 21.09.2020, 14:52 +0200 schrieb Pavel Machek:
> Hi!

> > 
> > Task goes to TASK_INTERRUPTIBLE
> > 
> > >  	if (retval >= 0)
> > >  		timeout = schedule_timeout(YUREX_WRITE_TIMEOUT);
> > 
> > Task turns into Sleeping Beauty until timeout
> 
> Is there way to do the allocations for submit_urb before the

No. In theory you do not even know which HC will get the URB.
Preallocating resources is impossible. I do consider this a
design bug in the usbcore API.

> prepare_to_wait? GFP_ATOMIC would be nice to avoid... and doing
> GFP_ATOMIC from normal process context just because of task_state
> seems ... wrong.

Well, then you will need to change the rest of the logic
and use a struct completion. Give the age and practical
relevance of the driver I would recommend against making
such drastic changes and let it just be in its awkward
but correct state.

	Regards
		Oliver


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

* Re: [PATCH] usb: yurex: Rearrange code not to need GFP_ATOMIC
  2020-09-21 12:24 ` Oliver Neukum
  2020-09-21 12:52   ` Pavel Machek
@ 2020-09-21 14:45   ` Alan Stern
  1 sibling, 0 replies; 5+ messages in thread
From: Alan Stern @ 2020-09-21 14:45 UTC (permalink / raw)
  To: Oliver Neukum
  Cc: Pavel Machek, gregkh, johan, gustavoars, linux-usb, linux-kernel

On Mon, Sep 21, 2020 at 02:24:52PM +0200, Oliver Neukum wrote:
> Am Sonntag, den 20.09.2020, 10:44 +0200 schrieb Pavel Machek:
> > Move prepare to wait around, so that normal GFP_KERNEL allocation can
> > be used.
> > 
> > Signed-off-by: Pavel Machek (CIP) <pavel@denx.de>
> > Acked-by: Alan Stern <stern@rowland.harvard.edu>
> 
> Ehm. Please recheck.
> 
> > diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c
> > index b2e09883c7e2..071f1debebba 100644
> > --- a/drivers/usb/misc/yurex.c
> > +++ b/drivers/usb/misc/yurex.c
> > @@ -489,10 +489,10 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
> >  	}
> >  
> >  	/* send the data as the control msg */
> > -	prepare_to_wait(&dev->waitq, &wait, TASK_INTERRUPTIBLE);
> >  	dev_dbg(&dev->interface->dev, "%s - submit %c\n", __func__,
> >  		dev->cntl_buffer[0]);
> > -	retval = usb_submit_urb(dev->cntl_urb, GFP_ATOMIC);
> > +	retval = usb_submit_urb(dev->cntl_urb, GFP_KERNEL);
> 
> URB completes here. wake_up() returns the task to RUNNING.
> 
> > +	prepare_to_wait(&dev->waitq, &wait, TASK_INTERRUPTIBLE);
> 
> Task goes to TASK_INTERRUPTIBLE
> 
> >  	if (retval >= 0)
> >  		timeout = schedule_timeout(YUREX_WRITE_TIMEOUT);
> 
> Task turns into Sleeping Beauty until timeout
> 
> >  	finish_wait(&dev->waitq, &wait);
> 
> And here task goes into error reporting as it checks timeout.

Arrgh.  Now I feel stupid.  (Me and Pavel both, probably.)

Thanks for spotting this.

Alan Stern

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

end of thread, other threads:[~2020-09-21 14:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-20  8:44 [PATCH] usb: yurex: Rearrange code not to need GFP_ATOMIC Pavel Machek
2020-09-21 12:24 ` Oliver Neukum
2020-09-21 12:52   ` Pavel Machek
2020-09-21 13:00     ` Oliver Neukum
2020-09-21 14:45   ` Alan Stern

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