mirror of
https://github.com/FEX-Emu/linux.git
synced 2024-12-25 02:48:21 +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>
219 lines
4.7 KiB
C
219 lines
4.7 KiB
C
/*
|
|
* 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.
|
|
*
|
|
* Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
|
|
*/
|
|
|
|
#include <linux/capability.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/types.h>
|
|
#include <linux/socket.h>
|
|
#include <linux/in.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/timer.h>
|
|
#include <linux/string.h>
|
|
#include <linux/sockios.h>
|
|
#include <linux/net.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/slab.h>
|
|
#include <net/ax25.h>
|
|
#include <linux/inet.h>
|
|
#include <linux/netdevice.h>
|
|
#include <linux/if_arp.h>
|
|
#include <linux/skbuff.h>
|
|
#include <net/sock.h>
|
|
#include <asm/uaccess.h>
|
|
#include <asm/system.h>
|
|
#include <linux/fcntl.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/list.h>
|
|
#include <linux/notifier.h>
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/stat.h>
|
|
#include <linux/netfilter.h>
|
|
#include <linux/sysctl.h>
|
|
#include <net/ip.h>
|
|
#include <net/arp.h>
|
|
|
|
/*
|
|
* Callsign/UID mapper. This is in kernel space for security on multi-amateur machines.
|
|
*/
|
|
|
|
static HLIST_HEAD(ax25_uid_list);
|
|
static DEFINE_RWLOCK(ax25_uid_lock);
|
|
|
|
int ax25_uid_policy;
|
|
|
|
EXPORT_SYMBOL(ax25_uid_policy);
|
|
|
|
ax25_uid_assoc *ax25_findbyuid(uid_t uid)
|
|
{
|
|
ax25_uid_assoc *ax25_uid, *res = NULL;
|
|
struct hlist_node *node;
|
|
|
|
read_lock(&ax25_uid_lock);
|
|
ax25_uid_for_each(ax25_uid, node, &ax25_uid_list) {
|
|
if (ax25_uid->uid == uid) {
|
|
ax25_uid_hold(ax25_uid);
|
|
res = ax25_uid;
|
|
break;
|
|
}
|
|
}
|
|
read_unlock(&ax25_uid_lock);
|
|
|
|
return res;
|
|
}
|
|
|
|
EXPORT_SYMBOL(ax25_findbyuid);
|
|
|
|
int ax25_uid_ioctl(int cmd, struct sockaddr_ax25 *sax)
|
|
{
|
|
ax25_uid_assoc *ax25_uid;
|
|
struct hlist_node *node;
|
|
ax25_uid_assoc *user;
|
|
unsigned long res;
|
|
|
|
switch (cmd) {
|
|
case SIOCAX25GETUID:
|
|
res = -ENOENT;
|
|
read_lock(&ax25_uid_lock);
|
|
ax25_uid_for_each(ax25_uid, node, &ax25_uid_list) {
|
|
if (ax25cmp(&sax->sax25_call, &ax25_uid->call) == 0) {
|
|
res = ax25_uid->uid;
|
|
break;
|
|
}
|
|
}
|
|
read_unlock(&ax25_uid_lock);
|
|
|
|
return res;
|
|
|
|
case SIOCAX25ADDUID:
|
|
if (!capable(CAP_NET_ADMIN))
|
|
return -EPERM;
|
|
user = ax25_findbyuid(sax->sax25_uid);
|
|
if (user) {
|
|
ax25_uid_put(user);
|
|
return -EEXIST;
|
|
}
|
|
if (sax->sax25_uid == 0)
|
|
return -EINVAL;
|
|
if ((ax25_uid = kmalloc(sizeof(*ax25_uid), GFP_KERNEL)) == NULL)
|
|
return -ENOMEM;
|
|
|
|
atomic_set(&ax25_uid->refcount, 1);
|
|
ax25_uid->uid = sax->sax25_uid;
|
|
ax25_uid->call = sax->sax25_call;
|
|
|
|
write_lock(&ax25_uid_lock);
|
|
hlist_add_head(&ax25_uid->uid_node, &ax25_uid_list);
|
|
write_unlock(&ax25_uid_lock);
|
|
|
|
return 0;
|
|
|
|
case SIOCAX25DELUID:
|
|
if (!capable(CAP_NET_ADMIN))
|
|
return -EPERM;
|
|
|
|
ax25_uid = NULL;
|
|
write_lock(&ax25_uid_lock);
|
|
ax25_uid_for_each(ax25_uid, node, &ax25_uid_list) {
|
|
if (ax25cmp(&sax->sax25_call, &ax25_uid->call) == 0)
|
|
break;
|
|
}
|
|
if (ax25_uid == NULL) {
|
|
write_unlock(&ax25_uid_lock);
|
|
return -ENOENT;
|
|
}
|
|
hlist_del_init(&ax25_uid->uid_node);
|
|
ax25_uid_put(ax25_uid);
|
|
write_unlock(&ax25_uid_lock);
|
|
|
|
return 0;
|
|
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
|
|
return -EINVAL; /*NOTREACHED */
|
|
}
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
static void *ax25_uid_seq_start(struct seq_file *seq, loff_t *pos)
|
|
__acquires(ax25_uid_lock)
|
|
{
|
|
read_lock(&ax25_uid_lock);
|
|
return seq_hlist_start_head(&ax25_uid_list, *pos);
|
|
}
|
|
|
|
static void *ax25_uid_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
|
{
|
|
return seq_hlist_next(v, &ax25_uid_list, pos);
|
|
}
|
|
|
|
static void ax25_uid_seq_stop(struct seq_file *seq, void *v)
|
|
__releases(ax25_uid_lock)
|
|
{
|
|
read_unlock(&ax25_uid_lock);
|
|
}
|
|
|
|
static int ax25_uid_seq_show(struct seq_file *seq, void *v)
|
|
{
|
|
char buf[11];
|
|
|
|
if (v == SEQ_START_TOKEN)
|
|
seq_printf(seq, "Policy: %d\n", ax25_uid_policy);
|
|
else {
|
|
struct ax25_uid_assoc *pt;
|
|
|
|
pt = hlist_entry(v, struct ax25_uid_assoc, uid_node);
|
|
seq_printf(seq, "%6d %s\n", pt->uid, ax2asc(buf, &pt->call));
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static const struct seq_operations ax25_uid_seqops = {
|
|
.start = ax25_uid_seq_start,
|
|
.next = ax25_uid_seq_next,
|
|
.stop = ax25_uid_seq_stop,
|
|
.show = ax25_uid_seq_show,
|
|
};
|
|
|
|
static int ax25_uid_info_open(struct inode *inode, struct file *file)
|
|
{
|
|
return seq_open(file, &ax25_uid_seqops);
|
|
}
|
|
|
|
const struct file_operations ax25_uid_fops = {
|
|
.owner = THIS_MODULE,
|
|
.open = ax25_uid_info_open,
|
|
.read = seq_read,
|
|
.llseek = seq_lseek,
|
|
.release = seq_release,
|
|
};
|
|
|
|
#endif
|
|
|
|
/*
|
|
* Free all memory associated with UID/Callsign structures.
|
|
*/
|
|
void __exit ax25_uid_free(void)
|
|
{
|
|
ax25_uid_assoc *ax25_uid;
|
|
struct hlist_node *node;
|
|
|
|
write_lock(&ax25_uid_lock);
|
|
again:
|
|
ax25_uid_for_each(ax25_uid, node, &ax25_uid_list) {
|
|
hlist_del_init(&ax25_uid->uid_node);
|
|
ax25_uid_put(ax25_uid);
|
|
goto again;
|
|
}
|
|
write_unlock(&ax25_uid_lock);
|
|
}
|