Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __SPARC_MMAN_H__
0003 #define __SPARC_MMAN_H__
0004 
0005 #include <uapi/asm/mman.h>
0006 
0007 #ifndef __ASSEMBLY__
0008 #define arch_mmap_check(addr,len,flags) sparc_mmap_check(addr,len)
0009 int sparc_mmap_check(unsigned long addr, unsigned long len);
0010 
0011 #ifdef CONFIG_SPARC64
0012 #include <asm/adi_64.h>
0013 
0014 static inline void ipi_set_tstate_mcde(void *arg)
0015 {
0016     struct mm_struct *mm = arg;
0017 
0018     /* Set TSTATE_MCDE for the task using address map that ADI has been
0019      * enabled on if the task is running. If not, it will be set
0020      * automatically at the next context switch
0021      */
0022     if (current->mm == mm) {
0023         struct pt_regs *regs;
0024 
0025         regs = task_pt_regs(current);
0026         regs->tstate |= TSTATE_MCDE;
0027     }
0028 }
0029 
0030 #define arch_calc_vm_prot_bits(prot, pkey) sparc_calc_vm_prot_bits(prot)
0031 static inline unsigned long sparc_calc_vm_prot_bits(unsigned long prot)
0032 {
0033     if (adi_capable() && (prot & PROT_ADI)) {
0034         struct pt_regs *regs;
0035 
0036         if (!current->mm->context.adi) {
0037             regs = task_pt_regs(current);
0038             regs->tstate |= TSTATE_MCDE;
0039             current->mm->context.adi = true;
0040             on_each_cpu_mask(mm_cpumask(current->mm),
0041                      ipi_set_tstate_mcde, current->mm, 0);
0042         }
0043         return VM_SPARC_ADI;
0044     } else {
0045         return 0;
0046     }
0047 }
0048 
0049 #define arch_validate_prot(prot, addr) sparc_validate_prot(prot, addr)
0050 static inline int sparc_validate_prot(unsigned long prot, unsigned long addr)
0051 {
0052     if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM | PROT_ADI))
0053         return 0;
0054     return 1;
0055 }
0056 
0057 #define arch_validate_flags(vm_flags) arch_validate_flags(vm_flags)
0058 /* arch_validate_flags() - Ensure combination of flags is valid for a
0059  *  VMA.
0060  */
0061 static inline bool arch_validate_flags(unsigned long vm_flags)
0062 {
0063     /* If ADI is being enabled on this VMA, check for ADI
0064      * capability on the platform and ensure VMA is suitable
0065      * for ADI
0066      */
0067     if (vm_flags & VM_SPARC_ADI) {
0068         if (!adi_capable())
0069             return false;
0070 
0071         /* ADI can not be enabled on PFN mapped pages */
0072         if (vm_flags & (VM_PFNMAP | VM_MIXEDMAP))
0073             return false;
0074 
0075         /* Mergeable pages can become unmergeable
0076          * if ADI is enabled on them even if they
0077          * have identical data on them. This can be
0078          * because ADI enabled pages with identical
0079          * data may still not have identical ADI
0080          * tags on them. Disallow ADI on mergeable
0081          * pages.
0082          */
0083         if (vm_flags & VM_MERGEABLE)
0084             return false;
0085     }
0086     return true;
0087 }
0088 #endif /* CONFIG_SPARC64 */
0089 
0090 #endif /* __ASSEMBLY__ */
0091 #endif /* __SPARC_MMAN_H__ */