![Tejun Heo](/assets/img/avatar_default.png)
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>
403 lines
8.4 KiB
C
403 lines
8.4 KiB
C
/*
|
|
* drivers/s390/cio/blacklist.c
|
|
* S/390 common I/O routines -- blacklisting of specific devices
|
|
*
|
|
* Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH,
|
|
* IBM Corporation
|
|
* Author(s): Ingo Adlung (adlung@de.ibm.com)
|
|
* Cornelia Huck (cornelia.huck@de.ibm.com)
|
|
* Arnd Bergmann (arndb@de.ibm.com)
|
|
*/
|
|
|
|
#define KMSG_COMPONENT "cio"
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
#include <linux/init.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/ctype.h>
|
|
#include <linux/device.h>
|
|
|
|
#include <asm/cio.h>
|
|
#include <asm/uaccess.h>
|
|
|
|
#include "blacklist.h"
|
|
#include "cio.h"
|
|
#include "cio_debug.h"
|
|
#include "css.h"
|
|
#include "device.h"
|
|
|
|
/*
|
|
* "Blacklisting" of certain devices:
|
|
* Device numbers given in the commandline as cio_ignore=... won't be known
|
|
* to Linux.
|
|
*
|
|
* These can be single devices or ranges of devices
|
|
*/
|
|
|
|
/* 65536 bits for each set to indicate if a devno is blacklisted or not */
|
|
#define __BL_DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \
|
|
(8*sizeof(long)))
|
|
static unsigned long bl_dev[__MAX_SSID + 1][__BL_DEV_WORDS];
|
|
typedef enum {add, free} range_action;
|
|
|
|
/*
|
|
* Function: blacklist_range
|
|
* (Un-)blacklist the devices from-to
|
|
*/
|
|
static int blacklist_range(range_action action, unsigned int from_ssid,
|
|
unsigned int to_ssid, unsigned int from,
|
|
unsigned int to, int msgtrigger)
|
|
{
|
|
if ((from_ssid > to_ssid) || ((from_ssid == to_ssid) && (from > to))) {
|
|
if (msgtrigger)
|
|
pr_warning("0.%x.%04x to 0.%x.%04x is not a valid "
|
|
"range for cio_ignore\n", from_ssid, from,
|
|
to_ssid, to);
|
|
|
|
return 1;
|
|
}
|
|
|
|
while ((from_ssid < to_ssid) || ((from_ssid == to_ssid) &&
|
|
(from <= to))) {
|
|
if (action == add)
|
|
set_bit(from, bl_dev[from_ssid]);
|
|
else
|
|
clear_bit(from, bl_dev[from_ssid]);
|
|
from++;
|
|
if (from > __MAX_SUBCHANNEL) {
|
|
from_ssid++;
|
|
from = 0;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int pure_hex(char **cp, unsigned int *val, int min_digit,
|
|
int max_digit, int max_val)
|
|
{
|
|
int diff;
|
|
unsigned int value;
|
|
|
|
diff = 0;
|
|
*val = 0;
|
|
|
|
while (isxdigit(**cp) && (diff <= max_digit)) {
|
|
|
|
if (isdigit(**cp))
|
|
value = **cp - '0';
|
|
else
|
|
value = tolower(**cp) - 'a' + 10;
|
|
*val = *val * 16 + value;
|
|
(*cp)++;
|
|
diff++;
|
|
}
|
|
|
|
if ((diff < min_digit) || (diff > max_digit) || (*val > max_val))
|
|
return 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int parse_busid(char *str, unsigned int *cssid, unsigned int *ssid,
|
|
unsigned int *devno, int msgtrigger)
|
|
{
|
|
char *str_work;
|
|
int val, rc, ret;
|
|
|
|
rc = 1;
|
|
|
|
if (*str == '\0')
|
|
goto out;
|
|
|
|
/* old style */
|
|
str_work = str;
|
|
val = simple_strtoul(str, &str_work, 16);
|
|
|
|
if (*str_work == '\0') {
|
|
if (val <= __MAX_SUBCHANNEL) {
|
|
*devno = val;
|
|
*ssid = 0;
|
|
*cssid = 0;
|
|
rc = 0;
|
|
}
|
|
goto out;
|
|
}
|
|
|
|
/* new style */
|
|
str_work = str;
|
|
ret = pure_hex(&str_work, cssid, 1, 2, __MAX_CSSID);
|
|
if (ret || (str_work[0] != '.'))
|
|
goto out;
|
|
str_work++;
|
|
ret = pure_hex(&str_work, ssid, 1, 1, __MAX_SSID);
|
|
if (ret || (str_work[0] != '.'))
|
|
goto out;
|
|
str_work++;
|
|
ret = pure_hex(&str_work, devno, 4, 4, __MAX_SUBCHANNEL);
|
|
if (ret || (str_work[0] != '\0'))
|
|
goto out;
|
|
|
|
rc = 0;
|
|
out:
|
|
if (rc && msgtrigger)
|
|
pr_warning("%s is not a valid device for the cio_ignore "
|
|
"kernel parameter\n", str);
|
|
|
|
return rc;
|
|
}
|
|
|
|
static int blacklist_parse_parameters(char *str, range_action action,
|
|
int msgtrigger)
|
|
{
|
|
unsigned int from_cssid, to_cssid, from_ssid, to_ssid, from, to;
|
|
int rc, totalrc;
|
|
char *parm;
|
|
range_action ra;
|
|
|
|
totalrc = 0;
|
|
|
|
while ((parm = strsep(&str, ","))) {
|
|
rc = 0;
|
|
ra = action;
|
|
if (*parm == '!') {
|
|
if (ra == add)
|
|
ra = free;
|
|
else
|
|
ra = add;
|
|
parm++;
|
|
}
|
|
if (strcmp(parm, "all") == 0) {
|
|
from_cssid = 0;
|
|
from_ssid = 0;
|
|
from = 0;
|
|
to_cssid = __MAX_CSSID;
|
|
to_ssid = __MAX_SSID;
|
|
to = __MAX_SUBCHANNEL;
|
|
} else {
|
|
rc = parse_busid(strsep(&parm, "-"), &from_cssid,
|
|
&from_ssid, &from, msgtrigger);
|
|
if (!rc) {
|
|
if (parm != NULL)
|
|
rc = parse_busid(parm, &to_cssid,
|
|
&to_ssid, &to,
|
|
msgtrigger);
|
|
else {
|
|
to_cssid = from_cssid;
|
|
to_ssid = from_ssid;
|
|
to = from;
|
|
}
|
|
}
|
|
}
|
|
if (!rc) {
|
|
rc = blacklist_range(ra, from_ssid, to_ssid, from, to,
|
|
msgtrigger);
|
|
if (rc)
|
|
totalrc = -EINVAL;
|
|
} else
|
|
totalrc = -EINVAL;
|
|
}
|
|
|
|
return totalrc;
|
|
}
|
|
|
|
static int __init
|
|
blacklist_setup (char *str)
|
|
{
|
|
CIO_MSG_EVENT(6, "Reading blacklist parameters\n");
|
|
if (blacklist_parse_parameters(str, add, 1))
|
|
return 0;
|
|
return 1;
|
|
}
|
|
|
|
__setup ("cio_ignore=", blacklist_setup);
|
|
|
|
/* Checking if devices are blacklisted */
|
|
|
|
/*
|
|
* Function: is_blacklisted
|
|
* Returns 1 if the given devicenumber can be found in the blacklist,
|
|
* otherwise 0.
|
|
* Used by validate_subchannel()
|
|
*/
|
|
int
|
|
is_blacklisted (int ssid, int devno)
|
|
{
|
|
return test_bit (devno, bl_dev[ssid]);
|
|
}
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
/*
|
|
* Function: blacklist_parse_proc_parameters
|
|
* parse the stuff which is piped to /proc/cio_ignore
|
|
*/
|
|
static int blacklist_parse_proc_parameters(char *buf)
|
|
{
|
|
int rc;
|
|
char *parm;
|
|
|
|
parm = strsep(&buf, " ");
|
|
|
|
if (strcmp("free", parm) == 0)
|
|
rc = blacklist_parse_parameters(buf, free, 0);
|
|
else if (strcmp("add", parm) == 0)
|
|
rc = blacklist_parse_parameters(buf, add, 0);
|
|
else if (strcmp("purge", parm) == 0)
|
|
return ccw_purge_blacklisted();
|
|
else
|
|
return -EINVAL;
|
|
|
|
css_schedule_reprobe();
|
|
|
|
return rc;
|
|
}
|
|
|
|
/* Iterator struct for all devices. */
|
|
struct ccwdev_iter {
|
|
int devno;
|
|
int ssid;
|
|
int in_range;
|
|
};
|
|
|
|
static void *
|
|
cio_ignore_proc_seq_start(struct seq_file *s, loff_t *offset)
|
|
{
|
|
struct ccwdev_iter *iter = s->private;
|
|
|
|
if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1))
|
|
return NULL;
|
|
memset(iter, 0, sizeof(*iter));
|
|
iter->ssid = *offset / (__MAX_SUBCHANNEL + 1);
|
|
iter->devno = *offset % (__MAX_SUBCHANNEL + 1);
|
|
return iter;
|
|
}
|
|
|
|
static void
|
|
cio_ignore_proc_seq_stop(struct seq_file *s, void *it)
|
|
{
|
|
}
|
|
|
|
static void *
|
|
cio_ignore_proc_seq_next(struct seq_file *s, void *it, loff_t *offset)
|
|
{
|
|
struct ccwdev_iter *iter;
|
|
|
|
if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1))
|
|
return NULL;
|
|
iter = it;
|
|
if (iter->devno == __MAX_SUBCHANNEL) {
|
|
iter->devno = 0;
|
|
iter->ssid++;
|
|
if (iter->ssid > __MAX_SSID)
|
|
return NULL;
|
|
} else
|
|
iter->devno++;
|
|
(*offset)++;
|
|
return iter;
|
|
}
|
|
|
|
static int
|
|
cio_ignore_proc_seq_show(struct seq_file *s, void *it)
|
|
{
|
|
struct ccwdev_iter *iter;
|
|
|
|
iter = it;
|
|
if (!is_blacklisted(iter->ssid, iter->devno))
|
|
/* Not blacklisted, nothing to output. */
|
|
return 0;
|
|
if (!iter->in_range) {
|
|
/* First device in range. */
|
|
if ((iter->devno == __MAX_SUBCHANNEL) ||
|
|
!is_blacklisted(iter->ssid, iter->devno + 1))
|
|
/* Singular device. */
|
|
return seq_printf(s, "0.%x.%04x\n",
|
|
iter->ssid, iter->devno);
|
|
iter->in_range = 1;
|
|
return seq_printf(s, "0.%x.%04x-", iter->ssid, iter->devno);
|
|
}
|
|
if ((iter->devno == __MAX_SUBCHANNEL) ||
|
|
!is_blacklisted(iter->ssid, iter->devno + 1)) {
|
|
/* Last device in range. */
|
|
iter->in_range = 0;
|
|
return seq_printf(s, "0.%x.%04x\n", iter->ssid, iter->devno);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static ssize_t
|
|
cio_ignore_write(struct file *file, const char __user *user_buf,
|
|
size_t user_len, loff_t *offset)
|
|
{
|
|
char *buf;
|
|
ssize_t rc, ret, i;
|
|
|
|
if (*offset)
|
|
return -EINVAL;
|
|
if (user_len > 65536)
|
|
user_len = 65536;
|
|
buf = vmalloc (user_len + 1); /* maybe better use the stack? */
|
|
if (buf == NULL)
|
|
return -ENOMEM;
|
|
memset(buf, 0, user_len + 1);
|
|
|
|
if (strncpy_from_user (buf, user_buf, user_len) < 0) {
|
|
rc = -EFAULT;
|
|
goto out_free;
|
|
}
|
|
|
|
i = user_len - 1;
|
|
while ((i >= 0) && (isspace(buf[i]) || (buf[i] == 0))) {
|
|
buf[i] = '\0';
|
|
i--;
|
|
}
|
|
ret = blacklist_parse_proc_parameters(buf);
|
|
if (ret)
|
|
rc = ret;
|
|
else
|
|
rc = user_len;
|
|
|
|
out_free:
|
|
vfree (buf);
|
|
return rc;
|
|
}
|
|
|
|
static const struct seq_operations cio_ignore_proc_seq_ops = {
|
|
.start = cio_ignore_proc_seq_start,
|
|
.stop = cio_ignore_proc_seq_stop,
|
|
.next = cio_ignore_proc_seq_next,
|
|
.show = cio_ignore_proc_seq_show,
|
|
};
|
|
|
|
static int
|
|
cio_ignore_proc_open(struct inode *inode, struct file *file)
|
|
{
|
|
return seq_open_private(file, &cio_ignore_proc_seq_ops,
|
|
sizeof(struct ccwdev_iter));
|
|
}
|
|
|
|
static const struct file_operations cio_ignore_proc_fops = {
|
|
.open = cio_ignore_proc_open,
|
|
.read = seq_read,
|
|
.llseek = seq_lseek,
|
|
.release = seq_release_private,
|
|
.write = cio_ignore_write,
|
|
};
|
|
|
|
static int
|
|
cio_ignore_proc_init (void)
|
|
{
|
|
struct proc_dir_entry *entry;
|
|
|
|
entry = proc_create("cio_ignore", S_IFREG | S_IRUGO | S_IWUSR, NULL,
|
|
&cio_ignore_proc_fops);
|
|
if (!entry)
|
|
return -ENOENT;
|
|
return 0;
|
|
}
|
|
|
|
__initcall (cio_ignore_proc_init);
|
|
|
|
#endif /* CONFIG_PROC_FS */
|