Re: [PATCH] kbuild: move .SECONDARY special target to Kbuild.include

2018-12-07 Thread Masahiro Yamada
On Sat, Dec 1, 2018 at 9:29 AM Masahiro Yamada
 wrote:
>
> In commit 54a702f70589 ("kbuild: mark $(targets) as .SECONDARY and
> remove .PRECIOUS markers"), I missed one important feature of the
> .SECONDARY target:
>
>   .SECONDARY with no prerequisites causes all targets to be treated
>as secondary.
>
> Kbuild's policy is, "Do not delete any intermediate files."
> So, just move it to scripts/Kbuild.include, with no prerequisites.
>
> Note:
> If an intermediate file is generated by $(call if_changed,...), you
> still need to add it to "targets" so its .*.cmd file is included.
>
> The arm/arm64 crypto files are generated by $(call cmd,shipped),
> so they do not need to be added to "targets", but need to be added
> to "clean-files" so "make clean" can properly clean them away.
>
> Signed-off-by: Masahiro Yamada 
> ---


Applied to linux-kbuild.



>  arch/arm/crypto/Makefile   | 2 +-
>  arch/arm64/crypto/Makefile | 2 +-
>  scripts/Kbuild.include | 3 +++
>  scripts/Makefile.build | 4 
>  4 files changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/arch/arm/crypto/Makefile b/arch/arm/crypto/Makefile
> index bd5bcee..89f88ab 100644
> --- a/arch/arm/crypto/Makefile
> +++ b/arch/arm/crypto/Makefile
> @@ -65,4 +65,4 @@ $(src)/sha512-core.S_shipped: $(src)/sha512-armv4.pl
> $(call cmd,perl)
>  endif
>
> -targets += sha256-core.S sha512-core.S
> +clean-files += sha256-core.S sha512-core.S
> diff --git a/arch/arm64/crypto/Makefile b/arch/arm64/crypto/Makefile
> index f476fed..860d931 100644
> --- a/arch/arm64/crypto/Makefile
> +++ b/arch/arm64/crypto/Makefile
> @@ -75,4 +75,4 @@ $(src)/sha512-core.S_shipped: $(src)/sha512-armv8.pl
> $(call cmd,perlasm)
>  endif
>
> -targets += sha256-core.S sha512-core.S
> +clean-files += sha256-core.S sha512-core.S
> diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
> index bb01555..0454916 100644
> --- a/scripts/Kbuild.include
> +++ b/scripts/Kbuild.include
> @@ -393,3 +393,6 @@ endef
>
>  # delete partially updated (i.e. corrupted) files on error
>  .DELETE_ON_ERROR:
> +
> +# do not delete intermediate files automatically
> +.SECONDARY:
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index a8e7ba9..604096a 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -546,8 +546,4 @@ $(shell mkdir -p $(obj-dirs))
>  endif
>  endif
>
> -# Some files contained in $(targets) are intermediate artifacts.
> -# We never want them to be removed automatically.
> -.SECONDARY: $(targets)
> -
>  .PHONY: $(PHONY)
> --
> 2.7.4
>


-- 
Best Regards
Masahiro Yamada


Re: [PATCH] crypto/testmgr: fix skcipher test with CONFIG_VMAP_STACK

2018-12-07 Thread Ard Biesheuvel
On Fri, 7 Dec 2018 at 18:33, Christophe Leroy  wrote:
>
> [2.364486] WARNING: CPU: 0 PID: 60 at ./arch/powerpc/include/asm/io.h:837 
> dma_nommu_map_page+0x44/0xd4
> [2.373579] CPU: 0 PID: 60 Comm: cryptomgr_test Tainted: GW
>  4.20.0-rc5-00560-g6bfb52e23a00-dirty #531
> [2.384740] NIP:  c000c540 LR: c000c584 CTR: 
> [2.389743] REGS: c95abab0 TRAP: 0700   Tainted: GW  
> (4.20.0-rc5-00560-g6bfb52e23a00-dirty)
> [2.400042] MSR:  00029032   CR: 24042204  XER: 
> [2.406669]
> [2.406669] GPR00: c02f2244 c95abb60 c6262990 c95abd80 256a 0001 
> 0001 0001
> [2.406669] GPR08:  2000 0010 0010 24042202  
> 0100 c95abd88
> [2.406669] GPR16:  c05569d4 0001 0010 c95abc88 c0615664 
> 0004 
> [2.406669] GPR24: 0010 c95abc88 c95abc88  c61ae210 c7ff6d40 
> c61ae210 3d68
> [2.441559] NIP [c000c540] dma_nommu_map_page+0x44/0xd4
> [2.446720] LR [c000c584] dma_nommu_map_page+0x88/0xd4
> [2.451762] Call Trace:
> [2.454195] [c95abb60] [82000808] 0x82000808 (unreliable)
> [2.459572] [c95abb80] [c02f2244] talitos_edesc_alloc+0xbc/0x3c8
> [2.465493] [c95abbb0] [c02f2600] ablkcipher_edesc_alloc+0x4c/0x5c
> [2.471606] [c95abbd0] [c02f4ed0] ablkcipher_encrypt+0x20/0x64
> [2.477389] [c95abbe0] [c02023b0] __test_skcipher+0x4bc/0xa08
> [2.483049] [c95abe00] [c0204b60] test_skcipher+0x2c/0xcc
> [2.488385] [c95abe20] [c0204c48] alg_test_skcipher+0x48/0xbc
> [2.494064] [c95abe40] [c0205cec] alg_test+0x164/0x2e8
> [2.499142] [c95abf00] [c0200dec] cryptomgr_test+0x48/0x50
> [2.504558] [c95abf10] [c0039ff4] kthread+0xe4/0x110
> [2.509471] [c95abf40] [c000e1d0] ret_from_kernel_thread+0x14/0x1c
> [2.515532] Instruction dump:
> [2.518468] 7c7e1b78 7c9d2378 7cbf2b78 41820054 3d20c076 8089c200 3d20c076 
> 7c84e850
> [2.526127] 8129c204 7c842e70 7f844840 419c0008 <0fe0> 2f9e 
> 54847022 7c84fa14
> [2.533960] ---[ end trace bf78d94af73fe3b8 ]---
> [2.539123] talitos ff02.crypto: master data transfer error
> [2.544775] talitos ff02.crypto: TEA error: ISR 0x2000_0040
> [2.551625] alg: skcipher: encryption failed on test 1 for 
> ecb-aes-talitos: ret=22
>
> IV cannot be on stack when CONFIG_VMAP_STACK is selected because the stack
> cannot be DMA mapped anymore.
>
> This patch allocates it with kmalloc()
>

This looks like a driver bug to me. Other accelerators in
drivers/crypto all take a copy of the IV before mapping it for DMA, so
it would be better if talitos did the same.

> Fixes: da7f033ddc9f ("crypto: cryptomgr - Add test infrastructure")
> Signed-off-by: Christophe Leroy 
> ---
>  crypto/testmgr.c | 8 +++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/crypto/testmgr.c b/crypto/testmgr.c
> index b1f79c6bf409..eea498f9030d 100644
> --- a/crypto/testmgr.c
> +++ b/crypto/testmgr.c
> @@ -1112,12 +1112,16 @@ static int __test_skcipher(struct crypto_skcipher 
> *tfm, int enc,
> struct crypto_wait wait;
> const char *input, *result;
> void *data;
> -   char iv[MAX_IVLEN];
> +   char *iv;
> char *xbuf[XBUFSIZE];
> char *xoutbuf[XBUFSIZE];
> int ret = -ENOMEM;
> unsigned int ivsize = crypto_skcipher_ivsize(tfm);
>
> +   iv = kmalloc(MAX_IVLEN, GFP_KERNEL | GFP_DMA);
> +   if (!iv)
> +   goto out_noiv;
> +
> if (testmgr_alloc_buf(xbuf))
> goto out_nobuf;
>
> @@ -1339,6 +1343,8 @@ static int __test_skcipher(struct crypto_skcipher *tfm, 
> int enc,
>  out_nooutbuf:
> testmgr_free_buf(xbuf);
>  out_nobuf:
> +   kfree(iv);
> +out_noiv:
> return ret;
>  }
>
> --
> 2.13.3
>


[PATCH] crypto/testmgr: fix skcipher test with CONFIG_VMAP_STACK

2018-12-07 Thread Christophe Leroy
[2.364486] WARNING: CPU: 0 PID: 60 at ./arch/powerpc/include/asm/io.h:837 
dma_nommu_map_page+0x44/0xd4
[2.373579] CPU: 0 PID: 60 Comm: cryptomgr_test Tainted: GW 
4.20.0-rc5-00560-g6bfb52e23a00-dirty #531
[2.384740] NIP:  c000c540 LR: c000c584 CTR: 
[2.389743] REGS: c95abab0 TRAP: 0700   Tainted: GW  
(4.20.0-rc5-00560-g6bfb52e23a00-dirty)
[2.400042] MSR:  00029032   CR: 24042204  XER: 
[2.406669]
[2.406669] GPR00: c02f2244 c95abb60 c6262990 c95abd80 256a 0001 
0001 0001
[2.406669] GPR08:  2000 0010 0010 24042202  
0100 c95abd88
[2.406669] GPR16:  c05569d4 0001 0010 c95abc88 c0615664 
0004 
[2.406669] GPR24: 0010 c95abc88 c95abc88  c61ae210 c7ff6d40 
c61ae210 3d68
[2.441559] NIP [c000c540] dma_nommu_map_page+0x44/0xd4
[2.446720] LR [c000c584] dma_nommu_map_page+0x88/0xd4
[2.451762] Call Trace:
[2.454195] [c95abb60] [82000808] 0x82000808 (unreliable)
[2.459572] [c95abb80] [c02f2244] talitos_edesc_alloc+0xbc/0x3c8
[2.465493] [c95abbb0] [c02f2600] ablkcipher_edesc_alloc+0x4c/0x5c
[2.471606] [c95abbd0] [c02f4ed0] ablkcipher_encrypt+0x20/0x64
[2.477389] [c95abbe0] [c02023b0] __test_skcipher+0x4bc/0xa08
[2.483049] [c95abe00] [c0204b60] test_skcipher+0x2c/0xcc
[2.488385] [c95abe20] [c0204c48] alg_test_skcipher+0x48/0xbc
[2.494064] [c95abe40] [c0205cec] alg_test+0x164/0x2e8
[2.499142] [c95abf00] [c0200dec] cryptomgr_test+0x48/0x50
[2.504558] [c95abf10] [c0039ff4] kthread+0xe4/0x110
[2.509471] [c95abf40] [c000e1d0] ret_from_kernel_thread+0x14/0x1c
[2.515532] Instruction dump:
[2.518468] 7c7e1b78 7c9d2378 7cbf2b78 41820054 3d20c076 8089c200 3d20c076 
7c84e850
[2.526127] 8129c204 7c842e70 7f844840 419c0008 <0fe0> 2f9e 54847022 
7c84fa14
[2.533960] ---[ end trace bf78d94af73fe3b8 ]---
[2.539123] talitos ff02.crypto: master data transfer error
[2.544775] talitos ff02.crypto: TEA error: ISR 0x2000_0040
[2.551625] alg: skcipher: encryption failed on test 1 for ecb-aes-talitos: 
ret=22

IV cannot be on stack when CONFIG_VMAP_STACK is selected because the stack
cannot be DMA mapped anymore.

This patch allocates it with kmalloc()

Fixes: da7f033ddc9f ("crypto: cryptomgr - Add test infrastructure")
Signed-off-by: Christophe Leroy 
---
 crypto/testmgr.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index b1f79c6bf409..eea498f9030d 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -1112,12 +1112,16 @@ static int __test_skcipher(struct crypto_skcipher *tfm, 
int enc,
struct crypto_wait wait;
const char *input, *result;
void *data;
-   char iv[MAX_IVLEN];
+   char *iv;
char *xbuf[XBUFSIZE];
char *xoutbuf[XBUFSIZE];
int ret = -ENOMEM;
unsigned int ivsize = crypto_skcipher_ivsize(tfm);
 
+   iv = kmalloc(MAX_IVLEN, GFP_KERNEL | GFP_DMA);
+   if (!iv)
+   goto out_noiv;
+
if (testmgr_alloc_buf(xbuf))
goto out_nobuf;
 
@@ -1339,6 +1343,8 @@ static int __test_skcipher(struct crypto_skcipher *tfm, 
int enc,
 out_nooutbuf:
testmgr_free_buf(xbuf);
 out_nobuf:
+   kfree(iv);
+out_noiv:
return ret;
 }
 
-- 
2.13.3



[cryptodev:master 81/86] htmldocs: include/linux/crypto.h:614: warning: Function parameter or member 'stats.aead' not described in 'crypto_alg'

2018-12-07 Thread kbuild test robot
tree:   
https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master
head:   88d905e20b11f7ad841e3afddaf1d59b6693c4a1
commit: 17c18f9e33282a170458cb5ea20759bfcb0da7d8 [81/86] crypto: user - Split 
stats in multiple structures
reproduce: make htmldocs

All warnings (new ones prefixed by >>):

   WARNING: convert(1) not found, for SVG to PDF conversion install ImageMagick 
(https://www.imagemagick.org)
   kernel/resource.c:337: warning: Function parameter or member 'start' not 
described in 'find_next_iomem_res'
   kernel/resource.c:337: warning: Function parameter or member 'end' not 
described in 'find_next_iomem_res'
   kernel/resource.c:337: warning: Function parameter or member 'flags' not 
described in 'find_next_iomem_res'
   kernel/resource.c:337: warning: Function parameter or member 'desc' not 
described in 'find_next_iomem_res'
   kernel/resource.c:337: warning: Function parameter or member 'first_lvl' not 
described in 'find_next_iomem_res'
   kernel/resource.c:337: warning: Function parameter or member 'res' not 
described in 'find_next_iomem_res'
   kernel/resource.c:409: warning: Function parameter or member 'arg' not 
described in 'walk_iomem_res_desc'
   kernel/resource.c:409: warning: Function parameter or member 'func' not 
described in 'walk_iomem_res_desc'
   kernel/resource.c:409: warning: Function parameter or member 'arg' not 
described in 'walk_iomem_res_desc'
   kernel/resource.c:409: warning: Function parameter or member 'func' not 
described in 'walk_iomem_res_desc'
   include/linux/rcutree.h:1: warning: no structured comments found
   kernel/rcu/tree.c:684: warning: Excess function parameter 'irq' description 
in 'rcu_nmi_exit'
   include/linux/srcu.h:175: warning: Function parameter or member 'p' not 
described in 'srcu_dereference_notrace'
   include/linux/srcu.h:175: warning: Function parameter or member 'sp' not 
described in 'srcu_dereference_notrace'
   include/linux/gfp.h:1: warning: no structured comments found
>> include/linux/crypto.h:614: warning: Function parameter or member 
>> 'stats.aead' not described in 'crypto_alg'
>> include/linux/crypto.h:614: warning: Function parameter or member 
>> 'stats.akcipher' not described in 'crypto_alg'
>> include/linux/crypto.h:614: warning: Function parameter or member 
>> 'stats.cipher' not described in 'crypto_alg'
>> include/linux/crypto.h:614: warning: Function parameter or member 
>> 'stats.compress' not described in 'crypto_alg'
>> include/linux/crypto.h:614: warning: Function parameter or member 
>> 'stats.hash' not described in 'crypto_alg'
>> include/linux/crypto.h:614: warning: Function parameter or member 
>> 'stats.rng' not described in 'crypto_alg'
>> include/linux/crypto.h:614: warning: Function parameter or member 
>> 'stats.kpp' not described in 'crypto_alg'
   include/net/cfg80211.h:2838: warning: cannot understand function prototype: 
'struct cfg80211_ftm_responder_stats '
   include/net/cfg80211.h:2838: warning: cannot understand function prototype: 
'struct cfg80211_ftm_responder_stats '
   include/net/cfg80211.h:2838: warning: cannot understand function prototype: 
'struct cfg80211_ftm_responder_stats '
   include/net/cfg80211.h:2838: warning: cannot understand function prototype: 
'struct cfg80211_ftm_responder_stats '
   include/net/cfg80211.h:2838: warning: cannot understand function prototype: 
'struct cfg80211_ftm_responder_stats '
   include/net/cfg80211.h:2838: warning: cannot understand function prototype: 
'struct cfg80211_ftm_responder_stats '
   include/net/cfg80211.h:2838: warning: cannot understand function prototype: 
'struct cfg80211_ftm_responder_stats '
   include/net/cfg80211.h:2838: warning: cannot understand function prototype: 
'struct cfg80211_ftm_responder_stats '
   include/net/cfg80211.h:2838: warning: cannot understand function prototype: 
'struct cfg80211_ftm_responder_stats '
   include/net/cfg80211.h:2838: warning: cannot understand function prototype: 
'struct cfg80211_ftm_responder_stats '
   include/net/cfg80211.h:2838: warning: cannot understand function prototype: 
'struct cfg80211_ftm_responder_stats '
   include/net/cfg80211.h:2838: warning: cannot understand function prototype: 
'struct cfg80211_ftm_responder_stats '
   include/net/cfg80211.h:2838: warning: cannot understand function prototype: 
'struct cfg80211_ftm_responder_stats '
   include/net/cfg80211.h:4439: warning: Function parameter or member 
'wext.ibss' not described in 'wireless_dev'
   include/net/cfg80211.h:4439: warning: Function parameter or member 
'wext.connect' not described in 'wireless_dev'
   include/net/cfg80211.h:4439: warning: Function parameter or member 
'wext.keys' not described in 'wireless_dev'
   include/net/cfg80211.h:4439: warning: Function parameter or member 'wext.ie' 
not described in 'wireless_dev'
   include/net/cfg80211.h:4439: warning: Function parameter or member 
'wext.ie_len' not described in 'wireless_dev'
   include/net/cfg80211.h:4439: warning: Function par

[PATCH] crypto: caam - fix setting IV after decrypt

2018-12-07 Thread Sascha Hauer
The crypto API wants the updated IV in req->info after decryption. The
updated IV used to be copied correctly to req->info after running the
decryption job. Since 115957bb3e59 this is done before running the job
so instead of the updated IV only the unmodified input IV is given back
to the crypto API.

This was observed running the gcm(aes) selftest which internally uses
ctr(aes) implemented by the CAAM engine.

Fixes: 115957bb3e59 ("crypto: caam - fix IV DMA mapping and updating")

Signed-off-by: Sascha Hauer 
Cc: sta...@vger.kernel.org
---
 drivers/crypto/caam/caamalg.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index 869f092432de..c05c7938439c 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -917,10 +917,10 @@ static void skcipher_decrypt_done(struct device *jrdev, 
u32 *desc, u32 err,
 {
struct skcipher_request *req = context;
struct skcipher_edesc *edesc;
-#ifdef DEBUG
struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
int ivsize = crypto_skcipher_ivsize(skcipher);
 
+#ifdef DEBUG
dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
 #endif
 
@@ -937,6 +937,14 @@ static void skcipher_decrypt_done(struct device *jrdev, 
u32 *desc, u32 err,
 edesc->dst_nents > 1 ? 100 : req->cryptlen, 1);
 
skcipher_unmap(jrdev, edesc, req);
+
+   /*
+* The crypto API expects us to set the IV (req->iv) to the last
+* ciphertext block.
+*/
+   scatterwalk_map_and_copy(req->iv, req->src, req->cryptlen - ivsize,
+ivsize, 0);
+
kfree(edesc);
 
skcipher_request_complete(req, err);
@@ -1588,13 +1596,6 @@ static int skcipher_decrypt(struct skcipher_request *req)
if (IS_ERR(edesc))
return PTR_ERR(edesc);
 
-   /*
-* The crypto API expects us to set the IV (req->iv) to the last
-* ciphertext block.
-*/
-   scatterwalk_map_and_copy(req->iv, req->src, req->cryptlen - ivsize,
-ivsize, 0);
-
/* Create and submit job descriptor*/
init_skcipher_job(req, edesc, false);
desc = edesc->hw_desc;
-- 
2.19.1