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
|
|
|
#ifndef _LINUX_HIGHMEM_H
|
|
|
|
#define _LINUX_HIGHMEM_H
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
2010-08-10 04:18:32 +04:00
|
|
|
#include <linux/kernel.h>
|
2011-11-24 05:12:59 +04:00
|
|
|
#include <linux/bug.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/mm.h>
|
2006-12-07 07:32:21 +03:00
|
|
|
#include <linux/uaccess.h>
|
2010-11-12 01:05:10 +03:00
|
|
|
#include <linux/hardirq.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
|
2020-11-03 12:27:34 +03:00
|
|
|
#include "highmem-internal.h"
|
2006-03-26 13:36:57 +04:00
|
|
|
|
2020-11-03 12:27:34 +03:00
|
|
|
/**
|
|
|
|
* kmap - Map a page for long term usage
|
|
|
|
* @page: Pointer to the page to be mapped
|
|
|
|
*
|
|
|
|
* Returns: The virtual address of the mapping
|
|
|
|
*
|
|
|
|
* Can only be invoked from preemptible task context because on 32bit
|
|
|
|
* systems with CONFIG_HIGHMEM enabled this function might sleep.
|
|
|
|
*
|
|
|
|
* For systems with CONFIG_HIGHMEM=n and for pages in the low memory area
|
|
|
|
* this returns the virtual address of the direct kernel mapping.
|
|
|
|
*
|
|
|
|
* The returned virtual address is globally visible and valid up to the
|
|
|
|
* point where it is unmapped via kunmap(). The pointer can be handed to
|
|
|
|
* other contexts.
|
|
|
|
*
|
|
|
|
* For highmem pages on 32bit systems this can be slow as the mapping space
|
|
|
|
* is limited and protected by a global lock. In case that there is no
|
|
|
|
* mapping slot available the function blocks until a slot is released via
|
|
|
|
* kunmap().
|
2020-11-03 12:27:18 +03:00
|
|
|
*/
|
2020-11-03 12:27:34 +03:00
|
|
|
static inline void *kmap(struct page *page);
|
2020-06-05 02:47:30 +03:00
|
|
|
|
2020-11-03 12:27:34 +03:00
|
|
|
/**
|
|
|
|
* kunmap - Unmap the virtual address mapped by kmap()
|
|
|
|
* @addr: Virtual address to be unmapped
|
|
|
|
*
|
|
|
|
* Counterpart to kmap(). A NOOP for CONFIG_HIGHMEM=n and for mappings of
|
|
|
|
* pages in the low memory area.
|
2020-06-05 02:47:42 +03:00
|
|
|
*/
|
2020-11-03 12:27:34 +03:00
|
|
|
static inline void kunmap(struct page *page);
|
2020-11-03 12:27:18 +03:00
|
|
|
|
2020-11-03 12:27:34 +03:00
|
|
|
/**
|
|
|
|
* kmap_to_page - Get the page for a kmap'ed address
|
|
|
|
* @addr: The address to look up
|
|
|
|
*
|
|
|
|
* Returns: The page which is mapped to @addr.
|
|
|
|
*/
|
|
|
|
static inline struct page *kmap_to_page(void *addr);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-11-03 12:27:34 +03:00
|
|
|
/**
|
|
|
|
* kmap_flush_unused - Flush all unused kmap mappings in order to
|
|
|
|
* remove stray mappings
|
|
|
|
*/
|
|
|
|
static inline void kmap_flush_unused(void);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-11-03 12:27:34 +03:00
|
|
|
/**
|
2020-11-18 22:48:44 +03:00
|
|
|
* kmap_local_page - Map a page for temporary usage
|
2020-11-03 12:27:34 +03:00
|
|
|
* @page: Pointer to the page to be mapped
|
|
|
|
*
|
|
|
|
* Returns: The virtual address of the mapping
|
|
|
|
*
|
|
|
|
* Can be invoked from any context.
|
|
|
|
*
|
|
|
|
* Requires careful handling when nesting multiple mappings because the map
|
|
|
|
* management is stack based. The unmap has to be in the reverse order of
|
|
|
|
* the map operation:
|
|
|
|
*
|
2020-11-18 22:48:44 +03:00
|
|
|
* addr1 = kmap_local_page(page1);
|
|
|
|
* addr2 = kmap_local_page(page2);
|
2020-11-03 12:27:34 +03:00
|
|
|
* ...
|
2020-11-18 22:48:44 +03:00
|
|
|
* kunmap_local(addr2);
|
|
|
|
* kunmap_local(addr1);
|
2020-11-03 12:27:34 +03:00
|
|
|
*
|
|
|
|
* Unmapping addr1 before addr2 is invalid and causes malfunction.
|
|
|
|
*
|
|
|
|
* Contrary to kmap() mappings the mapping is only valid in the context of
|
|
|
|
* the caller and cannot be handed to other contexts.
|
|
|
|
*
|
|
|
|
* On CONFIG_HIGHMEM=n kernels and for low memory pages this returns the
|
|
|
|
* virtual address of the direct mapping. Only real highmem pages are
|
|
|
|
* temporarily mapped.
|
|
|
|
*
|
2020-11-18 22:48:44 +03:00
|
|
|
* While it is significantly faster than kmap() for the higmem case it
|
|
|
|
* comes with restrictions about the pointer validity. Only use when really
|
|
|
|
* necessary.
|
|
|
|
*
|
|
|
|
* On HIGHMEM enabled systems mapping a highmem page has the side effect of
|
|
|
|
* disabling migration in order to keep the virtual address stable across
|
|
|
|
* preemption. No caller of kmap_local_page() can rely on this side effect.
|
|
|
|
*/
|
|
|
|
static inline void *kmap_local_page(struct page *page);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* kmap_atomic - Atomically map a page for temporary usage - Deprecated!
|
|
|
|
* @page: Pointer to the page to be mapped
|
|
|
|
*
|
|
|
|
* Returns: The virtual address of the mapping
|
|
|
|
*
|
|
|
|
* Effectively a wrapper around kmap_local_page() which disables pagefaults
|
|
|
|
* and preemption.
|
|
|
|
*
|
|
|
|
* Do not use in new code. Use kmap_local_page() instead.
|
2020-11-03 12:27:34 +03:00
|
|
|
*/
|
|
|
|
static inline void *kmap_atomic(struct page *page);
|
2012-08-01 03:45:02 +04:00
|
|
|
|
2020-11-03 12:27:34 +03:00
|
|
|
/**
|
|
|
|
* kunmap_atomic - Unmap the virtual address mapped by kmap_atomic()
|
|
|
|
* @addr: Virtual address to be unmapped
|
|
|
|
*
|
|
|
|
* Counterpart to kmap_atomic().
|
|
|
|
*
|
2020-11-18 22:48:44 +03:00
|
|
|
* Effectively a wrapper around kunmap_local() which additionally undoes
|
|
|
|
* the side effects of kmap_atomic(), i.e. reenabling pagefaults and
|
2020-11-03 12:27:34 +03:00
|
|
|
* preemption.
|
|
|
|
*/
|
2006-09-26 10:31:11 +04:00
|
|
|
|
2020-11-03 12:27:34 +03:00
|
|
|
/* Highmem related interfaces for management code */
|
|
|
|
static inline unsigned int nr_free_highpages(void);
|
|
|
|
static inline unsigned long totalhigh_pages(void);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-11-03 12:27:34 +03:00
|
|
|
#ifndef ARCH_HAS_FLUSH_ANON_PAGE
|
|
|
|
static inline void flush_anon_page(struct vm_area_struct *vma, struct page *page, unsigned long vmaddr)
|
2020-06-05 02:47:34 +03:00
|
|
|
{
|
|
|
|
}
|
2020-06-05 02:48:10 +03:00
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-11-03 12:27:34 +03:00
|
|
|
#ifndef ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE
|
|
|
|
static inline void flush_kernel_dcache_page(struct page *page)
|
2007-05-02 00:33:07 +04:00
|
|
|
{
|
|
|
|
}
|
2020-11-03 12:27:34 +03:00
|
|
|
static inline void flush_kernel_vmap_range(void *vaddr, int size)
|
2020-11-03 12:27:18 +03:00
|
|
|
{
|
|
|
|
}
|
2020-11-03 12:27:34 +03:00
|
|
|
static inline void invalidate_kernel_vmap_range(void *vaddr, int size)
|
2020-11-03 12:27:18 +03:00
|
|
|
{
|
|
|
|
}
|
2020-06-05 02:48:10 +03:00
|
|
|
#endif
|
2011-11-25 18:08:45 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* when CONFIG_HIGHMEM is not set these will be plain clear/copy_page */
|
2008-11-27 14:13:58 +03:00
|
|
|
#ifndef clear_user_highpage
|
2005-04-17 02:20:36 +04:00
|
|
|
static inline void clear_user_highpage(struct page *page, unsigned long vaddr)
|
|
|
|
{
|
2011-11-25 19:14:14 +04:00
|
|
|
void *addr = kmap_atomic(page);
|
2005-04-17 02:20:36 +04:00
|
|
|
clear_user_page(addr, vaddr, page);
|
2011-11-25 19:14:14 +04:00
|
|
|
kunmap_atomic(addr);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2008-11-27 14:13:58 +03:00
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#ifndef __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
|
2007-07-17 15:03:05 +04:00
|
|
|
/**
|
|
|
|
* __alloc_zeroed_user_highpage - Allocate a zeroed HIGHMEM page for a VMA with caller-specified movable GFP flags
|
|
|
|
* @movableflags: The GFP flags related to the pages future ability to move like __GFP_MOVABLE
|
|
|
|
* @vma: The VMA the page is to be allocated for
|
|
|
|
* @vaddr: The virtual address the page will be inserted into
|
|
|
|
*
|
|
|
|
* This function will allocate a page for a VMA but the caller is expected
|
|
|
|
* to specify via movableflags whether the page will be movable in the
|
|
|
|
* future or not
|
|
|
|
*
|
|
|
|
* An architecture may override this function by defining
|
|
|
|
* __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE and providing their own
|
|
|
|
* implementation.
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
static inline struct page *
|
2007-07-17 15:03:05 +04:00
|
|
|
__alloc_zeroed_user_highpage(gfp_t movableflags,
|
|
|
|
struct vm_area_struct *vma,
|
|
|
|
unsigned long vaddr)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2007-07-17 15:03:05 +04:00
|
|
|
struct page *page = alloc_page_vma(GFP_HIGHUSER | movableflags,
|
|
|
|
vma, vaddr);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (page)
|
|
|
|
clear_user_highpage(page, vaddr);
|
|
|
|
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-17 15:03:05 +04:00
|
|
|
/**
|
|
|
|
* alloc_zeroed_user_highpage_movable - Allocate a zeroed HIGHMEM page for a VMA that the caller knows can move
|
|
|
|
* @vma: The VMA the page is to be allocated for
|
|
|
|
* @vaddr: The virtual address the page will be inserted into
|
|
|
|
*
|
|
|
|
* This function will allocate a page for a VMA that the caller knows will
|
|
|
|
* be able to migrate in the future using move_pages() or reclaimed
|
|
|
|
*/
|
|
|
|
static inline struct page *
|
|
|
|
alloc_zeroed_user_highpage_movable(struct vm_area_struct *vma,
|
|
|
|
unsigned long vaddr)
|
|
|
|
{
|
|
|
|
return __alloc_zeroed_user_highpage(__GFP_MOVABLE, vma, vaddr);
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
static inline void clear_highpage(struct page *page)
|
|
|
|
{
|
2011-11-25 19:14:14 +04:00
|
|
|
void *kaddr = kmap_atomic(page);
|
2005-04-17 02:20:36 +04:00
|
|
|
clear_page(kaddr);
|
2011-11-25 19:14:14 +04:00
|
|
|
kunmap_atomic(kaddr);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2020-12-15 06:12:59 +03:00
|
|
|
/*
|
|
|
|
* If we pass in a base or tail page, we can zero up to PAGE_SIZE.
|
|
|
|
* If we pass in a head page, we can zero up to the size of the compound page.
|
|
|
|
*/
|
|
|
|
#if defined(CONFIG_HIGHMEM) && defined(CONFIG_TRANSPARENT_HUGEPAGE)
|
|
|
|
void zero_user_segments(struct page *page, unsigned start1, unsigned end1,
|
|
|
|
unsigned start2, unsigned end2);
|
|
|
|
#else /* !HIGHMEM || !TRANSPARENT_HUGEPAGE */
|
2008-02-05 09:28:29 +03:00
|
|
|
static inline void zero_user_segments(struct page *page,
|
2020-12-15 06:12:59 +03:00
|
|
|
unsigned start1, unsigned end1,
|
|
|
|
unsigned start2, unsigned end2)
|
2008-02-05 09:28:29 +03:00
|
|
|
{
|
2011-11-25 19:14:14 +04:00
|
|
|
void *kaddr = kmap_atomic(page);
|
2020-12-15 06:12:59 +03:00
|
|
|
unsigned int i;
|
2008-02-05 09:28:29 +03:00
|
|
|
|
2020-12-15 06:12:59 +03:00
|
|
|
BUG_ON(end1 > page_size(page) || end2 > page_size(page));
|
2008-02-05 09:28:29 +03:00
|
|
|
|
|
|
|
if (end1 > start1)
|
|
|
|
memset(kaddr + start1, 0, end1 - start1);
|
|
|
|
|
|
|
|
if (end2 > start2)
|
|
|
|
memset(kaddr + start2, 0, end2 - start2);
|
|
|
|
|
2011-11-25 19:14:14 +04:00
|
|
|
kunmap_atomic(kaddr);
|
2020-12-15 06:12:59 +03:00
|
|
|
for (i = 0; i < compound_nr(page); i++)
|
|
|
|
flush_dcache_page(page + i);
|
2008-02-05 09:28:29 +03:00
|
|
|
}
|
2020-12-15 06:12:59 +03:00
|
|
|
#endif /* !HIGHMEM || !TRANSPARENT_HUGEPAGE */
|
2008-02-05 09:28:29 +03:00
|
|
|
|
|
|
|
static inline void zero_user_segment(struct page *page,
|
|
|
|
unsigned start, unsigned end)
|
|
|
|
{
|
|
|
|
zero_user_segments(page, start, end, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void zero_user(struct page *page,
|
|
|
|
unsigned start, unsigned size)
|
|
|
|
{
|
|
|
|
zero_user_segments(page, start, start + size, 0, 0);
|
|
|
|
}
|
2007-05-09 13:35:07 +04:00
|
|
|
|
2006-12-12 20:14:54 +03:00
|
|
|
#ifndef __HAVE_ARCH_COPY_USER_HIGHPAGE
|
|
|
|
|
2006-12-12 20:14:55 +03:00
|
|
|
static inline void copy_user_highpage(struct page *to, struct page *from,
|
|
|
|
unsigned long vaddr, struct vm_area_struct *vma)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
char *vfrom, *vto;
|
|
|
|
|
2011-11-25 19:14:14 +04:00
|
|
|
vfrom = kmap_atomic(from);
|
|
|
|
vto = kmap_atomic(to);
|
2005-04-17 02:20:36 +04:00
|
|
|
copy_user_page(vto, vfrom, vaddr, to);
|
2011-11-25 19:14:14 +04:00
|
|
|
kunmap_atomic(vto);
|
|
|
|
kunmap_atomic(vfrom);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2006-12-12 20:14:54 +03:00
|
|
|
#endif
|
|
|
|
|
2018-02-21 20:15:51 +03:00
|
|
|
#ifndef __HAVE_ARCH_COPY_HIGHPAGE
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
static inline void copy_highpage(struct page *to, struct page *from)
|
|
|
|
{
|
|
|
|
char *vfrom, *vto;
|
|
|
|
|
2011-11-25 19:14:14 +04:00
|
|
|
vfrom = kmap_atomic(from);
|
|
|
|
vto = kmap_atomic(to);
|
2005-04-17 02:20:36 +04:00
|
|
|
copy_page(vto, vfrom);
|
2011-11-25 19:14:14 +04:00
|
|
|
kunmap_atomic(vto);
|
|
|
|
kunmap_atomic(vfrom);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2018-02-21 20:15:51 +03:00
|
|
|
#endif
|
|
|
|
|
2021-02-10 09:22:16 +03:00
|
|
|
static inline void memcpy_page(struct page *dst_page, size_t dst_off,
|
|
|
|
struct page *src_page, size_t src_off,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
char *dst = kmap_local_page(dst_page);
|
|
|
|
char *src = kmap_local_page(src_page);
|
|
|
|
|
2021-02-10 20:49:28 +03:00
|
|
|
VM_BUG_ON(dst_off + len > PAGE_SIZE || src_off + len > PAGE_SIZE);
|
2021-02-10 09:22:16 +03:00
|
|
|
memcpy(dst + dst_off, src + src_off, len);
|
|
|
|
kunmap_local(src);
|
|
|
|
kunmap_local(dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void memmove_page(struct page *dst_page, size_t dst_off,
|
|
|
|
struct page *src_page, size_t src_off,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
char *dst = kmap_local_page(dst_page);
|
|
|
|
char *src = kmap_local_page(src_page);
|
|
|
|
|
2021-02-10 20:49:28 +03:00
|
|
|
VM_BUG_ON(dst_off + len > PAGE_SIZE || src_off + len > PAGE_SIZE);
|
2021-02-10 09:22:16 +03:00
|
|
|
memmove(dst + dst_off, src + src_off, len);
|
|
|
|
kunmap_local(src);
|
|
|
|
kunmap_local(dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void memset_page(struct page *page, size_t offset, int val,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
char *addr = kmap_local_page(page);
|
|
|
|
|
2021-02-10 20:49:28 +03:00
|
|
|
VM_BUG_ON(offset + len > PAGE_SIZE);
|
2021-02-10 09:22:16 +03:00
|
|
|
memset(addr + offset, val, len);
|
|
|
|
kunmap_local(addr);
|
|
|
|
}
|
|
|
|
|
mm/highmem: Lift memcpy_[to|from]_page to core
Working through a conversion to a call kmap_local_page() instead of
kmap() revealed many places where the pattern kmap/memcpy/kunmap
occurred.
Eric Biggers, Matthew Wilcox, Christoph Hellwig, Dan Williams, and Al
Viro all suggested putting this code into helper functions. Al Viro
further pointed out that these functions already existed in the iov_iter
code.[1]
Various locations for the lifted functions were considered.
Headers like mm.h or string.h seem ok but don't really portray the
functionality well. pagemap.h made some sense but is for page cache
functionality.[2]
Another alternative would be to create a new header for the promoted
memcpy functions, but it masks the fact that these are designed to copy
to/from pages using the kernel direct mappings and complicates matters
with a new header.
Placing these functions in 'highmem.h' is suboptimal especially with the
changes being proposed in the functionality of kmap. From a caller
perspective including/using 'highmem.h' implies that the functions
defined in that header are only required when highmem is in use which is
increasingly not the case with modern processors. However, highmem.h is
where all the current functions like this reside (zero_user(),
clear_highpage(), clear_user_highpage(), copy_user_highpage(), and
copy_highpage()). So it makes the most sense even though it is
distasteful for some.[3]
Lift memcpy_to_page() and memcpy_from_page() to pagemap.h.
[1] https://lore.kernel.org/lkml/20201013200149.GI3576660@ZenIV.linux.org.uk/
https://lore.kernel.org/lkml/20201013112544.GA5249@infradead.org/
[2] https://lore.kernel.org/lkml/20201208122316.GH7338@casper.infradead.org/
[3] https://lore.kernel.org/lkml/20201013200149.GI3576660@ZenIV.linux.org.uk/#t
https://lore.kernel.org/lkml/20201208163814.GN1563847@iweiny-DESK2.sc.intel.com/
Cc: Boris Pismenny <borisp@mellanox.com>
Cc: Or Gerlitz <gerlitz.or@gmail.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Suggested-by: Matthew Wilcox <willy@infradead.org>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Suggested-by: Dan Williams <dan.j.williams@intel.com>
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Suggested-by: Eric Biggers <ebiggers@kernel.org>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-10 09:22:14 +03:00
|
|
|
static inline void memcpy_from_page(char *to, struct page *page,
|
|
|
|
size_t offset, size_t len)
|
|
|
|
{
|
2021-02-10 09:22:15 +03:00
|
|
|
char *from = kmap_local_page(page);
|
mm/highmem: Lift memcpy_[to|from]_page to core
Working through a conversion to a call kmap_local_page() instead of
kmap() revealed many places where the pattern kmap/memcpy/kunmap
occurred.
Eric Biggers, Matthew Wilcox, Christoph Hellwig, Dan Williams, and Al
Viro all suggested putting this code into helper functions. Al Viro
further pointed out that these functions already existed in the iov_iter
code.[1]
Various locations for the lifted functions were considered.
Headers like mm.h or string.h seem ok but don't really portray the
functionality well. pagemap.h made some sense but is for page cache
functionality.[2]
Another alternative would be to create a new header for the promoted
memcpy functions, but it masks the fact that these are designed to copy
to/from pages using the kernel direct mappings and complicates matters
with a new header.
Placing these functions in 'highmem.h' is suboptimal especially with the
changes being proposed in the functionality of kmap. From a caller
perspective including/using 'highmem.h' implies that the functions
defined in that header are only required when highmem is in use which is
increasingly not the case with modern processors. However, highmem.h is
where all the current functions like this reside (zero_user(),
clear_highpage(), clear_user_highpage(), copy_user_highpage(), and
copy_highpage()). So it makes the most sense even though it is
distasteful for some.[3]
Lift memcpy_to_page() and memcpy_from_page() to pagemap.h.
[1] https://lore.kernel.org/lkml/20201013200149.GI3576660@ZenIV.linux.org.uk/
https://lore.kernel.org/lkml/20201013112544.GA5249@infradead.org/
[2] https://lore.kernel.org/lkml/20201208122316.GH7338@casper.infradead.org/
[3] https://lore.kernel.org/lkml/20201013200149.GI3576660@ZenIV.linux.org.uk/#t
https://lore.kernel.org/lkml/20201208163814.GN1563847@iweiny-DESK2.sc.intel.com/
Cc: Boris Pismenny <borisp@mellanox.com>
Cc: Or Gerlitz <gerlitz.or@gmail.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Suggested-by: Matthew Wilcox <willy@infradead.org>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Suggested-by: Dan Williams <dan.j.williams@intel.com>
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Suggested-by: Eric Biggers <ebiggers@kernel.org>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-10 09:22:14 +03:00
|
|
|
|
2021-02-10 20:49:28 +03:00
|
|
|
VM_BUG_ON(offset + len > PAGE_SIZE);
|
mm/highmem: Lift memcpy_[to|from]_page to core
Working through a conversion to a call kmap_local_page() instead of
kmap() revealed many places where the pattern kmap/memcpy/kunmap
occurred.
Eric Biggers, Matthew Wilcox, Christoph Hellwig, Dan Williams, and Al
Viro all suggested putting this code into helper functions. Al Viro
further pointed out that these functions already existed in the iov_iter
code.[1]
Various locations for the lifted functions were considered.
Headers like mm.h or string.h seem ok but don't really portray the
functionality well. pagemap.h made some sense but is for page cache
functionality.[2]
Another alternative would be to create a new header for the promoted
memcpy functions, but it masks the fact that these are designed to copy
to/from pages using the kernel direct mappings and complicates matters
with a new header.
Placing these functions in 'highmem.h' is suboptimal especially with the
changes being proposed in the functionality of kmap. From a caller
perspective including/using 'highmem.h' implies that the functions
defined in that header are only required when highmem is in use which is
increasingly not the case with modern processors. However, highmem.h is
where all the current functions like this reside (zero_user(),
clear_highpage(), clear_user_highpage(), copy_user_highpage(), and
copy_highpage()). So it makes the most sense even though it is
distasteful for some.[3]
Lift memcpy_to_page() and memcpy_from_page() to pagemap.h.
[1] https://lore.kernel.org/lkml/20201013200149.GI3576660@ZenIV.linux.org.uk/
https://lore.kernel.org/lkml/20201013112544.GA5249@infradead.org/
[2] https://lore.kernel.org/lkml/20201208122316.GH7338@casper.infradead.org/
[3] https://lore.kernel.org/lkml/20201013200149.GI3576660@ZenIV.linux.org.uk/#t
https://lore.kernel.org/lkml/20201208163814.GN1563847@iweiny-DESK2.sc.intel.com/
Cc: Boris Pismenny <borisp@mellanox.com>
Cc: Or Gerlitz <gerlitz.or@gmail.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Suggested-by: Matthew Wilcox <willy@infradead.org>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Suggested-by: Dan Williams <dan.j.williams@intel.com>
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Suggested-by: Eric Biggers <ebiggers@kernel.org>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-10 09:22:14 +03:00
|
|
|
memcpy(to, from + offset, len);
|
2021-02-10 09:22:15 +03:00
|
|
|
kunmap_local(from);
|
mm/highmem: Lift memcpy_[to|from]_page to core
Working through a conversion to a call kmap_local_page() instead of
kmap() revealed many places where the pattern kmap/memcpy/kunmap
occurred.
Eric Biggers, Matthew Wilcox, Christoph Hellwig, Dan Williams, and Al
Viro all suggested putting this code into helper functions. Al Viro
further pointed out that these functions already existed in the iov_iter
code.[1]
Various locations for the lifted functions were considered.
Headers like mm.h or string.h seem ok but don't really portray the
functionality well. pagemap.h made some sense but is for page cache
functionality.[2]
Another alternative would be to create a new header for the promoted
memcpy functions, but it masks the fact that these are designed to copy
to/from pages using the kernel direct mappings and complicates matters
with a new header.
Placing these functions in 'highmem.h' is suboptimal especially with the
changes being proposed in the functionality of kmap. From a caller
perspective including/using 'highmem.h' implies that the functions
defined in that header are only required when highmem is in use which is
increasingly not the case with modern processors. However, highmem.h is
where all the current functions like this reside (zero_user(),
clear_highpage(), clear_user_highpage(), copy_user_highpage(), and
copy_highpage()). So it makes the most sense even though it is
distasteful for some.[3]
Lift memcpy_to_page() and memcpy_from_page() to pagemap.h.
[1] https://lore.kernel.org/lkml/20201013200149.GI3576660@ZenIV.linux.org.uk/
https://lore.kernel.org/lkml/20201013112544.GA5249@infradead.org/
[2] https://lore.kernel.org/lkml/20201208122316.GH7338@casper.infradead.org/
[3] https://lore.kernel.org/lkml/20201013200149.GI3576660@ZenIV.linux.org.uk/#t
https://lore.kernel.org/lkml/20201208163814.GN1563847@iweiny-DESK2.sc.intel.com/
Cc: Boris Pismenny <borisp@mellanox.com>
Cc: Or Gerlitz <gerlitz.or@gmail.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Suggested-by: Matthew Wilcox <willy@infradead.org>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Suggested-by: Dan Williams <dan.j.williams@intel.com>
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Suggested-by: Eric Biggers <ebiggers@kernel.org>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-10 09:22:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void memcpy_to_page(struct page *page, size_t offset,
|
|
|
|
const char *from, size_t len)
|
|
|
|
{
|
2021-02-10 09:22:15 +03:00
|
|
|
char *to = kmap_local_page(page);
|
mm/highmem: Lift memcpy_[to|from]_page to core
Working through a conversion to a call kmap_local_page() instead of
kmap() revealed many places where the pattern kmap/memcpy/kunmap
occurred.
Eric Biggers, Matthew Wilcox, Christoph Hellwig, Dan Williams, and Al
Viro all suggested putting this code into helper functions. Al Viro
further pointed out that these functions already existed in the iov_iter
code.[1]
Various locations for the lifted functions were considered.
Headers like mm.h or string.h seem ok but don't really portray the
functionality well. pagemap.h made some sense but is for page cache
functionality.[2]
Another alternative would be to create a new header for the promoted
memcpy functions, but it masks the fact that these are designed to copy
to/from pages using the kernel direct mappings and complicates matters
with a new header.
Placing these functions in 'highmem.h' is suboptimal especially with the
changes being proposed in the functionality of kmap. From a caller
perspective including/using 'highmem.h' implies that the functions
defined in that header are only required when highmem is in use which is
increasingly not the case with modern processors. However, highmem.h is
where all the current functions like this reside (zero_user(),
clear_highpage(), clear_user_highpage(), copy_user_highpage(), and
copy_highpage()). So it makes the most sense even though it is
distasteful for some.[3]
Lift memcpy_to_page() and memcpy_from_page() to pagemap.h.
[1] https://lore.kernel.org/lkml/20201013200149.GI3576660@ZenIV.linux.org.uk/
https://lore.kernel.org/lkml/20201013112544.GA5249@infradead.org/
[2] https://lore.kernel.org/lkml/20201208122316.GH7338@casper.infradead.org/
[3] https://lore.kernel.org/lkml/20201013200149.GI3576660@ZenIV.linux.org.uk/#t
https://lore.kernel.org/lkml/20201208163814.GN1563847@iweiny-DESK2.sc.intel.com/
Cc: Boris Pismenny <borisp@mellanox.com>
Cc: Or Gerlitz <gerlitz.or@gmail.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Suggested-by: Matthew Wilcox <willy@infradead.org>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Suggested-by: Dan Williams <dan.j.williams@intel.com>
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Suggested-by: Eric Biggers <ebiggers@kernel.org>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-10 09:22:14 +03:00
|
|
|
|
2021-02-10 20:49:28 +03:00
|
|
|
VM_BUG_ON(offset + len > PAGE_SIZE);
|
mm/highmem: Lift memcpy_[to|from]_page to core
Working through a conversion to a call kmap_local_page() instead of
kmap() revealed many places where the pattern kmap/memcpy/kunmap
occurred.
Eric Biggers, Matthew Wilcox, Christoph Hellwig, Dan Williams, and Al
Viro all suggested putting this code into helper functions. Al Viro
further pointed out that these functions already existed in the iov_iter
code.[1]
Various locations for the lifted functions were considered.
Headers like mm.h or string.h seem ok but don't really portray the
functionality well. pagemap.h made some sense but is for page cache
functionality.[2]
Another alternative would be to create a new header for the promoted
memcpy functions, but it masks the fact that these are designed to copy
to/from pages using the kernel direct mappings and complicates matters
with a new header.
Placing these functions in 'highmem.h' is suboptimal especially with the
changes being proposed in the functionality of kmap. From a caller
perspective including/using 'highmem.h' implies that the functions
defined in that header are only required when highmem is in use which is
increasingly not the case with modern processors. However, highmem.h is
where all the current functions like this reside (zero_user(),
clear_highpage(), clear_user_highpage(), copy_user_highpage(), and
copy_highpage()). So it makes the most sense even though it is
distasteful for some.[3]
Lift memcpy_to_page() and memcpy_from_page() to pagemap.h.
[1] https://lore.kernel.org/lkml/20201013200149.GI3576660@ZenIV.linux.org.uk/
https://lore.kernel.org/lkml/20201013112544.GA5249@infradead.org/
[2] https://lore.kernel.org/lkml/20201208122316.GH7338@casper.infradead.org/
[3] https://lore.kernel.org/lkml/20201013200149.GI3576660@ZenIV.linux.org.uk/#t
https://lore.kernel.org/lkml/20201208163814.GN1563847@iweiny-DESK2.sc.intel.com/
Cc: Boris Pismenny <borisp@mellanox.com>
Cc: Or Gerlitz <gerlitz.or@gmail.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Suggested-by: Matthew Wilcox <willy@infradead.org>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Suggested-by: Dan Williams <dan.j.williams@intel.com>
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Suggested-by: Eric Biggers <ebiggers@kernel.org>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-10 09:22:14 +03:00
|
|
|
memcpy(to + offset, from, len);
|
2021-02-10 09:22:15 +03:00
|
|
|
kunmap_local(to);
|
mm/highmem: Lift memcpy_[to|from]_page to core
Working through a conversion to a call kmap_local_page() instead of
kmap() revealed many places where the pattern kmap/memcpy/kunmap
occurred.
Eric Biggers, Matthew Wilcox, Christoph Hellwig, Dan Williams, and Al
Viro all suggested putting this code into helper functions. Al Viro
further pointed out that these functions already existed in the iov_iter
code.[1]
Various locations for the lifted functions were considered.
Headers like mm.h or string.h seem ok but don't really portray the
functionality well. pagemap.h made some sense but is for page cache
functionality.[2]
Another alternative would be to create a new header for the promoted
memcpy functions, but it masks the fact that these are designed to copy
to/from pages using the kernel direct mappings and complicates matters
with a new header.
Placing these functions in 'highmem.h' is suboptimal especially with the
changes being proposed in the functionality of kmap. From a caller
perspective including/using 'highmem.h' implies that the functions
defined in that header are only required when highmem is in use which is
increasingly not the case with modern processors. However, highmem.h is
where all the current functions like this reside (zero_user(),
clear_highpage(), clear_user_highpage(), copy_user_highpage(), and
copy_highpage()). So it makes the most sense even though it is
distasteful for some.[3]
Lift memcpy_to_page() and memcpy_from_page() to pagemap.h.
[1] https://lore.kernel.org/lkml/20201013200149.GI3576660@ZenIV.linux.org.uk/
https://lore.kernel.org/lkml/20201013112544.GA5249@infradead.org/
[2] https://lore.kernel.org/lkml/20201208122316.GH7338@casper.infradead.org/
[3] https://lore.kernel.org/lkml/20201013200149.GI3576660@ZenIV.linux.org.uk/#t
https://lore.kernel.org/lkml/20201208163814.GN1563847@iweiny-DESK2.sc.intel.com/
Cc: Boris Pismenny <borisp@mellanox.com>
Cc: Or Gerlitz <gerlitz.or@gmail.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Suggested-by: Matthew Wilcox <willy@infradead.org>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Suggested-by: Dan Williams <dan.j.williams@intel.com>
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Suggested-by: Eric Biggers <ebiggers@kernel.org>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-10 09:22:14 +03:00
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif /* _LINUX_HIGHMEM_H */
|