linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steffen Klassert <steffen.klassert@secunet.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Daniel Jordan <daniel.m.jordan@oracle.com>,
	<andrea.parri@amarulasolutions.com>, <boqun.feng@gmail.com>,
	<paulmck@linux.ibm.com>, <peterz@infradead.org>,
	<linux-arch@vger.kernel.org>, <linux-crypto@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [v2 PATCH] padata: Use RCU when fetching pd from do_serial
Date: Wed, 17 Jul 2019 10:36:41 +0200	[thread overview]
Message-ID: <20190717083641.GQ17989@gauss3.secunet.de> (raw)
In-Reply-To: <20190716132345.ujj2v3kqra2lbi75@gondor.apana.org.au>

On Tue, Jul 16, 2019 at 09:23:45PM +0800, Herbert Xu wrote:
> On Tue, Jul 16, 2019 at 09:09:28PM +0800, Herbert Xu wrote:
> >
> > Hmm, it doesn't work because the refcnt is attached to the old
> > pd.  That shouldn't be a problem though as we could simply ignore
> > the refcnt in padata_flush_queue.
> 
> This should fix it:
> 
> ---8<---
> The function padata_do_serial uses parallel_data without obeying
> the RCU rules around its life-cycle.  This means that a concurrent
> padata_replace call can result in a crash.
> 
> This patch fixes it by using RCU just as we do in padata_do_parallel.

RCU alone won't help because if some object is queued for async
crypto, we left the RCU protected aera. I think padata_do_serial
needs to do RCU and should free 'parallel_data' if the flag
PADATA_RESET is set and the refcount goes to zero. padata_replace
should do the same then.

> 
> As the refcnt may now span two parallel_data structures, this patch
> moves it to padata_instance instead.  FWIW the refcnt is used to
> limit the number of outstanding requests (albeit a soft limit as
> we don't do a proper atomic inc and test).
> 
> Fixes: 16295bec6398 ("padata: Generic parallelization/...")
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
> 
> diff --git a/include/linux/padata.h b/include/linux/padata.h

...

> index 5d13d25da2c8..ce51555cb86c 100644
> @@ -367,7 +367,7 @@ void padata_do_serial(struct padata_priv *padata)
>  	struct parallel_data *pd;
>  	int reorder_via_wq = 0;
>  
> -	pd = padata->pd;
> +	pd = rcu_dereference_bh(padata->inst->pd);

Why not just

pd = rcu_dereference_bh(padata->pd);


  reply	other threads:[~2019-07-17  8:36 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-11 22:12 [PATCH] padata: use smp_mb in padata_reorder to avoid orphaned padata jobs Daniel Jordan
2019-07-12 10:06 ` Herbert Xu
2019-07-12 10:10   ` Steffen Klassert
2019-07-12 16:07     ` Daniel Jordan
2019-07-13  5:03       ` Herbert Xu
2019-07-15 16:10         ` Daniel Jordan
2019-07-16 10:04           ` Herbert Xu
2019-07-16 11:14             ` Steffen Klassert
2019-07-16 12:57               ` [PATCH] padata: Use RCU when fetching pd from do_serial Herbert Xu
2019-07-16 13:09                 ` Herbert Xu
2019-07-16 13:23                   ` [v2 PATCH] " Herbert Xu
2019-07-17  8:36                     ` Steffen Klassert [this message]
2019-07-17  8:50                       ` Herbert Xu
2019-07-17  8:28                   ` [PATCH] " Steffen Klassert
2019-07-17  8:47                     ` Herbert Xu
2019-07-17  8:53                       ` Steffen Klassert
2019-07-16 13:15                 ` Peter Zijlstra
2019-07-16 13:18                   ` Herbert Xu
2019-07-16 13:50                     ` Peter Zijlstra
2019-07-16 13:52                       ` Herbert Xu
2019-07-16 12:53       ` [PATCH] padata: use smp_mb in padata_reorder to avoid orphaned padata jobs Andrea Parri
2019-07-16 13:13         ` Peter Zijlstra
2019-07-16 15:01         ` Herbert Xu
2019-07-16 15:44           ` Daniel Jordan
2019-07-16 16:32             ` [PATCH v2] " Daniel Jordan
2019-07-17 11:11               ` [PATCH] padata: Replace delayed timer with immediate workqueue in padata_reorder Herbert Xu
2019-07-17 18:32                 ` Daniel Jordan
2019-07-18  3:31                   ` Herbert Xu
2019-07-18 14:27                     ` Daniel Jordan
2019-07-18 14:56                       ` Herbert Xu
2019-07-18 15:01                         ` [v2 PATCH] " Herbert Xu
2019-07-19 14:37                           ` Daniel Jordan
2019-07-19 14:55                             ` Herbert Xu
2019-07-19 19:04                               ` [PATCH] padata: purge get_cpu and reorder_via_wq from padata_do_serial Daniel Jordan
2019-07-26 12:36                                 ` Herbert Xu
2019-07-19 14:27                         ` [PATCH] padata: Replace delayed timer with immediate workqueue in padata_reorder Daniel Jordan
2019-07-17 23:21                 ` Daniel Jordan
2019-07-18  3:30                   ` Herbert Xu
2019-07-18 14:25                     ` Daniel Jordan
2019-07-18 14:49                       ` Herbert Xu
2019-07-19 14:21                         ` Daniel Jordan
2019-07-18  5:42               ` [PATCH v2] padata: use smp_mb in padata_reorder to avoid orphaned padata jobs Herbert Xu

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=20190717083641.GQ17989@gauss3.secunet.de \
    --to=steffen.klassert@secunet.com \
    --cc=andrea.parri@amarulasolutions.com \
    --cc=boqun.feng@gmail.com \
    --cc=daniel.m.jordan@oracle.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.ibm.com \
    --cc=peterz@infradead.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 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).