[PATCH v3 2/3] powerpc: mm: add p{te,md,ud}_user_accessible_page helpers

Rohan McLure rmclure at linux.ibm.com
Mon Nov 7 09:47:34 AEDT 2022


> On 3 Nov 2022, at 7:02 pm, Christophe Leroy <christophe.leroy at csgroup.eu> wrote:
> 
> 
> 
> Le 24/10/2022 à 02:35, Rohan McLure a écrit :
>> 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
>> 
>> Also implement missing pud_user definitions for both Book3S/nohash 64-bit
>> systems, and pmd_user for Book3S/nohash 32-bit systems.
>> 
>> Signed-off-by: Rohan McLure <rmclure at linux.ibm.com>
>> ---
>> V2: Provide missing pud_user implementations, use p{u,m}d_is_leaf.
>> V3: Provide missing pmd_user implementations as stubs in 32-bit.
>> ---
>>  arch/powerpc/include/asm/book3s/32/pgtable.h |  4 ++++
>>  arch/powerpc/include/asm/book3s/64/pgtable.h | 10 ++++++++++
>>  arch/powerpc/include/asm/nohash/32/pgtable.h |  1 +
>>  arch/powerpc/include/asm/nohash/64/pgtable.h | 10 ++++++++++
>>  arch/powerpc/include/asm/pgtable.h           | 15 +++++++++++++++
>>  5 files changed, 40 insertions(+)
>> 
>> diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h b/arch/powerpc/include/asm/book3s/32/pgtable.h
>> index 40041ac713d9..8bf1c538839a 100644
>> --- a/arch/powerpc/include/asm/book3s/32/pgtable.h
>> +++ b/arch/powerpc/include/asm/book3s/32/pgtable.h
>> @@ -531,6 +531,10 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
>>   return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
>>  }
>> 
>> +static inline bool pmd_user(pmd_t pmd)
>> +{
>> + return 0;
>> +}
>> 
>> 
>>  /* This low level function performs the actual PTE insertion
>> diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
>> index f9aefa492df0..3083111f9d0a 100644
>> --- a/arch/powerpc/include/asm/book3s/64/pgtable.h
>> +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
>> @@ -621,6 +621,16 @@ static inline bool pte_user(pte_t pte)
>>   return !(pte_raw(pte) & cpu_to_be64(_PAGE_PRIVILEGED));
>>  }
>> 
>> +static inline bool pmd_user(pmd_t pmd)
>> +{
>> + return !(pmd_raw(pmd) & cpu_to_be64(_PAGE_PRIVILEGED));
>> +}
>> +
>> +static inline bool pud_user(pud_t pud)
>> +{
>> + return !(pud_raw(pud) & cpu_to_be64(_PAGE_PRIVILEGED));
>> +}
>> +
>>  #define pte_access_permitted pte_access_permitted
>>  static inline bool pte_access_permitted(pte_t pte, bool write)
>>  {
>> diff --git a/arch/powerpc/include/asm/nohash/32/pgtable.h b/arch/powerpc/include/asm/nohash/32/pgtable.h
>> index 9091e4904a6b..b92044d9d778 100644
>> --- a/arch/powerpc/include/asm/nohash/32/pgtable.h
>> +++ b/arch/powerpc/include/asm/nohash/32/pgtable.h
>> @@ -354,6 +354,7 @@ static inline int pte_young(pte_t pte)
>>  #endif
>> 
>>  #define pmd_page(pmd) pfn_to_page(pmd_pfn(pmd))
>> +#define pmd_user(pmd) 0
>>  /*
>>   * Encode and decode a swap entry.
>>   * Note that the bits we use in a PTE for representing a swap entry
>> diff --git a/arch/powerpc/include/asm/nohash/64/pgtable.h b/arch/powerpc/include/asm/nohash/64/pgtable.h
>> index 599921cc257e..23c5135178d1 100644
>> --- a/arch/powerpc/include/asm/nohash/64/pgtable.h
>> +++ b/arch/powerpc/include/asm/nohash/64/pgtable.h
>> @@ -123,6 +123,11 @@ static inline pte_t pmd_pte(pmd_t pmd)
>>   return __pte(pmd_val(pmd));
>>  }
>> 
>> +static inline bool pmd_user(pmd_t pmd)
>> +{
>> + return (pmd_val(pmd) & _PAGE_USER) == _PAGE_USER;
>> +}
>> +
>>  #define pmd_none(pmd) (!pmd_val(pmd))
>>  #define pmd_bad(pmd) (!is_kernel_addr(pmd_val(pmd)) \
>>    || (pmd_val(pmd) & PMD_BAD_BITS))
>> @@ -158,6 +163,11 @@ static inline pte_t pud_pte(pud_t pud)
>>   return __pte(pud_val(pud));
>>  }
>> 
>> +static inline bool pud_user(pud_t pud)
>> +{
>> + return (pud_val(pud) & _PAGE_USER) == _PAGE_USER;
>> +}
>> +
>>  static inline pud_t pte_pud(pte_t pte)
>>  {
>>   return __pud(pte_val(pte));
>> diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
>> index 36956fb440e1..3cb5de9f1aa4 100644
>> --- a/arch/powerpc/include/asm/pgtable.h
>> +++ b/arch/powerpc/include/asm/pgtable.h
>> @@ -172,6 +172,21 @@ static inline int pud_pfn(pud_t pud)
>>  }
>>  #endif
>> 
>> +static inline bool pte_user_accessible_page(pte_t pte)
>> +{
>> + return pte_present(pte) && pte_user(pte);
>> +}
>> +
>> +static inline bool pmd_user_accessible_page(pmd_t pmd)
>> +{
>> + return pmd_is_leaf(pmd) && pmd_present(pmd) && pmd_user(pmd);
> 
> pmd_is_leaf() is specific to powerpc and we may want to get rid of it.
> 
> Can you use pmd_leaf() instead ?
> 
>> +}
>> +
>> +static inline bool pud_user_accessible_page(pud_t pud)
>> +{
>> + return pud_is_leaf(pud) && pud_present(pud) && pud_user(pud);
> 
> pud_is_leaf() is specific to powerpc and we may want to get rid of it.
> 
> Can you use pud_leaf() instead ?

Going to resend, replacing all usages/definitions of p{m,u,4}d_is_leaf()
with p{m,u,4}_leaf() in arch/powerpc prior to this patch.

> 
>> +}
>> +
>>  #endif /* __ASSEMBLY__ */
>> 
>>  #endif /* _ASM_POWERPC_PGTABLE_H */




More information about the Linuxppc-dev mailing list