License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 17:07:57 +03:00
// SPDX-License-Identifier: GPL-2.0
2005-04-17 02:20:36 +04:00
/*
* linux / mm / mincore . c
*
2006-12-16 20:44:32 +03:00
* Copyright ( C ) 1994 - 2006 Linus Torvalds
2005-04-17 02:20:36 +04:00
*/
/*
* The mincore ( ) system call .
*/
# include <linux/pagemap.h>
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
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>
2010-03-24 11:04:11 +03:00
# include <linux/gfp.h>
2005-04-17 02:20:36 +04:00
# include <linux/mm.h>
# include <linux/mman.h>
# include <linux/syscalls.h>
2007-02-12 11:51:39 +03:00
# include <linux/swap.h>
# include <linux/swapops.h>
2017-02-25 01:59:36 +03:00
# include <linux/shmem_fs.h>
2009-12-15 04:59:58 +03:00
# include <linux/hugetlb.h>
2005-04-17 02:20:36 +04:00
2016-12-24 22:46:01 +03:00
# include <linux/uaccess.h>
2005-04-17 02:20:36 +04:00
# include <asm/pgtable.h>
2015-02-12 02:28:11 +03:00
static int mincore_hugetlb ( pte_t * pte , unsigned long hmask , unsigned long addr ,
unsigned long end , struct mm_walk * walk )
2010-05-25 01:32:10 +04:00
{
# ifdef CONFIG_HUGETLB_PAGE
2015-02-12 02:28:11 +03:00
unsigned char present ;
unsigned char * vec = walk - > private ;
2010-05-25 01:32:10 +04:00
2015-02-12 02:28:11 +03:00
/*
* Hugepages under user process are always in RAM and never
* swapped out , but theoretically it needs to be checked .
*/
present = pte & & ! huge_pte_none ( huge_ptep_get ( pte ) ) ;
for ( ; addr ! = end ; vec + + , addr + = PAGE_SIZE )
* vec = present ;
walk - > private = vec ;
2010-05-25 01:32:10 +04:00
# else
BUG ( ) ;
# endif
2015-02-12 02:28:11 +03:00
return 0 ;
2010-05-25 01:32:10 +04:00
}
2005-04-17 02:20:36 +04:00
/*
* Later we can get more picky about what " in core " means precisely .
* For now , simply check to see if the page is in the page cache ,
* and is up to date ; i . e . that no page - in operation would be required
* at this time if an application were to map and access this page .
*/
2007-02-12 11:51:39 +03:00
static unsigned char mincore_page ( struct address_space * mapping , pgoff_t pgoff )
2005-04-17 02:20:36 +04:00
{
unsigned char present = 0 ;
2007-02-12 11:51:39 +03:00
struct page * page ;
2005-04-17 02:20:36 +04:00
2007-02-12 11:51:39 +03:00
/*
* When tmpfs swaps out a page from a file , any process mapping that
* file will not get a swp_entry_t in its pte , but rather it is like
* any other file mapping ( ie . marked ! present and faulted in with
2008-04-28 13:12:10 +04:00
* tmpfs ' s . fault ) . So swapped out tmpfs mappings are tested here .
2007-02-12 11:51:39 +03:00
*/
2011-08-04 03:21:27 +04:00
# ifdef CONFIG_SWAP
2014-04-04 01:47:46 +04:00
if ( shmem_mapping ( mapping ) ) {
page = find_get_entry ( mapping , pgoff ) ;
/*
* shmem / tmpfs may return swap : account for swapcache
* page too .
*/
if ( radix_tree_exceptional_entry ( page ) ) {
swp_entry_t swp = radix_to_swp_entry ( page ) ;
mm, swap: use offset of swap entry as key of swap cache
This patch is to improve the performance of swap cache operations when
the type of the swap device is not 0. Originally, the whole swap entry
value is used as the key of the swap cache, even though there is one
radix tree for each swap device. If the type of the swap device is not
0, the height of the radix tree of the swap cache will be increased
unnecessary, especially on 64bit architecture. For example, for a 1GB
swap device on the x86_64 architecture, the height of the radix tree of
the swap cache is 11. But if the offset of the swap entry is used as
the key of the swap cache, the height of the radix tree of the swap
cache is 4. The increased height causes unnecessary radix tree
descending and increased cache footprint.
This patch reduces the height of the radix tree of the swap cache via
using the offset of the swap entry instead of the whole swap entry value
as the key of the swap cache. In 32 processes sequential swap out test
case on a Xeon E5 v3 system with RAM disk as swap, the lock contention
for the spinlock of the swap cache is reduced from 20.15% to 12.19%,
when the type of the swap device is 1.
Use the whole swap entry as key,
perf-profile.calltrace.cycles-pp._raw_spin_lock_irq.__add_to_swap_cache.add_to_swap_cache.add_to_swap.shrink_page_list: 10.37,
perf-profile.calltrace.cycles-pp._raw_spin_lock_irqsave.__remove_mapping.shrink_page_list.shrink_inactive_list.shrink_node_memcg: 9.78,
Use the swap offset as key,
perf-profile.calltrace.cycles-pp._raw_spin_lock_irq.__add_to_swap_cache.add_to_swap_cache.add_to_swap.shrink_page_list: 6.25,
perf-profile.calltrace.cycles-pp._raw_spin_lock_irqsave.__remove_mapping.shrink_page_list.shrink_inactive_list.shrink_node_memcg: 5.94,
Link: http://lkml.kernel.org/r/1473270649-27229-1-git-send-email-ying.huang@intel.com
Signed-off-by: "Huang, Ying" <ying.huang@intel.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Aaron Lu <aaron.lu@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-10-08 03:00:21 +03:00
page = find_get_page ( swap_address_space ( swp ) ,
swp_offset ( swp ) ) ;
2014-04-04 01:47:46 +04:00
}
} else
page = find_get_page ( mapping , pgoff ) ;
# else
page = find_get_page ( mapping , pgoff ) ;
2011-08-04 03:21:27 +04:00
# endif
2005-04-17 02:20:36 +04:00
if ( page ) {
present = PageUptodate ( page ) ;
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
put_page ( page ) ;
2005-04-17 02:20:36 +04:00
}
return present ;
}
2015-02-12 02:28:11 +03:00
static int __mincore_unmapped_range ( unsigned long addr , unsigned long end ,
struct vm_area_struct * vma , unsigned char * vec )
2010-05-25 01:32:10 +04:00
{
2010-05-25 01:32:11 +04:00
unsigned long nr = ( end - addr ) > > PAGE_SHIFT ;
2010-05-25 01:32:10 +04:00
int i ;
if ( vma - > vm_file ) {
pgoff_t pgoff ;
pgoff = linear_page_index ( vma , addr ) ;
for ( i = 0 ; i < nr ; i + + , pgoff + + )
vec [ i ] = mincore_page ( vma - > vm_file - > f_mapping , pgoff ) ;
} else {
for ( i = 0 ; i < nr ; i + + )
vec [ i ] = 0 ;
}
2015-02-12 02:28:11 +03:00
return nr ;
}
static int mincore_unmapped_range ( unsigned long addr , unsigned long end ,
struct mm_walk * walk )
{
walk - > private + = __mincore_unmapped_range ( addr , end ,
walk - > vma , walk - > private ) ;
return 0 ;
2010-05-25 01:32:10 +04:00
}
2015-02-12 02:28:11 +03:00
static int mincore_pte_range ( pmd_t * pmd , unsigned long addr , unsigned long end ,
struct mm_walk * walk )
2010-05-25 01:32:10 +04:00
{
spinlock_t * ptl ;
2015-02-12 02:28:11 +03:00
struct vm_area_struct * vma = walk - > vma ;
2010-05-25 01:32:10 +04:00
pte_t * ptep ;
2015-02-12 02:28:11 +03:00
unsigned char * vec = walk - > private ;
int nr = ( end - addr ) > > PAGE_SHIFT ;
2016-01-22 03:40:25 +03:00
ptl = pmd_trans_huge_lock ( pmd , vma ) ;
if ( ptl ) {
2015-02-12 02:28:11 +03:00
memset ( vec , 1 , nr ) ;
spin_unlock ( ptl ) ;
goto out ;
}
2010-05-25 01:32:10 +04:00
2015-02-12 02:28:11 +03:00
if ( pmd_trans_unstable ( pmd ) ) {
__mincore_unmapped_range ( addr , end , vma , vec ) ;
goto out ;
}
ptep = pte_offset_map_lock ( walk - > mm , pmd , addr , & ptl ) ;
for ( ; addr ! = end ; ptep + + , addr + = PAGE_SIZE ) {
2010-05-25 01:32:10 +04:00
pte_t pte = * ptep ;
if ( pte_none ( pte ) )
2015-02-12 02:28:11 +03:00
__mincore_unmapped_range ( addr , addr + PAGE_SIZE ,
vma , vec ) ;
2010-05-25 01:32:10 +04:00
else if ( pte_present ( pte ) )
2010-05-25 01:32:11 +04:00
* vec = 1 ;
2015-02-11 01:10:04 +03:00
else { /* pte is a swap entry */
2010-05-25 01:32:10 +04:00
swp_entry_t entry = pte_to_swp_entry ( pte ) ;
2014-12-13 03:55:07 +03:00
if ( non_swap_entry ( entry ) ) {
/*
* migration or hwpoison entries are always
* uptodate
*/
2010-05-25 01:32:11 +04:00
* vec = 1 ;
2010-05-25 01:32:10 +04:00
} else {
# ifdef CONFIG_SWAP
2013-02-23 04:34:37 +04:00
* vec = mincore_page ( swap_address_space ( entry ) ,
mm, swap: use offset of swap entry as key of swap cache
This patch is to improve the performance of swap cache operations when
the type of the swap device is not 0. Originally, the whole swap entry
value is used as the key of the swap cache, even though there is one
radix tree for each swap device. If the type of the swap device is not
0, the height of the radix tree of the swap cache will be increased
unnecessary, especially on 64bit architecture. For example, for a 1GB
swap device on the x86_64 architecture, the height of the radix tree of
the swap cache is 11. But if the offset of the swap entry is used as
the key of the swap cache, the height of the radix tree of the swap
cache is 4. The increased height causes unnecessary radix tree
descending and increased cache footprint.
This patch reduces the height of the radix tree of the swap cache via
using the offset of the swap entry instead of the whole swap entry value
as the key of the swap cache. In 32 processes sequential swap out test
case on a Xeon E5 v3 system with RAM disk as swap, the lock contention
for the spinlock of the swap cache is reduced from 20.15% to 12.19%,
when the type of the swap device is 1.
Use the whole swap entry as key,
perf-profile.calltrace.cycles-pp._raw_spin_lock_irq.__add_to_swap_cache.add_to_swap_cache.add_to_swap.shrink_page_list: 10.37,
perf-profile.calltrace.cycles-pp._raw_spin_lock_irqsave.__remove_mapping.shrink_page_list.shrink_inactive_list.shrink_node_memcg: 9.78,
Use the swap offset as key,
perf-profile.calltrace.cycles-pp._raw_spin_lock_irq.__add_to_swap_cache.add_to_swap_cache.add_to_swap.shrink_page_list: 6.25,
perf-profile.calltrace.cycles-pp._raw_spin_lock_irqsave.__remove_mapping.shrink_page_list.shrink_inactive_list.shrink_node_memcg: 5.94,
Link: http://lkml.kernel.org/r/1473270649-27229-1-git-send-email-ying.huang@intel.com
Signed-off-by: "Huang, Ying" <ying.huang@intel.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Aaron Lu <aaron.lu@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-10-08 03:00:21 +03:00
swp_offset ( entry ) ) ;
2010-05-25 01:32:10 +04:00
# else
WARN_ON ( 1 ) ;
2010-05-25 01:32:11 +04:00
* vec = 1 ;
2010-05-25 01:32:10 +04:00
# endif
}
}
2010-05-25 01:32:11 +04:00
vec + + ;
2015-02-12 02:28:11 +03:00
}
2010-05-25 01:32:10 +04:00
pte_unmap_unlock ( ptep - 1 , ptl ) ;
2015-02-12 02:28:11 +03:00
out :
walk - > private + = nr ;
cond_resched ( ) ;
return 0 ;
2010-05-25 01:32:11 +04:00
}
2006-12-16 20:44:32 +03:00
/*
* Do a chunk of " sys_mincore() " . We ' ve already checked
* all the arguments , we hold the mmap semaphore : we should
* just return the amount of info we ' re asked for .
*/
2010-05-25 01:32:09 +04:00
static long do_mincore ( unsigned long addr , unsigned long pages , unsigned char * vec )
2005-04-17 02:20:36 +04:00
{
2010-05-25 01:32:09 +04:00
struct vm_area_struct * vma ;
2010-05-25 01:32:11 +04:00
unsigned long end ;
2015-02-12 02:28:11 +03:00
int err ;
struct mm_walk mincore_walk = {
. pmd_entry = mincore_pte_range ,
. pte_hole = mincore_unmapped_range ,
. hugetlb_entry = mincore_hugetlb ,
. private = vec ,
} ;
2005-04-17 02:20:36 +04:00
2010-05-25 01:32:09 +04:00
vma = find_vma ( current - > mm , addr ) ;
2006-12-17 03:01:50 +03:00
if ( ! vma | | addr < vma - > vm_start )
return - ENOMEM ;
2015-02-12 02:28:11 +03:00
mincore_walk . mm = vma - > vm_mm ;
2010-05-25 01:32:11 +04:00
end = min ( vma - > vm_end , addr + ( pages < < PAGE_SHIFT ) ) ;
2015-02-12 02:28:11 +03:00
err = walk_page_range ( addr , end , & mincore_walk ) ;
if ( err < 0 )
return err ;
2010-05-25 01:32:11 +04:00
return ( end - addr ) > > PAGE_SHIFT ;
2005-04-17 02:20:36 +04:00
}
/*
* The mincore ( 2 ) system call .
*
* mincore ( ) returns the memory residency status of the pages in the
* current process ' s address space specified by [ addr , addr + len ) .
* The status is returned in a vector of bytes . The least significant
* bit of each byte is 1 if the referenced page is in memory , otherwise
* it is zero .
*
* Because the status of a page can change after mincore ( ) checks it
* but before it returns to the application , the returned vector may
* contain stale information . Only locked pages are guaranteed to
* remain in memory .
*
* return values :
* zero - success
* - EFAULT - vec points to an illegal address
2016-04-01 15:29:48 +03:00
* - EINVAL - addr is not a multiple of PAGE_SIZE
2005-04-17 02:20:36 +04:00
* - ENOMEM - Addresses in the range [ addr , addr + len ] are
* invalid for the address space of this process , or
* specify one or more pages which are not currently
* mapped
* - EAGAIN - A kernel resource was temporarily unavailable .
*/
2009-01-14 16:14:16 +03:00
SYSCALL_DEFINE3 ( mincore , unsigned long , start , size_t , len ,
unsigned char __user * , vec )
2005-04-17 02:20:36 +04:00
{
2006-12-16 20:44:32 +03:00
long retval ;
unsigned long pages ;
unsigned char * tmp ;
2005-04-17 02:20:36 +04:00
2006-12-16 20:44:32 +03:00
/* Check the start address: needs to be page-aligned.. */
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
if ( start & ~ PAGE_MASK )
2006-12-16 20:44:32 +03:00
return - EINVAL ;
2005-04-17 02:20:36 +04:00
2006-12-16 20:44:32 +03:00
/* ..and we need to be passed a valid user-space range */
if ( ! access_ok ( VERIFY_READ , ( void __user * ) start , len ) )
return - ENOMEM ;
2005-04-17 02:20:36 +04:00
2016-04-01 15:29:48 +03:00
/* This also avoids any overflows on PAGE_ALIGN */
2006-12-16 20:44:32 +03:00
pages = len > > PAGE_SHIFT ;
2015-11-06 05:46:38 +03:00
pages + = ( offset_in_page ( len ) ) ! = 0 ;
2005-04-17 02:20:36 +04:00
2006-12-16 20:44:32 +03:00
if ( ! access_ok ( VERIFY_WRITE , vec , pages ) )
return - EFAULT ;
2005-04-17 02:20:36 +04:00
2006-12-16 20:44:32 +03:00
tmp = ( void * ) __get_free_page ( GFP_USER ) ;
if ( ! tmp )
2006-12-17 03:01:50 +03:00
return - EAGAIN ;
2006-12-16 20:44:32 +03:00
retval = 0 ;
while ( pages ) {
/*
* Do at most PAGE_SIZE entries per iteration , due to
* the temporary buffer size .
*/
down_read ( & current - > mm - > mmap_sem ) ;
2010-05-25 01:32:09 +04:00
retval = do_mincore ( start , min ( pages , PAGE_SIZE ) , tmp ) ;
2006-12-16 20:44:32 +03:00
up_read ( & current - > mm - > mmap_sem ) ;
if ( retval < = 0 )
break ;
if ( copy_to_user ( vec , tmp , retval ) ) {
retval = - EFAULT ;
break ;
2005-04-17 02:20:36 +04:00
}
2006-12-16 20:44:32 +03:00
pages - = retval ;
vec + = retval ;
start + = retval < < PAGE_SHIFT ;
retval = 0 ;
2005-04-17 02:20:36 +04:00
}
2006-12-16 20:44:32 +03:00
free_page ( ( unsigned long ) tmp ) ;
return retval ;
2005-04-17 02:20:36 +04:00
}