linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Parvi Kaustubhi (pkaustub)" <pkaustub@cisco.com>
To: Davidlohr Bueso <dave@stgolabs.net>
Cc: "akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	Doug Ledford <dledford@redhat.com>,
	"jgg@mellanox.com" <jgg@mellanox.com>,
	"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"Christian Benvenuti (benve)" <benve@cisco.com>,
	"Nelson Escobar (neescoba)" <neescoba@cisco.com>,
	Davidlohr Bueso <dbueso@suse.de>
Subject: Re: [PATCH 5/6] drivers/IB,usnic: reduce scope of mmap_sem
Date: Thu, 17 Jan 2019 23:41:50 +0000	[thread overview]
Message-ID: <ED26DFF4-3798-417E-85BD-53FB32F2BE3A@cisco.com> (raw)
In-Reply-To: <20190115181300.27547-6-dave@stgolabs.net>

usnic driver was tested with this.

Acked-by: Parvi Kaustubhi <pkaustub@cisco.com>


> On Jan 15, 2019, at 10:12 AM, Davidlohr Bueso <dave@stgolabs.net> wrote:
> 
> usnic_uiom_get_pages() uses gup_longterm() so we cannot really
> get rid of mmap_sem altogether in the driver, but we can get
> rid of some complexity that mmap_sem brings with only pinned_vm.
> We can get rid of the wq altogether as we no longer need to
> defer work to unpin pages as the counter is now atomic.
> 
> Cc: benve@cisco.com
> Cc: neescoba@cisco.com
> Cc: pkaustub@cisco.com
> Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
> ---
> drivers/infiniband/hw/usnic/usnic_ib_main.c |  2 --
> drivers/infiniband/hw/usnic/usnic_uiom.c    | 54 +++--------------------------
> drivers/infiniband/hw/usnic/usnic_uiom.h    |  1 -
> 3 files changed, 4 insertions(+), 53 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/usnic/usnic_ib_main.c b/drivers/infiniband/hw/usnic/usnic_ib_main.c
> index b2323a52a0dd..64bc4fda36bf 100644
> --- a/drivers/infiniband/hw/usnic/usnic_ib_main.c
> +++ b/drivers/infiniband/hw/usnic/usnic_ib_main.c
> @@ -691,7 +691,6 @@ static int __init usnic_ib_init(void)
> out_pci_unreg:
> 	pci_unregister_driver(&usnic_ib_pci_driver);
> out_umem_fini:
> -	usnic_uiom_fini();
> 
> 	return err;
> }
> @@ -704,7 +703,6 @@ static void __exit usnic_ib_destroy(void)
> 	unregister_inetaddr_notifier(&usnic_ib_inetaddr_notifier);
> 	unregister_netdevice_notifier(&usnic_ib_netdevice_notifier);
> 	pci_unregister_driver(&usnic_ib_pci_driver);
> -	usnic_uiom_fini();
> }
> 
> MODULE_DESCRIPTION("Cisco VIC (usNIC) Verbs Driver");
> diff --git a/drivers/infiniband/hw/usnic/usnic_uiom.c b/drivers/infiniband/hw/usnic/usnic_uiom.c
> index 22c40c432b9e..555d7bc93e72 100644
> --- a/drivers/infiniband/hw/usnic/usnic_uiom.c
> +++ b/drivers/infiniband/hw/usnic/usnic_uiom.c
> @@ -47,8 +47,6 @@
> #include "usnic_uiom.h"
> #include "usnic_uiom_interval_tree.h"
> 
> -static struct workqueue_struct *usnic_uiom_wq;
> -
> #define USNIC_UIOM_PAGE_CHUNK						\
> 	((PAGE_SIZE - offsetof(struct usnic_uiom_chunk, page_list))	/\
> 	((void *) &((struct usnic_uiom_chunk *) 0)->page_list[1] -	\
> @@ -129,7 +127,7 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable,
> 	uiomr->owning_mm = mm = current->mm;
> 	down_write(&mm->mmap_sem);
> 
> -	locked = npages + atomic_long_read(&current->mm->pinned_vm);
> +	locked = atomic_long_add_return(npages, &current->mm->pinned_vm);
> 	lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
> 
> 	if ((locked > lock_limit) && !capable(CAP_IPC_LOCK)) {
> @@ -185,12 +183,11 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable,
> 	}
> 
> out:
> -	if (ret < 0)
> +	if (ret < 0) {
> 		usnic_uiom_put_pages(chunk_list, 0);
> -	else {
> -		atomic_long_set(&mm->pinned_vm, locked);
> +		atomic_long_sub(npages, &current->mm->pinned_vm);
> +	} else
> 		mmgrab(uiomr->owning_mm);
> -	}
> 
> 	up_write(&mm->mmap_sem);
> 	free_page((unsigned long) page_list);
> @@ -436,43 +433,12 @@ static inline size_t usnic_uiom_num_pages(struct usnic_uiom_reg *uiomr)
> 	return PAGE_ALIGN(uiomr->length + uiomr->offset) >> PAGE_SHIFT;
> }
> 
> -static void usnic_uiom_release_defer(struct work_struct *work)
> -{
> -	struct usnic_uiom_reg *uiomr =
> -		container_of(work, struct usnic_uiom_reg, work);
> -
> -	down_write(&uiomr->owning_mm->mmap_sem);
> -	atomic_long_sub(usnic_uiom_num_pages(uiomr), &uiomr->owning_mm->pinned_vm);
> -	up_write(&uiomr->owning_mm->mmap_sem);
> -
> -	__usnic_uiom_release_tail(uiomr);
> -}
> -
> void usnic_uiom_reg_release(struct usnic_uiom_reg *uiomr,
> 			    struct ib_ucontext *context)
> {
> 	__usnic_uiom_reg_release(uiomr->pd, uiomr, 1);
> 
> -	/*
> -	 * We may be called with the mm's mmap_sem already held.  This
> -	 * can happen when a userspace munmap() is the call that drops
> -	 * the last reference to our file and calls our release
> -	 * method.  If there are memory regions to destroy, we'll end
> -	 * up here and not be able to take the mmap_sem.  In that case
> -	 * we defer the vm_locked accounting to a workqueue.
> -	 */
> -	if (context->closing) {
> -		if (!down_write_trylock(&uiomr->owning_mm->mmap_sem)) {
> -			INIT_WORK(&uiomr->work, usnic_uiom_release_defer);
> -			queue_work(usnic_uiom_wq, &uiomr->work);
> -			return;
> -		}
> -	} else {
> -		down_write(&uiomr->owning_mm->mmap_sem);
> -	}
> 	atomic_long_sub(usnic_uiom_num_pages(uiomr), &uiomr->owning_mm->pinned_vm);
> -	up_write(&uiomr->owning_mm->mmap_sem);
> -
> 	__usnic_uiom_release_tail(uiomr);
> }
> 
> @@ -601,17 +567,5 @@ int usnic_uiom_init(char *drv_name)
> 		return -EPERM;
> 	}
> 
> -	usnic_uiom_wq = create_workqueue(drv_name);
> -	if (!usnic_uiom_wq) {
> -		usnic_err("Unable to alloc wq for drv %s\n", drv_name);
> -		return -ENOMEM;
> -	}
> -
> 	return 0;
> }
> -
> -void usnic_uiom_fini(void)
> -{
> -	flush_workqueue(usnic_uiom_wq);
> -	destroy_workqueue(usnic_uiom_wq);
> -}
> diff --git a/drivers/infiniband/hw/usnic/usnic_uiom.h b/drivers/infiniband/hw/usnic/usnic_uiom.h
> index b86a9731071b..c88cfa087e3a 100644
> --- a/drivers/infiniband/hw/usnic/usnic_uiom.h
> +++ b/drivers/infiniband/hw/usnic/usnic_uiom.h
> @@ -93,5 +93,4 @@ struct usnic_uiom_reg *usnic_uiom_reg_get(struct usnic_uiom_pd *pd,
> void usnic_uiom_reg_release(struct usnic_uiom_reg *uiomr,
> 			    struct ib_ucontext *ucontext);
> int usnic_uiom_init(char *drv_name);
> -void usnic_uiom_fini(void);
> #endif /* USNIC_UIOM_H_ */
> -- 
> 2.16.4
> 

  parent reply	other threads:[~2019-01-17 23:41 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-15 18:12 [PATCH -next 0/6] mm: make pinned_vm atomic and simplify users Davidlohr Bueso
2019-01-15 18:12 ` [PATCH 1/6] mm: make mm->pinned_vm an atomic counter Davidlohr Bueso
2019-01-15 20:28   ` Ira Weiny
2019-01-15 18:12 ` [PATCH 3/6] drivers/IB,qib: do not use mmap_sem Davidlohr Bueso
2019-01-15 20:29   ` Ira Weiny
2019-01-15 18:12 ` [PATCH 4/6] drivers/IB,hfi1: do not se mmap_sem Davidlohr Bueso
2019-01-15 20:29   ` Ira Weiny
2019-01-15 18:12 ` [PATCH 5/6] drivers/IB,usnic: reduce scope of mmap_sem Davidlohr Bueso
2019-01-15 20:30   ` Ira Weiny
2019-01-17 23:41   ` Parvi Kaustubhi (pkaustub) [this message]
2019-01-15 18:13 ` [PATCH 6/6] drivers/IB,core: " Davidlohr Bueso
2019-01-15 20:30   ` Ira Weiny
2019-01-15 20:53   ` Jason Gunthorpe
2019-01-15 21:12     ` Matthew Wilcox
2019-01-15 21:17       ` Jason Gunthorpe
2019-01-16 16:00         ` Davidlohr Bueso
2019-01-16 17:02           ` Jason Gunthorpe
2019-01-16 17:06             ` Matthew Wilcox
2019-01-16 17:29               ` Jason Gunthorpe
2019-01-15 18:18 ` [PATCH -next 0/6] mm: make pinned_vm atomic and simplify users Davidlohr Bueso
     [not found] ` <20190115181300.27547-3-dave@stgolabs.net>
2019-01-15 20:28   ` [PATCH 2/6] mic/scif: do not use mmap_sem Ira Weiny
2019-01-21 17:42 [PATCH v2 -next 0/6] mm: make pinned_vm atomic and simplify users Davidlohr Bueso
2019-01-21 17:42 ` [PATCH 5/6] drivers/IB,usnic: reduce scope of mmap_sem Davidlohr Bueso
2019-02-06 17:59 [PATCH v3 0/6] mm: make pinned_vm atomic and simplify users Davidlohr Bueso
2019-02-06 17:59 ` [PATCH 5/6] drivers/IB,usnic: reduce scope of mmap_sem Davidlohr Bueso

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=ED26DFF4-3798-417E-85BD-53FB32F2BE3A@cisco.com \
    --to=pkaustub@cisco.com \
    --cc=akpm@linux-foundation.org \
    --cc=benve@cisco.com \
    --cc=dave@stgolabs.net \
    --cc=dbueso@suse.de \
    --cc=dledford@redhat.com \
    --cc=jgg@mellanox.com \
    --cc=linux-mm@kvack.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=neescoba@cisco.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox