Re: [PATCH v3 07/17] IB/core: Add flags for on demand paging support

2014-12-16 Thread Yann Droneaud
Le mardi 16 décembre 2014 à 13:02 +0100, Yann Droneaud a écrit :
> Le jeudi 11 décembre 2014 à 17:04 +0200, Haggai Eran a écrit :
> > From: Sagi Grimberg 
> > 
> > * Add a configuration option for enable on-demand paging support in the
> >   infiniband subsystem (CONFIG_INFINIBAND_ON_DEMAND_PAGING). In a later 
> > patch,
> >   this configuration option will select the MMU_NOTIFIER configuration 
> > option
> >   to enable mmu notifiers.
> > * Add a flag for on demand paging (ODP) support in the IB device 
> > capabilities.
> > * Add a flag to request ODP MR in the access flags to reg_mr.
> > * Fail registrations done with the ODP flag when the low-level driver 
> > doesn't
> >   support this.
> > * Change the conditions in which an MR will be writable to explicitly
> >   specify the access flags. This is to avoid making an MR writable just
> >   because it is an ODP MR.
> > * Add a ODP capabilities to the extended query device verb.
> > 
> > Signed-off-by: Sagi Grimberg 
> > Signed-off-by: Shachar Raindel 
> > Signed-off-by: Haggai Eran 
> > ---
> >  drivers/infiniband/Kconfig   | 10 ++
> >  drivers/infiniband/core/umem.c   |  8 +---
> >  drivers/infiniband/core/uverbs_cmd.c | 25 +
> >  include/rdma/ib_verbs.h  | 28 ++--
> >  include/uapi/rdma/ib_user_verbs.h| 15 +++
> >  5 files changed, 81 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/infiniband/Kconfig b/drivers/infiniband/Kconfig
> > index 77089399359b..089a2c2af329 100644
> > --- a/drivers/infiniband/Kconfig
> > +++ b/drivers/infiniband/Kconfig
> > @@ -38,6 +38,16 @@ config INFINIBAND_USER_MEM
> > depends on INFINIBAND_USER_ACCESS != n
> > default y
> >  
> > +config INFINIBAND_ON_DEMAND_PAGING
> > +   bool "InfiniBand on-demand paging support"
> > +   depends on INFINIBAND_USER_MEM
> > +   default y
> > +   ---help---
> > + On demand paging support for the InfiniBand subsystem.
> > + Together with driver support this allows registration of
> > + memory regions without pinning their pages, fetching the
> > + pages on demand instead.
> > +
> >  config INFINIBAND_ADDR_TRANS
> > bool
> > depends on INFINIBAND
> > diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c
> > index 6f152628e0d2..c328e4693d14 100644
> > --- a/drivers/infiniband/core/umem.c
> > +++ b/drivers/infiniband/core/umem.c
> > @@ -107,13 +107,15 @@ struct ib_umem *ib_umem_get(struct ib_ucontext 
> > *context, unsigned long addr,
> > umem->page_size = PAGE_SIZE;
> > umem->pid   = get_task_pid(current, PIDTYPE_PID);
> > /*
> > -* We ask for writable memory if any access flags other than
> > -* "remote read" are set.  "Local write" and "remote write"
> > +* We ask for writable memory if any of the following
> > +* access flags are set.  "Local write" and "remote write"
> >  * obviously require write access.  "Remote atomic" can do
> >  * things like fetch and add, which will modify memory, and
> >  * "MW bind" can change permissions by binding a window.
> >  */
> > -   umem->writable  = !!(access & ~IB_ACCESS_REMOTE_READ);
> > +   umem->writable  = !!(access &
> > +   (IB_ACCESS_LOCAL_WRITE   | IB_ACCESS_REMOTE_WRITE |
> > +IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_MW_BIND));
> >  
> > /* We assume the memory is from hugetlb until proved otherwise */
> > umem->hugetlb   = 1;
> > diff --git a/drivers/infiniband/core/uverbs_cmd.c 
> > b/drivers/infiniband/core/uverbs_cmd.c
> > index c7a43624c96b..f9326ccda4b5 100644
> > --- a/drivers/infiniband/core/uverbs_cmd.c
> > +++ b/drivers/infiniband/core/uverbs_cmd.c
> > @@ -953,6 +953,18 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
> > goto err_free;
> > }
> >  
> > +   if (cmd.access_flags & IB_ACCESS_ON_DEMAND) {
> > +   struct ib_device_attr attr;
> > +
> > +   ret = ib_query_device(pd->device, &attr);
> > +   if (ret || !(attr.device_cap_flags &
> > +   IB_DEVICE_ON_DEMAND_PAGING)) {
> > +   pr_debug("ODP support not available\n");
> > +   ret = -EINVAL;
> > +   goto err_put;
> > +   }
> > +   }
> > +
> > mr = pd->device->reg_user_mr(pd, cmd.start, cmd.length, cmd.hca_va,
> >  cmd.access_flags, &udata);
> > if (IS_ERR(mr)) {
> > @@ -3289,6 +3301,19 @@ int ib_uverbs_ex_query_device(struct ib_uverbs_file 
> > *file,
> > copy_query_dev_fields(file, &resp.base, &attr);
> > resp.comp_mask = 0;
> >  
> > +#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
> > +   if (cmd.comp_mask & IB_USER_VERBS_EX_QUERY_DEVICE_ODP) {
> > +   resp.odp_caps.general_caps = attr.odp_caps.general_caps;
> > +   resp.odp_caps.per_transport_caps.rc_odp_caps =
> > +   attr.odp_caps.per_transport_caps.rc_odp_caps;
> > +   resp.odp_cap

Re: [PATCH v3 07/17] IB/core: Add flags for on demand paging support

2014-12-16 Thread Yann Droneaud
Hi,

Le jeudi 11 décembre 2014 à 17:04 +0200, Haggai Eran a écrit :
> From: Sagi Grimberg 
> 
> * Add a configuration option for enable on-demand paging support in the
>   infiniband subsystem (CONFIG_INFINIBAND_ON_DEMAND_PAGING). In a later patch,
>   this configuration option will select the MMU_NOTIFIER configuration option
>   to enable mmu notifiers.
> * Add a flag for on demand paging (ODP) support in the IB device capabilities.
> * Add a flag to request ODP MR in the access flags to reg_mr.
> * Fail registrations done with the ODP flag when the low-level driver doesn't
>   support this.
> * Change the conditions in which an MR will be writable to explicitly
>   specify the access flags. This is to avoid making an MR writable just
>   because it is an ODP MR.
> * Add a ODP capabilities to the extended query device verb.
> 
> Signed-off-by: Sagi Grimberg 
> Signed-off-by: Shachar Raindel 
> Signed-off-by: Haggai Eran 
> ---
>  drivers/infiniband/Kconfig   | 10 ++
>  drivers/infiniband/core/umem.c   |  8 +---
>  drivers/infiniband/core/uverbs_cmd.c | 25 +
>  include/rdma/ib_verbs.h  | 28 ++--
>  include/uapi/rdma/ib_user_verbs.h| 15 +++
>  5 files changed, 81 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/infiniband/Kconfig b/drivers/infiniband/Kconfig
> index 77089399359b..089a2c2af329 100644
> --- a/drivers/infiniband/Kconfig
> +++ b/drivers/infiniband/Kconfig
> @@ -38,6 +38,16 @@ config INFINIBAND_USER_MEM
>   depends on INFINIBAND_USER_ACCESS != n
>   default y
>  
> +config INFINIBAND_ON_DEMAND_PAGING
> + bool "InfiniBand on-demand paging support"
> + depends on INFINIBAND_USER_MEM
> + default y
> + ---help---
> +   On demand paging support for the InfiniBand subsystem.
> +   Together with driver support this allows registration of
> +   memory regions without pinning their pages, fetching the
> +   pages on demand instead.
> +
>  config INFINIBAND_ADDR_TRANS
>   bool
>   depends on INFINIBAND
> diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c
> index 6f152628e0d2..c328e4693d14 100644
> --- a/drivers/infiniband/core/umem.c
> +++ b/drivers/infiniband/core/umem.c
> @@ -107,13 +107,15 @@ struct ib_umem *ib_umem_get(struct ib_ucontext 
> *context, unsigned long addr,
>   umem->page_size = PAGE_SIZE;
>   umem->pid   = get_task_pid(current, PIDTYPE_PID);
>   /*
> -  * We ask for writable memory if any access flags other than
> -  * "remote read" are set.  "Local write" and "remote write"
> +  * We ask for writable memory if any of the following
> +  * access flags are set.  "Local write" and "remote write"
>* obviously require write access.  "Remote atomic" can do
>* things like fetch and add, which will modify memory, and
>* "MW bind" can change permissions by binding a window.
>*/
> - umem->writable  = !!(access & ~IB_ACCESS_REMOTE_READ);
> + umem->writable  = !!(access &
> + (IB_ACCESS_LOCAL_WRITE   | IB_ACCESS_REMOTE_WRITE |
> +  IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_MW_BIND));
>  
>   /* We assume the memory is from hugetlb until proved otherwise */
>   umem->hugetlb   = 1;
> diff --git a/drivers/infiniband/core/uverbs_cmd.c 
> b/drivers/infiniband/core/uverbs_cmd.c
> index c7a43624c96b..f9326ccda4b5 100644
> --- a/drivers/infiniband/core/uverbs_cmd.c
> +++ b/drivers/infiniband/core/uverbs_cmd.c
> @@ -953,6 +953,18 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
>   goto err_free;
>   }
>  
> + if (cmd.access_flags & IB_ACCESS_ON_DEMAND) {
> + struct ib_device_attr attr;
> +
> + ret = ib_query_device(pd->device, &attr);
> + if (ret || !(attr.device_cap_flags &
> + IB_DEVICE_ON_DEMAND_PAGING)) {
> + pr_debug("ODP support not available\n");
> + ret = -EINVAL;
> + goto err_put;
> + }
> + }
> +
>   mr = pd->device->reg_user_mr(pd, cmd.start, cmd.length, cmd.hca_va,
>cmd.access_flags, &udata);
>   if (IS_ERR(mr)) {
> @@ -3289,6 +3301,19 @@ int ib_uverbs_ex_query_device(struct ib_uverbs_file 
> *file,
>   copy_query_dev_fields(file, &resp.base, &attr);
>   resp.comp_mask = 0;
>  
> +#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
> + if (cmd.comp_mask & IB_USER_VERBS_EX_QUERY_DEVICE_ODP) {
> + resp.odp_caps.general_caps = attr.odp_caps.general_caps;
> + resp.odp_caps.per_transport_caps.rc_odp_caps =
> + attr.odp_caps.per_transport_caps.rc_odp_caps;
> + resp.odp_caps.per_transport_caps.uc_odp_caps =
> + attr.odp_caps.per_transport_caps.uc_odp_caps;
> + resp.odp_caps.per_transport_caps.ud_odp_caps =
> + 

[PATCH v3 07/17] IB/core: Add flags for on demand paging support

2014-12-11 Thread Haggai Eran
From: Sagi Grimberg 

* Add a configuration option for enable on-demand paging support in the
  infiniband subsystem (CONFIG_INFINIBAND_ON_DEMAND_PAGING). In a later patch,
  this configuration option will select the MMU_NOTIFIER configuration option
  to enable mmu notifiers.
* Add a flag for on demand paging (ODP) support in the IB device capabilities.
* Add a flag to request ODP MR in the access flags to reg_mr.
* Fail registrations done with the ODP flag when the low-level driver doesn't
  support this.
* Change the conditions in which an MR will be writable to explicitly
  specify the access flags. This is to avoid making an MR writable just
  because it is an ODP MR.
* Add a ODP capabilities to the extended query device verb.

Signed-off-by: Sagi Grimberg 
Signed-off-by: Shachar Raindel 
Signed-off-by: Haggai Eran 
---
 drivers/infiniband/Kconfig   | 10 ++
 drivers/infiniband/core/umem.c   |  8 +---
 drivers/infiniband/core/uverbs_cmd.c | 25 +
 include/rdma/ib_verbs.h  | 28 ++--
 include/uapi/rdma/ib_user_verbs.h| 15 +++
 5 files changed, 81 insertions(+), 5 deletions(-)

diff --git a/drivers/infiniband/Kconfig b/drivers/infiniband/Kconfig
index 77089399359b..089a2c2af329 100644
--- a/drivers/infiniband/Kconfig
+++ b/drivers/infiniband/Kconfig
@@ -38,6 +38,16 @@ config INFINIBAND_USER_MEM
depends on INFINIBAND_USER_ACCESS != n
default y
 
+config INFINIBAND_ON_DEMAND_PAGING
+   bool "InfiniBand on-demand paging support"
+   depends on INFINIBAND_USER_MEM
+   default y
+   ---help---
+ On demand paging support for the InfiniBand subsystem.
+ Together with driver support this allows registration of
+ memory regions without pinning their pages, fetching the
+ pages on demand instead.
+
 config INFINIBAND_ADDR_TRANS
bool
depends on INFINIBAND
diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c
index 6f152628e0d2..c328e4693d14 100644
--- a/drivers/infiniband/core/umem.c
+++ b/drivers/infiniband/core/umem.c
@@ -107,13 +107,15 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, 
unsigned long addr,
umem->page_size = PAGE_SIZE;
umem->pid   = get_task_pid(current, PIDTYPE_PID);
/*
-* We ask for writable memory if any access flags other than
-* "remote read" are set.  "Local write" and "remote write"
+* We ask for writable memory if any of the following
+* access flags are set.  "Local write" and "remote write"
 * obviously require write access.  "Remote atomic" can do
 * things like fetch and add, which will modify memory, and
 * "MW bind" can change permissions by binding a window.
 */
-   umem->writable  = !!(access & ~IB_ACCESS_REMOTE_READ);
+   umem->writable  = !!(access &
+   (IB_ACCESS_LOCAL_WRITE   | IB_ACCESS_REMOTE_WRITE |
+IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_MW_BIND));
 
/* We assume the memory is from hugetlb until proved otherwise */
umem->hugetlb   = 1;
diff --git a/drivers/infiniband/core/uverbs_cmd.c 
b/drivers/infiniband/core/uverbs_cmd.c
index c7a43624c96b..f9326ccda4b5 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -953,6 +953,18 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
goto err_free;
}
 
+   if (cmd.access_flags & IB_ACCESS_ON_DEMAND) {
+   struct ib_device_attr attr;
+
+   ret = ib_query_device(pd->device, &attr);
+   if (ret || !(attr.device_cap_flags &
+   IB_DEVICE_ON_DEMAND_PAGING)) {
+   pr_debug("ODP support not available\n");
+   ret = -EINVAL;
+   goto err_put;
+   }
+   }
+
mr = pd->device->reg_user_mr(pd, cmd.start, cmd.length, cmd.hca_va,
 cmd.access_flags, &udata);
if (IS_ERR(mr)) {
@@ -3289,6 +3301,19 @@ int ib_uverbs_ex_query_device(struct ib_uverbs_file 
*file,
copy_query_dev_fields(file, &resp.base, &attr);
resp.comp_mask = 0;
 
+#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
+   if (cmd.comp_mask & IB_USER_VERBS_EX_QUERY_DEVICE_ODP) {
+   resp.odp_caps.general_caps = attr.odp_caps.general_caps;
+   resp.odp_caps.per_transport_caps.rc_odp_caps =
+   attr.odp_caps.per_transport_caps.rc_odp_caps;
+   resp.odp_caps.per_transport_caps.uc_odp_caps =
+   attr.odp_caps.per_transport_caps.uc_odp_caps;
+   resp.odp_caps.per_transport_caps.ud_odp_caps =
+   attr.odp_caps.per_transport_caps.ud_odp_caps;
+   resp.comp_mask |= IB_USER_VERBS_EX_QUERY_DEVICE_ODP;
+   }
+#endif
+
err = ib_copy_to_udata(ucore, &resp