105d4f501SHans Petter Selasky /*-
205d4f501SHans Petter Selasky * Copyright (c) 2017 Mellanox Technologies, Ltd.
305d4f501SHans Petter Selasky * All rights reserved.
405d4f501SHans Petter Selasky *
505d4f501SHans Petter Selasky * Redistribution and use in source and binary forms, with or without
605d4f501SHans Petter Selasky * modification, are permitted provided that the following conditions
705d4f501SHans Petter Selasky * are met:
805d4f501SHans Petter Selasky * 1. Redistributions of source code must retain the above copyright
905d4f501SHans Petter Selasky * notice unmodified, this list of conditions, and the following
1005d4f501SHans Petter Selasky * disclaimer.
1105d4f501SHans Petter Selasky * 2. Redistributions in binary form must reproduce the above copyright
1205d4f501SHans Petter Selasky * notice, this list of conditions and the following disclaimer in the
1305d4f501SHans Petter Selasky * documentation and/or other materials provided with the distribution.
1405d4f501SHans Petter Selasky *
1505d4f501SHans Petter Selasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1605d4f501SHans Petter Selasky * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1705d4f501SHans Petter Selasky * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1805d4f501SHans Petter Selasky * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1905d4f501SHans Petter Selasky * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2005d4f501SHans Petter Selasky * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2105d4f501SHans Petter Selasky * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2205d4f501SHans Petter Selasky * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2305d4f501SHans Petter Selasky * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2405d4f501SHans Petter Selasky * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2505d4f501SHans Petter Selasky */
2605d4f501SHans Petter Selasky
27307f78f3SVladimir Kondratyev #ifndef _LINUXKPI_LINUX_MM_TYPES_H_
28307f78f3SVladimir Kondratyev #define _LINUXKPI_LINUX_MM_TYPES_H_
2905d4f501SHans Petter Selasky
3005d4f501SHans Petter Selasky #include <linux/types.h>
3105d4f501SHans Petter Selasky #include <linux/page.h>
32b292c995SJean-Sébastien Pédron #include <linux/rbtree.h>
3305d4f501SHans Petter Selasky #include <linux/rwsem.h>
3405d4f501SHans Petter Selasky
3505d4f501SHans Petter Selasky #include <asm/atomic.h>
3605d4f501SHans Petter Selasky
371462308dSJohannes Lundberg typedef int vm_fault_t;
381462308dSJohannes Lundberg
3905d4f501SHans Petter Selasky struct vm_area_struct;
4005d4f501SHans Petter Selasky struct task_struct;
4105d4f501SHans Petter Selasky
4205d4f501SHans Petter Selasky struct mm_struct {
4305d4f501SHans Petter Selasky struct vm_area_struct *mmap;
4405d4f501SHans Petter Selasky atomic_t mm_count;
4505d4f501SHans Petter Selasky atomic_t mm_users;
4605d4f501SHans Petter Selasky size_t pinned_vm;
47995c3b88SEmmanuel Vadot /* Renamed to mmap_lock in v5.8 */
4805d4f501SHans Petter Selasky struct rw_semaphore mmap_sem;
4905d4f501SHans Petter Selasky };
5005d4f501SHans Petter Selasky
5105d4f501SHans Petter Selasky extern void linux_mm_dtor(struct mm_struct *mm);
5205d4f501SHans Petter Selasky
5305d4f501SHans Petter Selasky static inline void
mmdrop(struct mm_struct * mm)5405d4f501SHans Petter Selasky mmdrop(struct mm_struct *mm)
5505d4f501SHans Petter Selasky {
5605d4f501SHans Petter Selasky if (__predict_false(atomic_dec_and_test(&mm->mm_count)))
5705d4f501SHans Petter Selasky linux_mm_dtor(mm);
5805d4f501SHans Petter Selasky }
5905d4f501SHans Petter Selasky
60b9a6330dSHans Petter Selasky static inline bool
mmget_not_zero(struct mm_struct * mm)61b9a6330dSHans Petter Selasky mmget_not_zero(struct mm_struct *mm)
62b9a6330dSHans Petter Selasky {
63b9a6330dSHans Petter Selasky return (atomic_inc_not_zero(&mm->mm_users));
64b9a6330dSHans Petter Selasky }
65b9a6330dSHans Petter Selasky
6605d4f501SHans Petter Selasky static inline void
mmput(struct mm_struct * mm)6705d4f501SHans Petter Selasky mmput(struct mm_struct *mm)
6805d4f501SHans Petter Selasky {
6905d4f501SHans Petter Selasky if (__predict_false(atomic_dec_and_test(&mm->mm_users)))
7005d4f501SHans Petter Selasky mmdrop(mm);
7105d4f501SHans Petter Selasky }
7205d4f501SHans Petter Selasky
7313a27c3bSHans Petter Selasky static inline void
mmgrab(struct mm_struct * mm)7413a27c3bSHans Petter Selasky mmgrab(struct mm_struct *mm)
7513a27c3bSHans Petter Selasky {
7613a27c3bSHans Petter Selasky atomic_inc(&mm->mm_count);
7713a27c3bSHans Petter Selasky }
7813a27c3bSHans Petter Selasky
7905d4f501SHans Petter Selasky extern struct mm_struct *linux_get_task_mm(struct task_struct *);
8005d4f501SHans Petter Selasky #define get_task_mm(task) linux_get_task_mm(task)
8105d4f501SHans Petter Selasky
82307f78f3SVladimir Kondratyev #endif /* _LINUXKPI_LINUX_MM_TYPES_H_ */
83