All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] crypto: testmgr - Only disable migration in crypto_disable_simd_for_test()
@ 2021-09-28 11:54 Sebastian Andrzej Siewior
  2021-10-05 18:17 ` Eric Biggers
  2021-10-08 12:24 ` Herbert Xu
  0 siblings, 2 replies; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2021-09-28 11:54 UTC (permalink / raw)
  To: linux-crypto
  Cc: Herbert Xu, David S. Miller, Thomas Gleixner, Sebastian Andrzej Siewior

crypto_disable_simd_for_test() disables preemption in order to receive a
stable per-CPU variable which it needs to modify in order to alter
crypto_simd_usable() results.

This can also be achived by migrate_disable() which forbidds CPU
migrations but allows the task to be preempted. The latter is important
for PREEMPT_RT since operation like skcipher_walk_first() may allocate
memory which must not happen with disabled preemption on PREEMPT_RT.

Use migrate_disable() in crypto_disable_simd_for_test() to achieve a
stable per-CPU pointer.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 crypto/testmgr.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -1061,14 +1061,14 @@ static void generate_random_testvec_conf
 
 static void crypto_disable_simd_for_test(void)
 {
-	preempt_disable();
+	migrate_disable();
 	__this_cpu_write(crypto_simd_disabled_for_test, true);
 }
 
 static void crypto_reenable_simd_for_test(void)
 {
 	__this_cpu_write(crypto_simd_disabled_for_test, false);
-	preempt_enable();
+	migrate_enable();
 }
 
 /*

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

* Re: [PATCH] crypto: testmgr - Only disable migration in crypto_disable_simd_for_test()
  2021-09-28 11:54 [PATCH] crypto: testmgr - Only disable migration in crypto_disable_simd_for_test() Sebastian Andrzej Siewior
@ 2021-10-05 18:17 ` Eric Biggers
  2021-10-07  9:42   ` Sebastian Andrzej Siewior
  2021-10-08 12:24 ` Herbert Xu
  1 sibling, 1 reply; 7+ messages in thread
From: Eric Biggers @ 2021-10-05 18:17 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-crypto, Herbert Xu, David S. Miller, Thomas Gleixner

Hi Sebastian,

On Tue, Sep 28, 2021 at 01:54:01PM +0200, Sebastian Andrzej Siewior wrote:
> crypto_disable_simd_for_test() disables preemption in order to receive a
> stable per-CPU variable which it needs to modify in order to alter
> crypto_simd_usable() results.
> 
> This can also be achived by migrate_disable() which forbidds CPU
> migrations but allows the task to be preempted. The latter is important
> for PREEMPT_RT since operation like skcipher_walk_first() may allocate
> memory which must not happen with disabled preemption on PREEMPT_RT.
> 
> Use migrate_disable() in crypto_disable_simd_for_test() to achieve a
> stable per-CPU pointer.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

The comment above the definition of migrate_disable() in include/linux/preempt.h
claims that it is a temporary workaround.

Is there a better way to do this that should be used instead?

- Eric

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

* Re: [PATCH] crypto: testmgr - Only disable migration in crypto_disable_simd_for_test()
  2021-10-05 18:17 ` Eric Biggers
@ 2021-10-07  9:42   ` Sebastian Andrzej Siewior
  2021-10-07 17:53     ` Eric Biggers
  0 siblings, 1 reply; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2021-10-07  9:42 UTC (permalink / raw)
  To: Eric Biggers
  Cc: linux-crypto, Herbert Xu, David S. Miller, Thomas Gleixner,
	Peter Zijlstra

On 2021-10-05 11:17:16 [-0700], Eric Biggers wrote:
> Hi Sebastian,
Hi,

> The comment above the definition of migrate_disable() in include/linux/preempt.h
> claims that it is a temporary workaround.

It claims that, yes. I think this is due to the scheduler's limitation
and should not encourage to use this over long sections.

> Is there a better way to do this that should be used instead?

An alternative might be to move the whole test into a kworker which is
bound to a specific CPU. So even without disabling preemption/ migration
the per-CPU pointer would remain stable.

> - Eric

Sebastian

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

* Re: [PATCH] crypto: testmgr - Only disable migration in crypto_disable_simd_for_test()
  2021-10-07  9:42   ` Sebastian Andrzej Siewior
@ 2021-10-07 17:53     ` Eric Biggers
  2021-10-07 19:03       ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Biggers @ 2021-10-07 17:53 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-crypto, Herbert Xu, David S. Miller, Thomas Gleixner,
	Peter Zijlstra

On Thu, Oct 07, 2021 at 11:42:24AM +0200, Sebastian Andrzej Siewior wrote:
> On 2021-10-05 11:17:16 [-0700], Eric Biggers wrote:
> > Hi Sebastian,
> Hi,
> 
> > The comment above the definition of migrate_disable() in include/linux/preempt.h
> > claims that it is a temporary workaround.
> 
> It claims that, yes. I think this is due to the scheduler's limitation
> and should not encourage to use this over long sections.
> 
> > Is there a better way to do this that should be used instead?
> 
> An alternative might be to move the whole test into a kworker which is
> bound to a specific CPU. So even without disabling preemption/ migration
> the per-CPU pointer would remain stable.
> 

It's only individual test cases that need to use the SIMD disabled flag, not the
whole test.  An algorithm test could involve 100 test cases, any subset of which
use the SIMD disabled flag and the others don't.  So the assumption is that this
can be a relatively fine-grained knob.  Executing different individual test
cases on different threads sounds painful.  Your simple change to use
migrate_disable() looks much better, but I'm not sure how to reconcile that with
the claim that migrate_disable() is a temporary workaround.

- Eric

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

* Re: [PATCH] crypto: testmgr - Only disable migration in crypto_disable_simd_for_test()
  2021-10-07 17:53     ` Eric Biggers
@ 2021-10-07 19:03       ` Sebastian Andrzej Siewior
  2021-10-08 11:34         ` Herbert Xu
  0 siblings, 1 reply; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2021-10-07 19:03 UTC (permalink / raw)
  To: Eric Biggers
  Cc: linux-crypto, Herbert Xu, David S. Miller, Thomas Gleixner,
	Peter Zijlstra

On 2021-10-07 10:53:03 [-0700], Eric Biggers wrote:
> On Thu, Oct 07, 2021 at 11:42:24AM +0200, Sebastian Andrzej Siewior wrote:
> > An alternative might be to move the whole test into a kworker which is
> > bound to a specific CPU. So even without disabling preemption/ migration
> > the per-CPU pointer would remain stable.
> > 
> 
> It's only individual test cases that need to use the SIMD disabled flag, not the
> whole test.  An algorithm test could involve 100 test cases, any subset of which
> use the SIMD disabled flag and the others don't.  So the assumption is that this
> can be a relatively fine-grained knob.  Executing different individual test
> cases on different threads sounds painful.  Your simple change to use
> migrate_disable() looks much better, but I'm not sure how to reconcile that with
> the claim that migrate_disable() is a temporary workaround.

Now that you bring it up, I was under the impression that the
"SIMD-disabled" flag is only changed by the tcrypt module not by the
individual tests which are performed at the algorithm lookup time. If it
is the latter than yes, it will be painful. If it is just tcrypt then
you could wrap the whole test-suite (at module init's time) into the
kworker and bind it to one CPU).

Maybe Peter can bring light into the temporary workaround but it does
look like simplest thing here.

> - Eric

Sebastian

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

* Re: [PATCH] crypto: testmgr - Only disable migration in crypto_disable_simd_for_test()
  2021-10-07 19:03       ` Sebastian Andrzej Siewior
@ 2021-10-08 11:34         ` Herbert Xu
  0 siblings, 0 replies; 7+ messages in thread
From: Herbert Xu @ 2021-10-08 11:34 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: Eric Biggers, linux-crypto, David S. Miller, Thomas Gleixner,
	Peter Zijlstra

On Thu, Oct 07, 2021 at 09:03:32PM +0200, Sebastian Andrzej Siewior wrote:
>
> Now that you bring it up, I was under the impression that the
> "SIMD-disabled" flag is only changed by the tcrypt module not by the
> individual tests which are performed at the algorithm lookup time. If it
> is the latter than yes, it will be painful. If it is just tcrypt then
> you could wrap the whole test-suite (at module init's time) into the
> kworker and bind it to one CPU).
> 
> Maybe Peter can bring light into the temporary workaround but it does
> look like simplest thing here.

Let's use migrate_disable for now.  If something better comes along
we can always change again.

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [PATCH] crypto: testmgr - Only disable migration in crypto_disable_simd_for_test()
  2021-09-28 11:54 [PATCH] crypto: testmgr - Only disable migration in crypto_disable_simd_for_test() Sebastian Andrzej Siewior
  2021-10-05 18:17 ` Eric Biggers
@ 2021-10-08 12:24 ` Herbert Xu
  1 sibling, 0 replies; 7+ messages in thread
From: Herbert Xu @ 2021-10-08 12:24 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior; +Cc: linux-crypto, David S. Miller, Thomas Gleixner

On Tue, Sep 28, 2021 at 01:54:01PM +0200, Sebastian Andrzej Siewior wrote:
> crypto_disable_simd_for_test() disables preemption in order to receive a
> stable per-CPU variable which it needs to modify in order to alter
> crypto_simd_usable() results.
> 
> This can also be achived by migrate_disable() which forbidds CPU
> migrations but allows the task to be preempted. The latter is important
> for PREEMPT_RT since operation like skcipher_walk_first() may allocate
> memory which must not happen with disabled preemption on PREEMPT_RT.
> 
> Use migrate_disable() in crypto_disable_simd_for_test() to achieve a
> stable per-CPU pointer.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  crypto/testmgr.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

end of thread, other threads:[~2021-10-08 12:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-28 11:54 [PATCH] crypto: testmgr - Only disable migration in crypto_disable_simd_for_test() Sebastian Andrzej Siewior
2021-10-05 18:17 ` Eric Biggers
2021-10-07  9:42   ` Sebastian Andrzej Siewior
2021-10-07 17:53     ` Eric Biggers
2021-10-07 19:03       ` Sebastian Andrzej Siewior
2021-10-08 11:34         ` Herbert Xu
2021-10-08 12:24 ` Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.