16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 21038628dSAndrea Arcangeli /* 31038628dSAndrea Arcangeli * include/linux/userfaultfd.h 41038628dSAndrea Arcangeli * 51038628dSAndrea Arcangeli * Copyright (C) 2007 Davide Libenzi <davidel@xmailserver.org> 61038628dSAndrea Arcangeli * Copyright (C) 2015 Red Hat, Inc. 71038628dSAndrea Arcangeli * 81038628dSAndrea Arcangeli */ 91038628dSAndrea Arcangeli 101038628dSAndrea Arcangeli #ifndef _LINUX_USERFAULTFD_H 111038628dSAndrea Arcangeli #define _LINUX_USERFAULTFD_H 121038628dSAndrea Arcangeli 131038628dSAndrea Arcangeli #include <linux/types.h> 141038628dSAndrea Arcangeli 152d5de004SAxel Rasmussen /* ioctls for /dev/userfaultfd */ 162d5de004SAxel Rasmussen #define USERFAULTFD_IOC 0xAA 172d5de004SAxel Rasmussen #define USERFAULTFD_IOC_NEW _IO(USERFAULTFD_IOC, 0x00) 182d5de004SAxel Rasmussen 19e067eba5SAndrea Arcangeli /* 20e067eba5SAndrea Arcangeli * If the UFFDIO_API is upgraded someday, the UFFDIO_UNREGISTER and 21e067eba5SAndrea Arcangeli * UFFDIO_WAKE ioctls should be defined as _IOW and not as _IOR. In 22e067eba5SAndrea Arcangeli * userfaultfd.h we assumed the kernel was reading (instead _IOC_READ 23e067eba5SAndrea Arcangeli * means the userland is reading). 24e067eba5SAndrea Arcangeli */ 251038628dSAndrea Arcangeli #define UFFD_API ((__u64)0xAA) 267677f7fdSAxel Rasmussen #define UFFD_API_REGISTER_MODES (UFFDIO_REGISTER_MODE_MISSING | \ 277677f7fdSAxel Rasmussen UFFDIO_REGISTER_MODE_WP | \ 287677f7fdSAxel Rasmussen UFFDIO_REGISTER_MODE_MINOR) 29e06f1e1dSShaohua Li #define UFFD_API_FEATURES (UFFD_FEATURE_PAGEFAULT_FLAG_WP | \ 30e06f1e1dSShaohua Li UFFD_FEATURE_EVENT_FORK | \ 3105ce7724SPavel Emelyanov UFFD_FEATURE_EVENT_REMAP | \ 32d811914dSMike Rapoport UFFD_FEATURE_EVENT_REMOVE | \ 33897ab3e0SMike Rapoport UFFD_FEATURE_EVENT_UNMAP | \ 3447dd9245SAndrea Arcangeli UFFD_FEATURE_MISSING_HUGETLBFS | \ 352d6d6f5aSPrakash Sangappa UFFD_FEATURE_MISSING_SHMEM | \ 369d4ac934SAlexey Perevalov UFFD_FEATURE_SIGBUS | \ 377677f7fdSAxel Rasmussen UFFD_FEATURE_THREAD_ID | \ 38964ab004SAxel Rasmussen UFFD_FEATURE_MINOR_HUGETLBFS | \ 39824ddc60SNadav Amit UFFD_FEATURE_MINOR_SHMEM | \ 40b1f9e876SPeter Xu UFFD_FEATURE_EXACT_ADDRESS | \ 412bad466cSPeter Xu UFFD_FEATURE_WP_HUGETLBFS_SHMEM | \ 42f442ab50SAxel Rasmussen UFFD_FEATURE_WP_UNPOPULATED | \ 43d61ea1cbSPeter Xu UFFD_FEATURE_POISON | \ 44*adef4406SAndrea Arcangeli UFFD_FEATURE_WP_ASYNC | \ 45*adef4406SAndrea Arcangeli UFFD_FEATURE_MOVE) 461038628dSAndrea Arcangeli #define UFFD_API_IOCTLS \ 471038628dSAndrea Arcangeli ((__u64)1 << _UFFDIO_REGISTER | \ 481038628dSAndrea Arcangeli (__u64)1 << _UFFDIO_UNREGISTER | \ 491038628dSAndrea Arcangeli (__u64)1 << _UFFDIO_API) 501038628dSAndrea Arcangeli #define UFFD_API_RANGE_IOCTLS \ 511f1c6f07SAndrea Arcangeli ((__u64)1 << _UFFDIO_WAKE | \ 521f1c6f07SAndrea Arcangeli (__u64)1 << _UFFDIO_COPY | \ 53e06f1e1dSShaohua Li (__u64)1 << _UFFDIO_ZEROPAGE | \ 54*adef4406SAndrea Arcangeli (__u64)1 << _UFFDIO_MOVE | \ 55f6191471SAxel Rasmussen (__u64)1 << _UFFDIO_WRITEPROTECT | \ 56f442ab50SAxel Rasmussen (__u64)1 << _UFFDIO_CONTINUE | \ 57f442ab50SAxel Rasmussen (__u64)1 << _UFFDIO_POISON) 58cac67329SMike Rapoport #define UFFD_API_RANGE_IOCTLS_BASIC \ 59cab350afSMike Kravetz ((__u64)1 << _UFFDIO_WAKE | \ 60f6191471SAxel Rasmussen (__u64)1 << _UFFDIO_COPY | \ 61f442ab50SAxel Rasmussen (__u64)1 << _UFFDIO_WRITEPROTECT | \ 62b1f9e876SPeter Xu (__u64)1 << _UFFDIO_CONTINUE | \ 63f442ab50SAxel Rasmussen (__u64)1 << _UFFDIO_POISON) 641038628dSAndrea Arcangeli 651038628dSAndrea Arcangeli /* 661038628dSAndrea Arcangeli * Valid ioctl command number range with this API is from 0x00 to 671038628dSAndrea Arcangeli * 0x3F. UFFDIO_API is the fixed number, everything else can be 681038628dSAndrea Arcangeli * changed by implementing a different UFFD_API. If sticking to the 691038628dSAndrea Arcangeli * same UFFD_API more ioctl can be added and userland will be aware of 701038628dSAndrea Arcangeli * which ioctl the running kernel implements through the ioctl command 711038628dSAndrea Arcangeli * bitmask written by the UFFDIO_API. 721038628dSAndrea Arcangeli */ 731038628dSAndrea Arcangeli #define _UFFDIO_REGISTER (0x00) 741038628dSAndrea Arcangeli #define _UFFDIO_UNREGISTER (0x01) 751038628dSAndrea Arcangeli #define _UFFDIO_WAKE (0x02) 761f1c6f07SAndrea Arcangeli #define _UFFDIO_COPY (0x03) 771f1c6f07SAndrea Arcangeli #define _UFFDIO_ZEROPAGE (0x04) 78*adef4406SAndrea Arcangeli #define _UFFDIO_MOVE (0x05) 7963b2d417SAndrea Arcangeli #define _UFFDIO_WRITEPROTECT (0x06) 80f6191471SAxel Rasmussen #define _UFFDIO_CONTINUE (0x07) 81fc71884aSAxel Rasmussen #define _UFFDIO_POISON (0x08) 821038628dSAndrea Arcangeli #define _UFFDIO_API (0x3F) 831038628dSAndrea Arcangeli 841038628dSAndrea Arcangeli /* userfaultfd ioctl ids */ 851038628dSAndrea Arcangeli #define UFFDIO 0xAA 861038628dSAndrea Arcangeli #define UFFDIO_API _IOWR(UFFDIO, _UFFDIO_API, \ 871038628dSAndrea Arcangeli struct uffdio_api) 881038628dSAndrea Arcangeli #define UFFDIO_REGISTER _IOWR(UFFDIO, _UFFDIO_REGISTER, \ 891038628dSAndrea Arcangeli struct uffdio_register) 901038628dSAndrea Arcangeli #define UFFDIO_UNREGISTER _IOR(UFFDIO, _UFFDIO_UNREGISTER, \ 911038628dSAndrea Arcangeli struct uffdio_range) 921038628dSAndrea Arcangeli #define UFFDIO_WAKE _IOR(UFFDIO, _UFFDIO_WAKE, \ 931038628dSAndrea Arcangeli struct uffdio_range) 941f1c6f07SAndrea Arcangeli #define UFFDIO_COPY _IOWR(UFFDIO, _UFFDIO_COPY, \ 951f1c6f07SAndrea Arcangeli struct uffdio_copy) 961f1c6f07SAndrea Arcangeli #define UFFDIO_ZEROPAGE _IOWR(UFFDIO, _UFFDIO_ZEROPAGE, \ 971f1c6f07SAndrea Arcangeli struct uffdio_zeropage) 98*adef4406SAndrea Arcangeli #define UFFDIO_MOVE _IOWR(UFFDIO, _UFFDIO_MOVE, \ 99*adef4406SAndrea Arcangeli struct uffdio_move) 10063b2d417SAndrea Arcangeli #define UFFDIO_WRITEPROTECT _IOWR(UFFDIO, _UFFDIO_WRITEPROTECT, \ 10163b2d417SAndrea Arcangeli struct uffdio_writeprotect) 102808e9df4SGleb Fotengauer-Malinovskiy #define UFFDIO_CONTINUE _IOWR(UFFDIO, _UFFDIO_CONTINUE, \ 103f6191471SAxel Rasmussen struct uffdio_continue) 104fc71884aSAxel Rasmussen #define UFFDIO_POISON _IOWR(UFFDIO, _UFFDIO_POISON, \ 105fc71884aSAxel Rasmussen struct uffdio_poison) 1061038628dSAndrea Arcangeli 107a9b85f94SAndrea Arcangeli /* read() structure */ 108a9b85f94SAndrea Arcangeli struct uffd_msg { 109a9b85f94SAndrea Arcangeli __u8 event; 110a9b85f94SAndrea Arcangeli 111a9b85f94SAndrea Arcangeli __u8 reserved1; 112a9b85f94SAndrea Arcangeli __u16 reserved2; 113a9b85f94SAndrea Arcangeli __u32 reserved3; 114a9b85f94SAndrea Arcangeli 115a9b85f94SAndrea Arcangeli union { 116a9b85f94SAndrea Arcangeli struct { 117a9b85f94SAndrea Arcangeli __u64 flags; 118a9b85f94SAndrea Arcangeli __u64 address; 119a36985d3SAndrea Arcangeli union { 1209d4ac934SAlexey Perevalov __u32 ptid; 121a36985d3SAndrea Arcangeli } feat; 122a9b85f94SAndrea Arcangeli } pagefault; 123a9b85f94SAndrea Arcangeli 124a9b85f94SAndrea Arcangeli struct { 125893e26e6SPavel Emelyanov __u32 ufd; 126893e26e6SPavel Emelyanov } fork; 127893e26e6SPavel Emelyanov 128893e26e6SPavel Emelyanov struct { 12972f87654SPavel Emelyanov __u64 from; 13072f87654SPavel Emelyanov __u64 to; 13172f87654SPavel Emelyanov __u64 len; 13272f87654SPavel Emelyanov } remap; 13372f87654SPavel Emelyanov 13472f87654SPavel Emelyanov struct { 13505ce7724SPavel Emelyanov __u64 start; 13605ce7724SPavel Emelyanov __u64 end; 137d811914dSMike Rapoport } remove; 13805ce7724SPavel Emelyanov 13905ce7724SPavel Emelyanov struct { 140a9b85f94SAndrea Arcangeli /* unused reserved fields */ 141a9b85f94SAndrea Arcangeli __u64 reserved1; 142a9b85f94SAndrea Arcangeli __u64 reserved2; 143a9b85f94SAndrea Arcangeli __u64 reserved3; 144a9b85f94SAndrea Arcangeli } reserved; 145a9b85f94SAndrea Arcangeli } arg; 146a9b85f94SAndrea Arcangeli } __packed; 1471038628dSAndrea Arcangeli 1483f602d27SPavel Emelyanov /* 149a9b85f94SAndrea Arcangeli * Start at 0x12 and not at 0 to be more strict against bugs. 1503f602d27SPavel Emelyanov */ 151a9b85f94SAndrea Arcangeli #define UFFD_EVENT_PAGEFAULT 0x12 152a9b85f94SAndrea Arcangeli #define UFFD_EVENT_FORK 0x13 15372f87654SPavel Emelyanov #define UFFD_EVENT_REMAP 0x14 154d811914dSMike Rapoport #define UFFD_EVENT_REMOVE 0x15 155897ab3e0SMike Rapoport #define UFFD_EVENT_UNMAP 0x16 156a9b85f94SAndrea Arcangeli 157a9b85f94SAndrea Arcangeli /* flags for UFFD_EVENT_PAGEFAULT */ 158a9b85f94SAndrea Arcangeli #define UFFD_PAGEFAULT_FLAG_WRITE (1<<0) /* If this was a write fault */ 159a9b85f94SAndrea Arcangeli #define UFFD_PAGEFAULT_FLAG_WP (1<<1) /* If reason is VM_UFFD_WP */ 1607677f7fdSAxel Rasmussen #define UFFD_PAGEFAULT_FLAG_MINOR (1<<2) /* If reason is VM_UFFD_MINOR */ 1613f602d27SPavel Emelyanov 1621038628dSAndrea Arcangeli struct uffdio_api { 163a9b85f94SAndrea Arcangeli /* userland asks for an API number and the features to enable */ 1641038628dSAndrea Arcangeli __u64 api; 165a9b85f94SAndrea Arcangeli /* 166a9b85f94SAndrea Arcangeli * Kernel answers below with the all available features for 167a9b85f94SAndrea Arcangeli * the API, this notifies userland of which events and/or 168a9b85f94SAndrea Arcangeli * which flags for each event are enabled in the current 169a9b85f94SAndrea Arcangeli * kernel. 170a9b85f94SAndrea Arcangeli * 171a9b85f94SAndrea Arcangeli * Note: UFFD_EVENT_PAGEFAULT and UFFD_PAGEFAULT_FLAG_WRITE 172a9b85f94SAndrea Arcangeli * are to be considered implicitly always enabled in all kernels as 173a9b85f94SAndrea Arcangeli * long as the uffdio_api.api requested matches UFFD_API. 174163e11bcSAndrea Arcangeli * 175163e11bcSAndrea Arcangeli * UFFD_FEATURE_MISSING_HUGETLBFS means an UFFDIO_REGISTER 176163e11bcSAndrea Arcangeli * with UFFDIO_REGISTER_MODE_MISSING mode will succeed on 177163e11bcSAndrea Arcangeli * hugetlbfs virtual memory ranges. Adding or not adding 178163e11bcSAndrea Arcangeli * UFFD_FEATURE_MISSING_HUGETLBFS to uffdio_api.features has 179163e11bcSAndrea Arcangeli * no real functional effect after UFFDIO_API returns, but 180163e11bcSAndrea Arcangeli * it's only useful for an initial feature set probe at 181163e11bcSAndrea Arcangeli * UFFDIO_API time. There are two ways to use it: 182163e11bcSAndrea Arcangeli * 183163e11bcSAndrea Arcangeli * 1) by adding UFFD_FEATURE_MISSING_HUGETLBFS to the 184163e11bcSAndrea Arcangeli * uffdio_api.features before calling UFFDIO_API, an error 185163e11bcSAndrea Arcangeli * will be returned by UFFDIO_API on a kernel without 186163e11bcSAndrea Arcangeli * hugetlbfs missing support 187163e11bcSAndrea Arcangeli * 188163e11bcSAndrea Arcangeli * 2) the UFFD_FEATURE_MISSING_HUGETLBFS can not be added in 189163e11bcSAndrea Arcangeli * uffdio_api.features and instead it will be set by the 190163e11bcSAndrea Arcangeli * kernel in the uffdio_api.features if the kernel supports 191163e11bcSAndrea Arcangeli * it, so userland can later check if the feature flag is 192163e11bcSAndrea Arcangeli * present in uffdio_api.features after UFFDIO_API 193163e11bcSAndrea Arcangeli * succeeded. 19447dd9245SAndrea Arcangeli * 19547dd9245SAndrea Arcangeli * UFFD_FEATURE_MISSING_SHMEM works the same as 19647dd9245SAndrea Arcangeli * UFFD_FEATURE_MISSING_HUGETLBFS, but it applies to shmem 19747dd9245SAndrea Arcangeli * (i.e. tmpfs and other shmem based APIs). 1982d6d6f5aSPrakash Sangappa * 1992d6d6f5aSPrakash Sangappa * UFFD_FEATURE_SIGBUS feature means no page-fault 2002d6d6f5aSPrakash Sangappa * (UFFD_EVENT_PAGEFAULT) event will be delivered, instead 2012d6d6f5aSPrakash Sangappa * a SIGBUS signal will be sent to the faulting process. 2029d4ac934SAlexey Perevalov * 2039d4ac934SAlexey Perevalov * UFFD_FEATURE_THREAD_ID pid of the page faulted task_struct will 2049d4ac934SAlexey Perevalov * be returned, if feature is not requested 0 will be returned. 2057677f7fdSAxel Rasmussen * 2067677f7fdSAxel Rasmussen * UFFD_FEATURE_MINOR_HUGETLBFS indicates that minor faults 2077677f7fdSAxel Rasmussen * can be intercepted (via REGISTER_MODE_MINOR) for 2087677f7fdSAxel Rasmussen * hugetlbfs-backed pages. 209964ab004SAxel Rasmussen * 210964ab004SAxel Rasmussen * UFFD_FEATURE_MINOR_SHMEM indicates the same support as 211964ab004SAxel Rasmussen * UFFD_FEATURE_MINOR_HUGETLBFS, but for shmem-backed pages instead. 212824ddc60SNadav Amit * 213824ddc60SNadav Amit * UFFD_FEATURE_EXACT_ADDRESS indicates that the exact address of page 214824ddc60SNadav Amit * faults would be provided and the offset within the page would not be 215824ddc60SNadav Amit * masked. 216b1f9e876SPeter Xu * 217b1f9e876SPeter Xu * UFFD_FEATURE_WP_HUGETLBFS_SHMEM indicates that userfaultfd 218b1f9e876SPeter Xu * write-protection mode is supported on both shmem and hugetlbfs. 2192bad466cSPeter Xu * 2202bad466cSPeter Xu * UFFD_FEATURE_WP_UNPOPULATED indicates that userfaultfd 2212bad466cSPeter Xu * write-protection mode will always apply to unpopulated pages 2222bad466cSPeter Xu * (i.e. empty ptes). This will be the default behavior for shmem 2232bad466cSPeter Xu * & hugetlbfs, so this flag only affects anonymous memory behavior 2242bad466cSPeter Xu * when userfault write-protection mode is registered. 225d61ea1cbSPeter Xu * 226d61ea1cbSPeter Xu * UFFD_FEATURE_WP_ASYNC indicates that userfaultfd write-protection 227d61ea1cbSPeter Xu * asynchronous mode is supported in which the write fault is 228d61ea1cbSPeter Xu * automatically resolved and write-protection is un-set. 229d61ea1cbSPeter Xu * It implies UFFD_FEATURE_WP_UNPOPULATED. 230*adef4406SAndrea Arcangeli * 231*adef4406SAndrea Arcangeli * UFFD_FEATURE_MOVE indicates that the kernel supports moving an 232*adef4406SAndrea Arcangeli * existing page contents from userspace. 233a9b85f94SAndrea Arcangeli */ 234a9b85f94SAndrea Arcangeli #define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0) 235a9b85f94SAndrea Arcangeli #define UFFD_FEATURE_EVENT_FORK (1<<1) 23672f87654SPavel Emelyanov #define UFFD_FEATURE_EVENT_REMAP (1<<2) 237d811914dSMike Rapoport #define UFFD_FEATURE_EVENT_REMOVE (1<<3) 238163e11bcSAndrea Arcangeli #define UFFD_FEATURE_MISSING_HUGETLBFS (1<<4) 23947dd9245SAndrea Arcangeli #define UFFD_FEATURE_MISSING_SHMEM (1<<5) 240897ab3e0SMike Rapoport #define UFFD_FEATURE_EVENT_UNMAP (1<<6) 2412d6d6f5aSPrakash Sangappa #define UFFD_FEATURE_SIGBUS (1<<7) 2429d4ac934SAlexey Perevalov #define UFFD_FEATURE_THREAD_ID (1<<8) 2437677f7fdSAxel Rasmussen #define UFFD_FEATURE_MINOR_HUGETLBFS (1<<9) 244964ab004SAxel Rasmussen #define UFFD_FEATURE_MINOR_SHMEM (1<<10) 245824ddc60SNadav Amit #define UFFD_FEATURE_EXACT_ADDRESS (1<<11) 246b1f9e876SPeter Xu #define UFFD_FEATURE_WP_HUGETLBFS_SHMEM (1<<12) 2472bad466cSPeter Xu #define UFFD_FEATURE_WP_UNPOPULATED (1<<13) 248fc71884aSAxel Rasmussen #define UFFD_FEATURE_POISON (1<<14) 249d61ea1cbSPeter Xu #define UFFD_FEATURE_WP_ASYNC (1<<15) 250*adef4406SAndrea Arcangeli #define UFFD_FEATURE_MOVE (1<<16) 2513f602d27SPavel Emelyanov __u64 features; 252a9b85f94SAndrea Arcangeli 2531038628dSAndrea Arcangeli __u64 ioctls; 2541038628dSAndrea Arcangeli }; 2551038628dSAndrea Arcangeli 2561038628dSAndrea Arcangeli struct uffdio_range { 2571038628dSAndrea Arcangeli __u64 start; 2581038628dSAndrea Arcangeli __u64 len; 2591038628dSAndrea Arcangeli }; 2601038628dSAndrea Arcangeli 2611038628dSAndrea Arcangeli struct uffdio_register { 2621038628dSAndrea Arcangeli struct uffdio_range range; 2631038628dSAndrea Arcangeli #define UFFDIO_REGISTER_MODE_MISSING ((__u64)1<<0) 2641038628dSAndrea Arcangeli #define UFFDIO_REGISTER_MODE_WP ((__u64)1<<1) 2657677f7fdSAxel Rasmussen #define UFFDIO_REGISTER_MODE_MINOR ((__u64)1<<2) 2661038628dSAndrea Arcangeli __u64 mode; 2671038628dSAndrea Arcangeli 2681038628dSAndrea Arcangeli /* 2691038628dSAndrea Arcangeli * kernel answers which ioctl commands are available for the 2701038628dSAndrea Arcangeli * range, keep at the end as the last 8 bytes aren't read. 2711038628dSAndrea Arcangeli */ 2721038628dSAndrea Arcangeli __u64 ioctls; 2731038628dSAndrea Arcangeli }; 2741038628dSAndrea Arcangeli 2751f1c6f07SAndrea Arcangeli struct uffdio_copy { 2761f1c6f07SAndrea Arcangeli __u64 dst; 2771f1c6f07SAndrea Arcangeli __u64 src; 2781f1c6f07SAndrea Arcangeli __u64 len; 2791f1c6f07SAndrea Arcangeli #define UFFDIO_COPY_MODE_DONTWAKE ((__u64)1<<0) 28072981e0eSAndrea Arcangeli /* 28172981e0eSAndrea Arcangeli * UFFDIO_COPY_MODE_WP will map the page write protected on 28272981e0eSAndrea Arcangeli * the fly. UFFDIO_COPY_MODE_WP is available only if the 28372981e0eSAndrea Arcangeli * write protected ioctl is implemented for the range 28472981e0eSAndrea Arcangeli * according to the uffdio_register.ioctls. 28572981e0eSAndrea Arcangeli */ 28672981e0eSAndrea Arcangeli #define UFFDIO_COPY_MODE_WP ((__u64)1<<1) 2871f1c6f07SAndrea Arcangeli __u64 mode; 2881f1c6f07SAndrea Arcangeli 2891f1c6f07SAndrea Arcangeli /* 2901f1c6f07SAndrea Arcangeli * "copy" is written by the ioctl and must be at the end: the 2911f1c6f07SAndrea Arcangeli * copy_from_user will not read the last 8 bytes. 2921f1c6f07SAndrea Arcangeli */ 2931f1c6f07SAndrea Arcangeli __s64 copy; 2941f1c6f07SAndrea Arcangeli }; 2951f1c6f07SAndrea Arcangeli 2961f1c6f07SAndrea Arcangeli struct uffdio_zeropage { 2971f1c6f07SAndrea Arcangeli struct uffdio_range range; 2981f1c6f07SAndrea Arcangeli #define UFFDIO_ZEROPAGE_MODE_DONTWAKE ((__u64)1<<0) 2991f1c6f07SAndrea Arcangeli __u64 mode; 3001f1c6f07SAndrea Arcangeli 3011f1c6f07SAndrea Arcangeli /* 3021f1c6f07SAndrea Arcangeli * "zeropage" is written by the ioctl and must be at the end: 3031f1c6f07SAndrea Arcangeli * the copy_from_user will not read the last 8 bytes. 3041f1c6f07SAndrea Arcangeli */ 3051f1c6f07SAndrea Arcangeli __s64 zeropage; 3061f1c6f07SAndrea Arcangeli }; 3071f1c6f07SAndrea Arcangeli 30863b2d417SAndrea Arcangeli struct uffdio_writeprotect { 30963b2d417SAndrea Arcangeli struct uffdio_range range; 31063b2d417SAndrea Arcangeli /* 31163b2d417SAndrea Arcangeli * UFFDIO_WRITEPROTECT_MODE_WP: set the flag to write protect a range, 31263b2d417SAndrea Arcangeli * unset the flag to undo protection of a range which was previously 31363b2d417SAndrea Arcangeli * write protected. 31463b2d417SAndrea Arcangeli * 31563b2d417SAndrea Arcangeli * UFFDIO_WRITEPROTECT_MODE_DONTWAKE: set the flag to avoid waking up 31663b2d417SAndrea Arcangeli * any wait thread after the operation succeeds. 31763b2d417SAndrea Arcangeli * 31863b2d417SAndrea Arcangeli * NOTE: Write protecting a region (WP=1) is unrelated to page faults, 31963b2d417SAndrea Arcangeli * therefore DONTWAKE flag is meaningless with WP=1. Removing write 32063b2d417SAndrea Arcangeli * protection (WP=0) in response to a page fault wakes the faulting 32163b2d417SAndrea Arcangeli * task unless DONTWAKE is set. 32263b2d417SAndrea Arcangeli */ 32363b2d417SAndrea Arcangeli #define UFFDIO_WRITEPROTECT_MODE_WP ((__u64)1<<0) 32463b2d417SAndrea Arcangeli #define UFFDIO_WRITEPROTECT_MODE_DONTWAKE ((__u64)1<<1) 32563b2d417SAndrea Arcangeli __u64 mode; 32663b2d417SAndrea Arcangeli }; 32763b2d417SAndrea Arcangeli 328f6191471SAxel Rasmussen struct uffdio_continue { 329f6191471SAxel Rasmussen struct uffdio_range range; 330f6191471SAxel Rasmussen #define UFFDIO_CONTINUE_MODE_DONTWAKE ((__u64)1<<0) 33102891844SAxel Rasmussen /* 33202891844SAxel Rasmussen * UFFDIO_CONTINUE_MODE_WP will map the page write protected on 33302891844SAxel Rasmussen * the fly. UFFDIO_CONTINUE_MODE_WP is available only if the 33402891844SAxel Rasmussen * write protected ioctl is implemented for the range 33502891844SAxel Rasmussen * according to the uffdio_register.ioctls. 33602891844SAxel Rasmussen */ 33702891844SAxel Rasmussen #define UFFDIO_CONTINUE_MODE_WP ((__u64)1<<1) 338f6191471SAxel Rasmussen __u64 mode; 339f6191471SAxel Rasmussen 340f6191471SAxel Rasmussen /* 341f6191471SAxel Rasmussen * Fields below here are written by the ioctl and must be at the end: 342f6191471SAxel Rasmussen * the copy_from_user will not read past here. 343f6191471SAxel Rasmussen */ 344f6191471SAxel Rasmussen __s64 mapped; 345f6191471SAxel Rasmussen }; 346f6191471SAxel Rasmussen 347fc71884aSAxel Rasmussen struct uffdio_poison { 348fc71884aSAxel Rasmussen struct uffdio_range range; 349fc71884aSAxel Rasmussen #define UFFDIO_POISON_MODE_DONTWAKE ((__u64)1<<0) 350fc71884aSAxel Rasmussen __u64 mode; 351fc71884aSAxel Rasmussen 352fc71884aSAxel Rasmussen /* 353fc71884aSAxel Rasmussen * Fields below here are written by the ioctl and must be at the end: 354fc71884aSAxel Rasmussen * the copy_from_user will not read past here. 355fc71884aSAxel Rasmussen */ 356fc71884aSAxel Rasmussen __s64 updated; 357fc71884aSAxel Rasmussen }; 358fc71884aSAxel Rasmussen 359*adef4406SAndrea Arcangeli struct uffdio_move { 360*adef4406SAndrea Arcangeli __u64 dst; 361*adef4406SAndrea Arcangeli __u64 src; 362*adef4406SAndrea Arcangeli __u64 len; 363*adef4406SAndrea Arcangeli /* 364*adef4406SAndrea Arcangeli * Especially if used to atomically remove memory from the 365*adef4406SAndrea Arcangeli * address space the wake on the dst range is not needed. 366*adef4406SAndrea Arcangeli */ 367*adef4406SAndrea Arcangeli #define UFFDIO_MOVE_MODE_DONTWAKE ((__u64)1<<0) 368*adef4406SAndrea Arcangeli #define UFFDIO_MOVE_MODE_ALLOW_SRC_HOLES ((__u64)1<<1) 369*adef4406SAndrea Arcangeli __u64 mode; 370*adef4406SAndrea Arcangeli /* 371*adef4406SAndrea Arcangeli * "move" is written by the ioctl and must be at the end: the 372*adef4406SAndrea Arcangeli * copy_from_user will not read the last 8 bytes. 373*adef4406SAndrea Arcangeli */ 374*adef4406SAndrea Arcangeli __s64 move; 375*adef4406SAndrea Arcangeli }; 376*adef4406SAndrea Arcangeli 37737cd0575SLokesh Gidra /* 37837cd0575SLokesh Gidra * Flags for the userfaultfd(2) system call itself. 37937cd0575SLokesh Gidra */ 38037cd0575SLokesh Gidra 38137cd0575SLokesh Gidra /* 38237cd0575SLokesh Gidra * Create a userfaultfd that can handle page faults only in user mode. 38337cd0575SLokesh Gidra */ 38437cd0575SLokesh Gidra #define UFFD_USER_MODE_ONLY 1 38537cd0575SLokesh Gidra 3861038628dSAndrea Arcangeli #endif /* _LINUX_USERFAULTFD_H */ 387