Skip to content

Commit 67ba049

Browse files
author
Al Viro
committed
aio: fold do_io_submit() into callers
get rid of insane "copy array of 32bit pointers into an array of native ones" glue. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 95af849 commit 67ba049

1 file changed

Lines changed: 45 additions & 54 deletions

File tree

‎fs/aio.c‎

Lines changed: 45 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,8 +1818,20 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
18181818
return ret;
18191819
}
18201820

1821-
static long do_io_submit(aio_context_t ctx_id, long nr,
1822-
struct iocb __user *__user *iocbpp, bool compat)
1821+
/* sys_io_submit:
1822+
* Queue the nr iocbs pointed to by iocbpp for processing. Returns
1823+
* the number of iocbs queued. May return -EINVAL if the aio_context
1824+
* specified by ctx_id is invalid, if nr is < 0, if the iocb at
1825+
* *iocbpp[0] is not properly initialized, if the operation specified
1826+
* is invalid for the file descriptor in the iocb. May fail with
1827+
* -EFAULT if any of the data structures point to invalid data. May
1828+
* fail with -EBADF if the file descriptor specified in the first
1829+
* iocb is invalid. May fail with -EAGAIN if insufficient resources
1830+
* are available to queue any iocbs. Will return 0 if nr is 0. Will
1831+
* fail with -ENOSYS if not implemented.
1832+
*/
1833+
SYSCALL_DEFINE3(io_submit, aio_context_t, ctx_id, long, nr,
1834+
struct iocb __user * __user *, iocbpp)
18231835
{
18241836
struct kioctx *ctx;
18251837
long ret = 0;
@@ -1832,30 +1844,22 @@ static long do_io_submit(aio_context_t ctx_id, long nr,
18321844
if (unlikely(nr > LONG_MAX/sizeof(*iocbpp)))
18331845
nr = LONG_MAX/sizeof(*iocbpp);
18341846

1835-
if (unlikely(!access_ok(VERIFY_READ, iocbpp, (nr*sizeof(*iocbpp)))))
1836-
return -EFAULT;
1837-
18381847
ctx = lookup_ioctx(ctx_id);
18391848
if (unlikely(!ctx)) {
18401849
pr_debug("EINVAL: invalid context id\n");
18411850
return -EINVAL;
18421851
}
18431852

18441853
blk_start_plug(&plug);
1845-
1846-
/*
1847-
* AKPM: should this return a partial result if some of the IOs were
1848-
* successfully submitted?
1849-
*/
1850-
for (i=0; i<nr; i++) {
1854+
for (i = 0; i < nr; i++) {
18511855
struct iocb __user *user_iocb;
18521856

1853-
if (unlikely(__get_user(user_iocb, iocbpp + i))) {
1857+
if (unlikely(get_user(user_iocb, iocbpp + i))) {
18541858
ret = -EFAULT;
18551859
break;
18561860
}
18571861

1858-
ret = io_submit_one(ctx, user_iocb, compat);
1862+
ret = io_submit_one(ctx, user_iocb, false);
18591863
if (ret)
18601864
break;
18611865
}
@@ -1865,59 +1869,46 @@ static long do_io_submit(aio_context_t ctx_id, long nr,
18651869
return i ? i : ret;
18661870
}
18671871

1868-
/* sys_io_submit:
1869-
* Queue the nr iocbs pointed to by iocbpp for processing. Returns
1870-
* the number of iocbs queued. May return -EINVAL if the aio_context
1871-
* specified by ctx_id is invalid, if nr is < 0, if the iocb at
1872-
* *iocbpp[0] is not properly initialized, if the operation specified
1873-
* is invalid for the file descriptor in the iocb. May fail with
1874-
* -EFAULT if any of the data structures point to invalid data. May
1875-
* fail with -EBADF if the file descriptor specified in the first
1876-
* iocb is invalid. May fail with -EAGAIN if insufficient resources
1877-
* are available to queue any iocbs. Will return 0 if nr is 0. Will
1878-
* fail with -ENOSYS if not implemented.
1879-
*/
1880-
SYSCALL_DEFINE3(io_submit, aio_context_t, ctx_id, long, nr,
1881-
struct iocb __user * __user *, iocbpp)
1882-
{
1883-
return do_io_submit(ctx_id, nr, iocbpp, 0);
1884-
}
1885-
18861872
#ifdef CONFIG_COMPAT
1887-
static inline long
1888-
copy_iocb(long nr, u32 __user *ptr32, struct iocb __user * __user *ptr64)
1889-
{
1890-
compat_uptr_t uptr;
1891-
int i;
1892-
1893-
for (i = 0; i < nr; ++i) {
1894-
if (get_user(uptr, ptr32 + i))
1895-
return -EFAULT;
1896-
if (put_user(compat_ptr(uptr), ptr64 + i))
1897-
return -EFAULT;
1898-
}
1899-
return 0;
1900-
}
1901-
19021873
#define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *))
19031874

19041875
COMPAT_SYSCALL_DEFINE3(io_submit, compat_aio_context_t, ctx_id,
1905-
int, nr, u32 __user *, iocb)
1876+
int, nr, compat_uptr_t __user *, iocbpp)
19061877
{
1907-
struct iocb __user * __user *iocb64;
1908-
long ret;
1878+
struct kioctx *ctx;
1879+
long ret = 0;
1880+
int i = 0;
1881+
struct blk_plug plug;
19091882

19101883
if (unlikely(nr < 0))
19111884
return -EINVAL;
19121885

19131886
if (nr > MAX_AIO_SUBMITS)
19141887
nr = MAX_AIO_SUBMITS;
19151888

1916-
iocb64 = compat_alloc_user_space(nr * sizeof(*iocb64));
1917-
ret = copy_iocb(nr, iocb, iocb64);
1918-
if (!ret)
1919-
ret = do_io_submit(ctx_id, nr, iocb64, 1);
1920-
return ret;
1889+
ctx = lookup_ioctx(ctx_id);
1890+
if (unlikely(!ctx)) {
1891+
pr_debug("EINVAL: invalid context id\n");
1892+
return -EINVAL;
1893+
}
1894+
1895+
blk_start_plug(&plug);
1896+
for (i = 0; i < nr; i++) {
1897+
compat_uptr_t user_iocb;
1898+
1899+
if (unlikely(get_user(user_iocb, iocbpp + i))) {
1900+
ret = -EFAULT;
1901+
break;
1902+
}
1903+
1904+
ret = io_submit_one(ctx, compat_ptr(user_iocb), true);
1905+
if (ret)
1906+
break;
1907+
}
1908+
blk_finish_plug(&plug);
1909+
1910+
percpu_ref_put(&ctx->users);
1911+
return i ? i : ret;
19211912
}
19221913
#endif
19231914

0 commit comments

Comments
 (0)