Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Corentin Labbe <clabbe.montjoie@gmail.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: davem@davemloft.net, linux-arm-kernel@lists.infradead.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: crypto: BUG: spinlock recursion when doing iperf over ipsec with crypto hardware device
Date: Tue, 18 Jan 2022 08:52:53 +0100	[thread overview]
Message-ID: <YeZx1aVL0HnT9tCB@Red> (raw)
In-Reply-To: <YeEiWmkyNwfgQgmn@Red>

Le Fri, Jan 14, 2022 at 08:12:26AM +0100, Corentin Labbe a écrit :
> Le Fri, Jan 14, 2022 at 03:23:26PM +1100, Herbert Xu a écrit :
> > On Fri, Jan 14, 2022 at 03:14:38PM +1100, Herbert Xu wrote:
> > > On Tue, Jan 11, 2022 at 10:47:12AM +0100, Corentin Labbe wrote:
> > > >
> > > > [   44.646050] [<c0100afc>] (__irq_svc) from [<c080b9d4>] (xfrm_replay_advance+0x11c/0x3dc)
> > > > [   44.654143] [<c080b9d4>] (xfrm_replay_advance) from [<c0809388>] (xfrm_input+0x4d0/0x1304)
> > > > [   44.662408] [<c0809388>] (xfrm_input) from [<c03a3d88>] (crypto_finalize_request+0x5c/0xc4)
> > > > [   44.670766] [<c03a3d88>] (crypto_finalize_request) from [<c06a0888>] (sun8i_ce_cipher_run+0x34/0x3c)
> > > > [   44.679900] [<c06a0888>] (sun8i_ce_cipher_run) from [<c03a4264>] (crypto_pump_work+0x1a8/0x330)
> > > 
> > > So did sun8i_ce_cipher_run ensure that BH is disabled before
> > > invoking xfrm_input? If not then this explains the dead-lock.
> > 
> > The issue appears to be with crypto_engine.  It needs to ensure
> > that completion functions are called with BH disabled, not IRQ
> > disabled and definitely not BH enabled.
> > 
> 
> Hello
> 
> This minimal patch fix my issue, does it is the rigth way ?
> 
> Thanks for your help
> Regards
> 
> diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c
> index fb07da9920ee..b3844f6d98a3 100644
> --- a/crypto/crypto_engine.c
> +++ b/crypto/crypto_engine.c
> @@ -7,6 +7,7 @@
>   * Author: Baolin Wang <baolin.wang@linaro.org>
>   */
>  
> +#include <linux/bottom_half.h>
>  #include <linux/err.h>
>  #include <linux/delay.h>
>  #include <linux/device.h>
> @@ -53,7 +54,9 @@ static void crypto_finalize_request(struct crypto_engine *engine,
>                                 dev_err(engine->dev, "failed to unprepare request\n");
>                 }
>         }
> +       local_bh_disable();
>         req->complete(req, err);
> +       local_bh_enable();
>  
>         kthread_queue_work(engine->kworker, &engine->pump_requests);
>  }
> 

Hello

With my patch, I got:
[   38.515668] BUG: sleeping function called from invalid context at crypto/skcipher.c:482
[   38.523708] in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 84, name: 1c15000.crypto-
[   38.532176] preempt_count: 200, expected: 0
[   38.536381] CPU: 6 PID: 84 Comm: 1c15000.crypto- Not tainted 5.16.0-next-20220115-00124-g13473e8fac33-dirty #116
[   38.546551] Hardware name: Allwinner A83t board
[   38.551100]  unwind_backtrace from show_stack+0x10/0x14
[   38.556358]  show_stack from dump_stack_lvl+0x40/0x4c
[   38.561428]  dump_stack_lvl from __might_resched+0x118/0x154
[   38.567107]  __might_resched from skcipher_walk_virt+0xe8/0xec
[   38.572955]  skcipher_walk_virt from crypto_cbc_decrypt+0x2c/0x170
[   38.579147]  crypto_cbc_decrypt from crypto_skcipher_decrypt+0x38/0x5c
[   38.585680]  crypto_skcipher_decrypt from authenc_verify_ahash_done+0x18/0x34
[   38.592825]  authenc_verify_ahash_done from crypto_finalize_request+0x6c/0xe4
[   38.599974]  crypto_finalize_request from sun8i_ss_hash_run+0x73c/0xb98
[   38.606602]  sun8i_ss_hash_run from crypto_pump_work+0x1a8/0x330
[   38.612616]  crypto_pump_work from kthread_worker_fn+0xa8/0x1c4
[   38.618550]  kthread_worker_fn from kthread+0xf0/0x110
[   38.623701]  kthread from ret_from_fork+0x14/0x2c
[   38.628414] Exception stack(0xc2247fb0 to 0xc2247ff8)
[   38.633468] 7fa0:                                     00000000 00000000 00000000 00000000
[   38.641640] 7fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[   38.649809] 7fe0:i 00000000 00000000 00000000 00000000 00000013 00000000

This is when testing hmac(sha1) on my crypto driver sun8i-ss and crypto testing authenc(hmac-sha1-sun8i-ss,cbc(aes-generic)).

Do you have any idea to better fix my issue ?

Regards

  reply	other threads:[~2022-01-18  7:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-11  9:47 Corentin Labbe
2022-01-12 12:07 ` Corentin Labbe
2022-01-14  4:14 ` Herbert Xu
2022-01-14  4:23   ` Herbert Xu
2022-01-14  7:12     ` Corentin Labbe
2022-01-18  7:52       ` Corentin Labbe [this message]
2022-01-19  6:58         ` [PATCH] crypto: authenc - Fix sleep in atomic context in decrypt_tail Herbert Xu
2022-01-27 13:34           ` Corentin Labbe

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=YeZx1aVL0HnT9tCB@Red \
    --to=clabbe.montjoie@gmail.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --subject='Re: crypto: BUG: spinlock recursion when doing iperf over ipsec with crypto hardware device' \
    /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

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).