lkml.org 
[lkml]   [2019]   [Jul]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC v2 05/26] mm/asi: Add ASI page-table entry offset functions
Date
Add wrappers around the p4d/pud/pmd/pte offset kernel functions which
ensure that page-table pointers are in the specified ASI page-table.

Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
---
arch/x86/mm/asi_pagetable.c | 62 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/arch/x86/mm/asi_pagetable.c b/arch/x86/mm/asi_pagetable.c
index 7a8f791..a89e02e 100644
--- a/arch/x86/mm/asi_pagetable.c
+++ b/arch/x86/mm/asi_pagetable.c
@@ -97,3 +97,65 @@ static bool asi_valid_offset(struct asi *asi, void *offset)

return valid;
}
+
+/*
+ * asi_pXX_offset() functions are equivalent to kernel pXX_offset()
+ * functions but, in addition, they ensure that page table pointers
+ * are in the kernel isolation page table. Otherwise an error is
+ * returned.
+ */
+
+static pte_t *asi_pte_offset(struct asi *asi, pmd_t *pmd, unsigned long addr)
+{
+ pte_t *pte;
+
+ pte = pte_offset_map(pmd, addr);
+ if (!asi_valid_offset(asi, pte)) {
+ pr_err("ASI %p: PTE %px not found\n", asi, pte);
+ return ERR_PTR(-EINVAL);
+ }
+
+ return pte;
+}
+
+static pmd_t *asi_pmd_offset(struct asi *asi, pud_t *pud, unsigned long addr)
+{
+ pmd_t *pmd;
+
+ pmd = pmd_offset(pud, addr);
+ if (!asi_valid_offset(asi, pmd)) {
+ pr_err("ASI %p: PMD %px not found\n", asi, pmd);
+ return ERR_PTR(-EINVAL);
+ }
+
+ return pmd;
+}
+
+static pud_t *asi_pud_offset(struct asi *asi, p4d_t *p4d, unsigned long addr)
+{
+ pud_t *pud;
+
+ pud = pud_offset(p4d, addr);
+ if (!asi_valid_offset(asi, pud)) {
+ pr_err("ASI %p: PUD %px not found\n", asi, pud);
+ return ERR_PTR(-EINVAL);
+ }
+
+ return pud;
+}
+
+static p4d_t *asi_p4d_offset(struct asi *asi, pgd_t *pgd, unsigned long addr)
+{
+ p4d_t *p4d;
+
+ p4d = p4d_offset(pgd, addr);
+ /*
+ * p4d is the same has pgd if we don't have a 5-level page table.
+ */
+ if ((p4d != (p4d_t *)pgd) && !asi_valid_offset(asi, p4d)) {
+ pr_err("ASI %p: P4D %px not found\n", asi, p4d);
+ return ERR_PTR(-EINVAL);
+ }
+
+ return p4d;
+}
--
1.7.1
\
 
 \ /
  Last update: 2019-07-11 16:28    [W:0.177 / U:37.420 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site