From: Christian Hohnstaedt Subject: Re: [PATCH] ixp4xx_crypto: fix possible sleep while atomic Date: Tue, 12 Jan 2010 16:52:50 +0100 Message-ID: <20100112155250.GH3056@elara.bln.innominate.local> References: <1263308765-17427-1-git-send-email-karl@hiramoto.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: chohnstaedt@innominate.com, linux-crypto@vger.kernel.org To: Karl Hiramoto Return-path: Received: from host2.bln.innominate.com ([77.245.32.75]:50665 "EHLO home.innominate.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751445Ab0ALPww (ORCPT ); Tue, 12 Jan 2010 10:52:52 -0500 Content-Disposition: inline In-Reply-To: <1263308765-17427-1-git-send-email-karl@hiramoto.org> Sender: linux-crypto-owner@vger.kernel.org List-ID: Hi Karl, initially I designed the driver to use as less memory as possible if it is only loaded but not used. Since during module load some testciphers are run with the driver, this approach became senseless. I would rather move the call to setup_crypt_desc() into the module-load function for 2 reasons: 1) keep GFP_KERNEL 2) remove some "if (!crypt_virt)" on the fast-path I will create a patch and sync it with the patches from Krzysztof Halasa. Christian On Tue, Jan 12, 2010 at 04:06:05PM +0100, Karl Hiramoto wrote: > use GFP_ATOMIC to allocate crypt_virt > > BUG: sleeping function called from invalid context at mm/page_alloc.c:1470 > in_atomic(): 0, irqs_disabled(): 128, pid: 1376, name: cryptomgr_test > 1 lock held by cryptomgr_test/1376: > #0: (&desc_lock){....}, at: [] get_crypt_desc+0x14/0xe8 [ixp4xx_crypto] > [] (dump_stack+0x0/0x14) from [] (__might_sleep+0xcc/0xe8) > [] (__might_sleep+0x0/0xe8) from [] (__alloc_pages_internal+0xa4/0x430) > r4:000000d0 > [] (__alloc_pages_internal+0x0/0x430) from [] (__dma_alloc+0x180/0x3e8) > [] (__dma_alloc+0x0/0x3e8) from [] (dma_alloc_coherent+0x58/0x64) > [] (dma_alloc_coherent+0x0/0x64) from [] (get_crypt_desc+0x3c/0xe8 [ixp4xx_crypto]) > r7:c3bc3ce8 r6:c3bc3cc0 r5:20000013 r4:bf14a81c > [] (get_crypt_desc+0x0/0xe8 [ixp4xx_crypto]) from [] (ablk_perform+0x68/0x248 [ixp4xx_crypto]) > r7:c3bc3ce8 r6:c3bc3cc0 r5:c2cefc2c r4:00000000 > [] (ablk_perform+0x0/0x248 [ixp4xx_crypto]) from [] (ablk_encrypt+0x14/0x18 [ixp4xx_crypto]) > [] (ablk_encrypt+0x0/0x18 [ixp4xx_crypto]) from [] (test_skcipher+0x1bc/0x668) > [] (test_skcipher+0x0/0x668) from [] (alg_test_skcipher+0x60/0xa0) > [] (alg_test_skcipher+0x0/0xa0) from [] (alg_test+0x128/0x160) > r7:00000000 r6:00000286 r5:c39ddd80 r4:c39dddc0 > [] (alg_test+0x0/0x160) from [] (cryptomgr_test+0x38/0x58) > [] (cryptomgr_test+0x0/0x58) from [] (kthread+0x58/0x90) > r4:c2e38000 > [] (kthread+0x0/0x90) from [] (do_exit+0x0/0x6d0) > r6:00000000 r5:00000000 r4:00000000 > > Note this is somewhat hard to reproduce, but can be reproduced under memory pressure when you first initialize ixp4xx_crypto. > > Signed-off-by: Karl Hiramoto > --- > drivers/crypto/ixp4xx_crypto.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c > index 6c6656d..564d68f 100644 > --- a/drivers/crypto/ixp4xx_crypto.c > +++ b/drivers/crypto/ixp4xx_crypto.c > @@ -246,7 +246,7 @@ static int setup_crypt_desc(void) > BUILD_BUG_ON(sizeof(struct crypt_ctl) != 64); > crypt_virt = dma_alloc_coherent(dev, > NPE_QLEN * sizeof(struct crypt_ctl), > - &crypt_phys, GFP_KERNEL); > + &crypt_phys, GFP_ATOMIC); > if (!crypt_virt) > return -ENOMEM; > memset(crypt_virt, 0, NPE_QLEN * sizeof(struct crypt_ctl)); > -- > 1.6.4.4 > Christian Hohnstaedt -- Christian Hohnstaedt / Project Manager Hardware and Manufacturing Innominate Security Technologies AG / protecting industrial networks tel: +49.30.921028.208 / fax: +49.30.921028.020 Rudower Chaussee 13, D-12489 Berlin / http://www.innominate.com Register Court: AG Charlottenburg, HR B 81603 Management Board: Dirk Seewald Chairman of the Supervisory Board: Volker Bibelhausen