The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/compat/linuxkpi/common/include/linux/mm.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2010 Isilon Systems, Inc.
    3  * Copyright (c) 2010 iX Systems, Inc.
    4  * Copyright (c) 2010 Panasas, Inc.
    5  * Copyright (c) 2013-2017 Mellanox Technologies, Ltd.
    6  * Copyright (c) 2015 François Tigeot
    7  * Copyright (c) 2015 Matthew Dillon <dillon@backplane.com>
    8  * All rights reserved.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice unmodified, this list of conditions, and the following
   15  *    disclaimer.
   16  * 2. Redistributions in binary form must reproduce the above copyright
   17  *    notice, this list of conditions and the following disclaimer in the
   18  *    documentation and/or other materials provided with the distribution.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   30  *
   31  * $FreeBSD$
   32  */
   33 #ifndef _LINUXKPI_LINUX_MM_H_
   34 #define _LINUXKPI_LINUX_MM_H_
   35 
   36 #include <linux/spinlock.h>
   37 #include <linux/gfp.h>
   38 #include <linux/kernel.h>
   39 #include <linux/mm_types.h>
   40 #include <linux/pfn.h>
   41 #include <linux/list.h>
   42 #include <linux/mmap_lock.h>
   43 #include <linux/shrinker.h>
   44 
   45 #include <asm/pgtable.h>
   46 
   47 #define PAGE_ALIGN(x)   ALIGN(x, PAGE_SIZE)
   48 
   49 /*
   50  * Make sure our LinuxKPI defined virtual memory flags don't conflict
   51  * with the ones defined by FreeBSD:
   52  */
   53 CTASSERT((VM_PROT_ALL & -(1 << 8)) == 0);
   54 
   55 #define VM_READ                 VM_PROT_READ
   56 #define VM_WRITE                VM_PROT_WRITE
   57 #define VM_EXEC                 VM_PROT_EXECUTE
   58 
   59 #define VM_PFNINTERNAL          (1 << 8)        /* FreeBSD private flag to vm_insert_pfn() */
   60 #define VM_MIXEDMAP             (1 << 9)
   61 #define VM_NORESERVE            (1 << 10)
   62 #define VM_PFNMAP               (1 << 11)
   63 #define VM_IO                   (1 << 12)
   64 #define VM_MAYWRITE             (1 << 13)
   65 #define VM_DONTCOPY             (1 << 14)
   66 #define VM_DONTEXPAND           (1 << 15)
   67 #define VM_DONTDUMP             (1 << 16)
   68 #define VM_SHARED               (1 << 17)
   69 
   70 #define VMA_MAX_PREFAULT_RECORD 1
   71 
   72 #define FOLL_WRITE              (1 << 0)
   73 #define FOLL_FORCE              (1 << 1)
   74 
   75 #define VM_FAULT_OOM            (1 << 0)
   76 #define VM_FAULT_SIGBUS         (1 << 1)
   77 #define VM_FAULT_MAJOR          (1 << 2)
   78 #define VM_FAULT_WRITE          (1 << 3)
   79 #define VM_FAULT_HWPOISON       (1 << 4)
   80 #define VM_FAULT_HWPOISON_LARGE (1 << 5)
   81 #define VM_FAULT_SIGSEGV        (1 << 6)
   82 #define VM_FAULT_NOPAGE         (1 << 7)
   83 #define VM_FAULT_LOCKED         (1 << 8)
   84 #define VM_FAULT_RETRY          (1 << 9)
   85 #define VM_FAULT_FALLBACK       (1 << 10)
   86 
   87 #define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV | \
   88         VM_FAULT_HWPOISON |VM_FAULT_HWPOISON_LARGE | VM_FAULT_FALLBACK)
   89 
   90 #define FAULT_FLAG_WRITE        (1 << 0)
   91 #define FAULT_FLAG_MKWRITE      (1 << 1)
   92 #define FAULT_FLAG_ALLOW_RETRY  (1 << 2)
   93 #define FAULT_FLAG_RETRY_NOWAIT (1 << 3)
   94 #define FAULT_FLAG_KILLABLE     (1 << 4)
   95 #define FAULT_FLAG_TRIED        (1 << 5)
   96 #define FAULT_FLAG_USER         (1 << 6)
   97 #define FAULT_FLAG_REMOTE       (1 << 7)
   98 #define FAULT_FLAG_INSTRUCTION  (1 << 8)
   99 
  100 #define fault_flag_allow_retry_first(flags) \
  101         (((flags) & (FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_TRIED)) == FAULT_FLAG_ALLOW_RETRY)
  102 
  103 typedef int (*pte_fn_t)(linux_pte_t *, unsigned long addr, void *data);
  104 
  105 struct vm_area_struct {
  106         vm_offset_t vm_start;
  107         vm_offset_t vm_end;
  108         vm_offset_t vm_pgoff;
  109         pgprot_t vm_page_prot;
  110         unsigned long vm_flags;
  111         struct mm_struct *vm_mm;
  112         void   *vm_private_data;
  113         const struct vm_operations_struct *vm_ops;
  114         struct linux_file *vm_file;
  115 
  116         /* internal operation */
  117         vm_paddr_t vm_pfn;              /* PFN for memory map */
  118         vm_size_t vm_len;               /* length for memory map */
  119         vm_pindex_t vm_pfn_first;
  120         int     vm_pfn_count;
  121         int    *vm_pfn_pcount;
  122         vm_object_t vm_obj;
  123         vm_map_t vm_cached_map;
  124         TAILQ_ENTRY(vm_area_struct) vm_entry;
  125 };
  126 
  127 struct vm_fault {
  128         unsigned int flags;
  129         pgoff_t pgoff;
  130         union {
  131                 /* user-space address */
  132                 void *virtual_address;  /* < 4.11 */
  133                 unsigned long address;  /* >= 4.11 */
  134         };
  135         struct page *page;
  136         struct vm_area_struct *vma;
  137 };
  138 
  139 struct vm_operations_struct {
  140         void    (*open) (struct vm_area_struct *);
  141         void    (*close) (struct vm_area_struct *);
  142         int     (*fault) (struct vm_fault *);
  143         int     (*access) (struct vm_area_struct *, unsigned long, void *, int, int);
  144 };
  145 
  146 struct sysinfo {
  147         uint64_t totalram;
  148         uint64_t totalhigh;
  149         uint32_t mem_unit;
  150 };
  151 
  152 /*
  153  * Compute log2 of the power of two rounded up count of pages
  154  * needed for size bytes.
  155  */
  156 static inline int
  157 get_order(unsigned long size)
  158 {
  159         int order;
  160 
  161         size = (size - 1) >> PAGE_SHIFT;
  162         order = 0;
  163         while (size) {
  164                 order++;
  165                 size >>= 1;
  166         }
  167         return (order);
  168 }
  169 
  170 static inline void *
  171 lowmem_page_address(struct page *page)
  172 {
  173         return (page_address(page));
  174 }
  175 
  176 /*
  177  * This only works via memory map operations.
  178  */
  179 static inline int
  180 io_remap_pfn_range(struct vm_area_struct *vma,
  181     unsigned long addr, unsigned long pfn, unsigned long size,
  182     vm_memattr_t prot)
  183 {
  184         vma->vm_page_prot = prot;
  185         vma->vm_pfn = pfn;
  186         vma->vm_len = size;
  187 
  188         return (0);
  189 }
  190 
  191 vm_fault_t
  192 lkpi_vmf_insert_pfn_prot_locked(struct vm_area_struct *vma, unsigned long addr,
  193     unsigned long pfn, pgprot_t prot);
  194 
  195 static inline vm_fault_t
  196 vmf_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr,
  197     unsigned long pfn, pgprot_t prot)
  198 {
  199         vm_fault_t ret;
  200 
  201         VM_OBJECT_WLOCK(vma->vm_obj);
  202         ret = lkpi_vmf_insert_pfn_prot_locked(vma, addr, pfn, prot);
  203         VM_OBJECT_WUNLOCK(vma->vm_obj);
  204 
  205         return (ret);
  206 }
  207 #define vmf_insert_pfn_prot(...)        \
  208         _Static_assert(false,           \
  209 "This function is always called in a loop. Consider using the locked version")
  210 
  211 static inline int
  212 apply_to_page_range(struct mm_struct *mm, unsigned long address,
  213     unsigned long size, pte_fn_t fn, void *data)
  214 {
  215         return (-ENOTSUP);
  216 }
  217 
  218 int zap_vma_ptes(struct vm_area_struct *vma, unsigned long address,
  219     unsigned long size);
  220 
  221 int lkpi_remap_pfn_range(struct vm_area_struct *vma,
  222     unsigned long start_addr, unsigned long start_pfn, unsigned long size,
  223     pgprot_t prot);
  224 
  225 static inline int
  226 remap_pfn_range(struct vm_area_struct *vma, unsigned long addr,
  227     unsigned long pfn, unsigned long size, pgprot_t prot)
  228 {
  229         return (lkpi_remap_pfn_range(vma, addr, pfn, size, prot));
  230 }
  231 
  232 static inline unsigned long
  233 vma_pages(struct vm_area_struct *vma)
  234 {
  235         return ((vma->vm_end - vma->vm_start) >> PAGE_SHIFT);
  236 }
  237 
  238 #define offset_in_page(off)     ((unsigned long)(off) & (PAGE_SIZE - 1))
  239 
  240 static inline void
  241 set_page_dirty(struct vm_page *page)
  242 {
  243         vm_page_dirty(page);
  244 }
  245 
  246 static inline void
  247 mark_page_accessed(struct vm_page *page)
  248 {
  249         vm_page_reference(page);
  250 }
  251 
  252 static inline void
  253 get_page(struct vm_page *page)
  254 {
  255         vm_page_wire(page);
  256 }
  257 
  258 extern long
  259 get_user_pages(unsigned long start, unsigned long nr_pages,
  260     unsigned int gup_flags, struct page **,
  261     struct vm_area_struct **);
  262 
  263 static inline long
  264 pin_user_pages(unsigned long start, unsigned long nr_pages,
  265     unsigned int gup_flags, struct page **pages,
  266     struct vm_area_struct **vmas)
  267 {
  268         return get_user_pages(start, nr_pages, gup_flags, pages, vmas);
  269 }
  270 
  271 extern int
  272 __get_user_pages_fast(unsigned long start, int nr_pages, int write,
  273     struct page **);
  274 
  275 static inline int
  276 pin_user_pages_fast(unsigned long start, int nr_pages,
  277     unsigned int gup_flags, struct page **pages)
  278 {
  279         return __get_user_pages_fast(
  280             start, nr_pages, !!(gup_flags & FOLL_WRITE), pages);
  281 }
  282 
  283 extern long
  284 get_user_pages_remote(struct task_struct *, struct mm_struct *,
  285     unsigned long start, unsigned long nr_pages,
  286     unsigned int gup_flags, struct page **,
  287     struct vm_area_struct **);
  288 
  289 static inline long
  290 pin_user_pages_remote(struct task_struct *task, struct mm_struct *mm,
  291     unsigned long start, unsigned long nr_pages,
  292     unsigned int gup_flags, struct page **pages,
  293     struct vm_area_struct **vmas)
  294 {
  295         return get_user_pages_remote(
  296             task, mm, start, nr_pages, gup_flags, pages, vmas);
  297 }
  298 
  299 static inline void
  300 put_page(struct vm_page *page)
  301 {
  302         vm_page_unwire(page, PQ_ACTIVE);
  303 }
  304 
  305 #define unpin_user_page(page) put_page(page)
  306 #define unpin_user_pages(pages, npages) release_pages(pages, npages)
  307 
  308 #define copy_highpage(to, from) pmap_copy_page(from, to)
  309 
  310 static inline pgprot_t
  311 vm_get_page_prot(unsigned long vm_flags)
  312 {
  313         return (vm_flags & VM_PROT_ALL);
  314 }
  315 
  316 static inline vm_page_t
  317 vmalloc_to_page(const void *addr)
  318 {
  319         vm_paddr_t paddr;
  320 
  321         paddr = pmap_kextract((vm_offset_t)addr);
  322         return (PHYS_TO_VM_PAGE(paddr));
  323 }
  324 
  325 static inline int
  326 trylock_page(struct page *page)
  327 {
  328         return (vm_page_trylock(page));
  329 }
  330 
  331 static inline void
  332 unlock_page(struct page *page)
  333 {
  334 
  335         vm_page_unlock(page);
  336 }
  337 
  338 extern int is_vmalloc_addr(const void *addr);
  339 void si_meminfo(struct sysinfo *si);
  340 
  341 #define unmap_mapping_range(...)        lkpi_unmap_mapping_range(__VA_ARGS__)
  342 void lkpi_unmap_mapping_range(void *obj, loff_t const holebegin __unused,
  343     loff_t const holelen, int even_cows __unused);
  344 
  345 #define PAGE_ALIGNED(p) __is_aligned(p, PAGE_SIZE)
  346 
  347 void vma_set_file(struct vm_area_struct *vma, struct linux_file *file);
  348 
  349 #define is_cow_mapping(flags)   (false)
  350 
  351 #endif                                  /* _LINUXKPI_LINUX_MM_H_ */

Cache object: 67fe66eac0a6ef6127a5fb5ae12eb8c3


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.