mirror of
https://github.com/torvalds/linux.git
synced 2024-12-29 06:12:08 +00:00
5a0e3ad6af
percpu.h is included by sched.h and module.h and thus ends up being included when building most .c files. percpu.h includes slab.h which in turn includes gfp.h making everything defined by the two files universally available and complicating inclusion dependencies. percpu.h -> slab.h dependency is about to be removed. Prepare for this change by updating users of gfp and slab facilities include those headers directly instead of assuming availability. As this conversion needs to touch large number of source files, the following script is used as the basis of conversion. http://userweb.kernel.org/~tj/misc/slabh-sweep.py The script does the followings. * Scan files for gfp and slab usages and update includes such that only the necessary includes are there. ie. if only gfp is used, gfp.h, if slab is used, slab.h. * When the script inserts a new include, it looks at the include blocks and try to put the new include such that its order conforms to its surrounding. It's put in the include block which contains core kernel includes, in the same order that the rest are ordered - alphabetical, Christmas tree, rev-Xmas-tree or at the end if there doesn't seem to be any matching order. * If the script can't find a place to put a new include (mostly because the file doesn't have fitting include block), it prints out an error message indicating which .h file needs to be added to the file. The conversion was done in the following steps. 1. The initial automatic conversion of all .c files updated slightly over 4000 files, deleting around 700 includes and adding ~480 gfp.h and ~3000 slab.h inclusions. The script emitted errors for ~400 files. 2. Each error was manually checked. Some didn't need the inclusion, some needed manual addition while adding it to implementation .h or embedding .c file was more appropriate for others. This step added inclusions to around 150 files. 3. The script was run again and the output was compared to the edits from #2 to make sure no file was left behind. 4. Several build tests were done and a couple of problems were fixed. e.g. lib/decompress_*.c used malloc/free() wrappers around slab APIs requiring slab.h to be added manually. 5. The script was run on all .h files but without automatically editing them as sprinkling gfp.h and slab.h inclusions around .h files could easily lead to inclusion dependency hell. Most gfp.h inclusion directives were ignored as stuff from gfp.h was usually wildly available and often used in preprocessor macros. Each slab.h inclusion directive was examined and added manually as necessary. 6. percpu.h was updated not to include slab.h. 7. Build test were done on the following configurations and failures were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my distributed build env didn't work with gcov compiles) and a few more options had to be turned off depending on archs to make things build (like ipr on powerpc/64 which failed due to missing writeq). * x86 and x86_64 UP and SMP allmodconfig and a custom test config. * powerpc and powerpc64 SMP allmodconfig * sparc and sparc64 SMP allmodconfig * ia64 SMP allmodconfig * s390 SMP allmodconfig * alpha SMP allmodconfig * um on x86_64 SMP allmodconfig 8. percpu.h modifications were reverted so that it could be applied as a separate patch and serve as bisection point. Given the fact that I had only a couple of failures from tests on step 6, I'm fairly confident about the coverage of this conversion patch. If there is a breakage, it's likely to be something in one of the arch headers which should be easily discoverable easily on most builds of the specific arch. Signed-off-by: Tejun Heo <tj@kernel.org> Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
303 lines
6.3 KiB
C
303 lines
6.3 KiB
C
/*
|
|
* Create default crypto algorithm instances.
|
|
*
|
|
* Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
* any later version.
|
|
*
|
|
*/
|
|
|
|
#include <crypto/internal/aead.h>
|
|
#include <linux/ctype.h>
|
|
#include <linux/err.h>
|
|
#include <linux/init.h>
|
|
#include <linux/kthread.h>
|
|
#include <linux/module.h>
|
|
#include <linux/notifier.h>
|
|
#include <linux/rtnetlink.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/string.h>
|
|
|
|
#include "internal.h"
|
|
|
|
struct cryptomgr_param {
|
|
struct rtattr *tb[CRYPTO_MAX_ATTRS + 2];
|
|
|
|
struct {
|
|
struct rtattr attr;
|
|
struct crypto_attr_type data;
|
|
} type;
|
|
|
|
union {
|
|
struct rtattr attr;
|
|
struct {
|
|
struct rtattr attr;
|
|
struct crypto_attr_alg data;
|
|
} alg;
|
|
struct {
|
|
struct rtattr attr;
|
|
struct crypto_attr_u32 data;
|
|
} nu32;
|
|
} attrs[CRYPTO_MAX_ATTRS];
|
|
|
|
char larval[CRYPTO_MAX_ALG_NAME];
|
|
char template[CRYPTO_MAX_ALG_NAME];
|
|
|
|
u32 otype;
|
|
u32 omask;
|
|
};
|
|
|
|
struct crypto_test_param {
|
|
char driver[CRYPTO_MAX_ALG_NAME];
|
|
char alg[CRYPTO_MAX_ALG_NAME];
|
|
u32 type;
|
|
};
|
|
|
|
static int cryptomgr_probe(void *data)
|
|
{
|
|
struct cryptomgr_param *param = data;
|
|
struct crypto_template *tmpl;
|
|
struct crypto_instance *inst;
|
|
int err;
|
|
|
|
tmpl = crypto_lookup_template(param->template);
|
|
if (!tmpl)
|
|
goto err;
|
|
|
|
do {
|
|
if (tmpl->create) {
|
|
err = tmpl->create(tmpl, param->tb);
|
|
continue;
|
|
}
|
|
|
|
inst = tmpl->alloc(param->tb);
|
|
if (IS_ERR(inst))
|
|
err = PTR_ERR(inst);
|
|
else if ((err = crypto_register_instance(tmpl, inst)))
|
|
tmpl->free(inst);
|
|
} while (err == -EAGAIN && !signal_pending(current));
|
|
|
|
crypto_tmpl_put(tmpl);
|
|
|
|
if (err)
|
|
goto err;
|
|
|
|
out:
|
|
kfree(param);
|
|
module_put_and_exit(0);
|
|
|
|
err:
|
|
crypto_larval_error(param->larval, param->otype, param->omask);
|
|
goto out;
|
|
}
|
|
|
|
static int cryptomgr_schedule_probe(struct crypto_larval *larval)
|
|
{
|
|
struct task_struct *thread;
|
|
struct cryptomgr_param *param;
|
|
const char *name = larval->alg.cra_name;
|
|
const char *p;
|
|
unsigned int len;
|
|
int i;
|
|
|
|
if (!try_module_get(THIS_MODULE))
|
|
goto err;
|
|
|
|
param = kzalloc(sizeof(*param), GFP_KERNEL);
|
|
if (!param)
|
|
goto err_put_module;
|
|
|
|
for (p = name; isalnum(*p) || *p == '-' || *p == '_'; p++)
|
|
;
|
|
|
|
len = p - name;
|
|
if (!len || *p != '(')
|
|
goto err_free_param;
|
|
|
|
memcpy(param->template, name, len);
|
|
|
|
i = 0;
|
|
for (;;) {
|
|
int notnum = 0;
|
|
|
|
name = ++p;
|
|
len = 0;
|
|
|
|
for (; isalnum(*p) || *p == '-' || *p == '_'; p++)
|
|
notnum |= !isdigit(*p);
|
|
|
|
if (*p == '(') {
|
|
int recursion = 0;
|
|
|
|
for (;;) {
|
|
if (!*++p)
|
|
goto err_free_param;
|
|
if (*p == '(')
|
|
recursion++;
|
|
else if (*p == ')' && !recursion--)
|
|
break;
|
|
}
|
|
|
|
notnum = 1;
|
|
p++;
|
|
}
|
|
|
|
len = p - name;
|
|
if (!len)
|
|
goto err_free_param;
|
|
|
|
if (notnum) {
|
|
param->attrs[i].alg.attr.rta_len =
|
|
sizeof(param->attrs[i].alg);
|
|
param->attrs[i].alg.attr.rta_type = CRYPTOA_ALG;
|
|
memcpy(param->attrs[i].alg.data.name, name, len);
|
|
} else {
|
|
param->attrs[i].nu32.attr.rta_len =
|
|
sizeof(param->attrs[i].nu32);
|
|
param->attrs[i].nu32.attr.rta_type = CRYPTOA_U32;
|
|
param->attrs[i].nu32.data.num =
|
|
simple_strtol(name, NULL, 0);
|
|
}
|
|
|
|
param->tb[i + 1] = ¶m->attrs[i].attr;
|
|
i++;
|
|
|
|
if (i >= CRYPTO_MAX_ATTRS)
|
|
goto err_free_param;
|
|
|
|
if (*p == ')')
|
|
break;
|
|
|
|
if (*p != ',')
|
|
goto err_free_param;
|
|
}
|
|
|
|
if (!i)
|
|
goto err_free_param;
|
|
|
|
param->tb[i + 1] = NULL;
|
|
|
|
param->type.attr.rta_len = sizeof(param->type);
|
|
param->type.attr.rta_type = CRYPTOA_TYPE;
|
|
param->type.data.type = larval->alg.cra_flags & ~CRYPTO_ALG_TESTED;
|
|
param->type.data.mask = larval->mask & ~CRYPTO_ALG_TESTED;
|
|
param->tb[0] = ¶m->type.attr;
|
|
|
|
param->otype = larval->alg.cra_flags;
|
|
param->omask = larval->mask;
|
|
|
|
memcpy(param->larval, larval->alg.cra_name, CRYPTO_MAX_ALG_NAME);
|
|
|
|
thread = kthread_run(cryptomgr_probe, param, "cryptomgr_probe");
|
|
if (IS_ERR(thread))
|
|
goto err_free_param;
|
|
|
|
return NOTIFY_STOP;
|
|
|
|
err_free_param:
|
|
kfree(param);
|
|
err_put_module:
|
|
module_put(THIS_MODULE);
|
|
err:
|
|
return NOTIFY_OK;
|
|
}
|
|
|
|
static int cryptomgr_test(void *data)
|
|
{
|
|
struct crypto_test_param *param = data;
|
|
u32 type = param->type;
|
|
int err = 0;
|
|
|
|
if (type & CRYPTO_ALG_TESTED)
|
|
goto skiptest;
|
|
|
|
err = alg_test(param->driver, param->alg, type, CRYPTO_ALG_TESTED);
|
|
|
|
skiptest:
|
|
crypto_alg_tested(param->driver, err);
|
|
|
|
kfree(param);
|
|
module_put_and_exit(0);
|
|
}
|
|
|
|
static int cryptomgr_schedule_test(struct crypto_alg *alg)
|
|
{
|
|
struct task_struct *thread;
|
|
struct crypto_test_param *param;
|
|
u32 type;
|
|
|
|
if (!try_module_get(THIS_MODULE))
|
|
goto err;
|
|
|
|
param = kzalloc(sizeof(*param), GFP_KERNEL);
|
|
if (!param)
|
|
goto err_put_module;
|
|
|
|
memcpy(param->driver, alg->cra_driver_name, sizeof(param->driver));
|
|
memcpy(param->alg, alg->cra_name, sizeof(param->alg));
|
|
type = alg->cra_flags;
|
|
|
|
/* This piece of crap needs to disappear into per-type test hooks. */
|
|
if ((!((type ^ CRYPTO_ALG_TYPE_BLKCIPHER) &
|
|
CRYPTO_ALG_TYPE_BLKCIPHER_MASK) && !(type & CRYPTO_ALG_GENIV) &&
|
|
((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) ==
|
|
CRYPTO_ALG_TYPE_BLKCIPHER ? alg->cra_blkcipher.ivsize :
|
|
alg->cra_ablkcipher.ivsize)) ||
|
|
(!((type ^ CRYPTO_ALG_TYPE_AEAD) & CRYPTO_ALG_TYPE_MASK) &&
|
|
alg->cra_type == &crypto_nivaead_type && alg->cra_aead.ivsize))
|
|
type |= CRYPTO_ALG_TESTED;
|
|
|
|
param->type = type;
|
|
|
|
thread = kthread_run(cryptomgr_test, param, "cryptomgr_test");
|
|
if (IS_ERR(thread))
|
|
goto err_free_param;
|
|
|
|
return NOTIFY_STOP;
|
|
|
|
err_free_param:
|
|
kfree(param);
|
|
err_put_module:
|
|
module_put(THIS_MODULE);
|
|
err:
|
|
return NOTIFY_OK;
|
|
}
|
|
|
|
static int cryptomgr_notify(struct notifier_block *this, unsigned long msg,
|
|
void *data)
|
|
{
|
|
switch (msg) {
|
|
case CRYPTO_MSG_ALG_REQUEST:
|
|
return cryptomgr_schedule_probe(data);
|
|
case CRYPTO_MSG_ALG_REGISTER:
|
|
return cryptomgr_schedule_test(data);
|
|
}
|
|
|
|
return NOTIFY_DONE;
|
|
}
|
|
|
|
static struct notifier_block cryptomgr_notifier = {
|
|
.notifier_call = cryptomgr_notify,
|
|
};
|
|
|
|
static int __init cryptomgr_init(void)
|
|
{
|
|
return crypto_register_notifier(&cryptomgr_notifier);
|
|
}
|
|
|
|
static void __exit cryptomgr_exit(void)
|
|
{
|
|
int err = crypto_unregister_notifier(&cryptomgr_notifier);
|
|
BUG_ON(err);
|
|
}
|
|
|
|
subsys_initcall(cryptomgr_init);
|
|
module_exit(cryptomgr_exit);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_DESCRIPTION("Crypto Algorithm Manager");
|