Commit eadec301 authored by James Morris's avatar James Morris

[CRYPTO]: Bug fixes and cleanups.

- try_inc_mod_count() already does what crypto_alg_get() was trying to do.
(feedback from Andrew Morton).
- Moved the BUG_ON() in crypto_unregister_alg() further up, no need to
bother iterating over the list.
- Always use kmap_atomic (feedback from Andrew Morton).  Implemented two
atomic kmaps, KM_USER for user context and KM_SOFTIRQ for softirq
context.
- Fixup KM_CRYPTO_ placement so Dave does not go crazy.
parent 6c1e4919
......@@ -27,10 +27,7 @@ static struct rw_semaphore crypto_alg_sem;
static inline int crypto_alg_get(struct crypto_alg *alg)
{
if (alg->cra_module)
return try_inc_mod_count(alg->cra_module);
else
return 1;
}
static inline void crypto_alg_put(struct crypto_alg *alg)
......@@ -170,11 +167,11 @@ int crypto_unregister_alg(struct crypto_alg *alg)
int ret = -ENOENT;
struct list_head *p;
down_write(&crypto_alg_sem);
BUG_ON(!alg->cra_module);
down_write(&crypto_alg_sem);
list_for_each(p, &crypto_alg_list) {
if (alg == (struct crypto_alg *)p) {
BUG_ON(!alg->cra_module);
list_del(p);
ret = 0;
goto out;
......
......@@ -76,7 +76,7 @@ static int copy_chunks(struct crypto_tfm *tfm, u8 *buf,
else
memcpy(p, &buf[copied], clen);
crypto_kunmap(tfm, sg[i].page, p);
crypto_kunmap(tfm, p);
*last = aligned ? 0 : clen;
copied += clen;
}
......@@ -130,7 +130,7 @@ static int crypt(struct crypto_tfm *tfm, struct scatterlist *sg,
while (len) {
if (len < bsize) {
crypto_kunmap(tfm, sg[i].page, p);
crypto_kunmap(tfm, p);
n = gather_chunks(tfm, tmp, sg, i, len, &coff);
prfn(tfm, tmp, crfn, enc);
scatter_chunks(tfm, tmp, sg, i, len, &coff);
......@@ -138,7 +138,7 @@ static int crypt(struct crypto_tfm *tfm, struct scatterlist *sg,
goto unmapped;
} else {
prfn(tfm, p, crfn, enc);
crypto_kunmap(tfm, sg[i].page, p);
crypto_kunmap(tfm, p);
crypto_yield(tfm);
/* remap and point to recalculated offset */
......@@ -153,7 +153,7 @@ static int crypt(struct crypto_tfm *tfm, struct scatterlist *sg,
coff = 0;
}
}
crypto_kunmap(tfm, sg[i].page, p);
crypto_kunmap(tfm, p);
unmapped:
i += n;
......
......@@ -33,7 +33,7 @@ static void update(struct crypto_tfm *tfm, struct scatterlist *sg, size_t nsg)
char *p = crypto_kmap(tfm, sg[i].page) + sg[i].offset;
tfm->__crt_alg->cra_digest.dia_update(tfm->crt_ctx,
p, sg[i].length);
crypto_kunmap(tfm, sg[i].page, p);
crypto_kunmap(tfm, p);
crypto_yield(tfm);
}
return;
......@@ -56,7 +56,7 @@ static void digest(struct crypto_tfm *tfm,
char *p = crypto_kmap(tfm, sg[i].page) + sg[i].offset;
tfm->__crt_alg->cra_digest.dia_update(tfm->crt_ctx,
p, sg[i].length);
crypto_kunmap(tfm, sg[i].page, p);
crypto_kunmap(tfm, p);
crypto_yield(tfm);
}
crypto_digest_final(tfm, out);
......
......@@ -23,21 +23,20 @@ static inline void *crypto_kmap(struct crypto_tfm *tfm, struct page *page)
#ifdef CONFIG_HIGHMEM
local_bh_disable();
#endif
return kmap_atomic(page, KM_CRYPTO);
return kmap_atomic(page, KM_CRYPTO_SOFTIRQ);
} else
return kmap(page);
return kmap_atomic(page, KM_CRYPTO_USER);
}
static inline void crypto_kunmap(struct crypto_tfm *tfm,
struct page *page, void *vaddr)
static inline void crypto_kunmap(struct crypto_tfm *tfm, void *vaddr)
{
if (tfm->crt_flags & CRYPTO_ATOMIC) {
kunmap_atomic(vaddr, KM_CRYPTO);
kunmap_atomic(vaddr, KM_CRYPTO_SOFTIRQ);
#ifdef CONFIG_HIGHMEM
local_bh_enable();
#endif
} else
kunmap(page);
kunmap_atomic(vaddr, KM_CRYPTO_USER);
}
static inline void crypto_yield(struct crypto_tfm *tfm)
......
......@@ -14,17 +14,18 @@
enum km_type {
D(0) KM_BOUNCE_READ,
D(1) KM_SKB_SUNRPC_DATA,
D(2) KM_CRYPTO,
D(3) KM_SKB_DATA_SOFTIRQ,
D(4) KM_USER0,
D(5) KM_USER1,
D(6) KM_BIO_SRC_IRQ,
D(7) KM_BIO_DST_IRQ,
D(8) KM_PTE0,
D(9) KM_PTE1,
D(10) KM_IRQ0,
D(11) KM_IRQ1,
D(12) KM_TYPE_NR
D(2) KM_SKB_DATA_SOFTIRQ,
D(3) KM_USER0,
D(4) KM_USER1,
D(5) KM_BIO_SRC_IRQ,
D(6) KM_BIO_DST_IRQ,
D(7) KM_PTE0,
D(8) KM_PTE1,
D(9) KM_IRQ0,
D(10) KM_IRQ1,
D(11) KM_CRYPTO_USER,
D(12) KM_CRYPTO_SOFTIRQ,
D(13) KM_TYPE_NR
};
#undef D
......
......@@ -12,18 +12,19 @@
enum km_type {
D(0) KM_BOUNCE_READ,
D(1) KM_SKB_SUNRPC_DATA,
D(2) KM_CRYPTO,
D(3) KM_SKB_DATA_SOFTIRQ,
D(4) KM_USER0,
D(5) KM_USER1,
D(6) KM_BIO_SRC_IRQ,
D(7) KM_BIO_DST_IRQ,
D(8) KM_PTE0,
D(9) KM_PTE1,
D(10) KM_PTE2,
D(11) KM_IRQ0,
D(12) KM_IRQ1,
D(13) KM_TYPE_NR
D(2) KM_SKB_DATA_SOFTIRQ,
D(3) KM_USER0,
D(4) KM_USER1,
D(5) KM_BIO_SRC_IRQ,
D(6) KM_BIO_DST_IRQ,
D(7) KM_PTE0,
D(8) KM_PTE1,
D(9) KM_PTE2,
D(10) KM_IRQ0,
D(11) KM_IRQ1,
D(12) KM_CRYPTO_USER,
D(13) KM_CRYPTO_SOFTIRQ,
D(14) KM_TYPE_NR
};
#undef D
......
......@@ -12,17 +12,18 @@
enum km_type {
D(0) KM_BOUNCE_READ,
D(1) KM_SKB_SUNRPC_DATA,
D(2) KM_CRYPTO,
D(3) KM_SKB_DATA_SOFTIRQ,
D(4) KM_USER0,
D(5) KM_USER1,
D(6) KM_BIO_SRC_IRQ,
D(7) KM_BIO_DST_IRQ,
D(8) KM_PTE0,
D(9) KM_PTE1,
D(10) KM_IRQ0,
D(11) KM_IRQ1,
D(12) KM_TYPE_NR
D(2) KM_SKB_DATA_SOFTIRQ,
D(3) KM_USER0,
D(4) KM_USER1,
D(5) KM_BIO_SRC_IRQ,
D(6) KM_BIO_DST_IRQ,
D(7) KM_PTE0,
D(8) KM_PTE1,
D(9) KM_IRQ0,
D(10) KM_IRQ1,
D(11) KM_CRYPTO_USER,
D(12) KM_CRYPTO_SOFTIRQ,
D(13) KM_TYPE_NR
};
#undef D
......
......@@ -5,7 +5,6 @@
enum km_type {
KM_BOUNCE_READ,
KM_SKB_SUNRPC_DATA,
KM_CRYPTO,
KM_SKB_DATA_SOFTIRQ,
KM_USER0,
KM_USER1,
......@@ -15,6 +14,8 @@ enum km_type {
KM_PTE1,
KM_IRQ0,
KM_IRQ1,
KM_CRYPTO_USER,
KM_CRYPTO_SOFTIRQ,
KM_TYPE_NR
};
......
......@@ -5,7 +5,6 @@
enum km_type {
KM_BOUNCE_READ,
KM_SKB_SUNRPC_DATA,
KM_CRYPTO,
KM_SKB_DATA_SOFTIRQ,
KM_USER0,
KM_USER1,
......@@ -15,6 +14,8 @@ enum km_type {
KM_PTE1,
KM_IRQ0,
KM_IRQ1,
KM_CRYPTO_USER,
KM_CRYPTO_SOFTIRQ,
KM_TYPE_NR
};
......
......@@ -5,7 +5,6 @@
enum km_type {
KM_BOUNCE_READ,
KM_SKB_SUNRPC_DATA,
KM_CRYPTO,
KM_SKB_DATA_SOFTIRQ,
KM_USER0,
KM_USER1,
......@@ -15,6 +14,8 @@ enum km_type {
KM_PTE1,
KM_IRQ0,
KM_IRQ1,
KM_CRYPTO_USER,
KM_CRYPTO_SOFTIRQ,
KM_TYPE_NR
};
......
......@@ -4,7 +4,6 @@
enum km_type {
KM_BOUNCE_READ,
KM_SKB_SUNRPC_DATA,
KM_CRYPTO,
KM_SKB_DATA_SOFTIRQ,
KM_USER0,
KM_USER1,
......@@ -14,6 +13,8 @@ enum km_type {
KM_PTE1,
KM_IRQ0,
KM_IRQ1,
KM_CRYPTO_USER,
KM_CRYPTO_SOFTIRQ,
KM_TYPE_NR
};
......
......@@ -8,7 +8,6 @@
enum km_type {
KM_BOUNCE_READ,
KM_SKB_SUNRPC_DATA,
KM_CRYPTO,
KM_SKB_DATA_SOFTIRQ,
KM_USER0,
KM_USER1,
......@@ -18,6 +17,8 @@ enum km_type {
KM_PTE1,
KM_IRQ0,
KM_IRQ1,
KM_CRYPTO_USER,
KM_CRYPTO_SOFTIRQ,
KM_TYPE_NR
};
......
......@@ -4,7 +4,6 @@
enum km_type {
KM_BOUNCE_READ,
KM_SKB_SUNRPC_DATA,
KM_CRYPTO,
KM_SKB_DATA_SOFTIRQ,
KM_USER0,
KM_USER1,
......@@ -12,6 +11,8 @@ enum km_type {
KM_BIO_DST_IRQ,
KM_IRQ0,
KM_IRQ1,
KM_CRYPTO_USER,
KM_CRYPTO_SOFTIRQ,
KM_TYPE_NR
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment