[PATCH v6 2/4] x86/mm/pat: Convert pmd code to use page table apis

Vishal Moola (Oracle) posted 4 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v6 2/4] x86/mm/pat: Convert pmd code to use page table apis
Posted by Vishal Moola (Oracle) 1 month, 1 week ago
We need all allocation and free sites to use the ptdesc APIs in order to
allocate them separately from regular pages. Convert the pmd
allocation/free sites to use the generic page table apis, since those
use ptdescs already.

Pass through init_mm since these are kernel page tables, pmd_alloc_one()
needs it to identify kernel page tables. Also, the generic implementation
doesn't use the second argument. Pass it a placeholder so we don't have
to reimplement it or risk breaking other architectures.

Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
---
 arch/x86/mm/pat/set_memory.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index d52010fd3023..655bef618ea0 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -1420,7 +1420,7 @@ static bool try_to_free_pmd_page(pmd_t *pmd)
 		if (!pmd_none(pmd[i]))
 			return false;
 
-	free_page((unsigned long)pmd);
+	pmd_free(&init_mm, pmd);
 	return true;
 }
 
@@ -1549,7 +1549,10 @@ static int alloc_pte_page(pmd_t *pmd)
 
 static int alloc_pmd_page(pud_t *pud)
 {
-	pmd_t *pmd = (pmd_t *)get_zeroed_page(GFP_KERNEL);
+	/* The generic implementation of pmd_alloc_one() doesn't use
+	 * the second argument. Pass it 0 as a placeholder.
+	 */
+	pmd_t *pmd = pmd_alloc_one(&init_mm, 0);
 	if (!pmd)
 		return -1;
 
-- 
2.53.0