1dd873966SEric Auger /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2c1fcf220SDr. David Alan Gilbert /* 3c1fcf220SDr. David Alan Gilbert * include/linux/userfaultfd.h 4c1fcf220SDr. David Alan Gilbert * 5c1fcf220SDr. David Alan Gilbert * Copyright (C) 2007 Davide Libenzi <davidel@xmailserver.org> 6c1fcf220SDr. David Alan Gilbert * Copyright (C) 2015 Red Hat, Inc. 7c1fcf220SDr. David Alan Gilbert * 8c1fcf220SDr. David Alan Gilbert */ 9c1fcf220SDr. David Alan Gilbert 10c1fcf220SDr. David Alan Gilbert #ifndef _LINUX_USERFAULTFD_H 11c1fcf220SDr. David Alan Gilbert #define _LINUX_USERFAULTFD_H 12c1fcf220SDr. David Alan Gilbert 13c1fcf220SDr. David Alan Gilbert #include <linux/types.h> 14c1fcf220SDr. David Alan Gilbert 1593e0932bSPeter Xu /* ioctls for /dev/userfaultfd */ 1693e0932bSPeter Xu #define USERFAULTFD_IOC 0xAA 1793e0932bSPeter Xu #define USERFAULTFD_IOC_NEW _IO(USERFAULTFD_IOC, 0x00) 1893e0932bSPeter Xu 19c1fcf220SDr. David Alan Gilbert /* 203a5eb5b4SPaolo Bonzini * If the UFFDIO_API is upgraded someday, the UFFDIO_UNREGISTER and 213a5eb5b4SPaolo Bonzini * UFFDIO_WAKE ioctls should be defined as _IOW and not as _IOR. In 223a5eb5b4SPaolo Bonzini * userfaultfd.h we assumed the kernel was reading (instead _IOC_READ 233a5eb5b4SPaolo Bonzini * means the userland is reading). 24c1fcf220SDr. David Alan Gilbert */ 253a5eb5b4SPaolo Bonzini #define UFFD_API ((__u64)0xAA) 26278f064eSEduardo Habkost #define UFFD_API_REGISTER_MODES (UFFDIO_REGISTER_MODE_MISSING | \ 27278f064eSEduardo Habkost UFFDIO_REGISTER_MODE_WP | \ 28278f064eSEduardo Habkost UFFDIO_REGISTER_MODE_MINOR) 29dc6f8d45SCornelia Huck #define UFFD_API_FEATURES (UFFD_FEATURE_PAGEFAULT_FLAG_WP | \ 30dc6f8d45SCornelia Huck UFFD_FEATURE_EVENT_FORK | \ 313a5eb5b4SPaolo Bonzini UFFD_FEATURE_EVENT_REMAP | \ 3274c98e20SCornelia Huck UFFD_FEATURE_EVENT_REMOVE | \ 3374c98e20SCornelia Huck UFFD_FEATURE_EVENT_UNMAP | \ 343a5eb5b4SPaolo Bonzini UFFD_FEATURE_MISSING_HUGETLBFS | \ 35d4083f50SAlexey Perevalov UFFD_FEATURE_MISSING_SHMEM | \ 36d4083f50SAlexey Perevalov UFFD_FEATURE_SIGBUS | \ 37278f064eSEduardo Habkost UFFD_FEATURE_THREAD_ID | \ 38327d4b7fSBharata B Rao UFFD_FEATURE_MINOR_HUGETLBFS | \ 39e4082063SAlex Williamson UFFD_FEATURE_MINOR_SHMEM | \ 40d525f73fSChenyi Qiang UFFD_FEATURE_EXACT_ADDRESS | \ 41d0bf492fSCédric Le Goater UFFD_FEATURE_WP_HUGETLBFS_SHMEM | \ 42da3c22c7SThomas Huth UFFD_FEATURE_WP_UNPOPULATED | \ 43efb91426SDaniel Henrique Barboza UFFD_FEATURE_POISON | \ 44*6a02465fSDaniel Henrique Barboza UFFD_FEATURE_WP_ASYNC | \ 45*6a02465fSDaniel Henrique Barboza UFFD_FEATURE_MOVE) 46c1fcf220SDr. David Alan Gilbert #define UFFD_API_IOCTLS \ 47c1fcf220SDr. David Alan Gilbert ((__u64)1 << _UFFDIO_REGISTER | \ 48c1fcf220SDr. David Alan Gilbert (__u64)1 << _UFFDIO_UNREGISTER | \ 49c1fcf220SDr. David Alan Gilbert (__u64)1 << _UFFDIO_API) 50c1fcf220SDr. David Alan Gilbert #define UFFD_API_RANGE_IOCTLS \ 51c1fcf220SDr. David Alan Gilbert ((__u64)1 << _UFFDIO_WAKE | \ 52c1fcf220SDr. David Alan Gilbert (__u64)1 << _UFFDIO_COPY | \ 53dc6f8d45SCornelia Huck (__u64)1 << _UFFDIO_ZEROPAGE | \ 54*6a02465fSDaniel Henrique Barboza (__u64)1 << _UFFDIO_MOVE | \ 55278f064eSEduardo Habkost (__u64)1 << _UFFDIO_WRITEPROTECT | \ 56da3c22c7SThomas Huth (__u64)1 << _UFFDIO_CONTINUE | \ 57da3c22c7SThomas Huth (__u64)1 << _UFFDIO_POISON) 583a5eb5b4SPaolo Bonzini #define UFFD_API_RANGE_IOCTLS_BASIC \ 593a5eb5b4SPaolo Bonzini ((__u64)1 << _UFFDIO_WAKE | \ 60278f064eSEduardo Habkost (__u64)1 << _UFFDIO_COPY | \ 61da3c22c7SThomas Huth (__u64)1 << _UFFDIO_WRITEPROTECT | \ 62d525f73fSChenyi Qiang (__u64)1 << _UFFDIO_CONTINUE | \ 63da3c22c7SThomas Huth (__u64)1 << _UFFDIO_POISON) 64c1fcf220SDr. David Alan Gilbert 65c1fcf220SDr. David Alan Gilbert /* 66c1fcf220SDr. David Alan Gilbert * Valid ioctl command number range with this API is from 0x00 to 67c1fcf220SDr. David Alan Gilbert * 0x3F. UFFDIO_API is the fixed number, everything else can be 68c1fcf220SDr. David Alan Gilbert * changed by implementing a different UFFD_API. If sticking to the 69c1fcf220SDr. David Alan Gilbert * same UFFD_API more ioctl can be added and userland will be aware of 70c1fcf220SDr. David Alan Gilbert * which ioctl the running kernel implements through the ioctl command 71c1fcf220SDr. David Alan Gilbert * bitmask written by the UFFDIO_API. 72c1fcf220SDr. David Alan Gilbert */ 73c1fcf220SDr. David Alan Gilbert #define _UFFDIO_REGISTER (0x00) 74c1fcf220SDr. David Alan Gilbert #define _UFFDIO_UNREGISTER (0x01) 75c1fcf220SDr. David Alan Gilbert #define _UFFDIO_WAKE (0x02) 76c1fcf220SDr. David Alan Gilbert #define _UFFDIO_COPY (0x03) 77c1fcf220SDr. David Alan Gilbert #define _UFFDIO_ZEROPAGE (0x04) 78*6a02465fSDaniel Henrique Barboza #define _UFFDIO_MOVE (0x05) 79dc6f8d45SCornelia Huck #define _UFFDIO_WRITEPROTECT (0x06) 80278f064eSEduardo Habkost #define _UFFDIO_CONTINUE (0x07) 81da3c22c7SThomas Huth #define _UFFDIO_POISON (0x08) 82c1fcf220SDr. David Alan Gilbert #define _UFFDIO_API (0x3F) 83c1fcf220SDr. David Alan Gilbert 84c1fcf220SDr. David Alan Gilbert /* userfaultfd ioctl ids */ 85c1fcf220SDr. David Alan Gilbert #define UFFDIO 0xAA 86c1fcf220SDr. David Alan Gilbert #define UFFDIO_API _IOWR(UFFDIO, _UFFDIO_API, \ 87c1fcf220SDr. David Alan Gilbert struct uffdio_api) 88c1fcf220SDr. David Alan Gilbert #define UFFDIO_REGISTER _IOWR(UFFDIO, _UFFDIO_REGISTER, \ 89c1fcf220SDr. David Alan Gilbert struct uffdio_register) 90c1fcf220SDr. David Alan Gilbert #define UFFDIO_UNREGISTER _IOR(UFFDIO, _UFFDIO_UNREGISTER, \ 91c1fcf220SDr. David Alan Gilbert struct uffdio_range) 92c1fcf220SDr. David Alan Gilbert #define UFFDIO_WAKE _IOR(UFFDIO, _UFFDIO_WAKE, \ 93c1fcf220SDr. David Alan Gilbert struct uffdio_range) 94c1fcf220SDr. David Alan Gilbert #define UFFDIO_COPY _IOWR(UFFDIO, _UFFDIO_COPY, \ 95c1fcf220SDr. David Alan Gilbert struct uffdio_copy) 96c1fcf220SDr. David Alan Gilbert #define UFFDIO_ZEROPAGE _IOWR(UFFDIO, _UFFDIO_ZEROPAGE, \ 97c1fcf220SDr. David Alan Gilbert struct uffdio_zeropage) 98*6a02465fSDaniel Henrique Barboza #define UFFDIO_MOVE _IOWR(UFFDIO, _UFFDIO_MOVE, \ 99*6a02465fSDaniel Henrique Barboza struct uffdio_move) 100dc6f8d45SCornelia Huck #define UFFDIO_WRITEPROTECT _IOWR(UFFDIO, _UFFDIO_WRITEPROTECT, \ 101dc6f8d45SCornelia Huck struct uffdio_writeprotect) 102327d4b7fSBharata B Rao #define UFFDIO_CONTINUE _IOWR(UFFDIO, _UFFDIO_CONTINUE, \ 103278f064eSEduardo Habkost struct uffdio_continue) 104da3c22c7SThomas Huth #define UFFDIO_POISON _IOWR(UFFDIO, _UFFDIO_POISON, \ 105da3c22c7SThomas Huth struct uffdio_poison) 106c1fcf220SDr. David Alan Gilbert 107c1fcf220SDr. David Alan Gilbert /* read() structure */ 108c1fcf220SDr. David Alan Gilbert struct uffd_msg { 109c1fcf220SDr. David Alan Gilbert __u8 event; 110c1fcf220SDr. David Alan Gilbert 111c1fcf220SDr. David Alan Gilbert __u8 reserved1; 112c1fcf220SDr. David Alan Gilbert __u16 reserved2; 113c1fcf220SDr. David Alan Gilbert __u32 reserved3; 114c1fcf220SDr. David Alan Gilbert 115c1fcf220SDr. David Alan Gilbert union { 116c1fcf220SDr. David Alan Gilbert struct { 117c1fcf220SDr. David Alan Gilbert __u64 flags; 118c1fcf220SDr. David Alan Gilbert __u64 address; 119d4083f50SAlexey Perevalov union { 120d4083f50SAlexey Perevalov __u32 ptid; 121d4083f50SAlexey Perevalov } feat; 122c1fcf220SDr. David Alan Gilbert } pagefault; 123c1fcf220SDr. David Alan Gilbert 124c1fcf220SDr. David Alan Gilbert struct { 1253a5eb5b4SPaolo Bonzini __u32 ufd; 1263a5eb5b4SPaolo Bonzini } fork; 1273a5eb5b4SPaolo Bonzini 1283a5eb5b4SPaolo Bonzini struct { 1293a5eb5b4SPaolo Bonzini __u64 from; 1303a5eb5b4SPaolo Bonzini __u64 to; 1313a5eb5b4SPaolo Bonzini __u64 len; 1323a5eb5b4SPaolo Bonzini } remap; 1333a5eb5b4SPaolo Bonzini 1343a5eb5b4SPaolo Bonzini struct { 1353a5eb5b4SPaolo Bonzini __u64 start; 1363a5eb5b4SPaolo Bonzini __u64 end; 13774c98e20SCornelia Huck } remove; 1383a5eb5b4SPaolo Bonzini 1393a5eb5b4SPaolo Bonzini struct { 140c1fcf220SDr. David Alan Gilbert /* unused reserved fields */ 141c1fcf220SDr. David Alan Gilbert __u64 reserved1; 142c1fcf220SDr. David Alan Gilbert __u64 reserved2; 143c1fcf220SDr. David Alan Gilbert __u64 reserved3; 144c1fcf220SDr. David Alan Gilbert } reserved; 145c1fcf220SDr. David Alan Gilbert } arg; 146b89485a5SPaolo Bonzini } __attribute__((packed)); 147c1fcf220SDr. David Alan Gilbert 148c1fcf220SDr. David Alan Gilbert /* 149c1fcf220SDr. David Alan Gilbert * Start at 0x12 and not at 0 to be more strict against bugs. 150c1fcf220SDr. David Alan Gilbert */ 151c1fcf220SDr. David Alan Gilbert #define UFFD_EVENT_PAGEFAULT 0x12 152c1fcf220SDr. David Alan Gilbert #define UFFD_EVENT_FORK 0x13 1533a5eb5b4SPaolo Bonzini #define UFFD_EVENT_REMAP 0x14 15474c98e20SCornelia Huck #define UFFD_EVENT_REMOVE 0x15 15574c98e20SCornelia Huck #define UFFD_EVENT_UNMAP 0x16 156c1fcf220SDr. David Alan Gilbert 157c1fcf220SDr. David Alan Gilbert /* flags for UFFD_EVENT_PAGEFAULT */ 158c1fcf220SDr. David Alan Gilbert #define UFFD_PAGEFAULT_FLAG_WRITE (1<<0) /* If this was a write fault */ 159c1fcf220SDr. David Alan Gilbert #define UFFD_PAGEFAULT_FLAG_WP (1<<1) /* If reason is VM_UFFD_WP */ 160278f064eSEduardo Habkost #define UFFD_PAGEFAULT_FLAG_MINOR (1<<2) /* If reason is VM_UFFD_MINOR */ 161c1fcf220SDr. David Alan Gilbert 162c1fcf220SDr. David Alan Gilbert struct uffdio_api { 163c1fcf220SDr. David Alan Gilbert /* userland asks for an API number and the features to enable */ 164c1fcf220SDr. David Alan Gilbert __u64 api; 165c1fcf220SDr. David Alan Gilbert /* 166c1fcf220SDr. David Alan Gilbert * Kernel answers below with the all available features for 167c1fcf220SDr. David Alan Gilbert * the API, this notifies userland of which events and/or 168c1fcf220SDr. David Alan Gilbert * which flags for each event are enabled in the current 169c1fcf220SDr. David Alan Gilbert * kernel. 170c1fcf220SDr. David Alan Gilbert * 171c1fcf220SDr. David Alan Gilbert * Note: UFFD_EVENT_PAGEFAULT and UFFD_PAGEFAULT_FLAG_WRITE 172c1fcf220SDr. David Alan Gilbert * are to be considered implicitly always enabled in all kernels as 173c1fcf220SDr. David Alan Gilbert * long as the uffdio_api.api requested matches UFFD_API. 1743a5eb5b4SPaolo Bonzini * 1753a5eb5b4SPaolo Bonzini * UFFD_FEATURE_MISSING_HUGETLBFS means an UFFDIO_REGISTER 1763a5eb5b4SPaolo Bonzini * with UFFDIO_REGISTER_MODE_MISSING mode will succeed on 1773a5eb5b4SPaolo Bonzini * hugetlbfs virtual memory ranges. Adding or not adding 1783a5eb5b4SPaolo Bonzini * UFFD_FEATURE_MISSING_HUGETLBFS to uffdio_api.features has 1793a5eb5b4SPaolo Bonzini * no real functional effect after UFFDIO_API returns, but 1803a5eb5b4SPaolo Bonzini * it's only useful for an initial feature set probe at 1813a5eb5b4SPaolo Bonzini * UFFDIO_API time. There are two ways to use it: 1823a5eb5b4SPaolo Bonzini * 1833a5eb5b4SPaolo Bonzini * 1) by adding UFFD_FEATURE_MISSING_HUGETLBFS to the 1843a5eb5b4SPaolo Bonzini * uffdio_api.features before calling UFFDIO_API, an error 1853a5eb5b4SPaolo Bonzini * will be returned by UFFDIO_API on a kernel without 1863a5eb5b4SPaolo Bonzini * hugetlbfs missing support 1873a5eb5b4SPaolo Bonzini * 1883a5eb5b4SPaolo Bonzini * 2) the UFFD_FEATURE_MISSING_HUGETLBFS can not be added in 1893a5eb5b4SPaolo Bonzini * uffdio_api.features and instead it will be set by the 1903a5eb5b4SPaolo Bonzini * kernel in the uffdio_api.features if the kernel supports 1913a5eb5b4SPaolo Bonzini * it, so userland can later check if the feature flag is 1923a5eb5b4SPaolo Bonzini * present in uffdio_api.features after UFFDIO_API 1933a5eb5b4SPaolo Bonzini * succeeded. 1943a5eb5b4SPaolo Bonzini * 1953a5eb5b4SPaolo Bonzini * UFFD_FEATURE_MISSING_SHMEM works the same as 1963a5eb5b4SPaolo Bonzini * UFFD_FEATURE_MISSING_HUGETLBFS, but it applies to shmem 1973a5eb5b4SPaolo Bonzini * (i.e. tmpfs and other shmem based APIs). 198d4083f50SAlexey Perevalov * 199d4083f50SAlexey Perevalov * UFFD_FEATURE_SIGBUS feature means no page-fault 200d4083f50SAlexey Perevalov * (UFFD_EVENT_PAGEFAULT) event will be delivered, instead 201d4083f50SAlexey Perevalov * a SIGBUS signal will be sent to the faulting process. 202d4083f50SAlexey Perevalov * 203d4083f50SAlexey Perevalov * UFFD_FEATURE_THREAD_ID pid of the page faulted task_struct will 204d4083f50SAlexey Perevalov * be returned, if feature is not requested 0 will be returned. 205278f064eSEduardo Habkost * 206278f064eSEduardo Habkost * UFFD_FEATURE_MINOR_HUGETLBFS indicates that minor faults 207278f064eSEduardo Habkost * can be intercepted (via REGISTER_MODE_MINOR) for 208278f064eSEduardo Habkost * hugetlbfs-backed pages. 209327d4b7fSBharata B Rao * 210327d4b7fSBharata B Rao * UFFD_FEATURE_MINOR_SHMEM indicates the same support as 211327d4b7fSBharata B Rao * UFFD_FEATURE_MINOR_HUGETLBFS, but for shmem-backed pages instead. 212e4082063SAlex Williamson * 213e4082063SAlex Williamson * UFFD_FEATURE_EXACT_ADDRESS indicates that the exact address of page 214e4082063SAlex Williamson * faults would be provided and the offset within the page would not be 215e4082063SAlex Williamson * masked. 216d525f73fSChenyi Qiang * 217d525f73fSChenyi Qiang * UFFD_FEATURE_WP_HUGETLBFS_SHMEM indicates that userfaultfd 218d525f73fSChenyi Qiang * write-protection mode is supported on both shmem and hugetlbfs. 219d0bf492fSCédric Le Goater * 220d0bf492fSCédric Le Goater * UFFD_FEATURE_WP_UNPOPULATED indicates that userfaultfd 221d0bf492fSCédric Le Goater * write-protection mode will always apply to unpopulated pages 222d0bf492fSCédric Le Goater * (i.e. empty ptes). This will be the default behavior for shmem 223d0bf492fSCédric Le Goater * & hugetlbfs, so this flag only affects anonymous memory behavior 224d0bf492fSCédric Le Goater * when userfault write-protection mode is registered. 225efb91426SDaniel Henrique Barboza * 226efb91426SDaniel Henrique Barboza * UFFD_FEATURE_WP_ASYNC indicates that userfaultfd write-protection 227efb91426SDaniel Henrique Barboza * asynchronous mode is supported in which the write fault is 228efb91426SDaniel Henrique Barboza * automatically resolved and write-protection is un-set. 229efb91426SDaniel Henrique Barboza * It implies UFFD_FEATURE_WP_UNPOPULATED. 230*6a02465fSDaniel Henrique Barboza * 231*6a02465fSDaniel Henrique Barboza * UFFD_FEATURE_MOVE indicates that the kernel supports moving an 232*6a02465fSDaniel Henrique Barboza * existing page contents from userspace. 233c1fcf220SDr. David Alan Gilbert */ 234c1fcf220SDr. David Alan Gilbert #define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0) 235c1fcf220SDr. David Alan Gilbert #define UFFD_FEATURE_EVENT_FORK (1<<1) 2363a5eb5b4SPaolo Bonzini #define UFFD_FEATURE_EVENT_REMAP (1<<2) 23774c98e20SCornelia Huck #define UFFD_FEATURE_EVENT_REMOVE (1<<3) 2383a5eb5b4SPaolo Bonzini #define UFFD_FEATURE_MISSING_HUGETLBFS (1<<4) 2393a5eb5b4SPaolo Bonzini #define UFFD_FEATURE_MISSING_SHMEM (1<<5) 24074c98e20SCornelia Huck #define UFFD_FEATURE_EVENT_UNMAP (1<<6) 241d4083f50SAlexey Perevalov #define UFFD_FEATURE_SIGBUS (1<<7) 242d4083f50SAlexey Perevalov #define UFFD_FEATURE_THREAD_ID (1<<8) 243278f064eSEduardo Habkost #define UFFD_FEATURE_MINOR_HUGETLBFS (1<<9) 244327d4b7fSBharata B Rao #define UFFD_FEATURE_MINOR_SHMEM (1<<10) 245e4082063SAlex Williamson #define UFFD_FEATURE_EXACT_ADDRESS (1<<11) 246d525f73fSChenyi Qiang #define UFFD_FEATURE_WP_HUGETLBFS_SHMEM (1<<12) 247d0bf492fSCédric Le Goater #define UFFD_FEATURE_WP_UNPOPULATED (1<<13) 248da3c22c7SThomas Huth #define UFFD_FEATURE_POISON (1<<14) 249efb91426SDaniel Henrique Barboza #define UFFD_FEATURE_WP_ASYNC (1<<15) 250*6a02465fSDaniel Henrique Barboza #define UFFD_FEATURE_MOVE (1<<16) 251c1fcf220SDr. David Alan Gilbert __u64 features; 252c1fcf220SDr. David Alan Gilbert 253c1fcf220SDr. David Alan Gilbert __u64 ioctls; 254c1fcf220SDr. David Alan Gilbert }; 255c1fcf220SDr. David Alan Gilbert 256c1fcf220SDr. David Alan Gilbert struct uffdio_range { 257c1fcf220SDr. David Alan Gilbert __u64 start; 258c1fcf220SDr. David Alan Gilbert __u64 len; 259c1fcf220SDr. David Alan Gilbert }; 260c1fcf220SDr. David Alan Gilbert 261c1fcf220SDr. David Alan Gilbert struct uffdio_register { 262c1fcf220SDr. David Alan Gilbert struct uffdio_range range; 263c1fcf220SDr. David Alan Gilbert #define UFFDIO_REGISTER_MODE_MISSING ((__u64)1<<0) 264c1fcf220SDr. David Alan Gilbert #define UFFDIO_REGISTER_MODE_WP ((__u64)1<<1) 265278f064eSEduardo Habkost #define UFFDIO_REGISTER_MODE_MINOR ((__u64)1<<2) 266c1fcf220SDr. David Alan Gilbert __u64 mode; 267c1fcf220SDr. David Alan Gilbert 268c1fcf220SDr. David Alan Gilbert /* 269c1fcf220SDr. David Alan Gilbert * kernel answers which ioctl commands are available for the 270c1fcf220SDr. David Alan Gilbert * range, keep at the end as the last 8 bytes aren't read. 271c1fcf220SDr. David Alan Gilbert */ 272c1fcf220SDr. David Alan Gilbert __u64 ioctls; 273c1fcf220SDr. David Alan Gilbert }; 274c1fcf220SDr. David Alan Gilbert 275c1fcf220SDr. David Alan Gilbert struct uffdio_copy { 276c1fcf220SDr. David Alan Gilbert __u64 dst; 277c1fcf220SDr. David Alan Gilbert __u64 src; 278c1fcf220SDr. David Alan Gilbert __u64 len; 279c1fcf220SDr. David Alan Gilbert #define UFFDIO_COPY_MODE_DONTWAKE ((__u64)1<<0) 280dc6f8d45SCornelia Huck /* 281dc6f8d45SCornelia Huck * UFFDIO_COPY_MODE_WP will map the page write protected on 282dc6f8d45SCornelia Huck * the fly. UFFDIO_COPY_MODE_WP is available only if the 283dc6f8d45SCornelia Huck * write protected ioctl is implemented for the range 284dc6f8d45SCornelia Huck * according to the uffdio_register.ioctls. 285dc6f8d45SCornelia Huck */ 286dc6f8d45SCornelia Huck #define UFFDIO_COPY_MODE_WP ((__u64)1<<1) 287c1fcf220SDr. David Alan Gilbert __u64 mode; 288c1fcf220SDr. David Alan Gilbert 289c1fcf220SDr. David Alan Gilbert /* 290c1fcf220SDr. David Alan Gilbert * "copy" is written by the ioctl and must be at the end: the 291c1fcf220SDr. David Alan Gilbert * copy_from_user will not read the last 8 bytes. 292c1fcf220SDr. David Alan Gilbert */ 293c1fcf220SDr. David Alan Gilbert __s64 copy; 294c1fcf220SDr. David Alan Gilbert }; 295c1fcf220SDr. David Alan Gilbert 296c1fcf220SDr. David Alan Gilbert struct uffdio_zeropage { 297c1fcf220SDr. David Alan Gilbert struct uffdio_range range; 298c1fcf220SDr. David Alan Gilbert #define UFFDIO_ZEROPAGE_MODE_DONTWAKE ((__u64)1<<0) 299c1fcf220SDr. David Alan Gilbert __u64 mode; 300c1fcf220SDr. David Alan Gilbert 301c1fcf220SDr. David Alan Gilbert /* 302c1fcf220SDr. David Alan Gilbert * "zeropage" is written by the ioctl and must be at the end: 303c1fcf220SDr. David Alan Gilbert * the copy_from_user will not read the last 8 bytes. 304c1fcf220SDr. David Alan Gilbert */ 305c1fcf220SDr. David Alan Gilbert __s64 zeropage; 306c1fcf220SDr. David Alan Gilbert }; 307c1fcf220SDr. David Alan Gilbert 308dc6f8d45SCornelia Huck struct uffdio_writeprotect { 309dc6f8d45SCornelia Huck struct uffdio_range range; 310dc6f8d45SCornelia Huck /* 311dc6f8d45SCornelia Huck * UFFDIO_WRITEPROTECT_MODE_WP: set the flag to write protect a range, 312dc6f8d45SCornelia Huck * unset the flag to undo protection of a range which was previously 313dc6f8d45SCornelia Huck * write protected. 314dc6f8d45SCornelia Huck * 315dc6f8d45SCornelia Huck * UFFDIO_WRITEPROTECT_MODE_DONTWAKE: set the flag to avoid waking up 316dc6f8d45SCornelia Huck * any wait thread after the operation succeeds. 317dc6f8d45SCornelia Huck * 318dc6f8d45SCornelia Huck * NOTE: Write protecting a region (WP=1) is unrelated to page faults, 319dc6f8d45SCornelia Huck * therefore DONTWAKE flag is meaningless with WP=1. Removing write 320dc6f8d45SCornelia Huck * protection (WP=0) in response to a page fault wakes the faulting 321dc6f8d45SCornelia Huck * task unless DONTWAKE is set. 322dc6f8d45SCornelia Huck */ 323dc6f8d45SCornelia Huck #define UFFDIO_WRITEPROTECT_MODE_WP ((__u64)1<<0) 324dc6f8d45SCornelia Huck #define UFFDIO_WRITEPROTECT_MODE_DONTWAKE ((__u64)1<<1) 325dc6f8d45SCornelia Huck __u64 mode; 326dc6f8d45SCornelia Huck }; 327dc6f8d45SCornelia Huck 328278f064eSEduardo Habkost struct uffdio_continue { 329278f064eSEduardo Habkost struct uffdio_range range; 330278f064eSEduardo Habkost #define UFFDIO_CONTINUE_MODE_DONTWAKE ((__u64)1<<0) 331d0bf492fSCédric Le Goater /* 332d0bf492fSCédric Le Goater * UFFDIO_CONTINUE_MODE_WP will map the page write protected on 333d0bf492fSCédric Le Goater * the fly. UFFDIO_CONTINUE_MODE_WP is available only if the 334d0bf492fSCédric Le Goater * write protected ioctl is implemented for the range 335d0bf492fSCédric Le Goater * according to the uffdio_register.ioctls. 336d0bf492fSCédric Le Goater */ 337d0bf492fSCédric Le Goater #define UFFDIO_CONTINUE_MODE_WP ((__u64)1<<1) 338278f064eSEduardo Habkost __u64 mode; 339278f064eSEduardo Habkost 340278f064eSEduardo Habkost /* 341278f064eSEduardo Habkost * Fields below here are written by the ioctl and must be at the end: 342278f064eSEduardo Habkost * the copy_from_user will not read past here. 343278f064eSEduardo Habkost */ 344278f064eSEduardo Habkost __s64 mapped; 345278f064eSEduardo Habkost }; 346278f064eSEduardo Habkost 347da3c22c7SThomas Huth struct uffdio_poison { 348da3c22c7SThomas Huth struct uffdio_range range; 349da3c22c7SThomas Huth #define UFFDIO_POISON_MODE_DONTWAKE ((__u64)1<<0) 350da3c22c7SThomas Huth __u64 mode; 351da3c22c7SThomas Huth 352da3c22c7SThomas Huth /* 353da3c22c7SThomas Huth * Fields below here are written by the ioctl and must be at the end: 354da3c22c7SThomas Huth * the copy_from_user will not read past here. 355da3c22c7SThomas Huth */ 356da3c22c7SThomas Huth __s64 updated; 357da3c22c7SThomas Huth }; 358da3c22c7SThomas Huth 359*6a02465fSDaniel Henrique Barboza struct uffdio_move { 360*6a02465fSDaniel Henrique Barboza __u64 dst; 361*6a02465fSDaniel Henrique Barboza __u64 src; 362*6a02465fSDaniel Henrique Barboza __u64 len; 363*6a02465fSDaniel Henrique Barboza /* 364*6a02465fSDaniel Henrique Barboza * Especially if used to atomically remove memory from the 365*6a02465fSDaniel Henrique Barboza * address space the wake on the dst range is not needed. 366*6a02465fSDaniel Henrique Barboza */ 367*6a02465fSDaniel Henrique Barboza #define UFFDIO_MOVE_MODE_DONTWAKE ((__u64)1<<0) 368*6a02465fSDaniel Henrique Barboza #define UFFDIO_MOVE_MODE_ALLOW_SRC_HOLES ((__u64)1<<1) 369*6a02465fSDaniel Henrique Barboza __u64 mode; 370*6a02465fSDaniel Henrique Barboza /* 371*6a02465fSDaniel Henrique Barboza * "move" is written by the ioctl and must be at the end: the 372*6a02465fSDaniel Henrique Barboza * copy_from_user will not read the last 8 bytes. 373*6a02465fSDaniel Henrique Barboza */ 374*6a02465fSDaniel Henrique Barboza __s64 move; 375*6a02465fSDaniel Henrique Barboza }; 376*6a02465fSDaniel Henrique Barboza 377b3c818a4SEric Farman /* 378b3c818a4SEric Farman * Flags for the userfaultfd(2) system call itself. 379b3c818a4SEric Farman */ 380b3c818a4SEric Farman 381b3c818a4SEric Farman /* 382b3c818a4SEric Farman * Create a userfaultfd that can handle page faults only in user mode. 383b3c818a4SEric Farman */ 384b3c818a4SEric Farman #define UFFD_USER_MODE_ONLY 1 385b3c818a4SEric Farman 386c1fcf220SDr. David Alan Gilbert #endif /* _LINUX_USERFAULTFD_H */ 387