Skip to content

Commit 5ecf8ef

Browse files
Catalin Vasileherbertx
authored andcommitted
crypto: caam - fix sg dump
Ensure scatterlists have a virtual memory mapping before dumping. Signed-off-by: Catalin Vasile <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent ad8529f commit 5ecf8ef

File tree

1 file changed

+61
-18
lines changed

1 file changed

+61
-18
lines changed

drivers/crypto/caam/caamalg.c

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,42 @@
111111
#else
112112
#define debug(format, arg...)
113113
#endif
114+
115+
#ifdef DEBUG
116+
#include <linux/highmem.h>
117+
118+
static 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+
114150
static struct list_head alg_list;
115151

116152
struct caam_alg_entry {
@@ -1982,9 +2018,9 @@ static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
19822018
print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ",
19832019
DUMP_PREFIX_ADDRESS, 16, 4, req->info,
19842020
edesc->src_nents > 1 ? 100 : ivsize, 1);
1985-
print_hex_dump(KERN_ERR, "dst @"__stringify(__LINE__)": ",
1986-
DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src),
1987-
edesc->dst_nents > 1 ? 100 : req->nbytes, 1);
2021+
dbg_dump_sg(KERN_ERR, "dst @"__stringify(__LINE__)": ",
2022+
DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
2023+
edesc->dst_nents > 1 ? 100 : req->nbytes, 1, true);
19882024
#endif
19892025

19902026
ablkcipher_unmap(jrdev, edesc, req);
@@ -2014,9 +2050,9 @@ static void ablkcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
20142050
print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ",
20152051
DUMP_PREFIX_ADDRESS, 16, 4, req->info,
20162052
ivsize, 1);
2017-
print_hex_dump(KERN_ERR, "dst @"__stringify(__LINE__)": ",
2018-
DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src),
2019-
edesc->dst_nents > 1 ? 100 : req->nbytes, 1);
2053+
dbg_dump_sg(KERN_ERR, "dst @"__stringify(__LINE__)": ",
2054+
DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
2055+
edesc->dst_nents > 1 ? 100 : req->nbytes, 1, true);
20202056
#endif
20212057

20222058
ablkcipher_unmap(jrdev, edesc, req);
@@ -2171,12 +2207,15 @@ static void init_ablkcipher_job(u32 *sh_desc, dma_addr_t ptr,
21712207
int len, sec4_sg_index = 0;
21722208

21732209
#ifdef DEBUG
2210+
bool may_sleep = ((req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
2211+
CRYPTO_TFM_REQ_MAY_SLEEP)) != 0);
21742212
print_hex_dump(KERN_ERR, "presciv@"__stringify(__LINE__)": ",
21752213
DUMP_PREFIX_ADDRESS, 16, 4, req->info,
21762214
ivsize, 1);
2177-
print_hex_dump(KERN_ERR, "src @"__stringify(__LINE__)": ",
2178-
DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src),
2179-
edesc->src_nents ? 100 : req->nbytes, 1);
2215+
printk(KERN_ERR "asked=%d, nbytes%d\n", (int)edesc->src_nents ? 100 : req->nbytes, req->nbytes);
2216+
dbg_dump_sg(KERN_ERR, "src @"__stringify(__LINE__)": ",
2217+
DUMP_PREFIX_ADDRESS, 16, 4, req->src,
2218+
edesc->src_nents ? 100 : req->nbytes, 1, may_sleep);
21802219
#endif
21812220

21822221
len = desc_len(sh_desc);
@@ -2228,12 +2267,14 @@ static void init_ablkcipher_giv_job(u32 *sh_desc, dma_addr_t ptr,
22282267
int len, sec4_sg_index = 0;
22292268

22302269
#ifdef DEBUG
2270+
bool may_sleep = ((req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
2271+
CRYPTO_TFM_REQ_MAY_SLEEP)) != 0);
22312272
print_hex_dump(KERN_ERR, "presciv@" __stringify(__LINE__) ": ",
22322273
DUMP_PREFIX_ADDRESS, 16, 4, req->info,
22332274
ivsize, 1);
2234-
print_hex_dump(KERN_ERR, "src @" __stringify(__LINE__) ": ",
2235-
DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src),
2236-
edesc->src_nents ? 100 : req->nbytes, 1);
2275+
dbg_dump_sg(KERN_ERR, "src @" __stringify(__LINE__) ": ",
2276+
DUMP_PREFIX_ADDRESS, 16, 4, req->src,
2277+
edesc->src_nents ? 100 : req->nbytes, 1, may_sleep);
22372278
#endif
22382279

22392280
len = desc_len(sh_desc);
@@ -2503,18 +2544,20 @@ static int aead_decrypt(struct aead_request *req)
25032544
u32 *desc;
25042545
int ret = 0;
25052546

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+
25062555
/* allocate extended descriptor */
25072556
edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN,
25082557
&all_contig, false);
25092558
if (IS_ERR(edesc))
25102559
return PTR_ERR(edesc);
25112560

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-
25182561
/* Create and submit job descriptor*/
25192562
init_authenc_job(req, edesc, all_contig, false);
25202563
#ifdef DEBUG

0 commit comments

Comments
 (0)