Re: [Nouveau] [PATCH 13/22] device-dax: use the dev_pagemap internal refcount

2019-06-14 Thread Christoph Hellwig
On Thu, Jun 13, 2019 at 05:22:17PM -0700, Ira Weiny wrote:
> > -   dev_dax->pgmap.ref = _dax->ref;
> 
> I don't think this exactly correct.  pgmap.ref is a pointer to the dev_dax ref
> structure.  Taking it away will cause devm_memremap_pages() to fail AFAICS.
> 
> I think you need to change struct dev_pagemap as well:

Take a look at the previous patch, which adds an internal_ref field
to dev_pagemap that ->ref is set up to point to if not otherwise
initialized.
___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

Re: [PATCH 13/22] device-dax: use the dev_pagemap internal refcount

2019-06-13 Thread Ira Weiny
On Thu, Jun 13, 2019 at 11:43:16AM +0200, Christoph Hellwig wrote:
> The functionality is identical to the one currently open coded in
> device-dax.
> 
> Signed-off-by: Christoph Hellwig 
> ---
>  drivers/dax/dax-private.h |  4 ---
>  drivers/dax/device.c  | 52 +--
>  2 files changed, 1 insertion(+), 55 deletions(-)
> 
> diff --git a/drivers/dax/dax-private.h b/drivers/dax/dax-private.h
> index a45612148ca0..ed04a18a35be 100644
> --- a/drivers/dax/dax-private.h
> +++ b/drivers/dax/dax-private.h
> @@ -51,8 +51,6 @@ struct dax_region {
>   * @target_node: effective numa node if dev_dax memory range is onlined
>   * @dev - device core
>   * @pgmap - pgmap for memmap setup / lifetime (driver owned)
> - * @ref: pgmap reference count (driver owned)
> - * @cmp: @ref final put completion (driver owned)
>   */
>  struct dev_dax {
>   struct dax_region *region;
> @@ -60,8 +58,6 @@ struct dev_dax {
>   int target_node;
>   struct device dev;
>   struct dev_pagemap pgmap;
> - struct percpu_ref ref;
> - struct completion cmp;
>  };
>  
>  static inline struct dev_dax *to_dev_dax(struct device *dev)
> diff --git a/drivers/dax/device.c b/drivers/dax/device.c
> index e23fa1bd8c97..a9d7c90ecf1e 100644
> --- a/drivers/dax/device.c
> +++ b/drivers/dax/device.c
> @@ -14,37 +14,6 @@
>  #include "dax-private.h"
>  #include "bus.h"
>  
> -static struct dev_dax *ref_to_dev_dax(struct percpu_ref *ref)
> -{
> - return container_of(ref, struct dev_dax, ref);
> -}
> -
> -static void dev_dax_percpu_release(struct percpu_ref *ref)
> -{
> - struct dev_dax *dev_dax = ref_to_dev_dax(ref);
> -
> - dev_dbg(_dax->dev, "%s\n", __func__);
> - complete(_dax->cmp);
> -}
> -
> -static void dev_dax_percpu_exit(void *data)
> -{
> - struct percpu_ref *ref = data;
> - struct dev_dax *dev_dax = ref_to_dev_dax(ref);
> -
> - dev_dbg(_dax->dev, "%s\n", __func__);
> - wait_for_completion(_dax->cmp);
> - percpu_ref_exit(ref);
> -}
> -
> -static void dev_dax_percpu_kill(struct dev_pagemap *pgmap)
> -{
> - struct dev_dax *dev_dax = container_of(pgmap, struct dev_dax, pgmap);
> -
> - dev_dbg(_dax->dev, "%s\n", __func__);
> - percpu_ref_kill(pgmap->ref);
> -}
> -
>  static int check_vma(struct dev_dax *dev_dax, struct vm_area_struct *vma,
>   const char *func)
>  {
> @@ -442,10 +411,6 @@ static void dev_dax_kill(void *dev_dax)
>   kill_dev_dax(dev_dax);
>  }
>  
> -static const struct dev_pagemap_ops dev_dax_pagemap_ops = {
> - .kill   = dev_dax_percpu_kill,
> -};
> -
>  int dev_dax_probe(struct device *dev)
>  {
>   struct dev_dax *dev_dax = to_dev_dax(dev);
> @@ -463,24 +428,9 @@ int dev_dax_probe(struct device *dev)
>   return -EBUSY;
>   }
>  
> - init_completion(_dax->cmp);
> - rc = percpu_ref_init(_dax->ref, dev_dax_percpu_release, 0,
> - GFP_KERNEL);
> - if (rc)
> - return rc;
> -
> - rc = devm_add_action_or_reset(dev, dev_dax_percpu_exit, _dax->ref);
> - if (rc)
> - return rc;
> -
> - dev_dax->pgmap.ref = _dax->ref;

I don't think this exactly correct.  pgmap.ref is a pointer to the dev_dax ref
structure.  Taking it away will cause devm_memremap_pages() to fail AFAICS.

I think you need to change struct dev_pagemap as well:

diff --git a/include/linux/memremap.h b/include/linux/memremap.h
index f0628660d541..5e2120589ddf 100644
--- a/include/linux/memremap.h
+++ b/include/linux/memremap.h
@@ -90,7 +90,7 @@ struct dev_pagemap {
struct vmem_altmap altmap;
bool altmap_valid;
struct resource res;
-   struct percpu_ref *ref;
+   struct percpu_ref ref;
void (*kill)(struct percpu_ref *ref);
struct device *dev;
void *data;

And all usages of it, right?

Ira

> - dev_dax->pgmap.ops = _dax_pagemap_ops;
>   addr = devm_memremap_pages(dev, _dax->pgmap);
> - if (IS_ERR(addr)) {
> - devm_remove_action(dev, dev_dax_percpu_exit, _dax->ref);
> - percpu_ref_exit(_dax->ref);
> + if (IS_ERR(addr))
>   return PTR_ERR(addr);
> - }
>  
>   inode = dax_inode(dax_dev);
>   cdev = inode->i_cdev;
> -- 
> 2.20.1
> 
> ___
> Linux-nvdimm mailing list
> linux-nvd...@lists.01.org
> https://lists.01.org/mailman/listinfo/linux-nvdimm


[Nouveau] [PATCH 13/22] device-dax: use the dev_pagemap internal refcount

2019-06-13 Thread Christoph Hellwig
The functionality is identical to the one currently open coded in
device-dax.

Signed-off-by: Christoph Hellwig 
---
 drivers/dax/dax-private.h |  4 ---
 drivers/dax/device.c  | 52 +--
 2 files changed, 1 insertion(+), 55 deletions(-)

diff --git a/drivers/dax/dax-private.h b/drivers/dax/dax-private.h
index a45612148ca0..ed04a18a35be 100644
--- a/drivers/dax/dax-private.h
+++ b/drivers/dax/dax-private.h
@@ -51,8 +51,6 @@ struct dax_region {
  * @target_node: effective numa node if dev_dax memory range is onlined
  * @dev - device core
  * @pgmap - pgmap for memmap setup / lifetime (driver owned)
- * @ref: pgmap reference count (driver owned)
- * @cmp: @ref final put completion (driver owned)
  */
 struct dev_dax {
struct dax_region *region;
@@ -60,8 +58,6 @@ struct dev_dax {
int target_node;
struct device dev;
struct dev_pagemap pgmap;
-   struct percpu_ref ref;
-   struct completion cmp;
 };
 
 static inline struct dev_dax *to_dev_dax(struct device *dev)
diff --git a/drivers/dax/device.c b/drivers/dax/device.c
index e23fa1bd8c97..a9d7c90ecf1e 100644
--- a/drivers/dax/device.c
+++ b/drivers/dax/device.c
@@ -14,37 +14,6 @@
 #include "dax-private.h"
 #include "bus.h"
 
-static struct dev_dax *ref_to_dev_dax(struct percpu_ref *ref)
-{
-   return container_of(ref, struct dev_dax, ref);
-}
-
-static void dev_dax_percpu_release(struct percpu_ref *ref)
-{
-   struct dev_dax *dev_dax = ref_to_dev_dax(ref);
-
-   dev_dbg(_dax->dev, "%s\n", __func__);
-   complete(_dax->cmp);
-}
-
-static void dev_dax_percpu_exit(void *data)
-{
-   struct percpu_ref *ref = data;
-   struct dev_dax *dev_dax = ref_to_dev_dax(ref);
-
-   dev_dbg(_dax->dev, "%s\n", __func__);
-   wait_for_completion(_dax->cmp);
-   percpu_ref_exit(ref);
-}
-
-static void dev_dax_percpu_kill(struct dev_pagemap *pgmap)
-{
-   struct dev_dax *dev_dax = container_of(pgmap, struct dev_dax, pgmap);
-
-   dev_dbg(_dax->dev, "%s\n", __func__);
-   percpu_ref_kill(pgmap->ref);
-}
-
 static int check_vma(struct dev_dax *dev_dax, struct vm_area_struct *vma,
const char *func)
 {
@@ -442,10 +411,6 @@ static void dev_dax_kill(void *dev_dax)
kill_dev_dax(dev_dax);
 }
 
-static const struct dev_pagemap_ops dev_dax_pagemap_ops = {
-   .kill   = dev_dax_percpu_kill,
-};
-
 int dev_dax_probe(struct device *dev)
 {
struct dev_dax *dev_dax = to_dev_dax(dev);
@@ -463,24 +428,9 @@ int dev_dax_probe(struct device *dev)
return -EBUSY;
}
 
-   init_completion(_dax->cmp);
-   rc = percpu_ref_init(_dax->ref, dev_dax_percpu_release, 0,
-   GFP_KERNEL);
-   if (rc)
-   return rc;
-
-   rc = devm_add_action_or_reset(dev, dev_dax_percpu_exit, _dax->ref);
-   if (rc)
-   return rc;
-
-   dev_dax->pgmap.ref = _dax->ref;
-   dev_dax->pgmap.ops = _dax_pagemap_ops;
addr = devm_memremap_pages(dev, _dax->pgmap);
-   if (IS_ERR(addr)) {
-   devm_remove_action(dev, dev_dax_percpu_exit, _dax->ref);
-   percpu_ref_exit(_dax->ref);
+   if (IS_ERR(addr))
return PTR_ERR(addr);
-   }
 
inode = dax_inode(dax_dev);
cdev = inode->i_cdev;
-- 
2.20.1

___
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau