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 22:07:57 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifndef _LINUX_HIGHMEM_H
|
|
|
|
#define _LINUX_HIGHMEM_H
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
2010-08-10 08:18:32 +08:00
|
|
|
#include <linux/kernel.h>
|
2011-11-24 09:12:59 +08:00
|
|
|
#include <linux/bug.h>
|
2021-11-07 05:13:35 +08:00
|
|
|
#include <linux/cacheflush.h>
|
2022-09-15 23:03:48 +08:00
|
|
|
#include <linux/kmsan.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/mm.h>
|
2006-12-07 12:32:21 +08:00
|
|
|
#include <linux/uaccess.h>
|
2010-11-12 06:05:10 +08:00
|
|
|
#include <linux/hardirq.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-11-03 17:27:34 +08:00
|
|
|
#include "highmem-internal.h"
|
2006-03-26 17:36:57 +08:00
|
|
|
|
2020-11-03 17:27:34 +08: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 17:27:18 +08:00
|
|
|
*/
|
2020-11-03 17:27:34 +08:00
|
|
|
static inline void *kmap(struct page *page);
|
2020-06-05 07:47:30 +08:00
|
|
|
|
2020-11-03 17:27:34 +08:00
|
|
|
/**
|
|
|
|
* kunmap - Unmap the virtual address mapped by kmap()
|
2022-05-14 07:48:55 +08:00
|
|
|
* @page: Pointer to the page which was mapped by kmap()
|
2020-11-03 17:27:34 +08:00
|
|
|
*
|
|
|
|
* Counterpart to kmap(). A NOOP for CONFIG_HIGHMEM=n and for mappings of
|
|
|
|
* pages in the low memory area.
|
2020-06-05 07:47:42 +08:00
|
|
|
*/
|
2020-11-03 17:27:34 +08:00
|
|
|
static inline void kunmap(struct page *page);
|
2020-11-03 17:27:18 +08:00
|
|
|
|
2020-11-03 17:27:34 +08: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 06:20:36 +08:00
|
|
|
|
2020-11-03 17:27:34 +08: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 06:20:36 +08:00
|
|
|
|
2020-11-03 17:27:34 +08:00
|
|
|
/**
|
2020-11-19 03:48:44 +08:00
|
|
|
* kmap_local_page - Map a page for temporary usage
|
2022-07-28 23:48:38 +08:00
|
|
|
* @page: Pointer to the page to be mapped
|
2020-11-03 17:27:34 +08:00
|
|
|
*
|
|
|
|
* Returns: The virtual address of the mapping
|
|
|
|
*
|
2022-07-28 23:48:39 +08:00
|
|
|
* Can be invoked from any context, including interrupts.
|
2020-11-03 17:27:34 +08:00
|
|
|
*
|
|
|
|
* 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-19 03:48:44 +08:00
|
|
|
* addr1 = kmap_local_page(page1);
|
|
|
|
* addr2 = kmap_local_page(page2);
|
2020-11-03 17:27:34 +08:00
|
|
|
* ...
|
2020-11-19 03:48:44 +08:00
|
|
|
* kunmap_local(addr2);
|
|
|
|
* kunmap_local(addr1);
|
2020-11-03 17:27:34 +08: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-19 03:48:44 +08:00
|
|
|
* While it is significantly faster than kmap() for the higmem case it
|
2022-07-28 23:48:43 +08:00
|
|
|
* comes with restrictions about the pointer validity.
|
2020-11-19 03:48:44 +08:00
|
|
|
*
|
|
|
|
* 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);
|
|
|
|
|
2020-12-30 23:21:39 +08:00
|
|
|
/**
|
|
|
|
* kmap_local_folio - Map a page in this folio for temporary usage
|
|
|
|
* @folio: The folio containing the page.
|
|
|
|
* @offset: The byte offset within the folio which identifies the page.
|
|
|
|
*
|
|
|
|
* 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::
|
|
|
|
*
|
|
|
|
* addr1 = kmap_local_folio(folio1, offset1);
|
|
|
|
* addr2 = kmap_local_folio(folio2, offset2);
|
|
|
|
* ...
|
|
|
|
* kunmap_local(addr2);
|
|
|
|
* kunmap_local(addr1);
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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_folio() can rely on this side effect.
|
|
|
|
*
|
|
|
|
* Context: Can be invoked from any context.
|
|
|
|
* Return: The virtual address of @offset.
|
|
|
|
*/
|
|
|
|
static inline void *kmap_local_folio(struct folio *folio, size_t offset);
|
|
|
|
|
2020-11-19 03:48:44 +08:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2022-05-14 07:48:55 +08:00
|
|
|
* In fact a wrapper around kmap_local_page() which also disables pagefaults
|
|
|
|
* and, depending on PREEMPT_RT configuration, also CPU migration and
|
|
|
|
* preemption. Therefore users should not count on the latter two side effects.
|
|
|
|
*
|
|
|
|
* Mappings should always be released by kunmap_atomic().
|
2020-11-19 03:48:44 +08:00
|
|
|
*
|
|
|
|
* Do not use in new code. Use kmap_local_page() instead.
|
2022-05-14 07:48:55 +08:00
|
|
|
*
|
|
|
|
* It is used in atomic context when code wants to access the contents of a
|
|
|
|
* page that might be allocated from high memory (see __GFP_HIGHMEM), for
|
|
|
|
* example a page in the pagecache. The API has two functions, and they
|
2022-06-22 16:45:46 +08:00
|
|
|
* can be used in a manner similar to the following::
|
2022-05-14 07:48:55 +08:00
|
|
|
*
|
2022-06-22 16:45:46 +08:00
|
|
|
* // Find the page of interest.
|
|
|
|
* struct page *page = find_get_page(mapping, offset);
|
2022-05-14 07:48:55 +08:00
|
|
|
*
|
2022-06-22 16:45:46 +08:00
|
|
|
* // Gain access to the contents of that page.
|
|
|
|
* void *vaddr = kmap_atomic(page);
|
2022-05-14 07:48:55 +08:00
|
|
|
*
|
2022-06-22 16:45:46 +08:00
|
|
|
* // Do something to the contents of that page.
|
|
|
|
* memset(vaddr, 0, PAGE_SIZE);
|
2022-05-14 07:48:55 +08:00
|
|
|
*
|
2022-06-22 16:45:46 +08:00
|
|
|
* // Unmap that page.
|
|
|
|
* kunmap_atomic(vaddr);
|
2022-05-14 07:48:55 +08:00
|
|
|
*
|
|
|
|
* Note that the kunmap_atomic() call takes the result of the kmap_atomic()
|
|
|
|
* call, not the argument.
|
|
|
|
*
|
|
|
|
* If you need to map two pages because you want to copy from one page to
|
|
|
|
* another you need to keep the kmap_atomic calls strictly nested, like:
|
|
|
|
*
|
|
|
|
* vaddr1 = kmap_atomic(page1);
|
|
|
|
* vaddr2 = kmap_atomic(page2);
|
|
|
|
*
|
|
|
|
* memcpy(vaddr1, vaddr2, PAGE_SIZE);
|
|
|
|
*
|
|
|
|
* kunmap_atomic(vaddr2);
|
|
|
|
* kunmap_atomic(vaddr1);
|
2020-11-03 17:27:34 +08:00
|
|
|
*/
|
|
|
|
static inline void *kmap_atomic(struct page *page);
|
2012-08-01 07:45:02 +08:00
|
|
|
|
2020-11-03 17:27:34 +08: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 06:20:36 +08:00
|
|
|
|
2020-11-03 17:27:34 +08: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 07:47:34 +08:00
|
|
|
{
|
|
|
|
}
|
2020-06-05 07:48:10 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2021-09-03 05:56:36 +08:00
|
|
|
#ifndef ARCH_IMPLEMENTS_FLUSH_KERNEL_VMAP_RANGE
|
2020-11-03 17:27:34 +08:00
|
|
|
static inline void flush_kernel_vmap_range(void *vaddr, int size)
|
2020-11-03 17:27:18 +08:00
|
|
|
{
|
|
|
|
}
|
2020-11-03 17:27:34 +08:00
|
|
|
static inline void invalidate_kernel_vmap_range(void *vaddr, int size)
|
2020-11-03 17:27:18 +08:00
|
|
|
{
|
|
|
|
}
|
2020-06-05 07:48:10 +08:00
|
|
|
#endif
|
2011-11-25 22:08:45 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* when CONFIG_HIGHMEM is not set these will be plain clear/copy_page */
|
2008-11-27 19:13:58 +08:00
|
|
|
#ifndef clear_user_highpage
|
2005-04-17 06:20:36 +08:00
|
|
|
static inline void clear_user_highpage(struct page *page, unsigned long vaddr)
|
|
|
|
{
|
2021-11-06 04:45:06 +08:00
|
|
|
void *addr = kmap_local_page(page);
|
2005-04-17 06:20:36 +08:00
|
|
|
clear_user_page(addr, vaddr, page);
|
2021-11-06 04:45:06 +08:00
|
|
|
kunmap_local(addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-11-27 19:13:58 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2021-06-03 07:52:27 +08:00
|
|
|
#ifndef __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE_MOVABLE
|
2007-07-17 19:03:05 +08:00
|
|
|
/**
|
2021-06-03 07:52:27 +08:00
|
|
|
* alloc_zeroed_user_highpage_movable - Allocate a zeroed HIGHMEM page for a VMA that the caller knows can move
|
2007-07-17 19:03:05 +08:00
|
|
|
* @vma: The VMA the page is to be allocated for
|
|
|
|
* @vaddr: The virtual address the page will be inserted into
|
|
|
|
*
|
2022-05-14 07:48:55 +08:00
|
|
|
* Returns: The allocated and zeroed HIGHMEM page
|
|
|
|
*
|
2021-06-03 07:52:27 +08:00
|
|
|
* 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
|
2007-07-17 19:03:05 +08:00
|
|
|
*
|
|
|
|
* An architecture may override this function by defining
|
2021-06-03 07:52:27 +08:00
|
|
|
* __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE_MOVABLE and providing their own
|
2007-07-17 19:03:05 +08:00
|
|
|
* implementation.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static inline struct page *
|
2021-06-03 07:52:27 +08:00
|
|
|
alloc_zeroed_user_highpage_movable(struct vm_area_struct *vma,
|
|
|
|
unsigned long vaddr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2021-06-03 07:52:27 +08:00
|
|
|
struct page *page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vaddr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (page)
|
|
|
|
clear_user_highpage(page, vaddr);
|
|
|
|
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline void clear_highpage(struct page *page)
|
|
|
|
{
|
2021-11-06 04:45:06 +08:00
|
|
|
void *kaddr = kmap_local_page(page);
|
2005-04-17 06:20:36 +08:00
|
|
|
clear_page(kaddr);
|
2021-11-06 04:45:06 +08:00
|
|
|
kunmap_local(kaddr);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2022-06-10 02:18:46 +08:00
|
|
|
static inline void clear_highpage_kasan_tagged(struct page *page)
|
|
|
|
{
|
|
|
|
u8 tag;
|
|
|
|
|
|
|
|
tag = page_kasan_tag(page);
|
|
|
|
page_kasan_tag_reset(page);
|
|
|
|
clear_highpage(page);
|
|
|
|
page_kasan_tag_set(page, tag);
|
|
|
|
}
|
|
|
|
|
2021-06-03 07:52:29 +08:00
|
|
|
#ifndef __HAVE_ARCH_TAG_CLEAR_HIGHPAGE
|
|
|
|
|
|
|
|
static inline void tag_clear_highpage(struct page *page)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-12-15 11:12:59 +08: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.
|
|
|
|
*/
|
2021-11-05 22:19:05 +08:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
2020-12-15 11:12:59 +08:00
|
|
|
void zero_user_segments(struct page *page, unsigned start1, unsigned end1,
|
|
|
|
unsigned start2, unsigned end2);
|
2021-11-05 22:19:05 +08:00
|
|
|
#else
|
2008-02-05 14:28:29 +08:00
|
|
|
static inline void zero_user_segments(struct page *page,
|
2020-12-15 11:12:59 +08:00
|
|
|
unsigned start1, unsigned end1,
|
|
|
|
unsigned start2, unsigned end2)
|
2008-02-05 14:28:29 +08:00
|
|
|
{
|
2021-11-06 04:45:06 +08:00
|
|
|
void *kaddr = kmap_local_page(page);
|
2020-12-15 11:12:59 +08:00
|
|
|
unsigned int i;
|
2008-02-05 14:28:29 +08:00
|
|
|
|
2020-12-15 11:12:59 +08:00
|
|
|
BUG_ON(end1 > page_size(page) || end2 > page_size(page));
|
2008-02-05 14:28:29 +08:00
|
|
|
|
|
|
|
if (end1 > start1)
|
|
|
|
memset(kaddr + start1, 0, end1 - start1);
|
|
|
|
|
|
|
|
if (end2 > start2)
|
|
|
|
memset(kaddr + start2, 0, end2 - start2);
|
|
|
|
|
2021-11-06 04:45:06 +08:00
|
|
|
kunmap_local(kaddr);
|
2020-12-15 11:12:59 +08:00
|
|
|
for (i = 0; i < compound_nr(page); i++)
|
|
|
|
flush_dcache_page(page + i);
|
2008-02-05 14:28:29 +08:00
|
|
|
}
|
2021-11-05 22:19:05 +08:00
|
|
|
#endif
|
2008-02-05 14:28:29 +08: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 17:35:07 +08:00
|
|
|
|
2006-12-13 01:14:54 +08:00
|
|
|
#ifndef __HAVE_ARCH_COPY_USER_HIGHPAGE
|
|
|
|
|
2006-12-13 01:14:55 +08:00
|
|
|
static inline void copy_user_highpage(struct page *to, struct page *from,
|
|
|
|
unsigned long vaddr, struct vm_area_struct *vma)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
char *vfrom, *vto;
|
|
|
|
|
2021-11-06 04:45:06 +08:00
|
|
|
vfrom = kmap_local_page(from);
|
|
|
|
vto = kmap_local_page(to);
|
2005-04-17 06:20:36 +08:00
|
|
|
copy_user_page(vto, vfrom, vaddr, to);
|
2022-09-15 23:03:48 +08:00
|
|
|
kmsan_unpoison_memory(page_address(to), PAGE_SIZE);
|
2021-11-06 04:45:06 +08:00
|
|
|
kunmap_local(vto);
|
|
|
|
kunmap_local(vfrom);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-12-13 01:14:54 +08:00
|
|
|
#endif
|
|
|
|
|
mm, hwpoison: try to recover from copy-on write faults
Patch series "Copy-on-write poison recovery", v3.
Part 1 deals with the process that triggered the copy on write fault with
a store to a shared read-only page. That process is send a SIGBUS with
the usual machine check decoration to specify the virtual address of the
lost page, together with the scope.
Part 2 sets up to asynchronously take the page with the uncorrected error
offline to prevent additional machine check faults. H/t to Miaohe Lin
<linmiaohe@huawei.com> and Shuai Xue <xueshuai@linux.alibaba.com> for
pointing me to the existing function to queue a call to memory_failure().
On x86 there is some duplicate reporting (because the error is also
signalled by the memory controller as well as by the core that triggered
the machine check). Console logs look like this:
This patch (of 2):
If the kernel is copying a page as the result of a copy-on-write
fault and runs into an uncorrectable error, Linux will crash because
it does not have recovery code for this case where poison is consumed
by the kernel.
It is easy to set up a test case. Just inject an error into a private
page, fork(2), and have the child process write to the page.
I wrapped that neatly into a test at:
git://git.kernel.org/pub/scm/linux/kernel/git/aegl/ras-tools.git
just enable ACPI error injection and run:
# ./einj_mem-uc -f copy-on-write
Add a new copy_user_highpage_mc() function that uses copy_mc_to_kernel()
on architectures where that is available (currently x86 and powerpc).
When an error is detected during the page copy, return VM_FAULT_HWPOISON
to caller of wp_page_copy(). This propagates up the call stack. Both x86
and powerpc have code in their fault handler to deal with this code by
sending a SIGBUS to the application.
Note that this patch avoids a system crash and signals the process that
triggered the copy-on-write action. It does not take any action for the
memory error that is still in the shared page. To handle that a call to
memory_failure() is needed. But this cannot be done from wp_page_copy()
because it holds mmap_lock(). Perhaps the architecture fault handlers
can deal with this loose end in a subsequent patch?
On Intel/x86 this loose end will often be handled automatically because
the memory controller provides an additional notification of the h/w
poison in memory, the handler for this will call memory_failure(). This
isn't a 100% solution. If there are multiple errors, not all may be
logged in this way.
[tony.luck@intel.com: add call to kmsan_unpoison_memory(), per Miaohe Lin]
Link: https://lkml.kernel.org/r/20221031201029.102123-2-tony.luck@intel.com
Link: https://lkml.kernel.org/r/20221021200120.175753-1-tony.luck@intel.com
Link: https://lkml.kernel.org/r/20221021200120.175753-2-tony.luck@intel.com
Signed-off-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
Reviewed-by: Alexander Potapenko <glider@google.com>
Tested-by: Shuai Xue <xueshuai@linux.alibaba.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-10-22 04:01:19 +08:00
|
|
|
#ifdef copy_mc_to_kernel
|
|
|
|
static inline int copy_mc_user_highpage(struct page *to, struct page *from,
|
|
|
|
unsigned long vaddr, struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
unsigned long ret;
|
|
|
|
char *vfrom, *vto;
|
|
|
|
|
|
|
|
vfrom = kmap_local_page(from);
|
|
|
|
vto = kmap_local_page(to);
|
|
|
|
ret = copy_mc_to_kernel(vto, vfrom, PAGE_SIZE);
|
|
|
|
if (!ret)
|
|
|
|
kmsan_unpoison_memory(page_address(to), PAGE_SIZE);
|
|
|
|
kunmap_local(vto);
|
|
|
|
kunmap_local(vfrom);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline int copy_mc_user_highpage(struct page *to, struct page *from,
|
|
|
|
unsigned long vaddr, struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
copy_user_highpage(to, from, vaddr, vma);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-02-22 01:15:51 +08:00
|
|
|
#ifndef __HAVE_ARCH_COPY_HIGHPAGE
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static inline void copy_highpage(struct page *to, struct page *from)
|
|
|
|
{
|
|
|
|
char *vfrom, *vto;
|
|
|
|
|
2021-11-06 04:45:06 +08:00
|
|
|
vfrom = kmap_local_page(from);
|
|
|
|
vto = kmap_local_page(to);
|
2005-04-17 06:20:36 +08:00
|
|
|
copy_page(vto, vfrom);
|
2022-09-15 23:03:48 +08:00
|
|
|
kmsan_copy_page_meta(to, from);
|
2021-11-06 04:45:06 +08:00
|
|
|
kunmap_local(vto);
|
|
|
|
kunmap_local(vfrom);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-02-22 01:15:51 +08:00
|
|
|
#endif
|
|
|
|
|
2021-02-10 14:22:16 +08: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-11 01:49:28 +08:00
|
|
|
VM_BUG_ON(dst_off + len > PAGE_SIZE || src_off + len > PAGE_SIZE);
|
2021-02-10 14:22:16 +08:00
|
|
|
memcpy(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-11 01:49:28 +08:00
|
|
|
VM_BUG_ON(offset + len > PAGE_SIZE);
|
2021-02-10 14:22:16 +08: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 14:22:14 +08:00
|
|
|
static inline void memcpy_from_page(char *to, struct page *page,
|
|
|
|
size_t offset, size_t len)
|
|
|
|
{
|
2021-02-10 14:22:15 +08: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 14:22:14 +08:00
|
|
|
|
2021-02-11 01:49:28 +08: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 14:22:14 +08:00
|
|
|
memcpy(to, from + offset, len);
|
2021-02-10 14:22:15 +08: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 14:22:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void memcpy_to_page(struct page *page, size_t offset,
|
|
|
|
const char *from, size_t len)
|
|
|
|
{
|
2021-02-10 14:22:15 +08: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 14:22:14 +08:00
|
|
|
|
2021-02-11 01:49:28 +08: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 14:22:14 +08:00
|
|
|
memcpy(to + offset, from, len);
|
2021-07-24 06:50:17 +08:00
|
|
|
flush_dcache_page(page);
|
2021-02-10 14:22:15 +08: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 14:22:14 +08:00
|
|
|
}
|
|
|
|
|
2021-05-05 09:40:03 +08:00
|
|
|
static inline void memzero_page(struct page *page, size_t offset, size_t len)
|
|
|
|
{
|
2021-07-24 06:50:20 +08:00
|
|
|
char *addr = kmap_local_page(page);
|
2022-05-10 09:20:51 +08:00
|
|
|
|
|
|
|
VM_BUG_ON(offset + len > PAGE_SIZE);
|
2021-05-05 09:40:03 +08:00
|
|
|
memset(addr + offset, 0, len);
|
2021-07-24 06:50:17 +08:00
|
|
|
flush_dcache_page(page);
|
2021-07-24 06:50:20 +08:00
|
|
|
kunmap_local(addr);
|
2021-05-05 09:40:03 +08:00
|
|
|
}
|
|
|
|
|
2021-11-05 22:19:05 +08:00
|
|
|
/**
|
|
|
|
* folio_zero_segments() - Zero two byte ranges in a folio.
|
|
|
|
* @folio: The folio to write to.
|
|
|
|
* @start1: The first byte to zero.
|
|
|
|
* @xend1: One more than the last byte in the first range.
|
|
|
|
* @start2: The first byte to zero in the second range.
|
|
|
|
* @xend2: One more than the last byte in the second range.
|
|
|
|
*/
|
|
|
|
static inline void folio_zero_segments(struct folio *folio,
|
|
|
|
size_t start1, size_t xend1, size_t start2, size_t xend2)
|
|
|
|
{
|
|
|
|
zero_user_segments(&folio->page, start1, xend1, start2, xend2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* folio_zero_segment() - Zero a byte range in a folio.
|
|
|
|
* @folio: The folio to write to.
|
|
|
|
* @start: The first byte to zero.
|
|
|
|
* @xend: One more than the last byte to zero.
|
|
|
|
*/
|
|
|
|
static inline void folio_zero_segment(struct folio *folio,
|
|
|
|
size_t start, size_t xend)
|
|
|
|
{
|
|
|
|
zero_user_segments(&folio->page, start, xend, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* folio_zero_range() - Zero a byte range in a folio.
|
|
|
|
* @folio: The folio to write to.
|
|
|
|
* @start: The first byte to zero.
|
|
|
|
* @length: The number of bytes to zero.
|
|
|
|
*/
|
|
|
|
static inline void folio_zero_range(struct folio *folio,
|
|
|
|
size_t start, size_t length)
|
|
|
|
{
|
|
|
|
zero_user_segments(&folio->page, start, start + length, 0, 0);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif /* _LINUX_HIGHMEM_H */
|