All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Daniel Jordan <daniel.m.jordan@oracle.com>
Cc: akpm@linux-foundation.org, dave@stgolabs.net, jack@suse.cz,
	cl@linux.com, linux-mm@kvack.org, kvm@vger.kernel.org,
	kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org,
	alex.williamson@redhat.com, paulus@ozlabs.org,
	benh@kernel.crashing.org, mpe@ellerman.id.au, hao.wu@intel.com,
	atull@kernel.org, mdf@kernel.org, aik@ozlabs.ru
Subject: Re: [PATCH 1/5] vfio/type1: use pinned_vm instead of locked_vm to account pinned pages
Date: Mon, 11 Feb 2019 22:56:20 +0000	[thread overview]
Message-ID: <20190211225620.GO24692@ziepe.ca> (raw)
In-Reply-To: <20190211224437.25267-2-daniel.m.jordan@oracle.com>

On Mon, Feb 11, 2019 at 05:44:33PM -0500, Daniel Jordan wrote:
> Beginning with bc3e53f682d9 ("mm: distinguish between mlocked and pinned
> pages"), locked and pinned pages are accounted separately.  Type1
> accounts pinned pages to locked_vm; use pinned_vm instead.
> 
> pinned_vm recently became atomic and so no longer relies on mmap_sem
> held as writer: delete.
> 
> Signed-off-by: Daniel Jordan <daniel.m.jordan@oracle.com>
>  drivers/vfio/vfio_iommu_type1.c | 31 ++++++++++++-------------------
>  1 file changed, 12 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> index 73652e21efec..a56cc341813f 100644
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -257,7 +257,8 @@ static int vfio_iova_put_vfio_pfn(struct vfio_dma *dma, struct vfio_pfn *vpfn)
>  static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async)
>  {
>  	struct mm_struct *mm;
> -	int ret;
> +	s64 pinned_vm;
> +	int ret = 0;
>  
>  	if (!npage)
>  		return 0;
> @@ -266,24 +267,15 @@ static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async)
>  	if (!mm)
>  		return -ESRCH; /* process exited */
>  
> -	ret = down_write_killable(&mm->mmap_sem);
> -	if (!ret) {
> -		if (npage > 0) {
> -			if (!dma->lock_cap) {
> -				unsigned long limit;
> -
> -				limit = task_rlimit(dma->task,
> -						RLIMIT_MEMLOCK) >> PAGE_SHIFT;
> +	pinned_vm = atomic64_add_return(npage, &mm->pinned_vm);
>  
> -				if (mm->locked_vm + npage > limit)
> -					ret = -ENOMEM;
> -			}
> +	if (npage > 0 && !dma->lock_cap) {
> +		unsigned long limit = task_rlimit(dma->task, RLIMIT_MEMLOCK) >>
> +
> -					PAGE_SHIFT;

I haven't looked at this super closely, but how does this stuff work?

do_mlock doesn't touch pinned_vm, and this doesn't touch locked_vm...

Shouldn't all this be 'if (locked_vm + pinned_vm < RLIMIT_MEMLOCK)' ?

Otherwise MEMLOCK is really doubled..

Jason

WARNING: multiple messages have this Message-ID (diff)
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Daniel Jordan <daniel.m.jordan@oracle.com>
Cc: akpm@linux-foundation.org, dave@stgolabs.net, jack@suse.cz,
	cl@linux.com, linux-mm@kvack.org, kvm@vger.kernel.org,
	kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org,
	alex.williamson@redhat.com, paulus@ozlabs.org,
	benh@kernel.crashing.org, mpe@ellerman.id.au, hao.wu@intel.com,
	atull@kernel.org, mdf@kernel.org, aik@ozlabs.ru
Subject: Re: [PATCH 1/5] vfio/type1: use pinned_vm instead of locked_vm to account pinned pages
Date: Mon, 11 Feb 2019 15:56:20 -0700	[thread overview]
Message-ID: <20190211225620.GO24692@ziepe.ca> (raw)
In-Reply-To: <20190211224437.25267-2-daniel.m.jordan@oracle.com>

On Mon, Feb 11, 2019 at 05:44:33PM -0500, Daniel Jordan wrote:
> Beginning with bc3e53f682d9 ("mm: distinguish between mlocked and pinned
> pages"), locked and pinned pages are accounted separately.  Type1
> accounts pinned pages to locked_vm; use pinned_vm instead.
> 
> pinned_vm recently became atomic and so no longer relies on mmap_sem
> held as writer: delete.
> 
> Signed-off-by: Daniel Jordan <daniel.m.jordan@oracle.com>
>  drivers/vfio/vfio_iommu_type1.c | 31 ++++++++++++-------------------
>  1 file changed, 12 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> index 73652e21efec..a56cc341813f 100644
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -257,7 +257,8 @@ static int vfio_iova_put_vfio_pfn(struct vfio_dma *dma, struct vfio_pfn *vpfn)
>  static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async)
>  {
>  	struct mm_struct *mm;
> -	int ret;
> +	s64 pinned_vm;
> +	int ret = 0;
>  
>  	if (!npage)
>  		return 0;
> @@ -266,24 +267,15 @@ static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async)
>  	if (!mm)
>  		return -ESRCH; /* process exited */
>  
> -	ret = down_write_killable(&mm->mmap_sem);
> -	if (!ret) {
> -		if (npage > 0) {
> -			if (!dma->lock_cap) {
> -				unsigned long limit;
> -
> -				limit = task_rlimit(dma->task,
> -						RLIMIT_MEMLOCK) >> PAGE_SHIFT;
> +	pinned_vm = atomic64_add_return(npage, &mm->pinned_vm);
>  
> -				if (mm->locked_vm + npage > limit)
> -					ret = -ENOMEM;
> -			}
> +	if (npage > 0 && !dma->lock_cap) {
> +		unsigned long limit = task_rlimit(dma->task, RLIMIT_MEMLOCK) >>
> +
> -					PAGE_SHIFT;

I haven't looked at this super closely, but how does this stuff work?

do_mlock doesn't touch pinned_vm, and this doesn't touch locked_vm...

Shouldn't all this be 'if (locked_vm + pinned_vm < RLIMIT_MEMLOCK)' ?

Otherwise MEMLOCK is really doubled..

Jason

WARNING: multiple messages have this Message-ID (diff)
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Daniel Jordan <daniel.m.jordan@oracle.com>
Cc: dave@stgolabs.net, jack@suse.cz, kvm@vger.kernel.org,
	atull@kernel.org, aik@ozlabs.ru, linux-fpga@vger.kernel.org,
	linux-kernel@vger.kernel.org, kvm-ppc@vger.kernel.org,
	linux-mm@kvack.org, alex.williamson@redhat.com, mdf@kernel.org,
	akpm@linux-foundation.org, linuxppc-dev@lists.ozlabs.org,
	cl@linux.com, hao.wu@intel.com
Subject: Re: [PATCH 1/5] vfio/type1: use pinned_vm instead of locked_vm to account pinned pages
Date: Mon, 11 Feb 2019 15:56:20 -0700	[thread overview]
Message-ID: <20190211225620.GO24692@ziepe.ca> (raw)
In-Reply-To: <20190211224437.25267-2-daniel.m.jordan@oracle.com>

On Mon, Feb 11, 2019 at 05:44:33PM -0500, Daniel Jordan wrote:
> Beginning with bc3e53f682d9 ("mm: distinguish between mlocked and pinned
> pages"), locked and pinned pages are accounted separately.  Type1
> accounts pinned pages to locked_vm; use pinned_vm instead.
> 
> pinned_vm recently became atomic and so no longer relies on mmap_sem
> held as writer: delete.
> 
> Signed-off-by: Daniel Jordan <daniel.m.jordan@oracle.com>
>  drivers/vfio/vfio_iommu_type1.c | 31 ++++++++++++-------------------
>  1 file changed, 12 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> index 73652e21efec..a56cc341813f 100644
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -257,7 +257,8 @@ static int vfio_iova_put_vfio_pfn(struct vfio_dma *dma, struct vfio_pfn *vpfn)
>  static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async)
>  {
>  	struct mm_struct *mm;
> -	int ret;
> +	s64 pinned_vm;
> +	int ret = 0;
>  
>  	if (!npage)
>  		return 0;
> @@ -266,24 +267,15 @@ static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async)
>  	if (!mm)
>  		return -ESRCH; /* process exited */
>  
> -	ret = down_write_killable(&mm->mmap_sem);
> -	if (!ret) {
> -		if (npage > 0) {
> -			if (!dma->lock_cap) {
> -				unsigned long limit;
> -
> -				limit = task_rlimit(dma->task,
> -						RLIMIT_MEMLOCK) >> PAGE_SHIFT;
> +	pinned_vm = atomic64_add_return(npage, &mm->pinned_vm);
>  
> -				if (mm->locked_vm + npage > limit)
> -					ret = -ENOMEM;
> -			}
> +	if (npage > 0 && !dma->lock_cap) {
> +		unsigned long limit = task_rlimit(dma->task, RLIMIT_MEMLOCK) >>
> +
> -					PAGE_SHIFT;

I haven't looked at this super closely, but how does this stuff work?

do_mlock doesn't touch pinned_vm, and this doesn't touch locked_vm...

Shouldn't all this be 'if (locked_vm + pinned_vm < RLIMIT_MEMLOCK)' ?

Otherwise MEMLOCK is really doubled..

Jason

  reply	other threads:[~2019-02-11 22:56 UTC|newest]

Thread overview: 91+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-11 22:44 [PATCH 0/5] use pinned_vm instead of locked_vm to account pinned pages Daniel Jordan
2019-02-11 22:44 ` Daniel Jordan
2019-02-11 22:44 ` Daniel Jordan
2019-02-11 22:44 ` [PATCH 1/5] vfio/type1: " Daniel Jordan
2019-02-11 22:44   ` Daniel Jordan
2019-02-11 22:44   ` Daniel Jordan
2019-02-11 22:56   ` Jason Gunthorpe [this message]
2019-02-11 22:56     ` Jason Gunthorpe
2019-02-11 22:56     ` Jason Gunthorpe
2019-02-11 23:11     ` Daniel Jordan
2019-02-11 23:11       ` Daniel Jordan
2019-02-11 23:11       ` Daniel Jordan
2019-02-12 18:41       ` Alex Williamson
2019-02-12 18:41         ` Alex Williamson
2019-02-12 18:41         ` Alex Williamson
2019-02-13  0:26         ` Daniel Jordan
2019-02-13  0:26           ` Daniel Jordan
2019-02-13  0:26           ` Daniel Jordan
2019-02-13 20:03           ` Alex Williamson
2019-02-13 20:03             ` Alex Williamson
2019-02-13 20:03             ` Alex Williamson
2019-02-13 23:07             ` Jason Gunthorpe
2019-02-13 23:07               ` Jason Gunthorpe
2019-02-13 23:07               ` Jason Gunthorpe
2019-02-14  1:46             ` Daniel Jordan
2019-02-14  1:46               ` Daniel Jordan
2019-02-14  1:46               ` Daniel Jordan
2019-02-11 22:44 ` [PATCH 2/5] vfio/spapr_tce: " Daniel Jordan
2019-02-11 22:44   ` Daniel Jordan
2019-02-11 22:44   ` Daniel Jordan
2019-02-12  6:56   ` Alexey Kardashevskiy
2019-02-12  6:56     ` Alexey Kardashevskiy
2019-02-12  6:56     ` Alexey Kardashevskiy
2019-02-12 16:50     ` Christopher Lameter
2019-02-12 16:50       ` Christopher Lameter
2019-02-12 17:18       ` Daniel Jordan
2019-02-12 17:18         ` Daniel Jordan
2019-02-12 17:18         ` Daniel Jordan
2019-02-13  0:37         ` Alexey Kardashevskiy
2019-02-13  0:37           ` Alexey Kardashevskiy
2019-02-13  0:37           ` Alexey Kardashevskiy
2019-02-12 18:56     ` Alex Williamson
2019-02-12 18:56       ` Alex Williamson
2019-02-12 18:56       ` Alex Williamson
2019-02-13  0:34       ` Alexey Kardashevskiy
2019-02-13  0:34         ` Alexey Kardashevskiy
2019-02-13  0:34         ` Alexey Kardashevskiy
2019-02-11 22:44 ` [PATCH 3/5] fpga/dlf/afu: " Daniel Jordan
2019-02-11 22:44   ` Daniel Jordan
2019-02-11 22:44   ` Daniel Jordan
2019-02-11 22:44 ` [PATCH 4/5] powerpc/mmu: " Daniel Jordan
2019-02-11 22:44   ` Daniel Jordan
2019-02-11 22:44   ` Daniel Jordan
2019-02-13  1:14   ` kbuild test robot
2019-02-13  1:14     ` kbuild test robot
2019-02-13  1:14     ` kbuild test robot
2019-02-13  1:14     ` kbuild test robot
2019-02-11 22:44 ` [PATCH 5/5] kvm/book3s: " Daniel Jordan
2019-02-11 22:44   ` Daniel Jordan
2019-02-11 22:44   ` Daniel Jordan
2019-02-13  1:43   ` kbuild test robot
2019-02-13  1:43     ` kbuild test robot
2019-02-13  1:43     ` kbuild test robot
2019-02-13  1:43     ` kbuild test robot
2019-02-11 22:54 ` [PATCH 0/5] " Jason Gunthorpe
2019-02-11 22:54   ` Jason Gunthorpe
2019-02-11 22:54   ` Jason Gunthorpe
2019-02-11 23:15   ` Daniel Jordan
2019-02-11 23:15     ` Daniel Jordan
2019-02-11 23:15     ` Daniel Jordan
2019-02-14  1:53   ` Ira Weiny
2019-02-14  1:53     ` Ira Weiny
2019-02-14  1:53     ` Ira Weiny
2019-02-14  1:53     ` Ira Weiny
2019-02-14  6:00     ` Jason Gunthorpe
2019-02-14  6:00       ` Jason Gunthorpe
2019-02-14  6:00       ` Jason Gunthorpe
2019-02-14 19:33       ` Ira Weiny
2019-02-14 19:33         ` Ira Weiny
2019-02-14 19:33         ` Ira Weiny
2019-02-14 20:12         ` Jason Gunthorpe
2019-02-14 20:12           ` Jason Gunthorpe
2019-02-14 20:12           ` Jason Gunthorpe
2019-02-14 21:46           ` Ira Weiny
2019-02-14 21:46             ` Ira Weiny
2019-02-14 21:46             ` Ira Weiny
2019-02-14 22:16             ` Jason Gunthorpe
2019-02-14 22:16               ` Jason Gunthorpe
2019-02-14 22:16               ` Jason Gunthorpe
2019-02-15 15:26               ` Christopher Lameter
2019-02-15 15:26                 ` Christopher Lameter

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=20190211225620.GO24692@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=aik@ozlabs.ru \
    --cc=akpm@linux-foundation.org \
    --cc=alex.williamson@redhat.com \
    --cc=atull@kernel.org \
    --cc=benh@kernel.crashing.org \
    --cc=cl@linux.com \
    --cc=daniel.m.jordan@oracle.com \
    --cc=dave@stgolabs.net \
    --cc=hao.wu@intel.com \
    --cc=jack@suse.cz \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-fpga@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mdf@kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@ozlabs.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 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.