aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto
diff options
context:
space:
mode:
authorCatalin Vasile <cata.vasile@nxp.com>2016-09-22 04:57:58 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2016-09-22 06:32:54 -0400
commit5ecf8ef9103cb018cbd82b6eace529ff4c5b5c66 (patch)
treee40cf1b4a15ba9bc16def74b571752ebe71e608f /drivers/crypto
parentad8529fde9e3601180a839867a8ab041109aebb5 (diff)
crypto: caam - fix sg dump
Ensure scatterlists have a virtual memory mapping before dumping. Signed-off-by: Catalin Vasile <cata.vasile@nxp.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto')
-rw-r--r--drivers/crypto/caam/caamalg.c79
1 files changed, 61 insertions, 18 deletions
diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index f1116e7f7cd5..eb97562414d2 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -111,6 +111,42 @@
111#else 111#else
112#define debug(format, arg...) 112#define debug(format, arg...)
113#endif 113#endif
114
115#ifdef DEBUG
116#include <linux/highmem.h>
117
118static void dbg_dump_sg(const char *level, const char *prefix_str,
119 int prefix_type, int rowsize, int groupsize,
120 struct scatterlist *sg, size_t tlen, bool ascii,
121 bool may_sleep)
122{
123 struct scatterlist *it;
124 void *it_page;
125 size_t len;
126 void *buf;
127
128 for (it = sg; it != NULL && tlen > 0 ; it = sg_next(sg)) {
129 /*
130 * make sure the scatterlist's page
131 * has a valid virtual memory mapping
132 */
133 it_page = kmap_atomic(sg_page(it));
134 if (unlikely(!it_page)) {
135 printk(KERN_ERR "dbg_dump_sg: kmap failed\n");
136 return;
137 }
138
139 buf = it_page + it->offset;
140 len = min(tlen, it->length);
141 print_hex_dump(level, prefix_str, prefix_type, rowsize,
142 groupsize, buf, len, ascii);
143 tlen -= len;
144
145 kunmap_atomic(it_page);
146 }
147}
148#endif
149
114static struct list_head alg_list; 150static struct list_head alg_list;
115 151
116struct caam_alg_entry { 152struct caam_alg_entry {
@@ -1982,9 +2018,9 @@ static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
1982 print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ", 2018 print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ",
1983 DUMP_PREFIX_ADDRESS, 16, 4, req->info, 2019 DUMP_PREFIX_ADDRESS, 16, 4, req->info,
1984 edesc->src_nents > 1 ? 100 : ivsize, 1); 2020 edesc->src_nents > 1 ? 100 : ivsize, 1);
1985 print_hex_dump(KERN_ERR, "dst @"__stringify(__LINE__)": ", 2021 dbg_dump_sg(KERN_ERR, "dst @"__stringify(__LINE__)": ",
1986 DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src), 2022 DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
1987 edesc->dst_nents > 1 ? 100 : req->nbytes, 1); 2023 edesc->dst_nents > 1 ? 100 : req->nbytes, 1, true);
1988#endif 2024#endif
1989 2025
1990 ablkcipher_unmap(jrdev, edesc, req); 2026 ablkcipher_unmap(jrdev, edesc, req);
@@ -2014,9 +2050,9 @@ static void ablkcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
2014 print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ", 2050 print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ",
2015 DUMP_PREFIX_ADDRESS, 16, 4, req->info, 2051 DUMP_PREFIX_ADDRESS, 16, 4, req->info,
2016 ivsize, 1); 2052 ivsize, 1);
2017 print_hex_dump(KERN_ERR, "dst @"__stringify(__LINE__)": ", 2053 dbg_dump_sg(KERN_ERR, "dst @"__stringify(__LINE__)": ",
2018 DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src), 2054 DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
2019 edesc->dst_nents > 1 ? 100 : req->nbytes, 1); 2055 edesc->dst_nents > 1 ? 100 : req->nbytes, 1, true);
2020#endif 2056#endif
2021 2057
2022 ablkcipher_unmap(jrdev, edesc, req); 2058 ablkcipher_unmap(jrdev, edesc, req);
@@ -2171,12 +2207,15 @@ static void init_ablkcipher_job(u32 *sh_desc, dma_addr_t ptr,
2171 int len, sec4_sg_index = 0; 2207 int len, sec4_sg_index = 0;
2172 2208
2173#ifdef DEBUG 2209#ifdef DEBUG
2210 bool may_sleep = ((req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
2211 CRYPTO_TFM_REQ_MAY_SLEEP)) != 0);
2174 print_hex_dump(KERN_ERR, "presciv@"__stringify(__LINE__)": ", 2212 print_hex_dump(KERN_ERR, "presciv@"__stringify(__LINE__)": ",
2175 DUMP_PREFIX_ADDRESS, 16, 4, req->info, 2213 DUMP_PREFIX_ADDRESS, 16, 4, req->info,
2176 ivsize, 1); 2214 ivsize, 1);
2177 print_hex_dump(KERN_ERR, "src @"__stringify(__LINE__)": ", 2215 printk(KERN_ERR "asked=%d, nbytes%d\n", (int)edesc->src_nents ? 100 : req->nbytes, req->nbytes);
2178 DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src), 2216 dbg_dump_sg(KERN_ERR, "src @"__stringify(__LINE__)": ",
2179 edesc->src_nents ? 100 : req->nbytes, 1); 2217 DUMP_PREFIX_ADDRESS, 16, 4, req->src,
2218 edesc->src_nents ? 100 : req->nbytes, 1, may_sleep);
2180#endif 2219#endif
2181 2220
2182 len = desc_len(sh_desc); 2221 len = desc_len(sh_desc);
@@ -2228,12 +2267,14 @@ static void init_ablkcipher_giv_job(u32 *sh_desc, dma_addr_t ptr,
2228 int len, sec4_sg_index = 0; 2267 int len, sec4_sg_index = 0;
2229 2268
2230#ifdef DEBUG 2269#ifdef DEBUG
2270 bool may_sleep = ((req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
2271 CRYPTO_TFM_REQ_MAY_SLEEP)) != 0);
2231 print_hex_dump(KERN_ERR, "presciv@" __stringify(__LINE__) ": ", 2272 print_hex_dump(KERN_ERR, "presciv@" __stringify(__LINE__) ": ",
2232 DUMP_PREFIX_ADDRESS, 16, 4, req->info, 2273 DUMP_PREFIX_ADDRESS, 16, 4, req->info,
2233 ivsize, 1); 2274 ivsize, 1);
2234 print_hex_dump(KERN_ERR, "src @" __stringify(__LINE__) ": ", 2275 dbg_dump_sg(KERN_ERR, "src @" __stringify(__LINE__) ": ",
2235 DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src), 2276 DUMP_PREFIX_ADDRESS, 16, 4, req->src,
2236 edesc->src_nents ? 100 : req->nbytes, 1); 2277 edesc->src_nents ? 100 : req->nbytes, 1, may_sleep);
2237#endif 2278#endif
2238 2279
2239 len = desc_len(sh_desc); 2280 len = desc_len(sh_desc);
@@ -2503,18 +2544,20 @@ static int aead_decrypt(struct aead_request *req)
2503 u32 *desc; 2544 u32 *desc;
2504 int ret = 0; 2545 int ret = 0;
2505 2546
2547#ifdef DEBUG
2548 bool may_sleep = ((req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
2549 CRYPTO_TFM_REQ_MAY_SLEEP)) != 0);
2550 dbg_dump_sg(KERN_ERR, "dec src@"__stringify(__LINE__)": ",
2551 DUMP_PREFIX_ADDRESS, 16, 4, req->src,
2552 req->assoclen + req->cryptlen, 1, may_sleep);
2553#endif
2554
2506 /* allocate extended descriptor */ 2555 /* allocate extended descriptor */
2507 edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN, 2556 edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN,
2508 &all_contig, false); 2557 &all_contig, false);
2509 if (IS_ERR(edesc)) 2558 if (IS_ERR(edesc))
2510 return PTR_ERR(edesc); 2559 return PTR_ERR(edesc);
2511 2560
2512#ifdef DEBUG
2513 print_hex_dump(KERN_ERR, "dec src@"__stringify(__LINE__)": ",
2514 DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src),
2515 req->assoclen + req->cryptlen, 1);
2516#endif
2517
2518 /* Create and submit job descriptor*/ 2561 /* Create and submit job descriptor*/
2519 init_authenc_job(req, edesc, all_contig, false); 2562 init_authenc_job(req, edesc, all_contig, false);
2520#ifdef DEBUG 2563#ifdef DEBUG