aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/usb/gadget/function/f_fs.c5
-rw-r--r--drivers/usb/gadget/legacy/inode.c5
-rw-r--r--fs/aio.c94
-rw-r--r--fs/direct-io.c4
-rw-r--r--fs/fuse/file.c2
-rw-r--r--fs/nfs/direct.c2
-rw-r--r--include/linux/aio.h46
7 files changed, 81 insertions, 77 deletions
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 175c9956cbe3..b64538b498dc 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -655,9 +655,10 @@ static void ffs_user_copy_worker(struct work_struct *work)
655 unuse_mm(io_data->mm); 655 unuse_mm(io_data->mm);
656 } 656 }
657 657
658 aio_complete(io_data->kiocb, ret, ret); 658 io_data->kiocb->ki_complete(io_data->kiocb, ret, ret);
659 659
660 if (io_data->ffs->ffs_eventfd && !io_data->kiocb->ki_eventfd) 660 if (io_data->ffs->ffs_eventfd &&
661 !(io_data->kiocb->ki_flags & IOCB_EVENTFD))
661 eventfd_signal(io_data->ffs->ffs_eventfd, 1); 662 eventfd_signal(io_data->ffs->ffs_eventfd, 1);
662 663
663 usb_ep_free_request(io_data->ep, io_data->req); 664 usb_ep_free_request(io_data->ep, io_data->req);
diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
index 200f9a584064..a4a80694f607 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -469,7 +469,7 @@ static void ep_user_copy_worker(struct work_struct *work)
469 ret = -EFAULT; 469 ret = -EFAULT;
470 470
471 /* completing the iocb can drop the ctx and mm, don't touch mm after */ 471 /* completing the iocb can drop the ctx and mm, don't touch mm after */
472 aio_complete(iocb, ret, ret); 472 iocb->ki_complete(iocb, ret, ret);
473 473
474 kfree(priv->buf); 474 kfree(priv->buf);
475 kfree(priv->to_free); 475 kfree(priv->to_free);
@@ -497,7 +497,8 @@ static void ep_aio_complete(struct usb_ep *ep, struct usb_request *req)
497 kfree(priv); 497 kfree(priv);
498 iocb->private = NULL; 498 iocb->private = NULL;
499 /* aio_complete() reports bytes-transferred _and_ faults */ 499 /* aio_complete() reports bytes-transferred _and_ faults */
500 aio_complete(iocb, req->actual ? req->actual : req->status, 500
501 iocb->ki_complete(iocb, req->actual ? req->actual : req->status,
501 req->status); 502 req->status);
502 } else { 503 } else {
503 /* ep_copy_to_user() won't report both; we hide some faults */ 504 /* ep_copy_to_user() won't report both; we hide some faults */
diff --git a/fs/aio.c b/fs/aio.c
index 8ca8df1c3550..958286536a10 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -151,6 +151,38 @@ struct kioctx {
151 unsigned id; 151 unsigned id;
152}; 152};
153 153
154/*
155 * We use ki_cancel == KIOCB_CANCELLED to indicate that a kiocb has been either
156 * cancelled or completed (this makes a certain amount of sense because
157 * successful cancellation - io_cancel() - does deliver the completion to
158 * userspace).
159 *
160 * And since most things don't implement kiocb cancellation and we'd really like
161 * kiocb completion to be lockless when possible, we use ki_cancel to
162 * synchronize cancellation and completion - we only set it to KIOCB_CANCELLED
163 * with xchg() or cmpxchg(), see batch_complete_aio() and kiocb_cancel().
164 */
165#define KIOCB_CANCELLED ((void *) (~0ULL))
166
167struct aio_kiocb {
168 struct kiocb common;
169
170 struct kioctx *ki_ctx;
171 kiocb_cancel_fn *ki_cancel;
172
173 struct iocb __user *ki_user_iocb; /* user's aiocb */
174 __u64 ki_user_data; /* user's data for completion */
175
176 struct list_head ki_list; /* the aio core uses this
177 * for cancellation */
178
179 /*
180 * If the aio_resfd field of the userspace iocb is not zero,
181 * this is the underlying eventfd context to deliver events to.
182 */
183 struct eventfd_ctx *ki_eventfd;
184};
185
154/*------ sysctl variables----*/ 186/*------ sysctl variables----*/
155static DEFINE_SPINLOCK(aio_nr_lock); 187static DEFINE_SPINLOCK(aio_nr_lock);
156unsigned long aio_nr; /* current system wide number of aio requests */ 188unsigned long aio_nr; /* current system wide number of aio requests */
@@ -220,7 +252,7 @@ static int __init aio_setup(void)
220 if (IS_ERR(aio_mnt)) 252 if (IS_ERR(aio_mnt))
221 panic("Failed to create aio fs mount."); 253 panic("Failed to create aio fs mount.");
222 254
223 kiocb_cachep = KMEM_CACHE(kiocb, SLAB_HWCACHE_ALIGN|SLAB_PANIC); 255 kiocb_cachep = KMEM_CACHE(aio_kiocb, SLAB_HWCACHE_ALIGN|SLAB_PANIC);
224 kioctx_cachep = KMEM_CACHE(kioctx,SLAB_HWCACHE_ALIGN|SLAB_PANIC); 256 kioctx_cachep = KMEM_CACHE(kioctx,SLAB_HWCACHE_ALIGN|SLAB_PANIC);
225 257
226 pr_debug("sizeof(struct page) = %zu\n", sizeof(struct page)); 258 pr_debug("sizeof(struct page) = %zu\n", sizeof(struct page));
@@ -480,8 +512,9 @@ static int aio_setup_ring(struct kioctx *ctx)
480#define AIO_EVENTS_FIRST_PAGE ((PAGE_SIZE - sizeof(struct aio_ring)) / sizeof(struct io_event)) 512#define AIO_EVENTS_FIRST_PAGE ((PAGE_SIZE - sizeof(struct aio_ring)) / sizeof(struct io_event))
481#define AIO_EVENTS_OFFSET (AIO_EVENTS_PER_PAGE - AIO_EVENTS_FIRST_PAGE) 513#define AIO_EVENTS_OFFSET (AIO_EVENTS_PER_PAGE - AIO_EVENTS_FIRST_PAGE)
482 514
483void kiocb_set_cancel_fn(struct kiocb *req, kiocb_cancel_fn *cancel) 515void kiocb_set_cancel_fn(struct kiocb *iocb, kiocb_cancel_fn *cancel)
484{ 516{
517 struct aio_kiocb *req = container_of(iocb, struct aio_kiocb, common);
485 struct kioctx *ctx = req->ki_ctx; 518 struct kioctx *ctx = req->ki_ctx;
486 unsigned long flags; 519 unsigned long flags;
487 520
@@ -496,7 +529,7 @@ void kiocb_set_cancel_fn(struct kiocb *req, kiocb_cancel_fn *cancel)
496} 529}
497EXPORT_SYMBOL(kiocb_set_cancel_fn); 530EXPORT_SYMBOL(kiocb_set_cancel_fn);
498 531
499static int kiocb_cancel(struct kiocb *kiocb) 532static int kiocb_cancel(struct aio_kiocb *kiocb)
500{ 533{
501 kiocb_cancel_fn *old, *cancel; 534 kiocb_cancel_fn *old, *cancel;
502 535
@@ -514,7 +547,7 @@ static int kiocb_cancel(struct kiocb *kiocb)
514 cancel = cmpxchg(&kiocb->ki_cancel, old, KIOCB_CANCELLED); 547 cancel = cmpxchg(&kiocb->ki_cancel, old, KIOCB_CANCELLED);
515 } while (cancel != old); 548 } while (cancel != old);
516 549
517 return cancel(kiocb); 550 return cancel(&kiocb->common);
518} 551}
519 552
520static void free_ioctx(struct work_struct *work) 553static void free_ioctx(struct work_struct *work)
@@ -550,13 +583,13 @@ static void free_ioctx_reqs(struct percpu_ref *ref)
550static void free_ioctx_users(struct percpu_ref *ref) 583static void free_ioctx_users(struct percpu_ref *ref)
551{ 584{
552 struct kioctx *ctx = container_of(ref, struct kioctx, users); 585 struct kioctx *ctx = container_of(ref, struct kioctx, users);
553 struct kiocb *req; 586 struct aio_kiocb *req;
554 587
555 spin_lock_irq(&ctx->ctx_lock); 588 spin_lock_irq(&ctx->ctx_lock);
556 589
557 while (!list_empty(&ctx->active_reqs)) { 590 while (!list_empty(&ctx->active_reqs)) {
558 req = list_first_entry(&ctx->active_reqs, 591 req = list_first_entry(&ctx->active_reqs,
559 struct kiocb, ki_list); 592 struct aio_kiocb, ki_list);
560 593
561 list_del_init(&req->ki_list); 594 list_del_init(&req->ki_list);
562 kiocb_cancel(req); 595 kiocb_cancel(req);
@@ -932,9 +965,9 @@ static void user_refill_reqs_available(struct kioctx *ctx)
932 * Allocate a slot for an aio request. 965 * Allocate a slot for an aio request.
933 * Returns NULL if no requests are free. 966 * Returns NULL if no requests are free.
934 */ 967 */
935static inline struct kiocb *aio_get_req(struct kioctx *ctx) 968static inline struct aio_kiocb *aio_get_req(struct kioctx *ctx)
936{ 969{
937 struct kiocb *req; 970 struct aio_kiocb *req;
938 971
939 if (!get_reqs_available(ctx)) { 972 if (!get_reqs_available(ctx)) {
940 user_refill_reqs_available(ctx); 973 user_refill_reqs_available(ctx);
@@ -955,10 +988,10 @@ out_put:
955 return NULL; 988 return NULL;
956} 989}
957 990
958static void kiocb_free(struct kiocb *req) 991static void kiocb_free(struct aio_kiocb *req)
959{ 992{
960 if (req->ki_filp) 993 if (req->common.ki_filp)
961 fput(req->ki_filp); 994 fput(req->common.ki_filp);
962 if (req->ki_eventfd != NULL) 995 if (req->ki_eventfd != NULL)
963 eventfd_ctx_put(req->ki_eventfd); 996 eventfd_ctx_put(req->ki_eventfd);
964 kmem_cache_free(kiocb_cachep, req); 997 kmem_cache_free(kiocb_cachep, req);
@@ -994,8 +1027,9 @@ out:
994/* aio_complete 1027/* aio_complete
995 * Called when the io request on the given iocb is complete. 1028 * Called when the io request on the given iocb is complete.
996 */ 1029 */
997void aio_complete(struct kiocb *iocb, long res, long res2) 1030static void aio_complete(struct kiocb *kiocb, long res, long res2)
998{ 1031{
1032 struct aio_kiocb *iocb = container_of(kiocb, struct aio_kiocb, common);
999 struct kioctx *ctx = iocb->ki_ctx; 1033 struct kioctx *ctx = iocb->ki_ctx;
1000 struct aio_ring *ring; 1034 struct aio_ring *ring;
1001 struct io_event *ev_page, *event; 1035 struct io_event *ev_page, *event;
@@ -1009,7 +1043,7 @@ void aio_complete(struct kiocb *iocb, long res, long res2)