hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/fs/aio.c
....@@ -27,7 +27,6 @@
2727 #include <linux/file.h>
2828 #include <linux/mm.h>
2929 #include <linux/mman.h>
30
-#include <linux/mmu_context.h>
3130 #include <linux/percpu.h>
3231 #include <linux/slab.h>
3332 #include <linux/timer.h>
....@@ -42,6 +41,7 @@
4241 #include <linux/ramfs.h>
4342 #include <linux/percpu-refcount.h>
4443 #include <linux/mount.h>
44
+#include <linux/pseudo_fs.h>
4545
4646 #include <asm/kmap_types.h>
4747 #include <linux/uaccess.h>
....@@ -67,8 +67,14 @@
6767 unsigned header_length; /* size of aio_ring */
6868
6969
70
- struct io_event io_events[0];
70
+ struct io_event io_events[];
7171 }; /* 128 bytes + ring size */
72
+
73
+/*
74
+ * Plugging is meant to work with larger batches of IOs. If we don't
75
+ * have more than the below, then don't bother setting up a plug.
76
+ */
77
+#define AIO_PLUG_THRESHOLD 2
7278
7379 #define AIO_RING_PAGES 8
7480
....@@ -121,7 +127,6 @@
121127 long nr_pages;
122128
123129 struct rcu_work free_rwork; /* see free_ioctx() */
124
- struct work_struct free_work; /* see free_ioctx() */
125130
126131 /*
127132 * signals when all in-flight requests are done
....@@ -246,15 +251,12 @@
246251 return file;
247252 }
248253
249
-static struct dentry *aio_mount(struct file_system_type *fs_type,
250
- int flags, const char *dev_name, void *data)
254
+static int aio_init_fs_context(struct fs_context *fc)
251255 {
252
- struct dentry *root = mount_pseudo(fs_type, "aio:", NULL, NULL,
253
- AIO_RING_MAGIC);
254
-
255
- if (!IS_ERR(root))
256
- root->d_sb->s_iflags |= SB_I_NOEXEC;
257
- return root;
256
+ if (!init_pseudo(fc, AIO_RING_MAGIC))
257
+ return -ENOMEM;
258
+ fc->s_iflags |= SB_I_NOEXEC;
259
+ return 0;
258260 }
259261
260262 /* aio_setup
....@@ -265,7 +267,7 @@
265267 {
266268 static struct file_system_type aio_fs = {
267269 .name = "aio",
268
- .mount = aio_mount,
270
+ .init_fs_context = aio_init_fs_context,
269271 .kill_sb = kill_anon_super,
270272 };
271273 aio_mnt = kern_mount(&aio_fs);
....@@ -333,6 +335,9 @@
333335 spin_lock(&mm->ioctx_lock);
334336 rcu_read_lock();
335337 table = rcu_dereference(mm->ioctx_table);
338
+ if (!table)
339
+ goto out_unlock;
340
+
336341 for (i = 0; i < table->nr; i++) {
337342 struct kioctx *ctx;
338343
....@@ -346,6 +351,7 @@
346351 }
347352 }
348353
354
+out_unlock:
349355 rcu_read_unlock();
350356 spin_unlock(&mm->ioctx_lock);
351357 return res;
....@@ -422,7 +428,7 @@
422428 BUG_ON(PageWriteback(old));
423429 get_page(new);
424430
425
- rc = migrate_page_move_mapping(mapping, new, old, NULL, mode, 1);
431
+ rc = migrate_page_move_mapping(mapping, new, old, 1);
426432 if (rc != MIGRATEPAGE_SUCCESS) {
427433 put_page(new);
428434 goto out_unlock;
....@@ -518,16 +524,16 @@
518524 ctx->mmap_size = nr_pages * PAGE_SIZE;
519525 pr_debug("attempting mmap of %lu bytes\n", ctx->mmap_size);
520526
521
- if (down_write_killable(&mm->mmap_sem)) {
527
+ if (mmap_write_lock_killable(mm)) {
522528 ctx->mmap_size = 0;
523529 aio_free_ring(ctx);
524530 return -EINTR;
525531 }
526532
527
- ctx->mmap_base = do_mmap_pgoff(ctx->aio_ring_file, 0, ctx->mmap_size,
528
- PROT_READ | PROT_WRITE,
529
- MAP_SHARED, 0, &unused, NULL);
530
- up_write(&mm->mmap_sem);
533
+ ctx->mmap_base = do_mmap(ctx->aio_ring_file, 0, ctx->mmap_size,
534
+ PROT_READ | PROT_WRITE,
535
+ MAP_SHARED, 0, &unused, NULL);
536
+ mmap_write_unlock(mm);
531537 if (IS_ERR((void *)ctx->mmap_base)) {
532538 ctx->mmap_size = 0;
533539 aio_free_ring(ctx);
....@@ -609,9 +615,9 @@
609615 * and ctx->users has dropped to 0, so we know no more kiocbs can be submitted -
610616 * now it's safe to cancel any that need to be.
611617 */
612
-static void free_ioctx_users_work(struct work_struct *work)
618
+static void free_ioctx_users(struct percpu_ref *ref)
613619 {
614
- struct kioctx *ctx = container_of(work, struct kioctx, free_work);
620
+ struct kioctx *ctx = container_of(ref, struct kioctx, users);
615621 struct aio_kiocb *req;
616622
617623 spin_lock_irq(&ctx->ctx_lock);
....@@ -627,14 +633,6 @@
627633
628634 percpu_ref_kill(&ctx->reqs);
629635 percpu_ref_put(&ctx->reqs);
630
-}
631
-
632
-static void free_ioctx_users(struct percpu_ref *ref)
633
-{
634
- struct kioctx *ctx = container_of(ref, struct kioctx, users);
635
-
636
- INIT_WORK(&ctx->free_work, free_ioctx_users_work);
637
- schedule_work(&ctx->free_work);
638636 }
639637
640638 static int ioctx_add_table(struct kioctx *ctx, struct mm_struct *mm)
....@@ -1038,6 +1036,11 @@
10381036 if (unlikely(!req))
10391037 return NULL;
10401038
1039
+ if (unlikely(!get_reqs_available(ctx))) {
1040
+ kmem_cache_free(kiocb_cachep, req);
1041
+ return NULL;
1042
+ }
1043
+
10411044 percpu_ref_get(&ctx->reqs);
10421045 req->ki_ctx = ctx;
10431046 INIT_LIST_HEAD(&req->ki_list);
....@@ -1076,6 +1079,8 @@
10761079
10771080 static inline void iocb_destroy(struct aio_kiocb *iocb)
10781081 {
1082
+ if (iocb->ki_eventfd)
1083
+ eventfd_ctx_put(iocb->ki_eventfd);
10791084 if (iocb->ki_filp)
10801085 fput(iocb->ki_filp);
10811086 percpu_ref_put(&iocb->ki_ctx->reqs);
....@@ -1143,10 +1148,8 @@
11431148 * eventfd. The eventfd_signal() function is safe to be called
11441149 * from IRQ context.
11451150 */
1146
- if (iocb->ki_eventfd) {
1151
+ if (iocb->ki_eventfd)
11471152 eventfd_signal(iocb->ki_eventfd, 1);
1148
- eventfd_ctx_put(iocb->ki_eventfd);
1149
- }
11501153
11511154 /*
11521155 * We have to order our ring_info tail store above and test
....@@ -1469,7 +1472,7 @@
14691472
14701473 req->ki_ioprio = iocb->aio_reqprio;
14711474 } else
1472
- req->ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0);
1475
+ req->ki_ioprio = get_current_ioprio();
14731476
14741477 ret = kiocb_set_rw_flags(req, iocb->aio_rw_flags);
14751478 if (unlikely(ret))
....@@ -1479,8 +1482,9 @@
14791482 return 0;
14801483 }
14811484
1482
-static int aio_setup_rw(int rw, const struct iocb *iocb, struct iovec **iovec,
1483
- bool vectored, bool compat, struct iov_iter *iter)
1485
+static ssize_t aio_setup_rw(int rw, const struct iocb *iocb,
1486
+ struct iovec **iovec, bool vectored, bool compat,
1487
+ struct iov_iter *iter)
14841488 {
14851489 void __user *buf = (void __user *)(uintptr_t)iocb->aio_buf;
14861490 size_t len = iocb->aio_nbytes;
....@@ -1490,12 +1494,8 @@
14901494 *iovec = NULL;
14911495 return ret;
14921496 }
1493
-#ifdef CONFIG_COMPAT
1494
- if (compat)
1495
- return compat_import_iovec(rw, buf, len, UIO_FASTIOV, iovec,
1496
- iter);
1497
-#endif
1498
- return import_iovec(rw, buf, len, UIO_FASTIOV, iovec, iter);
1497
+
1498
+ return __import_iovec(rw, buf, len, UIO_FASTIOV, iovec, iter, compat);
14991499 }
15001500
15011501 static inline void aio_rw_done(struct kiocb *req, ssize_t ret)
....@@ -1512,19 +1512,19 @@
15121512 * may be already running. Just fail this IO with EINTR.
15131513 */
15141514 ret = -EINTR;
1515
- /*FALLTHRU*/
1515
+ fallthrough;
15161516 default:
15171517 req->ki_complete(req, ret, 0);
15181518 }
15191519 }
15201520
1521
-static ssize_t aio_read(struct kiocb *req, const struct iocb *iocb,
1521
+static int aio_read(struct kiocb *req, const struct iocb *iocb,
15221522 bool vectored, bool compat)
15231523 {
15241524 struct iovec inline_vecs[UIO_FASTIOV], *iovec = inline_vecs;
15251525 struct iov_iter iter;
15261526 struct file *file;
1527
- ssize_t ret;
1527
+ int ret;
15281528
15291529 ret = aio_prep_rw(req, iocb);
15301530 if (ret)
....@@ -1537,7 +1537,7 @@
15371537 return -EINVAL;
15381538
15391539 ret = aio_setup_rw(READ, iocb, &iovec, vectored, compat, &iter);
1540
- if (ret)
1540
+ if (ret < 0)
15411541 return ret;
15421542 ret = rw_verify_area(READ, file, &req->ki_pos, iov_iter_count(&iter));
15431543 if (!ret)
....@@ -1546,13 +1546,13 @@
15461546 return ret;
15471547 }
15481548
1549
-static ssize_t aio_write(struct kiocb *req, const struct iocb *iocb,
1549
+static int aio_write(struct kiocb *req, const struct iocb *iocb,
15501550 bool vectored, bool compat)
15511551 {
15521552 struct iovec inline_vecs[UIO_FASTIOV], *iovec = inline_vecs;
15531553 struct iov_iter iter;
15541554 struct file *file;
1555
- ssize_t ret;
1555
+ int ret;
15561556
15571557 ret = aio_prep_rw(req, iocb);
15581558 if (ret)
....@@ -1565,7 +1565,7 @@
15651565 return -EINVAL;
15661566
15671567 ret = aio_setup_rw(WRITE, iocb, &iovec, vectored, compat, &iter);
1568
- if (ret)
1568
+ if (ret < 0)
15691569 return ret;
15701570 ret = rw_verify_area(WRITE, file, &req->ki_pos, iov_iter_count(&iter));
15711571 if (!ret) {
....@@ -1577,7 +1577,7 @@
15771577 * we return to userspace.
15781578 */
15791579 if (S_ISREG(file_inode(file)->i_mode)) {
1580
- __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, true);
1580
+ sb_start_write(file_inode(file)->i_sb);
15811581 __sb_writers_release(file_inode(file)->i_sb, SB_FREEZE_WRITE);
15821582 }
15831583 req->ki_flags |= IOCB_WRITE;
....@@ -1841,7 +1841,7 @@
18411841 add_wait_queue(head, &pt->iocb->poll.wait);
18421842 }
18431843
1844
-static ssize_t aio_poll(struct aio_kiocb *aiocb, const struct iocb *iocb)
1844
+static int aio_poll(struct aio_kiocb *aiocb, const struct iocb *iocb)
18451845 {
18461846 struct kioctx *ctx = aiocb->ki_ctx;
18471847 struct poll_iocb *req = &aiocb->poll;
....@@ -1917,59 +1917,31 @@
19171917 }
19181918
19191919 static int __io_submit_one(struct kioctx *ctx, const struct iocb *iocb,
1920
- struct iocb __user *user_iocb, bool compat)
1920
+ struct iocb __user *user_iocb, struct aio_kiocb *req,
1921
+ bool compat)
19211922 {
1922
- struct aio_kiocb *req;
1923
- ssize_t ret;
1924
-
1925
- /* enforce forwards compatibility on users */
1926
- if (unlikely(iocb->aio_reserved2)) {
1927
- pr_debug("EINVAL: reserve field set\n");
1928
- return -EINVAL;
1929
- }
1930
-
1931
- /* prevent overflows */
1932
- if (unlikely(
1933
- (iocb->aio_buf != (unsigned long)iocb->aio_buf) ||
1934
- (iocb->aio_nbytes != (size_t)iocb->aio_nbytes) ||
1935
- ((ssize_t)iocb->aio_nbytes < 0)
1936
- )) {
1937
- pr_debug("EINVAL: overflow check\n");
1938
- return -EINVAL;
1939
- }
1940
-
1941
- if (!get_reqs_available(ctx))
1942
- return -EAGAIN;
1943
-
1944
- ret = -EAGAIN;
1945
- req = aio_get_req(ctx);
1946
- if (unlikely(!req))
1947
- goto out_put_reqs_available;
1948
-
19491923 req->ki_filp = fget(iocb->aio_fildes);
1950
- ret = -EBADF;
19511924 if (unlikely(!req->ki_filp))
1952
- goto out_put_req;
1925
+ return -EBADF;
19531926
19541927 if (iocb->aio_flags & IOCB_FLAG_RESFD) {
1928
+ struct eventfd_ctx *eventfd;
19551929 /*
19561930 * If the IOCB_FLAG_RESFD flag of aio_flags is set, get an
19571931 * instance of the file* now. The file descriptor must be
19581932 * an eventfd() fd, and will be signaled for each completed
19591933 * event using the eventfd_signal() function.
19601934 */
1961
- req->ki_eventfd = eventfd_ctx_fdget((int) iocb->aio_resfd);
1962
- if (IS_ERR(req->ki_eventfd)) {
1963
- ret = PTR_ERR(req->ki_eventfd);
1964
- req->ki_eventfd = NULL;
1965
- goto out_put_req;
1966
- }
1935
+ eventfd = eventfd_ctx_fdget(iocb->aio_resfd);
1936
+ if (IS_ERR(eventfd))
1937
+ return PTR_ERR(eventfd);
1938
+
1939
+ req->ki_eventfd = eventfd;
19671940 }
19681941
1969
- ret = put_user(KIOCB_KEY, &user_iocb->aio_key);
1970
- if (unlikely(ret)) {
1942
+ if (unlikely(put_user(KIOCB_KEY, &user_iocb->aio_key))) {
19711943 pr_debug("EFAULT: aio_key\n");
1972
- goto out_put_req;
1944
+ return -EFAULT;
19731945 }
19741946
19751947 req->ki_res.obj = (u64)(unsigned long)user_iocb;
....@@ -1979,61 +1951,70 @@
19791951
19801952 switch (iocb->aio_lio_opcode) {
19811953 case IOCB_CMD_PREAD:
1982
- ret = aio_read(&req->rw, iocb, false, compat);
1983
- break;
1954
+ return aio_read(&req->rw, iocb, false, compat);
19841955 case IOCB_CMD_PWRITE:
1985
- ret = aio_write(&req->rw, iocb, false, compat);
1986
- break;
1956
+ return aio_write(&req->rw, iocb, false, compat);
19871957 case IOCB_CMD_PREADV:
1988
- ret = aio_read(&req->rw, iocb, true, compat);
1989
- break;
1958
+ return aio_read(&req->rw, iocb, true, compat);
19901959 case IOCB_CMD_PWRITEV:
1991
- ret = aio_write(&req->rw, iocb, true, compat);
1992
- break;
1960
+ return aio_write(&req->rw, iocb, true, compat);
19931961 case IOCB_CMD_FSYNC:
1994
- ret = aio_fsync(&req->fsync, iocb, false);
1995
- break;
1962
+ return aio_fsync(&req->fsync, iocb, false);
19961963 case IOCB_CMD_FDSYNC:
1997
- ret = aio_fsync(&req->fsync, iocb, true);
1998
- break;
1964
+ return aio_fsync(&req->fsync, iocb, true);
19991965 case IOCB_CMD_POLL:
2000
- ret = aio_poll(req, iocb);
2001
- break;
1966
+ return aio_poll(req, iocb);
20021967 default:
20031968 pr_debug("invalid aio operation %d\n", iocb->aio_lio_opcode);
2004
- ret = -EINVAL;
2005
- break;
1969
+ return -EINVAL;
20061970 }
2007
-
2008
- /* Done with the synchronous reference */
2009
- iocb_put(req);
2010
-
2011
- /*
2012
- * If ret is 0, we'd either done aio_complete() ourselves or have
2013
- * arranged for that to be done asynchronously. Anything non-zero
2014
- * means that we need to destroy req ourselves.
2015
- */
2016
- if (!ret)
2017
- return 0;
2018
-
2019
-out_put_req:
2020
- if (req->ki_eventfd)
2021
- eventfd_ctx_put(req->ki_eventfd);
2022
- iocb_destroy(req);
2023
-out_put_reqs_available:
2024
- put_reqs_available(ctx, 1);
2025
- return ret;
20261971 }
20271972
20281973 static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
20291974 bool compat)
20301975 {
1976
+ struct aio_kiocb *req;
20311977 struct iocb iocb;
1978
+ int err;
20321979
20331980 if (unlikely(copy_from_user(&iocb, user_iocb, sizeof(iocb))))
20341981 return -EFAULT;
20351982
2036
- return __io_submit_one(ctx, &iocb, user_iocb, compat);
1983
+ /* enforce forwards compatibility on users */
1984
+ if (unlikely(iocb.aio_reserved2)) {
1985
+ pr_debug("EINVAL: reserve field set\n");
1986
+ return -EINVAL;
1987
+ }
1988
+
1989
+ /* prevent overflows */
1990
+ if (unlikely(
1991
+ (iocb.aio_buf != (unsigned long)iocb.aio_buf) ||
1992
+ (iocb.aio_nbytes != (size_t)iocb.aio_nbytes) ||
1993
+ ((ssize_t)iocb.aio_nbytes < 0)
1994
+ )) {
1995
+ pr_debug("EINVAL: overflow check\n");
1996
+ return -EINVAL;
1997
+ }
1998
+
1999
+ req = aio_get_req(ctx);
2000
+ if (unlikely(!req))
2001
+ return -EAGAIN;
2002
+
2003
+ err = __io_submit_one(ctx, &iocb, user_iocb, req, compat);
2004
+
2005
+ /* Done with the synchronous reference */
2006
+ iocb_put(req);
2007
+
2008
+ /*
2009
+ * If err is 0, we'd either done aio_complete() ourselves or have
2010
+ * arranged for that to be done asynchronously. Anything non-zero
2011
+ * means that we need to destroy req ourselves.
2012
+ */
2013
+ if (unlikely(err)) {
2014
+ iocb_destroy(req);
2015
+ put_reqs_available(ctx, 1);
2016
+ }
2017
+ return err;
20372018 }
20382019
20392020 /* sys_io_submit:
....@@ -2068,7 +2049,8 @@
20682049 if (nr > ctx->nr_events)
20692050 nr = ctx->nr_events;
20702051
2071
- blk_start_plug(&plug);
2052
+ if (nr > AIO_PLUG_THRESHOLD)
2053
+ blk_start_plug(&plug);
20722054 for (i = 0; i < nr; i++) {
20732055 struct iocb __user *user_iocb;
20742056
....@@ -2081,7 +2063,8 @@
20812063 if (ret)
20822064 break;
20832065 }
2084
- blk_finish_plug(&plug);
2066
+ if (nr > AIO_PLUG_THRESHOLD)
2067
+ blk_finish_plug(&plug);
20852068
20862069 percpu_ref_put(&ctx->users);
20872070 return i ? i : ret;
....@@ -2108,7 +2091,8 @@
21082091 if (nr > ctx->nr_events)
21092092 nr = ctx->nr_events;
21102093
2111
- blk_start_plug(&plug);
2094
+ if (nr > AIO_PLUG_THRESHOLD)
2095
+ blk_start_plug(&plug);
21122096 for (i = 0; i < nr; i++) {
21132097 compat_uptr_t user_iocb;
21142098
....@@ -2121,7 +2105,8 @@
21212105 if (ret)
21222106 break;
21232107 }
2124
- blk_finish_plug(&plug);
2108
+ if (nr > AIO_PLUG_THRESHOLD)
2109
+ blk_finish_plug(&plug);
21252110
21262111 percpu_ref_put(&ctx->users);
21272112 return i ? i : ret;
....@@ -2212,11 +2197,13 @@
22122197 * specifies an infinite timeout. Note that the timeout pointed to by
22132198 * timeout is relative. Will fail with -ENOSYS if not implemented.
22142199 */
2200
+#ifdef CONFIG_64BIT
2201
+
22152202 SYSCALL_DEFINE5(io_getevents, aio_context_t, ctx_id,
22162203 long, min_nr,
22172204 long, nr,
22182205 struct io_event __user *, events,
2219
- struct timespec __user *, timeout)
2206
+ struct __kernel_timespec __user *, timeout)
22202207 {
22212208 struct timespec64 ts;
22222209 int ret;
....@@ -2230,6 +2217,8 @@
22302217 return ret;
22312218 }
22322219
2220
+#endif
2221
+
22332222 struct __aio_sigset {
22342223 const sigset_t __user *sigmask;
22352224 size_t sigsetsize;
....@@ -2240,12 +2229,12 @@
22402229 long, min_nr,
22412230 long, nr,
22422231 struct io_event __user *, events,
2243
- struct timespec __user *, timeout,
2232
+ struct __kernel_timespec __user *, timeout,
22442233 const struct __aio_sigset __user *, usig)
22452234 {
22462235 struct __aio_sigset ksig = { NULL, };
2247
- sigset_t ksigmask, sigsaved;
22482236 struct timespec64 ts;
2237
+ bool interrupted;
22492238 int ret;
22502239
22512240 if (timeout && unlikely(get_timespec64(&ts, timeout)))
....@@ -2254,43 +2243,70 @@
22542243 if (usig && copy_from_user(&ksig, usig, sizeof(ksig)))
22552244 return -EFAULT;
22562245
2257
- if (ksig.sigmask) {
2258
- if (ksig.sigsetsize != sizeof(sigset_t))
2259
- return -EINVAL;
2260
- if (copy_from_user(&ksigmask, ksig.sigmask, sizeof(ksigmask)))
2261
- return -EFAULT;
2262
- sigdelsetmask(&ksigmask, sigmask(SIGKILL) | sigmask(SIGSTOP));
2263
- sigprocmask(SIG_SETMASK, &ksigmask, &sigsaved);
2264
- }
2246
+ ret = set_user_sigmask(ksig.sigmask, ksig.sigsetsize);
2247
+ if (ret)
2248
+ return ret;
22652249
22662250 ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &ts : NULL);
2267
- if (signal_pending(current)) {
2268
- if (ksig.sigmask) {
2269
- current->saved_sigmask = sigsaved;
2270
- set_restore_sigmask();
2271
- }
22722251
2273
- if (!ret)
2274
- ret = -ERESTARTNOHAND;
2275
- } else {
2276
- if (ksig.sigmask)
2277
- sigprocmask(SIG_SETMASK, &sigsaved, NULL);
2278
- }
2252
+ interrupted = signal_pending(current);
2253
+ restore_saved_sigmask_unless(interrupted);
2254
+ if (interrupted && !ret)
2255
+ ret = -ERESTARTNOHAND;
22792256
22802257 return ret;
22812258 }
22822259
2283
-#ifdef CONFIG_COMPAT
2284
-COMPAT_SYSCALL_DEFINE5(io_getevents, compat_aio_context_t, ctx_id,
2285
- compat_long_t, min_nr,
2286
- compat_long_t, nr,
2287
- struct io_event __user *, events,
2288
- struct compat_timespec __user *, timeout)
2260
+#if defined(CONFIG_COMPAT_32BIT_TIME) && !defined(CONFIG_64BIT)
2261
+
2262
+SYSCALL_DEFINE6(io_pgetevents_time32,
2263
+ aio_context_t, ctx_id,
2264
+ long, min_nr,
2265
+ long, nr,
2266
+ struct io_event __user *, events,
2267
+ struct old_timespec32 __user *, timeout,
2268
+ const struct __aio_sigset __user *, usig)
2269
+{
2270
+ struct __aio_sigset ksig = { NULL, };
2271
+ struct timespec64 ts;
2272
+ bool interrupted;
2273
+ int ret;
2274
+
2275
+ if (timeout && unlikely(get_old_timespec32(&ts, timeout)))
2276
+ return -EFAULT;
2277
+
2278
+ if (usig && copy_from_user(&ksig, usig, sizeof(ksig)))
2279
+ return -EFAULT;
2280
+
2281
+
2282
+ ret = set_user_sigmask(ksig.sigmask, ksig.sigsetsize);
2283
+ if (ret)
2284
+ return ret;
2285
+
2286
+ ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &ts : NULL);
2287
+
2288
+ interrupted = signal_pending(current);
2289
+ restore_saved_sigmask_unless(interrupted);
2290
+ if (interrupted && !ret)
2291
+ ret = -ERESTARTNOHAND;
2292
+
2293
+ return ret;
2294
+}
2295
+
2296
+#endif
2297
+
2298
+#if defined(CONFIG_COMPAT_32BIT_TIME)
2299
+
2300
+SYSCALL_DEFINE5(io_getevents_time32, __u32, ctx_id,
2301
+ __s32, min_nr,
2302
+ __s32, nr,
2303
+ struct io_event __user *, events,
2304
+ struct old_timespec32 __user *, timeout)
22892305 {
22902306 struct timespec64 t;
22912307 int ret;
22922308
2293
- if (timeout && compat_get_timespec64(&t, timeout))
2309
+ if (timeout && get_old_timespec32(&t, timeout))
22942310 return -EFAULT;
22952311
22962312 ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &t : NULL);
....@@ -2299,52 +2315,81 @@
22992315 return ret;
23002316 }
23012317
2318
+#endif
2319
+
2320
+#ifdef CONFIG_COMPAT
23022321
23032322 struct __compat_aio_sigset {
2304
- compat_sigset_t __user *sigmask;
2323
+ compat_uptr_t sigmask;
23052324 compat_size_t sigsetsize;
23062325 };
2326
+
2327
+#if defined(CONFIG_COMPAT_32BIT_TIME)
23072328
23082329 COMPAT_SYSCALL_DEFINE6(io_pgetevents,
23092330 compat_aio_context_t, ctx_id,
23102331 compat_long_t, min_nr,
23112332 compat_long_t, nr,
23122333 struct io_event __user *, events,
2313
- struct compat_timespec __user *, timeout,
2334
+ struct old_timespec32 __user *, timeout,
23142335 const struct __compat_aio_sigset __user *, usig)
23152336 {
2316
- struct __compat_aio_sigset ksig = { NULL, };
2317
- sigset_t ksigmask, sigsaved;
2337
+ struct __compat_aio_sigset ksig = { 0, };
23182338 struct timespec64 t;
2339
+ bool interrupted;
23192340 int ret;
23202341
2321
- if (timeout && compat_get_timespec64(&t, timeout))
2342
+ if (timeout && get_old_timespec32(&t, timeout))
23222343 return -EFAULT;
23232344
23242345 if (usig && copy_from_user(&ksig, usig, sizeof(ksig)))
23252346 return -EFAULT;
23262347
2327
- if (ksig.sigmask) {
2328
- if (ksig.sigsetsize != sizeof(compat_sigset_t))
2329
- return -EINVAL;
2330
- if (get_compat_sigset(&ksigmask, ksig.sigmask))
2331
- return -EFAULT;
2332
- sigdelsetmask(&ksigmask, sigmask(SIGKILL) | sigmask(SIGSTOP));
2333
- sigprocmask(SIG_SETMASK, &ksigmask, &sigsaved);
2334
- }
2348
+ ret = set_compat_user_sigmask(compat_ptr(ksig.sigmask), ksig.sigsetsize);
2349
+ if (ret)
2350
+ return ret;
23352351
23362352 ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &t : NULL);
2337
- if (signal_pending(current)) {
2338
- if (ksig.sigmask) {
2339
- current->saved_sigmask = sigsaved;
2340
- set_restore_sigmask();
2341
- }
2342
- if (!ret)
2343
- ret = -ERESTARTNOHAND;
2344
- } else {
2345
- if (ksig.sigmask)
2346
- sigprocmask(SIG_SETMASK, &sigsaved, NULL);
2347
- }
2353
+
2354
+ interrupted = signal_pending(current);
2355
+ restore_saved_sigmask_unless(interrupted);
2356
+ if (interrupted && !ret)
2357
+ ret = -ERESTARTNOHAND;
2358
+
2359
+ return ret;
2360
+}
2361
+
2362
+#endif
2363
+
2364
+COMPAT_SYSCALL_DEFINE6(io_pgetevents_time64,
2365
+ compat_aio_context_t, ctx_id,
2366
+ compat_long_t, min_nr,
2367
+ compat_long_t, nr,
2368
+ struct io_event __user *, events,
2369
+ struct __kernel_timespec __user *, timeout,
2370
+ const struct __compat_aio_sigset __user *, usig)
2371
+{
2372
+ struct __compat_aio_sigset ksig = { 0, };
2373
+ struct timespec64 t;
2374
+ bool interrupted;
2375
+ int ret;
2376
+
2377
+ if (timeout && get_timespec64(&t, timeout))
2378
+ return -EFAULT;
2379
+
2380
+ if (usig && copy_from_user(&ksig, usig, sizeof(ksig)))
2381
+ return -EFAULT;
2382
+
2383
+ ret = set_compat_user_sigmask(compat_ptr(ksig.sigmask), ksig.sigsetsize);
2384
+ if (ret)
2385
+ return ret;
2386
+
2387
+ ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &t : NULL);
2388
+
2389
+ interrupted = signal_pending(current);
2390
+ restore_saved_sigmask_unless(interrupted);
2391
+ if (interrupted && !ret)
2392
+ ret = -ERESTARTNOHAND;
23482393
23492394 return ret;
23502395 }