Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] usb: usbfs: only account once for mmap()'ed usb memory usage
@ 2019-08-14 21:29 gavinli
  2019-08-15 12:53 ` Greg KH
  2019-08-15 19:16 ` Alan Stern
  0 siblings, 2 replies; 4+ messages in thread
From: gavinli @ 2019-08-14 21:29 UTC (permalink / raw)
  To: gregkh, linux-usb; +Cc: Gavin Li

From: Gavin Li <git@thegavinli.com>

Memory usage for USB memory allocated via mmap() is already accounted
for at mmap() time; no need to account for it again at submiturb time.

Signed-off-by: Gavin Li <git@thegavinli.com>
---
 drivers/usb/core/devio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index bbe9c2edd3e7..9681dd55473b 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1603,7 +1603,8 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
 	if (as->usbm)
 		num_sgs = 0;
 
-	u += sizeof(struct async) + sizeof(struct urb) + uurb->buffer_length +
+	u += sizeof(struct async) + sizeof(struct urb) +
+	     (as->usbm ? 0 : uurb->buffer_length) +
 	     num_sgs * sizeof(struct scatterlist);
 	ret = usbfs_increase_memory_usage(u);
 	if (ret)
-- 
2.22.0


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

* Re: [PATCH] usb: usbfs: only account once for mmap()'ed usb memory usage
  2019-08-14 21:29 [PATCH] usb: usbfs: only account once for mmap()'ed usb memory usage gavinli
@ 2019-08-15 12:53 ` Greg KH
  2019-08-16  5:51   ` Gavin Li
  2019-08-15 19:16 ` Alan Stern
  1 sibling, 1 reply; 4+ messages in thread
From: Greg KH @ 2019-08-15 12:53 UTC (permalink / raw)
  To: gavinli; +Cc: linux-usb, Gavin Li

On Wed, Aug 14, 2019 at 02:29:24PM -0700, gavinli@thegavinli.com wrote:
> From: Gavin Li <git@thegavinli.com>
> 
> Memory usage for USB memory allocated via mmap() is already accounted
> for at mmap() time; no need to account for it again at submiturb time.
> 
> Signed-off-by: Gavin Li <git@thegavinli.com>
> ---
>  drivers/usb/core/devio.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

What commit does this fix?  What issue does this fix, is it something
that is user-visable?

> 
> diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> index bbe9c2edd3e7..9681dd55473b 100644
> --- a/drivers/usb/core/devio.c
> +++ b/drivers/usb/core/devio.c
> @@ -1603,7 +1603,8 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
>  	if (as->usbm)
>  		num_sgs = 0;
>  
> -	u += sizeof(struct async) + sizeof(struct urb) + uurb->buffer_length +
> +	u += sizeof(struct async) + sizeof(struct urb) +
> +	     (as->usbm ? 0 : uurb->buffer_length) +
>  	     num_sgs * sizeof(struct scatterlist);

Are you sure?  Where is the buffer_length being added to the size here?
What am I missing?

thanks,

greg k-h

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

* Re: [PATCH] usb: usbfs: only account once for mmap()'ed usb memory usage
  2019-08-14 21:29 [PATCH] usb: usbfs: only account once for mmap()'ed usb memory usage gavinli
  2019-08-15 12:53 ` Greg KH
@ 2019-08-15 19:16 ` Alan Stern
  1 sibling, 0 replies; 4+ messages in thread
From: Alan Stern @ 2019-08-15 19:16 UTC (permalink / raw)
  To: gavinli; +Cc: gregkh, linux-usb, Gavin Li

On Wed, 14 Aug 2019 gavinli@thegavinli.com wrote:

> From: Gavin Li <git@thegavinli.com>
> 
> Memory usage for USB memory allocated via mmap() is already accounted
> for at mmap() time; no need to account for it again at submiturb time.
> 
> Signed-off-by: Gavin Li <git@thegavinli.com>
> ---
>  drivers/usb/core/devio.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> index bbe9c2edd3e7..9681dd55473b 100644
> --- a/drivers/usb/core/devio.c
> +++ b/drivers/usb/core/devio.c
> @@ -1603,7 +1603,8 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
>  	if (as->usbm)
>  		num_sgs = 0;
>  
> -	u += sizeof(struct async) + sizeof(struct urb) + uurb->buffer_length +
> +	u += sizeof(struct async) + sizeof(struct urb) +
> +	     (as->usbm ? 0 : uurb->buffer_length) +
>  	     num_sgs * sizeof(struct scatterlist);
>  	ret = usbfs_increase_memory_usage(u);
>  	if (ret)
> 

Acked-by: Alan Stern <stern@rowland.harvard.edu>


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

* Re: [PATCH] usb: usbfs: only account once for mmap()'ed usb memory usage
  2019-08-15 12:53 ` Greg KH
@ 2019-08-16  5:51   ` Gavin Li
  0 siblings, 0 replies; 4+ messages in thread
From: Gavin Li @ 2019-08-16  5:51 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-usb, Gavin Li

It is done in usbdev_mmap(); it calls usbfs_increase_memory_usage() to
account for the buffer it allocates. No additional memory (other than
for the control structures) is needed when actually submitting the
URB.

On Thu, Aug 15, 2019 at 5:53 AM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Wed, Aug 14, 2019 at 02:29:24PM -0700, gavinli@thegavinli.com wrote:
> > From: Gavin Li <git@thegavinli.com>
> >
> > Memory usage for USB memory allocated via mmap() is already accounted
> > for at mmap() time; no need to account for it again at submiturb time.
> >
> > Signed-off-by: Gavin Li <git@thegavinli.com>
> > ---
> >  drivers/usb/core/devio.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
>
> What commit does this fix?  What issue does this fix, is it something
> that is user-visable?
>
> >
> > diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> > index bbe9c2edd3e7..9681dd55473b 100644
> > --- a/drivers/usb/core/devio.c
> > +++ b/drivers/usb/core/devio.c
> > @@ -1603,7 +1603,8 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
> >       if (as->usbm)
> >               num_sgs = 0;
> >
> > -     u += sizeof(struct async) + sizeof(struct urb) + uurb->buffer_length +
> > +     u += sizeof(struct async) + sizeof(struct urb) +
> > +          (as->usbm ? 0 : uurb->buffer_length) +
> >            num_sgs * sizeof(struct scatterlist);
>
> Are you sure?  Where is the buffer_length being added to the size here?
> What am I missing?
>
> thanks,
>
> greg k-h

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-14 21:29 [PATCH] usb: usbfs: only account once for mmap()'ed usb memory usage gavinli
2019-08-15 12:53 ` Greg KH
2019-08-16  5:51   ` Gavin Li
2019-08-15 19:16 ` Alan Stern

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org
	public-inbox-index linux-usb

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git