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 10:07:57 -04:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-03-08 05:49:57 -05:00
|
|
|
/*
|
|
|
|
* Page table allocation functions
|
|
|
|
*
|
|
|
|
* Copyright IBM Corp. 2016
|
|
|
|
* Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/sysctl.h>
|
2017-06-13 08:46:18 -04:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/mm.h>
|
2016-03-08 05:49:57 -05:00
|
|
|
#include <asm/mmu_context.h>
|
2023-10-27 08:12:38 -04:00
|
|
|
#include <asm/page-states.h>
|
2016-03-08 05:49:57 -05:00
|
|
|
#include <asm/pgalloc.h>
|
|
|
|
#include <asm/gmap.h>
|
|
|
|
#include <asm/tlb.h>
|
|
|
|
#include <asm/tlbflush.h>
|
|
|
|
|
|
|
|
#ifdef CONFIG_PGSTE
|
|
|
|
|
|
|
|
int page_table_allocate_pgste = 0;
|
|
|
|
EXPORT_SYMBOL(page_table_allocate_pgste);
|
|
|
|
|
|
|
|
static struct ctl_table page_table_sysctl[] = {
|
|
|
|
{
|
|
|
|
.procname = "allocate_pgste",
|
|
|
|
.data = &page_table_allocate_pgste,
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = S_IRUGO | S_IWUSR,
|
2018-06-24 06:17:43 -04:00
|
|
|
.proc_handler = proc_dointvec_minmax,
|
2019-06-25 18:00:42 -04:00
|
|
|
.extra1 = SYSCTL_ZERO,
|
|
|
|
.extra2 = SYSCTL_ONE,
|
2016-03-08 05:49:57 -05:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init page_table_register_sysctl(void)
|
|
|
|
{
|
2023-03-10 18:45:24 -05:00
|
|
|
return register_sysctl("vm", page_table_sysctl) ? 0 : -ENOMEM;
|
2016-03-08 05:49:57 -05:00
|
|
|
}
|
|
|
|
__initcall(page_table_register_sysctl);
|
|
|
|
|
|
|
|
#endif /* CONFIG_PGSTE */
|
|
|
|
|
|
|
|
unsigned long *crst_table_alloc(struct mm_struct *mm)
|
|
|
|
{
|
2023-08-07 19:04:56 -04:00
|
|
|
struct ptdesc *ptdesc = pagetable_alloc(GFP_KERNEL, CRST_ALLOC_ORDER);
|
2023-10-27 08:12:38 -04:00
|
|
|
unsigned long *table;
|
2016-03-08 05:49:57 -05:00
|
|
|
|
2023-08-07 19:04:56 -04:00
|
|
|
if (!ptdesc)
|
2016-03-08 05:49:57 -05:00
|
|
|
return NULL;
|
2023-10-27 08:12:38 -04:00
|
|
|
table = ptdesc_to_virt(ptdesc);
|
|
|
|
__arch_set_page_dat(table, 1UL << CRST_ALLOC_ORDER);
|
|
|
|
return table;
|
2016-03-08 05:49:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void crst_table_free(struct mm_struct *mm, unsigned long *table)
|
|
|
|
{
|
2023-08-07 19:04:56 -04:00
|
|
|
pagetable_free(virt_to_ptdesc(table));
|
2016-03-08 05:49:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __crst_table_upgrade(void *arg)
|
|
|
|
{
|
|
|
|
struct mm_struct *mm = arg;
|
|
|
|
|
2020-11-16 02:06:40 -05:00
|
|
|
/* change all active ASCEs to avoid the creation of new TLBs */
|
s390/mm: fix page table upgrade vs 2ndary address mode accesses
A page table upgrade in a kernel section that uses secondary address
mode will mess up the kernel instructions as follows:
Consider the following scenario: two threads are sharing memory.
On CPU1 thread 1 does e.g. strnlen_user(). That gets to
old_fs = enable_sacf_uaccess();
len = strnlen_user_srst(src, size);
and
" la %2,0(%1)\n"
" la %3,0(%0,%1)\n"
" slgr %0,%0\n"
" sacf 256\n"
"0: srst %3,%2\n"
in strnlen_user_srst(). At that point we are in secondary space mode,
control register 1 points to kernel page table and instruction fetching
happens via c1, rather than usual c13. Interrupts are not disabled, for
obvious reasons.
On CPU2 thread 2 does MAP_FIXED mmap(), forcing the upgrade of page table
from 3-level to e.g. 4-level one. We'd allocated new top-level table,
set it up and now we hit this:
notify = 1;
spin_unlock_bh(&mm->page_table_lock);
}
if (notify)
on_each_cpu(__crst_table_upgrade, mm, 0);
OK, we need to actually change over to use of new page table and we
need that to happen in all threads that are currently running. Which
happens to include the thread 1. IPI is delivered and we have
static void __crst_table_upgrade(void *arg)
{
struct mm_struct *mm = arg;
if (current->active_mm == mm)
set_user_asce(mm);
__tlb_flush_local();
}
run on CPU1. That does
static inline void set_user_asce(struct mm_struct *mm)
{
S390_lowcore.user_asce = mm->context.asce;
OK, user page table address updated...
__ctl_load(S390_lowcore.user_asce, 1, 1);
... and control register 1 set to it.
clear_cpu_flag(CIF_ASCE_PRIMARY);
}
IPI is run in home space mode, so it's fine - insns are fetched
using c13, which always points to kernel page table. But as soon
as we return from the interrupt, previous PSW is restored, putting
CPU1 back into secondary space mode, at which point we no longer
get the kernel instructions from the kernel mapping.
The fix is to only fixup the control registers that are currently in use
for user processes during the page table update. We must also disable
interrupts in enable_sacf_uaccess to synchronize the cr and
thread.mm_segment updates against the on_each-cpu.
Fixes: 0aaba41b58bc ("s390: remove all code using the access register mode")
Cc: stable@vger.kernel.org # 4.15+
Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Reviewed-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
References: CVE-2020-11884
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
2020-04-15 09:21:01 -04:00
|
|
|
if (current->active_mm == mm) {
|
2023-09-11 15:40:04 -04:00
|
|
|
S390_lowcore.user_asce.val = mm->context.asce;
|
2023-09-11 15:40:00 -04:00
|
|
|
local_ctl_load(7, &S390_lowcore.user_asce);
|
s390/mm: fix page table upgrade vs 2ndary address mode accesses
A page table upgrade in a kernel section that uses secondary address
mode will mess up the kernel instructions as follows:
Consider the following scenario: two threads are sharing memory.
On CPU1 thread 1 does e.g. strnlen_user(). That gets to
old_fs = enable_sacf_uaccess();
len = strnlen_user_srst(src, size);
and
" la %2,0(%1)\n"
" la %3,0(%0,%1)\n"
" slgr %0,%0\n"
" sacf 256\n"
"0: srst %3,%2\n"
in strnlen_user_srst(). At that point we are in secondary space mode,
control register 1 points to kernel page table and instruction fetching
happens via c1, rather than usual c13. Interrupts are not disabled, for
obvious reasons.
On CPU2 thread 2 does MAP_FIXED mmap(), forcing the upgrade of page table
from 3-level to e.g. 4-level one. We'd allocated new top-level table,
set it up and now we hit this:
notify = 1;
spin_unlock_bh(&mm->page_table_lock);
}
if (notify)
on_each_cpu(__crst_table_upgrade, mm, 0);
OK, we need to actually change over to use of new page table and we
need that to happen in all threads that are currently running. Which
happens to include the thread 1. IPI is delivered and we have
static void __crst_table_upgrade(void *arg)
{
struct mm_struct *mm = arg;
if (current->active_mm == mm)
set_user_asce(mm);
__tlb_flush_local();
}
run on CPU1. That does
static inline void set_user_asce(struct mm_struct *mm)
{
S390_lowcore.user_asce = mm->context.asce;
OK, user page table address updated...
__ctl_load(S390_lowcore.user_asce, 1, 1);
... and control register 1 set to it.
clear_cpu_flag(CIF_ASCE_PRIMARY);
}
IPI is run in home space mode, so it's fine - insns are fetched
using c13, which always points to kernel page table. But as soon
as we return from the interrupt, previous PSW is restored, putting
CPU1 back into secondary space mode, at which point we no longer
get the kernel instructions from the kernel mapping.
The fix is to only fixup the control registers that are currently in use
for user processes during the page table update. We must also disable
interrupts in enable_sacf_uaccess to synchronize the cr and
thread.mm_segment updates against the on_each-cpu.
Fixes: 0aaba41b58bc ("s390: remove all code using the access register mode")
Cc: stable@vger.kernel.org # 4.15+
Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Reviewed-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
References: CVE-2020-11884
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
2020-04-15 09:21:01 -04:00
|
|
|
}
|
2016-03-08 05:49:57 -05:00
|
|
|
__tlb_flush_local();
|
|
|
|
}
|
|
|
|
|
2017-04-24 12:19:10 -04:00
|
|
|
int crst_table_upgrade(struct mm_struct *mm, unsigned long end)
|
2016-03-08 05:49:57 -05:00
|
|
|
{
|
2020-03-08 16:34:49 -04:00
|
|
|
unsigned long *pgd = NULL, *p4d = NULL, *__pgd;
|
|
|
|
unsigned long asce_limit = mm->context.asce_limit;
|
2016-03-08 05:49:57 -05:00
|
|
|
|
2017-04-24 12:19:10 -04:00
|
|
|
/* upgrade should only happen from 3 to 4, 3 to 5, or 4 to 5 levels */
|
2020-03-08 16:34:49 -04:00
|
|
|
VM_BUG_ON(asce_limit < _REGION2_SIZE);
|
|
|
|
|
|
|
|
if (end <= asce_limit)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (asce_limit == _REGION2_SIZE) {
|
|
|
|
p4d = crst_table_alloc(mm);
|
|
|
|
if (unlikely(!p4d))
|
|
|
|
goto err_p4d;
|
|
|
|
crst_table_init(p4d, _REGION2_ENTRY_EMPTY);
|
|
|
|
}
|
|
|
|
if (end > _REGION1_SIZE) {
|
|
|
|
pgd = crst_table_alloc(mm);
|
|
|
|
if (unlikely(!pgd))
|
|
|
|
goto err_pgd;
|
|
|
|
crst_table_init(pgd, _REGION1_ENTRY_EMPTY);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_bh(&mm->page_table_lock);
|
|
|
|
|
|
|
|
/*
|
2020-06-09 00:33:54 -04:00
|
|
|
* This routine gets called with mmap_lock lock held and there is
|
2020-03-08 16:34:49 -04:00
|
|
|
* no reason to optimize for the case of otherwise. However, if
|
|
|
|
* that would ever change, the below check will let us know.
|
|
|
|
*/
|
|
|
|
VM_BUG_ON(asce_limit != mm->context.asce_limit);
|
|
|
|
|
|
|
|
if (p4d) {
|
|
|
|
__pgd = (unsigned long *) mm->pgd;
|
|
|
|
p4d_populate(mm, (p4d_t *) p4d, (pud_t *) __pgd);
|
|
|
|
mm->pgd = (pgd_t *) p4d;
|
|
|
|
mm->context.asce_limit = _REGION1_SIZE;
|
|
|
|
mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
|
|
|
|
_ASCE_USER_BITS | _ASCE_TYPE_REGION2;
|
|
|
|
mm_inc_nr_puds(mm);
|
2017-04-24 12:19:10 -04:00
|
|
|
}
|
2020-03-08 16:34:49 -04:00
|
|
|
if (pgd) {
|
|
|
|
__pgd = (unsigned long *) mm->pgd;
|
|
|
|
pgd_populate(mm, (pgd_t *) pgd, (p4d_t *) __pgd);
|
|
|
|
mm->pgd = (pgd_t *) pgd;
|
2020-03-19 08:44:49 -04:00
|
|
|
mm->context.asce_limit = TASK_SIZE_MAX;
|
2020-03-08 16:34:49 -04:00
|
|
|
mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
|
|
|
|
_ASCE_USER_BITS | _ASCE_TYPE_REGION1;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_bh(&mm->page_table_lock);
|
|
|
|
|
|
|
|
on_each_cpu(__crst_table_upgrade, mm, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_pgd:
|
|
|
|
crst_table_free(mm, p4d);
|
|
|
|
err_p4d:
|
|
|
|
return -ENOMEM;
|
2016-03-08 05:49:57 -05:00
|
|
|
}
|
|
|
|
|
2016-03-08 06:12:18 -05:00
|
|
|
#ifdef CONFIG_PGSTE
|
|
|
|
|
2024-03-04 06:07:20 -05:00
|
|
|
struct ptdesc *page_table_alloc_pgste(struct mm_struct *mm)
|
2016-03-08 06:12:18 -05:00
|
|
|
{
|
2023-08-07 19:04:56 -04:00
|
|
|
struct ptdesc *ptdesc;
|
2017-10-04 13:27:07 -04:00
|
|
|
u64 *table;
|
2016-03-08 06:12:18 -05:00
|
|
|
|
2023-08-07 19:04:56 -04:00
|
|
|
ptdesc = pagetable_alloc(GFP_KERNEL, 0);
|
|
|
|
if (ptdesc) {
|
|
|
|
table = (u64 *)ptdesc_to_virt(ptdesc);
|
2023-10-27 08:12:38 -04:00
|
|
|
__arch_set_page_dat(table, 1);
|
2017-10-04 13:27:07 -04:00
|
|
|
memset64(table, _PAGE_INVALID, PTRS_PER_PTE);
|
|
|
|
memset64(table + PTRS_PER_PTE, 0, PTRS_PER_PTE);
|
2016-03-08 06:12:18 -05:00
|
|
|
}
|
2024-03-04 06:07:20 -05:00
|
|
|
return ptdesc;
|
2016-03-08 06:12:18 -05:00
|
|
|
}
|
|
|
|
|
2024-03-04 06:07:20 -05:00
|
|
|
void page_table_free_pgste(struct ptdesc *ptdesc)
|
2016-03-08 06:12:18 -05:00
|
|
|
{
|
2024-03-04 06:07:20 -05:00
|
|
|
pagetable_free(ptdesc);
|
2016-03-08 06:12:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_PGSTE */
|
|
|
|
|
2016-03-08 05:49:57 -05:00
|
|
|
unsigned long *page_table_alloc(struct mm_struct *mm)
|
|
|
|
{
|
2023-08-07 19:04:56 -04:00
|
|
|
struct ptdesc *ptdesc;
|
2023-10-12 14:28:51 -04:00
|
|
|
unsigned long *table;
|
|
|
|
|
2023-08-07 19:04:56 -04:00
|
|
|
ptdesc = pagetable_alloc(GFP_KERNEL, 0);
|
|
|
|
if (!ptdesc)
|
2016-03-08 05:49:57 -05:00
|
|
|
return NULL;
|
2023-08-07 19:04:56 -04:00
|
|
|
if (!pagetable_pte_ctor(ptdesc)) {
|
|
|
|
pagetable_free(ptdesc);
|
2016-03-08 05:49:57 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
2023-10-27 08:12:38 -04:00
|
|
|
table = ptdesc_to_virt(ptdesc);
|
|
|
|
__arch_set_page_dat(table, 1);
|
2023-10-12 14:28:51 -04:00
|
|
|
/* pt_list is used by gmap only */
|
|
|
|
INIT_LIST_HEAD(&ptdesc->pt_list);
|
|
|
|
memset64((u64 *)table, _PAGE_INVALID, PTRS_PER_PTE);
|
|
|
|
memset64((u64 *)table + PTRS_PER_PTE, 0, PTRS_PER_PTE);
|
2016-03-08 05:49:57 -05:00
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
2023-10-12 14:28:51 -04:00
|
|
|
static void pagetable_pte_dtor_free(struct ptdesc *ptdesc)
|
2021-11-04 02:14:46 -04:00
|
|
|
{
|
2023-08-07 19:04:56 -04:00
|
|
|
pagetable_pte_dtor(ptdesc);
|
|
|
|
pagetable_free(ptdesc);
|
s390: add pte_free_defer() for pgtables sharing page
Add s390-specific pte_free_defer(), to free table page via call_rcu().
pte_free_defer() will be called inside khugepaged's retract_page_tables()
loop, where allocating extra memory cannot be relied upon. This precedes
the generic version to avoid build breakage from incompatible pgtable_t.
This version is more complicated than others: because s390 fits two 2K
page tables into one 4K page (so page->rcu_head must be shared between
both halves), and already uses page->lru (which page->rcu_head overlays)
to list any free halves; with clever management by page->_refcount bits.
Build upon the existing management, adjusted to follow a new rule: that a
page is never on the free list if pte_free_defer() was used on either half
(marked by PageActive). And for simplicity, delay calling RCU until both
halves are freed.
Not adding back unallocated fragments to the list in pte_free_defer() can
result in wasting some amount of memory for pagetables, depending on how
long the allocated fragment will stay in use. In practice, this effect is
expected to be insignificant, and not justify a far more complex approach,
which might allow to add the fragments back later in __tlb_remove_table(),
where we might not have a stable mm any more.
[hughd@google.com: Claudio finds warning on mm_has_pgste() more useful than on mm_alloc_pgste()]
Link: https://lkml.kernel.org/r/3bc095ba-a180-ce3b-82b1-2bfc64612f3@google.com
Link: https://lkml.kernel.org/r/94eccf5f-264c-8abe-4567-e77f4b4e14a@google.com
Signed-off-by: Hugh Dickins <hughd@google.com>
Reviewed-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Tested-by: Alexander Gordeev <agordeev@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Jann Horn <jannh@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Naoya Horiguchi <naoya.horiguchi@nec.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Ralph Campbell <rcampbell@nvidia.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: SeongJae Park <sj@kernel.org>
Cc: Song Liu <song@kernel.org>
Cc: Steven Price <steven.price@arm.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Will Deacon <will@kernel.org>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Yu Zhao <yuzhao@google.com>
Cc: Zack Rusin <zackr@vmware.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-07-12 00:38:35 -04:00
|
|
|
}
|
|
|
|
|
2016-03-08 05:49:57 -05:00
|
|
|
void page_table_free(struct mm_struct *mm, unsigned long *table)
|
|
|
|
{
|
2023-08-07 19:04:56 -04:00
|
|
|
struct ptdesc *ptdesc = virt_to_ptdesc(table);
|
2016-03-08 05:49:57 -05:00
|
|
|
|
2023-10-12 14:28:51 -04:00
|
|
|
pagetable_pte_dtor_free(ptdesc);
|
2016-03-08 05:49:57 -05:00
|
|
|
}
|
|
|
|
|
2023-11-03 11:40:13 -04:00
|
|
|
void __tlb_remove_table(void *table)
|
2016-03-08 05:49:57 -05:00
|
|
|
{
|
2023-11-03 11:40:13 -04:00
|
|
|
struct ptdesc *ptdesc = virt_to_ptdesc(table);
|
|
|
|
struct page *page = ptdesc_page(ptdesc);
|
2023-10-12 14:28:51 -04:00
|
|
|
|
2023-11-03 11:40:13 -04:00
|
|
|
if (compound_order(page) == CRST_ALLOC_ORDER) {
|
2023-10-12 14:28:51 -04:00
|
|
|
/* pmd, pud, or p4d */
|
2023-08-07 19:04:56 -04:00
|
|
|
pagetable_free(ptdesc);
|
2021-11-04 02:14:46 -04:00
|
|
|
return;
|
2016-03-08 05:49:57 -05:00
|
|
|
}
|
2023-10-12 14:28:51 -04:00
|
|
|
pagetable_pte_dtor_free(ptdesc);
|
s390: add pte_free_defer() for pgtables sharing page
Add s390-specific pte_free_defer(), to free table page via call_rcu().
pte_free_defer() will be called inside khugepaged's retract_page_tables()
loop, where allocating extra memory cannot be relied upon. This precedes
the generic version to avoid build breakage from incompatible pgtable_t.
This version is more complicated than others: because s390 fits two 2K
page tables into one 4K page (so page->rcu_head must be shared between
both halves), and already uses page->lru (which page->rcu_head overlays)
to list any free halves; with clever management by page->_refcount bits.
Build upon the existing management, adjusted to follow a new rule: that a
page is never on the free list if pte_free_defer() was used on either half
(marked by PageActive). And for simplicity, delay calling RCU until both
halves are freed.
Not adding back unallocated fragments to the list in pte_free_defer() can
result in wasting some amount of memory for pagetables, depending on how
long the allocated fragment will stay in use. In practice, this effect is
expected to be insignificant, and not justify a far more complex approach,
which might allow to add the fragments back later in __tlb_remove_table(),
where we might not have a stable mm any more.
[hughd@google.com: Claudio finds warning on mm_has_pgste() more useful than on mm_alloc_pgste()]
Link: https://lkml.kernel.org/r/3bc095ba-a180-ce3b-82b1-2bfc64612f3@google.com
Link: https://lkml.kernel.org/r/94eccf5f-264c-8abe-4567-e77f4b4e14a@google.com
Signed-off-by: Hugh Dickins <hughd@google.com>
Reviewed-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Tested-by: Alexander Gordeev <agordeev@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Jann Horn <jannh@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Naoya Horiguchi <naoya.horiguchi@nec.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Ralph Campbell <rcampbell@nvidia.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: SeongJae Park <sj@kernel.org>
Cc: Song Liu <song@kernel.org>
Cc: Steven Price <steven.price@arm.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Will Deacon <will@kernel.org>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Yu Zhao <yuzhao@google.com>
Cc: Zack Rusin <zackr@vmware.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-07-12 00:38:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
|
2023-10-12 14:28:51 -04:00
|
|
|
static void pte_free_now(struct rcu_head *head)
|
|
|
|
{
|
|
|
|
struct ptdesc *ptdesc = container_of(head, struct ptdesc, pt_rcu_head);
|
|
|
|
|
|
|
|
pagetable_pte_dtor_free(ptdesc);
|
|
|
|
}
|
|
|
|
|
s390: add pte_free_defer() for pgtables sharing page
Add s390-specific pte_free_defer(), to free table page via call_rcu().
pte_free_defer() will be called inside khugepaged's retract_page_tables()
loop, where allocating extra memory cannot be relied upon. This precedes
the generic version to avoid build breakage from incompatible pgtable_t.
This version is more complicated than others: because s390 fits two 2K
page tables into one 4K page (so page->rcu_head must be shared between
both halves), and already uses page->lru (which page->rcu_head overlays)
to list any free halves; with clever management by page->_refcount bits.
Build upon the existing management, adjusted to follow a new rule: that a
page is never on the free list if pte_free_defer() was used on either half
(marked by PageActive). And for simplicity, delay calling RCU until both
halves are freed.
Not adding back unallocated fragments to the list in pte_free_defer() can
result in wasting some amount of memory for pagetables, depending on how
long the allocated fragment will stay in use. In practice, this effect is
expected to be insignificant, and not justify a far more complex approach,
which might allow to add the fragments back later in __tlb_remove_table(),
where we might not have a stable mm any more.
[hughd@google.com: Claudio finds warning on mm_has_pgste() more useful than on mm_alloc_pgste()]
Link: https://lkml.kernel.org/r/3bc095ba-a180-ce3b-82b1-2bfc64612f3@google.com
Link: https://lkml.kernel.org/r/94eccf5f-264c-8abe-4567-e77f4b4e14a@google.com
Signed-off-by: Hugh Dickins <hughd@google.com>
Reviewed-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Tested-by: Alexander Gordeev <agordeev@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Jann Horn <jannh@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Naoya Horiguchi <naoya.horiguchi@nec.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Ralph Campbell <rcampbell@nvidia.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: SeongJae Park <sj@kernel.org>
Cc: Song Liu <song@kernel.org>
Cc: Steven Price <steven.price@arm.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Will Deacon <will@kernel.org>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Yu Zhao <yuzhao@google.com>
Cc: Zack Rusin <zackr@vmware.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-07-12 00:38:35 -04:00
|
|
|
void pte_free_defer(struct mm_struct *mm, pgtable_t pgtable)
|
|
|
|
{
|
2023-10-12 14:28:51 -04:00
|
|
|
struct ptdesc *ptdesc = virt_to_ptdesc(pgtable);
|
s390: add pte_free_defer() for pgtables sharing page
Add s390-specific pte_free_defer(), to free table page via call_rcu().
pte_free_defer() will be called inside khugepaged's retract_page_tables()
loop, where allocating extra memory cannot be relied upon. This precedes
the generic version to avoid build breakage from incompatible pgtable_t.
This version is more complicated than others: because s390 fits two 2K
page tables into one 4K page (so page->rcu_head must be shared between
both halves), and already uses page->lru (which page->rcu_head overlays)
to list any free halves; with clever management by page->_refcount bits.
Build upon the existing management, adjusted to follow a new rule: that a
page is never on the free list if pte_free_defer() was used on either half
(marked by PageActive). And for simplicity, delay calling RCU until both
halves are freed.
Not adding back unallocated fragments to the list in pte_free_defer() can
result in wasting some amount of memory for pagetables, depending on how
long the allocated fragment will stay in use. In practice, this effect is
expected to be insignificant, and not justify a far more complex approach,
which might allow to add the fragments back later in __tlb_remove_table(),
where we might not have a stable mm any more.
[hughd@google.com: Claudio finds warning on mm_has_pgste() more useful than on mm_alloc_pgste()]
Link: https://lkml.kernel.org/r/3bc095ba-a180-ce3b-82b1-2bfc64612f3@google.com
Link: https://lkml.kernel.org/r/94eccf5f-264c-8abe-4567-e77f4b4e14a@google.com
Signed-off-by: Hugh Dickins <hughd@google.com>
Reviewed-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Tested-by: Alexander Gordeev <agordeev@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Jann Horn <jannh@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Naoya Horiguchi <naoya.horiguchi@nec.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Ralph Campbell <rcampbell@nvidia.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: SeongJae Park <sj@kernel.org>
Cc: Song Liu <song@kernel.org>
Cc: Steven Price <steven.price@arm.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Will Deacon <will@kernel.org>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Yu Zhao <yuzhao@google.com>
Cc: Zack Rusin <zackr@vmware.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-07-12 00:38:35 -04:00
|
|
|
|
2023-10-12 14:28:51 -04:00
|
|
|
call_rcu(&ptdesc->pt_rcu_head, pte_free_now);
|
s390: add pte_free_defer() for pgtables sharing page
Add s390-specific pte_free_defer(), to free table page via call_rcu().
pte_free_defer() will be called inside khugepaged's retract_page_tables()
loop, where allocating extra memory cannot be relied upon. This precedes
the generic version to avoid build breakage from incompatible pgtable_t.
This version is more complicated than others: because s390 fits two 2K
page tables into one 4K page (so page->rcu_head must be shared between
both halves), and already uses page->lru (which page->rcu_head overlays)
to list any free halves; with clever management by page->_refcount bits.
Build upon the existing management, adjusted to follow a new rule: that a
page is never on the free list if pte_free_defer() was used on either half
(marked by PageActive). And for simplicity, delay calling RCU until both
halves are freed.
Not adding back unallocated fragments to the list in pte_free_defer() can
result in wasting some amount of memory for pagetables, depending on how
long the allocated fragment will stay in use. In practice, this effect is
expected to be insignificant, and not justify a far more complex approach,
which might allow to add the fragments back later in __tlb_remove_table(),
where we might not have a stable mm any more.
[hughd@google.com: Claudio finds warning on mm_has_pgste() more useful than on mm_alloc_pgste()]
Link: https://lkml.kernel.org/r/3bc095ba-a180-ce3b-82b1-2bfc64612f3@google.com
Link: https://lkml.kernel.org/r/94eccf5f-264c-8abe-4567-e77f4b4e14a@google.com
Signed-off-by: Hugh Dickins <hughd@google.com>
Reviewed-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Tested-by: Alexander Gordeev <agordeev@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Jann Horn <jannh@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Naoya Horiguchi <naoya.horiguchi@nec.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Ralph Campbell <rcampbell@nvidia.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: SeongJae Park <sj@kernel.org>
Cc: Song Liu <song@kernel.org>
Cc: Steven Price <steven.price@arm.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Will Deacon <will@kernel.org>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Yu Zhao <yuzhao@google.com>
Cc: Zack Rusin <zackr@vmware.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-07-12 00:38:35 -04:00
|
|
|
/*
|
2023-10-12 14:28:51 -04:00
|
|
|
* THPs are not allowed for KVM guests. Warn if pgste ever reaches here.
|
|
|
|
* Turn to the generic pte_free_defer() version once gmap is removed.
|
s390: add pte_free_defer() for pgtables sharing page
Add s390-specific pte_free_defer(), to free table page via call_rcu().
pte_free_defer() will be called inside khugepaged's retract_page_tables()
loop, where allocating extra memory cannot be relied upon. This precedes
the generic version to avoid build breakage from incompatible pgtable_t.
This version is more complicated than others: because s390 fits two 2K
page tables into one 4K page (so page->rcu_head must be shared between
both halves), and already uses page->lru (which page->rcu_head overlays)
to list any free halves; with clever management by page->_refcount bits.
Build upon the existing management, adjusted to follow a new rule: that a
page is never on the free list if pte_free_defer() was used on either half
(marked by PageActive). And for simplicity, delay calling RCU until both
halves are freed.
Not adding back unallocated fragments to the list in pte_free_defer() can
result in wasting some amount of memory for pagetables, depending on how
long the allocated fragment will stay in use. In practice, this effect is
expected to be insignificant, and not justify a far more complex approach,
which might allow to add the fragments back later in __tlb_remove_table(),
where we might not have a stable mm any more.
[hughd@google.com: Claudio finds warning on mm_has_pgste() more useful than on mm_alloc_pgste()]
Link: https://lkml.kernel.org/r/3bc095ba-a180-ce3b-82b1-2bfc64612f3@google.com
Link: https://lkml.kernel.org/r/94eccf5f-264c-8abe-4567-e77f4b4e14a@google.com
Signed-off-by: Hugh Dickins <hughd@google.com>
Reviewed-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Tested-by: Alexander Gordeev <agordeev@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Jann Horn <jannh@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Naoya Horiguchi <naoya.horiguchi@nec.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Ralph Campbell <rcampbell@nvidia.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: SeongJae Park <sj@kernel.org>
Cc: Song Liu <song@kernel.org>
Cc: Steven Price <steven.price@arm.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Will Deacon <will@kernel.org>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Yu Zhao <yuzhao@google.com>
Cc: Zack Rusin <zackr@vmware.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-07-12 00:38:35 -04:00
|
|
|
*/
|
|
|
|
WARN_ON_ONCE(mm_has_pgste(mm));
|
2016-03-08 05:49:57 -05:00
|
|
|
}
|
s390: add pte_free_defer() for pgtables sharing page
Add s390-specific pte_free_defer(), to free table page via call_rcu().
pte_free_defer() will be called inside khugepaged's retract_page_tables()
loop, where allocating extra memory cannot be relied upon. This precedes
the generic version to avoid build breakage from incompatible pgtable_t.
This version is more complicated than others: because s390 fits two 2K
page tables into one 4K page (so page->rcu_head must be shared between
both halves), and already uses page->lru (which page->rcu_head overlays)
to list any free halves; with clever management by page->_refcount bits.
Build upon the existing management, adjusted to follow a new rule: that a
page is never on the free list if pte_free_defer() was used on either half
(marked by PageActive). And for simplicity, delay calling RCU until both
halves are freed.
Not adding back unallocated fragments to the list in pte_free_defer() can
result in wasting some amount of memory for pagetables, depending on how
long the allocated fragment will stay in use. In practice, this effect is
expected to be insignificant, and not justify a far more complex approach,
which might allow to add the fragments back later in __tlb_remove_table(),
where we might not have a stable mm any more.
[hughd@google.com: Claudio finds warning on mm_has_pgste() more useful than on mm_alloc_pgste()]
Link: https://lkml.kernel.org/r/3bc095ba-a180-ce3b-82b1-2bfc64612f3@google.com
Link: https://lkml.kernel.org/r/94eccf5f-264c-8abe-4567-e77f4b4e14a@google.com
Signed-off-by: Hugh Dickins <hughd@google.com>
Reviewed-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Tested-by: Alexander Gordeev <agordeev@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Jann Horn <jannh@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Naoya Horiguchi <naoya.horiguchi@nec.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Ralph Campbell <rcampbell@nvidia.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: SeongJae Park <sj@kernel.org>
Cc: Song Liu <song@kernel.org>
Cc: Steven Price <steven.price@arm.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Will Deacon <will@kernel.org>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Yu Zhao <yuzhao@google.com>
Cc: Zack Rusin <zackr@vmware.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-07-12 00:38:35 -04:00
|
|
|
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
|
2016-03-08 05:49:57 -05:00
|
|
|
|
2017-06-13 08:46:18 -04:00
|
|
|
/*
|
|
|
|
* Base infrastructure required to generate basic asces, region, segment,
|
|
|
|
* and page tables that do not make use of enhanced features like EDAT1.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct kmem_cache *base_pgt_cache;
|
|
|
|
|
2021-12-09 06:01:25 -05:00
|
|
|
static unsigned long *base_pgt_alloc(void)
|
2017-06-13 08:46:18 -04:00
|
|
|
{
|
2021-12-09 06:01:25 -05:00
|
|
|
unsigned long *table;
|
2017-06-13 08:46:18 -04:00
|
|
|
|
|
|
|
table = kmem_cache_alloc(base_pgt_cache, GFP_KERNEL);
|
|
|
|
if (table)
|
2021-12-09 06:01:25 -05:00
|
|
|
memset64((u64 *)table, _PAGE_INVALID, PTRS_PER_PTE);
|
|
|
|
return table;
|
2017-06-13 08:46:18 -04:00
|
|
|
}
|
|
|
|
|
2021-12-09 06:01:25 -05:00
|
|
|
static void base_pgt_free(unsigned long *table)
|
2017-06-13 08:46:18 -04:00
|
|
|
{
|
2021-12-09 06:01:25 -05:00
|
|
|
kmem_cache_free(base_pgt_cache, table);
|
2017-06-13 08:46:18 -04:00
|
|
|
}
|
|
|
|
|
2021-12-09 06:01:25 -05:00
|
|
|
static unsigned long *base_crst_alloc(unsigned long val)
|
2017-06-13 08:46:18 -04:00
|
|
|
{
|
2021-12-09 06:01:25 -05:00
|
|
|
unsigned long *table;
|
2023-08-07 19:04:56 -04:00
|
|
|
struct ptdesc *ptdesc;
|
2017-06-13 08:46:18 -04:00
|
|
|
|
2023-10-16 06:10:04 -04:00
|
|
|
ptdesc = pagetable_alloc(GFP_KERNEL, CRST_ALLOC_ORDER);
|
2023-08-07 19:04:56 -04:00
|
|
|
if (!ptdesc)
|
|
|
|
return NULL;
|
|
|
|
table = ptdesc_address(ptdesc);
|
|
|
|
crst_table_init(table, val);
|
2017-06-13 08:46:18 -04:00
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
2021-12-09 06:01:25 -05:00
|
|
|
static void base_crst_free(unsigned long *table)
|
2017-06-13 08:46:18 -04:00
|
|
|
{
|
2023-08-07 19:04:56 -04:00
|
|
|
pagetable_free(virt_to_ptdesc(table));
|
2017-06-13 08:46:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define BASE_ADDR_END_FUNC(NAME, SIZE) \
|
|
|
|
static inline unsigned long base_##NAME##_addr_end(unsigned long addr, \
|
|
|
|
unsigned long end) \
|
|
|
|
{ \
|
|
|
|
unsigned long next = (addr + (SIZE)) & ~((SIZE) - 1); \
|
|
|
|
\
|
|
|
|
return (next - 1) < (end - 1) ? next : end; \
|
|
|
|
}
|
|
|
|
|
|
|
|
BASE_ADDR_END_FUNC(page, _PAGE_SIZE)
|
|
|
|
BASE_ADDR_END_FUNC(segment, _SEGMENT_SIZE)
|
|
|
|
BASE_ADDR_END_FUNC(region3, _REGION3_SIZE)
|
|
|
|
BASE_ADDR_END_FUNC(region2, _REGION2_SIZE)
|
|
|
|
BASE_ADDR_END_FUNC(region1, _REGION1_SIZE)
|
|
|
|
|
|
|
|
static inline unsigned long base_lra(unsigned long address)
|
|
|
|
{
|
|
|
|
unsigned long real;
|
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
" lra %0,0(%1)\n"
|
|
|
|
: "=d" (real) : "a" (address) : "cc");
|
|
|
|
return real;
|
|
|
|
}
|
|
|
|
|
2021-12-09 06:01:25 -05:00
|
|
|
static int base_page_walk(unsigned long *origin, unsigned long addr,
|
2017-06-13 08:46:18 -04:00
|
|
|
unsigned long end, int alloc)
|
|
|
|
{
|
|
|
|
unsigned long *pte, next;
|
|
|
|
|
|
|
|
if (!alloc)
|
|
|
|
return 0;
|
2021-12-09 06:01:25 -05:00
|
|
|
pte = origin;
|
2017-06-13 08:46:18 -04:00
|
|
|
pte += (addr & _PAGE_INDEX) >> _PAGE_SHIFT;
|
|
|
|
do {
|
|
|
|
next = base_page_addr_end(addr, end);
|
|
|
|
*pte = base_lra(addr);
|
|
|
|
} while (pte++, addr = next, addr < end);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-12-09 06:01:25 -05:00
|
|
|
static int base_segment_walk(unsigned long *origin, unsigned long addr,
|
2017-06-13 08:46:18 -04:00
|
|
|
unsigned long end, int alloc)
|
|
|
|
{
|
2021-12-09 06:01:25 -05:00
|
|
|
unsigned long *ste, next, *table;
|
2017-06-13 08:46:18 -04:00
|
|
|
int rc;
|
|
|
|
|
2021-12-09 06:01:25 -05:00
|
|
|
ste = origin;
|
2017-06-13 08:46:18 -04:00
|
|
|
ste += (addr & _SEGMENT_INDEX) >> _SEGMENT_SHIFT;
|
|
|
|
do {
|
|
|
|
next = base_segment_addr_end(addr, end);
|
|
|
|
if (*ste & _SEGMENT_ENTRY_INVALID) {
|
|
|
|
if (!alloc)
|
|
|
|
continue;
|
|
|
|
table = base_pgt_alloc();
|
|
|
|
if (!table)
|
|
|
|
return -ENOMEM;
|
2021-12-07 14:06:21 -05:00
|
|
|
*ste = __pa(table) | _SEGMENT_ENTRY;
|
2017-06-13 08:46:18 -04:00
|
|
|
}
|
2021-12-09 06:01:25 -05:00
|
|
|
table = __va(*ste & _SEGMENT_ENTRY_ORIGIN);
|
2017-06-13 08:46:18 -04:00
|
|
|
rc = base_page_walk(table, addr, next, alloc);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
if (!alloc)
|
|
|
|
base_pgt_free(table);
|
|
|
|
cond_resched();
|
|
|
|
} while (ste++, addr = next, addr < end);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-12-09 06:01:25 -05:00
|
|
|
static int base_region3_walk(unsigned long *origin, unsigned long addr,
|
2017-06-13 08:46:18 -04:00
|
|
|
unsigned long end, int alloc)
|
|
|
|
{
|
2021-12-09 06:01:25 -05:00
|
|
|
unsigned long *rtte, next, *table;
|
2017-06-13 08:46:18 -04:00
|
|
|
int rc;
|
|
|
|
|
2021-12-09 06:01:25 -05:00
|
|
|
rtte = origin;
|
2017-06-13 08:46:18 -04:00
|
|
|
rtte += (addr & _REGION3_INDEX) >> _REGION3_SHIFT;
|
|
|
|
do {
|
|
|
|
next = base_region3_addr_end(addr, end);
|
|
|
|
if (*rtte & _REGION_ENTRY_INVALID) {
|
|
|
|
if (!alloc)
|
|
|
|
continue;
|
|
|
|
table = base_crst_alloc(_SEGMENT_ENTRY_EMPTY);
|
|
|
|
if (!table)
|
|
|
|
return -ENOMEM;
|
2021-12-07 14:06:21 -05:00
|
|
|
*rtte = __pa(table) | _REGION3_ENTRY;
|
2017-06-13 08:46:18 -04:00
|
|
|
}
|
2021-12-09 06:01:25 -05:00
|
|
|
table = __va(*rtte & _REGION_ENTRY_ORIGIN);
|
2017-06-13 08:46:18 -04:00
|
|
|
rc = base_segment_walk(table, addr, next, alloc);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
if (!alloc)
|
|
|
|
base_crst_free(table);
|
|
|
|
} while (rtte++, addr = next, addr < end);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-12-09 06:01:25 -05:00
|
|
|
static int base_region2_walk(unsigned long *origin, unsigned long addr,
|
2017-06-13 08:46:18 -04:00
|
|
|
unsigned long end, int alloc)
|
|
|
|
{
|
2021-12-09 06:01:25 -05:00
|
|
|
unsigned long *rste, next, *table;
|
2017-06-13 08:46:18 -04:00
|
|
|
int rc;
|
|
|
|
|
2021-12-09 06:01:25 -05:00
|
|
|
rste = origin;
|
2017-06-13 08:46:18 -04:00
|
|
|
rste += (addr & _REGION2_INDEX) >> _REGION2_SHIFT;
|
|
|
|
do {
|
|
|
|
next = base_region2_addr_end(addr, end);
|
|
|
|
if (*rste & _REGION_ENTRY_INVALID) {
|
|
|
|
if (!alloc)
|
|
|
|
continue;
|
|
|
|
table = base_crst_alloc(_REGION3_ENTRY_EMPTY);
|
|
|
|
if (!table)
|
|
|
|
return -ENOMEM;
|
2021-12-07 14:06:21 -05:00
|
|
|
*rste = __pa(table) | _REGION2_ENTRY;
|
2017-06-13 08:46:18 -04:00
|
|
|
}
|
2021-12-09 06:01:25 -05:00
|
|
|
table = __va(*rste & _REGION_ENTRY_ORIGIN);
|
2017-06-13 08:46:18 -04:00
|
|
|
rc = base_region3_walk(table, addr, next, alloc);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
if (!alloc)
|
|
|
|
base_crst_free(table);
|
|
|
|
} while (rste++, addr = next, addr < end);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-12-09 06:01:25 -05:00
|
|
|
static int base_region1_walk(unsigned long *origin, unsigned long addr,
|
2017-06-13 08:46:18 -04:00
|
|
|
unsigned long end, int alloc)
|
|
|
|
{
|
2021-12-09 06:01:25 -05:00
|
|
|
unsigned long *rfte, next, *table;
|
2017-06-13 08:46:18 -04:00
|
|
|
int rc;
|
|
|
|
|
2021-12-09 06:01:25 -05:00
|
|
|
rfte = origin;
|
2017-06-13 08:46:18 -04:00
|
|
|
rfte += (addr & _REGION1_INDEX) >> _REGION1_SHIFT;
|
|
|
|
do {
|
|
|
|
next = base_region1_addr_end(addr, end);
|
|
|
|
if (*rfte & _REGION_ENTRY_INVALID) {
|
|
|
|
if (!alloc)
|
|
|
|
continue;
|
|
|
|
table = base_crst_alloc(_REGION2_ENTRY_EMPTY);
|
|
|
|
if (!table)
|
|
|
|
return -ENOMEM;
|
2021-12-07 14:06:21 -05:00
|
|
|
*rfte = __pa(table) | _REGION1_ENTRY;
|
2017-06-13 08:46:18 -04:00
|
|
|
}
|
2021-12-09 06:01:25 -05:00
|
|
|
table = __va(*rfte & _REGION_ENTRY_ORIGIN);
|
2017-06-13 08:46:18 -04:00
|
|
|
rc = base_region2_walk(table, addr, next, alloc);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
if (!alloc)
|
|
|
|
base_crst_free(table);
|
|
|
|
} while (rfte++, addr = next, addr < end);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* base_asce_free - free asce and tables returned from base_asce_alloc()
|
|
|
|
* @asce: asce to be freed
|
|
|
|
*
|
|
|
|
* Frees all region, segment, and page tables that were allocated with a
|
|
|
|
* corresponding base_asce_alloc() call.
|
|
|
|
*/
|
|
|
|
void base_asce_free(unsigned long asce)
|
|
|
|
{
|
2021-12-09 06:01:25 -05:00
|
|
|
unsigned long *table = __va(asce & _ASCE_ORIGIN);
|
2017-06-13 08:46:18 -04:00
|
|
|
|
|
|
|
if (!asce)
|
|
|
|
return;
|
|
|
|
switch (asce & _ASCE_TYPE_MASK) {
|
|
|
|
case _ASCE_TYPE_SEGMENT:
|
|
|
|
base_segment_walk(table, 0, _REGION3_SIZE, 0);
|
|
|
|
break;
|
|
|
|
case _ASCE_TYPE_REGION3:
|
|
|
|
base_region3_walk(table, 0, _REGION2_SIZE, 0);
|
|
|
|
break;
|
|
|
|
case _ASCE_TYPE_REGION2:
|
|
|
|
base_region2_walk(table, 0, _REGION1_SIZE, 0);
|
|
|
|
break;
|
|
|
|
case _ASCE_TYPE_REGION1:
|
2020-03-19 08:44:49 -04:00
|
|
|
base_region1_walk(table, 0, TASK_SIZE_MAX, 0);
|
2017-06-13 08:46:18 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
base_crst_free(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int base_pgt_cache_init(void)
|
|
|
|
{
|
|
|
|
static DEFINE_MUTEX(base_pgt_cache_mutex);
|
|
|
|
unsigned long sz = _PAGE_TABLE_SIZE;
|
|
|
|
|
|
|
|
if (base_pgt_cache)
|
|
|
|
return 0;
|
|
|
|
mutex_lock(&base_pgt_cache_mutex);
|
|
|
|
if (!base_pgt_cache)
|
|
|
|
base_pgt_cache = kmem_cache_create("base_pgt", sz, sz, 0, NULL);
|
|
|
|
mutex_unlock(&base_pgt_cache_mutex);
|
|
|
|
return base_pgt_cache ? 0 : -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* base_asce_alloc - create kernel mapping without enhanced DAT features
|
|
|
|
* @addr: virtual start address of kernel mapping
|
|
|
|
* @num_pages: number of consecutive pages
|
|
|
|
*
|
|
|
|
* Generate an asce, including all required region, segment and page tables,
|
|
|
|
* that can be used to access the virtual kernel mapping. The difference is
|
|
|
|
* that the returned asce does not make use of any enhanced DAT features like
|
|
|
|
* e.g. large pages. This is required for some I/O functions that pass an
|
|
|
|
* asce, like e.g. some service call requests.
|
|
|
|
*
|
|
|
|
* Note: the returned asce may NEVER be attached to any cpu. It may only be
|
|
|
|
* used for I/O requests. tlb entries that might result because the
|
|
|
|
* asce was attached to a cpu won't be cleared.
|
|
|
|
*/
|
|
|
|
unsigned long base_asce_alloc(unsigned long addr, unsigned long num_pages)
|
|
|
|
{
|
2021-12-09 06:01:25 -05:00
|
|
|
unsigned long asce, *table, end;
|
2017-06-13 08:46:18 -04:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (base_pgt_cache_init())
|
|
|
|
return 0;
|
|
|
|
end = addr + num_pages * PAGE_SIZE;
|
|
|
|
if (end <= _REGION3_SIZE) {
|
|
|
|
table = base_crst_alloc(_SEGMENT_ENTRY_EMPTY);
|
|
|
|
if (!table)
|
|
|
|
return 0;
|
|
|
|
rc = base_segment_walk(table, addr, end, 1);
|
2021-12-07 14:06:21 -05:00
|
|
|
asce = __pa(table) | _ASCE_TYPE_SEGMENT | _ASCE_TABLE_LENGTH;
|
2017-06-13 08:46:18 -04:00
|
|
|
} else if (end <= _REGION2_SIZE) {
|
|
|
|
table = base_crst_alloc(_REGION3_ENTRY_EMPTY);
|
|
|
|
if (!table)
|
|
|
|
return 0;
|
|
|
|
rc = base_region3_walk(table, addr, end, 1);
|
2021-12-07 14:06:21 -05:00
|
|
|
asce = __pa(table) | _ASCE_TYPE_REGION3 | _ASCE_TABLE_LENGTH;
|
2017-06-13 08:46:18 -04:00
|
|
|
} else if (end <= _REGION1_SIZE) {
|
|
|
|
table = base_crst_alloc(_REGION2_ENTRY_EMPTY);
|
|
|
|
if (!table)
|
|
|
|
return 0;
|
|
|
|
rc = base_region2_walk(table, addr, end, 1);
|
2021-12-07 14:06:21 -05:00
|
|
|
asce = __pa(table) | _ASCE_TYPE_REGION2 | _ASCE_TABLE_LENGTH;
|
2017-06-13 08:46:18 -04:00
|
|
|
} else {
|
|
|
|
table = base_crst_alloc(_REGION1_ENTRY_EMPTY);
|
|
|
|
if (!table)
|
|
|
|
return 0;
|
|
|
|
rc = base_region1_walk(table, addr, end, 1);
|
2021-12-07 14:06:21 -05:00
|
|
|
asce = __pa(table) | _ASCE_TYPE_REGION1 | _ASCE_TABLE_LENGTH;
|
2017-06-13 08:46:18 -04:00
|
|
|
}
|
|
|
|
if (rc) {
|
|
|
|
base_asce_free(asce);
|
|
|
|
asce = 0;
|
|
|
|
}
|
|
|
|
return asce;
|
|
|
|
}
|