License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 17:07:57 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* S390 version
|
2012-07-20 13:15:04 +04:00
|
|
|
* Copyright IBM Corp. 1999
|
2005-04-17 02:20:36 +04:00
|
|
|
* Author(s): Hartmut Penner (hp@de.ibm.com)
|
|
|
|
*
|
|
|
|
* Derived from "arch/i386/mm/init.c"
|
|
|
|
* Copyright (C) 1995 Linus Torvalds
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/signal.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/mman.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/swap.h>
|
2018-09-13 19:57:16 +03:00
|
|
|
#include <linux/swiotlb.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/pagemap.h>
|
2018-10-31 01:09:49 +03:00
|
|
|
#include <linux/memblock.h>
|
2013-05-02 11:15:58 +04:00
|
|
|
#include <linux/memory.h>
|
2006-07-01 15:36:31 +04:00
|
|
|
#include <linux/pfn.h>
|
2006-12-08 17:56:13 +03:00
|
|
|
#include <linux/poison.h>
|
2007-02-05 23:16:47 +03:00
|
|
|
#include <linux/initrd.h>
|
2011-07-30 11:25:15 +04:00
|
|
|
#include <linux/export.h>
|
2017-08-07 16:16:15 +03:00
|
|
|
#include <linux/cma.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/gfp.h>
|
2019-07-10 22:01:19 +03:00
|
|
|
#include <linux/dma-direct.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <asm/processor.h>
|
2016-12-24 22:46:01 +03:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <asm/pgalloc.h>
|
2020-09-09 18:10:29 +03:00
|
|
|
#include <asm/ptdump.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <asm/dma.h>
|
|
|
|
#include <asm/lowcore.h>
|
|
|
|
#include <asm/tlb.h>
|
|
|
|
#include <asm/tlbflush.h>
|
2006-07-01 15:36:31 +04:00
|
|
|
#include <asm/sections.h>
|
2012-03-28 21:30:02 +04:00
|
|
|
#include <asm/ctl_reg.h>
|
2013-05-02 11:15:58 +04:00
|
|
|
#include <asm/sclp.h>
|
2017-05-09 01:58:08 +03:00
|
|
|
#include <asm/set_memory.h>
|
2017-11-17 16:29:13 +03:00
|
|
|
#include <asm/kasan.h>
|
2018-09-13 19:57:16 +03:00
|
|
|
#include <asm/dma-mapping.h>
|
|
|
|
#include <asm/uv.h>
|
2020-09-10 11:53:50 +03:00
|
|
|
#include <linux/virtio_config.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-10-22 05:36:07 +03:00
|
|
|
pgd_t swapper_pg_dir[PTRS_PER_PGD] __section(".bss..swapper_pg_dir");
|
2020-11-16 10:06:41 +03:00
|
|
|
static pgd_t invalid_pg_dir[PTRS_PER_PGD] __section(".bss..invalid_pg_dir");
|
|
|
|
|
|
|
|
unsigned long s390_invalid_asce;
|
2009-03-26 17:24:04 +03:00
|
|
|
|
2010-10-25 18:10:07 +04:00
|
|
|
unsigned long empty_zero_page, zero_page_mask;
|
2009-03-26 17:24:04 +03:00
|
|
|
EXPORT_SYMBOL(empty_zero_page);
|
2014-09-13 00:17:23 +04:00
|
|
|
EXPORT_SYMBOL(zero_page_mask);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
locking/lockdep: check for freed initmem in static_obj()
The following warning occurred on s390:
WARNING: CPU: 0 PID: 804 at kernel/locking/lockdep.c:1025 lockdep_register_key+0x30/0x150
This is because the check in static_obj() assumes that all memory within
[_stext, _end] belongs to static objects, which at least for s390 isn't
true. The init section is also part of this range, and freeing it allows
the buddy allocator to allocate memory from it. We have virt == phys for
the kernel on s390, so that such allocations would then have addresses
within the range [_stext, _end].
To fix this, introduce arch_is_kernel_initmem_freed(), similar to
arch_is_kernel_text/data(), and add it to the checks in static_obj().
This will always return 0 on architectures that do not define
arch_is_kernel_initmem_freed. On s390, it will return 1 if initmem has
been freed and the address is in the range [__init_begin, __init_end].
Signed-off-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Reviewed-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2019-04-18 17:24:50 +03:00
|
|
|
bool initmem_freed;
|
|
|
|
|
2013-04-30 02:06:48 +04:00
|
|
|
static void __init setup_zero_pages(void)
|
2010-10-25 18:10:07 +04:00
|
|
|
{
|
|
|
|
unsigned int order;
|
|
|
|
struct page *page;
|
|
|
|
int i;
|
|
|
|
|
2015-11-10 14:30:28 +03:00
|
|
|
/* Latest machines require a mapping granularity of 512KB */
|
|
|
|
order = 7;
|
|
|
|
|
2013-02-28 14:08:54 +04:00
|
|
|
/* Limit number of empty zero pages for small memory sizes */
|
2018-12-28 11:34:29 +03:00
|
|
|
while (order > 2 && (totalram_pages() >> 10) < (1UL << order))
|
2015-01-14 19:51:17 +03:00
|
|
|
order--;
|
2010-10-25 18:10:07 +04:00
|
|
|
|
|
|
|
empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
|
|
|
|
if (!empty_zero_page)
|
|
|
|
panic("Out of memory in setup_zero_pages");
|
|
|
|
|
|
|
|
page = virt_to_page((void *) empty_zero_page);
|
|
|
|
split_page(page, order);
|
|
|
|
for (i = 1 << order; i > 0; i--) {
|
2013-04-30 02:06:48 +04:00
|
|
|
mark_page_reserved(page);
|
2010-10-25 18:10:07 +04:00
|
|
|
page++;
|
|
|
|
}
|
|
|
|
|
2013-04-30 02:06:48 +04:00
|
|
|
zero_page_mask = ((PAGE_SIZE << order) - 1) & PAGE_MASK;
|
2010-10-25 18:10:07 +04:00
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* paging_init() sets up the page tables
|
|
|
|
*/
|
|
|
|
void __init paging_init(void)
|
|
|
|
{
|
2006-12-08 17:56:10 +03:00
|
|
|
unsigned long max_zone_pfns[MAX_NR_ZONES];
|
2011-12-27 14:27:07 +04:00
|
|
|
unsigned long pgd_type, asce_bits;
|
2017-06-01 12:04:04 +03:00
|
|
|
psw_t psw;
|
2006-07-01 15:36:31 +04:00
|
|
|
|
2020-11-16 10:06:41 +03:00
|
|
|
s390_invalid_asce = (unsigned long)invalid_pg_dir;
|
|
|
|
s390_invalid_asce |= _ASCE_TYPE_REGION3 | _ASCE_TABLE_LENGTH;
|
|
|
|
crst_table_init((unsigned long *)invalid_pg_dir, _REGION3_ENTRY_EMPTY);
|
2007-10-22 14:52:47 +04:00
|
|
|
init_mm.pgd = swapper_pg_dir;
|
2017-07-05 08:37:27 +03:00
|
|
|
if (VMALLOC_END > _REGION2_SIZE) {
|
2011-12-27 14:27:07 +04:00
|
|
|
asce_bits = _ASCE_TYPE_REGION2 | _ASCE_TABLE_LENGTH;
|
|
|
|
pgd_type = _REGION2_ENTRY_EMPTY;
|
|
|
|
} else {
|
|
|
|
asce_bits = _ASCE_TYPE_REGION3 | _ASCE_TABLE_LENGTH;
|
|
|
|
pgd_type = _REGION3_ENTRY_EMPTY;
|
|
|
|
}
|
s390/mm: fix asce_bits handling with dynamic pagetable levels
There is a race with multi-threaded applications between context switch and
pagetable upgrade. In switch_mm() a new user_asce is built from mm->pgd and
mm->context.asce_bits, w/o holding any locks. A concurrent mmap with a
pagetable upgrade on another thread in crst_table_upgrade() could already
have set new asce_bits, but not yet the new mm->pgd. This would result in a
corrupt user_asce in switch_mm(), and eventually in a kernel panic from a
translation exception.
Fix this by storing the complete asce instead of just the asce_bits, which
can then be read atomically from switch_mm(), so that it either sees the
old value or the new value, but no mixture. Both cases are OK. Having the
old value would result in a page fault on access to the higher level memory,
but the fault handler would see the new mm->pgd, if it was a valid access
after the mmap on the other thread has completed. So as worst-case scenario
we would have a page fault loop for the racing thread until the next time
slice.
Also remove dead code and simplify the upgrade/downgrade path, there are no
upgrades from 2 levels, and only downgrades from 3 levels for compat tasks.
There are also no concurrent upgrades, because the mmap_sem is held with
down_write() in do_mmap, so the flush and table checks during upgrade can
be removed.
Reported-by: Michael Munday <munday@ca.ibm.com>
Reviewed-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2016-04-15 17:38:40 +03:00
|
|
|
init_mm.context.asce = (__pa(init_mm.pgd) & PAGE_MASK) | asce_bits;
|
|
|
|
S390_lowcore.kernel_asce = init_mm.context.asce;
|
2020-11-16 10:06:41 +03:00
|
|
|
S390_lowcore.user_asce = s390_invalid_asce;
|
2017-07-05 08:37:27 +03:00
|
|
|
crst_table_init((unsigned long *) init_mm.pgd, pgd_type);
|
2006-12-08 17:56:07 +03:00
|
|
|
vmem_map_init();
|
2020-10-05 11:28:48 +03:00
|
|
|
kasan_copy_shadow_mapping();
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2017-11-17 16:29:13 +03:00
|
|
|
/* enable virtual mapping in kernel mode */
|
2007-10-22 14:52:47 +04:00
|
|
|
__ctl_load(S390_lowcore.kernel_asce, 1, 1);
|
2020-11-16 10:06:41 +03:00
|
|
|
__ctl_load(S390_lowcore.user_asce, 7, 7);
|
2007-10-22 14:52:47 +04:00
|
|
|
__ctl_load(S390_lowcore.kernel_asce, 13, 13);
|
2017-06-01 12:04:04 +03:00
|
|
|
psw.mask = __extract_psw();
|
2017-06-03 11:56:07 +03:00
|
|
|
psw_bits(psw).dat = 1;
|
2017-06-03 11:19:55 +03:00
|
|
|
psw_bits(psw).as = PSW_BITS_AS_HOME;
|
2017-06-01 12:04:04 +03:00
|
|
|
__load_psw_mask(psw.mask);
|
2017-11-20 14:56:10 +03:00
|
|
|
kasan_free_early_identity();
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-04-30 15:38:47 +04:00
|
|
|
sparse_init();
|
2019-10-14 21:31:03 +03:00
|
|
|
zone_dma_bits = 31;
|
2006-12-08 17:56:10 +03:00
|
|
|
memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
|
|
|
|
max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS);
|
|
|
|
max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
|
2020-06-04 01:57:10 +03:00
|
|
|
free_area_init(max_zone_pfns);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2016-03-17 14:47:12 +03:00
|
|
|
void mark_rodata_ro(void)
|
|
|
|
{
|
2016-06-07 11:12:55 +03:00
|
|
|
unsigned long size = __end_ro_after_init - __start_ro_after_init;
|
|
|
|
|
|
|
|
set_memory_ro((unsigned long)__start_ro_after_init, size >> PAGE_SHIFT);
|
|
|
|
pr_info("Write protected read-only-after-init data: %luk\n", size >> 10);
|
2020-09-09 18:10:29 +03:00
|
|
|
debug_checkwx();
|
2016-03-17 14:47:12 +03:00
|
|
|
}
|
|
|
|
|
2018-09-13 19:57:16 +03:00
|
|
|
int set_memory_encrypted(unsigned long addr, int numpages)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* make specified pages unshared, (swiotlb, dma_free) */
|
|
|
|
for (i = 0; i < numpages; ++i) {
|
|
|
|
uv_remove_shared(addr);
|
|
|
|
addr += PAGE_SIZE;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int set_memory_decrypted(unsigned long addr, int numpages)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
/* make specified pages shared (swiotlb, dma_alloca) */
|
|
|
|
for (i = 0; i < numpages; ++i) {
|
|
|
|
uv_set_shared(addr);
|
|
|
|
addr += PAGE_SIZE;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* are we a protected virtualization guest? */
|
2019-07-10 22:01:19 +03:00
|
|
|
bool force_dma_unencrypted(struct device *dev)
|
|
|
|
{
|
2019-08-06 07:49:19 +03:00
|
|
|
return is_prot_virt_guest();
|
2019-07-10 22:01:19 +03:00
|
|
|
}
|
|
|
|
|
2020-09-10 11:53:50 +03:00
|
|
|
#ifdef CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
|
|
|
|
|
|
|
|
int arch_has_restricted_virtio_memory_access(void)
|
|
|
|
{
|
|
|
|
return is_prot_virt_guest();
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(arch_has_restricted_virtio_memory_access);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-09-13 19:57:16 +03:00
|
|
|
/* protected virtualization */
|
|
|
|
static void pv_init(void)
|
|
|
|
{
|
|
|
|
if (!is_prot_virt_guest())
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* make sure bounce buffers are shared */
|
|
|
|
swiotlb_init(1);
|
|
|
|
swiotlb_update_mem_attributes();
|
|
|
|
swiotlb_force = SWIOTLB_FORCE;
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
void __init mem_init(void)
|
|
|
|
{
|
2016-05-25 10:45:26 +03:00
|
|
|
cpumask_set_cpu(0, &init_mm.context.cpu_attach_mask);
|
2014-04-03 15:55:01 +04:00
|
|
|
cpumask_set_cpu(0, mm_cpumask(&init_mm));
|
|
|
|
|
2014-03-06 21:25:13 +04:00
|
|
|
set_max_mapnr(max_low_pfn);
|
2005-04-17 02:20:36 +04:00
|
|
|
high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
|
|
|
|
|
2018-09-13 19:57:16 +03:00
|
|
|
pv_init();
|
|
|
|
|
2008-05-07 11:22:59 +04:00
|
|
|
/* Setup guest page hinting */
|
|
|
|
cmma_init();
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* this will put all low memory onto the freelists */
|
2018-10-31 01:09:30 +03:00
|
|
|
memblock_free_all();
|
2013-04-30 02:06:48 +04:00
|
|
|
setup_zero_pages(); /* Setup zeroed pages. */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2016-06-14 13:56:01 +03:00
|
|
|
cmma_init_nodat();
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2010-02-27 00:37:42 +03:00
|
|
|
void free_initmem(void)
|
|
|
|
{
|
locking/lockdep: check for freed initmem in static_obj()
The following warning occurred on s390:
WARNING: CPU: 0 PID: 804 at kernel/locking/lockdep.c:1025 lockdep_register_key+0x30/0x150
This is because the check in static_obj() assumes that all memory within
[_stext, _end] belongs to static objects, which at least for s390 isn't
true. The init section is also part of this range, and freeing it allows
the buddy allocator to allocate memory from it. We have virt == phys for
the kernel on s390, so that such allocations would then have addresses
within the range [_stext, _end].
To fix this, introduce arch_is_kernel_initmem_freed(), similar to
arch_is_kernel_text/data(), and add it to the checks in static_obj().
This will always return 0 on architectures that do not define
arch_is_kernel_initmem_freed. On s390, it will return 1 if initmem has
been freed and the address is in the range [__init_begin, __init_end].
Signed-off-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Reviewed-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2019-04-18 17:24:50 +03:00
|
|
|
initmem_freed = true;
|
2017-11-08 13:18:29 +03:00
|
|
|
__set_memory((unsigned long)_sinittext,
|
|
|
|
(unsigned long)(_einittext - _sinittext) >> PAGE_SHIFT,
|
2016-03-22 12:54:24 +03:00
|
|
|
SET_MEMORY_RW | SET_MEMORY_NX);
|
2013-07-04 02:02:51 +04:00
|
|
|
free_initmem_default(POISON_FREE_INITMEM);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2017-02-13 16:58:36 +03:00
|
|
|
unsigned long memory_block_size_bytes(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Make sure the memory block size is always greater
|
|
|
|
* or equal than the memory increment size.
|
|
|
|
*/
|
|
|
|
return max_t(unsigned long, MIN_MEMORY_BLOCK_SIZE, sclp.rzm);
|
|
|
|
}
|
|
|
|
|
2008-07-14 11:59:18 +04:00
|
|
|
#ifdef CONFIG_MEMORY_HOTPLUG
|
2017-08-07 16:16:15 +03:00
|
|
|
|
|
|
|
#ifdef CONFIG_CMA
|
|
|
|
|
|
|
|
/* Prevent memory blocks which contain cma regions from going offline */
|
|
|
|
|
|
|
|
struct s390_cma_mem_data {
|
|
|
|
unsigned long start;
|
|
|
|
unsigned long end;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int s390_cma_check_range(struct cma *cma, void *data)
|
|
|
|
{
|
|
|
|
struct s390_cma_mem_data *mem_data;
|
|
|
|
unsigned long start, end;
|
|
|
|
|
|
|
|
mem_data = data;
|
|
|
|
start = cma_get_base(cma);
|
|
|
|
end = start + cma_get_size(cma);
|
|
|
|
if (end < mem_data->start)
|
|
|
|
return 0;
|
|
|
|
if (start >= mem_data->end)
|
|
|
|
return 0;
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int s390_cma_mem_notifier(struct notifier_block *nb,
|
|
|
|
unsigned long action, void *data)
|
|
|
|
{
|
|
|
|
struct s390_cma_mem_data mem_data;
|
|
|
|
struct memory_notify *arg;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
arg = data;
|
|
|
|
mem_data.start = arg->start_pfn << PAGE_SHIFT;
|
|
|
|
mem_data.end = mem_data.start + (arg->nr_pages << PAGE_SHIFT);
|
|
|
|
if (action == MEM_GOING_OFFLINE)
|
|
|
|
rc = cma_for_each_area(s390_cma_check_range, &mem_data);
|
|
|
|
return notifier_from_errno(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct notifier_block s390_cma_mem_nb = {
|
|
|
|
.notifier_call = s390_cma_mem_notifier,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init s390_cma_mem_init(void)
|
|
|
|
{
|
|
|
|
return register_memory_notifier(&s390_cma_mem_nb);
|
|
|
|
}
|
|
|
|
device_initcall(s390_cma_mem_init);
|
|
|
|
|
|
|
|
#endif /* CONFIG_CMA */
|
|
|
|
|
2019-05-14 03:21:26 +03:00
|
|
|
int arch_add_memory(int nid, u64 start, u64 size,
|
2020-04-11 00:33:21 +03:00
|
|
|
struct mhp_params *params)
|
2008-07-14 11:59:18 +04:00
|
|
|
{
|
2012-02-24 21:01:29 +04:00
|
|
|
unsigned long start_pfn = PFN_DOWN(start);
|
|
|
|
unsigned long size_pages = PFN_DOWN(size);
|
2017-07-07 01:38:11 +03:00
|
|
|
int rc;
|
2008-07-14 11:59:18 +04:00
|
|
|
|
2020-04-11 00:33:21 +03:00
|
|
|
if (WARN_ON_ONCE(params->altmap))
|
2019-07-19 01:56:30 +03:00
|
|
|
return -EINVAL;
|
|
|
|
|
mm/memory_hotplug: add pgprot_t to mhp_params
devm_memremap_pages() is currently used by the PCI P2PDMA code to create
struct page mappings for IO memory. At present, these mappings are
created with PAGE_KERNEL which implies setting the PAT bits to be WB.
However, on x86, an mtrr register will typically override this and force
the cache type to be UC-. In the case firmware doesn't set this
register it is effectively WB and will typically result in a machine
check exception when it's accessed.
Other arches are not currently likely to function correctly seeing they
don't have any MTRR registers to fall back on.
To solve this, provide a way to specify the pgprot value explicitly to
arch_add_memory().
Of the arches that support MEMORY_HOTPLUG: x86_64, and arm64 need a
simple change to pass the pgprot_t down to their respective functions
which set up the page tables. For x86_32, set the page tables
explicitly using _set_memory_prot() (seeing they are already mapped).
For ia64, s390 and sh, reject anything but PAGE_KERNEL settings -- this
should be fine, for now, seeing these architectures don't support
ZONE_DEVICE.
A check in __add_pages() is also added to ensure the pgprot parameter
was set for all arches.
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: Dan Williams <dan.j.williams@intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Eric Badger <ebadger@gigaio.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Link: http://lkml.kernel.org/r/20200306170846.9333-7-logang@deltatee.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-04-11 00:33:36 +03:00
|
|
|
if (WARN_ON_ONCE(params->pgprot.pgprot != PAGE_KERNEL.pgprot))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2021-02-26 04:17:41 +03:00
|
|
|
VM_BUG_ON(!mhp_range_allowed(start, size, true));
|
2008-07-14 11:59:18 +04:00
|
|
|
rc = vmem_add_mapping(start, size);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2015-05-08 18:40:43 +03:00
|
|
|
|
2020-04-11 00:33:21 +03:00
|
|
|
rc = __add_pages(nid, start_pfn, size_pages, params);
|
2008-07-14 11:59:18 +04:00
|
|
|
if (rc)
|
|
|
|
vmem_remove_mapping(start, size);
|
|
|
|
return rc;
|
|
|
|
}
|
2013-02-23 04:32:58 +04:00
|
|
|
|
2019-05-14 03:21:46 +03:00
|
|
|
void arch_remove_memory(int nid, u64 start, u64 size,
|
|
|
|
struct vmem_altmap *altmap)
|
2013-02-23 04:32:58 +04:00
|
|
|
{
|
2019-07-19 01:56:35 +03:00
|
|
|
unsigned long start_pfn = start >> PAGE_SHIFT;
|
|
|
|
unsigned long nr_pages = size >> PAGE_SHIFT;
|
|
|
|
|
2020-01-04 23:59:33 +03:00
|
|
|
__remove_pages(start_pfn, nr_pages, altmap);
|
2019-07-19 01:56:35 +03:00
|
|
|
vmem_remove_mapping(start, size);
|
2013-02-23 04:32:58 +04:00
|
|
|
}
|
2008-07-14 11:59:18 +04:00
|
|
|
#endif /* CONFIG_MEMORY_HOTPLUG */
|