From: Peter Xu <peterx@redhat.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: kvm@vger.kernel.org, eric.auger@redhat.com, kwankhede@nvidia.com,
linux-kernel@vger.kernel.org, slp@redhat.com
Subject: Re: [PATCH v4 1/2] vfio/type1: Remove locked page accounting workqueue
Date: Mon, 17 Apr 2017 14:47:54 +0800 [thread overview]
Message-ID: <20170417064754.GC16703@pxdev.xzpeter.org> (raw)
In-Reply-To: <20170417014227.25866.59899.stgit@gimli.home>
On Sun, Apr 16, 2017 at 07:42:27PM -0600, Alex Williamson wrote:
[...]
> -static void vfio_lock_acct(struct task_struct *task, long npage)
> +static int vfio_lock_acct(struct task_struct *task, long npage, bool lock_cap)
> {
> - struct vwork *vwork;
> struct mm_struct *mm;
> bool is_current;
> + int ret;
>
> if (!npage)
> - return;
> + return 0;
>
> is_current = (task->mm == current->mm);
>
> mm = is_current ? task->mm : get_task_mm(task);
> if (!mm)
> - return; /* process exited */
> + return -ESRCH; /* process exited */
>
> - if (down_write_trylock(&mm->mmap_sem)) {
> - mm->locked_vm += npage;
> - up_write(&mm->mmap_sem);
> - if (!is_current)
> - mmput(mm);
> - return;
> - }
> + ret = down_write_killable(&mm->mmap_sem);
> + if (!ret) {
> + if (npage < 0 || lock_cap) {
Nit: maybe we can avoid passing in lock_cap in all the callers of
vfio_lock_acct() and fetch it via has_capability() only if npage < 0?
IMHO that'll keep the vfio_lock_acct() interface cleaner, and we won't
need to pass in "false" any time when doing unpins.
[...]
> @@ -405,7 +379,7 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr,
> static long vfio_pin_pages_remote(struct vfio_dma *dma, unsigned long vaddr,
> long npage, unsigned long *pfn_base)
> {
> - unsigned long limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
> + unsigned long pfn = 0, limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
> bool lock_cap = capable(CAP_IPC_LOCK);
> long ret, pinned = 0, lock_acct = 0;
> bool rsvd;
> @@ -442,8 +416,6 @@ static long vfio_pin_pages_remote(struct vfio_dma *dma, unsigned long vaddr,
> /* Lock all the consecutive pages from pfn_base */
> for (vaddr += PAGE_SIZE, iova += PAGE_SIZE; pinned < npage;
> pinned++, vaddr += PAGE_SIZE, iova += PAGE_SIZE) {
> - unsigned long pfn = 0;
> -
> ret = vaddr_get_pfn(current->mm, vaddr, dma->prot, &pfn);
> if (ret)
> break;
> @@ -460,14 +432,25 @@ static long vfio_pin_pages_remote(struct vfio_dma *dma, unsigned long vaddr,
> put_pfn(pfn, dma->prot);
> pr_warn("%s: RLIMIT_MEMLOCK (%ld) exceeded\n",
> __func__, limit << PAGE_SHIFT);
> - break;
> + ret = -ENOMEM;
> + goto unpin_out;
> }
> lock_acct++;
> }
> }
>
> out:
> - vfio_lock_acct(current, lock_acct);
> + ret = vfio_lock_acct(current, lock_acct, lock_cap);
I just didn't notice this in previous review, but... do we need to
check against !rsvd as well here before doing the accounting?
Thanks!
> +
> +unpin_out:
> + if (ret) {
> + if (!rsvd) {
> + for (pfn = *pfn_base ; pinned ; pfn++, pinned--)
> + put_pfn(pfn, dma->prot);
> + }
> +
> + return ret;
> + }
>
> return pinned;
> }
--
Peter Xu
next prev parent reply other threads:[~2017-04-17 6:48 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-17 1:42 [PATCH v4 0/2] vfio/type1: Synchronous locked page accounting Alex Williamson
2017-04-17 1:42 ` [PATCH v4 1/2] vfio/type1: Remove locked page accounting workqueue Alex Williamson
2017-04-17 6:47 ` Peter Xu [this message]
2017-04-17 14:32 ` Alex Williamson
2017-04-17 19:05 ` Kirti Wankhede
2017-04-17 19:19 ` Alex Williamson
2017-04-17 19:32 ` Kirti Wankhede
2017-04-17 21:32 ` Alex Williamson
2017-04-18 2:54 ` Peter Xu
2017-04-18 18:21 ` Kirti Wankhede
2017-04-17 1:42 ` [PATCH v4 2/2] vfio/type1: Prune vfio_pin_page_external() Alex Williamson
2017-04-17 6:54 ` Peter Xu
2017-04-17 17:20 ` Alex Williamson
2017-04-17 19:16 ` Kirti Wankhede
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=20170417064754.GC16703@pxdev.xzpeter.org \
--to=peterx@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=eric.auger@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=kwankhede@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=slp@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.