@@ -988,24 +988,14 @@ static int resolve_userfault_fork(struct userfaultfd_ctx *ctx,
988
988
struct uffd_msg * msg )
989
989
{
990
990
int fd ;
991
- struct file * file ;
992
- unsigned int flags = new -> flags & UFFD_SHARED_FCNTL_FLAGS ;
993
991
994
- fd = get_unused_fd_flags (flags );
992
+ fd = anon_inode_getfd ("[userfaultfd]" , & userfaultfd_fops , new ,
993
+ O_RDWR | (new -> flags & UFFD_SHARED_FCNTL_FLAGS ));
995
994
if (fd < 0 )
996
995
return fd ;
997
996
998
- file = anon_inode_getfile ("[userfaultfd]" , & userfaultfd_fops , new ,
999
- O_RDWR | flags );
1000
- if (IS_ERR (file )) {
1001
- put_unused_fd (fd );
1002
- return PTR_ERR (file );
1003
- }
1004
-
1005
- fd_install (fd , file );
1006
997
msg -> arg .reserved .reserved1 = 0 ;
1007
998
msg -> arg .fork .ufd = fd ;
1008
-
1009
999
return 0 ;
1010
1000
}
1011
1001
@@ -1887,39 +1877,23 @@ static void init_once_userfaultfd_ctx(void *mem)
1887
1877
seqcount_init (& ctx -> refile_seq );
1888
1878
}
1889
1879
1890
- /**
1891
- * userfaultfd_file_create - Creates a userfaultfd file pointer.
1892
- * @flags: Flags for the userfaultfd file.
1893
- *
1894
- * This function creates a userfaultfd file pointer, w/out installing
1895
- * it into the fd table. This is useful when the userfaultfd file is
1896
- * used during the initialization of data structures that require
1897
- * extra setup after the userfaultfd creation. So the userfaultfd
1898
- * creation is split into the file pointer creation phase, and the
1899
- * file descriptor installation phase. In this way races with
1900
- * userspace closing the newly installed file descriptor can be
1901
- * avoided. Returns a userfaultfd file pointer, or a proper error
1902
- * pointer.
1903
- */
1904
- static struct file * userfaultfd_file_create (int flags )
1880
+ SYSCALL_DEFINE1 (userfaultfd , int , flags )
1905
1881
{
1906
- struct file * file ;
1907
1882
struct userfaultfd_ctx * ctx ;
1883
+ int fd ;
1908
1884
1909
1885
BUG_ON (!current -> mm );
1910
1886
1911
1887
/* Check the UFFD_* constants for consistency. */
1912
1888
BUILD_BUG_ON (UFFD_CLOEXEC != O_CLOEXEC );
1913
1889
BUILD_BUG_ON (UFFD_NONBLOCK != O_NONBLOCK );
1914
1890
1915
- file = ERR_PTR (- EINVAL );
1916
1891
if (flags & ~UFFD_SHARED_FCNTL_FLAGS )
1917
- goto out ;
1892
+ return - EINVAL ;
1918
1893
1919
- file = ERR_PTR (- ENOMEM );
1920
1894
ctx = kmem_cache_alloc (userfaultfd_ctx_cachep , GFP_KERNEL );
1921
1895
if (!ctx )
1922
- goto out ;
1896
+ return - ENOMEM ;
1923
1897
1924
1898
atomic_set (& ctx -> refcount , 1 );
1925
1899
ctx -> flags = flags ;
@@ -1930,39 +1904,13 @@ static struct file *userfaultfd_file_create(int flags)
1930
1904
/* prevent the mm struct to be freed */
1931
1905
mmgrab (ctx -> mm );
1932
1906
1933
- file = anon_inode_getfile ("[userfaultfd]" , & userfaultfd_fops , ctx ,
1934
- O_RDWR | (flags & UFFD_SHARED_FCNTL_FLAGS ));
1935
- if (IS_ERR ( file ) ) {
1907
+ fd = anon_inode_getfd ("[userfaultfd]" , & userfaultfd_fops , ctx ,
1908
+ O_RDWR | (flags & UFFD_SHARED_FCNTL_FLAGS ));
1909
+ if (fd < 0 ) {
1936
1910
mmdrop (ctx -> mm );
1937
1911
kmem_cache_free (userfaultfd_ctx_cachep , ctx );
1938
1912
}
1939
- out :
1940
- return file ;
1941
- }
1942
-
1943
- SYSCALL_DEFINE1 (userfaultfd , int , flags )
1944
- {
1945
- int fd , error ;
1946
- struct file * file ;
1947
-
1948
- error = get_unused_fd_flags (flags & UFFD_SHARED_FCNTL_FLAGS );
1949
- if (error < 0 )
1950
- return error ;
1951
- fd = error ;
1952
-
1953
- file = userfaultfd_file_create (flags );
1954
- if (IS_ERR (file )) {
1955
- error = PTR_ERR (file );
1956
- goto err_put_unused_fd ;
1957
- }
1958
- fd_install (fd , file );
1959
-
1960
1913
return fd ;
1961
-
1962
- err_put_unused_fd :
1963
- put_unused_fd (fd );
1964
-
1965
- return error ;
1966
1914
}
1967
1915
1968
1916
static int __init userfaultfd_init (void )
0 commit comments