2011-03-16 00:08:22 +08:00
|
|
|
/*
|
|
|
|
* Copyright IBM Corp. 2011
|
|
|
|
* Author(s): Jan Glauber <jang@linux.vnet.ibm.com>
|
|
|
|
*/
|
2012-11-02 19:56:43 +08:00
|
|
|
#include <linux/hugetlb.h>
|
2011-03-16 00:08:22 +08:00
|
|
|
#include <linux/mm.h>
|
2011-10-30 22:17:13 +08:00
|
|
|
#include <asm/cacheflush.h>
|
2014-09-24 03:29:20 +08:00
|
|
|
#include <asm/facility.h>
|
2011-03-16 00:08:22 +08:00
|
|
|
#include <asm/pgtable.h>
|
2017-06-16 23:51:15 +08:00
|
|
|
#include <asm/pgalloc.h>
|
2012-11-02 19:56:43 +08:00
|
|
|
#include <asm/page.h>
|
2017-05-09 06:58:08 +08:00
|
|
|
#include <asm/set_memory.h>
|
2012-11-02 19:56:43 +08:00
|
|
|
|
2013-03-14 23:46:05 +08:00
|
|
|
static inline unsigned long sske_frame(unsigned long addr, unsigned char skey)
|
|
|
|
{
|
|
|
|
asm volatile(".insn rrf,0xb22b0000,%[skey],%[addr],9,0"
|
|
|
|
: [addr] "+a" (addr) : [skey] "d" (skey));
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2013-10-07 18:12:32 +08:00
|
|
|
void __storage_key_init_range(unsigned long start, unsigned long end)
|
2012-11-02 19:56:43 +08:00
|
|
|
{
|
2013-03-14 23:46:05 +08:00
|
|
|
unsigned long boundary, size;
|
2012-11-02 19:56:43 +08:00
|
|
|
|
2016-06-14 12:55:43 +08:00
|
|
|
if (!PAGE_DEFAULT_KEY)
|
|
|
|
return;
|
2012-11-02 19:56:43 +08:00
|
|
|
while (start < end) {
|
|
|
|
if (MACHINE_HAS_EDAT1) {
|
|
|
|
/* set storage keys for a 1MB frame */
|
|
|
|
size = 1UL << 20;
|
|
|
|
boundary = (start + size) & ~(size - 1);
|
|
|
|
if (boundary <= end) {
|
|
|
|
do {
|
2013-03-14 23:46:05 +08:00
|
|
|
start = sske_frame(start, PAGE_DEFAULT_KEY);
|
2012-11-02 19:56:43 +08:00
|
|
|
} while (start < boundary);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
page_set_storage_key(start, PAGE_DEFAULT_KEY, 0);
|
|
|
|
start += PAGE_SIZE;
|
|
|
|
}
|
|
|
|
}
|
2011-03-16 00:08:22 +08:00
|
|
|
|
2016-05-20 14:08:14 +08:00
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
atomic_long_t direct_pages_count[PG_DIRECT_MAP_MAX];
|
|
|
|
|
|
|
|
void arch_report_meminfo(struct seq_file *m)
|
|
|
|
{
|
|
|
|
seq_printf(m, "DirectMap4k: %8lu kB\n",
|
|
|
|
atomic_long_read(&direct_pages_count[PG_DIRECT_MAP_4K]) << 2);
|
|
|
|
seq_printf(m, "DirectMap1M: %8lu kB\n",
|
|
|
|
atomic_long_read(&direct_pages_count[PG_DIRECT_MAP_1M]) << 10);
|
|
|
|
seq_printf(m, "DirectMap2G: %8lu kB\n",
|
|
|
|
atomic_long_read(&direct_pages_count[PG_DIRECT_MAP_2G]) << 21);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
|
2016-05-17 16:50:15 +08:00
|
|
|
static void pgt_set(unsigned long *old, unsigned long new, unsigned long addr,
|
|
|
|
unsigned long dtt)
|
2012-10-01 22:18:46 +08:00
|
|
|
{
|
2016-05-17 16:50:15 +08:00
|
|
|
unsigned long table, mask;
|
|
|
|
|
|
|
|
mask = 0;
|
|
|
|
if (MACHINE_HAS_EDAT2) {
|
|
|
|
switch (dtt) {
|
|
|
|
case CRDTE_DTT_REGION3:
|
|
|
|
mask = ~(PTRS_PER_PUD * sizeof(pud_t) - 1);
|
|
|
|
break;
|
|
|
|
case CRDTE_DTT_SEGMENT:
|
|
|
|
mask = ~(PTRS_PER_PMD * sizeof(pmd_t) - 1);
|
|
|
|
break;
|
|
|
|
case CRDTE_DTT_PAGE:
|
|
|
|
mask = ~(PTRS_PER_PTE * sizeof(pte_t) - 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
table = (unsigned long)old & mask;
|
|
|
|
crdte(*old, new, table, dtt, addr, S390_lowcore.kernel_asce);
|
|
|
|
} else if (MACHINE_HAS_IDTE) {
|
|
|
|
cspg(old, *old, new);
|
|
|
|
} else {
|
|
|
|
csp((unsigned int *)old + 1, *old, new);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int walk_pte_level(pmd_t *pmdp, unsigned long addr, unsigned long end,
|
2016-03-22 17:54:24 +08:00
|
|
|
unsigned long flags)
|
2016-05-17 16:50:15 +08:00
|
|
|
{
|
|
|
|
pte_t *ptep, new;
|
|
|
|
|
|
|
|
ptep = pte_offset(pmdp, addr);
|
|
|
|
do {
|
2016-03-22 17:54:24 +08:00
|
|
|
new = *ptep;
|
|
|
|
if (pte_none(new))
|
2016-05-17 16:50:15 +08:00
|
|
|
return -EINVAL;
|
2016-03-22 17:54:24 +08:00
|
|
|
if (flags & SET_MEMORY_RO)
|
|
|
|
new = pte_wrprotect(new);
|
|
|
|
else if (flags & SET_MEMORY_RW)
|
|
|
|
new = pte_mkwrite(pte_mkdirty(new));
|
2017-04-24 21:27:35 +08:00
|
|
|
if (flags & SET_MEMORY_NX)
|
2016-03-22 17:54:24 +08:00
|
|
|
pte_val(new) |= _PAGE_NOEXEC;
|
|
|
|
else if (flags & SET_MEMORY_X)
|
|
|
|
pte_val(new) &= ~_PAGE_NOEXEC;
|
2016-05-17 16:50:15 +08:00
|
|
|
pgt_set((unsigned long *)ptep, pte_val(new), addr, CRDTE_DTT_PAGE);
|
|
|
|
ptep++;
|
|
|
|
addr += PAGE_SIZE;
|
|
|
|
cond_resched();
|
|
|
|
} while (addr < end);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int split_pmd_page(pmd_t *pmdp, unsigned long addr)
|
|
|
|
{
|
|
|
|
unsigned long pte_addr, prot;
|
|
|
|
pte_t *pt_dir, *ptep;
|
|
|
|
pmd_t new;
|
2016-03-22 17:54:24 +08:00
|
|
|
int i, ro, nx;
|
2016-05-17 16:50:15 +08:00
|
|
|
|
|
|
|
pt_dir = vmem_pte_alloc();
|
|
|
|
if (!pt_dir)
|
|
|
|
return -ENOMEM;
|
|
|
|
pte_addr = pmd_pfn(*pmdp) << PAGE_SHIFT;
|
|
|
|
ro = !!(pmd_val(*pmdp) & _SEGMENT_ENTRY_PROTECT);
|
2016-03-22 17:54:24 +08:00
|
|
|
nx = !!(pmd_val(*pmdp) & _SEGMENT_ENTRY_NOEXEC);
|
2016-05-17 16:50:15 +08:00
|
|
|
prot = pgprot_val(ro ? PAGE_KERNEL_RO : PAGE_KERNEL);
|
2016-03-22 17:54:24 +08:00
|
|
|
if (!nx)
|
|
|
|
prot &= ~_PAGE_NOEXEC;
|
2016-05-17 16:50:15 +08:00
|
|
|
ptep = pt_dir;
|
|
|
|
for (i = 0; i < PTRS_PER_PTE; i++) {
|
|
|
|
pte_val(*ptep) = pte_addr | prot;
|
|
|
|
pte_addr += PAGE_SIZE;
|
|
|
|
ptep++;
|
|
|
|
}
|
|
|
|
pmd_val(new) = __pa(pt_dir) | _SEGMENT_ENTRY;
|
|
|
|
pgt_set((unsigned long *)pmdp, pmd_val(new), addr, CRDTE_DTT_SEGMENT);
|
2016-05-20 14:08:14 +08:00
|
|
|
update_page_count(PG_DIRECT_MAP_4K, PTRS_PER_PTE);
|
|
|
|
update_page_count(PG_DIRECT_MAP_1M, -1);
|
2016-05-17 16:50:15 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-22 17:54:24 +08:00
|
|
|
static void modify_pmd_page(pmd_t *pmdp, unsigned long addr,
|
|
|
|
unsigned long flags)
|
2016-05-17 16:50:15 +08:00
|
|
|
{
|
2016-03-22 17:54:24 +08:00
|
|
|
pmd_t new = *pmdp;
|
|
|
|
|
|
|
|
if (flags & SET_MEMORY_RO)
|
|
|
|
new = pmd_wrprotect(new);
|
|
|
|
else if (flags & SET_MEMORY_RW)
|
|
|
|
new = pmd_mkwrite(pmd_mkdirty(new));
|
2017-04-24 21:27:35 +08:00
|
|
|
if (flags & SET_MEMORY_NX)
|
2016-03-22 17:54:24 +08:00
|
|
|
pmd_val(new) |= _SEGMENT_ENTRY_NOEXEC;
|
|
|
|
else if (flags & SET_MEMORY_X)
|
|
|
|
pmd_val(new) &= ~_SEGMENT_ENTRY_NOEXEC;
|
2016-05-17 16:50:15 +08:00
|
|
|
pgt_set((unsigned long *)pmdp, pmd_val(new), addr, CRDTE_DTT_SEGMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int walk_pmd_level(pud_t *pudp, unsigned long addr, unsigned long end,
|
2016-03-22 17:54:24 +08:00
|
|
|
unsigned long flags)
|
2016-05-17 16:50:15 +08:00
|
|
|
{
|
|
|
|
unsigned long next;
|
2012-10-01 22:18:46 +08:00
|
|
|
pmd_t *pmdp;
|
2016-05-17 16:50:15 +08:00
|
|
|
int rc = 0;
|
2012-10-01 22:18:46 +08:00
|
|
|
|
|
|
|
pmdp = pmd_offset(pudp, addr);
|
2016-05-17 16:50:15 +08:00
|
|
|
do {
|
|
|
|
if (pmd_none(*pmdp))
|
|
|
|
return -EINVAL;
|
|
|
|
next = pmd_addr_end(addr, end);
|
|
|
|
if (pmd_large(*pmdp)) {
|
|
|
|
if (addr & ~PMD_MASK || addr + PMD_SIZE > next) {
|
|
|
|
rc = split_pmd_page(pmdp, addr);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-22 17:54:24 +08:00
|
|
|
modify_pmd_page(pmdp, addr, flags);
|
2016-05-17 16:50:15 +08:00
|
|
|
} else {
|
2016-03-22 17:54:24 +08:00
|
|
|
rc = walk_pte_level(pmdp, addr, next, flags);
|
2016-05-17 16:50:15 +08:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
pmdp++;
|
|
|
|
addr = next;
|
|
|
|
cond_resched();
|
|
|
|
} while (addr < end);
|
|
|
|
return rc;
|
2012-10-01 22:18:46 +08:00
|
|
|
}
|
|
|
|
|
2016-05-17 16:50:15 +08:00
|
|
|
static int split_pud_page(pud_t *pudp, unsigned long addr)
|
2011-03-16 00:08:22 +08:00
|
|
|
{
|
2016-05-17 16:50:15 +08:00
|
|
|
unsigned long pmd_addr, prot;
|
|
|
|
pmd_t *pm_dir, *pmdp;
|
|
|
|
pud_t new;
|
2016-03-22 17:54:24 +08:00
|
|
|
int i, ro, nx;
|
2011-03-16 00:08:22 +08:00
|
|
|
|
2017-06-16 23:51:15 +08:00
|
|
|
pm_dir = vmem_crst_alloc(_SEGMENT_ENTRY_EMPTY);
|
2016-05-17 16:50:15 +08:00
|
|
|
if (!pm_dir)
|
|
|
|
return -ENOMEM;
|
|
|
|
pmd_addr = pud_pfn(*pudp) << PAGE_SHIFT;
|
|
|
|
ro = !!(pud_val(*pudp) & _REGION_ENTRY_PROTECT);
|
2016-03-22 17:54:24 +08:00
|
|
|
nx = !!(pud_val(*pudp) & _REGION_ENTRY_NOEXEC);
|
2016-05-17 16:50:15 +08:00
|
|
|
prot = pgprot_val(ro ? SEGMENT_KERNEL_RO : SEGMENT_KERNEL);
|
2016-03-22 17:54:24 +08:00
|
|
|
if (!nx)
|
|
|
|
prot &= ~_SEGMENT_ENTRY_NOEXEC;
|
2016-05-17 16:50:15 +08:00
|
|
|
pmdp = pm_dir;
|
|
|
|
for (i = 0; i < PTRS_PER_PMD; i++) {
|
|
|
|
pmd_val(*pmdp) = pmd_addr | prot;
|
|
|
|
pmd_addr += PMD_SIZE;
|
|
|
|
pmdp++;
|
2011-03-16 00:08:22 +08:00
|
|
|
}
|
2016-05-17 16:50:15 +08:00
|
|
|
pud_val(new) = __pa(pm_dir) | _REGION3_ENTRY;
|
|
|
|
pgt_set((unsigned long *)pudp, pud_val(new), addr, CRDTE_DTT_REGION3);
|
2016-05-20 14:08:14 +08:00
|
|
|
update_page_count(PG_DIRECT_MAP_1M, PTRS_PER_PMD);
|
|
|
|
update_page_count(PG_DIRECT_MAP_2G, -1);
|
2016-05-17 16:50:15 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-22 17:54:24 +08:00
|
|
|
static void modify_pud_page(pud_t *pudp, unsigned long addr,
|
|
|
|
unsigned long flags)
|
2016-05-17 16:50:15 +08:00
|
|
|
{
|
2016-03-22 17:54:24 +08:00
|
|
|
pud_t new = *pudp;
|
|
|
|
|
|
|
|
if (flags & SET_MEMORY_RO)
|
|
|
|
new = pud_wrprotect(new);
|
|
|
|
else if (flags & SET_MEMORY_RW)
|
|
|
|
new = pud_mkwrite(pud_mkdirty(new));
|
2017-04-24 21:27:35 +08:00
|
|
|
if (flags & SET_MEMORY_NX)
|
2016-03-22 17:54:24 +08:00
|
|
|
pud_val(new) |= _REGION_ENTRY_NOEXEC;
|
|
|
|
else if (flags & SET_MEMORY_X)
|
|
|
|
pud_val(new) &= ~_REGION_ENTRY_NOEXEC;
|
2016-05-17 16:50:15 +08:00
|
|
|
pgt_set((unsigned long *)pudp, pud_val(new), addr, CRDTE_DTT_REGION3);
|
|
|
|
}
|
|
|
|
|
2017-04-25 00:19:10 +08:00
|
|
|
static int walk_pud_level(p4d_t *p4d, unsigned long addr, unsigned long end,
|
2016-03-22 17:54:24 +08:00
|
|
|
unsigned long flags)
|
2016-05-17 16:50:15 +08:00
|
|
|
{
|
|
|
|
unsigned long next;
|
|
|
|
pud_t *pudp;
|
|
|
|
int rc = 0;
|
|
|
|
|
2017-04-25 00:19:10 +08:00
|
|
|
pudp = pud_offset(p4d, addr);
|
2016-05-17 16:50:15 +08:00
|
|
|
do {
|
|
|
|
if (pud_none(*pudp))
|
|
|
|
return -EINVAL;
|
|
|
|
next = pud_addr_end(addr, end);
|
|
|
|
if (pud_large(*pudp)) {
|
|
|
|
if (addr & ~PUD_MASK || addr + PUD_SIZE > next) {
|
|
|
|
rc = split_pud_page(pudp, addr);
|
|
|
|
if (rc)
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-22 17:54:24 +08:00
|
|
|
modify_pud_page(pudp, addr, flags);
|
2016-05-17 16:50:15 +08:00
|
|
|
} else {
|
2016-03-22 17:54:24 +08:00
|
|
|
rc = walk_pmd_level(pudp, addr, next, flags);
|
2016-05-17 16:50:15 +08:00
|
|
|
}
|
|
|
|
pudp++;
|
|
|
|
addr = next;
|
|
|
|
cond_resched();
|
|
|
|
} while (addr < end && !rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2017-04-25 00:19:10 +08:00
|
|
|
static int walk_p4d_level(pgd_t *pgd, unsigned long addr, unsigned long end,
|
|
|
|
unsigned long flags)
|
|
|
|
{
|
|
|
|
unsigned long next;
|
|
|
|
p4d_t *p4dp;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
p4dp = p4d_offset(pgd, addr);
|
|
|
|
do {
|
|
|
|
if (p4d_none(*p4dp))
|
|
|
|
return -EINVAL;
|
|
|
|
next = p4d_addr_end(addr, end);
|
|
|
|
rc = walk_pud_level(p4dp, addr, next, flags);
|
|
|
|
p4dp++;
|
|
|
|
addr = next;
|
|
|
|
cond_resched();
|
|
|
|
} while (addr < end && !rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-05-17 16:50:15 +08:00
|
|
|
static DEFINE_MUTEX(cpa_mutex);
|
|
|
|
|
|
|
|
static int change_page_attr(unsigned long addr, unsigned long end,
|
2016-03-22 17:54:24 +08:00
|
|
|
unsigned long flags)
|
2016-05-17 16:50:15 +08:00
|
|
|
{
|
|
|
|
unsigned long next;
|
|
|
|
int rc = -EINVAL;
|
|
|
|
pgd_t *pgdp;
|
|
|
|
|
s390/pageattr: handle numpages parameter correctly
Both set_memory_ro() and set_memory_rw() will modify the page
attributes of at least one page, even if the numpages parameter is
zero.
The author expected that calling these functions with numpages == zero
would never happen. However with the new 444d13ff10fb ("modules: add
ro_after_init support") feature this happens frequently.
Therefore do the right thing and make these two functions return
gracefully if nothing should be done.
Fixes crashes on module load like this one:
Unable to handle kernel pointer dereference in virtual kernel address space
Failing address: 000003ff80008000 TEID: 000003ff80008407
Fault in home space mode while using kernel ASCE.
AS:0000000000d18007 R3:00000001e6aa4007 S:00000001e6a10800 P:00000001e34ee21d
Oops: 0004 ilc:3 [#1] SMP
Modules linked in: x_tables
CPU: 10 PID: 1 Comm: systemd Not tainted 4.7.0-11895-g3fa9045 #4
Hardware name: IBM 2964 N96 703 (LPAR)
task: 00000001e9118000 task.stack: 00000001e9120000
Krnl PSW : 0704e00180000000 00000000005677f8 (rb_erase+0xf0/0x4d0)
R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:2 PM:0 RI:0 EA:3
Krnl GPRS: 000003ff80008b20 000003ff80008b20 000003ff80008b70 0000000000b9d608
000003ff80008b20 0000000000000000 00000001e9123e88 000003ff80008950
00000001e485ab40 000003ff00000000 000003ff80008b00 00000001e4858480
0000000100000000 000003ff80008b68 00000000001d5998 00000001e9123c28
Krnl Code: 00000000005677e8: ec1801c3007c cgij %r1,0,8,567b6e
00000000005677ee: e32010100020 cg %r2,16(%r1)
#00000000005677f4: a78401c2 brc 8,567b78
>00000000005677f8: e35010080024 stg %r5,8(%r1)
00000000005677fe: ec5801af007c cgij %r5,0,8,567b5c
0000000000567804: e30050000024 stg %r0,0(%r5)
000000000056780a: ebacf0680004 lmg %r10,%r12,104(%r15)
0000000000567810: 07fe bcr 15,%r14
Call Trace:
([<000003ff80008900>] __this_module+0x0/0xffffffffffffd700 [x_tables])
([<0000000000264fd4>] do_init_module+0x12c/0x220)
([<00000000001da14a>] load_module+0x24e2/0x2b10)
([<00000000001da976>] SyS_finit_module+0xbe/0xd8)
([<0000000000803b26>] system_call+0xd6/0x264)
Last Breaking-Event-Address:
[<000000000056771a>] rb_erase+0x12/0x4d0
Kernel panic - not syncing: Fatal exception: panic_on_oops
Reported-by: Christian Borntraeger <borntraeger@de.ibm.com>
Reported-and-tested-by: Sebastian Ott <sebott@linux.vnet.ibm.com>
Fixes: e8a97e42dc98 ("s390/pageattr: allow kernel page table splitting")
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2016-08-09 18:26:28 +08:00
|
|
|
if (addr == end)
|
|
|
|
return 0;
|
2016-05-17 16:50:15 +08:00
|
|
|
if (end >= MODULES_END)
|
|
|
|
return -EINVAL;
|
|
|
|
mutex_lock(&cpa_mutex);
|
|
|
|
pgdp = pgd_offset_k(addr);
|
|
|
|
do {
|
|
|
|
if (pgd_none(*pgdp))
|
|
|
|
break;
|
|
|
|
next = pgd_addr_end(addr, end);
|
2017-04-25 00:19:10 +08:00
|
|
|
rc = walk_p4d_level(pgdp, addr, next, flags);
|
2016-05-17 16:50:15 +08:00
|
|
|
if (rc)
|
|
|
|
break;
|
|
|
|
cond_resched();
|
|
|
|
} while (pgdp++, addr = next, addr < end && !rc);
|
|
|
|
mutex_unlock(&cpa_mutex);
|
|
|
|
return rc;
|
2011-03-16 00:08:22 +08:00
|
|
|
}
|
|
|
|
|
2016-03-22 17:54:24 +08:00
|
|
|
int __set_memory(unsigned long addr, int numpages, unsigned long flags)
|
2011-03-16 00:08:22 +08:00
|
|
|
{
|
2017-04-24 21:27:35 +08:00
|
|
|
if (!MACHINE_HAS_NX)
|
|
|
|
flags &= ~(SET_MEMORY_NX | SET_MEMORY_X);
|
|
|
|
if (!flags)
|
|
|
|
return 0;
|
2016-05-17 16:50:15 +08:00
|
|
|
addr &= PAGE_MASK;
|
2016-03-22 17:54:24 +08:00
|
|
|
return change_page_attr(addr, addr + numpages * PAGE_SIZE, flags);
|
2011-05-20 06:55:26 +08:00
|
|
|
}
|
2012-11-02 20:28:48 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_PAGEALLOC
|
2014-09-24 03:29:20 +08:00
|
|
|
|
|
|
|
static void ipte_range(pte_t *pte, unsigned long address, int nr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2015-02-12 20:08:27 +08:00
|
|
|
if (test_facility(13)) {
|
2016-06-14 18:38:40 +08:00
|
|
|
__ptep_ipte_range(address, nr - 1, pte, IPTE_GLOBAL);
|
2014-09-24 03:29:20 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 0; i < nr; i++) {
|
2016-07-26 22:00:22 +08:00
|
|
|
__ptep_ipte(address, pte, 0, 0, IPTE_GLOBAL);
|
2014-09-24 03:29:20 +08:00
|
|
|
address += PAGE_SIZE;
|
|
|
|
pte++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-13 08:55:52 +08:00
|
|
|
void __kernel_map_pages(struct page *page, int numpages, int enable)
|
2012-11-02 20:28:48 +08:00
|
|
|
{
|
|
|
|
unsigned long address;
|
2014-09-24 03:29:20 +08:00
|
|
|
int nr, i, j;
|
2012-11-02 20:28:48 +08:00
|
|
|
pgd_t *pgd;
|
2017-04-25 00:19:10 +08:00
|
|
|
p4d_t *p4d;
|
2012-11-02 20:28:48 +08:00
|
|
|
pud_t *pud;
|
|
|
|
pmd_t *pmd;
|
|
|
|
pte_t *pte;
|
|
|
|
|
2014-09-24 03:29:20 +08:00
|
|
|
for (i = 0; i < numpages;) {
|
2012-11-02 20:28:48 +08:00
|
|
|
address = page_to_phys(page + i);
|
|
|
|
pgd = pgd_offset_k(address);
|
2017-04-25 00:19:10 +08:00
|
|
|
p4d = p4d_offset(pgd, address);
|
|
|
|
pud = pud_offset(p4d, address);
|
2012-11-02 20:28:48 +08:00
|
|
|
pmd = pmd_offset(pud, address);
|
|
|
|
pte = pte_offset_kernel(pmd, address);
|
2014-09-24 03:29:20 +08:00
|
|
|
nr = (unsigned long)pte >> ilog2(sizeof(long));
|
|
|
|
nr = PTRS_PER_PTE - (nr & (PTRS_PER_PTE - 1));
|
|
|
|
nr = min(numpages - i, nr);
|
|
|
|
if (enable) {
|
|
|
|
for (j = 0; j < nr; j++) {
|
2016-03-22 17:54:24 +08:00
|
|
|
pte_val(*pte) &= ~_PAGE_INVALID;
|
2014-09-24 03:29:20 +08:00
|
|
|
address += PAGE_SIZE;
|
|
|
|
pte++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ipte_range(pte, address, nr);
|
2012-11-02 20:28:48 +08:00
|
|
|
}
|
2014-09-24 03:29:20 +08:00
|
|
|
i += nr;
|
2012-11-02 20:28:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_HIBERNATION
|
|
|
|
bool kernel_page_present(struct page *page)
|
|
|
|
{
|
|
|
|
unsigned long addr;
|
|
|
|
int cc;
|
|
|
|
|
|
|
|
addr = page_to_phys(page);
|
|
|
|
asm volatile(
|
|
|
|
" lra %1,0(%1)\n"
|
|
|
|
" ipm %0\n"
|
|
|
|
" srl %0,28"
|
|
|
|
: "=d" (cc), "+a" (addr) : : "cc");
|
|
|
|
return cc == 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_HIBERNATION */
|
|
|
|
|
|
|
|
#endif /* CONFIG_DEBUG_PAGEALLOC */
|