Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1624892 > unrolled thread
| Started by | Alex Williamson <alex.williamson@redhat.com> |
|---|---|
| First post | 2017-04-18 00:40 +0200 |
| Last post | 2017-04-18 21:00 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH v5 0/3] vfio/type1: Synchronous locked page accounting Alex Williamson <alex.williamson@redhat.com> - 2017-04-18 00:40 +0200
[PATCH v5 2/3] vfio/type1: Prune vfio_pin_page_external() Alex Williamson <alex.williamson@redhat.com> - 2017-04-18 00:40 +0200
Re: [PATCH v5 0/3] vfio/type1: Synchronous locked page accounting Peter Xu <peterx@redhat.com> - 2017-04-18 06:30 +0200
Re: [PATCH v5 0/3] vfio/type1: Synchronous locked page accounting Kirti Wankhede <kwankhede@nvidia.com> - 2017-04-18 21:00 +0200
| From | Alex Williamson <alex.williamson@redhat.com> |
|---|---|
| Date | 2017-04-18 00:40 +0200 |
| Subject | [PATCH v5 0/3] vfio/type1: Synchronous locked page accounting |
| Message-ID | <txntn-6u0-5@gated-at.bofh.it> |
v5:
- patch 1/ Use bool* to cleanup vfio_lock_acct() callers; sorry
we cannot re-test CAP_IPC_LOCK for all callers
- patch 2/ Re-add pr_warn, add Kirti's R-b
- patch 3/ NEW, analyzing impact of vfio_lock_acct() testing
CAP_IPC_LOCK for all callers revealed a long hanging
optimization
Thanks for the reviews, keep 'em coming,
Alex
---
Alex Williamson (3):
vfio/type1: Remove locked page accounting workqueue
vfio/type1: Prune vfio_pin_page_external()
vfio/type1: Reduce repetitive calls in vfio_pin_pages_remote()
drivers/vfio/vfio_iommu_type1.c | 150 +++++++++++++++++----------------------
1 file changed, 64 insertions(+), 86 deletions(-)
[toc] | [next] | [standalone]
| From | Alex Williamson <alex.williamson@redhat.com> |
|---|---|
| Date | 2017-04-18 00:40 +0200 |
| Subject | [PATCH v5 2/3] vfio/type1: Prune vfio_pin_page_external() |
| Message-ID | <txnto-6u0-19@gated-at.bofh.it> |
| In reply to | #1624892 |
With vfio_lock_acct() testing the locked memory limit under mmap_sem,
it's redundant to do it here for a single page. We can also reorder
our tests such that we can avoid testing for reserved pages if we're
not doing accounting and let vfio_lock_acct() test the process
CAP_IPC_LOCK. Finally, this function oddly returns 1 on success.
Update to return zero on success, -errno on error. Since the function
only pins a single page, there's no need to return the number of pages
pinned.
N.B. vfio_pin_pages_remote() can pin a large contiguous range of pages
before calling vfio_lock_acct(). If we were to similarly remove the
extra test there, a user could temporarily pin far more pages than
they're allowed.
Suggested-by: Kirti Wankhede <kwankhede@nvidia.com>
Suggested-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Kirti Wankhede <kwankhede@nvidia.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
drivers/vfio/vfio_iommu_type1.c | 35 ++++++++---------------------------
1 file changed, 8 insertions(+), 27 deletions(-)
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index a8a079ba9477..372e4f626138 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -482,43 +482,26 @@ static long vfio_unpin_pages_remote(struct vfio_dma *dma, dma_addr_t iova,
static int vfio_pin_page_external(struct vfio_dma *dma, unsigned long vaddr,
unsigned long *pfn_base, bool do_accounting)
{
- unsigned long limit;
- bool lock_cap = has_capability(dma->task, CAP_IPC_LOCK);
struct mm_struct *mm;
int ret;
- bool rsvd;
mm = get_task_mm(dma->task);
if (!mm)
return -ENODEV;
ret = vaddr_get_pfn(mm, vaddr, dma->prot, pfn_base);
- if (ret)
- goto pin_page_exit;
-
- rsvd = is_invalid_reserved_pfn(*pfn_base);
- limit = task_rlimit(dma->task, RLIMIT_MEMLOCK) >> PAGE_SHIFT;
-
- if (!rsvd && !lock_cap && mm->locked_vm + 1 > limit) {
- put_pfn(*pfn_base, dma->prot);
- pr_warn("%s: Task %s (%d) RLIMIT_MEMLOCK (%ld) exceeded\n",
- __func__, dma->task->comm, task_pid_nr(dma->task),
- limit << PAGE_SHIFT);
- ret = -ENOMEM;
- goto pin_page_exit;
- }
-
- if (!rsvd && do_accounting) {
- ret = vfio_lock_acct(dma->task, 1, &lock_cap);
+ if (!ret && do_accounting && !is_invalid_reserved_pfn(*pfn_base)) {
+ ret = vfio_lock_acct(dma->task, 1, NULL);
if (ret) {
put_pfn(*pfn_base, dma->prot);
- goto pin_page_exit;
+ if (ret == -ENOMEM)
+ pr_warn("%s: Task %s (%d) RLIMIT_MEMLOCK "
+ "(%ld) exceeded\n", __func__,
+ dma->task->comm, task_pid_nr(dma->task),
+ task_rlimit(dma->task, RLIMIT_MEMLOCK));
}
}
- ret = 1;
-
-pin_page_exit:
mmput(mm);
return ret;
}
@@ -598,10 +581,8 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data,
remote_vaddr = dma->vaddr + iova - dma->iova;
ret = vfio_pin_page_external(dma, remote_vaddr, &phys_pfn[i],
do_accounting);
- if (ret <= 0) {
- WARN_ON(!ret);
+ if (ret)
goto pin_unwind;
- }
ret = vfio_add_to_pfn_list(dma, iova, phys_pfn[i]);
if (ret) {
[toc] | [prev] | [next] | [standalone]
| From | Peter Xu <peterx@redhat.com> |
|---|---|
| Date | 2017-04-18 06:30 +0200 |
| Message-ID | <txsW5-1Cc-1@gated-at.bofh.it> |
| In reply to | #1624892 |
On Mon, Apr 17, 2017 at 04:37:38PM -0600, Alex Williamson wrote: > v5: > - patch 1/ Use bool* to cleanup vfio_lock_acct() callers; sorry > we cannot re-test CAP_IPC_LOCK for all callers > - patch 2/ Re-add pr_warn, add Kirti's R-b > - patch 3/ NEW, analyzing impact of vfio_lock_acct() testing > CAP_IPC_LOCK for all callers revealed a long hanging > optimization > > Thanks for the reviews, keep 'em coming, All patches looks good to me. Reviewed-by: Peter Xu <peterx@redhat.com> Thanks! -- Peter Xu
[toc] | [prev] | [next] | [standalone]
| From | Kirti Wankhede <kwankhede@nvidia.com> |
|---|---|
| Date | 2017-04-18 21:00 +0200 |
| Message-ID | <txGw2-1bd-1@gated-at.bofh.it> |
| In reply to | #1625012 |
On 4/18/2017 9:53 AM, Peter Xu wrote: > On Mon, Apr 17, 2017 at 04:37:38PM -0600, Alex Williamson wrote: >> v5: >> - patch 1/ Use bool* to cleanup vfio_lock_acct() callers; sorry >> we cannot re-test CAP_IPC_LOCK for all callers >> - patch 2/ Re-add pr_warn, add Kirti's R-b >> - patch 3/ NEW, analyzing impact of vfio_lock_acct() testing >> CAP_IPC_LOCK for all callers revealed a long hanging >> optimization >> >> Thanks for the reviews, keep 'em coming, > > All patches looks good to me. > > Reviewed-by: Peter Xu <peterx@redhat.com> > > Thanks! > All three looks good to me too. Reviewed-by: Kirti Wankhede <kwankhede@nvidia.com> Thanks, Kirti
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web