nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] device-dax: avoid hang on error before devm_memremap_pages()
@ 2018-07-31 14:32 Stefan Hajnoczi
  2018-08-01  0:26 ` Dave Jiang
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Hajnoczi @ 2018-07-31 14:32 UTC (permalink / raw)
  To: linux-nvdimm; +Cc: linux-kernel, Stefan Hajnoczi

dax_pmem_percpu_exit() waits for dax_pmem_percpu_release() to invoke the
dax_pmem->cmp completion.  Unfortunately this approach to cleaning up
the percpu_ref only works after devm_memremap_pages() was successful.

If devm_add_action_or_reset() or devm_memremap_pages() fails,
dax_pmem_percpu_release() is not invoked.  Therefore
dax_pmem_percpu_exit() hangs waiting for the completion:

  rc = devm_add_action_or_reset(dev, dax_pmem_percpu_exit,
  				&dax_pmem->ref);
  if (rc)
  	return rc;

  dax_pmem->pgmap.ref = &dax_pmem->ref;
  addr = devm_memremap_pages(dev, &dax_pmem->pgmap);

Avoid the hang by calling percpu_ref_exit() in the error paths instead
of going through dax_pmem_percpu_exit().

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
Found by code inspection.  Compile-tested only.
---
 drivers/dax/pmem.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c
index fd49b24fd6af..99e2aace8078 100644
--- a/drivers/dax/pmem.c
+++ b/drivers/dax/pmem.c
@@ -105,15 +105,19 @@ static int dax_pmem_probe(struct device *dev)
 	if (rc)
 		return rc;
 
-	rc = devm_add_action_or_reset(dev, dax_pmem_percpu_exit,
-							&dax_pmem->ref);
-	if (rc)
+	rc = devm_add_action(dev, dax_pmem_percpu_exit, &dax_pmem->ref);
+	if (rc) {
+		percpu_ref_exit(&dax_pmem->ref);
 		return rc;
+	}
 
 	dax_pmem->pgmap.ref = &dax_pmem->ref;
 	addr = devm_memremap_pages(dev, &dax_pmem->pgmap);
-	if (IS_ERR(addr))
+	if (IS_ERR(addr)) {
+		devm_remove_action(dev, dax_pmem_percpu_exit, &dax_pmem->ref);
+		percpu_ref_exit(&dax_pmem->ref);
 		return PTR_ERR(addr);
+	}
 
 	rc = devm_add_action_or_reset(dev, dax_pmem_percpu_kill,
 							&dax_pmem->ref);
-- 
2.17.1

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] device-dax: avoid hang on error before devm_memremap_pages()
  2018-07-31 14:32 [PATCH] device-dax: avoid hang on error before devm_memremap_pages() Stefan Hajnoczi
@ 2018-08-01  0:26 ` Dave Jiang
  2018-09-11  6:02   ` Dan Williams
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Jiang @ 2018-08-01  0:26 UTC (permalink / raw)
  To: Stefan Hajnoczi, linux-nvdimm; +Cc: linux-kernel


On 7/31/2018 7:32 AM, Stefan Hajnoczi wrote:
> dax_pmem_percpu_exit() waits for dax_pmem_percpu_release() to invoke the
> dax_pmem->cmp completion.  Unfortunately this approach to cleaning up
> the percpu_ref only works after devm_memremap_pages() was successful.
>
> If devm_add_action_or_reset() or devm_memremap_pages() fails,
> dax_pmem_percpu_release() is not invoked.  Therefore
> dax_pmem_percpu_exit() hangs waiting for the completion:
>
>    rc = devm_add_action_or_reset(dev, dax_pmem_percpu_exit,
>    				&dax_pmem->ref);
>    if (rc)
>    	return rc;
>
>    dax_pmem->pgmap.ref = &dax_pmem->ref;
>    addr = devm_memremap_pages(dev, &dax_pmem->pgmap);
>
> Avoid the hang by calling percpu_ref_exit() in the error paths instead
> of going through dax_pmem_percpu_exit().
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>

Applied


> ---
> Found by code inspection.  Compile-tested only.
> ---
>   drivers/dax/pmem.c | 12 ++++++++----
>   1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c
> index fd49b24fd6af..99e2aace8078 100644
> --- a/drivers/dax/pmem.c
> +++ b/drivers/dax/pmem.c
> @@ -105,15 +105,19 @@ static int dax_pmem_probe(struct device *dev)
>   	if (rc)
>   		return rc;
>   
> -	rc = devm_add_action_or_reset(dev, dax_pmem_percpu_exit,
> -							&dax_pmem->ref);
> -	if (rc)
> +	rc = devm_add_action(dev, dax_pmem_percpu_exit, &dax_pmem->ref);
> +	if (rc) {
> +		percpu_ref_exit(&dax_pmem->ref);
>   		return rc;
> +	}
>   
>   	dax_pmem->pgmap.ref = &dax_pmem->ref;
>   	addr = devm_memremap_pages(dev, &dax_pmem->pgmap);
> -	if (IS_ERR(addr))
> +	if (IS_ERR(addr)) {
> +		devm_remove_action(dev, dax_pmem_percpu_exit, &dax_pmem->ref);
> +		percpu_ref_exit(&dax_pmem->ref);
>   		return PTR_ERR(addr);
> +	}
>   
>   	rc = devm_add_action_or_reset(dev, dax_pmem_percpu_kill,
>   							&dax_pmem->ref);
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] device-dax: avoid hang on error before devm_memremap_pages()
  2018-08-01  0:26 ` Dave Jiang
@ 2018-09-11  6:02   ` Dan Williams
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Williams @ 2018-09-11  6:02 UTC (permalink / raw)
  To: Dave Jiang; +Cc: Linux Kernel Mailing List, Stefan Hajnoczi, linux-nvdimm

On Tue, Jul 31, 2018 at 5:26 PM, Dave Jiang <dave.jiang@intel.com> wrote:
>
>
> On 7/31/2018 7:32 AM, Stefan Hajnoczi wrote:
>>
>> dax_pmem_percpu_exit() waits for dax_pmem_percpu_release() to invoke the
>> dax_pmem->cmp completion.  Unfortunately this approach to cleaning up
>> the percpu_ref only works after devm_memremap_pages() was successful.
>>
>> If devm_add_action_or_reset() or devm_memremap_pages() fails,
>> dax_pmem_percpu_release() is not invoked.  Therefore
>> dax_pmem_percpu_exit() hangs waiting for the completion:
>>
>>    rc = devm_add_action_or_reset(dev, dax_pmem_percpu_exit,
>>                                 &dax_pmem->ref);
>>    if (rc)
>>         return rc;
>>
>>    dax_pmem->pgmap.ref = &dax_pmem->ref;
>>    addr = devm_memremap_pages(dev, &dax_pmem->pgmap);
>>
>> Avoid the hang by calling percpu_ref_exit() in the error paths instead
>> of going through dax_pmem_percpu_exit().
>>
>> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
>
>
> Applied
>

A similar problem exists in other devm_memremap_pages() users. I had a
more comprehensive fix in-flight that I will rebase on top of this
change.

    https://lore.kernel.org/patchwork/patch/961576/
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-09-11  6:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-31 14:32 [PATCH] device-dax: avoid hang on error before devm_memremap_pages() Stefan Hajnoczi
2018-08-01  0:26 ` Dave Jiang
2018-09-11  6:02   ` Dan Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).