From: Paul Durrant <Paul.Durrant@citrix.com>
To: "'Boris Ostrovsky'" <boris.ostrovsky@oracle.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Juergen Gross <jgross@suse.com>
Subject: RE: [PATCH v2 2/3] xen/privcmd: Add IOCTL_PRIVCMD_DM_OP
Date: Fri, 10 Feb 2017 16:28:47 +0000 [thread overview]
Message-ID: <abdb859b09504c0d8675ef824258dfaa@AMSPEX02CL03.citrite.net> (raw)
In-Reply-To: <2937e443-e83f-a8c4-674e-33a49d8d4ba1@oracle.com>
> -----Original Message-----
> From: Boris Ostrovsky [mailto:boris.ostrovsky@oracle.com]
> Sent: 10 February 2017 16:18
> To: Paul Durrant <Paul.Durrant@citrix.com>; xen-devel@lists.xenproject.org;
> linux-kernel@vger.kernel.org
> Cc: Juergen Gross <jgross@suse.com>
> Subject: Re: [PATCH v2 2/3] xen/privcmd: Add IOCTL_PRIVCMD_DM_OP
>
> On 02/10/2017 09:24 AM, Paul Durrant wrote:
> > +static long privcmd_ioctl_dm_op(void __user *udata)
> > +{
> > + struct privcmd_dm_op kdata;
> > + struct privcmd_dm_op_buf *kbufs;
> > + unsigned int nr_pages = 0;
> > + struct page **pages = NULL;
> > + struct xen_dm_op_buf *xbufs = NULL;
> > + unsigned int i;
> > + long rc;
> > +
> > + if (copy_from_user(&kdata, udata, sizeof(kdata)))
> > + return -EFAULT;
> > +
> > + if (kdata.num == 0)
> > + return 0;
> > +
> > + /*
> > + * Set a tolerable upper limit on the number of buffers
> > + * without being overly restrictive, since we can't easily
> > + * predict what future dm_ops may require.
> > + */
>
> I think this deserves its own macro since it really has nothing to do
> with page size, has it? Especially since you are referencing it again
> below too.
>
>
> > + if (kdata.num * sizeof(*kbufs) > PAGE_SIZE)
> > + return -E2BIG;
> > +
> > + kbufs = kcalloc(kdata.num, sizeof(*kbufs), GFP_KERNEL);
> > + if (!kbufs)
> > + return -ENOMEM;
> > +
> > + if (copy_from_user(kbufs, kdata.ubufs,
> > + sizeof(*kbufs) * kdata.num)) {
> > + rc = -EFAULT;
> > + goto out;
> > + }
> > +
> > + for (i = 0; i < kdata.num; i++) {
> > + if (!access_ok(VERIFY_WRITE, kbufs[i].uptr,
> > + kbufs[i].size)) {
> > + rc = -EFAULT;
> > + goto out;
> > + }
> > +
> > + nr_pages += DIV_ROUND_UP(
> > + offset_in_page(kbufs[i].uptr) + kbufs[i].size,
> > + PAGE_SIZE);
> > + }
> > +
> > + /*
> > + * Again, set a tolerable upper limit on the number of pages
> > + * needed to lock all the buffers without being overly
> > + * restrictive, since we can't easily predict the size of
> > + * buffers future dm_ops may use.
> > + */
>
> OTOH, these two cases describe different types of copying (the first one
> is for buffer descriptors and the second is for buffers themselves). And
> so should they be limited by the same value?
>
I think there needs to be some limit and limiting the allocation to a page was the best I came up with. Can you think of a better one?
> > + if (nr_pages * sizeof(*pages) > PAGE_SIZE) {
> > + rc = -E2BIG;
> > + goto out;
> > + }
> > +
> > + pages = kcalloc(nr_pages, sizeof(*pages), GFP_KERNEL);
> > + if (!pages) {
> > + rc = -ENOMEM;
> > + goto out;
> > + }
> > +
> > + xbufs = kcalloc(kdata.num, sizeof(*xbufs), GFP_KERNEL);
> > + if (!xbufs) {
> > + rc = -ENOMEM;
> > + goto out;
> > + }
> > +
> > + rc = lock_pages(kbufs, kdata.num, pages, nr_pages);
>
>
> Aren't those buffers already locked (as Andrew mentioned)? They are
> mmapped with MAP_LOCKED.
No, they're not. The new libxendevicemodel code I have does not make any use of xencall or guest handles when privcmd supports the DM_OP ioctl, so the caller buffers will not be locked.
>
> And I also wonder whether we need to take rlimit(RLIMIT_MEMLOCK) into
> account.
>
Maybe. I'll look at that.
Paul
> -boris
>
>
next prev parent reply other threads:[~2017-02-10 16:37 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-10 14:24 [PATCH v2 0/3] xen/privcmd: support for dm_op and restriction Paul Durrant
2017-02-10 14:24 ` [PATCH v2 1/3] xen/privcmd: return -ENOTTY for unimplemented IOCTLs Paul Durrant
2017-02-10 14:24 ` [PATCH v2 2/3] xen/privcmd: Add IOCTL_PRIVCMD_DM_OP Paul Durrant
2017-02-10 16:17 ` Boris Ostrovsky
2017-02-10 16:28 ` Paul Durrant [this message]
2017-02-10 17:44 ` Boris Ostrovsky
2017-02-13 9:03 ` Paul Durrant
2017-02-13 14:08 ` Boris Ostrovsky
2017-02-13 14:19 ` Paul Durrant
2017-02-10 19:25 ` kbuild test robot
2017-02-10 14:24 ` [PATCH v2 3/3] xen/privcmd: add IOCTL_PRIVCMD_RESTRICT Paul Durrant
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=abdb859b09504c0d8675ef824258dfaa@AMSPEX02CL03.citrite.net \
--to=paul.durrant@citrix.com \
--cc=boris.ostrovsky@oracle.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=xen-devel@lists.xenproject.org \
/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
all inboxes | Powered by JetHome®