mirror of
https://github.com/FEX-Emu/linux.git
synced 2024-12-30 21:46:31 +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>
218 lines
5.4 KiB
C
218 lines
5.4 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.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*
|
|
* Copyright (C) IBM Corp. 2006
|
|
*
|
|
* Authors: Hollis Blanchard <hollisb@us.ibm.com>
|
|
*/
|
|
|
|
#include <linux/mm.h>
|
|
#include <linux/slab.h>
|
|
#include <asm/page.h>
|
|
#include <xen/xencomm.h>
|
|
#include <xen/interface/xen.h>
|
|
#include <asm/xen/xencomm.h> /* for xencomm_is_phys_contiguous() */
|
|
|
|
static int xencomm_init(struct xencomm_desc *desc,
|
|
void *buffer, unsigned long bytes)
|
|
{
|
|
unsigned long recorded = 0;
|
|
int i = 0;
|
|
|
|
while ((recorded < bytes) && (i < desc->nr_addrs)) {
|
|
unsigned long vaddr = (unsigned long)buffer + recorded;
|
|
unsigned long paddr;
|
|
int offset;
|
|
int chunksz;
|
|
|
|
offset = vaddr % PAGE_SIZE; /* handle partial pages */
|
|
chunksz = min(PAGE_SIZE - offset, bytes - recorded);
|
|
|
|
paddr = xencomm_vtop(vaddr);
|
|
if (paddr == ~0UL) {
|
|
printk(KERN_DEBUG "%s: couldn't translate vaddr %lx\n",
|
|
__func__, vaddr);
|
|
return -EINVAL;
|
|
}
|
|
|
|
desc->address[i++] = paddr;
|
|
recorded += chunksz;
|
|
}
|
|
|
|
if (recorded < bytes) {
|
|
printk(KERN_DEBUG
|
|
"%s: could only translate %ld of %ld bytes\n",
|
|
__func__, recorded, bytes);
|
|
return -ENOSPC;
|
|
}
|
|
|
|
/* mark remaining addresses invalid (just for safety) */
|
|
while (i < desc->nr_addrs)
|
|
desc->address[i++] = XENCOMM_INVALID;
|
|
|
|
desc->magic = XENCOMM_MAGIC;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct xencomm_desc *xencomm_alloc(gfp_t gfp_mask,
|
|
void *buffer, unsigned long bytes)
|
|
{
|
|
struct xencomm_desc *desc;
|
|
unsigned long buffer_ulong = (unsigned long)buffer;
|
|
unsigned long start = buffer_ulong & PAGE_MASK;
|
|
unsigned long end = (buffer_ulong + bytes) | ~PAGE_MASK;
|
|
unsigned long nr_addrs = (end - start + 1) >> PAGE_SHIFT;
|
|
unsigned long size = sizeof(*desc) +
|
|
sizeof(desc->address[0]) * nr_addrs;
|
|
|
|
/*
|
|
* slab allocator returns at least sizeof(void*) aligned pointer.
|
|
* When sizeof(*desc) > sizeof(void*), struct xencomm_desc might
|
|
* cross page boundary.
|
|
*/
|
|
if (sizeof(*desc) > sizeof(void *)) {
|
|
unsigned long order = get_order(size);
|
|
desc = (struct xencomm_desc *)__get_free_pages(gfp_mask,
|
|
order);
|
|
if (desc == NULL)
|
|
return NULL;
|
|
|
|
desc->nr_addrs =
|
|
((PAGE_SIZE << order) - sizeof(struct xencomm_desc)) /
|
|
sizeof(*desc->address);
|
|
} else {
|
|
desc = kmalloc(size, gfp_mask);
|
|
if (desc == NULL)
|
|
return NULL;
|
|
|
|
desc->nr_addrs = nr_addrs;
|
|
}
|
|
return desc;
|
|
}
|
|
|
|
void xencomm_free(struct xencomm_handle *desc)
|
|
{
|
|
if (desc && !((ulong)desc & XENCOMM_INLINE_FLAG)) {
|
|
struct xencomm_desc *desc__ = (struct xencomm_desc *)desc;
|
|
if (sizeof(*desc__) > sizeof(void *)) {
|
|
unsigned long size = sizeof(*desc__) +
|
|
sizeof(desc__->address[0]) * desc__->nr_addrs;
|
|
unsigned long order = get_order(size);
|
|
free_pages((unsigned long)__va(desc), order);
|
|
} else
|
|
kfree(__va(desc));
|
|
}
|
|
}
|
|
|
|
static int xencomm_create(void *buffer, unsigned long bytes,
|
|
struct xencomm_desc **ret, gfp_t gfp_mask)
|
|
{
|
|
struct xencomm_desc *desc;
|
|
int rc;
|
|
|
|
pr_debug("%s: %p[%ld]\n", __func__, buffer, bytes);
|
|
|
|
if (bytes == 0) {
|
|
/* don't create a descriptor; Xen recognizes NULL. */
|
|
BUG_ON(buffer != NULL);
|
|
*ret = NULL;
|
|
return 0;
|
|
}
|
|
|
|
BUG_ON(buffer == NULL); /* 'bytes' is non-zero */
|
|
|
|
desc = xencomm_alloc(gfp_mask, buffer, bytes);
|
|
if (!desc) {
|
|
printk(KERN_DEBUG "%s failure\n", "xencomm_alloc");
|
|
return -ENOMEM;
|
|
}
|
|
|
|
rc = xencomm_init(desc, buffer, bytes);
|
|
if (rc) {
|
|
printk(KERN_DEBUG "%s failure: %d\n", "xencomm_init", rc);
|
|
xencomm_free((struct xencomm_handle *)__pa(desc));
|
|
return rc;
|
|
}
|
|
|
|
*ret = desc;
|
|
return 0;
|
|
}
|
|
|
|
static struct xencomm_handle *xencomm_create_inline(void *ptr)
|
|
{
|
|
unsigned long paddr;
|
|
|
|
BUG_ON(!xencomm_is_phys_contiguous((unsigned long)ptr));
|
|
|
|
paddr = (unsigned long)xencomm_pa(ptr);
|
|
BUG_ON(paddr & XENCOMM_INLINE_FLAG);
|
|
return (struct xencomm_handle *)(paddr | XENCOMM_INLINE_FLAG);
|
|
}
|
|
|
|
/* "mini" routine, for stack-based communications: */
|
|
static int xencomm_create_mini(void *buffer,
|
|
unsigned long bytes, struct xencomm_mini *xc_desc,
|
|
struct xencomm_desc **ret)
|
|
{
|
|
int rc = 0;
|
|
struct xencomm_desc *desc;
|
|
BUG_ON(((unsigned long)xc_desc) % sizeof(*xc_desc) != 0);
|
|
|
|
desc = (void *)xc_desc;
|
|
|
|
desc->nr_addrs = XENCOMM_MINI_ADDRS;
|
|
|
|
rc = xencomm_init(desc, buffer, bytes);
|
|
if (!rc)
|
|
*ret = desc;
|
|
|
|
return rc;
|
|
}
|
|
|
|
struct xencomm_handle *xencomm_map(void *ptr, unsigned long bytes)
|
|
{
|
|
int rc;
|
|
struct xencomm_desc *desc;
|
|
|
|
if (xencomm_is_phys_contiguous((unsigned long)ptr))
|
|
return xencomm_create_inline(ptr);
|
|
|
|
rc = xencomm_create(ptr, bytes, &desc, GFP_KERNEL);
|
|
|
|
if (rc || desc == NULL)
|
|
return NULL;
|
|
|
|
return xencomm_pa(desc);
|
|
}
|
|
|
|
struct xencomm_handle *__xencomm_map_no_alloc(void *ptr, unsigned long bytes,
|
|
struct xencomm_mini *xc_desc)
|
|
{
|
|
int rc;
|
|
struct xencomm_desc *desc = NULL;
|
|
|
|
if (xencomm_is_phys_contiguous((unsigned long)ptr))
|
|
return xencomm_create_inline(ptr);
|
|
|
|
rc = xencomm_create_mini(ptr, bytes, xc_desc,
|
|
&desc);
|
|
|
|
if (rc)
|
|
return NULL;
|
|
|
|
return xencomm_pa(desc);
|
|
}
|