linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oliver Neukum <oneukum@suse.de>
To: Stefan Klug <stefan.klug@baslerweb.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	stern@rowland.harvard.edu
Subject: Re: [PATCH][RFC] USB: zerocopy support for usbfs
Date: Fri, 04 Jul 2014 10:55:17 +0200	[thread overview]
Message-ID: <1404464117.1915.7.camel@linux-fkkt.site> (raw)
In-Reply-To: <53B42B14.7010303@baslerweb.com>

On Wed, 2014-07-02 at 17:53 +0200, Stefan Klug wrote:

> @@ -1471,6 +1526,57 @@ static int proc_do_submiturb(struct
> usb_dev_state 
> *ps, struct usbdevfs_urb *uurb
>               }
>               totlen -= u;
>           }
> +    } else if(num_pages) {
> +        pages = kmalloc(num_pages*sizeof(struct page*), GFP_KERNEL);
> +        if(!pages) {
> +            ret = -ENOMEM;
> +            goto error;
> +        }
> +
> +        //create the scatterlist
> +        as->urb->sg = kmalloc(num_pages * sizeof(struct
> scatterlist), 
> GFP_KERNEL);
> +        if (!as->urb->sg) {
> +            ret = -ENOMEM;
> +            goto error;
> +        }
> +
> +        ret = get_user_pages_fast((unsigned long)buf_aligned,
> +                   num_pages,
> +                   is_in,
> +                   pages);
> +
> +        if(ret < 0) {
> +            printk("get_user_pages failed %i\n", ret);
> +            goto error;
> +        }
> +
> +        //did we get all pages?
> +        if(ret < num_pages) {
> +            printk("get_user_pages didn't deliver all pages %i\n",
> ret);
> +            //free the pages and error out
> +            for(i=0; i<ret; i++) {
> +                page_cache_release(pages[i]);
> +            }
> +            ret = -ENOMEM;
> +            goto error;
> +        }
> +
> +        as->is_user_mem = 1;
> +        as->urb->num_sgs = num_pages;
> +        sg_init_table(as->urb->sg, as->urb->num_sgs);
> +
> +        totlen = uurb->buffer_length + buf_offset;
> +        o = buf_offset;
> +        for (i = 0; i < as->urb->num_sgs; i++) {
> +            u = (totlen > PAGE_SIZE) ? PAGE_SIZE : totlen;
> +            u-= o;
> +            sg_set_page(&as->urb->sg[i], pages[i], u, o);
> +            totlen -= u + o;
> +            o = 0;
> +        }
> +
> +        kfree(pages);
> +        pages = NULL;
>       } else if (uurb->buffer_length > 0) {
>           as->urb->transfer_buffer = kmalloc(uurb->buffer_length,
>                   GFP_KERNEL)


One more thing: Where do you check that the memory the user has passed
a pointer to is actually writable? It seems to me that for zerocopy you
must do the check before you submit the URB to the HCD.

	Regards
		Oliver



      parent reply	other threads:[~2014-07-04  8:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-02 15:53 [PATCH][RFC] USB: zerocopy support for usbfs Stefan Klug
2014-07-02 17:55 ` Greg KH
2014-07-03  7:06   ` Stefan Klug
2014-07-02 18:24 ` Alan Stern
2014-07-02 18:49   ` Peter Stuge
2014-07-02 19:31     ` Alan Stern
2014-07-02 19:42       ` Peter Stuge
2014-07-02 20:40         ` Alan Stern
2014-07-03  7:48   ` Stefan Klug
2014-07-03  8:40     ` David Laight
2014-07-03 14:15     ` Alan Stern
2014-07-02 18:58 ` Oliver Neukum
2014-07-02 19:38   ` Alan Stern
2014-07-03  8:22     ` Stefan Klug
2014-07-04  8:55 ` Oliver Neukum [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1404464117.1915.7.camel@linux-fkkt.site \
    --to=oneukum@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stefan.klug@baslerweb.com \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).