From: Rohan McLure <rmclure@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: Rohan McLure <rmclure@linux.ibm.com>
Subject: [PATCH 2/3] powerpc: mm: add p{te,md,ud}_user_accessible_page helpers
Date: Mon, 12 Sep 2022 11:47:02 +1000 [thread overview]
Message-ID: <20220912014703.185471-2-rmclure@linux.ibm.com> (raw)
In-Reply-To: <20220912014703.185471-1-rmclure@linux.ibm.com>
Add the following helpers for detecting whether a page table entry
is a leaf and is accessible to user space.
* pte_user_accessible_page
* pmd_user_accessible_page
* pud_user_accessible_page
The heavy lifting is done by pte_user, which checks user accessibility
on a per-mmu level, provided prior to this commit.
On 32-bit systems, provide stub implementations for these methods, with
BUG(), as debug features such as page table checks will emit functions
that call p{md,ud}_user_accessible_page but must not be used.
Signed-off-by: Rohan McLure <rmclure@linux.ibm.com>
---
arch/powerpc/include/asm/pgtable.h | 35 ++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
index 522145b16a07..8c1f5feb9360 100644
--- a/arch/powerpc/include/asm/pgtable.h
+++ b/arch/powerpc/include/asm/pgtable.h
@@ -170,6 +170,41 @@ static inline int pud_pfn(pud_t pud)
return 0;
}
+static inline bool pte_user_accessible_page(pte_t pte)
+{
+ return (pte_val(pte) & _PAGE_PRESENT) && pte_user(pte);
+}
+
+#ifdef CONFIG_PPC64
+
+static inline bool pmd_user_accessible_page(pmd_t pmd)
+{
+ return pmd_is_leaf(pmd) && pmd_present(pmd)
+ && pte_user(pmd_pte(pmd));
+}
+
+static inline bool pud_user_accessible_page(pud_t pud)
+{
+ return pud_is_leaf(pud) && pud_present(pud)
+ && pte_user(pud_pte(pud));
+}
+
+#else
+
+static inline bool pmd_user_accessible_page(pmd_t pmd)
+{
+ BUG();
+ return false;
+}
+
+static inline bool pud_user_accessible_page(pud_t pud)
+{
+ BUG();
+ return false;
+}
+
+#endif /* CONFIG_PPC64 */
+
#endif /* __ASSEMBLY__ */
#endif /* _ASM_POWERPC_PGTABLE_H */
--
2.34.1
next prev parent reply other threads:[~2022-09-12 1:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-12 1:47 [PATCH 1/3] powerpc: mm: move pud_pfn stub to common pgtable header Rohan McLure
2022-09-12 1:47 ` Rohan McLure [this message]
2022-09-12 5:40 ` [PATCH 2/3] powerpc: mm: add p{te,md,ud}_user_accessible_page helpers Christophe Leroy
2022-09-12 8:38 ` Rohan McLure
2022-09-13 14:12 ` Christophe Leroy
2022-09-12 1:47 ` [PATCH 3/3] powerpc: mm: support page table check Rohan McLure
2022-09-12 6:11 ` Christophe Leroy
2022-09-13 1:21 ` Rohan McLure
2022-09-13 14:36 ` Christophe Leroy
2022-09-12 1:51 ` [PATCH 1/3] powerpc: mm: move pud_pfn stub to common pgtable header Rohan McLure
2022-09-12 5:30 ` Christophe Leroy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220912014703.185471-2-rmclure@linux.ibm.com \
--to=rmclure@linux.ibm.com \
--cc=linuxppc-dev@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).