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 14:07:57 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2005-04-16 22:20:36 +00:00
|
|
|
#ifndef _LINUX_HIGHMEM_H
|
|
|
|
#define _LINUX_HIGHMEM_H
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
2010-08-10 00:18:32 +00:00
|
|
|
#include <linux/kernel.h>
|
2011-11-24 01:12:59 +00:00
|
|
|
#include <linux/bug.h>
|
2021-11-06 21:13:35 +00:00
|
|
|
#include <linux/cacheflush.h>
|
2022-09-15 15:03:48 +00:00
|
|
|
#include <linux/kmsan.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/mm.h>
|
2006-12-07 04:32:21 +00:00
|
|
|
#include <linux/uaccess.h>
|
2010-11-11 22:05:10 +00:00
|
|
|
#include <linux/hardirq.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2020-11-03 09:27:34 +00:00
|
|
|
#include "highmem-internal.h"
|
2006-03-26 09:36:57 +00:00
|
|
|
|
2020-11-03 09:27:34 +00: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 09:27:18 +00:00
|
|
|
*/
|
2020-11-03 09:27:34 +00:00
|
|
|
static inline void *kmap(struct page *page);
|
2020-06-04 23:47:30 +00:00
|
|
|
|
2020-11-03 09:27:34 +00:00
|
|
|
/**
|
|
|
|
* kunmap - Unmap the virtual address mapped by kmap()
|
2022-05-13 23:48:55 +00:00
|
|
|
* @page: Pointer to the page which was mapped by kmap()
|
2020-11-03 09:27:34 +00:00
|
|
|
*
|
|
|
|
* Counterpart to kmap(). A NOOP for CONFIG_HIGHMEM=n and for mappings of
|
|
|
|
* pages in the low memory area.
|
2020-06-04 23:47:42 +00:00
|
|
|
*/
|
2020-11-03 09:27:34 +00:00
|
|
|
static inline void kunmap(struct page *page);
|
2020-11-03 09:27:18 +00:00
|
|
|
|
2020-11-03 09:27:34 +00: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-16 22:20:36 +00:00
|
|
|
|
2020-11-03 09:27:34 +00:00
|
|
|
/**
|
|
|
|
* kmap_flush_unused - Flush all unused kmap mappings in order to
|
|
|
|
* remove stray mappings
|
|
|
|
*/
|
|
|
|
static inline void kmap_flush_unused(void);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2020-11-03 09:27:34 +00:00
|
|
|
/**
|
2020-11-18 19:48:44 +00:00
|
|
|
* kmap_local_page - Map a page for temporary usage
|
2022-07-28 15:48:38 +00:00
|
|
|
* @page: Pointer to the page to be mapped
|
2020-11-03 09:27:34 +00:00
|
|
|
*
|
|
|
|
* Returns: The virtual address of the mapping
|
|
|
|
*
|
2022-07-28 15:48:39 +00:00
|
|
|
* Can be invoked from any context, including interrupts.
|
2020-11-03 09:27:34 +00: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-18 19:48:44 +00:00
|
|
|
* addr1 = kmap_local_page(page1);
|
|
|
|
* addr2 = kmap_local_page(page2);
|
2020-11-03 09:27:34 +00:00
|
|
|
* ...
|
2020-11-18 19:48:44 +00:00
|
|
|
* kunmap_local(addr2);
|
|
|
|
* kunmap_local(addr1);
|
2020-11-03 09:27:34 +00: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.
|
|
|
|
*
|
2023-01-05 12:13:05 +00:00
|
|
|
* While kmap_local_page() is significantly faster than kmap() for the highmem
|
|
|
|
* case it comes with restrictions about the pointer validity.
|
2020-11-18 19:48:44 +00: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 15:21:39 +00: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.
|
|
|
|
*
|
2023-01-05 12:04:24 +00:00
|
|
|
* While it is significantly faster than kmap() for the highmem case it
|
|
|
|
* comes with restrictions about the pointer validity.
|
2020-12-30 15:21:39 +00: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_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-18 19:48:44 +00: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-13 23:48:55 +00: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-18 19:48:44 +00:00
|
|
|
*
|
|
|
|
* Do not use in new code. Use kmap_local_page() instead.
|
2022-05-13 23:48:55 +00: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 08:45:46 +00:00
|
|
|
* can be used in a manner similar to the following::
|
2022-05-13 23:48:55 +00:00
|
|
|
*
|
2022-06-22 08:45:46 +00:00
|
|
|
* // Find the page of interest.
|
|
|
|
* struct page *page = find_get_page(mapping, offset);
|
2022-05-13 23:48:55 +00:00
|
|
|
*
|
2022-06-22 08:45:46 +00:00
|
|
|
* // Gain access to the contents of that page.
|
|
|
|
* void *vaddr = kmap_atomic(page);
|
2022-05-13 23:48:55 +00:00
|
|
|
*
|
2022-06-22 08:45:46 +00:00
|
|
|
* // Do something to the contents of that page.
|
|
|
|
* memset(vaddr, 0, PAGE_SIZE);
|
2022-05-13 23:48:55 +00:00
|
|
|
*
|
2022-06-22 08:45:46 +00:00
|
|
|
* // Unmap that page.
|
|
|
|
* kunmap_atomic(vaddr);
|
2022-05-13 23:48:55 +00: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 09:27:34 +00:00
|
|
|
*/
|
|
|
|
static inline void *kmap_atomic(struct page *page);
|
2012-07-31 23:45:02 +00:00
|
|
|
|
2020-11-03 09:27:34 +00:00
|
|
|
/* Highmem related interfaces for management code */
|
2024-06-07 08:37:11 +00:00
|
|
|
static inline unsigned long nr_free_highpages(void);
|
2020-11-03 09:27:34 +00:00
|
|
|
static inline unsigned long totalhigh_pages(void);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2020-11-03 09:27:34 +00: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-04 23:47:34 +00:00
|
|
|
{
|
|
|
|
}
|
2020-06-04 23:48:10 +00:00
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-09-02 21:56:36 +00:00
|
|
|
#ifndef ARCH_IMPLEMENTS_FLUSH_KERNEL_VMAP_RANGE
|
2020-11-03 09:27:34 +00:00
|
|
|
static inline void flush_kernel_vmap_range(void *vaddr, int size)
|
2020-11-03 09:27:18 +00:00
|
|
|
{
|
|
|
|
}
|
2020-11-03 09:27:34 +00:00
|
|
|
static inline void invalidate_kernel_vmap_range(void *vaddr, int size)
|
2020-11-03 09:27:18 +00:00
|
|
|
{
|
|
|
|
}
|
2020-06-04 23:48:10 +00:00
|
|
|
#endif
|
2011-11-25 14:08:45 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* when CONFIG_HIGHMEM is not set these will be plain clear/copy_page */
|
2008-11-27 11:13:58 +00:00
|
|
|
#ifndef clear_user_highpage
|
2005-04-16 22:20:36 +00:00
|
|
|
static inline void clear_user_highpage(struct page *page, unsigned long vaddr)
|
|
|
|
{
|
2021-11-05 20:45:06 +00:00
|
|
|
void *addr = kmap_local_page(page);
|
2005-04-16 22:20:36 +00:00
|
|
|
clear_user_page(addr, vaddr, page);
|
2021-11-05 20:45:06 +00:00
|
|
|
kunmap_local(addr);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-11-27 11:13:58 +00:00
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2023-01-16 19:18:09 +00:00
|
|
|
#ifndef vma_alloc_zeroed_movable_folio
|
2007-07-17 11:03:05 +00:00
|
|
|
/**
|
2023-01-16 19:18:09 +00:00
|
|
|
* vma_alloc_zeroed_movable_folio - Allocate a zeroed page for a VMA.
|
|
|
|
* @vma: The VMA the page is to be allocated for.
|
|
|
|
* @vaddr: The virtual address the page will be inserted into.
|
2007-07-17 11:03:05 +00:00
|
|
|
*
|
2023-01-16 19:18:09 +00:00
|
|
|
* This function will allocate a page suitable for inserting into this
|
|
|
|
* VMA at this virtual address. It may be allocated from highmem or
|
|
|
|
* the movable zone. An architecture may provide its own implementation.
|
2022-05-13 23:48:55 +00:00
|
|
|
*
|
2023-01-16 19:18:09 +00:00
|
|
|
* Return: A folio containing one allocated and zeroed page or NULL if
|
|
|
|
* we are out of memory.
|
2007-07-17 11:03:05 +00:00
|
|
|
*/
|
2023-01-16 19:18:09 +00:00
|
|
|
static inline
|
|
|
|
struct folio *vma_alloc_zeroed_movable_folio(struct vm_area_struct *vma,
|
2021-06-02 23:52:27 +00:00
|
|
|
unsigned long vaddr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2024-12-09 18:23:26 +00:00
|
|
|
struct folio *folio;
|
|
|
|
|
|
|
|
folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, vaddr);
|
|
|
|
if (folio && user_alloc_needs_zeroing())
|
|
|
|
clear_user_highpage(&folio->page, vaddr);
|
|
|
|
|
|
|
|
return folio;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline void clear_highpage(struct page *page)
|
|
|
|
{
|
2021-11-05 20:45:06 +00:00
|
|
|
void *kaddr = kmap_local_page(page);
|
2005-04-16 22:20:36 +00:00
|
|
|
clear_page(kaddr);
|
2021-11-05 20:45:06 +00:00
|
|
|
kunmap_local(kaddr);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2022-06-09 18:18:46 +00:00
|
|
|
static inline void clear_highpage_kasan_tagged(struct page *page)
|
|
|
|
{
|
2023-02-16 19:59:24 +00:00
|
|
|
void *kaddr = kmap_local_page(page);
|
2022-06-09 18:18:46 +00:00
|
|
|
|
2023-02-16 19:59:24 +00:00
|
|
|
clear_page(kasan_reset_tag(kaddr));
|
|
|
|
kunmap_local(kaddr);
|
2022-06-09 18:18:46 +00:00
|
|
|
}
|
|
|
|
|
2021-06-02 23:52:29 +00:00
|
|
|
#ifndef __HAVE_ARCH_TAG_CLEAR_HIGHPAGE
|
|
|
|
|
|
|
|
static inline void tag_clear_highpage(struct page *page)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-12-15 03:12:59 +00: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 14:19:05 +00:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
2020-12-15 03:12:59 +00:00
|
|
|
void zero_user_segments(struct page *page, unsigned start1, unsigned end1,
|
|
|
|
unsigned start2, unsigned end2);
|
2021-11-05 14:19:05 +00:00
|
|
|
#else
|
2008-02-05 06:28:29 +00:00
|
|
|
static inline void zero_user_segments(struct page *page,
|
2020-12-15 03:12:59 +00:00
|
|
|
unsigned start1, unsigned end1,
|
|
|
|
unsigned start2, unsigned end2)
|
2008-02-05 06:28:29 +00:00
|
|
|
{
|
2021-11-05 20:45:06 +00:00
|
|
|
void *kaddr = kmap_local_page(page);
|
2020-12-15 03:12:59 +00:00
|
|
|
unsigned int i;
|
2008-02-05 06:28:29 +00:00
|
|
|
|
2020-12-15 03:12:59 +00:00
|
|
|
BUG_ON(end1 > page_size(page) || end2 > page_size(page));
|
2008-02-05 06:28:29 +00:00
|
|
|
|
|
|
|
if (end1 > start1)
|
|
|
|
memset(kaddr + start1, 0, end1 - start1);
|
|
|
|
|
|
|
|
if (end2 > start2)
|
|
|
|
memset(kaddr + start2, 0, end2 - start2);
|
|
|
|
|
2021-11-05 20:45:06 +00:00
|
|
|
kunmap_local(kaddr);
|
2020-12-15 03:12:59 +00:00
|
|
|
for (i = 0; i < compound_nr(page); i++)
|
|
|
|
flush_dcache_page(page + i);
|
2008-02-05 06:28:29 +00:00
|
|
|
}
|
2021-11-05 14:19:05 +00:00
|
|
|
#endif
|
2008-02-05 06:28:29 +00: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 09:35:07 +00:00
|
|
|
|
2006-12-12 17:14:54 +00:00
|
|
|
#ifndef __HAVE_ARCH_COPY_USER_HIGHPAGE
|
|
|
|
|
2006-12-12 17:14:55 +00:00
|
|
|
static inline void copy_user_highpage(struct page *to, struct page *from,
|
|
|
|
unsigned long vaddr, struct vm_area_struct *vma)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
char *vfrom, *vto;
|
|
|
|
|
2021-11-05 20:45:06 +00:00
|
|
|
vfrom = kmap_local_page(from);
|
|
|
|
vto = kmap_local_page(to);
|
2005-04-16 22:20:36 +00:00
|
|
|
copy_user_page(vto, vfrom, vaddr, to);
|
2022-09-15 15:03:48 +00:00
|
|
|
kmsan_unpoison_memory(page_address(to), PAGE_SIZE);
|
2021-11-05 20:45:06 +00:00
|
|
|
kunmap_local(vto);
|
|
|
|
kunmap_local(vfrom);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-12-12 17:14:54 +00:00
|
|
|
#endif
|
|
|
|
|
2023-03-29 15:11:20 +00:00
|
|
|
#ifndef __HAVE_ARCH_COPY_HIGHPAGE
|
|
|
|
|
|
|
|
static inline void copy_highpage(struct page *to, struct page *from)
|
|
|
|
{
|
|
|
|
char *vfrom, *vto;
|
|
|
|
|
|
|
|
vfrom = kmap_local_page(from);
|
|
|
|
vto = kmap_local_page(to);
|
|
|
|
copy_page(vto, vfrom);
|
|
|
|
kmsan_copy_page_meta(to, from);
|
|
|
|
kunmap_local(vto);
|
|
|
|
kunmap_local(vfrom);
|
|
|
|
}
|
|
|
|
|
|
|
|
#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-21 20:01:19 +00:00
|
|
|
#ifdef copy_mc_to_kernel
|
2023-03-29 15:11:20 +00:00
|
|
|
/*
|
|
|
|
* If architecture supports machine check exception handling, define the
|
|
|
|
* #MC versions of copy_user_highpage and copy_highpage. They copy a memory
|
|
|
|
* page with #MC in source page (@from) handled, and return the number
|
|
|
|
* of bytes not copied if there was a #MC, otherwise 0 for success.
|
|
|
|
*/
|
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-21 20:01:19 +00:00
|
|
|
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);
|
|
|
|
|
mm: move memory_failure_queue() into copy_mc_[user]_highpage()
Patch series "mm: migrate: support poison recover from migrate folio", v5.
The folio migration is widely used in kernel, memory compaction, memory
hotplug, soft offline page, numa balance, memory demote/promotion, etc,
but once access a poisoned source folio when migrating, the kernel will
panic.
There is a mechanism in the kernel to recover from uncorrectable memory
errors, ARCH_HAS_COPY_MC(eg, Machine Check Safe Memory Copy on x86), which
is already used in NVDIMM or core-mm paths(eg, CoW, khugepaged, coredump,
ksm copy), see copy_mc_to_{user,kernel}, copy_mc_{user_}highpage callers.
This series of patches provide the recovery mechanism from folio copy for
the widely used folio migration. Please note, because folio migration is
no guarantee of success, so we could chose to make folio migration
tolerant of memory failures, adding folio_mc_copy() which is a #MC
versions of folio_copy(), once accessing a poisoned source folio, we could
return error and make the folio migration fail, and this could avoid the
similar panic shown below.
CPU: 1 PID: 88343 Comm: test_softofflin Kdump: loaded Not tainted 6.6.0
pc : copy_page+0x10/0xc0
lr : copy_highpage+0x38/0x50
...
Call trace:
copy_page+0x10/0xc0
folio_copy+0x78/0x90
migrate_folio_extra+0x54/0xa0
move_to_new_folio+0xd8/0x1f0
migrate_folio_move+0xb8/0x300
migrate_pages_batch+0x528/0x788
migrate_pages_sync+0x8c/0x258
migrate_pages+0x440/0x528
soft_offline_in_use_page+0x2ec/0x3c0
soft_offline_page+0x238/0x310
soft_offline_page_store+0x6c/0xc0
dev_attr_store+0x20/0x40
sysfs_kf_write+0x4c/0x68
kernfs_fop_write_iter+0x130/0x1c8
new_sync_write+0xa4/0x138
vfs_write+0x238/0x2d8
ksys_write+0x74/0x110
This patch (of 5):
There is a memory_failure_queue() call after copy_mc_[user]_highpage(),
see callers, eg, CoW/KSM page copy, it is used to mark the source page as
h/w poisoned and unmap it from other tasks, and the upcomming poison
recover from migrate folio will do the similar thing, so let's move the
memory_failure_queue() into the copy_mc_[user]_highpage() instead of
adding it into each user, this should also enhance the handling of
poisoned page in khugepaged.
Link: https://lkml.kernel.org/r/20240626085328.608006-1-wangkefeng.wang@huawei.com
Link: https://lkml.kernel.org/r/20240626085328.608006-2-wangkefeng.wang@huawei.com
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Reviewed-by: Jane Chu <jane.chu@oracle.com>
Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Benjamin LaHaise <bcrl@kvack.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: Jiaqi Yan <jiaqiyan@google.com>
Cc: Lance Yang <ioworker0@gmail.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Naoya Horiguchi <nao.horiguchi@gmail.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-06-26 08:53:23 +00:00
|
|
|
if (ret)
|
|
|
|
memory_failure_queue(page_to_pfn(from), 0);
|
|
|
|
|
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-21 20:01:19 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-03-29 15:11:20 +00:00
|
|
|
static inline int copy_mc_highpage(struct page *to, struct page *from)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2023-03-29 15:11:20 +00:00
|
|
|
unsigned long ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
char *vfrom, *vto;
|
|
|
|
|
2021-11-05 20:45:06 +00:00
|
|
|
vfrom = kmap_local_page(from);
|
|
|
|
vto = kmap_local_page(to);
|
2023-03-29 15:11:20 +00:00
|
|
|
ret = copy_mc_to_kernel(vto, vfrom, PAGE_SIZE);
|
|
|
|
if (!ret)
|
|
|
|
kmsan_copy_page_meta(to, from);
|
2021-11-05 20:45:06 +00:00
|
|
|
kunmap_local(vto);
|
|
|
|
kunmap_local(vfrom);
|
2023-03-29 15:11:20 +00:00
|
|
|
|
mm: move memory_failure_queue() into copy_mc_[user]_highpage()
Patch series "mm: migrate: support poison recover from migrate folio", v5.
The folio migration is widely used in kernel, memory compaction, memory
hotplug, soft offline page, numa balance, memory demote/promotion, etc,
but once access a poisoned source folio when migrating, the kernel will
panic.
There is a mechanism in the kernel to recover from uncorrectable memory
errors, ARCH_HAS_COPY_MC(eg, Machine Check Safe Memory Copy on x86), which
is already used in NVDIMM or core-mm paths(eg, CoW, khugepaged, coredump,
ksm copy), see copy_mc_to_{user,kernel}, copy_mc_{user_}highpage callers.
This series of patches provide the recovery mechanism from folio copy for
the widely used folio migration. Please note, because folio migration is
no guarantee of success, so we could chose to make folio migration
tolerant of memory failures, adding folio_mc_copy() which is a #MC
versions of folio_copy(), once accessing a poisoned source folio, we could
return error and make the folio migration fail, and this could avoid the
similar panic shown below.
CPU: 1 PID: 88343 Comm: test_softofflin Kdump: loaded Not tainted 6.6.0
pc : copy_page+0x10/0xc0
lr : copy_highpage+0x38/0x50
...
Call trace:
copy_page+0x10/0xc0
folio_copy+0x78/0x90
migrate_folio_extra+0x54/0xa0
move_to_new_folio+0xd8/0x1f0
migrate_folio_move+0xb8/0x300
migrate_pages_batch+0x528/0x788
migrate_pages_sync+0x8c/0x258
migrate_pages+0x440/0x528
soft_offline_in_use_page+0x2ec/0x3c0
soft_offline_page+0x238/0x310
soft_offline_page_store+0x6c/0xc0
dev_attr_store+0x20/0x40
sysfs_kf_write+0x4c/0x68
kernfs_fop_write_iter+0x130/0x1c8
new_sync_write+0xa4/0x138
vfs_write+0x238/0x2d8
ksys_write+0x74/0x110
This patch (of 5):
There is a memory_failure_queue() call after copy_mc_[user]_highpage(),
see callers, eg, CoW/KSM page copy, it is used to mark the source page as
h/w poisoned and unmap it from other tasks, and the upcomming poison
recover from migrate folio will do the similar thing, so let's move the
memory_failure_queue() into the copy_mc_[user]_highpage() instead of
adding it into each user, this should also enhance the handling of
poisoned page in khugepaged.
Link: https://lkml.kernel.org/r/20240626085328.608006-1-wangkefeng.wang@huawei.com
Link: https://lkml.kernel.org/r/20240626085328.608006-2-wangkefeng.wang@huawei.com
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Reviewed-by: Jane Chu <jane.chu@oracle.com>
Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Benjamin LaHaise <bcrl@kvack.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: Jiaqi Yan <jiaqiyan@google.com>
Cc: Lance Yang <ioworker0@gmail.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Naoya Horiguchi <nao.horiguchi@gmail.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-06-26 08:53:23 +00:00
|
|
|
if (ret)
|
|
|
|
memory_failure_queue(page_to_pfn(from), 0);
|
|
|
|
|
2023-03-29 15:11:20 +00:00
|
|
|
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;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2023-03-29 15:11:20 +00:00
|
|
|
static inline int copy_mc_highpage(struct page *to, struct page *from)
|
|
|
|
{
|
|
|
|
copy_highpage(to, from);
|
|
|
|
return 0;
|
|
|
|
}
|
2018-02-21 17:15:51 +00:00
|
|
|
#endif
|
|
|
|
|
2021-02-10 06:22:16 +00: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 17:49:28 +00:00
|
|
|
VM_BUG_ON(dst_off + len > PAGE_SIZE || src_off + len > PAGE_SIZE);
|
2021-02-10 06:22:16 +00: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-10 17:49:28 +00:00
|
|
|
VM_BUG_ON(offset + len > PAGE_SIZE);
|
2021-02-10 06:22:16 +00: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 06:22:14 +00:00
|
|
|
static inline void memcpy_from_page(char *to, struct page *page,
|
|
|
|
size_t offset, size_t len)
|
|
|
|
{
|
2021-02-10 06:22:15 +00: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 06:22:14 +00:00
|
|
|
|
2021-02-10 17:49:28 +00: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 06:22:14 +00:00
|
|
|
memcpy(to, from + offset, len);
|
2021-02-10 06:22:15 +00: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 06:22:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void memcpy_to_page(struct page *page, size_t offset,
|
|
|
|
const char *from, size_t len)
|
|
|
|
{
|
2021-02-10 06:22:15 +00: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 06:22:14 +00:00
|
|
|
|
2021-02-10 17:49:28 +00: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 06:22:14 +00:00
|
|
|
memcpy(to + offset, from, len);
|
2021-07-23 22:50:17 +00:00
|
|
|
flush_dcache_page(page);
|
2021-02-10 06:22:15 +00: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 06:22:14 +00:00
|
|
|
}
|
|
|
|
|
2021-05-05 01:40:03 +00:00
|
|
|
static inline void memzero_page(struct page *page, size_t offset, size_t len)
|
|
|
|
{
|
2021-07-23 22:50:20 +00:00
|
|
|
char *addr = kmap_local_page(page);
|
2022-05-10 01:20:51 +00:00
|
|
|
|
|
|
|
VM_BUG_ON(offset + len > PAGE_SIZE);
|
2021-05-05 01:40:03 +00:00
|
|
|
memset(addr + offset, 0, len);
|
2021-07-23 22:50:17 +00:00
|
|
|
flush_dcache_page(page);
|
2021-07-23 22:50:20 +00:00
|
|
|
kunmap_local(addr);
|
2021-05-05 01:40:03 +00:00
|
|
|
}
|
|
|
|
|
2024-01-24 18:12:15 +00:00
|
|
|
/**
|
|
|
|
* memcpy_from_folio - Copy a range of bytes from a folio.
|
|
|
|
* @to: The memory to copy to.
|
|
|
|
* @folio: The folio to read from.
|
|
|
|
* @offset: The first byte in the folio to read.
|
|
|
|
* @len: The number of bytes to copy.
|
|
|
|
*/
|
2023-07-13 03:55:06 +00:00
|
|
|
static inline void memcpy_from_folio(char *to, struct folio *folio,
|
|
|
|
size_t offset, size_t len)
|
|
|
|
{
|
|
|
|
VM_BUG_ON(offset + len > folio_size(folio));
|
|
|
|
|
|
|
|
do {
|
|
|
|
const char *from = kmap_local_folio(folio, offset);
|
|
|
|
size_t chunk = len;
|
|
|
|
|
|
|
|
if (folio_test_highmem(folio) &&
|
|
|
|
chunk > PAGE_SIZE - offset_in_page(offset))
|
|
|
|
chunk = PAGE_SIZE - offset_in_page(offset);
|
|
|
|
memcpy(to, from, chunk);
|
|
|
|
kunmap_local(from);
|
|
|
|
|
2023-11-30 03:40:18 +00:00
|
|
|
to += chunk;
|
2023-07-13 03:55:06 +00:00
|
|
|
offset += chunk;
|
|
|
|
len -= chunk;
|
|
|
|
} while (len > 0);
|
|
|
|
}
|
|
|
|
|
2024-01-24 18:12:15 +00:00
|
|
|
/**
|
|
|
|
* memcpy_to_folio - Copy a range of bytes to a folio.
|
|
|
|
* @folio: The folio to write to.
|
|
|
|
* @offset: The first byte in the folio to store to.
|
|
|
|
* @from: The memory to copy from.
|
|
|
|
* @len: The number of bytes to copy.
|
|
|
|
*/
|
2023-07-13 03:55:06 +00:00
|
|
|
static inline void memcpy_to_folio(struct folio *folio, size_t offset,
|
|
|
|
const char *from, size_t len)
|
|
|
|
{
|
|
|
|
VM_BUG_ON(offset + len > folio_size(folio));
|
|
|
|
|
|
|
|
do {
|
|
|
|
char *to = kmap_local_folio(folio, offset);
|
|
|
|
size_t chunk = len;
|
|
|
|
|
|
|
|
if (folio_test_highmem(folio) &&
|
|
|
|
chunk > PAGE_SIZE - offset_in_page(offset))
|
|
|
|
chunk = PAGE_SIZE - offset_in_page(offset);
|
|
|
|
memcpy(to, from, chunk);
|
|
|
|
kunmap_local(to);
|
|
|
|
|
|
|
|
from += chunk;
|
|
|
|
offset += chunk;
|
|
|
|
len -= chunk;
|
|
|
|
} while (len > 0);
|
|
|
|
|
|
|
|
flush_dcache_folio(folio);
|
|
|
|
}
|
|
|
|
|
2023-11-07 21:26:40 +00:00
|
|
|
/**
|
|
|
|
* folio_zero_tail - Zero the tail of a folio.
|
|
|
|
* @folio: The folio to zero.
|
|
|
|
* @offset: The byte offset in the folio to start zeroing at.
|
|
|
|
* @kaddr: The address the folio is currently mapped to.
|
|
|
|
*
|
|
|
|
* If you have already used kmap_local_folio() to map a folio, written
|
|
|
|
* some data to it and now need to zero the end of the folio (and flush
|
|
|
|
* the dcache), you can use this function. If you do not have the
|
|
|
|
* folio kmapped (eg the folio has been partially populated by DMA),
|
|
|
|
* use folio_zero_range() or folio_zero_segment() instead.
|
|
|
|
*
|
|
|
|
* Return: An address which can be passed to kunmap_local().
|
|
|
|
*/
|
|
|
|
static inline __must_check void *folio_zero_tail(struct folio *folio,
|
|
|
|
size_t offset, void *kaddr)
|
|
|
|
{
|
|
|
|
size_t len = folio_size(folio) - offset;
|
|
|
|
|
|
|
|
if (folio_test_highmem(folio)) {
|
|
|
|
size_t max = PAGE_SIZE - offset_in_page(offset);
|
|
|
|
|
|
|
|
while (len > max) {
|
|
|
|
memset(kaddr, 0, max);
|
|
|
|
kunmap_local(kaddr);
|
|
|
|
len -= max;
|
|
|
|
offset += max;
|
|
|
|
max = PAGE_SIZE;
|
|
|
|
kaddr = kmap_local_folio(folio, offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(kaddr, 0, len);
|
|
|
|
flush_dcache_folio(folio);
|
|
|
|
|
|
|
|
return kaddr;
|
|
|
|
}
|
|
|
|
|
2023-11-07 21:26:41 +00:00
|
|
|
/**
|
|
|
|
* folio_fill_tail - Copy some data to a folio and pad with zeroes.
|
|
|
|
* @folio: The destination folio.
|
|
|
|
* @offset: The offset into @folio at which to start copying.
|
|
|
|
* @from: The data to copy.
|
|
|
|
* @len: How many bytes of data to copy.
|
|
|
|
*
|
|
|
|
* This function is most useful for filesystems which support inline data.
|
|
|
|
* When they want to copy data from the inode into the page cache, this
|
|
|
|
* function does everything for them. It supports large folios even on
|
|
|
|
* HIGHMEM configurations.
|
|
|
|
*/
|
|
|
|
static inline void folio_fill_tail(struct folio *folio, size_t offset,
|
|
|
|
const char *from, size_t len)
|
|
|
|
{
|
|
|
|
char *to = kmap_local_folio(folio, offset);
|
|
|
|
|
|
|
|
VM_BUG_ON(offset + len > folio_size(folio));
|
|
|
|
|
|
|
|
if (folio_test_highmem(folio)) {
|
|
|
|
size_t max = PAGE_SIZE - offset_in_page(offset);
|
|
|
|
|
|
|
|
while (len > max) {
|
|
|
|
memcpy(to, from, max);
|
|
|
|
kunmap_local(to);
|
|
|
|
len -= max;
|
|
|
|
from += max;
|
|
|
|
offset += max;
|
|
|
|
max = PAGE_SIZE;
|
|
|
|
to = kmap_local_folio(folio, offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(to, from, len);
|
|
|
|
to = folio_zero_tail(folio, offset + len, to + len);
|
|
|
|
kunmap_local(to);
|
|
|
|
}
|
|
|
|
|
2023-01-26 20:15:52 +00:00
|
|
|
/**
|
|
|
|
* memcpy_from_file_folio - Copy some bytes from a file folio.
|
|
|
|
* @to: The destination buffer.
|
|
|
|
* @folio: The folio to copy from.
|
|
|
|
* @pos: The position in the file.
|
|
|
|
* @len: The maximum number of bytes to copy.
|
|
|
|
*
|
|
|
|
* Copy up to @len bytes from this folio. This may be limited by PAGE_SIZE
|
|
|
|
* if the folio comes from HIGHMEM, and by the size of the folio.
|
|
|
|
*
|
|
|
|
* Return: The number of bytes copied from the folio.
|
|
|
|
*/
|
|
|
|
static inline size_t memcpy_from_file_folio(char *to, struct folio *folio,
|
|
|
|
loff_t pos, size_t len)
|
|
|
|
{
|
|
|
|
size_t offset = offset_in_folio(folio, pos);
|
|
|
|
char *from = kmap_local_folio(folio, offset);
|
|
|
|
|
2023-02-03 21:28:40 +00:00
|
|
|
if (folio_test_highmem(folio)) {
|
|
|
|
offset = offset_in_page(offset);
|
2023-01-26 20:15:52 +00:00
|
|
|
len = min_t(size_t, len, PAGE_SIZE - offset);
|
2023-02-03 21:28:40 +00:00
|
|
|
} else
|
2023-01-26 20:15:52 +00:00
|
|
|
len = min(len, folio_size(folio) - offset);
|
|
|
|
|
|
|
|
memcpy(to, from, len);
|
|
|
|
kunmap_local(from);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2021-11-05 14:19:05 +00: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);
|
|
|
|
}
|
|
|
|
|
2023-09-21 20:07:38 +00:00
|
|
|
/**
|
|
|
|
* folio_release_kmap - Unmap a folio and drop a refcount.
|
|
|
|
* @folio: The folio to release.
|
|
|
|
* @addr: The address previously returned by a call to kmap_local_folio().
|
|
|
|
*
|
|
|
|
* It is common, eg in directory handling to kmap a folio. This function
|
|
|
|
* unmaps the folio and drops the refcount that was being held to keep the
|
|
|
|
* folio alive while we accessed it.
|
|
|
|
*/
|
|
|
|
static inline void folio_release_kmap(struct folio *folio, void *addr)
|
2023-03-07 06:50:53 +00:00
|
|
|
{
|
|
|
|
kunmap_local(addr);
|
2023-09-21 20:07:38 +00:00
|
|
|
folio_put(folio);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void unmap_and_put_page(struct page *page, void *addr)
|
|
|
|
{
|
|
|
|
folio_release_kmap(page_folio(page), addr);
|
2023-03-07 06:50:53 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /* _LINUX_HIGHMEM_H */
|