powerpc: introduce get_mm_addr_key() helper
authorRam Pai <linuxram@us.ibm.com>
Fri, 19 Jan 2018 01:50:41 +0000 (17:50 -0800)
committerMichael Ellerman <mpe@ellerman.id.au>
Sat, 20 Jan 2018 11:59:05 +0000 (22:59 +1100)
get_mm_addr_key() helper returns the pkey associated with
an address corresponding to a given mm_struct.

Signed-off-by: Ram Pai <linuxram@us.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/include/asm/mmu.h
arch/powerpc/mm/hash_utils_64.c

index 6364f5c2cc3e6bbee1244a8a6dce09f968987b70..bb38312cff28ceba0ece038a4523dd22ce0910fa 100644 (file)
@@ -260,6 +260,15 @@ static inline bool early_radix_enabled(void)
 }
 #endif
 
+#ifdef CONFIG_PPC_MEM_KEYS
+extern u16 get_mm_addr_key(struct mm_struct *mm, unsigned long address);
+#else
+static inline u16 get_mm_addr_key(struct mm_struct *mm, unsigned long address)
+{
+       return 0;
+}
+#endif /* CONFIG_PPC_MEM_KEYS */
+
 #endif /* !__ASSEMBLY__ */
 
 /* The kernel use the constants below to index in the page sizes array.
index a78e24cf93ffe6d9cd9a5ec3130901fb9dc7d81f..462c34e7b01d294eb5ae7621c1440b94a6f302b0 100644 (file)
@@ -1581,6 +1581,30 @@ out_exit:
        local_irq_restore(flags);
 }
 
+#ifdef CONFIG_PPC_MEM_KEYS
+/*
+ * Return the protection key associated with the given address and the
+ * mm_struct.
+ */
+u16 get_mm_addr_key(struct mm_struct *mm, unsigned long address)
+{
+       pte_t *ptep;
+       u16 pkey = 0;
+       unsigned long flags;
+
+       if (!mm || !mm->pgd)
+               return 0;
+
+       local_irq_save(flags);
+       ptep = find_linux_pte(mm->pgd, address, NULL, NULL);
+       if (ptep)
+               pkey = pte_to_pkey_bits(pte_val(READ_ONCE(*ptep)));
+       local_irq_restore(flags);
+
+       return pkey;
+}
+#endif /* CONFIG_PPC_MEM_KEYS */
+
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
 static inline void tm_flush_hash_page(int local)
 {