--- v5
+++ v1
@@ -2,11 +2,10 @@
ptdesc equivalents, convert various page table functions to use ptdescs.
Some of the functions use the *get*page*() helper functions. Convert
-these to use pagetable_alloc() and ptdesc_address() instead to help
+these to use ptdesc_alloc() and ptdesc_address() instead to help
standardize page tables further.
Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
-Acked-by: Mike Rapoport (IBM) <rppt@kernel.org>
---
arch/s390/include/asm/pgalloc.h | 4 +-
arch/s390/include/asm/tlb.h | 4 +-
@@ -14,7 +13,7 @@
3 files changed, 59 insertions(+), 57 deletions(-)
diff --git a/arch/s390/include/asm/pgalloc.h b/arch/s390/include/asm/pgalloc.h
-index 17eb618f1348..00ad9b88fda9 100644
+index 17eb618f1348..9841481560ae 100644
--- a/arch/s390/include/asm/pgalloc.h
+++ b/arch/s390/include/asm/pgalloc.h
@@ -86,7 +86,7 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long vmaddr)
@@ -22,7 +21,7 @@
return NULL;
crst_table_init(table, _SEGMENT_ENTRY_EMPTY);
- if (!pgtable_pmd_page_ctor(virt_to_page(table))) {
-+ if (!pagetable_pmd_ctor(virt_to_ptdesc(table))) {
++ if (!ptdesc_pmd_ctor(virt_to_ptdesc(table))) {
crst_table_free(mm, table);
return NULL;
}
@@ -31,12 +30,12 @@
if (mm_pmd_folded(mm))
return;
- pgtable_pmd_page_dtor(virt_to_page(pmd));
-+ pagetable_pmd_dtor(virt_to_ptdesc(pmd));
++ ptdesc_pmd_dtor(virt_to_ptdesc(pmd));
crst_table_free(mm, (unsigned long *) pmd);
}
diff --git a/arch/s390/include/asm/tlb.h b/arch/s390/include/asm/tlb.h
-index b91f4a9b044c..383b1f91442c 100644
+index b91f4a9b044c..1388c819b467 100644
--- a/arch/s390/include/asm/tlb.h
+++ b/arch/s390/include/asm/tlb.h
@@ -89,12 +89,12 @@ static inline void pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
@@ -44,7 +43,7 @@
if (mm_pmd_folded(tlb->mm))
return;
- pgtable_pmd_page_dtor(virt_to_page(pmd));
-+ pagetable_pmd_dtor(virt_to_ptdesc(pmd));
++ ptdesc_pmd_dtor(virt_to_ptdesc(pmd));
__tlb_adjust_range(tlb, address, PAGE_SIZE);
tlb->mm->context.flush_mm = 1;
tlb->freed_tables = 1;
@@ -55,7 +54,7 @@
/*
diff --git a/arch/s390/mm/pgalloc.c b/arch/s390/mm/pgalloc.c
-index 66ab68db9842..79b1c2458d85 100644
+index 6b99932abc66..16a29d2cfe85 100644
--- a/arch/s390/mm/pgalloc.c
+++ b/arch/s390/mm/pgalloc.c
@@ -43,17 +43,17 @@ __initcall(page_table_register_sysctl);
@@ -63,7 +62,7 @@
unsigned long *crst_table_alloc(struct mm_struct *mm)
{
- struct page *page = alloc_pages(GFP_KERNEL, CRST_ALLOC_ORDER);
-+ struct ptdesc *ptdesc = pagetable_alloc(GFP_KERNEL, CRST_ALLOC_ORDER);
++ struct ptdesc *ptdesc = ptdesc(GFP_KERNEL, CRST_ALLOC_ORDER);
- if (!page)
+ if (!ptdesc)
@@ -77,7 +76,7 @@
void crst_table_free(struct mm_struct *mm, unsigned long *table)
{
- free_pages((unsigned long)table, CRST_ALLOC_ORDER);
-+ pagetable_free(virt_to_ptdesc(table));
++ ptdesc_free(virt_to_ptdesc(table);
}
static void __crst_table_upgrade(void *arg)
@@ -86,15 +85,15 @@
struct page *page_table_alloc_pgste(struct mm_struct *mm)
{
- struct page *page;
-+ struct ptdesc *ptdesc;
++ struct page *ptdesc;
u64 *table;
- page = alloc_page(GFP_KERNEL);
- if (page) {
- table = (u64 *)page_to_virt(page);
-+ ptdesc = pagetable_alloc(GFP_KERNEL, 0);
++ ptdesc = ptdesc_alloc(GFP_KERNEL, 0);
+ if (ptdesc) {
-+ table = (u64 *)ptdesc_to_virt(ptdesc);
++ table = (u64 *)ptdesc_to_virt(page);
memset64(table, _PAGE_INVALID, PTRS_PER_PTE);
memset64(table + PTRS_PER_PTE, 0, PTRS_PER_PTE);
}
@@ -105,11 +104,11 @@
void page_table_free_pgste(struct page *page)
{
- __free_page(page);
-+ pagetable_free(page_ptdesc(page));
++ ptdesc_free(page_ptdesc(page));
}
#endif /* CONFIG_PGSTE */
-@@ -233,7 +233,7 @@ void page_table_free_pgste(struct page *page)
+@@ -230,7 +230,7 @@ void page_table_free_pgste(struct page *page)
unsigned long *page_table_alloc(struct mm_struct *mm)
{
unsigned long *table;
@@ -118,20 +117,20 @@
unsigned int mask, bit;
/* Try to get a fragment of a 4K page as a 2K page table */
-@@ -241,9 +241,9 @@ unsigned long *page_table_alloc(struct mm_struct *mm)
+@@ -238,9 +238,9 @@ unsigned long *page_table_alloc(struct mm_struct *mm)
table = NULL;
spin_lock_bh(&mm->context.lock);
if (!list_empty(&mm->context.pgtable_list)) {
- page = list_first_entry(&mm->context.pgtable_list,
- struct page, lru);
-- mask = atomic_read(&page->_refcount) >> 24;
+- mask = atomic_read(&page->pt_frag_refcount);
+ ptdesc = list_first_entry(&mm->context.pgtable_list,
+ struct ptdesc, pt_list);
-+ mask = atomic_read(&ptdesc->_refcount) >> 24;
++ mask = atomic_read(&ptdesc->pt_frag_refcount);
/*
* The pending removal bits must also be checked.
* Failure to do so might lead to an impossible
-@@ -255,13 +255,13 @@ unsigned long *page_table_alloc(struct mm_struct *mm)
+@@ -253,13 +253,13 @@ unsigned long *page_table_alloc(struct mm_struct *mm)
*/
mask = (mask | (mask >> 4)) & 0x03U;
if (mask != 0x03U) {
@@ -140,27 +139,27 @@
bit = mask & 1; /* =1 -> second 2K */
if (bit)
table += PTRS_PER_PTE;
-- atomic_xor_bits(&page->_refcount,
-+ atomic_xor_bits(&ptdesc->_refcount,
- 0x01U << (bit + 24));
+- atomic_xor_bits(&page->pt_frag_refcount,
++ atomic_xor_bits(&ptdesc->pt_frag_refcount,
+ 0x01U << bit);
- list_del(&page->lru);
+ list_del(&ptdesc->pt_list);
}
}
spin_unlock_bh(&mm->context.lock);
-@@ -269,27 +269,27 @@ unsigned long *page_table_alloc(struct mm_struct *mm)
+@@ -267,27 +267,27 @@ unsigned long *page_table_alloc(struct mm_struct *mm)
return table;
}
/* Allocate a fresh page */
- page = alloc_page(GFP_KERNEL);
- if (!page)
-+ ptdesc = pagetable_alloc(GFP_KERNEL, 0);
++ ptdesc = ptdesc_alloc(GFP_KERNEL, 0);
+ if (!ptdesc)
return NULL;
- if (!pgtable_pte_page_ctor(page)) {
- __free_page(page);
-+ if (!pagetable_pte_ctor(ptdesc)) {
-+ pagetable_free(ptdesc);
++ if (!ptdesc_pte_ctor(ptdesc)) {
++ ptdesc_free(ptdesc);
return NULL;
}
- arch_set_page_dat(page, 0);
@@ -170,14 +169,14 @@
+ table = (unsigned long *) ptdesc_to_virt(ptdesc);
if (mm_alloc_pgste(mm)) {
/* Return 4K page table with PGSTEs */
-- atomic_xor_bits(&page->_refcount, 0x03U << 24);
-+ atomic_xor_bits(&ptdesc->_refcount, 0x03U << 24);
+- atomic_xor_bits(&page->pt_frag_refcount, 0x03U);
++ atomic_xor_bits(&ptdesc->pt_frag_refcount, 0x03U);
memset64((u64 *)table, _PAGE_INVALID, PTRS_PER_PTE);
memset64((u64 *)table + PTRS_PER_PTE, 0, PTRS_PER_PTE);
} else {
/* Return the first 2K fragment of the page */
-- atomic_xor_bits(&page->_refcount, 0x01U << 24);
-+ atomic_xor_bits(&ptdesc->_refcount, 0x01U << 24);
+- atomic_xor_bits(&page->pt_frag_refcount, 0x01U);
++ atomic_xor_bits(&ptdesc->pt_frag_refcount, 0x01U);
memset64((u64 *)table, _PAGE_INVALID, 2 * PTRS_PER_PTE);
spin_lock_bh(&mm->context.lock);
- list_add(&page->lru, &mm->context.pgtable_list);
@@ -185,7 +184,7 @@
spin_unlock_bh(&mm->context.lock);
}
return table;
-@@ -311,9 +311,8 @@ static void page_table_release_check(struct page *page, void *table,
+@@ -309,9 +309,8 @@ static void page_table_release_check(struct page *page, void *table,
void page_table_free(struct mm_struct *mm, unsigned long *table)
{
unsigned int mask, bit, half;
@@ -196,13 +195,12 @@
if (!mm_alloc_pgste(mm)) {
/* Free 2K page table fragment of a 4K page */
bit = ((unsigned long) table & ~PAGE_MASK)/(PTRS_PER_PTE*sizeof(pte_t));
-@@ -323,42 +322,41 @@ void page_table_free(struct mm_struct *mm, unsigned long *table)
+@@ -321,39 +320,38 @@ void page_table_free(struct mm_struct *mm, unsigned long *table)
* will happen outside of the critical section from this
* function or from __tlb_remove_table()
*/
-- mask = atomic_xor_bits(&page->_refcount, 0x11U << (bit + 24));
-+ mask = atomic_xor_bits(&ptdesc->_refcount, 0x11U << (bit + 24));
- mask >>= 24;
+- mask = atomic_xor_bits(&page->pt_frag_refcount, 0x11U << bit);
++ mask = atomic_xor_bits(&ptdesc->pt_frag_refcount, 0x11U << bit);
if (mask & 0x03U)
- list_add(&page->lru, &mm->context.pgtable_list);
+ list_add(&ptdesc->pt_list, &mm->context.pgtable_list);
@@ -210,25 +208,23 @@
- list_del(&page->lru);
+ list_del(&ptdesc->pt_list);
spin_unlock_bh(&mm->context.lock);
-- mask = atomic_xor_bits(&page->_refcount, 0x10U << (bit + 24));
-+ mask = atomic_xor_bits(&ptdesc->_refcount, 0x10U << (bit + 24));
- mask >>= 24;
+- mask = atomic_xor_bits(&page->pt_frag_refcount, 0x10U << bit);
++ mask = atomic_xor_bits(&ptdesc->pt_frag_refcount, 0x10U << bit);
if (mask != 0x00U)
return;
half = 0x01U << bit;
} else {
half = 0x03U;
-- mask = atomic_xor_bits(&page->_refcount, 0x03U << 24);
-+ mask = atomic_xor_bits(&ptdesc->_refcount, 0x03U << 24);
- mask >>= 24;
+- mask = atomic_xor_bits(&page->pt_frag_refcount, 0x03U);
++ mask = atomic_xor_bits(&ptdesc->pt_frag_refcount, 0x03U);
}
- page_table_release_check(page, table, half, mask);
- pgtable_pte_page_dtor(page);
- __free_page(page);
+ page_table_release_check(ptdesc_page(ptdesc), table, half, mask);
-+ pagetable_pte_dtor(ptdesc);
-+ pagetable_free(ptdesc);
++ ptdesc_pte_dtor(ptdesc);
++ ptdesc_free(ptdesc);
}
void page_table_free_rcu(struct mmu_gather *tlb, unsigned long *table,
@@ -249,13 +245,12 @@
return;
}
bit = ((unsigned long) table & ~PAGE_MASK) / (PTRS_PER_PTE*sizeof(pte_t));
-@@ -368,12 +366,12 @@ void page_table_free_rcu(struct mmu_gather *tlb, unsigned long *table,
+@@ -363,11 +361,11 @@ void page_table_free_rcu(struct mmu_gather *tlb, unsigned long *table,
* outside of the critical section from __tlb_remove_table() or from
* page_table_free()
*/
-- mask = atomic_xor_bits(&page->_refcount, 0x11U << (bit + 24));
-+ mask = atomic_xor_bits(&ptdesc->_refcount, 0x11U << (bit + 24));
- mask >>= 24;
+- mask = atomic_xor_bits(&page->pt_frag_refcount, 0x11U << bit);
++ mask = atomic_xor_bits(&ptdesc->pt_frag_refcount, 0x11U << bit);
if (mask & 0x03U)
- list_add_tail(&page->lru, &mm->context.pgtable_list);
+ list_add_tail(&ptdesc->pt_list, &mm->context.pgtable_list);
@@ -265,7 +260,7 @@
spin_unlock_bh(&mm->context.lock);
table = (unsigned long *) ((unsigned long) table | (0x01U << bit));
tlb_remove_table(tlb, table);
-@@ -383,7 +381,7 @@ void __tlb_remove_table(void *_table)
+@@ -377,7 +375,7 @@ void __tlb_remove_table(void *_table)
{
unsigned int mask = (unsigned long) _table & 0x03U, half = mask;
void *table = (void *)((unsigned long) _table ^ mask);
@@ -274,20 +269,18 @@
switch (half) {
case 0x00U: /* pmd, pud, or p4d */
-@@ -391,20 +389,20 @@ void __tlb_remove_table(void *_table)
+@@ -385,18 +383,18 @@ void __tlb_remove_table(void *_table)
return;
case 0x01U: /* lower 2K of a 4K page table */
case 0x02U: /* higher 2K of a 4K page table */
-- mask = atomic_xor_bits(&page->_refcount, mask << (4 + 24));
-+ mask = atomic_xor_bits(&ptdesc->_refcount, mask << (4 + 24));
- mask >>= 24;
+- mask = atomic_xor_bits(&page->pt_frag_refcount, mask << 4);
++ mask = atomic_xor_bits(&ptdesc->pt_frag_refcount, mask << 4);
if (mask != 0x00U)
return;
break;
case 0x03U: /* 4K page table with pgstes */
-- mask = atomic_xor_bits(&page->_refcount, 0x03U << 24);
-+ mask = atomic_xor_bits(&ptdesc->_refcount, 0x03U << 24);
- mask >>= 24;
+- mask = atomic_xor_bits(&page->pt_frag_refcount, 0x03U);
++ mask = atomic_xor_bits(&ptdesc->pt_frag_refcount, 0x03U);
break;
}
@@ -295,12 +288,12 @@
- pgtable_pte_page_dtor(page);
- __free_page(page);
+ page_table_release_check(ptdesc_page(ptdesc), table, half, mask);
-+ pagetable_pte_dtor(ptdesc);
-+ pagetable_free(ptdesc);
++ ptdesc_pte_dtor(ptdesc);
++ ptdesc_free(ptdesc);
}
/*
-@@ -432,16 +430,20 @@ static void base_pgt_free(unsigned long *table)
+@@ -424,16 +422,20 @@ static void base_pgt_free(unsigned long *table)
static unsigned long *base_crst_alloc(unsigned long val)
{
unsigned long *table;
@@ -309,7 +302,7 @@
- table = (unsigned long *)__get_free_pages(GFP_KERNEL, CRST_ALLOC_ORDER);
- if (table)
- crst_table_init(table, val);
-+ ptdesc = pagetable_alloc(GFP_KERNEL & ~__GFP_HIGHMEM, CRST_ALLOC_ORDER);
++ ptdesc = ptdesc_alloc(GFP_KERNEL, CRST_ALLOC_ORDER);
+ if (!ptdesc)
+ return NULL;
+ table = ptdesc_address(ptdesc);
@@ -321,10 +314,10 @@
static void base_crst_free(unsigned long *table)
{
- free_pages((unsigned long)table, CRST_ALLOC_ORDER);
-+ pagetable_free(virt_to_ptdesc(table));
++ ptdesc_free(virt_to_ptdesc(table));
}
#define BASE_ADDR_END_FUNC(NAME, SIZE) \
--
-2.40.1
+2.39.2